_VF.pyi 1.2 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842
  1. # @generated by tools/pyi/gen_pyi.py from torch/_C/_VariableFunctions.pyi.in
  2. # mypy: disable-error-code="type-arg"
  3. # mypy: allow-untyped-defs
  4. # ruff: noqa: F401,PYI054
  5. from collections.abc import Callable, Sequence
  6. from types import EllipsisType
  7. from typing import Any, Literal, overload, TypeVar
  8. import torch
  9. from torch import (
  10. contiguous_format,
  11. Generator,
  12. inf,
  13. memory_format,
  14. strided,
  15. SymInt,
  16. Tensor,
  17. )
  18. from torch._prims_common import DeviceLikeType
  19. from torch.types import (
  20. _bool,
  21. _complex,
  22. _device,
  23. _dtype,
  24. _float,
  25. _int,
  26. _layout,
  27. _qscheme,
  28. _size,
  29. Device,
  30. Number,
  31. )
  32. __all__ = [
  33. "__and__",
  34. "__lshift__",
  35. "__or__",
  36. "__rshift__",
  37. "__xor__",
  38. "_adaptive_avg_pool2d",
  39. "_adaptive_avg_pool3d",
  40. "_add_batch_dim",
  41. "_add_relu",
  42. "_add_relu_",
  43. "_addmm_activation",
  44. "_aminmax",
  45. "_amp_foreach_non_finite_check_and_unscale_",
  46. "_amp_update_scale_",
  47. "_assert_async",
  48. "_assert_scalar",
  49. "_assert_tensor_metadata",
  50. "_batch_norm_impl_index",
  51. "_cast_Byte",
  52. "_cast_Char",
  53. "_cast_Double",
  54. "_cast_Float",
  55. "_cast_Half",
  56. "_cast_Int",
  57. "_cast_Long",
  58. "_cast_Short",
  59. "_choose_qparams_per_tensor",
  60. "_chunk_cat",
  61. "_coalesce",
  62. "_compute_linear_combination",
  63. "_conj",
  64. "_conj_copy",
  65. "_conj_physical",
  66. "_convert_indices_from_coo_to_csr",
  67. "_convert_indices_from_csr_to_coo",
  68. "_convert_weight_to_int4pack",
  69. "_convert_weight_to_int4pack_for_cpu",
  70. "_convolution",
  71. "_convolution_mode",
  72. "_copy_from",
  73. "_copy_from_and_resize",
  74. "_cslt_compress",
  75. "_cslt_sparse_mm",
  76. "_cslt_sparse_mm_search",
  77. "_ctc_loss",
  78. "_cudnn_ctc_loss",
  79. "_cudnn_init_dropout_state",
  80. "_cudnn_rnn",
  81. "_cudnn_rnn_flatten_weight",
  82. "_cufft_clear_plan_cache",
  83. "_cufft_get_plan_cache_max_size",
  84. "_cufft_get_plan_cache_size",
  85. "_cufft_set_plan_cache_max_size",
  86. "_cummax_helper",
  87. "_cummin_helper",
  88. "_debug_has_internal_overlap",
  89. "_dim_arange",
  90. "_dirichlet_grad",
  91. "_disable_functionalization",
  92. "_dyn_quant_matmul_4bit",
  93. "_dyn_quant_pack_4bit_weight",
  94. "_efficientzerotensor",
  95. "_embedding_bag",
  96. "_embedding_bag_forward_only",
  97. "_empty_affine_quantized",
  98. "_empty_per_channel_affine_quantized",
  99. "_enable_functionalization",
  100. "_euclidean_dist",
  101. "_fake_quantize_learnable_per_channel_affine",
  102. "_fake_quantize_learnable_per_tensor_affine",
  103. "_fake_quantize_per_tensor_affine_cachemask_tensor_qparams",
  104. "_fft_c2c",
  105. "_fft_c2r",
  106. "_fft_r2c",
  107. "_fill_mem_eff_dropout_mask_",
  108. "_foobar",
  109. "_foreach_abs",
  110. "_foreach_abs_",
  111. "_foreach_acos",
  112. "_foreach_acos_",
  113. "_foreach_add",
  114. "_foreach_add_",
  115. "_foreach_addcdiv",
  116. "_foreach_addcdiv_",
  117. "_foreach_addcmul",
  118. "_foreach_addcmul_",
  119. "_foreach_asin",
  120. "_foreach_asin_",
  121. "_foreach_atan",
  122. "_foreach_atan_",
  123. "_foreach_ceil",
  124. "_foreach_ceil_",
  125. "_foreach_clamp_max",
  126. "_foreach_clamp_max_",
  127. "_foreach_clamp_min",
  128. "_foreach_clamp_min_",
  129. "_foreach_copy_",
  130. "_foreach_cos",
  131. "_foreach_cos_",
  132. "_foreach_cosh",
  133. "_foreach_cosh_",
  134. "_foreach_div",
  135. "_foreach_div_",
  136. "_foreach_erf",
  137. "_foreach_erf_",
  138. "_foreach_erfc",
  139. "_foreach_erfc_",
  140. "_foreach_exp",
  141. "_foreach_exp_",
  142. "_foreach_expm1",
  143. "_foreach_expm1_",
  144. "_foreach_floor",
  145. "_foreach_floor_",
  146. "_foreach_frac",
  147. "_foreach_frac_",
  148. "_foreach_lerp",
  149. "_foreach_lerp_",
  150. "_foreach_lgamma",
  151. "_foreach_lgamma_",
  152. "_foreach_log",
  153. "_foreach_log10",
  154. "_foreach_log10_",
  155. "_foreach_log1p",
  156. "_foreach_log1p_",
  157. "_foreach_log2",
  158. "_foreach_log2_",
  159. "_foreach_log_",
  160. "_foreach_max",
  161. "_foreach_maximum",
  162. "_foreach_maximum_",
  163. "_foreach_minimum",
  164. "_foreach_minimum_",
  165. "_foreach_mul",
  166. "_foreach_mul_",
  167. "_foreach_neg",
  168. "_foreach_neg_",
  169. "_foreach_norm",
  170. "_foreach_pow",
  171. "_foreach_pow_",
  172. "_foreach_powsum",
  173. "_foreach_reciprocal",
  174. "_foreach_reciprocal_",
  175. "_foreach_round",
  176. "_foreach_round_",
  177. "_foreach_rsqrt",
  178. "_foreach_rsqrt_",
  179. "_foreach_sigmoid",
  180. "_foreach_sigmoid_",
  181. "_foreach_sign",
  182. "_foreach_sign_",
  183. "_foreach_sin",
  184. "_foreach_sin_",
  185. "_foreach_sinh",
  186. "_foreach_sinh_",
  187. "_foreach_sqrt",
  188. "_foreach_sqrt_",
  189. "_foreach_sub",
  190. "_foreach_sub_",
  191. "_foreach_tan",
  192. "_foreach_tan_",
  193. "_foreach_tanh",
  194. "_foreach_tanh_",
  195. "_foreach_trunc",
  196. "_foreach_trunc_",
  197. "_foreach_zero_",
  198. "_from_functional_tensor",
  199. "_functional_assert_async",
  200. "_functional_assert_scalar",
  201. "_functional_sym_constrain_range",
  202. "_functional_sym_constrain_range_for_size",
  203. "_functionalize_apply_view_metas",
  204. "_functionalize_are_all_mutations_hidden_from_autograd",
  205. "_functionalize_are_all_mutations_under_no_grad_or_inference_mode",
  206. "_functionalize_commit_update",
  207. "_functionalize_has_metadata_mutation",
  208. "_functionalize_inductor_storage_resized_counter",
  209. "_functionalize_is_symbolic",
  210. "_functionalize_mark_mutation_hidden_from_autograd",
  211. "_functionalize_mark_storage_changed",
  212. "_functionalize_mutation_counter",
  213. "_functionalize_replace",
  214. "_functionalize_storage_changed_counter",
  215. "_functionalize_sync",
  216. "_functionalize_unsafe_set",
  217. "_functionalize_was_inductor_storage_resized",
  218. "_functionalize_was_storage_changed",
  219. "_fused_adagrad_",
  220. "_fused_adam_",
  221. "_fused_adamw_",
  222. "_fused_dropout",
  223. "_fused_moving_avg_obs_fq_helper",
  224. "_fused_rms_norm",
  225. "_fused_sdp_choice",
  226. "_fused_sgd_",
  227. "_fw_primal_copy",
  228. "_grid_sampler_2d_cpu_fallback",
  229. "_grouped_mm",
  230. "_has_compatible_shallow_copy_type",
  231. "_histogramdd_bin_edges",
  232. "_histogramdd_from_bin_cts",
  233. "_histogramdd_from_bin_tensors",
  234. "_index_put_impl_",
  235. "_indices_copy",
  236. "_int_mm",
  237. "_is_all_true",
  238. "_is_any_true",
  239. "_is_functional_tensor",
  240. "_is_functional_tensor_base",
  241. "_is_zerotensor",
  242. "_lazy_clone",
  243. "_linalg_check_errors",
  244. "_linalg_det",
  245. "_linalg_eigh",
  246. "_linalg_slogdet",
  247. "_linalg_solve_ex",
  248. "_linalg_svd",
  249. "_log_softmax",
  250. "_log_softmax_backward_data",
  251. "_logcumsumexp",
  252. "_lstm_mps",
  253. "_lu_with_info",
  254. "_make_dep_token",
  255. "_make_dual",
  256. "_make_dual_copy",
  257. "_make_per_channel_quantized_tensor",
  258. "_make_per_tensor_quantized_tensor",
  259. "_masked_scale",
  260. "_masked_softmax",
  261. "_mixed_dtypes_linear",
  262. "_mkldnn_reshape",
  263. "_mkldnn_transpose",
  264. "_mkldnn_transpose_",
  265. "_mps_convolution",
  266. "_mps_convolution_transpose",
  267. "_native_batch_norm_legit",
  268. "_native_batch_norm_legit_no_training",
  269. "_native_multi_head_attention",
  270. "_neg_view",
  271. "_neg_view_copy",
  272. "_nested_compute_contiguous_strides_offsets",
  273. "_nested_from_padded",
  274. "_nested_from_padded_and_nested_example",
  275. "_nested_from_padded_tensor",
  276. "_nested_get_jagged_dummy",
  277. "_nested_get_lengths",
  278. "_nested_get_max_seqlen",
  279. "_nested_get_min_seqlen",
  280. "_nested_get_offsets",
  281. "_nested_get_ragged_idx",
  282. "_nested_get_values",
  283. "_nested_get_values_copy",
  284. "_nested_tensor_from_mask",
  285. "_nested_tensor_from_mask_left_aligned",
  286. "_nested_tensor_from_tensor_list",
  287. "_nested_tensor_softmax_with_shape",
  288. "_nested_view_from_buffer",
  289. "_nested_view_from_buffer_copy",
  290. "_nested_view_from_jagged",
  291. "_nested_view_from_jagged_copy",
  292. "_nnpack_available",
  293. "_nnpack_spatial_convolution",
  294. "_pack_padded_sequence",
  295. "_pad_packed_sequence",
  296. "_pin_memory",
  297. "_prelu_kernel",
  298. "_print",
  299. "_propagate_xla_data",
  300. "_remove_batch_dim",
  301. "_reshape_alias_copy",
  302. "_reshape_from_tensor",
  303. "_resize_output_",
  304. "_rowwise_prune",
  305. "_safe_softmax",
  306. "_sample_dirichlet",
  307. "_saturate_weight_to_fp16",
  308. "_scaled_dot_product_attention_math",
  309. "_scaled_dot_product_attention_math_for_mps",
  310. "_scaled_dot_product_cudnn_attention",
  311. "_scaled_dot_product_efficient_attention",
  312. "_scaled_dot_product_flash_attention",
  313. "_scaled_dot_product_flash_attention_for_cpu",
  314. "_scaled_grouped_mm",
  315. "_scaled_grouped_mm_v2",
  316. "_scaled_mm",
  317. "_scaled_mm_v2",
  318. "_shape_as_tensor",
  319. "_sobol_engine_draw",
  320. "_sobol_engine_ff_",
  321. "_sobol_engine_initialize_state_",
  322. "_sobol_engine_scramble_",
  323. "_softmax",
  324. "_softmax_backward_data",
  325. "_sparse_broadcast_to",
  326. "_sparse_broadcast_to_copy",
  327. "_sparse_csr_prod",
  328. "_sparse_csr_sum",
  329. "_sparse_log_softmax_backward_data",
  330. "_sparse_semi_structured_addmm",
  331. "_sparse_semi_structured_apply",
  332. "_sparse_semi_structured_apply_dense",
  333. "_sparse_semi_structured_linear",
  334. "_sparse_semi_structured_mm",
  335. "_sparse_semi_structured_tile",
  336. "_sparse_softmax_backward_data",
  337. "_sparse_sparse_matmul",
  338. "_sparse_sum",
  339. "_stack",
  340. "_standard_gamma",
  341. "_standard_gamma_grad",
  342. "_sync",
  343. "_test_autograd_multiple_dispatch",
  344. "_test_autograd_multiple_dispatch_view",
  345. "_test_autograd_multiple_dispatch_view_copy",
  346. "_test_check_tensor",
  347. "_test_functorch_fallback",
  348. "_test_parallel_materialize",
  349. "_test_serialization_subcmul",
  350. "_to_cpu",
  351. "_to_functional_tensor",
  352. "_to_sparse_semi_structured",
  353. "_transform_bias_rescale_qkv",
  354. "_transformer_encoder_layer_fwd",
  355. "_trilinear",
  356. "_triton_multi_head_attention",
  357. "_triton_scaled_dot_attention",
  358. "_unique",
  359. "_unique2",
  360. "_unpack_dual",
  361. "_unsafe_index",
  362. "_unsafe_index_put",
  363. "_unsafe_masked_index",
  364. "_unsafe_masked_index_put_accumulate",
  365. "_use_cudnn_ctc_loss",
  366. "_use_cudnn_rnn_flatten_weight",
  367. "_use_miopen_ctc_loss",
  368. "_validate_compressed_sparse_indices",
  369. "_validate_sparse_bsc_tensor_args",
  370. "_validate_sparse_bsr_tensor_args",
  371. "_validate_sparse_compressed_tensor_args",
  372. "_validate_sparse_coo_tensor_args",
  373. "_validate_sparse_csc_tensor_args",
  374. "_validate_sparse_csr_tensor_args",
  375. "_values_copy",
  376. "_weight_int4pack_mm",
  377. "_weight_int4pack_mm_for_cpu",
  378. "_weight_int4pack_mm_with_scales_and_zeros",
  379. "_weight_int8pack_mm",
  380. "_weight_norm",
  381. "_weight_norm_interface",
  382. "_wrapped_linear_prepack",
  383. "_wrapped_quantized_linear_prepacked",
  384. "abs",
  385. "abs_",
  386. "absolute",
  387. "acos",
  388. "acos_",
  389. "acosh",
  390. "acosh_",
  391. "adaptive_avg_pool1d",
  392. "adaptive_max_pool1d",
  393. "add",
  394. "addbmm",
  395. "addcdiv",
  396. "addcmul",
  397. "addmm",
  398. "addmv",
  399. "addmv_",
  400. "addr",
  401. "adjoint",
  402. "affine_grid_generator",
  403. "alias_copy",
  404. "all",
  405. "allclose",
  406. "alpha_dropout",
  407. "alpha_dropout_",
  408. "amax",
  409. "amin",
  410. "aminmax",
  411. "angle",
  412. "any",
  413. "arange",
  414. "arccos",
  415. "arccos_",
  416. "arccosh",
  417. "arccosh_",
  418. "arcsin",
  419. "arcsin_",
  420. "arcsinh",
  421. "arcsinh_",
  422. "arctan",
  423. "arctan2",
  424. "arctan_",
  425. "arctanh",
  426. "arctanh_",
  427. "argmax",
  428. "argmin",
  429. "argsort",
  430. "argwhere",
  431. "as_strided",
  432. "as_strided_",
  433. "as_strided_copy",
  434. "as_strided_scatter",
  435. "as_tensor",
  436. "asarray",
  437. "asin",
  438. "asin_",
  439. "asinh",
  440. "asinh_",
  441. "atan",
  442. "atan2",
  443. "atan_",
  444. "atanh",
  445. "atanh_",
  446. "avg_pool1d",
  447. "baddbmm",
  448. "bartlett_window",
  449. "batch_norm",
  450. "batch_norm_backward_elemt",
  451. "batch_norm_backward_reduce",
  452. "batch_norm_elemt",
  453. "batch_norm_gather_stats",
  454. "batch_norm_gather_stats_with_counts",
  455. "batch_norm_stats",
  456. "batch_norm_update_stats",
  457. "bernoulli",
  458. "bilinear",
  459. "binary_cross_entropy_with_logits",
  460. "bincount",
  461. "binomial",
  462. "bitwise_and",
  463. "bitwise_left_shift",
  464. "bitwise_not",
  465. "bitwise_or",
  466. "bitwise_right_shift",
  467. "bitwise_xor",
  468. "blackman_window",
  469. "bmm",
  470. "broadcast_to",
  471. "bucketize",
  472. "can_cast",
  473. "cat",
  474. "ccol_indices_copy",
  475. "ceil",
  476. "ceil_",
  477. "celu",
  478. "celu_",
  479. "channel_shuffle",
  480. "cholesky",
  481. "cholesky_inverse",
  482. "cholesky_solve",
  483. "choose_qparams_optimized",
  484. "chunk",
  485. "clamp",
  486. "clamp_",
  487. "clamp_max",
  488. "clamp_max_",
  489. "clamp_min",
  490. "clamp_min_",
  491. "clip",
  492. "clip_",
  493. "clone",
  494. "col_indices_copy",
  495. "column_stack",
  496. "combinations",
  497. "complex",
  498. "concat",
  499. "concatenate",
  500. "conj",
  501. "conj_physical",
  502. "conj_physical_",
  503. "constant_pad_nd",
  504. "conv1d",
  505. "conv2d",
  506. "conv3d",
  507. "conv_tbc",
  508. "conv_transpose1d",
  509. "conv_transpose2d",
  510. "conv_transpose3d",
  511. "convolution",
  512. "copysign",
  513. "corrcoef",
  514. "cos",
  515. "cos_",
  516. "cosh",
  517. "cosh_",
  518. "cosine_embedding_loss",
  519. "cosine_similarity",
  520. "count_nonzero",
  521. "cov",
  522. "cross",
  523. "crow_indices_copy",
  524. "ctc_loss",
  525. "cudnn_affine_grid_generator",
  526. "cudnn_batch_norm",
  527. "cudnn_convolution",
  528. "cudnn_convolution_add_relu",
  529. "cudnn_convolution_relu",
  530. "cudnn_convolution_transpose",
  531. "cudnn_grid_sampler",
  532. "cudnn_is_acceptable",
  533. "cummax",
  534. "cummin",
  535. "cumprod",
  536. "cumsum",
  537. "cumulative_trapezoid",
  538. "deg2rad",
  539. "deg2rad_",
  540. "dequantize",
  541. "det",
  542. "detach",
  543. "detach_",
  544. "detach_copy",
  545. "diag",
  546. "diag_embed",
  547. "diagflat",
  548. "diagonal",
  549. "diagonal_copy",
  550. "diagonal_scatter",
  551. "diff",
  552. "digamma",
  553. "dist",
  554. "div",
  555. "divide",
  556. "dot",
  557. "dropout",
  558. "dropout_",
  559. "dsmm",
  560. "dsplit",
  561. "dstack",
  562. "embedding",
  563. "embedding_bag",
  564. "embedding_renorm_",
  565. "empty",
  566. "empty_like",
  567. "empty_permuted",
  568. "empty_quantized",
  569. "empty_strided",
  570. "eq",
  571. "equal",
  572. "erf",
  573. "erf_",
  574. "erfc",
  575. "erfc_",
  576. "erfinv",
  577. "exp",
  578. "exp2",
  579. "exp2_",
  580. "exp_",
  581. "expand_copy",
  582. "expm1",
  583. "expm1_",
  584. "eye",
  585. "fake_quantize_per_channel_affine",
  586. "fake_quantize_per_tensor_affine",
  587. "fbgemm_linear_fp16_weight",
  588. "fbgemm_linear_fp16_weight_fp32_activation",
  589. "fbgemm_linear_int8_weight",
  590. "fbgemm_linear_int8_weight_fp32_activation",
  591. "fbgemm_linear_quantize_weight",
  592. "fbgemm_pack_gemm_matrix_fp16",
  593. "fbgemm_pack_quantized_matrix",
  594. "feature_alpha_dropout",
  595. "feature_alpha_dropout_",
  596. "feature_dropout",
  597. "feature_dropout_",
  598. "fill",
  599. "fill_",
  600. "fix",
  601. "fix_",
  602. "flatten",
  603. "flip",
  604. "fliplr",
  605. "flipud",
  606. "float_power",
  607. "floor",
  608. "floor_",
  609. "floor_divide",
  610. "fmax",
  611. "fmin",
  612. "fmod",
  613. "frac",
  614. "frac_",
  615. "frexp",
  616. "frobenius_norm",
  617. "from_file",
  618. "from_numpy",
  619. "frombuffer",
  620. "full",
  621. "full_like",
  622. "fused_moving_avg_obs_fake_quant",
  623. "gather",
  624. "gcd",
  625. "gcd_",
  626. "ge",
  627. "geqrf",
  628. "ger",
  629. "get_default_dtype",
  630. "get_num_interop_threads",
  631. "get_num_threads",
  632. "gradient",
  633. "greater",
  634. "greater_equal",
  635. "grid_sampler",
  636. "grid_sampler_2d",
  637. "grid_sampler_3d",
  638. "group_norm",
  639. "gru",
  640. "gru_cell",
  641. "gt",
  642. "hamming_window",
  643. "hann_window",
  644. "hardshrink",
  645. "hash_tensor",
  646. "heaviside",
  647. "hinge_embedding_loss",
  648. "histc",
  649. "histogram",
  650. "histogramdd",
  651. "hsmm",
  652. "hsplit",
  653. "hspmm",
  654. "hstack",
  655. "hypot",
  656. "i0",
  657. "i0_",
  658. "igamma",
  659. "igammac",
  660. "imag",
  661. "index_add",
  662. "index_copy",
  663. "index_fill",
  664. "index_put",
  665. "index_put_",
  666. "index_reduce",
  667. "index_select",
  668. "indices_copy",
  669. "init_num_threads",
  670. "inner",
  671. "instance_norm",
  672. "int_repr",
  673. "inverse",
  674. "is_complex",
  675. "is_conj",
  676. "is_distributed",
  677. "is_floating_point",
  678. "is_grad_enabled",
  679. "is_inference",
  680. "is_inference_mode_enabled",
  681. "is_neg",
  682. "is_nonzero",
  683. "is_same_size",
  684. "is_signed",
  685. "is_vulkan_available",
  686. "isclose",
  687. "isfinite",
  688. "isin",
  689. "isinf",
  690. "isnan",
  691. "isneginf",
  692. "isposinf",
  693. "isreal",
  694. "istft",
  695. "kaiser_window",
  696. "kl_div",
  697. "kron",
  698. "kthvalue",
  699. "layer_norm",
  700. "lcm",
  701. "lcm_",
  702. "ldexp",
  703. "ldexp_",
  704. "le",
  705. "lerp",
  706. "less",
  707. "less_equal",
  708. "lgamma",
  709. "linspace",
  710. "log",
  711. "log10",
  712. "log10_",
  713. "log1p",
  714. "log1p_",
  715. "log2",
  716. "log2_",
  717. "log_",
  718. "log_softmax",
  719. "logaddexp",
  720. "logaddexp2",
  721. "logcumsumexp",
  722. "logdet",
  723. "logical_and",
  724. "logical_not",
  725. "logical_or",
  726. "logical_xor",
  727. "logit",
  728. "logit_",
  729. "logspace",
  730. "logsumexp",
  731. "lstm",
  732. "lstm_cell",
  733. "lt",
  734. "lu_solve",
  735. "lu_unpack",
  736. "margin_ranking_loss",
  737. "masked_fill",
  738. "masked_scatter",
  739. "masked_select",
  740. "matmul",
  741. "matrix_exp",
  742. "matrix_power",
  743. "max",
  744. "max_pool1d",
  745. "max_pool1d_with_indices",
  746. "max_pool2d",
  747. "max_pool3d",
  748. "maximum",
  749. "mean",
  750. "median",
  751. "min",
  752. "minimum",
  753. "miopen_batch_norm",
  754. "miopen_convolution",
  755. "miopen_convolution_add_relu",
  756. "miopen_convolution_relu",
  757. "miopen_convolution_transpose",
  758. "miopen_ctc_loss",
  759. "miopen_depthwise_convolution",
  760. "miopen_rnn",
  761. "mkldnn_adaptive_avg_pool2d",
  762. "mkldnn_convolution",
  763. "mkldnn_linear_backward_weights",
  764. "mkldnn_max_pool2d",
  765. "mkldnn_max_pool3d",
  766. "mkldnn_rnn_layer",
  767. "mm",
  768. "mode",
  769. "moveaxis",
  770. "movedim",
  771. "msort",
  772. "mul",
  773. "multinomial",
  774. "multiply",
  775. "mv",
  776. "mvlgamma",
  777. "nan_to_num",
  778. "nan_to_num_",
  779. "nanmean",
  780. "nanmedian",
  781. "nanquantile",
  782. "nansum",
  783. "narrow",
  784. "narrow_copy",
  785. "native_batch_norm",
  786. "native_channel_shuffle",
  787. "native_dropout",
  788. "native_group_norm",
  789. "native_layer_norm",
  790. "native_norm",
  791. "ne",
  792. "neg",
  793. "neg_",
  794. "negative",
  795. "negative_",
  796. "nextafter",
  797. "nonzero",
  798. "nonzero_static",
  799. "norm_except_dim",
  800. "normal",
  801. "not_equal",
  802. "nuclear_norm",
  803. "numel",
  804. "ones",
  805. "ones_like",
  806. "orgqr",
  807. "ormqr",
  808. "outer",
  809. "pairwise_distance",
  810. "pdist",
  811. "permute",
  812. "permute_copy",
  813. "pinverse",
  814. "pixel_shuffle",
  815. "pixel_unshuffle",
  816. "poisson",
  817. "poisson_nll_loss",
  818. "polar",
  819. "polygamma",
  820. "positive",
  821. "pow",
  822. "prelu",
  823. "prod",
  824. "promote_types",
  825. "put",
  826. "q_per_channel_axis",
  827. "q_per_channel_scales",
  828. "q_per_channel_zero_points",
  829. "q_scale",
  830. "q_zero_point",
  831. "qr",
  832. "quantile",
  833. "quantize_per_channel",
  834. "quantize_per_tensor",
  835. "quantize_per_tensor_dynamic",
  836. "quantized_batch_norm",
  837. "quantized_gru_cell",
  838. "quantized_lstm_cell",
  839. "quantized_max_pool1d",
  840. "quantized_max_pool2d",
  841. "quantized_max_pool3d",
  842. "quantized_rnn_relu_cell",
  843. "quantized_rnn_tanh_cell",
  844. "rad2deg",
  845. "rad2deg_",
  846. "rand",
  847. "rand_like",
  848. "randint",
  849. "randint_like",
  850. "randn",
  851. "randn_like",
  852. "randperm",
  853. "range",
  854. "ravel",
  855. "real",
  856. "reciprocal",
  857. "reciprocal_",
  858. "relu",
  859. "relu_",
  860. "remainder",
  861. "renorm",
  862. "repeat_interleave",
  863. "reshape",
  864. "resize_as_",
  865. "resize_as_sparse_",
  866. "resolve_conj",
  867. "resolve_neg",
  868. "result_type",
  869. "rms_norm",
  870. "rnn_relu",
  871. "rnn_relu_cell",
  872. "rnn_tanh",
  873. "rnn_tanh_cell",
  874. "roll",
  875. "rot90",
  876. "round",
  877. "round_",
  878. "row_indices_copy",
  879. "row_stack",
  880. "rrelu",
  881. "rrelu_",
  882. "rsqrt",
  883. "rsqrt_",
  884. "rsub",
  885. "saddmm",
  886. "scalar_tensor",
  887. "scatter",
  888. "scatter_add",
  889. "scatter_reduce",
  890. "searchsorted",
  891. "segment_reduce",
  892. "select",
  893. "select_copy",
  894. "select_scatter",
  895. "selu",
  896. "selu_",
  897. "set_flush_denormal",
  898. "set_num_interop_threads",
  899. "set_num_threads",
  900. "sgn",
  901. "sigmoid",
  902. "sigmoid_",
  903. "sign",
  904. "signbit",
  905. "sin",
  906. "sin_",
  907. "sinc",
  908. "sinc_",
  909. "sinh",
  910. "sinh_",
  911. "slice_copy",
  912. "slice_inverse",
  913. "slice_scatter",
  914. "slogdet",
  915. "smm",
  916. "softmax",
  917. "sort",
  918. "sparse_bsc_tensor",
  919. "sparse_bsr_tensor",
  920. "sparse_compressed_tensor",
  921. "sparse_coo_tensor",
  922. "sparse_csc_tensor",
  923. "sparse_csr_tensor",
  924. "split_copy",
  925. "split_with_sizes",
  926. "split_with_sizes_copy",
  927. "spmm",
  928. "sqrt",
  929. "sqrt_",
  930. "square",
  931. "square_",
  932. "squeeze",
  933. "squeeze_copy",
  934. "sspaddmm",
  935. "stack",
  936. "std",
  937. "std_mean",
  938. "sub",
  939. "subtract",
  940. "sum",
  941. "svd",
  942. "swapaxes",
  943. "swapdims",
  944. "sym_constrain_range",
  945. "sym_constrain_range_for_size",
  946. "t",
  947. "t_copy",
  948. "take",
  949. "take_along_dim",
  950. "tan",
  951. "tan_",
  952. "tanh",
  953. "tanh_",
  954. "tensor",
  955. "tensor_split",
  956. "threshold",
  957. "threshold_",
  958. "tile",
  959. "topk",
  960. "trace",
  961. "transpose",
  962. "transpose_copy",
  963. "trapezoid",
  964. "trapz",
  965. "triangular_solve",
  966. "tril",
  967. "tril_indices",
  968. "triplet_margin_loss",
  969. "triu",
  970. "triu_indices",
  971. "true_divide",
  972. "trunc",
  973. "trunc_",
  974. "unbind",
  975. "unbind_copy",
  976. "unflatten",
  977. "unfold_copy",
  978. "unique_dim",
  979. "unsafe_chunk",
  980. "unsafe_split",
  981. "unsafe_split_with_sizes",
  982. "unsqueeze",
  983. "unsqueeze_copy",
  984. "values_copy",
  985. "vander",
  986. "var",
  987. "var_mean",
  988. "vdot",
  989. "view_as_complex",
  990. "view_as_complex_copy",
  991. "view_as_real",
  992. "view_as_real_copy",
  993. "view_copy",
  994. "vsplit",
  995. "vstack",
  996. "where",
  997. "xlogy",
  998. "xlogy_",
  999. "zero_",
  1000. "zeros",
  1001. "zeros_like",
  1002. ]
  1003. @overload
  1004. def __and__(input: Tensor, other: Tensor) -> Tensor: ...
  1005. @overload
  1006. def __and__(input: Tensor, other: Number | _complex) -> Tensor: ...
  1007. @overload
  1008. def __lshift__(input: Tensor, other: Tensor) -> Tensor: ...
  1009. @overload
  1010. def __lshift__(input: Tensor, other: Number | _complex) -> Tensor: ...
  1011. @overload
  1012. def __or__(input: Tensor, other: Tensor) -> Tensor: ...
  1013. @overload
  1014. def __or__(input: Tensor, other: Number | _complex) -> Tensor: ...
  1015. @overload
  1016. def __rshift__(input: Tensor, other: Tensor) -> Tensor: ...
  1017. @overload
  1018. def __rshift__(input: Tensor, other: Number | _complex) -> Tensor: ...
  1019. @overload
  1020. def __xor__(input: Tensor, other: Tensor) -> Tensor: ...
  1021. @overload
  1022. def __xor__(input: Tensor, other: Number | _complex) -> Tensor: ...
  1023. def _adaptive_avg_pool2d(
  1024. input: Tensor,
  1025. output_size: _int | SymInt | Sequence[_int | SymInt],
  1026. ) -> Tensor: ...
  1027. def _adaptive_avg_pool3d(
  1028. input: Tensor,
  1029. output_size: _int | SymInt | Sequence[_int | SymInt],
  1030. ) -> Tensor: ...
  1031. def _add_batch_dim(input: Tensor, batch_dim: _int, level: _int) -> Tensor: ...
  1032. @overload
  1033. def _add_relu(
  1034. input: Tensor,
  1035. other: Tensor,
  1036. *,
  1037. alpha: Number | _complex = 1,
  1038. out: Tensor | None = None,
  1039. ) -> Tensor: ...
  1040. @overload
  1041. def _add_relu(
  1042. input: Tensor,
  1043. other: Number | _complex,
  1044. alpha: Number | _complex = 1,
  1045. ) -> Tensor: ...
  1046. @overload
  1047. def _add_relu_(
  1048. input: Tensor,
  1049. other: Tensor,
  1050. *,
  1051. alpha: Number | _complex = 1,
  1052. ) -> Tensor: ...
  1053. @overload
  1054. def _add_relu_(
  1055. input: Tensor,
  1056. other: Number | _complex,
  1057. alpha: Number | _complex = 1,
  1058. ) -> Tensor: ...
  1059. def _addmm_activation(
  1060. input: Tensor,
  1061. mat1: Tensor,
  1062. mat2: Tensor,
  1063. *,
  1064. beta: Number | _complex = 1,
  1065. alpha: Number | _complex = 1,
  1066. use_gelu: _bool = False,
  1067. out: Tensor | None = None,
  1068. ) -> Tensor: ...
  1069. @overload
  1070. def _aminmax(input: Tensor) -> tuple[Tensor, Tensor]: ...
  1071. @overload
  1072. def _aminmax(
  1073. input: Tensor,
  1074. dim: _int,
  1075. keepdim: _bool = False,
  1076. ) -> tuple[Tensor, Tensor]: ...
  1077. def _amp_foreach_non_finite_check_and_unscale_(
  1078. self: tuple[Tensor, ...] | list[Tensor] | None,
  1079. found_inf: Tensor,
  1080. inv_scale: Tensor,
  1081. ) -> None: ...
  1082. def _amp_update_scale_(
  1083. input: Tensor,
  1084. growth_tracker: Tensor,
  1085. found_inf: Tensor,
  1086. scale_growth_factor: _float,
  1087. scale_backoff_factor: _float,
  1088. growth_interval: _int,
  1089. ) -> Tensor: ...
  1090. @overload
  1091. def _assert_async(input: Tensor) -> None:
  1092. r"""
  1093. _assert_async(tensor) -> void
  1094. Asynchronously assert that the contents of tensor are nonzero. For CPU tensors,
  1095. this is equivalent to ``assert tensor`` or ``assert tensor.is_nonzero()``; for
  1096. CUDA tensors, we DO NOT synchronize and you may only find out the assertion
  1097. failed at a later CUDA kernel launch. Asynchronous assertion can be helpful for
  1098. testing invariants in CUDA tensors without giving up performance. This function
  1099. is NOT intended to be used for regular error checking, as it will trash your CUDA
  1100. context if the assert fails (forcing you to restart your PyTorch process.)
  1101. Args:
  1102. tensor (Tensor): a one element tensor to test to see if it is nonzero. Zero
  1103. elements (including False for boolean tensors) cause an assertion failure
  1104. to be raised.
  1105. """
  1106. @overload
  1107. def _assert_async(input: Tensor, assert_msg: str) -> None:
  1108. r"""
  1109. _assert_async(tensor) -> void
  1110. Asynchronously assert that the contents of tensor are nonzero. For CPU tensors,
  1111. this is equivalent to ``assert tensor`` or ``assert tensor.is_nonzero()``; for
  1112. CUDA tensors, we DO NOT synchronize and you may only find out the assertion
  1113. failed at a later CUDA kernel launch. Asynchronous assertion can be helpful for
  1114. testing invariants in CUDA tensors without giving up performance. This function
  1115. is NOT intended to be used for regular error checking, as it will trash your CUDA
  1116. context if the assert fails (forcing you to restart your PyTorch process.)
  1117. Args:
  1118. tensor (Tensor): a one element tensor to test to see if it is nonzero. Zero
  1119. elements (including False for boolean tensors) cause an assertion failure
  1120. to be raised.
  1121. """
  1122. def _assert_scalar(self: Number | _complex, assert_msg: str) -> None: ...
  1123. def _assert_tensor_metadata(
  1124. a: Tensor,
  1125. size: Sequence[_int | SymInt] | None = None,
  1126. stride: Sequence[_int | SymInt] | None = None,
  1127. dtype: _dtype | None = None,
  1128. *,
  1129. device: DeviceLikeType | None = None,
  1130. layout: _layout | None = None,
  1131. ) -> None: ...
  1132. def _batch_norm_impl_index(
  1133. input: Tensor,
  1134. weight: Tensor | None,
  1135. bias: Tensor | None,
  1136. running_mean: Tensor | None,
  1137. running_var: Tensor | None,
  1138. training: _bool,
  1139. momentum: _float,
  1140. eps: _float,
  1141. cudnn_enabled: _bool,
  1142. ) -> tuple[Tensor, Tensor, Tensor, Tensor, _int]: ...
  1143. def _cast_Byte(input: Tensor, non_blocking: _bool = False) -> Tensor: ...
  1144. def _cast_Char(input: Tensor, non_blocking: _bool = False) -> Tensor: ...
  1145. def _cast_Double(input: Tensor, non_blocking: _bool = False) -> Tensor: ...
  1146. def _cast_Float(input: Tensor, non_blocking: _bool = False) -> Tensor: ...
  1147. def _cast_Half(input: Tensor, non_blocking: _bool = False) -> Tensor: ...
  1148. def _cast_Int(input: Tensor, non_blocking: _bool = False) -> Tensor: ...
  1149. def _cast_Long(input: Tensor, non_blocking: _bool = False) -> Tensor: ...
  1150. def _cast_Short(input: Tensor, non_blocking: _bool = False) -> Tensor: ...
  1151. def _choose_qparams_per_tensor(
  1152. input: Tensor,
  1153. reduce_range: _bool = False,
  1154. ) -> tuple[_float, _int]: ...
  1155. def _chunk_cat(
  1156. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  1157. dim: _int,
  1158. num_chunks: _int,
  1159. *,
  1160. out: Tensor | None = None,
  1161. ) -> Tensor: ...
  1162. def _coalesce(input: Tensor) -> Tensor: ...
  1163. def _compute_linear_combination(
  1164. input: Tensor,
  1165. coefficients: Tensor,
  1166. *,
  1167. out: Tensor | None = None,
  1168. ) -> Tensor: ...
  1169. def _conj(input: Tensor) -> Tensor: ...
  1170. def _conj_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor: ...
  1171. def _conj_physical(input: Tensor) -> Tensor: ...
  1172. def _convert_indices_from_coo_to_csr(
  1173. input: Tensor,
  1174. size: _int,
  1175. *,
  1176. out_int32: _bool = False,
  1177. out: Tensor | None = None,
  1178. ) -> Tensor: ...
  1179. def _convert_indices_from_csr_to_coo(
  1180. crow_indices: Tensor,
  1181. col_indices: Tensor,
  1182. *,
  1183. out_int32: _bool = False,
  1184. transpose: _bool = False,
  1185. out: Tensor | None = None,
  1186. ) -> Tensor: ...
  1187. def _convert_weight_to_int4pack(input: Tensor, innerKTiles: _int) -> Tensor: ...
  1188. def _convert_weight_to_int4pack_for_cpu(
  1189. input: Tensor,
  1190. innerKTiles: _int,
  1191. ) -> Tensor: ...
  1192. @overload
  1193. def _convolution(
  1194. input: Tensor,
  1195. weight: Tensor,
  1196. bias: Tensor | None,
  1197. stride: Sequence[_int | SymInt],
  1198. padding: Sequence[_int | SymInt],
  1199. dilation: Sequence[_int | SymInt],
  1200. transposed: _bool,
  1201. output_padding: _size,
  1202. groups: _int | SymInt,
  1203. benchmark: _bool,
  1204. deterministic: _bool,
  1205. cudnn_enabled: _bool,
  1206. ) -> Tensor: ...
  1207. @overload
  1208. def _convolution(
  1209. input: Tensor,
  1210. weight: Tensor,
  1211. bias: Tensor | None,
  1212. stride: Sequence[_int | SymInt],
  1213. padding: Sequence[_int | SymInt],
  1214. dilation: Sequence[_int | SymInt],
  1215. transposed: _bool,
  1216. output_padding: Sequence[_int | SymInt],
  1217. groups: _int | SymInt,
  1218. benchmark: _bool,
  1219. deterministic: _bool,
  1220. cudnn_enabled: _bool,
  1221. allow_tf32: _bool,
  1222. ) -> Tensor: ...
  1223. def _convolution_mode(
  1224. input: Tensor,
  1225. weight: Tensor,
  1226. bias: Tensor | None,
  1227. stride: Sequence[_int | SymInt],
  1228. padding: str,
  1229. dilation: Sequence[_int | SymInt],
  1230. groups: _int | SymInt,
  1231. ) -> Tensor: ...
  1232. def _copy_from(
  1233. input: Tensor,
  1234. dst: Tensor,
  1235. non_blocking: _bool = False,
  1236. ) -> Tensor: ...
  1237. def _copy_from_and_resize(input: Tensor, dst: Tensor) -> Tensor: ...
  1238. def _cslt_compress(input: Tensor) -> Tensor: ...
  1239. def _cslt_sparse_mm(
  1240. compressed_A: Tensor,
  1241. dense_B: Tensor,
  1242. bias: Tensor | None = None,
  1243. alpha: Tensor | None = None,
  1244. out_dtype: _dtype | None = None,
  1245. transpose_result: _bool = False,
  1246. alg_id: _int = 0,
  1247. split_k: _int = 1,
  1248. split_k_mode: _int = -1,
  1249. ) -> Tensor: ...
  1250. def _cslt_sparse_mm_search(
  1251. compressed_A: Tensor,
  1252. dense_B: Tensor,
  1253. bias: Tensor | None = None,
  1254. alpha: Tensor | None = None,
  1255. out_dtype: _dtype | None = None,
  1256. transpose_result: _bool = False,
  1257. ) -> _int: ...
  1258. @overload
  1259. def _ctc_loss(
  1260. log_probs: Tensor,
  1261. targets: Tensor,
  1262. input_lengths: _size,
  1263. target_lengths: _size,
  1264. blank: _int = 0,
  1265. zero_infinity: _bool = False,
  1266. ) -> tuple[Tensor, Tensor]: ...
  1267. @overload
  1268. def _ctc_loss(
  1269. log_probs: Tensor,
  1270. targets: Tensor,
  1271. input_lengths: Tensor,
  1272. target_lengths: Tensor,
  1273. blank: _int = 0,
  1274. zero_infinity: _bool = False,
  1275. ) -> tuple[Tensor, Tensor]: ...
  1276. @overload
  1277. def _cudnn_ctc_loss(
  1278. log_probs: Tensor,
  1279. targets: Tensor,
  1280. input_lengths: _size,
  1281. target_lengths: _size,
  1282. blank: _int,
  1283. deterministic: _bool,
  1284. zero_infinity: _bool,
  1285. ) -> tuple[Tensor, Tensor]: ...
  1286. @overload
  1287. def _cudnn_ctc_loss(
  1288. log_probs: Tensor,
  1289. targets: Tensor,
  1290. input_lengths: Tensor,
  1291. target_lengths: Tensor,
  1292. blank: _int,
  1293. deterministic: _bool,
  1294. zero_infinity: _bool,
  1295. ) -> tuple[Tensor, Tensor]: ...
  1296. def _cudnn_init_dropout_state(
  1297. dropout: _float,
  1298. train: _bool,
  1299. dropout_seed: _int,
  1300. *,
  1301. dtype: _dtype | None = None,
  1302. layout: _layout | None = None,
  1303. device: DeviceLikeType | None = None,
  1304. pin_memory: _bool | None = False,
  1305. requires_grad: _bool | None = False,
  1306. ) -> Tensor: ...
  1307. def _cudnn_rnn(
  1308. input: Tensor,
  1309. weight: tuple[Tensor, ...] | list[Tensor] | None,
  1310. weight_stride0: _int,
  1311. weight_buf: Tensor | None,
  1312. hx: Tensor,
  1313. cx: Tensor | None,
  1314. mode: _int,
  1315. hidden_size: _int | SymInt,
  1316. proj_size: _int | SymInt,
  1317. num_layers: _int,
  1318. batch_first: _bool,
  1319. dropout: _float,
  1320. train: _bool,
  1321. bidirectional: _bool,
  1322. batch_sizes: Sequence[_int | SymInt],
  1323. dropout_state: Tensor | None,
  1324. ) -> tuple[Tensor, Tensor, Tensor, Tensor, Tensor]: ...
  1325. def _cudnn_rnn_flatten_weight(
  1326. weight_arr: tuple[Tensor, ...] | list[Tensor] | None,
  1327. weight_stride0: _int,
  1328. input_size: _int | SymInt,
  1329. mode: _int,
  1330. hidden_size: _int | SymInt,
  1331. proj_size: _int | SymInt,
  1332. num_layers: _int,
  1333. batch_first: _bool,
  1334. bidirectional: _bool,
  1335. ) -> Tensor: ...
  1336. def _cufft_clear_plan_cache(device_index: _int) -> None: ...
  1337. def _cufft_get_plan_cache_max_size(device_index: _int) -> _int: ...
  1338. def _cufft_get_plan_cache_size(device_index: _int) -> _int: ...
  1339. def _cufft_set_plan_cache_max_size(
  1340. device_index: _int,
  1341. max_size: _int,
  1342. ) -> None: ...
  1343. def _cummax_helper(
  1344. input: Tensor,
  1345. values: Tensor,
  1346. indices: Tensor,
  1347. dim: _int,
  1348. ) -> None: ...
  1349. def _cummin_helper(
  1350. input: Tensor,
  1351. values: Tensor,
  1352. indices: Tensor,
  1353. dim: _int,
  1354. ) -> None: ...
  1355. def _debug_has_internal_overlap(input: Tensor) -> _int: ...
  1356. def _dim_arange(like: Tensor, dim: _int) -> Tensor: ...
  1357. def _dirichlet_grad(x: Tensor, alpha: Tensor, total: Tensor) -> Tensor: ...
  1358. def _disable_functionalization(): ...
  1359. def _dyn_quant_matmul_4bit(
  1360. inp: Tensor,
  1361. packed_weights: Tensor,
  1362. block_size: _int,
  1363. in_features: _int,
  1364. out_features: _int,
  1365. ) -> Tensor: ...
  1366. def _dyn_quant_pack_4bit_weight(
  1367. weights: Tensor,
  1368. scales_zeros: Tensor,
  1369. bias: Tensor | None,
  1370. block_size: _int,
  1371. in_features: _int,
  1372. out_features: _int,
  1373. ) -> Tensor: ...
  1374. @overload
  1375. def _efficientzerotensor(
  1376. size: Sequence[_int | SymInt],
  1377. *,
  1378. dtype: _dtype | None = None,
  1379. layout: _layout | None = None,
  1380. device: DeviceLikeType | None = None,
  1381. pin_memory: _bool | None = False,
  1382. requires_grad: _bool | None = False,
  1383. ) -> Tensor: ...
  1384. @overload
  1385. def _efficientzerotensor(
  1386. *size: _int | SymInt,
  1387. dtype: _dtype | None = None,
  1388. layout: _layout | None = None,
  1389. device: DeviceLikeType | None = None,
  1390. pin_memory: _bool | None = False,
  1391. requires_grad: _bool | None = False,
  1392. ) -> Tensor: ...
  1393. def _embedding_bag(
  1394. weight: Tensor,
  1395. indices: Tensor,
  1396. offsets: Tensor,
  1397. scale_grad_by_freq: _bool = False,
  1398. mode: _int = 0,
  1399. sparse: _bool = False,
  1400. per_sample_weights: Tensor | None = None,
  1401. include_last_offset: _bool = False,
  1402. padding_idx: _int = -1,
  1403. ) -> tuple[Tensor, Tensor, Tensor, Tensor]: ...
  1404. def _embedding_bag_forward_only(
  1405. weight: Tensor,
  1406. indices: Tensor,
  1407. offsets: Tensor,
  1408. scale_grad_by_freq: _bool = False,
  1409. mode: _int = 0,
  1410. sparse: _bool = False,
  1411. per_sample_weights: Tensor | None = None,
  1412. include_last_offset: _bool = False,
  1413. padding_idx: _int = -1,
  1414. ) -> tuple[Tensor, Tensor, Tensor, Tensor]: ...
  1415. @overload
  1416. def _empty_affine_quantized(
  1417. size: Sequence[_int | SymInt],
  1418. *,
  1419. scale: _float = 1,
  1420. zero_point: _int = 0,
  1421. memory_format: memory_format | None = contiguous_format,
  1422. dtype: _dtype | None = None,
  1423. layout: _layout | None = None,
  1424. device: DeviceLikeType | None = None,
  1425. pin_memory: _bool | None = False,
  1426. requires_grad: _bool | None = False,
  1427. ) -> Tensor: ...
  1428. @overload
  1429. def _empty_affine_quantized(
  1430. *size: _int | SymInt,
  1431. scale: _float = 1,
  1432. zero_point: _int = 0,
  1433. memory_format: memory_format | None = contiguous_format,
  1434. dtype: _dtype | None = None,
  1435. layout: _layout | None = None,
  1436. device: DeviceLikeType | None = None,
  1437. pin_memory: _bool | None = False,
  1438. requires_grad: _bool | None = False,
  1439. ) -> Tensor: ...
  1440. @overload
  1441. def _empty_per_channel_affine_quantized(
  1442. size: Sequence[_int | SymInt],
  1443. *,
  1444. scales: Tensor,
  1445. zero_points: Tensor,
  1446. axis: _int,
  1447. memory_format: memory_format | None = contiguous_format,
  1448. dtype: _dtype | None = None,
  1449. layout: _layout | None = None,
  1450. device: DeviceLikeType | None = None,
  1451. pin_memory: _bool | None = False,
  1452. requires_grad: _bool | None = False,
  1453. ) -> Tensor: ...
  1454. @overload
  1455. def _empty_per_channel_affine_quantized(
  1456. *size: _int | SymInt,
  1457. scales: Tensor,
  1458. zero_points: Tensor,
  1459. axis: _int,
  1460. memory_format: memory_format | None = contiguous_format,
  1461. dtype: _dtype | None = None,
  1462. layout: _layout | None = None,
  1463. device: DeviceLikeType | None = None,
  1464. pin_memory: _bool | None = False,
  1465. requires_grad: _bool | None = False,
  1466. ) -> Tensor: ...
  1467. def _enable_functionalization(*, reapply_views: _bool = False) -> None: ...
  1468. def _euclidean_dist(x1: Tensor, x2: Tensor) -> Tensor: ...
  1469. def _fake_quantize_learnable_per_channel_affine(
  1470. input: Tensor,
  1471. scale: Tensor,
  1472. zero_point: Tensor,
  1473. axis: _int,
  1474. quant_min: _int,
  1475. quant_max: _int,
  1476. grad_factor: _float = 1.0,
  1477. ) -> Tensor: ...
  1478. def _fake_quantize_learnable_per_tensor_affine(
  1479. input: Tensor,
  1480. scale: Tensor,
  1481. zero_point: Tensor,
  1482. quant_min: _int,
  1483. quant_max: _int,
  1484. grad_factor: _float = 1.0,
  1485. ) -> Tensor: ...
  1486. def _fake_quantize_per_tensor_affine_cachemask_tensor_qparams(
  1487. input: Tensor,
  1488. scale: Tensor,
  1489. zero_point: Tensor,
  1490. fake_quant_enabled: Tensor,
  1491. quant_min: _int,
  1492. quant_max: _int,
  1493. ) -> torch.return_types._fake_quantize_per_tensor_affine_cachemask_tensor_qparams: # fmt: skip
  1494. ...
  1495. def _fft_c2c(
  1496. input: Tensor,
  1497. dim: Sequence[_int | SymInt],
  1498. normalization: _int,
  1499. forward: _bool,
  1500. *,
  1501. out: Tensor | None = None,
  1502. ) -> Tensor: ...
  1503. def _fft_c2r(
  1504. input: Tensor,
  1505. dim: _size,
  1506. normalization: _int,
  1507. last_dim_size: _int | SymInt,
  1508. *,
  1509. out: Tensor | None = None,
  1510. ) -> Tensor: ...
  1511. def _fft_r2c(
  1512. input: Tensor,
  1513. dim: _size,
  1514. normalization: _int,
  1515. onesided: _bool,
  1516. *,
  1517. out: Tensor | None = None,
  1518. ) -> Tensor: ...
  1519. def _fill_mem_eff_dropout_mask_(
  1520. input: Tensor,
  1521. dropout_p: _float,
  1522. seed: _int,
  1523. offset: _int,
  1524. ) -> Tensor: ...
  1525. def _foobar(
  1526. input: Tensor,
  1527. arg1: _bool = True,
  1528. arg2: _bool = True,
  1529. *,
  1530. arg3: _bool = True,
  1531. ) -> Tensor: ...
  1532. def _foreach_abs(
  1533. self: tuple[Tensor, ...] | list[Tensor] | None,
  1534. ) -> tuple[Tensor, ...]:
  1535. r"""
  1536. _foreach_abs(self: List[Tensor]) -> List[Tensor]
  1537. Apply :func:`torch.abs` to each Tensor of the input list.
  1538. """
  1539. def _foreach_abs_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1540. r"""
  1541. _foreach_abs_(self: List[Tensor]) -> None
  1542. Apply :func:`torch.abs` to each Tensor of the input list.
  1543. """
  1544. def _foreach_acos(
  1545. self: tuple[Tensor, ...] | list[Tensor] | None,
  1546. ) -> tuple[Tensor, ...]:
  1547. r"""
  1548. _foreach_acos(self: List[Tensor]) -> List[Tensor]
  1549. Apply :func:`torch.acos` to each Tensor of the input list.
  1550. """
  1551. def _foreach_acos_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1552. r"""
  1553. _foreach_acos_(self: List[Tensor]) -> None
  1554. Apply :func:`torch.acos` to each Tensor of the input list.
  1555. """
  1556. @overload
  1557. def _foreach_add(
  1558. self: tuple[Tensor, ...] | list[Tensor] | None,
  1559. scalars: Sequence[Number | _complex],
  1560. ) -> tuple[Tensor, ...]: ...
  1561. @overload
  1562. def _foreach_add(
  1563. self: tuple[Tensor, ...] | list[Tensor] | None,
  1564. other: tuple[Tensor, ...] | list[Tensor] | None,
  1565. *,
  1566. alpha: Number | _complex = 1,
  1567. ) -> tuple[Tensor, ...]: ...
  1568. @overload
  1569. def _foreach_add(
  1570. self: tuple[Tensor, ...] | list[Tensor] | None,
  1571. other: Tensor,
  1572. *,
  1573. alpha: Number | _complex = 1,
  1574. ) -> tuple[Tensor, ...]: ...
  1575. @overload
  1576. def _foreach_add(
  1577. self: tuple[Tensor, ...] | list[Tensor] | None,
  1578. scalar: Number | _complex,
  1579. ) -> tuple[Tensor, ...]: ...
  1580. @overload
  1581. def _foreach_add_(
  1582. self: tuple[Tensor, ...] | list[Tensor] | None,
  1583. scalars: Sequence[Number | _complex],
  1584. ) -> None: ...
  1585. @overload
  1586. def _foreach_add_(
  1587. self: tuple[Tensor, ...] | list[Tensor] | None,
  1588. other: tuple[Tensor, ...] | list[Tensor] | None,
  1589. *,
  1590. alpha: Number | _complex = 1,
  1591. ) -> None: ...
  1592. @overload
  1593. def _foreach_add_(
  1594. self: tuple[Tensor, ...] | list[Tensor] | None,
  1595. other: Tensor,
  1596. *,
  1597. alpha: Number | _complex = 1,
  1598. ) -> None: ...
  1599. @overload
  1600. def _foreach_add_(
  1601. self: tuple[Tensor, ...] | list[Tensor] | None,
  1602. scalar: Number | _complex,
  1603. ) -> None: ...
  1604. @overload
  1605. def _foreach_addcdiv(
  1606. self: tuple[Tensor, ...] | list[Tensor] | None,
  1607. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1608. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1609. scalars: Sequence[Number | _complex],
  1610. ) -> tuple[Tensor, ...]: ...
  1611. @overload
  1612. def _foreach_addcdiv(
  1613. self: tuple[Tensor, ...] | list[Tensor] | None,
  1614. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1615. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1616. scalars: Tensor,
  1617. ) -> tuple[Tensor, ...]: ...
  1618. @overload
  1619. def _foreach_addcdiv(
  1620. self: tuple[Tensor, ...] | list[Tensor] | None,
  1621. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1622. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1623. value: Number | _complex = 1,
  1624. ) -> tuple[Tensor, ...]: ...
  1625. @overload
  1626. def _foreach_addcdiv_(
  1627. self: tuple[Tensor, ...] | list[Tensor] | None,
  1628. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1629. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1630. scalars: Sequence[Number | _complex],
  1631. ) -> None: ...
  1632. @overload
  1633. def _foreach_addcdiv_(
  1634. self: tuple[Tensor, ...] | list[Tensor] | None,
  1635. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1636. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1637. scalars: Tensor,
  1638. ) -> None: ...
  1639. @overload
  1640. def _foreach_addcdiv_(
  1641. self: tuple[Tensor, ...] | list[Tensor] | None,
  1642. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1643. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1644. value: Number | _complex = 1,
  1645. ) -> None: ...
  1646. @overload
  1647. def _foreach_addcmul(
  1648. self: tuple[Tensor, ...] | list[Tensor] | None,
  1649. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1650. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1651. scalars: Sequence[Number | _complex],
  1652. ) -> tuple[Tensor, ...]: ...
  1653. @overload
  1654. def _foreach_addcmul(
  1655. self: tuple[Tensor, ...] | list[Tensor] | None,
  1656. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1657. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1658. scalars: Tensor,
  1659. ) -> tuple[Tensor, ...]: ...
  1660. @overload
  1661. def _foreach_addcmul(
  1662. self: tuple[Tensor, ...] | list[Tensor] | None,
  1663. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1664. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1665. value: Number | _complex = 1,
  1666. ) -> tuple[Tensor, ...]: ...
  1667. @overload
  1668. def _foreach_addcmul_(
  1669. self: tuple[Tensor, ...] | list[Tensor] | None,
  1670. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1671. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1672. scalars: Sequence[Number | _complex],
  1673. ) -> None: ...
  1674. @overload
  1675. def _foreach_addcmul_(
  1676. self: tuple[Tensor, ...] | list[Tensor] | None,
  1677. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1678. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1679. scalars: Tensor,
  1680. ) -> None: ...
  1681. @overload
  1682. def _foreach_addcmul_(
  1683. self: tuple[Tensor, ...] | list[Tensor] | None,
  1684. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1685. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1686. value: Number | _complex = 1,
  1687. ) -> None: ...
  1688. def _foreach_asin(
  1689. self: tuple[Tensor, ...] | list[Tensor] | None,
  1690. ) -> tuple[Tensor, ...]:
  1691. r"""
  1692. _foreach_asin(self: List[Tensor]) -> List[Tensor]
  1693. Apply :func:`torch.asin` to each Tensor of the input list.
  1694. """
  1695. def _foreach_asin_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1696. r"""
  1697. _foreach_asin_(self: List[Tensor]) -> None
  1698. Apply :func:`torch.asin` to each Tensor of the input list.
  1699. """
  1700. def _foreach_atan(
  1701. self: tuple[Tensor, ...] | list[Tensor] | None,
  1702. ) -> tuple[Tensor, ...]:
  1703. r"""
  1704. _foreach_atan(self: List[Tensor]) -> List[Tensor]
  1705. Apply :func:`torch.atan` to each Tensor of the input list.
  1706. """
  1707. def _foreach_atan_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1708. r"""
  1709. _foreach_atan_(self: List[Tensor]) -> None
  1710. Apply :func:`torch.atan` to each Tensor of the input list.
  1711. """
  1712. def _foreach_ceil(
  1713. self: tuple[Tensor, ...] | list[Tensor] | None,
  1714. ) -> tuple[Tensor, ...]:
  1715. r"""
  1716. _foreach_ceil(self: List[Tensor]) -> List[Tensor]
  1717. Apply :func:`torch.ceil` to each Tensor of the input list.
  1718. """
  1719. def _foreach_ceil_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1720. r"""
  1721. _foreach_ceil_(self: List[Tensor]) -> None
  1722. Apply :func:`torch.ceil` to each Tensor of the input list.
  1723. """
  1724. @overload
  1725. def _foreach_clamp_max(
  1726. self: tuple[Tensor, ...] | list[Tensor] | None,
  1727. scalars: Sequence[Number | _complex],
  1728. ) -> tuple[Tensor, ...]: ...
  1729. @overload
  1730. def _foreach_clamp_max(
  1731. self: tuple[Tensor, ...] | list[Tensor] | None,
  1732. scalar: Number | _complex,
  1733. ) -> tuple[Tensor, ...]: ...
  1734. @overload
  1735. def _foreach_clamp_max(
  1736. self: tuple[Tensor, ...] | list[Tensor] | None,
  1737. other: tuple[Tensor, ...] | list[Tensor] | None,
  1738. ) -> tuple[Tensor, ...]: ...
  1739. @overload
  1740. def _foreach_clamp_max_(
  1741. self: tuple[Tensor, ...] | list[Tensor] | None,
  1742. scalars: Sequence[Number | _complex],
  1743. ) -> None: ...
  1744. @overload
  1745. def _foreach_clamp_max_(
  1746. self: tuple[Tensor, ...] | list[Tensor] | None,
  1747. scalar: Number | _complex,
  1748. ) -> None: ...
  1749. @overload
  1750. def _foreach_clamp_max_(
  1751. self: tuple[Tensor, ...] | list[Tensor] | None,
  1752. other: tuple[Tensor, ...] | list[Tensor] | None,
  1753. ) -> None: ...
  1754. @overload
  1755. def _foreach_clamp_min(
  1756. self: tuple[Tensor, ...] | list[Tensor] | None,
  1757. scalars: Sequence[Number | _complex],
  1758. ) -> tuple[Tensor, ...]: ...
  1759. @overload
  1760. def _foreach_clamp_min(
  1761. self: tuple[Tensor, ...] | list[Tensor] | None,
  1762. scalar: Number | _complex,
  1763. ) -> tuple[Tensor, ...]: ...
  1764. @overload
  1765. def _foreach_clamp_min(
  1766. self: tuple[Tensor, ...] | list[Tensor] | None,
  1767. other: tuple[Tensor, ...] | list[Tensor] | None,
  1768. ) -> tuple[Tensor, ...]: ...
  1769. @overload
  1770. def _foreach_clamp_min_(
  1771. self: tuple[Tensor, ...] | list[Tensor] | None,
  1772. scalars: Sequence[Number | _complex],
  1773. ) -> None: ...
  1774. @overload
  1775. def _foreach_clamp_min_(
  1776. self: tuple[Tensor, ...] | list[Tensor] | None,
  1777. scalar: Number | _complex,
  1778. ) -> None: ...
  1779. @overload
  1780. def _foreach_clamp_min_(
  1781. self: tuple[Tensor, ...] | list[Tensor] | None,
  1782. other: tuple[Tensor, ...] | list[Tensor] | None,
  1783. ) -> None: ...
  1784. def _foreach_copy_(
  1785. self: tuple[Tensor, ...] | list[Tensor] | None,
  1786. src: tuple[Tensor, ...] | list[Tensor] | None,
  1787. non_blocking: _bool = False,
  1788. ) -> None: ...
  1789. def _foreach_cos(
  1790. self: tuple[Tensor, ...] | list[Tensor] | None,
  1791. ) -> tuple[Tensor, ...]:
  1792. r"""
  1793. _foreach_cos(self: List[Tensor]) -> List[Tensor]
  1794. Apply :func:`torch.cos` to each Tensor of the input list.
  1795. """
  1796. def _foreach_cos_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1797. r"""
  1798. _foreach_cos_(self: List[Tensor]) -> None
  1799. Apply :func:`torch.cos` to each Tensor of the input list.
  1800. """
  1801. def _foreach_cosh(
  1802. self: tuple[Tensor, ...] | list[Tensor] | None,
  1803. ) -> tuple[Tensor, ...]:
  1804. r"""
  1805. _foreach_cosh(self: List[Tensor]) -> List[Tensor]
  1806. Apply :func:`torch.cosh` to each Tensor of the input list.
  1807. """
  1808. def _foreach_cosh_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1809. r"""
  1810. _foreach_cosh_(self: List[Tensor]) -> None
  1811. Apply :func:`torch.cosh` to each Tensor of the input list.
  1812. """
  1813. @overload
  1814. def _foreach_div(
  1815. self: tuple[Tensor, ...] | list[Tensor] | None,
  1816. scalars: Sequence[Number | _complex],
  1817. ) -> tuple[Tensor, ...]: ...
  1818. @overload
  1819. def _foreach_div(
  1820. self: tuple[Tensor, ...] | list[Tensor] | None,
  1821. other: Tensor,
  1822. ) -> tuple[Tensor, ...]: ...
  1823. @overload
  1824. def _foreach_div(
  1825. self: tuple[Tensor, ...] | list[Tensor] | None,
  1826. scalar: Number | _complex,
  1827. ) -> tuple[Tensor, ...]: ...
  1828. @overload
  1829. def _foreach_div(
  1830. self: tuple[Tensor, ...] | list[Tensor] | None,
  1831. other: tuple[Tensor, ...] | list[Tensor] | None,
  1832. ) -> tuple[Tensor, ...]: ...
  1833. @overload
  1834. def _foreach_div_(
  1835. self: tuple[Tensor, ...] | list[Tensor] | None,
  1836. scalars: Sequence[Number | _complex],
  1837. ) -> None: ...
  1838. @overload
  1839. def _foreach_div_(
  1840. self: tuple[Tensor, ...] | list[Tensor] | None,
  1841. other: Tensor,
  1842. ) -> None: ...
  1843. @overload
  1844. def _foreach_div_(
  1845. self: tuple[Tensor, ...] | list[Tensor] | None,
  1846. scalar: Number | _complex,
  1847. ) -> None: ...
  1848. @overload
  1849. def _foreach_div_(
  1850. self: tuple[Tensor, ...] | list[Tensor] | None,
  1851. other: tuple[Tensor, ...] | list[Tensor] | None,
  1852. ) -> None: ...
  1853. def _foreach_erf(
  1854. self: tuple[Tensor, ...] | list[Tensor] | None,
  1855. ) -> tuple[Tensor, ...]:
  1856. r"""
  1857. _foreach_erf(self: List[Tensor]) -> List[Tensor]
  1858. Apply :func:`torch.erf` to each Tensor of the input list.
  1859. """
  1860. def _foreach_erf_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1861. r"""
  1862. _foreach_erf_(self: List[Tensor]) -> None
  1863. Apply :func:`torch.erf` to each Tensor of the input list.
  1864. """
  1865. def _foreach_erfc(
  1866. self: tuple[Tensor, ...] | list[Tensor] | None,
  1867. ) -> tuple[Tensor, ...]:
  1868. r"""
  1869. _foreach_erfc(self: List[Tensor]) -> List[Tensor]
  1870. Apply :func:`torch.erfc` to each Tensor of the input list.
  1871. """
  1872. def _foreach_erfc_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1873. r"""
  1874. _foreach_erfc_(self: List[Tensor]) -> None
  1875. Apply :func:`torch.erfc` to each Tensor of the input list.
  1876. """
  1877. def _foreach_exp(
  1878. self: tuple[Tensor, ...] | list[Tensor] | None,
  1879. ) -> tuple[Tensor, ...]:
  1880. r"""
  1881. _foreach_exp(self: List[Tensor]) -> List[Tensor]
  1882. Apply :func:`torch.exp` to each Tensor of the input list.
  1883. """
  1884. def _foreach_exp_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1885. r"""
  1886. _foreach_exp_(self: List[Tensor]) -> None
  1887. Apply :func:`torch.exp` to each Tensor of the input list.
  1888. """
  1889. def _foreach_expm1(
  1890. self: tuple[Tensor, ...] | list[Tensor] | None,
  1891. ) -> tuple[Tensor, ...]:
  1892. r"""
  1893. _foreach_expm1(self: List[Tensor]) -> List[Tensor]
  1894. Apply :func:`torch.expm1` to each Tensor of the input list.
  1895. """
  1896. def _foreach_expm1_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1897. r"""
  1898. _foreach_expm1_(self: List[Tensor]) -> None
  1899. Apply :func:`torch.expm1` to each Tensor of the input list.
  1900. """
  1901. def _foreach_floor(
  1902. self: tuple[Tensor, ...] | list[Tensor] | None,
  1903. ) -> tuple[Tensor, ...]:
  1904. r"""
  1905. _foreach_floor(self: List[Tensor]) -> List[Tensor]
  1906. Apply :func:`torch.floor` to each Tensor of the input list.
  1907. """
  1908. def _foreach_floor_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1909. r"""
  1910. _foreach_floor_(self: List[Tensor]) -> None
  1911. Apply :func:`torch.floor` to each Tensor of the input list.
  1912. """
  1913. def _foreach_frac(
  1914. self: tuple[Tensor, ...] | list[Tensor] | None,
  1915. ) -> tuple[Tensor, ...]:
  1916. r"""
  1917. _foreach_frac(self: List[Tensor]) -> List[Tensor]
  1918. Apply :func:`torch.frac` to each Tensor of the input list.
  1919. """
  1920. def _foreach_frac_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1921. r"""
  1922. _foreach_frac_(self: List[Tensor]) -> None
  1923. Apply :func:`torch.frac` to each Tensor of the input list.
  1924. """
  1925. @overload
  1926. def _foreach_lerp(
  1927. self: tuple[Tensor, ...] | list[Tensor] | None,
  1928. tensors1: tuple[Tensor, ...] | list[Tensor] | None,
  1929. weight: Number | _complex,
  1930. ) -> tuple[Tensor, ...]: ...
  1931. @overload
  1932. def _foreach_lerp(
  1933. self: tuple[Tensor, ...] | list[Tensor] | None,
  1934. tensors1: tuple[Tensor, ...] | list[Tensor] | None,
  1935. weight: Sequence[Number | _complex],
  1936. ) -> tuple[Tensor, ...]: ...
  1937. @overload
  1938. def _foreach_lerp(
  1939. self: tuple[Tensor, ...] | list[Tensor] | None,
  1940. tensors1: tuple[Tensor, ...] | list[Tensor] | None,
  1941. weights: tuple[Tensor, ...] | list[Tensor] | None,
  1942. ) -> tuple[Tensor, ...]: ...
  1943. @overload
  1944. def _foreach_lerp_(
  1945. self: tuple[Tensor, ...] | list[Tensor] | None,
  1946. tensors1: tuple[Tensor, ...] | list[Tensor] | None,
  1947. weight: Number | _complex,
  1948. ) -> None: ...
  1949. @overload
  1950. def _foreach_lerp_(
  1951. self: tuple[Tensor, ...] | list[Tensor] | None,
  1952. tensors1: tuple[Tensor, ...] | list[Tensor] | None,
  1953. weight: Sequence[Number | _complex],
  1954. ) -> None: ...
  1955. @overload
  1956. def _foreach_lerp_(
  1957. self: tuple[Tensor, ...] | list[Tensor] | None,
  1958. tensors1: tuple[Tensor, ...] | list[Tensor] | None,
  1959. weights: tuple[Tensor, ...] | list[Tensor] | None,
  1960. ) -> None: ...
  1961. def _foreach_lgamma(
  1962. self: tuple[Tensor, ...] | list[Tensor] | None,
  1963. ) -> tuple[Tensor, ...]:
  1964. r"""
  1965. _foreach_lgamma(self: List[Tensor]) -> List[Tensor]
  1966. Apply :func:`torch.lgamma` to each Tensor of the input list.
  1967. """
  1968. def _foreach_lgamma_(
  1969. self: tuple[Tensor, ...] | list[Tensor] | None,
  1970. ) -> None:
  1971. r"""
  1972. _foreach_lgamma_(self: List[Tensor]) -> None
  1973. Apply :func:`torch.lgamma` to each Tensor of the input list.
  1974. """
  1975. def _foreach_log(
  1976. self: tuple[Tensor, ...] | list[Tensor] | None,
  1977. ) -> tuple[Tensor, ...]:
  1978. r"""
  1979. _foreach_log(self: List[Tensor]) -> List[Tensor]
  1980. Apply :func:`torch.log` to each Tensor of the input list.
  1981. """
  1982. def _foreach_log10(
  1983. self: tuple[Tensor, ...] | list[Tensor] | None,
  1984. ) -> tuple[Tensor, ...]:
  1985. r"""
  1986. _foreach_log10(self: List[Tensor]) -> List[Tensor]
  1987. Apply :func:`torch.log10` to each Tensor of the input list.
  1988. """
  1989. def _foreach_log10_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1990. r"""
  1991. _foreach_log10_(self: List[Tensor]) -> None
  1992. Apply :func:`torch.log10` to each Tensor of the input list.
  1993. """
  1994. def _foreach_log1p(
  1995. self: tuple[Tensor, ...] | list[Tensor] | None,
  1996. ) -> tuple[Tensor, ...]:
  1997. r"""
  1998. _foreach_log1p(self: List[Tensor]) -> List[Tensor]
  1999. Apply :func:`torch.log1p` to each Tensor of the input list.
  2000. """
  2001. def _foreach_log1p_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2002. r"""
  2003. _foreach_log1p_(self: List[Tensor]) -> None
  2004. Apply :func:`torch.log1p` to each Tensor of the input list.
  2005. """
  2006. def _foreach_log2(
  2007. self: tuple[Tensor, ...] | list[Tensor] | None,
  2008. ) -> tuple[Tensor, ...]:
  2009. r"""
  2010. _foreach_log2(self: List[Tensor]) -> List[Tensor]
  2011. Apply :func:`torch.log2` to each Tensor of the input list.
  2012. """
  2013. def _foreach_log2_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2014. r"""
  2015. _foreach_log2_(self: List[Tensor]) -> None
  2016. Apply :func:`torch.log2` to each Tensor of the input list.
  2017. """
  2018. def _foreach_log_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2019. r"""
  2020. _foreach_log_(self: List[Tensor]) -> None
  2021. Apply :func:`torch.log` to each Tensor of the input list.
  2022. """
  2023. def _foreach_max(
  2024. self: tuple[Tensor, ...] | list[Tensor] | None,
  2025. ) -> tuple[Tensor, ...]: ...
  2026. @overload
  2027. def _foreach_maximum(
  2028. self: tuple[Tensor, ...] | list[Tensor] | None,
  2029. scalars: Sequence[Number | _complex],
  2030. ) -> tuple[Tensor, ...]: ...
  2031. @overload
  2032. def _foreach_maximum(
  2033. self: tuple[Tensor, ...] | list[Tensor] | None,
  2034. scalar: Number | _complex,
  2035. ) -> tuple[Tensor, ...]: ...
  2036. @overload
  2037. def _foreach_maximum(
  2038. self: tuple[Tensor, ...] | list[Tensor] | None,
  2039. other: tuple[Tensor, ...] | list[Tensor] | None,
  2040. ) -> tuple[Tensor, ...]: ...
  2041. @overload
  2042. def _foreach_maximum_(
  2043. self: tuple[Tensor, ...] | list[Tensor] | None,
  2044. scalars: Sequence[Number | _complex],
  2045. ) -> None: ...
  2046. @overload
  2047. def _foreach_maximum_(
  2048. self: tuple[Tensor, ...] | list[Tensor] | None,
  2049. scalar: Number | _complex,
  2050. ) -> None: ...
  2051. @overload
  2052. def _foreach_maximum_(
  2053. self: tuple[Tensor, ...] | list[Tensor] | None,
  2054. other: tuple[Tensor, ...] | list[Tensor] | None,
  2055. ) -> None: ...
  2056. @overload
  2057. def _foreach_minimum(
  2058. self: tuple[Tensor, ...] | list[Tensor] | None,
  2059. scalars: Sequence[Number | _complex],
  2060. ) -> tuple[Tensor, ...]: ...
  2061. @overload
  2062. def _foreach_minimum(
  2063. self: tuple[Tensor, ...] | list[Tensor] | None,
  2064. scalar: Number | _complex,
  2065. ) -> tuple[Tensor, ...]: ...
  2066. @overload
  2067. def _foreach_minimum(
  2068. self: tuple[Tensor, ...] | list[Tensor] | None,
  2069. other: tuple[Tensor, ...] | list[Tensor] | None,
  2070. ) -> tuple[Tensor, ...]: ...
  2071. @overload
  2072. def _foreach_minimum_(
  2073. self: tuple[Tensor, ...] | list[Tensor] | None,
  2074. scalars: Sequence[Number | _complex],
  2075. ) -> None: ...
  2076. @overload
  2077. def _foreach_minimum_(
  2078. self: tuple[Tensor, ...] | list[Tensor] | None,
  2079. scalar: Number | _complex,
  2080. ) -> None: ...
  2081. @overload
  2082. def _foreach_minimum_(
  2083. self: tuple[Tensor, ...] | list[Tensor] | None,
  2084. other: tuple[Tensor, ...] | list[Tensor] | None,
  2085. ) -> None: ...
  2086. @overload
  2087. def _foreach_mul(
  2088. self: tuple[Tensor, ...] | list[Tensor] | None,
  2089. scalars: Sequence[Number | _complex],
  2090. ) -> tuple[Tensor, ...]: ...
  2091. @overload
  2092. def _foreach_mul(
  2093. self: tuple[Tensor, ...] | list[Tensor] | None,
  2094. other: Tensor,
  2095. ) -> tuple[Tensor, ...]: ...
  2096. @overload
  2097. def _foreach_mul(
  2098. self: tuple[Tensor, ...] | list[Tensor] | None,
  2099. scalar: Number | _complex,
  2100. ) -> tuple[Tensor, ...]: ...
  2101. @overload
  2102. def _foreach_mul(
  2103. self: tuple[Tensor, ...] | list[Tensor] | None,
  2104. other: tuple[Tensor, ...] | list[Tensor] | None,
  2105. ) -> tuple[Tensor, ...]: ...
  2106. @overload
  2107. def _foreach_mul_(
  2108. self: tuple[Tensor, ...] | list[Tensor] | None,
  2109. scalars: Sequence[Number | _complex],
  2110. ) -> None: ...
  2111. @overload
  2112. def _foreach_mul_(
  2113. self: tuple[Tensor, ...] | list[Tensor] | None,
  2114. other: Tensor,
  2115. ) -> None: ...
  2116. @overload
  2117. def _foreach_mul_(
  2118. self: tuple[Tensor, ...] | list[Tensor] | None,
  2119. scalar: Number | _complex,
  2120. ) -> None: ...
  2121. @overload
  2122. def _foreach_mul_(
  2123. self: tuple[Tensor, ...] | list[Tensor] | None,
  2124. other: tuple[Tensor, ...] | list[Tensor] | None,
  2125. ) -> None: ...
  2126. def _foreach_neg(
  2127. self: tuple[Tensor, ...] | list[Tensor] | None,
  2128. ) -> tuple[Tensor, ...]:
  2129. r"""
  2130. _foreach_neg(self: List[Tensor]) -> List[Tensor]
  2131. Apply :func:`torch.neg` to each Tensor of the input list.
  2132. """
  2133. def _foreach_neg_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2134. r"""
  2135. _foreach_neg_(self: List[Tensor]) -> None
  2136. Apply :func:`torch.neg` to each Tensor of the input list.
  2137. """
  2138. def _foreach_norm(
  2139. self: tuple[Tensor, ...] | list[Tensor] | None,
  2140. ord: Number | _complex = 2,
  2141. dtype: _dtype | None = None,
  2142. ) -> tuple[Tensor, ...]: ...
  2143. @overload
  2144. def _foreach_pow(
  2145. self: tuple[Tensor, ...] | list[Tensor] | None,
  2146. exponent: Sequence[Number | _complex],
  2147. ) -> tuple[Tensor, ...]: ...
  2148. @overload
  2149. def _foreach_pow(
  2150. self: tuple[Tensor, ...] | list[Tensor] | None,
  2151. exponent: Number | _complex,
  2152. ) -> tuple[Tensor, ...]: ...
  2153. @overload
  2154. def _foreach_pow(
  2155. self: tuple[Tensor, ...] | list[Tensor] | None,
  2156. exponent: tuple[Tensor, ...] | list[Tensor] | None,
  2157. ) -> tuple[Tensor, ...]: ...
  2158. @overload
  2159. def _foreach_pow(
  2160. self: Number | _complex,
  2161. exponent: tuple[Tensor, ...] | list[Tensor] | None,
  2162. ) -> tuple[Tensor, ...]: ...
  2163. @overload
  2164. def _foreach_pow_(
  2165. self: tuple[Tensor, ...] | list[Tensor] | None,
  2166. exponent: Sequence[Number | _complex],
  2167. ) -> None: ...
  2168. @overload
  2169. def _foreach_pow_(
  2170. self: tuple[Tensor, ...] | list[Tensor] | None,
  2171. exponent: Number | _complex,
  2172. ) -> None: ...
  2173. @overload
  2174. def _foreach_pow_(
  2175. self: tuple[Tensor, ...] | list[Tensor] | None,
  2176. exponent: tuple[Tensor, ...] | list[Tensor] | None,
  2177. ) -> None: ...
  2178. def _foreach_powsum(
  2179. self: tuple[Tensor, ...] | list[Tensor] | None,
  2180. ord: Number | _complex = 2,
  2181. dtype: _dtype | None = None,
  2182. ) -> tuple[Tensor, ...]: ...
  2183. def _foreach_reciprocal(
  2184. self: tuple[Tensor, ...] | list[Tensor] | None,
  2185. ) -> tuple[Tensor, ...]:
  2186. r"""
  2187. _foreach_reciprocal(self: List[Tensor]) -> List[Tensor]
  2188. Apply :func:`torch.reciprocal` to each Tensor of the input list.
  2189. """
  2190. def _foreach_reciprocal_(
  2191. self: tuple[Tensor, ...] | list[Tensor] | None,
  2192. ) -> None:
  2193. r"""
  2194. _foreach_reciprocal_(self: List[Tensor]) -> None
  2195. Apply :func:`torch.reciprocal` to each Tensor of the input list.
  2196. """
  2197. def _foreach_round(
  2198. self: tuple[Tensor, ...] | list[Tensor] | None,
  2199. ) -> tuple[Tensor, ...]:
  2200. r"""
  2201. _foreach_round(self: List[Tensor]) -> List[Tensor]
  2202. Apply :func:`torch.round` to each Tensor of the input list.
  2203. """
  2204. def _foreach_round_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2205. r"""
  2206. _foreach_round_(self: List[Tensor]) -> None
  2207. Apply :func:`torch.round` to each Tensor of the input list.
  2208. """
  2209. def _foreach_rsqrt(
  2210. self: tuple[Tensor, ...] | list[Tensor] | None,
  2211. ) -> tuple[Tensor, ...]: ...
  2212. def _foreach_rsqrt_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None: ...
  2213. def _foreach_sigmoid(
  2214. self: tuple[Tensor, ...] | list[Tensor] | None,
  2215. ) -> tuple[Tensor, ...]:
  2216. r"""
  2217. _foreach_sigmoid(self: List[Tensor]) -> List[Tensor]
  2218. Apply :func:`torch.sigmoid` to each Tensor of the input list.
  2219. """
  2220. def _foreach_sigmoid_(
  2221. self: tuple[Tensor, ...] | list[Tensor] | None,
  2222. ) -> None:
  2223. r"""
  2224. _foreach_sigmoid_(self: List[Tensor]) -> None
  2225. Apply :func:`torch.sigmoid` to each Tensor of the input list.
  2226. """
  2227. def _foreach_sign(
  2228. self: tuple[Tensor, ...] | list[Tensor] | None,
  2229. ) -> tuple[Tensor, ...]: ...
  2230. def _foreach_sign_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None: ...
  2231. def _foreach_sin(
  2232. self: tuple[Tensor, ...] | list[Tensor] | None,
  2233. ) -> tuple[Tensor, ...]:
  2234. r"""
  2235. _foreach_sin(self: List[Tensor]) -> List[Tensor]
  2236. Apply :func:`torch.sin` to each Tensor of the input list.
  2237. """
  2238. def _foreach_sin_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2239. r"""
  2240. _foreach_sin_(self: List[Tensor]) -> None
  2241. Apply :func:`torch.sin` to each Tensor of the input list.
  2242. """
  2243. def _foreach_sinh(
  2244. self: tuple[Tensor, ...] | list[Tensor] | None,
  2245. ) -> tuple[Tensor, ...]:
  2246. r"""
  2247. _foreach_sinh(self: List[Tensor]) -> List[Tensor]
  2248. Apply :func:`torch.sinh` to each Tensor of the input list.
  2249. """
  2250. def _foreach_sinh_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2251. r"""
  2252. _foreach_sinh_(self: List[Tensor]) -> None
  2253. Apply :func:`torch.sinh` to each Tensor of the input list.
  2254. """
  2255. def _foreach_sqrt(
  2256. self: tuple[Tensor, ...] | list[Tensor] | None,
  2257. ) -> tuple[Tensor, ...]:
  2258. r"""
  2259. _foreach_sqrt(self: List[Tensor]) -> List[Tensor]
  2260. Apply :func:`torch.sqrt` to each Tensor of the input list.
  2261. """
  2262. def _foreach_sqrt_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2263. r"""
  2264. _foreach_sqrt_(self: List[Tensor]) -> None
  2265. Apply :func:`torch.sqrt` to each Tensor of the input list.
  2266. """
  2267. @overload
  2268. def _foreach_sub(
  2269. self: tuple[Tensor, ...] | list[Tensor] | None,
  2270. scalars: Sequence[Number | _complex],
  2271. ) -> tuple[Tensor, ...]: ...
  2272. @overload
  2273. def _foreach_sub(
  2274. self: tuple[Tensor, ...] | list[Tensor] | None,
  2275. other: tuple[Tensor, ...] | list[Tensor] | None,
  2276. *,
  2277. alpha: Number | _complex = 1,
  2278. ) -> tuple[Tensor, ...]: ...
  2279. @overload
  2280. def _foreach_sub(
  2281. self: tuple[Tensor, ...] | list[Tensor] | None,
  2282. scalar: Number | _complex,
  2283. ) -> tuple[Tensor, ...]: ...
  2284. @overload
  2285. def _foreach_sub_(
  2286. self: tuple[Tensor, ...] | list[Tensor] | None,
  2287. scalars: Sequence[Number | _complex],
  2288. ) -> None: ...
  2289. @overload
  2290. def _foreach_sub_(
  2291. self: tuple[Tensor, ...] | list[Tensor] | None,
  2292. other: tuple[Tensor, ...] | list[Tensor] | None,
  2293. *,
  2294. alpha: Number | _complex = 1,
  2295. ) -> None: ...
  2296. @overload
  2297. def _foreach_sub_(
  2298. self: tuple[Tensor, ...] | list[Tensor] | None,
  2299. scalar: Number | _complex,
  2300. ) -> None: ...
  2301. def _foreach_tan(
  2302. self: tuple[Tensor, ...] | list[Tensor] | None,
  2303. ) -> tuple[Tensor, ...]:
  2304. r"""
  2305. _foreach_tan(self: List[Tensor]) -> List[Tensor]
  2306. Apply :func:`torch.tan` to each Tensor of the input list.
  2307. """
  2308. def _foreach_tan_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2309. r"""
  2310. _foreach_tan_(self: List[Tensor]) -> None
  2311. Apply :func:`torch.tan` to each Tensor of the input list.
  2312. """
  2313. def _foreach_tanh(
  2314. self: tuple[Tensor, ...] | list[Tensor] | None,
  2315. ) -> tuple[Tensor, ...]:
  2316. r"""
  2317. _foreach_tanh(self: List[Tensor]) -> List[Tensor]
  2318. Apply :func:`torch.tanh` to each Tensor of the input list.
  2319. """
  2320. def _foreach_tanh_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2321. r"""
  2322. _foreach_tanh_(self: List[Tensor]) -> None
  2323. Apply :func:`torch.tanh` to each Tensor of the input list.
  2324. """
  2325. def _foreach_trunc(
  2326. self: tuple[Tensor, ...] | list[Tensor] | None,
  2327. ) -> tuple[Tensor, ...]:
  2328. r"""
  2329. _foreach_trunc(self: List[Tensor]) -> List[Tensor]
  2330. Apply :func:`torch.trunc` to each Tensor of the input list.
  2331. """
  2332. def _foreach_trunc_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2333. r"""
  2334. _foreach_trunc_(self: List[Tensor]) -> None
  2335. Apply :func:`torch.trunc` to each Tensor of the input list.
  2336. """
  2337. def _foreach_zero_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2338. r"""
  2339. _foreach_zero_(self: List[Tensor]) -> None
  2340. Apply :func:`torch.zero` to each Tensor of the input list.
  2341. """
  2342. def _from_functional_tensor(t: Tensor) -> Tensor: ...
  2343. def _functional_assert_async(
  2344. input: Tensor,
  2345. assert_msg: str,
  2346. dep_token: Tensor,
  2347. ) -> Tensor: ...
  2348. def _functional_assert_scalar(
  2349. self: Number | _complex,
  2350. assert_msg: str,
  2351. dep_token: Tensor,
  2352. ) -> Tensor: ...
  2353. def _functional_sym_constrain_range(
  2354. size: Number | _complex,
  2355. min: _int | None,
  2356. max: _int | None,
  2357. dep_token: Tensor,
  2358. ) -> Tensor: ...
  2359. def _functional_sym_constrain_range_for_size(
  2360. size: Number | _complex,
  2361. min: _int | None,
  2362. max: _int | None,
  2363. dep_token: Tensor,
  2364. ) -> Tensor: ...
  2365. def _functionalize_apply_view_metas(tensor: Tensor, base: Tensor) -> Tensor: ...
  2366. def _functionalize_are_all_mutations_hidden_from_autograd(
  2367. t: Tensor,
  2368. ) -> _bool: ...
  2369. def _functionalize_are_all_mutations_under_no_grad_or_inference_mode(
  2370. t: Tensor,
  2371. ) -> _bool: ...
  2372. def _functionalize_commit_update(t: Tensor) -> None: ...
  2373. def _functionalize_has_metadata_mutation(tensor: Tensor) -> _bool: ...
  2374. def _functionalize_inductor_storage_resized_counter(t: Tensor) -> _int: ...
  2375. def _functionalize_is_symbolic(tensor: Tensor) -> _bool: ...
  2376. def _functionalize_mark_mutation_hidden_from_autograd(t: Tensor) -> None: ...
  2377. def _functionalize_mark_storage_changed(tensor: Tensor) -> _bool: ...
  2378. def _functionalize_mutation_counter(t: Tensor) -> _int: ...
  2379. def _functionalize_replace(self_: Tensor, other: Tensor) -> None: ...
  2380. def _functionalize_storage_changed_counter(t: Tensor) -> _int: ...
  2381. def _functionalize_sync(t: Tensor) -> None: ...
  2382. def _functionalize_unsafe_set(dst: Tensor, src: Tensor) -> None: ...
  2383. def _functionalize_was_inductor_storage_resized(t: Tensor) -> _bool: ...
  2384. def _functionalize_was_storage_changed(tensor: Tensor) -> _bool: ...
  2385. @overload
  2386. def _fused_adagrad_(
  2387. self: tuple[Tensor, ...] | list[Tensor] | None,
  2388. grads: tuple[Tensor, ...] | list[Tensor] | None,
  2389. state_sums: tuple[Tensor, ...] | list[Tensor] | None,
  2390. state_steps: tuple[Tensor, ...] | list[Tensor] | None,
  2391. *,
  2392. lr: Tensor,
  2393. lr_decay: _float,
  2394. weight_decay: _float,
  2395. eps: _float,
  2396. maximize: _bool,
  2397. grad_scale: Tensor | None = None,
  2398. found_inf: Tensor | None = None,
  2399. ) -> None: ...
  2400. @overload
  2401. def _fused_adagrad_(
  2402. self: tuple[Tensor, ...] | list[Tensor] | None,
  2403. grads: tuple[Tensor, ...] | list[Tensor] | None,
  2404. state_sums: tuple[Tensor, ...] | list[Tensor] | None,
  2405. state_steps: tuple[Tensor, ...] | list[Tensor] | None,
  2406. *,
  2407. lr: _float,
  2408. lr_decay: _float,
  2409. weight_decay: _float,
  2410. eps: _float,
  2411. maximize: _bool,
  2412. grad_scale: Tensor | None = None,
  2413. found_inf: Tensor | None = None,
  2414. ) -> None: ...
  2415. @overload
  2416. def _fused_adam_(
  2417. self: tuple[Tensor, ...] | list[Tensor] | None,
  2418. grads: tuple[Tensor, ...] | list[Tensor] | None,
  2419. exp_avgs: tuple[Tensor, ...] | list[Tensor] | None,
  2420. exp_avg_sqs: tuple[Tensor, ...] | list[Tensor] | None,
  2421. max_exp_avg_sqs: tuple[Tensor, ...] | list[Tensor] | None,
  2422. state_steps: tuple[Tensor, ...] | list[Tensor] | None,
  2423. *,
  2424. lr: Tensor,
  2425. beta1: _float,
  2426. beta2: _float,
  2427. weight_decay: _float,
  2428. eps: _float,
  2429. amsgrad: _bool,
  2430. maximize: _bool,
  2431. grad_scale: Tensor | None = None,
  2432. found_inf: Tensor | None = None,
  2433. ) -> None: ...
  2434. @overload
  2435. def _fused_adam_(
  2436. self: tuple[Tensor, ...] | list[Tensor] | None,
  2437. grads: tuple[Tensor, ...] | list[Tensor] | None,
  2438. exp_avgs: tuple[Tensor, ...] | list[Tensor] | None,
  2439. exp_avg_sqs: tuple[Tensor, ...] | list[Tensor] | None,
  2440. max_exp_avg_sqs: tuple[Tensor, ...] | list[Tensor] | None,
  2441. state_steps: tuple[Tensor, ...] | list[Tensor] | None,
  2442. *,
  2443. lr: _float,
  2444. beta1: _float,
  2445. beta2: _float,
  2446. weight_decay: _float,
  2447. eps: _float,
  2448. amsgrad: _bool,
  2449. maximize: _bool,
  2450. grad_scale: Tensor | None = None,
  2451. found_inf: Tensor | None = None,
  2452. ) -> None: ...
  2453. @overload
  2454. def _fused_adamw_(
  2455. self: tuple[Tensor, ...] | list[Tensor] | None,
  2456. grads: tuple[Tensor, ...] | list[Tensor] | None,
  2457. exp_avgs: tuple[Tensor, ...] | list[Tensor] | None,
  2458. exp_avg_sqs: tuple[Tensor, ...] | list[Tensor] | None,
  2459. max_exp_avg_sqs: tuple[Tensor, ...] | list[Tensor] | None,
  2460. state_steps: tuple[Tensor, ...] | list[Tensor] | None,
  2461. *,
  2462. lr: Tensor,
  2463. beta1: _float,
  2464. beta2: _float,
  2465. weight_decay: _float,
  2466. eps: _float,
  2467. amsgrad: _bool,
  2468. maximize: _bool,
  2469. grad_scale: Tensor | None = None,
  2470. found_inf: Tensor | None = None,
  2471. ) -> None: ...
  2472. @overload
  2473. def _fused_adamw_(
  2474. self: tuple[Tensor, ...] | list[Tensor] | None,
  2475. grads: tuple[Tensor, ...] | list[Tensor] | None,
  2476. exp_avgs: tuple[Tensor, ...] | list[Tensor] | None,
  2477. exp_avg_sqs: tuple[Tensor, ...] | list[Tensor] | None,
  2478. max_exp_avg_sqs: tuple[Tensor, ...] | list[Tensor] | None,
  2479. state_steps: tuple[Tensor, ...] | list[Tensor] | None,
  2480. *,
  2481. lr: _float,
  2482. beta1: _float,
  2483. beta2: _float,
  2484. weight_decay: _float,
  2485. eps: _float,
  2486. amsgrad: _bool,
  2487. maximize: _bool,
  2488. grad_scale: Tensor | None = None,
  2489. found_inf: Tensor | None = None,
  2490. ) -> None: ...
  2491. def _fused_dropout(
  2492. input: Tensor,
  2493. p: _float,
  2494. generator: Generator | None = None,
  2495. ) -> tuple[Tensor, Tensor]: ...
  2496. def _fused_moving_avg_obs_fq_helper(
  2497. input: Tensor,
  2498. observer_on: Tensor,
  2499. fake_quant_on: Tensor,
  2500. running_min: Tensor,
  2501. running_max: Tensor,
  2502. scale: Tensor,
  2503. zero_point: Tensor,
  2504. averaging_const: _float,
  2505. quant_min: _int,
  2506. quant_max: _int,
  2507. ch_axis: _int,
  2508. per_row_fake_quant: _bool = False,
  2509. symmetric_quant: _bool = False,
  2510. ) -> torch.return_types._fused_moving_avg_obs_fq_helper: ...
  2511. def _fused_rms_norm(
  2512. input: Tensor,
  2513. normalized_shape: _size,
  2514. weight: Tensor | None,
  2515. eps: _float | None,
  2516. ) -> tuple[Tensor, Tensor]: ...
  2517. def _fused_sdp_choice(
  2518. query: Tensor,
  2519. key: Tensor,
  2520. value: Tensor,
  2521. attn_mask: Tensor | None = None,
  2522. dropout_p: _float = 0.0,
  2523. is_causal: _bool = False,
  2524. *,
  2525. scale: _float | None = None,
  2526. enable_gqa: _bool = False,
  2527. ) -> _int: ...
  2528. @overload
  2529. def _fused_sgd_(
  2530. self: tuple[Tensor, ...] | list[Tensor] | None,
  2531. grads: tuple[Tensor, ...] | list[Tensor] | None,
  2532. momentum_buffer_list: tuple[Tensor, ...] | list[Tensor] | None,
  2533. *,
  2534. weight_decay: _float,
  2535. momentum: _float,
  2536. lr: Tensor,
  2537. dampening: _float,
  2538. nesterov: _bool,
  2539. maximize: _bool,
  2540. is_first_step: _bool,
  2541. grad_scale: Tensor | None = None,
  2542. found_inf: Tensor | None = None,
  2543. ) -> None: ...
  2544. @overload
  2545. def _fused_sgd_(
  2546. self: tuple[Tensor, ...] | list[Tensor] | None,
  2547. grads: tuple[Tensor, ...] | list[Tensor] | None,
  2548. momentum_buffer_list: tuple[Tensor, ...] | list[Tensor] | None,
  2549. *,
  2550. weight_decay: _float,
  2551. momentum: _float,
  2552. lr: _float,
  2553. dampening: _float,
  2554. nesterov: _bool,
  2555. maximize: _bool,
  2556. is_first_step: _bool,
  2557. grad_scale: Tensor | None = None,
  2558. found_inf: Tensor | None = None,
  2559. ) -> None: ...
  2560. def _fw_primal_copy(
  2561. input: Tensor,
  2562. level: _int,
  2563. *,
  2564. out: Tensor | None = None,
  2565. ) -> Tensor: ...
  2566. def _grid_sampler_2d_cpu_fallback(
  2567. input: Tensor,
  2568. grid: Tensor,
  2569. interpolation_mode: _int,
  2570. padding_mode: _int,
  2571. align_corners: _bool,
  2572. ) -> Tensor: ...
  2573. def _grouped_mm(
  2574. input: Tensor,
  2575. mat2: Tensor,
  2576. offs: Tensor | None = None,
  2577. bias: Tensor | None = None,
  2578. out_dtype: _dtype | None = None,
  2579. ) -> Tensor: ...
  2580. def _has_compatible_shallow_copy_type(
  2581. input: Tensor,
  2582. from_: Tensor,
  2583. ) -> _bool: ...
  2584. def _histogramdd_bin_edges(
  2585. input: Tensor,
  2586. bins: _size,
  2587. *,
  2588. range: Sequence[_float] | None = None,
  2589. weight: Tensor | None = None,
  2590. density: _bool = False,
  2591. ) -> tuple[Tensor, ...]: ...
  2592. def _histogramdd_from_bin_cts(
  2593. input: Tensor,
  2594. bins: _size,
  2595. *,
  2596. range: Sequence[_float] | None = None,
  2597. weight: Tensor | None = None,
  2598. density: _bool = False,
  2599. ) -> Tensor: ...
  2600. def _histogramdd_from_bin_tensors(
  2601. input: Tensor,
  2602. bins: tuple[Tensor, ...] | list[Tensor] | None,
  2603. *,
  2604. weight: Tensor | None = None,
  2605. density: _bool = False,
  2606. ) -> Tensor: ...
  2607. def _index_put_impl_(
  2608. input: Tensor,
  2609. indices: tuple[Tensor, ...] | list[Tensor] | None,
  2610. values: Tensor,
  2611. accumulate: _bool = False,
  2612. unsafe: _bool = False,
  2613. ) -> Tensor: ...
  2614. def _indices_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor: ...
  2615. def _int_mm(
  2616. input: Tensor,
  2617. mat2: Tensor,
  2618. *,
  2619. out: Tensor | None = None,
  2620. ) -> Tensor: ...
  2621. def _is_all_true(input: Tensor) -> Tensor: ...
  2622. def _is_any_true(input: Tensor) -> Tensor: ...
  2623. def _is_functional_tensor(t: Tensor) -> _bool: ...
  2624. def _is_functional_tensor_base(t: Tensor) -> _bool: ...
  2625. def _is_zerotensor(input: Tensor) -> _bool: ...
  2626. def _lazy_clone(input: Tensor) -> Tensor: ...
  2627. def _linalg_check_errors(
  2628. info: Tensor,
  2629. api_name: str,
  2630. *,
  2631. is_matrix: _bool,
  2632. ) -> None: ...
  2633. def _linalg_det(
  2634. A: Tensor,
  2635. *,
  2636. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  2637. ) -> torch.return_types._linalg_det: ...
  2638. def _linalg_eigh(
  2639. A: Tensor,
  2640. UPLO: str = "L",
  2641. compute_v: _bool = True,
  2642. *,
  2643. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  2644. ) -> torch.return_types._linalg_eigh: ...
  2645. def _linalg_slogdet(
  2646. A: Tensor,
  2647. *,
  2648. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  2649. ) -> torch.return_types._linalg_slogdet: ...
  2650. def _linalg_solve_ex(
  2651. A: Tensor,
  2652. B: Tensor,
  2653. *,
  2654. left: _bool = True,
  2655. check_errors: _bool = False,
  2656. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  2657. ) -> torch.return_types._linalg_solve_ex: ...
  2658. def _linalg_svd(
  2659. A: Tensor,
  2660. full_matrices: _bool = False,
  2661. compute_uv: _bool = True,
  2662. *,
  2663. driver: str | None = None,
  2664. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  2665. ) -> torch.return_types._linalg_svd: ...
  2666. def _log_softmax(
  2667. input: Tensor,
  2668. dim: _int,
  2669. half_to_float: _bool,
  2670. *,
  2671. out: Tensor | None = None,
  2672. ) -> Tensor: ...
  2673. def _log_softmax_backward_data(
  2674. grad_output: Tensor,
  2675. output: Tensor,
  2676. dim: _int,
  2677. input_dtype: _dtype,
  2678. *,
  2679. out: Tensor | None = None,
  2680. ) -> Tensor: ...
  2681. def _logcumsumexp(
  2682. input: Tensor,
  2683. dim: _int,
  2684. *,
  2685. out: Tensor | None = None,
  2686. ) -> Tensor: ...
  2687. def _lstm_mps(
  2688. input: Tensor,
  2689. hx: tuple[Tensor, ...] | list[Tensor] | None,
  2690. params: tuple[Tensor, ...] | list[Tensor] | None,
  2691. has_biases: _bool,
  2692. num_layers: _int,
  2693. dropout: _float,
  2694. train: _bool,
  2695. bidirectional: _bool,
  2696. batch_first: _bool,
  2697. ) -> tuple[Tensor, Tensor, Tensor, Tensor, Tensor, Tensor]: ...
  2698. def _lu_with_info(
  2699. input: Tensor,
  2700. pivot: _bool = True,
  2701. check_errors: _bool = True,
  2702. ) -> torch.return_types._lu_with_info: ...
  2703. def _make_dep_token(
  2704. *,
  2705. memory_format: memory_format | None = None,
  2706. dtype: _dtype | None = None,
  2707. layout: _layout | None = None,
  2708. device: DeviceLikeType | None = None,
  2709. pin_memory: _bool | None = False,
  2710. requires_grad: _bool | None = False,
  2711. ) -> Tensor: ...
  2712. def _make_dual(primal: Tensor, tangent: Tensor, level: _int) -> Tensor: ...
  2713. def _make_dual_copy(
  2714. primal: Tensor,
  2715. tangent: Tensor,
  2716. level: _int,
  2717. *,
  2718. out: Tensor | None = None,
  2719. ) -> Tensor: ...
  2720. def _make_per_channel_quantized_tensor(
  2721. input: Tensor,
  2722. scale: Tensor,
  2723. zero_point: Tensor,
  2724. axis: _int,
  2725. ) -> Tensor: ...
  2726. def _make_per_tensor_quantized_tensor(
  2727. input: Tensor,
  2728. scale: _float,
  2729. zero_point: _int,
  2730. ) -> Tensor: ...
  2731. def _masked_scale(input: Tensor, mask: Tensor, scale: _float) -> Tensor: ...
  2732. def _masked_softmax(
  2733. input: Tensor,
  2734. mask: Tensor,
  2735. dim: _int | None = None,
  2736. mask_type: _int | None = None,
  2737. ) -> Tensor: ...
  2738. def _mixed_dtypes_linear(
  2739. input: Tensor,
  2740. weight: Tensor,
  2741. scale: Tensor,
  2742. *,
  2743. bias: Tensor | None = None,
  2744. activation: str | None = None,
  2745. ) -> Tensor: ...
  2746. def _mkldnn_reshape(input: Tensor, shape: _size) -> Tensor: ...
  2747. def _mkldnn_transpose(input: Tensor, dim0: _int, dim1: _int) -> Tensor: ...
  2748. def _mkldnn_transpose_(input: Tensor, dim0: _int, dim1: _int) -> Tensor: ...
  2749. def _mps_convolution(
  2750. input: Tensor,
  2751. weight: Tensor,
  2752. bias: Tensor | None,
  2753. padding: Sequence[_int | SymInt],
  2754. stride: Sequence[_int | SymInt],
  2755. dilation: Sequence[_int | SymInt],
  2756. groups: _int | SymInt,
  2757. ) -> Tensor: ...
  2758. def _mps_convolution_transpose(
  2759. input: Tensor,
  2760. weight: Tensor,
  2761. padding: Sequence[_int | SymInt],
  2762. output_padding: Sequence[_int | SymInt],
  2763. stride: Sequence[_int | SymInt],
  2764. dilation: Sequence[_int | SymInt],
  2765. groups: _int | SymInt,
  2766. ) -> Tensor: ...
  2767. @overload
  2768. def _native_batch_norm_legit(
  2769. input: Tensor,
  2770. weight: Tensor | None,
  2771. bias: Tensor | None,
  2772. running_mean: Tensor,
  2773. running_var: Tensor,
  2774. training: _bool,
  2775. momentum: _float,
  2776. eps: _float,
  2777. *,
  2778. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  2779. ) -> tuple[Tensor, Tensor, Tensor]: ...
  2780. @overload
  2781. def _native_batch_norm_legit(
  2782. input: Tensor,
  2783. weight: Tensor | None,
  2784. bias: Tensor | None,
  2785. training: _bool,
  2786. momentum: _float,
  2787. eps: _float,
  2788. *,
  2789. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  2790. ) -> tuple[Tensor, Tensor, Tensor]: ...
  2791. def _native_batch_norm_legit_no_training(
  2792. input: Tensor,
  2793. weight: Tensor | None,
  2794. bias: Tensor | None,
  2795. running_mean: Tensor,
  2796. running_var: Tensor,
  2797. momentum: _float,
  2798. eps: _float,
  2799. ) -> tuple[Tensor, Tensor, Tensor]: ...
  2800. def _native_multi_head_attention(
  2801. query: Tensor,
  2802. key: Tensor,
  2803. value: Tensor,
  2804. embed_dim: _int,
  2805. num_head: _int,
  2806. qkv_weight: Tensor,
  2807. qkv_bias: Tensor,
  2808. proj_weight: Tensor,
  2809. proj_bias: Tensor,
  2810. mask: Tensor | None = None,
  2811. need_weights: _bool = True,
  2812. average_attn_weights: _bool = True,
  2813. mask_type: _int | None = None,
  2814. ) -> tuple[Tensor, Tensor]: ...
  2815. def _neg_view(input: Tensor) -> Tensor: ...
  2816. def _neg_view_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor: ...
  2817. def _nested_compute_contiguous_strides_offsets(
  2818. nested_size: Tensor,
  2819. ) -> tuple[Tensor, Tensor]: ...
  2820. def _nested_from_padded(
  2821. padded: Tensor,
  2822. cpu_nested_shape_example: Tensor,
  2823. fuse_transform_0213: _bool = False,
  2824. ) -> Tensor: ...
  2825. def _nested_from_padded_and_nested_example(
  2826. padded: Tensor,
  2827. nt_example: Tensor,
  2828. ) -> Tensor: ...
  2829. def _nested_from_padded_tensor(
  2830. padded: Tensor,
  2831. offsets: Tensor,
  2832. dummy: Tensor,
  2833. ragged_idx: _int = 1,
  2834. min_seqlen: Tensor | None = None,
  2835. max_seqlen: Tensor | None = None,
  2836. sum_S: _int | SymInt | None = None,
  2837. ) -> Tensor: ...
  2838. def _nested_get_jagged_dummy(any: Tensor) -> Tensor: ...
  2839. def _nested_get_lengths(input: Tensor) -> Tensor: ...
  2840. def _nested_get_max_seqlen(input: Tensor) -> Tensor: ...
  2841. def _nested_get_min_seqlen(input: Tensor) -> Tensor: ...
  2842. def _nested_get_offsets(input: Tensor) -> Tensor: ...
  2843. def _nested_get_ragged_idx(input: Tensor) -> _int: ...
  2844. def _nested_get_values(input: Tensor) -> Tensor: ...
  2845. def _nested_get_values_copy(
  2846. input: Tensor,
  2847. *,
  2848. out: Tensor | None = None,
  2849. ) -> Tensor: ...
  2850. def _nested_tensor_from_mask(
  2851. t: Tensor,
  2852. mask: Tensor,
  2853. mask_check: _bool = True,
  2854. ) -> Tensor: ...
  2855. def _nested_tensor_from_mask_left_aligned(t: Tensor, mask: Tensor) -> _bool: ...
  2856. def _nested_tensor_from_tensor_list(
  2857. list: tuple[Tensor, ...] | list[Tensor] | None,
  2858. dtype: _dtype | None = None,
  2859. layout: _layout | None = None,
  2860. device: DeviceLikeType | None = None,
  2861. pin_memory: _bool | None = None,
  2862. ) -> Tensor: ...
  2863. def _nested_tensor_softmax_with_shape(
  2864. input: Tensor,
  2865. query: Tensor,
  2866. ) -> Tensor: ...
  2867. def _nested_view_from_buffer(
  2868. input: Tensor,
  2869. nested_size: Tensor,
  2870. nested_strides: Tensor,
  2871. offsets: Tensor,
  2872. ) -> Tensor: ...
  2873. def _nested_view_from_buffer_copy(
  2874. input: Tensor,
  2875. nested_size: Tensor,
  2876. nested_strides: Tensor,
  2877. offsets: Tensor,
  2878. *,
  2879. out: Tensor | None = None,
  2880. ) -> Tensor: ...
  2881. def _nested_view_from_jagged(
  2882. input: Tensor,
  2883. offsets: Tensor,
  2884. dummy: Tensor,
  2885. lengths: Tensor | None = None,
  2886. ragged_idx: _int = 1,
  2887. min_seqlen: Tensor | None = None,
  2888. max_seqlen: Tensor | None = None,
  2889. ) -> Tensor: ...
  2890. def _nested_view_from_jagged_copy(
  2891. input: Tensor,
  2892. offsets: Tensor,
  2893. dummy: Tensor,
  2894. lengths: Tensor | None = None,
  2895. ragged_idx: _int = 1,
  2896. min_seqlen: Tensor | None = None,
  2897. max_seqlen: Tensor | None = None,
  2898. *,
  2899. out: Tensor | None = None,
  2900. ) -> Tensor: ...
  2901. def _nnpack_available() -> _bool: ...
  2902. def _nnpack_spatial_convolution(
  2903. input: Tensor,
  2904. weight: Tensor,
  2905. bias: Tensor | None,
  2906. padding: _int | SymInt | Sequence[_int | SymInt],
  2907. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  2908. ) -> Tensor: ...
  2909. def _pack_padded_sequence(
  2910. input: Tensor,
  2911. lengths: Tensor,
  2912. batch_first: _bool,
  2913. ) -> tuple[Tensor, Tensor]: ...
  2914. def _pad_packed_sequence(
  2915. data: Tensor,
  2916. batch_sizes: Tensor,
  2917. batch_first: _bool,
  2918. padding_value: Number | _complex,
  2919. total_length: _int,
  2920. ) -> tuple[Tensor, Tensor]: ...
  2921. def _pin_memory(
  2922. input: Tensor,
  2923. device: DeviceLikeType | None = None,
  2924. ) -> Tensor: ...
  2925. def _prelu_kernel(input: Tensor, weight: Tensor) -> Tensor: ...
  2926. def _print(s: str) -> None: ...
  2927. def _propagate_xla_data(input: Tensor, output: Tensor) -> None: ...
  2928. def _remove_batch_dim(
  2929. input: Tensor,
  2930. level: _int,
  2931. batch_size: _int | SymInt,
  2932. out_dim: _int,
  2933. ) -> Tensor: ...
  2934. def _reshape_alias_copy(
  2935. input: Tensor,
  2936. size: Sequence[_int | SymInt],
  2937. stride: Sequence[_int | SymInt],
  2938. *,
  2939. out: Tensor | None = None,
  2940. ) -> Tensor: ...
  2941. def _reshape_from_tensor(input: Tensor, shape: Tensor) -> Tensor: ...
  2942. def _resize_output_(
  2943. input: Tensor,
  2944. size: Sequence[_int | SymInt],
  2945. device: DeviceLikeType | None,
  2946. ) -> Tensor: ...
  2947. def _rowwise_prune(
  2948. weight: Tensor,
  2949. mask: Tensor,
  2950. compressed_indices_dtype: _dtype,
  2951. ) -> tuple[Tensor, Tensor]: ...
  2952. def _safe_softmax(
  2953. input: Tensor,
  2954. dim: _int,
  2955. dtype: _dtype | None = None,
  2956. ) -> Tensor: ...
  2957. def _sample_dirichlet(
  2958. input: Tensor,
  2959. generator: Generator | None = None,
  2960. ) -> Tensor: ...
  2961. def _saturate_weight_to_fp16(weight: Tensor) -> Tensor: ...
  2962. def _scaled_dot_product_attention_math(
  2963. query: Tensor,
  2964. key: Tensor,
  2965. value: Tensor,
  2966. attn_mask: Tensor | None = None,
  2967. dropout_p: _float = 0.0,
  2968. is_causal: _bool = False,
  2969. dropout_mask: Tensor | None = None,
  2970. *,
  2971. scale: _float | None = None,
  2972. enable_gqa: _bool = False,
  2973. ) -> tuple[Tensor, Tensor]: ...
  2974. def _scaled_dot_product_attention_math_for_mps(
  2975. query: Tensor,
  2976. key: Tensor,
  2977. value: Tensor,
  2978. attn_mask: Tensor | None = None,
  2979. dropout_p: _float = 0.0,
  2980. is_causal: _bool = False,
  2981. dropout_mask: Tensor | None = None,
  2982. *,
  2983. scale: _float | None = None,
  2984. ) -> tuple[Tensor, Tensor]: ...
  2985. def _scaled_dot_product_cudnn_attention(
  2986. query: Tensor,
  2987. key: Tensor,
  2988. value: Tensor,
  2989. attn_bias: Tensor | None,
  2990. compute_log_sumexp: _bool,
  2991. dropout_p: _float = 0.0,
  2992. is_causal: _bool = False,
  2993. return_debug_mask: _bool = False,
  2994. *,
  2995. scale: _float | None = None,
  2996. ) -> torch.return_types._scaled_dot_product_cudnn_attention: ...
  2997. def _scaled_dot_product_efficient_attention(
  2998. query: Tensor,
  2999. key: Tensor,
  3000. value: Tensor,
  3001. attn_bias: Tensor | None,
  3002. compute_log_sumexp: _bool,
  3003. dropout_p: _float = 0.0,
  3004. is_causal: _bool = False,
  3005. *,
  3006. scale: _float | None = None,
  3007. ) -> torch.return_types._scaled_dot_product_efficient_attention: ...
  3008. @overload
  3009. def _scaled_dot_product_flash_attention(
  3010. query: Tensor,
  3011. key: Tensor,
  3012. value: Tensor,
  3013. q_descale: Tensor | None,
  3014. k_descale: Tensor | None,
  3015. v_descale: Tensor | None,
  3016. dropout_p: _float = 0.0,
  3017. is_causal: _bool = False,
  3018. return_debug_mask: _bool = False,
  3019. *,
  3020. scale: _float | None = None,
  3021. ) -> torch.return_types._scaled_dot_product_flash_attention: ...
  3022. @overload
  3023. def _scaled_dot_product_flash_attention(
  3024. query: Tensor,
  3025. key: Tensor,
  3026. value: Tensor,
  3027. dropout_p: _float = 0.0,
  3028. is_causal: _bool = False,
  3029. return_debug_mask: _bool = False,
  3030. *,
  3031. scale: _float | None = None,
  3032. ) -> torch.return_types._scaled_dot_product_flash_attention: ...
  3033. def _scaled_dot_product_flash_attention_for_cpu(
  3034. query: Tensor,
  3035. key: Tensor,
  3036. value: Tensor,
  3037. dropout_p: _float = 0.0,
  3038. is_causal: _bool = False,
  3039. *,
  3040. attn_mask: Tensor | None = None,
  3041. scale: _float | None = None,
  3042. ) -> torch.return_types._scaled_dot_product_flash_attention_for_cpu: ...
  3043. def _scaled_grouped_mm(
  3044. input: Tensor,
  3045. mat2: Tensor,
  3046. scale_a: Tensor,
  3047. scale_b: Tensor,
  3048. offs: Tensor | None = None,
  3049. bias: Tensor | None = None,
  3050. scale_result: Tensor | None = None,
  3051. out_dtype: _dtype | None = None,
  3052. use_fast_accum: _bool = False,
  3053. ) -> Tensor: ...
  3054. def _scaled_grouped_mm_v2(
  3055. input: Tensor,
  3056. mat2: Tensor,
  3057. scale_a: tuple[Tensor, ...] | list[Tensor] | None,
  3058. recipe_a: _size,
  3059. swizzle_a: _size,
  3060. scale_b: tuple[Tensor, ...] | list[Tensor] | None,
  3061. recipe_b: _size,
  3062. swizzle_b: _size,
  3063. offs: Tensor | None = None,
  3064. bias: Tensor | None = None,
  3065. out_dtype: _dtype | None = None,
  3066. contraction_dim: _size = (),
  3067. use_fast_accum: _bool = False,
  3068. ) -> Tensor: ...
  3069. def _scaled_mm(
  3070. input: Tensor,
  3071. mat2: Tensor,
  3072. scale_a: Tensor,
  3073. scale_b: Tensor,
  3074. bias: Tensor | None = None,
  3075. scale_result: Tensor | None = None,
  3076. out_dtype: _dtype | None = None,
  3077. use_fast_accum: _bool = False,
  3078. *,
  3079. out: Tensor | None = None,
  3080. ) -> Tensor: ...
  3081. def _scaled_mm_v2(
  3082. input: Tensor,
  3083. mat2: Tensor,
  3084. scale_a: tuple[Tensor, ...] | list[Tensor] | None,
  3085. recipe_a: _size,
  3086. swizzle_a: _size,
  3087. scale_b: tuple[Tensor, ...] | list[Tensor] | None,
  3088. recipe_b: _size,
  3089. swizzle_b: _size,
  3090. bias: Tensor | None,
  3091. out_dtype: _dtype | None,
  3092. contraction_dim: _size = (),
  3093. use_fast_accum: _bool = False,
  3094. *,
  3095. out: Tensor | None = None,
  3096. ) -> Tensor: ...
  3097. def _shape_as_tensor(input: Tensor) -> Tensor: ...
  3098. def _sobol_engine_draw(
  3099. quasi: Tensor,
  3100. n: _int,
  3101. sobolstate: Tensor,
  3102. dimension: _int,
  3103. num_generated: _int,
  3104. dtype: _dtype | None,
  3105. ) -> tuple[Tensor, Tensor]: ...
  3106. def _sobol_engine_ff_(
  3107. input: Tensor,
  3108. n: _int,
  3109. sobolstate: Tensor,
  3110. dimension: _int,
  3111. num_generated: _int,
  3112. ) -> Tensor: ...
  3113. def _sobol_engine_initialize_state_(
  3114. input: Tensor,
  3115. dimension: _int,
  3116. ) -> Tensor: ...
  3117. def _sobol_engine_scramble_(
  3118. input: Tensor,
  3119. ltm: Tensor,
  3120. dimension: _int,
  3121. ) -> Tensor: ...
  3122. def _softmax(
  3123. input: Tensor,
  3124. dim: _int,
  3125. half_to_float: _bool,
  3126. *,
  3127. out: Tensor | None = None,
  3128. ) -> Tensor: ...
  3129. def _softmax_backward_data(
  3130. grad_output: Tensor,
  3131. output: Tensor,
  3132. dim: _int,
  3133. input_dtype: _dtype,
  3134. *,
  3135. grad_input: Tensor | None = None,
  3136. ) -> Tensor: ...
  3137. def _sparse_broadcast_to(input: Tensor, size: _size) -> Tensor: ...
  3138. def _sparse_broadcast_to_copy(
  3139. input: Tensor,
  3140. size: _size,
  3141. *,
  3142. out: Tensor | None = None,
  3143. ) -> Tensor: ...
  3144. def _sparse_csr_prod(
  3145. input: Tensor,
  3146. dim: _int | _size,
  3147. keepdim: _bool = False,
  3148. *,
  3149. dtype: _dtype | None = None,
  3150. ) -> Tensor: ...
  3151. def _sparse_csr_sum(
  3152. input: Tensor,
  3153. dim: _int | _size,
  3154. keepdim: _bool = False,
  3155. *,
  3156. dtype: _dtype | None = None,
  3157. ) -> Tensor: ...
  3158. def _sparse_log_softmax_backward_data(
  3159. grad_output: Tensor,
  3160. output: Tensor,
  3161. dim: _int,
  3162. input: Tensor,
  3163. ) -> Tensor: ...
  3164. def _sparse_semi_structured_addmm(
  3165. input: Tensor,
  3166. mat1: Tensor,
  3167. mat1_meta: Tensor,
  3168. mat2: Tensor,
  3169. *,
  3170. alpha: Number | _complex = 1,
  3171. beta: Number | _complex = 1,
  3172. out_dtype: _dtype | None = None,
  3173. ) -> Tensor: ...
  3174. def _sparse_semi_structured_apply(
  3175. input: Tensor,
  3176. thread_masks: Tensor,
  3177. ) -> tuple[Tensor, Tensor]: ...
  3178. def _sparse_semi_structured_apply_dense(
  3179. input: Tensor,
  3180. thread_masks: Tensor,
  3181. ) -> Tensor: ...
  3182. def _sparse_semi_structured_linear(
  3183. input: Tensor,
  3184. weight: Tensor,
  3185. meta: Tensor,
  3186. *,
  3187. bias: Tensor | None = None,
  3188. activation: str | None = None,
  3189. out_dtype: _dtype | None = None,
  3190. ) -> Tensor: ...
  3191. def _sparse_semi_structured_mm(
  3192. mat1: Tensor,
  3193. mat1_meta: Tensor,
  3194. mat2: Tensor,
  3195. *,
  3196. out_dtype: _dtype | None = None,
  3197. ) -> Tensor: ...
  3198. def _sparse_semi_structured_tile(
  3199. input: Tensor,
  3200. algorithm: str = "",
  3201. use_cutlass: _bool = True,
  3202. ) -> tuple[Tensor, Tensor, Tensor, Tensor, Tensor]: ...
  3203. def _sparse_softmax_backward_data(
  3204. grad_output: Tensor,
  3205. output: Tensor,
  3206. dim: _int,
  3207. input: Tensor,
  3208. ) -> Tensor: ...
  3209. def _sparse_sparse_matmul(input: Tensor, other: Tensor) -> Tensor: ...
  3210. @overload
  3211. def _sparse_sum(input: Tensor) -> Tensor: ...
  3212. @overload
  3213. def _sparse_sum(input: Tensor, *, dtype: _dtype) -> Tensor: ...
  3214. @overload
  3215. def _sparse_sum(input: Tensor, dim: _int | _size) -> Tensor: ...
  3216. @overload
  3217. def _sparse_sum(
  3218. input: Tensor,
  3219. dim: _int | _size,
  3220. *,
  3221. dtype: _dtype,
  3222. ) -> Tensor: ...
  3223. def _stack(
  3224. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  3225. dim: _int = 0,
  3226. *,
  3227. out: Tensor | None = None,
  3228. ) -> Tensor: ...
  3229. def _standard_gamma(
  3230. input: Tensor,
  3231. generator: Generator | None = None,
  3232. ) -> Tensor: ...
  3233. def _standard_gamma_grad(input: Tensor, output: Tensor) -> Tensor: ...
  3234. def _sync(t: Tensor) -> None: ...
  3235. @overload
  3236. def _test_autograd_multiple_dispatch(input: Tensor) -> Tensor: ...
  3237. @overload
  3238. def _test_autograd_multiple_dispatch(input: Tensor, b: _bool) -> Tensor: ...
  3239. def _test_autograd_multiple_dispatch_view(input: Tensor) -> Tensor: ...
  3240. def _test_autograd_multiple_dispatch_view_copy(
  3241. input: Tensor,
  3242. *,
  3243. out: Tensor | None = None,
  3244. ) -> Tensor: ...
  3245. def _test_check_tensor(input: Tensor) -> Tensor: ...
  3246. def _test_functorch_fallback(input: Tensor, other: Tensor) -> Tensor: ...
  3247. def _test_parallel_materialize(
  3248. input: Tensor,
  3249. num_parallel: _int,
  3250. skip_first: _bool = False,
  3251. ) -> Tensor: ...
  3252. def _test_serialization_subcmul(
  3253. input: Tensor,
  3254. other: Tensor,
  3255. alpha: Number | _complex = 1,
  3256. ) -> Tensor: ...
  3257. def _to_cpu(
  3258. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  3259. ) -> tuple[Tensor, ...]: ...
  3260. def _to_functional_tensor(t: Tensor) -> Tensor: ...
  3261. def _to_sparse_semi_structured(dense: Tensor) -> tuple[Tensor, Tensor]: ...
  3262. def _transform_bias_rescale_qkv(
  3263. qkv: Tensor,
  3264. qkv_bias: Tensor,
  3265. num_heads: _int,
  3266. ) -> tuple[Tensor, Tensor, Tensor]: ...
  3267. def _transformer_encoder_layer_fwd(
  3268. src: Tensor,
  3269. embed_dim: _int,
  3270. num_heads: _int,
  3271. qkv_weight: Tensor,
  3272. qkv_bias: Tensor,
  3273. proj_weight: Tensor,
  3274. proj_bias: Tensor,
  3275. use_gelu: _bool,
  3276. norm_first: _bool,
  3277. eps: _float,
  3278. norm_weight_1: Tensor,
  3279. norm_bias_1: Tensor,
  3280. norm_weight_2: Tensor,
  3281. norm_bias_2: Tensor,
  3282. ffn_weight_1: Tensor,
  3283. ffn_bias_1: Tensor,
  3284. ffn_weight_2: Tensor,
  3285. ffn_bias_2: Tensor,
  3286. mask: Tensor | None = None,
  3287. mask_type: _int | None = None,
  3288. ) -> Tensor: ...
  3289. def _trilinear(
  3290. i1: Tensor,
  3291. i2: Tensor,
  3292. i3: Tensor,
  3293. expand1: _size,
  3294. expand2: _size,
  3295. expand3: _size,
  3296. sumdim: _size,
  3297. unroll_dim: _int = 1,
  3298. ) -> Tensor: ...
  3299. def _triton_multi_head_attention(
  3300. query: Tensor,
  3301. key: Tensor,
  3302. value: Tensor,
  3303. embed_dim: _int,
  3304. num_head: _int,
  3305. qkv_weight: Tensor,
  3306. qkv_bias: Tensor,
  3307. proj_weight: Tensor,
  3308. proj_bias: Tensor,
  3309. mask: Tensor | None = None,
  3310. ) -> Tensor: ...
  3311. def _triton_scaled_dot_attention(
  3312. q: Tensor,
  3313. k: Tensor,
  3314. v: Tensor,
  3315. dropout_p: _float = 0.0,
  3316. ) -> Tensor: ...
  3317. def _unique(
  3318. input: Tensor,
  3319. sorted: _bool = True,
  3320. return_inverse: _bool = False,
  3321. ) -> tuple[Tensor, Tensor]: ...
  3322. def _unique2(
  3323. input: Tensor,
  3324. sorted: _bool = True,
  3325. return_inverse: _bool = False,
  3326. return_counts: _bool = False,
  3327. ) -> tuple[Tensor, Tensor, Tensor]: ...
  3328. def _unpack_dual(
  3329. dual: Tensor,
  3330. level: _int,
  3331. ) -> torch.return_types._unpack_dual: ...
  3332. def _unsafe_index(
  3333. input: Tensor,
  3334. indices: tuple[Tensor, ...] | list[Tensor] | None,
  3335. ) -> Tensor: ...
  3336. def _unsafe_index_put(
  3337. input: Tensor,
  3338. indices: tuple[Tensor, ...] | list[Tensor] | None,
  3339. values: Tensor,
  3340. accumulate: _bool = False,
  3341. ) -> Tensor: ...
  3342. def _unsafe_masked_index(
  3343. input: Tensor,
  3344. mask: Tensor,
  3345. indices: tuple[Tensor, ...] | list[Tensor] | None,
  3346. fill: Number | _complex,
  3347. ) -> Tensor: ...
  3348. def _unsafe_masked_index_put_accumulate(
  3349. input: Tensor,
  3350. mask: Tensor,
  3351. indices: tuple[Tensor, ...] | list[Tensor] | None,
  3352. values: Tensor,
  3353. ) -> Tensor: ...
  3354. @overload
  3355. def _use_cudnn_ctc_loss(
  3356. log_probs: Tensor,
  3357. targets: Tensor,
  3358. input_lengths: Tensor,
  3359. target_lengths: Tensor,
  3360. blank: _int,
  3361. ) -> _bool: ...
  3362. @overload
  3363. def _use_cudnn_ctc_loss(
  3364. log_probs: Tensor,
  3365. targets: Tensor,
  3366. input_lengths: _size,
  3367. target_lengths: _size,
  3368. blank: _int,
  3369. ) -> _bool: ...
  3370. def _use_cudnn_rnn_flatten_weight() -> _bool: ...
  3371. @overload
  3372. def _use_miopen_ctc_loss(
  3373. log_probs: Tensor,
  3374. targets: Tensor,
  3375. input_lengths: Tensor,
  3376. target_lengths: Tensor,
  3377. blank: _int,
  3378. ) -> _bool: ...
  3379. @overload
  3380. def _use_miopen_ctc_loss(
  3381. log_probs: Tensor,
  3382. targets: Tensor,
  3383. input_lengths: _size,
  3384. target_lengths: _size,
  3385. blank: _int,
  3386. ) -> _bool: ...
  3387. def _validate_compressed_sparse_indices(
  3388. is_crow: _bool,
  3389. compressed_idx: Tensor,
  3390. plain_idx: Tensor,
  3391. cdim: _int,
  3392. dim: _int,
  3393. nnz: _int,
  3394. ) -> None: ...
  3395. def _validate_sparse_bsc_tensor_args(
  3396. ccol_indices: Tensor,
  3397. row_indices: Tensor,
  3398. values: Tensor,
  3399. size: _size,
  3400. check_pinning: _bool | None = None,
  3401. ) -> None: ...
  3402. def _validate_sparse_bsr_tensor_args(
  3403. crow_indices: Tensor,
  3404. col_indices: Tensor,
  3405. values: Tensor,
  3406. size: _size,
  3407. check_pinning: _bool | None = None,
  3408. ) -> None: ...
  3409. def _validate_sparse_compressed_tensor_args(
  3410. compressed_indices: Tensor,
  3411. plain_indices: Tensor,
  3412. values: Tensor,
  3413. size: _size,
  3414. layout: _layout,
  3415. check_pinning: _bool | None = None,
  3416. ) -> None: ...
  3417. def _validate_sparse_coo_tensor_args(
  3418. indices: Tensor,
  3419. values: Tensor,
  3420. size: _size,
  3421. is_coalesced: _bool | None = None,
  3422. check_pinning: _bool | None = None,
  3423. ) -> None: ...
  3424. def _validate_sparse_csc_tensor_args(
  3425. ccol_indices: Tensor,
  3426. row_indices: Tensor,
  3427. values: Tensor,
  3428. size: _size,
  3429. check_pinning: _bool | None = None,
  3430. ) -> None: ...
  3431. def _validate_sparse_csr_tensor_args(
  3432. crow_indices: Tensor,
  3433. col_indices: Tensor,
  3434. values: Tensor,
  3435. size: _size,
  3436. check_pinning: _bool | None = None,
  3437. ) -> None: ...
  3438. def _values_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor: ...
  3439. def _weight_int4pack_mm(
  3440. input: Tensor,
  3441. mat2: Tensor,
  3442. qGroupSize: _int,
  3443. qScaleAndZeros: Tensor,
  3444. ) -> Tensor: ...
  3445. def _weight_int4pack_mm_for_cpu(
  3446. input: Tensor,
  3447. mat2: Tensor,
  3448. qGroupSize: _int,
  3449. qScaleAndZeros: Tensor,
  3450. ) -> Tensor: ...
  3451. def _weight_int4pack_mm_with_scales_and_zeros(
  3452. input: Tensor,
  3453. mat2: Tensor,
  3454. qGroupSize: _int,
  3455. qScale: Tensor,
  3456. qZeros: Tensor,
  3457. ) -> Tensor: ...
  3458. def _weight_int8pack_mm(
  3459. input: Tensor,
  3460. mat2: Tensor,
  3461. scales: Tensor,
  3462. ) -> Tensor: ...
  3463. def _weight_norm(v: Tensor, g: Tensor, dim: _int = 0) -> Tensor: ...
  3464. def _weight_norm_interface(
  3465. v: Tensor,
  3466. g: Tensor,
  3467. dim: _int = 0,
  3468. ) -> tuple[Tensor, Tensor]: ...
  3469. def _wrapped_linear_prepack(
  3470. weight: Tensor,
  3471. weight_scale: Tensor,
  3472. weight_zero_point: Tensor,
  3473. bias: Tensor,
  3474. ) -> Tensor: ...
  3475. def _wrapped_quantized_linear_prepacked(
  3476. input: Tensor,
  3477. input_scale: Tensor,
  3478. input_zero_point: Tensor,
  3479. packed_weight: Tensor,
  3480. output_scale: Tensor,
  3481. output_zero_point: Tensor,
  3482. out_channel: _int,
  3483. ) -> Tensor: ...
  3484. def abs(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  3485. r"""
  3486. abs(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  3487. Computes the absolute value of each element in :attr:`input`.
  3488. .. math::
  3489. \text{out}_{i} = |\text{input}_{i}|
  3490. Args:
  3491. input (Tensor): the input tensor.
  3492. Keyword args:
  3493. out (Tensor, optional): the output tensor.
  3494. Example::
  3495. >>> torch.abs(torch.tensor([-1, -2, 3]))
  3496. tensor([ 1, 2, 3])
  3497. """
  3498. def abs_(input: Tensor) -> Tensor: ...
  3499. def absolute(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  3500. r"""
  3501. absolute(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  3502. Alias for :func:`torch.abs`
  3503. """
  3504. def acos(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  3505. r"""
  3506. acos(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  3507. Returns a new tensor with the arccosine (in radians) of each element in :attr:`input`.
  3508. .. math::
  3509. \text{out}_{i} = \cos^{-1}(\text{input}_{i})
  3510. Args:
  3511. input (Tensor): the input tensor.
  3512. Keyword args:
  3513. out (Tensor, optional): the output tensor.
  3514. Example::
  3515. >>> a = torch.randn(4)
  3516. >>> a
  3517. tensor([ 0.3348, -0.5889, 0.2005, -0.1584])
  3518. >>> torch.acos(a)
  3519. tensor([ 1.2294, 2.2004, 1.3690, 1.7298])
  3520. """
  3521. def acos_(input: Tensor) -> Tensor: ...
  3522. def acosh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  3523. r"""
  3524. acosh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  3525. Returns a new tensor with the inverse hyperbolic cosine of the elements of :attr:`input`.
  3526. .. math::
  3527. \text{out}_{i} = \cosh^{-1}(\text{input}_{i})
  3528. Note:
  3529. The domain of the inverse hyperbolic cosine is `[1, inf)` and values outside this range
  3530. will be mapped to ``NaN``, except for `+ INF` for which the output is mapped to `+ INF`.
  3531. Args:
  3532. input (Tensor): the input tensor.
  3533. Keyword arguments:
  3534. out (Tensor, optional): the output tensor.
  3535. Example::
  3536. >>> a = torch.randn(4).uniform_(1, 2)
  3537. >>> a
  3538. tensor([ 1.3192, 1.9915, 1.9674, 1.7151 ])
  3539. >>> torch.acosh(a)
  3540. tensor([ 0.7791, 1.3120, 1.2979, 1.1341 ])
  3541. """
  3542. def acosh_(input: Tensor) -> Tensor: ...
  3543. def adaptive_avg_pool1d(input: Tensor, output_size: _int | _size) -> Tensor: ...
  3544. def adaptive_max_pool1d(
  3545. input: Tensor,
  3546. output_size: _int | _size,
  3547. ) -> tuple[Tensor, Tensor]: ...
  3548. @overload
  3549. def add(
  3550. input: Tensor | Number | _complex,
  3551. other: Tensor | Number | _complex,
  3552. *,
  3553. alpha: Number | _complex | None = 1,
  3554. out: Tensor | None = None,
  3555. ) -> Tensor:
  3556. r"""
  3557. add(input, other, *, alpha=1, out=None) -> Tensor
  3558. Adds :attr:`other`, scaled by :attr:`alpha`, to :attr:`input`.
  3559. .. math::
  3560. \text{{out}}_i = \text{{input}}_i + \text{{alpha}} \times \text{{other}}_i
  3561. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  3562. :ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
  3563. Args:
  3564. input (Tensor): the input tensor.
  3565. other (Tensor or Number): the tensor or number to add to :attr:`input`.
  3566. Keyword arguments:
  3567. alpha (Number): the multiplier for :attr:`other`.
  3568. out (Tensor, optional): the output tensor.
  3569. Examples::
  3570. >>> a = torch.randn(4)
  3571. >>> a
  3572. tensor([ 0.0202, 1.0985, 1.3506, -0.6056])
  3573. >>> torch.add(a, 20)
  3574. tensor([ 20.0202, 21.0985, 21.3506, 19.3944])
  3575. >>> b = torch.randn(4)
  3576. >>> b
  3577. tensor([-0.9732, -0.3497, 0.6245, 0.4022])
  3578. >>> c = torch.randn(4, 1)
  3579. >>> c
  3580. tensor([[ 0.3743],
  3581. [-1.7724],
  3582. [-0.5811],
  3583. [-0.8017]])
  3584. >>> torch.add(b, c, alpha=10)
  3585. tensor([[ 2.7695, 3.3930, 4.3672, 4.1450],
  3586. [-18.6971, -18.0736, -17.0994, -17.3216],
  3587. [ -6.7845, -6.1610, -5.1868, -5.4090],
  3588. [ -8.9902, -8.3667, -7.3925, -7.6147]])
  3589. """
  3590. @overload
  3591. def add(self: Tensor, alpha: Number | _complex, other: Tensor) -> Tensor:
  3592. r"""
  3593. add(input, other, *, alpha=1, out=None) -> Tensor
  3594. Adds :attr:`other`, scaled by :attr:`alpha`, to :attr:`input`.
  3595. .. math::
  3596. \text{{out}}_i = \text{{input}}_i + \text{{alpha}} \times \text{{other}}_i
  3597. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  3598. :ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
  3599. Args:
  3600. input (Tensor): the input tensor.
  3601. other (Tensor or Number): the tensor or number to add to :attr:`input`.
  3602. Keyword arguments:
  3603. alpha (Number): the multiplier for :attr:`other`.
  3604. out (Tensor, optional): the output tensor.
  3605. Examples::
  3606. >>> a = torch.randn(4)
  3607. >>> a
  3608. tensor([ 0.0202, 1.0985, 1.3506, -0.6056])
  3609. >>> torch.add(a, 20)
  3610. tensor([ 20.0202, 21.0985, 21.3506, 19.3944])
  3611. >>> b = torch.randn(4)
  3612. >>> b
  3613. tensor([-0.9732, -0.3497, 0.6245, 0.4022])
  3614. >>> c = torch.randn(4, 1)
  3615. >>> c
  3616. tensor([[ 0.3743],
  3617. [-1.7724],
  3618. [-0.5811],
  3619. [-0.8017]])
  3620. >>> torch.add(b, c, alpha=10)
  3621. tensor([[ 2.7695, 3.3930, 4.3672, 4.1450],
  3622. [-18.6971, -18.0736, -17.0994, -17.3216],
  3623. [ -6.7845, -6.1610, -5.1868, -5.4090],
  3624. [ -8.9902, -8.3667, -7.3925, -7.6147]])
  3625. """
  3626. @overload
  3627. def add(
  3628. self: Tensor,
  3629. alpha: Number | _complex,
  3630. other: Tensor,
  3631. *,
  3632. out: Tensor,
  3633. ) -> Tensor:
  3634. r"""
  3635. add(input, other, *, alpha=1, out=None) -> Tensor
  3636. Adds :attr:`other`, scaled by :attr:`alpha`, to :attr:`input`.
  3637. .. math::
  3638. \text{{out}}_i = \text{{input}}_i + \text{{alpha}} \times \text{{other}}_i
  3639. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  3640. :ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
  3641. Args:
  3642. input (Tensor): the input tensor.
  3643. other (Tensor or Number): the tensor or number to add to :attr:`input`.
  3644. Keyword arguments:
  3645. alpha (Number): the multiplier for :attr:`other`.
  3646. out (Tensor, optional): the output tensor.
  3647. Examples::
  3648. >>> a = torch.randn(4)
  3649. >>> a
  3650. tensor([ 0.0202, 1.0985, 1.3506, -0.6056])
  3651. >>> torch.add(a, 20)
  3652. tensor([ 20.0202, 21.0985, 21.3506, 19.3944])
  3653. >>> b = torch.randn(4)
  3654. >>> b
  3655. tensor([-0.9732, -0.3497, 0.6245, 0.4022])
  3656. >>> c = torch.randn(4, 1)
  3657. >>> c
  3658. tensor([[ 0.3743],
  3659. [-1.7724],
  3660. [-0.5811],
  3661. [-0.8017]])
  3662. >>> torch.add(b, c, alpha=10)
  3663. tensor([[ 2.7695, 3.3930, 4.3672, 4.1450],
  3664. [-18.6971, -18.0736, -17.0994, -17.3216],
  3665. [ -6.7845, -6.1610, -5.1868, -5.4090],
  3666. [ -8.9902, -8.3667, -7.3925, -7.6147]])
  3667. """
  3668. @overload
  3669. def addbmm(
  3670. beta: Number | _complex,
  3671. self: Tensor,
  3672. alpha: Number | _complex,
  3673. batch1: Tensor,
  3674. batch2: Tensor,
  3675. ) -> Tensor:
  3676. r"""
  3677. addbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None) -> Tensor
  3678. Performs a batch matrix-matrix product of matrices stored
  3679. in :attr:`batch1` and :attr:`batch2`,
  3680. with a reduced add step (all matrix multiplications get accumulated
  3681. along the first dimension).
  3682. :attr:`input` is added to the final result.
  3683. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the
  3684. same number of matrices.
  3685. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  3686. :math:`(b \times m \times p)` tensor, :attr:`input` must be
  3687. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  3688. and :attr:`out` will be a :math:`(n \times p)` tensor.
  3689. .. math::
  3690. out = \beta\ \text{input} + \alpha\ (\sum_{i=0}^{b-1} \text{batch1}_i \mathbin{@} \text{batch2}_i)
  3691. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  3692. it will not be propagated.
  3693. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and :attr:`alpha`
  3694. must be real numbers, otherwise they should be integers.
  3695. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  3696. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  3697. Args:
  3698. input (Tensor): matrix to be added
  3699. batch1 (Tensor): the first batch of matrices to be multiplied
  3700. batch2 (Tensor): the second batch of matrices to be multiplied
  3701. Keyword args:
  3702. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  3703. alpha (Number, optional): multiplier for `batch1 @ batch2` (:math:`\alpha`)
  3704. out (Tensor, optional): the output tensor.
  3705. Example::
  3706. >>> M = torch.randn(3, 5)
  3707. >>> batch1 = torch.randn(10, 3, 4)
  3708. >>> batch2 = torch.randn(10, 4, 5)
  3709. >>> torch.addbmm(M, batch1, batch2)
  3710. tensor([[ 6.6311, 0.0503, 6.9768, -12.0362, -2.1653],
  3711. [ -4.8185, -1.4255, -6.6760, 8.9453, 2.5743],
  3712. [ -3.8202, 4.3691, 1.0943, -1.1109, 5.4730]])
  3713. """
  3714. @overload
  3715. def addbmm(
  3716. beta: Number | _complex,
  3717. self: Tensor,
  3718. alpha: Number | _complex,
  3719. batch1: Tensor,
  3720. batch2: Tensor,
  3721. *,
  3722. out: Tensor,
  3723. ) -> Tensor:
  3724. r"""
  3725. addbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None) -> Tensor
  3726. Performs a batch matrix-matrix product of matrices stored
  3727. in :attr:`batch1` and :attr:`batch2`,
  3728. with a reduced add step (all matrix multiplications get accumulated
  3729. along the first dimension).
  3730. :attr:`input` is added to the final result.
  3731. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the
  3732. same number of matrices.
  3733. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  3734. :math:`(b \times m \times p)` tensor, :attr:`input` must be
  3735. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  3736. and :attr:`out` will be a :math:`(n \times p)` tensor.
  3737. .. math::
  3738. out = \beta\ \text{input} + \alpha\ (\sum_{i=0}^{b-1} \text{batch1}_i \mathbin{@} \text{batch2}_i)
  3739. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  3740. it will not be propagated.
  3741. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and :attr:`alpha`
  3742. must be real numbers, otherwise they should be integers.
  3743. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  3744. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  3745. Args:
  3746. input (Tensor): matrix to be added
  3747. batch1 (Tensor): the first batch of matrices to be multiplied
  3748. batch2 (Tensor): the second batch of matrices to be multiplied
  3749. Keyword args:
  3750. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  3751. alpha (Number, optional): multiplier for `batch1 @ batch2` (:math:`\alpha`)
  3752. out (Tensor, optional): the output tensor.
  3753. Example::
  3754. >>> M = torch.randn(3, 5)
  3755. >>> batch1 = torch.randn(10, 3, 4)
  3756. >>> batch2 = torch.randn(10, 4, 5)
  3757. >>> torch.addbmm(M, batch1, batch2)
  3758. tensor([[ 6.6311, 0.0503, 6.9768, -12.0362, -2.1653],
  3759. [ -4.8185, -1.4255, -6.6760, 8.9453, 2.5743],
  3760. [ -3.8202, 4.3691, 1.0943, -1.1109, 5.4730]])
  3761. """
  3762. @overload
  3763. def addbmm(
  3764. input: Tensor,
  3765. batch1: Tensor,
  3766. batch2: Tensor,
  3767. *,
  3768. beta: Number | _complex = 1,
  3769. alpha: Number | _complex = 1,
  3770. out: Tensor | None = None,
  3771. ) -> Tensor:
  3772. r"""
  3773. addbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None) -> Tensor
  3774. Performs a batch matrix-matrix product of matrices stored
  3775. in :attr:`batch1` and :attr:`batch2`,
  3776. with a reduced add step (all matrix multiplications get accumulated
  3777. along the first dimension).
  3778. :attr:`input` is added to the final result.
  3779. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the
  3780. same number of matrices.
  3781. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  3782. :math:`(b \times m \times p)` tensor, :attr:`input` must be
  3783. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  3784. and :attr:`out` will be a :math:`(n \times p)` tensor.
  3785. .. math::
  3786. out = \beta\ \text{input} + \alpha\ (\sum_{i=0}^{b-1} \text{batch1}_i \mathbin{@} \text{batch2}_i)
  3787. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  3788. it will not be propagated.
  3789. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and :attr:`alpha`
  3790. must be real numbers, otherwise they should be integers.
  3791. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  3792. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  3793. Args:
  3794. input (Tensor): matrix to be added
  3795. batch1 (Tensor): the first batch of matrices to be multiplied
  3796. batch2 (Tensor): the second batch of matrices to be multiplied
  3797. Keyword args:
  3798. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  3799. alpha (Number, optional): multiplier for `batch1 @ batch2` (:math:`\alpha`)
  3800. out (Tensor, optional): the output tensor.
  3801. Example::
  3802. >>> M = torch.randn(3, 5)
  3803. >>> batch1 = torch.randn(10, 3, 4)
  3804. >>> batch2 = torch.randn(10, 4, 5)
  3805. >>> torch.addbmm(M, batch1, batch2)
  3806. tensor([[ 6.6311, 0.0503, 6.9768, -12.0362, -2.1653],
  3807. [ -4.8185, -1.4255, -6.6760, 8.9453, 2.5743],
  3808. [ -3.8202, 4.3691, 1.0943, -1.1109, 5.4730]])
  3809. """
  3810. @overload
  3811. def addbmm(
  3812. beta: Number | _complex,
  3813. self: Tensor,
  3814. batch1: Tensor,
  3815. batch2: Tensor,
  3816. ) -> Tensor:
  3817. r"""
  3818. addbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None) -> Tensor
  3819. Performs a batch matrix-matrix product of matrices stored
  3820. in :attr:`batch1` and :attr:`batch2`,
  3821. with a reduced add step (all matrix multiplications get accumulated
  3822. along the first dimension).
  3823. :attr:`input` is added to the final result.
  3824. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the
  3825. same number of matrices.
  3826. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  3827. :math:`(b \times m \times p)` tensor, :attr:`input` must be
  3828. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  3829. and :attr:`out` will be a :math:`(n \times p)` tensor.
  3830. .. math::
  3831. out = \beta\ \text{input} + \alpha\ (\sum_{i=0}^{b-1} \text{batch1}_i \mathbin{@} \text{batch2}_i)
  3832. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  3833. it will not be propagated.
  3834. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and :attr:`alpha`
  3835. must be real numbers, otherwise they should be integers.
  3836. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  3837. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  3838. Args:
  3839. input (Tensor): matrix to be added
  3840. batch1 (Tensor): the first batch of matrices to be multiplied
  3841. batch2 (Tensor): the second batch of matrices to be multiplied
  3842. Keyword args:
  3843. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  3844. alpha (Number, optional): multiplier for `batch1 @ batch2` (:math:`\alpha`)
  3845. out (Tensor, optional): the output tensor.
  3846. Example::
  3847. >>> M = torch.randn(3, 5)
  3848. >>> batch1 = torch.randn(10, 3, 4)
  3849. >>> batch2 = torch.randn(10, 4, 5)
  3850. >>> torch.addbmm(M, batch1, batch2)
  3851. tensor([[ 6.6311, 0.0503, 6.9768, -12.0362, -2.1653],
  3852. [ -4.8185, -1.4255, -6.6760, 8.9453, 2.5743],
  3853. [ -3.8202, 4.3691, 1.0943, -1.1109, 5.4730]])
  3854. """
  3855. @overload
  3856. def addbmm(
  3857. beta: Number | _complex,
  3858. self: Tensor,
  3859. batch1: Tensor,
  3860. batch2: Tensor,
  3861. *,
  3862. out: Tensor,
  3863. ) -> Tensor:
  3864. r"""
  3865. addbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None) -> Tensor
  3866. Performs a batch matrix-matrix product of matrices stored
  3867. in :attr:`batch1` and :attr:`batch2`,
  3868. with a reduced add step (all matrix multiplications get accumulated
  3869. along the first dimension).
  3870. :attr:`input` is added to the final result.
  3871. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the
  3872. same number of matrices.
  3873. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  3874. :math:`(b \times m \times p)` tensor, :attr:`input` must be
  3875. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  3876. and :attr:`out` will be a :math:`(n \times p)` tensor.
  3877. .. math::
  3878. out = \beta\ \text{input} + \alpha\ (\sum_{i=0}^{b-1} \text{batch1}_i \mathbin{@} \text{batch2}_i)
  3879. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  3880. it will not be propagated.
  3881. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and :attr:`alpha`
  3882. must be real numbers, otherwise they should be integers.
  3883. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  3884. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  3885. Args:
  3886. input (Tensor): matrix to be added
  3887. batch1 (Tensor): the first batch of matrices to be multiplied
  3888. batch2 (Tensor): the second batch of matrices to be multiplied
  3889. Keyword args:
  3890. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  3891. alpha (Number, optional): multiplier for `batch1 @ batch2` (:math:`\alpha`)
  3892. out (Tensor, optional): the output tensor.
  3893. Example::
  3894. >>> M = torch.randn(3, 5)
  3895. >>> batch1 = torch.randn(10, 3, 4)
  3896. >>> batch2 = torch.randn(10, 4, 5)
  3897. >>> torch.addbmm(M, batch1, batch2)
  3898. tensor([[ 6.6311, 0.0503, 6.9768, -12.0362, -2.1653],
  3899. [ -4.8185, -1.4255, -6.6760, 8.9453, 2.5743],
  3900. [ -3.8202, 4.3691, 1.0943, -1.1109, 5.4730]])
  3901. """
  3902. @overload
  3903. def addcdiv(
  3904. self: Tensor,
  3905. value: Number | _complex,
  3906. tensor1: Tensor,
  3907. tensor2: Tensor,
  3908. ) -> Tensor:
  3909. r"""
  3910. addcdiv(input, tensor1, tensor2, *, value=1, out=None) -> Tensor
  3911. Performs the element-wise division of :attr:`tensor1` by :attr:`tensor2`,
  3912. multiplies the result by the scalar :attr:`value` and adds it to :attr:`input`.
  3913. .. warning::
  3914. Integer division with addcdiv is no longer supported, and in a future
  3915. release addcdiv will perform a true division of tensor1 and tensor2.
  3916. The historic addcdiv behavior can be implemented as
  3917. (input + value * torch.trunc(tensor1 / tensor2)).to(input.dtype)
  3918. for integer inputs and as (input + value * tensor1 / tensor2) for float inputs.
  3919. The future addcdiv behavior is just the latter implementation:
  3920. (input + value * tensor1 / tensor2), for all dtypes.
  3921. .. math::
  3922. \text{out}_i = \text{input}_i + \text{value} \times \frac{\text{tensor1}_i}{\text{tensor2}_i}
  3923. The shapes of :attr:`input`, :attr:`tensor1`, and :attr:`tensor2` must be
  3924. :ref:`broadcastable <broadcasting-semantics>`.
  3925. For inputs of type `FloatTensor` or `DoubleTensor`, :attr:`value` must be
  3926. a real number, otherwise an integer.
  3927. Args:
  3928. input (Tensor): the tensor to be added
  3929. tensor1 (Tensor): the numerator tensor
  3930. tensor2 (Tensor): the denominator tensor
  3931. Keyword args:
  3932. value (Number, optional): multiplier for :math:`\text{tensor1} / \text{tensor2}`
  3933. out (Tensor, optional): the output tensor.
  3934. Example::
  3935. >>> t = torch.randn(1, 3)
  3936. >>> t1 = torch.randn(3, 1)
  3937. >>> t2 = torch.randn(1, 3)
  3938. >>> torch.addcdiv(t, t1, t2, value=0.1)
  3939. tensor([[-0.2312, -3.6496, 0.1312],
  3940. [-1.0428, 3.4292, -0.1030],
  3941. [-0.5369, -0.9829, 0.0430]])
  3942. """
  3943. @overload
  3944. def addcdiv(
  3945. self: Tensor,
  3946. value: Number | _complex,
  3947. tensor1: Tensor,
  3948. tensor2: Tensor,
  3949. *,
  3950. out: Tensor,
  3951. ) -> Tensor:
  3952. r"""
  3953. addcdiv(input, tensor1, tensor2, *, value=1, out=None) -> Tensor
  3954. Performs the element-wise division of :attr:`tensor1` by :attr:`tensor2`,
  3955. multiplies the result by the scalar :attr:`value` and adds it to :attr:`input`.
  3956. .. warning::
  3957. Integer division with addcdiv is no longer supported, and in a future
  3958. release addcdiv will perform a true division of tensor1 and tensor2.
  3959. The historic addcdiv behavior can be implemented as
  3960. (input + value * torch.trunc(tensor1 / tensor2)).to(input.dtype)
  3961. for integer inputs and as (input + value * tensor1 / tensor2) for float inputs.
  3962. The future addcdiv behavior is just the latter implementation:
  3963. (input + value * tensor1 / tensor2), for all dtypes.
  3964. .. math::
  3965. \text{out}_i = \text{input}_i + \text{value} \times \frac{\text{tensor1}_i}{\text{tensor2}_i}
  3966. The shapes of :attr:`input`, :attr:`tensor1`, and :attr:`tensor2` must be
  3967. :ref:`broadcastable <broadcasting-semantics>`.
  3968. For inputs of type `FloatTensor` or `DoubleTensor`, :attr:`value` must be
  3969. a real number, otherwise an integer.
  3970. Args:
  3971. input (Tensor): the tensor to be added
  3972. tensor1 (Tensor): the numerator tensor
  3973. tensor2 (Tensor): the denominator tensor
  3974. Keyword args:
  3975. value (Number, optional): multiplier for :math:`\text{tensor1} / \text{tensor2}`
  3976. out (Tensor, optional): the output tensor.
  3977. Example::
  3978. >>> t = torch.randn(1, 3)
  3979. >>> t1 = torch.randn(3, 1)
  3980. >>> t2 = torch.randn(1, 3)
  3981. >>> torch.addcdiv(t, t1, t2, value=0.1)
  3982. tensor([[-0.2312, -3.6496, 0.1312],
  3983. [-1.0428, 3.4292, -0.1030],
  3984. [-0.5369, -0.9829, 0.0430]])
  3985. """
  3986. @overload
  3987. def addcdiv(
  3988. input: Tensor,
  3989. tensor1: Tensor,
  3990. tensor2: Tensor,
  3991. *,
  3992. value: Number | _complex = 1,
  3993. out: Tensor | None = None,
  3994. ) -> Tensor:
  3995. r"""
  3996. addcdiv(input, tensor1, tensor2, *, value=1, out=None) -> Tensor
  3997. Performs the element-wise division of :attr:`tensor1` by :attr:`tensor2`,
  3998. multiplies the result by the scalar :attr:`value` and adds it to :attr:`input`.
  3999. .. warning::
  4000. Integer division with addcdiv is no longer supported, and in a future
  4001. release addcdiv will perform a true division of tensor1 and tensor2.
  4002. The historic addcdiv behavior can be implemented as
  4003. (input + value * torch.trunc(tensor1 / tensor2)).to(input.dtype)
  4004. for integer inputs and as (input + value * tensor1 / tensor2) for float inputs.
  4005. The future addcdiv behavior is just the latter implementation:
  4006. (input + value * tensor1 / tensor2), for all dtypes.
  4007. .. math::
  4008. \text{out}_i = \text{input}_i + \text{value} \times \frac{\text{tensor1}_i}{\text{tensor2}_i}
  4009. The shapes of :attr:`input`, :attr:`tensor1`, and :attr:`tensor2` must be
  4010. :ref:`broadcastable <broadcasting-semantics>`.
  4011. For inputs of type `FloatTensor` or `DoubleTensor`, :attr:`value` must be
  4012. a real number, otherwise an integer.
  4013. Args:
  4014. input (Tensor): the tensor to be added
  4015. tensor1 (Tensor): the numerator tensor
  4016. tensor2 (Tensor): the denominator tensor
  4017. Keyword args:
  4018. value (Number, optional): multiplier for :math:`\text{tensor1} / \text{tensor2}`
  4019. out (Tensor, optional): the output tensor.
  4020. Example::
  4021. >>> t = torch.randn(1, 3)
  4022. >>> t1 = torch.randn(3, 1)
  4023. >>> t2 = torch.randn(1, 3)
  4024. >>> torch.addcdiv(t, t1, t2, value=0.1)
  4025. tensor([[-0.2312, -3.6496, 0.1312],
  4026. [-1.0428, 3.4292, -0.1030],
  4027. [-0.5369, -0.9829, 0.0430]])
  4028. """
  4029. @overload
  4030. def addcmul(
  4031. self: Tensor,
  4032. value: Number | _complex,
  4033. tensor1: Tensor,
  4034. tensor2: Tensor,
  4035. ) -> Tensor:
  4036. r"""
  4037. addcmul(input, tensor1, tensor2, *, value=1, out=None) -> Tensor
  4038. Performs the element-wise multiplication of :attr:`tensor1`
  4039. by :attr:`tensor2`, multiplies the result by the scalar :attr:`value`
  4040. and adds it to :attr:`input`.
  4041. .. math::
  4042. \text{out}_i = \text{input}_i + \text{value} \times \text{tensor1}_i \times \text{tensor2}_i
  4043. The shapes of :attr:`tensor`, :attr:`tensor1`, and :attr:`tensor2` must be
  4044. :ref:`broadcastable <broadcasting-semantics>`.
  4045. For inputs of type `FloatTensor` or `DoubleTensor`, :attr:`value` must be
  4046. a real number, otherwise an integer.
  4047. Args:
  4048. input (Tensor): the tensor to be added
  4049. tensor1 (Tensor): the tensor to be multiplied
  4050. tensor2 (Tensor): the tensor to be multiplied
  4051. Keyword args:
  4052. value (Number, optional): multiplier for :math:`tensor1 .* tensor2`
  4053. out (Tensor, optional): the output tensor.
  4054. Example::
  4055. >>> t = torch.randn(1, 3)
  4056. >>> t1 = torch.randn(3, 1)
  4057. >>> t2 = torch.randn(1, 3)
  4058. >>> torch.addcmul(t, t1, t2, value=0.1)
  4059. tensor([[-0.8635, -0.6391, 1.6174],
  4060. [-0.7617, -0.5879, 1.7388],
  4061. [-0.8353, -0.6249, 1.6511]])
  4062. """
  4063. @overload
  4064. def addcmul(
  4065. self: Tensor,
  4066. value: Number | _complex,
  4067. tensor1: Tensor,
  4068. tensor2: Tensor,
  4069. *,
  4070. out: Tensor,
  4071. ) -> Tensor:
  4072. r"""
  4073. addcmul(input, tensor1, tensor2, *, value=1, out=None) -> Tensor
  4074. Performs the element-wise multiplication of :attr:`tensor1`
  4075. by :attr:`tensor2`, multiplies the result by the scalar :attr:`value`
  4076. and adds it to :attr:`input`.
  4077. .. math::
  4078. \text{out}_i = \text{input}_i + \text{value} \times \text{tensor1}_i \times \text{tensor2}_i
  4079. The shapes of :attr:`tensor`, :attr:`tensor1`, and :attr:`tensor2` must be
  4080. :ref:`broadcastable <broadcasting-semantics>`.
  4081. For inputs of type `FloatTensor` or `DoubleTensor`, :attr:`value` must be
  4082. a real number, otherwise an integer.
  4083. Args:
  4084. input (Tensor): the tensor to be added
  4085. tensor1 (Tensor): the tensor to be multiplied
  4086. tensor2 (Tensor): the tensor to be multiplied
  4087. Keyword args:
  4088. value (Number, optional): multiplier for :math:`tensor1 .* tensor2`
  4089. out (Tensor, optional): the output tensor.
  4090. Example::
  4091. >>> t = torch.randn(1, 3)
  4092. >>> t1 = torch.randn(3, 1)
  4093. >>> t2 = torch.randn(1, 3)
  4094. >>> torch.addcmul(t, t1, t2, value=0.1)
  4095. tensor([[-0.8635, -0.6391, 1.6174],
  4096. [-0.7617, -0.5879, 1.7388],
  4097. [-0.8353, -0.6249, 1.6511]])
  4098. """
  4099. @overload
  4100. def addcmul(
  4101. input: Tensor,
  4102. tensor1: Tensor,
  4103. tensor2: Tensor,
  4104. *,
  4105. value: Number | _complex = 1,
  4106. out: Tensor | None = None,
  4107. ) -> Tensor:
  4108. r"""
  4109. addcmul(input, tensor1, tensor2, *, value=1, out=None) -> Tensor
  4110. Performs the element-wise multiplication of :attr:`tensor1`
  4111. by :attr:`tensor2`, multiplies the result by the scalar :attr:`value`
  4112. and adds it to :attr:`input`.
  4113. .. math::
  4114. \text{out}_i = \text{input}_i + \text{value} \times \text{tensor1}_i \times \text{tensor2}_i
  4115. The shapes of :attr:`tensor`, :attr:`tensor1`, and :attr:`tensor2` must be
  4116. :ref:`broadcastable <broadcasting-semantics>`.
  4117. For inputs of type `FloatTensor` or `DoubleTensor`, :attr:`value` must be
  4118. a real number, otherwise an integer.
  4119. Args:
  4120. input (Tensor): the tensor to be added
  4121. tensor1 (Tensor): the tensor to be multiplied
  4122. tensor2 (Tensor): the tensor to be multiplied
  4123. Keyword args:
  4124. value (Number, optional): multiplier for :math:`tensor1 .* tensor2`
  4125. out (Tensor, optional): the output tensor.
  4126. Example::
  4127. >>> t = torch.randn(1, 3)
  4128. >>> t1 = torch.randn(3, 1)
  4129. >>> t2 = torch.randn(1, 3)
  4130. >>> torch.addcmul(t, t1, t2, value=0.1)
  4131. tensor([[-0.8635, -0.6391, 1.6174],
  4132. [-0.7617, -0.5879, 1.7388],
  4133. [-0.8353, -0.6249, 1.6511]])
  4134. """
  4135. @overload
  4136. def addmm(
  4137. beta: Number | _complex,
  4138. self: Tensor,
  4139. alpha: Number | _complex,
  4140. mat1: Tensor,
  4141. mat2: Tensor,
  4142. ) -> Tensor:
  4143. r"""
  4144. addmm(input, mat1, mat2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  4145. Performs a matrix multiplication of the matrices :attr:`mat1` and :attr:`mat2`.
  4146. The matrix :attr:`input` is added to the final result.
  4147. If :attr:`mat1` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
  4148. :math:`(m \times p)` tensor, then :attr:`input` must be
  4149. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  4150. and :attr:`out` will be a :math:`(n \times p)` tensor.
  4151. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4152. :attr:`mat1` and :attr:`mat2` and the added matrix :attr:`input` respectively.
  4153. .. math::
  4154. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat1}_i \mathbin{@} \text{mat2}_i)
  4155. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4156. it will not be propagated.
  4157. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4158. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4159. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`. If
  4160. :attr:`input` is sparse the result will have the same layout and if :attr:`out`
  4161. is provided it must have the same layout as :attr:`input`.
  4162. .. warning::
  4163. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  4164. or may not have autograd support. If you notice missing functionality please
  4165. open a feature request.
  4166. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  4167. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  4168. Args:
  4169. input (Tensor): matrix to be added
  4170. mat1 (Tensor): the first matrix to be matrix multiplied
  4171. mat2 (Tensor): the second matrix to be matrix multiplied
  4172. out_dtype (dtype, optional): the dtype of the output tensor,
  4173. Supported only on CUDA and for torch.float32 given
  4174. torch.float16/torch.bfloat16 input dtypes
  4175. Keyword args:
  4176. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4177. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  4178. out (Tensor, optional): the output tensor.
  4179. Example::
  4180. >>> M = torch.randn(2, 3)
  4181. >>> mat1 = torch.randn(2, 3)
  4182. >>> mat2 = torch.randn(3, 3)
  4183. >>> torch.addmm(M, mat1, mat2)
  4184. tensor([[-4.8716, 1.4671, -1.3746],
  4185. [ 0.7573, -3.9555, -2.8681]])
  4186. """
  4187. @overload
  4188. def addmm(
  4189. beta: Number | _complex,
  4190. self: Tensor,
  4191. alpha: Number | _complex,
  4192. mat1: Tensor,
  4193. mat2: Tensor,
  4194. *,
  4195. out: Tensor,
  4196. ) -> Tensor:
  4197. r"""
  4198. addmm(input, mat1, mat2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  4199. Performs a matrix multiplication of the matrices :attr:`mat1` and :attr:`mat2`.
  4200. The matrix :attr:`input` is added to the final result.
  4201. If :attr:`mat1` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
  4202. :math:`(m \times p)` tensor, then :attr:`input` must be
  4203. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  4204. and :attr:`out` will be a :math:`(n \times p)` tensor.
  4205. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4206. :attr:`mat1` and :attr:`mat2` and the added matrix :attr:`input` respectively.
  4207. .. math::
  4208. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat1}_i \mathbin{@} \text{mat2}_i)
  4209. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4210. it will not be propagated.
  4211. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4212. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4213. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`. If
  4214. :attr:`input` is sparse the result will have the same layout and if :attr:`out`
  4215. is provided it must have the same layout as :attr:`input`.
  4216. .. warning::
  4217. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  4218. or may not have autograd support. If you notice missing functionality please
  4219. open a feature request.
  4220. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  4221. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  4222. Args:
  4223. input (Tensor): matrix to be added
  4224. mat1 (Tensor): the first matrix to be matrix multiplied
  4225. mat2 (Tensor): the second matrix to be matrix multiplied
  4226. out_dtype (dtype, optional): the dtype of the output tensor,
  4227. Supported only on CUDA and for torch.float32 given
  4228. torch.float16/torch.bfloat16 input dtypes
  4229. Keyword args:
  4230. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4231. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  4232. out (Tensor, optional): the output tensor.
  4233. Example::
  4234. >>> M = torch.randn(2, 3)
  4235. >>> mat1 = torch.randn(2, 3)
  4236. >>> mat2 = torch.randn(3, 3)
  4237. >>> torch.addmm(M, mat1, mat2)
  4238. tensor([[-4.8716, 1.4671, -1.3746],
  4239. [ 0.7573, -3.9555, -2.8681]])
  4240. """
  4241. @overload
  4242. def addmm(
  4243. input: Tensor,
  4244. mat1: Tensor,
  4245. mat2: Tensor,
  4246. *,
  4247. beta: Number | _complex = 1,
  4248. alpha: Number | _complex = 1,
  4249. out: Tensor | None = None,
  4250. ) -> Tensor:
  4251. r"""
  4252. addmm(input, mat1, mat2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  4253. Performs a matrix multiplication of the matrices :attr:`mat1` and :attr:`mat2`.
  4254. The matrix :attr:`input` is added to the final result.
  4255. If :attr:`mat1` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
  4256. :math:`(m \times p)` tensor, then :attr:`input` must be
  4257. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  4258. and :attr:`out` will be a :math:`(n \times p)` tensor.
  4259. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4260. :attr:`mat1` and :attr:`mat2` and the added matrix :attr:`input` respectively.
  4261. .. math::
  4262. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat1}_i \mathbin{@} \text{mat2}_i)
  4263. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4264. it will not be propagated.
  4265. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4266. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4267. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`. If
  4268. :attr:`input` is sparse the result will have the same layout and if :attr:`out`
  4269. is provided it must have the same layout as :attr:`input`.
  4270. .. warning::
  4271. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  4272. or may not have autograd support. If you notice missing functionality please
  4273. open a feature request.
  4274. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  4275. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  4276. Args:
  4277. input (Tensor): matrix to be added
  4278. mat1 (Tensor): the first matrix to be matrix multiplied
  4279. mat2 (Tensor): the second matrix to be matrix multiplied
  4280. out_dtype (dtype, optional): the dtype of the output tensor,
  4281. Supported only on CUDA and for torch.float32 given
  4282. torch.float16/torch.bfloat16 input dtypes
  4283. Keyword args:
  4284. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4285. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  4286. out (Tensor, optional): the output tensor.
  4287. Example::
  4288. >>> M = torch.randn(2, 3)
  4289. >>> mat1 = torch.randn(2, 3)
  4290. >>> mat2 = torch.randn(3, 3)
  4291. >>> torch.addmm(M, mat1, mat2)
  4292. tensor([[-4.8716, 1.4671, -1.3746],
  4293. [ 0.7573, -3.9555, -2.8681]])
  4294. """
  4295. @overload
  4296. def addmm(
  4297. input: Tensor,
  4298. mat1: Tensor,
  4299. mat2: Tensor,
  4300. out_dtype: _dtype,
  4301. *,
  4302. beta: Number | _complex = 1,
  4303. alpha: Number | _complex = 1,
  4304. out: Tensor | None = None,
  4305. ) -> Tensor:
  4306. r"""
  4307. addmm(input, mat1, mat2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  4308. Performs a matrix multiplication of the matrices :attr:`mat1` and :attr:`mat2`.
  4309. The matrix :attr:`input` is added to the final result.
  4310. If :attr:`mat1` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
  4311. :math:`(m \times p)` tensor, then :attr:`input` must be
  4312. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  4313. and :attr:`out` will be a :math:`(n \times p)` tensor.
  4314. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4315. :attr:`mat1` and :attr:`mat2` and the added matrix :attr:`input` respectively.
  4316. .. math::
  4317. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat1}_i \mathbin{@} \text{mat2}_i)
  4318. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4319. it will not be propagated.
  4320. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4321. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4322. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`. If
  4323. :attr:`input` is sparse the result will have the same layout and if :attr:`out`
  4324. is provided it must have the same layout as :attr:`input`.
  4325. .. warning::
  4326. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  4327. or may not have autograd support. If you notice missing functionality please
  4328. open a feature request.
  4329. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  4330. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  4331. Args:
  4332. input (Tensor): matrix to be added
  4333. mat1 (Tensor): the first matrix to be matrix multiplied
  4334. mat2 (Tensor): the second matrix to be matrix multiplied
  4335. out_dtype (dtype, optional): the dtype of the output tensor,
  4336. Supported only on CUDA and for torch.float32 given
  4337. torch.float16/torch.bfloat16 input dtypes
  4338. Keyword args:
  4339. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4340. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  4341. out (Tensor, optional): the output tensor.
  4342. Example::
  4343. >>> M = torch.randn(2, 3)
  4344. >>> mat1 = torch.randn(2, 3)
  4345. >>> mat2 = torch.randn(3, 3)
  4346. >>> torch.addmm(M, mat1, mat2)
  4347. tensor([[-4.8716, 1.4671, -1.3746],
  4348. [ 0.7573, -3.9555, -2.8681]])
  4349. """
  4350. @overload
  4351. def addmm(
  4352. beta: Number | _complex,
  4353. self: Tensor,
  4354. mat1: Tensor,
  4355. mat2: Tensor,
  4356. ) -> Tensor:
  4357. r"""
  4358. addmm(input, mat1, mat2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  4359. Performs a matrix multiplication of the matrices :attr:`mat1` and :attr:`mat2`.
  4360. The matrix :attr:`input` is added to the final result.
  4361. If :attr:`mat1` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
  4362. :math:`(m \times p)` tensor, then :attr:`input` must be
  4363. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  4364. and :attr:`out` will be a :math:`(n \times p)` tensor.
  4365. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4366. :attr:`mat1` and :attr:`mat2` and the added matrix :attr:`input` respectively.
  4367. .. math::
  4368. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat1}_i \mathbin{@} \text{mat2}_i)
  4369. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4370. it will not be propagated.
  4371. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4372. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4373. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`. If
  4374. :attr:`input` is sparse the result will have the same layout and if :attr:`out`
  4375. is provided it must have the same layout as :attr:`input`.
  4376. .. warning::
  4377. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  4378. or may not have autograd support. If you notice missing functionality please
  4379. open a feature request.
  4380. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  4381. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  4382. Args:
  4383. input (Tensor): matrix to be added
  4384. mat1 (Tensor): the first matrix to be matrix multiplied
  4385. mat2 (Tensor): the second matrix to be matrix multiplied
  4386. out_dtype (dtype, optional): the dtype of the output tensor,
  4387. Supported only on CUDA and for torch.float32 given
  4388. torch.float16/torch.bfloat16 input dtypes
  4389. Keyword args:
  4390. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4391. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  4392. out (Tensor, optional): the output tensor.
  4393. Example::
  4394. >>> M = torch.randn(2, 3)
  4395. >>> mat1 = torch.randn(2, 3)
  4396. >>> mat2 = torch.randn(3, 3)
  4397. >>> torch.addmm(M, mat1, mat2)
  4398. tensor([[-4.8716, 1.4671, -1.3746],
  4399. [ 0.7573, -3.9555, -2.8681]])
  4400. """
  4401. @overload
  4402. def addmm(
  4403. beta: Number | _complex,
  4404. self: Tensor,
  4405. mat1: Tensor,
  4406. mat2: Tensor,
  4407. *,
  4408. out: Tensor,
  4409. ) -> Tensor:
  4410. r"""
  4411. addmm(input, mat1, mat2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  4412. Performs a matrix multiplication of the matrices :attr:`mat1` and :attr:`mat2`.
  4413. The matrix :attr:`input` is added to the final result.
  4414. If :attr:`mat1` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
  4415. :math:`(m \times p)` tensor, then :attr:`input` must be
  4416. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  4417. and :attr:`out` will be a :math:`(n \times p)` tensor.
  4418. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4419. :attr:`mat1` and :attr:`mat2` and the added matrix :attr:`input` respectively.
  4420. .. math::
  4421. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat1}_i \mathbin{@} \text{mat2}_i)
  4422. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4423. it will not be propagated.
  4424. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4425. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4426. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`. If
  4427. :attr:`input` is sparse the result will have the same layout and if :attr:`out`
  4428. is provided it must have the same layout as :attr:`input`.
  4429. .. warning::
  4430. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  4431. or may not have autograd support. If you notice missing functionality please
  4432. open a feature request.
  4433. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  4434. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  4435. Args:
  4436. input (Tensor): matrix to be added
  4437. mat1 (Tensor): the first matrix to be matrix multiplied
  4438. mat2 (Tensor): the second matrix to be matrix multiplied
  4439. out_dtype (dtype, optional): the dtype of the output tensor,
  4440. Supported only on CUDA and for torch.float32 given
  4441. torch.float16/torch.bfloat16 input dtypes
  4442. Keyword args:
  4443. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4444. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  4445. out (Tensor, optional): the output tensor.
  4446. Example::
  4447. >>> M = torch.randn(2, 3)
  4448. >>> mat1 = torch.randn(2, 3)
  4449. >>> mat2 = torch.randn(3, 3)
  4450. >>> torch.addmm(M, mat1, mat2)
  4451. tensor([[-4.8716, 1.4671, -1.3746],
  4452. [ 0.7573, -3.9555, -2.8681]])
  4453. """
  4454. @overload
  4455. def addmv(
  4456. beta: Number | _complex,
  4457. self: Tensor,
  4458. alpha: Number | _complex,
  4459. mat: Tensor,
  4460. vec: Tensor,
  4461. ) -> Tensor:
  4462. r"""
  4463. addmv(input, mat, vec, *, beta=1, alpha=1, out=None) -> Tensor
  4464. Performs a matrix-vector product of the matrix :attr:`mat` and
  4465. the vector :attr:`vec`.
  4466. The vector :attr:`input` is added to the final result.
  4467. If :attr:`mat` is a :math:`(n \times m)` tensor, :attr:`vec` is a 1-D tensor of
  4468. size `m`, then :attr:`input` must be
  4469. :ref:`broadcastable <broadcasting-semantics>` with a 1-D tensor of size `n` and
  4470. :attr:`out` will be 1-D tensor of size `n`.
  4471. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4472. :attr:`mat` and :attr:`vec` and the added tensor :attr:`input` respectively.
  4473. .. math::
  4474. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat} \mathbin{@} \text{vec})
  4475. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4476. it will not be propagated.
  4477. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4478. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4479. Args:
  4480. input (Tensor): vector to be added
  4481. mat (Tensor): matrix to be matrix multiplied
  4482. vec (Tensor): vector to be matrix multiplied
  4483. Keyword args:
  4484. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4485. alpha (Number, optional): multiplier for :math:`mat @ vec` (:math:`\alpha`)
  4486. out (Tensor, optional): the output tensor.
  4487. Example::
  4488. >>> M = torch.randn(2)
  4489. >>> mat = torch.randn(2, 3)
  4490. >>> vec = torch.randn(3)
  4491. >>> torch.addmv(M, mat, vec)
  4492. tensor([-0.3768, -5.5565])
  4493. """
  4494. @overload
  4495. def addmv(
  4496. beta: Number | _complex,
  4497. self: Tensor,
  4498. alpha: Number | _complex,
  4499. mat: Tensor,
  4500. vec: Tensor,
  4501. *,
  4502. out: Tensor,
  4503. ) -> Tensor:
  4504. r"""
  4505. addmv(input, mat, vec, *, beta=1, alpha=1, out=None) -> Tensor
  4506. Performs a matrix-vector product of the matrix :attr:`mat` and
  4507. the vector :attr:`vec`.
  4508. The vector :attr:`input` is added to the final result.
  4509. If :attr:`mat` is a :math:`(n \times m)` tensor, :attr:`vec` is a 1-D tensor of
  4510. size `m`, then :attr:`input` must be
  4511. :ref:`broadcastable <broadcasting-semantics>` with a 1-D tensor of size `n` and
  4512. :attr:`out` will be 1-D tensor of size `n`.
  4513. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4514. :attr:`mat` and :attr:`vec` and the added tensor :attr:`input` respectively.
  4515. .. math::
  4516. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat} \mathbin{@} \text{vec})
  4517. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4518. it will not be propagated.
  4519. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4520. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4521. Args:
  4522. input (Tensor): vector to be added
  4523. mat (Tensor): matrix to be matrix multiplied
  4524. vec (Tensor): vector to be matrix multiplied
  4525. Keyword args:
  4526. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4527. alpha (Number, optional): multiplier for :math:`mat @ vec` (:math:`\alpha`)
  4528. out (Tensor, optional): the output tensor.
  4529. Example::
  4530. >>> M = torch.randn(2)
  4531. >>> mat = torch.randn(2, 3)
  4532. >>> vec = torch.randn(3)
  4533. >>> torch.addmv(M, mat, vec)
  4534. tensor([-0.3768, -5.5565])
  4535. """
  4536. @overload
  4537. def addmv(
  4538. input: Tensor,
  4539. mat: Tensor,
  4540. vec: Tensor,
  4541. *,
  4542. beta: Number | _complex = 1,
  4543. alpha: Number | _complex = 1,
  4544. out: Tensor | None = None,
  4545. ) -> Tensor:
  4546. r"""
  4547. addmv(input, mat, vec, *, beta=1, alpha=1, out=None) -> Tensor
  4548. Performs a matrix-vector product of the matrix :attr:`mat` and
  4549. the vector :attr:`vec`.
  4550. The vector :attr:`input` is added to the final result.
  4551. If :attr:`mat` is a :math:`(n \times m)` tensor, :attr:`vec` is a 1-D tensor of
  4552. size `m`, then :attr:`input` must be
  4553. :ref:`broadcastable <broadcasting-semantics>` with a 1-D tensor of size `n` and
  4554. :attr:`out` will be 1-D tensor of size `n`.
  4555. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4556. :attr:`mat` and :attr:`vec` and the added tensor :attr:`input` respectively.
  4557. .. math::
  4558. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat} \mathbin{@} \text{vec})
  4559. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4560. it will not be propagated.
  4561. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4562. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4563. Args:
  4564. input (Tensor): vector to be added
  4565. mat (Tensor): matrix to be matrix multiplied
  4566. vec (Tensor): vector to be matrix multiplied
  4567. Keyword args:
  4568. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4569. alpha (Number, optional): multiplier for :math:`mat @ vec` (:math:`\alpha`)
  4570. out (Tensor, optional): the output tensor.
  4571. Example::
  4572. >>> M = torch.randn(2)
  4573. >>> mat = torch.randn(2, 3)
  4574. >>> vec = torch.randn(3)
  4575. >>> torch.addmv(M, mat, vec)
  4576. tensor([-0.3768, -5.5565])
  4577. """
  4578. @overload
  4579. def addmv(
  4580. beta: Number | _complex,
  4581. self: Tensor,
  4582. mat: Tensor,
  4583. vec: Tensor,
  4584. ) -> Tensor:
  4585. r"""
  4586. addmv(input, mat, vec, *, beta=1, alpha=1, out=None) -> Tensor
  4587. Performs a matrix-vector product of the matrix :attr:`mat` and
  4588. the vector :attr:`vec`.
  4589. The vector :attr:`input` is added to the final result.
  4590. If :attr:`mat` is a :math:`(n \times m)` tensor, :attr:`vec` is a 1-D tensor of
  4591. size `m`, then :attr:`input` must be
  4592. :ref:`broadcastable <broadcasting-semantics>` with a 1-D tensor of size `n` and
  4593. :attr:`out` will be 1-D tensor of size `n`.
  4594. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4595. :attr:`mat` and :attr:`vec` and the added tensor :attr:`input` respectively.
  4596. .. math::
  4597. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat} \mathbin{@} \text{vec})
  4598. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4599. it will not be propagated.
  4600. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4601. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4602. Args:
  4603. input (Tensor): vector to be added
  4604. mat (Tensor): matrix to be matrix multiplied
  4605. vec (Tensor): vector to be matrix multiplied
  4606. Keyword args:
  4607. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4608. alpha (Number, optional): multiplier for :math:`mat @ vec` (:math:`\alpha`)
  4609. out (Tensor, optional): the output tensor.
  4610. Example::
  4611. >>> M = torch.randn(2)
  4612. >>> mat = torch.randn(2, 3)
  4613. >>> vec = torch.randn(3)
  4614. >>> torch.addmv(M, mat, vec)
  4615. tensor([-0.3768, -5.5565])
  4616. """
  4617. @overload
  4618. def addmv(
  4619. beta: Number | _complex,
  4620. self: Tensor,
  4621. mat: Tensor,
  4622. vec: Tensor,
  4623. *,
  4624. out: Tensor,
  4625. ) -> Tensor:
  4626. r"""
  4627. addmv(input, mat, vec, *, beta=1, alpha=1, out=None) -> Tensor
  4628. Performs a matrix-vector product of the matrix :attr:`mat` and
  4629. the vector :attr:`vec`.
  4630. The vector :attr:`input` is added to the final result.
  4631. If :attr:`mat` is a :math:`(n \times m)` tensor, :attr:`vec` is a 1-D tensor of
  4632. size `m`, then :attr:`input` must be
  4633. :ref:`broadcastable <broadcasting-semantics>` with a 1-D tensor of size `n` and
  4634. :attr:`out` will be 1-D tensor of size `n`.
  4635. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4636. :attr:`mat` and :attr:`vec` and the added tensor :attr:`input` respectively.
  4637. .. math::
  4638. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat} \mathbin{@} \text{vec})
  4639. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4640. it will not be propagated.
  4641. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4642. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4643. Args:
  4644. input (Tensor): vector to be added
  4645. mat (Tensor): matrix to be matrix multiplied
  4646. vec (Tensor): vector to be matrix multiplied
  4647. Keyword args:
  4648. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4649. alpha (Number, optional): multiplier for :math:`mat @ vec` (:math:`\alpha`)
  4650. out (Tensor, optional): the output tensor.
  4651. Example::
  4652. >>> M = torch.randn(2)
  4653. >>> mat = torch.randn(2, 3)
  4654. >>> vec = torch.randn(3)
  4655. >>> torch.addmv(M, mat, vec)
  4656. tensor([-0.3768, -5.5565])
  4657. """
  4658. @overload
  4659. def addmv_(
  4660. beta: Number | _complex,
  4661. self: Tensor,
  4662. alpha: Number | _complex,
  4663. mat: Tensor,
  4664. vec: Tensor,
  4665. ) -> Tensor: ...
  4666. @overload
  4667. def addmv_(
  4668. input: Tensor,
  4669. mat: Tensor,
  4670. vec: Tensor,
  4671. *,
  4672. beta: Number | _complex = 1,
  4673. alpha: Number | _complex = 1,
  4674. ) -> Tensor: ...
  4675. @overload
  4676. def addmv_(
  4677. beta: Number | _complex,
  4678. self: Tensor,
  4679. mat: Tensor,
  4680. vec: Tensor,
  4681. ) -> Tensor: ...
  4682. @overload
  4683. def addr(
  4684. beta: Number | _complex,
  4685. self: Tensor,
  4686. alpha: Number | _complex,
  4687. vec1: Tensor,
  4688. vec2: Tensor,
  4689. ) -> Tensor:
  4690. r"""
  4691. addr(input, vec1, vec2, *, beta=1, alpha=1, out=None) -> Tensor
  4692. Performs the outer-product of vectors :attr:`vec1` and :attr:`vec2`
  4693. and adds it to the matrix :attr:`input`.
  4694. Optional values :attr:`beta` and :attr:`alpha` are scaling factors on the
  4695. outer product between :attr:`vec1` and :attr:`vec2` and the added matrix
  4696. :attr:`input` respectively.
  4697. .. math::
  4698. \text{out} = \beta\ \text{input} + \alpha\ (\text{vec1} \otimes \text{vec2})
  4699. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4700. it will not be propagated.
  4701. If :attr:`vec1` is a vector of size `n` and :attr:`vec2` is a vector
  4702. of size `m`, then :attr:`input` must be
  4703. :ref:`broadcastable <broadcasting-semantics>` with a matrix of size
  4704. :math:`(n \times m)` and :attr:`out` will be a matrix of size
  4705. :math:`(n \times m)`.
  4706. Args:
  4707. input (Tensor): matrix to be added
  4708. vec1 (Tensor): the first vector of the outer product
  4709. vec2 (Tensor): the second vector of the outer product
  4710. Keyword args:
  4711. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4712. alpha (Number, optional): multiplier for :math:`\text{vec1} \otimes \text{vec2}` (:math:`\alpha`)
  4713. out (Tensor, optional): the output tensor.
  4714. Example::
  4715. >>> vec1 = torch.arange(1., 4.)
  4716. >>> vec2 = torch.arange(1., 3.)
  4717. >>> M = torch.zeros(3, 2)
  4718. >>> torch.addr(M, vec1, vec2)
  4719. tensor([[ 1., 2.],
  4720. [ 2., 4.],
  4721. [ 3., 6.]])
  4722. """
  4723. @overload
  4724. def addr(
  4725. beta: Number | _complex,
  4726. self: Tensor,
  4727. alpha: Number | _complex,
  4728. vec1: Tensor,
  4729. vec2: Tensor,
  4730. *,
  4731. out: Tensor,
  4732. ) -> Tensor:
  4733. r"""
  4734. addr(input, vec1, vec2, *, beta=1, alpha=1, out=None) -> Tensor
  4735. Performs the outer-product of vectors :attr:`vec1` and :attr:`vec2`
  4736. and adds it to the matrix :attr:`input`.
  4737. Optional values :attr:`beta` and :attr:`alpha` are scaling factors on the
  4738. outer product between :attr:`vec1` and :attr:`vec2` and the added matrix
  4739. :attr:`input` respectively.
  4740. .. math::
  4741. \text{out} = \beta\ \text{input} + \alpha\ (\text{vec1} \otimes \text{vec2})
  4742. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4743. it will not be propagated.
  4744. If :attr:`vec1` is a vector of size `n` and :attr:`vec2` is a vector
  4745. of size `m`, then :attr:`input` must be
  4746. :ref:`broadcastable <broadcasting-semantics>` with a matrix of size
  4747. :math:`(n \times m)` and :attr:`out` will be a matrix of size
  4748. :math:`(n \times m)`.
  4749. Args:
  4750. input (Tensor): matrix to be added
  4751. vec1 (Tensor): the first vector of the outer product
  4752. vec2 (Tensor): the second vector of the outer product
  4753. Keyword args:
  4754. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4755. alpha (Number, optional): multiplier for :math:`\text{vec1} \otimes \text{vec2}` (:math:`\alpha`)
  4756. out (Tensor, optional): the output tensor.
  4757. Example::
  4758. >>> vec1 = torch.arange(1., 4.)
  4759. >>> vec2 = torch.arange(1., 3.)
  4760. >>> M = torch.zeros(3, 2)
  4761. >>> torch.addr(M, vec1, vec2)
  4762. tensor([[ 1., 2.],
  4763. [ 2., 4.],
  4764. [ 3., 6.]])
  4765. """
  4766. @overload
  4767. def addr(
  4768. input: Tensor,
  4769. vec1: Tensor,
  4770. vec2: Tensor,
  4771. *,
  4772. beta: Number | _complex = 1,
  4773. alpha: Number | _complex = 1,
  4774. out: Tensor | None = None,
  4775. ) -> Tensor:
  4776. r"""
  4777. addr(input, vec1, vec2, *, beta=1, alpha=1, out=None) -> Tensor
  4778. Performs the outer-product of vectors :attr:`vec1` and :attr:`vec2`
  4779. and adds it to the matrix :attr:`input`.
  4780. Optional values :attr:`beta` and :attr:`alpha` are scaling factors on the
  4781. outer product between :attr:`vec1` and :attr:`vec2` and the added matrix
  4782. :attr:`input` respectively.
  4783. .. math::
  4784. \text{out} = \beta\ \text{input} + \alpha\ (\text{vec1} \otimes \text{vec2})
  4785. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4786. it will not be propagated.
  4787. If :attr:`vec1` is a vector of size `n` and :attr:`vec2` is a vector
  4788. of size `m`, then :attr:`input` must be
  4789. :ref:`broadcastable <broadcasting-semantics>` with a matrix of size
  4790. :math:`(n \times m)` and :attr:`out` will be a matrix of size
  4791. :math:`(n \times m)`.
  4792. Args:
  4793. input (Tensor): matrix to be added
  4794. vec1 (Tensor): the first vector of the outer product
  4795. vec2 (Tensor): the second vector of the outer product
  4796. Keyword args:
  4797. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4798. alpha (Number, optional): multiplier for :math:`\text{vec1} \otimes \text{vec2}` (:math:`\alpha`)
  4799. out (Tensor, optional): the output tensor.
  4800. Example::
  4801. >>> vec1 = torch.arange(1., 4.)
  4802. >>> vec2 = torch.arange(1., 3.)
  4803. >>> M = torch.zeros(3, 2)
  4804. >>> torch.addr(M, vec1, vec2)
  4805. tensor([[ 1., 2.],
  4806. [ 2., 4.],
  4807. [ 3., 6.]])
  4808. """
  4809. @overload
  4810. def addr(
  4811. beta: Number | _complex,
  4812. self: Tensor,
  4813. vec1: Tensor,
  4814. vec2: Tensor,
  4815. ) -> Tensor:
  4816. r"""
  4817. addr(input, vec1, vec2, *, beta=1, alpha=1, out=None) -> Tensor
  4818. Performs the outer-product of vectors :attr:`vec1` and :attr:`vec2`
  4819. and adds it to the matrix :attr:`input`.
  4820. Optional values :attr:`beta` and :attr:`alpha` are scaling factors on the
  4821. outer product between :attr:`vec1` and :attr:`vec2` and the added matrix
  4822. :attr:`input` respectively.
  4823. .. math::
  4824. \text{out} = \beta\ \text{input} + \alpha\ (\text{vec1} \otimes \text{vec2})
  4825. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4826. it will not be propagated.
  4827. If :attr:`vec1` is a vector of size `n` and :attr:`vec2` is a vector
  4828. of size `m`, then :attr:`input` must be
  4829. :ref:`broadcastable <broadcasting-semantics>` with a matrix of size
  4830. :math:`(n \times m)` and :attr:`out` will be a matrix of size
  4831. :math:`(n \times m)`.
  4832. Args:
  4833. input (Tensor): matrix to be added
  4834. vec1 (Tensor): the first vector of the outer product
  4835. vec2 (Tensor): the second vector of the outer product
  4836. Keyword args:
  4837. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4838. alpha (Number, optional): multiplier for :math:`\text{vec1} \otimes \text{vec2}` (:math:`\alpha`)
  4839. out (Tensor, optional): the output tensor.
  4840. Example::
  4841. >>> vec1 = torch.arange(1., 4.)
  4842. >>> vec2 = torch.arange(1., 3.)
  4843. >>> M = torch.zeros(3, 2)
  4844. >>> torch.addr(M, vec1, vec2)
  4845. tensor([[ 1., 2.],
  4846. [ 2., 4.],
  4847. [ 3., 6.]])
  4848. """
  4849. @overload
  4850. def addr(
  4851. beta: Number | _complex,
  4852. self: Tensor,
  4853. vec1: Tensor,
  4854. vec2: Tensor,
  4855. *,
  4856. out: Tensor,
  4857. ) -> Tensor:
  4858. r"""
  4859. addr(input, vec1, vec2, *, beta=1, alpha=1, out=None) -> Tensor
  4860. Performs the outer-product of vectors :attr:`vec1` and :attr:`vec2`
  4861. and adds it to the matrix :attr:`input`.
  4862. Optional values :attr:`beta` and :attr:`alpha` are scaling factors on the
  4863. outer product between :attr:`vec1` and :attr:`vec2` and the added matrix
  4864. :attr:`input` respectively.
  4865. .. math::
  4866. \text{out} = \beta\ \text{input} + \alpha\ (\text{vec1} \otimes \text{vec2})
  4867. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4868. it will not be propagated.
  4869. If :attr:`vec1` is a vector of size `n` and :attr:`vec2` is a vector
  4870. of size `m`, then :attr:`input` must be
  4871. :ref:`broadcastable <broadcasting-semantics>` with a matrix of size
  4872. :math:`(n \times m)` and :attr:`out` will be a matrix of size
  4873. :math:`(n \times m)`.
  4874. Args:
  4875. input (Tensor): matrix to be added
  4876. vec1 (Tensor): the first vector of the outer product
  4877. vec2 (Tensor): the second vector of the outer product
  4878. Keyword args:
  4879. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4880. alpha (Number, optional): multiplier for :math:`\text{vec1} \otimes \text{vec2}` (:math:`\alpha`)
  4881. out (Tensor, optional): the output tensor.
  4882. Example::
  4883. >>> vec1 = torch.arange(1., 4.)
  4884. >>> vec2 = torch.arange(1., 3.)
  4885. >>> M = torch.zeros(3, 2)
  4886. >>> torch.addr(M, vec1, vec2)
  4887. tensor([[ 1., 2.],
  4888. [ 2., 4.],
  4889. [ 3., 6.]])
  4890. """
  4891. def adjoint(input: Tensor) -> Tensor:
  4892. r"""
  4893. adjoint(input: Tensor) -> Tensor
  4894. Returns a view of the tensor conjugated and with the last two dimensions transposed.
  4895. ``x.adjoint()`` is equivalent to ``x.transpose(-2, -1).conj()`` for complex tensors and
  4896. to ``x.transpose(-2, -1)`` for real tensors.
  4897. Args:
  4898. {input}
  4899. Example::
  4900. >>> x = torch.arange(4, dtype=torch.float)
  4901. >>> A = torch.complex(x, x).reshape(2, 2)
  4902. >>> A
  4903. tensor([[0.+0.j, 1.+1.j],
  4904. [2.+2.j, 3.+3.j]])
  4905. >>> A.adjoint()
  4906. tensor([[0.-0.j, 2.-2.j],
  4907. [1.-1.j, 3.-3.j]])
  4908. >>> (A.adjoint() == A.mH).all()
  4909. tensor(True)
  4910. """
  4911. def affine_grid_generator(
  4912. theta: Tensor,
  4913. size: Sequence[_int | SymInt],
  4914. align_corners: _bool,
  4915. ) -> Tensor: ...
  4916. def alias_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  4917. r"""
  4918. Performs the same operation as :func:`torch.alias`, but all output tensors
  4919. are freshly created instead of aliasing the input.
  4920. """
  4921. @overload
  4922. def all(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  4923. r"""
  4924. all(input: Tensor, *, out=None) -> Tensor
  4925. Tests if all elements in :attr:`input` evaluate to `True`.
  4926. .. note:: This function matches the behaviour of NumPy in returning
  4927. output of dtype `bool` for all supported dtypes except `uint8`.
  4928. For `uint8` the dtype of output is `uint8` itself.
  4929. Args:
  4930. input (Tensor): the input tensor.
  4931. Keyword args:
  4932. out (Tensor, optional): the output tensor.
  4933. Example::
  4934. >>> a = torch.rand(1, 2).bool()
  4935. >>> a
  4936. tensor([[False, True]], dtype=torch.bool)
  4937. >>> torch.all(a)
  4938. tensor(False, dtype=torch.bool)
  4939. >>> a = torch.arange(0, 3)
  4940. >>> a
  4941. tensor([0, 1, 2])
  4942. >>> torch.all(a)
  4943. tensor(False)
  4944. .. function:: all(input, dim, keepdim=False, *, out=None) -> Tensor
  4945. :noindex:
  4946. For each row of :attr:`input` in the given dimension :attr:`dim`,
  4947. returns `True` if all elements in the row evaluate to `True` and `False` otherwise.
  4948. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  4949. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  4950. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  4951. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  4952. Args:
  4953. input (Tensor): the input tensor.
  4954. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  4955. If ``None``, all dimensions are reduced.
  4956. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  4957. Keyword args:
  4958. out (Tensor, optional): the output tensor.
  4959. Example::
  4960. >>> a = torch.rand(4, 2).bool()
  4961. >>> a
  4962. tensor([[True, True],
  4963. [True, False],
  4964. [True, True],
  4965. [True, True]], dtype=torch.bool)
  4966. >>> torch.all(a, dim=1)
  4967. tensor([ True, False, True, True], dtype=torch.bool)
  4968. >>> torch.all(a, dim=0)
  4969. tensor([ True, False], dtype=torch.bool)
  4970. """
  4971. @overload
  4972. def all(
  4973. input: Tensor,
  4974. dim: _size | None = None,
  4975. keepdim: _bool = False,
  4976. *,
  4977. out: Tensor | None = None,
  4978. ) -> Tensor:
  4979. r"""
  4980. all(input: Tensor, *, out=None) -> Tensor
  4981. Tests if all elements in :attr:`input` evaluate to `True`.
  4982. .. note:: This function matches the behaviour of NumPy in returning
  4983. output of dtype `bool` for all supported dtypes except `uint8`.
  4984. For `uint8` the dtype of output is `uint8` itself.
  4985. Args:
  4986. input (Tensor): the input tensor.
  4987. Keyword args:
  4988. out (Tensor, optional): the output tensor.
  4989. Example::
  4990. >>> a = torch.rand(1, 2).bool()
  4991. >>> a
  4992. tensor([[False, True]], dtype=torch.bool)
  4993. >>> torch.all(a)
  4994. tensor(False, dtype=torch.bool)
  4995. >>> a = torch.arange(0, 3)
  4996. >>> a
  4997. tensor([0, 1, 2])
  4998. >>> torch.all(a)
  4999. tensor(False)
  5000. .. function:: all(input, dim, keepdim=False, *, out=None) -> Tensor
  5001. :noindex:
  5002. For each row of :attr:`input` in the given dimension :attr:`dim`,
  5003. returns `True` if all elements in the row evaluate to `True` and `False` otherwise.
  5004. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  5005. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  5006. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  5007. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  5008. Args:
  5009. input (Tensor): the input tensor.
  5010. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  5011. If ``None``, all dimensions are reduced.
  5012. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5013. Keyword args:
  5014. out (Tensor, optional): the output tensor.
  5015. Example::
  5016. >>> a = torch.rand(4, 2).bool()
  5017. >>> a
  5018. tensor([[True, True],
  5019. [True, False],
  5020. [True, True],
  5021. [True, True]], dtype=torch.bool)
  5022. >>> torch.all(a, dim=1)
  5023. tensor([ True, False, True, True], dtype=torch.bool)
  5024. >>> torch.all(a, dim=0)
  5025. tensor([ True, False], dtype=torch.bool)
  5026. """
  5027. @overload
  5028. def all(
  5029. input: Tensor,
  5030. dim: _int,
  5031. keepdim: _bool = False,
  5032. *,
  5033. out: Tensor | None = None,
  5034. ) -> Tensor:
  5035. r"""
  5036. all(input: Tensor, *, out=None) -> Tensor
  5037. Tests if all elements in :attr:`input` evaluate to `True`.
  5038. .. note:: This function matches the behaviour of NumPy in returning
  5039. output of dtype `bool` for all supported dtypes except `uint8`.
  5040. For `uint8` the dtype of output is `uint8` itself.
  5041. Args:
  5042. input (Tensor): the input tensor.
  5043. Keyword args:
  5044. out (Tensor, optional): the output tensor.
  5045. Example::
  5046. >>> a = torch.rand(1, 2).bool()
  5047. >>> a
  5048. tensor([[False, True]], dtype=torch.bool)
  5049. >>> torch.all(a)
  5050. tensor(False, dtype=torch.bool)
  5051. >>> a = torch.arange(0, 3)
  5052. >>> a
  5053. tensor([0, 1, 2])
  5054. >>> torch.all(a)
  5055. tensor(False)
  5056. .. function:: all(input, dim, keepdim=False, *, out=None) -> Tensor
  5057. :noindex:
  5058. For each row of :attr:`input` in the given dimension :attr:`dim`,
  5059. returns `True` if all elements in the row evaluate to `True` and `False` otherwise.
  5060. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  5061. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  5062. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  5063. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  5064. Args:
  5065. input (Tensor): the input tensor.
  5066. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  5067. If ``None``, all dimensions are reduced.
  5068. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5069. Keyword args:
  5070. out (Tensor, optional): the output tensor.
  5071. Example::
  5072. >>> a = torch.rand(4, 2).bool()
  5073. >>> a
  5074. tensor([[True, True],
  5075. [True, False],
  5076. [True, True],
  5077. [True, True]], dtype=torch.bool)
  5078. >>> torch.all(a, dim=1)
  5079. tensor([ True, False, True, True], dtype=torch.bool)
  5080. >>> torch.all(a, dim=0)
  5081. tensor([ True, False], dtype=torch.bool)
  5082. """
  5083. @overload
  5084. def all(
  5085. input: Tensor,
  5086. dim: str | EllipsisType | None,
  5087. keepdim: _bool = False,
  5088. *,
  5089. out: Tensor | None = None,
  5090. ) -> Tensor:
  5091. r"""
  5092. all(input: Tensor, *, out=None) -> Tensor
  5093. Tests if all elements in :attr:`input` evaluate to `True`.
  5094. .. note:: This function matches the behaviour of NumPy in returning
  5095. output of dtype `bool` for all supported dtypes except `uint8`.
  5096. For `uint8` the dtype of output is `uint8` itself.
  5097. Args:
  5098. input (Tensor): the input tensor.
  5099. Keyword args:
  5100. out (Tensor, optional): the output tensor.
  5101. Example::
  5102. >>> a = torch.rand(1, 2).bool()
  5103. >>> a
  5104. tensor([[False, True]], dtype=torch.bool)
  5105. >>> torch.all(a)
  5106. tensor(False, dtype=torch.bool)
  5107. >>> a = torch.arange(0, 3)
  5108. >>> a
  5109. tensor([0, 1, 2])
  5110. >>> torch.all(a)
  5111. tensor(False)
  5112. .. function:: all(input, dim, keepdim=False, *, out=None) -> Tensor
  5113. :noindex:
  5114. For each row of :attr:`input` in the given dimension :attr:`dim`,
  5115. returns `True` if all elements in the row evaluate to `True` and `False` otherwise.
  5116. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  5117. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  5118. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  5119. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  5120. Args:
  5121. input (Tensor): the input tensor.
  5122. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  5123. If ``None``, all dimensions are reduced.
  5124. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5125. Keyword args:
  5126. out (Tensor, optional): the output tensor.
  5127. Example::
  5128. >>> a = torch.rand(4, 2).bool()
  5129. >>> a
  5130. tensor([[True, True],
  5131. [True, False],
  5132. [True, True],
  5133. [True, True]], dtype=torch.bool)
  5134. >>> torch.all(a, dim=1)
  5135. tensor([ True, False, True, True], dtype=torch.bool)
  5136. >>> torch.all(a, dim=0)
  5137. tensor([ True, False], dtype=torch.bool)
  5138. """
  5139. def allclose(
  5140. input: Tensor,
  5141. other: Tensor,
  5142. rtol: _float = 1e-05,
  5143. atol: _float = 1e-08,
  5144. equal_nan: _bool = False,
  5145. ) -> _bool:
  5146. r"""
  5147. allclose(input: Tensor, other: Tensor, rtol: float = 1e-05, atol: float = 1e-08, equal_nan: bool = False) -> bool
  5148. This function checks if :attr:`input` and :attr:`other` satisfy the condition:
  5149. .. math::
  5150. \lvert \text{input}_i - \text{other}_i \rvert \leq \texttt{atol} + \texttt{rtol} \times \lvert \text{other}_i \rvert
  5151. elementwise, for all elements of :attr:`input` and :attr:`other`. The behaviour of this function is analogous to
  5152. `numpy.allclose <https://numpy.org/doc/stable/reference/generated/numpy.allclose.html>`_
  5153. Args:
  5154. input (Tensor): first tensor to compare
  5155. other (Tensor): second tensor to compare
  5156. atol (float, optional): absolute tolerance. Default: 1e-08
  5157. rtol (float, optional): relative tolerance. Default: 1e-05
  5158. equal_nan (bool, optional): if ``True``, then two ``NaN`` s will be considered equal. Default: ``False``
  5159. Example::
  5160. >>> torch.allclose(torch.tensor([10000., 1e-07]), torch.tensor([10000.1, 1e-08]))
  5161. False
  5162. >>> torch.allclose(torch.tensor([10000., 1e-08]), torch.tensor([10000.1, 1e-09]))
  5163. True
  5164. >>> torch.allclose(torch.tensor([1.0, float('nan')]), torch.tensor([1.0, float('nan')]))
  5165. False
  5166. >>> torch.allclose(torch.tensor([1.0, float('nan')]), torch.tensor([1.0, float('nan')]), equal_nan=True)
  5167. True
  5168. """
  5169. def alpha_dropout(input: Tensor, p: _float, train: _bool) -> Tensor: ...
  5170. def alpha_dropout_(input: Tensor, p: _float, train: _bool) -> Tensor: ...
  5171. def amax(
  5172. input: Tensor,
  5173. dim: _int | _size = (),
  5174. keepdim: _bool = False,
  5175. *,
  5176. out: Tensor | None = None,
  5177. ) -> Tensor:
  5178. r"""
  5179. amax(input, dim, keepdim=False, *, out=None) -> Tensor
  5180. Returns the maximum value of each slice of the :attr:`input` tensor in the given
  5181. dimension(s) :attr:`dim`.
  5182. .. note::
  5183. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  5184. - ``amax``/``amin`` supports reducing on multiple dimensions,
  5185. - ``amax``/``amin`` does not return indices.
  5186. Both ``amax``/``amin`` evenly distribute gradients between equal values
  5187. when there are multiple input elements with the same minimum or maximum value.
  5188. For ``max``/``min``:
  5189. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  5190. - If reduce over one specified axis, only propagate to the indexed element.
  5191. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  5192. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  5193. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  5194. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  5195. Args:
  5196. input (Tensor): the input tensor.
  5197. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  5198. If ``None``, all dimensions are reduced.
  5199. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5200. Keyword args:
  5201. out (Tensor, optional): the output tensor.
  5202. Example::
  5203. >>> a = torch.randn(4, 4)
  5204. >>> a
  5205. tensor([[ 0.8177, 1.4878, -0.2491, 0.9130],
  5206. [-0.7158, 1.1775, 2.0992, 0.4817],
  5207. [-0.0053, 0.0164, -1.3738, -0.0507],
  5208. [ 1.9700, 1.1106, -1.0318, -1.0816]])
  5209. >>> torch.amax(a, 1)
  5210. tensor([1.4878, 2.0992, 0.0164, 1.9700])
  5211. """
  5212. def amin(
  5213. input: Tensor,
  5214. dim: _int | _size = (),
  5215. keepdim: _bool = False,
  5216. *,
  5217. out: Tensor | None = None,
  5218. ) -> Tensor:
  5219. r"""
  5220. amin(input, dim, keepdim=False, *, out=None) -> Tensor
  5221. Returns the minimum value of each slice of the :attr:`input` tensor in the given
  5222. dimension(s) :attr:`dim`.
  5223. .. note::
  5224. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  5225. - ``amax``/``amin`` supports reducing on multiple dimensions,
  5226. - ``amax``/``amin`` does not return indices.
  5227. Both ``amax``/``amin`` evenly distribute gradients between equal values
  5228. when there are multiple input elements with the same minimum or maximum value.
  5229. For ``max``/``min``:
  5230. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  5231. - If reduce over one specified axis, only propagate to the indexed element.
  5232. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  5233. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  5234. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  5235. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  5236. Args:
  5237. input (Tensor): the input tensor.
  5238. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  5239. If ``None``, all dimensions are reduced.
  5240. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5241. Keyword args:
  5242. out (Tensor, optional): the output tensor.
  5243. Example::
  5244. >>> a = torch.randn(4, 4)
  5245. >>> a
  5246. tensor([[ 0.6451, -0.4866, 0.2987, -1.3312],
  5247. [-0.5744, 1.2980, 1.8397, -0.2713],
  5248. [ 0.9128, 0.9214, -1.7268, -0.2995],
  5249. [ 0.9023, 0.4853, 0.9075, -1.6165]])
  5250. >>> torch.amin(a, 1)
  5251. tensor([-1.3312, -0.5744, -1.7268, -1.6165])
  5252. """
  5253. def aminmax(
  5254. input: Tensor,
  5255. *,
  5256. dim: _int | None = None,
  5257. keepdim: _bool = False,
  5258. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  5259. ) -> torch.return_types.aminmax:
  5260. r"""
  5261. aminmax(input, *, dim=None, keepdim=False, out=None) -> (Tensor min, Tensor max)
  5262. Computes the minimum and maximum values of the :attr:`input` tensor.
  5263. Args:
  5264. input (Tensor):
  5265. The input tensor
  5266. Keyword Args:
  5267. dim (Optional[int]):
  5268. The dimension along which to compute the values. If `None`,
  5269. computes the values over the entire :attr:`input` tensor.
  5270. Default is `None`.
  5271. keepdim (bool):
  5272. If `True`, the reduced dimensions will be kept in the output
  5273. tensor as dimensions with size 1 for broadcasting, otherwise
  5274. they will be removed, as if calling (:func:`torch.squeeze`).
  5275. Default is `False`.
  5276. out (Optional[Tuple[Tensor, Tensor]]):
  5277. Optional tensors on which to write the result. Must have the same
  5278. shape and dtype as the expected output.
  5279. Default is `None`.
  5280. Returns:
  5281. A named tuple `(min, max)` containing the minimum and maximum values.
  5282. Raises:
  5283. RuntimeError
  5284. If any of the dimensions to compute the values over has size 0.
  5285. .. note::
  5286. NaN values are propagated to the output if at least one value is NaN.
  5287. .. seealso::
  5288. :func:`torch.amin` computes just the minimum value
  5289. :func:`torch.amax` computes just the maximum value
  5290. Example::
  5291. >>> torch.aminmax(torch.tensor([1, -3, 5]))
  5292. torch.return_types.aminmax(
  5293. min=tensor(-3),
  5294. max=tensor(5))
  5295. >>> # aminmax propagates NaNs
  5296. >>> torch.aminmax(torch.tensor([1, -3, 5, torch.nan]))
  5297. torch.return_types.aminmax(
  5298. min=tensor(nan),
  5299. max=tensor(nan))
  5300. >>> t = torch.arange(10).view(2, 5)
  5301. >>> t
  5302. tensor([[0, 1, 2, 3, 4],
  5303. [5, 6, 7, 8, 9]])
  5304. >>> t.aminmax(dim=0, keepdim=True)
  5305. torch.return_types.aminmax(
  5306. min=tensor([[0, 1, 2, 3, 4]]),
  5307. max=tensor([[5, 6, 7, 8, 9]]))
  5308. """
  5309. def angle(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  5310. r"""
  5311. angle(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5312. Computes the element-wise angle (in radians) of the given :attr:`input` tensor.
  5313. .. math::
  5314. \text{out}_{i} = angle(\text{input}_{i})
  5315. Args:
  5316. input (Tensor): the input tensor.
  5317. Keyword args:
  5318. out (Tensor, optional): the output tensor.
  5319. .. note:: Starting in PyTorch 1.8, angle returns pi for negative real numbers,
  5320. zero for non-negative real numbers, and propagates NaNs. Previously
  5321. the function would return zero for all real numbers and not propagate
  5322. floating-point NaNs.
  5323. Example::
  5324. >>> torch.angle(torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j]))*180/3.14159
  5325. tensor([ 135., 135, -45])
  5326. """
  5327. @overload
  5328. def any(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  5329. r"""
  5330. any(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5331. Tests if any element in :attr:`input` evaluates to `True`.
  5332. .. note:: This function matches the behaviour of NumPy in returning
  5333. output of dtype `bool` for all supported dtypes except `uint8`.
  5334. For `uint8` the dtype of output is `uint8` itself.
  5335. Args:
  5336. input (Tensor): the input tensor.
  5337. Keyword args:
  5338. out (Tensor, optional): the output tensor.
  5339. Example::
  5340. >>> a = torch.rand(1, 2).bool()
  5341. >>> a
  5342. tensor([[False, True]], dtype=torch.bool)
  5343. >>> torch.any(a)
  5344. tensor(True, dtype=torch.bool)
  5345. >>> a = torch.arange(0, 3)
  5346. >>> a
  5347. tensor([0, 1, 2])
  5348. >>> torch.any(a)
  5349. tensor(True)
  5350. .. function:: any(input, dim, keepdim=False, *, out=None) -> Tensor
  5351. :noindex:
  5352. For each row of :attr:`input` in the given dimension :attr:`dim`,
  5353. returns `True` if any element in the row evaluate to `True` and `False` otherwise.
  5354. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  5355. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  5356. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  5357. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  5358. Args:
  5359. input (Tensor): the input tensor.
  5360. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  5361. If ``None``, all dimensions are reduced.
  5362. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5363. Keyword args:
  5364. out (Tensor, optional): the output tensor.
  5365. Example::
  5366. >>> a = torch.randn(4, 2) < 0
  5367. >>> a
  5368. tensor([[ True, True],
  5369. [False, True],
  5370. [ True, True],
  5371. [False, False]])
  5372. >>> torch.any(a, 1)
  5373. tensor([ True, True, True, False])
  5374. >>> torch.any(a, 0)
  5375. tensor([True, True])
  5376. """
  5377. @overload
  5378. def any(
  5379. input: Tensor,
  5380. dim: _size | None = None,
  5381. keepdim: _bool = False,
  5382. *,
  5383. out: Tensor | None = None,
  5384. ) -> Tensor:
  5385. r"""
  5386. any(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5387. Tests if any element in :attr:`input` evaluates to `True`.
  5388. .. note:: This function matches the behaviour of NumPy in returning
  5389. output of dtype `bool` for all supported dtypes except `uint8`.
  5390. For `uint8` the dtype of output is `uint8` itself.
  5391. Args:
  5392. input (Tensor): the input tensor.
  5393. Keyword args:
  5394. out (Tensor, optional): the output tensor.
  5395. Example::
  5396. >>> a = torch.rand(1, 2).bool()
  5397. >>> a
  5398. tensor([[False, True]], dtype=torch.bool)
  5399. >>> torch.any(a)
  5400. tensor(True, dtype=torch.bool)
  5401. >>> a = torch.arange(0, 3)
  5402. >>> a
  5403. tensor([0, 1, 2])
  5404. >>> torch.any(a)
  5405. tensor(True)
  5406. .. function:: any(input, dim, keepdim=False, *, out=None) -> Tensor
  5407. :noindex:
  5408. For each row of :attr:`input` in the given dimension :attr:`dim`,
  5409. returns `True` if any element in the row evaluate to `True` and `False` otherwise.
  5410. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  5411. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  5412. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  5413. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  5414. Args:
  5415. input (Tensor): the input tensor.
  5416. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  5417. If ``None``, all dimensions are reduced.
  5418. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5419. Keyword args:
  5420. out (Tensor, optional): the output tensor.
  5421. Example::
  5422. >>> a = torch.randn(4, 2) < 0
  5423. >>> a
  5424. tensor([[ True, True],
  5425. [False, True],
  5426. [ True, True],
  5427. [False, False]])
  5428. >>> torch.any(a, 1)
  5429. tensor([ True, True, True, False])
  5430. >>> torch.any(a, 0)
  5431. tensor([True, True])
  5432. """
  5433. @overload
  5434. def any(
  5435. input: Tensor,
  5436. dim: _int,
  5437. keepdim: _bool = False,
  5438. *,
  5439. out: Tensor | None = None,
  5440. ) -> Tensor:
  5441. r"""
  5442. any(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5443. Tests if any element in :attr:`input` evaluates to `True`.
  5444. .. note:: This function matches the behaviour of NumPy in returning
  5445. output of dtype `bool` for all supported dtypes except `uint8`.
  5446. For `uint8` the dtype of output is `uint8` itself.
  5447. Args:
  5448. input (Tensor): the input tensor.
  5449. Keyword args:
  5450. out (Tensor, optional): the output tensor.
  5451. Example::
  5452. >>> a = torch.rand(1, 2).bool()
  5453. >>> a
  5454. tensor([[False, True]], dtype=torch.bool)
  5455. >>> torch.any(a)
  5456. tensor(True, dtype=torch.bool)
  5457. >>> a = torch.arange(0, 3)
  5458. >>> a
  5459. tensor([0, 1, 2])
  5460. >>> torch.any(a)
  5461. tensor(True)
  5462. .. function:: any(input, dim, keepdim=False, *, out=None) -> Tensor
  5463. :noindex:
  5464. For each row of :attr:`input` in the given dimension :attr:`dim`,
  5465. returns `True` if any element in the row evaluate to `True` and `False` otherwise.
  5466. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  5467. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  5468. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  5469. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  5470. Args:
  5471. input (Tensor): the input tensor.
  5472. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  5473. If ``None``, all dimensions are reduced.
  5474. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5475. Keyword args:
  5476. out (Tensor, optional): the output tensor.
  5477. Example::
  5478. >>> a = torch.randn(4, 2) < 0
  5479. >>> a
  5480. tensor([[ True, True],
  5481. [False, True],
  5482. [ True, True],
  5483. [False, False]])
  5484. >>> torch.any(a, 1)
  5485. tensor([ True, True, True, False])
  5486. >>> torch.any(a, 0)
  5487. tensor([True, True])
  5488. """
  5489. @overload
  5490. def any(
  5491. input: Tensor,
  5492. dim: str | EllipsisType | None,
  5493. keepdim: _bool = False,
  5494. *,
  5495. out: Tensor | None = None,
  5496. ) -> Tensor:
  5497. r"""
  5498. any(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5499. Tests if any element in :attr:`input` evaluates to `True`.
  5500. .. note:: This function matches the behaviour of NumPy in returning
  5501. output of dtype `bool` for all supported dtypes except `uint8`.
  5502. For `uint8` the dtype of output is `uint8` itself.
  5503. Args:
  5504. input (Tensor): the input tensor.
  5505. Keyword args:
  5506. out (Tensor, optional): the output tensor.
  5507. Example::
  5508. >>> a = torch.rand(1, 2).bool()
  5509. >>> a
  5510. tensor([[False, True]], dtype=torch.bool)
  5511. >>> torch.any(a)
  5512. tensor(True, dtype=torch.bool)
  5513. >>> a = torch.arange(0, 3)
  5514. >>> a
  5515. tensor([0, 1, 2])
  5516. >>> torch.any(a)
  5517. tensor(True)
  5518. .. function:: any(input, dim, keepdim=False, *, out=None) -> Tensor
  5519. :noindex:
  5520. For each row of :attr:`input` in the given dimension :attr:`dim`,
  5521. returns `True` if any element in the row evaluate to `True` and `False` otherwise.
  5522. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  5523. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  5524. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  5525. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  5526. Args:
  5527. input (Tensor): the input tensor.
  5528. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  5529. If ``None``, all dimensions are reduced.
  5530. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5531. Keyword args:
  5532. out (Tensor, optional): the output tensor.
  5533. Example::
  5534. >>> a = torch.randn(4, 2) < 0
  5535. >>> a
  5536. tensor([[ True, True],
  5537. [False, True],
  5538. [ True, True],
  5539. [False, False]])
  5540. >>> torch.any(a, 1)
  5541. tensor([ True, True, True, False])
  5542. >>> torch.any(a, 0)
  5543. tensor([True, True])
  5544. """
  5545. @overload
  5546. def arange(
  5547. start: Number,
  5548. end: Number,
  5549. step: Number,
  5550. *,
  5551. out: Tensor | None = None,
  5552. dtype: _dtype | None = None,
  5553. device: DeviceLikeType | None = None,
  5554. requires_grad: _bool = False,
  5555. pin_memory: _bool = False,
  5556. ) -> Tensor:
  5557. r"""
  5558. arange(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  5559. Returns a 1-D tensor of size :math:`\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil`
  5560. with values from the interval ``[start, end)`` taken with common difference
  5561. :attr:`step` beginning from `start`.
  5562. Note: When using floating-point dtypes (especially reduced precision types like ``bfloat16``),
  5563. the results may be affected by floating-point rounding behavior. Some values in the sequence
  5564. might not be exactly representable in certain floating-point formats, which can lead to
  5565. repeated values or unexpected rounding. For precise sequences, it is recommended to use
  5566. integer dtypes instead of floating-point dtypes.
  5567. Note that non-integer :attr:`step` is subject to floating point rounding errors when
  5568. comparing against :attr:`end`; to avoid inconsistency, we advise subtracting a small epsilon from :attr:`end`
  5569. in such cases.
  5570. .. math::
  5571. \text{out}_{{i+1}} = \text{out}_{i} + \text{step}
  5572. Args:
  5573. start (Number, optional): the starting value for the set of points. Default: ``0``.
  5574. end (Number): the ending value for the set of points
  5575. step (Number, optional): the gap between each pair of adjacent points. Default: ``1``.
  5576. Keyword args:
  5577. out (Tensor, optional): the output tensor.
  5578. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  5579. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). If `dtype` is not given, infer the data type from the other input
  5580. arguments. If any of `start`, `end`, or `stop` are floating-point, the
  5581. `dtype` is inferred to be the default dtype, see
  5582. :meth:`~torch.get_default_dtype`. Otherwise, the `dtype` is inferred to
  5583. be `torch.int64`.
  5584. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  5585. Default: ``torch.strided``.
  5586. device (:class:`torch.device`, optional): the desired device of returned tensor.
  5587. Default: if ``None``, uses the current device for the default tensor type
  5588. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  5589. for CPU tensor types and the current CUDA device for CUDA tensor types.
  5590. requires_grad (bool, optional): If autograd should record operations on the
  5591. returned tensor. Default: ``False``.
  5592. Example::
  5593. >>> torch.arange(5)
  5594. tensor([ 0, 1, 2, 3, 4])
  5595. >>> torch.arange(1, 4)
  5596. tensor([ 1, 2, 3])
  5597. >>> torch.arange(1, 2.5, 0.5)
  5598. tensor([ 1.0000, 1.5000, 2.0000])
  5599. """
  5600. @overload
  5601. def arange(
  5602. start: Number,
  5603. end: Number,
  5604. *,
  5605. out: Tensor | None = None,
  5606. dtype: _dtype | None = None,
  5607. device: DeviceLikeType | None = None,
  5608. requires_grad: _bool = False,
  5609. pin_memory: _bool = False,
  5610. ) -> Tensor:
  5611. r"""
  5612. arange(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  5613. Returns a 1-D tensor of size :math:`\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil`
  5614. with values from the interval ``[start, end)`` taken with common difference
  5615. :attr:`step` beginning from `start`.
  5616. Note: When using floating-point dtypes (especially reduced precision types like ``bfloat16``),
  5617. the results may be affected by floating-point rounding behavior. Some values in the sequence
  5618. might not be exactly representable in certain floating-point formats, which can lead to
  5619. repeated values or unexpected rounding. For precise sequences, it is recommended to use
  5620. integer dtypes instead of floating-point dtypes.
  5621. Note that non-integer :attr:`step` is subject to floating point rounding errors when
  5622. comparing against :attr:`end`; to avoid inconsistency, we advise subtracting a small epsilon from :attr:`end`
  5623. in such cases.
  5624. .. math::
  5625. \text{out}_{{i+1}} = \text{out}_{i} + \text{step}
  5626. Args:
  5627. start (Number, optional): the starting value for the set of points. Default: ``0``.
  5628. end (Number): the ending value for the set of points
  5629. step (Number, optional): the gap between each pair of adjacent points. Default: ``1``.
  5630. Keyword args:
  5631. out (Tensor, optional): the output tensor.
  5632. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  5633. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). If `dtype` is not given, infer the data type from the other input
  5634. arguments. If any of `start`, `end`, or `stop` are floating-point, the
  5635. `dtype` is inferred to be the default dtype, see
  5636. :meth:`~torch.get_default_dtype`. Otherwise, the `dtype` is inferred to
  5637. be `torch.int64`.
  5638. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  5639. Default: ``torch.strided``.
  5640. device (:class:`torch.device`, optional): the desired device of returned tensor.
  5641. Default: if ``None``, uses the current device for the default tensor type
  5642. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  5643. for CPU tensor types and the current CUDA device for CUDA tensor types.
  5644. requires_grad (bool, optional): If autograd should record operations on the
  5645. returned tensor. Default: ``False``.
  5646. Example::
  5647. >>> torch.arange(5)
  5648. tensor([ 0, 1, 2, 3, 4])
  5649. >>> torch.arange(1, 4)
  5650. tensor([ 1, 2, 3])
  5651. >>> torch.arange(1, 2.5, 0.5)
  5652. tensor([ 1.0000, 1.5000, 2.0000])
  5653. """
  5654. @overload
  5655. def arange(
  5656. end: Number,
  5657. *,
  5658. out: Tensor | None = None,
  5659. dtype: _dtype | None = None,
  5660. device: DeviceLikeType | None = None,
  5661. requires_grad: _bool = False,
  5662. pin_memory: _bool = False,
  5663. ) -> Tensor:
  5664. r"""
  5665. arange(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  5666. Returns a 1-D tensor of size :math:`\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil`
  5667. with values from the interval ``[start, end)`` taken with common difference
  5668. :attr:`step` beginning from `start`.
  5669. Note: When using floating-point dtypes (especially reduced precision types like ``bfloat16``),
  5670. the results may be affected by floating-point rounding behavior. Some values in the sequence
  5671. might not be exactly representable in certain floating-point formats, which can lead to
  5672. repeated values or unexpected rounding. For precise sequences, it is recommended to use
  5673. integer dtypes instead of floating-point dtypes.
  5674. Note that non-integer :attr:`step` is subject to floating point rounding errors when
  5675. comparing against :attr:`end`; to avoid inconsistency, we advise subtracting a small epsilon from :attr:`end`
  5676. in such cases.
  5677. .. math::
  5678. \text{out}_{{i+1}} = \text{out}_{i} + \text{step}
  5679. Args:
  5680. start (Number, optional): the starting value for the set of points. Default: ``0``.
  5681. end (Number): the ending value for the set of points
  5682. step (Number, optional): the gap between each pair of adjacent points. Default: ``1``.
  5683. Keyword args:
  5684. out (Tensor, optional): the output tensor.
  5685. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  5686. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). If `dtype` is not given, infer the data type from the other input
  5687. arguments. If any of `start`, `end`, or `stop` are floating-point, the
  5688. `dtype` is inferred to be the default dtype, see
  5689. :meth:`~torch.get_default_dtype`. Otherwise, the `dtype` is inferred to
  5690. be `torch.int64`.
  5691. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  5692. Default: ``torch.strided``.
  5693. device (:class:`torch.device`, optional): the desired device of returned tensor.
  5694. Default: if ``None``, uses the current device for the default tensor type
  5695. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  5696. for CPU tensor types and the current CUDA device for CUDA tensor types.
  5697. requires_grad (bool, optional): If autograd should record operations on the
  5698. returned tensor. Default: ``False``.
  5699. Example::
  5700. >>> torch.arange(5)
  5701. tensor([ 0, 1, 2, 3, 4])
  5702. >>> torch.arange(1, 4)
  5703. tensor([ 1, 2, 3])
  5704. >>> torch.arange(1, 2.5, 0.5)
  5705. tensor([ 1.0000, 1.5000, 2.0000])
  5706. """
  5707. @overload
  5708. def arange(
  5709. end: Number | _complex,
  5710. *,
  5711. out: Tensor | None = None,
  5712. dtype: _dtype | None = None,
  5713. layout: _layout | None = None,
  5714. device: DeviceLikeType | None = None,
  5715. pin_memory: _bool | None = False,
  5716. requires_grad: _bool | None = False,
  5717. ) -> Tensor:
  5718. r"""
  5719. arange(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  5720. Returns a 1-D tensor of size :math:`\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil`
  5721. with values from the interval ``[start, end)`` taken with common difference
  5722. :attr:`step` beginning from `start`.
  5723. Note: When using floating-point dtypes (especially reduced precision types like ``bfloat16``),
  5724. the results may be affected by floating-point rounding behavior. Some values in the sequence
  5725. might not be exactly representable in certain floating-point formats, which can lead to
  5726. repeated values or unexpected rounding. For precise sequences, it is recommended to use
  5727. integer dtypes instead of floating-point dtypes.
  5728. Note that non-integer :attr:`step` is subject to floating point rounding errors when
  5729. comparing against :attr:`end`; to avoid inconsistency, we advise subtracting a small epsilon from :attr:`end`
  5730. in such cases.
  5731. .. math::
  5732. \text{out}_{{i+1}} = \text{out}_{i} + \text{step}
  5733. Args:
  5734. start (Number, optional): the starting value for the set of points. Default: ``0``.
  5735. end (Number): the ending value for the set of points
  5736. step (Number, optional): the gap between each pair of adjacent points. Default: ``1``.
  5737. Keyword args:
  5738. out (Tensor, optional): the output tensor.
  5739. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  5740. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). If `dtype` is not given, infer the data type from the other input
  5741. arguments. If any of `start`, `end`, or `stop` are floating-point, the
  5742. `dtype` is inferred to be the default dtype, see
  5743. :meth:`~torch.get_default_dtype`. Otherwise, the `dtype` is inferred to
  5744. be `torch.int64`.
  5745. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  5746. Default: ``torch.strided``.
  5747. device (:class:`torch.device`, optional): the desired device of returned tensor.
  5748. Default: if ``None``, uses the current device for the default tensor type
  5749. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  5750. for CPU tensor types and the current CUDA device for CUDA tensor types.
  5751. requires_grad (bool, optional): If autograd should record operations on the
  5752. returned tensor. Default: ``False``.
  5753. Example::
  5754. >>> torch.arange(5)
  5755. tensor([ 0, 1, 2, 3, 4])
  5756. >>> torch.arange(1, 4)
  5757. tensor([ 1, 2, 3])
  5758. >>> torch.arange(1, 2.5, 0.5)
  5759. tensor([ 1.0000, 1.5000, 2.0000])
  5760. """
  5761. @overload
  5762. def arange(
  5763. start: Number | _complex,
  5764. end: Number | _complex,
  5765. *,
  5766. dtype: _dtype | None = None,
  5767. layout: _layout | None = None,
  5768. device: DeviceLikeType | None = None,
  5769. pin_memory: _bool | None = False,
  5770. requires_grad: _bool | None = False,
  5771. ) -> Tensor:
  5772. r"""
  5773. arange(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  5774. Returns a 1-D tensor of size :math:`\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil`
  5775. with values from the interval ``[start, end)`` taken with common difference
  5776. :attr:`step` beginning from `start`.
  5777. Note: When using floating-point dtypes (especially reduced precision types like ``bfloat16``),
  5778. the results may be affected by floating-point rounding behavior. Some values in the sequence
  5779. might not be exactly representable in certain floating-point formats, which can lead to
  5780. repeated values or unexpected rounding. For precise sequences, it is recommended to use
  5781. integer dtypes instead of floating-point dtypes.
  5782. Note that non-integer :attr:`step` is subject to floating point rounding errors when
  5783. comparing against :attr:`end`; to avoid inconsistency, we advise subtracting a small epsilon from :attr:`end`
  5784. in such cases.
  5785. .. math::
  5786. \text{out}_{{i+1}} = \text{out}_{i} + \text{step}
  5787. Args:
  5788. start (Number, optional): the starting value for the set of points. Default: ``0``.
  5789. end (Number): the ending value for the set of points
  5790. step (Number, optional): the gap between each pair of adjacent points. Default: ``1``.
  5791. Keyword args:
  5792. out (Tensor, optional): the output tensor.
  5793. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  5794. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). If `dtype` is not given, infer the data type from the other input
  5795. arguments. If any of `start`, `end`, or `stop` are floating-point, the
  5796. `dtype` is inferred to be the default dtype, see
  5797. :meth:`~torch.get_default_dtype`. Otherwise, the `dtype` is inferred to
  5798. be `torch.int64`.
  5799. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  5800. Default: ``torch.strided``.
  5801. device (:class:`torch.device`, optional): the desired device of returned tensor.
  5802. Default: if ``None``, uses the current device for the default tensor type
  5803. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  5804. for CPU tensor types and the current CUDA device for CUDA tensor types.
  5805. requires_grad (bool, optional): If autograd should record operations on the
  5806. returned tensor. Default: ``False``.
  5807. Example::
  5808. >>> torch.arange(5)
  5809. tensor([ 0, 1, 2, 3, 4])
  5810. >>> torch.arange(1, 4)
  5811. tensor([ 1, 2, 3])
  5812. >>> torch.arange(1, 2.5, 0.5)
  5813. tensor([ 1.0000, 1.5000, 2.0000])
  5814. """
  5815. @overload
  5816. def arange(
  5817. start: Number | _complex,
  5818. end: Number | _complex,
  5819. step: Number | _complex = 1,
  5820. *,
  5821. out: Tensor | None = None,
  5822. dtype: _dtype | None = None,
  5823. layout: _layout | None = None,
  5824. device: DeviceLikeType | None = None,
  5825. pin_memory: _bool | None = False,
  5826. requires_grad: _bool | None = False,
  5827. ) -> Tensor:
  5828. r"""
  5829. arange(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  5830. Returns a 1-D tensor of size :math:`\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil`
  5831. with values from the interval ``[start, end)`` taken with common difference
  5832. :attr:`step` beginning from `start`.
  5833. Note: When using floating-point dtypes (especially reduced precision types like ``bfloat16``),
  5834. the results may be affected by floating-point rounding behavior. Some values in the sequence
  5835. might not be exactly representable in certain floating-point formats, which can lead to
  5836. repeated values or unexpected rounding. For precise sequences, it is recommended to use
  5837. integer dtypes instead of floating-point dtypes.
  5838. Note that non-integer :attr:`step` is subject to floating point rounding errors when
  5839. comparing against :attr:`end`; to avoid inconsistency, we advise subtracting a small epsilon from :attr:`end`
  5840. in such cases.
  5841. .. math::
  5842. \text{out}_{{i+1}} = \text{out}_{i} + \text{step}
  5843. Args:
  5844. start (Number, optional): the starting value for the set of points. Default: ``0``.
  5845. end (Number): the ending value for the set of points
  5846. step (Number, optional): the gap between each pair of adjacent points. Default: ``1``.
  5847. Keyword args:
  5848. out (Tensor, optional): the output tensor.
  5849. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  5850. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). If `dtype` is not given, infer the data type from the other input
  5851. arguments. If any of `start`, `end`, or `stop` are floating-point, the
  5852. `dtype` is inferred to be the default dtype, see
  5853. :meth:`~torch.get_default_dtype`. Otherwise, the `dtype` is inferred to
  5854. be `torch.int64`.
  5855. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  5856. Default: ``torch.strided``.
  5857. device (:class:`torch.device`, optional): the desired device of returned tensor.
  5858. Default: if ``None``, uses the current device for the default tensor type
  5859. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  5860. for CPU tensor types and the current CUDA device for CUDA tensor types.
  5861. requires_grad (bool, optional): If autograd should record operations on the
  5862. returned tensor. Default: ``False``.
  5863. Example::
  5864. >>> torch.arange(5)
  5865. tensor([ 0, 1, 2, 3, 4])
  5866. >>> torch.arange(1, 4)
  5867. tensor([ 1, 2, 3])
  5868. >>> torch.arange(1, 2.5, 0.5)
  5869. tensor([ 1.0000, 1.5000, 2.0000])
  5870. """
  5871. def arccos(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  5872. r"""
  5873. arccos(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5874. Alias for :func:`torch.acos`.
  5875. """
  5876. def arccos_(input: Tensor) -> Tensor: ...
  5877. def arccosh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  5878. r"""
  5879. arccosh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5880. Alias for :func:`torch.acosh`.
  5881. """
  5882. def arccosh_(input: Tensor) -> Tensor: ...
  5883. def arcsin(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  5884. r"""
  5885. arcsin(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5886. Alias for :func:`torch.asin`.
  5887. """
  5888. def arcsin_(input: Tensor) -> Tensor: ...
  5889. def arcsinh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  5890. r"""
  5891. arcsinh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5892. Alias for :func:`torch.asinh`.
  5893. """
  5894. def arcsinh_(input: Tensor) -> Tensor: ...
  5895. def arctan(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  5896. r"""
  5897. arctan(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5898. Alias for :func:`torch.atan`.
  5899. """
  5900. def arctan2(
  5901. input: Tensor,
  5902. other: Tensor,
  5903. *,
  5904. out: Tensor | None = None,
  5905. ) -> Tensor:
  5906. r"""
  5907. arctan2(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
  5908. Alias for :func:`torch.atan2`.
  5909. """
  5910. def arctan_(input: Tensor) -> Tensor: ...
  5911. def arctanh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  5912. r"""
  5913. arctanh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5914. Alias for :func:`torch.atanh`.
  5915. """
  5916. def arctanh_(input: Tensor) -> Tensor: ...
  5917. def argmax(
  5918. input: Tensor,
  5919. dim: _int | None = None,
  5920. keepdim: _bool = False,
  5921. *,
  5922. out: Tensor | None = None,
  5923. ) -> Tensor:
  5924. r"""
  5925. argmax(input) -> LongTensor
  5926. Returns the indices of the maximum value of all elements in the :attr:`input` tensor.
  5927. This is the second value returned by :meth:`torch.max`. See its
  5928. documentation for the exact semantics of this method.
  5929. .. note:: If there are multiple maximal values then the indices of the first maximal value are returned.
  5930. Args:
  5931. input (Tensor): the input tensor.
  5932. Example::
  5933. >>> a = torch.randn(4, 4)
  5934. >>> a
  5935. tensor([[ 1.3398, 0.2663, -0.2686, 0.2450],
  5936. [-0.7401, -0.8805, -0.3402, -1.1936],
  5937. [ 0.4907, -1.3948, -1.0691, -0.3132],
  5938. [-1.6092, 0.5419, -0.2993, 0.3195]])
  5939. >>> torch.argmax(a)
  5940. tensor(0)
  5941. .. function:: argmax(input, dim, keepdim=False) -> LongTensor
  5942. :noindex:
  5943. Returns the indices of the maximum values of a tensor across a dimension.
  5944. This is the second value returned by :meth:`torch.max`. See its
  5945. documentation for the exact semantics of this method.
  5946. Args:
  5947. input (Tensor): the input tensor.
  5948. dim (int, optional): the dimension to reduce.
  5949. If ``None``, the argmax of the flattened input is returned.
  5950. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5951. Example::
  5952. >>> a = torch.randn(4, 4)
  5953. >>> a
  5954. tensor([[ 1.3398, 0.2663, -0.2686, 0.2450],
  5955. [-0.7401, -0.8805, -0.3402, -1.1936],
  5956. [ 0.4907, -1.3948, -1.0691, -0.3132],
  5957. [-1.6092, 0.5419, -0.2993, 0.3195]])
  5958. >>> torch.argmax(a, dim=1)
  5959. tensor([ 0, 2, 0, 1])
  5960. """
  5961. def argmin(
  5962. input: Tensor,
  5963. dim: _int | None = None,
  5964. keepdim: _bool = False,
  5965. *,
  5966. out: Tensor | None = None,
  5967. ) -> Tensor:
  5968. r"""
  5969. argmin(input, dim=None, keepdim=False) -> LongTensor
  5970. Returns the indices of the minimum value(s) of the flattened tensor or along a dimension
  5971. This is the second value returned by :meth:`torch.min`. See its
  5972. documentation for the exact semantics of this method.
  5973. .. note:: If there are multiple minimal values then the indices of the first minimal value are returned.
  5974. Args:
  5975. input (Tensor): the input tensor.
  5976. dim (int, optional): the dimension to reduce.
  5977. If ``None``, the argmin of the flattened input is returned.
  5978. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5979. Example::
  5980. >>> a = torch.randn(4, 4)
  5981. >>> a
  5982. tensor([[ 0.1139, 0.2254, -0.1381, 0.3687],
  5983. [ 1.0100, -1.1975, -0.0102, -0.4732],
  5984. [-0.9240, 0.1207, -0.7506, -1.0213],
  5985. [ 1.7809, -1.2960, 0.9384, 0.1438]])
  5986. >>> torch.argmin(a)
  5987. tensor(13)
  5988. >>> torch.argmin(a, dim=1)
  5989. tensor([ 2, 1, 3, 1])
  5990. >>> torch.argmin(a, dim=1, keepdim=True)
  5991. tensor([[2],
  5992. [1],
  5993. [3],
  5994. [1]])
  5995. """
  5996. @overload
  5997. def argsort(
  5998. input: Tensor,
  5999. *,
  6000. stable: _bool,
  6001. dim: _int = -1,
  6002. descending: _bool = False,
  6003. out: Tensor | None = None,
  6004. ) -> Tensor:
  6005. r"""
  6006. argsort(input, dim=-1, descending=False, *, stable=False) -> Tensor
  6007. Returns the indices that sort a tensor along a given dimension in ascending
  6008. order by value.
  6009. This is the second value returned by :meth:`torch.sort`. See its documentation
  6010. for the exact semantics of this method.
  6011. If :attr:`stable` is ``True`` then the sorting routine becomes stable, preserving
  6012. the order of equivalent elements. If ``False``, the relative order of values
  6013. which compare equal is not guaranteed. ``True`` is slower.
  6014. Args:
  6015. input (Tensor): the input tensor.
  6016. dim (int, optional): the dimension to sort along
  6017. descending (bool, optional): controls the sorting order (ascending or descending)
  6018. Keyword args:
  6019. stable (bool, optional): controls the relative order of equivalent elements
  6020. Example::
  6021. >>> a = torch.randn(4, 4)
  6022. >>> a
  6023. tensor([[ 0.0785, 1.5267, -0.8521, 0.4065],
  6024. [ 0.1598, 0.0788, -0.0745, -1.2700],
  6025. [ 1.2208, 1.0722, -0.7064, 1.2564],
  6026. [ 0.0669, -0.2318, -0.8229, -0.9280]])
  6027. >>> torch.argsort(a, dim=1)
  6028. tensor([[2, 0, 3, 1],
  6029. [3, 2, 1, 0],
  6030. [2, 1, 0, 3],
  6031. [3, 2, 1, 0]])
  6032. """
  6033. @overload
  6034. def argsort(
  6035. input: Tensor,
  6036. dim: _int = -1,
  6037. descending: _bool = False,
  6038. ) -> Tensor:
  6039. r"""
  6040. argsort(input, dim=-1, descending=False, *, stable=False) -> Tensor
  6041. Returns the indices that sort a tensor along a given dimension in ascending
  6042. order by value.
  6043. This is the second value returned by :meth:`torch.sort`. See its documentation
  6044. for the exact semantics of this method.
  6045. If :attr:`stable` is ``True`` then the sorting routine becomes stable, preserving
  6046. the order of equivalent elements. If ``False``, the relative order of values
  6047. which compare equal is not guaranteed. ``True`` is slower.
  6048. Args:
  6049. input (Tensor): the input tensor.
  6050. dim (int, optional): the dimension to sort along
  6051. descending (bool, optional): controls the sorting order (ascending or descending)
  6052. Keyword args:
  6053. stable (bool, optional): controls the relative order of equivalent elements
  6054. Example::
  6055. >>> a = torch.randn(4, 4)
  6056. >>> a
  6057. tensor([[ 0.0785, 1.5267, -0.8521, 0.4065],
  6058. [ 0.1598, 0.0788, -0.0745, -1.2700],
  6059. [ 1.2208, 1.0722, -0.7064, 1.2564],
  6060. [ 0.0669, -0.2318, -0.8229, -0.9280]])
  6061. >>> torch.argsort(a, dim=1)
  6062. tensor([[2, 0, 3, 1],
  6063. [3, 2, 1, 0],
  6064. [2, 1, 0, 3],
  6065. [3, 2, 1, 0]])
  6066. """
  6067. @overload
  6068. def argsort(
  6069. input: Tensor,
  6070. dim: str | EllipsisType | None,
  6071. descending: _bool = False,
  6072. ) -> Tensor:
  6073. r"""
  6074. argsort(input, dim=-1, descending=False, *, stable=False) -> Tensor
  6075. Returns the indices that sort a tensor along a given dimension in ascending
  6076. order by value.
  6077. This is the second value returned by :meth:`torch.sort`. See its documentation
  6078. for the exact semantics of this method.
  6079. If :attr:`stable` is ``True`` then the sorting routine becomes stable, preserving
  6080. the order of equivalent elements. If ``False``, the relative order of values
  6081. which compare equal is not guaranteed. ``True`` is slower.
  6082. Args:
  6083. input (Tensor): the input tensor.
  6084. dim (int, optional): the dimension to sort along
  6085. descending (bool, optional): controls the sorting order (ascending or descending)
  6086. Keyword args:
  6087. stable (bool, optional): controls the relative order of equivalent elements
  6088. Example::
  6089. >>> a = torch.randn(4, 4)
  6090. >>> a
  6091. tensor([[ 0.0785, 1.5267, -0.8521, 0.4065],
  6092. [ 0.1598, 0.0788, -0.0745, -1.2700],
  6093. [ 1.2208, 1.0722, -0.7064, 1.2564],
  6094. [ 0.0669, -0.2318, -0.8229, -0.9280]])
  6095. >>> torch.argsort(a, dim=1)
  6096. tensor([[2, 0, 3, 1],
  6097. [3, 2, 1, 0],
  6098. [2, 1, 0, 3],
  6099. [3, 2, 1, 0]])
  6100. """
  6101. def argwhere(input: Tensor) -> Tensor:
  6102. r"""
  6103. argwhere(input) -> Tensor
  6104. Returns a tensor containing the indices of all non-zero elements of
  6105. :attr:`input`. Each row in the result contains the indices of a non-zero
  6106. element in :attr:`input`. The result is sorted lexicographically, with
  6107. the last index changing the fastest (C-style).
  6108. If :attr:`input` has :math:`n` dimensions, then the resulting indices tensor
  6109. :attr:`out` is of size :math:`(z \times n)`, where :math:`z` is the total number of
  6110. non-zero elements in the :attr:`input` tensor.
  6111. .. note::
  6112. This function is similar to NumPy's `argwhere`.
  6113. When :attr:`input` is on CUDA, this function causes host-device synchronization.
  6114. Args:
  6115. {input}
  6116. Example::
  6117. >>> t = torch.tensor([1, 0, 1])
  6118. >>> torch.argwhere(t)
  6119. tensor([[0],
  6120. [2]])
  6121. >>> t = torch.tensor([[1, 0, 1], [0, 1, 1]])
  6122. >>> torch.argwhere(t)
  6123. tensor([[0, 0],
  6124. [0, 2],
  6125. [1, 1],
  6126. [1, 2]])
  6127. """
  6128. def as_strided(
  6129. input: Tensor,
  6130. size: Sequence[_int | SymInt],
  6131. stride: Sequence[_int | SymInt],
  6132. storage_offset: _int | SymInt | None = None,
  6133. ) -> Tensor:
  6134. r"""
  6135. as_strided(input, size, stride, storage_offset=None) -> Tensor
  6136. Create a view of an existing `torch.Tensor` :attr:`input` with specified
  6137. :attr:`size`, :attr:`stride` and :attr:`storage_offset`.
  6138. .. warning::
  6139. Prefer using other view functions, like :meth:`torch.Tensor.view` or
  6140. :meth:`torch.Tensor.expand`, to setting a view's strides manually with
  6141. `as_strided`, as this function will throw an error on non-standard Pytorch
  6142. backends (that do not have a concept of stride) and the result will depend
  6143. on the current layout in memory. The constructed view must only refer to
  6144. elements within the Tensor's storage or a runtime error will be thrown.
  6145. If the generated view is "overlapped" (with multiple indices referring to
  6146. the same element in memory), the behavior of inplace operations on this view
  6147. is undefined (and might not throw runtime errors).
  6148. Args:
  6149. input (Tensor): the input tensor.
  6150. size (tuple or ints): the shape of the output tensor
  6151. stride (tuple or ints): the stride of the output tensor
  6152. storage_offset (int, optional): the offset in the underlying storage of the output tensor.
  6153. If ``None``, the storage_offset of the output tensor will match the input tensor.
  6154. Example::
  6155. >>> x = torch.randn(3, 3)
  6156. >>> x
  6157. tensor([[ 0.9039, 0.6291, 1.0795],
  6158. [ 0.1586, 2.1939, -0.4900],
  6159. [-0.1909, -0.7503, 1.9355]])
  6160. >>> t = torch.as_strided(x, (2, 2), (1, 2))
  6161. >>> t
  6162. tensor([[0.9039, 1.0795],
  6163. [0.6291, 0.1586]])
  6164. >>> t = torch.as_strided(x, (2, 2), (1, 2), 1)
  6165. tensor([[0.6291, 0.1586],
  6166. [1.0795, 2.1939]])
  6167. """
  6168. def as_strided_(
  6169. input: Tensor,
  6170. size: Sequence[_int | SymInt],
  6171. stride: Sequence[_int | SymInt],
  6172. storage_offset: _int | SymInt | None = None,
  6173. ) -> Tensor: ...
  6174. def as_strided_copy(
  6175. input: Tensor,
  6176. size: Sequence[_int | SymInt],
  6177. stride: Sequence[_int | SymInt],
  6178. storage_offset: _int | SymInt | None = None,
  6179. *,
  6180. out: Tensor | None = None,
  6181. ) -> Tensor:
  6182. r"""
  6183. Performs the same operation as :func:`torch.as_strided`, but all output tensors
  6184. are freshly created instead of aliasing the input.
  6185. """
  6186. def as_strided_scatter(
  6187. input: Tensor,
  6188. src: Tensor,
  6189. size: Sequence[_int | SymInt],
  6190. stride: Sequence[_int | SymInt],
  6191. storage_offset: _int | SymInt | None = None,
  6192. ) -> Tensor:
  6193. r"""
  6194. as_strided_scatter(input, src, size, stride, storage_offset=None) -> Tensor
  6195. Embeds the values of the :attr:`src` tensor into :attr:`input` along
  6196. the elements corresponding to the result of calling
  6197. input.as_strided(size, stride, storage_offset).
  6198. This function returns a tensor with fresh storage; it does not
  6199. return a view.
  6200. Args:
  6201. input (Tensor): the input tensor.
  6202. size (tuple or ints): the shape of the output tensor
  6203. stride (tuple or ints): the stride of the output tensor
  6204. storage_offset (int, optional): the offset in the underlying storage of the output tensor
  6205. .. note::
  6206. :attr:`src` must be of the proper size in order to be embedded
  6207. into :attr:`input`. Specifically, it should have the same shape as
  6208. `torch.as_strided(input, size, stride, storage_offset)`
  6209. Example::
  6210. >>> a = torch.arange(4).reshape(2, 2) + 1
  6211. >>> a
  6212. tensor([[1, 2],
  6213. [3, 4]])
  6214. >>> b = torch.zeros(3, 3)
  6215. >>> b
  6216. tensor([[0., 0., 0.],
  6217. [0., 0., 0.],
  6218. [0., 0., 0.]])
  6219. >>> torch.as_strided_scatter(b, a, (2, 2), (1, 2))
  6220. tensor([[1., 3., 2.],
  6221. [4., 0., 0.],
  6222. [0., 0., 0.]])
  6223. """
  6224. def as_tensor(
  6225. data: Any,
  6226. dtype: _dtype | None = None,
  6227. device: DeviceLikeType | None = None,
  6228. ) -> Tensor:
  6229. r"""
  6230. as_tensor(data: Any, *, dtype: Optional[dtype] = None, device: Optional[DeviceLikeType]) -> Tensor
  6231. Converts :attr:`data` into a tensor, sharing data and preserving autograd
  6232. history if possible.
  6233. If :attr:`data` is already a tensor with the requested dtype and device
  6234. then :attr:`data` itself is returned, but if :attr:`data` is a
  6235. tensor with a different dtype or device then it's copied as if using
  6236. `data.to(dtype=dtype, device=device)`.
  6237. If :attr:`data` is a NumPy array (an ndarray) with the same dtype and device then a
  6238. tensor is constructed using :func:`torch.from_numpy`.
  6239. If :attr:`data` is a CuPy array, the returned tensor will be located on the same device as the CuPy array unless
  6240. specifically overwritten by :attr:`device` or a default device. The device of the CuPy array is inferred from the
  6241. pointer of the array using `cudaPointerGetAttributes` unless :attr:`device` is provided with an explicit device index.
  6242. .. seealso::
  6243. :func:`torch.tensor` never shares its data and creates a new "leaf tensor" (see :doc:`/notes/autograd`).
  6244. Args:
  6245. data (array_like): Initial data for the tensor. Can be a list, tuple,
  6246. NumPy ``ndarray``, scalar, and other types.
  6247. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  6248. Default: if ``None``, infers data type from :attr:`data`.
  6249. device (:class:`torch.device`, optional): the device of the constructed tensor. If None and data is a tensor
  6250. then the device of data is used. If None and data is not a tensor then
  6251. the result tensor is constructed on the current device.
  6252. Example::
  6253. >>> a = numpy.array([1, 2, 3])
  6254. >>> t = torch.as_tensor(a)
  6255. >>> t
  6256. tensor([ 1, 2, 3])
  6257. >>> t[0] = -1
  6258. >>> a
  6259. array([-1, 2, 3])
  6260. >>> a = numpy.array([1, 2, 3])
  6261. >>> t = torch.as_tensor(a, device=torch.device('cuda'))
  6262. >>> t
  6263. tensor([ 1, 2, 3])
  6264. >>> t[0] = -1
  6265. >>> a
  6266. array([1, 2, 3])
  6267. """
  6268. def asarray(
  6269. obj: Any,
  6270. *,
  6271. dtype: _dtype | None = None,
  6272. device: DeviceLikeType | None = None,
  6273. copy: _bool | None = None,
  6274. requires_grad: _bool = False,
  6275. ) -> Tensor:
  6276. r"""
  6277. asarray(obj: Any, *, dtype: Optional[dtype], device: Optional[DeviceLikeType], copy: Optional[bool] = None, requires_grad: bool = False) -> Tensor # noqa: B950
  6278. Converts :attr:`obj` to a tensor.
  6279. :attr:`obj` can be one of:
  6280. 1. a tensor
  6281. 2. a NumPy array or a NumPy scalar
  6282. 3. a DLPack capsule
  6283. 4. an object that implements Python's buffer protocol
  6284. 5. a scalar
  6285. 6. a sequence of scalars
  6286. When :attr:`obj` is a tensor, NumPy array, or DLPack capsule the returned tensor will,
  6287. by default, not require a gradient, have the same datatype as :attr:`obj`, be on the
  6288. same device, and share memory with it. These properties can be controlled with the
  6289. :attr:`dtype`, :attr:`device`, :attr:`copy`, and :attr:`requires_grad` keyword arguments.
  6290. If the returned tensor is of a different datatype, on a different device, or a copy is
  6291. requested then it will not share its memory with :attr:`obj`. If :attr:`requires_grad`
  6292. is ``True`` then the returned tensor will require a gradient, and if :attr:`obj` is
  6293. also a tensor with an autograd history then the returned tensor will have the same history.
  6294. When :attr:`obj` is not a tensor, NumPy array, or DLPack capsule but implements Python's
  6295. buffer protocol then the buffer is interpreted as an array of bytes grouped according to
  6296. the size of the datatype passed to the :attr:`dtype` keyword argument. (If no datatype is
  6297. passed then the default floating point datatype is used, instead.) The returned tensor
  6298. will have the specified datatype (or default floating point datatype if none is specified)
  6299. and, by default, be on the CPU device and share memory with the buffer.
  6300. When :attr:`obj` is a NumPy scalar, the returned tensor will be a 0-dimensional tensor on
  6301. the CPU and that doesn't share its memory (i.e. ``copy=True``). By default datatype will
  6302. be the PyTorch datatype corresponding to the NumPy's scalar's datatype.
  6303. When :attr:`obj` is none of the above but a scalar, or a sequence of scalars then the
  6304. returned tensor will, by default, infer its datatype from the scalar values, be on the
  6305. current default device, and not share its memory.
  6306. .. seealso::
  6307. :func:`torch.tensor` creates a tensor that always copies the data from the input object.
  6308. :func:`torch.from_numpy` creates a tensor that always shares memory from NumPy arrays.
  6309. :func:`torch.frombuffer` creates a tensor that always shares memory from objects that
  6310. implement the buffer protocol.
  6311. :func:`torch.from_dlpack` creates a tensor that always shares memory from
  6312. DLPack capsules.
  6313. Args:
  6314. obj (object): a tensor, NumPy array, DLPack Capsule, object that implements Python's
  6315. buffer protocol, scalar, or sequence of scalars.
  6316. Keyword args:
  6317. dtype (:class:`torch.dtype`, optional): the datatype of the returned tensor.
  6318. Default: ``None``, which causes the datatype of the returned tensor to be
  6319. inferred from :attr:`obj`.
  6320. copy (bool, optional): controls whether the returned tensor shares memory with :attr:`obj`.
  6321. Default: ``None``, which causes the returned tensor to share memory with :attr:`obj`
  6322. whenever possible. If ``True`` then the returned tensor does not share its memory.
  6323. If ``False`` then the returned tensor shares its memory with :attr:`obj` and an
  6324. error is thrown if it cannot.
  6325. device (:class:`torch.device`, optional): the device of the returned tensor.
  6326. Default: ``None``, which causes the device of :attr:`obj` to be used. Or, if
  6327. :attr:`obj` is a Python sequence, the current default device will be used.
  6328. requires_grad (bool, optional): whether the returned tensor requires grad.
  6329. Default: ``False``, which causes the returned tensor not to require a gradient.
  6330. If ``True``, then the returned tensor will require a gradient, and if :attr:`obj`
  6331. is also a tensor with an autograd history then the returned tensor will have
  6332. the same history.
  6333. Example::
  6334. >>> a = torch.tensor([1, 2, 3])
  6335. >>> # Shares memory with tensor 'a'
  6336. >>> b = torch.asarray(a)
  6337. >>> a.data_ptr() == b.data_ptr()
  6338. True
  6339. >>> # Forces memory copy
  6340. >>> c = torch.asarray(a, copy=True)
  6341. >>> a.data_ptr() == c.data_ptr()
  6342. False
  6343. >>> a = torch.tensor([1., 2., 3.], requires_grad=True)
  6344. >>> b = a + 2
  6345. >>> b
  6346. tensor([3., 4., 5.], grad_fn=<AddBackward0>)
  6347. >>> # Shares memory with tensor 'b', with no grad
  6348. >>> c = torch.asarray(b)
  6349. >>> c
  6350. tensor([3., 4., 5.])
  6351. >>> # Shares memory with tensor 'b', retaining autograd history
  6352. >>> d = torch.asarray(b, requires_grad=True)
  6353. >>> d
  6354. tensor([3., 4., 5.], grad_fn=<AddBackward0>)
  6355. >>> array = numpy.array([1, 2, 3])
  6356. >>> # Shares memory with array 'array'
  6357. >>> t1 = torch.asarray(array)
  6358. >>> array.__array_interface__['data'][0] == t1.data_ptr()
  6359. True
  6360. >>> # Copies memory due to dtype mismatch
  6361. >>> t2 = torch.asarray(array, dtype=torch.float32)
  6362. >>> array.__array_interface__['data'][0] == t2.data_ptr()
  6363. False
  6364. >>> scalar = numpy.float64(0.5)
  6365. >>> torch.asarray(scalar)
  6366. tensor(0.5000, dtype=torch.float64)
  6367. """
  6368. def asin(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  6369. r"""
  6370. asin(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  6371. Returns a new tensor with the arcsine of the elements (in radians) in the :attr:`input` tensor.
  6372. .. math::
  6373. \text{out}_{i} = \sin^{-1}(\text{input}_{i})
  6374. Args:
  6375. input (Tensor): the input tensor.
  6376. Keyword args:
  6377. out (Tensor, optional): the output tensor.
  6378. Example::
  6379. >>> a = torch.randn(4)
  6380. >>> a
  6381. tensor([-0.5962, 1.4985, -0.4396, 1.4525])
  6382. >>> torch.asin(a)
  6383. tensor([-0.6387, nan, -0.4552, nan])
  6384. """
  6385. def asin_(input: Tensor) -> Tensor: ...
  6386. def asinh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  6387. r"""
  6388. asinh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  6389. Returns a new tensor with the inverse hyperbolic sine of the elements of :attr:`input`.
  6390. .. math::
  6391. \text{out}_{i} = \sinh^{-1}(\text{input}_{i})
  6392. Args:
  6393. input (Tensor): the input tensor.
  6394. Keyword arguments:
  6395. out (Tensor, optional): the output tensor.
  6396. Example::
  6397. >>> a = torch.randn(4)
  6398. >>> a
  6399. tensor([ 0.1606, -1.4267, -1.0899, -1.0250 ])
  6400. >>> torch.asinh(a)
  6401. tensor([ 0.1599, -1.1534, -0.9435, -0.8990 ])
  6402. """
  6403. def asinh_(input: Tensor) -> Tensor: ...
  6404. def atan(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  6405. r"""
  6406. atan(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  6407. Returns a new tensor with the arctangent of the elements (in radians) in the :attr:`input` tensor.
  6408. .. math::
  6409. \text{out}_{i} = \tan^{-1}(\text{input}_{i})
  6410. Args:
  6411. input (Tensor): the input tensor.
  6412. Keyword args:
  6413. out (Tensor, optional): the output tensor.
  6414. Example::
  6415. >>> a = torch.randn(4)
  6416. >>> a
  6417. tensor([ 0.2341, 0.2539, -0.6256, -0.6448])
  6418. >>> torch.atan(a)
  6419. tensor([ 0.2299, 0.2487, -0.5591, -0.5727])
  6420. """
  6421. def atan2(
  6422. input: Tensor,
  6423. other: Tensor,
  6424. *,
  6425. out: Tensor | None = None,
  6426. ) -> Tensor:
  6427. r"""
  6428. atan2(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
  6429. Element-wise arctangent of :math:`\text{input}_{i} / \text{other}_{i}`
  6430. with consideration of the quadrant. Returns a new tensor with the signed angles
  6431. in radians between vector :math:`(\text{other}_{i}, \text{input}_{i})`
  6432. and vector :math:`(1, 0)`. (Note that :math:`\text{other}_{i}`, the second
  6433. parameter, is the x-coordinate, while :math:`\text{input}_{i}`, the first
  6434. parameter, is the y-coordinate.)
  6435. The shapes of ``input`` and ``other`` must be
  6436. :ref:`broadcastable <broadcasting-semantics>`.
  6437. Args:
  6438. input (Tensor): the first input tensor
  6439. other (Tensor): the second input tensor
  6440. Keyword args:
  6441. out (Tensor, optional): the output tensor.
  6442. Example::
  6443. >>> a = torch.randn(4)
  6444. >>> a
  6445. tensor([ 0.9041, 0.0196, -0.3108, -2.4423])
  6446. >>> torch.atan2(a, torch.randn(4))
  6447. tensor([ 0.9833, 0.0811, -1.9743, -1.4151])
  6448. """
  6449. def atan_(input: Tensor) -> Tensor: ...
  6450. def atanh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  6451. r"""
  6452. atanh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  6453. Returns a new tensor with the inverse hyperbolic tangent of the elements of :attr:`input`.
  6454. Note:
  6455. The domain of the inverse hyperbolic tangent is `(-1, 1)` and values outside this range
  6456. will be mapped to ``NaN``, except for the values `1` and `-1` for which the output is
  6457. mapped to `+/-INF` respectively.
  6458. .. math::
  6459. \text{out}_{i} = \tanh^{-1}(\text{input}_{i})
  6460. Args:
  6461. input (Tensor): the input tensor.
  6462. Keyword arguments:
  6463. out (Tensor, optional): the output tensor.
  6464. Example::
  6465. >>> a = torch.randn(4).uniform_(-1, 1)
  6466. >>> a
  6467. tensor([ -0.9385, 0.2968, -0.8591, -0.1871 ])
  6468. >>> torch.atanh(a)
  6469. tensor([ -1.7253, 0.3060, -1.2899, -0.1893 ])
  6470. """
  6471. def atanh_(input: Tensor) -> Tensor: ...
  6472. def avg_pool1d(
  6473. input: Tensor,
  6474. kernel_size: _int | _size,
  6475. stride: _int | _size = (),
  6476. padding: _int | _size = 0,
  6477. ceil_mode: _bool = False,
  6478. count_include_pad: _bool = True,
  6479. ) -> Tensor: ...
  6480. @overload
  6481. def baddbmm(
  6482. beta: Number | _complex,
  6483. self: Tensor,
  6484. alpha: Number | _complex,
  6485. batch1: Tensor,
  6486. batch2: Tensor,
  6487. ) -> Tensor:
  6488. r"""
  6489. baddbmm(input, batch1, batch2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  6490. Performs a batch matrix-matrix product of matrices in :attr:`batch1`
  6491. and :attr:`batch2`.
  6492. :attr:`input` is added to the final result.
  6493. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the same
  6494. number of matrices.
  6495. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  6496. :math:`(b \times m \times p)` tensor, then :attr:`input` must be
  6497. :ref:`broadcastable <broadcasting-semantics>` with a
  6498. :math:`(b \times n \times p)` tensor and :attr:`out` will be a
  6499. :math:`(b \times n \times p)` tensor. Both :attr:`alpha` and :attr:`beta` mean the
  6500. same as the scaling factors used in :meth:`torch.addbmm`.
  6501. .. math::
  6502. \text{out}_i = \beta\ \text{input}_i + \alpha\ (\text{batch1}_i \mathbin{@} \text{batch2}_i)
  6503. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  6504. it will not be propagated.
  6505. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  6506. :attr:`alpha` must be real numbers, otherwise they should be integers.
  6507. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  6508. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  6509. Args:
  6510. input (Tensor): the tensor to be added
  6511. batch1 (Tensor): the first batch of matrices to be multiplied
  6512. batch2 (Tensor): the second batch of matrices to be multiplied
  6513. out_dtype (dtype, optional): the dtype of the output tensor,
  6514. Supported only on CUDA and for torch.float32 given
  6515. torch.float16/torch.bfloat16 input dtypes
  6516. Keyword args:
  6517. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  6518. alpha (Number, optional): multiplier for :math:`\text{batch1} \mathbin{@} \text{batch2}` (:math:`\alpha`)
  6519. out (Tensor, optional): the output tensor.
  6520. Example::
  6521. >>> M = torch.randn(10, 3, 5)
  6522. >>> batch1 = torch.randn(10, 3, 4)
  6523. >>> batch2 = torch.randn(10, 4, 5)
  6524. >>> torch.baddbmm(M, batch1, batch2).size()
  6525. torch.Size([10, 3, 5])
  6526. """
  6527. @overload
  6528. def baddbmm(
  6529. beta: Number | _complex,
  6530. self: Tensor,
  6531. alpha: Number | _complex,
  6532. batch1: Tensor,
  6533. batch2: Tensor,
  6534. *,
  6535. out: Tensor,
  6536. ) -> Tensor:
  6537. r"""
  6538. baddbmm(input, batch1, batch2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  6539. Performs a batch matrix-matrix product of matrices in :attr:`batch1`
  6540. and :attr:`batch2`.
  6541. :attr:`input` is added to the final result.
  6542. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the same
  6543. number of matrices.
  6544. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  6545. :math:`(b \times m \times p)` tensor, then :attr:`input` must be
  6546. :ref:`broadcastable <broadcasting-semantics>` with a
  6547. :math:`(b \times n \times p)` tensor and :attr:`out` will be a
  6548. :math:`(b \times n \times p)` tensor. Both :attr:`alpha` and :attr:`beta` mean the
  6549. same as the scaling factors used in :meth:`torch.addbmm`.
  6550. .. math::
  6551. \text{out}_i = \beta\ \text{input}_i + \alpha\ (\text{batch1}_i \mathbin{@} \text{batch2}_i)
  6552. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  6553. it will not be propagated.
  6554. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  6555. :attr:`alpha` must be real numbers, otherwise they should be integers.
  6556. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  6557. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  6558. Args:
  6559. input (Tensor): the tensor to be added
  6560. batch1 (Tensor): the first batch of matrices to be multiplied
  6561. batch2 (Tensor): the second batch of matrices to be multiplied
  6562. out_dtype (dtype, optional): the dtype of the output tensor,
  6563. Supported only on CUDA and for torch.float32 given
  6564. torch.float16/torch.bfloat16 input dtypes
  6565. Keyword args:
  6566. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  6567. alpha (Number, optional): multiplier for :math:`\text{batch1} \mathbin{@} \text{batch2}` (:math:`\alpha`)
  6568. out (Tensor, optional): the output tensor.
  6569. Example::
  6570. >>> M = torch.randn(10, 3, 5)
  6571. >>> batch1 = torch.randn(10, 3, 4)
  6572. >>> batch2 = torch.randn(10, 4, 5)
  6573. >>> torch.baddbmm(M, batch1, batch2).size()
  6574. torch.Size([10, 3, 5])
  6575. """
  6576. @overload
  6577. def baddbmm(
  6578. input: Tensor,
  6579. batch1: Tensor,
  6580. batch2: Tensor,
  6581. *,
  6582. beta: Number | _complex = 1,
  6583. alpha: Number | _complex = 1,
  6584. out: Tensor | None = None,
  6585. ) -> Tensor:
  6586. r"""
  6587. baddbmm(input, batch1, batch2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  6588. Performs a batch matrix-matrix product of matrices in :attr:`batch1`
  6589. and :attr:`batch2`.
  6590. :attr:`input` is added to the final result.
  6591. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the same
  6592. number of matrices.
  6593. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  6594. :math:`(b \times m \times p)` tensor, then :attr:`input` must be
  6595. :ref:`broadcastable <broadcasting-semantics>` with a
  6596. :math:`(b \times n \times p)` tensor and :attr:`out` will be a
  6597. :math:`(b \times n \times p)` tensor. Both :attr:`alpha` and :attr:`beta` mean the
  6598. same as the scaling factors used in :meth:`torch.addbmm`.
  6599. .. math::
  6600. \text{out}_i = \beta\ \text{input}_i + \alpha\ (\text{batch1}_i \mathbin{@} \text{batch2}_i)
  6601. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  6602. it will not be propagated.
  6603. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  6604. :attr:`alpha` must be real numbers, otherwise they should be integers.
  6605. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  6606. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  6607. Args:
  6608. input (Tensor): the tensor to be added
  6609. batch1 (Tensor): the first batch of matrices to be multiplied
  6610. batch2 (Tensor): the second batch of matrices to be multiplied
  6611. out_dtype (dtype, optional): the dtype of the output tensor,
  6612. Supported only on CUDA and for torch.float32 given
  6613. torch.float16/torch.bfloat16 input dtypes
  6614. Keyword args:
  6615. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  6616. alpha (Number, optional): multiplier for :math:`\text{batch1} \mathbin{@} \text{batch2}` (:math:`\alpha`)
  6617. out (Tensor, optional): the output tensor.
  6618. Example::
  6619. >>> M = torch.randn(10, 3, 5)
  6620. >>> batch1 = torch.randn(10, 3, 4)
  6621. >>> batch2 = torch.randn(10, 4, 5)
  6622. >>> torch.baddbmm(M, batch1, batch2).size()
  6623. torch.Size([10, 3, 5])
  6624. """
  6625. @overload
  6626. def baddbmm(
  6627. input: Tensor,
  6628. batch1: Tensor,
  6629. batch2: Tensor,
  6630. out_dtype: _dtype,
  6631. *,
  6632. beta: Number | _complex = 1,
  6633. alpha: Number | _complex = 1,
  6634. out: Tensor | None = None,
  6635. ) -> Tensor:
  6636. r"""
  6637. baddbmm(input, batch1, batch2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  6638. Performs a batch matrix-matrix product of matrices in :attr:`batch1`
  6639. and :attr:`batch2`.
  6640. :attr:`input` is added to the final result.
  6641. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the same
  6642. number of matrices.
  6643. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  6644. :math:`(b \times m \times p)` tensor, then :attr:`input` must be
  6645. :ref:`broadcastable <broadcasting-semantics>` with a
  6646. :math:`(b \times n \times p)` tensor and :attr:`out` will be a
  6647. :math:`(b \times n \times p)` tensor. Both :attr:`alpha` and :attr:`beta` mean the
  6648. same as the scaling factors used in :meth:`torch.addbmm`.
  6649. .. math::
  6650. \text{out}_i = \beta\ \text{input}_i + \alpha\ (\text{batch1}_i \mathbin{@} \text{batch2}_i)
  6651. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  6652. it will not be propagated.
  6653. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  6654. :attr:`alpha` must be real numbers, otherwise they should be integers.
  6655. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  6656. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  6657. Args:
  6658. input (Tensor): the tensor to be added
  6659. batch1 (Tensor): the first batch of matrices to be multiplied
  6660. batch2 (Tensor): the second batch of matrices to be multiplied
  6661. out_dtype (dtype, optional): the dtype of the output tensor,
  6662. Supported only on CUDA and for torch.float32 given
  6663. torch.float16/torch.bfloat16 input dtypes
  6664. Keyword args:
  6665. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  6666. alpha (Number, optional): multiplier for :math:`\text{batch1} \mathbin{@} \text{batch2}` (:math:`\alpha`)
  6667. out (Tensor, optional): the output tensor.
  6668. Example::
  6669. >>> M = torch.randn(10, 3, 5)
  6670. >>> batch1 = torch.randn(10, 3, 4)
  6671. >>> batch2 = torch.randn(10, 4, 5)
  6672. >>> torch.baddbmm(M, batch1, batch2).size()
  6673. torch.Size([10, 3, 5])
  6674. """
  6675. @overload
  6676. def baddbmm(
  6677. beta: Number | _complex,
  6678. self: Tensor,
  6679. batch1: Tensor,
  6680. batch2: Tensor,
  6681. ) -> Tensor:
  6682. r"""
  6683. baddbmm(input, batch1, batch2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  6684. Performs a batch matrix-matrix product of matrices in :attr:`batch1`
  6685. and :attr:`batch2`.
  6686. :attr:`input` is added to the final result.
  6687. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the same
  6688. number of matrices.
  6689. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  6690. :math:`(b \times m \times p)` tensor, then :attr:`input` must be
  6691. :ref:`broadcastable <broadcasting-semantics>` with a
  6692. :math:`(b \times n \times p)` tensor and :attr:`out` will be a
  6693. :math:`(b \times n \times p)` tensor. Both :attr:`alpha` and :attr:`beta` mean the
  6694. same as the scaling factors used in :meth:`torch.addbmm`.
  6695. .. math::
  6696. \text{out}_i = \beta\ \text{input}_i + \alpha\ (\text{batch1}_i \mathbin{@} \text{batch2}_i)
  6697. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  6698. it will not be propagated.
  6699. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  6700. :attr:`alpha` must be real numbers, otherwise they should be integers.
  6701. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  6702. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  6703. Args:
  6704. input (Tensor): the tensor to be added
  6705. batch1 (Tensor): the first batch of matrices to be multiplied
  6706. batch2 (Tensor): the second batch of matrices to be multiplied
  6707. out_dtype (dtype, optional): the dtype of the output tensor,
  6708. Supported only on CUDA and for torch.float32 given
  6709. torch.float16/torch.bfloat16 input dtypes
  6710. Keyword args:
  6711. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  6712. alpha (Number, optional): multiplier for :math:`\text{batch1} \mathbin{@} \text{batch2}` (:math:`\alpha`)
  6713. out (Tensor, optional): the output tensor.
  6714. Example::
  6715. >>> M = torch.randn(10, 3, 5)
  6716. >>> batch1 = torch.randn(10, 3, 4)
  6717. >>> batch2 = torch.randn(10, 4, 5)
  6718. >>> torch.baddbmm(M, batch1, batch2).size()
  6719. torch.Size([10, 3, 5])
  6720. """
  6721. @overload
  6722. def baddbmm(
  6723. beta: Number | _complex,
  6724. self: Tensor,
  6725. batch1: Tensor,
  6726. batch2: Tensor,
  6727. *,
  6728. out: Tensor,
  6729. ) -> Tensor:
  6730. r"""
  6731. baddbmm(input, batch1, batch2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  6732. Performs a batch matrix-matrix product of matrices in :attr:`batch1`
  6733. and :attr:`batch2`.
  6734. :attr:`input` is added to the final result.
  6735. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the same
  6736. number of matrices.
  6737. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  6738. :math:`(b \times m \times p)` tensor, then :attr:`input` must be
  6739. :ref:`broadcastable <broadcasting-semantics>` with a
  6740. :math:`(b \times n \times p)` tensor and :attr:`out` will be a
  6741. :math:`(b \times n \times p)` tensor. Both :attr:`alpha` and :attr:`beta` mean the
  6742. same as the scaling factors used in :meth:`torch.addbmm`.
  6743. .. math::
  6744. \text{out}_i = \beta\ \text{input}_i + \alpha\ (\text{batch1}_i \mathbin{@} \text{batch2}_i)
  6745. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  6746. it will not be propagated.
  6747. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  6748. :attr:`alpha` must be real numbers, otherwise they should be integers.
  6749. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  6750. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  6751. Args:
  6752. input (Tensor): the tensor to be added
  6753. batch1 (Tensor): the first batch of matrices to be multiplied
  6754. batch2 (Tensor): the second batch of matrices to be multiplied
  6755. out_dtype (dtype, optional): the dtype of the output tensor,
  6756. Supported only on CUDA and for torch.float32 given
  6757. torch.float16/torch.bfloat16 input dtypes
  6758. Keyword args:
  6759. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  6760. alpha (Number, optional): multiplier for :math:`\text{batch1} \mathbin{@} \text{batch2}` (:math:`\alpha`)
  6761. out (Tensor, optional): the output tensor.
  6762. Example::
  6763. >>> M = torch.randn(10, 3, 5)
  6764. >>> batch1 = torch.randn(10, 3, 4)
  6765. >>> batch2 = torch.randn(10, 4, 5)
  6766. >>> torch.baddbmm(M, batch1, batch2).size()
  6767. torch.Size([10, 3, 5])
  6768. """
  6769. @overload
  6770. def bartlett_window(
  6771. window_length: _int,
  6772. *,
  6773. dtype: _dtype | None = None,
  6774. layout: _layout | None = None,
  6775. device: DeviceLikeType | None = None,
  6776. pin_memory: _bool | None = False,
  6777. requires_grad: _bool | None = False,
  6778. ) -> Tensor:
  6779. r"""
  6780. bartlett_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  6781. Bartlett window function.
  6782. .. math::
  6783. w[n] = 1 - \left| \frac{2n}{N-1} - 1 \right| = \begin{cases}
  6784. \frac{2n}{N - 1} & \text{if } 0 \leq n \leq \frac{N - 1}{2} \\
  6785. 2 - \frac{2n}{N - 1} & \text{if } \frac{N - 1}{2} < n < N \\
  6786. \end{cases},
  6787. where :math:`N` is the full window size.
  6788. The input :attr:`window_length` is a positive integer controlling the
  6789. returned window size. :attr:`periodic` flag determines whether the returned
  6790. window trims off the last duplicate value from the symmetric window and is
  6791. ready to be used as a periodic window with functions like
  6792. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  6793. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  6794. ``torch.bartlett_window(L, periodic=True)`` equal to
  6795. ``torch.bartlett_window(L + 1, periodic=False)[:-1])``.
  6796. .. note::
  6797. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  6798. Arguments:
  6799. window_length (int): the size of returned window
  6800. periodic (bool, optional): If True, returns a window to be used as periodic
  6801. function. If False, return a symmetric window.
  6802. Keyword args:
  6803. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  6804. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  6805. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  6806. ``torch.strided`` (dense layout) is supported.
  6807. device (:class:`torch.device`, optional): the desired device of returned tensor.
  6808. Default: if ``None``, uses the current device for the default tensor type
  6809. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  6810. for CPU tensor types and the current CUDA device for CUDA tensor types.
  6811. requires_grad (bool, optional): If autograd should record operations on the
  6812. returned tensor. Default: ``False``.
  6813. Returns:
  6814. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window
  6815. """
  6816. @overload
  6817. def bartlett_window(
  6818. window_length: _int,
  6819. periodic: _bool,
  6820. *,
  6821. dtype: _dtype | None = None,
  6822. layout: _layout | None = None,
  6823. device: DeviceLikeType | None = None,
  6824. pin_memory: _bool | None = False,
  6825. requires_grad: _bool | None = False,
  6826. ) -> Tensor:
  6827. r"""
  6828. bartlett_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  6829. Bartlett window function.
  6830. .. math::
  6831. w[n] = 1 - \left| \frac{2n}{N-1} - 1 \right| = \begin{cases}
  6832. \frac{2n}{N - 1} & \text{if } 0 \leq n \leq \frac{N - 1}{2} \\
  6833. 2 - \frac{2n}{N - 1} & \text{if } \frac{N - 1}{2} < n < N \\
  6834. \end{cases},
  6835. where :math:`N` is the full window size.
  6836. The input :attr:`window_length` is a positive integer controlling the
  6837. returned window size. :attr:`periodic` flag determines whether the returned
  6838. window trims off the last duplicate value from the symmetric window and is
  6839. ready to be used as a periodic window with functions like
  6840. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  6841. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  6842. ``torch.bartlett_window(L, periodic=True)`` equal to
  6843. ``torch.bartlett_window(L + 1, periodic=False)[:-1])``.
  6844. .. note::
  6845. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  6846. Arguments:
  6847. window_length (int): the size of returned window
  6848. periodic (bool, optional): If True, returns a window to be used as periodic
  6849. function. If False, return a symmetric window.
  6850. Keyword args:
  6851. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  6852. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  6853. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  6854. ``torch.strided`` (dense layout) is supported.
  6855. device (:class:`torch.device`, optional): the desired device of returned tensor.
  6856. Default: if ``None``, uses the current device for the default tensor type
  6857. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  6858. for CPU tensor types and the current CUDA device for CUDA tensor types.
  6859. requires_grad (bool, optional): If autograd should record operations on the
  6860. returned tensor. Default: ``False``.
  6861. Returns:
  6862. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window
  6863. """
  6864. def batch_norm(
  6865. input: Tensor,
  6866. weight: Tensor | None,
  6867. bias: Tensor | None,
  6868. running_mean: Tensor | None,
  6869. running_var: Tensor | None,
  6870. training: _bool,
  6871. momentum: _float,
  6872. eps: _float,
  6873. cudnn_enabled: _bool,
  6874. ) -> Tensor: ...
  6875. def batch_norm_backward_elemt(
  6876. grad_out: Tensor,
  6877. input: Tensor,
  6878. mean: Tensor,
  6879. invstd: Tensor,
  6880. weight: Tensor | None,
  6881. sum_dy: Tensor,
  6882. sum_dy_xmu: Tensor,
  6883. count: Tensor,
  6884. ) -> Tensor: ...
  6885. def batch_norm_backward_reduce(
  6886. grad_out: Tensor,
  6887. input: Tensor,
  6888. mean: Tensor,
  6889. invstd: Tensor,
  6890. weight: Tensor | None,
  6891. input_g: _bool,
  6892. weight_g: _bool,
  6893. bias_g: _bool,
  6894. ) -> tuple[Tensor, Tensor, Tensor, Tensor]: ...
  6895. def batch_norm_elemt(
  6896. input: Tensor,
  6897. weight: Tensor | None,
  6898. bias: Tensor | None,
  6899. mean: Tensor,
  6900. invstd: Tensor,
  6901. eps: _float,
  6902. *,
  6903. out: Tensor | None = None,
  6904. ) -> Tensor: ...
  6905. def batch_norm_gather_stats(
  6906. input: Tensor,
  6907. mean: Tensor,
  6908. invstd: Tensor,
  6909. running_mean: Tensor | None,
  6910. running_var: Tensor | None,
  6911. momentum: _float,
  6912. eps: _float,
  6913. count: _int,
  6914. ) -> tuple[Tensor, Tensor]: ...
  6915. def batch_norm_gather_stats_with_counts(
  6916. input: Tensor,
  6917. mean: Tensor,
  6918. invstd: Tensor,
  6919. running_mean: Tensor | None,
  6920. running_var: Tensor | None,
  6921. momentum: _float,
  6922. eps: _float,
  6923. counts: Tensor,
  6924. ) -> tuple[Tensor, Tensor]: ...
  6925. def batch_norm_stats(input: Tensor, eps: _float) -> tuple[Tensor, Tensor]: ...
  6926. def batch_norm_update_stats(
  6927. input: Tensor,
  6928. running_mean: Tensor | None,
  6929. running_var: Tensor | None,
  6930. momentum: _float,
  6931. ) -> tuple[Tensor, Tensor]: ...
  6932. @overload
  6933. def bernoulli(
  6934. input: Tensor,
  6935. *,
  6936. generator: Generator | None = None,
  6937. out: Tensor | None = None,
  6938. ) -> Tensor:
  6939. r"""
  6940. bernoulli(input: Tensor, *, generator: Optional[Generator], out: Optional[Tensor]) -> Tensor
  6941. Draws binary random numbers (0 or 1) from a Bernoulli distribution.
  6942. The :attr:`input` tensor should be a tensor containing probabilities
  6943. to be used for drawing the binary random number.
  6944. Hence, all values in :attr:`input` have to be in the range:
  6945. :math:`0 \leq \text{input}_i \leq 1`.
  6946. The :math:`\text{i}^{th}` element of the output tensor will draw a
  6947. value :math:`1` according to the :math:`\text{i}^{th}` probability value given
  6948. in :attr:`input`.
  6949. .. math::
  6950. \text{out}_{i} \sim \mathrm{Bernoulli}(p = \text{input}_{i})
  6951. The returned :attr:`out` tensor only has values 0 or 1 and is of the same
  6952. shape as :attr:`input`.
  6953. :attr:`out` can have integral ``dtype``, but :attr:`input` must have floating
  6954. point ``dtype``.
  6955. Args:
  6956. input (Tensor): the input tensor of probability values for the Bernoulli distribution
  6957. Keyword args:
  6958. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  6959. out (Tensor, optional): the output tensor.
  6960. Example::
  6961. >>> a = torch.empty(3, 3).uniform_(0, 1) # generate a uniform random matrix with range [0, 1]
  6962. >>> a
  6963. tensor([[ 0.1737, 0.0950, 0.3609],
  6964. [ 0.7148, 0.0289, 0.2676],
  6965. [ 0.9456, 0.8937, 0.7202]])
  6966. >>> torch.bernoulli(a)
  6967. tensor([[ 1., 0., 0.],
  6968. [ 0., 0., 0.],
  6969. [ 1., 1., 1.]])
  6970. >>> a = torch.ones(3, 3) # probability of drawing "1" is 1
  6971. >>> torch.bernoulli(a)
  6972. tensor([[ 1., 1., 1.],
  6973. [ 1., 1., 1.],
  6974. [ 1., 1., 1.]])
  6975. >>> a = torch.zeros(3, 3) # probability of drawing "1" is 0
  6976. >>> torch.bernoulli(a)
  6977. tensor([[ 0., 0., 0.],
  6978. [ 0., 0., 0.],
  6979. [ 0., 0., 0.]])
  6980. """
  6981. @overload
  6982. def bernoulli(
  6983. input: Tensor,
  6984. p: _float,
  6985. *,
  6986. generator: Generator | None = None,
  6987. ) -> Tensor:
  6988. r"""
  6989. bernoulli(input: Tensor, *, generator: Optional[Generator], out: Optional[Tensor]) -> Tensor
  6990. Draws binary random numbers (0 or 1) from a Bernoulli distribution.
  6991. The :attr:`input` tensor should be a tensor containing probabilities
  6992. to be used for drawing the binary random number.
  6993. Hence, all values in :attr:`input` have to be in the range:
  6994. :math:`0 \leq \text{input}_i \leq 1`.
  6995. The :math:`\text{i}^{th}` element of the output tensor will draw a
  6996. value :math:`1` according to the :math:`\text{i}^{th}` probability value given
  6997. in :attr:`input`.
  6998. .. math::
  6999. \text{out}_{i} \sim \mathrm{Bernoulli}(p = \text{input}_{i})
  7000. The returned :attr:`out` tensor only has values 0 or 1 and is of the same
  7001. shape as :attr:`input`.
  7002. :attr:`out` can have integral ``dtype``, but :attr:`input` must have floating
  7003. point ``dtype``.
  7004. Args:
  7005. input (Tensor): the input tensor of probability values for the Bernoulli distribution
  7006. Keyword args:
  7007. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  7008. out (Tensor, optional): the output tensor.
  7009. Example::
  7010. >>> a = torch.empty(3, 3).uniform_(0, 1) # generate a uniform random matrix with range [0, 1]
  7011. >>> a
  7012. tensor([[ 0.1737, 0.0950, 0.3609],
  7013. [ 0.7148, 0.0289, 0.2676],
  7014. [ 0.9456, 0.8937, 0.7202]])
  7015. >>> torch.bernoulli(a)
  7016. tensor([[ 1., 0., 0.],
  7017. [ 0., 0., 0.],
  7018. [ 1., 1., 1.]])
  7019. >>> a = torch.ones(3, 3) # probability of drawing "1" is 1
  7020. >>> torch.bernoulli(a)
  7021. tensor([[ 1., 1., 1.],
  7022. [ 1., 1., 1.],
  7023. [ 1., 1., 1.]])
  7024. >>> a = torch.zeros(3, 3) # probability of drawing "1" is 0
  7025. >>> torch.bernoulli(a)
  7026. tensor([[ 0., 0., 0.],
  7027. [ 0., 0., 0.],
  7028. [ 0., 0., 0.]])
  7029. """
  7030. def bilinear(
  7031. input1: Tensor,
  7032. input2: Tensor,
  7033. weight: Tensor,
  7034. bias: Tensor | None = None,
  7035. ) -> Tensor: ...
  7036. def binary_cross_entropy_with_logits(
  7037. input: Tensor,
  7038. target: Tensor,
  7039. weight: Tensor | None = None,
  7040. pos_weight: Tensor | None = None,
  7041. reduction: _int = 1,
  7042. ) -> Tensor: ...
  7043. def bincount(
  7044. input: Tensor,
  7045. weights: Tensor | None = None,
  7046. minlength: _int | SymInt = 0,
  7047. ) -> Tensor:
  7048. r"""
  7049. bincount(input, weights=None, minlength=0) -> Tensor
  7050. Count the frequency of each value in an array of non-negative ints.
  7051. The number of bins (size 1) is one larger than the largest value in
  7052. :attr:`input` unless :attr:`input` is empty, in which case the result is a
  7053. tensor of size 0. If :attr:`minlength` is specified, the number of bins is at least
  7054. :attr:`minlength` and if :attr:`input` is empty, then the result is tensor of size
  7055. :attr:`minlength` filled with zeros. If ``n`` is the value at position ``i``,
  7056. ``out[n] += weights[i]`` if :attr:`weights` is specified else
  7057. ``out[n] += 1``.
  7058. Note:
  7059. This operation may produce nondeterministic gradients when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
  7060. Arguments:
  7061. input (Tensor): 1-d int tensor
  7062. weights (Tensor): optional, weight for each value in the input tensor.
  7063. Should be of same size as input tensor.
  7064. minlength (int): optional, minimum number of bins. Should be non-negative.
  7065. Returns:
  7066. output (Tensor): a tensor of shape ``Size([max(input) + 1])`` if
  7067. :attr:`input` is non-empty, else ``Size(0)``
  7068. Example::
  7069. >>> input = torch.randint(0, 8, (5,), dtype=torch.int64)
  7070. >>> weights = torch.linspace(0, 1, steps=5)
  7071. >>> input, weights
  7072. (tensor([4, 3, 6, 3, 4]),
  7073. tensor([ 0.0000, 0.2500, 0.5000, 0.7500, 1.0000])
  7074. >>> torch.bincount(input)
  7075. tensor([0, 0, 0, 2, 2, 0, 1])
  7076. >>> input.bincount(weights)
  7077. tensor([0.0000, 0.0000, 0.0000, 1.0000, 1.0000, 0.0000, 0.5000])
  7078. """
  7079. def binomial(
  7080. count: Tensor,
  7081. prob: Tensor,
  7082. generator: Generator | None = None,
  7083. ) -> Tensor: ...
  7084. @overload
  7085. def bitwise_and(
  7086. input: Tensor,
  7087. other: Tensor,
  7088. *,
  7089. out: Tensor | None = None,
  7090. ) -> Tensor:
  7091. r"""
  7092. bitwise_and(input, other, *, out=None) -> Tensor
  7093. Computes the bitwise AND of :attr:`input` and :attr:`other`. The input tensor must be of
  7094. integral or Boolean types. For bool tensors, it computes the logical AND.
  7095. Args:
  7096. input: the first input tensor
  7097. other: the second input tensor
  7098. Keyword args:
  7099. out (Tensor, optional): the output tensor.
  7100. Example::
  7101. >>> torch.bitwise_and(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7102. tensor([1, 0, 3], dtype=torch.int8)
  7103. >>> torch.bitwise_and(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7104. tensor([ False, True, False])
  7105. """
  7106. @overload
  7107. def bitwise_and(self: Number | _complex, other: Tensor) -> Tensor:
  7108. r"""
  7109. bitwise_and(input, other, *, out=None) -> Tensor
  7110. Computes the bitwise AND of :attr:`input` and :attr:`other`. The input tensor must be of
  7111. integral or Boolean types. For bool tensors, it computes the logical AND.
  7112. Args:
  7113. input: the first input tensor
  7114. other: the second input tensor
  7115. Keyword args:
  7116. out (Tensor, optional): the output tensor.
  7117. Example::
  7118. >>> torch.bitwise_and(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7119. tensor([1, 0, 3], dtype=torch.int8)
  7120. >>> torch.bitwise_and(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7121. tensor([ False, True, False])
  7122. """
  7123. @overload
  7124. def bitwise_and(
  7125. input: Tensor,
  7126. other: Number | _complex,
  7127. *,
  7128. out: Tensor | None = None,
  7129. ) -> Tensor:
  7130. r"""
  7131. bitwise_and(input, other, *, out=None) -> Tensor
  7132. Computes the bitwise AND of :attr:`input` and :attr:`other`. The input tensor must be of
  7133. integral or Boolean types. For bool tensors, it computes the logical AND.
  7134. Args:
  7135. input: the first input tensor
  7136. other: the second input tensor
  7137. Keyword args:
  7138. out (Tensor, optional): the output tensor.
  7139. Example::
  7140. >>> torch.bitwise_and(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7141. tensor([1, 0, 3], dtype=torch.int8)
  7142. >>> torch.bitwise_and(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7143. tensor([ False, True, False])
  7144. """
  7145. @overload
  7146. def bitwise_left_shift(
  7147. input: Tensor,
  7148. other: Tensor,
  7149. *,
  7150. out: Tensor | None = None,
  7151. ) -> Tensor:
  7152. r"""
  7153. bitwise_left_shift(input, other, *, out=None) -> Tensor
  7154. Computes the left arithmetic shift of :attr:`input` by :attr:`other` bits.
  7155. The input tensor must be of integral type. This operator supports
  7156. :ref:`broadcasting to a common shape <broadcasting-semantics>` and
  7157. :ref:`type promotion <type-promotion-doc>`.
  7158. The operation applied is:
  7159. .. math::
  7160. \text{out}_i = \text{input}_i << \text{other}_i
  7161. Args:
  7162. input (Tensor or Scalar): the first input tensor
  7163. other (Tensor or Scalar): the second input tensor
  7164. Keyword args:
  7165. out (Tensor, optional): the output tensor.
  7166. Example::
  7167. >>> torch.bitwise_left_shift(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7168. tensor([-2, -2, 24], dtype=torch.int8)
  7169. """
  7170. @overload
  7171. def bitwise_left_shift(self: Number | _complex, other: Tensor) -> Tensor:
  7172. r"""
  7173. bitwise_left_shift(input, other, *, out=None) -> Tensor
  7174. Computes the left arithmetic shift of :attr:`input` by :attr:`other` bits.
  7175. The input tensor must be of integral type. This operator supports
  7176. :ref:`broadcasting to a common shape <broadcasting-semantics>` and
  7177. :ref:`type promotion <type-promotion-doc>`.
  7178. The operation applied is:
  7179. .. math::
  7180. \text{out}_i = \text{input}_i << \text{other}_i
  7181. Args:
  7182. input (Tensor or Scalar): the first input tensor
  7183. other (Tensor or Scalar): the second input tensor
  7184. Keyword args:
  7185. out (Tensor, optional): the output tensor.
  7186. Example::
  7187. >>> torch.bitwise_left_shift(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7188. tensor([-2, -2, 24], dtype=torch.int8)
  7189. """
  7190. @overload
  7191. def bitwise_left_shift(
  7192. input: Tensor,
  7193. other: Number | _complex,
  7194. *,
  7195. out: Tensor | None = None,
  7196. ) -> Tensor:
  7197. r"""
  7198. bitwise_left_shift(input, other, *, out=None) -> Tensor
  7199. Computes the left arithmetic shift of :attr:`input` by :attr:`other` bits.
  7200. The input tensor must be of integral type. This operator supports
  7201. :ref:`broadcasting to a common shape <broadcasting-semantics>` and
  7202. :ref:`type promotion <type-promotion-doc>`.
  7203. The operation applied is:
  7204. .. math::
  7205. \text{out}_i = \text{input}_i << \text{other}_i
  7206. Args:
  7207. input (Tensor or Scalar): the first input tensor
  7208. other (Tensor or Scalar): the second input tensor
  7209. Keyword args:
  7210. out (Tensor, optional): the output tensor.
  7211. Example::
  7212. >>> torch.bitwise_left_shift(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7213. tensor([-2, -2, 24], dtype=torch.int8)
  7214. """
  7215. def bitwise_not(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  7216. r"""
  7217. bitwise_not(input, *, out=None) -> Tensor
  7218. Computes the bitwise NOT of the given input tensor. The input tensor must be of
  7219. integral or Boolean types. For bool tensors, it computes the logical NOT.
  7220. Args:
  7221. input (Tensor): the input tensor.
  7222. Keyword args:
  7223. out (Tensor, optional): the output tensor.
  7224. Example::
  7225. >>> torch.bitwise_not(torch.tensor([-1, -2, 3], dtype=torch.int8))
  7226. tensor([ 0, 1, -4], dtype=torch.int8)
  7227. """
  7228. @overload
  7229. def bitwise_or(
  7230. input: Tensor,
  7231. other: Tensor,
  7232. *,
  7233. out: Tensor | None = None,
  7234. ) -> Tensor:
  7235. r"""
  7236. bitwise_or(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
  7237. Computes the bitwise OR of :attr:`input` and :attr:`other`. The input tensor must be of
  7238. integral or Boolean types. For bool tensors, it computes the logical OR.
  7239. Args:
  7240. input: the first input tensor
  7241. other: the second input tensor
  7242. Keyword args:
  7243. out (Tensor, optional): the output tensor.
  7244. Example::
  7245. >>> torch.bitwise_or(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7246. tensor([-1, -2, 3], dtype=torch.int8)
  7247. >>> torch.bitwise_or(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7248. tensor([ True, True, False])
  7249. """
  7250. @overload
  7251. def bitwise_or(self: Number | _complex, other: Tensor) -> Tensor:
  7252. r"""
  7253. bitwise_or(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
  7254. Computes the bitwise OR of :attr:`input` and :attr:`other`. The input tensor must be of
  7255. integral or Boolean types. For bool tensors, it computes the logical OR.
  7256. Args:
  7257. input: the first input tensor
  7258. other: the second input tensor
  7259. Keyword args:
  7260. out (Tensor, optional): the output tensor.
  7261. Example::
  7262. >>> torch.bitwise_or(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7263. tensor([-1, -2, 3], dtype=torch.int8)
  7264. >>> torch.bitwise_or(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7265. tensor([ True, True, False])
  7266. """
  7267. @overload
  7268. def bitwise_or(
  7269. input: Tensor,
  7270. other: Number | _complex,
  7271. *,
  7272. out: Tensor | None = None,
  7273. ) -> Tensor:
  7274. r"""
  7275. bitwise_or(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
  7276. Computes the bitwise OR of :attr:`input` and :attr:`other`. The input tensor must be of
  7277. integral or Boolean types. For bool tensors, it computes the logical OR.
  7278. Args:
  7279. input: the first input tensor
  7280. other: the second input tensor
  7281. Keyword args:
  7282. out (Tensor, optional): the output tensor.
  7283. Example::
  7284. >>> torch.bitwise_or(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7285. tensor([-1, -2, 3], dtype=torch.int8)
  7286. >>> torch.bitwise_or(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7287. tensor([ True, True, False])
  7288. """
  7289. @overload
  7290. def bitwise_right_shift(
  7291. input: Tensor,
  7292. other: Tensor,
  7293. *,
  7294. out: Tensor | None = None,
  7295. ) -> Tensor:
  7296. r"""
  7297. bitwise_right_shift(input, other, *, out=None) -> Tensor
  7298. Computes the right arithmetic shift of :attr:`input` by :attr:`other` bits.
  7299. The input tensor must be of integral type. This operator supports
  7300. :ref:`broadcasting to a common shape <broadcasting-semantics>` and
  7301. :ref:`type promotion <type-promotion-doc>`.
  7302. In any case, if the value of the right operand is negative or is greater
  7303. or equal to the number of bits in the promoted left operand, the behavior is undefined.
  7304. The operation applied is:
  7305. .. math::
  7306. \text{out}_i = \text{input}_i >> \text{other}_i
  7307. Args:
  7308. input (Tensor or Scalar): the first input tensor
  7309. other (Tensor or Scalar): the second input tensor
  7310. Keyword args:
  7311. out (Tensor, optional): the output tensor.
  7312. Example::
  7313. >>> torch.bitwise_right_shift(torch.tensor([-2, -7, 31], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7314. tensor([-1, -7, 3], dtype=torch.int8)
  7315. """
  7316. @overload
  7317. def bitwise_right_shift(self: Number | _complex, other: Tensor) -> Tensor:
  7318. r"""
  7319. bitwise_right_shift(input, other, *, out=None) -> Tensor
  7320. Computes the right arithmetic shift of :attr:`input` by :attr:`other` bits.
  7321. The input tensor must be of integral type. This operator supports
  7322. :ref:`broadcasting to a common shape <broadcasting-semantics>` and
  7323. :ref:`type promotion <type-promotion-doc>`.
  7324. In any case, if the value of the right operand is negative or is greater
  7325. or equal to the number of bits in the promoted left operand, the behavior is undefined.
  7326. The operation applied is:
  7327. .. math::
  7328. \text{out}_i = \text{input}_i >> \text{other}_i
  7329. Args:
  7330. input (Tensor or Scalar): the first input tensor
  7331. other (Tensor or Scalar): the second input tensor
  7332. Keyword args:
  7333. out (Tensor, optional): the output tensor.
  7334. Example::
  7335. >>> torch.bitwise_right_shift(torch.tensor([-2, -7, 31], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7336. tensor([-1, -7, 3], dtype=torch.int8)
  7337. """
  7338. @overload
  7339. def bitwise_right_shift(
  7340. input: Tensor,
  7341. other: Number | _complex,
  7342. *,
  7343. out: Tensor | None = None,
  7344. ) -> Tensor:
  7345. r"""
  7346. bitwise_right_shift(input, other, *, out=None) -> Tensor
  7347. Computes the right arithmetic shift of :attr:`input` by :attr:`other` bits.
  7348. The input tensor must be of integral type. This operator supports
  7349. :ref:`broadcasting to a common shape <broadcasting-semantics>` and
  7350. :ref:`type promotion <type-promotion-doc>`.
  7351. In any case, if the value of the right operand is negative or is greater
  7352. or equal to the number of bits in the promoted left operand, the behavior is undefined.
  7353. The operation applied is:
  7354. .. math::
  7355. \text{out}_i = \text{input}_i >> \text{other}_i
  7356. Args:
  7357. input (Tensor or Scalar): the first input tensor
  7358. other (Tensor or Scalar): the second input tensor
  7359. Keyword args:
  7360. out (Tensor, optional): the output tensor.
  7361. Example::
  7362. >>> torch.bitwise_right_shift(torch.tensor([-2, -7, 31], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7363. tensor([-1, -7, 3], dtype=torch.int8)
  7364. """
  7365. @overload
  7366. def bitwise_xor(
  7367. input: Tensor,
  7368. other: Tensor,
  7369. *,
  7370. out: Tensor | None = None,
  7371. ) -> Tensor:
  7372. r"""
  7373. bitwise_xor(input, other, *, out=None) -> Tensor
  7374. Computes the bitwise XOR of :attr:`input` and :attr:`other`. The input tensor must be of
  7375. integral or Boolean types. For bool tensors, it computes the logical XOR.
  7376. Args:
  7377. input: the first input tensor
  7378. other: the second input tensor
  7379. Keyword args:
  7380. out (Tensor, optional): the output tensor.
  7381. Example::
  7382. >>> torch.bitwise_xor(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7383. tensor([-2, -2, 0], dtype=torch.int8)
  7384. >>> torch.bitwise_xor(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7385. tensor([ True, False, False])
  7386. """
  7387. @overload
  7388. def bitwise_xor(self: Number | _complex, other: Tensor) -> Tensor:
  7389. r"""
  7390. bitwise_xor(input, other, *, out=None) -> Tensor
  7391. Computes the bitwise XOR of :attr:`input` and :attr:`other`. The input tensor must be of
  7392. integral or Boolean types. For bool tensors, it computes the logical XOR.
  7393. Args:
  7394. input: the first input tensor
  7395. other: the second input tensor
  7396. Keyword args:
  7397. out (Tensor, optional): the output tensor.
  7398. Example::
  7399. >>> torch.bitwise_xor(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7400. tensor([-2, -2, 0], dtype=torch.int8)
  7401. >>> torch.bitwise_xor(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7402. tensor([ True, False, False])
  7403. """
  7404. @overload
  7405. def bitwise_xor(
  7406. input: Tensor,
  7407. other: Number | _complex,
  7408. *,
  7409. out: Tensor | None = None,
  7410. ) -> Tensor:
  7411. r"""
  7412. bitwise_xor(input, other, *, out=None) -> Tensor
  7413. Computes the bitwise XOR of :attr:`input` and :attr:`other`. The input tensor must be of
  7414. integral or Boolean types. For bool tensors, it computes the logical XOR.
  7415. Args:
  7416. input: the first input tensor
  7417. other: the second input tensor
  7418. Keyword args:
  7419. out (Tensor, optional): the output tensor.
  7420. Example::
  7421. >>> torch.bitwise_xor(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7422. tensor([-2, -2, 0], dtype=torch.int8)
  7423. >>> torch.bitwise_xor(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7424. tensor([ True, False, False])
  7425. """
  7426. @overload
  7427. def blackman_window(
  7428. window_length: _int,
  7429. *,
  7430. dtype: _dtype | None = None,
  7431. layout: _layout | None = None,
  7432. device: DeviceLikeType | None = None,
  7433. pin_memory: _bool | None = False,
  7434. requires_grad: _bool | None = False,
  7435. ) -> Tensor:
  7436. r"""
  7437. blackman_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  7438. Blackman window function.
  7439. .. math::
  7440. w[n] = 0.42 - 0.5 \cos \left( \frac{2 \pi n}{N - 1} \right) + 0.08 \cos \left( \frac{4 \pi n}{N - 1} \right)
  7441. where :math:`N` is the full window size.
  7442. The input :attr:`window_length` is a positive integer controlling the
  7443. returned window size. :attr:`periodic` flag determines whether the returned
  7444. window trims off the last duplicate value from the symmetric window and is
  7445. ready to be used as a periodic window with functions like
  7446. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  7447. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  7448. ``torch.blackman_window(L, periodic=True)`` equal to
  7449. ``torch.blackman_window(L + 1, periodic=False)[:-1]``.
  7450. .. note::
  7451. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  7452. Arguments:
  7453. window_length (int): the size of returned window
  7454. periodic (bool, optional): If True, returns a window to be used as periodic
  7455. function. If False, return a symmetric window.
  7456. Keyword args:
  7457. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  7458. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  7459. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  7460. ``torch.strided`` (dense layout) is supported.
  7461. device (:class:`torch.device`, optional): the desired device of returned tensor.
  7462. Default: if ``None``, uses the current device for the default tensor type
  7463. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  7464. for CPU tensor types and the current CUDA device for CUDA tensor types.
  7465. requires_grad (bool, optional): If autograd should record operations on the
  7466. returned tensor. Default: ``False``.
  7467. Returns:
  7468. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window
  7469. """
  7470. @overload
  7471. def blackman_window(
  7472. window_length: _int,
  7473. periodic: _bool,
  7474. *,
  7475. dtype: _dtype | None = None,
  7476. layout: _layout | None = None,
  7477. device: DeviceLikeType | None = None,
  7478. pin_memory: _bool | None = False,
  7479. requires_grad: _bool | None = False,
  7480. ) -> Tensor:
  7481. r"""
  7482. blackman_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  7483. Blackman window function.
  7484. .. math::
  7485. w[n] = 0.42 - 0.5 \cos \left( \frac{2 \pi n}{N - 1} \right) + 0.08 \cos \left( \frac{4 \pi n}{N - 1} \right)
  7486. where :math:`N` is the full window size.
  7487. The input :attr:`window_length` is a positive integer controlling the
  7488. returned window size. :attr:`periodic` flag determines whether the returned
  7489. window trims off the last duplicate value from the symmetric window and is
  7490. ready to be used as a periodic window with functions like
  7491. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  7492. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  7493. ``torch.blackman_window(L, periodic=True)`` equal to
  7494. ``torch.blackman_window(L + 1, periodic=False)[:-1]``.
  7495. .. note::
  7496. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  7497. Arguments:
  7498. window_length (int): the size of returned window
  7499. periodic (bool, optional): If True, returns a window to be used as periodic
  7500. function. If False, return a symmetric window.
  7501. Keyword args:
  7502. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  7503. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  7504. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  7505. ``torch.strided`` (dense layout) is supported.
  7506. device (:class:`torch.device`, optional): the desired device of returned tensor.
  7507. Default: if ``None``, uses the current device for the default tensor type
  7508. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  7509. for CPU tensor types and the current CUDA device for CUDA tensor types.
  7510. requires_grad (bool, optional): If autograd should record operations on the
  7511. returned tensor. Default: ``False``.
  7512. Returns:
  7513. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window
  7514. """
  7515. @overload
  7516. def bmm(
  7517. input: Tensor,
  7518. mat2: Tensor,
  7519. *,
  7520. out: Tensor | None = None,
  7521. ) -> Tensor:
  7522. r"""
  7523. bmm(input, mat2, out_dtype=None, *, out=None) -> Tensor
  7524. Performs a batch matrix-matrix product of matrices stored in :attr:`input`
  7525. and :attr:`mat2`.
  7526. :attr:`input` and :attr:`mat2` must be 3-D tensors each containing
  7527. the same number of matrices.
  7528. If :attr:`input` is a :math:`(b \times n \times m)` tensor, :attr:`mat2` is a
  7529. :math:`(b \times m \times p)` tensor, :attr:`out` will be a
  7530. :math:`(b \times n \times p)` tensor.
  7531. .. math::
  7532. \text{out}_i = \text{input}_i \mathbin{@} \text{mat2}_i
  7533. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  7534. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  7535. .. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
  7536. For broadcasting matrix products, see :func:`torch.matmul`.
  7537. Args:
  7538. input (Tensor): the first batch of matrices to be multiplied
  7539. mat2 (Tensor): the second batch of matrices to be multiplied
  7540. out_dtype (dtype, optional): the dtype of the output tensor,
  7541. Supported only on CUDA and for torch.float32 given
  7542. torch.float16/torch.bfloat16 input dtypes
  7543. Keyword Args:
  7544. out (Tensor, optional): the output tensor.
  7545. Example::
  7546. >>> input = torch.randn(10, 3, 4)
  7547. >>> mat2 = torch.randn(10, 4, 5)
  7548. >>> res = torch.bmm(input, mat2)
  7549. >>> res.size()
  7550. torch.Size([10, 3, 5])
  7551. """
  7552. @overload
  7553. def bmm(
  7554. input: Tensor,
  7555. mat2: Tensor,
  7556. out_dtype: _dtype,
  7557. *,
  7558. out: Tensor | None = None,
  7559. ) -> Tensor:
  7560. r"""
  7561. bmm(input, mat2, out_dtype=None, *, out=None) -> Tensor
  7562. Performs a batch matrix-matrix product of matrices stored in :attr:`input`
  7563. and :attr:`mat2`.
  7564. :attr:`input` and :attr:`mat2` must be 3-D tensors each containing
  7565. the same number of matrices.
  7566. If :attr:`input` is a :math:`(b \times n \times m)` tensor, :attr:`mat2` is a
  7567. :math:`(b \times m \times p)` tensor, :attr:`out` will be a
  7568. :math:`(b \times n \times p)` tensor.
  7569. .. math::
  7570. \text{out}_i = \text{input}_i \mathbin{@} \text{mat2}_i
  7571. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  7572. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  7573. .. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
  7574. For broadcasting matrix products, see :func:`torch.matmul`.
  7575. Args:
  7576. input (Tensor): the first batch of matrices to be multiplied
  7577. mat2 (Tensor): the second batch of matrices to be multiplied
  7578. out_dtype (dtype, optional): the dtype of the output tensor,
  7579. Supported only on CUDA and for torch.float32 given
  7580. torch.float16/torch.bfloat16 input dtypes
  7581. Keyword Args:
  7582. out (Tensor, optional): the output tensor.
  7583. Example::
  7584. >>> input = torch.randn(10, 3, 4)
  7585. >>> mat2 = torch.randn(10, 4, 5)
  7586. >>> res = torch.bmm(input, mat2)
  7587. >>> res.size()
  7588. torch.Size([10, 3, 5])
  7589. """
  7590. def broadcast_to(input: Tensor, size: Sequence[_int | SymInt]) -> Tensor:
  7591. r"""
  7592. broadcast_to(input, shape) -> Tensor
  7593. Broadcasts :attr:`input` to the shape :attr:`\shape`.
  7594. Equivalent to calling ``input.expand(shape)``. See :meth:`~Tensor.expand` for details.
  7595. Args:
  7596. input (Tensor): the input tensor.
  7597. shape (list, tuple, or :class:`torch.Size`): the new shape.
  7598. Example::
  7599. >>> x = torch.tensor([1, 2, 3])
  7600. >>> torch.broadcast_to(x, (3, 3))
  7601. tensor([[1, 2, 3],
  7602. [1, 2, 3],
  7603. [1, 2, 3]])
  7604. """
  7605. @overload
  7606. def bucketize(
  7607. input: Tensor,
  7608. boundaries: Tensor,
  7609. *,
  7610. out_int32: _bool = False,
  7611. right: _bool = False,
  7612. out: Tensor | None = None,
  7613. ) -> Tensor:
  7614. r"""
  7615. bucketize(input, boundaries, *, out_int32=False, right=False, out=None) -> Tensor
  7616. Returns the indices of the buckets to which each value in the :attr:`input` belongs, where the
  7617. boundaries of the buckets are set by :attr:`boundaries`. Return a new tensor with the same size
  7618. as :attr:`input`. If :attr:`right` is False (default), then the left boundary is open. Note that
  7619. this behavior is opposite the behavior of
  7620. `numpy.digitize <https://numpy.org/doc/stable/reference/generated/numpy.digitize.html>`_.
  7621. More formally, the returned index satisfies the following rules:
  7622. .. list-table::
  7623. :widths: 15 85
  7624. :header-rows: 1
  7625. * - :attr:`right`
  7626. - *returned index satisfies*
  7627. * - False
  7628. - ``boundaries[i-1] < input[m][n]...[l][x] <= boundaries[i]``
  7629. * - True
  7630. - ``boundaries[i-1] <= input[m][n]...[l][x] < boundaries[i]``
  7631. Args:
  7632. input (Tensor or Scalar): N-D tensor or a Scalar containing the search value(s).
  7633. boundaries (Tensor): 1-D tensor, must contain a strictly increasing sequence, or the return value is undefined.
  7634. Keyword args:
  7635. out_int32 (bool, optional): indicate the output data type. torch.int32 if True, torch.int64 otherwise.
  7636. Default value is False, i.e. default output data type is torch.int64.
  7637. right (bool, optional): determines the behavior for values in :attr:`boundaries`. See the table above.
  7638. out (Tensor, optional): the output tensor, must be the same size as :attr:`input` if provided.
  7639. Example::
  7640. >>> boundaries = torch.tensor([1, 3, 5, 7, 9])
  7641. >>> boundaries
  7642. tensor([1, 3, 5, 7, 9])
  7643. >>> v = torch.tensor([[3, 6, 9], [3, 6, 9]])
  7644. >>> v
  7645. tensor([[3, 6, 9],
  7646. [3, 6, 9]])
  7647. >>> torch.bucketize(v, boundaries)
  7648. tensor([[1, 3, 4],
  7649. [1, 3, 4]])
  7650. >>> torch.bucketize(v, boundaries, right=True)
  7651. tensor([[2, 3, 5],
  7652. [2, 3, 5]])
  7653. """
  7654. @overload
  7655. def bucketize(
  7656. self: Number | _complex,
  7657. boundaries: Tensor,
  7658. *,
  7659. out_int32: _bool = False,
  7660. right: _bool = False,
  7661. ) -> Tensor:
  7662. r"""
  7663. bucketize(input, boundaries, *, out_int32=False, right=False, out=None) -> Tensor
  7664. Returns the indices of the buckets to which each value in the :attr:`input` belongs, where the
  7665. boundaries of the buckets are set by :attr:`boundaries`. Return a new tensor with the same size
  7666. as :attr:`input`. If :attr:`right` is False (default), then the left boundary is open. Note that
  7667. this behavior is opposite the behavior of
  7668. `numpy.digitize <https://numpy.org/doc/stable/reference/generated/numpy.digitize.html>`_.
  7669. More formally, the returned index satisfies the following rules:
  7670. .. list-table::
  7671. :widths: 15 85
  7672. :header-rows: 1
  7673. * - :attr:`right`
  7674. - *returned index satisfies*
  7675. * - False
  7676. - ``boundaries[i-1] < input[m][n]...[l][x] <= boundaries[i]``
  7677. * - True
  7678. - ``boundaries[i-1] <= input[m][n]...[l][x] < boundaries[i]``
  7679. Args:
  7680. input (Tensor or Scalar): N-D tensor or a Scalar containing the search value(s).
  7681. boundaries (Tensor): 1-D tensor, must contain a strictly increasing sequence, or the return value is undefined.
  7682. Keyword args:
  7683. out_int32 (bool, optional): indicate the output data type. torch.int32 if True, torch.int64 otherwise.
  7684. Default value is False, i.e. default output data type is torch.int64.
  7685. right (bool, optional): determines the behavior for values in :attr:`boundaries`. See the table above.
  7686. out (Tensor, optional): the output tensor, must be the same size as :attr:`input` if provided.
  7687. Example::
  7688. >>> boundaries = torch.tensor([1, 3, 5, 7, 9])
  7689. >>> boundaries
  7690. tensor([1, 3, 5, 7, 9])
  7691. >>> v = torch.tensor([[3, 6, 9], [3, 6, 9]])
  7692. >>> v
  7693. tensor([[3, 6, 9],
  7694. [3, 6, 9]])
  7695. >>> torch.bucketize(v, boundaries)
  7696. tensor([[1, 3, 4],
  7697. [1, 3, 4]])
  7698. >>> torch.bucketize(v, boundaries, right=True)
  7699. tensor([[2, 3, 5],
  7700. [2, 3, 5]])
  7701. """
  7702. def can_cast(from_: _dtype, to: _dtype) -> _bool:
  7703. r"""
  7704. can_cast(from_, to) -> bool
  7705. Determines if a type conversion is allowed under PyTorch casting rules
  7706. described in the type promotion :ref:`documentation <type-promotion-doc>`.
  7707. Args:
  7708. from\_ (dtype): The original :class:`torch.dtype`.
  7709. to (dtype): The target :class:`torch.dtype`.
  7710. Example::
  7711. >>> torch.can_cast(torch.double, torch.float)
  7712. True
  7713. >>> torch.can_cast(torch.float, torch.int)
  7714. False
  7715. """
  7716. @overload
  7717. def cat(
  7718. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  7719. dim: _int = 0,
  7720. *,
  7721. out: Tensor | None = None,
  7722. ) -> Tensor:
  7723. r"""
  7724. cat(tensors, dim=0, *, out=None) -> Tensor
  7725. Concatenates the given sequence of tensors in :attr:`tensors` in the given dimension.
  7726. All tensors must either have the same shape (except in the concatenating
  7727. dimension) or be a 1-D empty tensor with size ``(0,)``.
  7728. :func:`torch.cat` can be seen as an inverse operation for :func:`torch.split`
  7729. and :func:`torch.chunk`.
  7730. :func:`torch.cat` can be best understood via examples.
  7731. .. seealso::
  7732. :func:`torch.stack` concatenates the given sequence along a new dimension.
  7733. Args:
  7734. tensors (sequence of Tensors): Non-empty tensors provided must have the same shape,
  7735. except in the cat dimension.
  7736. dim (int, optional): the dimension over which the tensors are concatenated
  7737. Keyword args:
  7738. out (Tensor, optional): the output tensor.
  7739. Example::
  7740. >>> x = torch.randn(2, 3)
  7741. >>> x
  7742. tensor([[ 0.6580, -1.0969, -0.4614],
  7743. [-0.1034, -0.5790, 0.1497]])
  7744. >>> torch.cat((x, x, x), 0)
  7745. tensor([[ 0.6580, -1.0969, -0.4614],
  7746. [-0.1034, -0.5790, 0.1497],
  7747. [ 0.6580, -1.0969, -0.4614],
  7748. [-0.1034, -0.5790, 0.1497],
  7749. [ 0.6580, -1.0969, -0.4614],
  7750. [-0.1034, -0.5790, 0.1497]])
  7751. >>> torch.cat((x, x, x), 1)
  7752. tensor([[ 0.6580, -1.0969, -0.4614, 0.6580, -1.0969, -0.4614, 0.6580,
  7753. -1.0969, -0.4614],
  7754. [-0.1034, -0.5790, 0.1497, -0.1034, -0.5790, 0.1497, -0.1034,
  7755. -0.5790, 0.1497]])
  7756. """
  7757. @overload
  7758. def cat(
  7759. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  7760. dim: str | EllipsisType | None,
  7761. *,
  7762. out: Tensor | None = None,
  7763. ) -> Tensor:
  7764. r"""
  7765. cat(tensors, dim=0, *, out=None) -> Tensor
  7766. Concatenates the given sequence of tensors in :attr:`tensors` in the given dimension.
  7767. All tensors must either have the same shape (except in the concatenating
  7768. dimension) or be a 1-D empty tensor with size ``(0,)``.
  7769. :func:`torch.cat` can be seen as an inverse operation for :func:`torch.split`
  7770. and :func:`torch.chunk`.
  7771. :func:`torch.cat` can be best understood via examples.
  7772. .. seealso::
  7773. :func:`torch.stack` concatenates the given sequence along a new dimension.
  7774. Args:
  7775. tensors (sequence of Tensors): Non-empty tensors provided must have the same shape,
  7776. except in the cat dimension.
  7777. dim (int, optional): the dimension over which the tensors are concatenated
  7778. Keyword args:
  7779. out (Tensor, optional): the output tensor.
  7780. Example::
  7781. >>> x = torch.randn(2, 3)
  7782. >>> x
  7783. tensor([[ 0.6580, -1.0969, -0.4614],
  7784. [-0.1034, -0.5790, 0.1497]])
  7785. >>> torch.cat((x, x, x), 0)
  7786. tensor([[ 0.6580, -1.0969, -0.4614],
  7787. [-0.1034, -0.5790, 0.1497],
  7788. [ 0.6580, -1.0969, -0.4614],
  7789. [-0.1034, -0.5790, 0.1497],
  7790. [ 0.6580, -1.0969, -0.4614],
  7791. [-0.1034, -0.5790, 0.1497]])
  7792. >>> torch.cat((x, x, x), 1)
  7793. tensor([[ 0.6580, -1.0969, -0.4614, 0.6580, -1.0969, -0.4614, 0.6580,
  7794. -1.0969, -0.4614],
  7795. [-0.1034, -0.5790, 0.1497, -0.1034, -0.5790, 0.1497, -0.1034,
  7796. -0.5790, 0.1497]])
  7797. """
  7798. def ccol_indices_copy(
  7799. input: Tensor,
  7800. *,
  7801. out: Tensor | None = None,
  7802. ) -> Tensor: ...
  7803. def ceil(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  7804. r"""
  7805. ceil(input, *, out=None) -> Tensor
  7806. Returns a new tensor with the ceil of the elements of :attr:`input`,
  7807. the smallest integer greater than or equal to each element.
  7808. For integer inputs, follows the array-api convention of returning a
  7809. copy of the input tensor.
  7810. .. math::
  7811. \text{out}_{i} = \left\lceil \text{input}_{i} \right\rceil
  7812. Args:
  7813. input (Tensor): the input tensor.
  7814. Keyword args:
  7815. out (Tensor, optional): the output tensor.
  7816. Example::
  7817. >>> a = torch.randn(4)
  7818. >>> a
  7819. tensor([-0.6341, -1.4208, -1.0900, 0.5826])
  7820. >>> torch.ceil(a)
  7821. tensor([-0., -1., -1., 1.])
  7822. """
  7823. def ceil_(input: Tensor) -> Tensor: ...
  7824. def celu(input: Tensor, alpha: Number | _complex = 1.0) -> Tensor: ...
  7825. def celu_(input: Tensor, alpha: Number | _complex = 1.0) -> Tensor: ...
  7826. def channel_shuffle(input: Tensor, groups: _int | SymInt) -> Tensor: ...
  7827. def cholesky(
  7828. input: Tensor,
  7829. upper: _bool = False,
  7830. *,
  7831. out: Tensor | None = None,
  7832. ) -> Tensor:
  7833. r"""
  7834. cholesky(input, upper=False, *, out=None) -> Tensor
  7835. Computes the Cholesky decomposition of a symmetric positive-definite
  7836. matrix :math:`A` or for batches of symmetric positive-definite matrices.
  7837. If :attr:`upper` is ``True``, the returned matrix ``U`` is upper-triangular, and
  7838. the decomposition has the form:
  7839. .. math::
  7840. A = U^TU
  7841. If :attr:`upper` is ``False``, the returned matrix ``L`` is lower-triangular, and
  7842. the decomposition has the form:
  7843. .. math::
  7844. A = LL^T
  7845. If :attr:`upper` is ``True``, and :math:`A` is a batch of symmetric positive-definite
  7846. matrices, then the returned tensor will be composed of upper-triangular Cholesky factors
  7847. of each of the individual matrices. Similarly, when :attr:`upper` is ``False``, the returned
  7848. tensor will be composed of lower-triangular Cholesky factors of each of the individual
  7849. matrices.
  7850. .. warning::
  7851. :func:`torch.cholesky` is deprecated in favor of :func:`torch.linalg.cholesky`
  7852. and will be removed in a future PyTorch release.
  7853. ``L = torch.cholesky(A)`` should be replaced with
  7854. .. code:: python
  7855. L = torch.linalg.cholesky(A)
  7856. ``U = torch.cholesky(A, upper=True)`` should be replaced with
  7857. .. code:: python
  7858. U = torch.linalg.cholesky(A).mH
  7859. This transform will produce equivalent results for all valid (symmetric positive definite) inputs.
  7860. Args:
  7861. input (Tensor): the input tensor :math:`A` of size :math:`(*, n, n)` where `*` is zero or more
  7862. batch dimensions consisting of symmetric positive-definite matrices.
  7863. upper (bool, optional): flag that indicates whether to return a
  7864. upper or lower triangular matrix. Default: ``False``
  7865. Keyword args:
  7866. out (Tensor, optional): the output matrix
  7867. Example::
  7868. >>> a = torch.randn(3, 3)
  7869. >>> a = a @ a.mT + 1e-3 # make symmetric positive-definite
  7870. >>> l = torch.cholesky(a)
  7871. >>> a
  7872. tensor([[ 2.4112, -0.7486, 1.4551],
  7873. [-0.7486, 1.3544, 0.1294],
  7874. [ 1.4551, 0.1294, 1.6724]])
  7875. >>> l
  7876. tensor([[ 1.5528, 0.0000, 0.0000],
  7877. [-0.4821, 1.0592, 0.0000],
  7878. [ 0.9371, 0.5487, 0.7023]])
  7879. >>> l @ l.mT
  7880. tensor([[ 2.4112, -0.7486, 1.4551],
  7881. [-0.7486, 1.3544, 0.1294],
  7882. [ 1.4551, 0.1294, 1.6724]])
  7883. >>> a = torch.randn(3, 2, 2) # Example for batched input
  7884. >>> a = a @ a.mT + 1e-03 # make symmetric positive-definite
  7885. >>> l = torch.cholesky(a)
  7886. >>> z = l @ l.mT
  7887. >>> torch.dist(z, a)
  7888. tensor(2.3842e-07)
  7889. """
  7890. def cholesky_inverse(
  7891. input: Tensor,
  7892. upper: _bool = False,
  7893. *,
  7894. out: Tensor | None = None,
  7895. ) -> Tensor:
  7896. r"""
  7897. cholesky_inverse(L, upper=False, *, out=None) -> Tensor
  7898. Computes the inverse of a complex Hermitian or real symmetric
  7899. positive-definite matrix given its Cholesky decomposition.
  7900. Let :math:`A` be a complex Hermitian or real symmetric positive-definite matrix,
  7901. and :math:`L` its Cholesky decomposition such that:
  7902. .. math::
  7903. A = LL^{\text{H}}
  7904. where :math:`L^{\text{H}}` is the conjugate transpose when :math:`L` is complex,
  7905. and the transpose when :math:`L` is real-valued.
  7906. Computes the inverse matrix :math:`A^{-1}`.
  7907. Supports input of float, double, cfloat and cdouble dtypes.
  7908. Also supports batches of matrices, and if :math:`A` is a batch of matrices
  7909. then the output has the same batch dimensions.
  7910. Args:
  7911. L (Tensor): tensor of shape `(*, n, n)` where `*` is zero or more batch dimensions
  7912. consisting of lower or upper triangular Cholesky decompositions of
  7913. symmetric or Hermitian positive-definite matrices.
  7914. upper (bool, optional): flag that indicates whether :math:`L` is lower triangular
  7915. or upper triangular. Default: ``False``
  7916. Keyword args:
  7917. out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
  7918. Example::
  7919. >>> A = torch.randn(3, 3)
  7920. >>> A = A @ A.T + torch.eye(3) * 1e-3 # Creates a symmetric positive-definite matrix
  7921. >>> L = torch.linalg.cholesky(A) # Extract Cholesky decomposition
  7922. >>> torch.cholesky_inverse(L)
  7923. tensor([[ 1.9314, 1.2251, -0.0889],
  7924. [ 1.2251, 2.4439, 0.2122],
  7925. [-0.0889, 0.2122, 0.1412]])
  7926. >>> A.inverse()
  7927. tensor([[ 1.9314, 1.2251, -0.0889],
  7928. [ 1.2251, 2.4439, 0.2122],
  7929. [-0.0889, 0.2122, 0.1412]])
  7930. >>> A = torch.randn(3, 2, 2, dtype=torch.complex64)
  7931. >>> A = A @ A.mH + torch.eye(2) * 1e-3 # Batch of Hermitian positive-definite matrices
  7932. >>> L = torch.linalg.cholesky(A)
  7933. >>> torch.dist(torch.inverse(A), torch.cholesky_inverse(L))
  7934. tensor(5.6358e-7)
  7935. """
  7936. def cholesky_solve(
  7937. input: Tensor,
  7938. input2: Tensor,
  7939. upper: _bool = False,
  7940. *,
  7941. out: Tensor | None = None,
  7942. ) -> Tensor:
  7943. r"""
  7944. cholesky_solve(B, L, upper=False, *, out=None) -> Tensor
  7945. Computes the solution of a system of linear equations with complex Hermitian
  7946. or real symmetric positive-definite lhs given its Cholesky decomposition.
  7947. Let :math:`A` be a complex Hermitian or real symmetric positive-definite matrix,
  7948. and :math:`L` its Cholesky decomposition such that:
  7949. .. math::
  7950. A = LL^{\text{H}}
  7951. where :math:`L^{\text{H}}` is the conjugate transpose when :math:`L` is complex,
  7952. and the transpose when :math:`L` is real-valued.
  7953. Returns the solution :math:`X` of the following linear system:
  7954. .. math::
  7955. AX = B
  7956. Supports inputs of float, double, cfloat and cdouble dtypes.
  7957. Also supports batches of matrices, and if :math:`A` or :math:`B` is a batch of matrices
  7958. then the output has the same batch dimensions.
  7959. Args:
  7960. B (Tensor): right-hand side tensor of shape `(*, n, k)`
  7961. where :math:`*` is zero or more batch dimensions
  7962. L (Tensor): tensor of shape `(*, n, n)` where `*` is zero or more batch dimensions
  7963. consisting of lower or upper triangular Cholesky decompositions of
  7964. symmetric or Hermitian positive-definite matrices.
  7965. upper (bool, optional): flag that indicates whether :math:`L` is lower triangular
  7966. or upper triangular. Default: ``False``.
  7967. Keyword args:
  7968. out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
  7969. Example::
  7970. >>> A = torch.randn(3, 3)
  7971. >>> A = A @ A.T + torch.eye(3) * 1e-3 # Creates a symmetric positive-definite matrix
  7972. >>> L = torch.linalg.cholesky(A) # Extract Cholesky decomposition
  7973. >>> B = torch.randn(3, 2)
  7974. >>> torch.cholesky_solve(B, L)
  7975. tensor([[ -8.1625, 19.6097],
  7976. [ -5.8398, 14.2387],
  7977. [ -4.3771, 10.4173]])
  7978. >>> A.inverse() @ B
  7979. tensor([[ -8.1626, 19.6097],
  7980. [ -5.8398, 14.2387],
  7981. [ -4.3771, 10.4173]])
  7982. >>> A = torch.randn(3, 2, 2, dtype=torch.complex64)
  7983. >>> A = A @ A.mH + torch.eye(2) * 1e-3 # Batch of Hermitian positive-definite matrices
  7984. >>> L = torch.linalg.cholesky(A)
  7985. >>> B = torch.randn(2, 1, dtype=torch.complex64)
  7986. >>> X = torch.cholesky_solve(B, L)
  7987. >>> torch.dist(X, A.inverse() @ B)
  7988. tensor(1.6881e-5)
  7989. """
  7990. def choose_qparams_optimized(
  7991. input: Tensor,
  7992. numel: _int,
  7993. n_bins: _int,
  7994. ratio: _float,
  7995. bit_width: _int,
  7996. ) -> tuple[Tensor, Tensor]: ...
  7997. def chunk(input: Tensor, chunks: _int, dim: _int = 0) -> tuple[Tensor, ...]:
  7998. r"""
  7999. chunk(input: Tensor, chunks: int, dim: int = 0) -> Tuple[Tensor, ...]
  8000. Attempts to split a tensor into the specified number of chunks. Each chunk is a view of
  8001. the input tensor.
  8002. .. note::
  8003. This function may return fewer than the specified number of chunks!
  8004. .. seealso::
  8005. :func:`torch.tensor_split` a function that always returns exactly the specified number of chunks
  8006. If the tensor size along the given dimension :attr:`dim` is divisible by :attr:`chunks`,
  8007. all returned chunks will be the same size.
  8008. If the tensor size along the given dimension :attr:`dim` is not divisible by :attr:`chunks`,
  8009. all returned chunks will be the same size, except the last one.
  8010. If such division is not possible, this function may return fewer
  8011. than the specified number of chunks.
  8012. Arguments:
  8013. input (Tensor): the tensor to split
  8014. chunks (int): number of chunks to return
  8015. dim (int): dimension along which to split the tensor
  8016. Example:
  8017. >>> torch.arange(11).chunk(6)
  8018. (tensor([0, 1]),
  8019. tensor([2, 3]),
  8020. tensor([4, 5]),
  8021. tensor([6, 7]),
  8022. tensor([8, 9]),
  8023. tensor([10]))
  8024. >>> torch.arange(12).chunk(6)
  8025. (tensor([0, 1]),
  8026. tensor([2, 3]),
  8027. tensor([4, 5]),
  8028. tensor([6, 7]),
  8029. tensor([8, 9]),
  8030. tensor([10, 11]))
  8031. >>> torch.arange(13).chunk(6)
  8032. (tensor([0, 1, 2]),
  8033. tensor([3, 4, 5]),
  8034. tensor([6, 7, 8]),
  8035. tensor([ 9, 10, 11]),
  8036. tensor([12]))
  8037. """
  8038. @overload
  8039. def clamp(
  8040. input: Tensor,
  8041. min: Tensor | None = None,
  8042. max: Tensor | None = None,
  8043. *,
  8044. out: Tensor | None = None,
  8045. ) -> Tensor:
  8046. r"""
  8047. clamp(input, min=None, max=None, *, out=None) -> Tensor
  8048. Clamps all elements in :attr:`input` into the range `[` :attr:`min`, :attr:`max` `]`.
  8049. Letting min_value and max_value be :attr:`min` and :attr:`max`, respectively, this returns:
  8050. .. math::
  8051. y_i = \min(\max(x_i, \text{min\_value}_i), \text{max\_value}_i)
  8052. If :attr:`min` is ``None``, there is no lower bound.
  8053. Or, if :attr:`max` is ``None`` there is no upper bound.
  8054. .. note::
  8055. If :attr:`min` is greater than :attr:`max` :func:`torch.clamp(..., min, max) <torch.clamp>`
  8056. sets all elements in :attr:`input` to the value of :attr:`max`.
  8057. Args:
  8058. input (Tensor): the input tensor.
  8059. min (Number or Tensor, optional): lower-bound of the range to be clamped to
  8060. max (Number or Tensor, optional): upper-bound of the range to be clamped to
  8061. Keyword args:
  8062. out (Tensor, optional): the output tensor.
  8063. Example::
  8064. >>> a = torch.randn(4)
  8065. >>> a
  8066. tensor([-1.7120, 0.1734, -0.0478, -0.0922])
  8067. >>> torch.clamp(a, min=-0.5, max=0.5)
  8068. tensor([-0.5000, 0.1734, -0.0478, -0.0922])
  8069. >>> min = torch.linspace(-1, 1, steps=4)
  8070. >>> torch.clamp(a, min=min)
  8071. tensor([-1.0000, 0.1734, 0.3333, 1.0000])
  8072. """
  8073. @overload
  8074. def clamp(
  8075. input: Tensor,
  8076. min: Number | _complex | None = None,
  8077. max: Number | _complex | None = None,
  8078. *,
  8079. out: Tensor | None = None,
  8080. ) -> Tensor:
  8081. r"""
  8082. clamp(input, min=None, max=None, *, out=None) -> Tensor
  8083. Clamps all elements in :attr:`input` into the range `[` :attr:`min`, :attr:`max` `]`.
  8084. Letting min_value and max_value be :attr:`min` and :attr:`max`, respectively, this returns:
  8085. .. math::
  8086. y_i = \min(\max(x_i, \text{min\_value}_i), \text{max\_value}_i)
  8087. If :attr:`min` is ``None``, there is no lower bound.
  8088. Or, if :attr:`max` is ``None`` there is no upper bound.
  8089. .. note::
  8090. If :attr:`min` is greater than :attr:`max` :func:`torch.clamp(..., min, max) <torch.clamp>`
  8091. sets all elements in :attr:`input` to the value of :attr:`max`.
  8092. Args:
  8093. input (Tensor): the input tensor.
  8094. min (Number or Tensor, optional): lower-bound of the range to be clamped to
  8095. max (Number or Tensor, optional): upper-bound of the range to be clamped to
  8096. Keyword args:
  8097. out (Tensor, optional): the output tensor.
  8098. Example::
  8099. >>> a = torch.randn(4)
  8100. >>> a
  8101. tensor([-1.7120, 0.1734, -0.0478, -0.0922])
  8102. >>> torch.clamp(a, min=-0.5, max=0.5)
  8103. tensor([-0.5000, 0.1734, -0.0478, -0.0922])
  8104. >>> min = torch.linspace(-1, 1, steps=4)
  8105. >>> torch.clamp(a, min=min)
  8106. tensor([-1.0000, 0.1734, 0.3333, 1.0000])
  8107. """
  8108. @overload
  8109. def clamp_(
  8110. input: Tensor,
  8111. min: Tensor | None = None,
  8112. max: Tensor | None = None,
  8113. ) -> Tensor: ...
  8114. @overload
  8115. def clamp_(
  8116. input: Tensor,
  8117. min: Number | _complex | None = None,
  8118. max: Number | _complex | None = None,
  8119. ) -> Tensor: ...
  8120. @overload
  8121. def clamp_max(
  8122. input: Tensor,
  8123. max: Tensor,
  8124. *,
  8125. out: Tensor | None = None,
  8126. ) -> Tensor: ...
  8127. @overload
  8128. def clamp_max(
  8129. input: Tensor,
  8130. max: Number | _complex,
  8131. *,
  8132. out: Tensor | None = None,
  8133. ) -> Tensor: ...
  8134. @overload
  8135. def clamp_max_(input: Tensor, max: Tensor) -> Tensor: ...
  8136. @overload
  8137. def clamp_max_(input: Tensor, max: Number | _complex) -> Tensor: ...
  8138. @overload
  8139. def clamp_min(
  8140. input: Tensor,
  8141. min: Tensor,
  8142. *,
  8143. out: Tensor | None = None,
  8144. ) -> Tensor: ...
  8145. @overload
  8146. def clamp_min(
  8147. input: Tensor,
  8148. min: Number | _complex,
  8149. *,
  8150. out: Tensor | None = None,
  8151. ) -> Tensor: ...
  8152. @overload
  8153. def clamp_min_(input: Tensor, min: Tensor) -> Tensor: ...
  8154. @overload
  8155. def clamp_min_(input: Tensor, min: Number | _complex) -> Tensor: ...
  8156. @overload
  8157. def clip(
  8158. input: Tensor,
  8159. min: Tensor | None = None,
  8160. max: Tensor | None = None,
  8161. *,
  8162. out: Tensor | None = None,
  8163. ) -> Tensor:
  8164. r"""
  8165. clip(input, min=None, max=None, *, out=None) -> Tensor
  8166. Alias for :func:`torch.clamp`.
  8167. """
  8168. @overload
  8169. def clip(
  8170. input: Tensor,
  8171. min: Number | _complex | None = None,
  8172. max: Number | _complex | None = None,
  8173. *,
  8174. out: Tensor | None = None,
  8175. ) -> Tensor:
  8176. r"""
  8177. clip(input, min=None, max=None, *, out=None) -> Tensor
  8178. Alias for :func:`torch.clamp`.
  8179. """
  8180. @overload
  8181. def clip_(
  8182. input: Tensor,
  8183. min: Tensor | None = None,
  8184. max: Tensor | None = None,
  8185. ) -> Tensor: ...
  8186. @overload
  8187. def clip_(
  8188. input: Tensor,
  8189. min: Number | _complex | None = None,
  8190. max: Number | _complex | None = None,
  8191. ) -> Tensor: ...
  8192. def clone(
  8193. input: Tensor,
  8194. *,
  8195. memory_format: memory_format | None = None,
  8196. ) -> Tensor:
  8197. r"""
  8198. clone(input, *, memory_format=torch.preserve_format) -> Tensor
  8199. Returns a copy of :attr:`input`.
  8200. .. note::
  8201. This function is differentiable, so gradients will flow back from the
  8202. result of this operation to :attr:`input`. To create a tensor without an
  8203. autograd relationship to :attr:`input` see :meth:`~Tensor.detach`.
  8204. In addition, when ``torch.preserve_format`` is used:
  8205. If the input tensor is dense (i.e., non-overlapping strided),
  8206. its memory format (including strides) is retained.
  8207. Otherwise (e.g., a non-dense view like a stepped slice),
  8208. the output is converted to the dense (contiguous) format.
  8209. Args:
  8210. input (Tensor): the input tensor.
  8211. Keyword args:
  8212. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  8213. returned tensor. Default: ``torch.preserve_format``.
  8214. """
  8215. def col_indices_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  8216. r"""
  8217. Performs the same operation as :func:`torch.col_indices`, but all output tensors
  8218. are freshly created instead of aliasing the input.
  8219. """
  8220. def column_stack(
  8221. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  8222. *,
  8223. out: Tensor | None = None,
  8224. ) -> Tensor:
  8225. r"""
  8226. column_stack(tensors, *, out=None) -> Tensor
  8227. Creates a new tensor by horizontally stacking the tensors in :attr:`tensors`.
  8228. Equivalent to ``torch.hstack(tensors)``, except each zero or one dimensional tensor ``t``
  8229. in :attr:`tensors` is first reshaped into a ``(t.numel(), 1)`` column before being stacked horizontally.
  8230. Args:
  8231. tensors (sequence of Tensors): sequence of tensors to concatenate
  8232. Keyword args:
  8233. out (Tensor, optional): the output tensor.
  8234. Example::
  8235. >>> a = torch.tensor([1, 2, 3])
  8236. >>> b = torch.tensor([4, 5, 6])
  8237. >>> torch.column_stack((a, b))
  8238. tensor([[1, 4],
  8239. [2, 5],
  8240. [3, 6]])
  8241. >>> a = torch.arange(5)
  8242. >>> b = torch.arange(10).reshape(5, 2)
  8243. >>> torch.column_stack((a, b, b))
  8244. tensor([[0, 0, 1, 0, 1],
  8245. [1, 2, 3, 2, 3],
  8246. [2, 4, 5, 4, 5],
  8247. [3, 6, 7, 6, 7],
  8248. [4, 8, 9, 8, 9]])
  8249. """
  8250. def combinations(
  8251. input: Tensor,
  8252. r: _int = 2,
  8253. with_replacement: _bool = False,
  8254. ) -> Tensor:
  8255. r"""
  8256. combinations(input: Tensor, r: int = 2, with_replacement: bool = False) -> seq
  8257. Compute combinations of length :math:`r` of the given tensor. The behavior is similar to
  8258. python's `itertools.combinations` when `with_replacement` is set to `False`, and
  8259. `itertools.combinations_with_replacement` when `with_replacement` is set to `True`.
  8260. Arguments:
  8261. input (Tensor): 1D vector.
  8262. r (int, optional): number of elements to combine
  8263. with_replacement (bool, optional): whether to allow duplication in combination
  8264. Returns:
  8265. Tensor: A tensor equivalent to converting all the input tensors into lists, do
  8266. `itertools.combinations` or `itertools.combinations_with_replacement` on these
  8267. lists, and finally convert the resulting list into tensor.
  8268. Example::
  8269. >>> a = [1, 2, 3]
  8270. >>> list(itertools.combinations(a, r=2))
  8271. [(1, 2), (1, 3), (2, 3)]
  8272. >>> list(itertools.combinations(a, r=3))
  8273. [(1, 2, 3)]
  8274. >>> list(itertools.combinations_with_replacement(a, r=2))
  8275. [(1, 1), (1, 2), (1, 3), (2, 2), (2, 3), (3, 3)]
  8276. >>> tensor_a = torch.tensor(a)
  8277. >>> torch.combinations(tensor_a)
  8278. tensor([[1, 2],
  8279. [1, 3],
  8280. [2, 3]])
  8281. >>> torch.combinations(tensor_a, r=3)
  8282. tensor([[1, 2, 3]])
  8283. >>> torch.combinations(tensor_a, with_replacement=True)
  8284. tensor([[1, 1],
  8285. [1, 2],
  8286. [1, 3],
  8287. [2, 2],
  8288. [2, 3],
  8289. [3, 3]])
  8290. """
  8291. def complex(
  8292. real: Tensor,
  8293. imag: Tensor,
  8294. *,
  8295. out: Tensor | None = None,
  8296. ) -> Tensor:
  8297. r"""
  8298. complex(real, imag, *, out=None) -> Tensor
  8299. Constructs a complex tensor with its real part equal to :attr:`real` and its
  8300. imaginary part equal to :attr:`imag`.
  8301. Args:
  8302. real (Tensor): The real part of the complex tensor. Must be half, float or double.
  8303. imag (Tensor): The imaginary part of the complex tensor. Must be same dtype
  8304. as :attr:`real`.
  8305. Keyword args:
  8306. out (Tensor): If the inputs are ``torch.float32``, must be
  8307. ``torch.complex64``. If the inputs are ``torch.float64``, must be
  8308. ``torch.complex128``.
  8309. Example::
  8310. >>> real = torch.tensor([1, 2], dtype=torch.float32)
  8311. >>> imag = torch.tensor([3, 4], dtype=torch.float32)
  8312. >>> z = torch.complex(real, imag)
  8313. >>> z
  8314. tensor([(1.+3.j), (2.+4.j)])
  8315. >>> z.dtype
  8316. torch.complex64
  8317. """
  8318. @overload
  8319. def concat(
  8320. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  8321. dim: _int = 0,
  8322. *,
  8323. out: Tensor | None = None,
  8324. ) -> Tensor:
  8325. r"""
  8326. concat(tensors, dim=0, *, out=None) -> Tensor
  8327. Alias of :func:`torch.cat`.
  8328. """
  8329. @overload
  8330. def concat(
  8331. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  8332. dim: str | EllipsisType | None,
  8333. *,
  8334. out: Tensor | None = None,
  8335. ) -> Tensor:
  8336. r"""
  8337. concat(tensors, dim=0, *, out=None) -> Tensor
  8338. Alias of :func:`torch.cat`.
  8339. """
  8340. @overload
  8341. def concatenate(
  8342. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  8343. dim: _int = 0,
  8344. *,
  8345. out: Tensor | None = None,
  8346. ) -> Tensor:
  8347. r"""
  8348. concatenate(tensors, axis=0, out=None) -> Tensor
  8349. Alias of :func:`torch.cat`.
  8350. """
  8351. @overload
  8352. def concatenate(
  8353. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  8354. dim: str | EllipsisType | None,
  8355. *,
  8356. out: Tensor | None = None,
  8357. ) -> Tensor:
  8358. r"""
  8359. concatenate(tensors, axis=0, out=None) -> Tensor
  8360. Alias of :func:`torch.cat`.
  8361. """
  8362. def conj(input: Tensor) -> Tensor:
  8363. r"""
  8364. conj(input) -> Tensor
  8365. Returns a view of :attr:`input` with a flipped conjugate bit. If :attr:`input` has a non-complex dtype,
  8366. this function just returns :attr:`input`.
  8367. .. note::
  8368. :func:`torch.conj` performs a lazy conjugation, but the actual conjugated tensor can be materialized
  8369. at any time using :func:`torch.resolve_conj`.
  8370. .. warning:: In the future, :func:`torch.conj` may return a non-writeable view for an :attr:`input` of
  8371. non-complex dtype. It's recommended that programs not modify the tensor returned by :func:`torch.conj_physical`
  8372. when :attr:`input` is of non-complex dtype to be compatible with this change.
  8373. Args:
  8374. input (Tensor): the input tensor.
  8375. Example::
  8376. >>> x = torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j])
  8377. >>> x.is_conj()
  8378. False
  8379. >>> y = torch.conj(x)
  8380. >>> y.is_conj()
  8381. True
  8382. """
  8383. def conj_physical(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  8384. r"""
  8385. conj_physical(input, *, out=None) -> Tensor
  8386. Computes the element-wise conjugate of the given :attr:`input` tensor.
  8387. If :attr:`input` has a non-complex dtype, this function just returns :attr:`input`.
  8388. .. note::
  8389. This performs the conjugate operation regardless of the fact conjugate bit is set or not.
  8390. .. warning:: In the future, :func:`torch.conj_physical` may return a non-writeable view for an :attr:`input` of
  8391. non-complex dtype. It's recommended that programs not modify the tensor returned by :func:`torch.conj_physical`
  8392. when :attr:`input` is of non-complex dtype to be compatible with this change.
  8393. .. math::
  8394. \text{out}_{i} = conj(\text{input}_{i})
  8395. Args:
  8396. input (Tensor): the input tensor.
  8397. Keyword args:
  8398. out (Tensor, optional): the output tensor.
  8399. Example::
  8400. >>> torch.conj_physical(torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j]))
  8401. tensor([-1 - 1j, -2 - 2j, 3 + 3j])
  8402. """
  8403. def conj_physical_(input: Tensor) -> Tensor: ...
  8404. def constant_pad_nd(
  8405. input: Tensor,
  8406. pad: Sequence[_int | SymInt],
  8407. value: Number | _complex = 0,
  8408. ) -> Tensor: ...
  8409. @overload
  8410. def conv1d(
  8411. input: Tensor,
  8412. weight: Tensor,
  8413. bias: Tensor | None = None,
  8414. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8415. padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8416. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8417. groups: _int | SymInt = 1,
  8418. ) -> Tensor: ...
  8419. @overload
  8420. def conv1d(
  8421. input: Tensor,
  8422. weight: Tensor,
  8423. bias: Tensor | None = None,
  8424. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8425. padding: str = "valid",
  8426. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8427. groups: _int | SymInt = 1,
  8428. ) -> Tensor: ...
  8429. @overload
  8430. def conv2d(
  8431. input: Tensor,
  8432. weight: Tensor,
  8433. bias: Tensor | None = None,
  8434. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8435. padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8436. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8437. groups: _int | SymInt = 1,
  8438. ) -> Tensor: ...
  8439. @overload
  8440. def conv2d(
  8441. input: Tensor,
  8442. weight: Tensor,
  8443. bias: Tensor | None = None,
  8444. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8445. padding: str = "valid",
  8446. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8447. groups: _int | SymInt = 1,
  8448. ) -> Tensor: ...
  8449. @overload
  8450. def conv3d(
  8451. input: Tensor,
  8452. weight: Tensor,
  8453. bias: Tensor | None = None,
  8454. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8455. padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8456. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8457. groups: _int | SymInt = 1,
  8458. ) -> Tensor: ...
  8459. @overload
  8460. def conv3d(
  8461. input: Tensor,
  8462. weight: Tensor,
  8463. bias: Tensor | None = None,
  8464. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8465. padding: str = "valid",
  8466. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8467. groups: _int | SymInt = 1,
  8468. ) -> Tensor: ...
  8469. def conv_tbc(
  8470. input: Tensor,
  8471. weight: Tensor,
  8472. bias: Tensor,
  8473. pad: _int = 0,
  8474. ) -> Tensor: ...
  8475. def conv_transpose1d(
  8476. input: Tensor,
  8477. weight: Tensor,
  8478. bias: Tensor | None = None,
  8479. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8480. padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8481. output_padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8482. groups: _int | SymInt = 1,
  8483. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8484. ) -> Tensor: ...
  8485. def conv_transpose2d(
  8486. input: Tensor,
  8487. weight: Tensor,
  8488. bias: Tensor | None = None,
  8489. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8490. padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8491. output_padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8492. groups: _int | SymInt = 1,
  8493. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8494. ) -> Tensor: ...
  8495. def conv_transpose3d(
  8496. input: Tensor,
  8497. weight: Tensor,
  8498. bias: Tensor | None = None,
  8499. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8500. padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8501. output_padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8502. groups: _int | SymInt = 1,
  8503. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8504. ) -> Tensor: ...
  8505. def convolution(
  8506. input: Tensor,
  8507. weight: Tensor,
  8508. bias: Tensor | None,
  8509. stride: Sequence[_int | SymInt],
  8510. padding: Sequence[_int | SymInt],
  8511. dilation: Sequence[_int | SymInt],
  8512. transposed: _bool,
  8513. output_padding: Sequence[_int | SymInt],
  8514. groups: _int | SymInt,
  8515. ) -> Tensor: ...
  8516. @overload
  8517. def copysign(
  8518. input: Tensor,
  8519. other: Tensor,
  8520. *,
  8521. out: Tensor | None = None,
  8522. ) -> Tensor:
  8523. r"""
  8524. copysign(input, other, *, out=None) -> Tensor
  8525. Create a new floating-point tensor with the magnitude of :attr:`input` and the sign of :attr:`other`, elementwise.
  8526. .. math::
  8527. \text{out}_{i} = \begin{cases}
  8528. -|\text{input}_{i}| & \text{if } \text{other}_{i} \leq -0.0 \\
  8529. |\text{input}_{i}| & \text{if } \text{other}_{i} \geq 0.0 \\
  8530. \end{cases}
  8531. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  8532. and integer and float inputs.
  8533. Args:
  8534. input (Tensor): magnitudes.
  8535. other (Tensor or Number): contains value(s) whose signbit(s) are
  8536. applied to the magnitudes in :attr:`input`.
  8537. Keyword args:
  8538. out (Tensor, optional): the output tensor.
  8539. Example::
  8540. >>> a = torch.randn(5)
  8541. >>> a
  8542. tensor([-1.2557, -0.0026, -0.5387, 0.4740, -0.9244])
  8543. >>> torch.copysign(a, 1)
  8544. tensor([1.2557, 0.0026, 0.5387, 0.4740, 0.9244])
  8545. >>> a = torch.randn(4, 4)
  8546. >>> a
  8547. tensor([[ 0.7079, 0.2778, -1.0249, 0.5719],
  8548. [-0.0059, -0.2600, -0.4475, -1.3948],
  8549. [ 0.3667, -0.9567, -2.5757, -0.1751],
  8550. [ 0.2046, -0.0742, 0.2998, -0.1054]])
  8551. >>> b = torch.randn(4)
  8552. tensor([ 0.2373, 0.3120, 0.3190, -1.1128])
  8553. >>> torch.copysign(a, b)
  8554. tensor([[ 0.7079, 0.2778, 1.0249, -0.5719],
  8555. [ 0.0059, 0.2600, 0.4475, -1.3948],
  8556. [ 0.3667, 0.9567, 2.5757, -0.1751],
  8557. [ 0.2046, 0.0742, 0.2998, -0.1054]])
  8558. >>> a = torch.tensor([1.])
  8559. >>> b = torch.tensor([-0.])
  8560. >>> torch.copysign(a, b)
  8561. tensor([-1.])
  8562. .. note::
  8563. copysign handles signed zeros. If the other argument has a negative zero (-0),
  8564. the corresponding output value will be negative.
  8565. """
  8566. @overload
  8567. def copysign(
  8568. input: Tensor,
  8569. other: Number | _complex,
  8570. *,
  8571. out: Tensor | None = None,
  8572. ) -> Tensor:
  8573. r"""
  8574. copysign(input, other, *, out=None) -> Tensor
  8575. Create a new floating-point tensor with the magnitude of :attr:`input` and the sign of :attr:`other`, elementwise.
  8576. .. math::
  8577. \text{out}_{i} = \begin{cases}
  8578. -|\text{input}_{i}| & \text{if } \text{other}_{i} \leq -0.0 \\
  8579. |\text{input}_{i}| & \text{if } \text{other}_{i} \geq 0.0 \\
  8580. \end{cases}
  8581. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  8582. and integer and float inputs.
  8583. Args:
  8584. input (Tensor): magnitudes.
  8585. other (Tensor or Number): contains value(s) whose signbit(s) are
  8586. applied to the magnitudes in :attr:`input`.
  8587. Keyword args:
  8588. out (Tensor, optional): the output tensor.
  8589. Example::
  8590. >>> a = torch.randn(5)
  8591. >>> a
  8592. tensor([-1.2557, -0.0026, -0.5387, 0.4740, -0.9244])
  8593. >>> torch.copysign(a, 1)
  8594. tensor([1.2557, 0.0026, 0.5387, 0.4740, 0.9244])
  8595. >>> a = torch.randn(4, 4)
  8596. >>> a
  8597. tensor([[ 0.7079, 0.2778, -1.0249, 0.5719],
  8598. [-0.0059, -0.2600, -0.4475, -1.3948],
  8599. [ 0.3667, -0.9567, -2.5757, -0.1751],
  8600. [ 0.2046, -0.0742, 0.2998, -0.1054]])
  8601. >>> b = torch.randn(4)
  8602. tensor([ 0.2373, 0.3120, 0.3190, -1.1128])
  8603. >>> torch.copysign(a, b)
  8604. tensor([[ 0.7079, 0.2778, 1.0249, -0.5719],
  8605. [ 0.0059, 0.2600, 0.4475, -1.3948],
  8606. [ 0.3667, 0.9567, 2.5757, -0.1751],
  8607. [ 0.2046, 0.0742, 0.2998, -0.1054]])
  8608. >>> a = torch.tensor([1.])
  8609. >>> b = torch.tensor([-0.])
  8610. >>> torch.copysign(a, b)
  8611. tensor([-1.])
  8612. .. note::
  8613. copysign handles signed zeros. If the other argument has a negative zero (-0),
  8614. the corresponding output value will be negative.
  8615. """
  8616. def corrcoef(input: Tensor) -> Tensor:
  8617. r"""
  8618. corrcoef(input) -> Tensor
  8619. Estimates the Pearson product-moment correlation coefficient matrix of the variables given by the :attr:`input` matrix,
  8620. where rows are the variables and columns are the observations.
  8621. .. note::
  8622. The correlation coefficient matrix R is computed using the covariance matrix C as given by
  8623. :math:`R_{ij} = \frac{ C_{ij} } { \sqrt{ C_{ii} * C_{jj} } }`
  8624. .. note::
  8625. Due to floating point rounding, the resulting array may not be Hermitian and its diagonal elements may not be 1.
  8626. The real and imaginary values are clipped to the interval [-1, 1] in an attempt to improve this situation.
  8627. Args:
  8628. input (Tensor): A 2D matrix containing multiple variables and observations, or a
  8629. Scalar or 1D vector representing a single variable.
  8630. Returns:
  8631. (Tensor) The correlation coefficient matrix of the variables.
  8632. .. seealso::
  8633. :func:`torch.cov` covariance matrix.
  8634. Example::
  8635. >>> x = torch.tensor([[0, 1, 2], [2, 1, 0]])
  8636. >>> torch.corrcoef(x)
  8637. tensor([[ 1., -1.],
  8638. [-1., 1.]])
  8639. >>> x = torch.randn(2, 4)
  8640. >>> x
  8641. tensor([[-0.2678, -0.0908, -0.3766, 0.2780],
  8642. [-0.5812, 0.1535, 0.2387, 0.2350]])
  8643. >>> torch.corrcoef(x)
  8644. tensor([[1.0000, 0.3582],
  8645. [0.3582, 1.0000]])
  8646. >>> torch.corrcoef(x[0])
  8647. tensor(1.)
  8648. """
  8649. def cos(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  8650. r"""
  8651. cos(input, *, out=None) -> Tensor
  8652. Returns a new tensor with the cosine of the elements of :attr:`input` given in radians.
  8653. .. math::
  8654. \text{out}_{i} = \cos(\text{input}_{i})
  8655. Args:
  8656. input (Tensor): the input tensor.
  8657. Keyword args:
  8658. out (Tensor, optional): the output tensor.
  8659. Example::
  8660. >>> a = torch.randn(4)
  8661. >>> a
  8662. tensor([ 1.4309, 1.2706, -0.8562, 0.9796])
  8663. >>> torch.cos(a)
  8664. tensor([ 0.1395, 0.2957, 0.6553, 0.5574])
  8665. """
  8666. def cos_(input: Tensor) -> Tensor: ...
  8667. def cosh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  8668. r"""
  8669. cosh(input, *, out=None) -> Tensor
  8670. Returns a new tensor with the hyperbolic cosine of the elements of
  8671. :attr:`input`.
  8672. .. math::
  8673. \text{out}_{i} = \cosh(\text{input}_{i})
  8674. Args:
  8675. input (Tensor): the input tensor.
  8676. Keyword args:
  8677. out (Tensor, optional): the output tensor.
  8678. Example::
  8679. >>> a = torch.randn(4)
  8680. >>> a
  8681. tensor([ 0.1632, 1.1835, -0.6979, -0.7325])
  8682. >>> torch.cosh(a)
  8683. tensor([ 1.0133, 1.7860, 1.2536, 1.2805])
  8684. .. note::
  8685. When :attr:`input` is on the CPU, the implementation of torch.cosh may use
  8686. the Sleef library, which rounds very large results to infinity or negative
  8687. infinity. See `here <https://sleef.org/purec.xhtml>`_ for details.
  8688. """
  8689. def cosh_(input: Tensor) -> Tensor: ...
  8690. def cosine_embedding_loss(
  8691. input1: Tensor,
  8692. input2: Tensor,
  8693. target: Tensor,
  8694. margin: _float = 0.0,
  8695. reduction: _int = 1,
  8696. ) -> Tensor: ...
  8697. def cosine_similarity(
  8698. x1: Tensor,
  8699. x2: Tensor,
  8700. dim: _int = 1,
  8701. eps: _float = 1e-08,
  8702. ) -> Tensor: ...
  8703. @overload
  8704. def count_nonzero(input: Tensor, dim: _int | None = None) -> Tensor:
  8705. r"""
  8706. count_nonzero(input, dim=None) -> Tensor
  8707. Counts the number of non-zero values in the tensor :attr:`input` along the given :attr:`dim`.
  8708. If no dim is specified then all non-zeros in the tensor are counted.
  8709. Args:
  8710. input (Tensor): the input tensor.
  8711. dim (int or tuple of ints, optional): Dim or tuple of dims along which to count non-zeros.
  8712. Example::
  8713. >>> x = torch.zeros(3,3)
  8714. >>> x[torch.randn(3,3) > 0.5] = 1
  8715. >>> x
  8716. tensor([[0., 1., 1.],
  8717. [0., 0., 0.],
  8718. [0., 0., 1.]])
  8719. >>> torch.count_nonzero(x)
  8720. tensor(3)
  8721. >>> torch.count_nonzero(x, dim=0)
  8722. tensor([0, 1, 2])
  8723. """
  8724. @overload
  8725. def count_nonzero(input: Tensor, dim: _size) -> Tensor:
  8726. r"""
  8727. count_nonzero(input, dim=None) -> Tensor
  8728. Counts the number of non-zero values in the tensor :attr:`input` along the given :attr:`dim`.
  8729. If no dim is specified then all non-zeros in the tensor are counted.
  8730. Args:
  8731. input (Tensor): the input tensor.
  8732. dim (int or tuple of ints, optional): Dim or tuple of dims along which to count non-zeros.
  8733. Example::
  8734. >>> x = torch.zeros(3,3)
  8735. >>> x[torch.randn(3,3) > 0.5] = 1
  8736. >>> x
  8737. tensor([[0., 1., 1.],
  8738. [0., 0., 0.],
  8739. [0., 0., 1.]])
  8740. >>> torch.count_nonzero(x)
  8741. tensor(3)
  8742. >>> torch.count_nonzero(x, dim=0)
  8743. tensor([0, 1, 2])
  8744. """
  8745. def cov(
  8746. input: Tensor,
  8747. *,
  8748. correction: _int = 1,
  8749. fweights: Tensor | None = None,
  8750. aweights: Tensor | None = None,
  8751. ) -> Tensor:
  8752. r"""
  8753. cov(input, *, correction=1, fweights=None, aweights=None) -> Tensor
  8754. Estimates the covariance matrix of the variables given by the :attr:`input` matrix, where rows are
  8755. the variables and columns are the observations.
  8756. A covariance matrix is a square matrix giving the covariance of each pair of variables. The diagonal contains
  8757. the variance of each variable (covariance of a variable with itself). By definition, if :attr:`input` represents
  8758. a single variable (Scalar or 1D) then its variance is returned.
  8759. The sample covariance of the variables :math:`x` and :math:`y` is given by:
  8760. .. math::
  8761. \text{cov}(x,y) = \frac{\sum^{N}_{i = 1}(x_{i} - \bar{x})(y_{i} - \bar{y})}{\max(0,~N~-~\delta N)}
  8762. where :math:`\bar{x}` and :math:`\bar{y}` are the simple means of the :math:`x` and :math:`y` respectively, and
  8763. :math:`\delta N` is the :attr:`correction`.
  8764. If :attr:`fweights` and/or :attr:`aweights` are provided, the weighted covariance
  8765. is calculated, which is given by:
  8766. .. math::
  8767. \text{cov}_w(x,y) = \frac{\sum^{N}_{i = 1}w_i(x_{i} - \mu_x^*)(y_{i} - \mu_y^*)}
  8768. {\max(0,~\sum^{N}_{i = 1}w_i~-~\frac{\sum^{N}_{i = 1}w_ia_i}{\sum^{N}_{i = 1}w_i}~\delta N)}
  8769. where :math:`w` denotes :attr:`fweights` or :attr:`aweights` (``f`` and ``a`` for brevity) based on whichever is
  8770. provided, or :math:`w = f \times a` if both are provided, and
  8771. :math:`\mu_x^* = \frac{\sum^{N}_{i = 1}w_ix_{i} }{\sum^{N}_{i = 1}w_i}` is the weighted mean of the variable. If not
  8772. provided, ``f`` and/or ``a`` can be seen as a :math:`\mathbb{1}` vector of appropriate size.
  8773. Args:
  8774. input (Tensor): A 2D matrix containing multiple variables and observations, or a
  8775. Scalar or 1D vector representing a single variable.
  8776. Keyword Args:
  8777. correction (int, optional): difference between the sample size and sample degrees of freedom.
  8778. Defaults to Bessel's correction, ``correction = 1`` which returns the unbiased estimate,
  8779. even if both :attr:`fweights` and :attr:`aweights` are specified. ``correction = 0``
  8780. will return the simple average. Defaults to ``1``.
  8781. fweights (tensor, optional): A Scalar or 1D tensor of observation vector frequencies representing the number of
  8782. times each observation should be repeated. Its numel must equal the number of columns of :attr:`input`.
  8783. Must have integral dtype. Ignored if ``None``. Defaults to ``None``.
  8784. aweights (tensor, optional): A Scalar or 1D array of observation vector weights.
  8785. These relative weights are typically large for observations considered "important" and smaller for
  8786. observations considered less "important". Its numel must equal the number of columns of :attr:`input`.
  8787. Must have floating point dtype. Ignored if ``None``. Defaults to ``None``.
  8788. Returns:
  8789. (Tensor) The covariance matrix of the variables.
  8790. .. seealso::
  8791. :func:`torch.corrcoef` normalized covariance matrix.
  8792. Example::
  8793. >>> x = torch.tensor([[0, 2], [1, 1], [2, 0]]).T
  8794. >>> x
  8795. tensor([[0, 1, 2],
  8796. [2, 1, 0]])
  8797. >>> torch.cov(x)
  8798. tensor([[ 1., -1.],
  8799. [-1., 1.]])
  8800. >>> torch.cov(x, correction=0)
  8801. tensor([[ 0.6667, -0.6667],
  8802. [-0.6667, 0.6667]])
  8803. >>> fw = torch.randint(1, 10, (3,))
  8804. >>> fw
  8805. tensor([1, 6, 9])
  8806. >>> aw = torch.rand(3)
  8807. >>> aw
  8808. tensor([0.4282, 0.0255, 0.4144])
  8809. >>> torch.cov(x, fweights=fw, aweights=aw)
  8810. tensor([[ 0.4169, -0.4169],
  8811. [-0.4169, 0.4169]])
  8812. """
  8813. def cross(
  8814. input: Tensor,
  8815. other: Tensor,
  8816. dim: _int | None = None,
  8817. *,
  8818. out: Tensor | None = None,
  8819. ) -> Tensor:
  8820. r"""
  8821. cross(input, other, dim=None, *, out=None) -> Tensor
  8822. Returns the cross product of vectors in dimension :attr:`dim` of :attr:`input`
  8823. and :attr:`other`.
  8824. Supports input of float, double, cfloat and cdouble dtypes. Also supports batches
  8825. of vectors, for which it computes the product along the dimension :attr:`dim`.
  8826. In this case, the output has the same batch dimensions as the inputs.
  8827. .. warning::
  8828. If :attr:`dim` is not given, it defaults to the first dimension found
  8829. with the size 3. Note that this might be unexpected.
  8830. This behavior is deprecated and will be changed to match that of :func:`torch.linalg.cross`
  8831. in a future release.
  8832. .. seealso::
  8833. :func:`torch.linalg.cross` which has dim=-1 as default.
  8834. Args:
  8835. input (Tensor): the input tensor.
  8836. other (Tensor): the second input tensor
  8837. dim (int, optional): the dimension to take the cross-product in.
  8838. Keyword args:
  8839. out (Tensor, optional): the output tensor.
  8840. Example::
  8841. >>> a = torch.randn(4, 3)
  8842. >>> a
  8843. tensor([[-0.3956, 1.1455, 1.6895],
  8844. [-0.5849, 1.3672, 0.3599],
  8845. [-1.1626, 0.7180, -0.0521],
  8846. [-0.1339, 0.9902, -2.0225]])
  8847. >>> b = torch.randn(4, 3)
  8848. >>> b
  8849. tensor([[-0.0257, -1.4725, -1.2251],
  8850. [-1.1479, -0.7005, -1.9757],
  8851. [-1.3904, 0.3726, -1.1836],
  8852. [-0.9688, -0.7153, 0.2159]])
  8853. >>> torch.cross(a, b, dim=1)
  8854. tensor([[ 1.0844, -0.5281, 0.6120],
  8855. [-2.4490, -1.5687, 1.9792],
  8856. [-0.8304, -1.3037, 0.5650],
  8857. [-1.2329, 1.9883, 1.0551]])
  8858. >>> torch.cross(a, b)
  8859. tensor([[ 1.0844, -0.5281, 0.6120],
  8860. [-2.4490, -1.5687, 1.9792],
  8861. [-0.8304, -1.3037, 0.5650],
  8862. [-1.2329, 1.9883, 1.0551]])
  8863. """
  8864. def crow_indices_copy(
  8865. input: Tensor,
  8866. *,
  8867. out: Tensor | None = None,
  8868. ) -> Tensor:
  8869. r"""
  8870. Performs the same operation as :func:`torch.crow_indices`, but all output tensors
  8871. are freshly created instead of aliasing the input.
  8872. """
  8873. @overload
  8874. def ctc_loss(
  8875. log_probs: Tensor,
  8876. targets: Tensor,
  8877. input_lengths: _size,
  8878. target_lengths: _size,
  8879. blank: _int = 0,
  8880. reduction: _int = 1,
  8881. zero_infinity: _bool = False,
  8882. ) -> Tensor: ...
  8883. @overload
  8884. def ctc_loss(
  8885. log_probs: Tensor,
  8886. targets: Tensor,
  8887. input_lengths: Tensor,
  8888. target_lengths: Tensor,
  8889. blank: _int = 0,
  8890. reduction: _int = 1,
  8891. zero_infinity: _bool = False,
  8892. ) -> Tensor: ...
  8893. def cudnn_affine_grid_generator(
  8894. theta: Tensor,
  8895. N: _int,
  8896. C: _int,
  8897. H: _int,
  8898. W: _int,
  8899. ) -> Tensor: ...
  8900. def cudnn_batch_norm(
  8901. input: Tensor,
  8902. weight: Tensor,
  8903. bias: Tensor | None,
  8904. running_mean: Tensor | None,
  8905. running_var: Tensor | None,
  8906. training: _bool,
  8907. exponential_average_factor: _float,
  8908. epsilon: _float,
  8909. *,
  8910. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  8911. ) -> tuple[Tensor, Tensor, Tensor, Tensor]: ...
  8912. def cudnn_convolution(
  8913. input: Tensor,
  8914. weight: Tensor,
  8915. padding: Sequence[_int | SymInt],
  8916. stride: Sequence[_int | SymInt],
  8917. dilation: Sequence[_int | SymInt],
  8918. groups: _int | SymInt,
  8919. benchmark: _bool,
  8920. deterministic: _bool,
  8921. allow_tf32: _bool,
  8922. *,
  8923. out: Tensor | None = None,
  8924. ) -> Tensor: ...
  8925. def cudnn_convolution_add_relu(
  8926. input: Tensor,
  8927. weight: Tensor,
  8928. z: Tensor,
  8929. alpha: Number | _complex | None,
  8930. bias: Tensor | None,
  8931. stride: Sequence[_int | SymInt],
  8932. padding: Sequence[_int | SymInt],
  8933. dilation: Sequence[_int | SymInt],
  8934. groups: _int | SymInt,
  8935. ) -> Tensor: ...
  8936. def cudnn_convolution_relu(
  8937. input: Tensor,
  8938. weight: Tensor,
  8939. bias: Tensor | None,
  8940. stride: Sequence[_int | SymInt],
  8941. padding: Sequence[_int | SymInt],
  8942. dilation: Sequence[_int | SymInt],
  8943. groups: _int | SymInt,
  8944. ) -> Tensor: ...
  8945. def cudnn_convolution_transpose(
  8946. input: Tensor,
  8947. weight: Tensor,
  8948. padding: Sequence[_int | SymInt],
  8949. output_padding: Sequence[_int | SymInt],
  8950. stride: Sequence[_int | SymInt],
  8951. dilation: Sequence[_int | SymInt],
  8952. groups: _int | SymInt,
  8953. benchmark: _bool,
  8954. deterministic: _bool,
  8955. allow_tf32: _bool,
  8956. ) -> Tensor: ...
  8957. def cudnn_grid_sampler(input: Tensor, grid: Tensor) -> Tensor: ...
  8958. def cudnn_is_acceptable(input: Tensor) -> _bool: ...
  8959. @overload
  8960. def cummax(
  8961. input: Tensor,
  8962. dim: _int,
  8963. *,
  8964. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  8965. ) -> torch.return_types.cummax:
  8966. r"""
  8967. cummax(input, dim, *, out=None) -> (Tensor, LongTensor)
  8968. Returns a namedtuple ``(values, indices)`` where ``values`` is the cumulative maximum of
  8969. elements of :attr:`input` in the dimension :attr:`dim`. And ``indices`` is the index
  8970. location of each maximum value found in the dimension :attr:`dim`.
  8971. .. math::
  8972. y_i = max(x_1, x_2, x_3, \dots, x_i)
  8973. Args:
  8974. input (Tensor): the input tensor.
  8975. dim (int): the dimension to do the operation over
  8976. Keyword args:
  8977. out (tuple, optional): the result tuple of two output tensors (values, indices)
  8978. Example::
  8979. >>> a = torch.randn(10)
  8980. >>> a
  8981. tensor([-0.3449, -1.5447, 0.0685, -1.5104, -1.1706, 0.2259, 1.4696, -1.3284,
  8982. 1.9946, -0.8209])
  8983. >>> torch.cummax(a, dim=0)
  8984. torch.return_types.cummax(
  8985. values=tensor([-0.3449, -0.3449, 0.0685, 0.0685, 0.0685, 0.2259, 1.4696, 1.4696,
  8986. 1.9946, 1.9946]),
  8987. indices=tensor([0, 0, 2, 2, 2, 5, 6, 6, 8, 8]))
  8988. """
  8989. @overload
  8990. def cummax(
  8991. input: Tensor,
  8992. dim: str | EllipsisType | None,
  8993. *,
  8994. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  8995. ) -> torch.return_types.cummax:
  8996. r"""
  8997. cummax(input, dim, *, out=None) -> (Tensor, LongTensor)
  8998. Returns a namedtuple ``(values, indices)`` where ``values`` is the cumulative maximum of
  8999. elements of :attr:`input` in the dimension :attr:`dim`. And ``indices`` is the index
  9000. location of each maximum value found in the dimension :attr:`dim`.
  9001. .. math::
  9002. y_i = max(x_1, x_2, x_3, \dots, x_i)
  9003. Args:
  9004. input (Tensor): the input tensor.
  9005. dim (int): the dimension to do the operation over
  9006. Keyword args:
  9007. out (tuple, optional): the result tuple of two output tensors (values, indices)
  9008. Example::
  9009. >>> a = torch.randn(10)
  9010. >>> a
  9011. tensor([-0.3449, -1.5447, 0.0685, -1.5104, -1.1706, 0.2259, 1.4696, -1.3284,
  9012. 1.9946, -0.8209])
  9013. >>> torch.cummax(a, dim=0)
  9014. torch.return_types.cummax(
  9015. values=tensor([-0.3449, -0.3449, 0.0685, 0.0685, 0.0685, 0.2259, 1.4696, 1.4696,
  9016. 1.9946, 1.9946]),
  9017. indices=tensor([0, 0, 2, 2, 2, 5, 6, 6, 8, 8]))
  9018. """
  9019. @overload
  9020. def cummin(
  9021. input: Tensor,
  9022. dim: _int,
  9023. *,
  9024. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  9025. ) -> torch.return_types.cummin:
  9026. r"""
  9027. cummin(input, dim, *, out=None) -> (Tensor, LongTensor)
  9028. Returns a namedtuple ``(values, indices)`` where ``values`` is the cumulative minimum of
  9029. elements of :attr:`input` in the dimension :attr:`dim`. And ``indices`` is the index
  9030. location of each maximum value found in the dimension :attr:`dim`.
  9031. .. math::
  9032. y_i = min(x_1, x_2, x_3, \dots, x_i)
  9033. Args:
  9034. input (Tensor): the input tensor.
  9035. dim (int): the dimension to do the operation over
  9036. Keyword args:
  9037. out (tuple, optional): the result tuple of two output tensors (values, indices)
  9038. Example::
  9039. >>> a = torch.randn(10)
  9040. >>> a
  9041. tensor([-0.2284, -0.6628, 0.0975, 0.2680, -1.3298, -0.4220, -0.3885, 1.1762,
  9042. 0.9165, 1.6684])
  9043. >>> torch.cummin(a, dim=0)
  9044. torch.return_types.cummin(
  9045. values=tensor([-0.2284, -0.6628, -0.6628, -0.6628, -1.3298, -1.3298, -1.3298, -1.3298,
  9046. -1.3298, -1.3298]),
  9047. indices=tensor([0, 1, 1, 1, 4, 4, 4, 4, 4, 4]))
  9048. """
  9049. @overload
  9050. def cummin(
  9051. input: Tensor,
  9052. dim: str | EllipsisType | None,
  9053. *,
  9054. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  9055. ) -> torch.return_types.cummin:
  9056. r"""
  9057. cummin(input, dim, *, out=None) -> (Tensor, LongTensor)
  9058. Returns a namedtuple ``(values, indices)`` where ``values`` is the cumulative minimum of
  9059. elements of :attr:`input` in the dimension :attr:`dim`. And ``indices`` is the index
  9060. location of each maximum value found in the dimension :attr:`dim`.
  9061. .. math::
  9062. y_i = min(x_1, x_2, x_3, \dots, x_i)
  9063. Args:
  9064. input (Tensor): the input tensor.
  9065. dim (int): the dimension to do the operation over
  9066. Keyword args:
  9067. out (tuple, optional): the result tuple of two output tensors (values, indices)
  9068. Example::
  9069. >>> a = torch.randn(10)
  9070. >>> a
  9071. tensor([-0.2284, -0.6628, 0.0975, 0.2680, -1.3298, -0.4220, -0.3885, 1.1762,
  9072. 0.9165, 1.6684])
  9073. >>> torch.cummin(a, dim=0)
  9074. torch.return_types.cummin(
  9075. values=tensor([-0.2284, -0.6628, -0.6628, -0.6628, -1.3298, -1.3298, -1.3298, -1.3298,
  9076. -1.3298, -1.3298]),
  9077. indices=tensor([0, 1, 1, 1, 4, 4, 4, 4, 4, 4]))
  9078. """
  9079. @overload
  9080. def cumprod(
  9081. input: Tensor,
  9082. dim: _int,
  9083. *,
  9084. dtype: _dtype | None = None,
  9085. out: Tensor | None = None,
  9086. ) -> Tensor:
  9087. r"""
  9088. cumprod(input, dim, *, dtype=None, out=None) -> Tensor
  9089. Returns the cumulative product of elements of :attr:`input` in the dimension
  9090. :attr:`dim`.
  9091. For example, if :attr:`input` is a vector of size N, the result will also be
  9092. a vector of size N, with elements.
  9093. .. math::
  9094. y_i = x_1 \times x_2\times x_3\times \dots \times x_i
  9095. Args:
  9096. input (Tensor): the input tensor.
  9097. dim (int): the dimension to do the operation over
  9098. Keyword args:
  9099. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  9100. If specified, the input tensor is casted to :attr:`dtype` before the operation
  9101. is performed. This is useful for preventing data type overflows. Default: None.
  9102. out (Tensor, optional): the output tensor.
  9103. Example::
  9104. >>> a = torch.randn(10)
  9105. >>> a
  9106. tensor([ 0.6001, 0.2069, -0.1919, 0.9792, 0.6727, 1.0062, 0.4126,
  9107. -0.2129, -0.4206, 0.1968])
  9108. >>> torch.cumprod(a, dim=0)
  9109. tensor([ 0.6001, 0.1241, -0.0238, -0.0233, -0.0157, -0.0158, -0.0065,
  9110. 0.0014, -0.0006, -0.0001])
  9111. >>> a[5] = 0.0
  9112. >>> torch.cumprod(a, dim=0)
  9113. tensor([ 0.6001, 0.1241, -0.0238, -0.0233, -0.0157, -0.0000, -0.0000,
  9114. 0.0000, -0.0000, -0.0000])
  9115. """
  9116. @overload
  9117. def cumprod(
  9118. input: Tensor,
  9119. dim: str | EllipsisType | None,
  9120. *,
  9121. dtype: _dtype | None = None,
  9122. out: Tensor | None = None,
  9123. ) -> Tensor:
  9124. r"""
  9125. cumprod(input, dim, *, dtype=None, out=None) -> Tensor
  9126. Returns the cumulative product of elements of :attr:`input` in the dimension
  9127. :attr:`dim`.
  9128. For example, if :attr:`input` is a vector of size N, the result will also be
  9129. a vector of size N, with elements.
  9130. .. math::
  9131. y_i = x_1 \times x_2\times x_3\times \dots \times x_i
  9132. Args:
  9133. input (Tensor): the input tensor.
  9134. dim (int): the dimension to do the operation over
  9135. Keyword args:
  9136. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  9137. If specified, the input tensor is casted to :attr:`dtype` before the operation
  9138. is performed. This is useful for preventing data type overflows. Default: None.
  9139. out (Tensor, optional): the output tensor.
  9140. Example::
  9141. >>> a = torch.randn(10)
  9142. >>> a
  9143. tensor([ 0.6001, 0.2069, -0.1919, 0.9792, 0.6727, 1.0062, 0.4126,
  9144. -0.2129, -0.4206, 0.1968])
  9145. >>> torch.cumprod(a, dim=0)
  9146. tensor([ 0.6001, 0.1241, -0.0238, -0.0233, -0.0157, -0.0158, -0.0065,
  9147. 0.0014, -0.0006, -0.0001])
  9148. >>> a[5] = 0.0
  9149. >>> torch.cumprod(a, dim=0)
  9150. tensor([ 0.6001, 0.1241, -0.0238, -0.0233, -0.0157, -0.0000, -0.0000,
  9151. 0.0000, -0.0000, -0.0000])
  9152. """
  9153. @overload
  9154. def cumsum(
  9155. input: Tensor,
  9156. dim: _int,
  9157. *,
  9158. dtype: _dtype | None = None,
  9159. out: Tensor | None = None,
  9160. ) -> Tensor:
  9161. r"""
  9162. cumsum(input, dim, *, dtype=None, out=None) -> Tensor
  9163. Returns the cumulative sum of elements of :attr:`input` in the dimension
  9164. :attr:`dim`.
  9165. For example, if :attr:`input` is a vector of size N, the result will also be
  9166. a vector of size N, with elements.
  9167. .. math::
  9168. y_i = x_1 + x_2 + x_3 + \dots + x_i
  9169. Args:
  9170. input (Tensor): the input tensor.
  9171. dim (int): the dimension to do the operation over
  9172. Keyword args:
  9173. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  9174. If specified, the input tensor is casted to :attr:`dtype` before the operation
  9175. is performed. This is useful for preventing data type overflows. Default: None.
  9176. out (Tensor, optional): the output tensor.
  9177. Example::
  9178. >>> a = torch.randint(1, 20, (10,))
  9179. >>> a
  9180. tensor([13, 7, 3, 10, 13, 3, 15, 10, 9, 10])
  9181. >>> torch.cumsum(a, dim=0)
  9182. tensor([13, 20, 23, 33, 46, 49, 64, 74, 83, 93])
  9183. """
  9184. @overload
  9185. def cumsum(
  9186. input: Tensor,
  9187. dim: str | EllipsisType | None,
  9188. *,
  9189. dtype: _dtype | None = None,
  9190. out: Tensor | None = None,
  9191. ) -> Tensor:
  9192. r"""
  9193. cumsum(input, dim, *, dtype=None, out=None) -> Tensor
  9194. Returns the cumulative sum of elements of :attr:`input` in the dimension
  9195. :attr:`dim`.
  9196. For example, if :attr:`input` is a vector of size N, the result will also be
  9197. a vector of size N, with elements.
  9198. .. math::
  9199. y_i = x_1 + x_2 + x_3 + \dots + x_i
  9200. Args:
  9201. input (Tensor): the input tensor.
  9202. dim (int): the dimension to do the operation over
  9203. Keyword args:
  9204. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  9205. If specified, the input tensor is casted to :attr:`dtype` before the operation
  9206. is performed. This is useful for preventing data type overflows. Default: None.
  9207. out (Tensor, optional): the output tensor.
  9208. Example::
  9209. >>> a = torch.randint(1, 20, (10,))
  9210. >>> a
  9211. tensor([13, 7, 3, 10, 13, 3, 15, 10, 9, 10])
  9212. >>> torch.cumsum(a, dim=0)
  9213. tensor([13, 20, 23, 33, 46, 49, 64, 74, 83, 93])
  9214. """
  9215. @overload
  9216. def cumulative_trapezoid(y: Tensor, x: Tensor, *, dim: _int = -1) -> Tensor:
  9217. r"""
  9218. cumulative_trapezoid(y, x=None, *, dx=None, dim=-1) -> Tensor
  9219. Cumulatively computes the `trapezoidal rule <https://en.wikipedia.org/wiki/Trapezoidal_rule>`_
  9220. along :attr:`dim`. By default the spacing between elements is assumed to be 1, but
  9221. :attr:`dx` can be used to specify a different constant spacing, and :attr:`x` can be
  9222. used to specify arbitrary spacing along :attr:`dim`.
  9223. For more details, please read :func:`torch.trapezoid`. The difference between :func:`torch.trapezoid`
  9224. and this function is that, :func:`torch.trapezoid` returns a value for each integration,
  9225. where as this function returns a cumulative value for every spacing within the integration. This
  9226. is analogous to how `.sum` returns a value and `.cumsum` returns a cumulative sum.
  9227. Arguments:
  9228. y (Tensor): Values to use when computing the trapezoidal rule.
  9229. x (Tensor): If specified, defines spacing between values as specified above.
  9230. Keyword arguments:
  9231. dx (float): constant spacing between values. If neither :attr:`x` or :attr:`dx`
  9232. are specified then this defaults to 1. Effectively multiplies the result by its value.
  9233. dim (int): The dimension along which to compute the trapezoidal rule.
  9234. The last (inner-most) dimension by default.
  9235. Examples::
  9236. >>> # Cumulatively computes the trapezoidal rule in 1D, spacing is implicitly 1.
  9237. >>> y = torch.tensor([1, 5, 10])
  9238. >>> torch.cumulative_trapezoid(y)
  9239. tensor([3., 10.5])
  9240. >>> # Computes the same trapezoidal rule directly up to each element to verify
  9241. >>> (1 + 5) / 2
  9242. 3.0
  9243. >>> (1 + 10 + 10) / 2
  9244. 10.5
  9245. >>> # Cumulatively computes the trapezoidal rule in 1D with constant spacing of 2
  9246. >>> # NOTE: the result is the same as before, but multiplied by 2
  9247. >>> torch.cumulative_trapezoid(y, dx=2)
  9248. tensor([6., 21.])
  9249. >>> # Cumulatively computes the trapezoidal rule in 1D with arbitrary spacing
  9250. >>> x = torch.tensor([1, 3, 6])
  9251. >>> torch.cumulative_trapezoid(y, x)
  9252. tensor([6., 28.5])
  9253. >>> # Computes the same trapezoidal rule directly up to each element to verify
  9254. >>> ((3 - 1) * (1 + 5)) / 2
  9255. 6.0
  9256. >>> ((3 - 1) * (1 + 5) + (6 - 3) * (5 + 10)) / 2
  9257. 28.5
  9258. >>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 matrix
  9259. >>> y = torch.arange(9).reshape(3, 3)
  9260. tensor([[0, 1, 2],
  9261. [3, 4, 5],
  9262. [6, 7, 8]])
  9263. >>> torch.cumulative_trapezoid(y)
  9264. tensor([[ 0.5, 2.],
  9265. [ 3.5, 8.],
  9266. [ 6.5, 14.]])
  9267. >>> # Cumulatively computes the trapezoidal rule for each column of the matrix
  9268. >>> torch.cumulative_trapezoid(y, dim=0)
  9269. tensor([[ 1.5, 2.5, 3.5],
  9270. [ 6.0, 8.0, 10.0]])
  9271. >>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 ones matrix
  9272. >>> # with the same arbitrary spacing
  9273. >>> y = torch.ones(3, 3)
  9274. >>> x = torch.tensor([1, 3, 6])
  9275. >>> torch.cumulative_trapezoid(y, x)
  9276. tensor([[2., 5.],
  9277. [2., 5.],
  9278. [2., 5.]])
  9279. >>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 ones matrix
  9280. >>> # with different arbitrary spacing per row
  9281. >>> y = torch.ones(3, 3)
  9282. >>> x = torch.tensor([[1, 2, 3], [1, 3, 5], [1, 4, 7]])
  9283. >>> torch.cumulative_trapezoid(y, x)
  9284. tensor([[1., 2.],
  9285. [2., 4.],
  9286. [3., 6.]])
  9287. """
  9288. @overload
  9289. def cumulative_trapezoid(
  9290. y: Tensor,
  9291. *,
  9292. dx: Number | _complex = 1,
  9293. dim: _int = -1,
  9294. ) -> Tensor:
  9295. r"""
  9296. cumulative_trapezoid(y, x=None, *, dx=None, dim=-1) -> Tensor
  9297. Cumulatively computes the `trapezoidal rule <https://en.wikipedia.org/wiki/Trapezoidal_rule>`_
  9298. along :attr:`dim`. By default the spacing between elements is assumed to be 1, but
  9299. :attr:`dx` can be used to specify a different constant spacing, and :attr:`x` can be
  9300. used to specify arbitrary spacing along :attr:`dim`.
  9301. For more details, please read :func:`torch.trapezoid`. The difference between :func:`torch.trapezoid`
  9302. and this function is that, :func:`torch.trapezoid` returns a value for each integration,
  9303. where as this function returns a cumulative value for every spacing within the integration. This
  9304. is analogous to how `.sum` returns a value and `.cumsum` returns a cumulative sum.
  9305. Arguments:
  9306. y (Tensor): Values to use when computing the trapezoidal rule.
  9307. x (Tensor): If specified, defines spacing between values as specified above.
  9308. Keyword arguments:
  9309. dx (float): constant spacing between values. If neither :attr:`x` or :attr:`dx`
  9310. are specified then this defaults to 1. Effectively multiplies the result by its value.
  9311. dim (int): The dimension along which to compute the trapezoidal rule.
  9312. The last (inner-most) dimension by default.
  9313. Examples::
  9314. >>> # Cumulatively computes the trapezoidal rule in 1D, spacing is implicitly 1.
  9315. >>> y = torch.tensor([1, 5, 10])
  9316. >>> torch.cumulative_trapezoid(y)
  9317. tensor([3., 10.5])
  9318. >>> # Computes the same trapezoidal rule directly up to each element to verify
  9319. >>> (1 + 5) / 2
  9320. 3.0
  9321. >>> (1 + 10 + 10) / 2
  9322. 10.5
  9323. >>> # Cumulatively computes the trapezoidal rule in 1D with constant spacing of 2
  9324. >>> # NOTE: the result is the same as before, but multiplied by 2
  9325. >>> torch.cumulative_trapezoid(y, dx=2)
  9326. tensor([6., 21.])
  9327. >>> # Cumulatively computes the trapezoidal rule in 1D with arbitrary spacing
  9328. >>> x = torch.tensor([1, 3, 6])
  9329. >>> torch.cumulative_trapezoid(y, x)
  9330. tensor([6., 28.5])
  9331. >>> # Computes the same trapezoidal rule directly up to each element to verify
  9332. >>> ((3 - 1) * (1 + 5)) / 2
  9333. 6.0
  9334. >>> ((3 - 1) * (1 + 5) + (6 - 3) * (5 + 10)) / 2
  9335. 28.5
  9336. >>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 matrix
  9337. >>> y = torch.arange(9).reshape(3, 3)
  9338. tensor([[0, 1, 2],
  9339. [3, 4, 5],
  9340. [6, 7, 8]])
  9341. >>> torch.cumulative_trapezoid(y)
  9342. tensor([[ 0.5, 2.],
  9343. [ 3.5, 8.],
  9344. [ 6.5, 14.]])
  9345. >>> # Cumulatively computes the trapezoidal rule for each column of the matrix
  9346. >>> torch.cumulative_trapezoid(y, dim=0)
  9347. tensor([[ 1.5, 2.5, 3.5],
  9348. [ 6.0, 8.0, 10.0]])
  9349. >>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 ones matrix
  9350. >>> # with the same arbitrary spacing
  9351. >>> y = torch.ones(3, 3)
  9352. >>> x = torch.tensor([1, 3, 6])
  9353. >>> torch.cumulative_trapezoid(y, x)
  9354. tensor([[2., 5.],
  9355. [2., 5.],
  9356. [2., 5.]])
  9357. >>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 ones matrix
  9358. >>> # with different arbitrary spacing per row
  9359. >>> y = torch.ones(3, 3)
  9360. >>> x = torch.tensor([[1, 2, 3], [1, 3, 5], [1, 4, 7]])
  9361. >>> torch.cumulative_trapezoid(y, x)
  9362. tensor([[1., 2.],
  9363. [2., 4.],
  9364. [3., 6.]])
  9365. """
  9366. def deg2rad(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  9367. r"""
  9368. deg2rad(input, *, out=None) -> Tensor
  9369. Returns a new tensor with each of the elements of :attr:`input`
  9370. converted from angles in degrees to radians.
  9371. Args:
  9372. input (Tensor): the input tensor.
  9373. Keyword arguments:
  9374. out (Tensor, optional): the output tensor.
  9375. Example::
  9376. >>> a = torch.tensor([[180.0, -180.0], [360.0, -360.0], [90.0, -90.0]])
  9377. >>> torch.deg2rad(a)
  9378. tensor([[ 3.1416, -3.1416],
  9379. [ 6.2832, -6.2832],
  9380. [ 1.5708, -1.5708]])
  9381. """
  9382. def deg2rad_(input: Tensor) -> Tensor: ...
  9383. @overload
  9384. def dequantize(input: Tensor) -> Tensor:
  9385. r"""
  9386. dequantize(tensor) -> Tensor
  9387. Returns an fp32 Tensor by dequantizing a quantized Tensor
  9388. Args:
  9389. tensor (Tensor): A quantized Tensor
  9390. .. function:: dequantize(tensors) -> sequence of Tensors
  9391. :noindex:
  9392. Given a list of quantized Tensors, dequantize them and return a list of fp32 Tensors
  9393. Args:
  9394. tensors (sequence of Tensors): A list of quantized Tensors
  9395. """
  9396. @overload
  9397. def dequantize(
  9398. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  9399. ) -> tuple[Tensor, ...]:
  9400. r"""
  9401. dequantize(tensor) -> Tensor
  9402. Returns an fp32 Tensor by dequantizing a quantized Tensor
  9403. Args:
  9404. tensor (Tensor): A quantized Tensor
  9405. .. function:: dequantize(tensors) -> sequence of Tensors
  9406. :noindex:
  9407. Given a list of quantized Tensors, dequantize them and return a list of fp32 Tensors
  9408. Args:
  9409. tensors (sequence of Tensors): A list of quantized Tensors
  9410. """
  9411. def det(input: Tensor) -> Tensor:
  9412. r"""
  9413. det(input) -> Tensor
  9414. Alias for :func:`torch.linalg.det`
  9415. """
  9416. def detach(input: Tensor) -> Tensor: ...
  9417. def detach_(input: Tensor) -> Tensor: ...
  9418. def detach_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  9419. r"""
  9420. Performs the same operation as :func:`torch.detach`, but all output tensors
  9421. are freshly created instead of aliasing the input.
  9422. """
  9423. def diag(
  9424. input: Tensor,
  9425. diagonal: _int = 0,
  9426. *,
  9427. out: Tensor | None = None,
  9428. ) -> Tensor:
  9429. r"""
  9430. diag(input, diagonal=0, *, out=None) -> Tensor
  9431. - If :attr:`input` is a vector (1-D tensor), then returns a 2-D square tensor
  9432. with the elements of :attr:`input` as the diagonal.
  9433. - If :attr:`input` is a matrix (2-D tensor), then returns a 1-D tensor with
  9434. the diagonal elements of :attr:`input`.
  9435. The argument :attr:`diagonal` controls which diagonal to consider:
  9436. - If :attr:`diagonal` = 0, it is the main diagonal.
  9437. - If :attr:`diagonal` > 0, it is above the main diagonal.
  9438. - If :attr:`diagonal` < 0, it is below the main diagonal.
  9439. Args:
  9440. input (Tensor): the input tensor.
  9441. diagonal (int, optional): the diagonal to consider
  9442. Keyword args:
  9443. out (Tensor, optional): the output tensor.
  9444. .. seealso::
  9445. :func:`torch.diagonal` always returns the diagonal of its input.
  9446. :func:`torch.diagflat` always constructs a tensor with diagonal elements
  9447. specified by the input.
  9448. Examples:
  9449. Get the square matrix where the input vector is the diagonal::
  9450. >>> a = torch.randn(3)
  9451. >>> a
  9452. tensor([ 0.5950,-0.0872, 2.3298])
  9453. >>> torch.diag(a)
  9454. tensor([[ 0.5950, 0.0000, 0.0000],
  9455. [ 0.0000,-0.0872, 0.0000],
  9456. [ 0.0000, 0.0000, 2.3298]])
  9457. >>> torch.diag(a, 1)
  9458. tensor([[ 0.0000, 0.5950, 0.0000, 0.0000],
  9459. [ 0.0000, 0.0000,-0.0872, 0.0000],
  9460. [ 0.0000, 0.0000, 0.0000, 2.3298],
  9461. [ 0.0000, 0.0000, 0.0000, 0.0000]])
  9462. Get the k-th diagonal of a given matrix::
  9463. >>> a = torch.randn(3, 3)
  9464. >>> a
  9465. tensor([[-0.4264, 0.0255,-0.1064],
  9466. [ 0.8795,-0.2429, 0.1374],
  9467. [ 0.1029,-0.6482,-1.6300]])
  9468. >>> torch.diag(a, 0)
  9469. tensor([-0.4264,-0.2429,-1.6300])
  9470. >>> torch.diag(a, 1)
  9471. tensor([ 0.0255, 0.1374])
  9472. """
  9473. def diag_embed(
  9474. input: Tensor,
  9475. offset: _int = 0,
  9476. dim1: _int = -2,
  9477. dim2: _int = -1,
  9478. ) -> Tensor:
  9479. r"""
  9480. diag_embed(input, offset=0, dim1=-2, dim2=-1) -> Tensor
  9481. Creates a tensor whose diagonals of certain 2D planes (specified by
  9482. :attr:`dim1` and :attr:`dim2`) are filled by :attr:`input`.
  9483. To facilitate creating batched diagonal matrices, the 2D planes formed by
  9484. the last two dimensions of the returned tensor are chosen by default.
  9485. The argument :attr:`offset` controls which diagonal to consider:
  9486. - If :attr:`offset` = 0, it is the main diagonal.
  9487. - If :attr:`offset` > 0, it is above the main diagonal.
  9488. - If :attr:`offset` < 0, it is below the main diagonal.
  9489. The size of the new matrix will be calculated to make the specified diagonal
  9490. of the size of the last input dimension.
  9491. Note that for :attr:`offset` other than :math:`0`, the order of :attr:`dim1`
  9492. and :attr:`dim2` matters. Exchanging them is equivalent to changing the
  9493. sign of :attr:`offset`.
  9494. Applying :meth:`torch.diagonal` to the output of this function with
  9495. the same arguments yields a matrix identical to input. However,
  9496. :meth:`torch.diagonal` has different default dimensions, so those
  9497. need to be explicitly specified.
  9498. Args:
  9499. input (Tensor): the input tensor. Must be at least 1-dimensional.
  9500. offset (int, optional): which diagonal to consider. Default: 0
  9501. (main diagonal).
  9502. dim1 (int, optional): first dimension with respect to which to
  9503. take diagonal. Default: -2.
  9504. dim2 (int, optional): second dimension with respect to which to
  9505. take diagonal. Default: -1.
  9506. Example::
  9507. >>> a = torch.randn(2, 3)
  9508. >>> torch.diag_embed(a)
  9509. tensor([[[ 1.5410, 0.0000, 0.0000],
  9510. [ 0.0000, -0.2934, 0.0000],
  9511. [ 0.0000, 0.0000, -2.1788]],
  9512. [[ 0.5684, 0.0000, 0.0000],
  9513. [ 0.0000, -1.0845, 0.0000],
  9514. [ 0.0000, 0.0000, -1.3986]]])
  9515. >>> torch.diag_embed(a, offset=1, dim1=0, dim2=2)
  9516. tensor([[[ 0.0000, 1.5410, 0.0000, 0.0000],
  9517. [ 0.0000, 0.5684, 0.0000, 0.0000]],
  9518. [[ 0.0000, 0.0000, -0.2934, 0.0000],
  9519. [ 0.0000, 0.0000, -1.0845, 0.0000]],
  9520. [[ 0.0000, 0.0000, 0.0000, -2.1788],
  9521. [ 0.0000, 0.0000, 0.0000, -1.3986]],
  9522. [[ 0.0000, 0.0000, 0.0000, 0.0000],
  9523. [ 0.0000, 0.0000, 0.0000, 0.0000]]])
  9524. """
  9525. def diagflat(input: Tensor, offset: _int = 0) -> Tensor:
  9526. r"""
  9527. diagflat(input, offset=0) -> Tensor
  9528. - If :attr:`input` is a vector (1-D tensor), then returns a 2-D square tensor
  9529. with the elements of :attr:`input` as the diagonal.
  9530. - If :attr:`input` is a tensor with more than one dimension, then returns a
  9531. 2-D tensor with diagonal elements equal to a flattened :attr:`input`.
  9532. The argument :attr:`offset` controls which diagonal to consider:
  9533. - If :attr:`offset` = 0, it is the main diagonal.
  9534. - If :attr:`offset` > 0, it is above the main diagonal.
  9535. - If :attr:`offset` < 0, it is below the main diagonal.
  9536. Args:
  9537. input (Tensor): the input tensor.
  9538. offset (int, optional): the diagonal to consider. Default: 0 (main
  9539. diagonal).
  9540. Examples::
  9541. >>> a = torch.randn(3)
  9542. >>> a
  9543. tensor([-0.2956, -0.9068, 0.1695])
  9544. >>> torch.diagflat(a)
  9545. tensor([[-0.2956, 0.0000, 0.0000],
  9546. [ 0.0000, -0.9068, 0.0000],
  9547. [ 0.0000, 0.0000, 0.1695]])
  9548. >>> torch.diagflat(a, 1)
  9549. tensor([[ 0.0000, -0.2956, 0.0000, 0.0000],
  9550. [ 0.0000, 0.0000, -0.9068, 0.0000],
  9551. [ 0.0000, 0.0000, 0.0000, 0.1695],
  9552. [ 0.0000, 0.0000, 0.0000, 0.0000]])
  9553. >>> a = torch.randn(2, 2)
  9554. >>> a
  9555. tensor([[ 0.2094, -0.3018],
  9556. [-0.1516, 1.9342]])
  9557. >>> torch.diagflat(a)
  9558. tensor([[ 0.2094, 0.0000, 0.0000, 0.0000],
  9559. [ 0.0000, -0.3018, 0.0000, 0.0000],
  9560. [ 0.0000, 0.0000, -0.1516, 0.0000],
  9561. [ 0.0000, 0.0000, 0.0000, 1.9342]])
  9562. """
  9563. @overload
  9564. def diagonal(
  9565. input: Tensor,
  9566. offset: _int = 0,
  9567. dim1: _int = 0,
  9568. dim2: _int = 1,
  9569. ) -> Tensor:
  9570. r"""
  9571. diagonal(input, offset=0, dim1=0, dim2=1) -> Tensor
  9572. Returns a partial view of :attr:`input` with the its diagonal elements
  9573. with respect to :attr:`dim1` and :attr:`dim2` appended as a dimension
  9574. at the end of the shape.
  9575. The argument :attr:`offset` controls which diagonal to consider:
  9576. - If :attr:`offset` = 0, it is the main diagonal.
  9577. - If :attr:`offset` > 0, it is above the main diagonal.
  9578. - If :attr:`offset` < 0, it is below the main diagonal.
  9579. Applying :meth:`torch.diag_embed` to the output of this function with
  9580. the same arguments yields a diagonal matrix with the diagonal entries
  9581. of the input. However, :meth:`torch.diag_embed` has different default
  9582. dimensions, so those need to be explicitly specified.
  9583. Args:
  9584. input (Tensor): the input tensor. Must be at least 2-dimensional.
  9585. offset (int, optional): which diagonal to consider. Default: 0
  9586. (main diagonal).
  9587. dim1 (int, optional): first dimension with respect to which to
  9588. take diagonal. Default: 0.
  9589. dim2 (int, optional): second dimension with respect to which to
  9590. take diagonal. Default: 1.
  9591. .. note:: To take a batch diagonal, pass in dim1=-2, dim2=-1.
  9592. Examples::
  9593. >>> a = torch.randn(3, 3)
  9594. >>> a
  9595. tensor([[-1.0854, 1.1431, -0.1752],
  9596. [ 0.8536, -0.0905, 0.0360],
  9597. [ 0.6927, -0.3735, -0.4945]])
  9598. >>> torch.diagonal(a)
  9599. tensor([-1.0854, -0.0905, -0.4945])
  9600. >>> torch.diagonal(a, 1)
  9601. tensor([ 1.1431, 0.0360])
  9602. >>> b = torch.randn(2, 5)
  9603. >>> b
  9604. tensor([[-1.7948, -1.2731, -0.3181, 2.0200, -1.6745],
  9605. [ 1.8262, -1.5049, 0.4114, 1.0704, -1.2607]])
  9606. >>> torch.diagonal(b, 1, 1, 0)
  9607. tensor([1.8262])
  9608. >>> x = torch.randn(2, 5, 4, 2)
  9609. >>> torch.diagonal(x, offset=-1, dim1=1, dim2=2)
  9610. tensor([[[-1.2631, 0.3755, -1.5977, -1.8172],
  9611. [-1.1065, 1.0401, -0.2235, -0.7938]],
  9612. [[-1.7325, -0.3081, 0.6166, 0.2335],
  9613. [ 1.0500, 0.7336, -0.3836, -1.1015]]])
  9614. """
  9615. @overload
  9616. def diagonal(
  9617. input: Tensor,
  9618. *,
  9619. outdim: str | EllipsisType | None,
  9620. dim1: str | EllipsisType | None,
  9621. dim2: str | EllipsisType | None,
  9622. offset: _int = 0,
  9623. ) -> Tensor:
  9624. r"""
  9625. diagonal(input, offset=0, dim1=0, dim2=1) -> Tensor
  9626. Returns a partial view of :attr:`input` with the its diagonal elements
  9627. with respect to :attr:`dim1` and :attr:`dim2` appended as a dimension
  9628. at the end of the shape.
  9629. The argument :attr:`offset` controls which diagonal to consider:
  9630. - If :attr:`offset` = 0, it is the main diagonal.
  9631. - If :attr:`offset` > 0, it is above the main diagonal.
  9632. - If :attr:`offset` < 0, it is below the main diagonal.
  9633. Applying :meth:`torch.diag_embed` to the output of this function with
  9634. the same arguments yields a diagonal matrix with the diagonal entries
  9635. of the input. However, :meth:`torch.diag_embed` has different default
  9636. dimensions, so those need to be explicitly specified.
  9637. Args:
  9638. input (Tensor): the input tensor. Must be at least 2-dimensional.
  9639. offset (int, optional): which diagonal to consider. Default: 0
  9640. (main diagonal).
  9641. dim1 (int, optional): first dimension with respect to which to
  9642. take diagonal. Default: 0.
  9643. dim2 (int, optional): second dimension with respect to which to
  9644. take diagonal. Default: 1.
  9645. .. note:: To take a batch diagonal, pass in dim1=-2, dim2=-1.
  9646. Examples::
  9647. >>> a = torch.randn(3, 3)
  9648. >>> a
  9649. tensor([[-1.0854, 1.1431, -0.1752],
  9650. [ 0.8536, -0.0905, 0.0360],
  9651. [ 0.6927, -0.3735, -0.4945]])
  9652. >>> torch.diagonal(a)
  9653. tensor([-1.0854, -0.0905, -0.4945])
  9654. >>> torch.diagonal(a, 1)
  9655. tensor([ 1.1431, 0.0360])
  9656. >>> b = torch.randn(2, 5)
  9657. >>> b
  9658. tensor([[-1.7948, -1.2731, -0.3181, 2.0200, -1.6745],
  9659. [ 1.8262, -1.5049, 0.4114, 1.0704, -1.2607]])
  9660. >>> torch.diagonal(b, 1, 1, 0)
  9661. tensor([1.8262])
  9662. >>> x = torch.randn(2, 5, 4, 2)
  9663. >>> torch.diagonal(x, offset=-1, dim1=1, dim2=2)
  9664. tensor([[[-1.2631, 0.3755, -1.5977, -1.8172],
  9665. [-1.1065, 1.0401, -0.2235, -0.7938]],
  9666. [[-1.7325, -0.3081, 0.6166, 0.2335],
  9667. [ 1.0500, 0.7336, -0.3836, -1.1015]]])
  9668. """
  9669. def diagonal_copy(
  9670. input: Tensor,
  9671. offset: _int = 0,
  9672. dim1: _int = 0,
  9673. dim2: _int = 1,
  9674. *,
  9675. out: Tensor | None = None,
  9676. ) -> Tensor:
  9677. r"""
  9678. Performs the same operation as :func:`torch.diagonal`, but all output tensors
  9679. are freshly created instead of aliasing the input.
  9680. """
  9681. def diagonal_scatter(
  9682. input: Tensor,
  9683. src: Tensor,
  9684. offset: _int = 0,
  9685. dim1: _int = 0,
  9686. dim2: _int = 1,
  9687. ) -> Tensor:
  9688. r"""
  9689. diagonal_scatter(input, src, offset=0, dim1=0, dim2=1) -> Tensor
  9690. Embeds the values of the :attr:`src` tensor into :attr:`input` along
  9691. the diagonal elements of :attr:`input`, with respect to :attr:`dim1`
  9692. and :attr:`dim2`.
  9693. This function returns a tensor with fresh storage; it does not
  9694. return a view.
  9695. The argument :attr:`offset` controls which diagonal to consider:
  9696. - If :attr:`offset` = 0, it is the main diagonal.
  9697. - If :attr:`offset` > 0, it is above the main diagonal.
  9698. - If :attr:`offset` < 0, it is below the main diagonal.
  9699. Args:
  9700. input (Tensor): the input tensor. Must be at least 2-dimensional.
  9701. src (Tensor): the tensor to embed into :attr:`input`.
  9702. offset (int, optional): which diagonal to consider. Default: 0
  9703. (main diagonal).
  9704. dim1 (int, optional): first dimension with respect to which to
  9705. take diagonal. Default: 0.
  9706. dim2 (int, optional): second dimension with respect to which to
  9707. take diagonal. Default: 1.
  9708. .. note::
  9709. :attr:`src` must be of the proper size in order to be embedded
  9710. into :attr:`input`. Specifically, it should have the same shape as
  9711. ``torch.diagonal(input, offset, dim1, dim2)``
  9712. Examples::
  9713. >>> a = torch.zeros(3, 3)
  9714. >>> a
  9715. tensor([[0., 0., 0.],
  9716. [0., 0., 0.],
  9717. [0., 0., 0.]])
  9718. >>> torch.diagonal_scatter(a, torch.ones(3), 0)
  9719. tensor([[1., 0., 0.],
  9720. [0., 1., 0.],
  9721. [0., 0., 1.]])
  9722. >>> torch.diagonal_scatter(a, torch.ones(2), 1)
  9723. tensor([[0., 1., 0.],
  9724. [0., 0., 1.],
  9725. [0., 0., 0.]])
  9726. """
  9727. def diff(
  9728. input: Tensor,
  9729. n: _int = 1,
  9730. dim: _int = -1,
  9731. prepend: Tensor | None = None,
  9732. append: Tensor | None = None,
  9733. *,
  9734. out: Tensor | None = None,
  9735. ) -> Tensor:
  9736. r"""
  9737. diff(input, n=1, dim=-1, prepend=None, append=None) -> Tensor
  9738. Computes the n-th forward difference along the given dimension.
  9739. The first-order differences are given by `out[i] = input[i + 1] - input[i]`. Higher-order
  9740. differences are calculated by using :func:`torch.diff` recursively.
  9741. Args:
  9742. input (Tensor): the tensor to compute the differences on
  9743. n (int, optional): the number of times to recursively compute the difference
  9744. dim (int, optional): the dimension to compute the difference along.
  9745. Default is the last dimension.
  9746. prepend, append (Tensor, optional): values to prepend or append to
  9747. :attr:`input` along :attr:`dim` before computing the difference.
  9748. Their dimensions must be equivalent to that of input, and their shapes
  9749. must match input's shape except on :attr:`dim`.
  9750. Keyword args:
  9751. out (Tensor, optional): the output tensor.
  9752. Example::
  9753. >>> a = torch.tensor([1, 3, 2])
  9754. >>> torch.diff(a)
  9755. tensor([ 2, -1])
  9756. >>> b = torch.tensor([4, 5])
  9757. >>> torch.diff(a, append=b)
  9758. tensor([ 2, -1, 2, 1])
  9759. >>> c = torch.tensor([[1, 2, 3], [3, 4, 5]])
  9760. >>> torch.diff(c, dim=0)
  9761. tensor([[2, 2, 2]])
  9762. >>> torch.diff(c, dim=1)
  9763. tensor([[1, 1],
  9764. [1, 1]])
  9765. """
  9766. def digamma(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  9767. r"""
  9768. digamma(input, *, out=None) -> Tensor
  9769. Alias for :func:`torch.special.digamma`.
  9770. """
  9771. def dist(input: Tensor, other: Tensor, p: Number | _complex = 2) -> Tensor:
  9772. r"""
  9773. dist(input, other, p=2) -> Tensor
  9774. Returns the p-norm of (:attr:`input` - :attr:`other`)
  9775. The shapes of :attr:`input` and :attr:`other` must be
  9776. :ref:`broadcastable <broadcasting-semantics>`.
  9777. Args:
  9778. input (Tensor): the input tensor.
  9779. other (Tensor): the Right-hand-side input tensor
  9780. p (float, optional): the norm to be computed
  9781. Example::
  9782. >>> x = torch.randn(4)
  9783. >>> x
  9784. tensor([-1.5393, -0.8675, 0.5916, 1.6321])
  9785. >>> y = torch.randn(4)
  9786. >>> y
  9787. tensor([ 0.0967, -1.0511, 0.6295, 0.8360])
  9788. >>> torch.dist(x, y, 3.5)
  9789. tensor(1.6727)
  9790. >>> torch.dist(x, y, 3)
  9791. tensor(1.6973)
  9792. >>> torch.dist(x, y, 0)
  9793. tensor(4.)
  9794. >>> torch.dist(x, y, 1)
  9795. tensor(2.6537)
  9796. """
  9797. def div(
  9798. input: Tensor | Number,
  9799. other: Tensor | Number,
  9800. *,
  9801. rounding_mode: str | None = None,
  9802. out: Tensor | None = None,
  9803. ) -> Tensor:
  9804. r"""
  9805. div(input, other, *, rounding_mode=None, out=None) -> Tensor
  9806. Divides each element of the input ``input`` by the corresponding element of
  9807. :attr:`other`.
  9808. .. math::
  9809. \text{out}_i = \frac{\text{input}_i}{\text{other}_i}
  9810. .. note::
  9811. By default, this performs a "true" division like Python 3.
  9812. See the :attr:`rounding_mode` argument for floor division.
  9813. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  9814. :ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
  9815. Always promotes integer types to the default scalar type.
  9816. Args:
  9817. input (Tensor): the dividend
  9818. other (Tensor or Number): the divisor
  9819. Keyword args:
  9820. rounding_mode (str, optional): Type of rounding applied to the result:
  9821. * None - default behavior. Performs no rounding and, if both :attr:`input` and
  9822. :attr:`other` are integer types, promotes the inputs to the default scalar type.
  9823. Equivalent to true division in Python (the ``/`` operator) and NumPy's ``np.true_divide``.
  9824. * ``"trunc"`` - rounds the results of the division towards zero.
  9825. Equivalent to C-style integer division.
  9826. * ``"floor"`` - rounds the results of the division down.
  9827. Equivalent to floor division in Python (the ``//`` operator) and NumPy's ``np.floor_divide``.
  9828. out (Tensor, optional): the output tensor.
  9829. Examples::
  9830. >>> x = torch.tensor([ 0.3810, 1.2774, -0.2972, -0.3719, 0.4637])
  9831. >>> torch.div(x, 0.5)
  9832. tensor([ 0.7620, 2.5548, -0.5944, -0.7438, 0.9274])
  9833. >>> a = torch.tensor([[-0.3711, -1.9353, -0.4605, -0.2917],
  9834. ... [ 0.1815, -1.0111, 0.9805, -1.5923],
  9835. ... [ 0.1062, 1.4581, 0.7759, -1.2344],
  9836. ... [-0.1830, -0.0313, 1.1908, -1.4757]])
  9837. >>> b = torch.tensor([ 0.8032, 0.2930, -0.8113, -0.2308])
  9838. >>> torch.div(a, b)
  9839. tensor([[-0.4620, -6.6051, 0.5676, 1.2639],
  9840. [ 0.2260, -3.4509, -1.2086, 6.8990],
  9841. [ 0.1322, 4.9764, -0.9564, 5.3484],
  9842. [-0.2278, -0.1068, -1.4678, 6.3938]])
  9843. >>> torch.div(a, b, rounding_mode='trunc')
  9844. tensor([[-0., -6., 0., 1.],
  9845. [ 0., -3., -1., 6.],
  9846. [ 0., 4., -0., 5.],
  9847. [-0., -0., -1., 6.]])
  9848. >>> torch.div(a, b, rounding_mode='floor')
  9849. tensor([[-1., -7., 0., 1.],
  9850. [ 0., -4., -2., 6.],
  9851. [ 0., 4., -1., 5.],
  9852. [-1., -1., -2., 6.]])
  9853. """
  9854. @overload
  9855. def divide(
  9856. input: Tensor,
  9857. other: Tensor,
  9858. *,
  9859. out: Tensor | None = None,
  9860. ) -> Tensor:
  9861. r"""
  9862. divide(input, other, *, rounding_mode=None, out=None) -> Tensor
  9863. Alias for :func:`torch.div`.
  9864. """
  9865. @overload
  9866. def divide(
  9867. input: Tensor,
  9868. other: Tensor,
  9869. *,
  9870. rounding_mode: str | None,
  9871. out: Tensor | None = None,
  9872. ) -> Tensor:
  9873. r"""
  9874. divide(input, other, *, rounding_mode=None, out=None) -> Tensor
  9875. Alias for :func:`torch.div`.
  9876. """
  9877. @overload
  9878. def divide(
  9879. input: Tensor,
  9880. other: Number | _complex,
  9881. *,
  9882. rounding_mode: str | None,
  9883. ) -> Tensor:
  9884. r"""
  9885. divide(input, other, *, rounding_mode=None, out=None) -> Tensor
  9886. Alias for :func:`torch.div`.
  9887. """
  9888. @overload
  9889. def divide(input: Tensor, other: Number | _complex) -> Tensor:
  9890. r"""
  9891. divide(input, other, *, rounding_mode=None, out=None) -> Tensor
  9892. Alias for :func:`torch.div`.
  9893. """
  9894. def dot(
  9895. input: Tensor,
  9896. tensor: Tensor,
  9897. *,
  9898. out: Tensor | None = None,
  9899. ) -> Tensor:
  9900. r"""
  9901. dot(input, tensor, *, out=None) -> Tensor
  9902. Computes the dot product of two 1D tensors.
  9903. .. note::
  9904. Unlike NumPy's dot, torch.dot intentionally only supports computing the dot product
  9905. of two 1D tensors with the same number of elements.
  9906. Args:
  9907. input (Tensor): first tensor in the dot product, must be 1D.
  9908. tensor (Tensor): second tensor in the dot product, must be 1D.
  9909. Keyword args:
  9910. out (Tensor, optional): the output tensor.
  9911. Example::
  9912. >>> torch.dot(torch.tensor([2, 3]), torch.tensor([2, 1]))
  9913. tensor(7)
  9914. >>> t1, t2 = torch.tensor([0, 1]), torch.tensor([2, 3])
  9915. >>> torch.dot(t1, t2)
  9916. tensor(3)
  9917. """
  9918. def dropout(input: Tensor, p: _float, train: _bool) -> Tensor: ...
  9919. def dropout_(input: Tensor, p: _float, train: _bool) -> Tensor: ...
  9920. def dsmm(input: Tensor, mat2: Tensor) -> Tensor: ...
  9921. @overload
  9922. def dsplit(input: Tensor, sections: _int) -> tuple[Tensor, ...]:
  9923. r"""
  9924. dsplit(input, indices_or_sections) -> List of Tensors
  9925. Splits :attr:`input`, a tensor with three or more dimensions, into multiple tensors
  9926. depthwise according to :attr:`indices_or_sections`. Each split is a view of
  9927. :attr:`input`.
  9928. This is equivalent to calling torch.tensor_split(input, indices_or_sections, dim=2)
  9929. (the split dimension is 2), except that if :attr:`indices_or_sections` is an integer
  9930. it must evenly divide the split dimension or a runtime error will be thrown.
  9931. This function is based on NumPy's :func:`numpy.dsplit`.
  9932. Args:
  9933. input (Tensor): tensor to split.
  9934. indices_or_sections (int or list or tuple of ints): See argument in :func:`torch.tensor_split`.
  9935. Example::
  9936. >>> t = torch.arange(16.0).reshape(2, 2, 4)
  9937. >>> t
  9938. tensor([[[ 0., 1., 2., 3.],
  9939. [ 4., 5., 6., 7.]],
  9940. [[ 8., 9., 10., 11.],
  9941. [12., 13., 14., 15.]]])
  9942. >>> torch.dsplit(t, 2)
  9943. (tensor([[[ 0., 1.],
  9944. [ 4., 5.]],
  9945. [[ 8., 9.],
  9946. [12., 13.]]]),
  9947. tensor([[[ 2., 3.],
  9948. [ 6., 7.]],
  9949. [[10., 11.],
  9950. [14., 15.]]]))
  9951. >>> torch.dsplit(t, [3, 6])
  9952. (tensor([[[ 0., 1., 2.],
  9953. [ 4., 5., 6.]],
  9954. [[ 8., 9., 10.],
  9955. [12., 13., 14.]]]),
  9956. tensor([[[ 3.],
  9957. [ 7.]],
  9958. [[11.],
  9959. [15.]]]),
  9960. tensor([], size=(2, 2, 0)))
  9961. """
  9962. @overload
  9963. def dsplit(input: Tensor, indices: _size) -> tuple[Tensor, ...]:
  9964. r"""
  9965. dsplit(input, indices_or_sections) -> List of Tensors
  9966. Splits :attr:`input`, a tensor with three or more dimensions, into multiple tensors
  9967. depthwise according to :attr:`indices_or_sections`. Each split is a view of
  9968. :attr:`input`.
  9969. This is equivalent to calling torch.tensor_split(input, indices_or_sections, dim=2)
  9970. (the split dimension is 2), except that if :attr:`indices_or_sections` is an integer
  9971. it must evenly divide the split dimension or a runtime error will be thrown.
  9972. This function is based on NumPy's :func:`numpy.dsplit`.
  9973. Args:
  9974. input (Tensor): tensor to split.
  9975. indices_or_sections (int or list or tuple of ints): See argument in :func:`torch.tensor_split`.
  9976. Example::
  9977. >>> t = torch.arange(16.0).reshape(2, 2, 4)
  9978. >>> t
  9979. tensor([[[ 0., 1., 2., 3.],
  9980. [ 4., 5., 6., 7.]],
  9981. [[ 8., 9., 10., 11.],
  9982. [12., 13., 14., 15.]]])
  9983. >>> torch.dsplit(t, 2)
  9984. (tensor([[[ 0., 1.],
  9985. [ 4., 5.]],
  9986. [[ 8., 9.],
  9987. [12., 13.]]]),
  9988. tensor([[[ 2., 3.],
  9989. [ 6., 7.]],
  9990. [[10., 11.],
  9991. [14., 15.]]]))
  9992. >>> torch.dsplit(t, [3, 6])
  9993. (tensor([[[ 0., 1., 2.],
  9994. [ 4., 5., 6.]],
  9995. [[ 8., 9., 10.],
  9996. [12., 13., 14.]]]),
  9997. tensor([[[ 3.],
  9998. [ 7.]],
  9999. [[11.],
  10000. [15.]]]),
  10001. tensor([], size=(2, 2, 0)))
  10002. """
  10003. def dstack(
  10004. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  10005. *,
  10006. out: Tensor | None = None,
  10007. ) -> Tensor:
  10008. r"""
  10009. dstack(tensors, *, out=None) -> Tensor
  10010. Stack tensors in sequence depthwise (along third axis).
  10011. This is equivalent to concatenation along the third axis after 1-D and 2-D tensors have been reshaped by :func:`torch.atleast_3d`.
  10012. Args:
  10013. tensors (sequence of Tensors): sequence of tensors to concatenate
  10014. Keyword args:
  10015. out (Tensor, optional): the output tensor.
  10016. Example::
  10017. >>> a = torch.tensor([1, 2, 3])
  10018. >>> b = torch.tensor([4, 5, 6])
  10019. >>> torch.dstack((a,b))
  10020. tensor([[[1, 4],
  10021. [2, 5],
  10022. [3, 6]]])
  10023. >>> a = torch.tensor([[1],[2],[3]])
  10024. >>> b = torch.tensor([[4],[5],[6]])
  10025. >>> torch.dstack((a,b))
  10026. tensor([[[1, 4]],
  10027. [[2, 5]],
  10028. [[3, 6]]])
  10029. """
  10030. def embedding(
  10031. weight: Tensor,
  10032. indices: Tensor,
  10033. padding_idx: _int | SymInt = -1,
  10034. scale_grad_by_freq: _bool = False,
  10035. sparse: _bool = False,
  10036. ) -> Tensor: ...
  10037. @overload
  10038. def embedding_bag(
  10039. weight: Tensor,
  10040. indices: Tensor,
  10041. offsets: Tensor,
  10042. scale_grad_by_freq: _bool,
  10043. mode: _int,
  10044. sparse: _bool,
  10045. per_sample_weights: Tensor | None,
  10046. include_last_offset: _bool,
  10047. padding_idx: _int | None,
  10048. ) -> tuple[Tensor, Tensor, Tensor, Tensor]: ...
  10049. @overload
  10050. def embedding_bag(
  10051. weight: Tensor,
  10052. indices: Tensor,
  10053. offsets: Tensor,
  10054. scale_grad_by_freq: _bool = False,
  10055. mode: _int = 0,
  10056. sparse: _bool = False,
  10057. per_sample_weights: Tensor | None = None,
  10058. include_last_offset: _bool = False,
  10059. ) -> tuple[Tensor, Tensor, Tensor, Tensor]: ...
  10060. def embedding_renorm_(
  10061. input: Tensor,
  10062. indices: Tensor,
  10063. max_norm: _float,
  10064. norm_type: _float,
  10065. ) -> Tensor: ...
  10066. @overload
  10067. def empty(
  10068. size: Sequence[_int | SymInt],
  10069. *,
  10070. memory_format: memory_format | None = None,
  10071. out: Tensor | None = None,
  10072. dtype: _dtype | None = None,
  10073. layout: _layout | None = None,
  10074. device: DeviceLikeType | None = None,
  10075. pin_memory: _bool | None = False,
  10076. requires_grad: _bool | None = False,
  10077. ) -> Tensor:
  10078. r"""
  10079. empty(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False, memory_format=torch.contiguous_format) -> Tensor
  10080. Returns a tensor filled with uninitialized data. The shape of the tensor is
  10081. defined by the variable argument :attr:`size`.
  10082. .. note::
  10083. If :func:`torch.use_deterministic_algorithms()` and
  10084. :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
  10085. ``True``, the output tensor is initialized to prevent any possible
  10086. nondeterministic behavior from using the data as an input to an operation.
  10087. Floating point and complex tensors are filled with NaN, and integer tensors
  10088. are filled with the maximum value.
  10089. Args:
  10090. size (int...): a sequence of integers defining the shape of the output tensor.
  10091. Can be a variable number of arguments or a collection like a list or tuple.
  10092. Keyword args:
  10093. out (Tensor, optional): the output tensor.
  10094. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  10095. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  10096. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  10097. Default: ``torch.strided``.
  10098. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10099. Default: if ``None``, uses the current device for the default tensor type
  10100. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  10101. for CPU tensor types and the current CUDA device for CUDA tensor types.
  10102. requires_grad (bool, optional): If autograd should record operations on the
  10103. returned tensor. Default: ``False``.
  10104. pin_memory (bool, optional): If set, returned tensor would be allocated in
  10105. the pinned memory. Works only for CPU tensors. Default: ``False``.
  10106. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  10107. returned Tensor. Default: ``torch.contiguous_format``.
  10108. Example::
  10109. >>> torch.empty((2,3), dtype=torch.int64)
  10110. tensor([[ 9.4064e+13, 2.8000e+01, 9.3493e+13],
  10111. [ 7.5751e+18, 7.1428e+18, 7.5955e+18]])
  10112. """
  10113. @overload
  10114. def empty(
  10115. *size: _int | SymInt,
  10116. memory_format: memory_format | None = None,
  10117. out: Tensor | None = None,
  10118. dtype: _dtype | None = None,
  10119. layout: _layout | None = None,
  10120. device: DeviceLikeType | None = None,
  10121. pin_memory: _bool | None = False,
  10122. requires_grad: _bool | None = False,
  10123. ) -> Tensor:
  10124. r"""
  10125. empty(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False, memory_format=torch.contiguous_format) -> Tensor
  10126. Returns a tensor filled with uninitialized data. The shape of the tensor is
  10127. defined by the variable argument :attr:`size`.
  10128. .. note::
  10129. If :func:`torch.use_deterministic_algorithms()` and
  10130. :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
  10131. ``True``, the output tensor is initialized to prevent any possible
  10132. nondeterministic behavior from using the data as an input to an operation.
  10133. Floating point and complex tensors are filled with NaN, and integer tensors
  10134. are filled with the maximum value.
  10135. Args:
  10136. size (int...): a sequence of integers defining the shape of the output tensor.
  10137. Can be a variable number of arguments or a collection like a list or tuple.
  10138. Keyword args:
  10139. out (Tensor, optional): the output tensor.
  10140. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  10141. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  10142. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  10143. Default: ``torch.strided``.
  10144. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10145. Default: if ``None``, uses the current device for the default tensor type
  10146. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  10147. for CPU tensor types and the current CUDA device for CUDA tensor types.
  10148. requires_grad (bool, optional): If autograd should record operations on the
  10149. returned tensor. Default: ``False``.
  10150. pin_memory (bool, optional): If set, returned tensor would be allocated in
  10151. the pinned memory. Works only for CPU tensors. Default: ``False``.
  10152. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  10153. returned Tensor. Default: ``torch.contiguous_format``.
  10154. Example::
  10155. >>> torch.empty((2,3), dtype=torch.int64)
  10156. tensor([[ 9.4064e+13, 2.8000e+01, 9.3493e+13],
  10157. [ 7.5751e+18, 7.1428e+18, 7.5955e+18]])
  10158. """
  10159. @overload
  10160. def empty(
  10161. size: _size,
  10162. *,
  10163. names: Sequence[str | EllipsisType | None] | None,
  10164. memory_format: memory_format | None = None,
  10165. dtype: _dtype | None = None,
  10166. layout: _layout | None = None,
  10167. device: DeviceLikeType | None = None,
  10168. pin_memory: _bool | None = False,
  10169. requires_grad: _bool | None = False,
  10170. ) -> Tensor:
  10171. r"""
  10172. empty(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False, memory_format=torch.contiguous_format) -> Tensor
  10173. Returns a tensor filled with uninitialized data. The shape of the tensor is
  10174. defined by the variable argument :attr:`size`.
  10175. .. note::
  10176. If :func:`torch.use_deterministic_algorithms()` and
  10177. :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
  10178. ``True``, the output tensor is initialized to prevent any possible
  10179. nondeterministic behavior from using the data as an input to an operation.
  10180. Floating point and complex tensors are filled with NaN, and integer tensors
  10181. are filled with the maximum value.
  10182. Args:
  10183. size (int...): a sequence of integers defining the shape of the output tensor.
  10184. Can be a variable number of arguments or a collection like a list or tuple.
  10185. Keyword args:
  10186. out (Tensor, optional): the output tensor.
  10187. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  10188. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  10189. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  10190. Default: ``torch.strided``.
  10191. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10192. Default: if ``None``, uses the current device for the default tensor type
  10193. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  10194. for CPU tensor types and the current CUDA device for CUDA tensor types.
  10195. requires_grad (bool, optional): If autograd should record operations on the
  10196. returned tensor. Default: ``False``.
  10197. pin_memory (bool, optional): If set, returned tensor would be allocated in
  10198. the pinned memory. Works only for CPU tensors. Default: ``False``.
  10199. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  10200. returned Tensor. Default: ``torch.contiguous_format``.
  10201. Example::
  10202. >>> torch.empty((2,3), dtype=torch.int64)
  10203. tensor([[ 9.4064e+13, 2.8000e+01, 9.3493e+13],
  10204. [ 7.5751e+18, 7.1428e+18, 7.5955e+18]])
  10205. """
  10206. @overload
  10207. def empty(
  10208. *size: _int,
  10209. names: Sequence[str | EllipsisType | None] | None,
  10210. memory_format: memory_format | None = None,
  10211. dtype: _dtype | None = None,
  10212. layout: _layout | None = None,
  10213. device: DeviceLikeType | None = None,
  10214. pin_memory: _bool | None = False,
  10215. requires_grad: _bool | None = False,
  10216. ) -> Tensor:
  10217. r"""
  10218. empty(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False, memory_format=torch.contiguous_format) -> Tensor
  10219. Returns a tensor filled with uninitialized data. The shape of the tensor is
  10220. defined by the variable argument :attr:`size`.
  10221. .. note::
  10222. If :func:`torch.use_deterministic_algorithms()` and
  10223. :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
  10224. ``True``, the output tensor is initialized to prevent any possible
  10225. nondeterministic behavior from using the data as an input to an operation.
  10226. Floating point and complex tensors are filled with NaN, and integer tensors
  10227. are filled with the maximum value.
  10228. Args:
  10229. size (int...): a sequence of integers defining the shape of the output tensor.
  10230. Can be a variable number of arguments or a collection like a list or tuple.
  10231. Keyword args:
  10232. out (Tensor, optional): the output tensor.
  10233. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  10234. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  10235. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  10236. Default: ``torch.strided``.
  10237. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10238. Default: if ``None``, uses the current device for the default tensor type
  10239. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  10240. for CPU tensor types and the current CUDA device for CUDA tensor types.
  10241. requires_grad (bool, optional): If autograd should record operations on the
  10242. returned tensor. Default: ``False``.
  10243. pin_memory (bool, optional): If set, returned tensor would be allocated in
  10244. the pinned memory. Works only for CPU tensors. Default: ``False``.
  10245. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  10246. returned Tensor. Default: ``torch.contiguous_format``.
  10247. Example::
  10248. >>> torch.empty((2,3), dtype=torch.int64)
  10249. tensor([[ 9.4064e+13, 2.8000e+01, 9.3493e+13],
  10250. [ 7.5751e+18, 7.1428e+18, 7.5955e+18]])
  10251. """
  10252. def empty_like(
  10253. input: Tensor,
  10254. *,
  10255. memory_format: memory_format | None = None,
  10256. dtype: _dtype | None = None,
  10257. layout: _layout | None = None,
  10258. device: DeviceLikeType | None = None,
  10259. pin_memory: _bool | None = False,
  10260. requires_grad: _bool | None = False,
  10261. ) -> Tensor:
  10262. r"""
  10263. empty_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  10264. Returns an uninitialized tensor with the same size as :attr:`input`.
  10265. ``torch.empty_like(input)`` is equivalent to
  10266. ``torch.empty(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
  10267. .. note::
  10268. If :func:`torch.use_deterministic_algorithms()` and
  10269. :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
  10270. ``True``, the output tensor is initialized to prevent any possible
  10271. nondeterministic behavior from using the data as an input to an operation.
  10272. Floating point and complex tensors are filled with NaN, and integer tensors
  10273. are filled with the maximum value.
  10274. When ``torch.preserve_format`` is used:
  10275. If the input tensor is dense (i.e., non-overlapping strided),
  10276. its memory format (including strides) is retained.
  10277. Otherwise (e.g., a non-dense view like a stepped slice),
  10278. the output is converted to the dense format.
  10279. Args:
  10280. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  10281. Keyword args:
  10282. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  10283. Default: if ``None``, defaults to the dtype of :attr:`input`.
  10284. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  10285. Default: if ``None``, defaults to the layout of :attr:`input`.
  10286. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10287. Default: if ``None``, defaults to the device of :attr:`input`.
  10288. requires_grad (bool, optional): If autograd should record operations on the
  10289. returned tensor. Default: ``False``.
  10290. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  10291. returned Tensor. Default: ``torch.preserve_format``.
  10292. Example::
  10293. >>> a=torch.empty((2,3), dtype=torch.int32, device = 'cuda')
  10294. >>> torch.empty_like(a)
  10295. tensor([[0, 0, 0],
  10296. [0, 0, 0]], device='cuda:0', dtype=torch.int32)
  10297. """
  10298. def empty_permuted(
  10299. size: Sequence[_int | SymInt],
  10300. physical_layout: _size,
  10301. *,
  10302. dtype: _dtype | None = None,
  10303. layout: _layout | None = None,
  10304. device: DeviceLikeType | None = None,
  10305. pin_memory: _bool | None = False,
  10306. requires_grad: _bool | None = False,
  10307. ) -> Tensor:
  10308. r"""
  10309. empty_permuted(size, physical_layout, *, dtype=None, layout=None, device=None, requires_grad=False, pin_memory=False) -> Tensor
  10310. Creates an uninitialized, non-overlapping and dense tensor with the
  10311. specified :attr:`size`, with :attr:`physical_layout` specifying how the
  10312. dimensions are physically laid out in memory (each logical dimension is listed
  10313. from outermost to innermost). :attr:`physical_layout` is a generalization
  10314. of NCHW/NHWC notation: if each dimension is assigned a number according to
  10315. what order they occur in size (N=0, C=1, H=2, W=3), then NCHW is ``(0, 1, 2, 3)``
  10316. while NHWC is ``(0, 2, 3, 1)``. Equivalently, the strides of the output
  10317. tensor ``t`` are such that ``t.stride(physical_layout[i]) == contiguous_strides[i]``
  10318. (notably, this function is *not* equivalent to ``torch.empty(size).permute(physical_layout)``).
  10319. Unlike :func:`torch.empty_strided`, this is guaranteed to produce a dense
  10320. tensor with no overlaps. If possible, prefer using this function over
  10321. :func:`torch.empty_strided` or manual use of :func:`torch.as_strided`.
  10322. .. note::
  10323. If :func:`torch.use_deterministic_algorithms()` and
  10324. :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
  10325. ``True``, the output tensor is initialized to prevent any possible
  10326. nondeterministic behavior from using the data as an input to an operation.
  10327. Floating point and complex tensors are filled with NaN, and integer tensors
  10328. are filled with the maximum value.
  10329. Args:
  10330. size (tuple of int): the shape of the output tensor
  10331. physical_layout (tuple of int): the ordering of dimensions physically in memory
  10332. Keyword args:
  10333. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  10334. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  10335. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  10336. Default: ``torch.strided``.
  10337. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10338. Default: if ``None``, uses the current device for the default tensor type
  10339. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  10340. for CPU tensor types and the current CUDA device for CUDA tensor types.
  10341. requires_grad (bool, optional): If autograd should record operations on the
  10342. returned tensor. Default: ``False``.
  10343. pin_memory (bool, optional): If set, returned tensor would be allocated in
  10344. the pinned memory. Works only for CPU tensors. Default: ``False``.
  10345. Examples:
  10346. >>> torch.empty((2, 3, 5, 7)).stride()
  10347. (105, 35, 7, 1)
  10348. >>> torch.empty_permuted((2, 3, 5, 7), (0, 1, 2, 3)).stride()
  10349. (105, 35, 7, 1)
  10350. >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).stride()
  10351. (105, 1, 21, 3)
  10352. >>> torch.empty_permuted((2, 3, 5, 7), (0, 2, 3, 1)).stride()
  10353. (105, 1, 21, 3)
  10354. >>> torch.empty_permuted((2, 3, 5, 7), (0, 2, 3, 1)).dim_order()
  10355. (0, 2, 3, 1)
  10356. """
  10357. def empty_quantized(
  10358. size: _size,
  10359. qtensor: Tensor,
  10360. *,
  10361. memory_format: memory_format | None = None,
  10362. dtype: _dtype | None = None,
  10363. layout: _layout | None = None,
  10364. device: DeviceLikeType | None = None,
  10365. pin_memory: _bool | None = False,
  10366. requires_grad: _bool | None = False,
  10367. ) -> Tensor: ...
  10368. def empty_strided(
  10369. size: Sequence[_int | SymInt],
  10370. stride: Sequence[_int | SymInt],
  10371. *,
  10372. dtype: _dtype | None = None,
  10373. layout: _layout | None = None,
  10374. device: DeviceLikeType | None = None,
  10375. pin_memory: _bool | None = False,
  10376. requires_grad: _bool | None = False,
  10377. ) -> Tensor:
  10378. r"""
  10379. empty_strided(size, stride, *, dtype=None, layout=None, device=None, requires_grad=False, pin_memory=False) -> Tensor
  10380. Creates a tensor with the specified :attr:`size` and :attr:`stride` and filled with undefined data.
  10381. .. warning::
  10382. If the constructed tensor is "overlapped" (with multiple indices referring to the same element
  10383. in memory) its behavior is undefined.
  10384. .. note::
  10385. If :func:`torch.use_deterministic_algorithms()` and
  10386. :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
  10387. ``True``, the output tensor is initialized to prevent any possible
  10388. nondeterministic behavior from using the data as an input to an operation.
  10389. Floating point and complex tensors are filled with NaN, and integer tensors
  10390. are filled with the maximum value.
  10391. Args:
  10392. size (tuple of int): the shape of the output tensor
  10393. stride (tuple of int): the strides of the output tensor
  10394. Keyword args:
  10395. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  10396. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  10397. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  10398. Default: ``torch.strided``.
  10399. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10400. Default: if ``None``, uses the current device for the default tensor type
  10401. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  10402. for CPU tensor types and the current CUDA device for CUDA tensor types.
  10403. requires_grad (bool, optional): If autograd should record operations on the
  10404. returned tensor. Default: ``False``.
  10405. pin_memory (bool, optional): If set, returned tensor would be allocated in
  10406. the pinned memory. Works only for CPU tensors. Default: ``False``.
  10407. Example::
  10408. >>> a = torch.empty_strided((2, 3), (1, 2))
  10409. >>> a
  10410. tensor([[8.9683e-44, 4.4842e-44, 5.1239e+07],
  10411. [0.0000e+00, 0.0000e+00, 3.0705e-41]])
  10412. >>> a.stride()
  10413. (1, 2)
  10414. >>> a.size()
  10415. torch.Size([2, 3])
  10416. """
  10417. @overload
  10418. def eq(
  10419. input: Tensor,
  10420. other: Tensor,
  10421. *,
  10422. out: Tensor | None = None,
  10423. ) -> Tensor:
  10424. r"""
  10425. eq(input, other, *, out=None) -> Tensor
  10426. Computes element-wise equality
  10427. The second argument can be a number or a tensor whose shape is
  10428. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  10429. Args:
  10430. input (Tensor): the tensor to compare
  10431. other (Tensor or float): the tensor or value to compare
  10432. Keyword args:
  10433. out (Tensor, optional): the output tensor.
  10434. Returns:
  10435. A boolean tensor that is True where :attr:`input` is equal to :attr:`other` and False elsewhere
  10436. Example::
  10437. >>> torch.eq(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  10438. tensor([[ True, False],
  10439. [False, True]])
  10440. """
  10441. @overload
  10442. def eq(
  10443. input: Tensor,
  10444. other: Number | _complex,
  10445. *,
  10446. out: Tensor | None = None,
  10447. ) -> Tensor:
  10448. r"""
  10449. eq(input, other, *, out=None) -> Tensor
  10450. Computes element-wise equality
  10451. The second argument can be a number or a tensor whose shape is
  10452. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  10453. Args:
  10454. input (Tensor): the tensor to compare
  10455. other (Tensor or float): the tensor or value to compare
  10456. Keyword args:
  10457. out (Tensor, optional): the output tensor.
  10458. Returns:
  10459. A boolean tensor that is True where :attr:`input` is equal to :attr:`other` and False elsewhere
  10460. Example::
  10461. >>> torch.eq(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  10462. tensor([[ True, False],
  10463. [False, True]])
  10464. """
  10465. def equal(input: Tensor, other: Tensor) -> _bool:
  10466. r"""
  10467. equal(input, other) -> bool
  10468. ``True`` if two tensors have the same size and elements, ``False`` otherwise.
  10469. .. note::
  10470. Tensors containing NaNs are never equal to each other. Additionally, this function does not
  10471. differentiate between the data types of the tensors during comparison. For more thorough tensor checks,
  10472. use :meth:`torch.testing.assert_close`.
  10473. Example::
  10474. >>> torch.equal(torch.tensor([1, 2]), torch.tensor([1, 2]))
  10475. True
  10476. >>> torch.equal(torch.tensor([3, torch.nan]), torch.tensor([3, torch.nan]))
  10477. False
  10478. >>> torch.equal(torch.tensor([1, 2, 3], dtype=torch.int32), torch.tensor([1, 2, 3], dtype=torch.float32))
  10479. True
  10480. """
  10481. def erf(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  10482. r"""
  10483. erf(input, *, out=None) -> Tensor
  10484. Alias for :func:`torch.special.erf`.
  10485. """
  10486. def erf_(input: Tensor) -> Tensor: ...
  10487. def erfc(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  10488. r"""
  10489. erfc(input, *, out=None) -> Tensor
  10490. Alias for :func:`torch.special.erfc`.
  10491. """
  10492. def erfc_(input: Tensor) -> Tensor: ...
  10493. def erfinv(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  10494. r"""
  10495. erfinv(input, *, out=None) -> Tensor
  10496. Alias for :func:`torch.special.erfinv`.
  10497. """
  10498. def exp(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  10499. r"""
  10500. exp(input, *, out=None) -> Tensor
  10501. Returns a new tensor with the exponential of the elements
  10502. of the input tensor :attr:`input`.
  10503. .. math::
  10504. y_{i} = e^{x_{i}}
  10505. Args:
  10506. input (Tensor): the input tensor.
  10507. Keyword args:
  10508. out (Tensor, optional): the output tensor.
  10509. Example::
  10510. >>> torch.exp(torch.tensor([0, math.log(2.)]))
  10511. tensor([ 1., 2.])
  10512. """
  10513. def exp2(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  10514. r"""
  10515. exp2(input, *, out=None) -> Tensor
  10516. Alias for :func:`torch.special.exp2`.
  10517. """
  10518. def exp2_(input: Tensor) -> Tensor: ...
  10519. def exp_(input: Tensor) -> Tensor: ...
  10520. def expand_copy(
  10521. input: Tensor,
  10522. size: Sequence[_int | SymInt],
  10523. *,
  10524. implicit: _bool = False,
  10525. out: Tensor | None = None,
  10526. ) -> Tensor:
  10527. r"""
  10528. Performs the same operation as :func:`torch.Tensor.expand`, but all output tensors
  10529. are freshly created instead of aliasing the input.
  10530. """
  10531. def expm1(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  10532. r"""
  10533. expm1(input, *, out=None) -> Tensor
  10534. Alias for :func:`torch.special.expm1`.
  10535. """
  10536. def expm1_(input: Tensor) -> Tensor: ...
  10537. @overload
  10538. def eye(
  10539. n: _int | SymInt,
  10540. *,
  10541. out: Tensor | None = None,
  10542. dtype: _dtype | None = None,
  10543. layout: _layout | None = None,
  10544. device: DeviceLikeType | None = None,
  10545. pin_memory: _bool | None = False,
  10546. requires_grad: _bool | None = False,
  10547. ) -> Tensor:
  10548. r"""
  10549. eye(n, m=None, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  10550. Returns a 2-D tensor with ones on the diagonal and zeros elsewhere.
  10551. Args:
  10552. n (int): the number of rows
  10553. m (int, optional): the number of columns with default being :attr:`n`
  10554. Keyword arguments:
  10555. out (Tensor, optional): the output tensor.
  10556. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  10557. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  10558. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  10559. Default: ``torch.strided``.
  10560. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10561. Default: if ``None``, uses the current device for the default tensor type
  10562. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  10563. for CPU tensor types and the current CUDA device for CUDA tensor types.
  10564. requires_grad (bool, optional): If autograd should record operations on the
  10565. returned tensor. Default: ``False``.
  10566. Returns:
  10567. Tensor: A 2-D tensor with ones on the diagonal and zeros elsewhere
  10568. Example::
  10569. >>> torch.eye(3)
  10570. tensor([[ 1., 0., 0.],
  10571. [ 0., 1., 0.],
  10572. [ 0., 0., 1.]])
  10573. """
  10574. @overload
  10575. def eye(
  10576. n: _int | SymInt,
  10577. m: _int | SymInt,
  10578. *,
  10579. out: Tensor | None = None,
  10580. dtype: _dtype | None = None,
  10581. layout: _layout | None = None,
  10582. device: DeviceLikeType | None = None,
  10583. pin_memory: _bool | None = False,
  10584. requires_grad: _bool | None = False,
  10585. ) -> Tensor:
  10586. r"""
  10587. eye(n, m=None, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  10588. Returns a 2-D tensor with ones on the diagonal and zeros elsewhere.
  10589. Args:
  10590. n (int): the number of rows
  10591. m (int, optional): the number of columns with default being :attr:`n`
  10592. Keyword arguments:
  10593. out (Tensor, optional): the output tensor.
  10594. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  10595. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  10596. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  10597. Default: ``torch.strided``.
  10598. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10599. Default: if ``None``, uses the current device for the default tensor type
  10600. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  10601. for CPU tensor types and the current CUDA device for CUDA tensor types.
  10602. requires_grad (bool, optional): If autograd should record operations on the
  10603. returned tensor. Default: ``False``.
  10604. Returns:
  10605. Tensor: A 2-D tensor with ones on the diagonal and zeros elsewhere
  10606. Example::
  10607. >>> torch.eye(3)
  10608. tensor([[ 1., 0., 0.],
  10609. [ 0., 1., 0.],
  10610. [ 0., 0., 1.]])
  10611. """
  10612. def fake_quantize_per_channel_affine(
  10613. input: Tensor,
  10614. scale: Tensor,
  10615. zero_point: Tensor,
  10616. axis: _int,
  10617. quant_min: _int,
  10618. quant_max: _int,
  10619. ) -> Tensor:
  10620. r"""
  10621. fake_quantize_per_channel_affine(input, scale, zero_point, axis, quant_min, quant_max) -> Tensor
  10622. Returns a new tensor with the data in :attr:`input` fake quantized per channel using :attr:`scale`,
  10623. :attr:`zero_point`, :attr:`quant_min` and :attr:`quant_max`, across the channel specified by :attr:`axis`.
  10624. .. math::
  10625. \text{output} = (
  10626. min(
  10627. \text{quant\_max},
  10628. max(
  10629. \text{quant\_min},
  10630. \text{std::nearby\_int}(\text{input} / \text{scale}) + \text{zero\_point}
  10631. )
  10632. ) - \text{zero\_point}
  10633. ) \times \text{scale}
  10634. Args:
  10635. input (Tensor): the input value(s), in ``torch.float32``
  10636. scale (Tensor): quantization scale, per channel in ``torch.float32``
  10637. zero_point (Tensor): quantization zero_point, per channel in ``torch.int32`` or ``torch.half`` or ``torch.float32``
  10638. axis (int32): channel axis
  10639. quant_min (int64): lower bound of the quantized domain
  10640. quant_max (int64): upper bound of the quantized domain
  10641. Returns:
  10642. Tensor: A newly fake_quantized per channel ``torch.float32`` tensor
  10643. Example::
  10644. >>> x = torch.randn(2, 2, 2)
  10645. >>> x
  10646. tensor([[[-0.2525, -0.0466],
  10647. [ 0.3491, -0.2168]],
  10648. [[-0.5906, 1.6258],
  10649. [ 0.6444, -0.0542]]])
  10650. >>> scales = (torch.randn(2) + 1) * 0.05
  10651. >>> scales
  10652. tensor([0.0475, 0.0486])
  10653. >>> zero_points = torch.zeros(2).to(torch.int32)
  10654. >>> zero_points
  10655. tensor([0, 0])
  10656. >>> torch.fake_quantize_per_channel_affine(x, scales, zero_points, 1, 0, 255)
  10657. tensor([[[0.0000, 0.0000],
  10658. [0.3405, 0.0000]],
  10659. [[0.0000, 1.6134],
  10660. [0.6323, 0.0000]]])
  10661. """
  10662. @overload
  10663. def fake_quantize_per_tensor_affine(
  10664. input: Tensor,
  10665. scale: _float,
  10666. zero_point: _int,
  10667. quant_min: _int,
  10668. quant_max: _int,
  10669. ) -> Tensor:
  10670. r"""
  10671. fake_quantize_per_tensor_affine(input, scale, zero_point, quant_min, quant_max) -> Tensor
  10672. Returns a new tensor with the data in :attr:`input` fake quantized using :attr:`scale`,
  10673. :attr:`zero_point`, :attr:`quant_min` and :attr:`quant_max`.
  10674. .. math::
  10675. \text{output} = (
  10676. min(
  10677. \text{quant\_max},
  10678. max(
  10679. \text{quant\_min},
  10680. \text{std::nearby\_int}(\text{input} / \text{scale}) + \text{zero\_point}
  10681. )
  10682. ) - \text{zero\_point}
  10683. ) \times \text{scale}
  10684. Args:
  10685. input (Tensor): the input value(s), ``torch.float32`` tensor
  10686. scale (double scalar or ``float32`` Tensor): quantization scale
  10687. zero_point (int64 scalar or ``int32`` Tensor): quantization zero_point
  10688. quant_min (int64): lower bound of the quantized domain
  10689. quant_max (int64): upper bound of the quantized domain
  10690. Returns:
  10691. Tensor: A newly fake_quantized ``torch.float32`` tensor
  10692. Example::
  10693. >>> x = torch.randn(4)
  10694. >>> x
  10695. tensor([ 0.0552, 0.9730, 0.3973, -1.0780])
  10696. >>> torch.fake_quantize_per_tensor_affine(x, 0.1, 0, 0, 255)
  10697. tensor([0.1000, 1.0000, 0.4000, 0.0000])
  10698. >>> torch.fake_quantize_per_tensor_affine(x, torch.tensor(0.1), torch.tensor(0), 0, 255)
  10699. tensor([0.1000, 1.0000, 0.4000, 0.0000])
  10700. """
  10701. @overload
  10702. def fake_quantize_per_tensor_affine(
  10703. input: Tensor,
  10704. scale: Tensor,
  10705. zero_point: Tensor,
  10706. quant_min: _int,
  10707. quant_max: _int,
  10708. ) -> Tensor:
  10709. r"""
  10710. fake_quantize_per_tensor_affine(input, scale, zero_point, quant_min, quant_max) -> Tensor
  10711. Returns a new tensor with the data in :attr:`input` fake quantized using :attr:`scale`,
  10712. :attr:`zero_point`, :attr:`quant_min` and :attr:`quant_max`.
  10713. .. math::
  10714. \text{output} = (
  10715. min(
  10716. \text{quant\_max},
  10717. max(
  10718. \text{quant\_min},
  10719. \text{std::nearby\_int}(\text{input} / \text{scale}) + \text{zero\_point}
  10720. )
  10721. ) - \text{zero\_point}
  10722. ) \times \text{scale}
  10723. Args:
  10724. input (Tensor): the input value(s), ``torch.float32`` tensor
  10725. scale (double scalar or ``float32`` Tensor): quantization scale
  10726. zero_point (int64 scalar or ``int32`` Tensor): quantization zero_point
  10727. quant_min (int64): lower bound of the quantized domain
  10728. quant_max (int64): upper bound of the quantized domain
  10729. Returns:
  10730. Tensor: A newly fake_quantized ``torch.float32`` tensor
  10731. Example::
  10732. >>> x = torch.randn(4)
  10733. >>> x
  10734. tensor([ 0.0552, 0.9730, 0.3973, -1.0780])
  10735. >>> torch.fake_quantize_per_tensor_affine(x, 0.1, 0, 0, 255)
  10736. tensor([0.1000, 1.0000, 0.4000, 0.0000])
  10737. >>> torch.fake_quantize_per_tensor_affine(x, torch.tensor(0.1), torch.tensor(0), 0, 255)
  10738. tensor([0.1000, 1.0000, 0.4000, 0.0000])
  10739. """
  10740. @overload
  10741. def fbgemm_linear_fp16_weight(
  10742. input: Tensor,
  10743. packed_weight: Tensor,
  10744. bias: Tensor,
  10745. ) -> Tensor: ...
  10746. @overload
  10747. def fbgemm_linear_fp16_weight(
  10748. input: Tensor,
  10749. packed_weight: Tensor,
  10750. bias: Tensor,
  10751. output: Tensor,
  10752. ) -> Tensor: ...
  10753. @overload
  10754. def fbgemm_linear_fp16_weight_fp32_activation(
  10755. input: Tensor,
  10756. packed_weight: Tensor,
  10757. bias: Tensor | None,
  10758. ) -> Tensor: ...
  10759. @overload
  10760. def fbgemm_linear_fp16_weight_fp32_activation(
  10761. input: Tensor,
  10762. packed_weight: Tensor,
  10763. bias: Tensor | None,
  10764. output: Tensor,
  10765. ) -> Tensor: ...
  10766. def fbgemm_linear_int8_weight(
  10767. input: Tensor,
  10768. weight: Tensor,
  10769. packed: Tensor,
  10770. col_offsets: Tensor,
  10771. weight_scale: Number | _complex,
  10772. weight_zero_point: Number | _complex,
  10773. bias: Tensor,
  10774. ) -> Tensor: ...
  10775. def fbgemm_linear_int8_weight_fp32_activation(
  10776. input: Tensor,
  10777. weight: Tensor,
  10778. packed: Tensor,
  10779. col_offsets: Tensor,
  10780. weight_scale: Number | _complex,
  10781. weight_zero_point: Number | _complex,
  10782. bias: Tensor,
  10783. ) -> Tensor: ...
  10784. def fbgemm_linear_quantize_weight(
  10785. input: Tensor,
  10786. ) -> tuple[Tensor, Tensor, _float, _int]: ...
  10787. def fbgemm_pack_gemm_matrix_fp16(input: Tensor) -> Tensor: ...
  10788. @overload
  10789. def fbgemm_pack_quantized_matrix(input: Tensor) -> Tensor: ...
  10790. @overload
  10791. def fbgemm_pack_quantized_matrix(input: Tensor, K: _int, N: _int) -> Tensor: ...
  10792. def feature_alpha_dropout(input: Tensor, p: _float, train: _bool) -> Tensor: ...
  10793. def feature_alpha_dropout_(
  10794. input: Tensor,
  10795. p: _float,
  10796. train: _bool,
  10797. ) -> Tensor: ...
  10798. def feature_dropout(input: Tensor, p: _float, train: _bool) -> Tensor: ...
  10799. def feature_dropout_(input: Tensor, p: _float, train: _bool) -> Tensor: ...
  10800. @overload
  10801. def fill(input: Tensor, value: Tensor) -> Tensor: ...
  10802. @overload
  10803. def fill(input: Tensor, value: Number | _complex) -> Tensor: ...
  10804. @overload
  10805. def fill_(input: Tensor, value: Tensor) -> Tensor: ...
  10806. @overload
  10807. def fill_(input: Tensor, value: Number | _complex) -> Tensor: ...
  10808. def fix(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  10809. r"""
  10810. fix(input, *, out=None) -> Tensor
  10811. Alias for :func:`torch.trunc`
  10812. """
  10813. def fix_(input: Tensor) -> Tensor: ...
  10814. @overload
  10815. def flatten(
  10816. input: Tensor,
  10817. start_dim: _int = 0,
  10818. end_dim: _int = -1,
  10819. ) -> Tensor:
  10820. r"""
  10821. flatten(input, start_dim=0, end_dim=-1) -> Tensor
  10822. Flattens :attr:`input` by reshaping it into a one-dimensional tensor. If :attr:`start_dim` or :attr:`end_dim`
  10823. are passed, only dimensions starting with :attr:`start_dim` and ending with :attr:`end_dim` are flattened.
  10824. The order of elements in :attr:`input` is unchanged.
  10825. Unlike NumPy's flatten, which always copies input's data, this function may return the original object, a view,
  10826. or copy. If no dimensions are flattened, then the original object :attr:`input` is returned. Otherwise, if input can
  10827. be viewed as the flattened shape, then that view is returned. Finally, only if the input cannot be viewed as the
  10828. flattened shape is input's data copied. See :meth:`torch.Tensor.view` for details on when a view will be returned.
  10829. .. note::
  10830. Flattening a zero-dimensional tensor will return a one-dimensional view.
  10831. Args:
  10832. input (Tensor): the input tensor.
  10833. start_dim (int): the first dim to flatten
  10834. end_dim (int): the last dim to flatten
  10835. Example::
  10836. >>> t = torch.tensor([[[1, 2],
  10837. ... [3, 4]],
  10838. ... [[5, 6],
  10839. ... [7, 8]]])
  10840. >>> torch.flatten(t)
  10841. tensor([1, 2, 3, 4, 5, 6, 7, 8])
  10842. >>> torch.flatten(t, start_dim=1)
  10843. tensor([[1, 2, 3, 4],
  10844. [5, 6, 7, 8]])
  10845. """
  10846. @overload
  10847. def flatten(
  10848. input: Tensor,
  10849. start_dim: _int,
  10850. end_dim: _int,
  10851. out_dim: str | EllipsisType | None,
  10852. ) -> Tensor:
  10853. r"""
  10854. flatten(input, start_dim=0, end_dim=-1) -> Tensor
  10855. Flattens :attr:`input` by reshaping it into a one-dimensional tensor. If :attr:`start_dim` or :attr:`end_dim`
  10856. are passed, only dimensions starting with :attr:`start_dim` and ending with :attr:`end_dim` are flattened.
  10857. The order of elements in :attr:`input` is unchanged.
  10858. Unlike NumPy's flatten, which always copies input's data, this function may return the original object, a view,
  10859. or copy. If no dimensions are flattened, then the original object :attr:`input` is returned. Otherwise, if input can
  10860. be viewed as the flattened shape, then that view is returned. Finally, only if the input cannot be viewed as the
  10861. flattened shape is input's data copied. See :meth:`torch.Tensor.view` for details on when a view will be returned.
  10862. .. note::
  10863. Flattening a zero-dimensional tensor will return a one-dimensional view.
  10864. Args:
  10865. input (Tensor): the input tensor.
  10866. start_dim (int): the first dim to flatten
  10867. end_dim (int): the last dim to flatten
  10868. Example::
  10869. >>> t = torch.tensor([[[1, 2],
  10870. ... [3, 4]],
  10871. ... [[5, 6],
  10872. ... [7, 8]]])
  10873. >>> torch.flatten(t)
  10874. tensor([1, 2, 3, 4, 5, 6, 7, 8])
  10875. >>> torch.flatten(t, start_dim=1)
  10876. tensor([[1, 2, 3, 4],
  10877. [5, 6, 7, 8]])
  10878. """
  10879. @overload
  10880. def flatten(
  10881. input: Tensor,
  10882. start_dim: str | EllipsisType | None,
  10883. end_dim: str | EllipsisType | None,
  10884. out_dim: str | EllipsisType | None,
  10885. ) -> Tensor:
  10886. r"""
  10887. flatten(input, start_dim=0, end_dim=-1) -> Tensor
  10888. Flattens :attr:`input` by reshaping it into a one-dimensional tensor. If :attr:`start_dim` or :attr:`end_dim`
  10889. are passed, only dimensions starting with :attr:`start_dim` and ending with :attr:`end_dim` are flattened.
  10890. The order of elements in :attr:`input` is unchanged.
  10891. Unlike NumPy's flatten, which always copies input's data, this function may return the original object, a view,
  10892. or copy. If no dimensions are flattened, then the original object :attr:`input` is returned. Otherwise, if input can
  10893. be viewed as the flattened shape, then that view is returned. Finally, only if the input cannot be viewed as the
  10894. flattened shape is input's data copied. See :meth:`torch.Tensor.view` for details on when a view will be returned.
  10895. .. note::
  10896. Flattening a zero-dimensional tensor will return a one-dimensional view.
  10897. Args:
  10898. input (Tensor): the input tensor.
  10899. start_dim (int): the first dim to flatten
  10900. end_dim (int): the last dim to flatten
  10901. Example::
  10902. >>> t = torch.tensor([[[1, 2],
  10903. ... [3, 4]],
  10904. ... [[5, 6],
  10905. ... [7, 8]]])
  10906. >>> torch.flatten(t)
  10907. tensor([1, 2, 3, 4, 5, 6, 7, 8])
  10908. >>> torch.flatten(t, start_dim=1)
  10909. tensor([[1, 2, 3, 4],
  10910. [5, 6, 7, 8]])
  10911. """
  10912. @overload
  10913. def flatten(
  10914. input: Tensor,
  10915. dims: Sequence[str | EllipsisType | None],
  10916. out_dim: str | EllipsisType | None,
  10917. ) -> Tensor:
  10918. r"""
  10919. flatten(input, start_dim=0, end_dim=-1) -> Tensor
  10920. Flattens :attr:`input` by reshaping it into a one-dimensional tensor. If :attr:`start_dim` or :attr:`end_dim`
  10921. are passed, only dimensions starting with :attr:`start_dim` and ending with :attr:`end_dim` are flattened.
  10922. The order of elements in :attr:`input` is unchanged.
  10923. Unlike NumPy's flatten, which always copies input's data, this function may return the original object, a view,
  10924. or copy. If no dimensions are flattened, then the original object :attr:`input` is returned. Otherwise, if input can
  10925. be viewed as the flattened shape, then that view is returned. Finally, only if the input cannot be viewed as the
  10926. flattened shape is input's data copied. See :meth:`torch.Tensor.view` for details on when a view will be returned.
  10927. .. note::
  10928. Flattening a zero-dimensional tensor will return a one-dimensional view.
  10929. Args:
  10930. input (Tensor): the input tensor.
  10931. start_dim (int): the first dim to flatten
  10932. end_dim (int): the last dim to flatten
  10933. Example::
  10934. >>> t = torch.tensor([[[1, 2],
  10935. ... [3, 4]],
  10936. ... [[5, 6],
  10937. ... [7, 8]]])
  10938. >>> torch.flatten(t)
  10939. tensor([1, 2, 3, 4, 5, 6, 7, 8])
  10940. >>> torch.flatten(t, start_dim=1)
  10941. tensor([[1, 2, 3, 4],
  10942. [5, 6, 7, 8]])
  10943. """
  10944. def flip(input: Tensor, dims: _size) -> Tensor:
  10945. r"""
  10946. flip(input, dims) -> Tensor
  10947. Reverse the order of an n-D tensor along given axis in dims.
  10948. .. note::
  10949. `torch.flip` makes a copy of :attr:`input`'s data. This is different from NumPy's `np.flip`,
  10950. which returns a view in constant time. Since copying a tensor's data is more work than viewing that data,
  10951. `torch.flip` is expected to be slower than `np.flip`.
  10952. Args:
  10953. input (Tensor): the input tensor.
  10954. dims (a list or tuple): axis to flip on
  10955. Example::
  10956. >>> x = torch.arange(8).view(2, 2, 2)
  10957. >>> x
  10958. tensor([[[ 0, 1],
  10959. [ 2, 3]],
  10960. [[ 4, 5],
  10961. [ 6, 7]]])
  10962. >>> torch.flip(x, [0, 1])
  10963. tensor([[[ 6, 7],
  10964. [ 4, 5]],
  10965. [[ 2, 3],
  10966. [ 0, 1]]])
  10967. """
  10968. def fliplr(input: Tensor) -> Tensor:
  10969. r"""
  10970. fliplr(input) -> Tensor
  10971. Flip tensor in the left/right direction, returning a new tensor.
  10972. Flip the entries in each row in the left/right direction.
  10973. Columns are preserved, but appear in a different order than before.
  10974. Note:
  10975. Requires the tensor to be at least 2-D.
  10976. .. note::
  10977. `torch.fliplr` makes a copy of :attr:`input`'s data. This is different from NumPy's `np.fliplr`,
  10978. which returns a view in constant time. Since copying a tensor's data is more work than viewing that data,
  10979. `torch.fliplr` is expected to be slower than `np.fliplr`.
  10980. Args:
  10981. input (Tensor): Must be at least 2-dimensional.
  10982. Example::
  10983. >>> x = torch.arange(4).view(2, 2)
  10984. >>> x
  10985. tensor([[0, 1],
  10986. [2, 3]])
  10987. >>> torch.fliplr(x)
  10988. tensor([[1, 0],
  10989. [3, 2]])
  10990. """
  10991. def flipud(input: Tensor) -> Tensor:
  10992. r"""
  10993. flipud(input) -> Tensor
  10994. Flip tensor in the up/down direction, returning a new tensor.
  10995. Flip the entries in each column in the up/down direction.
  10996. Rows are preserved, but appear in a different order than before.
  10997. Note:
  10998. Requires the tensor to be at least 1-D.
  10999. .. note::
  11000. `torch.flipud` makes a copy of :attr:`input`'s data. This is different from NumPy's `np.flipud`,
  11001. which returns a view in constant time. Since copying a tensor's data is more work than viewing that data,
  11002. `torch.flipud` is expected to be slower than `np.flipud`.
  11003. Args:
  11004. input (Tensor): Must be at least 1-dimensional.
  11005. Example::
  11006. >>> x = torch.arange(4).view(2, 2)
  11007. >>> x
  11008. tensor([[0, 1],
  11009. [2, 3]])
  11010. >>> torch.flipud(x)
  11011. tensor([[2, 3],
  11012. [0, 1]])
  11013. """
  11014. @overload
  11015. def float_power(
  11016. input: Tensor,
  11017. exponent: Tensor,
  11018. *,
  11019. out: Tensor | None = None,
  11020. ) -> Tensor:
  11021. r"""
  11022. float_power(input, exponent, *, out=None) -> Tensor
  11023. Raises :attr:`input` to the power of :attr:`exponent`, elementwise, in double precision.
  11024. If neither input is complex returns a ``torch.float64`` tensor,
  11025. and if one or more inputs is complex returns a ``torch.complex128`` tensor.
  11026. .. note::
  11027. This function always computes in double precision, unlike :func:`torch.pow`,
  11028. which implements more typical :ref:`type promotion <type-promotion-doc>`.
  11029. This is useful when the computation needs to be performed in a wider or more precise dtype,
  11030. or the results of the computation may contain fractional values not representable in the input dtypes,
  11031. like when an integer base is raised to a negative integer exponent.
  11032. Args:
  11033. input (Tensor or Number): the base value(s)
  11034. exponent (Tensor or Number): the exponent value(s)
  11035. Keyword args:
  11036. out (Tensor, optional): the output tensor.
  11037. Example::
  11038. >>> a = torch.randint(10, (4,))
  11039. >>> a
  11040. tensor([6, 4, 7, 1])
  11041. >>> torch.float_power(a, 2)
  11042. tensor([36., 16., 49., 1.], dtype=torch.float64)
  11043. >>> a = torch.arange(1, 5)
  11044. >>> a
  11045. tensor([ 1, 2, 3, 4])
  11046. >>> exp = torch.tensor([2, -3, 4, -5])
  11047. >>> exp
  11048. tensor([ 2, -3, 4, -5])
  11049. >>> torch.float_power(a, exp)
  11050. tensor([1.0000e+00, 1.2500e-01, 8.1000e+01, 9.7656e-04], dtype=torch.float64)
  11051. """
  11052. @overload
  11053. def float_power(
  11054. self: Number | _complex,
  11055. exponent: Tensor,
  11056. *,
  11057. out: Tensor | None = None,
  11058. ) -> Tensor:
  11059. r"""
  11060. float_power(input, exponent, *, out=None) -> Tensor
  11061. Raises :attr:`input` to the power of :attr:`exponent`, elementwise, in double precision.
  11062. If neither input is complex returns a ``torch.float64`` tensor,
  11063. and if one or more inputs is complex returns a ``torch.complex128`` tensor.
  11064. .. note::
  11065. This function always computes in double precision, unlike :func:`torch.pow`,
  11066. which implements more typical :ref:`type promotion <type-promotion-doc>`.
  11067. This is useful when the computation needs to be performed in a wider or more precise dtype,
  11068. or the results of the computation may contain fractional values not representable in the input dtypes,
  11069. like when an integer base is raised to a negative integer exponent.
  11070. Args:
  11071. input (Tensor or Number): the base value(s)
  11072. exponent (Tensor or Number): the exponent value(s)
  11073. Keyword args:
  11074. out (Tensor, optional): the output tensor.
  11075. Example::
  11076. >>> a = torch.randint(10, (4,))
  11077. >>> a
  11078. tensor([6, 4, 7, 1])
  11079. >>> torch.float_power(a, 2)
  11080. tensor([36., 16., 49., 1.], dtype=torch.float64)
  11081. >>> a = torch.arange(1, 5)
  11082. >>> a
  11083. tensor([ 1, 2, 3, 4])
  11084. >>> exp = torch.tensor([2, -3, 4, -5])
  11085. >>> exp
  11086. tensor([ 2, -3, 4, -5])
  11087. >>> torch.float_power(a, exp)
  11088. tensor([1.0000e+00, 1.2500e-01, 8.1000e+01, 9.7656e-04], dtype=torch.float64)
  11089. """
  11090. @overload
  11091. def float_power(
  11092. input: Tensor,
  11093. exponent: Number | _complex,
  11094. *,
  11095. out: Tensor | None = None,
  11096. ) -> Tensor:
  11097. r"""
  11098. float_power(input, exponent, *, out=None) -> Tensor
  11099. Raises :attr:`input` to the power of :attr:`exponent`, elementwise, in double precision.
  11100. If neither input is complex returns a ``torch.float64`` tensor,
  11101. and if one or more inputs is complex returns a ``torch.complex128`` tensor.
  11102. .. note::
  11103. This function always computes in double precision, unlike :func:`torch.pow`,
  11104. which implements more typical :ref:`type promotion <type-promotion-doc>`.
  11105. This is useful when the computation needs to be performed in a wider or more precise dtype,
  11106. or the results of the computation may contain fractional values not representable in the input dtypes,
  11107. like when an integer base is raised to a negative integer exponent.
  11108. Args:
  11109. input (Tensor or Number): the base value(s)
  11110. exponent (Tensor or Number): the exponent value(s)
  11111. Keyword args:
  11112. out (Tensor, optional): the output tensor.
  11113. Example::
  11114. >>> a = torch.randint(10, (4,))
  11115. >>> a
  11116. tensor([6, 4, 7, 1])
  11117. >>> torch.float_power(a, 2)
  11118. tensor([36., 16., 49., 1.], dtype=torch.float64)
  11119. >>> a = torch.arange(1, 5)
  11120. >>> a
  11121. tensor([ 1, 2, 3, 4])
  11122. >>> exp = torch.tensor([2, -3, 4, -5])
  11123. >>> exp
  11124. tensor([ 2, -3, 4, -5])
  11125. >>> torch.float_power(a, exp)
  11126. tensor([1.0000e+00, 1.2500e-01, 8.1000e+01, 9.7656e-04], dtype=torch.float64)
  11127. """
  11128. def floor(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  11129. r"""
  11130. floor(input, *, out=None) -> Tensor
  11131. Returns a new tensor with the floor of the elements of :attr:`input`,
  11132. the largest integer less than or equal to each element.
  11133. For integer inputs, follows the array-api convention of returning a
  11134. copy of the input tensor.
  11135. .. math::
  11136. \text{out}_{i} = \left\lfloor \text{input}_{i} \right\rfloor
  11137. Args:
  11138. input (Tensor): the input tensor.
  11139. Keyword args:
  11140. out (Tensor, optional): the output tensor.
  11141. Example::
  11142. >>> a = torch.randn(4)
  11143. >>> a
  11144. tensor([-0.8166, 1.5308, -0.2530, -0.2091])
  11145. >>> torch.floor(a)
  11146. tensor([-1., 1., -1., -1.])
  11147. """
  11148. def floor_(input: Tensor) -> Tensor: ...
  11149. def floor_divide(
  11150. input: Tensor | Number,
  11151. other: Tensor | Number,
  11152. *,
  11153. out: Tensor | None = None,
  11154. ) -> Tensor:
  11155. r"""
  11156. floor_divide(input, other, *, out=None) -> Tensor
  11157. .. note::
  11158. Before PyTorch 1.13 :func:`torch.floor_divide` incorrectly performed
  11159. truncation division. To restore the previous behavior use
  11160. :func:`torch.div` with ``rounding_mode='trunc'``.
  11161. Computes :attr:`input` divided by :attr:`other`, elementwise, and floors
  11162. the result.
  11163. .. math::
  11164. \text{{out}}_i = \text{floor} \left( \frac{{\text{{input}}_i}}{{\text{{other}}_i}} \right)
  11165. Supports broadcasting to a common shape, type promotion, and integer and float inputs.
  11166. Args:
  11167. input (Tensor or Number): the dividend
  11168. other (Tensor or Number): the divisor
  11169. Keyword args:
  11170. out (Tensor, optional): the output tensor.
  11171. Example::
  11172. >>> a = torch.tensor([4.0, 3.0])
  11173. >>> b = torch.tensor([2.0, 2.0])
  11174. >>> torch.floor_divide(a, b)
  11175. tensor([2.0, 1.0])
  11176. >>> torch.floor_divide(a, 1.4)
  11177. tensor([2.0, 2.0])
  11178. """
  11179. def fmax(
  11180. input: Tensor,
  11181. other: Tensor,
  11182. *,
  11183. out: Tensor | None = None,
  11184. ) -> Tensor:
  11185. r"""
  11186. fmax(input, other, *, out=None) -> Tensor
  11187. Computes the element-wise maximum of :attr:`input` and :attr:`other`.
  11188. This is like :func:`torch.maximum` except it handles NaNs differently:
  11189. if exactly one of the two elements being compared is a NaN then the non-NaN element is taken as the maximum.
  11190. Only if both elements are NaN is NaN propagated.
  11191. This function is a wrapper around C++'s ``std::fmax`` and is similar to NumPy's ``fmax`` function.
  11192. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  11193. :ref:`type promotion <type-promotion-doc>`, and integer and floating-point inputs.
  11194. Args:
  11195. input (Tensor): the input tensor.
  11196. other (Tensor): the second input tensor
  11197. Keyword args:
  11198. out (Tensor, optional): the output tensor.
  11199. Example::
  11200. >>> a = torch.tensor([9.7, float('nan'), 3.1, float('nan')])
  11201. >>> b = torch.tensor([-2.2, 0.5, float('nan'), float('nan')])
  11202. >>> torch.fmax(a, b)
  11203. tensor([9.7000, 0.5000, 3.1000, nan])
  11204. """
  11205. def fmin(
  11206. input: Tensor,
  11207. other: Tensor,
  11208. *,
  11209. out: Tensor | None = None,
  11210. ) -> Tensor:
  11211. r"""
  11212. fmin(input, other, *, out=None) -> Tensor
  11213. Computes the element-wise minimum of :attr:`input` and :attr:`other`.
  11214. This is like :func:`torch.minimum` except it handles NaNs differently:
  11215. if exactly one of the two elements being compared is a NaN then the non-NaN element is taken as the minimum.
  11216. Only if both elements are NaN is NaN propagated.
  11217. This function is a wrapper around C++'s ``std::fmin`` and is similar to NumPy's ``fmin`` function.
  11218. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  11219. :ref:`type promotion <type-promotion-doc>`, and integer and floating-point inputs.
  11220. Args:
  11221. input (Tensor): the input tensor.
  11222. other (Tensor): the second input tensor
  11223. Keyword args:
  11224. out (Tensor, optional): the output tensor.
  11225. Example::
  11226. >>> a = torch.tensor([2.2, float('nan'), 2.1, float('nan')])
  11227. >>> b = torch.tensor([-9.3, 0.1, float('nan'), float('nan')])
  11228. >>> torch.fmin(a, b)
  11229. tensor([-9.3000, 0.1000, 2.1000, nan])
  11230. """
  11231. @overload
  11232. def fmod(
  11233. input: Tensor,
  11234. other: Tensor,
  11235. *,
  11236. out: Tensor | None = None,
  11237. ) -> Tensor:
  11238. r"""
  11239. fmod(input, other, *, out=None) -> Tensor
  11240. Applies C++'s `std::fmod <https://en.cppreference.com/w/cpp/numeric/math/fmod>`_ entrywise.
  11241. The result has the same sign as the dividend :attr:`input` and its absolute value
  11242. is less than that of :attr:`other`.
  11243. This function may be defined in terms of :func:`torch.div` as
  11244. .. code:: python
  11245. torch.fmod(a, b) == a - a.div(b, rounding_mode="trunc") * b
  11246. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  11247. :ref:`type promotion <type-promotion-doc>`, and integer and float inputs.
  11248. .. note::
  11249. When the divisor is zero, returns ``NaN`` for floating point dtypes
  11250. on both CPU and GPU; raises ``RuntimeError`` for integer division by
  11251. zero on CPU; Integer division by zero on GPU may return any value.
  11252. .. note::
  11253. Complex inputs are not supported. In some cases, it is not mathematically
  11254. possible to satisfy the definition of a modulo operation with complex numbers.
  11255. .. seealso::
  11256. :func:`torch.remainder` which implements Python's modulus operator.
  11257. This one is defined using division rounding down the result.
  11258. Args:
  11259. input (Tensor): the dividend
  11260. other (Tensor or Scalar): the divisor
  11261. Keyword args:
  11262. out (Tensor, optional): the output tensor.
  11263. Example::
  11264. >>> torch.fmod(torch.tensor([-3., -2, -1, 1, 2, 3]), 2)
  11265. tensor([-1., -0., -1., 1., 0., 1.])
  11266. >>> torch.fmod(torch.tensor([1, 2, 3, 4, 5]), -1.5)
  11267. tensor([1.0000, 0.5000, 0.0000, 1.0000, 0.5000])
  11268. """
  11269. @overload
  11270. def fmod(
  11271. input: Tensor,
  11272. other: Number | _complex,
  11273. *,
  11274. out: Tensor | None = None,
  11275. ) -> Tensor:
  11276. r"""
  11277. fmod(input, other, *, out=None) -> Tensor
  11278. Applies C++'s `std::fmod <https://en.cppreference.com/w/cpp/numeric/math/fmod>`_ entrywise.
  11279. The result has the same sign as the dividend :attr:`input` and its absolute value
  11280. is less than that of :attr:`other`.
  11281. This function may be defined in terms of :func:`torch.div` as
  11282. .. code:: python
  11283. torch.fmod(a, b) == a - a.div(b, rounding_mode="trunc") * b
  11284. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  11285. :ref:`type promotion <type-promotion-doc>`, and integer and float inputs.
  11286. .. note::
  11287. When the divisor is zero, returns ``NaN`` for floating point dtypes
  11288. on both CPU and GPU; raises ``RuntimeError`` for integer division by
  11289. zero on CPU; Integer division by zero on GPU may return any value.
  11290. .. note::
  11291. Complex inputs are not supported. In some cases, it is not mathematically
  11292. possible to satisfy the definition of a modulo operation with complex numbers.
  11293. .. seealso::
  11294. :func:`torch.remainder` which implements Python's modulus operator.
  11295. This one is defined using division rounding down the result.
  11296. Args:
  11297. input (Tensor): the dividend
  11298. other (Tensor or Scalar): the divisor
  11299. Keyword args:
  11300. out (Tensor, optional): the output tensor.
  11301. Example::
  11302. >>> torch.fmod(torch.tensor([-3., -2, -1, 1, 2, 3]), 2)
  11303. tensor([-1., -0., -1., 1., 0., 1.])
  11304. >>> torch.fmod(torch.tensor([1, 2, 3, 4, 5]), -1.5)
  11305. tensor([1.0000, 0.5000, 0.0000, 1.0000, 0.5000])
  11306. """
  11307. def frac(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  11308. r"""
  11309. frac(input, *, out=None) -> Tensor
  11310. Computes the fractional portion of each element in :attr:`input`.
  11311. .. math::
  11312. \text{out}_{i} = \text{input}_{i} - \left\lfloor |\text{input}_{i}| \right\rfloor * \operatorname{sgn}(\text{input}_{i})
  11313. Example::
  11314. >>> torch.frac(torch.tensor([1, 2.5, -3.2]))
  11315. tensor([ 0.0000, 0.5000, -0.2000])
  11316. """
  11317. def frac_(input: Tensor) -> Tensor: ...
  11318. def frexp(
  11319. input: Tensor,
  11320. *,
  11321. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  11322. ) -> torch.return_types.frexp:
  11323. r"""
  11324. frexp(input, *, out=None) -> (Tensor mantissa, Tensor exponent)
  11325. Decomposes :attr:`input` into mantissa and exponent tensors
  11326. such that :math:`\text{input} = \text{mantissa} \times 2^{\text{exponent}}`.
  11327. The range of mantissa is the open interval (-1, 1).
  11328. Supports float inputs.
  11329. Args:
  11330. input (Tensor): the input tensor
  11331. Keyword args:
  11332. out (tuple, optional): the output tensors
  11333. Example::
  11334. >>> x = torch.arange(9.)
  11335. >>> mantissa, exponent = torch.frexp(x)
  11336. >>> mantissa
  11337. tensor([0.0000, 0.5000, 0.5000, 0.7500, 0.5000, 0.6250, 0.7500, 0.8750, 0.5000])
  11338. >>> exponent
  11339. tensor([0, 1, 2, 2, 3, 3, 3, 3, 4], dtype=torch.int32)
  11340. >>> torch.ldexp(mantissa, exponent)
  11341. tensor([0., 1., 2., 3., 4., 5., 6., 7., 8.])
  11342. """
  11343. def frobenius_norm(
  11344. input: Tensor,
  11345. dim: _int | _size,
  11346. keepdim: _bool = False,
  11347. *,
  11348. out: Tensor | None = None,
  11349. ) -> Tensor: ...
  11350. def from_file(
  11351. filename: str,
  11352. shared: _bool | None = None,
  11353. size: _int | None = 0,
  11354. *,
  11355. dtype: _dtype | None = None,
  11356. layout: _layout | None = None,
  11357. device: DeviceLikeType | None = None,
  11358. pin_memory: _bool | None = False,
  11359. requires_grad: _bool | None = False,
  11360. ) -> Tensor:
  11361. r"""
  11362. from_file(filename, shared=None, size=0, *, dtype=None, layout=None, device=None, pin_memory=False)
  11363. Creates a CPU tensor with a storage backed by a memory-mapped file.
  11364. If ``shared`` is True, then memory is shared between processes. All changes are written to the file.
  11365. If ``shared`` is False, then changes to the tensor do not affect the file.
  11366. ``size`` is the number of elements in the Tensor. If ``shared`` is ``False``, then the file must contain
  11367. at least ``size * sizeof(dtype)`` bytes. If ``shared`` is ``True`` the file will be created if needed.
  11368. .. note::
  11369. Only CPU tensors can be mapped to files.
  11370. .. note::
  11371. For now, tensors with storages backed by a memory-mapped file cannot be created in pinned memory.
  11372. Args:
  11373. filename (str): file name to map
  11374. shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
  11375. underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
  11376. size (int): number of elements in the tensor
  11377. Keyword args:
  11378. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  11379. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  11380. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  11381. Default: ``torch.strided``.
  11382. device (:class:`torch.device`, optional): the desired device of returned tensor.
  11383. Default: if ``None``, uses the current device for the default tensor type
  11384. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  11385. for CPU tensor types and the current CUDA device for CUDA tensor types.
  11386. pin_memory (bool, optional): If set, returned tensor would be allocated in
  11387. the pinned memory. Works only for CPU tensors. Default: ``False``.
  11388. Example::
  11389. >>> t = torch.randn(2, 5, dtype=torch.float64)
  11390. >>> t.numpy().tofile('storage.pt')
  11391. >>> t_mapped = torch.from_file('storage.pt', shared=False, size=10, dtype=torch.float64)
  11392. """
  11393. def from_numpy(ndarray) -> Tensor:
  11394. r"""
  11395. from_numpy(ndarray) -> Tensor
  11396. Creates a :class:`Tensor` from a :class:`numpy.ndarray`.
  11397. The returned tensor and :attr:`ndarray` share the same memory. Modifications to
  11398. the tensor will be reflected in the :attr:`ndarray` and vice versa. The returned
  11399. tensor is not resizable.
  11400. It currently accepts :attr:`ndarray` with dtypes of ``numpy.float64``,
  11401. ``numpy.float32``, ``numpy.float16``, ``numpy.complex64``, ``numpy.complex128``,
  11402. ``numpy.int64``, ``numpy.int32``, ``numpy.int16``, ``numpy.int8``, ``numpy.uint8``,
  11403. and ``bool``.
  11404. .. warning::
  11405. Writing to a tensor created from a read-only NumPy array is not supported and will result in undefined behavior.
  11406. Example::
  11407. >>> a = numpy.array([1, 2, 3])
  11408. >>> t = torch.from_numpy(a)
  11409. >>> t
  11410. tensor([ 1, 2, 3])
  11411. >>> t[0] = -1
  11412. >>> a
  11413. array([-1, 2, 3])
  11414. """
  11415. def frombuffer(
  11416. buffer: Any,
  11417. *,
  11418. dtype: _dtype,
  11419. count: int = -1,
  11420. offset: int = 0,
  11421. requires_grad: _bool = False,
  11422. ) -> Tensor:
  11423. r"""
  11424. frombuffer(buffer, *, dtype, count=-1, offset=0, requires_grad=False) -> Tensor
  11425. Creates a 1-dimensional :class:`Tensor` from an object that implements
  11426. the Python buffer protocol.
  11427. Skips the first :attr:`offset` bytes in the buffer, and interprets the rest of
  11428. the raw bytes as a 1-dimensional tensor of type :attr:`dtype` with :attr:`count`
  11429. elements.
  11430. Note that either of the following must be true:
  11431. 1. :attr:`count` is a positive non-zero number, and the total number of bytes
  11432. in the buffer is more than :attr:`offset` plus :attr:`count` times the size
  11433. (in bytes) of :attr:`dtype`.
  11434. 2. :attr:`count` is negative, and the length (number of bytes) of the buffer
  11435. subtracted by the :attr:`offset` is a multiple of the size (in bytes) of
  11436. :attr:`dtype`.
  11437. The returned tensor and buffer share the same memory. Modifications to
  11438. the tensor will be reflected in the buffer and vice versa. The returned
  11439. tensor is not resizable.
  11440. .. note::
  11441. This function increments the reference count for the object that
  11442. owns the shared memory. Therefore, such memory will not be deallocated
  11443. before the returned tensor goes out of scope.
  11444. .. warning::
  11445. This function's behavior is undefined when passed an object implementing
  11446. the buffer protocol whose data is not on the CPU. Doing so is likely to
  11447. cause a segmentation fault.
  11448. .. warning::
  11449. This function does not try to infer the :attr:`dtype` (hence, it is not
  11450. optional). Passing a different :attr:`dtype` than its source may result
  11451. in unexpected behavior.
  11452. Args:
  11453. buffer (object): a Python object that exposes the buffer interface.
  11454. Keyword args:
  11455. dtype (:class:`torch.dtype`): the desired data type of returned tensor.
  11456. count (int, optional): the number of desired elements to be read.
  11457. If negative, all the elements (until the end of the buffer) will be
  11458. read. Default: -1.
  11459. offset (int, optional): the number of bytes to skip at the start of
  11460. the buffer. Default: 0.
  11461. requires_grad (bool, optional): If autograd should record operations on the
  11462. returned tensor. Default: ``False``.
  11463. Example::
  11464. >>> import array
  11465. >>> a = array.array('i', [1, 2, 3])
  11466. >>> t = torch.frombuffer(a, dtype=torch.int32)
  11467. >>> t
  11468. tensor([ 1, 2, 3])
  11469. >>> t[0] = -1
  11470. >>> a
  11471. array([-1, 2, 3])
  11472. >>> # Interprets the signed char bytes as 32-bit integers.
  11473. >>> # Each 4 signed char elements will be interpreted as
  11474. >>> # 1 signed 32-bit integer.
  11475. >>> import array
  11476. >>> a = array.array('b', [-1, 0, 0, 0])
  11477. >>> torch.frombuffer(a, dtype=torch.int32)
  11478. tensor([255], dtype=torch.int32)
  11479. """
  11480. @overload
  11481. def full(
  11482. size: _size,
  11483. fill_value: Number | _complex,
  11484. *,
  11485. out: Tensor | None = None,
  11486. layout: _layout = strided,
  11487. dtype: _dtype | None = None,
  11488. device: DeviceLikeType | None = None,
  11489. requires_grad: _bool = False,
  11490. pin_memory: _bool = False,
  11491. ) -> Tensor:
  11492. r"""
  11493. full(size, fill_value, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  11494. Creates a tensor of size :attr:`size` filled with :attr:`fill_value`. The
  11495. tensor's dtype is inferred from :attr:`fill_value`.
  11496. Args:
  11497. size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
  11498. shape of the output tensor.
  11499. fill_value (Scalar): the value to fill the output tensor with.
  11500. Keyword args:
  11501. out (Tensor, optional): the output tensor.
  11502. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  11503. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  11504. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  11505. Default: ``torch.strided``.
  11506. device (:class:`torch.device`, optional): the desired device of returned tensor.
  11507. Default: if ``None``, uses the current device for the default tensor type
  11508. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  11509. for CPU tensor types and the current CUDA device for CUDA tensor types.
  11510. requires_grad (bool, optional): If autograd should record operations on the
  11511. returned tensor. Default: ``False``.
  11512. Example::
  11513. >>> torch.full((2, 3), 3.141592)
  11514. tensor([[ 3.1416, 3.1416, 3.1416],
  11515. [ 3.1416, 3.1416, 3.1416]])
  11516. """
  11517. @overload
  11518. def full(
  11519. size: _size,
  11520. fill_value: Number | _complex,
  11521. *,
  11522. names: list[str | None],
  11523. layout: _layout = strided,
  11524. dtype: _dtype | None = None,
  11525. device: DeviceLikeType | None = None,
  11526. requires_grad: _bool = False,
  11527. pin_memory: _bool = False,
  11528. ) -> Tensor:
  11529. r"""
  11530. full(size, fill_value, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  11531. Creates a tensor of size :attr:`size` filled with :attr:`fill_value`. The
  11532. tensor's dtype is inferred from :attr:`fill_value`.
  11533. Args:
  11534. size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
  11535. shape of the output tensor.
  11536. fill_value (Scalar): the value to fill the output tensor with.
  11537. Keyword args:
  11538. out (Tensor, optional): the output tensor.
  11539. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  11540. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  11541. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  11542. Default: ``torch.strided``.
  11543. device (:class:`torch.device`, optional): the desired device of returned tensor.
  11544. Default: if ``None``, uses the current device for the default tensor type
  11545. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  11546. for CPU tensor types and the current CUDA device for CUDA tensor types.
  11547. requires_grad (bool, optional): If autograd should record operations on the
  11548. returned tensor. Default: ``False``.
  11549. Example::
  11550. >>> torch.full((2, 3), 3.141592)
  11551. tensor([[ 3.1416, 3.1416, 3.1416],
  11552. [ 3.1416, 3.1416, 3.1416]])
  11553. """
  11554. @overload
  11555. def full(
  11556. size: Sequence[_int | SymInt],
  11557. fill_value: Number | _complex,
  11558. *,
  11559. out: Tensor | None = None,
  11560. dtype: _dtype | None = None,
  11561. layout: _layout | None = None,
  11562. device: DeviceLikeType | None = None,
  11563. pin_memory: _bool | None = False,
  11564. requires_grad: _bool | None = False,
  11565. ) -> Tensor:
  11566. r"""
  11567. full(size, fill_value, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  11568. Creates a tensor of size :attr:`size` filled with :attr:`fill_value`. The
  11569. tensor's dtype is inferred from :attr:`fill_value`.
  11570. Args:
  11571. size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
  11572. shape of the output tensor.
  11573. fill_value (Scalar): the value to fill the output tensor with.
  11574. Keyword args:
  11575. out (Tensor, optional): the output tensor.
  11576. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  11577. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  11578. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  11579. Default: ``torch.strided``.
  11580. device (:class:`torch.device`, optional): the desired device of returned tensor.
  11581. Default: if ``None``, uses the current device for the default tensor type
  11582. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  11583. for CPU tensor types and the current CUDA device for CUDA tensor types.
  11584. requires_grad (bool, optional): If autograd should record operations on the
  11585. returned tensor. Default: ``False``.
  11586. Example::
  11587. >>> torch.full((2, 3), 3.141592)
  11588. tensor([[ 3.1416, 3.1416, 3.1416],
  11589. [ 3.1416, 3.1416, 3.1416]])
  11590. """
  11591. @overload
  11592. def full(
  11593. size: _size,
  11594. fill_value: Number | _complex,
  11595. *,
  11596. names: Sequence[str | EllipsisType | None] | None,
  11597. dtype: _dtype | None = None,
  11598. layout: _layout | None = None,
  11599. device: DeviceLikeType | None = None,
  11600. pin_memory: _bool | None = False,
  11601. requires_grad: _bool | None = False,
  11602. ) -> Tensor:
  11603. r"""
  11604. full(size, fill_value, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  11605. Creates a tensor of size :attr:`size` filled with :attr:`fill_value`. The
  11606. tensor's dtype is inferred from :attr:`fill_value`.
  11607. Args:
  11608. size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
  11609. shape of the output tensor.
  11610. fill_value (Scalar): the value to fill the output tensor with.
  11611. Keyword args:
  11612. out (Tensor, optional): the output tensor.
  11613. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  11614. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  11615. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  11616. Default: ``torch.strided``.
  11617. device (:class:`torch.device`, optional): the desired device of returned tensor.
  11618. Default: if ``None``, uses the current device for the default tensor type
  11619. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  11620. for CPU tensor types and the current CUDA device for CUDA tensor types.
  11621. requires_grad (bool, optional): If autograd should record operations on the
  11622. returned tensor. Default: ``False``.
  11623. Example::
  11624. >>> torch.full((2, 3), 3.141592)
  11625. tensor([[ 3.1416, 3.1416, 3.1416],
  11626. [ 3.1416, 3.1416, 3.1416]])
  11627. """
  11628. def full_like(
  11629. input: Tensor,
  11630. fill_value: Number | _complex,
  11631. *,
  11632. memory_format: memory_format | None = None,
  11633. dtype: _dtype | None = None,
  11634. layout: _layout | None = None,
  11635. device: DeviceLikeType | None = None,
  11636. pin_memory: _bool | None = False,
  11637. requires_grad: _bool | None = False,
  11638. ) -> Tensor:
  11639. r"""
  11640. full_like(input, fill_value, \*, dtype=None, layout=torch.strided, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  11641. Returns a tensor with the same size as :attr:`input` filled with :attr:`fill_value`.
  11642. ``torch.full_like(input, fill_value)`` is equivalent to
  11643. ``torch.full(input.size(), fill_value, dtype=input.dtype, layout=input.layout, device=input.device)``.
  11644. Args:
  11645. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  11646. fill_value: the number to fill the output tensor with.
  11647. Keyword args:
  11648. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  11649. Default: if ``None``, defaults to the dtype of :attr:`input`.
  11650. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  11651. Default: if ``None``, defaults to the layout of :attr:`input`.
  11652. device (:class:`torch.device`, optional): the desired device of returned tensor.
  11653. Default: if ``None``, defaults to the device of :attr:`input`.
  11654. requires_grad (bool, optional): If autograd should record operations on the
  11655. returned tensor. Default: ``False``.
  11656. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  11657. returned Tensor. Default: ``torch.preserve_format``.
  11658. Example::
  11659. >>> x = torch.ones(2, 3)
  11660. >>> torch.full_like(x, 3.141592)
  11661. tensor([[ 3.1416, 3.1416, 3.1416],
  11662. [ 3.1416, 3.1416, 3.1416]])
  11663. >>> torch.full_like(x, 7)
  11664. tensor([[7., 7., 7.],
  11665. [7., 7., 7.]])
  11666. >>> torch.full_like(x, 0.5, dtype=torch.int32)
  11667. tensor([[0, 0, 0],
  11668. [0, 0, 0]], dtype=torch.int32)
  11669. >>> y = torch.randn(3, 4, dtype=torch.float64)
  11670. >>> torch.full_like(y, -1.0)
  11671. tensor([[-1., -1., -1., -1.],
  11672. [-1., -1., -1., -1.],
  11673. [-1., -1., -1., -1.]], dtype=torch.float64)
  11674. """
  11675. def fused_moving_avg_obs_fake_quant(
  11676. input: Tensor,
  11677. observer_on: Tensor,
  11678. fake_quant_on: Tensor,
  11679. running_min: Tensor,
  11680. running_max: Tensor,
  11681. scale: Tensor,
  11682. zero_point: Tensor,
  11683. averaging_const: _float,
  11684. quant_min: _int,
  11685. quant_max: _int,
  11686. ch_axis: _int,
  11687. per_row_fake_quant: _bool = False,
  11688. symmetric_quant: _bool = False,
  11689. ) -> Tensor: ...
  11690. @overload
  11691. def gather(
  11692. input: Tensor,
  11693. dim: _int,
  11694. index: Tensor,
  11695. *,
  11696. sparse_grad: _bool = False,
  11697. out: Tensor | None = None,
  11698. ) -> Tensor:
  11699. r"""
  11700. gather(input, dim, index, *, sparse_grad=False, out=None) -> Tensor
  11701. Gathers values along an axis specified by `dim`.
  11702. For a 3-D tensor the output is specified by::
  11703. out[i][j][k] = input[index[i][j][k]][j][k] # if dim == 0
  11704. out[i][j][k] = input[i][index[i][j][k]][k] # if dim == 1
  11705. out[i][j][k] = input[i][j][index[i][j][k]] # if dim == 2
  11706. :attr:`input` and :attr:`index` must have the same number of dimensions.
  11707. It is also required that ``index.size(d) <= input.size(d)`` for all
  11708. dimensions ``d != dim``. :attr:`out` will have the same shape as :attr:`index`.
  11709. Note that ``input`` and ``index`` do not broadcast against each other.
  11710. When :attr:`index` is empty, we always return an empty output with the same shape
  11711. without further error checking.
  11712. Args:
  11713. input (Tensor): the source tensor
  11714. dim (int): the axis along which to index
  11715. index (LongTensor): the indices of elements to gather
  11716. Keyword arguments:
  11717. sparse_grad (bool, optional): If ``True``, gradient w.r.t. :attr:`input` will be a sparse tensor.
  11718. out (Tensor, optional): the destination tensor
  11719. Example::
  11720. >>> t = torch.tensor([[1, 2], [3, 4]])
  11721. >>> torch.gather(t, 1, torch.tensor([[0, 0], [1, 0]]))
  11722. tensor([[ 1, 1],
  11723. [ 4, 3]])
  11724. """
  11725. @overload
  11726. def gather(
  11727. input: Tensor,
  11728. dim: str | EllipsisType | None,
  11729. index: Tensor,
  11730. *,
  11731. sparse_grad: _bool = False,
  11732. out: Tensor | None = None,
  11733. ) -> Tensor:
  11734. r"""
  11735. gather(input, dim, index, *, sparse_grad=False, out=None) -> Tensor
  11736. Gathers values along an axis specified by `dim`.
  11737. For a 3-D tensor the output is specified by::
  11738. out[i][j][k] = input[index[i][j][k]][j][k] # if dim == 0
  11739. out[i][j][k] = input[i][index[i][j][k]][k] # if dim == 1
  11740. out[i][j][k] = input[i][j][index[i][j][k]] # if dim == 2
  11741. :attr:`input` and :attr:`index` must have the same number of dimensions.
  11742. It is also required that ``index.size(d) <= input.size(d)`` for all
  11743. dimensions ``d != dim``. :attr:`out` will have the same shape as :attr:`index`.
  11744. Note that ``input`` and ``index`` do not broadcast against each other.
  11745. When :attr:`index` is empty, we always return an empty output with the same shape
  11746. without further error checking.
  11747. Args:
  11748. input (Tensor): the source tensor
  11749. dim (int): the axis along which to index
  11750. index (LongTensor): the indices of elements to gather
  11751. Keyword arguments:
  11752. sparse_grad (bool, optional): If ``True``, gradient w.r.t. :attr:`input` will be a sparse tensor.
  11753. out (Tensor, optional): the destination tensor
  11754. Example::
  11755. >>> t = torch.tensor([[1, 2], [3, 4]])
  11756. >>> torch.gather(t, 1, torch.tensor([[0, 0], [1, 0]]))
  11757. tensor([[ 1, 1],
  11758. [ 4, 3]])
  11759. """
  11760. def gcd(
  11761. input: Tensor,
  11762. other: Tensor,
  11763. *,
  11764. out: Tensor | None = None,
  11765. ) -> Tensor:
  11766. r"""
  11767. gcd(input, other, *, out=None) -> Tensor
  11768. Computes the element-wise greatest common divisor (GCD) of :attr:`input` and :attr:`other`.
  11769. Both :attr:`input` and :attr:`other` must have integer types.
  11770. .. note::
  11771. This defines :math:`gcd(0, 0) = 0`.
  11772. Args:
  11773. input (Tensor): the input tensor.
  11774. other (Tensor): the second input tensor
  11775. Keyword arguments:
  11776. out (Tensor, optional): the output tensor.
  11777. Example::
  11778. >>> a = torch.tensor([5, 10, 15])
  11779. >>> b = torch.tensor([3, 4, 5])
  11780. >>> torch.gcd(a, b)
  11781. tensor([1, 2, 5])
  11782. >>> c = torch.tensor([3])
  11783. >>> torch.gcd(a, c)
  11784. tensor([1, 1, 3])
  11785. """
  11786. def gcd_(input: Tensor, other: Tensor) -> Tensor: ...
  11787. @overload
  11788. def ge(
  11789. input: Tensor,
  11790. other: Tensor,
  11791. *,
  11792. out: Tensor | None = None,
  11793. ) -> Tensor:
  11794. r"""
  11795. ge(input, other, *, out=None) -> Tensor
  11796. Computes :math:`\text{input} \geq \text{other}` element-wise.
  11797. The second argument can be a number or a tensor whose shape is
  11798. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  11799. Args:
  11800. input (Tensor): the tensor to compare
  11801. other (Tensor or float): the tensor or value to compare
  11802. Keyword args:
  11803. out (Tensor, optional): the output tensor.
  11804. Returns:
  11805. A boolean tensor that is True where :attr:`input` is greater than or equal to :attr:`other` and False elsewhere
  11806. Example::
  11807. >>> torch.ge(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  11808. tensor([[True, True], [False, True]])
  11809. """
  11810. @overload
  11811. def ge(
  11812. input: Tensor,
  11813. other: Number | _complex,
  11814. *,
  11815. out: Tensor | None = None,
  11816. ) -> Tensor:
  11817. r"""
  11818. ge(input, other, *, out=None) -> Tensor
  11819. Computes :math:`\text{input} \geq \text{other}` element-wise.
  11820. The second argument can be a number or a tensor whose shape is
  11821. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  11822. Args:
  11823. input (Tensor): the tensor to compare
  11824. other (Tensor or float): the tensor or value to compare
  11825. Keyword args:
  11826. out (Tensor, optional): the output tensor.
  11827. Returns:
  11828. A boolean tensor that is True where :attr:`input` is greater than or equal to :attr:`other` and False elsewhere
  11829. Example::
  11830. >>> torch.ge(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  11831. tensor([[True, True], [False, True]])
  11832. """
  11833. def geqrf(
  11834. input: Tensor,
  11835. *,
  11836. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  11837. ) -> torch.return_types.geqrf:
  11838. r"""
  11839. geqrf(input, *, out=None) -> (Tensor, Tensor)
  11840. This is a low-level function for calling LAPACK's geqrf directly. This function
  11841. returns a namedtuple (a, tau) as defined in `LAPACK documentation for geqrf`_ .
  11842. Computes a QR decomposition of :attr:`input`.
  11843. Both `Q` and `R` matrices are stored in the same output tensor `a`.
  11844. The elements of `R` are stored on and above the diagonal.
  11845. Elementary reflectors (or Householder vectors) implicitly defining matrix `Q`
  11846. are stored below the diagonal.
  11847. The results of this function can be used together with :func:`torch.linalg.householder_product`
  11848. to obtain the `Q` matrix or
  11849. with :func:`torch.ormqr`, which uses an implicit representation of the `Q` matrix,
  11850. for an efficient matrix-matrix multiplication.
  11851. See `LAPACK documentation for geqrf`_ for further details.
  11852. .. note::
  11853. See also :func:`torch.linalg.qr`, which computes Q and R matrices, and :func:`torch.linalg.lstsq`
  11854. with the ``driver="gels"`` option for a function that can solve matrix equations using a QR decomposition.
  11855. Args:
  11856. input (Tensor): the input matrix
  11857. Keyword args:
  11858. out (tuple, optional): the output tuple of (Tensor, Tensor). Ignored if `None`. Default: `None`.
  11859. .. _LAPACK documentation for geqrf:
  11860. http://www.netlib.org/lapack/explore-html/df/dc5/group__variants_g_ecomputational_ga3766ea903391b5cf9008132f7440ec7b.html
  11861. """
  11862. def ger(
  11863. input: Tensor,
  11864. vec2: Tensor,
  11865. *,
  11866. out: Tensor | None = None,
  11867. ) -> Tensor:
  11868. r"""
  11869. ger(input, vec2, *, out=None) -> Tensor
  11870. Alias of :func:`torch.outer`.
  11871. .. warning::
  11872. This function is deprecated and will be removed in a future PyTorch release.
  11873. Use :func:`torch.outer` instead.
  11874. """
  11875. def get_default_dtype() -> _dtype:
  11876. r"""
  11877. get_default_dtype() -> torch.dtype
  11878. Get the current default floating point :class:`torch.dtype`.
  11879. Example::
  11880. >>> torch.get_default_dtype() # initial default for floating point is torch.float32
  11881. torch.float32
  11882. >>> torch.set_default_dtype(torch.float64)
  11883. >>> torch.get_default_dtype() # default is now changed to torch.float64
  11884. torch.float64
  11885. """
  11886. def get_num_interop_threads() -> _int:
  11887. r"""
  11888. get_num_interop_threads() -> int
  11889. Returns the number of threads used for inter-op parallelism on CPU
  11890. (e.g. in JIT interpreter)
  11891. """
  11892. def get_num_threads() -> _int:
  11893. r"""
  11894. get_num_threads() -> int
  11895. Returns the number of threads used for parallelizing CPU operations
  11896. """
  11897. @overload
  11898. def gradient(
  11899. input: Tensor,
  11900. *,
  11901. spacing: Number | _complex | None = None,
  11902. dim: _int | None = None,
  11903. edge_order: _int = 1,
  11904. ) -> tuple[Tensor, ...]:
  11905. r"""
  11906. gradient(input, *, spacing=1, dim=None, edge_order=1) -> List of Tensors
  11907. Estimates the gradient of a function :math:`g : \mathbb{R}^n \rightarrow \mathbb{R}` in
  11908. one or more dimensions using the `second-order accurate central differences method
  11909. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ and
  11910. either first or second order estimates at the boundaries.
  11911. The gradient of :math:`g` is estimated using samples. By default, when :attr:`spacing` is not
  11912. specified, the samples are entirely described by :attr:`input`, and the mapping of input coordinates
  11913. to an output is the same as the tensor's mapping of indices to values. For example, for a three-dimensional
  11914. :attr:`input` the function described is :math:`g : \mathbb{R}^3 \rightarrow \mathbb{R}`, and
  11915. :math:`g(1, 2, 3)\ == input[1, 2, 3]`.
  11916. When :attr:`spacing` is specified, it modifies the relationship between :attr:`input` and input coordinates.
  11917. This is detailed in the "Keyword Arguments" section below.
  11918. The gradient is estimated by estimating each partial derivative of :math:`g` independently. This estimation is
  11919. accurate if :math:`g` is in :math:`C^3` (it has at least 3 continuous derivatives), and the estimation can be
  11920. improved by providing closer samples. Mathematically, the value at each interior point of a partial derivative
  11921. is estimated using `Taylor's theorem with remainder <https://en.wikipedia.org/wiki/Taylor%27s_theorem>`_.
  11922. Letting :math:`x` be an interior point with :math:`x-h_l` and :math:`x+h_r` be points neighboring
  11923. it to the left and right respectively, :math:`f(x+h_r)` and :math:`f(x-h_l)` can be estimated using:
  11924. .. math::
  11925. \begin{aligned}
  11926. f(x+h_r) = f(x) + h_r f'(x) + {h_r}^2 \frac{f''(x)}{2} + {h_r}^3 \frac{f'''(\xi_1)}{6}, \xi_1 \in (x, x+h_r) \\
  11927. f(x-h_l) = f(x) - h_l f'(x) + {h_l}^2 \frac{f''(x)}{2} - {h_l}^3 \frac{f'''(\xi_2)}{6}, \xi_2 \in (x, x-h_l) \\
  11928. \end{aligned}
  11929. Using the fact that :math:`f \in C^3` and solving the linear system, we derive:
  11930. .. math::
  11931. f'(x) \approx \frac{ {h_l}^2 f(x+h_r) - {h_r}^2 f(x-h_l)
  11932. + ({h_r}^2-{h_l}^2 ) f(x) }{ {h_r} {h_l}^2 + {h_r}^2 {h_l} }
  11933. .. note::
  11934. We estimate the gradient of functions in complex domain
  11935. :math:`g : \mathbb{C}^n \rightarrow \mathbb{C}` in the same way.
  11936. The value of each partial derivative at the boundary points is computed differently. See edge_order below.
  11937. Args:
  11938. input (``Tensor``): the tensor that represents the values of the function
  11939. Keyword args:
  11940. spacing (``scalar``, ``list of scalar``, ``list of Tensor``, optional): :attr:`spacing` can be used to modify
  11941. how the :attr:`input` tensor's indices relate to sample coordinates. If :attr:`spacing` is a scalar then
  11942. the indices are multiplied by the scalar to produce the coordinates. For example, if :attr:`spacing=2` the
  11943. indices (1, 2, 3) become coordinates (2, 4, 6). If :attr:`spacing` is a list of scalars then the corresponding
  11944. indices are multiplied. For example, if :attr:`spacing=(2, -1, 3)` the indices (1, 2, 3) become coordinates (2, -2, 9).
  11945. Finally, if :attr:`spacing` is a list of one-dimensional tensors then each tensor specifies the coordinates for
  11946. the corresponding dimension. For example, if the indices are (1, 2, 3) and the tensors are (t0, t1, t2), then
  11947. the coordinates are (t0[1], t1[2], t2[3])
  11948. dim (``int``, ``list of int``, optional): the dimension or dimensions to approximate the gradient over. By default
  11949. the partial gradient in every dimension is computed. Note that when :attr:`dim` is specified the elements of
  11950. the :attr:`spacing` argument must correspond with the specified dims."
  11951. edge_order (``int``, optional): 1 or 2, for `first-order
  11952. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ or
  11953. `second-order <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_
  11954. estimation of the boundary ("edge") values, respectively. Note that when :attr:`edge_order` is specified, each
  11955. dimension size of :attr:`input` should be at least edge_order+1
  11956. Examples::
  11957. >>> # Estimates the gradient of f(x)=x^2 at points [-2, -1, 2, 4]
  11958. >>> coordinates = (torch.tensor([-2., -1., 1., 4.]),)
  11959. >>> values = torch.tensor([4., 1., 1., 16.], )
  11960. >>> torch.gradient(values, spacing = coordinates)
  11961. (tensor([-3., -2., 2., 5.]),)
  11962. >>> # Estimates the gradient of the R^2 -> R function whose samples are
  11963. >>> # described by the tensor t. Implicit coordinates are [0, 1] for the outermost
  11964. >>> # dimension and [0, 1, 2, 3] for the innermost dimension, and function estimates
  11965. >>> # partial derivative for both dimensions.
  11966. >>> t = torch.tensor([[1, 2, 4, 8], [10, 20, 40, 80]])
  11967. >>> torch.gradient(t)
  11968. (tensor([[ 9., 18., 36., 72.],
  11969. [ 9., 18., 36., 72.]]),
  11970. tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  11971. [10.0000, 15.0000, 30.0000, 40.0000]]))
  11972. >>> # A scalar value for spacing modifies the relationship between tensor indices
  11973. >>> # and input coordinates by multiplying the indices to find the
  11974. >>> # coordinates. For example, below the indices of the innermost
  11975. >>> # 0, 1, 2, 3 translate to coordinates of [0, 2, 4, 6], and the indices of
  11976. >>> # the outermost dimension 0, 1 translate to coordinates of [0, 2].
  11977. >>> torch.gradient(t, spacing = 2.0) # dim = None (implicitly [0, 1])
  11978. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  11979. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  11980. tensor([[ 0.5000, 0.7500, 1.5000, 2.0000],
  11981. [ 5.0000, 7.5000, 15.0000, 20.0000]]))
  11982. >>> # doubling the spacing between samples halves the estimated partial gradients.
  11983. >>>
  11984. >>> # Estimates only the partial derivative for dimension 1
  11985. >>> torch.gradient(t, dim = 1) # spacing = None (implicitly 1.)
  11986. (tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  11987. [10.0000, 15.0000, 30.0000, 40.0000]]),)
  11988. >>> # When spacing is a list of scalars, the relationship between the tensor
  11989. >>> # indices and input coordinates changes based on dimension.
  11990. >>> # For example, below, the indices of the innermost dimension 0, 1, 2, 3 translate
  11991. >>> # to coordinates of [0, 3, 6, 9], and the indices of the outermost dimension
  11992. >>> # 0, 1 translate to coordinates of [0, 2].
  11993. >>> torch.gradient(t, spacing = [3., 2.])
  11994. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  11995. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  11996. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  11997. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  11998. >>> # The following example is a replication of the previous one with explicit
  11999. >>> # coordinates.
  12000. >>> coords = (torch.tensor([0, 2]), torch.tensor([0, 3, 6, 9]))
  12001. >>> torch.gradient(t, spacing = coords)
  12002. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12003. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12004. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12005. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12006. """
  12007. @overload
  12008. def gradient(
  12009. input: Tensor,
  12010. *,
  12011. spacing: Sequence[Number | _complex],
  12012. dim: _int | None = None,
  12013. edge_order: _int = 1,
  12014. ) -> tuple[Tensor, ...]:
  12015. r"""
  12016. gradient(input, *, spacing=1, dim=None, edge_order=1) -> List of Tensors
  12017. Estimates the gradient of a function :math:`g : \mathbb{R}^n \rightarrow \mathbb{R}` in
  12018. one or more dimensions using the `second-order accurate central differences method
  12019. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ and
  12020. either first or second order estimates at the boundaries.
  12021. The gradient of :math:`g` is estimated using samples. By default, when :attr:`spacing` is not
  12022. specified, the samples are entirely described by :attr:`input`, and the mapping of input coordinates
  12023. to an output is the same as the tensor's mapping of indices to values. For example, for a three-dimensional
  12024. :attr:`input` the function described is :math:`g : \mathbb{R}^3 \rightarrow \mathbb{R}`, and
  12025. :math:`g(1, 2, 3)\ == input[1, 2, 3]`.
  12026. When :attr:`spacing` is specified, it modifies the relationship between :attr:`input` and input coordinates.
  12027. This is detailed in the "Keyword Arguments" section below.
  12028. The gradient is estimated by estimating each partial derivative of :math:`g` independently. This estimation is
  12029. accurate if :math:`g` is in :math:`C^3` (it has at least 3 continuous derivatives), and the estimation can be
  12030. improved by providing closer samples. Mathematically, the value at each interior point of a partial derivative
  12031. is estimated using `Taylor's theorem with remainder <https://en.wikipedia.org/wiki/Taylor%27s_theorem>`_.
  12032. Letting :math:`x` be an interior point with :math:`x-h_l` and :math:`x+h_r` be points neighboring
  12033. it to the left and right respectively, :math:`f(x+h_r)` and :math:`f(x-h_l)` can be estimated using:
  12034. .. math::
  12035. \begin{aligned}
  12036. f(x+h_r) = f(x) + h_r f'(x) + {h_r}^2 \frac{f''(x)}{2} + {h_r}^3 \frac{f'''(\xi_1)}{6}, \xi_1 \in (x, x+h_r) \\
  12037. f(x-h_l) = f(x) - h_l f'(x) + {h_l}^2 \frac{f''(x)}{2} - {h_l}^3 \frac{f'''(\xi_2)}{6}, \xi_2 \in (x, x-h_l) \\
  12038. \end{aligned}
  12039. Using the fact that :math:`f \in C^3` and solving the linear system, we derive:
  12040. .. math::
  12041. f'(x) \approx \frac{ {h_l}^2 f(x+h_r) - {h_r}^2 f(x-h_l)
  12042. + ({h_r}^2-{h_l}^2 ) f(x) }{ {h_r} {h_l}^2 + {h_r}^2 {h_l} }
  12043. .. note::
  12044. We estimate the gradient of functions in complex domain
  12045. :math:`g : \mathbb{C}^n \rightarrow \mathbb{C}` in the same way.
  12046. The value of each partial derivative at the boundary points is computed differently. See edge_order below.
  12047. Args:
  12048. input (``Tensor``): the tensor that represents the values of the function
  12049. Keyword args:
  12050. spacing (``scalar``, ``list of scalar``, ``list of Tensor``, optional): :attr:`spacing` can be used to modify
  12051. how the :attr:`input` tensor's indices relate to sample coordinates. If :attr:`spacing` is a scalar then
  12052. the indices are multiplied by the scalar to produce the coordinates. For example, if :attr:`spacing=2` the
  12053. indices (1, 2, 3) become coordinates (2, 4, 6). If :attr:`spacing` is a list of scalars then the corresponding
  12054. indices are multiplied. For example, if :attr:`spacing=(2, -1, 3)` the indices (1, 2, 3) become coordinates (2, -2, 9).
  12055. Finally, if :attr:`spacing` is a list of one-dimensional tensors then each tensor specifies the coordinates for
  12056. the corresponding dimension. For example, if the indices are (1, 2, 3) and the tensors are (t0, t1, t2), then
  12057. the coordinates are (t0[1], t1[2], t2[3])
  12058. dim (``int``, ``list of int``, optional): the dimension or dimensions to approximate the gradient over. By default
  12059. the partial gradient in every dimension is computed. Note that when :attr:`dim` is specified the elements of
  12060. the :attr:`spacing` argument must correspond with the specified dims."
  12061. edge_order (``int``, optional): 1 or 2, for `first-order
  12062. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ or
  12063. `second-order <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_
  12064. estimation of the boundary ("edge") values, respectively. Note that when :attr:`edge_order` is specified, each
  12065. dimension size of :attr:`input` should be at least edge_order+1
  12066. Examples::
  12067. >>> # Estimates the gradient of f(x)=x^2 at points [-2, -1, 2, 4]
  12068. >>> coordinates = (torch.tensor([-2., -1., 1., 4.]),)
  12069. >>> values = torch.tensor([4., 1., 1., 16.], )
  12070. >>> torch.gradient(values, spacing = coordinates)
  12071. (tensor([-3., -2., 2., 5.]),)
  12072. >>> # Estimates the gradient of the R^2 -> R function whose samples are
  12073. >>> # described by the tensor t. Implicit coordinates are [0, 1] for the outermost
  12074. >>> # dimension and [0, 1, 2, 3] for the innermost dimension, and function estimates
  12075. >>> # partial derivative for both dimensions.
  12076. >>> t = torch.tensor([[1, 2, 4, 8], [10, 20, 40, 80]])
  12077. >>> torch.gradient(t)
  12078. (tensor([[ 9., 18., 36., 72.],
  12079. [ 9., 18., 36., 72.]]),
  12080. tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12081. [10.0000, 15.0000, 30.0000, 40.0000]]))
  12082. >>> # A scalar value for spacing modifies the relationship between tensor indices
  12083. >>> # and input coordinates by multiplying the indices to find the
  12084. >>> # coordinates. For example, below the indices of the innermost
  12085. >>> # 0, 1, 2, 3 translate to coordinates of [0, 2, 4, 6], and the indices of
  12086. >>> # the outermost dimension 0, 1 translate to coordinates of [0, 2].
  12087. >>> torch.gradient(t, spacing = 2.0) # dim = None (implicitly [0, 1])
  12088. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12089. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12090. tensor([[ 0.5000, 0.7500, 1.5000, 2.0000],
  12091. [ 5.0000, 7.5000, 15.0000, 20.0000]]))
  12092. >>> # doubling the spacing between samples halves the estimated partial gradients.
  12093. >>>
  12094. >>> # Estimates only the partial derivative for dimension 1
  12095. >>> torch.gradient(t, dim = 1) # spacing = None (implicitly 1.)
  12096. (tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12097. [10.0000, 15.0000, 30.0000, 40.0000]]),)
  12098. >>> # When spacing is a list of scalars, the relationship between the tensor
  12099. >>> # indices and input coordinates changes based on dimension.
  12100. >>> # For example, below, the indices of the innermost dimension 0, 1, 2, 3 translate
  12101. >>> # to coordinates of [0, 3, 6, 9], and the indices of the outermost dimension
  12102. >>> # 0, 1 translate to coordinates of [0, 2].
  12103. >>> torch.gradient(t, spacing = [3., 2.])
  12104. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12105. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12106. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12107. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12108. >>> # The following example is a replication of the previous one with explicit
  12109. >>> # coordinates.
  12110. >>> coords = (torch.tensor([0, 2]), torch.tensor([0, 3, 6, 9]))
  12111. >>> torch.gradient(t, spacing = coords)
  12112. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12113. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12114. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12115. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12116. """
  12117. @overload
  12118. def gradient(
  12119. input: Tensor,
  12120. *,
  12121. spacing: Sequence[Number | _complex],
  12122. dim: _size,
  12123. edge_order: _int = 1,
  12124. ) -> tuple[Tensor, ...]:
  12125. r"""
  12126. gradient(input, *, spacing=1, dim=None, edge_order=1) -> List of Tensors
  12127. Estimates the gradient of a function :math:`g : \mathbb{R}^n \rightarrow \mathbb{R}` in
  12128. one or more dimensions using the `second-order accurate central differences method
  12129. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ and
  12130. either first or second order estimates at the boundaries.
  12131. The gradient of :math:`g` is estimated using samples. By default, when :attr:`spacing` is not
  12132. specified, the samples are entirely described by :attr:`input`, and the mapping of input coordinates
  12133. to an output is the same as the tensor's mapping of indices to values. For example, for a three-dimensional
  12134. :attr:`input` the function described is :math:`g : \mathbb{R}^3 \rightarrow \mathbb{R}`, and
  12135. :math:`g(1, 2, 3)\ == input[1, 2, 3]`.
  12136. When :attr:`spacing` is specified, it modifies the relationship between :attr:`input` and input coordinates.
  12137. This is detailed in the "Keyword Arguments" section below.
  12138. The gradient is estimated by estimating each partial derivative of :math:`g` independently. This estimation is
  12139. accurate if :math:`g` is in :math:`C^3` (it has at least 3 continuous derivatives), and the estimation can be
  12140. improved by providing closer samples. Mathematically, the value at each interior point of a partial derivative
  12141. is estimated using `Taylor's theorem with remainder <https://en.wikipedia.org/wiki/Taylor%27s_theorem>`_.
  12142. Letting :math:`x` be an interior point with :math:`x-h_l` and :math:`x+h_r` be points neighboring
  12143. it to the left and right respectively, :math:`f(x+h_r)` and :math:`f(x-h_l)` can be estimated using:
  12144. .. math::
  12145. \begin{aligned}
  12146. f(x+h_r) = f(x) + h_r f'(x) + {h_r}^2 \frac{f''(x)}{2} + {h_r}^3 \frac{f'''(\xi_1)}{6}, \xi_1 \in (x, x+h_r) \\
  12147. f(x-h_l) = f(x) - h_l f'(x) + {h_l}^2 \frac{f''(x)}{2} - {h_l}^3 \frac{f'''(\xi_2)}{6}, \xi_2 \in (x, x-h_l) \\
  12148. \end{aligned}
  12149. Using the fact that :math:`f \in C^3` and solving the linear system, we derive:
  12150. .. math::
  12151. f'(x) \approx \frac{ {h_l}^2 f(x+h_r) - {h_r}^2 f(x-h_l)
  12152. + ({h_r}^2-{h_l}^2 ) f(x) }{ {h_r} {h_l}^2 + {h_r}^2 {h_l} }
  12153. .. note::
  12154. We estimate the gradient of functions in complex domain
  12155. :math:`g : \mathbb{C}^n \rightarrow \mathbb{C}` in the same way.
  12156. The value of each partial derivative at the boundary points is computed differently. See edge_order below.
  12157. Args:
  12158. input (``Tensor``): the tensor that represents the values of the function
  12159. Keyword args:
  12160. spacing (``scalar``, ``list of scalar``, ``list of Tensor``, optional): :attr:`spacing` can be used to modify
  12161. how the :attr:`input` tensor's indices relate to sample coordinates. If :attr:`spacing` is a scalar then
  12162. the indices are multiplied by the scalar to produce the coordinates. For example, if :attr:`spacing=2` the
  12163. indices (1, 2, 3) become coordinates (2, 4, 6). If :attr:`spacing` is a list of scalars then the corresponding
  12164. indices are multiplied. For example, if :attr:`spacing=(2, -1, 3)` the indices (1, 2, 3) become coordinates (2, -2, 9).
  12165. Finally, if :attr:`spacing` is a list of one-dimensional tensors then each tensor specifies the coordinates for
  12166. the corresponding dimension. For example, if the indices are (1, 2, 3) and the tensors are (t0, t1, t2), then
  12167. the coordinates are (t0[1], t1[2], t2[3])
  12168. dim (``int``, ``list of int``, optional): the dimension or dimensions to approximate the gradient over. By default
  12169. the partial gradient in every dimension is computed. Note that when :attr:`dim` is specified the elements of
  12170. the :attr:`spacing` argument must correspond with the specified dims."
  12171. edge_order (``int``, optional): 1 or 2, for `first-order
  12172. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ or
  12173. `second-order <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_
  12174. estimation of the boundary ("edge") values, respectively. Note that when :attr:`edge_order` is specified, each
  12175. dimension size of :attr:`input` should be at least edge_order+1
  12176. Examples::
  12177. >>> # Estimates the gradient of f(x)=x^2 at points [-2, -1, 2, 4]
  12178. >>> coordinates = (torch.tensor([-2., -1., 1., 4.]),)
  12179. >>> values = torch.tensor([4., 1., 1., 16.], )
  12180. >>> torch.gradient(values, spacing = coordinates)
  12181. (tensor([-3., -2., 2., 5.]),)
  12182. >>> # Estimates the gradient of the R^2 -> R function whose samples are
  12183. >>> # described by the tensor t. Implicit coordinates are [0, 1] for the outermost
  12184. >>> # dimension and [0, 1, 2, 3] for the innermost dimension, and function estimates
  12185. >>> # partial derivative for both dimensions.
  12186. >>> t = torch.tensor([[1, 2, 4, 8], [10, 20, 40, 80]])
  12187. >>> torch.gradient(t)
  12188. (tensor([[ 9., 18., 36., 72.],
  12189. [ 9., 18., 36., 72.]]),
  12190. tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12191. [10.0000, 15.0000, 30.0000, 40.0000]]))
  12192. >>> # A scalar value for spacing modifies the relationship between tensor indices
  12193. >>> # and input coordinates by multiplying the indices to find the
  12194. >>> # coordinates. For example, below the indices of the innermost
  12195. >>> # 0, 1, 2, 3 translate to coordinates of [0, 2, 4, 6], and the indices of
  12196. >>> # the outermost dimension 0, 1 translate to coordinates of [0, 2].
  12197. >>> torch.gradient(t, spacing = 2.0) # dim = None (implicitly [0, 1])
  12198. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12199. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12200. tensor([[ 0.5000, 0.7500, 1.5000, 2.0000],
  12201. [ 5.0000, 7.5000, 15.0000, 20.0000]]))
  12202. >>> # doubling the spacing between samples halves the estimated partial gradients.
  12203. >>>
  12204. >>> # Estimates only the partial derivative for dimension 1
  12205. >>> torch.gradient(t, dim = 1) # spacing = None (implicitly 1.)
  12206. (tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12207. [10.0000, 15.0000, 30.0000, 40.0000]]),)
  12208. >>> # When spacing is a list of scalars, the relationship between the tensor
  12209. >>> # indices and input coordinates changes based on dimension.
  12210. >>> # For example, below, the indices of the innermost dimension 0, 1, 2, 3 translate
  12211. >>> # to coordinates of [0, 3, 6, 9], and the indices of the outermost dimension
  12212. >>> # 0, 1 translate to coordinates of [0, 2].
  12213. >>> torch.gradient(t, spacing = [3., 2.])
  12214. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12215. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12216. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12217. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12218. >>> # The following example is a replication of the previous one with explicit
  12219. >>> # coordinates.
  12220. >>> coords = (torch.tensor([0, 2]), torch.tensor([0, 3, 6, 9]))
  12221. >>> torch.gradient(t, spacing = coords)
  12222. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12223. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12224. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12225. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12226. """
  12227. @overload
  12228. def gradient(
  12229. input: Tensor,
  12230. *,
  12231. spacing: tuple[Tensor, ...] | list[Tensor] | None,
  12232. dim: _int | None = None,
  12233. edge_order: _int = 1,
  12234. ) -> tuple[Tensor, ...]:
  12235. r"""
  12236. gradient(input, *, spacing=1, dim=None, edge_order=1) -> List of Tensors
  12237. Estimates the gradient of a function :math:`g : \mathbb{R}^n \rightarrow \mathbb{R}` in
  12238. one or more dimensions using the `second-order accurate central differences method
  12239. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ and
  12240. either first or second order estimates at the boundaries.
  12241. The gradient of :math:`g` is estimated using samples. By default, when :attr:`spacing` is not
  12242. specified, the samples are entirely described by :attr:`input`, and the mapping of input coordinates
  12243. to an output is the same as the tensor's mapping of indices to values. For example, for a three-dimensional
  12244. :attr:`input` the function described is :math:`g : \mathbb{R}^3 \rightarrow \mathbb{R}`, and
  12245. :math:`g(1, 2, 3)\ == input[1, 2, 3]`.
  12246. When :attr:`spacing` is specified, it modifies the relationship between :attr:`input` and input coordinates.
  12247. This is detailed in the "Keyword Arguments" section below.
  12248. The gradient is estimated by estimating each partial derivative of :math:`g` independently. This estimation is
  12249. accurate if :math:`g` is in :math:`C^3` (it has at least 3 continuous derivatives), and the estimation can be
  12250. improved by providing closer samples. Mathematically, the value at each interior point of a partial derivative
  12251. is estimated using `Taylor's theorem with remainder <https://en.wikipedia.org/wiki/Taylor%27s_theorem>`_.
  12252. Letting :math:`x` be an interior point with :math:`x-h_l` and :math:`x+h_r` be points neighboring
  12253. it to the left and right respectively, :math:`f(x+h_r)` and :math:`f(x-h_l)` can be estimated using:
  12254. .. math::
  12255. \begin{aligned}
  12256. f(x+h_r) = f(x) + h_r f'(x) + {h_r}^2 \frac{f''(x)}{2} + {h_r}^3 \frac{f'''(\xi_1)}{6}, \xi_1 \in (x, x+h_r) \\
  12257. f(x-h_l) = f(x) - h_l f'(x) + {h_l}^2 \frac{f''(x)}{2} - {h_l}^3 \frac{f'''(\xi_2)}{6}, \xi_2 \in (x, x-h_l) \\
  12258. \end{aligned}
  12259. Using the fact that :math:`f \in C^3` and solving the linear system, we derive:
  12260. .. math::
  12261. f'(x) \approx \frac{ {h_l}^2 f(x+h_r) - {h_r}^2 f(x-h_l)
  12262. + ({h_r}^2-{h_l}^2 ) f(x) }{ {h_r} {h_l}^2 + {h_r}^2 {h_l} }
  12263. .. note::
  12264. We estimate the gradient of functions in complex domain
  12265. :math:`g : \mathbb{C}^n \rightarrow \mathbb{C}` in the same way.
  12266. The value of each partial derivative at the boundary points is computed differently. See edge_order below.
  12267. Args:
  12268. input (``Tensor``): the tensor that represents the values of the function
  12269. Keyword args:
  12270. spacing (``scalar``, ``list of scalar``, ``list of Tensor``, optional): :attr:`spacing` can be used to modify
  12271. how the :attr:`input` tensor's indices relate to sample coordinates. If :attr:`spacing` is a scalar then
  12272. the indices are multiplied by the scalar to produce the coordinates. For example, if :attr:`spacing=2` the
  12273. indices (1, 2, 3) become coordinates (2, 4, 6). If :attr:`spacing` is a list of scalars then the corresponding
  12274. indices are multiplied. For example, if :attr:`spacing=(2, -1, 3)` the indices (1, 2, 3) become coordinates (2, -2, 9).
  12275. Finally, if :attr:`spacing` is a list of one-dimensional tensors then each tensor specifies the coordinates for
  12276. the corresponding dimension. For example, if the indices are (1, 2, 3) and the tensors are (t0, t1, t2), then
  12277. the coordinates are (t0[1], t1[2], t2[3])
  12278. dim (``int``, ``list of int``, optional): the dimension or dimensions to approximate the gradient over. By default
  12279. the partial gradient in every dimension is computed. Note that when :attr:`dim` is specified the elements of
  12280. the :attr:`spacing` argument must correspond with the specified dims."
  12281. edge_order (``int``, optional): 1 or 2, for `first-order
  12282. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ or
  12283. `second-order <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_
  12284. estimation of the boundary ("edge") values, respectively. Note that when :attr:`edge_order` is specified, each
  12285. dimension size of :attr:`input` should be at least edge_order+1
  12286. Examples::
  12287. >>> # Estimates the gradient of f(x)=x^2 at points [-2, -1, 2, 4]
  12288. >>> coordinates = (torch.tensor([-2., -1., 1., 4.]),)
  12289. >>> values = torch.tensor([4., 1., 1., 16.], )
  12290. >>> torch.gradient(values, spacing = coordinates)
  12291. (tensor([-3., -2., 2., 5.]),)
  12292. >>> # Estimates the gradient of the R^2 -> R function whose samples are
  12293. >>> # described by the tensor t. Implicit coordinates are [0, 1] for the outermost
  12294. >>> # dimension and [0, 1, 2, 3] for the innermost dimension, and function estimates
  12295. >>> # partial derivative for both dimensions.
  12296. >>> t = torch.tensor([[1, 2, 4, 8], [10, 20, 40, 80]])
  12297. >>> torch.gradient(t)
  12298. (tensor([[ 9., 18., 36., 72.],
  12299. [ 9., 18., 36., 72.]]),
  12300. tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12301. [10.0000, 15.0000, 30.0000, 40.0000]]))
  12302. >>> # A scalar value for spacing modifies the relationship between tensor indices
  12303. >>> # and input coordinates by multiplying the indices to find the
  12304. >>> # coordinates. For example, below the indices of the innermost
  12305. >>> # 0, 1, 2, 3 translate to coordinates of [0, 2, 4, 6], and the indices of
  12306. >>> # the outermost dimension 0, 1 translate to coordinates of [0, 2].
  12307. >>> torch.gradient(t, spacing = 2.0) # dim = None (implicitly [0, 1])
  12308. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12309. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12310. tensor([[ 0.5000, 0.7500, 1.5000, 2.0000],
  12311. [ 5.0000, 7.5000, 15.0000, 20.0000]]))
  12312. >>> # doubling the spacing between samples halves the estimated partial gradients.
  12313. >>>
  12314. >>> # Estimates only the partial derivative for dimension 1
  12315. >>> torch.gradient(t, dim = 1) # spacing = None (implicitly 1.)
  12316. (tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12317. [10.0000, 15.0000, 30.0000, 40.0000]]),)
  12318. >>> # When spacing is a list of scalars, the relationship between the tensor
  12319. >>> # indices and input coordinates changes based on dimension.
  12320. >>> # For example, below, the indices of the innermost dimension 0, 1, 2, 3 translate
  12321. >>> # to coordinates of [0, 3, 6, 9], and the indices of the outermost dimension
  12322. >>> # 0, 1 translate to coordinates of [0, 2].
  12323. >>> torch.gradient(t, spacing = [3., 2.])
  12324. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12325. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12326. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12327. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12328. >>> # The following example is a replication of the previous one with explicit
  12329. >>> # coordinates.
  12330. >>> coords = (torch.tensor([0, 2]), torch.tensor([0, 3, 6, 9]))
  12331. >>> torch.gradient(t, spacing = coords)
  12332. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12333. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12334. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12335. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12336. """
  12337. @overload
  12338. def gradient(
  12339. input: Tensor,
  12340. *,
  12341. spacing: Number | _complex,
  12342. dim: _size,
  12343. edge_order: _int = 1,
  12344. ) -> tuple[Tensor, ...]:
  12345. r"""
  12346. gradient(input, *, spacing=1, dim=None, edge_order=1) -> List of Tensors
  12347. Estimates the gradient of a function :math:`g : \mathbb{R}^n \rightarrow \mathbb{R}` in
  12348. one or more dimensions using the `second-order accurate central differences method
  12349. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ and
  12350. either first or second order estimates at the boundaries.
  12351. The gradient of :math:`g` is estimated using samples. By default, when :attr:`spacing` is not
  12352. specified, the samples are entirely described by :attr:`input`, and the mapping of input coordinates
  12353. to an output is the same as the tensor's mapping of indices to values. For example, for a three-dimensional
  12354. :attr:`input` the function described is :math:`g : \mathbb{R}^3 \rightarrow \mathbb{R}`, and
  12355. :math:`g(1, 2, 3)\ == input[1, 2, 3]`.
  12356. When :attr:`spacing` is specified, it modifies the relationship between :attr:`input` and input coordinates.
  12357. This is detailed in the "Keyword Arguments" section below.
  12358. The gradient is estimated by estimating each partial derivative of :math:`g` independently. This estimation is
  12359. accurate if :math:`g` is in :math:`C^3` (it has at least 3 continuous derivatives), and the estimation can be
  12360. improved by providing closer samples. Mathematically, the value at each interior point of a partial derivative
  12361. is estimated using `Taylor's theorem with remainder <https://en.wikipedia.org/wiki/Taylor%27s_theorem>`_.
  12362. Letting :math:`x` be an interior point with :math:`x-h_l` and :math:`x+h_r` be points neighboring
  12363. it to the left and right respectively, :math:`f(x+h_r)` and :math:`f(x-h_l)` can be estimated using:
  12364. .. math::
  12365. \begin{aligned}
  12366. f(x+h_r) = f(x) + h_r f'(x) + {h_r}^2 \frac{f''(x)}{2} + {h_r}^3 \frac{f'''(\xi_1)}{6}, \xi_1 \in (x, x+h_r) \\
  12367. f(x-h_l) = f(x) - h_l f'(x) + {h_l}^2 \frac{f''(x)}{2} - {h_l}^3 \frac{f'''(\xi_2)}{6}, \xi_2 \in (x, x-h_l) \\
  12368. \end{aligned}
  12369. Using the fact that :math:`f \in C^3` and solving the linear system, we derive:
  12370. .. math::
  12371. f'(x) \approx \frac{ {h_l}^2 f(x+h_r) - {h_r}^2 f(x-h_l)
  12372. + ({h_r}^2-{h_l}^2 ) f(x) }{ {h_r} {h_l}^2 + {h_r}^2 {h_l} }
  12373. .. note::
  12374. We estimate the gradient of functions in complex domain
  12375. :math:`g : \mathbb{C}^n \rightarrow \mathbb{C}` in the same way.
  12376. The value of each partial derivative at the boundary points is computed differently. See edge_order below.
  12377. Args:
  12378. input (``Tensor``): the tensor that represents the values of the function
  12379. Keyword args:
  12380. spacing (``scalar``, ``list of scalar``, ``list of Tensor``, optional): :attr:`spacing` can be used to modify
  12381. how the :attr:`input` tensor's indices relate to sample coordinates. If :attr:`spacing` is a scalar then
  12382. the indices are multiplied by the scalar to produce the coordinates. For example, if :attr:`spacing=2` the
  12383. indices (1, 2, 3) become coordinates (2, 4, 6). If :attr:`spacing` is a list of scalars then the corresponding
  12384. indices are multiplied. For example, if :attr:`spacing=(2, -1, 3)` the indices (1, 2, 3) become coordinates (2, -2, 9).
  12385. Finally, if :attr:`spacing` is a list of one-dimensional tensors then each tensor specifies the coordinates for
  12386. the corresponding dimension. For example, if the indices are (1, 2, 3) and the tensors are (t0, t1, t2), then
  12387. the coordinates are (t0[1], t1[2], t2[3])
  12388. dim (``int``, ``list of int``, optional): the dimension or dimensions to approximate the gradient over. By default
  12389. the partial gradient in every dimension is computed. Note that when :attr:`dim` is specified the elements of
  12390. the :attr:`spacing` argument must correspond with the specified dims."
  12391. edge_order (``int``, optional): 1 or 2, for `first-order
  12392. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ or
  12393. `second-order <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_
  12394. estimation of the boundary ("edge") values, respectively. Note that when :attr:`edge_order` is specified, each
  12395. dimension size of :attr:`input` should be at least edge_order+1
  12396. Examples::
  12397. >>> # Estimates the gradient of f(x)=x^2 at points [-2, -1, 2, 4]
  12398. >>> coordinates = (torch.tensor([-2., -1., 1., 4.]),)
  12399. >>> values = torch.tensor([4., 1., 1., 16.], )
  12400. >>> torch.gradient(values, spacing = coordinates)
  12401. (tensor([-3., -2., 2., 5.]),)
  12402. >>> # Estimates the gradient of the R^2 -> R function whose samples are
  12403. >>> # described by the tensor t. Implicit coordinates are [0, 1] for the outermost
  12404. >>> # dimension and [0, 1, 2, 3] for the innermost dimension, and function estimates
  12405. >>> # partial derivative for both dimensions.
  12406. >>> t = torch.tensor([[1, 2, 4, 8], [10, 20, 40, 80]])
  12407. >>> torch.gradient(t)
  12408. (tensor([[ 9., 18., 36., 72.],
  12409. [ 9., 18., 36., 72.]]),
  12410. tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12411. [10.0000, 15.0000, 30.0000, 40.0000]]))
  12412. >>> # A scalar value for spacing modifies the relationship between tensor indices
  12413. >>> # and input coordinates by multiplying the indices to find the
  12414. >>> # coordinates. For example, below the indices of the innermost
  12415. >>> # 0, 1, 2, 3 translate to coordinates of [0, 2, 4, 6], and the indices of
  12416. >>> # the outermost dimension 0, 1 translate to coordinates of [0, 2].
  12417. >>> torch.gradient(t, spacing = 2.0) # dim = None (implicitly [0, 1])
  12418. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12419. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12420. tensor([[ 0.5000, 0.7500, 1.5000, 2.0000],
  12421. [ 5.0000, 7.5000, 15.0000, 20.0000]]))
  12422. >>> # doubling the spacing between samples halves the estimated partial gradients.
  12423. >>>
  12424. >>> # Estimates only the partial derivative for dimension 1
  12425. >>> torch.gradient(t, dim = 1) # spacing = None (implicitly 1.)
  12426. (tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12427. [10.0000, 15.0000, 30.0000, 40.0000]]),)
  12428. >>> # When spacing is a list of scalars, the relationship between the tensor
  12429. >>> # indices and input coordinates changes based on dimension.
  12430. >>> # For example, below, the indices of the innermost dimension 0, 1, 2, 3 translate
  12431. >>> # to coordinates of [0, 3, 6, 9], and the indices of the outermost dimension
  12432. >>> # 0, 1 translate to coordinates of [0, 2].
  12433. >>> torch.gradient(t, spacing = [3., 2.])
  12434. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12435. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12436. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12437. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12438. >>> # The following example is a replication of the previous one with explicit
  12439. >>> # coordinates.
  12440. >>> coords = (torch.tensor([0, 2]), torch.tensor([0, 3, 6, 9]))
  12441. >>> torch.gradient(t, spacing = coords)
  12442. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12443. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12444. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12445. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12446. """
  12447. @overload
  12448. def gradient(
  12449. input: Tensor,
  12450. *,
  12451. spacing: tuple[Tensor, ...] | list[Tensor] | None,
  12452. dim: _size,
  12453. edge_order: _int = 1,
  12454. ) -> tuple[Tensor, ...]:
  12455. r"""
  12456. gradient(input, *, spacing=1, dim=None, edge_order=1) -> List of Tensors
  12457. Estimates the gradient of a function :math:`g : \mathbb{R}^n \rightarrow \mathbb{R}` in
  12458. one or more dimensions using the `second-order accurate central differences method
  12459. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ and
  12460. either first or second order estimates at the boundaries.
  12461. The gradient of :math:`g` is estimated using samples. By default, when :attr:`spacing` is not
  12462. specified, the samples are entirely described by :attr:`input`, and the mapping of input coordinates
  12463. to an output is the same as the tensor's mapping of indices to values. For example, for a three-dimensional
  12464. :attr:`input` the function described is :math:`g : \mathbb{R}^3 \rightarrow \mathbb{R}`, and
  12465. :math:`g(1, 2, 3)\ == input[1, 2, 3]`.
  12466. When :attr:`spacing` is specified, it modifies the relationship between :attr:`input` and input coordinates.
  12467. This is detailed in the "Keyword Arguments" section below.
  12468. The gradient is estimated by estimating each partial derivative of :math:`g` independently. This estimation is
  12469. accurate if :math:`g` is in :math:`C^3` (it has at least 3 continuous derivatives), and the estimation can be
  12470. improved by providing closer samples. Mathematically, the value at each interior point of a partial derivative
  12471. is estimated using `Taylor's theorem with remainder <https://en.wikipedia.org/wiki/Taylor%27s_theorem>`_.
  12472. Letting :math:`x` be an interior point with :math:`x-h_l` and :math:`x+h_r` be points neighboring
  12473. it to the left and right respectively, :math:`f(x+h_r)` and :math:`f(x-h_l)` can be estimated using:
  12474. .. math::
  12475. \begin{aligned}
  12476. f(x+h_r) = f(x) + h_r f'(x) + {h_r}^2 \frac{f''(x)}{2} + {h_r}^3 \frac{f'''(\xi_1)}{6}, \xi_1 \in (x, x+h_r) \\
  12477. f(x-h_l) = f(x) - h_l f'(x) + {h_l}^2 \frac{f''(x)}{2} - {h_l}^3 \frac{f'''(\xi_2)}{6}, \xi_2 \in (x, x-h_l) \\
  12478. \end{aligned}
  12479. Using the fact that :math:`f \in C^3` and solving the linear system, we derive:
  12480. .. math::
  12481. f'(x) \approx \frac{ {h_l}^2 f(x+h_r) - {h_r}^2 f(x-h_l)
  12482. + ({h_r}^2-{h_l}^2 ) f(x) }{ {h_r} {h_l}^2 + {h_r}^2 {h_l} }
  12483. .. note::
  12484. We estimate the gradient of functions in complex domain
  12485. :math:`g : \mathbb{C}^n \rightarrow \mathbb{C}` in the same way.
  12486. The value of each partial derivative at the boundary points is computed differently. See edge_order below.
  12487. Args:
  12488. input (``Tensor``): the tensor that represents the values of the function
  12489. Keyword args:
  12490. spacing (``scalar``, ``list of scalar``, ``list of Tensor``, optional): :attr:`spacing` can be used to modify
  12491. how the :attr:`input` tensor's indices relate to sample coordinates. If :attr:`spacing` is a scalar then
  12492. the indices are multiplied by the scalar to produce the coordinates. For example, if :attr:`spacing=2` the
  12493. indices (1, 2, 3) become coordinates (2, 4, 6). If :attr:`spacing` is a list of scalars then the corresponding
  12494. indices are multiplied. For example, if :attr:`spacing=(2, -1, 3)` the indices (1, 2, 3) become coordinates (2, -2, 9).
  12495. Finally, if :attr:`spacing` is a list of one-dimensional tensors then each tensor specifies the coordinates for
  12496. the corresponding dimension. For example, if the indices are (1, 2, 3) and the tensors are (t0, t1, t2), then
  12497. the coordinates are (t0[1], t1[2], t2[3])
  12498. dim (``int``, ``list of int``, optional): the dimension or dimensions to approximate the gradient over. By default
  12499. the partial gradient in every dimension is computed. Note that when :attr:`dim` is specified the elements of
  12500. the :attr:`spacing` argument must correspond with the specified dims."
  12501. edge_order (``int``, optional): 1 or 2, for `first-order
  12502. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ or
  12503. `second-order <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_
  12504. estimation of the boundary ("edge") values, respectively. Note that when :attr:`edge_order` is specified, each
  12505. dimension size of :attr:`input` should be at least edge_order+1
  12506. Examples::
  12507. >>> # Estimates the gradient of f(x)=x^2 at points [-2, -1, 2, 4]
  12508. >>> coordinates = (torch.tensor([-2., -1., 1., 4.]),)
  12509. >>> values = torch.tensor([4., 1., 1., 16.], )
  12510. >>> torch.gradient(values, spacing = coordinates)
  12511. (tensor([-3., -2., 2., 5.]),)
  12512. >>> # Estimates the gradient of the R^2 -> R function whose samples are
  12513. >>> # described by the tensor t. Implicit coordinates are [0, 1] for the outermost
  12514. >>> # dimension and [0, 1, 2, 3] for the innermost dimension, and function estimates
  12515. >>> # partial derivative for both dimensions.
  12516. >>> t = torch.tensor([[1, 2, 4, 8], [10, 20, 40, 80]])
  12517. >>> torch.gradient(t)
  12518. (tensor([[ 9., 18., 36., 72.],
  12519. [ 9., 18., 36., 72.]]),
  12520. tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12521. [10.0000, 15.0000, 30.0000, 40.0000]]))
  12522. >>> # A scalar value for spacing modifies the relationship between tensor indices
  12523. >>> # and input coordinates by multiplying the indices to find the
  12524. >>> # coordinates. For example, below the indices of the innermost
  12525. >>> # 0, 1, 2, 3 translate to coordinates of [0, 2, 4, 6], and the indices of
  12526. >>> # the outermost dimension 0, 1 translate to coordinates of [0, 2].
  12527. >>> torch.gradient(t, spacing = 2.0) # dim = None (implicitly [0, 1])
  12528. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12529. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12530. tensor([[ 0.5000, 0.7500, 1.5000, 2.0000],
  12531. [ 5.0000, 7.5000, 15.0000, 20.0000]]))
  12532. >>> # doubling the spacing between samples halves the estimated partial gradients.
  12533. >>>
  12534. >>> # Estimates only the partial derivative for dimension 1
  12535. >>> torch.gradient(t, dim = 1) # spacing = None (implicitly 1.)
  12536. (tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12537. [10.0000, 15.0000, 30.0000, 40.0000]]),)
  12538. >>> # When spacing is a list of scalars, the relationship between the tensor
  12539. >>> # indices and input coordinates changes based on dimension.
  12540. >>> # For example, below, the indices of the innermost dimension 0, 1, 2, 3 translate
  12541. >>> # to coordinates of [0, 3, 6, 9], and the indices of the outermost dimension
  12542. >>> # 0, 1 translate to coordinates of [0, 2].
  12543. >>> torch.gradient(t, spacing = [3., 2.])
  12544. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12545. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12546. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12547. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12548. >>> # The following example is a replication of the previous one with explicit
  12549. >>> # coordinates.
  12550. >>> coords = (torch.tensor([0, 2]), torch.tensor([0, 3, 6, 9]))
  12551. >>> torch.gradient(t, spacing = coords)
  12552. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12553. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12554. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12555. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12556. """
  12557. @overload
  12558. def gradient(
  12559. input: Tensor,
  12560. *,
  12561. dim: _size,
  12562. edge_order: _int = 1,
  12563. ) -> tuple[Tensor, ...]:
  12564. r"""
  12565. gradient(input, *, spacing=1, dim=None, edge_order=1) -> List of Tensors
  12566. Estimates the gradient of a function :math:`g : \mathbb{R}^n \rightarrow \mathbb{R}` in
  12567. one or more dimensions using the `second-order accurate central differences method
  12568. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ and
  12569. either first or second order estimates at the boundaries.
  12570. The gradient of :math:`g` is estimated using samples. By default, when :attr:`spacing` is not
  12571. specified, the samples are entirely described by :attr:`input`, and the mapping of input coordinates
  12572. to an output is the same as the tensor's mapping of indices to values. For example, for a three-dimensional
  12573. :attr:`input` the function described is :math:`g : \mathbb{R}^3 \rightarrow \mathbb{R}`, and
  12574. :math:`g(1, 2, 3)\ == input[1, 2, 3]`.
  12575. When :attr:`spacing` is specified, it modifies the relationship between :attr:`input` and input coordinates.
  12576. This is detailed in the "Keyword Arguments" section below.
  12577. The gradient is estimated by estimating each partial derivative of :math:`g` independently. This estimation is
  12578. accurate if :math:`g` is in :math:`C^3` (it has at least 3 continuous derivatives), and the estimation can be
  12579. improved by providing closer samples. Mathematically, the value at each interior point of a partial derivative
  12580. is estimated using `Taylor's theorem with remainder <https://en.wikipedia.org/wiki/Taylor%27s_theorem>`_.
  12581. Letting :math:`x` be an interior point with :math:`x-h_l` and :math:`x+h_r` be points neighboring
  12582. it to the left and right respectively, :math:`f(x+h_r)` and :math:`f(x-h_l)` can be estimated using:
  12583. .. math::
  12584. \begin{aligned}
  12585. f(x+h_r) = f(x) + h_r f'(x) + {h_r}^2 \frac{f''(x)}{2} + {h_r}^3 \frac{f'''(\xi_1)}{6}, \xi_1 \in (x, x+h_r) \\
  12586. f(x-h_l) = f(x) - h_l f'(x) + {h_l}^2 \frac{f''(x)}{2} - {h_l}^3 \frac{f'''(\xi_2)}{6}, \xi_2 \in (x, x-h_l) \\
  12587. \end{aligned}
  12588. Using the fact that :math:`f \in C^3` and solving the linear system, we derive:
  12589. .. math::
  12590. f'(x) \approx \frac{ {h_l}^2 f(x+h_r) - {h_r}^2 f(x-h_l)
  12591. + ({h_r}^2-{h_l}^2 ) f(x) }{ {h_r} {h_l}^2 + {h_r}^2 {h_l} }
  12592. .. note::
  12593. We estimate the gradient of functions in complex domain
  12594. :math:`g : \mathbb{C}^n \rightarrow \mathbb{C}` in the same way.
  12595. The value of each partial derivative at the boundary points is computed differently. See edge_order below.
  12596. Args:
  12597. input (``Tensor``): the tensor that represents the values of the function
  12598. Keyword args:
  12599. spacing (``scalar``, ``list of scalar``, ``list of Tensor``, optional): :attr:`spacing` can be used to modify
  12600. how the :attr:`input` tensor's indices relate to sample coordinates. If :attr:`spacing` is a scalar then
  12601. the indices are multiplied by the scalar to produce the coordinates. For example, if :attr:`spacing=2` the
  12602. indices (1, 2, 3) become coordinates (2, 4, 6). If :attr:`spacing` is a list of scalars then the corresponding
  12603. indices are multiplied. For example, if :attr:`spacing=(2, -1, 3)` the indices (1, 2, 3) become coordinates (2, -2, 9).
  12604. Finally, if :attr:`spacing` is a list of one-dimensional tensors then each tensor specifies the coordinates for
  12605. the corresponding dimension. For example, if the indices are (1, 2, 3) and the tensors are (t0, t1, t2), then
  12606. the coordinates are (t0[1], t1[2], t2[3])
  12607. dim (``int``, ``list of int``, optional): the dimension or dimensions to approximate the gradient over. By default
  12608. the partial gradient in every dimension is computed. Note that when :attr:`dim` is specified the elements of
  12609. the :attr:`spacing` argument must correspond with the specified dims."
  12610. edge_order (``int``, optional): 1 or 2, for `first-order
  12611. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ or
  12612. `second-order <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_
  12613. estimation of the boundary ("edge") values, respectively. Note that when :attr:`edge_order` is specified, each
  12614. dimension size of :attr:`input` should be at least edge_order+1
  12615. Examples::
  12616. >>> # Estimates the gradient of f(x)=x^2 at points [-2, -1, 2, 4]
  12617. >>> coordinates = (torch.tensor([-2., -1., 1., 4.]),)
  12618. >>> values = torch.tensor([4., 1., 1., 16.], )
  12619. >>> torch.gradient(values, spacing = coordinates)
  12620. (tensor([-3., -2., 2., 5.]),)
  12621. >>> # Estimates the gradient of the R^2 -> R function whose samples are
  12622. >>> # described by the tensor t. Implicit coordinates are [0, 1] for the outermost
  12623. >>> # dimension and [0, 1, 2, 3] for the innermost dimension, and function estimates
  12624. >>> # partial derivative for both dimensions.
  12625. >>> t = torch.tensor([[1, 2, 4, 8], [10, 20, 40, 80]])
  12626. >>> torch.gradient(t)
  12627. (tensor([[ 9., 18., 36., 72.],
  12628. [ 9., 18., 36., 72.]]),
  12629. tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12630. [10.0000, 15.0000, 30.0000, 40.0000]]))
  12631. >>> # A scalar value for spacing modifies the relationship between tensor indices
  12632. >>> # and input coordinates by multiplying the indices to find the
  12633. >>> # coordinates. For example, below the indices of the innermost
  12634. >>> # 0, 1, 2, 3 translate to coordinates of [0, 2, 4, 6], and the indices of
  12635. >>> # the outermost dimension 0, 1 translate to coordinates of [0, 2].
  12636. >>> torch.gradient(t, spacing = 2.0) # dim = None (implicitly [0, 1])
  12637. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12638. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12639. tensor([[ 0.5000, 0.7500, 1.5000, 2.0000],
  12640. [ 5.0000, 7.5000, 15.0000, 20.0000]]))
  12641. >>> # doubling the spacing between samples halves the estimated partial gradients.
  12642. >>>
  12643. >>> # Estimates only the partial derivative for dimension 1
  12644. >>> torch.gradient(t, dim = 1) # spacing = None (implicitly 1.)
  12645. (tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12646. [10.0000, 15.0000, 30.0000, 40.0000]]),)
  12647. >>> # When spacing is a list of scalars, the relationship between the tensor
  12648. >>> # indices and input coordinates changes based on dimension.
  12649. >>> # For example, below, the indices of the innermost dimension 0, 1, 2, 3 translate
  12650. >>> # to coordinates of [0, 3, 6, 9], and the indices of the outermost dimension
  12651. >>> # 0, 1 translate to coordinates of [0, 2].
  12652. >>> torch.gradient(t, spacing = [3., 2.])
  12653. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12654. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12655. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12656. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12657. >>> # The following example is a replication of the previous one with explicit
  12658. >>> # coordinates.
  12659. >>> coords = (torch.tensor([0, 2]), torch.tensor([0, 3, 6, 9]))
  12660. >>> torch.gradient(t, spacing = coords)
  12661. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12662. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12663. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12664. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12665. """
  12666. @overload
  12667. def greater(
  12668. input: Tensor,
  12669. other: Tensor,
  12670. *,
  12671. out: Tensor | None = None,
  12672. ) -> Tensor:
  12673. r"""
  12674. greater(input, other, *, out=None) -> Tensor
  12675. Alias for :func:`torch.gt`.
  12676. """
  12677. @overload
  12678. def greater(
  12679. input: Tensor,
  12680. other: Number | _complex,
  12681. *,
  12682. out: Tensor | None = None,
  12683. ) -> Tensor:
  12684. r"""
  12685. greater(input, other, *, out=None) -> Tensor
  12686. Alias for :func:`torch.gt`.
  12687. """
  12688. @overload
  12689. def greater_equal(
  12690. input: Tensor,
  12691. other: Tensor,
  12692. *,
  12693. out: Tensor | None = None,
  12694. ) -> Tensor:
  12695. r"""
  12696. greater_equal(input, other, *, out=None) -> Tensor
  12697. Alias for :func:`torch.ge`.
  12698. """
  12699. @overload
  12700. def greater_equal(
  12701. input: Tensor,
  12702. other: Number | _complex,
  12703. *,
  12704. out: Tensor | None = None,
  12705. ) -> Tensor:
  12706. r"""
  12707. greater_equal(input, other, *, out=None) -> Tensor
  12708. Alias for :func:`torch.ge`.
  12709. """
  12710. def grid_sampler(
  12711. input: Tensor,
  12712. grid: Tensor,
  12713. interpolation_mode: _int,
  12714. padding_mode: _int,
  12715. align_corners: _bool,
  12716. ) -> Tensor: ...
  12717. def grid_sampler_2d(
  12718. input: Tensor,
  12719. grid: Tensor,
  12720. interpolation_mode: _int,
  12721. padding_mode: _int,
  12722. align_corners: _bool,
  12723. ) -> Tensor: ...
  12724. def grid_sampler_3d(
  12725. input: Tensor,
  12726. grid: Tensor,
  12727. interpolation_mode: _int,
  12728. padding_mode: _int,
  12729. align_corners: _bool,
  12730. ) -> Tensor: ...
  12731. def group_norm(
  12732. input: Tensor,
  12733. num_groups: _int,
  12734. weight: Tensor | None = None,
  12735. bias: Tensor | None = None,
  12736. eps: _float = 1e-05,
  12737. cudnn_enabled: _bool = True,
  12738. ) -> Tensor: ...
  12739. @overload
  12740. def gru(
  12741. data: Tensor,
  12742. batch_sizes: Tensor,
  12743. hx: Tensor,
  12744. params: tuple[Tensor, ...] | list[Tensor] | None,
  12745. has_biases: _bool,
  12746. num_layers: _int,
  12747. dropout: _float,
  12748. train: _bool,
  12749. bidirectional: _bool,
  12750. ) -> tuple[Tensor, Tensor]: ...
  12751. @overload
  12752. def gru(
  12753. input: Tensor,
  12754. hx: Tensor,
  12755. params: tuple[Tensor, ...] | list[Tensor] | None,
  12756. has_biases: _bool,
  12757. num_layers: _int,
  12758. dropout: _float,
  12759. train: _bool,
  12760. bidirectional: _bool,
  12761. batch_first: _bool,
  12762. ) -> tuple[Tensor, Tensor]: ...
  12763. def gru_cell(
  12764. input: Tensor,
  12765. hx: Tensor,
  12766. w_ih: Tensor,
  12767. w_hh: Tensor,
  12768. b_ih: Tensor | None = None,
  12769. b_hh: Tensor | None = None,
  12770. ) -> Tensor: ...
  12771. @overload
  12772. def gt(
  12773. input: Tensor,
  12774. other: Tensor,
  12775. *,
  12776. out: Tensor | None = None,
  12777. ) -> Tensor:
  12778. r"""
  12779. gt(input, other, *, out=None) -> Tensor
  12780. Computes :math:`\text{input} > \text{other}` element-wise.
  12781. The second argument can be a number or a tensor whose shape is
  12782. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  12783. Args:
  12784. input (Tensor): the tensor to compare
  12785. other (Tensor or float): the tensor or value to compare
  12786. Keyword args:
  12787. out (Tensor, optional): the output tensor.
  12788. Returns:
  12789. A boolean tensor that is True where :attr:`input` is greater than :attr:`other` and False elsewhere
  12790. Example::
  12791. >>> torch.gt(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  12792. tensor([[False, True], [False, False]])
  12793. """
  12794. @overload
  12795. def gt(
  12796. input: Tensor,
  12797. other: Number | _complex,
  12798. *,
  12799. out: Tensor | None = None,
  12800. ) -> Tensor:
  12801. r"""
  12802. gt(input, other, *, out=None) -> Tensor
  12803. Computes :math:`\text{input} > \text{other}` element-wise.
  12804. The second argument can be a number or a tensor whose shape is
  12805. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  12806. Args:
  12807. input (Tensor): the tensor to compare
  12808. other (Tensor or float): the tensor or value to compare
  12809. Keyword args:
  12810. out (Tensor, optional): the output tensor.
  12811. Returns:
  12812. A boolean tensor that is True where :attr:`input` is greater than :attr:`other` and False elsewhere
  12813. Example::
  12814. >>> torch.gt(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  12815. tensor([[False, True], [False, False]])
  12816. """
  12817. @overload
  12818. def hamming_window(
  12819. window_length: _int,
  12820. *,
  12821. dtype: _dtype | None = None,
  12822. layout: _layout | None = None,
  12823. device: DeviceLikeType | None = None,
  12824. pin_memory: _bool | None = False,
  12825. requires_grad: _bool | None = False,
  12826. ) -> Tensor:
  12827. r"""
  12828. hamming_window(window_length, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) -> Tensor
  12829. Hamming window function.
  12830. .. math::
  12831. w[n] = \alpha - \beta\ \cos \left( \frac{2 \pi n}{N - 1} \right),
  12832. where :math:`N` is the full window size.
  12833. The input :attr:`window_length` is a positive integer controlling the
  12834. returned window size. :attr:`periodic` flag determines whether the returned
  12835. window trims off the last duplicate value from the symmetric window and is
  12836. ready to be used as a periodic window with functions like
  12837. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  12838. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  12839. ``torch.hamming_window(L, periodic=True)`` equal to
  12840. ``torch.hamming_window(L + 1, periodic=False)[:-1])``.
  12841. .. note::
  12842. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  12843. .. note::
  12844. This is a generalized version of :meth:`torch.hann_window`.
  12845. Arguments:
  12846. window_length (int): the size of returned window
  12847. Keyword args:
  12848. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  12849. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  12850. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  12851. ``torch.strided`` (dense layout) is supported.
  12852. device (:class:`torch.device`, optional): the desired device of returned tensor.
  12853. Default: if ``None``, uses the current device for the default tensor type
  12854. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  12855. for CPU tensor types and the current CUDA device for CUDA tensor types.
  12856. pin_memory (bool, optional): If set, returned tensor would be allocated in
  12857. the pinned memory. Works only for CPU tensors. Default: ``False``.
  12858. requires_grad (bool, optional): If autograd should record operations on the
  12859. returned tensor. Default: ``False``.
  12860. Returns:
  12861. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  12862. .. function:: hamming_window(window_length, periodic, *, dtype=None, layout=None, device=None, \
  12863. pin_memory=False, requires_grad=False) -> Tensor
  12864. :noindex:
  12865. Hamming window function with periodic specified.
  12866. Arguments:
  12867. window_length (int): the size of returned window
  12868. periodic (bool): If True, returns a window to be used as periodic
  12869. function. If False, return a symmetric window.
  12870. Keyword args:
  12871. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  12872. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  12873. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  12874. ``torch.strided`` (dense layout) is supported.
  12875. device (:class:`torch.device`, optional): the desired device of returned tensor.
  12876. Default: if ``None``, uses the current device for the default tensor type
  12877. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  12878. for CPU tensor types and the current CUDA device for CUDA tensor types.
  12879. pin_memory (bool, optional): If set, returned tensor would be allocated in
  12880. the pinned memory. Works only for CPU tensors. Default: ``False``.
  12881. requires_grad (bool, optional): If autograd should record operations on the
  12882. returned tensor. Default: ``False``.
  12883. Returns:
  12884. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  12885. .. function:: hamming_window(window_length, periodic, float alpha, *, dtype=None, layout=None, device=None, \
  12886. pin_memory=False, requires_grad=False) -> Tensor
  12887. :noindex:
  12888. Hamming window function with periodic and alpha specified.
  12889. Arguments:
  12890. window_length (int): the size of returned window
  12891. periodic (bool): If True, returns a window to be used as periodic
  12892. function. If False, return a symmetric window.
  12893. alpha (float): The coefficient :math:`\alpha` in the equation above
  12894. Keyword args:
  12895. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  12896. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  12897. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  12898. ``torch.strided`` (dense layout) is supported.
  12899. device (:class:`torch.device`, optional): the desired device of returned tensor.
  12900. Default: if ``None``, uses the current device for the default tensor type
  12901. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  12902. for CPU tensor types and the current CUDA device for CUDA tensor types.
  12903. pin_memory (bool, optional): If set, returned tensor would be allocated in
  12904. the pinned memory. Works only for CPU tensors. Default: ``False``.
  12905. requires_grad (bool, optional): If autograd should record operations on the
  12906. returned tensor. Default: ``False``.
  12907. Returns:
  12908. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  12909. .. function:: hamming_window(window_length, periodic, float alpha, float beta, *, dtype=None, layout=None, \
  12910. device=None, pin_memory=False, requires_grad=False) -> Tensor
  12911. :noindex:
  12912. Hamming window function with periodic, alpha and beta specified.
  12913. Arguments:
  12914. window_length (int): the size of returned window
  12915. periodic (bool): If True, returns a window to be used as periodic
  12916. function. If False, return a symmetric window.
  12917. alpha (float): The coefficient :math:`\alpha` in the equation above
  12918. beta (float): The coefficient :math:`\beta` in the equation above
  12919. Keyword args:
  12920. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  12921. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  12922. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  12923. ``torch.strided`` (dense layout) is supported.
  12924. device (:class:`torch.device`, optional): the desired device of returned tensor.
  12925. Default: if ``None``, uses the current device for the default tensor type
  12926. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  12927. for CPU tensor types and the current CUDA device for CUDA tensor types.
  12928. pin_memory (bool, optional): If set, returned tensor would be allocated in
  12929. the pinned memory. Works only for CPU tensors. Default: ``False``.
  12930. requires_grad (bool, optional): If autograd should record operations on the
  12931. returned tensor. Default: ``False``.
  12932. Returns:
  12933. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  12934. """
  12935. @overload
  12936. def hamming_window(
  12937. window_length: _int,
  12938. periodic: _bool,
  12939. *,
  12940. dtype: _dtype | None = None,
  12941. layout: _layout | None = None,
  12942. device: DeviceLikeType | None = None,
  12943. pin_memory: _bool | None = False,
  12944. requires_grad: _bool | None = False,
  12945. ) -> Tensor:
  12946. r"""
  12947. hamming_window(window_length, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) -> Tensor
  12948. Hamming window function.
  12949. .. math::
  12950. w[n] = \alpha - \beta\ \cos \left( \frac{2 \pi n}{N - 1} \right),
  12951. where :math:`N` is the full window size.
  12952. The input :attr:`window_length` is a positive integer controlling the
  12953. returned window size. :attr:`periodic` flag determines whether the returned
  12954. window trims off the last duplicate value from the symmetric window and is
  12955. ready to be used as a periodic window with functions like
  12956. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  12957. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  12958. ``torch.hamming_window(L, periodic=True)`` equal to
  12959. ``torch.hamming_window(L + 1, periodic=False)[:-1])``.
  12960. .. note::
  12961. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  12962. .. note::
  12963. This is a generalized version of :meth:`torch.hann_window`.
  12964. Arguments:
  12965. window_length (int): the size of returned window
  12966. Keyword args:
  12967. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  12968. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  12969. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  12970. ``torch.strided`` (dense layout) is supported.
  12971. device (:class:`torch.device`, optional): the desired device of returned tensor.
  12972. Default: if ``None``, uses the current device for the default tensor type
  12973. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  12974. for CPU tensor types and the current CUDA device for CUDA tensor types.
  12975. pin_memory (bool, optional): If set, returned tensor would be allocated in
  12976. the pinned memory. Works only for CPU tensors. Default: ``False``.
  12977. requires_grad (bool, optional): If autograd should record operations on the
  12978. returned tensor. Default: ``False``.
  12979. Returns:
  12980. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  12981. .. function:: hamming_window(window_length, periodic, *, dtype=None, layout=None, device=None, \
  12982. pin_memory=False, requires_grad=False) -> Tensor
  12983. :noindex:
  12984. Hamming window function with periodic specified.
  12985. Arguments:
  12986. window_length (int): the size of returned window
  12987. periodic (bool): If True, returns a window to be used as periodic
  12988. function. If False, return a symmetric window.
  12989. Keyword args:
  12990. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  12991. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  12992. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  12993. ``torch.strided`` (dense layout) is supported.
  12994. device (:class:`torch.device`, optional): the desired device of returned tensor.
  12995. Default: if ``None``, uses the current device for the default tensor type
  12996. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  12997. for CPU tensor types and the current CUDA device for CUDA tensor types.
  12998. pin_memory (bool, optional): If set, returned tensor would be allocated in
  12999. the pinned memory. Works only for CPU tensors. Default: ``False``.
  13000. requires_grad (bool, optional): If autograd should record operations on the
  13001. returned tensor. Default: ``False``.
  13002. Returns:
  13003. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  13004. .. function:: hamming_window(window_length, periodic, float alpha, *, dtype=None, layout=None, device=None, \
  13005. pin_memory=False, requires_grad=False) -> Tensor
  13006. :noindex:
  13007. Hamming window function with periodic and alpha specified.
  13008. Arguments:
  13009. window_length (int): the size of returned window
  13010. periodic (bool): If True, returns a window to be used as periodic
  13011. function. If False, return a symmetric window.
  13012. alpha (float): The coefficient :math:`\alpha` in the equation above
  13013. Keyword args:
  13014. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13015. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13016. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13017. ``torch.strided`` (dense layout) is supported.
  13018. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13019. Default: if ``None``, uses the current device for the default tensor type
  13020. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13021. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13022. pin_memory (bool, optional): If set, returned tensor would be allocated in
  13023. the pinned memory. Works only for CPU tensors. Default: ``False``.
  13024. requires_grad (bool, optional): If autograd should record operations on the
  13025. returned tensor. Default: ``False``.
  13026. Returns:
  13027. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  13028. .. function:: hamming_window(window_length, periodic, float alpha, float beta, *, dtype=None, layout=None, \
  13029. device=None, pin_memory=False, requires_grad=False) -> Tensor
  13030. :noindex:
  13031. Hamming window function with periodic, alpha and beta specified.
  13032. Arguments:
  13033. window_length (int): the size of returned window
  13034. periodic (bool): If True, returns a window to be used as periodic
  13035. function. If False, return a symmetric window.
  13036. alpha (float): The coefficient :math:`\alpha` in the equation above
  13037. beta (float): The coefficient :math:`\beta` in the equation above
  13038. Keyword args:
  13039. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13040. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13041. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13042. ``torch.strided`` (dense layout) is supported.
  13043. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13044. Default: if ``None``, uses the current device for the default tensor type
  13045. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13046. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13047. pin_memory (bool, optional): If set, returned tensor would be allocated in
  13048. the pinned memory. Works only for CPU tensors. Default: ``False``.
  13049. requires_grad (bool, optional): If autograd should record operations on the
  13050. returned tensor. Default: ``False``.
  13051. Returns:
  13052. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  13053. """
  13054. @overload
  13055. def hamming_window(
  13056. window_length: _int,
  13057. periodic: _bool,
  13058. alpha: _float,
  13059. *,
  13060. dtype: _dtype | None = None,
  13061. layout: _layout | None = None,
  13062. device: DeviceLikeType | None = None,
  13063. pin_memory: _bool | None = False,
  13064. requires_grad: _bool | None = False,
  13065. ) -> Tensor:
  13066. r"""
  13067. hamming_window(window_length, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) -> Tensor
  13068. Hamming window function.
  13069. .. math::
  13070. w[n] = \alpha - \beta\ \cos \left( \frac{2 \pi n}{N - 1} \right),
  13071. where :math:`N` is the full window size.
  13072. The input :attr:`window_length` is a positive integer controlling the
  13073. returned window size. :attr:`periodic` flag determines whether the returned
  13074. window trims off the last duplicate value from the symmetric window and is
  13075. ready to be used as a periodic window with functions like
  13076. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  13077. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  13078. ``torch.hamming_window(L, periodic=True)`` equal to
  13079. ``torch.hamming_window(L + 1, periodic=False)[:-1])``.
  13080. .. note::
  13081. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  13082. .. note::
  13083. This is a generalized version of :meth:`torch.hann_window`.
  13084. Arguments:
  13085. window_length (int): the size of returned window
  13086. Keyword args:
  13087. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13088. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13089. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13090. ``torch.strided`` (dense layout) is supported.
  13091. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13092. Default: if ``None``, uses the current device for the default tensor type
  13093. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13094. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13095. pin_memory (bool, optional): If set, returned tensor would be allocated in
  13096. the pinned memory. Works only for CPU tensors. Default: ``False``.
  13097. requires_grad (bool, optional): If autograd should record operations on the
  13098. returned tensor. Default: ``False``.
  13099. Returns:
  13100. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  13101. .. function:: hamming_window(window_length, periodic, *, dtype=None, layout=None, device=None, \
  13102. pin_memory=False, requires_grad=False) -> Tensor
  13103. :noindex:
  13104. Hamming window function with periodic specified.
  13105. Arguments:
  13106. window_length (int): the size of returned window
  13107. periodic (bool): If True, returns a window to be used as periodic
  13108. function. If False, return a symmetric window.
  13109. Keyword args:
  13110. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13111. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13112. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13113. ``torch.strided`` (dense layout) is supported.
  13114. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13115. Default: if ``None``, uses the current device for the default tensor type
  13116. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13117. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13118. pin_memory (bool, optional): If set, returned tensor would be allocated in
  13119. the pinned memory. Works only for CPU tensors. Default: ``False``.
  13120. requires_grad (bool, optional): If autograd should record operations on the
  13121. returned tensor. Default: ``False``.
  13122. Returns:
  13123. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  13124. .. function:: hamming_window(window_length, periodic, float alpha, *, dtype=None, layout=None, device=None, \
  13125. pin_memory=False, requires_grad=False) -> Tensor
  13126. :noindex:
  13127. Hamming window function with periodic and alpha specified.
  13128. Arguments:
  13129. window_length (int): the size of returned window
  13130. periodic (bool): If True, returns a window to be used as periodic
  13131. function. If False, return a symmetric window.
  13132. alpha (float): The coefficient :math:`\alpha` in the equation above
  13133. Keyword args:
  13134. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13135. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13136. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13137. ``torch.strided`` (dense layout) is supported.
  13138. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13139. Default: if ``None``, uses the current device for the default tensor type
  13140. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13141. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13142. pin_memory (bool, optional): If set, returned tensor would be allocated in
  13143. the pinned memory. Works only for CPU tensors. Default: ``False``.
  13144. requires_grad (bool, optional): If autograd should record operations on the
  13145. returned tensor. Default: ``False``.
  13146. Returns:
  13147. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  13148. .. function:: hamming_window(window_length, periodic, float alpha, float beta, *, dtype=None, layout=None, \
  13149. device=None, pin_memory=False, requires_grad=False) -> Tensor
  13150. :noindex:
  13151. Hamming window function with periodic, alpha and beta specified.
  13152. Arguments:
  13153. window_length (int): the size of returned window
  13154. periodic (bool): If True, returns a window to be used as periodic
  13155. function. If False, return a symmetric window.
  13156. alpha (float): The coefficient :math:`\alpha` in the equation above
  13157. beta (float): The coefficient :math:`\beta` in the equation above
  13158. Keyword args:
  13159. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13160. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13161. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13162. ``torch.strided`` (dense layout) is supported.
  13163. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13164. Default: if ``None``, uses the current device for the default tensor type
  13165. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13166. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13167. pin_memory (bool, optional): If set, returned tensor would be allocated in
  13168. the pinned memory. Works only for CPU tensors. Default: ``False``.
  13169. requires_grad (bool, optional): If autograd should record operations on the
  13170. returned tensor. Default: ``False``.
  13171. Returns:
  13172. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  13173. """
  13174. @overload
  13175. def hamming_window(
  13176. window_length: _int,
  13177. periodic: _bool,
  13178. alpha: _float,
  13179. beta: _float,
  13180. *,
  13181. dtype: _dtype | None = None,
  13182. layout: _layout | None = None,
  13183. device: DeviceLikeType | None = None,
  13184. pin_memory: _bool | None = False,
  13185. requires_grad: _bool | None = False,
  13186. ) -> Tensor:
  13187. r"""
  13188. hamming_window(window_length, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) -> Tensor
  13189. Hamming window function.
  13190. .. math::
  13191. w[n] = \alpha - \beta\ \cos \left( \frac{2 \pi n}{N - 1} \right),
  13192. where :math:`N` is the full window size.
  13193. The input :attr:`window_length` is a positive integer controlling the
  13194. returned window size. :attr:`periodic` flag determines whether the returned
  13195. window trims off the last duplicate value from the symmetric window and is
  13196. ready to be used as a periodic window with functions like
  13197. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  13198. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  13199. ``torch.hamming_window(L, periodic=True)`` equal to
  13200. ``torch.hamming_window(L + 1, periodic=False)[:-1])``.
  13201. .. note::
  13202. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  13203. .. note::
  13204. This is a generalized version of :meth:`torch.hann_window`.
  13205. Arguments:
  13206. window_length (int): the size of returned window
  13207. Keyword args:
  13208. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13209. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13210. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13211. ``torch.strided`` (dense layout) is supported.
  13212. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13213. Default: if ``None``, uses the current device for the default tensor type
  13214. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13215. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13216. pin_memory (bool, optional): If set, returned tensor would be allocated in
  13217. the pinned memory. Works only for CPU tensors. Default: ``False``.
  13218. requires_grad (bool, optional): If autograd should record operations on the
  13219. returned tensor. Default: ``False``.
  13220. Returns:
  13221. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  13222. .. function:: hamming_window(window_length, periodic, *, dtype=None, layout=None, device=None, \
  13223. pin_memory=False, requires_grad=False) -> Tensor
  13224. :noindex:
  13225. Hamming window function with periodic specified.
  13226. Arguments:
  13227. window_length (int): the size of returned window
  13228. periodic (bool): If True, returns a window to be used as periodic
  13229. function. If False, return a symmetric window.
  13230. Keyword args:
  13231. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13232. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13233. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13234. ``torch.strided`` (dense layout) is supported.
  13235. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13236. Default: if ``None``, uses the current device for the default tensor type
  13237. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13238. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13239. pin_memory (bool, optional): If set, returned tensor would be allocated in
  13240. the pinned memory. Works only for CPU tensors. Default: ``False``.
  13241. requires_grad (bool, optional): If autograd should record operations on the
  13242. returned tensor. Default: ``False``.
  13243. Returns:
  13244. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  13245. .. function:: hamming_window(window_length, periodic, float alpha, *, dtype=None, layout=None, device=None, \
  13246. pin_memory=False, requires_grad=False) -> Tensor
  13247. :noindex:
  13248. Hamming window function with periodic and alpha specified.
  13249. Arguments:
  13250. window_length (int): the size of returned window
  13251. periodic (bool): If True, returns a window to be used as periodic
  13252. function. If False, return a symmetric window.
  13253. alpha (float): The coefficient :math:`\alpha` in the equation above
  13254. Keyword args:
  13255. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13256. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13257. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13258. ``torch.strided`` (dense layout) is supported.
  13259. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13260. Default: if ``None``, uses the current device for the default tensor type
  13261. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13262. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13263. pin_memory (bool, optional): If set, returned tensor would be allocated in
  13264. the pinned memory. Works only for CPU tensors. Default: ``False``.
  13265. requires_grad (bool, optional): If autograd should record operations on the
  13266. returned tensor. Default: ``False``.
  13267. Returns:
  13268. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  13269. .. function:: hamming_window(window_length, periodic, float alpha, float beta, *, dtype=None, layout=None, \
  13270. device=None, pin_memory=False, requires_grad=False) -> Tensor
  13271. :noindex:
  13272. Hamming window function with periodic, alpha and beta specified.
  13273. Arguments:
  13274. window_length (int): the size of returned window
  13275. periodic (bool): If True, returns a window to be used as periodic
  13276. function. If False, return a symmetric window.
  13277. alpha (float): The coefficient :math:`\alpha` in the equation above
  13278. beta (float): The coefficient :math:`\beta` in the equation above
  13279. Keyword args:
  13280. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13281. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13282. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13283. ``torch.strided`` (dense layout) is supported.
  13284. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13285. Default: if ``None``, uses the current device for the default tensor type
  13286. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13287. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13288. pin_memory (bool, optional): If set, returned tensor would be allocated in
  13289. the pinned memory. Works only for CPU tensors. Default: ``False``.
  13290. requires_grad (bool, optional): If autograd should record operations on the
  13291. returned tensor. Default: ``False``.
  13292. Returns:
  13293. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  13294. """
  13295. @overload
  13296. def hann_window(
  13297. window_length: _int,
  13298. *,
  13299. dtype: _dtype | None = None,
  13300. layout: _layout | None = None,
  13301. device: DeviceLikeType | None = None,
  13302. pin_memory: _bool | None = False,
  13303. requires_grad: _bool | None = False,
  13304. ) -> Tensor:
  13305. r"""
  13306. hann_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  13307. Hann window function.
  13308. .. math::
  13309. w[n] = \frac{1}{2}\ \left[1 - \cos \left( \frac{2 \pi n}{N - 1} \right)\right] =
  13310. \sin^2 \left( \frac{\pi n}{N - 1} \right),
  13311. where :math:`N` is the full window size.
  13312. The input :attr:`window_length` is a positive integer controlling the
  13313. returned window size. :attr:`periodic` flag determines whether the returned
  13314. window trims off the last duplicate value from the symmetric window and is
  13315. ready to be used as a periodic window with functions like
  13316. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  13317. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  13318. ``torch.hann_window(L, periodic=True)`` equal to
  13319. ``torch.hann_window(L + 1, periodic=False)[:-1])``.
  13320. .. note::
  13321. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  13322. Arguments:
  13323. window_length (int): the size of returned window
  13324. periodic (bool, optional): If True, returns a window to be used as periodic
  13325. function. If False, return a symmetric window.
  13326. Keyword args:
  13327. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13328. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13329. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13330. ``torch.strided`` (dense layout) is supported.
  13331. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13332. Default: if ``None``, uses the current device for the default tensor type
  13333. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13334. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13335. requires_grad (bool, optional): If autograd should record operations on the
  13336. returned tensor. Default: ``False``.
  13337. Returns:
  13338. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window
  13339. """
  13340. @overload
  13341. def hann_window(
  13342. window_length: _int,
  13343. periodic: _bool,
  13344. *,
  13345. dtype: _dtype | None = None,
  13346. layout: _layout | None = None,
  13347. device: DeviceLikeType | None = None,
  13348. pin_memory: _bool | None = False,
  13349. requires_grad: _bool | None = False,
  13350. ) -> Tensor:
  13351. r"""
  13352. hann_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  13353. Hann window function.
  13354. .. math::
  13355. w[n] = \frac{1}{2}\ \left[1 - \cos \left( \frac{2 \pi n}{N - 1} \right)\right] =
  13356. \sin^2 \left( \frac{\pi n}{N - 1} \right),
  13357. where :math:`N` is the full window size.
  13358. The input :attr:`window_length` is a positive integer controlling the
  13359. returned window size. :attr:`periodic` flag determines whether the returned
  13360. window trims off the last duplicate value from the symmetric window and is
  13361. ready to be used as a periodic window with functions like
  13362. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  13363. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  13364. ``torch.hann_window(L, periodic=True)`` equal to
  13365. ``torch.hann_window(L + 1, periodic=False)[:-1])``.
  13366. .. note::
  13367. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  13368. Arguments:
  13369. window_length (int): the size of returned window
  13370. periodic (bool, optional): If True, returns a window to be used as periodic
  13371. function. If False, return a symmetric window.
  13372. Keyword args:
  13373. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13374. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13375. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13376. ``torch.strided`` (dense layout) is supported.
  13377. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13378. Default: if ``None``, uses the current device for the default tensor type
  13379. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13380. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13381. requires_grad (bool, optional): If autograd should record operations on the
  13382. returned tensor. Default: ``False``.
  13383. Returns:
  13384. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window
  13385. """
  13386. def hardshrink(
  13387. input: Tensor,
  13388. lambd: Number | _complex = 0.5,
  13389. *,
  13390. out: Tensor | None = None,
  13391. ) -> Tensor: ...
  13392. def hash_tensor(
  13393. input: Tensor,
  13394. dim: _int | _size = (),
  13395. *,
  13396. keepdim: _bool = False,
  13397. mode: _int = 0,
  13398. out: Tensor | None = None,
  13399. ) -> Tensor:
  13400. r"""
  13401. hash_tensor(input, *, mode=0) -> Tensor
  13402. Returns a hash of all elements in the :attr:`input` tensor.
  13403. Currently only mode=0 (reduction via xor) is supported. The output will always
  13404. be of type ``torch.uint64``. The elements of ``input`` are upcasted to their
  13405. 64 bit float / integer equivalent and bitcasted to ``torch.uint64`` before
  13406. reduction via xor.
  13407. Args:
  13408. input (Tensor): the input tensor.
  13409. Keyword Args:
  13410. mode (int) : The hash to use. Default: 0 (xor_reduction)
  13411. Example::
  13412. >>> a = torch.randn(1, 3)
  13413. >>> a
  13414. tensor([[ 1.1918, -1.1813, 0.3373]])
  13415. >>> torch.hash_tensor(a)
  13416. tensor(13822780554648485888, dtype=torch.uint64)
  13417. .. function:: hash_tensor(input, dim, *, keepdim=False, mode=0) -> Tensor
  13418. :noindex:
  13419. Returns the hash of each row of the :attr:`input` tensor in the given
  13420. dimension :attr:`dim` given by mode. If :attr:`dim` is a list of dimensions,
  13421. reduce over all of them.
  13422. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  13423. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  13424. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  13425. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  13426. Args:
  13427. input (Tensor): the input tensor.
  13428. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  13429. If ``None``, all dimensions are reduced.
  13430. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  13431. Keyword Args:
  13432. mode (int) : The hash to use. Default: 0 (xor_reduction)
  13433. Example::
  13434. >>> a = torch.randn(2, 4)
  13435. >>> a
  13436. tensor([[ 0.1317, -0.5554, -1.4724, -1.1391],
  13437. [ 0.0778, -0.6070, 0.6375, 0.1798]])
  13438. >>> torch.hash_tensor(a, 1)
  13439. tensor([9233691267014066176, 9255993250844508160], dtype=torch.uint64)
  13440. """
  13441. def heaviside(
  13442. input: Tensor,
  13443. values: Tensor,
  13444. *,
  13445. out: Tensor | None = None,
  13446. ) -> Tensor:
  13447. r"""
  13448. heaviside(input, values, *, out=None) -> Tensor
  13449. Computes the Heaviside step function for each element in :attr:`input`.
  13450. The Heaviside step function is defined as:
  13451. .. math::
  13452. \text{{heaviside}}(input, values) = \begin{cases}
  13453. 0, & \text{if input < 0}\\
  13454. values, & \text{if input == 0}\\
  13455. 1, & \text{if input > 0}
  13456. \end{cases}
  13457. Args:
  13458. input (Tensor): the input tensor.
  13459. values (Tensor): The values to use where :attr:`input` is zero.
  13460. Keyword arguments:
  13461. out (Tensor, optional): the output tensor.
  13462. Example::
  13463. >>> input = torch.tensor([-1.5, 0, 2.0])
  13464. >>> values = torch.tensor([0.5])
  13465. >>> torch.heaviside(input, values)
  13466. tensor([0.0000, 0.5000, 1.0000])
  13467. >>> values = torch.tensor([1.2, -2.0, 3.5])
  13468. >>> torch.heaviside(input, values)
  13469. tensor([0., -2., 1.])
  13470. """
  13471. def hinge_embedding_loss(
  13472. input: Tensor,
  13473. target: Tensor,
  13474. margin: _float = 1.0,
  13475. reduction: _int = 1,
  13476. ) -> Tensor: ...
  13477. def histc(
  13478. input: Tensor,
  13479. bins: _int = 100,
  13480. min: Number | _complex = 0,
  13481. max: Number | _complex = 0,
  13482. *,
  13483. out: Tensor | None = None,
  13484. ) -> Tensor:
  13485. r"""
  13486. histc(input, bins=100, min=0, max=0, *, out=None) -> Tensor
  13487. Computes the histogram of a tensor.
  13488. The elements are sorted into equal width bins between :attr:`min` and
  13489. :attr:`max`. If :attr:`min` and :attr:`max` are both zero, the minimum and
  13490. maximum values of the data are used.
  13491. Elements lower than min and higher than max and ``NaN`` elements are ignored.
  13492. Args:
  13493. input (Tensor): the input tensor.
  13494. bins (int): number of histogram bins
  13495. min (Scalar): lower end of the range (inclusive)
  13496. max (Scalar): upper end of the range (inclusive)
  13497. Keyword args:
  13498. out (Tensor, optional): the output tensor.
  13499. Returns:
  13500. Tensor: Histogram represented as a tensor
  13501. Example::
  13502. >>> torch.histc(torch.tensor([1., 2, 1]), bins=4, min=0, max=3)
  13503. tensor([ 0., 2., 1., 0.])
  13504. """
  13505. @overload
  13506. def histogram(
  13507. input: Tensor,
  13508. bins: Tensor,
  13509. *,
  13510. weight: Tensor | None = None,
  13511. density: _bool = False,
  13512. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  13513. ) -> torch.return_types.histogram:
  13514. r"""
  13515. histogram(input, bins, *, range=None, weight=None, density=False, out=None) -> (Tensor, Tensor)
  13516. Computes a histogram of the values in a tensor.
  13517. :attr:`bins` can be an integer or a 1D tensor.
  13518. If :attr:`bins` is an int, it specifies the number of equal-width bins.
  13519. By default, the lower and upper range of the bins is determined by the
  13520. minimum and maximum elements of the input tensor. The :attr:`range`
  13521. argument can be provided to specify a range for the bins.
  13522. If :attr:`bins` is a 1D tensor, it specifies the sequence of bin edges
  13523. including the rightmost edge. It should contain at least 2 elements
  13524. and its elements should be increasing.
  13525. Args:
  13526. input (Tensor): the input tensor.
  13527. bins: int or 1D Tensor. If int, defines the number of equal-width bins. If tensor,
  13528. defines the sequence of bin edges including the rightmost edge.
  13529. Keyword args:
  13530. range (tuple of float): Defines the range of the bins.
  13531. weight (Tensor): If provided, weight should have the same shape as input. Each value in
  13532. input contributes its associated weight towards its bin's result.
  13533. density (bool): If False, the result will contain the count (or total weight) in each bin.
  13534. If True, the result is the value of the probability density function over the bins,
  13535. normalized such that the integral over the range of the bins is 1.
  13536. out (Tensor, optional): the output tensor. (tuple, optional): The result tuple of two output tensors (hist, bin_edges).
  13537. Returns:
  13538. hist (Tensor): 1D Tensor containing the values of the histogram.
  13539. bin_edges(Tensor): 1D Tensor containing the edges of the histogram bins.
  13540. Example::
  13541. >>> torch.histogram(torch.tensor([1., 2, 1]), bins=4, range=(0., 3.), weight=torch.tensor([1., 2., 4.]))
  13542. (tensor([ 0., 5., 2., 0.]), tensor([0., 0.75, 1.5, 2.25, 3.]))
  13543. >>> torch.histogram(torch.tensor([1., 2, 1]), bins=4, range=(0., 3.), weight=torch.tensor([1., 2., 4.]), density=True)
  13544. (tensor([ 0., 0.9524, 0.3810, 0.]), tensor([0., 0.75, 1.5, 2.25, 3.]))
  13545. """
  13546. @overload
  13547. def histogram(
  13548. input: Tensor,
  13549. bins: _int = 100,
  13550. *,
  13551. range: Sequence[_float] | None = None,
  13552. weight: Tensor | None = None,
  13553. density: _bool = False,
  13554. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  13555. ) -> torch.return_types.histogram:
  13556. r"""
  13557. histogram(input, bins, *, range=None, weight=None, density=False, out=None) -> (Tensor, Tensor)
  13558. Computes a histogram of the values in a tensor.
  13559. :attr:`bins` can be an integer or a 1D tensor.
  13560. If :attr:`bins` is an int, it specifies the number of equal-width bins.
  13561. By default, the lower and upper range of the bins is determined by the
  13562. minimum and maximum elements of the input tensor. The :attr:`range`
  13563. argument can be provided to specify a range for the bins.
  13564. If :attr:`bins` is a 1D tensor, it specifies the sequence of bin edges
  13565. including the rightmost edge. It should contain at least 2 elements
  13566. and its elements should be increasing.
  13567. Args:
  13568. input (Tensor): the input tensor.
  13569. bins: int or 1D Tensor. If int, defines the number of equal-width bins. If tensor,
  13570. defines the sequence of bin edges including the rightmost edge.
  13571. Keyword args:
  13572. range (tuple of float): Defines the range of the bins.
  13573. weight (Tensor): If provided, weight should have the same shape as input. Each value in
  13574. input contributes its associated weight towards its bin's result.
  13575. density (bool): If False, the result will contain the count (or total weight) in each bin.
  13576. If True, the result is the value of the probability density function over the bins,
  13577. normalized such that the integral over the range of the bins is 1.
  13578. out (Tensor, optional): the output tensor. (tuple, optional): The result tuple of two output tensors (hist, bin_edges).
  13579. Returns:
  13580. hist (Tensor): 1D Tensor containing the values of the histogram.
  13581. bin_edges(Tensor): 1D Tensor containing the edges of the histogram bins.
  13582. Example::
  13583. >>> torch.histogram(torch.tensor([1., 2, 1]), bins=4, range=(0., 3.), weight=torch.tensor([1., 2., 4.]))
  13584. (tensor([ 0., 5., 2., 0.]), tensor([0., 0.75, 1.5, 2.25, 3.]))
  13585. >>> torch.histogram(torch.tensor([1., 2, 1]), bins=4, range=(0., 3.), weight=torch.tensor([1., 2., 4.]), density=True)
  13586. (tensor([ 0., 0.9524, 0.3810, 0.]), tensor([0., 0.75, 1.5, 2.25, 3.]))
  13587. """
  13588. @overload
  13589. def histogramdd(
  13590. input: Tensor,
  13591. bins: _int,
  13592. range: Sequence[_float] | None = None,
  13593. weight: Tensor | None = None,
  13594. density: _bool = False,
  13595. ) -> torch.return_types.histogramdd:
  13596. r"""
  13597. histogramdd(input, bins, *, range=None, weight=None, density=False, out=None) -> (Tensor, Tensor[])
  13598. Computes a multi-dimensional histogram of the values in a tensor.
  13599. Interprets the elements of an input tensor whose innermost dimension has size N
  13600. as a collection of N-dimensional points. Maps each of the points into a set of
  13601. N-dimensional bins and returns the number of points (or total weight) in each bin.
  13602. :attr:`input` must be a tensor with at least 2 dimensions.
  13603. If input has shape (M, N), each of its M rows defines a point in N-dimensional space.
  13604. If input has three or more dimensions, all but the last dimension are flattened.
  13605. Each dimension is independently associated with its own strictly increasing sequence
  13606. of bin edges. Bin edges may be specified explicitly by passing a sequence of 1D
  13607. tensors. Alternatively, bin edges may be constructed automatically by passing a
  13608. sequence of integers specifying the number of equal-width bins in each dimension.
  13609. For each N-dimensional point in input:
  13610. - Each of its coordinates is binned independently among the bin edges
  13611. corresponding to its dimension
  13612. - Binning results are combined to identify the N-dimensional bin (if any)
  13613. into which the point falls
  13614. - If the point falls into a bin, the bin's count (or total weight) is incremented
  13615. - Points which do not fall into any bin do not contribute to the output
  13616. :attr:`bins` can be a sequence of N 1D tensors, a sequence of N ints, or a single int.
  13617. If :attr:`bins` is a sequence of N 1D tensors, it explicitly specifies the N sequences
  13618. of bin edges. Each 1D tensor should contain a strictly increasing sequence with at
  13619. least one element. A sequence of K bin edges defines K-1 bins, explicitly specifying
  13620. the left and right edges of all bins. Every bin is inclusive of its left edge. Only
  13621. the rightmost bin is inclusive of its right edge.
  13622. If :attr:`bins` is a sequence of N ints, it specifies the number of equal-width bins
  13623. in each dimension. By default, the leftmost and rightmost bin edges in each dimension
  13624. are determined by the minimum and maximum elements of the input tensor in the
  13625. corresponding dimension. The :attr:`range` argument can be provided to manually
  13626. specify the leftmost and rightmost bin edges in each dimension.
  13627. If :attr:`bins` is an int, it specifies the number of equal-width bins for all dimensions.
  13628. .. note::
  13629. See also :func:`torch.histogram`, which specifically computes 1D histograms.
  13630. While :func:`torch.histogramdd` infers the dimensionality of its bins and
  13631. binned values from the shape of :attr:`input`, :func:`torch.histogram`
  13632. accepts and flattens :attr:`input` of any shape.
  13633. Args:
  13634. input (Tensor): the input tensor.
  13635. bins: Tensor[], int[], or int.
  13636. If Tensor[], defines the sequences of bin edges.
  13637. If int[], defines the number of equal-width bins in each dimension.
  13638. If int, defines the number of equal-width bins for all dimensions.
  13639. Keyword args:
  13640. range (sequence of float): Defines the leftmost and rightmost bin edges
  13641. in each dimension.
  13642. weight (Tensor): By default, each value in the input has weight 1. If a weight
  13643. tensor is passed, each N-dimensional coordinate in input
  13644. contributes its associated weight towards its bin's result.
  13645. The weight tensor should have the same shape as the :attr:`input`
  13646. tensor excluding its innermost dimension N.
  13647. density (bool): If False (default), the result will contain the count (or total weight)
  13648. in each bin. If True, each count (weight) is divided by the total count
  13649. (total weight), then divided by the volume of its associated bin.
  13650. Returns:
  13651. hist (Tensor): N-dimensional Tensor containing the values of the histogram.
  13652. bin_edges(Tensor[]): sequence of N 1D Tensors containing the bin edges.
  13653. Example::
  13654. >>> torch.histogramdd(torch.tensor([[0., 1.], [1., 0.], [2., 0.], [2., 2.]]), bins=[3, 3],
  13655. ... weight=torch.tensor([1., 2., 4., 8.]))
  13656. torch.return_types.histogramdd(
  13657. hist=tensor([[0., 1., 0.],
  13658. [2., 0., 0.],
  13659. [4., 0., 8.]]),
  13660. bin_edges=(tensor([0.0000, 0.6667, 1.3333, 2.0000]),
  13661. tensor([0.0000, 0.6667, 1.3333, 2.0000])))
  13662. >>> torch.histogramdd(torch.tensor([[0., 0.], [1., 1.], [2., 2.]]), bins=[2, 2],
  13663. ... range=[0., 1., 0., 1.], density=True)
  13664. torch.return_types.histogramdd(
  13665. hist=tensor([[2., 0.],
  13666. [0., 2.]]),
  13667. bin_edges=(tensor([0.0000, 0.5000, 1.0000]),
  13668. tensor([0.0000, 0.5000, 1.0000])))
  13669. """
  13670. @overload
  13671. def histogramdd(
  13672. input: Tensor,
  13673. bins: _size,
  13674. range: Sequence[_float] | None = None,
  13675. weight: Tensor | None = None,
  13676. density: _bool = False,
  13677. ) -> torch.return_types.histogramdd:
  13678. r"""
  13679. histogramdd(input, bins, *, range=None, weight=None, density=False, out=None) -> (Tensor, Tensor[])
  13680. Computes a multi-dimensional histogram of the values in a tensor.
  13681. Interprets the elements of an input tensor whose innermost dimension has size N
  13682. as a collection of N-dimensional points. Maps each of the points into a set of
  13683. N-dimensional bins and returns the number of points (or total weight) in each bin.
  13684. :attr:`input` must be a tensor with at least 2 dimensions.
  13685. If input has shape (M, N), each of its M rows defines a point in N-dimensional space.
  13686. If input has three or more dimensions, all but the last dimension are flattened.
  13687. Each dimension is independently associated with its own strictly increasing sequence
  13688. of bin edges. Bin edges may be specified explicitly by passing a sequence of 1D
  13689. tensors. Alternatively, bin edges may be constructed automatically by passing a
  13690. sequence of integers specifying the number of equal-width bins in each dimension.
  13691. For each N-dimensional point in input:
  13692. - Each of its coordinates is binned independently among the bin edges
  13693. corresponding to its dimension
  13694. - Binning results are combined to identify the N-dimensional bin (if any)
  13695. into which the point falls
  13696. - If the point falls into a bin, the bin's count (or total weight) is incremented
  13697. - Points which do not fall into any bin do not contribute to the output
  13698. :attr:`bins` can be a sequence of N 1D tensors, a sequence of N ints, or a single int.
  13699. If :attr:`bins` is a sequence of N 1D tensors, it explicitly specifies the N sequences
  13700. of bin edges. Each 1D tensor should contain a strictly increasing sequence with at
  13701. least one element. A sequence of K bin edges defines K-1 bins, explicitly specifying
  13702. the left and right edges of all bins. Every bin is inclusive of its left edge. Only
  13703. the rightmost bin is inclusive of its right edge.
  13704. If :attr:`bins` is a sequence of N ints, it specifies the number of equal-width bins
  13705. in each dimension. By default, the leftmost and rightmost bin edges in each dimension
  13706. are determined by the minimum and maximum elements of the input tensor in the
  13707. corresponding dimension. The :attr:`range` argument can be provided to manually
  13708. specify the leftmost and rightmost bin edges in each dimension.
  13709. If :attr:`bins` is an int, it specifies the number of equal-width bins for all dimensions.
  13710. .. note::
  13711. See also :func:`torch.histogram`, which specifically computes 1D histograms.
  13712. While :func:`torch.histogramdd` infers the dimensionality of its bins and
  13713. binned values from the shape of :attr:`input`, :func:`torch.histogram`
  13714. accepts and flattens :attr:`input` of any shape.
  13715. Args:
  13716. input (Tensor): the input tensor.
  13717. bins: Tensor[], int[], or int.
  13718. If Tensor[], defines the sequences of bin edges.
  13719. If int[], defines the number of equal-width bins in each dimension.
  13720. If int, defines the number of equal-width bins for all dimensions.
  13721. Keyword args:
  13722. range (sequence of float): Defines the leftmost and rightmost bin edges
  13723. in each dimension.
  13724. weight (Tensor): By default, each value in the input has weight 1. If a weight
  13725. tensor is passed, each N-dimensional coordinate in input
  13726. contributes its associated weight towards its bin's result.
  13727. The weight tensor should have the same shape as the :attr:`input`
  13728. tensor excluding its innermost dimension N.
  13729. density (bool): If False (default), the result will contain the count (or total weight)
  13730. in each bin. If True, each count (weight) is divided by the total count
  13731. (total weight), then divided by the volume of its associated bin.
  13732. Returns:
  13733. hist (Tensor): N-dimensional Tensor containing the values of the histogram.
  13734. bin_edges(Tensor[]): sequence of N 1D Tensors containing the bin edges.
  13735. Example::
  13736. >>> torch.histogramdd(torch.tensor([[0., 1.], [1., 0.], [2., 0.], [2., 2.]]), bins=[3, 3],
  13737. ... weight=torch.tensor([1., 2., 4., 8.]))
  13738. torch.return_types.histogramdd(
  13739. hist=tensor([[0., 1., 0.],
  13740. [2., 0., 0.],
  13741. [4., 0., 8.]]),
  13742. bin_edges=(tensor([0.0000, 0.6667, 1.3333, 2.0000]),
  13743. tensor([0.0000, 0.6667, 1.3333, 2.0000])))
  13744. >>> torch.histogramdd(torch.tensor([[0., 0.], [1., 1.], [2., 2.]]), bins=[2, 2],
  13745. ... range=[0., 1., 0., 1.], density=True)
  13746. torch.return_types.histogramdd(
  13747. hist=tensor([[2., 0.],
  13748. [0., 2.]]),
  13749. bin_edges=(tensor([0.0000, 0.5000, 1.0000]),
  13750. tensor([0.0000, 0.5000, 1.0000])))
  13751. """
  13752. @overload
  13753. def histogramdd(
  13754. input: Tensor,
  13755. bins: tuple[Tensor, ...] | list[Tensor] | None,
  13756. range: Sequence[_float] | None = None,
  13757. weight: Tensor | None = None,
  13758. density: _bool = False,
  13759. ) -> torch.return_types.histogramdd:
  13760. r"""
  13761. histogramdd(input, bins, *, range=None, weight=None, density=False, out=None) -> (Tensor, Tensor[])
  13762. Computes a multi-dimensional histogram of the values in a tensor.
  13763. Interprets the elements of an input tensor whose innermost dimension has size N
  13764. as a collection of N-dimensional points. Maps each of the points into a set of
  13765. N-dimensional bins and returns the number of points (or total weight) in each bin.
  13766. :attr:`input` must be a tensor with at least 2 dimensions.
  13767. If input has shape (M, N), each of its M rows defines a point in N-dimensional space.
  13768. If input has three or more dimensions, all but the last dimension are flattened.
  13769. Each dimension is independently associated with its own strictly increasing sequence
  13770. of bin edges. Bin edges may be specified explicitly by passing a sequence of 1D
  13771. tensors. Alternatively, bin edges may be constructed automatically by passing a
  13772. sequence of integers specifying the number of equal-width bins in each dimension.
  13773. For each N-dimensional point in input:
  13774. - Each of its coordinates is binned independently among the bin edges
  13775. corresponding to its dimension
  13776. - Binning results are combined to identify the N-dimensional bin (if any)
  13777. into which the point falls
  13778. - If the point falls into a bin, the bin's count (or total weight) is incremented
  13779. - Points which do not fall into any bin do not contribute to the output
  13780. :attr:`bins` can be a sequence of N 1D tensors, a sequence of N ints, or a single int.
  13781. If :attr:`bins` is a sequence of N 1D tensors, it explicitly specifies the N sequences
  13782. of bin edges. Each 1D tensor should contain a strictly increasing sequence with at
  13783. least one element. A sequence of K bin edges defines K-1 bins, explicitly specifying
  13784. the left and right edges of all bins. Every bin is inclusive of its left edge. Only
  13785. the rightmost bin is inclusive of its right edge.
  13786. If :attr:`bins` is a sequence of N ints, it specifies the number of equal-width bins
  13787. in each dimension. By default, the leftmost and rightmost bin edges in each dimension
  13788. are determined by the minimum and maximum elements of the input tensor in the
  13789. corresponding dimension. The :attr:`range` argument can be provided to manually
  13790. specify the leftmost and rightmost bin edges in each dimension.
  13791. If :attr:`bins` is an int, it specifies the number of equal-width bins for all dimensions.
  13792. .. note::
  13793. See also :func:`torch.histogram`, which specifically computes 1D histograms.
  13794. While :func:`torch.histogramdd` infers the dimensionality of its bins and
  13795. binned values from the shape of :attr:`input`, :func:`torch.histogram`
  13796. accepts and flattens :attr:`input` of any shape.
  13797. Args:
  13798. input (Tensor): the input tensor.
  13799. bins: Tensor[], int[], or int.
  13800. If Tensor[], defines the sequences of bin edges.
  13801. If int[], defines the number of equal-width bins in each dimension.
  13802. If int, defines the number of equal-width bins for all dimensions.
  13803. Keyword args:
  13804. range (sequence of float): Defines the leftmost and rightmost bin edges
  13805. in each dimension.
  13806. weight (Tensor): By default, each value in the input has weight 1. If a weight
  13807. tensor is passed, each N-dimensional coordinate in input
  13808. contributes its associated weight towards its bin's result.
  13809. The weight tensor should have the same shape as the :attr:`input`
  13810. tensor excluding its innermost dimension N.
  13811. density (bool): If False (default), the result will contain the count (or total weight)
  13812. in each bin. If True, each count (weight) is divided by the total count
  13813. (total weight), then divided by the volume of its associated bin.
  13814. Returns:
  13815. hist (Tensor): N-dimensional Tensor containing the values of the histogram.
  13816. bin_edges(Tensor[]): sequence of N 1D Tensors containing the bin edges.
  13817. Example::
  13818. >>> torch.histogramdd(torch.tensor([[0., 1.], [1., 0.], [2., 0.], [2., 2.]]), bins=[3, 3],
  13819. ... weight=torch.tensor([1., 2., 4., 8.]))
  13820. torch.return_types.histogramdd(
  13821. hist=tensor([[0., 1., 0.],
  13822. [2., 0., 0.],
  13823. [4., 0., 8.]]),
  13824. bin_edges=(tensor([0.0000, 0.6667, 1.3333, 2.0000]),
  13825. tensor([0.0000, 0.6667, 1.3333, 2.0000])))
  13826. >>> torch.histogramdd(torch.tensor([[0., 0.], [1., 1.], [2., 2.]]), bins=[2, 2],
  13827. ... range=[0., 1., 0., 1.], density=True)
  13828. torch.return_types.histogramdd(
  13829. hist=tensor([[2., 0.],
  13830. [0., 2.]]),
  13831. bin_edges=(tensor([0.0000, 0.5000, 1.0000]),
  13832. tensor([0.0000, 0.5000, 1.0000])))
  13833. """
  13834. def hsmm(input: Tensor, mat2: Tensor) -> Tensor: ...
  13835. @overload
  13836. def hsplit(input: Tensor, sections: _int) -> tuple[Tensor, ...]:
  13837. r"""
  13838. hsplit(input, indices_or_sections) -> List of Tensors
  13839. Splits :attr:`input`, a tensor with one or more dimensions, into multiple tensors
  13840. horizontally according to :attr:`indices_or_sections`. Each split is a view of
  13841. :attr:`input`.
  13842. If :attr:`input` is one dimensional this is equivalent to calling
  13843. torch.tensor_split(input, indices_or_sections, dim=0) (the split dimension is
  13844. zero), and if :attr:`input` has two or more dimensions it's equivalent to calling
  13845. torch.tensor_split(input, indices_or_sections, dim=1) (the split dimension is 1),
  13846. except that if :attr:`indices_or_sections` is an integer it must evenly divide
  13847. the split dimension or a runtime error will be thrown.
  13848. This function is based on NumPy's :func:`numpy.hsplit`.
  13849. Args:
  13850. input (Tensor): tensor to split.
  13851. indices_or_sections (int or list or tuple of ints): See argument in :func:`torch.tensor_split`.
  13852. Example::
  13853. >>> t = torch.arange(16.0).reshape(4,4)
  13854. >>> t
  13855. tensor([[ 0., 1., 2., 3.],
  13856. [ 4., 5., 6., 7.],
  13857. [ 8., 9., 10., 11.],
  13858. [12., 13., 14., 15.]])
  13859. >>> torch.hsplit(t, 2)
  13860. (tensor([[ 0., 1.],
  13861. [ 4., 5.],
  13862. [ 8., 9.],
  13863. [12., 13.]]),
  13864. tensor([[ 2., 3.],
  13865. [ 6., 7.],
  13866. [10., 11.],
  13867. [14., 15.]]))
  13868. >>> torch.hsplit(t, [3, 6])
  13869. (tensor([[ 0., 1., 2.],
  13870. [ 4., 5., 6.],
  13871. [ 8., 9., 10.],
  13872. [12., 13., 14.]]),
  13873. tensor([[ 3.],
  13874. [ 7.],
  13875. [11.],
  13876. [15.]]),
  13877. tensor([], size=(4, 0)))
  13878. """
  13879. @overload
  13880. def hsplit(input: Tensor, indices: _size) -> tuple[Tensor, ...]:
  13881. r"""
  13882. hsplit(input, indices_or_sections) -> List of Tensors
  13883. Splits :attr:`input`, a tensor with one or more dimensions, into multiple tensors
  13884. horizontally according to :attr:`indices_or_sections`. Each split is a view of
  13885. :attr:`input`.
  13886. If :attr:`input` is one dimensional this is equivalent to calling
  13887. torch.tensor_split(input, indices_or_sections, dim=0) (the split dimension is
  13888. zero), and if :attr:`input` has two or more dimensions it's equivalent to calling
  13889. torch.tensor_split(input, indices_or_sections, dim=1) (the split dimension is 1),
  13890. except that if :attr:`indices_or_sections` is an integer it must evenly divide
  13891. the split dimension or a runtime error will be thrown.
  13892. This function is based on NumPy's :func:`numpy.hsplit`.
  13893. Args:
  13894. input (Tensor): tensor to split.
  13895. indices_or_sections (int or list or tuple of ints): See argument in :func:`torch.tensor_split`.
  13896. Example::
  13897. >>> t = torch.arange(16.0).reshape(4,4)
  13898. >>> t
  13899. tensor([[ 0., 1., 2., 3.],
  13900. [ 4., 5., 6., 7.],
  13901. [ 8., 9., 10., 11.],
  13902. [12., 13., 14., 15.]])
  13903. >>> torch.hsplit(t, 2)
  13904. (tensor([[ 0., 1.],
  13905. [ 4., 5.],
  13906. [ 8., 9.],
  13907. [12., 13.]]),
  13908. tensor([[ 2., 3.],
  13909. [ 6., 7.],
  13910. [10., 11.],
  13911. [14., 15.]]))
  13912. >>> torch.hsplit(t, [3, 6])
  13913. (tensor([[ 0., 1., 2.],
  13914. [ 4., 5., 6.],
  13915. [ 8., 9., 10.],
  13916. [12., 13., 14.]]),
  13917. tensor([[ 3.],
  13918. [ 7.],
  13919. [11.],
  13920. [15.]]),
  13921. tensor([], size=(4, 0)))
  13922. """
  13923. def hspmm(
  13924. mat1: Tensor,
  13925. mat2: Tensor,
  13926. *,
  13927. out: Tensor | None = None,
  13928. ) -> Tensor:
  13929. r"""
  13930. hspmm(mat1, mat2, *, out=None) -> Tensor
  13931. Performs a matrix multiplication of a :ref:`sparse COO matrix
  13932. <sparse-coo-docs>` :attr:`mat1` and a strided matrix :attr:`mat2`. The
  13933. result is a (1 + 1)-dimensional :ref:`hybrid COO matrix
  13934. <sparse-hybrid-coo-docs>`.
  13935. Args:
  13936. mat1 (Tensor): the first sparse matrix to be matrix multiplied
  13937. mat2 (Tensor): the second strided matrix to be matrix multiplied
  13938. Keyword args:
  13939. out (Tensor, optional): the output tensor.
  13940. """
  13941. def hstack(
  13942. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  13943. *,
  13944. out: Tensor | None = None,
  13945. ) -> Tensor:
  13946. r"""
  13947. hstack(tensors, *, out=None) -> Tensor
  13948. Stack tensors in sequence horizontally (column wise).
  13949. This is equivalent to concatenation along the first axis for 1-D tensors, and along the second axis for all other tensors.
  13950. Args:
  13951. tensors (sequence of Tensors): sequence of tensors to concatenate
  13952. Keyword args:
  13953. out (Tensor, optional): the output tensor.
  13954. Example::
  13955. >>> a = torch.tensor([1, 2, 3])
  13956. >>> b = torch.tensor([4, 5, 6])
  13957. >>> torch.hstack((a,b))
  13958. tensor([1, 2, 3, 4, 5, 6])
  13959. >>> a = torch.tensor([[1],[2],[3]])
  13960. >>> b = torch.tensor([[4],[5],[6]])
  13961. >>> torch.hstack((a,b))
  13962. tensor([[1, 4],
  13963. [2, 5],
  13964. [3, 6]])
  13965. """
  13966. def hypot(
  13967. input: Tensor,
  13968. other: Tensor,
  13969. *,
  13970. out: Tensor | None = None,
  13971. ) -> Tensor:
  13972. r"""
  13973. hypot(input, other, *, out=None) -> Tensor
  13974. Given the legs of a right triangle, return its hypotenuse.
  13975. .. math::
  13976. \text{out}_{i} = \sqrt{\text{input}_{i}^{2} + \text{other}_{i}^{2}}
  13977. The shapes of ``input`` and ``other`` must be
  13978. :ref:`broadcastable <broadcasting-semantics>`.
  13979. Args:
  13980. input (Tensor): the first input tensor
  13981. other (Tensor): the second input tensor
  13982. Keyword args:
  13983. out (Tensor, optional): the output tensor.
  13984. Example::
  13985. >>> a = torch.hypot(torch.tensor([4.0]), torch.tensor([3.0, 4.0, 5.0]))
  13986. tensor([5.0000, 5.6569, 6.4031])
  13987. """
  13988. def i0(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  13989. r"""
  13990. i0(input, *, out=None) -> Tensor
  13991. Alias for :func:`torch.special.i0`.
  13992. """
  13993. def i0_(input: Tensor) -> Tensor: ...
  13994. def igamma(
  13995. input: Tensor,
  13996. other: Tensor,
  13997. *,
  13998. out: Tensor | None = None,
  13999. ) -> Tensor:
  14000. r"""
  14001. igamma(input, other, *, out=None) -> Tensor
  14002. Alias for :func:`torch.special.gammainc`.
  14003. """
  14004. def igammac(
  14005. input: Tensor,
  14006. other: Tensor,
  14007. *,
  14008. out: Tensor | None = None,
  14009. ) -> Tensor:
  14010. r"""
  14011. igammac(input, other, *, out=None) -> Tensor
  14012. Alias for :func:`torch.special.gammaincc`.
  14013. """
  14014. def imag(input: Tensor) -> Tensor:
  14015. r"""
  14016. imag(input) -> Tensor
  14017. Returns a new tensor containing imaginary values of the :attr:`self` tensor.
  14018. The returned tensor and :attr:`self` share the same underlying storage.
  14019. .. warning::
  14020. :func:`imag` is only supported for tensors with complex dtypes.
  14021. Args:
  14022. input (Tensor): the input tensor.
  14023. Example::
  14024. >>> x=torch.randn(4, dtype=torch.cfloat)
  14025. >>> x
  14026. tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
  14027. >>> x.imag
  14028. tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
  14029. """
  14030. @overload
  14031. def index_add(
  14032. input: Tensor,
  14033. dim: _int,
  14034. index: Tensor,
  14035. source: Tensor,
  14036. *,
  14037. alpha: Number | _complex = 1,
  14038. out: Tensor | None = None,
  14039. ) -> Tensor:
  14040. r"""
  14041. index_add(input: Tensor, dim: int, index: Tensor, source: Tensor, *, alpha: Union[Number, _complex] = 1, out: Optional[Tensor]) -> Tensor # noqa: B950
  14042. See :meth:`~Tensor.index_add_` for function description.
  14043. """
  14044. @overload
  14045. def index_add(
  14046. input: Tensor,
  14047. dim: str | EllipsisType | None,
  14048. index: Tensor,
  14049. source: Tensor,
  14050. *,
  14051. alpha: Number | _complex = 1,
  14052. ) -> Tensor:
  14053. r"""
  14054. index_add(input: Tensor, dim: int, index: Tensor, source: Tensor, *, alpha: Union[Number, _complex] = 1, out: Optional[Tensor]) -> Tensor # noqa: B950
  14055. See :meth:`~Tensor.index_add_` for function description.
  14056. """
  14057. @overload
  14058. def index_copy(
  14059. input: Tensor,
  14060. dim: _int,
  14061. index: Tensor,
  14062. source: Tensor,
  14063. *,
  14064. out: Tensor | None = None,
  14065. ) -> Tensor:
  14066. r"""
  14067. index_copy(input: Tensor, dim: int, index: Tensor, source: Tensor, *, out: Optional[Tensor]) -> Tensor
  14068. See :meth:`~Tensor.index_add_` for function description.
  14069. """
  14070. @overload
  14071. def index_copy(
  14072. input: Tensor,
  14073. dim: str | EllipsisType | None,
  14074. index: Tensor,
  14075. source: Tensor,
  14076. ) -> Tensor:
  14077. r"""
  14078. index_copy(input: Tensor, dim: int, index: Tensor, source: Tensor, *, out: Optional[Tensor]) -> Tensor
  14079. See :meth:`~Tensor.index_add_` for function description.
  14080. """
  14081. @overload
  14082. def index_fill(
  14083. input: Tensor,
  14084. dim: _int,
  14085. index: Tensor,
  14086. value: Tensor,
  14087. ) -> Tensor: ...
  14088. @overload
  14089. def index_fill(
  14090. input: Tensor,
  14091. dim: str | EllipsisType | None,
  14092. index: Tensor,
  14093. value: Tensor,
  14094. ) -> Tensor: ...
  14095. @overload
  14096. def index_fill(
  14097. input: Tensor,
  14098. dim: _int,
  14099. index: Tensor,
  14100. value: Number | _complex,
  14101. ) -> Tensor: ...
  14102. @overload
  14103. def index_fill(
  14104. input: Tensor,
  14105. dim: str | EllipsisType | None,
  14106. index: Tensor,
  14107. value: Number | _complex,
  14108. ) -> Tensor: ...
  14109. def index_put(
  14110. input: Tensor,
  14111. indices: tuple[Tensor, ...] | list[Tensor] | None,
  14112. values: Tensor,
  14113. accumulate: _bool = False,
  14114. ) -> Tensor: ...
  14115. def index_put_(
  14116. input: Tensor,
  14117. indices: tuple[Tensor, ...] | list[Tensor] | None,
  14118. values: Tensor,
  14119. accumulate: _bool = False,
  14120. ) -> Tensor: ...
  14121. def index_reduce(
  14122. input: Tensor,
  14123. dim: _int,
  14124. index: Tensor,
  14125. source: Tensor,
  14126. reduce: str,
  14127. *,
  14128. include_self: _bool = True,
  14129. out: Tensor | None = None,
  14130. ) -> Tensor:
  14131. r"""
  14132. index_reduce(input: Tensor, dim: int, index: Tensor, source: Tensor, reduce: str, *, include_self: bool = True, out: Optional[Tensor]) -> Tensor # noqa: B950
  14133. See :meth:`~Tensor.index_reduce_` for function description.
  14134. """
  14135. @overload
  14136. def index_select(
  14137. input: Tensor,
  14138. dim: _int,
  14139. index: Tensor,
  14140. *,
  14141. out: Tensor | None = None,
  14142. ) -> Tensor:
  14143. r"""
  14144. index_select(input, dim, index, *, out=None) -> Tensor
  14145. Returns a new tensor which indexes the :attr:`input` tensor along dimension
  14146. :attr:`dim` using the entries in :attr:`index`.
  14147. The returned tensor has the same number of dimensions as the original tensor
  14148. (:attr:`input`). The :attr:`dim`\ th dimension has the same size as the length
  14149. of :attr:`index`; other dimensions have the same size as in the original tensor.
  14150. .. note:: The returned tensor does **not** use the same storage as the original
  14151. tensor. If :attr:`out` has a different shape than expected, we
  14152. silently change it to the correct shape, reallocating the underlying
  14153. storage if necessary.
  14154. Args:
  14155. input (Tensor): the input tensor.
  14156. dim (int): the dimension in which we index
  14157. index (IntTensor or LongTensor): the 1-D tensor containing the indices to index
  14158. Keyword args:
  14159. out (Tensor, optional): the output tensor.
  14160. Example::
  14161. >>> x = torch.randn(3, 4)
  14162. >>> x
  14163. tensor([[ 0.1427, 0.0231, -0.5414, -1.0009],
  14164. [-0.4664, 0.2647, -0.1228, -1.1068],
  14165. [-1.1734, -0.6571, 0.7230, -0.6004]])
  14166. >>> indices = torch.tensor([0, 2])
  14167. >>> torch.index_select(x, 0, indices)
  14168. tensor([[ 0.1427, 0.0231, -0.5414, -1.0009],
  14169. [-1.1734, -0.6571, 0.7230, -0.6004]])
  14170. >>> torch.index_select(x, 1, indices)
  14171. tensor([[ 0.1427, -0.5414],
  14172. [-0.4664, -0.1228],
  14173. [-1.1734, 0.7230]])
  14174. """
  14175. @overload
  14176. def index_select(
  14177. input: Tensor,
  14178. dim: str | EllipsisType | None,
  14179. index: Tensor,
  14180. *,
  14181. out: Tensor | None = None,
  14182. ) -> Tensor:
  14183. r"""
  14184. index_select(input, dim, index, *, out=None) -> Tensor
  14185. Returns a new tensor which indexes the :attr:`input` tensor along dimension
  14186. :attr:`dim` using the entries in :attr:`index`.
  14187. The returned tensor has the same number of dimensions as the original tensor
  14188. (:attr:`input`). The :attr:`dim`\ th dimension has the same size as the length
  14189. of :attr:`index`; other dimensions have the same size as in the original tensor.
  14190. .. note:: The returned tensor does **not** use the same storage as the original
  14191. tensor. If :attr:`out` has a different shape than expected, we
  14192. silently change it to the correct shape, reallocating the underlying
  14193. storage if necessary.
  14194. Args:
  14195. input (Tensor): the input tensor.
  14196. dim (int): the dimension in which we index
  14197. index (IntTensor or LongTensor): the 1-D tensor containing the indices to index
  14198. Keyword args:
  14199. out (Tensor, optional): the output tensor.
  14200. Example::
  14201. >>> x = torch.randn(3, 4)
  14202. >>> x
  14203. tensor([[ 0.1427, 0.0231, -0.5414, -1.0009],
  14204. [-0.4664, 0.2647, -0.1228, -1.1068],
  14205. [-1.1734, -0.6571, 0.7230, -0.6004]])
  14206. >>> indices = torch.tensor([0, 2])
  14207. >>> torch.index_select(x, 0, indices)
  14208. tensor([[ 0.1427, 0.0231, -0.5414, -1.0009],
  14209. [-1.1734, -0.6571, 0.7230, -0.6004]])
  14210. >>> torch.index_select(x, 1, indices)
  14211. tensor([[ 0.1427, -0.5414],
  14212. [-0.4664, -0.1228],
  14213. [-1.1734, 0.7230]])
  14214. """
  14215. def indices_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  14216. r"""
  14217. Performs the same operation as :func:`torch.indices`, but all output tensors
  14218. are freshly created instead of aliasing the input.
  14219. """
  14220. def init_num_threads() -> None: ...
  14221. def inner(
  14222. input: Tensor,
  14223. other: Tensor,
  14224. *,
  14225. out: Tensor | None = None,
  14226. ) -> Tensor:
  14227. r"""
  14228. inner(input, other, *, out=None) -> Tensor
  14229. Computes the dot product for 1D tensors. For higher dimensions, sums the product
  14230. of elements from :attr:`input` and :attr:`other` along their last dimension.
  14231. .. note::
  14232. If either :attr:`input` or :attr:`other` is a scalar, the result is equivalent
  14233. to `torch.mul(input, other)`.
  14234. If both :attr:`input` and :attr:`other` are non-scalars, the size of their last
  14235. dimension must match and the result is equivalent to `torch.tensordot(input,
  14236. other, dims=([-1], [-1]))`
  14237. Args:
  14238. input (Tensor): First input tensor
  14239. other (Tensor): Second input tensor
  14240. Keyword args:
  14241. out (Tensor, optional): Optional output tensor to write result into. The output
  14242. shape is `input.shape[:-1] + other.shape[:-1]`.
  14243. Example::
  14244. # Dot product
  14245. >>> torch.inner(torch.tensor([1, 2, 3]), torch.tensor([0, 2, 1]))
  14246. tensor(7)
  14247. # Multidimensional input tensors
  14248. >>> a = torch.randn(2, 3)
  14249. >>> a
  14250. tensor([[0.8173, 1.0874, 1.1784],
  14251. [0.3279, 0.1234, 2.7894]])
  14252. >>> b = torch.randn(2, 4, 3)
  14253. >>> b
  14254. tensor([[[-0.4682, -0.7159, 0.1506],
  14255. [ 0.4034, -0.3657, 1.0387],
  14256. [ 0.9892, -0.6684, 0.1774],
  14257. [ 0.9482, 1.3261, 0.3917]],
  14258. [[ 0.4537, 0.7493, 1.1724],
  14259. [ 0.2291, 0.5749, -0.2267],
  14260. [-0.7920, 0.3607, -0.3701],
  14261. [ 1.3666, -0.5850, -1.7242]]])
  14262. >>> torch.inner(a, b)
  14263. tensor([[[-0.9837, 1.1560, 0.2907, 2.6785],
  14264. [ 2.5671, 0.5452, -0.6912, -1.5509]],
  14265. [[ 0.1782, 2.9843, 0.7366, 1.5672],
  14266. [ 3.5115, -0.4864, -1.2476, -4.4337]]])
  14267. # Scalar input
  14268. >>> torch.inner(a, torch.tensor(2))
  14269. tensor([[1.6347, 2.1748, 2.3567],
  14270. [0.6558, 0.2469, 5.5787]])
  14271. """
  14272. def instance_norm(
  14273. input: Tensor,
  14274. weight: Tensor | None,
  14275. bias: Tensor | None,
  14276. running_mean: Tensor | None,
  14277. running_var: Tensor | None,
  14278. use_input_stats: _bool,
  14279. momentum: _float,
  14280. eps: _float,
  14281. cudnn_enabled: _bool,
  14282. ) -> Tensor: ...
  14283. def int_repr(input: Tensor) -> Tensor: ...
  14284. def inverse(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  14285. r"""
  14286. inverse(input, *, out=None) -> Tensor
  14287. Alias for :func:`torch.linalg.inv`
  14288. """
  14289. def is_complex(input: Tensor) -> _bool:
  14290. r"""
  14291. is_complex(input: Tensor) -> bool
  14292. Returns True if the data type of :attr:`input` is a complex data type i.e.,
  14293. one of ``torch.complex64``, and ``torch.complex128``.
  14294. Args:
  14295. input (Tensor): the input tensor.
  14296. Example::
  14297. >>> torch.is_complex(torch.tensor([1, 2, 3], dtype=torch.complex64))
  14298. True
  14299. >>> torch.is_complex(torch.tensor([1, 2, 3], dtype=torch.complex128))
  14300. True
  14301. >>> torch.is_complex(torch.tensor([1, 2, 3], dtype=torch.int32))
  14302. False
  14303. >>> torch.is_complex(torch.tensor([1.0, 2.0, 3.0], dtype=torch.float16))
  14304. False
  14305. """
  14306. def is_conj(input: Tensor) -> _bool:
  14307. r"""
  14308. is_conj(input) -> (bool)
  14309. Returns True if the :attr:`input` is a conjugated tensor, i.e. its conjugate bit is set to `True`.
  14310. Args:
  14311. input (Tensor): the input tensor.
  14312. """
  14313. def is_distributed(input: Tensor) -> _bool: ...
  14314. def is_floating_point(input: Tensor) -> _bool:
  14315. r"""
  14316. is_floating_point(input: Tensor) -> bool
  14317. Returns True if the data type of :attr:`input` is a floating point data type i.e.,
  14318. one of ``torch.float64``, ``torch.float32``, ``torch.float16``, and ``torch.bfloat16``.
  14319. Args:
  14320. input (Tensor): the input tensor.
  14321. Example::
  14322. >>> torch.is_floating_point(torch.tensor([1.0, 2.0, 3.0]))
  14323. True
  14324. >>> torch.is_floating_point(torch.tensor([1, 2, 3], dtype=torch.int32))
  14325. False
  14326. >>> torch.is_floating_point(torch.tensor([1.0, 2.0, 3.0], dtype=torch.float16))
  14327. True
  14328. >>> torch.is_floating_point(torch.tensor([1, 2, 3], dtype=torch.complex64))
  14329. False
  14330. """
  14331. def is_grad_enabled() -> _bool:
  14332. r"""
  14333. is_grad_enabled() -> (bool)
  14334. Returns True if grad mode is currently enabled.
  14335. """
  14336. def is_inference(input: Tensor) -> _bool:
  14337. r"""
  14338. is_inference(input) -> (bool)
  14339. Returns True if :attr:`input` is an inference tensor.
  14340. A non-view tensor is an inference tensor if and only if it was
  14341. allocated during inference mode. A view tensor is an inference
  14342. tensor if and only if the tensor it is a view of is an inference tensor.
  14343. For details on inference mode please see
  14344. `Inference Mode <https://pytorch.org/cppdocs/notes/inference_mode.html>`_.
  14345. Args:
  14346. input (Tensor): the input tensor.
  14347. """
  14348. def is_inference_mode_enabled() -> _bool:
  14349. r"""
  14350. is_inference_mode_enabled() -> (bool)
  14351. Returns True if inference mode is currently enabled.
  14352. """
  14353. def is_neg(input: Tensor) -> _bool: ...
  14354. def is_nonzero(input: Tensor) -> _bool:
  14355. r"""
  14356. is_nonzero(input) -> (bool)
  14357. Returns True if the :attr:`input` is a single element tensor which is not equal to zero
  14358. after type conversions.
  14359. i.e. not equal to ``torch.tensor([0.])`` or ``torch.tensor([0])`` or
  14360. ``torch.tensor([False])``.
  14361. Throws a ``RuntimeError`` if ``torch.numel() != 1`` (even in case
  14362. of sparse tensors).
  14363. Args:
  14364. input (Tensor): the input tensor.
  14365. Examples::
  14366. >>> torch.is_nonzero(torch.tensor([0.]))
  14367. False
  14368. >>> torch.is_nonzero(torch.tensor([1.5]))
  14369. True
  14370. >>> torch.is_nonzero(torch.tensor([False]))
  14371. False
  14372. >>> torch.is_nonzero(torch.tensor([3]))
  14373. True
  14374. >>> torch.is_nonzero(torch.tensor([1, 3, 5]))
  14375. Traceback (most recent call last):
  14376. ...
  14377. RuntimeError: Boolean value of Tensor with more than one value is ambiguous
  14378. >>> torch.is_nonzero(torch.tensor([]))
  14379. Traceback (most recent call last):
  14380. ...
  14381. RuntimeError: Boolean value of Tensor with no values is ambiguous
  14382. """
  14383. def is_same_size(input: Tensor, other: Tensor) -> _bool: ...
  14384. def is_signed(input: Tensor) -> _bool: ...
  14385. def is_vulkan_available() -> _bool: ...
  14386. def isclose(
  14387. input: Tensor,
  14388. other: Tensor,
  14389. rtol: _float = 1e-05,
  14390. atol: _float = 1e-08,
  14391. equal_nan: _bool = False,
  14392. ) -> Tensor:
  14393. r"""
  14394. isclose(input, other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
  14395. Returns a new tensor with boolean elements representing if each element of
  14396. :attr:`input` is "close" to the corresponding element of :attr:`other`.
  14397. Closeness is defined as:
  14398. .. math::
  14399. \lvert \text{input}_i - \text{other}_i \rvert \leq \texttt{rtol} \times \lvert \text{other}_i \rvert + \texttt{atol}
  14400. where :attr:`input` and :attr:`other` are finite. Where :attr:`input`
  14401. and/or :attr:`other` are nonfinite they are close if and only if
  14402. they are equal, with NaNs being considered equal to each other when
  14403. :attr:`equal_nan` is True.
  14404. Args:
  14405. input (Tensor): first tensor to compare
  14406. other (Tensor): second tensor to compare
  14407. rtol (float, optional): relative tolerance. Default: 1e-05
  14408. atol (float, optional): absolute tolerance. Default: 1e-08
  14409. equal_nan (bool, optional): if ``True``, then two ``NaN`` s will be considered equal. Default: ``False``
  14410. Examples::
  14411. >>> torch.isclose(torch.tensor((1., 2, 3)), torch.tensor((1 + 1e-10, 3, 4)))
  14412. tensor([ True, False, False])
  14413. >>> torch.isclose(torch.tensor((float('inf'), 4)), torch.tensor((float('inf'), 6)), rtol=.5)
  14414. tensor([True, True])
  14415. """
  14416. def isfinite(input: Tensor) -> Tensor:
  14417. r"""
  14418. isfinite(input) -> Tensor
  14419. Returns a new tensor with boolean elements representing if each element is `finite` or not.
  14420. Real values are finite when they are not NaN, negative infinity, or infinity.
  14421. Complex values are finite when both their real and imaginary parts are finite.
  14422. Args:
  14423. input (Tensor): the input tensor.
  14424. Returns:
  14425. A boolean tensor that is True where :attr:`input` is finite and False elsewhere
  14426. Example::
  14427. >>> torch.isfinite(torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')]))
  14428. tensor([True, False, True, False, False])
  14429. """
  14430. @overload
  14431. def isin(
  14432. elements: Tensor,
  14433. test_elements: Tensor,
  14434. *,
  14435. assume_unique: _bool = False,
  14436. invert: _bool = False,
  14437. out: Tensor | None = None,
  14438. ) -> Tensor:
  14439. r"""
  14440. isin(elements, test_elements, *, assume_unique=False, invert=False) -> Tensor
  14441. Tests if each element of :attr:`elements` is in :attr:`test_elements`. Returns
  14442. a boolean tensor of the same shape as :attr:`elements` that is True for elements
  14443. in :attr:`test_elements` and False otherwise.
  14444. .. note::
  14445. One of :attr:`elements` or :attr:`test_elements` can be a scalar, but not both.
  14446. Args:
  14447. elements (Tensor or Scalar): Input elements
  14448. test_elements (Tensor or Scalar): Values against which to test for each input element
  14449. assume_unique (bool, optional): If True, assumes both :attr:`elements` and
  14450. :attr:`test_elements` contain unique elements, which can speed up the
  14451. calculation. Default: False
  14452. invert (bool, optional): If True, inverts the boolean return tensor, resulting in True
  14453. values for elements *not* in :attr:`test_elements`. Default: False
  14454. Returns:
  14455. A boolean tensor of the same shape as :attr:`elements` that is True for elements in
  14456. :attr:`test_elements` and False otherwise
  14457. Example:
  14458. >>> torch.isin(torch.tensor([[1, 2], [3, 4]]), torch.tensor([2, 3]))
  14459. tensor([[False, True],
  14460. [ True, False]])
  14461. """
  14462. @overload
  14463. def isin(
  14464. element: Number | _complex,
  14465. test_elements: Tensor,
  14466. *,
  14467. assume_unique: _bool = False,
  14468. invert: _bool = False,
  14469. out: Tensor | None = None,
  14470. ) -> Tensor:
  14471. r"""
  14472. isin(elements, test_elements, *, assume_unique=False, invert=False) -> Tensor
  14473. Tests if each element of :attr:`elements` is in :attr:`test_elements`. Returns
  14474. a boolean tensor of the same shape as :attr:`elements` that is True for elements
  14475. in :attr:`test_elements` and False otherwise.
  14476. .. note::
  14477. One of :attr:`elements` or :attr:`test_elements` can be a scalar, but not both.
  14478. Args:
  14479. elements (Tensor or Scalar): Input elements
  14480. test_elements (Tensor or Scalar): Values against which to test for each input element
  14481. assume_unique (bool, optional): If True, assumes both :attr:`elements` and
  14482. :attr:`test_elements` contain unique elements, which can speed up the
  14483. calculation. Default: False
  14484. invert (bool, optional): If True, inverts the boolean return tensor, resulting in True
  14485. values for elements *not* in :attr:`test_elements`. Default: False
  14486. Returns:
  14487. A boolean tensor of the same shape as :attr:`elements` that is True for elements in
  14488. :attr:`test_elements` and False otherwise
  14489. Example:
  14490. >>> torch.isin(torch.tensor([[1, 2], [3, 4]]), torch.tensor([2, 3]))
  14491. tensor([[False, True],
  14492. [ True, False]])
  14493. """
  14494. @overload
  14495. def isin(
  14496. elements: Tensor,
  14497. test_element: Number | _complex,
  14498. *,
  14499. assume_unique: _bool = False,
  14500. invert: _bool = False,
  14501. out: Tensor | None = None,
  14502. ) -> Tensor:
  14503. r"""
  14504. isin(elements, test_elements, *, assume_unique=False, invert=False) -> Tensor
  14505. Tests if each element of :attr:`elements` is in :attr:`test_elements`. Returns
  14506. a boolean tensor of the same shape as :attr:`elements` that is True for elements
  14507. in :attr:`test_elements` and False otherwise.
  14508. .. note::
  14509. One of :attr:`elements` or :attr:`test_elements` can be a scalar, but not both.
  14510. Args:
  14511. elements (Tensor or Scalar): Input elements
  14512. test_elements (Tensor or Scalar): Values against which to test for each input element
  14513. assume_unique (bool, optional): If True, assumes both :attr:`elements` and
  14514. :attr:`test_elements` contain unique elements, which can speed up the
  14515. calculation. Default: False
  14516. invert (bool, optional): If True, inverts the boolean return tensor, resulting in True
  14517. values for elements *not* in :attr:`test_elements`. Default: False
  14518. Returns:
  14519. A boolean tensor of the same shape as :attr:`elements` that is True for elements in
  14520. :attr:`test_elements` and False otherwise
  14521. Example:
  14522. >>> torch.isin(torch.tensor([[1, 2], [3, 4]]), torch.tensor([2, 3]))
  14523. tensor([[False, True],
  14524. [ True, False]])
  14525. """
  14526. def isinf(input: Tensor) -> Tensor:
  14527. r"""
  14528. isinf(input) -> Tensor
  14529. Tests if each element of :attr:`input` is infinite
  14530. (positive or negative infinity) or not.
  14531. .. note::
  14532. Complex values are infinite when their real or imaginary part is
  14533. infinite.
  14534. Args:
  14535. input (Tensor): the input tensor.
  14536. Returns:
  14537. A boolean tensor that is True where :attr:`input` is infinite and False elsewhere
  14538. Example::
  14539. >>> torch.isinf(torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')]))
  14540. tensor([False, True, False, True, False])
  14541. """
  14542. def isnan(input: Tensor) -> Tensor:
  14543. r"""
  14544. isnan(input) -> Tensor
  14545. Returns a new tensor with boolean elements representing if each element of :attr:`input`
  14546. is NaN or not. Complex values are considered NaN when either their real
  14547. and/or imaginary part is NaN.
  14548. Arguments:
  14549. input (Tensor): the input tensor.
  14550. Returns:
  14551. A boolean tensor that is True where :attr:`input` is NaN and False elsewhere
  14552. Example::
  14553. >>> torch.isnan(torch.tensor([1, float('nan'), 2]))
  14554. tensor([False, True, False])
  14555. """
  14556. def isneginf(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  14557. r"""
  14558. isneginf(input, *, out=None) -> Tensor
  14559. Tests if each element of :attr:`input` is negative infinity or not.
  14560. Args:
  14561. input (Tensor): the input tensor.
  14562. Keyword args:
  14563. out (Tensor, optional): the output tensor.
  14564. Example::
  14565. >>> a = torch.tensor([-float('inf'), float('inf'), 1.2])
  14566. >>> torch.isneginf(a)
  14567. tensor([ True, False, False])
  14568. """
  14569. def isposinf(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  14570. r"""
  14571. isposinf(input, *, out=None) -> Tensor
  14572. Tests if each element of :attr:`input` is positive infinity or not.
  14573. Args:
  14574. input (Tensor): the input tensor.
  14575. Keyword args:
  14576. out (Tensor, optional): the output tensor.
  14577. Example::
  14578. >>> a = torch.tensor([-float('inf'), float('inf'), 1.2])
  14579. >>> torch.isposinf(a)
  14580. tensor([False, True, False])
  14581. """
  14582. def isreal(input: Tensor) -> Tensor:
  14583. r"""
  14584. isreal(input) -> Tensor
  14585. Returns a new tensor with boolean elements representing if each element of :attr:`input` is real-valued or not.
  14586. All real-valued types are considered real. Complex values are considered real when their imaginary part is 0.
  14587. Arguments:
  14588. input (Tensor): the input tensor.
  14589. Returns:
  14590. A boolean tensor that is True where :attr:`input` is real and False elsewhere
  14591. Example::
  14592. >>> torch.isreal(torch.tensor([1, 1+1j, 2+0j]))
  14593. tensor([True, False, True])
  14594. """
  14595. def istft(
  14596. input: Tensor,
  14597. n_fft: _int,
  14598. hop_length: _int | None = None,
  14599. win_length: _int | None = None,
  14600. window: Tensor | None = None,
  14601. center: _bool = True,
  14602. normalized: _bool = False,
  14603. onesided: _bool | None = None,
  14604. length: _int | None = None,
  14605. return_complex: _bool = False,
  14606. ) -> Tensor: ...
  14607. @overload
  14608. def kaiser_window(
  14609. window_length: _int,
  14610. *,
  14611. dtype: _dtype | None = None,
  14612. layout: _layout | None = None,
  14613. device: DeviceLikeType | None = None,
  14614. pin_memory: _bool | None = False,
  14615. requires_grad: _bool | None = False,
  14616. ) -> Tensor:
  14617. r"""
  14618. kaiser_window(window_length, periodic=True, beta=12.0, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  14619. Computes the Kaiser window with window length :attr:`window_length` and shape parameter :attr:`beta`.
  14620. Let I_0 be the zeroth order modified Bessel function of the first kind (see :func:`torch.i0`) and
  14621. ``N = L - 1`` if :attr:`periodic` is False and ``L`` if :attr:`periodic` is True,
  14622. where ``L`` is the :attr:`window_length`. This function computes:
  14623. .. math::
  14624. out_i = I_0 \left( \beta \sqrt{1 - \left( {\frac{i - N/2}{N/2}} \right) ^2 } \right) / I_0( \beta )
  14625. Calling ``torch.kaiser_window(L, B, periodic=True)`` is equivalent to calling
  14626. ``torch.kaiser_window(L + 1, B, periodic=False)[:-1])``.
  14627. The :attr:`periodic` argument is intended as a helpful shorthand
  14628. to produce a periodic window as input to functions like :func:`torch.stft`.
  14629. .. note::
  14630. If :attr:`window_length` is one, then the returned window is a single element tensor containing a one.
  14631. Args:
  14632. window_length (int): length of the window.
  14633. periodic (bool, optional): If True, returns a periodic window suitable for use in spectral analysis.
  14634. If False, returns a symmetric window suitable for use in filter design.
  14635. beta (float, optional): shape parameter for the window.
  14636. Keyword args:
  14637. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  14638. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  14639. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  14640. ``torch.strided`` (dense layout) is supported.
  14641. device (:class:`torch.device`, optional): the desired device of returned tensor.
  14642. Default: if ``None``, uses the current device for the default tensor type
  14643. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  14644. for CPU tensor types and the current CUDA device for CUDA tensor types.
  14645. requires_grad (bool, optional): If autograd should record operations on the
  14646. returned tensor. Default: ``False``.
  14647. """
  14648. @overload
  14649. def kaiser_window(
  14650. window_length: _int,
  14651. periodic: _bool,
  14652. *,
  14653. dtype: _dtype | None = None,
  14654. layout: _layout | None = None,
  14655. device: DeviceLikeType | None = None,
  14656. pin_memory: _bool | None = False,
  14657. requires_grad: _bool | None = False,
  14658. ) -> Tensor:
  14659. r"""
  14660. kaiser_window(window_length, periodic=True, beta=12.0, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  14661. Computes the Kaiser window with window length :attr:`window_length` and shape parameter :attr:`beta`.
  14662. Let I_0 be the zeroth order modified Bessel function of the first kind (see :func:`torch.i0`) and
  14663. ``N = L - 1`` if :attr:`periodic` is False and ``L`` if :attr:`periodic` is True,
  14664. where ``L`` is the :attr:`window_length`. This function computes:
  14665. .. math::
  14666. out_i = I_0 \left( \beta \sqrt{1 - \left( {\frac{i - N/2}{N/2}} \right) ^2 } \right) / I_0( \beta )
  14667. Calling ``torch.kaiser_window(L, B, periodic=True)`` is equivalent to calling
  14668. ``torch.kaiser_window(L + 1, B, periodic=False)[:-1])``.
  14669. The :attr:`periodic` argument is intended as a helpful shorthand
  14670. to produce a periodic window as input to functions like :func:`torch.stft`.
  14671. .. note::
  14672. If :attr:`window_length` is one, then the returned window is a single element tensor containing a one.
  14673. Args:
  14674. window_length (int): length of the window.
  14675. periodic (bool, optional): If True, returns a periodic window suitable for use in spectral analysis.
  14676. If False, returns a symmetric window suitable for use in filter design.
  14677. beta (float, optional): shape parameter for the window.
  14678. Keyword args:
  14679. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  14680. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  14681. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  14682. ``torch.strided`` (dense layout) is supported.
  14683. device (:class:`torch.device`, optional): the desired device of returned tensor.
  14684. Default: if ``None``, uses the current device for the default tensor type
  14685. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  14686. for CPU tensor types and the current CUDA device for CUDA tensor types.
  14687. requires_grad (bool, optional): If autograd should record operations on the
  14688. returned tensor. Default: ``False``.
  14689. """
  14690. @overload
  14691. def kaiser_window(
  14692. window_length: _int,
  14693. periodic: _bool,
  14694. beta: _float,
  14695. *,
  14696. dtype: _dtype | None = None,
  14697. layout: _layout | None = None,
  14698. device: DeviceLikeType | None = None,
  14699. pin_memory: _bool | None = False,
  14700. requires_grad: _bool | None = False,
  14701. ) -> Tensor:
  14702. r"""
  14703. kaiser_window(window_length, periodic=True, beta=12.0, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  14704. Computes the Kaiser window with window length :attr:`window_length` and shape parameter :attr:`beta`.
  14705. Let I_0 be the zeroth order modified Bessel function of the first kind (see :func:`torch.i0`) and
  14706. ``N = L - 1`` if :attr:`periodic` is False and ``L`` if :attr:`periodic` is True,
  14707. where ``L`` is the :attr:`window_length`. This function computes:
  14708. .. math::
  14709. out_i = I_0 \left( \beta \sqrt{1 - \left( {\frac{i - N/2}{N/2}} \right) ^2 } \right) / I_0( \beta )
  14710. Calling ``torch.kaiser_window(L, B, periodic=True)`` is equivalent to calling
  14711. ``torch.kaiser_window(L + 1, B, periodic=False)[:-1])``.
  14712. The :attr:`periodic` argument is intended as a helpful shorthand
  14713. to produce a periodic window as input to functions like :func:`torch.stft`.
  14714. .. note::
  14715. If :attr:`window_length` is one, then the returned window is a single element tensor containing a one.
  14716. Args:
  14717. window_length (int): length of the window.
  14718. periodic (bool, optional): If True, returns a periodic window suitable for use in spectral analysis.
  14719. If False, returns a symmetric window suitable for use in filter design.
  14720. beta (float, optional): shape parameter for the window.
  14721. Keyword args:
  14722. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  14723. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  14724. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  14725. ``torch.strided`` (dense layout) is supported.
  14726. device (:class:`torch.device`, optional): the desired device of returned tensor.
  14727. Default: if ``None``, uses the current device for the default tensor type
  14728. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  14729. for CPU tensor types and the current CUDA device for CUDA tensor types.
  14730. requires_grad (bool, optional): If autograd should record operations on the
  14731. returned tensor. Default: ``False``.
  14732. """
  14733. def kl_div(
  14734. input: Tensor,
  14735. target: Tensor,
  14736. reduction: _int = 1,
  14737. *,
  14738. log_target: _bool = False,
  14739. ) -> Tensor: ...
  14740. def kron(
  14741. input: Tensor,
  14742. other: Tensor,
  14743. *,
  14744. out: Tensor | None = None,
  14745. ) -> Tensor:
  14746. r"""
  14747. kron(input, other, *, out=None) -> Tensor
  14748. Computes the Kronecker product, denoted by :math:`\otimes`, of :attr:`input` and :attr:`other`.
  14749. If :attr:`input` is a :math:`(a_0 \times a_1 \times \dots \times a_n)` tensor and :attr:`other` is a
  14750. :math:`(b_0 \times b_1 \times \dots \times b_n)` tensor, the result will be a
  14751. :math:`(a_0*b_0 \times a_1*b_1 \times \dots \times a_n*b_n)` tensor with the following entries:
  14752. .. math::
  14753. (\text{input} \otimes \text{other})_{k_0, k_1, \dots, k_n} =
  14754. \text{input}_{i_0, i_1, \dots, i_n} * \text{other}_{j_0, j_1, \dots, j_n},
  14755. where :math:`k_t = i_t * b_t + j_t` for :math:`0 \leq t \leq n`.
  14756. If one tensor has fewer dimensions than the other it is unsqueezed until it has the same number of dimensions.
  14757. Supports real-valued and complex-valued inputs.
  14758. .. note::
  14759. This function generalizes the typical definition of the Kronecker product for two matrices to two tensors,
  14760. as described above. When :attr:`input` is a :math:`(m \times n)` matrix and :attr:`other` is a
  14761. :math:`(p \times q)` matrix, the result will be a :math:`(p*m \times q*n)` block matrix:
  14762. .. math::
  14763. \mathbf{A} \otimes \mathbf{B}=\begin{bmatrix}
  14764. a_{11} \mathbf{B} & \cdots & a_{1 n} \mathbf{B} \\
  14765. \vdots & \ddots & \vdots \\
  14766. a_{m 1} \mathbf{B} & \cdots & a_{m n} \mathbf{B} \end{bmatrix}
  14767. where :attr:`input` is :math:`\mathbf{A}` and :attr:`other` is :math:`\mathbf{B}`.
  14768. Arguments:
  14769. input (Tensor)
  14770. other (Tensor)
  14771. Keyword args:
  14772. out (Tensor, optional): The output tensor. Ignored if ``None``. Default: ``None``
  14773. Examples::
  14774. >>> mat1 = torch.eye(2)
  14775. >>> mat2 = torch.ones(2, 2)
  14776. >>> torch.kron(mat1, mat2)
  14777. tensor([[1., 1., 0., 0.],
  14778. [1., 1., 0., 0.],
  14779. [0., 0., 1., 1.],
  14780. [0., 0., 1., 1.]])
  14781. >>> mat1 = torch.eye(2)
  14782. >>> mat2 = torch.arange(1, 5).reshape(2, 2)
  14783. >>> torch.kron(mat1, mat2)
  14784. tensor([[1., 2., 0., 0.],
  14785. [3., 4., 0., 0.],
  14786. [0., 0., 1., 2.],
  14787. [0., 0., 3., 4.]])
  14788. """
  14789. @overload
  14790. def kthvalue(
  14791. input: Tensor,
  14792. k: _int | SymInt,
  14793. dim: _int = -1,
  14794. keepdim: _bool = False,
  14795. *,
  14796. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  14797. ) -> torch.return_types.kthvalue:
  14798. r"""
  14799. kthvalue(input, k, dim=None, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  14800. Returns a namedtuple ``(values, indices)`` where ``values`` is the :attr:`k` th
  14801. smallest element of each row of the :attr:`input` tensor in the given dimension
  14802. :attr:`dim`. And ``indices`` is the index location of each element found.
  14803. If :attr:`dim` is not given, the last dimension of the `input` is chosen.
  14804. If :attr:`keepdim` is ``True``, both the :attr:`values` and :attr:`indices` tensors
  14805. are the same size as :attr:`input`, except in the dimension :attr:`dim` where
  14806. they are of size 1. Otherwise, :attr:`dim` is squeezed
  14807. (see :func:`torch.squeeze`), resulting in both the :attr:`values` and
  14808. :attr:`indices` tensors having 1 fewer dimension than the :attr:`input` tensor.
  14809. .. note::
  14810. When :attr:`input` is a CUDA tensor and there are multiple valid
  14811. :attr:`k` th values, this function may nondeterministically return
  14812. :attr:`indices` for any of them.
  14813. Args:
  14814. input (Tensor): the input tensor.
  14815. k (int): k for the k-th smallest element
  14816. dim (int, optional): the dimension to find the kth value along
  14817. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  14818. Keyword args:
  14819. out (tuple, optional): the output tuple of (Tensor, LongTensor)
  14820. can be optionally given to be used as output buffers
  14821. Example::
  14822. >>> x = torch.arange(1., 6.)
  14823. >>> x
  14824. tensor([ 1., 2., 3., 4., 5.])
  14825. >>> torch.kthvalue(x, 4)
  14826. torch.return_types.kthvalue(values=tensor(4.), indices=tensor(3))
  14827. >>> x=torch.arange(1.,7.).resize_(2,3)
  14828. >>> x
  14829. tensor([[ 1., 2., 3.],
  14830. [ 4., 5., 6.]])
  14831. >>> torch.kthvalue(x, 2, 0, True)
  14832. torch.return_types.kthvalue(values=tensor([[4., 5., 6.]]), indices=tensor([[1, 1, 1]]))
  14833. """
  14834. @overload
  14835. def kthvalue(
  14836. input: Tensor,
  14837. k: _int | SymInt,
  14838. dim: str | EllipsisType | None,
  14839. keepdim: _bool = False,
  14840. *,
  14841. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  14842. ) -> torch.return_types.kthvalue:
  14843. r"""
  14844. kthvalue(input, k, dim=None, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  14845. Returns a namedtuple ``(values, indices)`` where ``values`` is the :attr:`k` th
  14846. smallest element of each row of the :attr:`input` tensor in the given dimension
  14847. :attr:`dim`. And ``indices`` is the index location of each element found.
  14848. If :attr:`dim` is not given, the last dimension of the `input` is chosen.
  14849. If :attr:`keepdim` is ``True``, both the :attr:`values` and :attr:`indices` tensors
  14850. are the same size as :attr:`input`, except in the dimension :attr:`dim` where
  14851. they are of size 1. Otherwise, :attr:`dim` is squeezed
  14852. (see :func:`torch.squeeze`), resulting in both the :attr:`values` and
  14853. :attr:`indices` tensors having 1 fewer dimension than the :attr:`input` tensor.
  14854. .. note::
  14855. When :attr:`input` is a CUDA tensor and there are multiple valid
  14856. :attr:`k` th values, this function may nondeterministically return
  14857. :attr:`indices` for any of them.
  14858. Args:
  14859. input (Tensor): the input tensor.
  14860. k (int): k for the k-th smallest element
  14861. dim (int, optional): the dimension to find the kth value along
  14862. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  14863. Keyword args:
  14864. out (tuple, optional): the output tuple of (Tensor, LongTensor)
  14865. can be optionally given to be used as output buffers
  14866. Example::
  14867. >>> x = torch.arange(1., 6.)
  14868. >>> x
  14869. tensor([ 1., 2., 3., 4., 5.])
  14870. >>> torch.kthvalue(x, 4)
  14871. torch.return_types.kthvalue(values=tensor(4.), indices=tensor(3))
  14872. >>> x=torch.arange(1.,7.).resize_(2,3)
  14873. >>> x
  14874. tensor([[ 1., 2., 3.],
  14875. [ 4., 5., 6.]])
  14876. >>> torch.kthvalue(x, 2, 0, True)
  14877. torch.return_types.kthvalue(values=tensor([[4., 5., 6.]]), indices=tensor([[1, 1, 1]]))
  14878. """
  14879. def layer_norm(
  14880. input: Tensor,
  14881. normalized_shape: Sequence[_int | SymInt],
  14882. weight: Tensor | None = None,
  14883. bias: Tensor | None = None,
  14884. eps: _float = 1e-05,
  14885. cudnn_enable: _bool = True,
  14886. ) -> Tensor: ...
  14887. def lcm(
  14888. input: Tensor,
  14889. other: Tensor,
  14890. *,
  14891. out: Tensor | None = None,
  14892. ) -> Tensor:
  14893. r"""
  14894. lcm(input, other, *, out=None) -> Tensor
  14895. Computes the element-wise least common multiple (LCM) of :attr:`input` and :attr:`other`.
  14896. Both :attr:`input` and :attr:`other` must have integer types.
  14897. .. note::
  14898. This defines :math:`lcm(0, 0) = 0` and :math:`lcm(0, a) = 0`.
  14899. Args:
  14900. input (Tensor): the input tensor.
  14901. other (Tensor): the second input tensor
  14902. Keyword arguments:
  14903. out (Tensor, optional): the output tensor.
  14904. Example::
  14905. >>> a = torch.tensor([5, 10, 15])
  14906. >>> b = torch.tensor([3, 4, 5])
  14907. >>> torch.lcm(a, b)
  14908. tensor([15, 20, 15])
  14909. >>> c = torch.tensor([3])
  14910. >>> torch.lcm(a, c)
  14911. tensor([15, 30, 15])
  14912. """
  14913. def lcm_(input: Tensor, other: Tensor) -> Tensor: ...
  14914. def ldexp(
  14915. input: Tensor,
  14916. other: Tensor,
  14917. *,
  14918. out: Tensor | None = None,
  14919. ) -> Tensor:
  14920. r"""
  14921. ldexp(input, other, *, out=None) -> Tensor
  14922. Multiplies :attr:`input` by 2 ** :attr:`other`.
  14923. .. math::
  14924. \text{{out}}_i = \text{{input}}_i * 2^\text{{other}}_i
  14925. Typically this function is used to construct floating point numbers by multiplying
  14926. mantissas in :attr:`input` with integral powers of two created from the exponents
  14927. in :attr:`other`.
  14928. Args:
  14929. input (Tensor): the input tensor.
  14930. other (Tensor): a tensor of exponents, typically integers.
  14931. Keyword args:
  14932. out (Tensor, optional): the output tensor.
  14933. Example::
  14934. >>> torch.ldexp(torch.tensor([1.]), torch.tensor([1]))
  14935. tensor([2.])
  14936. >>> torch.ldexp(torch.tensor([1.0]), torch.tensor([1, 2, 3, 4]))
  14937. tensor([ 2., 4., 8., 16.])
  14938. """
  14939. def ldexp_(input: Tensor, other: Tensor) -> Tensor: ...
  14940. @overload
  14941. def le(
  14942. input: Tensor,
  14943. other: Tensor,
  14944. *,
  14945. out: Tensor | None = None,
  14946. ) -> Tensor:
  14947. r"""
  14948. le(input, other, *, out=None) -> Tensor
  14949. Computes :math:`\text{input} \leq \text{other}` element-wise.
  14950. The second argument can be a number or a tensor whose shape is
  14951. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  14952. Args:
  14953. input (Tensor): the tensor to compare
  14954. other (Tensor or Scalar): the tensor or value to compare
  14955. Keyword args:
  14956. out (Tensor, optional): the output tensor.
  14957. Returns:
  14958. A boolean tensor that is True where :attr:`input` is less than or equal to
  14959. :attr:`other` and False elsewhere
  14960. Example::
  14961. >>> torch.le(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  14962. tensor([[True, False], [True, True]])
  14963. """
  14964. @overload
  14965. def le(
  14966. input: Tensor,
  14967. other: Number | _complex,
  14968. *,
  14969. out: Tensor | None = None,
  14970. ) -> Tensor:
  14971. r"""
  14972. le(input, other, *, out=None) -> Tensor
  14973. Computes :math:`\text{input} \leq \text{other}` element-wise.
  14974. The second argument can be a number or a tensor whose shape is
  14975. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  14976. Args:
  14977. input (Tensor): the tensor to compare
  14978. other (Tensor or Scalar): the tensor or value to compare
  14979. Keyword args:
  14980. out (Tensor, optional): the output tensor.
  14981. Returns:
  14982. A boolean tensor that is True where :attr:`input` is less than or equal to
  14983. :attr:`other` and False elsewhere
  14984. Example::
  14985. >>> torch.le(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  14986. tensor([[True, False], [True, True]])
  14987. """
  14988. @overload
  14989. def lerp(
  14990. input: Tensor,
  14991. end: Tensor,
  14992. weight: Tensor,
  14993. *,
  14994. out: Tensor | None = None,
  14995. ) -> Tensor:
  14996. r"""
  14997. lerp(input, end, weight, *, out=None)
  14998. Does a linear interpolation of two tensors :attr:`start` (given by :attr:`input`) and :attr:`end` based
  14999. on a scalar or tensor :attr:`weight` and returns the resulting :attr:`out` tensor.
  15000. .. math::
  15001. \text{out}_i = \text{start}_i + \text{weight}_i \times (\text{end}_i - \text{start}_i)
  15002. The shapes of :attr:`start` and :attr:`end` must be
  15003. :ref:`broadcastable <broadcasting-semantics>`. If :attr:`weight` is a tensor, then
  15004. the shapes of :attr:`weight`, :attr:`start`, and :attr:`end` must be :ref:`broadcastable <broadcasting-semantics>`.
  15005. Args:
  15006. input (Tensor): the tensor with the starting points
  15007. end (Tensor): the tensor with the ending points
  15008. weight (float or tensor): the weight for the interpolation formula
  15009. Keyword args:
  15010. out (Tensor, optional): the output tensor.
  15011. Example::
  15012. >>> start = torch.arange(1., 5.)
  15013. >>> end = torch.empty(4).fill_(10)
  15014. >>> start
  15015. tensor([ 1., 2., 3., 4.])
  15016. >>> end
  15017. tensor([ 10., 10., 10., 10.])
  15018. >>> torch.lerp(start, end, 0.5)
  15019. tensor([ 5.5000, 6.0000, 6.5000, 7.0000])
  15020. >>> torch.lerp(start, end, torch.full_like(start, 0.5))
  15021. tensor([ 5.5000, 6.0000, 6.5000, 7.0000])
  15022. """
  15023. @overload
  15024. def lerp(
  15025. input: Tensor,
  15026. end: Tensor,
  15027. weight: Number | _complex,
  15028. *,
  15029. out: Tensor | None = None,
  15030. ) -> Tensor:
  15031. r"""
  15032. lerp(input, end, weight, *, out=None)
  15033. Does a linear interpolation of two tensors :attr:`start` (given by :attr:`input`) and :attr:`end` based
  15034. on a scalar or tensor :attr:`weight` and returns the resulting :attr:`out` tensor.
  15035. .. math::
  15036. \text{out}_i = \text{start}_i + \text{weight}_i \times (\text{end}_i - \text{start}_i)
  15037. The shapes of :attr:`start` and :attr:`end` must be
  15038. :ref:`broadcastable <broadcasting-semantics>`. If :attr:`weight` is a tensor, then
  15039. the shapes of :attr:`weight`, :attr:`start`, and :attr:`end` must be :ref:`broadcastable <broadcasting-semantics>`.
  15040. Args:
  15041. input (Tensor): the tensor with the starting points
  15042. end (Tensor): the tensor with the ending points
  15043. weight (float or tensor): the weight for the interpolation formula
  15044. Keyword args:
  15045. out (Tensor, optional): the output tensor.
  15046. Example::
  15047. >>> start = torch.arange(1., 5.)
  15048. >>> end = torch.empty(4).fill_(10)
  15049. >>> start
  15050. tensor([ 1., 2., 3., 4.])
  15051. >>> end
  15052. tensor([ 10., 10., 10., 10.])
  15053. >>> torch.lerp(start, end, 0.5)
  15054. tensor([ 5.5000, 6.0000, 6.5000, 7.0000])
  15055. >>> torch.lerp(start, end, torch.full_like(start, 0.5))
  15056. tensor([ 5.5000, 6.0000, 6.5000, 7.0000])
  15057. """
  15058. @overload
  15059. def less(
  15060. input: Tensor,
  15061. other: Tensor,
  15062. *,
  15063. out: Tensor | None = None,
  15064. ) -> Tensor:
  15065. r"""
  15066. less(input, other, *, out=None) -> Tensor
  15067. Alias for :func:`torch.lt`.
  15068. """
  15069. @overload
  15070. def less(
  15071. input: Tensor,
  15072. other: Number | _complex,
  15073. *,
  15074. out: Tensor | None = None,
  15075. ) -> Tensor:
  15076. r"""
  15077. less(input, other, *, out=None) -> Tensor
  15078. Alias for :func:`torch.lt`.
  15079. """
  15080. @overload
  15081. def less_equal(
  15082. input: Tensor,
  15083. other: Tensor,
  15084. *,
  15085. out: Tensor | None = None,
  15086. ) -> Tensor:
  15087. r"""
  15088. less_equal(input, other, *, out=None) -> Tensor
  15089. Alias for :func:`torch.le`.
  15090. """
  15091. @overload
  15092. def less_equal(
  15093. input: Tensor,
  15094. other: Number | _complex,
  15095. *,
  15096. out: Tensor | None = None,
  15097. ) -> Tensor:
  15098. r"""
  15099. less_equal(input, other, *, out=None) -> Tensor
  15100. Alias for :func:`torch.le`.
  15101. """
  15102. def lgamma(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  15103. r"""
  15104. lgamma(input, *, out=None) -> Tensor
  15105. Computes the natural logarithm of the absolute value of the gamma function on :attr:`input`.
  15106. .. math::
  15107. \text{out}_{i} = \ln |\Gamma(\text{input}_{i})|
  15108. Args:
  15109. input (Tensor): the input tensor.
  15110. Keyword args:
  15111. out (Tensor, optional): the output tensor.
  15112. Example::
  15113. >>> a = torch.arange(0.5, 2, 0.5)
  15114. >>> torch.lgamma(a)
  15115. tensor([ 0.5724, 0.0000, -0.1208])
  15116. """
  15117. @overload
  15118. def linspace(
  15119. start: Number,
  15120. end: Number,
  15121. steps: _int | None = None,
  15122. *,
  15123. out: Tensor | None = None,
  15124. dtype: _dtype | None = None,
  15125. device: DeviceLikeType | None = None,
  15126. requires_grad: _bool = False,
  15127. pin_memory: _bool = False,
  15128. ) -> Tensor:
  15129. r"""
  15130. linspace(start, end, steps, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15131. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15132. spaced from :attr:`start` to :attr:`end`, inclusive. That is, the value are:
  15133. .. math::
  15134. (\text{start},
  15135. \text{start} + \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15136. \ldots,
  15137. \text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15138. \text{end})
  15139. From PyTorch 1.11 linspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15140. Args:
  15141. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15142. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15143. steps (int): size of the constructed tensor
  15144. Keyword arguments:
  15145. out (Tensor, optional): the output tensor.
  15146. dtype (torch.dtype, optional): the data type to perform the computation in.
  15147. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15148. when both :attr:`start` and :attr:`end` are real,
  15149. and corresponding complex dtype when either is complex.
  15150. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15151. Default: ``torch.strided``.
  15152. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15153. Default: if ``None``, uses the current device for the default tensor type
  15154. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15155. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15156. requires_grad (bool, optional): If autograd should record operations on the
  15157. returned tensor. Default: ``False``.
  15158. Example::
  15159. >>> torch.linspace(3, 10, steps=5)
  15160. tensor([ 3.0000, 4.7500, 6.5000, 8.2500, 10.0000])
  15161. >>> torch.linspace(-10, 10, steps=5)
  15162. tensor([-10., -5., 0., 5., 10.])
  15163. >>> torch.linspace(start=-10, end=10, steps=5)
  15164. tensor([-10., -5., 0., 5., 10.])
  15165. >>> torch.linspace(start=-10, end=10, steps=1)
  15166. tensor([-10.])
  15167. """
  15168. @overload
  15169. def linspace(
  15170. start: Tensor,
  15171. end: Tensor,
  15172. steps: _int,
  15173. *,
  15174. out: Tensor | None = None,
  15175. dtype: _dtype | None = None,
  15176. layout: _layout | None = None,
  15177. device: DeviceLikeType | None = None,
  15178. pin_memory: _bool | None = False,
  15179. requires_grad: _bool | None = False,
  15180. ) -> Tensor:
  15181. r"""
  15182. linspace(start, end, steps, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15183. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15184. spaced from :attr:`start` to :attr:`end`, inclusive. That is, the value are:
  15185. .. math::
  15186. (\text{start},
  15187. \text{start} + \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15188. \ldots,
  15189. \text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15190. \text{end})
  15191. From PyTorch 1.11 linspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15192. Args:
  15193. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15194. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15195. steps (int): size of the constructed tensor
  15196. Keyword arguments:
  15197. out (Tensor, optional): the output tensor.
  15198. dtype (torch.dtype, optional): the data type to perform the computation in.
  15199. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15200. when both :attr:`start` and :attr:`end` are real,
  15201. and corresponding complex dtype when either is complex.
  15202. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15203. Default: ``torch.strided``.
  15204. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15205. Default: if ``None``, uses the current device for the default tensor type
  15206. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15207. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15208. requires_grad (bool, optional): If autograd should record operations on the
  15209. returned tensor. Default: ``False``.
  15210. Example::
  15211. >>> torch.linspace(3, 10, steps=5)
  15212. tensor([ 3.0000, 4.7500, 6.5000, 8.2500, 10.0000])
  15213. >>> torch.linspace(-10, 10, steps=5)
  15214. tensor([-10., -5., 0., 5., 10.])
  15215. >>> torch.linspace(start=-10, end=10, steps=5)
  15216. tensor([-10., -5., 0., 5., 10.])
  15217. >>> torch.linspace(start=-10, end=10, steps=1)
  15218. tensor([-10.])
  15219. """
  15220. @overload
  15221. def linspace(
  15222. start: Number | _complex,
  15223. end: Tensor,
  15224. steps: _int,
  15225. *,
  15226. out: Tensor | None = None,
  15227. dtype: _dtype | None = None,
  15228. layout: _layout | None = None,
  15229. device: DeviceLikeType | None = None,
  15230. pin_memory: _bool | None = False,
  15231. requires_grad: _bool | None = False,
  15232. ) -> Tensor:
  15233. r"""
  15234. linspace(start, end, steps, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15235. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15236. spaced from :attr:`start` to :attr:`end`, inclusive. That is, the value are:
  15237. .. math::
  15238. (\text{start},
  15239. \text{start} + \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15240. \ldots,
  15241. \text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15242. \text{end})
  15243. From PyTorch 1.11 linspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15244. Args:
  15245. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15246. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15247. steps (int): size of the constructed tensor
  15248. Keyword arguments:
  15249. out (Tensor, optional): the output tensor.
  15250. dtype (torch.dtype, optional): the data type to perform the computation in.
  15251. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15252. when both :attr:`start` and :attr:`end` are real,
  15253. and corresponding complex dtype when either is complex.
  15254. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15255. Default: ``torch.strided``.
  15256. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15257. Default: if ``None``, uses the current device for the default tensor type
  15258. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15259. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15260. requires_grad (bool, optional): If autograd should record operations on the
  15261. returned tensor. Default: ``False``.
  15262. Example::
  15263. >>> torch.linspace(3, 10, steps=5)
  15264. tensor([ 3.0000, 4.7500, 6.5000, 8.2500, 10.0000])
  15265. >>> torch.linspace(-10, 10, steps=5)
  15266. tensor([-10., -5., 0., 5., 10.])
  15267. >>> torch.linspace(start=-10, end=10, steps=5)
  15268. tensor([-10., -5., 0., 5., 10.])
  15269. >>> torch.linspace(start=-10, end=10, steps=1)
  15270. tensor([-10.])
  15271. """
  15272. @overload
  15273. def linspace(
  15274. start: Tensor,
  15275. end: Number | _complex,
  15276. steps: _int,
  15277. *,
  15278. out: Tensor | None = None,
  15279. dtype: _dtype | None = None,
  15280. layout: _layout | None = None,
  15281. device: DeviceLikeType | None = None,
  15282. pin_memory: _bool | None = False,
  15283. requires_grad: _bool | None = False,
  15284. ) -> Tensor:
  15285. r"""
  15286. linspace(start, end, steps, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15287. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15288. spaced from :attr:`start` to :attr:`end`, inclusive. That is, the value are:
  15289. .. math::
  15290. (\text{start},
  15291. \text{start} + \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15292. \ldots,
  15293. \text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15294. \text{end})
  15295. From PyTorch 1.11 linspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15296. Args:
  15297. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15298. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15299. steps (int): size of the constructed tensor
  15300. Keyword arguments:
  15301. out (Tensor, optional): the output tensor.
  15302. dtype (torch.dtype, optional): the data type to perform the computation in.
  15303. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15304. when both :attr:`start` and :attr:`end` are real,
  15305. and corresponding complex dtype when either is complex.
  15306. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15307. Default: ``torch.strided``.
  15308. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15309. Default: if ``None``, uses the current device for the default tensor type
  15310. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15311. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15312. requires_grad (bool, optional): If autograd should record operations on the
  15313. returned tensor. Default: ``False``.
  15314. Example::
  15315. >>> torch.linspace(3, 10, steps=5)
  15316. tensor([ 3.0000, 4.7500, 6.5000, 8.2500, 10.0000])
  15317. >>> torch.linspace(-10, 10, steps=5)
  15318. tensor([-10., -5., 0., 5., 10.])
  15319. >>> torch.linspace(start=-10, end=10, steps=5)
  15320. tensor([-10., -5., 0., 5., 10.])
  15321. >>> torch.linspace(start=-10, end=10, steps=1)
  15322. tensor([-10.])
  15323. """
  15324. @overload
  15325. def linspace(
  15326. start: Number | _complex,
  15327. end: Number | _complex,
  15328. steps: _int,
  15329. *,
  15330. out: Tensor | None = None,
  15331. dtype: _dtype | None = None,
  15332. layout: _layout | None = None,
  15333. device: DeviceLikeType | None = None,
  15334. pin_memory: _bool | None = False,
  15335. requires_grad: _bool | None = False,
  15336. ) -> Tensor:
  15337. r"""
  15338. linspace(start, end, steps, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15339. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15340. spaced from :attr:`start` to :attr:`end`, inclusive. That is, the value are:
  15341. .. math::
  15342. (\text{start},
  15343. \text{start} + \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15344. \ldots,
  15345. \text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15346. \text{end})
  15347. From PyTorch 1.11 linspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15348. Args:
  15349. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15350. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15351. steps (int): size of the constructed tensor
  15352. Keyword arguments:
  15353. out (Tensor, optional): the output tensor.
  15354. dtype (torch.dtype, optional): the data type to perform the computation in.
  15355. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15356. when both :attr:`start` and :attr:`end` are real,
  15357. and corresponding complex dtype when either is complex.
  15358. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15359. Default: ``torch.strided``.
  15360. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15361. Default: if ``None``, uses the current device for the default tensor type
  15362. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15363. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15364. requires_grad (bool, optional): If autograd should record operations on the
  15365. returned tensor. Default: ``False``.
  15366. Example::
  15367. >>> torch.linspace(3, 10, steps=5)
  15368. tensor([ 3.0000, 4.7500, 6.5000, 8.2500, 10.0000])
  15369. >>> torch.linspace(-10, 10, steps=5)
  15370. tensor([-10., -5., 0., 5., 10.])
  15371. >>> torch.linspace(start=-10, end=10, steps=5)
  15372. tensor([-10., -5., 0., 5., 10.])
  15373. >>> torch.linspace(start=-10, end=10, steps=1)
  15374. tensor([-10.])
  15375. """
  15376. def log(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  15377. r"""
  15378. log(input, *, out=None) -> Tensor
  15379. Returns a new tensor with the natural logarithm of the elements
  15380. of :attr:`input`.
  15381. .. math::
  15382. y_{i} = \log_{e} (x_{i})
  15383. Args:
  15384. input (Tensor): the input tensor.
  15385. Keyword args:
  15386. out (Tensor, optional): the output tensor.
  15387. Example::
  15388. >>> a = torch.rand(5) * 5
  15389. >>> a
  15390. tensor([4.7767, 4.3234, 1.2156, 0.2411, 4.5739])
  15391. >>> torch.log(a)
  15392. tensor([ 1.5637, 1.4640, 0.1952, -1.4226, 1.5204])
  15393. """
  15394. def log10(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  15395. r"""
  15396. log10(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  15397. Returns a new tensor with the logarithm to the base 10 of the elements
  15398. of :attr:`input`.
  15399. .. math::
  15400. y_{i} = \log_{10} (x_{i})
  15401. Args:
  15402. input (Tensor): the input tensor.
  15403. Keyword args:
  15404. out (Tensor, optional): the output tensor.
  15405. Example::
  15406. >>> a = torch.rand(5)
  15407. >>> a
  15408. tensor([ 0.5224, 0.9354, 0.7257, 0.1301, 0.2251])
  15409. >>> torch.log10(a)
  15410. tensor([-0.2820, -0.0290, -0.1392, -0.8857, -0.6476])
  15411. """
  15412. def log10_(input: Tensor) -> Tensor: ...
  15413. def log1p(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  15414. r"""
  15415. log1p(input, *, out=None) -> Tensor
  15416. Returns a new tensor with the natural logarithm of (1 + :attr:`input`).
  15417. .. math::
  15418. y_i = \log_{e} (x_i + 1)
  15419. .. note:: This function is more accurate than :func:`torch.log` for small
  15420. values of :attr:`input`
  15421. Args:
  15422. input (Tensor): the input tensor.
  15423. Keyword args:
  15424. out (Tensor, optional): the output tensor.
  15425. Example::
  15426. >>> a = torch.randn(5)
  15427. >>> a
  15428. tensor([-1.0090, -0.9923, 1.0249, -0.5372, 0.2492])
  15429. >>> torch.log1p(a)
  15430. tensor([ nan, -4.8653, 0.7055, -0.7705, 0.2225])
  15431. """
  15432. def log1p_(input: Tensor) -> Tensor: ...
  15433. def log2(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  15434. r"""
  15435. log2(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  15436. Returns a new tensor with the logarithm to the base 2 of the elements
  15437. of :attr:`input`.
  15438. .. math::
  15439. y_{i} = \log_{2} (x_{i})
  15440. Args:
  15441. input (Tensor): the input tensor.
  15442. Keyword args:
  15443. out (Tensor, optional): the output tensor.
  15444. Example::
  15445. >>> a = torch.rand(5)
  15446. >>> a
  15447. tensor([ 0.8419, 0.8003, 0.9971, 0.5287, 0.0490])
  15448. >>> torch.log2(a)
  15449. tensor([-0.2483, -0.3213, -0.0042, -0.9196, -4.3504])
  15450. """
  15451. def log2_(input: Tensor) -> Tensor: ...
  15452. def log_(input: Tensor) -> Tensor: ...
  15453. @overload
  15454. def log_softmax(
  15455. input: Tensor,
  15456. dim: _int,
  15457. dtype: _dtype | None = None,
  15458. *,
  15459. out: Tensor | None = None,
  15460. ) -> Tensor: ...
  15461. @overload
  15462. def log_softmax(
  15463. input: Tensor,
  15464. dim: str | EllipsisType | None,
  15465. *,
  15466. dtype: _dtype | None = None,
  15467. ) -> Tensor: ...
  15468. def logaddexp(
  15469. input: Tensor,
  15470. other: Tensor,
  15471. *,
  15472. out: Tensor | None = None,
  15473. ) -> Tensor:
  15474. r"""
  15475. logaddexp(input, other, *, out=None) -> Tensor
  15476. Logarithm of the sum of exponentiations of the inputs.
  15477. Calculates pointwise :math:`\log\left(e^x + e^y\right)`. This function is useful
  15478. in statistics where the calculated probabilities of events may be so small as to
  15479. exceed the range of normal floating point numbers. In such cases the logarithm
  15480. of the calculated probability is stored. This function allows adding
  15481. probabilities stored in such a fashion.
  15482. This op should be disambiguated with :func:`torch.logsumexp` which performs a
  15483. reduction on a single tensor.
  15484. Args:
  15485. input (Tensor): the input tensor.
  15486. other (Tensor): the second input tensor
  15487. Keyword arguments:
  15488. out (Tensor, optional): the output tensor.
  15489. Example::
  15490. >>> torch.logaddexp(torch.tensor([-1.0]), torch.tensor([-1.0, -2, -3]))
  15491. tensor([-0.3069, -0.6867, -0.8731])
  15492. >>> torch.logaddexp(torch.tensor([-100.0, -200, -300]), torch.tensor([-1.0, -2, -3]))
  15493. tensor([-1., -2., -3.])
  15494. >>> torch.logaddexp(torch.tensor([1.0, 2000, 30000]), torch.tensor([-1.0, -2, -3]))
  15495. tensor([1.1269e+00, 2.0000e+03, 3.0000e+04])
  15496. """
  15497. def logaddexp2(
  15498. input: Tensor,
  15499. other: Tensor,
  15500. *,
  15501. out: Tensor | None = None,
  15502. ) -> Tensor:
  15503. r"""
  15504. logaddexp2(input, other, *, out=None) -> Tensor
  15505. Logarithm of the sum of exponentiations of the inputs in base-2.
  15506. Calculates pointwise :math:`\log_2\left(2^x + 2^y\right)`. See
  15507. :func:`torch.logaddexp` for more details.
  15508. Args:
  15509. input (Tensor): the input tensor.
  15510. other (Tensor): the second input tensor
  15511. Keyword arguments:
  15512. out (Tensor, optional): the output tensor.
  15513. """
  15514. @overload
  15515. def logcumsumexp(
  15516. input: Tensor,
  15517. dim: _int,
  15518. *,
  15519. out: Tensor | None = None,
  15520. ) -> Tensor:
  15521. r"""
  15522. logcumsumexp(input, dim, *, out=None) -> Tensor
  15523. Returns the logarithm of the cumulative summation of the exponentiation of
  15524. elements of :attr:`input` in the dimension :attr:`dim`.
  15525. For summation index :math:`j` given by `dim` and other indices :math:`i`, the result is
  15526. .. math::
  15527. \text{logcumsumexp}(x)_{ij} = \log \sum\limits_{k=0}^{j} \exp(x_{ik})
  15528. Args:
  15529. input (Tensor): the input tensor.
  15530. dim (int): the dimension to do the operation over
  15531. Keyword args:
  15532. out (Tensor, optional): the output tensor.
  15533. Example::
  15534. >>> a = torch.randn(10)
  15535. >>> torch.logcumsumexp(a, dim=0)
  15536. tensor([-0.42296738, -0.04462666, 0.86278635, 0.94622083, 1.05277811,
  15537. 1.39202815, 1.83525007, 1.84492621, 2.06084887, 2.06844475]))
  15538. """
  15539. @overload
  15540. def logcumsumexp(
  15541. input: Tensor,
  15542. dim: str | EllipsisType | None,
  15543. *,
  15544. out: Tensor | None = None,
  15545. ) -> Tensor:
  15546. r"""
  15547. logcumsumexp(input, dim, *, out=None) -> Tensor
  15548. Returns the logarithm of the cumulative summation of the exponentiation of
  15549. elements of :attr:`input` in the dimension :attr:`dim`.
  15550. For summation index :math:`j` given by `dim` and other indices :math:`i`, the result is
  15551. .. math::
  15552. \text{logcumsumexp}(x)_{ij} = \log \sum\limits_{k=0}^{j} \exp(x_{ik})
  15553. Args:
  15554. input (Tensor): the input tensor.
  15555. dim (int): the dimension to do the operation over
  15556. Keyword args:
  15557. out (Tensor, optional): the output tensor.
  15558. Example::
  15559. >>> a = torch.randn(10)
  15560. >>> torch.logcumsumexp(a, dim=0)
  15561. tensor([-0.42296738, -0.04462666, 0.86278635, 0.94622083, 1.05277811,
  15562. 1.39202815, 1.83525007, 1.84492621, 2.06084887, 2.06844475]))
  15563. """
  15564. def logdet(input: Tensor) -> Tensor:
  15565. r"""
  15566. logdet(input) -> Tensor
  15567. Calculates log determinant of a square matrix or batches of square matrices.
  15568. It returns ``-inf`` if the input has a determinant of zero, and ``NaN`` if it has
  15569. a negative determinant.
  15570. .. note::
  15571. Backward through :meth:`logdet` internally uses SVD results when :attr:`input`
  15572. is not invertible. In this case, double backward through :meth:`logdet` will
  15573. be unstable in when :attr:`input` doesn't have distinct singular values. See
  15574. :func:`torch.linalg.svd` for details.
  15575. .. seealso::
  15576. :func:`torch.linalg.slogdet` computes the sign (resp. angle) and natural logarithm of the
  15577. absolute value of the determinant of real-valued (resp. complex) square matrices.
  15578. Arguments:
  15579. input (Tensor): the input tensor of size ``(*, n, n)`` where ``*`` is zero or more
  15580. batch dimensions.
  15581. Example::
  15582. >>> A = torch.randn(3, 3)
  15583. >>> torch.det(A)
  15584. tensor(0.2611)
  15585. >>> torch.logdet(A)
  15586. tensor(-1.3430)
  15587. >>> A
  15588. tensor([[[ 0.9254, -0.6213],
  15589. [-0.5787, 1.6843]],
  15590. [[ 0.3242, -0.9665],
  15591. [ 0.4539, -0.0887]],
  15592. [[ 1.1336, -0.4025],
  15593. [-0.7089, 0.9032]]])
  15594. >>> A.det()
  15595. tensor([1.1990, 0.4099, 0.7386])
  15596. >>> A.det().log()
  15597. tensor([ 0.1815, -0.8917, -0.3031])
  15598. """
  15599. def logical_and(
  15600. input: Tensor,
  15601. other: Tensor,
  15602. *,
  15603. out: Tensor | None = None,
  15604. ) -> Tensor:
  15605. r"""
  15606. logical_and(input, other, *, out=None) -> Tensor
  15607. Computes the element-wise logical AND of the given input tensors. Zeros are treated as ``False`` and nonzeros are
  15608. treated as ``True``.
  15609. Args:
  15610. input (Tensor): the input tensor.
  15611. other (Tensor): the tensor to compute AND with
  15612. Keyword args:
  15613. out (Tensor, optional): the output tensor.
  15614. Example::
  15615. >>> torch.logical_and(torch.tensor([True, False, True]), torch.tensor([True, False, False]))
  15616. tensor([ True, False, False])
  15617. >>> a = torch.tensor([0, 1, 10, 0], dtype=torch.int8)
  15618. >>> b = torch.tensor([4, 0, 1, 0], dtype=torch.int8)
  15619. >>> torch.logical_and(a, b)
  15620. tensor([False, False, True, False])
  15621. >>> torch.logical_and(a.double(), b.double())
  15622. tensor([False, False, True, False])
  15623. >>> torch.logical_and(a.double(), b)
  15624. tensor([False, False, True, False])
  15625. >>> torch.logical_and(a, b, out=torch.empty(4, dtype=torch.bool))
  15626. tensor([False, False, True, False])
  15627. """
  15628. def logical_not(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  15629. r"""
  15630. logical_not(input, *, out=None) -> Tensor
  15631. Computes the element-wise logical NOT of the given input tensor. If not specified, the output tensor will have the bool
  15632. dtype. If the input tensor is not a bool tensor, zeros are treated as ``False`` and non-zeros are treated as ``True``.
  15633. Args:
  15634. input (Tensor): the input tensor.
  15635. Keyword args:
  15636. out (Tensor, optional): the output tensor.
  15637. Example::
  15638. >>> torch.logical_not(torch.tensor([True, False]))
  15639. tensor([False, True])
  15640. >>> torch.logical_not(torch.tensor([0, 1, -10], dtype=torch.int8))
  15641. tensor([ True, False, False])
  15642. >>> torch.logical_not(torch.tensor([0., 1.5, -10.], dtype=torch.double))
  15643. tensor([ True, False, False])
  15644. >>> torch.logical_not(torch.tensor([0., 1., -10.], dtype=torch.double), out=torch.empty(3, dtype=torch.int16))
  15645. tensor([1, 0, 0], dtype=torch.int16)
  15646. """
  15647. def logical_or(
  15648. input: Tensor,
  15649. other: Tensor,
  15650. *,
  15651. out: Tensor | None = None,
  15652. ) -> Tensor:
  15653. r"""
  15654. logical_or(input, other, *, out=None) -> Tensor
  15655. Computes the element-wise logical OR of the given input tensors. Zeros are treated as ``False`` and nonzeros are
  15656. treated as ``True``.
  15657. Args:
  15658. input (Tensor): the input tensor.
  15659. other (Tensor): the tensor to compute OR with
  15660. Keyword args:
  15661. out (Tensor, optional): the output tensor.
  15662. Example::
  15663. >>> torch.logical_or(torch.tensor([True, False, True]), torch.tensor([True, False, False]))
  15664. tensor([ True, False, True])
  15665. >>> a = torch.tensor([0, 1, 10, 0], dtype=torch.int8)
  15666. >>> b = torch.tensor([4, 0, 1, 0], dtype=torch.int8)
  15667. >>> torch.logical_or(a, b)
  15668. tensor([ True, True, True, False])
  15669. >>> torch.logical_or(a.double(), b.double())
  15670. tensor([ True, True, True, False])
  15671. >>> torch.logical_or(a.double(), b)
  15672. tensor([ True, True, True, False])
  15673. >>> torch.logical_or(a, b, out=torch.empty(4, dtype=torch.bool))
  15674. tensor([ True, True, True, False])
  15675. """
  15676. def logical_xor(
  15677. input: Tensor,
  15678. other: Tensor,
  15679. *,
  15680. out: Tensor | None = None,
  15681. ) -> Tensor:
  15682. r"""
  15683. logical_xor(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
  15684. Computes the element-wise logical XOR of the given input tensors. Zeros are treated as ``False`` and nonzeros are
  15685. treated as ``True``.
  15686. Args:
  15687. input (Tensor): the input tensor.
  15688. other (Tensor): the tensor to compute XOR with
  15689. Keyword args:
  15690. out (Tensor, optional): the output tensor.
  15691. Example::
  15692. >>> torch.logical_xor(torch.tensor([True, False, True]), torch.tensor([True, False, False]))
  15693. tensor([False, False, True])
  15694. >>> a = torch.tensor([0, 1, 10, 0], dtype=torch.int8)
  15695. >>> b = torch.tensor([4, 0, 1, 0], dtype=torch.int8)
  15696. >>> torch.logical_xor(a, b)
  15697. tensor([ True, True, False, False])
  15698. >>> torch.logical_xor(a.double(), b.double())
  15699. tensor([ True, True, False, False])
  15700. >>> torch.logical_xor(a.double(), b)
  15701. tensor([ True, True, False, False])
  15702. >>> torch.logical_xor(a, b, out=torch.empty(4, dtype=torch.bool))
  15703. tensor([ True, True, False, False])
  15704. """
  15705. def logit(
  15706. input: Tensor,
  15707. eps: _float | None = None,
  15708. *,
  15709. out: Tensor | None = None,
  15710. ) -> Tensor:
  15711. r"""
  15712. logit(input, eps=None, *, out=None) -> Tensor
  15713. Alias for :func:`torch.special.logit`.
  15714. """
  15715. def logit_(input: Tensor, eps: _float | None = None) -> Tensor: ...
  15716. @overload
  15717. def logspace(
  15718. start: Number,
  15719. end: Number,
  15720. steps: _int | None = None,
  15721. base: _float = 10.0,
  15722. *,
  15723. out: Tensor | None = None,
  15724. dtype: _dtype | None = None,
  15725. device: DeviceLikeType | None = None,
  15726. requires_grad: _bool = False,
  15727. pin_memory: _bool = False,
  15728. ) -> Tensor:
  15729. r"""
  15730. logspace(start, end, steps, base=10.0, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15731. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15732. spaced from :math:`{{\text{{base}}}}^{{\text{{start}}}}` to
  15733. :math:`{{\text{{base}}}}^{{\text{{end}}}}`, inclusive, on a logarithmic scale
  15734. with base :attr:`base`. That is, the values are:
  15735. .. math::
  15736. (\text{base}^{\text{start}},
  15737. \text{base}^{(\text{start} + \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15738. \ldots,
  15739. \text{base}^{(\text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15740. \text{base}^{\text{end}})
  15741. From PyTorch 1.11 logspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15742. Args:
  15743. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15744. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15745. steps (int): size of the constructed tensor
  15746. base (float, optional): base of the logarithm function. Default: ``10.0``.
  15747. Keyword arguments:
  15748. out (Tensor, optional): the output tensor.
  15749. dtype (torch.dtype, optional): the data type to perform the computation in.
  15750. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15751. when both :attr:`start` and :attr:`end` are real,
  15752. and corresponding complex dtype when either is complex.
  15753. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15754. Default: ``torch.strided``.
  15755. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15756. Default: if ``None``, uses the current device for the default tensor type
  15757. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15758. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15759. requires_grad (bool, optional): If autograd should record operations on the
  15760. returned tensor. Default: ``False``.
  15761. Example::
  15762. >>> torch.logspace(start=-10, end=10, steps=5)
  15763. tensor([ 1.0000e-10, 1.0000e-05, 1.0000e+00, 1.0000e+05, 1.0000e+10])
  15764. >>> torch.logspace(start=0.1, end=1.0, steps=5)
  15765. tensor([ 1.2589, 2.1135, 3.5481, 5.9566, 10.0000])
  15766. >>> torch.logspace(start=0.1, end=1.0, steps=1)
  15767. tensor([1.2589])
  15768. >>> torch.logspace(start=2, end=2, steps=1, base=2)
  15769. tensor([4.0])
  15770. """
  15771. @overload
  15772. def logspace(
  15773. start: Tensor,
  15774. end: Tensor,
  15775. steps: _int,
  15776. base: _float = 10.0,
  15777. *,
  15778. out: Tensor | None = None,
  15779. dtype: _dtype | None = None,
  15780. layout: _layout | None = None,
  15781. device: DeviceLikeType | None = None,
  15782. pin_memory: _bool | None = False,
  15783. requires_grad: _bool | None = False,
  15784. ) -> Tensor:
  15785. r"""
  15786. logspace(start, end, steps, base=10.0, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15787. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15788. spaced from :math:`{{\text{{base}}}}^{{\text{{start}}}}` to
  15789. :math:`{{\text{{base}}}}^{{\text{{end}}}}`, inclusive, on a logarithmic scale
  15790. with base :attr:`base`. That is, the values are:
  15791. .. math::
  15792. (\text{base}^{\text{start}},
  15793. \text{base}^{(\text{start} + \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15794. \ldots,
  15795. \text{base}^{(\text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15796. \text{base}^{\text{end}})
  15797. From PyTorch 1.11 logspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15798. Args:
  15799. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15800. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15801. steps (int): size of the constructed tensor
  15802. base (float, optional): base of the logarithm function. Default: ``10.0``.
  15803. Keyword arguments:
  15804. out (Tensor, optional): the output tensor.
  15805. dtype (torch.dtype, optional): the data type to perform the computation in.
  15806. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15807. when both :attr:`start` and :attr:`end` are real,
  15808. and corresponding complex dtype when either is complex.
  15809. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15810. Default: ``torch.strided``.
  15811. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15812. Default: if ``None``, uses the current device for the default tensor type
  15813. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15814. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15815. requires_grad (bool, optional): If autograd should record operations on the
  15816. returned tensor. Default: ``False``.
  15817. Example::
  15818. >>> torch.logspace(start=-10, end=10, steps=5)
  15819. tensor([ 1.0000e-10, 1.0000e-05, 1.0000e+00, 1.0000e+05, 1.0000e+10])
  15820. >>> torch.logspace(start=0.1, end=1.0, steps=5)
  15821. tensor([ 1.2589, 2.1135, 3.5481, 5.9566, 10.0000])
  15822. >>> torch.logspace(start=0.1, end=1.0, steps=1)
  15823. tensor([1.2589])
  15824. >>> torch.logspace(start=2, end=2, steps=1, base=2)
  15825. tensor([4.0])
  15826. """
  15827. @overload
  15828. def logspace(
  15829. start: Number | _complex,
  15830. end: Tensor,
  15831. steps: _int,
  15832. base: _float = 10.0,
  15833. *,
  15834. out: Tensor | None = None,
  15835. dtype: _dtype | None = None,
  15836. layout: _layout | None = None,
  15837. device: DeviceLikeType | None = None,
  15838. pin_memory: _bool | None = False,
  15839. requires_grad: _bool | None = False,
  15840. ) -> Tensor:
  15841. r"""
  15842. logspace(start, end, steps, base=10.0, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15843. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15844. spaced from :math:`{{\text{{base}}}}^{{\text{{start}}}}` to
  15845. :math:`{{\text{{base}}}}^{{\text{{end}}}}`, inclusive, on a logarithmic scale
  15846. with base :attr:`base`. That is, the values are:
  15847. .. math::
  15848. (\text{base}^{\text{start}},
  15849. \text{base}^{(\text{start} + \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15850. \ldots,
  15851. \text{base}^{(\text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15852. \text{base}^{\text{end}})
  15853. From PyTorch 1.11 logspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15854. Args:
  15855. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15856. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15857. steps (int): size of the constructed tensor
  15858. base (float, optional): base of the logarithm function. Default: ``10.0``.
  15859. Keyword arguments:
  15860. out (Tensor, optional): the output tensor.
  15861. dtype (torch.dtype, optional): the data type to perform the computation in.
  15862. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15863. when both :attr:`start` and :attr:`end` are real,
  15864. and corresponding complex dtype when either is complex.
  15865. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15866. Default: ``torch.strided``.
  15867. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15868. Default: if ``None``, uses the current device for the default tensor type
  15869. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15870. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15871. requires_grad (bool, optional): If autograd should record operations on the
  15872. returned tensor. Default: ``False``.
  15873. Example::
  15874. >>> torch.logspace(start=-10, end=10, steps=5)
  15875. tensor([ 1.0000e-10, 1.0000e-05, 1.0000e+00, 1.0000e+05, 1.0000e+10])
  15876. >>> torch.logspace(start=0.1, end=1.0, steps=5)
  15877. tensor([ 1.2589, 2.1135, 3.5481, 5.9566, 10.0000])
  15878. >>> torch.logspace(start=0.1, end=1.0, steps=1)
  15879. tensor([1.2589])
  15880. >>> torch.logspace(start=2, end=2, steps=1, base=2)
  15881. tensor([4.0])
  15882. """
  15883. @overload
  15884. def logspace(
  15885. start: Tensor,
  15886. end: Number | _complex,
  15887. steps: _int,
  15888. base: _float = 10.0,
  15889. *,
  15890. out: Tensor | None = None,
  15891. dtype: _dtype | None = None,
  15892. layout: _layout | None = None,
  15893. device: DeviceLikeType | None = None,
  15894. pin_memory: _bool | None = False,
  15895. requires_grad: _bool | None = False,
  15896. ) -> Tensor:
  15897. r"""
  15898. logspace(start, end, steps, base=10.0, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15899. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15900. spaced from :math:`{{\text{{base}}}}^{{\text{{start}}}}` to
  15901. :math:`{{\text{{base}}}}^{{\text{{end}}}}`, inclusive, on a logarithmic scale
  15902. with base :attr:`base`. That is, the values are:
  15903. .. math::
  15904. (\text{base}^{\text{start}},
  15905. \text{base}^{(\text{start} + \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15906. \ldots,
  15907. \text{base}^{(\text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15908. \text{base}^{\text{end}})
  15909. From PyTorch 1.11 logspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15910. Args:
  15911. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15912. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15913. steps (int): size of the constructed tensor
  15914. base (float, optional): base of the logarithm function. Default: ``10.0``.
  15915. Keyword arguments:
  15916. out (Tensor, optional): the output tensor.
  15917. dtype (torch.dtype, optional): the data type to perform the computation in.
  15918. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15919. when both :attr:`start` and :attr:`end` are real,
  15920. and corresponding complex dtype when either is complex.
  15921. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15922. Default: ``torch.strided``.
  15923. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15924. Default: if ``None``, uses the current device for the default tensor type
  15925. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15926. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15927. requires_grad (bool, optional): If autograd should record operations on the
  15928. returned tensor. Default: ``False``.
  15929. Example::
  15930. >>> torch.logspace(start=-10, end=10, steps=5)
  15931. tensor([ 1.0000e-10, 1.0000e-05, 1.0000e+00, 1.0000e+05, 1.0000e+10])
  15932. >>> torch.logspace(start=0.1, end=1.0, steps=5)
  15933. tensor([ 1.2589, 2.1135, 3.5481, 5.9566, 10.0000])
  15934. >>> torch.logspace(start=0.1, end=1.0, steps=1)
  15935. tensor([1.2589])
  15936. >>> torch.logspace(start=2, end=2, steps=1, base=2)
  15937. tensor([4.0])
  15938. """
  15939. @overload
  15940. def logspace(
  15941. start: Number | _complex,
  15942. end: Number | _complex,
  15943. steps: _int,
  15944. base: _float = 10.0,
  15945. *,
  15946. out: Tensor | None = None,
  15947. dtype: _dtype | None = None,
  15948. layout: _layout | None = None,
  15949. device: DeviceLikeType | None = None,
  15950. pin_memory: _bool | None = False,
  15951. requires_grad: _bool | None = False,
  15952. ) -> Tensor:
  15953. r"""
  15954. logspace(start, end, steps, base=10.0, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15955. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15956. spaced from :math:`{{\text{{base}}}}^{{\text{{start}}}}` to
  15957. :math:`{{\text{{base}}}}^{{\text{{end}}}}`, inclusive, on a logarithmic scale
  15958. with base :attr:`base`. That is, the values are:
  15959. .. math::
  15960. (\text{base}^{\text{start}},
  15961. \text{base}^{(\text{start} + \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15962. \ldots,
  15963. \text{base}^{(\text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15964. \text{base}^{\text{end}})
  15965. From PyTorch 1.11 logspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15966. Args:
  15967. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15968. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15969. steps (int): size of the constructed tensor
  15970. base (float, optional): base of the logarithm function. Default: ``10.0``.
  15971. Keyword arguments:
  15972. out (Tensor, optional): the output tensor.
  15973. dtype (torch.dtype, optional): the data type to perform the computation in.
  15974. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15975. when both :attr:`start` and :attr:`end` are real,
  15976. and corresponding complex dtype when either is complex.
  15977. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15978. Default: ``torch.strided``.
  15979. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15980. Default: if ``None``, uses the current device for the default tensor type
  15981. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15982. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15983. requires_grad (bool, optional): If autograd should record operations on the
  15984. returned tensor. Default: ``False``.
  15985. Example::
  15986. >>> torch.logspace(start=-10, end=10, steps=5)
  15987. tensor([ 1.0000e-10, 1.0000e-05, 1.0000e+00, 1.0000e+05, 1.0000e+10])
  15988. >>> torch.logspace(start=0.1, end=1.0, steps=5)
  15989. tensor([ 1.2589, 2.1135, 3.5481, 5.9566, 10.0000])
  15990. >>> torch.logspace(start=0.1, end=1.0, steps=1)
  15991. tensor([1.2589])
  15992. >>> torch.logspace(start=2, end=2, steps=1, base=2)
  15993. tensor([4.0])
  15994. """
  15995. @overload
  15996. def logsumexp(
  15997. input: Tensor,
  15998. dim: _int | _size,
  15999. keepdim: _bool = False,
  16000. *,
  16001. out: Tensor | None = None,
  16002. ) -> Tensor:
  16003. r"""
  16004. logsumexp(input, dim, keepdim=False, *, out=None)
  16005. Returns the log of summed exponentials of each row of the :attr:`input`
  16006. tensor in the given dimension :attr:`dim`. The computation is numerically
  16007. stabilized.
  16008. For summation index :math:`j` given by `dim` and other indices :math:`i`, the result is
  16009. .. math::
  16010. \text{logsumexp}(x)_{i} = \log \sum_j \exp(x_{ij})
  16011. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  16012. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  16013. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  16014. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  16015. Args:
  16016. input (Tensor): the input tensor.
  16017. dim (int or tuple of ints): the dimension or dimensions to reduce.
  16018. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16019. Keyword args:
  16020. out (Tensor, optional): the output tensor.
  16021. Example::
  16022. >>> a = torch.randn(3, 3)
  16023. >>> torch.logsumexp(a, 1)
  16024. tensor([1.4907, 1.0593, 1.5696])
  16025. >>> torch.dist(torch.logsumexp(a, 1), torch.log(torch.sum(torch.exp(a), 1)))
  16026. tensor(1.6859e-07)
  16027. """
  16028. @overload
  16029. def logsumexp(
  16030. input: Tensor,
  16031. dim: Sequence[str | EllipsisType | None],
  16032. keepdim: _bool = False,
  16033. *,
  16034. out: Tensor | None = None,
  16035. ) -> Tensor:
  16036. r"""
  16037. logsumexp(input, dim, keepdim=False, *, out=None)
  16038. Returns the log of summed exponentials of each row of the :attr:`input`
  16039. tensor in the given dimension :attr:`dim`. The computation is numerically
  16040. stabilized.
  16041. For summation index :math:`j` given by `dim` and other indices :math:`i`, the result is
  16042. .. math::
  16043. \text{logsumexp}(x)_{i} = \log \sum_j \exp(x_{ij})
  16044. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  16045. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  16046. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  16047. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  16048. Args:
  16049. input (Tensor): the input tensor.
  16050. dim (int or tuple of ints): the dimension or dimensions to reduce.
  16051. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16052. Keyword args:
  16053. out (Tensor, optional): the output tensor.
  16054. Example::
  16055. >>> a = torch.randn(3, 3)
  16056. >>> torch.logsumexp(a, 1)
  16057. tensor([1.4907, 1.0593, 1.5696])
  16058. >>> torch.dist(torch.logsumexp(a, 1), torch.log(torch.sum(torch.exp(a), 1)))
  16059. tensor(1.6859e-07)
  16060. """
  16061. @overload
  16062. def lstm(
  16063. data: Tensor,
  16064. batch_sizes: Tensor,
  16065. hx: tuple[Tensor, ...] | list[Tensor] | None,
  16066. params: tuple[Tensor, ...] | list[Tensor] | None,
  16067. has_biases: _bool,
  16068. num_layers: _int,
  16069. dropout: _float,
  16070. train: _bool,
  16071. bidirectional: _bool,
  16072. ) -> tuple[Tensor, Tensor, Tensor]: ...
  16073. @overload
  16074. def lstm(
  16075. input: Tensor,
  16076. hx: tuple[Tensor, ...] | list[Tensor] | None,
  16077. params: tuple[Tensor, ...] | list[Tensor] | None,
  16078. has_biases: _bool,
  16079. num_layers: _int,
  16080. dropout: _float,
  16081. train: _bool,
  16082. bidirectional: _bool,
  16083. batch_first: _bool,
  16084. ) -> tuple[Tensor, Tensor, Tensor]: ...
  16085. def lstm_cell(
  16086. input: Tensor,
  16087. hx: tuple[Tensor, ...] | list[Tensor] | None,
  16088. w_ih: Tensor,
  16089. w_hh: Tensor,
  16090. b_ih: Tensor | None = None,
  16091. b_hh: Tensor | None = None,
  16092. ) -> tuple[Tensor, Tensor]: ...
  16093. @overload
  16094. def lt(
  16095. input: Tensor,
  16096. other: Tensor,
  16097. *,
  16098. out: Tensor | None = None,
  16099. ) -> Tensor:
  16100. r"""
  16101. lt(input, other, *, out=None) -> Tensor
  16102. Computes :math:`\text{input} < \text{other}` element-wise.
  16103. The second argument can be a number or a tensor whose shape is
  16104. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  16105. Args:
  16106. input (Tensor): the tensor to compare
  16107. other (Tensor or float): the tensor or value to compare
  16108. Keyword args:
  16109. out (Tensor, optional): the output tensor.
  16110. Returns:
  16111. A boolean tensor that is True where :attr:`input` is less than :attr:`other` and False elsewhere
  16112. Example::
  16113. >>> torch.lt(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  16114. tensor([[False, False], [True, False]])
  16115. """
  16116. @overload
  16117. def lt(
  16118. input: Tensor,
  16119. other: Number | _complex,
  16120. *,
  16121. out: Tensor | None = None,
  16122. ) -> Tensor:
  16123. r"""
  16124. lt(input, other, *, out=None) -> Tensor
  16125. Computes :math:`\text{input} < \text{other}` element-wise.
  16126. The second argument can be a number or a tensor whose shape is
  16127. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  16128. Args:
  16129. input (Tensor): the tensor to compare
  16130. other (Tensor or float): the tensor or value to compare
  16131. Keyword args:
  16132. out (Tensor, optional): the output tensor.
  16133. Returns:
  16134. A boolean tensor that is True where :attr:`input` is less than :attr:`other` and False elsewhere
  16135. Example::
  16136. >>> torch.lt(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  16137. tensor([[False, False], [True, False]])
  16138. """
  16139. def lu_solve(
  16140. input: Tensor,
  16141. LU_data: Tensor,
  16142. LU_pivots: Tensor,
  16143. *,
  16144. out: Tensor | None = None,
  16145. ) -> Tensor:
  16146. r"""
  16147. lu_solve(b, LU_data, LU_pivots, *, out=None) -> Tensor
  16148. Returns the LU solve of the linear system :math:`Ax = b` using the partially pivoted
  16149. LU factorization of A from :func:`~linalg.lu_factor`.
  16150. This function supports ``float``, ``double``, ``cfloat`` and ``cdouble`` dtypes for :attr:`input`.
  16151. .. warning::
  16152. :func:`torch.lu_solve` is deprecated in favor of :func:`torch.linalg.lu_solve`.
  16153. :func:`torch.lu_solve` will be removed in a future PyTorch release.
  16154. ``X = torch.lu_solve(B, LU, pivots)`` should be replaced with
  16155. .. code:: python
  16156. X = linalg.lu_solve(LU, pivots, B)
  16157. Arguments:
  16158. b (Tensor): the RHS tensor of size :math:`(*, m, k)`, where :math:`*`
  16159. is zero or more batch dimensions.
  16160. LU_data (Tensor): the pivoted LU factorization of A from :meth:`~linalg.lu_factor` of size :math:`(*, m, m)`,
  16161. where :math:`*` is zero or more batch dimensions.
  16162. LU_pivots (IntTensor): the pivots of the LU factorization from :meth:`~linalg.lu_factor` of size :math:`(*, m)`,
  16163. where :math:`*` is zero or more batch dimensions.
  16164. The batch dimensions of :attr:`LU_pivots` must be equal to the batch dimensions of
  16165. :attr:`LU_data`.
  16166. Keyword args:
  16167. out (Tensor, optional): the output tensor.
  16168. Example::
  16169. >>> A = torch.randn(2, 3, 3)
  16170. >>> b = torch.randn(2, 3, 1)
  16171. >>> LU, pivots = torch.linalg.lu_factor(A)
  16172. >>> x = torch.lu_solve(b, LU, pivots)
  16173. >>> torch.dist(A @ x, b)
  16174. tensor(1.00000e-07 *
  16175. 2.8312)
  16176. """
  16177. def lu_unpack(
  16178. LU_data: Tensor,
  16179. LU_pivots: Tensor,
  16180. unpack_data: _bool = True,
  16181. unpack_pivots: _bool = True,
  16182. *,
  16183. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  16184. ) -> torch.return_types.lu_unpack:
  16185. r"""
  16186. lu_unpack(LU_data, LU_pivots, unpack_data=True, unpack_pivots=True, *, out=None) -> (Tensor, Tensor, Tensor)
  16187. Unpacks the LU decomposition returned by :func:`~linalg.lu_factor` into the `P, L, U` matrices.
  16188. .. seealso::
  16189. :func:`~linalg.lu` returns the matrices from the LU decomposition. Its gradient formula is more efficient
  16190. than that of doing :func:`~linalg.lu_factor` followed by :func:`~linalg.lu_unpack`.
  16191. Args:
  16192. LU_data (Tensor): the packed LU factorization data
  16193. LU_pivots (Tensor): the packed LU factorization pivots
  16194. unpack_data (bool): flag indicating if the data should be unpacked.
  16195. If ``False``, then the returned ``L`` and ``U`` are empty tensors.
  16196. Default: ``True``
  16197. unpack_pivots (bool): flag indicating if the pivots should be unpacked into a permutation matrix ``P``.
  16198. If ``False``, then the returned ``P`` is an empty tensor.
  16199. Default: ``True``
  16200. Keyword args:
  16201. out (tuple, optional): output tuple of three tensors. Ignored if `None`.
  16202. Returns:
  16203. A namedtuple ``(P, L, U)``
  16204. Examples::
  16205. >>> A = torch.randn(2, 3, 3)
  16206. >>> LU, pivots = torch.linalg.lu_factor(A)
  16207. >>> P, L, U = torch.lu_unpack(LU, pivots)
  16208. >>> # We can recover A from the factorization
  16209. >>> A_ = P @ L @ U
  16210. >>> torch.allclose(A, A_)
  16211. True
  16212. >>> # LU factorization of a rectangular matrix:
  16213. >>> A = torch.randn(2, 3, 2)
  16214. >>> LU, pivots = torch.linalg.lu_factor(A)
  16215. >>> P, L, U = torch.lu_unpack(LU, pivots)
  16216. >>> # P, L, U are the same as returned by linalg.lu
  16217. >>> P_, L_, U_ = torch.linalg.lu(A)
  16218. >>> torch.allclose(P, P_) and torch.allclose(L, L_) and torch.allclose(U, U_)
  16219. True
  16220. """
  16221. def margin_ranking_loss(
  16222. input1: Tensor,
  16223. input2: Tensor,
  16224. target: Tensor,
  16225. margin: _float = 0.0,
  16226. reduction: _int = 1,
  16227. ) -> Tensor: ...
  16228. @overload
  16229. def masked_fill(input: Tensor, mask: Tensor, value: Tensor) -> Tensor: ...
  16230. @overload
  16231. def masked_fill(
  16232. input: Tensor,
  16233. mask: Tensor,
  16234. value: Number | _complex,
  16235. ) -> Tensor: ...
  16236. def masked_scatter(input: Tensor, mask: Tensor, source: Tensor) -> Tensor: ...
  16237. def masked_select(
  16238. input: Tensor,
  16239. mask: Tensor,
  16240. *,
  16241. out: Tensor | None = None,
  16242. ) -> Tensor:
  16243. r"""
  16244. masked_select(input, mask, *, out=None) -> Tensor
  16245. Returns a new 1-D tensor which indexes the :attr:`input` tensor according to
  16246. the boolean mask :attr:`mask` which is a `BoolTensor`.
  16247. The shapes of the :attr:`mask` tensor and the :attr:`input` tensor don't need
  16248. to match, but they must be :ref:`broadcastable <broadcasting-semantics>`.
  16249. .. note:: The returned tensor does **not** use the same storage
  16250. as the original tensor
  16251. Args:
  16252. input (Tensor): the input tensor.
  16253. mask (BoolTensor): the tensor containing the binary mask to index with
  16254. Keyword args:
  16255. out (Tensor, optional): the output tensor.
  16256. Example::
  16257. >>> x = torch.randn(3, 4)
  16258. >>> x
  16259. tensor([[ 0.3552, -2.3825, -0.8297, 0.3477],
  16260. [-1.2035, 1.2252, 0.5002, 0.6248],
  16261. [ 0.1307, -2.0608, 0.1244, 2.0139]])
  16262. >>> mask = x.ge(0.5)
  16263. >>> mask
  16264. tensor([[False, False, False, False],
  16265. [False, True, True, True],
  16266. [False, False, False, True]])
  16267. >>> torch.masked_select(x, mask)
  16268. tensor([ 1.2252, 0.5002, 0.6248, 2.0139])
  16269. """
  16270. def matmul(
  16271. input: Tensor,
  16272. other: Tensor,
  16273. *,
  16274. out: Tensor | None = None,
  16275. ) -> Tensor:
  16276. r"""
  16277. matmul(input, other, *, out=None) -> Tensor
  16278. Matrix product of two tensors.
  16279. The behavior depends on the dimensionality of the tensors as follows:
  16280. - If both tensors are 1-dimensional, the dot product (scalar) is returned.
  16281. - If both arguments are 2-dimensional, the matrix-matrix product is returned.
  16282. - If the first argument is 1-dimensional and the second argument is 2-dimensional,
  16283. a 1 is prepended to its dimension for the purpose of the matrix multiply.
  16284. After the matrix multiply, the prepended dimension is removed.
  16285. - If the first argument is 2-dimensional and the second argument is 1-dimensional,
  16286. the matrix-vector product is returned.
  16287. - If both arguments are at least 1-dimensional and at least one argument is
  16288. N-dimensional (where N > 2), then a batched matrix multiply is returned. If the first
  16289. argument is 1-dimensional, a 1 is prepended to its dimension for the purpose of the
  16290. batched matrix multiply and removed after. If the second argument is 1-dimensional, a
  16291. 1 is appended to its dimension for the purpose of the batched matrix multiply and removed after.
  16292. The first N-2 dimensions of each argument, the batch dimensions, are
  16293. :ref:`broadcast <broadcasting-semantics>` (and thus must be broadcastable).
  16294. The last 2, the matrix dimensions, are handled as in the matrix-matrix product.
  16295. For example, if :attr:`input` is a
  16296. :math:`(j \times 1 \times n \times m)` tensor and :attr:`other` is a :math:`(k \times m \times p)`
  16297. tensor, the batch dimensions are :math:`(j \times 1)` and :math:`(k)`,
  16298. and the matrix dimensions are :math:`(n \times m)` and :math:`(m \times p)`.
  16299. :attr:`out` will be a :math:`(j \times k \times n \times p)` tensor.
  16300. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`. In particular the
  16301. matrix-matrix (both arguments 2-dimensional) supports sparse arguments with the same restrictions
  16302. as :func:`torch.mm`
  16303. .. warning::
  16304. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  16305. or may not have autograd support. If you notice missing functionality please
  16306. open a feature request.
  16307. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  16308. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  16309. .. note::
  16310. The 1-dimensional dot product version of this function does not support an :attr:`out` parameter.
  16311. Arguments:
  16312. input (Tensor): the first tensor to be multiplied
  16313. other (Tensor): the second tensor to be multiplied
  16314. Keyword args:
  16315. out (Tensor, optional): the output tensor.
  16316. Example::
  16317. >>> # vector x vector
  16318. >>> tensor1 = torch.randn(3)
  16319. >>> tensor2 = torch.randn(3)
  16320. >>> torch.matmul(tensor1, tensor2).size()
  16321. torch.Size([])
  16322. >>> # matrix x vector
  16323. >>> tensor1 = torch.randn(3, 4)
  16324. >>> tensor2 = torch.randn(4)
  16325. >>> torch.matmul(tensor1, tensor2).size()
  16326. torch.Size([3])
  16327. >>> # batched matrix x broadcasted vector
  16328. >>> tensor1 = torch.randn(10, 3, 4)
  16329. >>> tensor2 = torch.randn(4)
  16330. >>> torch.matmul(tensor1, tensor2).size()
  16331. torch.Size([10, 3])
  16332. >>> # batched matrix x batched matrix
  16333. >>> tensor1 = torch.randn(10, 3, 4)
  16334. >>> tensor2 = torch.randn(10, 4, 5)
  16335. >>> torch.matmul(tensor1, tensor2).size()
  16336. torch.Size([10, 3, 5])
  16337. >>> # batched matrix x broadcasted matrix
  16338. >>> tensor1 = torch.randn(10, 3, 4)
  16339. >>> tensor2 = torch.randn(4, 5)
  16340. >>> torch.matmul(tensor1, tensor2).size()
  16341. torch.Size([10, 3, 5])
  16342. """
  16343. def matrix_exp(input: Tensor) -> Tensor:
  16344. r"""
  16345. matrix_exp(A) -> Tensor
  16346. Alias for :func:`torch.linalg.matrix_exp`.
  16347. """
  16348. def matrix_power(
  16349. input: Tensor,
  16350. n: _int,
  16351. *,
  16352. out: Tensor | None = None,
  16353. ) -> Tensor:
  16354. r"""
  16355. matrix_power(input, n, *, out=None) -> Tensor
  16356. Alias for :func:`torch.linalg.matrix_power`
  16357. """
  16358. @overload
  16359. def max(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  16360. r"""
  16361. max(input, *, out=None) -> Tensor
  16362. Returns the maximum value of all elements in the ``input`` tensor.
  16363. .. note::
  16364. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  16365. - ``amax``/``amin`` supports reducing on multiple dimensions,
  16366. - ``amax``/``amin`` does not return indices.
  16367. Both ``amax``/``amin`` evenly distribute gradients between equal values
  16368. when there are multiple input elements with the same minimum or maximum value.
  16369. For ``max``/``min``:
  16370. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  16371. - If reduce over one specified axis, only propagate to the indexed element.
  16372. Args:
  16373. input (Tensor): the input tensor.
  16374. Keyword args:
  16375. out (Tensor, optional): the output tensor.
  16376. Example::
  16377. >>> a = torch.randn(1, 3)
  16378. >>> a
  16379. tensor([[ 0.6763, 0.7445, -2.2369]])
  16380. >>> torch.max(a)
  16381. tensor(0.7445)
  16382. .. function:: max(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  16383. :noindex:
  16384. Returns a namedtuple ``(values, indices)`` where ``values`` is the maximum
  16385. value of each row of the :attr:`input` tensor in the given dimension
  16386. :attr:`dim`. And ``indices`` is the index location of each maximum value found
  16387. (argmax).
  16388. If ``keepdim`` is ``True``, the output tensors are of the same size
  16389. as ``input`` except in the dimension ``dim`` where they are of size 1.
  16390. Otherwise, ``dim`` is squeezed (see :func:`torch.squeeze`), resulting
  16391. in the output tensors having 1 fewer dimension than ``input``.
  16392. .. note:: If there are multiple maximal values in a reduced row then
  16393. the indices of the first maximal value are returned.
  16394. Args:
  16395. input (Tensor): the input tensor.
  16396. dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
  16397. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16398. Keyword args:
  16399. out (tuple, optional): the result tuple of two output tensors (max, max_indices)
  16400. Example::
  16401. >>> a = torch.randn(4, 4)
  16402. >>> a
  16403. tensor([[-1.2360, -0.2942, -0.1222, 0.8475],
  16404. [ 1.1949, -1.1127, -2.2379, -0.6702],
  16405. [ 1.5717, -0.9207, 0.1297, -1.8768],
  16406. [-0.6172, 1.0036, -0.6060, -0.2432]])
  16407. >>> torch.max(a, 1)
  16408. torch.return_types.max(values=tensor([0.8475, 1.1949, 1.5717, 1.0036]), indices=tensor([3, 0, 0, 1]))
  16409. >>> a = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
  16410. >>> a.max(dim=1, keepdim=True)
  16411. torch.return_types.max(
  16412. values=tensor([[2.], [4.]]),
  16413. indices=tensor([[1], [1]]))
  16414. >>> a.max(dim=1, keepdim=False)
  16415. torch.return_types.max(
  16416. values=tensor([2., 4.]),
  16417. indices=tensor([1, 1]))
  16418. .. function:: max(input, other, *, out=None) -> Tensor
  16419. :noindex:
  16420. See :func:`torch.maximum`.
  16421. """
  16422. @overload
  16423. def max(
  16424. input: Tensor,
  16425. other: Tensor,
  16426. *,
  16427. out: Tensor | None = None,
  16428. ) -> Tensor:
  16429. r"""
  16430. max(input, *, out=None) -> Tensor
  16431. Returns the maximum value of all elements in the ``input`` tensor.
  16432. .. note::
  16433. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  16434. - ``amax``/``amin`` supports reducing on multiple dimensions,
  16435. - ``amax``/``amin`` does not return indices.
  16436. Both ``amax``/``amin`` evenly distribute gradients between equal values
  16437. when there are multiple input elements with the same minimum or maximum value.
  16438. For ``max``/``min``:
  16439. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  16440. - If reduce over one specified axis, only propagate to the indexed element.
  16441. Args:
  16442. input (Tensor): the input tensor.
  16443. Keyword args:
  16444. out (Tensor, optional): the output tensor.
  16445. Example::
  16446. >>> a = torch.randn(1, 3)
  16447. >>> a
  16448. tensor([[ 0.6763, 0.7445, -2.2369]])
  16449. >>> torch.max(a)
  16450. tensor(0.7445)
  16451. .. function:: max(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  16452. :noindex:
  16453. Returns a namedtuple ``(values, indices)`` where ``values`` is the maximum
  16454. value of each row of the :attr:`input` tensor in the given dimension
  16455. :attr:`dim`. And ``indices`` is the index location of each maximum value found
  16456. (argmax).
  16457. If ``keepdim`` is ``True``, the output tensors are of the same size
  16458. as ``input`` except in the dimension ``dim`` where they are of size 1.
  16459. Otherwise, ``dim`` is squeezed (see :func:`torch.squeeze`), resulting
  16460. in the output tensors having 1 fewer dimension than ``input``.
  16461. .. note:: If there are multiple maximal values in a reduced row then
  16462. the indices of the first maximal value are returned.
  16463. Args:
  16464. input (Tensor): the input tensor.
  16465. dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
  16466. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16467. Keyword args:
  16468. out (tuple, optional): the result tuple of two output tensors (max, max_indices)
  16469. Example::
  16470. >>> a = torch.randn(4, 4)
  16471. >>> a
  16472. tensor([[-1.2360, -0.2942, -0.1222, 0.8475],
  16473. [ 1.1949, -1.1127, -2.2379, -0.6702],
  16474. [ 1.5717, -0.9207, 0.1297, -1.8768],
  16475. [-0.6172, 1.0036, -0.6060, -0.2432]])
  16476. >>> torch.max(a, 1)
  16477. torch.return_types.max(values=tensor([0.8475, 1.1949, 1.5717, 1.0036]), indices=tensor([3, 0, 0, 1]))
  16478. >>> a = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
  16479. >>> a.max(dim=1, keepdim=True)
  16480. torch.return_types.max(
  16481. values=tensor([[2.], [4.]]),
  16482. indices=tensor([[1], [1]]))
  16483. >>> a.max(dim=1, keepdim=False)
  16484. torch.return_types.max(
  16485. values=tensor([2., 4.]),
  16486. indices=tensor([1, 1]))
  16487. .. function:: max(input, other, *, out=None) -> Tensor
  16488. :noindex:
  16489. See :func:`torch.maximum`.
  16490. """
  16491. @overload
  16492. def max(
  16493. input: Tensor,
  16494. dim: _int,
  16495. keepdim: _bool = False,
  16496. *,
  16497. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  16498. ) -> torch.return_types.max:
  16499. r"""
  16500. max(input, *, out=None) -> Tensor
  16501. Returns the maximum value of all elements in the ``input`` tensor.
  16502. .. note::
  16503. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  16504. - ``amax``/``amin`` supports reducing on multiple dimensions,
  16505. - ``amax``/``amin`` does not return indices.
  16506. Both ``amax``/``amin`` evenly distribute gradients between equal values
  16507. when there are multiple input elements with the same minimum or maximum value.
  16508. For ``max``/``min``:
  16509. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  16510. - If reduce over one specified axis, only propagate to the indexed element.
  16511. Args:
  16512. input (Tensor): the input tensor.
  16513. Keyword args:
  16514. out (Tensor, optional): the output tensor.
  16515. Example::
  16516. >>> a = torch.randn(1, 3)
  16517. >>> a
  16518. tensor([[ 0.6763, 0.7445, -2.2369]])
  16519. >>> torch.max(a)
  16520. tensor(0.7445)
  16521. .. function:: max(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  16522. :noindex:
  16523. Returns a namedtuple ``(values, indices)`` where ``values`` is the maximum
  16524. value of each row of the :attr:`input` tensor in the given dimension
  16525. :attr:`dim`. And ``indices`` is the index location of each maximum value found
  16526. (argmax).
  16527. If ``keepdim`` is ``True``, the output tensors are of the same size
  16528. as ``input`` except in the dimension ``dim`` where they are of size 1.
  16529. Otherwise, ``dim`` is squeezed (see :func:`torch.squeeze`), resulting
  16530. in the output tensors having 1 fewer dimension than ``input``.
  16531. .. note:: If there are multiple maximal values in a reduced row then
  16532. the indices of the first maximal value are returned.
  16533. Args:
  16534. input (Tensor): the input tensor.
  16535. dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
  16536. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16537. Keyword args:
  16538. out (tuple, optional): the result tuple of two output tensors (max, max_indices)
  16539. Example::
  16540. >>> a = torch.randn(4, 4)
  16541. >>> a
  16542. tensor([[-1.2360, -0.2942, -0.1222, 0.8475],
  16543. [ 1.1949, -1.1127, -2.2379, -0.6702],
  16544. [ 1.5717, -0.9207, 0.1297, -1.8768],
  16545. [-0.6172, 1.0036, -0.6060, -0.2432]])
  16546. >>> torch.max(a, 1)
  16547. torch.return_types.max(values=tensor([0.8475, 1.1949, 1.5717, 1.0036]), indices=tensor([3, 0, 0, 1]))
  16548. >>> a = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
  16549. >>> a.max(dim=1, keepdim=True)
  16550. torch.return_types.max(
  16551. values=tensor([[2.], [4.]]),
  16552. indices=tensor([[1], [1]]))
  16553. >>> a.max(dim=1, keepdim=False)
  16554. torch.return_types.max(
  16555. values=tensor([2., 4.]),
  16556. indices=tensor([1, 1]))
  16557. .. function:: max(input, other, *, out=None) -> Tensor
  16558. :noindex:
  16559. See :func:`torch.maximum`.
  16560. """
  16561. @overload
  16562. def max(
  16563. input: Tensor,
  16564. dim: str | EllipsisType | None,
  16565. keepdim: _bool = False,
  16566. *,
  16567. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  16568. ) -> torch.return_types.max:
  16569. r"""
  16570. max(input, *, out=None) -> Tensor
  16571. Returns the maximum value of all elements in the ``input`` tensor.
  16572. .. note::
  16573. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  16574. - ``amax``/``amin`` supports reducing on multiple dimensions,
  16575. - ``amax``/``amin`` does not return indices.
  16576. Both ``amax``/``amin`` evenly distribute gradients between equal values
  16577. when there are multiple input elements with the same minimum or maximum value.
  16578. For ``max``/``min``:
  16579. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  16580. - If reduce over one specified axis, only propagate to the indexed element.
  16581. Args:
  16582. input (Tensor): the input tensor.
  16583. Keyword args:
  16584. out (Tensor, optional): the output tensor.
  16585. Example::
  16586. >>> a = torch.randn(1, 3)
  16587. >>> a
  16588. tensor([[ 0.6763, 0.7445, -2.2369]])
  16589. >>> torch.max(a)
  16590. tensor(0.7445)
  16591. .. function:: max(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  16592. :noindex:
  16593. Returns a namedtuple ``(values, indices)`` where ``values`` is the maximum
  16594. value of each row of the :attr:`input` tensor in the given dimension
  16595. :attr:`dim`. And ``indices`` is the index location of each maximum value found
  16596. (argmax).
  16597. If ``keepdim`` is ``True``, the output tensors are of the same size
  16598. as ``input`` except in the dimension ``dim`` where they are of size 1.
  16599. Otherwise, ``dim`` is squeezed (see :func:`torch.squeeze`), resulting
  16600. in the output tensors having 1 fewer dimension than ``input``.
  16601. .. note:: If there are multiple maximal values in a reduced row then
  16602. the indices of the first maximal value are returned.
  16603. Args:
  16604. input (Tensor): the input tensor.
  16605. dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
  16606. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16607. Keyword args:
  16608. out (tuple, optional): the result tuple of two output tensors (max, max_indices)
  16609. Example::
  16610. >>> a = torch.randn(4, 4)
  16611. >>> a
  16612. tensor([[-1.2360, -0.2942, -0.1222, 0.8475],
  16613. [ 1.1949, -1.1127, -2.2379, -0.6702],
  16614. [ 1.5717, -0.9207, 0.1297, -1.8768],
  16615. [-0.6172, 1.0036, -0.6060, -0.2432]])
  16616. >>> torch.max(a, 1)
  16617. torch.return_types.max(values=tensor([0.8475, 1.1949, 1.5717, 1.0036]), indices=tensor([3, 0, 0, 1]))
  16618. >>> a = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
  16619. >>> a.max(dim=1, keepdim=True)
  16620. torch.return_types.max(
  16621. values=tensor([[2.], [4.]]),
  16622. indices=tensor([[1], [1]]))
  16623. >>> a.max(dim=1, keepdim=False)
  16624. torch.return_types.max(
  16625. values=tensor([2., 4.]),
  16626. indices=tensor([1, 1]))
  16627. .. function:: max(input, other, *, out=None) -> Tensor
  16628. :noindex:
  16629. See :func:`torch.maximum`.
  16630. """
  16631. def max_pool1d(
  16632. input: Tensor,
  16633. kernel_size: _int | _size,
  16634. stride: _int | _size = (),
  16635. padding: _int | _size = 0,
  16636. dilation: _int | _size = 1,
  16637. ceil_mode: _bool = False,
  16638. ) -> Tensor: ...
  16639. def max_pool1d_with_indices(
  16640. input: Tensor,
  16641. kernel_size: _int | _size,
  16642. stride: _int | _size = (),
  16643. padding: _int | _size = 0,
  16644. dilation: _int | _size = 1,
  16645. ceil_mode: _bool = False,
  16646. ) -> tuple[Tensor, Tensor]: ...
  16647. def max_pool2d(
  16648. input: Tensor,
  16649. kernel_size: _int | _size,
  16650. stride: _int | _size = (),
  16651. padding: _int | _size = 0,
  16652. dilation: _int | _size = 1,
  16653. ceil_mode: _bool = False,
  16654. ) -> Tensor: ...
  16655. def max_pool3d(
  16656. input: Tensor,
  16657. kernel_size: _int | _size,
  16658. stride: _int | _size = (),
  16659. padding: _int | _size = 0,
  16660. dilation: _int | _size = 1,
  16661. ceil_mode: _bool = False,
  16662. ) -> Tensor: ...
  16663. def maximum(
  16664. input: Tensor,
  16665. other: Tensor,
  16666. *,
  16667. out: Tensor | None = None,
  16668. ) -> Tensor:
  16669. r"""
  16670. maximum(input, other, *, out=None) -> Tensor
  16671. Computes the element-wise maximum of :attr:`input` and :attr:`other`.
  16672. .. note::
  16673. If one of the elements being compared is a NaN, then that element is returned.
  16674. :func:`maximum` is not supported for tensors with complex dtypes.
  16675. Args:
  16676. input (Tensor): the input tensor.
  16677. other (Tensor): the second input tensor
  16678. Keyword args:
  16679. out (Tensor, optional): the output tensor.
  16680. Example::
  16681. >>> a = torch.tensor((1, 2, -1))
  16682. >>> b = torch.tensor((3, 0, 4))
  16683. >>> torch.maximum(a, b)
  16684. tensor([3, 2, 4])
  16685. """
  16686. @overload
  16687. def mean(
  16688. input: Tensor,
  16689. *,
  16690. dtype: _dtype | None = None,
  16691. out: Tensor | None = None,
  16692. ) -> Tensor:
  16693. r"""
  16694. mean(input, *, dtype=None) -> Tensor
  16695. .. note::
  16696. If the `input` tensor is empty, ``torch.mean()`` returns ``nan``.
  16697. This behavior is consistent with NumPy and follows the definition
  16698. that the mean over an empty set is undefined.
  16699. Returns the mean value of all elements in the :attr:`input` tensor. Input must be floating point or complex.
  16700. Args:
  16701. input (Tensor):
  16702. the input tensor, either of floating point or complex dtype
  16703. Keyword args:
  16704. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  16705. If specified, the input tensor is casted to :attr:`dtype` before the operation
  16706. is performed. This is useful for preventing data type overflows. Default: None.
  16707. Example::
  16708. >>> a = torch.randn(1, 3)
  16709. >>> a
  16710. tensor([[ 0.2294, -0.5481, 1.3288]])
  16711. >>> torch.mean(a)
  16712. tensor(0.3367)
  16713. .. function:: mean(input, dim, keepdim=False, *, dtype=None, out=None) -> Tensor
  16714. :noindex:
  16715. Returns the mean value of each row of the :attr:`input` tensor in the given
  16716. dimension :attr:`dim`. If :attr:`dim` is a list of dimensions,
  16717. reduce over all of them.
  16718. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  16719. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  16720. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  16721. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  16722. Args:
  16723. input (Tensor): the input tensor.
  16724. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  16725. If ``None``, all dimensions are reduced.
  16726. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16727. Keyword args:
  16728. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  16729. If specified, the input tensor is casted to :attr:`dtype` before the operation
  16730. is performed. This is useful for preventing data type overflows. Default: None.
  16731. out (Tensor, optional): the output tensor.
  16732. .. seealso::
  16733. :func:`torch.nanmean` computes the mean value of `non-NaN` elements.
  16734. Example::
  16735. >>> a = torch.randn(4, 4)
  16736. >>> a
  16737. tensor([[-0.3841, 0.6320, 0.4254, -0.7384],
  16738. [-0.9644, 1.0131, -0.6549, -1.4279],
  16739. [-0.2951, -1.3350, -0.7694, 0.5600],
  16740. [ 1.0842, -0.9580, 0.3623, 0.2343]])
  16741. >>> torch.mean(a, 1)
  16742. tensor([-0.0163, -0.5085, -0.4599, 0.1807])
  16743. >>> torch.mean(a, 1, True)
  16744. tensor([[-0.0163],
  16745. [-0.5085],
  16746. [-0.4599],
  16747. [ 0.1807]])
  16748. """
  16749. @overload
  16750. def mean(
  16751. input: Tensor,
  16752. dim: _int | _size | None,
  16753. keepdim: _bool = False,
  16754. *,
  16755. dtype: _dtype | None = None,
  16756. out: Tensor | None = None,
  16757. ) -> Tensor:
  16758. r"""
  16759. mean(input, *, dtype=None) -> Tensor
  16760. .. note::
  16761. If the `input` tensor is empty, ``torch.mean()`` returns ``nan``.
  16762. This behavior is consistent with NumPy and follows the definition
  16763. that the mean over an empty set is undefined.
  16764. Returns the mean value of all elements in the :attr:`input` tensor. Input must be floating point or complex.
  16765. Args:
  16766. input (Tensor):
  16767. the input tensor, either of floating point or complex dtype
  16768. Keyword args:
  16769. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  16770. If specified, the input tensor is casted to :attr:`dtype` before the operation
  16771. is performed. This is useful for preventing data type overflows. Default: None.
  16772. Example::
  16773. >>> a = torch.randn(1, 3)
  16774. >>> a
  16775. tensor([[ 0.2294, -0.5481, 1.3288]])
  16776. >>> torch.mean(a)
  16777. tensor(0.3367)
  16778. .. function:: mean(input, dim, keepdim=False, *, dtype=None, out=None) -> Tensor
  16779. :noindex:
  16780. Returns the mean value of each row of the :attr:`input` tensor in the given
  16781. dimension :attr:`dim`. If :attr:`dim` is a list of dimensions,
  16782. reduce over all of them.
  16783. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  16784. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  16785. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  16786. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  16787. Args:
  16788. input (Tensor): the input tensor.
  16789. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  16790. If ``None``, all dimensions are reduced.
  16791. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16792. Keyword args:
  16793. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  16794. If specified, the input tensor is casted to :attr:`dtype` before the operation
  16795. is performed. This is useful for preventing data type overflows. Default: None.
  16796. out (Tensor, optional): the output tensor.
  16797. .. seealso::
  16798. :func:`torch.nanmean` computes the mean value of `non-NaN` elements.
  16799. Example::
  16800. >>> a = torch.randn(4, 4)
  16801. >>> a
  16802. tensor([[-0.3841, 0.6320, 0.4254, -0.7384],
  16803. [-0.9644, 1.0131, -0.6549, -1.4279],
  16804. [-0.2951, -1.3350, -0.7694, 0.5600],
  16805. [ 1.0842, -0.9580, 0.3623, 0.2343]])
  16806. >>> torch.mean(a, 1)
  16807. tensor([-0.0163, -0.5085, -0.4599, 0.1807])
  16808. >>> torch.mean(a, 1, True)
  16809. tensor([[-0.0163],
  16810. [-0.5085],
  16811. [-0.4599],
  16812. [ 0.1807]])
  16813. """
  16814. @overload
  16815. def mean(
  16816. input: Tensor,
  16817. dim: Sequence[str | EllipsisType | None],
  16818. keepdim: _bool = False,
  16819. *,
  16820. dtype: _dtype | None = None,
  16821. out: Tensor | None = None,
  16822. ) -> Tensor:
  16823. r"""
  16824. mean(input, *, dtype=None) -> Tensor
  16825. .. note::
  16826. If the `input` tensor is empty, ``torch.mean()`` returns ``nan``.
  16827. This behavior is consistent with NumPy and follows the definition
  16828. that the mean over an empty set is undefined.
  16829. Returns the mean value of all elements in the :attr:`input` tensor. Input must be floating point or complex.
  16830. Args:
  16831. input (Tensor):
  16832. the input tensor, either of floating point or complex dtype
  16833. Keyword args:
  16834. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  16835. If specified, the input tensor is casted to :attr:`dtype` before the operation
  16836. is performed. This is useful for preventing data type overflows. Default: None.
  16837. Example::
  16838. >>> a = torch.randn(1, 3)
  16839. >>> a
  16840. tensor([[ 0.2294, -0.5481, 1.3288]])
  16841. >>> torch.mean(a)
  16842. tensor(0.3367)
  16843. .. function:: mean(input, dim, keepdim=False, *, dtype=None, out=None) -> Tensor
  16844. :noindex:
  16845. Returns the mean value of each row of the :attr:`input` tensor in the given
  16846. dimension :attr:`dim`. If :attr:`dim` is a list of dimensions,
  16847. reduce over all of them.
  16848. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  16849. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  16850. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  16851. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  16852. Args:
  16853. input (Tensor): the input tensor.
  16854. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  16855. If ``None``, all dimensions are reduced.
  16856. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16857. Keyword args:
  16858. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  16859. If specified, the input tensor is casted to :attr:`dtype` before the operation
  16860. is performed. This is useful for preventing data type overflows. Default: None.
  16861. out (Tensor, optional): the output tensor.
  16862. .. seealso::
  16863. :func:`torch.nanmean` computes the mean value of `non-NaN` elements.
  16864. Example::
  16865. >>> a = torch.randn(4, 4)
  16866. >>> a
  16867. tensor([[-0.3841, 0.6320, 0.4254, -0.7384],
  16868. [-0.9644, 1.0131, -0.6549, -1.4279],
  16869. [-0.2951, -1.3350, -0.7694, 0.5600],
  16870. [ 1.0842, -0.9580, 0.3623, 0.2343]])
  16871. >>> torch.mean(a, 1)
  16872. tensor([-0.0163, -0.5085, -0.4599, 0.1807])
  16873. >>> torch.mean(a, 1, True)
  16874. tensor([[-0.0163],
  16875. [-0.5085],
  16876. [-0.4599],
  16877. [ 0.1807]])
  16878. """
  16879. @overload
  16880. def median(input: Tensor) -> Tensor:
  16881. r"""
  16882. median(input) -> Tensor
  16883. Returns the median of the values in :attr:`input`.
  16884. .. note::
  16885. The median is not unique for :attr:`input` tensors with an even number
  16886. of elements. In this case the lower of the two medians is returned. To
  16887. compute the mean of both medians, use :func:`torch.quantile` with ``q=0.5`` instead.
  16888. .. warning::
  16889. This function produces deterministic (sub)gradients unlike ``median(dim=0)``
  16890. Args:
  16891. input (Tensor): the input tensor.
  16892. Example::
  16893. >>> a = torch.randn(1, 3)
  16894. >>> a
  16895. tensor([[ 1.5219, -1.5212, 0.2202]])
  16896. >>> torch.median(a)
  16897. tensor(0.2202)
  16898. .. function:: median(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  16899. :noindex:
  16900. Returns a namedtuple ``(values, indices)`` where ``values`` contains the median of each row of :attr:`input`
  16901. in the dimension :attr:`dim`, and ``indices`` contains the index of the median values found in the dimension :attr:`dim`.
  16902. By default, :attr:`dim` is the last dimension of the :attr:`input` tensor.
  16903. If :attr:`keepdim` is ``True``, the output tensors are of the same size
  16904. as :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  16905. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  16906. the outputs tensor having 1 fewer dimension than :attr:`input`.
  16907. .. note::
  16908. The median is not unique for :attr:`input` tensors with an even number
  16909. of elements in the dimension :attr:`dim`. In this case the lower of the
  16910. two medians is returned. To compute the mean of both medians in
  16911. :attr:`input`, use :func:`torch.quantile` with ``q=0.5`` instead.
  16912. .. warning::
  16913. ``indices`` does not necessarily contain the first occurrence of each
  16914. median value found, unless it is unique.
  16915. The exact implementation details are device-specific.
  16916. Do not expect the same result when run on CPU and GPU in general.
  16917. For the same reason do not expect the gradients to be deterministic.
  16918. Args:
  16919. input (Tensor): the input tensor.
  16920. dim (int, optional): the dimension to reduce.
  16921. If ``None``, all dimensions are reduced.
  16922. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16923. Keyword args:
  16924. out ((Tensor, Tensor), optional): The first tensor will be populated with the median values and the second
  16925. tensor, which must have dtype long, with their indices in the dimension
  16926. :attr:`dim` of :attr:`input`.
  16927. Example::
  16928. >>> a = torch.randn(4, 5)
  16929. >>> a
  16930. tensor([[ 0.2505, -0.3982, -0.9948, 0.3518, -1.3131],
  16931. [ 0.3180, -0.6993, 1.0436, 0.0438, 0.2270],
  16932. [-0.2751, 0.7303, 0.2192, 0.3321, 0.2488],
  16933. [ 1.0778, -1.9510, 0.7048, 0.4742, -0.7125]])
  16934. >>> torch.median(a, 1)
  16935. torch.return_types.median(values=tensor([-0.3982, 0.2270, 0.2488, 0.4742]), indices=tensor([1, 4, 4, 3]))
  16936. """
  16937. @overload
  16938. def median(
  16939. input: Tensor,
  16940. dim: _int,
  16941. keepdim: _bool = False,
  16942. *,
  16943. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  16944. ) -> torch.return_types.median:
  16945. r"""
  16946. median(input) -> Tensor
  16947. Returns the median of the values in :attr:`input`.
  16948. .. note::
  16949. The median is not unique for :attr:`input` tensors with an even number
  16950. of elements. In this case the lower of the two medians is returned. To
  16951. compute the mean of both medians, use :func:`torch.quantile` with ``q=0.5`` instead.
  16952. .. warning::
  16953. This function produces deterministic (sub)gradients unlike ``median(dim=0)``
  16954. Args:
  16955. input (Tensor): the input tensor.
  16956. Example::
  16957. >>> a = torch.randn(1, 3)
  16958. >>> a
  16959. tensor([[ 1.5219, -1.5212, 0.2202]])
  16960. >>> torch.median(a)
  16961. tensor(0.2202)
  16962. .. function:: median(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  16963. :noindex:
  16964. Returns a namedtuple ``(values, indices)`` where ``values`` contains the median of each row of :attr:`input`
  16965. in the dimension :attr:`dim`, and ``indices`` contains the index of the median values found in the dimension :attr:`dim`.
  16966. By default, :attr:`dim` is the last dimension of the :attr:`input` tensor.
  16967. If :attr:`keepdim` is ``True``, the output tensors are of the same size
  16968. as :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  16969. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  16970. the outputs tensor having 1 fewer dimension than :attr:`input`.
  16971. .. note::
  16972. The median is not unique for :attr:`input` tensors with an even number
  16973. of elements in the dimension :attr:`dim`. In this case the lower of the
  16974. two medians is returned. To compute the mean of both medians in
  16975. :attr:`input`, use :func:`torch.quantile` with ``q=0.5`` instead.
  16976. .. warning::
  16977. ``indices`` does not necessarily contain the first occurrence of each
  16978. median value found, unless it is unique.
  16979. The exact implementation details are device-specific.
  16980. Do not expect the same result when run on CPU and GPU in general.
  16981. For the same reason do not expect the gradients to be deterministic.
  16982. Args:
  16983. input (Tensor): the input tensor.
  16984. dim (int, optional): the dimension to reduce.
  16985. If ``None``, all dimensions are reduced.
  16986. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16987. Keyword args:
  16988. out ((Tensor, Tensor), optional): The first tensor will be populated with the median values and the second
  16989. tensor, which must have dtype long, with their indices in the dimension
  16990. :attr:`dim` of :attr:`input`.
  16991. Example::
  16992. >>> a = torch.randn(4, 5)
  16993. >>> a
  16994. tensor([[ 0.2505, -0.3982, -0.9948, 0.3518, -1.3131],
  16995. [ 0.3180, -0.6993, 1.0436, 0.0438, 0.2270],
  16996. [-0.2751, 0.7303, 0.2192, 0.3321, 0.2488],
  16997. [ 1.0778, -1.9510, 0.7048, 0.4742, -0.7125]])
  16998. >>> torch.median(a, 1)
  16999. torch.return_types.median(values=tensor([-0.3982, 0.2270, 0.2488, 0.4742]), indices=tensor([1, 4, 4, 3]))
  17000. """
  17001. @overload
  17002. def median(
  17003. input: Tensor,
  17004. dim: str | EllipsisType | None,
  17005. keepdim: _bool = False,
  17006. *,
  17007. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  17008. ) -> torch.return_types.median:
  17009. r"""
  17010. median(input) -> Tensor
  17011. Returns the median of the values in :attr:`input`.
  17012. .. note::
  17013. The median is not unique for :attr:`input` tensors with an even number
  17014. of elements. In this case the lower of the two medians is returned. To
  17015. compute the mean of both medians, use :func:`torch.quantile` with ``q=0.5`` instead.
  17016. .. warning::
  17017. This function produces deterministic (sub)gradients unlike ``median(dim=0)``
  17018. Args:
  17019. input (Tensor): the input tensor.
  17020. Example::
  17021. >>> a = torch.randn(1, 3)
  17022. >>> a
  17023. tensor([[ 1.5219, -1.5212, 0.2202]])
  17024. >>> torch.median(a)
  17025. tensor(0.2202)
  17026. .. function:: median(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  17027. :noindex:
  17028. Returns a namedtuple ``(values, indices)`` where ``values`` contains the median of each row of :attr:`input`
  17029. in the dimension :attr:`dim`, and ``indices`` contains the index of the median values found in the dimension :attr:`dim`.
  17030. By default, :attr:`dim` is the last dimension of the :attr:`input` tensor.
  17031. If :attr:`keepdim` is ``True``, the output tensors are of the same size
  17032. as :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  17033. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  17034. the outputs tensor having 1 fewer dimension than :attr:`input`.
  17035. .. note::
  17036. The median is not unique for :attr:`input` tensors with an even number
  17037. of elements in the dimension :attr:`dim`. In this case the lower of the
  17038. two medians is returned. To compute the mean of both medians in
  17039. :attr:`input`, use :func:`torch.quantile` with ``q=0.5`` instead.
  17040. .. warning::
  17041. ``indices`` does not necessarily contain the first occurrence of each
  17042. median value found, unless it is unique.
  17043. The exact implementation details are device-specific.
  17044. Do not expect the same result when run on CPU and GPU in general.
  17045. For the same reason do not expect the gradients to be deterministic.
  17046. Args:
  17047. input (Tensor): the input tensor.
  17048. dim (int, optional): the dimension to reduce.
  17049. If ``None``, all dimensions are reduced.
  17050. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17051. Keyword args:
  17052. out ((Tensor, Tensor), optional): The first tensor will be populated with the median values and the second
  17053. tensor, which must have dtype long, with their indices in the dimension
  17054. :attr:`dim` of :attr:`input`.
  17055. Example::
  17056. >>> a = torch.randn(4, 5)
  17057. >>> a
  17058. tensor([[ 0.2505, -0.3982, -0.9948, 0.3518, -1.3131],
  17059. [ 0.3180, -0.6993, 1.0436, 0.0438, 0.2270],
  17060. [-0.2751, 0.7303, 0.2192, 0.3321, 0.2488],
  17061. [ 1.0778, -1.9510, 0.7048, 0.4742, -0.7125]])
  17062. >>> torch.median(a, 1)
  17063. torch.return_types.median(values=tensor([-0.3982, 0.2270, 0.2488, 0.4742]), indices=tensor([1, 4, 4, 3]))
  17064. """
  17065. @overload
  17066. def min(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  17067. r"""
  17068. min(input, *, out=None) -> Tensor
  17069. Returns the minimum value of all elements in the :attr:`input` tensor.
  17070. .. note::
  17071. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  17072. - ``amax``/``amin`` supports reducing on multiple dimensions,
  17073. - ``amax``/``amin`` does not return indices.
  17074. Both ``amax``/``amin`` evenly distribute gradients between equal values
  17075. when there are multiple input elements with the same minimum or maximum value.
  17076. For ``max``/``min``:
  17077. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  17078. - If reduce over one specified axis, only propagate to the indexed element.
  17079. Args:
  17080. input (Tensor): the input tensor.
  17081. Keyword args:
  17082. out (Tensor, optional): the output tensor.
  17083. Example::
  17084. >>> a = torch.randn(1, 3)
  17085. >>> a
  17086. tensor([[ 0.6750, 1.0857, 1.7197]])
  17087. >>> torch.min(a)
  17088. tensor(0.6750)
  17089. .. function:: min(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  17090. :noindex:
  17091. Returns a namedtuple ``(values, indices)`` where ``values`` is the minimum
  17092. value of each row of the :attr:`input` tensor in the given dimension
  17093. :attr:`dim`. And ``indices`` is the index location of each minimum value found
  17094. (argmin).
  17095. If :attr:`keepdim` is ``True``, the output tensors are of the same size as
  17096. :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  17097. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  17098. the output tensors having 1 fewer dimension than :attr:`input`.
  17099. .. note:: If there are multiple minimal values in a reduced row then
  17100. the indices of the first minimal value are returned.
  17101. Args:
  17102. input (Tensor): the input tensor.
  17103. dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
  17104. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17105. Keyword args:
  17106. out (tuple, optional): the tuple of two output tensors (min, min_indices)
  17107. Example::
  17108. >>> a = torch.randn(4, 4)
  17109. >>> a
  17110. tensor([[-0.6248, 1.1334, -1.1899, -0.2803],
  17111. [-1.4644, -0.2635, -0.3651, 0.6134],
  17112. [ 0.2457, 0.0384, 1.0128, 0.7015],
  17113. [-0.1153, 2.9849, 2.1458, 0.5788]])
  17114. >>> torch.min(a, 1)
  17115. torch.return_types.min(values=tensor([-1.1899, -1.4644, 0.0384, -0.1153]), indices=tensor([2, 0, 1, 0]))
  17116. .. function:: min(input, other, *, out=None) -> Tensor
  17117. :noindex:
  17118. See :func:`torch.minimum`.
  17119. """
  17120. @overload
  17121. def min(
  17122. input: Tensor,
  17123. other: Tensor,
  17124. *,
  17125. out: Tensor | None = None,
  17126. ) -> Tensor:
  17127. r"""
  17128. min(input, *, out=None) -> Tensor
  17129. Returns the minimum value of all elements in the :attr:`input` tensor.
  17130. .. note::
  17131. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  17132. - ``amax``/``amin`` supports reducing on multiple dimensions,
  17133. - ``amax``/``amin`` does not return indices.
  17134. Both ``amax``/``amin`` evenly distribute gradients between equal values
  17135. when there are multiple input elements with the same minimum or maximum value.
  17136. For ``max``/``min``:
  17137. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  17138. - If reduce over one specified axis, only propagate to the indexed element.
  17139. Args:
  17140. input (Tensor): the input tensor.
  17141. Keyword args:
  17142. out (Tensor, optional): the output tensor.
  17143. Example::
  17144. >>> a = torch.randn(1, 3)
  17145. >>> a
  17146. tensor([[ 0.6750, 1.0857, 1.7197]])
  17147. >>> torch.min(a)
  17148. tensor(0.6750)
  17149. .. function:: min(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  17150. :noindex:
  17151. Returns a namedtuple ``(values, indices)`` where ``values`` is the minimum
  17152. value of each row of the :attr:`input` tensor in the given dimension
  17153. :attr:`dim`. And ``indices`` is the index location of each minimum value found
  17154. (argmin).
  17155. If :attr:`keepdim` is ``True``, the output tensors are of the same size as
  17156. :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  17157. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  17158. the output tensors having 1 fewer dimension than :attr:`input`.
  17159. .. note:: If there are multiple minimal values in a reduced row then
  17160. the indices of the first minimal value are returned.
  17161. Args:
  17162. input (Tensor): the input tensor.
  17163. dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
  17164. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17165. Keyword args:
  17166. out (tuple, optional): the tuple of two output tensors (min, min_indices)
  17167. Example::
  17168. >>> a = torch.randn(4, 4)
  17169. >>> a
  17170. tensor([[-0.6248, 1.1334, -1.1899, -0.2803],
  17171. [-1.4644, -0.2635, -0.3651, 0.6134],
  17172. [ 0.2457, 0.0384, 1.0128, 0.7015],
  17173. [-0.1153, 2.9849, 2.1458, 0.5788]])
  17174. >>> torch.min(a, 1)
  17175. torch.return_types.min(values=tensor([-1.1899, -1.4644, 0.0384, -0.1153]), indices=tensor([2, 0, 1, 0]))
  17176. .. function:: min(input, other, *, out=None) -> Tensor
  17177. :noindex:
  17178. See :func:`torch.minimum`.
  17179. """
  17180. @overload
  17181. def min(
  17182. input: Tensor,
  17183. dim: _int,
  17184. keepdim: _bool = False,
  17185. *,
  17186. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  17187. ) -> torch.return_types.min:
  17188. r"""
  17189. min(input, *, out=None) -> Tensor
  17190. Returns the minimum value of all elements in the :attr:`input` tensor.
  17191. .. note::
  17192. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  17193. - ``amax``/``amin`` supports reducing on multiple dimensions,
  17194. - ``amax``/``amin`` does not return indices.
  17195. Both ``amax``/``amin`` evenly distribute gradients between equal values
  17196. when there are multiple input elements with the same minimum or maximum value.
  17197. For ``max``/``min``:
  17198. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  17199. - If reduce over one specified axis, only propagate to the indexed element.
  17200. Args:
  17201. input (Tensor): the input tensor.
  17202. Keyword args:
  17203. out (Tensor, optional): the output tensor.
  17204. Example::
  17205. >>> a = torch.randn(1, 3)
  17206. >>> a
  17207. tensor([[ 0.6750, 1.0857, 1.7197]])
  17208. >>> torch.min(a)
  17209. tensor(0.6750)
  17210. .. function:: min(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  17211. :noindex:
  17212. Returns a namedtuple ``(values, indices)`` where ``values`` is the minimum
  17213. value of each row of the :attr:`input` tensor in the given dimension
  17214. :attr:`dim`. And ``indices`` is the index location of each minimum value found
  17215. (argmin).
  17216. If :attr:`keepdim` is ``True``, the output tensors are of the same size as
  17217. :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  17218. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  17219. the output tensors having 1 fewer dimension than :attr:`input`.
  17220. .. note:: If there are multiple minimal values in a reduced row then
  17221. the indices of the first minimal value are returned.
  17222. Args:
  17223. input (Tensor): the input tensor.
  17224. dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
  17225. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17226. Keyword args:
  17227. out (tuple, optional): the tuple of two output tensors (min, min_indices)
  17228. Example::
  17229. >>> a = torch.randn(4, 4)
  17230. >>> a
  17231. tensor([[-0.6248, 1.1334, -1.1899, -0.2803],
  17232. [-1.4644, -0.2635, -0.3651, 0.6134],
  17233. [ 0.2457, 0.0384, 1.0128, 0.7015],
  17234. [-0.1153, 2.9849, 2.1458, 0.5788]])
  17235. >>> torch.min(a, 1)
  17236. torch.return_types.min(values=tensor([-1.1899, -1.4644, 0.0384, -0.1153]), indices=tensor([2, 0, 1, 0]))
  17237. .. function:: min(input, other, *, out=None) -> Tensor
  17238. :noindex:
  17239. See :func:`torch.minimum`.
  17240. """
  17241. @overload
  17242. def min(
  17243. input: Tensor,
  17244. dim: str | EllipsisType | None,
  17245. keepdim: _bool = False,
  17246. *,
  17247. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  17248. ) -> torch.return_types.min:
  17249. r"""
  17250. min(input, *, out=None) -> Tensor
  17251. Returns the minimum value of all elements in the :attr:`input` tensor.
  17252. .. note::
  17253. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  17254. - ``amax``/``amin`` supports reducing on multiple dimensions,
  17255. - ``amax``/``amin`` does not return indices.
  17256. Both ``amax``/``amin`` evenly distribute gradients between equal values
  17257. when there are multiple input elements with the same minimum or maximum value.
  17258. For ``max``/``min``:
  17259. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  17260. - If reduce over one specified axis, only propagate to the indexed element.
  17261. Args:
  17262. input (Tensor): the input tensor.
  17263. Keyword args:
  17264. out (Tensor, optional): the output tensor.
  17265. Example::
  17266. >>> a = torch.randn(1, 3)
  17267. >>> a
  17268. tensor([[ 0.6750, 1.0857, 1.7197]])
  17269. >>> torch.min(a)
  17270. tensor(0.6750)
  17271. .. function:: min(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  17272. :noindex:
  17273. Returns a namedtuple ``(values, indices)`` where ``values`` is the minimum
  17274. value of each row of the :attr:`input` tensor in the given dimension
  17275. :attr:`dim`. And ``indices`` is the index location of each minimum value found
  17276. (argmin).
  17277. If :attr:`keepdim` is ``True``, the output tensors are of the same size as
  17278. :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  17279. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  17280. the output tensors having 1 fewer dimension than :attr:`input`.
  17281. .. note:: If there are multiple minimal values in a reduced row then
  17282. the indices of the first minimal value are returned.
  17283. Args:
  17284. input (Tensor): the input tensor.
  17285. dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
  17286. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17287. Keyword args:
  17288. out (tuple, optional): the tuple of two output tensors (min, min_indices)
  17289. Example::
  17290. >>> a = torch.randn(4, 4)
  17291. >>> a
  17292. tensor([[-0.6248, 1.1334, -1.1899, -0.2803],
  17293. [-1.4644, -0.2635, -0.3651, 0.6134],
  17294. [ 0.2457, 0.0384, 1.0128, 0.7015],
  17295. [-0.1153, 2.9849, 2.1458, 0.5788]])
  17296. >>> torch.min(a, 1)
  17297. torch.return_types.min(values=tensor([-1.1899, -1.4644, 0.0384, -0.1153]), indices=tensor([2, 0, 1, 0]))
  17298. .. function:: min(input, other, *, out=None) -> Tensor
  17299. :noindex:
  17300. See :func:`torch.minimum`.
  17301. """
  17302. def minimum(
  17303. input: Tensor,
  17304. other: Tensor,
  17305. *,
  17306. out: Tensor | None = None,
  17307. ) -> Tensor:
  17308. r"""
  17309. minimum(input, other, *, out=None) -> Tensor
  17310. Computes the element-wise minimum of :attr:`input` and :attr:`other`.
  17311. .. note::
  17312. If one of the elements being compared is a NaN, then that element is returned.
  17313. :func:`minimum` is not supported for tensors with complex dtypes.
  17314. Args:
  17315. input (Tensor): the input tensor.
  17316. other (Tensor): the second input tensor
  17317. Keyword args:
  17318. out (Tensor, optional): the output tensor.
  17319. Example::
  17320. >>> a = torch.tensor((1, 2, -1))
  17321. >>> b = torch.tensor((3, 0, 4))
  17322. >>> torch.minimum(a, b)
  17323. tensor([1, 0, -1])
  17324. """
  17325. def miopen_batch_norm(
  17326. input: Tensor,
  17327. weight: Tensor,
  17328. bias: Tensor | None,
  17329. running_mean: Tensor | None,
  17330. running_var: Tensor | None,
  17331. training: _bool,
  17332. exponential_average_factor: _float,
  17333. epsilon: _float,
  17334. ) -> tuple[Tensor, Tensor, Tensor]: ...
  17335. def miopen_convolution(
  17336. input: Tensor,
  17337. weight: Tensor,
  17338. bias: Tensor | None,
  17339. padding: Sequence[_int | SymInt],
  17340. stride: Sequence[_int | SymInt],
  17341. dilation: Sequence[_int | SymInt],
  17342. groups: _int | SymInt,
  17343. benchmark: _bool,
  17344. deterministic: _bool,
  17345. ) -> Tensor: ...
  17346. def miopen_convolution_add_relu(
  17347. input: Tensor,
  17348. weight: Tensor,
  17349. z: Tensor,
  17350. alpha: Number | _complex | None,
  17351. bias: Tensor | None,
  17352. stride: Sequence[_int | SymInt],
  17353. padding: Sequence[_int | SymInt],
  17354. dilation: Sequence[_int | SymInt],
  17355. groups: _int | SymInt,
  17356. ) -> Tensor: ...
  17357. def miopen_convolution_relu(
  17358. input: Tensor,
  17359. weight: Tensor,
  17360. bias: Tensor | None,
  17361. stride: Sequence[_int | SymInt],
  17362. padding: Sequence[_int | SymInt],
  17363. dilation: Sequence[_int | SymInt],
  17364. groups: _int | SymInt,
  17365. ) -> Tensor: ...
  17366. def miopen_convolution_transpose(
  17367. input: Tensor,
  17368. weight: Tensor,
  17369. bias: Tensor | None,
  17370. padding: Sequence[_int | SymInt],
  17371. output_padding: Sequence[_int | SymInt],
  17372. stride: Sequence[_int | SymInt],
  17373. dilation: Sequence[_int | SymInt],
  17374. groups: _int | SymInt,
  17375. benchmark: _bool,
  17376. deterministic: _bool,
  17377. ) -> Tensor: ...
  17378. @overload
  17379. def miopen_ctc_loss(
  17380. log_probs: Tensor,
  17381. targets: Tensor,
  17382. input_lengths: _size,
  17383. target_lengths: _size,
  17384. blank: _int,
  17385. deterministic: _bool,
  17386. zero_infinity: _bool,
  17387. ) -> tuple[Tensor, Tensor]: ...
  17388. @overload
  17389. def miopen_ctc_loss(
  17390. log_probs: Tensor,
  17391. targets: Tensor,
  17392. input_lengths: Tensor,
  17393. target_lengths: Tensor,
  17394. blank: _int,
  17395. deterministic: _bool,
  17396. zero_infinity: _bool,
  17397. ) -> tuple[Tensor, Tensor]: ...
  17398. def miopen_depthwise_convolution(
  17399. input: Tensor,
  17400. weight: Tensor,
  17401. bias: Tensor | None,
  17402. padding: Sequence[_int | SymInt],
  17403. stride: Sequence[_int | SymInt],
  17404. dilation: Sequence[_int | SymInt],
  17405. groups: _int | SymInt,
  17406. benchmark: _bool,
  17407. deterministic: _bool,
  17408. ) -> Tensor: ...
  17409. def miopen_rnn(
  17410. input: Tensor,
  17411. weight: tuple[Tensor, ...] | list[Tensor] | None,
  17412. weight_stride0: _int,
  17413. hx: Tensor,
  17414. cx: Tensor | None,
  17415. mode: _int,
  17416. hidden_size: _int,
  17417. num_layers: _int,
  17418. batch_first: _bool,
  17419. dropout: _float,
  17420. train: _bool,
  17421. bidirectional: _bool,
  17422. batch_sizes: _size,
  17423. dropout_state: Tensor | None,
  17424. ) -> tuple[Tensor, Tensor, Tensor, Tensor, Tensor]: ...
  17425. def mkldnn_adaptive_avg_pool2d(
  17426. input: Tensor,
  17427. output_size: _int | _size,
  17428. *,
  17429. out: Tensor | None = None,
  17430. ) -> Tensor: ...
  17431. def mkldnn_convolution(
  17432. input: Tensor,
  17433. weight: Tensor,
  17434. bias: Tensor | None,
  17435. padding: Sequence[_int | SymInt],
  17436. stride: Sequence[_int | SymInt],
  17437. dilation: Sequence[_int | SymInt],
  17438. groups: _int | SymInt,
  17439. ) -> Tensor: ...
  17440. def mkldnn_linear_backward_weights(
  17441. grad_output: Tensor,
  17442. input: Tensor,
  17443. weight: Tensor,
  17444. bias_defined: _bool,
  17445. ) -> tuple[Tensor, Tensor]: ...
  17446. def mkldnn_max_pool2d(
  17447. input: Tensor,
  17448. kernel_size: _int | _size,
  17449. stride: _int | _size = (),
  17450. padding: _int | _size = 0,
  17451. dilation: _int | _size = 1,
  17452. ceil_mode: _bool = False,
  17453. ) -> Tensor: ...
  17454. def mkldnn_max_pool3d(
  17455. input: Tensor,
  17456. kernel_size: _int | _size,
  17457. stride: _int | _size = (),
  17458. padding: _int | _size = 0,
  17459. dilation: _int | _size = 1,
  17460. ceil_mode: _bool = False,
  17461. ) -> Tensor: ...
  17462. def mkldnn_rnn_layer(
  17463. input: Tensor,
  17464. weight0: Tensor,
  17465. weight1: Tensor,
  17466. weight2: Tensor,
  17467. weight3: Tensor,
  17468. hx_: Tensor,
  17469. cx_: Tensor,
  17470. reverse: _bool,
  17471. batch_sizes: _size,
  17472. mode: _int,
  17473. hidden_size: _int,
  17474. num_layers: _int,
  17475. has_biases: _bool,
  17476. bidirectional: _bool,
  17477. batch_first: _bool,
  17478. train: _bool,
  17479. ) -> tuple[Tensor, Tensor, Tensor, Tensor]: ...
  17480. @overload
  17481. def mm(input: Tensor, mat2: Tensor, *, out: Tensor | None = None) -> Tensor:
  17482. r"""
  17483. mm(input, mat2, out_dtype=None, *, out=None) -> Tensor
  17484. Performs a matrix multiplication of the matrices :attr:`input` and :attr:`mat2`.
  17485. If :attr:`input` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
  17486. :math:`(m \times p)` tensor, :attr:`out` will be a :math:`(n \times p)` tensor.
  17487. .. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
  17488. For broadcasting matrix products, see :func:`torch.matmul`.
  17489. Supports strided and sparse 2-D tensors as inputs, autograd with
  17490. respect to strided inputs.
  17491. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`.
  17492. If :attr:`out` is provided its layout will be used. Otherwise, the result
  17493. layout will be deduced from that of :attr:`input`.
  17494. .. warning::
  17495. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  17496. or may not have autograd support. If you notice missing functionality please
  17497. open a feature request.
  17498. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  17499. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  17500. Args:
  17501. input (Tensor): the first matrix to be matrix multiplied
  17502. mat2 (Tensor): the second matrix to be matrix multiplied
  17503. out_dtype (dtype, optional): the dtype of the output tensor,
  17504. Supported only on CUDA and for torch.float32 given
  17505. torch.float16/torch.bfloat16 input dtypes
  17506. Keyword args:
  17507. out (Tensor, optional): the output tensor.
  17508. Example::
  17509. >>> mat1 = torch.randn(2, 3)
  17510. >>> mat2 = torch.randn(3, 3)
  17511. >>> torch.mm(mat1, mat2)
  17512. tensor([[ 0.4851, 0.5037, -0.3633],
  17513. [-0.0760, -3.6705, 2.4784]])
  17514. """
  17515. @overload
  17516. def mm(
  17517. input: Tensor,
  17518. mat2: Tensor,
  17519. out_dtype: _dtype,
  17520. *,
  17521. out: Tensor | None = None,
  17522. ) -> Tensor:
  17523. r"""
  17524. mm(input, mat2, out_dtype=None, *, out=None) -> Tensor
  17525. Performs a matrix multiplication of the matrices :attr:`input` and :attr:`mat2`.
  17526. If :attr:`input` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
  17527. :math:`(m \times p)` tensor, :attr:`out` will be a :math:`(n \times p)` tensor.
  17528. .. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
  17529. For broadcasting matrix products, see :func:`torch.matmul`.
  17530. Supports strided and sparse 2-D tensors as inputs, autograd with
  17531. respect to strided inputs.
  17532. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`.
  17533. If :attr:`out` is provided its layout will be used. Otherwise, the result
  17534. layout will be deduced from that of :attr:`input`.
  17535. .. warning::
  17536. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  17537. or may not have autograd support. If you notice missing functionality please
  17538. open a feature request.
  17539. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  17540. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  17541. Args:
  17542. input (Tensor): the first matrix to be matrix multiplied
  17543. mat2 (Tensor): the second matrix to be matrix multiplied
  17544. out_dtype (dtype, optional): the dtype of the output tensor,
  17545. Supported only on CUDA and for torch.float32 given
  17546. torch.float16/torch.bfloat16 input dtypes
  17547. Keyword args:
  17548. out (Tensor, optional): the output tensor.
  17549. Example::
  17550. >>> mat1 = torch.randn(2, 3)
  17551. >>> mat2 = torch.randn(3, 3)
  17552. >>> torch.mm(mat1, mat2)
  17553. tensor([[ 0.4851, 0.5037, -0.3633],
  17554. [-0.0760, -3.6705, 2.4784]])
  17555. """
  17556. @overload
  17557. def mode(
  17558. input: Tensor,
  17559. dim: _int = -1,
  17560. keepdim: _bool = False,
  17561. *,
  17562. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  17563. ) -> torch.return_types.mode:
  17564. r"""
  17565. mode(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  17566. Returns a namedtuple ``(values, indices)`` where ``values`` is the mode
  17567. value of each row of the :attr:`input` tensor in the given dimension
  17568. :attr:`dim`, i.e. a value which appears most often
  17569. in that row, and ``indices`` is the index location of each mode value found.
  17570. By default, :attr:`dim` is the last dimension of the :attr:`input` tensor.
  17571. If :attr:`keepdim` is ``True``, the output tensors are of the same size as
  17572. :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  17573. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting
  17574. in the output tensors having 1 fewer dimension than :attr:`input`.
  17575. Args:
  17576. input (Tensor): the input tensor.
  17577. dim (int, optional): the dimension to reduce.
  17578. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17579. Keyword args:
  17580. out (tuple, optional): the result tuple of two output tensors (values, indices)
  17581. Example::
  17582. >>> b = torch.tensor([[0, 0, 0, 2, 0, 0, 2],
  17583. ... [0, 3, 0, 0, 2, 0, 1],
  17584. ... [2, 2, 2, 0, 0, 0, 3],
  17585. ... [2, 2, 3, 0, 1, 1, 0],
  17586. ... [1, 1, 0, 0, 2, 0, 2]])
  17587. >>> torch.mode(b, 0)
  17588. torch.return_types.mode(
  17589. values=tensor([0, 2, 0, 0, 0, 0, 2]),
  17590. indices=tensor([1, 3, 4, 4, 2, 4, 4]))
  17591. """
  17592. @overload
  17593. def mode(
  17594. input: Tensor,
  17595. dim: str | EllipsisType | None,
  17596. keepdim: _bool = False,
  17597. *,
  17598. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  17599. ) -> torch.return_types.mode:
  17600. r"""
  17601. mode(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  17602. Returns a namedtuple ``(values, indices)`` where ``values`` is the mode
  17603. value of each row of the :attr:`input` tensor in the given dimension
  17604. :attr:`dim`, i.e. a value which appears most often
  17605. in that row, and ``indices`` is the index location of each mode value found.
  17606. By default, :attr:`dim` is the last dimension of the :attr:`input` tensor.
  17607. If :attr:`keepdim` is ``True``, the output tensors are of the same size as
  17608. :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  17609. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting
  17610. in the output tensors having 1 fewer dimension than :attr:`input`.
  17611. Args:
  17612. input (Tensor): the input tensor.
  17613. dim (int, optional): the dimension to reduce.
  17614. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17615. Keyword args:
  17616. out (tuple, optional): the result tuple of two output tensors (values, indices)
  17617. Example::
  17618. >>> b = torch.tensor([[0, 0, 0, 2, 0, 0, 2],
  17619. ... [0, 3, 0, 0, 2, 0, 1],
  17620. ... [2, 2, 2, 0, 0, 0, 3],
  17621. ... [2, 2, 3, 0, 1, 1, 0],
  17622. ... [1, 1, 0, 0, 2, 0, 2]])
  17623. >>> torch.mode(b, 0)
  17624. torch.return_types.mode(
  17625. values=tensor([0, 2, 0, 0, 0, 0, 2]),
  17626. indices=tensor([1, 3, 4, 4, 2, 4, 4]))
  17627. """
  17628. @overload
  17629. def moveaxis(input: Tensor, source: _int, destination: _int) -> Tensor:
  17630. r"""
  17631. moveaxis(input, source, destination) -> Tensor
  17632. Alias for :func:`torch.movedim`.
  17633. This function is equivalent to NumPy's moveaxis function.
  17634. Examples::
  17635. >>> t = torch.randn(3,2,1)
  17636. >>> t
  17637. tensor([[[-0.3362],
  17638. [-0.8437]],
  17639. [[-0.9627],
  17640. [ 0.1727]],
  17641. [[ 0.5173],
  17642. [-0.1398]]])
  17643. >>> torch.moveaxis(t, 1, 0).shape
  17644. torch.Size([2, 3, 1])
  17645. >>> torch.moveaxis(t, 1, 0)
  17646. tensor([[[-0.3362],
  17647. [-0.9627],
  17648. [ 0.5173]],
  17649. [[-0.8437],
  17650. [ 0.1727],
  17651. [-0.1398]]])
  17652. >>> torch.moveaxis(t, (1, 2), (0, 1)).shape
  17653. torch.Size([2, 1, 3])
  17654. >>> torch.moveaxis(t, (1, 2), (0, 1))
  17655. tensor([[[-0.3362, -0.9627, 0.5173]],
  17656. [[-0.8437, 0.1727, -0.1398]]])
  17657. """
  17658. @overload
  17659. def moveaxis(input: Tensor, source: _size, destination: _size) -> Tensor:
  17660. r"""
  17661. moveaxis(input, source, destination) -> Tensor
  17662. Alias for :func:`torch.movedim`.
  17663. This function is equivalent to NumPy's moveaxis function.
  17664. Examples::
  17665. >>> t = torch.randn(3,2,1)
  17666. >>> t
  17667. tensor([[[-0.3362],
  17668. [-0.8437]],
  17669. [[-0.9627],
  17670. [ 0.1727]],
  17671. [[ 0.5173],
  17672. [-0.1398]]])
  17673. >>> torch.moveaxis(t, 1, 0).shape
  17674. torch.Size([2, 3, 1])
  17675. >>> torch.moveaxis(t, 1, 0)
  17676. tensor([[[-0.3362],
  17677. [-0.9627],
  17678. [ 0.5173]],
  17679. [[-0.8437],
  17680. [ 0.1727],
  17681. [-0.1398]]])
  17682. >>> torch.moveaxis(t, (1, 2), (0, 1)).shape
  17683. torch.Size([2, 1, 3])
  17684. >>> torch.moveaxis(t, (1, 2), (0, 1))
  17685. tensor([[[-0.3362, -0.9627, 0.5173]],
  17686. [[-0.8437, 0.1727, -0.1398]]])
  17687. """
  17688. @overload
  17689. def movedim(input: Tensor, source: _int, destination: _int) -> Tensor:
  17690. r"""
  17691. movedim(input, source, destination) -> Tensor
  17692. Moves the dimension(s) of :attr:`input` at the position(s) in :attr:`source`
  17693. to the position(s) in :attr:`destination`.
  17694. Other dimensions of :attr:`input` that are not explicitly moved remain in
  17695. their original order and appear at the positions not specified in :attr:`destination`.
  17696. Args:
  17697. input (Tensor): the input tensor.
  17698. source (int or tuple of ints): Original positions of the dims to move. These must be unique.
  17699. destination (int or tuple of ints): Destination positions for each of the original dims. These must also be unique.
  17700. Examples::
  17701. >>> t = torch.randn(3,2,1)
  17702. >>> t
  17703. tensor([[[-0.3362],
  17704. [-0.8437]],
  17705. [[-0.9627],
  17706. [ 0.1727]],
  17707. [[ 0.5173],
  17708. [-0.1398]]])
  17709. >>> torch.movedim(t, 1, 0).shape
  17710. torch.Size([2, 3, 1])
  17711. >>> torch.movedim(t, 1, 0)
  17712. tensor([[[-0.3362],
  17713. [-0.9627],
  17714. [ 0.5173]],
  17715. [[-0.8437],
  17716. [ 0.1727],
  17717. [-0.1398]]])
  17718. >>> torch.movedim(t, (1, 2), (0, 1)).shape
  17719. torch.Size([2, 1, 3])
  17720. >>> torch.movedim(t, (1, 2), (0, 1))
  17721. tensor([[[-0.3362, -0.9627, 0.5173]],
  17722. [[-0.8437, 0.1727, -0.1398]]])
  17723. """
  17724. @overload
  17725. def movedim(input: Tensor, source: _size, destination: _size) -> Tensor:
  17726. r"""
  17727. movedim(input, source, destination) -> Tensor
  17728. Moves the dimension(s) of :attr:`input` at the position(s) in :attr:`source`
  17729. to the position(s) in :attr:`destination`.
  17730. Other dimensions of :attr:`input` that are not explicitly moved remain in
  17731. their original order and appear at the positions not specified in :attr:`destination`.
  17732. Args:
  17733. input (Tensor): the input tensor.
  17734. source (int or tuple of ints): Original positions of the dims to move. These must be unique.
  17735. destination (int or tuple of ints): Destination positions for each of the original dims. These must also be unique.
  17736. Examples::
  17737. >>> t = torch.randn(3,2,1)
  17738. >>> t
  17739. tensor([[[-0.3362],
  17740. [-0.8437]],
  17741. [[-0.9627],
  17742. [ 0.1727]],
  17743. [[ 0.5173],
  17744. [-0.1398]]])
  17745. >>> torch.movedim(t, 1, 0).shape
  17746. torch.Size([2, 3, 1])
  17747. >>> torch.movedim(t, 1, 0)
  17748. tensor([[[-0.3362],
  17749. [-0.9627],
  17750. [ 0.5173]],
  17751. [[-0.8437],
  17752. [ 0.1727],
  17753. [-0.1398]]])
  17754. >>> torch.movedim(t, (1, 2), (0, 1)).shape
  17755. torch.Size([2, 1, 3])
  17756. >>> torch.movedim(t, (1, 2), (0, 1))
  17757. tensor([[[-0.3362, -0.9627, 0.5173]],
  17758. [[-0.8437, 0.1727, -0.1398]]])
  17759. """
  17760. def msort(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  17761. r"""
  17762. msort(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  17763. Sorts the elements of the :attr:`input` tensor along its first dimension
  17764. in ascending order by value.
  17765. .. note:: `torch.msort(t)` is equivalent to `torch.sort(t, dim=0)[0]`.
  17766. See also :func:`torch.sort`.
  17767. Args:
  17768. input (Tensor): the input tensor.
  17769. Keyword args:
  17770. out (Tensor, optional): the output tensor.
  17771. Example::
  17772. >>> t = torch.randn(3, 4)
  17773. >>> t
  17774. tensor([[-0.1321, 0.4370, -1.2631, -1.1289],
  17775. [-2.0527, -1.1250, 0.2275, 0.3077],
  17776. [-0.0881, -0.1259, -0.5495, 1.0284]])
  17777. >>> torch.msort(t)
  17778. tensor([[-2.0527, -1.1250, -1.2631, -1.1289],
  17779. [-0.1321, -0.1259, -0.5495, 0.3077],
  17780. [-0.0881, 0.4370, 0.2275, 1.0284]])
  17781. """
  17782. def mul(
  17783. input: Tensor | Number | _complex,
  17784. other: Tensor | Number | _complex,
  17785. *,
  17786. out: Tensor | None = None,
  17787. ) -> Tensor:
  17788. r"""
  17789. mul(input, other, *, out=None) -> Tensor
  17790. Multiplies :attr:`input` by :attr:`other`.
  17791. .. math::
  17792. \text{out}_i = \text{input}_i \times \text{other}_i
  17793. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  17794. :ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
  17795. Args:
  17796. input (Tensor): the input tensor.
  17797. other (Tensor or Number): the tensor or number to multiply input by.
  17798. Keyword args:
  17799. out (Tensor, optional): the output tensor.
  17800. Examples::
  17801. >>> a = torch.randn(3)
  17802. >>> a
  17803. tensor([ 0.2015, -0.4255, 2.6087])
  17804. >>> torch.mul(a, 100)
  17805. tensor([ 20.1494, -42.5491, 260.8663])
  17806. >>> b = torch.randn(4, 1)
  17807. >>> b
  17808. tensor([[ 1.1207],
  17809. [-0.3137],
  17810. [ 0.0700],
  17811. [ 0.8378]])
  17812. >>> c = torch.randn(1, 4)
  17813. >>> c
  17814. tensor([[ 0.5146, 0.1216, -0.5244, 2.2382]])
  17815. >>> torch.mul(b, c)
  17816. tensor([[ 0.5767, 0.1363, -0.5877, 2.5083],
  17817. [-0.1614, -0.0382, 0.1645, -0.7021],
  17818. [ 0.0360, 0.0085, -0.0367, 0.1567],
  17819. [ 0.4312, 0.1019, -0.4394, 1.8753]])
  17820. """
  17821. def multinomial(
  17822. input: Tensor,
  17823. num_samples: _int | SymInt,
  17824. replacement: _bool = False,
  17825. *,
  17826. generator: Generator | None = None,
  17827. out: Tensor | None = None,
  17828. ) -> Tensor:
  17829. r"""
  17830. multinomial(input, num_samples, replacement=False, *, generator=None, out=None) -> LongTensor
  17831. Returns a tensor where each row contains :attr:`num_samples` indices sampled
  17832. from the multinomial (a stricter definition would be multivariate,
  17833. refer to :class:`torch.distributions.multinomial.Multinomial` for more details)
  17834. probability distribution located in the corresponding row
  17835. of tensor :attr:`input`.
  17836. .. note::
  17837. The rows of :attr:`input` do not need to sum to one (in which case we use
  17838. the values as weights), but must be non-negative, finite and have
  17839. a non-zero sum.
  17840. Indices are ordered from left to right according to when each was sampled
  17841. (first samples are placed in first column).
  17842. If :attr:`input` is a vector, :attr:`out` is a vector of size :attr:`num_samples`.
  17843. If :attr:`input` is a matrix with `m` rows, :attr:`out` is an matrix of shape
  17844. :math:`(m \times \text{num\_samples})`.
  17845. If replacement is ``True``, samples are drawn with replacement.
  17846. If not, they are drawn without replacement, which means that when a
  17847. sample index is drawn for a row, it cannot be drawn again for that row.
  17848. .. note::
  17849. When drawn without replacement, :attr:`num_samples` must be lower than
  17850. number of non-zero elements in :attr:`input` (or the min number of non-zero
  17851. elements in each row of :attr:`input` if it is a matrix).
  17852. Args:
  17853. input (Tensor): the input tensor containing probabilities
  17854. num_samples (int): number of samples to draw
  17855. replacement (bool, optional): whether to draw with replacement or not
  17856. Keyword args:
  17857. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  17858. out (Tensor, optional): the output tensor.
  17859. Example::
  17860. >>> weights = torch.tensor([0, 10, 3, 0], dtype=torch.float) # create a tensor of weights
  17861. >>> torch.multinomial(weights, 2)
  17862. tensor([1, 2])
  17863. >>> torch.multinomial(weights, 5) # ERROR!
  17864. RuntimeError: cannot sample n_sample > prob_dist.size(-1) samples without replacement
  17865. >>> torch.multinomial(weights, 4, replacement=True)
  17866. tensor([ 2, 1, 1, 1])
  17867. """
  17868. @overload
  17869. def multiply(
  17870. input: Tensor,
  17871. other: Tensor,
  17872. *,
  17873. out: Tensor | None = None,
  17874. ) -> Tensor:
  17875. r"""
  17876. multiply(input, other, *, out=None)
  17877. Alias for :func:`torch.mul`.
  17878. """
  17879. @overload
  17880. def multiply(input: Tensor, other: Number | _complex) -> Tensor:
  17881. r"""
  17882. multiply(input, other, *, out=None)
  17883. Alias for :func:`torch.mul`.
  17884. """
  17885. def mv(input: Tensor, vec: Tensor, *, out: Tensor | None = None) -> Tensor:
  17886. r"""
  17887. mv(input, vec, *, out=None) -> Tensor
  17888. Performs a matrix-vector product of the matrix :attr:`input` and the vector
  17889. :attr:`vec`.
  17890. If :attr:`input` is a :math:`(n \times m)` tensor, :attr:`vec` is a 1-D tensor of
  17891. size :math:`m`, :attr:`out` will be 1-D of size :math:`n`.
  17892. .. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
  17893. Args:
  17894. input (Tensor): matrix to be multiplied
  17895. vec (Tensor): vector to be multiplied
  17896. Keyword args:
  17897. out (Tensor, optional): the output tensor.
  17898. Example::
  17899. >>> mat = torch.randn(2, 3)
  17900. >>> vec = torch.randn(3)
  17901. >>> torch.mv(mat, vec)
  17902. tensor([ 1.0404, -0.6361])
  17903. """
  17904. def mvlgamma(
  17905. input: Tensor,
  17906. p: _int,
  17907. *,
  17908. out: Tensor | None = None,
  17909. ) -> Tensor:
  17910. r"""
  17911. mvlgamma(input, p, *, out=None) -> Tensor
  17912. Alias for :func:`torch.special.multigammaln`.
  17913. """
  17914. def nan_to_num(
  17915. input: Tensor,
  17916. nan: _float | None = None,
  17917. posinf: _float | None = None,
  17918. neginf: _float | None = None,
  17919. *,
  17920. out: Tensor | None = None,
  17921. ) -> Tensor:
  17922. r"""
  17923. nan_to_num(input, nan=0.0, posinf=None, neginf=None, *, out=None) -> Tensor
  17924. Replaces :literal:`NaN`, positive infinity, and negative infinity values in :attr:`input`
  17925. with the values specified by :attr:`nan`, :attr:`posinf`, and :attr:`neginf`, respectively.
  17926. By default, :literal:`NaN`\ s are replaced with zero, positive infinity is replaced with the
  17927. greatest finite value representable by :attr:`input`'s dtype, and negative infinity
  17928. is replaced with the least finite value representable by :attr:`input`'s dtype.
  17929. Args:
  17930. input (Tensor): the input tensor.
  17931. nan (Number, optional): the value to replace :literal:`NaN`\s with. Default is zero.
  17932. posinf (Number, optional): if a Number, the value to replace positive infinity values with.
  17933. If None, positive infinity values are replaced with the greatest finite value representable by :attr:`input`'s dtype.
  17934. Default is None.
  17935. neginf (Number, optional): if a Number, the value to replace negative infinity values with.
  17936. If None, negative infinity values are replaced with the lowest finite value representable by :attr:`input`'s dtype.
  17937. Default is None.
  17938. Keyword args:
  17939. out (Tensor, optional): the output tensor.
  17940. Example::
  17941. >>> x = torch.tensor([float('nan'), float('inf'), -float('inf'), 3.14])
  17942. >>> torch.nan_to_num(x)
  17943. tensor([ 0.0000e+00, 3.4028e+38, -3.4028e+38, 3.1400e+00])
  17944. >>> torch.nan_to_num(x, nan=2.0)
  17945. tensor([ 2.0000e+00, 3.4028e+38, -3.4028e+38, 3.1400e+00])
  17946. >>> torch.nan_to_num(x, nan=2.0, posinf=1.0)
  17947. tensor([ 2.0000e+00, 1.0000e+00, -3.4028e+38, 3.1400e+00])
  17948. """
  17949. def nan_to_num_(
  17950. input: Tensor,
  17951. nan: _float | None = None,
  17952. posinf: _float | None = None,
  17953. neginf: _float | None = None,
  17954. ) -> Tensor: ...
  17955. def nanmean(
  17956. input: Tensor,
  17957. dim: _int | _size | None = None,
  17958. keepdim: _bool = False,
  17959. *,
  17960. dtype: _dtype | None = None,
  17961. out: Tensor | None = None,
  17962. ) -> Tensor:
  17963. r"""
  17964. nanmean(input, dim=None, keepdim=False, *, dtype=None, out=None) -> Tensor
  17965. Computes the mean of all `non-NaN` elements along the specified dimensions.
  17966. Input must be floating point or complex.
  17967. This function is identical to :func:`torch.mean` when there are no `NaN` values
  17968. in the :attr:`input` tensor. In the presence of `NaN`, :func:`torch.mean` will
  17969. propagate the `NaN` to the output whereas :func:`torch.nanmean` will ignore the
  17970. `NaN` values (`torch.nanmean(a)` is equivalent to `torch.mean(a[~a.isnan()])`).
  17971. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  17972. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  17973. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  17974. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  17975. Args:
  17976. input (Tensor): the input tensor, either of floating point or complex dtype
  17977. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  17978. If ``None``, all dimensions are reduced.
  17979. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17980. Keyword args:
  17981. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  17982. If specified, the input tensor is casted to :attr:`dtype` before the operation
  17983. is performed. This is useful for preventing data type overflows. Default: None.
  17984. out (Tensor, optional): the output tensor.
  17985. .. seealso::
  17986. :func:`torch.mean` computes the mean value, propagating `NaN`.
  17987. Example::
  17988. >>> x = torch.tensor([[torch.nan, 1, 2], [1, 2, 3]])
  17989. >>> x.mean()
  17990. tensor(nan)
  17991. >>> x.nanmean()
  17992. tensor(1.8000)
  17993. >>> x.mean(dim=0)
  17994. tensor([ nan, 1.5000, 2.5000])
  17995. >>> x.nanmean(dim=0)
  17996. tensor([1.0000, 1.5000, 2.5000])
  17997. # If all elements in the reduced dimensions are NaN then the result is NaN
  17998. >>> torch.tensor([torch.nan]).nanmean()
  17999. tensor(nan)
  18000. """
  18001. @overload
  18002. def nanmedian(input: Tensor) -> Tensor:
  18003. r"""
  18004. nanmedian(input) -> Tensor
  18005. Returns the median of the values in :attr:`input`, ignoring ``NaN`` values.
  18006. This function is identical to :func:`torch.median` when there are no ``NaN`` values in :attr:`input`.
  18007. When :attr:`input` has one or more ``NaN`` values, :func:`torch.median` will always return ``NaN``,
  18008. while this function will return the median of the non-``NaN`` elements in :attr:`input`.
  18009. If all the elements in :attr:`input` are ``NaN`` it will also return ``NaN``.
  18010. Args:
  18011. input (Tensor): the input tensor.
  18012. Example::
  18013. >>> a = torch.tensor([1, float('nan'), 3, 2])
  18014. >>> a.median()
  18015. tensor(nan)
  18016. >>> a.nanmedian()
  18017. tensor(2.)
  18018. .. function:: nanmedian(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  18019. :noindex:
  18020. Returns a namedtuple ``(values, indices)`` where ``values`` contains the median of each row of :attr:`input`
  18021. in the dimension :attr:`dim`, ignoring ``NaN`` values, and ``indices`` contains the index of the median values
  18022. found in the dimension :attr:`dim`.
  18023. This function is identical to :func:`torch.median` when there are no ``NaN`` values in a reduced row. When a reduced row has
  18024. one or more ``NaN`` values, :func:`torch.median` will always reduce it to ``NaN``, while this function will reduce it to the
  18025. median of the non-``NaN`` elements. If all the elements in a reduced row are ``NaN`` then it will be reduced to ``NaN``, too.
  18026. Args:
  18027. input (Tensor): the input tensor.
  18028. dim (int, optional): the dimension to reduce.
  18029. If ``None``, all dimensions are reduced.
  18030. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  18031. Keyword args:
  18032. out ((Tensor, Tensor), optional): The first tensor will be populated with the median values and the second
  18033. tensor, which must have dtype long, with their indices in the dimension
  18034. :attr:`dim` of :attr:`input`.
  18035. Example::
  18036. >>> a = torch.tensor([[2, 3, 1], [float('nan'), 1, float('nan')]])
  18037. >>> a
  18038. tensor([[2., 3., 1.],
  18039. [nan, 1., nan]])
  18040. >>> a.median(0)
  18041. torch.return_types.median(values=tensor([nan, 1., nan]), indices=tensor([1, 1, 1]))
  18042. >>> a.nanmedian(0)
  18043. torch.return_types.nanmedian(values=tensor([2., 1., 1.]), indices=tensor([0, 1, 0]))
  18044. """
  18045. @overload
  18046. def nanmedian(
  18047. input: Tensor,
  18048. dim: _int,
  18049. keepdim: _bool = False,
  18050. *,
  18051. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  18052. ) -> torch.return_types.nanmedian:
  18053. r"""
  18054. nanmedian(input) -> Tensor
  18055. Returns the median of the values in :attr:`input`, ignoring ``NaN`` values.
  18056. This function is identical to :func:`torch.median` when there are no ``NaN`` values in :attr:`input`.
  18057. When :attr:`input` has one or more ``NaN`` values, :func:`torch.median` will always return ``NaN``,
  18058. while this function will return the median of the non-``NaN`` elements in :attr:`input`.
  18059. If all the elements in :attr:`input` are ``NaN`` it will also return ``NaN``.
  18060. Args:
  18061. input (Tensor): the input tensor.
  18062. Example::
  18063. >>> a = torch.tensor([1, float('nan'), 3, 2])
  18064. >>> a.median()
  18065. tensor(nan)
  18066. >>> a.nanmedian()
  18067. tensor(2.)
  18068. .. function:: nanmedian(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  18069. :noindex:
  18070. Returns a namedtuple ``(values, indices)`` where ``values`` contains the median of each row of :attr:`input`
  18071. in the dimension :attr:`dim`, ignoring ``NaN`` values, and ``indices`` contains the index of the median values
  18072. found in the dimension :attr:`dim`.
  18073. This function is identical to :func:`torch.median` when there are no ``NaN`` values in a reduced row. When a reduced row has
  18074. one or more ``NaN`` values, :func:`torch.median` will always reduce it to ``NaN``, while this function will reduce it to the
  18075. median of the non-``NaN`` elements. If all the elements in a reduced row are ``NaN`` then it will be reduced to ``NaN``, too.
  18076. Args:
  18077. input (Tensor): the input tensor.
  18078. dim (int, optional): the dimension to reduce.
  18079. If ``None``, all dimensions are reduced.
  18080. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  18081. Keyword args:
  18082. out ((Tensor, Tensor), optional): The first tensor will be populated with the median values and the second
  18083. tensor, which must have dtype long, with their indices in the dimension
  18084. :attr:`dim` of :attr:`input`.
  18085. Example::
  18086. >>> a = torch.tensor([[2, 3, 1], [float('nan'), 1, float('nan')]])
  18087. >>> a
  18088. tensor([[2., 3., 1.],
  18089. [nan, 1., nan]])
  18090. >>> a.median(0)
  18091. torch.return_types.median(values=tensor([nan, 1., nan]), indices=tensor([1, 1, 1]))
  18092. >>> a.nanmedian(0)
  18093. torch.return_types.nanmedian(values=tensor([2., 1., 1.]), indices=tensor([0, 1, 0]))
  18094. """
  18095. @overload
  18096. def nanmedian(
  18097. input: Tensor,
  18098. dim: str | EllipsisType | None,
  18099. keepdim: _bool = False,
  18100. *,
  18101. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  18102. ) -> torch.return_types.nanmedian:
  18103. r"""
  18104. nanmedian(input) -> Tensor
  18105. Returns the median of the values in :attr:`input`, ignoring ``NaN`` values.
  18106. This function is identical to :func:`torch.median` when there are no ``NaN`` values in :attr:`input`.
  18107. When :attr:`input` has one or more ``NaN`` values, :func:`torch.median` will always return ``NaN``,
  18108. while this function will return the median of the non-``NaN`` elements in :attr:`input`.
  18109. If all the elements in :attr:`input` are ``NaN`` it will also return ``NaN``.
  18110. Args:
  18111. input (Tensor): the input tensor.
  18112. Example::
  18113. >>> a = torch.tensor([1, float('nan'), 3, 2])
  18114. >>> a.median()
  18115. tensor(nan)
  18116. >>> a.nanmedian()
  18117. tensor(2.)
  18118. .. function:: nanmedian(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  18119. :noindex:
  18120. Returns a namedtuple ``(values, indices)`` where ``values`` contains the median of each row of :attr:`input`
  18121. in the dimension :attr:`dim`, ignoring ``NaN`` values, and ``indices`` contains the index of the median values
  18122. found in the dimension :attr:`dim`.
  18123. This function is identical to :func:`torch.median` when there are no ``NaN`` values in a reduced row. When a reduced row has
  18124. one or more ``NaN`` values, :func:`torch.median` will always reduce it to ``NaN``, while this function will reduce it to the
  18125. median of the non-``NaN`` elements. If all the elements in a reduced row are ``NaN`` then it will be reduced to ``NaN``, too.
  18126. Args:
  18127. input (Tensor): the input tensor.
  18128. dim (int, optional): the dimension to reduce.
  18129. If ``None``, all dimensions are reduced.
  18130. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  18131. Keyword args:
  18132. out ((Tensor, Tensor), optional): The first tensor will be populated with the median values and the second
  18133. tensor, which must have dtype long, with their indices in the dimension
  18134. :attr:`dim` of :attr:`input`.
  18135. Example::
  18136. >>> a = torch.tensor([[2, 3, 1], [float('nan'), 1, float('nan')]])
  18137. >>> a
  18138. tensor([[2., 3., 1.],
  18139. [nan, 1., nan]])
  18140. >>> a.median(0)
  18141. torch.return_types.median(values=tensor([nan, 1., nan]), indices=tensor([1, 1, 1]))
  18142. >>> a.nanmedian(0)
  18143. torch.return_types.nanmedian(values=tensor([2., 1., 1.]), indices=tensor([0, 1, 0]))
  18144. """
  18145. @overload
  18146. def nanquantile(
  18147. input: Tensor,
  18148. q: Tensor,
  18149. dim: _int | None = None,
  18150. keepdim: _bool = False,
  18151. *,
  18152. interpolation: str = "linear",
  18153. out: Tensor | None = None,
  18154. ) -> Tensor:
  18155. r"""
  18156. nanquantile(input, q, dim=None, keepdim=False, *, interpolation='linear', out=None) -> Tensor
  18157. This is a variant of :func:`torch.quantile` that "ignores" ``NaN`` values,
  18158. computing the quantiles :attr:`q` as if ``NaN`` values in :attr:`input` did
  18159. not exist. If all values in a reduced row are ``NaN`` then the quantiles for
  18160. that reduction will be ``NaN``. See the documentation for :func:`torch.quantile`.
  18161. Args:
  18162. input (Tensor): the input tensor.
  18163. q (float or Tensor): a scalar or 1D tensor of quantile values in the range [0, 1]
  18164. dim (int, optional): the dimension to reduce.
  18165. If ``None``, all dimensions are reduced.
  18166. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  18167. Keyword arguments:
  18168. interpolation (str): interpolation method to use when the desired quantile lies between two data points.
  18169. Can be ``linear``, ``lower``, ``higher``, ``midpoint`` and ``nearest``.
  18170. Default is ``linear``.
  18171. out (Tensor, optional): the output tensor.
  18172. Example::
  18173. >>> t = torch.tensor([float('nan'), 1, 2])
  18174. >>> t.quantile(0.5)
  18175. tensor(nan)
  18176. >>> t.nanquantile(0.5)
  18177. tensor(1.5000)
  18178. >>> t = torch.tensor([[float('nan'), float('nan')], [1, 2]])
  18179. >>> t
  18180. tensor([[nan, nan],
  18181. [1., 2.]])
  18182. >>> t.nanquantile(0.5, dim=0)
  18183. tensor([1., 2.])
  18184. >>> t.nanquantile(0.5, dim=1)
  18185. tensor([ nan, 1.5000])
  18186. """
  18187. @overload
  18188. def nanquantile(
  18189. input: Tensor,
  18190. q: _float,
  18191. dim: _int | None = None,
  18192. keepdim: _bool = False,
  18193. *,
  18194. interpolation: str = "linear",
  18195. out: Tensor | None = None,
  18196. ) -> Tensor:
  18197. r"""
  18198. nanquantile(input, q, dim=None, keepdim=False, *, interpolation='linear', out=None) -> Tensor
  18199. This is a variant of :func:`torch.quantile` that "ignores" ``NaN`` values,
  18200. computing the quantiles :attr:`q` as if ``NaN`` values in :attr:`input` did
  18201. not exist. If all values in a reduced row are ``NaN`` then the quantiles for
  18202. that reduction will be ``NaN``. See the documentation for :func:`torch.quantile`.
  18203. Args:
  18204. input (Tensor): the input tensor.
  18205. q (float or Tensor): a scalar or 1D tensor of quantile values in the range [0, 1]
  18206. dim (int, optional): the dimension to reduce.
  18207. If ``None``, all dimensions are reduced.
  18208. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  18209. Keyword arguments:
  18210. interpolation (str): interpolation method to use when the desired quantile lies between two data points.
  18211. Can be ``linear``, ``lower``, ``higher``, ``midpoint`` and ``nearest``.
  18212. Default is ``linear``.
  18213. out (Tensor, optional): the output tensor.
  18214. Example::
  18215. >>> t = torch.tensor([float('nan'), 1, 2])
  18216. >>> t.quantile(0.5)
  18217. tensor(nan)
  18218. >>> t.nanquantile(0.5)
  18219. tensor(1.5000)
  18220. >>> t = torch.tensor([[float('nan'), float('nan')], [1, 2]])
  18221. >>> t
  18222. tensor([[nan, nan],
  18223. [1., 2.]])
  18224. >>> t.nanquantile(0.5, dim=0)
  18225. tensor([1., 2.])
  18226. >>> t.nanquantile(0.5, dim=1)
  18227. tensor([ nan, 1.5000])
  18228. """
  18229. def nansum(
  18230. input: Tensor,
  18231. dim: _int | _size | None = None,
  18232. keepdim: _bool = False,
  18233. *,
  18234. dtype: _dtype | None = None,
  18235. out: Tensor | None = None,
  18236. ) -> Tensor:
  18237. r"""
  18238. nansum(input, *, dtype=None) -> Tensor
  18239. Returns the sum of all elements, treating Not a Numbers (NaNs) as zero.
  18240. Args:
  18241. input (Tensor): the input tensor.
  18242. Keyword args:
  18243. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  18244. If specified, the input tensor is casted to :attr:`dtype` before the operation
  18245. is performed. This is useful for preventing data type overflows. Default: None.
  18246. Example::
  18247. >>> a = torch.tensor([1., 2., float('nan'), 4.])
  18248. >>> torch.nansum(a)
  18249. tensor(7.)
  18250. .. function:: nansum(input, dim, keepdim=False, *, dtype=None) -> Tensor
  18251. :noindex:
  18252. Returns the sum of each row of the :attr:`input` tensor in the given
  18253. dimension :attr:`dim`, treating Not a Numbers (NaNs) as zero.
  18254. If :attr:`dim` is a list of dimensions, reduce over all of them.
  18255. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  18256. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  18257. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  18258. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  18259. Args:
  18260. input (Tensor): the input tensor.
  18261. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  18262. If ``None``, all dimensions are reduced.
  18263. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  18264. Keyword args:
  18265. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  18266. If specified, the input tensor is casted to :attr:`dtype` before the operation
  18267. is performed. This is useful for preventing data type overflows. Default: None.
  18268. Example::
  18269. >>> torch.nansum(torch.tensor([1., float("nan")]))
  18270. tensor(1.)
  18271. >>> a = torch.tensor([[1, 2], [3., float("nan")]])
  18272. >>> torch.nansum(a)
  18273. tensor(6.)
  18274. >>> torch.nansum(a, dim=0)
  18275. tensor([4., 2.])
  18276. >>> torch.nansum(a, dim=1)
  18277. tensor([3., 3.])
  18278. """
  18279. @overload
  18280. def narrow(
  18281. input: Tensor,
  18282. dim: _int,
  18283. start: Tensor,
  18284. length: _int | SymInt,
  18285. ) -> Tensor:
  18286. r"""
  18287. narrow(input, dim, start, length) -> Tensor
  18288. Returns a new tensor that is a narrowed version of :attr:`input` tensor. The
  18289. dimension :attr:`dim` is input from :attr:`start` to ``start + length``. The
  18290. returned tensor and :attr:`input` tensor share the same underlying storage.
  18291. Args:
  18292. input (Tensor): the tensor to narrow
  18293. dim (int): the dimension along which to narrow
  18294. start (int or Tensor): index of the element to start the narrowed dimension
  18295. from. Can be negative, which means indexing from the end of `dim`. If
  18296. `Tensor`, it must be an 0-dim integral `Tensor` (bools not allowed)
  18297. length (int): length of the narrowed dimension, must be weakly positive
  18298. Example::
  18299. >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
  18300. >>> torch.narrow(x, 0, 0, 2)
  18301. tensor([[ 1, 2, 3],
  18302. [ 4, 5, 6]])
  18303. >>> torch.narrow(x, 1, 1, 2)
  18304. tensor([[ 2, 3],
  18305. [ 5, 6],
  18306. [ 8, 9]])
  18307. >>> torch.narrow(x, -1, torch.tensor(-1), 1)
  18308. tensor([[3],
  18309. [6],
  18310. [9]])
  18311. """
  18312. @overload
  18313. def narrow(
  18314. input: Tensor,
  18315. dim: _int,
  18316. start: _int | SymInt,
  18317. length: _int | SymInt,
  18318. ) -> Tensor:
  18319. r"""
  18320. narrow(input, dim, start, length) -> Tensor
  18321. Returns a new tensor that is a narrowed version of :attr:`input` tensor. The
  18322. dimension :attr:`dim` is input from :attr:`start` to ``start + length``. The
  18323. returned tensor and :attr:`input` tensor share the same underlying storage.
  18324. Args:
  18325. input (Tensor): the tensor to narrow
  18326. dim (int): the dimension along which to narrow
  18327. start (int or Tensor): index of the element to start the narrowed dimension
  18328. from. Can be negative, which means indexing from the end of `dim`. If
  18329. `Tensor`, it must be an 0-dim integral `Tensor` (bools not allowed)
  18330. length (int): length of the narrowed dimension, must be weakly positive
  18331. Example::
  18332. >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
  18333. >>> torch.narrow(x, 0, 0, 2)
  18334. tensor([[ 1, 2, 3],
  18335. [ 4, 5, 6]])
  18336. >>> torch.narrow(x, 1, 1, 2)
  18337. tensor([[ 2, 3],
  18338. [ 5, 6],
  18339. [ 8, 9]])
  18340. >>> torch.narrow(x, -1, torch.tensor(-1), 1)
  18341. tensor([[3],
  18342. [6],
  18343. [9]])
  18344. """
  18345. def narrow_copy(
  18346. input: Tensor,
  18347. dim: _int,
  18348. start: _int | SymInt,
  18349. length: _int | SymInt,
  18350. *,
  18351. out: Tensor | None = None,
  18352. ) -> Tensor:
  18353. r"""
  18354. narrow_copy(input, dim, start, length, *, out=None) -> Tensor
  18355. Same as :meth:`Tensor.narrow` except this returns a copy rather
  18356. than shared storage. This is primarily for sparse tensors, which
  18357. do not have a shared-storage narrow method.
  18358. Args:
  18359. input (Tensor): the tensor to narrow
  18360. dim (int): the dimension along which to narrow
  18361. start (int): index of the element to start the narrowed dimension from. Can
  18362. be negative, which means indexing from the end of `dim`
  18363. length (int): length of the narrowed dimension, must be weakly positive
  18364. Keyword args:
  18365. out (Tensor, optional): the output tensor.
  18366. Example::
  18367. >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
  18368. >>> torch.narrow_copy(x, 0, 0, 2)
  18369. tensor([[ 1, 2, 3],
  18370. [ 4, 5, 6]])
  18371. >>> torch.narrow_copy(x, 1, 1, 2)
  18372. tensor([[ 2, 3],
  18373. [ 5, 6],
  18374. [ 8, 9]])
  18375. >>> s = torch.arange(16).reshape(2, 2, 2, 2).to_sparse(2)
  18376. >>> torch.narrow_copy(s, 0, 0, 1)
  18377. tensor(indices=tensor([[0, 0],
  18378. [0, 1]]),
  18379. values=tensor([[[0, 1],
  18380. [2, 3]],
  18381. [[4, 5],
  18382. [6, 7]]]),
  18383. size=(1, 2, 2, 2), nnz=2, layout=torch.sparse_coo)
  18384. .. seealso::
  18385. :func:`torch.narrow` for a non copy variant
  18386. """
  18387. def native_batch_norm(
  18388. input: Tensor,
  18389. weight: Tensor | None,
  18390. bias: Tensor | None,
  18391. running_mean: Tensor | None,
  18392. running_var: Tensor | None,
  18393. training: _bool,
  18394. momentum: _float,
  18395. eps: _float,
  18396. *,
  18397. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  18398. ) -> tuple[Tensor, Tensor, Tensor]: ...
  18399. def native_channel_shuffle(input: Tensor, groups: _int | SymInt) -> Tensor: ...
  18400. def native_dropout(
  18401. input: Tensor,
  18402. p: _float,
  18403. train: _bool | None,
  18404. ) -> tuple[Tensor, Tensor]: ...
  18405. def native_group_norm(
  18406. input: Tensor,
  18407. weight: Tensor | None,
  18408. bias: Tensor | None,
  18409. N: _int | SymInt,
  18410. C: _int | SymInt,
  18411. HxW: _int | SymInt,
  18412. group: _int,
  18413. eps: _float,
  18414. ) -> tuple[Tensor, Tensor, Tensor]: ...
  18415. def native_layer_norm(
  18416. input: Tensor,
  18417. normalized_shape: Sequence[_int | SymInt],
  18418. weight: Tensor | None,
  18419. bias: Tensor | None,
  18420. eps: _float,
  18421. ) -> tuple[Tensor, Tensor, Tensor]: ...
  18422. @overload
  18423. def native_norm(
  18424. input: Tensor,
  18425. p: Number | _complex | None,
  18426. dim: _int | _size,
  18427. keepdim: _bool,
  18428. dtype: _dtype | None,
  18429. ) -> Tensor: ...
  18430. @overload
  18431. def native_norm(input: Tensor, p: Number | _complex = 2) -> Tensor: ...
  18432. @overload
  18433. def ne(
  18434. input: Tensor,
  18435. other: Tensor,
  18436. *,
  18437. out: Tensor | None = None,
  18438. ) -> Tensor:
  18439. r"""
  18440. ne(input, other, *, out=None) -> Tensor
  18441. Computes :math:`\text{input} \neq \text{other}` element-wise.
  18442. The second argument can be a number or a tensor whose shape is
  18443. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  18444. Args:
  18445. input (Tensor): the tensor to compare
  18446. other (Tensor or float): the tensor or value to compare
  18447. Keyword args:
  18448. out (Tensor, optional): the output tensor.
  18449. Returns:
  18450. A boolean tensor that is True where :attr:`input` is not equal to :attr:`other` and False elsewhere
  18451. Example::
  18452. >>> torch.ne(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  18453. tensor([[False, True], [True, False]])
  18454. """
  18455. @overload
  18456. def ne(
  18457. input: Tensor,
  18458. other: Number | _complex,
  18459. *,
  18460. out: Tensor | None = None,
  18461. ) -> Tensor:
  18462. r"""
  18463. ne(input, other, *, out=None) -> Tensor
  18464. Computes :math:`\text{input} \neq \text{other}` element-wise.
  18465. The second argument can be a number or a tensor whose shape is
  18466. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  18467. Args:
  18468. input (Tensor): the tensor to compare
  18469. other (Tensor or float): the tensor or value to compare
  18470. Keyword args:
  18471. out (Tensor, optional): the output tensor.
  18472. Returns:
  18473. A boolean tensor that is True where :attr:`input` is not equal to :attr:`other` and False elsewhere
  18474. Example::
  18475. >>> torch.ne(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  18476. tensor([[False, True], [True, False]])
  18477. """
  18478. def neg(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  18479. r"""
  18480. neg(input, *, out=None) -> Tensor
  18481. Returns a new tensor with the negative of the elements of :attr:`input`.
  18482. .. math::
  18483. \text{out} = -1 \times \text{input}
  18484. Args:
  18485. input (Tensor): the input tensor.
  18486. Keyword args:
  18487. out (Tensor, optional): the output tensor.
  18488. Example::
  18489. >>> a = torch.randn(5)
  18490. >>> a
  18491. tensor([ 0.0090, -0.2262, -0.0682, -0.2866, 0.3940])
  18492. >>> torch.neg(a)
  18493. tensor([-0.0090, 0.2262, 0.0682, 0.2866, -0.3940])
  18494. """
  18495. def neg_(input: Tensor) -> Tensor: ...
  18496. def negative(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  18497. r"""
  18498. negative(input, *, out=None) -> Tensor
  18499. Alias for :func:`torch.neg`
  18500. """
  18501. def negative_(input: Tensor) -> Tensor: ...
  18502. def nextafter(
  18503. input: Tensor,
  18504. other: Tensor,
  18505. *,
  18506. out: Tensor | None = None,
  18507. ) -> Tensor:
  18508. r"""
  18509. nextafter(input, other, *, out=None) -> Tensor
  18510. Return the next floating-point value after :attr:`input` towards :attr:`other`, elementwise.
  18511. The shapes of ``input`` and ``other`` must be
  18512. :ref:`broadcastable <broadcasting-semantics>`.
  18513. Args:
  18514. input (Tensor): the first input tensor
  18515. other (Tensor): the second input tensor
  18516. Keyword args:
  18517. out (Tensor, optional): the output tensor.
  18518. Example::
  18519. >>> eps = torch.finfo(torch.float32).eps
  18520. >>> torch.nextafter(torch.tensor([1.0, 2.0]), torch.tensor([2.0, 1.0])) == torch.tensor([eps + 1, 2 - eps])
  18521. tensor([True, True])
  18522. """
  18523. @overload
  18524. def nonzero(
  18525. input: Tensor,
  18526. *,
  18527. as_tuple: Literal[False] = False,
  18528. out: Tensor | None = None,
  18529. ) -> Tensor:
  18530. r"""
  18531. nonzero(input, *, out=None, as_tuple=False) -> LongTensor or tuple of LongTensors
  18532. .. note::
  18533. :func:`torch.nonzero(..., as_tuple=False) <torch.nonzero>` (default) returns a
  18534. 2-D tensor where each row is the index for a nonzero value.
  18535. :func:`torch.nonzero(..., as_tuple=True) <torch.nonzero>` returns a tuple of 1-D
  18536. index tensors, allowing for advanced indexing, so ``x[x.nonzero(as_tuple=True)]``
  18537. gives all nonzero values of tensor ``x``. Of the returned tuple, each index tensor
  18538. contains nonzero indices for a certain dimension.
  18539. See below for more details on the two behaviors.
  18540. When :attr:`input` is on CUDA, :func:`torch.nonzero() <torch.nonzero>` causes
  18541. host-device synchronization.
  18542. **When** :attr:`as_tuple` **is** ``False`` **(default)**:
  18543. Returns a tensor containing the indices of all non-zero elements of
  18544. :attr:`input`. Each row in the result contains the indices of a non-zero
  18545. element in :attr:`input`. The result is sorted lexicographically, with
  18546. the last index changing the fastest (C-style).
  18547. If :attr:`input` has :math:`n` dimensions, then the resulting indices tensor
  18548. :attr:`out` is of size :math:`(z \times n)`, where :math:`z` is the total number of
  18549. non-zero elements in the :attr:`input` tensor.
  18550. **When** :attr:`as_tuple` **is** ``True``:
  18551. Returns a tuple of 1-D tensors, one for each dimension in :attr:`input`,
  18552. each containing the indices (in that dimension) of all non-zero elements of
  18553. :attr:`input` .
  18554. If :attr:`input` has :math:`n` dimensions, then the resulting tuple contains :math:`n`
  18555. tensors of size :math:`z`, where :math:`z` is the total number of
  18556. non-zero elements in the :attr:`input` tensor.
  18557. As a special case, when :attr:`input` has zero dimensions and a nonzero scalar
  18558. value, it is treated as a one-dimensional tensor with one element.
  18559. Args:
  18560. input (Tensor): the input tensor.
  18561. Keyword args:
  18562. out (LongTensor, optional): the output tensor containing indices
  18563. Returns:
  18564. LongTensor or tuple of LongTensor: If :attr:`as_tuple` is ``False``, the output
  18565. tensor containing indices. If :attr:`as_tuple` is ``True``, one 1-D tensor for
  18566. each dimension, containing the indices of each nonzero element along that
  18567. dimension.
  18568. Example::
  18569. >>> torch.nonzero(torch.tensor([1, 1, 1, 0, 1]))
  18570. tensor([[ 0],
  18571. [ 1],
  18572. [ 2],
  18573. [ 4]])
  18574. >>> torch.nonzero(torch.tensor([[0.6, 0.0, 0.0, 0.0],
  18575. ... [0.0, 0.4, 0.0, 0.0],
  18576. ... [0.0, 0.0, 1.2, 0.0],
  18577. ... [0.0, 0.0, 0.0,-0.4]]))
  18578. tensor([[ 0, 0],
  18579. [ 1, 1],
  18580. [ 2, 2],
  18581. [ 3, 3]])
  18582. >>> torch.nonzero(torch.tensor([1, 1, 1, 0, 1]), as_tuple=True)
  18583. (tensor([0, 1, 2, 4]),)
  18584. >>> torch.nonzero(torch.tensor([[0.6, 0.0, 0.0, 0.0],
  18585. ... [0.0, 0.4, 0.0, 0.0],
  18586. ... [0.0, 0.0, 1.2, 0.0],
  18587. ... [0.0, 0.0, 0.0,-0.4]]), as_tuple=True)
  18588. (tensor([0, 1, 2, 3]), tensor([0, 1, 2, 3]))
  18589. >>> torch.nonzero(torch.tensor(5), as_tuple=True)
  18590. (tensor([0]),)
  18591. """
  18592. @overload
  18593. def nonzero(
  18594. input: Tensor,
  18595. *,
  18596. as_tuple: Literal[True],
  18597. ) -> tuple[Tensor, ...]:
  18598. r"""
  18599. nonzero(input, *, out=None, as_tuple=False) -> LongTensor or tuple of LongTensors
  18600. .. note::
  18601. :func:`torch.nonzero(..., as_tuple=False) <torch.nonzero>` (default) returns a
  18602. 2-D tensor where each row is the index for a nonzero value.
  18603. :func:`torch.nonzero(..., as_tuple=True) <torch.nonzero>` returns a tuple of 1-D
  18604. index tensors, allowing for advanced indexing, so ``x[x.nonzero(as_tuple=True)]``
  18605. gives all nonzero values of tensor ``x``. Of the returned tuple, each index tensor
  18606. contains nonzero indices for a certain dimension.
  18607. See below for more details on the two behaviors.
  18608. When :attr:`input` is on CUDA, :func:`torch.nonzero() <torch.nonzero>` causes
  18609. host-device synchronization.
  18610. **When** :attr:`as_tuple` **is** ``False`` **(default)**:
  18611. Returns a tensor containing the indices of all non-zero elements of
  18612. :attr:`input`. Each row in the result contains the indices of a non-zero
  18613. element in :attr:`input`. The result is sorted lexicographically, with
  18614. the last index changing the fastest (C-style).
  18615. If :attr:`input` has :math:`n` dimensions, then the resulting indices tensor
  18616. :attr:`out` is of size :math:`(z \times n)`, where :math:`z` is the total number of
  18617. non-zero elements in the :attr:`input` tensor.
  18618. **When** :attr:`as_tuple` **is** ``True``:
  18619. Returns a tuple of 1-D tensors, one for each dimension in :attr:`input`,
  18620. each containing the indices (in that dimension) of all non-zero elements of
  18621. :attr:`input` .
  18622. If :attr:`input` has :math:`n` dimensions, then the resulting tuple contains :math:`n`
  18623. tensors of size :math:`z`, where :math:`z` is the total number of
  18624. non-zero elements in the :attr:`input` tensor.
  18625. As a special case, when :attr:`input` has zero dimensions and a nonzero scalar
  18626. value, it is treated as a one-dimensional tensor with one element.
  18627. Args:
  18628. input (Tensor): the input tensor.
  18629. Keyword args:
  18630. out (LongTensor, optional): the output tensor containing indices
  18631. Returns:
  18632. LongTensor or tuple of LongTensor: If :attr:`as_tuple` is ``False``, the output
  18633. tensor containing indices. If :attr:`as_tuple` is ``True``, one 1-D tensor for
  18634. each dimension, containing the indices of each nonzero element along that
  18635. dimension.
  18636. Example::
  18637. >>> torch.nonzero(torch.tensor([1, 1, 1, 0, 1]))
  18638. tensor([[ 0],
  18639. [ 1],
  18640. [ 2],
  18641. [ 4]])
  18642. >>> torch.nonzero(torch.tensor([[0.6, 0.0, 0.0, 0.0],
  18643. ... [0.0, 0.4, 0.0, 0.0],
  18644. ... [0.0, 0.0, 1.2, 0.0],
  18645. ... [0.0, 0.0, 0.0,-0.4]]))
  18646. tensor([[ 0, 0],
  18647. [ 1, 1],
  18648. [ 2, 2],
  18649. [ 3, 3]])
  18650. >>> torch.nonzero(torch.tensor([1, 1, 1, 0, 1]), as_tuple=True)
  18651. (tensor([0, 1, 2, 4]),)
  18652. >>> torch.nonzero(torch.tensor([[0.6, 0.0, 0.0, 0.0],
  18653. ... [0.0, 0.4, 0.0, 0.0],
  18654. ... [0.0, 0.0, 1.2, 0.0],
  18655. ... [0.0, 0.0, 0.0,-0.4]]), as_tuple=True)
  18656. (tensor([0, 1, 2, 3]), tensor([0, 1, 2, 3]))
  18657. >>> torch.nonzero(torch.tensor(5), as_tuple=True)
  18658. (tensor([0]),)
  18659. """
  18660. def nonzero_static(
  18661. input: Tensor,
  18662. *,
  18663. size: _int | SymInt,
  18664. fill_value: _int = -1,
  18665. out: Tensor | None = None,
  18666. ) -> Tensor: ...
  18667. def norm_except_dim(v: Tensor, pow: _int = 2, dim: _int = 0) -> Tensor: ...
  18668. @overload
  18669. def normal(
  18670. mean: Tensor,
  18671. std: Tensor,
  18672. *,
  18673. generator: Generator | None = None,
  18674. out: Tensor | None = None,
  18675. ) -> Tensor:
  18676. r"""
  18677. normal(mean, std, *, generator=None, out=None) -> Tensor
  18678. Returns a tensor of random numbers drawn from separate normal distributions
  18679. whose mean and standard deviation are given.
  18680. The :attr:`mean` is a tensor with the mean of
  18681. each output element's normal distribution
  18682. The :attr:`std` is a tensor with the standard deviation of
  18683. each output element's normal distribution
  18684. The shapes of :attr:`mean` and :attr:`std` don't need to match, but the
  18685. total number of elements in each tensor need to be the same.
  18686. .. note:: When the shapes do not match, the shape of :attr:`mean`
  18687. is used as the shape for the returned output tensor
  18688. .. note:: When :attr:`std` is a CUDA tensor, this function synchronizes
  18689. its device with the CPU.
  18690. Args:
  18691. mean (Tensor): the tensor of per-element means
  18692. std (Tensor): the tensor of per-element standard deviations
  18693. Keyword args:
  18694. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  18695. out (Tensor, optional): the output tensor.
  18696. Example::
  18697. >>> torch.normal(mean=torch.arange(1., 11.), std=torch.arange(1, 0, -0.1))
  18698. tensor([ 1.0425, 3.5672, 2.7969, 4.2925, 4.7229, 6.2134,
  18699. 8.0505, 8.1408, 9.0563, 10.0566])
  18700. .. function:: normal(mean=0.0, std, *, out=None) -> Tensor
  18701. :noindex:
  18702. Similar to the function above, but the means are shared among all drawn
  18703. elements.
  18704. Args:
  18705. mean (float, optional): the mean for all distributions
  18706. std (Tensor): the tensor of per-element standard deviations
  18707. Keyword args:
  18708. out (Tensor, optional): the output tensor.
  18709. Example::
  18710. >>> torch.normal(mean=0.5, std=torch.arange(1., 6.))
  18711. tensor([-1.2793, -1.0732, -2.0687, 5.1177, -1.2303])
  18712. .. function:: normal(mean, std=1.0, *, out=None) -> Tensor
  18713. :noindex:
  18714. Similar to the function above, but the standard deviations are shared among
  18715. all drawn elements.
  18716. Args:
  18717. mean (Tensor): the tensor of per-element means
  18718. std (float, optional): the standard deviation for all distributions
  18719. Keyword args:
  18720. out (Tensor, optional): the output tensor
  18721. Example::
  18722. >>> torch.normal(mean=torch.arange(1., 6.))
  18723. tensor([ 1.1552, 2.6148, 2.6535, 5.8318, 4.2361])
  18724. .. function:: normal(mean, std, size, *, out=None) -> Tensor
  18725. :noindex:
  18726. Similar to the function above, but the means and standard deviations are shared
  18727. among all drawn elements. The resulting tensor has size given by :attr:`size`.
  18728. Args:
  18729. mean (float): the mean for all distributions
  18730. std (float): the standard deviation for all distributions
  18731. size (int...): a sequence of integers defining the shape of the output tensor.
  18732. Keyword args:
  18733. out (Tensor, optional): the output tensor.
  18734. Example::
  18735. >>> torch.normal(2, 3, size=(1, 4))
  18736. tensor([[-1.3987, -1.9544, 3.6048, 0.7909]])
  18737. """
  18738. @overload
  18739. def normal(
  18740. mean: Tensor,
  18741. std: _float = 1,
  18742. *,
  18743. generator: Generator | None = None,
  18744. out: Tensor | None = None,
  18745. ) -> Tensor:
  18746. r"""
  18747. normal(mean, std, *, generator=None, out=None) -> Tensor
  18748. Returns a tensor of random numbers drawn from separate normal distributions
  18749. whose mean and standard deviation are given.
  18750. The :attr:`mean` is a tensor with the mean of
  18751. each output element's normal distribution
  18752. The :attr:`std` is a tensor with the standard deviation of
  18753. each output element's normal distribution
  18754. The shapes of :attr:`mean` and :attr:`std` don't need to match, but the
  18755. total number of elements in each tensor need to be the same.
  18756. .. note:: When the shapes do not match, the shape of :attr:`mean`
  18757. is used as the shape for the returned output tensor
  18758. .. note:: When :attr:`std` is a CUDA tensor, this function synchronizes
  18759. its device with the CPU.
  18760. Args:
  18761. mean (Tensor): the tensor of per-element means
  18762. std (Tensor): the tensor of per-element standard deviations
  18763. Keyword args:
  18764. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  18765. out (Tensor, optional): the output tensor.
  18766. Example::
  18767. >>> torch.normal(mean=torch.arange(1., 11.), std=torch.arange(1, 0, -0.1))
  18768. tensor([ 1.0425, 3.5672, 2.7969, 4.2925, 4.7229, 6.2134,
  18769. 8.0505, 8.1408, 9.0563, 10.0566])
  18770. .. function:: normal(mean=0.0, std, *, out=None) -> Tensor
  18771. :noindex:
  18772. Similar to the function above, but the means are shared among all drawn
  18773. elements.
  18774. Args:
  18775. mean (float, optional): the mean for all distributions
  18776. std (Tensor): the tensor of per-element standard deviations
  18777. Keyword args:
  18778. out (Tensor, optional): the output tensor.
  18779. Example::
  18780. >>> torch.normal(mean=0.5, std=torch.arange(1., 6.))
  18781. tensor([-1.2793, -1.0732, -2.0687, 5.1177, -1.2303])
  18782. .. function:: normal(mean, std=1.0, *, out=None) -> Tensor
  18783. :noindex:
  18784. Similar to the function above, but the standard deviations are shared among
  18785. all drawn elements.
  18786. Args:
  18787. mean (Tensor): the tensor of per-element means
  18788. std (float, optional): the standard deviation for all distributions
  18789. Keyword args:
  18790. out (Tensor, optional): the output tensor
  18791. Example::
  18792. >>> torch.normal(mean=torch.arange(1., 6.))
  18793. tensor([ 1.1552, 2.6148, 2.6535, 5.8318, 4.2361])
  18794. .. function:: normal(mean, std, size, *, out=None) -> Tensor
  18795. :noindex:
  18796. Similar to the function above, but the means and standard deviations are shared
  18797. among all drawn elements. The resulting tensor has size given by :attr:`size`.
  18798. Args:
  18799. mean (float): the mean for all distributions
  18800. std (float): the standard deviation for all distributions
  18801. size (int...): a sequence of integers defining the shape of the output tensor.
  18802. Keyword args:
  18803. out (Tensor, optional): the output tensor.
  18804. Example::
  18805. >>> torch.normal(2, 3, size=(1, 4))
  18806. tensor([[-1.3987, -1.9544, 3.6048, 0.7909]])
  18807. """
  18808. @overload
  18809. def normal(
  18810. mean: _float,
  18811. std: Tensor,
  18812. *,
  18813. generator: Generator | None = None,
  18814. out: Tensor | None = None,
  18815. ) -> Tensor:
  18816. r"""
  18817. normal(mean, std, *, generator=None, out=None) -> Tensor
  18818. Returns a tensor of random numbers drawn from separate normal distributions
  18819. whose mean and standard deviation are given.
  18820. The :attr:`mean` is a tensor with the mean of
  18821. each output element's normal distribution
  18822. The :attr:`std` is a tensor with the standard deviation of
  18823. each output element's normal distribution
  18824. The shapes of :attr:`mean` and :attr:`std` don't need to match, but the
  18825. total number of elements in each tensor need to be the same.
  18826. .. note:: When the shapes do not match, the shape of :attr:`mean`
  18827. is used as the shape for the returned output tensor
  18828. .. note:: When :attr:`std` is a CUDA tensor, this function synchronizes
  18829. its device with the CPU.
  18830. Args:
  18831. mean (Tensor): the tensor of per-element means
  18832. std (Tensor): the tensor of per-element standard deviations
  18833. Keyword args:
  18834. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  18835. out (Tensor, optional): the output tensor.
  18836. Example::
  18837. >>> torch.normal(mean=torch.arange(1., 11.), std=torch.arange(1, 0, -0.1))
  18838. tensor([ 1.0425, 3.5672, 2.7969, 4.2925, 4.7229, 6.2134,
  18839. 8.0505, 8.1408, 9.0563, 10.0566])
  18840. .. function:: normal(mean=0.0, std, *, out=None) -> Tensor
  18841. :noindex:
  18842. Similar to the function above, but the means are shared among all drawn
  18843. elements.
  18844. Args:
  18845. mean (float, optional): the mean for all distributions
  18846. std (Tensor): the tensor of per-element standard deviations
  18847. Keyword args:
  18848. out (Tensor, optional): the output tensor.
  18849. Example::
  18850. >>> torch.normal(mean=0.5, std=torch.arange(1., 6.))
  18851. tensor([-1.2793, -1.0732, -2.0687, 5.1177, -1.2303])
  18852. .. function:: normal(mean, std=1.0, *, out=None) -> Tensor
  18853. :noindex:
  18854. Similar to the function above, but the standard deviations are shared among
  18855. all drawn elements.
  18856. Args:
  18857. mean (Tensor): the tensor of per-element means
  18858. std (float, optional): the standard deviation for all distributions
  18859. Keyword args:
  18860. out (Tensor, optional): the output tensor
  18861. Example::
  18862. >>> torch.normal(mean=torch.arange(1., 6.))
  18863. tensor([ 1.1552, 2.6148, 2.6535, 5.8318, 4.2361])
  18864. .. function:: normal(mean, std, size, *, out=None) -> Tensor
  18865. :noindex:
  18866. Similar to the function above, but the means and standard deviations are shared
  18867. among all drawn elements. The resulting tensor has size given by :attr:`size`.
  18868. Args:
  18869. mean (float): the mean for all distributions
  18870. std (float): the standard deviation for all distributions
  18871. size (int...): a sequence of integers defining the shape of the output tensor.
  18872. Keyword args:
  18873. out (Tensor, optional): the output tensor.
  18874. Example::
  18875. >>> torch.normal(2, 3, size=(1, 4))
  18876. tensor([[-1.3987, -1.9544, 3.6048, 0.7909]])
  18877. """
  18878. @overload
  18879. def normal(
  18880. mean: _float,
  18881. std: _float,
  18882. size: Sequence[_int | SymInt],
  18883. *,
  18884. generator: Generator | None = None,
  18885. out: Tensor | None = None,
  18886. dtype: _dtype | None = None,
  18887. layout: _layout | None = None,
  18888. device: DeviceLikeType | None = None,
  18889. pin_memory: _bool | None = False,
  18890. requires_grad: _bool | None = False,
  18891. ) -> Tensor:
  18892. r"""
  18893. normal(mean, std, *, generator=None, out=None) -> Tensor
  18894. Returns a tensor of random numbers drawn from separate normal distributions
  18895. whose mean and standard deviation are given.
  18896. The :attr:`mean` is a tensor with the mean of
  18897. each output element's normal distribution
  18898. The :attr:`std` is a tensor with the standard deviation of
  18899. each output element's normal distribution
  18900. The shapes of :attr:`mean` and :attr:`std` don't need to match, but the
  18901. total number of elements in each tensor need to be the same.
  18902. .. note:: When the shapes do not match, the shape of :attr:`mean`
  18903. is used as the shape for the returned output tensor
  18904. .. note:: When :attr:`std` is a CUDA tensor, this function synchronizes
  18905. its device with the CPU.
  18906. Args:
  18907. mean (Tensor): the tensor of per-element means
  18908. std (Tensor): the tensor of per-element standard deviations
  18909. Keyword args:
  18910. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  18911. out (Tensor, optional): the output tensor.
  18912. Example::
  18913. >>> torch.normal(mean=torch.arange(1., 11.), std=torch.arange(1, 0, -0.1))
  18914. tensor([ 1.0425, 3.5672, 2.7969, 4.2925, 4.7229, 6.2134,
  18915. 8.0505, 8.1408, 9.0563, 10.0566])
  18916. .. function:: normal(mean=0.0, std, *, out=None) -> Tensor
  18917. :noindex:
  18918. Similar to the function above, but the means are shared among all drawn
  18919. elements.
  18920. Args:
  18921. mean (float, optional): the mean for all distributions
  18922. std (Tensor): the tensor of per-element standard deviations
  18923. Keyword args:
  18924. out (Tensor, optional): the output tensor.
  18925. Example::
  18926. >>> torch.normal(mean=0.5, std=torch.arange(1., 6.))
  18927. tensor([-1.2793, -1.0732, -2.0687, 5.1177, -1.2303])
  18928. .. function:: normal(mean, std=1.0, *, out=None) -> Tensor
  18929. :noindex:
  18930. Similar to the function above, but the standard deviations are shared among
  18931. all drawn elements.
  18932. Args:
  18933. mean (Tensor): the tensor of per-element means
  18934. std (float, optional): the standard deviation for all distributions
  18935. Keyword args:
  18936. out (Tensor, optional): the output tensor
  18937. Example::
  18938. >>> torch.normal(mean=torch.arange(1., 6.))
  18939. tensor([ 1.1552, 2.6148, 2.6535, 5.8318, 4.2361])
  18940. .. function:: normal(mean, std, size, *, out=None) -> Tensor
  18941. :noindex:
  18942. Similar to the function above, but the means and standard deviations are shared
  18943. among all drawn elements. The resulting tensor has size given by :attr:`size`.
  18944. Args:
  18945. mean (float): the mean for all distributions
  18946. std (float): the standard deviation for all distributions
  18947. size (int...): a sequence of integers defining the shape of the output tensor.
  18948. Keyword args:
  18949. out (Tensor, optional): the output tensor.
  18950. Example::
  18951. >>> torch.normal(2, 3, size=(1, 4))
  18952. tensor([[-1.3987, -1.9544, 3.6048, 0.7909]])
  18953. """
  18954. @overload
  18955. def not_equal(
  18956. input: Tensor,
  18957. other: Tensor,
  18958. *,
  18959. out: Tensor | None = None,
  18960. ) -> Tensor:
  18961. r"""
  18962. not_equal(input, other, *, out=None) -> Tensor
  18963. Alias for :func:`torch.ne`.
  18964. """
  18965. @overload
  18966. def not_equal(
  18967. input: Tensor,
  18968. other: Number | _complex,
  18969. *,
  18970. out: Tensor | None = None,
  18971. ) -> Tensor:
  18972. r"""
  18973. not_equal(input, other, *, out=None) -> Tensor
  18974. Alias for :func:`torch.ne`.
  18975. """
  18976. @overload
  18977. def nuclear_norm(
  18978. input: Tensor,
  18979. dim: _int | _size,
  18980. keepdim: _bool = False,
  18981. *,
  18982. out: Tensor | None = None,
  18983. ) -> Tensor: ...
  18984. @overload
  18985. def nuclear_norm(
  18986. input: Tensor,
  18987. keepdim: _bool = False,
  18988. *,
  18989. out: Tensor | None = None,
  18990. ) -> Tensor: ...
  18991. def numel(self: Tensor) -> _int:
  18992. r"""
  18993. numel(input: Tensor) -> int
  18994. Returns the total number of elements in the :attr:`input` tensor.
  18995. Args:
  18996. input (Tensor): the input tensor.
  18997. Example::
  18998. >>> a = torch.randn(1, 2, 3, 4, 5)
  18999. >>> torch.numel(a)
  19000. 120
  19001. >>> a = torch.zeros(4,4)
  19002. >>> torch.numel(a)
  19003. 16
  19004. """
  19005. @overload
  19006. def ones(
  19007. size: Sequence[_int | SymInt],
  19008. *,
  19009. out: Tensor | None = None,
  19010. dtype: _dtype | None = None,
  19011. layout: _layout | None = None,
  19012. device: DeviceLikeType | None = None,
  19013. pin_memory: _bool | None = False,
  19014. requires_grad: _bool | None = False,
  19015. ) -> Tensor:
  19016. r"""
  19017. ones(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  19018. Returns a tensor filled with the scalar value `1`, with the shape defined
  19019. by the variable argument :attr:`size`.
  19020. Args:
  19021. size (int...): a sequence of integers defining the shape of the output tensor.
  19022. Can be a variable number of arguments or a collection like a list or tuple.
  19023. Keyword arguments:
  19024. out (Tensor, optional): the output tensor.
  19025. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19026. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  19027. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  19028. Default: ``torch.strided``.
  19029. device (:class:`torch.device`, optional): the desired device of returned tensor.
  19030. Default: if ``None``, uses the current device for the default tensor type
  19031. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  19032. for CPU tensor types and the current CUDA device for CUDA tensor types.
  19033. requires_grad (bool, optional): If autograd should record operations on the
  19034. returned tensor. Default: ``False``.
  19035. Example::
  19036. >>> torch.ones(2, 3)
  19037. tensor([[ 1., 1., 1.],
  19038. [ 1., 1., 1.]])
  19039. >>> torch.ones(5)
  19040. tensor([ 1., 1., 1., 1., 1.])
  19041. """
  19042. @overload
  19043. def ones(
  19044. *size: _int | SymInt,
  19045. out: Tensor | None = None,
  19046. dtype: _dtype | None = None,
  19047. layout: _layout | None = None,
  19048. device: DeviceLikeType | None = None,
  19049. pin_memory: _bool | None = False,
  19050. requires_grad: _bool | None = False,
  19051. ) -> Tensor:
  19052. r"""
  19053. ones(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  19054. Returns a tensor filled with the scalar value `1`, with the shape defined
  19055. by the variable argument :attr:`size`.
  19056. Args:
  19057. size (int...): a sequence of integers defining the shape of the output tensor.
  19058. Can be a variable number of arguments or a collection like a list or tuple.
  19059. Keyword arguments:
  19060. out (Tensor, optional): the output tensor.
  19061. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19062. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  19063. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  19064. Default: ``torch.strided``.
  19065. device (:class:`torch.device`, optional): the desired device of returned tensor.
  19066. Default: if ``None``, uses the current device for the default tensor type
  19067. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  19068. for CPU tensor types and the current CUDA device for CUDA tensor types.
  19069. requires_grad (bool, optional): If autograd should record operations on the
  19070. returned tensor. Default: ``False``.
  19071. Example::
  19072. >>> torch.ones(2, 3)
  19073. tensor([[ 1., 1., 1.],
  19074. [ 1., 1., 1.]])
  19075. >>> torch.ones(5)
  19076. tensor([ 1., 1., 1., 1., 1.])
  19077. """
  19078. @overload
  19079. def ones(
  19080. size: _size,
  19081. *,
  19082. names: Sequence[str | EllipsisType | None] | None,
  19083. dtype: _dtype | None = None,
  19084. layout: _layout | None = None,
  19085. device: DeviceLikeType | None = None,
  19086. pin_memory: _bool | None = False,
  19087. requires_grad: _bool | None = False,
  19088. ) -> Tensor:
  19089. r"""
  19090. ones(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  19091. Returns a tensor filled with the scalar value `1`, with the shape defined
  19092. by the variable argument :attr:`size`.
  19093. Args:
  19094. size (int...): a sequence of integers defining the shape of the output tensor.
  19095. Can be a variable number of arguments or a collection like a list or tuple.
  19096. Keyword arguments:
  19097. out (Tensor, optional): the output tensor.
  19098. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19099. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  19100. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  19101. Default: ``torch.strided``.
  19102. device (:class:`torch.device`, optional): the desired device of returned tensor.
  19103. Default: if ``None``, uses the current device for the default tensor type
  19104. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  19105. for CPU tensor types and the current CUDA device for CUDA tensor types.
  19106. requires_grad (bool, optional): If autograd should record operations on the
  19107. returned tensor. Default: ``False``.
  19108. Example::
  19109. >>> torch.ones(2, 3)
  19110. tensor([[ 1., 1., 1.],
  19111. [ 1., 1., 1.]])
  19112. >>> torch.ones(5)
  19113. tensor([ 1., 1., 1., 1., 1.])
  19114. """
  19115. @overload
  19116. def ones(
  19117. *size: _int,
  19118. names: Sequence[str | EllipsisType | None] | None,
  19119. dtype: _dtype | None = None,
  19120. layout: _layout | None = None,
  19121. device: DeviceLikeType | None = None,
  19122. pin_memory: _bool | None = False,
  19123. requires_grad: _bool | None = False,
  19124. ) -> Tensor:
  19125. r"""
  19126. ones(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  19127. Returns a tensor filled with the scalar value `1`, with the shape defined
  19128. by the variable argument :attr:`size`.
  19129. Args:
  19130. size (int...): a sequence of integers defining the shape of the output tensor.
  19131. Can be a variable number of arguments or a collection like a list or tuple.
  19132. Keyword arguments:
  19133. out (Tensor, optional): the output tensor.
  19134. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19135. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  19136. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  19137. Default: ``torch.strided``.
  19138. device (:class:`torch.device`, optional): the desired device of returned tensor.
  19139. Default: if ``None``, uses the current device for the default tensor type
  19140. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  19141. for CPU tensor types and the current CUDA device for CUDA tensor types.
  19142. requires_grad (bool, optional): If autograd should record operations on the
  19143. returned tensor. Default: ``False``.
  19144. Example::
  19145. >>> torch.ones(2, 3)
  19146. tensor([[ 1., 1., 1.],
  19147. [ 1., 1., 1.]])
  19148. >>> torch.ones(5)
  19149. tensor([ 1., 1., 1., 1., 1.])
  19150. """
  19151. def ones_like(
  19152. input: Tensor,
  19153. *,
  19154. memory_format: memory_format | None = None,
  19155. dtype: _dtype | None = None,
  19156. layout: _layout | None = None,
  19157. device: DeviceLikeType | None = None,
  19158. pin_memory: _bool | None = False,
  19159. requires_grad: _bool | None = False,
  19160. ) -> Tensor:
  19161. r"""
  19162. ones_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  19163. Returns a tensor filled with the scalar value `1`, with the same size as
  19164. :attr:`input`. ``torch.ones_like(input)`` is equivalent to
  19165. ``torch.ones(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
  19166. .. warning::
  19167. As of 0.4, this function does not support an :attr:`out` keyword. As an alternative,
  19168. the old ``torch.ones_like(input, out=output)`` is equivalent to
  19169. ``torch.ones(input.size(), out=output)``.
  19170. Args:
  19171. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  19172. Keyword arguments:
  19173. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  19174. Default: if ``None``, defaults to the dtype of :attr:`input`.
  19175. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  19176. Default: if ``None``, defaults to the layout of :attr:`input`.
  19177. device (:class:`torch.device`, optional): the desired device of returned tensor.
  19178. Default: if ``None``, defaults to the device of :attr:`input`.
  19179. requires_grad (bool, optional): If autograd should record operations on the
  19180. returned tensor. Default: ``False``.
  19181. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  19182. returned Tensor. Default: ``torch.preserve_format``.
  19183. Example::
  19184. >>> input = torch.empty(2, 3)
  19185. >>> torch.ones_like(input)
  19186. tensor([[ 1., 1., 1.],
  19187. [ 1., 1., 1.]])
  19188. """
  19189. def orgqr(
  19190. input: Tensor,
  19191. input2: Tensor,
  19192. *,
  19193. out: Tensor | None = None,
  19194. ) -> Tensor:
  19195. r"""
  19196. orgqr(input, tau) -> Tensor
  19197. Alias for :func:`torch.linalg.householder_product`.
  19198. """
  19199. def ormqr(
  19200. input: Tensor,
  19201. input2: Tensor,
  19202. input3: Tensor,
  19203. left: _bool = True,
  19204. transpose: _bool = False,
  19205. *,
  19206. out: Tensor | None = None,
  19207. ) -> Tensor:
  19208. r"""
  19209. ormqr(input, tau, other, left=True, transpose=False, *, out=None) -> Tensor
  19210. Computes the matrix-matrix multiplication of a product of Householder matrices with a general matrix.
  19211. Multiplies a :math:`m \times n` matrix `C` (given by :attr:`other`) with a matrix `Q`,
  19212. where `Q` is represented using Householder reflectors `(input, tau)`.
  19213. See `Representation of Orthogonal or Unitary Matrices`_ for further details.
  19214. If :attr:`left` is `True` then `op(Q)` times `C` is computed, otherwise the result is `C` times `op(Q)`.
  19215. When :attr:`left` is `True`, the implicit matrix `Q` has size :math:`m \times m`.
  19216. It has size :math:`n \times n` otherwise.
  19217. If :attr:`transpose` is `True` then `op` is the conjugate transpose operation, otherwise it's a no-op.
  19218. Supports inputs of float, double, cfloat and cdouble dtypes.
  19219. Also supports batched inputs, and, if the input is batched, the output is batched with the same dimensions.
  19220. .. seealso::
  19221. :func:`torch.geqrf` can be used to form the Householder representation `(input, tau)` of matrix `Q`
  19222. from the QR decomposition.
  19223. .. note::
  19224. This function supports backward but it is only fast when ``(input, tau)`` do not require gradients
  19225. and/or ``tau.size(-1)`` is very small.
  19226. ``
  19227. Args:
  19228. input (Tensor): tensor of shape `(*, mn, k)` where `*` is zero or more batch dimensions
  19229. and `mn` equals to `m` or `n` depending on the :attr:`left`.
  19230. tau (Tensor): tensor of shape `(*, min(mn, k))` where `*` is zero or more batch dimensions.
  19231. other (Tensor): tensor of shape `(*, m, n)` where `*` is zero or more batch dimensions.
  19232. left (bool): controls the order of multiplication.
  19233. transpose (bool): controls whether the matrix `Q` is conjugate transposed or not.
  19234. Keyword args:
  19235. out (Tensor, optional): the output Tensor. Ignored if `None`. Default: `None`.
  19236. .. _Representation of Orthogonal or Unitary Matrices:
  19237. https://www.netlib.org/lapack/lug/node128.html
  19238. """
  19239. def outer(
  19240. input: Tensor,
  19241. vec2: Tensor,
  19242. *,
  19243. out: Tensor | None = None,
  19244. ) -> Tensor:
  19245. r"""
  19246. outer(input, vec2, *, out=None) -> Tensor
  19247. Outer product of :attr:`input` and :attr:`vec2`.
  19248. If :attr:`input` is a vector of size :math:`n` and :attr:`vec2` is a vector of
  19249. size :math:`m`, then :attr:`out` must be a matrix of size :math:`(n \times m)`.
  19250. .. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
  19251. Args:
  19252. input (Tensor): 1-D input vector
  19253. vec2 (Tensor): 1-D input vector
  19254. Keyword args:
  19255. out (Tensor, optional): optional output matrix
  19256. Example::
  19257. >>> v1 = torch.arange(1., 5.)
  19258. >>> v2 = torch.arange(1., 4.)
  19259. >>> torch.outer(v1, v2)
  19260. tensor([[ 1., 2., 3.],
  19261. [ 2., 4., 6.],
  19262. [ 3., 6., 9.],
  19263. [ 4., 8., 12.]])
  19264. """
  19265. def pairwise_distance(
  19266. x1: Tensor,
  19267. x2: Tensor,
  19268. p: _float = 2,
  19269. eps: _float = 1e-06,
  19270. keepdim: _bool = False,
  19271. ) -> Tensor: ...
  19272. def pdist(input: Tensor, p: _float = 2) -> Tensor: ...
  19273. def permute(input: Tensor, dims: _size) -> Tensor:
  19274. r"""
  19275. permute(input, dims) -> Tensor
  19276. Returns a view of the original tensor :attr:`input` with its dimensions permuted.
  19277. Args:
  19278. input (Tensor): the input tensor.
  19279. dims (torch.Size, tuple of int or list of int): the desired ordering of dimensions.
  19280. Example:
  19281. >>> x = torch.randn(2, 3, 5)
  19282. >>> x.size()
  19283. torch.Size([2, 3, 5])
  19284. >>> torch.permute(x, (2, 0, 1)).size()
  19285. torch.Size([5, 2, 3])
  19286. """
  19287. def permute_copy(
  19288. input: Tensor,
  19289. dims: _size,
  19290. *,
  19291. out: Tensor | None = None,
  19292. ) -> Tensor:
  19293. r"""
  19294. Performs the same operation as :func:`torch.permute`, but all output tensors
  19295. are freshly created instead of aliasing the input.
  19296. """
  19297. def pinverse(input: Tensor, rcond: _float = 1e-15) -> Tensor:
  19298. r"""
  19299. pinverse(input, rcond=1e-15) -> Tensor
  19300. Alias for :func:`torch.linalg.pinv`
  19301. """
  19302. def pixel_shuffle(input: Tensor, upscale_factor: _int) -> Tensor: ...
  19303. def pixel_unshuffle(input: Tensor, downscale_factor: _int) -> Tensor: ...
  19304. def poisson(input: Tensor, generator: Generator | None = None) -> Tensor:
  19305. r"""
  19306. poisson(input, generator=None) -> Tensor
  19307. Returns a tensor of the same size as :attr:`input` with each element
  19308. sampled from a Poisson distribution with rate parameter given by the corresponding
  19309. element in :attr:`input` i.e.,
  19310. .. math::
  19311. \text{out}_i \sim \text{Poisson}(\text{input}_i)
  19312. :attr:`input` must be non-negative.
  19313. Args:
  19314. input (Tensor): the input tensor containing the rates of the Poisson distribution
  19315. Keyword args:
  19316. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  19317. Example::
  19318. >>> rates = torch.rand(4, 4) * 5 # rate parameter between 0 and 5
  19319. >>> torch.poisson(rates)
  19320. tensor([[9., 1., 3., 5.],
  19321. [8., 6., 6., 0.],
  19322. [0., 4., 5., 3.],
  19323. [2., 1., 4., 2.]])
  19324. """
  19325. def poisson_nll_loss(
  19326. input: Tensor,
  19327. target: Tensor,
  19328. log_input: _bool,
  19329. full: _bool,
  19330. eps: _float,
  19331. reduction: _int,
  19332. ) -> Tensor: ...
  19333. def polar(
  19334. abs: Tensor,
  19335. angle: Tensor,
  19336. *,
  19337. out: Tensor | None = None,
  19338. ) -> Tensor:
  19339. r"""
  19340. polar(abs, angle, *, out=None) -> Tensor
  19341. Constructs a complex tensor whose elements are Cartesian coordinates
  19342. corresponding to the polar coordinates with absolute value :attr:`abs` and angle
  19343. :attr:`angle`.
  19344. .. math::
  19345. \text{out} = \text{abs} \cdot \cos(\text{angle}) + \text{abs} \cdot \sin(\text{angle}) \cdot j
  19346. .. note::
  19347. `torch.polar` is similar to
  19348. `std::polar <https://en.cppreference.com/w/cpp/numeric/complex/polar>`_
  19349. and does not compute the polar decomposition
  19350. of a complex tensor like Python's `cmath.polar` and SciPy's `linalg.polar` do.
  19351. The behavior of this function is undefined if `abs` is negative or NaN, or if `angle` is
  19352. infinite.
  19353. Args:
  19354. abs (Tensor): The absolute value the complex tensor. Must be float or double.
  19355. angle (Tensor): The angle of the complex tensor. Must be same dtype as
  19356. :attr:`abs`.
  19357. Keyword args:
  19358. out (Tensor): If the inputs are ``torch.float32``, must be
  19359. ``torch.complex64``. If the inputs are ``torch.float64``, must be
  19360. ``torch.complex128``.
  19361. Example::
  19362. >>> import numpy as np
  19363. >>> abs = torch.tensor([1, 2], dtype=torch.float64)
  19364. >>> angle = torch.tensor([np.pi / 2, 5 * np.pi / 4], dtype=torch.float64)
  19365. >>> z = torch.polar(abs, angle)
  19366. >>> z
  19367. tensor([(0.0000+1.0000j), (-1.4142-1.4142j)], dtype=torch.complex128)
  19368. """
  19369. def polygamma(
  19370. n: _int,
  19371. input: Tensor,
  19372. *,
  19373. out: Tensor | None = None,
  19374. ) -> Tensor:
  19375. r"""
  19376. polygamma(n, input, *, out=None) -> Tensor
  19377. Alias for :func:`torch.special.polygamma`.
  19378. """
  19379. def positive(input: Tensor) -> Tensor:
  19380. r"""
  19381. positive(input) -> Tensor
  19382. Returns :attr:`input`.
  19383. Throws a runtime error if :attr:`input` is a bool tensor.
  19384. Args:
  19385. input (Tensor): the input tensor.
  19386. Example::
  19387. >>> t = torch.randn(5)
  19388. >>> t
  19389. tensor([ 0.0090, -0.2262, -0.0682, -0.2866, 0.3940])
  19390. >>> torch.positive(t)
  19391. tensor([ 0.0090, -0.2262, -0.0682, -0.2866, 0.3940])
  19392. """
  19393. @overload
  19394. def pow(
  19395. input: Tensor,
  19396. exponent: Tensor,
  19397. *,
  19398. out: Tensor | None = None,
  19399. ) -> Tensor:
  19400. r"""
  19401. pow(input, exponent, *, out=None) -> Tensor
  19402. Takes the power of each element in :attr:`input` with :attr:`exponent` and
  19403. returns a tensor with the result.
  19404. :attr:`exponent` can be either a single ``float`` number or a `Tensor`
  19405. with the same number of elements as :attr:`input`.
  19406. When :attr:`exponent` is a scalar value, the operation applied is:
  19407. .. math::
  19408. \text{out}_i = x_i ^ \text{exponent}
  19409. When :attr:`exponent` is a tensor, the operation applied is:
  19410. .. math::
  19411. \text{out}_i = x_i ^ {\text{exponent}_i}
  19412. When :attr:`exponent` is a tensor, the shapes of :attr:`input`
  19413. and :attr:`exponent` must be :ref:`broadcastable <broadcasting-semantics>`.
  19414. Args:
  19415. input (Tensor): the input tensor.
  19416. exponent (float or tensor): the exponent value
  19417. Keyword args:
  19418. out (Tensor, optional): the output tensor.
  19419. Example::
  19420. >>> a = torch.randn(4)
  19421. >>> a
  19422. tensor([ 0.4331, 1.2475, 0.6834, -0.2791])
  19423. >>> torch.pow(a, 2)
  19424. tensor([ 0.1875, 1.5561, 0.4670, 0.0779])
  19425. >>> exp = torch.arange(1., 5.)
  19426. >>> a = torch.arange(1., 5.)
  19427. >>> a
  19428. tensor([ 1., 2., 3., 4.])
  19429. >>> exp
  19430. tensor([ 1., 2., 3., 4.])
  19431. >>> torch.pow(a, exp)
  19432. tensor([ 1., 4., 27., 256.])
  19433. .. function:: pow(self, exponent, *, out=None) -> Tensor
  19434. :noindex:
  19435. :attr:`self` is a scalar ``float`` value, and :attr:`exponent` is a tensor.
  19436. The returned tensor :attr:`out` is of the same shape as :attr:`exponent`
  19437. The operation applied is:
  19438. .. math::
  19439. \text{out}_i = \text{self} ^ {\text{exponent}_i}
  19440. Args:
  19441. self (float): the scalar base value for the power operation
  19442. exponent (Tensor): the exponent tensor
  19443. Keyword args:
  19444. out (Tensor, optional): the output tensor.
  19445. Example::
  19446. >>> exp = torch.arange(1., 5.)
  19447. >>> base = 2
  19448. >>> torch.pow(base, exp)
  19449. tensor([ 2., 4., 8., 16.])
  19450. """
  19451. @overload
  19452. def pow(
  19453. self: Number | _complex,
  19454. exponent: Tensor,
  19455. *,
  19456. out: Tensor | None = None,
  19457. ) -> Tensor:
  19458. r"""
  19459. pow(input, exponent, *, out=None) -> Tensor
  19460. Takes the power of each element in :attr:`input` with :attr:`exponent` and
  19461. returns a tensor with the result.
  19462. :attr:`exponent` can be either a single ``float`` number or a `Tensor`
  19463. with the same number of elements as :attr:`input`.
  19464. When :attr:`exponent` is a scalar value, the operation applied is:
  19465. .. math::
  19466. \text{out}_i = x_i ^ \text{exponent}
  19467. When :attr:`exponent` is a tensor, the operation applied is:
  19468. .. math::
  19469. \text{out}_i = x_i ^ {\text{exponent}_i}
  19470. When :attr:`exponent` is a tensor, the shapes of :attr:`input`
  19471. and :attr:`exponent` must be :ref:`broadcastable <broadcasting-semantics>`.
  19472. Args:
  19473. input (Tensor): the input tensor.
  19474. exponent (float or tensor): the exponent value
  19475. Keyword args:
  19476. out (Tensor, optional): the output tensor.
  19477. Example::
  19478. >>> a = torch.randn(4)
  19479. >>> a
  19480. tensor([ 0.4331, 1.2475, 0.6834, -0.2791])
  19481. >>> torch.pow(a, 2)
  19482. tensor([ 0.1875, 1.5561, 0.4670, 0.0779])
  19483. >>> exp = torch.arange(1., 5.)
  19484. >>> a = torch.arange(1., 5.)
  19485. >>> a
  19486. tensor([ 1., 2., 3., 4.])
  19487. >>> exp
  19488. tensor([ 1., 2., 3., 4.])
  19489. >>> torch.pow(a, exp)
  19490. tensor([ 1., 4., 27., 256.])
  19491. .. function:: pow(self, exponent, *, out=None) -> Tensor
  19492. :noindex:
  19493. :attr:`self` is a scalar ``float`` value, and :attr:`exponent` is a tensor.
  19494. The returned tensor :attr:`out` is of the same shape as :attr:`exponent`
  19495. The operation applied is:
  19496. .. math::
  19497. \text{out}_i = \text{self} ^ {\text{exponent}_i}
  19498. Args:
  19499. self (float): the scalar base value for the power operation
  19500. exponent (Tensor): the exponent tensor
  19501. Keyword args:
  19502. out (Tensor, optional): the output tensor.
  19503. Example::
  19504. >>> exp = torch.arange(1., 5.)
  19505. >>> base = 2
  19506. >>> torch.pow(base, exp)
  19507. tensor([ 2., 4., 8., 16.])
  19508. """
  19509. @overload
  19510. def pow(
  19511. input: Tensor,
  19512. exponent: Number | _complex,
  19513. *,
  19514. out: Tensor | None = None,
  19515. ) -> Tensor:
  19516. r"""
  19517. pow(input, exponent, *, out=None) -> Tensor
  19518. Takes the power of each element in :attr:`input` with :attr:`exponent` and
  19519. returns a tensor with the result.
  19520. :attr:`exponent` can be either a single ``float`` number or a `Tensor`
  19521. with the same number of elements as :attr:`input`.
  19522. When :attr:`exponent` is a scalar value, the operation applied is:
  19523. .. math::
  19524. \text{out}_i = x_i ^ \text{exponent}
  19525. When :attr:`exponent` is a tensor, the operation applied is:
  19526. .. math::
  19527. \text{out}_i = x_i ^ {\text{exponent}_i}
  19528. When :attr:`exponent` is a tensor, the shapes of :attr:`input`
  19529. and :attr:`exponent` must be :ref:`broadcastable <broadcasting-semantics>`.
  19530. Args:
  19531. input (Tensor): the input tensor.
  19532. exponent (float or tensor): the exponent value
  19533. Keyword args:
  19534. out (Tensor, optional): the output tensor.
  19535. Example::
  19536. >>> a = torch.randn(4)
  19537. >>> a
  19538. tensor([ 0.4331, 1.2475, 0.6834, -0.2791])
  19539. >>> torch.pow(a, 2)
  19540. tensor([ 0.1875, 1.5561, 0.4670, 0.0779])
  19541. >>> exp = torch.arange(1., 5.)
  19542. >>> a = torch.arange(1., 5.)
  19543. >>> a
  19544. tensor([ 1., 2., 3., 4.])
  19545. >>> exp
  19546. tensor([ 1., 2., 3., 4.])
  19547. >>> torch.pow(a, exp)
  19548. tensor([ 1., 4., 27., 256.])
  19549. .. function:: pow(self, exponent, *, out=None) -> Tensor
  19550. :noindex:
  19551. :attr:`self` is a scalar ``float`` value, and :attr:`exponent` is a tensor.
  19552. The returned tensor :attr:`out` is of the same shape as :attr:`exponent`
  19553. The operation applied is:
  19554. .. math::
  19555. \text{out}_i = \text{self} ^ {\text{exponent}_i}
  19556. Args:
  19557. self (float): the scalar base value for the power operation
  19558. exponent (Tensor): the exponent tensor
  19559. Keyword args:
  19560. out (Tensor, optional): the output tensor.
  19561. Example::
  19562. >>> exp = torch.arange(1., 5.)
  19563. >>> base = 2
  19564. >>> torch.pow(base, exp)
  19565. tensor([ 2., 4., 8., 16.])
  19566. """
  19567. def prelu(input: Tensor, weight: Tensor) -> Tensor: ...
  19568. @overload
  19569. def prod(input: Tensor, *, dtype: _dtype | None = None) -> Tensor:
  19570. r"""
  19571. prod(input: Tensor, *, dtype: Optional[_dtype]) -> Tensor
  19572. Returns the product of all elements in the :attr:`input` tensor.
  19573. Args:
  19574. input (Tensor): the input tensor.
  19575. Keyword args:
  19576. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19577. If specified, the input tensor is casted to :attr:`dtype` before the operation
  19578. is performed. This is useful for preventing data type overflows. Default: None.
  19579. Example::
  19580. >>> a = torch.randn(1, 3)
  19581. >>> a
  19582. tensor([[-0.8020, 0.5428, -1.5854]])
  19583. >>> torch.prod(a)
  19584. tensor(0.6902)
  19585. .. function:: prod(input, dim, keepdim=False, *, dtype=None) -> Tensor
  19586. :noindex:
  19587. Returns the product of each row of the :attr:`input` tensor in the given
  19588. dimension :attr:`dim`.
  19589. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  19590. as :attr:`input` except in the dimension :attr:`dim` where it is of size 1.
  19591. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  19592. the output tensor having 1 fewer dimension than :attr:`input`.
  19593. Args:
  19594. input (Tensor): the input tensor.
  19595. dim (int, optional): the dimension to reduce.
  19596. If ``None``, all dimensions are reduced.
  19597. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  19598. Keyword args:
  19599. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19600. If specified, the input tensor is casted to :attr:`dtype` before the operation
  19601. is performed. This is useful for preventing data type overflows. Default: None.
  19602. Example::
  19603. >>> a = torch.randn(4, 2)
  19604. >>> a
  19605. tensor([[ 0.5261, -0.3837],
  19606. [ 1.1857, -0.2498],
  19607. [-1.1646, 0.0705],
  19608. [ 1.1131, -1.0629]])
  19609. >>> torch.prod(a, 1)
  19610. tensor([-0.2018, -0.2962, -0.0821, -1.1831])
  19611. """
  19612. @overload
  19613. def prod(
  19614. input: Tensor,
  19615. dim: _int,
  19616. keepdim: _bool = False,
  19617. *,
  19618. dtype: _dtype | None = None,
  19619. out: Tensor | None = None,
  19620. ) -> Tensor:
  19621. r"""
  19622. prod(input: Tensor, *, dtype: Optional[_dtype]) -> Tensor
  19623. Returns the product of all elements in the :attr:`input` tensor.
  19624. Args:
  19625. input (Tensor): the input tensor.
  19626. Keyword args:
  19627. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19628. If specified, the input tensor is casted to :attr:`dtype` before the operation
  19629. is performed. This is useful for preventing data type overflows. Default: None.
  19630. Example::
  19631. >>> a = torch.randn(1, 3)
  19632. >>> a
  19633. tensor([[-0.8020, 0.5428, -1.5854]])
  19634. >>> torch.prod(a)
  19635. tensor(0.6902)
  19636. .. function:: prod(input, dim, keepdim=False, *, dtype=None) -> Tensor
  19637. :noindex:
  19638. Returns the product of each row of the :attr:`input` tensor in the given
  19639. dimension :attr:`dim`.
  19640. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  19641. as :attr:`input` except in the dimension :attr:`dim` where it is of size 1.
  19642. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  19643. the output tensor having 1 fewer dimension than :attr:`input`.
  19644. Args:
  19645. input (Tensor): the input tensor.
  19646. dim (int, optional): the dimension to reduce.
  19647. If ``None``, all dimensions are reduced.
  19648. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  19649. Keyword args:
  19650. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19651. If specified, the input tensor is casted to :attr:`dtype` before the operation
  19652. is performed. This is useful for preventing data type overflows. Default: None.
  19653. Example::
  19654. >>> a = torch.randn(4, 2)
  19655. >>> a
  19656. tensor([[ 0.5261, -0.3837],
  19657. [ 1.1857, -0.2498],
  19658. [-1.1646, 0.0705],
  19659. [ 1.1131, -1.0629]])
  19660. >>> torch.prod(a, 1)
  19661. tensor([-0.2018, -0.2962, -0.0821, -1.1831])
  19662. """
  19663. @overload
  19664. def prod(
  19665. input: Tensor,
  19666. dim: str | EllipsisType | None,
  19667. keepdim: _bool = False,
  19668. *,
  19669. dtype: _dtype | None = None,
  19670. out: Tensor | None = None,
  19671. ) -> Tensor:
  19672. r"""
  19673. prod(input: Tensor, *, dtype: Optional[_dtype]) -> Tensor
  19674. Returns the product of all elements in the :attr:`input` tensor.
  19675. Args:
  19676. input (Tensor): the input tensor.
  19677. Keyword args:
  19678. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19679. If specified, the input tensor is casted to :attr:`dtype` before the operation
  19680. is performed. This is useful for preventing data type overflows. Default: None.
  19681. Example::
  19682. >>> a = torch.randn(1, 3)
  19683. >>> a
  19684. tensor([[-0.8020, 0.5428, -1.5854]])
  19685. >>> torch.prod(a)
  19686. tensor(0.6902)
  19687. .. function:: prod(input, dim, keepdim=False, *, dtype=None) -> Tensor
  19688. :noindex:
  19689. Returns the product of each row of the :attr:`input` tensor in the given
  19690. dimension :attr:`dim`.
  19691. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  19692. as :attr:`input` except in the dimension :attr:`dim` where it is of size 1.
  19693. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  19694. the output tensor having 1 fewer dimension than :attr:`input`.
  19695. Args:
  19696. input (Tensor): the input tensor.
  19697. dim (int, optional): the dimension to reduce.
  19698. If ``None``, all dimensions are reduced.
  19699. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  19700. Keyword args:
  19701. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19702. If specified, the input tensor is casted to :attr:`dtype` before the operation
  19703. is performed. This is useful for preventing data type overflows. Default: None.
  19704. Example::
  19705. >>> a = torch.randn(4, 2)
  19706. >>> a
  19707. tensor([[ 0.5261, -0.3837],
  19708. [ 1.1857, -0.2498],
  19709. [-1.1646, 0.0705],
  19710. [ 1.1131, -1.0629]])
  19711. >>> torch.prod(a, 1)
  19712. tensor([-0.2018, -0.2962, -0.0821, -1.1831])
  19713. """
  19714. def promote_types(type1: _dtype, type2: _dtype) -> _dtype:
  19715. r"""
  19716. promote_types(type1, type2) -> dtype
  19717. Returns the :class:`torch.dtype` with the smallest size and scalar kind that is
  19718. not smaller nor of lower kind than either `type1` or `type2`. See type promotion
  19719. :ref:`documentation <type-promotion-doc>` for more information on the type
  19720. promotion logic.
  19721. Args:
  19722. type1 (:class:`torch.dtype`)
  19723. type2 (:class:`torch.dtype`)
  19724. Example::
  19725. >>> torch.promote_types(torch.int32, torch.float32)
  19726. torch.float32
  19727. >>> torch.promote_types(torch.uint8, torch.long)
  19728. torch.long
  19729. """
  19730. def put(
  19731. input: Tensor,
  19732. index: Tensor,
  19733. source: Tensor,
  19734. accumulate: _bool = False,
  19735. ) -> Tensor: ...
  19736. def q_per_channel_axis(input: Tensor) -> _int: ...
  19737. def q_per_channel_scales(input: Tensor) -> Tensor: ...
  19738. def q_per_channel_zero_points(input: Tensor) -> Tensor: ...
  19739. def q_scale(input: Tensor) -> _float: ...
  19740. def q_zero_point(input: Tensor) -> _int: ...
  19741. def qr(
  19742. input: Tensor,
  19743. some: _bool = True,
  19744. *,
  19745. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  19746. ) -> torch.return_types.qr:
  19747. r"""
  19748. qr(input: Tensor, some: bool = True, *, out: Union[Tensor, Tuple[Tensor, ...], List[Tensor], None]) -> (Tensor, Tensor)
  19749. Computes the QR decomposition of a matrix or a batch of matrices :attr:`input`,
  19750. and returns a namedtuple (Q, R) of tensors such that :math:`\text{input} = Q R`
  19751. with :math:`Q` being an orthogonal matrix or batch of orthogonal matrices and
  19752. :math:`R` being an upper triangular matrix or batch of upper triangular matrices.
  19753. If :attr:`some` is ``True``, then this function returns the thin (reduced) QR factorization.
  19754. Otherwise, if :attr:`some` is ``False``, this function returns the complete QR factorization.
  19755. .. warning::
  19756. :func:`torch.qr` is deprecated in favor of :func:`torch.linalg.qr`
  19757. and will be removed in a future PyTorch release. The boolean parameter :attr:`some` has been
  19758. replaced with a string parameter :attr:`mode`.
  19759. ``Q, R = torch.qr(A)`` should be replaced with
  19760. .. code:: python
  19761. Q, R = torch.linalg.qr(A)
  19762. ``Q, R = torch.qr(A, some=False)`` should be replaced with
  19763. .. code:: python
  19764. Q, R = torch.linalg.qr(A, mode="complete")
  19765. .. warning::
  19766. If you plan to backpropagate through QR, note that the current backward implementation
  19767. is only well-defined when the first :math:`\min(input.size(-1), input.size(-2))`
  19768. columns of :attr:`input` are linearly independent.
  19769. This behavior will probably change once QR supports pivoting.
  19770. .. note:: This function uses LAPACK for CPU inputs and MAGMA for CUDA inputs,
  19771. and may produce different (valid) decompositions on different device types
  19772. or different platforms.
  19773. Args:
  19774. input (Tensor): the input tensor of size :math:`(*, m, n)` where `*` is zero or more
  19775. batch dimensions consisting of matrices of dimension :math:`m \times n`.
  19776. some (bool, optional): Set to ``True`` for reduced QR decomposition and ``False`` for
  19777. complete QR decomposition. If `k = min(m, n)` then:
  19778. * ``some=True`` : returns `(Q, R)` with dimensions (m, k), (k, n) (default)
  19779. * ``'some=False'``: returns `(Q, R)` with dimensions (m, m), (m, n)
  19780. Keyword args:
  19781. out (tuple, optional): tuple of `Q` and `R` tensors.
  19782. The dimensions of `Q` and `R` are detailed in the description of :attr:`some` above.
  19783. Example::
  19784. >>> a = torch.tensor([[12., -51, 4], [6, 167, -68], [-4, 24, -41]])
  19785. >>> q, r = torch.qr(a)
  19786. >>> q
  19787. tensor([[-0.8571, 0.3943, 0.3314],
  19788. [-0.4286, -0.9029, -0.0343],
  19789. [ 0.2857, -0.1714, 0.9429]])
  19790. >>> r
  19791. tensor([[ -14.0000, -21.0000, 14.0000],
  19792. [ 0.0000, -175.0000, 70.0000],
  19793. [ 0.0000, 0.0000, -35.0000]])
  19794. >>> torch.mm(q, r).round()
  19795. tensor([[ 12., -51., 4.],
  19796. [ 6., 167., -68.],
  19797. [ -4., 24., -41.]])
  19798. >>> torch.mm(q.t(), q).round()
  19799. tensor([[ 1., 0., 0.],
  19800. [ 0., 1., -0.],
  19801. [ 0., -0., 1.]])
  19802. >>> a = torch.randn(3, 4, 5)
  19803. >>> q, r = torch.qr(a, some=False)
  19804. >>> torch.allclose(torch.matmul(q, r), a)
  19805. True
  19806. >>> torch.allclose(torch.matmul(q.mT, q), torch.eye(5))
  19807. True
  19808. """
  19809. @overload
  19810. def quantile(
  19811. input: Tensor,
  19812. q: Tensor,
  19813. dim: _int | None = None,
  19814. keepdim: _bool = False,
  19815. *,
  19816. interpolation: str = "linear",
  19817. out: Tensor | None = None,
  19818. ) -> Tensor:
  19819. r"""
  19820. quantile(input, q, dim=None, keepdim=False, *, interpolation='linear', out=None) -> Tensor
  19821. Computes the q-th quantiles of each row of the :attr:`input` tensor along the dimension :attr:`dim`.
  19822. To compute the quantile, we map q in [0, 1] to the range of indices [0, n] to find the location
  19823. of the quantile in the sorted input. If the quantile lies between two data points ``a < b`` with
  19824. indices ``i`` and ``j`` in the sorted order, result is computed according to the given
  19825. :attr:`interpolation` method as follows:
  19826. - ``linear``: ``a + (b - a) * fraction``, where ``fraction`` is the fractional part of the computed quantile index.
  19827. - ``lower``: ``a``.
  19828. - ``higher``: ``b``.
  19829. - ``nearest``: ``a`` or ``b``, whichever's index is closer to the computed quantile index (follows :func:`torch.round`).
  19830. - ``midpoint``: ``(a + b) / 2``.
  19831. If :attr:`q` is a 1D tensor, the first dimension of the output represents the quantiles and has size
  19832. equal to the size of :attr:`q`, the remaining dimensions are what remains from the reduction.
  19833. .. note::
  19834. By default :attr:`dim` is ``None`` resulting in the :attr:`input` tensor being flattened before computation.
  19835. Args:
  19836. input (Tensor): the input tensor.
  19837. q (float or Tensor): a scalar or 1D tensor of values in the range [0, 1].
  19838. dim (int, optional): the dimension to reduce.
  19839. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  19840. Keyword arguments:
  19841. interpolation (str, optional): interpolation method to use when the desired quantile lies between two data points.
  19842. Can be ``linear``, ``lower``, ``higher``, ``midpoint`` and ``nearest``.
  19843. Default is ``linear``.
  19844. out (Tensor, optional): the output tensor.
  19845. Example::
  19846. >>> a = torch.randn(2, 3)
  19847. >>> a
  19848. tensor([[ 0.0795, -1.2117, 0.9765],
  19849. [ 1.1707, 0.6706, 0.4884]])
  19850. >>> q = torch.tensor([0.25, 0.5, 0.75])
  19851. >>> torch.quantile(a, q, dim=1, keepdim=True)
  19852. tensor([[[-0.5661],
  19853. [ 0.5795]],
  19854. [[ 0.0795],
  19855. [ 0.6706]],
  19856. [[ 0.5280],
  19857. [ 0.9206]]])
  19858. >>> torch.quantile(a, q, dim=1, keepdim=True).shape
  19859. torch.Size([3, 2, 1])
  19860. >>> a = torch.arange(4.)
  19861. >>> a
  19862. tensor([0., 1., 2., 3.])
  19863. >>> torch.quantile(a, 0.6, interpolation='linear')
  19864. tensor(1.8000)
  19865. >>> torch.quantile(a, 0.6, interpolation='lower')
  19866. tensor(1.)
  19867. >>> torch.quantile(a, 0.6, interpolation='higher')
  19868. tensor(2.)
  19869. >>> torch.quantile(a, 0.6, interpolation='midpoint')
  19870. tensor(1.5000)
  19871. >>> torch.quantile(a, 0.6, interpolation='nearest')
  19872. tensor(2.)
  19873. >>> torch.quantile(a, 0.4, interpolation='nearest')
  19874. tensor(1.)
  19875. """
  19876. @overload
  19877. def quantile(
  19878. input: Tensor,
  19879. q: _float,
  19880. dim: _int | None = None,
  19881. keepdim: _bool = False,
  19882. *,
  19883. interpolation: str = "linear",
  19884. out: Tensor | None = None,
  19885. ) -> Tensor:
  19886. r"""
  19887. quantile(input, q, dim=None, keepdim=False, *, interpolation='linear', out=None) -> Tensor
  19888. Computes the q-th quantiles of each row of the :attr:`input` tensor along the dimension :attr:`dim`.
  19889. To compute the quantile, we map q in [0, 1] to the range of indices [0, n] to find the location
  19890. of the quantile in the sorted input. If the quantile lies between two data points ``a < b`` with
  19891. indices ``i`` and ``j`` in the sorted order, result is computed according to the given
  19892. :attr:`interpolation` method as follows:
  19893. - ``linear``: ``a + (b - a) * fraction``, where ``fraction`` is the fractional part of the computed quantile index.
  19894. - ``lower``: ``a``.
  19895. - ``higher``: ``b``.
  19896. - ``nearest``: ``a`` or ``b``, whichever's index is closer to the computed quantile index (follows :func:`torch.round`).
  19897. - ``midpoint``: ``(a + b) / 2``.
  19898. If :attr:`q` is a 1D tensor, the first dimension of the output represents the quantiles and has size
  19899. equal to the size of :attr:`q`, the remaining dimensions are what remains from the reduction.
  19900. .. note::
  19901. By default :attr:`dim` is ``None`` resulting in the :attr:`input` tensor being flattened before computation.
  19902. Args:
  19903. input (Tensor): the input tensor.
  19904. q (float or Tensor): a scalar or 1D tensor of values in the range [0, 1].
  19905. dim (int, optional): the dimension to reduce.
  19906. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  19907. Keyword arguments:
  19908. interpolation (str, optional): interpolation method to use when the desired quantile lies between two data points.
  19909. Can be ``linear``, ``lower``, ``higher``, ``midpoint`` and ``nearest``.
  19910. Default is ``linear``.
  19911. out (Tensor, optional): the output tensor.
  19912. Example::
  19913. >>> a = torch.randn(2, 3)
  19914. >>> a
  19915. tensor([[ 0.0795, -1.2117, 0.9765],
  19916. [ 1.1707, 0.6706, 0.4884]])
  19917. >>> q = torch.tensor([0.25, 0.5, 0.75])
  19918. >>> torch.quantile(a, q, dim=1, keepdim=True)
  19919. tensor([[[-0.5661],
  19920. [ 0.5795]],
  19921. [[ 0.0795],
  19922. [ 0.6706]],
  19923. [[ 0.5280],
  19924. [ 0.9206]]])
  19925. >>> torch.quantile(a, q, dim=1, keepdim=True).shape
  19926. torch.Size([3, 2, 1])
  19927. >>> a = torch.arange(4.)
  19928. >>> a
  19929. tensor([0., 1., 2., 3.])
  19930. >>> torch.quantile(a, 0.6, interpolation='linear')
  19931. tensor(1.8000)
  19932. >>> torch.quantile(a, 0.6, interpolation='lower')
  19933. tensor(1.)
  19934. >>> torch.quantile(a, 0.6, interpolation='higher')
  19935. tensor(2.)
  19936. >>> torch.quantile(a, 0.6, interpolation='midpoint')
  19937. tensor(1.5000)
  19938. >>> torch.quantile(a, 0.6, interpolation='nearest')
  19939. tensor(2.)
  19940. >>> torch.quantile(a, 0.4, interpolation='nearest')
  19941. tensor(1.)
  19942. """
  19943. def quantize_per_channel(
  19944. input: Tensor,
  19945. scales: Tensor,
  19946. zero_points: Tensor,
  19947. axis: _int,
  19948. dtype: _dtype,
  19949. ) -> Tensor:
  19950. r"""
  19951. quantize_per_channel(input, scales, zero_points, axis, dtype) -> Tensor
  19952. Converts a float tensor to a per-channel quantized tensor with given scales and zero points.
  19953. Arguments:
  19954. input (Tensor): float tensor to quantize
  19955. scales (Tensor): float 1D tensor of scales to use, size should match ``input.size(axis)``
  19956. zero_points (int): integer 1D tensor of offset to use, size should match ``input.size(axis)``
  19957. axis (int): dimension on which apply per-channel quantization
  19958. dtype (:class:`torch.dtype`): the desired data type of returned tensor.
  19959. Has to be one of the quantized dtypes: ``torch.quint8``, ``torch.qint8``, ``torch.qint32``
  19960. Returns:
  19961. Tensor: A newly quantized tensor
  19962. Example::
  19963. >>> x = torch.tensor([[-1.0, 0.0], [1.0, 2.0]])
  19964. >>> torch.quantize_per_channel(x, torch.tensor([0.1, 0.01]), torch.tensor([10, 0]), 0, torch.quint8)
  19965. tensor([[-1., 0.],
  19966. [ 1., 2.]], size=(2, 2), dtype=torch.quint8,
  19967. quantization_scheme=torch.per_channel_affine,
  19968. scale=tensor([0.1000, 0.0100], dtype=torch.float64),
  19969. zero_point=tensor([10, 0]), axis=0)
  19970. >>> torch.quantize_per_channel(x, torch.tensor([0.1, 0.01]), torch.tensor([10, 0]), 0, torch.quint8).int_repr()
  19971. tensor([[ 0, 10],
  19972. [100, 200]], dtype=torch.uint8)
  19973. """
  19974. @overload
  19975. def quantize_per_tensor(
  19976. input: Tensor,
  19977. scale: Tensor,
  19978. zero_point: Tensor,
  19979. dtype: _dtype,
  19980. ) -> Tensor:
  19981. r"""
  19982. quantize_per_tensor(input, scale, zero_point, dtype) -> Tensor
  19983. Converts a float tensor to a quantized tensor with given scale and zero point.
  19984. Arguments:
  19985. input (Tensor): float tensor or list of tensors to quantize
  19986. scale (float or Tensor): scale to apply in quantization formula
  19987. zero_point (int or Tensor): offset in integer value that maps to float zero
  19988. dtype (:class:`torch.dtype`): the desired data type of returned tensor.
  19989. Has to be one of the quantized dtypes: ``torch.quint8``, ``torch.qint8``, ``torch.qint32``
  19990. Returns:
  19991. Tensor: A newly quantized tensor or list of quantized tensors.
  19992. Example::
  19993. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8)
  19994. tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
  19995. quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10)
  19996. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8).int_repr()
  19997. tensor([ 0, 10, 20, 30], dtype=torch.uint8)
  19998. >>> torch.quantize_per_tensor([torch.tensor([-1.0, 0.0]), torch.tensor([-2.0, 2.0])],
  19999. >>> torch.tensor([0.1, 0.2]), torch.tensor([10, 20]), torch.quint8)
  20000. (tensor([-1., 0.], size=(2,), dtype=torch.quint8,
  20001. quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10),
  20002. tensor([-2., 2.], size=(2,), dtype=torch.quint8,
  20003. quantization_scheme=torch.per_tensor_affine, scale=0.2, zero_point=20))
  20004. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), torch.tensor(0.1), torch.tensor(10), torch.quint8)
  20005. tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
  20006. quantization_scheme=torch.per_tensor_affine, scale=0.10, zero_point=10)
  20007. """
  20008. @overload
  20009. def quantize_per_tensor(
  20010. input: Tensor,
  20011. scale: _float,
  20012. zero_point: _int,
  20013. dtype: _dtype,
  20014. ) -> Tensor:
  20015. r"""
  20016. quantize_per_tensor(input, scale, zero_point, dtype) -> Tensor
  20017. Converts a float tensor to a quantized tensor with given scale and zero point.
  20018. Arguments:
  20019. input (Tensor): float tensor or list of tensors to quantize
  20020. scale (float or Tensor): scale to apply in quantization formula
  20021. zero_point (int or Tensor): offset in integer value that maps to float zero
  20022. dtype (:class:`torch.dtype`): the desired data type of returned tensor.
  20023. Has to be one of the quantized dtypes: ``torch.quint8``, ``torch.qint8``, ``torch.qint32``
  20024. Returns:
  20025. Tensor: A newly quantized tensor or list of quantized tensors.
  20026. Example::
  20027. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8)
  20028. tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
  20029. quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10)
  20030. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8).int_repr()
  20031. tensor([ 0, 10, 20, 30], dtype=torch.uint8)
  20032. >>> torch.quantize_per_tensor([torch.tensor([-1.0, 0.0]), torch.tensor([-2.0, 2.0])],
  20033. >>> torch.tensor([0.1, 0.2]), torch.tensor([10, 20]), torch.quint8)
  20034. (tensor([-1., 0.], size=(2,), dtype=torch.quint8,
  20035. quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10),
  20036. tensor([-2., 2.], size=(2,), dtype=torch.quint8,
  20037. quantization_scheme=torch.per_tensor_affine, scale=0.2, zero_point=20))
  20038. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), torch.tensor(0.1), torch.tensor(10), torch.quint8)
  20039. tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
  20040. quantization_scheme=torch.per_tensor_affine, scale=0.10, zero_point=10)
  20041. """
  20042. @overload
  20043. def quantize_per_tensor(
  20044. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  20045. scales: Tensor,
  20046. zero_points: Tensor,
  20047. dtype: _dtype,
  20048. ) -> tuple[Tensor, ...]:
  20049. r"""
  20050. quantize_per_tensor(input, scale, zero_point, dtype) -> Tensor
  20051. Converts a float tensor to a quantized tensor with given scale and zero point.
  20052. Arguments:
  20053. input (Tensor): float tensor or list of tensors to quantize
  20054. scale (float or Tensor): scale to apply in quantization formula
  20055. zero_point (int or Tensor): offset in integer value that maps to float zero
  20056. dtype (:class:`torch.dtype`): the desired data type of returned tensor.
  20057. Has to be one of the quantized dtypes: ``torch.quint8``, ``torch.qint8``, ``torch.qint32``
  20058. Returns:
  20059. Tensor: A newly quantized tensor or list of quantized tensors.
  20060. Example::
  20061. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8)
  20062. tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
  20063. quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10)
  20064. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8).int_repr()
  20065. tensor([ 0, 10, 20, 30], dtype=torch.uint8)
  20066. >>> torch.quantize_per_tensor([torch.tensor([-1.0, 0.0]), torch.tensor([-2.0, 2.0])],
  20067. >>> torch.tensor([0.1, 0.2]), torch.tensor([10, 20]), torch.quint8)
  20068. (tensor([-1., 0.], size=(2,), dtype=torch.quint8,
  20069. quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10),
  20070. tensor([-2., 2.], size=(2,), dtype=torch.quint8,
  20071. quantization_scheme=torch.per_tensor_affine, scale=0.2, zero_point=20))
  20072. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), torch.tensor(0.1), torch.tensor(10), torch.quint8)
  20073. tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
  20074. quantization_scheme=torch.per_tensor_affine, scale=0.10, zero_point=10)
  20075. """
  20076. def quantize_per_tensor_dynamic(
  20077. input: Tensor,
  20078. dtype: _dtype,
  20079. reduce_range: _bool,
  20080. ) -> Tensor:
  20081. r"""
  20082. quantize_per_tensor_dynamic(input, dtype, reduce_range) -> Tensor
  20083. Converts a float tensor to a quantized tensor with scale and zero_point calculated
  20084. dynamically based on the input.
  20085. Arguments:
  20086. input (Tensor): float tensor or list of tensors to quantize
  20087. dtype (:class:`torch.dtype`): the desired data type of returned tensor.
  20088. Has to be one of the quantized dtypes: ``torch.quint8``, ``torch.qint8``
  20089. reduce_range (bool): a flag to indicate whether to reduce the range of quantized
  20090. data by 1 bit, it's required to avoid instruction overflow for some hardwares
  20091. Returns:
  20092. Tensor: A newly (dynamically) quantized tensor
  20093. Example::
  20094. >>> t = torch.quantize_per_tensor_dynamic(torch.tensor([-1.0, 0.0, 1.0, 2.0]), torch.quint8, False)
  20095. >>> print(t)
  20096. tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
  20097. quantization_scheme=torch.per_tensor_affine, scale=0.011764705882352941,
  20098. zero_point=85)
  20099. >>> t.int_repr()
  20100. tensor([ 0, 85, 170, 255], dtype=torch.uint8)
  20101. """
  20102. def quantized_batch_norm(
  20103. input: Tensor,
  20104. weight: Tensor | None,
  20105. bias: Tensor | None,
  20106. mean: Tensor,
  20107. var: Tensor,
  20108. eps: _float,
  20109. output_scale: _float,
  20110. output_zero_point: _int,
  20111. ) -> Tensor:
  20112. r"""
  20113. quantized_batch_norm(input, weight=None, bias=None, mean, var, eps, output_scale, output_zero_point) -> Tensor
  20114. Applies batch normalization on a 4D (NCHW) quantized tensor.
  20115. .. math::
  20116. y = \frac{x - \mathrm{E}[x]}{\sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta
  20117. Arguments:
  20118. input (Tensor): quantized tensor
  20119. weight (Tensor): float tensor that corresponds to the gamma, size C
  20120. bias (Tensor): float tensor that corresponds to the beta, size C
  20121. mean (Tensor): float mean value in batch normalization, size C
  20122. var (Tensor): float tensor for variance, size C
  20123. eps (float): a value added to the denominator for numerical stability.
  20124. output_scale (float): output quantized tensor scale
  20125. output_zero_point (int): output quantized tensor zero_point
  20126. Returns:
  20127. Tensor: A quantized tensor with batch normalization applied.
  20128. Example::
  20129. >>> qx = torch.quantize_per_tensor(torch.rand(2, 2, 2, 2), 1.5, 3, torch.quint8)
  20130. >>> torch.quantized_batch_norm(qx, torch.ones(2), torch.zeros(2), torch.rand(2), torch.rand(2), 0.00001, 0.2, 2)
  20131. tensor([[[[-0.2000, -0.2000],
  20132. [ 1.6000, -0.2000]],
  20133. [[-0.4000, -0.4000],
  20134. [-0.4000, 0.6000]]],
  20135. [[[-0.2000, -0.2000],
  20136. [-0.2000, -0.2000]],
  20137. [[ 0.6000, -0.4000],
  20138. [ 0.6000, -0.4000]]]], size=(2, 2, 2, 2), dtype=torch.quint8,
  20139. quantization_scheme=torch.per_tensor_affine, scale=0.2, zero_point=2)
  20140. """
  20141. def quantized_gru_cell(
  20142. input: Tensor,
  20143. hx: Tensor,
  20144. w_ih: Tensor,
  20145. w_hh: Tensor,
  20146. b_ih: Tensor,
  20147. b_hh: Tensor,
  20148. packed_ih: Tensor,
  20149. packed_hh: Tensor,
  20150. col_offsets_ih: Tensor,
  20151. col_offsets_hh: Tensor,
  20152. scale_ih: Number | _complex,
  20153. scale_hh: Number | _complex,
  20154. zero_point_ih: Number | _complex,
  20155. zero_point_hh: Number | _complex,
  20156. ) -> Tensor: ...
  20157. def quantized_lstm_cell(
  20158. input: Tensor,
  20159. hx: tuple[Tensor, ...] | list[Tensor] | None,
  20160. w_ih: Tensor,
  20161. w_hh: Tensor,
  20162. b_ih: Tensor,
  20163. b_hh: Tensor,
  20164. packed_ih: Tensor,
  20165. packed_hh: Tensor,
  20166. col_offsets_ih: Tensor,
  20167. col_offsets_hh: Tensor,
  20168. scale_ih: Number | _complex,
  20169. scale_hh: Number | _complex,
  20170. zero_point_ih: Number | _complex,
  20171. zero_point_hh: Number | _complex,
  20172. ) -> tuple[Tensor, Tensor]: ...
  20173. def quantized_max_pool1d(
  20174. input: Tensor,
  20175. kernel_size: _int | _size,
  20176. stride: _int | _size = (),
  20177. padding: _int | _size = 0,
  20178. dilation: _int | _size = 1,
  20179. ceil_mode: _bool = False,
  20180. ) -> Tensor:
  20181. r"""
  20182. quantized_max_pool1d(input, kernel_size, stride=[], padding=0, dilation=1, ceil_mode=False) -> Tensor
  20183. Applies a 1D max pooling over an input quantized tensor composed of several input planes.
  20184. Arguments:
  20185. input (Tensor): quantized tensor
  20186. kernel_size (list of int): the size of the sliding window
  20187. stride (``list of int``, optional): the stride of the sliding window
  20188. padding (``list of int``, optional): padding to be added on both sides, must be >= 0 and <= kernel_size / 2
  20189. dilation (``list of int``, optional): The stride between elements within a sliding window, must be > 0. Default 1
  20190. ceil_mode (bool, optional): If True, will use ceil instead of floor to compute the output shape.
  20191. Defaults to False.
  20192. Returns:
  20193. Tensor: A quantized tensor with max_pool1d applied.
  20194. Example::
  20195. >>> qx = torch.quantize_per_tensor(torch.rand(2, 2), 1.5, 3, torch.quint8)
  20196. >>> torch.quantized_max_pool1d(qx, [2])
  20197. tensor([[0.0000],
  20198. [1.5000]], size=(2, 1), dtype=torch.quint8,
  20199. quantization_scheme=torch.per_tensor_affine, scale=1.5, zero_point=3)
  20200. """
  20201. def quantized_max_pool2d(
  20202. input: Tensor,
  20203. kernel_size: _int | _size,
  20204. stride: _int | _size = (),
  20205. padding: _int | _size = 0,
  20206. dilation: _int | _size = 1,
  20207. ceil_mode: _bool = False,
  20208. ) -> Tensor:
  20209. r"""
  20210. quantized_max_pool2d(input, kernel_size, stride=[], padding=0, dilation=1, ceil_mode=False) -> Tensor
  20211. Applies a 2D max pooling over an input quantized tensor composed of several input planes.
  20212. Arguments:
  20213. input (Tensor): quantized tensor
  20214. kernel_size (``list of int``): the size of the sliding window
  20215. stride (``list of int``, optional): the stride of the sliding window
  20216. padding (``list of int``, optional): padding to be added on both sides, must be >= 0 and <= kernel_size / 2
  20217. dilation (``list of int``, optional): The stride between elements within a sliding window, must be > 0. Default 1
  20218. ceil_mode (bool, optional): If True, will use ceil instead of floor to compute the output shape.
  20219. Defaults to False.
  20220. Returns:
  20221. Tensor: A quantized tensor with max_pool2d applied.
  20222. Example::
  20223. >>> qx = torch.quantize_per_tensor(torch.rand(2, 2, 2, 2), 1.5, 3, torch.quint8)
  20224. >>> torch.quantized_max_pool2d(qx, [2,2])
  20225. tensor([[[[1.5000]],
  20226. [[1.5000]]],
  20227. [[[0.0000]],
  20228. [[0.0000]]]], size=(2, 2, 1, 1), dtype=torch.quint8,
  20229. quantization_scheme=torch.per_tensor_affine, scale=1.5, zero_point=3)
  20230. """
  20231. def quantized_max_pool3d(
  20232. input: Tensor,
  20233. kernel_size: _int | _size,
  20234. stride: _int | _size = (),
  20235. padding: _int | _size = 0,
  20236. dilation: _int | _size = 1,
  20237. ceil_mode: _bool = False,
  20238. ) -> Tensor: ...
  20239. def quantized_rnn_relu_cell(
  20240. input: Tensor,
  20241. hx: Tensor,
  20242. w_ih: Tensor,
  20243. w_hh: Tensor,
  20244. b_ih: Tensor,
  20245. b_hh: Tensor,
  20246. packed_ih: Tensor,
  20247. packed_hh: Tensor,
  20248. col_offsets_ih: Tensor,
  20249. col_offsets_hh: Tensor,
  20250. scale_ih: Number | _complex,
  20251. scale_hh: Number | _complex,
  20252. zero_point_ih: Number | _complex,
  20253. zero_point_hh: Number | _complex,
  20254. ) -> Tensor: ...
  20255. def quantized_rnn_tanh_cell(
  20256. input: Tensor,
  20257. hx: Tensor,
  20258. w_ih: Tensor,
  20259. w_hh: Tensor,
  20260. b_ih: Tensor,
  20261. b_hh: Tensor,
  20262. packed_ih: Tensor,
  20263. packed_hh: Tensor,
  20264. col_offsets_ih: Tensor,
  20265. col_offsets_hh: Tensor,
  20266. scale_ih: Number | _complex,
  20267. scale_hh: Number | _complex,
  20268. zero_point_ih: Number | _complex,
  20269. zero_point_hh: Number | _complex,
  20270. ) -> Tensor: ...
  20271. def rad2deg(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  20272. r"""
  20273. rad2deg(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  20274. Returns a new tensor with each of the elements of :attr:`input`
  20275. converted from angles in radians to degrees.
  20276. Args:
  20277. input (Tensor): the input tensor.
  20278. Keyword arguments:
  20279. out (Tensor, optional): the output tensor.
  20280. Example::
  20281. >>> a = torch.tensor([[3.142, -3.142], [6.283, -6.283], [1.570, -1.570]])
  20282. >>> torch.rad2deg(a)
  20283. tensor([[ 180.0233, -180.0233],
  20284. [ 359.9894, -359.9894],
  20285. [ 89.9544, -89.9544]])
  20286. """
  20287. def rad2deg_(input: Tensor) -> Tensor: ...
  20288. @overload
  20289. def rand(
  20290. size: Sequence[_int | SymInt],
  20291. *,
  20292. generator: Generator | None,
  20293. names: Sequence[str | EllipsisType | None] | None,
  20294. dtype: _dtype | None = None,
  20295. layout: _layout | None = None,
  20296. device: DeviceLikeType | None = None,
  20297. pin_memory: _bool | None = False,
  20298. requires_grad: _bool | None = False,
  20299. ) -> Tensor:
  20300. r"""
  20301. rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  20302. Returns a tensor filled with random numbers from a uniform distribution
  20303. on the interval :math:`[0, 1)`
  20304. The shape of the tensor is defined by the variable argument :attr:`size`.
  20305. Args:
  20306. size (int...): a sequence of integers defining the shape of the output tensor.
  20307. Can be a variable number of arguments or a collection like a list or tuple.
  20308. Keyword args:
  20309. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20310. out (Tensor, optional): the output tensor.
  20311. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  20312. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  20313. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20314. Default: ``torch.strided``.
  20315. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20316. Default: if ``None``, uses the current device for the default tensor type
  20317. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20318. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20319. requires_grad (bool, optional): If autograd should record operations on the
  20320. returned tensor. Default: ``False``.
  20321. pin_memory (bool, optional): If set, returned tensor would be allocated in
  20322. the pinned memory. Works only for CPU tensors. Default: ``False``.
  20323. Example::
  20324. >>> torch.rand(4)
  20325. tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
  20326. >>> torch.rand(2, 3)
  20327. tensor([[ 0.8237, 0.5781, 0.6879],
  20328. [ 0.3816, 0.7249, 0.0998]])
  20329. """
  20330. @overload
  20331. def rand(
  20332. *size: _int | SymInt,
  20333. generator: Generator | None,
  20334. names: Sequence[str | EllipsisType | None] | None,
  20335. dtype: _dtype | None = None,
  20336. layout: _layout | None = None,
  20337. device: DeviceLikeType | None = None,
  20338. pin_memory: _bool | None = False,
  20339. requires_grad: _bool | None = False,
  20340. ) -> Tensor:
  20341. r"""
  20342. rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  20343. Returns a tensor filled with random numbers from a uniform distribution
  20344. on the interval :math:`[0, 1)`
  20345. The shape of the tensor is defined by the variable argument :attr:`size`.
  20346. Args:
  20347. size (int...): a sequence of integers defining the shape of the output tensor.
  20348. Can be a variable number of arguments or a collection like a list or tuple.
  20349. Keyword args:
  20350. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20351. out (Tensor, optional): the output tensor.
  20352. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  20353. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  20354. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20355. Default: ``torch.strided``.
  20356. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20357. Default: if ``None``, uses the current device for the default tensor type
  20358. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20359. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20360. requires_grad (bool, optional): If autograd should record operations on the
  20361. returned tensor. Default: ``False``.
  20362. pin_memory (bool, optional): If set, returned tensor would be allocated in
  20363. the pinned memory. Works only for CPU tensors. Default: ``False``.
  20364. Example::
  20365. >>> torch.rand(4)
  20366. tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
  20367. >>> torch.rand(2, 3)
  20368. tensor([[ 0.8237, 0.5781, 0.6879],
  20369. [ 0.3816, 0.7249, 0.0998]])
  20370. """
  20371. @overload
  20372. def rand(
  20373. size: Sequence[_int | SymInt],
  20374. *,
  20375. generator: Generator | None,
  20376. out: Tensor | None = None,
  20377. dtype: _dtype | None = None,
  20378. layout: _layout | None = None,
  20379. device: DeviceLikeType | None = None,
  20380. pin_memory: _bool | None = False,
  20381. requires_grad: _bool | None = False,
  20382. ) -> Tensor:
  20383. r"""
  20384. rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  20385. Returns a tensor filled with random numbers from a uniform distribution
  20386. on the interval :math:`[0, 1)`
  20387. The shape of the tensor is defined by the variable argument :attr:`size`.
  20388. Args:
  20389. size (int...): a sequence of integers defining the shape of the output tensor.
  20390. Can be a variable number of arguments or a collection like a list or tuple.
  20391. Keyword args:
  20392. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20393. out (Tensor, optional): the output tensor.
  20394. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  20395. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  20396. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20397. Default: ``torch.strided``.
  20398. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20399. Default: if ``None``, uses the current device for the default tensor type
  20400. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20401. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20402. requires_grad (bool, optional): If autograd should record operations on the
  20403. returned tensor. Default: ``False``.
  20404. pin_memory (bool, optional): If set, returned tensor would be allocated in
  20405. the pinned memory. Works only for CPU tensors. Default: ``False``.
  20406. Example::
  20407. >>> torch.rand(4)
  20408. tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
  20409. >>> torch.rand(2, 3)
  20410. tensor([[ 0.8237, 0.5781, 0.6879],
  20411. [ 0.3816, 0.7249, 0.0998]])
  20412. """
  20413. @overload
  20414. def rand(
  20415. *size: _int | SymInt,
  20416. generator: Generator | None,
  20417. out: Tensor | None = None,
  20418. dtype: _dtype | None = None,
  20419. layout: _layout | None = None,
  20420. device: DeviceLikeType | None = None,
  20421. pin_memory: _bool | None = False,
  20422. requires_grad: _bool | None = False,
  20423. ) -> Tensor:
  20424. r"""
  20425. rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  20426. Returns a tensor filled with random numbers from a uniform distribution
  20427. on the interval :math:`[0, 1)`
  20428. The shape of the tensor is defined by the variable argument :attr:`size`.
  20429. Args:
  20430. size (int...): a sequence of integers defining the shape of the output tensor.
  20431. Can be a variable number of arguments or a collection like a list or tuple.
  20432. Keyword args:
  20433. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20434. out (Tensor, optional): the output tensor.
  20435. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  20436. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  20437. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20438. Default: ``torch.strided``.
  20439. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20440. Default: if ``None``, uses the current device for the default tensor type
  20441. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20442. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20443. requires_grad (bool, optional): If autograd should record operations on the
  20444. returned tensor. Default: ``False``.
  20445. pin_memory (bool, optional): If set, returned tensor would be allocated in
  20446. the pinned memory. Works only for CPU tensors. Default: ``False``.
  20447. Example::
  20448. >>> torch.rand(4)
  20449. tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
  20450. >>> torch.rand(2, 3)
  20451. tensor([[ 0.8237, 0.5781, 0.6879],
  20452. [ 0.3816, 0.7249, 0.0998]])
  20453. """
  20454. @overload
  20455. def rand(
  20456. size: Sequence[_int | SymInt],
  20457. *,
  20458. out: Tensor | None = None,
  20459. dtype: _dtype | None = None,
  20460. layout: _layout | None = None,
  20461. device: DeviceLikeType | None = None,
  20462. pin_memory: _bool | None = False,
  20463. requires_grad: _bool | None = False,
  20464. ) -> Tensor:
  20465. r"""
  20466. rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  20467. Returns a tensor filled with random numbers from a uniform distribution
  20468. on the interval :math:`[0, 1)`
  20469. The shape of the tensor is defined by the variable argument :attr:`size`.
  20470. Args:
  20471. size (int...): a sequence of integers defining the shape of the output tensor.
  20472. Can be a variable number of arguments or a collection like a list or tuple.
  20473. Keyword args:
  20474. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20475. out (Tensor, optional): the output tensor.
  20476. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  20477. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  20478. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20479. Default: ``torch.strided``.
  20480. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20481. Default: if ``None``, uses the current device for the default tensor type
  20482. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20483. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20484. requires_grad (bool, optional): If autograd should record operations on the
  20485. returned tensor. Default: ``False``.
  20486. pin_memory (bool, optional): If set, returned tensor would be allocated in
  20487. the pinned memory. Works only for CPU tensors. Default: ``False``.
  20488. Example::
  20489. >>> torch.rand(4)
  20490. tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
  20491. >>> torch.rand(2, 3)
  20492. tensor([[ 0.8237, 0.5781, 0.6879],
  20493. [ 0.3816, 0.7249, 0.0998]])
  20494. """
  20495. @overload
  20496. def rand(
  20497. *size: _int | SymInt,
  20498. out: Tensor | None = None,
  20499. dtype: _dtype | None = None,
  20500. layout: _layout | None = None,
  20501. device: DeviceLikeType | None = None,
  20502. pin_memory: _bool | None = False,
  20503. requires_grad: _bool | None = False,
  20504. ) -> Tensor:
  20505. r"""
  20506. rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  20507. Returns a tensor filled with random numbers from a uniform distribution
  20508. on the interval :math:`[0, 1)`
  20509. The shape of the tensor is defined by the variable argument :attr:`size`.
  20510. Args:
  20511. size (int...): a sequence of integers defining the shape of the output tensor.
  20512. Can be a variable number of arguments or a collection like a list or tuple.
  20513. Keyword args:
  20514. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20515. out (Tensor, optional): the output tensor.
  20516. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  20517. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  20518. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20519. Default: ``torch.strided``.
  20520. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20521. Default: if ``None``, uses the current device for the default tensor type
  20522. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20523. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20524. requires_grad (bool, optional): If autograd should record operations on the
  20525. returned tensor. Default: ``False``.
  20526. pin_memory (bool, optional): If set, returned tensor would be allocated in
  20527. the pinned memory. Works only for CPU tensors. Default: ``False``.
  20528. Example::
  20529. >>> torch.rand(4)
  20530. tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
  20531. >>> torch.rand(2, 3)
  20532. tensor([[ 0.8237, 0.5781, 0.6879],
  20533. [ 0.3816, 0.7249, 0.0998]])
  20534. """
  20535. @overload
  20536. def rand(
  20537. size: Sequence[_int | SymInt],
  20538. *,
  20539. names: Sequence[str | EllipsisType | None] | None,
  20540. dtype: _dtype | None = None,
  20541. layout: _layout | None = None,
  20542. device: DeviceLikeType | None = None,
  20543. pin_memory: _bool | None = False,
  20544. requires_grad: _bool | None = False,
  20545. ) -> Tensor:
  20546. r"""
  20547. rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  20548. Returns a tensor filled with random numbers from a uniform distribution
  20549. on the interval :math:`[0, 1)`
  20550. The shape of the tensor is defined by the variable argument :attr:`size`.
  20551. Args:
  20552. size (int...): a sequence of integers defining the shape of the output tensor.
  20553. Can be a variable number of arguments or a collection like a list or tuple.
  20554. Keyword args:
  20555. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20556. out (Tensor, optional): the output tensor.
  20557. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  20558. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  20559. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20560. Default: ``torch.strided``.
  20561. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20562. Default: if ``None``, uses the current device for the default tensor type
  20563. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20564. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20565. requires_grad (bool, optional): If autograd should record operations on the
  20566. returned tensor. Default: ``False``.
  20567. pin_memory (bool, optional): If set, returned tensor would be allocated in
  20568. the pinned memory. Works only for CPU tensors. Default: ``False``.
  20569. Example::
  20570. >>> torch.rand(4)
  20571. tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
  20572. >>> torch.rand(2, 3)
  20573. tensor([[ 0.8237, 0.5781, 0.6879],
  20574. [ 0.3816, 0.7249, 0.0998]])
  20575. """
  20576. @overload
  20577. def rand(
  20578. *size: _int | SymInt,
  20579. names: Sequence[str | EllipsisType | None] | None,
  20580. dtype: _dtype | None = None,
  20581. layout: _layout | None = None,
  20582. device: DeviceLikeType | None = None,
  20583. pin_memory: _bool | None = False,
  20584. requires_grad: _bool | None = False,
  20585. ) -> Tensor:
  20586. r"""
  20587. rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  20588. Returns a tensor filled with random numbers from a uniform distribution
  20589. on the interval :math:`[0, 1)`
  20590. The shape of the tensor is defined by the variable argument :attr:`size`.
  20591. Args:
  20592. size (int...): a sequence of integers defining the shape of the output tensor.
  20593. Can be a variable number of arguments or a collection like a list or tuple.
  20594. Keyword args:
  20595. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20596. out (Tensor, optional): the output tensor.
  20597. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  20598. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  20599. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20600. Default: ``torch.strided``.
  20601. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20602. Default: if ``None``, uses the current device for the default tensor type
  20603. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20604. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20605. requires_grad (bool, optional): If autograd should record operations on the
  20606. returned tensor. Default: ``False``.
  20607. pin_memory (bool, optional): If set, returned tensor would be allocated in
  20608. the pinned memory. Works only for CPU tensors. Default: ``False``.
  20609. Example::
  20610. >>> torch.rand(4)
  20611. tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
  20612. >>> torch.rand(2, 3)
  20613. tensor([[ 0.8237, 0.5781, 0.6879],
  20614. [ 0.3816, 0.7249, 0.0998]])
  20615. """
  20616. @overload
  20617. def rand_like(
  20618. input: Tensor,
  20619. *,
  20620. generator: Generator | None,
  20621. memory_format: memory_format | None = None,
  20622. dtype: _dtype | None = None,
  20623. layout: _layout | None = None,
  20624. device: DeviceLikeType | None = None,
  20625. pin_memory: _bool | None = False,
  20626. requires_grad: _bool | None = False,
  20627. ) -> Tensor:
  20628. r"""
  20629. rand_like(input, *, generator=None, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  20630. Returns a tensor with the same size as :attr:`input` that is filled with
  20631. random numbers from a uniform distribution on the interval :math:`[0, 1)`.
  20632. ``torch.rand_like(input)`` is equivalent to
  20633. ``torch.rand(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
  20634. Args:
  20635. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  20636. Keyword args:
  20637. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
  20638. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  20639. Default: if ``None``, defaults to the dtype of :attr:`input`.
  20640. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  20641. Default: if ``None``, defaults to the layout of :attr:`input`.
  20642. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20643. Default: if ``None``, defaults to the device of :attr:`input`.
  20644. requires_grad (bool, optional): If autograd should record operations on the
  20645. returned tensor. Default: ``False``.
  20646. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  20647. returned Tensor. Default: ``torch.preserve_format``.
  20648. """
  20649. @overload
  20650. def rand_like(
  20651. input: Tensor,
  20652. *,
  20653. memory_format: memory_format | None = None,
  20654. dtype: _dtype | None = None,
  20655. layout: _layout | None = None,
  20656. device: DeviceLikeType | None = None,
  20657. pin_memory: _bool | None = False,
  20658. requires_grad: _bool | None = False,
  20659. ) -> Tensor:
  20660. r"""
  20661. rand_like(input, *, generator=None, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  20662. Returns a tensor with the same size as :attr:`input` that is filled with
  20663. random numbers from a uniform distribution on the interval :math:`[0, 1)`.
  20664. ``torch.rand_like(input)`` is equivalent to
  20665. ``torch.rand(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
  20666. Args:
  20667. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  20668. Keyword args:
  20669. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
  20670. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  20671. Default: if ``None``, defaults to the dtype of :attr:`input`.
  20672. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  20673. Default: if ``None``, defaults to the layout of :attr:`input`.
  20674. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20675. Default: if ``None``, defaults to the device of :attr:`input`.
  20676. requires_grad (bool, optional): If autograd should record operations on the
  20677. returned tensor. Default: ``False``.
  20678. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  20679. returned Tensor. Default: ``torch.preserve_format``.
  20680. """
  20681. @overload
  20682. def randint(
  20683. low: _int,
  20684. high: _int,
  20685. size: _size,
  20686. *,
  20687. generator: Generator | None = None,
  20688. dtype: _dtype | None = None,
  20689. device: DeviceLikeType | None = None,
  20690. requires_grad: _bool = False,
  20691. pin_memory: _bool = False,
  20692. ) -> Tensor:
  20693. r"""
  20694. randint(low=0, high, size, \*, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  20695. Returns a tensor filled with random integers generated uniformly
  20696. between :attr:`low` (inclusive) and :attr:`high` (exclusive).
  20697. The shape of the tensor is defined by the variable argument :attr:`size`.
  20698. .. note::
  20699. With the global dtype default (``torch.float32``), this function returns
  20700. a tensor with dtype ``torch.int64``.
  20701. Args:
  20702. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  20703. high (int): One above the highest integer to be drawn from the distribution.
  20704. size (tuple): a tuple defining the shape of the output tensor.
  20705. Keyword args:
  20706. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20707. out (Tensor, optional): the output tensor.
  20708. dtype (torch.dtype, optional): the desired data type of returned tensor. Default: if ``None``,
  20709. this function returns a tensor with dtype ``torch.int64``.
  20710. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20711. Default: ``torch.strided``.
  20712. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20713. Default: if ``None``, uses the current device for the default tensor type
  20714. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20715. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20716. requires_grad (bool, optional): If autograd should record operations on the
  20717. returned tensor. Default: ``False``.
  20718. Example::
  20719. >>> torch.randint(3, 5, (3,))
  20720. tensor([4, 3, 4])
  20721. >>> torch.randint(10, (2, 2))
  20722. tensor([[0, 2],
  20723. [5, 5]])
  20724. >>> torch.randint(3, 10, (2, 2))
  20725. tensor([[4, 5],
  20726. [6, 7]])
  20727. """
  20728. @overload
  20729. def randint(
  20730. high: _int,
  20731. size: _size,
  20732. *,
  20733. generator: Generator | None = None,
  20734. dtype: _dtype | None = None,
  20735. device: DeviceLikeType | None = None,
  20736. requires_grad: _bool = False,
  20737. pin_memory: _bool = False,
  20738. ) -> Tensor:
  20739. r"""
  20740. randint(low=0, high, size, \*, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  20741. Returns a tensor filled with random integers generated uniformly
  20742. between :attr:`low` (inclusive) and :attr:`high` (exclusive).
  20743. The shape of the tensor is defined by the variable argument :attr:`size`.
  20744. .. note::
  20745. With the global dtype default (``torch.float32``), this function returns
  20746. a tensor with dtype ``torch.int64``.
  20747. Args:
  20748. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  20749. high (int): One above the highest integer to be drawn from the distribution.
  20750. size (tuple): a tuple defining the shape of the output tensor.
  20751. Keyword args:
  20752. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20753. out (Tensor, optional): the output tensor.
  20754. dtype (torch.dtype, optional): the desired data type of returned tensor. Default: if ``None``,
  20755. this function returns a tensor with dtype ``torch.int64``.
  20756. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20757. Default: ``torch.strided``.
  20758. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20759. Default: if ``None``, uses the current device for the default tensor type
  20760. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20761. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20762. requires_grad (bool, optional): If autograd should record operations on the
  20763. returned tensor. Default: ``False``.
  20764. Example::
  20765. >>> torch.randint(3, 5, (3,))
  20766. tensor([4, 3, 4])
  20767. >>> torch.randint(10, (2, 2))
  20768. tensor([[0, 2],
  20769. [5, 5]])
  20770. >>> torch.randint(3, 10, (2, 2))
  20771. tensor([[4, 5],
  20772. [6, 7]])
  20773. """
  20774. @overload
  20775. def randint(
  20776. high: _int | SymInt,
  20777. size: Sequence[_int | SymInt],
  20778. *,
  20779. generator: Generator | None,
  20780. out: Tensor | None = None,
  20781. dtype: _dtype | None = None,
  20782. layout: _layout | None = None,
  20783. device: DeviceLikeType | None = None,
  20784. pin_memory: _bool | None = False,
  20785. requires_grad: _bool | None = False,
  20786. ) -> Tensor:
  20787. r"""
  20788. randint(low=0, high, size, \*, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  20789. Returns a tensor filled with random integers generated uniformly
  20790. between :attr:`low` (inclusive) and :attr:`high` (exclusive).
  20791. The shape of the tensor is defined by the variable argument :attr:`size`.
  20792. .. note::
  20793. With the global dtype default (``torch.float32``), this function returns
  20794. a tensor with dtype ``torch.int64``.
  20795. Args:
  20796. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  20797. high (int): One above the highest integer to be drawn from the distribution.
  20798. size (tuple): a tuple defining the shape of the output tensor.
  20799. Keyword args:
  20800. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20801. out (Tensor, optional): the output tensor.
  20802. dtype (torch.dtype, optional): the desired data type of returned tensor. Default: if ``None``,
  20803. this function returns a tensor with dtype ``torch.int64``.
  20804. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20805. Default: ``torch.strided``.
  20806. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20807. Default: if ``None``, uses the current device for the default tensor type
  20808. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20809. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20810. requires_grad (bool, optional): If autograd should record operations on the
  20811. returned tensor. Default: ``False``.
  20812. Example::
  20813. >>> torch.randint(3, 5, (3,))
  20814. tensor([4, 3, 4])
  20815. >>> torch.randint(10, (2, 2))
  20816. tensor([[0, 2],
  20817. [5, 5]])
  20818. >>> torch.randint(3, 10, (2, 2))
  20819. tensor([[4, 5],
  20820. [6, 7]])
  20821. """
  20822. @overload
  20823. def randint(
  20824. high: _int | SymInt,
  20825. size: Sequence[_int | SymInt],
  20826. *,
  20827. out: Tensor | None = None,
  20828. dtype: _dtype | None = None,
  20829. layout: _layout | None = None,
  20830. device: DeviceLikeType | None = None,
  20831. pin_memory: _bool | None = False,
  20832. requires_grad: _bool | None = False,
  20833. ) -> Tensor:
  20834. r"""
  20835. randint(low=0, high, size, \*, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  20836. Returns a tensor filled with random integers generated uniformly
  20837. between :attr:`low` (inclusive) and :attr:`high` (exclusive).
  20838. The shape of the tensor is defined by the variable argument :attr:`size`.
  20839. .. note::
  20840. With the global dtype default (``torch.float32``), this function returns
  20841. a tensor with dtype ``torch.int64``.
  20842. Args:
  20843. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  20844. high (int): One above the highest integer to be drawn from the distribution.
  20845. size (tuple): a tuple defining the shape of the output tensor.
  20846. Keyword args:
  20847. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20848. out (Tensor, optional): the output tensor.
  20849. dtype (torch.dtype, optional): the desired data type of returned tensor. Default: if ``None``,
  20850. this function returns a tensor with dtype ``torch.int64``.
  20851. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20852. Default: ``torch.strided``.
  20853. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20854. Default: if ``None``, uses the current device for the default tensor type
  20855. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20856. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20857. requires_grad (bool, optional): If autograd should record operations on the
  20858. returned tensor. Default: ``False``.
  20859. Example::
  20860. >>> torch.randint(3, 5, (3,))
  20861. tensor([4, 3, 4])
  20862. >>> torch.randint(10, (2, 2))
  20863. tensor([[0, 2],
  20864. [5, 5]])
  20865. >>> torch.randint(3, 10, (2, 2))
  20866. tensor([[4, 5],
  20867. [6, 7]])
  20868. """
  20869. @overload
  20870. def randint(
  20871. low: _int | SymInt,
  20872. high: _int | SymInt,
  20873. size: Sequence[_int | SymInt],
  20874. *,
  20875. generator: Generator | None,
  20876. out: Tensor | None = None,
  20877. dtype: _dtype | None = None,
  20878. layout: _layout | None = None,
  20879. device: DeviceLikeType | None = None,
  20880. pin_memory: _bool | None = False,
  20881. requires_grad: _bool | None = False,
  20882. ) -> Tensor:
  20883. r"""
  20884. randint(low=0, high, size, \*, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  20885. Returns a tensor filled with random integers generated uniformly
  20886. between :attr:`low` (inclusive) and :attr:`high` (exclusive).
  20887. The shape of the tensor is defined by the variable argument :attr:`size`.
  20888. .. note::
  20889. With the global dtype default (``torch.float32``), this function returns
  20890. a tensor with dtype ``torch.int64``.
  20891. Args:
  20892. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  20893. high (int): One above the highest integer to be drawn from the distribution.
  20894. size (tuple): a tuple defining the shape of the output tensor.
  20895. Keyword args:
  20896. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20897. out (Tensor, optional): the output tensor.
  20898. dtype (torch.dtype, optional): the desired data type of returned tensor. Default: if ``None``,
  20899. this function returns a tensor with dtype ``torch.int64``.
  20900. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20901. Default: ``torch.strided``.
  20902. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20903. Default: if ``None``, uses the current device for the default tensor type
  20904. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20905. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20906. requires_grad (bool, optional): If autograd should record operations on the
  20907. returned tensor. Default: ``False``.
  20908. Example::
  20909. >>> torch.randint(3, 5, (3,))
  20910. tensor([4, 3, 4])
  20911. >>> torch.randint(10, (2, 2))
  20912. tensor([[0, 2],
  20913. [5, 5]])
  20914. >>> torch.randint(3, 10, (2, 2))
  20915. tensor([[4, 5],
  20916. [6, 7]])
  20917. """
  20918. @overload
  20919. def randint(
  20920. low: _int | SymInt,
  20921. high: _int | SymInt,
  20922. size: Sequence[_int | SymInt],
  20923. *,
  20924. out: Tensor | None = None,
  20925. dtype: _dtype | None = None,
  20926. layout: _layout | None = None,
  20927. device: DeviceLikeType | None = None,
  20928. pin_memory: _bool | None = False,
  20929. requires_grad: _bool | None = False,
  20930. ) -> Tensor:
  20931. r"""
  20932. randint(low=0, high, size, \*, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  20933. Returns a tensor filled with random integers generated uniformly
  20934. between :attr:`low` (inclusive) and :attr:`high` (exclusive).
  20935. The shape of the tensor is defined by the variable argument :attr:`size`.
  20936. .. note::
  20937. With the global dtype default (``torch.float32``), this function returns
  20938. a tensor with dtype ``torch.int64``.
  20939. Args:
  20940. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  20941. high (int): One above the highest integer to be drawn from the distribution.
  20942. size (tuple): a tuple defining the shape of the output tensor.
  20943. Keyword args:
  20944. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20945. out (Tensor, optional): the output tensor.
  20946. dtype (torch.dtype, optional): the desired data type of returned tensor. Default: if ``None``,
  20947. this function returns a tensor with dtype ``torch.int64``.
  20948. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20949. Default: ``torch.strided``.
  20950. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20951. Default: if ``None``, uses the current device for the default tensor type
  20952. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20953. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20954. requires_grad (bool, optional): If autograd should record operations on the
  20955. returned tensor. Default: ``False``.
  20956. Example::
  20957. >>> torch.randint(3, 5, (3,))
  20958. tensor([4, 3, 4])
  20959. >>> torch.randint(10, (2, 2))
  20960. tensor([[0, 2],
  20961. [5, 5]])
  20962. >>> torch.randint(3, 10, (2, 2))
  20963. tensor([[4, 5],
  20964. [6, 7]])
  20965. """
  20966. @overload
  20967. def randint_like(
  20968. input: Tensor,
  20969. low: _int | SymInt,
  20970. high: _int | SymInt,
  20971. *,
  20972. generator: Generator | None,
  20973. memory_format: memory_format | None = None,
  20974. dtype: _dtype | None = None,
  20975. layout: _layout | None = None,
  20976. device: DeviceLikeType | None = None,
  20977. pin_memory: _bool | None = False,
  20978. requires_grad: _bool | None = False,
  20979. ) -> Tensor:
  20980. r"""
  20981. randint_like(input, low=0, high, \*, generator=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  20982. Returns a tensor with the same shape as Tensor :attr:`input` filled with
  20983. random integers generated uniformly between :attr:`low` (inclusive) and
  20984. :attr:`high` (exclusive).
  20985. .. note:
  20986. With the global dtype default (``torch.float32``), this function returns
  20987. a tensor with dtype ``torch.int64``.
  20988. Args:
  20989. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  20990. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  20991. high (int): One above the highest integer to be drawn from the distribution.
  20992. Keyword args:
  20993. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
  20994. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  20995. Default: if ``None``, defaults to the dtype of :attr:`input`.
  20996. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  20997. Default: if ``None``, defaults to the layout of :attr:`input`.
  20998. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20999. Default: if ``None``, defaults to the device of :attr:`input`.
  21000. requires_grad (bool, optional): If autograd should record operations on the
  21001. returned tensor. Default: ``False``.
  21002. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  21003. returned Tensor. Default: ``torch.preserve_format``.
  21004. """
  21005. @overload
  21006. def randint_like(
  21007. input: Tensor,
  21008. low: _int | SymInt,
  21009. high: _int | SymInt,
  21010. *,
  21011. memory_format: memory_format | None = None,
  21012. dtype: _dtype | None = None,
  21013. layout: _layout | None = None,
  21014. device: DeviceLikeType | None = None,
  21015. pin_memory: _bool | None = False,
  21016. requires_grad: _bool | None = False,
  21017. ) -> Tensor:
  21018. r"""
  21019. randint_like(input, low=0, high, \*, generator=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  21020. Returns a tensor with the same shape as Tensor :attr:`input` filled with
  21021. random integers generated uniformly between :attr:`low` (inclusive) and
  21022. :attr:`high` (exclusive).
  21023. .. note:
  21024. With the global dtype default (``torch.float32``), this function returns
  21025. a tensor with dtype ``torch.int64``.
  21026. Args:
  21027. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  21028. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  21029. high (int): One above the highest integer to be drawn from the distribution.
  21030. Keyword args:
  21031. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
  21032. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  21033. Default: if ``None``, defaults to the dtype of :attr:`input`.
  21034. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  21035. Default: if ``None``, defaults to the layout of :attr:`input`.
  21036. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21037. Default: if ``None``, defaults to the device of :attr:`input`.
  21038. requires_grad (bool, optional): If autograd should record operations on the
  21039. returned tensor. Default: ``False``.
  21040. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  21041. returned Tensor. Default: ``torch.preserve_format``.
  21042. """
  21043. @overload
  21044. def randint_like(
  21045. input: Tensor,
  21046. high: Tensor,
  21047. *,
  21048. generator: Generator | None,
  21049. memory_format: memory_format | None = None,
  21050. dtype: _dtype | None = None,
  21051. layout: _layout | None = None,
  21052. device: DeviceLikeType | None = None,
  21053. pin_memory: _bool | None = False,
  21054. requires_grad: _bool | None = False,
  21055. ) -> Tensor:
  21056. r"""
  21057. randint_like(input, low=0, high, \*, generator=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  21058. Returns a tensor with the same shape as Tensor :attr:`input` filled with
  21059. random integers generated uniformly between :attr:`low` (inclusive) and
  21060. :attr:`high` (exclusive).
  21061. .. note:
  21062. With the global dtype default (``torch.float32``), this function returns
  21063. a tensor with dtype ``torch.int64``.
  21064. Args:
  21065. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  21066. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  21067. high (int): One above the highest integer to be drawn from the distribution.
  21068. Keyword args:
  21069. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
  21070. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  21071. Default: if ``None``, defaults to the dtype of :attr:`input`.
  21072. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  21073. Default: if ``None``, defaults to the layout of :attr:`input`.
  21074. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21075. Default: if ``None``, defaults to the device of :attr:`input`.
  21076. requires_grad (bool, optional): If autograd should record operations on the
  21077. returned tensor. Default: ``False``.
  21078. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  21079. returned Tensor. Default: ``torch.preserve_format``.
  21080. """
  21081. @overload
  21082. def randint_like(
  21083. input: Tensor,
  21084. high: Tensor,
  21085. *,
  21086. memory_format: memory_format | None = None,
  21087. dtype: _dtype | None = None,
  21088. layout: _layout | None = None,
  21089. device: DeviceLikeType | None = None,
  21090. pin_memory: _bool | None = False,
  21091. requires_grad: _bool | None = False,
  21092. ) -> Tensor:
  21093. r"""
  21094. randint_like(input, low=0, high, \*, generator=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  21095. Returns a tensor with the same shape as Tensor :attr:`input` filled with
  21096. random integers generated uniformly between :attr:`low` (inclusive) and
  21097. :attr:`high` (exclusive).
  21098. .. note:
  21099. With the global dtype default (``torch.float32``), this function returns
  21100. a tensor with dtype ``torch.int64``.
  21101. Args:
  21102. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  21103. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  21104. high (int): One above the highest integer to be drawn from the distribution.
  21105. Keyword args:
  21106. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
  21107. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  21108. Default: if ``None``, defaults to the dtype of :attr:`input`.
  21109. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  21110. Default: if ``None``, defaults to the layout of :attr:`input`.
  21111. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21112. Default: if ``None``, defaults to the device of :attr:`input`.
  21113. requires_grad (bool, optional): If autograd should record operations on the
  21114. returned tensor. Default: ``False``.
  21115. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  21116. returned Tensor. Default: ``torch.preserve_format``.
  21117. """
  21118. @overload
  21119. def randint_like(
  21120. input: Tensor,
  21121. high: _int | SymInt,
  21122. *,
  21123. generator: Generator | None,
  21124. memory_format: memory_format | None = None,
  21125. dtype: _dtype | None = None,
  21126. layout: _layout | None = None,
  21127. device: DeviceLikeType | None = None,
  21128. pin_memory: _bool | None = False,
  21129. requires_grad: _bool | None = False,
  21130. ) -> Tensor:
  21131. r"""
  21132. randint_like(input, low=0, high, \*, generator=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  21133. Returns a tensor with the same shape as Tensor :attr:`input` filled with
  21134. random integers generated uniformly between :attr:`low` (inclusive) and
  21135. :attr:`high` (exclusive).
  21136. .. note:
  21137. With the global dtype default (``torch.float32``), this function returns
  21138. a tensor with dtype ``torch.int64``.
  21139. Args:
  21140. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  21141. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  21142. high (int): One above the highest integer to be drawn from the distribution.
  21143. Keyword args:
  21144. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
  21145. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  21146. Default: if ``None``, defaults to the dtype of :attr:`input`.
  21147. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  21148. Default: if ``None``, defaults to the layout of :attr:`input`.
  21149. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21150. Default: if ``None``, defaults to the device of :attr:`input`.
  21151. requires_grad (bool, optional): If autograd should record operations on the
  21152. returned tensor. Default: ``False``.
  21153. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  21154. returned Tensor. Default: ``torch.preserve_format``.
  21155. """
  21156. @overload
  21157. def randint_like(
  21158. input: Tensor,
  21159. high: _int | SymInt,
  21160. *,
  21161. memory_format: memory_format | None = None,
  21162. dtype: _dtype | None = None,
  21163. layout: _layout | None = None,
  21164. device: DeviceLikeType | None = None,
  21165. pin_memory: _bool | None = False,
  21166. requires_grad: _bool | None = False,
  21167. ) -> Tensor:
  21168. r"""
  21169. randint_like(input, low=0, high, \*, generator=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  21170. Returns a tensor with the same shape as Tensor :attr:`input` filled with
  21171. random integers generated uniformly between :attr:`low` (inclusive) and
  21172. :attr:`high` (exclusive).
  21173. .. note:
  21174. With the global dtype default (``torch.float32``), this function returns
  21175. a tensor with dtype ``torch.int64``.
  21176. Args:
  21177. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  21178. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  21179. high (int): One above the highest integer to be drawn from the distribution.
  21180. Keyword args:
  21181. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
  21182. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  21183. Default: if ``None``, defaults to the dtype of :attr:`input`.
  21184. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  21185. Default: if ``None``, defaults to the layout of :attr:`input`.
  21186. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21187. Default: if ``None``, defaults to the device of :attr:`input`.
  21188. requires_grad (bool, optional): If autograd should record operations on the
  21189. returned tensor. Default: ``False``.
  21190. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  21191. returned Tensor. Default: ``torch.preserve_format``.
  21192. """
  21193. @overload
  21194. def randn(
  21195. size: Sequence[_int | SymInt],
  21196. *,
  21197. generator: Generator | None,
  21198. names: Sequence[str | EllipsisType | None] | None,
  21199. dtype: _dtype | None = None,
  21200. layout: _layout | None = None,
  21201. device: DeviceLikeType | None = None,
  21202. pin_memory: _bool | None = False,
  21203. requires_grad: _bool | None = False,
  21204. ) -> Tensor:
  21205. r"""
  21206. randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21207. Returns a tensor filled with random numbers from a normal distribution
  21208. with mean `0` and variance `1` (also called the standard normal
  21209. distribution).
  21210. .. math::
  21211. \text{out}_{i} \sim \mathcal{N}(0, 1)
  21212. For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
  21213. unit variance as
  21214. .. math::
  21215. \text{out}_{i} \sim \mathcal{CN}(0, 1)
  21216. This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
  21217. :math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
  21218. .. math::
  21219. \operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
  21220. \operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
  21221. The shape of the tensor is defined by the variable argument :attr:`size`.
  21222. Args:
  21223. size (int...): a sequence of integers defining the shape of the output tensor.
  21224. Can be a variable number of arguments or a collection like a list or tuple.
  21225. Keyword args:
  21226. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21227. out (Tensor, optional): the output tensor.
  21228. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21229. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  21230. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21231. Default: ``torch.strided``.
  21232. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21233. Default: if ``None``, uses the current device for the default tensor type
  21234. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21235. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21236. requires_grad (bool, optional): If autograd should record operations on the
  21237. returned tensor. Default: ``False``.
  21238. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21239. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21240. Example::
  21241. >>> torch.randn(4)
  21242. tensor([-2.1436, 0.9966, 2.3426, -0.6366])
  21243. >>> torch.randn(2, 3)
  21244. tensor([[ 1.5954, 2.8929, -1.0923],
  21245. [ 1.1719, -0.4709, -0.1996]])
  21246. .. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
  21247. """
  21248. @overload
  21249. def randn(
  21250. *size: _int | SymInt,
  21251. generator: Generator | None,
  21252. names: Sequence[str | EllipsisType | None] | None,
  21253. dtype: _dtype | None = None,
  21254. layout: _layout | None = None,
  21255. device: DeviceLikeType | None = None,
  21256. pin_memory: _bool | None = False,
  21257. requires_grad: _bool | None = False,
  21258. ) -> Tensor:
  21259. r"""
  21260. randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21261. Returns a tensor filled with random numbers from a normal distribution
  21262. with mean `0` and variance `1` (also called the standard normal
  21263. distribution).
  21264. .. math::
  21265. \text{out}_{i} \sim \mathcal{N}(0, 1)
  21266. For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
  21267. unit variance as
  21268. .. math::
  21269. \text{out}_{i} \sim \mathcal{CN}(0, 1)
  21270. This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
  21271. :math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
  21272. .. math::
  21273. \operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
  21274. \operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
  21275. The shape of the tensor is defined by the variable argument :attr:`size`.
  21276. Args:
  21277. size (int...): a sequence of integers defining the shape of the output tensor.
  21278. Can be a variable number of arguments or a collection like a list or tuple.
  21279. Keyword args:
  21280. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21281. out (Tensor, optional): the output tensor.
  21282. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21283. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  21284. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21285. Default: ``torch.strided``.
  21286. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21287. Default: if ``None``, uses the current device for the default tensor type
  21288. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21289. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21290. requires_grad (bool, optional): If autograd should record operations on the
  21291. returned tensor. Default: ``False``.
  21292. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21293. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21294. Example::
  21295. >>> torch.randn(4)
  21296. tensor([-2.1436, 0.9966, 2.3426, -0.6366])
  21297. >>> torch.randn(2, 3)
  21298. tensor([[ 1.5954, 2.8929, -1.0923],
  21299. [ 1.1719, -0.4709, -0.1996]])
  21300. .. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
  21301. """
  21302. @overload
  21303. def randn(
  21304. size: Sequence[_int | SymInt],
  21305. *,
  21306. generator: Generator | None,
  21307. out: Tensor | None = None,
  21308. dtype: _dtype | None = None,
  21309. layout: _layout | None = None,
  21310. device: DeviceLikeType | None = None,
  21311. pin_memory: _bool | None = False,
  21312. requires_grad: _bool | None = False,
  21313. ) -> Tensor:
  21314. r"""
  21315. randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21316. Returns a tensor filled with random numbers from a normal distribution
  21317. with mean `0` and variance `1` (also called the standard normal
  21318. distribution).
  21319. .. math::
  21320. \text{out}_{i} \sim \mathcal{N}(0, 1)
  21321. For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
  21322. unit variance as
  21323. .. math::
  21324. \text{out}_{i} \sim \mathcal{CN}(0, 1)
  21325. This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
  21326. :math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
  21327. .. math::
  21328. \operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
  21329. \operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
  21330. The shape of the tensor is defined by the variable argument :attr:`size`.
  21331. Args:
  21332. size (int...): a sequence of integers defining the shape of the output tensor.
  21333. Can be a variable number of arguments or a collection like a list or tuple.
  21334. Keyword args:
  21335. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21336. out (Tensor, optional): the output tensor.
  21337. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21338. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  21339. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21340. Default: ``torch.strided``.
  21341. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21342. Default: if ``None``, uses the current device for the default tensor type
  21343. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21344. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21345. requires_grad (bool, optional): If autograd should record operations on the
  21346. returned tensor. Default: ``False``.
  21347. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21348. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21349. Example::
  21350. >>> torch.randn(4)
  21351. tensor([-2.1436, 0.9966, 2.3426, -0.6366])
  21352. >>> torch.randn(2, 3)
  21353. tensor([[ 1.5954, 2.8929, -1.0923],
  21354. [ 1.1719, -0.4709, -0.1996]])
  21355. .. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
  21356. """
  21357. @overload
  21358. def randn(
  21359. *size: _int | SymInt,
  21360. generator: Generator | None,
  21361. out: Tensor | None = None,
  21362. dtype: _dtype | None = None,
  21363. layout: _layout | None = None,
  21364. device: DeviceLikeType | None = None,
  21365. pin_memory: _bool | None = False,
  21366. requires_grad: _bool | None = False,
  21367. ) -> Tensor:
  21368. r"""
  21369. randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21370. Returns a tensor filled with random numbers from a normal distribution
  21371. with mean `0` and variance `1` (also called the standard normal
  21372. distribution).
  21373. .. math::
  21374. \text{out}_{i} \sim \mathcal{N}(0, 1)
  21375. For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
  21376. unit variance as
  21377. .. math::
  21378. \text{out}_{i} \sim \mathcal{CN}(0, 1)
  21379. This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
  21380. :math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
  21381. .. math::
  21382. \operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
  21383. \operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
  21384. The shape of the tensor is defined by the variable argument :attr:`size`.
  21385. Args:
  21386. size (int...): a sequence of integers defining the shape of the output tensor.
  21387. Can be a variable number of arguments or a collection like a list or tuple.
  21388. Keyword args:
  21389. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21390. out (Tensor, optional): the output tensor.
  21391. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21392. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  21393. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21394. Default: ``torch.strided``.
  21395. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21396. Default: if ``None``, uses the current device for the default tensor type
  21397. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21398. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21399. requires_grad (bool, optional): If autograd should record operations on the
  21400. returned tensor. Default: ``False``.
  21401. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21402. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21403. Example::
  21404. >>> torch.randn(4)
  21405. tensor([-2.1436, 0.9966, 2.3426, -0.6366])
  21406. >>> torch.randn(2, 3)
  21407. tensor([[ 1.5954, 2.8929, -1.0923],
  21408. [ 1.1719, -0.4709, -0.1996]])
  21409. .. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
  21410. """
  21411. @overload
  21412. def randn(
  21413. size: Sequence[_int | SymInt],
  21414. *,
  21415. out: Tensor | None = None,
  21416. dtype: _dtype | None = None,
  21417. layout: _layout | None = None,
  21418. device: DeviceLikeType | None = None,
  21419. pin_memory: _bool | None = False,
  21420. requires_grad: _bool | None = False,
  21421. ) -> Tensor:
  21422. r"""
  21423. randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21424. Returns a tensor filled with random numbers from a normal distribution
  21425. with mean `0` and variance `1` (also called the standard normal
  21426. distribution).
  21427. .. math::
  21428. \text{out}_{i} \sim \mathcal{N}(0, 1)
  21429. For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
  21430. unit variance as
  21431. .. math::
  21432. \text{out}_{i} \sim \mathcal{CN}(0, 1)
  21433. This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
  21434. :math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
  21435. .. math::
  21436. \operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
  21437. \operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
  21438. The shape of the tensor is defined by the variable argument :attr:`size`.
  21439. Args:
  21440. size (int...): a sequence of integers defining the shape of the output tensor.
  21441. Can be a variable number of arguments or a collection like a list or tuple.
  21442. Keyword args:
  21443. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21444. out (Tensor, optional): the output tensor.
  21445. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21446. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  21447. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21448. Default: ``torch.strided``.
  21449. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21450. Default: if ``None``, uses the current device for the default tensor type
  21451. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21452. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21453. requires_grad (bool, optional): If autograd should record operations on the
  21454. returned tensor. Default: ``False``.
  21455. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21456. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21457. Example::
  21458. >>> torch.randn(4)
  21459. tensor([-2.1436, 0.9966, 2.3426, -0.6366])
  21460. >>> torch.randn(2, 3)
  21461. tensor([[ 1.5954, 2.8929, -1.0923],
  21462. [ 1.1719, -0.4709, -0.1996]])
  21463. .. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
  21464. """
  21465. @overload
  21466. def randn(
  21467. *size: _int | SymInt,
  21468. out: Tensor | None = None,
  21469. dtype: _dtype | None = None,
  21470. layout: _layout | None = None,
  21471. device: DeviceLikeType | None = None,
  21472. pin_memory: _bool | None = False,
  21473. requires_grad: _bool | None = False,
  21474. ) -> Tensor:
  21475. r"""
  21476. randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21477. Returns a tensor filled with random numbers from a normal distribution
  21478. with mean `0` and variance `1` (also called the standard normal
  21479. distribution).
  21480. .. math::
  21481. \text{out}_{i} \sim \mathcal{N}(0, 1)
  21482. For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
  21483. unit variance as
  21484. .. math::
  21485. \text{out}_{i} \sim \mathcal{CN}(0, 1)
  21486. This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
  21487. :math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
  21488. .. math::
  21489. \operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
  21490. \operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
  21491. The shape of the tensor is defined by the variable argument :attr:`size`.
  21492. Args:
  21493. size (int...): a sequence of integers defining the shape of the output tensor.
  21494. Can be a variable number of arguments or a collection like a list or tuple.
  21495. Keyword args:
  21496. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21497. out (Tensor, optional): the output tensor.
  21498. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21499. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  21500. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21501. Default: ``torch.strided``.
  21502. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21503. Default: if ``None``, uses the current device for the default tensor type
  21504. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21505. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21506. requires_grad (bool, optional): If autograd should record operations on the
  21507. returned tensor. Default: ``False``.
  21508. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21509. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21510. Example::
  21511. >>> torch.randn(4)
  21512. tensor([-2.1436, 0.9966, 2.3426, -0.6366])
  21513. >>> torch.randn(2, 3)
  21514. tensor([[ 1.5954, 2.8929, -1.0923],
  21515. [ 1.1719, -0.4709, -0.1996]])
  21516. .. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
  21517. """
  21518. @overload
  21519. def randn(
  21520. size: Sequence[_int | SymInt],
  21521. *,
  21522. names: Sequence[str | EllipsisType | None] | None,
  21523. dtype: _dtype | None = None,
  21524. layout: _layout | None = None,
  21525. device: DeviceLikeType | None = None,
  21526. pin_memory: _bool | None = False,
  21527. requires_grad: _bool | None = False,
  21528. ) -> Tensor:
  21529. r"""
  21530. randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21531. Returns a tensor filled with random numbers from a normal distribution
  21532. with mean `0` and variance `1` (also called the standard normal
  21533. distribution).
  21534. .. math::
  21535. \text{out}_{i} \sim \mathcal{N}(0, 1)
  21536. For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
  21537. unit variance as
  21538. .. math::
  21539. \text{out}_{i} \sim \mathcal{CN}(0, 1)
  21540. This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
  21541. :math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
  21542. .. math::
  21543. \operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
  21544. \operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
  21545. The shape of the tensor is defined by the variable argument :attr:`size`.
  21546. Args:
  21547. size (int...): a sequence of integers defining the shape of the output tensor.
  21548. Can be a variable number of arguments or a collection like a list or tuple.
  21549. Keyword args:
  21550. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21551. out (Tensor, optional): the output tensor.
  21552. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21553. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  21554. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21555. Default: ``torch.strided``.
  21556. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21557. Default: if ``None``, uses the current device for the default tensor type
  21558. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21559. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21560. requires_grad (bool, optional): If autograd should record operations on the
  21561. returned tensor. Default: ``False``.
  21562. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21563. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21564. Example::
  21565. >>> torch.randn(4)
  21566. tensor([-2.1436, 0.9966, 2.3426, -0.6366])
  21567. >>> torch.randn(2, 3)
  21568. tensor([[ 1.5954, 2.8929, -1.0923],
  21569. [ 1.1719, -0.4709, -0.1996]])
  21570. .. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
  21571. """
  21572. @overload
  21573. def randn(
  21574. *size: _int | SymInt,
  21575. names: Sequence[str | EllipsisType | None] | None,
  21576. dtype: _dtype | None = None,
  21577. layout: _layout | None = None,
  21578. device: DeviceLikeType | None = None,
  21579. pin_memory: _bool | None = False,
  21580. requires_grad: _bool | None = False,
  21581. ) -> Tensor:
  21582. r"""
  21583. randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21584. Returns a tensor filled with random numbers from a normal distribution
  21585. with mean `0` and variance `1` (also called the standard normal
  21586. distribution).
  21587. .. math::
  21588. \text{out}_{i} \sim \mathcal{N}(0, 1)
  21589. For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
  21590. unit variance as
  21591. .. math::
  21592. \text{out}_{i} \sim \mathcal{CN}(0, 1)
  21593. This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
  21594. :math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
  21595. .. math::
  21596. \operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
  21597. \operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
  21598. The shape of the tensor is defined by the variable argument :attr:`size`.
  21599. Args:
  21600. size (int...): a sequence of integers defining the shape of the output tensor.
  21601. Can be a variable number of arguments or a collection like a list or tuple.
  21602. Keyword args:
  21603. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21604. out (Tensor, optional): the output tensor.
  21605. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21606. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  21607. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21608. Default: ``torch.strided``.
  21609. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21610. Default: if ``None``, uses the current device for the default tensor type
  21611. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21612. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21613. requires_grad (bool, optional): If autograd should record operations on the
  21614. returned tensor. Default: ``False``.
  21615. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21616. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21617. Example::
  21618. >>> torch.randn(4)
  21619. tensor([-2.1436, 0.9966, 2.3426, -0.6366])
  21620. >>> torch.randn(2, 3)
  21621. tensor([[ 1.5954, 2.8929, -1.0923],
  21622. [ 1.1719, -0.4709, -0.1996]])
  21623. .. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
  21624. """
  21625. @overload
  21626. def randn_like(
  21627. input: Tensor,
  21628. *,
  21629. generator: Generator | None,
  21630. memory_format: memory_format | None = None,
  21631. dtype: _dtype | None = None,
  21632. layout: _layout | None = None,
  21633. device: DeviceLikeType | None = None,
  21634. pin_memory: _bool | None = False,
  21635. requires_grad: _bool | None = False,
  21636. ) -> Tensor:
  21637. r"""
  21638. randn_like(input, *, generator=None, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  21639. Returns a tensor with the same size as :attr:`input` that is filled with
  21640. random numbers from a normal distribution with mean 0 and variance 1. Please refer to :func:`torch.randn` for the
  21641. sampling process of complex dtypes. ``torch.randn_like(input)`` is equivalent to
  21642. ``torch.randn(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
  21643. Args:
  21644. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  21645. Keyword args:
  21646. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
  21647. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  21648. Default: if ``None``, defaults to the dtype of :attr:`input`.
  21649. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  21650. Default: if ``None``, defaults to the layout of :attr:`input`.
  21651. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21652. Default: if ``None``, defaults to the device of :attr:`input`.
  21653. requires_grad (bool, optional): If autograd should record operations on the
  21654. returned tensor. Default: ``False``.
  21655. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  21656. returned Tensor. Default: ``torch.preserve_format``.
  21657. """
  21658. @overload
  21659. def randn_like(
  21660. input: Tensor,
  21661. *,
  21662. memory_format: memory_format | None = None,
  21663. dtype: _dtype | None = None,
  21664. layout: _layout | None = None,
  21665. device: DeviceLikeType | None = None,
  21666. pin_memory: _bool | None = False,
  21667. requires_grad: _bool | None = False,
  21668. ) -> Tensor:
  21669. r"""
  21670. randn_like(input, *, generator=None, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  21671. Returns a tensor with the same size as :attr:`input` that is filled with
  21672. random numbers from a normal distribution with mean 0 and variance 1. Please refer to :func:`torch.randn` for the
  21673. sampling process of complex dtypes. ``torch.randn_like(input)`` is equivalent to
  21674. ``torch.randn(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
  21675. Args:
  21676. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  21677. Keyword args:
  21678. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
  21679. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  21680. Default: if ``None``, defaults to the dtype of :attr:`input`.
  21681. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  21682. Default: if ``None``, defaults to the layout of :attr:`input`.
  21683. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21684. Default: if ``None``, defaults to the device of :attr:`input`.
  21685. requires_grad (bool, optional): If autograd should record operations on the
  21686. returned tensor. Default: ``False``.
  21687. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  21688. returned Tensor. Default: ``torch.preserve_format``.
  21689. """
  21690. @overload
  21691. def randperm(
  21692. n: _int | SymInt,
  21693. *,
  21694. generator: Generator | None,
  21695. out: Tensor | None = None,
  21696. dtype: _dtype | None = None,
  21697. layout: _layout | None = None,
  21698. device: DeviceLikeType | None = None,
  21699. pin_memory: _bool | None = False,
  21700. requires_grad: _bool | None = False,
  21701. ) -> Tensor:
  21702. r"""
  21703. randperm(n, *, generator=None, out=None, dtype=torch.int64,layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21704. Returns a random permutation of integers from ``0`` to ``n - 1``.
  21705. Args:
  21706. n (int): the upper bound (exclusive)
  21707. Keyword args:
  21708. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21709. out (Tensor, optional): the output tensor.
  21710. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21711. Default: ``torch.int64``.
  21712. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21713. Default: ``torch.strided``.
  21714. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21715. Default: if ``None``, uses the current device for the default tensor type
  21716. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21717. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21718. requires_grad (bool, optional): If autograd should record operations on the
  21719. returned tensor. Default: ``False``.
  21720. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21721. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21722. Example::
  21723. >>> torch.randperm(4)
  21724. tensor([2, 1, 0, 3])
  21725. """
  21726. @overload
  21727. def randperm(
  21728. n: _int | SymInt,
  21729. *,
  21730. out: Tensor | None = None,
  21731. dtype: _dtype | None = None,
  21732. layout: _layout | None = None,
  21733. device: DeviceLikeType | None = None,
  21734. pin_memory: _bool | None = False,
  21735. requires_grad: _bool | None = False,
  21736. ) -> Tensor:
  21737. r"""
  21738. randperm(n, *, generator=None, out=None, dtype=torch.int64,layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21739. Returns a random permutation of integers from ``0`` to ``n - 1``.
  21740. Args:
  21741. n (int): the upper bound (exclusive)
  21742. Keyword args:
  21743. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21744. out (Tensor, optional): the output tensor.
  21745. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21746. Default: ``torch.int64``.
  21747. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21748. Default: ``torch.strided``.
  21749. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21750. Default: if ``None``, uses the current device for the default tensor type
  21751. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21752. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21753. requires_grad (bool, optional): If autograd should record operations on the
  21754. returned tensor. Default: ``False``.
  21755. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21756. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21757. Example::
  21758. >>> torch.randperm(4)
  21759. tensor([2, 1, 0, 3])
  21760. """
  21761. def range(
  21762. start: Number,
  21763. end: Number,
  21764. step: Number = 1,
  21765. *,
  21766. out: Tensor | None = None,
  21767. dtype: _dtype | None = None,
  21768. device: DeviceLikeType | None = None,
  21769. requires_grad: _bool = False,
  21770. pin_memory: _bool = False,
  21771. ) -> Tensor:
  21772. r"""
  21773. range(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  21774. Returns a 1-D tensor of size :math:`\left\lfloor \frac{\text{end} - \text{start}}{\text{step}} \right\rfloor + 1`
  21775. with values from :attr:`start` to :attr:`end` with step :attr:`step`. Step is
  21776. the gap between two values in the tensor.
  21777. .. math::
  21778. \text{out}_{i+1} = \text{out}_i + \text{step}.
  21779. .. warning::
  21780. This function is deprecated and will be removed in a future release because its behavior is inconsistent with
  21781. Python's range builtin. Instead, use :func:`torch.arange`, which produces values in [start, end).
  21782. Args:
  21783. start (float, optional): the starting value for the set of points. Default: ``0``.
  21784. end (float): the ending value for the set of points
  21785. step (float, optional): the gap between each pair of adjacent points. Default: ``1``.
  21786. Keyword args:
  21787. out (Tensor, optional): the output tensor.
  21788. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21789. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). If `dtype` is not given, infer the data type from the other input
  21790. arguments. If any of `start`, `end`, or `step` are floating-point, the
  21791. `dtype` is inferred to be the default dtype, see
  21792. :meth:`~torch.get_default_dtype`. Otherwise, the `dtype` is inferred to
  21793. be `torch.int64`.
  21794. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21795. Default: ``torch.strided``.
  21796. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21797. Default: if ``None``, uses the current device for the default tensor type
  21798. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21799. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21800. requires_grad (bool, optional): If autograd should record operations on the
  21801. returned tensor. Default: ``False``.
  21802. Example::
  21803. >>> torch.range(1, 4)
  21804. tensor([ 1., 2., 3., 4.])
  21805. >>> torch.range(1, 4, 0.5)
  21806. tensor([ 1.0000, 1.5000, 2.0000, 2.5000, 3.0000, 3.5000, 4.0000])
  21807. """
  21808. def ravel(input: Tensor) -> Tensor:
  21809. r"""
  21810. ravel(input) -> Tensor
  21811. Return a contiguous flattened tensor. A copy is made only if needed.
  21812. Args:
  21813. input (Tensor): the input tensor.
  21814. Example::
  21815. >>> t = torch.tensor([[[1, 2],
  21816. ... [3, 4]],
  21817. ... [[5, 6],
  21818. ... [7, 8]]])
  21819. >>> torch.ravel(t)
  21820. tensor([1, 2, 3, 4, 5, 6, 7, 8])
  21821. """
  21822. def real(input: Tensor) -> Tensor:
  21823. r"""
  21824. real(input) -> Tensor
  21825. Returns a new tensor containing real values of the :attr:`self` tensor.
  21826. The returned tensor and :attr:`self` share the same underlying storage.
  21827. Args:
  21828. input (Tensor): the input tensor.
  21829. Example::
  21830. >>> x=torch.randn(4, dtype=torch.cfloat)
  21831. >>> x
  21832. tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
  21833. >>> x.real
  21834. tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
  21835. """
  21836. def reciprocal(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  21837. r"""
  21838. reciprocal(input, *, out=None) -> Tensor
  21839. Returns a new tensor with the reciprocal of the elements of :attr:`input`
  21840. .. math::
  21841. \text{out}_{i} = \frac{1}{\text{input}_{i}}
  21842. .. note::
  21843. Unlike NumPy's reciprocal, torch.reciprocal supports integral inputs. Integral
  21844. inputs to reciprocal are automatically :ref:`promoted <type-promotion-doc>` to
  21845. the default scalar type.
  21846. Args:
  21847. input (Tensor): the input tensor.
  21848. Keyword args:
  21849. out (Tensor, optional): the output tensor.
  21850. Example::
  21851. >>> a = torch.randn(4)
  21852. >>> a
  21853. tensor([-0.4595, -2.1219, -1.4314, 0.7298])
  21854. >>> torch.reciprocal(a)
  21855. tensor([-2.1763, -0.4713, -0.6986, 1.3702])
  21856. """
  21857. def reciprocal_(input: Tensor) -> Tensor: ...
  21858. def relu(input: Tensor) -> Tensor: ...
  21859. def relu_(input: Tensor) -> Tensor: ...
  21860. @overload
  21861. def remainder(
  21862. input: Tensor,
  21863. other: Tensor,
  21864. *,
  21865. out: Tensor | None = None,
  21866. ) -> Tensor:
  21867. r"""
  21868. remainder(input, other, *, out=None) -> Tensor
  21869. Computes
  21870. `Python's modulus operation <https://docs.python.org/3/reference/expressions.html#binary-arithmetic-operations>`_
  21871. entrywise. The result has the same sign as the divisor :attr:`other` and its absolute value
  21872. is less than that of :attr:`other`.
  21873. It may also be defined in terms of :func:`torch.div` as
  21874. .. code:: python
  21875. torch.remainder(a, b) == a - a.div(b, rounding_mode="floor") * b
  21876. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  21877. :ref:`type promotion <type-promotion-doc>`, and integer and float inputs.
  21878. .. note::
  21879. Complex inputs are not supported. In some cases, it is not mathematically
  21880. possible to satisfy the definition of a modulo operation with complex numbers.
  21881. See :func:`torch.fmod` for how division by zero is handled.
  21882. .. seealso::
  21883. :func:`torch.fmod` which implements C++'s `std::fmod <https://en.cppreference.com/w/cpp/numeric/math/fmod>`_.
  21884. This one is defined in terms of division rounding towards zero.
  21885. Args:
  21886. input (Tensor or Scalar): the dividend
  21887. other (Tensor or Scalar): the divisor
  21888. Keyword args:
  21889. out (Tensor, optional): the output tensor.
  21890. Example::
  21891. >>> torch.remainder(torch.tensor([-3., -2, -1, 1, 2, 3]), 2)
  21892. tensor([ 1., 0., 1., 1., 0., 1.])
  21893. >>> torch.remainder(torch.tensor([1, 2, 3, 4, 5]), -1.5)
  21894. tensor([ -0.5000, -1.0000, 0.0000, -0.5000, -1.0000 ])
  21895. """
  21896. @overload
  21897. def remainder(self: Number | _complex, other: Tensor) -> Tensor:
  21898. r"""
  21899. remainder(input, other, *, out=None) -> Tensor
  21900. Computes
  21901. `Python's modulus operation <https://docs.python.org/3/reference/expressions.html#binary-arithmetic-operations>`_
  21902. entrywise. The result has the same sign as the divisor :attr:`other` and its absolute value
  21903. is less than that of :attr:`other`.
  21904. It may also be defined in terms of :func:`torch.div` as
  21905. .. code:: python
  21906. torch.remainder(a, b) == a - a.div(b, rounding_mode="floor") * b
  21907. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  21908. :ref:`type promotion <type-promotion-doc>`, and integer and float inputs.
  21909. .. note::
  21910. Complex inputs are not supported. In some cases, it is not mathematically
  21911. possible to satisfy the definition of a modulo operation with complex numbers.
  21912. See :func:`torch.fmod` for how division by zero is handled.
  21913. .. seealso::
  21914. :func:`torch.fmod` which implements C++'s `std::fmod <https://en.cppreference.com/w/cpp/numeric/math/fmod>`_.
  21915. This one is defined in terms of division rounding towards zero.
  21916. Args:
  21917. input (Tensor or Scalar): the dividend
  21918. other (Tensor or Scalar): the divisor
  21919. Keyword args:
  21920. out (Tensor, optional): the output tensor.
  21921. Example::
  21922. >>> torch.remainder(torch.tensor([-3., -2, -1, 1, 2, 3]), 2)
  21923. tensor([ 1., 0., 1., 1., 0., 1.])
  21924. >>> torch.remainder(torch.tensor([1, 2, 3, 4, 5]), -1.5)
  21925. tensor([ -0.5000, -1.0000, 0.0000, -0.5000, -1.0000 ])
  21926. """
  21927. @overload
  21928. def remainder(
  21929. input: Tensor,
  21930. other: Number | _complex,
  21931. *,
  21932. out: Tensor | None = None,
  21933. ) -> Tensor:
  21934. r"""
  21935. remainder(input, other, *, out=None) -> Tensor
  21936. Computes
  21937. `Python's modulus operation <https://docs.python.org/3/reference/expressions.html#binary-arithmetic-operations>`_
  21938. entrywise. The result has the same sign as the divisor :attr:`other` and its absolute value
  21939. is less than that of :attr:`other`.
  21940. It may also be defined in terms of :func:`torch.div` as
  21941. .. code:: python
  21942. torch.remainder(a, b) == a - a.div(b, rounding_mode="floor") * b
  21943. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  21944. :ref:`type promotion <type-promotion-doc>`, and integer and float inputs.
  21945. .. note::
  21946. Complex inputs are not supported. In some cases, it is not mathematically
  21947. possible to satisfy the definition of a modulo operation with complex numbers.
  21948. See :func:`torch.fmod` for how division by zero is handled.
  21949. .. seealso::
  21950. :func:`torch.fmod` which implements C++'s `std::fmod <https://en.cppreference.com/w/cpp/numeric/math/fmod>`_.
  21951. This one is defined in terms of division rounding towards zero.
  21952. Args:
  21953. input (Tensor or Scalar): the dividend
  21954. other (Tensor or Scalar): the divisor
  21955. Keyword args:
  21956. out (Tensor, optional): the output tensor.
  21957. Example::
  21958. >>> torch.remainder(torch.tensor([-3., -2, -1, 1, 2, 3]), 2)
  21959. tensor([ 1., 0., 1., 1., 0., 1.])
  21960. >>> torch.remainder(torch.tensor([1, 2, 3, 4, 5]), -1.5)
  21961. tensor([ -0.5000, -1.0000, 0.0000, -0.5000, -1.0000 ])
  21962. """
  21963. def renorm(
  21964. input: Tensor,
  21965. p: Number | _complex,
  21966. dim: _int,
  21967. maxnorm: Number | _complex,
  21968. *,
  21969. out: Tensor | None = None,
  21970. ) -> Tensor:
  21971. r"""
  21972. renorm(input, p, dim, maxnorm, *, out=None) -> Tensor
  21973. Returns a tensor where each sub-tensor of :attr:`input` along dimension
  21974. :attr:`dim` is normalized such that the `p`-norm of the sub-tensor is lower
  21975. than the value :attr:`maxnorm`
  21976. .. note:: If the norm of a row is lower than `maxnorm`, the row is unchanged
  21977. Args:
  21978. input (Tensor): the input tensor.
  21979. p (float): the power for the norm computation
  21980. dim (int): the dimension to slice over to get the sub-tensors
  21981. maxnorm (float): the maximum norm to keep each sub-tensor under
  21982. Keyword args:
  21983. out (Tensor, optional): the output tensor.
  21984. Example::
  21985. >>> x = torch.ones(3, 3)
  21986. >>> x[1].fill_(2)
  21987. tensor([ 2., 2., 2.])
  21988. >>> x[2].fill_(3)
  21989. tensor([ 3., 3., 3.])
  21990. >>> x
  21991. tensor([[ 1., 1., 1.],
  21992. [ 2., 2., 2.],
  21993. [ 3., 3., 3.]])
  21994. >>> torch.renorm(x, 1, 0, 5)
  21995. tensor([[ 1.0000, 1.0000, 1.0000],
  21996. [ 1.6667, 1.6667, 1.6667],
  21997. [ 1.6667, 1.6667, 1.6667]])
  21998. """
  21999. @overload
  22000. def repeat_interleave(
  22001. input: Tensor,
  22002. repeats: Tensor,
  22003. dim: _int | None = None,
  22004. *,
  22005. output_size: _int | SymInt | None = None,
  22006. ) -> Tensor:
  22007. r"""
  22008. repeat_interleave(input, repeats, dim=None, *, output_size=None) -> Tensor
  22009. Repeat elements of a tensor.
  22010. .. warning::
  22011. This is different from :meth:`torch.Tensor.repeat` but similar to ``numpy.repeat``.
  22012. Args:
  22013. input (Tensor): the input tensor.
  22014. repeats (Tensor or int): The number of repetitions for each element.
  22015. repeats is broadcasted to fit the shape of the given axis.
  22016. dim (int, optional): The dimension along which to repeat values.
  22017. By default, use the flattened input array, and return a flat output
  22018. array.
  22019. Keyword args:
  22020. output_size (int, optional): Total output size for the given axis
  22021. ( e.g. sum of repeats). If given, it will avoid stream synchronization
  22022. needed to calculate output shape of the tensor.
  22023. Returns:
  22024. Tensor: Repeated tensor which has the same shape as input, except along the given axis.
  22025. Example::
  22026. >>> x = torch.tensor([1, 2, 3])
  22027. >>> x.repeat_interleave(2)
  22028. tensor([1, 1, 2, 2, 3, 3])
  22029. >>> y = torch.tensor([[1, 2], [3, 4]])
  22030. >>> torch.repeat_interleave(y, 2)
  22031. tensor([1, 1, 2, 2, 3, 3, 4, 4])
  22032. >>> torch.repeat_interleave(y, 3, dim=1)
  22033. tensor([[1, 1, 1, 2, 2, 2],
  22034. [3, 3, 3, 4, 4, 4]])
  22035. >>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0)
  22036. tensor([[1, 2],
  22037. [3, 4],
  22038. [3, 4]])
  22039. >>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0, output_size=3)
  22040. tensor([[1, 2],
  22041. [3, 4],
  22042. [3, 4]])
  22043. If the `repeats` is `tensor([n1, n2, n3, ...])`, then the output will be
  22044. `tensor([0, 0, ..., 1, 1, ..., 2, 2, ..., ...])` where `0` appears `n1` times,
  22045. `1` appears `n2` times, `2` appears `n3` times, etc.
  22046. .. function:: repeat_interleave(repeats, *) -> Tensor
  22047. :noindex:
  22048. Repeats 0 repeats[0] times, 1 repeats[1] times, 2 repeats[2] times, etc.
  22049. Args:
  22050. repeats (Tensor): The number of repetitions for each element.
  22051. Returns:
  22052. Tensor: Repeated tensor of size `sum(repeats)`.
  22053. Example::
  22054. >>> torch.repeat_interleave(torch.tensor([1, 2, 3]))
  22055. tensor([0, 1, 1, 2, 2, 2])
  22056. """
  22057. @overload
  22058. def repeat_interleave(
  22059. repeats: Tensor,
  22060. *,
  22061. output_size: _int | SymInt | None = None,
  22062. ) -> Tensor:
  22063. r"""
  22064. repeat_interleave(input, repeats, dim=None, *, output_size=None) -> Tensor
  22065. Repeat elements of a tensor.
  22066. .. warning::
  22067. This is different from :meth:`torch.Tensor.repeat` but similar to ``numpy.repeat``.
  22068. Args:
  22069. input (Tensor): the input tensor.
  22070. repeats (Tensor or int): The number of repetitions for each element.
  22071. repeats is broadcasted to fit the shape of the given axis.
  22072. dim (int, optional): The dimension along which to repeat values.
  22073. By default, use the flattened input array, and return a flat output
  22074. array.
  22075. Keyword args:
  22076. output_size (int, optional): Total output size for the given axis
  22077. ( e.g. sum of repeats). If given, it will avoid stream synchronization
  22078. needed to calculate output shape of the tensor.
  22079. Returns:
  22080. Tensor: Repeated tensor which has the same shape as input, except along the given axis.
  22081. Example::
  22082. >>> x = torch.tensor([1, 2, 3])
  22083. >>> x.repeat_interleave(2)
  22084. tensor([1, 1, 2, 2, 3, 3])
  22085. >>> y = torch.tensor([[1, 2], [3, 4]])
  22086. >>> torch.repeat_interleave(y, 2)
  22087. tensor([1, 1, 2, 2, 3, 3, 4, 4])
  22088. >>> torch.repeat_interleave(y, 3, dim=1)
  22089. tensor([[1, 1, 1, 2, 2, 2],
  22090. [3, 3, 3, 4, 4, 4]])
  22091. >>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0)
  22092. tensor([[1, 2],
  22093. [3, 4],
  22094. [3, 4]])
  22095. >>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0, output_size=3)
  22096. tensor([[1, 2],
  22097. [3, 4],
  22098. [3, 4]])
  22099. If the `repeats` is `tensor([n1, n2, n3, ...])`, then the output will be
  22100. `tensor([0, 0, ..., 1, 1, ..., 2, 2, ..., ...])` where `0` appears `n1` times,
  22101. `1` appears `n2` times, `2` appears `n3` times, etc.
  22102. .. function:: repeat_interleave(repeats, *) -> Tensor
  22103. :noindex:
  22104. Repeats 0 repeats[0] times, 1 repeats[1] times, 2 repeats[2] times, etc.
  22105. Args:
  22106. repeats (Tensor): The number of repetitions for each element.
  22107. Returns:
  22108. Tensor: Repeated tensor of size `sum(repeats)`.
  22109. Example::
  22110. >>> torch.repeat_interleave(torch.tensor([1, 2, 3]))
  22111. tensor([0, 1, 1, 2, 2, 2])
  22112. """
  22113. @overload
  22114. def repeat_interleave(
  22115. input: Tensor,
  22116. repeats: _int | SymInt,
  22117. dim: _int | None = None,
  22118. *,
  22119. output_size: _int | SymInt | None = None,
  22120. ) -> Tensor:
  22121. r"""
  22122. repeat_interleave(input, repeats, dim=None, *, output_size=None) -> Tensor
  22123. Repeat elements of a tensor.
  22124. .. warning::
  22125. This is different from :meth:`torch.Tensor.repeat` but similar to ``numpy.repeat``.
  22126. Args:
  22127. input (Tensor): the input tensor.
  22128. repeats (Tensor or int): The number of repetitions for each element.
  22129. repeats is broadcasted to fit the shape of the given axis.
  22130. dim (int, optional): The dimension along which to repeat values.
  22131. By default, use the flattened input array, and return a flat output
  22132. array.
  22133. Keyword args:
  22134. output_size (int, optional): Total output size for the given axis
  22135. ( e.g. sum of repeats). If given, it will avoid stream synchronization
  22136. needed to calculate output shape of the tensor.
  22137. Returns:
  22138. Tensor: Repeated tensor which has the same shape as input, except along the given axis.
  22139. Example::
  22140. >>> x = torch.tensor([1, 2, 3])
  22141. >>> x.repeat_interleave(2)
  22142. tensor([1, 1, 2, 2, 3, 3])
  22143. >>> y = torch.tensor([[1, 2], [3, 4]])
  22144. >>> torch.repeat_interleave(y, 2)
  22145. tensor([1, 1, 2, 2, 3, 3, 4, 4])
  22146. >>> torch.repeat_interleave(y, 3, dim=1)
  22147. tensor([[1, 1, 1, 2, 2, 2],
  22148. [3, 3, 3, 4, 4, 4]])
  22149. >>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0)
  22150. tensor([[1, 2],
  22151. [3, 4],
  22152. [3, 4]])
  22153. >>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0, output_size=3)
  22154. tensor([[1, 2],
  22155. [3, 4],
  22156. [3, 4]])
  22157. If the `repeats` is `tensor([n1, n2, n3, ...])`, then the output will be
  22158. `tensor([0, 0, ..., 1, 1, ..., 2, 2, ..., ...])` where `0` appears `n1` times,
  22159. `1` appears `n2` times, `2` appears `n3` times, etc.
  22160. .. function:: repeat_interleave(repeats, *) -> Tensor
  22161. :noindex:
  22162. Repeats 0 repeats[0] times, 1 repeats[1] times, 2 repeats[2] times, etc.
  22163. Args:
  22164. repeats (Tensor): The number of repetitions for each element.
  22165. Returns:
  22166. Tensor: Repeated tensor of size `sum(repeats)`.
  22167. Example::
  22168. >>> torch.repeat_interleave(torch.tensor([1, 2, 3]))
  22169. tensor([0, 1, 1, 2, 2, 2])
  22170. """
  22171. def reshape(input: Tensor, shape: Sequence[_int | SymInt]) -> Tensor:
  22172. r"""
  22173. reshape(input, shape) -> Tensor
  22174. Returns a tensor with the same data and number of elements as :attr:`input`,
  22175. but with the specified shape. When possible, the returned tensor will be a view
  22176. of :attr:`input`. Otherwise, it will be a copy. Contiguous inputs and inputs
  22177. with compatible strides can be reshaped without copying, but you should not
  22178. depend on the copying vs. viewing behavior.
  22179. See :meth:`torch.Tensor.view` on when it is possible to return a view.
  22180. A single dimension may be -1, in which case it's inferred from the remaining
  22181. dimensions and the number of elements in :attr:`input`.
  22182. Args:
  22183. input (Tensor): the tensor to be reshaped
  22184. shape (tuple of int): the new shape
  22185. Example::
  22186. >>> a = torch.arange(4.)
  22187. >>> torch.reshape(a, (2, 2))
  22188. tensor([[ 0., 1.],
  22189. [ 2., 3.]])
  22190. >>> b = torch.tensor([[0, 1], [2, 3]])
  22191. >>> torch.reshape(b, (-1,))
  22192. tensor([ 0, 1, 2, 3])
  22193. """
  22194. def resize_as_(
  22195. input: Tensor,
  22196. the_template: Tensor,
  22197. *,
  22198. memory_format: memory_format | None = None,
  22199. ) -> Tensor: ...
  22200. def resize_as_sparse_(input: Tensor, the_template: Tensor) -> Tensor: ...
  22201. def resolve_conj(input: Tensor) -> Tensor:
  22202. r"""
  22203. resolve_conj(input) -> Tensor
  22204. Returns a new tensor with materialized conjugation if :attr:`input`'s conjugate bit is set to `True`,
  22205. else returns :attr:`input`. The output tensor will always have its conjugate bit set to `False`.
  22206. Args:
  22207. input (Tensor): the input tensor.
  22208. Example::
  22209. >>> x = torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j])
  22210. >>> y = x.conj()
  22211. >>> y.is_conj()
  22212. True
  22213. >>> z = y.resolve_conj()
  22214. >>> z
  22215. tensor([-1 - 1j, -2 - 2j, 3 + 3j])
  22216. >>> z.is_conj()
  22217. False
  22218. """
  22219. def resolve_neg(input: Tensor) -> Tensor:
  22220. r"""
  22221. resolve_neg(input) -> Tensor
  22222. Returns a new tensor with materialized negation if :attr:`input`'s negative bit is set to `True`,
  22223. else returns :attr:`input`. The output tensor will always have its negative bit set to `False`.
  22224. Args:
  22225. input (Tensor): the input tensor.
  22226. Example::
  22227. >>> x = torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j])
  22228. >>> y = x.conj()
  22229. >>> z = y.imag
  22230. >>> z.is_neg()
  22231. True
  22232. >>> out = z.resolve_neg()
  22233. >>> out
  22234. tensor([-1., -2., 3.])
  22235. >>> out.is_neg()
  22236. False
  22237. """
  22238. @overload
  22239. def result_type(tensor: Tensor, other: Tensor) -> _dtype:
  22240. r"""
  22241. result_type(tensor1, tensor2) -> dtype
  22242. Returns the :class:`torch.dtype` that would result from performing an arithmetic
  22243. operation on the provided input tensors. See type promotion :ref:`documentation <type-promotion-doc>`
  22244. for more information on the type promotion logic.
  22245. Args:
  22246. tensor1 (Tensor or Number): an input tensor or number
  22247. tensor2 (Tensor or Number): an input tensor or number
  22248. Example::
  22249. >>> torch.result_type(torch.tensor([1, 2], dtype=torch.int), 1.0)
  22250. torch.float32
  22251. >>> torch.result_type(torch.tensor([1, 2], dtype=torch.uint8), torch.tensor(1))
  22252. torch.uint8
  22253. """
  22254. @overload
  22255. def result_type(scalar: Number | _complex, tensor: Tensor) -> _dtype:
  22256. r"""
  22257. result_type(tensor1, tensor2) -> dtype
  22258. Returns the :class:`torch.dtype` that would result from performing an arithmetic
  22259. operation on the provided input tensors. See type promotion :ref:`documentation <type-promotion-doc>`
  22260. for more information on the type promotion logic.
  22261. Args:
  22262. tensor1 (Tensor or Number): an input tensor or number
  22263. tensor2 (Tensor or Number): an input tensor or number
  22264. Example::
  22265. >>> torch.result_type(torch.tensor([1, 2], dtype=torch.int), 1.0)
  22266. torch.float32
  22267. >>> torch.result_type(torch.tensor([1, 2], dtype=torch.uint8), torch.tensor(1))
  22268. torch.uint8
  22269. """
  22270. @overload
  22271. def result_type(tensor: Tensor, other: Number | _complex) -> _dtype:
  22272. r"""
  22273. result_type(tensor1, tensor2) -> dtype
  22274. Returns the :class:`torch.dtype` that would result from performing an arithmetic
  22275. operation on the provided input tensors. See type promotion :ref:`documentation <type-promotion-doc>`
  22276. for more information on the type promotion logic.
  22277. Args:
  22278. tensor1 (Tensor or Number): an input tensor or number
  22279. tensor2 (Tensor or Number): an input tensor or number
  22280. Example::
  22281. >>> torch.result_type(torch.tensor([1, 2], dtype=torch.int), 1.0)
  22282. torch.float32
  22283. >>> torch.result_type(torch.tensor([1, 2], dtype=torch.uint8), torch.tensor(1))
  22284. torch.uint8
  22285. """
  22286. @overload
  22287. def result_type(
  22288. scalar1: Number | _complex,
  22289. scalar2: Number | _complex,
  22290. ) -> _dtype:
  22291. r"""
  22292. result_type(tensor1, tensor2) -> dtype
  22293. Returns the :class:`torch.dtype` that would result from performing an arithmetic
  22294. operation on the provided input tensors. See type promotion :ref:`documentation <type-promotion-doc>`
  22295. for more information on the type promotion logic.
  22296. Args:
  22297. tensor1 (Tensor or Number): an input tensor or number
  22298. tensor2 (Tensor or Number): an input tensor or number
  22299. Example::
  22300. >>> torch.result_type(torch.tensor([1, 2], dtype=torch.int), 1.0)
  22301. torch.float32
  22302. >>> torch.result_type(torch.tensor([1, 2], dtype=torch.uint8), torch.tensor(1))
  22303. torch.uint8
  22304. """
  22305. def rms_norm(
  22306. input: Tensor,
  22307. normalized_shape: Sequence[_int | SymInt],
  22308. weight: Tensor | None = None,
  22309. eps: _float | None = None,
  22310. ) -> Tensor: ...
  22311. @overload
  22312. def rnn_relu(
  22313. data: Tensor,
  22314. batch_sizes: Tensor,
  22315. hx: Tensor,
  22316. params: tuple[Tensor, ...] | list[Tensor] | None,
  22317. has_biases: _bool,
  22318. num_layers: _int,
  22319. dropout: _float,
  22320. train: _bool,
  22321. bidirectional: _bool,
  22322. ) -> tuple[Tensor, Tensor]: ...
  22323. @overload
  22324. def rnn_relu(
  22325. input: Tensor,
  22326. hx: Tensor,
  22327. params: tuple[Tensor, ...] | list[Tensor] | None,
  22328. has_biases: _bool,
  22329. num_layers: _int,
  22330. dropout: _float,
  22331. train: _bool,
  22332. bidirectional: _bool,
  22333. batch_first: _bool,
  22334. ) -> tuple[Tensor, Tensor]: ...
  22335. def rnn_relu_cell(
  22336. input: Tensor,
  22337. hx: Tensor,
  22338. w_ih: Tensor,
  22339. w_hh: Tensor,
  22340. b_ih: Tensor | None = None,
  22341. b_hh: Tensor | None = None,
  22342. ) -> Tensor: ...
  22343. @overload
  22344. def rnn_tanh(
  22345. data: Tensor,
  22346. batch_sizes: Tensor,
  22347. hx: Tensor,
  22348. params: tuple[Tensor, ...] | list[Tensor] | None,
  22349. has_biases: _bool,
  22350. num_layers: _int,
  22351. dropout: _float,
  22352. train: _bool,
  22353. bidirectional: _bool,
  22354. ) -> tuple[Tensor, Tensor]: ...
  22355. @overload
  22356. def rnn_tanh(
  22357. input: Tensor,
  22358. hx: Tensor,
  22359. params: tuple[Tensor, ...] | list[Tensor] | None,
  22360. has_biases: _bool,
  22361. num_layers: _int,
  22362. dropout: _float,
  22363. train: _bool,
  22364. bidirectional: _bool,
  22365. batch_first: _bool,
  22366. ) -> tuple[Tensor, Tensor]: ...
  22367. def rnn_tanh_cell(
  22368. input: Tensor,
  22369. hx: Tensor,
  22370. w_ih: Tensor,
  22371. w_hh: Tensor,
  22372. b_ih: Tensor | None = None,
  22373. b_hh: Tensor | None = None,
  22374. ) -> Tensor: ...
  22375. def roll(
  22376. input: Tensor,
  22377. shifts: _int | SymInt | Sequence[_int | SymInt],
  22378. dims: _int | _size = (),
  22379. ) -> Tensor:
  22380. r"""
  22381. roll(input, shifts, dims=None) -> Tensor
  22382. Roll the tensor :attr:`input` along the given dimension(s). Elements that are
  22383. shifted beyond the last position are re-introduced at the first position. If
  22384. :attr:`dims` is `None`, the tensor will be flattened before rolling and then
  22385. restored to the original shape.
  22386. Args:
  22387. input (Tensor): the input tensor.
  22388. shifts (int or tuple of ints): The number of places by which the elements
  22389. of the tensor are shifted. If shifts is a tuple, dims must be a tuple of
  22390. the same size, and each dimension will be rolled by the corresponding
  22391. value
  22392. dims (int or tuple of ints): Axis along which to roll
  22393. Example::
  22394. >>> x = torch.tensor([1, 2, 3, 4, 5, 6, 7, 8]).view(4, 2)
  22395. >>> x
  22396. tensor([[1, 2],
  22397. [3, 4],
  22398. [5, 6],
  22399. [7, 8]])
  22400. >>> torch.roll(x, 1)
  22401. tensor([[8, 1],
  22402. [2, 3],
  22403. [4, 5],
  22404. [6, 7]])
  22405. >>> torch.roll(x, 1, 0)
  22406. tensor([[7, 8],
  22407. [1, 2],
  22408. [3, 4],
  22409. [5, 6]])
  22410. >>> torch.roll(x, -1, 0)
  22411. tensor([[3, 4],
  22412. [5, 6],
  22413. [7, 8],
  22414. [1, 2]])
  22415. >>> torch.roll(x, shifts=(2, 1), dims=(0, 1))
  22416. tensor([[6, 5],
  22417. [8, 7],
  22418. [2, 1],
  22419. [4, 3]])
  22420. """
  22421. def rot90(input: Tensor, k: _int = 1, dims: _size = (0, 1)) -> Tensor:
  22422. r"""
  22423. rot90(input, k=1, dims=(0, 1)) -> Tensor
  22424. Rotate an n-D tensor by 90 degrees in the plane specified by dims axis.
  22425. Rotation direction is from the first towards the second axis if k > 0, and from the second towards the first for k < 0.
  22426. Args:
  22427. input (Tensor): the input tensor.
  22428. k (int): number of times to rotate. Default value is 1
  22429. dims (a list or tuple): axis to rotate. Default value is [0, 1]
  22430. Example::
  22431. >>> x = torch.arange(4).view(2, 2)
  22432. >>> x
  22433. tensor([[0, 1],
  22434. [2, 3]])
  22435. >>> torch.rot90(x, 1, [0, 1])
  22436. tensor([[1, 3],
  22437. [0, 2]])
  22438. >>> x = torch.arange(8).view(2, 2, 2)
  22439. >>> x
  22440. tensor([[[0, 1],
  22441. [2, 3]],
  22442. [[4, 5],
  22443. [6, 7]]])
  22444. >>> torch.rot90(x, 1, [1, 2])
  22445. tensor([[[1, 3],
  22446. [0, 2]],
  22447. [[5, 7],
  22448. [4, 6]]])
  22449. """
  22450. @overload
  22451. def round(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  22452. r"""
  22453. round(input, *, decimals=0, out=None) -> Tensor
  22454. Rounds elements of :attr:`input` to the nearest integer.
  22455. For integer inputs, follows the array-api convention of returning a
  22456. copy of the input tensor.
  22457. The return type of output is same as that of input's dtype.
  22458. .. note::
  22459. This function implements the "round half to even" to
  22460. break ties when a number is equidistant from two
  22461. integers (e.g. `round(2.5)` is 2).
  22462. When the :attr:\`decimals\` argument is specified the
  22463. algorithm used is similar to NumPy's `around`. This
  22464. algorithm is fast but inexact and it can easily
  22465. overflow for low precision dtypes.
  22466. Eg. `round(tensor([10000], dtype=torch.float16), decimals=3)` is `inf`.
  22467. .. seealso::
  22468. :func:`torch.ceil`, which rounds up.
  22469. :func:`torch.floor`, which rounds down.
  22470. :func:`torch.trunc`, which rounds towards zero.
  22471. Args:
  22472. input (Tensor): the input tensor.
  22473. decimals (int): Number of decimal places to round to (default: 0).
  22474. If decimals is negative, it specifies the number of positions
  22475. to the left of the decimal point.
  22476. Keyword args:
  22477. out (Tensor, optional): the output tensor.
  22478. Example::
  22479. >>> torch.round(torch.tensor((4.7, -2.3, 9.1, -7.7)))
  22480. tensor([ 5., -2., 9., -8.])
  22481. >>> # Values equidistant from two integers are rounded towards the
  22482. >>> # the nearest even value (zero is treated as even)
  22483. >>> torch.round(torch.tensor([-0.5, 0.5, 1.5, 2.5]))
  22484. tensor([-0., 0., 2., 2.])
  22485. >>> # A positive decimals argument rounds to the to that decimal place
  22486. >>> torch.round(torch.tensor([0.1234567]), decimals=3)
  22487. tensor([0.1230])
  22488. >>> # A negative decimals argument rounds to the left of the decimal
  22489. >>> torch.round(torch.tensor([1200.1234567]), decimals=-3)
  22490. tensor([1000.])
  22491. """
  22492. @overload
  22493. def round(
  22494. input: Tensor,
  22495. *,
  22496. decimals: _int,
  22497. out: Tensor | None = None,
  22498. ) -> Tensor:
  22499. r"""
  22500. round(input, *, decimals=0, out=None) -> Tensor
  22501. Rounds elements of :attr:`input` to the nearest integer.
  22502. For integer inputs, follows the array-api convention of returning a
  22503. copy of the input tensor.
  22504. The return type of output is same as that of input's dtype.
  22505. .. note::
  22506. This function implements the "round half to even" to
  22507. break ties when a number is equidistant from two
  22508. integers (e.g. `round(2.5)` is 2).
  22509. When the :attr:\`decimals\` argument is specified the
  22510. algorithm used is similar to NumPy's `around`. This
  22511. algorithm is fast but inexact and it can easily
  22512. overflow for low precision dtypes.
  22513. Eg. `round(tensor([10000], dtype=torch.float16), decimals=3)` is `inf`.
  22514. .. seealso::
  22515. :func:`torch.ceil`, which rounds up.
  22516. :func:`torch.floor`, which rounds down.
  22517. :func:`torch.trunc`, which rounds towards zero.
  22518. Args:
  22519. input (Tensor): the input tensor.
  22520. decimals (int): Number of decimal places to round to (default: 0).
  22521. If decimals is negative, it specifies the number of positions
  22522. to the left of the decimal point.
  22523. Keyword args:
  22524. out (Tensor, optional): the output tensor.
  22525. Example::
  22526. >>> torch.round(torch.tensor((4.7, -2.3, 9.1, -7.7)))
  22527. tensor([ 5., -2., 9., -8.])
  22528. >>> # Values equidistant from two integers are rounded towards the
  22529. >>> # the nearest even value (zero is treated as even)
  22530. >>> torch.round(torch.tensor([-0.5, 0.5, 1.5, 2.5]))
  22531. tensor([-0., 0., 2., 2.])
  22532. >>> # A positive decimals argument rounds to the to that decimal place
  22533. >>> torch.round(torch.tensor([0.1234567]), decimals=3)
  22534. tensor([0.1230])
  22535. >>> # A negative decimals argument rounds to the left of the decimal
  22536. >>> torch.round(torch.tensor([1200.1234567]), decimals=-3)
  22537. tensor([1000.])
  22538. """
  22539. @overload
  22540. def round_(input: Tensor) -> Tensor: ...
  22541. @overload
  22542. def round_(input: Tensor, *, decimals: _int) -> Tensor: ...
  22543. def row_indices_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor: ...
  22544. def row_stack(
  22545. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  22546. *,
  22547. out: Tensor | None = None,
  22548. ) -> Tensor:
  22549. r"""
  22550. row_stack(tensors, *, out=None) -> Tensor
  22551. Alias of :func:`torch.vstack`.
  22552. """
  22553. def rrelu(
  22554. input: Tensor,
  22555. lower: Number | _complex = 0.125,
  22556. upper: Number | _complex = 0.3333333333333333,
  22557. training: _bool = False,
  22558. generator: Generator | None = None,
  22559. ) -> Tensor: ...
  22560. def rrelu_(
  22561. input: Tensor,
  22562. lower: Number | _complex = 0.125,
  22563. upper: Number | _complex = 0.3333333333333333,
  22564. training: _bool = False,
  22565. generator: Generator | None = None,
  22566. ) -> Tensor: ...
  22567. def rsqrt(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  22568. r"""
  22569. rsqrt(input, *, out=None) -> Tensor
  22570. Returns a new tensor with the reciprocal of the square-root of each of
  22571. the elements of :attr:`input`.
  22572. .. math::
  22573. \text{out}_{i} = \frac{1}{\sqrt{\text{input}_{i}}}
  22574. Args:
  22575. input (Tensor): the input tensor.
  22576. Keyword args:
  22577. out (Tensor, optional): the output tensor.
  22578. Example::
  22579. >>> a = torch.randn(4)
  22580. >>> a
  22581. tensor([-0.0370, 0.2970, 1.5420, -0.9105])
  22582. >>> torch.rsqrt(a)
  22583. tensor([ nan, 1.8351, 0.8053, nan])
  22584. """
  22585. def rsqrt_(input: Tensor) -> Tensor: ...
  22586. @overload
  22587. def rsub(
  22588. input: Tensor,
  22589. other: Tensor,
  22590. *,
  22591. alpha: Number | _complex = 1,
  22592. ) -> Tensor: ...
  22593. @overload
  22594. def rsub(
  22595. input: Tensor,
  22596. other: Number | _complex,
  22597. alpha: Number | _complex = 1,
  22598. ) -> Tensor: ...
  22599. def saddmm(
  22600. input: Tensor,
  22601. mat1: Tensor,
  22602. mat2: Tensor,
  22603. *,
  22604. beta: Number = 1,
  22605. alpha: Number = 1,
  22606. out: Tensor | None = None,
  22607. ) -> Tensor: ...
  22608. def scalar_tensor(
  22609. s: Number | _complex,
  22610. *,
  22611. dtype: _dtype | None = None,
  22612. layout: _layout | None = None,
  22613. device: DeviceLikeType | None = None,
  22614. pin_memory: _bool | None = False,
  22615. requires_grad: _bool | None = False,
  22616. ) -> Tensor: ...
  22617. @overload
  22618. def scatter(
  22619. input: Tensor,
  22620. dim: _int,
  22621. index: Tensor,
  22622. src: Tensor,
  22623. *,
  22624. reduce: str,
  22625. out: Tensor | None = None,
  22626. ) -> Tensor:
  22627. r"""
  22628. scatter(input, dim, index, src) -> Tensor
  22629. Out-of-place version of :meth:`torch.Tensor.scatter_`
  22630. """
  22631. @overload
  22632. def scatter(
  22633. input: Tensor,
  22634. dim: _int,
  22635. index: Tensor,
  22636. src: Tensor,
  22637. *,
  22638. out: Tensor | None = None,
  22639. ) -> Tensor:
  22640. r"""
  22641. scatter(input, dim, index, src) -> Tensor
  22642. Out-of-place version of :meth:`torch.Tensor.scatter_`
  22643. """
  22644. @overload
  22645. def scatter(
  22646. input: Tensor,
  22647. dim: _int,
  22648. index: Tensor,
  22649. value: Number | _complex,
  22650. *,
  22651. reduce: str,
  22652. out: Tensor | None = None,
  22653. ) -> Tensor:
  22654. r"""
  22655. scatter(input, dim, index, src) -> Tensor
  22656. Out-of-place version of :meth:`torch.Tensor.scatter_`
  22657. """
  22658. @overload
  22659. def scatter(
  22660. input: Tensor,
  22661. dim: str | EllipsisType | None,
  22662. index: Tensor,
  22663. src: Tensor,
  22664. ) -> Tensor:
  22665. r"""
  22666. scatter(input, dim, index, src) -> Tensor
  22667. Out-of-place version of :meth:`torch.Tensor.scatter_`
  22668. """
  22669. @overload
  22670. def scatter(
  22671. input: Tensor,
  22672. dim: _int,
  22673. index: Tensor,
  22674. value: Number | _complex,
  22675. *,
  22676. out: Tensor | None = None,
  22677. ) -> Tensor:
  22678. r"""
  22679. scatter(input, dim, index, src) -> Tensor
  22680. Out-of-place version of :meth:`torch.Tensor.scatter_`
  22681. """
  22682. @overload
  22683. def scatter(
  22684. input: Tensor,
  22685. dim: str | EllipsisType | None,
  22686. index: Tensor,
  22687. value: Number | _complex,
  22688. ) -> Tensor:
  22689. r"""
  22690. scatter(input, dim, index, src) -> Tensor
  22691. Out-of-place version of :meth:`torch.Tensor.scatter_`
  22692. """
  22693. @overload
  22694. def scatter_add(
  22695. input: Tensor,
  22696. dim: _int,
  22697. index: Tensor,
  22698. src: Tensor,
  22699. *,
  22700. out: Tensor | None = None,
  22701. ) -> Tensor:
  22702. r"""
  22703. scatter_add(input, dim, index, src) -> Tensor
  22704. Out-of-place version of :meth:`torch.Tensor.scatter_add_`
  22705. """
  22706. @overload
  22707. def scatter_add(
  22708. input: Tensor,
  22709. dim: str | EllipsisType | None,
  22710. index: Tensor,
  22711. src: Tensor,
  22712. ) -> Tensor:
  22713. r"""
  22714. scatter_add(input, dim, index, src) -> Tensor
  22715. Out-of-place version of :meth:`torch.Tensor.scatter_add_`
  22716. """
  22717. def scatter_reduce(
  22718. input: Tensor,
  22719. dim: _int,
  22720. index: Tensor,
  22721. src: Tensor,
  22722. reduce: str,
  22723. *,
  22724. include_self: _bool = True,
  22725. out: Tensor | None = None,
  22726. ) -> Tensor:
  22727. r"""
  22728. scatter_reduce(input, dim, index, src, reduce, *, include_self=True) -> Tensor
  22729. Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
  22730. """
  22731. @overload
  22732. def searchsorted(
  22733. sorted_sequence: Tensor,
  22734. input: Tensor,
  22735. *,
  22736. out_int32: _bool = False,
  22737. right: _bool = False,
  22738. side: str | None = None,
  22739. sorter: Tensor | None = None,
  22740. out: Tensor | None = None,
  22741. ) -> Tensor:
  22742. r"""
  22743. searchsorted(sorted_sequence, values, *, out_int32=False, right=False, side=None, out=None, sorter=None) -> Tensor
  22744. Find the indices from the *innermost* dimension of :attr:`sorted_sequence` such that, if the
  22745. corresponding values in :attr:`values` were inserted before the indices, when sorted, the order
  22746. of the corresponding *innermost* dimension within :attr:`sorted_sequence` would be preserved.
  22747. Return a new tensor with the same size as :attr:`values`. More formally,
  22748. the returned index satisfies the following rules:
  22749. .. list-table::
  22750. :widths: 12 10 78
  22751. :header-rows: 1
  22752. * - :attr:`sorted_sequence`
  22753. - :attr:`right`
  22754. - *returned index satisfies*
  22755. * - 1-D
  22756. - False
  22757. - ``sorted_sequence[i-1] < values[m][n]...[l][x] <= sorted_sequence[i]``
  22758. * - 1-D
  22759. - True
  22760. - ``sorted_sequence[i-1] <= values[m][n]...[l][x] < sorted_sequence[i]``
  22761. * - N-D
  22762. - False
  22763. - ``sorted_sequence[m][n]...[l][i-1] < values[m][n]...[l][x] <= sorted_sequence[m][n]...[l][i]``
  22764. * - N-D
  22765. - True
  22766. - ``sorted_sequence[m][n]...[l][i-1] <= values[m][n]...[l][x] < sorted_sequence[m][n]...[l][i]``
  22767. Args:
  22768. sorted_sequence (Tensor): N-D or 1-D tensor, containing monotonically increasing sequence on the *innermost*
  22769. dimension unless :attr:`sorter` is provided, in which case the sequence does not
  22770. need to be sorted
  22771. values (Tensor or Scalar): N-D tensor or a Scalar containing the search value(s).
  22772. Keyword args:
  22773. out_int32 (bool, optional): indicate the output data type. torch.int32 if True, torch.int64 otherwise.
  22774. Default value is False, i.e. default output data type is torch.int64.
  22775. right (bool, optional): if False, return the first suitable location that is found. If True, return the
  22776. last such index. If no suitable index found, return 0 for non-numerical value
  22777. (eg. nan, inf) or the size of *innermost* dimension within :attr:`sorted_sequence`
  22778. (one pass the last index of the *innermost* dimension). In other words, if False,
  22779. gets the lower bound index for each value in :attr:`values` on the corresponding
  22780. *innermost* dimension of the :attr:`sorted_sequence`. If True, gets the upper
  22781. bound index instead. Default value is False. :attr:`side` does the same and is
  22782. preferred. It will error if :attr:`side` is set to "left" while this is True.
  22783. side (str, optional): the same as :attr:`right` but preferred. "left" corresponds to False for :attr:`right`
  22784. and "right" corresponds to True for :attr:`right`. It will error if this is set to
  22785. "left" while :attr:`right` is True. Default value is None.
  22786. out (Tensor, optional): the output tensor, must be the same size as :attr:`values` if provided.
  22787. sorter (LongTensor, optional): if provided, a tensor matching the shape of the unsorted
  22788. :attr:`sorted_sequence` containing a sequence of indices that sort it in the
  22789. ascending order on the innermost dimension
  22790. Example::
  22791. >>> sorted_sequence = torch.tensor([[1, 3, 5, 7, 9], [2, 4, 6, 8, 10]])
  22792. >>> sorted_sequence
  22793. tensor([[ 1, 3, 5, 7, 9],
  22794. [ 2, 4, 6, 8, 10]])
  22795. >>> values = torch.tensor([[3, 6, 9], [3, 6, 9]])
  22796. >>> values
  22797. tensor([[3, 6, 9],
  22798. [3, 6, 9]])
  22799. >>> torch.searchsorted(sorted_sequence, values)
  22800. tensor([[1, 3, 4],
  22801. [1, 2, 4]])
  22802. >>> torch.searchsorted(sorted_sequence, values, side='right')
  22803. tensor([[2, 3, 5],
  22804. [1, 3, 4]])
  22805. >>> sorted_sequence_1d = torch.tensor([1, 3, 5, 7, 9])
  22806. >>> sorted_sequence_1d
  22807. tensor([1, 3, 5, 7, 9])
  22808. >>> torch.searchsorted(sorted_sequence_1d, values)
  22809. tensor([[1, 3, 4],
  22810. [1, 3, 4]])
  22811. """
  22812. @overload
  22813. def searchsorted(
  22814. sorted_sequence: Tensor,
  22815. self: Number | _complex,
  22816. *,
  22817. out_int32: _bool = False,
  22818. right: _bool = False,
  22819. side: str | None = None,
  22820. sorter: Tensor | None = None,
  22821. out: Tensor | None = None,
  22822. ) -> Tensor:
  22823. r"""
  22824. searchsorted(sorted_sequence, values, *, out_int32=False, right=False, side=None, out=None, sorter=None) -> Tensor
  22825. Find the indices from the *innermost* dimension of :attr:`sorted_sequence` such that, if the
  22826. corresponding values in :attr:`values` were inserted before the indices, when sorted, the order
  22827. of the corresponding *innermost* dimension within :attr:`sorted_sequence` would be preserved.
  22828. Return a new tensor with the same size as :attr:`values`. More formally,
  22829. the returned index satisfies the following rules:
  22830. .. list-table::
  22831. :widths: 12 10 78
  22832. :header-rows: 1
  22833. * - :attr:`sorted_sequence`
  22834. - :attr:`right`
  22835. - *returned index satisfies*
  22836. * - 1-D
  22837. - False
  22838. - ``sorted_sequence[i-1] < values[m][n]...[l][x] <= sorted_sequence[i]``
  22839. * - 1-D
  22840. - True
  22841. - ``sorted_sequence[i-1] <= values[m][n]...[l][x] < sorted_sequence[i]``
  22842. * - N-D
  22843. - False
  22844. - ``sorted_sequence[m][n]...[l][i-1] < values[m][n]...[l][x] <= sorted_sequence[m][n]...[l][i]``
  22845. * - N-D
  22846. - True
  22847. - ``sorted_sequence[m][n]...[l][i-1] <= values[m][n]...[l][x] < sorted_sequence[m][n]...[l][i]``
  22848. Args:
  22849. sorted_sequence (Tensor): N-D or 1-D tensor, containing monotonically increasing sequence on the *innermost*
  22850. dimension unless :attr:`sorter` is provided, in which case the sequence does not
  22851. need to be sorted
  22852. values (Tensor or Scalar): N-D tensor or a Scalar containing the search value(s).
  22853. Keyword args:
  22854. out_int32 (bool, optional): indicate the output data type. torch.int32 if True, torch.int64 otherwise.
  22855. Default value is False, i.e. default output data type is torch.int64.
  22856. right (bool, optional): if False, return the first suitable location that is found. If True, return the
  22857. last such index. If no suitable index found, return 0 for non-numerical value
  22858. (eg. nan, inf) or the size of *innermost* dimension within :attr:`sorted_sequence`
  22859. (one pass the last index of the *innermost* dimension). In other words, if False,
  22860. gets the lower bound index for each value in :attr:`values` on the corresponding
  22861. *innermost* dimension of the :attr:`sorted_sequence`. If True, gets the upper
  22862. bound index instead. Default value is False. :attr:`side` does the same and is
  22863. preferred. It will error if :attr:`side` is set to "left" while this is True.
  22864. side (str, optional): the same as :attr:`right` but preferred. "left" corresponds to False for :attr:`right`
  22865. and "right" corresponds to True for :attr:`right`. It will error if this is set to
  22866. "left" while :attr:`right` is True. Default value is None.
  22867. out (Tensor, optional): the output tensor, must be the same size as :attr:`values` if provided.
  22868. sorter (LongTensor, optional): if provided, a tensor matching the shape of the unsorted
  22869. :attr:`sorted_sequence` containing a sequence of indices that sort it in the
  22870. ascending order on the innermost dimension
  22871. Example::
  22872. >>> sorted_sequence = torch.tensor([[1, 3, 5, 7, 9], [2, 4, 6, 8, 10]])
  22873. >>> sorted_sequence
  22874. tensor([[ 1, 3, 5, 7, 9],
  22875. [ 2, 4, 6, 8, 10]])
  22876. >>> values = torch.tensor([[3, 6, 9], [3, 6, 9]])
  22877. >>> values
  22878. tensor([[3, 6, 9],
  22879. [3, 6, 9]])
  22880. >>> torch.searchsorted(sorted_sequence, values)
  22881. tensor([[1, 3, 4],
  22882. [1, 2, 4]])
  22883. >>> torch.searchsorted(sorted_sequence, values, side='right')
  22884. tensor([[2, 3, 5],
  22885. [1, 3, 4]])
  22886. >>> sorted_sequence_1d = torch.tensor([1, 3, 5, 7, 9])
  22887. >>> sorted_sequence_1d
  22888. tensor([1, 3, 5, 7, 9])
  22889. >>> torch.searchsorted(sorted_sequence_1d, values)
  22890. tensor([[1, 3, 4],
  22891. [1, 3, 4]])
  22892. """
  22893. def segment_reduce(
  22894. data: Tensor,
  22895. reduce: str,
  22896. *,
  22897. lengths: Tensor | None = None,
  22898. indices: Tensor | None = None,
  22899. offsets: Tensor | None = None,
  22900. axis: _int = 0,
  22901. unsafe: _bool = False,
  22902. initial: Number | _complex | None = None,
  22903. ) -> Tensor:
  22904. r"""
  22905. segment_reduce(data: Tensor, reduce: str, *, lengths: Tensor | None = None, indices: Tensor | None = None, offsets: Tensor | None = None, axis: _int = 0, unsafe: _bool = False, initial: Number | _complex | None = None) -> Tensor # noqa: B950
  22906. Perform a segment reduction operation on the input tensor along the specified axis.
  22907. Args:
  22908. data (Tensor): The input tensor on which the segment reduction operation will be performed.
  22909. reduce (str): The type of reduction operation. Supported values are ``sum``, ``mean``, ``max``, ``min``, ``prod``.
  22910. Keyword args:
  22911. lengths (Tensor, optional): Length of each segment. Default: ``None``.
  22912. offsets (Tensor, optional): Offset of each segment. Default: ``None``.
  22913. axis (int, optional): The axis perform reduction. Default: ``0``.
  22914. unsafe (bool, optional): Skip validation If `True`. Default: ``False``.
  22915. initial (Number, optional): The initial value for the reduction operation. Default: ``None``.
  22916. Example::
  22917. >>> data = torch.tensor([[1, 2, 3, 4],[5, 6, 7, 8],[9, 10, 11, 12]], dtype=torch.float32, device='cuda')
  22918. >>> lengths = torch.tensor([2, 1], device='cuda')
  22919. >>> torch.segment_reduce(data, 'max', lengths=lengths)
  22920. tensor([[ 5., 6., 7., 8.],
  22921. [ 9., 10., 11., 12.]], device='cuda:0')
  22922. """
  22923. @overload
  22924. def select(input: Tensor, dim: _int, index: _int | SymInt) -> Tensor:
  22925. r"""
  22926. select(input, dim, index) -> Tensor
  22927. Slices the :attr:`input` tensor along the selected dimension at the given index.
  22928. This function returns a view of the original tensor with the given dimension removed.
  22929. .. note:: If :attr:`input` is a sparse tensor and returning a view of
  22930. the tensor is not possible, a RuntimeError exception is
  22931. raised. In this is the case, consider using
  22932. :func:`torch.select_copy` function.
  22933. Args:
  22934. input (Tensor): the input tensor.
  22935. dim (int): the dimension to slice
  22936. index (int): the index to select with
  22937. .. note::
  22938. :meth:`select` is equivalent to slicing. For example,
  22939. ``tensor.select(0, index)`` is equivalent to ``tensor[index]`` and
  22940. ``tensor.select(2, index)`` is equivalent to ``tensor[:,:,index]``.
  22941. """
  22942. @overload
  22943. def select(
  22944. input: Tensor,
  22945. dim: str | EllipsisType | None,
  22946. index: _int,
  22947. ) -> Tensor:
  22948. r"""
  22949. select(input, dim, index) -> Tensor
  22950. Slices the :attr:`input` tensor along the selected dimension at the given index.
  22951. This function returns a view of the original tensor with the given dimension removed.
  22952. .. note:: If :attr:`input` is a sparse tensor and returning a view of
  22953. the tensor is not possible, a RuntimeError exception is
  22954. raised. In this is the case, consider using
  22955. :func:`torch.select_copy` function.
  22956. Args:
  22957. input (Tensor): the input tensor.
  22958. dim (int): the dimension to slice
  22959. index (int): the index to select with
  22960. .. note::
  22961. :meth:`select` is equivalent to slicing. For example,
  22962. ``tensor.select(0, index)`` is equivalent to ``tensor[index]`` and
  22963. ``tensor.select(2, index)`` is equivalent to ``tensor[:,:,index]``.
  22964. """
  22965. def select_copy(
  22966. input: Tensor,
  22967. dim: _int,
  22968. index: _int | SymInt,
  22969. *,
  22970. out: Tensor | None = None,
  22971. ) -> Tensor:
  22972. r"""
  22973. Performs the same operation as :func:`torch.select`, but all output tensors
  22974. are freshly created instead of aliasing the input.
  22975. """
  22976. def select_scatter(
  22977. input: Tensor,
  22978. src: Tensor,
  22979. dim: _int,
  22980. index: _int | SymInt,
  22981. ) -> Tensor:
  22982. r"""
  22983. select_scatter(input, src, dim, index) -> Tensor
  22984. Embeds the values of the :attr:`src` tensor into :attr:`input` at the given index.
  22985. This function returns a tensor with fresh storage; it does not create a view.
  22986. Args:
  22987. input (Tensor): the input tensor.
  22988. src (Tensor): The tensor to embed into :attr:`input`
  22989. dim (int): the dimension to insert the slice into.
  22990. index (int): the index to select with
  22991. .. note::
  22992. :attr:`src` must be of the proper size in order to be embedded
  22993. into :attr:`input`. Specifically, it should have the same shape as
  22994. ``torch.select(input, dim, index)``
  22995. Example::
  22996. >>> a = torch.zeros(2, 2)
  22997. >>> b = torch.ones(2)
  22998. >>> a.select_scatter(b, 0, 0)
  22999. tensor([[1., 1.],
  23000. [0., 0.]])
  23001. """
  23002. def selu(input: Tensor) -> Tensor: ...
  23003. def selu_(input: Tensor) -> Tensor: ...
  23004. def set_flush_denormal(mode: _bool) -> _bool:
  23005. r"""
  23006. set_flush_denormal(mode) -> bool
  23007. Disables denormal floating numbers on CPU.
  23008. Returns ``True`` if your system supports flushing denormal numbers and it
  23009. successfully configures flush denormal mode. :meth:`~torch.set_flush_denormal`
  23010. is supported on x86 architectures supporting SSE3 and AArch64 architecture.
  23011. Args:
  23012. mode (bool): Controls whether to enable flush denormal mode or not
  23013. Example::
  23014. >>> torch.set_flush_denormal(True)
  23015. True
  23016. >>> torch.tensor([1e-323], dtype=torch.float64)
  23017. tensor([ 0.], dtype=torch.float64)
  23018. >>> torch.set_flush_denormal(False)
  23019. True
  23020. >>> torch.tensor([1e-323], dtype=torch.float64)
  23021. tensor(9.88131e-324 *
  23022. [ 1.0000], dtype=torch.float64)
  23023. """
  23024. def set_num_interop_threads(num: _int) -> None:
  23025. r"""
  23026. set_num_interop_threads(int)
  23027. Sets the number of threads used for interop parallelism
  23028. (e.g. in JIT interpreter) on CPU.
  23029. .. warning::
  23030. Can only be called once and before any inter-op parallel work
  23031. is started (e.g. JIT execution).
  23032. """
  23033. def set_num_threads(num: _int) -> None:
  23034. r"""
  23035. set_num_threads(int)
  23036. Sets the number of threads used for intraop parallelism on CPU.
  23037. .. warning::
  23038. To ensure that the correct number of threads is used, set_num_threads
  23039. must be called before running eager, JIT or autograd code.
  23040. """
  23041. def sgn(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  23042. r"""
  23043. sgn(input, *, out=None) -> Tensor
  23044. This function is an extension of torch.sign() to complex tensors.
  23045. It computes a new tensor whose elements have
  23046. the same angles as the corresponding elements of :attr:`input` and
  23047. absolute values (i.e. magnitudes) of one for complex tensors and
  23048. is equivalent to torch.sign() for non-complex tensors.
  23049. .. math::
  23050. \text{out}_{i} = \begin{cases}
  23051. 0 & |\text{{input}}_i| == 0 \\
  23052. \frac{{\text{{input}}_i}}{|{\text{{input}}_i}|} & \text{otherwise}
  23053. \end{cases}
  23054. Args:
  23055. input (Tensor): the input tensor.
  23056. Keyword args:
  23057. out (Tensor, optional): the output tensor.
  23058. Example::
  23059. >>> t = torch.tensor([3+4j, 7-24j, 0, 1+2j])
  23060. >>> t.sgn()
  23061. tensor([0.6000+0.8000j, 0.2800-0.9600j, 0.0000+0.0000j, 0.4472+0.8944j])
  23062. """
  23063. def sigmoid(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  23064. r"""
  23065. sigmoid(input, *, out=None) -> Tensor
  23066. Alias for :func:`torch.special.expit`.
  23067. """
  23068. def sigmoid_(input: Tensor) -> Tensor: ...
  23069. def sign(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  23070. r"""
  23071. sign(input, *, out=None) -> Tensor
  23072. Returns a new tensor with the signs of the elements of :attr:`input`.
  23073. .. math::
  23074. \text{out}_{i} = \operatorname{sgn}(\text{input}_{i})
  23075. Args:
  23076. input (Tensor): the input tensor.
  23077. Keyword args:
  23078. out (Tensor, optional): the output tensor.
  23079. Example::
  23080. >>> a = torch.tensor([0.7, -1.2, 0., 2.3])
  23081. >>> a
  23082. tensor([ 0.7000, -1.2000, 0.0000, 2.3000])
  23083. >>> torch.sign(a)
  23084. tensor([ 1., -1., 0., 1.])
  23085. """
  23086. def signbit(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  23087. r"""
  23088. signbit(input, *, out=None) -> Tensor
  23089. Tests if each element of :attr:`input` has its sign bit set or not.
  23090. Args:
  23091. input (Tensor): the input tensor.
  23092. Keyword args:
  23093. out (Tensor, optional): the output tensor.
  23094. Example::
  23095. >>> a = torch.tensor([0.7, -1.2, 0., 2.3])
  23096. >>> torch.signbit(a)
  23097. tensor([ False, True, False, False])
  23098. >>> a = torch.tensor([-0.0, 0.0])
  23099. >>> torch.signbit(a)
  23100. tensor([ True, False])
  23101. .. note::
  23102. signbit handles signed zeros, so negative zero (-0) returns True.
  23103. """
  23104. def sin(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  23105. r"""
  23106. sin(input, *, out=None) -> Tensor
  23107. Returns a new tensor with the sine of the elements in the :attr:`input` tensor,
  23108. where each value in this input tensor is in radians.
  23109. .. math::
  23110. \text{out}_{i} = \sin(\text{input}_{i})
  23111. Args:
  23112. input (Tensor): the input tensor.
  23113. Keyword args:
  23114. out (Tensor, optional): the output tensor.
  23115. Example::
  23116. >>> a = torch.randn(4)
  23117. >>> a
  23118. tensor([-0.5461, 0.1347, -2.7266, -0.2746])
  23119. >>> torch.sin(a)
  23120. tensor([-0.5194, 0.1343, -0.4032, -0.2711])
  23121. """
  23122. def sin_(input: Tensor) -> Tensor: ...
  23123. def sinc(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  23124. r"""
  23125. sinc(input, *, out=None) -> Tensor
  23126. Alias for :func:`torch.special.sinc`.
  23127. """
  23128. def sinc_(input: Tensor) -> Tensor: ...
  23129. def sinh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  23130. r"""
  23131. sinh(input, *, out=None) -> Tensor
  23132. Returns a new tensor with the hyperbolic sine of the elements of
  23133. :attr:`input`.
  23134. .. math::
  23135. \text{out}_{i} = \sinh(\text{input}_{i})
  23136. Args:
  23137. input (Tensor): the input tensor.
  23138. Keyword args:
  23139. out (Tensor, optional): the output tensor.
  23140. Example::
  23141. >>> a = torch.randn(4)
  23142. >>> a
  23143. tensor([ 0.5380, -0.8632, -0.1265, 0.9399])
  23144. >>> torch.sinh(a)
  23145. tensor([ 0.5644, -0.9744, -0.1268, 1.0845])
  23146. .. note::
  23147. When :attr:`input` is on the CPU, the implementation of torch.sinh may use
  23148. the Sleef library, which rounds very large results to infinity or negative
  23149. infinity. See `here <https://sleef.org/purec.xhtml>`_ for details.
  23150. """
  23151. def sinh_(input: Tensor) -> Tensor: ...
  23152. def slice_copy(
  23153. input: Tensor,
  23154. dim: _int = 0,
  23155. start: _int | SymInt | None = None,
  23156. end: _int | SymInt | None = None,
  23157. step: _int | SymInt = 1,
  23158. *,
  23159. out: Tensor | None = None,
  23160. ) -> Tensor:
  23161. r"""
  23162. Performs the same operation as :func:`torch.slice`, but all output tensors
  23163. are freshly created instead of aliasing the input.
  23164. """
  23165. def slice_inverse(
  23166. input: Tensor,
  23167. src: Tensor,
  23168. dim: _int = 0,
  23169. start: _int | SymInt | None = None,
  23170. end: _int | SymInt | None = None,
  23171. step: _int | SymInt = 1,
  23172. ) -> Tensor: ...
  23173. def slice_scatter(
  23174. input: Tensor,
  23175. src: Tensor,
  23176. dim: _int = 0,
  23177. start: _int | SymInt | None = None,
  23178. end: _int | SymInt | None = None,
  23179. step: _int | SymInt = 1,
  23180. *,
  23181. out: Tensor | None = None,
  23182. ) -> Tensor:
  23183. r"""
  23184. slice_scatter(input, src, dim=0, start=None, end=None, step=1) -> Tensor
  23185. Embeds the values of the :attr:`src` tensor into :attr:`input` at the given
  23186. dimension.
  23187. This function returns a tensor with fresh storage; it does not create a view.
  23188. Args:
  23189. input (Tensor): the input tensor.
  23190. src (Tensor): The tensor to embed into :attr:`input`
  23191. dim (int): the dimension to insert the slice into
  23192. start (Optional[int]): the start index of where to insert the slice
  23193. end (Optional[int]): the end index of where to insert the slice
  23194. step (int): the how many elements to skip in
  23195. Example::
  23196. >>> a = torch.zeros(8, 8)
  23197. >>> b = torch.ones(2, 8)
  23198. >>> a.slice_scatter(b, start=6)
  23199. tensor([[0., 0., 0., 0., 0., 0., 0., 0.],
  23200. [0., 0., 0., 0., 0., 0., 0., 0.],
  23201. [0., 0., 0., 0., 0., 0., 0., 0.],
  23202. [0., 0., 0., 0., 0., 0., 0., 0.],
  23203. [0., 0., 0., 0., 0., 0., 0., 0.],
  23204. [0., 0., 0., 0., 0., 0., 0., 0.],
  23205. [1., 1., 1., 1., 1., 1., 1., 1.],
  23206. [1., 1., 1., 1., 1., 1., 1., 1.]])
  23207. >>> b = torch.ones(8, 2)
  23208. >>> a.slice_scatter(b, dim=1, start=2, end=6, step=2)
  23209. tensor([[0., 0., 1., 0., 1., 0., 0., 0.],
  23210. [0., 0., 1., 0., 1., 0., 0., 0.],
  23211. [0., 0., 1., 0., 1., 0., 0., 0.],
  23212. [0., 0., 1., 0., 1., 0., 0., 0.],
  23213. [0., 0., 1., 0., 1., 0., 0., 0.],
  23214. [0., 0., 1., 0., 1., 0., 0., 0.],
  23215. [0., 0., 1., 0., 1., 0., 0., 0.],
  23216. [0., 0., 1., 0., 1., 0., 0., 0.]])
  23217. """
  23218. def slogdet(
  23219. input: Tensor,
  23220. *,
  23221. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  23222. ) -> torch.return_types.slogdet:
  23223. r"""
  23224. slogdet(input) -> (Tensor, Tensor)
  23225. Alias for :func:`torch.linalg.slogdet`
  23226. """
  23227. def smm(input: Tensor, mat2: Tensor) -> Tensor:
  23228. r"""
  23229. smm(input, mat) -> Tensor
  23230. Performs a matrix multiplication of the sparse matrix :attr:`input`
  23231. with the dense matrix :attr:`mat`.
  23232. Args:
  23233. input (Tensor): a sparse matrix to be matrix multiplied
  23234. mat (Tensor): a dense matrix to be matrix multiplied
  23235. """
  23236. @overload
  23237. def softmax(
  23238. input: Tensor,
  23239. dim: _int,
  23240. dtype: _dtype | None = None,
  23241. *,
  23242. out: Tensor | None = None,
  23243. ) -> Tensor:
  23244. r"""
  23245. softmax(input, dim, *, dtype=None) -> Tensor
  23246. Alias for :func:`torch.nn.functional.softmax`.
  23247. """
  23248. @overload
  23249. def softmax(
  23250. input: Tensor,
  23251. dim: str | EllipsisType | None,
  23252. *,
  23253. dtype: _dtype | None = None,
  23254. ) -> Tensor:
  23255. r"""
  23256. softmax(input, dim, *, dtype=None) -> Tensor
  23257. Alias for :func:`torch.nn.functional.softmax`.
  23258. """
  23259. @overload
  23260. def sort(
  23261. input: Tensor,
  23262. *,
  23263. stable: _bool | None,
  23264. dim: _int = -1,
  23265. descending: _bool = False,
  23266. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  23267. ) -> torch.return_types.sort:
  23268. r"""
  23269. sort(input, dim=-1, descending=False, *, stable=False, out=None) -> (Tensor, LongTensor)
  23270. Sorts the elements of the :attr:`input` tensor along a given dimension
  23271. in ascending order by value.
  23272. If :attr:`dim` is not given, the last dimension of the `input` is chosen.
  23273. If :attr:`descending` is ``True`` then the elements are sorted in descending
  23274. order by value.
  23275. If :attr:`stable` is ``True`` then the sorting routine becomes stable, preserving
  23276. the order of equivalent elements.
  23277. A namedtuple of (values, indices) is returned, where the `values` are the
  23278. sorted values and `indices` are the indices of the elements in the original
  23279. `input` tensor.
  23280. Args:
  23281. input (Tensor): the input tensor.
  23282. dim (int, optional): the dimension to sort along
  23283. descending (bool, optional): controls the sorting order (ascending or descending)
  23284. Keyword args:
  23285. stable (bool, optional): makes the sorting routine stable, which guarantees that the order
  23286. of equivalent elements is preserved.
  23287. out (tuple, optional): the output tuple of (`Tensor`, `LongTensor`) that can
  23288. be optionally given to be used as output buffers
  23289. Example::
  23290. >>> x = torch.randn(3, 4)
  23291. >>> sorted, indices = torch.sort(x)
  23292. >>> sorted
  23293. tensor([[-0.2162, 0.0608, 0.6719, 2.3332],
  23294. [-0.5793, 0.0061, 0.6058, 0.9497],
  23295. [-0.5071, 0.3343, 0.9553, 1.0960]])
  23296. >>> indices
  23297. tensor([[ 1, 0, 2, 3],
  23298. [ 3, 1, 0, 2],
  23299. [ 0, 3, 1, 2]])
  23300. >>> sorted, indices = torch.sort(x, 0)
  23301. >>> sorted
  23302. tensor([[-0.5071, -0.2162, 0.6719, -0.5793],
  23303. [ 0.0608, 0.0061, 0.9497, 0.3343],
  23304. [ 0.6058, 0.9553, 1.0960, 2.3332]])
  23305. >>> indices
  23306. tensor([[ 2, 0, 0, 1],
  23307. [ 0, 1, 1, 2],
  23308. [ 1, 2, 2, 0]])
  23309. >>> x = torch.tensor([0, 1] * 9)
  23310. >>> x.sort()
  23311. torch.return_types.sort(
  23312. values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
  23313. indices=tensor([ 2, 16, 4, 6, 14, 8, 0, 10, 12, 9, 17, 15, 13, 11, 7, 5, 3, 1]))
  23314. >>> x.sort(stable=True)
  23315. torch.return_types.sort(
  23316. values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
  23317. indices=tensor([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 17]))
  23318. """
  23319. @overload
  23320. def sort(
  23321. input: Tensor,
  23322. dim: _int = -1,
  23323. descending: _bool = False,
  23324. *,
  23325. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  23326. ) -> torch.return_types.sort:
  23327. r"""
  23328. sort(input, dim=-1, descending=False, *, stable=False, out=None) -> (Tensor, LongTensor)
  23329. Sorts the elements of the :attr:`input` tensor along a given dimension
  23330. in ascending order by value.
  23331. If :attr:`dim` is not given, the last dimension of the `input` is chosen.
  23332. If :attr:`descending` is ``True`` then the elements are sorted in descending
  23333. order by value.
  23334. If :attr:`stable` is ``True`` then the sorting routine becomes stable, preserving
  23335. the order of equivalent elements.
  23336. A namedtuple of (values, indices) is returned, where the `values` are the
  23337. sorted values and `indices` are the indices of the elements in the original
  23338. `input` tensor.
  23339. Args:
  23340. input (Tensor): the input tensor.
  23341. dim (int, optional): the dimension to sort along
  23342. descending (bool, optional): controls the sorting order (ascending or descending)
  23343. Keyword args:
  23344. stable (bool, optional): makes the sorting routine stable, which guarantees that the order
  23345. of equivalent elements is preserved.
  23346. out (tuple, optional): the output tuple of (`Tensor`, `LongTensor`) that can
  23347. be optionally given to be used as output buffers
  23348. Example::
  23349. >>> x = torch.randn(3, 4)
  23350. >>> sorted, indices = torch.sort(x)
  23351. >>> sorted
  23352. tensor([[-0.2162, 0.0608, 0.6719, 2.3332],
  23353. [-0.5793, 0.0061, 0.6058, 0.9497],
  23354. [-0.5071, 0.3343, 0.9553, 1.0960]])
  23355. >>> indices
  23356. tensor([[ 1, 0, 2, 3],
  23357. [ 3, 1, 0, 2],
  23358. [ 0, 3, 1, 2]])
  23359. >>> sorted, indices = torch.sort(x, 0)
  23360. >>> sorted
  23361. tensor([[-0.5071, -0.2162, 0.6719, -0.5793],
  23362. [ 0.0608, 0.0061, 0.9497, 0.3343],
  23363. [ 0.6058, 0.9553, 1.0960, 2.3332]])
  23364. >>> indices
  23365. tensor([[ 2, 0, 0, 1],
  23366. [ 0, 1, 1, 2],
  23367. [ 1, 2, 2, 0]])
  23368. >>> x = torch.tensor([0, 1] * 9)
  23369. >>> x.sort()
  23370. torch.return_types.sort(
  23371. values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
  23372. indices=tensor([ 2, 16, 4, 6, 14, 8, 0, 10, 12, 9, 17, 15, 13, 11, 7, 5, 3, 1]))
  23373. >>> x.sort(stable=True)
  23374. torch.return_types.sort(
  23375. values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
  23376. indices=tensor([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 17]))
  23377. """
  23378. @overload
  23379. def sort(
  23380. input: Tensor,
  23381. *,
  23382. stable: _bool | None,
  23383. dim: str | EllipsisType | None,
  23384. descending: _bool = False,
  23385. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  23386. ) -> torch.return_types.sort:
  23387. r"""
  23388. sort(input, dim=-1, descending=False, *, stable=False, out=None) -> (Tensor, LongTensor)
  23389. Sorts the elements of the :attr:`input` tensor along a given dimension
  23390. in ascending order by value.
  23391. If :attr:`dim` is not given, the last dimension of the `input` is chosen.
  23392. If :attr:`descending` is ``True`` then the elements are sorted in descending
  23393. order by value.
  23394. If :attr:`stable` is ``True`` then the sorting routine becomes stable, preserving
  23395. the order of equivalent elements.
  23396. A namedtuple of (values, indices) is returned, where the `values` are the
  23397. sorted values and `indices` are the indices of the elements in the original
  23398. `input` tensor.
  23399. Args:
  23400. input (Tensor): the input tensor.
  23401. dim (int, optional): the dimension to sort along
  23402. descending (bool, optional): controls the sorting order (ascending or descending)
  23403. Keyword args:
  23404. stable (bool, optional): makes the sorting routine stable, which guarantees that the order
  23405. of equivalent elements is preserved.
  23406. out (tuple, optional): the output tuple of (`Tensor`, `LongTensor`) that can
  23407. be optionally given to be used as output buffers
  23408. Example::
  23409. >>> x = torch.randn(3, 4)
  23410. >>> sorted, indices = torch.sort(x)
  23411. >>> sorted
  23412. tensor([[-0.2162, 0.0608, 0.6719, 2.3332],
  23413. [-0.5793, 0.0061, 0.6058, 0.9497],
  23414. [-0.5071, 0.3343, 0.9553, 1.0960]])
  23415. >>> indices
  23416. tensor([[ 1, 0, 2, 3],
  23417. [ 3, 1, 0, 2],
  23418. [ 0, 3, 1, 2]])
  23419. >>> sorted, indices = torch.sort(x, 0)
  23420. >>> sorted
  23421. tensor([[-0.5071, -0.2162, 0.6719, -0.5793],
  23422. [ 0.0608, 0.0061, 0.9497, 0.3343],
  23423. [ 0.6058, 0.9553, 1.0960, 2.3332]])
  23424. >>> indices
  23425. tensor([[ 2, 0, 0, 1],
  23426. [ 0, 1, 1, 2],
  23427. [ 1, 2, 2, 0]])
  23428. >>> x = torch.tensor([0, 1] * 9)
  23429. >>> x.sort()
  23430. torch.return_types.sort(
  23431. values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
  23432. indices=tensor([ 2, 16, 4, 6, 14, 8, 0, 10, 12, 9, 17, 15, 13, 11, 7, 5, 3, 1]))
  23433. >>> x.sort(stable=True)
  23434. torch.return_types.sort(
  23435. values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
  23436. indices=tensor([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 17]))
  23437. """
  23438. @overload
  23439. def sort(
  23440. input: Tensor,
  23441. dim: str | EllipsisType | None,
  23442. descending: _bool = False,
  23443. *,
  23444. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  23445. ) -> torch.return_types.sort:
  23446. r"""
  23447. sort(input, dim=-1, descending=False, *, stable=False, out=None) -> (Tensor, LongTensor)
  23448. Sorts the elements of the :attr:`input` tensor along a given dimension
  23449. in ascending order by value.
  23450. If :attr:`dim` is not given, the last dimension of the `input` is chosen.
  23451. If :attr:`descending` is ``True`` then the elements are sorted in descending
  23452. order by value.
  23453. If :attr:`stable` is ``True`` then the sorting routine becomes stable, preserving
  23454. the order of equivalent elements.
  23455. A namedtuple of (values, indices) is returned, where the `values` are the
  23456. sorted values and `indices` are the indices of the elements in the original
  23457. `input` tensor.
  23458. Args:
  23459. input (Tensor): the input tensor.
  23460. dim (int, optional): the dimension to sort along
  23461. descending (bool, optional): controls the sorting order (ascending or descending)
  23462. Keyword args:
  23463. stable (bool, optional): makes the sorting routine stable, which guarantees that the order
  23464. of equivalent elements is preserved.
  23465. out (tuple, optional): the output tuple of (`Tensor`, `LongTensor`) that can
  23466. be optionally given to be used as output buffers
  23467. Example::
  23468. >>> x = torch.randn(3, 4)
  23469. >>> sorted, indices = torch.sort(x)
  23470. >>> sorted
  23471. tensor([[-0.2162, 0.0608, 0.6719, 2.3332],
  23472. [-0.5793, 0.0061, 0.6058, 0.9497],
  23473. [-0.5071, 0.3343, 0.9553, 1.0960]])
  23474. >>> indices
  23475. tensor([[ 1, 0, 2, 3],
  23476. [ 3, 1, 0, 2],
  23477. [ 0, 3, 1, 2]])
  23478. >>> sorted, indices = torch.sort(x, 0)
  23479. >>> sorted
  23480. tensor([[-0.5071, -0.2162, 0.6719, -0.5793],
  23481. [ 0.0608, 0.0061, 0.9497, 0.3343],
  23482. [ 0.6058, 0.9553, 1.0960, 2.3332]])
  23483. >>> indices
  23484. tensor([[ 2, 0, 0, 1],
  23485. [ 0, 1, 1, 2],
  23486. [ 1, 2, 2, 0]])
  23487. >>> x = torch.tensor([0, 1] * 9)
  23488. >>> x.sort()
  23489. torch.return_types.sort(
  23490. values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
  23491. indices=tensor([ 2, 16, 4, 6, 14, 8, 0, 10, 12, 9, 17, 15, 13, 11, 7, 5, 3, 1]))
  23492. >>> x.sort(stable=True)
  23493. torch.return_types.sort(
  23494. values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
  23495. indices=tensor([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 17]))
  23496. """
  23497. def sparse_bsc_tensor(
  23498. ccol_indices: Tensor | list,
  23499. row_indices: Tensor | list,
  23500. values: Tensor | list,
  23501. size: _size | None = None,
  23502. *,
  23503. dtype: _dtype | None = None,
  23504. device: DeviceLikeType | None = None,
  23505. requires_grad: _bool = False,
  23506. check_invariants: _bool | None = None,
  23507. ) -> Tensor:
  23508. r"""
  23509. sparse_bsc_tensor(ccol_indices, row_indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) -> Tensor
  23510. Constructs a :ref:`sparse tensor in BSC (Block Compressed Sparse
  23511. Column)) <sparse-bsc-docs>` with specified 2-dimensional blocks at the
  23512. given :attr:`ccol_indices` and :attr:`row_indices`. Sparse matrix
  23513. multiplication operations in BSC format are typically faster than that
  23514. for sparse tensors in COO format. Make you have a look at :ref:`the
  23515. note on the data type of the indices <sparse-bsc-docs>`.
  23516. .. note::
  23517. If the ``device`` argument is not specified the device of the given
  23518. :attr:`values` and indices tensor(s) must match. If, however, the
  23519. argument is specified the input Tensors will be converted to the
  23520. given device and in turn determine the device of the constructed
  23521. sparse tensor.
  23522. Args:
  23523. ccol_indices (array_like): (B+1)-dimensional array of size
  23524. ``(*batchsize, ncolblocks + 1)``. The last element of each
  23525. batch is the number of non-zeros. This tensor encodes the
  23526. index in values and row_indices depending on where the given
  23527. column starts. Each successive number in the tensor subtracted
  23528. by the number before it denotes the number of elements in a
  23529. given column.
  23530. row_indices (array_like): Row block coordinates of each block in
  23531. values. (B+1)-dimensional tensor with the same length
  23532. as values.
  23533. values (array_list): Initial blocks for the tensor. Can be a list,
  23534. tuple, NumPy ``ndarray``, and other types that
  23535. represents a (1 + 2 + K)-dimensional tensor where ``K`` is the
  23536. number of dense dimensions.
  23537. size (list, tuple, :class:`torch.Size`, optional): Size of the
  23538. sparse tensor: ``(*batchsize, nrows * blocksize[0], ncols *
  23539. blocksize[1], *densesize)`` If not provided, the size will be
  23540. inferred as the minimum size big enough to hold all non-zero
  23541. blocks.
  23542. Keyword args:
  23543. dtype (:class:`torch.dtype`, optional): the desired data type of
  23544. returned tensor. Default: if None, infers data type from
  23545. :attr:`values`.
  23546. device (:class:`torch.device`, optional): the desired device of
  23547. returned tensor. Default: if None, uses the current device
  23548. for the default tensor type (see
  23549. :func:`torch.set_default_device`). :attr:`device` will be
  23550. the CPU for CPU tensor types and the current CUDA device for
  23551. CUDA tensor types.
  23552. pin_memory (bool, optional): If set, returned tensor would be allocated in
  23553. the pinned memory. Works only for CPU tensors. Default: ``False``.
  23554. requires_grad (bool, optional): If autograd should record operations on the
  23555. returned tensor. Default: ``False``.
  23556. check_invariants (bool, optional): If sparse tensor invariants are checked.
  23557. Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
  23558. initially False.
  23559. Example::
  23560. >>> ccol_indices = [0, 1, 2]
  23561. >>> row_indices = [0, 1]
  23562. >>> values = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
  23563. >>> torch.sparse_bsc_tensor(torch.tensor(ccol_indices, dtype=torch.int64),
  23564. ... torch.tensor(row_indices, dtype=torch.int64),
  23565. ... torch.tensor(values), dtype=torch.double)
  23566. tensor(ccol_indices=tensor([0, 1, 2]),
  23567. row_indices=tensor([0, 1]),
  23568. values=tensor([[[1., 2.],
  23569. [3., 4.]],
  23570. [[5., 6.],
  23571. [7., 8.]]]), size=(2, 2), nnz=2, dtype=torch.float64,
  23572. layout=torch.sparse_bsc)
  23573. """
  23574. def sparse_bsr_tensor(
  23575. crow_indices: Tensor | list,
  23576. col_indices: Tensor | list,
  23577. values: Tensor | list,
  23578. size: _size | None = None,
  23579. *,
  23580. dtype: _dtype | None = None,
  23581. device: DeviceLikeType | None = None,
  23582. requires_grad: _bool = False,
  23583. check_invariants: _bool | None = None,
  23584. ) -> Tensor:
  23585. r"""
  23586. sparse_bsr_tensor(crow_indices, col_indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) -> Tensor
  23587. Constructs a :ref:`sparse tensor in BSR (Block Compressed Sparse Row))
  23588. <sparse-bsr-docs>` with specified 2-dimensional blocks at the given
  23589. :attr:`crow_indices` and :attr:`col_indices`. Sparse matrix
  23590. multiplication operations in BSR format are typically faster than that
  23591. for sparse tensors in COO format. Make you have a look at :ref:`the
  23592. note on the data type of the indices <sparse-bsr-docs>`.
  23593. .. note::
  23594. If the ``device`` argument is not specified the device of the given
  23595. :attr:`values` and indices tensor(s) must match. If, however, the
  23596. argument is specified the input Tensors will be converted to the
  23597. given device and in turn determine the device of the constructed
  23598. sparse tensor.
  23599. Args:
  23600. crow_indices (array_like): (B+1)-dimensional array of size
  23601. ``(*batchsize, nrowblocks + 1)``. The last element of each
  23602. batch is the number of non-zeros. This tensor encodes the
  23603. block index in values and col_indices depending on where the
  23604. given row block starts. Each successive number in the tensor
  23605. subtracted by the number before it denotes the number of
  23606. blocks in a given row.
  23607. col_indices (array_like): Column block coordinates of each block
  23608. in values. (B+1)-dimensional tensor with the same length as
  23609. values.
  23610. values (array_list): Initial values for the tensor. Can be a list,
  23611. tuple, NumPy ``ndarray``, scalar, and other types that
  23612. represents a (1 + 2 + K)-dimensional tensor where ``K`` is the
  23613. number of dense dimensions.
  23614. size (list, tuple, :class:`torch.Size`, optional): Size of the
  23615. sparse tensor: ``(*batchsize, nrows * blocksize[0], ncols *
  23616. blocksize[1], *densesize)`` where ``blocksize ==
  23617. values.shape[1:3]``. If not provided, the size will be
  23618. inferred as the minimum size big enough to hold all non-zero
  23619. blocks.
  23620. Keyword args:
  23621. dtype (:class:`torch.dtype`, optional): the desired data type of
  23622. returned tensor. Default: if None, infers data type from
  23623. :attr:`values`.
  23624. device (:class:`torch.device`, optional): the desired device of
  23625. returned tensor. Default: if None, uses the current device
  23626. for the default tensor type (see
  23627. :func:`torch.set_default_device`). :attr:`device` will be
  23628. the CPU for CPU tensor types and the current CUDA device for
  23629. CUDA tensor types.
  23630. pin_memory (bool, optional): If set, returned tensor would be allocated in
  23631. the pinned memory. Works only for CPU tensors. Default: ``False``.
  23632. requires_grad (bool, optional): If autograd should record operations on the
  23633. returned tensor. Default: ``False``.
  23634. check_invariants (bool, optional): If sparse tensor invariants are checked.
  23635. Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
  23636. initially False.
  23637. Example::
  23638. >>> crow_indices = [0, 1, 2]
  23639. >>> col_indices = [0, 1]
  23640. >>> values = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
  23641. >>> torch.sparse_bsr_tensor(torch.tensor(crow_indices, dtype=torch.int64),
  23642. ... torch.tensor(col_indices, dtype=torch.int64),
  23643. ... torch.tensor(values), dtype=torch.double)
  23644. tensor(crow_indices=tensor([0, 1, 2]),
  23645. col_indices=tensor([0, 1]),
  23646. values=tensor([[[1., 2.],
  23647. [3., 4.]],
  23648. [[5., 6.],
  23649. [7., 8.]]]), size=(2, 2), nnz=2, dtype=torch.float64,
  23650. layout=torch.sparse_bsr)
  23651. """
  23652. def sparse_compressed_tensor(
  23653. compressed_indices: Tensor | list,
  23654. plain_indices: Tensor | list,
  23655. values: Tensor | list,
  23656. size: _size | None = None,
  23657. *,
  23658. dtype: _dtype | None = None,
  23659. layout: _layout | None = None,
  23660. device: DeviceLikeType | None = None,
  23661. requires_grad: _bool = False,
  23662. check_invariants: _bool | None = None,
  23663. ) -> Tensor:
  23664. r"""
  23665. sparse_compressed_tensor(compressed_indices, plain_indices, values, size=None, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) -> Tensor
  23666. Constructs a :ref:`sparse tensor in Compressed Sparse format - CSR,
  23667. CSC, BSR, or BSC - <sparse-compressed-docs>` with specified values at
  23668. the given :attr:`compressed_indices` and :attr:`plain_indices`. Sparse
  23669. matrix multiplication operations in Compressed Sparse format are
  23670. typically faster than that for sparse tensors in COO format. Make you
  23671. have a look at :ref:`the note on the data type of the indices
  23672. <sparse-compressed-docs>`.
  23673. .. note::
  23674. If the ``device`` argument is not specified the device of the given
  23675. :attr:`values` and indices tensor(s) must match. If, however, the
  23676. argument is specified the input Tensors will be converted to the
  23677. given device and in turn determine the device of the constructed
  23678. sparse tensor.
  23679. Args:
  23680. compressed_indices (array_like): (B+1)-dimensional array of size
  23681. ``(*batchsize, compressed_dim_size + 1)``. The last element of
  23682. each batch is the number of non-zero elements or blocks. This
  23683. tensor encodes the index in ``values`` and ``plain_indices``
  23684. depending on where the given compressed dimension (row or
  23685. column) starts. Each successive number in the tensor
  23686. subtracted by the number before it denotes the number of
  23687. elements or blocks in a given compressed dimension.
  23688. plain_indices (array_like): Plain dimension (column or row)
  23689. coordinates of each element or block in values. (B+1)-dimensional
  23690. tensor with the same length as values.
  23691. values (array_list): Initial values for the tensor. Can be a list,
  23692. tuple, NumPy ``ndarray``, scalar, and other types. that
  23693. represents a (1+K)-dimensional (for CSR and CSC layouts) or
  23694. (1+2+K)-dimensional tensor (for BSR and BSC layouts) where
  23695. ``K`` is the number of dense dimensions.
  23696. size (list, tuple, :class:`torch.Size`, optional): Size of the
  23697. sparse tensor: ``(*batchsize, nrows * blocksize[0], ncols *
  23698. blocksize[1], *densesize)`` where ``blocksize[0] ==
  23699. blocksize[1] == 1`` for CSR and CSC formats. If not provided,
  23700. the size will be inferred as the minimum size big enough to
  23701. hold all non-zero elements or blocks.
  23702. Keyword args:
  23703. dtype (:class:`torch.dtype`, optional): the desired data type of
  23704. returned tensor. Default: if None, infers data type from
  23705. :attr:`values`.
  23706. layout (:class:`torch.layout`, required): the desired layout of
  23707. returned tensor: :attr:`torch.sparse_csr`,
  23708. :attr:`torch.sparse_csc`, :attr:`torch.sparse_bsr`, or
  23709. :attr:`torch.sparse_bsc`.
  23710. device (:class:`torch.device`, optional): the desired device of
  23711. returned tensor. Default: if None, uses the current device
  23712. for the default tensor type (see
  23713. :func:`torch.set_default_device`). :attr:`device` will be
  23714. the CPU for CPU tensor types and the current CUDA device for
  23715. CUDA tensor types.
  23716. pin_memory (bool, optional): If set, returned tensor would be allocated in
  23717. the pinned memory. Works only for CPU tensors. Default: ``False``.
  23718. requires_grad (bool, optional): If autograd should record operations on the
  23719. returned tensor. Default: ``False``.
  23720. check_invariants (bool, optional): If sparse tensor invariants are checked.
  23721. Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
  23722. initially False.
  23723. Example::
  23724. >>> compressed_indices = [0, 2, 4]
  23725. >>> plain_indices = [0, 1, 0, 1]
  23726. >>> values = [1, 2, 3, 4]
  23727. >>> torch.sparse_compressed_tensor(torch.tensor(compressed_indices, dtype=torch.int64),
  23728. ... torch.tensor(plain_indices, dtype=torch.int64),
  23729. ... torch.tensor(values), dtype=torch.double, layout=torch.sparse_csr)
  23730. tensor(crow_indices=tensor([0, 2, 4]),
  23731. col_indices=tensor([0, 1, 0, 1]),
  23732. values=tensor([1., 2., 3., 4.]), size=(2, 2), nnz=4,
  23733. dtype=torch.float64, layout=torch.sparse_csr)
  23734. """
  23735. def sparse_coo_tensor(
  23736. indices: Tensor,
  23737. values: Tensor | list,
  23738. size: _size | None = None,
  23739. *,
  23740. dtype: _dtype | None = None,
  23741. device: DeviceLikeType | None = None,
  23742. requires_grad: _bool = False,
  23743. check_invariants: _bool | None = None,
  23744. is_coalesced: _bool | None = None,
  23745. ) -> Tensor:
  23746. r"""
  23747. sparse_coo_tensor(indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None, is_coalesced=None) -> Tensor
  23748. Constructs a :ref:`sparse tensor in COO(rdinate) format
  23749. <sparse-coo-docs>` with specified values at the given
  23750. :attr:`indices`.
  23751. .. note::
  23752. This function returns an :ref:`uncoalesced tensor
  23753. <sparse-uncoalesced-coo-docs>` when :attr:`is_coalesced` is
  23754. unspecified or ``None``.
  23755. .. note::
  23756. If the ``device`` argument is not specified the device of the given
  23757. :attr:`values` and indices tensor(s) must match. If, however, the
  23758. argument is specified the input Tensors will be converted to the
  23759. given device and in turn determine the device of the constructed
  23760. sparse tensor.
  23761. Args:
  23762. indices (array_like): Initial data for the tensor. Can be a list, tuple,
  23763. NumPy ``ndarray``, scalar, and other types. Will be cast to a :class:`torch.LongTensor`
  23764. internally. The indices are the coordinates of the non-zero values in the matrix, and thus
  23765. should be two-dimensional where the first dimension is the number of tensor dimensions and
  23766. the second dimension is the number of non-zero values.
  23767. values (array_like): Initial values for the tensor. Can be a list, tuple,
  23768. NumPy ``ndarray``, scalar, and other types.
  23769. size (list, tuple, or :class:`torch.Size`, optional): Size of the sparse tensor. If not
  23770. provided the size will be inferred as the minimum size big enough to hold all non-zero
  23771. elements.
  23772. Keyword args:
  23773. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  23774. Default: if None, infers data type from :attr:`values`.
  23775. device (:class:`torch.device`, optional): the desired device of returned tensor.
  23776. Default: if None, uses the current device for the default tensor type
  23777. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  23778. for CPU tensor types and the current CUDA device for CUDA tensor types.
  23779. pin_memory (bool, optional): If set, returned tensor would be allocated in
  23780. the pinned memory. Works only for CPU tensors. Default: ``False``.
  23781. requires_grad (bool, optional): If autograd should record operations on the
  23782. returned tensor. Default: ``False``.
  23783. check_invariants (bool, optional): If sparse tensor invariants are checked.
  23784. Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
  23785. initially False.
  23786. is_coalesced (bool, optional): When``True``, the caller is
  23787. responsible for providing tensor indices that correspond to a
  23788. coalesced tensor. If the :attr:`check_invariants` flag is
  23789. False, no error will be raised if the prerequisites are not
  23790. met and this will lead to silently incorrect results. To force
  23791. coalescion please use :meth:`coalesce` on the resulting
  23792. Tensor.
  23793. Default: None: except for trivial cases (e.g. nnz < 2) the
  23794. resulting Tensor has is_coalesced set to ``False```.
  23795. Example::
  23796. >>> i = torch.tensor([[0, 1, 1],
  23797. ... [2, 0, 2]])
  23798. >>> v = torch.tensor([3, 4, 5], dtype=torch.float32)
  23799. >>> torch.sparse_coo_tensor(i, v, [2, 4])
  23800. tensor(indices=tensor([[0, 1, 1],
  23801. [2, 0, 2]]),
  23802. values=tensor([3., 4., 5.]),
  23803. size=(2, 4), nnz=3, layout=torch.sparse_coo)
  23804. >>> torch.sparse_coo_tensor(i, v) # Shape inference
  23805. tensor(indices=tensor([[0, 1, 1],
  23806. [2, 0, 2]]),
  23807. values=tensor([3., 4., 5.]),
  23808. size=(2, 3), nnz=3, layout=torch.sparse_coo)
  23809. >>> torch.sparse_coo_tensor(i, v, [2, 4],
  23810. ... dtype=torch.float64,
  23811. ... device=torch.device('cuda:0'))
  23812. tensor(indices=tensor([[0, 1, 1],
  23813. [2, 0, 2]]),
  23814. values=tensor([3., 4., 5.]),
  23815. device='cuda:0', size=(2, 4), nnz=3, dtype=torch.float64,
  23816. layout=torch.sparse_coo)
  23817. # Create an empty sparse tensor with the following invariants:
  23818. # 1. sparse_dim + dense_dim = len(SparseTensor.shape)
  23819. # 2. SparseTensor._indices().shape = (sparse_dim, nnz)
  23820. # 3. SparseTensor._values().shape = (nnz, SparseTensor.shape[sparse_dim:])
  23821. #
  23822. # For instance, to create an empty sparse tensor with nnz = 0, dense_dim = 0 and
  23823. # sparse_dim = 1 (hence indices is a 2D tensor of shape = (1, 0))
  23824. >>> S = torch.sparse_coo_tensor(torch.empty([1, 0]), [], [1])
  23825. tensor(indices=tensor([], size=(1, 0)),
  23826. values=tensor([], size=(0,)),
  23827. size=(1,), nnz=0, layout=torch.sparse_coo)
  23828. # and to create an empty sparse tensor with nnz = 0, dense_dim = 1 and
  23829. # sparse_dim = 1
  23830. >>> S = torch.sparse_coo_tensor(torch.empty([1, 0]), torch.empty([0, 2]), [1, 2])
  23831. tensor(indices=tensor([], size=(1, 0)),
  23832. values=tensor([], size=(0, 2)),
  23833. size=(1, 2), nnz=0, layout=torch.sparse_coo)
  23834. .. _torch.sparse: https://pytorch.org/docs/stable/sparse.html
  23835. """
  23836. def sparse_csc_tensor(
  23837. ccol_indices: Tensor | list,
  23838. row_indices: Tensor | list,
  23839. values: Tensor | list,
  23840. size: _size | None = None,
  23841. *,
  23842. dtype: _dtype | None = None,
  23843. device: DeviceLikeType | None = None,
  23844. requires_grad: _bool = False,
  23845. check_invariants: _bool | None = None,
  23846. ) -> Tensor:
  23847. r"""
  23848. sparse_csc_tensor(ccol_indices, row_indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) -> Tensor
  23849. Constructs a :ref:`sparse tensor in CSC (Compressed Sparse Column)
  23850. <sparse-csc-docs>` with specified values at the given
  23851. :attr:`ccol_indices` and :attr:`row_indices`. Sparse matrix
  23852. multiplication operations in CSC format are typically faster than that
  23853. for sparse tensors in COO format. Make you have a look at :ref:`the
  23854. note on the data type of the indices <sparse-csc-docs>`.
  23855. .. note::
  23856. If the ``device`` argument is not specified the device of the given
  23857. :attr:`values` and indices tensor(s) must match. If, however, the
  23858. argument is specified the input Tensors will be converted to the
  23859. given device and in turn determine the device of the constructed
  23860. sparse tensor.
  23861. Args:
  23862. ccol_indices (array_like): (B+1)-dimensional array of size
  23863. ``(*batchsize, ncols + 1)``. The last element of each batch
  23864. is the number of non-zeros. This tensor encodes the index in
  23865. values and row_indices depending on where the given column
  23866. starts. Each successive number in the tensor subtracted by the
  23867. number before it denotes the number of elements in a given
  23868. column.
  23869. row_indices (array_like): Row coordinates of each element in
  23870. values. (B+1)-dimensional tensor with the same length as
  23871. values.
  23872. values (array_list): Initial values for the tensor. Can be a list,
  23873. tuple, NumPy ``ndarray``, scalar, and other types that
  23874. represents a (1+K)-dimensional tensor where ``K`` is the number
  23875. of dense dimensions.
  23876. size (list, tuple, :class:`torch.Size`, optional): Size of the
  23877. sparse tensor: ``(*batchsize, nrows, ncols, *densesize)``. If
  23878. not provided, the size will be inferred as the minimum size
  23879. big enough to hold all non-zero elements.
  23880. Keyword args:
  23881. dtype (:class:`torch.dtype`, optional): the desired data type of
  23882. returned tensor. Default: if None, infers data type from
  23883. :attr:`values`.
  23884. device (:class:`torch.device`, optional): the desired device of
  23885. returned tensor. Default: if None, uses the current device
  23886. for the default tensor type (see
  23887. :func:`torch.set_default_device`). :attr:`device` will be
  23888. the CPU for CPU tensor types and the current CUDA device for
  23889. CUDA tensor types.
  23890. pin_memory (bool, optional): If set, returned tensor would be allocated in
  23891. the pinned memory. Works only for CPU tensors. Default: ``False``.
  23892. requires_grad (bool, optional): If autograd should record operations on the
  23893. returned tensor. Default: ``False``.
  23894. check_invariants (bool, optional): If sparse tensor invariants are checked.
  23895. Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
  23896. initially False.
  23897. Example::
  23898. >>> ccol_indices = [0, 2, 4]
  23899. >>> row_indices = [0, 1, 0, 1]
  23900. >>> values = [1, 2, 3, 4]
  23901. >>> torch.sparse_csc_tensor(torch.tensor(ccol_indices, dtype=torch.int64),
  23902. ... torch.tensor(row_indices, dtype=torch.int64),
  23903. ... torch.tensor(values), dtype=torch.double)
  23904. tensor(ccol_indices=tensor([0, 2, 4]),
  23905. row_indices=tensor([0, 1, 0, 1]),
  23906. values=tensor([1., 2., 3., 4.]), size=(2, 2), nnz=4,
  23907. dtype=torch.float64, layout=torch.sparse_csc)
  23908. """
  23909. def sparse_csr_tensor(
  23910. crow_indices: Tensor | list,
  23911. col_indices: Tensor | list,
  23912. values: Tensor | list,
  23913. size: _size | None = None,
  23914. *,
  23915. dtype: _dtype | None = None,
  23916. device: DeviceLikeType | None = None,
  23917. requires_grad: _bool = False,
  23918. check_invariants: _bool | None = None,
  23919. ) -> Tensor:
  23920. r"""
  23921. sparse_csr_tensor(crow_indices, col_indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) -> Tensor
  23922. Constructs a :ref:`sparse tensor in CSR (Compressed Sparse Row) <sparse-csr-docs>` with specified
  23923. values at the given :attr:`crow_indices` and :attr:`col_indices`. Sparse matrix multiplication operations
  23924. in CSR format are typically faster than that for sparse tensors in COO format. Make you have a look
  23925. at :ref:`the note on the data type of the indices <sparse-csr-docs>`.
  23926. .. note::
  23927. If the ``device`` argument is not specified the device of the given
  23928. :attr:`values` and indices tensor(s) must match. If, however, the
  23929. argument is specified the input Tensors will be converted to the
  23930. given device and in turn determine the device of the constructed
  23931. sparse tensor.
  23932. Args:
  23933. crow_indices (array_like): (B+1)-dimensional array of size
  23934. ``(*batchsize, nrows + 1)``. The last element of each batch
  23935. is the number of non-zeros. This tensor encodes the index in
  23936. values and col_indices depending on where the given row
  23937. starts. Each successive number in the tensor subtracted by the
  23938. number before it denotes the number of elements in a given
  23939. row.
  23940. col_indices (array_like): Column coordinates of each element in
  23941. values. (B+1)-dimensional tensor with the same length
  23942. as values.
  23943. values (array_list): Initial values for the tensor. Can be a list,
  23944. tuple, NumPy ``ndarray``, scalar, and other types that
  23945. represents a (1+K)-dimensional tensor where ``K`` is the number
  23946. of dense dimensions.
  23947. size (list, tuple, :class:`torch.Size`, optional): Size of the
  23948. sparse tensor: ``(*batchsize, nrows, ncols, *densesize)``. If
  23949. not provided, the size will be inferred as the minimum size
  23950. big enough to hold all non-zero elements.
  23951. Keyword args:
  23952. dtype (:class:`torch.dtype`, optional): the desired data type of
  23953. returned tensor. Default: if None, infers data type from
  23954. :attr:`values`.
  23955. device (:class:`torch.device`, optional): the desired device of
  23956. returned tensor. Default: if None, uses the current device
  23957. for the default tensor type (see
  23958. :func:`torch.set_default_device`). :attr:`device` will be
  23959. the CPU for CPU tensor types and the current CUDA device for
  23960. CUDA tensor types.
  23961. pin_memory (bool, optional): If set, returned tensor would be allocated in
  23962. the pinned memory. Works only for CPU tensors. Default: ``False``.
  23963. requires_grad (bool, optional): If autograd should record operations on the
  23964. returned tensor. Default: ``False``.
  23965. check_invariants (bool, optional): If sparse tensor invariants are checked.
  23966. Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
  23967. initially False.
  23968. Example::
  23969. >>> crow_indices = [0, 2, 4]
  23970. >>> col_indices = [0, 1, 0, 1]
  23971. >>> values = [1, 2, 3, 4]
  23972. >>> torch.sparse_csr_tensor(torch.tensor(crow_indices, dtype=torch.int64),
  23973. ... torch.tensor(col_indices, dtype=torch.int64),
  23974. ... torch.tensor(values), dtype=torch.double)
  23975. tensor(crow_indices=tensor([0, 2, 4]),
  23976. col_indices=tensor([0, 1, 0, 1]),
  23977. values=tensor([1., 2., 3., 4.]), size=(2, 2), nnz=4,
  23978. dtype=torch.float64, layout=torch.sparse_csr)
  23979. """
  23980. def split_copy(
  23981. input: Tensor,
  23982. split_size: _int | SymInt,
  23983. dim: _int = 0,
  23984. *,
  23985. out: tuple[Tensor, ...] | list[Tensor] | None = None,
  23986. ) -> None:
  23987. r"""
  23988. Performs the same operation as :func:`torch.split`, but all output tensors
  23989. are freshly created instead of aliasing the input.
  23990. """
  23991. def split_with_sizes(
  23992. input: Tensor,
  23993. split_sizes: Sequence[_int | SymInt],
  23994. dim: _int = 0,
  23995. ) -> tuple[Tensor, ...]: ...
  23996. def split_with_sizes_copy(
  23997. input: Tensor,
  23998. split_sizes: Sequence[_int | SymInt],
  23999. dim: _int = 0,
  24000. *,
  24001. out: tuple[Tensor, ...] | list[Tensor] | None = None,
  24002. ) -> None:
  24003. r"""
  24004. Performs the same operation as :func:`torch.split_with_sizes`, but all output tensors
  24005. are freshly created instead of aliasing the input.
  24006. """
  24007. def spmm(input: Tensor, mat2: Tensor) -> Tensor: ...
  24008. def sqrt(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  24009. r"""
  24010. sqrt(input, *, out=None) -> Tensor
  24011. Returns a new tensor with the square-root of the elements of :attr:`input`.
  24012. .. math::
  24013. \text{out}_{i} = \sqrt{\text{input}_{i}}
  24014. Args:
  24015. input (Tensor): the input tensor.
  24016. Keyword args:
  24017. out (Tensor, optional): the output tensor.
  24018. Example::
  24019. >>> a = torch.randn(4)
  24020. >>> a
  24021. tensor([-2.0755, 1.0226, 0.0831, 0.4806])
  24022. >>> torch.sqrt(a)
  24023. tensor([ nan, 1.0112, 0.2883, 0.6933])
  24024. """
  24025. def sqrt_(input: Tensor) -> Tensor: ...
  24026. def square(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  24027. r"""
  24028. square(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  24029. Returns a new tensor with the square of the elements of :attr:`input`.
  24030. Args:
  24031. input (Tensor): the input tensor.
  24032. Keyword args:
  24033. out (Tensor, optional): the output tensor.
  24034. Example::
  24035. >>> a = torch.randn(4)
  24036. >>> a
  24037. tensor([-2.0755, 1.0226, 0.0831, 0.4806])
  24038. >>> torch.square(a)
  24039. tensor([ 4.3077, 1.0457, 0.0069, 0.2310])
  24040. """
  24041. def square_(input: Tensor) -> Tensor: ...
  24042. @overload
  24043. def squeeze(input: Tensor) -> Tensor:
  24044. r"""
  24045. squeeze(input: Tensor, dim: Optional[Union[int, List[int]]]) -> Tensor
  24046. Returns a tensor with all specified dimensions of :attr:`input` of size `1` removed.
  24047. For example, if `input` is of shape:
  24048. :math:`(A \times 1 \times B \times C \times 1 \times D)` then the `input.squeeze()`
  24049. will be of shape: :math:`(A \times B \times C \times D)`.
  24050. When :attr:`dim` is given, a squeeze operation is done only in the given
  24051. dimension(s). If `input` is of shape: :math:`(A \times 1 \times B)`,
  24052. ``squeeze(input, 0)`` leaves the tensor unchanged, but ``squeeze(input, 1)``
  24053. will squeeze the tensor to the shape :math:`(A \times B)`.
  24054. .. note:: The returned tensor shares the storage with the input tensor,
  24055. so changing the contents of one will change the contents of the other.
  24056. .. warning:: If the tensor has a batch dimension of size 1, then `squeeze(input)`
  24057. will also remove the batch dimension, which can lead to unexpected
  24058. errors. Consider specifying only the dims you wish to be squeezed.
  24059. Args:
  24060. input (Tensor): the input tensor.
  24061. dim (int or tuple of ints, optional): if given, the input will be squeezed
  24062. only in the specified dimensions.
  24063. .. versionchanged:: 2.0
  24064. :attr:`dim` now accepts tuples of dimensions.
  24065. Example::
  24066. >>> x = torch.zeros(2, 1, 2, 1, 2)
  24067. >>> x.size()
  24068. torch.Size([2, 1, 2, 1, 2])
  24069. >>> y = torch.squeeze(x)
  24070. >>> y.size()
  24071. torch.Size([2, 2, 2])
  24072. >>> y = torch.squeeze(x, 0)
  24073. >>> y.size()
  24074. torch.Size([2, 1, 2, 1, 2])
  24075. >>> y = torch.squeeze(x, 1)
  24076. >>> y.size()
  24077. torch.Size([2, 2, 1, 2])
  24078. >>> y = torch.squeeze(x, (1, 2, 3))
  24079. torch.Size([2, 2, 2])
  24080. """
  24081. @overload
  24082. def squeeze(input: Tensor, dim: _int) -> Tensor:
  24083. r"""
  24084. squeeze(input: Tensor, dim: Optional[Union[int, List[int]]]) -> Tensor
  24085. Returns a tensor with all specified dimensions of :attr:`input` of size `1` removed.
  24086. For example, if `input` is of shape:
  24087. :math:`(A \times 1 \times B \times C \times 1 \times D)` then the `input.squeeze()`
  24088. will be of shape: :math:`(A \times B \times C \times D)`.
  24089. When :attr:`dim` is given, a squeeze operation is done only in the given
  24090. dimension(s). If `input` is of shape: :math:`(A \times 1 \times B)`,
  24091. ``squeeze(input, 0)`` leaves the tensor unchanged, but ``squeeze(input, 1)``
  24092. will squeeze the tensor to the shape :math:`(A \times B)`.
  24093. .. note:: The returned tensor shares the storage with the input tensor,
  24094. so changing the contents of one will change the contents of the other.
  24095. .. warning:: If the tensor has a batch dimension of size 1, then `squeeze(input)`
  24096. will also remove the batch dimension, which can lead to unexpected
  24097. errors. Consider specifying only the dims you wish to be squeezed.
  24098. Args:
  24099. input (Tensor): the input tensor.
  24100. dim (int or tuple of ints, optional): if given, the input will be squeezed
  24101. only in the specified dimensions.
  24102. .. versionchanged:: 2.0
  24103. :attr:`dim` now accepts tuples of dimensions.
  24104. Example::
  24105. >>> x = torch.zeros(2, 1, 2, 1, 2)
  24106. >>> x.size()
  24107. torch.Size([2, 1, 2, 1, 2])
  24108. >>> y = torch.squeeze(x)
  24109. >>> y.size()
  24110. torch.Size([2, 2, 2])
  24111. >>> y = torch.squeeze(x, 0)
  24112. >>> y.size()
  24113. torch.Size([2, 1, 2, 1, 2])
  24114. >>> y = torch.squeeze(x, 1)
  24115. >>> y.size()
  24116. torch.Size([2, 2, 1, 2])
  24117. >>> y = torch.squeeze(x, (1, 2, 3))
  24118. torch.Size([2, 2, 2])
  24119. """
  24120. @overload
  24121. def squeeze(input: Tensor, dim: _size) -> Tensor:
  24122. r"""
  24123. squeeze(input: Tensor, dim: Optional[Union[int, List[int]]]) -> Tensor
  24124. Returns a tensor with all specified dimensions of :attr:`input` of size `1` removed.
  24125. For example, if `input` is of shape:
  24126. :math:`(A \times 1 \times B \times C \times 1 \times D)` then the `input.squeeze()`
  24127. will be of shape: :math:`(A \times B \times C \times D)`.
  24128. When :attr:`dim` is given, a squeeze operation is done only in the given
  24129. dimension(s). If `input` is of shape: :math:`(A \times 1 \times B)`,
  24130. ``squeeze(input, 0)`` leaves the tensor unchanged, but ``squeeze(input, 1)``
  24131. will squeeze the tensor to the shape :math:`(A \times B)`.
  24132. .. note:: The returned tensor shares the storage with the input tensor,
  24133. so changing the contents of one will change the contents of the other.
  24134. .. warning:: If the tensor has a batch dimension of size 1, then `squeeze(input)`
  24135. will also remove the batch dimension, which can lead to unexpected
  24136. errors. Consider specifying only the dims you wish to be squeezed.
  24137. Args:
  24138. input (Tensor): the input tensor.
  24139. dim (int or tuple of ints, optional): if given, the input will be squeezed
  24140. only in the specified dimensions.
  24141. .. versionchanged:: 2.0
  24142. :attr:`dim` now accepts tuples of dimensions.
  24143. Example::
  24144. >>> x = torch.zeros(2, 1, 2, 1, 2)
  24145. >>> x.size()
  24146. torch.Size([2, 1, 2, 1, 2])
  24147. >>> y = torch.squeeze(x)
  24148. >>> y.size()
  24149. torch.Size([2, 2, 2])
  24150. >>> y = torch.squeeze(x, 0)
  24151. >>> y.size()
  24152. torch.Size([2, 1, 2, 1, 2])
  24153. >>> y = torch.squeeze(x, 1)
  24154. >>> y.size()
  24155. torch.Size([2, 2, 1, 2])
  24156. >>> y = torch.squeeze(x, (1, 2, 3))
  24157. torch.Size([2, 2, 2])
  24158. """
  24159. @overload
  24160. def squeeze(input: Tensor, dim: str | EllipsisType | None) -> Tensor:
  24161. r"""
  24162. squeeze(input: Tensor, dim: Optional[Union[int, List[int]]]) -> Tensor
  24163. Returns a tensor with all specified dimensions of :attr:`input` of size `1` removed.
  24164. For example, if `input` is of shape:
  24165. :math:`(A \times 1 \times B \times C \times 1 \times D)` then the `input.squeeze()`
  24166. will be of shape: :math:`(A \times B \times C \times D)`.
  24167. When :attr:`dim` is given, a squeeze operation is done only in the given
  24168. dimension(s). If `input` is of shape: :math:`(A \times 1 \times B)`,
  24169. ``squeeze(input, 0)`` leaves the tensor unchanged, but ``squeeze(input, 1)``
  24170. will squeeze the tensor to the shape :math:`(A \times B)`.
  24171. .. note:: The returned tensor shares the storage with the input tensor,
  24172. so changing the contents of one will change the contents of the other.
  24173. .. warning:: If the tensor has a batch dimension of size 1, then `squeeze(input)`
  24174. will also remove the batch dimension, which can lead to unexpected
  24175. errors. Consider specifying only the dims you wish to be squeezed.
  24176. Args:
  24177. input (Tensor): the input tensor.
  24178. dim (int or tuple of ints, optional): if given, the input will be squeezed
  24179. only in the specified dimensions.
  24180. .. versionchanged:: 2.0
  24181. :attr:`dim` now accepts tuples of dimensions.
  24182. Example::
  24183. >>> x = torch.zeros(2, 1, 2, 1, 2)
  24184. >>> x.size()
  24185. torch.Size([2, 1, 2, 1, 2])
  24186. >>> y = torch.squeeze(x)
  24187. >>> y.size()
  24188. torch.Size([2, 2, 2])
  24189. >>> y = torch.squeeze(x, 0)
  24190. >>> y.size()
  24191. torch.Size([2, 1, 2, 1, 2])
  24192. >>> y = torch.squeeze(x, 1)
  24193. >>> y.size()
  24194. torch.Size([2, 2, 1, 2])
  24195. >>> y = torch.squeeze(x, (1, 2, 3))
  24196. torch.Size([2, 2, 2])
  24197. """
  24198. @overload
  24199. def squeeze_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  24200. r"""
  24201. Performs the same operation as :func:`torch.squeeze`, but all output tensors
  24202. are freshly created instead of aliasing the input.
  24203. """
  24204. @overload
  24205. def squeeze_copy(
  24206. input: Tensor,
  24207. dim: _int,
  24208. *,
  24209. out: Tensor | None = None,
  24210. ) -> Tensor:
  24211. r"""
  24212. Performs the same operation as :func:`torch.squeeze`, but all output tensors
  24213. are freshly created instead of aliasing the input.
  24214. """
  24215. @overload
  24216. def squeeze_copy(
  24217. input: Tensor,
  24218. dim: _size,
  24219. *,
  24220. out: Tensor | None = None,
  24221. ) -> Tensor:
  24222. r"""
  24223. Performs the same operation as :func:`torch.squeeze`, but all output tensors
  24224. are freshly created instead of aliasing the input.
  24225. """
  24226. @overload
  24227. def sspaddmm(
  24228. beta: Number | _complex,
  24229. self: Tensor,
  24230. alpha: Number | _complex,
  24231. mat1: Tensor,
  24232. mat2: Tensor,
  24233. ) -> Tensor:
  24234. r"""
  24235. sspaddmm(input, mat1, mat2, *, beta=1, alpha=1, out=None) -> Tensor
  24236. Matrix multiplies a sparse tensor :attr:`mat1` with a dense tensor
  24237. :attr:`mat2`, then adds the sparse tensor :attr:`input` to the result.
  24238. Note: This function is equivalent to :func:`torch.addmm`, except
  24239. :attr:`input` and :attr:`mat1` are sparse.
  24240. Args:
  24241. input (Tensor): a sparse matrix to be added
  24242. mat1 (Tensor): a sparse matrix to be matrix multiplied
  24243. mat2 (Tensor): a dense matrix to be matrix multiplied
  24244. Keyword args:
  24245. beta (Number, optional): multiplier for :attr:`mat` (:math:`\beta`)
  24246. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  24247. out (Tensor, optional): the output tensor.
  24248. """
  24249. @overload
  24250. def sspaddmm(
  24251. input: Tensor,
  24252. mat1: Tensor,
  24253. mat2: Tensor,
  24254. *,
  24255. beta: Number | _complex = 1,
  24256. alpha: Number | _complex = 1,
  24257. out: Tensor | None = None,
  24258. ) -> Tensor:
  24259. r"""
  24260. sspaddmm(input, mat1, mat2, *, beta=1, alpha=1, out=None) -> Tensor
  24261. Matrix multiplies a sparse tensor :attr:`mat1` with a dense tensor
  24262. :attr:`mat2`, then adds the sparse tensor :attr:`input` to the result.
  24263. Note: This function is equivalent to :func:`torch.addmm`, except
  24264. :attr:`input` and :attr:`mat1` are sparse.
  24265. Args:
  24266. input (Tensor): a sparse matrix to be added
  24267. mat1 (Tensor): a sparse matrix to be matrix multiplied
  24268. mat2 (Tensor): a dense matrix to be matrix multiplied
  24269. Keyword args:
  24270. beta (Number, optional): multiplier for :attr:`mat` (:math:`\beta`)
  24271. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  24272. out (Tensor, optional): the output tensor.
  24273. """
  24274. @overload
  24275. def sspaddmm(
  24276. beta: Number | _complex,
  24277. self: Tensor,
  24278. mat1: Tensor,
  24279. mat2: Tensor,
  24280. ) -> Tensor:
  24281. r"""
  24282. sspaddmm(input, mat1, mat2, *, beta=1, alpha=1, out=None) -> Tensor
  24283. Matrix multiplies a sparse tensor :attr:`mat1` with a dense tensor
  24284. :attr:`mat2`, then adds the sparse tensor :attr:`input` to the result.
  24285. Note: This function is equivalent to :func:`torch.addmm`, except
  24286. :attr:`input` and :attr:`mat1` are sparse.
  24287. Args:
  24288. input (Tensor): a sparse matrix to be added
  24289. mat1 (Tensor): a sparse matrix to be matrix multiplied
  24290. mat2 (Tensor): a dense matrix to be matrix multiplied
  24291. Keyword args:
  24292. beta (Number, optional): multiplier for :attr:`mat` (:math:`\beta`)
  24293. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  24294. out (Tensor, optional): the output tensor.
  24295. """
  24296. def stack(
  24297. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  24298. dim: _int = 0,
  24299. *,
  24300. out: Tensor | None = None,
  24301. ) -> Tensor:
  24302. r"""
  24303. stack(tensors, dim=0, *, out=None) -> Tensor
  24304. Concatenates a sequence of tensors along a new dimension.
  24305. All tensors need to be of the same size.
  24306. .. seealso::
  24307. :func:`torch.cat` concatenates the given sequence along an existing dimension.
  24308. Arguments:
  24309. tensors (sequence of Tensors): sequence of tensors to concatenate
  24310. dim (int, optional): dimension to insert. Has to be between 0 and the number
  24311. of dimensions of concatenated tensors (inclusive). Default: 0
  24312. Keyword args:
  24313. out (Tensor, optional): the output tensor.
  24314. Example::
  24315. >>> x = torch.randn(2, 3)
  24316. >>> x
  24317. tensor([[ 0.3367, 0.1288, 0.2345],
  24318. [ 0.2303, -1.1229, -0.1863]])
  24319. >>> torch.stack((x, x)) # same as torch.stack((x, x), dim=0)
  24320. tensor([[[ 0.3367, 0.1288, 0.2345],
  24321. [ 0.2303, -1.1229, -0.1863]],
  24322. [[ 0.3367, 0.1288, 0.2345],
  24323. [ 0.2303, -1.1229, -0.1863]]])
  24324. >>> torch.stack((x, x)).size()
  24325. torch.Size([2, 2, 3])
  24326. >>> torch.stack((x, x), dim=1)
  24327. tensor([[[ 0.3367, 0.1288, 0.2345],
  24328. [ 0.3367, 0.1288, 0.2345]],
  24329. [[ 0.2303, -1.1229, -0.1863],
  24330. [ 0.2303, -1.1229, -0.1863]]])
  24331. >>> torch.stack((x, x), dim=2)
  24332. tensor([[[ 0.3367, 0.3367],
  24333. [ 0.1288, 0.1288],
  24334. [ 0.2345, 0.2345]],
  24335. [[ 0.2303, 0.2303],
  24336. [-1.1229, -1.1229],
  24337. [-0.1863, -0.1863]]])
  24338. >>> torch.stack((x, x), dim=-1)
  24339. tensor([[[ 0.3367, 0.3367],
  24340. [ 0.1288, 0.1288],
  24341. [ 0.2345, 0.2345]],
  24342. [[ 0.2303, 0.2303],
  24343. [-1.1229, -1.1229],
  24344. [-0.1863, -0.1863]]])
  24345. """
  24346. @overload
  24347. def std(
  24348. input: Tensor,
  24349. dim: _int | _size | None,
  24350. unbiased: _bool = True,
  24351. keepdim: _bool = False,
  24352. *,
  24353. out: Tensor | None = None,
  24354. ) -> Tensor:
  24355. r"""
  24356. std(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  24357. Calculates the standard deviation over the dimensions specified by :attr:`dim`.
  24358. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  24359. reduce over all dimensions.
  24360. The standard deviation (:math:`\sigma`) is calculated as
  24361. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24362. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24363. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24364. the :attr:`correction`.
  24365. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24366. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24367. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24368. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24369. Args:
  24370. input (Tensor): the input tensor.
  24371. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24372. If ``None``, all dimensions are reduced.
  24373. Keyword args:
  24374. correction (int): difference between the sample size and sample degrees of freedom.
  24375. Defaults to `Bessel's correction`_, ``correction=1``.
  24376. .. versionchanged:: 2.0
  24377. Previously this argument was called ``unbiased`` and was a boolean
  24378. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24379. ``correction=0``.
  24380. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24381. out (Tensor, optional): the output tensor.
  24382. Example:
  24383. >>> a = torch.tensor(
  24384. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24385. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24386. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24387. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24388. ... ) # fmt: skip
  24389. >>> torch.std(a, dim=1, keepdim=True)
  24390. tensor([[1.0311],
  24391. [0.7477],
  24392. [1.2204],
  24393. [0.9087]])
  24394. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24395. """
  24396. @overload
  24397. def std(
  24398. input: Tensor,
  24399. dim: _int | _size | None = None,
  24400. *,
  24401. correction: Number | _complex | None = None,
  24402. keepdim: _bool = False,
  24403. out: Tensor | None = None,
  24404. ) -> Tensor:
  24405. r"""
  24406. std(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  24407. Calculates the standard deviation over the dimensions specified by :attr:`dim`.
  24408. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  24409. reduce over all dimensions.
  24410. The standard deviation (:math:`\sigma`) is calculated as
  24411. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24412. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24413. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24414. the :attr:`correction`.
  24415. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24416. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24417. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24418. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24419. Args:
  24420. input (Tensor): the input tensor.
  24421. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24422. If ``None``, all dimensions are reduced.
  24423. Keyword args:
  24424. correction (int): difference between the sample size and sample degrees of freedom.
  24425. Defaults to `Bessel's correction`_, ``correction=1``.
  24426. .. versionchanged:: 2.0
  24427. Previously this argument was called ``unbiased`` and was a boolean
  24428. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24429. ``correction=0``.
  24430. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24431. out (Tensor, optional): the output tensor.
  24432. Example:
  24433. >>> a = torch.tensor(
  24434. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24435. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24436. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24437. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24438. ... ) # fmt: skip
  24439. >>> torch.std(a, dim=1, keepdim=True)
  24440. tensor([[1.0311],
  24441. [0.7477],
  24442. [1.2204],
  24443. [0.9087]])
  24444. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24445. """
  24446. @overload
  24447. def std(input: Tensor, unbiased: _bool = True) -> Tensor:
  24448. r"""
  24449. std(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  24450. Calculates the standard deviation over the dimensions specified by :attr:`dim`.
  24451. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  24452. reduce over all dimensions.
  24453. The standard deviation (:math:`\sigma`) is calculated as
  24454. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24455. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24456. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24457. the :attr:`correction`.
  24458. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24459. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24460. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24461. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24462. Args:
  24463. input (Tensor): the input tensor.
  24464. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24465. If ``None``, all dimensions are reduced.
  24466. Keyword args:
  24467. correction (int): difference between the sample size and sample degrees of freedom.
  24468. Defaults to `Bessel's correction`_, ``correction=1``.
  24469. .. versionchanged:: 2.0
  24470. Previously this argument was called ``unbiased`` and was a boolean
  24471. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24472. ``correction=0``.
  24473. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24474. out (Tensor, optional): the output tensor.
  24475. Example:
  24476. >>> a = torch.tensor(
  24477. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24478. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24479. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24480. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24481. ... ) # fmt: skip
  24482. >>> torch.std(a, dim=1, keepdim=True)
  24483. tensor([[1.0311],
  24484. [0.7477],
  24485. [1.2204],
  24486. [0.9087]])
  24487. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24488. """
  24489. @overload
  24490. def std(
  24491. input: Tensor,
  24492. dim: Sequence[str | EllipsisType | None],
  24493. *,
  24494. correction: Number | _complex | None = None,
  24495. keepdim: _bool = False,
  24496. out: Tensor | None = None,
  24497. ) -> Tensor:
  24498. r"""
  24499. std(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  24500. Calculates the standard deviation over the dimensions specified by :attr:`dim`.
  24501. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  24502. reduce over all dimensions.
  24503. The standard deviation (:math:`\sigma`) is calculated as
  24504. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24505. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24506. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24507. the :attr:`correction`.
  24508. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24509. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24510. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24511. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24512. Args:
  24513. input (Tensor): the input tensor.
  24514. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24515. If ``None``, all dimensions are reduced.
  24516. Keyword args:
  24517. correction (int): difference between the sample size and sample degrees of freedom.
  24518. Defaults to `Bessel's correction`_, ``correction=1``.
  24519. .. versionchanged:: 2.0
  24520. Previously this argument was called ``unbiased`` and was a boolean
  24521. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24522. ``correction=0``.
  24523. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24524. out (Tensor, optional): the output tensor.
  24525. Example:
  24526. >>> a = torch.tensor(
  24527. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24528. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24529. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24530. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24531. ... ) # fmt: skip
  24532. >>> torch.std(a, dim=1, keepdim=True)
  24533. tensor([[1.0311],
  24534. [0.7477],
  24535. [1.2204],
  24536. [0.9087]])
  24537. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24538. """
  24539. @overload
  24540. def std(
  24541. input: Tensor,
  24542. dim: Sequence[str | EllipsisType | None],
  24543. unbiased: _bool = True,
  24544. keepdim: _bool = False,
  24545. *,
  24546. out: Tensor | None = None,
  24547. ) -> Tensor:
  24548. r"""
  24549. std(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  24550. Calculates the standard deviation over the dimensions specified by :attr:`dim`.
  24551. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  24552. reduce over all dimensions.
  24553. The standard deviation (:math:`\sigma`) is calculated as
  24554. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24555. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24556. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24557. the :attr:`correction`.
  24558. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24559. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24560. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24561. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24562. Args:
  24563. input (Tensor): the input tensor.
  24564. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24565. If ``None``, all dimensions are reduced.
  24566. Keyword args:
  24567. correction (int): difference between the sample size and sample degrees of freedom.
  24568. Defaults to `Bessel's correction`_, ``correction=1``.
  24569. .. versionchanged:: 2.0
  24570. Previously this argument was called ``unbiased`` and was a boolean
  24571. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24572. ``correction=0``.
  24573. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24574. out (Tensor, optional): the output tensor.
  24575. Example:
  24576. >>> a = torch.tensor(
  24577. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24578. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24579. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24580. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24581. ... ) # fmt: skip
  24582. >>> torch.std(a, dim=1, keepdim=True)
  24583. tensor([[1.0311],
  24584. [0.7477],
  24585. [1.2204],
  24586. [0.9087]])
  24587. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24588. """
  24589. @overload
  24590. def std_mean(
  24591. input: Tensor,
  24592. dim: _int | _size | None,
  24593. unbiased: _bool = True,
  24594. keepdim: _bool = False,
  24595. ) -> tuple[Tensor, Tensor]:
  24596. r"""
  24597. std_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  24598. Calculates the standard deviation and mean over the dimensions specified by
  24599. :attr:`dim`. :attr:`dim` can be a single dimension, list of dimensions, or
  24600. ``None`` to reduce over all dimensions.
  24601. The standard deviation (:math:`\sigma`) is calculated as
  24602. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24603. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24604. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24605. the :attr:`correction`.
  24606. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24607. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24608. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24609. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24610. Args:
  24611. input (Tensor): the input tensor.
  24612. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24613. If ``None``, all dimensions are reduced.
  24614. Keyword args:
  24615. correction (int): difference between the sample size and sample degrees of freedom.
  24616. Defaults to `Bessel's correction`_, ``correction=1``.
  24617. .. versionchanged:: 2.0
  24618. Previously this argument was called ``unbiased`` and was a boolean
  24619. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24620. ``correction=0``.
  24621. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24622. out (Tensor, optional): the output tensor.
  24623. Returns:
  24624. A tuple (std, mean) containing the standard deviation and mean.
  24625. Example:
  24626. >>> a = torch.tensor(
  24627. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24628. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24629. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24630. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24631. ... ) # fmt: skip
  24632. >>> torch.std_mean(a, dim=0, keepdim=True)
  24633. (tensor([[1.2620, 1.0028, 1.0957, 0.6038]]),
  24634. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  24635. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24636. """
  24637. @overload
  24638. def std_mean(
  24639. input: Tensor,
  24640. dim: _int | _size | None = None,
  24641. *,
  24642. correction: Number | _complex | None = None,
  24643. keepdim: _bool = False,
  24644. ) -> tuple[Tensor, Tensor]:
  24645. r"""
  24646. std_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  24647. Calculates the standard deviation and mean over the dimensions specified by
  24648. :attr:`dim`. :attr:`dim` can be a single dimension, list of dimensions, or
  24649. ``None`` to reduce over all dimensions.
  24650. The standard deviation (:math:`\sigma`) is calculated as
  24651. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24652. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24653. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24654. the :attr:`correction`.
  24655. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24656. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24657. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24658. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24659. Args:
  24660. input (Tensor): the input tensor.
  24661. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24662. If ``None``, all dimensions are reduced.
  24663. Keyword args:
  24664. correction (int): difference between the sample size and sample degrees of freedom.
  24665. Defaults to `Bessel's correction`_, ``correction=1``.
  24666. .. versionchanged:: 2.0
  24667. Previously this argument was called ``unbiased`` and was a boolean
  24668. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24669. ``correction=0``.
  24670. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24671. out (Tensor, optional): the output tensor.
  24672. Returns:
  24673. A tuple (std, mean) containing the standard deviation and mean.
  24674. Example:
  24675. >>> a = torch.tensor(
  24676. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24677. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24678. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24679. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24680. ... ) # fmt: skip
  24681. >>> torch.std_mean(a, dim=0, keepdim=True)
  24682. (tensor([[1.2620, 1.0028, 1.0957, 0.6038]]),
  24683. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  24684. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24685. """
  24686. @overload
  24687. def std_mean(
  24688. input: Tensor,
  24689. unbiased: _bool = True,
  24690. ) -> tuple[Tensor, Tensor]:
  24691. r"""
  24692. std_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  24693. Calculates the standard deviation and mean over the dimensions specified by
  24694. :attr:`dim`. :attr:`dim` can be a single dimension, list of dimensions, or
  24695. ``None`` to reduce over all dimensions.
  24696. The standard deviation (:math:`\sigma`) is calculated as
  24697. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24698. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24699. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24700. the :attr:`correction`.
  24701. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24702. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24703. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24704. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24705. Args:
  24706. input (Tensor): the input tensor.
  24707. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24708. If ``None``, all dimensions are reduced.
  24709. Keyword args:
  24710. correction (int): difference between the sample size and sample degrees of freedom.
  24711. Defaults to `Bessel's correction`_, ``correction=1``.
  24712. .. versionchanged:: 2.0
  24713. Previously this argument was called ``unbiased`` and was a boolean
  24714. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24715. ``correction=0``.
  24716. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24717. out (Tensor, optional): the output tensor.
  24718. Returns:
  24719. A tuple (std, mean) containing the standard deviation and mean.
  24720. Example:
  24721. >>> a = torch.tensor(
  24722. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24723. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24724. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24725. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24726. ... ) # fmt: skip
  24727. >>> torch.std_mean(a, dim=0, keepdim=True)
  24728. (tensor([[1.2620, 1.0028, 1.0957, 0.6038]]),
  24729. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  24730. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24731. """
  24732. @overload
  24733. def std_mean(
  24734. input: Tensor,
  24735. dim: Sequence[str | EllipsisType | None],
  24736. *,
  24737. correction: Number | _complex | None = None,
  24738. keepdim: _bool = False,
  24739. ) -> tuple[Tensor, Tensor]:
  24740. r"""
  24741. std_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  24742. Calculates the standard deviation and mean over the dimensions specified by
  24743. :attr:`dim`. :attr:`dim` can be a single dimension, list of dimensions, or
  24744. ``None`` to reduce over all dimensions.
  24745. The standard deviation (:math:`\sigma`) is calculated as
  24746. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24747. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24748. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24749. the :attr:`correction`.
  24750. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24751. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24752. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24753. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24754. Args:
  24755. input (Tensor): the input tensor.
  24756. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24757. If ``None``, all dimensions are reduced.
  24758. Keyword args:
  24759. correction (int): difference between the sample size and sample degrees of freedom.
  24760. Defaults to `Bessel's correction`_, ``correction=1``.
  24761. .. versionchanged:: 2.0
  24762. Previously this argument was called ``unbiased`` and was a boolean
  24763. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24764. ``correction=0``.
  24765. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24766. out (Tensor, optional): the output tensor.
  24767. Returns:
  24768. A tuple (std, mean) containing the standard deviation and mean.
  24769. Example:
  24770. >>> a = torch.tensor(
  24771. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24772. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24773. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24774. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24775. ... ) # fmt: skip
  24776. >>> torch.std_mean(a, dim=0, keepdim=True)
  24777. (tensor([[1.2620, 1.0028, 1.0957, 0.6038]]),
  24778. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  24779. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24780. """
  24781. @overload
  24782. def std_mean(
  24783. input: Tensor,
  24784. dim: Sequence[str | EllipsisType | None],
  24785. unbiased: _bool = True,
  24786. keepdim: _bool = False,
  24787. ) -> tuple[Tensor, Tensor]:
  24788. r"""
  24789. std_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  24790. Calculates the standard deviation and mean over the dimensions specified by
  24791. :attr:`dim`. :attr:`dim` can be a single dimension, list of dimensions, or
  24792. ``None`` to reduce over all dimensions.
  24793. The standard deviation (:math:`\sigma`) is calculated as
  24794. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24795. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24796. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24797. the :attr:`correction`.
  24798. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24799. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24800. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24801. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24802. Args:
  24803. input (Tensor): the input tensor.
  24804. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24805. If ``None``, all dimensions are reduced.
  24806. Keyword args:
  24807. correction (int): difference between the sample size and sample degrees of freedom.
  24808. Defaults to `Bessel's correction`_, ``correction=1``.
  24809. .. versionchanged:: 2.0
  24810. Previously this argument was called ``unbiased`` and was a boolean
  24811. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24812. ``correction=0``.
  24813. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24814. out (Tensor, optional): the output tensor.
  24815. Returns:
  24816. A tuple (std, mean) containing the standard deviation and mean.
  24817. Example:
  24818. >>> a = torch.tensor(
  24819. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24820. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24821. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24822. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24823. ... ) # fmt: skip
  24824. >>> torch.std_mean(a, dim=0, keepdim=True)
  24825. (tensor([[1.2620, 1.0028, 1.0957, 0.6038]]),
  24826. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  24827. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24828. """
  24829. @overload
  24830. def sub(
  24831. input: Tensor | Number | _complex,
  24832. other: Tensor | Number | _complex,
  24833. *,
  24834. alpha: Number | _complex | None = 1,
  24835. out: Tensor | None = None,
  24836. ) -> Tensor:
  24837. r"""
  24838. sub(input, other, *, alpha=1, out=None) -> Tensor
  24839. Subtracts :attr:`other`, scaled by :attr:`alpha`, from :attr:`input`.
  24840. .. math::
  24841. \text{{out}}_i = \text{{input}}_i - \text{{alpha}} \times \text{{other}}_i
  24842. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  24843. :ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
  24844. Args:
  24845. input (Tensor): the input tensor.
  24846. other (Tensor or Number): the tensor or number to subtract from :attr:`input`.
  24847. Keyword args:
  24848. alpha (Number): the multiplier for :attr:`other`.
  24849. out (Tensor, optional): the output tensor.
  24850. Example::
  24851. >>> a = torch.tensor((1, 2))
  24852. >>> b = torch.tensor((0, 1))
  24853. >>> torch.sub(a, b, alpha=2)
  24854. tensor([1, 0])
  24855. """
  24856. @overload
  24857. def sub(self: Tensor, alpha: Number | _complex, other: Tensor) -> Tensor:
  24858. r"""
  24859. sub(input, other, *, alpha=1, out=None) -> Tensor
  24860. Subtracts :attr:`other`, scaled by :attr:`alpha`, from :attr:`input`.
  24861. .. math::
  24862. \text{{out}}_i = \text{{input}}_i - \text{{alpha}} \times \text{{other}}_i
  24863. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  24864. :ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
  24865. Args:
  24866. input (Tensor): the input tensor.
  24867. other (Tensor or Number): the tensor or number to subtract from :attr:`input`.
  24868. Keyword args:
  24869. alpha (Number): the multiplier for :attr:`other`.
  24870. out (Tensor, optional): the output tensor.
  24871. Example::
  24872. >>> a = torch.tensor((1, 2))
  24873. >>> b = torch.tensor((0, 1))
  24874. >>> torch.sub(a, b, alpha=2)
  24875. tensor([1, 0])
  24876. """
  24877. @overload
  24878. def sub(
  24879. self: Tensor,
  24880. alpha: Number | _complex,
  24881. other: Tensor,
  24882. *,
  24883. out: Tensor,
  24884. ) -> Tensor:
  24885. r"""
  24886. sub(input, other, *, alpha=1, out=None) -> Tensor
  24887. Subtracts :attr:`other`, scaled by :attr:`alpha`, from :attr:`input`.
  24888. .. math::
  24889. \text{{out}}_i = \text{{input}}_i - \text{{alpha}} \times \text{{other}}_i
  24890. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  24891. :ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
  24892. Args:
  24893. input (Tensor): the input tensor.
  24894. other (Tensor or Number): the tensor or number to subtract from :attr:`input`.
  24895. Keyword args:
  24896. alpha (Number): the multiplier for :attr:`other`.
  24897. out (Tensor, optional): the output tensor.
  24898. Example::
  24899. >>> a = torch.tensor((1, 2))
  24900. >>> b = torch.tensor((0, 1))
  24901. >>> torch.sub(a, b, alpha=2)
  24902. tensor([1, 0])
  24903. """
  24904. @overload
  24905. def subtract(
  24906. input: Tensor,
  24907. other: Tensor,
  24908. *,
  24909. alpha: Number | _complex = 1,
  24910. out: Tensor | None = None,
  24911. ) -> Tensor:
  24912. r"""
  24913. subtract(input, other, *, alpha=1, out=None) -> Tensor
  24914. Alias for :func:`torch.sub`.
  24915. """
  24916. @overload
  24917. def subtract(
  24918. input: Tensor,
  24919. other: Number | _complex,
  24920. alpha: Number | _complex = 1,
  24921. ) -> Tensor:
  24922. r"""
  24923. subtract(input, other, *, alpha=1, out=None) -> Tensor
  24924. Alias for :func:`torch.sub`.
  24925. """
  24926. @overload
  24927. def sum(input: Tensor, *, dtype: _dtype | None = None) -> Tensor:
  24928. r"""
  24929. sum(input, *, dtype=None) -> Tensor
  24930. Returns the sum of all elements in the :attr:`input` tensor.
  24931. Args:
  24932. input (Tensor): the input tensor.
  24933. Keyword args:
  24934. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  24935. If specified, the input tensor is casted to :attr:`dtype` before the operation
  24936. is performed. This is useful for preventing data type overflows. Default: None.
  24937. .. note:: Use the `dtype` argument if you need the result in a specific tensor type.
  24938. Otherwise, the result type may be automatically promoted (e.g., from `torch.int32` to `torch.int64`).
  24939. Example::
  24940. >>> a = torch.randn(1, 3)
  24941. >>> a
  24942. tensor([[ 0.1133, -0.9567, 0.2958]])
  24943. >>> torch.sum(a)
  24944. tensor(-0.5475)
  24945. .. function:: sum(input, dim, keepdim=False, *, dtype=None) -> Tensor
  24946. :noindex:
  24947. Returns the sum of each row of the :attr:`input` tensor in the given
  24948. dimension :attr:`dim`. If :attr:`dim` is a list of dimensions,
  24949. reduce over all of them.
  24950. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24951. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24952. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24953. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24954. Args:
  24955. input (Tensor): the input tensor.
  24956. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24957. If ``None``, all dimensions are reduced.
  24958. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24959. Keyword args:
  24960. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  24961. If specified, the input tensor is casted to :attr:`dtype` before the operation
  24962. is performed. This is useful for preventing data type overflows. Default: None.
  24963. Example::
  24964. >>> a = torch.randn(4, 4)
  24965. >>> a
  24966. tensor([[ 0.0569, -0.2475, 0.0737, -0.3429],
  24967. [-0.2993, 0.9138, 0.9337, -1.6864],
  24968. [ 0.1132, 0.7892, -0.1003, 0.5688],
  24969. [ 0.3637, -0.9906, -0.4752, -1.5197]])
  24970. >>> torch.sum(a, 1)
  24971. tensor([-0.4598, -0.1381, 1.3708, -2.6217])
  24972. >>> b = torch.arange(4 * 5 * 6).view(4, 5, 6)
  24973. >>> torch.sum(b, (2, 1))
  24974. tensor([ 435., 1335., 2235., 3135.])
  24975. """
  24976. @overload
  24977. def sum(
  24978. input: Tensor,
  24979. dim: _int | _size | None,
  24980. keepdim: _bool = False,
  24981. *,
  24982. dtype: _dtype | None = None,
  24983. out: Tensor | None = None,
  24984. ) -> Tensor:
  24985. r"""
  24986. sum(input, *, dtype=None) -> Tensor
  24987. Returns the sum of all elements in the :attr:`input` tensor.
  24988. Args:
  24989. input (Tensor): the input tensor.
  24990. Keyword args:
  24991. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  24992. If specified, the input tensor is casted to :attr:`dtype` before the operation
  24993. is performed. This is useful for preventing data type overflows. Default: None.
  24994. .. note:: Use the `dtype` argument if you need the result in a specific tensor type.
  24995. Otherwise, the result type may be automatically promoted (e.g., from `torch.int32` to `torch.int64`).
  24996. Example::
  24997. >>> a = torch.randn(1, 3)
  24998. >>> a
  24999. tensor([[ 0.1133, -0.9567, 0.2958]])
  25000. >>> torch.sum(a)
  25001. tensor(-0.5475)
  25002. .. function:: sum(input, dim, keepdim=False, *, dtype=None) -> Tensor
  25003. :noindex:
  25004. Returns the sum of each row of the :attr:`input` tensor in the given
  25005. dimension :attr:`dim`. If :attr:`dim` is a list of dimensions,
  25006. reduce over all of them.
  25007. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  25008. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  25009. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  25010. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  25011. Args:
  25012. input (Tensor): the input tensor.
  25013. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  25014. If ``None``, all dimensions are reduced.
  25015. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  25016. Keyword args:
  25017. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  25018. If specified, the input tensor is casted to :attr:`dtype` before the operation
  25019. is performed. This is useful for preventing data type overflows. Default: None.
  25020. Example::
  25021. >>> a = torch.randn(4, 4)
  25022. >>> a
  25023. tensor([[ 0.0569, -0.2475, 0.0737, -0.3429],
  25024. [-0.2993, 0.9138, 0.9337, -1.6864],
  25025. [ 0.1132, 0.7892, -0.1003, 0.5688],
  25026. [ 0.3637, -0.9906, -0.4752, -1.5197]])
  25027. >>> torch.sum(a, 1)
  25028. tensor([-0.4598, -0.1381, 1.3708, -2.6217])
  25029. >>> b = torch.arange(4 * 5 * 6).view(4, 5, 6)
  25030. >>> torch.sum(b, (2, 1))
  25031. tensor([ 435., 1335., 2235., 3135.])
  25032. """
  25033. @overload
  25034. def sum(
  25035. input: Tensor,
  25036. dim: Sequence[str | EllipsisType | None],
  25037. keepdim: _bool = False,
  25038. *,
  25039. dtype: _dtype | None = None,
  25040. out: Tensor | None = None,
  25041. ) -> Tensor:
  25042. r"""
  25043. sum(input, *, dtype=None) -> Tensor
  25044. Returns the sum of all elements in the :attr:`input` tensor.
  25045. Args:
  25046. input (Tensor): the input tensor.
  25047. Keyword args:
  25048. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  25049. If specified, the input tensor is casted to :attr:`dtype` before the operation
  25050. is performed. This is useful for preventing data type overflows. Default: None.
  25051. .. note:: Use the `dtype` argument if you need the result in a specific tensor type.
  25052. Otherwise, the result type may be automatically promoted (e.g., from `torch.int32` to `torch.int64`).
  25053. Example::
  25054. >>> a = torch.randn(1, 3)
  25055. >>> a
  25056. tensor([[ 0.1133, -0.9567, 0.2958]])
  25057. >>> torch.sum(a)
  25058. tensor(-0.5475)
  25059. .. function:: sum(input, dim, keepdim=False, *, dtype=None) -> Tensor
  25060. :noindex:
  25061. Returns the sum of each row of the :attr:`input` tensor in the given
  25062. dimension :attr:`dim`. If :attr:`dim` is a list of dimensions,
  25063. reduce over all of them.
  25064. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  25065. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  25066. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  25067. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  25068. Args:
  25069. input (Tensor): the input tensor.
  25070. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  25071. If ``None``, all dimensions are reduced.
  25072. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  25073. Keyword args:
  25074. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  25075. If specified, the input tensor is casted to :attr:`dtype` before the operation
  25076. is performed. This is useful for preventing data type overflows. Default: None.
  25077. Example::
  25078. >>> a = torch.randn(4, 4)
  25079. >>> a
  25080. tensor([[ 0.0569, -0.2475, 0.0737, -0.3429],
  25081. [-0.2993, 0.9138, 0.9337, -1.6864],
  25082. [ 0.1132, 0.7892, -0.1003, 0.5688],
  25083. [ 0.3637, -0.9906, -0.4752, -1.5197]])
  25084. >>> torch.sum(a, 1)
  25085. tensor([-0.4598, -0.1381, 1.3708, -2.6217])
  25086. >>> b = torch.arange(4 * 5 * 6).view(4, 5, 6)
  25087. >>> torch.sum(b, (2, 1))
  25088. tensor([ 435., 1335., 2235., 3135.])
  25089. """
  25090. def svd(
  25091. input: Tensor,
  25092. some: _bool = True,
  25093. compute_uv: _bool = True,
  25094. *,
  25095. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  25096. ) -> torch.return_types.svd:
  25097. r"""
  25098. svd(input, some=True, compute_uv=True, *, out=None) -> (Tensor, Tensor, Tensor)
  25099. Computes the singular value decomposition of either a matrix or batch of
  25100. matrices :attr:`input`. The singular value decomposition is represented as a
  25101. namedtuple `(U, S, V)`, such that :attr:`input` :math:`= U \text{diag}(S) V^{\text{H}}`.
  25102. where :math:`V^{\text{H}}` is the transpose of `V` for real inputs,
  25103. and the conjugate transpose of `V` for complex inputs.
  25104. If :attr:`input` is a batch of matrices, then `U`, `S`, and `V` are also
  25105. batched with the same batch dimensions as :attr:`input`.
  25106. If :attr:`some` is `True` (default), the method returns the reduced singular
  25107. value decomposition. In this case, if the last two dimensions of :attr:`input` are
  25108. `m` and `n`, then the returned `U` and `V` matrices will contain only
  25109. `min(n, m)` orthonormal columns.
  25110. If :attr:`compute_uv` is `False`, the returned `U` and `V` will be
  25111. zero-filled matrices of shape `(m, m)` and `(n, n)`
  25112. respectively, and the same device as :attr:`input`. The argument :attr:`some`
  25113. has no effect when :attr:`compute_uv` is `False`.
  25114. Supports :attr:`input` of float, double, cfloat and cdouble data types.
  25115. The dtypes of `U` and `V` are the same as :attr:`input`'s. `S` will
  25116. always be real-valued, even if :attr:`input` is complex.
  25117. .. warning::
  25118. :func:`torch.svd` is deprecated in favor of :func:`torch.linalg.svd`
  25119. and will be removed in a future PyTorch release.
  25120. ``U, S, V = torch.svd(A, some=some, compute_uv=True)`` (default) should be replaced with
  25121. .. code:: python
  25122. U, S, Vh = torch.linalg.svd(A, full_matrices=not some)
  25123. V = Vh.mH
  25124. ``_, S, _ = torch.svd(A, some=some, compute_uv=False)`` should be replaced with
  25125. .. code:: python
  25126. S = torch.linalg.svdvals(A)
  25127. .. note:: Differences with :func:`torch.linalg.svd`:
  25128. * :attr:`some` is the opposite of
  25129. :func:`torch.linalg.svd`'s :attr:`full_matrices`. Note that
  25130. default value for both is `True`, so the default behavior is
  25131. effectively the opposite.
  25132. * :func:`torch.svd` returns `V`, whereas :func:`torch.linalg.svd` returns
  25133. `Vh`, that is, :math:`V^{\text{H}}`.
  25134. * If :attr:`compute_uv` is `False`, :func:`torch.svd` returns zero-filled
  25135. tensors for `U` and `Vh`, whereas :func:`torch.linalg.svd` returns
  25136. empty tensors.
  25137. .. note:: The singular values are returned in descending order. If :attr:`input` is a batch of matrices,
  25138. then the singular values of each matrix in the batch are returned in descending order.
  25139. .. note:: The `S` tensor can only be used to compute gradients if :attr:`compute_uv` is `True`.
  25140. .. note:: When :attr:`some` is `False`, the gradients on `U[..., :, min(m, n):]`
  25141. and `V[..., :, min(m, n):]` will be ignored in the backward pass, as those vectors
  25142. can be arbitrary bases of the corresponding subspaces.
  25143. .. note:: The implementation of :func:`torch.linalg.svd` on CPU uses LAPACK's routine `?gesdd`
  25144. (a divide-and-conquer algorithm) instead of `?gesvd` for speed. Analogously,
  25145. on GPU, it uses cuSOLVER's routines `gesvdj` and `gesvdjBatched` on CUDA 10.1.243
  25146. and later, and MAGMA's routine `gesdd` on earlier versions of CUDA.
  25147. .. note:: The returned `U` will not be contiguous. The matrix (or batch of matrices) will
  25148. be represented as a column-major matrix (i.e. Fortran-contiguous).
  25149. .. warning:: The gradients with respect to `U` and `V` will only be finite when the input does not
  25150. have zero nor repeated singular values.
  25151. .. warning:: If the distance between any two singular values is close to zero, the gradients with respect to
  25152. `U` and `V` will be numerically unstable, as they depends on
  25153. :math:`\frac{1}{\min_{i \neq j} \sigma_i^2 - \sigma_j^2}`. The same happens when the matrix
  25154. has small singular values, as these gradients also depend on `S^{-1}`.
  25155. .. warning:: For complex-valued :attr:`input` the singular value decomposition is not unique,
  25156. as `U` and `V` may be multiplied by an arbitrary phase factor :math:`e^{i \phi}` on every column.
  25157. The same happens when :attr:`input` has repeated singular values, where one may multiply
  25158. the columns of the spanning subspace in `U` and `V` by a rotation matrix
  25159. and `the resulting vectors will span the same subspace`_.
  25160. Different platforms, like NumPy, or inputs on different device types,
  25161. may produce different `U` and `V` tensors.
  25162. Args:
  25163. input (Tensor): the input tensor of size `(*, m, n)` where `*` is zero or more
  25164. batch dimensions consisting of `(m, n)` matrices.
  25165. some (bool, optional): controls whether to compute the reduced or full decomposition, and
  25166. consequently, the shape of returned `U` and `V`. Default: `True`.
  25167. compute_uv (bool, optional): controls whether to compute `U` and `V`. Default: `True`.
  25168. Keyword args:
  25169. out (tuple, optional): the output tuple of tensors
  25170. Example::
  25171. >>> a = torch.randn(5, 3)
  25172. >>> a
  25173. tensor([[ 0.2364, -0.7752, 0.6372],
  25174. [ 1.7201, 0.7394, -0.0504],
  25175. [-0.3371, -1.0584, 0.5296],
  25176. [ 0.3550, -0.4022, 1.5569],
  25177. [ 0.2445, -0.0158, 1.1414]])
  25178. >>> u, s, v = torch.svd(a)
  25179. >>> u
  25180. tensor([[ 0.4027, 0.0287, 0.5434],
  25181. [-0.1946, 0.8833, 0.3679],
  25182. [ 0.4296, -0.2890, 0.5261],
  25183. [ 0.6604, 0.2717, -0.2618],
  25184. [ 0.4234, 0.2481, -0.4733]])
  25185. >>> s
  25186. tensor([2.3289, 2.0315, 0.7806])
  25187. >>> v
  25188. tensor([[-0.0199, 0.8766, 0.4809],
  25189. [-0.5080, 0.4054, -0.7600],
  25190. [ 0.8611, 0.2594, -0.4373]])
  25191. >>> torch.dist(a, torch.mm(torch.mm(u, torch.diag(s)), v.t()))
  25192. tensor(8.6531e-07)
  25193. >>> a_big = torch.randn(7, 5, 3)
  25194. >>> u, s, v = torch.svd(a_big)
  25195. >>> torch.dist(a_big, torch.matmul(torch.matmul(u, torch.diag_embed(s)), v.mT))
  25196. tensor(2.6503e-06)
  25197. .. _the resulting vectors will span the same subspace:
  25198. (https://en.wikipedia.org/wiki/Singular_value_decomposition#Singular_values,_singular_vectors,_and_their_relation_to_the_SVD)
  25199. """
  25200. def swapaxes(input: Tensor, axis0: _int, axis1: _int) -> Tensor:
  25201. r"""
  25202. swapaxes(input, axis0, axis1) -> Tensor
  25203. Alias for :func:`torch.transpose`.
  25204. This function is equivalent to NumPy's swapaxes function.
  25205. Examples::
  25206. >>> x = torch.tensor([[[0,1],[2,3]],[[4,5],[6,7]]])
  25207. >>> x
  25208. tensor([[[0, 1],
  25209. [2, 3]],
  25210. [[4, 5],
  25211. [6, 7]]])
  25212. >>> torch.swapaxes(x, 0, 1)
  25213. tensor([[[0, 1],
  25214. [4, 5]],
  25215. [[2, 3],
  25216. [6, 7]]])
  25217. >>> torch.swapaxes(x, 0, 2)
  25218. tensor([[[0, 4],
  25219. [2, 6]],
  25220. [[1, 5],
  25221. [3, 7]]])
  25222. """
  25223. def swapdims(input: Tensor, dim0: _int, dim1: _int) -> Tensor:
  25224. r"""
  25225. swapdims(input, dim0, dim1) -> Tensor
  25226. Alias for :func:`torch.transpose`.
  25227. This function is equivalent to NumPy's swapaxes function.
  25228. Examples::
  25229. >>> x = torch.tensor([[[0,1],[2,3]],[[4,5],[6,7]]])
  25230. >>> x
  25231. tensor([[[0, 1],
  25232. [2, 3]],
  25233. [[4, 5],
  25234. [6, 7]]])
  25235. >>> torch.swapdims(x, 0, 1)
  25236. tensor([[[0, 1],
  25237. [4, 5]],
  25238. [[2, 3],
  25239. [6, 7]]])
  25240. >>> torch.swapdims(x, 0, 2)
  25241. tensor([[[0, 4],
  25242. [2, 6]],
  25243. [[1, 5],
  25244. [3, 7]]])
  25245. """
  25246. def sym_constrain_range(
  25247. size: Number | _complex,
  25248. *,
  25249. min: _int | None = None,
  25250. max: _int | None = None,
  25251. ) -> None: ...
  25252. def sym_constrain_range_for_size(
  25253. size: Number | _complex,
  25254. *,
  25255. min: _int | None = None,
  25256. max: _int | None = None,
  25257. ) -> None: ...
  25258. def t(input: Tensor) -> Tensor:
  25259. r"""
  25260. t(input) -> Tensor
  25261. Expects :attr:`input` to be <= 2-D tensor and transposes dimensions 0
  25262. and 1.
  25263. 0-D and 1-D tensors are returned as is. When input is a 2-D tensor this
  25264. is equivalent to ``transpose(input, 0, 1)``.
  25265. Args:
  25266. input (Tensor): the input tensor.
  25267. Example::
  25268. >>> x = torch.randn(())
  25269. >>> x
  25270. tensor(0.1995)
  25271. >>> torch.t(x)
  25272. tensor(0.1995)
  25273. >>> x = torch.randn(3)
  25274. >>> x
  25275. tensor([ 2.4320, -0.4608, 0.7702])
  25276. >>> torch.t(x)
  25277. tensor([ 2.4320, -0.4608, 0.7702])
  25278. >>> x = torch.randn(2, 3)
  25279. >>> x
  25280. tensor([[ 0.4875, 0.9158, -0.5872],
  25281. [ 0.3938, -0.6929, 0.6932]])
  25282. >>> torch.t(x)
  25283. tensor([[ 0.4875, 0.3938],
  25284. [ 0.9158, -0.6929],
  25285. [-0.5872, 0.6932]])
  25286. See also :func:`torch.transpose`.
  25287. """
  25288. def t_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  25289. r"""
  25290. Performs the same operation as :func:`torch.t`, but all output tensors
  25291. are freshly created instead of aliasing the input.
  25292. """
  25293. def take(
  25294. input: Tensor,
  25295. index: Tensor,
  25296. *,
  25297. out: Tensor | None = None,
  25298. ) -> Tensor:
  25299. r"""
  25300. take(input, index) -> Tensor
  25301. Returns a new tensor with the elements of :attr:`input` at the given indices.
  25302. The input tensor is treated as if it were viewed as a 1-D tensor. The result
  25303. takes the same shape as the indices.
  25304. Args:
  25305. input (Tensor): the input tensor.
  25306. index (LongTensor): the indices into tensor
  25307. Example::
  25308. >>> src = torch.tensor([[4, 3, 5],
  25309. ... [6, 7, 8]])
  25310. >>> torch.take(src, torch.tensor([0, 2, 5]))
  25311. tensor([ 4, 5, 8])
  25312. """
  25313. def take_along_dim(
  25314. input: Tensor,
  25315. indices: Tensor,
  25316. dim: _int | None = None,
  25317. *,
  25318. out: Tensor | None = None,
  25319. ) -> Tensor:
  25320. r"""
  25321. take_along_dim(input, indices, dim=None, *, out=None) -> Tensor
  25322. Selects values from :attr:`input` at the 1-dimensional indices from :attr:`indices` along the given :attr:`dim`.
  25323. If :attr:`dim` is None, the input array is treated as if it has been flattened to 1d.
  25324. Functions that return indices along a dimension, like :func:`torch.argmax` and :func:`torch.argsort`,
  25325. are designed to work with this function. See the examples below.
  25326. .. note::
  25327. This function is similar to NumPy's `take_along_axis`.
  25328. See also :func:`torch.gather`.
  25329. Args:
  25330. input (Tensor): the input tensor.
  25331. indices (LongTensor): the indices into :attr:`input`. Must have long dtype.
  25332. dim (int, optional): dimension to select along. Default: 0
  25333. Keyword args:
  25334. out (Tensor, optional): the output tensor.
  25335. Example::
  25336. >>> t = torch.tensor([[10, 30, 20], [60, 40, 50]])
  25337. >>> max_idx = torch.argmax(t)
  25338. >>> torch.take_along_dim(t, max_idx)
  25339. tensor([60])
  25340. >>> sorted_idx = torch.argsort(t, dim=1)
  25341. >>> torch.take_along_dim(t, sorted_idx, dim=1)
  25342. tensor([[10, 20, 30],
  25343. [40, 50, 60]])
  25344. """
  25345. def tan(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  25346. r"""
  25347. tan(input, *, out=None) -> Tensor
  25348. Returns a new tensor with the tangent of the elements in the :attr:`input` tensor,
  25349. where each value in this input tensor is in radians.
  25350. .. math::
  25351. \text{out}_{i} = \tan(\text{input}_{i})
  25352. Args:
  25353. input (Tensor): the input tensor.
  25354. Keyword args:
  25355. out (Tensor, optional): the output tensor.
  25356. Example::
  25357. >>> a = torch.randn(4)
  25358. >>> a
  25359. tensor([-1.2027, -1.7687, 0.4412, -1.3856])
  25360. >>> torch.tan(a)
  25361. tensor([-2.5930, 4.9859, 0.4722, -5.3366])
  25362. """
  25363. def tan_(input: Tensor) -> Tensor: ...
  25364. def tanh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  25365. r"""
  25366. tanh(input, *, out=None) -> Tensor
  25367. Returns a new tensor with the hyperbolic tangent of the elements
  25368. of :attr:`input`.
  25369. .. math::
  25370. \text{out}_{i} = \tanh(\text{input}_{i})
  25371. Args:
  25372. input (Tensor): the input tensor.
  25373. Keyword args:
  25374. out (Tensor, optional): the output tensor.
  25375. Example::
  25376. >>> a = torch.randn(4)
  25377. >>> a
  25378. tensor([ 0.8986, -0.7279, 1.1745, 0.2611])
  25379. >>> torch.tanh(a)
  25380. tensor([ 0.7156, -0.6218, 0.8257, 0.2553])
  25381. """
  25382. def tanh_(input: Tensor) -> Tensor: ...
  25383. def tensor(
  25384. data: Any,
  25385. dtype: _dtype | None = None,
  25386. device: DeviceLikeType | None = None,
  25387. requires_grad: _bool = False,
  25388. pin_memory: _bool = False,
  25389. ) -> Tensor:
  25390. r"""
  25391. tensor(data, *, dtype=None, device=None, requires_grad=False, pin_memory=False) -> Tensor
  25392. Constructs a tensor with no autograd history (also known as a "leaf tensor", see :doc:`/notes/autograd`) by copying :attr:`data`.
  25393. .. warning::
  25394. When working with tensors prefer using :func:`torch.Tensor.clone`,
  25395. :func:`torch.Tensor.detach`, and :func:`torch.Tensor.requires_grad_` for
  25396. readability. Letting `t` be a tensor, ``torch.tensor(t)`` is equivalent to
  25397. ``t.detach().clone()``, and ``torch.tensor(t, requires_grad=True)``
  25398. is equivalent to ``t.detach().clone().requires_grad_(True)``.
  25399. .. seealso::
  25400. :func:`torch.as_tensor` preserves autograd history and avoids copies where possible.
  25401. :func:`torch.from_numpy` creates a tensor that shares storage with a NumPy array.
  25402. Args:
  25403. data (array_like): Initial data for the tensor. Can be a list, tuple,
  25404. NumPy ``ndarray``, scalar, and other types.
  25405. Keyword args:
  25406. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  25407. Default: if ``None``, infers data type from :attr:`data`.
  25408. device (:class:`torch.device`, optional): the device of the constructed tensor. If None and data is a tensor
  25409. then the device of data is used. If None and data is not a tensor then
  25410. the result tensor is constructed on the current device.
  25411. requires_grad (bool, optional): If autograd should record operations on the
  25412. returned tensor. Default: ``False``.
  25413. pin_memory (bool, optional): If set, returned tensor would be allocated in
  25414. the pinned memory. Works only for CPU tensors. Default: ``False``.
  25415. Example::
  25416. >>> torch.tensor([[0.1, 1.2], [2.2, 3.1], [4.9, 5.2]])
  25417. tensor([[ 0.1000, 1.2000],
  25418. [ 2.2000, 3.1000],
  25419. [ 4.9000, 5.2000]])
  25420. >>> torch.tensor([0, 1]) # Type inference on data
  25421. tensor([ 0, 1])
  25422. >>> torch.tensor([[0.11111, 0.222222, 0.3333333]],
  25423. ... dtype=torch.float64,
  25424. ... device=torch.device('cuda:0')) # creates a double tensor on a CUDA device
  25425. tensor([[ 0.1111, 0.2222, 0.3333]], dtype=torch.float64, device='cuda:0')
  25426. >>> torch.tensor(3.14159) # Create a zero-dimensional (scalar) tensor
  25427. tensor(3.1416)
  25428. >>> torch.tensor([]) # Create an empty tensor (of size (0,))
  25429. tensor([])
  25430. """
  25431. @overload
  25432. def tensor_split(
  25433. input: Tensor,
  25434. tensor_indices_or_sections: Tensor,
  25435. dim: _int = 0,
  25436. ) -> tuple[Tensor, ...]:
  25437. r"""
  25438. tensor_split(input, indices_or_sections, dim=0) -> List of Tensors
  25439. Splits a tensor into multiple sub-tensors, all of which are views of :attr:`input`,
  25440. along dimension :attr:`dim` according to the indices or number of sections specified
  25441. by :attr:`indices_or_sections`. This function is based on NumPy's
  25442. :func:`numpy.array_split`.
  25443. Args:
  25444. input (Tensor): the tensor to split
  25445. indices_or_sections (Tensor, int or list or tuple of ints):
  25446. If :attr:`indices_or_sections` is an integer ``n`` or a zero dimensional long tensor
  25447. with value ``n``, :attr:`input` is split into ``n`` sections along dimension :attr:`dim`.
  25448. If :attr:`input` is divisible by ``n`` along dimension :attr:`dim`, each
  25449. section will be of equal size, :code:`input.size(dim) / n`. If :attr:`input`
  25450. is not divisible by ``n``, the sizes of the first :code:`int(input.size(dim) % n)`
  25451. sections will have size :code:`int(input.size(dim) / n) + 1`, and the rest will
  25452. have size :code:`int(input.size(dim) / n)`.
  25453. If :attr:`indices_or_sections` is a list or tuple of ints, or a one-dimensional long
  25454. tensor, then :attr:`input` is split along dimension :attr:`dim` at each of the indices
  25455. in the list, tuple or tensor. For instance, :code:`indices_or_sections=[2, 3]` and :code:`dim=0`
  25456. would result in the tensors :code:`input[:2]`, :code:`input[2:3]`, and :code:`input[3:]`.
  25457. If :attr:`indices_or_sections` is a tensor, it must be a zero-dimensional or one-dimensional
  25458. long tensor on the CPU.
  25459. dim (int, optional): dimension along which to split the tensor. Default: ``0``
  25460. Example::
  25461. >>> x = torch.arange(8)
  25462. >>> torch.tensor_split(x, 3)
  25463. (tensor([0, 1, 2]), tensor([3, 4, 5]), tensor([6, 7]))
  25464. >>> x = torch.arange(7)
  25465. >>> torch.tensor_split(x, 3)
  25466. (tensor([0, 1, 2]), tensor([3, 4]), tensor([5, 6]))
  25467. >>> torch.tensor_split(x, (1, 6))
  25468. (tensor([0]), tensor([1, 2, 3, 4, 5]), tensor([6]))
  25469. >>> x = torch.arange(14).reshape(2, 7)
  25470. >>> x
  25471. tensor([[ 0, 1, 2, 3, 4, 5, 6],
  25472. [ 7, 8, 9, 10, 11, 12, 13]])
  25473. >>> torch.tensor_split(x, 3, dim=1)
  25474. (tensor([[0, 1, 2],
  25475. [7, 8, 9]]),
  25476. tensor([[ 3, 4],
  25477. [10, 11]]),
  25478. tensor([[ 5, 6],
  25479. [12, 13]]))
  25480. >>> torch.tensor_split(x, (1, 6), dim=1)
  25481. (tensor([[0],
  25482. [7]]),
  25483. tensor([[ 1, 2, 3, 4, 5],
  25484. [ 8, 9, 10, 11, 12]]),
  25485. tensor([[ 6],
  25486. [13]]))
  25487. """
  25488. @overload
  25489. def tensor_split(
  25490. input: Tensor,
  25491. sections: _int | SymInt,
  25492. dim: _int = 0,
  25493. ) -> tuple[Tensor, ...]:
  25494. r"""
  25495. tensor_split(input, indices_or_sections, dim=0) -> List of Tensors
  25496. Splits a tensor into multiple sub-tensors, all of which are views of :attr:`input`,
  25497. along dimension :attr:`dim` according to the indices or number of sections specified
  25498. by :attr:`indices_or_sections`. This function is based on NumPy's
  25499. :func:`numpy.array_split`.
  25500. Args:
  25501. input (Tensor): the tensor to split
  25502. indices_or_sections (Tensor, int or list or tuple of ints):
  25503. If :attr:`indices_or_sections` is an integer ``n`` or a zero dimensional long tensor
  25504. with value ``n``, :attr:`input` is split into ``n`` sections along dimension :attr:`dim`.
  25505. If :attr:`input` is divisible by ``n`` along dimension :attr:`dim`, each
  25506. section will be of equal size, :code:`input.size(dim) / n`. If :attr:`input`
  25507. is not divisible by ``n``, the sizes of the first :code:`int(input.size(dim) % n)`
  25508. sections will have size :code:`int(input.size(dim) / n) + 1`, and the rest will
  25509. have size :code:`int(input.size(dim) / n)`.
  25510. If :attr:`indices_or_sections` is a list or tuple of ints, or a one-dimensional long
  25511. tensor, then :attr:`input` is split along dimension :attr:`dim` at each of the indices
  25512. in the list, tuple or tensor. For instance, :code:`indices_or_sections=[2, 3]` and :code:`dim=0`
  25513. would result in the tensors :code:`input[:2]`, :code:`input[2:3]`, and :code:`input[3:]`.
  25514. If :attr:`indices_or_sections` is a tensor, it must be a zero-dimensional or one-dimensional
  25515. long tensor on the CPU.
  25516. dim (int, optional): dimension along which to split the tensor. Default: ``0``
  25517. Example::
  25518. >>> x = torch.arange(8)
  25519. >>> torch.tensor_split(x, 3)
  25520. (tensor([0, 1, 2]), tensor([3, 4, 5]), tensor([6, 7]))
  25521. >>> x = torch.arange(7)
  25522. >>> torch.tensor_split(x, 3)
  25523. (tensor([0, 1, 2]), tensor([3, 4]), tensor([5, 6]))
  25524. >>> torch.tensor_split(x, (1, 6))
  25525. (tensor([0]), tensor([1, 2, 3, 4, 5]), tensor([6]))
  25526. >>> x = torch.arange(14).reshape(2, 7)
  25527. >>> x
  25528. tensor([[ 0, 1, 2, 3, 4, 5, 6],
  25529. [ 7, 8, 9, 10, 11, 12, 13]])
  25530. >>> torch.tensor_split(x, 3, dim=1)
  25531. (tensor([[0, 1, 2],
  25532. [7, 8, 9]]),
  25533. tensor([[ 3, 4],
  25534. [10, 11]]),
  25535. tensor([[ 5, 6],
  25536. [12, 13]]))
  25537. >>> torch.tensor_split(x, (1, 6), dim=1)
  25538. (tensor([[0],
  25539. [7]]),
  25540. tensor([[ 1, 2, 3, 4, 5],
  25541. [ 8, 9, 10, 11, 12]]),
  25542. tensor([[ 6],
  25543. [13]]))
  25544. """
  25545. @overload
  25546. def tensor_split(
  25547. input: Tensor,
  25548. indices: Sequence[_int | SymInt],
  25549. dim: _int = 0,
  25550. ) -> tuple[Tensor, ...]:
  25551. r"""
  25552. tensor_split(input, indices_or_sections, dim=0) -> List of Tensors
  25553. Splits a tensor into multiple sub-tensors, all of which are views of :attr:`input`,
  25554. along dimension :attr:`dim` according to the indices or number of sections specified
  25555. by :attr:`indices_or_sections`. This function is based on NumPy's
  25556. :func:`numpy.array_split`.
  25557. Args:
  25558. input (Tensor): the tensor to split
  25559. indices_or_sections (Tensor, int or list or tuple of ints):
  25560. If :attr:`indices_or_sections` is an integer ``n`` or a zero dimensional long tensor
  25561. with value ``n``, :attr:`input` is split into ``n`` sections along dimension :attr:`dim`.
  25562. If :attr:`input` is divisible by ``n`` along dimension :attr:`dim`, each
  25563. section will be of equal size, :code:`input.size(dim) / n`. If :attr:`input`
  25564. is not divisible by ``n``, the sizes of the first :code:`int(input.size(dim) % n)`
  25565. sections will have size :code:`int(input.size(dim) / n) + 1`, and the rest will
  25566. have size :code:`int(input.size(dim) / n)`.
  25567. If :attr:`indices_or_sections` is a list or tuple of ints, or a one-dimensional long
  25568. tensor, then :attr:`input` is split along dimension :attr:`dim` at each of the indices
  25569. in the list, tuple or tensor. For instance, :code:`indices_or_sections=[2, 3]` and :code:`dim=0`
  25570. would result in the tensors :code:`input[:2]`, :code:`input[2:3]`, and :code:`input[3:]`.
  25571. If :attr:`indices_or_sections` is a tensor, it must be a zero-dimensional or one-dimensional
  25572. long tensor on the CPU.
  25573. dim (int, optional): dimension along which to split the tensor. Default: ``0``
  25574. Example::
  25575. >>> x = torch.arange(8)
  25576. >>> torch.tensor_split(x, 3)
  25577. (tensor([0, 1, 2]), tensor([3, 4, 5]), tensor([6, 7]))
  25578. >>> x = torch.arange(7)
  25579. >>> torch.tensor_split(x, 3)
  25580. (tensor([0, 1, 2]), tensor([3, 4]), tensor([5, 6]))
  25581. >>> torch.tensor_split(x, (1, 6))
  25582. (tensor([0]), tensor([1, 2, 3, 4, 5]), tensor([6]))
  25583. >>> x = torch.arange(14).reshape(2, 7)
  25584. >>> x
  25585. tensor([[ 0, 1, 2, 3, 4, 5, 6],
  25586. [ 7, 8, 9, 10, 11, 12, 13]])
  25587. >>> torch.tensor_split(x, 3, dim=1)
  25588. (tensor([[0, 1, 2],
  25589. [7, 8, 9]]),
  25590. tensor([[ 3, 4],
  25591. [10, 11]]),
  25592. tensor([[ 5, 6],
  25593. [12, 13]]))
  25594. >>> torch.tensor_split(x, (1, 6), dim=1)
  25595. (tensor([[0],
  25596. [7]]),
  25597. tensor([[ 1, 2, 3, 4, 5],
  25598. [ 8, 9, 10, 11, 12]]),
  25599. tensor([[ 6],
  25600. [13]]))
  25601. """
  25602. def threshold(
  25603. input: Tensor,
  25604. threshold: Number | _complex,
  25605. value: Number | _complex,
  25606. *,
  25607. out: Tensor | None = None,
  25608. ) -> Tensor: ...
  25609. def threshold_(
  25610. input: Tensor,
  25611. threshold: Number | _complex,
  25612. value: Number | _complex,
  25613. ) -> Tensor: ...
  25614. def tile(input: Tensor, dims: Sequence[_int | SymInt]) -> Tensor:
  25615. r"""
  25616. tile(input, dims) -> Tensor
  25617. Constructs a tensor by repeating the elements of :attr:`input`.
  25618. The :attr:`dims` argument specifies the number of repetitions
  25619. in each dimension.
  25620. If :attr:`dims` specifies fewer dimensions than :attr:`input` has, then
  25621. ones are prepended to :attr:`dims` until all dimensions are specified.
  25622. For example, if :attr:`input` has shape (8, 6, 4, 2) and :attr:`dims`
  25623. is (2, 2), then :attr:`dims` is treated as (1, 1, 2, 2).
  25624. Analogously, if :attr:`input` has fewer dimensions than :attr:`dims`
  25625. specifies, then :attr:`input` is treated as if it were unsqueezed at
  25626. dimension zero until it has as many dimensions as :attr:`dims` specifies.
  25627. For example, if :attr:`input` has shape (4, 2) and :attr:`dims`
  25628. is (3, 3, 2, 2), then :attr:`input` is treated as if it had the
  25629. shape (1, 1, 4, 2).
  25630. .. note::
  25631. This function is similar to NumPy's tile function.
  25632. Args:
  25633. input (Tensor): the tensor whose elements to repeat.
  25634. dims (tuple): the number of repetitions per dimension.
  25635. Example::
  25636. >>> x = torch.tensor([1, 2, 3])
  25637. >>> x.tile((2,))
  25638. tensor([1, 2, 3, 1, 2, 3])
  25639. >>> y = torch.tensor([[1, 2], [3, 4]])
  25640. >>> torch.tile(y, (2, 2))
  25641. tensor([[1, 2, 1, 2],
  25642. [3, 4, 3, 4],
  25643. [1, 2, 1, 2],
  25644. [3, 4, 3, 4]])
  25645. """
  25646. def topk(
  25647. input: Tensor,
  25648. k: _int | SymInt,
  25649. dim: _int = -1,
  25650. largest: _bool = True,
  25651. sorted: _bool = True,
  25652. *,
  25653. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  25654. ) -> torch.return_types.topk:
  25655. r"""
  25656. topk(input, k, dim=None, largest=True, sorted=True, *, out=None) -> (Tensor, LongTensor)
  25657. Returns the :attr:`k` largest elements of the given :attr:`input` tensor along
  25658. a given dimension.
  25659. If :attr:`dim` is not given, the last dimension of the `input` is chosen.
  25660. If :attr:`largest` is ``False`` then the `k` smallest elements are returned.
  25661. A namedtuple of `(values, indices)` is returned with the `values` and
  25662. `indices` of the largest `k` elements of each row of the `input` tensor in the
  25663. given dimension `dim`.
  25664. The boolean option :attr:`sorted` if ``True``, will make sure that the returned
  25665. `k` elements are themselves sorted
  25666. .. note::
  25667. When using `torch.topk`, the indices of tied elements are not guaranteed to be stable
  25668. and may vary across different invocations.
  25669. Args:
  25670. input (Tensor): the input tensor.
  25671. k (int): the k in "top-k"
  25672. dim (int, optional): the dimension to sort along
  25673. largest (bool, optional): controls whether to return largest or
  25674. smallest elements
  25675. sorted (bool, optional): controls whether to return the elements
  25676. in sorted order
  25677. Keyword args:
  25678. out (tuple, optional): the output tuple of (Tensor, LongTensor) that can be
  25679. optionally given to be used as output buffers
  25680. Example::
  25681. >>> x = torch.arange(1., 6.)
  25682. >>> x
  25683. tensor([ 1., 2., 3., 4., 5.])
  25684. >>> torch.topk(x, 3)
  25685. torch.return_types.topk(values=tensor([5., 4., 3.]), indices=tensor([4, 3, 2]))
  25686. """
  25687. def trace(input: Tensor) -> Tensor:
  25688. r"""
  25689. trace(input) -> Tensor
  25690. Returns the sum of the elements of the diagonal of the input 2-D matrix.
  25691. Example::
  25692. >>> x = torch.arange(1., 10.).view(3, 3)
  25693. >>> x
  25694. tensor([[ 1., 2., 3.],
  25695. [ 4., 5., 6.],
  25696. [ 7., 8., 9.]])
  25697. >>> torch.trace(x)
  25698. tensor(15.)
  25699. """
  25700. @overload
  25701. def transpose(input: Tensor, dim0: _int, dim1: _int) -> Tensor:
  25702. r"""
  25703. transpose(input, dim0, dim1) -> Tensor
  25704. Returns a tensor that is a transposed version of :attr:`input`.
  25705. The given dimensions :attr:`dim0` and :attr:`dim1` are swapped.
  25706. If :attr:`input` is a strided tensor then the resulting :attr:`out`
  25707. tensor shares its underlying storage with the :attr:`input` tensor, so
  25708. changing the content of one would change the content of the other.
  25709. If :attr:`input` is a :ref:`sparse tensor <sparse-docs>` then the
  25710. resulting :attr:`out` tensor *does not* share the underlying storage
  25711. with the :attr:`input` tensor.
  25712. If :attr:`input` is a :ref:`sparse tensor <sparse-docs>` with compressed
  25713. layout (SparseCSR, SparseBSR, SparseCSC or SparseBSC) the arguments
  25714. :attr:`dim0` and :attr:`dim1` must be both batch dimensions, or must
  25715. both be sparse dimensions. The batch dimensions of a sparse tensor are the
  25716. dimensions preceding the sparse dimensions.
  25717. .. note::
  25718. Transpositions which interchange the sparse dimensions of a `SparseCSR`
  25719. or `SparseCSC` layout tensor will result in the layout changing between
  25720. the two options. Transposition of the sparse dimensions of a ` SparseBSR`
  25721. or `SparseBSC` layout tensor will likewise generate a result with the
  25722. opposite layout.
  25723. Args:
  25724. input (Tensor): the input tensor.
  25725. dim0 (int): the first dimension to be transposed
  25726. dim1 (int): the second dimension to be transposed
  25727. Example::
  25728. >>> x = torch.randn(2, 3)
  25729. >>> x
  25730. tensor([[ 1.0028, -0.9893, 0.5809],
  25731. [-0.1669, 0.7299, 0.4942]])
  25732. >>> torch.transpose(x, 0, 1)
  25733. tensor([[ 1.0028, -0.1669],
  25734. [-0.9893, 0.7299],
  25735. [ 0.5809, 0.4942]])
  25736. See also :func:`torch.t`.
  25737. """
  25738. @overload
  25739. def transpose(
  25740. input: Tensor,
  25741. dim0: str | EllipsisType | None,
  25742. dim1: str | EllipsisType | None,
  25743. ) -> Tensor:
  25744. r"""
  25745. transpose(input, dim0, dim1) -> Tensor
  25746. Returns a tensor that is a transposed version of :attr:`input`.
  25747. The given dimensions :attr:`dim0` and :attr:`dim1` are swapped.
  25748. If :attr:`input` is a strided tensor then the resulting :attr:`out`
  25749. tensor shares its underlying storage with the :attr:`input` tensor, so
  25750. changing the content of one would change the content of the other.
  25751. If :attr:`input` is a :ref:`sparse tensor <sparse-docs>` then the
  25752. resulting :attr:`out` tensor *does not* share the underlying storage
  25753. with the :attr:`input` tensor.
  25754. If :attr:`input` is a :ref:`sparse tensor <sparse-docs>` with compressed
  25755. layout (SparseCSR, SparseBSR, SparseCSC or SparseBSC) the arguments
  25756. :attr:`dim0` and :attr:`dim1` must be both batch dimensions, or must
  25757. both be sparse dimensions. The batch dimensions of a sparse tensor are the
  25758. dimensions preceding the sparse dimensions.
  25759. .. note::
  25760. Transpositions which interchange the sparse dimensions of a `SparseCSR`
  25761. or `SparseCSC` layout tensor will result in the layout changing between
  25762. the two options. Transposition of the sparse dimensions of a ` SparseBSR`
  25763. or `SparseBSC` layout tensor will likewise generate a result with the
  25764. opposite layout.
  25765. Args:
  25766. input (Tensor): the input tensor.
  25767. dim0 (int): the first dimension to be transposed
  25768. dim1 (int): the second dimension to be transposed
  25769. Example::
  25770. >>> x = torch.randn(2, 3)
  25771. >>> x
  25772. tensor([[ 1.0028, -0.9893, 0.5809],
  25773. [-0.1669, 0.7299, 0.4942]])
  25774. >>> torch.transpose(x, 0, 1)
  25775. tensor([[ 1.0028, -0.1669],
  25776. [-0.9893, 0.7299],
  25777. [ 0.5809, 0.4942]])
  25778. See also :func:`torch.t`.
  25779. """
  25780. def transpose_copy(
  25781. input: Tensor,
  25782. dim0: _int,
  25783. dim1: _int,
  25784. *,
  25785. out: Tensor | None = None,
  25786. ) -> Tensor:
  25787. r"""
  25788. Performs the same operation as :func:`torch.transpose`, but all output tensors
  25789. are freshly created instead of aliasing the input.
  25790. """
  25791. @overload
  25792. def trapezoid(y: Tensor, x: Tensor, *, dim: _int = -1) -> Tensor:
  25793. r"""
  25794. trapezoid(y, x=None, *, dx=None, dim=-1) -> Tensor
  25795. Computes the `trapezoidal rule <https://en.wikipedia.org/wiki/Trapezoidal_rule>`_ along
  25796. :attr:`dim`. By default the spacing between elements is assumed to be 1, but
  25797. :attr:`dx` can be used to specify a different constant spacing, and :attr:`x` can be
  25798. used to specify arbitrary spacing along :attr:`dim`. Only one of :attr:`x` or :attr:`dx` should be specified.
  25799. Assuming :attr:`y` is a one-dimensional tensor with elements :math:`{y_0, y_1, ..., y_n}`,
  25800. the default computation is
  25801. .. math::
  25802. \begin{aligned}
  25803. \sum_{i = 1}^{n} \frac{1}{2} (y_i + y_{i-1})
  25804. \end{aligned}
  25805. When :attr:`dx` is specified the computation becomes
  25806. .. math::
  25807. \begin{aligned}
  25808. \sum_{i = 1}^{n} \frac{\Delta x}{2} (y_i + y_{i-1})
  25809. \end{aligned}
  25810. effectively multiplying the result by :attr:`dx`. When :attr:`x` is specified,
  25811. assuming :attr:`x` is also a one-dimensional tensor with
  25812. elements :math:`{x_0, x_1, ..., x_n}`, the computation becomes
  25813. .. math::
  25814. \begin{aligned}
  25815. \sum_{i = 1}^{n} \frac{(x_i - x_{i-1})}{2} (y_i + y_{i-1})
  25816. \end{aligned}
  25817. When :attr:`x` and :attr:`y` have the same size, the computation is as described above and no broadcasting is needed.
  25818. The broadcasting behavior of this function is as follows when their sizes are different. For both :attr:`x`
  25819. and :attr:`y`, the function computes the difference between consecutive elements along
  25820. dimension :attr:`dim`. This effectively creates two tensors, `x_diff` and `y_diff`, that have
  25821. the same shape as the original tensors except their lengths along the dimension :attr:`dim` is reduced by 1.
  25822. After that, those two tensors are broadcast together to compute final output as part of the trapezoidal rule.
  25823. See the examples below for details.
  25824. .. note::
  25825. The trapezoidal rule is a technique for approximating the definite integral of a function
  25826. by averaging its left and right Riemann sums. The approximation becomes more accurate as
  25827. the resolution of the partition increases.
  25828. Arguments:
  25829. y (Tensor): Values to use when computing the trapezoidal rule.
  25830. x (Tensor): If specified, defines spacing between values as specified above.
  25831. Keyword arguments:
  25832. dx (float): constant spacing between values. If neither :attr:`x` or :attr:`dx`
  25833. are specified then this defaults to 1. Effectively multiplies the result by its value.
  25834. dim (int): The dimension along which to compute the trapezoidal rule.
  25835. The last (inner-most) dimension by default.
  25836. Examples::
  25837. >>> # Computes the trapezoidal rule in 1D, spacing is implicitly 1
  25838. >>> y = torch.tensor([1, 5, 10])
  25839. >>> torch.trapezoid(y)
  25840. tensor(10.5)
  25841. >>> # Computes the same trapezoidal rule directly to verify
  25842. >>> (1 + 10 + 10) / 2
  25843. 10.5
  25844. >>> # Computes the trapezoidal rule in 1D with constant spacing of 2
  25845. >>> # NOTE: the result is the same as before, but multiplied by 2
  25846. >>> torch.trapezoid(y, dx=2)
  25847. 21.0
  25848. >>> # Computes the trapezoidal rule in 1D with arbitrary spacing
  25849. >>> x = torch.tensor([1, 3, 6])
  25850. >>> torch.trapezoid(y, x)
  25851. 28.5
  25852. >>> # Computes the same trapezoidal rule directly to verify
  25853. >>> ((3 - 1) * (1 + 5) + (6 - 3) * (5 + 10)) / 2
  25854. 28.5
  25855. >>> # Computes the trapezoidal rule for each row of a 3x3 matrix
  25856. >>> y = torch.arange(9).reshape(3, 3)
  25857. tensor([[0, 1, 2],
  25858. [3, 4, 5],
  25859. [6, 7, 8]])
  25860. >>> torch.trapezoid(y)
  25861. tensor([ 2., 8., 14.])
  25862. >>> # Computes the trapezoidal rule for each column of the matrix
  25863. >>> torch.trapezoid(y, dim=0)
  25864. tensor([ 6., 8., 10.])
  25865. >>> # Computes the trapezoidal rule for each row of a 3x3 ones matrix
  25866. >>> # with the same arbitrary spacing
  25867. >>> y = torch.ones(3, 3)
  25868. >>> x = torch.tensor([1, 3, 6])
  25869. >>> torch.trapezoid(y, x)
  25870. array([5., 5., 5.])
  25871. >>> # Computes the trapezoidal rule for each row of a 3x3 ones matrix
  25872. >>> # with different arbitrary spacing per row
  25873. >>> y = torch.ones(3, 3)
  25874. >>> x = torch.tensor([[1, 2, 3], [1, 3, 5], [1, 4, 7]])
  25875. >>> torch.trapezoid(y, x)
  25876. array([2., 4., 6.])
  25877. """
  25878. @overload
  25879. def trapezoid(
  25880. y: Tensor,
  25881. *,
  25882. dx: Number | _complex = 1,
  25883. dim: _int = -1,
  25884. ) -> Tensor:
  25885. r"""
  25886. trapezoid(y, x=None, *, dx=None, dim=-1) -> Tensor
  25887. Computes the `trapezoidal rule <https://en.wikipedia.org/wiki/Trapezoidal_rule>`_ along
  25888. :attr:`dim`. By default the spacing between elements is assumed to be 1, but
  25889. :attr:`dx` can be used to specify a different constant spacing, and :attr:`x` can be
  25890. used to specify arbitrary spacing along :attr:`dim`. Only one of :attr:`x` or :attr:`dx` should be specified.
  25891. Assuming :attr:`y` is a one-dimensional tensor with elements :math:`{y_0, y_1, ..., y_n}`,
  25892. the default computation is
  25893. .. math::
  25894. \begin{aligned}
  25895. \sum_{i = 1}^{n} \frac{1}{2} (y_i + y_{i-1})
  25896. \end{aligned}
  25897. When :attr:`dx` is specified the computation becomes
  25898. .. math::
  25899. \begin{aligned}
  25900. \sum_{i = 1}^{n} \frac{\Delta x}{2} (y_i + y_{i-1})
  25901. \end{aligned}
  25902. effectively multiplying the result by :attr:`dx`. When :attr:`x` is specified,
  25903. assuming :attr:`x` is also a one-dimensional tensor with
  25904. elements :math:`{x_0, x_1, ..., x_n}`, the computation becomes
  25905. .. math::
  25906. \begin{aligned}
  25907. \sum_{i = 1}^{n} \frac{(x_i - x_{i-1})}{2} (y_i + y_{i-1})
  25908. \end{aligned}
  25909. When :attr:`x` and :attr:`y` have the same size, the computation is as described above and no broadcasting is needed.
  25910. The broadcasting behavior of this function is as follows when their sizes are different. For both :attr:`x`
  25911. and :attr:`y`, the function computes the difference between consecutive elements along
  25912. dimension :attr:`dim`. This effectively creates two tensors, `x_diff` and `y_diff`, that have
  25913. the same shape as the original tensors except their lengths along the dimension :attr:`dim` is reduced by 1.
  25914. After that, those two tensors are broadcast together to compute final output as part of the trapezoidal rule.
  25915. See the examples below for details.
  25916. .. note::
  25917. The trapezoidal rule is a technique for approximating the definite integral of a function
  25918. by averaging its left and right Riemann sums. The approximation becomes more accurate as
  25919. the resolution of the partition increases.
  25920. Arguments:
  25921. y (Tensor): Values to use when computing the trapezoidal rule.
  25922. x (Tensor): If specified, defines spacing between values as specified above.
  25923. Keyword arguments:
  25924. dx (float): constant spacing between values. If neither :attr:`x` or :attr:`dx`
  25925. are specified then this defaults to 1. Effectively multiplies the result by its value.
  25926. dim (int): The dimension along which to compute the trapezoidal rule.
  25927. The last (inner-most) dimension by default.
  25928. Examples::
  25929. >>> # Computes the trapezoidal rule in 1D, spacing is implicitly 1
  25930. >>> y = torch.tensor([1, 5, 10])
  25931. >>> torch.trapezoid(y)
  25932. tensor(10.5)
  25933. >>> # Computes the same trapezoidal rule directly to verify
  25934. >>> (1 + 10 + 10) / 2
  25935. 10.5
  25936. >>> # Computes the trapezoidal rule in 1D with constant spacing of 2
  25937. >>> # NOTE: the result is the same as before, but multiplied by 2
  25938. >>> torch.trapezoid(y, dx=2)
  25939. 21.0
  25940. >>> # Computes the trapezoidal rule in 1D with arbitrary spacing
  25941. >>> x = torch.tensor([1, 3, 6])
  25942. >>> torch.trapezoid(y, x)
  25943. 28.5
  25944. >>> # Computes the same trapezoidal rule directly to verify
  25945. >>> ((3 - 1) * (1 + 5) + (6 - 3) * (5 + 10)) / 2
  25946. 28.5
  25947. >>> # Computes the trapezoidal rule for each row of a 3x3 matrix
  25948. >>> y = torch.arange(9).reshape(3, 3)
  25949. tensor([[0, 1, 2],
  25950. [3, 4, 5],
  25951. [6, 7, 8]])
  25952. >>> torch.trapezoid(y)
  25953. tensor([ 2., 8., 14.])
  25954. >>> # Computes the trapezoidal rule for each column of the matrix
  25955. >>> torch.trapezoid(y, dim=0)
  25956. tensor([ 6., 8., 10.])
  25957. >>> # Computes the trapezoidal rule for each row of a 3x3 ones matrix
  25958. >>> # with the same arbitrary spacing
  25959. >>> y = torch.ones(3, 3)
  25960. >>> x = torch.tensor([1, 3, 6])
  25961. >>> torch.trapezoid(y, x)
  25962. array([5., 5., 5.])
  25963. >>> # Computes the trapezoidal rule for each row of a 3x3 ones matrix
  25964. >>> # with different arbitrary spacing per row
  25965. >>> y = torch.ones(3, 3)
  25966. >>> x = torch.tensor([[1, 2, 3], [1, 3, 5], [1, 4, 7]])
  25967. >>> torch.trapezoid(y, x)
  25968. array([2., 4., 6.])
  25969. """
  25970. @overload
  25971. def trapz(y: Tensor, *, dx: _float = 1, dim: _int = -1) -> Tensor:
  25972. r"""
  25973. trapz(y, x, *, dim=-1) -> Tensor
  25974. Alias for :func:`torch.trapezoid`.
  25975. """
  25976. @overload
  25977. def trapz(y: Tensor, x: Tensor, *, dim: _int = -1) -> Tensor:
  25978. r"""
  25979. trapz(y, x, *, dim=-1) -> Tensor
  25980. Alias for :func:`torch.trapezoid`.
  25981. """
  25982. def triangular_solve(
  25983. input: Tensor,
  25984. A: Tensor,
  25985. upper: _bool = True,
  25986. transpose: _bool = False,
  25987. unitriangular: _bool = False,
  25988. *,
  25989. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  25990. ) -> torch.return_types.triangular_solve:
  25991. r"""
  25992. triangular_solve(b, A, upper=True, transpose=False, unitriangular=False, *, out=None) -> (Tensor, Tensor)
  25993. Solves a system of equations with a square upper or lower triangular invertible matrix :math:`A`
  25994. and multiple right-hand sides :math:`b`.
  25995. In symbols, it solves :math:`AX = b` and assumes :math:`A` is square upper-triangular
  25996. (or lower-triangular if :attr:`upper`\ `= False`) and does not have zeros on the diagonal.
  25997. `torch.triangular_solve(b, A)` can take in 2D inputs `b, A` or inputs that are
  25998. batches of 2D matrices. If the inputs are batches, then returns
  25999. batched outputs `X`
  26000. If the diagonal of :attr:`A` contains zeros or elements that are very close to zero and
  26001. :attr:`unitriangular`\ `= False` (default) or if the input matrix is badly conditioned,
  26002. the result may contain `NaN` s.
  26003. Supports input of float, double, cfloat and cdouble data types.
  26004. .. warning::
  26005. :func:`torch.triangular_solve` is deprecated in favor of :func:`torch.linalg.solve_triangular`
  26006. and will be removed in a future PyTorch release.
  26007. :func:`torch.linalg.solve_triangular` has its arguments reversed and does not return a
  26008. copy of one of the inputs.
  26009. ``X = torch.triangular_solve(B, A).solution`` should be replaced with
  26010. .. code:: python
  26011. X = torch.linalg.solve_triangular(A, B)
  26012. Args:
  26013. b (Tensor): multiple right-hand sides of size :math:`(*, m, k)` where
  26014. :math:`*` is zero of more batch dimensions
  26015. A (Tensor): the input triangular coefficient matrix of size :math:`(*, m, m)`
  26016. where :math:`*` is zero or more batch dimensions
  26017. upper (bool, optional): whether :math:`A` is upper or lower triangular. Default: ``True``.
  26018. transpose (bool, optional): solves `op(A)X = b` where `op(A) = A^T` if this flag is ``True``,
  26019. and `op(A) = A` if it is ``False``. Default: ``False``.
  26020. unitriangular (bool, optional): whether :math:`A` is unit triangular.
  26021. If True, the diagonal elements of :math:`A` are assumed to be
  26022. 1 and not referenced from :math:`A`. Default: ``False``.
  26023. Keyword args:
  26024. out ((Tensor, Tensor), optional): tuple of two tensors to write
  26025. the output to. Ignored if `None`. Default: `None`.
  26026. Returns:
  26027. A namedtuple `(solution, cloned_coefficient)` where `cloned_coefficient`
  26028. is a clone of :math:`A` and `solution` is the solution :math:`X` to :math:`AX = b`
  26029. (or whatever variant of the system of equations, depending on the keyword arguments.)
  26030. Examples::
  26031. >>> A = torch.randn(2, 2).triu()
  26032. >>> A
  26033. tensor([[ 1.1527, -1.0753],
  26034. [ 0.0000, 0.7986]])
  26035. >>> b = torch.randn(2, 3)
  26036. >>> b
  26037. tensor([[-0.0210, 2.3513, -1.5492],
  26038. [ 1.5429, 0.7403, -1.0243]])
  26039. >>> torch.triangular_solve(b, A)
  26040. torch.return_types.triangular_solve(
  26041. solution=tensor([[ 1.7841, 2.9046, -2.5405],
  26042. [ 1.9320, 0.9270, -1.2826]]),
  26043. cloned_coefficient=tensor([[ 1.1527, -1.0753],
  26044. [ 0.0000, 0.7986]]))
  26045. """
  26046. def tril(
  26047. input: Tensor,
  26048. diagonal: _int | SymInt = 0,
  26049. *,
  26050. out: Tensor | None = None,
  26051. ) -> Tensor:
  26052. r"""
  26053. tril(input, diagonal=0, *, out=None) -> Tensor
  26054. Returns the lower triangular part of the matrix (2-D tensor) or batch of matrices
  26055. :attr:`input`, the other elements of the result tensor :attr:`out` are set to 0.
  26056. The lower triangular part of the matrix is defined as the elements on and
  26057. below the diagonal.
  26058. The argument :attr:`diagonal` controls which diagonal to consider. If
  26059. :attr:`diagonal` = 0, all elements on and below the main diagonal are
  26060. retained. A positive value includes just as many diagonals above the main
  26061. diagonal, and similarly a negative value excludes just as many diagonals below
  26062. the main diagonal. The main diagonal are the set of indices
  26063. :math:`\lbrace (i, i) \rbrace` for :math:`i \in [0, \min\{d_{1}, d_{2}\} - 1]` where
  26064. :math:`d_{1}, d_{2}` are the dimensions of the matrix.
  26065. Args:
  26066. input (Tensor): the input tensor.
  26067. diagonal (int, optional): the diagonal to consider
  26068. Keyword args:
  26069. out (Tensor, optional): the output tensor.
  26070. Example::
  26071. >>> a = torch.randn(3, 3)
  26072. >>> a
  26073. tensor([[-1.0813, -0.8619, 0.7105],
  26074. [ 0.0935, 0.1380, 2.2112],
  26075. [-0.3409, -0.9828, 0.0289]])
  26076. >>> torch.tril(a)
  26077. tensor([[-1.0813, 0.0000, 0.0000],
  26078. [ 0.0935, 0.1380, 0.0000],
  26079. [-0.3409, -0.9828, 0.0289]])
  26080. >>> b = torch.randn(4, 6)
  26081. >>> b
  26082. tensor([[ 1.2219, 0.5653, -0.2521, -0.2345, 1.2544, 0.3461],
  26083. [ 0.4785, -0.4477, 0.6049, 0.6368, 0.8775, 0.7145],
  26084. [ 1.1502, 3.2716, -1.1243, -0.5413, 0.3615, 0.6864],
  26085. [-0.0614, -0.7344, -1.3164, -0.7648, -1.4024, 0.0978]])
  26086. >>> torch.tril(b, diagonal=1)
  26087. tensor([[ 1.2219, 0.5653, 0.0000, 0.0000, 0.0000, 0.0000],
  26088. [ 0.4785, -0.4477, 0.6049, 0.0000, 0.0000, 0.0000],
  26089. [ 1.1502, 3.2716, -1.1243, -0.5413, 0.0000, 0.0000],
  26090. [-0.0614, -0.7344, -1.3164, -0.7648, -1.4024, 0.0000]])
  26091. >>> torch.tril(b, diagonal=-1)
  26092. tensor([[ 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
  26093. [ 0.4785, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
  26094. [ 1.1502, 3.2716, 0.0000, 0.0000, 0.0000, 0.0000],
  26095. [-0.0614, -0.7344, -1.3164, 0.0000, 0.0000, 0.0000]])
  26096. """
  26097. def tril_indices(
  26098. row: _int,
  26099. col: _int,
  26100. offset: _int = 0,
  26101. *,
  26102. dtype: _dtype | None = None,
  26103. layout: _layout | None = None,
  26104. device: DeviceLikeType | None = None,
  26105. pin_memory: _bool | None = False,
  26106. requires_grad: _bool | None = False,
  26107. ) -> Tensor:
  26108. r"""
  26109. tril_indices(row, col, offset=0, *, dtype=torch.long, device='cpu', layout=torch.strided) -> Tensor
  26110. Returns the indices of the lower triangular part of a :attr:`row`-by-
  26111. :attr:`col` matrix in a 2-by-N Tensor, where the first row contains row
  26112. coordinates of all indices and the second row contains column coordinates.
  26113. Indices are ordered based on rows and then columns.
  26114. The lower triangular part of the matrix is defined as the elements on and
  26115. below the diagonal.
  26116. The argument :attr:`offset` controls which diagonal to consider. If
  26117. :attr:`offset` = 0, all elements on and below the main diagonal are
  26118. retained. A positive value includes just as many diagonals above the main
  26119. diagonal, and similarly a negative value excludes just as many diagonals below
  26120. the main diagonal. The main diagonal are the set of indices
  26121. :math:`\lbrace (i, i) \rbrace` for :math:`i \in [0, \min\{d_{1}, d_{2}\} - 1]`
  26122. where :math:`d_{1}, d_{2}` are the dimensions of the matrix.
  26123. .. note::
  26124. When running on CUDA, ``row * col`` must be less than :math:`2^{59}` to
  26125. prevent overflow during calculation.
  26126. Args:
  26127. row (``int``): number of rows in the 2-D matrix.
  26128. col (``int``): number of columns in the 2-D matrix.
  26129. offset (``int``): diagonal offset from the main diagonal.
  26130. Default: if not provided, 0.
  26131. Keyword args:
  26132. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor,
  26133. only support ``torch.int``, ``torch.long``. Default: if ``None``, ``torch.long``.
  26134. device (:class:`torch.device`, optional): the desired device of returned tensor.
  26135. Default: if ``None``, uses the current device for the default tensor type
  26136. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  26137. for CPU tensor types and the current CUDA device for CUDA tensor types.
  26138. layout (:class:`torch.layout`, optional): currently only support ``torch.strided``.
  26139. Example::
  26140. >>> a = torch.tril_indices(3, 3)
  26141. >>> a
  26142. tensor([[0, 1, 1, 2, 2, 2],
  26143. [0, 0, 1, 0, 1, 2]])
  26144. >>> a = torch.tril_indices(4, 3, -1)
  26145. >>> a
  26146. tensor([[1, 2, 2, 3, 3, 3],
  26147. [0, 0, 1, 0, 1, 2]])
  26148. >>> a = torch.tril_indices(4, 3, 1)
  26149. >>> a
  26150. tensor([[0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3],
  26151. [0, 1, 0, 1, 2, 0, 1, 2, 0, 1, 2]])
  26152. """
  26153. def triplet_margin_loss(
  26154. anchor: Tensor,
  26155. positive: Tensor,
  26156. negative: Tensor,
  26157. margin: _float = 1.0,
  26158. p: _float = 2,
  26159. eps: _float = 1e-06,
  26160. swap: _bool = False,
  26161. reduction: _int = 1,
  26162. ) -> Tensor: ...
  26163. def triu(
  26164. input: Tensor,
  26165. diagonal: _int | SymInt = 0,
  26166. *,
  26167. out: Tensor | None = None,
  26168. ) -> Tensor:
  26169. r"""
  26170. triu(input, diagonal=0, *, out=None) -> Tensor
  26171. Returns the upper triangular part of a matrix (2-D tensor) or batch of matrices
  26172. :attr:`input`, the other elements of the result tensor :attr:`out` are set to 0.
  26173. The upper triangular part of the matrix is defined as the elements on and
  26174. above the diagonal.
  26175. The argument :attr:`diagonal` controls which diagonal to consider. If
  26176. :attr:`diagonal` = 0, all elements on and above the main diagonal are
  26177. retained. A positive value excludes just as many diagonals above the main
  26178. diagonal, and similarly a negative value includes just as many diagonals below
  26179. the main diagonal. The main diagonal are the set of indices
  26180. :math:`\lbrace (i, i) \rbrace` for :math:`i \in [0, \min\{d_{1}, d_{2}\} - 1]` where
  26181. :math:`d_{1}, d_{2}` are the dimensions of the matrix.
  26182. Args:
  26183. input (Tensor): the input tensor.
  26184. diagonal (int, optional): the diagonal to consider
  26185. Keyword args:
  26186. out (Tensor, optional): the output tensor.
  26187. Example::
  26188. >>> a = torch.randn(3, 3)
  26189. >>> a
  26190. tensor([[ 0.2309, 0.5207, 2.0049],
  26191. [ 0.2072, -1.0680, 0.6602],
  26192. [ 0.3480, -0.5211, -0.4573]])
  26193. >>> torch.triu(a)
  26194. tensor([[ 0.2309, 0.5207, 2.0049],
  26195. [ 0.0000, -1.0680, 0.6602],
  26196. [ 0.0000, 0.0000, -0.4573]])
  26197. >>> torch.triu(a, diagonal=1)
  26198. tensor([[ 0.0000, 0.5207, 2.0049],
  26199. [ 0.0000, 0.0000, 0.6602],
  26200. [ 0.0000, 0.0000, 0.0000]])
  26201. >>> torch.triu(a, diagonal=-1)
  26202. tensor([[ 0.2309, 0.5207, 2.0049],
  26203. [ 0.2072, -1.0680, 0.6602],
  26204. [ 0.0000, -0.5211, -0.4573]])
  26205. >>> b = torch.randn(4, 6)
  26206. >>> b
  26207. tensor([[ 0.5876, -0.0794, -1.8373, 0.6654, 0.2604, 1.5235],
  26208. [-0.2447, 0.9556, -1.2919, 1.3378, -0.1768, -1.0857],
  26209. [ 0.4333, 0.3146, 0.6576, -1.0432, 0.9348, -0.4410],
  26210. [-0.9888, 1.0679, -1.3337, -1.6556, 0.4798, 0.2830]])
  26211. >>> torch.triu(b, diagonal=1)
  26212. tensor([[ 0.0000, -0.0794, -1.8373, 0.6654, 0.2604, 1.5235],
  26213. [ 0.0000, 0.0000, -1.2919, 1.3378, -0.1768, -1.0857],
  26214. [ 0.0000, 0.0000, 0.0000, -1.0432, 0.9348, -0.4410],
  26215. [ 0.0000, 0.0000, 0.0000, 0.0000, 0.4798, 0.2830]])
  26216. >>> torch.triu(b, diagonal=-1)
  26217. tensor([[ 0.5876, -0.0794, -1.8373, 0.6654, 0.2604, 1.5235],
  26218. [-0.2447, 0.9556, -1.2919, 1.3378, -0.1768, -1.0857],
  26219. [ 0.0000, 0.3146, 0.6576, -1.0432, 0.9348, -0.4410],
  26220. [ 0.0000, 0.0000, -1.3337, -1.6556, 0.4798, 0.2830]])
  26221. """
  26222. def triu_indices(
  26223. row: _int,
  26224. col: _int,
  26225. offset: _int = 0,
  26226. *,
  26227. dtype: _dtype | None = None,
  26228. layout: _layout | None = None,
  26229. device: DeviceLikeType | None = None,
  26230. pin_memory: _bool | None = False,
  26231. requires_grad: _bool | None = False,
  26232. ) -> Tensor:
  26233. r"""
  26234. triu_indices(row, col, offset=0, *, dtype=torch.long, device='cpu', layout=torch.strided) -> Tensor
  26235. Returns the indices of the upper triangular part of a :attr:`row` by
  26236. :attr:`col` matrix in a 2-by-N Tensor, where the first row contains row
  26237. coordinates of all indices and the second row contains column coordinates.
  26238. Indices are ordered based on rows and then columns.
  26239. The upper triangular part of the matrix is defined as the elements on and
  26240. above the diagonal.
  26241. The argument :attr:`offset` controls which diagonal to consider. If
  26242. :attr:`offset` = 0, all elements on and above the main diagonal are
  26243. retained. A positive value excludes just as many diagonals above the main
  26244. diagonal, and similarly a negative value includes just as many diagonals below
  26245. the main diagonal. The main diagonal are the set of indices
  26246. :math:`\lbrace (i, i) \rbrace` for :math:`i \in [0, \min\{d_{1}, d_{2}\} - 1]`
  26247. where :math:`d_{1}, d_{2}` are the dimensions of the matrix.
  26248. .. note::
  26249. When running on CUDA, ``row * col`` must be less than :math:`2^{59}` to
  26250. prevent overflow during calculation.
  26251. Args:
  26252. row (``int``): number of rows in the 2-D matrix.
  26253. col (``int``): number of columns in the 2-D matrix.
  26254. offset (``int``): diagonal offset from the main diagonal.
  26255. Default: if not provided, 0.
  26256. Keyword args:
  26257. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor,
  26258. only support ``torch.int``, ``torch.long``. Default: if ``None``, ``torch.long``.
  26259. device (:class:`torch.device`, optional): the desired device of returned tensor.
  26260. Default: if ``None``, uses the current device for the default tensor type
  26261. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  26262. for CPU tensor types and the current CUDA device for CUDA tensor types.
  26263. layout (:class:`torch.layout`, optional): currently only support ``torch.strided``.
  26264. Example::
  26265. >>> a = torch.triu_indices(3, 3)
  26266. >>> a
  26267. tensor([[0, 0, 0, 1, 1, 2],
  26268. [0, 1, 2, 1, 2, 2]])
  26269. >>> a = torch.triu_indices(4, 3, -1)
  26270. >>> a
  26271. tensor([[0, 0, 0, 1, 1, 1, 2, 2, 3],
  26272. [0, 1, 2, 0, 1, 2, 1, 2, 2]])
  26273. >>> a = torch.triu_indices(4, 3, 1)
  26274. >>> a
  26275. tensor([[0, 0, 1],
  26276. [1, 2, 2]])
  26277. """
  26278. def true_divide(
  26279. input: Tensor | Number,
  26280. other: Tensor | Number,
  26281. *,
  26282. out: Tensor | None = None,
  26283. ) -> Tensor:
  26284. r"""
  26285. true_divide(dividend, divisor, *, out) -> Tensor
  26286. Alias for :func:`torch.div` with ``rounding_mode=None``.
  26287. """
  26288. def trunc(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  26289. r"""
  26290. trunc(input, *, out=None) -> Tensor
  26291. Returns a new tensor with the truncated integer values of
  26292. the elements of :attr:`input`.
  26293. For integer inputs, follows the array-api convention of returning a
  26294. copy of the input tensor.
  26295. Args:
  26296. input (Tensor): the input tensor.
  26297. Keyword args:
  26298. out (Tensor, optional): the output tensor.
  26299. Example::
  26300. >>> a = torch.randn(4)
  26301. >>> a
  26302. tensor([ 3.4742, 0.5466, -0.8008, -0.9079])
  26303. >>> torch.trunc(a)
  26304. tensor([ 3., 0., -0., -0.])
  26305. """
  26306. def trunc_(input: Tensor) -> Tensor: ...
  26307. @overload
  26308. def unbind(input: Tensor, dim: _int = 0) -> tuple[Tensor, ...]:
  26309. r"""
  26310. unbind(input, dim=0) -> seq
  26311. Removes a tensor dimension.
  26312. Returns a tuple of all slices along a given dimension, already without it.
  26313. Arguments:
  26314. input (Tensor): the tensor to unbind
  26315. dim (int): dimension to remove
  26316. Example::
  26317. >>> torch.unbind(torch.tensor([[1, 2, 3],
  26318. >>> [4, 5, 6],
  26319. >>> [7, 8, 9]]))
  26320. (tensor([1, 2, 3]), tensor([4, 5, 6]), tensor([7, 8, 9]))
  26321. """
  26322. @overload
  26323. def unbind(
  26324. input: Tensor,
  26325. dim: str | EllipsisType | None,
  26326. ) -> tuple[Tensor, ...]:
  26327. r"""
  26328. unbind(input, dim=0) -> seq
  26329. Removes a tensor dimension.
  26330. Returns a tuple of all slices along a given dimension, already without it.
  26331. Arguments:
  26332. input (Tensor): the tensor to unbind
  26333. dim (int): dimension to remove
  26334. Example::
  26335. >>> torch.unbind(torch.tensor([[1, 2, 3],
  26336. >>> [4, 5, 6],
  26337. >>> [7, 8, 9]]))
  26338. (tensor([1, 2, 3]), tensor([4, 5, 6]), tensor([7, 8, 9]))
  26339. """
  26340. def unbind_copy(
  26341. input: Tensor,
  26342. dim: _int = 0,
  26343. *,
  26344. out: tuple[Tensor, ...] | list[Tensor] | None = None,
  26345. ) -> None:
  26346. r"""
  26347. Performs the same operation as :func:`torch.unbind`, but all output tensors
  26348. are freshly created instead of aliasing the input.
  26349. """
  26350. @overload
  26351. def unflatten(
  26352. input: Tensor,
  26353. dim: str | EllipsisType | None,
  26354. sizes: Sequence[_int | SymInt],
  26355. names: Sequence[str | EllipsisType | None],
  26356. ) -> Tensor:
  26357. r"""
  26358. unflatten(input, dim, sizes) -> Tensor
  26359. Expands a dimension of the input tensor over multiple dimensions.
  26360. .. seealso::
  26361. :func:`torch.flatten` the inverse of this function. It coalesces several dimensions into one.
  26362. Args:
  26363. input (Tensor): the input tensor.
  26364. dim (int): Dimension to be unflattened, specified as an index into
  26365. ``input.shape``.
  26366. sizes (Tuple[int]): New shape of the unflattened dimension.
  26367. One of its elements can be `-1` in which case the corresponding output
  26368. dimension is inferred. Otherwise, the product of ``sizes`` *must*
  26369. equal ``input.shape[dim]``.
  26370. Returns:
  26371. A View of input with the specified dimension unflattened.
  26372. Examples::
  26373. >>> torch.unflatten(torch.randn(3, 4, 1), 1, (2, 2)).shape
  26374. torch.Size([3, 2, 2, 1])
  26375. >>> torch.unflatten(torch.randn(3, 4, 1), 1, (-1, 2)).shape
  26376. torch.Size([3, 2, 2, 1])
  26377. >>> torch.unflatten(torch.randn(5, 12, 3), -2, (2, 2, 3, 1, 1)).shape
  26378. torch.Size([5, 2, 2, 3, 1, 1, 3])
  26379. """
  26380. @overload
  26381. def unflatten(
  26382. input: Tensor,
  26383. dim: _int,
  26384. sizes: Sequence[_int | SymInt],
  26385. ) -> Tensor:
  26386. r"""
  26387. unflatten(input, dim, sizes) -> Tensor
  26388. Expands a dimension of the input tensor over multiple dimensions.
  26389. .. seealso::
  26390. :func:`torch.flatten` the inverse of this function. It coalesces several dimensions into one.
  26391. Args:
  26392. input (Tensor): the input tensor.
  26393. dim (int): Dimension to be unflattened, specified as an index into
  26394. ``input.shape``.
  26395. sizes (Tuple[int]): New shape of the unflattened dimension.
  26396. One of its elements can be `-1` in which case the corresponding output
  26397. dimension is inferred. Otherwise, the product of ``sizes`` *must*
  26398. equal ``input.shape[dim]``.
  26399. Returns:
  26400. A View of input with the specified dimension unflattened.
  26401. Examples::
  26402. >>> torch.unflatten(torch.randn(3, 4, 1), 1, (2, 2)).shape
  26403. torch.Size([3, 2, 2, 1])
  26404. >>> torch.unflatten(torch.randn(3, 4, 1), 1, (-1, 2)).shape
  26405. torch.Size([3, 2, 2, 1])
  26406. >>> torch.unflatten(torch.randn(5, 12, 3), -2, (2, 2, 3, 1, 1)).shape
  26407. torch.Size([5, 2, 2, 3, 1, 1, 3])
  26408. """
  26409. def unfold_copy(
  26410. input: Tensor,
  26411. dimension: _int,
  26412. size: _int,
  26413. step: _int,
  26414. *,
  26415. out: Tensor | None = None,
  26416. ) -> Tensor:
  26417. r"""
  26418. Performs the same operation as :func:`torch.unfold`, but all output tensors
  26419. are freshly created instead of aliasing the input.
  26420. """
  26421. def unique_dim(
  26422. input: Tensor,
  26423. dim: _int,
  26424. sorted: _bool = True,
  26425. return_inverse: _bool = False,
  26426. return_counts: _bool = False,
  26427. ) -> tuple[Tensor, Tensor, Tensor]: ...
  26428. def unsafe_chunk(
  26429. input: Tensor,
  26430. chunks: _int,
  26431. dim: _int = 0,
  26432. ) -> tuple[Tensor, ...]:
  26433. r"""
  26434. unsafe_chunk(input, chunks, dim=0) -> List of Tensors
  26435. Works like :func:`torch.chunk` but without enforcing the autograd restrictions
  26436. on inplace modification of the outputs.
  26437. .. warning::
  26438. This function is safe to use as long as only the input, or only the outputs
  26439. are modified inplace after calling this function. It is user's
  26440. responsibility to ensure that is the case. If both the input and one or more
  26441. of the outputs are modified inplace, gradients computed by autograd will be
  26442. silently incorrect.
  26443. """
  26444. def unsafe_split(
  26445. input: Tensor,
  26446. split_size: _int | SymInt,
  26447. dim: _int = 0,
  26448. ) -> tuple[Tensor, ...]:
  26449. r"""
  26450. unsafe_split(tensor, split_size_or_sections, dim=0) -> List of Tensors
  26451. Works like :func:`torch.split` but without enforcing the autograd restrictions
  26452. on inplace modification of the outputs.
  26453. .. warning::
  26454. This function is safe to use as long as only the input, or only the outputs
  26455. are modified inplace after calling this function. It is user's
  26456. responsibility to ensure that is the case. If both the input and one or more
  26457. of the outputs are modified inplace, gradients computed by autograd will be
  26458. silently incorrect.
  26459. """
  26460. def unsafe_split_with_sizes(
  26461. input: Tensor,
  26462. split_sizes: Sequence[_int | SymInt],
  26463. dim: _int = 0,
  26464. ) -> tuple[Tensor, ...]: ...
  26465. def unsqueeze(input: Tensor, dim: _int) -> Tensor:
  26466. r"""
  26467. unsqueeze(input, dim) -> Tensor
  26468. Returns a new tensor with a dimension of size one inserted at the
  26469. specified position.
  26470. The returned tensor shares the same underlying data with this tensor.
  26471. A :attr:`dim` value within the range ``[-input.dim() - 1, input.dim() + 1)``
  26472. can be used. Negative :attr:`dim` will correspond to :meth:`unsqueeze`
  26473. applied at :attr:`dim` = ``dim + input.dim() + 1``.
  26474. Args:
  26475. input (Tensor): the input tensor.
  26476. dim (int): the index at which to insert the singleton dimension
  26477. Example::
  26478. >>> x = torch.tensor([1, 2, 3, 4])
  26479. >>> torch.unsqueeze(x, 0)
  26480. tensor([[ 1, 2, 3, 4]])
  26481. >>> torch.unsqueeze(x, 1)
  26482. tensor([[ 1],
  26483. [ 2],
  26484. [ 3],
  26485. [ 4]])
  26486. """
  26487. def unsqueeze_copy(
  26488. input: Tensor,
  26489. dim: _int,
  26490. *,
  26491. out: Tensor | None = None,
  26492. ) -> Tensor:
  26493. r"""
  26494. Performs the same operation as :func:`torch.unsqueeze`, but all output tensors
  26495. are freshly created instead of aliasing the input.
  26496. """
  26497. def values_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  26498. r"""
  26499. Performs the same operation as :func:`torch.values`, but all output tensors
  26500. are freshly created instead of aliasing the input.
  26501. """
  26502. def vander(
  26503. x: Tensor,
  26504. N: _int | None = None,
  26505. increasing: _bool = False,
  26506. ) -> Tensor:
  26507. r"""
  26508. vander(x, N=None, increasing=False) -> Tensor
  26509. Generates a Vandermonde matrix.
  26510. The columns of the output matrix are elementwise powers of the input vector :math:`x^{(N-1)}, x^{(N-2)}, ..., x^0`.
  26511. If increasing is True, the order of the columns is reversed :math:`x^0, x^1, ..., x^{(N-1)}`. Such a
  26512. matrix with a geometric progression in each row is named for Alexandre-Theophile Vandermonde.
  26513. Arguments:
  26514. x (Tensor): 1-D input tensor.
  26515. N (int, optional): Number of columns in the output. If N is not specified,
  26516. a square array is returned :math:`(N = len(x))`.
  26517. increasing (bool, optional): Order of the powers of the columns. If True,
  26518. the powers increase from left to right, if False (the default) they are reversed.
  26519. Returns:
  26520. Tensor: Vandermonde matrix. If increasing is False, the first column is :math:`x^{(N-1)}`,
  26521. the second :math:`x^{(N-2)}` and so forth. If increasing is True, the columns
  26522. are :math:`x^0, x^1, ..., x^{(N-1)}`.
  26523. Example::
  26524. >>> x = torch.tensor([1, 2, 3, 5])
  26525. >>> torch.vander(x)
  26526. tensor([[ 1, 1, 1, 1],
  26527. [ 8, 4, 2, 1],
  26528. [ 27, 9, 3, 1],
  26529. [125, 25, 5, 1]])
  26530. >>> torch.vander(x, N=3)
  26531. tensor([[ 1, 1, 1],
  26532. [ 4, 2, 1],
  26533. [ 9, 3, 1],
  26534. [25, 5, 1]])
  26535. >>> torch.vander(x, N=3, increasing=True)
  26536. tensor([[ 1, 1, 1],
  26537. [ 1, 2, 4],
  26538. [ 1, 3, 9],
  26539. [ 1, 5, 25]])
  26540. """
  26541. @overload
  26542. def var(
  26543. input: Tensor,
  26544. dim: _int | _size | None,
  26545. unbiased: _bool = True,
  26546. keepdim: _bool = False,
  26547. *,
  26548. out: Tensor | None = None,
  26549. ) -> Tensor:
  26550. r"""
  26551. var(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  26552. Calculates the variance over the dimensions specified by :attr:`dim`. :attr:`dim`
  26553. can be a single dimension, list of dimensions, or ``None`` to reduce over all
  26554. dimensions.
  26555. The variance (:math:`\sigma^2`) is calculated as
  26556. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26557. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26558. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26559. the :attr:`correction`.
  26560. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26561. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26562. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26563. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26564. Args:
  26565. input (Tensor): the input tensor.
  26566. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26567. If ``None``, all dimensions are reduced.
  26568. Keyword args:
  26569. correction (int): difference between the sample size and sample degrees of freedom.
  26570. Defaults to `Bessel's correction`_, ``correction=1``.
  26571. .. versionchanged:: 2.0
  26572. Previously this argument was called ``unbiased`` and was a boolean
  26573. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26574. ``correction=0``.
  26575. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26576. out (Tensor, optional): the output tensor.
  26577. Example:
  26578. >>> a = torch.tensor(
  26579. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26580. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26581. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26582. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26583. ... ) # fmt: skip
  26584. >>> torch.var(a, dim=1, keepdim=True)
  26585. tensor([[1.0631],
  26586. [0.5590],
  26587. [1.4893],
  26588. [0.8258]])
  26589. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26590. """
  26591. @overload
  26592. def var(
  26593. input: Tensor,
  26594. dim: _int | _size | None = None,
  26595. *,
  26596. correction: Number | _complex | None = None,
  26597. keepdim: _bool = False,
  26598. out: Tensor | None = None,
  26599. ) -> Tensor:
  26600. r"""
  26601. var(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  26602. Calculates the variance over the dimensions specified by :attr:`dim`. :attr:`dim`
  26603. can be a single dimension, list of dimensions, or ``None`` to reduce over all
  26604. dimensions.
  26605. The variance (:math:`\sigma^2`) is calculated as
  26606. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26607. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26608. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26609. the :attr:`correction`.
  26610. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26611. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26612. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26613. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26614. Args:
  26615. input (Tensor): the input tensor.
  26616. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26617. If ``None``, all dimensions are reduced.
  26618. Keyword args:
  26619. correction (int): difference between the sample size and sample degrees of freedom.
  26620. Defaults to `Bessel's correction`_, ``correction=1``.
  26621. .. versionchanged:: 2.0
  26622. Previously this argument was called ``unbiased`` and was a boolean
  26623. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26624. ``correction=0``.
  26625. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26626. out (Tensor, optional): the output tensor.
  26627. Example:
  26628. >>> a = torch.tensor(
  26629. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26630. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26631. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26632. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26633. ... ) # fmt: skip
  26634. >>> torch.var(a, dim=1, keepdim=True)
  26635. tensor([[1.0631],
  26636. [0.5590],
  26637. [1.4893],
  26638. [0.8258]])
  26639. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26640. """
  26641. @overload
  26642. def var(input: Tensor, unbiased: _bool = True) -> Tensor:
  26643. r"""
  26644. var(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  26645. Calculates the variance over the dimensions specified by :attr:`dim`. :attr:`dim`
  26646. can be a single dimension, list of dimensions, or ``None`` to reduce over all
  26647. dimensions.
  26648. The variance (:math:`\sigma^2`) is calculated as
  26649. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26650. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26651. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26652. the :attr:`correction`.
  26653. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26654. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26655. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26656. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26657. Args:
  26658. input (Tensor): the input tensor.
  26659. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26660. If ``None``, all dimensions are reduced.
  26661. Keyword args:
  26662. correction (int): difference between the sample size and sample degrees of freedom.
  26663. Defaults to `Bessel's correction`_, ``correction=1``.
  26664. .. versionchanged:: 2.0
  26665. Previously this argument was called ``unbiased`` and was a boolean
  26666. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26667. ``correction=0``.
  26668. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26669. out (Tensor, optional): the output tensor.
  26670. Example:
  26671. >>> a = torch.tensor(
  26672. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26673. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26674. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26675. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26676. ... ) # fmt: skip
  26677. >>> torch.var(a, dim=1, keepdim=True)
  26678. tensor([[1.0631],
  26679. [0.5590],
  26680. [1.4893],
  26681. [0.8258]])
  26682. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26683. """
  26684. @overload
  26685. def var(
  26686. input: Tensor,
  26687. dim: Sequence[str | EllipsisType | None],
  26688. *,
  26689. correction: Number | _complex | None = None,
  26690. keepdim: _bool = False,
  26691. out: Tensor | None = None,
  26692. ) -> Tensor:
  26693. r"""
  26694. var(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  26695. Calculates the variance over the dimensions specified by :attr:`dim`. :attr:`dim`
  26696. can be a single dimension, list of dimensions, or ``None`` to reduce over all
  26697. dimensions.
  26698. The variance (:math:`\sigma^2`) is calculated as
  26699. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26700. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26701. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26702. the :attr:`correction`.
  26703. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26704. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26705. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26706. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26707. Args:
  26708. input (Tensor): the input tensor.
  26709. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26710. If ``None``, all dimensions are reduced.
  26711. Keyword args:
  26712. correction (int): difference between the sample size and sample degrees of freedom.
  26713. Defaults to `Bessel's correction`_, ``correction=1``.
  26714. .. versionchanged:: 2.0
  26715. Previously this argument was called ``unbiased`` and was a boolean
  26716. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26717. ``correction=0``.
  26718. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26719. out (Tensor, optional): the output tensor.
  26720. Example:
  26721. >>> a = torch.tensor(
  26722. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26723. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26724. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26725. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26726. ... ) # fmt: skip
  26727. >>> torch.var(a, dim=1, keepdim=True)
  26728. tensor([[1.0631],
  26729. [0.5590],
  26730. [1.4893],
  26731. [0.8258]])
  26732. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26733. """
  26734. @overload
  26735. def var(
  26736. input: Tensor,
  26737. dim: Sequence[str | EllipsisType | None],
  26738. unbiased: _bool = True,
  26739. keepdim: _bool = False,
  26740. *,
  26741. out: Tensor | None = None,
  26742. ) -> Tensor:
  26743. r"""
  26744. var(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  26745. Calculates the variance over the dimensions specified by :attr:`dim`. :attr:`dim`
  26746. can be a single dimension, list of dimensions, or ``None`` to reduce over all
  26747. dimensions.
  26748. The variance (:math:`\sigma^2`) is calculated as
  26749. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26750. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26751. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26752. the :attr:`correction`.
  26753. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26754. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26755. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26756. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26757. Args:
  26758. input (Tensor): the input tensor.
  26759. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26760. If ``None``, all dimensions are reduced.
  26761. Keyword args:
  26762. correction (int): difference between the sample size and sample degrees of freedom.
  26763. Defaults to `Bessel's correction`_, ``correction=1``.
  26764. .. versionchanged:: 2.0
  26765. Previously this argument was called ``unbiased`` and was a boolean
  26766. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26767. ``correction=0``.
  26768. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26769. out (Tensor, optional): the output tensor.
  26770. Example:
  26771. >>> a = torch.tensor(
  26772. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26773. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26774. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26775. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26776. ... ) # fmt: skip
  26777. >>> torch.var(a, dim=1, keepdim=True)
  26778. tensor([[1.0631],
  26779. [0.5590],
  26780. [1.4893],
  26781. [0.8258]])
  26782. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26783. """
  26784. @overload
  26785. def var_mean(
  26786. input: Tensor,
  26787. dim: _int | _size | None,
  26788. unbiased: _bool = True,
  26789. keepdim: _bool = False,
  26790. ) -> tuple[Tensor, Tensor]:
  26791. r"""
  26792. var_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  26793. Calculates the variance and mean over the dimensions specified by :attr:`dim`.
  26794. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  26795. reduce over all dimensions.
  26796. The variance (:math:`\sigma^2`) is calculated as
  26797. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26798. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26799. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26800. the :attr:`correction`.
  26801. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26802. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26803. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26804. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26805. Args:
  26806. input (Tensor): the input tensor.
  26807. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26808. If ``None``, all dimensions are reduced.
  26809. Keyword args:
  26810. correction (int): difference between the sample size and sample degrees of freedom.
  26811. Defaults to `Bessel's correction`_, ``correction=1``.
  26812. .. versionchanged:: 2.0
  26813. Previously this argument was called ``unbiased`` and was a boolean
  26814. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26815. ``correction=0``.
  26816. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26817. out (Tensor, optional): the output tensor.
  26818. Returns:
  26819. A tuple (var, mean) containing the variance and mean.
  26820. Example:
  26821. >>> a = torch.tensor(
  26822. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26823. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26824. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26825. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26826. ... ) # fmt: skip
  26827. >>> torch.var_mean(a, dim=0, keepdim=True)
  26828. (tensor([[1.5926, 1.0056, 1.2005, 0.3646]]),
  26829. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  26830. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26831. """
  26832. @overload
  26833. def var_mean(
  26834. input: Tensor,
  26835. dim: _int | _size | None = None,
  26836. *,
  26837. correction: Number | _complex | None = None,
  26838. keepdim: _bool = False,
  26839. ) -> tuple[Tensor, Tensor]:
  26840. r"""
  26841. var_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  26842. Calculates the variance and mean over the dimensions specified by :attr:`dim`.
  26843. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  26844. reduce over all dimensions.
  26845. The variance (:math:`\sigma^2`) is calculated as
  26846. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26847. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26848. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26849. the :attr:`correction`.
  26850. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26851. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26852. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26853. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26854. Args:
  26855. input (Tensor): the input tensor.
  26856. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26857. If ``None``, all dimensions are reduced.
  26858. Keyword args:
  26859. correction (int): difference between the sample size and sample degrees of freedom.
  26860. Defaults to `Bessel's correction`_, ``correction=1``.
  26861. .. versionchanged:: 2.0
  26862. Previously this argument was called ``unbiased`` and was a boolean
  26863. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26864. ``correction=0``.
  26865. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26866. out (Tensor, optional): the output tensor.
  26867. Returns:
  26868. A tuple (var, mean) containing the variance and mean.
  26869. Example:
  26870. >>> a = torch.tensor(
  26871. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26872. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26873. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26874. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26875. ... ) # fmt: skip
  26876. >>> torch.var_mean(a, dim=0, keepdim=True)
  26877. (tensor([[1.5926, 1.0056, 1.2005, 0.3646]]),
  26878. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  26879. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26880. """
  26881. @overload
  26882. def var_mean(
  26883. input: Tensor,
  26884. unbiased: _bool = True,
  26885. ) -> tuple[Tensor, Tensor]:
  26886. r"""
  26887. var_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  26888. Calculates the variance and mean over the dimensions specified by :attr:`dim`.
  26889. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  26890. reduce over all dimensions.
  26891. The variance (:math:`\sigma^2`) is calculated as
  26892. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26893. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26894. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26895. the :attr:`correction`.
  26896. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26897. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26898. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26899. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26900. Args:
  26901. input (Tensor): the input tensor.
  26902. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26903. If ``None``, all dimensions are reduced.
  26904. Keyword args:
  26905. correction (int): difference between the sample size and sample degrees of freedom.
  26906. Defaults to `Bessel's correction`_, ``correction=1``.
  26907. .. versionchanged:: 2.0
  26908. Previously this argument was called ``unbiased`` and was a boolean
  26909. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26910. ``correction=0``.
  26911. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26912. out (Tensor, optional): the output tensor.
  26913. Returns:
  26914. A tuple (var, mean) containing the variance and mean.
  26915. Example:
  26916. >>> a = torch.tensor(
  26917. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26918. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26919. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26920. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26921. ... ) # fmt: skip
  26922. >>> torch.var_mean(a, dim=0, keepdim=True)
  26923. (tensor([[1.5926, 1.0056, 1.2005, 0.3646]]),
  26924. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  26925. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26926. """
  26927. @overload
  26928. def var_mean(
  26929. input: Tensor,
  26930. dim: Sequence[str | EllipsisType | None],
  26931. *,
  26932. correction: Number | _complex | None = None,
  26933. keepdim: _bool = False,
  26934. ) -> tuple[Tensor, Tensor]:
  26935. r"""
  26936. var_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  26937. Calculates the variance and mean over the dimensions specified by :attr:`dim`.
  26938. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  26939. reduce over all dimensions.
  26940. The variance (:math:`\sigma^2`) is calculated as
  26941. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26942. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26943. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26944. the :attr:`correction`.
  26945. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26946. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26947. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26948. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26949. Args:
  26950. input (Tensor): the input tensor.
  26951. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26952. If ``None``, all dimensions are reduced.
  26953. Keyword args:
  26954. correction (int): difference between the sample size and sample degrees of freedom.
  26955. Defaults to `Bessel's correction`_, ``correction=1``.
  26956. .. versionchanged:: 2.0
  26957. Previously this argument was called ``unbiased`` and was a boolean
  26958. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26959. ``correction=0``.
  26960. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26961. out (Tensor, optional): the output tensor.
  26962. Returns:
  26963. A tuple (var, mean) containing the variance and mean.
  26964. Example:
  26965. >>> a = torch.tensor(
  26966. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26967. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26968. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26969. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26970. ... ) # fmt: skip
  26971. >>> torch.var_mean(a, dim=0, keepdim=True)
  26972. (tensor([[1.5926, 1.0056, 1.2005, 0.3646]]),
  26973. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  26974. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26975. """
  26976. @overload
  26977. def var_mean(
  26978. input: Tensor,
  26979. dim: Sequence[str | EllipsisType | None],
  26980. unbiased: _bool = True,
  26981. keepdim: _bool = False,
  26982. ) -> tuple[Tensor, Tensor]:
  26983. r"""
  26984. var_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  26985. Calculates the variance and mean over the dimensions specified by :attr:`dim`.
  26986. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  26987. reduce over all dimensions.
  26988. The variance (:math:`\sigma^2`) is calculated as
  26989. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26990. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26991. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26992. the :attr:`correction`.
  26993. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26994. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26995. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26996. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26997. Args:
  26998. input (Tensor): the input tensor.
  26999. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  27000. If ``None``, all dimensions are reduced.
  27001. Keyword args:
  27002. correction (int): difference between the sample size and sample degrees of freedom.
  27003. Defaults to `Bessel's correction`_, ``correction=1``.
  27004. .. versionchanged:: 2.0
  27005. Previously this argument was called ``unbiased`` and was a boolean
  27006. with ``True`` corresponding to ``correction=1`` and ``False`` being
  27007. ``correction=0``.
  27008. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  27009. out (Tensor, optional): the output tensor.
  27010. Returns:
  27011. A tuple (var, mean) containing the variance and mean.
  27012. Example:
  27013. >>> a = torch.tensor(
  27014. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  27015. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  27016. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  27017. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  27018. ... ) # fmt: skip
  27019. >>> torch.var_mean(a, dim=0, keepdim=True)
  27020. (tensor([[1.5926, 1.0056, 1.2005, 0.3646]]),
  27021. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  27022. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  27023. """
  27024. def vdot(
  27025. input: Tensor,
  27026. other: Tensor,
  27027. *,
  27028. out: Tensor | None = None,
  27029. ) -> Tensor:
  27030. r"""
  27031. vdot(input, other, *, out=None) -> Tensor
  27032. Computes the dot product of two 1D vectors along a dimension.
  27033. In symbols, this function computes
  27034. .. math::
  27035. \sum_{i=1}^n \overline{x_i}y_i.
  27036. where :math:`\overline{x_i}` denotes the conjugate for complex
  27037. vectors, and it is the identity for real vectors.
  27038. .. note::
  27039. Unlike NumPy's vdot, torch.vdot intentionally only supports computing the dot product
  27040. of two 1D tensors with the same number of elements.
  27041. .. seealso::
  27042. :func:`torch.linalg.vecdot` computes the dot product of two batches of vectors along a dimension.
  27043. Args:
  27044. input (Tensor): first tensor in the dot product, must be 1D. Its conjugate is used if it's complex.
  27045. other (Tensor): second tensor in the dot product, must be 1D.
  27046. Keyword args:
  27047. .. note:: out (Tensor, optional): the output tensor.
  27048. Example::
  27049. >>> torch.vdot(torch.tensor([2, 3]), torch.tensor([2, 1]))
  27050. tensor(7)
  27051. >>> a = torch.tensor((1 +2j, 3 - 1j))
  27052. >>> b = torch.tensor((2 +1j, 4 - 0j))
  27053. >>> torch.vdot(a, b)
  27054. tensor([16.+1.j])
  27055. >>> torch.vdot(b, a)
  27056. tensor([16.-1.j])
  27057. """
  27058. def view_as_complex(input: Tensor) -> Tensor:
  27059. r"""
  27060. view_as_complex(input) -> Tensor
  27061. Returns a view of :attr:`input` as a complex tensor. For an input complex
  27062. tensor of :attr:`size` :math:`m1, m2, \dots, mi, 2`, this function returns a
  27063. new complex tensor of :attr:`size` :math:`m1, m2, \dots, mi` where the last
  27064. dimension of the input tensor is expected to represent the real and imaginary
  27065. components of complex numbers.
  27066. .. warning::
  27067. :func:`view_as_complex` is only supported for tensors with
  27068. :class:`torch.dtype` ``torch.float64`` and ``torch.float32``. The input is
  27069. expected to have the last dimension of :attr:`size` 2. In addition, the
  27070. tensor must have a `stride` of 1 for its last dimension. The strides of all
  27071. other dimensions must be even numbers.
  27072. Args:
  27073. input (Tensor): the input tensor.
  27074. Example::
  27075. >>> x=torch.randn(4, 2)
  27076. >>> x
  27077. tensor([[ 1.6116, -0.5772],
  27078. [-1.4606, -0.9120],
  27079. [ 0.0786, -1.7497],
  27080. [-0.6561, -1.6623]])
  27081. >>> torch.view_as_complex(x)
  27082. tensor([(1.6116-0.5772j), (-1.4606-0.9120j), (0.0786-1.7497j), (-0.6561-1.6623j)])
  27083. """
  27084. def view_as_complex_copy(
  27085. input: Tensor,
  27086. *,
  27087. out: Tensor | None = None,
  27088. ) -> Tensor:
  27089. r"""
  27090. Performs the same operation as :func:`torch.view_as_complex`, but all output tensors
  27091. are freshly created instead of aliasing the input.
  27092. """
  27093. def view_as_real(input: Tensor) -> Tensor:
  27094. r"""
  27095. view_as_real(input) -> Tensor
  27096. Returns a view of :attr:`input` as a real tensor. For an input complex tensor of
  27097. :attr:`size` :math:`m1, m2, \dots, mi`, this function returns a new
  27098. real tensor of size :math:`m1, m2, \dots, mi, 2`, where the last dimension of size 2
  27099. represents the real and imaginary components of complex numbers.
  27100. .. warning::
  27101. :func:`view_as_real` is only supported for tensors with ``complex dtypes``.
  27102. Args:
  27103. input (Tensor): the input tensor.
  27104. Example::
  27105. >>> x=torch.randn(4, dtype=torch.cfloat)
  27106. >>> x
  27107. tensor([(0.4737-0.3839j), (-0.2098-0.6699j), (0.3470-0.9451j), (-0.5174-1.3136j)])
  27108. >>> torch.view_as_real(x)
  27109. tensor([[ 0.4737, -0.3839],
  27110. [-0.2098, -0.6699],
  27111. [ 0.3470, -0.9451],
  27112. [-0.5174, -1.3136]])
  27113. """
  27114. def view_as_real_copy(
  27115. input: Tensor,
  27116. *,
  27117. out: Tensor | None = None,
  27118. ) -> Tensor:
  27119. r"""
  27120. Performs the same operation as :func:`torch.view_as_real`, but all output tensors
  27121. are freshly created instead of aliasing the input.
  27122. """
  27123. @overload
  27124. def view_copy(
  27125. input: Tensor,
  27126. dtype: _dtype,
  27127. *,
  27128. out: Tensor | None = None,
  27129. ) -> Tensor:
  27130. r"""
  27131. Performs the same operation as :func:`torch.view`, but all output tensors
  27132. are freshly created instead of aliasing the input.
  27133. """
  27134. @overload
  27135. def view_copy(
  27136. input: Tensor,
  27137. size: Sequence[_int | SymInt],
  27138. *,
  27139. out: Tensor | None = None,
  27140. ) -> Tensor:
  27141. r"""
  27142. Performs the same operation as :func:`torch.view`, but all output tensors
  27143. are freshly created instead of aliasing the input.
  27144. """
  27145. @overload
  27146. def vsplit(input: Tensor, sections: _int) -> tuple[Tensor, ...]:
  27147. r"""
  27148. vsplit(input, indices_or_sections) -> List of Tensors
  27149. Splits :attr:`input`, a tensor with two or more dimensions, into multiple tensors
  27150. vertically according to :attr:`indices_or_sections`. Each split is a view of
  27151. :attr:`input`.
  27152. This is equivalent to calling torch.tensor_split(input, indices_or_sections, dim=0)
  27153. (the split dimension is 0), except that if :attr:`indices_or_sections` is an integer
  27154. it must evenly divide the split dimension or a runtime error will be thrown.
  27155. This function is based on NumPy's :func:`numpy.vsplit`.
  27156. Args:
  27157. input (Tensor): tensor to split.
  27158. indices_or_sections (int or list or tuple of ints): See argument in :func:`torch.tensor_split`.
  27159. Example::
  27160. >>> t = torch.arange(16.0).reshape(4,4)
  27161. >>> t
  27162. tensor([[ 0., 1., 2., 3.],
  27163. [ 4., 5., 6., 7.],
  27164. [ 8., 9., 10., 11.],
  27165. [12., 13., 14., 15.]])
  27166. >>> torch.vsplit(t, 2)
  27167. (tensor([[0., 1., 2., 3.],
  27168. [4., 5., 6., 7.]]),
  27169. tensor([[ 8., 9., 10., 11.],
  27170. [12., 13., 14., 15.]]))
  27171. >>> torch.vsplit(t, [3, 6])
  27172. (tensor([[ 0., 1., 2., 3.],
  27173. [ 4., 5., 6., 7.],
  27174. [ 8., 9., 10., 11.]]),
  27175. tensor([[12., 13., 14., 15.]]),
  27176. tensor([], size=(0, 4)))
  27177. """
  27178. @overload
  27179. def vsplit(input: Tensor, indices: _size) -> tuple[Tensor, ...]:
  27180. r"""
  27181. vsplit(input, indices_or_sections) -> List of Tensors
  27182. Splits :attr:`input`, a tensor with two or more dimensions, into multiple tensors
  27183. vertically according to :attr:`indices_or_sections`. Each split is a view of
  27184. :attr:`input`.
  27185. This is equivalent to calling torch.tensor_split(input, indices_or_sections, dim=0)
  27186. (the split dimension is 0), except that if :attr:`indices_or_sections` is an integer
  27187. it must evenly divide the split dimension or a runtime error will be thrown.
  27188. This function is based on NumPy's :func:`numpy.vsplit`.
  27189. Args:
  27190. input (Tensor): tensor to split.
  27191. indices_or_sections (int or list or tuple of ints): See argument in :func:`torch.tensor_split`.
  27192. Example::
  27193. >>> t = torch.arange(16.0).reshape(4,4)
  27194. >>> t
  27195. tensor([[ 0., 1., 2., 3.],
  27196. [ 4., 5., 6., 7.],
  27197. [ 8., 9., 10., 11.],
  27198. [12., 13., 14., 15.]])
  27199. >>> torch.vsplit(t, 2)
  27200. (tensor([[0., 1., 2., 3.],
  27201. [4., 5., 6., 7.]]),
  27202. tensor([[ 8., 9., 10., 11.],
  27203. [12., 13., 14., 15.]]))
  27204. >>> torch.vsplit(t, [3, 6])
  27205. (tensor([[ 0., 1., 2., 3.],
  27206. [ 4., 5., 6., 7.],
  27207. [ 8., 9., 10., 11.]]),
  27208. tensor([[12., 13., 14., 15.]]),
  27209. tensor([], size=(0, 4)))
  27210. """
  27211. def vstack(
  27212. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  27213. *,
  27214. out: Tensor | None = None,
  27215. ) -> Tensor:
  27216. r"""
  27217. vstack(tensors, *, out=None) -> Tensor
  27218. Stack tensors in sequence vertically (row wise).
  27219. This is equivalent to concatenation along the first axis after all 1-D tensors have been reshaped by :func:`torch.atleast_2d`.
  27220. Args:
  27221. tensors (sequence of Tensors): sequence of tensors to concatenate
  27222. Keyword args:
  27223. out (Tensor, optional): the output tensor.
  27224. Example::
  27225. >>> a = torch.tensor([1, 2, 3])
  27226. >>> b = torch.tensor([4, 5, 6])
  27227. >>> torch.vstack((a,b))
  27228. tensor([[1, 2, 3],
  27229. [4, 5, 6]])
  27230. >>> a = torch.tensor([[1],[2],[3]])
  27231. >>> b = torch.tensor([[4],[5],[6]])
  27232. >>> torch.vstack((a,b))
  27233. tensor([[1],
  27234. [2],
  27235. [3],
  27236. [4],
  27237. [5],
  27238. [6]])
  27239. """
  27240. @overload
  27241. def where(condition: Tensor) -> tuple[Tensor, ...]:
  27242. r"""
  27243. where(condition, input, other, *, out=None) -> Tensor
  27244. Return a tensor of elements selected from either :attr:`input` or :attr:`other`, depending on :attr:`condition`.
  27245. The operation is defined as:
  27246. .. math::
  27247. \text{out}_i = \begin{cases}
  27248. \text{input}_i & \text{if } \text{condition}_i \\
  27249. \text{other}_i & \text{otherwise} \\
  27250. \end{cases}
  27251. .. note::
  27252. The tensors :attr:`condition`, :attr:`input`, :attr:`other` must be :ref:`broadcastable <broadcasting-semantics>`.
  27253. Arguments:
  27254. condition (BoolTensor): When True (nonzero), yield input, otherwise yield other
  27255. input (Tensor or Scalar): value (if :attr:`input` is a scalar) or values selected at indices
  27256. where :attr:`condition` is ``True``
  27257. other (Tensor or Scalar): value (if :attr:`other` is a scalar) or values selected at indices
  27258. where :attr:`condition` is ``False``
  27259. Keyword args:
  27260. out (Tensor, optional): the output tensor.
  27261. Returns:
  27262. Tensor: A tensor of shape equal to the broadcasted shape of :attr:`condition`, :attr:`input`, :attr:`other`
  27263. Example::
  27264. >>> x = torch.randn(3, 2)
  27265. >>> y = torch.ones(3, 2)
  27266. >>> x
  27267. tensor([[-0.4620, 0.3139],
  27268. [ 0.3898, -0.7197],
  27269. [ 0.0478, -0.1657]])
  27270. >>> torch.where(x > 0, 1.0, 0.0)
  27271. tensor([[0., 1.],
  27272. [1., 0.],
  27273. [1., 0.]])
  27274. >>> torch.where(x > 0, x, y)
  27275. tensor([[ 1.0000, 0.3139],
  27276. [ 0.3898, 1.0000],
  27277. [ 0.0478, 1.0000]])
  27278. >>> x = torch.randn(2, 2, dtype=torch.double)
  27279. >>> x
  27280. tensor([[ 1.0779, 0.0383],
  27281. [-0.8785, -1.1089]], dtype=torch.float64)
  27282. >>> torch.where(x > 0, x, 0.)
  27283. tensor([[1.0779, 0.0383],
  27284. [0.0000, 0.0000]], dtype=torch.float64)
  27285. .. function:: where(condition) -> tuple of LongTensor
  27286. :noindex:
  27287. ``torch.where(condition)`` is identical to
  27288. ``torch.nonzero(condition, as_tuple=True)``.
  27289. .. note::
  27290. See also :func:`torch.nonzero`.
  27291. """
  27292. @overload
  27293. def where(
  27294. condition: Tensor,
  27295. input: Tensor,
  27296. other: Tensor,
  27297. *,
  27298. out: Tensor | None = None,
  27299. ) -> Tensor:
  27300. r"""
  27301. where(condition, input, other, *, out=None) -> Tensor
  27302. Return a tensor of elements selected from either :attr:`input` or :attr:`other`, depending on :attr:`condition`.
  27303. The operation is defined as:
  27304. .. math::
  27305. \text{out}_i = \begin{cases}
  27306. \text{input}_i & \text{if } \text{condition}_i \\
  27307. \text{other}_i & \text{otherwise} \\
  27308. \end{cases}
  27309. .. note::
  27310. The tensors :attr:`condition`, :attr:`input`, :attr:`other` must be :ref:`broadcastable <broadcasting-semantics>`.
  27311. Arguments:
  27312. condition (BoolTensor): When True (nonzero), yield input, otherwise yield other
  27313. input (Tensor or Scalar): value (if :attr:`input` is a scalar) or values selected at indices
  27314. where :attr:`condition` is ``True``
  27315. other (Tensor or Scalar): value (if :attr:`other` is a scalar) or values selected at indices
  27316. where :attr:`condition` is ``False``
  27317. Keyword args:
  27318. out (Tensor, optional): the output tensor.
  27319. Returns:
  27320. Tensor: A tensor of shape equal to the broadcasted shape of :attr:`condition`, :attr:`input`, :attr:`other`
  27321. Example::
  27322. >>> x = torch.randn(3, 2)
  27323. >>> y = torch.ones(3, 2)
  27324. >>> x
  27325. tensor([[-0.4620, 0.3139],
  27326. [ 0.3898, -0.7197],
  27327. [ 0.0478, -0.1657]])
  27328. >>> torch.where(x > 0, 1.0, 0.0)
  27329. tensor([[0., 1.],
  27330. [1., 0.],
  27331. [1., 0.]])
  27332. >>> torch.where(x > 0, x, y)
  27333. tensor([[ 1.0000, 0.3139],
  27334. [ 0.3898, 1.0000],
  27335. [ 0.0478, 1.0000]])
  27336. >>> x = torch.randn(2, 2, dtype=torch.double)
  27337. >>> x
  27338. tensor([[ 1.0779, 0.0383],
  27339. [-0.8785, -1.1089]], dtype=torch.float64)
  27340. >>> torch.where(x > 0, x, 0.)
  27341. tensor([[1.0779, 0.0383],
  27342. [0.0000, 0.0000]], dtype=torch.float64)
  27343. .. function:: where(condition) -> tuple of LongTensor
  27344. :noindex:
  27345. ``torch.where(condition)`` is identical to
  27346. ``torch.nonzero(condition, as_tuple=True)``.
  27347. .. note::
  27348. See also :func:`torch.nonzero`.
  27349. """
  27350. @overload
  27351. def where(
  27352. condition: Tensor,
  27353. self: Number | _complex,
  27354. other: Tensor,
  27355. ) -> Tensor:
  27356. r"""
  27357. where(condition, input, other, *, out=None) -> Tensor
  27358. Return a tensor of elements selected from either :attr:`input` or :attr:`other`, depending on :attr:`condition`.
  27359. The operation is defined as:
  27360. .. math::
  27361. \text{out}_i = \begin{cases}
  27362. \text{input}_i & \text{if } \text{condition}_i \\
  27363. \text{other}_i & \text{otherwise} \\
  27364. \end{cases}
  27365. .. note::
  27366. The tensors :attr:`condition`, :attr:`input`, :attr:`other` must be :ref:`broadcastable <broadcasting-semantics>`.
  27367. Arguments:
  27368. condition (BoolTensor): When True (nonzero), yield input, otherwise yield other
  27369. input (Tensor or Scalar): value (if :attr:`input` is a scalar) or values selected at indices
  27370. where :attr:`condition` is ``True``
  27371. other (Tensor or Scalar): value (if :attr:`other` is a scalar) or values selected at indices
  27372. where :attr:`condition` is ``False``
  27373. Keyword args:
  27374. out (Tensor, optional): the output tensor.
  27375. Returns:
  27376. Tensor: A tensor of shape equal to the broadcasted shape of :attr:`condition`, :attr:`input`, :attr:`other`
  27377. Example::
  27378. >>> x = torch.randn(3, 2)
  27379. >>> y = torch.ones(3, 2)
  27380. >>> x
  27381. tensor([[-0.4620, 0.3139],
  27382. [ 0.3898, -0.7197],
  27383. [ 0.0478, -0.1657]])
  27384. >>> torch.where(x > 0, 1.0, 0.0)
  27385. tensor([[0., 1.],
  27386. [1., 0.],
  27387. [1., 0.]])
  27388. >>> torch.where(x > 0, x, y)
  27389. tensor([[ 1.0000, 0.3139],
  27390. [ 0.3898, 1.0000],
  27391. [ 0.0478, 1.0000]])
  27392. >>> x = torch.randn(2, 2, dtype=torch.double)
  27393. >>> x
  27394. tensor([[ 1.0779, 0.0383],
  27395. [-0.8785, -1.1089]], dtype=torch.float64)
  27396. >>> torch.where(x > 0, x, 0.)
  27397. tensor([[1.0779, 0.0383],
  27398. [0.0000, 0.0000]], dtype=torch.float64)
  27399. .. function:: where(condition) -> tuple of LongTensor
  27400. :noindex:
  27401. ``torch.where(condition)`` is identical to
  27402. ``torch.nonzero(condition, as_tuple=True)``.
  27403. .. note::
  27404. See also :func:`torch.nonzero`.
  27405. """
  27406. @overload
  27407. def where(
  27408. condition: Tensor,
  27409. input: Tensor,
  27410. other: Number | _complex,
  27411. ) -> Tensor:
  27412. r"""
  27413. where(condition, input, other, *, out=None) -> Tensor
  27414. Return a tensor of elements selected from either :attr:`input` or :attr:`other`, depending on :attr:`condition`.
  27415. The operation is defined as:
  27416. .. math::
  27417. \text{out}_i = \begin{cases}
  27418. \text{input}_i & \text{if } \text{condition}_i \\
  27419. \text{other}_i & \text{otherwise} \\
  27420. \end{cases}
  27421. .. note::
  27422. The tensors :attr:`condition`, :attr:`input`, :attr:`other` must be :ref:`broadcastable <broadcasting-semantics>`.
  27423. Arguments:
  27424. condition (BoolTensor): When True (nonzero), yield input, otherwise yield other
  27425. input (Tensor or Scalar): value (if :attr:`input` is a scalar) or values selected at indices
  27426. where :attr:`condition` is ``True``
  27427. other (Tensor or Scalar): value (if :attr:`other` is a scalar) or values selected at indices
  27428. where :attr:`condition` is ``False``
  27429. Keyword args:
  27430. out (Tensor, optional): the output tensor.
  27431. Returns:
  27432. Tensor: A tensor of shape equal to the broadcasted shape of :attr:`condition`, :attr:`input`, :attr:`other`
  27433. Example::
  27434. >>> x = torch.randn(3, 2)
  27435. >>> y = torch.ones(3, 2)
  27436. >>> x
  27437. tensor([[-0.4620, 0.3139],
  27438. [ 0.3898, -0.7197],
  27439. [ 0.0478, -0.1657]])
  27440. >>> torch.where(x > 0, 1.0, 0.0)
  27441. tensor([[0., 1.],
  27442. [1., 0.],
  27443. [1., 0.]])
  27444. >>> torch.where(x > 0, x, y)
  27445. tensor([[ 1.0000, 0.3139],
  27446. [ 0.3898, 1.0000],
  27447. [ 0.0478, 1.0000]])
  27448. >>> x = torch.randn(2, 2, dtype=torch.double)
  27449. >>> x
  27450. tensor([[ 1.0779, 0.0383],
  27451. [-0.8785, -1.1089]], dtype=torch.float64)
  27452. >>> torch.where(x > 0, x, 0.)
  27453. tensor([[1.0779, 0.0383],
  27454. [0.0000, 0.0000]], dtype=torch.float64)
  27455. .. function:: where(condition) -> tuple of LongTensor
  27456. :noindex:
  27457. ``torch.where(condition)`` is identical to
  27458. ``torch.nonzero(condition, as_tuple=True)``.
  27459. .. note::
  27460. See also :func:`torch.nonzero`.
  27461. """
  27462. @overload
  27463. def where(
  27464. condition: Tensor,
  27465. self: Number | _complex,
  27466. other: Number | _complex,
  27467. ) -> Tensor:
  27468. r"""
  27469. where(condition, input, other, *, out=None) -> Tensor
  27470. Return a tensor of elements selected from either :attr:`input` or :attr:`other`, depending on :attr:`condition`.
  27471. The operation is defined as:
  27472. .. math::
  27473. \text{out}_i = \begin{cases}
  27474. \text{input}_i & \text{if } \text{condition}_i \\
  27475. \text{other}_i & \text{otherwise} \\
  27476. \end{cases}
  27477. .. note::
  27478. The tensors :attr:`condition`, :attr:`input`, :attr:`other` must be :ref:`broadcastable <broadcasting-semantics>`.
  27479. Arguments:
  27480. condition (BoolTensor): When True (nonzero), yield input, otherwise yield other
  27481. input (Tensor or Scalar): value (if :attr:`input` is a scalar) or values selected at indices
  27482. where :attr:`condition` is ``True``
  27483. other (Tensor or Scalar): value (if :attr:`other` is a scalar) or values selected at indices
  27484. where :attr:`condition` is ``False``
  27485. Keyword args:
  27486. out (Tensor, optional): the output tensor.
  27487. Returns:
  27488. Tensor: A tensor of shape equal to the broadcasted shape of :attr:`condition`, :attr:`input`, :attr:`other`
  27489. Example::
  27490. >>> x = torch.randn(3, 2)
  27491. >>> y = torch.ones(3, 2)
  27492. >>> x
  27493. tensor([[-0.4620, 0.3139],
  27494. [ 0.3898, -0.7197],
  27495. [ 0.0478, -0.1657]])
  27496. >>> torch.where(x > 0, 1.0, 0.0)
  27497. tensor([[0., 1.],
  27498. [1., 0.],
  27499. [1., 0.]])
  27500. >>> torch.where(x > 0, x, y)
  27501. tensor([[ 1.0000, 0.3139],
  27502. [ 0.3898, 1.0000],
  27503. [ 0.0478, 1.0000]])
  27504. >>> x = torch.randn(2, 2, dtype=torch.double)
  27505. >>> x
  27506. tensor([[ 1.0779, 0.0383],
  27507. [-0.8785, -1.1089]], dtype=torch.float64)
  27508. >>> torch.where(x > 0, x, 0.)
  27509. tensor([[1.0779, 0.0383],
  27510. [0.0000, 0.0000]], dtype=torch.float64)
  27511. .. function:: where(condition) -> tuple of LongTensor
  27512. :noindex:
  27513. ``torch.where(condition)`` is identical to
  27514. ``torch.nonzero(condition, as_tuple=True)``.
  27515. .. note::
  27516. See also :func:`torch.nonzero`.
  27517. """
  27518. @overload
  27519. def xlogy(
  27520. input: Tensor,
  27521. other: Tensor,
  27522. *,
  27523. out: Tensor | None = None,
  27524. ) -> Tensor:
  27525. r"""
  27526. xlogy(input, other, *, out=None) -> Tensor
  27527. Alias for :func:`torch.special.xlogy`.
  27528. """
  27529. @overload
  27530. def xlogy(
  27531. self: Number | _complex,
  27532. other: Tensor,
  27533. *,
  27534. out: Tensor | None = None,
  27535. ) -> Tensor:
  27536. r"""
  27537. xlogy(input, other, *, out=None) -> Tensor
  27538. Alias for :func:`torch.special.xlogy`.
  27539. """
  27540. @overload
  27541. def xlogy(
  27542. input: Tensor,
  27543. other: Number | _complex,
  27544. *,
  27545. out: Tensor | None = None,
  27546. ) -> Tensor:
  27547. r"""
  27548. xlogy(input, other, *, out=None) -> Tensor
  27549. Alias for :func:`torch.special.xlogy`.
  27550. """
  27551. @overload
  27552. def xlogy_(input: Tensor, other: Tensor) -> Tensor: ...
  27553. @overload
  27554. def xlogy_(input: Tensor, other: Number | _complex) -> Tensor: ...
  27555. def zero_(input: Tensor) -> Tensor: ...
  27556. @overload
  27557. def zeros(
  27558. size: Sequence[_int | SymInt],
  27559. *,
  27560. out: Tensor | None = None,
  27561. dtype: _dtype | None = None,
  27562. layout: _layout | None = None,
  27563. device: DeviceLikeType | None = None,
  27564. pin_memory: _bool | None = False,
  27565. requires_grad: _bool | None = False,
  27566. ) -> Tensor:
  27567. r"""
  27568. zeros(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  27569. Returns a tensor filled with the scalar value `0`, with the shape defined
  27570. by the variable argument :attr:`size`.
  27571. Args:
  27572. size (int...): a sequence of integers defining the shape of the output tensor.
  27573. Can be a variable number of arguments or a collection like a list or tuple.
  27574. Keyword args:
  27575. out (Tensor, optional): the output tensor.
  27576. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  27577. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  27578. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  27579. Default: ``torch.strided``.
  27580. device (:class:`torch.device`, optional): the desired device of returned tensor.
  27581. Default: if ``None``, uses the current device for the default tensor type
  27582. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  27583. for CPU tensor types and the current CUDA device for CUDA tensor types.
  27584. requires_grad (bool, optional): If autograd should record operations on the
  27585. returned tensor. Default: ``False``.
  27586. Example::
  27587. >>> torch.zeros(2, 3)
  27588. tensor([[ 0., 0., 0.],
  27589. [ 0., 0., 0.]])
  27590. >>> torch.zeros(5)
  27591. tensor([ 0., 0., 0., 0., 0.])
  27592. """
  27593. @overload
  27594. def zeros(
  27595. *size: _int | SymInt,
  27596. out: Tensor | None = None,
  27597. dtype: _dtype | None = None,
  27598. layout: _layout | None = None,
  27599. device: DeviceLikeType | None = None,
  27600. pin_memory: _bool | None = False,
  27601. requires_grad: _bool | None = False,
  27602. ) -> Tensor:
  27603. r"""
  27604. zeros(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  27605. Returns a tensor filled with the scalar value `0`, with the shape defined
  27606. by the variable argument :attr:`size`.
  27607. Args:
  27608. size (int...): a sequence of integers defining the shape of the output tensor.
  27609. Can be a variable number of arguments or a collection like a list or tuple.
  27610. Keyword args:
  27611. out (Tensor, optional): the output tensor.
  27612. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  27613. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  27614. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  27615. Default: ``torch.strided``.
  27616. device (:class:`torch.device`, optional): the desired device of returned tensor.
  27617. Default: if ``None``, uses the current device for the default tensor type
  27618. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  27619. for CPU tensor types and the current CUDA device for CUDA tensor types.
  27620. requires_grad (bool, optional): If autograd should record operations on the
  27621. returned tensor. Default: ``False``.
  27622. Example::
  27623. >>> torch.zeros(2, 3)
  27624. tensor([[ 0., 0., 0.],
  27625. [ 0., 0., 0.]])
  27626. >>> torch.zeros(5)
  27627. tensor([ 0., 0., 0., 0., 0.])
  27628. """
  27629. @overload
  27630. def zeros(
  27631. size: _size,
  27632. *,
  27633. names: Sequence[str | EllipsisType | None] | None,
  27634. dtype: _dtype | None = None,
  27635. layout: _layout | None = None,
  27636. device: DeviceLikeType | None = None,
  27637. pin_memory: _bool | None = False,
  27638. requires_grad: _bool | None = False,
  27639. ) -> Tensor:
  27640. r"""
  27641. zeros(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  27642. Returns a tensor filled with the scalar value `0`, with the shape defined
  27643. by the variable argument :attr:`size`.
  27644. Args:
  27645. size (int...): a sequence of integers defining the shape of the output tensor.
  27646. Can be a variable number of arguments or a collection like a list or tuple.
  27647. Keyword args:
  27648. out (Tensor, optional): the output tensor.
  27649. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  27650. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  27651. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  27652. Default: ``torch.strided``.
  27653. device (:class:`torch.device`, optional): the desired device of returned tensor.
  27654. Default: if ``None``, uses the current device for the default tensor type
  27655. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  27656. for CPU tensor types and the current CUDA device for CUDA tensor types.
  27657. requires_grad (bool, optional): If autograd should record operations on the
  27658. returned tensor. Default: ``False``.
  27659. Example::
  27660. >>> torch.zeros(2, 3)
  27661. tensor([[ 0., 0., 0.],
  27662. [ 0., 0., 0.]])
  27663. >>> torch.zeros(5)
  27664. tensor([ 0., 0., 0., 0., 0.])
  27665. """
  27666. @overload
  27667. def zeros(
  27668. *size: _int,
  27669. names: Sequence[str | EllipsisType | None] | None,
  27670. dtype: _dtype | None = None,
  27671. layout: _layout | None = None,
  27672. device: DeviceLikeType | None = None,
  27673. pin_memory: _bool | None = False,
  27674. requires_grad: _bool | None = False,
  27675. ) -> Tensor:
  27676. r"""
  27677. zeros(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  27678. Returns a tensor filled with the scalar value `0`, with the shape defined
  27679. by the variable argument :attr:`size`.
  27680. Args:
  27681. size (int...): a sequence of integers defining the shape of the output tensor.
  27682. Can be a variable number of arguments or a collection like a list or tuple.
  27683. Keyword args:
  27684. out (Tensor, optional): the output tensor.
  27685. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  27686. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  27687. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  27688. Default: ``torch.strided``.
  27689. device (:class:`torch.device`, optional): the desired device of returned tensor.
  27690. Default: if ``None``, uses the current device for the default tensor type
  27691. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  27692. for CPU tensor types and the current CUDA device for CUDA tensor types.
  27693. requires_grad (bool, optional): If autograd should record operations on the
  27694. returned tensor. Default: ``False``.
  27695. Example::
  27696. >>> torch.zeros(2, 3)
  27697. tensor([[ 0., 0., 0.],
  27698. [ 0., 0., 0.]])
  27699. >>> torch.zeros(5)
  27700. tensor([ 0., 0., 0., 0., 0.])
  27701. """
  27702. def zeros_like(
  27703. input: Tensor,
  27704. *,
  27705. memory_format: memory_format | None = None,
  27706. dtype: _dtype | None = None,
  27707. layout: _layout | None = None,
  27708. device: DeviceLikeType | None = None,
  27709. pin_memory: _bool | None = False,
  27710. requires_grad: _bool | None = False,
  27711. ) -> Tensor:
  27712. r"""
  27713. zeros_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  27714. Returns a tensor filled with the scalar value `0`, with the same size as
  27715. :attr:`input`. ``torch.zeros_like(input)`` is equivalent to
  27716. ``torch.zeros(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
  27717. .. warning::
  27718. As of 0.4, this function does not support an :attr:`out` keyword. As an alternative,
  27719. the old ``torch.zeros_like(input, out=output)`` is equivalent to
  27720. ``torch.zeros(input.size(), out=output)``.
  27721. Args:
  27722. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  27723. Keyword args:
  27724. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  27725. Default: if ``None``, defaults to the dtype of :attr:`input`.
  27726. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  27727. Default: if ``None``, defaults to the layout of :attr:`input`.
  27728. device (:class:`torch.device`, optional): the desired device of returned tensor.
  27729. Default: if ``None``, defaults to the device of :attr:`input`.
  27730. requires_grad (bool, optional): If autograd should record operations on the
  27731. returned tensor. Default: ``False``.
  27732. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  27733. returned Tensor. Default: ``torch.preserve_format``.
  27734. Example::
  27735. >>> input = torch.empty(2, 3)
  27736. >>> torch.zeros_like(input)
  27737. tensor([[ 0., 0., 0.],
  27738. [ 0., 0., 0.]])
  27739. """