_VariableFunctions.pyi 1.1 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541
  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 Sequence
  6. from types import EllipsisType
  7. from typing import Any, Callable, 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_reciprocal",
  173. "_foreach_reciprocal_",
  174. "_foreach_round",
  175. "_foreach_round_",
  176. "_foreach_rsqrt",
  177. "_foreach_rsqrt_",
  178. "_foreach_sigmoid",
  179. "_foreach_sigmoid_",
  180. "_foreach_sign",
  181. "_foreach_sign_",
  182. "_foreach_sin",
  183. "_foreach_sin_",
  184. "_foreach_sinh",
  185. "_foreach_sinh_",
  186. "_foreach_sqrt",
  187. "_foreach_sqrt_",
  188. "_foreach_sub",
  189. "_foreach_sub_",
  190. "_foreach_tan",
  191. "_foreach_tan_",
  192. "_foreach_tanh",
  193. "_foreach_tanh_",
  194. "_foreach_trunc",
  195. "_foreach_trunc_",
  196. "_foreach_zero_",
  197. "_from_functional_tensor",
  198. "_functional_assert_async",
  199. "_functional_assert_scalar",
  200. "_functional_sym_constrain_range",
  201. "_functional_sym_constrain_range_for_size",
  202. "_functionalize_apply_view_metas",
  203. "_functionalize_are_all_mutations_hidden_from_autograd",
  204. "_functionalize_are_all_mutations_under_no_grad_or_inference_mode",
  205. "_functionalize_commit_update",
  206. "_functionalize_has_metadata_mutation",
  207. "_functionalize_inductor_storage_resized_counter",
  208. "_functionalize_is_symbolic",
  209. "_functionalize_mark_mutation_hidden_from_autograd",
  210. "_functionalize_mark_storage_changed",
  211. "_functionalize_mutation_counter",
  212. "_functionalize_replace",
  213. "_functionalize_storage_changed_counter",
  214. "_functionalize_sync",
  215. "_functionalize_unsafe_set",
  216. "_functionalize_was_inductor_storage_resized",
  217. "_functionalize_was_storage_changed",
  218. "_fused_adagrad_",
  219. "_fused_adam_",
  220. "_fused_adamw_",
  221. "_fused_dropout",
  222. "_fused_moving_avg_obs_fq_helper",
  223. "_fused_rms_norm",
  224. "_fused_sdp_choice",
  225. "_fused_sgd_",
  226. "_fw_primal_copy",
  227. "_grid_sampler_2d_cpu_fallback",
  228. "_grouped_mm",
  229. "_has_compatible_shallow_copy_type",
  230. "_histogramdd_bin_edges",
  231. "_histogramdd_from_bin_cts",
  232. "_histogramdd_from_bin_tensors",
  233. "_index_put_impl_",
  234. "_indices_copy",
  235. "_int_mm",
  236. "_is_all_true",
  237. "_is_any_true",
  238. "_is_functional_tensor",
  239. "_is_functional_tensor_base",
  240. "_is_zerotensor",
  241. "_lazy_clone",
  242. "_linalg_check_errors",
  243. "_linalg_det",
  244. "_linalg_eigh",
  245. "_linalg_slogdet",
  246. "_linalg_solve_ex",
  247. "_linalg_svd",
  248. "_log_softmax",
  249. "_log_softmax_backward_data",
  250. "_logcumsumexp",
  251. "_lstm_mps",
  252. "_lu_with_info",
  253. "_make_dep_token",
  254. "_make_dual",
  255. "_make_dual_copy",
  256. "_make_per_channel_quantized_tensor",
  257. "_make_per_tensor_quantized_tensor",
  258. "_masked_scale",
  259. "_masked_softmax",
  260. "_mixed_dtypes_linear",
  261. "_mkldnn_reshape",
  262. "_mkldnn_transpose",
  263. "_mkldnn_transpose_",
  264. "_mps_convolution",
  265. "_mps_convolution_transpose",
  266. "_native_batch_norm_legit",
  267. "_native_batch_norm_legit_no_training",
  268. "_native_multi_head_attention",
  269. "_neg_view",
  270. "_neg_view_copy",
  271. "_nested_compute_contiguous_strides_offsets",
  272. "_nested_from_padded",
  273. "_nested_from_padded_and_nested_example",
  274. "_nested_from_padded_tensor",
  275. "_nested_get_jagged_dummy",
  276. "_nested_get_lengths",
  277. "_nested_get_max_seqlen",
  278. "_nested_get_min_seqlen",
  279. "_nested_get_offsets",
  280. "_nested_get_ragged_idx",
  281. "_nested_get_values",
  282. "_nested_get_values_copy",
  283. "_nested_tensor_from_mask",
  284. "_nested_tensor_from_mask_left_aligned",
  285. "_nested_tensor_from_tensor_list",
  286. "_nested_tensor_softmax_with_shape",
  287. "_nested_view_from_buffer",
  288. "_nested_view_from_buffer_copy",
  289. "_nested_view_from_jagged",
  290. "_nested_view_from_jagged_copy",
  291. "_nnpack_available",
  292. "_nnpack_spatial_convolution",
  293. "_pack_padded_sequence",
  294. "_pad_packed_sequence",
  295. "_pin_memory",
  296. "_prelu_kernel",
  297. "_print",
  298. "_propagate_xla_data",
  299. "_remove_batch_dim",
  300. "_reshape_alias_copy",
  301. "_reshape_from_tensor",
  302. "_resize_output_",
  303. "_rowwise_prune",
  304. "_safe_softmax",
  305. "_sample_dirichlet",
  306. "_saturate_weight_to_fp16",
  307. "_scaled_dot_product_attention_math",
  308. "_scaled_dot_product_attention_math_for_mps",
  309. "_scaled_dot_product_cudnn_attention",
  310. "_scaled_dot_product_efficient_attention",
  311. "_scaled_dot_product_flash_attention",
  312. "_scaled_dot_product_flash_attention_for_cpu",
  313. "_scaled_grouped_mm",
  314. "_scaled_mm",
  315. "_shape_as_tensor",
  316. "_sobol_engine_draw",
  317. "_sobol_engine_ff_",
  318. "_sobol_engine_initialize_state_",
  319. "_sobol_engine_scramble_",
  320. "_softmax",
  321. "_softmax_backward_data",
  322. "_sparse_broadcast_to",
  323. "_sparse_broadcast_to_copy",
  324. "_sparse_csr_prod",
  325. "_sparse_csr_sum",
  326. "_sparse_log_softmax_backward_data",
  327. "_sparse_semi_structured_addmm",
  328. "_sparse_semi_structured_apply",
  329. "_sparse_semi_structured_apply_dense",
  330. "_sparse_semi_structured_linear",
  331. "_sparse_semi_structured_mm",
  332. "_sparse_semi_structured_tile",
  333. "_sparse_softmax_backward_data",
  334. "_sparse_sparse_matmul",
  335. "_sparse_sum",
  336. "_stack",
  337. "_standard_gamma",
  338. "_standard_gamma_grad",
  339. "_sync",
  340. "_test_autograd_multiple_dispatch",
  341. "_test_autograd_multiple_dispatch_view",
  342. "_test_autograd_multiple_dispatch_view_copy",
  343. "_test_check_tensor",
  344. "_test_functorch_fallback",
  345. "_test_parallel_materialize",
  346. "_test_serialization_subcmul",
  347. "_to_cpu",
  348. "_to_functional_tensor",
  349. "_to_sparse_semi_structured",
  350. "_transform_bias_rescale_qkv",
  351. "_transformer_encoder_layer_fwd",
  352. "_trilinear",
  353. "_triton_multi_head_attention",
  354. "_triton_scaled_dot_attention",
  355. "_unique",
  356. "_unique2",
  357. "_unpack_dual",
  358. "_unsafe_index",
  359. "_unsafe_index_put",
  360. "_unsafe_masked_index",
  361. "_unsafe_masked_index_put_accumulate",
  362. "_use_cudnn_ctc_loss",
  363. "_use_cudnn_rnn_flatten_weight",
  364. "_validate_compressed_sparse_indices",
  365. "_validate_sparse_bsc_tensor_args",
  366. "_validate_sparse_bsr_tensor_args",
  367. "_validate_sparse_compressed_tensor_args",
  368. "_validate_sparse_coo_tensor_args",
  369. "_validate_sparse_csc_tensor_args",
  370. "_validate_sparse_csr_tensor_args",
  371. "_values_copy",
  372. "_weight_int4pack_mm",
  373. "_weight_int4pack_mm_for_cpu",
  374. "_weight_int4pack_mm_with_scales_and_zeros",
  375. "_weight_int8pack_mm",
  376. "_weight_norm",
  377. "_weight_norm_interface",
  378. "_wrapped_linear_prepack",
  379. "_wrapped_quantized_linear_prepacked",
  380. "abs",
  381. "abs_",
  382. "absolute",
  383. "acos",
  384. "acos_",
  385. "acosh",
  386. "acosh_",
  387. "adaptive_avg_pool1d",
  388. "adaptive_max_pool1d",
  389. "add",
  390. "addbmm",
  391. "addcdiv",
  392. "addcmul",
  393. "addmm",
  394. "addmv",
  395. "addmv_",
  396. "addr",
  397. "adjoint",
  398. "affine_grid_generator",
  399. "alias_copy",
  400. "all",
  401. "allclose",
  402. "alpha_dropout",
  403. "alpha_dropout_",
  404. "amax",
  405. "amin",
  406. "aminmax",
  407. "angle",
  408. "any",
  409. "arange",
  410. "arccos",
  411. "arccos_",
  412. "arccosh",
  413. "arccosh_",
  414. "arcsin",
  415. "arcsin_",
  416. "arcsinh",
  417. "arcsinh_",
  418. "arctan",
  419. "arctan2",
  420. "arctan_",
  421. "arctanh",
  422. "arctanh_",
  423. "argmax",
  424. "argmin",
  425. "argsort",
  426. "argwhere",
  427. "as_strided",
  428. "as_strided_",
  429. "as_strided_copy",
  430. "as_strided_scatter",
  431. "as_tensor",
  432. "asarray",
  433. "asin",
  434. "asin_",
  435. "asinh",
  436. "asinh_",
  437. "atan",
  438. "atan2",
  439. "atan_",
  440. "atanh",
  441. "atanh_",
  442. "avg_pool1d",
  443. "baddbmm",
  444. "bartlett_window",
  445. "batch_norm",
  446. "batch_norm_backward_elemt",
  447. "batch_norm_backward_reduce",
  448. "batch_norm_elemt",
  449. "batch_norm_gather_stats",
  450. "batch_norm_gather_stats_with_counts",
  451. "batch_norm_stats",
  452. "batch_norm_update_stats",
  453. "bernoulli",
  454. "bilinear",
  455. "binary_cross_entropy_with_logits",
  456. "bincount",
  457. "binomial",
  458. "bitwise_and",
  459. "bitwise_left_shift",
  460. "bitwise_not",
  461. "bitwise_or",
  462. "bitwise_right_shift",
  463. "bitwise_xor",
  464. "blackman_window",
  465. "bmm",
  466. "broadcast_to",
  467. "bucketize",
  468. "can_cast",
  469. "cat",
  470. "ccol_indices_copy",
  471. "ceil",
  472. "ceil_",
  473. "celu",
  474. "celu_",
  475. "channel_shuffle",
  476. "cholesky",
  477. "cholesky_inverse",
  478. "cholesky_solve",
  479. "choose_qparams_optimized",
  480. "chunk",
  481. "clamp",
  482. "clamp_",
  483. "clamp_max",
  484. "clamp_max_",
  485. "clamp_min",
  486. "clamp_min_",
  487. "clip",
  488. "clip_",
  489. "clone",
  490. "col_indices_copy",
  491. "column_stack",
  492. "combinations",
  493. "complex",
  494. "concat",
  495. "concatenate",
  496. "conj",
  497. "conj_physical",
  498. "conj_physical_",
  499. "constant_pad_nd",
  500. "conv1d",
  501. "conv2d",
  502. "conv3d",
  503. "conv_tbc",
  504. "conv_transpose1d",
  505. "conv_transpose2d",
  506. "conv_transpose3d",
  507. "convolution",
  508. "copysign",
  509. "corrcoef",
  510. "cos",
  511. "cos_",
  512. "cosh",
  513. "cosh_",
  514. "cosine_embedding_loss",
  515. "cosine_similarity",
  516. "count_nonzero",
  517. "cov",
  518. "cross",
  519. "crow_indices_copy",
  520. "ctc_loss",
  521. "cudnn_affine_grid_generator",
  522. "cudnn_batch_norm",
  523. "cudnn_convolution",
  524. "cudnn_convolution_add_relu",
  525. "cudnn_convolution_relu",
  526. "cudnn_convolution_transpose",
  527. "cudnn_grid_sampler",
  528. "cudnn_is_acceptable",
  529. "cummax",
  530. "cummin",
  531. "cumprod",
  532. "cumsum",
  533. "cumulative_trapezoid",
  534. "deg2rad",
  535. "deg2rad_",
  536. "dequantize",
  537. "det",
  538. "detach",
  539. "detach_",
  540. "detach_copy",
  541. "diag",
  542. "diag_embed",
  543. "diagflat",
  544. "diagonal",
  545. "diagonal_copy",
  546. "diagonal_scatter",
  547. "diff",
  548. "digamma",
  549. "dist",
  550. "div",
  551. "divide",
  552. "dot",
  553. "dropout",
  554. "dropout_",
  555. "dsmm",
  556. "dsplit",
  557. "dstack",
  558. "embedding",
  559. "embedding_bag",
  560. "embedding_renorm_",
  561. "empty",
  562. "empty_like",
  563. "empty_permuted",
  564. "empty_quantized",
  565. "empty_strided",
  566. "eq",
  567. "equal",
  568. "erf",
  569. "erf_",
  570. "erfc",
  571. "erfc_",
  572. "erfinv",
  573. "exp",
  574. "exp2",
  575. "exp2_",
  576. "exp_",
  577. "expand_copy",
  578. "expm1",
  579. "expm1_",
  580. "eye",
  581. "fake_quantize_per_channel_affine",
  582. "fake_quantize_per_tensor_affine",
  583. "fbgemm_linear_fp16_weight",
  584. "fbgemm_linear_fp16_weight_fp32_activation",
  585. "fbgemm_linear_int8_weight",
  586. "fbgemm_linear_int8_weight_fp32_activation",
  587. "fbgemm_linear_quantize_weight",
  588. "fbgemm_pack_gemm_matrix_fp16",
  589. "fbgemm_pack_quantized_matrix",
  590. "feature_alpha_dropout",
  591. "feature_alpha_dropout_",
  592. "feature_dropout",
  593. "feature_dropout_",
  594. "fill",
  595. "fill_",
  596. "fix",
  597. "fix_",
  598. "flatten",
  599. "flip",
  600. "fliplr",
  601. "flipud",
  602. "float_power",
  603. "floor",
  604. "floor_",
  605. "floor_divide",
  606. "fmax",
  607. "fmin",
  608. "fmod",
  609. "frac",
  610. "frac_",
  611. "frexp",
  612. "frobenius_norm",
  613. "from_file",
  614. "from_numpy",
  615. "frombuffer",
  616. "full",
  617. "full_like",
  618. "fused_moving_avg_obs_fake_quant",
  619. "gather",
  620. "gcd",
  621. "gcd_",
  622. "ge",
  623. "geqrf",
  624. "ger",
  625. "get_default_dtype",
  626. "get_num_interop_threads",
  627. "get_num_threads",
  628. "gradient",
  629. "greater",
  630. "greater_equal",
  631. "grid_sampler",
  632. "grid_sampler_2d",
  633. "grid_sampler_3d",
  634. "group_norm",
  635. "gru",
  636. "gru_cell",
  637. "gt",
  638. "hamming_window",
  639. "hann_window",
  640. "hardshrink",
  641. "hash_tensor",
  642. "heaviside",
  643. "hinge_embedding_loss",
  644. "histc",
  645. "histogram",
  646. "histogramdd",
  647. "hsmm",
  648. "hsplit",
  649. "hspmm",
  650. "hstack",
  651. "hypot",
  652. "i0",
  653. "i0_",
  654. "igamma",
  655. "igammac",
  656. "imag",
  657. "index_add",
  658. "index_copy",
  659. "index_fill",
  660. "index_put",
  661. "index_put_",
  662. "index_reduce",
  663. "index_select",
  664. "indices_copy",
  665. "init_num_threads",
  666. "inner",
  667. "instance_norm",
  668. "int_repr",
  669. "inverse",
  670. "is_complex",
  671. "is_conj",
  672. "is_distributed",
  673. "is_floating_point",
  674. "is_grad_enabled",
  675. "is_inference",
  676. "is_inference_mode_enabled",
  677. "is_neg",
  678. "is_nonzero",
  679. "is_same_size",
  680. "is_signed",
  681. "is_vulkan_available",
  682. "isclose",
  683. "isfinite",
  684. "isin",
  685. "isinf",
  686. "isnan",
  687. "isneginf",
  688. "isposinf",
  689. "isreal",
  690. "istft",
  691. "kaiser_window",
  692. "kl_div",
  693. "kron",
  694. "kthvalue",
  695. "layer_norm",
  696. "lcm",
  697. "lcm_",
  698. "ldexp",
  699. "ldexp_",
  700. "le",
  701. "lerp",
  702. "less",
  703. "less_equal",
  704. "lgamma",
  705. "linspace",
  706. "log",
  707. "log10",
  708. "log10_",
  709. "log1p",
  710. "log1p_",
  711. "log2",
  712. "log2_",
  713. "log_",
  714. "log_softmax",
  715. "logaddexp",
  716. "logaddexp2",
  717. "logcumsumexp",
  718. "logdet",
  719. "logical_and",
  720. "logical_not",
  721. "logical_or",
  722. "logical_xor",
  723. "logit",
  724. "logit_",
  725. "logspace",
  726. "logsumexp",
  727. "lstm",
  728. "lstm_cell",
  729. "lt",
  730. "lu_solve",
  731. "lu_unpack",
  732. "margin_ranking_loss",
  733. "masked_fill",
  734. "masked_scatter",
  735. "masked_select",
  736. "matmul",
  737. "matrix_exp",
  738. "matrix_power",
  739. "max",
  740. "max_pool1d",
  741. "max_pool1d_with_indices",
  742. "max_pool2d",
  743. "max_pool3d",
  744. "maximum",
  745. "mean",
  746. "median",
  747. "min",
  748. "minimum",
  749. "miopen_batch_norm",
  750. "miopen_convolution",
  751. "miopen_convolution_add_relu",
  752. "miopen_convolution_relu",
  753. "miopen_convolution_transpose",
  754. "miopen_depthwise_convolution",
  755. "miopen_rnn",
  756. "mkldnn_adaptive_avg_pool2d",
  757. "mkldnn_convolution",
  758. "mkldnn_linear_backward_weights",
  759. "mkldnn_max_pool2d",
  760. "mkldnn_max_pool3d",
  761. "mkldnn_rnn_layer",
  762. "mm",
  763. "mode",
  764. "moveaxis",
  765. "movedim",
  766. "msort",
  767. "mul",
  768. "multinomial",
  769. "multiply",
  770. "mv",
  771. "mvlgamma",
  772. "nan_to_num",
  773. "nan_to_num_",
  774. "nanmean",
  775. "nanmedian",
  776. "nanquantile",
  777. "nansum",
  778. "narrow",
  779. "narrow_copy",
  780. "native_batch_norm",
  781. "native_channel_shuffle",
  782. "native_dropout",
  783. "native_group_norm",
  784. "native_layer_norm",
  785. "native_norm",
  786. "ne",
  787. "neg",
  788. "neg_",
  789. "negative",
  790. "negative_",
  791. "nextafter",
  792. "nonzero",
  793. "nonzero_static",
  794. "norm_except_dim",
  795. "normal",
  796. "not_equal",
  797. "nuclear_norm",
  798. "numel",
  799. "ones",
  800. "ones_like",
  801. "orgqr",
  802. "ormqr",
  803. "outer",
  804. "pairwise_distance",
  805. "pdist",
  806. "permute",
  807. "permute_copy",
  808. "pinverse",
  809. "pixel_shuffle",
  810. "pixel_unshuffle",
  811. "poisson",
  812. "poisson_nll_loss",
  813. "polar",
  814. "polygamma",
  815. "positive",
  816. "pow",
  817. "prelu",
  818. "prod",
  819. "promote_types",
  820. "put",
  821. "q_per_channel_axis",
  822. "q_per_channel_scales",
  823. "q_per_channel_zero_points",
  824. "q_scale",
  825. "q_zero_point",
  826. "qr",
  827. "quantile",
  828. "quantize_per_channel",
  829. "quantize_per_tensor",
  830. "quantize_per_tensor_dynamic",
  831. "quantized_batch_norm",
  832. "quantized_gru_cell",
  833. "quantized_lstm_cell",
  834. "quantized_max_pool1d",
  835. "quantized_max_pool2d",
  836. "quantized_max_pool3d",
  837. "quantized_rnn_relu_cell",
  838. "quantized_rnn_tanh_cell",
  839. "rad2deg",
  840. "rad2deg_",
  841. "rand",
  842. "rand_like",
  843. "randint",
  844. "randint_like",
  845. "randn",
  846. "randn_like",
  847. "randperm",
  848. "range",
  849. "ravel",
  850. "real",
  851. "reciprocal",
  852. "reciprocal_",
  853. "relu",
  854. "relu_",
  855. "remainder",
  856. "renorm",
  857. "repeat_interleave",
  858. "reshape",
  859. "resize_as_",
  860. "resize_as_sparse_",
  861. "resolve_conj",
  862. "resolve_neg",
  863. "result_type",
  864. "rms_norm",
  865. "rnn_relu",
  866. "rnn_relu_cell",
  867. "rnn_tanh",
  868. "rnn_tanh_cell",
  869. "roll",
  870. "rot90",
  871. "round",
  872. "round_",
  873. "row_indices_copy",
  874. "row_stack",
  875. "rrelu",
  876. "rrelu_",
  877. "rsqrt",
  878. "rsqrt_",
  879. "rsub",
  880. "saddmm",
  881. "scalar_tensor",
  882. "scatter",
  883. "scatter_add",
  884. "scatter_reduce",
  885. "searchsorted",
  886. "segment_reduce",
  887. "select",
  888. "select_copy",
  889. "select_scatter",
  890. "selu",
  891. "selu_",
  892. "set_flush_denormal",
  893. "set_num_interop_threads",
  894. "set_num_threads",
  895. "sgn",
  896. "sigmoid",
  897. "sigmoid_",
  898. "sign",
  899. "signbit",
  900. "sin",
  901. "sin_",
  902. "sinc",
  903. "sinc_",
  904. "sinh",
  905. "sinh_",
  906. "slice_copy",
  907. "slice_inverse",
  908. "slice_scatter",
  909. "slogdet",
  910. "smm",
  911. "softmax",
  912. "sort",
  913. "sparse_bsc_tensor",
  914. "sparse_bsr_tensor",
  915. "sparse_compressed_tensor",
  916. "sparse_coo_tensor",
  917. "sparse_csc_tensor",
  918. "sparse_csr_tensor",
  919. "split_copy",
  920. "split_with_sizes",
  921. "split_with_sizes_copy",
  922. "spmm",
  923. "sqrt",
  924. "sqrt_",
  925. "square",
  926. "square_",
  927. "squeeze",
  928. "squeeze_copy",
  929. "sspaddmm",
  930. "stack",
  931. "std",
  932. "std_mean",
  933. "sub",
  934. "subtract",
  935. "sum",
  936. "svd",
  937. "swapaxes",
  938. "swapdims",
  939. "sym_constrain_range",
  940. "sym_constrain_range_for_size",
  941. "t",
  942. "t_copy",
  943. "take",
  944. "take_along_dim",
  945. "tan",
  946. "tan_",
  947. "tanh",
  948. "tanh_",
  949. "tensor",
  950. "tensor_split",
  951. "threshold",
  952. "threshold_",
  953. "tile",
  954. "topk",
  955. "trace",
  956. "transpose",
  957. "transpose_copy",
  958. "trapezoid",
  959. "trapz",
  960. "triangular_solve",
  961. "tril",
  962. "tril_indices",
  963. "triplet_margin_loss",
  964. "triu",
  965. "triu_indices",
  966. "true_divide",
  967. "trunc",
  968. "trunc_",
  969. "unbind",
  970. "unbind_copy",
  971. "unflatten",
  972. "unfold_copy",
  973. "unique_dim",
  974. "unsafe_chunk",
  975. "unsafe_split",
  976. "unsafe_split_with_sizes",
  977. "unsqueeze",
  978. "unsqueeze_copy",
  979. "values_copy",
  980. "vander",
  981. "var",
  982. "var_mean",
  983. "vdot",
  984. "view_as_complex",
  985. "view_as_complex_copy",
  986. "view_as_real",
  987. "view_as_real_copy",
  988. "view_copy",
  989. "vsplit",
  990. "vstack",
  991. "where",
  992. "xlogy",
  993. "xlogy_",
  994. "zero_",
  995. "zeros",
  996. "zeros_like",
  997. ]
  998. @overload
  999. def __and__(input: Tensor, other: Tensor) -> Tensor: ...
  1000. @overload
  1001. def __and__(input: Tensor, other: Number | _complex) -> Tensor: ...
  1002. @overload
  1003. def __lshift__(input: Tensor, other: Tensor) -> Tensor: ...
  1004. @overload
  1005. def __lshift__(input: Tensor, other: Number | _complex) -> Tensor: ...
  1006. @overload
  1007. def __or__(input: Tensor, other: Tensor) -> Tensor: ...
  1008. @overload
  1009. def __or__(input: Tensor, other: Number | _complex) -> Tensor: ...
  1010. @overload
  1011. def __rshift__(input: Tensor, other: Tensor) -> Tensor: ...
  1012. @overload
  1013. def __rshift__(input: Tensor, other: Number | _complex) -> Tensor: ...
  1014. @overload
  1015. def __xor__(input: Tensor, other: Tensor) -> Tensor: ...
  1016. @overload
  1017. def __xor__(input: Tensor, other: Number | _complex) -> Tensor: ...
  1018. def _adaptive_avg_pool2d(
  1019. input: Tensor,
  1020. output_size: _int | SymInt | Sequence[_int | SymInt],
  1021. ) -> Tensor: ...
  1022. def _adaptive_avg_pool3d(
  1023. input: Tensor,
  1024. output_size: _int | SymInt | Sequence[_int | SymInt],
  1025. ) -> Tensor: ...
  1026. def _add_batch_dim(input: Tensor, batch_dim: _int, level: _int) -> Tensor: ...
  1027. @overload
  1028. def _add_relu(
  1029. input: Tensor,
  1030. other: Tensor,
  1031. *,
  1032. alpha: Number | _complex = 1,
  1033. out: Tensor | None = None,
  1034. ) -> Tensor: ...
  1035. @overload
  1036. def _add_relu(
  1037. input: Tensor,
  1038. other: Number | _complex,
  1039. alpha: Number | _complex = 1,
  1040. ) -> Tensor: ...
  1041. @overload
  1042. def _add_relu_(
  1043. input: Tensor,
  1044. other: Tensor,
  1045. *,
  1046. alpha: Number | _complex = 1,
  1047. ) -> Tensor: ...
  1048. @overload
  1049. def _add_relu_(
  1050. input: Tensor,
  1051. other: Number | _complex,
  1052. alpha: Number | _complex = 1,
  1053. ) -> Tensor: ...
  1054. def _addmm_activation(
  1055. input: Tensor,
  1056. mat1: Tensor,
  1057. mat2: Tensor,
  1058. *,
  1059. beta: Number | _complex = 1,
  1060. alpha: Number | _complex = 1,
  1061. use_gelu: _bool = False,
  1062. out: Tensor | None = None,
  1063. ) -> Tensor: ...
  1064. @overload
  1065. def _aminmax(input: Tensor) -> tuple[Tensor, Tensor]: ...
  1066. @overload
  1067. def _aminmax(
  1068. input: Tensor,
  1069. dim: _int,
  1070. keepdim: _bool = False,
  1071. ) -> tuple[Tensor, Tensor]: ...
  1072. def _amp_foreach_non_finite_check_and_unscale_(
  1073. self: tuple[Tensor, ...] | list[Tensor] | None,
  1074. found_inf: Tensor,
  1075. inv_scale: Tensor,
  1076. ) -> None: ...
  1077. def _amp_update_scale_(
  1078. input: Tensor,
  1079. growth_tracker: Tensor,
  1080. found_inf: Tensor,
  1081. scale_growth_factor: _float,
  1082. scale_backoff_factor: _float,
  1083. growth_interval: _int,
  1084. ) -> Tensor: ...
  1085. @overload
  1086. def _assert_async(input: Tensor) -> None:
  1087. r"""
  1088. _assert_async(tensor) -> void
  1089. Asynchronously assert that the contents of tensor are nonzero. For CPU tensors,
  1090. this is equivalent to ``assert tensor`` or ``assert tensor.is_nonzero()``; for
  1091. CUDA tensors, we DO NOT synchronize and you may only find out the assertion
  1092. failed at a later CUDA kernel launch. Asynchronous assertion can be helpful for
  1093. testing invariants in CUDA tensors without giving up performance. This function
  1094. is NOT intended to be used for regular error checking, as it will trash your CUDA
  1095. context if the assert fails (forcing you to restart your PyTorch process.)
  1096. Args:
  1097. tensor (Tensor): a one element tensor to test to see if it is nonzero. Zero
  1098. elements (including False for boolean tensors) cause an assertion failure
  1099. to be raised.
  1100. """
  1101. @overload
  1102. def _assert_async(input: Tensor, assert_msg: str) -> None:
  1103. r"""
  1104. _assert_async(tensor) -> void
  1105. Asynchronously assert that the contents of tensor are nonzero. For CPU tensors,
  1106. this is equivalent to ``assert tensor`` or ``assert tensor.is_nonzero()``; for
  1107. CUDA tensors, we DO NOT synchronize and you may only find out the assertion
  1108. failed at a later CUDA kernel launch. Asynchronous assertion can be helpful for
  1109. testing invariants in CUDA tensors without giving up performance. This function
  1110. is NOT intended to be used for regular error checking, as it will trash your CUDA
  1111. context if the assert fails (forcing you to restart your PyTorch process.)
  1112. Args:
  1113. tensor (Tensor): a one element tensor to test to see if it is nonzero. Zero
  1114. elements (including False for boolean tensors) cause an assertion failure
  1115. to be raised.
  1116. """
  1117. def _assert_scalar(self: Number | _complex, assert_msg: str) -> None: ...
  1118. def _assert_tensor_metadata(
  1119. a: Tensor,
  1120. size: Sequence[_int | SymInt] | None = None,
  1121. stride: Sequence[_int | SymInt] | None = None,
  1122. dtype: _dtype | None = None,
  1123. *,
  1124. device: DeviceLikeType | None = None,
  1125. layout: _layout | None = None,
  1126. ) -> None: ...
  1127. def _batch_norm_impl_index(
  1128. input: Tensor,
  1129. weight: Tensor | None,
  1130. bias: Tensor | None,
  1131. running_mean: Tensor | None,
  1132. running_var: Tensor | None,
  1133. training: _bool,
  1134. momentum: _float,
  1135. eps: _float,
  1136. cudnn_enabled: _bool,
  1137. ) -> tuple[Tensor, Tensor, Tensor, Tensor, _int]: ...
  1138. def _cast_Byte(input: Tensor, non_blocking: _bool = False) -> Tensor: ...
  1139. def _cast_Char(input: Tensor, non_blocking: _bool = False) -> Tensor: ...
  1140. def _cast_Double(input: Tensor, non_blocking: _bool = False) -> Tensor: ...
  1141. def _cast_Float(input: Tensor, non_blocking: _bool = False) -> Tensor: ...
  1142. def _cast_Half(input: Tensor, non_blocking: _bool = False) -> Tensor: ...
  1143. def _cast_Int(input: Tensor, non_blocking: _bool = False) -> Tensor: ...
  1144. def _cast_Long(input: Tensor, non_blocking: _bool = False) -> Tensor: ...
  1145. def _cast_Short(input: Tensor, non_blocking: _bool = False) -> Tensor: ...
  1146. def _choose_qparams_per_tensor(
  1147. input: Tensor,
  1148. reduce_range: _bool = False,
  1149. ) -> tuple[_float, _int]: ...
  1150. def _chunk_cat(
  1151. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  1152. dim: _int,
  1153. num_chunks: _int,
  1154. *,
  1155. out: Tensor | None = None,
  1156. ) -> Tensor: ...
  1157. def _coalesce(input: Tensor) -> Tensor: ...
  1158. def _compute_linear_combination(
  1159. input: Tensor,
  1160. coefficients: Tensor,
  1161. *,
  1162. out: Tensor | None = None,
  1163. ) -> Tensor: ...
  1164. def _conj(input: Tensor) -> Tensor: ...
  1165. def _conj_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor: ...
  1166. def _conj_physical(input: Tensor) -> Tensor: ...
  1167. def _convert_indices_from_coo_to_csr(
  1168. input: Tensor,
  1169. size: _int,
  1170. *,
  1171. out_int32: _bool = False,
  1172. out: Tensor | None = None,
  1173. ) -> Tensor: ...
  1174. def _convert_indices_from_csr_to_coo(
  1175. crow_indices: Tensor,
  1176. col_indices: Tensor,
  1177. *,
  1178. out_int32: _bool = False,
  1179. transpose: _bool = False,
  1180. out: Tensor | None = None,
  1181. ) -> Tensor: ...
  1182. def _convert_weight_to_int4pack(input: Tensor, innerKTiles: _int) -> Tensor: ...
  1183. def _convert_weight_to_int4pack_for_cpu(
  1184. input: Tensor,
  1185. innerKTiles: _int,
  1186. ) -> Tensor: ...
  1187. @overload
  1188. def _convolution(
  1189. input: Tensor,
  1190. weight: Tensor,
  1191. bias: Tensor | None,
  1192. stride: Sequence[_int | SymInt],
  1193. padding: Sequence[_int | SymInt],
  1194. dilation: Sequence[_int | SymInt],
  1195. transposed: _bool,
  1196. output_padding: _size,
  1197. groups: _int | SymInt,
  1198. benchmark: _bool,
  1199. deterministic: _bool,
  1200. cudnn_enabled: _bool,
  1201. ) -> Tensor: ...
  1202. @overload
  1203. def _convolution(
  1204. input: Tensor,
  1205. weight: Tensor,
  1206. bias: Tensor | None,
  1207. stride: Sequence[_int | SymInt],
  1208. padding: Sequence[_int | SymInt],
  1209. dilation: Sequence[_int | SymInt],
  1210. transposed: _bool,
  1211. output_padding: Sequence[_int | SymInt],
  1212. groups: _int | SymInt,
  1213. benchmark: _bool,
  1214. deterministic: _bool,
  1215. cudnn_enabled: _bool,
  1216. allow_tf32: _bool,
  1217. ) -> Tensor: ...
  1218. def _convolution_mode(
  1219. input: Tensor,
  1220. weight: Tensor,
  1221. bias: Tensor | None,
  1222. stride: Sequence[_int | SymInt],
  1223. padding: str,
  1224. dilation: Sequence[_int | SymInt],
  1225. groups: _int | SymInt,
  1226. ) -> Tensor: ...
  1227. def _copy_from(
  1228. input: Tensor,
  1229. dst: Tensor,
  1230. non_blocking: _bool = False,
  1231. ) -> Tensor: ...
  1232. def _copy_from_and_resize(input: Tensor, dst: Tensor) -> Tensor: ...
  1233. def _cslt_compress(input: Tensor) -> Tensor: ...
  1234. def _cslt_sparse_mm(
  1235. compressed_A: Tensor,
  1236. dense_B: Tensor,
  1237. bias: Tensor | None = None,
  1238. alpha: Tensor | None = None,
  1239. out_dtype: _dtype | None = None,
  1240. transpose_result: _bool = False,
  1241. alg_id: _int = 0,
  1242. split_k: _int = 1,
  1243. split_k_mode: _int = -1,
  1244. ) -> Tensor: ...
  1245. def _cslt_sparse_mm_search(
  1246. compressed_A: Tensor,
  1247. dense_B: Tensor,
  1248. bias: Tensor | None = None,
  1249. alpha: Tensor | None = None,
  1250. out_dtype: _dtype | None = None,
  1251. transpose_result: _bool = False,
  1252. ) -> _int: ...
  1253. @overload
  1254. def _ctc_loss(
  1255. log_probs: Tensor,
  1256. targets: Tensor,
  1257. input_lengths: _size,
  1258. target_lengths: _size,
  1259. blank: _int = 0,
  1260. zero_infinity: _bool = False,
  1261. ) -> tuple[Tensor, Tensor]: ...
  1262. @overload
  1263. def _ctc_loss(
  1264. log_probs: Tensor,
  1265. targets: Tensor,
  1266. input_lengths: Tensor,
  1267. target_lengths: Tensor,
  1268. blank: _int = 0,
  1269. zero_infinity: _bool = False,
  1270. ) -> tuple[Tensor, Tensor]: ...
  1271. @overload
  1272. def _cudnn_ctc_loss(
  1273. log_probs: Tensor,
  1274. targets: Tensor,
  1275. input_lengths: _size,
  1276. target_lengths: _size,
  1277. blank: _int,
  1278. deterministic: _bool,
  1279. zero_infinity: _bool,
  1280. ) -> tuple[Tensor, Tensor]: ...
  1281. @overload
  1282. def _cudnn_ctc_loss(
  1283. log_probs: Tensor,
  1284. targets: Tensor,
  1285. input_lengths: Tensor,
  1286. target_lengths: Tensor,
  1287. blank: _int,
  1288. deterministic: _bool,
  1289. zero_infinity: _bool,
  1290. ) -> tuple[Tensor, Tensor]: ...
  1291. def _cudnn_init_dropout_state(
  1292. dropout: _float,
  1293. train: _bool,
  1294. dropout_seed: _int,
  1295. *,
  1296. dtype: _dtype | None = None,
  1297. layout: _layout | None = None,
  1298. device: DeviceLikeType | None = None,
  1299. pin_memory: _bool | None = False,
  1300. requires_grad: _bool | None = False,
  1301. ) -> Tensor: ...
  1302. def _cudnn_rnn(
  1303. input: Tensor,
  1304. weight: tuple[Tensor, ...] | list[Tensor] | None,
  1305. weight_stride0: _int,
  1306. weight_buf: Tensor | None,
  1307. hx: Tensor,
  1308. cx: Tensor | None,
  1309. mode: _int,
  1310. hidden_size: _int | SymInt,
  1311. proj_size: _int | SymInt,
  1312. num_layers: _int,
  1313. batch_first: _bool,
  1314. dropout: _float,
  1315. train: _bool,
  1316. bidirectional: _bool,
  1317. batch_sizes: Sequence[_int | SymInt],
  1318. dropout_state: Tensor | None,
  1319. ) -> tuple[Tensor, Tensor, Tensor, Tensor, Tensor]: ...
  1320. def _cudnn_rnn_flatten_weight(
  1321. weight_arr: tuple[Tensor, ...] | list[Tensor] | None,
  1322. weight_stride0: _int,
  1323. input_size: _int | SymInt,
  1324. mode: _int,
  1325. hidden_size: _int | SymInt,
  1326. proj_size: _int | SymInt,
  1327. num_layers: _int,
  1328. batch_first: _bool,
  1329. bidirectional: _bool,
  1330. ) -> Tensor: ...
  1331. def _cufft_clear_plan_cache(device_index: _int) -> None: ...
  1332. def _cufft_get_plan_cache_max_size(device_index: _int) -> _int: ...
  1333. def _cufft_get_plan_cache_size(device_index: _int) -> _int: ...
  1334. def _cufft_set_plan_cache_max_size(
  1335. device_index: _int,
  1336. max_size: _int,
  1337. ) -> None: ...
  1338. def _cummax_helper(
  1339. input: Tensor,
  1340. values: Tensor,
  1341. indices: Tensor,
  1342. dim: _int,
  1343. ) -> None: ...
  1344. def _cummin_helper(
  1345. input: Tensor,
  1346. values: Tensor,
  1347. indices: Tensor,
  1348. dim: _int,
  1349. ) -> None: ...
  1350. def _debug_has_internal_overlap(input: Tensor) -> _int: ...
  1351. def _dim_arange(like: Tensor, dim: _int) -> Tensor: ...
  1352. def _dirichlet_grad(x: Tensor, alpha: Tensor, total: Tensor) -> Tensor: ...
  1353. def _disable_functionalization(): ...
  1354. def _dyn_quant_matmul_4bit(
  1355. inp: Tensor,
  1356. packed_weights: Tensor,
  1357. block_size: _int,
  1358. in_features: _int,
  1359. out_features: _int,
  1360. ) -> Tensor: ...
  1361. def _dyn_quant_pack_4bit_weight(
  1362. weights: Tensor,
  1363. scales_zeros: Tensor,
  1364. bias: Tensor | None,
  1365. block_size: _int,
  1366. in_features: _int,
  1367. out_features: _int,
  1368. ) -> Tensor: ...
  1369. @overload
  1370. def _efficientzerotensor(
  1371. size: Sequence[_int | SymInt],
  1372. *,
  1373. dtype: _dtype | None = None,
  1374. layout: _layout | None = None,
  1375. device: DeviceLikeType | None = None,
  1376. pin_memory: _bool | None = False,
  1377. requires_grad: _bool | None = False,
  1378. ) -> Tensor: ...
  1379. @overload
  1380. def _efficientzerotensor(
  1381. *size: _int | SymInt,
  1382. dtype: _dtype | None = None,
  1383. layout: _layout | None = None,
  1384. device: DeviceLikeType | None = None,
  1385. pin_memory: _bool | None = False,
  1386. requires_grad: _bool | None = False,
  1387. ) -> Tensor: ...
  1388. def _embedding_bag(
  1389. weight: Tensor,
  1390. indices: Tensor,
  1391. offsets: Tensor,
  1392. scale_grad_by_freq: _bool = False,
  1393. mode: _int = 0,
  1394. sparse: _bool = False,
  1395. per_sample_weights: Tensor | None = None,
  1396. include_last_offset: _bool = False,
  1397. padding_idx: _int = -1,
  1398. ) -> tuple[Tensor, Tensor, Tensor, Tensor]: ...
  1399. def _embedding_bag_forward_only(
  1400. weight: Tensor,
  1401. indices: Tensor,
  1402. offsets: Tensor,
  1403. scale_grad_by_freq: _bool = False,
  1404. mode: _int = 0,
  1405. sparse: _bool = False,
  1406. per_sample_weights: Tensor | None = None,
  1407. include_last_offset: _bool = False,
  1408. padding_idx: _int = -1,
  1409. ) -> tuple[Tensor, Tensor, Tensor, Tensor]: ...
  1410. @overload
  1411. def _empty_affine_quantized(
  1412. size: Sequence[_int | SymInt],
  1413. *,
  1414. scale: _float = 1,
  1415. zero_point: _int = 0,
  1416. memory_format: memory_format | None = contiguous_format,
  1417. dtype: _dtype | None = None,
  1418. layout: _layout | None = None,
  1419. device: DeviceLikeType | None = None,
  1420. pin_memory: _bool | None = False,
  1421. requires_grad: _bool | None = False,
  1422. ) -> Tensor: ...
  1423. @overload
  1424. def _empty_affine_quantized(
  1425. *size: _int | SymInt,
  1426. scale: _float = 1,
  1427. zero_point: _int = 0,
  1428. memory_format: memory_format | None = contiguous_format,
  1429. dtype: _dtype | None = None,
  1430. layout: _layout | None = None,
  1431. device: DeviceLikeType | None = None,
  1432. pin_memory: _bool | None = False,
  1433. requires_grad: _bool | None = False,
  1434. ) -> Tensor: ...
  1435. @overload
  1436. def _empty_per_channel_affine_quantized(
  1437. size: Sequence[_int | SymInt],
  1438. *,
  1439. scales: Tensor,
  1440. zero_points: Tensor,
  1441. axis: _int,
  1442. memory_format: memory_format | None = contiguous_format,
  1443. dtype: _dtype | None = None,
  1444. layout: _layout | None = None,
  1445. device: DeviceLikeType | None = None,
  1446. pin_memory: _bool | None = False,
  1447. requires_grad: _bool | None = False,
  1448. ) -> Tensor: ...
  1449. @overload
  1450. def _empty_per_channel_affine_quantized(
  1451. *size: _int | SymInt,
  1452. scales: Tensor,
  1453. zero_points: Tensor,
  1454. axis: _int,
  1455. memory_format: memory_format | None = contiguous_format,
  1456. dtype: _dtype | None = None,
  1457. layout: _layout | None = None,
  1458. device: DeviceLikeType | None = None,
  1459. pin_memory: _bool | None = False,
  1460. requires_grad: _bool | None = False,
  1461. ) -> Tensor: ...
  1462. def _enable_functionalization(*, reapply_views: _bool = False) -> None: ...
  1463. def _euclidean_dist(x1: Tensor, x2: Tensor) -> Tensor: ...
  1464. def _fake_quantize_learnable_per_channel_affine(
  1465. input: Tensor,
  1466. scale: Tensor,
  1467. zero_point: Tensor,
  1468. axis: _int,
  1469. quant_min: _int,
  1470. quant_max: _int,
  1471. grad_factor: _float = 1.0,
  1472. ) -> Tensor: ...
  1473. def _fake_quantize_learnable_per_tensor_affine(
  1474. input: Tensor,
  1475. scale: Tensor,
  1476. zero_point: Tensor,
  1477. quant_min: _int,
  1478. quant_max: _int,
  1479. grad_factor: _float = 1.0,
  1480. ) -> Tensor: ...
  1481. def _fake_quantize_per_tensor_affine_cachemask_tensor_qparams(
  1482. input: Tensor,
  1483. scale: Tensor,
  1484. zero_point: Tensor,
  1485. fake_quant_enabled: Tensor,
  1486. quant_min: _int,
  1487. quant_max: _int,
  1488. ) -> torch.return_types._fake_quantize_per_tensor_affine_cachemask_tensor_qparams: # fmt: skip
  1489. ...
  1490. def _fft_c2c(
  1491. input: Tensor,
  1492. dim: Sequence[_int | SymInt],
  1493. normalization: _int,
  1494. forward: _bool,
  1495. *,
  1496. out: Tensor | None = None,
  1497. ) -> Tensor: ...
  1498. def _fft_c2r(
  1499. input: Tensor,
  1500. dim: _size,
  1501. normalization: _int,
  1502. last_dim_size: _int | SymInt,
  1503. *,
  1504. out: Tensor | None = None,
  1505. ) -> Tensor: ...
  1506. def _fft_r2c(
  1507. input: Tensor,
  1508. dim: _size,
  1509. normalization: _int,
  1510. onesided: _bool,
  1511. *,
  1512. out: Tensor | None = None,
  1513. ) -> Tensor: ...
  1514. def _fill_mem_eff_dropout_mask_(
  1515. input: Tensor,
  1516. dropout_p: _float,
  1517. seed: _int,
  1518. offset: _int,
  1519. ) -> Tensor: ...
  1520. def _foobar(
  1521. input: Tensor,
  1522. arg1: _bool = True,
  1523. arg2: _bool = True,
  1524. *,
  1525. arg3: _bool = True,
  1526. ) -> Tensor: ...
  1527. def _foreach_abs(
  1528. self: tuple[Tensor, ...] | list[Tensor] | None,
  1529. ) -> tuple[Tensor, ...]:
  1530. r"""
  1531. _foreach_abs(self: List[Tensor]) -> List[Tensor]
  1532. Apply :func:`torch.abs` to each Tensor of the input list.
  1533. """
  1534. def _foreach_abs_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1535. r"""
  1536. _foreach_abs_(self: List[Tensor]) -> None
  1537. Apply :func:`torch.abs` to each Tensor of the input list.
  1538. """
  1539. def _foreach_acos(
  1540. self: tuple[Tensor, ...] | list[Tensor] | None,
  1541. ) -> tuple[Tensor, ...]:
  1542. r"""
  1543. _foreach_acos(self: List[Tensor]) -> List[Tensor]
  1544. Apply :func:`torch.acos` to each Tensor of the input list.
  1545. """
  1546. def _foreach_acos_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1547. r"""
  1548. _foreach_acos_(self: List[Tensor]) -> None
  1549. Apply :func:`torch.acos` to each Tensor of the input list.
  1550. """
  1551. @overload
  1552. def _foreach_add(
  1553. self: tuple[Tensor, ...] | list[Tensor] | None,
  1554. scalars: Sequence[Number | _complex],
  1555. ) -> tuple[Tensor, ...]: ...
  1556. @overload
  1557. def _foreach_add(
  1558. self: tuple[Tensor, ...] | list[Tensor] | None,
  1559. other: tuple[Tensor, ...] | list[Tensor] | None,
  1560. *,
  1561. alpha: Number | _complex = 1,
  1562. ) -> tuple[Tensor, ...]: ...
  1563. @overload
  1564. def _foreach_add(
  1565. self: tuple[Tensor, ...] | list[Tensor] | None,
  1566. other: Tensor,
  1567. *,
  1568. alpha: Number | _complex = 1,
  1569. ) -> tuple[Tensor, ...]: ...
  1570. @overload
  1571. def _foreach_add(
  1572. self: tuple[Tensor, ...] | list[Tensor] | None,
  1573. scalar: Number | _complex,
  1574. ) -> tuple[Tensor, ...]: ...
  1575. @overload
  1576. def _foreach_add_(
  1577. self: tuple[Tensor, ...] | list[Tensor] | None,
  1578. scalars: Sequence[Number | _complex],
  1579. ) -> None: ...
  1580. @overload
  1581. def _foreach_add_(
  1582. self: tuple[Tensor, ...] | list[Tensor] | None,
  1583. other: tuple[Tensor, ...] | list[Tensor] | None,
  1584. *,
  1585. alpha: Number | _complex = 1,
  1586. ) -> None: ...
  1587. @overload
  1588. def _foreach_add_(
  1589. self: tuple[Tensor, ...] | list[Tensor] | None,
  1590. other: Tensor,
  1591. *,
  1592. alpha: Number | _complex = 1,
  1593. ) -> None: ...
  1594. @overload
  1595. def _foreach_add_(
  1596. self: tuple[Tensor, ...] | list[Tensor] | None,
  1597. scalar: Number | _complex,
  1598. ) -> None: ...
  1599. @overload
  1600. def _foreach_addcdiv(
  1601. self: tuple[Tensor, ...] | list[Tensor] | None,
  1602. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1603. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1604. scalars: Sequence[Number | _complex],
  1605. ) -> tuple[Tensor, ...]: ...
  1606. @overload
  1607. def _foreach_addcdiv(
  1608. self: tuple[Tensor, ...] | list[Tensor] | None,
  1609. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1610. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1611. scalars: Tensor,
  1612. ) -> tuple[Tensor, ...]: ...
  1613. @overload
  1614. def _foreach_addcdiv(
  1615. self: tuple[Tensor, ...] | list[Tensor] | None,
  1616. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1617. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1618. value: Number | _complex = 1,
  1619. ) -> tuple[Tensor, ...]: ...
  1620. @overload
  1621. def _foreach_addcdiv_(
  1622. self: tuple[Tensor, ...] | list[Tensor] | None,
  1623. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1624. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1625. scalars: Sequence[Number | _complex],
  1626. ) -> None: ...
  1627. @overload
  1628. def _foreach_addcdiv_(
  1629. self: tuple[Tensor, ...] | list[Tensor] | None,
  1630. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1631. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1632. scalars: Tensor,
  1633. ) -> None: ...
  1634. @overload
  1635. def _foreach_addcdiv_(
  1636. self: tuple[Tensor, ...] | list[Tensor] | None,
  1637. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1638. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1639. value: Number | _complex = 1,
  1640. ) -> None: ...
  1641. @overload
  1642. def _foreach_addcmul(
  1643. self: tuple[Tensor, ...] | list[Tensor] | None,
  1644. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1645. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1646. scalars: Sequence[Number | _complex],
  1647. ) -> tuple[Tensor, ...]: ...
  1648. @overload
  1649. def _foreach_addcmul(
  1650. self: tuple[Tensor, ...] | list[Tensor] | None,
  1651. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1652. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1653. scalars: Tensor,
  1654. ) -> tuple[Tensor, ...]: ...
  1655. @overload
  1656. def _foreach_addcmul(
  1657. self: tuple[Tensor, ...] | list[Tensor] | None,
  1658. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1659. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1660. value: Number | _complex = 1,
  1661. ) -> tuple[Tensor, ...]: ...
  1662. @overload
  1663. def _foreach_addcmul_(
  1664. self: tuple[Tensor, ...] | list[Tensor] | None,
  1665. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1666. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1667. scalars: Sequence[Number | _complex],
  1668. ) -> None: ...
  1669. @overload
  1670. def _foreach_addcmul_(
  1671. self: tuple[Tensor, ...] | list[Tensor] | None,
  1672. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1673. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1674. scalars: Tensor,
  1675. ) -> None: ...
  1676. @overload
  1677. def _foreach_addcmul_(
  1678. self: tuple[Tensor, ...] | list[Tensor] | None,
  1679. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1680. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1681. value: Number | _complex = 1,
  1682. ) -> None: ...
  1683. def _foreach_asin(
  1684. self: tuple[Tensor, ...] | list[Tensor] | None,
  1685. ) -> tuple[Tensor, ...]:
  1686. r"""
  1687. _foreach_asin(self: List[Tensor]) -> List[Tensor]
  1688. Apply :func:`torch.asin` to each Tensor of the input list.
  1689. """
  1690. def _foreach_asin_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1691. r"""
  1692. _foreach_asin_(self: List[Tensor]) -> None
  1693. Apply :func:`torch.asin` to each Tensor of the input list.
  1694. """
  1695. def _foreach_atan(
  1696. self: tuple[Tensor, ...] | list[Tensor] | None,
  1697. ) -> tuple[Tensor, ...]:
  1698. r"""
  1699. _foreach_atan(self: List[Tensor]) -> List[Tensor]
  1700. Apply :func:`torch.atan` to each Tensor of the input list.
  1701. """
  1702. def _foreach_atan_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1703. r"""
  1704. _foreach_atan_(self: List[Tensor]) -> None
  1705. Apply :func:`torch.atan` to each Tensor of the input list.
  1706. """
  1707. def _foreach_ceil(
  1708. self: tuple[Tensor, ...] | list[Tensor] | None,
  1709. ) -> tuple[Tensor, ...]:
  1710. r"""
  1711. _foreach_ceil(self: List[Tensor]) -> List[Tensor]
  1712. Apply :func:`torch.ceil` to each Tensor of the input list.
  1713. """
  1714. def _foreach_ceil_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1715. r"""
  1716. _foreach_ceil_(self: List[Tensor]) -> None
  1717. Apply :func:`torch.ceil` to each Tensor of the input list.
  1718. """
  1719. @overload
  1720. def _foreach_clamp_max(
  1721. self: tuple[Tensor, ...] | list[Tensor] | None,
  1722. scalars: Sequence[Number | _complex],
  1723. ) -> tuple[Tensor, ...]: ...
  1724. @overload
  1725. def _foreach_clamp_max(
  1726. self: tuple[Tensor, ...] | list[Tensor] | None,
  1727. scalar: Number | _complex,
  1728. ) -> tuple[Tensor, ...]: ...
  1729. @overload
  1730. def _foreach_clamp_max(
  1731. self: tuple[Tensor, ...] | list[Tensor] | None,
  1732. other: tuple[Tensor, ...] | list[Tensor] | None,
  1733. ) -> tuple[Tensor, ...]: ...
  1734. @overload
  1735. def _foreach_clamp_max_(
  1736. self: tuple[Tensor, ...] | list[Tensor] | None,
  1737. scalars: Sequence[Number | _complex],
  1738. ) -> None: ...
  1739. @overload
  1740. def _foreach_clamp_max_(
  1741. self: tuple[Tensor, ...] | list[Tensor] | None,
  1742. scalar: Number | _complex,
  1743. ) -> None: ...
  1744. @overload
  1745. def _foreach_clamp_max_(
  1746. self: tuple[Tensor, ...] | list[Tensor] | None,
  1747. other: tuple[Tensor, ...] | list[Tensor] | None,
  1748. ) -> None: ...
  1749. @overload
  1750. def _foreach_clamp_min(
  1751. self: tuple[Tensor, ...] | list[Tensor] | None,
  1752. scalars: Sequence[Number | _complex],
  1753. ) -> tuple[Tensor, ...]: ...
  1754. @overload
  1755. def _foreach_clamp_min(
  1756. self: tuple[Tensor, ...] | list[Tensor] | None,
  1757. scalar: Number | _complex,
  1758. ) -> tuple[Tensor, ...]: ...
  1759. @overload
  1760. def _foreach_clamp_min(
  1761. self: tuple[Tensor, ...] | list[Tensor] | None,
  1762. other: tuple[Tensor, ...] | list[Tensor] | None,
  1763. ) -> tuple[Tensor, ...]: ...
  1764. @overload
  1765. def _foreach_clamp_min_(
  1766. self: tuple[Tensor, ...] | list[Tensor] | None,
  1767. scalars: Sequence[Number | _complex],
  1768. ) -> None: ...
  1769. @overload
  1770. def _foreach_clamp_min_(
  1771. self: tuple[Tensor, ...] | list[Tensor] | None,
  1772. scalar: Number | _complex,
  1773. ) -> None: ...
  1774. @overload
  1775. def _foreach_clamp_min_(
  1776. self: tuple[Tensor, ...] | list[Tensor] | None,
  1777. other: tuple[Tensor, ...] | list[Tensor] | None,
  1778. ) -> None: ...
  1779. def _foreach_copy_(
  1780. self: tuple[Tensor, ...] | list[Tensor] | None,
  1781. src: tuple[Tensor, ...] | list[Tensor] | None,
  1782. non_blocking: _bool = False,
  1783. ) -> None: ...
  1784. def _foreach_cos(
  1785. self: tuple[Tensor, ...] | list[Tensor] | None,
  1786. ) -> tuple[Tensor, ...]:
  1787. r"""
  1788. _foreach_cos(self: List[Tensor]) -> List[Tensor]
  1789. Apply :func:`torch.cos` to each Tensor of the input list.
  1790. """
  1791. def _foreach_cos_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1792. r"""
  1793. _foreach_cos_(self: List[Tensor]) -> None
  1794. Apply :func:`torch.cos` to each Tensor of the input list.
  1795. """
  1796. def _foreach_cosh(
  1797. self: tuple[Tensor, ...] | list[Tensor] | None,
  1798. ) -> tuple[Tensor, ...]:
  1799. r"""
  1800. _foreach_cosh(self: List[Tensor]) -> List[Tensor]
  1801. Apply :func:`torch.cosh` to each Tensor of the input list.
  1802. """
  1803. def _foreach_cosh_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1804. r"""
  1805. _foreach_cosh_(self: List[Tensor]) -> None
  1806. Apply :func:`torch.cosh` to each Tensor of the input list.
  1807. """
  1808. @overload
  1809. def _foreach_div(
  1810. self: tuple[Tensor, ...] | list[Tensor] | None,
  1811. scalars: Sequence[Number | _complex],
  1812. ) -> tuple[Tensor, ...]: ...
  1813. @overload
  1814. def _foreach_div(
  1815. self: tuple[Tensor, ...] | list[Tensor] | None,
  1816. other: Tensor,
  1817. ) -> tuple[Tensor, ...]: ...
  1818. @overload
  1819. def _foreach_div(
  1820. self: tuple[Tensor, ...] | list[Tensor] | None,
  1821. scalar: Number | _complex,
  1822. ) -> tuple[Tensor, ...]: ...
  1823. @overload
  1824. def _foreach_div(
  1825. self: tuple[Tensor, ...] | list[Tensor] | None,
  1826. other: tuple[Tensor, ...] | list[Tensor] | None,
  1827. ) -> tuple[Tensor, ...]: ...
  1828. @overload
  1829. def _foreach_div_(
  1830. self: tuple[Tensor, ...] | list[Tensor] | None,
  1831. scalars: Sequence[Number | _complex],
  1832. ) -> None: ...
  1833. @overload
  1834. def _foreach_div_(
  1835. self: tuple[Tensor, ...] | list[Tensor] | None,
  1836. other: Tensor,
  1837. ) -> None: ...
  1838. @overload
  1839. def _foreach_div_(
  1840. self: tuple[Tensor, ...] | list[Tensor] | None,
  1841. scalar: Number | _complex,
  1842. ) -> None: ...
  1843. @overload
  1844. def _foreach_div_(
  1845. self: tuple[Tensor, ...] | list[Tensor] | None,
  1846. other: tuple[Tensor, ...] | list[Tensor] | None,
  1847. ) -> None: ...
  1848. def _foreach_erf(
  1849. self: tuple[Tensor, ...] | list[Tensor] | None,
  1850. ) -> tuple[Tensor, ...]:
  1851. r"""
  1852. _foreach_erf(self: List[Tensor]) -> List[Tensor]
  1853. Apply :func:`torch.erf` to each Tensor of the input list.
  1854. """
  1855. def _foreach_erf_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1856. r"""
  1857. _foreach_erf_(self: List[Tensor]) -> None
  1858. Apply :func:`torch.erf` to each Tensor of the input list.
  1859. """
  1860. def _foreach_erfc(
  1861. self: tuple[Tensor, ...] | list[Tensor] | None,
  1862. ) -> tuple[Tensor, ...]:
  1863. r"""
  1864. _foreach_erfc(self: List[Tensor]) -> List[Tensor]
  1865. Apply :func:`torch.erfc` to each Tensor of the input list.
  1866. """
  1867. def _foreach_erfc_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1868. r"""
  1869. _foreach_erfc_(self: List[Tensor]) -> None
  1870. Apply :func:`torch.erfc` to each Tensor of the input list.
  1871. """
  1872. def _foreach_exp(
  1873. self: tuple[Tensor, ...] | list[Tensor] | None,
  1874. ) -> tuple[Tensor, ...]:
  1875. r"""
  1876. _foreach_exp(self: List[Tensor]) -> List[Tensor]
  1877. Apply :func:`torch.exp` to each Tensor of the input list.
  1878. """
  1879. def _foreach_exp_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1880. r"""
  1881. _foreach_exp_(self: List[Tensor]) -> None
  1882. Apply :func:`torch.exp` to each Tensor of the input list.
  1883. """
  1884. def _foreach_expm1(
  1885. self: tuple[Tensor, ...] | list[Tensor] | None,
  1886. ) -> tuple[Tensor, ...]:
  1887. r"""
  1888. _foreach_expm1(self: List[Tensor]) -> List[Tensor]
  1889. Apply :func:`torch.expm1` to each Tensor of the input list.
  1890. """
  1891. def _foreach_expm1_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1892. r"""
  1893. _foreach_expm1_(self: List[Tensor]) -> None
  1894. Apply :func:`torch.expm1` to each Tensor of the input list.
  1895. """
  1896. def _foreach_floor(
  1897. self: tuple[Tensor, ...] | list[Tensor] | None,
  1898. ) -> tuple[Tensor, ...]:
  1899. r"""
  1900. _foreach_floor(self: List[Tensor]) -> List[Tensor]
  1901. Apply :func:`torch.floor` to each Tensor of the input list.
  1902. """
  1903. def _foreach_floor_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1904. r"""
  1905. _foreach_floor_(self: List[Tensor]) -> None
  1906. Apply :func:`torch.floor` to each Tensor of the input list.
  1907. """
  1908. def _foreach_frac(
  1909. self: tuple[Tensor, ...] | list[Tensor] | None,
  1910. ) -> tuple[Tensor, ...]:
  1911. r"""
  1912. _foreach_frac(self: List[Tensor]) -> List[Tensor]
  1913. Apply :func:`torch.frac` to each Tensor of the input list.
  1914. """
  1915. def _foreach_frac_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1916. r"""
  1917. _foreach_frac_(self: List[Tensor]) -> None
  1918. Apply :func:`torch.frac` to each Tensor of the input list.
  1919. """
  1920. @overload
  1921. def _foreach_lerp(
  1922. self: tuple[Tensor, ...] | list[Tensor] | None,
  1923. tensors1: tuple[Tensor, ...] | list[Tensor] | None,
  1924. weight: Number | _complex,
  1925. ) -> tuple[Tensor, ...]: ...
  1926. @overload
  1927. def _foreach_lerp(
  1928. self: tuple[Tensor, ...] | list[Tensor] | None,
  1929. tensors1: tuple[Tensor, ...] | list[Tensor] | None,
  1930. weight: Sequence[Number | _complex],
  1931. ) -> tuple[Tensor, ...]: ...
  1932. @overload
  1933. def _foreach_lerp(
  1934. self: tuple[Tensor, ...] | list[Tensor] | None,
  1935. tensors1: tuple[Tensor, ...] | list[Tensor] | None,
  1936. weights: tuple[Tensor, ...] | list[Tensor] | None,
  1937. ) -> tuple[Tensor, ...]: ...
  1938. @overload
  1939. def _foreach_lerp_(
  1940. self: tuple[Tensor, ...] | list[Tensor] | None,
  1941. tensors1: tuple[Tensor, ...] | list[Tensor] | None,
  1942. weight: Number | _complex,
  1943. ) -> None: ...
  1944. @overload
  1945. def _foreach_lerp_(
  1946. self: tuple[Tensor, ...] | list[Tensor] | None,
  1947. tensors1: tuple[Tensor, ...] | list[Tensor] | None,
  1948. weight: Sequence[Number | _complex],
  1949. ) -> None: ...
  1950. @overload
  1951. def _foreach_lerp_(
  1952. self: tuple[Tensor, ...] | list[Tensor] | None,
  1953. tensors1: tuple[Tensor, ...] | list[Tensor] | None,
  1954. weights: tuple[Tensor, ...] | list[Tensor] | None,
  1955. ) -> None: ...
  1956. def _foreach_lgamma(
  1957. self: tuple[Tensor, ...] | list[Tensor] | None,
  1958. ) -> tuple[Tensor, ...]:
  1959. r"""
  1960. _foreach_lgamma(self: List[Tensor]) -> List[Tensor]
  1961. Apply :func:`torch.lgamma` to each Tensor of the input list.
  1962. """
  1963. def _foreach_lgamma_(
  1964. self: tuple[Tensor, ...] | list[Tensor] | None,
  1965. ) -> None:
  1966. r"""
  1967. _foreach_lgamma_(self: List[Tensor]) -> None
  1968. Apply :func:`torch.lgamma` to each Tensor of the input list.
  1969. """
  1970. def _foreach_log(
  1971. self: tuple[Tensor, ...] | list[Tensor] | None,
  1972. ) -> tuple[Tensor, ...]:
  1973. r"""
  1974. _foreach_log(self: List[Tensor]) -> List[Tensor]
  1975. Apply :func:`torch.log` to each Tensor of the input list.
  1976. """
  1977. def _foreach_log10(
  1978. self: tuple[Tensor, ...] | list[Tensor] | None,
  1979. ) -> tuple[Tensor, ...]:
  1980. r"""
  1981. _foreach_log10(self: List[Tensor]) -> List[Tensor]
  1982. Apply :func:`torch.log10` to each Tensor of the input list.
  1983. """
  1984. def _foreach_log10_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1985. r"""
  1986. _foreach_log10_(self: List[Tensor]) -> None
  1987. Apply :func:`torch.log10` to each Tensor of the input list.
  1988. """
  1989. def _foreach_log1p(
  1990. self: tuple[Tensor, ...] | list[Tensor] | None,
  1991. ) -> tuple[Tensor, ...]:
  1992. r"""
  1993. _foreach_log1p(self: List[Tensor]) -> List[Tensor]
  1994. Apply :func:`torch.log1p` to each Tensor of the input list.
  1995. """
  1996. def _foreach_log1p_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1997. r"""
  1998. _foreach_log1p_(self: List[Tensor]) -> None
  1999. Apply :func:`torch.log1p` to each Tensor of the input list.
  2000. """
  2001. def _foreach_log2(
  2002. self: tuple[Tensor, ...] | list[Tensor] | None,
  2003. ) -> tuple[Tensor, ...]:
  2004. r"""
  2005. _foreach_log2(self: List[Tensor]) -> List[Tensor]
  2006. Apply :func:`torch.log2` to each Tensor of the input list.
  2007. """
  2008. def _foreach_log2_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2009. r"""
  2010. _foreach_log2_(self: List[Tensor]) -> None
  2011. Apply :func:`torch.log2` to each Tensor of the input list.
  2012. """
  2013. def _foreach_log_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2014. r"""
  2015. _foreach_log_(self: List[Tensor]) -> None
  2016. Apply :func:`torch.log` to each Tensor of the input list.
  2017. """
  2018. def _foreach_max(
  2019. self: tuple[Tensor, ...] | list[Tensor] | None,
  2020. ) -> tuple[Tensor, ...]: ...
  2021. @overload
  2022. def _foreach_maximum(
  2023. self: tuple[Tensor, ...] | list[Tensor] | None,
  2024. scalars: Sequence[Number | _complex],
  2025. ) -> tuple[Tensor, ...]: ...
  2026. @overload
  2027. def _foreach_maximum(
  2028. self: tuple[Tensor, ...] | list[Tensor] | None,
  2029. scalar: Number | _complex,
  2030. ) -> tuple[Tensor, ...]: ...
  2031. @overload
  2032. def _foreach_maximum(
  2033. self: tuple[Tensor, ...] | list[Tensor] | None,
  2034. other: tuple[Tensor, ...] | list[Tensor] | None,
  2035. ) -> tuple[Tensor, ...]: ...
  2036. @overload
  2037. def _foreach_maximum_(
  2038. self: tuple[Tensor, ...] | list[Tensor] | None,
  2039. scalars: Sequence[Number | _complex],
  2040. ) -> None: ...
  2041. @overload
  2042. def _foreach_maximum_(
  2043. self: tuple[Tensor, ...] | list[Tensor] | None,
  2044. scalar: Number | _complex,
  2045. ) -> None: ...
  2046. @overload
  2047. def _foreach_maximum_(
  2048. self: tuple[Tensor, ...] | list[Tensor] | None,
  2049. other: tuple[Tensor, ...] | list[Tensor] | None,
  2050. ) -> None: ...
  2051. @overload
  2052. def _foreach_minimum(
  2053. self: tuple[Tensor, ...] | list[Tensor] | None,
  2054. scalars: Sequence[Number | _complex],
  2055. ) -> tuple[Tensor, ...]: ...
  2056. @overload
  2057. def _foreach_minimum(
  2058. self: tuple[Tensor, ...] | list[Tensor] | None,
  2059. scalar: Number | _complex,
  2060. ) -> tuple[Tensor, ...]: ...
  2061. @overload
  2062. def _foreach_minimum(
  2063. self: tuple[Tensor, ...] | list[Tensor] | None,
  2064. other: tuple[Tensor, ...] | list[Tensor] | None,
  2065. ) -> tuple[Tensor, ...]: ...
  2066. @overload
  2067. def _foreach_minimum_(
  2068. self: tuple[Tensor, ...] | list[Tensor] | None,
  2069. scalars: Sequence[Number | _complex],
  2070. ) -> None: ...
  2071. @overload
  2072. def _foreach_minimum_(
  2073. self: tuple[Tensor, ...] | list[Tensor] | None,
  2074. scalar: Number | _complex,
  2075. ) -> None: ...
  2076. @overload
  2077. def _foreach_minimum_(
  2078. self: tuple[Tensor, ...] | list[Tensor] | None,
  2079. other: tuple[Tensor, ...] | list[Tensor] | None,
  2080. ) -> None: ...
  2081. @overload
  2082. def _foreach_mul(
  2083. self: tuple[Tensor, ...] | list[Tensor] | None,
  2084. scalars: Sequence[Number | _complex],
  2085. ) -> tuple[Tensor, ...]: ...
  2086. @overload
  2087. def _foreach_mul(
  2088. self: tuple[Tensor, ...] | list[Tensor] | None,
  2089. other: Tensor,
  2090. ) -> tuple[Tensor, ...]: ...
  2091. @overload
  2092. def _foreach_mul(
  2093. self: tuple[Tensor, ...] | list[Tensor] | None,
  2094. scalar: Number | _complex,
  2095. ) -> tuple[Tensor, ...]: ...
  2096. @overload
  2097. def _foreach_mul(
  2098. self: tuple[Tensor, ...] | list[Tensor] | None,
  2099. other: tuple[Tensor, ...] | list[Tensor] | None,
  2100. ) -> tuple[Tensor, ...]: ...
  2101. @overload
  2102. def _foreach_mul_(
  2103. self: tuple[Tensor, ...] | list[Tensor] | None,
  2104. scalars: Sequence[Number | _complex],
  2105. ) -> None: ...
  2106. @overload
  2107. def _foreach_mul_(
  2108. self: tuple[Tensor, ...] | list[Tensor] | None,
  2109. other: Tensor,
  2110. ) -> None: ...
  2111. @overload
  2112. def _foreach_mul_(
  2113. self: tuple[Tensor, ...] | list[Tensor] | None,
  2114. scalar: Number | _complex,
  2115. ) -> None: ...
  2116. @overload
  2117. def _foreach_mul_(
  2118. self: tuple[Tensor, ...] | list[Tensor] | None,
  2119. other: tuple[Tensor, ...] | list[Tensor] | None,
  2120. ) -> None: ...
  2121. def _foreach_neg(
  2122. self: tuple[Tensor, ...] | list[Tensor] | None,
  2123. ) -> tuple[Tensor, ...]:
  2124. r"""
  2125. _foreach_neg(self: List[Tensor]) -> List[Tensor]
  2126. Apply :func:`torch.neg` to each Tensor of the input list.
  2127. """
  2128. def _foreach_neg_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2129. r"""
  2130. _foreach_neg_(self: List[Tensor]) -> None
  2131. Apply :func:`torch.neg` to each Tensor of the input list.
  2132. """
  2133. def _foreach_norm(
  2134. self: tuple[Tensor, ...] | list[Tensor] | None,
  2135. ord: Number | _complex = 2,
  2136. dtype: _dtype | None = None,
  2137. ) -> tuple[Tensor, ...]: ...
  2138. @overload
  2139. def _foreach_pow(
  2140. self: tuple[Tensor, ...] | list[Tensor] | None,
  2141. exponent: Sequence[Number | _complex],
  2142. ) -> tuple[Tensor, ...]: ...
  2143. @overload
  2144. def _foreach_pow(
  2145. self: tuple[Tensor, ...] | list[Tensor] | None,
  2146. exponent: Number | _complex,
  2147. ) -> tuple[Tensor, ...]: ...
  2148. @overload
  2149. def _foreach_pow(
  2150. self: tuple[Tensor, ...] | list[Tensor] | None,
  2151. exponent: tuple[Tensor, ...] | list[Tensor] | None,
  2152. ) -> tuple[Tensor, ...]: ...
  2153. @overload
  2154. def _foreach_pow(
  2155. self: Number | _complex,
  2156. exponent: tuple[Tensor, ...] | list[Tensor] | None,
  2157. ) -> tuple[Tensor, ...]: ...
  2158. @overload
  2159. def _foreach_pow_(
  2160. self: tuple[Tensor, ...] | list[Tensor] | None,
  2161. exponent: Sequence[Number | _complex],
  2162. ) -> None: ...
  2163. @overload
  2164. def _foreach_pow_(
  2165. self: tuple[Tensor, ...] | list[Tensor] | None,
  2166. exponent: Number | _complex,
  2167. ) -> None: ...
  2168. @overload
  2169. def _foreach_pow_(
  2170. self: tuple[Tensor, ...] | list[Tensor] | None,
  2171. exponent: tuple[Tensor, ...] | list[Tensor] | None,
  2172. ) -> None: ...
  2173. def _foreach_reciprocal(
  2174. self: tuple[Tensor, ...] | list[Tensor] | None,
  2175. ) -> tuple[Tensor, ...]:
  2176. r"""
  2177. _foreach_reciprocal(self: List[Tensor]) -> List[Tensor]
  2178. Apply :func:`torch.reciprocal` to each Tensor of the input list.
  2179. """
  2180. def _foreach_reciprocal_(
  2181. self: tuple[Tensor, ...] | list[Tensor] | None,
  2182. ) -> None:
  2183. r"""
  2184. _foreach_reciprocal_(self: List[Tensor]) -> None
  2185. Apply :func:`torch.reciprocal` to each Tensor of the input list.
  2186. """
  2187. def _foreach_round(
  2188. self: tuple[Tensor, ...] | list[Tensor] | None,
  2189. ) -> tuple[Tensor, ...]:
  2190. r"""
  2191. _foreach_round(self: List[Tensor]) -> List[Tensor]
  2192. Apply :func:`torch.round` to each Tensor of the input list.
  2193. """
  2194. def _foreach_round_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2195. r"""
  2196. _foreach_round_(self: List[Tensor]) -> None
  2197. Apply :func:`torch.round` to each Tensor of the input list.
  2198. """
  2199. def _foreach_rsqrt(
  2200. self: tuple[Tensor, ...] | list[Tensor] | None,
  2201. ) -> tuple[Tensor, ...]: ...
  2202. def _foreach_rsqrt_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None: ...
  2203. def _foreach_sigmoid(
  2204. self: tuple[Tensor, ...] | list[Tensor] | None,
  2205. ) -> tuple[Tensor, ...]:
  2206. r"""
  2207. _foreach_sigmoid(self: List[Tensor]) -> List[Tensor]
  2208. Apply :func:`torch.sigmoid` to each Tensor of the input list.
  2209. """
  2210. def _foreach_sigmoid_(
  2211. self: tuple[Tensor, ...] | list[Tensor] | None,
  2212. ) -> None:
  2213. r"""
  2214. _foreach_sigmoid_(self: List[Tensor]) -> None
  2215. Apply :func:`torch.sigmoid` to each Tensor of the input list.
  2216. """
  2217. def _foreach_sign(
  2218. self: tuple[Tensor, ...] | list[Tensor] | None,
  2219. ) -> tuple[Tensor, ...]: ...
  2220. def _foreach_sign_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None: ...
  2221. def _foreach_sin(
  2222. self: tuple[Tensor, ...] | list[Tensor] | None,
  2223. ) -> tuple[Tensor, ...]:
  2224. r"""
  2225. _foreach_sin(self: List[Tensor]) -> List[Tensor]
  2226. Apply :func:`torch.sin` to each Tensor of the input list.
  2227. """
  2228. def _foreach_sin_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2229. r"""
  2230. _foreach_sin_(self: List[Tensor]) -> None
  2231. Apply :func:`torch.sin` to each Tensor of the input list.
  2232. """
  2233. def _foreach_sinh(
  2234. self: tuple[Tensor, ...] | list[Tensor] | None,
  2235. ) -> tuple[Tensor, ...]:
  2236. r"""
  2237. _foreach_sinh(self: List[Tensor]) -> List[Tensor]
  2238. Apply :func:`torch.sinh` to each Tensor of the input list.
  2239. """
  2240. def _foreach_sinh_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2241. r"""
  2242. _foreach_sinh_(self: List[Tensor]) -> None
  2243. Apply :func:`torch.sinh` to each Tensor of the input list.
  2244. """
  2245. def _foreach_sqrt(
  2246. self: tuple[Tensor, ...] | list[Tensor] | None,
  2247. ) -> tuple[Tensor, ...]:
  2248. r"""
  2249. _foreach_sqrt(self: List[Tensor]) -> List[Tensor]
  2250. Apply :func:`torch.sqrt` to each Tensor of the input list.
  2251. """
  2252. def _foreach_sqrt_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2253. r"""
  2254. _foreach_sqrt_(self: List[Tensor]) -> None
  2255. Apply :func:`torch.sqrt` to each Tensor of the input list.
  2256. """
  2257. @overload
  2258. def _foreach_sub(
  2259. self: tuple[Tensor, ...] | list[Tensor] | None,
  2260. scalars: Sequence[Number | _complex],
  2261. ) -> tuple[Tensor, ...]: ...
  2262. @overload
  2263. def _foreach_sub(
  2264. self: tuple[Tensor, ...] | list[Tensor] | None,
  2265. other: tuple[Tensor, ...] | list[Tensor] | None,
  2266. *,
  2267. alpha: Number | _complex = 1,
  2268. ) -> tuple[Tensor, ...]: ...
  2269. @overload
  2270. def _foreach_sub(
  2271. self: tuple[Tensor, ...] | list[Tensor] | None,
  2272. scalar: Number | _complex,
  2273. ) -> tuple[Tensor, ...]: ...
  2274. @overload
  2275. def _foreach_sub_(
  2276. self: tuple[Tensor, ...] | list[Tensor] | None,
  2277. scalars: Sequence[Number | _complex],
  2278. ) -> None: ...
  2279. @overload
  2280. def _foreach_sub_(
  2281. self: tuple[Tensor, ...] | list[Tensor] | None,
  2282. other: tuple[Tensor, ...] | list[Tensor] | None,
  2283. *,
  2284. alpha: Number | _complex = 1,
  2285. ) -> None: ...
  2286. @overload
  2287. def _foreach_sub_(
  2288. self: tuple[Tensor, ...] | list[Tensor] | None,
  2289. scalar: Number | _complex,
  2290. ) -> None: ...
  2291. def _foreach_tan(
  2292. self: tuple[Tensor, ...] | list[Tensor] | None,
  2293. ) -> tuple[Tensor, ...]:
  2294. r"""
  2295. _foreach_tan(self: List[Tensor]) -> List[Tensor]
  2296. Apply :func:`torch.tan` to each Tensor of the input list.
  2297. """
  2298. def _foreach_tan_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2299. r"""
  2300. _foreach_tan_(self: List[Tensor]) -> None
  2301. Apply :func:`torch.tan` to each Tensor of the input list.
  2302. """
  2303. def _foreach_tanh(
  2304. self: tuple[Tensor, ...] | list[Tensor] | None,
  2305. ) -> tuple[Tensor, ...]:
  2306. r"""
  2307. _foreach_tanh(self: List[Tensor]) -> List[Tensor]
  2308. Apply :func:`torch.tanh` to each Tensor of the input list.
  2309. """
  2310. def _foreach_tanh_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2311. r"""
  2312. _foreach_tanh_(self: List[Tensor]) -> None
  2313. Apply :func:`torch.tanh` to each Tensor of the input list.
  2314. """
  2315. def _foreach_trunc(
  2316. self: tuple[Tensor, ...] | list[Tensor] | None,
  2317. ) -> tuple[Tensor, ...]:
  2318. r"""
  2319. _foreach_trunc(self: List[Tensor]) -> List[Tensor]
  2320. Apply :func:`torch.trunc` to each Tensor of the input list.
  2321. """
  2322. def _foreach_trunc_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2323. r"""
  2324. _foreach_trunc_(self: List[Tensor]) -> None
  2325. Apply :func:`torch.trunc` to each Tensor of the input list.
  2326. """
  2327. def _foreach_zero_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2328. r"""
  2329. _foreach_zero_(self: List[Tensor]) -> None
  2330. Apply :func:`torch.zero` to each Tensor of the input list.
  2331. """
  2332. def _from_functional_tensor(t: Tensor) -> Tensor: ...
  2333. def _functional_assert_async(
  2334. input: Tensor,
  2335. assert_msg: str,
  2336. dep_token: Tensor,
  2337. ) -> Tensor: ...
  2338. def _functional_assert_scalar(
  2339. self: Number | _complex,
  2340. assert_msg: str,
  2341. dep_token: Tensor,
  2342. ) -> Tensor: ...
  2343. def _functional_sym_constrain_range(
  2344. size: Number | _complex,
  2345. min: _int | None,
  2346. max: _int | None,
  2347. dep_token: Tensor,
  2348. ) -> Tensor: ...
  2349. def _functional_sym_constrain_range_for_size(
  2350. size: Number | _complex,
  2351. min: _int | None,
  2352. max: _int | None,
  2353. dep_token: Tensor,
  2354. ) -> Tensor: ...
  2355. def _functionalize_apply_view_metas(tensor: Tensor, base: Tensor) -> Tensor: ...
  2356. def _functionalize_are_all_mutations_hidden_from_autograd(
  2357. t: Tensor,
  2358. ) -> _bool: ...
  2359. def _functionalize_are_all_mutations_under_no_grad_or_inference_mode(
  2360. t: Tensor,
  2361. ) -> _bool: ...
  2362. def _functionalize_commit_update(t: Tensor) -> None: ...
  2363. def _functionalize_has_metadata_mutation(tensor: Tensor) -> _bool: ...
  2364. def _functionalize_inductor_storage_resized_counter(t: Tensor) -> _int: ...
  2365. def _functionalize_is_symbolic(tensor: Tensor) -> _bool: ...
  2366. def _functionalize_mark_mutation_hidden_from_autograd(t: Tensor) -> None: ...
  2367. def _functionalize_mark_storage_changed(tensor: Tensor) -> _bool: ...
  2368. def _functionalize_mutation_counter(t: Tensor) -> _int: ...
  2369. def _functionalize_replace(self_: Tensor, other: Tensor) -> None: ...
  2370. def _functionalize_storage_changed_counter(t: Tensor) -> _int: ...
  2371. def _functionalize_sync(t: Tensor) -> None: ...
  2372. def _functionalize_unsafe_set(dst: Tensor, src: Tensor) -> None: ...
  2373. def _functionalize_was_inductor_storage_resized(t: Tensor) -> _bool: ...
  2374. def _functionalize_was_storage_changed(tensor: Tensor) -> _bool: ...
  2375. @overload
  2376. def _fused_adagrad_(
  2377. self: tuple[Tensor, ...] | list[Tensor] | None,
  2378. grads: tuple[Tensor, ...] | list[Tensor] | None,
  2379. state_sums: tuple[Tensor, ...] | list[Tensor] | None,
  2380. state_steps: tuple[Tensor, ...] | list[Tensor] | None,
  2381. *,
  2382. lr: Tensor,
  2383. lr_decay: _float,
  2384. weight_decay: _float,
  2385. eps: _float,
  2386. maximize: _bool,
  2387. grad_scale: Tensor | None = None,
  2388. found_inf: Tensor | None = None,
  2389. ) -> None: ...
  2390. @overload
  2391. def _fused_adagrad_(
  2392. self: tuple[Tensor, ...] | list[Tensor] | None,
  2393. grads: tuple[Tensor, ...] | list[Tensor] | None,
  2394. state_sums: tuple[Tensor, ...] | list[Tensor] | None,
  2395. state_steps: tuple[Tensor, ...] | list[Tensor] | None,
  2396. *,
  2397. lr: _float,
  2398. lr_decay: _float,
  2399. weight_decay: _float,
  2400. eps: _float,
  2401. maximize: _bool,
  2402. grad_scale: Tensor | None = None,
  2403. found_inf: Tensor | None = None,
  2404. ) -> None: ...
  2405. @overload
  2406. def _fused_adam_(
  2407. self: tuple[Tensor, ...] | list[Tensor] | None,
  2408. grads: tuple[Tensor, ...] | list[Tensor] | None,
  2409. exp_avgs: tuple[Tensor, ...] | list[Tensor] | None,
  2410. exp_avg_sqs: tuple[Tensor, ...] | list[Tensor] | None,
  2411. max_exp_avg_sqs: tuple[Tensor, ...] | list[Tensor] | None,
  2412. state_steps: tuple[Tensor, ...] | list[Tensor] | None,
  2413. *,
  2414. lr: Tensor,
  2415. beta1: _float,
  2416. beta2: _float,
  2417. weight_decay: _float,
  2418. eps: _float,
  2419. amsgrad: _bool,
  2420. maximize: _bool,
  2421. grad_scale: Tensor | None = None,
  2422. found_inf: Tensor | None = None,
  2423. ) -> None: ...
  2424. @overload
  2425. def _fused_adam_(
  2426. self: tuple[Tensor, ...] | list[Tensor] | None,
  2427. grads: tuple[Tensor, ...] | list[Tensor] | None,
  2428. exp_avgs: tuple[Tensor, ...] | list[Tensor] | None,
  2429. exp_avg_sqs: tuple[Tensor, ...] | list[Tensor] | None,
  2430. max_exp_avg_sqs: tuple[Tensor, ...] | list[Tensor] | None,
  2431. state_steps: tuple[Tensor, ...] | list[Tensor] | None,
  2432. *,
  2433. lr: _float,
  2434. beta1: _float,
  2435. beta2: _float,
  2436. weight_decay: _float,
  2437. eps: _float,
  2438. amsgrad: _bool,
  2439. maximize: _bool,
  2440. grad_scale: Tensor | None = None,
  2441. found_inf: Tensor | None = None,
  2442. ) -> None: ...
  2443. @overload
  2444. def _fused_adamw_(
  2445. self: tuple[Tensor, ...] | list[Tensor] | None,
  2446. grads: tuple[Tensor, ...] | list[Tensor] | None,
  2447. exp_avgs: tuple[Tensor, ...] | list[Tensor] | None,
  2448. exp_avg_sqs: tuple[Tensor, ...] | list[Tensor] | None,
  2449. max_exp_avg_sqs: tuple[Tensor, ...] | list[Tensor] | None,
  2450. state_steps: tuple[Tensor, ...] | list[Tensor] | None,
  2451. *,
  2452. lr: Tensor,
  2453. beta1: _float,
  2454. beta2: _float,
  2455. weight_decay: _float,
  2456. eps: _float,
  2457. amsgrad: _bool,
  2458. maximize: _bool,
  2459. grad_scale: Tensor | None = None,
  2460. found_inf: Tensor | None = None,
  2461. ) -> None: ...
  2462. @overload
  2463. def _fused_adamw_(
  2464. self: tuple[Tensor, ...] | list[Tensor] | None,
  2465. grads: tuple[Tensor, ...] | list[Tensor] | None,
  2466. exp_avgs: tuple[Tensor, ...] | list[Tensor] | None,
  2467. exp_avg_sqs: tuple[Tensor, ...] | list[Tensor] | None,
  2468. max_exp_avg_sqs: tuple[Tensor, ...] | list[Tensor] | None,
  2469. state_steps: tuple[Tensor, ...] | list[Tensor] | None,
  2470. *,
  2471. lr: _float,
  2472. beta1: _float,
  2473. beta2: _float,
  2474. weight_decay: _float,
  2475. eps: _float,
  2476. amsgrad: _bool,
  2477. maximize: _bool,
  2478. grad_scale: Tensor | None = None,
  2479. found_inf: Tensor | None = None,
  2480. ) -> None: ...
  2481. def _fused_dropout(
  2482. input: Tensor,
  2483. p: _float,
  2484. generator: Generator | None = None,
  2485. ) -> tuple[Tensor, Tensor]: ...
  2486. def _fused_moving_avg_obs_fq_helper(
  2487. input: Tensor,
  2488. observer_on: Tensor,
  2489. fake_quant_on: Tensor,
  2490. running_min: Tensor,
  2491. running_max: Tensor,
  2492. scale: Tensor,
  2493. zero_point: Tensor,
  2494. averaging_const: _float,
  2495. quant_min: _int,
  2496. quant_max: _int,
  2497. ch_axis: _int,
  2498. per_row_fake_quant: _bool = False,
  2499. symmetric_quant: _bool = False,
  2500. ) -> torch.return_types._fused_moving_avg_obs_fq_helper: ...
  2501. def _fused_rms_norm(
  2502. input: Tensor,
  2503. normalized_shape: _size,
  2504. weight: Tensor | None,
  2505. eps: _float | None,
  2506. ) -> tuple[Tensor, Tensor]: ...
  2507. def _fused_sdp_choice(
  2508. query: Tensor,
  2509. key: Tensor,
  2510. value: Tensor,
  2511. attn_mask: Tensor | None = None,
  2512. dropout_p: _float = 0.0,
  2513. is_causal: _bool = False,
  2514. *,
  2515. scale: _float | None = None,
  2516. enable_gqa: _bool = False,
  2517. ) -> _int: ...
  2518. @overload
  2519. def _fused_sgd_(
  2520. self: tuple[Tensor, ...] | list[Tensor] | None,
  2521. grads: tuple[Tensor, ...] | list[Tensor] | None,
  2522. momentum_buffer_list: tuple[Tensor, ...] | list[Tensor] | None,
  2523. *,
  2524. weight_decay: _float,
  2525. momentum: _float,
  2526. lr: Tensor,
  2527. dampening: _float,
  2528. nesterov: _bool,
  2529. maximize: _bool,
  2530. is_first_step: _bool,
  2531. grad_scale: Tensor | None = None,
  2532. found_inf: Tensor | None = None,
  2533. ) -> None: ...
  2534. @overload
  2535. def _fused_sgd_(
  2536. self: tuple[Tensor, ...] | list[Tensor] | None,
  2537. grads: tuple[Tensor, ...] | list[Tensor] | None,
  2538. momentum_buffer_list: tuple[Tensor, ...] | list[Tensor] | None,
  2539. *,
  2540. weight_decay: _float,
  2541. momentum: _float,
  2542. lr: _float,
  2543. dampening: _float,
  2544. nesterov: _bool,
  2545. maximize: _bool,
  2546. is_first_step: _bool,
  2547. grad_scale: Tensor | None = None,
  2548. found_inf: Tensor | None = None,
  2549. ) -> None: ...
  2550. def _fw_primal_copy(
  2551. input: Tensor,
  2552. level: _int,
  2553. *,
  2554. out: Tensor | None = None,
  2555. ) -> Tensor: ...
  2556. def _grid_sampler_2d_cpu_fallback(
  2557. input: Tensor,
  2558. grid: Tensor,
  2559. interpolation_mode: _int,
  2560. padding_mode: _int,
  2561. align_corners: _bool,
  2562. ) -> Tensor: ...
  2563. def _grouped_mm(
  2564. input: Tensor,
  2565. mat2: Tensor,
  2566. offs: Tensor | None = None,
  2567. bias: Tensor | None = None,
  2568. out_dtype: _dtype | None = None,
  2569. ) -> Tensor: ...
  2570. def _has_compatible_shallow_copy_type(
  2571. input: Tensor,
  2572. from_: Tensor,
  2573. ) -> _bool: ...
  2574. def _histogramdd_bin_edges(
  2575. input: Tensor,
  2576. bins: _size,
  2577. *,
  2578. range: Sequence[_float] | None = None,
  2579. weight: Tensor | None = None,
  2580. density: _bool = False,
  2581. ) -> tuple[Tensor, ...]: ...
  2582. def _histogramdd_from_bin_cts(
  2583. input: Tensor,
  2584. bins: _size,
  2585. *,
  2586. range: Sequence[_float] | None = None,
  2587. weight: Tensor | None = None,
  2588. density: _bool = False,
  2589. ) -> Tensor: ...
  2590. def _histogramdd_from_bin_tensors(
  2591. input: Tensor,
  2592. bins: tuple[Tensor, ...] | list[Tensor] | None,
  2593. *,
  2594. weight: Tensor | None = None,
  2595. density: _bool = False,
  2596. ) -> Tensor: ...
  2597. def _index_put_impl_(
  2598. input: Tensor,
  2599. indices: tuple[Tensor, ...] | list[Tensor] | None,
  2600. values: Tensor,
  2601. accumulate: _bool = False,
  2602. unsafe: _bool = False,
  2603. ) -> Tensor: ...
  2604. def _indices_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor: ...
  2605. def _int_mm(
  2606. input: Tensor,
  2607. mat2: Tensor,
  2608. *,
  2609. out: Tensor | None = None,
  2610. ) -> Tensor: ...
  2611. def _is_all_true(input: Tensor) -> Tensor: ...
  2612. def _is_any_true(input: Tensor) -> Tensor: ...
  2613. def _is_functional_tensor(t: Tensor) -> _bool: ...
  2614. def _is_functional_tensor_base(t: Tensor) -> _bool: ...
  2615. def _is_zerotensor(input: Tensor) -> _bool: ...
  2616. def _lazy_clone(input: Tensor) -> Tensor: ...
  2617. def _linalg_check_errors(
  2618. info: Tensor,
  2619. api_name: str,
  2620. *,
  2621. is_matrix: _bool,
  2622. ) -> None: ...
  2623. def _linalg_det(
  2624. A: Tensor,
  2625. *,
  2626. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  2627. ) -> torch.return_types._linalg_det: ...
  2628. def _linalg_eigh(
  2629. A: Tensor,
  2630. UPLO: str = "L",
  2631. compute_v: _bool = True,
  2632. *,
  2633. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  2634. ) -> torch.return_types._linalg_eigh: ...
  2635. def _linalg_slogdet(
  2636. A: Tensor,
  2637. *,
  2638. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  2639. ) -> torch.return_types._linalg_slogdet: ...
  2640. def _linalg_solve_ex(
  2641. A: Tensor,
  2642. B: Tensor,
  2643. *,
  2644. left: _bool = True,
  2645. check_errors: _bool = False,
  2646. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  2647. ) -> torch.return_types._linalg_solve_ex: ...
  2648. def _linalg_svd(
  2649. A: Tensor,
  2650. full_matrices: _bool = False,
  2651. compute_uv: _bool = True,
  2652. *,
  2653. driver: str | None = None,
  2654. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  2655. ) -> torch.return_types._linalg_svd: ...
  2656. def _log_softmax(
  2657. input: Tensor,
  2658. dim: _int,
  2659. half_to_float: _bool,
  2660. *,
  2661. out: Tensor | None = None,
  2662. ) -> Tensor: ...
  2663. def _log_softmax_backward_data(
  2664. grad_output: Tensor,
  2665. output: Tensor,
  2666. dim: _int,
  2667. input_dtype: _dtype,
  2668. *,
  2669. out: Tensor | None = None,
  2670. ) -> Tensor: ...
  2671. def _logcumsumexp(
  2672. input: Tensor,
  2673. dim: _int,
  2674. *,
  2675. out: Tensor | None = None,
  2676. ) -> Tensor: ...
  2677. def _lstm_mps(
  2678. input: Tensor,
  2679. hx: tuple[Tensor, ...] | list[Tensor] | None,
  2680. params: tuple[Tensor, ...] | list[Tensor] | None,
  2681. has_biases: _bool,
  2682. num_layers: _int,
  2683. dropout: _float,
  2684. train: _bool,
  2685. bidirectional: _bool,
  2686. batch_first: _bool,
  2687. ) -> tuple[Tensor, Tensor, Tensor, Tensor, Tensor, Tensor]: ...
  2688. def _lu_with_info(
  2689. input: Tensor,
  2690. pivot: _bool = True,
  2691. check_errors: _bool = True,
  2692. ) -> torch.return_types._lu_with_info: ...
  2693. def _make_dep_token(
  2694. *,
  2695. memory_format: memory_format | None = None,
  2696. dtype: _dtype | None = None,
  2697. layout: _layout | None = None,
  2698. device: DeviceLikeType | None = None,
  2699. pin_memory: _bool | None = False,
  2700. requires_grad: _bool | None = False,
  2701. ) -> Tensor: ...
  2702. def _make_dual(primal: Tensor, tangent: Tensor, level: _int) -> Tensor: ...
  2703. def _make_dual_copy(
  2704. primal: Tensor,
  2705. tangent: Tensor,
  2706. level: _int,
  2707. *,
  2708. out: Tensor | None = None,
  2709. ) -> Tensor: ...
  2710. def _make_per_channel_quantized_tensor(
  2711. input: Tensor,
  2712. scale: Tensor,
  2713. zero_point: Tensor,
  2714. axis: _int,
  2715. ) -> Tensor: ...
  2716. def _make_per_tensor_quantized_tensor(
  2717. input: Tensor,
  2718. scale: _float,
  2719. zero_point: _int,
  2720. ) -> Tensor: ...
  2721. def _masked_scale(input: Tensor, mask: Tensor, scale: _float) -> Tensor: ...
  2722. def _masked_softmax(
  2723. input: Tensor,
  2724. mask: Tensor,
  2725. dim: _int | None = None,
  2726. mask_type: _int | None = None,
  2727. ) -> Tensor: ...
  2728. def _mixed_dtypes_linear(
  2729. input: Tensor,
  2730. weight: Tensor,
  2731. scale: Tensor,
  2732. *,
  2733. bias: Tensor | None = None,
  2734. activation: str | None = None,
  2735. ) -> Tensor: ...
  2736. def _mkldnn_reshape(input: Tensor, shape: _size) -> Tensor: ...
  2737. def _mkldnn_transpose(input: Tensor, dim0: _int, dim1: _int) -> Tensor: ...
  2738. def _mkldnn_transpose_(input: Tensor, dim0: _int, dim1: _int) -> Tensor: ...
  2739. def _mps_convolution(
  2740. input: Tensor,
  2741. weight: Tensor,
  2742. bias: Tensor | None,
  2743. padding: Sequence[_int | SymInt],
  2744. stride: Sequence[_int | SymInt],
  2745. dilation: Sequence[_int | SymInt],
  2746. groups: _int | SymInt,
  2747. ) -> Tensor: ...
  2748. def _mps_convolution_transpose(
  2749. input: Tensor,
  2750. weight: Tensor,
  2751. padding: Sequence[_int | SymInt],
  2752. output_padding: Sequence[_int | SymInt],
  2753. stride: Sequence[_int | SymInt],
  2754. dilation: Sequence[_int | SymInt],
  2755. groups: _int | SymInt,
  2756. ) -> Tensor: ...
  2757. @overload
  2758. def _native_batch_norm_legit(
  2759. input: Tensor,
  2760. weight: Tensor | None,
  2761. bias: Tensor | None,
  2762. running_mean: Tensor,
  2763. running_var: Tensor,
  2764. training: _bool,
  2765. momentum: _float,
  2766. eps: _float,
  2767. *,
  2768. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  2769. ) -> tuple[Tensor, Tensor, Tensor]: ...
  2770. @overload
  2771. def _native_batch_norm_legit(
  2772. input: Tensor,
  2773. weight: Tensor | None,
  2774. bias: Tensor | None,
  2775. training: _bool,
  2776. momentum: _float,
  2777. eps: _float,
  2778. *,
  2779. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  2780. ) -> tuple[Tensor, Tensor, Tensor]: ...
  2781. def _native_batch_norm_legit_no_training(
  2782. input: Tensor,
  2783. weight: Tensor | None,
  2784. bias: Tensor | None,
  2785. running_mean: Tensor,
  2786. running_var: Tensor,
  2787. momentum: _float,
  2788. eps: _float,
  2789. ) -> tuple[Tensor, Tensor, Tensor]: ...
  2790. def _native_multi_head_attention(
  2791. query: Tensor,
  2792. key: Tensor,
  2793. value: Tensor,
  2794. embed_dim: _int,
  2795. num_head: _int,
  2796. qkv_weight: Tensor,
  2797. qkv_bias: Tensor,
  2798. proj_weight: Tensor,
  2799. proj_bias: Tensor,
  2800. mask: Tensor | None = None,
  2801. need_weights: _bool = True,
  2802. average_attn_weights: _bool = True,
  2803. mask_type: _int | None = None,
  2804. ) -> tuple[Tensor, Tensor]: ...
  2805. def _neg_view(input: Tensor) -> Tensor: ...
  2806. def _neg_view_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor: ...
  2807. def _nested_compute_contiguous_strides_offsets(
  2808. nested_size: Tensor,
  2809. ) -> tuple[Tensor, Tensor]: ...
  2810. def _nested_from_padded(
  2811. padded: Tensor,
  2812. cpu_nested_shape_example: Tensor,
  2813. fuse_transform_0213: _bool = False,
  2814. ) -> Tensor: ...
  2815. def _nested_from_padded_and_nested_example(
  2816. padded: Tensor,
  2817. nt_example: Tensor,
  2818. ) -> Tensor: ...
  2819. def _nested_from_padded_tensor(
  2820. padded: Tensor,
  2821. offsets: Tensor,
  2822. dummy: Tensor,
  2823. ragged_idx: _int = 1,
  2824. min_seqlen: Tensor | None = None,
  2825. max_seqlen: Tensor | None = None,
  2826. sum_S: _int | SymInt | None = None,
  2827. ) -> Tensor: ...
  2828. def _nested_get_jagged_dummy(any: Tensor) -> Tensor: ...
  2829. def _nested_get_lengths(input: Tensor) -> Tensor: ...
  2830. def _nested_get_max_seqlen(input: Tensor) -> Tensor: ...
  2831. def _nested_get_min_seqlen(input: Tensor) -> Tensor: ...
  2832. def _nested_get_offsets(input: Tensor) -> Tensor: ...
  2833. def _nested_get_ragged_idx(input: Tensor) -> _int: ...
  2834. def _nested_get_values(input: Tensor) -> Tensor: ...
  2835. def _nested_get_values_copy(
  2836. input: Tensor,
  2837. *,
  2838. out: Tensor | None = None,
  2839. ) -> Tensor: ...
  2840. def _nested_tensor_from_mask(
  2841. t: Tensor,
  2842. mask: Tensor,
  2843. mask_check: _bool = True,
  2844. ) -> Tensor: ...
  2845. def _nested_tensor_from_mask_left_aligned(t: Tensor, mask: Tensor) -> _bool: ...
  2846. def _nested_tensor_from_tensor_list(
  2847. list: tuple[Tensor, ...] | list[Tensor] | None,
  2848. dtype: _dtype | None = None,
  2849. layout: _layout | None = None,
  2850. device: DeviceLikeType | None = None,
  2851. pin_memory: _bool | None = None,
  2852. ) -> Tensor: ...
  2853. def _nested_tensor_softmax_with_shape(
  2854. input: Tensor,
  2855. query: Tensor,
  2856. ) -> Tensor: ...
  2857. def _nested_view_from_buffer(
  2858. input: Tensor,
  2859. nested_size: Tensor,
  2860. nested_strides: Tensor,
  2861. offsets: Tensor,
  2862. ) -> Tensor: ...
  2863. def _nested_view_from_buffer_copy(
  2864. input: Tensor,
  2865. nested_size: Tensor,
  2866. nested_strides: Tensor,
  2867. offsets: Tensor,
  2868. *,
  2869. out: Tensor | None = None,
  2870. ) -> Tensor: ...
  2871. def _nested_view_from_jagged(
  2872. input: Tensor,
  2873. offsets: Tensor,
  2874. dummy: Tensor,
  2875. lengths: Tensor | None = None,
  2876. ragged_idx: _int = 1,
  2877. min_seqlen: Tensor | None = None,
  2878. max_seqlen: Tensor | None = None,
  2879. ) -> Tensor: ...
  2880. def _nested_view_from_jagged_copy(
  2881. input: Tensor,
  2882. offsets: Tensor,
  2883. dummy: Tensor,
  2884. lengths: Tensor | None = None,
  2885. ragged_idx: _int = 1,
  2886. min_seqlen: Tensor | None = None,
  2887. max_seqlen: Tensor | None = None,
  2888. *,
  2889. out: Tensor | None = None,
  2890. ) -> Tensor: ...
  2891. def _nnpack_available() -> _bool: ...
  2892. def _nnpack_spatial_convolution(
  2893. input: Tensor,
  2894. weight: Tensor,
  2895. bias: Tensor | None,
  2896. padding: _int | SymInt | Sequence[_int | SymInt],
  2897. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  2898. ) -> Tensor: ...
  2899. def _pack_padded_sequence(
  2900. input: Tensor,
  2901. lengths: Tensor,
  2902. batch_first: _bool,
  2903. ) -> tuple[Tensor, Tensor]: ...
  2904. def _pad_packed_sequence(
  2905. data: Tensor,
  2906. batch_sizes: Tensor,
  2907. batch_first: _bool,
  2908. padding_value: Number | _complex,
  2909. total_length: _int,
  2910. ) -> tuple[Tensor, Tensor]: ...
  2911. def _pin_memory(
  2912. input: Tensor,
  2913. device: DeviceLikeType | None = None,
  2914. ) -> Tensor: ...
  2915. def _prelu_kernel(input: Tensor, weight: Tensor) -> Tensor: ...
  2916. def _print(s: str) -> None: ...
  2917. def _propagate_xla_data(input: Tensor, output: Tensor) -> None: ...
  2918. def _remove_batch_dim(
  2919. input: Tensor,
  2920. level: _int,
  2921. batch_size: _int | SymInt,
  2922. out_dim: _int,
  2923. ) -> Tensor: ...
  2924. def _reshape_alias_copy(
  2925. input: Tensor,
  2926. size: Sequence[_int | SymInt],
  2927. stride: Sequence[_int | SymInt],
  2928. *,
  2929. out: Tensor | None = None,
  2930. ) -> Tensor: ...
  2931. def _reshape_from_tensor(input: Tensor, shape: Tensor) -> Tensor: ...
  2932. def _resize_output_(
  2933. input: Tensor,
  2934. size: Sequence[_int | SymInt],
  2935. device: DeviceLikeType | None,
  2936. ) -> Tensor: ...
  2937. def _rowwise_prune(
  2938. weight: Tensor,
  2939. mask: Tensor,
  2940. compressed_indices_dtype: _dtype,
  2941. ) -> tuple[Tensor, Tensor]: ...
  2942. def _safe_softmax(
  2943. input: Tensor,
  2944. dim: _int,
  2945. dtype: _dtype | None = None,
  2946. ) -> Tensor: ...
  2947. def _sample_dirichlet(
  2948. input: Tensor,
  2949. generator: Generator | None = None,
  2950. ) -> Tensor: ...
  2951. def _saturate_weight_to_fp16(weight: Tensor) -> Tensor: ...
  2952. def _scaled_dot_product_attention_math(
  2953. query: Tensor,
  2954. key: Tensor,
  2955. value: Tensor,
  2956. attn_mask: Tensor | None = None,
  2957. dropout_p: _float = 0.0,
  2958. is_causal: _bool = False,
  2959. dropout_mask: Tensor | None = None,
  2960. *,
  2961. scale: _float | None = None,
  2962. enable_gqa: _bool = False,
  2963. ) -> tuple[Tensor, Tensor]: ...
  2964. def _scaled_dot_product_attention_math_for_mps(
  2965. query: Tensor,
  2966. key: Tensor,
  2967. value: Tensor,
  2968. attn_mask: Tensor | None = None,
  2969. dropout_p: _float = 0.0,
  2970. is_causal: _bool = False,
  2971. dropout_mask: Tensor | None = None,
  2972. *,
  2973. scale: _float | None = None,
  2974. ) -> tuple[Tensor, Tensor]: ...
  2975. def _scaled_dot_product_cudnn_attention(
  2976. query: Tensor,
  2977. key: Tensor,
  2978. value: Tensor,
  2979. attn_bias: Tensor | None,
  2980. compute_log_sumexp: _bool,
  2981. dropout_p: _float = 0.0,
  2982. is_causal: _bool = False,
  2983. return_debug_mask: _bool = False,
  2984. *,
  2985. scale: _float | None = None,
  2986. ) -> torch.return_types._scaled_dot_product_cudnn_attention: ...
  2987. def _scaled_dot_product_efficient_attention(
  2988. query: Tensor,
  2989. key: Tensor,
  2990. value: Tensor,
  2991. attn_bias: Tensor | None,
  2992. compute_log_sumexp: _bool,
  2993. dropout_p: _float = 0.0,
  2994. is_causal: _bool = False,
  2995. *,
  2996. scale: _float | None = None,
  2997. ) -> torch.return_types._scaled_dot_product_efficient_attention: ...
  2998. def _scaled_dot_product_flash_attention(
  2999. query: Tensor,
  3000. key: Tensor,
  3001. value: Tensor,
  3002. dropout_p: _float = 0.0,
  3003. is_causal: _bool = False,
  3004. return_debug_mask: _bool = False,
  3005. *,
  3006. scale: _float | None = None,
  3007. ) -> torch.return_types._scaled_dot_product_flash_attention: ...
  3008. def _scaled_dot_product_flash_attention_for_cpu(
  3009. query: Tensor,
  3010. key: Tensor,
  3011. value: Tensor,
  3012. dropout_p: _float = 0.0,
  3013. is_causal: _bool = False,
  3014. *,
  3015. attn_mask: Tensor | None = None,
  3016. scale: _float | None = None,
  3017. ) -> torch.return_types._scaled_dot_product_flash_attention_for_cpu: ...
  3018. def _scaled_grouped_mm(
  3019. input: Tensor,
  3020. mat2: Tensor,
  3021. scale_a: Tensor,
  3022. scale_b: Tensor,
  3023. offs: Tensor | None = None,
  3024. bias: Tensor | None = None,
  3025. scale_result: Tensor | None = None,
  3026. out_dtype: _dtype | None = None,
  3027. use_fast_accum: _bool = False,
  3028. ) -> Tensor: ...
  3029. def _scaled_mm(
  3030. input: Tensor,
  3031. mat2: Tensor,
  3032. scale_a: Tensor,
  3033. scale_b: Tensor,
  3034. bias: Tensor | None = None,
  3035. scale_result: Tensor | None = None,
  3036. out_dtype: _dtype | None = None,
  3037. use_fast_accum: _bool = False,
  3038. *,
  3039. out: Tensor | None = None,
  3040. ) -> Tensor: ...
  3041. def _shape_as_tensor(input: Tensor) -> Tensor: ...
  3042. def _sobol_engine_draw(
  3043. quasi: Tensor,
  3044. n: _int,
  3045. sobolstate: Tensor,
  3046. dimension: _int,
  3047. num_generated: _int,
  3048. dtype: _dtype | None,
  3049. ) -> tuple[Tensor, Tensor]: ...
  3050. def _sobol_engine_ff_(
  3051. input: Tensor,
  3052. n: _int,
  3053. sobolstate: Tensor,
  3054. dimension: _int,
  3055. num_generated: _int,
  3056. ) -> Tensor: ...
  3057. def _sobol_engine_initialize_state_(
  3058. input: Tensor,
  3059. dimension: _int,
  3060. ) -> Tensor: ...
  3061. def _sobol_engine_scramble_(
  3062. input: Tensor,
  3063. ltm: Tensor,
  3064. dimension: _int,
  3065. ) -> Tensor: ...
  3066. def _softmax(
  3067. input: Tensor,
  3068. dim: _int,
  3069. half_to_float: _bool,
  3070. *,
  3071. out: Tensor | None = None,
  3072. ) -> Tensor: ...
  3073. def _softmax_backward_data(
  3074. grad_output: Tensor,
  3075. output: Tensor,
  3076. dim: _int,
  3077. input_dtype: _dtype,
  3078. *,
  3079. grad_input: Tensor | None = None,
  3080. ) -> Tensor: ...
  3081. def _sparse_broadcast_to(input: Tensor, size: _size) -> Tensor: ...
  3082. def _sparse_broadcast_to_copy(
  3083. input: Tensor,
  3084. size: _size,
  3085. *,
  3086. out: Tensor | None = None,
  3087. ) -> Tensor: ...
  3088. def _sparse_csr_prod(
  3089. input: Tensor,
  3090. dim: _int | _size,
  3091. keepdim: _bool = False,
  3092. *,
  3093. dtype: _dtype | None = None,
  3094. ) -> Tensor: ...
  3095. def _sparse_csr_sum(
  3096. input: Tensor,
  3097. dim: _int | _size,
  3098. keepdim: _bool = False,
  3099. *,
  3100. dtype: _dtype | None = None,
  3101. ) -> Tensor: ...
  3102. def _sparse_log_softmax_backward_data(
  3103. grad_output: Tensor,
  3104. output: Tensor,
  3105. dim: _int,
  3106. input: Tensor,
  3107. ) -> Tensor: ...
  3108. def _sparse_semi_structured_addmm(
  3109. input: Tensor,
  3110. mat1: Tensor,
  3111. mat1_meta: Tensor,
  3112. mat2: Tensor,
  3113. *,
  3114. alpha: Number | _complex = 1,
  3115. beta: Number | _complex = 1,
  3116. out_dtype: _dtype | None = None,
  3117. ) -> Tensor: ...
  3118. def _sparse_semi_structured_apply(
  3119. input: Tensor,
  3120. thread_masks: Tensor,
  3121. ) -> tuple[Tensor, Tensor]: ...
  3122. def _sparse_semi_structured_apply_dense(
  3123. input: Tensor,
  3124. thread_masks: Tensor,
  3125. ) -> Tensor: ...
  3126. def _sparse_semi_structured_linear(
  3127. input: Tensor,
  3128. weight: Tensor,
  3129. meta: Tensor,
  3130. *,
  3131. bias: Tensor | None = None,
  3132. activation: str | None = None,
  3133. out_dtype: _dtype | None = None,
  3134. ) -> Tensor: ...
  3135. def _sparse_semi_structured_mm(
  3136. mat1: Tensor,
  3137. mat1_meta: Tensor,
  3138. mat2: Tensor,
  3139. *,
  3140. out_dtype: _dtype | None = None,
  3141. ) -> Tensor: ...
  3142. def _sparse_semi_structured_tile(
  3143. input: Tensor,
  3144. algorithm: str = "",
  3145. use_cutlass: _bool = True,
  3146. ) -> tuple[Tensor, Tensor, Tensor, Tensor, Tensor]: ...
  3147. def _sparse_softmax_backward_data(
  3148. grad_output: Tensor,
  3149. output: Tensor,
  3150. dim: _int,
  3151. input: Tensor,
  3152. ) -> Tensor: ...
  3153. def _sparse_sparse_matmul(input: Tensor, other: Tensor) -> Tensor: ...
  3154. @overload
  3155. def _sparse_sum(input: Tensor) -> Tensor: ...
  3156. @overload
  3157. def _sparse_sum(input: Tensor, *, dtype: _dtype) -> Tensor: ...
  3158. @overload
  3159. def _sparse_sum(input: Tensor, dim: _int | _size) -> Tensor: ...
  3160. @overload
  3161. def _sparse_sum(
  3162. input: Tensor,
  3163. dim: _int | _size,
  3164. *,
  3165. dtype: _dtype,
  3166. ) -> Tensor: ...
  3167. def _stack(
  3168. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  3169. dim: _int = 0,
  3170. *,
  3171. out: Tensor | None = None,
  3172. ) -> Tensor: ...
  3173. def _standard_gamma(
  3174. input: Tensor,
  3175. generator: Generator | None = None,
  3176. ) -> Tensor: ...
  3177. def _standard_gamma_grad(input: Tensor, output: Tensor) -> Tensor: ...
  3178. def _sync(t: Tensor) -> None: ...
  3179. @overload
  3180. def _test_autograd_multiple_dispatch(input: Tensor) -> Tensor: ...
  3181. @overload
  3182. def _test_autograd_multiple_dispatch(input: Tensor, b: _bool) -> Tensor: ...
  3183. def _test_autograd_multiple_dispatch_view(input: Tensor) -> Tensor: ...
  3184. def _test_autograd_multiple_dispatch_view_copy(
  3185. input: Tensor,
  3186. *,
  3187. out: Tensor | None = None,
  3188. ) -> Tensor: ...
  3189. def _test_check_tensor(input: Tensor) -> Tensor: ...
  3190. def _test_functorch_fallback(input: Tensor, other: Tensor) -> Tensor: ...
  3191. def _test_parallel_materialize(
  3192. input: Tensor,
  3193. num_parallel: _int,
  3194. skip_first: _bool = False,
  3195. ) -> Tensor: ...
  3196. def _test_serialization_subcmul(
  3197. input: Tensor,
  3198. other: Tensor,
  3199. alpha: Number | _complex = 1,
  3200. ) -> Tensor: ...
  3201. def _to_cpu(
  3202. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  3203. ) -> tuple[Tensor, ...]: ...
  3204. def _to_functional_tensor(t: Tensor) -> Tensor: ...
  3205. def _to_sparse_semi_structured(dense: Tensor) -> tuple[Tensor, Tensor]: ...
  3206. def _transform_bias_rescale_qkv(
  3207. qkv: Tensor,
  3208. qkv_bias: Tensor,
  3209. num_heads: _int,
  3210. ) -> tuple[Tensor, Tensor, Tensor]: ...
  3211. def _transformer_encoder_layer_fwd(
  3212. src: Tensor,
  3213. embed_dim: _int,
  3214. num_heads: _int,
  3215. qkv_weight: Tensor,
  3216. qkv_bias: Tensor,
  3217. proj_weight: Tensor,
  3218. proj_bias: Tensor,
  3219. use_gelu: _bool,
  3220. norm_first: _bool,
  3221. eps: _float,
  3222. norm_weight_1: Tensor,
  3223. norm_bias_1: Tensor,
  3224. norm_weight_2: Tensor,
  3225. norm_bias_2: Tensor,
  3226. ffn_weight_1: Tensor,
  3227. ffn_bias_1: Tensor,
  3228. ffn_weight_2: Tensor,
  3229. ffn_bias_2: Tensor,
  3230. mask: Tensor | None = None,
  3231. mask_type: _int | None = None,
  3232. ) -> Tensor: ...
  3233. def _trilinear(
  3234. i1: Tensor,
  3235. i2: Tensor,
  3236. i3: Tensor,
  3237. expand1: _size,
  3238. expand2: _size,
  3239. expand3: _size,
  3240. sumdim: _size,
  3241. unroll_dim: _int = 1,
  3242. ) -> Tensor: ...
  3243. def _triton_multi_head_attention(
  3244. query: Tensor,
  3245. key: Tensor,
  3246. value: Tensor,
  3247. embed_dim: _int,
  3248. num_head: _int,
  3249. qkv_weight: Tensor,
  3250. qkv_bias: Tensor,
  3251. proj_weight: Tensor,
  3252. proj_bias: Tensor,
  3253. mask: Tensor | None = None,
  3254. ) -> Tensor: ...
  3255. def _triton_scaled_dot_attention(
  3256. q: Tensor,
  3257. k: Tensor,
  3258. v: Tensor,
  3259. dropout_p: _float = 0.0,
  3260. ) -> Tensor: ...
  3261. def _unique(
  3262. input: Tensor,
  3263. sorted: _bool = True,
  3264. return_inverse: _bool = False,
  3265. ) -> tuple[Tensor, Tensor]: ...
  3266. def _unique2(
  3267. input: Tensor,
  3268. sorted: _bool = True,
  3269. return_inverse: _bool = False,
  3270. return_counts: _bool = False,
  3271. ) -> tuple[Tensor, Tensor, Tensor]: ...
  3272. def _unpack_dual(
  3273. dual: Tensor,
  3274. level: _int,
  3275. ) -> torch.return_types._unpack_dual: ...
  3276. def _unsafe_index(
  3277. input: Tensor,
  3278. indices: tuple[Tensor, ...] | list[Tensor] | None,
  3279. ) -> Tensor: ...
  3280. def _unsafe_index_put(
  3281. input: Tensor,
  3282. indices: tuple[Tensor, ...] | list[Tensor] | None,
  3283. values: Tensor,
  3284. accumulate: _bool = False,
  3285. ) -> Tensor: ...
  3286. def _unsafe_masked_index(
  3287. input: Tensor,
  3288. mask: Tensor,
  3289. indices: tuple[Tensor, ...] | list[Tensor] | None,
  3290. fill: Number | _complex,
  3291. ) -> Tensor: ...
  3292. def _unsafe_masked_index_put_accumulate(
  3293. input: Tensor,
  3294. mask: Tensor,
  3295. indices: tuple[Tensor, ...] | list[Tensor] | None,
  3296. values: Tensor,
  3297. ) -> Tensor: ...
  3298. @overload
  3299. def _use_cudnn_ctc_loss(
  3300. log_probs: Tensor,
  3301. targets: Tensor,
  3302. input_lengths: Tensor,
  3303. target_lengths: Tensor,
  3304. blank: _int,
  3305. ) -> _bool: ...
  3306. @overload
  3307. def _use_cudnn_ctc_loss(
  3308. log_probs: Tensor,
  3309. targets: Tensor,
  3310. input_lengths: _size,
  3311. target_lengths: _size,
  3312. blank: _int,
  3313. ) -> _bool: ...
  3314. def _use_cudnn_rnn_flatten_weight() -> _bool: ...
  3315. def _validate_compressed_sparse_indices(
  3316. is_crow: _bool,
  3317. compressed_idx: Tensor,
  3318. plain_idx: Tensor,
  3319. cdim: _int,
  3320. dim: _int,
  3321. nnz: _int,
  3322. ) -> None: ...
  3323. def _validate_sparse_bsc_tensor_args(
  3324. ccol_indices: Tensor,
  3325. row_indices: Tensor,
  3326. values: Tensor,
  3327. size: _size,
  3328. check_pinning: _bool | None = None,
  3329. ) -> None: ...
  3330. def _validate_sparse_bsr_tensor_args(
  3331. crow_indices: Tensor,
  3332. col_indices: Tensor,
  3333. values: Tensor,
  3334. size: _size,
  3335. check_pinning: _bool | None = None,
  3336. ) -> None: ...
  3337. def _validate_sparse_compressed_tensor_args(
  3338. compressed_indices: Tensor,
  3339. plain_indices: Tensor,
  3340. values: Tensor,
  3341. size: _size,
  3342. layout: _layout,
  3343. check_pinning: _bool | None = None,
  3344. ) -> None: ...
  3345. def _validate_sparse_coo_tensor_args(
  3346. indices: Tensor,
  3347. values: Tensor,
  3348. size: _size,
  3349. is_coalesced: _bool | None = None,
  3350. check_pinning: _bool | None = None,
  3351. ) -> None: ...
  3352. def _validate_sparse_csc_tensor_args(
  3353. ccol_indices: Tensor,
  3354. row_indices: Tensor,
  3355. values: Tensor,
  3356. size: _size,
  3357. check_pinning: _bool | None = None,
  3358. ) -> None: ...
  3359. def _validate_sparse_csr_tensor_args(
  3360. crow_indices: Tensor,
  3361. col_indices: Tensor,
  3362. values: Tensor,
  3363. size: _size,
  3364. check_pinning: _bool | None = None,
  3365. ) -> None: ...
  3366. def _values_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor: ...
  3367. def _weight_int4pack_mm(
  3368. input: Tensor,
  3369. mat2: Tensor,
  3370. qGroupSize: _int,
  3371. qScaleAndZeros: Tensor,
  3372. ) -> Tensor: ...
  3373. def _weight_int4pack_mm_for_cpu(
  3374. input: Tensor,
  3375. mat2: Tensor,
  3376. qGroupSize: _int,
  3377. qScaleAndZeros: Tensor,
  3378. ) -> Tensor: ...
  3379. def _weight_int4pack_mm_with_scales_and_zeros(
  3380. input: Tensor,
  3381. mat2: Tensor,
  3382. qGroupSize: _int,
  3383. qScale: Tensor,
  3384. qZeros: Tensor,
  3385. ) -> Tensor: ...
  3386. def _weight_int8pack_mm(
  3387. input: Tensor,
  3388. mat2: Tensor,
  3389. scales: Tensor,
  3390. ) -> Tensor: ...
  3391. def _weight_norm(v: Tensor, g: Tensor, dim: _int = 0) -> Tensor: ...
  3392. def _weight_norm_interface(
  3393. v: Tensor,
  3394. g: Tensor,
  3395. dim: _int = 0,
  3396. ) -> tuple[Tensor, Tensor]: ...
  3397. def _wrapped_linear_prepack(
  3398. weight: Tensor,
  3399. weight_scale: Tensor,
  3400. weight_zero_point: Tensor,
  3401. bias: Tensor,
  3402. ) -> Tensor: ...
  3403. def _wrapped_quantized_linear_prepacked(
  3404. input: Tensor,
  3405. input_scale: Tensor,
  3406. input_zero_point: Tensor,
  3407. packed_weight: Tensor,
  3408. output_scale: Tensor,
  3409. output_zero_point: Tensor,
  3410. out_channel: _int,
  3411. ) -> Tensor: ...
  3412. def abs(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  3413. r"""
  3414. abs(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  3415. Computes the absolute value of each element in :attr:`input`.
  3416. .. math::
  3417. \text{out}_{i} = |\text{input}_{i}|
  3418. Args:
  3419. input (Tensor): the input tensor.
  3420. Keyword args:
  3421. out (Tensor, optional): the output tensor.
  3422. Example::
  3423. >>> torch.abs(torch.tensor([-1, -2, 3]))
  3424. tensor([ 1, 2, 3])
  3425. """
  3426. def abs_(input: Tensor) -> Tensor: ...
  3427. def absolute(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  3428. r"""
  3429. absolute(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  3430. Alias for :func:`torch.abs`
  3431. """
  3432. def acos(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  3433. r"""
  3434. acos(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  3435. Computes the inverse cosine of each element in :attr:`input`.
  3436. .. math::
  3437. \text{out}_{i} = \cos^{-1}(\text{input}_{i})
  3438. Args:
  3439. input (Tensor): the input tensor.
  3440. Keyword args:
  3441. out (Tensor, optional): the output tensor.
  3442. Example::
  3443. >>> a = torch.randn(4)
  3444. >>> a
  3445. tensor([ 0.3348, -0.5889, 0.2005, -0.1584])
  3446. >>> torch.acos(a)
  3447. tensor([ 1.2294, 2.2004, 1.3690, 1.7298])
  3448. """
  3449. def acos_(input: Tensor) -> Tensor: ...
  3450. def acosh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  3451. r"""
  3452. acosh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  3453. Returns a new tensor with the inverse hyperbolic cosine of the elements of :attr:`input`.
  3454. .. math::
  3455. \text{out}_{i} = \cosh^{-1}(\text{input}_{i})
  3456. Note:
  3457. The domain of the inverse hyperbolic cosine is `[1, inf)` and values outside this range
  3458. will be mapped to ``NaN``, except for `+ INF` for which the output is mapped to `+ INF`.
  3459. Args:
  3460. input (Tensor): the input tensor.
  3461. Keyword arguments:
  3462. out (Tensor, optional): the output tensor.
  3463. Example::
  3464. >>> a = torch.randn(4).uniform_(1, 2)
  3465. >>> a
  3466. tensor([ 1.3192, 1.9915, 1.9674, 1.7151 ])
  3467. >>> torch.acosh(a)
  3468. tensor([ 0.7791, 1.3120, 1.2979, 1.1341 ])
  3469. """
  3470. def acosh_(input: Tensor) -> Tensor: ...
  3471. def adaptive_avg_pool1d(input: Tensor, output_size: _int | _size) -> Tensor: ...
  3472. def adaptive_max_pool1d(
  3473. input: Tensor,
  3474. output_size: _int | _size,
  3475. ) -> tuple[Tensor, Tensor]: ...
  3476. @overload
  3477. def add(
  3478. input: Tensor | Number | _complex,
  3479. other: Tensor | Number | _complex,
  3480. *,
  3481. alpha: Number | _complex | None = 1,
  3482. out: Tensor | None = None,
  3483. ) -> Tensor:
  3484. r"""
  3485. add(input, other, *, alpha=1, out=None) -> Tensor
  3486. Adds :attr:`other`, scaled by :attr:`alpha`, to :attr:`input`.
  3487. .. math::
  3488. \text{{out}}_i = \text{{input}}_i + \text{{alpha}} \times \text{{other}}_i
  3489. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  3490. :ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
  3491. Args:
  3492. input (Tensor): the input tensor.
  3493. other (Tensor or Number): the tensor or number to add to :attr:`input`.
  3494. Keyword arguments:
  3495. alpha (Number): the multiplier for :attr:`other`.
  3496. out (Tensor, optional): the output tensor.
  3497. Examples::
  3498. >>> a = torch.randn(4)
  3499. >>> a
  3500. tensor([ 0.0202, 1.0985, 1.3506, -0.6056])
  3501. >>> torch.add(a, 20)
  3502. tensor([ 20.0202, 21.0985, 21.3506, 19.3944])
  3503. >>> b = torch.randn(4)
  3504. >>> b
  3505. tensor([-0.9732, -0.3497, 0.6245, 0.4022])
  3506. >>> c = torch.randn(4, 1)
  3507. >>> c
  3508. tensor([[ 0.3743],
  3509. [-1.7724],
  3510. [-0.5811],
  3511. [-0.8017]])
  3512. >>> torch.add(b, c, alpha=10)
  3513. tensor([[ 2.7695, 3.3930, 4.3672, 4.1450],
  3514. [-18.6971, -18.0736, -17.0994, -17.3216],
  3515. [ -6.7845, -6.1610, -5.1868, -5.4090],
  3516. [ -8.9902, -8.3667, -7.3925, -7.6147]])
  3517. """
  3518. @overload
  3519. def add(self: Tensor, alpha: Number | _complex, other: Tensor) -> Tensor:
  3520. r"""
  3521. add(input, other, *, alpha=1, out=None) -> Tensor
  3522. Adds :attr:`other`, scaled by :attr:`alpha`, to :attr:`input`.
  3523. .. math::
  3524. \text{{out}}_i = \text{{input}}_i + \text{{alpha}} \times \text{{other}}_i
  3525. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  3526. :ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
  3527. Args:
  3528. input (Tensor): the input tensor.
  3529. other (Tensor or Number): the tensor or number to add to :attr:`input`.
  3530. Keyword arguments:
  3531. alpha (Number): the multiplier for :attr:`other`.
  3532. out (Tensor, optional): the output tensor.
  3533. Examples::
  3534. >>> a = torch.randn(4)
  3535. >>> a
  3536. tensor([ 0.0202, 1.0985, 1.3506, -0.6056])
  3537. >>> torch.add(a, 20)
  3538. tensor([ 20.0202, 21.0985, 21.3506, 19.3944])
  3539. >>> b = torch.randn(4)
  3540. >>> b
  3541. tensor([-0.9732, -0.3497, 0.6245, 0.4022])
  3542. >>> c = torch.randn(4, 1)
  3543. >>> c
  3544. tensor([[ 0.3743],
  3545. [-1.7724],
  3546. [-0.5811],
  3547. [-0.8017]])
  3548. >>> torch.add(b, c, alpha=10)
  3549. tensor([[ 2.7695, 3.3930, 4.3672, 4.1450],
  3550. [-18.6971, -18.0736, -17.0994, -17.3216],
  3551. [ -6.7845, -6.1610, -5.1868, -5.4090],
  3552. [ -8.9902, -8.3667, -7.3925, -7.6147]])
  3553. """
  3554. @overload
  3555. def add(
  3556. self: Tensor,
  3557. alpha: Number | _complex,
  3558. other: Tensor,
  3559. *,
  3560. out: Tensor,
  3561. ) -> Tensor:
  3562. r"""
  3563. add(input, other, *, alpha=1, out=None) -> Tensor
  3564. Adds :attr:`other`, scaled by :attr:`alpha`, to :attr:`input`.
  3565. .. math::
  3566. \text{{out}}_i = \text{{input}}_i + \text{{alpha}} \times \text{{other}}_i
  3567. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  3568. :ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
  3569. Args:
  3570. input (Tensor): the input tensor.
  3571. other (Tensor or Number): the tensor or number to add to :attr:`input`.
  3572. Keyword arguments:
  3573. alpha (Number): the multiplier for :attr:`other`.
  3574. out (Tensor, optional): the output tensor.
  3575. Examples::
  3576. >>> a = torch.randn(4)
  3577. >>> a
  3578. tensor([ 0.0202, 1.0985, 1.3506, -0.6056])
  3579. >>> torch.add(a, 20)
  3580. tensor([ 20.0202, 21.0985, 21.3506, 19.3944])
  3581. >>> b = torch.randn(4)
  3582. >>> b
  3583. tensor([-0.9732, -0.3497, 0.6245, 0.4022])
  3584. >>> c = torch.randn(4, 1)
  3585. >>> c
  3586. tensor([[ 0.3743],
  3587. [-1.7724],
  3588. [-0.5811],
  3589. [-0.8017]])
  3590. >>> torch.add(b, c, alpha=10)
  3591. tensor([[ 2.7695, 3.3930, 4.3672, 4.1450],
  3592. [-18.6971, -18.0736, -17.0994, -17.3216],
  3593. [ -6.7845, -6.1610, -5.1868, -5.4090],
  3594. [ -8.9902, -8.3667, -7.3925, -7.6147]])
  3595. """
  3596. @overload
  3597. def addbmm(
  3598. beta: Number | _complex,
  3599. self: Tensor,
  3600. alpha: Number | _complex,
  3601. batch1: Tensor,
  3602. batch2: Tensor,
  3603. ) -> Tensor:
  3604. r"""
  3605. addbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None) -> Tensor
  3606. Performs a batch matrix-matrix product of matrices stored
  3607. in :attr:`batch1` and :attr:`batch2`,
  3608. with a reduced add step (all matrix multiplications get accumulated
  3609. along the first dimension).
  3610. :attr:`input` is added to the final result.
  3611. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the
  3612. same number of matrices.
  3613. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  3614. :math:`(b \times m \times p)` tensor, :attr:`input` must be
  3615. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  3616. and :attr:`out` will be a :math:`(n \times p)` tensor.
  3617. .. math::
  3618. out = \beta\ \text{input} + \alpha\ (\sum_{i=0}^{b-1} \text{batch1}_i \mathbin{@} \text{batch2}_i)
  3619. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  3620. it will not be propagated.
  3621. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and :attr:`alpha`
  3622. must be real numbers, otherwise they should be integers.
  3623. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  3624. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  3625. Args:
  3626. input (Tensor): matrix to be added
  3627. batch1 (Tensor): the first batch of matrices to be multiplied
  3628. batch2 (Tensor): the second batch of matrices to be multiplied
  3629. Keyword args:
  3630. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  3631. alpha (Number, optional): multiplier for `batch1 @ batch2` (:math:`\alpha`)
  3632. out (Tensor, optional): the output tensor.
  3633. Example::
  3634. >>> M = torch.randn(3, 5)
  3635. >>> batch1 = torch.randn(10, 3, 4)
  3636. >>> batch2 = torch.randn(10, 4, 5)
  3637. >>> torch.addbmm(M, batch1, batch2)
  3638. tensor([[ 6.6311, 0.0503, 6.9768, -12.0362, -2.1653],
  3639. [ -4.8185, -1.4255, -6.6760, 8.9453, 2.5743],
  3640. [ -3.8202, 4.3691, 1.0943, -1.1109, 5.4730]])
  3641. """
  3642. @overload
  3643. def addbmm(
  3644. beta: Number | _complex,
  3645. self: Tensor,
  3646. alpha: Number | _complex,
  3647. batch1: Tensor,
  3648. batch2: Tensor,
  3649. *,
  3650. out: Tensor,
  3651. ) -> Tensor:
  3652. r"""
  3653. addbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None) -> Tensor
  3654. Performs a batch matrix-matrix product of matrices stored
  3655. in :attr:`batch1` and :attr:`batch2`,
  3656. with a reduced add step (all matrix multiplications get accumulated
  3657. along the first dimension).
  3658. :attr:`input` is added to the final result.
  3659. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the
  3660. same number of matrices.
  3661. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  3662. :math:`(b \times m \times p)` tensor, :attr:`input` must be
  3663. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  3664. and :attr:`out` will be a :math:`(n \times p)` tensor.
  3665. .. math::
  3666. out = \beta\ \text{input} + \alpha\ (\sum_{i=0}^{b-1} \text{batch1}_i \mathbin{@} \text{batch2}_i)
  3667. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  3668. it will not be propagated.
  3669. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and :attr:`alpha`
  3670. must be real numbers, otherwise they should be integers.
  3671. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  3672. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  3673. Args:
  3674. input (Tensor): matrix to be added
  3675. batch1 (Tensor): the first batch of matrices to be multiplied
  3676. batch2 (Tensor): the second batch of matrices to be multiplied
  3677. Keyword args:
  3678. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  3679. alpha (Number, optional): multiplier for `batch1 @ batch2` (:math:`\alpha`)
  3680. out (Tensor, optional): the output tensor.
  3681. Example::
  3682. >>> M = torch.randn(3, 5)
  3683. >>> batch1 = torch.randn(10, 3, 4)
  3684. >>> batch2 = torch.randn(10, 4, 5)
  3685. >>> torch.addbmm(M, batch1, batch2)
  3686. tensor([[ 6.6311, 0.0503, 6.9768, -12.0362, -2.1653],
  3687. [ -4.8185, -1.4255, -6.6760, 8.9453, 2.5743],
  3688. [ -3.8202, 4.3691, 1.0943, -1.1109, 5.4730]])
  3689. """
  3690. @overload
  3691. def addbmm(
  3692. input: Tensor,
  3693. batch1: Tensor,
  3694. batch2: Tensor,
  3695. *,
  3696. beta: Number | _complex = 1,
  3697. alpha: Number | _complex = 1,
  3698. out: Tensor | None = None,
  3699. ) -> Tensor:
  3700. r"""
  3701. addbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None) -> Tensor
  3702. Performs a batch matrix-matrix product of matrices stored
  3703. in :attr:`batch1` and :attr:`batch2`,
  3704. with a reduced add step (all matrix multiplications get accumulated
  3705. along the first dimension).
  3706. :attr:`input` is added to the final result.
  3707. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the
  3708. same number of matrices.
  3709. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  3710. :math:`(b \times m \times p)` tensor, :attr:`input` must be
  3711. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  3712. and :attr:`out` will be a :math:`(n \times p)` tensor.
  3713. .. math::
  3714. out = \beta\ \text{input} + \alpha\ (\sum_{i=0}^{b-1} \text{batch1}_i \mathbin{@} \text{batch2}_i)
  3715. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  3716. it will not be propagated.
  3717. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and :attr:`alpha`
  3718. must be real numbers, otherwise they should be integers.
  3719. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  3720. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  3721. Args:
  3722. input (Tensor): matrix to be added
  3723. batch1 (Tensor): the first batch of matrices to be multiplied
  3724. batch2 (Tensor): the second batch of matrices to be multiplied
  3725. Keyword args:
  3726. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  3727. alpha (Number, optional): multiplier for `batch1 @ batch2` (:math:`\alpha`)
  3728. out (Tensor, optional): the output tensor.
  3729. Example::
  3730. >>> M = torch.randn(3, 5)
  3731. >>> batch1 = torch.randn(10, 3, 4)
  3732. >>> batch2 = torch.randn(10, 4, 5)
  3733. >>> torch.addbmm(M, batch1, batch2)
  3734. tensor([[ 6.6311, 0.0503, 6.9768, -12.0362, -2.1653],
  3735. [ -4.8185, -1.4255, -6.6760, 8.9453, 2.5743],
  3736. [ -3.8202, 4.3691, 1.0943, -1.1109, 5.4730]])
  3737. """
  3738. @overload
  3739. def addbmm(
  3740. beta: Number | _complex,
  3741. self: Tensor,
  3742. batch1: Tensor,
  3743. batch2: Tensor,
  3744. ) -> Tensor:
  3745. r"""
  3746. addbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None) -> Tensor
  3747. Performs a batch matrix-matrix product of matrices stored
  3748. in :attr:`batch1` and :attr:`batch2`,
  3749. with a reduced add step (all matrix multiplications get accumulated
  3750. along the first dimension).
  3751. :attr:`input` is added to the final result.
  3752. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the
  3753. same number of matrices.
  3754. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  3755. :math:`(b \times m \times p)` tensor, :attr:`input` must be
  3756. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  3757. and :attr:`out` will be a :math:`(n \times p)` tensor.
  3758. .. math::
  3759. out = \beta\ \text{input} + \alpha\ (\sum_{i=0}^{b-1} \text{batch1}_i \mathbin{@} \text{batch2}_i)
  3760. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  3761. it will not be propagated.
  3762. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and :attr:`alpha`
  3763. must be real numbers, otherwise they should be integers.
  3764. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  3765. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  3766. Args:
  3767. input (Tensor): matrix to be added
  3768. batch1 (Tensor): the first batch of matrices to be multiplied
  3769. batch2 (Tensor): the second batch of matrices to be multiplied
  3770. Keyword args:
  3771. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  3772. alpha (Number, optional): multiplier for `batch1 @ batch2` (:math:`\alpha`)
  3773. out (Tensor, optional): the output tensor.
  3774. Example::
  3775. >>> M = torch.randn(3, 5)
  3776. >>> batch1 = torch.randn(10, 3, 4)
  3777. >>> batch2 = torch.randn(10, 4, 5)
  3778. >>> torch.addbmm(M, batch1, batch2)
  3779. tensor([[ 6.6311, 0.0503, 6.9768, -12.0362, -2.1653],
  3780. [ -4.8185, -1.4255, -6.6760, 8.9453, 2.5743],
  3781. [ -3.8202, 4.3691, 1.0943, -1.1109, 5.4730]])
  3782. """
  3783. @overload
  3784. def addbmm(
  3785. beta: Number | _complex,
  3786. self: Tensor,
  3787. batch1: Tensor,
  3788. batch2: Tensor,
  3789. *,
  3790. out: Tensor,
  3791. ) -> Tensor:
  3792. r"""
  3793. addbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None) -> Tensor
  3794. Performs a batch matrix-matrix product of matrices stored
  3795. in :attr:`batch1` and :attr:`batch2`,
  3796. with a reduced add step (all matrix multiplications get accumulated
  3797. along the first dimension).
  3798. :attr:`input` is added to the final result.
  3799. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the
  3800. same number of matrices.
  3801. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  3802. :math:`(b \times m \times p)` tensor, :attr:`input` must be
  3803. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  3804. and :attr:`out` will be a :math:`(n \times p)` tensor.
  3805. .. math::
  3806. out = \beta\ \text{input} + \alpha\ (\sum_{i=0}^{b-1} \text{batch1}_i \mathbin{@} \text{batch2}_i)
  3807. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  3808. it will not be propagated.
  3809. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and :attr:`alpha`
  3810. must be real numbers, otherwise they should be integers.
  3811. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  3812. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  3813. Args:
  3814. input (Tensor): matrix to be added
  3815. batch1 (Tensor): the first batch of matrices to be multiplied
  3816. batch2 (Tensor): the second batch of matrices to be multiplied
  3817. Keyword args:
  3818. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  3819. alpha (Number, optional): multiplier for `batch1 @ batch2` (:math:`\alpha`)
  3820. out (Tensor, optional): the output tensor.
  3821. Example::
  3822. >>> M = torch.randn(3, 5)
  3823. >>> batch1 = torch.randn(10, 3, 4)
  3824. >>> batch2 = torch.randn(10, 4, 5)
  3825. >>> torch.addbmm(M, batch1, batch2)
  3826. tensor([[ 6.6311, 0.0503, 6.9768, -12.0362, -2.1653],
  3827. [ -4.8185, -1.4255, -6.6760, 8.9453, 2.5743],
  3828. [ -3.8202, 4.3691, 1.0943, -1.1109, 5.4730]])
  3829. """
  3830. @overload
  3831. def addcdiv(
  3832. self: Tensor,
  3833. value: Number | _complex,
  3834. tensor1: Tensor,
  3835. tensor2: Tensor,
  3836. ) -> Tensor:
  3837. r"""
  3838. addcdiv(input, tensor1, tensor2, *, value=1, out=None) -> Tensor
  3839. Performs the element-wise division of :attr:`tensor1` by :attr:`tensor2`,
  3840. multiplies the result by the scalar :attr:`value` and adds it to :attr:`input`.
  3841. .. warning::
  3842. Integer division with addcdiv is no longer supported, and in a future
  3843. release addcdiv will perform a true division of tensor1 and tensor2.
  3844. The historic addcdiv behavior can be implemented as
  3845. (input + value * torch.trunc(tensor1 / tensor2)).to(input.dtype)
  3846. for integer inputs and as (input + value * tensor1 / tensor2) for float inputs.
  3847. The future addcdiv behavior is just the latter implementation:
  3848. (input + value * tensor1 / tensor2), for all dtypes.
  3849. .. math::
  3850. \text{out}_i = \text{input}_i + \text{value} \times \frac{\text{tensor1}_i}{\text{tensor2}_i}
  3851. The shapes of :attr:`input`, :attr:`tensor1`, and :attr:`tensor2` must be
  3852. :ref:`broadcastable <broadcasting-semantics>`.
  3853. For inputs of type `FloatTensor` or `DoubleTensor`, :attr:`value` must be
  3854. a real number, otherwise an integer.
  3855. Args:
  3856. input (Tensor): the tensor to be added
  3857. tensor1 (Tensor): the numerator tensor
  3858. tensor2 (Tensor): the denominator tensor
  3859. Keyword args:
  3860. value (Number, optional): multiplier for :math:`\text{tensor1} / \text{tensor2}`
  3861. out (Tensor, optional): the output tensor.
  3862. Example::
  3863. >>> t = torch.randn(1, 3)
  3864. >>> t1 = torch.randn(3, 1)
  3865. >>> t2 = torch.randn(1, 3)
  3866. >>> torch.addcdiv(t, t1, t2, value=0.1)
  3867. tensor([[-0.2312, -3.6496, 0.1312],
  3868. [-1.0428, 3.4292, -0.1030],
  3869. [-0.5369, -0.9829, 0.0430]])
  3870. """
  3871. @overload
  3872. def addcdiv(
  3873. self: Tensor,
  3874. value: Number | _complex,
  3875. tensor1: Tensor,
  3876. tensor2: Tensor,
  3877. *,
  3878. out: Tensor,
  3879. ) -> Tensor:
  3880. r"""
  3881. addcdiv(input, tensor1, tensor2, *, value=1, out=None) -> Tensor
  3882. Performs the element-wise division of :attr:`tensor1` by :attr:`tensor2`,
  3883. multiplies the result by the scalar :attr:`value` and adds it to :attr:`input`.
  3884. .. warning::
  3885. Integer division with addcdiv is no longer supported, and in a future
  3886. release addcdiv will perform a true division of tensor1 and tensor2.
  3887. The historic addcdiv behavior can be implemented as
  3888. (input + value * torch.trunc(tensor1 / tensor2)).to(input.dtype)
  3889. for integer inputs and as (input + value * tensor1 / tensor2) for float inputs.
  3890. The future addcdiv behavior is just the latter implementation:
  3891. (input + value * tensor1 / tensor2), for all dtypes.
  3892. .. math::
  3893. \text{out}_i = \text{input}_i + \text{value} \times \frac{\text{tensor1}_i}{\text{tensor2}_i}
  3894. The shapes of :attr:`input`, :attr:`tensor1`, and :attr:`tensor2` must be
  3895. :ref:`broadcastable <broadcasting-semantics>`.
  3896. For inputs of type `FloatTensor` or `DoubleTensor`, :attr:`value` must be
  3897. a real number, otherwise an integer.
  3898. Args:
  3899. input (Tensor): the tensor to be added
  3900. tensor1 (Tensor): the numerator tensor
  3901. tensor2 (Tensor): the denominator tensor
  3902. Keyword args:
  3903. value (Number, optional): multiplier for :math:`\text{tensor1} / \text{tensor2}`
  3904. out (Tensor, optional): the output tensor.
  3905. Example::
  3906. >>> t = torch.randn(1, 3)
  3907. >>> t1 = torch.randn(3, 1)
  3908. >>> t2 = torch.randn(1, 3)
  3909. >>> torch.addcdiv(t, t1, t2, value=0.1)
  3910. tensor([[-0.2312, -3.6496, 0.1312],
  3911. [-1.0428, 3.4292, -0.1030],
  3912. [-0.5369, -0.9829, 0.0430]])
  3913. """
  3914. @overload
  3915. def addcdiv(
  3916. input: Tensor,
  3917. tensor1: Tensor,
  3918. tensor2: Tensor,
  3919. *,
  3920. value: Number | _complex = 1,
  3921. out: Tensor | None = None,
  3922. ) -> Tensor:
  3923. r"""
  3924. addcdiv(input, tensor1, tensor2, *, value=1, out=None) -> Tensor
  3925. Performs the element-wise division of :attr:`tensor1` by :attr:`tensor2`,
  3926. multiplies the result by the scalar :attr:`value` and adds it to :attr:`input`.
  3927. .. warning::
  3928. Integer division with addcdiv is no longer supported, and in a future
  3929. release addcdiv will perform a true division of tensor1 and tensor2.
  3930. The historic addcdiv behavior can be implemented as
  3931. (input + value * torch.trunc(tensor1 / tensor2)).to(input.dtype)
  3932. for integer inputs and as (input + value * tensor1 / tensor2) for float inputs.
  3933. The future addcdiv behavior is just the latter implementation:
  3934. (input + value * tensor1 / tensor2), for all dtypes.
  3935. .. math::
  3936. \text{out}_i = \text{input}_i + \text{value} \times \frac{\text{tensor1}_i}{\text{tensor2}_i}
  3937. The shapes of :attr:`input`, :attr:`tensor1`, and :attr:`tensor2` must be
  3938. :ref:`broadcastable <broadcasting-semantics>`.
  3939. For inputs of type `FloatTensor` or `DoubleTensor`, :attr:`value` must be
  3940. a real number, otherwise an integer.
  3941. Args:
  3942. input (Tensor): the tensor to be added
  3943. tensor1 (Tensor): the numerator tensor
  3944. tensor2 (Tensor): the denominator tensor
  3945. Keyword args:
  3946. value (Number, optional): multiplier for :math:`\text{tensor1} / \text{tensor2}`
  3947. out (Tensor, optional): the output tensor.
  3948. Example::
  3949. >>> t = torch.randn(1, 3)
  3950. >>> t1 = torch.randn(3, 1)
  3951. >>> t2 = torch.randn(1, 3)
  3952. >>> torch.addcdiv(t, t1, t2, value=0.1)
  3953. tensor([[-0.2312, -3.6496, 0.1312],
  3954. [-1.0428, 3.4292, -0.1030],
  3955. [-0.5369, -0.9829, 0.0430]])
  3956. """
  3957. @overload
  3958. def addcmul(
  3959. self: Tensor,
  3960. value: Number | _complex,
  3961. tensor1: Tensor,
  3962. tensor2: Tensor,
  3963. ) -> Tensor:
  3964. r"""
  3965. addcmul(input, tensor1, tensor2, *, value=1, out=None) -> Tensor
  3966. Performs the element-wise multiplication of :attr:`tensor1`
  3967. by :attr:`tensor2`, multiplies the result by the scalar :attr:`value`
  3968. and adds it to :attr:`input`.
  3969. .. math::
  3970. \text{out}_i = \text{input}_i + \text{value} \times \text{tensor1}_i \times \text{tensor2}_i
  3971. The shapes of :attr:`tensor`, :attr:`tensor1`, and :attr:`tensor2` must be
  3972. :ref:`broadcastable <broadcasting-semantics>`.
  3973. For inputs of type `FloatTensor` or `DoubleTensor`, :attr:`value` must be
  3974. a real number, otherwise an integer.
  3975. Args:
  3976. input (Tensor): the tensor to be added
  3977. tensor1 (Tensor): the tensor to be multiplied
  3978. tensor2 (Tensor): the tensor to be multiplied
  3979. Keyword args:
  3980. value (Number, optional): multiplier for :math:`tensor1 .* tensor2`
  3981. out (Tensor, optional): the output tensor.
  3982. Example::
  3983. >>> t = torch.randn(1, 3)
  3984. >>> t1 = torch.randn(3, 1)
  3985. >>> t2 = torch.randn(1, 3)
  3986. >>> torch.addcmul(t, t1, t2, value=0.1)
  3987. tensor([[-0.8635, -0.6391, 1.6174],
  3988. [-0.7617, -0.5879, 1.7388],
  3989. [-0.8353, -0.6249, 1.6511]])
  3990. """
  3991. @overload
  3992. def addcmul(
  3993. self: Tensor,
  3994. value: Number | _complex,
  3995. tensor1: Tensor,
  3996. tensor2: Tensor,
  3997. *,
  3998. out: Tensor,
  3999. ) -> Tensor:
  4000. r"""
  4001. addcmul(input, tensor1, tensor2, *, value=1, out=None) -> Tensor
  4002. Performs the element-wise multiplication of :attr:`tensor1`
  4003. by :attr:`tensor2`, multiplies the result by the scalar :attr:`value`
  4004. and adds it to :attr:`input`.
  4005. .. math::
  4006. \text{out}_i = \text{input}_i + \text{value} \times \text{tensor1}_i \times \text{tensor2}_i
  4007. The shapes of :attr:`tensor`, :attr:`tensor1`, and :attr:`tensor2` must be
  4008. :ref:`broadcastable <broadcasting-semantics>`.
  4009. For inputs of type `FloatTensor` or `DoubleTensor`, :attr:`value` must be
  4010. a real number, otherwise an integer.
  4011. Args:
  4012. input (Tensor): the tensor to be added
  4013. tensor1 (Tensor): the tensor to be multiplied
  4014. tensor2 (Tensor): the tensor to be multiplied
  4015. Keyword args:
  4016. value (Number, optional): multiplier for :math:`tensor1 .* tensor2`
  4017. out (Tensor, optional): the output tensor.
  4018. Example::
  4019. >>> t = torch.randn(1, 3)
  4020. >>> t1 = torch.randn(3, 1)
  4021. >>> t2 = torch.randn(1, 3)
  4022. >>> torch.addcmul(t, t1, t2, value=0.1)
  4023. tensor([[-0.8635, -0.6391, 1.6174],
  4024. [-0.7617, -0.5879, 1.7388],
  4025. [-0.8353, -0.6249, 1.6511]])
  4026. """
  4027. @overload
  4028. def addcmul(
  4029. input: Tensor,
  4030. tensor1: Tensor,
  4031. tensor2: Tensor,
  4032. *,
  4033. value: Number | _complex = 1,
  4034. out: Tensor | None = None,
  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 addmm(
  4065. beta: Number | _complex,
  4066. self: Tensor,
  4067. alpha: Number | _complex,
  4068. mat1: Tensor,
  4069. mat2: Tensor,
  4070. ) -> Tensor:
  4071. r"""
  4072. addmm(input, mat1, mat2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  4073. Performs a matrix multiplication of the matrices :attr:`mat1` and :attr:`mat2`.
  4074. The matrix :attr:`input` is added to the final result.
  4075. If :attr:`mat1` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
  4076. :math:`(m \times p)` tensor, then :attr:`input` must be
  4077. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  4078. and :attr:`out` will be a :math:`(n \times p)` tensor.
  4079. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4080. :attr:`mat1` and :attr:`mat2` and the added matrix :attr:`input` respectively.
  4081. .. math::
  4082. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat1}_i \mathbin{@} \text{mat2}_i)
  4083. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4084. it will not be propagated.
  4085. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4086. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4087. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`. If
  4088. :attr:`input` is sparse the result will have the same layout and if :attr:`out`
  4089. is provided it must have the same layout as :attr:`input`.
  4090. .. warning::
  4091. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  4092. or may not have autograd support. If you notice missing functionality please
  4093. open a feature request.
  4094. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  4095. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  4096. Args:
  4097. input (Tensor): matrix to be added
  4098. mat1 (Tensor): the first matrix to be matrix multiplied
  4099. mat2 (Tensor): the second matrix to be matrix multiplied
  4100. out_dtype (dtype, optional): the dtype of the output tensor,
  4101. Supported only on CUDA and for torch.float32 given
  4102. torch.float16/torch.bfloat16 input dtypes
  4103. Keyword args:
  4104. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4105. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  4106. out (Tensor, optional): the output tensor.
  4107. Example::
  4108. >>> M = torch.randn(2, 3)
  4109. >>> mat1 = torch.randn(2, 3)
  4110. >>> mat2 = torch.randn(3, 3)
  4111. >>> torch.addmm(M, mat1, mat2)
  4112. tensor([[-4.8716, 1.4671, -1.3746],
  4113. [ 0.7573, -3.9555, -2.8681]])
  4114. """
  4115. @overload
  4116. def addmm(
  4117. beta: Number | _complex,
  4118. self: Tensor,
  4119. alpha: Number | _complex,
  4120. mat1: Tensor,
  4121. mat2: Tensor,
  4122. *,
  4123. out: Tensor,
  4124. ) -> Tensor:
  4125. r"""
  4126. addmm(input, mat1, mat2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  4127. Performs a matrix multiplication of the matrices :attr:`mat1` and :attr:`mat2`.
  4128. The matrix :attr:`input` is added to the final result.
  4129. If :attr:`mat1` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
  4130. :math:`(m \times p)` tensor, then :attr:`input` must be
  4131. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  4132. and :attr:`out` will be a :math:`(n \times p)` tensor.
  4133. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4134. :attr:`mat1` and :attr:`mat2` and the added matrix :attr:`input` respectively.
  4135. .. math::
  4136. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat1}_i \mathbin{@} \text{mat2}_i)
  4137. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4138. it will not be propagated.
  4139. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4140. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4141. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`. If
  4142. :attr:`input` is sparse the result will have the same layout and if :attr:`out`
  4143. is provided it must have the same layout as :attr:`input`.
  4144. .. warning::
  4145. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  4146. or may not have autograd support. If you notice missing functionality please
  4147. open a feature request.
  4148. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  4149. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  4150. Args:
  4151. input (Tensor): matrix to be added
  4152. mat1 (Tensor): the first matrix to be matrix multiplied
  4153. mat2 (Tensor): the second matrix to be matrix multiplied
  4154. out_dtype (dtype, optional): the dtype of the output tensor,
  4155. Supported only on CUDA and for torch.float32 given
  4156. torch.float16/torch.bfloat16 input dtypes
  4157. Keyword args:
  4158. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4159. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  4160. out (Tensor, optional): the output tensor.
  4161. Example::
  4162. >>> M = torch.randn(2, 3)
  4163. >>> mat1 = torch.randn(2, 3)
  4164. >>> mat2 = torch.randn(3, 3)
  4165. >>> torch.addmm(M, mat1, mat2)
  4166. tensor([[-4.8716, 1.4671, -1.3746],
  4167. [ 0.7573, -3.9555, -2.8681]])
  4168. """
  4169. @overload
  4170. def addmm(
  4171. input: Tensor,
  4172. mat1: Tensor,
  4173. mat2: Tensor,
  4174. *,
  4175. beta: Number | _complex = 1,
  4176. alpha: Number | _complex = 1,
  4177. out: Tensor | None = None,
  4178. ) -> Tensor:
  4179. r"""
  4180. addmm(input, mat1, mat2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  4181. Performs a matrix multiplication of the matrices :attr:`mat1` and :attr:`mat2`.
  4182. The matrix :attr:`input` is added to the final result.
  4183. If :attr:`mat1` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
  4184. :math:`(m \times p)` tensor, then :attr:`input` must be
  4185. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  4186. and :attr:`out` will be a :math:`(n \times p)` tensor.
  4187. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4188. :attr:`mat1` and :attr:`mat2` and the added matrix :attr:`input` respectively.
  4189. .. math::
  4190. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat1}_i \mathbin{@} \text{mat2}_i)
  4191. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4192. it will not be propagated.
  4193. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4194. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4195. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`. If
  4196. :attr:`input` is sparse the result will have the same layout and if :attr:`out`
  4197. is provided it must have the same layout as :attr:`input`.
  4198. .. warning::
  4199. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  4200. or may not have autograd support. If you notice missing functionality please
  4201. open a feature request.
  4202. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  4203. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  4204. Args:
  4205. input (Tensor): matrix to be added
  4206. mat1 (Tensor): the first matrix to be matrix multiplied
  4207. mat2 (Tensor): the second matrix to be matrix multiplied
  4208. out_dtype (dtype, optional): the dtype of the output tensor,
  4209. Supported only on CUDA and for torch.float32 given
  4210. torch.float16/torch.bfloat16 input dtypes
  4211. Keyword args:
  4212. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4213. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  4214. out (Tensor, optional): the output tensor.
  4215. Example::
  4216. >>> M = torch.randn(2, 3)
  4217. >>> mat1 = torch.randn(2, 3)
  4218. >>> mat2 = torch.randn(3, 3)
  4219. >>> torch.addmm(M, mat1, mat2)
  4220. tensor([[-4.8716, 1.4671, -1.3746],
  4221. [ 0.7573, -3.9555, -2.8681]])
  4222. """
  4223. @overload
  4224. def addmm(
  4225. input: Tensor,
  4226. mat1: Tensor,
  4227. mat2: Tensor,
  4228. out_dtype: _dtype,
  4229. *,
  4230. beta: Number | _complex = 1,
  4231. alpha: Number | _complex = 1,
  4232. out: Tensor | None = None,
  4233. ) -> Tensor:
  4234. r"""
  4235. addmm(input, mat1, mat2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  4236. Performs a matrix multiplication of the matrices :attr:`mat1` and :attr:`mat2`.
  4237. The matrix :attr:`input` is added to the final result.
  4238. If :attr:`mat1` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
  4239. :math:`(m \times p)` tensor, then :attr:`input` must be
  4240. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  4241. and :attr:`out` will be a :math:`(n \times p)` tensor.
  4242. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4243. :attr:`mat1` and :attr:`mat2` and the added matrix :attr:`input` respectively.
  4244. .. math::
  4245. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat1}_i \mathbin{@} \text{mat2}_i)
  4246. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4247. it will not be propagated.
  4248. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4249. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4250. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`. If
  4251. :attr:`input` is sparse the result will have the same layout and if :attr:`out`
  4252. is provided it must have the same layout as :attr:`input`.
  4253. .. warning::
  4254. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  4255. or may not have autograd support. If you notice missing functionality please
  4256. open a feature request.
  4257. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  4258. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  4259. Args:
  4260. input (Tensor): matrix to be added
  4261. mat1 (Tensor): the first matrix to be matrix multiplied
  4262. mat2 (Tensor): the second matrix to be matrix multiplied
  4263. out_dtype (dtype, optional): the dtype of the output tensor,
  4264. Supported only on CUDA and for torch.float32 given
  4265. torch.float16/torch.bfloat16 input dtypes
  4266. Keyword args:
  4267. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4268. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  4269. out (Tensor, optional): the output tensor.
  4270. Example::
  4271. >>> M = torch.randn(2, 3)
  4272. >>> mat1 = torch.randn(2, 3)
  4273. >>> mat2 = torch.randn(3, 3)
  4274. >>> torch.addmm(M, mat1, mat2)
  4275. tensor([[-4.8716, 1.4671, -1.3746],
  4276. [ 0.7573, -3.9555, -2.8681]])
  4277. """
  4278. @overload
  4279. def addmm(
  4280. beta: Number | _complex,
  4281. self: Tensor,
  4282. mat1: Tensor,
  4283. mat2: Tensor,
  4284. ) -> Tensor:
  4285. r"""
  4286. addmm(input, mat1, mat2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  4287. Performs a matrix multiplication of the matrices :attr:`mat1` and :attr:`mat2`.
  4288. The matrix :attr:`input` is added to the final result.
  4289. If :attr:`mat1` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
  4290. :math:`(m \times p)` tensor, then :attr:`input` must be
  4291. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  4292. and :attr:`out` will be a :math:`(n \times p)` tensor.
  4293. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4294. :attr:`mat1` and :attr:`mat2` and the added matrix :attr:`input` respectively.
  4295. .. math::
  4296. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat1}_i \mathbin{@} \text{mat2}_i)
  4297. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4298. it will not be propagated.
  4299. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4300. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4301. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`. If
  4302. :attr:`input` is sparse the result will have the same layout and if :attr:`out`
  4303. is provided it must have the same layout as :attr:`input`.
  4304. .. warning::
  4305. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  4306. or may not have autograd support. If you notice missing functionality please
  4307. open a feature request.
  4308. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  4309. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  4310. Args:
  4311. input (Tensor): matrix to be added
  4312. mat1 (Tensor): the first matrix to be matrix multiplied
  4313. mat2 (Tensor): the second matrix to be matrix multiplied
  4314. out_dtype (dtype, optional): the dtype of the output tensor,
  4315. Supported only on CUDA and for torch.float32 given
  4316. torch.float16/torch.bfloat16 input dtypes
  4317. Keyword args:
  4318. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4319. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  4320. out (Tensor, optional): the output tensor.
  4321. Example::
  4322. >>> M = torch.randn(2, 3)
  4323. >>> mat1 = torch.randn(2, 3)
  4324. >>> mat2 = torch.randn(3, 3)
  4325. >>> torch.addmm(M, mat1, mat2)
  4326. tensor([[-4.8716, 1.4671, -1.3746],
  4327. [ 0.7573, -3.9555, -2.8681]])
  4328. """
  4329. @overload
  4330. def addmm(
  4331. beta: Number | _complex,
  4332. self: Tensor,
  4333. mat1: Tensor,
  4334. mat2: Tensor,
  4335. *,
  4336. out: Tensor,
  4337. ) -> Tensor:
  4338. r"""
  4339. addmm(input, mat1, mat2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  4340. Performs a matrix multiplication of the matrices :attr:`mat1` and :attr:`mat2`.
  4341. The matrix :attr:`input` is added to the final result.
  4342. If :attr:`mat1` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
  4343. :math:`(m \times p)` tensor, then :attr:`input` must be
  4344. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  4345. and :attr:`out` will be a :math:`(n \times p)` tensor.
  4346. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4347. :attr:`mat1` and :attr:`mat2` and the added matrix :attr:`input` respectively.
  4348. .. math::
  4349. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat1}_i \mathbin{@} \text{mat2}_i)
  4350. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4351. it will not be propagated.
  4352. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4353. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4354. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`. If
  4355. :attr:`input` is sparse the result will have the same layout and if :attr:`out`
  4356. is provided it must have the same layout as :attr:`input`.
  4357. .. warning::
  4358. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  4359. or may not have autograd support. If you notice missing functionality please
  4360. open a feature request.
  4361. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  4362. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  4363. Args:
  4364. input (Tensor): matrix to be added
  4365. mat1 (Tensor): the first matrix to be matrix multiplied
  4366. mat2 (Tensor): the second matrix to be matrix multiplied
  4367. out_dtype (dtype, optional): the dtype of the output tensor,
  4368. Supported only on CUDA and for torch.float32 given
  4369. torch.float16/torch.bfloat16 input dtypes
  4370. Keyword args:
  4371. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4372. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  4373. out (Tensor, optional): the output tensor.
  4374. Example::
  4375. >>> M = torch.randn(2, 3)
  4376. >>> mat1 = torch.randn(2, 3)
  4377. >>> mat2 = torch.randn(3, 3)
  4378. >>> torch.addmm(M, mat1, mat2)
  4379. tensor([[-4.8716, 1.4671, -1.3746],
  4380. [ 0.7573, -3.9555, -2.8681]])
  4381. """
  4382. @overload
  4383. def addmv(
  4384. beta: Number | _complex,
  4385. self: Tensor,
  4386. alpha: Number | _complex,
  4387. mat: Tensor,
  4388. vec: Tensor,
  4389. ) -> Tensor:
  4390. r"""
  4391. addmv(input, mat, vec, *, beta=1, alpha=1, out=None) -> Tensor
  4392. Performs a matrix-vector product of the matrix :attr:`mat` and
  4393. the vector :attr:`vec`.
  4394. The vector :attr:`input` is added to the final result.
  4395. If :attr:`mat` is a :math:`(n \times m)` tensor, :attr:`vec` is a 1-D tensor of
  4396. size `m`, then :attr:`input` must be
  4397. :ref:`broadcastable <broadcasting-semantics>` with a 1-D tensor of size `n` and
  4398. :attr:`out` will be 1-D tensor of size `n`.
  4399. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4400. :attr:`mat` and :attr:`vec` and the added tensor :attr:`input` respectively.
  4401. .. math::
  4402. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat} \mathbin{@} \text{vec})
  4403. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4404. it will not be propagated.
  4405. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4406. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4407. Args:
  4408. input (Tensor): vector to be added
  4409. mat (Tensor): matrix to be matrix multiplied
  4410. vec (Tensor): vector to be matrix multiplied
  4411. Keyword args:
  4412. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4413. alpha (Number, optional): multiplier for :math:`mat @ vec` (:math:`\alpha`)
  4414. out (Tensor, optional): the output tensor.
  4415. Example::
  4416. >>> M = torch.randn(2)
  4417. >>> mat = torch.randn(2, 3)
  4418. >>> vec = torch.randn(3)
  4419. >>> torch.addmv(M, mat, vec)
  4420. tensor([-0.3768, -5.5565])
  4421. """
  4422. @overload
  4423. def addmv(
  4424. beta: Number | _complex,
  4425. self: Tensor,
  4426. alpha: Number | _complex,
  4427. mat: Tensor,
  4428. vec: Tensor,
  4429. *,
  4430. out: Tensor,
  4431. ) -> Tensor:
  4432. r"""
  4433. addmv(input, mat, vec, *, beta=1, alpha=1, out=None) -> Tensor
  4434. Performs a matrix-vector product of the matrix :attr:`mat` and
  4435. the vector :attr:`vec`.
  4436. The vector :attr:`input` is added to the final result.
  4437. If :attr:`mat` is a :math:`(n \times m)` tensor, :attr:`vec` is a 1-D tensor of
  4438. size `m`, then :attr:`input` must be
  4439. :ref:`broadcastable <broadcasting-semantics>` with a 1-D tensor of size `n` and
  4440. :attr:`out` will be 1-D tensor of size `n`.
  4441. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4442. :attr:`mat` and :attr:`vec` and the added tensor :attr:`input` respectively.
  4443. .. math::
  4444. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat} \mathbin{@} \text{vec})
  4445. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4446. it will not be propagated.
  4447. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4448. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4449. Args:
  4450. input (Tensor): vector to be added
  4451. mat (Tensor): matrix to be matrix multiplied
  4452. vec (Tensor): vector to be matrix multiplied
  4453. Keyword args:
  4454. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4455. alpha (Number, optional): multiplier for :math:`mat @ vec` (:math:`\alpha`)
  4456. out (Tensor, optional): the output tensor.
  4457. Example::
  4458. >>> M = torch.randn(2)
  4459. >>> mat = torch.randn(2, 3)
  4460. >>> vec = torch.randn(3)
  4461. >>> torch.addmv(M, mat, vec)
  4462. tensor([-0.3768, -5.5565])
  4463. """
  4464. @overload
  4465. def addmv(
  4466. input: Tensor,
  4467. mat: Tensor,
  4468. vec: Tensor,
  4469. *,
  4470. beta: Number | _complex = 1,
  4471. alpha: Number | _complex = 1,
  4472. out: Tensor | None = None,
  4473. ) -> Tensor:
  4474. r"""
  4475. addmv(input, mat, vec, *, beta=1, alpha=1, out=None) -> Tensor
  4476. Performs a matrix-vector product of the matrix :attr:`mat` and
  4477. the vector :attr:`vec`.
  4478. The vector :attr:`input` is added to the final result.
  4479. If :attr:`mat` is a :math:`(n \times m)` tensor, :attr:`vec` is a 1-D tensor of
  4480. size `m`, then :attr:`input` must be
  4481. :ref:`broadcastable <broadcasting-semantics>` with a 1-D tensor of size `n` and
  4482. :attr:`out` will be 1-D tensor of size `n`.
  4483. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4484. :attr:`mat` and :attr:`vec` and the added tensor :attr:`input` respectively.
  4485. .. math::
  4486. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat} \mathbin{@} \text{vec})
  4487. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4488. it will not be propagated.
  4489. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4490. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4491. Args:
  4492. input (Tensor): vector to be added
  4493. mat (Tensor): matrix to be matrix multiplied
  4494. vec (Tensor): vector to be matrix multiplied
  4495. Keyword args:
  4496. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4497. alpha (Number, optional): multiplier for :math:`mat @ vec` (:math:`\alpha`)
  4498. out (Tensor, optional): the output tensor.
  4499. Example::
  4500. >>> M = torch.randn(2)
  4501. >>> mat = torch.randn(2, 3)
  4502. >>> vec = torch.randn(3)
  4503. >>> torch.addmv(M, mat, vec)
  4504. tensor([-0.3768, -5.5565])
  4505. """
  4506. @overload
  4507. def addmv(
  4508. beta: Number | _complex,
  4509. self: Tensor,
  4510. mat: Tensor,
  4511. vec: Tensor,
  4512. ) -> Tensor:
  4513. r"""
  4514. addmv(input, mat, vec, *, beta=1, alpha=1, out=None) -> Tensor
  4515. Performs a matrix-vector product of the matrix :attr:`mat` and
  4516. the vector :attr:`vec`.
  4517. The vector :attr:`input` is added to the final result.
  4518. If :attr:`mat` is a :math:`(n \times m)` tensor, :attr:`vec` is a 1-D tensor of
  4519. size `m`, then :attr:`input` must be
  4520. :ref:`broadcastable <broadcasting-semantics>` with a 1-D tensor of size `n` and
  4521. :attr:`out` will be 1-D tensor of size `n`.
  4522. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4523. :attr:`mat` and :attr:`vec` and the added tensor :attr:`input` respectively.
  4524. .. math::
  4525. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat} \mathbin{@} \text{vec})
  4526. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4527. it will not be propagated.
  4528. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4529. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4530. Args:
  4531. input (Tensor): vector to be added
  4532. mat (Tensor): matrix to be matrix multiplied
  4533. vec (Tensor): vector to be matrix multiplied
  4534. Keyword args:
  4535. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4536. alpha (Number, optional): multiplier for :math:`mat @ vec` (:math:`\alpha`)
  4537. out (Tensor, optional): the output tensor.
  4538. Example::
  4539. >>> M = torch.randn(2)
  4540. >>> mat = torch.randn(2, 3)
  4541. >>> vec = torch.randn(3)
  4542. >>> torch.addmv(M, mat, vec)
  4543. tensor([-0.3768, -5.5565])
  4544. """
  4545. @overload
  4546. def addmv(
  4547. beta: Number | _complex,
  4548. self: Tensor,
  4549. mat: Tensor,
  4550. vec: Tensor,
  4551. *,
  4552. out: Tensor,
  4553. ) -> Tensor:
  4554. r"""
  4555. addmv(input, mat, vec, *, beta=1, alpha=1, out=None) -> Tensor
  4556. Performs a matrix-vector product of the matrix :attr:`mat` and
  4557. the vector :attr:`vec`.
  4558. The vector :attr:`input` is added to the final result.
  4559. If :attr:`mat` is a :math:`(n \times m)` tensor, :attr:`vec` is a 1-D tensor of
  4560. size `m`, then :attr:`input` must be
  4561. :ref:`broadcastable <broadcasting-semantics>` with a 1-D tensor of size `n` and
  4562. :attr:`out` will be 1-D tensor of size `n`.
  4563. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4564. :attr:`mat` and :attr:`vec` and the added tensor :attr:`input` respectively.
  4565. .. math::
  4566. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat} \mathbin{@} \text{vec})
  4567. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4568. it will not be propagated.
  4569. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4570. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4571. Args:
  4572. input (Tensor): vector to be added
  4573. mat (Tensor): matrix to be matrix multiplied
  4574. vec (Tensor): vector to be matrix multiplied
  4575. Keyword args:
  4576. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4577. alpha (Number, optional): multiplier for :math:`mat @ vec` (:math:`\alpha`)
  4578. out (Tensor, optional): the output tensor.
  4579. Example::
  4580. >>> M = torch.randn(2)
  4581. >>> mat = torch.randn(2, 3)
  4582. >>> vec = torch.randn(3)
  4583. >>> torch.addmv(M, mat, vec)
  4584. tensor([-0.3768, -5.5565])
  4585. """
  4586. @overload
  4587. def addmv_(
  4588. beta: Number | _complex,
  4589. self: Tensor,
  4590. alpha: Number | _complex,
  4591. mat: Tensor,
  4592. vec: Tensor,
  4593. ) -> Tensor: ...
  4594. @overload
  4595. def addmv_(
  4596. input: Tensor,
  4597. mat: Tensor,
  4598. vec: Tensor,
  4599. *,
  4600. beta: Number | _complex = 1,
  4601. alpha: Number | _complex = 1,
  4602. ) -> Tensor: ...
  4603. @overload
  4604. def addmv_(
  4605. beta: Number | _complex,
  4606. self: Tensor,
  4607. mat: Tensor,
  4608. vec: Tensor,
  4609. ) -> Tensor: ...
  4610. @overload
  4611. def addr(
  4612. beta: Number | _complex,
  4613. self: Tensor,
  4614. alpha: Number | _complex,
  4615. vec1: Tensor,
  4616. vec2: Tensor,
  4617. ) -> Tensor:
  4618. r"""
  4619. addr(input, vec1, vec2, *, beta=1, alpha=1, out=None) -> Tensor
  4620. Performs the outer-product of vectors :attr:`vec1` and :attr:`vec2`
  4621. and adds it to the matrix :attr:`input`.
  4622. Optional values :attr:`beta` and :attr:`alpha` are scaling factors on the
  4623. outer product between :attr:`vec1` and :attr:`vec2` and the added matrix
  4624. :attr:`input` respectively.
  4625. .. math::
  4626. \text{out} = \beta\ \text{input} + \alpha\ (\text{vec1} \otimes \text{vec2})
  4627. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4628. it will not be propagated.
  4629. If :attr:`vec1` is a vector of size `n` and :attr:`vec2` is a vector
  4630. of size `m`, then :attr:`input` must be
  4631. :ref:`broadcastable <broadcasting-semantics>` with a matrix of size
  4632. :math:`(n \times m)` and :attr:`out` will be a matrix of size
  4633. :math:`(n \times m)`.
  4634. Args:
  4635. input (Tensor): matrix to be added
  4636. vec1 (Tensor): the first vector of the outer product
  4637. vec2 (Tensor): the second vector of the outer product
  4638. Keyword args:
  4639. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4640. alpha (Number, optional): multiplier for :math:`\text{vec1} \otimes \text{vec2}` (:math:`\alpha`)
  4641. out (Tensor, optional): the output tensor.
  4642. Example::
  4643. >>> vec1 = torch.arange(1., 4.)
  4644. >>> vec2 = torch.arange(1., 3.)
  4645. >>> M = torch.zeros(3, 2)
  4646. >>> torch.addr(M, vec1, vec2)
  4647. tensor([[ 1., 2.],
  4648. [ 2., 4.],
  4649. [ 3., 6.]])
  4650. """
  4651. @overload
  4652. def addr(
  4653. beta: Number | _complex,
  4654. self: Tensor,
  4655. alpha: Number | _complex,
  4656. vec1: Tensor,
  4657. vec2: Tensor,
  4658. *,
  4659. out: Tensor,
  4660. ) -> Tensor:
  4661. r"""
  4662. addr(input, vec1, vec2, *, beta=1, alpha=1, out=None) -> Tensor
  4663. Performs the outer-product of vectors :attr:`vec1` and :attr:`vec2`
  4664. and adds it to the matrix :attr:`input`.
  4665. Optional values :attr:`beta` and :attr:`alpha` are scaling factors on the
  4666. outer product between :attr:`vec1` and :attr:`vec2` and the added matrix
  4667. :attr:`input` respectively.
  4668. .. math::
  4669. \text{out} = \beta\ \text{input} + \alpha\ (\text{vec1} \otimes \text{vec2})
  4670. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4671. it will not be propagated.
  4672. If :attr:`vec1` is a vector of size `n` and :attr:`vec2` is a vector
  4673. of size `m`, then :attr:`input` must be
  4674. :ref:`broadcastable <broadcasting-semantics>` with a matrix of size
  4675. :math:`(n \times m)` and :attr:`out` will be a matrix of size
  4676. :math:`(n \times m)`.
  4677. Args:
  4678. input (Tensor): matrix to be added
  4679. vec1 (Tensor): the first vector of the outer product
  4680. vec2 (Tensor): the second vector of the outer product
  4681. Keyword args:
  4682. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4683. alpha (Number, optional): multiplier for :math:`\text{vec1} \otimes \text{vec2}` (:math:`\alpha`)
  4684. out (Tensor, optional): the output tensor.
  4685. Example::
  4686. >>> vec1 = torch.arange(1., 4.)
  4687. >>> vec2 = torch.arange(1., 3.)
  4688. >>> M = torch.zeros(3, 2)
  4689. >>> torch.addr(M, vec1, vec2)
  4690. tensor([[ 1., 2.],
  4691. [ 2., 4.],
  4692. [ 3., 6.]])
  4693. """
  4694. @overload
  4695. def addr(
  4696. input: Tensor,
  4697. vec1: Tensor,
  4698. vec2: Tensor,
  4699. *,
  4700. beta: Number | _complex = 1,
  4701. alpha: Number | _complex = 1,
  4702. out: Tensor | None = None,
  4703. ) -> Tensor:
  4704. r"""
  4705. addr(input, vec1, vec2, *, beta=1, alpha=1, out=None) -> Tensor
  4706. Performs the outer-product of vectors :attr:`vec1` and :attr:`vec2`
  4707. and adds it to the matrix :attr:`input`.
  4708. Optional values :attr:`beta` and :attr:`alpha` are scaling factors on the
  4709. outer product between :attr:`vec1` and :attr:`vec2` and the added matrix
  4710. :attr:`input` respectively.
  4711. .. math::
  4712. \text{out} = \beta\ \text{input} + \alpha\ (\text{vec1} \otimes \text{vec2})
  4713. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4714. it will not be propagated.
  4715. If :attr:`vec1` is a vector of size `n` and :attr:`vec2` is a vector
  4716. of size `m`, then :attr:`input` must be
  4717. :ref:`broadcastable <broadcasting-semantics>` with a matrix of size
  4718. :math:`(n \times m)` and :attr:`out` will be a matrix of size
  4719. :math:`(n \times m)`.
  4720. Args:
  4721. input (Tensor): matrix to be added
  4722. vec1 (Tensor): the first vector of the outer product
  4723. vec2 (Tensor): the second vector of the outer product
  4724. Keyword args:
  4725. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4726. alpha (Number, optional): multiplier for :math:`\text{vec1} \otimes \text{vec2}` (:math:`\alpha`)
  4727. out (Tensor, optional): the output tensor.
  4728. Example::
  4729. >>> vec1 = torch.arange(1., 4.)
  4730. >>> vec2 = torch.arange(1., 3.)
  4731. >>> M = torch.zeros(3, 2)
  4732. >>> torch.addr(M, vec1, vec2)
  4733. tensor([[ 1., 2.],
  4734. [ 2., 4.],
  4735. [ 3., 6.]])
  4736. """
  4737. @overload
  4738. def addr(
  4739. beta: Number | _complex,
  4740. self: Tensor,
  4741. vec1: Tensor,
  4742. vec2: Tensor,
  4743. ) -> Tensor:
  4744. r"""
  4745. addr(input, vec1, vec2, *, beta=1, alpha=1, out=None) -> Tensor
  4746. Performs the outer-product of vectors :attr:`vec1` and :attr:`vec2`
  4747. and adds it to the matrix :attr:`input`.
  4748. Optional values :attr:`beta` and :attr:`alpha` are scaling factors on the
  4749. outer product between :attr:`vec1` and :attr:`vec2` and the added matrix
  4750. :attr:`input` respectively.
  4751. .. math::
  4752. \text{out} = \beta\ \text{input} + \alpha\ (\text{vec1} \otimes \text{vec2})
  4753. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4754. it will not be propagated.
  4755. If :attr:`vec1` is a vector of size `n` and :attr:`vec2` is a vector
  4756. of size `m`, then :attr:`input` must be
  4757. :ref:`broadcastable <broadcasting-semantics>` with a matrix of size
  4758. :math:`(n \times m)` and :attr:`out` will be a matrix of size
  4759. :math:`(n \times m)`.
  4760. Args:
  4761. input (Tensor): matrix to be added
  4762. vec1 (Tensor): the first vector of the outer product
  4763. vec2 (Tensor): the second vector of the outer product
  4764. Keyword args:
  4765. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4766. alpha (Number, optional): multiplier for :math:`\text{vec1} \otimes \text{vec2}` (:math:`\alpha`)
  4767. out (Tensor, optional): the output tensor.
  4768. Example::
  4769. >>> vec1 = torch.arange(1., 4.)
  4770. >>> vec2 = torch.arange(1., 3.)
  4771. >>> M = torch.zeros(3, 2)
  4772. >>> torch.addr(M, vec1, vec2)
  4773. tensor([[ 1., 2.],
  4774. [ 2., 4.],
  4775. [ 3., 6.]])
  4776. """
  4777. @overload
  4778. def addr(
  4779. beta: Number | _complex,
  4780. self: Tensor,
  4781. vec1: Tensor,
  4782. vec2: Tensor,
  4783. *,
  4784. out: Tensor,
  4785. ) -> Tensor:
  4786. r"""
  4787. addr(input, vec1, vec2, *, beta=1, alpha=1, out=None) -> Tensor
  4788. Performs the outer-product of vectors :attr:`vec1` and :attr:`vec2`
  4789. and adds it to the matrix :attr:`input`.
  4790. Optional values :attr:`beta` and :attr:`alpha` are scaling factors on the
  4791. outer product between :attr:`vec1` and :attr:`vec2` and the added matrix
  4792. :attr:`input` respectively.
  4793. .. math::
  4794. \text{out} = \beta\ \text{input} + \alpha\ (\text{vec1} \otimes \text{vec2})
  4795. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4796. it will not be propagated.
  4797. If :attr:`vec1` is a vector of size `n` and :attr:`vec2` is a vector
  4798. of size `m`, then :attr:`input` must be
  4799. :ref:`broadcastable <broadcasting-semantics>` with a matrix of size
  4800. :math:`(n \times m)` and :attr:`out` will be a matrix of size
  4801. :math:`(n \times m)`.
  4802. Args:
  4803. input (Tensor): matrix to be added
  4804. vec1 (Tensor): the first vector of the outer product
  4805. vec2 (Tensor): the second vector of the outer product
  4806. Keyword args:
  4807. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4808. alpha (Number, optional): multiplier for :math:`\text{vec1} \otimes \text{vec2}` (:math:`\alpha`)
  4809. out (Tensor, optional): the output tensor.
  4810. Example::
  4811. >>> vec1 = torch.arange(1., 4.)
  4812. >>> vec2 = torch.arange(1., 3.)
  4813. >>> M = torch.zeros(3, 2)
  4814. >>> torch.addr(M, vec1, vec2)
  4815. tensor([[ 1., 2.],
  4816. [ 2., 4.],
  4817. [ 3., 6.]])
  4818. """
  4819. def adjoint(input: Tensor) -> Tensor:
  4820. r"""
  4821. adjoint(input: Tensor) -> Tensor
  4822. Returns a view of the tensor conjugated and with the last two dimensions transposed.
  4823. ``x.adjoint()`` is equivalent to ``x.transpose(-2, -1).conj()`` for complex tensors and
  4824. to ``x.transpose(-2, -1)`` for real tensors.
  4825. Args:
  4826. {input}
  4827. Example::
  4828. >>> x = torch.arange(4, dtype=torch.float)
  4829. >>> A = torch.complex(x, x).reshape(2, 2)
  4830. >>> A
  4831. tensor([[0.+0.j, 1.+1.j],
  4832. [2.+2.j, 3.+3.j]])
  4833. >>> A.adjoint()
  4834. tensor([[0.-0.j, 2.-2.j],
  4835. [1.-1.j, 3.-3.j]])
  4836. >>> (A.adjoint() == A.mH).all()
  4837. tensor(True)
  4838. """
  4839. def affine_grid_generator(
  4840. theta: Tensor,
  4841. size: Sequence[_int | SymInt],
  4842. align_corners: _bool,
  4843. ) -> Tensor: ...
  4844. def alias_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  4845. r"""
  4846. Performs the same operation as :func:`torch.alias`, but all output tensors
  4847. are freshly created instead of aliasing the input.
  4848. """
  4849. @overload
  4850. def all(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  4851. r"""
  4852. all(input: Tensor, *, out=None) -> Tensor
  4853. Tests if all elements in :attr:`input` evaluate to `True`.
  4854. .. note:: This function matches the behaviour of NumPy in returning
  4855. output of dtype `bool` for all supported dtypes except `uint8`.
  4856. For `uint8` the dtype of output is `uint8` itself.
  4857. Args:
  4858. input (Tensor): the input tensor.
  4859. Keyword args:
  4860. out (Tensor, optional): the output tensor.
  4861. Example::
  4862. >>> a = torch.rand(1, 2).bool()
  4863. >>> a
  4864. tensor([[False, True]], dtype=torch.bool)
  4865. >>> torch.all(a)
  4866. tensor(False, dtype=torch.bool)
  4867. >>> a = torch.arange(0, 3)
  4868. >>> a
  4869. tensor([0, 1, 2])
  4870. >>> torch.all(a)
  4871. tensor(False)
  4872. .. function:: all(input, dim, keepdim=False, *, out=None) -> Tensor
  4873. :noindex:
  4874. For each row of :attr:`input` in the given dimension :attr:`dim`,
  4875. returns `True` if all elements in the row evaluate to `True` and `False` otherwise.
  4876. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  4877. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  4878. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  4879. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  4880. Args:
  4881. input (Tensor): the input tensor.
  4882. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  4883. If ``None``, all dimensions are reduced.
  4884. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  4885. Keyword args:
  4886. out (Tensor, optional): the output tensor.
  4887. Example::
  4888. >>> a = torch.rand(4, 2).bool()
  4889. >>> a
  4890. tensor([[True, True],
  4891. [True, False],
  4892. [True, True],
  4893. [True, True]], dtype=torch.bool)
  4894. >>> torch.all(a, dim=1)
  4895. tensor([ True, False, True, True], dtype=torch.bool)
  4896. >>> torch.all(a, dim=0)
  4897. tensor([ True, False], dtype=torch.bool)
  4898. """
  4899. @overload
  4900. def all(
  4901. input: Tensor,
  4902. dim: _size | None = None,
  4903. keepdim: _bool = False,
  4904. *,
  4905. out: Tensor | None = None,
  4906. ) -> Tensor:
  4907. r"""
  4908. all(input: Tensor, *, out=None) -> Tensor
  4909. Tests if all elements in :attr:`input` evaluate to `True`.
  4910. .. note:: This function matches the behaviour of NumPy in returning
  4911. output of dtype `bool` for all supported dtypes except `uint8`.
  4912. For `uint8` the dtype of output is `uint8` itself.
  4913. Args:
  4914. input (Tensor): the input tensor.
  4915. Keyword args:
  4916. out (Tensor, optional): the output tensor.
  4917. Example::
  4918. >>> a = torch.rand(1, 2).bool()
  4919. >>> a
  4920. tensor([[False, True]], dtype=torch.bool)
  4921. >>> torch.all(a)
  4922. tensor(False, dtype=torch.bool)
  4923. >>> a = torch.arange(0, 3)
  4924. >>> a
  4925. tensor([0, 1, 2])
  4926. >>> torch.all(a)
  4927. tensor(False)
  4928. .. function:: all(input, dim, keepdim=False, *, out=None) -> Tensor
  4929. :noindex:
  4930. For each row of :attr:`input` in the given dimension :attr:`dim`,
  4931. returns `True` if all elements in the row evaluate to `True` and `False` otherwise.
  4932. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  4933. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  4934. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  4935. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  4936. Args:
  4937. input (Tensor): the input tensor.
  4938. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  4939. If ``None``, all dimensions are reduced.
  4940. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  4941. Keyword args:
  4942. out (Tensor, optional): the output tensor.
  4943. Example::
  4944. >>> a = torch.rand(4, 2).bool()
  4945. >>> a
  4946. tensor([[True, True],
  4947. [True, False],
  4948. [True, True],
  4949. [True, True]], dtype=torch.bool)
  4950. >>> torch.all(a, dim=1)
  4951. tensor([ True, False, True, True], dtype=torch.bool)
  4952. >>> torch.all(a, dim=0)
  4953. tensor([ True, False], dtype=torch.bool)
  4954. """
  4955. @overload
  4956. def all(
  4957. input: Tensor,
  4958. dim: _int,
  4959. keepdim: _bool = False,
  4960. *,
  4961. out: Tensor | None = None,
  4962. ) -> Tensor:
  4963. r"""
  4964. all(input: Tensor, *, out=None) -> Tensor
  4965. Tests if all elements in :attr:`input` evaluate to `True`.
  4966. .. note:: This function matches the behaviour of NumPy in returning
  4967. output of dtype `bool` for all supported dtypes except `uint8`.
  4968. For `uint8` the dtype of output is `uint8` itself.
  4969. Args:
  4970. input (Tensor): the input tensor.
  4971. Keyword args:
  4972. out (Tensor, optional): the output tensor.
  4973. Example::
  4974. >>> a = torch.rand(1, 2).bool()
  4975. >>> a
  4976. tensor([[False, True]], dtype=torch.bool)
  4977. >>> torch.all(a)
  4978. tensor(False, dtype=torch.bool)
  4979. >>> a = torch.arange(0, 3)
  4980. >>> a
  4981. tensor([0, 1, 2])
  4982. >>> torch.all(a)
  4983. tensor(False)
  4984. .. function:: all(input, dim, keepdim=False, *, out=None) -> Tensor
  4985. :noindex:
  4986. For each row of :attr:`input` in the given dimension :attr:`dim`,
  4987. returns `True` if all elements in the row evaluate to `True` and `False` otherwise.
  4988. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  4989. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  4990. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  4991. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  4992. Args:
  4993. input (Tensor): the input tensor.
  4994. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  4995. If ``None``, all dimensions are reduced.
  4996. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  4997. Keyword args:
  4998. out (Tensor, optional): the output tensor.
  4999. Example::
  5000. >>> a = torch.rand(4, 2).bool()
  5001. >>> a
  5002. tensor([[True, True],
  5003. [True, False],
  5004. [True, True],
  5005. [True, True]], dtype=torch.bool)
  5006. >>> torch.all(a, dim=1)
  5007. tensor([ True, False, True, True], dtype=torch.bool)
  5008. >>> torch.all(a, dim=0)
  5009. tensor([ True, False], dtype=torch.bool)
  5010. """
  5011. @overload
  5012. def all(
  5013. input: Tensor,
  5014. dim: str | EllipsisType | None,
  5015. keepdim: _bool = False,
  5016. *,
  5017. out: Tensor | None = None,
  5018. ) -> Tensor:
  5019. r"""
  5020. all(input: Tensor, *, out=None) -> Tensor
  5021. Tests if all elements in :attr:`input` evaluate to `True`.
  5022. .. note:: This function matches the behaviour of NumPy in returning
  5023. output of dtype `bool` for all supported dtypes except `uint8`.
  5024. For `uint8` the dtype of output is `uint8` itself.
  5025. Args:
  5026. input (Tensor): the input tensor.
  5027. Keyword args:
  5028. out (Tensor, optional): the output tensor.
  5029. Example::
  5030. >>> a = torch.rand(1, 2).bool()
  5031. >>> a
  5032. tensor([[False, True]], dtype=torch.bool)
  5033. >>> torch.all(a)
  5034. tensor(False, dtype=torch.bool)
  5035. >>> a = torch.arange(0, 3)
  5036. >>> a
  5037. tensor([0, 1, 2])
  5038. >>> torch.all(a)
  5039. tensor(False)
  5040. .. function:: all(input, dim, keepdim=False, *, out=None) -> Tensor
  5041. :noindex:
  5042. For each row of :attr:`input` in the given dimension :attr:`dim`,
  5043. returns `True` if all elements in the row evaluate to `True` and `False` otherwise.
  5044. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  5045. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  5046. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  5047. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  5048. Args:
  5049. input (Tensor): the input tensor.
  5050. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  5051. If ``None``, all dimensions are reduced.
  5052. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5053. Keyword args:
  5054. out (Tensor, optional): the output tensor.
  5055. Example::
  5056. >>> a = torch.rand(4, 2).bool()
  5057. >>> a
  5058. tensor([[True, True],
  5059. [True, False],
  5060. [True, True],
  5061. [True, True]], dtype=torch.bool)
  5062. >>> torch.all(a, dim=1)
  5063. tensor([ True, False, True, True], dtype=torch.bool)
  5064. >>> torch.all(a, dim=0)
  5065. tensor([ True, False], dtype=torch.bool)
  5066. """
  5067. def allclose(
  5068. input: Tensor,
  5069. other: Tensor,
  5070. rtol: _float = 1e-05,
  5071. atol: _float = 1e-08,
  5072. equal_nan: _bool = False,
  5073. ) -> _bool:
  5074. r"""
  5075. allclose(input: Tensor, other: Tensor, rtol: float = 1e-05, atol: float = 1e-08, equal_nan: bool = False) -> bool
  5076. This function checks if :attr:`input` and :attr:`other` satisfy the condition:
  5077. .. math::
  5078. \lvert \text{input}_i - \text{other}_i \rvert \leq \texttt{atol} + \texttt{rtol} \times \lvert \text{other}_i \rvert
  5079. elementwise, for all elements of :attr:`input` and :attr:`other`. The behaviour of this function is analogous to
  5080. `numpy.allclose <https://numpy.org/doc/stable/reference/generated/numpy.allclose.html>`_
  5081. Args:
  5082. input (Tensor): first tensor to compare
  5083. other (Tensor): second tensor to compare
  5084. atol (float, optional): absolute tolerance. Default: 1e-08
  5085. rtol (float, optional): relative tolerance. Default: 1e-05
  5086. equal_nan (bool, optional): if ``True``, then two ``NaN`` s will be considered equal. Default: ``False``
  5087. Example::
  5088. >>> torch.allclose(torch.tensor([10000., 1e-07]), torch.tensor([10000.1, 1e-08]))
  5089. False
  5090. >>> torch.allclose(torch.tensor([10000., 1e-08]), torch.tensor([10000.1, 1e-09]))
  5091. True
  5092. >>> torch.allclose(torch.tensor([1.0, float('nan')]), torch.tensor([1.0, float('nan')]))
  5093. False
  5094. >>> torch.allclose(torch.tensor([1.0, float('nan')]), torch.tensor([1.0, float('nan')]), equal_nan=True)
  5095. True
  5096. """
  5097. def alpha_dropout(input: Tensor, p: _float, train: _bool) -> Tensor: ...
  5098. def alpha_dropout_(input: Tensor, p: _float, train: _bool) -> Tensor: ...
  5099. def amax(
  5100. input: Tensor,
  5101. dim: _int | _size = (),
  5102. keepdim: _bool = False,
  5103. *,
  5104. out: Tensor | None = None,
  5105. ) -> Tensor:
  5106. r"""
  5107. amax(input, dim, keepdim=False, *, out=None) -> Tensor
  5108. Returns the maximum value of each slice of the :attr:`input` tensor in the given
  5109. dimension(s) :attr:`dim`.
  5110. .. note::
  5111. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  5112. - ``amax``/``amin`` supports reducing on multiple dimensions,
  5113. - ``amax``/``amin`` does not return indices.
  5114. Both ``amax``/``amin`` evenly distribute gradients between equal values
  5115. when there are multiple input elements with the same minimum or maximum value.
  5116. For ``max``/``min``:
  5117. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  5118. - If reduce over one specified axis, only propagate to the indexed element.
  5119. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  5120. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  5121. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  5122. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  5123. Args:
  5124. input (Tensor): the input tensor.
  5125. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  5126. If ``None``, all dimensions are reduced.
  5127. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5128. Keyword args:
  5129. out (Tensor, optional): the output tensor.
  5130. Example::
  5131. >>> a = torch.randn(4, 4)
  5132. >>> a
  5133. tensor([[ 0.8177, 1.4878, -0.2491, 0.9130],
  5134. [-0.7158, 1.1775, 2.0992, 0.4817],
  5135. [-0.0053, 0.0164, -1.3738, -0.0507],
  5136. [ 1.9700, 1.1106, -1.0318, -1.0816]])
  5137. >>> torch.amax(a, 1)
  5138. tensor([1.4878, 2.0992, 0.0164, 1.9700])
  5139. """
  5140. def amin(
  5141. input: Tensor,
  5142. dim: _int | _size = (),
  5143. keepdim: _bool = False,
  5144. *,
  5145. out: Tensor | None = None,
  5146. ) -> Tensor:
  5147. r"""
  5148. amin(input, dim, keepdim=False, *, out=None) -> Tensor
  5149. Returns the minimum value of each slice of the :attr:`input` tensor in the given
  5150. dimension(s) :attr:`dim`.
  5151. .. note::
  5152. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  5153. - ``amax``/``amin`` supports reducing on multiple dimensions,
  5154. - ``amax``/``amin`` does not return indices.
  5155. Both ``amax``/``amin`` evenly distribute gradients between equal values
  5156. when there are multiple input elements with the same minimum or maximum value.
  5157. For ``max``/``min``:
  5158. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  5159. - If reduce over one specified axis, only propagate to the indexed element.
  5160. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  5161. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  5162. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  5163. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  5164. Args:
  5165. input (Tensor): the input tensor.
  5166. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  5167. If ``None``, all dimensions are reduced.
  5168. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5169. Keyword args:
  5170. out (Tensor, optional): the output tensor.
  5171. Example::
  5172. >>> a = torch.randn(4, 4)
  5173. >>> a
  5174. tensor([[ 0.6451, -0.4866, 0.2987, -1.3312],
  5175. [-0.5744, 1.2980, 1.8397, -0.2713],
  5176. [ 0.9128, 0.9214, -1.7268, -0.2995],
  5177. [ 0.9023, 0.4853, 0.9075, -1.6165]])
  5178. >>> torch.amin(a, 1)
  5179. tensor([-1.3312, -0.5744, -1.7268, -1.6165])
  5180. """
  5181. def aminmax(
  5182. input: Tensor,
  5183. *,
  5184. dim: _int | None = None,
  5185. keepdim: _bool = False,
  5186. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  5187. ) -> torch.return_types.aminmax:
  5188. r"""
  5189. aminmax(input, *, dim=None, keepdim=False, out=None) -> (Tensor min, Tensor max)
  5190. Computes the minimum and maximum values of the :attr:`input` tensor.
  5191. Args:
  5192. input (Tensor):
  5193. The input tensor
  5194. Keyword Args:
  5195. dim (Optional[int]):
  5196. The dimension along which to compute the values. If `None`,
  5197. computes the values over the entire :attr:`input` tensor.
  5198. Default is `None`.
  5199. keepdim (bool):
  5200. If `True`, the reduced dimensions will be kept in the output
  5201. tensor as dimensions with size 1 for broadcasting, otherwise
  5202. they will be removed, as if calling (:func:`torch.squeeze`).
  5203. Default is `False`.
  5204. out (Optional[Tuple[Tensor, Tensor]]):
  5205. Optional tensors on which to write the result. Must have the same
  5206. shape and dtype as the expected output.
  5207. Default is `None`.
  5208. Returns:
  5209. A named tuple `(min, max)` containing the minimum and maximum values.
  5210. Raises:
  5211. RuntimeError
  5212. If any of the dimensions to compute the values over has size 0.
  5213. .. note::
  5214. NaN values are propagated to the output if at least one value is NaN.
  5215. .. seealso::
  5216. :func:`torch.amin` computes just the minimum value
  5217. :func:`torch.amax` computes just the maximum value
  5218. Example::
  5219. >>> torch.aminmax(torch.tensor([1, -3, 5]))
  5220. torch.return_types.aminmax(
  5221. min=tensor(-3),
  5222. max=tensor(5))
  5223. >>> # aminmax propagates NaNs
  5224. >>> torch.aminmax(torch.tensor([1, -3, 5, torch.nan]))
  5225. torch.return_types.aminmax(
  5226. min=tensor(nan),
  5227. max=tensor(nan))
  5228. >>> t = torch.arange(10).view(2, 5)
  5229. >>> t
  5230. tensor([[0, 1, 2, 3, 4],
  5231. [5, 6, 7, 8, 9]])
  5232. >>> t.aminmax(dim=0, keepdim=True)
  5233. torch.return_types.aminmax(
  5234. min=tensor([[0, 1, 2, 3, 4]]),
  5235. max=tensor([[5, 6, 7, 8, 9]]))
  5236. """
  5237. def angle(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  5238. r"""
  5239. angle(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5240. Computes the element-wise angle (in radians) of the given :attr:`input` tensor.
  5241. .. math::
  5242. \text{out}_{i} = angle(\text{input}_{i})
  5243. Args:
  5244. input (Tensor): the input tensor.
  5245. Keyword args:
  5246. out (Tensor, optional): the output tensor.
  5247. .. note:: Starting in PyTorch 1.8, angle returns pi for negative real numbers,
  5248. zero for non-negative real numbers, and propagates NaNs. Previously
  5249. the function would return zero for all real numbers and not propagate
  5250. floating-point NaNs.
  5251. Example::
  5252. >>> torch.angle(torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j]))*180/3.14159
  5253. tensor([ 135., 135, -45])
  5254. """
  5255. @overload
  5256. def any(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  5257. r"""
  5258. any(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5259. Tests if any element in :attr:`input` evaluates to `True`.
  5260. .. note:: This function matches the behaviour of NumPy in returning
  5261. output of dtype `bool` for all supported dtypes except `uint8`.
  5262. For `uint8` the dtype of output is `uint8` itself.
  5263. Args:
  5264. input (Tensor): the input tensor.
  5265. Keyword args:
  5266. out (Tensor, optional): the output tensor.
  5267. Example::
  5268. >>> a = torch.rand(1, 2).bool()
  5269. >>> a
  5270. tensor([[False, True]], dtype=torch.bool)
  5271. >>> torch.any(a)
  5272. tensor(True, dtype=torch.bool)
  5273. >>> a = torch.arange(0, 3)
  5274. >>> a
  5275. tensor([0, 1, 2])
  5276. >>> torch.any(a)
  5277. tensor(True)
  5278. .. function:: any(input, dim, keepdim=False, *, out=None) -> Tensor
  5279. :noindex:
  5280. For each row of :attr:`input` in the given dimension :attr:`dim`,
  5281. returns `True` if any element in the row evaluate to `True` and `False` otherwise.
  5282. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  5283. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  5284. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  5285. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  5286. Args:
  5287. input (Tensor): the input tensor.
  5288. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  5289. If ``None``, all dimensions are reduced.
  5290. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5291. Keyword args:
  5292. out (Tensor, optional): the output tensor.
  5293. Example::
  5294. >>> a = torch.randn(4, 2) < 0
  5295. >>> a
  5296. tensor([[ True, True],
  5297. [False, True],
  5298. [ True, True],
  5299. [False, False]])
  5300. >>> torch.any(a, 1)
  5301. tensor([ True, True, True, False])
  5302. >>> torch.any(a, 0)
  5303. tensor([True, True])
  5304. """
  5305. @overload
  5306. def any(
  5307. input: Tensor,
  5308. dim: _size | None = None,
  5309. keepdim: _bool = False,
  5310. *,
  5311. out: Tensor | None = None,
  5312. ) -> Tensor:
  5313. r"""
  5314. any(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5315. Tests if any element in :attr:`input` evaluates to `True`.
  5316. .. note:: This function matches the behaviour of NumPy in returning
  5317. output of dtype `bool` for all supported dtypes except `uint8`.
  5318. For `uint8` the dtype of output is `uint8` itself.
  5319. Args:
  5320. input (Tensor): the input tensor.
  5321. Keyword args:
  5322. out (Tensor, optional): the output tensor.
  5323. Example::
  5324. >>> a = torch.rand(1, 2).bool()
  5325. >>> a
  5326. tensor([[False, True]], dtype=torch.bool)
  5327. >>> torch.any(a)
  5328. tensor(True, dtype=torch.bool)
  5329. >>> a = torch.arange(0, 3)
  5330. >>> a
  5331. tensor([0, 1, 2])
  5332. >>> torch.any(a)
  5333. tensor(True)
  5334. .. function:: any(input, dim, keepdim=False, *, out=None) -> Tensor
  5335. :noindex:
  5336. For each row of :attr:`input` in the given dimension :attr:`dim`,
  5337. returns `True` if any element in the row evaluate to `True` and `False` otherwise.
  5338. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  5339. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  5340. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  5341. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  5342. Args:
  5343. input (Tensor): the input tensor.
  5344. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  5345. If ``None``, all dimensions are reduced.
  5346. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5347. Keyword args:
  5348. out (Tensor, optional): the output tensor.
  5349. Example::
  5350. >>> a = torch.randn(4, 2) < 0
  5351. >>> a
  5352. tensor([[ True, True],
  5353. [False, True],
  5354. [ True, True],
  5355. [False, False]])
  5356. >>> torch.any(a, 1)
  5357. tensor([ True, True, True, False])
  5358. >>> torch.any(a, 0)
  5359. tensor([True, True])
  5360. """
  5361. @overload
  5362. def any(
  5363. input: Tensor,
  5364. dim: _int,
  5365. keepdim: _bool = False,
  5366. *,
  5367. out: Tensor | None = None,
  5368. ) -> Tensor:
  5369. r"""
  5370. any(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5371. Tests if any element in :attr:`input` evaluates to `True`.
  5372. .. note:: This function matches the behaviour of NumPy in returning
  5373. output of dtype `bool` for all supported dtypes except `uint8`.
  5374. For `uint8` the dtype of output is `uint8` itself.
  5375. Args:
  5376. input (Tensor): the input tensor.
  5377. Keyword args:
  5378. out (Tensor, optional): the output tensor.
  5379. Example::
  5380. >>> a = torch.rand(1, 2).bool()
  5381. >>> a
  5382. tensor([[False, True]], dtype=torch.bool)
  5383. >>> torch.any(a)
  5384. tensor(True, dtype=torch.bool)
  5385. >>> a = torch.arange(0, 3)
  5386. >>> a
  5387. tensor([0, 1, 2])
  5388. >>> torch.any(a)
  5389. tensor(True)
  5390. .. function:: any(input, dim, keepdim=False, *, out=None) -> Tensor
  5391. :noindex:
  5392. For each row of :attr:`input` in the given dimension :attr:`dim`,
  5393. returns `True` if any element in the row evaluate to `True` and `False` otherwise.
  5394. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  5395. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  5396. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  5397. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  5398. Args:
  5399. input (Tensor): the input tensor.
  5400. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  5401. If ``None``, all dimensions are reduced.
  5402. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5403. Keyword args:
  5404. out (Tensor, optional): the output tensor.
  5405. Example::
  5406. >>> a = torch.randn(4, 2) < 0
  5407. >>> a
  5408. tensor([[ True, True],
  5409. [False, True],
  5410. [ True, True],
  5411. [False, False]])
  5412. >>> torch.any(a, 1)
  5413. tensor([ True, True, True, False])
  5414. >>> torch.any(a, 0)
  5415. tensor([True, True])
  5416. """
  5417. @overload
  5418. def any(
  5419. input: Tensor,
  5420. dim: str | EllipsisType | None,
  5421. keepdim: _bool = False,
  5422. *,
  5423. out: Tensor | None = None,
  5424. ) -> Tensor:
  5425. r"""
  5426. any(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5427. Tests if any element in :attr:`input` evaluates to `True`.
  5428. .. note:: This function matches the behaviour of NumPy in returning
  5429. output of dtype `bool` for all supported dtypes except `uint8`.
  5430. For `uint8` the dtype of output is `uint8` itself.
  5431. Args:
  5432. input (Tensor): the input tensor.
  5433. Keyword args:
  5434. out (Tensor, optional): the output tensor.
  5435. Example::
  5436. >>> a = torch.rand(1, 2).bool()
  5437. >>> a
  5438. tensor([[False, True]], dtype=torch.bool)
  5439. >>> torch.any(a)
  5440. tensor(True, dtype=torch.bool)
  5441. >>> a = torch.arange(0, 3)
  5442. >>> a
  5443. tensor([0, 1, 2])
  5444. >>> torch.any(a)
  5445. tensor(True)
  5446. .. function:: any(input, dim, keepdim=False, *, out=None) -> Tensor
  5447. :noindex:
  5448. For each row of :attr:`input` in the given dimension :attr:`dim`,
  5449. returns `True` if any element in the row evaluate to `True` and `False` otherwise.
  5450. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  5451. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  5452. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  5453. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  5454. Args:
  5455. input (Tensor): the input tensor.
  5456. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  5457. If ``None``, all dimensions are reduced.
  5458. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5459. Keyword args:
  5460. out (Tensor, optional): the output tensor.
  5461. Example::
  5462. >>> a = torch.randn(4, 2) < 0
  5463. >>> a
  5464. tensor([[ True, True],
  5465. [False, True],
  5466. [ True, True],
  5467. [False, False]])
  5468. >>> torch.any(a, 1)
  5469. tensor([ True, True, True, False])
  5470. >>> torch.any(a, 0)
  5471. tensor([True, True])
  5472. """
  5473. @overload
  5474. def arange(
  5475. start: Number,
  5476. end: Number,
  5477. step: Number,
  5478. *,
  5479. out: Tensor | None = None,
  5480. dtype: _dtype | None = None,
  5481. device: DeviceLikeType | None = None,
  5482. requires_grad: _bool = False,
  5483. pin_memory: _bool = False,
  5484. ) -> Tensor:
  5485. r"""
  5486. arange(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  5487. Returns a 1-D tensor of size :math:`\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil`
  5488. with values from the interval ``[start, end)`` taken with common difference
  5489. :attr:`step` beginning from `start`.
  5490. Note: When using floating-point dtypes (especially reduced precision types like ``bfloat16``),
  5491. the results may be affected by floating-point rounding behavior. Some values in the sequence
  5492. might not be exactly representable in certain floating-point formats, which can lead to
  5493. repeated values or unexpected rounding. For precise sequences, it is recommended to use
  5494. integer dtypes instead of floating-point dtypes.
  5495. Note that non-integer :attr:`step` is subject to floating point rounding errors when
  5496. comparing against :attr:`end`; to avoid inconsistency, we advise subtracting a small epsilon from :attr:`end`
  5497. in such cases.
  5498. .. math::
  5499. \text{out}_{{i+1}} = \text{out}_{i} + \text{step}
  5500. Args:
  5501. start (Number, optional): the starting value for the set of points. Default: ``0``.
  5502. end (Number): the ending value for the set of points
  5503. step (Number, optional): the gap between each pair of adjacent points. Default: ``1``.
  5504. Keyword args:
  5505. out (Tensor, optional): the output tensor.
  5506. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  5507. 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
  5508. arguments. If any of `start`, `end`, or `stop` are floating-point, the
  5509. `dtype` is inferred to be the default dtype, see
  5510. :meth:`~torch.get_default_dtype`. Otherwise, the `dtype` is inferred to
  5511. be `torch.int64`.
  5512. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  5513. Default: ``torch.strided``.
  5514. device (:class:`torch.device`, optional): the desired device of returned tensor.
  5515. Default: if ``None``, uses the current device for the default tensor type
  5516. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  5517. for CPU tensor types and the current CUDA device for CUDA tensor types.
  5518. requires_grad (bool, optional): If autograd should record operations on the
  5519. returned tensor. Default: ``False``.
  5520. Example::
  5521. >>> torch.arange(5)
  5522. tensor([ 0, 1, 2, 3, 4])
  5523. >>> torch.arange(1, 4)
  5524. tensor([ 1, 2, 3])
  5525. >>> torch.arange(1, 2.5, 0.5)
  5526. tensor([ 1.0000, 1.5000, 2.0000])
  5527. """
  5528. @overload
  5529. def arange(
  5530. start: Number,
  5531. end: Number,
  5532. *,
  5533. out: Tensor | None = None,
  5534. dtype: _dtype | None = None,
  5535. device: DeviceLikeType | None = None,
  5536. requires_grad: _bool = False,
  5537. pin_memory: _bool = False,
  5538. ) -> Tensor:
  5539. r"""
  5540. arange(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  5541. Returns a 1-D tensor of size :math:`\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil`
  5542. with values from the interval ``[start, end)`` taken with common difference
  5543. :attr:`step` beginning from `start`.
  5544. Note: When using floating-point dtypes (especially reduced precision types like ``bfloat16``),
  5545. the results may be affected by floating-point rounding behavior. Some values in the sequence
  5546. might not be exactly representable in certain floating-point formats, which can lead to
  5547. repeated values or unexpected rounding. For precise sequences, it is recommended to use
  5548. integer dtypes instead of floating-point dtypes.
  5549. Note that non-integer :attr:`step` is subject to floating point rounding errors when
  5550. comparing against :attr:`end`; to avoid inconsistency, we advise subtracting a small epsilon from :attr:`end`
  5551. in such cases.
  5552. .. math::
  5553. \text{out}_{{i+1}} = \text{out}_{i} + \text{step}
  5554. Args:
  5555. start (Number, optional): the starting value for the set of points. Default: ``0``.
  5556. end (Number): the ending value for the set of points
  5557. step (Number, optional): the gap between each pair of adjacent points. Default: ``1``.
  5558. Keyword args:
  5559. out (Tensor, optional): the output tensor.
  5560. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  5561. 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
  5562. arguments. If any of `start`, `end`, or `stop` are floating-point, the
  5563. `dtype` is inferred to be the default dtype, see
  5564. :meth:`~torch.get_default_dtype`. Otherwise, the `dtype` is inferred to
  5565. be `torch.int64`.
  5566. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  5567. Default: ``torch.strided``.
  5568. device (:class:`torch.device`, optional): the desired device of returned tensor.
  5569. Default: if ``None``, uses the current device for the default tensor type
  5570. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  5571. for CPU tensor types and the current CUDA device for CUDA tensor types.
  5572. requires_grad (bool, optional): If autograd should record operations on the
  5573. returned tensor. Default: ``False``.
  5574. Example::
  5575. >>> torch.arange(5)
  5576. tensor([ 0, 1, 2, 3, 4])
  5577. >>> torch.arange(1, 4)
  5578. tensor([ 1, 2, 3])
  5579. >>> torch.arange(1, 2.5, 0.5)
  5580. tensor([ 1.0000, 1.5000, 2.0000])
  5581. """
  5582. @overload
  5583. def arange(
  5584. end: Number,
  5585. *,
  5586. out: Tensor | None = None,
  5587. dtype: _dtype | None = None,
  5588. device: DeviceLikeType | None = None,
  5589. requires_grad: _bool = False,
  5590. pin_memory: _bool = False,
  5591. ) -> Tensor:
  5592. r"""
  5593. arange(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  5594. Returns a 1-D tensor of size :math:`\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil`
  5595. with values from the interval ``[start, end)`` taken with common difference
  5596. :attr:`step` beginning from `start`.
  5597. Note: When using floating-point dtypes (especially reduced precision types like ``bfloat16``),
  5598. the results may be affected by floating-point rounding behavior. Some values in the sequence
  5599. might not be exactly representable in certain floating-point formats, which can lead to
  5600. repeated values or unexpected rounding. For precise sequences, it is recommended to use
  5601. integer dtypes instead of floating-point dtypes.
  5602. Note that non-integer :attr:`step` is subject to floating point rounding errors when
  5603. comparing against :attr:`end`; to avoid inconsistency, we advise subtracting a small epsilon from :attr:`end`
  5604. in such cases.
  5605. .. math::
  5606. \text{out}_{{i+1}} = \text{out}_{i} + \text{step}
  5607. Args:
  5608. start (Number, optional): the starting value for the set of points. Default: ``0``.
  5609. end (Number): the ending value for the set of points
  5610. step (Number, optional): the gap between each pair of adjacent points. Default: ``1``.
  5611. Keyword args:
  5612. out (Tensor, optional): the output tensor.
  5613. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  5614. 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
  5615. arguments. If any of `start`, `end`, or `stop` are floating-point, the
  5616. `dtype` is inferred to be the default dtype, see
  5617. :meth:`~torch.get_default_dtype`. Otherwise, the `dtype` is inferred to
  5618. be `torch.int64`.
  5619. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  5620. Default: ``torch.strided``.
  5621. device (:class:`torch.device`, optional): the desired device of returned tensor.
  5622. Default: if ``None``, uses the current device for the default tensor type
  5623. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  5624. for CPU tensor types and the current CUDA device for CUDA tensor types.
  5625. requires_grad (bool, optional): If autograd should record operations on the
  5626. returned tensor. Default: ``False``.
  5627. Example::
  5628. >>> torch.arange(5)
  5629. tensor([ 0, 1, 2, 3, 4])
  5630. >>> torch.arange(1, 4)
  5631. tensor([ 1, 2, 3])
  5632. >>> torch.arange(1, 2.5, 0.5)
  5633. tensor([ 1.0000, 1.5000, 2.0000])
  5634. """
  5635. @overload
  5636. def arange(
  5637. end: Number | _complex,
  5638. *,
  5639. out: Tensor | None = None,
  5640. dtype: _dtype | None = None,
  5641. layout: _layout | None = None,
  5642. device: DeviceLikeType | None = None,
  5643. pin_memory: _bool | None = False,
  5644. requires_grad: _bool | None = False,
  5645. ) -> Tensor:
  5646. r"""
  5647. arange(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  5648. Returns a 1-D tensor of size :math:`\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil`
  5649. with values from the interval ``[start, end)`` taken with common difference
  5650. :attr:`step` beginning from `start`.
  5651. Note: When using floating-point dtypes (especially reduced precision types like ``bfloat16``),
  5652. the results may be affected by floating-point rounding behavior. Some values in the sequence
  5653. might not be exactly representable in certain floating-point formats, which can lead to
  5654. repeated values or unexpected rounding. For precise sequences, it is recommended to use
  5655. integer dtypes instead of floating-point dtypes.
  5656. Note that non-integer :attr:`step` is subject to floating point rounding errors when
  5657. comparing against :attr:`end`; to avoid inconsistency, we advise subtracting a small epsilon from :attr:`end`
  5658. in such cases.
  5659. .. math::
  5660. \text{out}_{{i+1}} = \text{out}_{i} + \text{step}
  5661. Args:
  5662. start (Number, optional): the starting value for the set of points. Default: ``0``.
  5663. end (Number): the ending value for the set of points
  5664. step (Number, optional): the gap between each pair of adjacent points. Default: ``1``.
  5665. Keyword args:
  5666. out (Tensor, optional): the output tensor.
  5667. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  5668. 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
  5669. arguments. If any of `start`, `end`, or `stop` are floating-point, the
  5670. `dtype` is inferred to be the default dtype, see
  5671. :meth:`~torch.get_default_dtype`. Otherwise, the `dtype` is inferred to
  5672. be `torch.int64`.
  5673. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  5674. Default: ``torch.strided``.
  5675. device (:class:`torch.device`, optional): the desired device of returned tensor.
  5676. Default: if ``None``, uses the current device for the default tensor type
  5677. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  5678. for CPU tensor types and the current CUDA device for CUDA tensor types.
  5679. requires_grad (bool, optional): If autograd should record operations on the
  5680. returned tensor. Default: ``False``.
  5681. Example::
  5682. >>> torch.arange(5)
  5683. tensor([ 0, 1, 2, 3, 4])
  5684. >>> torch.arange(1, 4)
  5685. tensor([ 1, 2, 3])
  5686. >>> torch.arange(1, 2.5, 0.5)
  5687. tensor([ 1.0000, 1.5000, 2.0000])
  5688. """
  5689. @overload
  5690. def arange(
  5691. start: Number | _complex,
  5692. end: Number | _complex,
  5693. *,
  5694. dtype: _dtype | None = None,
  5695. layout: _layout | None = None,
  5696. device: DeviceLikeType | None = None,
  5697. pin_memory: _bool | None = False,
  5698. requires_grad: _bool | None = False,
  5699. ) -> Tensor:
  5700. r"""
  5701. arange(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  5702. Returns a 1-D tensor of size :math:`\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil`
  5703. with values from the interval ``[start, end)`` taken with common difference
  5704. :attr:`step` beginning from `start`.
  5705. Note: When using floating-point dtypes (especially reduced precision types like ``bfloat16``),
  5706. the results may be affected by floating-point rounding behavior. Some values in the sequence
  5707. might not be exactly representable in certain floating-point formats, which can lead to
  5708. repeated values or unexpected rounding. For precise sequences, it is recommended to use
  5709. integer dtypes instead of floating-point dtypes.
  5710. Note that non-integer :attr:`step` is subject to floating point rounding errors when
  5711. comparing against :attr:`end`; to avoid inconsistency, we advise subtracting a small epsilon from :attr:`end`
  5712. in such cases.
  5713. .. math::
  5714. \text{out}_{{i+1}} = \text{out}_{i} + \text{step}
  5715. Args:
  5716. start (Number, optional): the starting value for the set of points. Default: ``0``.
  5717. end (Number): the ending value for the set of points
  5718. step (Number, optional): the gap between each pair of adjacent points. Default: ``1``.
  5719. Keyword args:
  5720. out (Tensor, optional): the output tensor.
  5721. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  5722. 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
  5723. arguments. If any of `start`, `end`, or `stop` are floating-point, the
  5724. `dtype` is inferred to be the default dtype, see
  5725. :meth:`~torch.get_default_dtype`. Otherwise, the `dtype` is inferred to
  5726. be `torch.int64`.
  5727. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  5728. Default: ``torch.strided``.
  5729. device (:class:`torch.device`, optional): the desired device of returned tensor.
  5730. Default: if ``None``, uses the current device for the default tensor type
  5731. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  5732. for CPU tensor types and the current CUDA device for CUDA tensor types.
  5733. requires_grad (bool, optional): If autograd should record operations on the
  5734. returned tensor. Default: ``False``.
  5735. Example::
  5736. >>> torch.arange(5)
  5737. tensor([ 0, 1, 2, 3, 4])
  5738. >>> torch.arange(1, 4)
  5739. tensor([ 1, 2, 3])
  5740. >>> torch.arange(1, 2.5, 0.5)
  5741. tensor([ 1.0000, 1.5000, 2.0000])
  5742. """
  5743. @overload
  5744. def arange(
  5745. start: Number | _complex,
  5746. end: Number | _complex,
  5747. step: Number | _complex = 1,
  5748. *,
  5749. out: Tensor | None = None,
  5750. dtype: _dtype | None = None,
  5751. layout: _layout | None = None,
  5752. device: DeviceLikeType | None = None,
  5753. pin_memory: _bool | None = False,
  5754. requires_grad: _bool | None = False,
  5755. ) -> Tensor:
  5756. r"""
  5757. arange(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  5758. Returns a 1-D tensor of size :math:`\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil`
  5759. with values from the interval ``[start, end)`` taken with common difference
  5760. :attr:`step` beginning from `start`.
  5761. Note: When using floating-point dtypes (especially reduced precision types like ``bfloat16``),
  5762. the results may be affected by floating-point rounding behavior. Some values in the sequence
  5763. might not be exactly representable in certain floating-point formats, which can lead to
  5764. repeated values or unexpected rounding. For precise sequences, it is recommended to use
  5765. integer dtypes instead of floating-point dtypes.
  5766. Note that non-integer :attr:`step` is subject to floating point rounding errors when
  5767. comparing against :attr:`end`; to avoid inconsistency, we advise subtracting a small epsilon from :attr:`end`
  5768. in such cases.
  5769. .. math::
  5770. \text{out}_{{i+1}} = \text{out}_{i} + \text{step}
  5771. Args:
  5772. start (Number, optional): the starting value for the set of points. Default: ``0``.
  5773. end (Number): the ending value for the set of points
  5774. step (Number, optional): the gap between each pair of adjacent points. Default: ``1``.
  5775. Keyword args:
  5776. out (Tensor, optional): the output tensor.
  5777. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  5778. 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
  5779. arguments. If any of `start`, `end`, or `stop` are floating-point, the
  5780. `dtype` is inferred to be the default dtype, see
  5781. :meth:`~torch.get_default_dtype`. Otherwise, the `dtype` is inferred to
  5782. be `torch.int64`.
  5783. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  5784. Default: ``torch.strided``.
  5785. device (:class:`torch.device`, optional): the desired device of returned tensor.
  5786. Default: if ``None``, uses the current device for the default tensor type
  5787. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  5788. for CPU tensor types and the current CUDA device for CUDA tensor types.
  5789. requires_grad (bool, optional): If autograd should record operations on the
  5790. returned tensor. Default: ``False``.
  5791. Example::
  5792. >>> torch.arange(5)
  5793. tensor([ 0, 1, 2, 3, 4])
  5794. >>> torch.arange(1, 4)
  5795. tensor([ 1, 2, 3])
  5796. >>> torch.arange(1, 2.5, 0.5)
  5797. tensor([ 1.0000, 1.5000, 2.0000])
  5798. """
  5799. def arccos(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  5800. r"""
  5801. arccos(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5802. Alias for :func:`torch.acos`.
  5803. """
  5804. def arccos_(input: Tensor) -> Tensor: ...
  5805. def arccosh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  5806. r"""
  5807. arccosh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5808. Alias for :func:`torch.acosh`.
  5809. """
  5810. def arccosh_(input: Tensor) -> Tensor: ...
  5811. def arcsin(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  5812. r"""
  5813. arcsin(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5814. Alias for :func:`torch.asin`.
  5815. """
  5816. def arcsin_(input: Tensor) -> Tensor: ...
  5817. def arcsinh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  5818. r"""
  5819. arcsinh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5820. Alias for :func:`torch.asinh`.
  5821. """
  5822. def arcsinh_(input: Tensor) -> Tensor: ...
  5823. def arctan(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  5824. r"""
  5825. arctan(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5826. Alias for :func:`torch.atan`.
  5827. """
  5828. def arctan2(
  5829. input: Tensor,
  5830. other: Tensor,
  5831. *,
  5832. out: Tensor | None = None,
  5833. ) -> Tensor:
  5834. r"""
  5835. arctan2(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
  5836. Alias for :func:`torch.atan2`.
  5837. """
  5838. def arctan_(input: Tensor) -> Tensor: ...
  5839. def arctanh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  5840. r"""
  5841. arctanh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5842. Alias for :func:`torch.atanh`.
  5843. """
  5844. def arctanh_(input: Tensor) -> Tensor: ...
  5845. def argmax(
  5846. input: Tensor,
  5847. dim: _int | None = None,
  5848. keepdim: _bool = False,
  5849. *,
  5850. out: Tensor | None = None,
  5851. ) -> Tensor:
  5852. r"""
  5853. argmax(input) -> LongTensor
  5854. Returns the indices of the maximum value of all elements in the :attr:`input` tensor.
  5855. This is the second value returned by :meth:`torch.max`. See its
  5856. documentation for the exact semantics of this method.
  5857. .. note:: If there are multiple maximal values then the indices of the first maximal value are returned.
  5858. Args:
  5859. input (Tensor): the input tensor.
  5860. Example::
  5861. >>> a = torch.randn(4, 4)
  5862. >>> a
  5863. tensor([[ 1.3398, 0.2663, -0.2686, 0.2450],
  5864. [-0.7401, -0.8805, -0.3402, -1.1936],
  5865. [ 0.4907, -1.3948, -1.0691, -0.3132],
  5866. [-1.6092, 0.5419, -0.2993, 0.3195]])
  5867. >>> torch.argmax(a)
  5868. tensor(0)
  5869. .. function:: argmax(input, dim, keepdim=False) -> LongTensor
  5870. :noindex:
  5871. Returns the indices of the maximum values of a tensor across a dimension.
  5872. This is the second value returned by :meth:`torch.max`. See its
  5873. documentation for the exact semantics of this method.
  5874. Args:
  5875. input (Tensor): the input tensor.
  5876. dim (int, optional): the dimension to reduce.
  5877. If ``None``, the argmax of the flattened input is returned.
  5878. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5879. Example::
  5880. >>> a = torch.randn(4, 4)
  5881. >>> a
  5882. tensor([[ 1.3398, 0.2663, -0.2686, 0.2450],
  5883. [-0.7401, -0.8805, -0.3402, -1.1936],
  5884. [ 0.4907, -1.3948, -1.0691, -0.3132],
  5885. [-1.6092, 0.5419, -0.2993, 0.3195]])
  5886. >>> torch.argmax(a, dim=1)
  5887. tensor([ 0, 2, 0, 1])
  5888. """
  5889. def argmin(
  5890. input: Tensor,
  5891. dim: _int | None = None,
  5892. keepdim: _bool = False,
  5893. *,
  5894. out: Tensor | None = None,
  5895. ) -> Tensor:
  5896. r"""
  5897. argmin(input, dim=None, keepdim=False) -> LongTensor
  5898. Returns the indices of the minimum value(s) of the flattened tensor or along a dimension
  5899. This is the second value returned by :meth:`torch.min`. See its
  5900. documentation for the exact semantics of this method.
  5901. .. note:: If there are multiple minimal values then the indices of the first minimal value are returned.
  5902. Args:
  5903. input (Tensor): the input tensor.
  5904. dim (int, optional): the dimension to reduce.
  5905. If ``None``, the argmin of the flattened input is returned.
  5906. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5907. Example::
  5908. >>> a = torch.randn(4, 4)
  5909. >>> a
  5910. tensor([[ 0.1139, 0.2254, -0.1381, 0.3687],
  5911. [ 1.0100, -1.1975, -0.0102, -0.4732],
  5912. [-0.9240, 0.1207, -0.7506, -1.0213],
  5913. [ 1.7809, -1.2960, 0.9384, 0.1438]])
  5914. >>> torch.argmin(a)
  5915. tensor(13)
  5916. >>> torch.argmin(a, dim=1)
  5917. tensor([ 2, 1, 3, 1])
  5918. >>> torch.argmin(a, dim=1, keepdim=True)
  5919. tensor([[2],
  5920. [1],
  5921. [3],
  5922. [1]])
  5923. """
  5924. @overload
  5925. def argsort(
  5926. input: Tensor,
  5927. *,
  5928. stable: _bool,
  5929. dim: _int = -1,
  5930. descending: _bool = False,
  5931. out: Tensor | None = None,
  5932. ) -> Tensor:
  5933. r"""
  5934. argsort(input, dim=-1, descending=False, *, stable=False) -> Tensor
  5935. Returns the indices that sort a tensor along a given dimension in ascending
  5936. order by value.
  5937. This is the second value returned by :meth:`torch.sort`. See its documentation
  5938. for the exact semantics of this method.
  5939. If :attr:`stable` is ``True`` then the sorting routine becomes stable, preserving
  5940. the order of equivalent elements. If ``False``, the relative order of values
  5941. which compare equal is not guaranteed. ``True`` is slower.
  5942. Args:
  5943. input (Tensor): the input tensor.
  5944. dim (int, optional): the dimension to sort along
  5945. descending (bool, optional): controls the sorting order (ascending or descending)
  5946. Keyword args:
  5947. stable (bool, optional): controls the relative order of equivalent elements
  5948. Example::
  5949. >>> a = torch.randn(4, 4)
  5950. >>> a
  5951. tensor([[ 0.0785, 1.5267, -0.8521, 0.4065],
  5952. [ 0.1598, 0.0788, -0.0745, -1.2700],
  5953. [ 1.2208, 1.0722, -0.7064, 1.2564],
  5954. [ 0.0669, -0.2318, -0.8229, -0.9280]])
  5955. >>> torch.argsort(a, dim=1)
  5956. tensor([[2, 0, 3, 1],
  5957. [3, 2, 1, 0],
  5958. [2, 1, 0, 3],
  5959. [3, 2, 1, 0]])
  5960. """
  5961. @overload
  5962. def argsort(
  5963. input: Tensor,
  5964. dim: _int = -1,
  5965. descending: _bool = False,
  5966. ) -> Tensor:
  5967. r"""
  5968. argsort(input, dim=-1, descending=False, *, stable=False) -> Tensor
  5969. Returns the indices that sort a tensor along a given dimension in ascending
  5970. order by value.
  5971. This is the second value returned by :meth:`torch.sort`. See its documentation
  5972. for the exact semantics of this method.
  5973. If :attr:`stable` is ``True`` then the sorting routine becomes stable, preserving
  5974. the order of equivalent elements. If ``False``, the relative order of values
  5975. which compare equal is not guaranteed. ``True`` is slower.
  5976. Args:
  5977. input (Tensor): the input tensor.
  5978. dim (int, optional): the dimension to sort along
  5979. descending (bool, optional): controls the sorting order (ascending or descending)
  5980. Keyword args:
  5981. stable (bool, optional): controls the relative order of equivalent elements
  5982. Example::
  5983. >>> a = torch.randn(4, 4)
  5984. >>> a
  5985. tensor([[ 0.0785, 1.5267, -0.8521, 0.4065],
  5986. [ 0.1598, 0.0788, -0.0745, -1.2700],
  5987. [ 1.2208, 1.0722, -0.7064, 1.2564],
  5988. [ 0.0669, -0.2318, -0.8229, -0.9280]])
  5989. >>> torch.argsort(a, dim=1)
  5990. tensor([[2, 0, 3, 1],
  5991. [3, 2, 1, 0],
  5992. [2, 1, 0, 3],
  5993. [3, 2, 1, 0]])
  5994. """
  5995. @overload
  5996. def argsort(
  5997. input: Tensor,
  5998. dim: str | EllipsisType | None,
  5999. descending: _bool = False,
  6000. ) -> Tensor:
  6001. r"""
  6002. argsort(input, dim=-1, descending=False, *, stable=False) -> Tensor
  6003. Returns the indices that sort a tensor along a given dimension in ascending
  6004. order by value.
  6005. This is the second value returned by :meth:`torch.sort`. See its documentation
  6006. for the exact semantics of this method.
  6007. If :attr:`stable` is ``True`` then the sorting routine becomes stable, preserving
  6008. the order of equivalent elements. If ``False``, the relative order of values
  6009. which compare equal is not guaranteed. ``True`` is slower.
  6010. Args:
  6011. input (Tensor): the input tensor.
  6012. dim (int, optional): the dimension to sort along
  6013. descending (bool, optional): controls the sorting order (ascending or descending)
  6014. Keyword args:
  6015. stable (bool, optional): controls the relative order of equivalent elements
  6016. Example::
  6017. >>> a = torch.randn(4, 4)
  6018. >>> a
  6019. tensor([[ 0.0785, 1.5267, -0.8521, 0.4065],
  6020. [ 0.1598, 0.0788, -0.0745, -1.2700],
  6021. [ 1.2208, 1.0722, -0.7064, 1.2564],
  6022. [ 0.0669, -0.2318, -0.8229, -0.9280]])
  6023. >>> torch.argsort(a, dim=1)
  6024. tensor([[2, 0, 3, 1],
  6025. [3, 2, 1, 0],
  6026. [2, 1, 0, 3],
  6027. [3, 2, 1, 0]])
  6028. """
  6029. def argwhere(input: Tensor) -> Tensor:
  6030. r"""
  6031. argwhere(input) -> Tensor
  6032. Returns a tensor containing the indices of all non-zero elements of
  6033. :attr:`input`. Each row in the result contains the indices of a non-zero
  6034. element in :attr:`input`. The result is sorted lexicographically, with
  6035. the last index changing the fastest (C-style).
  6036. If :attr:`input` has :math:`n` dimensions, then the resulting indices tensor
  6037. :attr:`out` is of size :math:`(z \times n)`, where :math:`z` is the total number of
  6038. non-zero elements in the :attr:`input` tensor.
  6039. .. note::
  6040. This function is similar to NumPy's `argwhere`.
  6041. When :attr:`input` is on CUDA, this function causes host-device synchronization.
  6042. Args:
  6043. {input}
  6044. Example::
  6045. >>> t = torch.tensor([1, 0, 1])
  6046. >>> torch.argwhere(t)
  6047. tensor([[0],
  6048. [2]])
  6049. >>> t = torch.tensor([[1, 0, 1], [0, 1, 1]])
  6050. >>> torch.argwhere(t)
  6051. tensor([[0, 0],
  6052. [0, 2],
  6053. [1, 1],
  6054. [1, 2]])
  6055. """
  6056. def as_strided(
  6057. input: Tensor,
  6058. size: Sequence[_int | SymInt],
  6059. stride: Sequence[_int | SymInt],
  6060. storage_offset: _int | SymInt | None = None,
  6061. ) -> Tensor:
  6062. r"""
  6063. as_strided(input, size, stride, storage_offset=None) -> Tensor
  6064. Create a view of an existing `torch.Tensor` :attr:`input` with specified
  6065. :attr:`size`, :attr:`stride` and :attr:`storage_offset`.
  6066. .. warning::
  6067. Prefer using other view functions, like :meth:`torch.Tensor.view` or
  6068. :meth:`torch.Tensor.expand`, to setting a view's strides manually with
  6069. `as_strided`, as this function will throw an error on non-standard Pytorch
  6070. backends (that do not have a concept of stride) and the result will depend
  6071. on the current layout in memory. The constructed view must only refer to
  6072. elements within the Tensor's storage or a runtime error will be thrown.
  6073. If the generated view is "overlapped" (with multiple indices referring to
  6074. the same element in memory), the behavior of inplace operations on this view
  6075. is undefined (and might not throw runtime errors).
  6076. Args:
  6077. input (Tensor): the input tensor.
  6078. size (tuple or ints): the shape of the output tensor
  6079. stride (tuple or ints): the stride of the output tensor
  6080. storage_offset (int, optional): the offset in the underlying storage of the output tensor.
  6081. If ``None``, the storage_offset of the output tensor will match the input tensor.
  6082. Example::
  6083. >>> x = torch.randn(3, 3)
  6084. >>> x
  6085. tensor([[ 0.9039, 0.6291, 1.0795],
  6086. [ 0.1586, 2.1939, -0.4900],
  6087. [-0.1909, -0.7503, 1.9355]])
  6088. >>> t = torch.as_strided(x, (2, 2), (1, 2))
  6089. >>> t
  6090. tensor([[0.9039, 1.0795],
  6091. [0.6291, 0.1586]])
  6092. >>> t = torch.as_strided(x, (2, 2), (1, 2), 1)
  6093. tensor([[0.6291, 0.1586],
  6094. [1.0795, 2.1939]])
  6095. """
  6096. def as_strided_(
  6097. input: Tensor,
  6098. size: Sequence[_int | SymInt],
  6099. stride: Sequence[_int | SymInt],
  6100. storage_offset: _int | SymInt | None = None,
  6101. ) -> Tensor: ...
  6102. def as_strided_copy(
  6103. input: Tensor,
  6104. size: Sequence[_int | SymInt],
  6105. stride: Sequence[_int | SymInt],
  6106. storage_offset: _int | SymInt | None = None,
  6107. *,
  6108. out: Tensor | None = None,
  6109. ) -> Tensor:
  6110. r"""
  6111. Performs the same operation as :func:`torch.as_strided`, but all output tensors
  6112. are freshly created instead of aliasing the input.
  6113. """
  6114. def as_strided_scatter(
  6115. input: Tensor,
  6116. src: Tensor,
  6117. size: Sequence[_int | SymInt],
  6118. stride: Sequence[_int | SymInt],
  6119. storage_offset: _int | SymInt | None = None,
  6120. ) -> Tensor:
  6121. r"""
  6122. as_strided_scatter(input, src, size, stride, storage_offset=None) -> Tensor
  6123. Embeds the values of the :attr:`src` tensor into :attr:`input` along
  6124. the elements corresponding to the result of calling
  6125. input.as_strided(size, stride, storage_offset).
  6126. This function returns a tensor with fresh storage; it does not
  6127. return a view.
  6128. Args:
  6129. input (Tensor): the input tensor.
  6130. size (tuple or ints): the shape of the output tensor
  6131. stride (tuple or ints): the stride of the output tensor
  6132. storage_offset (int, optional): the offset in the underlying storage of the output tensor
  6133. .. note::
  6134. :attr:`src` must be of the proper size in order to be embedded
  6135. into :attr:`input`. Specifically, it should have the same shape as
  6136. `torch.as_strided(input, size, stride, storage_offset)`
  6137. Example::
  6138. >>> a = torch.arange(4).reshape(2, 2) + 1
  6139. >>> a
  6140. tensor([[1, 2],
  6141. [3, 4]])
  6142. >>> b = torch.zeros(3, 3)
  6143. >>> b
  6144. tensor([[0., 0., 0.],
  6145. [0., 0., 0.],
  6146. [0., 0., 0.]])
  6147. >>> torch.as_strided_scatter(b, a, (2, 2), (1, 2))
  6148. tensor([[1., 3., 2.],
  6149. [4., 0., 0.],
  6150. [0., 0., 0.]])
  6151. """
  6152. def as_tensor(
  6153. data: Any,
  6154. dtype: _dtype | None = None,
  6155. device: DeviceLikeType | None = None,
  6156. ) -> Tensor:
  6157. r"""
  6158. as_tensor(data: Any, dtype: Optional[dtype] = None, device: Optional[DeviceLikeType]) -> Tensor
  6159. Converts :attr:`data` into a tensor, sharing data and preserving autograd
  6160. history if possible.
  6161. If :attr:`data` is already a tensor with the requested dtype and device
  6162. then :attr:`data` itself is returned, but if :attr:`data` is a
  6163. tensor with a different dtype or device then it's copied as if using
  6164. `data.to(dtype=dtype, device=device)`.
  6165. If :attr:`data` is a NumPy array (an ndarray) with the same dtype and device then a
  6166. tensor is constructed using :func:`torch.from_numpy`.
  6167. If :attr:`data` is a CuPy array, the returned tensor will be located on the same device as the CuPy array unless
  6168. specifically overwritten by :attr:`device` or a default device. The device of the CuPy array is inferred from the
  6169. pointer of the array using `cudaPointerGetAttributes` unless :attr:`device` is provided with an explicit device index.
  6170. .. seealso::
  6171. :func:`torch.tensor` never shares its data and creates a new "leaf tensor" (see :doc:`/notes/autograd`).
  6172. Args:
  6173. data (array_like): Initial data for the tensor. Can be a list, tuple,
  6174. NumPy ``ndarray``, scalar, and other types.
  6175. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  6176. Default: if ``None``, infers data type from :attr:`data`.
  6177. device (:class:`torch.device`, optional): the device of the constructed tensor. If None and data is a tensor
  6178. then the device of data is used. If None and data is not a tensor then
  6179. the result tensor is constructed on the current device.
  6180. Example::
  6181. >>> a = numpy.array([1, 2, 3])
  6182. >>> t = torch.as_tensor(a)
  6183. >>> t
  6184. tensor([ 1, 2, 3])
  6185. >>> t[0] = -1
  6186. >>> a
  6187. array([-1, 2, 3])
  6188. >>> a = numpy.array([1, 2, 3])
  6189. >>> t = torch.as_tensor(a, device=torch.device('cuda'))
  6190. >>> t
  6191. tensor([ 1, 2, 3])
  6192. >>> t[0] = -1
  6193. >>> a
  6194. array([1, 2, 3])
  6195. """
  6196. def asarray(
  6197. obj: Any,
  6198. *,
  6199. dtype: _dtype | None = None,
  6200. device: DeviceLikeType | None = None,
  6201. copy: _bool | None = None,
  6202. requires_grad: _bool = False,
  6203. ) -> Tensor:
  6204. r"""
  6205. asarray(obj: Any, *, dtype: Optional[dtype], device: Optional[DeviceLikeType], copy: Optional[bool] = None, requires_grad: bool = False) -> Tensor # noqa: B950
  6206. Converts :attr:`obj` to a tensor.
  6207. :attr:`obj` can be one of:
  6208. 1. a tensor
  6209. 2. a NumPy array or a NumPy scalar
  6210. 3. a DLPack capsule
  6211. 4. an object that implements Python's buffer protocol
  6212. 5. a scalar
  6213. 6. a sequence of scalars
  6214. When :attr:`obj` is a tensor, NumPy array, or DLPack capsule the returned tensor will,
  6215. by default, not require a gradient, have the same datatype as :attr:`obj`, be on the
  6216. same device, and share memory with it. These properties can be controlled with the
  6217. :attr:`dtype`, :attr:`device`, :attr:`copy`, and :attr:`requires_grad` keyword arguments.
  6218. If the returned tensor is of a different datatype, on a different device, or a copy is
  6219. requested then it will not share its memory with :attr:`obj`. If :attr:`requires_grad`
  6220. is ``True`` then the returned tensor will require a gradient, and if :attr:`obj` is
  6221. also a tensor with an autograd history then the returned tensor will have the same history.
  6222. When :attr:`obj` is not a tensor, NumPy array, or DLPack capsule but implements Python's
  6223. buffer protocol then the buffer is interpreted as an array of bytes grouped according to
  6224. the size of the datatype passed to the :attr:`dtype` keyword argument. (If no datatype is
  6225. passed then the default floating point datatype is used, instead.) The returned tensor
  6226. will have the specified datatype (or default floating point datatype if none is specified)
  6227. and, by default, be on the CPU device and share memory with the buffer.
  6228. When :attr:`obj` is a NumPy scalar, the returned tensor will be a 0-dimensional tensor on
  6229. the CPU and that doesn't share its memory (i.e. ``copy=True``). By default datatype will
  6230. be the PyTorch datatype corresponding to the NumPy's scalar's datatype.
  6231. When :attr:`obj` is none of the above but a scalar, or a sequence of scalars then the
  6232. returned tensor will, by default, infer its datatype from the scalar values, be on the
  6233. current default device, and not share its memory.
  6234. .. seealso::
  6235. :func:`torch.tensor` creates a tensor that always copies the data from the input object.
  6236. :func:`torch.from_numpy` creates a tensor that always shares memory from NumPy arrays.
  6237. :func:`torch.frombuffer` creates a tensor that always shares memory from objects that
  6238. implement the buffer protocol.
  6239. :func:`torch.from_dlpack` creates a tensor that always shares memory from
  6240. DLPack capsules.
  6241. Args:
  6242. obj (object): a tensor, NumPy array, DLPack Capsule, object that implements Python's
  6243. buffer protocol, scalar, or sequence of scalars.
  6244. Keyword args:
  6245. dtype (:class:`torch.dtype`, optional): the datatype of the returned tensor.
  6246. Default: ``None``, which causes the datatype of the returned tensor to be
  6247. inferred from :attr:`obj`.
  6248. copy (bool, optional): controls whether the returned tensor shares memory with :attr:`obj`.
  6249. Default: ``None``, which causes the returned tensor to share memory with :attr:`obj`
  6250. whenever possible. If ``True`` then the returned tensor does not share its memory.
  6251. If ``False`` then the returned tensor shares its memory with :attr:`obj` and an
  6252. error is thrown if it cannot.
  6253. device (:class:`torch.device`, optional): the device of the returned tensor.
  6254. Default: ``None``, which causes the device of :attr:`obj` to be used. Or, if
  6255. :attr:`obj` is a Python sequence, the current default device will be used.
  6256. requires_grad (bool, optional): whether the returned tensor requires grad.
  6257. Default: ``False``, which causes the returned tensor not to require a gradient.
  6258. If ``True``, then the returned tensor will require a gradient, and if :attr:`obj`
  6259. is also a tensor with an autograd history then the returned tensor will have
  6260. the same history.
  6261. Example::
  6262. >>> a = torch.tensor([1, 2, 3])
  6263. >>> # Shares memory with tensor 'a'
  6264. >>> b = torch.asarray(a)
  6265. >>> a.data_ptr() == b.data_ptr()
  6266. True
  6267. >>> # Forces memory copy
  6268. >>> c = torch.asarray(a, copy=True)
  6269. >>> a.data_ptr() == c.data_ptr()
  6270. False
  6271. >>> a = torch.tensor([1., 2., 3.], requires_grad=True)
  6272. >>> b = a + 2
  6273. >>> b
  6274. tensor([3., 4., 5.], grad_fn=<AddBackward0>)
  6275. >>> # Shares memory with tensor 'b', with no grad
  6276. >>> c = torch.asarray(b)
  6277. >>> c
  6278. tensor([3., 4., 5.])
  6279. >>> # Shares memory with tensor 'b', retaining autograd history
  6280. >>> d = torch.asarray(b, requires_grad=True)
  6281. >>> d
  6282. tensor([3., 4., 5.], grad_fn=<AddBackward0>)
  6283. >>> array = numpy.array([1, 2, 3])
  6284. >>> # Shares memory with array 'array'
  6285. >>> t1 = torch.asarray(array)
  6286. >>> array.__array_interface__['data'][0] == t1.data_ptr()
  6287. True
  6288. >>> # Copies memory due to dtype mismatch
  6289. >>> t2 = torch.asarray(array, dtype=torch.float32)
  6290. >>> array.__array_interface__['data'][0] == t2.data_ptr()
  6291. False
  6292. >>> scalar = numpy.float64(0.5)
  6293. >>> torch.asarray(scalar)
  6294. tensor(0.5000, dtype=torch.float64)
  6295. """
  6296. def asin(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  6297. r"""
  6298. asin(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  6299. Returns a new tensor with the arcsine of the elements of :attr:`input`.
  6300. .. math::
  6301. \text{out}_{i} = \sin^{-1}(\text{input}_{i})
  6302. Args:
  6303. input (Tensor): the input tensor.
  6304. Keyword args:
  6305. out (Tensor, optional): the output tensor.
  6306. Example::
  6307. >>> a = torch.randn(4)
  6308. >>> a
  6309. tensor([-0.5962, 1.4985, -0.4396, 1.4525])
  6310. >>> torch.asin(a)
  6311. tensor([-0.6387, nan, -0.4552, nan])
  6312. """
  6313. def asin_(input: Tensor) -> Tensor: ...
  6314. def asinh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  6315. r"""
  6316. asinh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  6317. Returns a new tensor with the inverse hyperbolic sine of the elements of :attr:`input`.
  6318. .. math::
  6319. \text{out}_{i} = \sinh^{-1}(\text{input}_{i})
  6320. Args:
  6321. input (Tensor): the input tensor.
  6322. Keyword arguments:
  6323. out (Tensor, optional): the output tensor.
  6324. Example::
  6325. >>> a = torch.randn(4)
  6326. >>> a
  6327. tensor([ 0.1606, -1.4267, -1.0899, -1.0250 ])
  6328. >>> torch.asinh(a)
  6329. tensor([ 0.1599, -1.1534, -0.9435, -0.8990 ])
  6330. """
  6331. def asinh_(input: Tensor) -> Tensor: ...
  6332. def atan(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  6333. r"""
  6334. atan(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  6335. Returns a new tensor with the arctangent of the elements of :attr:`input`.
  6336. .. math::
  6337. \text{out}_{i} = \tan^{-1}(\text{input}_{i})
  6338. Args:
  6339. input (Tensor): the input tensor.
  6340. Keyword args:
  6341. out (Tensor, optional): the output tensor.
  6342. Example::
  6343. >>> a = torch.randn(4)
  6344. >>> a
  6345. tensor([ 0.2341, 0.2539, -0.6256, -0.6448])
  6346. >>> torch.atan(a)
  6347. tensor([ 0.2299, 0.2487, -0.5591, -0.5727])
  6348. """
  6349. def atan2(
  6350. input: Tensor,
  6351. other: Tensor,
  6352. *,
  6353. out: Tensor | None = None,
  6354. ) -> Tensor:
  6355. r"""
  6356. atan2(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
  6357. Element-wise arctangent of :math:`\text{input}_{i} / \text{other}_{i}`
  6358. with consideration of the quadrant. Returns a new tensor with the signed angles
  6359. in radians between vector :math:`(\text{other}_{i}, \text{input}_{i})`
  6360. and vector :math:`(1, 0)`. (Note that :math:`\text{other}_{i}`, the second
  6361. parameter, is the x-coordinate, while :math:`\text{input}_{i}`, the first
  6362. parameter, is the y-coordinate.)
  6363. The shapes of ``input`` and ``other`` must be
  6364. :ref:`broadcastable <broadcasting-semantics>`.
  6365. Args:
  6366. input (Tensor): the first input tensor
  6367. other (Tensor): the second input tensor
  6368. Keyword args:
  6369. out (Tensor, optional): the output tensor.
  6370. Example::
  6371. >>> a = torch.randn(4)
  6372. >>> a
  6373. tensor([ 0.9041, 0.0196, -0.3108, -2.4423])
  6374. >>> torch.atan2(a, torch.randn(4))
  6375. tensor([ 0.9833, 0.0811, -1.9743, -1.4151])
  6376. """
  6377. def atan_(input: Tensor) -> Tensor: ...
  6378. def atanh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  6379. r"""
  6380. atanh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  6381. Returns a new tensor with the inverse hyperbolic tangent of the elements of :attr:`input`.
  6382. Note:
  6383. The domain of the inverse hyperbolic tangent is `(-1, 1)` and values outside this range
  6384. will be mapped to ``NaN``, except for the values `1` and `-1` for which the output is
  6385. mapped to `+/-INF` respectively.
  6386. .. math::
  6387. \text{out}_{i} = \tanh^{-1}(\text{input}_{i})
  6388. Args:
  6389. input (Tensor): the input tensor.
  6390. Keyword arguments:
  6391. out (Tensor, optional): the output tensor.
  6392. Example::
  6393. >>> a = torch.randn(4).uniform_(-1, 1)
  6394. >>> a
  6395. tensor([ -0.9385, 0.2968, -0.8591, -0.1871 ])
  6396. >>> torch.atanh(a)
  6397. tensor([ -1.7253, 0.3060, -1.2899, -0.1893 ])
  6398. """
  6399. def atanh_(input: Tensor) -> Tensor: ...
  6400. def avg_pool1d(
  6401. input: Tensor,
  6402. kernel_size: _int | _size,
  6403. stride: _int | _size = (),
  6404. padding: _int | _size = 0,
  6405. ceil_mode: _bool = False,
  6406. count_include_pad: _bool = True,
  6407. ) -> Tensor: ...
  6408. @overload
  6409. def baddbmm(
  6410. beta: Number | _complex,
  6411. self: Tensor,
  6412. alpha: Number | _complex,
  6413. batch1: Tensor,
  6414. batch2: Tensor,
  6415. ) -> Tensor:
  6416. r"""
  6417. baddbmm(input, batch1, batch2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  6418. Performs a batch matrix-matrix product of matrices in :attr:`batch1`
  6419. and :attr:`batch2`.
  6420. :attr:`input` is added to the final result.
  6421. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the same
  6422. number of matrices.
  6423. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  6424. :math:`(b \times m \times p)` tensor, then :attr:`input` must be
  6425. :ref:`broadcastable <broadcasting-semantics>` with a
  6426. :math:`(b \times n \times p)` tensor and :attr:`out` will be a
  6427. :math:`(b \times n \times p)` tensor. Both :attr:`alpha` and :attr:`beta` mean the
  6428. same as the scaling factors used in :meth:`torch.addbmm`.
  6429. .. math::
  6430. \text{out}_i = \beta\ \text{input}_i + \alpha\ (\text{batch1}_i \mathbin{@} \text{batch2}_i)
  6431. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  6432. it will not be propagated.
  6433. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  6434. :attr:`alpha` must be real numbers, otherwise they should be integers.
  6435. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  6436. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  6437. Args:
  6438. input (Tensor): the tensor to be added
  6439. batch1 (Tensor): the first batch of matrices to be multiplied
  6440. batch2 (Tensor): the second batch of matrices to be multiplied
  6441. out_dtype (dtype, optional): the dtype of the output tensor,
  6442. Supported only on CUDA and for torch.float32 given
  6443. torch.float16/torch.bfloat16 input dtypes
  6444. Keyword args:
  6445. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  6446. alpha (Number, optional): multiplier for :math:`\text{batch1} \mathbin{@} \text{batch2}` (:math:`\alpha`)
  6447. out (Tensor, optional): the output tensor.
  6448. Example::
  6449. >>> M = torch.randn(10, 3, 5)
  6450. >>> batch1 = torch.randn(10, 3, 4)
  6451. >>> batch2 = torch.randn(10, 4, 5)
  6452. >>> torch.baddbmm(M, batch1, batch2).size()
  6453. torch.Size([10, 3, 5])
  6454. """
  6455. @overload
  6456. def baddbmm(
  6457. beta: Number | _complex,
  6458. self: Tensor,
  6459. alpha: Number | _complex,
  6460. batch1: Tensor,
  6461. batch2: Tensor,
  6462. *,
  6463. out: Tensor,
  6464. ) -> Tensor:
  6465. r"""
  6466. baddbmm(input, batch1, batch2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  6467. Performs a batch matrix-matrix product of matrices in :attr:`batch1`
  6468. and :attr:`batch2`.
  6469. :attr:`input` is added to the final result.
  6470. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the same
  6471. number of matrices.
  6472. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  6473. :math:`(b \times m \times p)` tensor, then :attr:`input` must be
  6474. :ref:`broadcastable <broadcasting-semantics>` with a
  6475. :math:`(b \times n \times p)` tensor and :attr:`out` will be a
  6476. :math:`(b \times n \times p)` tensor. Both :attr:`alpha` and :attr:`beta` mean the
  6477. same as the scaling factors used in :meth:`torch.addbmm`.
  6478. .. math::
  6479. \text{out}_i = \beta\ \text{input}_i + \alpha\ (\text{batch1}_i \mathbin{@} \text{batch2}_i)
  6480. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  6481. it will not be propagated.
  6482. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  6483. :attr:`alpha` must be real numbers, otherwise they should be integers.
  6484. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  6485. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  6486. Args:
  6487. input (Tensor): the tensor to be added
  6488. batch1 (Tensor): the first batch of matrices to be multiplied
  6489. batch2 (Tensor): the second batch of matrices to be multiplied
  6490. out_dtype (dtype, optional): the dtype of the output tensor,
  6491. Supported only on CUDA and for torch.float32 given
  6492. torch.float16/torch.bfloat16 input dtypes
  6493. Keyword args:
  6494. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  6495. alpha (Number, optional): multiplier for :math:`\text{batch1} \mathbin{@} \text{batch2}` (:math:`\alpha`)
  6496. out (Tensor, optional): the output tensor.
  6497. Example::
  6498. >>> M = torch.randn(10, 3, 5)
  6499. >>> batch1 = torch.randn(10, 3, 4)
  6500. >>> batch2 = torch.randn(10, 4, 5)
  6501. >>> torch.baddbmm(M, batch1, batch2).size()
  6502. torch.Size([10, 3, 5])
  6503. """
  6504. @overload
  6505. def baddbmm(
  6506. input: Tensor,
  6507. batch1: Tensor,
  6508. batch2: Tensor,
  6509. *,
  6510. beta: Number | _complex = 1,
  6511. alpha: Number | _complex = 1,
  6512. out: Tensor | None = None,
  6513. ) -> Tensor:
  6514. r"""
  6515. baddbmm(input, batch1, batch2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  6516. Performs a batch matrix-matrix product of matrices in :attr:`batch1`
  6517. and :attr:`batch2`.
  6518. :attr:`input` is added to the final result.
  6519. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the same
  6520. number of matrices.
  6521. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  6522. :math:`(b \times m \times p)` tensor, then :attr:`input` must be
  6523. :ref:`broadcastable <broadcasting-semantics>` with a
  6524. :math:`(b \times n \times p)` tensor and :attr:`out` will be a
  6525. :math:`(b \times n \times p)` tensor. Both :attr:`alpha` and :attr:`beta` mean the
  6526. same as the scaling factors used in :meth:`torch.addbmm`.
  6527. .. math::
  6528. \text{out}_i = \beta\ \text{input}_i + \alpha\ (\text{batch1}_i \mathbin{@} \text{batch2}_i)
  6529. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  6530. it will not be propagated.
  6531. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  6532. :attr:`alpha` must be real numbers, otherwise they should be integers.
  6533. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  6534. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  6535. Args:
  6536. input (Tensor): the tensor to be added
  6537. batch1 (Tensor): the first batch of matrices to be multiplied
  6538. batch2 (Tensor): the second batch of matrices to be multiplied
  6539. out_dtype (dtype, optional): the dtype of the output tensor,
  6540. Supported only on CUDA and for torch.float32 given
  6541. torch.float16/torch.bfloat16 input dtypes
  6542. Keyword args:
  6543. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  6544. alpha (Number, optional): multiplier for :math:`\text{batch1} \mathbin{@} \text{batch2}` (:math:`\alpha`)
  6545. out (Tensor, optional): the output tensor.
  6546. Example::
  6547. >>> M = torch.randn(10, 3, 5)
  6548. >>> batch1 = torch.randn(10, 3, 4)
  6549. >>> batch2 = torch.randn(10, 4, 5)
  6550. >>> torch.baddbmm(M, batch1, batch2).size()
  6551. torch.Size([10, 3, 5])
  6552. """
  6553. @overload
  6554. def baddbmm(
  6555. input: Tensor,
  6556. batch1: Tensor,
  6557. batch2: Tensor,
  6558. out_dtype: _dtype,
  6559. *,
  6560. beta: Number | _complex = 1,
  6561. alpha: Number | _complex = 1,
  6562. out: Tensor | None = None,
  6563. ) -> Tensor:
  6564. r"""
  6565. baddbmm(input, batch1, batch2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  6566. Performs a batch matrix-matrix product of matrices in :attr:`batch1`
  6567. and :attr:`batch2`.
  6568. :attr:`input` is added to the final result.
  6569. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the same
  6570. number of matrices.
  6571. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  6572. :math:`(b \times m \times p)` tensor, then :attr:`input` must be
  6573. :ref:`broadcastable <broadcasting-semantics>` with a
  6574. :math:`(b \times n \times p)` tensor and :attr:`out` will be a
  6575. :math:`(b \times n \times p)` tensor. Both :attr:`alpha` and :attr:`beta` mean the
  6576. same as the scaling factors used in :meth:`torch.addbmm`.
  6577. .. math::
  6578. \text{out}_i = \beta\ \text{input}_i + \alpha\ (\text{batch1}_i \mathbin{@} \text{batch2}_i)
  6579. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  6580. it will not be propagated.
  6581. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  6582. :attr:`alpha` must be real numbers, otherwise they should be integers.
  6583. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  6584. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  6585. Args:
  6586. input (Tensor): the tensor to be added
  6587. batch1 (Tensor): the first batch of matrices to be multiplied
  6588. batch2 (Tensor): the second batch of matrices to be multiplied
  6589. out_dtype (dtype, optional): the dtype of the output tensor,
  6590. Supported only on CUDA and for torch.float32 given
  6591. torch.float16/torch.bfloat16 input dtypes
  6592. Keyword args:
  6593. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  6594. alpha (Number, optional): multiplier for :math:`\text{batch1} \mathbin{@} \text{batch2}` (:math:`\alpha`)
  6595. out (Tensor, optional): the output tensor.
  6596. Example::
  6597. >>> M = torch.randn(10, 3, 5)
  6598. >>> batch1 = torch.randn(10, 3, 4)
  6599. >>> batch2 = torch.randn(10, 4, 5)
  6600. >>> torch.baddbmm(M, batch1, batch2).size()
  6601. torch.Size([10, 3, 5])
  6602. """
  6603. @overload
  6604. def baddbmm(
  6605. beta: Number | _complex,
  6606. self: Tensor,
  6607. batch1: Tensor,
  6608. batch2: Tensor,
  6609. ) -> Tensor:
  6610. r"""
  6611. baddbmm(input, batch1, batch2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  6612. Performs a batch matrix-matrix product of matrices in :attr:`batch1`
  6613. and :attr:`batch2`.
  6614. :attr:`input` is added to the final result.
  6615. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the same
  6616. number of matrices.
  6617. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  6618. :math:`(b \times m \times p)` tensor, then :attr:`input` must be
  6619. :ref:`broadcastable <broadcasting-semantics>` with a
  6620. :math:`(b \times n \times p)` tensor and :attr:`out` will be a
  6621. :math:`(b \times n \times p)` tensor. Both :attr:`alpha` and :attr:`beta` mean the
  6622. same as the scaling factors used in :meth:`torch.addbmm`.
  6623. .. math::
  6624. \text{out}_i = \beta\ \text{input}_i + \alpha\ (\text{batch1}_i \mathbin{@} \text{batch2}_i)
  6625. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  6626. it will not be propagated.
  6627. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  6628. :attr:`alpha` must be real numbers, otherwise they should be integers.
  6629. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  6630. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  6631. Args:
  6632. input (Tensor): the tensor to be added
  6633. batch1 (Tensor): the first batch of matrices to be multiplied
  6634. batch2 (Tensor): the second batch of matrices to be multiplied
  6635. out_dtype (dtype, optional): the dtype of the output tensor,
  6636. Supported only on CUDA and for torch.float32 given
  6637. torch.float16/torch.bfloat16 input dtypes
  6638. Keyword args:
  6639. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  6640. alpha (Number, optional): multiplier for :math:`\text{batch1} \mathbin{@} \text{batch2}` (:math:`\alpha`)
  6641. out (Tensor, optional): the output tensor.
  6642. Example::
  6643. >>> M = torch.randn(10, 3, 5)
  6644. >>> batch1 = torch.randn(10, 3, 4)
  6645. >>> batch2 = torch.randn(10, 4, 5)
  6646. >>> torch.baddbmm(M, batch1, batch2).size()
  6647. torch.Size([10, 3, 5])
  6648. """
  6649. @overload
  6650. def baddbmm(
  6651. beta: Number | _complex,
  6652. self: Tensor,
  6653. batch1: Tensor,
  6654. batch2: Tensor,
  6655. *,
  6656. out: Tensor,
  6657. ) -> Tensor:
  6658. r"""
  6659. baddbmm(input, batch1, batch2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  6660. Performs a batch matrix-matrix product of matrices in :attr:`batch1`
  6661. and :attr:`batch2`.
  6662. :attr:`input` is added to the final result.
  6663. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the same
  6664. number of matrices.
  6665. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  6666. :math:`(b \times m \times p)` tensor, then :attr:`input` must be
  6667. :ref:`broadcastable <broadcasting-semantics>` with a
  6668. :math:`(b \times n \times p)` tensor and :attr:`out` will be a
  6669. :math:`(b \times n \times p)` tensor. Both :attr:`alpha` and :attr:`beta` mean the
  6670. same as the scaling factors used in :meth:`torch.addbmm`.
  6671. .. math::
  6672. \text{out}_i = \beta\ \text{input}_i + \alpha\ (\text{batch1}_i \mathbin{@} \text{batch2}_i)
  6673. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  6674. it will not be propagated.
  6675. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  6676. :attr:`alpha` must be real numbers, otherwise they should be integers.
  6677. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  6678. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  6679. Args:
  6680. input (Tensor): the tensor to be added
  6681. batch1 (Tensor): the first batch of matrices to be multiplied
  6682. batch2 (Tensor): the second batch of matrices to be multiplied
  6683. out_dtype (dtype, optional): the dtype of the output tensor,
  6684. Supported only on CUDA and for torch.float32 given
  6685. torch.float16/torch.bfloat16 input dtypes
  6686. Keyword args:
  6687. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  6688. alpha (Number, optional): multiplier for :math:`\text{batch1} \mathbin{@} \text{batch2}` (:math:`\alpha`)
  6689. out (Tensor, optional): the output tensor.
  6690. Example::
  6691. >>> M = torch.randn(10, 3, 5)
  6692. >>> batch1 = torch.randn(10, 3, 4)
  6693. >>> batch2 = torch.randn(10, 4, 5)
  6694. >>> torch.baddbmm(M, batch1, batch2).size()
  6695. torch.Size([10, 3, 5])
  6696. """
  6697. @overload
  6698. def bartlett_window(
  6699. window_length: _int,
  6700. *,
  6701. dtype: _dtype | None = None,
  6702. layout: _layout | None = None,
  6703. device: DeviceLikeType | None = None,
  6704. pin_memory: _bool | None = False,
  6705. requires_grad: _bool | None = False,
  6706. ) -> Tensor:
  6707. r"""
  6708. bartlett_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  6709. Bartlett window function.
  6710. .. math::
  6711. w[n] = 1 - \left| \frac{2n}{N-1} - 1 \right| = \begin{cases}
  6712. \frac{2n}{N - 1} & \text{if } 0 \leq n \leq \frac{N - 1}{2} \\
  6713. 2 - \frac{2n}{N - 1} & \text{if } \frac{N - 1}{2} < n < N \\
  6714. \end{cases},
  6715. where :math:`N` is the full window size.
  6716. The input :attr:`window_length` is a positive integer controlling the
  6717. returned window size. :attr:`periodic` flag determines whether the returned
  6718. window trims off the last duplicate value from the symmetric window and is
  6719. ready to be used as a periodic window with functions like
  6720. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  6721. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  6722. ``torch.bartlett_window(L, periodic=True)`` equal to
  6723. ``torch.bartlett_window(L + 1, periodic=False)[:-1])``.
  6724. .. note::
  6725. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  6726. Arguments:
  6727. window_length (int): the size of returned window
  6728. periodic (bool, optional): If True, returns a window to be used as periodic
  6729. function. If False, return a symmetric window.
  6730. Keyword args:
  6731. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  6732. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  6733. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  6734. ``torch.strided`` (dense layout) is supported.
  6735. device (:class:`torch.device`, optional): the desired device of returned tensor.
  6736. Default: if ``None``, uses the current device for the default tensor type
  6737. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  6738. for CPU tensor types and the current CUDA device for CUDA tensor types.
  6739. requires_grad (bool, optional): If autograd should record operations on the
  6740. returned tensor. Default: ``False``.
  6741. Returns:
  6742. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window
  6743. """
  6744. @overload
  6745. def bartlett_window(
  6746. window_length: _int,
  6747. periodic: _bool,
  6748. *,
  6749. dtype: _dtype | None = None,
  6750. layout: _layout | None = None,
  6751. device: DeviceLikeType | None = None,
  6752. pin_memory: _bool | None = False,
  6753. requires_grad: _bool | None = False,
  6754. ) -> Tensor:
  6755. r"""
  6756. bartlett_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  6757. Bartlett window function.
  6758. .. math::
  6759. w[n] = 1 - \left| \frac{2n}{N-1} - 1 \right| = \begin{cases}
  6760. \frac{2n}{N - 1} & \text{if } 0 \leq n \leq \frac{N - 1}{2} \\
  6761. 2 - \frac{2n}{N - 1} & \text{if } \frac{N - 1}{2} < n < N \\
  6762. \end{cases},
  6763. where :math:`N` is the full window size.
  6764. The input :attr:`window_length` is a positive integer controlling the
  6765. returned window size. :attr:`periodic` flag determines whether the returned
  6766. window trims off the last duplicate value from the symmetric window and is
  6767. ready to be used as a periodic window with functions like
  6768. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  6769. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  6770. ``torch.bartlett_window(L, periodic=True)`` equal to
  6771. ``torch.bartlett_window(L + 1, periodic=False)[:-1])``.
  6772. .. note::
  6773. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  6774. Arguments:
  6775. window_length (int): the size of returned window
  6776. periodic (bool, optional): If True, returns a window to be used as periodic
  6777. function. If False, return a symmetric window.
  6778. Keyword args:
  6779. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  6780. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  6781. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  6782. ``torch.strided`` (dense layout) is supported.
  6783. device (:class:`torch.device`, optional): the desired device of returned tensor.
  6784. Default: if ``None``, uses the current device for the default tensor type
  6785. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  6786. for CPU tensor types and the current CUDA device for CUDA tensor types.
  6787. requires_grad (bool, optional): If autograd should record operations on the
  6788. returned tensor. Default: ``False``.
  6789. Returns:
  6790. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window
  6791. """
  6792. def batch_norm(
  6793. input: Tensor,
  6794. weight: Tensor | None,
  6795. bias: Tensor | None,
  6796. running_mean: Tensor | None,
  6797. running_var: Tensor | None,
  6798. training: _bool,
  6799. momentum: _float,
  6800. eps: _float,
  6801. cudnn_enabled: _bool,
  6802. ) -> Tensor: ...
  6803. def batch_norm_backward_elemt(
  6804. grad_out: Tensor,
  6805. input: Tensor,
  6806. mean: Tensor,
  6807. invstd: Tensor,
  6808. weight: Tensor | None,
  6809. sum_dy: Tensor,
  6810. sum_dy_xmu: Tensor,
  6811. count: Tensor,
  6812. ) -> Tensor: ...
  6813. def batch_norm_backward_reduce(
  6814. grad_out: Tensor,
  6815. input: Tensor,
  6816. mean: Tensor,
  6817. invstd: Tensor,
  6818. weight: Tensor | None,
  6819. input_g: _bool,
  6820. weight_g: _bool,
  6821. bias_g: _bool,
  6822. ) -> tuple[Tensor, Tensor, Tensor, Tensor]: ...
  6823. def batch_norm_elemt(
  6824. input: Tensor,
  6825. weight: Tensor | None,
  6826. bias: Tensor | None,
  6827. mean: Tensor,
  6828. invstd: Tensor,
  6829. eps: _float,
  6830. *,
  6831. out: Tensor | None = None,
  6832. ) -> Tensor: ...
  6833. def batch_norm_gather_stats(
  6834. input: Tensor,
  6835. mean: Tensor,
  6836. invstd: Tensor,
  6837. running_mean: Tensor | None,
  6838. running_var: Tensor | None,
  6839. momentum: _float,
  6840. eps: _float,
  6841. count: _int,
  6842. ) -> tuple[Tensor, Tensor]: ...
  6843. def batch_norm_gather_stats_with_counts(
  6844. input: Tensor,
  6845. mean: Tensor,
  6846. invstd: Tensor,
  6847. running_mean: Tensor | None,
  6848. running_var: Tensor | None,
  6849. momentum: _float,
  6850. eps: _float,
  6851. counts: Tensor,
  6852. ) -> tuple[Tensor, Tensor]: ...
  6853. def batch_norm_stats(input: Tensor, eps: _float) -> tuple[Tensor, Tensor]: ...
  6854. def batch_norm_update_stats(
  6855. input: Tensor,
  6856. running_mean: Tensor | None,
  6857. running_var: Tensor | None,
  6858. momentum: _float,
  6859. ) -> tuple[Tensor, Tensor]: ...
  6860. @overload
  6861. def bernoulli(
  6862. input: Tensor,
  6863. *,
  6864. generator: Generator | None = None,
  6865. out: Tensor | None = None,
  6866. ) -> Tensor:
  6867. r"""
  6868. bernoulli(input: Tensor, *, generator: Optional[Generator], out: Optional[Tensor]) -> Tensor
  6869. Draws binary random numbers (0 or 1) from a Bernoulli distribution.
  6870. The :attr:`input` tensor should be a tensor containing probabilities
  6871. to be used for drawing the binary random number.
  6872. Hence, all values in :attr:`input` have to be in the range:
  6873. :math:`0 \leq \text{input}_i \leq 1`.
  6874. The :math:`\text{i}^{th}` element of the output tensor will draw a
  6875. value :math:`1` according to the :math:`\text{i}^{th}` probability value given
  6876. in :attr:`input`.
  6877. .. math::
  6878. \text{out}_{i} \sim \mathrm{Bernoulli}(p = \text{input}_{i})
  6879. The returned :attr:`out` tensor only has values 0 or 1 and is of the same
  6880. shape as :attr:`input`.
  6881. :attr:`out` can have integral ``dtype``, but :attr:`input` must have floating
  6882. point ``dtype``.
  6883. Args:
  6884. input (Tensor): the input tensor of probability values for the Bernoulli distribution
  6885. Keyword args:
  6886. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  6887. out (Tensor, optional): the output tensor.
  6888. Example::
  6889. >>> a = torch.empty(3, 3).uniform_(0, 1) # generate a uniform random matrix with range [0, 1]
  6890. >>> a
  6891. tensor([[ 0.1737, 0.0950, 0.3609],
  6892. [ 0.7148, 0.0289, 0.2676],
  6893. [ 0.9456, 0.8937, 0.7202]])
  6894. >>> torch.bernoulli(a)
  6895. tensor([[ 1., 0., 0.],
  6896. [ 0., 0., 0.],
  6897. [ 1., 1., 1.]])
  6898. >>> a = torch.ones(3, 3) # probability of drawing "1" is 1
  6899. >>> torch.bernoulli(a)
  6900. tensor([[ 1., 1., 1.],
  6901. [ 1., 1., 1.],
  6902. [ 1., 1., 1.]])
  6903. >>> a = torch.zeros(3, 3) # probability of drawing "1" is 0
  6904. >>> torch.bernoulli(a)
  6905. tensor([[ 0., 0., 0.],
  6906. [ 0., 0., 0.],
  6907. [ 0., 0., 0.]])
  6908. """
  6909. @overload
  6910. def bernoulli(
  6911. input: Tensor,
  6912. p: _float,
  6913. *,
  6914. generator: Generator | None = None,
  6915. ) -> Tensor:
  6916. r"""
  6917. bernoulli(input: Tensor, *, generator: Optional[Generator], out: Optional[Tensor]) -> Tensor
  6918. Draws binary random numbers (0 or 1) from a Bernoulli distribution.
  6919. The :attr:`input` tensor should be a tensor containing probabilities
  6920. to be used for drawing the binary random number.
  6921. Hence, all values in :attr:`input` have to be in the range:
  6922. :math:`0 \leq \text{input}_i \leq 1`.
  6923. The :math:`\text{i}^{th}` element of the output tensor will draw a
  6924. value :math:`1` according to the :math:`\text{i}^{th}` probability value given
  6925. in :attr:`input`.
  6926. .. math::
  6927. \text{out}_{i} \sim \mathrm{Bernoulli}(p = \text{input}_{i})
  6928. The returned :attr:`out` tensor only has values 0 or 1 and is of the same
  6929. shape as :attr:`input`.
  6930. :attr:`out` can have integral ``dtype``, but :attr:`input` must have floating
  6931. point ``dtype``.
  6932. Args:
  6933. input (Tensor): the input tensor of probability values for the Bernoulli distribution
  6934. Keyword args:
  6935. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  6936. out (Tensor, optional): the output tensor.
  6937. Example::
  6938. >>> a = torch.empty(3, 3).uniform_(0, 1) # generate a uniform random matrix with range [0, 1]
  6939. >>> a
  6940. tensor([[ 0.1737, 0.0950, 0.3609],
  6941. [ 0.7148, 0.0289, 0.2676],
  6942. [ 0.9456, 0.8937, 0.7202]])
  6943. >>> torch.bernoulli(a)
  6944. tensor([[ 1., 0., 0.],
  6945. [ 0., 0., 0.],
  6946. [ 1., 1., 1.]])
  6947. >>> a = torch.ones(3, 3) # probability of drawing "1" is 1
  6948. >>> torch.bernoulli(a)
  6949. tensor([[ 1., 1., 1.],
  6950. [ 1., 1., 1.],
  6951. [ 1., 1., 1.]])
  6952. >>> a = torch.zeros(3, 3) # probability of drawing "1" is 0
  6953. >>> torch.bernoulli(a)
  6954. tensor([[ 0., 0., 0.],
  6955. [ 0., 0., 0.],
  6956. [ 0., 0., 0.]])
  6957. """
  6958. def bilinear(
  6959. input1: Tensor,
  6960. input2: Tensor,
  6961. weight: Tensor,
  6962. bias: Tensor | None = None,
  6963. ) -> Tensor: ...
  6964. def binary_cross_entropy_with_logits(
  6965. input: Tensor,
  6966. target: Tensor,
  6967. weight: Tensor | None = None,
  6968. pos_weight: Tensor | None = None,
  6969. reduction: _int = 1,
  6970. ) -> Tensor: ...
  6971. def bincount(
  6972. input: Tensor,
  6973. weights: Tensor | None = None,
  6974. minlength: _int | SymInt = 0,
  6975. ) -> Tensor:
  6976. r"""
  6977. bincount(input, weights=None, minlength=0) -> Tensor
  6978. Count the frequency of each value in an array of non-negative ints.
  6979. The number of bins (size 1) is one larger than the largest value in
  6980. :attr:`input` unless :attr:`input` is empty, in which case the result is a
  6981. tensor of size 0. If :attr:`minlength` is specified, the number of bins is at least
  6982. :attr:`minlength` and if :attr:`input` is empty, then the result is tensor of size
  6983. :attr:`minlength` filled with zeros. If ``n`` is the value at position ``i``,
  6984. ``out[n] += weights[i]`` if :attr:`weights` is specified else
  6985. ``out[n] += 1``.
  6986. Note:
  6987. This operation may produce nondeterministic gradients when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
  6988. Arguments:
  6989. input (Tensor): 1-d int tensor
  6990. weights (Tensor): optional, weight for each value in the input tensor.
  6991. Should be of same size as input tensor.
  6992. minlength (int): optional, minimum number of bins. Should be non-negative.
  6993. Returns:
  6994. output (Tensor): a tensor of shape ``Size([max(input) + 1])`` if
  6995. :attr:`input` is non-empty, else ``Size(0)``
  6996. Example::
  6997. >>> input = torch.randint(0, 8, (5,), dtype=torch.int64)
  6998. >>> weights = torch.linspace(0, 1, steps=5)
  6999. >>> input, weights
  7000. (tensor([4, 3, 6, 3, 4]),
  7001. tensor([ 0.0000, 0.2500, 0.5000, 0.7500, 1.0000])
  7002. >>> torch.bincount(input)
  7003. tensor([0, 0, 0, 2, 2, 0, 1])
  7004. >>> input.bincount(weights)
  7005. tensor([0.0000, 0.0000, 0.0000, 1.0000, 1.0000, 0.0000, 0.5000])
  7006. """
  7007. def binomial(
  7008. count: Tensor,
  7009. prob: Tensor,
  7010. generator: Generator | None = None,
  7011. ) -> Tensor: ...
  7012. @overload
  7013. def bitwise_and(
  7014. input: Tensor,
  7015. other: Tensor,
  7016. *,
  7017. out: Tensor | None = None,
  7018. ) -> Tensor:
  7019. r"""
  7020. bitwise_and(input, other, *, out=None) -> Tensor
  7021. Computes the bitwise AND of :attr:`input` and :attr:`other`. The input tensor must be of
  7022. integral or Boolean types. For bool tensors, it computes the logical AND.
  7023. Args:
  7024. input: the first input tensor
  7025. other: the second input tensor
  7026. Keyword args:
  7027. out (Tensor, optional): the output tensor.
  7028. Example::
  7029. >>> torch.bitwise_and(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7030. tensor([1, 0, 3], dtype=torch.int8)
  7031. >>> torch.bitwise_and(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7032. tensor([ False, True, False])
  7033. """
  7034. @overload
  7035. def bitwise_and(self: Number | _complex, other: Tensor) -> Tensor:
  7036. r"""
  7037. bitwise_and(input, other, *, out=None) -> Tensor
  7038. Computes the bitwise AND of :attr:`input` and :attr:`other`. The input tensor must be of
  7039. integral or Boolean types. For bool tensors, it computes the logical AND.
  7040. Args:
  7041. input: the first input tensor
  7042. other: the second input tensor
  7043. Keyword args:
  7044. out (Tensor, optional): the output tensor.
  7045. Example::
  7046. >>> torch.bitwise_and(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7047. tensor([1, 0, 3], dtype=torch.int8)
  7048. >>> torch.bitwise_and(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7049. tensor([ False, True, False])
  7050. """
  7051. @overload
  7052. def bitwise_and(
  7053. input: Tensor,
  7054. other: Number | _complex,
  7055. *,
  7056. out: Tensor | None = None,
  7057. ) -> Tensor:
  7058. r"""
  7059. bitwise_and(input, other, *, out=None) -> Tensor
  7060. Computes the bitwise AND of :attr:`input` and :attr:`other`. The input tensor must be of
  7061. integral or Boolean types. For bool tensors, it computes the logical AND.
  7062. Args:
  7063. input: the first input tensor
  7064. other: the second input tensor
  7065. Keyword args:
  7066. out (Tensor, optional): the output tensor.
  7067. Example::
  7068. >>> torch.bitwise_and(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7069. tensor([1, 0, 3], dtype=torch.int8)
  7070. >>> torch.bitwise_and(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7071. tensor([ False, True, False])
  7072. """
  7073. @overload
  7074. def bitwise_left_shift(
  7075. input: Tensor,
  7076. other: Tensor,
  7077. *,
  7078. out: Tensor | None = None,
  7079. ) -> Tensor:
  7080. r"""
  7081. bitwise_left_shift(input, other, *, out=None) -> Tensor
  7082. Computes the left arithmetic shift of :attr:`input` by :attr:`other` bits.
  7083. The input tensor must be of integral type. This operator supports
  7084. :ref:`broadcasting to a common shape <broadcasting-semantics>` and
  7085. :ref:`type promotion <type-promotion-doc>`.
  7086. The operation applied is:
  7087. .. math::
  7088. \text{out}_i = \text{input}_i << \text{other}_i
  7089. Args:
  7090. input (Tensor or Scalar): the first input tensor
  7091. other (Tensor or Scalar): the second input tensor
  7092. Keyword args:
  7093. out (Tensor, optional): the output tensor.
  7094. Example::
  7095. >>> torch.bitwise_left_shift(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7096. tensor([-2, -2, 24], dtype=torch.int8)
  7097. """
  7098. @overload
  7099. def bitwise_left_shift(self: Number | _complex, other: Tensor) -> Tensor:
  7100. r"""
  7101. bitwise_left_shift(input, other, *, out=None) -> Tensor
  7102. Computes the left arithmetic shift of :attr:`input` by :attr:`other` bits.
  7103. The input tensor must be of integral type. This operator supports
  7104. :ref:`broadcasting to a common shape <broadcasting-semantics>` and
  7105. :ref:`type promotion <type-promotion-doc>`.
  7106. The operation applied is:
  7107. .. math::
  7108. \text{out}_i = \text{input}_i << \text{other}_i
  7109. Args:
  7110. input (Tensor or Scalar): the first input tensor
  7111. other (Tensor or Scalar): the second input tensor
  7112. Keyword args:
  7113. out (Tensor, optional): the output tensor.
  7114. Example::
  7115. >>> torch.bitwise_left_shift(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7116. tensor([-2, -2, 24], dtype=torch.int8)
  7117. """
  7118. @overload
  7119. def bitwise_left_shift(
  7120. input: Tensor,
  7121. other: Number | _complex,
  7122. *,
  7123. out: Tensor | None = None,
  7124. ) -> Tensor:
  7125. r"""
  7126. bitwise_left_shift(input, other, *, out=None) -> Tensor
  7127. Computes the left arithmetic shift of :attr:`input` by :attr:`other` bits.
  7128. The input tensor must be of integral type. This operator supports
  7129. :ref:`broadcasting to a common shape <broadcasting-semantics>` and
  7130. :ref:`type promotion <type-promotion-doc>`.
  7131. The operation applied is:
  7132. .. math::
  7133. \text{out}_i = \text{input}_i << \text{other}_i
  7134. Args:
  7135. input (Tensor or Scalar): the first input tensor
  7136. other (Tensor or Scalar): the second input tensor
  7137. Keyword args:
  7138. out (Tensor, optional): the output tensor.
  7139. Example::
  7140. >>> torch.bitwise_left_shift(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7141. tensor([-2, -2, 24], dtype=torch.int8)
  7142. """
  7143. def bitwise_not(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  7144. r"""
  7145. bitwise_not(input, *, out=None) -> Tensor
  7146. Computes the bitwise NOT of the given input tensor. The input tensor must be of
  7147. integral or Boolean types. For bool tensors, it computes the logical NOT.
  7148. Args:
  7149. input (Tensor): the input tensor.
  7150. Keyword args:
  7151. out (Tensor, optional): the output tensor.
  7152. Example::
  7153. >>> torch.bitwise_not(torch.tensor([-1, -2, 3], dtype=torch.int8))
  7154. tensor([ 0, 1, -4], dtype=torch.int8)
  7155. """
  7156. @overload
  7157. def bitwise_or(
  7158. input: Tensor,
  7159. other: Tensor,
  7160. *,
  7161. out: Tensor | None = None,
  7162. ) -> Tensor:
  7163. r"""
  7164. bitwise_or(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
  7165. Computes the bitwise OR of :attr:`input` and :attr:`other`. The input tensor must be of
  7166. integral or Boolean types. For bool tensors, it computes the logical OR.
  7167. Args:
  7168. input: the first input tensor
  7169. other: the second input tensor
  7170. Keyword args:
  7171. out (Tensor, optional): the output tensor.
  7172. Example::
  7173. >>> torch.bitwise_or(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7174. tensor([-1, -2, 3], dtype=torch.int8)
  7175. >>> torch.bitwise_or(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7176. tensor([ True, True, False])
  7177. """
  7178. @overload
  7179. def bitwise_or(self: Number | _complex, other: Tensor) -> Tensor:
  7180. r"""
  7181. bitwise_or(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
  7182. Computes the bitwise OR of :attr:`input` and :attr:`other`. The input tensor must be of
  7183. integral or Boolean types. For bool tensors, it computes the logical OR.
  7184. Args:
  7185. input: the first input tensor
  7186. other: the second input tensor
  7187. Keyword args:
  7188. out (Tensor, optional): the output tensor.
  7189. Example::
  7190. >>> torch.bitwise_or(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7191. tensor([-1, -2, 3], dtype=torch.int8)
  7192. >>> torch.bitwise_or(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7193. tensor([ True, True, False])
  7194. """
  7195. @overload
  7196. def bitwise_or(
  7197. input: Tensor,
  7198. other: Number | _complex,
  7199. *,
  7200. out: Tensor | None = None,
  7201. ) -> Tensor:
  7202. r"""
  7203. bitwise_or(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
  7204. Computes the bitwise OR of :attr:`input` and :attr:`other`. The input tensor must be of
  7205. integral or Boolean types. For bool tensors, it computes the logical OR.
  7206. Args:
  7207. input: the first input tensor
  7208. other: the second input tensor
  7209. Keyword args:
  7210. out (Tensor, optional): the output tensor.
  7211. Example::
  7212. >>> torch.bitwise_or(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7213. tensor([-1, -2, 3], dtype=torch.int8)
  7214. >>> torch.bitwise_or(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7215. tensor([ True, True, False])
  7216. """
  7217. @overload
  7218. def bitwise_right_shift(
  7219. input: Tensor,
  7220. other: Tensor,
  7221. *,
  7222. out: Tensor | None = None,
  7223. ) -> Tensor:
  7224. r"""
  7225. bitwise_right_shift(input, other, *, out=None) -> Tensor
  7226. Computes the right arithmetic shift of :attr:`input` by :attr:`other` bits.
  7227. The input tensor must be of integral type. This operator supports
  7228. :ref:`broadcasting to a common shape <broadcasting-semantics>` and
  7229. :ref:`type promotion <type-promotion-doc>`.
  7230. In any case, if the value of the right operand is negative or is greater
  7231. or equal to the number of bits in the promoted left operand, the behavior is undefined.
  7232. The operation applied is:
  7233. .. math::
  7234. \text{out}_i = \text{input}_i >> \text{other}_i
  7235. Args:
  7236. input (Tensor or Scalar): the first input tensor
  7237. other (Tensor or Scalar): the second input tensor
  7238. Keyword args:
  7239. out (Tensor, optional): the output tensor.
  7240. Example::
  7241. >>> torch.bitwise_right_shift(torch.tensor([-2, -7, 31], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7242. tensor([-1, -7, 3], dtype=torch.int8)
  7243. """
  7244. @overload
  7245. def bitwise_right_shift(self: Number | _complex, other: Tensor) -> Tensor:
  7246. r"""
  7247. bitwise_right_shift(input, other, *, out=None) -> Tensor
  7248. Computes the right arithmetic shift of :attr:`input` by :attr:`other` bits.
  7249. The input tensor must be of integral type. This operator supports
  7250. :ref:`broadcasting to a common shape <broadcasting-semantics>` and
  7251. :ref:`type promotion <type-promotion-doc>`.
  7252. In any case, if the value of the right operand is negative or is greater
  7253. or equal to the number of bits in the promoted left operand, the behavior is undefined.
  7254. The operation applied is:
  7255. .. math::
  7256. \text{out}_i = \text{input}_i >> \text{other}_i
  7257. Args:
  7258. input (Tensor or Scalar): the first input tensor
  7259. other (Tensor or Scalar): the second input tensor
  7260. Keyword args:
  7261. out (Tensor, optional): the output tensor.
  7262. Example::
  7263. >>> torch.bitwise_right_shift(torch.tensor([-2, -7, 31], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7264. tensor([-1, -7, 3], dtype=torch.int8)
  7265. """
  7266. @overload
  7267. def bitwise_right_shift(
  7268. input: Tensor,
  7269. other: Number | _complex,
  7270. *,
  7271. out: Tensor | None = None,
  7272. ) -> Tensor:
  7273. r"""
  7274. bitwise_right_shift(input, other, *, out=None) -> Tensor
  7275. Computes the right arithmetic shift of :attr:`input` by :attr:`other` bits.
  7276. The input tensor must be of integral type. This operator supports
  7277. :ref:`broadcasting to a common shape <broadcasting-semantics>` and
  7278. :ref:`type promotion <type-promotion-doc>`.
  7279. In any case, if the value of the right operand is negative or is greater
  7280. or equal to the number of bits in the promoted left operand, the behavior is undefined.
  7281. The operation applied is:
  7282. .. math::
  7283. \text{out}_i = \text{input}_i >> \text{other}_i
  7284. Args:
  7285. input (Tensor or Scalar): the first input tensor
  7286. other (Tensor or Scalar): the second input tensor
  7287. Keyword args:
  7288. out (Tensor, optional): the output tensor.
  7289. Example::
  7290. >>> torch.bitwise_right_shift(torch.tensor([-2, -7, 31], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7291. tensor([-1, -7, 3], dtype=torch.int8)
  7292. """
  7293. @overload
  7294. def bitwise_xor(
  7295. input: Tensor,
  7296. other: Tensor,
  7297. *,
  7298. out: Tensor | None = None,
  7299. ) -> Tensor:
  7300. r"""
  7301. bitwise_xor(input, other, *, out=None) -> Tensor
  7302. Computes the bitwise XOR of :attr:`input` and :attr:`other`. The input tensor must be of
  7303. integral or Boolean types. For bool tensors, it computes the logical XOR.
  7304. Args:
  7305. input: the first input tensor
  7306. other: the second input tensor
  7307. Keyword args:
  7308. out (Tensor, optional): the output tensor.
  7309. Example::
  7310. >>> torch.bitwise_xor(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7311. tensor([-2, -2, 0], dtype=torch.int8)
  7312. >>> torch.bitwise_xor(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7313. tensor([ True, False, False])
  7314. """
  7315. @overload
  7316. def bitwise_xor(self: Number | _complex, other: Tensor) -> Tensor:
  7317. r"""
  7318. bitwise_xor(input, other, *, out=None) -> Tensor
  7319. Computes the bitwise XOR of :attr:`input` and :attr:`other`. The input tensor must be of
  7320. integral or Boolean types. For bool tensors, it computes the logical XOR.
  7321. Args:
  7322. input: the first input tensor
  7323. other: the second input tensor
  7324. Keyword args:
  7325. out (Tensor, optional): the output tensor.
  7326. Example::
  7327. >>> torch.bitwise_xor(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7328. tensor([-2, -2, 0], dtype=torch.int8)
  7329. >>> torch.bitwise_xor(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7330. tensor([ True, False, False])
  7331. """
  7332. @overload
  7333. def bitwise_xor(
  7334. input: Tensor,
  7335. other: Number | _complex,
  7336. *,
  7337. out: Tensor | None = None,
  7338. ) -> Tensor:
  7339. r"""
  7340. bitwise_xor(input, other, *, out=None) -> Tensor
  7341. Computes the bitwise XOR of :attr:`input` and :attr:`other`. The input tensor must be of
  7342. integral or Boolean types. For bool tensors, it computes the logical XOR.
  7343. Args:
  7344. input: the first input tensor
  7345. other: the second input tensor
  7346. Keyword args:
  7347. out (Tensor, optional): the output tensor.
  7348. Example::
  7349. >>> torch.bitwise_xor(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7350. tensor([-2, -2, 0], dtype=torch.int8)
  7351. >>> torch.bitwise_xor(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7352. tensor([ True, False, False])
  7353. """
  7354. @overload
  7355. def blackman_window(
  7356. window_length: _int,
  7357. *,
  7358. dtype: _dtype | None = None,
  7359. layout: _layout | None = None,
  7360. device: DeviceLikeType | None = None,
  7361. pin_memory: _bool | None = False,
  7362. requires_grad: _bool | None = False,
  7363. ) -> Tensor:
  7364. r"""
  7365. blackman_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  7366. Blackman window function.
  7367. .. math::
  7368. 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)
  7369. where :math:`N` is the full window size.
  7370. The input :attr:`window_length` is a positive integer controlling the
  7371. returned window size. :attr:`periodic` flag determines whether the returned
  7372. window trims off the last duplicate value from the symmetric window and is
  7373. ready to be used as a periodic window with functions like
  7374. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  7375. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  7376. ``torch.blackman_window(L, periodic=True)`` equal to
  7377. ``torch.blackman_window(L + 1, periodic=False)[:-1]``.
  7378. .. note::
  7379. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  7380. Arguments:
  7381. window_length (int): the size of returned window
  7382. periodic (bool, optional): If True, returns a window to be used as periodic
  7383. function. If False, return a symmetric window.
  7384. Keyword args:
  7385. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  7386. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  7387. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  7388. ``torch.strided`` (dense layout) is supported.
  7389. device (:class:`torch.device`, optional): the desired device of returned tensor.
  7390. Default: if ``None``, uses the current device for the default tensor type
  7391. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  7392. for CPU tensor types and the current CUDA device for CUDA tensor types.
  7393. requires_grad (bool, optional): If autograd should record operations on the
  7394. returned tensor. Default: ``False``.
  7395. Returns:
  7396. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window
  7397. """
  7398. @overload
  7399. def blackman_window(
  7400. window_length: _int,
  7401. periodic: _bool,
  7402. *,
  7403. dtype: _dtype | None = None,
  7404. layout: _layout | None = None,
  7405. device: DeviceLikeType | None = None,
  7406. pin_memory: _bool | None = False,
  7407. requires_grad: _bool | None = False,
  7408. ) -> Tensor:
  7409. r"""
  7410. blackman_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  7411. Blackman window function.
  7412. .. math::
  7413. 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)
  7414. where :math:`N` is the full window size.
  7415. The input :attr:`window_length` is a positive integer controlling the
  7416. returned window size. :attr:`periodic` flag determines whether the returned
  7417. window trims off the last duplicate value from the symmetric window and is
  7418. ready to be used as a periodic window with functions like
  7419. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  7420. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  7421. ``torch.blackman_window(L, periodic=True)`` equal to
  7422. ``torch.blackman_window(L + 1, periodic=False)[:-1]``.
  7423. .. note::
  7424. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  7425. Arguments:
  7426. window_length (int): the size of returned window
  7427. periodic (bool, optional): If True, returns a window to be used as periodic
  7428. function. If False, return a symmetric window.
  7429. Keyword args:
  7430. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  7431. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  7432. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  7433. ``torch.strided`` (dense layout) is supported.
  7434. device (:class:`torch.device`, optional): the desired device of returned tensor.
  7435. Default: if ``None``, uses the current device for the default tensor type
  7436. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  7437. for CPU tensor types and the current CUDA device for CUDA tensor types.
  7438. requires_grad (bool, optional): If autograd should record operations on the
  7439. returned tensor. Default: ``False``.
  7440. Returns:
  7441. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window
  7442. """
  7443. @overload
  7444. def bmm(
  7445. input: Tensor,
  7446. mat2: Tensor,
  7447. *,
  7448. out: Tensor | None = None,
  7449. ) -> Tensor:
  7450. r"""
  7451. bmm(input, mat2, out_dtype=None, *, out=None) -> Tensor
  7452. Performs a batch matrix-matrix product of matrices stored in :attr:`input`
  7453. and :attr:`mat2`.
  7454. :attr:`input` and :attr:`mat2` must be 3-D tensors each containing
  7455. the same number of matrices.
  7456. If :attr:`input` is a :math:`(b \times n \times m)` tensor, :attr:`mat2` is a
  7457. :math:`(b \times m \times p)` tensor, :attr:`out` will be a
  7458. :math:`(b \times n \times p)` tensor.
  7459. .. math::
  7460. \text{out}_i = \text{input}_i \mathbin{@} \text{mat2}_i
  7461. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  7462. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  7463. .. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
  7464. For broadcasting matrix products, see :func:`torch.matmul`.
  7465. Args:
  7466. input (Tensor): the first batch of matrices to be multiplied
  7467. mat2 (Tensor): the second batch of matrices to be multiplied
  7468. out_dtype (dtype, optional): the dtype of the output tensor,
  7469. Supported only on CUDA and for torch.float32 given
  7470. torch.float16/torch.bfloat16 input dtypes
  7471. Keyword Args:
  7472. out (Tensor, optional): the output tensor.
  7473. Example::
  7474. >>> input = torch.randn(10, 3, 4)
  7475. >>> mat2 = torch.randn(10, 4, 5)
  7476. >>> res = torch.bmm(input, mat2)
  7477. >>> res.size()
  7478. torch.Size([10, 3, 5])
  7479. """
  7480. @overload
  7481. def bmm(
  7482. input: Tensor,
  7483. mat2: Tensor,
  7484. out_dtype: _dtype,
  7485. *,
  7486. out: Tensor | None = None,
  7487. ) -> Tensor:
  7488. r"""
  7489. bmm(input, mat2, out_dtype=None, *, out=None) -> Tensor
  7490. Performs a batch matrix-matrix product of matrices stored in :attr:`input`
  7491. and :attr:`mat2`.
  7492. :attr:`input` and :attr:`mat2` must be 3-D tensors each containing
  7493. the same number of matrices.
  7494. If :attr:`input` is a :math:`(b \times n \times m)` tensor, :attr:`mat2` is a
  7495. :math:`(b \times m \times p)` tensor, :attr:`out` will be a
  7496. :math:`(b \times n \times p)` tensor.
  7497. .. math::
  7498. \text{out}_i = \text{input}_i \mathbin{@} \text{mat2}_i
  7499. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  7500. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  7501. .. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
  7502. For broadcasting matrix products, see :func:`torch.matmul`.
  7503. Args:
  7504. input (Tensor): the first batch of matrices to be multiplied
  7505. mat2 (Tensor): the second batch of matrices to be multiplied
  7506. out_dtype (dtype, optional): the dtype of the output tensor,
  7507. Supported only on CUDA and for torch.float32 given
  7508. torch.float16/torch.bfloat16 input dtypes
  7509. Keyword Args:
  7510. out (Tensor, optional): the output tensor.
  7511. Example::
  7512. >>> input = torch.randn(10, 3, 4)
  7513. >>> mat2 = torch.randn(10, 4, 5)
  7514. >>> res = torch.bmm(input, mat2)
  7515. >>> res.size()
  7516. torch.Size([10, 3, 5])
  7517. """
  7518. def broadcast_to(input: Tensor, size: Sequence[_int | SymInt]) -> Tensor:
  7519. r"""
  7520. broadcast_to(input, shape) -> Tensor
  7521. Broadcasts :attr:`input` to the shape :attr:`\shape`.
  7522. Equivalent to calling ``input.expand(shape)``. See :meth:`~Tensor.expand` for details.
  7523. Args:
  7524. input (Tensor): the input tensor.
  7525. shape (list, tuple, or :class:`torch.Size`): the new shape.
  7526. Example::
  7527. >>> x = torch.tensor([1, 2, 3])
  7528. >>> torch.broadcast_to(x, (3, 3))
  7529. tensor([[1, 2, 3],
  7530. [1, 2, 3],
  7531. [1, 2, 3]])
  7532. """
  7533. @overload
  7534. def bucketize(
  7535. input: Tensor,
  7536. boundaries: Tensor,
  7537. *,
  7538. out_int32: _bool = False,
  7539. right: _bool = False,
  7540. out: Tensor | None = None,
  7541. ) -> Tensor:
  7542. r"""
  7543. bucketize(input, boundaries, *, out_int32=False, right=False, out=None) -> Tensor
  7544. Returns the indices of the buckets to which each value in the :attr:`input` belongs, where the
  7545. boundaries of the buckets are set by :attr:`boundaries`. Return a new tensor with the same size
  7546. as :attr:`input`. If :attr:`right` is False (default), then the left boundary is open. Note that
  7547. this behavior is opposite the behavior of
  7548. `numpy.digitize <https://numpy.org/doc/stable/reference/generated/numpy.digitize.html>`_.
  7549. More formally, the returned index satisfies the following rules:
  7550. .. list-table::
  7551. :widths: 15 85
  7552. :header-rows: 1
  7553. * - :attr:`right`
  7554. - *returned index satisfies*
  7555. * - False
  7556. - ``boundaries[i-1] < input[m][n]...[l][x] <= boundaries[i]``
  7557. * - True
  7558. - ``boundaries[i-1] <= input[m][n]...[l][x] < boundaries[i]``
  7559. Args:
  7560. input (Tensor or Scalar): N-D tensor or a Scalar containing the search value(s).
  7561. boundaries (Tensor): 1-D tensor, must contain a strictly increasing sequence, or the return value is undefined.
  7562. Keyword args:
  7563. out_int32 (bool, optional): indicate the output data type. torch.int32 if True, torch.int64 otherwise.
  7564. Default value is False, i.e. default output data type is torch.int64.
  7565. right (bool, optional): determines the behavior for values in :attr:`boundaries`. See the table above.
  7566. out (Tensor, optional): the output tensor, must be the same size as :attr:`input` if provided.
  7567. Example::
  7568. >>> boundaries = torch.tensor([1, 3, 5, 7, 9])
  7569. >>> boundaries
  7570. tensor([1, 3, 5, 7, 9])
  7571. >>> v = torch.tensor([[3, 6, 9], [3, 6, 9]])
  7572. >>> v
  7573. tensor([[3, 6, 9],
  7574. [3, 6, 9]])
  7575. >>> torch.bucketize(v, boundaries)
  7576. tensor([[1, 3, 4],
  7577. [1, 3, 4]])
  7578. >>> torch.bucketize(v, boundaries, right=True)
  7579. tensor([[2, 3, 5],
  7580. [2, 3, 5]])
  7581. """
  7582. @overload
  7583. def bucketize(
  7584. self: Number | _complex,
  7585. boundaries: Tensor,
  7586. *,
  7587. out_int32: _bool = False,
  7588. right: _bool = False,
  7589. ) -> Tensor:
  7590. r"""
  7591. bucketize(input, boundaries, *, out_int32=False, right=False, out=None) -> Tensor
  7592. Returns the indices of the buckets to which each value in the :attr:`input` belongs, where the
  7593. boundaries of the buckets are set by :attr:`boundaries`. Return a new tensor with the same size
  7594. as :attr:`input`. If :attr:`right` is False (default), then the left boundary is open. Note that
  7595. this behavior is opposite the behavior of
  7596. `numpy.digitize <https://numpy.org/doc/stable/reference/generated/numpy.digitize.html>`_.
  7597. More formally, the returned index satisfies the following rules:
  7598. .. list-table::
  7599. :widths: 15 85
  7600. :header-rows: 1
  7601. * - :attr:`right`
  7602. - *returned index satisfies*
  7603. * - False
  7604. - ``boundaries[i-1] < input[m][n]...[l][x] <= boundaries[i]``
  7605. * - True
  7606. - ``boundaries[i-1] <= input[m][n]...[l][x] < boundaries[i]``
  7607. Args:
  7608. input (Tensor or Scalar): N-D tensor or a Scalar containing the search value(s).
  7609. boundaries (Tensor): 1-D tensor, must contain a strictly increasing sequence, or the return value is undefined.
  7610. Keyword args:
  7611. out_int32 (bool, optional): indicate the output data type. torch.int32 if True, torch.int64 otherwise.
  7612. Default value is False, i.e. default output data type is torch.int64.
  7613. right (bool, optional): determines the behavior for values in :attr:`boundaries`. See the table above.
  7614. out (Tensor, optional): the output tensor, must be the same size as :attr:`input` if provided.
  7615. Example::
  7616. >>> boundaries = torch.tensor([1, 3, 5, 7, 9])
  7617. >>> boundaries
  7618. tensor([1, 3, 5, 7, 9])
  7619. >>> v = torch.tensor([[3, 6, 9], [3, 6, 9]])
  7620. >>> v
  7621. tensor([[3, 6, 9],
  7622. [3, 6, 9]])
  7623. >>> torch.bucketize(v, boundaries)
  7624. tensor([[1, 3, 4],
  7625. [1, 3, 4]])
  7626. >>> torch.bucketize(v, boundaries, right=True)
  7627. tensor([[2, 3, 5],
  7628. [2, 3, 5]])
  7629. """
  7630. def can_cast(from_: _dtype, to: _dtype) -> _bool:
  7631. r"""
  7632. can_cast(from_, to) -> bool
  7633. Determines if a type conversion is allowed under PyTorch casting rules
  7634. described in the type promotion :ref:`documentation <type-promotion-doc>`.
  7635. Args:
  7636. from\_ (dtype): The original :class:`torch.dtype`.
  7637. to (dtype): The target :class:`torch.dtype`.
  7638. Example::
  7639. >>> torch.can_cast(torch.double, torch.float)
  7640. True
  7641. >>> torch.can_cast(torch.float, torch.int)
  7642. False
  7643. """
  7644. @overload
  7645. def cat(
  7646. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  7647. dim: _int = 0,
  7648. *,
  7649. out: Tensor | None = None,
  7650. ) -> Tensor:
  7651. r"""
  7652. cat(tensors, dim=0, *, out=None) -> Tensor
  7653. Concatenates the given sequence of tensors in :attr:`tensors` in the given dimension.
  7654. All tensors must either have the same shape (except in the concatenating
  7655. dimension) or be a 1-D empty tensor with size ``(0,)``.
  7656. :func:`torch.cat` can be seen as an inverse operation for :func:`torch.split`
  7657. and :func:`torch.chunk`.
  7658. :func:`torch.cat` can be best understood via examples.
  7659. .. seealso::
  7660. :func:`torch.stack` concatenates the given sequence along a new dimension.
  7661. Args:
  7662. tensors (sequence of Tensors): Non-empty tensors provided must have the same shape,
  7663. except in the cat dimension.
  7664. dim (int, optional): the dimension over which the tensors are concatenated
  7665. Keyword args:
  7666. out (Tensor, optional): the output tensor.
  7667. Example::
  7668. >>> x = torch.randn(2, 3)
  7669. >>> x
  7670. tensor([[ 0.6580, -1.0969, -0.4614],
  7671. [-0.1034, -0.5790, 0.1497]])
  7672. >>> torch.cat((x, x, x), 0)
  7673. tensor([[ 0.6580, -1.0969, -0.4614],
  7674. [-0.1034, -0.5790, 0.1497],
  7675. [ 0.6580, -1.0969, -0.4614],
  7676. [-0.1034, -0.5790, 0.1497],
  7677. [ 0.6580, -1.0969, -0.4614],
  7678. [-0.1034, -0.5790, 0.1497]])
  7679. >>> torch.cat((x, x, x), 1)
  7680. tensor([[ 0.6580, -1.0969, -0.4614, 0.6580, -1.0969, -0.4614, 0.6580,
  7681. -1.0969, -0.4614],
  7682. [-0.1034, -0.5790, 0.1497, -0.1034, -0.5790, 0.1497, -0.1034,
  7683. -0.5790, 0.1497]])
  7684. """
  7685. @overload
  7686. def cat(
  7687. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  7688. dim: str | EllipsisType | None,
  7689. *,
  7690. out: Tensor | None = None,
  7691. ) -> Tensor:
  7692. r"""
  7693. cat(tensors, dim=0, *, out=None) -> Tensor
  7694. Concatenates the given sequence of tensors in :attr:`tensors` in the given dimension.
  7695. All tensors must either have the same shape (except in the concatenating
  7696. dimension) or be a 1-D empty tensor with size ``(0,)``.
  7697. :func:`torch.cat` can be seen as an inverse operation for :func:`torch.split`
  7698. and :func:`torch.chunk`.
  7699. :func:`torch.cat` can be best understood via examples.
  7700. .. seealso::
  7701. :func:`torch.stack` concatenates the given sequence along a new dimension.
  7702. Args:
  7703. tensors (sequence of Tensors): Non-empty tensors provided must have the same shape,
  7704. except in the cat dimension.
  7705. dim (int, optional): the dimension over which the tensors are concatenated
  7706. Keyword args:
  7707. out (Tensor, optional): the output tensor.
  7708. Example::
  7709. >>> x = torch.randn(2, 3)
  7710. >>> x
  7711. tensor([[ 0.6580, -1.0969, -0.4614],
  7712. [-0.1034, -0.5790, 0.1497]])
  7713. >>> torch.cat((x, x, x), 0)
  7714. tensor([[ 0.6580, -1.0969, -0.4614],
  7715. [-0.1034, -0.5790, 0.1497],
  7716. [ 0.6580, -1.0969, -0.4614],
  7717. [-0.1034, -0.5790, 0.1497],
  7718. [ 0.6580, -1.0969, -0.4614],
  7719. [-0.1034, -0.5790, 0.1497]])
  7720. >>> torch.cat((x, x, x), 1)
  7721. tensor([[ 0.6580, -1.0969, -0.4614, 0.6580, -1.0969, -0.4614, 0.6580,
  7722. -1.0969, -0.4614],
  7723. [-0.1034, -0.5790, 0.1497, -0.1034, -0.5790, 0.1497, -0.1034,
  7724. -0.5790, 0.1497]])
  7725. """
  7726. def ccol_indices_copy(
  7727. input: Tensor,
  7728. *,
  7729. out: Tensor | None = None,
  7730. ) -> Tensor: ...
  7731. def ceil(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  7732. r"""
  7733. ceil(input, *, out=None) -> Tensor
  7734. Returns a new tensor with the ceil of the elements of :attr:`input`,
  7735. the smallest integer greater than or equal to each element.
  7736. For integer inputs, follows the array-api convention of returning a
  7737. copy of the input tensor.
  7738. .. math::
  7739. \text{out}_{i} = \left\lceil \text{input}_{i} \right\rceil
  7740. Args:
  7741. input (Tensor): the input tensor.
  7742. Keyword args:
  7743. out (Tensor, optional): the output tensor.
  7744. Example::
  7745. >>> a = torch.randn(4)
  7746. >>> a
  7747. tensor([-0.6341, -1.4208, -1.0900, 0.5826])
  7748. >>> torch.ceil(a)
  7749. tensor([-0., -1., -1., 1.])
  7750. """
  7751. def ceil_(input: Tensor) -> Tensor: ...
  7752. def celu(input: Tensor, alpha: Number | _complex = 1.0) -> Tensor: ...
  7753. def celu_(input: Tensor, alpha: Number | _complex = 1.0) -> Tensor: ...
  7754. def channel_shuffle(input: Tensor, groups: _int | SymInt) -> Tensor: ...
  7755. def cholesky(
  7756. input: Tensor,
  7757. upper: _bool = False,
  7758. *,
  7759. out: Tensor | None = None,
  7760. ) -> Tensor:
  7761. r"""
  7762. cholesky(input, upper=False, *, out=None) -> Tensor
  7763. Computes the Cholesky decomposition of a symmetric positive-definite
  7764. matrix :math:`A` or for batches of symmetric positive-definite matrices.
  7765. If :attr:`upper` is ``True``, the returned matrix ``U`` is upper-triangular, and
  7766. the decomposition has the form:
  7767. .. math::
  7768. A = U^TU
  7769. If :attr:`upper` is ``False``, the returned matrix ``L`` is lower-triangular, and
  7770. the decomposition has the form:
  7771. .. math::
  7772. A = LL^T
  7773. If :attr:`upper` is ``True``, and :math:`A` is a batch of symmetric positive-definite
  7774. matrices, then the returned tensor will be composed of upper-triangular Cholesky factors
  7775. of each of the individual matrices. Similarly, when :attr:`upper` is ``False``, the returned
  7776. tensor will be composed of lower-triangular Cholesky factors of each of the individual
  7777. matrices.
  7778. .. warning::
  7779. :func:`torch.cholesky` is deprecated in favor of :func:`torch.linalg.cholesky`
  7780. and will be removed in a future PyTorch release.
  7781. ``L = torch.cholesky(A)`` should be replaced with
  7782. .. code:: python
  7783. L = torch.linalg.cholesky(A)
  7784. ``U = torch.cholesky(A, upper=True)`` should be replaced with
  7785. .. code:: python
  7786. U = torch.linalg.cholesky(A).mH
  7787. This transform will produce equivalent results for all valid (symmetric positive definite) inputs.
  7788. Args:
  7789. input (Tensor): the input tensor :math:`A` of size :math:`(*, n, n)` where `*` is zero or more
  7790. batch dimensions consisting of symmetric positive-definite matrices.
  7791. upper (bool, optional): flag that indicates whether to return a
  7792. upper or lower triangular matrix. Default: ``False``
  7793. Keyword args:
  7794. out (Tensor, optional): the output matrix
  7795. Example::
  7796. >>> a = torch.randn(3, 3)
  7797. >>> a = a @ a.mT + 1e-3 # make symmetric positive-definite
  7798. >>> l = torch.cholesky(a)
  7799. >>> a
  7800. tensor([[ 2.4112, -0.7486, 1.4551],
  7801. [-0.7486, 1.3544, 0.1294],
  7802. [ 1.4551, 0.1294, 1.6724]])
  7803. >>> l
  7804. tensor([[ 1.5528, 0.0000, 0.0000],
  7805. [-0.4821, 1.0592, 0.0000],
  7806. [ 0.9371, 0.5487, 0.7023]])
  7807. >>> l @ l.mT
  7808. tensor([[ 2.4112, -0.7486, 1.4551],
  7809. [-0.7486, 1.3544, 0.1294],
  7810. [ 1.4551, 0.1294, 1.6724]])
  7811. >>> a = torch.randn(3, 2, 2) # Example for batched input
  7812. >>> a = a @ a.mT + 1e-03 # make symmetric positive-definite
  7813. >>> l = torch.cholesky(a)
  7814. >>> z = l @ l.mT
  7815. >>> torch.dist(z, a)
  7816. tensor(2.3842e-07)
  7817. """
  7818. def cholesky_inverse(
  7819. input: Tensor,
  7820. upper: _bool = False,
  7821. *,
  7822. out: Tensor | None = None,
  7823. ) -> Tensor:
  7824. r"""
  7825. cholesky_inverse(L, upper=False, *, out=None) -> Tensor
  7826. Computes the inverse of a complex Hermitian or real symmetric
  7827. positive-definite matrix given its Cholesky decomposition.
  7828. Let :math:`A` be a complex Hermitian or real symmetric positive-definite matrix,
  7829. and :math:`L` its Cholesky decomposition such that:
  7830. .. math::
  7831. A = LL^{\text{H}}
  7832. where :math:`L^{\text{H}}` is the conjugate transpose when :math:`L` is complex,
  7833. and the transpose when :math:`L` is real-valued.
  7834. Computes the inverse matrix :math:`A^{-1}`.
  7835. Supports input of float, double, cfloat and cdouble dtypes.
  7836. Also supports batches of matrices, and if :math:`A` is a batch of matrices
  7837. then the output has the same batch dimensions.
  7838. Args:
  7839. L (Tensor): tensor of shape `(*, n, n)` where `*` is zero or more batch dimensions
  7840. consisting of lower or upper triangular Cholesky decompositions of
  7841. symmetric or Hermitian positive-definite matrices.
  7842. upper (bool, optional): flag that indicates whether :math:`L` is lower triangular
  7843. or upper triangular. Default: ``False``
  7844. Keyword args:
  7845. out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
  7846. Example::
  7847. >>> A = torch.randn(3, 3)
  7848. >>> A = A @ A.T + torch.eye(3) * 1e-3 # Creates a symmetric positive-definite matrix
  7849. >>> L = torch.linalg.cholesky(A) # Extract Cholesky decomposition
  7850. >>> torch.cholesky_inverse(L)
  7851. tensor([[ 1.9314, 1.2251, -0.0889],
  7852. [ 1.2251, 2.4439, 0.2122],
  7853. [-0.0889, 0.2122, 0.1412]])
  7854. >>> A.inverse()
  7855. tensor([[ 1.9314, 1.2251, -0.0889],
  7856. [ 1.2251, 2.4439, 0.2122],
  7857. [-0.0889, 0.2122, 0.1412]])
  7858. >>> A = torch.randn(3, 2, 2, dtype=torch.complex64)
  7859. >>> A = A @ A.mH + torch.eye(2) * 1e-3 # Batch of Hermitian positive-definite matrices
  7860. >>> L = torch.linalg.cholesky(A)
  7861. >>> torch.dist(torch.inverse(A), torch.cholesky_inverse(L))
  7862. tensor(5.6358e-7)
  7863. """
  7864. def cholesky_solve(
  7865. input: Tensor,
  7866. input2: Tensor,
  7867. upper: _bool = False,
  7868. *,
  7869. out: Tensor | None = None,
  7870. ) -> Tensor:
  7871. r"""
  7872. cholesky_solve(B, L, upper=False, *, out=None) -> Tensor
  7873. Computes the solution of a system of linear equations with complex Hermitian
  7874. or real symmetric positive-definite lhs given its Cholesky decomposition.
  7875. Let :math:`A` be a complex Hermitian or real symmetric positive-definite matrix,
  7876. and :math:`L` its Cholesky decomposition such that:
  7877. .. math::
  7878. A = LL^{\text{H}}
  7879. where :math:`L^{\text{H}}` is the conjugate transpose when :math:`L` is complex,
  7880. and the transpose when :math:`L` is real-valued.
  7881. Returns the solution :math:`X` of the following linear system:
  7882. .. math::
  7883. AX = B
  7884. Supports inputs of float, double, cfloat and cdouble dtypes.
  7885. Also supports batches of matrices, and if :math:`A` or :math:`B` is a batch of matrices
  7886. then the output has the same batch dimensions.
  7887. Args:
  7888. B (Tensor): right-hand side tensor of shape `(*, n, k)`
  7889. where :math:`*` is zero or more batch dimensions
  7890. L (Tensor): tensor of shape `(*, n, n)` where `*` is zero or more batch dimensions
  7891. consisting of lower or upper triangular Cholesky decompositions of
  7892. symmetric or Hermitian positive-definite matrices.
  7893. upper (bool, optional): flag that indicates whether :math:`L` is lower triangular
  7894. or upper triangular. Default: ``False``.
  7895. Keyword args:
  7896. out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
  7897. Example::
  7898. >>> A = torch.randn(3, 3)
  7899. >>> A = A @ A.T + torch.eye(3) * 1e-3 # Creates a symmetric positive-definite matrix
  7900. >>> L = torch.linalg.cholesky(A) # Extract Cholesky decomposition
  7901. >>> B = torch.randn(3, 2)
  7902. >>> torch.cholesky_solve(B, L)
  7903. tensor([[ -8.1625, 19.6097],
  7904. [ -5.8398, 14.2387],
  7905. [ -4.3771, 10.4173]])
  7906. >>> A.inverse() @ B
  7907. tensor([[ -8.1626, 19.6097],
  7908. [ -5.8398, 14.2387],
  7909. [ -4.3771, 10.4173]])
  7910. >>> A = torch.randn(3, 2, 2, dtype=torch.complex64)
  7911. >>> A = A @ A.mH + torch.eye(2) * 1e-3 # Batch of Hermitian positive-definite matrices
  7912. >>> L = torch.linalg.cholesky(A)
  7913. >>> B = torch.randn(2, 1, dtype=torch.complex64)
  7914. >>> X = torch.cholesky_solve(B, L)
  7915. >>> torch.dist(X, A.inverse() @ B)
  7916. tensor(1.6881e-5)
  7917. """
  7918. def choose_qparams_optimized(
  7919. input: Tensor,
  7920. numel: _int,
  7921. n_bins: _int,
  7922. ratio: _float,
  7923. bit_width: _int,
  7924. ) -> tuple[Tensor, Tensor]: ...
  7925. def chunk(input: Tensor, chunks: _int, dim: _int = 0) -> tuple[Tensor, ...]:
  7926. r"""
  7927. chunk(input: Tensor, chunks: int, dim: int = 0) -> Tuple[Tensor, ...]
  7928. Attempts to split a tensor into the specified number of chunks. Each chunk is a view of
  7929. the input tensor.
  7930. .. note::
  7931. This function may return fewer than the specified number of chunks!
  7932. .. seealso::
  7933. :func:`torch.tensor_split` a function that always returns exactly the specified number of chunks
  7934. If the tensor size along the given dimension :attr:`dim` is divisible by :attr:`chunks`,
  7935. all returned chunks will be the same size.
  7936. If the tensor size along the given dimension :attr:`dim` is not divisible by :attr:`chunks`,
  7937. all returned chunks will be the same size, except the last one.
  7938. If such division is not possible, this function may return fewer
  7939. than the specified number of chunks.
  7940. Arguments:
  7941. input (Tensor): the tensor to split
  7942. chunks (int): number of chunks to return
  7943. dim (int): dimension along which to split the tensor
  7944. Example:
  7945. >>> torch.arange(11).chunk(6)
  7946. (tensor([0, 1]),
  7947. tensor([2, 3]),
  7948. tensor([4, 5]),
  7949. tensor([6, 7]),
  7950. tensor([8, 9]),
  7951. tensor([10]))
  7952. >>> torch.arange(12).chunk(6)
  7953. (tensor([0, 1]),
  7954. tensor([2, 3]),
  7955. tensor([4, 5]),
  7956. tensor([6, 7]),
  7957. tensor([8, 9]),
  7958. tensor([10, 11]))
  7959. >>> torch.arange(13).chunk(6)
  7960. (tensor([0, 1, 2]),
  7961. tensor([3, 4, 5]),
  7962. tensor([6, 7, 8]),
  7963. tensor([ 9, 10, 11]),
  7964. tensor([12]))
  7965. """
  7966. @overload
  7967. def clamp(
  7968. input: Tensor,
  7969. min: Tensor | None = None,
  7970. max: Tensor | None = None,
  7971. *,
  7972. out: Tensor | None = None,
  7973. ) -> Tensor:
  7974. r"""
  7975. clamp(input, min=None, max=None, *, out=None) -> Tensor
  7976. Clamps all elements in :attr:`input` into the range `[` :attr:`min`, :attr:`max` `]`.
  7977. Letting min_value and max_value be :attr:`min` and :attr:`max`, respectively, this returns:
  7978. .. math::
  7979. y_i = \min(\max(x_i, \text{min\_value}_i), \text{max\_value}_i)
  7980. If :attr:`min` is ``None``, there is no lower bound.
  7981. Or, if :attr:`max` is ``None`` there is no upper bound.
  7982. .. note::
  7983. If :attr:`min` is greater than :attr:`max` :func:`torch.clamp(..., min, max) <torch.clamp>`
  7984. sets all elements in :attr:`input` to the value of :attr:`max`.
  7985. Args:
  7986. input (Tensor): the input tensor.
  7987. min (Number or Tensor, optional): lower-bound of the range to be clamped to
  7988. max (Number or Tensor, optional): upper-bound of the range to be clamped to
  7989. Keyword args:
  7990. out (Tensor, optional): the output tensor.
  7991. Example::
  7992. >>> a = torch.randn(4)
  7993. >>> a
  7994. tensor([-1.7120, 0.1734, -0.0478, -0.0922])
  7995. >>> torch.clamp(a, min=-0.5, max=0.5)
  7996. tensor([-0.5000, 0.1734, -0.0478, -0.0922])
  7997. >>> min = torch.linspace(-1, 1, steps=4)
  7998. >>> torch.clamp(a, min=min)
  7999. tensor([-1.0000, 0.1734, 0.3333, 1.0000])
  8000. """
  8001. @overload
  8002. def clamp(
  8003. input: Tensor,
  8004. min: Number | _complex | None = None,
  8005. max: Number | _complex | None = None,
  8006. *,
  8007. out: Tensor | None = None,
  8008. ) -> Tensor:
  8009. r"""
  8010. clamp(input, min=None, max=None, *, out=None) -> Tensor
  8011. Clamps all elements in :attr:`input` into the range `[` :attr:`min`, :attr:`max` `]`.
  8012. Letting min_value and max_value be :attr:`min` and :attr:`max`, respectively, this returns:
  8013. .. math::
  8014. y_i = \min(\max(x_i, \text{min\_value}_i), \text{max\_value}_i)
  8015. If :attr:`min` is ``None``, there is no lower bound.
  8016. Or, if :attr:`max` is ``None`` there is no upper bound.
  8017. .. note::
  8018. If :attr:`min` is greater than :attr:`max` :func:`torch.clamp(..., min, max) <torch.clamp>`
  8019. sets all elements in :attr:`input` to the value of :attr:`max`.
  8020. Args:
  8021. input (Tensor): the input tensor.
  8022. min (Number or Tensor, optional): lower-bound of the range to be clamped to
  8023. max (Number or Tensor, optional): upper-bound of the range to be clamped to
  8024. Keyword args:
  8025. out (Tensor, optional): the output tensor.
  8026. Example::
  8027. >>> a = torch.randn(4)
  8028. >>> a
  8029. tensor([-1.7120, 0.1734, -0.0478, -0.0922])
  8030. >>> torch.clamp(a, min=-0.5, max=0.5)
  8031. tensor([-0.5000, 0.1734, -0.0478, -0.0922])
  8032. >>> min = torch.linspace(-1, 1, steps=4)
  8033. >>> torch.clamp(a, min=min)
  8034. tensor([-1.0000, 0.1734, 0.3333, 1.0000])
  8035. """
  8036. @overload
  8037. def clamp_(
  8038. input: Tensor,
  8039. min: Tensor | None = None,
  8040. max: Tensor | None = None,
  8041. ) -> Tensor: ...
  8042. @overload
  8043. def clamp_(
  8044. input: Tensor,
  8045. min: Number | _complex | None = None,
  8046. max: Number | _complex | None = None,
  8047. ) -> Tensor: ...
  8048. @overload
  8049. def clamp_max(
  8050. input: Tensor,
  8051. max: Tensor,
  8052. *,
  8053. out: Tensor | None = None,
  8054. ) -> Tensor: ...
  8055. @overload
  8056. def clamp_max(
  8057. input: Tensor,
  8058. max: Number | _complex,
  8059. *,
  8060. out: Tensor | None = None,
  8061. ) -> Tensor: ...
  8062. @overload
  8063. def clamp_max_(input: Tensor, max: Tensor) -> Tensor: ...
  8064. @overload
  8065. def clamp_max_(input: Tensor, max: Number | _complex) -> Tensor: ...
  8066. @overload
  8067. def clamp_min(
  8068. input: Tensor,
  8069. min: Tensor,
  8070. *,
  8071. out: Tensor | None = None,
  8072. ) -> Tensor: ...
  8073. @overload
  8074. def clamp_min(
  8075. input: Tensor,
  8076. min: Number | _complex,
  8077. *,
  8078. out: Tensor | None = None,
  8079. ) -> Tensor: ...
  8080. @overload
  8081. def clamp_min_(input: Tensor, min: Tensor) -> Tensor: ...
  8082. @overload
  8083. def clamp_min_(input: Tensor, min: Number | _complex) -> Tensor: ...
  8084. @overload
  8085. def clip(
  8086. input: Tensor,
  8087. min: Tensor | None = None,
  8088. max: Tensor | None = None,
  8089. *,
  8090. out: Tensor | None = None,
  8091. ) -> Tensor:
  8092. r"""
  8093. clip(input, min=None, max=None, *, out=None) -> Tensor
  8094. Alias for :func:`torch.clamp`.
  8095. """
  8096. @overload
  8097. def clip(
  8098. input: Tensor,
  8099. min: Number | _complex | None = None,
  8100. max: Number | _complex | None = None,
  8101. *,
  8102. out: Tensor | None = None,
  8103. ) -> Tensor:
  8104. r"""
  8105. clip(input, min=None, max=None, *, out=None) -> Tensor
  8106. Alias for :func:`torch.clamp`.
  8107. """
  8108. @overload
  8109. def clip_(
  8110. input: Tensor,
  8111. min: Tensor | None = None,
  8112. max: Tensor | None = None,
  8113. ) -> Tensor: ...
  8114. @overload
  8115. def clip_(
  8116. input: Tensor,
  8117. min: Number | _complex | None = None,
  8118. max: Number | _complex | None = None,
  8119. ) -> Tensor: ...
  8120. def clone(
  8121. input: Tensor,
  8122. *,
  8123. memory_format: memory_format | None = None,
  8124. ) -> Tensor:
  8125. r"""
  8126. clone(input, *, memory_format=torch.preserve_format) -> Tensor
  8127. Returns a copy of :attr:`input`.
  8128. .. note::
  8129. This function is differentiable, so gradients will flow back from the
  8130. result of this operation to :attr:`input`. To create a tensor without an
  8131. autograd relationship to :attr:`input` see :meth:`~Tensor.detach`.
  8132. In addition, when ``torch.preserve_format`` is used:
  8133. If the input tensor is dense (i.e., non-overlapping strided),
  8134. its memory format (including strides) is retained.
  8135. Otherwise (e.g., a non-dense view like a stepped slice),
  8136. the output is converted to the dense (contiguous) format.
  8137. Args:
  8138. input (Tensor): the input tensor.
  8139. Keyword args:
  8140. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  8141. returned tensor. Default: ``torch.preserve_format``.
  8142. """
  8143. def col_indices_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  8144. r"""
  8145. Performs the same operation as :func:`torch.col_indices`, but all output tensors
  8146. are freshly created instead of aliasing the input.
  8147. """
  8148. def column_stack(
  8149. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  8150. *,
  8151. out: Tensor | None = None,
  8152. ) -> Tensor:
  8153. r"""
  8154. column_stack(tensors, *, out=None) -> Tensor
  8155. Creates a new tensor by horizontally stacking the tensors in :attr:`tensors`.
  8156. Equivalent to ``torch.hstack(tensors)``, except each zero or one dimensional tensor ``t``
  8157. in :attr:`tensors` is first reshaped into a ``(t.numel(), 1)`` column before being stacked horizontally.
  8158. Args:
  8159. tensors (sequence of Tensors): sequence of tensors to concatenate
  8160. Keyword args:
  8161. out (Tensor, optional): the output tensor.
  8162. Example::
  8163. >>> a = torch.tensor([1, 2, 3])
  8164. >>> b = torch.tensor([4, 5, 6])
  8165. >>> torch.column_stack((a, b))
  8166. tensor([[1, 4],
  8167. [2, 5],
  8168. [3, 6]])
  8169. >>> a = torch.arange(5)
  8170. >>> b = torch.arange(10).reshape(5, 2)
  8171. >>> torch.column_stack((a, b, b))
  8172. tensor([[0, 0, 1, 0, 1],
  8173. [1, 2, 3, 2, 3],
  8174. [2, 4, 5, 4, 5],
  8175. [3, 6, 7, 6, 7],
  8176. [4, 8, 9, 8, 9]])
  8177. """
  8178. def combinations(
  8179. input: Tensor,
  8180. r: _int = 2,
  8181. with_replacement: _bool = False,
  8182. ) -> Tensor:
  8183. r"""
  8184. combinations(input: Tensor, r: int = 2, with_replacement: bool = False) -> seq
  8185. Compute combinations of length :math:`r` of the given tensor. The behavior is similar to
  8186. python's `itertools.combinations` when `with_replacement` is set to `False`, and
  8187. `itertools.combinations_with_replacement` when `with_replacement` is set to `True`.
  8188. Arguments:
  8189. input (Tensor): 1D vector.
  8190. r (int, optional): number of elements to combine
  8191. with_replacement (bool, optional): whether to allow duplication in combination
  8192. Returns:
  8193. Tensor: A tensor equivalent to converting all the input tensors into lists, do
  8194. `itertools.combinations` or `itertools.combinations_with_replacement` on these
  8195. lists, and finally convert the resulting list into tensor.
  8196. Example::
  8197. >>> a = [1, 2, 3]
  8198. >>> list(itertools.combinations(a, r=2))
  8199. [(1, 2), (1, 3), (2, 3)]
  8200. >>> list(itertools.combinations(a, r=3))
  8201. [(1, 2, 3)]
  8202. >>> list(itertools.combinations_with_replacement(a, r=2))
  8203. [(1, 1), (1, 2), (1, 3), (2, 2), (2, 3), (3, 3)]
  8204. >>> tensor_a = torch.tensor(a)
  8205. >>> torch.combinations(tensor_a)
  8206. tensor([[1, 2],
  8207. [1, 3],
  8208. [2, 3]])
  8209. >>> torch.combinations(tensor_a, r=3)
  8210. tensor([[1, 2, 3]])
  8211. >>> torch.combinations(tensor_a, with_replacement=True)
  8212. tensor([[1, 1],
  8213. [1, 2],
  8214. [1, 3],
  8215. [2, 2],
  8216. [2, 3],
  8217. [3, 3]])
  8218. """
  8219. def complex(
  8220. real: Tensor,
  8221. imag: Tensor,
  8222. *,
  8223. out: Tensor | None = None,
  8224. ) -> Tensor:
  8225. r"""
  8226. complex(real, imag, *, out=None) -> Tensor
  8227. Constructs a complex tensor with its real part equal to :attr:`real` and its
  8228. imaginary part equal to :attr:`imag`.
  8229. Args:
  8230. real (Tensor): The real part of the complex tensor. Must be half, float or double.
  8231. imag (Tensor): The imaginary part of the complex tensor. Must be same dtype
  8232. as :attr:`real`.
  8233. Keyword args:
  8234. out (Tensor): If the inputs are ``torch.float32``, must be
  8235. ``torch.complex64``. If the inputs are ``torch.float64``, must be
  8236. ``torch.complex128``.
  8237. Example::
  8238. >>> real = torch.tensor([1, 2], dtype=torch.float32)
  8239. >>> imag = torch.tensor([3, 4], dtype=torch.float32)
  8240. >>> z = torch.complex(real, imag)
  8241. >>> z
  8242. tensor([(1.+3.j), (2.+4.j)])
  8243. >>> z.dtype
  8244. torch.complex64
  8245. """
  8246. @overload
  8247. def concat(
  8248. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  8249. dim: _int = 0,
  8250. *,
  8251. out: Tensor | None = None,
  8252. ) -> Tensor:
  8253. r"""
  8254. concat(tensors, dim=0, *, out=None) -> Tensor
  8255. Alias of :func:`torch.cat`.
  8256. """
  8257. @overload
  8258. def concat(
  8259. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  8260. dim: str | EllipsisType | None,
  8261. *,
  8262. out: Tensor | None = None,
  8263. ) -> Tensor:
  8264. r"""
  8265. concat(tensors, dim=0, *, out=None) -> Tensor
  8266. Alias of :func:`torch.cat`.
  8267. """
  8268. @overload
  8269. def concatenate(
  8270. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  8271. dim: _int = 0,
  8272. *,
  8273. out: Tensor | None = None,
  8274. ) -> Tensor:
  8275. r"""
  8276. concatenate(tensors, axis=0, out=None) -> Tensor
  8277. Alias of :func:`torch.cat`.
  8278. """
  8279. @overload
  8280. def concatenate(
  8281. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  8282. dim: str | EllipsisType | None,
  8283. *,
  8284. out: Tensor | None = None,
  8285. ) -> Tensor:
  8286. r"""
  8287. concatenate(tensors, axis=0, out=None) -> Tensor
  8288. Alias of :func:`torch.cat`.
  8289. """
  8290. def conj(input: Tensor) -> Tensor:
  8291. r"""
  8292. conj(input) -> Tensor
  8293. Returns a view of :attr:`input` with a flipped conjugate bit. If :attr:`input` has a non-complex dtype,
  8294. this function just returns :attr:`input`.
  8295. .. note::
  8296. :func:`torch.conj` performs a lazy conjugation, but the actual conjugated tensor can be materialized
  8297. at any time using :func:`torch.resolve_conj`.
  8298. .. warning:: In the future, :func:`torch.conj` may return a non-writeable view for an :attr:`input` of
  8299. non-complex dtype. It's recommended that programs not modify the tensor returned by :func:`torch.conj_physical`
  8300. when :attr:`input` is of non-complex dtype to be compatible with this change.
  8301. Args:
  8302. input (Tensor): the input tensor.
  8303. Example::
  8304. >>> x = torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j])
  8305. >>> x.is_conj()
  8306. False
  8307. >>> y = torch.conj(x)
  8308. >>> y.is_conj()
  8309. True
  8310. """
  8311. def conj_physical(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  8312. r"""
  8313. conj_physical(input, *, out=None) -> Tensor
  8314. Computes the element-wise conjugate of the given :attr:`input` tensor.
  8315. If :attr:`input` has a non-complex dtype, this function just returns :attr:`input`.
  8316. .. note::
  8317. This performs the conjugate operation regardless of the fact conjugate bit is set or not.
  8318. .. warning:: In the future, :func:`torch.conj_physical` may return a non-writeable view for an :attr:`input` of
  8319. non-complex dtype. It's recommended that programs not modify the tensor returned by :func:`torch.conj_physical`
  8320. when :attr:`input` is of non-complex dtype to be compatible with this change.
  8321. .. math::
  8322. \text{out}_{i} = conj(\text{input}_{i})
  8323. Args:
  8324. input (Tensor): the input tensor.
  8325. Keyword args:
  8326. out (Tensor, optional): the output tensor.
  8327. Example::
  8328. >>> torch.conj_physical(torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j]))
  8329. tensor([-1 - 1j, -2 - 2j, 3 + 3j])
  8330. """
  8331. def conj_physical_(input: Tensor) -> Tensor: ...
  8332. def constant_pad_nd(
  8333. input: Tensor,
  8334. pad: Sequence[_int | SymInt],
  8335. value: Number | _complex = 0,
  8336. ) -> Tensor: ...
  8337. @overload
  8338. def conv1d(
  8339. input: Tensor,
  8340. weight: Tensor,
  8341. bias: Tensor | None = None,
  8342. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8343. padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8344. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8345. groups: _int | SymInt = 1,
  8346. ) -> Tensor: ...
  8347. @overload
  8348. def conv1d(
  8349. input: Tensor,
  8350. weight: Tensor,
  8351. bias: Tensor | None = None,
  8352. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8353. padding: str = "valid",
  8354. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8355. groups: _int | SymInt = 1,
  8356. ) -> Tensor: ...
  8357. @overload
  8358. def conv2d(
  8359. input: Tensor,
  8360. weight: Tensor,
  8361. bias: Tensor | None = None,
  8362. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8363. padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8364. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8365. groups: _int | SymInt = 1,
  8366. ) -> Tensor: ...
  8367. @overload
  8368. def conv2d(
  8369. input: Tensor,
  8370. weight: Tensor,
  8371. bias: Tensor | None = None,
  8372. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8373. padding: str = "valid",
  8374. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8375. groups: _int | SymInt = 1,
  8376. ) -> Tensor: ...
  8377. @overload
  8378. def conv3d(
  8379. input: Tensor,
  8380. weight: Tensor,
  8381. bias: Tensor | None = None,
  8382. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8383. padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8384. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8385. groups: _int | SymInt = 1,
  8386. ) -> Tensor: ...
  8387. @overload
  8388. def conv3d(
  8389. input: Tensor,
  8390. weight: Tensor,
  8391. bias: Tensor | None = None,
  8392. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8393. padding: str = "valid",
  8394. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8395. groups: _int | SymInt = 1,
  8396. ) -> Tensor: ...
  8397. def conv_tbc(
  8398. input: Tensor,
  8399. weight: Tensor,
  8400. bias: Tensor,
  8401. pad: _int = 0,
  8402. ) -> Tensor: ...
  8403. def conv_transpose1d(
  8404. input: Tensor,
  8405. weight: Tensor,
  8406. bias: Tensor | None = None,
  8407. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8408. padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8409. output_padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8410. groups: _int | SymInt = 1,
  8411. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8412. ) -> Tensor: ...
  8413. def conv_transpose2d(
  8414. input: Tensor,
  8415. weight: Tensor,
  8416. bias: Tensor | None = None,
  8417. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8418. padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8419. output_padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8420. groups: _int | SymInt = 1,
  8421. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8422. ) -> Tensor: ...
  8423. def conv_transpose3d(
  8424. input: Tensor,
  8425. weight: Tensor,
  8426. bias: Tensor | None = None,
  8427. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8428. padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8429. output_padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8430. groups: _int | SymInt = 1,
  8431. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8432. ) -> Tensor: ...
  8433. def convolution(
  8434. input: Tensor,
  8435. weight: Tensor,
  8436. bias: Tensor | None,
  8437. stride: Sequence[_int | SymInt],
  8438. padding: Sequence[_int | SymInt],
  8439. dilation: Sequence[_int | SymInt],
  8440. transposed: _bool,
  8441. output_padding: Sequence[_int | SymInt],
  8442. groups: _int | SymInt,
  8443. ) -> Tensor: ...
  8444. @overload
  8445. def copysign(
  8446. input: Tensor,
  8447. other: Tensor,
  8448. *,
  8449. out: Tensor | None = None,
  8450. ) -> Tensor:
  8451. r"""
  8452. copysign(input, other, *, out=None) -> Tensor
  8453. Create a new floating-point tensor with the magnitude of :attr:`input` and the sign of :attr:`other`, elementwise.
  8454. .. math::
  8455. \text{out}_{i} = \begin{cases}
  8456. -|\text{input}_{i}| & \text{if } \text{other}_{i} \leq -0.0 \\
  8457. |\text{input}_{i}| & \text{if } \text{other}_{i} \geq 0.0 \\
  8458. \end{cases}
  8459. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  8460. and integer and float inputs.
  8461. Args:
  8462. input (Tensor): magnitudes.
  8463. other (Tensor or Number): contains value(s) whose signbit(s) are
  8464. applied to the magnitudes in :attr:`input`.
  8465. Keyword args:
  8466. out (Tensor, optional): the output tensor.
  8467. Example::
  8468. >>> a = torch.randn(5)
  8469. >>> a
  8470. tensor([-1.2557, -0.0026, -0.5387, 0.4740, -0.9244])
  8471. >>> torch.copysign(a, 1)
  8472. tensor([1.2557, 0.0026, 0.5387, 0.4740, 0.9244])
  8473. >>> a = torch.randn(4, 4)
  8474. >>> a
  8475. tensor([[ 0.7079, 0.2778, -1.0249, 0.5719],
  8476. [-0.0059, -0.2600, -0.4475, -1.3948],
  8477. [ 0.3667, -0.9567, -2.5757, -0.1751],
  8478. [ 0.2046, -0.0742, 0.2998, -0.1054]])
  8479. >>> b = torch.randn(4)
  8480. tensor([ 0.2373, 0.3120, 0.3190, -1.1128])
  8481. >>> torch.copysign(a, b)
  8482. tensor([[ 0.7079, 0.2778, 1.0249, -0.5719],
  8483. [ 0.0059, 0.2600, 0.4475, -1.3948],
  8484. [ 0.3667, 0.9567, 2.5757, -0.1751],
  8485. [ 0.2046, 0.0742, 0.2998, -0.1054]])
  8486. >>> a = torch.tensor([1.])
  8487. >>> b = torch.tensor([-0.])
  8488. >>> torch.copysign(a, b)
  8489. tensor([-1.])
  8490. .. note::
  8491. copysign handles signed zeros. If the other argument has a negative zero (-0),
  8492. the corresponding output value will be negative.
  8493. """
  8494. @overload
  8495. def copysign(
  8496. input: Tensor,
  8497. other: Number | _complex,
  8498. *,
  8499. out: Tensor | None = None,
  8500. ) -> Tensor:
  8501. r"""
  8502. copysign(input, other, *, out=None) -> Tensor
  8503. Create a new floating-point tensor with the magnitude of :attr:`input` and the sign of :attr:`other`, elementwise.
  8504. .. math::
  8505. \text{out}_{i} = \begin{cases}
  8506. -|\text{input}_{i}| & \text{if } \text{other}_{i} \leq -0.0 \\
  8507. |\text{input}_{i}| & \text{if } \text{other}_{i} \geq 0.0 \\
  8508. \end{cases}
  8509. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  8510. and integer and float inputs.
  8511. Args:
  8512. input (Tensor): magnitudes.
  8513. other (Tensor or Number): contains value(s) whose signbit(s) are
  8514. applied to the magnitudes in :attr:`input`.
  8515. Keyword args:
  8516. out (Tensor, optional): the output tensor.
  8517. Example::
  8518. >>> a = torch.randn(5)
  8519. >>> a
  8520. tensor([-1.2557, -0.0026, -0.5387, 0.4740, -0.9244])
  8521. >>> torch.copysign(a, 1)
  8522. tensor([1.2557, 0.0026, 0.5387, 0.4740, 0.9244])
  8523. >>> a = torch.randn(4, 4)
  8524. >>> a
  8525. tensor([[ 0.7079, 0.2778, -1.0249, 0.5719],
  8526. [-0.0059, -0.2600, -0.4475, -1.3948],
  8527. [ 0.3667, -0.9567, -2.5757, -0.1751],
  8528. [ 0.2046, -0.0742, 0.2998, -0.1054]])
  8529. >>> b = torch.randn(4)
  8530. tensor([ 0.2373, 0.3120, 0.3190, -1.1128])
  8531. >>> torch.copysign(a, b)
  8532. tensor([[ 0.7079, 0.2778, 1.0249, -0.5719],
  8533. [ 0.0059, 0.2600, 0.4475, -1.3948],
  8534. [ 0.3667, 0.9567, 2.5757, -0.1751],
  8535. [ 0.2046, 0.0742, 0.2998, -0.1054]])
  8536. >>> a = torch.tensor([1.])
  8537. >>> b = torch.tensor([-0.])
  8538. >>> torch.copysign(a, b)
  8539. tensor([-1.])
  8540. .. note::
  8541. copysign handles signed zeros. If the other argument has a negative zero (-0),
  8542. the corresponding output value will be negative.
  8543. """
  8544. def corrcoef(input: Tensor) -> Tensor:
  8545. r"""
  8546. corrcoef(input) -> Tensor
  8547. Estimates the Pearson product-moment correlation coefficient matrix of the variables given by the :attr:`input` matrix,
  8548. where rows are the variables and columns are the observations.
  8549. .. note::
  8550. The correlation coefficient matrix R is computed using the covariance matrix C as given by
  8551. :math:`R_{ij} = \frac{ C_{ij} } { \sqrt{ C_{ii} * C_{jj} } }`
  8552. .. note::
  8553. Due to floating point rounding, the resulting array may not be Hermitian and its diagonal elements may not be 1.
  8554. The real and imaginary values are clipped to the interval [-1, 1] in an attempt to improve this situation.
  8555. Args:
  8556. input (Tensor): A 2D matrix containing multiple variables and observations, or a
  8557. Scalar or 1D vector representing a single variable.
  8558. Returns:
  8559. (Tensor) The correlation coefficient matrix of the variables.
  8560. .. seealso::
  8561. :func:`torch.cov` covariance matrix.
  8562. Example::
  8563. >>> x = torch.tensor([[0, 1, 2], [2, 1, 0]])
  8564. >>> torch.corrcoef(x)
  8565. tensor([[ 1., -1.],
  8566. [-1., 1.]])
  8567. >>> x = torch.randn(2, 4)
  8568. >>> x
  8569. tensor([[-0.2678, -0.0908, -0.3766, 0.2780],
  8570. [-0.5812, 0.1535, 0.2387, 0.2350]])
  8571. >>> torch.corrcoef(x)
  8572. tensor([[1.0000, 0.3582],
  8573. [0.3582, 1.0000]])
  8574. >>> torch.corrcoef(x[0])
  8575. tensor(1.)
  8576. """
  8577. def cos(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  8578. r"""
  8579. cos(input, *, out=None) -> Tensor
  8580. Returns a new tensor with the cosine of the elements of :attr:`input`.
  8581. .. math::
  8582. \text{out}_{i} = \cos(\text{input}_{i})
  8583. Args:
  8584. input (Tensor): the input tensor.
  8585. Keyword args:
  8586. out (Tensor, optional): the output tensor.
  8587. Example::
  8588. >>> a = torch.randn(4)
  8589. >>> a
  8590. tensor([ 1.4309, 1.2706, -0.8562, 0.9796])
  8591. >>> torch.cos(a)
  8592. tensor([ 0.1395, 0.2957, 0.6553, 0.5574])
  8593. """
  8594. def cos_(input: Tensor) -> Tensor: ...
  8595. def cosh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  8596. r"""
  8597. cosh(input, *, out=None) -> Tensor
  8598. Returns a new tensor with the hyperbolic cosine of the elements of
  8599. :attr:`input`.
  8600. .. math::
  8601. \text{out}_{i} = \cosh(\text{input}_{i})
  8602. Args:
  8603. input (Tensor): the input tensor.
  8604. Keyword args:
  8605. out (Tensor, optional): the output tensor.
  8606. Example::
  8607. >>> a = torch.randn(4)
  8608. >>> a
  8609. tensor([ 0.1632, 1.1835, -0.6979, -0.7325])
  8610. >>> torch.cosh(a)
  8611. tensor([ 1.0133, 1.7860, 1.2536, 1.2805])
  8612. .. note::
  8613. When :attr:`input` is on the CPU, the implementation of torch.cosh may use
  8614. the Sleef library, which rounds very large results to infinity or negative
  8615. infinity. See `here <https://sleef.org/purec.xhtml>`_ for details.
  8616. """
  8617. def cosh_(input: Tensor) -> Tensor: ...
  8618. def cosine_embedding_loss(
  8619. input1: Tensor,
  8620. input2: Tensor,
  8621. target: Tensor,
  8622. margin: _float = 0.0,
  8623. reduction: _int = 1,
  8624. ) -> Tensor: ...
  8625. def cosine_similarity(
  8626. x1: Tensor,
  8627. x2: Tensor,
  8628. dim: _int = 1,
  8629. eps: _float = 1e-08,
  8630. ) -> Tensor: ...
  8631. @overload
  8632. def count_nonzero(input: Tensor, dim: _int | None = None) -> Tensor:
  8633. r"""
  8634. count_nonzero(input, dim=None) -> Tensor
  8635. Counts the number of non-zero values in the tensor :attr:`input` along the given :attr:`dim`.
  8636. If no dim is specified then all non-zeros in the tensor are counted.
  8637. Args:
  8638. input (Tensor): the input tensor.
  8639. dim (int or tuple of ints, optional): Dim or tuple of dims along which to count non-zeros.
  8640. Example::
  8641. >>> x = torch.zeros(3,3)
  8642. >>> x[torch.randn(3,3) > 0.5] = 1
  8643. >>> x
  8644. tensor([[0., 1., 1.],
  8645. [0., 0., 0.],
  8646. [0., 0., 1.]])
  8647. >>> torch.count_nonzero(x)
  8648. tensor(3)
  8649. >>> torch.count_nonzero(x, dim=0)
  8650. tensor([0, 1, 2])
  8651. """
  8652. @overload
  8653. def count_nonzero(input: Tensor, dim: _size) -> Tensor:
  8654. r"""
  8655. count_nonzero(input, dim=None) -> Tensor
  8656. Counts the number of non-zero values in the tensor :attr:`input` along the given :attr:`dim`.
  8657. If no dim is specified then all non-zeros in the tensor are counted.
  8658. Args:
  8659. input (Tensor): the input tensor.
  8660. dim (int or tuple of ints, optional): Dim or tuple of dims along which to count non-zeros.
  8661. Example::
  8662. >>> x = torch.zeros(3,3)
  8663. >>> x[torch.randn(3,3) > 0.5] = 1
  8664. >>> x
  8665. tensor([[0., 1., 1.],
  8666. [0., 0., 0.],
  8667. [0., 0., 1.]])
  8668. >>> torch.count_nonzero(x)
  8669. tensor(3)
  8670. >>> torch.count_nonzero(x, dim=0)
  8671. tensor([0, 1, 2])
  8672. """
  8673. def cov(
  8674. input: Tensor,
  8675. *,
  8676. correction: _int = 1,
  8677. fweights: Tensor | None = None,
  8678. aweights: Tensor | None = None,
  8679. ) -> Tensor:
  8680. r"""
  8681. cov(input, *, correction=1, fweights=None, aweights=None) -> Tensor
  8682. Estimates the covariance matrix of the variables given by the :attr:`input` matrix, where rows are
  8683. the variables and columns are the observations.
  8684. A covariance matrix is a square matrix giving the covariance of each pair of variables. The diagonal contains
  8685. the variance of each variable (covariance of a variable with itself). By definition, if :attr:`input` represents
  8686. a single variable (Scalar or 1D) then its variance is returned.
  8687. The sample covariance of the variables :math:`x` and :math:`y` is given by:
  8688. .. math::
  8689. \text{cov}(x,y) = \frac{\sum^{N}_{i = 1}(x_{i} - \bar{x})(y_{i} - \bar{y})}{\max(0,~N~-~\delta N)}
  8690. where :math:`\bar{x}` and :math:`\bar{y}` are the simple means of the :math:`x` and :math:`y` respectively, and
  8691. :math:`\delta N` is the :attr:`correction`.
  8692. If :attr:`fweights` and/or :attr:`aweights` are provided, the weighted covariance
  8693. is calculated, which is given by:
  8694. .. math::
  8695. \text{cov}_w(x,y) = \frac{\sum^{N}_{i = 1}w_i(x_{i} - \mu_x^*)(y_{i} - \mu_y^*)}
  8696. {\max(0,~\sum^{N}_{i = 1}w_i~-~\frac{\sum^{N}_{i = 1}w_ia_i}{\sum^{N}_{i = 1}w_i}~\delta N)}
  8697. where :math:`w` denotes :attr:`fweights` or :attr:`aweights` (``f`` and ``a`` for brevity) based on whichever is
  8698. provided, or :math:`w = f \times a` if both are provided, and
  8699. :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
  8700. provided, ``f`` and/or ``a`` can be seen as a :math:`\mathbb{1}` vector of appropriate size.
  8701. Args:
  8702. input (Tensor): A 2D matrix containing multiple variables and observations, or a
  8703. Scalar or 1D vector representing a single variable.
  8704. Keyword Args:
  8705. correction (int, optional): difference between the sample size and sample degrees of freedom.
  8706. Defaults to Bessel's correction, ``correction = 1`` which returns the unbiased estimate,
  8707. even if both :attr:`fweights` and :attr:`aweights` are specified. ``correction = 0``
  8708. will return the simple average. Defaults to ``1``.
  8709. fweights (tensor, optional): A Scalar or 1D tensor of observation vector frequencies representing the number of
  8710. times each observation should be repeated. Its numel must equal the number of columns of :attr:`input`.
  8711. Must have integral dtype. Ignored if ``None``. Defaults to ``None``.
  8712. aweights (tensor, optional): A Scalar or 1D array of observation vector weights.
  8713. These relative weights are typically large for observations considered "important" and smaller for
  8714. observations considered less "important". Its numel must equal the number of columns of :attr:`input`.
  8715. Must have floating point dtype. Ignored if ``None``. Defaults to ``None``.
  8716. Returns:
  8717. (Tensor) The covariance matrix of the variables.
  8718. .. seealso::
  8719. :func:`torch.corrcoef` normalized covariance matrix.
  8720. Example::
  8721. >>> x = torch.tensor([[0, 2], [1, 1], [2, 0]]).T
  8722. >>> x
  8723. tensor([[0, 1, 2],
  8724. [2, 1, 0]])
  8725. >>> torch.cov(x)
  8726. tensor([[ 1., -1.],
  8727. [-1., 1.]])
  8728. >>> torch.cov(x, correction=0)
  8729. tensor([[ 0.6667, -0.6667],
  8730. [-0.6667, 0.6667]])
  8731. >>> fw = torch.randint(1, 10, (3,))
  8732. >>> fw
  8733. tensor([1, 6, 9])
  8734. >>> aw = torch.rand(3)
  8735. >>> aw
  8736. tensor([0.4282, 0.0255, 0.4144])
  8737. >>> torch.cov(x, fweights=fw, aweights=aw)
  8738. tensor([[ 0.4169, -0.4169],
  8739. [-0.4169, 0.4169]])
  8740. """
  8741. def cross(
  8742. input: Tensor,
  8743. other: Tensor,
  8744. dim: _int | None = None,
  8745. *,
  8746. out: Tensor | None = None,
  8747. ) -> Tensor:
  8748. r"""
  8749. cross(input, other, dim=None, *, out=None) -> Tensor
  8750. Returns the cross product of vectors in dimension :attr:`dim` of :attr:`input`
  8751. and :attr:`other`.
  8752. Supports input of float, double, cfloat and cdouble dtypes. Also supports batches
  8753. of vectors, for which it computes the product along the dimension :attr:`dim`.
  8754. In this case, the output has the same batch dimensions as the inputs.
  8755. .. warning::
  8756. If :attr:`dim` is not given, it defaults to the first dimension found
  8757. with the size 3. Note that this might be unexpected.
  8758. This behavior is deprecated and will be changed to match that of :func:`torch.linalg.cross`
  8759. in a future release.
  8760. .. seealso::
  8761. :func:`torch.linalg.cross` which has dim=-1 as default.
  8762. Args:
  8763. input (Tensor): the input tensor.
  8764. other (Tensor): the second input tensor
  8765. dim (int, optional): the dimension to take the cross-product in.
  8766. Keyword args:
  8767. out (Tensor, optional): the output tensor.
  8768. Example::
  8769. >>> a = torch.randn(4, 3)
  8770. >>> a
  8771. tensor([[-0.3956, 1.1455, 1.6895],
  8772. [-0.5849, 1.3672, 0.3599],
  8773. [-1.1626, 0.7180, -0.0521],
  8774. [-0.1339, 0.9902, -2.0225]])
  8775. >>> b = torch.randn(4, 3)
  8776. >>> b
  8777. tensor([[-0.0257, -1.4725, -1.2251],
  8778. [-1.1479, -0.7005, -1.9757],
  8779. [-1.3904, 0.3726, -1.1836],
  8780. [-0.9688, -0.7153, 0.2159]])
  8781. >>> torch.cross(a, b, dim=1)
  8782. tensor([[ 1.0844, -0.5281, 0.6120],
  8783. [-2.4490, -1.5687, 1.9792],
  8784. [-0.8304, -1.3037, 0.5650],
  8785. [-1.2329, 1.9883, 1.0551]])
  8786. >>> torch.cross(a, b)
  8787. tensor([[ 1.0844, -0.5281, 0.6120],
  8788. [-2.4490, -1.5687, 1.9792],
  8789. [-0.8304, -1.3037, 0.5650],
  8790. [-1.2329, 1.9883, 1.0551]])
  8791. """
  8792. def crow_indices_copy(
  8793. input: Tensor,
  8794. *,
  8795. out: Tensor | None = None,
  8796. ) -> Tensor:
  8797. r"""
  8798. Performs the same operation as :func:`torch.crow_indices`, but all output tensors
  8799. are freshly created instead of aliasing the input.
  8800. """
  8801. @overload
  8802. def ctc_loss(
  8803. log_probs: Tensor,
  8804. targets: Tensor,
  8805. input_lengths: _size,
  8806. target_lengths: _size,
  8807. blank: _int = 0,
  8808. reduction: _int = 1,
  8809. zero_infinity: _bool = False,
  8810. ) -> Tensor: ...
  8811. @overload
  8812. def ctc_loss(
  8813. log_probs: Tensor,
  8814. targets: Tensor,
  8815. input_lengths: Tensor,
  8816. target_lengths: Tensor,
  8817. blank: _int = 0,
  8818. reduction: _int = 1,
  8819. zero_infinity: _bool = False,
  8820. ) -> Tensor: ...
  8821. def cudnn_affine_grid_generator(
  8822. theta: Tensor,
  8823. N: _int,
  8824. C: _int,
  8825. H: _int,
  8826. W: _int,
  8827. ) -> Tensor: ...
  8828. def cudnn_batch_norm(
  8829. input: Tensor,
  8830. weight: Tensor,
  8831. bias: Tensor | None,
  8832. running_mean: Tensor | None,
  8833. running_var: Tensor | None,
  8834. training: _bool,
  8835. exponential_average_factor: _float,
  8836. epsilon: _float,
  8837. *,
  8838. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  8839. ) -> tuple[Tensor, Tensor, Tensor, Tensor]: ...
  8840. def cudnn_convolution(
  8841. input: Tensor,
  8842. weight: Tensor,
  8843. padding: Sequence[_int | SymInt],
  8844. stride: Sequence[_int | SymInt],
  8845. dilation: Sequence[_int | SymInt],
  8846. groups: _int | SymInt,
  8847. benchmark: _bool,
  8848. deterministic: _bool,
  8849. allow_tf32: _bool,
  8850. *,
  8851. out: Tensor | None = None,
  8852. ) -> Tensor: ...
  8853. def cudnn_convolution_add_relu(
  8854. input: Tensor,
  8855. weight: Tensor,
  8856. z: Tensor,
  8857. alpha: Number | _complex | None,
  8858. bias: Tensor | None,
  8859. stride: Sequence[_int | SymInt],
  8860. padding: Sequence[_int | SymInt],
  8861. dilation: Sequence[_int | SymInt],
  8862. groups: _int | SymInt,
  8863. ) -> Tensor: ...
  8864. def cudnn_convolution_relu(
  8865. input: Tensor,
  8866. weight: Tensor,
  8867. bias: Tensor | None,
  8868. stride: Sequence[_int | SymInt],
  8869. padding: Sequence[_int | SymInt],
  8870. dilation: Sequence[_int | SymInt],
  8871. groups: _int | SymInt,
  8872. ) -> Tensor: ...
  8873. def cudnn_convolution_transpose(
  8874. input: Tensor,
  8875. weight: Tensor,
  8876. padding: Sequence[_int | SymInt],
  8877. output_padding: Sequence[_int | SymInt],
  8878. stride: Sequence[_int | SymInt],
  8879. dilation: Sequence[_int | SymInt],
  8880. groups: _int | SymInt,
  8881. benchmark: _bool,
  8882. deterministic: _bool,
  8883. allow_tf32: _bool,
  8884. ) -> Tensor: ...
  8885. def cudnn_grid_sampler(input: Tensor, grid: Tensor) -> Tensor: ...
  8886. def cudnn_is_acceptable(input: Tensor) -> _bool: ...
  8887. @overload
  8888. def cummax(
  8889. input: Tensor,
  8890. dim: _int,
  8891. *,
  8892. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  8893. ) -> torch.return_types.cummax:
  8894. r"""
  8895. cummax(input, dim, *, out=None) -> (Tensor, LongTensor)
  8896. Returns a namedtuple ``(values, indices)`` where ``values`` is the cumulative maximum of
  8897. elements of :attr:`input` in the dimension :attr:`dim`. And ``indices`` is the index
  8898. location of each maximum value found in the dimension :attr:`dim`.
  8899. .. math::
  8900. y_i = max(x_1, x_2, x_3, \dots, x_i)
  8901. Args:
  8902. input (Tensor): the input tensor.
  8903. dim (int): the dimension to do the operation over
  8904. Keyword args:
  8905. out (tuple, optional): the result tuple of two output tensors (values, indices)
  8906. Example::
  8907. >>> a = torch.randn(10)
  8908. >>> a
  8909. tensor([-0.3449, -1.5447, 0.0685, -1.5104, -1.1706, 0.2259, 1.4696, -1.3284,
  8910. 1.9946, -0.8209])
  8911. >>> torch.cummax(a, dim=0)
  8912. torch.return_types.cummax(
  8913. values=tensor([-0.3449, -0.3449, 0.0685, 0.0685, 0.0685, 0.2259, 1.4696, 1.4696,
  8914. 1.9946, 1.9946]),
  8915. indices=tensor([0, 0, 2, 2, 2, 5, 6, 6, 8, 8]))
  8916. """
  8917. @overload
  8918. def cummax(
  8919. input: Tensor,
  8920. dim: str | EllipsisType | None,
  8921. *,
  8922. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  8923. ) -> torch.return_types.cummax:
  8924. r"""
  8925. cummax(input, dim, *, out=None) -> (Tensor, LongTensor)
  8926. Returns a namedtuple ``(values, indices)`` where ``values`` is the cumulative maximum of
  8927. elements of :attr:`input` in the dimension :attr:`dim`. And ``indices`` is the index
  8928. location of each maximum value found in the dimension :attr:`dim`.
  8929. .. math::
  8930. y_i = max(x_1, x_2, x_3, \dots, x_i)
  8931. Args:
  8932. input (Tensor): the input tensor.
  8933. dim (int): the dimension to do the operation over
  8934. Keyword args:
  8935. out (tuple, optional): the result tuple of two output tensors (values, indices)
  8936. Example::
  8937. >>> a = torch.randn(10)
  8938. >>> a
  8939. tensor([-0.3449, -1.5447, 0.0685, -1.5104, -1.1706, 0.2259, 1.4696, -1.3284,
  8940. 1.9946, -0.8209])
  8941. >>> torch.cummax(a, dim=0)
  8942. torch.return_types.cummax(
  8943. values=tensor([-0.3449, -0.3449, 0.0685, 0.0685, 0.0685, 0.2259, 1.4696, 1.4696,
  8944. 1.9946, 1.9946]),
  8945. indices=tensor([0, 0, 2, 2, 2, 5, 6, 6, 8, 8]))
  8946. """
  8947. @overload
  8948. def cummin(
  8949. input: Tensor,
  8950. dim: _int,
  8951. *,
  8952. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  8953. ) -> torch.return_types.cummin:
  8954. r"""
  8955. cummin(input, dim, *, out=None) -> (Tensor, LongTensor)
  8956. Returns a namedtuple ``(values, indices)`` where ``values`` is the cumulative minimum of
  8957. elements of :attr:`input` in the dimension :attr:`dim`. And ``indices`` is the index
  8958. location of each maximum value found in the dimension :attr:`dim`.
  8959. .. math::
  8960. y_i = min(x_1, x_2, x_3, \dots, x_i)
  8961. Args:
  8962. input (Tensor): the input tensor.
  8963. dim (int): the dimension to do the operation over
  8964. Keyword args:
  8965. out (tuple, optional): the result tuple of two output tensors (values, indices)
  8966. Example::
  8967. >>> a = torch.randn(10)
  8968. >>> a
  8969. tensor([-0.2284, -0.6628, 0.0975, 0.2680, -1.3298, -0.4220, -0.3885, 1.1762,
  8970. 0.9165, 1.6684])
  8971. >>> torch.cummin(a, dim=0)
  8972. torch.return_types.cummin(
  8973. values=tensor([-0.2284, -0.6628, -0.6628, -0.6628, -1.3298, -1.3298, -1.3298, -1.3298,
  8974. -1.3298, -1.3298]),
  8975. indices=tensor([0, 1, 1, 1, 4, 4, 4, 4, 4, 4]))
  8976. """
  8977. @overload
  8978. def cummin(
  8979. input: Tensor,
  8980. dim: str | EllipsisType | None,
  8981. *,
  8982. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  8983. ) -> torch.return_types.cummin:
  8984. r"""
  8985. cummin(input, dim, *, out=None) -> (Tensor, LongTensor)
  8986. Returns a namedtuple ``(values, indices)`` where ``values`` is the cumulative minimum of
  8987. elements of :attr:`input` in the dimension :attr:`dim`. And ``indices`` is the index
  8988. location of each maximum value found in the dimension :attr:`dim`.
  8989. .. math::
  8990. y_i = min(x_1, x_2, x_3, \dots, x_i)
  8991. Args:
  8992. input (Tensor): the input tensor.
  8993. dim (int): the dimension to do the operation over
  8994. Keyword args:
  8995. out (tuple, optional): the result tuple of two output tensors (values, indices)
  8996. Example::
  8997. >>> a = torch.randn(10)
  8998. >>> a
  8999. tensor([-0.2284, -0.6628, 0.0975, 0.2680, -1.3298, -0.4220, -0.3885, 1.1762,
  9000. 0.9165, 1.6684])
  9001. >>> torch.cummin(a, dim=0)
  9002. torch.return_types.cummin(
  9003. values=tensor([-0.2284, -0.6628, -0.6628, -0.6628, -1.3298, -1.3298, -1.3298, -1.3298,
  9004. -1.3298, -1.3298]),
  9005. indices=tensor([0, 1, 1, 1, 4, 4, 4, 4, 4, 4]))
  9006. """
  9007. @overload
  9008. def cumprod(
  9009. input: Tensor,
  9010. dim: _int,
  9011. *,
  9012. dtype: _dtype | None = None,
  9013. out: Tensor | None = None,
  9014. ) -> Tensor:
  9015. r"""
  9016. cumprod(input, dim, *, dtype=None, out=None) -> Tensor
  9017. Returns the cumulative product of elements of :attr:`input` in the dimension
  9018. :attr:`dim`.
  9019. For example, if :attr:`input` is a vector of size N, the result will also be
  9020. a vector of size N, with elements.
  9021. .. math::
  9022. y_i = x_1 \times x_2\times x_3\times \dots \times x_i
  9023. Args:
  9024. input (Tensor): the input tensor.
  9025. dim (int): the dimension to do the operation over
  9026. Keyword args:
  9027. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  9028. If specified, the input tensor is casted to :attr:`dtype` before the operation
  9029. is performed. This is useful for preventing data type overflows. Default: None.
  9030. out (Tensor, optional): the output tensor.
  9031. Example::
  9032. >>> a = torch.randn(10)
  9033. >>> a
  9034. tensor([ 0.6001, 0.2069, -0.1919, 0.9792, 0.6727, 1.0062, 0.4126,
  9035. -0.2129, -0.4206, 0.1968])
  9036. >>> torch.cumprod(a, dim=0)
  9037. tensor([ 0.6001, 0.1241, -0.0238, -0.0233, -0.0157, -0.0158, -0.0065,
  9038. 0.0014, -0.0006, -0.0001])
  9039. >>> a[5] = 0.0
  9040. >>> torch.cumprod(a, dim=0)
  9041. tensor([ 0.6001, 0.1241, -0.0238, -0.0233, -0.0157, -0.0000, -0.0000,
  9042. 0.0000, -0.0000, -0.0000])
  9043. """
  9044. @overload
  9045. def cumprod(
  9046. input: Tensor,
  9047. dim: str | EllipsisType | None,
  9048. *,
  9049. dtype: _dtype | None = None,
  9050. out: Tensor | None = None,
  9051. ) -> Tensor:
  9052. r"""
  9053. cumprod(input, dim, *, dtype=None, out=None) -> Tensor
  9054. Returns the cumulative product of elements of :attr:`input` in the dimension
  9055. :attr:`dim`.
  9056. For example, if :attr:`input` is a vector of size N, the result will also be
  9057. a vector of size N, with elements.
  9058. .. math::
  9059. y_i = x_1 \times x_2\times x_3\times \dots \times x_i
  9060. Args:
  9061. input (Tensor): the input tensor.
  9062. dim (int): the dimension to do the operation over
  9063. Keyword args:
  9064. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  9065. If specified, the input tensor is casted to :attr:`dtype` before the operation
  9066. is performed. This is useful for preventing data type overflows. Default: None.
  9067. out (Tensor, optional): the output tensor.
  9068. Example::
  9069. >>> a = torch.randn(10)
  9070. >>> a
  9071. tensor([ 0.6001, 0.2069, -0.1919, 0.9792, 0.6727, 1.0062, 0.4126,
  9072. -0.2129, -0.4206, 0.1968])
  9073. >>> torch.cumprod(a, dim=0)
  9074. tensor([ 0.6001, 0.1241, -0.0238, -0.0233, -0.0157, -0.0158, -0.0065,
  9075. 0.0014, -0.0006, -0.0001])
  9076. >>> a[5] = 0.0
  9077. >>> torch.cumprod(a, dim=0)
  9078. tensor([ 0.6001, 0.1241, -0.0238, -0.0233, -0.0157, -0.0000, -0.0000,
  9079. 0.0000, -0.0000, -0.0000])
  9080. """
  9081. @overload
  9082. def cumsum(
  9083. input: Tensor,
  9084. dim: _int,
  9085. *,
  9086. dtype: _dtype | None = None,
  9087. out: Tensor | None = None,
  9088. ) -> Tensor:
  9089. r"""
  9090. cumsum(input, dim, *, dtype=None, out=None) -> Tensor
  9091. Returns the cumulative sum of elements of :attr:`input` in the dimension
  9092. :attr:`dim`.
  9093. For example, if :attr:`input` is a vector of size N, the result will also be
  9094. a vector of size N, with elements.
  9095. .. math::
  9096. y_i = x_1 + x_2 + x_3 + \dots + x_i
  9097. Args:
  9098. input (Tensor): the input tensor.
  9099. dim (int): the dimension to do the operation over
  9100. Keyword args:
  9101. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  9102. If specified, the input tensor is casted to :attr:`dtype` before the operation
  9103. is performed. This is useful for preventing data type overflows. Default: None.
  9104. out (Tensor, optional): the output tensor.
  9105. Example::
  9106. >>> a = torch.randint(1, 20, (10,))
  9107. >>> a
  9108. tensor([13, 7, 3, 10, 13, 3, 15, 10, 9, 10])
  9109. >>> torch.cumsum(a, dim=0)
  9110. tensor([13, 20, 23, 33, 46, 49, 64, 74, 83, 93])
  9111. """
  9112. @overload
  9113. def cumsum(
  9114. input: Tensor,
  9115. dim: str | EllipsisType | None,
  9116. *,
  9117. dtype: _dtype | None = None,
  9118. out: Tensor | None = None,
  9119. ) -> Tensor:
  9120. r"""
  9121. cumsum(input, dim, *, dtype=None, out=None) -> Tensor
  9122. Returns the cumulative sum of elements of :attr:`input` in the dimension
  9123. :attr:`dim`.
  9124. For example, if :attr:`input` is a vector of size N, the result will also be
  9125. a vector of size N, with elements.
  9126. .. math::
  9127. y_i = x_1 + x_2 + x_3 + \dots + x_i
  9128. Args:
  9129. input (Tensor): the input tensor.
  9130. dim (int): the dimension to do the operation over
  9131. Keyword args:
  9132. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  9133. If specified, the input tensor is casted to :attr:`dtype` before the operation
  9134. is performed. This is useful for preventing data type overflows. Default: None.
  9135. out (Tensor, optional): the output tensor.
  9136. Example::
  9137. >>> a = torch.randint(1, 20, (10,))
  9138. >>> a
  9139. tensor([13, 7, 3, 10, 13, 3, 15, 10, 9, 10])
  9140. >>> torch.cumsum(a, dim=0)
  9141. tensor([13, 20, 23, 33, 46, 49, 64, 74, 83, 93])
  9142. """
  9143. @overload
  9144. def cumulative_trapezoid(y: Tensor, x: Tensor, *, dim: _int = -1) -> Tensor:
  9145. r"""
  9146. cumulative_trapezoid(y, x=None, *, dx=None, dim=-1) -> Tensor
  9147. Cumulatively computes the `trapezoidal rule <https://en.wikipedia.org/wiki/Trapezoidal_rule>`_
  9148. along :attr:`dim`. By default the spacing between elements is assumed to be 1, but
  9149. :attr:`dx` can be used to specify a different constant spacing, and :attr:`x` can be
  9150. used to specify arbitrary spacing along :attr:`dim`.
  9151. For more details, please read :func:`torch.trapezoid`. The difference between :func:`torch.trapezoid`
  9152. and this function is that, :func:`torch.trapezoid` returns a value for each integration,
  9153. where as this function returns a cumulative value for every spacing within the integration. This
  9154. is analogous to how `.sum` returns a value and `.cumsum` returns a cumulative sum.
  9155. Arguments:
  9156. y (Tensor): Values to use when computing the trapezoidal rule.
  9157. x (Tensor): If specified, defines spacing between values as specified above.
  9158. Keyword arguments:
  9159. dx (float): constant spacing between values. If neither :attr:`x` or :attr:`dx`
  9160. are specified then this defaults to 1. Effectively multiplies the result by its value.
  9161. dim (int): The dimension along which to compute the trapezoidal rule.
  9162. The last (inner-most) dimension by default.
  9163. Examples::
  9164. >>> # Cumulatively computes the trapezoidal rule in 1D, spacing is implicitly 1.
  9165. >>> y = torch.tensor([1, 5, 10])
  9166. >>> torch.cumulative_trapezoid(y)
  9167. tensor([3., 10.5])
  9168. >>> # Computes the same trapezoidal rule directly up to each element to verify
  9169. >>> (1 + 5) / 2
  9170. 3.0
  9171. >>> (1 + 10 + 10) / 2
  9172. 10.5
  9173. >>> # Cumulatively computes the trapezoidal rule in 1D with constant spacing of 2
  9174. >>> # NOTE: the result is the same as before, but multiplied by 2
  9175. >>> torch.cumulative_trapezoid(y, dx=2)
  9176. tensor([6., 21.])
  9177. >>> # Cumulatively computes the trapezoidal rule in 1D with arbitrary spacing
  9178. >>> x = torch.tensor([1, 3, 6])
  9179. >>> torch.cumulative_trapezoid(y, x)
  9180. tensor([6., 28.5])
  9181. >>> # Computes the same trapezoidal rule directly up to each element to verify
  9182. >>> ((3 - 1) * (1 + 5)) / 2
  9183. 6.0
  9184. >>> ((3 - 1) * (1 + 5) + (6 - 3) * (5 + 10)) / 2
  9185. 28.5
  9186. >>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 matrix
  9187. >>> y = torch.arange(9).reshape(3, 3)
  9188. tensor([[0, 1, 2],
  9189. [3, 4, 5],
  9190. [6, 7, 8]])
  9191. >>> torch.cumulative_trapezoid(y)
  9192. tensor([[ 0.5, 2.],
  9193. [ 3.5, 8.],
  9194. [ 6.5, 14.]])
  9195. >>> # Cumulatively computes the trapezoidal rule for each column of the matrix
  9196. >>> torch.cumulative_trapezoid(y, dim=0)
  9197. tensor([[ 1.5, 2.5, 3.5],
  9198. [ 6.0, 8.0, 10.0]])
  9199. >>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 ones matrix
  9200. >>> # with the same arbitrary spacing
  9201. >>> y = torch.ones(3, 3)
  9202. >>> x = torch.tensor([1, 3, 6])
  9203. >>> torch.cumulative_trapezoid(y, x)
  9204. tensor([[2., 5.],
  9205. [2., 5.],
  9206. [2., 5.]])
  9207. >>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 ones matrix
  9208. >>> # with different arbitrary spacing per row
  9209. >>> y = torch.ones(3, 3)
  9210. >>> x = torch.tensor([[1, 2, 3], [1, 3, 5], [1, 4, 7]])
  9211. >>> torch.cumulative_trapezoid(y, x)
  9212. tensor([[1., 2.],
  9213. [2., 4.],
  9214. [3., 6.]])
  9215. """
  9216. @overload
  9217. def cumulative_trapezoid(
  9218. y: Tensor,
  9219. *,
  9220. dx: Number | _complex = 1,
  9221. dim: _int = -1,
  9222. ) -> Tensor:
  9223. r"""
  9224. cumulative_trapezoid(y, x=None, *, dx=None, dim=-1) -> Tensor
  9225. Cumulatively computes the `trapezoidal rule <https://en.wikipedia.org/wiki/Trapezoidal_rule>`_
  9226. along :attr:`dim`. By default the spacing between elements is assumed to be 1, but
  9227. :attr:`dx` can be used to specify a different constant spacing, and :attr:`x` can be
  9228. used to specify arbitrary spacing along :attr:`dim`.
  9229. For more details, please read :func:`torch.trapezoid`. The difference between :func:`torch.trapezoid`
  9230. and this function is that, :func:`torch.trapezoid` returns a value for each integration,
  9231. where as this function returns a cumulative value for every spacing within the integration. This
  9232. is analogous to how `.sum` returns a value and `.cumsum` returns a cumulative sum.
  9233. Arguments:
  9234. y (Tensor): Values to use when computing the trapezoidal rule.
  9235. x (Tensor): If specified, defines spacing between values as specified above.
  9236. Keyword arguments:
  9237. dx (float): constant spacing between values. If neither :attr:`x` or :attr:`dx`
  9238. are specified then this defaults to 1. Effectively multiplies the result by its value.
  9239. dim (int): The dimension along which to compute the trapezoidal rule.
  9240. The last (inner-most) dimension by default.
  9241. Examples::
  9242. >>> # Cumulatively computes the trapezoidal rule in 1D, spacing is implicitly 1.
  9243. >>> y = torch.tensor([1, 5, 10])
  9244. >>> torch.cumulative_trapezoid(y)
  9245. tensor([3., 10.5])
  9246. >>> # Computes the same trapezoidal rule directly up to each element to verify
  9247. >>> (1 + 5) / 2
  9248. 3.0
  9249. >>> (1 + 10 + 10) / 2
  9250. 10.5
  9251. >>> # Cumulatively computes the trapezoidal rule in 1D with constant spacing of 2
  9252. >>> # NOTE: the result is the same as before, but multiplied by 2
  9253. >>> torch.cumulative_trapezoid(y, dx=2)
  9254. tensor([6., 21.])
  9255. >>> # Cumulatively computes the trapezoidal rule in 1D with arbitrary spacing
  9256. >>> x = torch.tensor([1, 3, 6])
  9257. >>> torch.cumulative_trapezoid(y, x)
  9258. tensor([6., 28.5])
  9259. >>> # Computes the same trapezoidal rule directly up to each element to verify
  9260. >>> ((3 - 1) * (1 + 5)) / 2
  9261. 6.0
  9262. >>> ((3 - 1) * (1 + 5) + (6 - 3) * (5 + 10)) / 2
  9263. 28.5
  9264. >>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 matrix
  9265. >>> y = torch.arange(9).reshape(3, 3)
  9266. tensor([[0, 1, 2],
  9267. [3, 4, 5],
  9268. [6, 7, 8]])
  9269. >>> torch.cumulative_trapezoid(y)
  9270. tensor([[ 0.5, 2.],
  9271. [ 3.5, 8.],
  9272. [ 6.5, 14.]])
  9273. >>> # Cumulatively computes the trapezoidal rule for each column of the matrix
  9274. >>> torch.cumulative_trapezoid(y, dim=0)
  9275. tensor([[ 1.5, 2.5, 3.5],
  9276. [ 6.0, 8.0, 10.0]])
  9277. >>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 ones matrix
  9278. >>> # with the same arbitrary spacing
  9279. >>> y = torch.ones(3, 3)
  9280. >>> x = torch.tensor([1, 3, 6])
  9281. >>> torch.cumulative_trapezoid(y, x)
  9282. tensor([[2., 5.],
  9283. [2., 5.],
  9284. [2., 5.]])
  9285. >>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 ones matrix
  9286. >>> # with different arbitrary spacing per row
  9287. >>> y = torch.ones(3, 3)
  9288. >>> x = torch.tensor([[1, 2, 3], [1, 3, 5], [1, 4, 7]])
  9289. >>> torch.cumulative_trapezoid(y, x)
  9290. tensor([[1., 2.],
  9291. [2., 4.],
  9292. [3., 6.]])
  9293. """
  9294. def deg2rad(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  9295. r"""
  9296. deg2rad(input, *, out=None) -> Tensor
  9297. Returns a new tensor with each of the elements of :attr:`input`
  9298. converted from angles in degrees to radians.
  9299. Args:
  9300. input (Tensor): the input tensor.
  9301. Keyword arguments:
  9302. out (Tensor, optional): the output tensor.
  9303. Example::
  9304. >>> a = torch.tensor([[180.0, -180.0], [360.0, -360.0], [90.0, -90.0]])
  9305. >>> torch.deg2rad(a)
  9306. tensor([[ 3.1416, -3.1416],
  9307. [ 6.2832, -6.2832],
  9308. [ 1.5708, -1.5708]])
  9309. """
  9310. def deg2rad_(input: Tensor) -> Tensor: ...
  9311. @overload
  9312. def dequantize(input: Tensor) -> Tensor:
  9313. r"""
  9314. dequantize(tensor) -> Tensor
  9315. Returns an fp32 Tensor by dequantizing a quantized Tensor
  9316. Args:
  9317. tensor (Tensor): A quantized Tensor
  9318. .. function:: dequantize(tensors) -> sequence of Tensors
  9319. :noindex:
  9320. Given a list of quantized Tensors, dequantize them and return a list of fp32 Tensors
  9321. Args:
  9322. tensors (sequence of Tensors): A list of quantized Tensors
  9323. """
  9324. @overload
  9325. def dequantize(
  9326. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  9327. ) -> tuple[Tensor, ...]:
  9328. r"""
  9329. dequantize(tensor) -> Tensor
  9330. Returns an fp32 Tensor by dequantizing a quantized Tensor
  9331. Args:
  9332. tensor (Tensor): A quantized Tensor
  9333. .. function:: dequantize(tensors) -> sequence of Tensors
  9334. :noindex:
  9335. Given a list of quantized Tensors, dequantize them and return a list of fp32 Tensors
  9336. Args:
  9337. tensors (sequence of Tensors): A list of quantized Tensors
  9338. """
  9339. def det(input: Tensor) -> Tensor:
  9340. r"""
  9341. det(input) -> Tensor
  9342. Alias for :func:`torch.linalg.det`
  9343. """
  9344. def detach(input: Tensor) -> Tensor: ...
  9345. def detach_(input: Tensor) -> Tensor: ...
  9346. def detach_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  9347. r"""
  9348. Performs the same operation as :func:`torch.detach`, but all output tensors
  9349. are freshly created instead of aliasing the input.
  9350. """
  9351. def diag(
  9352. input: Tensor,
  9353. diagonal: _int = 0,
  9354. *,
  9355. out: Tensor | None = None,
  9356. ) -> Tensor:
  9357. r"""
  9358. diag(input, diagonal=0, *, out=None) -> Tensor
  9359. - If :attr:`input` is a vector (1-D tensor), then returns a 2-D square tensor
  9360. with the elements of :attr:`input` as the diagonal.
  9361. - If :attr:`input` is a matrix (2-D tensor), then returns a 1-D tensor with
  9362. the diagonal elements of :attr:`input`.
  9363. The argument :attr:`diagonal` controls which diagonal to consider:
  9364. - If :attr:`diagonal` = 0, it is the main diagonal.
  9365. - If :attr:`diagonal` > 0, it is above the main diagonal.
  9366. - If :attr:`diagonal` < 0, it is below the main diagonal.
  9367. Args:
  9368. input (Tensor): the input tensor.
  9369. diagonal (int, optional): the diagonal to consider
  9370. Keyword args:
  9371. out (Tensor, optional): the output tensor.
  9372. .. seealso::
  9373. :func:`torch.diagonal` always returns the diagonal of its input.
  9374. :func:`torch.diagflat` always constructs a tensor with diagonal elements
  9375. specified by the input.
  9376. Examples:
  9377. Get the square matrix where the input vector is the diagonal::
  9378. >>> a = torch.randn(3)
  9379. >>> a
  9380. tensor([ 0.5950,-0.0872, 2.3298])
  9381. >>> torch.diag(a)
  9382. tensor([[ 0.5950, 0.0000, 0.0000],
  9383. [ 0.0000,-0.0872, 0.0000],
  9384. [ 0.0000, 0.0000, 2.3298]])
  9385. >>> torch.diag(a, 1)
  9386. tensor([[ 0.0000, 0.5950, 0.0000, 0.0000],
  9387. [ 0.0000, 0.0000,-0.0872, 0.0000],
  9388. [ 0.0000, 0.0000, 0.0000, 2.3298],
  9389. [ 0.0000, 0.0000, 0.0000, 0.0000]])
  9390. Get the k-th diagonal of a given matrix::
  9391. >>> a = torch.randn(3, 3)
  9392. >>> a
  9393. tensor([[-0.4264, 0.0255,-0.1064],
  9394. [ 0.8795,-0.2429, 0.1374],
  9395. [ 0.1029,-0.6482,-1.6300]])
  9396. >>> torch.diag(a, 0)
  9397. tensor([-0.4264,-0.2429,-1.6300])
  9398. >>> torch.diag(a, 1)
  9399. tensor([ 0.0255, 0.1374])
  9400. """
  9401. def diag_embed(
  9402. input: Tensor,
  9403. offset: _int = 0,
  9404. dim1: _int = -2,
  9405. dim2: _int = -1,
  9406. ) -> Tensor:
  9407. r"""
  9408. diag_embed(input, offset=0, dim1=-2, dim2=-1) -> Tensor
  9409. Creates a tensor whose diagonals of certain 2D planes (specified by
  9410. :attr:`dim1` and :attr:`dim2`) are filled by :attr:`input`.
  9411. To facilitate creating batched diagonal matrices, the 2D planes formed by
  9412. the last two dimensions of the returned tensor are chosen by default.
  9413. The argument :attr:`offset` controls which diagonal to consider:
  9414. - If :attr:`offset` = 0, it is the main diagonal.
  9415. - If :attr:`offset` > 0, it is above the main diagonal.
  9416. - If :attr:`offset` < 0, it is below the main diagonal.
  9417. The size of the new matrix will be calculated to make the specified diagonal
  9418. of the size of the last input dimension.
  9419. Note that for :attr:`offset` other than :math:`0`, the order of :attr:`dim1`
  9420. and :attr:`dim2` matters. Exchanging them is equivalent to changing the
  9421. sign of :attr:`offset`.
  9422. Applying :meth:`torch.diagonal` to the output of this function with
  9423. the same arguments yields a matrix identical to input. However,
  9424. :meth:`torch.diagonal` has different default dimensions, so those
  9425. need to be explicitly specified.
  9426. Args:
  9427. input (Tensor): the input tensor. Must be at least 1-dimensional.
  9428. offset (int, optional): which diagonal to consider. Default: 0
  9429. (main diagonal).
  9430. dim1 (int, optional): first dimension with respect to which to
  9431. take diagonal. Default: -2.
  9432. dim2 (int, optional): second dimension with respect to which to
  9433. take diagonal. Default: -1.
  9434. Example::
  9435. >>> a = torch.randn(2, 3)
  9436. >>> torch.diag_embed(a)
  9437. tensor([[[ 1.5410, 0.0000, 0.0000],
  9438. [ 0.0000, -0.2934, 0.0000],
  9439. [ 0.0000, 0.0000, -2.1788]],
  9440. [[ 0.5684, 0.0000, 0.0000],
  9441. [ 0.0000, -1.0845, 0.0000],
  9442. [ 0.0000, 0.0000, -1.3986]]])
  9443. >>> torch.diag_embed(a, offset=1, dim1=0, dim2=2)
  9444. tensor([[[ 0.0000, 1.5410, 0.0000, 0.0000],
  9445. [ 0.0000, 0.5684, 0.0000, 0.0000]],
  9446. [[ 0.0000, 0.0000, -0.2934, 0.0000],
  9447. [ 0.0000, 0.0000, -1.0845, 0.0000]],
  9448. [[ 0.0000, 0.0000, 0.0000, -2.1788],
  9449. [ 0.0000, 0.0000, 0.0000, -1.3986]],
  9450. [[ 0.0000, 0.0000, 0.0000, 0.0000],
  9451. [ 0.0000, 0.0000, 0.0000, 0.0000]]])
  9452. """
  9453. def diagflat(input: Tensor, offset: _int = 0) -> Tensor:
  9454. r"""
  9455. diagflat(input, offset=0) -> Tensor
  9456. - If :attr:`input` is a vector (1-D tensor), then returns a 2-D square tensor
  9457. with the elements of :attr:`input` as the diagonal.
  9458. - If :attr:`input` is a tensor with more than one dimension, then returns a
  9459. 2-D tensor with diagonal elements equal to a flattened :attr:`input`.
  9460. The argument :attr:`offset` controls which diagonal to consider:
  9461. - If :attr:`offset` = 0, it is the main diagonal.
  9462. - If :attr:`offset` > 0, it is above the main diagonal.
  9463. - If :attr:`offset` < 0, it is below the main diagonal.
  9464. Args:
  9465. input (Tensor): the input tensor.
  9466. offset (int, optional): the diagonal to consider. Default: 0 (main
  9467. diagonal).
  9468. Examples::
  9469. >>> a = torch.randn(3)
  9470. >>> a
  9471. tensor([-0.2956, -0.9068, 0.1695])
  9472. >>> torch.diagflat(a)
  9473. tensor([[-0.2956, 0.0000, 0.0000],
  9474. [ 0.0000, -0.9068, 0.0000],
  9475. [ 0.0000, 0.0000, 0.1695]])
  9476. >>> torch.diagflat(a, 1)
  9477. tensor([[ 0.0000, -0.2956, 0.0000, 0.0000],
  9478. [ 0.0000, 0.0000, -0.9068, 0.0000],
  9479. [ 0.0000, 0.0000, 0.0000, 0.1695],
  9480. [ 0.0000, 0.0000, 0.0000, 0.0000]])
  9481. >>> a = torch.randn(2, 2)
  9482. >>> a
  9483. tensor([[ 0.2094, -0.3018],
  9484. [-0.1516, 1.9342]])
  9485. >>> torch.diagflat(a)
  9486. tensor([[ 0.2094, 0.0000, 0.0000, 0.0000],
  9487. [ 0.0000, -0.3018, 0.0000, 0.0000],
  9488. [ 0.0000, 0.0000, -0.1516, 0.0000],
  9489. [ 0.0000, 0.0000, 0.0000, 1.9342]])
  9490. """
  9491. @overload
  9492. def diagonal(
  9493. input: Tensor,
  9494. offset: _int = 0,
  9495. dim1: _int = 0,
  9496. dim2: _int = 1,
  9497. ) -> Tensor:
  9498. r"""
  9499. diagonal(input, offset=0, dim1=0, dim2=1) -> Tensor
  9500. Returns a partial view of :attr:`input` with the its diagonal elements
  9501. with respect to :attr:`dim1` and :attr:`dim2` appended as a dimension
  9502. at the end of the shape.
  9503. The argument :attr:`offset` controls which diagonal to consider:
  9504. - If :attr:`offset` = 0, it is the main diagonal.
  9505. - If :attr:`offset` > 0, it is above the main diagonal.
  9506. - If :attr:`offset` < 0, it is below the main diagonal.
  9507. Applying :meth:`torch.diag_embed` to the output of this function with
  9508. the same arguments yields a diagonal matrix with the diagonal entries
  9509. of the input. However, :meth:`torch.diag_embed` has different default
  9510. dimensions, so those need to be explicitly specified.
  9511. Args:
  9512. input (Tensor): the input tensor. Must be at least 2-dimensional.
  9513. offset (int, optional): which diagonal to consider. Default: 0
  9514. (main diagonal).
  9515. dim1 (int, optional): first dimension with respect to which to
  9516. take diagonal. Default: 0.
  9517. dim2 (int, optional): second dimension with respect to which to
  9518. take diagonal. Default: 1.
  9519. .. note:: To take a batch diagonal, pass in dim1=-2, dim2=-1.
  9520. Examples::
  9521. >>> a = torch.randn(3, 3)
  9522. >>> a
  9523. tensor([[-1.0854, 1.1431, -0.1752],
  9524. [ 0.8536, -0.0905, 0.0360],
  9525. [ 0.6927, -0.3735, -0.4945]])
  9526. >>> torch.diagonal(a)
  9527. tensor([-1.0854, -0.0905, -0.4945])
  9528. >>> torch.diagonal(a, 1)
  9529. tensor([ 1.1431, 0.0360])
  9530. >>> b = torch.randn(2, 5)
  9531. >>> b
  9532. tensor([[-1.7948, -1.2731, -0.3181, 2.0200, -1.6745],
  9533. [ 1.8262, -1.5049, 0.4114, 1.0704, -1.2607]])
  9534. >>> torch.diagonal(b, 1, 1, 0)
  9535. tensor([1.8262])
  9536. >>> x = torch.randn(2, 5, 4, 2)
  9537. >>> torch.diagonal(x, offset=-1, dim1=1, dim2=2)
  9538. tensor([[[-1.2631, 0.3755, -1.5977, -1.8172],
  9539. [-1.1065, 1.0401, -0.2235, -0.7938]],
  9540. [[-1.7325, -0.3081, 0.6166, 0.2335],
  9541. [ 1.0500, 0.7336, -0.3836, -1.1015]]])
  9542. """
  9543. @overload
  9544. def diagonal(
  9545. input: Tensor,
  9546. *,
  9547. outdim: str | EllipsisType | None,
  9548. dim1: str | EllipsisType | None,
  9549. dim2: str | EllipsisType | None,
  9550. offset: _int = 0,
  9551. ) -> Tensor:
  9552. r"""
  9553. diagonal(input, offset=0, dim1=0, dim2=1) -> Tensor
  9554. Returns a partial view of :attr:`input` with the its diagonal elements
  9555. with respect to :attr:`dim1` and :attr:`dim2` appended as a dimension
  9556. at the end of the shape.
  9557. The argument :attr:`offset` controls which diagonal to consider:
  9558. - If :attr:`offset` = 0, it is the main diagonal.
  9559. - If :attr:`offset` > 0, it is above the main diagonal.
  9560. - If :attr:`offset` < 0, it is below the main diagonal.
  9561. Applying :meth:`torch.diag_embed` to the output of this function with
  9562. the same arguments yields a diagonal matrix with the diagonal entries
  9563. of the input. However, :meth:`torch.diag_embed` has different default
  9564. dimensions, so those need to be explicitly specified.
  9565. Args:
  9566. input (Tensor): the input tensor. Must be at least 2-dimensional.
  9567. offset (int, optional): which diagonal to consider. Default: 0
  9568. (main diagonal).
  9569. dim1 (int, optional): first dimension with respect to which to
  9570. take diagonal. Default: 0.
  9571. dim2 (int, optional): second dimension with respect to which to
  9572. take diagonal. Default: 1.
  9573. .. note:: To take a batch diagonal, pass in dim1=-2, dim2=-1.
  9574. Examples::
  9575. >>> a = torch.randn(3, 3)
  9576. >>> a
  9577. tensor([[-1.0854, 1.1431, -0.1752],
  9578. [ 0.8536, -0.0905, 0.0360],
  9579. [ 0.6927, -0.3735, -0.4945]])
  9580. >>> torch.diagonal(a)
  9581. tensor([-1.0854, -0.0905, -0.4945])
  9582. >>> torch.diagonal(a, 1)
  9583. tensor([ 1.1431, 0.0360])
  9584. >>> b = torch.randn(2, 5)
  9585. >>> b
  9586. tensor([[-1.7948, -1.2731, -0.3181, 2.0200, -1.6745],
  9587. [ 1.8262, -1.5049, 0.4114, 1.0704, -1.2607]])
  9588. >>> torch.diagonal(b, 1, 1, 0)
  9589. tensor([1.8262])
  9590. >>> x = torch.randn(2, 5, 4, 2)
  9591. >>> torch.diagonal(x, offset=-1, dim1=1, dim2=2)
  9592. tensor([[[-1.2631, 0.3755, -1.5977, -1.8172],
  9593. [-1.1065, 1.0401, -0.2235, -0.7938]],
  9594. [[-1.7325, -0.3081, 0.6166, 0.2335],
  9595. [ 1.0500, 0.7336, -0.3836, -1.1015]]])
  9596. """
  9597. def diagonal_copy(
  9598. input: Tensor,
  9599. offset: _int = 0,
  9600. dim1: _int = 0,
  9601. dim2: _int = 1,
  9602. *,
  9603. out: Tensor | None = None,
  9604. ) -> Tensor:
  9605. r"""
  9606. Performs the same operation as :func:`torch.diagonal`, but all output tensors
  9607. are freshly created instead of aliasing the input.
  9608. """
  9609. def diagonal_scatter(
  9610. input: Tensor,
  9611. src: Tensor,
  9612. offset: _int = 0,
  9613. dim1: _int = 0,
  9614. dim2: _int = 1,
  9615. ) -> Tensor:
  9616. r"""
  9617. diagonal_scatter(input, src, offset=0, dim1=0, dim2=1) -> Tensor
  9618. Embeds the values of the :attr:`src` tensor into :attr:`input` along
  9619. the diagonal elements of :attr:`input`, with respect to :attr:`dim1`
  9620. and :attr:`dim2`.
  9621. This function returns a tensor with fresh storage; it does not
  9622. return a view.
  9623. The argument :attr:`offset` controls which diagonal to consider:
  9624. - If :attr:`offset` = 0, it is the main diagonal.
  9625. - If :attr:`offset` > 0, it is above the main diagonal.
  9626. - If :attr:`offset` < 0, it is below the main diagonal.
  9627. Args:
  9628. input (Tensor): the input tensor. Must be at least 2-dimensional.
  9629. src (Tensor): the tensor to embed into :attr:`input`.
  9630. offset (int, optional): which diagonal to consider. Default: 0
  9631. (main diagonal).
  9632. dim1 (int, optional): first dimension with respect to which to
  9633. take diagonal. Default: 0.
  9634. dim2 (int, optional): second dimension with respect to which to
  9635. take diagonal. Default: 1.
  9636. .. note::
  9637. :attr:`src` must be of the proper size in order to be embedded
  9638. into :attr:`input`. Specifically, it should have the same shape as
  9639. ``torch.diagonal(input, offset, dim1, dim2)``
  9640. Examples::
  9641. >>> a = torch.zeros(3, 3)
  9642. >>> a
  9643. tensor([[0., 0., 0.],
  9644. [0., 0., 0.],
  9645. [0., 0., 0.]])
  9646. >>> torch.diagonal_scatter(a, torch.ones(3), 0)
  9647. tensor([[1., 0., 0.],
  9648. [0., 1., 0.],
  9649. [0., 0., 1.]])
  9650. >>> torch.diagonal_scatter(a, torch.ones(2), 1)
  9651. tensor([[0., 1., 0.],
  9652. [0., 0., 1.],
  9653. [0., 0., 0.]])
  9654. """
  9655. def diff(
  9656. input: Tensor,
  9657. n: _int = 1,
  9658. dim: _int = -1,
  9659. prepend: Tensor | None = None,
  9660. append: Tensor | None = None,
  9661. *,
  9662. out: Tensor | None = None,
  9663. ) -> Tensor:
  9664. r"""
  9665. diff(input, n=1, dim=-1, prepend=None, append=None) -> Tensor
  9666. Computes the n-th forward difference along the given dimension.
  9667. The first-order differences are given by `out[i] = input[i + 1] - input[i]`. Higher-order
  9668. differences are calculated by using :func:`torch.diff` recursively.
  9669. Args:
  9670. input (Tensor): the tensor to compute the differences on
  9671. n (int, optional): the number of times to recursively compute the difference
  9672. dim (int, optional): the dimension to compute the difference along.
  9673. Default is the last dimension.
  9674. prepend, append (Tensor, optional): values to prepend or append to
  9675. :attr:`input` along :attr:`dim` before computing the difference.
  9676. Their dimensions must be equivalent to that of input, and their shapes
  9677. must match input's shape except on :attr:`dim`.
  9678. Keyword args:
  9679. out (Tensor, optional): the output tensor.
  9680. Example::
  9681. >>> a = torch.tensor([1, 3, 2])
  9682. >>> torch.diff(a)
  9683. tensor([ 2, -1])
  9684. >>> b = torch.tensor([4, 5])
  9685. >>> torch.diff(a, append=b)
  9686. tensor([ 2, -1, 2, 1])
  9687. >>> c = torch.tensor([[1, 2, 3], [3, 4, 5]])
  9688. >>> torch.diff(c, dim=0)
  9689. tensor([[2, 2, 2]])
  9690. >>> torch.diff(c, dim=1)
  9691. tensor([[1, 1],
  9692. [1, 1]])
  9693. """
  9694. def digamma(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  9695. r"""
  9696. digamma(input, *, out=None) -> Tensor
  9697. Alias for :func:`torch.special.digamma`.
  9698. """
  9699. def dist(input: Tensor, other: Tensor, p: Number | _complex = 2) -> Tensor:
  9700. r"""
  9701. dist(input, other, p=2) -> Tensor
  9702. Returns the p-norm of (:attr:`input` - :attr:`other`)
  9703. The shapes of :attr:`input` and :attr:`other` must be
  9704. :ref:`broadcastable <broadcasting-semantics>`.
  9705. Args:
  9706. input (Tensor): the input tensor.
  9707. other (Tensor): the Right-hand-side input tensor
  9708. p (float, optional): the norm to be computed
  9709. Example::
  9710. >>> x = torch.randn(4)
  9711. >>> x
  9712. tensor([-1.5393, -0.8675, 0.5916, 1.6321])
  9713. >>> y = torch.randn(4)
  9714. >>> y
  9715. tensor([ 0.0967, -1.0511, 0.6295, 0.8360])
  9716. >>> torch.dist(x, y, 3.5)
  9717. tensor(1.6727)
  9718. >>> torch.dist(x, y, 3)
  9719. tensor(1.6973)
  9720. >>> torch.dist(x, y, 0)
  9721. tensor(4.)
  9722. >>> torch.dist(x, y, 1)
  9723. tensor(2.6537)
  9724. """
  9725. def div(
  9726. input: Tensor | Number,
  9727. other: Tensor | Number,
  9728. *,
  9729. rounding_mode: str | None = None,
  9730. out: Tensor | None = None,
  9731. ) -> Tensor:
  9732. r"""
  9733. div(input, other, *, rounding_mode=None, out=None) -> Tensor
  9734. Divides each element of the input ``input`` by the corresponding element of
  9735. :attr:`other`.
  9736. .. math::
  9737. \text{out}_i = \frac{\text{input}_i}{\text{other}_i}
  9738. .. note::
  9739. By default, this performs a "true" division like Python 3.
  9740. See the :attr:`rounding_mode` argument for floor division.
  9741. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  9742. :ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
  9743. Always promotes integer types to the default scalar type.
  9744. Args:
  9745. input (Tensor): the dividend
  9746. other (Tensor or Number): the divisor
  9747. Keyword args:
  9748. rounding_mode (str, optional): Type of rounding applied to the result:
  9749. * None - default behavior. Performs no rounding and, if both :attr:`input` and
  9750. :attr:`other` are integer types, promotes the inputs to the default scalar type.
  9751. Equivalent to true division in Python (the ``/`` operator) and NumPy's ``np.true_divide``.
  9752. * ``"trunc"`` - rounds the results of the division towards zero.
  9753. Equivalent to C-style integer division.
  9754. * ``"floor"`` - rounds the results of the division down.
  9755. Equivalent to floor division in Python (the ``//`` operator) and NumPy's ``np.floor_divide``.
  9756. out (Tensor, optional): the output tensor.
  9757. Examples::
  9758. >>> x = torch.tensor([ 0.3810, 1.2774, -0.2972, -0.3719, 0.4637])
  9759. >>> torch.div(x, 0.5)
  9760. tensor([ 0.7620, 2.5548, -0.5944, -0.7438, 0.9274])
  9761. >>> a = torch.tensor([[-0.3711, -1.9353, -0.4605, -0.2917],
  9762. ... [ 0.1815, -1.0111, 0.9805, -1.5923],
  9763. ... [ 0.1062, 1.4581, 0.7759, -1.2344],
  9764. ... [-0.1830, -0.0313, 1.1908, -1.4757]])
  9765. >>> b = torch.tensor([ 0.8032, 0.2930, -0.8113, -0.2308])
  9766. >>> torch.div(a, b)
  9767. tensor([[-0.4620, -6.6051, 0.5676, 1.2639],
  9768. [ 0.2260, -3.4509, -1.2086, 6.8990],
  9769. [ 0.1322, 4.9764, -0.9564, 5.3484],
  9770. [-0.2278, -0.1068, -1.4678, 6.3938]])
  9771. >>> torch.div(a, b, rounding_mode='trunc')
  9772. tensor([[-0., -6., 0., 1.],
  9773. [ 0., -3., -1., 6.],
  9774. [ 0., 4., -0., 5.],
  9775. [-0., -0., -1., 6.]])
  9776. >>> torch.div(a, b, rounding_mode='floor')
  9777. tensor([[-1., -7., 0., 1.],
  9778. [ 0., -4., -2., 6.],
  9779. [ 0., 4., -1., 5.],
  9780. [-1., -1., -2., 6.]])
  9781. """
  9782. @overload
  9783. def divide(
  9784. input: Tensor,
  9785. other: Tensor,
  9786. *,
  9787. out: Tensor | None = None,
  9788. ) -> Tensor:
  9789. r"""
  9790. divide(input, other, *, rounding_mode=None, out=None) -> Tensor
  9791. Alias for :func:`torch.div`.
  9792. """
  9793. @overload
  9794. def divide(
  9795. input: Tensor,
  9796. other: Tensor,
  9797. *,
  9798. rounding_mode: str | None,
  9799. out: Tensor | None = None,
  9800. ) -> Tensor:
  9801. r"""
  9802. divide(input, other, *, rounding_mode=None, out=None) -> Tensor
  9803. Alias for :func:`torch.div`.
  9804. """
  9805. @overload
  9806. def divide(
  9807. input: Tensor,
  9808. other: Number | _complex,
  9809. *,
  9810. rounding_mode: str | None,
  9811. ) -> Tensor:
  9812. r"""
  9813. divide(input, other, *, rounding_mode=None, out=None) -> Tensor
  9814. Alias for :func:`torch.div`.
  9815. """
  9816. @overload
  9817. def divide(input: Tensor, other: Number | _complex) -> Tensor:
  9818. r"""
  9819. divide(input, other, *, rounding_mode=None, out=None) -> Tensor
  9820. Alias for :func:`torch.div`.
  9821. """
  9822. def dot(
  9823. input: Tensor,
  9824. tensor: Tensor,
  9825. *,
  9826. out: Tensor | None = None,
  9827. ) -> Tensor:
  9828. r"""
  9829. dot(input, tensor, *, out=None) -> Tensor
  9830. Computes the dot product of two 1D tensors.
  9831. .. note::
  9832. Unlike NumPy's dot, torch.dot intentionally only supports computing the dot product
  9833. of two 1D tensors with the same number of elements.
  9834. Args:
  9835. input (Tensor): first tensor in the dot product, must be 1D.
  9836. tensor (Tensor): second tensor in the dot product, must be 1D.
  9837. Keyword args:
  9838. out (Tensor, optional): the output tensor.
  9839. Example::
  9840. >>> torch.dot(torch.tensor([2, 3]), torch.tensor([2, 1]))
  9841. tensor(7)
  9842. >>> t1, t2 = torch.tensor([0, 1]), torch.tensor([2, 3])
  9843. >>> torch.dot(t1, t2)
  9844. tensor(3)
  9845. """
  9846. def dropout(input: Tensor, p: _float, train: _bool) -> Tensor: ...
  9847. def dropout_(input: Tensor, p: _float, train: _bool) -> Tensor: ...
  9848. def dsmm(input: Tensor, mat2: Tensor) -> Tensor: ...
  9849. @overload
  9850. def dsplit(input: Tensor, sections: _int) -> tuple[Tensor, ...]:
  9851. r"""
  9852. dsplit(input, indices_or_sections) -> List of Tensors
  9853. Splits :attr:`input`, a tensor with three or more dimensions, into multiple tensors
  9854. depthwise according to :attr:`indices_or_sections`. Each split is a view of
  9855. :attr:`input`.
  9856. This is equivalent to calling torch.tensor_split(input, indices_or_sections, dim=2)
  9857. (the split dimension is 2), except that if :attr:`indices_or_sections` is an integer
  9858. it must evenly divide the split dimension or a runtime error will be thrown.
  9859. This function is based on NumPy's :func:`numpy.dsplit`.
  9860. Args:
  9861. input (Tensor): tensor to split.
  9862. indices_or_sections (int or list or tuple of ints): See argument in :func:`torch.tensor_split`.
  9863. Example::
  9864. >>> t = torch.arange(16.0).reshape(2, 2, 4)
  9865. >>> t
  9866. tensor([[[ 0., 1., 2., 3.],
  9867. [ 4., 5., 6., 7.]],
  9868. [[ 8., 9., 10., 11.],
  9869. [12., 13., 14., 15.]]])
  9870. >>> torch.dsplit(t, 2)
  9871. (tensor([[[ 0., 1.],
  9872. [ 4., 5.]],
  9873. [[ 8., 9.],
  9874. [12., 13.]]]),
  9875. tensor([[[ 2., 3.],
  9876. [ 6., 7.]],
  9877. [[10., 11.],
  9878. [14., 15.]]]))
  9879. >>> torch.dsplit(t, [3, 6])
  9880. (tensor([[[ 0., 1., 2.],
  9881. [ 4., 5., 6.]],
  9882. [[ 8., 9., 10.],
  9883. [12., 13., 14.]]]),
  9884. tensor([[[ 3.],
  9885. [ 7.]],
  9886. [[11.],
  9887. [15.]]]),
  9888. tensor([], size=(2, 2, 0)))
  9889. """
  9890. @overload
  9891. def dsplit(input: Tensor, indices: _size) -> tuple[Tensor, ...]:
  9892. r"""
  9893. dsplit(input, indices_or_sections) -> List of Tensors
  9894. Splits :attr:`input`, a tensor with three or more dimensions, into multiple tensors
  9895. depthwise according to :attr:`indices_or_sections`. Each split is a view of
  9896. :attr:`input`.
  9897. This is equivalent to calling torch.tensor_split(input, indices_or_sections, dim=2)
  9898. (the split dimension is 2), except that if :attr:`indices_or_sections` is an integer
  9899. it must evenly divide the split dimension or a runtime error will be thrown.
  9900. This function is based on NumPy's :func:`numpy.dsplit`.
  9901. Args:
  9902. input (Tensor): tensor to split.
  9903. indices_or_sections (int or list or tuple of ints): See argument in :func:`torch.tensor_split`.
  9904. Example::
  9905. >>> t = torch.arange(16.0).reshape(2, 2, 4)
  9906. >>> t
  9907. tensor([[[ 0., 1., 2., 3.],
  9908. [ 4., 5., 6., 7.]],
  9909. [[ 8., 9., 10., 11.],
  9910. [12., 13., 14., 15.]]])
  9911. >>> torch.dsplit(t, 2)
  9912. (tensor([[[ 0., 1.],
  9913. [ 4., 5.]],
  9914. [[ 8., 9.],
  9915. [12., 13.]]]),
  9916. tensor([[[ 2., 3.],
  9917. [ 6., 7.]],
  9918. [[10., 11.],
  9919. [14., 15.]]]))
  9920. >>> torch.dsplit(t, [3, 6])
  9921. (tensor([[[ 0., 1., 2.],
  9922. [ 4., 5., 6.]],
  9923. [[ 8., 9., 10.],
  9924. [12., 13., 14.]]]),
  9925. tensor([[[ 3.],
  9926. [ 7.]],
  9927. [[11.],
  9928. [15.]]]),
  9929. tensor([], size=(2, 2, 0)))
  9930. """
  9931. def dstack(
  9932. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  9933. *,
  9934. out: Tensor | None = None,
  9935. ) -> Tensor:
  9936. r"""
  9937. dstack(tensors, *, out=None) -> Tensor
  9938. Stack tensors in sequence depthwise (along third axis).
  9939. This is equivalent to concatenation along the third axis after 1-D and 2-D tensors have been reshaped by :func:`torch.atleast_3d`.
  9940. Args:
  9941. tensors (sequence of Tensors): sequence of tensors to concatenate
  9942. Keyword args:
  9943. out (Tensor, optional): the output tensor.
  9944. Example::
  9945. >>> a = torch.tensor([1, 2, 3])
  9946. >>> b = torch.tensor([4, 5, 6])
  9947. >>> torch.dstack((a,b))
  9948. tensor([[[1, 4],
  9949. [2, 5],
  9950. [3, 6]]])
  9951. >>> a = torch.tensor([[1],[2],[3]])
  9952. >>> b = torch.tensor([[4],[5],[6]])
  9953. >>> torch.dstack((a,b))
  9954. tensor([[[1, 4]],
  9955. [[2, 5]],
  9956. [[3, 6]]])
  9957. """
  9958. def embedding(
  9959. weight: Tensor,
  9960. indices: Tensor,
  9961. padding_idx: _int | SymInt = -1,
  9962. scale_grad_by_freq: _bool = False,
  9963. sparse: _bool = False,
  9964. ) -> Tensor: ...
  9965. @overload
  9966. def embedding_bag(
  9967. weight: Tensor,
  9968. indices: Tensor,
  9969. offsets: Tensor,
  9970. scale_grad_by_freq: _bool,
  9971. mode: _int,
  9972. sparse: _bool,
  9973. per_sample_weights: Tensor | None,
  9974. include_last_offset: _bool,
  9975. padding_idx: _int | None,
  9976. ) -> tuple[Tensor, Tensor, Tensor, Tensor]: ...
  9977. @overload
  9978. def embedding_bag(
  9979. weight: Tensor,
  9980. indices: Tensor,
  9981. offsets: Tensor,
  9982. scale_grad_by_freq: _bool = False,
  9983. mode: _int = 0,
  9984. sparse: _bool = False,
  9985. per_sample_weights: Tensor | None = None,
  9986. include_last_offset: _bool = False,
  9987. ) -> tuple[Tensor, Tensor, Tensor, Tensor]: ...
  9988. def embedding_renorm_(
  9989. input: Tensor,
  9990. indices: Tensor,
  9991. max_norm: _float,
  9992. norm_type: _float,
  9993. ) -> Tensor: ...
  9994. @overload
  9995. def empty(
  9996. size: Sequence[_int | SymInt],
  9997. *,
  9998. memory_format: memory_format | None = None,
  9999. out: Tensor | None = None,
  10000. dtype: _dtype | None = None,
  10001. layout: _layout | None = None,
  10002. device: DeviceLikeType | None = None,
  10003. pin_memory: _bool | None = False,
  10004. requires_grad: _bool | None = False,
  10005. ) -> Tensor:
  10006. r"""
  10007. empty(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False, memory_format=torch.contiguous_format) -> Tensor
  10008. Returns a tensor filled with uninitialized data. The shape of the tensor is
  10009. defined by the variable argument :attr:`size`.
  10010. .. note::
  10011. If :func:`torch.use_deterministic_algorithms()` and
  10012. :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
  10013. ``True``, the output tensor is initialized to prevent any possible
  10014. nondeterministic behavior from using the data as an input to an operation.
  10015. Floating point and complex tensors are filled with NaN, and integer tensors
  10016. are filled with the maximum value.
  10017. Args:
  10018. size (int...): a sequence of integers defining the shape of the output tensor.
  10019. Can be a variable number of arguments or a collection like a list or tuple.
  10020. Keyword args:
  10021. out (Tensor, optional): the output tensor.
  10022. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  10023. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  10024. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  10025. Default: ``torch.strided``.
  10026. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10027. Default: if ``None``, uses the current device for the default tensor type
  10028. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  10029. for CPU tensor types and the current CUDA device for CUDA tensor types.
  10030. requires_grad (bool, optional): If autograd should record operations on the
  10031. returned tensor. Default: ``False``.
  10032. pin_memory (bool, optional): If set, returned tensor would be allocated in
  10033. the pinned memory. Works only for CPU tensors. Default: ``False``.
  10034. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  10035. returned Tensor. Default: ``torch.contiguous_format``.
  10036. Example::
  10037. >>> torch.empty((2,3), dtype=torch.int64)
  10038. tensor([[ 9.4064e+13, 2.8000e+01, 9.3493e+13],
  10039. [ 7.5751e+18, 7.1428e+18, 7.5955e+18]])
  10040. """
  10041. @overload
  10042. def empty(
  10043. *size: _int | SymInt,
  10044. memory_format: memory_format | None = None,
  10045. out: Tensor | None = None,
  10046. dtype: _dtype | None = None,
  10047. layout: _layout | None = None,
  10048. device: DeviceLikeType | None = None,
  10049. pin_memory: _bool | None = False,
  10050. requires_grad: _bool | None = False,
  10051. ) -> Tensor:
  10052. r"""
  10053. empty(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False, memory_format=torch.contiguous_format) -> Tensor
  10054. Returns a tensor filled with uninitialized data. The shape of the tensor is
  10055. defined by the variable argument :attr:`size`.
  10056. .. note::
  10057. If :func:`torch.use_deterministic_algorithms()` and
  10058. :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
  10059. ``True``, the output tensor is initialized to prevent any possible
  10060. nondeterministic behavior from using the data as an input to an operation.
  10061. Floating point and complex tensors are filled with NaN, and integer tensors
  10062. are filled with the maximum value.
  10063. Args:
  10064. size (int...): a sequence of integers defining the shape of the output tensor.
  10065. Can be a variable number of arguments or a collection like a list or tuple.
  10066. Keyword args:
  10067. out (Tensor, optional): the output tensor.
  10068. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  10069. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  10070. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  10071. Default: ``torch.strided``.
  10072. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10073. Default: if ``None``, uses the current device for the default tensor type
  10074. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  10075. for CPU tensor types and the current CUDA device for CUDA tensor types.
  10076. requires_grad (bool, optional): If autograd should record operations on the
  10077. returned tensor. Default: ``False``.
  10078. pin_memory (bool, optional): If set, returned tensor would be allocated in
  10079. the pinned memory. Works only for CPU tensors. Default: ``False``.
  10080. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  10081. returned Tensor. Default: ``torch.contiguous_format``.
  10082. Example::
  10083. >>> torch.empty((2,3), dtype=torch.int64)
  10084. tensor([[ 9.4064e+13, 2.8000e+01, 9.3493e+13],
  10085. [ 7.5751e+18, 7.1428e+18, 7.5955e+18]])
  10086. """
  10087. @overload
  10088. def empty(
  10089. size: _size,
  10090. *,
  10091. names: Sequence[str | EllipsisType | None] | None,
  10092. memory_format: memory_format | None = None,
  10093. dtype: _dtype | None = None,
  10094. layout: _layout | None = None,
  10095. device: DeviceLikeType | None = None,
  10096. pin_memory: _bool | None = False,
  10097. requires_grad: _bool | None = False,
  10098. ) -> Tensor:
  10099. r"""
  10100. empty(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False, memory_format=torch.contiguous_format) -> Tensor
  10101. Returns a tensor filled with uninitialized data. The shape of the tensor is
  10102. defined by the variable argument :attr:`size`.
  10103. .. note::
  10104. If :func:`torch.use_deterministic_algorithms()` and
  10105. :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
  10106. ``True``, the output tensor is initialized to prevent any possible
  10107. nondeterministic behavior from using the data as an input to an operation.
  10108. Floating point and complex tensors are filled with NaN, and integer tensors
  10109. are filled with the maximum value.
  10110. Args:
  10111. size (int...): a sequence of integers defining the shape of the output tensor.
  10112. Can be a variable number of arguments or a collection like a list or tuple.
  10113. Keyword args:
  10114. out (Tensor, optional): the output tensor.
  10115. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  10116. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  10117. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  10118. Default: ``torch.strided``.
  10119. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10120. Default: if ``None``, uses the current device for the default tensor type
  10121. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  10122. for CPU tensor types and the current CUDA device for CUDA tensor types.
  10123. requires_grad (bool, optional): If autograd should record operations on the
  10124. returned tensor. Default: ``False``.
  10125. pin_memory (bool, optional): If set, returned tensor would be allocated in
  10126. the pinned memory. Works only for CPU tensors. Default: ``False``.
  10127. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  10128. returned Tensor. Default: ``torch.contiguous_format``.
  10129. Example::
  10130. >>> torch.empty((2,3), dtype=torch.int64)
  10131. tensor([[ 9.4064e+13, 2.8000e+01, 9.3493e+13],
  10132. [ 7.5751e+18, 7.1428e+18, 7.5955e+18]])
  10133. """
  10134. @overload
  10135. def empty(
  10136. *size: _int,
  10137. names: Sequence[str | EllipsisType | None] | None,
  10138. memory_format: memory_format | None = None,
  10139. dtype: _dtype | None = None,
  10140. layout: _layout | None = None,
  10141. device: DeviceLikeType | None = None,
  10142. pin_memory: _bool | None = False,
  10143. requires_grad: _bool | None = False,
  10144. ) -> Tensor:
  10145. r"""
  10146. empty(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False, memory_format=torch.contiguous_format) -> Tensor
  10147. Returns a tensor filled with uninitialized data. The shape of the tensor is
  10148. defined by the variable argument :attr:`size`.
  10149. .. note::
  10150. If :func:`torch.use_deterministic_algorithms()` and
  10151. :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
  10152. ``True``, the output tensor is initialized to prevent any possible
  10153. nondeterministic behavior from using the data as an input to an operation.
  10154. Floating point and complex tensors are filled with NaN, and integer tensors
  10155. are filled with the maximum value.
  10156. Args:
  10157. size (int...): a sequence of integers defining the shape of the output tensor.
  10158. Can be a variable number of arguments or a collection like a list or tuple.
  10159. Keyword args:
  10160. out (Tensor, optional): the output tensor.
  10161. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  10162. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  10163. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  10164. Default: ``torch.strided``.
  10165. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10166. Default: if ``None``, uses the current device for the default tensor type
  10167. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  10168. for CPU tensor types and the current CUDA device for CUDA tensor types.
  10169. requires_grad (bool, optional): If autograd should record operations on the
  10170. returned tensor. Default: ``False``.
  10171. pin_memory (bool, optional): If set, returned tensor would be allocated in
  10172. the pinned memory. Works only for CPU tensors. Default: ``False``.
  10173. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  10174. returned Tensor. Default: ``torch.contiguous_format``.
  10175. Example::
  10176. >>> torch.empty((2,3), dtype=torch.int64)
  10177. tensor([[ 9.4064e+13, 2.8000e+01, 9.3493e+13],
  10178. [ 7.5751e+18, 7.1428e+18, 7.5955e+18]])
  10179. """
  10180. def empty_like(
  10181. input: Tensor,
  10182. *,
  10183. memory_format: memory_format | None = None,
  10184. dtype: _dtype | None = None,
  10185. layout: _layout | None = None,
  10186. device: DeviceLikeType | None = None,
  10187. pin_memory: _bool | None = False,
  10188. requires_grad: _bool | None = False,
  10189. ) -> Tensor:
  10190. r"""
  10191. empty_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  10192. Returns an uninitialized tensor with the same size as :attr:`input`.
  10193. ``torch.empty_like(input)`` is equivalent to
  10194. ``torch.empty(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
  10195. .. note::
  10196. If :func:`torch.use_deterministic_algorithms()` and
  10197. :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
  10198. ``True``, the output tensor is initialized to prevent any possible
  10199. nondeterministic behavior from using the data as an input to an operation.
  10200. Floating point and complex tensors are filled with NaN, and integer tensors
  10201. are filled with the maximum value.
  10202. When ``torch.preserve_format`` is used:
  10203. If the input tensor is dense (i.e., non-overlapping strided),
  10204. its memory format (including strides) is retained.
  10205. Otherwise (e.g., a non-dense view like a stepped slice),
  10206. the output is converted to the dense format.
  10207. Args:
  10208. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  10209. Keyword args:
  10210. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  10211. Default: if ``None``, defaults to the dtype of :attr:`input`.
  10212. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  10213. Default: if ``None``, defaults to the layout of :attr:`input`.
  10214. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10215. Default: if ``None``, defaults to the device of :attr:`input`.
  10216. requires_grad (bool, optional): If autograd should record operations on the
  10217. returned tensor. Default: ``False``.
  10218. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  10219. returned Tensor. Default: ``torch.preserve_format``.
  10220. Example::
  10221. >>> a=torch.empty((2,3), dtype=torch.int32, device = 'cuda')
  10222. >>> torch.empty_like(a)
  10223. tensor([[0, 0, 0],
  10224. [0, 0, 0]], device='cuda:0', dtype=torch.int32)
  10225. """
  10226. def empty_permuted(
  10227. size: Sequence[_int | SymInt],
  10228. physical_layout: _size,
  10229. *,
  10230. dtype: _dtype | None = None,
  10231. layout: _layout | None = None,
  10232. device: DeviceLikeType | None = None,
  10233. pin_memory: _bool | None = False,
  10234. requires_grad: _bool | None = False,
  10235. ) -> Tensor:
  10236. r"""
  10237. empty_permuted(size, physical_layout, *, dtype=None, layout=None, device=None, requires_grad=False, pin_memory=False) -> Tensor
  10238. Creates an uninitialized, non-overlapping and dense tensor with the
  10239. specified :attr:`size`, with :attr:`physical_layout` specifying how the
  10240. dimensions are physically laid out in memory (each logical dimension is listed
  10241. from outermost to innermost). :attr:`physical_layout` is a generalization
  10242. of NCHW/NHWC notation: if each dimension is assigned a number according to
  10243. what order they occur in size (N=0, C=1, H=2, W=3), then NCHW is ``(0, 1, 2, 3)``
  10244. while NHWC is ``(0, 2, 3, 1)``. Equivalently, the strides of the output
  10245. tensor ``t`` are such that ``t.stride(physical_layout[i]) == contiguous_strides[i]``
  10246. (notably, this function is *not* equivalent to ``torch.empty(size).permute(physical_layout)``).
  10247. Unlike :func:`torch.empty_strided`, this is guaranteed to produce a dense
  10248. tensor with no overlaps. If possible, prefer using this function over
  10249. :func:`torch.empty_strided` or manual use of :func:`torch.as_strided`.
  10250. .. note::
  10251. If :func:`torch.use_deterministic_algorithms()` and
  10252. :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
  10253. ``True``, the output tensor is initialized to prevent any possible
  10254. nondeterministic behavior from using the data as an input to an operation.
  10255. Floating point and complex tensors are filled with NaN, and integer tensors
  10256. are filled with the maximum value.
  10257. Args:
  10258. size (tuple of int): the shape of the output tensor
  10259. physical_layout (tuple of int): the ordering of dimensions physically in memory
  10260. Keyword args:
  10261. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  10262. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  10263. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  10264. Default: ``torch.strided``.
  10265. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10266. Default: if ``None``, uses the current device for the default tensor type
  10267. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  10268. for CPU tensor types and the current CUDA device for CUDA tensor types.
  10269. requires_grad (bool, optional): If autograd should record operations on the
  10270. returned tensor. Default: ``False``.
  10271. pin_memory (bool, optional): If set, returned tensor would be allocated in
  10272. the pinned memory. Works only for CPU tensors. Default: ``False``.
  10273. Examples:
  10274. >>> torch.empty((2, 3, 5, 7)).stride()
  10275. (105, 35, 7, 1)
  10276. >>> torch.empty_permuted((2, 3, 5, 7), (0, 1, 2, 3)).stride()
  10277. (105, 35, 7, 1)
  10278. >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).stride()
  10279. (105, 1, 21, 3)
  10280. >>> torch.empty_permuted((2, 3, 5, 7), (0, 2, 3, 1)).stride()
  10281. (105, 1, 21, 3)
  10282. >>> torch.empty_permuted((2, 3, 5, 7), (0, 2, 3, 1)).dim_order()
  10283. (0, 2, 3, 1)
  10284. """
  10285. def empty_quantized(
  10286. size: _size,
  10287. qtensor: Tensor,
  10288. *,
  10289. memory_format: memory_format | None = None,
  10290. dtype: _dtype | None = None,
  10291. layout: _layout | None = None,
  10292. device: DeviceLikeType | None = None,
  10293. pin_memory: _bool | None = False,
  10294. requires_grad: _bool | None = False,
  10295. ) -> Tensor: ...
  10296. def empty_strided(
  10297. size: Sequence[_int | SymInt],
  10298. stride: Sequence[_int | SymInt],
  10299. *,
  10300. dtype: _dtype | None = None,
  10301. layout: _layout | None = None,
  10302. device: DeviceLikeType | None = None,
  10303. pin_memory: _bool | None = False,
  10304. requires_grad: _bool | None = False,
  10305. ) -> Tensor:
  10306. r"""
  10307. empty_strided(size, stride, *, dtype=None, layout=None, device=None, requires_grad=False, pin_memory=False) -> Tensor
  10308. Creates a tensor with the specified :attr:`size` and :attr:`stride` and filled with undefined data.
  10309. .. warning::
  10310. If the constructed tensor is "overlapped" (with multiple indices referring to the same element
  10311. in memory) its behavior is undefined.
  10312. .. note::
  10313. If :func:`torch.use_deterministic_algorithms()` and
  10314. :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
  10315. ``True``, the output tensor is initialized to prevent any possible
  10316. nondeterministic behavior from using the data as an input to an operation.
  10317. Floating point and complex tensors are filled with NaN, and integer tensors
  10318. are filled with the maximum value.
  10319. Args:
  10320. size (tuple of int): the shape of the output tensor
  10321. stride (tuple of int): the strides of the output tensor
  10322. Keyword args:
  10323. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  10324. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  10325. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  10326. Default: ``torch.strided``.
  10327. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10328. Default: if ``None``, uses the current device for the default tensor type
  10329. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  10330. for CPU tensor types and the current CUDA device for CUDA tensor types.
  10331. requires_grad (bool, optional): If autograd should record operations on the
  10332. returned tensor. Default: ``False``.
  10333. pin_memory (bool, optional): If set, returned tensor would be allocated in
  10334. the pinned memory. Works only for CPU tensors. Default: ``False``.
  10335. Example::
  10336. >>> a = torch.empty_strided((2, 3), (1, 2))
  10337. >>> a
  10338. tensor([[8.9683e-44, 4.4842e-44, 5.1239e+07],
  10339. [0.0000e+00, 0.0000e+00, 3.0705e-41]])
  10340. >>> a.stride()
  10341. (1, 2)
  10342. >>> a.size()
  10343. torch.Size([2, 3])
  10344. """
  10345. @overload
  10346. def eq(
  10347. input: Tensor,
  10348. other: Tensor,
  10349. *,
  10350. out: Tensor | None = None,
  10351. ) -> Tensor:
  10352. r"""
  10353. eq(input, other, *, out=None) -> Tensor
  10354. Computes element-wise equality
  10355. The second argument can be a number or a tensor whose shape is
  10356. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  10357. Args:
  10358. input (Tensor): the tensor to compare
  10359. other (Tensor or float): the tensor or value to compare
  10360. Keyword args:
  10361. out (Tensor, optional): the output tensor.
  10362. Returns:
  10363. A boolean tensor that is True where :attr:`input` is equal to :attr:`other` and False elsewhere
  10364. Example::
  10365. >>> torch.eq(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  10366. tensor([[ True, False],
  10367. [False, True]])
  10368. """
  10369. @overload
  10370. def eq(
  10371. input: Tensor,
  10372. other: Number | _complex,
  10373. *,
  10374. out: Tensor | None = None,
  10375. ) -> Tensor:
  10376. r"""
  10377. eq(input, other, *, out=None) -> Tensor
  10378. Computes element-wise equality
  10379. The second argument can be a number or a tensor whose shape is
  10380. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  10381. Args:
  10382. input (Tensor): the tensor to compare
  10383. other (Tensor or float): the tensor or value to compare
  10384. Keyword args:
  10385. out (Tensor, optional): the output tensor.
  10386. Returns:
  10387. A boolean tensor that is True where :attr:`input` is equal to :attr:`other` and False elsewhere
  10388. Example::
  10389. >>> torch.eq(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  10390. tensor([[ True, False],
  10391. [False, True]])
  10392. """
  10393. def equal(input: Tensor, other: Tensor) -> _bool:
  10394. r"""
  10395. equal(input, other) -> bool
  10396. ``True`` if two tensors have the same size and elements, ``False`` otherwise.
  10397. .. note::
  10398. Tensors containing NaNs are never equal to each other. Additionally, this function does not
  10399. differentiate between the data types of the tensors during comparison. For more thorough tensor checks,
  10400. use :meth:`torch.testing.assert_close`.
  10401. Example::
  10402. >>> torch.equal(torch.tensor([1, 2]), torch.tensor([1, 2]))
  10403. True
  10404. >>> torch.equal(torch.tensor([3, torch.nan]), torch.tensor([3, torch.nan]))
  10405. False
  10406. >>> torch.equal(torch.tensor([1, 2, 3], dtype=torch.int32), torch.tensor([1, 2, 3], dtype=torch.float32))
  10407. True
  10408. """
  10409. def erf(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  10410. r"""
  10411. erf(input, *, out=None) -> Tensor
  10412. Alias for :func:`torch.special.erf`.
  10413. """
  10414. def erf_(input: Tensor) -> Tensor: ...
  10415. def erfc(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  10416. r"""
  10417. erfc(input, *, out=None) -> Tensor
  10418. Alias for :func:`torch.special.erfc`.
  10419. """
  10420. def erfc_(input: Tensor) -> Tensor: ...
  10421. def erfinv(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  10422. r"""
  10423. erfinv(input, *, out=None) -> Tensor
  10424. Alias for :func:`torch.special.erfinv`.
  10425. """
  10426. def exp(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  10427. r"""
  10428. exp(input, *, out=None) -> Tensor
  10429. Returns a new tensor with the exponential of the elements
  10430. of the input tensor :attr:`input`.
  10431. .. math::
  10432. y_{i} = e^{x_{i}}
  10433. Args:
  10434. input (Tensor): the input tensor.
  10435. Keyword args:
  10436. out (Tensor, optional): the output tensor.
  10437. Example::
  10438. >>> torch.exp(torch.tensor([0, math.log(2.)]))
  10439. tensor([ 1., 2.])
  10440. """
  10441. def exp2(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  10442. r"""
  10443. exp2(input, *, out=None) -> Tensor
  10444. Alias for :func:`torch.special.exp2`.
  10445. """
  10446. def exp2_(input: Tensor) -> Tensor: ...
  10447. def exp_(input: Tensor) -> Tensor: ...
  10448. def expand_copy(
  10449. input: Tensor,
  10450. size: Sequence[_int | SymInt],
  10451. *,
  10452. implicit: _bool = False,
  10453. out: Tensor | None = None,
  10454. ) -> Tensor:
  10455. r"""
  10456. Performs the same operation as :func:`torch.Tensor.expand`, but all output tensors
  10457. are freshly created instead of aliasing the input.
  10458. """
  10459. def expm1(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  10460. r"""
  10461. expm1(input, *, out=None) -> Tensor
  10462. Alias for :func:`torch.special.expm1`.
  10463. """
  10464. def expm1_(input: Tensor) -> Tensor: ...
  10465. @overload
  10466. def eye(
  10467. n: _int | SymInt,
  10468. *,
  10469. out: Tensor | None = None,
  10470. dtype: _dtype | None = None,
  10471. layout: _layout | None = None,
  10472. device: DeviceLikeType | None = None,
  10473. pin_memory: _bool | None = False,
  10474. requires_grad: _bool | None = False,
  10475. ) -> Tensor:
  10476. r"""
  10477. eye(n, m=None, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  10478. Returns a 2-D tensor with ones on the diagonal and zeros elsewhere.
  10479. Args:
  10480. n (int): the number of rows
  10481. m (int, optional): the number of columns with default being :attr:`n`
  10482. Keyword arguments:
  10483. out (Tensor, optional): the output tensor.
  10484. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  10485. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  10486. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  10487. Default: ``torch.strided``.
  10488. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10489. Default: if ``None``, uses the current device for the default tensor type
  10490. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  10491. for CPU tensor types and the current CUDA device for CUDA tensor types.
  10492. requires_grad (bool, optional): If autograd should record operations on the
  10493. returned tensor. Default: ``False``.
  10494. Returns:
  10495. Tensor: A 2-D tensor with ones on the diagonal and zeros elsewhere
  10496. Example::
  10497. >>> torch.eye(3)
  10498. tensor([[ 1., 0., 0.],
  10499. [ 0., 1., 0.],
  10500. [ 0., 0., 1.]])
  10501. """
  10502. @overload
  10503. def eye(
  10504. n: _int | SymInt,
  10505. m: _int | SymInt,
  10506. *,
  10507. out: Tensor | None = None,
  10508. dtype: _dtype | None = None,
  10509. layout: _layout | None = None,
  10510. device: DeviceLikeType | None = None,
  10511. pin_memory: _bool | None = False,
  10512. requires_grad: _bool | None = False,
  10513. ) -> Tensor:
  10514. r"""
  10515. eye(n, m=None, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  10516. Returns a 2-D tensor with ones on the diagonal and zeros elsewhere.
  10517. Args:
  10518. n (int): the number of rows
  10519. m (int, optional): the number of columns with default being :attr:`n`
  10520. Keyword arguments:
  10521. out (Tensor, optional): the output tensor.
  10522. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  10523. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  10524. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  10525. Default: ``torch.strided``.
  10526. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10527. Default: if ``None``, uses the current device for the default tensor type
  10528. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  10529. for CPU tensor types and the current CUDA device for CUDA tensor types.
  10530. requires_grad (bool, optional): If autograd should record operations on the
  10531. returned tensor. Default: ``False``.
  10532. Returns:
  10533. Tensor: A 2-D tensor with ones on the diagonal and zeros elsewhere
  10534. Example::
  10535. >>> torch.eye(3)
  10536. tensor([[ 1., 0., 0.],
  10537. [ 0., 1., 0.],
  10538. [ 0., 0., 1.]])
  10539. """
  10540. def fake_quantize_per_channel_affine(
  10541. input: Tensor,
  10542. scale: Tensor,
  10543. zero_point: Tensor,
  10544. axis: _int,
  10545. quant_min: _int,
  10546. quant_max: _int,
  10547. ) -> Tensor:
  10548. r"""
  10549. fake_quantize_per_channel_affine(input, scale, zero_point, axis, quant_min, quant_max) -> Tensor
  10550. Returns a new tensor with the data in :attr:`input` fake quantized per channel using :attr:`scale`,
  10551. :attr:`zero_point`, :attr:`quant_min` and :attr:`quant_max`, across the channel specified by :attr:`axis`.
  10552. .. math::
  10553. \text{output} = (
  10554. min(
  10555. \text{quant\_max},
  10556. max(
  10557. \text{quant\_min},
  10558. \text{std::nearby\_int}(\text{input} / \text{scale}) + \text{zero\_point}
  10559. )
  10560. ) - \text{zero\_point}
  10561. ) \times \text{scale}
  10562. Args:
  10563. input (Tensor): the input value(s), in ``torch.float32``
  10564. scale (Tensor): quantization scale, per channel in ``torch.float32``
  10565. zero_point (Tensor): quantization zero_point, per channel in ``torch.int32`` or ``torch.half`` or ``torch.float32``
  10566. axis (int32): channel axis
  10567. quant_min (int64): lower bound of the quantized domain
  10568. quant_max (int64): upper bound of the quantized domain
  10569. Returns:
  10570. Tensor: A newly fake_quantized per channel ``torch.float32`` tensor
  10571. Example::
  10572. >>> x = torch.randn(2, 2, 2)
  10573. >>> x
  10574. tensor([[[-0.2525, -0.0466],
  10575. [ 0.3491, -0.2168]],
  10576. [[-0.5906, 1.6258],
  10577. [ 0.6444, -0.0542]]])
  10578. >>> scales = (torch.randn(2) + 1) * 0.05
  10579. >>> scales
  10580. tensor([0.0475, 0.0486])
  10581. >>> zero_points = torch.zeros(2).to(torch.int32)
  10582. >>> zero_points
  10583. tensor([0, 0])
  10584. >>> torch.fake_quantize_per_channel_affine(x, scales, zero_points, 1, 0, 255)
  10585. tensor([[[0.0000, 0.0000],
  10586. [0.3405, 0.0000]],
  10587. [[0.0000, 1.6134],
  10588. [0.6323, 0.0000]]])
  10589. """
  10590. @overload
  10591. def fake_quantize_per_tensor_affine(
  10592. input: Tensor,
  10593. scale: _float,
  10594. zero_point: _int,
  10595. quant_min: _int,
  10596. quant_max: _int,
  10597. ) -> Tensor:
  10598. r"""
  10599. fake_quantize_per_tensor_affine(input, scale, zero_point, quant_min, quant_max) -> Tensor
  10600. Returns a new tensor with the data in :attr:`input` fake quantized using :attr:`scale`,
  10601. :attr:`zero_point`, :attr:`quant_min` and :attr:`quant_max`.
  10602. .. math::
  10603. \text{output} = (
  10604. min(
  10605. \text{quant\_max},
  10606. max(
  10607. \text{quant\_min},
  10608. \text{std::nearby\_int}(\text{input} / \text{scale}) + \text{zero\_point}
  10609. )
  10610. ) - \text{zero\_point}
  10611. ) \times \text{scale}
  10612. Args:
  10613. input (Tensor): the input value(s), ``torch.float32`` tensor
  10614. scale (double scalar or ``float32`` Tensor): quantization scale
  10615. zero_point (int64 scalar or ``int32`` Tensor): quantization zero_point
  10616. quant_min (int64): lower bound of the quantized domain
  10617. quant_max (int64): upper bound of the quantized domain
  10618. Returns:
  10619. Tensor: A newly fake_quantized ``torch.float32`` tensor
  10620. Example::
  10621. >>> x = torch.randn(4)
  10622. >>> x
  10623. tensor([ 0.0552, 0.9730, 0.3973, -1.0780])
  10624. >>> torch.fake_quantize_per_tensor_affine(x, 0.1, 0, 0, 255)
  10625. tensor([0.1000, 1.0000, 0.4000, 0.0000])
  10626. >>> torch.fake_quantize_per_tensor_affine(x, torch.tensor(0.1), torch.tensor(0), 0, 255)
  10627. tensor([0.1000, 1.0000, 0.4000, 0.0000])
  10628. """
  10629. @overload
  10630. def fake_quantize_per_tensor_affine(
  10631. input: Tensor,
  10632. scale: Tensor,
  10633. zero_point: Tensor,
  10634. quant_min: _int,
  10635. quant_max: _int,
  10636. ) -> Tensor:
  10637. r"""
  10638. fake_quantize_per_tensor_affine(input, scale, zero_point, quant_min, quant_max) -> Tensor
  10639. Returns a new tensor with the data in :attr:`input` fake quantized using :attr:`scale`,
  10640. :attr:`zero_point`, :attr:`quant_min` and :attr:`quant_max`.
  10641. .. math::
  10642. \text{output} = (
  10643. min(
  10644. \text{quant\_max},
  10645. max(
  10646. \text{quant\_min},
  10647. \text{std::nearby\_int}(\text{input} / \text{scale}) + \text{zero\_point}
  10648. )
  10649. ) - \text{zero\_point}
  10650. ) \times \text{scale}
  10651. Args:
  10652. input (Tensor): the input value(s), ``torch.float32`` tensor
  10653. scale (double scalar or ``float32`` Tensor): quantization scale
  10654. zero_point (int64 scalar or ``int32`` Tensor): quantization zero_point
  10655. quant_min (int64): lower bound of the quantized domain
  10656. quant_max (int64): upper bound of the quantized domain
  10657. Returns:
  10658. Tensor: A newly fake_quantized ``torch.float32`` tensor
  10659. Example::
  10660. >>> x = torch.randn(4)
  10661. >>> x
  10662. tensor([ 0.0552, 0.9730, 0.3973, -1.0780])
  10663. >>> torch.fake_quantize_per_tensor_affine(x, 0.1, 0, 0, 255)
  10664. tensor([0.1000, 1.0000, 0.4000, 0.0000])
  10665. >>> torch.fake_quantize_per_tensor_affine(x, torch.tensor(0.1), torch.tensor(0), 0, 255)
  10666. tensor([0.1000, 1.0000, 0.4000, 0.0000])
  10667. """
  10668. @overload
  10669. def fbgemm_linear_fp16_weight(
  10670. input: Tensor,
  10671. packed_weight: Tensor,
  10672. bias: Tensor,
  10673. ) -> Tensor: ...
  10674. @overload
  10675. def fbgemm_linear_fp16_weight(
  10676. input: Tensor,
  10677. packed_weight: Tensor,
  10678. bias: Tensor,
  10679. output: Tensor,
  10680. ) -> Tensor: ...
  10681. @overload
  10682. def fbgemm_linear_fp16_weight_fp32_activation(
  10683. input: Tensor,
  10684. packed_weight: Tensor,
  10685. bias: Tensor | None,
  10686. ) -> Tensor: ...
  10687. @overload
  10688. def fbgemm_linear_fp16_weight_fp32_activation(
  10689. input: Tensor,
  10690. packed_weight: Tensor,
  10691. bias: Tensor | None,
  10692. output: Tensor,
  10693. ) -> Tensor: ...
  10694. def fbgemm_linear_int8_weight(
  10695. input: Tensor,
  10696. weight: Tensor,
  10697. packed: Tensor,
  10698. col_offsets: Tensor,
  10699. weight_scale: Number | _complex,
  10700. weight_zero_point: Number | _complex,
  10701. bias: Tensor,
  10702. ) -> Tensor: ...
  10703. def fbgemm_linear_int8_weight_fp32_activation(
  10704. input: Tensor,
  10705. weight: Tensor,
  10706. packed: Tensor,
  10707. col_offsets: Tensor,
  10708. weight_scale: Number | _complex,
  10709. weight_zero_point: Number | _complex,
  10710. bias: Tensor,
  10711. ) -> Tensor: ...
  10712. def fbgemm_linear_quantize_weight(
  10713. input: Tensor,
  10714. ) -> tuple[Tensor, Tensor, _float, _int]: ...
  10715. def fbgemm_pack_gemm_matrix_fp16(input: Tensor) -> Tensor: ...
  10716. @overload
  10717. def fbgemm_pack_quantized_matrix(input: Tensor) -> Tensor: ...
  10718. @overload
  10719. def fbgemm_pack_quantized_matrix(input: Tensor, K: _int, N: _int) -> Tensor: ...
  10720. def feature_alpha_dropout(input: Tensor, p: _float, train: _bool) -> Tensor: ...
  10721. def feature_alpha_dropout_(
  10722. input: Tensor,
  10723. p: _float,
  10724. train: _bool,
  10725. ) -> Tensor: ...
  10726. def feature_dropout(input: Tensor, p: _float, train: _bool) -> Tensor: ...
  10727. def feature_dropout_(input: Tensor, p: _float, train: _bool) -> Tensor: ...
  10728. @overload
  10729. def fill(input: Tensor, value: Tensor) -> Tensor: ...
  10730. @overload
  10731. def fill(input: Tensor, value: Number | _complex) -> Tensor: ...
  10732. @overload
  10733. def fill_(input: Tensor, value: Tensor) -> Tensor: ...
  10734. @overload
  10735. def fill_(input: Tensor, value: Number | _complex) -> Tensor: ...
  10736. def fix(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  10737. r"""
  10738. fix(input, *, out=None) -> Tensor
  10739. Alias for :func:`torch.trunc`
  10740. """
  10741. def fix_(input: Tensor) -> Tensor: ...
  10742. @overload
  10743. def flatten(
  10744. input: Tensor,
  10745. start_dim: _int = 0,
  10746. end_dim: _int = -1,
  10747. ) -> Tensor:
  10748. r"""
  10749. flatten(input, start_dim=0, end_dim=-1) -> Tensor
  10750. Flattens :attr:`input` by reshaping it into a one-dimensional tensor. If :attr:`start_dim` or :attr:`end_dim`
  10751. are passed, only dimensions starting with :attr:`start_dim` and ending with :attr:`end_dim` are flattened.
  10752. The order of elements in :attr:`input` is unchanged.
  10753. Unlike NumPy's flatten, which always copies input's data, this function may return the original object, a view,
  10754. or copy. If no dimensions are flattened, then the original object :attr:`input` is returned. Otherwise, if input can
  10755. be viewed as the flattened shape, then that view is returned. Finally, only if the input cannot be viewed as the
  10756. flattened shape is input's data copied. See :meth:`torch.Tensor.view` for details on when a view will be returned.
  10757. .. note::
  10758. Flattening a zero-dimensional tensor will return a one-dimensional view.
  10759. Args:
  10760. input (Tensor): the input tensor.
  10761. start_dim (int): the first dim to flatten
  10762. end_dim (int): the last dim to flatten
  10763. Example::
  10764. >>> t = torch.tensor([[[1, 2],
  10765. ... [3, 4]],
  10766. ... [[5, 6],
  10767. ... [7, 8]]])
  10768. >>> torch.flatten(t)
  10769. tensor([1, 2, 3, 4, 5, 6, 7, 8])
  10770. >>> torch.flatten(t, start_dim=1)
  10771. tensor([[1, 2, 3, 4],
  10772. [5, 6, 7, 8]])
  10773. """
  10774. @overload
  10775. def flatten(
  10776. input: Tensor,
  10777. start_dim: _int,
  10778. end_dim: _int,
  10779. out_dim: str | EllipsisType | None,
  10780. ) -> Tensor:
  10781. r"""
  10782. flatten(input, start_dim=0, end_dim=-1) -> Tensor
  10783. Flattens :attr:`input` by reshaping it into a one-dimensional tensor. If :attr:`start_dim` or :attr:`end_dim`
  10784. are passed, only dimensions starting with :attr:`start_dim` and ending with :attr:`end_dim` are flattened.
  10785. The order of elements in :attr:`input` is unchanged.
  10786. Unlike NumPy's flatten, which always copies input's data, this function may return the original object, a view,
  10787. or copy. If no dimensions are flattened, then the original object :attr:`input` is returned. Otherwise, if input can
  10788. be viewed as the flattened shape, then that view is returned. Finally, only if the input cannot be viewed as the
  10789. flattened shape is input's data copied. See :meth:`torch.Tensor.view` for details on when a view will be returned.
  10790. .. note::
  10791. Flattening a zero-dimensional tensor will return a one-dimensional view.
  10792. Args:
  10793. input (Tensor): the input tensor.
  10794. start_dim (int): the first dim to flatten
  10795. end_dim (int): the last dim to flatten
  10796. Example::
  10797. >>> t = torch.tensor([[[1, 2],
  10798. ... [3, 4]],
  10799. ... [[5, 6],
  10800. ... [7, 8]]])
  10801. >>> torch.flatten(t)
  10802. tensor([1, 2, 3, 4, 5, 6, 7, 8])
  10803. >>> torch.flatten(t, start_dim=1)
  10804. tensor([[1, 2, 3, 4],
  10805. [5, 6, 7, 8]])
  10806. """
  10807. @overload
  10808. def flatten(
  10809. input: Tensor,
  10810. start_dim: str | EllipsisType | None,
  10811. end_dim: str | EllipsisType | None,
  10812. out_dim: str | EllipsisType | None,
  10813. ) -> Tensor:
  10814. r"""
  10815. flatten(input, start_dim=0, end_dim=-1) -> Tensor
  10816. Flattens :attr:`input` by reshaping it into a one-dimensional tensor. If :attr:`start_dim` or :attr:`end_dim`
  10817. are passed, only dimensions starting with :attr:`start_dim` and ending with :attr:`end_dim` are flattened.
  10818. The order of elements in :attr:`input` is unchanged.
  10819. Unlike NumPy's flatten, which always copies input's data, this function may return the original object, a view,
  10820. or copy. If no dimensions are flattened, then the original object :attr:`input` is returned. Otherwise, if input can
  10821. be viewed as the flattened shape, then that view is returned. Finally, only if the input cannot be viewed as the
  10822. flattened shape is input's data copied. See :meth:`torch.Tensor.view` for details on when a view will be returned.
  10823. .. note::
  10824. Flattening a zero-dimensional tensor will return a one-dimensional view.
  10825. Args:
  10826. input (Tensor): the input tensor.
  10827. start_dim (int): the first dim to flatten
  10828. end_dim (int): the last dim to flatten
  10829. Example::
  10830. >>> t = torch.tensor([[[1, 2],
  10831. ... [3, 4]],
  10832. ... [[5, 6],
  10833. ... [7, 8]]])
  10834. >>> torch.flatten(t)
  10835. tensor([1, 2, 3, 4, 5, 6, 7, 8])
  10836. >>> torch.flatten(t, start_dim=1)
  10837. tensor([[1, 2, 3, 4],
  10838. [5, 6, 7, 8]])
  10839. """
  10840. @overload
  10841. def flatten(
  10842. input: Tensor,
  10843. dims: Sequence[str | EllipsisType | None],
  10844. out_dim: str | EllipsisType | None,
  10845. ) -> Tensor:
  10846. r"""
  10847. flatten(input, start_dim=0, end_dim=-1) -> Tensor
  10848. Flattens :attr:`input` by reshaping it into a one-dimensional tensor. If :attr:`start_dim` or :attr:`end_dim`
  10849. are passed, only dimensions starting with :attr:`start_dim` and ending with :attr:`end_dim` are flattened.
  10850. The order of elements in :attr:`input` is unchanged.
  10851. Unlike NumPy's flatten, which always copies input's data, this function may return the original object, a view,
  10852. or copy. If no dimensions are flattened, then the original object :attr:`input` is returned. Otherwise, if input can
  10853. be viewed as the flattened shape, then that view is returned. Finally, only if the input cannot be viewed as the
  10854. flattened shape is input's data copied. See :meth:`torch.Tensor.view` for details on when a view will be returned.
  10855. .. note::
  10856. Flattening a zero-dimensional tensor will return a one-dimensional view.
  10857. Args:
  10858. input (Tensor): the input tensor.
  10859. start_dim (int): the first dim to flatten
  10860. end_dim (int): the last dim to flatten
  10861. Example::
  10862. >>> t = torch.tensor([[[1, 2],
  10863. ... [3, 4]],
  10864. ... [[5, 6],
  10865. ... [7, 8]]])
  10866. >>> torch.flatten(t)
  10867. tensor([1, 2, 3, 4, 5, 6, 7, 8])
  10868. >>> torch.flatten(t, start_dim=1)
  10869. tensor([[1, 2, 3, 4],
  10870. [5, 6, 7, 8]])
  10871. """
  10872. def flip(input: Tensor, dims: _size) -> Tensor:
  10873. r"""
  10874. flip(input, dims) -> Tensor
  10875. Reverse the order of an n-D tensor along given axis in dims.
  10876. .. note::
  10877. `torch.flip` makes a copy of :attr:`input`'s data. This is different from NumPy's `np.flip`,
  10878. which returns a view in constant time. Since copying a tensor's data is more work than viewing that data,
  10879. `torch.flip` is expected to be slower than `np.flip`.
  10880. Args:
  10881. input (Tensor): the input tensor.
  10882. dims (a list or tuple): axis to flip on
  10883. Example::
  10884. >>> x = torch.arange(8).view(2, 2, 2)
  10885. >>> x
  10886. tensor([[[ 0, 1],
  10887. [ 2, 3]],
  10888. [[ 4, 5],
  10889. [ 6, 7]]])
  10890. >>> torch.flip(x, [0, 1])
  10891. tensor([[[ 6, 7],
  10892. [ 4, 5]],
  10893. [[ 2, 3],
  10894. [ 0, 1]]])
  10895. """
  10896. def fliplr(input: Tensor) -> Tensor:
  10897. r"""
  10898. fliplr(input) -> Tensor
  10899. Flip tensor in the left/right direction, returning a new tensor.
  10900. Flip the entries in each row in the left/right direction.
  10901. Columns are preserved, but appear in a different order than before.
  10902. Note:
  10903. Requires the tensor to be at least 2-D.
  10904. .. note::
  10905. `torch.fliplr` makes a copy of :attr:`input`'s data. This is different from NumPy's `np.fliplr`,
  10906. which returns a view in constant time. Since copying a tensor's data is more work than viewing that data,
  10907. `torch.fliplr` is expected to be slower than `np.fliplr`.
  10908. Args:
  10909. input (Tensor): Must be at least 2-dimensional.
  10910. Example::
  10911. >>> x = torch.arange(4).view(2, 2)
  10912. >>> x
  10913. tensor([[0, 1],
  10914. [2, 3]])
  10915. >>> torch.fliplr(x)
  10916. tensor([[1, 0],
  10917. [3, 2]])
  10918. """
  10919. def flipud(input: Tensor) -> Tensor:
  10920. r"""
  10921. flipud(input) -> Tensor
  10922. Flip tensor in the up/down direction, returning a new tensor.
  10923. Flip the entries in each column in the up/down direction.
  10924. Rows are preserved, but appear in a different order than before.
  10925. Note:
  10926. Requires the tensor to be at least 1-D.
  10927. .. note::
  10928. `torch.flipud` makes a copy of :attr:`input`'s data. This is different from NumPy's `np.flipud`,
  10929. which returns a view in constant time. Since copying a tensor's data is more work than viewing that data,
  10930. `torch.flipud` is expected to be slower than `np.flipud`.
  10931. Args:
  10932. input (Tensor): Must be at least 1-dimensional.
  10933. Example::
  10934. >>> x = torch.arange(4).view(2, 2)
  10935. >>> x
  10936. tensor([[0, 1],
  10937. [2, 3]])
  10938. >>> torch.flipud(x)
  10939. tensor([[2, 3],
  10940. [0, 1]])
  10941. """
  10942. @overload
  10943. def float_power(
  10944. input: Tensor,
  10945. exponent: Tensor,
  10946. *,
  10947. out: Tensor | None = None,
  10948. ) -> Tensor:
  10949. r"""
  10950. float_power(input, exponent, *, out=None) -> Tensor
  10951. Raises :attr:`input` to the power of :attr:`exponent`, elementwise, in double precision.
  10952. If neither input is complex returns a ``torch.float64`` tensor,
  10953. and if one or more inputs is complex returns a ``torch.complex128`` tensor.
  10954. .. note::
  10955. This function always computes in double precision, unlike :func:`torch.pow`,
  10956. which implements more typical :ref:`type promotion <type-promotion-doc>`.
  10957. This is useful when the computation needs to be performed in a wider or more precise dtype,
  10958. or the results of the computation may contain fractional values not representable in the input dtypes,
  10959. like when an integer base is raised to a negative integer exponent.
  10960. Args:
  10961. input (Tensor or Number): the base value(s)
  10962. exponent (Tensor or Number): the exponent value(s)
  10963. Keyword args:
  10964. out (Tensor, optional): the output tensor.
  10965. Example::
  10966. >>> a = torch.randint(10, (4,))
  10967. >>> a
  10968. tensor([6, 4, 7, 1])
  10969. >>> torch.float_power(a, 2)
  10970. tensor([36., 16., 49., 1.], dtype=torch.float64)
  10971. >>> a = torch.arange(1, 5)
  10972. >>> a
  10973. tensor([ 1, 2, 3, 4])
  10974. >>> exp = torch.tensor([2, -3, 4, -5])
  10975. >>> exp
  10976. tensor([ 2, -3, 4, -5])
  10977. >>> torch.float_power(a, exp)
  10978. tensor([1.0000e+00, 1.2500e-01, 8.1000e+01, 9.7656e-04], dtype=torch.float64)
  10979. """
  10980. @overload
  10981. def float_power(
  10982. self: Number | _complex,
  10983. exponent: Tensor,
  10984. *,
  10985. out: Tensor | None = None,
  10986. ) -> Tensor:
  10987. r"""
  10988. float_power(input, exponent, *, out=None) -> Tensor
  10989. Raises :attr:`input` to the power of :attr:`exponent`, elementwise, in double precision.
  10990. If neither input is complex returns a ``torch.float64`` tensor,
  10991. and if one or more inputs is complex returns a ``torch.complex128`` tensor.
  10992. .. note::
  10993. This function always computes in double precision, unlike :func:`torch.pow`,
  10994. which implements more typical :ref:`type promotion <type-promotion-doc>`.
  10995. This is useful when the computation needs to be performed in a wider or more precise dtype,
  10996. or the results of the computation may contain fractional values not representable in the input dtypes,
  10997. like when an integer base is raised to a negative integer exponent.
  10998. Args:
  10999. input (Tensor or Number): the base value(s)
  11000. exponent (Tensor or Number): the exponent value(s)
  11001. Keyword args:
  11002. out (Tensor, optional): the output tensor.
  11003. Example::
  11004. >>> a = torch.randint(10, (4,))
  11005. >>> a
  11006. tensor([6, 4, 7, 1])
  11007. >>> torch.float_power(a, 2)
  11008. tensor([36., 16., 49., 1.], dtype=torch.float64)
  11009. >>> a = torch.arange(1, 5)
  11010. >>> a
  11011. tensor([ 1, 2, 3, 4])
  11012. >>> exp = torch.tensor([2, -3, 4, -5])
  11013. >>> exp
  11014. tensor([ 2, -3, 4, -5])
  11015. >>> torch.float_power(a, exp)
  11016. tensor([1.0000e+00, 1.2500e-01, 8.1000e+01, 9.7656e-04], dtype=torch.float64)
  11017. """
  11018. @overload
  11019. def float_power(
  11020. input: Tensor,
  11021. exponent: Number | _complex,
  11022. *,
  11023. out: Tensor | None = None,
  11024. ) -> Tensor:
  11025. r"""
  11026. float_power(input, exponent, *, out=None) -> Tensor
  11027. Raises :attr:`input` to the power of :attr:`exponent`, elementwise, in double precision.
  11028. If neither input is complex returns a ``torch.float64`` tensor,
  11029. and if one or more inputs is complex returns a ``torch.complex128`` tensor.
  11030. .. note::
  11031. This function always computes in double precision, unlike :func:`torch.pow`,
  11032. which implements more typical :ref:`type promotion <type-promotion-doc>`.
  11033. This is useful when the computation needs to be performed in a wider or more precise dtype,
  11034. or the results of the computation may contain fractional values not representable in the input dtypes,
  11035. like when an integer base is raised to a negative integer exponent.
  11036. Args:
  11037. input (Tensor or Number): the base value(s)
  11038. exponent (Tensor or Number): the exponent value(s)
  11039. Keyword args:
  11040. out (Tensor, optional): the output tensor.
  11041. Example::
  11042. >>> a = torch.randint(10, (4,))
  11043. >>> a
  11044. tensor([6, 4, 7, 1])
  11045. >>> torch.float_power(a, 2)
  11046. tensor([36., 16., 49., 1.], dtype=torch.float64)
  11047. >>> a = torch.arange(1, 5)
  11048. >>> a
  11049. tensor([ 1, 2, 3, 4])
  11050. >>> exp = torch.tensor([2, -3, 4, -5])
  11051. >>> exp
  11052. tensor([ 2, -3, 4, -5])
  11053. >>> torch.float_power(a, exp)
  11054. tensor([1.0000e+00, 1.2500e-01, 8.1000e+01, 9.7656e-04], dtype=torch.float64)
  11055. """
  11056. def floor(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  11057. r"""
  11058. floor(input, *, out=None) -> Tensor
  11059. Returns a new tensor with the floor of the elements of :attr:`input`,
  11060. the largest integer less than or equal to each element.
  11061. For integer inputs, follows the array-api convention of returning a
  11062. copy of the input tensor.
  11063. .. math::
  11064. \text{out}_{i} = \left\lfloor \text{input}_{i} \right\rfloor
  11065. Args:
  11066. input (Tensor): the input tensor.
  11067. Keyword args:
  11068. out (Tensor, optional): the output tensor.
  11069. Example::
  11070. >>> a = torch.randn(4)
  11071. >>> a
  11072. tensor([-0.8166, 1.5308, -0.2530, -0.2091])
  11073. >>> torch.floor(a)
  11074. tensor([-1., 1., -1., -1.])
  11075. """
  11076. def floor_(input: Tensor) -> Tensor: ...
  11077. def floor_divide(
  11078. input: Tensor | Number,
  11079. other: Tensor | Number,
  11080. *,
  11081. out: Tensor | None = None,
  11082. ) -> Tensor:
  11083. r"""
  11084. floor_divide(input, other, *, out=None) -> Tensor
  11085. .. note::
  11086. Before PyTorch 1.13 :func:`torch.floor_divide` incorrectly performed
  11087. truncation division. To restore the previous behavior use
  11088. :func:`torch.div` with ``rounding_mode='trunc'``.
  11089. Computes :attr:`input` divided by :attr:`other`, elementwise, and floors
  11090. the result.
  11091. .. math::
  11092. \text{{out}}_i = \text{floor} \left( \frac{{\text{{input}}_i}}{{\text{{other}}_i}} \right)
  11093. Supports broadcasting to a common shape, type promotion, and integer and float inputs.
  11094. Args:
  11095. input (Tensor or Number): the dividend
  11096. other (Tensor or Number): the divisor
  11097. Keyword args:
  11098. out (Tensor, optional): the output tensor.
  11099. Example::
  11100. >>> a = torch.tensor([4.0, 3.0])
  11101. >>> b = torch.tensor([2.0, 2.0])
  11102. >>> torch.floor_divide(a, b)
  11103. tensor([2.0, 1.0])
  11104. >>> torch.floor_divide(a, 1.4)
  11105. tensor([2.0, 2.0])
  11106. """
  11107. def fmax(
  11108. input: Tensor,
  11109. other: Tensor,
  11110. *,
  11111. out: Tensor | None = None,
  11112. ) -> Tensor:
  11113. r"""
  11114. fmax(input, other, *, out=None) -> Tensor
  11115. Computes the element-wise maximum of :attr:`input` and :attr:`other`.
  11116. This is like :func:`torch.maximum` except it handles NaNs differently:
  11117. if exactly one of the two elements being compared is a NaN then the non-NaN element is taken as the maximum.
  11118. Only if both elements are NaN is NaN propagated.
  11119. This function is a wrapper around C++'s ``std::fmax`` and is similar to NumPy's ``fmax`` function.
  11120. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  11121. :ref:`type promotion <type-promotion-doc>`, and integer and floating-point inputs.
  11122. Args:
  11123. input (Tensor): the input tensor.
  11124. other (Tensor): the second input tensor
  11125. Keyword args:
  11126. out (Tensor, optional): the output tensor.
  11127. Example::
  11128. >>> a = torch.tensor([9.7, float('nan'), 3.1, float('nan')])
  11129. >>> b = torch.tensor([-2.2, 0.5, float('nan'), float('nan')])
  11130. >>> torch.fmax(a, b)
  11131. tensor([9.7000, 0.5000, 3.1000, nan])
  11132. """
  11133. def fmin(
  11134. input: Tensor,
  11135. other: Tensor,
  11136. *,
  11137. out: Tensor | None = None,
  11138. ) -> Tensor:
  11139. r"""
  11140. fmin(input, other, *, out=None) -> Tensor
  11141. Computes the element-wise minimum of :attr:`input` and :attr:`other`.
  11142. This is like :func:`torch.minimum` except it handles NaNs differently:
  11143. if exactly one of the two elements being compared is a NaN then the non-NaN element is taken as the minimum.
  11144. Only if both elements are NaN is NaN propagated.
  11145. This function is a wrapper around C++'s ``std::fmin`` and is similar to NumPy's ``fmin`` function.
  11146. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  11147. :ref:`type promotion <type-promotion-doc>`, and integer and floating-point inputs.
  11148. Args:
  11149. input (Tensor): the input tensor.
  11150. other (Tensor): the second input tensor
  11151. Keyword args:
  11152. out (Tensor, optional): the output tensor.
  11153. Example::
  11154. >>> a = torch.tensor([2.2, float('nan'), 2.1, float('nan')])
  11155. >>> b = torch.tensor([-9.3, 0.1, float('nan'), float('nan')])
  11156. >>> torch.fmin(a, b)
  11157. tensor([-9.3000, 0.1000, 2.1000, nan])
  11158. """
  11159. @overload
  11160. def fmod(
  11161. input: Tensor,
  11162. other: Tensor,
  11163. *,
  11164. out: Tensor | None = None,
  11165. ) -> Tensor:
  11166. r"""
  11167. fmod(input, other, *, out=None) -> Tensor
  11168. Applies C++'s `std::fmod <https://en.cppreference.com/w/cpp/numeric/math/fmod>`_ entrywise.
  11169. The result has the same sign as the dividend :attr:`input` and its absolute value
  11170. is less than that of :attr:`other`.
  11171. This function may be defined in terms of :func:`torch.div` as
  11172. .. code:: python
  11173. torch.fmod(a, b) == a - a.div(b, rounding_mode="trunc") * b
  11174. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  11175. :ref:`type promotion <type-promotion-doc>`, and integer and float inputs.
  11176. .. note::
  11177. When the divisor is zero, returns ``NaN`` for floating point dtypes
  11178. on both CPU and GPU; raises ``RuntimeError`` for integer division by
  11179. zero on CPU; Integer division by zero on GPU may return any value.
  11180. .. note::
  11181. Complex inputs are not supported. In some cases, it is not mathematically
  11182. possible to satisfy the definition of a modulo operation with complex numbers.
  11183. .. seealso::
  11184. :func:`torch.remainder` which implements Python's modulus operator.
  11185. This one is defined using division rounding down the result.
  11186. Args:
  11187. input (Tensor): the dividend
  11188. other (Tensor or Scalar): the divisor
  11189. Keyword args:
  11190. out (Tensor, optional): the output tensor.
  11191. Example::
  11192. >>> torch.fmod(torch.tensor([-3., -2, -1, 1, 2, 3]), 2)
  11193. tensor([-1., -0., -1., 1., 0., 1.])
  11194. >>> torch.fmod(torch.tensor([1, 2, 3, 4, 5]), -1.5)
  11195. tensor([1.0000, 0.5000, 0.0000, 1.0000, 0.5000])
  11196. """
  11197. @overload
  11198. def fmod(
  11199. input: Tensor,
  11200. other: Number | _complex,
  11201. *,
  11202. out: Tensor | None = None,
  11203. ) -> Tensor:
  11204. r"""
  11205. fmod(input, other, *, out=None) -> Tensor
  11206. Applies C++'s `std::fmod <https://en.cppreference.com/w/cpp/numeric/math/fmod>`_ entrywise.
  11207. The result has the same sign as the dividend :attr:`input` and its absolute value
  11208. is less than that of :attr:`other`.
  11209. This function may be defined in terms of :func:`torch.div` as
  11210. .. code:: python
  11211. torch.fmod(a, b) == a - a.div(b, rounding_mode="trunc") * b
  11212. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  11213. :ref:`type promotion <type-promotion-doc>`, and integer and float inputs.
  11214. .. note::
  11215. When the divisor is zero, returns ``NaN`` for floating point dtypes
  11216. on both CPU and GPU; raises ``RuntimeError`` for integer division by
  11217. zero on CPU; Integer division by zero on GPU may return any value.
  11218. .. note::
  11219. Complex inputs are not supported. In some cases, it is not mathematically
  11220. possible to satisfy the definition of a modulo operation with complex numbers.
  11221. .. seealso::
  11222. :func:`torch.remainder` which implements Python's modulus operator.
  11223. This one is defined using division rounding down the result.
  11224. Args:
  11225. input (Tensor): the dividend
  11226. other (Tensor or Scalar): the divisor
  11227. Keyword args:
  11228. out (Tensor, optional): the output tensor.
  11229. Example::
  11230. >>> torch.fmod(torch.tensor([-3., -2, -1, 1, 2, 3]), 2)
  11231. tensor([-1., -0., -1., 1., 0., 1.])
  11232. >>> torch.fmod(torch.tensor([1, 2, 3, 4, 5]), -1.5)
  11233. tensor([1.0000, 0.5000, 0.0000, 1.0000, 0.5000])
  11234. """
  11235. def frac(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  11236. r"""
  11237. frac(input, *, out=None) -> Tensor
  11238. Computes the fractional portion of each element in :attr:`input`.
  11239. .. math::
  11240. \text{out}_{i} = \text{input}_{i} - \left\lfloor |\text{input}_{i}| \right\rfloor * \operatorname{sgn}(\text{input}_{i})
  11241. Example::
  11242. >>> torch.frac(torch.tensor([1, 2.5, -3.2]))
  11243. tensor([ 0.0000, 0.5000, -0.2000])
  11244. """
  11245. def frac_(input: Tensor) -> Tensor: ...
  11246. def frexp(
  11247. input: Tensor,
  11248. *,
  11249. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  11250. ) -> torch.return_types.frexp:
  11251. r"""
  11252. frexp(input, *, out=None) -> (Tensor mantissa, Tensor exponent)
  11253. Decomposes :attr:`input` into mantissa and exponent tensors
  11254. such that :math:`\text{input} = \text{mantissa} \times 2^{\text{exponent}}`.
  11255. The range of mantissa is the open interval (-1, 1).
  11256. Supports float inputs.
  11257. Args:
  11258. input (Tensor): the input tensor
  11259. Keyword args:
  11260. out (tuple, optional): the output tensors
  11261. Example::
  11262. >>> x = torch.arange(9.)
  11263. >>> mantissa, exponent = torch.frexp(x)
  11264. >>> mantissa
  11265. tensor([0.0000, 0.5000, 0.5000, 0.7500, 0.5000, 0.6250, 0.7500, 0.8750, 0.5000])
  11266. >>> exponent
  11267. tensor([0, 1, 2, 2, 3, 3, 3, 3, 4], dtype=torch.int32)
  11268. >>> torch.ldexp(mantissa, exponent)
  11269. tensor([0., 1., 2., 3., 4., 5., 6., 7., 8.])
  11270. """
  11271. def frobenius_norm(
  11272. input: Tensor,
  11273. dim: _int | _size,
  11274. keepdim: _bool = False,
  11275. *,
  11276. out: Tensor | None = None,
  11277. ) -> Tensor: ...
  11278. def from_file(
  11279. filename: str,
  11280. shared: _bool | None = None,
  11281. size: _int | None = 0,
  11282. *,
  11283. dtype: _dtype | None = None,
  11284. layout: _layout | None = None,
  11285. device: DeviceLikeType | None = None,
  11286. pin_memory: _bool | None = False,
  11287. requires_grad: _bool | None = False,
  11288. ) -> Tensor:
  11289. r"""
  11290. from_file(filename, shared=None, size=0, *, dtype=None, layout=None, device=None, pin_memory=False)
  11291. Creates a CPU tensor with a storage backed by a memory-mapped file.
  11292. If ``shared`` is True, then memory is shared between processes. All changes are written to the file.
  11293. If ``shared`` is False, then changes to the tensor do not affect the file.
  11294. ``size`` is the number of elements in the Tensor. If ``shared`` is ``False``, then the file must contain
  11295. at least ``size * sizeof(dtype)`` bytes. If ``shared`` is ``True`` the file will be created if needed.
  11296. .. note::
  11297. Only CPU tensors can be mapped to files.
  11298. .. note::
  11299. For now, tensors with storages backed by a memory-mapped file cannot be created in pinned memory.
  11300. Args:
  11301. filename (str): file name to map
  11302. shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
  11303. underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
  11304. size (int): number of elements in the tensor
  11305. Keyword args:
  11306. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  11307. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  11308. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  11309. Default: ``torch.strided``.
  11310. device (:class:`torch.device`, optional): the desired device of returned tensor.
  11311. Default: if ``None``, uses the current device for the default tensor type
  11312. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  11313. for CPU tensor types and the current CUDA device for CUDA tensor types.
  11314. pin_memory (bool, optional): If set, returned tensor would be allocated in
  11315. the pinned memory. Works only for CPU tensors. Default: ``False``.
  11316. Example::
  11317. >>> t = torch.randn(2, 5, dtype=torch.float64)
  11318. >>> t.numpy().tofile('storage.pt')
  11319. >>> t_mapped = torch.from_file('storage.pt', shared=False, size=10, dtype=torch.float64)
  11320. """
  11321. def from_numpy(ndarray) -> Tensor:
  11322. r"""
  11323. from_numpy(ndarray) -> Tensor
  11324. Creates a :class:`Tensor` from a :class:`numpy.ndarray`.
  11325. The returned tensor and :attr:`ndarray` share the same memory. Modifications to
  11326. the tensor will be reflected in the :attr:`ndarray` and vice versa. The returned
  11327. tensor is not resizable.
  11328. It currently accepts :attr:`ndarray` with dtypes of ``numpy.float64``,
  11329. ``numpy.float32``, ``numpy.float16``, ``numpy.complex64``, ``numpy.complex128``,
  11330. ``numpy.int64``, ``numpy.int32``, ``numpy.int16``, ``numpy.int8``, ``numpy.uint8``,
  11331. and ``bool``.
  11332. .. warning::
  11333. Writing to a tensor created from a read-only NumPy array is not supported and will result in undefined behavior.
  11334. Example::
  11335. >>> a = numpy.array([1, 2, 3])
  11336. >>> t = torch.from_numpy(a)
  11337. >>> t
  11338. tensor([ 1, 2, 3])
  11339. >>> t[0] = -1
  11340. >>> a
  11341. array([-1, 2, 3])
  11342. """
  11343. def frombuffer(
  11344. buffer: Any,
  11345. *,
  11346. dtype: _dtype,
  11347. count: int = -1,
  11348. offset: int = 0,
  11349. requires_grad: _bool = False,
  11350. ) -> Tensor:
  11351. r"""
  11352. frombuffer(buffer, *, dtype, count=-1, offset=0, requires_grad=False) -> Tensor
  11353. Creates a 1-dimensional :class:`Tensor` from an object that implements
  11354. the Python buffer protocol.
  11355. Skips the first :attr:`offset` bytes in the buffer, and interprets the rest of
  11356. the raw bytes as a 1-dimensional tensor of type :attr:`dtype` with :attr:`count`
  11357. elements.
  11358. Note that either of the following must be true:
  11359. 1. :attr:`count` is a positive non-zero number, and the total number of bytes
  11360. in the buffer is more than :attr:`offset` plus :attr:`count` times the size
  11361. (in bytes) of :attr:`dtype`.
  11362. 2. :attr:`count` is negative, and the length (number of bytes) of the buffer
  11363. subtracted by the :attr:`offset` is a multiple of the size (in bytes) of
  11364. :attr:`dtype`.
  11365. The returned tensor and buffer share the same memory. Modifications to
  11366. the tensor will be reflected in the buffer and vice versa. The returned
  11367. tensor is not resizable.
  11368. .. note::
  11369. This function increments the reference count for the object that
  11370. owns the shared memory. Therefore, such memory will not be deallocated
  11371. before the returned tensor goes out of scope.
  11372. .. warning::
  11373. This function's behavior is undefined when passed an object implementing
  11374. the buffer protocol whose data is not on the CPU. Doing so is likely to
  11375. cause a segmentation fault.
  11376. .. warning::
  11377. This function does not try to infer the :attr:`dtype` (hence, it is not
  11378. optional). Passing a different :attr:`dtype` than its source may result
  11379. in unexpected behavior.
  11380. Args:
  11381. buffer (object): a Python object that exposes the buffer interface.
  11382. Keyword args:
  11383. dtype (:class:`torch.dtype`): the desired data type of returned tensor.
  11384. count (int, optional): the number of desired elements to be read.
  11385. If negative, all the elements (until the end of the buffer) will be
  11386. read. Default: -1.
  11387. offset (int, optional): the number of bytes to skip at the start of
  11388. the buffer. Default: 0.
  11389. requires_grad (bool, optional): If autograd should record operations on the
  11390. returned tensor. Default: ``False``.
  11391. Example::
  11392. >>> import array
  11393. >>> a = array.array('i', [1, 2, 3])
  11394. >>> t = torch.frombuffer(a, dtype=torch.int32)
  11395. >>> t
  11396. tensor([ 1, 2, 3])
  11397. >>> t[0] = -1
  11398. >>> a
  11399. array([-1, 2, 3])
  11400. >>> # Interprets the signed char bytes as 32-bit integers.
  11401. >>> # Each 4 signed char elements will be interpreted as
  11402. >>> # 1 signed 32-bit integer.
  11403. >>> import array
  11404. >>> a = array.array('b', [-1, 0, 0, 0])
  11405. >>> torch.frombuffer(a, dtype=torch.int32)
  11406. tensor([255], dtype=torch.int32)
  11407. """
  11408. @overload
  11409. def full(
  11410. size: _size,
  11411. fill_value: Number | _complex,
  11412. *,
  11413. out: Tensor | None = None,
  11414. layout: _layout = strided,
  11415. dtype: _dtype | None = None,
  11416. device: DeviceLikeType | None = None,
  11417. requires_grad: _bool = False,
  11418. pin_memory: _bool = False,
  11419. ) -> Tensor:
  11420. r"""
  11421. full(size, fill_value, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  11422. Creates a tensor of size :attr:`size` filled with :attr:`fill_value`. The
  11423. tensor's dtype is inferred from :attr:`fill_value`.
  11424. Args:
  11425. size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
  11426. shape of the output tensor.
  11427. fill_value (Scalar): the value to fill the output tensor with.
  11428. Keyword args:
  11429. out (Tensor, optional): the output tensor.
  11430. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  11431. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  11432. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  11433. Default: ``torch.strided``.
  11434. device (:class:`torch.device`, optional): the desired device of returned tensor.
  11435. Default: if ``None``, uses the current device for the default tensor type
  11436. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  11437. for CPU tensor types and the current CUDA device for CUDA tensor types.
  11438. requires_grad (bool, optional): If autograd should record operations on the
  11439. returned tensor. Default: ``False``.
  11440. Example::
  11441. >>> torch.full((2, 3), 3.141592)
  11442. tensor([[ 3.1416, 3.1416, 3.1416],
  11443. [ 3.1416, 3.1416, 3.1416]])
  11444. """
  11445. @overload
  11446. def full(
  11447. size: _size,
  11448. fill_value: Number | _complex,
  11449. *,
  11450. names: list[str | None],
  11451. layout: _layout = strided,
  11452. dtype: _dtype | None = None,
  11453. device: DeviceLikeType | None = None,
  11454. requires_grad: _bool = False,
  11455. pin_memory: _bool = False,
  11456. ) -> Tensor:
  11457. r"""
  11458. full(size, fill_value, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  11459. Creates a tensor of size :attr:`size` filled with :attr:`fill_value`. The
  11460. tensor's dtype is inferred from :attr:`fill_value`.
  11461. Args:
  11462. size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
  11463. shape of the output tensor.
  11464. fill_value (Scalar): the value to fill the output tensor with.
  11465. Keyword args:
  11466. out (Tensor, optional): the output tensor.
  11467. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  11468. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  11469. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  11470. Default: ``torch.strided``.
  11471. device (:class:`torch.device`, optional): the desired device of returned tensor.
  11472. Default: if ``None``, uses the current device for the default tensor type
  11473. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  11474. for CPU tensor types and the current CUDA device for CUDA tensor types.
  11475. requires_grad (bool, optional): If autograd should record operations on the
  11476. returned tensor. Default: ``False``.
  11477. Example::
  11478. >>> torch.full((2, 3), 3.141592)
  11479. tensor([[ 3.1416, 3.1416, 3.1416],
  11480. [ 3.1416, 3.1416, 3.1416]])
  11481. """
  11482. @overload
  11483. def full(
  11484. size: Sequence[_int | SymInt],
  11485. fill_value: Number | _complex,
  11486. *,
  11487. out: Tensor | None = None,
  11488. dtype: _dtype | None = None,
  11489. layout: _layout | None = None,
  11490. device: DeviceLikeType | None = None,
  11491. pin_memory: _bool | None = False,
  11492. requires_grad: _bool | None = False,
  11493. ) -> Tensor:
  11494. r"""
  11495. full(size, fill_value, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  11496. Creates a tensor of size :attr:`size` filled with :attr:`fill_value`. The
  11497. tensor's dtype is inferred from :attr:`fill_value`.
  11498. Args:
  11499. size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
  11500. shape of the output tensor.
  11501. fill_value (Scalar): the value to fill the output tensor with.
  11502. Keyword args:
  11503. out (Tensor, optional): the output tensor.
  11504. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  11505. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  11506. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  11507. Default: ``torch.strided``.
  11508. device (:class:`torch.device`, optional): the desired device of returned tensor.
  11509. Default: if ``None``, uses the current device for the default tensor type
  11510. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  11511. for CPU tensor types and the current CUDA device for CUDA tensor types.
  11512. requires_grad (bool, optional): If autograd should record operations on the
  11513. returned tensor. Default: ``False``.
  11514. Example::
  11515. >>> torch.full((2, 3), 3.141592)
  11516. tensor([[ 3.1416, 3.1416, 3.1416],
  11517. [ 3.1416, 3.1416, 3.1416]])
  11518. """
  11519. @overload
  11520. def full(
  11521. size: _size,
  11522. fill_value: Number | _complex,
  11523. *,
  11524. names: Sequence[str | EllipsisType | None] | None,
  11525. dtype: _dtype | None = None,
  11526. layout: _layout | None = None,
  11527. device: DeviceLikeType | None = None,
  11528. pin_memory: _bool | None = False,
  11529. requires_grad: _bool | None = False,
  11530. ) -> Tensor:
  11531. r"""
  11532. full(size, fill_value, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  11533. Creates a tensor of size :attr:`size` filled with :attr:`fill_value`. The
  11534. tensor's dtype is inferred from :attr:`fill_value`.
  11535. Args:
  11536. size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
  11537. shape of the output tensor.
  11538. fill_value (Scalar): the value to fill the output tensor with.
  11539. Keyword args:
  11540. out (Tensor, optional): the output tensor.
  11541. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  11542. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  11543. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  11544. Default: ``torch.strided``.
  11545. device (:class:`torch.device`, optional): the desired device of returned tensor.
  11546. Default: if ``None``, uses the current device for the default tensor type
  11547. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  11548. for CPU tensor types and the current CUDA device for CUDA tensor types.
  11549. requires_grad (bool, optional): If autograd should record operations on the
  11550. returned tensor. Default: ``False``.
  11551. Example::
  11552. >>> torch.full((2, 3), 3.141592)
  11553. tensor([[ 3.1416, 3.1416, 3.1416],
  11554. [ 3.1416, 3.1416, 3.1416]])
  11555. """
  11556. def full_like(
  11557. input: Tensor,
  11558. fill_value: Number | _complex,
  11559. *,
  11560. memory_format: memory_format | None = None,
  11561. dtype: _dtype | None = None,
  11562. layout: _layout | None = None,
  11563. device: DeviceLikeType | None = None,
  11564. pin_memory: _bool | None = False,
  11565. requires_grad: _bool | None = False,
  11566. ) -> Tensor:
  11567. r"""
  11568. full_like(input, fill_value, \*, dtype=None, layout=torch.strided, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  11569. Returns a tensor with the same size as :attr:`input` filled with :attr:`fill_value`.
  11570. ``torch.full_like(input, fill_value)`` is equivalent to
  11571. ``torch.full(input.size(), fill_value, dtype=input.dtype, layout=input.layout, device=input.device)``.
  11572. Args:
  11573. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  11574. fill_value: the number to fill the output tensor with.
  11575. Keyword args:
  11576. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  11577. Default: if ``None``, defaults to the dtype of :attr:`input`.
  11578. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  11579. Default: if ``None``, defaults to the layout of :attr:`input`.
  11580. device (:class:`torch.device`, optional): the desired device of returned tensor.
  11581. Default: if ``None``, defaults to the device of :attr:`input`.
  11582. requires_grad (bool, optional): If autograd should record operations on the
  11583. returned tensor. Default: ``False``.
  11584. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  11585. returned Tensor. Default: ``torch.preserve_format``.
  11586. Example::
  11587. >>> x = torch.ones(2, 3)
  11588. >>> torch.full_like(x, 3.141592)
  11589. tensor([[ 3.1416, 3.1416, 3.1416],
  11590. [ 3.1416, 3.1416, 3.1416]])
  11591. >>> torch.full_like(x, 7)
  11592. tensor([[7., 7., 7.],
  11593. [7., 7., 7.]])
  11594. >>> torch.full_like(x, 0.5, dtype=torch.int32)
  11595. tensor([[0, 0, 0],
  11596. [0, 0, 0]], dtype=torch.int32)
  11597. >>> y = torch.randn(3, 4, dtype=torch.float64)
  11598. >>> torch.full_like(y, -1.0)
  11599. tensor([[-1., -1., -1., -1.],
  11600. [-1., -1., -1., -1.],
  11601. [-1., -1., -1., -1.]], dtype=torch.float64)
  11602. """
  11603. def fused_moving_avg_obs_fake_quant(
  11604. input: Tensor,
  11605. observer_on: Tensor,
  11606. fake_quant_on: Tensor,
  11607. running_min: Tensor,
  11608. running_max: Tensor,
  11609. scale: Tensor,
  11610. zero_point: Tensor,
  11611. averaging_const: _float,
  11612. quant_min: _int,
  11613. quant_max: _int,
  11614. ch_axis: _int,
  11615. per_row_fake_quant: _bool = False,
  11616. symmetric_quant: _bool = False,
  11617. ) -> Tensor: ...
  11618. @overload
  11619. def gather(
  11620. input: Tensor,
  11621. dim: _int,
  11622. index: Tensor,
  11623. *,
  11624. sparse_grad: _bool = False,
  11625. out: Tensor | None = None,
  11626. ) -> Tensor:
  11627. r"""
  11628. gather(input, dim, index, *, sparse_grad=False, out=None) -> Tensor
  11629. Gathers values along an axis specified by `dim`.
  11630. For a 3-D tensor the output is specified by::
  11631. out[i][j][k] = input[index[i][j][k]][j][k] # if dim == 0
  11632. out[i][j][k] = input[i][index[i][j][k]][k] # if dim == 1
  11633. out[i][j][k] = input[i][j][index[i][j][k]] # if dim == 2
  11634. :attr:`input` and :attr:`index` must have the same number of dimensions.
  11635. It is also required that ``index.size(d) <= input.size(d)`` for all
  11636. dimensions ``d != dim``. :attr:`out` will have the same shape as :attr:`index`.
  11637. Note that ``input`` and ``index`` do not broadcast against each other.
  11638. When :attr:`index` is empty, we always return an empty output with the same shape
  11639. without further error checking.
  11640. Args:
  11641. input (Tensor): the source tensor
  11642. dim (int): the axis along which to index
  11643. index (LongTensor): the indices of elements to gather
  11644. Keyword arguments:
  11645. sparse_grad (bool, optional): If ``True``, gradient w.r.t. :attr:`input` will be a sparse tensor.
  11646. out (Tensor, optional): the destination tensor
  11647. Example::
  11648. >>> t = torch.tensor([[1, 2], [3, 4]])
  11649. >>> torch.gather(t, 1, torch.tensor([[0, 0], [1, 0]]))
  11650. tensor([[ 1, 1],
  11651. [ 4, 3]])
  11652. """
  11653. @overload
  11654. def gather(
  11655. input: Tensor,
  11656. dim: str | EllipsisType | None,
  11657. index: Tensor,
  11658. *,
  11659. sparse_grad: _bool = False,
  11660. out: Tensor | None = None,
  11661. ) -> Tensor:
  11662. r"""
  11663. gather(input, dim, index, *, sparse_grad=False, out=None) -> Tensor
  11664. Gathers values along an axis specified by `dim`.
  11665. For a 3-D tensor the output is specified by::
  11666. out[i][j][k] = input[index[i][j][k]][j][k] # if dim == 0
  11667. out[i][j][k] = input[i][index[i][j][k]][k] # if dim == 1
  11668. out[i][j][k] = input[i][j][index[i][j][k]] # if dim == 2
  11669. :attr:`input` and :attr:`index` must have the same number of dimensions.
  11670. It is also required that ``index.size(d) <= input.size(d)`` for all
  11671. dimensions ``d != dim``. :attr:`out` will have the same shape as :attr:`index`.
  11672. Note that ``input`` and ``index`` do not broadcast against each other.
  11673. When :attr:`index` is empty, we always return an empty output with the same shape
  11674. without further error checking.
  11675. Args:
  11676. input (Tensor): the source tensor
  11677. dim (int): the axis along which to index
  11678. index (LongTensor): the indices of elements to gather
  11679. Keyword arguments:
  11680. sparse_grad (bool, optional): If ``True``, gradient w.r.t. :attr:`input` will be a sparse tensor.
  11681. out (Tensor, optional): the destination tensor
  11682. Example::
  11683. >>> t = torch.tensor([[1, 2], [3, 4]])
  11684. >>> torch.gather(t, 1, torch.tensor([[0, 0], [1, 0]]))
  11685. tensor([[ 1, 1],
  11686. [ 4, 3]])
  11687. """
  11688. def gcd(
  11689. input: Tensor,
  11690. other: Tensor,
  11691. *,
  11692. out: Tensor | None = None,
  11693. ) -> Tensor:
  11694. r"""
  11695. gcd(input, other, *, out=None) -> Tensor
  11696. Computes the element-wise greatest common divisor (GCD) of :attr:`input` and :attr:`other`.
  11697. Both :attr:`input` and :attr:`other` must have integer types.
  11698. .. note::
  11699. This defines :math:`gcd(0, 0) = 0`.
  11700. Args:
  11701. input (Tensor): the input tensor.
  11702. other (Tensor): the second input tensor
  11703. Keyword arguments:
  11704. out (Tensor, optional): the output tensor.
  11705. Example::
  11706. >>> a = torch.tensor([5, 10, 15])
  11707. >>> b = torch.tensor([3, 4, 5])
  11708. >>> torch.gcd(a, b)
  11709. tensor([1, 2, 5])
  11710. >>> c = torch.tensor([3])
  11711. >>> torch.gcd(a, c)
  11712. tensor([1, 1, 3])
  11713. """
  11714. def gcd_(input: Tensor, other: Tensor) -> Tensor: ...
  11715. @overload
  11716. def ge(
  11717. input: Tensor,
  11718. other: Tensor,
  11719. *,
  11720. out: Tensor | None = None,
  11721. ) -> Tensor:
  11722. r"""
  11723. ge(input, other, *, out=None) -> Tensor
  11724. Computes :math:`\text{input} \geq \text{other}` element-wise.
  11725. The second argument can be a number or a tensor whose shape is
  11726. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  11727. Args:
  11728. input (Tensor): the tensor to compare
  11729. other (Tensor or float): the tensor or value to compare
  11730. Keyword args:
  11731. out (Tensor, optional): the output tensor.
  11732. Returns:
  11733. A boolean tensor that is True where :attr:`input` is greater than or equal to :attr:`other` and False elsewhere
  11734. Example::
  11735. >>> torch.ge(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  11736. tensor([[True, True], [False, True]])
  11737. """
  11738. @overload
  11739. def ge(
  11740. input: Tensor,
  11741. other: Number | _complex,
  11742. *,
  11743. out: Tensor | None = None,
  11744. ) -> Tensor:
  11745. r"""
  11746. ge(input, other, *, out=None) -> Tensor
  11747. Computes :math:`\text{input} \geq \text{other}` element-wise.
  11748. The second argument can be a number or a tensor whose shape is
  11749. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  11750. Args:
  11751. input (Tensor): the tensor to compare
  11752. other (Tensor or float): the tensor or value to compare
  11753. Keyword args:
  11754. out (Tensor, optional): the output tensor.
  11755. Returns:
  11756. A boolean tensor that is True where :attr:`input` is greater than or equal to :attr:`other` and False elsewhere
  11757. Example::
  11758. >>> torch.ge(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  11759. tensor([[True, True], [False, True]])
  11760. """
  11761. def geqrf(
  11762. input: Tensor,
  11763. *,
  11764. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  11765. ) -> torch.return_types.geqrf:
  11766. r"""
  11767. geqrf(input, *, out=None) -> (Tensor, Tensor)
  11768. This is a low-level function for calling LAPACK's geqrf directly. This function
  11769. returns a namedtuple (a, tau) as defined in `LAPACK documentation for geqrf`_ .
  11770. Computes a QR decomposition of :attr:`input`.
  11771. Both `Q` and `R` matrices are stored in the same output tensor `a`.
  11772. The elements of `R` are stored on and above the diagonal.
  11773. Elementary reflectors (or Householder vectors) implicitly defining matrix `Q`
  11774. are stored below the diagonal.
  11775. The results of this function can be used together with :func:`torch.linalg.householder_product`
  11776. to obtain the `Q` matrix or
  11777. with :func:`torch.ormqr`, which uses an implicit representation of the `Q` matrix,
  11778. for an efficient matrix-matrix multiplication.
  11779. See `LAPACK documentation for geqrf`_ for further details.
  11780. .. note::
  11781. See also :func:`torch.linalg.qr`, which computes Q and R matrices, and :func:`torch.linalg.lstsq`
  11782. with the ``driver="gels"`` option for a function that can solve matrix equations using a QR decomposition.
  11783. Args:
  11784. input (Tensor): the input matrix
  11785. Keyword args:
  11786. out (tuple, optional): the output tuple of (Tensor, Tensor). Ignored if `None`. Default: `None`.
  11787. .. _LAPACK documentation for geqrf:
  11788. http://www.netlib.org/lapack/explore-html/df/dc5/group__variants_g_ecomputational_ga3766ea903391b5cf9008132f7440ec7b.html
  11789. """
  11790. def ger(
  11791. input: Tensor,
  11792. vec2: Tensor,
  11793. *,
  11794. out: Tensor | None = None,
  11795. ) -> Tensor:
  11796. r"""
  11797. ger(input, vec2, *, out=None) -> Tensor
  11798. Alias of :func:`torch.outer`.
  11799. .. warning::
  11800. This function is deprecated and will be removed in a future PyTorch release.
  11801. Use :func:`torch.outer` instead.
  11802. """
  11803. def get_default_dtype() -> _dtype:
  11804. r"""
  11805. get_default_dtype() -> torch.dtype
  11806. Get the current default floating point :class:`torch.dtype`.
  11807. Example::
  11808. >>> torch.get_default_dtype() # initial default for floating point is torch.float32
  11809. torch.float32
  11810. >>> torch.set_default_dtype(torch.float64)
  11811. >>> torch.get_default_dtype() # default is now changed to torch.float64
  11812. torch.float64
  11813. """
  11814. def get_num_interop_threads() -> _int:
  11815. r"""
  11816. get_num_interop_threads() -> int
  11817. Returns the number of threads used for inter-op parallelism on CPU
  11818. (e.g. in JIT interpreter)
  11819. """
  11820. def get_num_threads() -> _int:
  11821. r"""
  11822. get_num_threads() -> int
  11823. Returns the number of threads used for parallelizing CPU operations
  11824. """
  11825. @overload
  11826. def gradient(
  11827. input: Tensor,
  11828. *,
  11829. spacing: Number | _complex | None = None,
  11830. dim: _int | None = None,
  11831. edge_order: _int = 1,
  11832. ) -> tuple[Tensor, ...]:
  11833. r"""
  11834. gradient(input, *, spacing=1, dim=None, edge_order=1) -> List of Tensors
  11835. Estimates the gradient of a function :math:`g : \mathbb{R}^n \rightarrow \mathbb{R}` in
  11836. one or more dimensions using the `second-order accurate central differences method
  11837. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ and
  11838. either first or second order estimates at the boundaries.
  11839. The gradient of :math:`g` is estimated using samples. By default, when :attr:`spacing` is not
  11840. specified, the samples are entirely described by :attr:`input`, and the mapping of input coordinates
  11841. to an output is the same as the tensor's mapping of indices to values. For example, for a three-dimensional
  11842. :attr:`input` the function described is :math:`g : \mathbb{R}^3 \rightarrow \mathbb{R}`, and
  11843. :math:`g(1, 2, 3)\ == input[1, 2, 3]`.
  11844. When :attr:`spacing` is specified, it modifies the relationship between :attr:`input` and input coordinates.
  11845. This is detailed in the "Keyword Arguments" section below.
  11846. The gradient is estimated by estimating each partial derivative of :math:`g` independently. This estimation is
  11847. accurate if :math:`g` is in :math:`C^3` (it has at least 3 continuous derivatives), and the estimation can be
  11848. improved by providing closer samples. Mathematically, the value at each interior point of a partial derivative
  11849. is estimated using `Taylor's theorem with remainder <https://en.wikipedia.org/wiki/Taylor%27s_theorem>`_.
  11850. Letting :math:`x` be an interior point with :math:`x-h_l` and :math:`x+h_r` be points neighboring
  11851. it to the left and right respectively, :math:`f(x+h_r)` and :math:`f(x-h_l)` can be estimated using:
  11852. .. math::
  11853. \begin{aligned}
  11854. 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) \\
  11855. 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) \\
  11856. \end{aligned}
  11857. Using the fact that :math:`f \in C^3` and solving the linear system, we derive:
  11858. .. math::
  11859. f'(x) \approx \frac{ {h_l}^2 f(x+h_r) - {h_r}^2 f(x-h_l)
  11860. + ({h_r}^2-{h_l}^2 ) f(x) }{ {h_r} {h_l}^2 + {h_r}^2 {h_l} }
  11861. .. note::
  11862. We estimate the gradient of functions in complex domain
  11863. :math:`g : \mathbb{C}^n \rightarrow \mathbb{C}` in the same way.
  11864. The value of each partial derivative at the boundary points is computed differently. See edge_order below.
  11865. Args:
  11866. input (``Tensor``): the tensor that represents the values of the function
  11867. Keyword args:
  11868. spacing (``scalar``, ``list of scalar``, ``list of Tensor``, optional): :attr:`spacing` can be used to modify
  11869. how the :attr:`input` tensor's indices relate to sample coordinates. If :attr:`spacing` is a scalar then
  11870. the indices are multiplied by the scalar to produce the coordinates. For example, if :attr:`spacing=2` the
  11871. indices (1, 2, 3) become coordinates (2, 4, 6). If :attr:`spacing` is a list of scalars then the corresponding
  11872. indices are multiplied. For example, if :attr:`spacing=(2, -1, 3)` the indices (1, 2, 3) become coordinates (2, -2, 9).
  11873. Finally, if :attr:`spacing` is a list of one-dimensional tensors then each tensor specifies the coordinates for
  11874. the corresponding dimension. For example, if the indices are (1, 2, 3) and the tensors are (t0, t1, t2), then
  11875. the coordinates are (t0[1], t1[2], t2[3])
  11876. dim (``int``, ``list of int``, optional): the dimension or dimensions to approximate the gradient over. By default
  11877. the partial gradient in every dimension is computed. Note that when :attr:`dim` is specified the elements of
  11878. the :attr:`spacing` argument must correspond with the specified dims."
  11879. edge_order (``int``, optional): 1 or 2, for `first-order
  11880. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ or
  11881. `second-order <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_
  11882. estimation of the boundary ("edge") values, respectively. Note that when :attr:`edge_order` is specified, each
  11883. dimension size of :attr:`input` should be at least edge_order+1
  11884. Examples::
  11885. >>> # Estimates the gradient of f(x)=x^2 at points [-2, -1, 2, 4]
  11886. >>> coordinates = (torch.tensor([-2., -1., 1., 4.]),)
  11887. >>> values = torch.tensor([4., 1., 1., 16.], )
  11888. >>> torch.gradient(values, spacing = coordinates)
  11889. (tensor([-3., -2., 2., 5.]),)
  11890. >>> # Estimates the gradient of the R^2 -> R function whose samples are
  11891. >>> # described by the tensor t. Implicit coordinates are [0, 1] for the outermost
  11892. >>> # dimension and [0, 1, 2, 3] for the innermost dimension, and function estimates
  11893. >>> # partial derivative for both dimensions.
  11894. >>> t = torch.tensor([[1, 2, 4, 8], [10, 20, 40, 80]])
  11895. >>> torch.gradient(t)
  11896. (tensor([[ 9., 18., 36., 72.],
  11897. [ 9., 18., 36., 72.]]),
  11898. tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  11899. [10.0000, 15.0000, 30.0000, 40.0000]]))
  11900. >>> # A scalar value for spacing modifies the relationship between tensor indices
  11901. >>> # and input coordinates by multiplying the indices to find the
  11902. >>> # coordinates. For example, below the indices of the innermost
  11903. >>> # 0, 1, 2, 3 translate to coordinates of [0, 2, 4, 6], and the indices of
  11904. >>> # the outermost dimension 0, 1 translate to coordinates of [0, 2].
  11905. >>> torch.gradient(t, spacing = 2.0) # dim = None (implicitly [0, 1])
  11906. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  11907. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  11908. tensor([[ 0.5000, 0.7500, 1.5000, 2.0000],
  11909. [ 5.0000, 7.5000, 15.0000, 20.0000]]))
  11910. >>> # doubling the spacing between samples halves the estimated partial gradients.
  11911. >>>
  11912. >>> # Estimates only the partial derivative for dimension 1
  11913. >>> torch.gradient(t, dim = 1) # spacing = None (implicitly 1.)
  11914. (tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  11915. [10.0000, 15.0000, 30.0000, 40.0000]]),)
  11916. >>> # When spacing is a list of scalars, the relationship between the tensor
  11917. >>> # indices and input coordinates changes based on dimension.
  11918. >>> # For example, below, the indices of the innermost dimension 0, 1, 2, 3 translate
  11919. >>> # to coordinates of [0, 3, 6, 9], and the indices of the outermost dimension
  11920. >>> # 0, 1 translate to coordinates of [0, 2].
  11921. >>> torch.gradient(t, spacing = [3., 2.])
  11922. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  11923. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  11924. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  11925. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  11926. >>> # The following example is a replication of the previous one with explicit
  11927. >>> # coordinates.
  11928. >>> coords = (torch.tensor([0, 2]), torch.tensor([0, 3, 6, 9]))
  11929. >>> torch.gradient(t, spacing = coords)
  11930. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  11931. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  11932. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  11933. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  11934. """
  11935. @overload
  11936. def gradient(
  11937. input: Tensor,
  11938. *,
  11939. spacing: Sequence[Number | _complex],
  11940. dim: _int | None = None,
  11941. edge_order: _int = 1,
  11942. ) -> tuple[Tensor, ...]:
  11943. r"""
  11944. gradient(input, *, spacing=1, dim=None, edge_order=1) -> List of Tensors
  11945. Estimates the gradient of a function :math:`g : \mathbb{R}^n \rightarrow \mathbb{R}` in
  11946. one or more dimensions using the `second-order accurate central differences method
  11947. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ and
  11948. either first or second order estimates at the boundaries.
  11949. The gradient of :math:`g` is estimated using samples. By default, when :attr:`spacing` is not
  11950. specified, the samples are entirely described by :attr:`input`, and the mapping of input coordinates
  11951. to an output is the same as the tensor's mapping of indices to values. For example, for a three-dimensional
  11952. :attr:`input` the function described is :math:`g : \mathbb{R}^3 \rightarrow \mathbb{R}`, and
  11953. :math:`g(1, 2, 3)\ == input[1, 2, 3]`.
  11954. When :attr:`spacing` is specified, it modifies the relationship between :attr:`input` and input coordinates.
  11955. This is detailed in the "Keyword Arguments" section below.
  11956. The gradient is estimated by estimating each partial derivative of :math:`g` independently. This estimation is
  11957. accurate if :math:`g` is in :math:`C^3` (it has at least 3 continuous derivatives), and the estimation can be
  11958. improved by providing closer samples. Mathematically, the value at each interior point of a partial derivative
  11959. is estimated using `Taylor's theorem with remainder <https://en.wikipedia.org/wiki/Taylor%27s_theorem>`_.
  11960. Letting :math:`x` be an interior point with :math:`x-h_l` and :math:`x+h_r` be points neighboring
  11961. it to the left and right respectively, :math:`f(x+h_r)` and :math:`f(x-h_l)` can be estimated using:
  11962. .. math::
  11963. \begin{aligned}
  11964. 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) \\
  11965. 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) \\
  11966. \end{aligned}
  11967. Using the fact that :math:`f \in C^3` and solving the linear system, we derive:
  11968. .. math::
  11969. f'(x) \approx \frac{ {h_l}^2 f(x+h_r) - {h_r}^2 f(x-h_l)
  11970. + ({h_r}^2-{h_l}^2 ) f(x) }{ {h_r} {h_l}^2 + {h_r}^2 {h_l} }
  11971. .. note::
  11972. We estimate the gradient of functions in complex domain
  11973. :math:`g : \mathbb{C}^n \rightarrow \mathbb{C}` in the same way.
  11974. The value of each partial derivative at the boundary points is computed differently. See edge_order below.
  11975. Args:
  11976. input (``Tensor``): the tensor that represents the values of the function
  11977. Keyword args:
  11978. spacing (``scalar``, ``list of scalar``, ``list of Tensor``, optional): :attr:`spacing` can be used to modify
  11979. how the :attr:`input` tensor's indices relate to sample coordinates. If :attr:`spacing` is a scalar then
  11980. the indices are multiplied by the scalar to produce the coordinates. For example, if :attr:`spacing=2` the
  11981. indices (1, 2, 3) become coordinates (2, 4, 6). If :attr:`spacing` is a list of scalars then the corresponding
  11982. indices are multiplied. For example, if :attr:`spacing=(2, -1, 3)` the indices (1, 2, 3) become coordinates (2, -2, 9).
  11983. Finally, if :attr:`spacing` is a list of one-dimensional tensors then each tensor specifies the coordinates for
  11984. the corresponding dimension. For example, if the indices are (1, 2, 3) and the tensors are (t0, t1, t2), then
  11985. the coordinates are (t0[1], t1[2], t2[3])
  11986. dim (``int``, ``list of int``, optional): the dimension or dimensions to approximate the gradient over. By default
  11987. the partial gradient in every dimension is computed. Note that when :attr:`dim` is specified the elements of
  11988. the :attr:`spacing` argument must correspond with the specified dims."
  11989. edge_order (``int``, optional): 1 or 2, for `first-order
  11990. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ or
  11991. `second-order <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_
  11992. estimation of the boundary ("edge") values, respectively. Note that when :attr:`edge_order` is specified, each
  11993. dimension size of :attr:`input` should be at least edge_order+1
  11994. Examples::
  11995. >>> # Estimates the gradient of f(x)=x^2 at points [-2, -1, 2, 4]
  11996. >>> coordinates = (torch.tensor([-2., -1., 1., 4.]),)
  11997. >>> values = torch.tensor([4., 1., 1., 16.], )
  11998. >>> torch.gradient(values, spacing = coordinates)
  11999. (tensor([-3., -2., 2., 5.]),)
  12000. >>> # Estimates the gradient of the R^2 -> R function whose samples are
  12001. >>> # described by the tensor t. Implicit coordinates are [0, 1] for the outermost
  12002. >>> # dimension and [0, 1, 2, 3] for the innermost dimension, and function estimates
  12003. >>> # partial derivative for both dimensions.
  12004. >>> t = torch.tensor([[1, 2, 4, 8], [10, 20, 40, 80]])
  12005. >>> torch.gradient(t)
  12006. (tensor([[ 9., 18., 36., 72.],
  12007. [ 9., 18., 36., 72.]]),
  12008. tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12009. [10.0000, 15.0000, 30.0000, 40.0000]]))
  12010. >>> # A scalar value for spacing modifies the relationship between tensor indices
  12011. >>> # and input coordinates by multiplying the indices to find the
  12012. >>> # coordinates. For example, below the indices of the innermost
  12013. >>> # 0, 1, 2, 3 translate to coordinates of [0, 2, 4, 6], and the indices of
  12014. >>> # the outermost dimension 0, 1 translate to coordinates of [0, 2].
  12015. >>> torch.gradient(t, spacing = 2.0) # dim = None (implicitly [0, 1])
  12016. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12017. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12018. tensor([[ 0.5000, 0.7500, 1.5000, 2.0000],
  12019. [ 5.0000, 7.5000, 15.0000, 20.0000]]))
  12020. >>> # doubling the spacing between samples halves the estimated partial gradients.
  12021. >>>
  12022. >>> # Estimates only the partial derivative for dimension 1
  12023. >>> torch.gradient(t, dim = 1) # spacing = None (implicitly 1.)
  12024. (tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12025. [10.0000, 15.0000, 30.0000, 40.0000]]),)
  12026. >>> # When spacing is a list of scalars, the relationship between the tensor
  12027. >>> # indices and input coordinates changes based on dimension.
  12028. >>> # For example, below, the indices of the innermost dimension 0, 1, 2, 3 translate
  12029. >>> # to coordinates of [0, 3, 6, 9], and the indices of the outermost dimension
  12030. >>> # 0, 1 translate to coordinates of [0, 2].
  12031. >>> torch.gradient(t, spacing = [3., 2.])
  12032. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12033. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12034. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12035. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12036. >>> # The following example is a replication of the previous one with explicit
  12037. >>> # coordinates.
  12038. >>> coords = (torch.tensor([0, 2]), torch.tensor([0, 3, 6, 9]))
  12039. >>> torch.gradient(t, spacing = coords)
  12040. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12041. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12042. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12043. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12044. """
  12045. @overload
  12046. def gradient(
  12047. input: Tensor,
  12048. *,
  12049. spacing: Sequence[Number | _complex],
  12050. dim: _size,
  12051. edge_order: _int = 1,
  12052. ) -> tuple[Tensor, ...]:
  12053. r"""
  12054. gradient(input, *, spacing=1, dim=None, edge_order=1) -> List of Tensors
  12055. Estimates the gradient of a function :math:`g : \mathbb{R}^n \rightarrow \mathbb{R}` in
  12056. one or more dimensions using the `second-order accurate central differences method
  12057. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ and
  12058. either first or second order estimates at the boundaries.
  12059. The gradient of :math:`g` is estimated using samples. By default, when :attr:`spacing` is not
  12060. specified, the samples are entirely described by :attr:`input`, and the mapping of input coordinates
  12061. to an output is the same as the tensor's mapping of indices to values. For example, for a three-dimensional
  12062. :attr:`input` the function described is :math:`g : \mathbb{R}^3 \rightarrow \mathbb{R}`, and
  12063. :math:`g(1, 2, 3)\ == input[1, 2, 3]`.
  12064. When :attr:`spacing` is specified, it modifies the relationship between :attr:`input` and input coordinates.
  12065. This is detailed in the "Keyword Arguments" section below.
  12066. The gradient is estimated by estimating each partial derivative of :math:`g` independently. This estimation is
  12067. accurate if :math:`g` is in :math:`C^3` (it has at least 3 continuous derivatives), and the estimation can be
  12068. improved by providing closer samples. Mathematically, the value at each interior point of a partial derivative
  12069. is estimated using `Taylor's theorem with remainder <https://en.wikipedia.org/wiki/Taylor%27s_theorem>`_.
  12070. Letting :math:`x` be an interior point with :math:`x-h_l` and :math:`x+h_r` be points neighboring
  12071. it to the left and right respectively, :math:`f(x+h_r)` and :math:`f(x-h_l)` can be estimated using:
  12072. .. math::
  12073. \begin{aligned}
  12074. 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) \\
  12075. 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) \\
  12076. \end{aligned}
  12077. Using the fact that :math:`f \in C^3` and solving the linear system, we derive:
  12078. .. math::
  12079. f'(x) \approx \frac{ {h_l}^2 f(x+h_r) - {h_r}^2 f(x-h_l)
  12080. + ({h_r}^2-{h_l}^2 ) f(x) }{ {h_r} {h_l}^2 + {h_r}^2 {h_l} }
  12081. .. note::
  12082. We estimate the gradient of functions in complex domain
  12083. :math:`g : \mathbb{C}^n \rightarrow \mathbb{C}` in the same way.
  12084. The value of each partial derivative at the boundary points is computed differently. See edge_order below.
  12085. Args:
  12086. input (``Tensor``): the tensor that represents the values of the function
  12087. Keyword args:
  12088. spacing (``scalar``, ``list of scalar``, ``list of Tensor``, optional): :attr:`spacing` can be used to modify
  12089. how the :attr:`input` tensor's indices relate to sample coordinates. If :attr:`spacing` is a scalar then
  12090. the indices are multiplied by the scalar to produce the coordinates. For example, if :attr:`spacing=2` the
  12091. indices (1, 2, 3) become coordinates (2, 4, 6). If :attr:`spacing` is a list of scalars then the corresponding
  12092. indices are multiplied. For example, if :attr:`spacing=(2, -1, 3)` the indices (1, 2, 3) become coordinates (2, -2, 9).
  12093. Finally, if :attr:`spacing` is a list of one-dimensional tensors then each tensor specifies the coordinates for
  12094. the corresponding dimension. For example, if the indices are (1, 2, 3) and the tensors are (t0, t1, t2), then
  12095. the coordinates are (t0[1], t1[2], t2[3])
  12096. dim (``int``, ``list of int``, optional): the dimension or dimensions to approximate the gradient over. By default
  12097. the partial gradient in every dimension is computed. Note that when :attr:`dim` is specified the elements of
  12098. the :attr:`spacing` argument must correspond with the specified dims."
  12099. edge_order (``int``, optional): 1 or 2, for `first-order
  12100. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ or
  12101. `second-order <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_
  12102. estimation of the boundary ("edge") values, respectively. Note that when :attr:`edge_order` is specified, each
  12103. dimension size of :attr:`input` should be at least edge_order+1
  12104. Examples::
  12105. >>> # Estimates the gradient of f(x)=x^2 at points [-2, -1, 2, 4]
  12106. >>> coordinates = (torch.tensor([-2., -1., 1., 4.]),)
  12107. >>> values = torch.tensor([4., 1., 1., 16.], )
  12108. >>> torch.gradient(values, spacing = coordinates)
  12109. (tensor([-3., -2., 2., 5.]),)
  12110. >>> # Estimates the gradient of the R^2 -> R function whose samples are
  12111. >>> # described by the tensor t. Implicit coordinates are [0, 1] for the outermost
  12112. >>> # dimension and [0, 1, 2, 3] for the innermost dimension, and function estimates
  12113. >>> # partial derivative for both dimensions.
  12114. >>> t = torch.tensor([[1, 2, 4, 8], [10, 20, 40, 80]])
  12115. >>> torch.gradient(t)
  12116. (tensor([[ 9., 18., 36., 72.],
  12117. [ 9., 18., 36., 72.]]),
  12118. tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12119. [10.0000, 15.0000, 30.0000, 40.0000]]))
  12120. >>> # A scalar value for spacing modifies the relationship between tensor indices
  12121. >>> # and input coordinates by multiplying the indices to find the
  12122. >>> # coordinates. For example, below the indices of the innermost
  12123. >>> # 0, 1, 2, 3 translate to coordinates of [0, 2, 4, 6], and the indices of
  12124. >>> # the outermost dimension 0, 1 translate to coordinates of [0, 2].
  12125. >>> torch.gradient(t, spacing = 2.0) # dim = None (implicitly [0, 1])
  12126. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12127. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12128. tensor([[ 0.5000, 0.7500, 1.5000, 2.0000],
  12129. [ 5.0000, 7.5000, 15.0000, 20.0000]]))
  12130. >>> # doubling the spacing between samples halves the estimated partial gradients.
  12131. >>>
  12132. >>> # Estimates only the partial derivative for dimension 1
  12133. >>> torch.gradient(t, dim = 1) # spacing = None (implicitly 1.)
  12134. (tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12135. [10.0000, 15.0000, 30.0000, 40.0000]]),)
  12136. >>> # When spacing is a list of scalars, the relationship between the tensor
  12137. >>> # indices and input coordinates changes based on dimension.
  12138. >>> # For example, below, the indices of the innermost dimension 0, 1, 2, 3 translate
  12139. >>> # to coordinates of [0, 3, 6, 9], and the indices of the outermost dimension
  12140. >>> # 0, 1 translate to coordinates of [0, 2].
  12141. >>> torch.gradient(t, spacing = [3., 2.])
  12142. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12143. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12144. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12145. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12146. >>> # The following example is a replication of the previous one with explicit
  12147. >>> # coordinates.
  12148. >>> coords = (torch.tensor([0, 2]), torch.tensor([0, 3, 6, 9]))
  12149. >>> torch.gradient(t, spacing = coords)
  12150. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12151. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12152. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12153. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12154. """
  12155. @overload
  12156. def gradient(
  12157. input: Tensor,
  12158. *,
  12159. spacing: tuple[Tensor, ...] | list[Tensor] | None,
  12160. dim: _int | None = None,
  12161. edge_order: _int = 1,
  12162. ) -> tuple[Tensor, ...]:
  12163. r"""
  12164. gradient(input, *, spacing=1, dim=None, edge_order=1) -> List of Tensors
  12165. Estimates the gradient of a function :math:`g : \mathbb{R}^n \rightarrow \mathbb{R}` in
  12166. one or more dimensions using the `second-order accurate central differences method
  12167. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ and
  12168. either first or second order estimates at the boundaries.
  12169. The gradient of :math:`g` is estimated using samples. By default, when :attr:`spacing` is not
  12170. specified, the samples are entirely described by :attr:`input`, and the mapping of input coordinates
  12171. to an output is the same as the tensor's mapping of indices to values. For example, for a three-dimensional
  12172. :attr:`input` the function described is :math:`g : \mathbb{R}^3 \rightarrow \mathbb{R}`, and
  12173. :math:`g(1, 2, 3)\ == input[1, 2, 3]`.
  12174. When :attr:`spacing` is specified, it modifies the relationship between :attr:`input` and input coordinates.
  12175. This is detailed in the "Keyword Arguments" section below.
  12176. The gradient is estimated by estimating each partial derivative of :math:`g` independently. This estimation is
  12177. accurate if :math:`g` is in :math:`C^3` (it has at least 3 continuous derivatives), and the estimation can be
  12178. improved by providing closer samples. Mathematically, the value at each interior point of a partial derivative
  12179. is estimated using `Taylor's theorem with remainder <https://en.wikipedia.org/wiki/Taylor%27s_theorem>`_.
  12180. Letting :math:`x` be an interior point with :math:`x-h_l` and :math:`x+h_r` be points neighboring
  12181. it to the left and right respectively, :math:`f(x+h_r)` and :math:`f(x-h_l)` can be estimated using:
  12182. .. math::
  12183. \begin{aligned}
  12184. 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) \\
  12185. 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) \\
  12186. \end{aligned}
  12187. Using the fact that :math:`f \in C^3` and solving the linear system, we derive:
  12188. .. math::
  12189. f'(x) \approx \frac{ {h_l}^2 f(x+h_r) - {h_r}^2 f(x-h_l)
  12190. + ({h_r}^2-{h_l}^2 ) f(x) }{ {h_r} {h_l}^2 + {h_r}^2 {h_l} }
  12191. .. note::
  12192. We estimate the gradient of functions in complex domain
  12193. :math:`g : \mathbb{C}^n \rightarrow \mathbb{C}` in the same way.
  12194. The value of each partial derivative at the boundary points is computed differently. See edge_order below.
  12195. Args:
  12196. input (``Tensor``): the tensor that represents the values of the function
  12197. Keyword args:
  12198. spacing (``scalar``, ``list of scalar``, ``list of Tensor``, optional): :attr:`spacing` can be used to modify
  12199. how the :attr:`input` tensor's indices relate to sample coordinates. If :attr:`spacing` is a scalar then
  12200. the indices are multiplied by the scalar to produce the coordinates. For example, if :attr:`spacing=2` the
  12201. indices (1, 2, 3) become coordinates (2, 4, 6). If :attr:`spacing` is a list of scalars then the corresponding
  12202. indices are multiplied. For example, if :attr:`spacing=(2, -1, 3)` the indices (1, 2, 3) become coordinates (2, -2, 9).
  12203. Finally, if :attr:`spacing` is a list of one-dimensional tensors then each tensor specifies the coordinates for
  12204. the corresponding dimension. For example, if the indices are (1, 2, 3) and the tensors are (t0, t1, t2), then
  12205. the coordinates are (t0[1], t1[2], t2[3])
  12206. dim (``int``, ``list of int``, optional): the dimension or dimensions to approximate the gradient over. By default
  12207. the partial gradient in every dimension is computed. Note that when :attr:`dim` is specified the elements of
  12208. the :attr:`spacing` argument must correspond with the specified dims."
  12209. edge_order (``int``, optional): 1 or 2, for `first-order
  12210. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ or
  12211. `second-order <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_
  12212. estimation of the boundary ("edge") values, respectively. Note that when :attr:`edge_order` is specified, each
  12213. dimension size of :attr:`input` should be at least edge_order+1
  12214. Examples::
  12215. >>> # Estimates the gradient of f(x)=x^2 at points [-2, -1, 2, 4]
  12216. >>> coordinates = (torch.tensor([-2., -1., 1., 4.]),)
  12217. >>> values = torch.tensor([4., 1., 1., 16.], )
  12218. >>> torch.gradient(values, spacing = coordinates)
  12219. (tensor([-3., -2., 2., 5.]),)
  12220. >>> # Estimates the gradient of the R^2 -> R function whose samples are
  12221. >>> # described by the tensor t. Implicit coordinates are [0, 1] for the outermost
  12222. >>> # dimension and [0, 1, 2, 3] for the innermost dimension, and function estimates
  12223. >>> # partial derivative for both dimensions.
  12224. >>> t = torch.tensor([[1, 2, 4, 8], [10, 20, 40, 80]])
  12225. >>> torch.gradient(t)
  12226. (tensor([[ 9., 18., 36., 72.],
  12227. [ 9., 18., 36., 72.]]),
  12228. tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12229. [10.0000, 15.0000, 30.0000, 40.0000]]))
  12230. >>> # A scalar value for spacing modifies the relationship between tensor indices
  12231. >>> # and input coordinates by multiplying the indices to find the
  12232. >>> # coordinates. For example, below the indices of the innermost
  12233. >>> # 0, 1, 2, 3 translate to coordinates of [0, 2, 4, 6], and the indices of
  12234. >>> # the outermost dimension 0, 1 translate to coordinates of [0, 2].
  12235. >>> torch.gradient(t, spacing = 2.0) # dim = None (implicitly [0, 1])
  12236. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12237. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12238. tensor([[ 0.5000, 0.7500, 1.5000, 2.0000],
  12239. [ 5.0000, 7.5000, 15.0000, 20.0000]]))
  12240. >>> # doubling the spacing between samples halves the estimated partial gradients.
  12241. >>>
  12242. >>> # Estimates only the partial derivative for dimension 1
  12243. >>> torch.gradient(t, dim = 1) # spacing = None (implicitly 1.)
  12244. (tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12245. [10.0000, 15.0000, 30.0000, 40.0000]]),)
  12246. >>> # When spacing is a list of scalars, the relationship between the tensor
  12247. >>> # indices and input coordinates changes based on dimension.
  12248. >>> # For example, below, the indices of the innermost dimension 0, 1, 2, 3 translate
  12249. >>> # to coordinates of [0, 3, 6, 9], and the indices of the outermost dimension
  12250. >>> # 0, 1 translate to coordinates of [0, 2].
  12251. >>> torch.gradient(t, spacing = [3., 2.])
  12252. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12253. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12254. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12255. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12256. >>> # The following example is a replication of the previous one with explicit
  12257. >>> # coordinates.
  12258. >>> coords = (torch.tensor([0, 2]), torch.tensor([0, 3, 6, 9]))
  12259. >>> torch.gradient(t, spacing = coords)
  12260. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12261. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12262. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12263. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12264. """
  12265. @overload
  12266. def gradient(
  12267. input: Tensor,
  12268. *,
  12269. spacing: Number | _complex,
  12270. dim: _size,
  12271. edge_order: _int = 1,
  12272. ) -> tuple[Tensor, ...]:
  12273. r"""
  12274. gradient(input, *, spacing=1, dim=None, edge_order=1) -> List of Tensors
  12275. Estimates the gradient of a function :math:`g : \mathbb{R}^n \rightarrow \mathbb{R}` in
  12276. one or more dimensions using the `second-order accurate central differences method
  12277. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ and
  12278. either first or second order estimates at the boundaries.
  12279. The gradient of :math:`g` is estimated using samples. By default, when :attr:`spacing` is not
  12280. specified, the samples are entirely described by :attr:`input`, and the mapping of input coordinates
  12281. to an output is the same as the tensor's mapping of indices to values. For example, for a three-dimensional
  12282. :attr:`input` the function described is :math:`g : \mathbb{R}^3 \rightarrow \mathbb{R}`, and
  12283. :math:`g(1, 2, 3)\ == input[1, 2, 3]`.
  12284. When :attr:`spacing` is specified, it modifies the relationship between :attr:`input` and input coordinates.
  12285. This is detailed in the "Keyword Arguments" section below.
  12286. The gradient is estimated by estimating each partial derivative of :math:`g` independently. This estimation is
  12287. accurate if :math:`g` is in :math:`C^3` (it has at least 3 continuous derivatives), and the estimation can be
  12288. improved by providing closer samples. Mathematically, the value at each interior point of a partial derivative
  12289. is estimated using `Taylor's theorem with remainder <https://en.wikipedia.org/wiki/Taylor%27s_theorem>`_.
  12290. Letting :math:`x` be an interior point with :math:`x-h_l` and :math:`x+h_r` be points neighboring
  12291. it to the left and right respectively, :math:`f(x+h_r)` and :math:`f(x-h_l)` can be estimated using:
  12292. .. math::
  12293. \begin{aligned}
  12294. 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) \\
  12295. 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) \\
  12296. \end{aligned}
  12297. Using the fact that :math:`f \in C^3` and solving the linear system, we derive:
  12298. .. math::
  12299. f'(x) \approx \frac{ {h_l}^2 f(x+h_r) - {h_r}^2 f(x-h_l)
  12300. + ({h_r}^2-{h_l}^2 ) f(x) }{ {h_r} {h_l}^2 + {h_r}^2 {h_l} }
  12301. .. note::
  12302. We estimate the gradient of functions in complex domain
  12303. :math:`g : \mathbb{C}^n \rightarrow \mathbb{C}` in the same way.
  12304. The value of each partial derivative at the boundary points is computed differently. See edge_order below.
  12305. Args:
  12306. input (``Tensor``): the tensor that represents the values of the function
  12307. Keyword args:
  12308. spacing (``scalar``, ``list of scalar``, ``list of Tensor``, optional): :attr:`spacing` can be used to modify
  12309. how the :attr:`input` tensor's indices relate to sample coordinates. If :attr:`spacing` is a scalar then
  12310. the indices are multiplied by the scalar to produce the coordinates. For example, if :attr:`spacing=2` the
  12311. indices (1, 2, 3) become coordinates (2, 4, 6). If :attr:`spacing` is a list of scalars then the corresponding
  12312. indices are multiplied. For example, if :attr:`spacing=(2, -1, 3)` the indices (1, 2, 3) become coordinates (2, -2, 9).
  12313. Finally, if :attr:`spacing` is a list of one-dimensional tensors then each tensor specifies the coordinates for
  12314. the corresponding dimension. For example, if the indices are (1, 2, 3) and the tensors are (t0, t1, t2), then
  12315. the coordinates are (t0[1], t1[2], t2[3])
  12316. dim (``int``, ``list of int``, optional): the dimension or dimensions to approximate the gradient over. By default
  12317. the partial gradient in every dimension is computed. Note that when :attr:`dim` is specified the elements of
  12318. the :attr:`spacing` argument must correspond with the specified dims."
  12319. edge_order (``int``, optional): 1 or 2, for `first-order
  12320. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ or
  12321. `second-order <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_
  12322. estimation of the boundary ("edge") values, respectively. Note that when :attr:`edge_order` is specified, each
  12323. dimension size of :attr:`input` should be at least edge_order+1
  12324. Examples::
  12325. >>> # Estimates the gradient of f(x)=x^2 at points [-2, -1, 2, 4]
  12326. >>> coordinates = (torch.tensor([-2., -1., 1., 4.]),)
  12327. >>> values = torch.tensor([4., 1., 1., 16.], )
  12328. >>> torch.gradient(values, spacing = coordinates)
  12329. (tensor([-3., -2., 2., 5.]),)
  12330. >>> # Estimates the gradient of the R^2 -> R function whose samples are
  12331. >>> # described by the tensor t. Implicit coordinates are [0, 1] for the outermost
  12332. >>> # dimension and [0, 1, 2, 3] for the innermost dimension, and function estimates
  12333. >>> # partial derivative for both dimensions.
  12334. >>> t = torch.tensor([[1, 2, 4, 8], [10, 20, 40, 80]])
  12335. >>> torch.gradient(t)
  12336. (tensor([[ 9., 18., 36., 72.],
  12337. [ 9., 18., 36., 72.]]),
  12338. tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12339. [10.0000, 15.0000, 30.0000, 40.0000]]))
  12340. >>> # A scalar value for spacing modifies the relationship between tensor indices
  12341. >>> # and input coordinates by multiplying the indices to find the
  12342. >>> # coordinates. For example, below the indices of the innermost
  12343. >>> # 0, 1, 2, 3 translate to coordinates of [0, 2, 4, 6], and the indices of
  12344. >>> # the outermost dimension 0, 1 translate to coordinates of [0, 2].
  12345. >>> torch.gradient(t, spacing = 2.0) # dim = None (implicitly [0, 1])
  12346. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12347. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12348. tensor([[ 0.5000, 0.7500, 1.5000, 2.0000],
  12349. [ 5.0000, 7.5000, 15.0000, 20.0000]]))
  12350. >>> # doubling the spacing between samples halves the estimated partial gradients.
  12351. >>>
  12352. >>> # Estimates only the partial derivative for dimension 1
  12353. >>> torch.gradient(t, dim = 1) # spacing = None (implicitly 1.)
  12354. (tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12355. [10.0000, 15.0000, 30.0000, 40.0000]]),)
  12356. >>> # When spacing is a list of scalars, the relationship between the tensor
  12357. >>> # indices and input coordinates changes based on dimension.
  12358. >>> # For example, below, the indices of the innermost dimension 0, 1, 2, 3 translate
  12359. >>> # to coordinates of [0, 3, 6, 9], and the indices of the outermost dimension
  12360. >>> # 0, 1 translate to coordinates of [0, 2].
  12361. >>> torch.gradient(t, spacing = [3., 2.])
  12362. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12363. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12364. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12365. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12366. >>> # The following example is a replication of the previous one with explicit
  12367. >>> # coordinates.
  12368. >>> coords = (torch.tensor([0, 2]), torch.tensor([0, 3, 6, 9]))
  12369. >>> torch.gradient(t, spacing = coords)
  12370. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12371. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12372. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12373. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12374. """
  12375. @overload
  12376. def gradient(
  12377. input: Tensor,
  12378. *,
  12379. spacing: tuple[Tensor, ...] | list[Tensor] | None,
  12380. dim: _size,
  12381. edge_order: _int = 1,
  12382. ) -> tuple[Tensor, ...]:
  12383. r"""
  12384. gradient(input, *, spacing=1, dim=None, edge_order=1) -> List of Tensors
  12385. Estimates the gradient of a function :math:`g : \mathbb{R}^n \rightarrow \mathbb{R}` in
  12386. one or more dimensions using the `second-order accurate central differences method
  12387. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ and
  12388. either first or second order estimates at the boundaries.
  12389. The gradient of :math:`g` is estimated using samples. By default, when :attr:`spacing` is not
  12390. specified, the samples are entirely described by :attr:`input`, and the mapping of input coordinates
  12391. to an output is the same as the tensor's mapping of indices to values. For example, for a three-dimensional
  12392. :attr:`input` the function described is :math:`g : \mathbb{R}^3 \rightarrow \mathbb{R}`, and
  12393. :math:`g(1, 2, 3)\ == input[1, 2, 3]`.
  12394. When :attr:`spacing` is specified, it modifies the relationship between :attr:`input` and input coordinates.
  12395. This is detailed in the "Keyword Arguments" section below.
  12396. The gradient is estimated by estimating each partial derivative of :math:`g` independently. This estimation is
  12397. accurate if :math:`g` is in :math:`C^3` (it has at least 3 continuous derivatives), and the estimation can be
  12398. improved by providing closer samples. Mathematically, the value at each interior point of a partial derivative
  12399. is estimated using `Taylor's theorem with remainder <https://en.wikipedia.org/wiki/Taylor%27s_theorem>`_.
  12400. Letting :math:`x` be an interior point with :math:`x-h_l` and :math:`x+h_r` be points neighboring
  12401. it to the left and right respectively, :math:`f(x+h_r)` and :math:`f(x-h_l)` can be estimated using:
  12402. .. math::
  12403. \begin{aligned}
  12404. 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) \\
  12405. 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) \\
  12406. \end{aligned}
  12407. Using the fact that :math:`f \in C^3` and solving the linear system, we derive:
  12408. .. math::
  12409. f'(x) \approx \frac{ {h_l}^2 f(x+h_r) - {h_r}^2 f(x-h_l)
  12410. + ({h_r}^2-{h_l}^2 ) f(x) }{ {h_r} {h_l}^2 + {h_r}^2 {h_l} }
  12411. .. note::
  12412. We estimate the gradient of functions in complex domain
  12413. :math:`g : \mathbb{C}^n \rightarrow \mathbb{C}` in the same way.
  12414. The value of each partial derivative at the boundary points is computed differently. See edge_order below.
  12415. Args:
  12416. input (``Tensor``): the tensor that represents the values of the function
  12417. Keyword args:
  12418. spacing (``scalar``, ``list of scalar``, ``list of Tensor``, optional): :attr:`spacing` can be used to modify
  12419. how the :attr:`input` tensor's indices relate to sample coordinates. If :attr:`spacing` is a scalar then
  12420. the indices are multiplied by the scalar to produce the coordinates. For example, if :attr:`spacing=2` the
  12421. indices (1, 2, 3) become coordinates (2, 4, 6). If :attr:`spacing` is a list of scalars then the corresponding
  12422. indices are multiplied. For example, if :attr:`spacing=(2, -1, 3)` the indices (1, 2, 3) become coordinates (2, -2, 9).
  12423. Finally, if :attr:`spacing` is a list of one-dimensional tensors then each tensor specifies the coordinates for
  12424. the corresponding dimension. For example, if the indices are (1, 2, 3) and the tensors are (t0, t1, t2), then
  12425. the coordinates are (t0[1], t1[2], t2[3])
  12426. dim (``int``, ``list of int``, optional): the dimension or dimensions to approximate the gradient over. By default
  12427. the partial gradient in every dimension is computed. Note that when :attr:`dim` is specified the elements of
  12428. the :attr:`spacing` argument must correspond with the specified dims."
  12429. edge_order (``int``, optional): 1 or 2, for `first-order
  12430. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ or
  12431. `second-order <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_
  12432. estimation of the boundary ("edge") values, respectively. Note that when :attr:`edge_order` is specified, each
  12433. dimension size of :attr:`input` should be at least edge_order+1
  12434. Examples::
  12435. >>> # Estimates the gradient of f(x)=x^2 at points [-2, -1, 2, 4]
  12436. >>> coordinates = (torch.tensor([-2., -1., 1., 4.]),)
  12437. >>> values = torch.tensor([4., 1., 1., 16.], )
  12438. >>> torch.gradient(values, spacing = coordinates)
  12439. (tensor([-3., -2., 2., 5.]),)
  12440. >>> # Estimates the gradient of the R^2 -> R function whose samples are
  12441. >>> # described by the tensor t. Implicit coordinates are [0, 1] for the outermost
  12442. >>> # dimension and [0, 1, 2, 3] for the innermost dimension, and function estimates
  12443. >>> # partial derivative for both dimensions.
  12444. >>> t = torch.tensor([[1, 2, 4, 8], [10, 20, 40, 80]])
  12445. >>> torch.gradient(t)
  12446. (tensor([[ 9., 18., 36., 72.],
  12447. [ 9., 18., 36., 72.]]),
  12448. tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12449. [10.0000, 15.0000, 30.0000, 40.0000]]))
  12450. >>> # A scalar value for spacing modifies the relationship between tensor indices
  12451. >>> # and input coordinates by multiplying the indices to find the
  12452. >>> # coordinates. For example, below the indices of the innermost
  12453. >>> # 0, 1, 2, 3 translate to coordinates of [0, 2, 4, 6], and the indices of
  12454. >>> # the outermost dimension 0, 1 translate to coordinates of [0, 2].
  12455. >>> torch.gradient(t, spacing = 2.0) # dim = None (implicitly [0, 1])
  12456. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12457. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12458. tensor([[ 0.5000, 0.7500, 1.5000, 2.0000],
  12459. [ 5.0000, 7.5000, 15.0000, 20.0000]]))
  12460. >>> # doubling the spacing between samples halves the estimated partial gradients.
  12461. >>>
  12462. >>> # Estimates only the partial derivative for dimension 1
  12463. >>> torch.gradient(t, dim = 1) # spacing = None (implicitly 1.)
  12464. (tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12465. [10.0000, 15.0000, 30.0000, 40.0000]]),)
  12466. >>> # When spacing is a list of scalars, the relationship between the tensor
  12467. >>> # indices and input coordinates changes based on dimension.
  12468. >>> # For example, below, the indices of the innermost dimension 0, 1, 2, 3 translate
  12469. >>> # to coordinates of [0, 3, 6, 9], and the indices of the outermost dimension
  12470. >>> # 0, 1 translate to coordinates of [0, 2].
  12471. >>> torch.gradient(t, spacing = [3., 2.])
  12472. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12473. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12474. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12475. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12476. >>> # The following example is a replication of the previous one with explicit
  12477. >>> # coordinates.
  12478. >>> coords = (torch.tensor([0, 2]), torch.tensor([0, 3, 6, 9]))
  12479. >>> torch.gradient(t, spacing = coords)
  12480. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12481. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12482. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12483. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12484. """
  12485. @overload
  12486. def gradient(
  12487. input: Tensor,
  12488. *,
  12489. dim: _size,
  12490. edge_order: _int = 1,
  12491. ) -> tuple[Tensor, ...]:
  12492. r"""
  12493. gradient(input, *, spacing=1, dim=None, edge_order=1) -> List of Tensors
  12494. Estimates the gradient of a function :math:`g : \mathbb{R}^n \rightarrow \mathbb{R}` in
  12495. one or more dimensions using the `second-order accurate central differences method
  12496. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ and
  12497. either first or second order estimates at the boundaries.
  12498. The gradient of :math:`g` is estimated using samples. By default, when :attr:`spacing` is not
  12499. specified, the samples are entirely described by :attr:`input`, and the mapping of input coordinates
  12500. to an output is the same as the tensor's mapping of indices to values. For example, for a three-dimensional
  12501. :attr:`input` the function described is :math:`g : \mathbb{R}^3 \rightarrow \mathbb{R}`, and
  12502. :math:`g(1, 2, 3)\ == input[1, 2, 3]`.
  12503. When :attr:`spacing` is specified, it modifies the relationship between :attr:`input` and input coordinates.
  12504. This is detailed in the "Keyword Arguments" section below.
  12505. The gradient is estimated by estimating each partial derivative of :math:`g` independently. This estimation is
  12506. accurate if :math:`g` is in :math:`C^3` (it has at least 3 continuous derivatives), and the estimation can be
  12507. improved by providing closer samples. Mathematically, the value at each interior point of a partial derivative
  12508. is estimated using `Taylor's theorem with remainder <https://en.wikipedia.org/wiki/Taylor%27s_theorem>`_.
  12509. Letting :math:`x` be an interior point with :math:`x-h_l` and :math:`x+h_r` be points neighboring
  12510. it to the left and right respectively, :math:`f(x+h_r)` and :math:`f(x-h_l)` can be estimated using:
  12511. .. math::
  12512. \begin{aligned}
  12513. 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) \\
  12514. 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) \\
  12515. \end{aligned}
  12516. Using the fact that :math:`f \in C^3` and solving the linear system, we derive:
  12517. .. math::
  12518. f'(x) \approx \frac{ {h_l}^2 f(x+h_r) - {h_r}^2 f(x-h_l)
  12519. + ({h_r}^2-{h_l}^2 ) f(x) }{ {h_r} {h_l}^2 + {h_r}^2 {h_l} }
  12520. .. note::
  12521. We estimate the gradient of functions in complex domain
  12522. :math:`g : \mathbb{C}^n \rightarrow \mathbb{C}` in the same way.
  12523. The value of each partial derivative at the boundary points is computed differently. See edge_order below.
  12524. Args:
  12525. input (``Tensor``): the tensor that represents the values of the function
  12526. Keyword args:
  12527. spacing (``scalar``, ``list of scalar``, ``list of Tensor``, optional): :attr:`spacing` can be used to modify
  12528. how the :attr:`input` tensor's indices relate to sample coordinates. If :attr:`spacing` is a scalar then
  12529. the indices are multiplied by the scalar to produce the coordinates. For example, if :attr:`spacing=2` the
  12530. indices (1, 2, 3) become coordinates (2, 4, 6). If :attr:`spacing` is a list of scalars then the corresponding
  12531. indices are multiplied. For example, if :attr:`spacing=(2, -1, 3)` the indices (1, 2, 3) become coordinates (2, -2, 9).
  12532. Finally, if :attr:`spacing` is a list of one-dimensional tensors then each tensor specifies the coordinates for
  12533. the corresponding dimension. For example, if the indices are (1, 2, 3) and the tensors are (t0, t1, t2), then
  12534. the coordinates are (t0[1], t1[2], t2[3])
  12535. dim (``int``, ``list of int``, optional): the dimension or dimensions to approximate the gradient over. By default
  12536. the partial gradient in every dimension is computed. Note that when :attr:`dim` is specified the elements of
  12537. the :attr:`spacing` argument must correspond with the specified dims."
  12538. edge_order (``int``, optional): 1 or 2, for `first-order
  12539. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ or
  12540. `second-order <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_
  12541. estimation of the boundary ("edge") values, respectively. Note that when :attr:`edge_order` is specified, each
  12542. dimension size of :attr:`input` should be at least edge_order+1
  12543. Examples::
  12544. >>> # Estimates the gradient of f(x)=x^2 at points [-2, -1, 2, 4]
  12545. >>> coordinates = (torch.tensor([-2., -1., 1., 4.]),)
  12546. >>> values = torch.tensor([4., 1., 1., 16.], )
  12547. >>> torch.gradient(values, spacing = coordinates)
  12548. (tensor([-3., -2., 2., 5.]),)
  12549. >>> # Estimates the gradient of the R^2 -> R function whose samples are
  12550. >>> # described by the tensor t. Implicit coordinates are [0, 1] for the outermost
  12551. >>> # dimension and [0, 1, 2, 3] for the innermost dimension, and function estimates
  12552. >>> # partial derivative for both dimensions.
  12553. >>> t = torch.tensor([[1, 2, 4, 8], [10, 20, 40, 80]])
  12554. >>> torch.gradient(t)
  12555. (tensor([[ 9., 18., 36., 72.],
  12556. [ 9., 18., 36., 72.]]),
  12557. tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12558. [10.0000, 15.0000, 30.0000, 40.0000]]))
  12559. >>> # A scalar value for spacing modifies the relationship between tensor indices
  12560. >>> # and input coordinates by multiplying the indices to find the
  12561. >>> # coordinates. For example, below the indices of the innermost
  12562. >>> # 0, 1, 2, 3 translate to coordinates of [0, 2, 4, 6], and the indices of
  12563. >>> # the outermost dimension 0, 1 translate to coordinates of [0, 2].
  12564. >>> torch.gradient(t, spacing = 2.0) # dim = None (implicitly [0, 1])
  12565. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12566. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12567. tensor([[ 0.5000, 0.7500, 1.5000, 2.0000],
  12568. [ 5.0000, 7.5000, 15.0000, 20.0000]]))
  12569. >>> # doubling the spacing between samples halves the estimated partial gradients.
  12570. >>>
  12571. >>> # Estimates only the partial derivative for dimension 1
  12572. >>> torch.gradient(t, dim = 1) # spacing = None (implicitly 1.)
  12573. (tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12574. [10.0000, 15.0000, 30.0000, 40.0000]]),)
  12575. >>> # When spacing is a list of scalars, the relationship between the tensor
  12576. >>> # indices and input coordinates changes based on dimension.
  12577. >>> # For example, below, the indices of the innermost dimension 0, 1, 2, 3 translate
  12578. >>> # to coordinates of [0, 3, 6, 9], and the indices of the outermost dimension
  12579. >>> # 0, 1 translate to coordinates of [0, 2].
  12580. >>> torch.gradient(t, spacing = [3., 2.])
  12581. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12582. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12583. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12584. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12585. >>> # The following example is a replication of the previous one with explicit
  12586. >>> # coordinates.
  12587. >>> coords = (torch.tensor([0, 2]), torch.tensor([0, 3, 6, 9]))
  12588. >>> torch.gradient(t, spacing = coords)
  12589. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12590. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12591. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12592. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12593. """
  12594. @overload
  12595. def greater(
  12596. input: Tensor,
  12597. other: Tensor,
  12598. *,
  12599. out: Tensor | None = None,
  12600. ) -> Tensor:
  12601. r"""
  12602. greater(input, other, *, out=None) -> Tensor
  12603. Alias for :func:`torch.gt`.
  12604. """
  12605. @overload
  12606. def greater(
  12607. input: Tensor,
  12608. other: Number | _complex,
  12609. *,
  12610. out: Tensor | None = None,
  12611. ) -> Tensor:
  12612. r"""
  12613. greater(input, other, *, out=None) -> Tensor
  12614. Alias for :func:`torch.gt`.
  12615. """
  12616. @overload
  12617. def greater_equal(
  12618. input: Tensor,
  12619. other: Tensor,
  12620. *,
  12621. out: Tensor | None = None,
  12622. ) -> Tensor:
  12623. r"""
  12624. greater_equal(input, other, *, out=None) -> Tensor
  12625. Alias for :func:`torch.ge`.
  12626. """
  12627. @overload
  12628. def greater_equal(
  12629. input: Tensor,
  12630. other: Number | _complex,
  12631. *,
  12632. out: Tensor | None = None,
  12633. ) -> Tensor:
  12634. r"""
  12635. greater_equal(input, other, *, out=None) -> Tensor
  12636. Alias for :func:`torch.ge`.
  12637. """
  12638. def grid_sampler(
  12639. input: Tensor,
  12640. grid: Tensor,
  12641. interpolation_mode: _int,
  12642. padding_mode: _int,
  12643. align_corners: _bool,
  12644. ) -> Tensor: ...
  12645. def grid_sampler_2d(
  12646. input: Tensor,
  12647. grid: Tensor,
  12648. interpolation_mode: _int,
  12649. padding_mode: _int,
  12650. align_corners: _bool,
  12651. ) -> Tensor: ...
  12652. def grid_sampler_3d(
  12653. input: Tensor,
  12654. grid: Tensor,
  12655. interpolation_mode: _int,
  12656. padding_mode: _int,
  12657. align_corners: _bool,
  12658. ) -> Tensor: ...
  12659. def group_norm(
  12660. input: Tensor,
  12661. num_groups: _int,
  12662. weight: Tensor | None = None,
  12663. bias: Tensor | None = None,
  12664. eps: _float = 1e-05,
  12665. cudnn_enabled: _bool = True,
  12666. ) -> Tensor: ...
  12667. @overload
  12668. def gru(
  12669. data: Tensor,
  12670. batch_sizes: Tensor,
  12671. hx: Tensor,
  12672. params: tuple[Tensor, ...] | list[Tensor] | None,
  12673. has_biases: _bool,
  12674. num_layers: _int,
  12675. dropout: _float,
  12676. train: _bool,
  12677. bidirectional: _bool,
  12678. ) -> tuple[Tensor, Tensor]: ...
  12679. @overload
  12680. def gru(
  12681. input: Tensor,
  12682. hx: Tensor,
  12683. params: tuple[Tensor, ...] | list[Tensor] | None,
  12684. has_biases: _bool,
  12685. num_layers: _int,
  12686. dropout: _float,
  12687. train: _bool,
  12688. bidirectional: _bool,
  12689. batch_first: _bool,
  12690. ) -> tuple[Tensor, Tensor]: ...
  12691. def gru_cell(
  12692. input: Tensor,
  12693. hx: Tensor,
  12694. w_ih: Tensor,
  12695. w_hh: Tensor,
  12696. b_ih: Tensor | None = None,
  12697. b_hh: Tensor | None = None,
  12698. ) -> Tensor: ...
  12699. @overload
  12700. def gt(
  12701. input: Tensor,
  12702. other: Tensor,
  12703. *,
  12704. out: Tensor | None = None,
  12705. ) -> Tensor:
  12706. r"""
  12707. gt(input, other, *, out=None) -> Tensor
  12708. Computes :math:`\text{input} > \text{other}` element-wise.
  12709. The second argument can be a number or a tensor whose shape is
  12710. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  12711. Args:
  12712. input (Tensor): the tensor to compare
  12713. other (Tensor or float): the tensor or value to compare
  12714. Keyword args:
  12715. out (Tensor, optional): the output tensor.
  12716. Returns:
  12717. A boolean tensor that is True where :attr:`input` is greater than :attr:`other` and False elsewhere
  12718. Example::
  12719. >>> torch.gt(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  12720. tensor([[False, True], [False, False]])
  12721. """
  12722. @overload
  12723. def gt(
  12724. input: Tensor,
  12725. other: Number | _complex,
  12726. *,
  12727. out: Tensor | None = None,
  12728. ) -> Tensor:
  12729. r"""
  12730. gt(input, other, *, out=None) -> Tensor
  12731. Computes :math:`\text{input} > \text{other}` element-wise.
  12732. The second argument can be a number or a tensor whose shape is
  12733. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  12734. Args:
  12735. input (Tensor): the tensor to compare
  12736. other (Tensor or float): the tensor or value to compare
  12737. Keyword args:
  12738. out (Tensor, optional): the output tensor.
  12739. Returns:
  12740. A boolean tensor that is True where :attr:`input` is greater than :attr:`other` and False elsewhere
  12741. Example::
  12742. >>> torch.gt(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  12743. tensor([[False, True], [False, False]])
  12744. """
  12745. @overload
  12746. def hamming_window(
  12747. window_length: _int,
  12748. *,
  12749. dtype: _dtype | None = None,
  12750. layout: _layout | None = None,
  12751. device: DeviceLikeType | None = None,
  12752. pin_memory: _bool | None = False,
  12753. requires_grad: _bool | None = False,
  12754. ) -> Tensor:
  12755. r"""
  12756. hamming_window(window_length, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) -> Tensor
  12757. Hamming window function.
  12758. .. math::
  12759. w[n] = \alpha - \beta\ \cos \left( \frac{2 \pi n}{N - 1} \right),
  12760. where :math:`N` is the full window size.
  12761. The input :attr:`window_length` is a positive integer controlling the
  12762. returned window size. :attr:`periodic` flag determines whether the returned
  12763. window trims off the last duplicate value from the symmetric window and is
  12764. ready to be used as a periodic window with functions like
  12765. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  12766. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  12767. ``torch.hamming_window(L, periodic=True)`` equal to
  12768. ``torch.hamming_window(L + 1, periodic=False)[:-1])``.
  12769. .. note::
  12770. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  12771. .. note::
  12772. This is a generalized version of :meth:`torch.hann_window`.
  12773. Arguments:
  12774. window_length (int): the size of returned window
  12775. Keyword args:
  12776. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  12777. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  12778. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  12779. ``torch.strided`` (dense layout) is supported.
  12780. device (:class:`torch.device`, optional): the desired device of returned tensor.
  12781. Default: if ``None``, uses the current device for the default tensor type
  12782. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  12783. for CPU tensor types and the current CUDA device for CUDA tensor types.
  12784. pin_memory (bool, optional): If set, returned tensor would be allocated in
  12785. the pinned memory. Works only for CPU tensors. Default: ``False``.
  12786. requires_grad (bool, optional): If autograd should record operations on the
  12787. returned tensor. Default: ``False``.
  12788. Returns:
  12789. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  12790. .. function:: hamming_window(window_length, periodic, *, dtype=None, layout=None, device=None, \
  12791. pin_memory=False, requires_grad=False) -> Tensor
  12792. :noindex:
  12793. Hamming window function with periodic specified.
  12794. Arguments:
  12795. window_length (int): the size of returned window
  12796. periodic (bool): If True, returns a window to be used as periodic
  12797. function. If False, return a symmetric window.
  12798. Keyword args:
  12799. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  12800. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  12801. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  12802. ``torch.strided`` (dense layout) is supported.
  12803. device (:class:`torch.device`, optional): the desired device of returned tensor.
  12804. Default: if ``None``, uses the current device for the default tensor type
  12805. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  12806. for CPU tensor types and the current CUDA device for CUDA tensor types.
  12807. pin_memory (bool, optional): If set, returned tensor would be allocated in
  12808. the pinned memory. Works only for CPU tensors. Default: ``False``.
  12809. requires_grad (bool, optional): If autograd should record operations on the
  12810. returned tensor. Default: ``False``.
  12811. Returns:
  12812. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  12813. .. function:: hamming_window(window_length, periodic, float alpha, *, dtype=None, layout=None, device=None, \
  12814. pin_memory=False, requires_grad=False) -> Tensor
  12815. :noindex:
  12816. Hamming window function with periodic and alpha specified.
  12817. Arguments:
  12818. window_length (int): the size of returned window
  12819. periodic (bool): If True, returns a window to be used as periodic
  12820. function. If False, return a symmetric window.
  12821. alpha (float): The coefficient :math:`\alpha` in the equation above
  12822. Keyword args:
  12823. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  12824. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  12825. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  12826. ``torch.strided`` (dense layout) is supported.
  12827. device (:class:`torch.device`, optional): the desired device of returned tensor.
  12828. Default: if ``None``, uses the current device for the default tensor type
  12829. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  12830. for CPU tensor types and the current CUDA device for CUDA tensor types.
  12831. pin_memory (bool, optional): If set, returned tensor would be allocated in
  12832. the pinned memory. Works only for CPU tensors. Default: ``False``.
  12833. requires_grad (bool, optional): If autograd should record operations on the
  12834. returned tensor. Default: ``False``.
  12835. Returns:
  12836. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  12837. .. function:: hamming_window(window_length, periodic, float alpha, float beta, *, dtype=None, layout=None, \
  12838. device=None, pin_memory=False, requires_grad=False) -> Tensor
  12839. :noindex:
  12840. Hamming window function with periodic, alpha and beta specified.
  12841. Arguments:
  12842. window_length (int): the size of returned window
  12843. periodic (bool): If True, returns a window to be used as periodic
  12844. function. If False, return a symmetric window.
  12845. alpha (float): The coefficient :math:`\alpha` in the equation above
  12846. beta (float): The coefficient :math:`\beta` in the equation above
  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. """
  12863. @overload
  12864. def hamming_window(
  12865. window_length: _int,
  12866. periodic: _bool,
  12867. *,
  12868. dtype: _dtype | None = None,
  12869. layout: _layout | None = None,
  12870. device: DeviceLikeType | None = None,
  12871. pin_memory: _bool | None = False,
  12872. requires_grad: _bool | None = False,
  12873. ) -> Tensor:
  12874. r"""
  12875. hamming_window(window_length, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) -> Tensor
  12876. Hamming window function.
  12877. .. math::
  12878. w[n] = \alpha - \beta\ \cos \left( \frac{2 \pi n}{N - 1} \right),
  12879. where :math:`N` is the full window size.
  12880. The input :attr:`window_length` is a positive integer controlling the
  12881. returned window size. :attr:`periodic` flag determines whether the returned
  12882. window trims off the last duplicate value from the symmetric window and is
  12883. ready to be used as a periodic window with functions like
  12884. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  12885. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  12886. ``torch.hamming_window(L, periodic=True)`` equal to
  12887. ``torch.hamming_window(L + 1, periodic=False)[:-1])``.
  12888. .. note::
  12889. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  12890. .. note::
  12891. This is a generalized version of :meth:`torch.hann_window`.
  12892. Arguments:
  12893. window_length (int): the size of returned window
  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, *, dtype=None, layout=None, device=None, \
  12910. pin_memory=False, requires_grad=False) -> Tensor
  12911. :noindex:
  12912. Hamming window function with periodic 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. Keyword args:
  12918. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  12919. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  12920. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  12921. ``torch.strided`` (dense layout) is supported.
  12922. device (:class:`torch.device`, optional): the desired device of returned tensor.
  12923. Default: if ``None``, uses the current device for the default tensor type
  12924. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  12925. for CPU tensor types and the current CUDA device for CUDA tensor types.
  12926. pin_memory (bool, optional): If set, returned tensor would be allocated in
  12927. the pinned memory. Works only for CPU tensors. Default: ``False``.
  12928. requires_grad (bool, optional): If autograd should record operations on the
  12929. returned tensor. Default: ``False``.
  12930. Returns:
  12931. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  12932. .. function:: hamming_window(window_length, periodic, float alpha, *, dtype=None, layout=None, device=None, \
  12933. pin_memory=False, requires_grad=False) -> Tensor
  12934. :noindex:
  12935. Hamming window function with periodic and alpha specified.
  12936. Arguments:
  12937. window_length (int): the size of returned window
  12938. periodic (bool): If True, returns a window to be used as periodic
  12939. function. If False, return a symmetric window.
  12940. alpha (float): The coefficient :math:`\alpha` in the equation above
  12941. Keyword args:
  12942. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  12943. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  12944. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  12945. ``torch.strided`` (dense layout) is supported.
  12946. device (:class:`torch.device`, optional): the desired device of returned tensor.
  12947. Default: if ``None``, uses the current device for the default tensor type
  12948. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  12949. for CPU tensor types and the current CUDA device for CUDA tensor types.
  12950. pin_memory (bool, optional): If set, returned tensor would be allocated in
  12951. the pinned memory. Works only for CPU tensors. Default: ``False``.
  12952. requires_grad (bool, optional): If autograd should record operations on the
  12953. returned tensor. Default: ``False``.
  12954. Returns:
  12955. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  12956. .. function:: hamming_window(window_length, periodic, float alpha, float beta, *, dtype=None, layout=None, \
  12957. device=None, pin_memory=False, requires_grad=False) -> Tensor
  12958. :noindex:
  12959. Hamming window function with periodic, alpha and beta specified.
  12960. Arguments:
  12961. window_length (int): the size of returned window
  12962. periodic (bool): If True, returns a window to be used as periodic
  12963. function. If False, return a symmetric window.
  12964. alpha (float): The coefficient :math:`\alpha` in the equation above
  12965. beta (float): The coefficient :math:`\beta` in the equation above
  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. """
  12982. @overload
  12983. def hamming_window(
  12984. window_length: _int,
  12985. periodic: _bool,
  12986. alpha: _float,
  12987. *,
  12988. dtype: _dtype | None = None,
  12989. layout: _layout | None = None,
  12990. device: DeviceLikeType | None = None,
  12991. pin_memory: _bool | None = False,
  12992. requires_grad: _bool | None = False,
  12993. ) -> Tensor:
  12994. r"""
  12995. hamming_window(window_length, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) -> Tensor
  12996. Hamming window function.
  12997. .. math::
  12998. w[n] = \alpha - \beta\ \cos \left( \frac{2 \pi n}{N - 1} \right),
  12999. where :math:`N` is the full window size.
  13000. The input :attr:`window_length` is a positive integer controlling the
  13001. returned window size. :attr:`periodic` flag determines whether the returned
  13002. window trims off the last duplicate value from the symmetric window and is
  13003. ready to be used as a periodic window with functions like
  13004. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  13005. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  13006. ``torch.hamming_window(L, periodic=True)`` equal to
  13007. ``torch.hamming_window(L + 1, periodic=False)[:-1])``.
  13008. .. note::
  13009. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  13010. .. note::
  13011. This is a generalized version of :meth:`torch.hann_window`.
  13012. Arguments:
  13013. window_length (int): the size of returned window
  13014. Keyword args:
  13015. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13016. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13017. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13018. ``torch.strided`` (dense layout) is supported.
  13019. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13020. Default: if ``None``, uses the current device for the default tensor type
  13021. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13022. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13023. pin_memory (bool, optional): If set, returned tensor would be allocated in
  13024. the pinned memory. Works only for CPU tensors. Default: ``False``.
  13025. requires_grad (bool, optional): If autograd should record operations on the
  13026. returned tensor. Default: ``False``.
  13027. Returns:
  13028. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  13029. .. function:: hamming_window(window_length, periodic, *, dtype=None, layout=None, device=None, \
  13030. pin_memory=False, requires_grad=False) -> Tensor
  13031. :noindex:
  13032. Hamming window function with periodic specified.
  13033. Arguments:
  13034. window_length (int): the size of returned window
  13035. periodic (bool): If True, returns a window to be used as periodic
  13036. function. If False, return a symmetric window.
  13037. Keyword args:
  13038. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13039. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13040. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13041. ``torch.strided`` (dense layout) is supported.
  13042. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13043. Default: if ``None``, uses the current device for the default tensor type
  13044. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13045. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13046. pin_memory (bool, optional): If set, returned tensor would be allocated in
  13047. the pinned memory. Works only for CPU tensors. Default: ``False``.
  13048. requires_grad (bool, optional): If autograd should record operations on the
  13049. returned tensor. Default: ``False``.
  13050. Returns:
  13051. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  13052. .. function:: hamming_window(window_length, periodic, float alpha, *, dtype=None, layout=None, device=None, \
  13053. pin_memory=False, requires_grad=False) -> Tensor
  13054. :noindex:
  13055. Hamming window function with periodic and alpha specified.
  13056. Arguments:
  13057. window_length (int): the size of returned window
  13058. periodic (bool): If True, returns a window to be used as periodic
  13059. function. If False, return a symmetric window.
  13060. alpha (float): The coefficient :math:`\alpha` in the equation above
  13061. Keyword args:
  13062. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13063. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13064. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13065. ``torch.strided`` (dense layout) is supported.
  13066. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13067. Default: if ``None``, uses the current device for the default tensor type
  13068. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13069. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13070. pin_memory (bool, optional): If set, returned tensor would be allocated in
  13071. the pinned memory. Works only for CPU tensors. Default: ``False``.
  13072. requires_grad (bool, optional): If autograd should record operations on the
  13073. returned tensor. Default: ``False``.
  13074. Returns:
  13075. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  13076. .. function:: hamming_window(window_length, periodic, float alpha, float beta, *, dtype=None, layout=None, \
  13077. device=None, pin_memory=False, requires_grad=False) -> Tensor
  13078. :noindex:
  13079. Hamming window function with periodic, alpha and beta specified.
  13080. Arguments:
  13081. window_length (int): the size of returned window
  13082. periodic (bool): If True, returns a window to be used as periodic
  13083. function. If False, return a symmetric window.
  13084. alpha (float): The coefficient :math:`\alpha` in the equation above
  13085. beta (float): The coefficient :math:`\beta` in the equation above
  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. """
  13102. @overload
  13103. def hamming_window(
  13104. window_length: _int,
  13105. periodic: _bool,
  13106. alpha: _float,
  13107. beta: _float,
  13108. *,
  13109. dtype: _dtype | None = None,
  13110. layout: _layout | None = None,
  13111. device: DeviceLikeType | None = None,
  13112. pin_memory: _bool | None = False,
  13113. requires_grad: _bool | None = False,
  13114. ) -> Tensor:
  13115. r"""
  13116. hamming_window(window_length, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) -> Tensor
  13117. Hamming window function.
  13118. .. math::
  13119. w[n] = \alpha - \beta\ \cos \left( \frac{2 \pi n}{N - 1} \right),
  13120. where :math:`N` is the full window size.
  13121. The input :attr:`window_length` is a positive integer controlling the
  13122. returned window size. :attr:`periodic` flag determines whether the returned
  13123. window trims off the last duplicate value from the symmetric window and is
  13124. ready to be used as a periodic window with functions like
  13125. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  13126. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  13127. ``torch.hamming_window(L, periodic=True)`` equal to
  13128. ``torch.hamming_window(L + 1, periodic=False)[:-1])``.
  13129. .. note::
  13130. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  13131. .. note::
  13132. This is a generalized version of :meth:`torch.hann_window`.
  13133. Arguments:
  13134. window_length (int): the size of returned window
  13135. Keyword args:
  13136. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13137. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13138. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13139. ``torch.strided`` (dense layout) is supported.
  13140. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13141. Default: if ``None``, uses the current device for the default tensor type
  13142. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13143. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13144. pin_memory (bool, optional): If set, returned tensor would be allocated in
  13145. the pinned memory. Works only for CPU tensors. Default: ``False``.
  13146. requires_grad (bool, optional): If autograd should record operations on the
  13147. returned tensor. Default: ``False``.
  13148. Returns:
  13149. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  13150. .. function:: hamming_window(window_length, periodic, *, dtype=None, layout=None, device=None, \
  13151. pin_memory=False, requires_grad=False) -> Tensor
  13152. :noindex:
  13153. Hamming window function with periodic specified.
  13154. Arguments:
  13155. window_length (int): the size of returned window
  13156. periodic (bool): If True, returns a window to be used as periodic
  13157. function. If False, return a symmetric window.
  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. .. function:: hamming_window(window_length, periodic, float alpha, *, dtype=None, layout=None, device=None, \
  13174. pin_memory=False, requires_grad=False) -> Tensor
  13175. :noindex:
  13176. Hamming window function with periodic and alpha specified.
  13177. Arguments:
  13178. window_length (int): the size of returned window
  13179. periodic (bool): If True, returns a window to be used as periodic
  13180. function. If False, return a symmetric window.
  13181. alpha (float): The coefficient :math:`\alpha` in the equation above
  13182. Keyword args:
  13183. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13184. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13185. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13186. ``torch.strided`` (dense layout) is supported.
  13187. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13188. Default: if ``None``, uses the current device for the default tensor type
  13189. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13190. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13191. pin_memory (bool, optional): If set, returned tensor would be allocated in
  13192. the pinned memory. Works only for CPU tensors. Default: ``False``.
  13193. requires_grad (bool, optional): If autograd should record operations on the
  13194. returned tensor. Default: ``False``.
  13195. Returns:
  13196. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  13197. .. function:: hamming_window(window_length, periodic, float alpha, float beta, *, dtype=None, layout=None, \
  13198. device=None, pin_memory=False, requires_grad=False) -> Tensor
  13199. :noindex:
  13200. Hamming window function with periodic, alpha and beta specified.
  13201. Arguments:
  13202. window_length (int): the size of returned window
  13203. periodic (bool): If True, returns a window to be used as periodic
  13204. function. If False, return a symmetric window.
  13205. alpha (float): The coefficient :math:`\alpha` in the equation above
  13206. beta (float): The coefficient :math:`\beta` in the equation above
  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. """
  13223. @overload
  13224. def hann_window(
  13225. window_length: _int,
  13226. *,
  13227. dtype: _dtype | None = None,
  13228. layout: _layout | None = None,
  13229. device: DeviceLikeType | None = None,
  13230. pin_memory: _bool | None = False,
  13231. requires_grad: _bool | None = False,
  13232. ) -> Tensor:
  13233. r"""
  13234. hann_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  13235. Hann window function.
  13236. .. math::
  13237. w[n] = \frac{1}{2}\ \left[1 - \cos \left( \frac{2 \pi n}{N - 1} \right)\right] =
  13238. \sin^2 \left( \frac{\pi n}{N - 1} \right),
  13239. where :math:`N` is the full window size.
  13240. The input :attr:`window_length` is a positive integer controlling the
  13241. returned window size. :attr:`periodic` flag determines whether the returned
  13242. window trims off the last duplicate value from the symmetric window and is
  13243. ready to be used as a periodic window with functions like
  13244. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  13245. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  13246. ``torch.hann_window(L, periodic=True)`` equal to
  13247. ``torch.hann_window(L + 1, periodic=False)[:-1])``.
  13248. .. note::
  13249. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  13250. Arguments:
  13251. window_length (int): the size of returned window
  13252. periodic (bool, optional): If True, returns a window to be used as periodic
  13253. function. If False, return a symmetric window.
  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. requires_grad (bool, optional): If autograd should record operations on the
  13264. returned tensor. Default: ``False``.
  13265. Returns:
  13266. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window
  13267. """
  13268. @overload
  13269. def hann_window(
  13270. window_length: _int,
  13271. periodic: _bool,
  13272. *,
  13273. dtype: _dtype | None = None,
  13274. layout: _layout | None = None,
  13275. device: DeviceLikeType | None = None,
  13276. pin_memory: _bool | None = False,
  13277. requires_grad: _bool | None = False,
  13278. ) -> Tensor:
  13279. r"""
  13280. hann_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  13281. Hann window function.
  13282. .. math::
  13283. w[n] = \frac{1}{2}\ \left[1 - \cos \left( \frac{2 \pi n}{N - 1} \right)\right] =
  13284. \sin^2 \left( \frac{\pi n}{N - 1} \right),
  13285. where :math:`N` is the full window size.
  13286. The input :attr:`window_length` is a positive integer controlling the
  13287. returned window size. :attr:`periodic` flag determines whether the returned
  13288. window trims off the last duplicate value from the symmetric window and is
  13289. ready to be used as a periodic window with functions like
  13290. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  13291. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  13292. ``torch.hann_window(L, periodic=True)`` equal to
  13293. ``torch.hann_window(L + 1, periodic=False)[:-1])``.
  13294. .. note::
  13295. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  13296. Arguments:
  13297. window_length (int): the size of returned window
  13298. periodic (bool, optional): If True, returns a window to be used as periodic
  13299. function. If False, return a symmetric window.
  13300. Keyword args:
  13301. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13302. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13303. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13304. ``torch.strided`` (dense layout) is supported.
  13305. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13306. Default: if ``None``, uses the current device for the default tensor type
  13307. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13308. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13309. requires_grad (bool, optional): If autograd should record operations on the
  13310. returned tensor. Default: ``False``.
  13311. Returns:
  13312. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window
  13313. """
  13314. def hardshrink(
  13315. input: Tensor,
  13316. lambd: Number | _complex = 0.5,
  13317. *,
  13318. out: Tensor | None = None,
  13319. ) -> Tensor: ...
  13320. def hash_tensor(
  13321. input: Tensor,
  13322. dim: _int | _size = (),
  13323. *,
  13324. keepdim: _bool = False,
  13325. mode: _int = 0,
  13326. out: Tensor | None = None,
  13327. ) -> Tensor:
  13328. r"""
  13329. hash_tensor(input, *, mode=0) -> Tensor
  13330. Returns a hash of all elements in the :attr:`input` tensor.
  13331. Currently only mode=0 (reduction via xor) is supported. The output will always
  13332. be of type ``torch.uint64``. The elements of ``input`` are upcasted to their
  13333. 64 bit float / integer equivalent and bitcasted to ``torch.uint64`` before
  13334. reduction via xor.
  13335. Args:
  13336. input (Tensor): the input tensor.
  13337. Keyword Args:
  13338. mode (int) : The hash to use. Default: 0 (xor_reduction)
  13339. Example::
  13340. >>> a = torch.randn(1, 3)
  13341. >>> a
  13342. tensor([[ 1.1918, -1.1813, 0.3373]])
  13343. >>> torch.hash_tensor(a)
  13344. tensor(13822780554648485888, dtype=torch.uint64)
  13345. .. function:: hash_tensor(input, dim, *, keepdim=False, mode=0) -> Tensor
  13346. :noindex:
  13347. Returns the hash of each row of the :attr:`input` tensor in the given
  13348. dimension :attr:`dim` given by mode. If :attr:`dim` is a list of dimensions,
  13349. reduce over all of them.
  13350. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  13351. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  13352. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  13353. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  13354. Args:
  13355. input (Tensor): the input tensor.
  13356. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  13357. If ``None``, all dimensions are reduced.
  13358. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  13359. Keyword Args:
  13360. mode (int) : The hash to use. Default: 0 (xor_reduction)
  13361. Example::
  13362. >>> a = torch.randn(2, 4)
  13363. >>> a
  13364. tensor([[ 0.1317, -0.5554, -1.4724, -1.1391],
  13365. [ 0.0778, -0.6070, 0.6375, 0.1798]])
  13366. >>> torch.hash_tensor(a, 1)
  13367. tensor([9233691267014066176, 9255993250844508160], dtype=torch.uint64)
  13368. """
  13369. def heaviside(
  13370. input: Tensor,
  13371. values: Tensor,
  13372. *,
  13373. out: Tensor | None = None,
  13374. ) -> Tensor:
  13375. r"""
  13376. heaviside(input, values, *, out=None) -> Tensor
  13377. Computes the Heaviside step function for each element in :attr:`input`.
  13378. The Heaviside step function is defined as:
  13379. .. math::
  13380. \text{{heaviside}}(input, values) = \begin{cases}
  13381. 0, & \text{if input < 0}\\
  13382. values, & \text{if input == 0}\\
  13383. 1, & \text{if input > 0}
  13384. \end{cases}
  13385. Args:
  13386. input (Tensor): the input tensor.
  13387. values (Tensor): The values to use where :attr:`input` is zero.
  13388. Keyword arguments:
  13389. out (Tensor, optional): the output tensor.
  13390. Example::
  13391. >>> input = torch.tensor([-1.5, 0, 2.0])
  13392. >>> values = torch.tensor([0.5])
  13393. >>> torch.heaviside(input, values)
  13394. tensor([0.0000, 0.5000, 1.0000])
  13395. >>> values = torch.tensor([1.2, -2.0, 3.5])
  13396. >>> torch.heaviside(input, values)
  13397. tensor([0., -2., 1.])
  13398. """
  13399. def hinge_embedding_loss(
  13400. input: Tensor,
  13401. target: Tensor,
  13402. margin: _float = 1.0,
  13403. reduction: _int = 1,
  13404. ) -> Tensor: ...
  13405. def histc(
  13406. input: Tensor,
  13407. bins: _int = 100,
  13408. min: Number | _complex = 0,
  13409. max: Number | _complex = 0,
  13410. *,
  13411. out: Tensor | None = None,
  13412. ) -> Tensor:
  13413. r"""
  13414. histc(input, bins=100, min=0, max=0, *, out=None) -> Tensor
  13415. Computes the histogram of a tensor.
  13416. The elements are sorted into equal width bins between :attr:`min` and
  13417. :attr:`max`. If :attr:`min` and :attr:`max` are both zero, the minimum and
  13418. maximum values of the data are used.
  13419. Elements lower than min and higher than max and ``NaN`` elements are ignored.
  13420. Args:
  13421. input (Tensor): the input tensor.
  13422. bins (int): number of histogram bins
  13423. min (Scalar): lower end of the range (inclusive)
  13424. max (Scalar): upper end of the range (inclusive)
  13425. Keyword args:
  13426. out (Tensor, optional): the output tensor.
  13427. Returns:
  13428. Tensor: Histogram represented as a tensor
  13429. Example::
  13430. >>> torch.histc(torch.tensor([1., 2, 1]), bins=4, min=0, max=3)
  13431. tensor([ 0., 2., 1., 0.])
  13432. """
  13433. @overload
  13434. def histogram(
  13435. input: Tensor,
  13436. bins: Tensor,
  13437. *,
  13438. weight: Tensor | None = None,
  13439. density: _bool = False,
  13440. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  13441. ) -> torch.return_types.histogram:
  13442. r"""
  13443. histogram(input, bins, *, range=None, weight=None, density=False, out=None) -> (Tensor, Tensor)
  13444. Computes a histogram of the values in a tensor.
  13445. :attr:`bins` can be an integer or a 1D tensor.
  13446. If :attr:`bins` is an int, it specifies the number of equal-width bins.
  13447. By default, the lower and upper range of the bins is determined by the
  13448. minimum and maximum elements of the input tensor. The :attr:`range`
  13449. argument can be provided to specify a range for the bins.
  13450. If :attr:`bins` is a 1D tensor, it specifies the sequence of bin edges
  13451. including the rightmost edge. It should contain at least 2 elements
  13452. and its elements should be increasing.
  13453. Args:
  13454. input (Tensor): the input tensor.
  13455. bins: int or 1D Tensor. If int, defines the number of equal-width bins. If tensor,
  13456. defines the sequence of bin edges including the rightmost edge.
  13457. Keyword args:
  13458. range (tuple of float): Defines the range of the bins.
  13459. weight (Tensor): If provided, weight should have the same shape as input. Each value in
  13460. input contributes its associated weight towards its bin's result.
  13461. density (bool): If False, the result will contain the count (or total weight) in each bin.
  13462. If True, the result is the value of the probability density function over the bins,
  13463. normalized such that the integral over the range of the bins is 1.
  13464. out (Tensor, optional): the output tensor. (tuple, optional): The result tuple of two output tensors (hist, bin_edges).
  13465. Returns:
  13466. hist (Tensor): 1D Tensor containing the values of the histogram.
  13467. bin_edges(Tensor): 1D Tensor containing the edges of the histogram bins.
  13468. Example::
  13469. >>> torch.histogram(torch.tensor([1., 2, 1]), bins=4, range=(0., 3.), weight=torch.tensor([1., 2., 4.]))
  13470. (tensor([ 0., 5., 2., 0.]), tensor([0., 0.75, 1.5, 2.25, 3.]))
  13471. >>> torch.histogram(torch.tensor([1., 2, 1]), bins=4, range=(0., 3.), weight=torch.tensor([1., 2., 4.]), density=True)
  13472. (tensor([ 0., 0.9524, 0.3810, 0.]), tensor([0., 0.75, 1.5, 2.25, 3.]))
  13473. """
  13474. @overload
  13475. def histogram(
  13476. input: Tensor,
  13477. bins: _int = 100,
  13478. *,
  13479. range: Sequence[_float] | None = None,
  13480. weight: Tensor | None = None,
  13481. density: _bool = False,
  13482. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  13483. ) -> torch.return_types.histogram:
  13484. r"""
  13485. histogram(input, bins, *, range=None, weight=None, density=False, out=None) -> (Tensor, Tensor)
  13486. Computes a histogram of the values in a tensor.
  13487. :attr:`bins` can be an integer or a 1D tensor.
  13488. If :attr:`bins` is an int, it specifies the number of equal-width bins.
  13489. By default, the lower and upper range of the bins is determined by the
  13490. minimum and maximum elements of the input tensor. The :attr:`range`
  13491. argument can be provided to specify a range for the bins.
  13492. If :attr:`bins` is a 1D tensor, it specifies the sequence of bin edges
  13493. including the rightmost edge. It should contain at least 2 elements
  13494. and its elements should be increasing.
  13495. Args:
  13496. input (Tensor): the input tensor.
  13497. bins: int or 1D Tensor. If int, defines the number of equal-width bins. If tensor,
  13498. defines the sequence of bin edges including the rightmost edge.
  13499. Keyword args:
  13500. range (tuple of float): Defines the range of the bins.
  13501. weight (Tensor): If provided, weight should have the same shape as input. Each value in
  13502. input contributes its associated weight towards its bin's result.
  13503. density (bool): If False, the result will contain the count (or total weight) in each bin.
  13504. If True, the result is the value of the probability density function over the bins,
  13505. normalized such that the integral over the range of the bins is 1.
  13506. out (Tensor, optional): the output tensor. (tuple, optional): The result tuple of two output tensors (hist, bin_edges).
  13507. Returns:
  13508. hist (Tensor): 1D Tensor containing the values of the histogram.
  13509. bin_edges(Tensor): 1D Tensor containing the edges of the histogram bins.
  13510. Example::
  13511. >>> torch.histogram(torch.tensor([1., 2, 1]), bins=4, range=(0., 3.), weight=torch.tensor([1., 2., 4.]))
  13512. (tensor([ 0., 5., 2., 0.]), tensor([0., 0.75, 1.5, 2.25, 3.]))
  13513. >>> torch.histogram(torch.tensor([1., 2, 1]), bins=4, range=(0., 3.), weight=torch.tensor([1., 2., 4.]), density=True)
  13514. (tensor([ 0., 0.9524, 0.3810, 0.]), tensor([0., 0.75, 1.5, 2.25, 3.]))
  13515. """
  13516. @overload
  13517. def histogramdd(
  13518. input: Tensor,
  13519. bins: _int,
  13520. range: Sequence[_float] | None = None,
  13521. weight: Tensor | None = None,
  13522. density: _bool = False,
  13523. ) -> torch.return_types.histogramdd:
  13524. r"""
  13525. histogramdd(input, bins, *, range=None, weight=None, density=False, out=None) -> (Tensor, Tensor[])
  13526. Computes a multi-dimensional histogram of the values in a tensor.
  13527. Interprets the elements of an input tensor whose innermost dimension has size N
  13528. as a collection of N-dimensional points. Maps each of the points into a set of
  13529. N-dimensional bins and returns the number of points (or total weight) in each bin.
  13530. :attr:`input` must be a tensor with at least 2 dimensions.
  13531. If input has shape (M, N), each of its M rows defines a point in N-dimensional space.
  13532. If input has three or more dimensions, all but the last dimension are flattened.
  13533. Each dimension is independently associated with its own strictly increasing sequence
  13534. of bin edges. Bin edges may be specified explicitly by passing a sequence of 1D
  13535. tensors. Alternatively, bin edges may be constructed automatically by passing a
  13536. sequence of integers specifying the number of equal-width bins in each dimension.
  13537. For each N-dimensional point in input:
  13538. - Each of its coordinates is binned independently among the bin edges
  13539. corresponding to its dimension
  13540. - Binning results are combined to identify the N-dimensional bin (if any)
  13541. into which the point falls
  13542. - If the point falls into a bin, the bin's count (or total weight) is incremented
  13543. - Points which do not fall into any bin do not contribute to the output
  13544. :attr:`bins` can be a sequence of N 1D tensors, a sequence of N ints, or a single int.
  13545. If :attr:`bins` is a sequence of N 1D tensors, it explicitly specifies the N sequences
  13546. of bin edges. Each 1D tensor should contain a strictly increasing sequence with at
  13547. least one element. A sequence of K bin edges defines K-1 bins, explicitly specifying
  13548. the left and right edges of all bins. Every bin is inclusive of its left edge. Only
  13549. the rightmost bin is inclusive of its right edge.
  13550. If :attr:`bins` is a sequence of N ints, it specifies the number of equal-width bins
  13551. in each dimension. By default, the leftmost and rightmost bin edges in each dimension
  13552. are determined by the minimum and maximum elements of the input tensor in the
  13553. corresponding dimension. The :attr:`range` argument can be provided to manually
  13554. specify the leftmost and rightmost bin edges in each dimension.
  13555. If :attr:`bins` is an int, it specifies the number of equal-width bins for all dimensions.
  13556. .. note::
  13557. See also :func:`torch.histogram`, which specifically computes 1D histograms.
  13558. While :func:`torch.histogramdd` infers the dimensionality of its bins and
  13559. binned values from the shape of :attr:`input`, :func:`torch.histogram`
  13560. accepts and flattens :attr:`input` of any shape.
  13561. Args:
  13562. input (Tensor): the input tensor.
  13563. bins: Tensor[], int[], or int.
  13564. If Tensor[], defines the sequences of bin edges.
  13565. If int[], defines the number of equal-width bins in each dimension.
  13566. If int, defines the number of equal-width bins for all dimensions.
  13567. Keyword args:
  13568. range (sequence of float): Defines the leftmost and rightmost bin edges
  13569. in each dimension.
  13570. weight (Tensor): By default, each value in the input has weight 1. If a weight
  13571. tensor is passed, each N-dimensional coordinate in input
  13572. contributes its associated weight towards its bin's result.
  13573. The weight tensor should have the same shape as the :attr:`input`
  13574. tensor excluding its innermost dimension N.
  13575. density (bool): If False (default), the result will contain the count (or total weight)
  13576. in each bin. If True, each count (weight) is divided by the total count
  13577. (total weight), then divided by the volume of its associated bin.
  13578. Returns:
  13579. hist (Tensor): N-dimensional Tensor containing the values of the histogram.
  13580. bin_edges(Tensor[]): sequence of N 1D Tensors containing the bin edges.
  13581. Example::
  13582. >>> torch.histogramdd(torch.tensor([[0., 1.], [1., 0.], [2., 0.], [2., 2.]]), bins=[3, 3],
  13583. ... weight=torch.tensor([1., 2., 4., 8.]))
  13584. torch.return_types.histogramdd(
  13585. hist=tensor([[0., 1., 0.],
  13586. [2., 0., 0.],
  13587. [4., 0., 8.]]),
  13588. bin_edges=(tensor([0.0000, 0.6667, 1.3333, 2.0000]),
  13589. tensor([0.0000, 0.6667, 1.3333, 2.0000])))
  13590. >>> torch.histogramdd(torch.tensor([[0., 0.], [1., 1.], [2., 2.]]), bins=[2, 2],
  13591. ... range=[0., 1., 0., 1.], density=True)
  13592. torch.return_types.histogramdd(
  13593. hist=tensor([[2., 0.],
  13594. [0., 2.]]),
  13595. bin_edges=(tensor([0.0000, 0.5000, 1.0000]),
  13596. tensor([0.0000, 0.5000, 1.0000])))
  13597. """
  13598. @overload
  13599. def histogramdd(
  13600. input: Tensor,
  13601. bins: _size,
  13602. range: Sequence[_float] | None = None,
  13603. weight: Tensor | None = None,
  13604. density: _bool = False,
  13605. ) -> torch.return_types.histogramdd:
  13606. r"""
  13607. histogramdd(input, bins, *, range=None, weight=None, density=False, out=None) -> (Tensor, Tensor[])
  13608. Computes a multi-dimensional histogram of the values in a tensor.
  13609. Interprets the elements of an input tensor whose innermost dimension has size N
  13610. as a collection of N-dimensional points. Maps each of the points into a set of
  13611. N-dimensional bins and returns the number of points (or total weight) in each bin.
  13612. :attr:`input` must be a tensor with at least 2 dimensions.
  13613. If input has shape (M, N), each of its M rows defines a point in N-dimensional space.
  13614. If input has three or more dimensions, all but the last dimension are flattened.
  13615. Each dimension is independently associated with its own strictly increasing sequence
  13616. of bin edges. Bin edges may be specified explicitly by passing a sequence of 1D
  13617. tensors. Alternatively, bin edges may be constructed automatically by passing a
  13618. sequence of integers specifying the number of equal-width bins in each dimension.
  13619. For each N-dimensional point in input:
  13620. - Each of its coordinates is binned independently among the bin edges
  13621. corresponding to its dimension
  13622. - Binning results are combined to identify the N-dimensional bin (if any)
  13623. into which the point falls
  13624. - If the point falls into a bin, the bin's count (or total weight) is incremented
  13625. - Points which do not fall into any bin do not contribute to the output
  13626. :attr:`bins` can be a sequence of N 1D tensors, a sequence of N ints, or a single int.
  13627. If :attr:`bins` is a sequence of N 1D tensors, it explicitly specifies the N sequences
  13628. of bin edges. Each 1D tensor should contain a strictly increasing sequence with at
  13629. least one element. A sequence of K bin edges defines K-1 bins, explicitly specifying
  13630. the left and right edges of all bins. Every bin is inclusive of its left edge. Only
  13631. the rightmost bin is inclusive of its right edge.
  13632. If :attr:`bins` is a sequence of N ints, it specifies the number of equal-width bins
  13633. in each dimension. By default, the leftmost and rightmost bin edges in each dimension
  13634. are determined by the minimum and maximum elements of the input tensor in the
  13635. corresponding dimension. The :attr:`range` argument can be provided to manually
  13636. specify the leftmost and rightmost bin edges in each dimension.
  13637. If :attr:`bins` is an int, it specifies the number of equal-width bins for all dimensions.
  13638. .. note::
  13639. See also :func:`torch.histogram`, which specifically computes 1D histograms.
  13640. While :func:`torch.histogramdd` infers the dimensionality of its bins and
  13641. binned values from the shape of :attr:`input`, :func:`torch.histogram`
  13642. accepts and flattens :attr:`input` of any shape.
  13643. Args:
  13644. input (Tensor): the input tensor.
  13645. bins: Tensor[], int[], or int.
  13646. If Tensor[], defines the sequences of bin edges.
  13647. If int[], defines the number of equal-width bins in each dimension.
  13648. If int, defines the number of equal-width bins for all dimensions.
  13649. Keyword args:
  13650. range (sequence of float): Defines the leftmost and rightmost bin edges
  13651. in each dimension.
  13652. weight (Tensor): By default, each value in the input has weight 1. If a weight
  13653. tensor is passed, each N-dimensional coordinate in input
  13654. contributes its associated weight towards its bin's result.
  13655. The weight tensor should have the same shape as the :attr:`input`
  13656. tensor excluding its innermost dimension N.
  13657. density (bool): If False (default), the result will contain the count (or total weight)
  13658. in each bin. If True, each count (weight) is divided by the total count
  13659. (total weight), then divided by the volume of its associated bin.
  13660. Returns:
  13661. hist (Tensor): N-dimensional Tensor containing the values of the histogram.
  13662. bin_edges(Tensor[]): sequence of N 1D Tensors containing the bin edges.
  13663. Example::
  13664. >>> torch.histogramdd(torch.tensor([[0., 1.], [1., 0.], [2., 0.], [2., 2.]]), bins=[3, 3],
  13665. ... weight=torch.tensor([1., 2., 4., 8.]))
  13666. torch.return_types.histogramdd(
  13667. hist=tensor([[0., 1., 0.],
  13668. [2., 0., 0.],
  13669. [4., 0., 8.]]),
  13670. bin_edges=(tensor([0.0000, 0.6667, 1.3333, 2.0000]),
  13671. tensor([0.0000, 0.6667, 1.3333, 2.0000])))
  13672. >>> torch.histogramdd(torch.tensor([[0., 0.], [1., 1.], [2., 2.]]), bins=[2, 2],
  13673. ... range=[0., 1., 0., 1.], density=True)
  13674. torch.return_types.histogramdd(
  13675. hist=tensor([[2., 0.],
  13676. [0., 2.]]),
  13677. bin_edges=(tensor([0.0000, 0.5000, 1.0000]),
  13678. tensor([0.0000, 0.5000, 1.0000])))
  13679. """
  13680. @overload
  13681. def histogramdd(
  13682. input: Tensor,
  13683. bins: tuple[Tensor, ...] | list[Tensor] | None,
  13684. range: Sequence[_float] | None = None,
  13685. weight: Tensor | None = None,
  13686. density: _bool = False,
  13687. ) -> torch.return_types.histogramdd:
  13688. r"""
  13689. histogramdd(input, bins, *, range=None, weight=None, density=False, out=None) -> (Tensor, Tensor[])
  13690. Computes a multi-dimensional histogram of the values in a tensor.
  13691. Interprets the elements of an input tensor whose innermost dimension has size N
  13692. as a collection of N-dimensional points. Maps each of the points into a set of
  13693. N-dimensional bins and returns the number of points (or total weight) in each bin.
  13694. :attr:`input` must be a tensor with at least 2 dimensions.
  13695. If input has shape (M, N), each of its M rows defines a point in N-dimensional space.
  13696. If input has three or more dimensions, all but the last dimension are flattened.
  13697. Each dimension is independently associated with its own strictly increasing sequence
  13698. of bin edges. Bin edges may be specified explicitly by passing a sequence of 1D
  13699. tensors. Alternatively, bin edges may be constructed automatically by passing a
  13700. sequence of integers specifying the number of equal-width bins in each dimension.
  13701. For each N-dimensional point in input:
  13702. - Each of its coordinates is binned independently among the bin edges
  13703. corresponding to its dimension
  13704. - Binning results are combined to identify the N-dimensional bin (if any)
  13705. into which the point falls
  13706. - If the point falls into a bin, the bin's count (or total weight) is incremented
  13707. - Points which do not fall into any bin do not contribute to the output
  13708. :attr:`bins` can be a sequence of N 1D tensors, a sequence of N ints, or a single int.
  13709. If :attr:`bins` is a sequence of N 1D tensors, it explicitly specifies the N sequences
  13710. of bin edges. Each 1D tensor should contain a strictly increasing sequence with at
  13711. least one element. A sequence of K bin edges defines K-1 bins, explicitly specifying
  13712. the left and right edges of all bins. Every bin is inclusive of its left edge. Only
  13713. the rightmost bin is inclusive of its right edge.
  13714. If :attr:`bins` is a sequence of N ints, it specifies the number of equal-width bins
  13715. in each dimension. By default, the leftmost and rightmost bin edges in each dimension
  13716. are determined by the minimum and maximum elements of the input tensor in the
  13717. corresponding dimension. The :attr:`range` argument can be provided to manually
  13718. specify the leftmost and rightmost bin edges in each dimension.
  13719. If :attr:`bins` is an int, it specifies the number of equal-width bins for all dimensions.
  13720. .. note::
  13721. See also :func:`torch.histogram`, which specifically computes 1D histograms.
  13722. While :func:`torch.histogramdd` infers the dimensionality of its bins and
  13723. binned values from the shape of :attr:`input`, :func:`torch.histogram`
  13724. accepts and flattens :attr:`input` of any shape.
  13725. Args:
  13726. input (Tensor): the input tensor.
  13727. bins: Tensor[], int[], or int.
  13728. If Tensor[], defines the sequences of bin edges.
  13729. If int[], defines the number of equal-width bins in each dimension.
  13730. If int, defines the number of equal-width bins for all dimensions.
  13731. Keyword args:
  13732. range (sequence of float): Defines the leftmost and rightmost bin edges
  13733. in each dimension.
  13734. weight (Tensor): By default, each value in the input has weight 1. If a weight
  13735. tensor is passed, each N-dimensional coordinate in input
  13736. contributes its associated weight towards its bin's result.
  13737. The weight tensor should have the same shape as the :attr:`input`
  13738. tensor excluding its innermost dimension N.
  13739. density (bool): If False (default), the result will contain the count (or total weight)
  13740. in each bin. If True, each count (weight) is divided by the total count
  13741. (total weight), then divided by the volume of its associated bin.
  13742. Returns:
  13743. hist (Tensor): N-dimensional Tensor containing the values of the histogram.
  13744. bin_edges(Tensor[]): sequence of N 1D Tensors containing the bin edges.
  13745. Example::
  13746. >>> torch.histogramdd(torch.tensor([[0., 1.], [1., 0.], [2., 0.], [2., 2.]]), bins=[3, 3],
  13747. ... weight=torch.tensor([1., 2., 4., 8.]))
  13748. torch.return_types.histogramdd(
  13749. hist=tensor([[0., 1., 0.],
  13750. [2., 0., 0.],
  13751. [4., 0., 8.]]),
  13752. bin_edges=(tensor([0.0000, 0.6667, 1.3333, 2.0000]),
  13753. tensor([0.0000, 0.6667, 1.3333, 2.0000])))
  13754. >>> torch.histogramdd(torch.tensor([[0., 0.], [1., 1.], [2., 2.]]), bins=[2, 2],
  13755. ... range=[0., 1., 0., 1.], density=True)
  13756. torch.return_types.histogramdd(
  13757. hist=tensor([[2., 0.],
  13758. [0., 2.]]),
  13759. bin_edges=(tensor([0.0000, 0.5000, 1.0000]),
  13760. tensor([0.0000, 0.5000, 1.0000])))
  13761. """
  13762. def hsmm(input: Tensor, mat2: Tensor) -> Tensor: ...
  13763. @overload
  13764. def hsplit(input: Tensor, sections: _int) -> tuple[Tensor, ...]:
  13765. r"""
  13766. hsplit(input, indices_or_sections) -> List of Tensors
  13767. Splits :attr:`input`, a tensor with one or more dimensions, into multiple tensors
  13768. horizontally according to :attr:`indices_or_sections`. Each split is a view of
  13769. :attr:`input`.
  13770. If :attr:`input` is one dimensional this is equivalent to calling
  13771. torch.tensor_split(input, indices_or_sections, dim=0) (the split dimension is
  13772. zero), and if :attr:`input` has two or more dimensions it's equivalent to calling
  13773. torch.tensor_split(input, indices_or_sections, dim=1) (the split dimension is 1),
  13774. except that if :attr:`indices_or_sections` is an integer it must evenly divide
  13775. the split dimension or a runtime error will be thrown.
  13776. This function is based on NumPy's :func:`numpy.hsplit`.
  13777. Args:
  13778. input (Tensor): tensor to split.
  13779. indices_or_sections (int or list or tuple of ints): See argument in :func:`torch.tensor_split`.
  13780. Example::
  13781. >>> t = torch.arange(16.0).reshape(4,4)
  13782. >>> t
  13783. tensor([[ 0., 1., 2., 3.],
  13784. [ 4., 5., 6., 7.],
  13785. [ 8., 9., 10., 11.],
  13786. [12., 13., 14., 15.]])
  13787. >>> torch.hsplit(t, 2)
  13788. (tensor([[ 0., 1.],
  13789. [ 4., 5.],
  13790. [ 8., 9.],
  13791. [12., 13.]]),
  13792. tensor([[ 2., 3.],
  13793. [ 6., 7.],
  13794. [10., 11.],
  13795. [14., 15.]]))
  13796. >>> torch.hsplit(t, [3, 6])
  13797. (tensor([[ 0., 1., 2.],
  13798. [ 4., 5., 6.],
  13799. [ 8., 9., 10.],
  13800. [12., 13., 14.]]),
  13801. tensor([[ 3.],
  13802. [ 7.],
  13803. [11.],
  13804. [15.]]),
  13805. tensor([], size=(4, 0)))
  13806. """
  13807. @overload
  13808. def hsplit(input: Tensor, indices: _size) -> tuple[Tensor, ...]:
  13809. r"""
  13810. hsplit(input, indices_or_sections) -> List of Tensors
  13811. Splits :attr:`input`, a tensor with one or more dimensions, into multiple tensors
  13812. horizontally according to :attr:`indices_or_sections`. Each split is a view of
  13813. :attr:`input`.
  13814. If :attr:`input` is one dimensional this is equivalent to calling
  13815. torch.tensor_split(input, indices_or_sections, dim=0) (the split dimension is
  13816. zero), and if :attr:`input` has two or more dimensions it's equivalent to calling
  13817. torch.tensor_split(input, indices_or_sections, dim=1) (the split dimension is 1),
  13818. except that if :attr:`indices_or_sections` is an integer it must evenly divide
  13819. the split dimension or a runtime error will be thrown.
  13820. This function is based on NumPy's :func:`numpy.hsplit`.
  13821. Args:
  13822. input (Tensor): tensor to split.
  13823. indices_or_sections (int or list or tuple of ints): See argument in :func:`torch.tensor_split`.
  13824. Example::
  13825. >>> t = torch.arange(16.0).reshape(4,4)
  13826. >>> t
  13827. tensor([[ 0., 1., 2., 3.],
  13828. [ 4., 5., 6., 7.],
  13829. [ 8., 9., 10., 11.],
  13830. [12., 13., 14., 15.]])
  13831. >>> torch.hsplit(t, 2)
  13832. (tensor([[ 0., 1.],
  13833. [ 4., 5.],
  13834. [ 8., 9.],
  13835. [12., 13.]]),
  13836. tensor([[ 2., 3.],
  13837. [ 6., 7.],
  13838. [10., 11.],
  13839. [14., 15.]]))
  13840. >>> torch.hsplit(t, [3, 6])
  13841. (tensor([[ 0., 1., 2.],
  13842. [ 4., 5., 6.],
  13843. [ 8., 9., 10.],
  13844. [12., 13., 14.]]),
  13845. tensor([[ 3.],
  13846. [ 7.],
  13847. [11.],
  13848. [15.]]),
  13849. tensor([], size=(4, 0)))
  13850. """
  13851. def hspmm(
  13852. mat1: Tensor,
  13853. mat2: Tensor,
  13854. *,
  13855. out: Tensor | None = None,
  13856. ) -> Tensor:
  13857. r"""
  13858. hspmm(mat1, mat2, *, out=None) -> Tensor
  13859. Performs a matrix multiplication of a :ref:`sparse COO matrix
  13860. <sparse-coo-docs>` :attr:`mat1` and a strided matrix :attr:`mat2`. The
  13861. result is a (1 + 1)-dimensional :ref:`hybrid COO matrix
  13862. <sparse-hybrid-coo-docs>`.
  13863. Args:
  13864. mat1 (Tensor): the first sparse matrix to be matrix multiplied
  13865. mat2 (Tensor): the second strided matrix to be matrix multiplied
  13866. Keyword args:
  13867. out (Tensor, optional): the output tensor.
  13868. """
  13869. def hstack(
  13870. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  13871. *,
  13872. out: Tensor | None = None,
  13873. ) -> Tensor:
  13874. r"""
  13875. hstack(tensors, *, out=None) -> Tensor
  13876. Stack tensors in sequence horizontally (column wise).
  13877. This is equivalent to concatenation along the first axis for 1-D tensors, and along the second axis for all other tensors.
  13878. Args:
  13879. tensors (sequence of Tensors): sequence of tensors to concatenate
  13880. Keyword args:
  13881. out (Tensor, optional): the output tensor.
  13882. Example::
  13883. >>> a = torch.tensor([1, 2, 3])
  13884. >>> b = torch.tensor([4, 5, 6])
  13885. >>> torch.hstack((a,b))
  13886. tensor([1, 2, 3, 4, 5, 6])
  13887. >>> a = torch.tensor([[1],[2],[3]])
  13888. >>> b = torch.tensor([[4],[5],[6]])
  13889. >>> torch.hstack((a,b))
  13890. tensor([[1, 4],
  13891. [2, 5],
  13892. [3, 6]])
  13893. """
  13894. def hypot(
  13895. input: Tensor,
  13896. other: Tensor,
  13897. *,
  13898. out: Tensor | None = None,
  13899. ) -> Tensor:
  13900. r"""
  13901. hypot(input, other, *, out=None) -> Tensor
  13902. Given the legs of a right triangle, return its hypotenuse.
  13903. .. math::
  13904. \text{out}_{i} = \sqrt{\text{input}_{i}^{2} + \text{other}_{i}^{2}}
  13905. The shapes of ``input`` and ``other`` must be
  13906. :ref:`broadcastable <broadcasting-semantics>`.
  13907. Args:
  13908. input (Tensor): the first input tensor
  13909. other (Tensor): the second input tensor
  13910. Keyword args:
  13911. out (Tensor, optional): the output tensor.
  13912. Example::
  13913. >>> a = torch.hypot(torch.tensor([4.0]), torch.tensor([3.0, 4.0, 5.0]))
  13914. tensor([5.0000, 5.6569, 6.4031])
  13915. """
  13916. def i0(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  13917. r"""
  13918. i0(input, *, out=None) -> Tensor
  13919. Alias for :func:`torch.special.i0`.
  13920. """
  13921. def i0_(input: Tensor) -> Tensor: ...
  13922. def igamma(
  13923. input: Tensor,
  13924. other: Tensor,
  13925. *,
  13926. out: Tensor | None = None,
  13927. ) -> Tensor:
  13928. r"""
  13929. igamma(input, other, *, out=None) -> Tensor
  13930. Alias for :func:`torch.special.gammainc`.
  13931. """
  13932. def igammac(
  13933. input: Tensor,
  13934. other: Tensor,
  13935. *,
  13936. out: Tensor | None = None,
  13937. ) -> Tensor:
  13938. r"""
  13939. igammac(input, other, *, out=None) -> Tensor
  13940. Alias for :func:`torch.special.gammaincc`.
  13941. """
  13942. def imag(input: Tensor) -> Tensor:
  13943. r"""
  13944. imag(input) -> Tensor
  13945. Returns a new tensor containing imaginary values of the :attr:`self` tensor.
  13946. The returned tensor and :attr:`self` share the same underlying storage.
  13947. .. warning::
  13948. :func:`imag` is only supported for tensors with complex dtypes.
  13949. Args:
  13950. input (Tensor): the input tensor.
  13951. Example::
  13952. >>> x=torch.randn(4, dtype=torch.cfloat)
  13953. >>> x
  13954. tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
  13955. >>> x.imag
  13956. tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
  13957. """
  13958. @overload
  13959. def index_add(
  13960. input: Tensor,
  13961. dim: _int,
  13962. index: Tensor,
  13963. source: Tensor,
  13964. *,
  13965. alpha: Number | _complex = 1,
  13966. out: Tensor | None = None,
  13967. ) -> Tensor:
  13968. r"""
  13969. index_add(input: Tensor, dim: int, index: Tensor, source: Tensor, *, alpha: Union[Number, _complex] = 1, out: Optional[Tensor]) -> Tensor # noqa: B950
  13970. See :meth:`~Tensor.index_add_` for function description.
  13971. """
  13972. @overload
  13973. def index_add(
  13974. input: Tensor,
  13975. dim: str | EllipsisType | None,
  13976. index: Tensor,
  13977. source: Tensor,
  13978. *,
  13979. alpha: Number | _complex = 1,
  13980. ) -> Tensor:
  13981. r"""
  13982. index_add(input: Tensor, dim: int, index: Tensor, source: Tensor, *, alpha: Union[Number, _complex] = 1, out: Optional[Tensor]) -> Tensor # noqa: B950
  13983. See :meth:`~Tensor.index_add_` for function description.
  13984. """
  13985. @overload
  13986. def index_copy(
  13987. input: Tensor,
  13988. dim: _int,
  13989. index: Tensor,
  13990. source: Tensor,
  13991. *,
  13992. out: Tensor | None = None,
  13993. ) -> Tensor:
  13994. r"""
  13995. index_copy(input: Tensor, dim: int, index: Tensor, source: Tensor, *, out: Optional[Tensor]) -> Tensor
  13996. See :meth:`~Tensor.index_add_` for function description.
  13997. """
  13998. @overload
  13999. def index_copy(
  14000. input: Tensor,
  14001. dim: str | EllipsisType | None,
  14002. index: Tensor,
  14003. source: Tensor,
  14004. ) -> Tensor:
  14005. r"""
  14006. index_copy(input: Tensor, dim: int, index: Tensor, source: Tensor, *, out: Optional[Tensor]) -> Tensor
  14007. See :meth:`~Tensor.index_add_` for function description.
  14008. """
  14009. @overload
  14010. def index_fill(
  14011. input: Tensor,
  14012. dim: _int,
  14013. index: Tensor,
  14014. value: Tensor,
  14015. ) -> Tensor: ...
  14016. @overload
  14017. def index_fill(
  14018. input: Tensor,
  14019. dim: str | EllipsisType | None,
  14020. index: Tensor,
  14021. value: Tensor,
  14022. ) -> Tensor: ...
  14023. @overload
  14024. def index_fill(
  14025. input: Tensor,
  14026. dim: _int,
  14027. index: Tensor,
  14028. value: Number | _complex,
  14029. ) -> Tensor: ...
  14030. @overload
  14031. def index_fill(
  14032. input: Tensor,
  14033. dim: str | EllipsisType | None,
  14034. index: Tensor,
  14035. value: Number | _complex,
  14036. ) -> Tensor: ...
  14037. def index_put(
  14038. input: Tensor,
  14039. indices: tuple[Tensor, ...] | list[Tensor] | None,
  14040. values: Tensor,
  14041. accumulate: _bool = False,
  14042. ) -> Tensor: ...
  14043. def index_put_(
  14044. input: Tensor,
  14045. indices: tuple[Tensor, ...] | list[Tensor] | None,
  14046. values: Tensor,
  14047. accumulate: _bool = False,
  14048. ) -> Tensor: ...
  14049. def index_reduce(
  14050. input: Tensor,
  14051. dim: _int,
  14052. index: Tensor,
  14053. source: Tensor,
  14054. reduce: str,
  14055. *,
  14056. include_self: _bool = True,
  14057. out: Tensor | None = None,
  14058. ) -> Tensor:
  14059. r"""
  14060. index_reduce(input: Tensor, dim: int, index: Tensor, source: Tensor, reduce: str, *, include_self: bool = True, out: Optional[Tensor]) -> Tensor # noqa: B950
  14061. See :meth:`~Tensor.index_reduce_` for function description.
  14062. """
  14063. @overload
  14064. def index_select(
  14065. input: Tensor,
  14066. dim: _int,
  14067. index: Tensor,
  14068. *,
  14069. out: Tensor | None = None,
  14070. ) -> Tensor:
  14071. r"""
  14072. index_select(input, dim, index, *, out=None) -> Tensor
  14073. Returns a new tensor which indexes the :attr:`input` tensor along dimension
  14074. :attr:`dim` using the entries in :attr:`index` which is a `LongTensor`.
  14075. The returned tensor has the same number of dimensions as the original tensor
  14076. (:attr:`input`). The :attr:`dim`\ th dimension has the same size as the length
  14077. of :attr:`index`; other dimensions have the same size as in the original tensor.
  14078. .. note:: The returned tensor does **not** use the same storage as the original
  14079. tensor. If :attr:`out` has a different shape than expected, we
  14080. silently change it to the correct shape, reallocating the underlying
  14081. storage if necessary.
  14082. Args:
  14083. input (Tensor): the input tensor.
  14084. dim (int): the dimension in which we index
  14085. index (IntTensor or LongTensor): the 1-D tensor containing the indices to index
  14086. Keyword args:
  14087. out (Tensor, optional): the output tensor.
  14088. Example::
  14089. >>> x = torch.randn(3, 4)
  14090. >>> x
  14091. tensor([[ 0.1427, 0.0231, -0.5414, -1.0009],
  14092. [-0.4664, 0.2647, -0.1228, -1.1068],
  14093. [-1.1734, -0.6571, 0.7230, -0.6004]])
  14094. >>> indices = torch.tensor([0, 2])
  14095. >>> torch.index_select(x, 0, indices)
  14096. tensor([[ 0.1427, 0.0231, -0.5414, -1.0009],
  14097. [-1.1734, -0.6571, 0.7230, -0.6004]])
  14098. >>> torch.index_select(x, 1, indices)
  14099. tensor([[ 0.1427, -0.5414],
  14100. [-0.4664, -0.1228],
  14101. [-1.1734, 0.7230]])
  14102. """
  14103. @overload
  14104. def index_select(
  14105. input: Tensor,
  14106. dim: str | EllipsisType | None,
  14107. index: Tensor,
  14108. *,
  14109. out: Tensor | None = None,
  14110. ) -> Tensor:
  14111. r"""
  14112. index_select(input, dim, index, *, out=None) -> Tensor
  14113. Returns a new tensor which indexes the :attr:`input` tensor along dimension
  14114. :attr:`dim` using the entries in :attr:`index` which is a `LongTensor`.
  14115. The returned tensor has the same number of dimensions as the original tensor
  14116. (:attr:`input`). The :attr:`dim`\ th dimension has the same size as the length
  14117. of :attr:`index`; other dimensions have the same size as in the original tensor.
  14118. .. note:: The returned tensor does **not** use the same storage as the original
  14119. tensor. If :attr:`out` has a different shape than expected, we
  14120. silently change it to the correct shape, reallocating the underlying
  14121. storage if necessary.
  14122. Args:
  14123. input (Tensor): the input tensor.
  14124. dim (int): the dimension in which we index
  14125. index (IntTensor or LongTensor): the 1-D tensor containing the indices to index
  14126. Keyword args:
  14127. out (Tensor, optional): the output tensor.
  14128. Example::
  14129. >>> x = torch.randn(3, 4)
  14130. >>> x
  14131. tensor([[ 0.1427, 0.0231, -0.5414, -1.0009],
  14132. [-0.4664, 0.2647, -0.1228, -1.1068],
  14133. [-1.1734, -0.6571, 0.7230, -0.6004]])
  14134. >>> indices = torch.tensor([0, 2])
  14135. >>> torch.index_select(x, 0, indices)
  14136. tensor([[ 0.1427, 0.0231, -0.5414, -1.0009],
  14137. [-1.1734, -0.6571, 0.7230, -0.6004]])
  14138. >>> torch.index_select(x, 1, indices)
  14139. tensor([[ 0.1427, -0.5414],
  14140. [-0.4664, -0.1228],
  14141. [-1.1734, 0.7230]])
  14142. """
  14143. def indices_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  14144. r"""
  14145. Performs the same operation as :func:`torch.indices`, but all output tensors
  14146. are freshly created instead of aliasing the input.
  14147. """
  14148. def init_num_threads() -> None: ...
  14149. def inner(
  14150. input: Tensor,
  14151. other: Tensor,
  14152. *,
  14153. out: Tensor | None = None,
  14154. ) -> Tensor:
  14155. r"""
  14156. inner(input, other, *, out=None) -> Tensor
  14157. Computes the dot product for 1D tensors. For higher dimensions, sums the product
  14158. of elements from :attr:`input` and :attr:`other` along their last dimension.
  14159. .. note::
  14160. If either :attr:`input` or :attr:`other` is a scalar, the result is equivalent
  14161. to `torch.mul(input, other)`.
  14162. If both :attr:`input` and :attr:`other` are non-scalars, the size of their last
  14163. dimension must match and the result is equivalent to `torch.tensordot(input,
  14164. other, dims=([-1], [-1]))`
  14165. Args:
  14166. input (Tensor): First input tensor
  14167. other (Tensor): Second input tensor
  14168. Keyword args:
  14169. out (Tensor, optional): Optional output tensor to write result into. The output
  14170. shape is `input.shape[:-1] + other.shape[:-1]`.
  14171. Example::
  14172. # Dot product
  14173. >>> torch.inner(torch.tensor([1, 2, 3]), torch.tensor([0, 2, 1]))
  14174. tensor(7)
  14175. # Multidimensional input tensors
  14176. >>> a = torch.randn(2, 3)
  14177. >>> a
  14178. tensor([[0.8173, 1.0874, 1.1784],
  14179. [0.3279, 0.1234, 2.7894]])
  14180. >>> b = torch.randn(2, 4, 3)
  14181. >>> b
  14182. tensor([[[-0.4682, -0.7159, 0.1506],
  14183. [ 0.4034, -0.3657, 1.0387],
  14184. [ 0.9892, -0.6684, 0.1774],
  14185. [ 0.9482, 1.3261, 0.3917]],
  14186. [[ 0.4537, 0.7493, 1.1724],
  14187. [ 0.2291, 0.5749, -0.2267],
  14188. [-0.7920, 0.3607, -0.3701],
  14189. [ 1.3666, -0.5850, -1.7242]]])
  14190. >>> torch.inner(a, b)
  14191. tensor([[[-0.9837, 1.1560, 0.2907, 2.6785],
  14192. [ 2.5671, 0.5452, -0.6912, -1.5509]],
  14193. [[ 0.1782, 2.9843, 0.7366, 1.5672],
  14194. [ 3.5115, -0.4864, -1.2476, -4.4337]]])
  14195. # Scalar input
  14196. >>> torch.inner(a, torch.tensor(2))
  14197. tensor([[1.6347, 2.1748, 2.3567],
  14198. [0.6558, 0.2469, 5.5787]])
  14199. """
  14200. def instance_norm(
  14201. input: Tensor,
  14202. weight: Tensor | None,
  14203. bias: Tensor | None,
  14204. running_mean: Tensor | None,
  14205. running_var: Tensor | None,
  14206. use_input_stats: _bool,
  14207. momentum: _float,
  14208. eps: _float,
  14209. cudnn_enabled: _bool,
  14210. ) -> Tensor: ...
  14211. def int_repr(input: Tensor) -> Tensor: ...
  14212. def inverse(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  14213. r"""
  14214. inverse(input, *, out=None) -> Tensor
  14215. Alias for :func:`torch.linalg.inv`
  14216. """
  14217. def is_complex(input: Tensor) -> _bool:
  14218. r"""
  14219. is_complex(input: Tensor) -> bool
  14220. Returns True if the data type of :attr:`input` is a complex data type i.e.,
  14221. one of ``torch.complex64``, and ``torch.complex128``.
  14222. Args:
  14223. input (Tensor): the input tensor.
  14224. Example::
  14225. >>> torch.is_complex(torch.tensor([1, 2, 3], dtype=torch.complex64))
  14226. True
  14227. >>> torch.is_complex(torch.tensor([1, 2, 3], dtype=torch.complex128))
  14228. True
  14229. >>> torch.is_complex(torch.tensor([1, 2, 3], dtype=torch.int32))
  14230. False
  14231. >>> torch.is_complex(torch.tensor([1.0, 2.0, 3.0], dtype=torch.float16))
  14232. False
  14233. """
  14234. def is_conj(input: Tensor) -> _bool:
  14235. r"""
  14236. is_conj(input) -> (bool)
  14237. Returns True if the :attr:`input` is a conjugated tensor, i.e. its conjugate bit is set to `True`.
  14238. Args:
  14239. input (Tensor): the input tensor.
  14240. """
  14241. def is_distributed(input: Tensor) -> _bool: ...
  14242. def is_floating_point(input: Tensor) -> _bool:
  14243. r"""
  14244. is_floating_point(input: Tensor) -> bool
  14245. Returns True if the data type of :attr:`input` is a floating point data type i.e.,
  14246. one of ``torch.float64``, ``torch.float32``, ``torch.float16``, and ``torch.bfloat16``.
  14247. Args:
  14248. input (Tensor): the input tensor.
  14249. Example::
  14250. >>> torch.is_floating_point(torch.tensor([1.0, 2.0, 3.0]))
  14251. True
  14252. >>> torch.is_floating_point(torch.tensor([1, 2, 3], dtype=torch.int32))
  14253. False
  14254. >>> torch.is_floating_point(torch.tensor([1.0, 2.0, 3.0], dtype=torch.float16))
  14255. True
  14256. >>> torch.is_floating_point(torch.tensor([1, 2, 3], dtype=torch.complex64))
  14257. False
  14258. """
  14259. def is_grad_enabled() -> _bool:
  14260. r"""
  14261. is_grad_enabled() -> (bool)
  14262. Returns True if grad mode is currently enabled.
  14263. """
  14264. def is_inference(input: Tensor) -> _bool:
  14265. r"""
  14266. is_inference(input) -> (bool)
  14267. Returns True if :attr:`input` is an inference tensor.
  14268. A non-view tensor is an inference tensor if and only if it was
  14269. allocated during inference mode. A view tensor is an inference
  14270. tensor if and only if the tensor it is a view of is an inference tensor.
  14271. For details on inference mode please see
  14272. `Inference Mode <https://pytorch.org/cppdocs/notes/inference_mode.html>`_.
  14273. Args:
  14274. input (Tensor): the input tensor.
  14275. """
  14276. def is_inference_mode_enabled() -> _bool:
  14277. r"""
  14278. is_inference_mode_enabled() -> (bool)
  14279. Returns True if inference mode is currently enabled.
  14280. """
  14281. def is_neg(input: Tensor) -> _bool: ...
  14282. def is_nonzero(input: Tensor) -> _bool:
  14283. r"""
  14284. is_nonzero(input) -> (bool)
  14285. Returns True if the :attr:`input` is a single element tensor which is not equal to zero
  14286. after type conversions.
  14287. i.e. not equal to ``torch.tensor([0.])`` or ``torch.tensor([0])`` or
  14288. ``torch.tensor([False])``.
  14289. Throws a ``RuntimeError`` if ``torch.numel() != 1`` (even in case
  14290. of sparse tensors).
  14291. Args:
  14292. input (Tensor): the input tensor.
  14293. Examples::
  14294. >>> torch.is_nonzero(torch.tensor([0.]))
  14295. False
  14296. >>> torch.is_nonzero(torch.tensor([1.5]))
  14297. True
  14298. >>> torch.is_nonzero(torch.tensor([False]))
  14299. False
  14300. >>> torch.is_nonzero(torch.tensor([3]))
  14301. True
  14302. >>> torch.is_nonzero(torch.tensor([1, 3, 5]))
  14303. Traceback (most recent call last):
  14304. ...
  14305. RuntimeError: Boolean value of Tensor with more than one value is ambiguous
  14306. >>> torch.is_nonzero(torch.tensor([]))
  14307. Traceback (most recent call last):
  14308. ...
  14309. RuntimeError: Boolean value of Tensor with no values is ambiguous
  14310. """
  14311. def is_same_size(input: Tensor, other: Tensor) -> _bool: ...
  14312. def is_signed(input: Tensor) -> _bool: ...
  14313. def is_vulkan_available() -> _bool: ...
  14314. def isclose(
  14315. input: Tensor,
  14316. other: Tensor,
  14317. rtol: _float = 1e-05,
  14318. atol: _float = 1e-08,
  14319. equal_nan: _bool = False,
  14320. ) -> Tensor:
  14321. r"""
  14322. isclose(input, other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
  14323. Returns a new tensor with boolean elements representing if each element of
  14324. :attr:`input` is "close" to the corresponding element of :attr:`other`.
  14325. Closeness is defined as:
  14326. .. math::
  14327. \lvert \text{input}_i - \text{other}_i \rvert \leq \texttt{rtol} \times \lvert \text{other}_i \rvert + \texttt{atol}
  14328. where :attr:`input` and :attr:`other` are finite. Where :attr:`input`
  14329. and/or :attr:`other` are nonfinite they are close if and only if
  14330. they are equal, with NaNs being considered equal to each other when
  14331. :attr:`equal_nan` is True.
  14332. Args:
  14333. input (Tensor): first tensor to compare
  14334. other (Tensor): second tensor to compare
  14335. rtol (float, optional): relative tolerance. Default: 1e-05
  14336. atol (float, optional): absolute tolerance. Default: 1e-08
  14337. equal_nan (bool, optional): if ``True``, then two ``NaN`` s will be considered equal. Default: ``False``
  14338. Examples::
  14339. >>> torch.isclose(torch.tensor((1., 2, 3)), torch.tensor((1 + 1e-10, 3, 4)))
  14340. tensor([ True, False, False])
  14341. >>> torch.isclose(torch.tensor((float('inf'), 4)), torch.tensor((float('inf'), 6)), rtol=.5)
  14342. tensor([True, True])
  14343. """
  14344. def isfinite(input: Tensor) -> Tensor:
  14345. r"""
  14346. isfinite(input) -> Tensor
  14347. Returns a new tensor with boolean elements representing if each element is `finite` or not.
  14348. Real values are finite when they are not NaN, negative infinity, or infinity.
  14349. Complex values are finite when both their real and imaginary parts are finite.
  14350. Args:
  14351. input (Tensor): the input tensor.
  14352. Returns:
  14353. A boolean tensor that is True where :attr:`input` is finite and False elsewhere
  14354. Example::
  14355. >>> torch.isfinite(torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')]))
  14356. tensor([True, False, True, False, False])
  14357. """
  14358. @overload
  14359. def isin(
  14360. elements: Tensor,
  14361. test_elements: Tensor,
  14362. *,
  14363. assume_unique: _bool = False,
  14364. invert: _bool = False,
  14365. out: Tensor | None = None,
  14366. ) -> Tensor:
  14367. r"""
  14368. isin(elements, test_elements, *, assume_unique=False, invert=False) -> Tensor
  14369. Tests if each element of :attr:`elements` is in :attr:`test_elements`. Returns
  14370. a boolean tensor of the same shape as :attr:`elements` that is True for elements
  14371. in :attr:`test_elements` and False otherwise.
  14372. .. note::
  14373. One of :attr:`elements` or :attr:`test_elements` can be a scalar, but not both.
  14374. Args:
  14375. elements (Tensor or Scalar): Input elements
  14376. test_elements (Tensor or Scalar): Values against which to test for each input element
  14377. assume_unique (bool, optional): If True, assumes both :attr:`elements` and
  14378. :attr:`test_elements` contain unique elements, which can speed up the
  14379. calculation. Default: False
  14380. invert (bool, optional): If True, inverts the boolean return tensor, resulting in True
  14381. values for elements *not* in :attr:`test_elements`. Default: False
  14382. Returns:
  14383. A boolean tensor of the same shape as :attr:`elements` that is True for elements in
  14384. :attr:`test_elements` and False otherwise
  14385. Example:
  14386. >>> torch.isin(torch.tensor([[1, 2], [3, 4]]), torch.tensor([2, 3]))
  14387. tensor([[False, True],
  14388. [ True, False]])
  14389. """
  14390. @overload
  14391. def isin(
  14392. element: Number | _complex,
  14393. test_elements: Tensor,
  14394. *,
  14395. assume_unique: _bool = False,
  14396. invert: _bool = False,
  14397. out: Tensor | None = None,
  14398. ) -> Tensor:
  14399. r"""
  14400. isin(elements, test_elements, *, assume_unique=False, invert=False) -> Tensor
  14401. Tests if each element of :attr:`elements` is in :attr:`test_elements`. Returns
  14402. a boolean tensor of the same shape as :attr:`elements` that is True for elements
  14403. in :attr:`test_elements` and False otherwise.
  14404. .. note::
  14405. One of :attr:`elements` or :attr:`test_elements` can be a scalar, but not both.
  14406. Args:
  14407. elements (Tensor or Scalar): Input elements
  14408. test_elements (Tensor or Scalar): Values against which to test for each input element
  14409. assume_unique (bool, optional): If True, assumes both :attr:`elements` and
  14410. :attr:`test_elements` contain unique elements, which can speed up the
  14411. calculation. Default: False
  14412. invert (bool, optional): If True, inverts the boolean return tensor, resulting in True
  14413. values for elements *not* in :attr:`test_elements`. Default: False
  14414. Returns:
  14415. A boolean tensor of the same shape as :attr:`elements` that is True for elements in
  14416. :attr:`test_elements` and False otherwise
  14417. Example:
  14418. >>> torch.isin(torch.tensor([[1, 2], [3, 4]]), torch.tensor([2, 3]))
  14419. tensor([[False, True],
  14420. [ True, False]])
  14421. """
  14422. @overload
  14423. def isin(
  14424. elements: Tensor,
  14425. test_element: Number | _complex,
  14426. *,
  14427. assume_unique: _bool = False,
  14428. invert: _bool = False,
  14429. out: Tensor | None = None,
  14430. ) -> Tensor:
  14431. r"""
  14432. isin(elements, test_elements, *, assume_unique=False, invert=False) -> Tensor
  14433. Tests if each element of :attr:`elements` is in :attr:`test_elements`. Returns
  14434. a boolean tensor of the same shape as :attr:`elements` that is True for elements
  14435. in :attr:`test_elements` and False otherwise.
  14436. .. note::
  14437. One of :attr:`elements` or :attr:`test_elements` can be a scalar, but not both.
  14438. Args:
  14439. elements (Tensor or Scalar): Input elements
  14440. test_elements (Tensor or Scalar): Values against which to test for each input element
  14441. assume_unique (bool, optional): If True, assumes both :attr:`elements` and
  14442. :attr:`test_elements` contain unique elements, which can speed up the
  14443. calculation. Default: False
  14444. invert (bool, optional): If True, inverts the boolean return tensor, resulting in True
  14445. values for elements *not* in :attr:`test_elements`. Default: False
  14446. Returns:
  14447. A boolean tensor of the same shape as :attr:`elements` that is True for elements in
  14448. :attr:`test_elements` and False otherwise
  14449. Example:
  14450. >>> torch.isin(torch.tensor([[1, 2], [3, 4]]), torch.tensor([2, 3]))
  14451. tensor([[False, True],
  14452. [ True, False]])
  14453. """
  14454. def isinf(input: Tensor) -> Tensor:
  14455. r"""
  14456. isinf(input) -> Tensor
  14457. Tests if each element of :attr:`input` is infinite
  14458. (positive or negative infinity) or not.
  14459. .. note::
  14460. Complex values are infinite when their real or imaginary part is
  14461. infinite.
  14462. Args:
  14463. input (Tensor): the input tensor.
  14464. Returns:
  14465. A boolean tensor that is True where :attr:`input` is infinite and False elsewhere
  14466. Example::
  14467. >>> torch.isinf(torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')]))
  14468. tensor([False, True, False, True, False])
  14469. """
  14470. def isnan(input: Tensor) -> Tensor:
  14471. r"""
  14472. isnan(input) -> Tensor
  14473. Returns a new tensor with boolean elements representing if each element of :attr:`input`
  14474. is NaN or not. Complex values are considered NaN when either their real
  14475. and/or imaginary part is NaN.
  14476. Arguments:
  14477. input (Tensor): the input tensor.
  14478. Returns:
  14479. A boolean tensor that is True where :attr:`input` is NaN and False elsewhere
  14480. Example::
  14481. >>> torch.isnan(torch.tensor([1, float('nan'), 2]))
  14482. tensor([False, True, False])
  14483. """
  14484. def isneginf(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  14485. r"""
  14486. isneginf(input, *, out=None) -> Tensor
  14487. Tests if each element of :attr:`input` is negative infinity or not.
  14488. Args:
  14489. input (Tensor): the input tensor.
  14490. Keyword args:
  14491. out (Tensor, optional): the output tensor.
  14492. Example::
  14493. >>> a = torch.tensor([-float('inf'), float('inf'), 1.2])
  14494. >>> torch.isneginf(a)
  14495. tensor([ True, False, False])
  14496. """
  14497. def isposinf(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  14498. r"""
  14499. isposinf(input, *, out=None) -> Tensor
  14500. Tests if each element of :attr:`input` is positive infinity or not.
  14501. Args:
  14502. input (Tensor): the input tensor.
  14503. Keyword args:
  14504. out (Tensor, optional): the output tensor.
  14505. Example::
  14506. >>> a = torch.tensor([-float('inf'), float('inf'), 1.2])
  14507. >>> torch.isposinf(a)
  14508. tensor([False, True, False])
  14509. """
  14510. def isreal(input: Tensor) -> Tensor:
  14511. r"""
  14512. isreal(input) -> Tensor
  14513. Returns a new tensor with boolean elements representing if each element of :attr:`input` is real-valued or not.
  14514. All real-valued types are considered real. Complex values are considered real when their imaginary part is 0.
  14515. Arguments:
  14516. input (Tensor): the input tensor.
  14517. Returns:
  14518. A boolean tensor that is True where :attr:`input` is real and False elsewhere
  14519. Example::
  14520. >>> torch.isreal(torch.tensor([1, 1+1j, 2+0j]))
  14521. tensor([True, False, True])
  14522. """
  14523. def istft(
  14524. input: Tensor,
  14525. n_fft: _int,
  14526. hop_length: _int | None = None,
  14527. win_length: _int | None = None,
  14528. window: Tensor | None = None,
  14529. center: _bool = True,
  14530. normalized: _bool = False,
  14531. onesided: _bool | None = None,
  14532. length: _int | None = None,
  14533. return_complex: _bool = False,
  14534. ) -> Tensor: ...
  14535. @overload
  14536. def kaiser_window(
  14537. window_length: _int,
  14538. *,
  14539. dtype: _dtype | None = None,
  14540. layout: _layout | None = None,
  14541. device: DeviceLikeType | None = None,
  14542. pin_memory: _bool | None = False,
  14543. requires_grad: _bool | None = False,
  14544. ) -> Tensor:
  14545. r"""
  14546. kaiser_window(window_length, periodic=True, beta=12.0, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  14547. Computes the Kaiser window with window length :attr:`window_length` and shape parameter :attr:`beta`.
  14548. Let I_0 be the zeroth order modified Bessel function of the first kind (see :func:`torch.i0`) and
  14549. ``N = L - 1`` if :attr:`periodic` is False and ``L`` if :attr:`periodic` is True,
  14550. where ``L`` is the :attr:`window_length`. This function computes:
  14551. .. math::
  14552. out_i = I_0 \left( \beta \sqrt{1 - \left( {\frac{i - N/2}{N/2}} \right) ^2 } \right) / I_0( \beta )
  14553. Calling ``torch.kaiser_window(L, B, periodic=True)`` is equivalent to calling
  14554. ``torch.kaiser_window(L + 1, B, periodic=False)[:-1])``.
  14555. The :attr:`periodic` argument is intended as a helpful shorthand
  14556. to produce a periodic window as input to functions like :func:`torch.stft`.
  14557. .. note::
  14558. If :attr:`window_length` is one, then the returned window is a single element tensor containing a one.
  14559. Args:
  14560. window_length (int): length of the window.
  14561. periodic (bool, optional): If True, returns a periodic window suitable for use in spectral analysis.
  14562. If False, returns a symmetric window suitable for use in filter design.
  14563. beta (float, optional): shape parameter for the window.
  14564. Keyword args:
  14565. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  14566. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  14567. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  14568. ``torch.strided`` (dense layout) is supported.
  14569. device (:class:`torch.device`, optional): the desired device of returned tensor.
  14570. Default: if ``None``, uses the current device for the default tensor type
  14571. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  14572. for CPU tensor types and the current CUDA device for CUDA tensor types.
  14573. requires_grad (bool, optional): If autograd should record operations on the
  14574. returned tensor. Default: ``False``.
  14575. """
  14576. @overload
  14577. def kaiser_window(
  14578. window_length: _int,
  14579. periodic: _bool,
  14580. *,
  14581. dtype: _dtype | None = None,
  14582. layout: _layout | None = None,
  14583. device: DeviceLikeType | None = None,
  14584. pin_memory: _bool | None = False,
  14585. requires_grad: _bool | None = False,
  14586. ) -> Tensor:
  14587. r"""
  14588. kaiser_window(window_length, periodic=True, beta=12.0, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  14589. Computes the Kaiser window with window length :attr:`window_length` and shape parameter :attr:`beta`.
  14590. Let I_0 be the zeroth order modified Bessel function of the first kind (see :func:`torch.i0`) and
  14591. ``N = L - 1`` if :attr:`periodic` is False and ``L`` if :attr:`periodic` is True,
  14592. where ``L`` is the :attr:`window_length`. This function computes:
  14593. .. math::
  14594. out_i = I_0 \left( \beta \sqrt{1 - \left( {\frac{i - N/2}{N/2}} \right) ^2 } \right) / I_0( \beta )
  14595. Calling ``torch.kaiser_window(L, B, periodic=True)`` is equivalent to calling
  14596. ``torch.kaiser_window(L + 1, B, periodic=False)[:-1])``.
  14597. The :attr:`periodic` argument is intended as a helpful shorthand
  14598. to produce a periodic window as input to functions like :func:`torch.stft`.
  14599. .. note::
  14600. If :attr:`window_length` is one, then the returned window is a single element tensor containing a one.
  14601. Args:
  14602. window_length (int): length of the window.
  14603. periodic (bool, optional): If True, returns a periodic window suitable for use in spectral analysis.
  14604. If False, returns a symmetric window suitable for use in filter design.
  14605. beta (float, optional): shape parameter for the window.
  14606. Keyword args:
  14607. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  14608. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  14609. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  14610. ``torch.strided`` (dense layout) is supported.
  14611. device (:class:`torch.device`, optional): the desired device of returned tensor.
  14612. Default: if ``None``, uses the current device for the default tensor type
  14613. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  14614. for CPU tensor types and the current CUDA device for CUDA tensor types.
  14615. requires_grad (bool, optional): If autograd should record operations on the
  14616. returned tensor. Default: ``False``.
  14617. """
  14618. @overload
  14619. def kaiser_window(
  14620. window_length: _int,
  14621. periodic: _bool,
  14622. beta: _float,
  14623. *,
  14624. dtype: _dtype | None = None,
  14625. layout: _layout | None = None,
  14626. device: DeviceLikeType | None = None,
  14627. pin_memory: _bool | None = False,
  14628. requires_grad: _bool | None = False,
  14629. ) -> Tensor:
  14630. r"""
  14631. kaiser_window(window_length, periodic=True, beta=12.0, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  14632. Computes the Kaiser window with window length :attr:`window_length` and shape parameter :attr:`beta`.
  14633. Let I_0 be the zeroth order modified Bessel function of the first kind (see :func:`torch.i0`) and
  14634. ``N = L - 1`` if :attr:`periodic` is False and ``L`` if :attr:`periodic` is True,
  14635. where ``L`` is the :attr:`window_length`. This function computes:
  14636. .. math::
  14637. out_i = I_0 \left( \beta \sqrt{1 - \left( {\frac{i - N/2}{N/2}} \right) ^2 } \right) / I_0( \beta )
  14638. Calling ``torch.kaiser_window(L, B, periodic=True)`` is equivalent to calling
  14639. ``torch.kaiser_window(L + 1, B, periodic=False)[:-1])``.
  14640. The :attr:`periodic` argument is intended as a helpful shorthand
  14641. to produce a periodic window as input to functions like :func:`torch.stft`.
  14642. .. note::
  14643. If :attr:`window_length` is one, then the returned window is a single element tensor containing a one.
  14644. Args:
  14645. window_length (int): length of the window.
  14646. periodic (bool, optional): If True, returns a periodic window suitable for use in spectral analysis.
  14647. If False, returns a symmetric window suitable for use in filter design.
  14648. beta (float, optional): shape parameter for the window.
  14649. Keyword args:
  14650. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  14651. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  14652. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  14653. ``torch.strided`` (dense layout) is supported.
  14654. device (:class:`torch.device`, optional): the desired device of returned tensor.
  14655. Default: if ``None``, uses the current device for the default tensor type
  14656. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  14657. for CPU tensor types and the current CUDA device for CUDA tensor types.
  14658. requires_grad (bool, optional): If autograd should record operations on the
  14659. returned tensor. Default: ``False``.
  14660. """
  14661. def kl_div(
  14662. input: Tensor,
  14663. target: Tensor,
  14664. reduction: _int = 1,
  14665. *,
  14666. log_target: _bool = False,
  14667. ) -> Tensor: ...
  14668. def kron(
  14669. input: Tensor,
  14670. other: Tensor,
  14671. *,
  14672. out: Tensor | None = None,
  14673. ) -> Tensor:
  14674. r"""
  14675. kron(input, other, *, out=None) -> Tensor
  14676. Computes the Kronecker product, denoted by :math:`\otimes`, of :attr:`input` and :attr:`other`.
  14677. If :attr:`input` is a :math:`(a_0 \times a_1 \times \dots \times a_n)` tensor and :attr:`other` is a
  14678. :math:`(b_0 \times b_1 \times \dots \times b_n)` tensor, the result will be a
  14679. :math:`(a_0*b_0 \times a_1*b_1 \times \dots \times a_n*b_n)` tensor with the following entries:
  14680. .. math::
  14681. (\text{input} \otimes \text{other})_{k_0, k_1, \dots, k_n} =
  14682. \text{input}_{i_0, i_1, \dots, i_n} * \text{other}_{j_0, j_1, \dots, j_n},
  14683. where :math:`k_t = i_t * b_t + j_t` for :math:`0 \leq t \leq n`.
  14684. If one tensor has fewer dimensions than the other it is unsqueezed until it has the same number of dimensions.
  14685. Supports real-valued and complex-valued inputs.
  14686. .. note::
  14687. This function generalizes the typical definition of the Kronecker product for two matrices to two tensors,
  14688. as described above. When :attr:`input` is a :math:`(m \times n)` matrix and :attr:`other` is a
  14689. :math:`(p \times q)` matrix, the result will be a :math:`(p*m \times q*n)` block matrix:
  14690. .. math::
  14691. \mathbf{A} \otimes \mathbf{B}=\begin{bmatrix}
  14692. a_{11} \mathbf{B} & \cdots & a_{1 n} \mathbf{B} \\
  14693. \vdots & \ddots & \vdots \\
  14694. a_{m 1} \mathbf{B} & \cdots & a_{m n} \mathbf{B} \end{bmatrix}
  14695. where :attr:`input` is :math:`\mathbf{A}` and :attr:`other` is :math:`\mathbf{B}`.
  14696. Arguments:
  14697. input (Tensor)
  14698. other (Tensor)
  14699. Keyword args:
  14700. out (Tensor, optional): The output tensor. Ignored if ``None``. Default: ``None``
  14701. Examples::
  14702. >>> mat1 = torch.eye(2)
  14703. >>> mat2 = torch.ones(2, 2)
  14704. >>> torch.kron(mat1, mat2)
  14705. tensor([[1., 1., 0., 0.],
  14706. [1., 1., 0., 0.],
  14707. [0., 0., 1., 1.],
  14708. [0., 0., 1., 1.]])
  14709. >>> mat1 = torch.eye(2)
  14710. >>> mat2 = torch.arange(1, 5).reshape(2, 2)
  14711. >>> torch.kron(mat1, mat2)
  14712. tensor([[1., 2., 0., 0.],
  14713. [3., 4., 0., 0.],
  14714. [0., 0., 1., 2.],
  14715. [0., 0., 3., 4.]])
  14716. """
  14717. @overload
  14718. def kthvalue(
  14719. input: Tensor,
  14720. k: _int | SymInt,
  14721. dim: _int = -1,
  14722. keepdim: _bool = False,
  14723. *,
  14724. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  14725. ) -> torch.return_types.kthvalue:
  14726. r"""
  14727. kthvalue(input, k, dim=None, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  14728. Returns a namedtuple ``(values, indices)`` where ``values`` is the :attr:`k` th
  14729. smallest element of each row of the :attr:`input` tensor in the given dimension
  14730. :attr:`dim`. And ``indices`` is the index location of each element found.
  14731. If :attr:`dim` is not given, the last dimension of the `input` is chosen.
  14732. If :attr:`keepdim` is ``True``, both the :attr:`values` and :attr:`indices` tensors
  14733. are the same size as :attr:`input`, except in the dimension :attr:`dim` where
  14734. they are of size 1. Otherwise, :attr:`dim` is squeezed
  14735. (see :func:`torch.squeeze`), resulting in both the :attr:`values` and
  14736. :attr:`indices` tensors having 1 fewer dimension than the :attr:`input` tensor.
  14737. .. note::
  14738. When :attr:`input` is a CUDA tensor and there are multiple valid
  14739. :attr:`k` th values, this function may nondeterministically return
  14740. :attr:`indices` for any of them.
  14741. Args:
  14742. input (Tensor): the input tensor.
  14743. k (int): k for the k-th smallest element
  14744. dim (int, optional): the dimension to find the kth value along
  14745. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  14746. Keyword args:
  14747. out (tuple, optional): the output tuple of (Tensor, LongTensor)
  14748. can be optionally given to be used as output buffers
  14749. Example::
  14750. >>> x = torch.arange(1., 6.)
  14751. >>> x
  14752. tensor([ 1., 2., 3., 4., 5.])
  14753. >>> torch.kthvalue(x, 4)
  14754. torch.return_types.kthvalue(values=tensor(4.), indices=tensor(3))
  14755. >>> x=torch.arange(1.,7.).resize_(2,3)
  14756. >>> x
  14757. tensor([[ 1., 2., 3.],
  14758. [ 4., 5., 6.]])
  14759. >>> torch.kthvalue(x, 2, 0, True)
  14760. torch.return_types.kthvalue(values=tensor([[4., 5., 6.]]), indices=tensor([[1, 1, 1]]))
  14761. """
  14762. @overload
  14763. def kthvalue(
  14764. input: Tensor,
  14765. k: _int | SymInt,
  14766. dim: str | EllipsisType | None,
  14767. keepdim: _bool = False,
  14768. *,
  14769. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  14770. ) -> torch.return_types.kthvalue:
  14771. r"""
  14772. kthvalue(input, k, dim=None, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  14773. Returns a namedtuple ``(values, indices)`` where ``values`` is the :attr:`k` th
  14774. smallest element of each row of the :attr:`input` tensor in the given dimension
  14775. :attr:`dim`. And ``indices`` is the index location of each element found.
  14776. If :attr:`dim` is not given, the last dimension of the `input` is chosen.
  14777. If :attr:`keepdim` is ``True``, both the :attr:`values` and :attr:`indices` tensors
  14778. are the same size as :attr:`input`, except in the dimension :attr:`dim` where
  14779. they are of size 1. Otherwise, :attr:`dim` is squeezed
  14780. (see :func:`torch.squeeze`), resulting in both the :attr:`values` and
  14781. :attr:`indices` tensors having 1 fewer dimension than the :attr:`input` tensor.
  14782. .. note::
  14783. When :attr:`input` is a CUDA tensor and there are multiple valid
  14784. :attr:`k` th values, this function may nondeterministically return
  14785. :attr:`indices` for any of them.
  14786. Args:
  14787. input (Tensor): the input tensor.
  14788. k (int): k for the k-th smallest element
  14789. dim (int, optional): the dimension to find the kth value along
  14790. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  14791. Keyword args:
  14792. out (tuple, optional): the output tuple of (Tensor, LongTensor)
  14793. can be optionally given to be used as output buffers
  14794. Example::
  14795. >>> x = torch.arange(1., 6.)
  14796. >>> x
  14797. tensor([ 1., 2., 3., 4., 5.])
  14798. >>> torch.kthvalue(x, 4)
  14799. torch.return_types.kthvalue(values=tensor(4.), indices=tensor(3))
  14800. >>> x=torch.arange(1.,7.).resize_(2,3)
  14801. >>> x
  14802. tensor([[ 1., 2., 3.],
  14803. [ 4., 5., 6.]])
  14804. >>> torch.kthvalue(x, 2, 0, True)
  14805. torch.return_types.kthvalue(values=tensor([[4., 5., 6.]]), indices=tensor([[1, 1, 1]]))
  14806. """
  14807. def layer_norm(
  14808. input: Tensor,
  14809. normalized_shape: Sequence[_int | SymInt],
  14810. weight: Tensor | None = None,
  14811. bias: Tensor | None = None,
  14812. eps: _float = 1e-05,
  14813. cudnn_enable: _bool = True,
  14814. ) -> Tensor: ...
  14815. def lcm(
  14816. input: Tensor,
  14817. other: Tensor,
  14818. *,
  14819. out: Tensor | None = None,
  14820. ) -> Tensor:
  14821. r"""
  14822. lcm(input, other, *, out=None) -> Tensor
  14823. Computes the element-wise least common multiple (LCM) of :attr:`input` and :attr:`other`.
  14824. Both :attr:`input` and :attr:`other` must have integer types.
  14825. .. note::
  14826. This defines :math:`lcm(0, 0) = 0` and :math:`lcm(0, a) = 0`.
  14827. Args:
  14828. input (Tensor): the input tensor.
  14829. other (Tensor): the second input tensor
  14830. Keyword arguments:
  14831. out (Tensor, optional): the output tensor.
  14832. Example::
  14833. >>> a = torch.tensor([5, 10, 15])
  14834. >>> b = torch.tensor([3, 4, 5])
  14835. >>> torch.lcm(a, b)
  14836. tensor([15, 20, 15])
  14837. >>> c = torch.tensor([3])
  14838. >>> torch.lcm(a, c)
  14839. tensor([15, 30, 15])
  14840. """
  14841. def lcm_(input: Tensor, other: Tensor) -> Tensor: ...
  14842. def ldexp(
  14843. input: Tensor,
  14844. other: Tensor,
  14845. *,
  14846. out: Tensor | None = None,
  14847. ) -> Tensor:
  14848. r"""
  14849. ldexp(input, other, *, out=None) -> Tensor
  14850. Multiplies :attr:`input` by 2 ** :attr:`other`.
  14851. .. math::
  14852. \text{{out}}_i = \text{{input}}_i * 2^\text{{other}}_i
  14853. Typically this function is used to construct floating point numbers by multiplying
  14854. mantissas in :attr:`input` with integral powers of two created from the exponents
  14855. in :attr:`other`.
  14856. Args:
  14857. input (Tensor): the input tensor.
  14858. other (Tensor): a tensor of exponents, typically integers.
  14859. Keyword args:
  14860. out (Tensor, optional): the output tensor.
  14861. Example::
  14862. >>> torch.ldexp(torch.tensor([1.]), torch.tensor([1]))
  14863. tensor([2.])
  14864. >>> torch.ldexp(torch.tensor([1.0]), torch.tensor([1, 2, 3, 4]))
  14865. tensor([ 2., 4., 8., 16.])
  14866. """
  14867. def ldexp_(input: Tensor, other: Tensor) -> Tensor: ...
  14868. @overload
  14869. def le(
  14870. input: Tensor,
  14871. other: Tensor,
  14872. *,
  14873. out: Tensor | None = None,
  14874. ) -> Tensor:
  14875. r"""
  14876. le(input, other, *, out=None) -> Tensor
  14877. Computes :math:`\text{input} \leq \text{other}` element-wise.
  14878. The second argument can be a number or a tensor whose shape is
  14879. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  14880. Args:
  14881. input (Tensor): the tensor to compare
  14882. other (Tensor or Scalar): the tensor or value to compare
  14883. Keyword args:
  14884. out (Tensor, optional): the output tensor.
  14885. Returns:
  14886. A boolean tensor that is True where :attr:`input` is less than or equal to
  14887. :attr:`other` and False elsewhere
  14888. Example::
  14889. >>> torch.le(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  14890. tensor([[True, False], [True, True]])
  14891. """
  14892. @overload
  14893. def le(
  14894. input: Tensor,
  14895. other: Number | _complex,
  14896. *,
  14897. out: Tensor | None = None,
  14898. ) -> Tensor:
  14899. r"""
  14900. le(input, other, *, out=None) -> Tensor
  14901. Computes :math:`\text{input} \leq \text{other}` element-wise.
  14902. The second argument can be a number or a tensor whose shape is
  14903. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  14904. Args:
  14905. input (Tensor): the tensor to compare
  14906. other (Tensor or Scalar): the tensor or value to compare
  14907. Keyword args:
  14908. out (Tensor, optional): the output tensor.
  14909. Returns:
  14910. A boolean tensor that is True where :attr:`input` is less than or equal to
  14911. :attr:`other` and False elsewhere
  14912. Example::
  14913. >>> torch.le(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  14914. tensor([[True, False], [True, True]])
  14915. """
  14916. @overload
  14917. def lerp(
  14918. input: Tensor,
  14919. end: Tensor,
  14920. weight: Tensor,
  14921. *,
  14922. out: Tensor | None = None,
  14923. ) -> Tensor:
  14924. r"""
  14925. lerp(input, end, weight, *, out=None)
  14926. Does a linear interpolation of two tensors :attr:`start` (given by :attr:`input`) and :attr:`end` based
  14927. on a scalar or tensor :attr:`weight` and returns the resulting :attr:`out` tensor.
  14928. .. math::
  14929. \text{out}_i = \text{start}_i + \text{weight}_i \times (\text{end}_i - \text{start}_i)
  14930. The shapes of :attr:`start` and :attr:`end` must be
  14931. :ref:`broadcastable <broadcasting-semantics>`. If :attr:`weight` is a tensor, then
  14932. the shapes of :attr:`weight`, :attr:`start`, and :attr:`end` must be :ref:`broadcastable <broadcasting-semantics>`.
  14933. Args:
  14934. input (Tensor): the tensor with the starting points
  14935. end (Tensor): the tensor with the ending points
  14936. weight (float or tensor): the weight for the interpolation formula
  14937. Keyword args:
  14938. out (Tensor, optional): the output tensor.
  14939. Example::
  14940. >>> start = torch.arange(1., 5.)
  14941. >>> end = torch.empty(4).fill_(10)
  14942. >>> start
  14943. tensor([ 1., 2., 3., 4.])
  14944. >>> end
  14945. tensor([ 10., 10., 10., 10.])
  14946. >>> torch.lerp(start, end, 0.5)
  14947. tensor([ 5.5000, 6.0000, 6.5000, 7.0000])
  14948. >>> torch.lerp(start, end, torch.full_like(start, 0.5))
  14949. tensor([ 5.5000, 6.0000, 6.5000, 7.0000])
  14950. """
  14951. @overload
  14952. def lerp(
  14953. input: Tensor,
  14954. end: Tensor,
  14955. weight: Number | _complex,
  14956. *,
  14957. out: Tensor | None = None,
  14958. ) -> Tensor:
  14959. r"""
  14960. lerp(input, end, weight, *, out=None)
  14961. Does a linear interpolation of two tensors :attr:`start` (given by :attr:`input`) and :attr:`end` based
  14962. on a scalar or tensor :attr:`weight` and returns the resulting :attr:`out` tensor.
  14963. .. math::
  14964. \text{out}_i = \text{start}_i + \text{weight}_i \times (\text{end}_i - \text{start}_i)
  14965. The shapes of :attr:`start` and :attr:`end` must be
  14966. :ref:`broadcastable <broadcasting-semantics>`. If :attr:`weight` is a tensor, then
  14967. the shapes of :attr:`weight`, :attr:`start`, and :attr:`end` must be :ref:`broadcastable <broadcasting-semantics>`.
  14968. Args:
  14969. input (Tensor): the tensor with the starting points
  14970. end (Tensor): the tensor with the ending points
  14971. weight (float or tensor): the weight for the interpolation formula
  14972. Keyword args:
  14973. out (Tensor, optional): the output tensor.
  14974. Example::
  14975. >>> start = torch.arange(1., 5.)
  14976. >>> end = torch.empty(4).fill_(10)
  14977. >>> start
  14978. tensor([ 1., 2., 3., 4.])
  14979. >>> end
  14980. tensor([ 10., 10., 10., 10.])
  14981. >>> torch.lerp(start, end, 0.5)
  14982. tensor([ 5.5000, 6.0000, 6.5000, 7.0000])
  14983. >>> torch.lerp(start, end, torch.full_like(start, 0.5))
  14984. tensor([ 5.5000, 6.0000, 6.5000, 7.0000])
  14985. """
  14986. @overload
  14987. def less(
  14988. input: Tensor,
  14989. other: Tensor,
  14990. *,
  14991. out: Tensor | None = None,
  14992. ) -> Tensor:
  14993. r"""
  14994. less(input, other, *, out=None) -> Tensor
  14995. Alias for :func:`torch.lt`.
  14996. """
  14997. @overload
  14998. def less(
  14999. input: Tensor,
  15000. other: Number | _complex,
  15001. *,
  15002. out: Tensor | None = None,
  15003. ) -> Tensor:
  15004. r"""
  15005. less(input, other, *, out=None) -> Tensor
  15006. Alias for :func:`torch.lt`.
  15007. """
  15008. @overload
  15009. def less_equal(
  15010. input: Tensor,
  15011. other: Tensor,
  15012. *,
  15013. out: Tensor | None = None,
  15014. ) -> Tensor:
  15015. r"""
  15016. less_equal(input, other, *, out=None) -> Tensor
  15017. Alias for :func:`torch.le`.
  15018. """
  15019. @overload
  15020. def less_equal(
  15021. input: Tensor,
  15022. other: Number | _complex,
  15023. *,
  15024. out: Tensor | None = None,
  15025. ) -> Tensor:
  15026. r"""
  15027. less_equal(input, other, *, out=None) -> Tensor
  15028. Alias for :func:`torch.le`.
  15029. """
  15030. def lgamma(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  15031. r"""
  15032. lgamma(input, *, out=None) -> Tensor
  15033. Computes the natural logarithm of the absolute value of the gamma function on :attr:`input`.
  15034. .. math::
  15035. \text{out}_{i} = \ln |\Gamma(\text{input}_{i})|
  15036. Args:
  15037. input (Tensor): the input tensor.
  15038. Keyword args:
  15039. out (Tensor, optional): the output tensor.
  15040. Example::
  15041. >>> a = torch.arange(0.5, 2, 0.5)
  15042. >>> torch.lgamma(a)
  15043. tensor([ 0.5724, 0.0000, -0.1208])
  15044. """
  15045. @overload
  15046. def linspace(
  15047. start: Number,
  15048. end: Number,
  15049. steps: _int | None = None,
  15050. *,
  15051. out: Tensor | None = None,
  15052. dtype: _dtype | None = None,
  15053. device: DeviceLikeType | None = None,
  15054. requires_grad: _bool = False,
  15055. pin_memory: _bool = False,
  15056. ) -> Tensor:
  15057. r"""
  15058. linspace(start, end, steps, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15059. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15060. spaced from :attr:`start` to :attr:`end`, inclusive. That is, the value are:
  15061. .. math::
  15062. (\text{start},
  15063. \text{start} + \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15064. \ldots,
  15065. \text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15066. \text{end})
  15067. From PyTorch 1.11 linspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15068. Args:
  15069. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15070. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15071. steps (int): size of the constructed tensor
  15072. Keyword arguments:
  15073. out (Tensor, optional): the output tensor.
  15074. dtype (torch.dtype, optional): the data type to perform the computation in.
  15075. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15076. when both :attr:`start` and :attr:`end` are real,
  15077. and corresponding complex dtype when either is complex.
  15078. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15079. Default: ``torch.strided``.
  15080. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15081. Default: if ``None``, uses the current device for the default tensor type
  15082. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15083. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15084. requires_grad (bool, optional): If autograd should record operations on the
  15085. returned tensor. Default: ``False``.
  15086. Example::
  15087. >>> torch.linspace(3, 10, steps=5)
  15088. tensor([ 3.0000, 4.7500, 6.5000, 8.2500, 10.0000])
  15089. >>> torch.linspace(-10, 10, steps=5)
  15090. tensor([-10., -5., 0., 5., 10.])
  15091. >>> torch.linspace(start=-10, end=10, steps=5)
  15092. tensor([-10., -5., 0., 5., 10.])
  15093. >>> torch.linspace(start=-10, end=10, steps=1)
  15094. tensor([-10.])
  15095. """
  15096. @overload
  15097. def linspace(
  15098. start: Tensor,
  15099. end: Tensor,
  15100. steps: _int,
  15101. *,
  15102. out: Tensor | None = None,
  15103. dtype: _dtype | None = None,
  15104. layout: _layout | None = None,
  15105. device: DeviceLikeType | None = None,
  15106. pin_memory: _bool | None = False,
  15107. requires_grad: _bool | None = False,
  15108. ) -> Tensor:
  15109. r"""
  15110. linspace(start, end, steps, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15111. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15112. spaced from :attr:`start` to :attr:`end`, inclusive. That is, the value are:
  15113. .. math::
  15114. (\text{start},
  15115. \text{start} + \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15116. \ldots,
  15117. \text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15118. \text{end})
  15119. From PyTorch 1.11 linspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15120. Args:
  15121. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15122. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15123. steps (int): size of the constructed tensor
  15124. Keyword arguments:
  15125. out (Tensor, optional): the output tensor.
  15126. dtype (torch.dtype, optional): the data type to perform the computation in.
  15127. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15128. when both :attr:`start` and :attr:`end` are real,
  15129. and corresponding complex dtype when either is complex.
  15130. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15131. Default: ``torch.strided``.
  15132. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15133. Default: if ``None``, uses the current device for the default tensor type
  15134. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15135. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15136. requires_grad (bool, optional): If autograd should record operations on the
  15137. returned tensor. Default: ``False``.
  15138. Example::
  15139. >>> torch.linspace(3, 10, steps=5)
  15140. tensor([ 3.0000, 4.7500, 6.5000, 8.2500, 10.0000])
  15141. >>> torch.linspace(-10, 10, steps=5)
  15142. tensor([-10., -5., 0., 5., 10.])
  15143. >>> torch.linspace(start=-10, end=10, steps=5)
  15144. tensor([-10., -5., 0., 5., 10.])
  15145. >>> torch.linspace(start=-10, end=10, steps=1)
  15146. tensor([-10.])
  15147. """
  15148. @overload
  15149. def linspace(
  15150. start: Number | _complex,
  15151. end: Tensor,
  15152. steps: _int,
  15153. *,
  15154. out: Tensor | None = None,
  15155. dtype: _dtype | None = None,
  15156. layout: _layout | None = None,
  15157. device: DeviceLikeType | None = None,
  15158. pin_memory: _bool | None = False,
  15159. requires_grad: _bool | None = False,
  15160. ) -> Tensor:
  15161. r"""
  15162. linspace(start, end, steps, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15163. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15164. spaced from :attr:`start` to :attr:`end`, inclusive. That is, the value are:
  15165. .. math::
  15166. (\text{start},
  15167. \text{start} + \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15168. \ldots,
  15169. \text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15170. \text{end})
  15171. From PyTorch 1.11 linspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15172. Args:
  15173. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15174. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15175. steps (int): size of the constructed tensor
  15176. Keyword arguments:
  15177. out (Tensor, optional): the output tensor.
  15178. dtype (torch.dtype, optional): the data type to perform the computation in.
  15179. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15180. when both :attr:`start` and :attr:`end` are real,
  15181. and corresponding complex dtype when either is complex.
  15182. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15183. Default: ``torch.strided``.
  15184. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15185. Default: if ``None``, uses the current device for the default tensor type
  15186. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15187. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15188. requires_grad (bool, optional): If autograd should record operations on the
  15189. returned tensor. Default: ``False``.
  15190. Example::
  15191. >>> torch.linspace(3, 10, steps=5)
  15192. tensor([ 3.0000, 4.7500, 6.5000, 8.2500, 10.0000])
  15193. >>> torch.linspace(-10, 10, steps=5)
  15194. tensor([-10., -5., 0., 5., 10.])
  15195. >>> torch.linspace(start=-10, end=10, steps=5)
  15196. tensor([-10., -5., 0., 5., 10.])
  15197. >>> torch.linspace(start=-10, end=10, steps=1)
  15198. tensor([-10.])
  15199. """
  15200. @overload
  15201. def linspace(
  15202. start: Tensor,
  15203. end: Number | _complex,
  15204. steps: _int,
  15205. *,
  15206. out: Tensor | None = None,
  15207. dtype: _dtype | None = None,
  15208. layout: _layout | None = None,
  15209. device: DeviceLikeType | None = None,
  15210. pin_memory: _bool | None = False,
  15211. requires_grad: _bool | None = False,
  15212. ) -> Tensor:
  15213. r"""
  15214. linspace(start, end, steps, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15215. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15216. spaced from :attr:`start` to :attr:`end`, inclusive. That is, the value are:
  15217. .. math::
  15218. (\text{start},
  15219. \text{start} + \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15220. \ldots,
  15221. \text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15222. \text{end})
  15223. From PyTorch 1.11 linspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15224. Args:
  15225. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15226. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15227. steps (int): size of the constructed tensor
  15228. Keyword arguments:
  15229. out (Tensor, optional): the output tensor.
  15230. dtype (torch.dtype, optional): the data type to perform the computation in.
  15231. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15232. when both :attr:`start` and :attr:`end` are real,
  15233. and corresponding complex dtype when either is complex.
  15234. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15235. Default: ``torch.strided``.
  15236. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15237. Default: if ``None``, uses the current device for the default tensor type
  15238. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15239. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15240. requires_grad (bool, optional): If autograd should record operations on the
  15241. returned tensor. Default: ``False``.
  15242. Example::
  15243. >>> torch.linspace(3, 10, steps=5)
  15244. tensor([ 3.0000, 4.7500, 6.5000, 8.2500, 10.0000])
  15245. >>> torch.linspace(-10, 10, steps=5)
  15246. tensor([-10., -5., 0., 5., 10.])
  15247. >>> torch.linspace(start=-10, end=10, steps=5)
  15248. tensor([-10., -5., 0., 5., 10.])
  15249. >>> torch.linspace(start=-10, end=10, steps=1)
  15250. tensor([-10.])
  15251. """
  15252. @overload
  15253. def linspace(
  15254. start: Number | _complex,
  15255. end: Number | _complex,
  15256. steps: _int,
  15257. *,
  15258. out: Tensor | None = None,
  15259. dtype: _dtype | None = None,
  15260. layout: _layout | None = None,
  15261. device: DeviceLikeType | None = None,
  15262. pin_memory: _bool | None = False,
  15263. requires_grad: _bool | None = False,
  15264. ) -> Tensor:
  15265. r"""
  15266. linspace(start, end, steps, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15267. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15268. spaced from :attr:`start` to :attr:`end`, inclusive. That is, the value are:
  15269. .. math::
  15270. (\text{start},
  15271. \text{start} + \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15272. \ldots,
  15273. \text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15274. \text{end})
  15275. From PyTorch 1.11 linspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15276. Args:
  15277. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15278. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15279. steps (int): size of the constructed tensor
  15280. Keyword arguments:
  15281. out (Tensor, optional): the output tensor.
  15282. dtype (torch.dtype, optional): the data type to perform the computation in.
  15283. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15284. when both :attr:`start` and :attr:`end` are real,
  15285. and corresponding complex dtype when either is complex.
  15286. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15287. Default: ``torch.strided``.
  15288. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15289. Default: if ``None``, uses the current device for the default tensor type
  15290. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15291. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15292. requires_grad (bool, optional): If autograd should record operations on the
  15293. returned tensor. Default: ``False``.
  15294. Example::
  15295. >>> torch.linspace(3, 10, steps=5)
  15296. tensor([ 3.0000, 4.7500, 6.5000, 8.2500, 10.0000])
  15297. >>> torch.linspace(-10, 10, steps=5)
  15298. tensor([-10., -5., 0., 5., 10.])
  15299. >>> torch.linspace(start=-10, end=10, steps=5)
  15300. tensor([-10., -5., 0., 5., 10.])
  15301. >>> torch.linspace(start=-10, end=10, steps=1)
  15302. tensor([-10.])
  15303. """
  15304. def log(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  15305. r"""
  15306. log(input, *, out=None) -> Tensor
  15307. Returns a new tensor with the natural logarithm of the elements
  15308. of :attr:`input`.
  15309. .. math::
  15310. y_{i} = \log_{e} (x_{i})
  15311. Args:
  15312. input (Tensor): the input tensor.
  15313. Keyword args:
  15314. out (Tensor, optional): the output tensor.
  15315. Example::
  15316. >>> a = torch.rand(5) * 5
  15317. >>> a
  15318. tensor([4.7767, 4.3234, 1.2156, 0.2411, 4.5739])
  15319. >>> torch.log(a)
  15320. tensor([ 1.5637, 1.4640, 0.1952, -1.4226, 1.5204])
  15321. """
  15322. def log10(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  15323. r"""
  15324. log10(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  15325. Returns a new tensor with the logarithm to the base 10 of the elements
  15326. of :attr:`input`.
  15327. .. math::
  15328. y_{i} = \log_{10} (x_{i})
  15329. Args:
  15330. input (Tensor): the input tensor.
  15331. Keyword args:
  15332. out (Tensor, optional): the output tensor.
  15333. Example::
  15334. >>> a = torch.rand(5)
  15335. >>> a
  15336. tensor([ 0.5224, 0.9354, 0.7257, 0.1301, 0.2251])
  15337. >>> torch.log10(a)
  15338. tensor([-0.2820, -0.0290, -0.1392, -0.8857, -0.6476])
  15339. """
  15340. def log10_(input: Tensor) -> Tensor: ...
  15341. def log1p(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  15342. r"""
  15343. log1p(input, *, out=None) -> Tensor
  15344. Returns a new tensor with the natural logarithm of (1 + :attr:`input`).
  15345. .. math::
  15346. y_i = \log_{e} (x_i + 1)
  15347. .. note:: This function is more accurate than :func:`torch.log` for small
  15348. values of :attr:`input`
  15349. Args:
  15350. input (Tensor): the input tensor.
  15351. Keyword args:
  15352. out (Tensor, optional): the output tensor.
  15353. Example::
  15354. >>> a = torch.randn(5)
  15355. >>> a
  15356. tensor([-1.0090, -0.9923, 1.0249, -0.5372, 0.2492])
  15357. >>> torch.log1p(a)
  15358. tensor([ nan, -4.8653, 0.7055, -0.7705, 0.2225])
  15359. """
  15360. def log1p_(input: Tensor) -> Tensor: ...
  15361. def log2(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  15362. r"""
  15363. log2(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  15364. Returns a new tensor with the logarithm to the base 2 of the elements
  15365. of :attr:`input`.
  15366. .. math::
  15367. y_{i} = \log_{2} (x_{i})
  15368. Args:
  15369. input (Tensor): the input tensor.
  15370. Keyword args:
  15371. out (Tensor, optional): the output tensor.
  15372. Example::
  15373. >>> a = torch.rand(5)
  15374. >>> a
  15375. tensor([ 0.8419, 0.8003, 0.9971, 0.5287, 0.0490])
  15376. >>> torch.log2(a)
  15377. tensor([-0.2483, -0.3213, -0.0042, -0.9196, -4.3504])
  15378. """
  15379. def log2_(input: Tensor) -> Tensor: ...
  15380. def log_(input: Tensor) -> Tensor: ...
  15381. @overload
  15382. def log_softmax(
  15383. input: Tensor,
  15384. dim: _int,
  15385. dtype: _dtype | None = None,
  15386. *,
  15387. out: Tensor | None = None,
  15388. ) -> Tensor: ...
  15389. @overload
  15390. def log_softmax(
  15391. input: Tensor,
  15392. dim: str | EllipsisType | None,
  15393. *,
  15394. dtype: _dtype | None = None,
  15395. ) -> Tensor: ...
  15396. def logaddexp(
  15397. input: Tensor,
  15398. other: Tensor,
  15399. *,
  15400. out: Tensor | None = None,
  15401. ) -> Tensor:
  15402. r"""
  15403. logaddexp(input, other, *, out=None) -> Tensor
  15404. Logarithm of the sum of exponentiations of the inputs.
  15405. Calculates pointwise :math:`\log\left(e^x + e^y\right)`. This function is useful
  15406. in statistics where the calculated probabilities of events may be so small as to
  15407. exceed the range of normal floating point numbers. In such cases the logarithm
  15408. of the calculated probability is stored. This function allows adding
  15409. probabilities stored in such a fashion.
  15410. This op should be disambiguated with :func:`torch.logsumexp` which performs a
  15411. reduction on a single tensor.
  15412. Args:
  15413. input (Tensor): the input tensor.
  15414. other (Tensor): the second input tensor
  15415. Keyword arguments:
  15416. out (Tensor, optional): the output tensor.
  15417. Example::
  15418. >>> torch.logaddexp(torch.tensor([-1.0]), torch.tensor([-1.0, -2, -3]))
  15419. tensor([-0.3069, -0.6867, -0.8731])
  15420. >>> torch.logaddexp(torch.tensor([-100.0, -200, -300]), torch.tensor([-1.0, -2, -3]))
  15421. tensor([-1., -2., -3.])
  15422. >>> torch.logaddexp(torch.tensor([1.0, 2000, 30000]), torch.tensor([-1.0, -2, -3]))
  15423. tensor([1.1269e+00, 2.0000e+03, 3.0000e+04])
  15424. """
  15425. def logaddexp2(
  15426. input: Tensor,
  15427. other: Tensor,
  15428. *,
  15429. out: Tensor | None = None,
  15430. ) -> Tensor:
  15431. r"""
  15432. logaddexp2(input, other, *, out=None) -> Tensor
  15433. Logarithm of the sum of exponentiations of the inputs in base-2.
  15434. Calculates pointwise :math:`\log_2\left(2^x + 2^y\right)`. See
  15435. :func:`torch.logaddexp` for more details.
  15436. Args:
  15437. input (Tensor): the input tensor.
  15438. other (Tensor): the second input tensor
  15439. Keyword arguments:
  15440. out (Tensor, optional): the output tensor.
  15441. """
  15442. @overload
  15443. def logcumsumexp(
  15444. input: Tensor,
  15445. dim: _int,
  15446. *,
  15447. out: Tensor | None = None,
  15448. ) -> Tensor:
  15449. r"""
  15450. logcumsumexp(input, dim, *, out=None) -> Tensor
  15451. Returns the logarithm of the cumulative summation of the exponentiation of
  15452. elements of :attr:`input` in the dimension :attr:`dim`.
  15453. For summation index :math:`j` given by `dim` and other indices :math:`i`, the result is
  15454. .. math::
  15455. \text{logcumsumexp}(x)_{ij} = \log \sum\limits_{k=0}^{j} \exp(x_{ik})
  15456. Args:
  15457. input (Tensor): the input tensor.
  15458. dim (int): the dimension to do the operation over
  15459. Keyword args:
  15460. out (Tensor, optional): the output tensor.
  15461. Example::
  15462. >>> a = torch.randn(10)
  15463. >>> torch.logcumsumexp(a, dim=0)
  15464. tensor([-0.42296738, -0.04462666, 0.86278635, 0.94622083, 1.05277811,
  15465. 1.39202815, 1.83525007, 1.84492621, 2.06084887, 2.06844475]))
  15466. """
  15467. @overload
  15468. def logcumsumexp(
  15469. input: Tensor,
  15470. dim: str | EllipsisType | None,
  15471. *,
  15472. out: Tensor | None = None,
  15473. ) -> Tensor:
  15474. r"""
  15475. logcumsumexp(input, dim, *, out=None) -> Tensor
  15476. Returns the logarithm of the cumulative summation of the exponentiation of
  15477. elements of :attr:`input` in the dimension :attr:`dim`.
  15478. For summation index :math:`j` given by `dim` and other indices :math:`i`, the result is
  15479. .. math::
  15480. \text{logcumsumexp}(x)_{ij} = \log \sum\limits_{k=0}^{j} \exp(x_{ik})
  15481. Args:
  15482. input (Tensor): the input tensor.
  15483. dim (int): the dimension to do the operation over
  15484. Keyword args:
  15485. out (Tensor, optional): the output tensor.
  15486. Example::
  15487. >>> a = torch.randn(10)
  15488. >>> torch.logcumsumexp(a, dim=0)
  15489. tensor([-0.42296738, -0.04462666, 0.86278635, 0.94622083, 1.05277811,
  15490. 1.39202815, 1.83525007, 1.84492621, 2.06084887, 2.06844475]))
  15491. """
  15492. def logdet(input: Tensor) -> Tensor:
  15493. r"""
  15494. logdet(input) -> Tensor
  15495. Calculates log determinant of a square matrix or batches of square matrices.
  15496. It returns ``-inf`` if the input has a determinant of zero, and ``NaN`` if it has
  15497. a negative determinant.
  15498. .. note::
  15499. Backward through :meth:`logdet` internally uses SVD results when :attr:`input`
  15500. is not invertible. In this case, double backward through :meth:`logdet` will
  15501. be unstable in when :attr:`input` doesn't have distinct singular values. See
  15502. :func:`torch.linalg.svd` for details.
  15503. .. seealso::
  15504. :func:`torch.linalg.slogdet` computes the sign (resp. angle) and natural logarithm of the
  15505. absolute value of the determinant of real-valued (resp. complex) square matrices.
  15506. Arguments:
  15507. input (Tensor): the input tensor of size ``(*, n, n)`` where ``*`` is zero or more
  15508. batch dimensions.
  15509. Example::
  15510. >>> A = torch.randn(3, 3)
  15511. >>> torch.det(A)
  15512. tensor(0.2611)
  15513. >>> torch.logdet(A)
  15514. tensor(-1.3430)
  15515. >>> A
  15516. tensor([[[ 0.9254, -0.6213],
  15517. [-0.5787, 1.6843]],
  15518. [[ 0.3242, -0.9665],
  15519. [ 0.4539, -0.0887]],
  15520. [[ 1.1336, -0.4025],
  15521. [-0.7089, 0.9032]]])
  15522. >>> A.det()
  15523. tensor([1.1990, 0.4099, 0.7386])
  15524. >>> A.det().log()
  15525. tensor([ 0.1815, -0.8917, -0.3031])
  15526. """
  15527. def logical_and(
  15528. input: Tensor,
  15529. other: Tensor,
  15530. *,
  15531. out: Tensor | None = None,
  15532. ) -> Tensor:
  15533. r"""
  15534. logical_and(input, other, *, out=None) -> Tensor
  15535. Computes the element-wise logical AND of the given input tensors. Zeros are treated as ``False`` and nonzeros are
  15536. treated as ``True``.
  15537. Args:
  15538. input (Tensor): the input tensor.
  15539. other (Tensor): the tensor to compute AND with
  15540. Keyword args:
  15541. out (Tensor, optional): the output tensor.
  15542. Example::
  15543. >>> torch.logical_and(torch.tensor([True, False, True]), torch.tensor([True, False, False]))
  15544. tensor([ True, False, False])
  15545. >>> a = torch.tensor([0, 1, 10, 0], dtype=torch.int8)
  15546. >>> b = torch.tensor([4, 0, 1, 0], dtype=torch.int8)
  15547. >>> torch.logical_and(a, b)
  15548. tensor([False, False, True, False])
  15549. >>> torch.logical_and(a.double(), b.double())
  15550. tensor([False, False, True, False])
  15551. >>> torch.logical_and(a.double(), b)
  15552. tensor([False, False, True, False])
  15553. >>> torch.logical_and(a, b, out=torch.empty(4, dtype=torch.bool))
  15554. tensor([False, False, True, False])
  15555. """
  15556. def logical_not(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  15557. r"""
  15558. logical_not(input, *, out=None) -> Tensor
  15559. Computes the element-wise logical NOT of the given input tensor. If not specified, the output tensor will have the bool
  15560. dtype. If the input tensor is not a bool tensor, zeros are treated as ``False`` and non-zeros are treated as ``True``.
  15561. Args:
  15562. input (Tensor): the input tensor.
  15563. Keyword args:
  15564. out (Tensor, optional): the output tensor.
  15565. Example::
  15566. >>> torch.logical_not(torch.tensor([True, False]))
  15567. tensor([False, True])
  15568. >>> torch.logical_not(torch.tensor([0, 1, -10], dtype=torch.int8))
  15569. tensor([ True, False, False])
  15570. >>> torch.logical_not(torch.tensor([0., 1.5, -10.], dtype=torch.double))
  15571. tensor([ True, False, False])
  15572. >>> torch.logical_not(torch.tensor([0., 1., -10.], dtype=torch.double), out=torch.empty(3, dtype=torch.int16))
  15573. tensor([1, 0, 0], dtype=torch.int16)
  15574. """
  15575. def logical_or(
  15576. input: Tensor,
  15577. other: Tensor,
  15578. *,
  15579. out: Tensor | None = None,
  15580. ) -> Tensor:
  15581. r"""
  15582. logical_or(input, other, *, out=None) -> Tensor
  15583. Computes the element-wise logical OR of the given input tensors. Zeros are treated as ``False`` and nonzeros are
  15584. treated as ``True``.
  15585. Args:
  15586. input (Tensor): the input tensor.
  15587. other (Tensor): the tensor to compute OR with
  15588. Keyword args:
  15589. out (Tensor, optional): the output tensor.
  15590. Example::
  15591. >>> torch.logical_or(torch.tensor([True, False, True]), torch.tensor([True, False, False]))
  15592. tensor([ True, False, True])
  15593. >>> a = torch.tensor([0, 1, 10, 0], dtype=torch.int8)
  15594. >>> b = torch.tensor([4, 0, 1, 0], dtype=torch.int8)
  15595. >>> torch.logical_or(a, b)
  15596. tensor([ True, True, True, False])
  15597. >>> torch.logical_or(a.double(), b.double())
  15598. tensor([ True, True, True, False])
  15599. >>> torch.logical_or(a.double(), b)
  15600. tensor([ True, True, True, False])
  15601. >>> torch.logical_or(a, b, out=torch.empty(4, dtype=torch.bool))
  15602. tensor([ True, True, True, False])
  15603. """
  15604. def logical_xor(
  15605. input: Tensor,
  15606. other: Tensor,
  15607. *,
  15608. out: Tensor | None = None,
  15609. ) -> Tensor:
  15610. r"""
  15611. logical_xor(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
  15612. Computes the element-wise logical XOR of the given input tensors. Zeros are treated as ``False`` and nonzeros are
  15613. treated as ``True``.
  15614. Args:
  15615. input (Tensor): the input tensor.
  15616. other (Tensor): the tensor to compute XOR with
  15617. Keyword args:
  15618. out (Tensor, optional): the output tensor.
  15619. Example::
  15620. >>> torch.logical_xor(torch.tensor([True, False, True]), torch.tensor([True, False, False]))
  15621. tensor([False, False, True])
  15622. >>> a = torch.tensor([0, 1, 10, 0], dtype=torch.int8)
  15623. >>> b = torch.tensor([4, 0, 1, 0], dtype=torch.int8)
  15624. >>> torch.logical_xor(a, b)
  15625. tensor([ True, True, False, False])
  15626. >>> torch.logical_xor(a.double(), b.double())
  15627. tensor([ True, True, False, False])
  15628. >>> torch.logical_xor(a.double(), b)
  15629. tensor([ True, True, False, False])
  15630. >>> torch.logical_xor(a, b, out=torch.empty(4, dtype=torch.bool))
  15631. tensor([ True, True, False, False])
  15632. """
  15633. def logit(
  15634. input: Tensor,
  15635. eps: _float | None = None,
  15636. *,
  15637. out: Tensor | None = None,
  15638. ) -> Tensor:
  15639. r"""
  15640. logit(input, eps=None, *, out=None) -> Tensor
  15641. Alias for :func:`torch.special.logit`.
  15642. """
  15643. def logit_(input: Tensor, eps: _float | None = None) -> Tensor: ...
  15644. @overload
  15645. def logspace(
  15646. start: Number,
  15647. end: Number,
  15648. steps: _int | None = None,
  15649. base: _float = 10.0,
  15650. *,
  15651. out: Tensor | None = None,
  15652. dtype: _dtype | None = None,
  15653. device: DeviceLikeType | None = None,
  15654. requires_grad: _bool = False,
  15655. pin_memory: _bool = False,
  15656. ) -> Tensor:
  15657. r"""
  15658. logspace(start, end, steps, base=10.0, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15659. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15660. spaced from :math:`{{\text{{base}}}}^{{\text{{start}}}}` to
  15661. :math:`{{\text{{base}}}}^{{\text{{end}}}}`, inclusive, on a logarithmic scale
  15662. with base :attr:`base`. That is, the values are:
  15663. .. math::
  15664. (\text{base}^{\text{start}},
  15665. \text{base}^{(\text{start} + \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15666. \ldots,
  15667. \text{base}^{(\text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15668. \text{base}^{\text{end}})
  15669. From PyTorch 1.11 logspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15670. Args:
  15671. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15672. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15673. steps (int): size of the constructed tensor
  15674. base (float, optional): base of the logarithm function. Default: ``10.0``.
  15675. Keyword arguments:
  15676. out (Tensor, optional): the output tensor.
  15677. dtype (torch.dtype, optional): the data type to perform the computation in.
  15678. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15679. when both :attr:`start` and :attr:`end` are real,
  15680. and corresponding complex dtype when either is complex.
  15681. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15682. Default: ``torch.strided``.
  15683. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15684. Default: if ``None``, uses the current device for the default tensor type
  15685. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15686. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15687. requires_grad (bool, optional): If autograd should record operations on the
  15688. returned tensor. Default: ``False``.
  15689. Example::
  15690. >>> torch.logspace(start=-10, end=10, steps=5)
  15691. tensor([ 1.0000e-10, 1.0000e-05, 1.0000e+00, 1.0000e+05, 1.0000e+10])
  15692. >>> torch.logspace(start=0.1, end=1.0, steps=5)
  15693. tensor([ 1.2589, 2.1135, 3.5481, 5.9566, 10.0000])
  15694. >>> torch.logspace(start=0.1, end=1.0, steps=1)
  15695. tensor([1.2589])
  15696. >>> torch.logspace(start=2, end=2, steps=1, base=2)
  15697. tensor([4.0])
  15698. """
  15699. @overload
  15700. def logspace(
  15701. start: Tensor,
  15702. end: Tensor,
  15703. steps: _int,
  15704. base: _float = 10.0,
  15705. *,
  15706. out: Tensor | None = None,
  15707. dtype: _dtype | None = None,
  15708. layout: _layout | None = None,
  15709. device: DeviceLikeType | None = None,
  15710. pin_memory: _bool | None = False,
  15711. requires_grad: _bool | None = False,
  15712. ) -> Tensor:
  15713. r"""
  15714. logspace(start, end, steps, base=10.0, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15715. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15716. spaced from :math:`{{\text{{base}}}}^{{\text{{start}}}}` to
  15717. :math:`{{\text{{base}}}}^{{\text{{end}}}}`, inclusive, on a logarithmic scale
  15718. with base :attr:`base`. That is, the values are:
  15719. .. math::
  15720. (\text{base}^{\text{start}},
  15721. \text{base}^{(\text{start} + \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15722. \ldots,
  15723. \text{base}^{(\text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15724. \text{base}^{\text{end}})
  15725. From PyTorch 1.11 logspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15726. Args:
  15727. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15728. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15729. steps (int): size of the constructed tensor
  15730. base (float, optional): base of the logarithm function. Default: ``10.0``.
  15731. Keyword arguments:
  15732. out (Tensor, optional): the output tensor.
  15733. dtype (torch.dtype, optional): the data type to perform the computation in.
  15734. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15735. when both :attr:`start` and :attr:`end` are real,
  15736. and corresponding complex dtype when either is complex.
  15737. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15738. Default: ``torch.strided``.
  15739. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15740. Default: if ``None``, uses the current device for the default tensor type
  15741. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15742. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15743. requires_grad (bool, optional): If autograd should record operations on the
  15744. returned tensor. Default: ``False``.
  15745. Example::
  15746. >>> torch.logspace(start=-10, end=10, steps=5)
  15747. tensor([ 1.0000e-10, 1.0000e-05, 1.0000e+00, 1.0000e+05, 1.0000e+10])
  15748. >>> torch.logspace(start=0.1, end=1.0, steps=5)
  15749. tensor([ 1.2589, 2.1135, 3.5481, 5.9566, 10.0000])
  15750. >>> torch.logspace(start=0.1, end=1.0, steps=1)
  15751. tensor([1.2589])
  15752. >>> torch.logspace(start=2, end=2, steps=1, base=2)
  15753. tensor([4.0])
  15754. """
  15755. @overload
  15756. def logspace(
  15757. start: Number | _complex,
  15758. end: Tensor,
  15759. steps: _int,
  15760. base: _float = 10.0,
  15761. *,
  15762. out: Tensor | None = None,
  15763. dtype: _dtype | None = None,
  15764. layout: _layout | None = None,
  15765. device: DeviceLikeType | None = None,
  15766. pin_memory: _bool | None = False,
  15767. requires_grad: _bool | None = False,
  15768. ) -> Tensor:
  15769. r"""
  15770. logspace(start, end, steps, base=10.0, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15771. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15772. spaced from :math:`{{\text{{base}}}}^{{\text{{start}}}}` to
  15773. :math:`{{\text{{base}}}}^{{\text{{end}}}}`, inclusive, on a logarithmic scale
  15774. with base :attr:`base`. That is, the values are:
  15775. .. math::
  15776. (\text{base}^{\text{start}},
  15777. \text{base}^{(\text{start} + \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15778. \ldots,
  15779. \text{base}^{(\text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15780. \text{base}^{\text{end}})
  15781. From PyTorch 1.11 logspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15782. Args:
  15783. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15784. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15785. steps (int): size of the constructed tensor
  15786. base (float, optional): base of the logarithm function. Default: ``10.0``.
  15787. Keyword arguments:
  15788. out (Tensor, optional): the output tensor.
  15789. dtype (torch.dtype, optional): the data type to perform the computation in.
  15790. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15791. when both :attr:`start` and :attr:`end` are real,
  15792. and corresponding complex dtype when either is complex.
  15793. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15794. Default: ``torch.strided``.
  15795. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15796. Default: if ``None``, uses the current device for the default tensor type
  15797. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15798. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15799. requires_grad (bool, optional): If autograd should record operations on the
  15800. returned tensor. Default: ``False``.
  15801. Example::
  15802. >>> torch.logspace(start=-10, end=10, steps=5)
  15803. tensor([ 1.0000e-10, 1.0000e-05, 1.0000e+00, 1.0000e+05, 1.0000e+10])
  15804. >>> torch.logspace(start=0.1, end=1.0, steps=5)
  15805. tensor([ 1.2589, 2.1135, 3.5481, 5.9566, 10.0000])
  15806. >>> torch.logspace(start=0.1, end=1.0, steps=1)
  15807. tensor([1.2589])
  15808. >>> torch.logspace(start=2, end=2, steps=1, base=2)
  15809. tensor([4.0])
  15810. """
  15811. @overload
  15812. def logspace(
  15813. start: Tensor,
  15814. end: Number | _complex,
  15815. steps: _int,
  15816. base: _float = 10.0,
  15817. *,
  15818. out: Tensor | None = None,
  15819. dtype: _dtype | None = None,
  15820. layout: _layout | None = None,
  15821. device: DeviceLikeType | None = None,
  15822. pin_memory: _bool | None = False,
  15823. requires_grad: _bool | None = False,
  15824. ) -> Tensor:
  15825. r"""
  15826. logspace(start, end, steps, base=10.0, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15827. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15828. spaced from :math:`{{\text{{base}}}}^{{\text{{start}}}}` to
  15829. :math:`{{\text{{base}}}}^{{\text{{end}}}}`, inclusive, on a logarithmic scale
  15830. with base :attr:`base`. That is, the values are:
  15831. .. math::
  15832. (\text{base}^{\text{start}},
  15833. \text{base}^{(\text{start} + \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15834. \ldots,
  15835. \text{base}^{(\text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15836. \text{base}^{\text{end}})
  15837. From PyTorch 1.11 logspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15838. Args:
  15839. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15840. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15841. steps (int): size of the constructed tensor
  15842. base (float, optional): base of the logarithm function. Default: ``10.0``.
  15843. Keyword arguments:
  15844. out (Tensor, optional): the output tensor.
  15845. dtype (torch.dtype, optional): the data type to perform the computation in.
  15846. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15847. when both :attr:`start` and :attr:`end` are real,
  15848. and corresponding complex dtype when either is complex.
  15849. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15850. Default: ``torch.strided``.
  15851. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15852. Default: if ``None``, uses the current device for the default tensor type
  15853. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15854. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15855. requires_grad (bool, optional): If autograd should record operations on the
  15856. returned tensor. Default: ``False``.
  15857. Example::
  15858. >>> torch.logspace(start=-10, end=10, steps=5)
  15859. tensor([ 1.0000e-10, 1.0000e-05, 1.0000e+00, 1.0000e+05, 1.0000e+10])
  15860. >>> torch.logspace(start=0.1, end=1.0, steps=5)
  15861. tensor([ 1.2589, 2.1135, 3.5481, 5.9566, 10.0000])
  15862. >>> torch.logspace(start=0.1, end=1.0, steps=1)
  15863. tensor([1.2589])
  15864. >>> torch.logspace(start=2, end=2, steps=1, base=2)
  15865. tensor([4.0])
  15866. """
  15867. @overload
  15868. def logspace(
  15869. start: Number | _complex,
  15870. end: Number | _complex,
  15871. steps: _int,
  15872. base: _float = 10.0,
  15873. *,
  15874. out: Tensor | None = None,
  15875. dtype: _dtype | None = None,
  15876. layout: _layout | None = None,
  15877. device: DeviceLikeType | None = None,
  15878. pin_memory: _bool | None = False,
  15879. requires_grad: _bool | None = False,
  15880. ) -> Tensor:
  15881. r"""
  15882. logspace(start, end, steps, base=10.0, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15883. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15884. spaced from :math:`{{\text{{base}}}}^{{\text{{start}}}}` to
  15885. :math:`{{\text{{base}}}}^{{\text{{end}}}}`, inclusive, on a logarithmic scale
  15886. with base :attr:`base`. That is, the values are:
  15887. .. math::
  15888. (\text{base}^{\text{start}},
  15889. \text{base}^{(\text{start} + \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15890. \ldots,
  15891. \text{base}^{(\text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15892. \text{base}^{\text{end}})
  15893. From PyTorch 1.11 logspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15894. Args:
  15895. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15896. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15897. steps (int): size of the constructed tensor
  15898. base (float, optional): base of the logarithm function. Default: ``10.0``.
  15899. Keyword arguments:
  15900. out (Tensor, optional): the output tensor.
  15901. dtype (torch.dtype, optional): the data type to perform the computation in.
  15902. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15903. when both :attr:`start` and :attr:`end` are real,
  15904. and corresponding complex dtype when either is complex.
  15905. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15906. Default: ``torch.strided``.
  15907. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15908. Default: if ``None``, uses the current device for the default tensor type
  15909. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15910. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15911. requires_grad (bool, optional): If autograd should record operations on the
  15912. returned tensor. Default: ``False``.
  15913. Example::
  15914. >>> torch.logspace(start=-10, end=10, steps=5)
  15915. tensor([ 1.0000e-10, 1.0000e-05, 1.0000e+00, 1.0000e+05, 1.0000e+10])
  15916. >>> torch.logspace(start=0.1, end=1.0, steps=5)
  15917. tensor([ 1.2589, 2.1135, 3.5481, 5.9566, 10.0000])
  15918. >>> torch.logspace(start=0.1, end=1.0, steps=1)
  15919. tensor([1.2589])
  15920. >>> torch.logspace(start=2, end=2, steps=1, base=2)
  15921. tensor([4.0])
  15922. """
  15923. @overload
  15924. def logsumexp(
  15925. input: Tensor,
  15926. dim: _int | _size,
  15927. keepdim: _bool = False,
  15928. *,
  15929. out: Tensor | None = None,
  15930. ) -> Tensor:
  15931. r"""
  15932. logsumexp(input, dim, keepdim=False, *, out=None)
  15933. Returns the log of summed exponentials of each row of the :attr:`input`
  15934. tensor in the given dimension :attr:`dim`. The computation is numerically
  15935. stabilized.
  15936. For summation index :math:`j` given by `dim` and other indices :math:`i`, the result is
  15937. .. math::
  15938. \text{logsumexp}(x)_{i} = \log \sum_j \exp(x_{ij})
  15939. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  15940. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  15941. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  15942. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  15943. Args:
  15944. input (Tensor): the input tensor.
  15945. dim (int or tuple of ints): the dimension or dimensions to reduce.
  15946. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  15947. Keyword args:
  15948. out (Tensor, optional): the output tensor.
  15949. Example::
  15950. >>> a = torch.randn(3, 3)
  15951. >>> torch.logsumexp(a, 1)
  15952. tensor([1.4907, 1.0593, 1.5696])
  15953. >>> torch.dist(torch.logsumexp(a, 1), torch.log(torch.sum(torch.exp(a), 1)))
  15954. tensor(1.6859e-07)
  15955. """
  15956. @overload
  15957. def logsumexp(
  15958. input: Tensor,
  15959. dim: Sequence[str | EllipsisType | None],
  15960. keepdim: _bool = False,
  15961. *,
  15962. out: Tensor | None = None,
  15963. ) -> Tensor:
  15964. r"""
  15965. logsumexp(input, dim, keepdim=False, *, out=None)
  15966. Returns the log of summed exponentials of each row of the :attr:`input`
  15967. tensor in the given dimension :attr:`dim`. The computation is numerically
  15968. stabilized.
  15969. For summation index :math:`j` given by `dim` and other indices :math:`i`, the result is
  15970. .. math::
  15971. \text{logsumexp}(x)_{i} = \log \sum_j \exp(x_{ij})
  15972. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  15973. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  15974. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  15975. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  15976. Args:
  15977. input (Tensor): the input tensor.
  15978. dim (int or tuple of ints): the dimension or dimensions to reduce.
  15979. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  15980. Keyword args:
  15981. out (Tensor, optional): the output tensor.
  15982. Example::
  15983. >>> a = torch.randn(3, 3)
  15984. >>> torch.logsumexp(a, 1)
  15985. tensor([1.4907, 1.0593, 1.5696])
  15986. >>> torch.dist(torch.logsumexp(a, 1), torch.log(torch.sum(torch.exp(a), 1)))
  15987. tensor(1.6859e-07)
  15988. """
  15989. @overload
  15990. def lstm(
  15991. data: Tensor,
  15992. batch_sizes: Tensor,
  15993. hx: tuple[Tensor, ...] | list[Tensor] | None,
  15994. params: tuple[Tensor, ...] | list[Tensor] | None,
  15995. has_biases: _bool,
  15996. num_layers: _int,
  15997. dropout: _float,
  15998. train: _bool,
  15999. bidirectional: _bool,
  16000. ) -> tuple[Tensor, Tensor, Tensor]: ...
  16001. @overload
  16002. def lstm(
  16003. input: Tensor,
  16004. hx: tuple[Tensor, ...] | list[Tensor] | None,
  16005. params: tuple[Tensor, ...] | list[Tensor] | None,
  16006. has_biases: _bool,
  16007. num_layers: _int,
  16008. dropout: _float,
  16009. train: _bool,
  16010. bidirectional: _bool,
  16011. batch_first: _bool,
  16012. ) -> tuple[Tensor, Tensor, Tensor]: ...
  16013. def lstm_cell(
  16014. input: Tensor,
  16015. hx: tuple[Tensor, ...] | list[Tensor] | None,
  16016. w_ih: Tensor,
  16017. w_hh: Tensor,
  16018. b_ih: Tensor | None = None,
  16019. b_hh: Tensor | None = None,
  16020. ) -> tuple[Tensor, Tensor]: ...
  16021. @overload
  16022. def lt(
  16023. input: Tensor,
  16024. other: Tensor,
  16025. *,
  16026. out: Tensor | None = None,
  16027. ) -> Tensor:
  16028. r"""
  16029. lt(input, other, *, out=None) -> Tensor
  16030. Computes :math:`\text{input} < \text{other}` element-wise.
  16031. The second argument can be a number or a tensor whose shape is
  16032. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  16033. Args:
  16034. input (Tensor): the tensor to compare
  16035. other (Tensor or float): the tensor or value to compare
  16036. Keyword args:
  16037. out (Tensor, optional): the output tensor.
  16038. Returns:
  16039. A boolean tensor that is True where :attr:`input` is less than :attr:`other` and False elsewhere
  16040. Example::
  16041. >>> torch.lt(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  16042. tensor([[False, False], [True, False]])
  16043. """
  16044. @overload
  16045. def lt(
  16046. input: Tensor,
  16047. other: Number | _complex,
  16048. *,
  16049. out: Tensor | None = None,
  16050. ) -> Tensor:
  16051. r"""
  16052. lt(input, other, *, out=None) -> Tensor
  16053. Computes :math:`\text{input} < \text{other}` element-wise.
  16054. The second argument can be a number or a tensor whose shape is
  16055. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  16056. Args:
  16057. input (Tensor): the tensor to compare
  16058. other (Tensor or float): the tensor or value to compare
  16059. Keyword args:
  16060. out (Tensor, optional): the output tensor.
  16061. Returns:
  16062. A boolean tensor that is True where :attr:`input` is less than :attr:`other` and False elsewhere
  16063. Example::
  16064. >>> torch.lt(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  16065. tensor([[False, False], [True, False]])
  16066. """
  16067. def lu_solve(
  16068. input: Tensor,
  16069. LU_data: Tensor,
  16070. LU_pivots: Tensor,
  16071. *,
  16072. out: Tensor | None = None,
  16073. ) -> Tensor:
  16074. r"""
  16075. lu_solve(b, LU_data, LU_pivots, *, out=None) -> Tensor
  16076. Returns the LU solve of the linear system :math:`Ax = b` using the partially pivoted
  16077. LU factorization of A from :func:`~linalg.lu_factor`.
  16078. This function supports ``float``, ``double``, ``cfloat`` and ``cdouble`` dtypes for :attr:`input`.
  16079. .. warning::
  16080. :func:`torch.lu_solve` is deprecated in favor of :func:`torch.linalg.lu_solve`.
  16081. :func:`torch.lu_solve` will be removed in a future PyTorch release.
  16082. ``X = torch.lu_solve(B, LU, pivots)`` should be replaced with
  16083. .. code:: python
  16084. X = linalg.lu_solve(LU, pivots, B)
  16085. Arguments:
  16086. b (Tensor): the RHS tensor of size :math:`(*, m, k)`, where :math:`*`
  16087. is zero or more batch dimensions.
  16088. LU_data (Tensor): the pivoted LU factorization of A from :meth:`~linalg.lu_factor` of size :math:`(*, m, m)`,
  16089. where :math:`*` is zero or more batch dimensions.
  16090. LU_pivots (IntTensor): the pivots of the LU factorization from :meth:`~linalg.lu_factor` of size :math:`(*, m)`,
  16091. where :math:`*` is zero or more batch dimensions.
  16092. The batch dimensions of :attr:`LU_pivots` must be equal to the batch dimensions of
  16093. :attr:`LU_data`.
  16094. Keyword args:
  16095. out (Tensor, optional): the output tensor.
  16096. Example::
  16097. >>> A = torch.randn(2, 3, 3)
  16098. >>> b = torch.randn(2, 3, 1)
  16099. >>> LU, pivots = torch.linalg.lu_factor(A)
  16100. >>> x = torch.lu_solve(b, LU, pivots)
  16101. >>> torch.dist(A @ x, b)
  16102. tensor(1.00000e-07 *
  16103. 2.8312)
  16104. """
  16105. def lu_unpack(
  16106. LU_data: Tensor,
  16107. LU_pivots: Tensor,
  16108. unpack_data: _bool = True,
  16109. unpack_pivots: _bool = True,
  16110. *,
  16111. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  16112. ) -> torch.return_types.lu_unpack:
  16113. r"""
  16114. lu_unpack(LU_data, LU_pivots, unpack_data=True, unpack_pivots=True, *, out=None) -> (Tensor, Tensor, Tensor)
  16115. Unpacks the LU decomposition returned by :func:`~linalg.lu_factor` into the `P, L, U` matrices.
  16116. .. seealso::
  16117. :func:`~linalg.lu` returns the matrices from the LU decomposition. Its gradient formula is more efficient
  16118. than that of doing :func:`~linalg.lu_factor` followed by :func:`~linalg.lu_unpack`.
  16119. Args:
  16120. LU_data (Tensor): the packed LU factorization data
  16121. LU_pivots (Tensor): the packed LU factorization pivots
  16122. unpack_data (bool): flag indicating if the data should be unpacked.
  16123. If ``False``, then the returned ``L`` and ``U`` are empty tensors.
  16124. Default: ``True``
  16125. unpack_pivots (bool): flag indicating if the pivots should be unpacked into a permutation matrix ``P``.
  16126. If ``False``, then the returned ``P`` is an empty tensor.
  16127. Default: ``True``
  16128. Keyword args:
  16129. out (tuple, optional): output tuple of three tensors. Ignored if `None`.
  16130. Returns:
  16131. A namedtuple ``(P, L, U)``
  16132. Examples::
  16133. >>> A = torch.randn(2, 3, 3)
  16134. >>> LU, pivots = torch.linalg.lu_factor(A)
  16135. >>> P, L, U = torch.lu_unpack(LU, pivots)
  16136. >>> # We can recover A from the factorization
  16137. >>> A_ = P @ L @ U
  16138. >>> torch.allclose(A, A_)
  16139. True
  16140. >>> # LU factorization of a rectangular matrix:
  16141. >>> A = torch.randn(2, 3, 2)
  16142. >>> LU, pivots = torch.linalg.lu_factor(A)
  16143. >>> P, L, U = torch.lu_unpack(LU, pivots)
  16144. >>> # P, L, U are the same as returned by linalg.lu
  16145. >>> P_, L_, U_ = torch.linalg.lu(A)
  16146. >>> torch.allclose(P, P_) and torch.allclose(L, L_) and torch.allclose(U, U_)
  16147. True
  16148. """
  16149. def margin_ranking_loss(
  16150. input1: Tensor,
  16151. input2: Tensor,
  16152. target: Tensor,
  16153. margin: _float = 0.0,
  16154. reduction: _int = 1,
  16155. ) -> Tensor: ...
  16156. @overload
  16157. def masked_fill(input: Tensor, mask: Tensor, value: Tensor) -> Tensor: ...
  16158. @overload
  16159. def masked_fill(
  16160. input: Tensor,
  16161. mask: Tensor,
  16162. value: Number | _complex,
  16163. ) -> Tensor: ...
  16164. def masked_scatter(input: Tensor, mask: Tensor, source: Tensor) -> Tensor: ...
  16165. def masked_select(
  16166. input: Tensor,
  16167. mask: Tensor,
  16168. *,
  16169. out: Tensor | None = None,
  16170. ) -> Tensor:
  16171. r"""
  16172. masked_select(input, mask, *, out=None) -> Tensor
  16173. Returns a new 1-D tensor which indexes the :attr:`input` tensor according to
  16174. the boolean mask :attr:`mask` which is a `BoolTensor`.
  16175. The shapes of the :attr:`mask` tensor and the :attr:`input` tensor don't need
  16176. to match, but they must be :ref:`broadcastable <broadcasting-semantics>`.
  16177. .. note:: The returned tensor does **not** use the same storage
  16178. as the original tensor
  16179. Args:
  16180. input (Tensor): the input tensor.
  16181. mask (BoolTensor): the tensor containing the binary mask to index with
  16182. Keyword args:
  16183. out (Tensor, optional): the output tensor.
  16184. Example::
  16185. >>> x = torch.randn(3, 4)
  16186. >>> x
  16187. tensor([[ 0.3552, -2.3825, -0.8297, 0.3477],
  16188. [-1.2035, 1.2252, 0.5002, 0.6248],
  16189. [ 0.1307, -2.0608, 0.1244, 2.0139]])
  16190. >>> mask = x.ge(0.5)
  16191. >>> mask
  16192. tensor([[False, False, False, False],
  16193. [False, True, True, True],
  16194. [False, False, False, True]])
  16195. >>> torch.masked_select(x, mask)
  16196. tensor([ 1.2252, 0.5002, 0.6248, 2.0139])
  16197. """
  16198. def matmul(
  16199. input: Tensor,
  16200. other: Tensor,
  16201. *,
  16202. out: Tensor | None = None,
  16203. ) -> Tensor:
  16204. r"""
  16205. matmul(input, other, *, out=None) -> Tensor
  16206. Matrix product of two tensors.
  16207. The behavior depends on the dimensionality of the tensors as follows:
  16208. - If both tensors are 1-dimensional, the dot product (scalar) is returned.
  16209. - If both arguments are 2-dimensional, the matrix-matrix product is returned.
  16210. - If the first argument is 1-dimensional and the second argument is 2-dimensional,
  16211. a 1 is prepended to its dimension for the purpose of the matrix multiply.
  16212. After the matrix multiply, the prepended dimension is removed.
  16213. - If the first argument is 2-dimensional and the second argument is 1-dimensional,
  16214. the matrix-vector product is returned.
  16215. - If both arguments are at least 1-dimensional and at least one argument is
  16216. N-dimensional (where N > 2), then a batched matrix multiply is returned. If the first
  16217. argument is 1-dimensional, a 1 is prepended to its dimension for the purpose of the
  16218. batched matrix multiply and removed after. If the second argument is 1-dimensional, a
  16219. 1 is appended to its dimension for the purpose of the batched matrix multiply and removed after.
  16220. The first N-2 dimensions of each argument, the batch dimensions, are
  16221. :ref:`broadcast <broadcasting-semantics>` (and thus must be broadcastable).
  16222. The last 2, the matrix dimensions, are handled as in the matrix-matrix product.
  16223. For example, if :attr:`input` is a
  16224. :math:`(j \times 1 \times n \times m)` tensor and :attr:`other` is a :math:`(k \times m \times p)`
  16225. tensor, the batch dimensions are :math:`(j \times 1)` and :math:`(k)`,
  16226. and the matrix dimensions are :math:`(n \times m)` and :math:`(m \times p)`.
  16227. :attr:`out` will be a :math:`(j \times k \times n \times p)` tensor.
  16228. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`. In particular the
  16229. matrix-matrix (both arguments 2-dimensional) supports sparse arguments with the same restrictions
  16230. as :func:`torch.mm`
  16231. .. warning::
  16232. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  16233. or may not have autograd support. If you notice missing functionality please
  16234. open a feature request.
  16235. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  16236. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  16237. .. note::
  16238. The 1-dimensional dot product version of this function does not support an :attr:`out` parameter.
  16239. Arguments:
  16240. input (Tensor): the first tensor to be multiplied
  16241. other (Tensor): the second tensor to be multiplied
  16242. Keyword args:
  16243. out (Tensor, optional): the output tensor.
  16244. Example::
  16245. >>> # vector x vector
  16246. >>> tensor1 = torch.randn(3)
  16247. >>> tensor2 = torch.randn(3)
  16248. >>> torch.matmul(tensor1, tensor2).size()
  16249. torch.Size([])
  16250. >>> # matrix x vector
  16251. >>> tensor1 = torch.randn(3, 4)
  16252. >>> tensor2 = torch.randn(4)
  16253. >>> torch.matmul(tensor1, tensor2).size()
  16254. torch.Size([3])
  16255. >>> # batched matrix x broadcasted vector
  16256. >>> tensor1 = torch.randn(10, 3, 4)
  16257. >>> tensor2 = torch.randn(4)
  16258. >>> torch.matmul(tensor1, tensor2).size()
  16259. torch.Size([10, 3])
  16260. >>> # batched matrix x batched matrix
  16261. >>> tensor1 = torch.randn(10, 3, 4)
  16262. >>> tensor2 = torch.randn(10, 4, 5)
  16263. >>> torch.matmul(tensor1, tensor2).size()
  16264. torch.Size([10, 3, 5])
  16265. >>> # batched matrix x broadcasted matrix
  16266. >>> tensor1 = torch.randn(10, 3, 4)
  16267. >>> tensor2 = torch.randn(4, 5)
  16268. >>> torch.matmul(tensor1, tensor2).size()
  16269. torch.Size([10, 3, 5])
  16270. """
  16271. def matrix_exp(input: Tensor) -> Tensor:
  16272. r"""
  16273. matrix_exp(A) -> Tensor
  16274. Alias for :func:`torch.linalg.matrix_exp`.
  16275. """
  16276. def matrix_power(
  16277. input: Tensor,
  16278. n: _int,
  16279. *,
  16280. out: Tensor | None = None,
  16281. ) -> Tensor:
  16282. r"""
  16283. matrix_power(input, n, *, out=None) -> Tensor
  16284. Alias for :func:`torch.linalg.matrix_power`
  16285. """
  16286. @overload
  16287. def max(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  16288. r"""
  16289. max(input, *, out=None) -> Tensor
  16290. Returns the maximum value of all elements in the ``input`` tensor.
  16291. .. note::
  16292. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  16293. - ``amax``/``amin`` supports reducing on multiple dimensions,
  16294. - ``amax``/``amin`` does not return indices.
  16295. Both ``amax``/``amin`` evenly distribute gradients between equal values
  16296. when there are multiple input elements with the same minimum or maximum value.
  16297. For ``max``/``min``:
  16298. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  16299. - If reduce over one specified axis, only propagate to the indexed element.
  16300. Args:
  16301. input (Tensor): the input tensor.
  16302. Keyword args:
  16303. out (Tensor, optional): the output tensor.
  16304. Example::
  16305. >>> a = torch.randn(1, 3)
  16306. >>> a
  16307. tensor([[ 0.6763, 0.7445, -2.2369]])
  16308. >>> torch.max(a)
  16309. tensor(0.7445)
  16310. .. function:: max(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  16311. :noindex:
  16312. Returns a namedtuple ``(values, indices)`` where ``values`` is the maximum
  16313. value of each row of the :attr:`input` tensor in the given dimension
  16314. :attr:`dim`. And ``indices`` is the index location of each maximum value found
  16315. (argmax).
  16316. If ``keepdim`` is ``True``, the output tensors are of the same size
  16317. as ``input`` except in the dimension ``dim`` where they are of size 1.
  16318. Otherwise, ``dim`` is squeezed (see :func:`torch.squeeze`), resulting
  16319. in the output tensors having 1 fewer dimension than ``input``.
  16320. .. note:: If there are multiple maximal values in a reduced row then
  16321. the indices of the first maximal value are returned.
  16322. Args:
  16323. input (Tensor): the input tensor.
  16324. dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
  16325. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16326. Keyword args:
  16327. out (tuple, optional): the result tuple of two output tensors (max, max_indices)
  16328. Example::
  16329. >>> a = torch.randn(4, 4)
  16330. >>> a
  16331. tensor([[-1.2360, -0.2942, -0.1222, 0.8475],
  16332. [ 1.1949, -1.1127, -2.2379, -0.6702],
  16333. [ 1.5717, -0.9207, 0.1297, -1.8768],
  16334. [-0.6172, 1.0036, -0.6060, -0.2432]])
  16335. >>> torch.max(a, 1)
  16336. torch.return_types.max(values=tensor([0.8475, 1.1949, 1.5717, 1.0036]), indices=tensor([3, 0, 0, 1]))
  16337. >>> a = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
  16338. >>> a.max(dim=1, keepdim=True)
  16339. torch.return_types.max(
  16340. values=tensor([[2.], [4.]]),
  16341. indices=tensor([[1], [1]]))
  16342. >>> a.max(dim=1, keepdim=False)
  16343. torch.return_types.max(
  16344. values=tensor([2., 4.]),
  16345. indices=tensor([1, 1]))
  16346. .. function:: max(input, other, *, out=None) -> Tensor
  16347. :noindex:
  16348. See :func:`torch.maximum`.
  16349. """
  16350. @overload
  16351. def max(
  16352. input: Tensor,
  16353. other: Tensor,
  16354. *,
  16355. out: Tensor | None = None,
  16356. ) -> Tensor:
  16357. r"""
  16358. max(input, *, out=None) -> Tensor
  16359. Returns the maximum value of all elements in the ``input`` tensor.
  16360. .. note::
  16361. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  16362. - ``amax``/``amin`` supports reducing on multiple dimensions,
  16363. - ``amax``/``amin`` does not return indices.
  16364. Both ``amax``/``amin`` evenly distribute gradients between equal values
  16365. when there are multiple input elements with the same minimum or maximum value.
  16366. For ``max``/``min``:
  16367. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  16368. - If reduce over one specified axis, only propagate to the indexed element.
  16369. Args:
  16370. input (Tensor): the input tensor.
  16371. Keyword args:
  16372. out (Tensor, optional): the output tensor.
  16373. Example::
  16374. >>> a = torch.randn(1, 3)
  16375. >>> a
  16376. tensor([[ 0.6763, 0.7445, -2.2369]])
  16377. >>> torch.max(a)
  16378. tensor(0.7445)
  16379. .. function:: max(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  16380. :noindex:
  16381. Returns a namedtuple ``(values, indices)`` where ``values`` is the maximum
  16382. value of each row of the :attr:`input` tensor in the given dimension
  16383. :attr:`dim`. And ``indices`` is the index location of each maximum value found
  16384. (argmax).
  16385. If ``keepdim`` is ``True``, the output tensors are of the same size
  16386. as ``input`` except in the dimension ``dim`` where they are of size 1.
  16387. Otherwise, ``dim`` is squeezed (see :func:`torch.squeeze`), resulting
  16388. in the output tensors having 1 fewer dimension than ``input``.
  16389. .. note:: If there are multiple maximal values in a reduced row then
  16390. the indices of the first maximal value are returned.
  16391. Args:
  16392. input (Tensor): the input tensor.
  16393. dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
  16394. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16395. Keyword args:
  16396. out (tuple, optional): the result tuple of two output tensors (max, max_indices)
  16397. Example::
  16398. >>> a = torch.randn(4, 4)
  16399. >>> a
  16400. tensor([[-1.2360, -0.2942, -0.1222, 0.8475],
  16401. [ 1.1949, -1.1127, -2.2379, -0.6702],
  16402. [ 1.5717, -0.9207, 0.1297, -1.8768],
  16403. [-0.6172, 1.0036, -0.6060, -0.2432]])
  16404. >>> torch.max(a, 1)
  16405. torch.return_types.max(values=tensor([0.8475, 1.1949, 1.5717, 1.0036]), indices=tensor([3, 0, 0, 1]))
  16406. >>> a = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
  16407. >>> a.max(dim=1, keepdim=True)
  16408. torch.return_types.max(
  16409. values=tensor([[2.], [4.]]),
  16410. indices=tensor([[1], [1]]))
  16411. >>> a.max(dim=1, keepdim=False)
  16412. torch.return_types.max(
  16413. values=tensor([2., 4.]),
  16414. indices=tensor([1, 1]))
  16415. .. function:: max(input, other, *, out=None) -> Tensor
  16416. :noindex:
  16417. See :func:`torch.maximum`.
  16418. """
  16419. @overload
  16420. def max(
  16421. input: Tensor,
  16422. dim: _int,
  16423. keepdim: _bool = False,
  16424. *,
  16425. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  16426. ) -> torch.return_types.max:
  16427. r"""
  16428. max(input, *, out=None) -> Tensor
  16429. Returns the maximum value of all elements in the ``input`` tensor.
  16430. .. note::
  16431. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  16432. - ``amax``/``amin`` supports reducing on multiple dimensions,
  16433. - ``amax``/``amin`` does not return indices.
  16434. Both ``amax``/``amin`` evenly distribute gradients between equal values
  16435. when there are multiple input elements with the same minimum or maximum value.
  16436. For ``max``/``min``:
  16437. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  16438. - If reduce over one specified axis, only propagate to the indexed element.
  16439. Args:
  16440. input (Tensor): the input tensor.
  16441. Keyword args:
  16442. out (Tensor, optional): the output tensor.
  16443. Example::
  16444. >>> a = torch.randn(1, 3)
  16445. >>> a
  16446. tensor([[ 0.6763, 0.7445, -2.2369]])
  16447. >>> torch.max(a)
  16448. tensor(0.7445)
  16449. .. function:: max(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  16450. :noindex:
  16451. Returns a namedtuple ``(values, indices)`` where ``values`` is the maximum
  16452. value of each row of the :attr:`input` tensor in the given dimension
  16453. :attr:`dim`. And ``indices`` is the index location of each maximum value found
  16454. (argmax).
  16455. If ``keepdim`` is ``True``, the output tensors are of the same size
  16456. as ``input`` except in the dimension ``dim`` where they are of size 1.
  16457. Otherwise, ``dim`` is squeezed (see :func:`torch.squeeze`), resulting
  16458. in the output tensors having 1 fewer dimension than ``input``.
  16459. .. note:: If there are multiple maximal values in a reduced row then
  16460. the indices of the first maximal value are returned.
  16461. Args:
  16462. input (Tensor): the input tensor.
  16463. dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
  16464. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16465. Keyword args:
  16466. out (tuple, optional): the result tuple of two output tensors (max, max_indices)
  16467. Example::
  16468. >>> a = torch.randn(4, 4)
  16469. >>> a
  16470. tensor([[-1.2360, -0.2942, -0.1222, 0.8475],
  16471. [ 1.1949, -1.1127, -2.2379, -0.6702],
  16472. [ 1.5717, -0.9207, 0.1297, -1.8768],
  16473. [-0.6172, 1.0036, -0.6060, -0.2432]])
  16474. >>> torch.max(a, 1)
  16475. torch.return_types.max(values=tensor([0.8475, 1.1949, 1.5717, 1.0036]), indices=tensor([3, 0, 0, 1]))
  16476. >>> a = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
  16477. >>> a.max(dim=1, keepdim=True)
  16478. torch.return_types.max(
  16479. values=tensor([[2.], [4.]]),
  16480. indices=tensor([[1], [1]]))
  16481. >>> a.max(dim=1, keepdim=False)
  16482. torch.return_types.max(
  16483. values=tensor([2., 4.]),
  16484. indices=tensor([1, 1]))
  16485. .. function:: max(input, other, *, out=None) -> Tensor
  16486. :noindex:
  16487. See :func:`torch.maximum`.
  16488. """
  16489. @overload
  16490. def max(
  16491. input: Tensor,
  16492. dim: str | EllipsisType | None,
  16493. keepdim: _bool = False,
  16494. *,
  16495. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  16496. ) -> torch.return_types.max:
  16497. r"""
  16498. max(input, *, out=None) -> Tensor
  16499. Returns the maximum value of all elements in the ``input`` tensor.
  16500. .. note::
  16501. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  16502. - ``amax``/``amin`` supports reducing on multiple dimensions,
  16503. - ``amax``/``amin`` does not return indices.
  16504. Both ``amax``/``amin`` evenly distribute gradients between equal values
  16505. when there are multiple input elements with the same minimum or maximum value.
  16506. For ``max``/``min``:
  16507. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  16508. - If reduce over one specified axis, only propagate to the indexed element.
  16509. Args:
  16510. input (Tensor): the input tensor.
  16511. Keyword args:
  16512. out (Tensor, optional): the output tensor.
  16513. Example::
  16514. >>> a = torch.randn(1, 3)
  16515. >>> a
  16516. tensor([[ 0.6763, 0.7445, -2.2369]])
  16517. >>> torch.max(a)
  16518. tensor(0.7445)
  16519. .. function:: max(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  16520. :noindex:
  16521. Returns a namedtuple ``(values, indices)`` where ``values`` is the maximum
  16522. value of each row of the :attr:`input` tensor in the given dimension
  16523. :attr:`dim`. And ``indices`` is the index location of each maximum value found
  16524. (argmax).
  16525. If ``keepdim`` is ``True``, the output tensors are of the same size
  16526. as ``input`` except in the dimension ``dim`` where they are of size 1.
  16527. Otherwise, ``dim`` is squeezed (see :func:`torch.squeeze`), resulting
  16528. in the output tensors having 1 fewer dimension than ``input``.
  16529. .. note:: If there are multiple maximal values in a reduced row then
  16530. the indices of the first maximal value are returned.
  16531. Args:
  16532. input (Tensor): the input tensor.
  16533. dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
  16534. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16535. Keyword args:
  16536. out (tuple, optional): the result tuple of two output tensors (max, max_indices)
  16537. Example::
  16538. >>> a = torch.randn(4, 4)
  16539. >>> a
  16540. tensor([[-1.2360, -0.2942, -0.1222, 0.8475],
  16541. [ 1.1949, -1.1127, -2.2379, -0.6702],
  16542. [ 1.5717, -0.9207, 0.1297, -1.8768],
  16543. [-0.6172, 1.0036, -0.6060, -0.2432]])
  16544. >>> torch.max(a, 1)
  16545. torch.return_types.max(values=tensor([0.8475, 1.1949, 1.5717, 1.0036]), indices=tensor([3, 0, 0, 1]))
  16546. >>> a = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
  16547. >>> a.max(dim=1, keepdim=True)
  16548. torch.return_types.max(
  16549. values=tensor([[2.], [4.]]),
  16550. indices=tensor([[1], [1]]))
  16551. >>> a.max(dim=1, keepdim=False)
  16552. torch.return_types.max(
  16553. values=tensor([2., 4.]),
  16554. indices=tensor([1, 1]))
  16555. .. function:: max(input, other, *, out=None) -> Tensor
  16556. :noindex:
  16557. See :func:`torch.maximum`.
  16558. """
  16559. def max_pool1d(
  16560. input: Tensor,
  16561. kernel_size: _int | _size,
  16562. stride: _int | _size = (),
  16563. padding: _int | _size = 0,
  16564. dilation: _int | _size = 1,
  16565. ceil_mode: _bool = False,
  16566. ) -> Tensor: ...
  16567. def max_pool1d_with_indices(
  16568. input: Tensor,
  16569. kernel_size: _int | _size,
  16570. stride: _int | _size = (),
  16571. padding: _int | _size = 0,
  16572. dilation: _int | _size = 1,
  16573. ceil_mode: _bool = False,
  16574. ) -> tuple[Tensor, Tensor]: ...
  16575. def max_pool2d(
  16576. input: Tensor,
  16577. kernel_size: _int | _size,
  16578. stride: _int | _size = (),
  16579. padding: _int | _size = 0,
  16580. dilation: _int | _size = 1,
  16581. ceil_mode: _bool = False,
  16582. ) -> Tensor: ...
  16583. def max_pool3d(
  16584. input: Tensor,
  16585. kernel_size: _int | _size,
  16586. stride: _int | _size = (),
  16587. padding: _int | _size = 0,
  16588. dilation: _int | _size = 1,
  16589. ceil_mode: _bool = False,
  16590. ) -> Tensor: ...
  16591. def maximum(
  16592. input: Tensor,
  16593. other: Tensor,
  16594. *,
  16595. out: Tensor | None = None,
  16596. ) -> Tensor:
  16597. r"""
  16598. maximum(input, other, *, out=None) -> Tensor
  16599. Computes the element-wise maximum of :attr:`input` and :attr:`other`.
  16600. .. note::
  16601. If one of the elements being compared is a NaN, then that element is returned.
  16602. :func:`maximum` is not supported for tensors with complex dtypes.
  16603. Args:
  16604. input (Tensor): the input tensor.
  16605. other (Tensor): the second input tensor
  16606. Keyword args:
  16607. out (Tensor, optional): the output tensor.
  16608. Example::
  16609. >>> a = torch.tensor((1, 2, -1))
  16610. >>> b = torch.tensor((3, 0, 4))
  16611. >>> torch.maximum(a, b)
  16612. tensor([3, 2, 4])
  16613. """
  16614. @overload
  16615. def mean(
  16616. input: Tensor,
  16617. *,
  16618. dtype: _dtype | None = None,
  16619. out: Tensor | None = None,
  16620. ) -> Tensor:
  16621. r"""
  16622. mean(input, *, dtype=None) -> Tensor
  16623. .. note::
  16624. If the `input` tensor is empty, ``torch.mean()`` returns ``nan``.
  16625. This behavior is consistent with NumPy and follows the definition
  16626. that the mean over an empty set is undefined.
  16627. Returns the mean value of all elements in the :attr:`input` tensor. Input must be floating point or complex.
  16628. Args:
  16629. input (Tensor):
  16630. the input tensor, either of floating point or complex dtype
  16631. Keyword args:
  16632. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  16633. If specified, the input tensor is casted to :attr:`dtype` before the operation
  16634. is performed. This is useful for preventing data type overflows. Default: None.
  16635. Example::
  16636. >>> a = torch.randn(1, 3)
  16637. >>> a
  16638. tensor([[ 0.2294, -0.5481, 1.3288]])
  16639. >>> torch.mean(a)
  16640. tensor(0.3367)
  16641. .. function:: mean(input, dim, keepdim=False, *, dtype=None, out=None) -> Tensor
  16642. :noindex:
  16643. Returns the mean value of each row of the :attr:`input` tensor in the given
  16644. dimension :attr:`dim`. If :attr:`dim` is a list of dimensions,
  16645. reduce over all of them.
  16646. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  16647. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  16648. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  16649. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  16650. Args:
  16651. input (Tensor): the input tensor.
  16652. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  16653. If ``None``, all dimensions are reduced.
  16654. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16655. Keyword args:
  16656. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  16657. If specified, the input tensor is casted to :attr:`dtype` before the operation
  16658. is performed. This is useful for preventing data type overflows. Default: None.
  16659. out (Tensor, optional): the output tensor.
  16660. .. seealso::
  16661. :func:`torch.nanmean` computes the mean value of `non-NaN` elements.
  16662. Example::
  16663. >>> a = torch.randn(4, 4)
  16664. >>> a
  16665. tensor([[-0.3841, 0.6320, 0.4254, -0.7384],
  16666. [-0.9644, 1.0131, -0.6549, -1.4279],
  16667. [-0.2951, -1.3350, -0.7694, 0.5600],
  16668. [ 1.0842, -0.9580, 0.3623, 0.2343]])
  16669. >>> torch.mean(a, 1)
  16670. tensor([-0.0163, -0.5085, -0.4599, 0.1807])
  16671. >>> torch.mean(a, 1, True)
  16672. tensor([[-0.0163],
  16673. [-0.5085],
  16674. [-0.4599],
  16675. [ 0.1807]])
  16676. """
  16677. @overload
  16678. def mean(
  16679. input: Tensor,
  16680. dim: _int | _size | None,
  16681. keepdim: _bool = False,
  16682. *,
  16683. dtype: _dtype | None = None,
  16684. out: Tensor | None = None,
  16685. ) -> Tensor:
  16686. r"""
  16687. mean(input, *, dtype=None) -> Tensor
  16688. .. note::
  16689. If the `input` tensor is empty, ``torch.mean()`` returns ``nan``.
  16690. This behavior is consistent with NumPy and follows the definition
  16691. that the mean over an empty set is undefined.
  16692. Returns the mean value of all elements in the :attr:`input` tensor. Input must be floating point or complex.
  16693. Args:
  16694. input (Tensor):
  16695. the input tensor, either of floating point or complex dtype
  16696. Keyword args:
  16697. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  16698. If specified, the input tensor is casted to :attr:`dtype` before the operation
  16699. is performed. This is useful for preventing data type overflows. Default: None.
  16700. Example::
  16701. >>> a = torch.randn(1, 3)
  16702. >>> a
  16703. tensor([[ 0.2294, -0.5481, 1.3288]])
  16704. >>> torch.mean(a)
  16705. tensor(0.3367)
  16706. .. function:: mean(input, dim, keepdim=False, *, dtype=None, out=None) -> Tensor
  16707. :noindex:
  16708. Returns the mean value of each row of the :attr:`input` tensor in the given
  16709. dimension :attr:`dim`. If :attr:`dim` is a list of dimensions,
  16710. reduce over all of them.
  16711. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  16712. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  16713. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  16714. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  16715. Args:
  16716. input (Tensor): the input tensor.
  16717. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  16718. If ``None``, all dimensions are reduced.
  16719. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16720. Keyword args:
  16721. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  16722. If specified, the input tensor is casted to :attr:`dtype` before the operation
  16723. is performed. This is useful for preventing data type overflows. Default: None.
  16724. out (Tensor, optional): the output tensor.
  16725. .. seealso::
  16726. :func:`torch.nanmean` computes the mean value of `non-NaN` elements.
  16727. Example::
  16728. >>> a = torch.randn(4, 4)
  16729. >>> a
  16730. tensor([[-0.3841, 0.6320, 0.4254, -0.7384],
  16731. [-0.9644, 1.0131, -0.6549, -1.4279],
  16732. [-0.2951, -1.3350, -0.7694, 0.5600],
  16733. [ 1.0842, -0.9580, 0.3623, 0.2343]])
  16734. >>> torch.mean(a, 1)
  16735. tensor([-0.0163, -0.5085, -0.4599, 0.1807])
  16736. >>> torch.mean(a, 1, True)
  16737. tensor([[-0.0163],
  16738. [-0.5085],
  16739. [-0.4599],
  16740. [ 0.1807]])
  16741. """
  16742. @overload
  16743. def mean(
  16744. input: Tensor,
  16745. dim: Sequence[str | EllipsisType | None],
  16746. keepdim: _bool = False,
  16747. *,
  16748. dtype: _dtype | None = None,
  16749. out: Tensor | None = None,
  16750. ) -> Tensor:
  16751. r"""
  16752. mean(input, *, dtype=None) -> Tensor
  16753. .. note::
  16754. If the `input` tensor is empty, ``torch.mean()`` returns ``nan``.
  16755. This behavior is consistent with NumPy and follows the definition
  16756. that the mean over an empty set is undefined.
  16757. Returns the mean value of all elements in the :attr:`input` tensor. Input must be floating point or complex.
  16758. Args:
  16759. input (Tensor):
  16760. the input tensor, either of floating point or complex dtype
  16761. Keyword args:
  16762. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  16763. If specified, the input tensor is casted to :attr:`dtype` before the operation
  16764. is performed. This is useful for preventing data type overflows. Default: None.
  16765. Example::
  16766. >>> a = torch.randn(1, 3)
  16767. >>> a
  16768. tensor([[ 0.2294, -0.5481, 1.3288]])
  16769. >>> torch.mean(a)
  16770. tensor(0.3367)
  16771. .. function:: mean(input, dim, keepdim=False, *, dtype=None, out=None) -> Tensor
  16772. :noindex:
  16773. Returns the mean value of each row of the :attr:`input` tensor in the given
  16774. dimension :attr:`dim`. If :attr:`dim` is a list of dimensions,
  16775. reduce over all of them.
  16776. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  16777. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  16778. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  16779. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  16780. Args:
  16781. input (Tensor): the input tensor.
  16782. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  16783. If ``None``, all dimensions are reduced.
  16784. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16785. Keyword args:
  16786. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  16787. If specified, the input tensor is casted to :attr:`dtype` before the operation
  16788. is performed. This is useful for preventing data type overflows. Default: None.
  16789. out (Tensor, optional): the output tensor.
  16790. .. seealso::
  16791. :func:`torch.nanmean` computes the mean value of `non-NaN` elements.
  16792. Example::
  16793. >>> a = torch.randn(4, 4)
  16794. >>> a
  16795. tensor([[-0.3841, 0.6320, 0.4254, -0.7384],
  16796. [-0.9644, 1.0131, -0.6549, -1.4279],
  16797. [-0.2951, -1.3350, -0.7694, 0.5600],
  16798. [ 1.0842, -0.9580, 0.3623, 0.2343]])
  16799. >>> torch.mean(a, 1)
  16800. tensor([-0.0163, -0.5085, -0.4599, 0.1807])
  16801. >>> torch.mean(a, 1, True)
  16802. tensor([[-0.0163],
  16803. [-0.5085],
  16804. [-0.4599],
  16805. [ 0.1807]])
  16806. """
  16807. @overload
  16808. def median(input: Tensor) -> Tensor:
  16809. r"""
  16810. median(input) -> Tensor
  16811. Returns the median of the values in :attr:`input`.
  16812. .. note::
  16813. The median is not unique for :attr:`input` tensors with an even number
  16814. of elements. In this case the lower of the two medians is returned. To
  16815. compute the mean of both medians, use :func:`torch.quantile` with ``q=0.5`` instead.
  16816. .. warning::
  16817. This function produces deterministic (sub)gradients unlike ``median(dim=0)``
  16818. Args:
  16819. input (Tensor): the input tensor.
  16820. Example::
  16821. >>> a = torch.randn(1, 3)
  16822. >>> a
  16823. tensor([[ 1.5219, -1.5212, 0.2202]])
  16824. >>> torch.median(a)
  16825. tensor(0.2202)
  16826. .. function:: median(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  16827. :noindex:
  16828. Returns a namedtuple ``(values, indices)`` where ``values`` contains the median of each row of :attr:`input`
  16829. in the dimension :attr:`dim`, and ``indices`` contains the index of the median values found in the dimension :attr:`dim`.
  16830. By default, :attr:`dim` is the last dimension of the :attr:`input` tensor.
  16831. If :attr:`keepdim` is ``True``, the output tensors are of the same size
  16832. as :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  16833. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  16834. the outputs tensor having 1 fewer dimension than :attr:`input`.
  16835. .. note::
  16836. The median is not unique for :attr:`input` tensors with an even number
  16837. of elements in the dimension :attr:`dim`. In this case the lower of the
  16838. two medians is returned. To compute the mean of both medians in
  16839. :attr:`input`, use :func:`torch.quantile` with ``q=0.5`` instead.
  16840. .. warning::
  16841. ``indices`` does not necessarily contain the first occurrence of each
  16842. median value found, unless it is unique.
  16843. The exact implementation details are device-specific.
  16844. Do not expect the same result when run on CPU and GPU in general.
  16845. For the same reason do not expect the gradients to be deterministic.
  16846. Args:
  16847. input (Tensor): the input tensor.
  16848. dim (int, optional): the dimension to reduce.
  16849. If ``None``, all dimensions are reduced.
  16850. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16851. Keyword args:
  16852. out ((Tensor, Tensor), optional): The first tensor will be populated with the median values and the second
  16853. tensor, which must have dtype long, with their indices in the dimension
  16854. :attr:`dim` of :attr:`input`.
  16855. Example::
  16856. >>> a = torch.randn(4, 5)
  16857. >>> a
  16858. tensor([[ 0.2505, -0.3982, -0.9948, 0.3518, -1.3131],
  16859. [ 0.3180, -0.6993, 1.0436, 0.0438, 0.2270],
  16860. [-0.2751, 0.7303, 0.2192, 0.3321, 0.2488],
  16861. [ 1.0778, -1.9510, 0.7048, 0.4742, -0.7125]])
  16862. >>> torch.median(a, 1)
  16863. torch.return_types.median(values=tensor([-0.3982, 0.2270, 0.2488, 0.4742]), indices=tensor([1, 4, 4, 3]))
  16864. """
  16865. @overload
  16866. def median(
  16867. input: Tensor,
  16868. dim: _int,
  16869. keepdim: _bool = False,
  16870. *,
  16871. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  16872. ) -> torch.return_types.median:
  16873. r"""
  16874. median(input) -> Tensor
  16875. Returns the median of the values in :attr:`input`.
  16876. .. note::
  16877. The median is not unique for :attr:`input` tensors with an even number
  16878. of elements. In this case the lower of the two medians is returned. To
  16879. compute the mean of both medians, use :func:`torch.quantile` with ``q=0.5`` instead.
  16880. .. warning::
  16881. This function produces deterministic (sub)gradients unlike ``median(dim=0)``
  16882. Args:
  16883. input (Tensor): the input tensor.
  16884. Example::
  16885. >>> a = torch.randn(1, 3)
  16886. >>> a
  16887. tensor([[ 1.5219, -1.5212, 0.2202]])
  16888. >>> torch.median(a)
  16889. tensor(0.2202)
  16890. .. function:: median(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  16891. :noindex:
  16892. Returns a namedtuple ``(values, indices)`` where ``values`` contains the median of each row of :attr:`input`
  16893. in the dimension :attr:`dim`, and ``indices`` contains the index of the median values found in the dimension :attr:`dim`.
  16894. By default, :attr:`dim` is the last dimension of the :attr:`input` tensor.
  16895. If :attr:`keepdim` is ``True``, the output tensors are of the same size
  16896. as :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  16897. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  16898. the outputs tensor having 1 fewer dimension than :attr:`input`.
  16899. .. note::
  16900. The median is not unique for :attr:`input` tensors with an even number
  16901. of elements in the dimension :attr:`dim`. In this case the lower of the
  16902. two medians is returned. To compute the mean of both medians in
  16903. :attr:`input`, use :func:`torch.quantile` with ``q=0.5`` instead.
  16904. .. warning::
  16905. ``indices`` does not necessarily contain the first occurrence of each
  16906. median value found, unless it is unique.
  16907. The exact implementation details are device-specific.
  16908. Do not expect the same result when run on CPU and GPU in general.
  16909. For the same reason do not expect the gradients to be deterministic.
  16910. Args:
  16911. input (Tensor): the input tensor.
  16912. dim (int, optional): the dimension to reduce.
  16913. If ``None``, all dimensions are reduced.
  16914. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16915. Keyword args:
  16916. out ((Tensor, Tensor), optional): The first tensor will be populated with the median values and the second
  16917. tensor, which must have dtype long, with their indices in the dimension
  16918. :attr:`dim` of :attr:`input`.
  16919. Example::
  16920. >>> a = torch.randn(4, 5)
  16921. >>> a
  16922. tensor([[ 0.2505, -0.3982, -0.9948, 0.3518, -1.3131],
  16923. [ 0.3180, -0.6993, 1.0436, 0.0438, 0.2270],
  16924. [-0.2751, 0.7303, 0.2192, 0.3321, 0.2488],
  16925. [ 1.0778, -1.9510, 0.7048, 0.4742, -0.7125]])
  16926. >>> torch.median(a, 1)
  16927. torch.return_types.median(values=tensor([-0.3982, 0.2270, 0.2488, 0.4742]), indices=tensor([1, 4, 4, 3]))
  16928. """
  16929. @overload
  16930. def median(
  16931. input: Tensor,
  16932. dim: str | EllipsisType | None,
  16933. keepdim: _bool = False,
  16934. *,
  16935. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  16936. ) -> torch.return_types.median:
  16937. r"""
  16938. median(input) -> Tensor
  16939. Returns the median of the values in :attr:`input`.
  16940. .. note::
  16941. The median is not unique for :attr:`input` tensors with an even number
  16942. of elements. In this case the lower of the two medians is returned. To
  16943. compute the mean of both medians, use :func:`torch.quantile` with ``q=0.5`` instead.
  16944. .. warning::
  16945. This function produces deterministic (sub)gradients unlike ``median(dim=0)``
  16946. Args:
  16947. input (Tensor): the input tensor.
  16948. Example::
  16949. >>> a = torch.randn(1, 3)
  16950. >>> a
  16951. tensor([[ 1.5219, -1.5212, 0.2202]])
  16952. >>> torch.median(a)
  16953. tensor(0.2202)
  16954. .. function:: median(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  16955. :noindex:
  16956. Returns a namedtuple ``(values, indices)`` where ``values`` contains the median of each row of :attr:`input`
  16957. in the dimension :attr:`dim`, and ``indices`` contains the index of the median values found in the dimension :attr:`dim`.
  16958. By default, :attr:`dim` is the last dimension of the :attr:`input` tensor.
  16959. If :attr:`keepdim` is ``True``, the output tensors are of the same size
  16960. as :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  16961. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  16962. the outputs tensor having 1 fewer dimension than :attr:`input`.
  16963. .. note::
  16964. The median is not unique for :attr:`input` tensors with an even number
  16965. of elements in the dimension :attr:`dim`. In this case the lower of the
  16966. two medians is returned. To compute the mean of both medians in
  16967. :attr:`input`, use :func:`torch.quantile` with ``q=0.5`` instead.
  16968. .. warning::
  16969. ``indices`` does not necessarily contain the first occurrence of each
  16970. median value found, unless it is unique.
  16971. The exact implementation details are device-specific.
  16972. Do not expect the same result when run on CPU and GPU in general.
  16973. For the same reason do not expect the gradients to be deterministic.
  16974. Args:
  16975. input (Tensor): the input tensor.
  16976. dim (int, optional): the dimension to reduce.
  16977. If ``None``, all dimensions are reduced.
  16978. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16979. Keyword args:
  16980. out ((Tensor, Tensor), optional): The first tensor will be populated with the median values and the second
  16981. tensor, which must have dtype long, with their indices in the dimension
  16982. :attr:`dim` of :attr:`input`.
  16983. Example::
  16984. >>> a = torch.randn(4, 5)
  16985. >>> a
  16986. tensor([[ 0.2505, -0.3982, -0.9948, 0.3518, -1.3131],
  16987. [ 0.3180, -0.6993, 1.0436, 0.0438, 0.2270],
  16988. [-0.2751, 0.7303, 0.2192, 0.3321, 0.2488],
  16989. [ 1.0778, -1.9510, 0.7048, 0.4742, -0.7125]])
  16990. >>> torch.median(a, 1)
  16991. torch.return_types.median(values=tensor([-0.3982, 0.2270, 0.2488, 0.4742]), indices=tensor([1, 4, 4, 3]))
  16992. """
  16993. @overload
  16994. def min(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  16995. r"""
  16996. min(input, *, out=None) -> Tensor
  16997. Returns the minimum value of all elements in the :attr:`input` tensor.
  16998. .. note::
  16999. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  17000. - ``amax``/``amin`` supports reducing on multiple dimensions,
  17001. - ``amax``/``amin`` does not return indices.
  17002. Both ``amax``/``amin`` evenly distribute gradients between equal values
  17003. when there are multiple input elements with the same minimum or maximum value.
  17004. For ``max``/``min``:
  17005. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  17006. - If reduce over one specified axis, only propagate to the indexed element.
  17007. Args:
  17008. input (Tensor): the input tensor.
  17009. Keyword args:
  17010. out (Tensor, optional): the output tensor.
  17011. Example::
  17012. >>> a = torch.randn(1, 3)
  17013. >>> a
  17014. tensor([[ 0.6750, 1.0857, 1.7197]])
  17015. >>> torch.min(a)
  17016. tensor(0.6750)
  17017. .. function:: min(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  17018. :noindex:
  17019. Returns a namedtuple ``(values, indices)`` where ``values`` is the minimum
  17020. value of each row of the :attr:`input` tensor in the given dimension
  17021. :attr:`dim`. And ``indices`` is the index location of each minimum value found
  17022. (argmin).
  17023. If :attr:`keepdim` is ``True``, the output tensors are of the same size as
  17024. :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  17025. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  17026. the output tensors having 1 fewer dimension than :attr:`input`.
  17027. .. note:: If there are multiple minimal values in a reduced row then
  17028. the indices of the first minimal value are returned.
  17029. Args:
  17030. input (Tensor): the input tensor.
  17031. dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
  17032. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17033. Keyword args:
  17034. out (tuple, optional): the tuple of two output tensors (min, min_indices)
  17035. Example::
  17036. >>> a = torch.randn(4, 4)
  17037. >>> a
  17038. tensor([[-0.6248, 1.1334, -1.1899, -0.2803],
  17039. [-1.4644, -0.2635, -0.3651, 0.6134],
  17040. [ 0.2457, 0.0384, 1.0128, 0.7015],
  17041. [-0.1153, 2.9849, 2.1458, 0.5788]])
  17042. >>> torch.min(a, 1)
  17043. torch.return_types.min(values=tensor([-1.1899, -1.4644, 0.0384, -0.1153]), indices=tensor([2, 0, 1, 0]))
  17044. .. function:: min(input, other, *, out=None) -> Tensor
  17045. :noindex:
  17046. See :func:`torch.minimum`.
  17047. """
  17048. @overload
  17049. def min(
  17050. input: Tensor,
  17051. other: Tensor,
  17052. *,
  17053. out: Tensor | None = None,
  17054. ) -> Tensor:
  17055. r"""
  17056. min(input, *, out=None) -> Tensor
  17057. Returns the minimum value of all elements in the :attr:`input` tensor.
  17058. .. note::
  17059. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  17060. - ``amax``/``amin`` supports reducing on multiple dimensions,
  17061. - ``amax``/``amin`` does not return indices.
  17062. Both ``amax``/``amin`` evenly distribute gradients between equal values
  17063. when there are multiple input elements with the same minimum or maximum value.
  17064. For ``max``/``min``:
  17065. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  17066. - If reduce over one specified axis, only propagate to the indexed element.
  17067. Args:
  17068. input (Tensor): the input tensor.
  17069. Keyword args:
  17070. out (Tensor, optional): the output tensor.
  17071. Example::
  17072. >>> a = torch.randn(1, 3)
  17073. >>> a
  17074. tensor([[ 0.6750, 1.0857, 1.7197]])
  17075. >>> torch.min(a)
  17076. tensor(0.6750)
  17077. .. function:: min(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  17078. :noindex:
  17079. Returns a namedtuple ``(values, indices)`` where ``values`` is the minimum
  17080. value of each row of the :attr:`input` tensor in the given dimension
  17081. :attr:`dim`. And ``indices`` is the index location of each minimum value found
  17082. (argmin).
  17083. If :attr:`keepdim` is ``True``, the output tensors are of the same size as
  17084. :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  17085. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  17086. the output tensors having 1 fewer dimension than :attr:`input`.
  17087. .. note:: If there are multiple minimal values in a reduced row then
  17088. the indices of the first minimal value are returned.
  17089. Args:
  17090. input (Tensor): the input tensor.
  17091. dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
  17092. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17093. Keyword args:
  17094. out (tuple, optional): the tuple of two output tensors (min, min_indices)
  17095. Example::
  17096. >>> a = torch.randn(4, 4)
  17097. >>> a
  17098. tensor([[-0.6248, 1.1334, -1.1899, -0.2803],
  17099. [-1.4644, -0.2635, -0.3651, 0.6134],
  17100. [ 0.2457, 0.0384, 1.0128, 0.7015],
  17101. [-0.1153, 2.9849, 2.1458, 0.5788]])
  17102. >>> torch.min(a, 1)
  17103. torch.return_types.min(values=tensor([-1.1899, -1.4644, 0.0384, -0.1153]), indices=tensor([2, 0, 1, 0]))
  17104. .. function:: min(input, other, *, out=None) -> Tensor
  17105. :noindex:
  17106. See :func:`torch.minimum`.
  17107. """
  17108. @overload
  17109. def min(
  17110. input: Tensor,
  17111. dim: _int,
  17112. keepdim: _bool = False,
  17113. *,
  17114. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  17115. ) -> torch.return_types.min:
  17116. r"""
  17117. min(input, *, out=None) -> Tensor
  17118. Returns the minimum value of all elements in the :attr:`input` tensor.
  17119. .. note::
  17120. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  17121. - ``amax``/``amin`` supports reducing on multiple dimensions,
  17122. - ``amax``/``amin`` does not return indices.
  17123. Both ``amax``/``amin`` evenly distribute gradients between equal values
  17124. when there are multiple input elements with the same minimum or maximum value.
  17125. For ``max``/``min``:
  17126. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  17127. - If reduce over one specified axis, only propagate to the indexed element.
  17128. Args:
  17129. input (Tensor): the input tensor.
  17130. Keyword args:
  17131. out (Tensor, optional): the output tensor.
  17132. Example::
  17133. >>> a = torch.randn(1, 3)
  17134. >>> a
  17135. tensor([[ 0.6750, 1.0857, 1.7197]])
  17136. >>> torch.min(a)
  17137. tensor(0.6750)
  17138. .. function:: min(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  17139. :noindex:
  17140. Returns a namedtuple ``(values, indices)`` where ``values`` is the minimum
  17141. value of each row of the :attr:`input` tensor in the given dimension
  17142. :attr:`dim`. And ``indices`` is the index location of each minimum value found
  17143. (argmin).
  17144. If :attr:`keepdim` is ``True``, the output tensors are of the same size as
  17145. :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  17146. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  17147. the output tensors having 1 fewer dimension than :attr:`input`.
  17148. .. note:: If there are multiple minimal values in a reduced row then
  17149. the indices of the first minimal value are returned.
  17150. Args:
  17151. input (Tensor): the input tensor.
  17152. dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
  17153. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17154. Keyword args:
  17155. out (tuple, optional): the tuple of two output tensors (min, min_indices)
  17156. Example::
  17157. >>> a = torch.randn(4, 4)
  17158. >>> a
  17159. tensor([[-0.6248, 1.1334, -1.1899, -0.2803],
  17160. [-1.4644, -0.2635, -0.3651, 0.6134],
  17161. [ 0.2457, 0.0384, 1.0128, 0.7015],
  17162. [-0.1153, 2.9849, 2.1458, 0.5788]])
  17163. >>> torch.min(a, 1)
  17164. torch.return_types.min(values=tensor([-1.1899, -1.4644, 0.0384, -0.1153]), indices=tensor([2, 0, 1, 0]))
  17165. .. function:: min(input, other, *, out=None) -> Tensor
  17166. :noindex:
  17167. See :func:`torch.minimum`.
  17168. """
  17169. @overload
  17170. def min(
  17171. input: Tensor,
  17172. dim: str | EllipsisType | None,
  17173. keepdim: _bool = False,
  17174. *,
  17175. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  17176. ) -> torch.return_types.min:
  17177. r"""
  17178. min(input, *, out=None) -> Tensor
  17179. Returns the minimum value of all elements in the :attr:`input` tensor.
  17180. .. note::
  17181. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  17182. - ``amax``/``amin`` supports reducing on multiple dimensions,
  17183. - ``amax``/``amin`` does not return indices.
  17184. Both ``amax``/``amin`` evenly distribute gradients between equal values
  17185. when there are multiple input elements with the same minimum or maximum value.
  17186. For ``max``/``min``:
  17187. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  17188. - If reduce over one specified axis, only propagate to the indexed element.
  17189. Args:
  17190. input (Tensor): the input tensor.
  17191. Keyword args:
  17192. out (Tensor, optional): the output tensor.
  17193. Example::
  17194. >>> a = torch.randn(1, 3)
  17195. >>> a
  17196. tensor([[ 0.6750, 1.0857, 1.7197]])
  17197. >>> torch.min(a)
  17198. tensor(0.6750)
  17199. .. function:: min(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  17200. :noindex:
  17201. Returns a namedtuple ``(values, indices)`` where ``values`` is the minimum
  17202. value of each row of the :attr:`input` tensor in the given dimension
  17203. :attr:`dim`. And ``indices`` is the index location of each minimum value found
  17204. (argmin).
  17205. If :attr:`keepdim` is ``True``, the output tensors are of the same size as
  17206. :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  17207. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  17208. the output tensors having 1 fewer dimension than :attr:`input`.
  17209. .. note:: If there are multiple minimal values in a reduced row then
  17210. the indices of the first minimal value are returned.
  17211. Args:
  17212. input (Tensor): the input tensor.
  17213. dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
  17214. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17215. Keyword args:
  17216. out (tuple, optional): the tuple of two output tensors (min, min_indices)
  17217. Example::
  17218. >>> a = torch.randn(4, 4)
  17219. >>> a
  17220. tensor([[-0.6248, 1.1334, -1.1899, -0.2803],
  17221. [-1.4644, -0.2635, -0.3651, 0.6134],
  17222. [ 0.2457, 0.0384, 1.0128, 0.7015],
  17223. [-0.1153, 2.9849, 2.1458, 0.5788]])
  17224. >>> torch.min(a, 1)
  17225. torch.return_types.min(values=tensor([-1.1899, -1.4644, 0.0384, -0.1153]), indices=tensor([2, 0, 1, 0]))
  17226. .. function:: min(input, other, *, out=None) -> Tensor
  17227. :noindex:
  17228. See :func:`torch.minimum`.
  17229. """
  17230. def minimum(
  17231. input: Tensor,
  17232. other: Tensor,
  17233. *,
  17234. out: Tensor | None = None,
  17235. ) -> Tensor:
  17236. r"""
  17237. minimum(input, other, *, out=None) -> Tensor
  17238. Computes the element-wise minimum of :attr:`input` and :attr:`other`.
  17239. .. note::
  17240. If one of the elements being compared is a NaN, then that element is returned.
  17241. :func:`minimum` is not supported for tensors with complex dtypes.
  17242. Args:
  17243. input (Tensor): the input tensor.
  17244. other (Tensor): the second input tensor
  17245. Keyword args:
  17246. out (Tensor, optional): the output tensor.
  17247. Example::
  17248. >>> a = torch.tensor((1, 2, -1))
  17249. >>> b = torch.tensor((3, 0, 4))
  17250. >>> torch.minimum(a, b)
  17251. tensor([1, 0, -1])
  17252. """
  17253. def miopen_batch_norm(
  17254. input: Tensor,
  17255. weight: Tensor,
  17256. bias: Tensor | None,
  17257. running_mean: Tensor | None,
  17258. running_var: Tensor | None,
  17259. training: _bool,
  17260. exponential_average_factor: _float,
  17261. epsilon: _float,
  17262. ) -> tuple[Tensor, Tensor, Tensor]: ...
  17263. def miopen_convolution(
  17264. input: Tensor,
  17265. weight: Tensor,
  17266. bias: Tensor | None,
  17267. padding: Sequence[_int | SymInt],
  17268. stride: Sequence[_int | SymInt],
  17269. dilation: Sequence[_int | SymInt],
  17270. groups: _int | SymInt,
  17271. benchmark: _bool,
  17272. deterministic: _bool,
  17273. ) -> Tensor: ...
  17274. def miopen_convolution_add_relu(
  17275. input: Tensor,
  17276. weight: Tensor,
  17277. z: Tensor,
  17278. alpha: Number | _complex | None,
  17279. bias: Tensor | None,
  17280. stride: Sequence[_int | SymInt],
  17281. padding: Sequence[_int | SymInt],
  17282. dilation: Sequence[_int | SymInt],
  17283. groups: _int | SymInt,
  17284. ) -> Tensor: ...
  17285. def miopen_convolution_relu(
  17286. input: Tensor,
  17287. weight: Tensor,
  17288. bias: Tensor | None,
  17289. stride: Sequence[_int | SymInt],
  17290. padding: Sequence[_int | SymInt],
  17291. dilation: Sequence[_int | SymInt],
  17292. groups: _int | SymInt,
  17293. ) -> Tensor: ...
  17294. def miopen_convolution_transpose(
  17295. input: Tensor,
  17296. weight: Tensor,
  17297. bias: Tensor | None,
  17298. padding: Sequence[_int | SymInt],
  17299. output_padding: Sequence[_int | SymInt],
  17300. stride: Sequence[_int | SymInt],
  17301. dilation: Sequence[_int | SymInt],
  17302. groups: _int | SymInt,
  17303. benchmark: _bool,
  17304. deterministic: _bool,
  17305. ) -> Tensor: ...
  17306. def miopen_depthwise_convolution(
  17307. input: Tensor,
  17308. weight: Tensor,
  17309. bias: Tensor | None,
  17310. padding: Sequence[_int | SymInt],
  17311. stride: Sequence[_int | SymInt],
  17312. dilation: Sequence[_int | SymInt],
  17313. groups: _int | SymInt,
  17314. benchmark: _bool,
  17315. deterministic: _bool,
  17316. ) -> Tensor: ...
  17317. def miopen_rnn(
  17318. input: Tensor,
  17319. weight: tuple[Tensor, ...] | list[Tensor] | None,
  17320. weight_stride0: _int,
  17321. hx: Tensor,
  17322. cx: Tensor | None,
  17323. mode: _int,
  17324. hidden_size: _int,
  17325. num_layers: _int,
  17326. batch_first: _bool,
  17327. dropout: _float,
  17328. train: _bool,
  17329. bidirectional: _bool,
  17330. batch_sizes: _size,
  17331. dropout_state: Tensor | None,
  17332. ) -> tuple[Tensor, Tensor, Tensor, Tensor, Tensor]: ...
  17333. def mkldnn_adaptive_avg_pool2d(
  17334. input: Tensor,
  17335. output_size: _int | _size,
  17336. *,
  17337. out: Tensor | None = None,
  17338. ) -> Tensor: ...
  17339. def mkldnn_convolution(
  17340. input: Tensor,
  17341. weight: Tensor,
  17342. bias: Tensor | None,
  17343. padding: Sequence[_int | SymInt],
  17344. stride: Sequence[_int | SymInt],
  17345. dilation: Sequence[_int | SymInt],
  17346. groups: _int | SymInt,
  17347. ) -> Tensor: ...
  17348. def mkldnn_linear_backward_weights(
  17349. grad_output: Tensor,
  17350. input: Tensor,
  17351. weight: Tensor,
  17352. bias_defined: _bool,
  17353. ) -> tuple[Tensor, Tensor]: ...
  17354. def mkldnn_max_pool2d(
  17355. input: Tensor,
  17356. kernel_size: _int | _size,
  17357. stride: _int | _size = (),
  17358. padding: _int | _size = 0,
  17359. dilation: _int | _size = 1,
  17360. ceil_mode: _bool = False,
  17361. ) -> Tensor: ...
  17362. def mkldnn_max_pool3d(
  17363. input: Tensor,
  17364. kernel_size: _int | _size,
  17365. stride: _int | _size = (),
  17366. padding: _int | _size = 0,
  17367. dilation: _int | _size = 1,
  17368. ceil_mode: _bool = False,
  17369. ) -> Tensor: ...
  17370. def mkldnn_rnn_layer(
  17371. input: Tensor,
  17372. weight0: Tensor,
  17373. weight1: Tensor,
  17374. weight2: Tensor,
  17375. weight3: Tensor,
  17376. hx_: Tensor,
  17377. cx_: Tensor,
  17378. reverse: _bool,
  17379. batch_sizes: _size,
  17380. mode: _int,
  17381. hidden_size: _int,
  17382. num_layers: _int,
  17383. has_biases: _bool,
  17384. bidirectional: _bool,
  17385. batch_first: _bool,
  17386. train: _bool,
  17387. ) -> tuple[Tensor, Tensor, Tensor, Tensor]: ...
  17388. @overload
  17389. def mm(input: Tensor, mat2: Tensor, *, out: Tensor | None = None) -> Tensor:
  17390. r"""
  17391. mm(input, mat2, out_dtype=None, *, out=None) -> Tensor
  17392. Performs a matrix multiplication of the matrices :attr:`input` and :attr:`mat2`.
  17393. If :attr:`input` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
  17394. :math:`(m \times p)` tensor, :attr:`out` will be a :math:`(n \times p)` tensor.
  17395. .. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
  17396. For broadcasting matrix products, see :func:`torch.matmul`.
  17397. Supports strided and sparse 2-D tensors as inputs, autograd with
  17398. respect to strided inputs.
  17399. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`.
  17400. If :attr:`out` is provided its layout will be used. Otherwise, the result
  17401. layout will be deduced from that of :attr:`input`.
  17402. .. warning::
  17403. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  17404. or may not have autograd support. If you notice missing functionality please
  17405. open a feature request.
  17406. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  17407. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  17408. Args:
  17409. input (Tensor): the first matrix to be matrix multiplied
  17410. mat2 (Tensor): the second matrix to be matrix multiplied
  17411. out_dtype (dtype, optional): the dtype of the output tensor,
  17412. Supported only on CUDA and for torch.float32 given
  17413. torch.float16/torch.bfloat16 input dtypes
  17414. Keyword args:
  17415. out (Tensor, optional): the output tensor.
  17416. Example::
  17417. >>> mat1 = torch.randn(2, 3)
  17418. >>> mat2 = torch.randn(3, 3)
  17419. >>> torch.mm(mat1, mat2)
  17420. tensor([[ 0.4851, 0.5037, -0.3633],
  17421. [-0.0760, -3.6705, 2.4784]])
  17422. """
  17423. @overload
  17424. def mm(
  17425. input: Tensor,
  17426. mat2: Tensor,
  17427. out_dtype: _dtype,
  17428. *,
  17429. out: Tensor | None = None,
  17430. ) -> Tensor:
  17431. r"""
  17432. mm(input, mat2, out_dtype=None, *, out=None) -> Tensor
  17433. Performs a matrix multiplication of the matrices :attr:`input` and :attr:`mat2`.
  17434. If :attr:`input` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
  17435. :math:`(m \times p)` tensor, :attr:`out` will be a :math:`(n \times p)` tensor.
  17436. .. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
  17437. For broadcasting matrix products, see :func:`torch.matmul`.
  17438. Supports strided and sparse 2-D tensors as inputs, autograd with
  17439. respect to strided inputs.
  17440. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`.
  17441. If :attr:`out` is provided its layout will be used. Otherwise, the result
  17442. layout will be deduced from that of :attr:`input`.
  17443. .. warning::
  17444. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  17445. or may not have autograd support. If you notice missing functionality please
  17446. open a feature request.
  17447. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  17448. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  17449. Args:
  17450. input (Tensor): the first matrix to be matrix multiplied
  17451. mat2 (Tensor): the second matrix to be matrix multiplied
  17452. out_dtype (dtype, optional): the dtype of the output tensor,
  17453. Supported only on CUDA and for torch.float32 given
  17454. torch.float16/torch.bfloat16 input dtypes
  17455. Keyword args:
  17456. out (Tensor, optional): the output tensor.
  17457. Example::
  17458. >>> mat1 = torch.randn(2, 3)
  17459. >>> mat2 = torch.randn(3, 3)
  17460. >>> torch.mm(mat1, mat2)
  17461. tensor([[ 0.4851, 0.5037, -0.3633],
  17462. [-0.0760, -3.6705, 2.4784]])
  17463. """
  17464. @overload
  17465. def mode(
  17466. input: Tensor,
  17467. dim: _int = -1,
  17468. keepdim: _bool = False,
  17469. *,
  17470. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  17471. ) -> torch.return_types.mode:
  17472. r"""
  17473. mode(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  17474. Returns a namedtuple ``(values, indices)`` where ``values`` is the mode
  17475. value of each row of the :attr:`input` tensor in the given dimension
  17476. :attr:`dim`, i.e. a value which appears most often
  17477. in that row, and ``indices`` is the index location of each mode value found.
  17478. By default, :attr:`dim` is the last dimension of the :attr:`input` tensor.
  17479. If :attr:`keepdim` is ``True``, the output tensors are of the same size as
  17480. :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  17481. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting
  17482. in the output tensors having 1 fewer dimension than :attr:`input`.
  17483. .. note:: This function is not defined for ``torch.cuda.Tensor`` yet.
  17484. Args:
  17485. input (Tensor): the input tensor.
  17486. dim (int, optional): the dimension to reduce.
  17487. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17488. Keyword args:
  17489. out (tuple, optional): the result tuple of two output tensors (values, indices)
  17490. Example::
  17491. >>> b = torch.tensor([[0, 0, 0, 2, 0, 0, 2],
  17492. ... [0, 3, 0, 0, 2, 0, 1],
  17493. ... [2, 2, 2, 0, 0, 0, 3],
  17494. ... [2, 2, 3, 0, 1, 1, 0],
  17495. ... [1, 1, 0, 0, 2, 0, 2]])
  17496. >>> torch.mode(b, 0)
  17497. torch.return_types.mode(
  17498. values=tensor([0, 2, 0, 0, 0, 0, 2]),
  17499. indices=tensor([1, 3, 4, 4, 2, 4, 4]))
  17500. """
  17501. @overload
  17502. def mode(
  17503. input: Tensor,
  17504. dim: str | EllipsisType | None,
  17505. keepdim: _bool = False,
  17506. *,
  17507. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  17508. ) -> torch.return_types.mode:
  17509. r"""
  17510. mode(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  17511. Returns a namedtuple ``(values, indices)`` where ``values`` is the mode
  17512. value of each row of the :attr:`input` tensor in the given dimension
  17513. :attr:`dim`, i.e. a value which appears most often
  17514. in that row, and ``indices`` is the index location of each mode value found.
  17515. By default, :attr:`dim` is the last dimension of the :attr:`input` tensor.
  17516. If :attr:`keepdim` is ``True``, the output tensors are of the same size as
  17517. :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  17518. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting
  17519. in the output tensors having 1 fewer dimension than :attr:`input`.
  17520. .. note:: This function is not defined for ``torch.cuda.Tensor`` yet.
  17521. Args:
  17522. input (Tensor): the input tensor.
  17523. dim (int, optional): the dimension to reduce.
  17524. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17525. Keyword args:
  17526. out (tuple, optional): the result tuple of two output tensors (values, indices)
  17527. Example::
  17528. >>> b = torch.tensor([[0, 0, 0, 2, 0, 0, 2],
  17529. ... [0, 3, 0, 0, 2, 0, 1],
  17530. ... [2, 2, 2, 0, 0, 0, 3],
  17531. ... [2, 2, 3, 0, 1, 1, 0],
  17532. ... [1, 1, 0, 0, 2, 0, 2]])
  17533. >>> torch.mode(b, 0)
  17534. torch.return_types.mode(
  17535. values=tensor([0, 2, 0, 0, 0, 0, 2]),
  17536. indices=tensor([1, 3, 4, 4, 2, 4, 4]))
  17537. """
  17538. @overload
  17539. def moveaxis(input: Tensor, source: _int, destination: _int) -> Tensor:
  17540. r"""
  17541. moveaxis(input, source, destination) -> Tensor
  17542. Alias for :func:`torch.movedim`.
  17543. This function is equivalent to NumPy's moveaxis function.
  17544. Examples::
  17545. >>> t = torch.randn(3,2,1)
  17546. >>> t
  17547. tensor([[[-0.3362],
  17548. [-0.8437]],
  17549. [[-0.9627],
  17550. [ 0.1727]],
  17551. [[ 0.5173],
  17552. [-0.1398]]])
  17553. >>> torch.moveaxis(t, 1, 0).shape
  17554. torch.Size([2, 3, 1])
  17555. >>> torch.moveaxis(t, 1, 0)
  17556. tensor([[[-0.3362],
  17557. [-0.9627],
  17558. [ 0.5173]],
  17559. [[-0.8437],
  17560. [ 0.1727],
  17561. [-0.1398]]])
  17562. >>> torch.moveaxis(t, (1, 2), (0, 1)).shape
  17563. torch.Size([2, 1, 3])
  17564. >>> torch.moveaxis(t, (1, 2), (0, 1))
  17565. tensor([[[-0.3362, -0.9627, 0.5173]],
  17566. [[-0.8437, 0.1727, -0.1398]]])
  17567. """
  17568. @overload
  17569. def moveaxis(input: Tensor, source: _size, destination: _size) -> Tensor:
  17570. r"""
  17571. moveaxis(input, source, destination) -> Tensor
  17572. Alias for :func:`torch.movedim`.
  17573. This function is equivalent to NumPy's moveaxis function.
  17574. Examples::
  17575. >>> t = torch.randn(3,2,1)
  17576. >>> t
  17577. tensor([[[-0.3362],
  17578. [-0.8437]],
  17579. [[-0.9627],
  17580. [ 0.1727]],
  17581. [[ 0.5173],
  17582. [-0.1398]]])
  17583. >>> torch.moveaxis(t, 1, 0).shape
  17584. torch.Size([2, 3, 1])
  17585. >>> torch.moveaxis(t, 1, 0)
  17586. tensor([[[-0.3362],
  17587. [-0.9627],
  17588. [ 0.5173]],
  17589. [[-0.8437],
  17590. [ 0.1727],
  17591. [-0.1398]]])
  17592. >>> torch.moveaxis(t, (1, 2), (0, 1)).shape
  17593. torch.Size([2, 1, 3])
  17594. >>> torch.moveaxis(t, (1, 2), (0, 1))
  17595. tensor([[[-0.3362, -0.9627, 0.5173]],
  17596. [[-0.8437, 0.1727, -0.1398]]])
  17597. """
  17598. @overload
  17599. def movedim(input: Tensor, source: _int, destination: _int) -> Tensor:
  17600. r"""
  17601. movedim(input, source, destination) -> Tensor
  17602. Moves the dimension(s) of :attr:`input` at the position(s) in :attr:`source`
  17603. to the position(s) in :attr:`destination`.
  17604. Other dimensions of :attr:`input` that are not explicitly moved remain in
  17605. their original order and appear at the positions not specified in :attr:`destination`.
  17606. Args:
  17607. input (Tensor): the input tensor.
  17608. source (int or tuple of ints): Original positions of the dims to move. These must be unique.
  17609. destination (int or tuple of ints): Destination positions for each of the original dims. These must also be unique.
  17610. Examples::
  17611. >>> t = torch.randn(3,2,1)
  17612. >>> t
  17613. tensor([[[-0.3362],
  17614. [-0.8437]],
  17615. [[-0.9627],
  17616. [ 0.1727]],
  17617. [[ 0.5173],
  17618. [-0.1398]]])
  17619. >>> torch.movedim(t, 1, 0).shape
  17620. torch.Size([2, 3, 1])
  17621. >>> torch.movedim(t, 1, 0)
  17622. tensor([[[-0.3362],
  17623. [-0.9627],
  17624. [ 0.5173]],
  17625. [[-0.8437],
  17626. [ 0.1727],
  17627. [-0.1398]]])
  17628. >>> torch.movedim(t, (1, 2), (0, 1)).shape
  17629. torch.Size([2, 1, 3])
  17630. >>> torch.movedim(t, (1, 2), (0, 1))
  17631. tensor([[[-0.3362, -0.9627, 0.5173]],
  17632. [[-0.8437, 0.1727, -0.1398]]])
  17633. """
  17634. @overload
  17635. def movedim(input: Tensor, source: _size, destination: _size) -> Tensor:
  17636. r"""
  17637. movedim(input, source, destination) -> Tensor
  17638. Moves the dimension(s) of :attr:`input` at the position(s) in :attr:`source`
  17639. to the position(s) in :attr:`destination`.
  17640. Other dimensions of :attr:`input` that are not explicitly moved remain in
  17641. their original order and appear at the positions not specified in :attr:`destination`.
  17642. Args:
  17643. input (Tensor): the input tensor.
  17644. source (int or tuple of ints): Original positions of the dims to move. These must be unique.
  17645. destination (int or tuple of ints): Destination positions for each of the original dims. These must also be unique.
  17646. Examples::
  17647. >>> t = torch.randn(3,2,1)
  17648. >>> t
  17649. tensor([[[-0.3362],
  17650. [-0.8437]],
  17651. [[-0.9627],
  17652. [ 0.1727]],
  17653. [[ 0.5173],
  17654. [-0.1398]]])
  17655. >>> torch.movedim(t, 1, 0).shape
  17656. torch.Size([2, 3, 1])
  17657. >>> torch.movedim(t, 1, 0)
  17658. tensor([[[-0.3362],
  17659. [-0.9627],
  17660. [ 0.5173]],
  17661. [[-0.8437],
  17662. [ 0.1727],
  17663. [-0.1398]]])
  17664. >>> torch.movedim(t, (1, 2), (0, 1)).shape
  17665. torch.Size([2, 1, 3])
  17666. >>> torch.movedim(t, (1, 2), (0, 1))
  17667. tensor([[[-0.3362, -0.9627, 0.5173]],
  17668. [[-0.8437, 0.1727, -0.1398]]])
  17669. """
  17670. def msort(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  17671. r"""
  17672. msort(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  17673. Sorts the elements of the :attr:`input` tensor along its first dimension
  17674. in ascending order by value.
  17675. .. note:: `torch.msort(t)` is equivalent to `torch.sort(t, dim=0)[0]`.
  17676. See also :func:`torch.sort`.
  17677. Args:
  17678. input (Tensor): the input tensor.
  17679. Keyword args:
  17680. out (Tensor, optional): the output tensor.
  17681. Example::
  17682. >>> t = torch.randn(3, 4)
  17683. >>> t
  17684. tensor([[-0.1321, 0.4370, -1.2631, -1.1289],
  17685. [-2.0527, -1.1250, 0.2275, 0.3077],
  17686. [-0.0881, -0.1259, -0.5495, 1.0284]])
  17687. >>> torch.msort(t)
  17688. tensor([[-2.0527, -1.1250, -1.2631, -1.1289],
  17689. [-0.1321, -0.1259, -0.5495, 0.3077],
  17690. [-0.0881, 0.4370, 0.2275, 1.0284]])
  17691. """
  17692. def mul(
  17693. input: Tensor | Number | _complex,
  17694. other: Tensor | Number | _complex,
  17695. *,
  17696. out: Tensor | None = None,
  17697. ) -> Tensor:
  17698. r"""
  17699. mul(input, other, *, out=None) -> Tensor
  17700. Multiplies :attr:`input` by :attr:`other`.
  17701. .. math::
  17702. \text{out}_i = \text{input}_i \times \text{other}_i
  17703. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  17704. :ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
  17705. Args:
  17706. input (Tensor): the input tensor.
  17707. other (Tensor or Number): the tensor or number to multiply input by.
  17708. Keyword args:
  17709. out (Tensor, optional): the output tensor.
  17710. Examples::
  17711. >>> a = torch.randn(3)
  17712. >>> a
  17713. tensor([ 0.2015, -0.4255, 2.6087])
  17714. >>> torch.mul(a, 100)
  17715. tensor([ 20.1494, -42.5491, 260.8663])
  17716. >>> b = torch.randn(4, 1)
  17717. >>> b
  17718. tensor([[ 1.1207],
  17719. [-0.3137],
  17720. [ 0.0700],
  17721. [ 0.8378]])
  17722. >>> c = torch.randn(1, 4)
  17723. >>> c
  17724. tensor([[ 0.5146, 0.1216, -0.5244, 2.2382]])
  17725. >>> torch.mul(b, c)
  17726. tensor([[ 0.5767, 0.1363, -0.5877, 2.5083],
  17727. [-0.1614, -0.0382, 0.1645, -0.7021],
  17728. [ 0.0360, 0.0085, -0.0367, 0.1567],
  17729. [ 0.4312, 0.1019, -0.4394, 1.8753]])
  17730. """
  17731. def multinomial(
  17732. input: Tensor,
  17733. num_samples: _int | SymInt,
  17734. replacement: _bool = False,
  17735. *,
  17736. generator: Generator | None = None,
  17737. out: Tensor | None = None,
  17738. ) -> Tensor:
  17739. r"""
  17740. multinomial(input, num_samples, replacement=False, *, generator=None, out=None) -> LongTensor
  17741. Returns a tensor where each row contains :attr:`num_samples` indices sampled
  17742. from the multinomial (a stricter definition would be multivariate,
  17743. refer to :class:`torch.distributions.multinomial.Multinomial` for more details)
  17744. probability distribution located in the corresponding row
  17745. of tensor :attr:`input`.
  17746. .. note::
  17747. The rows of :attr:`input` do not need to sum to one (in which case we use
  17748. the values as weights), but must be non-negative, finite and have
  17749. a non-zero sum.
  17750. Indices are ordered from left to right according to when each was sampled
  17751. (first samples are placed in first column).
  17752. If :attr:`input` is a vector, :attr:`out` is a vector of size :attr:`num_samples`.
  17753. If :attr:`input` is a matrix with `m` rows, :attr:`out` is an matrix of shape
  17754. :math:`(m \times \text{num\_samples})`.
  17755. If replacement is ``True``, samples are drawn with replacement.
  17756. If not, they are drawn without replacement, which means that when a
  17757. sample index is drawn for a row, it cannot be drawn again for that row.
  17758. .. note::
  17759. When drawn without replacement, :attr:`num_samples` must be lower than
  17760. number of non-zero elements in :attr:`input` (or the min number of non-zero
  17761. elements in each row of :attr:`input` if it is a matrix).
  17762. Args:
  17763. input (Tensor): the input tensor containing probabilities
  17764. num_samples (int): number of samples to draw
  17765. replacement (bool, optional): whether to draw with replacement or not
  17766. Keyword args:
  17767. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  17768. out (Tensor, optional): the output tensor.
  17769. Example::
  17770. >>> weights = torch.tensor([0, 10, 3, 0], dtype=torch.float) # create a tensor of weights
  17771. >>> torch.multinomial(weights, 2)
  17772. tensor([1, 2])
  17773. >>> torch.multinomial(weights, 5) # ERROR!
  17774. RuntimeError: cannot sample n_sample > prob_dist.size(-1) samples without replacement
  17775. >>> torch.multinomial(weights, 4, replacement=True)
  17776. tensor([ 2, 1, 1, 1])
  17777. """
  17778. @overload
  17779. def multiply(
  17780. input: Tensor,
  17781. other: Tensor,
  17782. *,
  17783. out: Tensor | None = None,
  17784. ) -> Tensor:
  17785. r"""
  17786. multiply(input, other, *, out=None)
  17787. Alias for :func:`torch.mul`.
  17788. """
  17789. @overload
  17790. def multiply(input: Tensor, other: Number | _complex) -> Tensor:
  17791. r"""
  17792. multiply(input, other, *, out=None)
  17793. Alias for :func:`torch.mul`.
  17794. """
  17795. def mv(input: Tensor, vec: Tensor, *, out: Tensor | None = None) -> Tensor:
  17796. r"""
  17797. mv(input, vec, *, out=None) -> Tensor
  17798. Performs a matrix-vector product of the matrix :attr:`input` and the vector
  17799. :attr:`vec`.
  17800. If :attr:`input` is a :math:`(n \times m)` tensor, :attr:`vec` is a 1-D tensor of
  17801. size :math:`m`, :attr:`out` will be 1-D of size :math:`n`.
  17802. .. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
  17803. Args:
  17804. input (Tensor): matrix to be multiplied
  17805. vec (Tensor): vector to be multiplied
  17806. Keyword args:
  17807. out (Tensor, optional): the output tensor.
  17808. Example::
  17809. >>> mat = torch.randn(2, 3)
  17810. >>> vec = torch.randn(3)
  17811. >>> torch.mv(mat, vec)
  17812. tensor([ 1.0404, -0.6361])
  17813. """
  17814. def mvlgamma(
  17815. input: Tensor,
  17816. p: _int,
  17817. *,
  17818. out: Tensor | None = None,
  17819. ) -> Tensor:
  17820. r"""
  17821. mvlgamma(input, p, *, out=None) -> Tensor
  17822. Alias for :func:`torch.special.multigammaln`.
  17823. """
  17824. def nan_to_num(
  17825. input: Tensor,
  17826. nan: _float | None = None,
  17827. posinf: _float | None = None,
  17828. neginf: _float | None = None,
  17829. *,
  17830. out: Tensor | None = None,
  17831. ) -> Tensor:
  17832. r"""
  17833. nan_to_num(input, nan=0.0, posinf=None, neginf=None, *, out=None) -> Tensor
  17834. Replaces :literal:`NaN`, positive infinity, and negative infinity values in :attr:`input`
  17835. with the values specified by :attr:`nan`, :attr:`posinf`, and :attr:`neginf`, respectively.
  17836. By default, :literal:`NaN`\ s are replaced with zero, positive infinity is replaced with the
  17837. greatest finite value representable by :attr:`input`'s dtype, and negative infinity
  17838. is replaced with the least finite value representable by :attr:`input`'s dtype.
  17839. Args:
  17840. input (Tensor): the input tensor.
  17841. nan (Number, optional): the value to replace :literal:`NaN`\s with. Default is zero.
  17842. posinf (Number, optional): if a Number, the value to replace positive infinity values with.
  17843. If None, positive infinity values are replaced with the greatest finite value representable by :attr:`input`'s dtype.
  17844. Default is None.
  17845. neginf (Number, optional): if a Number, the value to replace negative infinity values with.
  17846. If None, negative infinity values are replaced with the lowest finite value representable by :attr:`input`'s dtype.
  17847. Default is None.
  17848. Keyword args:
  17849. out (Tensor, optional): the output tensor.
  17850. Example::
  17851. >>> x = torch.tensor([float('nan'), float('inf'), -float('inf'), 3.14])
  17852. >>> torch.nan_to_num(x)
  17853. tensor([ 0.0000e+00, 3.4028e+38, -3.4028e+38, 3.1400e+00])
  17854. >>> torch.nan_to_num(x, nan=2.0)
  17855. tensor([ 2.0000e+00, 3.4028e+38, -3.4028e+38, 3.1400e+00])
  17856. >>> torch.nan_to_num(x, nan=2.0, posinf=1.0)
  17857. tensor([ 2.0000e+00, 1.0000e+00, -3.4028e+38, 3.1400e+00])
  17858. """
  17859. def nan_to_num_(
  17860. input: Tensor,
  17861. nan: _float | None = None,
  17862. posinf: _float | None = None,
  17863. neginf: _float | None = None,
  17864. ) -> Tensor: ...
  17865. def nanmean(
  17866. input: Tensor,
  17867. dim: _int | _size | None = None,
  17868. keepdim: _bool = False,
  17869. *,
  17870. dtype: _dtype | None = None,
  17871. out: Tensor | None = None,
  17872. ) -> Tensor:
  17873. r"""
  17874. nanmean(input, dim=None, keepdim=False, *, dtype=None, out=None) -> Tensor
  17875. Computes the mean of all `non-NaN` elements along the specified dimensions.
  17876. Input must be floating point or complex.
  17877. This function is identical to :func:`torch.mean` when there are no `NaN` values
  17878. in the :attr:`input` tensor. In the presence of `NaN`, :func:`torch.mean` will
  17879. propagate the `NaN` to the output whereas :func:`torch.nanmean` will ignore the
  17880. `NaN` values (`torch.nanmean(a)` is equivalent to `torch.mean(a[~a.isnan()])`).
  17881. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  17882. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  17883. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  17884. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  17885. Args:
  17886. input (Tensor): the input tensor, either of floating point or complex dtype
  17887. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  17888. If ``None``, all dimensions are reduced.
  17889. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17890. Keyword args:
  17891. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  17892. If specified, the input tensor is casted to :attr:`dtype` before the operation
  17893. is performed. This is useful for preventing data type overflows. Default: None.
  17894. out (Tensor, optional): the output tensor.
  17895. .. seealso::
  17896. :func:`torch.mean` computes the mean value, propagating `NaN`.
  17897. Example::
  17898. >>> x = torch.tensor([[torch.nan, 1, 2], [1, 2, 3]])
  17899. >>> x.mean()
  17900. tensor(nan)
  17901. >>> x.nanmean()
  17902. tensor(1.8000)
  17903. >>> x.mean(dim=0)
  17904. tensor([ nan, 1.5000, 2.5000])
  17905. >>> x.nanmean(dim=0)
  17906. tensor([1.0000, 1.5000, 2.5000])
  17907. # If all elements in the reduced dimensions are NaN then the result is NaN
  17908. >>> torch.tensor([torch.nan]).nanmean()
  17909. tensor(nan)
  17910. """
  17911. @overload
  17912. def nanmedian(input: Tensor) -> Tensor:
  17913. r"""
  17914. nanmedian(input) -> Tensor
  17915. Returns the median of the values in :attr:`input`, ignoring ``NaN`` values.
  17916. This function is identical to :func:`torch.median` when there are no ``NaN`` values in :attr:`input`.
  17917. When :attr:`input` has one or more ``NaN`` values, :func:`torch.median` will always return ``NaN``,
  17918. while this function will return the median of the non-``NaN`` elements in :attr:`input`.
  17919. If all the elements in :attr:`input` are ``NaN`` it will also return ``NaN``.
  17920. Args:
  17921. input (Tensor): the input tensor.
  17922. Example::
  17923. >>> a = torch.tensor([1, float('nan'), 3, 2])
  17924. >>> a.median()
  17925. tensor(nan)
  17926. >>> a.nanmedian()
  17927. tensor(2.)
  17928. .. function:: nanmedian(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  17929. :noindex:
  17930. Returns a namedtuple ``(values, indices)`` where ``values`` contains the median of each row of :attr:`input`
  17931. in the dimension :attr:`dim`, ignoring ``NaN`` values, and ``indices`` contains the index of the median values
  17932. found in the dimension :attr:`dim`.
  17933. This function is identical to :func:`torch.median` when there are no ``NaN`` values in a reduced row. When a reduced row has
  17934. one or more ``NaN`` values, :func:`torch.median` will always reduce it to ``NaN``, while this function will reduce it to the
  17935. median of the non-``NaN`` elements. If all the elements in a reduced row are ``NaN`` then it will be reduced to ``NaN``, too.
  17936. Args:
  17937. input (Tensor): the input tensor.
  17938. dim (int, optional): the dimension to reduce.
  17939. If ``None``, all dimensions are reduced.
  17940. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17941. Keyword args:
  17942. out ((Tensor, Tensor), optional): The first tensor will be populated with the median values and the second
  17943. tensor, which must have dtype long, with their indices in the dimension
  17944. :attr:`dim` of :attr:`input`.
  17945. Example::
  17946. >>> a = torch.tensor([[2, 3, 1], [float('nan'), 1, float('nan')]])
  17947. >>> a
  17948. tensor([[2., 3., 1.],
  17949. [nan, 1., nan]])
  17950. >>> a.median(0)
  17951. torch.return_types.median(values=tensor([nan, 1., nan]), indices=tensor([1, 1, 1]))
  17952. >>> a.nanmedian(0)
  17953. torch.return_types.nanmedian(values=tensor([2., 1., 1.]), indices=tensor([0, 1, 0]))
  17954. """
  17955. @overload
  17956. def nanmedian(
  17957. input: Tensor,
  17958. dim: _int,
  17959. keepdim: _bool = False,
  17960. *,
  17961. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  17962. ) -> torch.return_types.nanmedian:
  17963. r"""
  17964. nanmedian(input) -> Tensor
  17965. Returns the median of the values in :attr:`input`, ignoring ``NaN`` values.
  17966. This function is identical to :func:`torch.median` when there are no ``NaN`` values in :attr:`input`.
  17967. When :attr:`input` has one or more ``NaN`` values, :func:`torch.median` will always return ``NaN``,
  17968. while this function will return the median of the non-``NaN`` elements in :attr:`input`.
  17969. If all the elements in :attr:`input` are ``NaN`` it will also return ``NaN``.
  17970. Args:
  17971. input (Tensor): the input tensor.
  17972. Example::
  17973. >>> a = torch.tensor([1, float('nan'), 3, 2])
  17974. >>> a.median()
  17975. tensor(nan)
  17976. >>> a.nanmedian()
  17977. tensor(2.)
  17978. .. function:: nanmedian(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  17979. :noindex:
  17980. Returns a namedtuple ``(values, indices)`` where ``values`` contains the median of each row of :attr:`input`
  17981. in the dimension :attr:`dim`, ignoring ``NaN`` values, and ``indices`` contains the index of the median values
  17982. found in the dimension :attr:`dim`.
  17983. This function is identical to :func:`torch.median` when there are no ``NaN`` values in a reduced row. When a reduced row has
  17984. one or more ``NaN`` values, :func:`torch.median` will always reduce it to ``NaN``, while this function will reduce it to the
  17985. median of the non-``NaN`` elements. If all the elements in a reduced row are ``NaN`` then it will be reduced to ``NaN``, too.
  17986. Args:
  17987. input (Tensor): the input tensor.
  17988. dim (int, optional): the dimension to reduce.
  17989. If ``None``, all dimensions are reduced.
  17990. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17991. Keyword args:
  17992. out ((Tensor, Tensor), optional): The first tensor will be populated with the median values and the second
  17993. tensor, which must have dtype long, with their indices in the dimension
  17994. :attr:`dim` of :attr:`input`.
  17995. Example::
  17996. >>> a = torch.tensor([[2, 3, 1], [float('nan'), 1, float('nan')]])
  17997. >>> a
  17998. tensor([[2., 3., 1.],
  17999. [nan, 1., nan]])
  18000. >>> a.median(0)
  18001. torch.return_types.median(values=tensor([nan, 1., nan]), indices=tensor([1, 1, 1]))
  18002. >>> a.nanmedian(0)
  18003. torch.return_types.nanmedian(values=tensor([2., 1., 1.]), indices=tensor([0, 1, 0]))
  18004. """
  18005. @overload
  18006. def nanmedian(
  18007. input: Tensor,
  18008. dim: str | EllipsisType | None,
  18009. keepdim: _bool = False,
  18010. *,
  18011. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  18012. ) -> torch.return_types.nanmedian:
  18013. r"""
  18014. nanmedian(input) -> Tensor
  18015. Returns the median of the values in :attr:`input`, ignoring ``NaN`` values.
  18016. This function is identical to :func:`torch.median` when there are no ``NaN`` values in :attr:`input`.
  18017. When :attr:`input` has one or more ``NaN`` values, :func:`torch.median` will always return ``NaN``,
  18018. while this function will return the median of the non-``NaN`` elements in :attr:`input`.
  18019. If all the elements in :attr:`input` are ``NaN`` it will also return ``NaN``.
  18020. Args:
  18021. input (Tensor): the input tensor.
  18022. Example::
  18023. >>> a = torch.tensor([1, float('nan'), 3, 2])
  18024. >>> a.median()
  18025. tensor(nan)
  18026. >>> a.nanmedian()
  18027. tensor(2.)
  18028. .. function:: nanmedian(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  18029. :noindex:
  18030. Returns a namedtuple ``(values, indices)`` where ``values`` contains the median of each row of :attr:`input`
  18031. in the dimension :attr:`dim`, ignoring ``NaN`` values, and ``indices`` contains the index of the median values
  18032. found in the dimension :attr:`dim`.
  18033. This function is identical to :func:`torch.median` when there are no ``NaN`` values in a reduced row. When a reduced row has
  18034. one or more ``NaN`` values, :func:`torch.median` will always reduce it to ``NaN``, while this function will reduce it to the
  18035. median of the non-``NaN`` elements. If all the elements in a reduced row are ``NaN`` then it will be reduced to ``NaN``, too.
  18036. Args:
  18037. input (Tensor): the input tensor.
  18038. dim (int, optional): the dimension to reduce.
  18039. If ``None``, all dimensions are reduced.
  18040. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  18041. Keyword args:
  18042. out ((Tensor, Tensor), optional): The first tensor will be populated with the median values and the second
  18043. tensor, which must have dtype long, with their indices in the dimension
  18044. :attr:`dim` of :attr:`input`.
  18045. Example::
  18046. >>> a = torch.tensor([[2, 3, 1], [float('nan'), 1, float('nan')]])
  18047. >>> a
  18048. tensor([[2., 3., 1.],
  18049. [nan, 1., nan]])
  18050. >>> a.median(0)
  18051. torch.return_types.median(values=tensor([nan, 1., nan]), indices=tensor([1, 1, 1]))
  18052. >>> a.nanmedian(0)
  18053. torch.return_types.nanmedian(values=tensor([2., 1., 1.]), indices=tensor([0, 1, 0]))
  18054. """
  18055. @overload
  18056. def nanquantile(
  18057. input: Tensor,
  18058. q: Tensor,
  18059. dim: _int | None = None,
  18060. keepdim: _bool = False,
  18061. *,
  18062. interpolation: str = "linear",
  18063. out: Tensor | None = None,
  18064. ) -> Tensor:
  18065. r"""
  18066. nanquantile(input, q, dim=None, keepdim=False, *, interpolation='linear', out=None) -> Tensor
  18067. This is a variant of :func:`torch.quantile` that "ignores" ``NaN`` values,
  18068. computing the quantiles :attr:`q` as if ``NaN`` values in :attr:`input` did
  18069. not exist. If all values in a reduced row are ``NaN`` then the quantiles for
  18070. that reduction will be ``NaN``. See the documentation for :func:`torch.quantile`.
  18071. Args:
  18072. input (Tensor): the input tensor.
  18073. q (float or Tensor): a scalar or 1D tensor of quantile values in the range [0, 1]
  18074. dim (int, optional): the dimension to reduce.
  18075. If ``None``, all dimensions are reduced.
  18076. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  18077. Keyword arguments:
  18078. interpolation (str): interpolation method to use when the desired quantile lies between two data points.
  18079. Can be ``linear``, ``lower``, ``higher``, ``midpoint`` and ``nearest``.
  18080. Default is ``linear``.
  18081. out (Tensor, optional): the output tensor.
  18082. Example::
  18083. >>> t = torch.tensor([float('nan'), 1, 2])
  18084. >>> t.quantile(0.5)
  18085. tensor(nan)
  18086. >>> t.nanquantile(0.5)
  18087. tensor(1.5000)
  18088. >>> t = torch.tensor([[float('nan'), float('nan')], [1, 2]])
  18089. >>> t
  18090. tensor([[nan, nan],
  18091. [1., 2.]])
  18092. >>> t.nanquantile(0.5, dim=0)
  18093. tensor([1., 2.])
  18094. >>> t.nanquantile(0.5, dim=1)
  18095. tensor([ nan, 1.5000])
  18096. """
  18097. @overload
  18098. def nanquantile(
  18099. input: Tensor,
  18100. q: _float,
  18101. dim: _int | None = None,
  18102. keepdim: _bool = False,
  18103. *,
  18104. interpolation: str = "linear",
  18105. out: Tensor | None = None,
  18106. ) -> Tensor:
  18107. r"""
  18108. nanquantile(input, q, dim=None, keepdim=False, *, interpolation='linear', out=None) -> Tensor
  18109. This is a variant of :func:`torch.quantile` that "ignores" ``NaN`` values,
  18110. computing the quantiles :attr:`q` as if ``NaN`` values in :attr:`input` did
  18111. not exist. If all values in a reduced row are ``NaN`` then the quantiles for
  18112. that reduction will be ``NaN``. See the documentation for :func:`torch.quantile`.
  18113. Args:
  18114. input (Tensor): the input tensor.
  18115. q (float or Tensor): a scalar or 1D tensor of quantile values in the range [0, 1]
  18116. dim (int, optional): the dimension to reduce.
  18117. If ``None``, all dimensions are reduced.
  18118. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  18119. Keyword arguments:
  18120. interpolation (str): interpolation method to use when the desired quantile lies between two data points.
  18121. Can be ``linear``, ``lower``, ``higher``, ``midpoint`` and ``nearest``.
  18122. Default is ``linear``.
  18123. out (Tensor, optional): the output tensor.
  18124. Example::
  18125. >>> t = torch.tensor([float('nan'), 1, 2])
  18126. >>> t.quantile(0.5)
  18127. tensor(nan)
  18128. >>> t.nanquantile(0.5)
  18129. tensor(1.5000)
  18130. >>> t = torch.tensor([[float('nan'), float('nan')], [1, 2]])
  18131. >>> t
  18132. tensor([[nan, nan],
  18133. [1., 2.]])
  18134. >>> t.nanquantile(0.5, dim=0)
  18135. tensor([1., 2.])
  18136. >>> t.nanquantile(0.5, dim=1)
  18137. tensor([ nan, 1.5000])
  18138. """
  18139. def nansum(
  18140. input: Tensor,
  18141. dim: _int | _size | None = None,
  18142. keepdim: _bool = False,
  18143. *,
  18144. dtype: _dtype | None = None,
  18145. out: Tensor | None = None,
  18146. ) -> Tensor:
  18147. r"""
  18148. nansum(input, *, dtype=None) -> Tensor
  18149. Returns the sum of all elements, treating Not a Numbers (NaNs) as zero.
  18150. Args:
  18151. input (Tensor): the input tensor.
  18152. Keyword args:
  18153. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  18154. If specified, the input tensor is casted to :attr:`dtype` before the operation
  18155. is performed. This is useful for preventing data type overflows. Default: None.
  18156. Example::
  18157. >>> a = torch.tensor([1., 2., float('nan'), 4.])
  18158. >>> torch.nansum(a)
  18159. tensor(7.)
  18160. .. function:: nansum(input, dim, keepdim=False, *, dtype=None) -> Tensor
  18161. :noindex:
  18162. Returns the sum of each row of the :attr:`input` tensor in the given
  18163. dimension :attr:`dim`, treating Not a Numbers (NaNs) as zero.
  18164. If :attr:`dim` is a list of dimensions, reduce over all of them.
  18165. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  18166. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  18167. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  18168. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  18169. Args:
  18170. input (Tensor): the input tensor.
  18171. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  18172. If ``None``, all dimensions are reduced.
  18173. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  18174. Keyword args:
  18175. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  18176. If specified, the input tensor is casted to :attr:`dtype` before the operation
  18177. is performed. This is useful for preventing data type overflows. Default: None.
  18178. Example::
  18179. >>> torch.nansum(torch.tensor([1., float("nan")]))
  18180. tensor(1.)
  18181. >>> a = torch.tensor([[1, 2], [3., float("nan")]])
  18182. >>> torch.nansum(a)
  18183. tensor(6.)
  18184. >>> torch.nansum(a, dim=0)
  18185. tensor([4., 2.])
  18186. >>> torch.nansum(a, dim=1)
  18187. tensor([3., 3.])
  18188. """
  18189. @overload
  18190. def narrow(
  18191. input: Tensor,
  18192. dim: _int,
  18193. start: Tensor,
  18194. length: _int | SymInt,
  18195. ) -> Tensor:
  18196. r"""
  18197. narrow(input, dim, start, length) -> Tensor
  18198. Returns a new tensor that is a narrowed version of :attr:`input` tensor. The
  18199. dimension :attr:`dim` is input from :attr:`start` to ``start + length``. The
  18200. returned tensor and :attr:`input` tensor share the same underlying storage.
  18201. Args:
  18202. input (Tensor): the tensor to narrow
  18203. dim (int): the dimension along which to narrow
  18204. start (int or Tensor): index of the element to start the narrowed dimension
  18205. from. Can be negative, which means indexing from the end of `dim`. If
  18206. `Tensor`, it must be an 0-dim integral `Tensor` (bools not allowed)
  18207. length (int): length of the narrowed dimension, must be weakly positive
  18208. Example::
  18209. >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
  18210. >>> torch.narrow(x, 0, 0, 2)
  18211. tensor([[ 1, 2, 3],
  18212. [ 4, 5, 6]])
  18213. >>> torch.narrow(x, 1, 1, 2)
  18214. tensor([[ 2, 3],
  18215. [ 5, 6],
  18216. [ 8, 9]])
  18217. >>> torch.narrow(x, -1, torch.tensor(-1), 1)
  18218. tensor([[3],
  18219. [6],
  18220. [9]])
  18221. """
  18222. @overload
  18223. def narrow(
  18224. input: Tensor,
  18225. dim: _int,
  18226. start: _int | SymInt,
  18227. length: _int | SymInt,
  18228. ) -> Tensor:
  18229. r"""
  18230. narrow(input, dim, start, length) -> Tensor
  18231. Returns a new tensor that is a narrowed version of :attr:`input` tensor. The
  18232. dimension :attr:`dim` is input from :attr:`start` to ``start + length``. The
  18233. returned tensor and :attr:`input` tensor share the same underlying storage.
  18234. Args:
  18235. input (Tensor): the tensor to narrow
  18236. dim (int): the dimension along which to narrow
  18237. start (int or Tensor): index of the element to start the narrowed dimension
  18238. from. Can be negative, which means indexing from the end of `dim`. If
  18239. `Tensor`, it must be an 0-dim integral `Tensor` (bools not allowed)
  18240. length (int): length of the narrowed dimension, must be weakly positive
  18241. Example::
  18242. >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
  18243. >>> torch.narrow(x, 0, 0, 2)
  18244. tensor([[ 1, 2, 3],
  18245. [ 4, 5, 6]])
  18246. >>> torch.narrow(x, 1, 1, 2)
  18247. tensor([[ 2, 3],
  18248. [ 5, 6],
  18249. [ 8, 9]])
  18250. >>> torch.narrow(x, -1, torch.tensor(-1), 1)
  18251. tensor([[3],
  18252. [6],
  18253. [9]])
  18254. """
  18255. def narrow_copy(
  18256. input: Tensor,
  18257. dim: _int,
  18258. start: _int | SymInt,
  18259. length: _int | SymInt,
  18260. *,
  18261. out: Tensor | None = None,
  18262. ) -> Tensor:
  18263. r"""
  18264. narrow_copy(input, dim, start, length, *, out=None) -> Tensor
  18265. Same as :meth:`Tensor.narrow` except this returns a copy rather
  18266. than shared storage. This is primarily for sparse tensors, which
  18267. do not have a shared-storage narrow method.
  18268. Args:
  18269. input (Tensor): the tensor to narrow
  18270. dim (int): the dimension along which to narrow
  18271. start (int): index of the element to start the narrowed dimension from. Can
  18272. be negative, which means indexing from the end of `dim`
  18273. length (int): length of the narrowed dimension, must be weakly positive
  18274. Keyword args:
  18275. out (Tensor, optional): the output tensor.
  18276. Example::
  18277. >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
  18278. >>> torch.narrow_copy(x, 0, 0, 2)
  18279. tensor([[ 1, 2, 3],
  18280. [ 4, 5, 6]])
  18281. >>> torch.narrow_copy(x, 1, 1, 2)
  18282. tensor([[ 2, 3],
  18283. [ 5, 6],
  18284. [ 8, 9]])
  18285. >>> s = torch.arange(16).reshape(2, 2, 2, 2).to_sparse(2)
  18286. >>> torch.narrow_copy(s, 0, 0, 1)
  18287. tensor(indices=tensor([[0, 0],
  18288. [0, 1]]),
  18289. values=tensor([[[0, 1],
  18290. [2, 3]],
  18291. [[4, 5],
  18292. [6, 7]]]),
  18293. size=(1, 2, 2, 2), nnz=2, layout=torch.sparse_coo)
  18294. .. seealso::
  18295. :func:`torch.narrow` for a non copy variant
  18296. """
  18297. def native_batch_norm(
  18298. input: Tensor,
  18299. weight: Tensor | None,
  18300. bias: Tensor | None,
  18301. running_mean: Tensor | None,
  18302. running_var: Tensor | None,
  18303. training: _bool,
  18304. momentum: _float,
  18305. eps: _float,
  18306. *,
  18307. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  18308. ) -> tuple[Tensor, Tensor, Tensor]: ...
  18309. def native_channel_shuffle(input: Tensor, groups: _int | SymInt) -> Tensor: ...
  18310. def native_dropout(
  18311. input: Tensor,
  18312. p: _float,
  18313. train: _bool | None,
  18314. ) -> tuple[Tensor, Tensor]: ...
  18315. def native_group_norm(
  18316. input: Tensor,
  18317. weight: Tensor | None,
  18318. bias: Tensor | None,
  18319. N: _int | SymInt,
  18320. C: _int | SymInt,
  18321. HxW: _int | SymInt,
  18322. group: _int,
  18323. eps: _float,
  18324. ) -> tuple[Tensor, Tensor, Tensor]: ...
  18325. def native_layer_norm(
  18326. input: Tensor,
  18327. normalized_shape: Sequence[_int | SymInt],
  18328. weight: Tensor | None,
  18329. bias: Tensor | None,
  18330. eps: _float,
  18331. ) -> tuple[Tensor, Tensor, Tensor]: ...
  18332. @overload
  18333. def native_norm(
  18334. input: Tensor,
  18335. p: Number | _complex | None,
  18336. dim: _int | _size,
  18337. keepdim: _bool,
  18338. dtype: _dtype | None,
  18339. ) -> Tensor: ...
  18340. @overload
  18341. def native_norm(input: Tensor, p: Number | _complex = 2) -> Tensor: ...
  18342. @overload
  18343. def ne(
  18344. input: Tensor,
  18345. other: Tensor,
  18346. *,
  18347. out: Tensor | None = None,
  18348. ) -> Tensor:
  18349. r"""
  18350. ne(input, other, *, out=None) -> Tensor
  18351. Computes :math:`\text{input} \neq \text{other}` element-wise.
  18352. The second argument can be a number or a tensor whose shape is
  18353. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  18354. Args:
  18355. input (Tensor): the tensor to compare
  18356. other (Tensor or float): the tensor or value to compare
  18357. Keyword args:
  18358. out (Tensor, optional): the output tensor.
  18359. Returns:
  18360. A boolean tensor that is True where :attr:`input` is not equal to :attr:`other` and False elsewhere
  18361. Example::
  18362. >>> torch.ne(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  18363. tensor([[False, True], [True, False]])
  18364. """
  18365. @overload
  18366. def ne(
  18367. input: Tensor,
  18368. other: Number | _complex,
  18369. *,
  18370. out: Tensor | None = None,
  18371. ) -> Tensor:
  18372. r"""
  18373. ne(input, other, *, out=None) -> Tensor
  18374. Computes :math:`\text{input} \neq \text{other}` element-wise.
  18375. The second argument can be a number or a tensor whose shape is
  18376. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  18377. Args:
  18378. input (Tensor): the tensor to compare
  18379. other (Tensor or float): the tensor or value to compare
  18380. Keyword args:
  18381. out (Tensor, optional): the output tensor.
  18382. Returns:
  18383. A boolean tensor that is True where :attr:`input` is not equal to :attr:`other` and False elsewhere
  18384. Example::
  18385. >>> torch.ne(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  18386. tensor([[False, True], [True, False]])
  18387. """
  18388. def neg(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  18389. r"""
  18390. neg(input, *, out=None) -> Tensor
  18391. Returns a new tensor with the negative of the elements of :attr:`input`.
  18392. .. math::
  18393. \text{out} = -1 \times \text{input}
  18394. Args:
  18395. input (Tensor): the input tensor.
  18396. Keyword args:
  18397. out (Tensor, optional): the output tensor.
  18398. Example::
  18399. >>> a = torch.randn(5)
  18400. >>> a
  18401. tensor([ 0.0090, -0.2262, -0.0682, -0.2866, 0.3940])
  18402. >>> torch.neg(a)
  18403. tensor([-0.0090, 0.2262, 0.0682, 0.2866, -0.3940])
  18404. """
  18405. def neg_(input: Tensor) -> Tensor: ...
  18406. def negative(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  18407. r"""
  18408. negative(input, *, out=None) -> Tensor
  18409. Alias for :func:`torch.neg`
  18410. """
  18411. def negative_(input: Tensor) -> Tensor: ...
  18412. def nextafter(
  18413. input: Tensor,
  18414. other: Tensor,
  18415. *,
  18416. out: Tensor | None = None,
  18417. ) -> Tensor:
  18418. r"""
  18419. nextafter(input, other, *, out=None) -> Tensor
  18420. Return the next floating-point value after :attr:`input` towards :attr:`other`, elementwise.
  18421. The shapes of ``input`` and ``other`` must be
  18422. :ref:`broadcastable <broadcasting-semantics>`.
  18423. Args:
  18424. input (Tensor): the first input tensor
  18425. other (Tensor): the second input tensor
  18426. Keyword args:
  18427. out (Tensor, optional): the output tensor.
  18428. Example::
  18429. >>> eps = torch.finfo(torch.float32).eps
  18430. >>> torch.nextafter(torch.tensor([1.0, 2.0]), torch.tensor([2.0, 1.0])) == torch.tensor([eps + 1, 2 - eps])
  18431. tensor([True, True])
  18432. """
  18433. @overload
  18434. def nonzero(
  18435. input: Tensor,
  18436. *,
  18437. as_tuple: Literal[False] = False,
  18438. out: Tensor | None = None,
  18439. ) -> Tensor:
  18440. r"""
  18441. nonzero(input, *, out=None, as_tuple=False) -> LongTensor or tuple of LongTensors
  18442. .. note::
  18443. :func:`torch.nonzero(..., as_tuple=False) <torch.nonzero>` (default) returns a
  18444. 2-D tensor where each row is the index for a nonzero value.
  18445. :func:`torch.nonzero(..., as_tuple=True) <torch.nonzero>` returns a tuple of 1-D
  18446. index tensors, allowing for advanced indexing, so ``x[x.nonzero(as_tuple=True)]``
  18447. gives all nonzero values of tensor ``x``. Of the returned tuple, each index tensor
  18448. contains nonzero indices for a certain dimension.
  18449. See below for more details on the two behaviors.
  18450. When :attr:`input` is on CUDA, :func:`torch.nonzero() <torch.nonzero>` causes
  18451. host-device synchronization.
  18452. **When** :attr:`as_tuple` **is** ``False`` **(default)**:
  18453. Returns a tensor containing the indices of all non-zero elements of
  18454. :attr:`input`. Each row in the result contains the indices of a non-zero
  18455. element in :attr:`input`. The result is sorted lexicographically, with
  18456. the last index changing the fastest (C-style).
  18457. If :attr:`input` has :math:`n` dimensions, then the resulting indices tensor
  18458. :attr:`out` is of size :math:`(z \times n)`, where :math:`z` is the total number of
  18459. non-zero elements in the :attr:`input` tensor.
  18460. **When** :attr:`as_tuple` **is** ``True``:
  18461. Returns a tuple of 1-D tensors, one for each dimension in :attr:`input`,
  18462. each containing the indices (in that dimension) of all non-zero elements of
  18463. :attr:`input` .
  18464. If :attr:`input` has :math:`n` dimensions, then the resulting tuple contains :math:`n`
  18465. tensors of size :math:`z`, where :math:`z` is the total number of
  18466. non-zero elements in the :attr:`input` tensor.
  18467. As a special case, when :attr:`input` has zero dimensions and a nonzero scalar
  18468. value, it is treated as a one-dimensional tensor with one element.
  18469. Args:
  18470. input (Tensor): the input tensor.
  18471. Keyword args:
  18472. out (LongTensor, optional): the output tensor containing indices
  18473. Returns:
  18474. LongTensor or tuple of LongTensor: If :attr:`as_tuple` is ``False``, the output
  18475. tensor containing indices. If :attr:`as_tuple` is ``True``, one 1-D tensor for
  18476. each dimension, containing the indices of each nonzero element along that
  18477. dimension.
  18478. Example::
  18479. >>> torch.nonzero(torch.tensor([1, 1, 1, 0, 1]))
  18480. tensor([[ 0],
  18481. [ 1],
  18482. [ 2],
  18483. [ 4]])
  18484. >>> torch.nonzero(torch.tensor([[0.6, 0.0, 0.0, 0.0],
  18485. ... [0.0, 0.4, 0.0, 0.0],
  18486. ... [0.0, 0.0, 1.2, 0.0],
  18487. ... [0.0, 0.0, 0.0,-0.4]]))
  18488. tensor([[ 0, 0],
  18489. [ 1, 1],
  18490. [ 2, 2],
  18491. [ 3, 3]])
  18492. >>> torch.nonzero(torch.tensor([1, 1, 1, 0, 1]), as_tuple=True)
  18493. (tensor([0, 1, 2, 4]),)
  18494. >>> torch.nonzero(torch.tensor([[0.6, 0.0, 0.0, 0.0],
  18495. ... [0.0, 0.4, 0.0, 0.0],
  18496. ... [0.0, 0.0, 1.2, 0.0],
  18497. ... [0.0, 0.0, 0.0,-0.4]]), as_tuple=True)
  18498. (tensor([0, 1, 2, 3]), tensor([0, 1, 2, 3]))
  18499. >>> torch.nonzero(torch.tensor(5), as_tuple=True)
  18500. (tensor([0]),)
  18501. """
  18502. @overload
  18503. def nonzero(
  18504. input: Tensor,
  18505. *,
  18506. as_tuple: Literal[True],
  18507. ) -> tuple[Tensor, ...]:
  18508. r"""
  18509. nonzero(input, *, out=None, as_tuple=False) -> LongTensor or tuple of LongTensors
  18510. .. note::
  18511. :func:`torch.nonzero(..., as_tuple=False) <torch.nonzero>` (default) returns a
  18512. 2-D tensor where each row is the index for a nonzero value.
  18513. :func:`torch.nonzero(..., as_tuple=True) <torch.nonzero>` returns a tuple of 1-D
  18514. index tensors, allowing for advanced indexing, so ``x[x.nonzero(as_tuple=True)]``
  18515. gives all nonzero values of tensor ``x``. Of the returned tuple, each index tensor
  18516. contains nonzero indices for a certain dimension.
  18517. See below for more details on the two behaviors.
  18518. When :attr:`input` is on CUDA, :func:`torch.nonzero() <torch.nonzero>` causes
  18519. host-device synchronization.
  18520. **When** :attr:`as_tuple` **is** ``False`` **(default)**:
  18521. Returns a tensor containing the indices of all non-zero elements of
  18522. :attr:`input`. Each row in the result contains the indices of a non-zero
  18523. element in :attr:`input`. The result is sorted lexicographically, with
  18524. the last index changing the fastest (C-style).
  18525. If :attr:`input` has :math:`n` dimensions, then the resulting indices tensor
  18526. :attr:`out` is of size :math:`(z \times n)`, where :math:`z` is the total number of
  18527. non-zero elements in the :attr:`input` tensor.
  18528. **When** :attr:`as_tuple` **is** ``True``:
  18529. Returns a tuple of 1-D tensors, one for each dimension in :attr:`input`,
  18530. each containing the indices (in that dimension) of all non-zero elements of
  18531. :attr:`input` .
  18532. If :attr:`input` has :math:`n` dimensions, then the resulting tuple contains :math:`n`
  18533. tensors of size :math:`z`, where :math:`z` is the total number of
  18534. non-zero elements in the :attr:`input` tensor.
  18535. As a special case, when :attr:`input` has zero dimensions and a nonzero scalar
  18536. value, it is treated as a one-dimensional tensor with one element.
  18537. Args:
  18538. input (Tensor): the input tensor.
  18539. Keyword args:
  18540. out (LongTensor, optional): the output tensor containing indices
  18541. Returns:
  18542. LongTensor or tuple of LongTensor: If :attr:`as_tuple` is ``False``, the output
  18543. tensor containing indices. If :attr:`as_tuple` is ``True``, one 1-D tensor for
  18544. each dimension, containing the indices of each nonzero element along that
  18545. dimension.
  18546. Example::
  18547. >>> torch.nonzero(torch.tensor([1, 1, 1, 0, 1]))
  18548. tensor([[ 0],
  18549. [ 1],
  18550. [ 2],
  18551. [ 4]])
  18552. >>> torch.nonzero(torch.tensor([[0.6, 0.0, 0.0, 0.0],
  18553. ... [0.0, 0.4, 0.0, 0.0],
  18554. ... [0.0, 0.0, 1.2, 0.0],
  18555. ... [0.0, 0.0, 0.0,-0.4]]))
  18556. tensor([[ 0, 0],
  18557. [ 1, 1],
  18558. [ 2, 2],
  18559. [ 3, 3]])
  18560. >>> torch.nonzero(torch.tensor([1, 1, 1, 0, 1]), as_tuple=True)
  18561. (tensor([0, 1, 2, 4]),)
  18562. >>> torch.nonzero(torch.tensor([[0.6, 0.0, 0.0, 0.0],
  18563. ... [0.0, 0.4, 0.0, 0.0],
  18564. ... [0.0, 0.0, 1.2, 0.0],
  18565. ... [0.0, 0.0, 0.0,-0.4]]), as_tuple=True)
  18566. (tensor([0, 1, 2, 3]), tensor([0, 1, 2, 3]))
  18567. >>> torch.nonzero(torch.tensor(5), as_tuple=True)
  18568. (tensor([0]),)
  18569. """
  18570. def nonzero_static(
  18571. input: Tensor,
  18572. *,
  18573. size: _int | SymInt,
  18574. fill_value: _int = -1,
  18575. out: Tensor | None = None,
  18576. ) -> Tensor: ...
  18577. def norm_except_dim(v: Tensor, pow: _int = 2, dim: _int = 0) -> Tensor: ...
  18578. @overload
  18579. def normal(
  18580. mean: Tensor,
  18581. std: Tensor,
  18582. *,
  18583. generator: Generator | None = None,
  18584. out: Tensor | None = None,
  18585. ) -> Tensor:
  18586. r"""
  18587. normal(mean, std, *, generator=None, out=None) -> Tensor
  18588. Returns a tensor of random numbers drawn from separate normal distributions
  18589. whose mean and standard deviation are given.
  18590. The :attr:`mean` is a tensor with the mean of
  18591. each output element's normal distribution
  18592. The :attr:`std` is a tensor with the standard deviation of
  18593. each output element's normal distribution
  18594. The shapes of :attr:`mean` and :attr:`std` don't need to match, but the
  18595. total number of elements in each tensor need to be the same.
  18596. .. note:: When the shapes do not match, the shape of :attr:`mean`
  18597. is used as the shape for the returned output tensor
  18598. .. note:: When :attr:`std` is a CUDA tensor, this function synchronizes
  18599. its device with the CPU.
  18600. Args:
  18601. mean (Tensor): the tensor of per-element means
  18602. std (Tensor): the tensor of per-element standard deviations
  18603. Keyword args:
  18604. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  18605. out (Tensor, optional): the output tensor.
  18606. Example::
  18607. >>> torch.normal(mean=torch.arange(1., 11.), std=torch.arange(1, 0, -0.1))
  18608. tensor([ 1.0425, 3.5672, 2.7969, 4.2925, 4.7229, 6.2134,
  18609. 8.0505, 8.1408, 9.0563, 10.0566])
  18610. .. function:: normal(mean=0.0, std, *, out=None) -> Tensor
  18611. :noindex:
  18612. Similar to the function above, but the means are shared among all drawn
  18613. elements.
  18614. Args:
  18615. mean (float, optional): the mean for all distributions
  18616. std (Tensor): the tensor of per-element standard deviations
  18617. Keyword args:
  18618. out (Tensor, optional): the output tensor.
  18619. Example::
  18620. >>> torch.normal(mean=0.5, std=torch.arange(1., 6.))
  18621. tensor([-1.2793, -1.0732, -2.0687, 5.1177, -1.2303])
  18622. .. function:: normal(mean, std=1.0, *, out=None) -> Tensor
  18623. :noindex:
  18624. Similar to the function above, but the standard deviations are shared among
  18625. all drawn elements.
  18626. Args:
  18627. mean (Tensor): the tensor of per-element means
  18628. std (float, optional): the standard deviation for all distributions
  18629. Keyword args:
  18630. out (Tensor, optional): the output tensor
  18631. Example::
  18632. >>> torch.normal(mean=torch.arange(1., 6.))
  18633. tensor([ 1.1552, 2.6148, 2.6535, 5.8318, 4.2361])
  18634. .. function:: normal(mean, std, size, *, out=None) -> Tensor
  18635. :noindex:
  18636. Similar to the function above, but the means and standard deviations are shared
  18637. among all drawn elements. The resulting tensor has size given by :attr:`size`.
  18638. Args:
  18639. mean (float): the mean for all distributions
  18640. std (float): the standard deviation for all distributions
  18641. size (int...): a sequence of integers defining the shape of the output tensor.
  18642. Keyword args:
  18643. out (Tensor, optional): the output tensor.
  18644. Example::
  18645. >>> torch.normal(2, 3, size=(1, 4))
  18646. tensor([[-1.3987, -1.9544, 3.6048, 0.7909]])
  18647. """
  18648. @overload
  18649. def normal(
  18650. mean: Tensor,
  18651. std: _float = 1,
  18652. *,
  18653. generator: Generator | None = None,
  18654. out: Tensor | None = None,
  18655. ) -> Tensor:
  18656. r"""
  18657. normal(mean, std, *, generator=None, out=None) -> Tensor
  18658. Returns a tensor of random numbers drawn from separate normal distributions
  18659. whose mean and standard deviation are given.
  18660. The :attr:`mean` is a tensor with the mean of
  18661. each output element's normal distribution
  18662. The :attr:`std` is a tensor with the standard deviation of
  18663. each output element's normal distribution
  18664. The shapes of :attr:`mean` and :attr:`std` don't need to match, but the
  18665. total number of elements in each tensor need to be the same.
  18666. .. note:: When the shapes do not match, the shape of :attr:`mean`
  18667. is used as the shape for the returned output tensor
  18668. .. note:: When :attr:`std` is a CUDA tensor, this function synchronizes
  18669. its device with the CPU.
  18670. Args:
  18671. mean (Tensor): the tensor of per-element means
  18672. std (Tensor): the tensor of per-element standard deviations
  18673. Keyword args:
  18674. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  18675. out (Tensor, optional): the output tensor.
  18676. Example::
  18677. >>> torch.normal(mean=torch.arange(1., 11.), std=torch.arange(1, 0, -0.1))
  18678. tensor([ 1.0425, 3.5672, 2.7969, 4.2925, 4.7229, 6.2134,
  18679. 8.0505, 8.1408, 9.0563, 10.0566])
  18680. .. function:: normal(mean=0.0, std, *, out=None) -> Tensor
  18681. :noindex:
  18682. Similar to the function above, but the means are shared among all drawn
  18683. elements.
  18684. Args:
  18685. mean (float, optional): the mean for all distributions
  18686. std (Tensor): the tensor of per-element standard deviations
  18687. Keyword args:
  18688. out (Tensor, optional): the output tensor.
  18689. Example::
  18690. >>> torch.normal(mean=0.5, std=torch.arange(1., 6.))
  18691. tensor([-1.2793, -1.0732, -2.0687, 5.1177, -1.2303])
  18692. .. function:: normal(mean, std=1.0, *, out=None) -> Tensor
  18693. :noindex:
  18694. Similar to the function above, but the standard deviations are shared among
  18695. all drawn elements.
  18696. Args:
  18697. mean (Tensor): the tensor of per-element means
  18698. std (float, optional): the standard deviation for all distributions
  18699. Keyword args:
  18700. out (Tensor, optional): the output tensor
  18701. Example::
  18702. >>> torch.normal(mean=torch.arange(1., 6.))
  18703. tensor([ 1.1552, 2.6148, 2.6535, 5.8318, 4.2361])
  18704. .. function:: normal(mean, std, size, *, out=None) -> Tensor
  18705. :noindex:
  18706. Similar to the function above, but the means and standard deviations are shared
  18707. among all drawn elements. The resulting tensor has size given by :attr:`size`.
  18708. Args:
  18709. mean (float): the mean for all distributions
  18710. std (float): the standard deviation for all distributions
  18711. size (int...): a sequence of integers defining the shape of the output tensor.
  18712. Keyword args:
  18713. out (Tensor, optional): the output tensor.
  18714. Example::
  18715. >>> torch.normal(2, 3, size=(1, 4))
  18716. tensor([[-1.3987, -1.9544, 3.6048, 0.7909]])
  18717. """
  18718. @overload
  18719. def normal(
  18720. mean: _float,
  18721. std: Tensor,
  18722. *,
  18723. generator: Generator | None = None,
  18724. out: Tensor | None = None,
  18725. ) -> Tensor:
  18726. r"""
  18727. normal(mean, std, *, generator=None, out=None) -> Tensor
  18728. Returns a tensor of random numbers drawn from separate normal distributions
  18729. whose mean and standard deviation are given.
  18730. The :attr:`mean` is a tensor with the mean of
  18731. each output element's normal distribution
  18732. The :attr:`std` is a tensor with the standard deviation of
  18733. each output element's normal distribution
  18734. The shapes of :attr:`mean` and :attr:`std` don't need to match, but the
  18735. total number of elements in each tensor need to be the same.
  18736. .. note:: When the shapes do not match, the shape of :attr:`mean`
  18737. is used as the shape for the returned output tensor
  18738. .. note:: When :attr:`std` is a CUDA tensor, this function synchronizes
  18739. its device with the CPU.
  18740. Args:
  18741. mean (Tensor): the tensor of per-element means
  18742. std (Tensor): the tensor of per-element standard deviations
  18743. Keyword args:
  18744. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  18745. out (Tensor, optional): the output tensor.
  18746. Example::
  18747. >>> torch.normal(mean=torch.arange(1., 11.), std=torch.arange(1, 0, -0.1))
  18748. tensor([ 1.0425, 3.5672, 2.7969, 4.2925, 4.7229, 6.2134,
  18749. 8.0505, 8.1408, 9.0563, 10.0566])
  18750. .. function:: normal(mean=0.0, std, *, out=None) -> Tensor
  18751. :noindex:
  18752. Similar to the function above, but the means are shared among all drawn
  18753. elements.
  18754. Args:
  18755. mean (float, optional): the mean for all distributions
  18756. std (Tensor): the tensor of per-element standard deviations
  18757. Keyword args:
  18758. out (Tensor, optional): the output tensor.
  18759. Example::
  18760. >>> torch.normal(mean=0.5, std=torch.arange(1., 6.))
  18761. tensor([-1.2793, -1.0732, -2.0687, 5.1177, -1.2303])
  18762. .. function:: normal(mean, std=1.0, *, out=None) -> Tensor
  18763. :noindex:
  18764. Similar to the function above, but the standard deviations are shared among
  18765. all drawn elements.
  18766. Args:
  18767. mean (Tensor): the tensor of per-element means
  18768. std (float, optional): the standard deviation for all distributions
  18769. Keyword args:
  18770. out (Tensor, optional): the output tensor
  18771. Example::
  18772. >>> torch.normal(mean=torch.arange(1., 6.))
  18773. tensor([ 1.1552, 2.6148, 2.6535, 5.8318, 4.2361])
  18774. .. function:: normal(mean, std, size, *, out=None) -> Tensor
  18775. :noindex:
  18776. Similar to the function above, but the means and standard deviations are shared
  18777. among all drawn elements. The resulting tensor has size given by :attr:`size`.
  18778. Args:
  18779. mean (float): the mean for all distributions
  18780. std (float): the standard deviation for all distributions
  18781. size (int...): a sequence of integers defining the shape of the output tensor.
  18782. Keyword args:
  18783. out (Tensor, optional): the output tensor.
  18784. Example::
  18785. >>> torch.normal(2, 3, size=(1, 4))
  18786. tensor([[-1.3987, -1.9544, 3.6048, 0.7909]])
  18787. """
  18788. @overload
  18789. def normal(
  18790. mean: _float,
  18791. std: _float,
  18792. size: Sequence[_int | SymInt],
  18793. *,
  18794. generator: Generator | None = None,
  18795. out: Tensor | None = None,
  18796. dtype: _dtype | None = None,
  18797. layout: _layout | None = None,
  18798. device: DeviceLikeType | None = None,
  18799. pin_memory: _bool | None = False,
  18800. requires_grad: _bool | None = False,
  18801. ) -> Tensor:
  18802. r"""
  18803. normal(mean, std, *, generator=None, out=None) -> Tensor
  18804. Returns a tensor of random numbers drawn from separate normal distributions
  18805. whose mean and standard deviation are given.
  18806. The :attr:`mean` is a tensor with the mean of
  18807. each output element's normal distribution
  18808. The :attr:`std` is a tensor with the standard deviation of
  18809. each output element's normal distribution
  18810. The shapes of :attr:`mean` and :attr:`std` don't need to match, but the
  18811. total number of elements in each tensor need to be the same.
  18812. .. note:: When the shapes do not match, the shape of :attr:`mean`
  18813. is used as the shape for the returned output tensor
  18814. .. note:: When :attr:`std` is a CUDA tensor, this function synchronizes
  18815. its device with the CPU.
  18816. Args:
  18817. mean (Tensor): the tensor of per-element means
  18818. std (Tensor): the tensor of per-element standard deviations
  18819. Keyword args:
  18820. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  18821. out (Tensor, optional): the output tensor.
  18822. Example::
  18823. >>> torch.normal(mean=torch.arange(1., 11.), std=torch.arange(1, 0, -0.1))
  18824. tensor([ 1.0425, 3.5672, 2.7969, 4.2925, 4.7229, 6.2134,
  18825. 8.0505, 8.1408, 9.0563, 10.0566])
  18826. .. function:: normal(mean=0.0, std, *, out=None) -> Tensor
  18827. :noindex:
  18828. Similar to the function above, but the means are shared among all drawn
  18829. elements.
  18830. Args:
  18831. mean (float, optional): the mean for all distributions
  18832. std (Tensor): the tensor of per-element standard deviations
  18833. Keyword args:
  18834. out (Tensor, optional): the output tensor.
  18835. Example::
  18836. >>> torch.normal(mean=0.5, std=torch.arange(1., 6.))
  18837. tensor([-1.2793, -1.0732, -2.0687, 5.1177, -1.2303])
  18838. .. function:: normal(mean, std=1.0, *, out=None) -> Tensor
  18839. :noindex:
  18840. Similar to the function above, but the standard deviations are shared among
  18841. all drawn elements.
  18842. Args:
  18843. mean (Tensor): the tensor of per-element means
  18844. std (float, optional): the standard deviation for all distributions
  18845. Keyword args:
  18846. out (Tensor, optional): the output tensor
  18847. Example::
  18848. >>> torch.normal(mean=torch.arange(1., 6.))
  18849. tensor([ 1.1552, 2.6148, 2.6535, 5.8318, 4.2361])
  18850. .. function:: normal(mean, std, size, *, out=None) -> Tensor
  18851. :noindex:
  18852. Similar to the function above, but the means and standard deviations are shared
  18853. among all drawn elements. The resulting tensor has size given by :attr:`size`.
  18854. Args:
  18855. mean (float): the mean for all distributions
  18856. std (float): the standard deviation for all distributions
  18857. size (int...): a sequence of integers defining the shape of the output tensor.
  18858. Keyword args:
  18859. out (Tensor, optional): the output tensor.
  18860. Example::
  18861. >>> torch.normal(2, 3, size=(1, 4))
  18862. tensor([[-1.3987, -1.9544, 3.6048, 0.7909]])
  18863. """
  18864. @overload
  18865. def not_equal(
  18866. input: Tensor,
  18867. other: Tensor,
  18868. *,
  18869. out: Tensor | None = None,
  18870. ) -> Tensor:
  18871. r"""
  18872. not_equal(input, other, *, out=None) -> Tensor
  18873. Alias for :func:`torch.ne`.
  18874. """
  18875. @overload
  18876. def not_equal(
  18877. input: Tensor,
  18878. other: Number | _complex,
  18879. *,
  18880. out: Tensor | None = None,
  18881. ) -> Tensor:
  18882. r"""
  18883. not_equal(input, other, *, out=None) -> Tensor
  18884. Alias for :func:`torch.ne`.
  18885. """
  18886. @overload
  18887. def nuclear_norm(
  18888. input: Tensor,
  18889. dim: _int | _size,
  18890. keepdim: _bool = False,
  18891. *,
  18892. out: Tensor | None = None,
  18893. ) -> Tensor: ...
  18894. @overload
  18895. def nuclear_norm(
  18896. input: Tensor,
  18897. keepdim: _bool = False,
  18898. *,
  18899. out: Tensor | None = None,
  18900. ) -> Tensor: ...
  18901. def numel(self: Tensor) -> _int:
  18902. r"""
  18903. numel(input: Tensor) -> int
  18904. Returns the total number of elements in the :attr:`input` tensor.
  18905. Args:
  18906. input (Tensor): the input tensor.
  18907. Example::
  18908. >>> a = torch.randn(1, 2, 3, 4, 5)
  18909. >>> torch.numel(a)
  18910. 120
  18911. >>> a = torch.zeros(4,4)
  18912. >>> torch.numel(a)
  18913. 16
  18914. """
  18915. @overload
  18916. def ones(
  18917. size: Sequence[_int | SymInt],
  18918. *,
  18919. out: Tensor | None = None,
  18920. dtype: _dtype | None = None,
  18921. layout: _layout | None = None,
  18922. device: DeviceLikeType | None = None,
  18923. pin_memory: _bool | None = False,
  18924. requires_grad: _bool | None = False,
  18925. ) -> Tensor:
  18926. r"""
  18927. ones(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  18928. Returns a tensor filled with the scalar value `1`, with the shape defined
  18929. by the variable argument :attr:`size`.
  18930. Args:
  18931. size (int...): a sequence of integers defining the shape of the output tensor.
  18932. Can be a variable number of arguments or a collection like a list or tuple.
  18933. Keyword arguments:
  18934. out (Tensor, optional): the output tensor.
  18935. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  18936. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  18937. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  18938. Default: ``torch.strided``.
  18939. device (:class:`torch.device`, optional): the desired device of returned tensor.
  18940. Default: if ``None``, uses the current device for the default tensor type
  18941. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  18942. for CPU tensor types and the current CUDA device for CUDA tensor types.
  18943. requires_grad (bool, optional): If autograd should record operations on the
  18944. returned tensor. Default: ``False``.
  18945. Example::
  18946. >>> torch.ones(2, 3)
  18947. tensor([[ 1., 1., 1.],
  18948. [ 1., 1., 1.]])
  18949. >>> torch.ones(5)
  18950. tensor([ 1., 1., 1., 1., 1.])
  18951. """
  18952. @overload
  18953. def ones(
  18954. *size: _int | SymInt,
  18955. out: Tensor | None = None,
  18956. dtype: _dtype | None = None,
  18957. layout: _layout | None = None,
  18958. device: DeviceLikeType | None = None,
  18959. pin_memory: _bool | None = False,
  18960. requires_grad: _bool | None = False,
  18961. ) -> Tensor:
  18962. r"""
  18963. ones(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  18964. Returns a tensor filled with the scalar value `1`, with the shape defined
  18965. by the variable argument :attr:`size`.
  18966. Args:
  18967. size (int...): a sequence of integers defining the shape of the output tensor.
  18968. Can be a variable number of arguments or a collection like a list or tuple.
  18969. Keyword arguments:
  18970. out (Tensor, optional): the output tensor.
  18971. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  18972. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  18973. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  18974. Default: ``torch.strided``.
  18975. device (:class:`torch.device`, optional): the desired device of returned tensor.
  18976. Default: if ``None``, uses the current device for the default tensor type
  18977. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  18978. for CPU tensor types and the current CUDA device for CUDA tensor types.
  18979. requires_grad (bool, optional): If autograd should record operations on the
  18980. returned tensor. Default: ``False``.
  18981. Example::
  18982. >>> torch.ones(2, 3)
  18983. tensor([[ 1., 1., 1.],
  18984. [ 1., 1., 1.]])
  18985. >>> torch.ones(5)
  18986. tensor([ 1., 1., 1., 1., 1.])
  18987. """
  18988. @overload
  18989. def ones(
  18990. size: _size,
  18991. *,
  18992. names: Sequence[str | EllipsisType | None] | None,
  18993. dtype: _dtype | None = None,
  18994. layout: _layout | None = None,
  18995. device: DeviceLikeType | None = None,
  18996. pin_memory: _bool | None = False,
  18997. requires_grad: _bool | None = False,
  18998. ) -> Tensor:
  18999. r"""
  19000. ones(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  19001. Returns a tensor filled with the scalar value `1`, with the shape defined
  19002. by the variable argument :attr:`size`.
  19003. Args:
  19004. size (int...): a sequence of integers defining the shape of the output tensor.
  19005. Can be a variable number of arguments or a collection like a list or tuple.
  19006. Keyword arguments:
  19007. out (Tensor, optional): the output tensor.
  19008. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19009. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  19010. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  19011. Default: ``torch.strided``.
  19012. device (:class:`torch.device`, optional): the desired device of returned tensor.
  19013. Default: if ``None``, uses the current device for the default tensor type
  19014. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  19015. for CPU tensor types and the current CUDA device for CUDA tensor types.
  19016. requires_grad (bool, optional): If autograd should record operations on the
  19017. returned tensor. Default: ``False``.
  19018. Example::
  19019. >>> torch.ones(2, 3)
  19020. tensor([[ 1., 1., 1.],
  19021. [ 1., 1., 1.]])
  19022. >>> torch.ones(5)
  19023. tensor([ 1., 1., 1., 1., 1.])
  19024. """
  19025. @overload
  19026. def ones(
  19027. *size: _int,
  19028. names: Sequence[str | EllipsisType | None] | None,
  19029. dtype: _dtype | None = None,
  19030. layout: _layout | None = None,
  19031. device: DeviceLikeType | None = None,
  19032. pin_memory: _bool | None = False,
  19033. requires_grad: _bool | None = False,
  19034. ) -> Tensor:
  19035. r"""
  19036. ones(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  19037. Returns a tensor filled with the scalar value `1`, with the shape defined
  19038. by the variable argument :attr:`size`.
  19039. Args:
  19040. size (int...): a sequence of integers defining the shape of the output tensor.
  19041. Can be a variable number of arguments or a collection like a list or tuple.
  19042. Keyword arguments:
  19043. out (Tensor, optional): the output tensor.
  19044. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19045. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  19046. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  19047. Default: ``torch.strided``.
  19048. device (:class:`torch.device`, optional): the desired device of returned tensor.
  19049. Default: if ``None``, uses the current device for the default tensor type
  19050. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  19051. for CPU tensor types and the current CUDA device for CUDA tensor types.
  19052. requires_grad (bool, optional): If autograd should record operations on the
  19053. returned tensor. Default: ``False``.
  19054. Example::
  19055. >>> torch.ones(2, 3)
  19056. tensor([[ 1., 1., 1.],
  19057. [ 1., 1., 1.]])
  19058. >>> torch.ones(5)
  19059. tensor([ 1., 1., 1., 1., 1.])
  19060. """
  19061. def ones_like(
  19062. input: Tensor,
  19063. *,
  19064. memory_format: memory_format | None = None,
  19065. dtype: _dtype | None = None,
  19066. layout: _layout | None = None,
  19067. device: DeviceLikeType | None = None,
  19068. pin_memory: _bool | None = False,
  19069. requires_grad: _bool | None = False,
  19070. ) -> Tensor:
  19071. r"""
  19072. ones_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  19073. Returns a tensor filled with the scalar value `1`, with the same size as
  19074. :attr:`input`. ``torch.ones_like(input)`` is equivalent to
  19075. ``torch.ones(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
  19076. .. warning::
  19077. As of 0.4, this function does not support an :attr:`out` keyword. As an alternative,
  19078. the old ``torch.ones_like(input, out=output)`` is equivalent to
  19079. ``torch.ones(input.size(), out=output)``.
  19080. Args:
  19081. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  19082. Keyword arguments:
  19083. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  19084. Default: if ``None``, defaults to the dtype of :attr:`input`.
  19085. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  19086. Default: if ``None``, defaults to the layout of :attr:`input`.
  19087. device (:class:`torch.device`, optional): the desired device of returned tensor.
  19088. Default: if ``None``, defaults to the device of :attr:`input`.
  19089. requires_grad (bool, optional): If autograd should record operations on the
  19090. returned tensor. Default: ``False``.
  19091. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  19092. returned Tensor. Default: ``torch.preserve_format``.
  19093. Example::
  19094. >>> input = torch.empty(2, 3)
  19095. >>> torch.ones_like(input)
  19096. tensor([[ 1., 1., 1.],
  19097. [ 1., 1., 1.]])
  19098. """
  19099. def orgqr(
  19100. input: Tensor,
  19101. input2: Tensor,
  19102. *,
  19103. out: Tensor | None = None,
  19104. ) -> Tensor:
  19105. r"""
  19106. orgqr(input, tau) -> Tensor
  19107. Alias for :func:`torch.linalg.householder_product`.
  19108. """
  19109. def ormqr(
  19110. input: Tensor,
  19111. input2: Tensor,
  19112. input3: Tensor,
  19113. left: _bool = True,
  19114. transpose: _bool = False,
  19115. *,
  19116. out: Tensor | None = None,
  19117. ) -> Tensor:
  19118. r"""
  19119. ormqr(input, tau, other, left=True, transpose=False, *, out=None) -> Tensor
  19120. Computes the matrix-matrix multiplication of a product of Householder matrices with a general matrix.
  19121. Multiplies a :math:`m \times n` matrix `C` (given by :attr:`other`) with a matrix `Q`,
  19122. where `Q` is represented using Householder reflectors `(input, tau)`.
  19123. See `Representation of Orthogonal or Unitary Matrices`_ for further details.
  19124. If :attr:`left` is `True` then `op(Q)` times `C` is computed, otherwise the result is `C` times `op(Q)`.
  19125. When :attr:`left` is `True`, the implicit matrix `Q` has size :math:`m \times m`.
  19126. It has size :math:`n \times n` otherwise.
  19127. If :attr:`transpose` is `True` then `op` is the conjugate transpose operation, otherwise it's a no-op.
  19128. Supports inputs of float, double, cfloat and cdouble dtypes.
  19129. Also supports batched inputs, and, if the input is batched, the output is batched with the same dimensions.
  19130. .. seealso::
  19131. :func:`torch.geqrf` can be used to form the Householder representation `(input, tau)` of matrix `Q`
  19132. from the QR decomposition.
  19133. .. note::
  19134. This function supports backward but it is only fast when ``(input, tau)`` do not require gradients
  19135. and/or ``tau.size(-1)`` is very small.
  19136. ``
  19137. Args:
  19138. input (Tensor): tensor of shape `(*, mn, k)` where `*` is zero or more batch dimensions
  19139. and `mn` equals to `m` or `n` depending on the :attr:`left`.
  19140. tau (Tensor): tensor of shape `(*, min(mn, k))` where `*` is zero or more batch dimensions.
  19141. other (Tensor): tensor of shape `(*, m, n)` where `*` is zero or more batch dimensions.
  19142. left (bool): controls the order of multiplication.
  19143. transpose (bool): controls whether the matrix `Q` is conjugate transposed or not.
  19144. Keyword args:
  19145. out (Tensor, optional): the output Tensor. Ignored if `None`. Default: `None`.
  19146. .. _Representation of Orthogonal or Unitary Matrices:
  19147. https://www.netlib.org/lapack/lug/node128.html
  19148. """
  19149. def outer(
  19150. input: Tensor,
  19151. vec2: Tensor,
  19152. *,
  19153. out: Tensor | None = None,
  19154. ) -> Tensor:
  19155. r"""
  19156. outer(input, vec2, *, out=None) -> Tensor
  19157. Outer product of :attr:`input` and :attr:`vec2`.
  19158. If :attr:`input` is a vector of size :math:`n` and :attr:`vec2` is a vector of
  19159. size :math:`m`, then :attr:`out` must be a matrix of size :math:`(n \times m)`.
  19160. .. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
  19161. Args:
  19162. input (Tensor): 1-D input vector
  19163. vec2 (Tensor): 1-D input vector
  19164. Keyword args:
  19165. out (Tensor, optional): optional output matrix
  19166. Example::
  19167. >>> v1 = torch.arange(1., 5.)
  19168. >>> v2 = torch.arange(1., 4.)
  19169. >>> torch.outer(v1, v2)
  19170. tensor([[ 1., 2., 3.],
  19171. [ 2., 4., 6.],
  19172. [ 3., 6., 9.],
  19173. [ 4., 8., 12.]])
  19174. """
  19175. def pairwise_distance(
  19176. x1: Tensor,
  19177. x2: Tensor,
  19178. p: _float = 2,
  19179. eps: _float = 1e-06,
  19180. keepdim: _bool = False,
  19181. ) -> Tensor: ...
  19182. def pdist(input: Tensor, p: _float = 2) -> Tensor: ...
  19183. def permute(input: Tensor, dims: _size) -> Tensor:
  19184. r"""
  19185. permute(input, dims) -> Tensor
  19186. Returns a view of the original tensor :attr:`input` with its dimensions permuted.
  19187. Args:
  19188. input (Tensor): the input tensor.
  19189. dims (tuple of int): The desired ordering of dimensions
  19190. Example:
  19191. >>> x = torch.randn(2, 3, 5)
  19192. >>> x.size()
  19193. torch.Size([2, 3, 5])
  19194. >>> torch.permute(x, (2, 0, 1)).size()
  19195. torch.Size([5, 2, 3])
  19196. """
  19197. def permute_copy(
  19198. input: Tensor,
  19199. dims: _size,
  19200. *,
  19201. out: Tensor | None = None,
  19202. ) -> Tensor:
  19203. r"""
  19204. Performs the same operation as :func:`torch.permute`, but all output tensors
  19205. are freshly created instead of aliasing the input.
  19206. """
  19207. def pinverse(input: Tensor, rcond: _float = 1e-15) -> Tensor:
  19208. r"""
  19209. pinverse(input, rcond=1e-15) -> Tensor
  19210. Alias for :func:`torch.linalg.pinv`
  19211. """
  19212. def pixel_shuffle(input: Tensor, upscale_factor: _int) -> Tensor: ...
  19213. def pixel_unshuffle(input: Tensor, downscale_factor: _int) -> Tensor: ...
  19214. def poisson(input: Tensor, generator: Generator | None = None) -> Tensor:
  19215. r"""
  19216. poisson(input, generator=None) -> Tensor
  19217. Returns a tensor of the same size as :attr:`input` with each element
  19218. sampled from a Poisson distribution with rate parameter given by the corresponding
  19219. element in :attr:`input` i.e.,
  19220. .. math::
  19221. \text{out}_i \sim \text{Poisson}(\text{input}_i)
  19222. :attr:`input` must be non-negative.
  19223. Args:
  19224. input (Tensor): the input tensor containing the rates of the Poisson distribution
  19225. Keyword args:
  19226. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  19227. Example::
  19228. >>> rates = torch.rand(4, 4) * 5 # rate parameter between 0 and 5
  19229. >>> torch.poisson(rates)
  19230. tensor([[9., 1., 3., 5.],
  19231. [8., 6., 6., 0.],
  19232. [0., 4., 5., 3.],
  19233. [2., 1., 4., 2.]])
  19234. """
  19235. def poisson_nll_loss(
  19236. input: Tensor,
  19237. target: Tensor,
  19238. log_input: _bool,
  19239. full: _bool,
  19240. eps: _float,
  19241. reduction: _int,
  19242. ) -> Tensor: ...
  19243. def polar(
  19244. abs: Tensor,
  19245. angle: Tensor,
  19246. *,
  19247. out: Tensor | None = None,
  19248. ) -> Tensor:
  19249. r"""
  19250. polar(abs, angle, *, out=None) -> Tensor
  19251. Constructs a complex tensor whose elements are Cartesian coordinates
  19252. corresponding to the polar coordinates with absolute value :attr:`abs` and angle
  19253. :attr:`angle`.
  19254. .. math::
  19255. \text{out} = \text{abs} \cdot \cos(\text{angle}) + \text{abs} \cdot \sin(\text{angle}) \cdot j
  19256. .. note::
  19257. `torch.polar` is similar to
  19258. `std::polar <https://en.cppreference.com/w/cpp/numeric/complex/polar>`_
  19259. and does not compute the polar decomposition
  19260. of a complex tensor like Python's `cmath.polar` and SciPy's `linalg.polar` do.
  19261. The behavior of this function is undefined if `abs` is negative or NaN, or if `angle` is
  19262. infinite.
  19263. Args:
  19264. abs (Tensor): The absolute value the complex tensor. Must be float or double.
  19265. angle (Tensor): The angle of the complex tensor. Must be same dtype as
  19266. :attr:`abs`.
  19267. Keyword args:
  19268. out (Tensor): If the inputs are ``torch.float32``, must be
  19269. ``torch.complex64``. If the inputs are ``torch.float64``, must be
  19270. ``torch.complex128``.
  19271. Example::
  19272. >>> import numpy as np
  19273. >>> abs = torch.tensor([1, 2], dtype=torch.float64)
  19274. >>> angle = torch.tensor([np.pi / 2, 5 * np.pi / 4], dtype=torch.float64)
  19275. >>> z = torch.polar(abs, angle)
  19276. >>> z
  19277. tensor([(0.0000+1.0000j), (-1.4142-1.4142j)], dtype=torch.complex128)
  19278. """
  19279. def polygamma(
  19280. n: _int,
  19281. input: Tensor,
  19282. *,
  19283. out: Tensor | None = None,
  19284. ) -> Tensor:
  19285. r"""
  19286. polygamma(n, input, *, out=None) -> Tensor
  19287. Alias for :func:`torch.special.polygamma`.
  19288. """
  19289. def positive(input: Tensor) -> Tensor:
  19290. r"""
  19291. positive(input) -> Tensor
  19292. Returns :attr:`input`.
  19293. Throws a runtime error if :attr:`input` is a bool tensor.
  19294. Args:
  19295. input (Tensor): the input tensor.
  19296. Example::
  19297. >>> t = torch.randn(5)
  19298. >>> t
  19299. tensor([ 0.0090, -0.2262, -0.0682, -0.2866, 0.3940])
  19300. >>> torch.positive(t)
  19301. tensor([ 0.0090, -0.2262, -0.0682, -0.2866, 0.3940])
  19302. """
  19303. @overload
  19304. def pow(
  19305. input: Tensor,
  19306. exponent: Tensor,
  19307. *,
  19308. out: Tensor | None = None,
  19309. ) -> Tensor:
  19310. r"""
  19311. pow(input, exponent, *, out=None) -> Tensor
  19312. Takes the power of each element in :attr:`input` with :attr:`exponent` and
  19313. returns a tensor with the result.
  19314. :attr:`exponent` can be either a single ``float`` number or a `Tensor`
  19315. with the same number of elements as :attr:`input`.
  19316. When :attr:`exponent` is a scalar value, the operation applied is:
  19317. .. math::
  19318. \text{out}_i = x_i ^ \text{exponent}
  19319. When :attr:`exponent` is a tensor, the operation applied is:
  19320. .. math::
  19321. \text{out}_i = x_i ^ {\text{exponent}_i}
  19322. When :attr:`exponent` is a tensor, the shapes of :attr:`input`
  19323. and :attr:`exponent` must be :ref:`broadcastable <broadcasting-semantics>`.
  19324. Args:
  19325. input (Tensor): the input tensor.
  19326. exponent (float or tensor): the exponent value
  19327. Keyword args:
  19328. out (Tensor, optional): the output tensor.
  19329. Example::
  19330. >>> a = torch.randn(4)
  19331. >>> a
  19332. tensor([ 0.4331, 1.2475, 0.6834, -0.2791])
  19333. >>> torch.pow(a, 2)
  19334. tensor([ 0.1875, 1.5561, 0.4670, 0.0779])
  19335. >>> exp = torch.arange(1., 5.)
  19336. >>> a = torch.arange(1., 5.)
  19337. >>> a
  19338. tensor([ 1., 2., 3., 4.])
  19339. >>> exp
  19340. tensor([ 1., 2., 3., 4.])
  19341. >>> torch.pow(a, exp)
  19342. tensor([ 1., 4., 27., 256.])
  19343. .. function:: pow(self, exponent, *, out=None) -> Tensor
  19344. :noindex:
  19345. :attr:`self` is a scalar ``float`` value, and :attr:`exponent` is a tensor.
  19346. The returned tensor :attr:`out` is of the same shape as :attr:`exponent`
  19347. The operation applied is:
  19348. .. math::
  19349. \text{out}_i = \text{self} ^ {\text{exponent}_i}
  19350. Args:
  19351. self (float): the scalar base value for the power operation
  19352. exponent (Tensor): the exponent tensor
  19353. Keyword args:
  19354. out (Tensor, optional): the output tensor.
  19355. Example::
  19356. >>> exp = torch.arange(1., 5.)
  19357. >>> base = 2
  19358. >>> torch.pow(base, exp)
  19359. tensor([ 2., 4., 8., 16.])
  19360. """
  19361. @overload
  19362. def pow(
  19363. self: Number | _complex,
  19364. exponent: Tensor,
  19365. *,
  19366. out: Tensor | None = None,
  19367. ) -> Tensor:
  19368. r"""
  19369. pow(input, exponent, *, out=None) -> Tensor
  19370. Takes the power of each element in :attr:`input` with :attr:`exponent` and
  19371. returns a tensor with the result.
  19372. :attr:`exponent` can be either a single ``float`` number or a `Tensor`
  19373. with the same number of elements as :attr:`input`.
  19374. When :attr:`exponent` is a scalar value, the operation applied is:
  19375. .. math::
  19376. \text{out}_i = x_i ^ \text{exponent}
  19377. When :attr:`exponent` is a tensor, the operation applied is:
  19378. .. math::
  19379. \text{out}_i = x_i ^ {\text{exponent}_i}
  19380. When :attr:`exponent` is a tensor, the shapes of :attr:`input`
  19381. and :attr:`exponent` must be :ref:`broadcastable <broadcasting-semantics>`.
  19382. Args:
  19383. input (Tensor): the input tensor.
  19384. exponent (float or tensor): the exponent value
  19385. Keyword args:
  19386. out (Tensor, optional): the output tensor.
  19387. Example::
  19388. >>> a = torch.randn(4)
  19389. >>> a
  19390. tensor([ 0.4331, 1.2475, 0.6834, -0.2791])
  19391. >>> torch.pow(a, 2)
  19392. tensor([ 0.1875, 1.5561, 0.4670, 0.0779])
  19393. >>> exp = torch.arange(1., 5.)
  19394. >>> a = torch.arange(1., 5.)
  19395. >>> a
  19396. tensor([ 1., 2., 3., 4.])
  19397. >>> exp
  19398. tensor([ 1., 2., 3., 4.])
  19399. >>> torch.pow(a, exp)
  19400. tensor([ 1., 4., 27., 256.])
  19401. .. function:: pow(self, exponent, *, out=None) -> Tensor
  19402. :noindex:
  19403. :attr:`self` is a scalar ``float`` value, and :attr:`exponent` is a tensor.
  19404. The returned tensor :attr:`out` is of the same shape as :attr:`exponent`
  19405. The operation applied is:
  19406. .. math::
  19407. \text{out}_i = \text{self} ^ {\text{exponent}_i}
  19408. Args:
  19409. self (float): the scalar base value for the power operation
  19410. exponent (Tensor): the exponent tensor
  19411. Keyword args:
  19412. out (Tensor, optional): the output tensor.
  19413. Example::
  19414. >>> exp = torch.arange(1., 5.)
  19415. >>> base = 2
  19416. >>> torch.pow(base, exp)
  19417. tensor([ 2., 4., 8., 16.])
  19418. """
  19419. @overload
  19420. def pow(
  19421. input: Tensor,
  19422. exponent: Number | _complex,
  19423. *,
  19424. out: Tensor | None = None,
  19425. ) -> Tensor:
  19426. r"""
  19427. pow(input, exponent, *, out=None) -> Tensor
  19428. Takes the power of each element in :attr:`input` with :attr:`exponent` and
  19429. returns a tensor with the result.
  19430. :attr:`exponent` can be either a single ``float`` number or a `Tensor`
  19431. with the same number of elements as :attr:`input`.
  19432. When :attr:`exponent` is a scalar value, the operation applied is:
  19433. .. math::
  19434. \text{out}_i = x_i ^ \text{exponent}
  19435. When :attr:`exponent` is a tensor, the operation applied is:
  19436. .. math::
  19437. \text{out}_i = x_i ^ {\text{exponent}_i}
  19438. When :attr:`exponent` is a tensor, the shapes of :attr:`input`
  19439. and :attr:`exponent` must be :ref:`broadcastable <broadcasting-semantics>`.
  19440. Args:
  19441. input (Tensor): the input tensor.
  19442. exponent (float or tensor): the exponent value
  19443. Keyword args:
  19444. out (Tensor, optional): the output tensor.
  19445. Example::
  19446. >>> a = torch.randn(4)
  19447. >>> a
  19448. tensor([ 0.4331, 1.2475, 0.6834, -0.2791])
  19449. >>> torch.pow(a, 2)
  19450. tensor([ 0.1875, 1.5561, 0.4670, 0.0779])
  19451. >>> exp = torch.arange(1., 5.)
  19452. >>> a = torch.arange(1., 5.)
  19453. >>> a
  19454. tensor([ 1., 2., 3., 4.])
  19455. >>> exp
  19456. tensor([ 1., 2., 3., 4.])
  19457. >>> torch.pow(a, exp)
  19458. tensor([ 1., 4., 27., 256.])
  19459. .. function:: pow(self, exponent, *, out=None) -> Tensor
  19460. :noindex:
  19461. :attr:`self` is a scalar ``float`` value, and :attr:`exponent` is a tensor.
  19462. The returned tensor :attr:`out` is of the same shape as :attr:`exponent`
  19463. The operation applied is:
  19464. .. math::
  19465. \text{out}_i = \text{self} ^ {\text{exponent}_i}
  19466. Args:
  19467. self (float): the scalar base value for the power operation
  19468. exponent (Tensor): the exponent tensor
  19469. Keyword args:
  19470. out (Tensor, optional): the output tensor.
  19471. Example::
  19472. >>> exp = torch.arange(1., 5.)
  19473. >>> base = 2
  19474. >>> torch.pow(base, exp)
  19475. tensor([ 2., 4., 8., 16.])
  19476. """
  19477. def prelu(input: Tensor, weight: Tensor) -> Tensor: ...
  19478. @overload
  19479. def prod(input: Tensor, *, dtype: _dtype | None = None) -> Tensor:
  19480. r"""
  19481. prod(input: Tensor, *, dtype: Optional[_dtype]) -> Tensor
  19482. Returns the product of all elements in the :attr:`input` tensor.
  19483. Args:
  19484. input (Tensor): the input tensor.
  19485. Keyword args:
  19486. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19487. If specified, the input tensor is casted to :attr:`dtype` before the operation
  19488. is performed. This is useful for preventing data type overflows. Default: None.
  19489. Example::
  19490. >>> a = torch.randn(1, 3)
  19491. >>> a
  19492. tensor([[-0.8020, 0.5428, -1.5854]])
  19493. >>> torch.prod(a)
  19494. tensor(0.6902)
  19495. .. function:: prod(input, dim, keepdim=False, *, dtype=None) -> Tensor
  19496. :noindex:
  19497. Returns the product of each row of the :attr:`input` tensor in the given
  19498. dimension :attr:`dim`.
  19499. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  19500. as :attr:`input` except in the dimension :attr:`dim` where it is of size 1.
  19501. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  19502. the output tensor having 1 fewer dimension than :attr:`input`.
  19503. Args:
  19504. input (Tensor): the input tensor.
  19505. dim (int, optional): the dimension to reduce.
  19506. If ``None``, all dimensions are reduced.
  19507. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  19508. Keyword args:
  19509. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19510. If specified, the input tensor is casted to :attr:`dtype` before the operation
  19511. is performed. This is useful for preventing data type overflows. Default: None.
  19512. Example::
  19513. >>> a = torch.randn(4, 2)
  19514. >>> a
  19515. tensor([[ 0.5261, -0.3837],
  19516. [ 1.1857, -0.2498],
  19517. [-1.1646, 0.0705],
  19518. [ 1.1131, -1.0629]])
  19519. >>> torch.prod(a, 1)
  19520. tensor([-0.2018, -0.2962, -0.0821, -1.1831])
  19521. """
  19522. @overload
  19523. def prod(
  19524. input: Tensor,
  19525. dim: _int,
  19526. keepdim: _bool = False,
  19527. *,
  19528. dtype: _dtype | None = None,
  19529. out: Tensor | None = None,
  19530. ) -> Tensor:
  19531. r"""
  19532. prod(input: Tensor, *, dtype: Optional[_dtype]) -> Tensor
  19533. Returns the product of all elements in the :attr:`input` tensor.
  19534. Args:
  19535. input (Tensor): the input tensor.
  19536. Keyword args:
  19537. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19538. If specified, the input tensor is casted to :attr:`dtype` before the operation
  19539. is performed. This is useful for preventing data type overflows. Default: None.
  19540. Example::
  19541. >>> a = torch.randn(1, 3)
  19542. >>> a
  19543. tensor([[-0.8020, 0.5428, -1.5854]])
  19544. >>> torch.prod(a)
  19545. tensor(0.6902)
  19546. .. function:: prod(input, dim, keepdim=False, *, dtype=None) -> Tensor
  19547. :noindex:
  19548. Returns the product of each row of the :attr:`input` tensor in the given
  19549. dimension :attr:`dim`.
  19550. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  19551. as :attr:`input` except in the dimension :attr:`dim` where it is of size 1.
  19552. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  19553. the output tensor having 1 fewer dimension than :attr:`input`.
  19554. Args:
  19555. input (Tensor): the input tensor.
  19556. dim (int, optional): the dimension to reduce.
  19557. If ``None``, all dimensions are reduced.
  19558. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  19559. Keyword args:
  19560. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19561. If specified, the input tensor is casted to :attr:`dtype` before the operation
  19562. is performed. This is useful for preventing data type overflows. Default: None.
  19563. Example::
  19564. >>> a = torch.randn(4, 2)
  19565. >>> a
  19566. tensor([[ 0.5261, -0.3837],
  19567. [ 1.1857, -0.2498],
  19568. [-1.1646, 0.0705],
  19569. [ 1.1131, -1.0629]])
  19570. >>> torch.prod(a, 1)
  19571. tensor([-0.2018, -0.2962, -0.0821, -1.1831])
  19572. """
  19573. @overload
  19574. def prod(
  19575. input: Tensor,
  19576. dim: str | EllipsisType | None,
  19577. keepdim: _bool = False,
  19578. *,
  19579. dtype: _dtype | None = None,
  19580. out: Tensor | None = None,
  19581. ) -> Tensor:
  19582. r"""
  19583. prod(input: Tensor, *, dtype: Optional[_dtype]) -> Tensor
  19584. Returns the product of all elements in the :attr:`input` tensor.
  19585. Args:
  19586. input (Tensor): the input tensor.
  19587. Keyword args:
  19588. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19589. If specified, the input tensor is casted to :attr:`dtype` before the operation
  19590. is performed. This is useful for preventing data type overflows. Default: None.
  19591. Example::
  19592. >>> a = torch.randn(1, 3)
  19593. >>> a
  19594. tensor([[-0.8020, 0.5428, -1.5854]])
  19595. >>> torch.prod(a)
  19596. tensor(0.6902)
  19597. .. function:: prod(input, dim, keepdim=False, *, dtype=None) -> Tensor
  19598. :noindex:
  19599. Returns the product of each row of the :attr:`input` tensor in the given
  19600. dimension :attr:`dim`.
  19601. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  19602. as :attr:`input` except in the dimension :attr:`dim` where it is of size 1.
  19603. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  19604. the output tensor having 1 fewer dimension than :attr:`input`.
  19605. Args:
  19606. input (Tensor): the input tensor.
  19607. dim (int, optional): the dimension to reduce.
  19608. If ``None``, all dimensions are reduced.
  19609. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  19610. Keyword args:
  19611. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19612. If specified, the input tensor is casted to :attr:`dtype` before the operation
  19613. is performed. This is useful for preventing data type overflows. Default: None.
  19614. Example::
  19615. >>> a = torch.randn(4, 2)
  19616. >>> a
  19617. tensor([[ 0.5261, -0.3837],
  19618. [ 1.1857, -0.2498],
  19619. [-1.1646, 0.0705],
  19620. [ 1.1131, -1.0629]])
  19621. >>> torch.prod(a, 1)
  19622. tensor([-0.2018, -0.2962, -0.0821, -1.1831])
  19623. """
  19624. def promote_types(type1: _dtype, type2: _dtype) -> _dtype:
  19625. r"""
  19626. promote_types(type1, type2) -> dtype
  19627. Returns the :class:`torch.dtype` with the smallest size and scalar kind that is
  19628. not smaller nor of lower kind than either `type1` or `type2`. See type promotion
  19629. :ref:`documentation <type-promotion-doc>` for more information on the type
  19630. promotion logic.
  19631. Args:
  19632. type1 (:class:`torch.dtype`)
  19633. type2 (:class:`torch.dtype`)
  19634. Example::
  19635. >>> torch.promote_types(torch.int32, torch.float32)
  19636. torch.float32
  19637. >>> torch.promote_types(torch.uint8, torch.long)
  19638. torch.long
  19639. """
  19640. def put(
  19641. input: Tensor,
  19642. index: Tensor,
  19643. source: Tensor,
  19644. accumulate: _bool = False,
  19645. ) -> Tensor: ...
  19646. def q_per_channel_axis(input: Tensor) -> _int: ...
  19647. def q_per_channel_scales(input: Tensor) -> Tensor: ...
  19648. def q_per_channel_zero_points(input: Tensor) -> Tensor: ...
  19649. def q_scale(input: Tensor) -> _float: ...
  19650. def q_zero_point(input: Tensor) -> _int: ...
  19651. def qr(
  19652. input: Tensor,
  19653. some: _bool = True,
  19654. *,
  19655. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  19656. ) -> torch.return_types.qr:
  19657. r"""
  19658. qr(input: Tensor, some: bool = True, *, out: Union[Tensor, Tuple[Tensor, ...], List[Tensor], None]) -> (Tensor, Tensor)
  19659. Computes the QR decomposition of a matrix or a batch of matrices :attr:`input`,
  19660. and returns a namedtuple (Q, R) of tensors such that :math:`\text{input} = Q R`
  19661. with :math:`Q` being an orthogonal matrix or batch of orthogonal matrices and
  19662. :math:`R` being an upper triangular matrix or batch of upper triangular matrices.
  19663. If :attr:`some` is ``True``, then this function returns the thin (reduced) QR factorization.
  19664. Otherwise, if :attr:`some` is ``False``, this function returns the complete QR factorization.
  19665. .. warning::
  19666. :func:`torch.qr` is deprecated in favor of :func:`torch.linalg.qr`
  19667. and will be removed in a future PyTorch release. The boolean parameter :attr:`some` has been
  19668. replaced with a string parameter :attr:`mode`.
  19669. ``Q, R = torch.qr(A)`` should be replaced with
  19670. .. code:: python
  19671. Q, R = torch.linalg.qr(A)
  19672. ``Q, R = torch.qr(A, some=False)`` should be replaced with
  19673. .. code:: python
  19674. Q, R = torch.linalg.qr(A, mode="complete")
  19675. .. warning::
  19676. If you plan to backpropagate through QR, note that the current backward implementation
  19677. is only well-defined when the first :math:`\min(input.size(-1), input.size(-2))`
  19678. columns of :attr:`input` are linearly independent.
  19679. This behavior will probably change once QR supports pivoting.
  19680. .. note:: This function uses LAPACK for CPU inputs and MAGMA for CUDA inputs,
  19681. and may produce different (valid) decompositions on different device types
  19682. or different platforms.
  19683. Args:
  19684. input (Tensor): the input tensor of size :math:`(*, m, n)` where `*` is zero or more
  19685. batch dimensions consisting of matrices of dimension :math:`m \times n`.
  19686. some (bool, optional): Set to ``True`` for reduced QR decomposition and ``False`` for
  19687. complete QR decomposition. If `k = min(m, n)` then:
  19688. * ``some=True`` : returns `(Q, R)` with dimensions (m, k), (k, n) (default)
  19689. * ``'some=False'``: returns `(Q, R)` with dimensions (m, m), (m, n)
  19690. Keyword args:
  19691. out (tuple, optional): tuple of `Q` and `R` tensors.
  19692. The dimensions of `Q` and `R` are detailed in the description of :attr:`some` above.
  19693. Example::
  19694. >>> a = torch.tensor([[12., -51, 4], [6, 167, -68], [-4, 24, -41]])
  19695. >>> q, r = torch.qr(a)
  19696. >>> q
  19697. tensor([[-0.8571, 0.3943, 0.3314],
  19698. [-0.4286, -0.9029, -0.0343],
  19699. [ 0.2857, -0.1714, 0.9429]])
  19700. >>> r
  19701. tensor([[ -14.0000, -21.0000, 14.0000],
  19702. [ 0.0000, -175.0000, 70.0000],
  19703. [ 0.0000, 0.0000, -35.0000]])
  19704. >>> torch.mm(q, r).round()
  19705. tensor([[ 12., -51., 4.],
  19706. [ 6., 167., -68.],
  19707. [ -4., 24., -41.]])
  19708. >>> torch.mm(q.t(), q).round()
  19709. tensor([[ 1., 0., 0.],
  19710. [ 0., 1., -0.],
  19711. [ 0., -0., 1.]])
  19712. >>> a = torch.randn(3, 4, 5)
  19713. >>> q, r = torch.qr(a, some=False)
  19714. >>> torch.allclose(torch.matmul(q, r), a)
  19715. True
  19716. >>> torch.allclose(torch.matmul(q.mT, q), torch.eye(5))
  19717. True
  19718. """
  19719. @overload
  19720. def quantile(
  19721. input: Tensor,
  19722. q: Tensor,
  19723. dim: _int | None = None,
  19724. keepdim: _bool = False,
  19725. *,
  19726. interpolation: str = "linear",
  19727. out: Tensor | None = None,
  19728. ) -> Tensor:
  19729. r"""
  19730. quantile(input, q, dim=None, keepdim=False, *, interpolation='linear', out=None) -> Tensor
  19731. Computes the q-th quantiles of each row of the :attr:`input` tensor along the dimension :attr:`dim`.
  19732. To compute the quantile, we map q in [0, 1] to the range of indices [0, n] to find the location
  19733. of the quantile in the sorted input. If the quantile lies between two data points ``a < b`` with
  19734. indices ``i`` and ``j`` in the sorted order, result is computed according to the given
  19735. :attr:`interpolation` method as follows:
  19736. - ``linear``: ``a + (b - a) * fraction``, where ``fraction`` is the fractional part of the computed quantile index.
  19737. - ``lower``: ``a``.
  19738. - ``higher``: ``b``.
  19739. - ``nearest``: ``a`` or ``b``, whichever's index is closer to the computed quantile index (rounding down for .5 fractions).
  19740. - ``midpoint``: ``(a + b) / 2``.
  19741. If :attr:`q` is a 1D tensor, the first dimension of the output represents the quantiles and has size
  19742. equal to the size of :attr:`q`, the remaining dimensions are what remains from the reduction.
  19743. .. note::
  19744. By default :attr:`dim` is ``None`` resulting in the :attr:`input` tensor being flattened before computation.
  19745. Args:
  19746. input (Tensor): the input tensor.
  19747. q (float or Tensor): a scalar or 1D tensor of values in the range [0, 1].
  19748. dim (int, optional): the dimension to reduce.
  19749. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  19750. Keyword arguments:
  19751. interpolation (str, optional): interpolation method to use when the desired quantile lies between two data points.
  19752. Can be ``linear``, ``lower``, ``higher``, ``midpoint`` and ``nearest``.
  19753. Default is ``linear``.
  19754. out (Tensor, optional): the output tensor.
  19755. Example::
  19756. >>> a = torch.randn(2, 3)
  19757. >>> a
  19758. tensor([[ 0.0795, -1.2117, 0.9765],
  19759. [ 1.1707, 0.6706, 0.4884]])
  19760. >>> q = torch.tensor([0.25, 0.5, 0.75])
  19761. >>> torch.quantile(a, q, dim=1, keepdim=True)
  19762. tensor([[[-0.5661],
  19763. [ 0.5795]],
  19764. [[ 0.0795],
  19765. [ 0.6706]],
  19766. [[ 0.5280],
  19767. [ 0.9206]]])
  19768. >>> torch.quantile(a, q, dim=1, keepdim=True).shape
  19769. torch.Size([3, 2, 1])
  19770. >>> a = torch.arange(4.)
  19771. >>> a
  19772. tensor([0., 1., 2., 3.])
  19773. >>> torch.quantile(a, 0.6, interpolation='linear')
  19774. tensor(1.8000)
  19775. >>> torch.quantile(a, 0.6, interpolation='lower')
  19776. tensor(1.)
  19777. >>> torch.quantile(a, 0.6, interpolation='higher')
  19778. tensor(2.)
  19779. >>> torch.quantile(a, 0.6, interpolation='midpoint')
  19780. tensor(1.5000)
  19781. >>> torch.quantile(a, 0.6, interpolation='nearest')
  19782. tensor(2.)
  19783. >>> torch.quantile(a, 0.4, interpolation='nearest')
  19784. tensor(1.)
  19785. """
  19786. @overload
  19787. def quantile(
  19788. input: Tensor,
  19789. q: _float,
  19790. dim: _int | None = None,
  19791. keepdim: _bool = False,
  19792. *,
  19793. interpolation: str = "linear",
  19794. out: Tensor | None = None,
  19795. ) -> Tensor:
  19796. r"""
  19797. quantile(input, q, dim=None, keepdim=False, *, interpolation='linear', out=None) -> Tensor
  19798. Computes the q-th quantiles of each row of the :attr:`input` tensor along the dimension :attr:`dim`.
  19799. To compute the quantile, we map q in [0, 1] to the range of indices [0, n] to find the location
  19800. of the quantile in the sorted input. If the quantile lies between two data points ``a < b`` with
  19801. indices ``i`` and ``j`` in the sorted order, result is computed according to the given
  19802. :attr:`interpolation` method as follows:
  19803. - ``linear``: ``a + (b - a) * fraction``, where ``fraction`` is the fractional part of the computed quantile index.
  19804. - ``lower``: ``a``.
  19805. - ``higher``: ``b``.
  19806. - ``nearest``: ``a`` or ``b``, whichever's index is closer to the computed quantile index (rounding down for .5 fractions).
  19807. - ``midpoint``: ``(a + b) / 2``.
  19808. If :attr:`q` is a 1D tensor, the first dimension of the output represents the quantiles and has size
  19809. equal to the size of :attr:`q`, the remaining dimensions are what remains from the reduction.
  19810. .. note::
  19811. By default :attr:`dim` is ``None`` resulting in the :attr:`input` tensor being flattened before computation.
  19812. Args:
  19813. input (Tensor): the input tensor.
  19814. q (float or Tensor): a scalar or 1D tensor of values in the range [0, 1].
  19815. dim (int, optional): the dimension to reduce.
  19816. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  19817. Keyword arguments:
  19818. interpolation (str, optional): interpolation method to use when the desired quantile lies between two data points.
  19819. Can be ``linear``, ``lower``, ``higher``, ``midpoint`` and ``nearest``.
  19820. Default is ``linear``.
  19821. out (Tensor, optional): the output tensor.
  19822. Example::
  19823. >>> a = torch.randn(2, 3)
  19824. >>> a
  19825. tensor([[ 0.0795, -1.2117, 0.9765],
  19826. [ 1.1707, 0.6706, 0.4884]])
  19827. >>> q = torch.tensor([0.25, 0.5, 0.75])
  19828. >>> torch.quantile(a, q, dim=1, keepdim=True)
  19829. tensor([[[-0.5661],
  19830. [ 0.5795]],
  19831. [[ 0.0795],
  19832. [ 0.6706]],
  19833. [[ 0.5280],
  19834. [ 0.9206]]])
  19835. >>> torch.quantile(a, q, dim=1, keepdim=True).shape
  19836. torch.Size([3, 2, 1])
  19837. >>> a = torch.arange(4.)
  19838. >>> a
  19839. tensor([0., 1., 2., 3.])
  19840. >>> torch.quantile(a, 0.6, interpolation='linear')
  19841. tensor(1.8000)
  19842. >>> torch.quantile(a, 0.6, interpolation='lower')
  19843. tensor(1.)
  19844. >>> torch.quantile(a, 0.6, interpolation='higher')
  19845. tensor(2.)
  19846. >>> torch.quantile(a, 0.6, interpolation='midpoint')
  19847. tensor(1.5000)
  19848. >>> torch.quantile(a, 0.6, interpolation='nearest')
  19849. tensor(2.)
  19850. >>> torch.quantile(a, 0.4, interpolation='nearest')
  19851. tensor(1.)
  19852. """
  19853. def quantize_per_channel(
  19854. input: Tensor,
  19855. scales: Tensor,
  19856. zero_points: Tensor,
  19857. axis: _int,
  19858. dtype: _dtype,
  19859. ) -> Tensor:
  19860. r"""
  19861. quantize_per_channel(input, scales, zero_points, axis, dtype) -> Tensor
  19862. Converts a float tensor to a per-channel quantized tensor with given scales and zero points.
  19863. Arguments:
  19864. input (Tensor): float tensor to quantize
  19865. scales (Tensor): float 1D tensor of scales to use, size should match ``input.size(axis)``
  19866. zero_points (int): integer 1D tensor of offset to use, size should match ``input.size(axis)``
  19867. axis (int): dimension on which apply per-channel quantization
  19868. dtype (:class:`torch.dtype`): the desired data type of returned tensor.
  19869. Has to be one of the quantized dtypes: ``torch.quint8``, ``torch.qint8``, ``torch.qint32``
  19870. Returns:
  19871. Tensor: A newly quantized tensor
  19872. Example::
  19873. >>> x = torch.tensor([[-1.0, 0.0], [1.0, 2.0]])
  19874. >>> torch.quantize_per_channel(x, torch.tensor([0.1, 0.01]), torch.tensor([10, 0]), 0, torch.quint8)
  19875. tensor([[-1., 0.],
  19876. [ 1., 2.]], size=(2, 2), dtype=torch.quint8,
  19877. quantization_scheme=torch.per_channel_affine,
  19878. scale=tensor([0.1000, 0.0100], dtype=torch.float64),
  19879. zero_point=tensor([10, 0]), axis=0)
  19880. >>> torch.quantize_per_channel(x, torch.tensor([0.1, 0.01]), torch.tensor([10, 0]), 0, torch.quint8).int_repr()
  19881. tensor([[ 0, 10],
  19882. [100, 200]], dtype=torch.uint8)
  19883. """
  19884. @overload
  19885. def quantize_per_tensor(
  19886. input: Tensor,
  19887. scale: Tensor,
  19888. zero_point: Tensor,
  19889. dtype: _dtype,
  19890. ) -> Tensor:
  19891. r"""
  19892. quantize_per_tensor(input, scale, zero_point, dtype) -> Tensor
  19893. Converts a float tensor to a quantized tensor with given scale and zero point.
  19894. Arguments:
  19895. input (Tensor): float tensor or list of tensors to quantize
  19896. scale (float or Tensor): scale to apply in quantization formula
  19897. zero_point (int or Tensor): offset in integer value that maps to float zero
  19898. dtype (:class:`torch.dtype`): the desired data type of returned tensor.
  19899. Has to be one of the quantized dtypes: ``torch.quint8``, ``torch.qint8``, ``torch.qint32``
  19900. Returns:
  19901. Tensor: A newly quantized tensor or list of quantized tensors.
  19902. Example::
  19903. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8)
  19904. tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
  19905. quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10)
  19906. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8).int_repr()
  19907. tensor([ 0, 10, 20, 30], dtype=torch.uint8)
  19908. >>> torch.quantize_per_tensor([torch.tensor([-1.0, 0.0]), torch.tensor([-2.0, 2.0])],
  19909. >>> torch.tensor([0.1, 0.2]), torch.tensor([10, 20]), torch.quint8)
  19910. (tensor([-1., 0.], size=(2,), dtype=torch.quint8,
  19911. quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10),
  19912. tensor([-2., 2.], size=(2,), dtype=torch.quint8,
  19913. quantization_scheme=torch.per_tensor_affine, scale=0.2, zero_point=20))
  19914. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), torch.tensor(0.1), torch.tensor(10), torch.quint8)
  19915. tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
  19916. quantization_scheme=torch.per_tensor_affine, scale=0.10, zero_point=10)
  19917. """
  19918. @overload
  19919. def quantize_per_tensor(
  19920. input: Tensor,
  19921. scale: _float,
  19922. zero_point: _int,
  19923. dtype: _dtype,
  19924. ) -> Tensor:
  19925. r"""
  19926. quantize_per_tensor(input, scale, zero_point, dtype) -> Tensor
  19927. Converts a float tensor to a quantized tensor with given scale and zero point.
  19928. Arguments:
  19929. input (Tensor): float tensor or list of tensors to quantize
  19930. scale (float or Tensor): scale to apply in quantization formula
  19931. zero_point (int or Tensor): offset in integer value that maps to float zero
  19932. dtype (:class:`torch.dtype`): the desired data type of returned tensor.
  19933. Has to be one of the quantized dtypes: ``torch.quint8``, ``torch.qint8``, ``torch.qint32``
  19934. Returns:
  19935. Tensor: A newly quantized tensor or list of quantized tensors.
  19936. Example::
  19937. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8)
  19938. tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
  19939. quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10)
  19940. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8).int_repr()
  19941. tensor([ 0, 10, 20, 30], dtype=torch.uint8)
  19942. >>> torch.quantize_per_tensor([torch.tensor([-1.0, 0.0]), torch.tensor([-2.0, 2.0])],
  19943. >>> torch.tensor([0.1, 0.2]), torch.tensor([10, 20]), torch.quint8)
  19944. (tensor([-1., 0.], size=(2,), dtype=torch.quint8,
  19945. quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10),
  19946. tensor([-2., 2.], size=(2,), dtype=torch.quint8,
  19947. quantization_scheme=torch.per_tensor_affine, scale=0.2, zero_point=20))
  19948. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), torch.tensor(0.1), torch.tensor(10), torch.quint8)
  19949. tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
  19950. quantization_scheme=torch.per_tensor_affine, scale=0.10, zero_point=10)
  19951. """
  19952. @overload
  19953. def quantize_per_tensor(
  19954. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  19955. scales: Tensor,
  19956. zero_points: Tensor,
  19957. dtype: _dtype,
  19958. ) -> tuple[Tensor, ...]:
  19959. r"""
  19960. quantize_per_tensor(input, scale, zero_point, dtype) -> Tensor
  19961. Converts a float tensor to a quantized tensor with given scale and zero point.
  19962. Arguments:
  19963. input (Tensor): float tensor or list of tensors to quantize
  19964. scale (float or Tensor): scale to apply in quantization formula
  19965. zero_point (int or Tensor): offset in integer value that maps to float zero
  19966. dtype (:class:`torch.dtype`): the desired data type of returned tensor.
  19967. Has to be one of the quantized dtypes: ``torch.quint8``, ``torch.qint8``, ``torch.qint32``
  19968. Returns:
  19969. Tensor: A newly quantized tensor or list of quantized tensors.
  19970. Example::
  19971. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8)
  19972. tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
  19973. quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10)
  19974. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8).int_repr()
  19975. tensor([ 0, 10, 20, 30], dtype=torch.uint8)
  19976. >>> torch.quantize_per_tensor([torch.tensor([-1.0, 0.0]), torch.tensor([-2.0, 2.0])],
  19977. >>> torch.tensor([0.1, 0.2]), torch.tensor([10, 20]), torch.quint8)
  19978. (tensor([-1., 0.], size=(2,), dtype=torch.quint8,
  19979. quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10),
  19980. tensor([-2., 2.], size=(2,), dtype=torch.quint8,
  19981. quantization_scheme=torch.per_tensor_affine, scale=0.2, zero_point=20))
  19982. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), torch.tensor(0.1), torch.tensor(10), torch.quint8)
  19983. tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
  19984. quantization_scheme=torch.per_tensor_affine, scale=0.10, zero_point=10)
  19985. """
  19986. def quantize_per_tensor_dynamic(
  19987. input: Tensor,
  19988. dtype: _dtype,
  19989. reduce_range: _bool,
  19990. ) -> Tensor:
  19991. r"""
  19992. quantize_per_tensor_dynamic(input, dtype, reduce_range) -> Tensor
  19993. Converts a float tensor to a quantized tensor with scale and zero_point calculated
  19994. dynamically based on the input.
  19995. Arguments:
  19996. input (Tensor): float tensor or list of tensors to quantize
  19997. dtype (:class:`torch.dtype`): the desired data type of returned tensor.
  19998. Has to be one of the quantized dtypes: ``torch.quint8``, ``torch.qint8``
  19999. reduce_range (bool): a flag to indicate whether to reduce the range of quantized
  20000. data by 1 bit, it's required to avoid instruction overflow for some hardwares
  20001. Returns:
  20002. Tensor: A newly (dynamically) quantized tensor
  20003. Example::
  20004. >>> t = torch.quantize_per_tensor_dynamic(torch.tensor([-1.0, 0.0, 1.0, 2.0]), torch.quint8, False)
  20005. >>> print(t)
  20006. tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
  20007. quantization_scheme=torch.per_tensor_affine, scale=0.011764705882352941,
  20008. zero_point=85)
  20009. >>> t.int_repr()
  20010. tensor([ 0, 85, 170, 255], dtype=torch.uint8)
  20011. """
  20012. def quantized_batch_norm(
  20013. input: Tensor,
  20014. weight: Tensor | None,
  20015. bias: Tensor | None,
  20016. mean: Tensor,
  20017. var: Tensor,
  20018. eps: _float,
  20019. output_scale: _float,
  20020. output_zero_point: _int,
  20021. ) -> Tensor:
  20022. r"""
  20023. quantized_batch_norm(input, weight=None, bias=None, mean, var, eps, output_scale, output_zero_point) -> Tensor
  20024. Applies batch normalization on a 4D (NCHW) quantized tensor.
  20025. .. math::
  20026. y = \frac{x - \mathrm{E}[x]}{\sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta
  20027. Arguments:
  20028. input (Tensor): quantized tensor
  20029. weight (Tensor): float tensor that corresponds to the gamma, size C
  20030. bias (Tensor): float tensor that corresponds to the beta, size C
  20031. mean (Tensor): float mean value in batch normalization, size C
  20032. var (Tensor): float tensor for variance, size C
  20033. eps (float): a value added to the denominator for numerical stability.
  20034. output_scale (float): output quantized tensor scale
  20035. output_zero_point (int): output quantized tensor zero_point
  20036. Returns:
  20037. Tensor: A quantized tensor with batch normalization applied.
  20038. Example::
  20039. >>> qx = torch.quantize_per_tensor(torch.rand(2, 2, 2, 2), 1.5, 3, torch.quint8)
  20040. >>> torch.quantized_batch_norm(qx, torch.ones(2), torch.zeros(2), torch.rand(2), torch.rand(2), 0.00001, 0.2, 2)
  20041. tensor([[[[-0.2000, -0.2000],
  20042. [ 1.6000, -0.2000]],
  20043. [[-0.4000, -0.4000],
  20044. [-0.4000, 0.6000]]],
  20045. [[[-0.2000, -0.2000],
  20046. [-0.2000, -0.2000]],
  20047. [[ 0.6000, -0.4000],
  20048. [ 0.6000, -0.4000]]]], size=(2, 2, 2, 2), dtype=torch.quint8,
  20049. quantization_scheme=torch.per_tensor_affine, scale=0.2, zero_point=2)
  20050. """
  20051. def quantized_gru_cell(
  20052. input: Tensor,
  20053. hx: Tensor,
  20054. w_ih: Tensor,
  20055. w_hh: Tensor,
  20056. b_ih: Tensor,
  20057. b_hh: Tensor,
  20058. packed_ih: Tensor,
  20059. packed_hh: Tensor,
  20060. col_offsets_ih: Tensor,
  20061. col_offsets_hh: Tensor,
  20062. scale_ih: Number | _complex,
  20063. scale_hh: Number | _complex,
  20064. zero_point_ih: Number | _complex,
  20065. zero_point_hh: Number | _complex,
  20066. ) -> Tensor: ...
  20067. def quantized_lstm_cell(
  20068. input: Tensor,
  20069. hx: tuple[Tensor, ...] | list[Tensor] | None,
  20070. w_ih: Tensor,
  20071. w_hh: Tensor,
  20072. b_ih: Tensor,
  20073. b_hh: Tensor,
  20074. packed_ih: Tensor,
  20075. packed_hh: Tensor,
  20076. col_offsets_ih: Tensor,
  20077. col_offsets_hh: Tensor,
  20078. scale_ih: Number | _complex,
  20079. scale_hh: Number | _complex,
  20080. zero_point_ih: Number | _complex,
  20081. zero_point_hh: Number | _complex,
  20082. ) -> tuple[Tensor, Tensor]: ...
  20083. def quantized_max_pool1d(
  20084. input: Tensor,
  20085. kernel_size: _int | _size,
  20086. stride: _int | _size = (),
  20087. padding: _int | _size = 0,
  20088. dilation: _int | _size = 1,
  20089. ceil_mode: _bool = False,
  20090. ) -> Tensor:
  20091. r"""
  20092. quantized_max_pool1d(input, kernel_size, stride=[], padding=0, dilation=1, ceil_mode=False) -> Tensor
  20093. Applies a 1D max pooling over an input quantized tensor composed of several input planes.
  20094. Arguments:
  20095. input (Tensor): quantized tensor
  20096. kernel_size (list of int): the size of the sliding window
  20097. stride (``list of int``, optional): the stride of the sliding window
  20098. padding (``list of int``, optional): padding to be added on both sides, must be >= 0 and <= kernel_size / 2
  20099. dilation (``list of int``, optional): The stride between elements within a sliding window, must be > 0. Default 1
  20100. ceil_mode (bool, optional): If True, will use ceil instead of floor to compute the output shape.
  20101. Defaults to False.
  20102. Returns:
  20103. Tensor: A quantized tensor with max_pool1d applied.
  20104. Example::
  20105. >>> qx = torch.quantize_per_tensor(torch.rand(2, 2), 1.5, 3, torch.quint8)
  20106. >>> torch.quantized_max_pool1d(qx, [2])
  20107. tensor([[0.0000],
  20108. [1.5000]], size=(2, 1), dtype=torch.quint8,
  20109. quantization_scheme=torch.per_tensor_affine, scale=1.5, zero_point=3)
  20110. """
  20111. def quantized_max_pool2d(
  20112. input: Tensor,
  20113. kernel_size: _int | _size,
  20114. stride: _int | _size = (),
  20115. padding: _int | _size = 0,
  20116. dilation: _int | _size = 1,
  20117. ceil_mode: _bool = False,
  20118. ) -> Tensor:
  20119. r"""
  20120. quantized_max_pool2d(input, kernel_size, stride=[], padding=0, dilation=1, ceil_mode=False) -> Tensor
  20121. Applies a 2D max pooling over an input quantized tensor composed of several input planes.
  20122. Arguments:
  20123. input (Tensor): quantized tensor
  20124. kernel_size (``list of int``): the size of the sliding window
  20125. stride (``list of int``, optional): the stride of the sliding window
  20126. padding (``list of int``, optional): padding to be added on both sides, must be >= 0 and <= kernel_size / 2
  20127. dilation (``list of int``, optional): The stride between elements within a sliding window, must be > 0. Default 1
  20128. ceil_mode (bool, optional): If True, will use ceil instead of floor to compute the output shape.
  20129. Defaults to False.
  20130. Returns:
  20131. Tensor: A quantized tensor with max_pool2d applied.
  20132. Example::
  20133. >>> qx = torch.quantize_per_tensor(torch.rand(2, 2, 2, 2), 1.5, 3, torch.quint8)
  20134. >>> torch.quantized_max_pool2d(qx, [2,2])
  20135. tensor([[[[1.5000]],
  20136. [[1.5000]]],
  20137. [[[0.0000]],
  20138. [[0.0000]]]], size=(2, 2, 1, 1), dtype=torch.quint8,
  20139. quantization_scheme=torch.per_tensor_affine, scale=1.5, zero_point=3)
  20140. """
  20141. def quantized_max_pool3d(
  20142. input: Tensor,
  20143. kernel_size: _int | _size,
  20144. stride: _int | _size = (),
  20145. padding: _int | _size = 0,
  20146. dilation: _int | _size = 1,
  20147. ceil_mode: _bool = False,
  20148. ) -> Tensor: ...
  20149. def quantized_rnn_relu_cell(
  20150. input: Tensor,
  20151. hx: Tensor,
  20152. w_ih: Tensor,
  20153. w_hh: Tensor,
  20154. b_ih: Tensor,
  20155. b_hh: Tensor,
  20156. packed_ih: Tensor,
  20157. packed_hh: Tensor,
  20158. col_offsets_ih: Tensor,
  20159. col_offsets_hh: Tensor,
  20160. scale_ih: Number | _complex,
  20161. scale_hh: Number | _complex,
  20162. zero_point_ih: Number | _complex,
  20163. zero_point_hh: Number | _complex,
  20164. ) -> Tensor: ...
  20165. def quantized_rnn_tanh_cell(
  20166. input: Tensor,
  20167. hx: Tensor,
  20168. w_ih: Tensor,
  20169. w_hh: Tensor,
  20170. b_ih: Tensor,
  20171. b_hh: Tensor,
  20172. packed_ih: Tensor,
  20173. packed_hh: Tensor,
  20174. col_offsets_ih: Tensor,
  20175. col_offsets_hh: Tensor,
  20176. scale_ih: Number | _complex,
  20177. scale_hh: Number | _complex,
  20178. zero_point_ih: Number | _complex,
  20179. zero_point_hh: Number | _complex,
  20180. ) -> Tensor: ...
  20181. def rad2deg(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  20182. r"""
  20183. rad2deg(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  20184. Returns a new tensor with each of the elements of :attr:`input`
  20185. converted from angles in radians to degrees.
  20186. Args:
  20187. input (Tensor): the input tensor.
  20188. Keyword arguments:
  20189. out (Tensor, optional): the output tensor.
  20190. Example::
  20191. >>> a = torch.tensor([[3.142, -3.142], [6.283, -6.283], [1.570, -1.570]])
  20192. >>> torch.rad2deg(a)
  20193. tensor([[ 180.0233, -180.0233],
  20194. [ 359.9894, -359.9894],
  20195. [ 89.9544, -89.9544]])
  20196. """
  20197. def rad2deg_(input: Tensor) -> Tensor: ...
  20198. @overload
  20199. def rand(
  20200. size: Sequence[_int | SymInt],
  20201. *,
  20202. generator: Generator | None,
  20203. names: Sequence[str | EllipsisType | None] | None,
  20204. dtype: _dtype | None = None,
  20205. layout: _layout | None = None,
  20206. device: DeviceLikeType | None = None,
  20207. pin_memory: _bool | None = False,
  20208. requires_grad: _bool | None = False,
  20209. ) -> Tensor:
  20210. r"""
  20211. rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  20212. Returns a tensor filled with random numbers from a uniform distribution
  20213. on the interval :math:`[0, 1)`
  20214. The shape of the tensor is defined by the variable argument :attr:`size`.
  20215. Args:
  20216. size (int...): a sequence of integers defining the shape of the output tensor.
  20217. Can be a variable number of arguments or a collection like a list or tuple.
  20218. Keyword args:
  20219. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20220. out (Tensor, optional): the output tensor.
  20221. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  20222. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  20223. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20224. Default: ``torch.strided``.
  20225. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20226. Default: if ``None``, uses the current device for the default tensor type
  20227. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20228. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20229. requires_grad (bool, optional): If autograd should record operations on the
  20230. returned tensor. Default: ``False``.
  20231. pin_memory (bool, optional): If set, returned tensor would be allocated in
  20232. the pinned memory. Works only for CPU tensors. Default: ``False``.
  20233. Example::
  20234. >>> torch.rand(4)
  20235. tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
  20236. >>> torch.rand(2, 3)
  20237. tensor([[ 0.8237, 0.5781, 0.6879],
  20238. [ 0.3816, 0.7249, 0.0998]])
  20239. """
  20240. @overload
  20241. def rand(
  20242. *size: _int | SymInt,
  20243. generator: Generator | None,
  20244. names: Sequence[str | EllipsisType | None] | None,
  20245. dtype: _dtype | None = None,
  20246. layout: _layout | None = None,
  20247. device: DeviceLikeType | None = None,
  20248. pin_memory: _bool | None = False,
  20249. requires_grad: _bool | None = False,
  20250. ) -> Tensor:
  20251. r"""
  20252. rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  20253. Returns a tensor filled with random numbers from a uniform distribution
  20254. on the interval :math:`[0, 1)`
  20255. The shape of the tensor is defined by the variable argument :attr:`size`.
  20256. Args:
  20257. size (int...): a sequence of integers defining the shape of the output tensor.
  20258. Can be a variable number of arguments or a collection like a list or tuple.
  20259. Keyword args:
  20260. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20261. out (Tensor, optional): the output tensor.
  20262. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  20263. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  20264. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20265. Default: ``torch.strided``.
  20266. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20267. Default: if ``None``, uses the current device for the default tensor type
  20268. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20269. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20270. requires_grad (bool, optional): If autograd should record operations on the
  20271. returned tensor. Default: ``False``.
  20272. pin_memory (bool, optional): If set, returned tensor would be allocated in
  20273. the pinned memory. Works only for CPU tensors. Default: ``False``.
  20274. Example::
  20275. >>> torch.rand(4)
  20276. tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
  20277. >>> torch.rand(2, 3)
  20278. tensor([[ 0.8237, 0.5781, 0.6879],
  20279. [ 0.3816, 0.7249, 0.0998]])
  20280. """
  20281. @overload
  20282. def rand(
  20283. size: Sequence[_int | SymInt],
  20284. *,
  20285. generator: Generator | None,
  20286. out: Tensor | None = None,
  20287. dtype: _dtype | None = None,
  20288. layout: _layout | None = None,
  20289. device: DeviceLikeType | None = None,
  20290. pin_memory: _bool | None = False,
  20291. requires_grad: _bool | None = False,
  20292. ) -> Tensor:
  20293. r"""
  20294. rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  20295. Returns a tensor filled with random numbers from a uniform distribution
  20296. on the interval :math:`[0, 1)`
  20297. The shape of the tensor is defined by the variable argument :attr:`size`.
  20298. Args:
  20299. size (int...): a sequence of integers defining the shape of the output tensor.
  20300. Can be a variable number of arguments or a collection like a list or tuple.
  20301. Keyword args:
  20302. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20303. out (Tensor, optional): the output tensor.
  20304. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  20305. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  20306. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20307. Default: ``torch.strided``.
  20308. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20309. Default: if ``None``, uses the current device for the default tensor type
  20310. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20311. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20312. requires_grad (bool, optional): If autograd should record operations on the
  20313. returned tensor. Default: ``False``.
  20314. pin_memory (bool, optional): If set, returned tensor would be allocated in
  20315. the pinned memory. Works only for CPU tensors. Default: ``False``.
  20316. Example::
  20317. >>> torch.rand(4)
  20318. tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
  20319. >>> torch.rand(2, 3)
  20320. tensor([[ 0.8237, 0.5781, 0.6879],
  20321. [ 0.3816, 0.7249, 0.0998]])
  20322. """
  20323. @overload
  20324. def rand(
  20325. *size: _int | SymInt,
  20326. generator: Generator | None,
  20327. out: Tensor | None = None,
  20328. dtype: _dtype | None = None,
  20329. layout: _layout | None = None,
  20330. device: DeviceLikeType | None = None,
  20331. pin_memory: _bool | None = False,
  20332. requires_grad: _bool | None = False,
  20333. ) -> Tensor:
  20334. r"""
  20335. rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  20336. Returns a tensor filled with random numbers from a uniform distribution
  20337. on the interval :math:`[0, 1)`
  20338. The shape of the tensor is defined by the variable argument :attr:`size`.
  20339. Args:
  20340. size (int...): a sequence of integers defining the shape of the output tensor.
  20341. Can be a variable number of arguments or a collection like a list or tuple.
  20342. Keyword args:
  20343. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20344. out (Tensor, optional): the output tensor.
  20345. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  20346. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  20347. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20348. Default: ``torch.strided``.
  20349. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20350. Default: if ``None``, uses the current device for the default tensor type
  20351. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20352. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20353. requires_grad (bool, optional): If autograd should record operations on the
  20354. returned tensor. Default: ``False``.
  20355. pin_memory (bool, optional): If set, returned tensor would be allocated in
  20356. the pinned memory. Works only for CPU tensors. Default: ``False``.
  20357. Example::
  20358. >>> torch.rand(4)
  20359. tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
  20360. >>> torch.rand(2, 3)
  20361. tensor([[ 0.8237, 0.5781, 0.6879],
  20362. [ 0.3816, 0.7249, 0.0998]])
  20363. """
  20364. @overload
  20365. def rand(
  20366. size: Sequence[_int | SymInt],
  20367. *,
  20368. out: Tensor | None = None,
  20369. dtype: _dtype | None = None,
  20370. layout: _layout | None = None,
  20371. device: DeviceLikeType | None = None,
  20372. pin_memory: _bool | None = False,
  20373. requires_grad: _bool | None = False,
  20374. ) -> Tensor:
  20375. r"""
  20376. rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  20377. Returns a tensor filled with random numbers from a uniform distribution
  20378. on the interval :math:`[0, 1)`
  20379. The shape of the tensor is defined by the variable argument :attr:`size`.
  20380. Args:
  20381. size (int...): a sequence of integers defining the shape of the output tensor.
  20382. Can be a variable number of arguments or a collection like a list or tuple.
  20383. Keyword args:
  20384. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20385. out (Tensor, optional): the output tensor.
  20386. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  20387. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  20388. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20389. Default: ``torch.strided``.
  20390. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20391. Default: if ``None``, uses the current device for the default tensor type
  20392. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20393. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20394. requires_grad (bool, optional): If autograd should record operations on the
  20395. returned tensor. Default: ``False``.
  20396. pin_memory (bool, optional): If set, returned tensor would be allocated in
  20397. the pinned memory. Works only for CPU tensors. Default: ``False``.
  20398. Example::
  20399. >>> torch.rand(4)
  20400. tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
  20401. >>> torch.rand(2, 3)
  20402. tensor([[ 0.8237, 0.5781, 0.6879],
  20403. [ 0.3816, 0.7249, 0.0998]])
  20404. """
  20405. @overload
  20406. def rand(
  20407. *size: _int | SymInt,
  20408. out: Tensor | None = None,
  20409. dtype: _dtype | None = None,
  20410. layout: _layout | None = None,
  20411. device: DeviceLikeType | None = None,
  20412. pin_memory: _bool | None = False,
  20413. requires_grad: _bool | None = False,
  20414. ) -> Tensor:
  20415. r"""
  20416. rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  20417. Returns a tensor filled with random numbers from a uniform distribution
  20418. on the interval :math:`[0, 1)`
  20419. The shape of the tensor is defined by the variable argument :attr:`size`.
  20420. Args:
  20421. size (int...): a sequence of integers defining the shape of the output tensor.
  20422. Can be a variable number of arguments or a collection like a list or tuple.
  20423. Keyword args:
  20424. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20425. out (Tensor, optional): the output tensor.
  20426. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  20427. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  20428. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20429. Default: ``torch.strided``.
  20430. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20431. Default: if ``None``, uses the current device for the default tensor type
  20432. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20433. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20434. requires_grad (bool, optional): If autograd should record operations on the
  20435. returned tensor. Default: ``False``.
  20436. pin_memory (bool, optional): If set, returned tensor would be allocated in
  20437. the pinned memory. Works only for CPU tensors. Default: ``False``.
  20438. Example::
  20439. >>> torch.rand(4)
  20440. tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
  20441. >>> torch.rand(2, 3)
  20442. tensor([[ 0.8237, 0.5781, 0.6879],
  20443. [ 0.3816, 0.7249, 0.0998]])
  20444. """
  20445. @overload
  20446. def rand(
  20447. size: Sequence[_int | SymInt],
  20448. *,
  20449. names: Sequence[str | EllipsisType | None] | None,
  20450. dtype: _dtype | None = None,
  20451. layout: _layout | None = None,
  20452. device: DeviceLikeType | None = None,
  20453. pin_memory: _bool | None = False,
  20454. requires_grad: _bool | None = False,
  20455. ) -> Tensor:
  20456. r"""
  20457. rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  20458. Returns a tensor filled with random numbers from a uniform distribution
  20459. on the interval :math:`[0, 1)`
  20460. The shape of the tensor is defined by the variable argument :attr:`size`.
  20461. Args:
  20462. size (int...): a sequence of integers defining the shape of the output tensor.
  20463. Can be a variable number of arguments or a collection like a list or tuple.
  20464. Keyword args:
  20465. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20466. out (Tensor, optional): the output tensor.
  20467. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  20468. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  20469. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20470. Default: ``torch.strided``.
  20471. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20472. Default: if ``None``, uses the current device for the default tensor type
  20473. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20474. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20475. requires_grad (bool, optional): If autograd should record operations on the
  20476. returned tensor. Default: ``False``.
  20477. pin_memory (bool, optional): If set, returned tensor would be allocated in
  20478. the pinned memory. Works only for CPU tensors. Default: ``False``.
  20479. Example::
  20480. >>> torch.rand(4)
  20481. tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
  20482. >>> torch.rand(2, 3)
  20483. tensor([[ 0.8237, 0.5781, 0.6879],
  20484. [ 0.3816, 0.7249, 0.0998]])
  20485. """
  20486. @overload
  20487. def rand(
  20488. *size: _int | SymInt,
  20489. names: Sequence[str | EllipsisType | None] | None,
  20490. dtype: _dtype | None = None,
  20491. layout: _layout | None = None,
  20492. device: DeviceLikeType | None = None,
  20493. pin_memory: _bool | None = False,
  20494. requires_grad: _bool | None = False,
  20495. ) -> Tensor:
  20496. r"""
  20497. rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  20498. Returns a tensor filled with random numbers from a uniform distribution
  20499. on the interval :math:`[0, 1)`
  20500. The shape of the tensor is defined by the variable argument :attr:`size`.
  20501. Args:
  20502. size (int...): a sequence of integers defining the shape of the output tensor.
  20503. Can be a variable number of arguments or a collection like a list or tuple.
  20504. Keyword args:
  20505. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20506. out (Tensor, optional): the output tensor.
  20507. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  20508. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  20509. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20510. Default: ``torch.strided``.
  20511. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20512. Default: if ``None``, uses the current device for the default tensor type
  20513. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20514. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20515. requires_grad (bool, optional): If autograd should record operations on the
  20516. returned tensor. Default: ``False``.
  20517. pin_memory (bool, optional): If set, returned tensor would be allocated in
  20518. the pinned memory. Works only for CPU tensors. Default: ``False``.
  20519. Example::
  20520. >>> torch.rand(4)
  20521. tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
  20522. >>> torch.rand(2, 3)
  20523. tensor([[ 0.8237, 0.5781, 0.6879],
  20524. [ 0.3816, 0.7249, 0.0998]])
  20525. """
  20526. def rand_like(
  20527. input: Tensor,
  20528. *,
  20529. memory_format: memory_format | None = None,
  20530. dtype: _dtype | None = None,
  20531. layout: _layout | None = None,
  20532. device: DeviceLikeType | None = None,
  20533. pin_memory: _bool | None = False,
  20534. requires_grad: _bool | None = False,
  20535. ) -> Tensor:
  20536. r"""
  20537. rand_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  20538. Returns a tensor with the same size as :attr:`input` that is filled with
  20539. random numbers from a uniform distribution on the interval :math:`[0, 1)`.
  20540. ``torch.rand_like(input)`` is equivalent to
  20541. ``torch.rand(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
  20542. Args:
  20543. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  20544. Keyword args:
  20545. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  20546. Default: if ``None``, defaults to the dtype of :attr:`input`.
  20547. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  20548. Default: if ``None``, defaults to the layout of :attr:`input`.
  20549. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20550. Default: if ``None``, defaults to the device of :attr:`input`.
  20551. requires_grad (bool, optional): If autograd should record operations on the
  20552. returned tensor. Default: ``False``.
  20553. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  20554. returned Tensor. Default: ``torch.preserve_format``.
  20555. """
  20556. @overload
  20557. def randint(
  20558. low: _int,
  20559. high: _int,
  20560. size: _size,
  20561. *,
  20562. generator: Generator | None = None,
  20563. dtype: _dtype | None = None,
  20564. device: DeviceLikeType | None = None,
  20565. requires_grad: _bool = False,
  20566. pin_memory: _bool = False,
  20567. ) -> Tensor:
  20568. r"""
  20569. randint(low=0, high, size, \*, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  20570. Returns a tensor filled with random integers generated uniformly
  20571. between :attr:`low` (inclusive) and :attr:`high` (exclusive).
  20572. The shape of the tensor is defined by the variable argument :attr:`size`.
  20573. .. note::
  20574. With the global dtype default (``torch.float32``), this function returns
  20575. a tensor with dtype ``torch.int64``.
  20576. Args:
  20577. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  20578. high (int): One above the highest integer to be drawn from the distribution.
  20579. size (tuple): a tuple defining the shape of the output tensor.
  20580. Keyword args:
  20581. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20582. out (Tensor, optional): the output tensor.
  20583. dtype (torch.dtype, optional): the desired data type of returned tensor. Default: if ``None``,
  20584. this function returns a tensor with dtype ``torch.int64``.
  20585. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20586. Default: ``torch.strided``.
  20587. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20588. Default: if ``None``, uses the current device for the default tensor type
  20589. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20590. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20591. requires_grad (bool, optional): If autograd should record operations on the
  20592. returned tensor. Default: ``False``.
  20593. Example::
  20594. >>> torch.randint(3, 5, (3,))
  20595. tensor([4, 3, 4])
  20596. >>> torch.randint(10, (2, 2))
  20597. tensor([[0, 2],
  20598. [5, 5]])
  20599. >>> torch.randint(3, 10, (2, 2))
  20600. tensor([[4, 5],
  20601. [6, 7]])
  20602. """
  20603. @overload
  20604. def randint(
  20605. high: _int,
  20606. size: _size,
  20607. *,
  20608. generator: Generator | None = None,
  20609. dtype: _dtype | None = None,
  20610. device: DeviceLikeType | None = None,
  20611. requires_grad: _bool = False,
  20612. pin_memory: _bool = False,
  20613. ) -> Tensor:
  20614. r"""
  20615. randint(low=0, high, size, \*, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  20616. Returns a tensor filled with random integers generated uniformly
  20617. between :attr:`low` (inclusive) and :attr:`high` (exclusive).
  20618. The shape of the tensor is defined by the variable argument :attr:`size`.
  20619. .. note::
  20620. With the global dtype default (``torch.float32``), this function returns
  20621. a tensor with dtype ``torch.int64``.
  20622. Args:
  20623. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  20624. high (int): One above the highest integer to be drawn from the distribution.
  20625. size (tuple): a tuple defining the shape of the output tensor.
  20626. Keyword args:
  20627. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20628. out (Tensor, optional): the output tensor.
  20629. dtype (torch.dtype, optional): the desired data type of returned tensor. Default: if ``None``,
  20630. this function returns a tensor with dtype ``torch.int64``.
  20631. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20632. Default: ``torch.strided``.
  20633. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20634. Default: if ``None``, uses the current device for the default tensor type
  20635. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20636. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20637. requires_grad (bool, optional): If autograd should record operations on the
  20638. returned tensor. Default: ``False``.
  20639. Example::
  20640. >>> torch.randint(3, 5, (3,))
  20641. tensor([4, 3, 4])
  20642. >>> torch.randint(10, (2, 2))
  20643. tensor([[0, 2],
  20644. [5, 5]])
  20645. >>> torch.randint(3, 10, (2, 2))
  20646. tensor([[4, 5],
  20647. [6, 7]])
  20648. """
  20649. @overload
  20650. def randint(
  20651. high: _int | SymInt,
  20652. size: Sequence[_int | SymInt],
  20653. *,
  20654. generator: Generator | None,
  20655. out: Tensor | None = None,
  20656. dtype: _dtype | None = None,
  20657. layout: _layout | None = None,
  20658. device: DeviceLikeType | None = None,
  20659. pin_memory: _bool | None = False,
  20660. requires_grad: _bool | None = False,
  20661. ) -> Tensor:
  20662. r"""
  20663. randint(low=0, high, size, \*, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  20664. Returns a tensor filled with random integers generated uniformly
  20665. between :attr:`low` (inclusive) and :attr:`high` (exclusive).
  20666. The shape of the tensor is defined by the variable argument :attr:`size`.
  20667. .. note::
  20668. With the global dtype default (``torch.float32``), this function returns
  20669. a tensor with dtype ``torch.int64``.
  20670. Args:
  20671. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  20672. high (int): One above the highest integer to be drawn from the distribution.
  20673. size (tuple): a tuple defining the shape of the output tensor.
  20674. Keyword args:
  20675. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20676. out (Tensor, optional): the output tensor.
  20677. dtype (torch.dtype, optional): the desired data type of returned tensor. Default: if ``None``,
  20678. this function returns a tensor with dtype ``torch.int64``.
  20679. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20680. Default: ``torch.strided``.
  20681. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20682. Default: if ``None``, uses the current device for the default tensor type
  20683. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20684. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20685. requires_grad (bool, optional): If autograd should record operations on the
  20686. returned tensor. Default: ``False``.
  20687. Example::
  20688. >>> torch.randint(3, 5, (3,))
  20689. tensor([4, 3, 4])
  20690. >>> torch.randint(10, (2, 2))
  20691. tensor([[0, 2],
  20692. [5, 5]])
  20693. >>> torch.randint(3, 10, (2, 2))
  20694. tensor([[4, 5],
  20695. [6, 7]])
  20696. """
  20697. @overload
  20698. def randint(
  20699. high: _int | SymInt,
  20700. size: Sequence[_int | SymInt],
  20701. *,
  20702. out: Tensor | None = None,
  20703. dtype: _dtype | None = None,
  20704. layout: _layout | None = None,
  20705. device: DeviceLikeType | None = None,
  20706. pin_memory: _bool | None = False,
  20707. requires_grad: _bool | None = False,
  20708. ) -> Tensor:
  20709. r"""
  20710. randint(low=0, high, size, \*, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  20711. Returns a tensor filled with random integers generated uniformly
  20712. between :attr:`low` (inclusive) and :attr:`high` (exclusive).
  20713. The shape of the tensor is defined by the variable argument :attr:`size`.
  20714. .. note::
  20715. With the global dtype default (``torch.float32``), this function returns
  20716. a tensor with dtype ``torch.int64``.
  20717. Args:
  20718. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  20719. high (int): One above the highest integer to be drawn from the distribution.
  20720. size (tuple): a tuple defining the shape of the output tensor.
  20721. Keyword args:
  20722. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20723. out (Tensor, optional): the output tensor.
  20724. dtype (torch.dtype, optional): the desired data type of returned tensor. Default: if ``None``,
  20725. this function returns a tensor with dtype ``torch.int64``.
  20726. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20727. Default: ``torch.strided``.
  20728. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20729. Default: if ``None``, uses the current device for the default tensor type
  20730. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20731. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20732. requires_grad (bool, optional): If autograd should record operations on the
  20733. returned tensor. Default: ``False``.
  20734. Example::
  20735. >>> torch.randint(3, 5, (3,))
  20736. tensor([4, 3, 4])
  20737. >>> torch.randint(10, (2, 2))
  20738. tensor([[0, 2],
  20739. [5, 5]])
  20740. >>> torch.randint(3, 10, (2, 2))
  20741. tensor([[4, 5],
  20742. [6, 7]])
  20743. """
  20744. @overload
  20745. def randint(
  20746. low: _int | SymInt,
  20747. high: _int | SymInt,
  20748. size: Sequence[_int | SymInt],
  20749. *,
  20750. generator: Generator | None,
  20751. out: Tensor | None = None,
  20752. dtype: _dtype | None = None,
  20753. layout: _layout | None = None,
  20754. device: DeviceLikeType | None = None,
  20755. pin_memory: _bool | None = False,
  20756. requires_grad: _bool | None = False,
  20757. ) -> Tensor:
  20758. r"""
  20759. randint(low=0, high, size, \*, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  20760. Returns a tensor filled with random integers generated uniformly
  20761. between :attr:`low` (inclusive) and :attr:`high` (exclusive).
  20762. The shape of the tensor is defined by the variable argument :attr:`size`.
  20763. .. note::
  20764. With the global dtype default (``torch.float32``), this function returns
  20765. a tensor with dtype ``torch.int64``.
  20766. Args:
  20767. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  20768. high (int): One above the highest integer to be drawn from the distribution.
  20769. size (tuple): a tuple defining the shape of the output tensor.
  20770. Keyword args:
  20771. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20772. out (Tensor, optional): the output tensor.
  20773. dtype (torch.dtype, optional): the desired data type of returned tensor. Default: if ``None``,
  20774. this function returns a tensor with dtype ``torch.int64``.
  20775. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20776. Default: ``torch.strided``.
  20777. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20778. Default: if ``None``, uses the current device for the default tensor type
  20779. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20780. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20781. requires_grad (bool, optional): If autograd should record operations on the
  20782. returned tensor. Default: ``False``.
  20783. Example::
  20784. >>> torch.randint(3, 5, (3,))
  20785. tensor([4, 3, 4])
  20786. >>> torch.randint(10, (2, 2))
  20787. tensor([[0, 2],
  20788. [5, 5]])
  20789. >>> torch.randint(3, 10, (2, 2))
  20790. tensor([[4, 5],
  20791. [6, 7]])
  20792. """
  20793. @overload
  20794. def randint(
  20795. low: _int | SymInt,
  20796. high: _int | SymInt,
  20797. size: Sequence[_int | SymInt],
  20798. *,
  20799. out: Tensor | None = None,
  20800. dtype: _dtype | None = None,
  20801. layout: _layout | None = None,
  20802. device: DeviceLikeType | None = None,
  20803. pin_memory: _bool | None = False,
  20804. requires_grad: _bool | None = False,
  20805. ) -> Tensor:
  20806. r"""
  20807. randint(low=0, high, size, \*, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  20808. Returns a tensor filled with random integers generated uniformly
  20809. between :attr:`low` (inclusive) and :attr:`high` (exclusive).
  20810. The shape of the tensor is defined by the variable argument :attr:`size`.
  20811. .. note::
  20812. With the global dtype default (``torch.float32``), this function returns
  20813. a tensor with dtype ``torch.int64``.
  20814. Args:
  20815. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  20816. high (int): One above the highest integer to be drawn from the distribution.
  20817. size (tuple): a tuple defining the shape of the output tensor.
  20818. Keyword args:
  20819. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20820. out (Tensor, optional): the output tensor.
  20821. dtype (torch.dtype, optional): the desired data type of returned tensor. Default: if ``None``,
  20822. this function returns a tensor with dtype ``torch.int64``.
  20823. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20824. Default: ``torch.strided``.
  20825. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20826. Default: if ``None``, uses the current device for the default tensor type
  20827. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20828. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20829. requires_grad (bool, optional): If autograd should record operations on the
  20830. returned tensor. Default: ``False``.
  20831. Example::
  20832. >>> torch.randint(3, 5, (3,))
  20833. tensor([4, 3, 4])
  20834. >>> torch.randint(10, (2, 2))
  20835. tensor([[0, 2],
  20836. [5, 5]])
  20837. >>> torch.randint(3, 10, (2, 2))
  20838. tensor([[4, 5],
  20839. [6, 7]])
  20840. """
  20841. @overload
  20842. def randint_like(
  20843. input: Tensor,
  20844. low: _int | SymInt,
  20845. high: _int | SymInt,
  20846. *,
  20847. memory_format: memory_format | None = None,
  20848. dtype: _dtype | None = None,
  20849. layout: _layout | None = None,
  20850. device: DeviceLikeType | None = None,
  20851. pin_memory: _bool | None = False,
  20852. requires_grad: _bool | None = False,
  20853. ) -> Tensor:
  20854. r"""
  20855. randint_like(input, low=0, high, \*, dtype=None, layout=torch.strided, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  20856. Returns a tensor with the same shape as Tensor :attr:`input` filled with
  20857. random integers generated uniformly between :attr:`low` (inclusive) and
  20858. :attr:`high` (exclusive).
  20859. .. note:
  20860. With the global dtype default (``torch.float32``), this function returns
  20861. a tensor with dtype ``torch.int64``.
  20862. Args:
  20863. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  20864. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  20865. high (int): One above the highest integer to be drawn from the distribution.
  20866. Keyword args:
  20867. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  20868. Default: if ``None``, defaults to the dtype of :attr:`input`.
  20869. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  20870. Default: if ``None``, defaults to the layout of :attr:`input`.
  20871. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20872. Default: if ``None``, defaults to the device of :attr:`input`.
  20873. requires_grad (bool, optional): If autograd should record operations on the
  20874. returned tensor. Default: ``False``.
  20875. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  20876. returned Tensor. Default: ``torch.preserve_format``.
  20877. """
  20878. @overload
  20879. def randint_like(
  20880. input: Tensor,
  20881. high: Tensor,
  20882. *,
  20883. memory_format: memory_format | None = None,
  20884. dtype: _dtype | None = None,
  20885. layout: _layout | None = None,
  20886. device: DeviceLikeType | None = None,
  20887. pin_memory: _bool | None = False,
  20888. requires_grad: _bool | None = False,
  20889. ) -> Tensor:
  20890. r"""
  20891. randint_like(input, low=0, high, \*, dtype=None, layout=torch.strided, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  20892. Returns a tensor with the same shape as Tensor :attr:`input` filled with
  20893. random integers generated uniformly between :attr:`low` (inclusive) and
  20894. :attr:`high` (exclusive).
  20895. .. note:
  20896. With the global dtype default (``torch.float32``), this function returns
  20897. a tensor with dtype ``torch.int64``.
  20898. Args:
  20899. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  20900. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  20901. high (int): One above the highest integer to be drawn from the distribution.
  20902. Keyword args:
  20903. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  20904. Default: if ``None``, defaults to the dtype of :attr:`input`.
  20905. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  20906. Default: if ``None``, defaults to the layout of :attr:`input`.
  20907. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20908. Default: if ``None``, defaults to the device of :attr:`input`.
  20909. requires_grad (bool, optional): If autograd should record operations on the
  20910. returned tensor. Default: ``False``.
  20911. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  20912. returned Tensor. Default: ``torch.preserve_format``.
  20913. """
  20914. @overload
  20915. def randint_like(
  20916. input: Tensor,
  20917. high: _int | SymInt,
  20918. *,
  20919. memory_format: memory_format | None = None,
  20920. dtype: _dtype | None = None,
  20921. layout: _layout | None = None,
  20922. device: DeviceLikeType | None = None,
  20923. pin_memory: _bool | None = False,
  20924. requires_grad: _bool | None = False,
  20925. ) -> Tensor:
  20926. r"""
  20927. randint_like(input, low=0, high, \*, dtype=None, layout=torch.strided, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  20928. Returns a tensor with the same shape as Tensor :attr:`input` filled with
  20929. random integers generated uniformly between :attr:`low` (inclusive) and
  20930. :attr:`high` (exclusive).
  20931. .. note:
  20932. With the global dtype default (``torch.float32``), this function returns
  20933. a tensor with dtype ``torch.int64``.
  20934. Args:
  20935. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  20936. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  20937. high (int): One above the highest integer to be drawn from the distribution.
  20938. Keyword args:
  20939. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  20940. Default: if ``None``, defaults to the dtype of :attr:`input`.
  20941. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  20942. Default: if ``None``, defaults to the layout of :attr:`input`.
  20943. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20944. Default: if ``None``, defaults to the device of :attr:`input`.
  20945. requires_grad (bool, optional): If autograd should record operations on the
  20946. returned tensor. Default: ``False``.
  20947. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  20948. returned Tensor. Default: ``torch.preserve_format``.
  20949. """
  20950. @overload
  20951. def randn(
  20952. size: Sequence[_int | SymInt],
  20953. *,
  20954. generator: Generator | None,
  20955. names: Sequence[str | EllipsisType | None] | None,
  20956. dtype: _dtype | None = None,
  20957. layout: _layout | None = None,
  20958. device: DeviceLikeType | None = None,
  20959. pin_memory: _bool | None = False,
  20960. requires_grad: _bool | None = False,
  20961. ) -> Tensor:
  20962. r"""
  20963. randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  20964. Returns a tensor filled with random numbers from a normal distribution
  20965. with mean `0` and variance `1` (also called the standard normal
  20966. distribution).
  20967. .. math::
  20968. \text{out}_{i} \sim \mathcal{N}(0, 1)
  20969. For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
  20970. unit variance as
  20971. .. math::
  20972. \text{out}_{i} \sim \mathcal{CN}(0, 1)
  20973. This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
  20974. :math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
  20975. .. math::
  20976. \operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
  20977. \operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
  20978. The shape of the tensor is defined by the variable argument :attr:`size`.
  20979. Args:
  20980. size (int...): a sequence of integers defining the shape of the output tensor.
  20981. Can be a variable number of arguments or a collection like a list or tuple.
  20982. Keyword args:
  20983. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20984. out (Tensor, optional): the output tensor.
  20985. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  20986. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  20987. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20988. Default: ``torch.strided``.
  20989. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20990. Default: if ``None``, uses the current device for the default tensor type
  20991. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20992. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20993. requires_grad (bool, optional): If autograd should record operations on the
  20994. returned tensor. Default: ``False``.
  20995. pin_memory (bool, optional): If set, returned tensor would be allocated in
  20996. the pinned memory. Works only for CPU tensors. Default: ``False``.
  20997. Example::
  20998. >>> torch.randn(4)
  20999. tensor([-2.1436, 0.9966, 2.3426, -0.6366])
  21000. >>> torch.randn(2, 3)
  21001. tensor([[ 1.5954, 2.8929, -1.0923],
  21002. [ 1.1719, -0.4709, -0.1996]])
  21003. .. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
  21004. """
  21005. @overload
  21006. def randn(
  21007. *size: _int | SymInt,
  21008. generator: Generator | None,
  21009. names: Sequence[str | EllipsisType | None] | None,
  21010. dtype: _dtype | None = None,
  21011. layout: _layout | None = None,
  21012. device: DeviceLikeType | None = None,
  21013. pin_memory: _bool | None = False,
  21014. requires_grad: _bool | None = False,
  21015. ) -> Tensor:
  21016. r"""
  21017. randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21018. Returns a tensor filled with random numbers from a normal distribution
  21019. with mean `0` and variance `1` (also called the standard normal
  21020. distribution).
  21021. .. math::
  21022. \text{out}_{i} \sim \mathcal{N}(0, 1)
  21023. For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
  21024. unit variance as
  21025. .. math::
  21026. \text{out}_{i} \sim \mathcal{CN}(0, 1)
  21027. This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
  21028. :math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
  21029. .. math::
  21030. \operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
  21031. \operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
  21032. The shape of the tensor is defined by the variable argument :attr:`size`.
  21033. Args:
  21034. size (int...): a sequence of integers defining the shape of the output tensor.
  21035. Can be a variable number of arguments or a collection like a list or tuple.
  21036. Keyword args:
  21037. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21038. out (Tensor, optional): the output tensor.
  21039. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21040. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  21041. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21042. Default: ``torch.strided``.
  21043. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21044. Default: if ``None``, uses the current device for the default tensor type
  21045. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21046. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21047. requires_grad (bool, optional): If autograd should record operations on the
  21048. returned tensor. Default: ``False``.
  21049. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21050. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21051. Example::
  21052. >>> torch.randn(4)
  21053. tensor([-2.1436, 0.9966, 2.3426, -0.6366])
  21054. >>> torch.randn(2, 3)
  21055. tensor([[ 1.5954, 2.8929, -1.0923],
  21056. [ 1.1719, -0.4709, -0.1996]])
  21057. .. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
  21058. """
  21059. @overload
  21060. def randn(
  21061. size: Sequence[_int | SymInt],
  21062. *,
  21063. generator: Generator | None,
  21064. out: Tensor | None = None,
  21065. dtype: _dtype | None = None,
  21066. layout: _layout | None = None,
  21067. device: DeviceLikeType | None = None,
  21068. pin_memory: _bool | None = False,
  21069. requires_grad: _bool | None = False,
  21070. ) -> Tensor:
  21071. r"""
  21072. randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21073. Returns a tensor filled with random numbers from a normal distribution
  21074. with mean `0` and variance `1` (also called the standard normal
  21075. distribution).
  21076. .. math::
  21077. \text{out}_{i} \sim \mathcal{N}(0, 1)
  21078. For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
  21079. unit variance as
  21080. .. math::
  21081. \text{out}_{i} \sim \mathcal{CN}(0, 1)
  21082. This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
  21083. :math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
  21084. .. math::
  21085. \operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
  21086. \operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
  21087. The shape of the tensor is defined by the variable argument :attr:`size`.
  21088. Args:
  21089. size (int...): a sequence of integers defining the shape of the output tensor.
  21090. Can be a variable number of arguments or a collection like a list or tuple.
  21091. Keyword args:
  21092. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21093. out (Tensor, optional): the output tensor.
  21094. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21095. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  21096. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21097. Default: ``torch.strided``.
  21098. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21099. Default: if ``None``, uses the current device for the default tensor type
  21100. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21101. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21102. requires_grad (bool, optional): If autograd should record operations on the
  21103. returned tensor. Default: ``False``.
  21104. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21105. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21106. Example::
  21107. >>> torch.randn(4)
  21108. tensor([-2.1436, 0.9966, 2.3426, -0.6366])
  21109. >>> torch.randn(2, 3)
  21110. tensor([[ 1.5954, 2.8929, -1.0923],
  21111. [ 1.1719, -0.4709, -0.1996]])
  21112. .. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
  21113. """
  21114. @overload
  21115. def randn(
  21116. *size: _int | SymInt,
  21117. generator: Generator | None,
  21118. out: Tensor | None = None,
  21119. dtype: _dtype | None = None,
  21120. layout: _layout | None = None,
  21121. device: DeviceLikeType | None = None,
  21122. pin_memory: _bool | None = False,
  21123. requires_grad: _bool | None = False,
  21124. ) -> Tensor:
  21125. r"""
  21126. randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21127. Returns a tensor filled with random numbers from a normal distribution
  21128. with mean `0` and variance `1` (also called the standard normal
  21129. distribution).
  21130. .. math::
  21131. \text{out}_{i} \sim \mathcal{N}(0, 1)
  21132. For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
  21133. unit variance as
  21134. .. math::
  21135. \text{out}_{i} \sim \mathcal{CN}(0, 1)
  21136. This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
  21137. :math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
  21138. .. math::
  21139. \operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
  21140. \operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
  21141. The shape of the tensor is defined by the variable argument :attr:`size`.
  21142. Args:
  21143. size (int...): a sequence of integers defining the shape of the output tensor.
  21144. Can be a variable number of arguments or a collection like a list or tuple.
  21145. Keyword args:
  21146. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21147. out (Tensor, optional): the output tensor.
  21148. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21149. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  21150. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21151. Default: ``torch.strided``.
  21152. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21153. Default: if ``None``, uses the current device for the default tensor type
  21154. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21155. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21156. requires_grad (bool, optional): If autograd should record operations on the
  21157. returned tensor. Default: ``False``.
  21158. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21159. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21160. Example::
  21161. >>> torch.randn(4)
  21162. tensor([-2.1436, 0.9966, 2.3426, -0.6366])
  21163. >>> torch.randn(2, 3)
  21164. tensor([[ 1.5954, 2.8929, -1.0923],
  21165. [ 1.1719, -0.4709, -0.1996]])
  21166. .. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
  21167. """
  21168. @overload
  21169. def randn(
  21170. size: Sequence[_int | SymInt],
  21171. *,
  21172. out: Tensor | None = None,
  21173. dtype: _dtype | None = None,
  21174. layout: _layout | None = None,
  21175. device: DeviceLikeType | None = None,
  21176. pin_memory: _bool | None = False,
  21177. requires_grad: _bool | None = False,
  21178. ) -> Tensor:
  21179. r"""
  21180. randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21181. Returns a tensor filled with random numbers from a normal distribution
  21182. with mean `0` and variance `1` (also called the standard normal
  21183. distribution).
  21184. .. math::
  21185. \text{out}_{i} \sim \mathcal{N}(0, 1)
  21186. For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
  21187. unit variance as
  21188. .. math::
  21189. \text{out}_{i} \sim \mathcal{CN}(0, 1)
  21190. This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
  21191. :math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
  21192. .. math::
  21193. \operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
  21194. \operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
  21195. The shape of the tensor is defined by the variable argument :attr:`size`.
  21196. Args:
  21197. size (int...): a sequence of integers defining the shape of the output tensor.
  21198. Can be a variable number of arguments or a collection like a list or tuple.
  21199. Keyword args:
  21200. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21201. out (Tensor, optional): the output tensor.
  21202. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21203. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  21204. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21205. Default: ``torch.strided``.
  21206. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21207. Default: if ``None``, uses the current device for the default tensor type
  21208. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21209. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21210. requires_grad (bool, optional): If autograd should record operations on the
  21211. returned tensor. Default: ``False``.
  21212. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21213. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21214. Example::
  21215. >>> torch.randn(4)
  21216. tensor([-2.1436, 0.9966, 2.3426, -0.6366])
  21217. >>> torch.randn(2, 3)
  21218. tensor([[ 1.5954, 2.8929, -1.0923],
  21219. [ 1.1719, -0.4709, -0.1996]])
  21220. .. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
  21221. """
  21222. @overload
  21223. def randn(
  21224. *size: _int | SymInt,
  21225. out: Tensor | None = None,
  21226. dtype: _dtype | None = None,
  21227. layout: _layout | None = None,
  21228. device: DeviceLikeType | None = None,
  21229. pin_memory: _bool | None = False,
  21230. requires_grad: _bool | None = False,
  21231. ) -> Tensor:
  21232. r"""
  21233. randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21234. Returns a tensor filled with random numbers from a normal distribution
  21235. with mean `0` and variance `1` (also called the standard normal
  21236. distribution).
  21237. .. math::
  21238. \text{out}_{i} \sim \mathcal{N}(0, 1)
  21239. For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
  21240. unit variance as
  21241. .. math::
  21242. \text{out}_{i} \sim \mathcal{CN}(0, 1)
  21243. This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
  21244. :math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
  21245. .. math::
  21246. \operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
  21247. \operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
  21248. The shape of the tensor is defined by the variable argument :attr:`size`.
  21249. Args:
  21250. size (int...): a sequence of integers defining the shape of the output tensor.
  21251. Can be a variable number of arguments or a collection like a list or tuple.
  21252. Keyword args:
  21253. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21254. out (Tensor, optional): the output tensor.
  21255. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21256. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  21257. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21258. Default: ``torch.strided``.
  21259. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21260. Default: if ``None``, uses the current device for the default tensor type
  21261. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21262. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21263. requires_grad (bool, optional): If autograd should record operations on the
  21264. returned tensor. Default: ``False``.
  21265. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21266. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21267. Example::
  21268. >>> torch.randn(4)
  21269. tensor([-2.1436, 0.9966, 2.3426, -0.6366])
  21270. >>> torch.randn(2, 3)
  21271. tensor([[ 1.5954, 2.8929, -1.0923],
  21272. [ 1.1719, -0.4709, -0.1996]])
  21273. .. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
  21274. """
  21275. @overload
  21276. def randn(
  21277. size: Sequence[_int | SymInt],
  21278. *,
  21279. names: Sequence[str | EllipsisType | None] | None,
  21280. dtype: _dtype | None = None,
  21281. layout: _layout | None = None,
  21282. device: DeviceLikeType | None = None,
  21283. pin_memory: _bool | None = False,
  21284. requires_grad: _bool | None = False,
  21285. ) -> Tensor:
  21286. r"""
  21287. randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21288. Returns a tensor filled with random numbers from a normal distribution
  21289. with mean `0` and variance `1` (also called the standard normal
  21290. distribution).
  21291. .. math::
  21292. \text{out}_{i} \sim \mathcal{N}(0, 1)
  21293. For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
  21294. unit variance as
  21295. .. math::
  21296. \text{out}_{i} \sim \mathcal{CN}(0, 1)
  21297. This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
  21298. :math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
  21299. .. math::
  21300. \operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
  21301. \operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
  21302. The shape of the tensor is defined by the variable argument :attr:`size`.
  21303. Args:
  21304. size (int...): a sequence of integers defining the shape of the output tensor.
  21305. Can be a variable number of arguments or a collection like a list or tuple.
  21306. Keyword args:
  21307. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21308. out (Tensor, optional): the output tensor.
  21309. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21310. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  21311. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21312. Default: ``torch.strided``.
  21313. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21314. Default: if ``None``, uses the current device for the default tensor type
  21315. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21316. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21317. requires_grad (bool, optional): If autograd should record operations on the
  21318. returned tensor. Default: ``False``.
  21319. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21320. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21321. Example::
  21322. >>> torch.randn(4)
  21323. tensor([-2.1436, 0.9966, 2.3426, -0.6366])
  21324. >>> torch.randn(2, 3)
  21325. tensor([[ 1.5954, 2.8929, -1.0923],
  21326. [ 1.1719, -0.4709, -0.1996]])
  21327. .. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
  21328. """
  21329. @overload
  21330. def randn(
  21331. *size: _int | SymInt,
  21332. names: Sequence[str | EllipsisType | None] | None,
  21333. dtype: _dtype | None = None,
  21334. layout: _layout | None = None,
  21335. device: DeviceLikeType | None = None,
  21336. pin_memory: _bool | None = False,
  21337. requires_grad: _bool | None = False,
  21338. ) -> Tensor:
  21339. r"""
  21340. randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21341. Returns a tensor filled with random numbers from a normal distribution
  21342. with mean `0` and variance `1` (also called the standard normal
  21343. distribution).
  21344. .. math::
  21345. \text{out}_{i} \sim \mathcal{N}(0, 1)
  21346. For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
  21347. unit variance as
  21348. .. math::
  21349. \text{out}_{i} \sim \mathcal{CN}(0, 1)
  21350. This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
  21351. :math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
  21352. .. math::
  21353. \operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
  21354. \operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
  21355. The shape of the tensor is defined by the variable argument :attr:`size`.
  21356. Args:
  21357. size (int...): a sequence of integers defining the shape of the output tensor.
  21358. Can be a variable number of arguments or a collection like a list or tuple.
  21359. Keyword args:
  21360. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21361. out (Tensor, optional): the output tensor.
  21362. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21363. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  21364. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21365. Default: ``torch.strided``.
  21366. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21367. Default: if ``None``, uses the current device for the default tensor type
  21368. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21369. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21370. requires_grad (bool, optional): If autograd should record operations on the
  21371. returned tensor. Default: ``False``.
  21372. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21373. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21374. Example::
  21375. >>> torch.randn(4)
  21376. tensor([-2.1436, 0.9966, 2.3426, -0.6366])
  21377. >>> torch.randn(2, 3)
  21378. tensor([[ 1.5954, 2.8929, -1.0923],
  21379. [ 1.1719, -0.4709, -0.1996]])
  21380. .. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
  21381. """
  21382. def randn_like(
  21383. input: Tensor,
  21384. *,
  21385. memory_format: memory_format | None = None,
  21386. dtype: _dtype | None = None,
  21387. layout: _layout | None = None,
  21388. device: DeviceLikeType | None = None,
  21389. pin_memory: _bool | None = False,
  21390. requires_grad: _bool | None = False,
  21391. ) -> Tensor:
  21392. r"""
  21393. randn_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  21394. Returns a tensor with the same size as :attr:`input` that is filled with
  21395. random numbers from a normal distribution with mean 0 and variance 1. Please refer to :func:`torch.randn` for the
  21396. sampling process of complex dtypes. ``torch.randn_like(input)`` is equivalent to
  21397. ``torch.randn(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
  21398. Args:
  21399. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  21400. Keyword args:
  21401. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  21402. Default: if ``None``, defaults to the dtype of :attr:`input`.
  21403. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  21404. Default: if ``None``, defaults to the layout of :attr:`input`.
  21405. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21406. Default: if ``None``, defaults to the device of :attr:`input`.
  21407. requires_grad (bool, optional): If autograd should record operations on the
  21408. returned tensor. Default: ``False``.
  21409. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  21410. returned Tensor. Default: ``torch.preserve_format``.
  21411. """
  21412. @overload
  21413. def randperm(
  21414. n: _int | SymInt,
  21415. *,
  21416. generator: Generator | None,
  21417. out: Tensor | None = None,
  21418. dtype: _dtype | None = None,
  21419. layout: _layout | None = None,
  21420. device: DeviceLikeType | None = None,
  21421. pin_memory: _bool | None = False,
  21422. requires_grad: _bool | None = False,
  21423. ) -> Tensor:
  21424. r"""
  21425. randperm(n, *, generator=None, out=None, dtype=torch.int64,layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21426. Returns a random permutation of integers from ``0`` to ``n - 1``.
  21427. Args:
  21428. n (int): the upper bound (exclusive)
  21429. Keyword args:
  21430. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21431. out (Tensor, optional): the output tensor.
  21432. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21433. Default: ``torch.int64``.
  21434. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21435. Default: ``torch.strided``.
  21436. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21437. Default: if ``None``, uses the current device for the default tensor type
  21438. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21439. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21440. requires_grad (bool, optional): If autograd should record operations on the
  21441. returned tensor. Default: ``False``.
  21442. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21443. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21444. Example::
  21445. >>> torch.randperm(4)
  21446. tensor([2, 1, 0, 3])
  21447. """
  21448. @overload
  21449. def randperm(
  21450. n: _int | SymInt,
  21451. *,
  21452. out: Tensor | None = None,
  21453. dtype: _dtype | None = None,
  21454. layout: _layout | None = None,
  21455. device: DeviceLikeType | None = None,
  21456. pin_memory: _bool | None = False,
  21457. requires_grad: _bool | None = False,
  21458. ) -> Tensor:
  21459. r"""
  21460. randperm(n, *, generator=None, out=None, dtype=torch.int64,layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21461. Returns a random permutation of integers from ``0`` to ``n - 1``.
  21462. Args:
  21463. n (int): the upper bound (exclusive)
  21464. Keyword args:
  21465. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21466. out (Tensor, optional): the output tensor.
  21467. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21468. Default: ``torch.int64``.
  21469. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21470. Default: ``torch.strided``.
  21471. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21472. Default: if ``None``, uses the current device for the default tensor type
  21473. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21474. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21475. requires_grad (bool, optional): If autograd should record operations on the
  21476. returned tensor. Default: ``False``.
  21477. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21478. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21479. Example::
  21480. >>> torch.randperm(4)
  21481. tensor([2, 1, 0, 3])
  21482. """
  21483. def range(
  21484. start: Number,
  21485. end: Number,
  21486. step: Number = 1,
  21487. *,
  21488. out: Tensor | None = None,
  21489. dtype: _dtype | None = None,
  21490. device: DeviceLikeType | None = None,
  21491. requires_grad: _bool = False,
  21492. pin_memory: _bool = False,
  21493. ) -> Tensor:
  21494. r"""
  21495. range(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  21496. Returns a 1-D tensor of size :math:`\left\lfloor \frac{\text{end} - \text{start}}{\text{step}} \right\rfloor + 1`
  21497. with values from :attr:`start` to :attr:`end` with step :attr:`step`. Step is
  21498. the gap between two values in the tensor.
  21499. .. math::
  21500. \text{out}_{i+1} = \text{out}_i + \text{step}.
  21501. .. warning::
  21502. This function is deprecated and will be removed in a future release because its behavior is inconsistent with
  21503. Python's range builtin. Instead, use :func:`torch.arange`, which produces values in [start, end).
  21504. Args:
  21505. start (float, optional): the starting value for the set of points. Default: ``0``.
  21506. end (float): the ending value for the set of points
  21507. step (float, optional): the gap between each pair of adjacent points. Default: ``1``.
  21508. Keyword args:
  21509. out (Tensor, optional): the output tensor.
  21510. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21511. 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
  21512. arguments. If any of `start`, `end`, or `step` are floating-point, the
  21513. `dtype` is inferred to be the default dtype, see
  21514. :meth:`~torch.get_default_dtype`. Otherwise, the `dtype` is inferred to
  21515. be `torch.int64`.
  21516. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21517. Default: ``torch.strided``.
  21518. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21519. Default: if ``None``, uses the current device for the default tensor type
  21520. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21521. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21522. requires_grad (bool, optional): If autograd should record operations on the
  21523. returned tensor. Default: ``False``.
  21524. Example::
  21525. >>> torch.range(1, 4)
  21526. tensor([ 1., 2., 3., 4.])
  21527. >>> torch.range(1, 4, 0.5)
  21528. tensor([ 1.0000, 1.5000, 2.0000, 2.5000, 3.0000, 3.5000, 4.0000])
  21529. """
  21530. def ravel(input: Tensor) -> Tensor:
  21531. r"""
  21532. ravel(input) -> Tensor
  21533. Return a contiguous flattened tensor. A copy is made only if needed.
  21534. Args:
  21535. input (Tensor): the input tensor.
  21536. Example::
  21537. >>> t = torch.tensor([[[1, 2],
  21538. ... [3, 4]],
  21539. ... [[5, 6],
  21540. ... [7, 8]]])
  21541. >>> torch.ravel(t)
  21542. tensor([1, 2, 3, 4, 5, 6, 7, 8])
  21543. """
  21544. def real(input: Tensor) -> Tensor:
  21545. r"""
  21546. real(input) -> Tensor
  21547. Returns a new tensor containing real values of the :attr:`self` tensor.
  21548. The returned tensor and :attr:`self` share the same underlying storage.
  21549. Args:
  21550. input (Tensor): the input tensor.
  21551. Example::
  21552. >>> x=torch.randn(4, dtype=torch.cfloat)
  21553. >>> x
  21554. tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
  21555. >>> x.real
  21556. tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
  21557. """
  21558. def reciprocal(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  21559. r"""
  21560. reciprocal(input, *, out=None) -> Tensor
  21561. Returns a new tensor with the reciprocal of the elements of :attr:`input`
  21562. .. math::
  21563. \text{out}_{i} = \frac{1}{\text{input}_{i}}
  21564. .. note::
  21565. Unlike NumPy's reciprocal, torch.reciprocal supports integral inputs. Integral
  21566. inputs to reciprocal are automatically :ref:`promoted <type-promotion-doc>` to
  21567. the default scalar type.
  21568. Args:
  21569. input (Tensor): the input tensor.
  21570. Keyword args:
  21571. out (Tensor, optional): the output tensor.
  21572. Example::
  21573. >>> a = torch.randn(4)
  21574. >>> a
  21575. tensor([-0.4595, -2.1219, -1.4314, 0.7298])
  21576. >>> torch.reciprocal(a)
  21577. tensor([-2.1763, -0.4713, -0.6986, 1.3702])
  21578. """
  21579. def reciprocal_(input: Tensor) -> Tensor: ...
  21580. def relu(input: Tensor) -> Tensor: ...
  21581. def relu_(input: Tensor) -> Tensor: ...
  21582. @overload
  21583. def remainder(
  21584. input: Tensor,
  21585. other: Tensor,
  21586. *,
  21587. out: Tensor | None = None,
  21588. ) -> Tensor:
  21589. r"""
  21590. remainder(input, other, *, out=None) -> Tensor
  21591. Computes
  21592. `Python's modulus operation <https://docs.python.org/3/reference/expressions.html#binary-arithmetic-operations>`_
  21593. entrywise. The result has the same sign as the divisor :attr:`other` and its absolute value
  21594. is less than that of :attr:`other`.
  21595. It may also be defined in terms of :func:`torch.div` as
  21596. .. code:: python
  21597. torch.remainder(a, b) == a - a.div(b, rounding_mode="floor") * b
  21598. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  21599. :ref:`type promotion <type-promotion-doc>`, and integer and float inputs.
  21600. .. note::
  21601. Complex inputs are not supported. In some cases, it is not mathematically
  21602. possible to satisfy the definition of a modulo operation with complex numbers.
  21603. See :func:`torch.fmod` for how division by zero is handled.
  21604. .. seealso::
  21605. :func:`torch.fmod` which implements C++'s `std::fmod <https://en.cppreference.com/w/cpp/numeric/math/fmod>`_.
  21606. This one is defined in terms of division rounding towards zero.
  21607. Args:
  21608. input (Tensor or Scalar): the dividend
  21609. other (Tensor or Scalar): the divisor
  21610. Keyword args:
  21611. out (Tensor, optional): the output tensor.
  21612. Example::
  21613. >>> torch.remainder(torch.tensor([-3., -2, -1, 1, 2, 3]), 2)
  21614. tensor([ 1., 0., 1., 1., 0., 1.])
  21615. >>> torch.remainder(torch.tensor([1, 2, 3, 4, 5]), -1.5)
  21616. tensor([ -0.5000, -1.0000, 0.0000, -0.5000, -1.0000 ])
  21617. """
  21618. @overload
  21619. def remainder(self: Number | _complex, other: Tensor) -> Tensor:
  21620. r"""
  21621. remainder(input, other, *, out=None) -> Tensor
  21622. Computes
  21623. `Python's modulus operation <https://docs.python.org/3/reference/expressions.html#binary-arithmetic-operations>`_
  21624. entrywise. The result has the same sign as the divisor :attr:`other` and its absolute value
  21625. is less than that of :attr:`other`.
  21626. It may also be defined in terms of :func:`torch.div` as
  21627. .. code:: python
  21628. torch.remainder(a, b) == a - a.div(b, rounding_mode="floor") * b
  21629. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  21630. :ref:`type promotion <type-promotion-doc>`, and integer and float inputs.
  21631. .. note::
  21632. Complex inputs are not supported. In some cases, it is not mathematically
  21633. possible to satisfy the definition of a modulo operation with complex numbers.
  21634. See :func:`torch.fmod` for how division by zero is handled.
  21635. .. seealso::
  21636. :func:`torch.fmod` which implements C++'s `std::fmod <https://en.cppreference.com/w/cpp/numeric/math/fmod>`_.
  21637. This one is defined in terms of division rounding towards zero.
  21638. Args:
  21639. input (Tensor or Scalar): the dividend
  21640. other (Tensor or Scalar): the divisor
  21641. Keyword args:
  21642. out (Tensor, optional): the output tensor.
  21643. Example::
  21644. >>> torch.remainder(torch.tensor([-3., -2, -1, 1, 2, 3]), 2)
  21645. tensor([ 1., 0., 1., 1., 0., 1.])
  21646. >>> torch.remainder(torch.tensor([1, 2, 3, 4, 5]), -1.5)
  21647. tensor([ -0.5000, -1.0000, 0.0000, -0.5000, -1.0000 ])
  21648. """
  21649. @overload
  21650. def remainder(
  21651. input: Tensor,
  21652. other: Number | _complex,
  21653. *,
  21654. out: Tensor | None = None,
  21655. ) -> Tensor:
  21656. r"""
  21657. remainder(input, other, *, out=None) -> Tensor
  21658. Computes
  21659. `Python's modulus operation <https://docs.python.org/3/reference/expressions.html#binary-arithmetic-operations>`_
  21660. entrywise. The result has the same sign as the divisor :attr:`other` and its absolute value
  21661. is less than that of :attr:`other`.
  21662. It may also be defined in terms of :func:`torch.div` as
  21663. .. code:: python
  21664. torch.remainder(a, b) == a - a.div(b, rounding_mode="floor") * b
  21665. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  21666. :ref:`type promotion <type-promotion-doc>`, and integer and float inputs.
  21667. .. note::
  21668. Complex inputs are not supported. In some cases, it is not mathematically
  21669. possible to satisfy the definition of a modulo operation with complex numbers.
  21670. See :func:`torch.fmod` for how division by zero is handled.
  21671. .. seealso::
  21672. :func:`torch.fmod` which implements C++'s `std::fmod <https://en.cppreference.com/w/cpp/numeric/math/fmod>`_.
  21673. This one is defined in terms of division rounding towards zero.
  21674. Args:
  21675. input (Tensor or Scalar): the dividend
  21676. other (Tensor or Scalar): the divisor
  21677. Keyword args:
  21678. out (Tensor, optional): the output tensor.
  21679. Example::
  21680. >>> torch.remainder(torch.tensor([-3., -2, -1, 1, 2, 3]), 2)
  21681. tensor([ 1., 0., 1., 1., 0., 1.])
  21682. >>> torch.remainder(torch.tensor([1, 2, 3, 4, 5]), -1.5)
  21683. tensor([ -0.5000, -1.0000, 0.0000, -0.5000, -1.0000 ])
  21684. """
  21685. def renorm(
  21686. input: Tensor,
  21687. p: Number | _complex,
  21688. dim: _int,
  21689. maxnorm: Number | _complex,
  21690. *,
  21691. out: Tensor | None = None,
  21692. ) -> Tensor:
  21693. r"""
  21694. renorm(input, p, dim, maxnorm, *, out=None) -> Tensor
  21695. Returns a tensor where each sub-tensor of :attr:`input` along dimension
  21696. :attr:`dim` is normalized such that the `p`-norm of the sub-tensor is lower
  21697. than the value :attr:`maxnorm`
  21698. .. note:: If the norm of a row is lower than `maxnorm`, the row is unchanged
  21699. Args:
  21700. input (Tensor): the input tensor.
  21701. p (float): the power for the norm computation
  21702. dim (int): the dimension to slice over to get the sub-tensors
  21703. maxnorm (float): the maximum norm to keep each sub-tensor under
  21704. Keyword args:
  21705. out (Tensor, optional): the output tensor.
  21706. Example::
  21707. >>> x = torch.ones(3, 3)
  21708. >>> x[1].fill_(2)
  21709. tensor([ 2., 2., 2.])
  21710. >>> x[2].fill_(3)
  21711. tensor([ 3., 3., 3.])
  21712. >>> x
  21713. tensor([[ 1., 1., 1.],
  21714. [ 2., 2., 2.],
  21715. [ 3., 3., 3.]])
  21716. >>> torch.renorm(x, 1, 0, 5)
  21717. tensor([[ 1.0000, 1.0000, 1.0000],
  21718. [ 1.6667, 1.6667, 1.6667],
  21719. [ 1.6667, 1.6667, 1.6667]])
  21720. """
  21721. @overload
  21722. def repeat_interleave(
  21723. input: Tensor,
  21724. repeats: Tensor,
  21725. dim: _int | None = None,
  21726. *,
  21727. output_size: _int | SymInt | None = None,
  21728. ) -> Tensor:
  21729. r"""
  21730. repeat_interleave(input, repeats, dim=None, *, output_size=None) -> Tensor
  21731. Repeat elements of a tensor.
  21732. .. warning::
  21733. This is different from :meth:`torch.Tensor.repeat` but similar to ``numpy.repeat``.
  21734. Args:
  21735. input (Tensor): the input tensor.
  21736. repeats (Tensor or int): The number of repetitions for each element.
  21737. repeats is broadcasted to fit the shape of the given axis.
  21738. dim (int, optional): The dimension along which to repeat values.
  21739. By default, use the flattened input array, and return a flat output
  21740. array.
  21741. Keyword args:
  21742. output_size (int, optional): Total output size for the given axis
  21743. ( e.g. sum of repeats). If given, it will avoid stream synchronization
  21744. needed to calculate output shape of the tensor.
  21745. Returns:
  21746. Tensor: Repeated tensor which has the same shape as input, except along the given axis.
  21747. Example::
  21748. >>> x = torch.tensor([1, 2, 3])
  21749. >>> x.repeat_interleave(2)
  21750. tensor([1, 1, 2, 2, 3, 3])
  21751. >>> y = torch.tensor([[1, 2], [3, 4]])
  21752. >>> torch.repeat_interleave(y, 2)
  21753. tensor([1, 1, 2, 2, 3, 3, 4, 4])
  21754. >>> torch.repeat_interleave(y, 3, dim=1)
  21755. tensor([[1, 1, 1, 2, 2, 2],
  21756. [3, 3, 3, 4, 4, 4]])
  21757. >>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0)
  21758. tensor([[1, 2],
  21759. [3, 4],
  21760. [3, 4]])
  21761. >>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0, output_size=3)
  21762. tensor([[1, 2],
  21763. [3, 4],
  21764. [3, 4]])
  21765. If the `repeats` is `tensor([n1, n2, n3, ...])`, then the output will be
  21766. `tensor([0, 0, ..., 1, 1, ..., 2, 2, ..., ...])` where `0` appears `n1` times,
  21767. `1` appears `n2` times, `2` appears `n3` times, etc.
  21768. .. function:: repeat_interleave(repeats, *) -> Tensor
  21769. :noindex:
  21770. Repeats 0 repeats[0] times, 1 repeats[1] times, 2 repeats[2] times, etc.
  21771. Args:
  21772. repeats (Tensor): The number of repetitions for each element.
  21773. Returns:
  21774. Tensor: Repeated tensor of size `sum(repeats)`.
  21775. Example::
  21776. >>> torch.repeat_interleave(torch.tensor([1, 2, 3]))
  21777. tensor([0, 1, 1, 2, 2, 2])
  21778. """
  21779. @overload
  21780. def repeat_interleave(
  21781. repeats: Tensor,
  21782. *,
  21783. output_size: _int | SymInt | None = None,
  21784. ) -> Tensor:
  21785. r"""
  21786. repeat_interleave(input, repeats, dim=None, *, output_size=None) -> Tensor
  21787. Repeat elements of a tensor.
  21788. .. warning::
  21789. This is different from :meth:`torch.Tensor.repeat` but similar to ``numpy.repeat``.
  21790. Args:
  21791. input (Tensor): the input tensor.
  21792. repeats (Tensor or int): The number of repetitions for each element.
  21793. repeats is broadcasted to fit the shape of the given axis.
  21794. dim (int, optional): The dimension along which to repeat values.
  21795. By default, use the flattened input array, and return a flat output
  21796. array.
  21797. Keyword args:
  21798. output_size (int, optional): Total output size for the given axis
  21799. ( e.g. sum of repeats). If given, it will avoid stream synchronization
  21800. needed to calculate output shape of the tensor.
  21801. Returns:
  21802. Tensor: Repeated tensor which has the same shape as input, except along the given axis.
  21803. Example::
  21804. >>> x = torch.tensor([1, 2, 3])
  21805. >>> x.repeat_interleave(2)
  21806. tensor([1, 1, 2, 2, 3, 3])
  21807. >>> y = torch.tensor([[1, 2], [3, 4]])
  21808. >>> torch.repeat_interleave(y, 2)
  21809. tensor([1, 1, 2, 2, 3, 3, 4, 4])
  21810. >>> torch.repeat_interleave(y, 3, dim=1)
  21811. tensor([[1, 1, 1, 2, 2, 2],
  21812. [3, 3, 3, 4, 4, 4]])
  21813. >>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0)
  21814. tensor([[1, 2],
  21815. [3, 4],
  21816. [3, 4]])
  21817. >>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0, output_size=3)
  21818. tensor([[1, 2],
  21819. [3, 4],
  21820. [3, 4]])
  21821. If the `repeats` is `tensor([n1, n2, n3, ...])`, then the output will be
  21822. `tensor([0, 0, ..., 1, 1, ..., 2, 2, ..., ...])` where `0` appears `n1` times,
  21823. `1` appears `n2` times, `2` appears `n3` times, etc.
  21824. .. function:: repeat_interleave(repeats, *) -> Tensor
  21825. :noindex:
  21826. Repeats 0 repeats[0] times, 1 repeats[1] times, 2 repeats[2] times, etc.
  21827. Args:
  21828. repeats (Tensor): The number of repetitions for each element.
  21829. Returns:
  21830. Tensor: Repeated tensor of size `sum(repeats)`.
  21831. Example::
  21832. >>> torch.repeat_interleave(torch.tensor([1, 2, 3]))
  21833. tensor([0, 1, 1, 2, 2, 2])
  21834. """
  21835. @overload
  21836. def repeat_interleave(
  21837. input: Tensor,
  21838. repeats: _int | SymInt,
  21839. dim: _int | None = None,
  21840. *,
  21841. output_size: _int | SymInt | None = None,
  21842. ) -> Tensor:
  21843. r"""
  21844. repeat_interleave(input, repeats, dim=None, *, output_size=None) -> Tensor
  21845. Repeat elements of a tensor.
  21846. .. warning::
  21847. This is different from :meth:`torch.Tensor.repeat` but similar to ``numpy.repeat``.
  21848. Args:
  21849. input (Tensor): the input tensor.
  21850. repeats (Tensor or int): The number of repetitions for each element.
  21851. repeats is broadcasted to fit the shape of the given axis.
  21852. dim (int, optional): The dimension along which to repeat values.
  21853. By default, use the flattened input array, and return a flat output
  21854. array.
  21855. Keyword args:
  21856. output_size (int, optional): Total output size for the given axis
  21857. ( e.g. sum of repeats). If given, it will avoid stream synchronization
  21858. needed to calculate output shape of the tensor.
  21859. Returns:
  21860. Tensor: Repeated tensor which has the same shape as input, except along the given axis.
  21861. Example::
  21862. >>> x = torch.tensor([1, 2, 3])
  21863. >>> x.repeat_interleave(2)
  21864. tensor([1, 1, 2, 2, 3, 3])
  21865. >>> y = torch.tensor([[1, 2], [3, 4]])
  21866. >>> torch.repeat_interleave(y, 2)
  21867. tensor([1, 1, 2, 2, 3, 3, 4, 4])
  21868. >>> torch.repeat_interleave(y, 3, dim=1)
  21869. tensor([[1, 1, 1, 2, 2, 2],
  21870. [3, 3, 3, 4, 4, 4]])
  21871. >>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0)
  21872. tensor([[1, 2],
  21873. [3, 4],
  21874. [3, 4]])
  21875. >>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0, output_size=3)
  21876. tensor([[1, 2],
  21877. [3, 4],
  21878. [3, 4]])
  21879. If the `repeats` is `tensor([n1, n2, n3, ...])`, then the output will be
  21880. `tensor([0, 0, ..., 1, 1, ..., 2, 2, ..., ...])` where `0` appears `n1` times,
  21881. `1` appears `n2` times, `2` appears `n3` times, etc.
  21882. .. function:: repeat_interleave(repeats, *) -> Tensor
  21883. :noindex:
  21884. Repeats 0 repeats[0] times, 1 repeats[1] times, 2 repeats[2] times, etc.
  21885. Args:
  21886. repeats (Tensor): The number of repetitions for each element.
  21887. Returns:
  21888. Tensor: Repeated tensor of size `sum(repeats)`.
  21889. Example::
  21890. >>> torch.repeat_interleave(torch.tensor([1, 2, 3]))
  21891. tensor([0, 1, 1, 2, 2, 2])
  21892. """
  21893. def reshape(input: Tensor, shape: Sequence[_int | SymInt]) -> Tensor:
  21894. r"""
  21895. reshape(input, shape) -> Tensor
  21896. Returns a tensor with the same data and number of elements as :attr:`input`,
  21897. but with the specified shape. When possible, the returned tensor will be a view
  21898. of :attr:`input`. Otherwise, it will be a copy. Contiguous inputs and inputs
  21899. with compatible strides can be reshaped without copying, but you should not
  21900. depend on the copying vs. viewing behavior.
  21901. See :meth:`torch.Tensor.view` on when it is possible to return a view.
  21902. A single dimension may be -1, in which case it's inferred from the remaining
  21903. dimensions and the number of elements in :attr:`input`.
  21904. Args:
  21905. input (Tensor): the tensor to be reshaped
  21906. shape (tuple of int): the new shape
  21907. Example::
  21908. >>> a = torch.arange(4.)
  21909. >>> torch.reshape(a, (2, 2))
  21910. tensor([[ 0., 1.],
  21911. [ 2., 3.]])
  21912. >>> b = torch.tensor([[0, 1], [2, 3]])
  21913. >>> torch.reshape(b, (-1,))
  21914. tensor([ 0, 1, 2, 3])
  21915. """
  21916. def resize_as_(
  21917. input: Tensor,
  21918. the_template: Tensor,
  21919. *,
  21920. memory_format: memory_format | None = None,
  21921. ) -> Tensor: ...
  21922. def resize_as_sparse_(input: Tensor, the_template: Tensor) -> Tensor: ...
  21923. def resolve_conj(input: Tensor) -> Tensor:
  21924. r"""
  21925. resolve_conj(input) -> Tensor
  21926. Returns a new tensor with materialized conjugation if :attr:`input`'s conjugate bit is set to `True`,
  21927. else returns :attr:`input`. The output tensor will always have its conjugate bit set to `False`.
  21928. Args:
  21929. input (Tensor): the input tensor.
  21930. Example::
  21931. >>> x = torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j])
  21932. >>> y = x.conj()
  21933. >>> y.is_conj()
  21934. True
  21935. >>> z = y.resolve_conj()
  21936. >>> z
  21937. tensor([-1 - 1j, -2 - 2j, 3 + 3j])
  21938. >>> z.is_conj()
  21939. False
  21940. """
  21941. def resolve_neg(input: Tensor) -> Tensor:
  21942. r"""
  21943. resolve_neg(input) -> Tensor
  21944. Returns a new tensor with materialized negation if :attr:`input`'s negative bit is set to `True`,
  21945. else returns :attr:`input`. The output tensor will always have its negative bit set to `False`.
  21946. Args:
  21947. input (Tensor): the input tensor.
  21948. Example::
  21949. >>> x = torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j])
  21950. >>> y = x.conj()
  21951. >>> z = y.imag
  21952. >>> z.is_neg()
  21953. True
  21954. >>> out = z.resolve_neg()
  21955. >>> out
  21956. tensor([-1., -2., 3.])
  21957. >>> out.is_neg()
  21958. False
  21959. """
  21960. @overload
  21961. def result_type(tensor: Tensor, other: Tensor) -> _dtype:
  21962. r"""
  21963. result_type(tensor1, tensor2) -> dtype
  21964. Returns the :class:`torch.dtype` that would result from performing an arithmetic
  21965. operation on the provided input tensors. See type promotion :ref:`documentation <type-promotion-doc>`
  21966. for more information on the type promotion logic.
  21967. Args:
  21968. tensor1 (Tensor or Number): an input tensor or number
  21969. tensor2 (Tensor or Number): an input tensor or number
  21970. Example::
  21971. >>> torch.result_type(torch.tensor([1, 2], dtype=torch.int), 1.0)
  21972. torch.float32
  21973. >>> torch.result_type(torch.tensor([1, 2], dtype=torch.uint8), torch.tensor(1))
  21974. torch.uint8
  21975. """
  21976. @overload
  21977. def result_type(scalar: Number | _complex, tensor: Tensor) -> _dtype:
  21978. r"""
  21979. result_type(tensor1, tensor2) -> dtype
  21980. Returns the :class:`torch.dtype` that would result from performing an arithmetic
  21981. operation on the provided input tensors. See type promotion :ref:`documentation <type-promotion-doc>`
  21982. for more information on the type promotion logic.
  21983. Args:
  21984. tensor1 (Tensor or Number): an input tensor or number
  21985. tensor2 (Tensor or Number): an input tensor or number
  21986. Example::
  21987. >>> torch.result_type(torch.tensor([1, 2], dtype=torch.int), 1.0)
  21988. torch.float32
  21989. >>> torch.result_type(torch.tensor([1, 2], dtype=torch.uint8), torch.tensor(1))
  21990. torch.uint8
  21991. """
  21992. @overload
  21993. def result_type(tensor: Tensor, other: Number | _complex) -> _dtype:
  21994. r"""
  21995. result_type(tensor1, tensor2) -> dtype
  21996. Returns the :class:`torch.dtype` that would result from performing an arithmetic
  21997. operation on the provided input tensors. See type promotion :ref:`documentation <type-promotion-doc>`
  21998. for more information on the type promotion logic.
  21999. Args:
  22000. tensor1 (Tensor or Number): an input tensor or number
  22001. tensor2 (Tensor or Number): an input tensor or number
  22002. Example::
  22003. >>> torch.result_type(torch.tensor([1, 2], dtype=torch.int), 1.0)
  22004. torch.float32
  22005. >>> torch.result_type(torch.tensor([1, 2], dtype=torch.uint8), torch.tensor(1))
  22006. torch.uint8
  22007. """
  22008. @overload
  22009. def result_type(
  22010. scalar1: Number | _complex,
  22011. scalar2: Number | _complex,
  22012. ) -> _dtype:
  22013. r"""
  22014. result_type(tensor1, tensor2) -> dtype
  22015. Returns the :class:`torch.dtype` that would result from performing an arithmetic
  22016. operation on the provided input tensors. See type promotion :ref:`documentation <type-promotion-doc>`
  22017. for more information on the type promotion logic.
  22018. Args:
  22019. tensor1 (Tensor or Number): an input tensor or number
  22020. tensor2 (Tensor or Number): an input tensor or number
  22021. Example::
  22022. >>> torch.result_type(torch.tensor([1, 2], dtype=torch.int), 1.0)
  22023. torch.float32
  22024. >>> torch.result_type(torch.tensor([1, 2], dtype=torch.uint8), torch.tensor(1))
  22025. torch.uint8
  22026. """
  22027. def rms_norm(
  22028. input: Tensor,
  22029. normalized_shape: Sequence[_int | SymInt],
  22030. weight: Tensor | None = None,
  22031. eps: _float | None = None,
  22032. ) -> Tensor: ...
  22033. @overload
  22034. def rnn_relu(
  22035. data: Tensor,
  22036. batch_sizes: Tensor,
  22037. hx: Tensor,
  22038. params: tuple[Tensor, ...] | list[Tensor] | None,
  22039. has_biases: _bool,
  22040. num_layers: _int,
  22041. dropout: _float,
  22042. train: _bool,
  22043. bidirectional: _bool,
  22044. ) -> tuple[Tensor, Tensor]: ...
  22045. @overload
  22046. def rnn_relu(
  22047. input: Tensor,
  22048. hx: Tensor,
  22049. params: tuple[Tensor, ...] | list[Tensor] | None,
  22050. has_biases: _bool,
  22051. num_layers: _int,
  22052. dropout: _float,
  22053. train: _bool,
  22054. bidirectional: _bool,
  22055. batch_first: _bool,
  22056. ) -> tuple[Tensor, Tensor]: ...
  22057. def rnn_relu_cell(
  22058. input: Tensor,
  22059. hx: Tensor,
  22060. w_ih: Tensor,
  22061. w_hh: Tensor,
  22062. b_ih: Tensor | None = None,
  22063. b_hh: Tensor | None = None,
  22064. ) -> Tensor: ...
  22065. @overload
  22066. def rnn_tanh(
  22067. data: Tensor,
  22068. batch_sizes: Tensor,
  22069. hx: Tensor,
  22070. params: tuple[Tensor, ...] | list[Tensor] | None,
  22071. has_biases: _bool,
  22072. num_layers: _int,
  22073. dropout: _float,
  22074. train: _bool,
  22075. bidirectional: _bool,
  22076. ) -> tuple[Tensor, Tensor]: ...
  22077. @overload
  22078. def rnn_tanh(
  22079. input: Tensor,
  22080. hx: Tensor,
  22081. params: tuple[Tensor, ...] | list[Tensor] | None,
  22082. has_biases: _bool,
  22083. num_layers: _int,
  22084. dropout: _float,
  22085. train: _bool,
  22086. bidirectional: _bool,
  22087. batch_first: _bool,
  22088. ) -> tuple[Tensor, Tensor]: ...
  22089. def rnn_tanh_cell(
  22090. input: Tensor,
  22091. hx: Tensor,
  22092. w_ih: Tensor,
  22093. w_hh: Tensor,
  22094. b_ih: Tensor | None = None,
  22095. b_hh: Tensor | None = None,
  22096. ) -> Tensor: ...
  22097. def roll(
  22098. input: Tensor,
  22099. shifts: _int | SymInt | Sequence[_int | SymInt],
  22100. dims: _int | _size = (),
  22101. ) -> Tensor:
  22102. r"""
  22103. roll(input, shifts, dims=None) -> Tensor
  22104. Roll the tensor :attr:`input` along the given dimension(s). Elements that are
  22105. shifted beyond the last position are re-introduced at the first position. If
  22106. :attr:`dims` is `None`, the tensor will be flattened before rolling and then
  22107. restored to the original shape.
  22108. Args:
  22109. input (Tensor): the input tensor.
  22110. shifts (int or tuple of ints): The number of places by which the elements
  22111. of the tensor are shifted. If shifts is a tuple, dims must be a tuple of
  22112. the same size, and each dimension will be rolled by the corresponding
  22113. value
  22114. dims (int or tuple of ints): Axis along which to roll
  22115. Example::
  22116. >>> x = torch.tensor([1, 2, 3, 4, 5, 6, 7, 8]).view(4, 2)
  22117. >>> x
  22118. tensor([[1, 2],
  22119. [3, 4],
  22120. [5, 6],
  22121. [7, 8]])
  22122. >>> torch.roll(x, 1)
  22123. tensor([[8, 1],
  22124. [2, 3],
  22125. [4, 5],
  22126. [6, 7]])
  22127. >>> torch.roll(x, 1, 0)
  22128. tensor([[7, 8],
  22129. [1, 2],
  22130. [3, 4],
  22131. [5, 6]])
  22132. >>> torch.roll(x, -1, 0)
  22133. tensor([[3, 4],
  22134. [5, 6],
  22135. [7, 8],
  22136. [1, 2]])
  22137. >>> torch.roll(x, shifts=(2, 1), dims=(0, 1))
  22138. tensor([[6, 5],
  22139. [8, 7],
  22140. [2, 1],
  22141. [4, 3]])
  22142. """
  22143. def rot90(input: Tensor, k: _int = 1, dims: _size = (0, 1)) -> Tensor:
  22144. r"""
  22145. rot90(input, k=1, dims=(0, 1)) -> Tensor
  22146. Rotate an n-D tensor by 90 degrees in the plane specified by dims axis.
  22147. Rotation direction is from the first towards the second axis if k > 0, and from the second towards the first for k < 0.
  22148. Args:
  22149. input (Tensor): the input tensor.
  22150. k (int): number of times to rotate. Default value is 1
  22151. dims (a list or tuple): axis to rotate. Default value is [0, 1]
  22152. Example::
  22153. >>> x = torch.arange(4).view(2, 2)
  22154. >>> x
  22155. tensor([[0, 1],
  22156. [2, 3]])
  22157. >>> torch.rot90(x, 1, [0, 1])
  22158. tensor([[1, 3],
  22159. [0, 2]])
  22160. >>> x = torch.arange(8).view(2, 2, 2)
  22161. >>> x
  22162. tensor([[[0, 1],
  22163. [2, 3]],
  22164. [[4, 5],
  22165. [6, 7]]])
  22166. >>> torch.rot90(x, 1, [1, 2])
  22167. tensor([[[1, 3],
  22168. [0, 2]],
  22169. [[5, 7],
  22170. [4, 6]]])
  22171. """
  22172. @overload
  22173. def round(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  22174. r"""
  22175. round(input, *, decimals=0, out=None) -> Tensor
  22176. Rounds elements of :attr:`input` to the nearest integer.
  22177. For integer inputs, follows the array-api convention of returning a
  22178. copy of the input tensor.
  22179. The return type of output is same as that of input's dtype.
  22180. .. note::
  22181. This function implements the "round half to even" to
  22182. break ties when a number is equidistant from two
  22183. integers (e.g. `round(2.5)` is 2).
  22184. When the :attr:\`decimals\` argument is specified the
  22185. algorithm used is similar to NumPy's `around`. This
  22186. algorithm is fast but inexact and it can easily
  22187. overflow for low precision dtypes.
  22188. Eg. `round(tensor([10000], dtype=torch.float16), decimals=3)` is `inf`.
  22189. .. seealso::
  22190. :func:`torch.ceil`, which rounds up.
  22191. :func:`torch.floor`, which rounds down.
  22192. :func:`torch.trunc`, which rounds towards zero.
  22193. Args:
  22194. input (Tensor): the input tensor.
  22195. decimals (int): Number of decimal places to round to (default: 0).
  22196. If decimals is negative, it specifies the number of positions
  22197. to the left of the decimal point.
  22198. Keyword args:
  22199. out (Tensor, optional): the output tensor.
  22200. Example::
  22201. >>> torch.round(torch.tensor((4.7, -2.3, 9.1, -7.7)))
  22202. tensor([ 5., -2., 9., -8.])
  22203. >>> # Values equidistant from two integers are rounded towards the
  22204. >>> # the nearest even value (zero is treated as even)
  22205. >>> torch.round(torch.tensor([-0.5, 0.5, 1.5, 2.5]))
  22206. tensor([-0., 0., 2., 2.])
  22207. >>> # A positive decimals argument rounds to the to that decimal place
  22208. >>> torch.round(torch.tensor([0.1234567]), decimals=3)
  22209. tensor([0.1230])
  22210. >>> # A negative decimals argument rounds to the left of the decimal
  22211. >>> torch.round(torch.tensor([1200.1234567]), decimals=-3)
  22212. tensor([1000.])
  22213. """
  22214. @overload
  22215. def round(
  22216. input: Tensor,
  22217. *,
  22218. decimals: _int,
  22219. out: Tensor | None = None,
  22220. ) -> Tensor:
  22221. r"""
  22222. round(input, *, decimals=0, out=None) -> Tensor
  22223. Rounds elements of :attr:`input` to the nearest integer.
  22224. For integer inputs, follows the array-api convention of returning a
  22225. copy of the input tensor.
  22226. The return type of output is same as that of input's dtype.
  22227. .. note::
  22228. This function implements the "round half to even" to
  22229. break ties when a number is equidistant from two
  22230. integers (e.g. `round(2.5)` is 2).
  22231. When the :attr:\`decimals\` argument is specified the
  22232. algorithm used is similar to NumPy's `around`. This
  22233. algorithm is fast but inexact and it can easily
  22234. overflow for low precision dtypes.
  22235. Eg. `round(tensor([10000], dtype=torch.float16), decimals=3)` is `inf`.
  22236. .. seealso::
  22237. :func:`torch.ceil`, which rounds up.
  22238. :func:`torch.floor`, which rounds down.
  22239. :func:`torch.trunc`, which rounds towards zero.
  22240. Args:
  22241. input (Tensor): the input tensor.
  22242. decimals (int): Number of decimal places to round to (default: 0).
  22243. If decimals is negative, it specifies the number of positions
  22244. to the left of the decimal point.
  22245. Keyword args:
  22246. out (Tensor, optional): the output tensor.
  22247. Example::
  22248. >>> torch.round(torch.tensor((4.7, -2.3, 9.1, -7.7)))
  22249. tensor([ 5., -2., 9., -8.])
  22250. >>> # Values equidistant from two integers are rounded towards the
  22251. >>> # the nearest even value (zero is treated as even)
  22252. >>> torch.round(torch.tensor([-0.5, 0.5, 1.5, 2.5]))
  22253. tensor([-0., 0., 2., 2.])
  22254. >>> # A positive decimals argument rounds to the to that decimal place
  22255. >>> torch.round(torch.tensor([0.1234567]), decimals=3)
  22256. tensor([0.1230])
  22257. >>> # A negative decimals argument rounds to the left of the decimal
  22258. >>> torch.round(torch.tensor([1200.1234567]), decimals=-3)
  22259. tensor([1000.])
  22260. """
  22261. @overload
  22262. def round_(input: Tensor) -> Tensor: ...
  22263. @overload
  22264. def round_(input: Tensor, *, decimals: _int) -> Tensor: ...
  22265. def row_indices_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor: ...
  22266. def row_stack(
  22267. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  22268. *,
  22269. out: Tensor | None = None,
  22270. ) -> Tensor:
  22271. r"""
  22272. row_stack(tensors, *, out=None) -> Tensor
  22273. Alias of :func:`torch.vstack`.
  22274. """
  22275. def rrelu(
  22276. input: Tensor,
  22277. lower: Number | _complex = 0.125,
  22278. upper: Number | _complex = 0.3333333333333333,
  22279. training: _bool = False,
  22280. generator: Generator | None = None,
  22281. ) -> Tensor: ...
  22282. def rrelu_(
  22283. input: Tensor,
  22284. lower: Number | _complex = 0.125,
  22285. upper: Number | _complex = 0.3333333333333333,
  22286. training: _bool = False,
  22287. generator: Generator | None = None,
  22288. ) -> Tensor: ...
  22289. def rsqrt(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  22290. r"""
  22291. rsqrt(input, *, out=None) -> Tensor
  22292. Returns a new tensor with the reciprocal of the square-root of each of
  22293. the elements of :attr:`input`.
  22294. .. math::
  22295. \text{out}_{i} = \frac{1}{\sqrt{\text{input}_{i}}}
  22296. Args:
  22297. input (Tensor): the input tensor.
  22298. Keyword args:
  22299. out (Tensor, optional): the output tensor.
  22300. Example::
  22301. >>> a = torch.randn(4)
  22302. >>> a
  22303. tensor([-0.0370, 0.2970, 1.5420, -0.9105])
  22304. >>> torch.rsqrt(a)
  22305. tensor([ nan, 1.8351, 0.8053, nan])
  22306. """
  22307. def rsqrt_(input: Tensor) -> Tensor: ...
  22308. @overload
  22309. def rsub(
  22310. input: Tensor,
  22311. other: Tensor,
  22312. *,
  22313. alpha: Number | _complex = 1,
  22314. ) -> Tensor: ...
  22315. @overload
  22316. def rsub(
  22317. input: Tensor,
  22318. other: Number | _complex,
  22319. alpha: Number | _complex = 1,
  22320. ) -> Tensor: ...
  22321. def saddmm(
  22322. input: Tensor,
  22323. mat1: Tensor,
  22324. mat2: Tensor,
  22325. *,
  22326. beta: Number = 1,
  22327. alpha: Number = 1,
  22328. out: Tensor | None = None,
  22329. ) -> Tensor: ...
  22330. def scalar_tensor(
  22331. s: Number | _complex,
  22332. *,
  22333. dtype: _dtype | None = None,
  22334. layout: _layout | None = None,
  22335. device: DeviceLikeType | None = None,
  22336. pin_memory: _bool | None = False,
  22337. requires_grad: _bool | None = False,
  22338. ) -> Tensor: ...
  22339. @overload
  22340. def scatter(
  22341. input: Tensor,
  22342. dim: _int,
  22343. index: Tensor,
  22344. src: Tensor,
  22345. *,
  22346. reduce: str,
  22347. out: Tensor | None = None,
  22348. ) -> Tensor:
  22349. r"""
  22350. scatter(input, dim, index, src) -> Tensor
  22351. Out-of-place version of :meth:`torch.Tensor.scatter_`
  22352. """
  22353. @overload
  22354. def scatter(
  22355. input: Tensor,
  22356. dim: _int,
  22357. index: Tensor,
  22358. src: Tensor,
  22359. *,
  22360. out: Tensor | None = None,
  22361. ) -> Tensor:
  22362. r"""
  22363. scatter(input, dim, index, src) -> Tensor
  22364. Out-of-place version of :meth:`torch.Tensor.scatter_`
  22365. """
  22366. @overload
  22367. def scatter(
  22368. input: Tensor,
  22369. dim: _int,
  22370. index: Tensor,
  22371. value: Number | _complex,
  22372. *,
  22373. reduce: str,
  22374. out: Tensor | None = None,
  22375. ) -> Tensor:
  22376. r"""
  22377. scatter(input, dim, index, src) -> Tensor
  22378. Out-of-place version of :meth:`torch.Tensor.scatter_`
  22379. """
  22380. @overload
  22381. def scatter(
  22382. input: Tensor,
  22383. dim: str | EllipsisType | None,
  22384. index: Tensor,
  22385. src: Tensor,
  22386. ) -> Tensor:
  22387. r"""
  22388. scatter(input, dim, index, src) -> Tensor
  22389. Out-of-place version of :meth:`torch.Tensor.scatter_`
  22390. """
  22391. @overload
  22392. def scatter(
  22393. input: Tensor,
  22394. dim: _int,
  22395. index: Tensor,
  22396. value: Number | _complex,
  22397. *,
  22398. out: Tensor | None = None,
  22399. ) -> Tensor:
  22400. r"""
  22401. scatter(input, dim, index, src) -> Tensor
  22402. Out-of-place version of :meth:`torch.Tensor.scatter_`
  22403. """
  22404. @overload
  22405. def scatter(
  22406. input: Tensor,
  22407. dim: str | EllipsisType | None,
  22408. index: Tensor,
  22409. value: Number | _complex,
  22410. ) -> Tensor:
  22411. r"""
  22412. scatter(input, dim, index, src) -> Tensor
  22413. Out-of-place version of :meth:`torch.Tensor.scatter_`
  22414. """
  22415. @overload
  22416. def scatter_add(
  22417. input: Tensor,
  22418. dim: _int,
  22419. index: Tensor,
  22420. src: Tensor,
  22421. *,
  22422. out: Tensor | None = None,
  22423. ) -> Tensor:
  22424. r"""
  22425. scatter_add(input, dim, index, src) -> Tensor
  22426. Out-of-place version of :meth:`torch.Tensor.scatter_add_`
  22427. """
  22428. @overload
  22429. def scatter_add(
  22430. input: Tensor,
  22431. dim: str | EllipsisType | None,
  22432. index: Tensor,
  22433. src: Tensor,
  22434. ) -> Tensor:
  22435. r"""
  22436. scatter_add(input, dim, index, src) -> Tensor
  22437. Out-of-place version of :meth:`torch.Tensor.scatter_add_`
  22438. """
  22439. def scatter_reduce(
  22440. input: Tensor,
  22441. dim: _int,
  22442. index: Tensor,
  22443. src: Tensor,
  22444. reduce: str,
  22445. *,
  22446. include_self: _bool = True,
  22447. out: Tensor | None = None,
  22448. ) -> Tensor:
  22449. r"""
  22450. scatter_reduce(input, dim, index, src, reduce, *, include_self=True) -> Tensor
  22451. Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
  22452. """
  22453. @overload
  22454. def searchsorted(
  22455. sorted_sequence: Tensor,
  22456. input: Tensor,
  22457. *,
  22458. out_int32: _bool = False,
  22459. right: _bool = False,
  22460. side: str | None = None,
  22461. sorter: Tensor | None = None,
  22462. out: Tensor | None = None,
  22463. ) -> Tensor:
  22464. r"""
  22465. searchsorted(sorted_sequence, values, *, out_int32=False, right=False, side=None, out=None, sorter=None) -> Tensor
  22466. Find the indices from the *innermost* dimension of :attr:`sorted_sequence` such that, if the
  22467. corresponding values in :attr:`values` were inserted before the indices, when sorted, the order
  22468. of the corresponding *innermost* dimension within :attr:`sorted_sequence` would be preserved.
  22469. Return a new tensor with the same size as :attr:`values`. More formally,
  22470. the returned index satisfies the following rules:
  22471. .. list-table::
  22472. :widths: 12 10 78
  22473. :header-rows: 1
  22474. * - :attr:`sorted_sequence`
  22475. - :attr:`right`
  22476. - *returned index satisfies*
  22477. * - 1-D
  22478. - False
  22479. - ``sorted_sequence[i-1] < values[m][n]...[l][x] <= sorted_sequence[i]``
  22480. * - 1-D
  22481. - True
  22482. - ``sorted_sequence[i-1] <= values[m][n]...[l][x] < sorted_sequence[i]``
  22483. * - N-D
  22484. - False
  22485. - ``sorted_sequence[m][n]...[l][i-1] < values[m][n]...[l][x] <= sorted_sequence[m][n]...[l][i]``
  22486. * - N-D
  22487. - True
  22488. - ``sorted_sequence[m][n]...[l][i-1] <= values[m][n]...[l][x] < sorted_sequence[m][n]...[l][i]``
  22489. Args:
  22490. sorted_sequence (Tensor): N-D or 1-D tensor, containing monotonically increasing sequence on the *innermost*
  22491. dimension unless :attr:`sorter` is provided, in which case the sequence does not
  22492. need to be sorted
  22493. values (Tensor or Scalar): N-D tensor or a Scalar containing the search value(s).
  22494. Keyword args:
  22495. out_int32 (bool, optional): indicate the output data type. torch.int32 if True, torch.int64 otherwise.
  22496. Default value is False, i.e. default output data type is torch.int64.
  22497. right (bool, optional): if False, return the first suitable location that is found. If True, return the
  22498. last such index. If no suitable index found, return 0 for non-numerical value
  22499. (eg. nan, inf) or the size of *innermost* dimension within :attr:`sorted_sequence`
  22500. (one pass the last index of the *innermost* dimension). In other words, if False,
  22501. gets the lower bound index for each value in :attr:`values` on the corresponding
  22502. *innermost* dimension of the :attr:`sorted_sequence`. If True, gets the upper
  22503. bound index instead. Default value is False. :attr:`side` does the same and is
  22504. preferred. It will error if :attr:`side` is set to "left" while this is True.
  22505. side (str, optional): the same as :attr:`right` but preferred. "left" corresponds to False for :attr:`right`
  22506. and "right" corresponds to True for :attr:`right`. It will error if this is set to
  22507. "left" while :attr:`right` is True. Default value is None.
  22508. out (Tensor, optional): the output tensor, must be the same size as :attr:`values` if provided.
  22509. sorter (LongTensor, optional): if provided, a tensor matching the shape of the unsorted
  22510. :attr:`sorted_sequence` containing a sequence of indices that sort it in the
  22511. ascending order on the innermost dimension
  22512. Example::
  22513. >>> sorted_sequence = torch.tensor([[1, 3, 5, 7, 9], [2, 4, 6, 8, 10]])
  22514. >>> sorted_sequence
  22515. tensor([[ 1, 3, 5, 7, 9],
  22516. [ 2, 4, 6, 8, 10]])
  22517. >>> values = torch.tensor([[3, 6, 9], [3, 6, 9]])
  22518. >>> values
  22519. tensor([[3, 6, 9],
  22520. [3, 6, 9]])
  22521. >>> torch.searchsorted(sorted_sequence, values)
  22522. tensor([[1, 3, 4],
  22523. [1, 2, 4]])
  22524. >>> torch.searchsorted(sorted_sequence, values, side='right')
  22525. tensor([[2, 3, 5],
  22526. [1, 3, 4]])
  22527. >>> sorted_sequence_1d = torch.tensor([1, 3, 5, 7, 9])
  22528. >>> sorted_sequence_1d
  22529. tensor([1, 3, 5, 7, 9])
  22530. >>> torch.searchsorted(sorted_sequence_1d, values)
  22531. tensor([[1, 3, 4],
  22532. [1, 3, 4]])
  22533. """
  22534. @overload
  22535. def searchsorted(
  22536. sorted_sequence: Tensor,
  22537. self: Number | _complex,
  22538. *,
  22539. out_int32: _bool = False,
  22540. right: _bool = False,
  22541. side: str | None = None,
  22542. sorter: Tensor | None = None,
  22543. out: Tensor | None = None,
  22544. ) -> Tensor:
  22545. r"""
  22546. searchsorted(sorted_sequence, values, *, out_int32=False, right=False, side=None, out=None, sorter=None) -> Tensor
  22547. Find the indices from the *innermost* dimension of :attr:`sorted_sequence` such that, if the
  22548. corresponding values in :attr:`values` were inserted before the indices, when sorted, the order
  22549. of the corresponding *innermost* dimension within :attr:`sorted_sequence` would be preserved.
  22550. Return a new tensor with the same size as :attr:`values`. More formally,
  22551. the returned index satisfies the following rules:
  22552. .. list-table::
  22553. :widths: 12 10 78
  22554. :header-rows: 1
  22555. * - :attr:`sorted_sequence`
  22556. - :attr:`right`
  22557. - *returned index satisfies*
  22558. * - 1-D
  22559. - False
  22560. - ``sorted_sequence[i-1] < values[m][n]...[l][x] <= sorted_sequence[i]``
  22561. * - 1-D
  22562. - True
  22563. - ``sorted_sequence[i-1] <= values[m][n]...[l][x] < sorted_sequence[i]``
  22564. * - N-D
  22565. - False
  22566. - ``sorted_sequence[m][n]...[l][i-1] < values[m][n]...[l][x] <= sorted_sequence[m][n]...[l][i]``
  22567. * - N-D
  22568. - True
  22569. - ``sorted_sequence[m][n]...[l][i-1] <= values[m][n]...[l][x] < sorted_sequence[m][n]...[l][i]``
  22570. Args:
  22571. sorted_sequence (Tensor): N-D or 1-D tensor, containing monotonically increasing sequence on the *innermost*
  22572. dimension unless :attr:`sorter` is provided, in which case the sequence does not
  22573. need to be sorted
  22574. values (Tensor or Scalar): N-D tensor or a Scalar containing the search value(s).
  22575. Keyword args:
  22576. out_int32 (bool, optional): indicate the output data type. torch.int32 if True, torch.int64 otherwise.
  22577. Default value is False, i.e. default output data type is torch.int64.
  22578. right (bool, optional): if False, return the first suitable location that is found. If True, return the
  22579. last such index. If no suitable index found, return 0 for non-numerical value
  22580. (eg. nan, inf) or the size of *innermost* dimension within :attr:`sorted_sequence`
  22581. (one pass the last index of the *innermost* dimension). In other words, if False,
  22582. gets the lower bound index for each value in :attr:`values` on the corresponding
  22583. *innermost* dimension of the :attr:`sorted_sequence`. If True, gets the upper
  22584. bound index instead. Default value is False. :attr:`side` does the same and is
  22585. preferred. It will error if :attr:`side` is set to "left" while this is True.
  22586. side (str, optional): the same as :attr:`right` but preferred. "left" corresponds to False for :attr:`right`
  22587. and "right" corresponds to True for :attr:`right`. It will error if this is set to
  22588. "left" while :attr:`right` is True. Default value is None.
  22589. out (Tensor, optional): the output tensor, must be the same size as :attr:`values` if provided.
  22590. sorter (LongTensor, optional): if provided, a tensor matching the shape of the unsorted
  22591. :attr:`sorted_sequence` containing a sequence of indices that sort it in the
  22592. ascending order on the innermost dimension
  22593. Example::
  22594. >>> sorted_sequence = torch.tensor([[1, 3, 5, 7, 9], [2, 4, 6, 8, 10]])
  22595. >>> sorted_sequence
  22596. tensor([[ 1, 3, 5, 7, 9],
  22597. [ 2, 4, 6, 8, 10]])
  22598. >>> values = torch.tensor([[3, 6, 9], [3, 6, 9]])
  22599. >>> values
  22600. tensor([[3, 6, 9],
  22601. [3, 6, 9]])
  22602. >>> torch.searchsorted(sorted_sequence, values)
  22603. tensor([[1, 3, 4],
  22604. [1, 2, 4]])
  22605. >>> torch.searchsorted(sorted_sequence, values, side='right')
  22606. tensor([[2, 3, 5],
  22607. [1, 3, 4]])
  22608. >>> sorted_sequence_1d = torch.tensor([1, 3, 5, 7, 9])
  22609. >>> sorted_sequence_1d
  22610. tensor([1, 3, 5, 7, 9])
  22611. >>> torch.searchsorted(sorted_sequence_1d, values)
  22612. tensor([[1, 3, 4],
  22613. [1, 3, 4]])
  22614. """
  22615. def segment_reduce(
  22616. data: Tensor,
  22617. reduce: str,
  22618. *,
  22619. lengths: Tensor | None = None,
  22620. indices: Tensor | None = None,
  22621. offsets: Tensor | None = None,
  22622. axis: _int = 0,
  22623. unsafe: _bool = False,
  22624. initial: Number | _complex | None = None,
  22625. ) -> Tensor:
  22626. r"""
  22627. 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
  22628. Perform a segment reduction operation on the input tensor along the specified axis.
  22629. Args:
  22630. data (Tensor): The input tensor on which the segment reduction operation will be performed.
  22631. reduce (str): The type of reduction operation. Supported values are ``sum``, ``mean``, ``max``, ``min``, ``prod``.
  22632. Keyword args:
  22633. lengths (Tensor, optional): Length of each segment. Default: ``None``.
  22634. offsets (Tensor, optional): Offset of each segment. Default: ``None``.
  22635. axis (int, optional): The axis perform reduction. Default: ``0``.
  22636. unsafe (bool, optional): Skip validation If `True`. Default: ``False``.
  22637. initial (Number, optional): The initial value for the reduction operation. Default: ``None``.
  22638. Example::
  22639. >>> data = torch.tensor([[1, 2, 3, 4],[5, 6, 7, 8],[9, 10, 11, 12]], dtype=torch.float32, device='cuda')
  22640. >>> lengths = torch.tensor([2, 1], device='cuda')
  22641. >>> torch.segment_reduce(data, 'max', lengths=lengths)
  22642. tensor([[ 5., 6., 7., 8.],
  22643. [ 9., 10., 11., 12.]], device='cuda:0')
  22644. """
  22645. @overload
  22646. def select(input: Tensor, dim: _int, index: _int | SymInt) -> Tensor:
  22647. r"""
  22648. select(input, dim, index) -> Tensor
  22649. Slices the :attr:`input` tensor along the selected dimension at the given index.
  22650. This function returns a view of the original tensor with the given dimension removed.
  22651. .. note:: If :attr:`input` is a sparse tensor and returning a view of
  22652. the tensor is not possible, a RuntimeError exception is
  22653. raised. In this is the case, consider using
  22654. :func:`torch.select_copy` function.
  22655. Args:
  22656. input (Tensor): the input tensor.
  22657. dim (int): the dimension to slice
  22658. index (int): the index to select with
  22659. .. note::
  22660. :meth:`select` is equivalent to slicing. For example,
  22661. ``tensor.select(0, index)`` is equivalent to ``tensor[index]`` and
  22662. ``tensor.select(2, index)`` is equivalent to ``tensor[:,:,index]``.
  22663. """
  22664. @overload
  22665. def select(
  22666. input: Tensor,
  22667. dim: str | EllipsisType | None,
  22668. index: _int,
  22669. ) -> Tensor:
  22670. r"""
  22671. select(input, dim, index) -> Tensor
  22672. Slices the :attr:`input` tensor along the selected dimension at the given index.
  22673. This function returns a view of the original tensor with the given dimension removed.
  22674. .. note:: If :attr:`input` is a sparse tensor and returning a view of
  22675. the tensor is not possible, a RuntimeError exception is
  22676. raised. In this is the case, consider using
  22677. :func:`torch.select_copy` function.
  22678. Args:
  22679. input (Tensor): the input tensor.
  22680. dim (int): the dimension to slice
  22681. index (int): the index to select with
  22682. .. note::
  22683. :meth:`select` is equivalent to slicing. For example,
  22684. ``tensor.select(0, index)`` is equivalent to ``tensor[index]`` and
  22685. ``tensor.select(2, index)`` is equivalent to ``tensor[:,:,index]``.
  22686. """
  22687. def select_copy(
  22688. input: Tensor,
  22689. dim: _int,
  22690. index: _int | SymInt,
  22691. *,
  22692. out: Tensor | None = None,
  22693. ) -> Tensor:
  22694. r"""
  22695. Performs the same operation as :func:`torch.select`, but all output tensors
  22696. are freshly created instead of aliasing the input.
  22697. """
  22698. def select_scatter(
  22699. input: Tensor,
  22700. src: Tensor,
  22701. dim: _int,
  22702. index: _int | SymInt,
  22703. ) -> Tensor:
  22704. r"""
  22705. select_scatter(input, src, dim, index) -> Tensor
  22706. Embeds the values of the :attr:`src` tensor into :attr:`input` at the given index.
  22707. This function returns a tensor with fresh storage; it does not create a view.
  22708. Args:
  22709. input (Tensor): the input tensor.
  22710. src (Tensor): The tensor to embed into :attr:`input`
  22711. dim (int): the dimension to insert the slice into.
  22712. index (int): the index to select with
  22713. .. note::
  22714. :attr:`src` must be of the proper size in order to be embedded
  22715. into :attr:`input`. Specifically, it should have the same shape as
  22716. ``torch.select(input, dim, index)``
  22717. Example::
  22718. >>> a = torch.zeros(2, 2)
  22719. >>> b = torch.ones(2)
  22720. >>> a.select_scatter(b, 0, 0)
  22721. tensor([[1., 1.],
  22722. [0., 0.]])
  22723. """
  22724. def selu(input: Tensor) -> Tensor: ...
  22725. def selu_(input: Tensor) -> Tensor: ...
  22726. def set_flush_denormal(mode: _bool) -> _bool:
  22727. r"""
  22728. set_flush_denormal(mode) -> bool
  22729. Disables denormal floating numbers on CPU.
  22730. Returns ``True`` if your system supports flushing denormal numbers and it
  22731. successfully configures flush denormal mode. :meth:`~torch.set_flush_denormal`
  22732. is supported on x86 architectures supporting SSE3 and AArch64 architecture.
  22733. Args:
  22734. mode (bool): Controls whether to enable flush denormal mode or not
  22735. Example::
  22736. >>> torch.set_flush_denormal(True)
  22737. True
  22738. >>> torch.tensor([1e-323], dtype=torch.float64)
  22739. tensor([ 0.], dtype=torch.float64)
  22740. >>> torch.set_flush_denormal(False)
  22741. True
  22742. >>> torch.tensor([1e-323], dtype=torch.float64)
  22743. tensor(9.88131e-324 *
  22744. [ 1.0000], dtype=torch.float64)
  22745. """
  22746. def set_num_interop_threads(num: _int) -> None:
  22747. r"""
  22748. set_num_interop_threads(int)
  22749. Sets the number of threads used for interop parallelism
  22750. (e.g. in JIT interpreter) on CPU.
  22751. .. warning::
  22752. Can only be called once and before any inter-op parallel work
  22753. is started (e.g. JIT execution).
  22754. """
  22755. def set_num_threads(num: _int) -> None:
  22756. r"""
  22757. set_num_threads(int)
  22758. Sets the number of threads used for intraop parallelism on CPU.
  22759. .. warning::
  22760. To ensure that the correct number of threads is used, set_num_threads
  22761. must be called before running eager, JIT or autograd code.
  22762. """
  22763. def sgn(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  22764. r"""
  22765. sgn(input, *, out=None) -> Tensor
  22766. This function is an extension of torch.sign() to complex tensors.
  22767. It computes a new tensor whose elements have
  22768. the same angles as the corresponding elements of :attr:`input` and
  22769. absolute values (i.e. magnitudes) of one for complex tensors and
  22770. is equivalent to torch.sign() for non-complex tensors.
  22771. .. math::
  22772. \text{out}_{i} = \begin{cases}
  22773. 0 & |\text{{input}}_i| == 0 \\
  22774. \frac{{\text{{input}}_i}}{|{\text{{input}}_i}|} & \text{otherwise}
  22775. \end{cases}
  22776. Args:
  22777. input (Tensor): the input tensor.
  22778. Keyword args:
  22779. out (Tensor, optional): the output tensor.
  22780. Example::
  22781. >>> t = torch.tensor([3+4j, 7-24j, 0, 1+2j])
  22782. >>> t.sgn()
  22783. tensor([0.6000+0.8000j, 0.2800-0.9600j, 0.0000+0.0000j, 0.4472+0.8944j])
  22784. """
  22785. def sigmoid(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  22786. r"""
  22787. sigmoid(input, *, out=None) -> Tensor
  22788. Alias for :func:`torch.special.expit`.
  22789. """
  22790. def sigmoid_(input: Tensor) -> Tensor: ...
  22791. def sign(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  22792. r"""
  22793. sign(input, *, out=None) -> Tensor
  22794. Returns a new tensor with the signs of the elements of :attr:`input`.
  22795. .. math::
  22796. \text{out}_{i} = \operatorname{sgn}(\text{input}_{i})
  22797. Args:
  22798. input (Tensor): the input tensor.
  22799. Keyword args:
  22800. out (Tensor, optional): the output tensor.
  22801. Example::
  22802. >>> a = torch.tensor([0.7, -1.2, 0., 2.3])
  22803. >>> a
  22804. tensor([ 0.7000, -1.2000, 0.0000, 2.3000])
  22805. >>> torch.sign(a)
  22806. tensor([ 1., -1., 0., 1.])
  22807. """
  22808. def signbit(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  22809. r"""
  22810. signbit(input, *, out=None) -> Tensor
  22811. Tests if each element of :attr:`input` has its sign bit set or not.
  22812. Args:
  22813. input (Tensor): the input tensor.
  22814. Keyword args:
  22815. out (Tensor, optional): the output tensor.
  22816. Example::
  22817. >>> a = torch.tensor([0.7, -1.2, 0., 2.3])
  22818. >>> torch.signbit(a)
  22819. tensor([ False, True, False, False])
  22820. >>> a = torch.tensor([-0.0, 0.0])
  22821. >>> torch.signbit(a)
  22822. tensor([ True, False])
  22823. .. note::
  22824. signbit handles signed zeros, so negative zero (-0) returns True.
  22825. """
  22826. def sin(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  22827. r"""
  22828. sin(input, *, out=None) -> Tensor
  22829. Returns a new tensor with the sine of the elements of :attr:`input`.
  22830. .. math::
  22831. \text{out}_{i} = \sin(\text{input}_{i})
  22832. Args:
  22833. input (Tensor): the input tensor.
  22834. Keyword args:
  22835. out (Tensor, optional): the output tensor.
  22836. Example::
  22837. >>> a = torch.randn(4)
  22838. >>> a
  22839. tensor([-0.5461, 0.1347, -2.7266, -0.2746])
  22840. >>> torch.sin(a)
  22841. tensor([-0.5194, 0.1343, -0.4032, -0.2711])
  22842. """
  22843. def sin_(input: Tensor) -> Tensor: ...
  22844. def sinc(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  22845. r"""
  22846. sinc(input, *, out=None) -> Tensor
  22847. Alias for :func:`torch.special.sinc`.
  22848. """
  22849. def sinc_(input: Tensor) -> Tensor: ...
  22850. def sinh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  22851. r"""
  22852. sinh(input, *, out=None) -> Tensor
  22853. Returns a new tensor with the hyperbolic sine of the elements of
  22854. :attr:`input`.
  22855. .. math::
  22856. \text{out}_{i} = \sinh(\text{input}_{i})
  22857. Args:
  22858. input (Tensor): the input tensor.
  22859. Keyword args:
  22860. out (Tensor, optional): the output tensor.
  22861. Example::
  22862. >>> a = torch.randn(4)
  22863. >>> a
  22864. tensor([ 0.5380, -0.8632, -0.1265, 0.9399])
  22865. >>> torch.sinh(a)
  22866. tensor([ 0.5644, -0.9744, -0.1268, 1.0845])
  22867. .. note::
  22868. When :attr:`input` is on the CPU, the implementation of torch.sinh may use
  22869. the Sleef library, which rounds very large results to infinity or negative
  22870. infinity. See `here <https://sleef.org/purec.xhtml>`_ for details.
  22871. """
  22872. def sinh_(input: Tensor) -> Tensor: ...
  22873. def slice_copy(
  22874. input: Tensor,
  22875. dim: _int = 0,
  22876. start: _int | SymInt | None = None,
  22877. end: _int | SymInt | None = None,
  22878. step: _int | SymInt = 1,
  22879. *,
  22880. out: Tensor | None = None,
  22881. ) -> Tensor:
  22882. r"""
  22883. Performs the same operation as :func:`torch.slice`, but all output tensors
  22884. are freshly created instead of aliasing the input.
  22885. """
  22886. def slice_inverse(
  22887. input: Tensor,
  22888. src: Tensor,
  22889. dim: _int = 0,
  22890. start: _int | SymInt | None = None,
  22891. end: _int | SymInt | None = None,
  22892. step: _int | SymInt = 1,
  22893. ) -> Tensor: ...
  22894. def slice_scatter(
  22895. input: Tensor,
  22896. src: Tensor,
  22897. dim: _int = 0,
  22898. start: _int | SymInt | None = None,
  22899. end: _int | SymInt | None = None,
  22900. step: _int | SymInt = 1,
  22901. *,
  22902. out: Tensor | None = None,
  22903. ) -> Tensor:
  22904. r"""
  22905. slice_scatter(input, src, dim=0, start=None, end=None, step=1) -> Tensor
  22906. Embeds the values of the :attr:`src` tensor into :attr:`input` at the given
  22907. dimension.
  22908. This function returns a tensor with fresh storage; it does not create a view.
  22909. Args:
  22910. input (Tensor): the input tensor.
  22911. src (Tensor): The tensor to embed into :attr:`input`
  22912. dim (int): the dimension to insert the slice into
  22913. start (Optional[int]): the start index of where to insert the slice
  22914. end (Optional[int]): the end index of where to insert the slice
  22915. step (int): the how many elements to skip in
  22916. Example::
  22917. >>> a = torch.zeros(8, 8)
  22918. >>> b = torch.ones(2, 8)
  22919. >>> a.slice_scatter(b, start=6)
  22920. tensor([[0., 0., 0., 0., 0., 0., 0., 0.],
  22921. [0., 0., 0., 0., 0., 0., 0., 0.],
  22922. [0., 0., 0., 0., 0., 0., 0., 0.],
  22923. [0., 0., 0., 0., 0., 0., 0., 0.],
  22924. [0., 0., 0., 0., 0., 0., 0., 0.],
  22925. [0., 0., 0., 0., 0., 0., 0., 0.],
  22926. [1., 1., 1., 1., 1., 1., 1., 1.],
  22927. [1., 1., 1., 1., 1., 1., 1., 1.]])
  22928. >>> b = torch.ones(8, 2)
  22929. >>> a.slice_scatter(b, dim=1, start=2, end=6, step=2)
  22930. tensor([[0., 0., 1., 0., 1., 0., 0., 0.],
  22931. [0., 0., 1., 0., 1., 0., 0., 0.],
  22932. [0., 0., 1., 0., 1., 0., 0., 0.],
  22933. [0., 0., 1., 0., 1., 0., 0., 0.],
  22934. [0., 0., 1., 0., 1., 0., 0., 0.],
  22935. [0., 0., 1., 0., 1., 0., 0., 0.],
  22936. [0., 0., 1., 0., 1., 0., 0., 0.],
  22937. [0., 0., 1., 0., 1., 0., 0., 0.]])
  22938. """
  22939. def slogdet(
  22940. input: Tensor,
  22941. *,
  22942. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  22943. ) -> torch.return_types.slogdet:
  22944. r"""
  22945. slogdet(input) -> (Tensor, Tensor)
  22946. Alias for :func:`torch.linalg.slogdet`
  22947. """
  22948. def smm(input: Tensor, mat2: Tensor) -> Tensor:
  22949. r"""
  22950. smm(input, mat) -> Tensor
  22951. Performs a matrix multiplication of the sparse matrix :attr:`input`
  22952. with the dense matrix :attr:`mat`.
  22953. Args:
  22954. input (Tensor): a sparse matrix to be matrix multiplied
  22955. mat (Tensor): a dense matrix to be matrix multiplied
  22956. """
  22957. @overload
  22958. def softmax(
  22959. input: Tensor,
  22960. dim: _int,
  22961. dtype: _dtype | None = None,
  22962. *,
  22963. out: Tensor | None = None,
  22964. ) -> Tensor:
  22965. r"""
  22966. softmax(input, dim, *, dtype=None) -> Tensor
  22967. Alias for :func:`torch.nn.functional.softmax`.
  22968. """
  22969. @overload
  22970. def softmax(
  22971. input: Tensor,
  22972. dim: str | EllipsisType | None,
  22973. *,
  22974. dtype: _dtype | None = None,
  22975. ) -> Tensor:
  22976. r"""
  22977. softmax(input, dim, *, dtype=None) -> Tensor
  22978. Alias for :func:`torch.nn.functional.softmax`.
  22979. """
  22980. @overload
  22981. def sort(
  22982. input: Tensor,
  22983. *,
  22984. stable: _bool | None,
  22985. dim: _int = -1,
  22986. descending: _bool = False,
  22987. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  22988. ) -> torch.return_types.sort:
  22989. r"""
  22990. sort(input, dim=-1, descending=False, *, stable=False, out=None) -> (Tensor, LongTensor)
  22991. Sorts the elements of the :attr:`input` tensor along a given dimension
  22992. in ascending order by value.
  22993. If :attr:`dim` is not given, the last dimension of the `input` is chosen.
  22994. If :attr:`descending` is ``True`` then the elements are sorted in descending
  22995. order by value.
  22996. If :attr:`stable` is ``True`` then the sorting routine becomes stable, preserving
  22997. the order of equivalent elements.
  22998. A namedtuple of (values, indices) is returned, where the `values` are the
  22999. sorted values and `indices` are the indices of the elements in the original
  23000. `input` tensor.
  23001. Args:
  23002. input (Tensor): the input tensor.
  23003. dim (int, optional): the dimension to sort along
  23004. descending (bool, optional): controls the sorting order (ascending or descending)
  23005. Keyword args:
  23006. stable (bool, optional): makes the sorting routine stable, which guarantees that the order
  23007. of equivalent elements is preserved.
  23008. out (tuple, optional): the output tuple of (`Tensor`, `LongTensor`) that can
  23009. be optionally given to be used as output buffers
  23010. Example::
  23011. >>> x = torch.randn(3, 4)
  23012. >>> sorted, indices = torch.sort(x)
  23013. >>> sorted
  23014. tensor([[-0.2162, 0.0608, 0.6719, 2.3332],
  23015. [-0.5793, 0.0061, 0.6058, 0.9497],
  23016. [-0.5071, 0.3343, 0.9553, 1.0960]])
  23017. >>> indices
  23018. tensor([[ 1, 0, 2, 3],
  23019. [ 3, 1, 0, 2],
  23020. [ 0, 3, 1, 2]])
  23021. >>> sorted, indices = torch.sort(x, 0)
  23022. >>> sorted
  23023. tensor([[-0.5071, -0.2162, 0.6719, -0.5793],
  23024. [ 0.0608, 0.0061, 0.9497, 0.3343],
  23025. [ 0.6058, 0.9553, 1.0960, 2.3332]])
  23026. >>> indices
  23027. tensor([[ 2, 0, 0, 1],
  23028. [ 0, 1, 1, 2],
  23029. [ 1, 2, 2, 0]])
  23030. >>> x = torch.tensor([0, 1] * 9)
  23031. >>> x.sort()
  23032. torch.return_types.sort(
  23033. values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
  23034. indices=tensor([ 2, 16, 4, 6, 14, 8, 0, 10, 12, 9, 17, 15, 13, 11, 7, 5, 3, 1]))
  23035. >>> x.sort(stable=True)
  23036. torch.return_types.sort(
  23037. values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
  23038. indices=tensor([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 17]))
  23039. """
  23040. @overload
  23041. def sort(
  23042. input: Tensor,
  23043. dim: _int = -1,
  23044. descending: _bool = False,
  23045. *,
  23046. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  23047. ) -> torch.return_types.sort:
  23048. r"""
  23049. sort(input, dim=-1, descending=False, *, stable=False, out=None) -> (Tensor, LongTensor)
  23050. Sorts the elements of the :attr:`input` tensor along a given dimension
  23051. in ascending order by value.
  23052. If :attr:`dim` is not given, the last dimension of the `input` is chosen.
  23053. If :attr:`descending` is ``True`` then the elements are sorted in descending
  23054. order by value.
  23055. If :attr:`stable` is ``True`` then the sorting routine becomes stable, preserving
  23056. the order of equivalent elements.
  23057. A namedtuple of (values, indices) is returned, where the `values` are the
  23058. sorted values and `indices` are the indices of the elements in the original
  23059. `input` tensor.
  23060. Args:
  23061. input (Tensor): the input tensor.
  23062. dim (int, optional): the dimension to sort along
  23063. descending (bool, optional): controls the sorting order (ascending or descending)
  23064. Keyword args:
  23065. stable (bool, optional): makes the sorting routine stable, which guarantees that the order
  23066. of equivalent elements is preserved.
  23067. out (tuple, optional): the output tuple of (`Tensor`, `LongTensor`) that can
  23068. be optionally given to be used as output buffers
  23069. Example::
  23070. >>> x = torch.randn(3, 4)
  23071. >>> sorted, indices = torch.sort(x)
  23072. >>> sorted
  23073. tensor([[-0.2162, 0.0608, 0.6719, 2.3332],
  23074. [-0.5793, 0.0061, 0.6058, 0.9497],
  23075. [-0.5071, 0.3343, 0.9553, 1.0960]])
  23076. >>> indices
  23077. tensor([[ 1, 0, 2, 3],
  23078. [ 3, 1, 0, 2],
  23079. [ 0, 3, 1, 2]])
  23080. >>> sorted, indices = torch.sort(x, 0)
  23081. >>> sorted
  23082. tensor([[-0.5071, -0.2162, 0.6719, -0.5793],
  23083. [ 0.0608, 0.0061, 0.9497, 0.3343],
  23084. [ 0.6058, 0.9553, 1.0960, 2.3332]])
  23085. >>> indices
  23086. tensor([[ 2, 0, 0, 1],
  23087. [ 0, 1, 1, 2],
  23088. [ 1, 2, 2, 0]])
  23089. >>> x = torch.tensor([0, 1] * 9)
  23090. >>> x.sort()
  23091. torch.return_types.sort(
  23092. values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
  23093. indices=tensor([ 2, 16, 4, 6, 14, 8, 0, 10, 12, 9, 17, 15, 13, 11, 7, 5, 3, 1]))
  23094. >>> x.sort(stable=True)
  23095. torch.return_types.sort(
  23096. values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
  23097. indices=tensor([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 17]))
  23098. """
  23099. @overload
  23100. def sort(
  23101. input: Tensor,
  23102. *,
  23103. stable: _bool | None,
  23104. dim: str | EllipsisType | None,
  23105. descending: _bool = False,
  23106. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  23107. ) -> torch.return_types.sort:
  23108. r"""
  23109. sort(input, dim=-1, descending=False, *, stable=False, out=None) -> (Tensor, LongTensor)
  23110. Sorts the elements of the :attr:`input` tensor along a given dimension
  23111. in ascending order by value.
  23112. If :attr:`dim` is not given, the last dimension of the `input` is chosen.
  23113. If :attr:`descending` is ``True`` then the elements are sorted in descending
  23114. order by value.
  23115. If :attr:`stable` is ``True`` then the sorting routine becomes stable, preserving
  23116. the order of equivalent elements.
  23117. A namedtuple of (values, indices) is returned, where the `values` are the
  23118. sorted values and `indices` are the indices of the elements in the original
  23119. `input` tensor.
  23120. Args:
  23121. input (Tensor): the input tensor.
  23122. dim (int, optional): the dimension to sort along
  23123. descending (bool, optional): controls the sorting order (ascending or descending)
  23124. Keyword args:
  23125. stable (bool, optional): makes the sorting routine stable, which guarantees that the order
  23126. of equivalent elements is preserved.
  23127. out (tuple, optional): the output tuple of (`Tensor`, `LongTensor`) that can
  23128. be optionally given to be used as output buffers
  23129. Example::
  23130. >>> x = torch.randn(3, 4)
  23131. >>> sorted, indices = torch.sort(x)
  23132. >>> sorted
  23133. tensor([[-0.2162, 0.0608, 0.6719, 2.3332],
  23134. [-0.5793, 0.0061, 0.6058, 0.9497],
  23135. [-0.5071, 0.3343, 0.9553, 1.0960]])
  23136. >>> indices
  23137. tensor([[ 1, 0, 2, 3],
  23138. [ 3, 1, 0, 2],
  23139. [ 0, 3, 1, 2]])
  23140. >>> sorted, indices = torch.sort(x, 0)
  23141. >>> sorted
  23142. tensor([[-0.5071, -0.2162, 0.6719, -0.5793],
  23143. [ 0.0608, 0.0061, 0.9497, 0.3343],
  23144. [ 0.6058, 0.9553, 1.0960, 2.3332]])
  23145. >>> indices
  23146. tensor([[ 2, 0, 0, 1],
  23147. [ 0, 1, 1, 2],
  23148. [ 1, 2, 2, 0]])
  23149. >>> x = torch.tensor([0, 1] * 9)
  23150. >>> x.sort()
  23151. torch.return_types.sort(
  23152. values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
  23153. indices=tensor([ 2, 16, 4, 6, 14, 8, 0, 10, 12, 9, 17, 15, 13, 11, 7, 5, 3, 1]))
  23154. >>> x.sort(stable=True)
  23155. torch.return_types.sort(
  23156. values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
  23157. indices=tensor([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 17]))
  23158. """
  23159. @overload
  23160. def sort(
  23161. input: Tensor,
  23162. dim: str | EllipsisType | None,
  23163. descending: _bool = False,
  23164. *,
  23165. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  23166. ) -> torch.return_types.sort:
  23167. r"""
  23168. sort(input, dim=-1, descending=False, *, stable=False, out=None) -> (Tensor, LongTensor)
  23169. Sorts the elements of the :attr:`input` tensor along a given dimension
  23170. in ascending order by value.
  23171. If :attr:`dim` is not given, the last dimension of the `input` is chosen.
  23172. If :attr:`descending` is ``True`` then the elements are sorted in descending
  23173. order by value.
  23174. If :attr:`stable` is ``True`` then the sorting routine becomes stable, preserving
  23175. the order of equivalent elements.
  23176. A namedtuple of (values, indices) is returned, where the `values` are the
  23177. sorted values and `indices` are the indices of the elements in the original
  23178. `input` tensor.
  23179. Args:
  23180. input (Tensor): the input tensor.
  23181. dim (int, optional): the dimension to sort along
  23182. descending (bool, optional): controls the sorting order (ascending or descending)
  23183. Keyword args:
  23184. stable (bool, optional): makes the sorting routine stable, which guarantees that the order
  23185. of equivalent elements is preserved.
  23186. out (tuple, optional): the output tuple of (`Tensor`, `LongTensor`) that can
  23187. be optionally given to be used as output buffers
  23188. Example::
  23189. >>> x = torch.randn(3, 4)
  23190. >>> sorted, indices = torch.sort(x)
  23191. >>> sorted
  23192. tensor([[-0.2162, 0.0608, 0.6719, 2.3332],
  23193. [-0.5793, 0.0061, 0.6058, 0.9497],
  23194. [-0.5071, 0.3343, 0.9553, 1.0960]])
  23195. >>> indices
  23196. tensor([[ 1, 0, 2, 3],
  23197. [ 3, 1, 0, 2],
  23198. [ 0, 3, 1, 2]])
  23199. >>> sorted, indices = torch.sort(x, 0)
  23200. >>> sorted
  23201. tensor([[-0.5071, -0.2162, 0.6719, -0.5793],
  23202. [ 0.0608, 0.0061, 0.9497, 0.3343],
  23203. [ 0.6058, 0.9553, 1.0960, 2.3332]])
  23204. >>> indices
  23205. tensor([[ 2, 0, 0, 1],
  23206. [ 0, 1, 1, 2],
  23207. [ 1, 2, 2, 0]])
  23208. >>> x = torch.tensor([0, 1] * 9)
  23209. >>> x.sort()
  23210. torch.return_types.sort(
  23211. values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
  23212. indices=tensor([ 2, 16, 4, 6, 14, 8, 0, 10, 12, 9, 17, 15, 13, 11, 7, 5, 3, 1]))
  23213. >>> x.sort(stable=True)
  23214. torch.return_types.sort(
  23215. values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
  23216. indices=tensor([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 17]))
  23217. """
  23218. def sparse_bsc_tensor(
  23219. ccol_indices: Tensor | list,
  23220. row_indices: Tensor | list,
  23221. values: Tensor | list,
  23222. size: _size | None = None,
  23223. *,
  23224. dtype: _dtype | None = None,
  23225. device: DeviceLikeType | None = None,
  23226. requires_grad: _bool = False,
  23227. check_invariants: _bool | None = None,
  23228. ) -> Tensor:
  23229. r"""
  23230. sparse_bsc_tensor(ccol_indices, row_indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) -> Tensor
  23231. Constructs a :ref:`sparse tensor in BSC (Block Compressed Sparse
  23232. Column)) <sparse-bsc-docs>` with specified 2-dimensional blocks at the
  23233. given :attr:`ccol_indices` and :attr:`row_indices`. Sparse matrix
  23234. multiplication operations in BSC format are typically faster than that
  23235. for sparse tensors in COO format. Make you have a look at :ref:`the
  23236. note on the data type of the indices <sparse-bsc-docs>`.
  23237. .. note::
  23238. If the ``device`` argument is not specified the device of the given
  23239. :attr:`values` and indices tensor(s) must match. If, however, the
  23240. argument is specified the input Tensors will be converted to the
  23241. given device and in turn determine the device of the constructed
  23242. sparse tensor.
  23243. Args:
  23244. ccol_indices (array_like): (B+1)-dimensional array of size
  23245. ``(*batchsize, ncolblocks + 1)``. The last element of each
  23246. batch is the number of non-zeros. This tensor encodes the
  23247. index in values and row_indices depending on where the given
  23248. column starts. Each successive number in the tensor subtracted
  23249. by the number before it denotes the number of elements in a
  23250. given column.
  23251. row_indices (array_like): Row block coordinates of each block in
  23252. values. (B+1)-dimensional tensor with the same length
  23253. as values.
  23254. values (array_list): Initial blocks for the tensor. Can be a list,
  23255. tuple, NumPy ``ndarray``, and other types that
  23256. represents a (1 + 2 + K)-dimensional tensor where ``K`` is the
  23257. number of dense dimensions.
  23258. size (list, tuple, :class:`torch.Size`, optional): Size of the
  23259. sparse tensor: ``(*batchsize, nrows * blocksize[0], ncols *
  23260. blocksize[1], *densesize)`` If not provided, the size will be
  23261. inferred as the minimum size big enough to hold all non-zero
  23262. blocks.
  23263. Keyword args:
  23264. dtype (:class:`torch.dtype`, optional): the desired data type of
  23265. returned tensor. Default: if None, infers data type from
  23266. :attr:`values`.
  23267. device (:class:`torch.device`, optional): the desired device of
  23268. returned tensor. Default: if None, uses the current device
  23269. for the default tensor type (see
  23270. :func:`torch.set_default_device`). :attr:`device` will be
  23271. the CPU for CPU tensor types and the current CUDA device for
  23272. CUDA tensor types.
  23273. pin_memory (bool, optional): If set, returned tensor would be allocated in
  23274. the pinned memory. Works only for CPU tensors. Default: ``False``.
  23275. requires_grad (bool, optional): If autograd should record operations on the
  23276. returned tensor. Default: ``False``.
  23277. check_invariants (bool, optional): If sparse tensor invariants are checked.
  23278. Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
  23279. initially False.
  23280. Example::
  23281. >>> ccol_indices = [0, 1, 2]
  23282. >>> row_indices = [0, 1]
  23283. >>> values = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
  23284. >>> torch.sparse_bsc_tensor(torch.tensor(ccol_indices, dtype=torch.int64),
  23285. ... torch.tensor(row_indices, dtype=torch.int64),
  23286. ... torch.tensor(values), dtype=torch.double)
  23287. tensor(ccol_indices=tensor([0, 1, 2]),
  23288. row_indices=tensor([0, 1]),
  23289. values=tensor([[[1., 2.],
  23290. [3., 4.]],
  23291. [[5., 6.],
  23292. [7., 8.]]]), size=(2, 2), nnz=2, dtype=torch.float64,
  23293. layout=torch.sparse_bsc)
  23294. """
  23295. def sparse_bsr_tensor(
  23296. crow_indices: Tensor | list,
  23297. col_indices: Tensor | list,
  23298. values: Tensor | list,
  23299. size: _size | None = None,
  23300. *,
  23301. dtype: _dtype | None = None,
  23302. device: DeviceLikeType | None = None,
  23303. requires_grad: _bool = False,
  23304. check_invariants: _bool | None = None,
  23305. ) -> Tensor:
  23306. r"""
  23307. sparse_bsr_tensor(crow_indices, col_indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) -> Tensor
  23308. Constructs a :ref:`sparse tensor in BSR (Block Compressed Sparse Row))
  23309. <sparse-bsr-docs>` with specified 2-dimensional blocks at the given
  23310. :attr:`crow_indices` and :attr:`col_indices`. Sparse matrix
  23311. multiplication operations in BSR format are typically faster than that
  23312. for sparse tensors in COO format. Make you have a look at :ref:`the
  23313. note on the data type of the indices <sparse-bsr-docs>`.
  23314. .. note::
  23315. If the ``device`` argument is not specified the device of the given
  23316. :attr:`values` and indices tensor(s) must match. If, however, the
  23317. argument is specified the input Tensors will be converted to the
  23318. given device and in turn determine the device of the constructed
  23319. sparse tensor.
  23320. Args:
  23321. crow_indices (array_like): (B+1)-dimensional array of size
  23322. ``(*batchsize, nrowblocks + 1)``. The last element of each
  23323. batch is the number of non-zeros. This tensor encodes the
  23324. block index in values and col_indices depending on where the
  23325. given row block starts. Each successive number in the tensor
  23326. subtracted by the number before it denotes the number of
  23327. blocks in a given row.
  23328. col_indices (array_like): Column block coordinates of each block
  23329. in values. (B+1)-dimensional tensor with the same length as
  23330. values.
  23331. values (array_list): Initial values for the tensor. Can be a list,
  23332. tuple, NumPy ``ndarray``, scalar, and other types that
  23333. represents a (1 + 2 + K)-dimensional tensor where ``K`` is the
  23334. number of dense dimensions.
  23335. size (list, tuple, :class:`torch.Size`, optional): Size of the
  23336. sparse tensor: ``(*batchsize, nrows * blocksize[0], ncols *
  23337. blocksize[1], *densesize)`` where ``blocksize ==
  23338. values.shape[1:3]``. If not provided, the size will be
  23339. inferred as the minimum size big enough to hold all non-zero
  23340. blocks.
  23341. Keyword args:
  23342. dtype (:class:`torch.dtype`, optional): the desired data type of
  23343. returned tensor. Default: if None, infers data type from
  23344. :attr:`values`.
  23345. device (:class:`torch.device`, optional): the desired device of
  23346. returned tensor. Default: if None, uses the current device
  23347. for the default tensor type (see
  23348. :func:`torch.set_default_device`). :attr:`device` will be
  23349. the CPU for CPU tensor types and the current CUDA device for
  23350. CUDA tensor types.
  23351. pin_memory (bool, optional): If set, returned tensor would be allocated in
  23352. the pinned memory. Works only for CPU tensors. Default: ``False``.
  23353. requires_grad (bool, optional): If autograd should record operations on the
  23354. returned tensor. Default: ``False``.
  23355. check_invariants (bool, optional): If sparse tensor invariants are checked.
  23356. Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
  23357. initially False.
  23358. Example::
  23359. >>> crow_indices = [0, 1, 2]
  23360. >>> col_indices = [0, 1]
  23361. >>> values = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
  23362. >>> torch.sparse_bsr_tensor(torch.tensor(crow_indices, dtype=torch.int64),
  23363. ... torch.tensor(col_indices, dtype=torch.int64),
  23364. ... torch.tensor(values), dtype=torch.double)
  23365. tensor(crow_indices=tensor([0, 1, 2]),
  23366. col_indices=tensor([0, 1]),
  23367. values=tensor([[[1., 2.],
  23368. [3., 4.]],
  23369. [[5., 6.],
  23370. [7., 8.]]]), size=(2, 2), nnz=2, dtype=torch.float64,
  23371. layout=torch.sparse_bsr)
  23372. """
  23373. def sparse_compressed_tensor(
  23374. compressed_indices: Tensor | list,
  23375. plain_indices: Tensor | list,
  23376. values: Tensor | list,
  23377. size: _size | None = None,
  23378. *,
  23379. dtype: _dtype | None = None,
  23380. layout: _layout | None = None,
  23381. device: DeviceLikeType | None = None,
  23382. requires_grad: _bool = False,
  23383. check_invariants: _bool | None = None,
  23384. ) -> Tensor:
  23385. r"""
  23386. 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
  23387. Constructs a :ref:`sparse tensor in Compressed Sparse format - CSR,
  23388. CSC, BSR, or BSC - <sparse-compressed-docs>` with specified values at
  23389. the given :attr:`compressed_indices` and :attr:`plain_indices`. Sparse
  23390. matrix multiplication operations in Compressed Sparse format are
  23391. typically faster than that for sparse tensors in COO format. Make you
  23392. have a look at :ref:`the note on the data type of the indices
  23393. <sparse-compressed-docs>`.
  23394. .. note::
  23395. If the ``device`` argument is not specified the device of the given
  23396. :attr:`values` and indices tensor(s) must match. If, however, the
  23397. argument is specified the input Tensors will be converted to the
  23398. given device and in turn determine the device of the constructed
  23399. sparse tensor.
  23400. Args:
  23401. compressed_indices (array_like): (B+1)-dimensional array of size
  23402. ``(*batchsize, compressed_dim_size + 1)``. The last element of
  23403. each batch is the number of non-zero elements or blocks. This
  23404. tensor encodes the index in ``values`` and ``plain_indices``
  23405. depending on where the given compressed dimension (row or
  23406. column) starts. Each successive number in the tensor
  23407. subtracted by the number before it denotes the number of
  23408. elements or blocks in a given compressed dimension.
  23409. plain_indices (array_like): Plain dimension (column or row)
  23410. coordinates of each element or block in values. (B+1)-dimensional
  23411. tensor with the same length as values.
  23412. values (array_list): Initial values for the tensor. Can be a list,
  23413. tuple, NumPy ``ndarray``, scalar, and other types. that
  23414. represents a (1+K)-dimensional (for CSR and CSC layouts) or
  23415. (1+2+K)-dimensional tensor (for BSR and BSC layouts) where
  23416. ``K`` is the number of dense dimensions.
  23417. size (list, tuple, :class:`torch.Size`, optional): Size of the
  23418. sparse tensor: ``(*batchsize, nrows * blocksize[0], ncols *
  23419. blocksize[1], *densesize)`` where ``blocksize[0] ==
  23420. blocksize[1] == 1`` for CSR and CSC formats. If not provided,
  23421. the size will be inferred as the minimum size big enough to
  23422. hold all non-zero elements or blocks.
  23423. Keyword args:
  23424. dtype (:class:`torch.dtype`, optional): the desired data type of
  23425. returned tensor. Default: if None, infers data type from
  23426. :attr:`values`.
  23427. layout (:class:`torch.layout`, required): the desired layout of
  23428. returned tensor: :attr:`torch.sparse_csr`,
  23429. :attr:`torch.sparse_csc`, :attr:`torch.sparse_bsr`, or
  23430. :attr:`torch.sparse_bsc`.
  23431. device (:class:`torch.device`, optional): the desired device of
  23432. returned tensor. Default: if None, uses the current device
  23433. for the default tensor type (see
  23434. :func:`torch.set_default_device`). :attr:`device` will be
  23435. the CPU for CPU tensor types and the current CUDA device for
  23436. CUDA tensor types.
  23437. pin_memory (bool, optional): If set, returned tensor would be allocated in
  23438. the pinned memory. Works only for CPU tensors. Default: ``False``.
  23439. requires_grad (bool, optional): If autograd should record operations on the
  23440. returned tensor. Default: ``False``.
  23441. check_invariants (bool, optional): If sparse tensor invariants are checked.
  23442. Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
  23443. initially False.
  23444. Example::
  23445. >>> compressed_indices = [0, 2, 4]
  23446. >>> plain_indices = [0, 1, 0, 1]
  23447. >>> values = [1, 2, 3, 4]
  23448. >>> torch.sparse_compressed_tensor(torch.tensor(compressed_indices, dtype=torch.int64),
  23449. ... torch.tensor(plain_indices, dtype=torch.int64),
  23450. ... torch.tensor(values), dtype=torch.double, layout=torch.sparse_csr)
  23451. tensor(crow_indices=tensor([0, 2, 4]),
  23452. col_indices=tensor([0, 1, 0, 1]),
  23453. values=tensor([1., 2., 3., 4.]), size=(2, 2), nnz=4,
  23454. dtype=torch.float64, layout=torch.sparse_csr)
  23455. """
  23456. def sparse_coo_tensor(
  23457. indices: Tensor,
  23458. values: Tensor | list,
  23459. size: _size | None = None,
  23460. *,
  23461. dtype: _dtype | None = None,
  23462. device: DeviceLikeType | None = None,
  23463. requires_grad: _bool = False,
  23464. check_invariants: _bool | None = None,
  23465. is_coalesced: _bool | None = None,
  23466. ) -> Tensor:
  23467. r"""
  23468. sparse_coo_tensor(indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None, is_coalesced=None) -> Tensor
  23469. Constructs a :ref:`sparse tensor in COO(rdinate) format
  23470. <sparse-coo-docs>` with specified values at the given
  23471. :attr:`indices`.
  23472. .. note::
  23473. This function returns an :ref:`uncoalesced tensor
  23474. <sparse-uncoalesced-coo-docs>` when :attr:`is_coalesced` is
  23475. unspecified or ``None``.
  23476. .. note::
  23477. If the ``device`` argument is not specified the device of the given
  23478. :attr:`values` and indices tensor(s) must match. If, however, the
  23479. argument is specified the input Tensors will be converted to the
  23480. given device and in turn determine the device of the constructed
  23481. sparse tensor.
  23482. Args:
  23483. indices (array_like): Initial data for the tensor. Can be a list, tuple,
  23484. NumPy ``ndarray``, scalar, and other types. Will be cast to a :class:`torch.LongTensor`
  23485. internally. The indices are the coordinates of the non-zero values in the matrix, and thus
  23486. should be two-dimensional where the first dimension is the number of tensor dimensions and
  23487. the second dimension is the number of non-zero values.
  23488. values (array_like): Initial values for the tensor. Can be a list, tuple,
  23489. NumPy ``ndarray``, scalar, and other types.
  23490. size (list, tuple, or :class:`torch.Size`, optional): Size of the sparse tensor. If not
  23491. provided the size will be inferred as the minimum size big enough to hold all non-zero
  23492. elements.
  23493. Keyword args:
  23494. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  23495. Default: if None, infers data type from :attr:`values`.
  23496. device (:class:`torch.device`, optional): the desired device of returned tensor.
  23497. Default: if None, uses the current device for the default tensor type
  23498. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  23499. for CPU tensor types and the current CUDA device for CUDA tensor types.
  23500. pin_memory (bool, optional): If set, returned tensor would be allocated in
  23501. the pinned memory. Works only for CPU tensors. Default: ``False``.
  23502. requires_grad (bool, optional): If autograd should record operations on the
  23503. returned tensor. Default: ``False``.
  23504. check_invariants (bool, optional): If sparse tensor invariants are checked.
  23505. Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
  23506. initially False.
  23507. is_coalesced (bool, optional): When``True``, the caller is
  23508. responsible for providing tensor indices that correspond to a
  23509. coalesced tensor. If the :attr:`check_invariants` flag is
  23510. False, no error will be raised if the prerequisites are not
  23511. met and this will lead to silently incorrect results. To force
  23512. coalescion please use :meth:`coalesce` on the resulting
  23513. Tensor.
  23514. Default: None: except for trivial cases (e.g. nnz < 2) the
  23515. resulting Tensor has is_coalesced set to ``False```.
  23516. Example::
  23517. >>> i = torch.tensor([[0, 1, 1],
  23518. ... [2, 0, 2]])
  23519. >>> v = torch.tensor([3, 4, 5], dtype=torch.float32)
  23520. >>> torch.sparse_coo_tensor(i, v, [2, 4])
  23521. tensor(indices=tensor([[0, 1, 1],
  23522. [2, 0, 2]]),
  23523. values=tensor([3., 4., 5.]),
  23524. size=(2, 4), nnz=3, layout=torch.sparse_coo)
  23525. >>> torch.sparse_coo_tensor(i, v) # Shape inference
  23526. tensor(indices=tensor([[0, 1, 1],
  23527. [2, 0, 2]]),
  23528. values=tensor([3., 4., 5.]),
  23529. size=(2, 3), nnz=3, layout=torch.sparse_coo)
  23530. >>> torch.sparse_coo_tensor(i, v, [2, 4],
  23531. ... dtype=torch.float64,
  23532. ... device=torch.device('cuda:0'))
  23533. tensor(indices=tensor([[0, 1, 1],
  23534. [2, 0, 2]]),
  23535. values=tensor([3., 4., 5.]),
  23536. device='cuda:0', size=(2, 4), nnz=3, dtype=torch.float64,
  23537. layout=torch.sparse_coo)
  23538. # Create an empty sparse tensor with the following invariants:
  23539. # 1. sparse_dim + dense_dim = len(SparseTensor.shape)
  23540. # 2. SparseTensor._indices().shape = (sparse_dim, nnz)
  23541. # 3. SparseTensor._values().shape = (nnz, SparseTensor.shape[sparse_dim:])
  23542. #
  23543. # For instance, to create an empty sparse tensor with nnz = 0, dense_dim = 0 and
  23544. # sparse_dim = 1 (hence indices is a 2D tensor of shape = (1, 0))
  23545. >>> S = torch.sparse_coo_tensor(torch.empty([1, 0]), [], [1])
  23546. tensor(indices=tensor([], size=(1, 0)),
  23547. values=tensor([], size=(0,)),
  23548. size=(1,), nnz=0, layout=torch.sparse_coo)
  23549. # and to create an empty sparse tensor with nnz = 0, dense_dim = 1 and
  23550. # sparse_dim = 1
  23551. >>> S = torch.sparse_coo_tensor(torch.empty([1, 0]), torch.empty([0, 2]), [1, 2])
  23552. tensor(indices=tensor([], size=(1, 0)),
  23553. values=tensor([], size=(0, 2)),
  23554. size=(1, 2), nnz=0, layout=torch.sparse_coo)
  23555. .. _torch.sparse: https://pytorch.org/docs/stable/sparse.html
  23556. """
  23557. def sparse_csc_tensor(
  23558. ccol_indices: Tensor | list,
  23559. row_indices: Tensor | list,
  23560. values: Tensor | list,
  23561. size: _size | None = None,
  23562. *,
  23563. dtype: _dtype | None = None,
  23564. device: DeviceLikeType | None = None,
  23565. requires_grad: _bool = False,
  23566. check_invariants: _bool | None = None,
  23567. ) -> Tensor:
  23568. r"""
  23569. sparse_csc_tensor(ccol_indices, row_indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) -> Tensor
  23570. Constructs a :ref:`sparse tensor in CSC (Compressed Sparse Column)
  23571. <sparse-csc-docs>` with specified values at the given
  23572. :attr:`ccol_indices` and :attr:`row_indices`. Sparse matrix
  23573. multiplication operations in CSC format are typically faster than that
  23574. for sparse tensors in COO format. Make you have a look at :ref:`the
  23575. note on the data type of the indices <sparse-csc-docs>`.
  23576. .. note::
  23577. If the ``device`` argument is not specified the device of the given
  23578. :attr:`values` and indices tensor(s) must match. If, however, the
  23579. argument is specified the input Tensors will be converted to the
  23580. given device and in turn determine the device of the constructed
  23581. sparse tensor.
  23582. Args:
  23583. ccol_indices (array_like): (B+1)-dimensional array of size
  23584. ``(*batchsize, ncols + 1)``. The last element of each batch
  23585. is the number of non-zeros. This tensor encodes the index in
  23586. values and row_indices depending on where the given column
  23587. starts. Each successive number in the tensor subtracted by the
  23588. number before it denotes the number of elements in a given
  23589. column.
  23590. row_indices (array_like): Row coordinates of each element in
  23591. values. (B+1)-dimensional tensor with the same length as
  23592. values.
  23593. values (array_list): Initial values for the tensor. Can be a list,
  23594. tuple, NumPy ``ndarray``, scalar, and other types that
  23595. represents a (1+K)-dimensional tensor where ``K`` is the number
  23596. of dense dimensions.
  23597. size (list, tuple, :class:`torch.Size`, optional): Size of the
  23598. sparse tensor: ``(*batchsize, nrows, ncols, *densesize)``. If
  23599. not provided, the size will be inferred as the minimum size
  23600. big enough to hold all non-zero elements.
  23601. Keyword args:
  23602. dtype (:class:`torch.dtype`, optional): the desired data type of
  23603. returned tensor. Default: if None, infers data type from
  23604. :attr:`values`.
  23605. device (:class:`torch.device`, optional): the desired device of
  23606. returned tensor. Default: if None, uses the current device
  23607. for the default tensor type (see
  23608. :func:`torch.set_default_device`). :attr:`device` will be
  23609. the CPU for CPU tensor types and the current CUDA device for
  23610. CUDA tensor types.
  23611. pin_memory (bool, optional): If set, returned tensor would be allocated in
  23612. the pinned memory. Works only for CPU tensors. Default: ``False``.
  23613. requires_grad (bool, optional): If autograd should record operations on the
  23614. returned tensor. Default: ``False``.
  23615. check_invariants (bool, optional): If sparse tensor invariants are checked.
  23616. Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
  23617. initially False.
  23618. Example::
  23619. >>> ccol_indices = [0, 2, 4]
  23620. >>> row_indices = [0, 1, 0, 1]
  23621. >>> values = [1, 2, 3, 4]
  23622. >>> torch.sparse_csc_tensor(torch.tensor(ccol_indices, dtype=torch.int64),
  23623. ... torch.tensor(row_indices, dtype=torch.int64),
  23624. ... torch.tensor(values), dtype=torch.double)
  23625. tensor(ccol_indices=tensor([0, 2, 4]),
  23626. row_indices=tensor([0, 1, 0, 1]),
  23627. values=tensor([1., 2., 3., 4.]), size=(2, 2), nnz=4,
  23628. dtype=torch.float64, layout=torch.sparse_csc)
  23629. """
  23630. def sparse_csr_tensor(
  23631. crow_indices: Tensor | list,
  23632. col_indices: Tensor | list,
  23633. values: Tensor | list,
  23634. size: _size | None = None,
  23635. *,
  23636. dtype: _dtype | None = None,
  23637. device: DeviceLikeType | None = None,
  23638. requires_grad: _bool = False,
  23639. check_invariants: _bool | None = None,
  23640. ) -> Tensor:
  23641. r"""
  23642. sparse_csr_tensor(crow_indices, col_indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) -> Tensor
  23643. Constructs a :ref:`sparse tensor in CSR (Compressed Sparse Row) <sparse-csr-docs>` with specified
  23644. values at the given :attr:`crow_indices` and :attr:`col_indices`. Sparse matrix multiplication operations
  23645. in CSR format are typically faster than that for sparse tensors in COO format. Make you have a look
  23646. at :ref:`the note on the data type of the indices <sparse-csr-docs>`.
  23647. .. note::
  23648. If the ``device`` argument is not specified the device of the given
  23649. :attr:`values` and indices tensor(s) must match. If, however, the
  23650. argument is specified the input Tensors will be converted to the
  23651. given device and in turn determine the device of the constructed
  23652. sparse tensor.
  23653. Args:
  23654. crow_indices (array_like): (B+1)-dimensional array of size
  23655. ``(*batchsize, nrows + 1)``. The last element of each batch
  23656. is the number of non-zeros. This tensor encodes the index in
  23657. values and col_indices depending on where the given row
  23658. starts. Each successive number in the tensor subtracted by the
  23659. number before it denotes the number of elements in a given
  23660. row.
  23661. col_indices (array_like): Column coordinates of each element in
  23662. values. (B+1)-dimensional tensor with the same length
  23663. as values.
  23664. values (array_list): Initial values for the tensor. Can be a list,
  23665. tuple, NumPy ``ndarray``, scalar, and other types that
  23666. represents a (1+K)-dimensional tensor where ``K`` is the number
  23667. of dense dimensions.
  23668. size (list, tuple, :class:`torch.Size`, optional): Size of the
  23669. sparse tensor: ``(*batchsize, nrows, ncols, *densesize)``. If
  23670. not provided, the size will be inferred as the minimum size
  23671. big enough to hold all non-zero elements.
  23672. Keyword args:
  23673. dtype (:class:`torch.dtype`, optional): the desired data type of
  23674. returned tensor. Default: if None, infers data type from
  23675. :attr:`values`.
  23676. device (:class:`torch.device`, optional): the desired device of
  23677. returned tensor. Default: if None, uses the current device
  23678. for the default tensor type (see
  23679. :func:`torch.set_default_device`). :attr:`device` will be
  23680. the CPU for CPU tensor types and the current CUDA device for
  23681. CUDA tensor types.
  23682. pin_memory (bool, optional): If set, returned tensor would be allocated in
  23683. the pinned memory. Works only for CPU tensors. Default: ``False``.
  23684. requires_grad (bool, optional): If autograd should record operations on the
  23685. returned tensor. Default: ``False``.
  23686. check_invariants (bool, optional): If sparse tensor invariants are checked.
  23687. Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
  23688. initially False.
  23689. Example::
  23690. >>> crow_indices = [0, 2, 4]
  23691. >>> col_indices = [0, 1, 0, 1]
  23692. >>> values = [1, 2, 3, 4]
  23693. >>> torch.sparse_csr_tensor(torch.tensor(crow_indices, dtype=torch.int64),
  23694. ... torch.tensor(col_indices, dtype=torch.int64),
  23695. ... torch.tensor(values), dtype=torch.double)
  23696. tensor(crow_indices=tensor([0, 2, 4]),
  23697. col_indices=tensor([0, 1, 0, 1]),
  23698. values=tensor([1., 2., 3., 4.]), size=(2, 2), nnz=4,
  23699. dtype=torch.float64, layout=torch.sparse_csr)
  23700. """
  23701. def split_copy(
  23702. input: Tensor,
  23703. split_size: _int | SymInt,
  23704. dim: _int = 0,
  23705. *,
  23706. out: tuple[Tensor, ...] | list[Tensor] | None = None,
  23707. ) -> None:
  23708. r"""
  23709. Performs the same operation as :func:`torch.split`, but all output tensors
  23710. are freshly created instead of aliasing the input.
  23711. """
  23712. def split_with_sizes(
  23713. input: Tensor,
  23714. split_sizes: Sequence[_int | SymInt],
  23715. dim: _int = 0,
  23716. ) -> tuple[Tensor, ...]: ...
  23717. def split_with_sizes_copy(
  23718. input: Tensor,
  23719. split_sizes: Sequence[_int | SymInt],
  23720. dim: _int = 0,
  23721. *,
  23722. out: tuple[Tensor, ...] | list[Tensor] | None = None,
  23723. ) -> None:
  23724. r"""
  23725. Performs the same operation as :func:`torch.split_with_sizes`, but all output tensors
  23726. are freshly created instead of aliasing the input.
  23727. """
  23728. def spmm(input: Tensor, mat2: Tensor) -> Tensor: ...
  23729. def sqrt(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  23730. r"""
  23731. sqrt(input, *, out=None) -> Tensor
  23732. Returns a new tensor with the square-root of the elements of :attr:`input`.
  23733. .. math::
  23734. \text{out}_{i} = \sqrt{\text{input}_{i}}
  23735. Args:
  23736. input (Tensor): the input tensor.
  23737. Keyword args:
  23738. out (Tensor, optional): the output tensor.
  23739. Example::
  23740. >>> a = torch.randn(4)
  23741. >>> a
  23742. tensor([-2.0755, 1.0226, 0.0831, 0.4806])
  23743. >>> torch.sqrt(a)
  23744. tensor([ nan, 1.0112, 0.2883, 0.6933])
  23745. """
  23746. def sqrt_(input: Tensor) -> Tensor: ...
  23747. def square(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  23748. r"""
  23749. square(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  23750. Returns a new tensor with the square of the elements of :attr:`input`.
  23751. Args:
  23752. input (Tensor): the input tensor.
  23753. Keyword args:
  23754. out (Tensor, optional): the output tensor.
  23755. Example::
  23756. >>> a = torch.randn(4)
  23757. >>> a
  23758. tensor([-2.0755, 1.0226, 0.0831, 0.4806])
  23759. >>> torch.square(a)
  23760. tensor([ 4.3077, 1.0457, 0.0069, 0.2310])
  23761. """
  23762. def square_(input: Tensor) -> Tensor: ...
  23763. @overload
  23764. def squeeze(input: Tensor) -> Tensor:
  23765. r"""
  23766. squeeze(input: Tensor, dim: Optional[Union[int, List[int]]]) -> Tensor
  23767. Returns a tensor with all specified dimensions of :attr:`input` of size `1` removed.
  23768. For example, if `input` is of shape:
  23769. :math:`(A \times 1 \times B \times C \times 1 \times D)` then the `input.squeeze()`
  23770. will be of shape: :math:`(A \times B \times C \times D)`.
  23771. When :attr:`dim` is given, a squeeze operation is done only in the given
  23772. dimension(s). If `input` is of shape: :math:`(A \times 1 \times B)`,
  23773. ``squeeze(input, 0)`` leaves the tensor unchanged, but ``squeeze(input, 1)``
  23774. will squeeze the tensor to the shape :math:`(A \times B)`.
  23775. .. note:: The returned tensor shares the storage with the input tensor,
  23776. so changing the contents of one will change the contents of the other.
  23777. .. warning:: If the tensor has a batch dimension of size 1, then `squeeze(input)`
  23778. will also remove the batch dimension, which can lead to unexpected
  23779. errors. Consider specifying only the dims you wish to be squeezed.
  23780. Args:
  23781. input (Tensor): the input tensor.
  23782. dim (int or tuple of ints, optional): if given, the input will be squeezed
  23783. only in the specified dimensions.
  23784. .. versionchanged:: 2.0
  23785. :attr:`dim` now accepts tuples of dimensions.
  23786. Example::
  23787. >>> x = torch.zeros(2, 1, 2, 1, 2)
  23788. >>> x.size()
  23789. torch.Size([2, 1, 2, 1, 2])
  23790. >>> y = torch.squeeze(x)
  23791. >>> y.size()
  23792. torch.Size([2, 2, 2])
  23793. >>> y = torch.squeeze(x, 0)
  23794. >>> y.size()
  23795. torch.Size([2, 1, 2, 1, 2])
  23796. >>> y = torch.squeeze(x, 1)
  23797. >>> y.size()
  23798. torch.Size([2, 2, 1, 2])
  23799. >>> y = torch.squeeze(x, (1, 2, 3))
  23800. torch.Size([2, 2, 2])
  23801. """
  23802. @overload
  23803. def squeeze(input: Tensor, dim: _int) -> Tensor:
  23804. r"""
  23805. squeeze(input: Tensor, dim: Optional[Union[int, List[int]]]) -> Tensor
  23806. Returns a tensor with all specified dimensions of :attr:`input` of size `1` removed.
  23807. For example, if `input` is of shape:
  23808. :math:`(A \times 1 \times B \times C \times 1 \times D)` then the `input.squeeze()`
  23809. will be of shape: :math:`(A \times B \times C \times D)`.
  23810. When :attr:`dim` is given, a squeeze operation is done only in the given
  23811. dimension(s). If `input` is of shape: :math:`(A \times 1 \times B)`,
  23812. ``squeeze(input, 0)`` leaves the tensor unchanged, but ``squeeze(input, 1)``
  23813. will squeeze the tensor to the shape :math:`(A \times B)`.
  23814. .. note:: The returned tensor shares the storage with the input tensor,
  23815. so changing the contents of one will change the contents of the other.
  23816. .. warning:: If the tensor has a batch dimension of size 1, then `squeeze(input)`
  23817. will also remove the batch dimension, which can lead to unexpected
  23818. errors. Consider specifying only the dims you wish to be squeezed.
  23819. Args:
  23820. input (Tensor): the input tensor.
  23821. dim (int or tuple of ints, optional): if given, the input will be squeezed
  23822. only in the specified dimensions.
  23823. .. versionchanged:: 2.0
  23824. :attr:`dim` now accepts tuples of dimensions.
  23825. Example::
  23826. >>> x = torch.zeros(2, 1, 2, 1, 2)
  23827. >>> x.size()
  23828. torch.Size([2, 1, 2, 1, 2])
  23829. >>> y = torch.squeeze(x)
  23830. >>> y.size()
  23831. torch.Size([2, 2, 2])
  23832. >>> y = torch.squeeze(x, 0)
  23833. >>> y.size()
  23834. torch.Size([2, 1, 2, 1, 2])
  23835. >>> y = torch.squeeze(x, 1)
  23836. >>> y.size()
  23837. torch.Size([2, 2, 1, 2])
  23838. >>> y = torch.squeeze(x, (1, 2, 3))
  23839. torch.Size([2, 2, 2])
  23840. """
  23841. @overload
  23842. def squeeze(input: Tensor, dim: _size) -> Tensor:
  23843. r"""
  23844. squeeze(input: Tensor, dim: Optional[Union[int, List[int]]]) -> Tensor
  23845. Returns a tensor with all specified dimensions of :attr:`input` of size `1` removed.
  23846. For example, if `input` is of shape:
  23847. :math:`(A \times 1 \times B \times C \times 1 \times D)` then the `input.squeeze()`
  23848. will be of shape: :math:`(A \times B \times C \times D)`.
  23849. When :attr:`dim` is given, a squeeze operation is done only in the given
  23850. dimension(s). If `input` is of shape: :math:`(A \times 1 \times B)`,
  23851. ``squeeze(input, 0)`` leaves the tensor unchanged, but ``squeeze(input, 1)``
  23852. will squeeze the tensor to the shape :math:`(A \times B)`.
  23853. .. note:: The returned tensor shares the storage with the input tensor,
  23854. so changing the contents of one will change the contents of the other.
  23855. .. warning:: If the tensor has a batch dimension of size 1, then `squeeze(input)`
  23856. will also remove the batch dimension, which can lead to unexpected
  23857. errors. Consider specifying only the dims you wish to be squeezed.
  23858. Args:
  23859. input (Tensor): the input tensor.
  23860. dim (int or tuple of ints, optional): if given, the input will be squeezed
  23861. only in the specified dimensions.
  23862. .. versionchanged:: 2.0
  23863. :attr:`dim` now accepts tuples of dimensions.
  23864. Example::
  23865. >>> x = torch.zeros(2, 1, 2, 1, 2)
  23866. >>> x.size()
  23867. torch.Size([2, 1, 2, 1, 2])
  23868. >>> y = torch.squeeze(x)
  23869. >>> y.size()
  23870. torch.Size([2, 2, 2])
  23871. >>> y = torch.squeeze(x, 0)
  23872. >>> y.size()
  23873. torch.Size([2, 1, 2, 1, 2])
  23874. >>> y = torch.squeeze(x, 1)
  23875. >>> y.size()
  23876. torch.Size([2, 2, 1, 2])
  23877. >>> y = torch.squeeze(x, (1, 2, 3))
  23878. torch.Size([2, 2, 2])
  23879. """
  23880. @overload
  23881. def squeeze(input: Tensor, dim: str | EllipsisType | None) -> Tensor:
  23882. r"""
  23883. squeeze(input: Tensor, dim: Optional[Union[int, List[int]]]) -> Tensor
  23884. Returns a tensor with all specified dimensions of :attr:`input` of size `1` removed.
  23885. For example, if `input` is of shape:
  23886. :math:`(A \times 1 \times B \times C \times 1 \times D)` then the `input.squeeze()`
  23887. will be of shape: :math:`(A \times B \times C \times D)`.
  23888. When :attr:`dim` is given, a squeeze operation is done only in the given
  23889. dimension(s). If `input` is of shape: :math:`(A \times 1 \times B)`,
  23890. ``squeeze(input, 0)`` leaves the tensor unchanged, but ``squeeze(input, 1)``
  23891. will squeeze the tensor to the shape :math:`(A \times B)`.
  23892. .. note:: The returned tensor shares the storage with the input tensor,
  23893. so changing the contents of one will change the contents of the other.
  23894. .. warning:: If the tensor has a batch dimension of size 1, then `squeeze(input)`
  23895. will also remove the batch dimension, which can lead to unexpected
  23896. errors. Consider specifying only the dims you wish to be squeezed.
  23897. Args:
  23898. input (Tensor): the input tensor.
  23899. dim (int or tuple of ints, optional): if given, the input will be squeezed
  23900. only in the specified dimensions.
  23901. .. versionchanged:: 2.0
  23902. :attr:`dim` now accepts tuples of dimensions.
  23903. Example::
  23904. >>> x = torch.zeros(2, 1, 2, 1, 2)
  23905. >>> x.size()
  23906. torch.Size([2, 1, 2, 1, 2])
  23907. >>> y = torch.squeeze(x)
  23908. >>> y.size()
  23909. torch.Size([2, 2, 2])
  23910. >>> y = torch.squeeze(x, 0)
  23911. >>> y.size()
  23912. torch.Size([2, 1, 2, 1, 2])
  23913. >>> y = torch.squeeze(x, 1)
  23914. >>> y.size()
  23915. torch.Size([2, 2, 1, 2])
  23916. >>> y = torch.squeeze(x, (1, 2, 3))
  23917. torch.Size([2, 2, 2])
  23918. """
  23919. @overload
  23920. def squeeze_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  23921. r"""
  23922. Performs the same operation as :func:`torch.squeeze`, but all output tensors
  23923. are freshly created instead of aliasing the input.
  23924. """
  23925. @overload
  23926. def squeeze_copy(
  23927. input: Tensor,
  23928. dim: _int,
  23929. *,
  23930. out: Tensor | None = None,
  23931. ) -> Tensor:
  23932. r"""
  23933. Performs the same operation as :func:`torch.squeeze`, but all output tensors
  23934. are freshly created instead of aliasing the input.
  23935. """
  23936. @overload
  23937. def squeeze_copy(
  23938. input: Tensor,
  23939. dim: _size,
  23940. *,
  23941. out: Tensor | None = None,
  23942. ) -> Tensor:
  23943. r"""
  23944. Performs the same operation as :func:`torch.squeeze`, but all output tensors
  23945. are freshly created instead of aliasing the input.
  23946. """
  23947. @overload
  23948. def sspaddmm(
  23949. beta: Number | _complex,
  23950. self: Tensor,
  23951. alpha: Number | _complex,
  23952. mat1: Tensor,
  23953. mat2: Tensor,
  23954. ) -> Tensor:
  23955. r"""
  23956. sspaddmm(input, mat1, mat2, *, beta=1, alpha=1, out=None) -> Tensor
  23957. Matrix multiplies a sparse tensor :attr:`mat1` with a dense tensor
  23958. :attr:`mat2`, then adds the sparse tensor :attr:`input` to the result.
  23959. Note: This function is equivalent to :func:`torch.addmm`, except
  23960. :attr:`input` and :attr:`mat1` are sparse.
  23961. Args:
  23962. input (Tensor): a sparse matrix to be added
  23963. mat1 (Tensor): a sparse matrix to be matrix multiplied
  23964. mat2 (Tensor): a dense matrix to be matrix multiplied
  23965. Keyword args:
  23966. beta (Number, optional): multiplier for :attr:`mat` (:math:`\beta`)
  23967. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  23968. out (Tensor, optional): the output tensor.
  23969. """
  23970. @overload
  23971. def sspaddmm(
  23972. input: Tensor,
  23973. mat1: Tensor,
  23974. mat2: Tensor,
  23975. *,
  23976. beta: Number | _complex = 1,
  23977. alpha: Number | _complex = 1,
  23978. out: Tensor | None = None,
  23979. ) -> Tensor:
  23980. r"""
  23981. sspaddmm(input, mat1, mat2, *, beta=1, alpha=1, out=None) -> Tensor
  23982. Matrix multiplies a sparse tensor :attr:`mat1` with a dense tensor
  23983. :attr:`mat2`, then adds the sparse tensor :attr:`input` to the result.
  23984. Note: This function is equivalent to :func:`torch.addmm`, except
  23985. :attr:`input` and :attr:`mat1` are sparse.
  23986. Args:
  23987. input (Tensor): a sparse matrix to be added
  23988. mat1 (Tensor): a sparse matrix to be matrix multiplied
  23989. mat2 (Tensor): a dense matrix to be matrix multiplied
  23990. Keyword args:
  23991. beta (Number, optional): multiplier for :attr:`mat` (:math:`\beta`)
  23992. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  23993. out (Tensor, optional): the output tensor.
  23994. """
  23995. @overload
  23996. def sspaddmm(
  23997. beta: Number | _complex,
  23998. self: Tensor,
  23999. mat1: Tensor,
  24000. mat2: Tensor,
  24001. ) -> Tensor:
  24002. r"""
  24003. sspaddmm(input, mat1, mat2, *, beta=1, alpha=1, out=None) -> Tensor
  24004. Matrix multiplies a sparse tensor :attr:`mat1` with a dense tensor
  24005. :attr:`mat2`, then adds the sparse tensor :attr:`input` to the result.
  24006. Note: This function is equivalent to :func:`torch.addmm`, except
  24007. :attr:`input` and :attr:`mat1` are sparse.
  24008. Args:
  24009. input (Tensor): a sparse matrix to be added
  24010. mat1 (Tensor): a sparse matrix to be matrix multiplied
  24011. mat2 (Tensor): a dense matrix to be matrix multiplied
  24012. Keyword args:
  24013. beta (Number, optional): multiplier for :attr:`mat` (:math:`\beta`)
  24014. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  24015. out (Tensor, optional): the output tensor.
  24016. """
  24017. def stack(
  24018. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  24019. dim: _int = 0,
  24020. *,
  24021. out: Tensor | None = None,
  24022. ) -> Tensor:
  24023. r"""
  24024. stack(tensors, dim=0, *, out=None) -> Tensor
  24025. Concatenates a sequence of tensors along a new dimension.
  24026. All tensors need to be of the same size.
  24027. .. seealso::
  24028. :func:`torch.cat` concatenates the given sequence along an existing dimension.
  24029. Arguments:
  24030. tensors (sequence of Tensors): sequence of tensors to concatenate
  24031. dim (int, optional): dimension to insert. Has to be between 0 and the number
  24032. of dimensions of concatenated tensors (inclusive). Default: 0
  24033. Keyword args:
  24034. out (Tensor, optional): the output tensor.
  24035. Example::
  24036. >>> x = torch.randn(2, 3)
  24037. >>> x
  24038. tensor([[ 0.3367, 0.1288, 0.2345],
  24039. [ 0.2303, -1.1229, -0.1863]])
  24040. >>> torch.stack((x, x)) # same as torch.stack((x, x), dim=0)
  24041. tensor([[[ 0.3367, 0.1288, 0.2345],
  24042. [ 0.2303, -1.1229, -0.1863]],
  24043. [[ 0.3367, 0.1288, 0.2345],
  24044. [ 0.2303, -1.1229, -0.1863]]])
  24045. >>> torch.stack((x, x)).size()
  24046. torch.Size([2, 2, 3])
  24047. >>> torch.stack((x, x), dim=1)
  24048. tensor([[[ 0.3367, 0.1288, 0.2345],
  24049. [ 0.3367, 0.1288, 0.2345]],
  24050. [[ 0.2303, -1.1229, -0.1863],
  24051. [ 0.2303, -1.1229, -0.1863]]])
  24052. >>> torch.stack((x, x), dim=2)
  24053. tensor([[[ 0.3367, 0.3367],
  24054. [ 0.1288, 0.1288],
  24055. [ 0.2345, 0.2345]],
  24056. [[ 0.2303, 0.2303],
  24057. [-1.1229, -1.1229],
  24058. [-0.1863, -0.1863]]])
  24059. >>> torch.stack((x, x), dim=-1)
  24060. tensor([[[ 0.3367, 0.3367],
  24061. [ 0.1288, 0.1288],
  24062. [ 0.2345, 0.2345]],
  24063. [[ 0.2303, 0.2303],
  24064. [-1.1229, -1.1229],
  24065. [-0.1863, -0.1863]]])
  24066. """
  24067. @overload
  24068. def std(
  24069. input: Tensor,
  24070. dim: _int | _size | None,
  24071. unbiased: _bool = True,
  24072. keepdim: _bool = False,
  24073. *,
  24074. out: Tensor | None = None,
  24075. ) -> Tensor:
  24076. r"""
  24077. std(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  24078. Calculates the standard deviation over the dimensions specified by :attr:`dim`.
  24079. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  24080. reduce over all dimensions.
  24081. The standard deviation (:math:`\sigma`) is calculated as
  24082. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24083. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24084. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24085. the :attr:`correction`.
  24086. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24087. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24088. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24089. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24090. Args:
  24091. input (Tensor): the input tensor.
  24092. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24093. If ``None``, all dimensions are reduced.
  24094. Keyword args:
  24095. correction (int): difference between the sample size and sample degrees of freedom.
  24096. Defaults to `Bessel's correction`_, ``correction=1``.
  24097. .. versionchanged:: 2.0
  24098. Previously this argument was called ``unbiased`` and was a boolean
  24099. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24100. ``correction=0``.
  24101. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24102. out (Tensor, optional): the output tensor.
  24103. Example:
  24104. >>> a = torch.tensor(
  24105. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24106. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24107. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24108. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24109. ... ) # fmt: skip
  24110. >>> torch.std(a, dim=1, keepdim=True)
  24111. tensor([[1.0311],
  24112. [0.7477],
  24113. [1.2204],
  24114. [0.9087]])
  24115. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24116. """
  24117. @overload
  24118. def std(
  24119. input: Tensor,
  24120. dim: _int | _size | None = None,
  24121. *,
  24122. correction: Number | _complex | None = None,
  24123. keepdim: _bool = False,
  24124. out: Tensor | None = None,
  24125. ) -> Tensor:
  24126. r"""
  24127. std(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  24128. Calculates the standard deviation over the dimensions specified by :attr:`dim`.
  24129. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  24130. reduce over all dimensions.
  24131. The standard deviation (:math:`\sigma`) is calculated as
  24132. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24133. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24134. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24135. the :attr:`correction`.
  24136. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24137. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24138. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24139. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24140. Args:
  24141. input (Tensor): the input tensor.
  24142. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24143. If ``None``, all dimensions are reduced.
  24144. Keyword args:
  24145. correction (int): difference between the sample size and sample degrees of freedom.
  24146. Defaults to `Bessel's correction`_, ``correction=1``.
  24147. .. versionchanged:: 2.0
  24148. Previously this argument was called ``unbiased`` and was a boolean
  24149. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24150. ``correction=0``.
  24151. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24152. out (Tensor, optional): the output tensor.
  24153. Example:
  24154. >>> a = torch.tensor(
  24155. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24156. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24157. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24158. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24159. ... ) # fmt: skip
  24160. >>> torch.std(a, dim=1, keepdim=True)
  24161. tensor([[1.0311],
  24162. [0.7477],
  24163. [1.2204],
  24164. [0.9087]])
  24165. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24166. """
  24167. @overload
  24168. def std(input: Tensor, unbiased: _bool = True) -> Tensor:
  24169. r"""
  24170. std(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  24171. Calculates the standard deviation over the dimensions specified by :attr:`dim`.
  24172. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  24173. reduce over all dimensions.
  24174. The standard deviation (:math:`\sigma`) is calculated as
  24175. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24176. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24177. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24178. the :attr:`correction`.
  24179. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24180. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24181. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24182. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24183. Args:
  24184. input (Tensor): the input tensor.
  24185. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24186. If ``None``, all dimensions are reduced.
  24187. Keyword args:
  24188. correction (int): difference between the sample size and sample degrees of freedom.
  24189. Defaults to `Bessel's correction`_, ``correction=1``.
  24190. .. versionchanged:: 2.0
  24191. Previously this argument was called ``unbiased`` and was a boolean
  24192. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24193. ``correction=0``.
  24194. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24195. out (Tensor, optional): the output tensor.
  24196. Example:
  24197. >>> a = torch.tensor(
  24198. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24199. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24200. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24201. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24202. ... ) # fmt: skip
  24203. >>> torch.std(a, dim=1, keepdim=True)
  24204. tensor([[1.0311],
  24205. [0.7477],
  24206. [1.2204],
  24207. [0.9087]])
  24208. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24209. """
  24210. @overload
  24211. def std(
  24212. input: Tensor,
  24213. dim: Sequence[str | EllipsisType | None],
  24214. *,
  24215. correction: Number | _complex | None = None,
  24216. keepdim: _bool = False,
  24217. out: Tensor | None = None,
  24218. ) -> Tensor:
  24219. r"""
  24220. std(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  24221. Calculates the standard deviation over the dimensions specified by :attr:`dim`.
  24222. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  24223. reduce over all dimensions.
  24224. The standard deviation (:math:`\sigma`) is calculated as
  24225. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24226. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24227. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24228. the :attr:`correction`.
  24229. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24230. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24231. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24232. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24233. Args:
  24234. input (Tensor): the input tensor.
  24235. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24236. If ``None``, all dimensions are reduced.
  24237. Keyword args:
  24238. correction (int): difference between the sample size and sample degrees of freedom.
  24239. Defaults to `Bessel's correction`_, ``correction=1``.
  24240. .. versionchanged:: 2.0
  24241. Previously this argument was called ``unbiased`` and was a boolean
  24242. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24243. ``correction=0``.
  24244. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24245. out (Tensor, optional): the output tensor.
  24246. Example:
  24247. >>> a = torch.tensor(
  24248. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24249. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24250. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24251. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24252. ... ) # fmt: skip
  24253. >>> torch.std(a, dim=1, keepdim=True)
  24254. tensor([[1.0311],
  24255. [0.7477],
  24256. [1.2204],
  24257. [0.9087]])
  24258. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24259. """
  24260. @overload
  24261. def std(
  24262. input: Tensor,
  24263. dim: Sequence[str | EllipsisType | None],
  24264. unbiased: _bool = True,
  24265. keepdim: _bool = False,
  24266. *,
  24267. out: Tensor | None = None,
  24268. ) -> Tensor:
  24269. r"""
  24270. std(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  24271. Calculates the standard deviation over the dimensions specified by :attr:`dim`.
  24272. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  24273. reduce over all dimensions.
  24274. The standard deviation (:math:`\sigma`) is calculated as
  24275. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24276. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24277. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24278. the :attr:`correction`.
  24279. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24280. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24281. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24282. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24283. Args:
  24284. input (Tensor): the input tensor.
  24285. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24286. If ``None``, all dimensions are reduced.
  24287. Keyword args:
  24288. correction (int): difference between the sample size and sample degrees of freedom.
  24289. Defaults to `Bessel's correction`_, ``correction=1``.
  24290. .. versionchanged:: 2.0
  24291. Previously this argument was called ``unbiased`` and was a boolean
  24292. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24293. ``correction=0``.
  24294. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24295. out (Tensor, optional): the output tensor.
  24296. Example:
  24297. >>> a = torch.tensor(
  24298. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24299. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24300. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24301. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24302. ... ) # fmt: skip
  24303. >>> torch.std(a, dim=1, keepdim=True)
  24304. tensor([[1.0311],
  24305. [0.7477],
  24306. [1.2204],
  24307. [0.9087]])
  24308. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24309. """
  24310. @overload
  24311. def std_mean(
  24312. input: Tensor,
  24313. dim: _int | _size | None,
  24314. unbiased: _bool = True,
  24315. keepdim: _bool = False,
  24316. ) -> tuple[Tensor, Tensor]:
  24317. r"""
  24318. std_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  24319. Calculates the standard deviation and mean over the dimensions specified by
  24320. :attr:`dim`. :attr:`dim` can be a single dimension, list of dimensions, or
  24321. ``None`` to reduce over all dimensions.
  24322. The standard deviation (:math:`\sigma`) is calculated as
  24323. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24324. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24325. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24326. the :attr:`correction`.
  24327. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24328. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24329. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24330. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24331. Args:
  24332. input (Tensor): the input tensor.
  24333. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24334. If ``None``, all dimensions are reduced.
  24335. Keyword args:
  24336. correction (int): difference between the sample size and sample degrees of freedom.
  24337. Defaults to `Bessel's correction`_, ``correction=1``.
  24338. .. versionchanged:: 2.0
  24339. Previously this argument was called ``unbiased`` and was a boolean
  24340. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24341. ``correction=0``.
  24342. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24343. out (Tensor, optional): the output tensor.
  24344. Returns:
  24345. A tuple (std, mean) containing the standard deviation and mean.
  24346. Example:
  24347. >>> a = torch.tensor(
  24348. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24349. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24350. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24351. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24352. ... ) # fmt: skip
  24353. >>> torch.std_mean(a, dim=0, keepdim=True)
  24354. (tensor([[1.2620, 1.0028, 1.0957, 0.6038]]),
  24355. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  24356. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24357. """
  24358. @overload
  24359. def std_mean(
  24360. input: Tensor,
  24361. dim: _int | _size | None = None,
  24362. *,
  24363. correction: Number | _complex | None = None,
  24364. keepdim: _bool = False,
  24365. ) -> tuple[Tensor, Tensor]:
  24366. r"""
  24367. std_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  24368. Calculates the standard deviation and mean over the dimensions specified by
  24369. :attr:`dim`. :attr:`dim` can be a single dimension, list of dimensions, or
  24370. ``None`` to reduce over all dimensions.
  24371. The standard deviation (:math:`\sigma`) is calculated as
  24372. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24373. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24374. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24375. the :attr:`correction`.
  24376. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24377. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24378. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24379. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24380. Args:
  24381. input (Tensor): the input tensor.
  24382. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24383. If ``None``, all dimensions are reduced.
  24384. Keyword args:
  24385. correction (int): difference between the sample size and sample degrees of freedom.
  24386. Defaults to `Bessel's correction`_, ``correction=1``.
  24387. .. versionchanged:: 2.0
  24388. Previously this argument was called ``unbiased`` and was a boolean
  24389. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24390. ``correction=0``.
  24391. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24392. out (Tensor, optional): the output tensor.
  24393. Returns:
  24394. A tuple (std, mean) containing the standard deviation and mean.
  24395. Example:
  24396. >>> a = torch.tensor(
  24397. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24398. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24399. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24400. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24401. ... ) # fmt: skip
  24402. >>> torch.std_mean(a, dim=0, keepdim=True)
  24403. (tensor([[1.2620, 1.0028, 1.0957, 0.6038]]),
  24404. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  24405. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24406. """
  24407. @overload
  24408. def std_mean(
  24409. input: Tensor,
  24410. unbiased: _bool = True,
  24411. ) -> tuple[Tensor, Tensor]:
  24412. r"""
  24413. std_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  24414. Calculates the standard deviation and mean over the dimensions specified by
  24415. :attr:`dim`. :attr:`dim` can be a single dimension, list of dimensions, or
  24416. ``None`` to reduce over all dimensions.
  24417. The standard deviation (:math:`\sigma`) is calculated as
  24418. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24419. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24420. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24421. the :attr:`correction`.
  24422. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24423. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24424. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24425. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24426. Args:
  24427. input (Tensor): the input tensor.
  24428. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24429. If ``None``, all dimensions are reduced.
  24430. Keyword args:
  24431. correction (int): difference between the sample size and sample degrees of freedom.
  24432. Defaults to `Bessel's correction`_, ``correction=1``.
  24433. .. versionchanged:: 2.0
  24434. Previously this argument was called ``unbiased`` and was a boolean
  24435. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24436. ``correction=0``.
  24437. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24438. out (Tensor, optional): the output tensor.
  24439. Returns:
  24440. A tuple (std, mean) containing the standard deviation and mean.
  24441. Example:
  24442. >>> a = torch.tensor(
  24443. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24444. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24445. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24446. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24447. ... ) # fmt: skip
  24448. >>> torch.std_mean(a, dim=0, keepdim=True)
  24449. (tensor([[1.2620, 1.0028, 1.0957, 0.6038]]),
  24450. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  24451. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24452. """
  24453. @overload
  24454. def std_mean(
  24455. input: Tensor,
  24456. dim: Sequence[str | EllipsisType | None],
  24457. *,
  24458. correction: Number | _complex | None = None,
  24459. keepdim: _bool = False,
  24460. ) -> tuple[Tensor, Tensor]:
  24461. r"""
  24462. std_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  24463. Calculates the standard deviation and mean over the dimensions specified by
  24464. :attr:`dim`. :attr:`dim` can be a single dimension, list of dimensions, or
  24465. ``None`` to reduce over all dimensions.
  24466. The standard deviation (:math:`\sigma`) is calculated as
  24467. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24468. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24469. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24470. the :attr:`correction`.
  24471. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24472. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24473. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24474. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24475. Args:
  24476. input (Tensor): the input tensor.
  24477. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24478. If ``None``, all dimensions are reduced.
  24479. Keyword args:
  24480. correction (int): difference between the sample size and sample degrees of freedom.
  24481. Defaults to `Bessel's correction`_, ``correction=1``.
  24482. .. versionchanged:: 2.0
  24483. Previously this argument was called ``unbiased`` and was a boolean
  24484. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24485. ``correction=0``.
  24486. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24487. out (Tensor, optional): the output tensor.
  24488. Returns:
  24489. A tuple (std, mean) containing the standard deviation and mean.
  24490. Example:
  24491. >>> a = torch.tensor(
  24492. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24493. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24494. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24495. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24496. ... ) # fmt: skip
  24497. >>> torch.std_mean(a, dim=0, keepdim=True)
  24498. (tensor([[1.2620, 1.0028, 1.0957, 0.6038]]),
  24499. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  24500. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24501. """
  24502. @overload
  24503. def std_mean(
  24504. input: Tensor,
  24505. dim: Sequence[str | EllipsisType | None],
  24506. unbiased: _bool = True,
  24507. keepdim: _bool = False,
  24508. ) -> tuple[Tensor, Tensor]:
  24509. r"""
  24510. std_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  24511. Calculates the standard deviation and mean over the dimensions specified by
  24512. :attr:`dim`. :attr:`dim` can be a single dimension, list of dimensions, or
  24513. ``None`` to reduce over all dimensions.
  24514. The standard deviation (:math:`\sigma`) is calculated as
  24515. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24516. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24517. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24518. the :attr:`correction`.
  24519. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24520. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24521. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24522. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24523. Args:
  24524. input (Tensor): the input tensor.
  24525. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24526. If ``None``, all dimensions are reduced.
  24527. Keyword args:
  24528. correction (int): difference between the sample size and sample degrees of freedom.
  24529. Defaults to `Bessel's correction`_, ``correction=1``.
  24530. .. versionchanged:: 2.0
  24531. Previously this argument was called ``unbiased`` and was a boolean
  24532. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24533. ``correction=0``.
  24534. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24535. out (Tensor, optional): the output tensor.
  24536. Returns:
  24537. A tuple (std, mean) containing the standard deviation and mean.
  24538. Example:
  24539. >>> a = torch.tensor(
  24540. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24541. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24542. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24543. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24544. ... ) # fmt: skip
  24545. >>> torch.std_mean(a, dim=0, keepdim=True)
  24546. (tensor([[1.2620, 1.0028, 1.0957, 0.6038]]),
  24547. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  24548. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24549. """
  24550. @overload
  24551. def sub(
  24552. input: Tensor | Number | _complex,
  24553. other: Tensor | Number | _complex,
  24554. *,
  24555. alpha: Number | _complex | None = 1,
  24556. out: Tensor | None = None,
  24557. ) -> Tensor:
  24558. r"""
  24559. sub(input, other, *, alpha=1, out=None) -> Tensor
  24560. Subtracts :attr:`other`, scaled by :attr:`alpha`, from :attr:`input`.
  24561. .. math::
  24562. \text{{out}}_i = \text{{input}}_i - \text{{alpha}} \times \text{{other}}_i
  24563. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  24564. :ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
  24565. Args:
  24566. input (Tensor): the input tensor.
  24567. other (Tensor or Number): the tensor or number to subtract from :attr:`input`.
  24568. Keyword args:
  24569. alpha (Number): the multiplier for :attr:`other`.
  24570. out (Tensor, optional): the output tensor.
  24571. Example::
  24572. >>> a = torch.tensor((1, 2))
  24573. >>> b = torch.tensor((0, 1))
  24574. >>> torch.sub(a, b, alpha=2)
  24575. tensor([1, 0])
  24576. """
  24577. @overload
  24578. def sub(self: Tensor, alpha: Number | _complex, other: Tensor) -> Tensor:
  24579. r"""
  24580. sub(input, other, *, alpha=1, out=None) -> Tensor
  24581. Subtracts :attr:`other`, scaled by :attr:`alpha`, from :attr:`input`.
  24582. .. math::
  24583. \text{{out}}_i = \text{{input}}_i - \text{{alpha}} \times \text{{other}}_i
  24584. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  24585. :ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
  24586. Args:
  24587. input (Tensor): the input tensor.
  24588. other (Tensor or Number): the tensor or number to subtract from :attr:`input`.
  24589. Keyword args:
  24590. alpha (Number): the multiplier for :attr:`other`.
  24591. out (Tensor, optional): the output tensor.
  24592. Example::
  24593. >>> a = torch.tensor((1, 2))
  24594. >>> b = torch.tensor((0, 1))
  24595. >>> torch.sub(a, b, alpha=2)
  24596. tensor([1, 0])
  24597. """
  24598. @overload
  24599. def sub(
  24600. self: Tensor,
  24601. alpha: Number | _complex,
  24602. other: Tensor,
  24603. *,
  24604. out: Tensor,
  24605. ) -> Tensor:
  24606. r"""
  24607. sub(input, other, *, alpha=1, out=None) -> Tensor
  24608. Subtracts :attr:`other`, scaled by :attr:`alpha`, from :attr:`input`.
  24609. .. math::
  24610. \text{{out}}_i = \text{{input}}_i - \text{{alpha}} \times \text{{other}}_i
  24611. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  24612. :ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
  24613. Args:
  24614. input (Tensor): the input tensor.
  24615. other (Tensor or Number): the tensor or number to subtract from :attr:`input`.
  24616. Keyword args:
  24617. alpha (Number): the multiplier for :attr:`other`.
  24618. out (Tensor, optional): the output tensor.
  24619. Example::
  24620. >>> a = torch.tensor((1, 2))
  24621. >>> b = torch.tensor((0, 1))
  24622. >>> torch.sub(a, b, alpha=2)
  24623. tensor([1, 0])
  24624. """
  24625. @overload
  24626. def subtract(
  24627. input: Tensor,
  24628. other: Tensor,
  24629. *,
  24630. alpha: Number | _complex = 1,
  24631. out: Tensor | None = None,
  24632. ) -> Tensor:
  24633. r"""
  24634. subtract(input, other, *, alpha=1, out=None) -> Tensor
  24635. Alias for :func:`torch.sub`.
  24636. """
  24637. @overload
  24638. def subtract(
  24639. input: Tensor,
  24640. other: Number | _complex,
  24641. alpha: Number | _complex = 1,
  24642. ) -> Tensor:
  24643. r"""
  24644. subtract(input, other, *, alpha=1, out=None) -> Tensor
  24645. Alias for :func:`torch.sub`.
  24646. """
  24647. @overload
  24648. def sum(input: Tensor, *, dtype: _dtype | None = None) -> Tensor:
  24649. r"""
  24650. sum(input, *, dtype=None) -> Tensor
  24651. Returns the sum of all elements in the :attr:`input` tensor.
  24652. Args:
  24653. input (Tensor): the input tensor.
  24654. Keyword args:
  24655. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  24656. If specified, the input tensor is casted to :attr:`dtype` before the operation
  24657. is performed. This is useful for preventing data type overflows. Default: None.
  24658. .. note:: Use the `dtype` argument if you need the result in a specific tensor type.
  24659. Otherwise, the result type may be automatically promoted (e.g., from `torch.int32` to `torch.int64`).
  24660. Example::
  24661. >>> a = torch.randn(1, 3)
  24662. >>> a
  24663. tensor([[ 0.1133, -0.9567, 0.2958]])
  24664. >>> torch.sum(a)
  24665. tensor(-0.5475)
  24666. .. function:: sum(input, dim, keepdim=False, *, dtype=None) -> Tensor
  24667. :noindex:
  24668. Returns the sum of each row of the :attr:`input` tensor in the given
  24669. dimension :attr:`dim`. If :attr:`dim` is a list of dimensions,
  24670. reduce over all of them.
  24671. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24672. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24673. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24674. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24675. Args:
  24676. input (Tensor): the input tensor.
  24677. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24678. If ``None``, all dimensions are reduced.
  24679. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24680. Keyword args:
  24681. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  24682. If specified, the input tensor is casted to :attr:`dtype` before the operation
  24683. is performed. This is useful for preventing data type overflows. Default: None.
  24684. Example::
  24685. >>> a = torch.randn(4, 4)
  24686. >>> a
  24687. tensor([[ 0.0569, -0.2475, 0.0737, -0.3429],
  24688. [-0.2993, 0.9138, 0.9337, -1.6864],
  24689. [ 0.1132, 0.7892, -0.1003, 0.5688],
  24690. [ 0.3637, -0.9906, -0.4752, -1.5197]])
  24691. >>> torch.sum(a, 1)
  24692. tensor([-0.4598, -0.1381, 1.3708, -2.6217])
  24693. >>> b = torch.arange(4 * 5 * 6).view(4, 5, 6)
  24694. >>> torch.sum(b, (2, 1))
  24695. tensor([ 435., 1335., 2235., 3135.])
  24696. """
  24697. @overload
  24698. def sum(
  24699. input: Tensor,
  24700. dim: _int | _size | None,
  24701. keepdim: _bool = False,
  24702. *,
  24703. dtype: _dtype | None = None,
  24704. out: Tensor | None = None,
  24705. ) -> Tensor:
  24706. r"""
  24707. sum(input, *, dtype=None) -> Tensor
  24708. Returns the sum of all elements in the :attr:`input` tensor.
  24709. Args:
  24710. input (Tensor): the input tensor.
  24711. Keyword args:
  24712. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  24713. If specified, the input tensor is casted to :attr:`dtype` before the operation
  24714. is performed. This is useful for preventing data type overflows. Default: None.
  24715. .. note:: Use the `dtype` argument if you need the result in a specific tensor type.
  24716. Otherwise, the result type may be automatically promoted (e.g., from `torch.int32` to `torch.int64`).
  24717. Example::
  24718. >>> a = torch.randn(1, 3)
  24719. >>> a
  24720. tensor([[ 0.1133, -0.9567, 0.2958]])
  24721. >>> torch.sum(a)
  24722. tensor(-0.5475)
  24723. .. function:: sum(input, dim, keepdim=False, *, dtype=None) -> Tensor
  24724. :noindex:
  24725. Returns the sum of each row of the :attr:`input` tensor in the given
  24726. dimension :attr:`dim`. If :attr:`dim` is a list of dimensions,
  24727. reduce over all of them.
  24728. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24729. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24730. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24731. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24732. Args:
  24733. input (Tensor): the input tensor.
  24734. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24735. If ``None``, all dimensions are reduced.
  24736. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24737. Keyword args:
  24738. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  24739. If specified, the input tensor is casted to :attr:`dtype` before the operation
  24740. is performed. This is useful for preventing data type overflows. Default: None.
  24741. Example::
  24742. >>> a = torch.randn(4, 4)
  24743. >>> a
  24744. tensor([[ 0.0569, -0.2475, 0.0737, -0.3429],
  24745. [-0.2993, 0.9138, 0.9337, -1.6864],
  24746. [ 0.1132, 0.7892, -0.1003, 0.5688],
  24747. [ 0.3637, -0.9906, -0.4752, -1.5197]])
  24748. >>> torch.sum(a, 1)
  24749. tensor([-0.4598, -0.1381, 1.3708, -2.6217])
  24750. >>> b = torch.arange(4 * 5 * 6).view(4, 5, 6)
  24751. >>> torch.sum(b, (2, 1))
  24752. tensor([ 435., 1335., 2235., 3135.])
  24753. """
  24754. @overload
  24755. def sum(
  24756. input: Tensor,
  24757. dim: Sequence[str | EllipsisType | None],
  24758. keepdim: _bool = False,
  24759. *,
  24760. dtype: _dtype | None = None,
  24761. out: Tensor | None = None,
  24762. ) -> Tensor:
  24763. r"""
  24764. sum(input, *, dtype=None) -> Tensor
  24765. Returns the sum of all elements in the :attr:`input` tensor.
  24766. Args:
  24767. input (Tensor): the input tensor.
  24768. Keyword args:
  24769. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  24770. If specified, the input tensor is casted to :attr:`dtype` before the operation
  24771. is performed. This is useful for preventing data type overflows. Default: None.
  24772. .. note:: Use the `dtype` argument if you need the result in a specific tensor type.
  24773. Otherwise, the result type may be automatically promoted (e.g., from `torch.int32` to `torch.int64`).
  24774. Example::
  24775. >>> a = torch.randn(1, 3)
  24776. >>> a
  24777. tensor([[ 0.1133, -0.9567, 0.2958]])
  24778. >>> torch.sum(a)
  24779. tensor(-0.5475)
  24780. .. function:: sum(input, dim, keepdim=False, *, dtype=None) -> Tensor
  24781. :noindex:
  24782. Returns the sum of each row of the :attr:`input` tensor in the given
  24783. dimension :attr:`dim`. If :attr:`dim` is a list of dimensions,
  24784. reduce over all of them.
  24785. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24786. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24787. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24788. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24789. Args:
  24790. input (Tensor): the input tensor.
  24791. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24792. If ``None``, all dimensions are reduced.
  24793. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24794. Keyword args:
  24795. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  24796. If specified, the input tensor is casted to :attr:`dtype` before the operation
  24797. is performed. This is useful for preventing data type overflows. Default: None.
  24798. Example::
  24799. >>> a = torch.randn(4, 4)
  24800. >>> a
  24801. tensor([[ 0.0569, -0.2475, 0.0737, -0.3429],
  24802. [-0.2993, 0.9138, 0.9337, -1.6864],
  24803. [ 0.1132, 0.7892, -0.1003, 0.5688],
  24804. [ 0.3637, -0.9906, -0.4752, -1.5197]])
  24805. >>> torch.sum(a, 1)
  24806. tensor([-0.4598, -0.1381, 1.3708, -2.6217])
  24807. >>> b = torch.arange(4 * 5 * 6).view(4, 5, 6)
  24808. >>> torch.sum(b, (2, 1))
  24809. tensor([ 435., 1335., 2235., 3135.])
  24810. """
  24811. def svd(
  24812. input: Tensor,
  24813. some: _bool = True,
  24814. compute_uv: _bool = True,
  24815. *,
  24816. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  24817. ) -> torch.return_types.svd:
  24818. r"""
  24819. svd(input, some=True, compute_uv=True, *, out=None) -> (Tensor, Tensor, Tensor)
  24820. Computes the singular value decomposition of either a matrix or batch of
  24821. matrices :attr:`input`. The singular value decomposition is represented as a
  24822. namedtuple `(U, S, V)`, such that :attr:`input` :math:`= U \text{diag}(S) V^{\text{H}}`.
  24823. where :math:`V^{\text{H}}` is the transpose of `V` for real inputs,
  24824. and the conjugate transpose of `V` for complex inputs.
  24825. If :attr:`input` is a batch of matrices, then `U`, `S`, and `V` are also
  24826. batched with the same batch dimensions as :attr:`input`.
  24827. If :attr:`some` is `True` (default), the method returns the reduced singular
  24828. value decomposition. In this case, if the last two dimensions of :attr:`input` are
  24829. `m` and `n`, then the returned `U` and `V` matrices will contain only
  24830. `min(n, m)` orthonormal columns.
  24831. If :attr:`compute_uv` is `False`, the returned `U` and `V` will be
  24832. zero-filled matrices of shape `(m, m)` and `(n, n)`
  24833. respectively, and the same device as :attr:`input`. The argument :attr:`some`
  24834. has no effect when :attr:`compute_uv` is `False`.
  24835. Supports :attr:`input` of float, double, cfloat and cdouble data types.
  24836. The dtypes of `U` and `V` are the same as :attr:`input`'s. `S` will
  24837. always be real-valued, even if :attr:`input` is complex.
  24838. .. warning::
  24839. :func:`torch.svd` is deprecated in favor of :func:`torch.linalg.svd`
  24840. and will be removed in a future PyTorch release.
  24841. ``U, S, V = torch.svd(A, some=some, compute_uv=True)`` (default) should be replaced with
  24842. .. code:: python
  24843. U, S, Vh = torch.linalg.svd(A, full_matrices=not some)
  24844. V = Vh.mH
  24845. ``_, S, _ = torch.svd(A, some=some, compute_uv=False)`` should be replaced with
  24846. .. code:: python
  24847. S = torch.linalg.svdvals(A)
  24848. .. note:: Differences with :func:`torch.linalg.svd`:
  24849. * :attr:`some` is the opposite of
  24850. :func:`torch.linalg.svd`'s :attr:`full_matrices`. Note that
  24851. default value for both is `True`, so the default behavior is
  24852. effectively the opposite.
  24853. * :func:`torch.svd` returns `V`, whereas :func:`torch.linalg.svd` returns
  24854. `Vh`, that is, :math:`V^{\text{H}}`.
  24855. * If :attr:`compute_uv` is `False`, :func:`torch.svd` returns zero-filled
  24856. tensors for `U` and `Vh`, whereas :func:`torch.linalg.svd` returns
  24857. empty tensors.
  24858. .. note:: The singular values are returned in descending order. If :attr:`input` is a batch of matrices,
  24859. then the singular values of each matrix in the batch are returned in descending order.
  24860. .. note:: The `S` tensor can only be used to compute gradients if :attr:`compute_uv` is `True`.
  24861. .. note:: When :attr:`some` is `False`, the gradients on `U[..., :, min(m, n):]`
  24862. and `V[..., :, min(m, n):]` will be ignored in the backward pass, as those vectors
  24863. can be arbitrary bases of the corresponding subspaces.
  24864. .. note:: The implementation of :func:`torch.linalg.svd` on CPU uses LAPACK's routine `?gesdd`
  24865. (a divide-and-conquer algorithm) instead of `?gesvd` for speed. Analogously,
  24866. on GPU, it uses cuSOLVER's routines `gesvdj` and `gesvdjBatched` on CUDA 10.1.243
  24867. and later, and MAGMA's routine `gesdd` on earlier versions of CUDA.
  24868. .. note:: The returned `U` will not be contiguous. The matrix (or batch of matrices) will
  24869. be represented as a column-major matrix (i.e. Fortran-contiguous).
  24870. .. warning:: The gradients with respect to `U` and `V` will only be finite when the input does not
  24871. have zero nor repeated singular values.
  24872. .. warning:: If the distance between any two singular values is close to zero, the gradients with respect to
  24873. `U` and `V` will be numerically unstable, as they depends on
  24874. :math:`\frac{1}{\min_{i \neq j} \sigma_i^2 - \sigma_j^2}`. The same happens when the matrix
  24875. has small singular values, as these gradients also depend on `S^{-1}`.
  24876. .. warning:: For complex-valued :attr:`input` the singular value decomposition is not unique,
  24877. as `U` and `V` may be multiplied by an arbitrary phase factor :math:`e^{i \phi}` on every column.
  24878. The same happens when :attr:`input` has repeated singular values, where one may multiply
  24879. the columns of the spanning subspace in `U` and `V` by a rotation matrix
  24880. and `the resulting vectors will span the same subspace`_.
  24881. Different platforms, like NumPy, or inputs on different device types,
  24882. may produce different `U` and `V` tensors.
  24883. Args:
  24884. input (Tensor): the input tensor of size `(*, m, n)` where `*` is zero or more
  24885. batch dimensions consisting of `(m, n)` matrices.
  24886. some (bool, optional): controls whether to compute the reduced or full decomposition, and
  24887. consequently, the shape of returned `U` and `V`. Default: `True`.
  24888. compute_uv (bool, optional): controls whether to compute `U` and `V`. Default: `True`.
  24889. Keyword args:
  24890. out (tuple, optional): the output tuple of tensors
  24891. Example::
  24892. >>> a = torch.randn(5, 3)
  24893. >>> a
  24894. tensor([[ 0.2364, -0.7752, 0.6372],
  24895. [ 1.7201, 0.7394, -0.0504],
  24896. [-0.3371, -1.0584, 0.5296],
  24897. [ 0.3550, -0.4022, 1.5569],
  24898. [ 0.2445, -0.0158, 1.1414]])
  24899. >>> u, s, v = torch.svd(a)
  24900. >>> u
  24901. tensor([[ 0.4027, 0.0287, 0.5434],
  24902. [-0.1946, 0.8833, 0.3679],
  24903. [ 0.4296, -0.2890, 0.5261],
  24904. [ 0.6604, 0.2717, -0.2618],
  24905. [ 0.4234, 0.2481, -0.4733]])
  24906. >>> s
  24907. tensor([2.3289, 2.0315, 0.7806])
  24908. >>> v
  24909. tensor([[-0.0199, 0.8766, 0.4809],
  24910. [-0.5080, 0.4054, -0.7600],
  24911. [ 0.8611, 0.2594, -0.4373]])
  24912. >>> torch.dist(a, torch.mm(torch.mm(u, torch.diag(s)), v.t()))
  24913. tensor(8.6531e-07)
  24914. >>> a_big = torch.randn(7, 5, 3)
  24915. >>> u, s, v = torch.svd(a_big)
  24916. >>> torch.dist(a_big, torch.matmul(torch.matmul(u, torch.diag_embed(s)), v.mT))
  24917. tensor(2.6503e-06)
  24918. .. _the resulting vectors will span the same subspace:
  24919. (https://en.wikipedia.org/wiki/Singular_value_decomposition#Singular_values,_singular_vectors,_and_their_relation_to_the_SVD)
  24920. """
  24921. def swapaxes(input: Tensor, axis0: _int, axis1: _int) -> Tensor:
  24922. r"""
  24923. swapaxes(input, axis0, axis1) -> Tensor
  24924. Alias for :func:`torch.transpose`.
  24925. This function is equivalent to NumPy's swapaxes function.
  24926. Examples::
  24927. >>> x = torch.tensor([[[0,1],[2,3]],[[4,5],[6,7]]])
  24928. >>> x
  24929. tensor([[[0, 1],
  24930. [2, 3]],
  24931. [[4, 5],
  24932. [6, 7]]])
  24933. >>> torch.swapaxes(x, 0, 1)
  24934. tensor([[[0, 1],
  24935. [4, 5]],
  24936. [[2, 3],
  24937. [6, 7]]])
  24938. >>> torch.swapaxes(x, 0, 2)
  24939. tensor([[[0, 4],
  24940. [2, 6]],
  24941. [[1, 5],
  24942. [3, 7]]])
  24943. """
  24944. def swapdims(input: Tensor, dim0: _int, dim1: _int) -> Tensor:
  24945. r"""
  24946. swapdims(input, dim0, dim1) -> Tensor
  24947. Alias for :func:`torch.transpose`.
  24948. This function is equivalent to NumPy's swapaxes function.
  24949. Examples::
  24950. >>> x = torch.tensor([[[0,1],[2,3]],[[4,5],[6,7]]])
  24951. >>> x
  24952. tensor([[[0, 1],
  24953. [2, 3]],
  24954. [[4, 5],
  24955. [6, 7]]])
  24956. >>> torch.swapdims(x, 0, 1)
  24957. tensor([[[0, 1],
  24958. [4, 5]],
  24959. [[2, 3],
  24960. [6, 7]]])
  24961. >>> torch.swapdims(x, 0, 2)
  24962. tensor([[[0, 4],
  24963. [2, 6]],
  24964. [[1, 5],
  24965. [3, 7]]])
  24966. """
  24967. def sym_constrain_range(
  24968. size: Number | _complex,
  24969. *,
  24970. min: _int | None = None,
  24971. max: _int | None = None,
  24972. ) -> None: ...
  24973. def sym_constrain_range_for_size(
  24974. size: Number | _complex,
  24975. *,
  24976. min: _int | None = None,
  24977. max: _int | None = None,
  24978. ) -> None: ...
  24979. def t(input: Tensor) -> Tensor:
  24980. r"""
  24981. t(input) -> Tensor
  24982. Expects :attr:`input` to be <= 2-D tensor and transposes dimensions 0
  24983. and 1.
  24984. 0-D and 1-D tensors are returned as is. When input is a 2-D tensor this
  24985. is equivalent to ``transpose(input, 0, 1)``.
  24986. Args:
  24987. input (Tensor): the input tensor.
  24988. Example::
  24989. >>> x = torch.randn(())
  24990. >>> x
  24991. tensor(0.1995)
  24992. >>> torch.t(x)
  24993. tensor(0.1995)
  24994. >>> x = torch.randn(3)
  24995. >>> x
  24996. tensor([ 2.4320, -0.4608, 0.7702])
  24997. >>> torch.t(x)
  24998. tensor([ 2.4320, -0.4608, 0.7702])
  24999. >>> x = torch.randn(2, 3)
  25000. >>> x
  25001. tensor([[ 0.4875, 0.9158, -0.5872],
  25002. [ 0.3938, -0.6929, 0.6932]])
  25003. >>> torch.t(x)
  25004. tensor([[ 0.4875, 0.3938],
  25005. [ 0.9158, -0.6929],
  25006. [-0.5872, 0.6932]])
  25007. See also :func:`torch.transpose`.
  25008. """
  25009. def t_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  25010. r"""
  25011. Performs the same operation as :func:`torch.t`, but all output tensors
  25012. are freshly created instead of aliasing the input.
  25013. """
  25014. def take(
  25015. input: Tensor,
  25016. index: Tensor,
  25017. *,
  25018. out: Tensor | None = None,
  25019. ) -> Tensor:
  25020. r"""
  25021. take(input, index) -> Tensor
  25022. Returns a new tensor with the elements of :attr:`input` at the given indices.
  25023. The input tensor is treated as if it were viewed as a 1-D tensor. The result
  25024. takes the same shape as the indices.
  25025. Args:
  25026. input (Tensor): the input tensor.
  25027. index (LongTensor): the indices into tensor
  25028. Example::
  25029. >>> src = torch.tensor([[4, 3, 5],
  25030. ... [6, 7, 8]])
  25031. >>> torch.take(src, torch.tensor([0, 2, 5]))
  25032. tensor([ 4, 5, 8])
  25033. """
  25034. def take_along_dim(
  25035. input: Tensor,
  25036. indices: Tensor,
  25037. dim: _int | None = None,
  25038. *,
  25039. out: Tensor | None = None,
  25040. ) -> Tensor:
  25041. r"""
  25042. take_along_dim(input, indices, dim=None, *, out=None) -> Tensor
  25043. Selects values from :attr:`input` at the 1-dimensional indices from :attr:`indices` along the given :attr:`dim`.
  25044. If :attr:`dim` is None, the input array is treated as if it has been flattened to 1d.
  25045. Functions that return indices along a dimension, like :func:`torch.argmax` and :func:`torch.argsort`,
  25046. are designed to work with this function. See the examples below.
  25047. .. note::
  25048. This function is similar to NumPy's `take_along_axis`.
  25049. See also :func:`torch.gather`.
  25050. Args:
  25051. input (Tensor): the input tensor.
  25052. indices (LongTensor): the indices into :attr:`input`. Must have long dtype.
  25053. dim (int, optional): dimension to select along. Default: 0
  25054. Keyword args:
  25055. out (Tensor, optional): the output tensor.
  25056. Example::
  25057. >>> t = torch.tensor([[10, 30, 20], [60, 40, 50]])
  25058. >>> max_idx = torch.argmax(t)
  25059. >>> torch.take_along_dim(t, max_idx)
  25060. tensor([60])
  25061. >>> sorted_idx = torch.argsort(t, dim=1)
  25062. >>> torch.take_along_dim(t, sorted_idx, dim=1)
  25063. tensor([[10, 20, 30],
  25064. [40, 50, 60]])
  25065. """
  25066. def tan(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  25067. r"""
  25068. tan(input, *, out=None) -> Tensor
  25069. Returns a new tensor with the tangent of the elements of :attr:`input`.
  25070. .. math::
  25071. \text{out}_{i} = \tan(\text{input}_{i})
  25072. Args:
  25073. input (Tensor): the input tensor.
  25074. Keyword args:
  25075. out (Tensor, optional): the output tensor.
  25076. Example::
  25077. >>> a = torch.randn(4)
  25078. >>> a
  25079. tensor([-1.2027, -1.7687, 0.4412, -1.3856])
  25080. >>> torch.tan(a)
  25081. tensor([-2.5930, 4.9859, 0.4722, -5.3366])
  25082. """
  25083. def tan_(input: Tensor) -> Tensor: ...
  25084. def tanh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  25085. r"""
  25086. tanh(input, *, out=None) -> Tensor
  25087. Returns a new tensor with the hyperbolic tangent of the elements
  25088. of :attr:`input`.
  25089. .. math::
  25090. \text{out}_{i} = \tanh(\text{input}_{i})
  25091. Args:
  25092. input (Tensor): the input tensor.
  25093. Keyword args:
  25094. out (Tensor, optional): the output tensor.
  25095. Example::
  25096. >>> a = torch.randn(4)
  25097. >>> a
  25098. tensor([ 0.8986, -0.7279, 1.1745, 0.2611])
  25099. >>> torch.tanh(a)
  25100. tensor([ 0.7156, -0.6218, 0.8257, 0.2553])
  25101. """
  25102. def tanh_(input: Tensor) -> Tensor: ...
  25103. def tensor(
  25104. data: Any,
  25105. dtype: _dtype | None = None,
  25106. device: DeviceLikeType | None = None,
  25107. requires_grad: _bool = False,
  25108. pin_memory: _bool = False,
  25109. ) -> Tensor:
  25110. r"""
  25111. tensor(data, *, dtype=None, device=None, requires_grad=False, pin_memory=False) -> Tensor
  25112. Constructs a tensor with no autograd history (also known as a "leaf tensor", see :doc:`/notes/autograd`) by copying :attr:`data`.
  25113. .. warning::
  25114. When working with tensors prefer using :func:`torch.Tensor.clone`,
  25115. :func:`torch.Tensor.detach`, and :func:`torch.Tensor.requires_grad_` for
  25116. readability. Letting `t` be a tensor, ``torch.tensor(t)`` is equivalent to
  25117. ``t.detach().clone()``, and ``torch.tensor(t, requires_grad=True)``
  25118. is equivalent to ``t.detach().clone().requires_grad_(True)``.
  25119. .. seealso::
  25120. :func:`torch.as_tensor` preserves autograd history and avoids copies where possible.
  25121. :func:`torch.from_numpy` creates a tensor that shares storage with a NumPy array.
  25122. Args:
  25123. data (array_like): Initial data for the tensor. Can be a list, tuple,
  25124. NumPy ``ndarray``, scalar, and other types.
  25125. Keyword args:
  25126. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  25127. Default: if ``None``, infers data type from :attr:`data`.
  25128. device (:class:`torch.device`, optional): the device of the constructed tensor. If None and data is a tensor
  25129. then the device of data is used. If None and data is not a tensor then
  25130. the result tensor is constructed on the current device.
  25131. requires_grad (bool, optional): If autograd should record operations on the
  25132. returned tensor. Default: ``False``.
  25133. pin_memory (bool, optional): If set, returned tensor would be allocated in
  25134. the pinned memory. Works only for CPU tensors. Default: ``False``.
  25135. Example::
  25136. >>> torch.tensor([[0.1, 1.2], [2.2, 3.1], [4.9, 5.2]])
  25137. tensor([[ 0.1000, 1.2000],
  25138. [ 2.2000, 3.1000],
  25139. [ 4.9000, 5.2000]])
  25140. >>> torch.tensor([0, 1]) # Type inference on data
  25141. tensor([ 0, 1])
  25142. >>> torch.tensor([[0.11111, 0.222222, 0.3333333]],
  25143. ... dtype=torch.float64,
  25144. ... device=torch.device('cuda:0')) # creates a double tensor on a CUDA device
  25145. tensor([[ 0.1111, 0.2222, 0.3333]], dtype=torch.float64, device='cuda:0')
  25146. >>> torch.tensor(3.14159) # Create a zero-dimensional (scalar) tensor
  25147. tensor(3.1416)
  25148. >>> torch.tensor([]) # Create an empty tensor (of size (0,))
  25149. tensor([])
  25150. """
  25151. @overload
  25152. def tensor_split(
  25153. input: Tensor,
  25154. tensor_indices_or_sections: Tensor,
  25155. dim: _int = 0,
  25156. ) -> tuple[Tensor, ...]:
  25157. r"""
  25158. tensor_split(input, indices_or_sections, dim=0) -> List of Tensors
  25159. Splits a tensor into multiple sub-tensors, all of which are views of :attr:`input`,
  25160. along dimension :attr:`dim` according to the indices or number of sections specified
  25161. by :attr:`indices_or_sections`. This function is based on NumPy's
  25162. :func:`numpy.array_split`.
  25163. Args:
  25164. input (Tensor): the tensor to split
  25165. indices_or_sections (Tensor, int or list or tuple of ints):
  25166. If :attr:`indices_or_sections` is an integer ``n`` or a zero dimensional long tensor
  25167. with value ``n``, :attr:`input` is split into ``n`` sections along dimension :attr:`dim`.
  25168. If :attr:`input` is divisible by ``n`` along dimension :attr:`dim`, each
  25169. section will be of equal size, :code:`input.size(dim) / n`. If :attr:`input`
  25170. is not divisible by ``n``, the sizes of the first :code:`int(input.size(dim) % n)`
  25171. sections will have size :code:`int(input.size(dim) / n) + 1`, and the rest will
  25172. have size :code:`int(input.size(dim) / n)`.
  25173. If :attr:`indices_or_sections` is a list or tuple of ints, or a one-dimensional long
  25174. tensor, then :attr:`input` is split along dimension :attr:`dim` at each of the indices
  25175. in the list, tuple or tensor. For instance, :code:`indices_or_sections=[2, 3]` and :code:`dim=0`
  25176. would result in the tensors :code:`input[:2]`, :code:`input[2:3]`, and :code:`input[3:]`.
  25177. If :attr:`indices_or_sections` is a tensor, it must be a zero-dimensional or one-dimensional
  25178. long tensor on the CPU.
  25179. dim (int, optional): dimension along which to split the tensor. Default: ``0``
  25180. Example::
  25181. >>> x = torch.arange(8)
  25182. >>> torch.tensor_split(x, 3)
  25183. (tensor([0, 1, 2]), tensor([3, 4, 5]), tensor([6, 7]))
  25184. >>> x = torch.arange(7)
  25185. >>> torch.tensor_split(x, 3)
  25186. (tensor([0, 1, 2]), tensor([3, 4]), tensor([5, 6]))
  25187. >>> torch.tensor_split(x, (1, 6))
  25188. (tensor([0]), tensor([1, 2, 3, 4, 5]), tensor([6]))
  25189. >>> x = torch.arange(14).reshape(2, 7)
  25190. >>> x
  25191. tensor([[ 0, 1, 2, 3, 4, 5, 6],
  25192. [ 7, 8, 9, 10, 11, 12, 13]])
  25193. >>> torch.tensor_split(x, 3, dim=1)
  25194. (tensor([[0, 1, 2],
  25195. [7, 8, 9]]),
  25196. tensor([[ 3, 4],
  25197. [10, 11]]),
  25198. tensor([[ 5, 6],
  25199. [12, 13]]))
  25200. >>> torch.tensor_split(x, (1, 6), dim=1)
  25201. (tensor([[0],
  25202. [7]]),
  25203. tensor([[ 1, 2, 3, 4, 5],
  25204. [ 8, 9, 10, 11, 12]]),
  25205. tensor([[ 6],
  25206. [13]]))
  25207. """
  25208. @overload
  25209. def tensor_split(
  25210. input: Tensor,
  25211. sections: _int | SymInt,
  25212. dim: _int = 0,
  25213. ) -> tuple[Tensor, ...]:
  25214. r"""
  25215. tensor_split(input, indices_or_sections, dim=0) -> List of Tensors
  25216. Splits a tensor into multiple sub-tensors, all of which are views of :attr:`input`,
  25217. along dimension :attr:`dim` according to the indices or number of sections specified
  25218. by :attr:`indices_or_sections`. This function is based on NumPy's
  25219. :func:`numpy.array_split`.
  25220. Args:
  25221. input (Tensor): the tensor to split
  25222. indices_or_sections (Tensor, int or list or tuple of ints):
  25223. If :attr:`indices_or_sections` is an integer ``n`` or a zero dimensional long tensor
  25224. with value ``n``, :attr:`input` is split into ``n`` sections along dimension :attr:`dim`.
  25225. If :attr:`input` is divisible by ``n`` along dimension :attr:`dim`, each
  25226. section will be of equal size, :code:`input.size(dim) / n`. If :attr:`input`
  25227. is not divisible by ``n``, the sizes of the first :code:`int(input.size(dim) % n)`
  25228. sections will have size :code:`int(input.size(dim) / n) + 1`, and the rest will
  25229. have size :code:`int(input.size(dim) / n)`.
  25230. If :attr:`indices_or_sections` is a list or tuple of ints, or a one-dimensional long
  25231. tensor, then :attr:`input` is split along dimension :attr:`dim` at each of the indices
  25232. in the list, tuple or tensor. For instance, :code:`indices_or_sections=[2, 3]` and :code:`dim=0`
  25233. would result in the tensors :code:`input[:2]`, :code:`input[2:3]`, and :code:`input[3:]`.
  25234. If :attr:`indices_or_sections` is a tensor, it must be a zero-dimensional or one-dimensional
  25235. long tensor on the CPU.
  25236. dim (int, optional): dimension along which to split the tensor. Default: ``0``
  25237. Example::
  25238. >>> x = torch.arange(8)
  25239. >>> torch.tensor_split(x, 3)
  25240. (tensor([0, 1, 2]), tensor([3, 4, 5]), tensor([6, 7]))
  25241. >>> x = torch.arange(7)
  25242. >>> torch.tensor_split(x, 3)
  25243. (tensor([0, 1, 2]), tensor([3, 4]), tensor([5, 6]))
  25244. >>> torch.tensor_split(x, (1, 6))
  25245. (tensor([0]), tensor([1, 2, 3, 4, 5]), tensor([6]))
  25246. >>> x = torch.arange(14).reshape(2, 7)
  25247. >>> x
  25248. tensor([[ 0, 1, 2, 3, 4, 5, 6],
  25249. [ 7, 8, 9, 10, 11, 12, 13]])
  25250. >>> torch.tensor_split(x, 3, dim=1)
  25251. (tensor([[0, 1, 2],
  25252. [7, 8, 9]]),
  25253. tensor([[ 3, 4],
  25254. [10, 11]]),
  25255. tensor([[ 5, 6],
  25256. [12, 13]]))
  25257. >>> torch.tensor_split(x, (1, 6), dim=1)
  25258. (tensor([[0],
  25259. [7]]),
  25260. tensor([[ 1, 2, 3, 4, 5],
  25261. [ 8, 9, 10, 11, 12]]),
  25262. tensor([[ 6],
  25263. [13]]))
  25264. """
  25265. @overload
  25266. def tensor_split(
  25267. input: Tensor,
  25268. indices: Sequence[_int | SymInt],
  25269. dim: _int = 0,
  25270. ) -> tuple[Tensor, ...]:
  25271. r"""
  25272. tensor_split(input, indices_or_sections, dim=0) -> List of Tensors
  25273. Splits a tensor into multiple sub-tensors, all of which are views of :attr:`input`,
  25274. along dimension :attr:`dim` according to the indices or number of sections specified
  25275. by :attr:`indices_or_sections`. This function is based on NumPy's
  25276. :func:`numpy.array_split`.
  25277. Args:
  25278. input (Tensor): the tensor to split
  25279. indices_or_sections (Tensor, int or list or tuple of ints):
  25280. If :attr:`indices_or_sections` is an integer ``n`` or a zero dimensional long tensor
  25281. with value ``n``, :attr:`input` is split into ``n`` sections along dimension :attr:`dim`.
  25282. If :attr:`input` is divisible by ``n`` along dimension :attr:`dim`, each
  25283. section will be of equal size, :code:`input.size(dim) / n`. If :attr:`input`
  25284. is not divisible by ``n``, the sizes of the first :code:`int(input.size(dim) % n)`
  25285. sections will have size :code:`int(input.size(dim) / n) + 1`, and the rest will
  25286. have size :code:`int(input.size(dim) / n)`.
  25287. If :attr:`indices_or_sections` is a list or tuple of ints, or a one-dimensional long
  25288. tensor, then :attr:`input` is split along dimension :attr:`dim` at each of the indices
  25289. in the list, tuple or tensor. For instance, :code:`indices_or_sections=[2, 3]` and :code:`dim=0`
  25290. would result in the tensors :code:`input[:2]`, :code:`input[2:3]`, and :code:`input[3:]`.
  25291. If :attr:`indices_or_sections` is a tensor, it must be a zero-dimensional or one-dimensional
  25292. long tensor on the CPU.
  25293. dim (int, optional): dimension along which to split the tensor. Default: ``0``
  25294. Example::
  25295. >>> x = torch.arange(8)
  25296. >>> torch.tensor_split(x, 3)
  25297. (tensor([0, 1, 2]), tensor([3, 4, 5]), tensor([6, 7]))
  25298. >>> x = torch.arange(7)
  25299. >>> torch.tensor_split(x, 3)
  25300. (tensor([0, 1, 2]), tensor([3, 4]), tensor([5, 6]))
  25301. >>> torch.tensor_split(x, (1, 6))
  25302. (tensor([0]), tensor([1, 2, 3, 4, 5]), tensor([6]))
  25303. >>> x = torch.arange(14).reshape(2, 7)
  25304. >>> x
  25305. tensor([[ 0, 1, 2, 3, 4, 5, 6],
  25306. [ 7, 8, 9, 10, 11, 12, 13]])
  25307. >>> torch.tensor_split(x, 3, dim=1)
  25308. (tensor([[0, 1, 2],
  25309. [7, 8, 9]]),
  25310. tensor([[ 3, 4],
  25311. [10, 11]]),
  25312. tensor([[ 5, 6],
  25313. [12, 13]]))
  25314. >>> torch.tensor_split(x, (1, 6), dim=1)
  25315. (tensor([[0],
  25316. [7]]),
  25317. tensor([[ 1, 2, 3, 4, 5],
  25318. [ 8, 9, 10, 11, 12]]),
  25319. tensor([[ 6],
  25320. [13]]))
  25321. """
  25322. def threshold(
  25323. input: Tensor,
  25324. threshold: Number | _complex,
  25325. value: Number | _complex,
  25326. *,
  25327. out: Tensor | None = None,
  25328. ) -> Tensor: ...
  25329. def threshold_(
  25330. input: Tensor,
  25331. threshold: Number | _complex,
  25332. value: Number | _complex,
  25333. ) -> Tensor: ...
  25334. def tile(input: Tensor, dims: Sequence[_int | SymInt]) -> Tensor:
  25335. r"""
  25336. tile(input, dims) -> Tensor
  25337. Constructs a tensor by repeating the elements of :attr:`input`.
  25338. The :attr:`dims` argument specifies the number of repetitions
  25339. in each dimension.
  25340. If :attr:`dims` specifies fewer dimensions than :attr:`input` has, then
  25341. ones are prepended to :attr:`dims` until all dimensions are specified.
  25342. For example, if :attr:`input` has shape (8, 6, 4, 2) and :attr:`dims`
  25343. is (2, 2), then :attr:`dims` is treated as (1, 1, 2, 2).
  25344. Analogously, if :attr:`input` has fewer dimensions than :attr:`dims`
  25345. specifies, then :attr:`input` is treated as if it were unsqueezed at
  25346. dimension zero until it has as many dimensions as :attr:`dims` specifies.
  25347. For example, if :attr:`input` has shape (4, 2) and :attr:`dims`
  25348. is (3, 3, 2, 2), then :attr:`input` is treated as if it had the
  25349. shape (1, 1, 4, 2).
  25350. .. note::
  25351. This function is similar to NumPy's tile function.
  25352. Args:
  25353. input (Tensor): the tensor whose elements to repeat.
  25354. dims (tuple): the number of repetitions per dimension.
  25355. Example::
  25356. >>> x = torch.tensor([1, 2, 3])
  25357. >>> x.tile((2,))
  25358. tensor([1, 2, 3, 1, 2, 3])
  25359. >>> y = torch.tensor([[1, 2], [3, 4]])
  25360. >>> torch.tile(y, (2, 2))
  25361. tensor([[1, 2, 1, 2],
  25362. [3, 4, 3, 4],
  25363. [1, 2, 1, 2],
  25364. [3, 4, 3, 4]])
  25365. """
  25366. def topk(
  25367. input: Tensor,
  25368. k: _int | SymInt,
  25369. dim: _int = -1,
  25370. largest: _bool = True,
  25371. sorted: _bool = True,
  25372. *,
  25373. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  25374. ) -> torch.return_types.topk:
  25375. r"""
  25376. topk(input, k, dim=None, largest=True, sorted=True, *, out=None) -> (Tensor, LongTensor)
  25377. Returns the :attr:`k` largest elements of the given :attr:`input` tensor along
  25378. a given dimension.
  25379. If :attr:`dim` is not given, the last dimension of the `input` is chosen.
  25380. If :attr:`largest` is ``False`` then the `k` smallest elements are returned.
  25381. A namedtuple of `(values, indices)` is returned with the `values` and
  25382. `indices` of the largest `k` elements of each row of the `input` tensor in the
  25383. given dimension `dim`.
  25384. The boolean option :attr:`sorted` if ``True``, will make sure that the returned
  25385. `k` elements are themselves sorted
  25386. .. note::
  25387. When using `torch.topk`, the indices of tied elements are not guaranteed to be stable
  25388. and may vary across different invocations.
  25389. Args:
  25390. input (Tensor): the input tensor.
  25391. k (int): the k in "top-k"
  25392. dim (int, optional): the dimension to sort along
  25393. largest (bool, optional): controls whether to return largest or
  25394. smallest elements
  25395. sorted (bool, optional): controls whether to return the elements
  25396. in sorted order
  25397. Keyword args:
  25398. out (tuple, optional): the output tuple of (Tensor, LongTensor) that can be
  25399. optionally given to be used as output buffers
  25400. Example::
  25401. >>> x = torch.arange(1., 6.)
  25402. >>> x
  25403. tensor([ 1., 2., 3., 4., 5.])
  25404. >>> torch.topk(x, 3)
  25405. torch.return_types.topk(values=tensor([5., 4., 3.]), indices=tensor([4, 3, 2]))
  25406. """
  25407. def trace(input: Tensor) -> Tensor:
  25408. r"""
  25409. trace(input) -> Tensor
  25410. Returns the sum of the elements of the diagonal of the input 2-D matrix.
  25411. Example::
  25412. >>> x = torch.arange(1., 10.).view(3, 3)
  25413. >>> x
  25414. tensor([[ 1., 2., 3.],
  25415. [ 4., 5., 6.],
  25416. [ 7., 8., 9.]])
  25417. >>> torch.trace(x)
  25418. tensor(15.)
  25419. """
  25420. @overload
  25421. def transpose(input: Tensor, dim0: _int, dim1: _int) -> Tensor:
  25422. r"""
  25423. transpose(input, dim0, dim1) -> Tensor
  25424. Returns a tensor that is a transposed version of :attr:`input`.
  25425. The given dimensions :attr:`dim0` and :attr:`dim1` are swapped.
  25426. If :attr:`input` is a strided tensor then the resulting :attr:`out`
  25427. tensor shares its underlying storage with the :attr:`input` tensor, so
  25428. changing the content of one would change the content of the other.
  25429. If :attr:`input` is a :ref:`sparse tensor <sparse-docs>` then the
  25430. resulting :attr:`out` tensor *does not* share the underlying storage
  25431. with the :attr:`input` tensor.
  25432. If :attr:`input` is a :ref:`sparse tensor <sparse-docs>` with compressed
  25433. layout (SparseCSR, SparseBSR, SparseCSC or SparseBSC) the arguments
  25434. :attr:`dim0` and :attr:`dim1` must be both batch dimensions, or must
  25435. both be sparse dimensions. The batch dimensions of a sparse tensor are the
  25436. dimensions preceding the sparse dimensions.
  25437. .. note::
  25438. Transpositions which interchange the sparse dimensions of a `SparseCSR`
  25439. or `SparseCSC` layout tensor will result in the layout changing between
  25440. the two options. Transposition of the sparse dimensions of a ` SparseBSR`
  25441. or `SparseBSC` layout tensor will likewise generate a result with the
  25442. opposite layout.
  25443. Args:
  25444. input (Tensor): the input tensor.
  25445. dim0 (int): the first dimension to be transposed
  25446. dim1 (int): the second dimension to be transposed
  25447. Example::
  25448. >>> x = torch.randn(2, 3)
  25449. >>> x
  25450. tensor([[ 1.0028, -0.9893, 0.5809],
  25451. [-0.1669, 0.7299, 0.4942]])
  25452. >>> torch.transpose(x, 0, 1)
  25453. tensor([[ 1.0028, -0.1669],
  25454. [-0.9893, 0.7299],
  25455. [ 0.5809, 0.4942]])
  25456. See also :func:`torch.t`.
  25457. """
  25458. @overload
  25459. def transpose(
  25460. input: Tensor,
  25461. dim0: str | EllipsisType | None,
  25462. dim1: str | EllipsisType | None,
  25463. ) -> Tensor:
  25464. r"""
  25465. transpose(input, dim0, dim1) -> Tensor
  25466. Returns a tensor that is a transposed version of :attr:`input`.
  25467. The given dimensions :attr:`dim0` and :attr:`dim1` are swapped.
  25468. If :attr:`input` is a strided tensor then the resulting :attr:`out`
  25469. tensor shares its underlying storage with the :attr:`input` tensor, so
  25470. changing the content of one would change the content of the other.
  25471. If :attr:`input` is a :ref:`sparse tensor <sparse-docs>` then the
  25472. resulting :attr:`out` tensor *does not* share the underlying storage
  25473. with the :attr:`input` tensor.
  25474. If :attr:`input` is a :ref:`sparse tensor <sparse-docs>` with compressed
  25475. layout (SparseCSR, SparseBSR, SparseCSC or SparseBSC) the arguments
  25476. :attr:`dim0` and :attr:`dim1` must be both batch dimensions, or must
  25477. both be sparse dimensions. The batch dimensions of a sparse tensor are the
  25478. dimensions preceding the sparse dimensions.
  25479. .. note::
  25480. Transpositions which interchange the sparse dimensions of a `SparseCSR`
  25481. or `SparseCSC` layout tensor will result in the layout changing between
  25482. the two options. Transposition of the sparse dimensions of a ` SparseBSR`
  25483. or `SparseBSC` layout tensor will likewise generate a result with the
  25484. opposite layout.
  25485. Args:
  25486. input (Tensor): the input tensor.
  25487. dim0 (int): the first dimension to be transposed
  25488. dim1 (int): the second dimension to be transposed
  25489. Example::
  25490. >>> x = torch.randn(2, 3)
  25491. >>> x
  25492. tensor([[ 1.0028, -0.9893, 0.5809],
  25493. [-0.1669, 0.7299, 0.4942]])
  25494. >>> torch.transpose(x, 0, 1)
  25495. tensor([[ 1.0028, -0.1669],
  25496. [-0.9893, 0.7299],
  25497. [ 0.5809, 0.4942]])
  25498. See also :func:`torch.t`.
  25499. """
  25500. def transpose_copy(
  25501. input: Tensor,
  25502. dim0: _int,
  25503. dim1: _int,
  25504. *,
  25505. out: Tensor | None = None,
  25506. ) -> Tensor:
  25507. r"""
  25508. Performs the same operation as :func:`torch.transpose`, but all output tensors
  25509. are freshly created instead of aliasing the input.
  25510. """
  25511. @overload
  25512. def trapezoid(y: Tensor, x: Tensor, *, dim: _int = -1) -> Tensor:
  25513. r"""
  25514. trapezoid(y, x=None, *, dx=None, dim=-1) -> Tensor
  25515. Computes the `trapezoidal rule <https://en.wikipedia.org/wiki/Trapezoidal_rule>`_ along
  25516. :attr:`dim`. By default the spacing between elements is assumed to be 1, but
  25517. :attr:`dx` can be used to specify a different constant spacing, and :attr:`x` can be
  25518. used to specify arbitrary spacing along :attr:`dim`. Only one of :attr:`x` or :attr:`dx` should be specified.
  25519. Assuming :attr:`y` is a one-dimensional tensor with elements :math:`{y_0, y_1, ..., y_n}`,
  25520. the default computation is
  25521. .. math::
  25522. \begin{aligned}
  25523. \sum_{i = 1}^{n} \frac{1}{2} (y_i + y_{i-1})
  25524. \end{aligned}
  25525. When :attr:`dx` is specified the computation becomes
  25526. .. math::
  25527. \begin{aligned}
  25528. \sum_{i = 1}^{n} \frac{\Delta x}{2} (y_i + y_{i-1})
  25529. \end{aligned}
  25530. effectively multiplying the result by :attr:`dx`. When :attr:`x` is specified,
  25531. assuming :attr:`x` is also a one-dimensional tensor with
  25532. elements :math:`{x_0, x_1, ..., x_n}`, the computation becomes
  25533. .. math::
  25534. \begin{aligned}
  25535. \sum_{i = 1}^{n} \frac{(x_i - x_{i-1})}{2} (y_i + y_{i-1})
  25536. \end{aligned}
  25537. When :attr:`x` and :attr:`y` have the same size, the computation is as described above and no broadcasting is needed.
  25538. The broadcasting behavior of this function is as follows when their sizes are different. For both :attr:`x`
  25539. and :attr:`y`, the function computes the difference between consecutive elements along
  25540. dimension :attr:`dim`. This effectively creates two tensors, `x_diff` and `y_diff`, that have
  25541. the same shape as the original tensors except their lengths along the dimension :attr:`dim` is reduced by 1.
  25542. After that, those two tensors are broadcast together to compute final output as part of the trapezoidal rule.
  25543. See the examples below for details.
  25544. .. note::
  25545. The trapezoidal rule is a technique for approximating the definite integral of a function
  25546. by averaging its left and right Riemann sums. The approximation becomes more accurate as
  25547. the resolution of the partition increases.
  25548. Arguments:
  25549. y (Tensor): Values to use when computing the trapezoidal rule.
  25550. x (Tensor): If specified, defines spacing between values as specified above.
  25551. Keyword arguments:
  25552. dx (float): constant spacing between values. If neither :attr:`x` or :attr:`dx`
  25553. are specified then this defaults to 1. Effectively multiplies the result by its value.
  25554. dim (int): The dimension along which to compute the trapezoidal rule.
  25555. The last (inner-most) dimension by default.
  25556. Examples::
  25557. >>> # Computes the trapezoidal rule in 1D, spacing is implicitly 1
  25558. >>> y = torch.tensor([1, 5, 10])
  25559. >>> torch.trapezoid(y)
  25560. tensor(10.5)
  25561. >>> # Computes the same trapezoidal rule directly to verify
  25562. >>> (1 + 10 + 10) / 2
  25563. 10.5
  25564. >>> # Computes the trapezoidal rule in 1D with constant spacing of 2
  25565. >>> # NOTE: the result is the same as before, but multiplied by 2
  25566. >>> torch.trapezoid(y, dx=2)
  25567. 21.0
  25568. >>> # Computes the trapezoidal rule in 1D with arbitrary spacing
  25569. >>> x = torch.tensor([1, 3, 6])
  25570. >>> torch.trapezoid(y, x)
  25571. 28.5
  25572. >>> # Computes the same trapezoidal rule directly to verify
  25573. >>> ((3 - 1) * (1 + 5) + (6 - 3) * (5 + 10)) / 2
  25574. 28.5
  25575. >>> # Computes the trapezoidal rule for each row of a 3x3 matrix
  25576. >>> y = torch.arange(9).reshape(3, 3)
  25577. tensor([[0, 1, 2],
  25578. [3, 4, 5],
  25579. [6, 7, 8]])
  25580. >>> torch.trapezoid(y)
  25581. tensor([ 2., 8., 14.])
  25582. >>> # Computes the trapezoidal rule for each column of the matrix
  25583. >>> torch.trapezoid(y, dim=0)
  25584. tensor([ 6., 8., 10.])
  25585. >>> # Computes the trapezoidal rule for each row of a 3x3 ones matrix
  25586. >>> # with the same arbitrary spacing
  25587. >>> y = torch.ones(3, 3)
  25588. >>> x = torch.tensor([1, 3, 6])
  25589. >>> torch.trapezoid(y, x)
  25590. array([5., 5., 5.])
  25591. >>> # Computes the trapezoidal rule for each row of a 3x3 ones matrix
  25592. >>> # with different arbitrary spacing per row
  25593. >>> y = torch.ones(3, 3)
  25594. >>> x = torch.tensor([[1, 2, 3], [1, 3, 5], [1, 4, 7]])
  25595. >>> torch.trapezoid(y, x)
  25596. array([2., 4., 6.])
  25597. """
  25598. @overload
  25599. def trapezoid(
  25600. y: Tensor,
  25601. *,
  25602. dx: Number | _complex = 1,
  25603. dim: _int = -1,
  25604. ) -> Tensor:
  25605. r"""
  25606. trapezoid(y, x=None, *, dx=None, dim=-1) -> Tensor
  25607. Computes the `trapezoidal rule <https://en.wikipedia.org/wiki/Trapezoidal_rule>`_ along
  25608. :attr:`dim`. By default the spacing between elements is assumed to be 1, but
  25609. :attr:`dx` can be used to specify a different constant spacing, and :attr:`x` can be
  25610. used to specify arbitrary spacing along :attr:`dim`. Only one of :attr:`x` or :attr:`dx` should be specified.
  25611. Assuming :attr:`y` is a one-dimensional tensor with elements :math:`{y_0, y_1, ..., y_n}`,
  25612. the default computation is
  25613. .. math::
  25614. \begin{aligned}
  25615. \sum_{i = 1}^{n} \frac{1}{2} (y_i + y_{i-1})
  25616. \end{aligned}
  25617. When :attr:`dx` is specified the computation becomes
  25618. .. math::
  25619. \begin{aligned}
  25620. \sum_{i = 1}^{n} \frac{\Delta x}{2} (y_i + y_{i-1})
  25621. \end{aligned}
  25622. effectively multiplying the result by :attr:`dx`. When :attr:`x` is specified,
  25623. assuming :attr:`x` is also a one-dimensional tensor with
  25624. elements :math:`{x_0, x_1, ..., x_n}`, the computation becomes
  25625. .. math::
  25626. \begin{aligned}
  25627. \sum_{i = 1}^{n} \frac{(x_i - x_{i-1})}{2} (y_i + y_{i-1})
  25628. \end{aligned}
  25629. When :attr:`x` and :attr:`y` have the same size, the computation is as described above and no broadcasting is needed.
  25630. The broadcasting behavior of this function is as follows when their sizes are different. For both :attr:`x`
  25631. and :attr:`y`, the function computes the difference between consecutive elements along
  25632. dimension :attr:`dim`. This effectively creates two tensors, `x_diff` and `y_diff`, that have
  25633. the same shape as the original tensors except their lengths along the dimension :attr:`dim` is reduced by 1.
  25634. After that, those two tensors are broadcast together to compute final output as part of the trapezoidal rule.
  25635. See the examples below for details.
  25636. .. note::
  25637. The trapezoidal rule is a technique for approximating the definite integral of a function
  25638. by averaging its left and right Riemann sums. The approximation becomes more accurate as
  25639. the resolution of the partition increases.
  25640. Arguments:
  25641. y (Tensor): Values to use when computing the trapezoidal rule.
  25642. x (Tensor): If specified, defines spacing between values as specified above.
  25643. Keyword arguments:
  25644. dx (float): constant spacing between values. If neither :attr:`x` or :attr:`dx`
  25645. are specified then this defaults to 1. Effectively multiplies the result by its value.
  25646. dim (int): The dimension along which to compute the trapezoidal rule.
  25647. The last (inner-most) dimension by default.
  25648. Examples::
  25649. >>> # Computes the trapezoidal rule in 1D, spacing is implicitly 1
  25650. >>> y = torch.tensor([1, 5, 10])
  25651. >>> torch.trapezoid(y)
  25652. tensor(10.5)
  25653. >>> # Computes the same trapezoidal rule directly to verify
  25654. >>> (1 + 10 + 10) / 2
  25655. 10.5
  25656. >>> # Computes the trapezoidal rule in 1D with constant spacing of 2
  25657. >>> # NOTE: the result is the same as before, but multiplied by 2
  25658. >>> torch.trapezoid(y, dx=2)
  25659. 21.0
  25660. >>> # Computes the trapezoidal rule in 1D with arbitrary spacing
  25661. >>> x = torch.tensor([1, 3, 6])
  25662. >>> torch.trapezoid(y, x)
  25663. 28.5
  25664. >>> # Computes the same trapezoidal rule directly to verify
  25665. >>> ((3 - 1) * (1 + 5) + (6 - 3) * (5 + 10)) / 2
  25666. 28.5
  25667. >>> # Computes the trapezoidal rule for each row of a 3x3 matrix
  25668. >>> y = torch.arange(9).reshape(3, 3)
  25669. tensor([[0, 1, 2],
  25670. [3, 4, 5],
  25671. [6, 7, 8]])
  25672. >>> torch.trapezoid(y)
  25673. tensor([ 2., 8., 14.])
  25674. >>> # Computes the trapezoidal rule for each column of the matrix
  25675. >>> torch.trapezoid(y, dim=0)
  25676. tensor([ 6., 8., 10.])
  25677. >>> # Computes the trapezoidal rule for each row of a 3x3 ones matrix
  25678. >>> # with the same arbitrary spacing
  25679. >>> y = torch.ones(3, 3)
  25680. >>> x = torch.tensor([1, 3, 6])
  25681. >>> torch.trapezoid(y, x)
  25682. array([5., 5., 5.])
  25683. >>> # Computes the trapezoidal rule for each row of a 3x3 ones matrix
  25684. >>> # with different arbitrary spacing per row
  25685. >>> y = torch.ones(3, 3)
  25686. >>> x = torch.tensor([[1, 2, 3], [1, 3, 5], [1, 4, 7]])
  25687. >>> torch.trapezoid(y, x)
  25688. array([2., 4., 6.])
  25689. """
  25690. @overload
  25691. def trapz(y: Tensor, *, dx: _float = 1, dim: _int = -1) -> Tensor:
  25692. r"""
  25693. trapz(y, x, *, dim=-1) -> Tensor
  25694. Alias for :func:`torch.trapezoid`.
  25695. """
  25696. @overload
  25697. def trapz(y: Tensor, x: Tensor, *, dim: _int = -1) -> Tensor:
  25698. r"""
  25699. trapz(y, x, *, dim=-1) -> Tensor
  25700. Alias for :func:`torch.trapezoid`.
  25701. """
  25702. def triangular_solve(
  25703. input: Tensor,
  25704. A: Tensor,
  25705. upper: _bool = True,
  25706. transpose: _bool = False,
  25707. unitriangular: _bool = False,
  25708. *,
  25709. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  25710. ) -> torch.return_types.triangular_solve:
  25711. r"""
  25712. triangular_solve(b, A, upper=True, transpose=False, unitriangular=False, *, out=None) -> (Tensor, Tensor)
  25713. Solves a system of equations with a square upper or lower triangular invertible matrix :math:`A`
  25714. and multiple right-hand sides :math:`b`.
  25715. In symbols, it solves :math:`AX = b` and assumes :math:`A` is square upper-triangular
  25716. (or lower-triangular if :attr:`upper`\ `= False`) and does not have zeros on the diagonal.
  25717. `torch.triangular_solve(b, A)` can take in 2D inputs `b, A` or inputs that are
  25718. batches of 2D matrices. If the inputs are batches, then returns
  25719. batched outputs `X`
  25720. If the diagonal of :attr:`A` contains zeros or elements that are very close to zero and
  25721. :attr:`unitriangular`\ `= False` (default) or if the input matrix is badly conditioned,
  25722. the result may contain `NaN` s.
  25723. Supports input of float, double, cfloat and cdouble data types.
  25724. .. warning::
  25725. :func:`torch.triangular_solve` is deprecated in favor of :func:`torch.linalg.solve_triangular`
  25726. and will be removed in a future PyTorch release.
  25727. :func:`torch.linalg.solve_triangular` has its arguments reversed and does not return a
  25728. copy of one of the inputs.
  25729. ``X = torch.triangular_solve(B, A).solution`` should be replaced with
  25730. .. code:: python
  25731. X = torch.linalg.solve_triangular(A, B)
  25732. Args:
  25733. b (Tensor): multiple right-hand sides of size :math:`(*, m, k)` where
  25734. :math:`*` is zero of more batch dimensions
  25735. A (Tensor): the input triangular coefficient matrix of size :math:`(*, m, m)`
  25736. where :math:`*` is zero or more batch dimensions
  25737. upper (bool, optional): whether :math:`A` is upper or lower triangular. Default: ``True``.
  25738. transpose (bool, optional): solves `op(A)X = b` where `op(A) = A^T` if this flag is ``True``,
  25739. and `op(A) = A` if it is ``False``. Default: ``False``.
  25740. unitriangular (bool, optional): whether :math:`A` is unit triangular.
  25741. If True, the diagonal elements of :math:`A` are assumed to be
  25742. 1 and not referenced from :math:`A`. Default: ``False``.
  25743. Keyword args:
  25744. out ((Tensor, Tensor), optional): tuple of two tensors to write
  25745. the output to. Ignored if `None`. Default: `None`.
  25746. Returns:
  25747. A namedtuple `(solution, cloned_coefficient)` where `cloned_coefficient`
  25748. is a clone of :math:`A` and `solution` is the solution :math:`X` to :math:`AX = b`
  25749. (or whatever variant of the system of equations, depending on the keyword arguments.)
  25750. Examples::
  25751. >>> A = torch.randn(2, 2).triu()
  25752. >>> A
  25753. tensor([[ 1.1527, -1.0753],
  25754. [ 0.0000, 0.7986]])
  25755. >>> b = torch.randn(2, 3)
  25756. >>> b
  25757. tensor([[-0.0210, 2.3513, -1.5492],
  25758. [ 1.5429, 0.7403, -1.0243]])
  25759. >>> torch.triangular_solve(b, A)
  25760. torch.return_types.triangular_solve(
  25761. solution=tensor([[ 1.7841, 2.9046, -2.5405],
  25762. [ 1.9320, 0.9270, -1.2826]]),
  25763. cloned_coefficient=tensor([[ 1.1527, -1.0753],
  25764. [ 0.0000, 0.7986]]))
  25765. """
  25766. def tril(
  25767. input: Tensor,
  25768. diagonal: _int = 0,
  25769. *,
  25770. out: Tensor | None = None,
  25771. ) -> Tensor:
  25772. r"""
  25773. tril(input, diagonal=0, *, out=None) -> Tensor
  25774. Returns the lower triangular part of the matrix (2-D tensor) or batch of matrices
  25775. :attr:`input`, the other elements of the result tensor :attr:`out` are set to 0.
  25776. The lower triangular part of the matrix is defined as the elements on and
  25777. below the diagonal.
  25778. The argument :attr:`diagonal` controls which diagonal to consider. If
  25779. :attr:`diagonal` = 0, all elements on and below the main diagonal are
  25780. retained. A positive value includes just as many diagonals above the main
  25781. diagonal, and similarly a negative value excludes just as many diagonals below
  25782. the main diagonal. The main diagonal are the set of indices
  25783. :math:`\lbrace (i, i) \rbrace` for :math:`i \in [0, \min\{d_{1}, d_{2}\} - 1]` where
  25784. :math:`d_{1}, d_{2}` are the dimensions of the matrix.
  25785. Args:
  25786. input (Tensor): the input tensor.
  25787. diagonal (int, optional): the diagonal to consider
  25788. Keyword args:
  25789. out (Tensor, optional): the output tensor.
  25790. Example::
  25791. >>> a = torch.randn(3, 3)
  25792. >>> a
  25793. tensor([[-1.0813, -0.8619, 0.7105],
  25794. [ 0.0935, 0.1380, 2.2112],
  25795. [-0.3409, -0.9828, 0.0289]])
  25796. >>> torch.tril(a)
  25797. tensor([[-1.0813, 0.0000, 0.0000],
  25798. [ 0.0935, 0.1380, 0.0000],
  25799. [-0.3409, -0.9828, 0.0289]])
  25800. >>> b = torch.randn(4, 6)
  25801. >>> b
  25802. tensor([[ 1.2219, 0.5653, -0.2521, -0.2345, 1.2544, 0.3461],
  25803. [ 0.4785, -0.4477, 0.6049, 0.6368, 0.8775, 0.7145],
  25804. [ 1.1502, 3.2716, -1.1243, -0.5413, 0.3615, 0.6864],
  25805. [-0.0614, -0.7344, -1.3164, -0.7648, -1.4024, 0.0978]])
  25806. >>> torch.tril(b, diagonal=1)
  25807. tensor([[ 1.2219, 0.5653, 0.0000, 0.0000, 0.0000, 0.0000],
  25808. [ 0.4785, -0.4477, 0.6049, 0.0000, 0.0000, 0.0000],
  25809. [ 1.1502, 3.2716, -1.1243, -0.5413, 0.0000, 0.0000],
  25810. [-0.0614, -0.7344, -1.3164, -0.7648, -1.4024, 0.0000]])
  25811. >>> torch.tril(b, diagonal=-1)
  25812. tensor([[ 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
  25813. [ 0.4785, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
  25814. [ 1.1502, 3.2716, 0.0000, 0.0000, 0.0000, 0.0000],
  25815. [-0.0614, -0.7344, -1.3164, 0.0000, 0.0000, 0.0000]])
  25816. """
  25817. def tril_indices(
  25818. row: _int,
  25819. col: _int,
  25820. offset: _int = 0,
  25821. *,
  25822. dtype: _dtype | None = None,
  25823. layout: _layout | None = None,
  25824. device: DeviceLikeType | None = None,
  25825. pin_memory: _bool | None = False,
  25826. requires_grad: _bool | None = False,
  25827. ) -> Tensor:
  25828. r"""
  25829. tril_indices(row, col, offset=0, *, dtype=torch.long, device='cpu', layout=torch.strided) -> Tensor
  25830. Returns the indices of the lower triangular part of a :attr:`row`-by-
  25831. :attr:`col` matrix in a 2-by-N Tensor, where the first row contains row
  25832. coordinates of all indices and the second row contains column coordinates.
  25833. Indices are ordered based on rows and then columns.
  25834. The lower triangular part of the matrix is defined as the elements on and
  25835. below the diagonal.
  25836. The argument :attr:`offset` controls which diagonal to consider. If
  25837. :attr:`offset` = 0, all elements on and below the main diagonal are
  25838. retained. A positive value includes just as many diagonals above the main
  25839. diagonal, and similarly a negative value excludes just as many diagonals below
  25840. the main diagonal. The main diagonal are the set of indices
  25841. :math:`\lbrace (i, i) \rbrace` for :math:`i \in [0, \min\{d_{1}, d_{2}\} - 1]`
  25842. where :math:`d_{1}, d_{2}` are the dimensions of the matrix.
  25843. .. note::
  25844. When running on CUDA, ``row * col`` must be less than :math:`2^{59}` to
  25845. prevent overflow during calculation.
  25846. Args:
  25847. row (``int``): number of rows in the 2-D matrix.
  25848. col (``int``): number of columns in the 2-D matrix.
  25849. offset (``int``): diagonal offset from the main diagonal.
  25850. Default: if not provided, 0.
  25851. Keyword args:
  25852. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor,
  25853. only support ``torch.int``, ``torch.long``. Default: if ``None``, ``torch.long``.
  25854. device (:class:`torch.device`, optional): the desired device of returned tensor.
  25855. Default: if ``None``, uses the current device for the default tensor type
  25856. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  25857. for CPU tensor types and the current CUDA device for CUDA tensor types.
  25858. layout (:class:`torch.layout`, optional): currently only support ``torch.strided``.
  25859. Example::
  25860. >>> a = torch.tril_indices(3, 3)
  25861. >>> a
  25862. tensor([[0, 1, 1, 2, 2, 2],
  25863. [0, 0, 1, 0, 1, 2]])
  25864. >>> a = torch.tril_indices(4, 3, -1)
  25865. >>> a
  25866. tensor([[1, 2, 2, 3, 3, 3],
  25867. [0, 0, 1, 0, 1, 2]])
  25868. >>> a = torch.tril_indices(4, 3, 1)
  25869. >>> a
  25870. tensor([[0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3],
  25871. [0, 1, 0, 1, 2, 0, 1, 2, 0, 1, 2]])
  25872. """
  25873. def triplet_margin_loss(
  25874. anchor: Tensor,
  25875. positive: Tensor,
  25876. negative: Tensor,
  25877. margin: _float = 1.0,
  25878. p: _float = 2,
  25879. eps: _float = 1e-06,
  25880. swap: _bool = False,
  25881. reduction: _int = 1,
  25882. ) -> Tensor: ...
  25883. def triu(
  25884. input: Tensor,
  25885. diagonal: _int = 0,
  25886. *,
  25887. out: Tensor | None = None,
  25888. ) -> Tensor:
  25889. r"""
  25890. triu(input, diagonal=0, *, out=None) -> Tensor
  25891. Returns the upper triangular part of a matrix (2-D tensor) or batch of matrices
  25892. :attr:`input`, the other elements of the result tensor :attr:`out` are set to 0.
  25893. The upper triangular part of the matrix is defined as the elements on and
  25894. above the diagonal.
  25895. The argument :attr:`diagonal` controls which diagonal to consider. If
  25896. :attr:`diagonal` = 0, all elements on and above the main diagonal are
  25897. retained. A positive value excludes just as many diagonals above the main
  25898. diagonal, and similarly a negative value includes just as many diagonals below
  25899. the main diagonal. The main diagonal are the set of indices
  25900. :math:`\lbrace (i, i) \rbrace` for :math:`i \in [0, \min\{d_{1}, d_{2}\} - 1]` where
  25901. :math:`d_{1}, d_{2}` are the dimensions of the matrix.
  25902. Args:
  25903. input (Tensor): the input tensor.
  25904. diagonal (int, optional): the diagonal to consider
  25905. Keyword args:
  25906. out (Tensor, optional): the output tensor.
  25907. Example::
  25908. >>> a = torch.randn(3, 3)
  25909. >>> a
  25910. tensor([[ 0.2309, 0.5207, 2.0049],
  25911. [ 0.2072, -1.0680, 0.6602],
  25912. [ 0.3480, -0.5211, -0.4573]])
  25913. >>> torch.triu(a)
  25914. tensor([[ 0.2309, 0.5207, 2.0049],
  25915. [ 0.0000, -1.0680, 0.6602],
  25916. [ 0.0000, 0.0000, -0.4573]])
  25917. >>> torch.triu(a, diagonal=1)
  25918. tensor([[ 0.0000, 0.5207, 2.0049],
  25919. [ 0.0000, 0.0000, 0.6602],
  25920. [ 0.0000, 0.0000, 0.0000]])
  25921. >>> torch.triu(a, diagonal=-1)
  25922. tensor([[ 0.2309, 0.5207, 2.0049],
  25923. [ 0.2072, -1.0680, 0.6602],
  25924. [ 0.0000, -0.5211, -0.4573]])
  25925. >>> b = torch.randn(4, 6)
  25926. >>> b
  25927. tensor([[ 0.5876, -0.0794, -1.8373, 0.6654, 0.2604, 1.5235],
  25928. [-0.2447, 0.9556, -1.2919, 1.3378, -0.1768, -1.0857],
  25929. [ 0.4333, 0.3146, 0.6576, -1.0432, 0.9348, -0.4410],
  25930. [-0.9888, 1.0679, -1.3337, -1.6556, 0.4798, 0.2830]])
  25931. >>> torch.triu(b, diagonal=1)
  25932. tensor([[ 0.0000, -0.0794, -1.8373, 0.6654, 0.2604, 1.5235],
  25933. [ 0.0000, 0.0000, -1.2919, 1.3378, -0.1768, -1.0857],
  25934. [ 0.0000, 0.0000, 0.0000, -1.0432, 0.9348, -0.4410],
  25935. [ 0.0000, 0.0000, 0.0000, 0.0000, 0.4798, 0.2830]])
  25936. >>> torch.triu(b, diagonal=-1)
  25937. tensor([[ 0.5876, -0.0794, -1.8373, 0.6654, 0.2604, 1.5235],
  25938. [-0.2447, 0.9556, -1.2919, 1.3378, -0.1768, -1.0857],
  25939. [ 0.0000, 0.3146, 0.6576, -1.0432, 0.9348, -0.4410],
  25940. [ 0.0000, 0.0000, -1.3337, -1.6556, 0.4798, 0.2830]])
  25941. """
  25942. def triu_indices(
  25943. row: _int,
  25944. col: _int,
  25945. offset: _int = 0,
  25946. *,
  25947. dtype: _dtype | None = None,
  25948. layout: _layout | None = None,
  25949. device: DeviceLikeType | None = None,
  25950. pin_memory: _bool | None = False,
  25951. requires_grad: _bool | None = False,
  25952. ) -> Tensor:
  25953. r"""
  25954. triu_indices(row, col, offset=0, *, dtype=torch.long, device='cpu', layout=torch.strided) -> Tensor
  25955. Returns the indices of the upper triangular part of a :attr:`row` by
  25956. :attr:`col` matrix in a 2-by-N Tensor, where the first row contains row
  25957. coordinates of all indices and the second row contains column coordinates.
  25958. Indices are ordered based on rows and then columns.
  25959. The upper triangular part of the matrix is defined as the elements on and
  25960. above the diagonal.
  25961. The argument :attr:`offset` controls which diagonal to consider. If
  25962. :attr:`offset` = 0, all elements on and above the main diagonal are
  25963. retained. A positive value excludes just as many diagonals above the main
  25964. diagonal, and similarly a negative value includes just as many diagonals below
  25965. the main diagonal. The main diagonal are the set of indices
  25966. :math:`\lbrace (i, i) \rbrace` for :math:`i \in [0, \min\{d_{1}, d_{2}\} - 1]`
  25967. where :math:`d_{1}, d_{2}` are the dimensions of the matrix.
  25968. .. note::
  25969. When running on CUDA, ``row * col`` must be less than :math:`2^{59}` to
  25970. prevent overflow during calculation.
  25971. Args:
  25972. row (``int``): number of rows in the 2-D matrix.
  25973. col (``int``): number of columns in the 2-D matrix.
  25974. offset (``int``): diagonal offset from the main diagonal.
  25975. Default: if not provided, 0.
  25976. Keyword args:
  25977. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor,
  25978. only support ``torch.int``, ``torch.long``. Default: if ``None``, ``torch.long``.
  25979. device (:class:`torch.device`, optional): the desired device of returned tensor.
  25980. Default: if ``None``, uses the current device for the default tensor type
  25981. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  25982. for CPU tensor types and the current CUDA device for CUDA tensor types.
  25983. layout (:class:`torch.layout`, optional): currently only support ``torch.strided``.
  25984. Example::
  25985. >>> a = torch.triu_indices(3, 3)
  25986. >>> a
  25987. tensor([[0, 0, 0, 1, 1, 2],
  25988. [0, 1, 2, 1, 2, 2]])
  25989. >>> a = torch.triu_indices(4, 3, -1)
  25990. >>> a
  25991. tensor([[0, 0, 0, 1, 1, 1, 2, 2, 3],
  25992. [0, 1, 2, 0, 1, 2, 1, 2, 2]])
  25993. >>> a = torch.triu_indices(4, 3, 1)
  25994. >>> a
  25995. tensor([[0, 0, 1],
  25996. [1, 2, 2]])
  25997. """
  25998. def true_divide(
  25999. input: Tensor | Number,
  26000. other: Tensor | Number,
  26001. *,
  26002. out: Tensor | None = None,
  26003. ) -> Tensor:
  26004. r"""
  26005. true_divide(dividend, divisor, *, out) -> Tensor
  26006. Alias for :func:`torch.div` with ``rounding_mode=None``.
  26007. """
  26008. def trunc(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  26009. r"""
  26010. trunc(input, *, out=None) -> Tensor
  26011. Returns a new tensor with the truncated integer values of
  26012. the elements of :attr:`input`.
  26013. For integer inputs, follows the array-api convention of returning a
  26014. copy of the input tensor.
  26015. Args:
  26016. input (Tensor): the input tensor.
  26017. Keyword args:
  26018. out (Tensor, optional): the output tensor.
  26019. Example::
  26020. >>> a = torch.randn(4)
  26021. >>> a
  26022. tensor([ 3.4742, 0.5466, -0.8008, -0.9079])
  26023. >>> torch.trunc(a)
  26024. tensor([ 3., 0., -0., -0.])
  26025. """
  26026. def trunc_(input: Tensor) -> Tensor: ...
  26027. @overload
  26028. def unbind(input: Tensor, dim: _int = 0) -> tuple[Tensor, ...]:
  26029. r"""
  26030. unbind(input, dim=0) -> seq
  26031. Removes a tensor dimension.
  26032. Returns a tuple of all slices along a given dimension, already without it.
  26033. Arguments:
  26034. input (Tensor): the tensor to unbind
  26035. dim (int): dimension to remove
  26036. Example::
  26037. >>> torch.unbind(torch.tensor([[1, 2, 3],
  26038. >>> [4, 5, 6],
  26039. >>> [7, 8, 9]]))
  26040. (tensor([1, 2, 3]), tensor([4, 5, 6]), tensor([7, 8, 9]))
  26041. """
  26042. @overload
  26043. def unbind(
  26044. input: Tensor,
  26045. dim: str | EllipsisType | None,
  26046. ) -> tuple[Tensor, ...]:
  26047. r"""
  26048. unbind(input, dim=0) -> seq
  26049. Removes a tensor dimension.
  26050. Returns a tuple of all slices along a given dimension, already without it.
  26051. Arguments:
  26052. input (Tensor): the tensor to unbind
  26053. dim (int): dimension to remove
  26054. Example::
  26055. >>> torch.unbind(torch.tensor([[1, 2, 3],
  26056. >>> [4, 5, 6],
  26057. >>> [7, 8, 9]]))
  26058. (tensor([1, 2, 3]), tensor([4, 5, 6]), tensor([7, 8, 9]))
  26059. """
  26060. def unbind_copy(
  26061. input: Tensor,
  26062. dim: _int = 0,
  26063. *,
  26064. out: tuple[Tensor, ...] | list[Tensor] | None = None,
  26065. ) -> None:
  26066. r"""
  26067. Performs the same operation as :func:`torch.unbind`, but all output tensors
  26068. are freshly created instead of aliasing the input.
  26069. """
  26070. @overload
  26071. def unflatten(
  26072. input: Tensor,
  26073. dim: str | EllipsisType | None,
  26074. sizes: Sequence[_int | SymInt],
  26075. names: Sequence[str | EllipsisType | None],
  26076. ) -> Tensor:
  26077. r"""
  26078. unflatten(input, dim, sizes) -> Tensor
  26079. Expands a dimension of the input tensor over multiple dimensions.
  26080. .. seealso::
  26081. :func:`torch.flatten` the inverse of this function. It coalesces several dimensions into one.
  26082. Args:
  26083. input (Tensor): the input tensor.
  26084. dim (int): Dimension to be unflattened, specified as an index into
  26085. ``input.shape``.
  26086. sizes (Tuple[int]): New shape of the unflattened dimension.
  26087. One of its elements can be `-1` in which case the corresponding output
  26088. dimension is inferred. Otherwise, the product of ``sizes`` *must*
  26089. equal ``input.shape[dim]``.
  26090. Returns:
  26091. A View of input with the specified dimension unflattened.
  26092. Examples::
  26093. >>> torch.unflatten(torch.randn(3, 4, 1), 1, (2, 2)).shape
  26094. torch.Size([3, 2, 2, 1])
  26095. >>> torch.unflatten(torch.randn(3, 4, 1), 1, (-1, 2)).shape
  26096. torch.Size([3, 2, 2, 1])
  26097. >>> torch.unflatten(torch.randn(5, 12, 3), -2, (2, 2, 3, 1, 1)).shape
  26098. torch.Size([5, 2, 2, 3, 1, 1, 3])
  26099. """
  26100. @overload
  26101. def unflatten(
  26102. input: Tensor,
  26103. dim: _int,
  26104. sizes: Sequence[_int | SymInt],
  26105. ) -> Tensor:
  26106. r"""
  26107. unflatten(input, dim, sizes) -> Tensor
  26108. Expands a dimension of the input tensor over multiple dimensions.
  26109. .. seealso::
  26110. :func:`torch.flatten` the inverse of this function. It coalesces several dimensions into one.
  26111. Args:
  26112. input (Tensor): the input tensor.
  26113. dim (int): Dimension to be unflattened, specified as an index into
  26114. ``input.shape``.
  26115. sizes (Tuple[int]): New shape of the unflattened dimension.
  26116. One of its elements can be `-1` in which case the corresponding output
  26117. dimension is inferred. Otherwise, the product of ``sizes`` *must*
  26118. equal ``input.shape[dim]``.
  26119. Returns:
  26120. A View of input with the specified dimension unflattened.
  26121. Examples::
  26122. >>> torch.unflatten(torch.randn(3, 4, 1), 1, (2, 2)).shape
  26123. torch.Size([3, 2, 2, 1])
  26124. >>> torch.unflatten(torch.randn(3, 4, 1), 1, (-1, 2)).shape
  26125. torch.Size([3, 2, 2, 1])
  26126. >>> torch.unflatten(torch.randn(5, 12, 3), -2, (2, 2, 3, 1, 1)).shape
  26127. torch.Size([5, 2, 2, 3, 1, 1, 3])
  26128. """
  26129. def unfold_copy(
  26130. input: Tensor,
  26131. dimension: _int,
  26132. size: _int,
  26133. step: _int,
  26134. *,
  26135. out: Tensor | None = None,
  26136. ) -> Tensor:
  26137. r"""
  26138. Performs the same operation as :func:`torch.unfold`, but all output tensors
  26139. are freshly created instead of aliasing the input.
  26140. """
  26141. def unique_dim(
  26142. input: Tensor,
  26143. dim: _int,
  26144. sorted: _bool = True,
  26145. return_inverse: _bool = False,
  26146. return_counts: _bool = False,
  26147. ) -> tuple[Tensor, Tensor, Tensor]: ...
  26148. def unsafe_chunk(
  26149. input: Tensor,
  26150. chunks: _int,
  26151. dim: _int = 0,
  26152. ) -> tuple[Tensor, ...]:
  26153. r"""
  26154. unsafe_chunk(input, chunks, dim=0) -> List of Tensors
  26155. Works like :func:`torch.chunk` but without enforcing the autograd restrictions
  26156. on inplace modification of the outputs.
  26157. .. warning::
  26158. This function is safe to use as long as only the input, or only the outputs
  26159. are modified inplace after calling this function. It is user's
  26160. responsibility to ensure that is the case. If both the input and one or more
  26161. of the outputs are modified inplace, gradients computed by autograd will be
  26162. silently incorrect.
  26163. """
  26164. def unsafe_split(
  26165. input: Tensor,
  26166. split_size: _int | SymInt,
  26167. dim: _int = 0,
  26168. ) -> tuple[Tensor, ...]:
  26169. r"""
  26170. unsafe_split(tensor, split_size_or_sections, dim=0) -> List of Tensors
  26171. Works like :func:`torch.split` but without enforcing the autograd restrictions
  26172. on inplace modification of the outputs.
  26173. .. warning::
  26174. This function is safe to use as long as only the input, or only the outputs
  26175. are modified inplace after calling this function. It is user's
  26176. responsibility to ensure that is the case. If both the input and one or more
  26177. of the outputs are modified inplace, gradients computed by autograd will be
  26178. silently incorrect.
  26179. """
  26180. def unsafe_split_with_sizes(
  26181. input: Tensor,
  26182. split_sizes: Sequence[_int | SymInt],
  26183. dim: _int = 0,
  26184. ) -> tuple[Tensor, ...]: ...
  26185. def unsqueeze(input: Tensor, dim: _int) -> Tensor:
  26186. r"""
  26187. unsqueeze(input, dim) -> Tensor
  26188. Returns a new tensor with a dimension of size one inserted at the
  26189. specified position.
  26190. The returned tensor shares the same underlying data with this tensor.
  26191. A :attr:`dim` value within the range ``[-input.dim() - 1, input.dim() + 1)``
  26192. can be used. Negative :attr:`dim` will correspond to :meth:`unsqueeze`
  26193. applied at :attr:`dim` = ``dim + input.dim() + 1``.
  26194. Args:
  26195. input (Tensor): the input tensor.
  26196. dim (int): the index at which to insert the singleton dimension
  26197. Example::
  26198. >>> x = torch.tensor([1, 2, 3, 4])
  26199. >>> torch.unsqueeze(x, 0)
  26200. tensor([[ 1, 2, 3, 4]])
  26201. >>> torch.unsqueeze(x, 1)
  26202. tensor([[ 1],
  26203. [ 2],
  26204. [ 3],
  26205. [ 4]])
  26206. """
  26207. def unsqueeze_copy(
  26208. input: Tensor,
  26209. dim: _int,
  26210. *,
  26211. out: Tensor | None = None,
  26212. ) -> Tensor:
  26213. r"""
  26214. Performs the same operation as :func:`torch.unsqueeze`, but all output tensors
  26215. are freshly created instead of aliasing the input.
  26216. """
  26217. def values_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  26218. r"""
  26219. Performs the same operation as :func:`torch.values`, but all output tensors
  26220. are freshly created instead of aliasing the input.
  26221. """
  26222. def vander(
  26223. x: Tensor,
  26224. N: _int | None = None,
  26225. increasing: _bool = False,
  26226. ) -> Tensor:
  26227. r"""
  26228. vander(x, N=None, increasing=False) -> Tensor
  26229. Generates a Vandermonde matrix.
  26230. The columns of the output matrix are elementwise powers of the input vector :math:`x^{(N-1)}, x^{(N-2)}, ..., x^0`.
  26231. If increasing is True, the order of the columns is reversed :math:`x^0, x^1, ..., x^{(N-1)}`. Such a
  26232. matrix with a geometric progression in each row is named for Alexandre-Theophile Vandermonde.
  26233. Arguments:
  26234. x (Tensor): 1-D input tensor.
  26235. N (int, optional): Number of columns in the output. If N is not specified,
  26236. a square array is returned :math:`(N = len(x))`.
  26237. increasing (bool, optional): Order of the powers of the columns. If True,
  26238. the powers increase from left to right, if False (the default) they are reversed.
  26239. Returns:
  26240. Tensor: Vandermonde matrix. If increasing is False, the first column is :math:`x^{(N-1)}`,
  26241. the second :math:`x^{(N-2)}` and so forth. If increasing is True, the columns
  26242. are :math:`x^0, x^1, ..., x^{(N-1)}`.
  26243. Example::
  26244. >>> x = torch.tensor([1, 2, 3, 5])
  26245. >>> torch.vander(x)
  26246. tensor([[ 1, 1, 1, 1],
  26247. [ 8, 4, 2, 1],
  26248. [ 27, 9, 3, 1],
  26249. [125, 25, 5, 1]])
  26250. >>> torch.vander(x, N=3)
  26251. tensor([[ 1, 1, 1],
  26252. [ 4, 2, 1],
  26253. [ 9, 3, 1],
  26254. [25, 5, 1]])
  26255. >>> torch.vander(x, N=3, increasing=True)
  26256. tensor([[ 1, 1, 1],
  26257. [ 1, 2, 4],
  26258. [ 1, 3, 9],
  26259. [ 1, 5, 25]])
  26260. """
  26261. @overload
  26262. def var(
  26263. input: Tensor,
  26264. dim: _int | _size | None,
  26265. unbiased: _bool = True,
  26266. keepdim: _bool = False,
  26267. *,
  26268. out: Tensor | None = None,
  26269. ) -> Tensor:
  26270. r"""
  26271. var(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  26272. Calculates the variance over the dimensions specified by :attr:`dim`. :attr:`dim`
  26273. can be a single dimension, list of dimensions, or ``None`` to reduce over all
  26274. dimensions.
  26275. The variance (:math:`\sigma^2`) is calculated as
  26276. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26277. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26278. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26279. the :attr:`correction`.
  26280. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26281. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26282. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26283. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26284. Args:
  26285. input (Tensor): the input tensor.
  26286. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26287. If ``None``, all dimensions are reduced.
  26288. Keyword args:
  26289. correction (int): difference between the sample size and sample degrees of freedom.
  26290. Defaults to `Bessel's correction`_, ``correction=1``.
  26291. .. versionchanged:: 2.0
  26292. Previously this argument was called ``unbiased`` and was a boolean
  26293. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26294. ``correction=0``.
  26295. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26296. out (Tensor, optional): the output tensor.
  26297. Example:
  26298. >>> a = torch.tensor(
  26299. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26300. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26301. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26302. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26303. ... ) # fmt: skip
  26304. >>> torch.var(a, dim=1, keepdim=True)
  26305. tensor([[1.0631],
  26306. [0.5590],
  26307. [1.4893],
  26308. [0.8258]])
  26309. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26310. """
  26311. @overload
  26312. def var(
  26313. input: Tensor,
  26314. dim: _int | _size | None = None,
  26315. *,
  26316. correction: Number | _complex | None = None,
  26317. keepdim: _bool = False,
  26318. out: Tensor | None = None,
  26319. ) -> Tensor:
  26320. r"""
  26321. var(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  26322. Calculates the variance over the dimensions specified by :attr:`dim`. :attr:`dim`
  26323. can be a single dimension, list of dimensions, or ``None`` to reduce over all
  26324. dimensions.
  26325. The variance (:math:`\sigma^2`) is calculated as
  26326. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26327. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26328. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26329. the :attr:`correction`.
  26330. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26331. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26332. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26333. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26334. Args:
  26335. input (Tensor): the input tensor.
  26336. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26337. If ``None``, all dimensions are reduced.
  26338. Keyword args:
  26339. correction (int): difference between the sample size and sample degrees of freedom.
  26340. Defaults to `Bessel's correction`_, ``correction=1``.
  26341. .. versionchanged:: 2.0
  26342. Previously this argument was called ``unbiased`` and was a boolean
  26343. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26344. ``correction=0``.
  26345. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26346. out (Tensor, optional): the output tensor.
  26347. Example:
  26348. >>> a = torch.tensor(
  26349. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26350. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26351. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26352. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26353. ... ) # fmt: skip
  26354. >>> torch.var(a, dim=1, keepdim=True)
  26355. tensor([[1.0631],
  26356. [0.5590],
  26357. [1.4893],
  26358. [0.8258]])
  26359. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26360. """
  26361. @overload
  26362. def var(input: Tensor, unbiased: _bool = True) -> Tensor:
  26363. r"""
  26364. var(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  26365. Calculates the variance over the dimensions specified by :attr:`dim`. :attr:`dim`
  26366. can be a single dimension, list of dimensions, or ``None`` to reduce over all
  26367. dimensions.
  26368. The variance (:math:`\sigma^2`) is calculated as
  26369. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26370. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26371. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26372. the :attr:`correction`.
  26373. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26374. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26375. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26376. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26377. Args:
  26378. input (Tensor): the input tensor.
  26379. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26380. If ``None``, all dimensions are reduced.
  26381. Keyword args:
  26382. correction (int): difference between the sample size and sample degrees of freedom.
  26383. Defaults to `Bessel's correction`_, ``correction=1``.
  26384. .. versionchanged:: 2.0
  26385. Previously this argument was called ``unbiased`` and was a boolean
  26386. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26387. ``correction=0``.
  26388. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26389. out (Tensor, optional): the output tensor.
  26390. Example:
  26391. >>> a = torch.tensor(
  26392. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26393. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26394. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26395. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26396. ... ) # fmt: skip
  26397. >>> torch.var(a, dim=1, keepdim=True)
  26398. tensor([[1.0631],
  26399. [0.5590],
  26400. [1.4893],
  26401. [0.8258]])
  26402. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26403. """
  26404. @overload
  26405. def var(
  26406. input: Tensor,
  26407. dim: Sequence[str | EllipsisType | None],
  26408. *,
  26409. correction: Number | _complex | None = None,
  26410. keepdim: _bool = False,
  26411. out: Tensor | None = None,
  26412. ) -> Tensor:
  26413. r"""
  26414. var(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  26415. Calculates the variance over the dimensions specified by :attr:`dim`. :attr:`dim`
  26416. can be a single dimension, list of dimensions, or ``None`` to reduce over all
  26417. dimensions.
  26418. The variance (:math:`\sigma^2`) is calculated as
  26419. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26420. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26421. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26422. the :attr:`correction`.
  26423. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26424. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26425. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26426. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26427. Args:
  26428. input (Tensor): the input tensor.
  26429. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26430. If ``None``, all dimensions are reduced.
  26431. Keyword args:
  26432. correction (int): difference between the sample size and sample degrees of freedom.
  26433. Defaults to `Bessel's correction`_, ``correction=1``.
  26434. .. versionchanged:: 2.0
  26435. Previously this argument was called ``unbiased`` and was a boolean
  26436. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26437. ``correction=0``.
  26438. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26439. out (Tensor, optional): the output tensor.
  26440. Example:
  26441. >>> a = torch.tensor(
  26442. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26443. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26444. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26445. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26446. ... ) # fmt: skip
  26447. >>> torch.var(a, dim=1, keepdim=True)
  26448. tensor([[1.0631],
  26449. [0.5590],
  26450. [1.4893],
  26451. [0.8258]])
  26452. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26453. """
  26454. @overload
  26455. def var(
  26456. input: Tensor,
  26457. dim: Sequence[str | EllipsisType | None],
  26458. unbiased: _bool = True,
  26459. keepdim: _bool = False,
  26460. *,
  26461. out: Tensor | None = None,
  26462. ) -> Tensor:
  26463. r"""
  26464. var(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  26465. Calculates the variance over the dimensions specified by :attr:`dim`. :attr:`dim`
  26466. can be a single dimension, list of dimensions, or ``None`` to reduce over all
  26467. dimensions.
  26468. The variance (:math:`\sigma^2`) is calculated as
  26469. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26470. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26471. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26472. the :attr:`correction`.
  26473. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26474. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26475. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26476. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26477. Args:
  26478. input (Tensor): the input tensor.
  26479. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26480. If ``None``, all dimensions are reduced.
  26481. Keyword args:
  26482. correction (int): difference between the sample size and sample degrees of freedom.
  26483. Defaults to `Bessel's correction`_, ``correction=1``.
  26484. .. versionchanged:: 2.0
  26485. Previously this argument was called ``unbiased`` and was a boolean
  26486. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26487. ``correction=0``.
  26488. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26489. out (Tensor, optional): the output tensor.
  26490. Example:
  26491. >>> a = torch.tensor(
  26492. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26493. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26494. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26495. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26496. ... ) # fmt: skip
  26497. >>> torch.var(a, dim=1, keepdim=True)
  26498. tensor([[1.0631],
  26499. [0.5590],
  26500. [1.4893],
  26501. [0.8258]])
  26502. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26503. """
  26504. @overload
  26505. def var_mean(
  26506. input: Tensor,
  26507. dim: _int | _size | None,
  26508. unbiased: _bool = True,
  26509. keepdim: _bool = False,
  26510. ) -> tuple[Tensor, Tensor]:
  26511. r"""
  26512. var_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  26513. Calculates the variance and mean over the dimensions specified by :attr:`dim`.
  26514. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  26515. reduce over all dimensions.
  26516. The variance (:math:`\sigma^2`) is calculated as
  26517. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26518. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26519. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26520. the :attr:`correction`.
  26521. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26522. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26523. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26524. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26525. Args:
  26526. input (Tensor): the input tensor.
  26527. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26528. If ``None``, all dimensions are reduced.
  26529. Keyword args:
  26530. correction (int): difference between the sample size and sample degrees of freedom.
  26531. Defaults to `Bessel's correction`_, ``correction=1``.
  26532. .. versionchanged:: 2.0
  26533. Previously this argument was called ``unbiased`` and was a boolean
  26534. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26535. ``correction=0``.
  26536. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26537. out (Tensor, optional): the output tensor.
  26538. Returns:
  26539. A tuple (var, mean) containing the variance and mean.
  26540. Example:
  26541. >>> a = torch.tensor(
  26542. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26543. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26544. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26545. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26546. ... ) # fmt: skip
  26547. >>> torch.var_mean(a, dim=0, keepdim=True)
  26548. (tensor([[1.5926, 1.0056, 1.2005, 0.3646]]),
  26549. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  26550. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26551. """
  26552. @overload
  26553. def var_mean(
  26554. input: Tensor,
  26555. dim: _int | _size | None = None,
  26556. *,
  26557. correction: Number | _complex | None = None,
  26558. keepdim: _bool = False,
  26559. ) -> tuple[Tensor, Tensor]:
  26560. r"""
  26561. var_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  26562. Calculates the variance and mean over the dimensions specified by :attr:`dim`.
  26563. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  26564. reduce over all dimensions.
  26565. The variance (:math:`\sigma^2`) is calculated as
  26566. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26567. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26568. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26569. the :attr:`correction`.
  26570. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26571. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26572. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26573. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26574. Args:
  26575. input (Tensor): the input tensor.
  26576. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26577. If ``None``, all dimensions are reduced.
  26578. Keyword args:
  26579. correction (int): difference between the sample size and sample degrees of freedom.
  26580. Defaults to `Bessel's correction`_, ``correction=1``.
  26581. .. versionchanged:: 2.0
  26582. Previously this argument was called ``unbiased`` and was a boolean
  26583. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26584. ``correction=0``.
  26585. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26586. out (Tensor, optional): the output tensor.
  26587. Returns:
  26588. A tuple (var, mean) containing the variance and mean.
  26589. Example:
  26590. >>> a = torch.tensor(
  26591. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26592. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26593. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26594. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26595. ... ) # fmt: skip
  26596. >>> torch.var_mean(a, dim=0, keepdim=True)
  26597. (tensor([[1.5926, 1.0056, 1.2005, 0.3646]]),
  26598. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  26599. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26600. """
  26601. @overload
  26602. def var_mean(
  26603. input: Tensor,
  26604. unbiased: _bool = True,
  26605. ) -> tuple[Tensor, Tensor]:
  26606. r"""
  26607. var_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  26608. Calculates the variance and mean over the dimensions specified by :attr:`dim`.
  26609. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  26610. reduce over all dimensions.
  26611. The variance (:math:`\sigma^2`) is calculated as
  26612. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26613. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26614. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26615. the :attr:`correction`.
  26616. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26617. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26618. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26619. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26620. Args:
  26621. input (Tensor): the input tensor.
  26622. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26623. If ``None``, all dimensions are reduced.
  26624. Keyword args:
  26625. correction (int): difference between the sample size and sample degrees of freedom.
  26626. Defaults to `Bessel's correction`_, ``correction=1``.
  26627. .. versionchanged:: 2.0
  26628. Previously this argument was called ``unbiased`` and was a boolean
  26629. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26630. ``correction=0``.
  26631. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26632. out (Tensor, optional): the output tensor.
  26633. Returns:
  26634. A tuple (var, mean) containing the variance and mean.
  26635. Example:
  26636. >>> a = torch.tensor(
  26637. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26638. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26639. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26640. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26641. ... ) # fmt: skip
  26642. >>> torch.var_mean(a, dim=0, keepdim=True)
  26643. (tensor([[1.5926, 1.0056, 1.2005, 0.3646]]),
  26644. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  26645. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26646. """
  26647. @overload
  26648. def var_mean(
  26649. input: Tensor,
  26650. dim: Sequence[str | EllipsisType | None],
  26651. *,
  26652. correction: Number | _complex | None = None,
  26653. keepdim: _bool = False,
  26654. ) -> tuple[Tensor, Tensor]:
  26655. r"""
  26656. var_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  26657. Calculates the variance and mean over the dimensions specified by :attr:`dim`.
  26658. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  26659. reduce over all dimensions.
  26660. The variance (:math:`\sigma^2`) is calculated as
  26661. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26662. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26663. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26664. the :attr:`correction`.
  26665. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26666. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26667. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26668. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26669. Args:
  26670. input (Tensor): the input tensor.
  26671. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26672. If ``None``, all dimensions are reduced.
  26673. Keyword args:
  26674. correction (int): difference between the sample size and sample degrees of freedom.
  26675. Defaults to `Bessel's correction`_, ``correction=1``.
  26676. .. versionchanged:: 2.0
  26677. Previously this argument was called ``unbiased`` and was a boolean
  26678. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26679. ``correction=0``.
  26680. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26681. out (Tensor, optional): the output tensor.
  26682. Returns:
  26683. A tuple (var, mean) containing the variance and mean.
  26684. Example:
  26685. >>> a = torch.tensor(
  26686. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26687. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26688. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26689. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26690. ... ) # fmt: skip
  26691. >>> torch.var_mean(a, dim=0, keepdim=True)
  26692. (tensor([[1.5926, 1.0056, 1.2005, 0.3646]]),
  26693. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  26694. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26695. """
  26696. @overload
  26697. def var_mean(
  26698. input: Tensor,
  26699. dim: Sequence[str | EllipsisType | None],
  26700. unbiased: _bool = True,
  26701. keepdim: _bool = False,
  26702. ) -> tuple[Tensor, Tensor]:
  26703. r"""
  26704. var_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  26705. Calculates the variance and mean over the dimensions specified by :attr:`dim`.
  26706. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  26707. reduce over all dimensions.
  26708. The variance (:math:`\sigma^2`) is calculated as
  26709. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26710. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26711. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26712. the :attr:`correction`.
  26713. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26714. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26715. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26716. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26717. Args:
  26718. input (Tensor): the input tensor.
  26719. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26720. If ``None``, all dimensions are reduced.
  26721. Keyword args:
  26722. correction (int): difference between the sample size and sample degrees of freedom.
  26723. Defaults to `Bessel's correction`_, ``correction=1``.
  26724. .. versionchanged:: 2.0
  26725. Previously this argument was called ``unbiased`` and was a boolean
  26726. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26727. ``correction=0``.
  26728. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26729. out (Tensor, optional): the output tensor.
  26730. Returns:
  26731. A tuple (var, mean) containing the variance and mean.
  26732. Example:
  26733. >>> a = torch.tensor(
  26734. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26735. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26736. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26737. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26738. ... ) # fmt: skip
  26739. >>> torch.var_mean(a, dim=0, keepdim=True)
  26740. (tensor([[1.5926, 1.0056, 1.2005, 0.3646]]),
  26741. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  26742. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26743. """
  26744. def vdot(
  26745. input: Tensor,
  26746. other: Tensor,
  26747. *,
  26748. out: Tensor | None = None,
  26749. ) -> Tensor:
  26750. r"""
  26751. vdot(input, other, *, out=None) -> Tensor
  26752. Computes the dot product of two 1D vectors along a dimension.
  26753. In symbols, this function computes
  26754. .. math::
  26755. \sum_{i=1}^n \overline{x_i}y_i.
  26756. where :math:`\overline{x_i}` denotes the conjugate for complex
  26757. vectors, and it is the identity for real vectors.
  26758. .. note::
  26759. Unlike NumPy's vdot, torch.vdot intentionally only supports computing the dot product
  26760. of two 1D tensors with the same number of elements.
  26761. .. seealso::
  26762. :func:`torch.linalg.vecdot` computes the dot product of two batches of vectors along a dimension.
  26763. Args:
  26764. input (Tensor): first tensor in the dot product, must be 1D. Its conjugate is used if it's complex.
  26765. other (Tensor): second tensor in the dot product, must be 1D.
  26766. Keyword args:
  26767. .. note:: out (Tensor, optional): the output tensor.
  26768. Example::
  26769. >>> torch.vdot(torch.tensor([2, 3]), torch.tensor([2, 1]))
  26770. tensor(7)
  26771. >>> a = torch.tensor((1 +2j, 3 - 1j))
  26772. >>> b = torch.tensor((2 +1j, 4 - 0j))
  26773. >>> torch.vdot(a, b)
  26774. tensor([16.+1.j])
  26775. >>> torch.vdot(b, a)
  26776. tensor([16.-1.j])
  26777. """
  26778. def view_as_complex(input: Tensor) -> Tensor:
  26779. r"""
  26780. view_as_complex(input) -> Tensor
  26781. Returns a view of :attr:`input` as a complex tensor. For an input complex
  26782. tensor of :attr:`size` :math:`m1, m2, \dots, mi, 2`, this function returns a
  26783. new complex tensor of :attr:`size` :math:`m1, m2, \dots, mi` where the last
  26784. dimension of the input tensor is expected to represent the real and imaginary
  26785. components of complex numbers.
  26786. .. warning::
  26787. :func:`view_as_complex` is only supported for tensors with
  26788. :class:`torch.dtype` ``torch.float64`` and ``torch.float32``. The input is
  26789. expected to have the last dimension of :attr:`size` 2. In addition, the
  26790. tensor must have a `stride` of 1 for its last dimension. The strides of all
  26791. other dimensions must be even numbers.
  26792. Args:
  26793. input (Tensor): the input tensor.
  26794. Example::
  26795. >>> x=torch.randn(4, 2)
  26796. >>> x
  26797. tensor([[ 1.6116, -0.5772],
  26798. [-1.4606, -0.9120],
  26799. [ 0.0786, -1.7497],
  26800. [-0.6561, -1.6623]])
  26801. >>> torch.view_as_complex(x)
  26802. tensor([(1.6116-0.5772j), (-1.4606-0.9120j), (0.0786-1.7497j), (-0.6561-1.6623j)])
  26803. """
  26804. def view_as_complex_copy(
  26805. input: Tensor,
  26806. *,
  26807. out: Tensor | None = None,
  26808. ) -> Tensor:
  26809. r"""
  26810. Performs the same operation as :func:`torch.view_as_complex`, but all output tensors
  26811. are freshly created instead of aliasing the input.
  26812. """
  26813. def view_as_real(input: Tensor) -> Tensor:
  26814. r"""
  26815. view_as_real(input) -> Tensor
  26816. Returns a view of :attr:`input` as a real tensor. For an input complex tensor of
  26817. :attr:`size` :math:`m1, m2, \dots, mi`, this function returns a new
  26818. real tensor of size :math:`m1, m2, \dots, mi, 2`, where the last dimension of size 2
  26819. represents the real and imaginary components of complex numbers.
  26820. .. warning::
  26821. :func:`view_as_real` is only supported for tensors with ``complex dtypes``.
  26822. Args:
  26823. input (Tensor): the input tensor.
  26824. Example::
  26825. >>> x=torch.randn(4, dtype=torch.cfloat)
  26826. >>> x
  26827. tensor([(0.4737-0.3839j), (-0.2098-0.6699j), (0.3470-0.9451j), (-0.5174-1.3136j)])
  26828. >>> torch.view_as_real(x)
  26829. tensor([[ 0.4737, -0.3839],
  26830. [-0.2098, -0.6699],
  26831. [ 0.3470, -0.9451],
  26832. [-0.5174, -1.3136]])
  26833. """
  26834. def view_as_real_copy(
  26835. input: Tensor,
  26836. *,
  26837. out: Tensor | None = None,
  26838. ) -> Tensor:
  26839. r"""
  26840. Performs the same operation as :func:`torch.view_as_real`, but all output tensors
  26841. are freshly created instead of aliasing the input.
  26842. """
  26843. @overload
  26844. def view_copy(
  26845. input: Tensor,
  26846. dtype: _dtype,
  26847. *,
  26848. out: Tensor | None = None,
  26849. ) -> Tensor:
  26850. r"""
  26851. Performs the same operation as :func:`torch.view`, but all output tensors
  26852. are freshly created instead of aliasing the input.
  26853. """
  26854. @overload
  26855. def view_copy(
  26856. input: Tensor,
  26857. size: Sequence[_int | SymInt],
  26858. *,
  26859. out: Tensor | None = None,
  26860. ) -> Tensor:
  26861. r"""
  26862. Performs the same operation as :func:`torch.view`, but all output tensors
  26863. are freshly created instead of aliasing the input.
  26864. """
  26865. @overload
  26866. def vsplit(input: Tensor, sections: _int) -> tuple[Tensor, ...]:
  26867. r"""
  26868. vsplit(input, indices_or_sections) -> List of Tensors
  26869. Splits :attr:`input`, a tensor with two or more dimensions, into multiple tensors
  26870. vertically according to :attr:`indices_or_sections`. Each split is a view of
  26871. :attr:`input`.
  26872. This is equivalent to calling torch.tensor_split(input, indices_or_sections, dim=0)
  26873. (the split dimension is 0), except that if :attr:`indices_or_sections` is an integer
  26874. it must evenly divide the split dimension or a runtime error will be thrown.
  26875. This function is based on NumPy's :func:`numpy.vsplit`.
  26876. Args:
  26877. input (Tensor): tensor to split.
  26878. indices_or_sections (int or list or tuple of ints): See argument in :func:`torch.tensor_split`.
  26879. Example::
  26880. >>> t = torch.arange(16.0).reshape(4,4)
  26881. >>> t
  26882. tensor([[ 0., 1., 2., 3.],
  26883. [ 4., 5., 6., 7.],
  26884. [ 8., 9., 10., 11.],
  26885. [12., 13., 14., 15.]])
  26886. >>> torch.vsplit(t, 2)
  26887. (tensor([[0., 1., 2., 3.],
  26888. [4., 5., 6., 7.]]),
  26889. tensor([[ 8., 9., 10., 11.],
  26890. [12., 13., 14., 15.]]))
  26891. >>> torch.vsplit(t, [3, 6])
  26892. (tensor([[ 0., 1., 2., 3.],
  26893. [ 4., 5., 6., 7.],
  26894. [ 8., 9., 10., 11.]]),
  26895. tensor([[12., 13., 14., 15.]]),
  26896. tensor([], size=(0, 4)))
  26897. """
  26898. @overload
  26899. def vsplit(input: Tensor, indices: _size) -> tuple[Tensor, ...]:
  26900. r"""
  26901. vsplit(input, indices_or_sections) -> List of Tensors
  26902. Splits :attr:`input`, a tensor with two or more dimensions, into multiple tensors
  26903. vertically according to :attr:`indices_or_sections`. Each split is a view of
  26904. :attr:`input`.
  26905. This is equivalent to calling torch.tensor_split(input, indices_or_sections, dim=0)
  26906. (the split dimension is 0), except that if :attr:`indices_or_sections` is an integer
  26907. it must evenly divide the split dimension or a runtime error will be thrown.
  26908. This function is based on NumPy's :func:`numpy.vsplit`.
  26909. Args:
  26910. input (Tensor): tensor to split.
  26911. indices_or_sections (int or list or tuple of ints): See argument in :func:`torch.tensor_split`.
  26912. Example::
  26913. >>> t = torch.arange(16.0).reshape(4,4)
  26914. >>> t
  26915. tensor([[ 0., 1., 2., 3.],
  26916. [ 4., 5., 6., 7.],
  26917. [ 8., 9., 10., 11.],
  26918. [12., 13., 14., 15.]])
  26919. >>> torch.vsplit(t, 2)
  26920. (tensor([[0., 1., 2., 3.],
  26921. [4., 5., 6., 7.]]),
  26922. tensor([[ 8., 9., 10., 11.],
  26923. [12., 13., 14., 15.]]))
  26924. >>> torch.vsplit(t, [3, 6])
  26925. (tensor([[ 0., 1., 2., 3.],
  26926. [ 4., 5., 6., 7.],
  26927. [ 8., 9., 10., 11.]]),
  26928. tensor([[12., 13., 14., 15.]]),
  26929. tensor([], size=(0, 4)))
  26930. """
  26931. def vstack(
  26932. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  26933. *,
  26934. out: Tensor | None = None,
  26935. ) -> Tensor:
  26936. r"""
  26937. vstack(tensors, *, out=None) -> Tensor
  26938. Stack tensors in sequence vertically (row wise).
  26939. This is equivalent to concatenation along the first axis after all 1-D tensors have been reshaped by :func:`torch.atleast_2d`.
  26940. Args:
  26941. tensors (sequence of Tensors): sequence of tensors to concatenate
  26942. Keyword args:
  26943. out (Tensor, optional): the output tensor.
  26944. Example::
  26945. >>> a = torch.tensor([1, 2, 3])
  26946. >>> b = torch.tensor([4, 5, 6])
  26947. >>> torch.vstack((a,b))
  26948. tensor([[1, 2, 3],
  26949. [4, 5, 6]])
  26950. >>> a = torch.tensor([[1],[2],[3]])
  26951. >>> b = torch.tensor([[4],[5],[6]])
  26952. >>> torch.vstack((a,b))
  26953. tensor([[1],
  26954. [2],
  26955. [3],
  26956. [4],
  26957. [5],
  26958. [6]])
  26959. """
  26960. @overload
  26961. def where(condition: Tensor) -> tuple[Tensor, ...]:
  26962. r"""
  26963. where(condition, input, other, *, out=None) -> Tensor
  26964. Return a tensor of elements selected from either :attr:`input` or :attr:`other`, depending on :attr:`condition`.
  26965. The operation is defined as:
  26966. .. math::
  26967. \text{out}_i = \begin{cases}
  26968. \text{input}_i & \text{if } \text{condition}_i \\
  26969. \text{other}_i & \text{otherwise} \\
  26970. \end{cases}
  26971. .. note::
  26972. The tensors :attr:`condition`, :attr:`input`, :attr:`other` must be :ref:`broadcastable <broadcasting-semantics>`.
  26973. Arguments:
  26974. condition (BoolTensor): When True (nonzero), yield input, otherwise yield other
  26975. input (Tensor or Scalar): value (if :attr:`input` is a scalar) or values selected at indices
  26976. where :attr:`condition` is ``True``
  26977. other (Tensor or Scalar): value (if :attr:`other` is a scalar) or values selected at indices
  26978. where :attr:`condition` is ``False``
  26979. Keyword args:
  26980. out (Tensor, optional): the output tensor.
  26981. Returns:
  26982. Tensor: A tensor of shape equal to the broadcasted shape of :attr:`condition`, :attr:`input`, :attr:`other`
  26983. Example::
  26984. >>> x = torch.randn(3, 2)
  26985. >>> y = torch.ones(3, 2)
  26986. >>> x
  26987. tensor([[-0.4620, 0.3139],
  26988. [ 0.3898, -0.7197],
  26989. [ 0.0478, -0.1657]])
  26990. >>> torch.where(x > 0, 1.0, 0.0)
  26991. tensor([[0., 1.],
  26992. [1., 0.],
  26993. [1., 0.]])
  26994. >>> torch.where(x > 0, x, y)
  26995. tensor([[ 1.0000, 0.3139],
  26996. [ 0.3898, 1.0000],
  26997. [ 0.0478, 1.0000]])
  26998. >>> x = torch.randn(2, 2, dtype=torch.double)
  26999. >>> x
  27000. tensor([[ 1.0779, 0.0383],
  27001. [-0.8785, -1.1089]], dtype=torch.float64)
  27002. >>> torch.where(x > 0, x, 0.)
  27003. tensor([[1.0779, 0.0383],
  27004. [0.0000, 0.0000]], dtype=torch.float64)
  27005. .. function:: where(condition) -> tuple of LongTensor
  27006. :noindex:
  27007. ``torch.where(condition)`` is identical to
  27008. ``torch.nonzero(condition, as_tuple=True)``.
  27009. .. note::
  27010. See also :func:`torch.nonzero`.
  27011. """
  27012. @overload
  27013. def where(
  27014. condition: Tensor,
  27015. input: Tensor,
  27016. other: Tensor,
  27017. *,
  27018. out: Tensor | None = None,
  27019. ) -> Tensor:
  27020. r"""
  27021. where(condition, input, other, *, out=None) -> Tensor
  27022. Return a tensor of elements selected from either :attr:`input` or :attr:`other`, depending on :attr:`condition`.
  27023. The operation is defined as:
  27024. .. math::
  27025. \text{out}_i = \begin{cases}
  27026. \text{input}_i & \text{if } \text{condition}_i \\
  27027. \text{other}_i & \text{otherwise} \\
  27028. \end{cases}
  27029. .. note::
  27030. The tensors :attr:`condition`, :attr:`input`, :attr:`other` must be :ref:`broadcastable <broadcasting-semantics>`.
  27031. Arguments:
  27032. condition (BoolTensor): When True (nonzero), yield input, otherwise yield other
  27033. input (Tensor or Scalar): value (if :attr:`input` is a scalar) or values selected at indices
  27034. where :attr:`condition` is ``True``
  27035. other (Tensor or Scalar): value (if :attr:`other` is a scalar) or values selected at indices
  27036. where :attr:`condition` is ``False``
  27037. Keyword args:
  27038. out (Tensor, optional): the output tensor.
  27039. Returns:
  27040. Tensor: A tensor of shape equal to the broadcasted shape of :attr:`condition`, :attr:`input`, :attr:`other`
  27041. Example::
  27042. >>> x = torch.randn(3, 2)
  27043. >>> y = torch.ones(3, 2)
  27044. >>> x
  27045. tensor([[-0.4620, 0.3139],
  27046. [ 0.3898, -0.7197],
  27047. [ 0.0478, -0.1657]])
  27048. >>> torch.where(x > 0, 1.0, 0.0)
  27049. tensor([[0., 1.],
  27050. [1., 0.],
  27051. [1., 0.]])
  27052. >>> torch.where(x > 0, x, y)
  27053. tensor([[ 1.0000, 0.3139],
  27054. [ 0.3898, 1.0000],
  27055. [ 0.0478, 1.0000]])
  27056. >>> x = torch.randn(2, 2, dtype=torch.double)
  27057. >>> x
  27058. tensor([[ 1.0779, 0.0383],
  27059. [-0.8785, -1.1089]], dtype=torch.float64)
  27060. >>> torch.where(x > 0, x, 0.)
  27061. tensor([[1.0779, 0.0383],
  27062. [0.0000, 0.0000]], dtype=torch.float64)
  27063. .. function:: where(condition) -> tuple of LongTensor
  27064. :noindex:
  27065. ``torch.where(condition)`` is identical to
  27066. ``torch.nonzero(condition, as_tuple=True)``.
  27067. .. note::
  27068. See also :func:`torch.nonzero`.
  27069. """
  27070. @overload
  27071. def where(
  27072. condition: Tensor,
  27073. self: Number | _complex,
  27074. other: Tensor,
  27075. ) -> Tensor:
  27076. r"""
  27077. where(condition, input, other, *, out=None) -> Tensor
  27078. Return a tensor of elements selected from either :attr:`input` or :attr:`other`, depending on :attr:`condition`.
  27079. The operation is defined as:
  27080. .. math::
  27081. \text{out}_i = \begin{cases}
  27082. \text{input}_i & \text{if } \text{condition}_i \\
  27083. \text{other}_i & \text{otherwise} \\
  27084. \end{cases}
  27085. .. note::
  27086. The tensors :attr:`condition`, :attr:`input`, :attr:`other` must be :ref:`broadcastable <broadcasting-semantics>`.
  27087. Arguments:
  27088. condition (BoolTensor): When True (nonzero), yield input, otherwise yield other
  27089. input (Tensor or Scalar): value (if :attr:`input` is a scalar) or values selected at indices
  27090. where :attr:`condition` is ``True``
  27091. other (Tensor or Scalar): value (if :attr:`other` is a scalar) or values selected at indices
  27092. where :attr:`condition` is ``False``
  27093. Keyword args:
  27094. out (Tensor, optional): the output tensor.
  27095. Returns:
  27096. Tensor: A tensor of shape equal to the broadcasted shape of :attr:`condition`, :attr:`input`, :attr:`other`
  27097. Example::
  27098. >>> x = torch.randn(3, 2)
  27099. >>> y = torch.ones(3, 2)
  27100. >>> x
  27101. tensor([[-0.4620, 0.3139],
  27102. [ 0.3898, -0.7197],
  27103. [ 0.0478, -0.1657]])
  27104. >>> torch.where(x > 0, 1.0, 0.0)
  27105. tensor([[0., 1.],
  27106. [1., 0.],
  27107. [1., 0.]])
  27108. >>> torch.where(x > 0, x, y)
  27109. tensor([[ 1.0000, 0.3139],
  27110. [ 0.3898, 1.0000],
  27111. [ 0.0478, 1.0000]])
  27112. >>> x = torch.randn(2, 2, dtype=torch.double)
  27113. >>> x
  27114. tensor([[ 1.0779, 0.0383],
  27115. [-0.8785, -1.1089]], dtype=torch.float64)
  27116. >>> torch.where(x > 0, x, 0.)
  27117. tensor([[1.0779, 0.0383],
  27118. [0.0000, 0.0000]], dtype=torch.float64)
  27119. .. function:: where(condition) -> tuple of LongTensor
  27120. :noindex:
  27121. ``torch.where(condition)`` is identical to
  27122. ``torch.nonzero(condition, as_tuple=True)``.
  27123. .. note::
  27124. See also :func:`torch.nonzero`.
  27125. """
  27126. @overload
  27127. def where(
  27128. condition: Tensor,
  27129. input: Tensor,
  27130. other: Number | _complex,
  27131. ) -> Tensor:
  27132. r"""
  27133. where(condition, input, other, *, out=None) -> Tensor
  27134. Return a tensor of elements selected from either :attr:`input` or :attr:`other`, depending on :attr:`condition`.
  27135. The operation is defined as:
  27136. .. math::
  27137. \text{out}_i = \begin{cases}
  27138. \text{input}_i & \text{if } \text{condition}_i \\
  27139. \text{other}_i & \text{otherwise} \\
  27140. \end{cases}
  27141. .. note::
  27142. The tensors :attr:`condition`, :attr:`input`, :attr:`other` must be :ref:`broadcastable <broadcasting-semantics>`.
  27143. Arguments:
  27144. condition (BoolTensor): When True (nonzero), yield input, otherwise yield other
  27145. input (Tensor or Scalar): value (if :attr:`input` is a scalar) or values selected at indices
  27146. where :attr:`condition` is ``True``
  27147. other (Tensor or Scalar): value (if :attr:`other` is a scalar) or values selected at indices
  27148. where :attr:`condition` is ``False``
  27149. Keyword args:
  27150. out (Tensor, optional): the output tensor.
  27151. Returns:
  27152. Tensor: A tensor of shape equal to the broadcasted shape of :attr:`condition`, :attr:`input`, :attr:`other`
  27153. Example::
  27154. >>> x = torch.randn(3, 2)
  27155. >>> y = torch.ones(3, 2)
  27156. >>> x
  27157. tensor([[-0.4620, 0.3139],
  27158. [ 0.3898, -0.7197],
  27159. [ 0.0478, -0.1657]])
  27160. >>> torch.where(x > 0, 1.0, 0.0)
  27161. tensor([[0., 1.],
  27162. [1., 0.],
  27163. [1., 0.]])
  27164. >>> torch.where(x > 0, x, y)
  27165. tensor([[ 1.0000, 0.3139],
  27166. [ 0.3898, 1.0000],
  27167. [ 0.0478, 1.0000]])
  27168. >>> x = torch.randn(2, 2, dtype=torch.double)
  27169. >>> x
  27170. tensor([[ 1.0779, 0.0383],
  27171. [-0.8785, -1.1089]], dtype=torch.float64)
  27172. >>> torch.where(x > 0, x, 0.)
  27173. tensor([[1.0779, 0.0383],
  27174. [0.0000, 0.0000]], dtype=torch.float64)
  27175. .. function:: where(condition) -> tuple of LongTensor
  27176. :noindex:
  27177. ``torch.where(condition)`` is identical to
  27178. ``torch.nonzero(condition, as_tuple=True)``.
  27179. .. note::
  27180. See also :func:`torch.nonzero`.
  27181. """
  27182. @overload
  27183. def where(
  27184. condition: Tensor,
  27185. self: Number | _complex,
  27186. other: Number | _complex,
  27187. ) -> Tensor:
  27188. r"""
  27189. where(condition, input, other, *, out=None) -> Tensor
  27190. Return a tensor of elements selected from either :attr:`input` or :attr:`other`, depending on :attr:`condition`.
  27191. The operation is defined as:
  27192. .. math::
  27193. \text{out}_i = \begin{cases}
  27194. \text{input}_i & \text{if } \text{condition}_i \\
  27195. \text{other}_i & \text{otherwise} \\
  27196. \end{cases}
  27197. .. note::
  27198. The tensors :attr:`condition`, :attr:`input`, :attr:`other` must be :ref:`broadcastable <broadcasting-semantics>`.
  27199. Arguments:
  27200. condition (BoolTensor): When True (nonzero), yield input, otherwise yield other
  27201. input (Tensor or Scalar): value (if :attr:`input` is a scalar) or values selected at indices
  27202. where :attr:`condition` is ``True``
  27203. other (Tensor or Scalar): value (if :attr:`other` is a scalar) or values selected at indices
  27204. where :attr:`condition` is ``False``
  27205. Keyword args:
  27206. out (Tensor, optional): the output tensor.
  27207. Returns:
  27208. Tensor: A tensor of shape equal to the broadcasted shape of :attr:`condition`, :attr:`input`, :attr:`other`
  27209. Example::
  27210. >>> x = torch.randn(3, 2)
  27211. >>> y = torch.ones(3, 2)
  27212. >>> x
  27213. tensor([[-0.4620, 0.3139],
  27214. [ 0.3898, -0.7197],
  27215. [ 0.0478, -0.1657]])
  27216. >>> torch.where(x > 0, 1.0, 0.0)
  27217. tensor([[0., 1.],
  27218. [1., 0.],
  27219. [1., 0.]])
  27220. >>> torch.where(x > 0, x, y)
  27221. tensor([[ 1.0000, 0.3139],
  27222. [ 0.3898, 1.0000],
  27223. [ 0.0478, 1.0000]])
  27224. >>> x = torch.randn(2, 2, dtype=torch.double)
  27225. >>> x
  27226. tensor([[ 1.0779, 0.0383],
  27227. [-0.8785, -1.1089]], dtype=torch.float64)
  27228. >>> torch.where(x > 0, x, 0.)
  27229. tensor([[1.0779, 0.0383],
  27230. [0.0000, 0.0000]], dtype=torch.float64)
  27231. .. function:: where(condition) -> tuple of LongTensor
  27232. :noindex:
  27233. ``torch.where(condition)`` is identical to
  27234. ``torch.nonzero(condition, as_tuple=True)``.
  27235. .. note::
  27236. See also :func:`torch.nonzero`.
  27237. """
  27238. @overload
  27239. def xlogy(
  27240. input: Tensor,
  27241. other: Tensor,
  27242. *,
  27243. out: Tensor | None = None,
  27244. ) -> Tensor:
  27245. r"""
  27246. xlogy(input, other, *, out=None) -> Tensor
  27247. Alias for :func:`torch.special.xlogy`.
  27248. """
  27249. @overload
  27250. def xlogy(
  27251. self: Number | _complex,
  27252. other: Tensor,
  27253. *,
  27254. out: Tensor | None = None,
  27255. ) -> Tensor:
  27256. r"""
  27257. xlogy(input, other, *, out=None) -> Tensor
  27258. Alias for :func:`torch.special.xlogy`.
  27259. """
  27260. @overload
  27261. def xlogy(
  27262. input: Tensor,
  27263. other: Number | _complex,
  27264. *,
  27265. out: Tensor | None = None,
  27266. ) -> Tensor:
  27267. r"""
  27268. xlogy(input, other, *, out=None) -> Tensor
  27269. Alias for :func:`torch.special.xlogy`.
  27270. """
  27271. @overload
  27272. def xlogy_(input: Tensor, other: Tensor) -> Tensor: ...
  27273. @overload
  27274. def xlogy_(input: Tensor, other: Number | _complex) -> Tensor: ...
  27275. def zero_(input: Tensor) -> Tensor: ...
  27276. @overload
  27277. def zeros(
  27278. size: Sequence[_int | SymInt],
  27279. *,
  27280. out: Tensor | None = None,
  27281. dtype: _dtype | None = None,
  27282. layout: _layout | None = None,
  27283. device: DeviceLikeType | None = None,
  27284. pin_memory: _bool | None = False,
  27285. requires_grad: _bool | None = False,
  27286. ) -> Tensor:
  27287. r"""
  27288. zeros(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  27289. Returns a tensor filled with the scalar value `0`, with the shape defined
  27290. by the variable argument :attr:`size`.
  27291. Args:
  27292. size (int...): a sequence of integers defining the shape of the output tensor.
  27293. Can be a variable number of arguments or a collection like a list or tuple.
  27294. Keyword args:
  27295. out (Tensor, optional): the output tensor.
  27296. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  27297. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  27298. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  27299. Default: ``torch.strided``.
  27300. device (:class:`torch.device`, optional): the desired device of returned tensor.
  27301. Default: if ``None``, uses the current device for the default tensor type
  27302. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  27303. for CPU tensor types and the current CUDA device for CUDA tensor types.
  27304. requires_grad (bool, optional): If autograd should record operations on the
  27305. returned tensor. Default: ``False``.
  27306. Example::
  27307. >>> torch.zeros(2, 3)
  27308. tensor([[ 0., 0., 0.],
  27309. [ 0., 0., 0.]])
  27310. >>> torch.zeros(5)
  27311. tensor([ 0., 0., 0., 0., 0.])
  27312. """
  27313. @overload
  27314. def zeros(
  27315. *size: _int | SymInt,
  27316. out: Tensor | None = None,
  27317. dtype: _dtype | None = None,
  27318. layout: _layout | None = None,
  27319. device: DeviceLikeType | None = None,
  27320. pin_memory: _bool | None = False,
  27321. requires_grad: _bool | None = False,
  27322. ) -> Tensor:
  27323. r"""
  27324. zeros(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  27325. Returns a tensor filled with the scalar value `0`, with the shape defined
  27326. by the variable argument :attr:`size`.
  27327. Args:
  27328. size (int...): a sequence of integers defining the shape of the output tensor.
  27329. Can be a variable number of arguments or a collection like a list or tuple.
  27330. Keyword args:
  27331. out (Tensor, optional): the output tensor.
  27332. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  27333. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  27334. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  27335. Default: ``torch.strided``.
  27336. device (:class:`torch.device`, optional): the desired device of returned tensor.
  27337. Default: if ``None``, uses the current device for the default tensor type
  27338. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  27339. for CPU tensor types and the current CUDA device for CUDA tensor types.
  27340. requires_grad (bool, optional): If autograd should record operations on the
  27341. returned tensor. Default: ``False``.
  27342. Example::
  27343. >>> torch.zeros(2, 3)
  27344. tensor([[ 0., 0., 0.],
  27345. [ 0., 0., 0.]])
  27346. >>> torch.zeros(5)
  27347. tensor([ 0., 0., 0., 0., 0.])
  27348. """
  27349. @overload
  27350. def zeros(
  27351. size: _size,
  27352. *,
  27353. names: Sequence[str | EllipsisType | None] | None,
  27354. dtype: _dtype | None = None,
  27355. layout: _layout | None = None,
  27356. device: DeviceLikeType | None = None,
  27357. pin_memory: _bool | None = False,
  27358. requires_grad: _bool | None = False,
  27359. ) -> Tensor:
  27360. r"""
  27361. zeros(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  27362. Returns a tensor filled with the scalar value `0`, with the shape defined
  27363. by the variable argument :attr:`size`.
  27364. Args:
  27365. size (int...): a sequence of integers defining the shape of the output tensor.
  27366. Can be a variable number of arguments or a collection like a list or tuple.
  27367. Keyword args:
  27368. out (Tensor, optional): the output tensor.
  27369. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  27370. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  27371. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  27372. Default: ``torch.strided``.
  27373. device (:class:`torch.device`, optional): the desired device of returned tensor.
  27374. Default: if ``None``, uses the current device for the default tensor type
  27375. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  27376. for CPU tensor types and the current CUDA device for CUDA tensor types.
  27377. requires_grad (bool, optional): If autograd should record operations on the
  27378. returned tensor. Default: ``False``.
  27379. Example::
  27380. >>> torch.zeros(2, 3)
  27381. tensor([[ 0., 0., 0.],
  27382. [ 0., 0., 0.]])
  27383. >>> torch.zeros(5)
  27384. tensor([ 0., 0., 0., 0., 0.])
  27385. """
  27386. @overload
  27387. def zeros(
  27388. *size: _int,
  27389. names: Sequence[str | EllipsisType | None] | None,
  27390. dtype: _dtype | None = None,
  27391. layout: _layout | None = None,
  27392. device: DeviceLikeType | None = None,
  27393. pin_memory: _bool | None = False,
  27394. requires_grad: _bool | None = False,
  27395. ) -> Tensor:
  27396. r"""
  27397. zeros(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  27398. Returns a tensor filled with the scalar value `0`, with the shape defined
  27399. by the variable argument :attr:`size`.
  27400. Args:
  27401. size (int...): a sequence of integers defining the shape of the output tensor.
  27402. Can be a variable number of arguments or a collection like a list or tuple.
  27403. Keyword args:
  27404. out (Tensor, optional): the output tensor.
  27405. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  27406. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  27407. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  27408. Default: ``torch.strided``.
  27409. device (:class:`torch.device`, optional): the desired device of returned tensor.
  27410. Default: if ``None``, uses the current device for the default tensor type
  27411. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  27412. for CPU tensor types and the current CUDA device for CUDA tensor types.
  27413. requires_grad (bool, optional): If autograd should record operations on the
  27414. returned tensor. Default: ``False``.
  27415. Example::
  27416. >>> torch.zeros(2, 3)
  27417. tensor([[ 0., 0., 0.],
  27418. [ 0., 0., 0.]])
  27419. >>> torch.zeros(5)
  27420. tensor([ 0., 0., 0., 0., 0.])
  27421. """
  27422. def zeros_like(
  27423. input: Tensor,
  27424. *,
  27425. memory_format: memory_format | None = None,
  27426. dtype: _dtype | None = None,
  27427. layout: _layout | None = None,
  27428. device: DeviceLikeType | None = None,
  27429. pin_memory: _bool | None = False,
  27430. requires_grad: _bool | None = False,
  27431. ) -> Tensor:
  27432. r"""
  27433. zeros_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  27434. Returns a tensor filled with the scalar value `0`, with the same size as
  27435. :attr:`input`. ``torch.zeros_like(input)`` is equivalent to
  27436. ``torch.zeros(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
  27437. .. warning::
  27438. As of 0.4, this function does not support an :attr:`out` keyword. As an alternative,
  27439. the old ``torch.zeros_like(input, out=output)`` is equivalent to
  27440. ``torch.zeros(input.size(), out=output)``.
  27441. Args:
  27442. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  27443. Keyword args:
  27444. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  27445. Default: if ``None``, defaults to the dtype of :attr:`input`.
  27446. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  27447. Default: if ``None``, defaults to the layout of :attr:`input`.
  27448. device (:class:`torch.device`, optional): the desired device of returned tensor.
  27449. Default: if ``None``, defaults to the device of :attr:`input`.
  27450. requires_grad (bool, optional): If autograd should record operations on the
  27451. returned tensor. Default: ``False``.
  27452. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  27453. returned Tensor. Default: ``torch.preserve_format``.
  27454. Example::
  27455. >>> input = torch.empty(2, 3)
  27456. >>> torch.zeros_like(input)
  27457. tensor([[ 0., 0., 0.],
  27458. [ 0., 0., 0.]])
  27459. """