_VF.pyi 1.2 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783
  1. # @generated by tools/pyi/gen_pyi.py from torch/_C/_VariableFunctions.pyi.in
  2. # mypy: disable-error-code="type-arg"
  3. # mypy: allow-untyped-defs
  4. # ruff: noqa: F401,PYI054
  5. from collections.abc import Callable, Sequence
  6. from types import EllipsisType
  7. from typing import Any, Literal, overload, TypeVar
  8. import torch
  9. from torch import (
  10. contiguous_format,
  11. Generator,
  12. inf,
  13. memory_format,
  14. strided,
  15. SymInt,
  16. Tensor,
  17. )
  18. from torch._prims_common import DeviceLikeType
  19. from torch.types import (
  20. _bool,
  21. _complex,
  22. _device,
  23. _dtype,
  24. _float,
  25. _int,
  26. _layout,
  27. _qscheme,
  28. _size,
  29. Device,
  30. Number,
  31. )
  32. __all__ = [
  33. "__and__",
  34. "__lshift__",
  35. "__or__",
  36. "__rshift__",
  37. "__xor__",
  38. "_adaptive_avg_pool2d",
  39. "_adaptive_avg_pool3d",
  40. "_add_batch_dim",
  41. "_add_relu",
  42. "_add_relu_",
  43. "_addmm_activation",
  44. "_aminmax",
  45. "_amp_foreach_non_finite_check_and_unscale_",
  46. "_amp_update_scale_",
  47. "_assert_async",
  48. "_assert_scalar",
  49. "_assert_tensor_metadata",
  50. "_batch_norm_impl_index",
  51. "_cast_Byte",
  52. "_cast_Char",
  53. "_cast_Double",
  54. "_cast_Float",
  55. "_cast_Half",
  56. "_cast_Int",
  57. "_cast_Long",
  58. "_cast_Short",
  59. "_choose_qparams_per_tensor",
  60. "_chunk_cat",
  61. "_coalesce",
  62. "_compute_linear_combination",
  63. "_conj",
  64. "_conj_copy",
  65. "_conj_physical",
  66. "_convert_indices_from_coo_to_csr",
  67. "_convert_indices_from_csr_to_coo",
  68. "_convert_weight_to_int4pack",
  69. "_convert_weight_to_int4pack_for_cpu",
  70. "_convolution",
  71. "_convolution_mode",
  72. "_copy_from",
  73. "_copy_from_and_resize",
  74. "_cslt_compress",
  75. "_cslt_sparse_mm",
  76. "_cslt_sparse_mm_search",
  77. "_ctc_loss",
  78. "_cudnn_ctc_loss",
  79. "_cudnn_init_dropout_state",
  80. "_cudnn_rnn",
  81. "_cudnn_rnn_flatten_weight",
  82. "_cufft_clear_plan_cache",
  83. "_cufft_get_plan_cache_max_size",
  84. "_cufft_get_plan_cache_size",
  85. "_cufft_set_plan_cache_max_size",
  86. "_cummax_helper",
  87. "_cummin_helper",
  88. "_debug_has_internal_overlap",
  89. "_dim_arange",
  90. "_dirichlet_grad",
  91. "_disable_functionalization",
  92. "_dyn_quant_matmul_4bit",
  93. "_dyn_quant_pack_4bit_weight",
  94. "_efficientzerotensor",
  95. "_embedding_bag",
  96. "_embedding_bag_forward_only",
  97. "_empty_affine_quantized",
  98. "_empty_per_channel_affine_quantized",
  99. "_enable_functionalization",
  100. "_euclidean_dist",
  101. "_fake_quantize_learnable_per_channel_affine",
  102. "_fake_quantize_learnable_per_tensor_affine",
  103. "_fake_quantize_per_tensor_affine_cachemask_tensor_qparams",
  104. "_fft_c2c",
  105. "_fft_c2r",
  106. "_fft_r2c",
  107. "_fill_mem_eff_dropout_mask_",
  108. "_foobar",
  109. "_foreach_abs",
  110. "_foreach_abs_",
  111. "_foreach_acos",
  112. "_foreach_acos_",
  113. "_foreach_add",
  114. "_foreach_add_",
  115. "_foreach_addcdiv",
  116. "_foreach_addcdiv_",
  117. "_foreach_addcmul",
  118. "_foreach_addcmul_",
  119. "_foreach_asin",
  120. "_foreach_asin_",
  121. "_foreach_atan",
  122. "_foreach_atan_",
  123. "_foreach_ceil",
  124. "_foreach_ceil_",
  125. "_foreach_clamp_max",
  126. "_foreach_clamp_max_",
  127. "_foreach_clamp_min",
  128. "_foreach_clamp_min_",
  129. "_foreach_copy_",
  130. "_foreach_cos",
  131. "_foreach_cos_",
  132. "_foreach_cosh",
  133. "_foreach_cosh_",
  134. "_foreach_div",
  135. "_foreach_div_",
  136. "_foreach_erf",
  137. "_foreach_erf_",
  138. "_foreach_erfc",
  139. "_foreach_erfc_",
  140. "_foreach_exp",
  141. "_foreach_exp_",
  142. "_foreach_expm1",
  143. "_foreach_expm1_",
  144. "_foreach_floor",
  145. "_foreach_floor_",
  146. "_foreach_frac",
  147. "_foreach_frac_",
  148. "_foreach_lerp",
  149. "_foreach_lerp_",
  150. "_foreach_lgamma",
  151. "_foreach_lgamma_",
  152. "_foreach_log",
  153. "_foreach_log10",
  154. "_foreach_log10_",
  155. "_foreach_log1p",
  156. "_foreach_log1p_",
  157. "_foreach_log2",
  158. "_foreach_log2_",
  159. "_foreach_log_",
  160. "_foreach_max",
  161. "_foreach_maximum",
  162. "_foreach_maximum_",
  163. "_foreach_minimum",
  164. "_foreach_minimum_",
  165. "_foreach_mul",
  166. "_foreach_mul_",
  167. "_foreach_neg",
  168. "_foreach_neg_",
  169. "_foreach_norm",
  170. "_foreach_pow",
  171. "_foreach_pow_",
  172. "_foreach_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_grouped_mm_v2",
  315. "_scaled_mm",
  316. "_scaled_mm_v2",
  317. "_shape_as_tensor",
  318. "_sobol_engine_draw",
  319. "_sobol_engine_ff_",
  320. "_sobol_engine_initialize_state_",
  321. "_sobol_engine_scramble_",
  322. "_softmax",
  323. "_softmax_backward_data",
  324. "_sparse_broadcast_to",
  325. "_sparse_broadcast_to_copy",
  326. "_sparse_csr_prod",
  327. "_sparse_csr_sum",
  328. "_sparse_log_softmax_backward_data",
  329. "_sparse_semi_structured_addmm",
  330. "_sparse_semi_structured_apply",
  331. "_sparse_semi_structured_apply_dense",
  332. "_sparse_semi_structured_linear",
  333. "_sparse_semi_structured_mm",
  334. "_sparse_semi_structured_tile",
  335. "_sparse_softmax_backward_data",
  336. "_sparse_sparse_matmul",
  337. "_sparse_sum",
  338. "_stack",
  339. "_standard_gamma",
  340. "_standard_gamma_grad",
  341. "_sync",
  342. "_test_autograd_multiple_dispatch",
  343. "_test_autograd_multiple_dispatch_view",
  344. "_test_autograd_multiple_dispatch_view_copy",
  345. "_test_check_tensor",
  346. "_test_functorch_fallback",
  347. "_test_parallel_materialize",
  348. "_test_serialization_subcmul",
  349. "_to_cpu",
  350. "_to_functional_tensor",
  351. "_to_sparse_semi_structured",
  352. "_transform_bias_rescale_qkv",
  353. "_transformer_encoder_layer_fwd",
  354. "_trilinear",
  355. "_triton_multi_head_attention",
  356. "_triton_scaled_dot_attention",
  357. "_unique",
  358. "_unique2",
  359. "_unpack_dual",
  360. "_unsafe_index",
  361. "_unsafe_index_put",
  362. "_unsafe_masked_index",
  363. "_unsafe_masked_index_put_accumulate",
  364. "_use_cudnn_ctc_loss",
  365. "_use_cudnn_rnn_flatten_weight",
  366. "_validate_compressed_sparse_indices",
  367. "_validate_sparse_bsc_tensor_args",
  368. "_validate_sparse_bsr_tensor_args",
  369. "_validate_sparse_compressed_tensor_args",
  370. "_validate_sparse_coo_tensor_args",
  371. "_validate_sparse_csc_tensor_args",
  372. "_validate_sparse_csr_tensor_args",
  373. "_values_copy",
  374. "_weight_int4pack_mm",
  375. "_weight_int4pack_mm_for_cpu",
  376. "_weight_int4pack_mm_with_scales_and_zeros",
  377. "_weight_int8pack_mm",
  378. "_weight_norm",
  379. "_weight_norm_interface",
  380. "_wrapped_linear_prepack",
  381. "_wrapped_quantized_linear_prepacked",
  382. "abs",
  383. "abs_",
  384. "absolute",
  385. "acos",
  386. "acos_",
  387. "acosh",
  388. "acosh_",
  389. "adaptive_avg_pool1d",
  390. "adaptive_max_pool1d",
  391. "add",
  392. "addbmm",
  393. "addcdiv",
  394. "addcmul",
  395. "addmm",
  396. "addmv",
  397. "addmv_",
  398. "addr",
  399. "adjoint",
  400. "affine_grid_generator",
  401. "alias_copy",
  402. "all",
  403. "allclose",
  404. "alpha_dropout",
  405. "alpha_dropout_",
  406. "amax",
  407. "amin",
  408. "aminmax",
  409. "angle",
  410. "any",
  411. "arange",
  412. "arccos",
  413. "arccos_",
  414. "arccosh",
  415. "arccosh_",
  416. "arcsin",
  417. "arcsin_",
  418. "arcsinh",
  419. "arcsinh_",
  420. "arctan",
  421. "arctan2",
  422. "arctan_",
  423. "arctanh",
  424. "arctanh_",
  425. "argmax",
  426. "argmin",
  427. "argsort",
  428. "argwhere",
  429. "as_strided",
  430. "as_strided_",
  431. "as_strided_copy",
  432. "as_strided_scatter",
  433. "as_tensor",
  434. "asarray",
  435. "asin",
  436. "asin_",
  437. "asinh",
  438. "asinh_",
  439. "atan",
  440. "atan2",
  441. "atan_",
  442. "atanh",
  443. "atanh_",
  444. "avg_pool1d",
  445. "baddbmm",
  446. "bartlett_window",
  447. "batch_norm",
  448. "batch_norm_backward_elemt",
  449. "batch_norm_backward_reduce",
  450. "batch_norm_elemt",
  451. "batch_norm_gather_stats",
  452. "batch_norm_gather_stats_with_counts",
  453. "batch_norm_stats",
  454. "batch_norm_update_stats",
  455. "bernoulli",
  456. "bilinear",
  457. "binary_cross_entropy_with_logits",
  458. "bincount",
  459. "binomial",
  460. "bitwise_and",
  461. "bitwise_left_shift",
  462. "bitwise_not",
  463. "bitwise_or",
  464. "bitwise_right_shift",
  465. "bitwise_xor",
  466. "blackman_window",
  467. "bmm",
  468. "broadcast_to",
  469. "bucketize",
  470. "can_cast",
  471. "cat",
  472. "ccol_indices_copy",
  473. "ceil",
  474. "ceil_",
  475. "celu",
  476. "celu_",
  477. "channel_shuffle",
  478. "cholesky",
  479. "cholesky_inverse",
  480. "cholesky_solve",
  481. "choose_qparams_optimized",
  482. "chunk",
  483. "clamp",
  484. "clamp_",
  485. "clamp_max",
  486. "clamp_max_",
  487. "clamp_min",
  488. "clamp_min_",
  489. "clip",
  490. "clip_",
  491. "clone",
  492. "col_indices_copy",
  493. "column_stack",
  494. "combinations",
  495. "complex",
  496. "concat",
  497. "concatenate",
  498. "conj",
  499. "conj_physical",
  500. "conj_physical_",
  501. "constant_pad_nd",
  502. "conv1d",
  503. "conv2d",
  504. "conv3d",
  505. "conv_tbc",
  506. "conv_transpose1d",
  507. "conv_transpose2d",
  508. "conv_transpose3d",
  509. "convolution",
  510. "copysign",
  511. "corrcoef",
  512. "cos",
  513. "cos_",
  514. "cosh",
  515. "cosh_",
  516. "cosine_embedding_loss",
  517. "cosine_similarity",
  518. "count_nonzero",
  519. "cov",
  520. "cross",
  521. "crow_indices_copy",
  522. "ctc_loss",
  523. "cudnn_affine_grid_generator",
  524. "cudnn_batch_norm",
  525. "cudnn_convolution",
  526. "cudnn_convolution_add_relu",
  527. "cudnn_convolution_relu",
  528. "cudnn_convolution_transpose",
  529. "cudnn_grid_sampler",
  530. "cudnn_is_acceptable",
  531. "cummax",
  532. "cummin",
  533. "cumprod",
  534. "cumsum",
  535. "cumulative_trapezoid",
  536. "deg2rad",
  537. "deg2rad_",
  538. "dequantize",
  539. "det",
  540. "detach",
  541. "detach_",
  542. "detach_copy",
  543. "diag",
  544. "diag_embed",
  545. "diagflat",
  546. "diagonal",
  547. "diagonal_copy",
  548. "diagonal_scatter",
  549. "diff",
  550. "digamma",
  551. "dist",
  552. "div",
  553. "divide",
  554. "dot",
  555. "dropout",
  556. "dropout_",
  557. "dsmm",
  558. "dsplit",
  559. "dstack",
  560. "embedding",
  561. "embedding_bag",
  562. "embedding_renorm_",
  563. "empty",
  564. "empty_like",
  565. "empty_permuted",
  566. "empty_quantized",
  567. "empty_strided",
  568. "eq",
  569. "equal",
  570. "erf",
  571. "erf_",
  572. "erfc",
  573. "erfc_",
  574. "erfinv",
  575. "exp",
  576. "exp2",
  577. "exp2_",
  578. "exp_",
  579. "expand_copy",
  580. "expm1",
  581. "expm1_",
  582. "eye",
  583. "fake_quantize_per_channel_affine",
  584. "fake_quantize_per_tensor_affine",
  585. "fbgemm_linear_fp16_weight",
  586. "fbgemm_linear_fp16_weight_fp32_activation",
  587. "fbgemm_linear_int8_weight",
  588. "fbgemm_linear_int8_weight_fp32_activation",
  589. "fbgemm_linear_quantize_weight",
  590. "fbgemm_pack_gemm_matrix_fp16",
  591. "fbgemm_pack_quantized_matrix",
  592. "feature_alpha_dropout",
  593. "feature_alpha_dropout_",
  594. "feature_dropout",
  595. "feature_dropout_",
  596. "fill",
  597. "fill_",
  598. "fix",
  599. "fix_",
  600. "flatten",
  601. "flip",
  602. "fliplr",
  603. "flipud",
  604. "float_power",
  605. "floor",
  606. "floor_",
  607. "floor_divide",
  608. "fmax",
  609. "fmin",
  610. "fmod",
  611. "frac",
  612. "frac_",
  613. "frexp",
  614. "frobenius_norm",
  615. "from_file",
  616. "from_numpy",
  617. "frombuffer",
  618. "full",
  619. "full_like",
  620. "fused_moving_avg_obs_fake_quant",
  621. "gather",
  622. "gcd",
  623. "gcd_",
  624. "ge",
  625. "geqrf",
  626. "ger",
  627. "get_default_dtype",
  628. "get_num_interop_threads",
  629. "get_num_threads",
  630. "gradient",
  631. "greater",
  632. "greater_equal",
  633. "grid_sampler",
  634. "grid_sampler_2d",
  635. "grid_sampler_3d",
  636. "group_norm",
  637. "gru",
  638. "gru_cell",
  639. "gt",
  640. "hamming_window",
  641. "hann_window",
  642. "hardshrink",
  643. "hash_tensor",
  644. "heaviside",
  645. "hinge_embedding_loss",
  646. "histc",
  647. "histogram",
  648. "histogramdd",
  649. "hsmm",
  650. "hsplit",
  651. "hspmm",
  652. "hstack",
  653. "hypot",
  654. "i0",
  655. "i0_",
  656. "igamma",
  657. "igammac",
  658. "imag",
  659. "index_add",
  660. "index_copy",
  661. "index_fill",
  662. "index_put",
  663. "index_put_",
  664. "index_reduce",
  665. "index_select",
  666. "indices_copy",
  667. "init_num_threads",
  668. "inner",
  669. "instance_norm",
  670. "int_repr",
  671. "inverse",
  672. "is_complex",
  673. "is_conj",
  674. "is_distributed",
  675. "is_floating_point",
  676. "is_grad_enabled",
  677. "is_inference",
  678. "is_inference_mode_enabled",
  679. "is_neg",
  680. "is_nonzero",
  681. "is_same_size",
  682. "is_signed",
  683. "is_vulkan_available",
  684. "isclose",
  685. "isfinite",
  686. "isin",
  687. "isinf",
  688. "isnan",
  689. "isneginf",
  690. "isposinf",
  691. "isreal",
  692. "istft",
  693. "kaiser_window",
  694. "kl_div",
  695. "kron",
  696. "kthvalue",
  697. "layer_norm",
  698. "lcm",
  699. "lcm_",
  700. "ldexp",
  701. "ldexp_",
  702. "le",
  703. "lerp",
  704. "less",
  705. "less_equal",
  706. "lgamma",
  707. "linspace",
  708. "log",
  709. "log10",
  710. "log10_",
  711. "log1p",
  712. "log1p_",
  713. "log2",
  714. "log2_",
  715. "log_",
  716. "log_softmax",
  717. "logaddexp",
  718. "logaddexp2",
  719. "logcumsumexp",
  720. "logdet",
  721. "logical_and",
  722. "logical_not",
  723. "logical_or",
  724. "logical_xor",
  725. "logit",
  726. "logit_",
  727. "logspace",
  728. "logsumexp",
  729. "lstm",
  730. "lstm_cell",
  731. "lt",
  732. "lu_solve",
  733. "lu_unpack",
  734. "margin_ranking_loss",
  735. "masked_fill",
  736. "masked_scatter",
  737. "masked_select",
  738. "matmul",
  739. "matrix_exp",
  740. "matrix_power",
  741. "max",
  742. "max_pool1d",
  743. "max_pool1d_with_indices",
  744. "max_pool2d",
  745. "max_pool3d",
  746. "maximum",
  747. "mean",
  748. "median",
  749. "min",
  750. "minimum",
  751. "miopen_batch_norm",
  752. "miopen_convolution",
  753. "miopen_convolution_add_relu",
  754. "miopen_convolution_relu",
  755. "miopen_convolution_transpose",
  756. "miopen_depthwise_convolution",
  757. "miopen_rnn",
  758. "mkldnn_adaptive_avg_pool2d",
  759. "mkldnn_convolution",
  760. "mkldnn_linear_backward_weights",
  761. "mkldnn_max_pool2d",
  762. "mkldnn_max_pool3d",
  763. "mkldnn_rnn_layer",
  764. "mm",
  765. "mode",
  766. "moveaxis",
  767. "movedim",
  768. "msort",
  769. "mul",
  770. "multinomial",
  771. "multiply",
  772. "mv",
  773. "mvlgamma",
  774. "nan_to_num",
  775. "nan_to_num_",
  776. "nanmean",
  777. "nanmedian",
  778. "nanquantile",
  779. "nansum",
  780. "narrow",
  781. "narrow_copy",
  782. "native_batch_norm",
  783. "native_channel_shuffle",
  784. "native_dropout",
  785. "native_group_norm",
  786. "native_layer_norm",
  787. "native_norm",
  788. "ne",
  789. "neg",
  790. "neg_",
  791. "negative",
  792. "negative_",
  793. "nextafter",
  794. "nonzero",
  795. "nonzero_static",
  796. "norm_except_dim",
  797. "normal",
  798. "not_equal",
  799. "nuclear_norm",
  800. "numel",
  801. "ones",
  802. "ones_like",
  803. "orgqr",
  804. "ormqr",
  805. "outer",
  806. "pairwise_distance",
  807. "pdist",
  808. "permute",
  809. "permute_copy",
  810. "pinverse",
  811. "pixel_shuffle",
  812. "pixel_unshuffle",
  813. "poisson",
  814. "poisson_nll_loss",
  815. "polar",
  816. "polygamma",
  817. "positive",
  818. "pow",
  819. "prelu",
  820. "prod",
  821. "promote_types",
  822. "put",
  823. "q_per_channel_axis",
  824. "q_per_channel_scales",
  825. "q_per_channel_zero_points",
  826. "q_scale",
  827. "q_zero_point",
  828. "qr",
  829. "quantile",
  830. "quantize_per_channel",
  831. "quantize_per_tensor",
  832. "quantize_per_tensor_dynamic",
  833. "quantized_batch_norm",
  834. "quantized_gru_cell",
  835. "quantized_lstm_cell",
  836. "quantized_max_pool1d",
  837. "quantized_max_pool2d",
  838. "quantized_max_pool3d",
  839. "quantized_rnn_relu_cell",
  840. "quantized_rnn_tanh_cell",
  841. "rad2deg",
  842. "rad2deg_",
  843. "rand",
  844. "rand_like",
  845. "randint",
  846. "randint_like",
  847. "randn",
  848. "randn_like",
  849. "randperm",
  850. "range",
  851. "ravel",
  852. "real",
  853. "reciprocal",
  854. "reciprocal_",
  855. "relu",
  856. "relu_",
  857. "remainder",
  858. "renorm",
  859. "repeat_interleave",
  860. "reshape",
  861. "resize_as_",
  862. "resize_as_sparse_",
  863. "resolve_conj",
  864. "resolve_neg",
  865. "result_type",
  866. "rms_norm",
  867. "rnn_relu",
  868. "rnn_relu_cell",
  869. "rnn_tanh",
  870. "rnn_tanh_cell",
  871. "roll",
  872. "rot90",
  873. "round",
  874. "round_",
  875. "row_indices_copy",
  876. "row_stack",
  877. "rrelu",
  878. "rrelu_",
  879. "rsqrt",
  880. "rsqrt_",
  881. "rsub",
  882. "saddmm",
  883. "scalar_tensor",
  884. "scatter",
  885. "scatter_add",
  886. "scatter_reduce",
  887. "searchsorted",
  888. "segment_reduce",
  889. "select",
  890. "select_copy",
  891. "select_scatter",
  892. "selu",
  893. "selu_",
  894. "set_flush_denormal",
  895. "set_num_interop_threads",
  896. "set_num_threads",
  897. "sgn",
  898. "sigmoid",
  899. "sigmoid_",
  900. "sign",
  901. "signbit",
  902. "sin",
  903. "sin_",
  904. "sinc",
  905. "sinc_",
  906. "sinh",
  907. "sinh_",
  908. "slice_copy",
  909. "slice_inverse",
  910. "slice_scatter",
  911. "slogdet",
  912. "smm",
  913. "softmax",
  914. "sort",
  915. "sparse_bsc_tensor",
  916. "sparse_bsr_tensor",
  917. "sparse_compressed_tensor",
  918. "sparse_coo_tensor",
  919. "sparse_csc_tensor",
  920. "sparse_csr_tensor",
  921. "split_copy",
  922. "split_with_sizes",
  923. "split_with_sizes_copy",
  924. "spmm",
  925. "sqrt",
  926. "sqrt_",
  927. "square",
  928. "square_",
  929. "squeeze",
  930. "squeeze_copy",
  931. "sspaddmm",
  932. "stack",
  933. "std",
  934. "std_mean",
  935. "sub",
  936. "subtract",
  937. "sum",
  938. "svd",
  939. "swapaxes",
  940. "swapdims",
  941. "sym_constrain_range",
  942. "sym_constrain_range_for_size",
  943. "t",
  944. "t_copy",
  945. "take",
  946. "take_along_dim",
  947. "tan",
  948. "tan_",
  949. "tanh",
  950. "tanh_",
  951. "tensor",
  952. "tensor_split",
  953. "threshold",
  954. "threshold_",
  955. "tile",
  956. "topk",
  957. "trace",
  958. "transpose",
  959. "transpose_copy",
  960. "trapezoid",
  961. "trapz",
  962. "triangular_solve",
  963. "tril",
  964. "tril_indices",
  965. "triplet_margin_loss",
  966. "triu",
  967. "triu_indices",
  968. "true_divide",
  969. "trunc",
  970. "trunc_",
  971. "unbind",
  972. "unbind_copy",
  973. "unflatten",
  974. "unfold_copy",
  975. "unique_dim",
  976. "unsafe_chunk",
  977. "unsafe_split",
  978. "unsafe_split_with_sizes",
  979. "unsqueeze",
  980. "unsqueeze_copy",
  981. "values_copy",
  982. "vander",
  983. "var",
  984. "var_mean",
  985. "vdot",
  986. "view_as_complex",
  987. "view_as_complex_copy",
  988. "view_as_real",
  989. "view_as_real_copy",
  990. "view_copy",
  991. "vsplit",
  992. "vstack",
  993. "where",
  994. "xlogy",
  995. "xlogy_",
  996. "zero_",
  997. "zeros",
  998. "zeros_like",
  999. ]
  1000. @overload
  1001. def __and__(input: Tensor, other: Tensor) -> Tensor: ...
  1002. @overload
  1003. def __and__(input: Tensor, other: Number | _complex) -> Tensor: ...
  1004. @overload
  1005. def __lshift__(input: Tensor, other: Tensor) -> Tensor: ...
  1006. @overload
  1007. def __lshift__(input: Tensor, other: Number | _complex) -> Tensor: ...
  1008. @overload
  1009. def __or__(input: Tensor, other: Tensor) -> Tensor: ...
  1010. @overload
  1011. def __or__(input: Tensor, other: Number | _complex) -> Tensor: ...
  1012. @overload
  1013. def __rshift__(input: Tensor, other: Tensor) -> Tensor: ...
  1014. @overload
  1015. def __rshift__(input: Tensor, other: Number | _complex) -> Tensor: ...
  1016. @overload
  1017. def __xor__(input: Tensor, other: Tensor) -> Tensor: ...
  1018. @overload
  1019. def __xor__(input: Tensor, other: Number | _complex) -> Tensor: ...
  1020. def _adaptive_avg_pool2d(
  1021. input: Tensor,
  1022. output_size: _int | SymInt | Sequence[_int | SymInt],
  1023. ) -> Tensor: ...
  1024. def _adaptive_avg_pool3d(
  1025. input: Tensor,
  1026. output_size: _int | SymInt | Sequence[_int | SymInt],
  1027. ) -> Tensor: ...
  1028. def _add_batch_dim(input: Tensor, batch_dim: _int, level: _int) -> Tensor: ...
  1029. @overload
  1030. def _add_relu(
  1031. input: Tensor,
  1032. other: Tensor,
  1033. *,
  1034. alpha: Number | _complex = 1,
  1035. out: Tensor | None = None,
  1036. ) -> Tensor: ...
  1037. @overload
  1038. def _add_relu(
  1039. input: Tensor,
  1040. other: Number | _complex,
  1041. alpha: Number | _complex = 1,
  1042. ) -> Tensor: ...
  1043. @overload
  1044. def _add_relu_(
  1045. input: Tensor,
  1046. other: Tensor,
  1047. *,
  1048. alpha: Number | _complex = 1,
  1049. ) -> Tensor: ...
  1050. @overload
  1051. def _add_relu_(
  1052. input: Tensor,
  1053. other: Number | _complex,
  1054. alpha: Number | _complex = 1,
  1055. ) -> Tensor: ...
  1056. def _addmm_activation(
  1057. input: Tensor,
  1058. mat1: Tensor,
  1059. mat2: Tensor,
  1060. *,
  1061. beta: Number | _complex = 1,
  1062. alpha: Number | _complex = 1,
  1063. use_gelu: _bool = False,
  1064. out: Tensor | None = None,
  1065. ) -> Tensor: ...
  1066. @overload
  1067. def _aminmax(input: Tensor) -> tuple[Tensor, Tensor]: ...
  1068. @overload
  1069. def _aminmax(
  1070. input: Tensor,
  1071. dim: _int,
  1072. keepdim: _bool = False,
  1073. ) -> tuple[Tensor, Tensor]: ...
  1074. def _amp_foreach_non_finite_check_and_unscale_(
  1075. self: tuple[Tensor, ...] | list[Tensor] | None,
  1076. found_inf: Tensor,
  1077. inv_scale: Tensor,
  1078. ) -> None: ...
  1079. def _amp_update_scale_(
  1080. input: Tensor,
  1081. growth_tracker: Tensor,
  1082. found_inf: Tensor,
  1083. scale_growth_factor: _float,
  1084. scale_backoff_factor: _float,
  1085. growth_interval: _int,
  1086. ) -> Tensor: ...
  1087. @overload
  1088. def _assert_async(input: Tensor) -> None:
  1089. r"""
  1090. _assert_async(tensor) -> void
  1091. Asynchronously assert that the contents of tensor are nonzero. For CPU tensors,
  1092. this is equivalent to ``assert tensor`` or ``assert tensor.is_nonzero()``; for
  1093. CUDA tensors, we DO NOT synchronize and you may only find out the assertion
  1094. failed at a later CUDA kernel launch. Asynchronous assertion can be helpful for
  1095. testing invariants in CUDA tensors without giving up performance. This function
  1096. is NOT intended to be used for regular error checking, as it will trash your CUDA
  1097. context if the assert fails (forcing you to restart your PyTorch process.)
  1098. Args:
  1099. tensor (Tensor): a one element tensor to test to see if it is nonzero. Zero
  1100. elements (including False for boolean tensors) cause an assertion failure
  1101. to be raised.
  1102. """
  1103. @overload
  1104. def _assert_async(input: Tensor, assert_msg: str) -> None:
  1105. r"""
  1106. _assert_async(tensor) -> void
  1107. Asynchronously assert that the contents of tensor are nonzero. For CPU tensors,
  1108. this is equivalent to ``assert tensor`` or ``assert tensor.is_nonzero()``; for
  1109. CUDA tensors, we DO NOT synchronize and you may only find out the assertion
  1110. failed at a later CUDA kernel launch. Asynchronous assertion can be helpful for
  1111. testing invariants in CUDA tensors without giving up performance. This function
  1112. is NOT intended to be used for regular error checking, as it will trash your CUDA
  1113. context if the assert fails (forcing you to restart your PyTorch process.)
  1114. Args:
  1115. tensor (Tensor): a one element tensor to test to see if it is nonzero. Zero
  1116. elements (including False for boolean tensors) cause an assertion failure
  1117. to be raised.
  1118. """
  1119. def _assert_scalar(self: Number | _complex, assert_msg: str) -> None: ...
  1120. def _assert_tensor_metadata(
  1121. a: Tensor,
  1122. size: Sequence[_int | SymInt] | None = None,
  1123. stride: Sequence[_int | SymInt] | None = None,
  1124. dtype: _dtype | None = None,
  1125. *,
  1126. device: DeviceLikeType | None = None,
  1127. layout: _layout | None = None,
  1128. ) -> None: ...
  1129. def _batch_norm_impl_index(
  1130. input: Tensor,
  1131. weight: Tensor | None,
  1132. bias: Tensor | None,
  1133. running_mean: Tensor | None,
  1134. running_var: Tensor | None,
  1135. training: _bool,
  1136. momentum: _float,
  1137. eps: _float,
  1138. cudnn_enabled: _bool,
  1139. ) -> tuple[Tensor, Tensor, Tensor, Tensor, _int]: ...
  1140. def _cast_Byte(input: Tensor, non_blocking: _bool = False) -> Tensor: ...
  1141. def _cast_Char(input: Tensor, non_blocking: _bool = False) -> Tensor: ...
  1142. def _cast_Double(input: Tensor, non_blocking: _bool = False) -> Tensor: ...
  1143. def _cast_Float(input: Tensor, non_blocking: _bool = False) -> Tensor: ...
  1144. def _cast_Half(input: Tensor, non_blocking: _bool = False) -> Tensor: ...
  1145. def _cast_Int(input: Tensor, non_blocking: _bool = False) -> Tensor: ...
  1146. def _cast_Long(input: Tensor, non_blocking: _bool = False) -> Tensor: ...
  1147. def _cast_Short(input: Tensor, non_blocking: _bool = False) -> Tensor: ...
  1148. def _choose_qparams_per_tensor(
  1149. input: Tensor,
  1150. reduce_range: _bool = False,
  1151. ) -> tuple[_float, _int]: ...
  1152. def _chunk_cat(
  1153. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  1154. dim: _int,
  1155. num_chunks: _int,
  1156. *,
  1157. out: Tensor | None = None,
  1158. ) -> Tensor: ...
  1159. def _coalesce(input: Tensor) -> Tensor: ...
  1160. def _compute_linear_combination(
  1161. input: Tensor,
  1162. coefficients: Tensor,
  1163. *,
  1164. out: Tensor | None = None,
  1165. ) -> Tensor: ...
  1166. def _conj(input: Tensor) -> Tensor: ...
  1167. def _conj_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor: ...
  1168. def _conj_physical(input: Tensor) -> Tensor: ...
  1169. def _convert_indices_from_coo_to_csr(
  1170. input: Tensor,
  1171. size: _int,
  1172. *,
  1173. out_int32: _bool = False,
  1174. out: Tensor | None = None,
  1175. ) -> Tensor: ...
  1176. def _convert_indices_from_csr_to_coo(
  1177. crow_indices: Tensor,
  1178. col_indices: Tensor,
  1179. *,
  1180. out_int32: _bool = False,
  1181. transpose: _bool = False,
  1182. out: Tensor | None = None,
  1183. ) -> Tensor: ...
  1184. def _convert_weight_to_int4pack(input: Tensor, innerKTiles: _int) -> Tensor: ...
  1185. def _convert_weight_to_int4pack_for_cpu(
  1186. input: Tensor,
  1187. innerKTiles: _int,
  1188. ) -> Tensor: ...
  1189. @overload
  1190. def _convolution(
  1191. input: Tensor,
  1192. weight: Tensor,
  1193. bias: Tensor | None,
  1194. stride: Sequence[_int | SymInt],
  1195. padding: Sequence[_int | SymInt],
  1196. dilation: Sequence[_int | SymInt],
  1197. transposed: _bool,
  1198. output_padding: _size,
  1199. groups: _int | SymInt,
  1200. benchmark: _bool,
  1201. deterministic: _bool,
  1202. cudnn_enabled: _bool,
  1203. ) -> Tensor: ...
  1204. @overload
  1205. def _convolution(
  1206. input: Tensor,
  1207. weight: Tensor,
  1208. bias: Tensor | None,
  1209. stride: Sequence[_int | SymInt],
  1210. padding: Sequence[_int | SymInt],
  1211. dilation: Sequence[_int | SymInt],
  1212. transposed: _bool,
  1213. output_padding: Sequence[_int | SymInt],
  1214. groups: _int | SymInt,
  1215. benchmark: _bool,
  1216. deterministic: _bool,
  1217. cudnn_enabled: _bool,
  1218. allow_tf32: _bool,
  1219. ) -> Tensor: ...
  1220. def _convolution_mode(
  1221. input: Tensor,
  1222. weight: Tensor,
  1223. bias: Tensor | None,
  1224. stride: Sequence[_int | SymInt],
  1225. padding: str,
  1226. dilation: Sequence[_int | SymInt],
  1227. groups: _int | SymInt,
  1228. ) -> Tensor: ...
  1229. def _copy_from(
  1230. input: Tensor,
  1231. dst: Tensor,
  1232. non_blocking: _bool = False,
  1233. ) -> Tensor: ...
  1234. def _copy_from_and_resize(input: Tensor, dst: Tensor) -> Tensor: ...
  1235. def _cslt_compress(input: Tensor) -> Tensor: ...
  1236. def _cslt_sparse_mm(
  1237. compressed_A: Tensor,
  1238. dense_B: Tensor,
  1239. bias: Tensor | None = None,
  1240. alpha: Tensor | None = None,
  1241. out_dtype: _dtype | None = None,
  1242. transpose_result: _bool = False,
  1243. alg_id: _int = 0,
  1244. split_k: _int = 1,
  1245. split_k_mode: _int = -1,
  1246. ) -> Tensor: ...
  1247. def _cslt_sparse_mm_search(
  1248. compressed_A: Tensor,
  1249. dense_B: Tensor,
  1250. bias: Tensor | None = None,
  1251. alpha: Tensor | None = None,
  1252. out_dtype: _dtype | None = None,
  1253. transpose_result: _bool = False,
  1254. ) -> _int: ...
  1255. @overload
  1256. def _ctc_loss(
  1257. log_probs: Tensor,
  1258. targets: Tensor,
  1259. input_lengths: _size,
  1260. target_lengths: _size,
  1261. blank: _int = 0,
  1262. zero_infinity: _bool = False,
  1263. ) -> tuple[Tensor, Tensor]: ...
  1264. @overload
  1265. def _ctc_loss(
  1266. log_probs: Tensor,
  1267. targets: Tensor,
  1268. input_lengths: Tensor,
  1269. target_lengths: Tensor,
  1270. blank: _int = 0,
  1271. zero_infinity: _bool = False,
  1272. ) -> tuple[Tensor, Tensor]: ...
  1273. @overload
  1274. def _cudnn_ctc_loss(
  1275. log_probs: Tensor,
  1276. targets: Tensor,
  1277. input_lengths: _size,
  1278. target_lengths: _size,
  1279. blank: _int,
  1280. deterministic: _bool,
  1281. zero_infinity: _bool,
  1282. ) -> tuple[Tensor, Tensor]: ...
  1283. @overload
  1284. def _cudnn_ctc_loss(
  1285. log_probs: Tensor,
  1286. targets: Tensor,
  1287. input_lengths: Tensor,
  1288. target_lengths: Tensor,
  1289. blank: _int,
  1290. deterministic: _bool,
  1291. zero_infinity: _bool,
  1292. ) -> tuple[Tensor, Tensor]: ...
  1293. def _cudnn_init_dropout_state(
  1294. dropout: _float,
  1295. train: _bool,
  1296. dropout_seed: _int,
  1297. *,
  1298. dtype: _dtype | None = None,
  1299. layout: _layout | None = None,
  1300. device: DeviceLikeType | None = None,
  1301. pin_memory: _bool | None = False,
  1302. requires_grad: _bool | None = False,
  1303. ) -> Tensor: ...
  1304. def _cudnn_rnn(
  1305. input: Tensor,
  1306. weight: tuple[Tensor, ...] | list[Tensor] | None,
  1307. weight_stride0: _int,
  1308. weight_buf: Tensor | None,
  1309. hx: Tensor,
  1310. cx: Tensor | None,
  1311. mode: _int,
  1312. hidden_size: _int | SymInt,
  1313. proj_size: _int | SymInt,
  1314. num_layers: _int,
  1315. batch_first: _bool,
  1316. dropout: _float,
  1317. train: _bool,
  1318. bidirectional: _bool,
  1319. batch_sizes: Sequence[_int | SymInt],
  1320. dropout_state: Tensor | None,
  1321. ) -> tuple[Tensor, Tensor, Tensor, Tensor, Tensor]: ...
  1322. def _cudnn_rnn_flatten_weight(
  1323. weight_arr: tuple[Tensor, ...] | list[Tensor] | None,
  1324. weight_stride0: _int,
  1325. input_size: _int | SymInt,
  1326. mode: _int,
  1327. hidden_size: _int | SymInt,
  1328. proj_size: _int | SymInt,
  1329. num_layers: _int,
  1330. batch_first: _bool,
  1331. bidirectional: _bool,
  1332. ) -> Tensor: ...
  1333. def _cufft_clear_plan_cache(device_index: _int) -> None: ...
  1334. def _cufft_get_plan_cache_max_size(device_index: _int) -> _int: ...
  1335. def _cufft_get_plan_cache_size(device_index: _int) -> _int: ...
  1336. def _cufft_set_plan_cache_max_size(
  1337. device_index: _int,
  1338. max_size: _int,
  1339. ) -> None: ...
  1340. def _cummax_helper(
  1341. input: Tensor,
  1342. values: Tensor,
  1343. indices: Tensor,
  1344. dim: _int,
  1345. ) -> None: ...
  1346. def _cummin_helper(
  1347. input: Tensor,
  1348. values: Tensor,
  1349. indices: Tensor,
  1350. dim: _int,
  1351. ) -> None: ...
  1352. def _debug_has_internal_overlap(input: Tensor) -> _int: ...
  1353. def _dim_arange(like: Tensor, dim: _int) -> Tensor: ...
  1354. def _dirichlet_grad(x: Tensor, alpha: Tensor, total: Tensor) -> Tensor: ...
  1355. def _disable_functionalization(): ...
  1356. def _dyn_quant_matmul_4bit(
  1357. inp: Tensor,
  1358. packed_weights: Tensor,
  1359. block_size: _int,
  1360. in_features: _int,
  1361. out_features: _int,
  1362. ) -> Tensor: ...
  1363. def _dyn_quant_pack_4bit_weight(
  1364. weights: Tensor,
  1365. scales_zeros: Tensor,
  1366. bias: Tensor | None,
  1367. block_size: _int,
  1368. in_features: _int,
  1369. out_features: _int,
  1370. ) -> Tensor: ...
  1371. @overload
  1372. def _efficientzerotensor(
  1373. size: Sequence[_int | SymInt],
  1374. *,
  1375. dtype: _dtype | None = None,
  1376. layout: _layout | None = None,
  1377. device: DeviceLikeType | None = None,
  1378. pin_memory: _bool | None = False,
  1379. requires_grad: _bool | None = False,
  1380. ) -> Tensor: ...
  1381. @overload
  1382. def _efficientzerotensor(
  1383. *size: _int | SymInt,
  1384. dtype: _dtype | None = None,
  1385. layout: _layout | None = None,
  1386. device: DeviceLikeType | None = None,
  1387. pin_memory: _bool | None = False,
  1388. requires_grad: _bool | None = False,
  1389. ) -> Tensor: ...
  1390. def _embedding_bag(
  1391. weight: Tensor,
  1392. indices: Tensor,
  1393. offsets: Tensor,
  1394. scale_grad_by_freq: _bool = False,
  1395. mode: _int = 0,
  1396. sparse: _bool = False,
  1397. per_sample_weights: Tensor | None = None,
  1398. include_last_offset: _bool = False,
  1399. padding_idx: _int = -1,
  1400. ) -> tuple[Tensor, Tensor, Tensor, Tensor]: ...
  1401. def _embedding_bag_forward_only(
  1402. weight: Tensor,
  1403. indices: Tensor,
  1404. offsets: Tensor,
  1405. scale_grad_by_freq: _bool = False,
  1406. mode: _int = 0,
  1407. sparse: _bool = False,
  1408. per_sample_weights: Tensor | None = None,
  1409. include_last_offset: _bool = False,
  1410. padding_idx: _int = -1,
  1411. ) -> tuple[Tensor, Tensor, Tensor, Tensor]: ...
  1412. @overload
  1413. def _empty_affine_quantized(
  1414. size: Sequence[_int | SymInt],
  1415. *,
  1416. scale: _float = 1,
  1417. zero_point: _int = 0,
  1418. memory_format: memory_format | None = contiguous_format,
  1419. dtype: _dtype | None = None,
  1420. layout: _layout | None = None,
  1421. device: DeviceLikeType | None = None,
  1422. pin_memory: _bool | None = False,
  1423. requires_grad: _bool | None = False,
  1424. ) -> Tensor: ...
  1425. @overload
  1426. def _empty_affine_quantized(
  1427. *size: _int | SymInt,
  1428. scale: _float = 1,
  1429. zero_point: _int = 0,
  1430. memory_format: memory_format | None = contiguous_format,
  1431. dtype: _dtype | None = None,
  1432. layout: _layout | None = None,
  1433. device: DeviceLikeType | None = None,
  1434. pin_memory: _bool | None = False,
  1435. requires_grad: _bool | None = False,
  1436. ) -> Tensor: ...
  1437. @overload
  1438. def _empty_per_channel_affine_quantized(
  1439. size: Sequence[_int | SymInt],
  1440. *,
  1441. scales: Tensor,
  1442. zero_points: Tensor,
  1443. axis: _int,
  1444. memory_format: memory_format | None = contiguous_format,
  1445. dtype: _dtype | None = None,
  1446. layout: _layout | None = None,
  1447. device: DeviceLikeType | None = None,
  1448. pin_memory: _bool | None = False,
  1449. requires_grad: _bool | None = False,
  1450. ) -> Tensor: ...
  1451. @overload
  1452. def _empty_per_channel_affine_quantized(
  1453. *size: _int | SymInt,
  1454. scales: Tensor,
  1455. zero_points: Tensor,
  1456. axis: _int,
  1457. memory_format: memory_format | None = contiguous_format,
  1458. dtype: _dtype | None = None,
  1459. layout: _layout | None = None,
  1460. device: DeviceLikeType | None = None,
  1461. pin_memory: _bool | None = False,
  1462. requires_grad: _bool | None = False,
  1463. ) -> Tensor: ...
  1464. def _enable_functionalization(*, reapply_views: _bool = False) -> None: ...
  1465. def _euclidean_dist(x1: Tensor, x2: Tensor) -> Tensor: ...
  1466. def _fake_quantize_learnable_per_channel_affine(
  1467. input: Tensor,
  1468. scale: Tensor,
  1469. zero_point: Tensor,
  1470. axis: _int,
  1471. quant_min: _int,
  1472. quant_max: _int,
  1473. grad_factor: _float = 1.0,
  1474. ) -> Tensor: ...
  1475. def _fake_quantize_learnable_per_tensor_affine(
  1476. input: Tensor,
  1477. scale: Tensor,
  1478. zero_point: Tensor,
  1479. quant_min: _int,
  1480. quant_max: _int,
  1481. grad_factor: _float = 1.0,
  1482. ) -> Tensor: ...
  1483. def _fake_quantize_per_tensor_affine_cachemask_tensor_qparams(
  1484. input: Tensor,
  1485. scale: Tensor,
  1486. zero_point: Tensor,
  1487. fake_quant_enabled: Tensor,
  1488. quant_min: _int,
  1489. quant_max: _int,
  1490. ) -> torch.return_types._fake_quantize_per_tensor_affine_cachemask_tensor_qparams: # fmt: skip
  1491. ...
  1492. def _fft_c2c(
  1493. input: Tensor,
  1494. dim: Sequence[_int | SymInt],
  1495. normalization: _int,
  1496. forward: _bool,
  1497. *,
  1498. out: Tensor | None = None,
  1499. ) -> Tensor: ...
  1500. def _fft_c2r(
  1501. input: Tensor,
  1502. dim: _size,
  1503. normalization: _int,
  1504. last_dim_size: _int | SymInt,
  1505. *,
  1506. out: Tensor | None = None,
  1507. ) -> Tensor: ...
  1508. def _fft_r2c(
  1509. input: Tensor,
  1510. dim: _size,
  1511. normalization: _int,
  1512. onesided: _bool,
  1513. *,
  1514. out: Tensor | None = None,
  1515. ) -> Tensor: ...
  1516. def _fill_mem_eff_dropout_mask_(
  1517. input: Tensor,
  1518. dropout_p: _float,
  1519. seed: _int,
  1520. offset: _int,
  1521. ) -> Tensor: ...
  1522. def _foobar(
  1523. input: Tensor,
  1524. arg1: _bool = True,
  1525. arg2: _bool = True,
  1526. *,
  1527. arg3: _bool = True,
  1528. ) -> Tensor: ...
  1529. def _foreach_abs(
  1530. self: tuple[Tensor, ...] | list[Tensor] | None,
  1531. ) -> tuple[Tensor, ...]:
  1532. r"""
  1533. _foreach_abs(self: List[Tensor]) -> List[Tensor]
  1534. Apply :func:`torch.abs` to each Tensor of the input list.
  1535. """
  1536. def _foreach_abs_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1537. r"""
  1538. _foreach_abs_(self: List[Tensor]) -> None
  1539. Apply :func:`torch.abs` to each Tensor of the input list.
  1540. """
  1541. def _foreach_acos(
  1542. self: tuple[Tensor, ...] | list[Tensor] | None,
  1543. ) -> tuple[Tensor, ...]:
  1544. r"""
  1545. _foreach_acos(self: List[Tensor]) -> List[Tensor]
  1546. Apply :func:`torch.acos` to each Tensor of the input list.
  1547. """
  1548. def _foreach_acos_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1549. r"""
  1550. _foreach_acos_(self: List[Tensor]) -> None
  1551. Apply :func:`torch.acos` to each Tensor of the input list.
  1552. """
  1553. @overload
  1554. def _foreach_add(
  1555. self: tuple[Tensor, ...] | list[Tensor] | None,
  1556. scalars: Sequence[Number | _complex],
  1557. ) -> tuple[Tensor, ...]: ...
  1558. @overload
  1559. def _foreach_add(
  1560. self: tuple[Tensor, ...] | list[Tensor] | None,
  1561. other: tuple[Tensor, ...] | list[Tensor] | None,
  1562. *,
  1563. alpha: Number | _complex = 1,
  1564. ) -> tuple[Tensor, ...]: ...
  1565. @overload
  1566. def _foreach_add(
  1567. self: tuple[Tensor, ...] | list[Tensor] | None,
  1568. other: Tensor,
  1569. *,
  1570. alpha: Number | _complex = 1,
  1571. ) -> tuple[Tensor, ...]: ...
  1572. @overload
  1573. def _foreach_add(
  1574. self: tuple[Tensor, ...] | list[Tensor] | None,
  1575. scalar: Number | _complex,
  1576. ) -> tuple[Tensor, ...]: ...
  1577. @overload
  1578. def _foreach_add_(
  1579. self: tuple[Tensor, ...] | list[Tensor] | None,
  1580. scalars: Sequence[Number | _complex],
  1581. ) -> None: ...
  1582. @overload
  1583. def _foreach_add_(
  1584. self: tuple[Tensor, ...] | list[Tensor] | None,
  1585. other: tuple[Tensor, ...] | list[Tensor] | None,
  1586. *,
  1587. alpha: Number | _complex = 1,
  1588. ) -> None: ...
  1589. @overload
  1590. def _foreach_add_(
  1591. self: tuple[Tensor, ...] | list[Tensor] | None,
  1592. other: Tensor,
  1593. *,
  1594. alpha: Number | _complex = 1,
  1595. ) -> None: ...
  1596. @overload
  1597. def _foreach_add_(
  1598. self: tuple[Tensor, ...] | list[Tensor] | None,
  1599. scalar: Number | _complex,
  1600. ) -> None: ...
  1601. @overload
  1602. def _foreach_addcdiv(
  1603. self: tuple[Tensor, ...] | list[Tensor] | None,
  1604. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1605. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1606. scalars: Sequence[Number | _complex],
  1607. ) -> tuple[Tensor, ...]: ...
  1608. @overload
  1609. def _foreach_addcdiv(
  1610. self: tuple[Tensor, ...] | list[Tensor] | None,
  1611. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1612. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1613. scalars: Tensor,
  1614. ) -> tuple[Tensor, ...]: ...
  1615. @overload
  1616. def _foreach_addcdiv(
  1617. self: tuple[Tensor, ...] | list[Tensor] | None,
  1618. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1619. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1620. value: Number | _complex = 1,
  1621. ) -> tuple[Tensor, ...]: ...
  1622. @overload
  1623. def _foreach_addcdiv_(
  1624. self: tuple[Tensor, ...] | list[Tensor] | None,
  1625. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1626. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1627. scalars: Sequence[Number | _complex],
  1628. ) -> None: ...
  1629. @overload
  1630. def _foreach_addcdiv_(
  1631. self: tuple[Tensor, ...] | list[Tensor] | None,
  1632. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1633. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1634. scalars: Tensor,
  1635. ) -> None: ...
  1636. @overload
  1637. def _foreach_addcdiv_(
  1638. self: tuple[Tensor, ...] | list[Tensor] | None,
  1639. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1640. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1641. value: Number | _complex = 1,
  1642. ) -> None: ...
  1643. @overload
  1644. def _foreach_addcmul(
  1645. self: tuple[Tensor, ...] | list[Tensor] | None,
  1646. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1647. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1648. scalars: Sequence[Number | _complex],
  1649. ) -> tuple[Tensor, ...]: ...
  1650. @overload
  1651. def _foreach_addcmul(
  1652. self: tuple[Tensor, ...] | list[Tensor] | None,
  1653. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1654. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1655. scalars: Tensor,
  1656. ) -> tuple[Tensor, ...]: ...
  1657. @overload
  1658. def _foreach_addcmul(
  1659. self: tuple[Tensor, ...] | list[Tensor] | None,
  1660. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1661. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1662. value: Number | _complex = 1,
  1663. ) -> tuple[Tensor, ...]: ...
  1664. @overload
  1665. def _foreach_addcmul_(
  1666. self: tuple[Tensor, ...] | list[Tensor] | None,
  1667. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1668. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1669. scalars: Sequence[Number | _complex],
  1670. ) -> None: ...
  1671. @overload
  1672. def _foreach_addcmul_(
  1673. self: tuple[Tensor, ...] | list[Tensor] | None,
  1674. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1675. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1676. scalars: Tensor,
  1677. ) -> None: ...
  1678. @overload
  1679. def _foreach_addcmul_(
  1680. self: tuple[Tensor, ...] | list[Tensor] | None,
  1681. tensor1: tuple[Tensor, ...] | list[Tensor] | None,
  1682. tensor2: tuple[Tensor, ...] | list[Tensor] | None,
  1683. value: Number | _complex = 1,
  1684. ) -> None: ...
  1685. def _foreach_asin(
  1686. self: tuple[Tensor, ...] | list[Tensor] | None,
  1687. ) -> tuple[Tensor, ...]:
  1688. r"""
  1689. _foreach_asin(self: List[Tensor]) -> List[Tensor]
  1690. Apply :func:`torch.asin` to each Tensor of the input list.
  1691. """
  1692. def _foreach_asin_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1693. r"""
  1694. _foreach_asin_(self: List[Tensor]) -> None
  1695. Apply :func:`torch.asin` to each Tensor of the input list.
  1696. """
  1697. def _foreach_atan(
  1698. self: tuple[Tensor, ...] | list[Tensor] | None,
  1699. ) -> tuple[Tensor, ...]:
  1700. r"""
  1701. _foreach_atan(self: List[Tensor]) -> List[Tensor]
  1702. Apply :func:`torch.atan` to each Tensor of the input list.
  1703. """
  1704. def _foreach_atan_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1705. r"""
  1706. _foreach_atan_(self: List[Tensor]) -> None
  1707. Apply :func:`torch.atan` to each Tensor of the input list.
  1708. """
  1709. def _foreach_ceil(
  1710. self: tuple[Tensor, ...] | list[Tensor] | None,
  1711. ) -> tuple[Tensor, ...]:
  1712. r"""
  1713. _foreach_ceil(self: List[Tensor]) -> List[Tensor]
  1714. Apply :func:`torch.ceil` to each Tensor of the input list.
  1715. """
  1716. def _foreach_ceil_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1717. r"""
  1718. _foreach_ceil_(self: List[Tensor]) -> None
  1719. Apply :func:`torch.ceil` to each Tensor of the input list.
  1720. """
  1721. @overload
  1722. def _foreach_clamp_max(
  1723. self: tuple[Tensor, ...] | list[Tensor] | None,
  1724. scalars: Sequence[Number | _complex],
  1725. ) -> tuple[Tensor, ...]: ...
  1726. @overload
  1727. def _foreach_clamp_max(
  1728. self: tuple[Tensor, ...] | list[Tensor] | None,
  1729. scalar: Number | _complex,
  1730. ) -> tuple[Tensor, ...]: ...
  1731. @overload
  1732. def _foreach_clamp_max(
  1733. self: tuple[Tensor, ...] | list[Tensor] | None,
  1734. other: tuple[Tensor, ...] | list[Tensor] | None,
  1735. ) -> tuple[Tensor, ...]: ...
  1736. @overload
  1737. def _foreach_clamp_max_(
  1738. self: tuple[Tensor, ...] | list[Tensor] | None,
  1739. scalars: Sequence[Number | _complex],
  1740. ) -> None: ...
  1741. @overload
  1742. def _foreach_clamp_max_(
  1743. self: tuple[Tensor, ...] | list[Tensor] | None,
  1744. scalar: Number | _complex,
  1745. ) -> None: ...
  1746. @overload
  1747. def _foreach_clamp_max_(
  1748. self: tuple[Tensor, ...] | list[Tensor] | None,
  1749. other: tuple[Tensor, ...] | list[Tensor] | None,
  1750. ) -> None: ...
  1751. @overload
  1752. def _foreach_clamp_min(
  1753. self: tuple[Tensor, ...] | list[Tensor] | None,
  1754. scalars: Sequence[Number | _complex],
  1755. ) -> tuple[Tensor, ...]: ...
  1756. @overload
  1757. def _foreach_clamp_min(
  1758. self: tuple[Tensor, ...] | list[Tensor] | None,
  1759. scalar: Number | _complex,
  1760. ) -> tuple[Tensor, ...]: ...
  1761. @overload
  1762. def _foreach_clamp_min(
  1763. self: tuple[Tensor, ...] | list[Tensor] | None,
  1764. other: tuple[Tensor, ...] | list[Tensor] | None,
  1765. ) -> tuple[Tensor, ...]: ...
  1766. @overload
  1767. def _foreach_clamp_min_(
  1768. self: tuple[Tensor, ...] | list[Tensor] | None,
  1769. scalars: Sequence[Number | _complex],
  1770. ) -> None: ...
  1771. @overload
  1772. def _foreach_clamp_min_(
  1773. self: tuple[Tensor, ...] | list[Tensor] | None,
  1774. scalar: Number | _complex,
  1775. ) -> None: ...
  1776. @overload
  1777. def _foreach_clamp_min_(
  1778. self: tuple[Tensor, ...] | list[Tensor] | None,
  1779. other: tuple[Tensor, ...] | list[Tensor] | None,
  1780. ) -> None: ...
  1781. def _foreach_copy_(
  1782. self: tuple[Tensor, ...] | list[Tensor] | None,
  1783. src: tuple[Tensor, ...] | list[Tensor] | None,
  1784. non_blocking: _bool = False,
  1785. ) -> None: ...
  1786. def _foreach_cos(
  1787. self: tuple[Tensor, ...] | list[Tensor] | None,
  1788. ) -> tuple[Tensor, ...]:
  1789. r"""
  1790. _foreach_cos(self: List[Tensor]) -> List[Tensor]
  1791. Apply :func:`torch.cos` to each Tensor of the input list.
  1792. """
  1793. def _foreach_cos_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1794. r"""
  1795. _foreach_cos_(self: List[Tensor]) -> None
  1796. Apply :func:`torch.cos` to each Tensor of the input list.
  1797. """
  1798. def _foreach_cosh(
  1799. self: tuple[Tensor, ...] | list[Tensor] | None,
  1800. ) -> tuple[Tensor, ...]:
  1801. r"""
  1802. _foreach_cosh(self: List[Tensor]) -> List[Tensor]
  1803. Apply :func:`torch.cosh` to each Tensor of the input list.
  1804. """
  1805. def _foreach_cosh_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1806. r"""
  1807. _foreach_cosh_(self: List[Tensor]) -> None
  1808. Apply :func:`torch.cosh` to each Tensor of the input list.
  1809. """
  1810. @overload
  1811. def _foreach_div(
  1812. self: tuple[Tensor, ...] | list[Tensor] | None,
  1813. scalars: Sequence[Number | _complex],
  1814. ) -> tuple[Tensor, ...]: ...
  1815. @overload
  1816. def _foreach_div(
  1817. self: tuple[Tensor, ...] | list[Tensor] | None,
  1818. other: Tensor,
  1819. ) -> tuple[Tensor, ...]: ...
  1820. @overload
  1821. def _foreach_div(
  1822. self: tuple[Tensor, ...] | list[Tensor] | None,
  1823. scalar: Number | _complex,
  1824. ) -> tuple[Tensor, ...]: ...
  1825. @overload
  1826. def _foreach_div(
  1827. self: tuple[Tensor, ...] | list[Tensor] | None,
  1828. other: tuple[Tensor, ...] | list[Tensor] | None,
  1829. ) -> tuple[Tensor, ...]: ...
  1830. @overload
  1831. def _foreach_div_(
  1832. self: tuple[Tensor, ...] | list[Tensor] | None,
  1833. scalars: Sequence[Number | _complex],
  1834. ) -> None: ...
  1835. @overload
  1836. def _foreach_div_(
  1837. self: tuple[Tensor, ...] | list[Tensor] | None,
  1838. other: Tensor,
  1839. ) -> None: ...
  1840. @overload
  1841. def _foreach_div_(
  1842. self: tuple[Tensor, ...] | list[Tensor] | None,
  1843. scalar: Number | _complex,
  1844. ) -> None: ...
  1845. @overload
  1846. def _foreach_div_(
  1847. self: tuple[Tensor, ...] | list[Tensor] | None,
  1848. other: tuple[Tensor, ...] | list[Tensor] | None,
  1849. ) -> None: ...
  1850. def _foreach_erf(
  1851. self: tuple[Tensor, ...] | list[Tensor] | None,
  1852. ) -> tuple[Tensor, ...]:
  1853. r"""
  1854. _foreach_erf(self: List[Tensor]) -> List[Tensor]
  1855. Apply :func:`torch.erf` to each Tensor of the input list.
  1856. """
  1857. def _foreach_erf_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1858. r"""
  1859. _foreach_erf_(self: List[Tensor]) -> None
  1860. Apply :func:`torch.erf` to each Tensor of the input list.
  1861. """
  1862. def _foreach_erfc(
  1863. self: tuple[Tensor, ...] | list[Tensor] | None,
  1864. ) -> tuple[Tensor, ...]:
  1865. r"""
  1866. _foreach_erfc(self: List[Tensor]) -> List[Tensor]
  1867. Apply :func:`torch.erfc` to each Tensor of the input list.
  1868. """
  1869. def _foreach_erfc_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1870. r"""
  1871. _foreach_erfc_(self: List[Tensor]) -> None
  1872. Apply :func:`torch.erfc` to each Tensor of the input list.
  1873. """
  1874. def _foreach_exp(
  1875. self: tuple[Tensor, ...] | list[Tensor] | None,
  1876. ) -> tuple[Tensor, ...]:
  1877. r"""
  1878. _foreach_exp(self: List[Tensor]) -> List[Tensor]
  1879. Apply :func:`torch.exp` to each Tensor of the input list.
  1880. """
  1881. def _foreach_exp_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1882. r"""
  1883. _foreach_exp_(self: List[Tensor]) -> None
  1884. Apply :func:`torch.exp` to each Tensor of the input list.
  1885. """
  1886. def _foreach_expm1(
  1887. self: tuple[Tensor, ...] | list[Tensor] | None,
  1888. ) -> tuple[Tensor, ...]:
  1889. r"""
  1890. _foreach_expm1(self: List[Tensor]) -> List[Tensor]
  1891. Apply :func:`torch.expm1` to each Tensor of the input list.
  1892. """
  1893. def _foreach_expm1_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1894. r"""
  1895. _foreach_expm1_(self: List[Tensor]) -> None
  1896. Apply :func:`torch.expm1` to each Tensor of the input list.
  1897. """
  1898. def _foreach_floor(
  1899. self: tuple[Tensor, ...] | list[Tensor] | None,
  1900. ) -> tuple[Tensor, ...]:
  1901. r"""
  1902. _foreach_floor(self: List[Tensor]) -> List[Tensor]
  1903. Apply :func:`torch.floor` to each Tensor of the input list.
  1904. """
  1905. def _foreach_floor_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1906. r"""
  1907. _foreach_floor_(self: List[Tensor]) -> None
  1908. Apply :func:`torch.floor` to each Tensor of the input list.
  1909. """
  1910. def _foreach_frac(
  1911. self: tuple[Tensor, ...] | list[Tensor] | None,
  1912. ) -> tuple[Tensor, ...]:
  1913. r"""
  1914. _foreach_frac(self: List[Tensor]) -> List[Tensor]
  1915. Apply :func:`torch.frac` to each Tensor of the input list.
  1916. """
  1917. def _foreach_frac_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1918. r"""
  1919. _foreach_frac_(self: List[Tensor]) -> None
  1920. Apply :func:`torch.frac` to each Tensor of the input list.
  1921. """
  1922. @overload
  1923. def _foreach_lerp(
  1924. self: tuple[Tensor, ...] | list[Tensor] | None,
  1925. tensors1: tuple[Tensor, ...] | list[Tensor] | None,
  1926. weight: Number | _complex,
  1927. ) -> tuple[Tensor, ...]: ...
  1928. @overload
  1929. def _foreach_lerp(
  1930. self: tuple[Tensor, ...] | list[Tensor] | None,
  1931. tensors1: tuple[Tensor, ...] | list[Tensor] | None,
  1932. weight: Sequence[Number | _complex],
  1933. ) -> tuple[Tensor, ...]: ...
  1934. @overload
  1935. def _foreach_lerp(
  1936. self: tuple[Tensor, ...] | list[Tensor] | None,
  1937. tensors1: tuple[Tensor, ...] | list[Tensor] | None,
  1938. weights: tuple[Tensor, ...] | list[Tensor] | None,
  1939. ) -> tuple[Tensor, ...]: ...
  1940. @overload
  1941. def _foreach_lerp_(
  1942. self: tuple[Tensor, ...] | list[Tensor] | None,
  1943. tensors1: tuple[Tensor, ...] | list[Tensor] | None,
  1944. weight: Number | _complex,
  1945. ) -> None: ...
  1946. @overload
  1947. def _foreach_lerp_(
  1948. self: tuple[Tensor, ...] | list[Tensor] | None,
  1949. tensors1: tuple[Tensor, ...] | list[Tensor] | None,
  1950. weight: Sequence[Number | _complex],
  1951. ) -> None: ...
  1952. @overload
  1953. def _foreach_lerp_(
  1954. self: tuple[Tensor, ...] | list[Tensor] | None,
  1955. tensors1: tuple[Tensor, ...] | list[Tensor] | None,
  1956. weights: tuple[Tensor, ...] | list[Tensor] | None,
  1957. ) -> None: ...
  1958. def _foreach_lgamma(
  1959. self: tuple[Tensor, ...] | list[Tensor] | None,
  1960. ) -> tuple[Tensor, ...]:
  1961. r"""
  1962. _foreach_lgamma(self: List[Tensor]) -> List[Tensor]
  1963. Apply :func:`torch.lgamma` to each Tensor of the input list.
  1964. """
  1965. def _foreach_lgamma_(
  1966. self: tuple[Tensor, ...] | list[Tensor] | None,
  1967. ) -> None:
  1968. r"""
  1969. _foreach_lgamma_(self: List[Tensor]) -> None
  1970. Apply :func:`torch.lgamma` to each Tensor of the input list.
  1971. """
  1972. def _foreach_log(
  1973. self: tuple[Tensor, ...] | list[Tensor] | None,
  1974. ) -> tuple[Tensor, ...]:
  1975. r"""
  1976. _foreach_log(self: List[Tensor]) -> List[Tensor]
  1977. Apply :func:`torch.log` to each Tensor of the input list.
  1978. """
  1979. def _foreach_log10(
  1980. self: tuple[Tensor, ...] | list[Tensor] | None,
  1981. ) -> tuple[Tensor, ...]:
  1982. r"""
  1983. _foreach_log10(self: List[Tensor]) -> List[Tensor]
  1984. Apply :func:`torch.log10` to each Tensor of the input list.
  1985. """
  1986. def _foreach_log10_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1987. r"""
  1988. _foreach_log10_(self: List[Tensor]) -> None
  1989. Apply :func:`torch.log10` to each Tensor of the input list.
  1990. """
  1991. def _foreach_log1p(
  1992. self: tuple[Tensor, ...] | list[Tensor] | None,
  1993. ) -> tuple[Tensor, ...]:
  1994. r"""
  1995. _foreach_log1p(self: List[Tensor]) -> List[Tensor]
  1996. Apply :func:`torch.log1p` to each Tensor of the input list.
  1997. """
  1998. def _foreach_log1p_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  1999. r"""
  2000. _foreach_log1p_(self: List[Tensor]) -> None
  2001. Apply :func:`torch.log1p` to each Tensor of the input list.
  2002. """
  2003. def _foreach_log2(
  2004. self: tuple[Tensor, ...] | list[Tensor] | None,
  2005. ) -> tuple[Tensor, ...]:
  2006. r"""
  2007. _foreach_log2(self: List[Tensor]) -> List[Tensor]
  2008. Apply :func:`torch.log2` to each Tensor of the input list.
  2009. """
  2010. def _foreach_log2_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2011. r"""
  2012. _foreach_log2_(self: List[Tensor]) -> None
  2013. Apply :func:`torch.log2` to each Tensor of the input list.
  2014. """
  2015. def _foreach_log_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2016. r"""
  2017. _foreach_log_(self: List[Tensor]) -> None
  2018. Apply :func:`torch.log` to each Tensor of the input list.
  2019. """
  2020. def _foreach_max(
  2021. self: tuple[Tensor, ...] | list[Tensor] | None,
  2022. ) -> tuple[Tensor, ...]: ...
  2023. @overload
  2024. def _foreach_maximum(
  2025. self: tuple[Tensor, ...] | list[Tensor] | None,
  2026. scalars: Sequence[Number | _complex],
  2027. ) -> tuple[Tensor, ...]: ...
  2028. @overload
  2029. def _foreach_maximum(
  2030. self: tuple[Tensor, ...] | list[Tensor] | None,
  2031. scalar: Number | _complex,
  2032. ) -> tuple[Tensor, ...]: ...
  2033. @overload
  2034. def _foreach_maximum(
  2035. self: tuple[Tensor, ...] | list[Tensor] | None,
  2036. other: tuple[Tensor, ...] | list[Tensor] | None,
  2037. ) -> tuple[Tensor, ...]: ...
  2038. @overload
  2039. def _foreach_maximum_(
  2040. self: tuple[Tensor, ...] | list[Tensor] | None,
  2041. scalars: Sequence[Number | _complex],
  2042. ) -> None: ...
  2043. @overload
  2044. def _foreach_maximum_(
  2045. self: tuple[Tensor, ...] | list[Tensor] | None,
  2046. scalar: Number | _complex,
  2047. ) -> None: ...
  2048. @overload
  2049. def _foreach_maximum_(
  2050. self: tuple[Tensor, ...] | list[Tensor] | None,
  2051. other: tuple[Tensor, ...] | list[Tensor] | None,
  2052. ) -> None: ...
  2053. @overload
  2054. def _foreach_minimum(
  2055. self: tuple[Tensor, ...] | list[Tensor] | None,
  2056. scalars: Sequence[Number | _complex],
  2057. ) -> tuple[Tensor, ...]: ...
  2058. @overload
  2059. def _foreach_minimum(
  2060. self: tuple[Tensor, ...] | list[Tensor] | None,
  2061. scalar: Number | _complex,
  2062. ) -> tuple[Tensor, ...]: ...
  2063. @overload
  2064. def _foreach_minimum(
  2065. self: tuple[Tensor, ...] | list[Tensor] | None,
  2066. other: tuple[Tensor, ...] | list[Tensor] | None,
  2067. ) -> tuple[Tensor, ...]: ...
  2068. @overload
  2069. def _foreach_minimum_(
  2070. self: tuple[Tensor, ...] | list[Tensor] | None,
  2071. scalars: Sequence[Number | _complex],
  2072. ) -> None: ...
  2073. @overload
  2074. def _foreach_minimum_(
  2075. self: tuple[Tensor, ...] | list[Tensor] | None,
  2076. scalar: Number | _complex,
  2077. ) -> None: ...
  2078. @overload
  2079. def _foreach_minimum_(
  2080. self: tuple[Tensor, ...] | list[Tensor] | None,
  2081. other: tuple[Tensor, ...] | list[Tensor] | None,
  2082. ) -> None: ...
  2083. @overload
  2084. def _foreach_mul(
  2085. self: tuple[Tensor, ...] | list[Tensor] | None,
  2086. scalars: Sequence[Number | _complex],
  2087. ) -> tuple[Tensor, ...]: ...
  2088. @overload
  2089. def _foreach_mul(
  2090. self: tuple[Tensor, ...] | list[Tensor] | None,
  2091. other: Tensor,
  2092. ) -> tuple[Tensor, ...]: ...
  2093. @overload
  2094. def _foreach_mul(
  2095. self: tuple[Tensor, ...] | list[Tensor] | None,
  2096. scalar: Number | _complex,
  2097. ) -> tuple[Tensor, ...]: ...
  2098. @overload
  2099. def _foreach_mul(
  2100. self: tuple[Tensor, ...] | list[Tensor] | None,
  2101. other: tuple[Tensor, ...] | list[Tensor] | None,
  2102. ) -> tuple[Tensor, ...]: ...
  2103. @overload
  2104. def _foreach_mul_(
  2105. self: tuple[Tensor, ...] | list[Tensor] | None,
  2106. scalars: Sequence[Number | _complex],
  2107. ) -> None: ...
  2108. @overload
  2109. def _foreach_mul_(
  2110. self: tuple[Tensor, ...] | list[Tensor] | None,
  2111. other: Tensor,
  2112. ) -> None: ...
  2113. @overload
  2114. def _foreach_mul_(
  2115. self: tuple[Tensor, ...] | list[Tensor] | None,
  2116. scalar: Number | _complex,
  2117. ) -> None: ...
  2118. @overload
  2119. def _foreach_mul_(
  2120. self: tuple[Tensor, ...] | list[Tensor] | None,
  2121. other: tuple[Tensor, ...] | list[Tensor] | None,
  2122. ) -> None: ...
  2123. def _foreach_neg(
  2124. self: tuple[Tensor, ...] | list[Tensor] | None,
  2125. ) -> tuple[Tensor, ...]:
  2126. r"""
  2127. _foreach_neg(self: List[Tensor]) -> List[Tensor]
  2128. Apply :func:`torch.neg` to each Tensor of the input list.
  2129. """
  2130. def _foreach_neg_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2131. r"""
  2132. _foreach_neg_(self: List[Tensor]) -> None
  2133. Apply :func:`torch.neg` to each Tensor of the input list.
  2134. """
  2135. def _foreach_norm(
  2136. self: tuple[Tensor, ...] | list[Tensor] | None,
  2137. ord: Number | _complex = 2,
  2138. dtype: _dtype | None = None,
  2139. ) -> tuple[Tensor, ...]: ...
  2140. @overload
  2141. def _foreach_pow(
  2142. self: tuple[Tensor, ...] | list[Tensor] | None,
  2143. exponent: Sequence[Number | _complex],
  2144. ) -> tuple[Tensor, ...]: ...
  2145. @overload
  2146. def _foreach_pow(
  2147. self: tuple[Tensor, ...] | list[Tensor] | None,
  2148. exponent: Number | _complex,
  2149. ) -> tuple[Tensor, ...]: ...
  2150. @overload
  2151. def _foreach_pow(
  2152. self: tuple[Tensor, ...] | list[Tensor] | None,
  2153. exponent: tuple[Tensor, ...] | list[Tensor] | None,
  2154. ) -> tuple[Tensor, ...]: ...
  2155. @overload
  2156. def _foreach_pow(
  2157. self: Number | _complex,
  2158. exponent: tuple[Tensor, ...] | list[Tensor] | None,
  2159. ) -> tuple[Tensor, ...]: ...
  2160. @overload
  2161. def _foreach_pow_(
  2162. self: tuple[Tensor, ...] | list[Tensor] | None,
  2163. exponent: Sequence[Number | _complex],
  2164. ) -> None: ...
  2165. @overload
  2166. def _foreach_pow_(
  2167. self: tuple[Tensor, ...] | list[Tensor] | None,
  2168. exponent: Number | _complex,
  2169. ) -> None: ...
  2170. @overload
  2171. def _foreach_pow_(
  2172. self: tuple[Tensor, ...] | list[Tensor] | None,
  2173. exponent: tuple[Tensor, ...] | list[Tensor] | None,
  2174. ) -> None: ...
  2175. def _foreach_reciprocal(
  2176. self: tuple[Tensor, ...] | list[Tensor] | None,
  2177. ) -> tuple[Tensor, ...]:
  2178. r"""
  2179. _foreach_reciprocal(self: List[Tensor]) -> List[Tensor]
  2180. Apply :func:`torch.reciprocal` to each Tensor of the input list.
  2181. """
  2182. def _foreach_reciprocal_(
  2183. self: tuple[Tensor, ...] | list[Tensor] | None,
  2184. ) -> None:
  2185. r"""
  2186. _foreach_reciprocal_(self: List[Tensor]) -> None
  2187. Apply :func:`torch.reciprocal` to each Tensor of the input list.
  2188. """
  2189. def _foreach_round(
  2190. self: tuple[Tensor, ...] | list[Tensor] | None,
  2191. ) -> tuple[Tensor, ...]:
  2192. r"""
  2193. _foreach_round(self: List[Tensor]) -> List[Tensor]
  2194. Apply :func:`torch.round` to each Tensor of the input list.
  2195. """
  2196. def _foreach_round_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2197. r"""
  2198. _foreach_round_(self: List[Tensor]) -> None
  2199. Apply :func:`torch.round` to each Tensor of the input list.
  2200. """
  2201. def _foreach_rsqrt(
  2202. self: tuple[Tensor, ...] | list[Tensor] | None,
  2203. ) -> tuple[Tensor, ...]: ...
  2204. def _foreach_rsqrt_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None: ...
  2205. def _foreach_sigmoid(
  2206. self: tuple[Tensor, ...] | list[Tensor] | None,
  2207. ) -> tuple[Tensor, ...]:
  2208. r"""
  2209. _foreach_sigmoid(self: List[Tensor]) -> List[Tensor]
  2210. Apply :func:`torch.sigmoid` to each Tensor of the input list.
  2211. """
  2212. def _foreach_sigmoid_(
  2213. self: tuple[Tensor, ...] | list[Tensor] | None,
  2214. ) -> None:
  2215. r"""
  2216. _foreach_sigmoid_(self: List[Tensor]) -> None
  2217. Apply :func:`torch.sigmoid` to each Tensor of the input list.
  2218. """
  2219. def _foreach_sign(
  2220. self: tuple[Tensor, ...] | list[Tensor] | None,
  2221. ) -> tuple[Tensor, ...]: ...
  2222. def _foreach_sign_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None: ...
  2223. def _foreach_sin(
  2224. self: tuple[Tensor, ...] | list[Tensor] | None,
  2225. ) -> tuple[Tensor, ...]:
  2226. r"""
  2227. _foreach_sin(self: List[Tensor]) -> List[Tensor]
  2228. Apply :func:`torch.sin` to each Tensor of the input list.
  2229. """
  2230. def _foreach_sin_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2231. r"""
  2232. _foreach_sin_(self: List[Tensor]) -> None
  2233. Apply :func:`torch.sin` to each Tensor of the input list.
  2234. """
  2235. def _foreach_sinh(
  2236. self: tuple[Tensor, ...] | list[Tensor] | None,
  2237. ) -> tuple[Tensor, ...]:
  2238. r"""
  2239. _foreach_sinh(self: List[Tensor]) -> List[Tensor]
  2240. Apply :func:`torch.sinh` to each Tensor of the input list.
  2241. """
  2242. def _foreach_sinh_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2243. r"""
  2244. _foreach_sinh_(self: List[Tensor]) -> None
  2245. Apply :func:`torch.sinh` to each Tensor of the input list.
  2246. """
  2247. def _foreach_sqrt(
  2248. self: tuple[Tensor, ...] | list[Tensor] | None,
  2249. ) -> tuple[Tensor, ...]:
  2250. r"""
  2251. _foreach_sqrt(self: List[Tensor]) -> List[Tensor]
  2252. Apply :func:`torch.sqrt` to each Tensor of the input list.
  2253. """
  2254. def _foreach_sqrt_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2255. r"""
  2256. _foreach_sqrt_(self: List[Tensor]) -> None
  2257. Apply :func:`torch.sqrt` to each Tensor of the input list.
  2258. """
  2259. @overload
  2260. def _foreach_sub(
  2261. self: tuple[Tensor, ...] | list[Tensor] | None,
  2262. scalars: Sequence[Number | _complex],
  2263. ) -> tuple[Tensor, ...]: ...
  2264. @overload
  2265. def _foreach_sub(
  2266. self: tuple[Tensor, ...] | list[Tensor] | None,
  2267. other: tuple[Tensor, ...] | list[Tensor] | None,
  2268. *,
  2269. alpha: Number | _complex = 1,
  2270. ) -> tuple[Tensor, ...]: ...
  2271. @overload
  2272. def _foreach_sub(
  2273. self: tuple[Tensor, ...] | list[Tensor] | None,
  2274. scalar: Number | _complex,
  2275. ) -> tuple[Tensor, ...]: ...
  2276. @overload
  2277. def _foreach_sub_(
  2278. self: tuple[Tensor, ...] | list[Tensor] | None,
  2279. scalars: Sequence[Number | _complex],
  2280. ) -> None: ...
  2281. @overload
  2282. def _foreach_sub_(
  2283. self: tuple[Tensor, ...] | list[Tensor] | None,
  2284. other: tuple[Tensor, ...] | list[Tensor] | None,
  2285. *,
  2286. alpha: Number | _complex = 1,
  2287. ) -> None: ...
  2288. @overload
  2289. def _foreach_sub_(
  2290. self: tuple[Tensor, ...] | list[Tensor] | None,
  2291. scalar: Number | _complex,
  2292. ) -> None: ...
  2293. def _foreach_tan(
  2294. self: tuple[Tensor, ...] | list[Tensor] | None,
  2295. ) -> tuple[Tensor, ...]:
  2296. r"""
  2297. _foreach_tan(self: List[Tensor]) -> List[Tensor]
  2298. Apply :func:`torch.tan` to each Tensor of the input list.
  2299. """
  2300. def _foreach_tan_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2301. r"""
  2302. _foreach_tan_(self: List[Tensor]) -> None
  2303. Apply :func:`torch.tan` to each Tensor of the input list.
  2304. """
  2305. def _foreach_tanh(
  2306. self: tuple[Tensor, ...] | list[Tensor] | None,
  2307. ) -> tuple[Tensor, ...]:
  2308. r"""
  2309. _foreach_tanh(self: List[Tensor]) -> List[Tensor]
  2310. Apply :func:`torch.tanh` to each Tensor of the input list.
  2311. """
  2312. def _foreach_tanh_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2313. r"""
  2314. _foreach_tanh_(self: List[Tensor]) -> None
  2315. Apply :func:`torch.tanh` to each Tensor of the input list.
  2316. """
  2317. def _foreach_trunc(
  2318. self: tuple[Tensor, ...] | list[Tensor] | None,
  2319. ) -> tuple[Tensor, ...]:
  2320. r"""
  2321. _foreach_trunc(self: List[Tensor]) -> List[Tensor]
  2322. Apply :func:`torch.trunc` to each Tensor of the input list.
  2323. """
  2324. def _foreach_trunc_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2325. r"""
  2326. _foreach_trunc_(self: List[Tensor]) -> None
  2327. Apply :func:`torch.trunc` to each Tensor of the input list.
  2328. """
  2329. def _foreach_zero_(self: tuple[Tensor, ...] | list[Tensor] | None) -> None:
  2330. r"""
  2331. _foreach_zero_(self: List[Tensor]) -> None
  2332. Apply :func:`torch.zero` to each Tensor of the input list.
  2333. """
  2334. def _from_functional_tensor(t: Tensor) -> Tensor: ...
  2335. def _functional_assert_async(
  2336. input: Tensor,
  2337. assert_msg: str,
  2338. dep_token: Tensor,
  2339. ) -> Tensor: ...
  2340. def _functional_assert_scalar(
  2341. self: Number | _complex,
  2342. assert_msg: str,
  2343. dep_token: Tensor,
  2344. ) -> Tensor: ...
  2345. def _functional_sym_constrain_range(
  2346. size: Number | _complex,
  2347. min: _int | None,
  2348. max: _int | None,
  2349. dep_token: Tensor,
  2350. ) -> Tensor: ...
  2351. def _functional_sym_constrain_range_for_size(
  2352. size: Number | _complex,
  2353. min: _int | None,
  2354. max: _int | None,
  2355. dep_token: Tensor,
  2356. ) -> Tensor: ...
  2357. def _functionalize_apply_view_metas(tensor: Tensor, base: Tensor) -> Tensor: ...
  2358. def _functionalize_are_all_mutations_hidden_from_autograd(
  2359. t: Tensor,
  2360. ) -> _bool: ...
  2361. def _functionalize_are_all_mutations_under_no_grad_or_inference_mode(
  2362. t: Tensor,
  2363. ) -> _bool: ...
  2364. def _functionalize_commit_update(t: Tensor) -> None: ...
  2365. def _functionalize_has_metadata_mutation(tensor: Tensor) -> _bool: ...
  2366. def _functionalize_inductor_storage_resized_counter(t: Tensor) -> _int: ...
  2367. def _functionalize_is_symbolic(tensor: Tensor) -> _bool: ...
  2368. def _functionalize_mark_mutation_hidden_from_autograd(t: Tensor) -> None: ...
  2369. def _functionalize_mark_storage_changed(tensor: Tensor) -> _bool: ...
  2370. def _functionalize_mutation_counter(t: Tensor) -> _int: ...
  2371. def _functionalize_replace(self_: Tensor, other: Tensor) -> None: ...
  2372. def _functionalize_storage_changed_counter(t: Tensor) -> _int: ...
  2373. def _functionalize_sync(t: Tensor) -> None: ...
  2374. def _functionalize_unsafe_set(dst: Tensor, src: Tensor) -> None: ...
  2375. def _functionalize_was_inductor_storage_resized(t: Tensor) -> _bool: ...
  2376. def _functionalize_was_storage_changed(tensor: Tensor) -> _bool: ...
  2377. @overload
  2378. def _fused_adagrad_(
  2379. self: tuple[Tensor, ...] | list[Tensor] | None,
  2380. grads: tuple[Tensor, ...] | list[Tensor] | None,
  2381. state_sums: tuple[Tensor, ...] | list[Tensor] | None,
  2382. state_steps: tuple[Tensor, ...] | list[Tensor] | None,
  2383. *,
  2384. lr: Tensor,
  2385. lr_decay: _float,
  2386. weight_decay: _float,
  2387. eps: _float,
  2388. maximize: _bool,
  2389. grad_scale: Tensor | None = None,
  2390. found_inf: Tensor | None = None,
  2391. ) -> None: ...
  2392. @overload
  2393. def _fused_adagrad_(
  2394. self: tuple[Tensor, ...] | list[Tensor] | None,
  2395. grads: tuple[Tensor, ...] | list[Tensor] | None,
  2396. state_sums: tuple[Tensor, ...] | list[Tensor] | None,
  2397. state_steps: tuple[Tensor, ...] | list[Tensor] | None,
  2398. *,
  2399. lr: _float,
  2400. lr_decay: _float,
  2401. weight_decay: _float,
  2402. eps: _float,
  2403. maximize: _bool,
  2404. grad_scale: Tensor | None = None,
  2405. found_inf: Tensor | None = None,
  2406. ) -> None: ...
  2407. @overload
  2408. def _fused_adam_(
  2409. self: tuple[Tensor, ...] | list[Tensor] | None,
  2410. grads: tuple[Tensor, ...] | list[Tensor] | None,
  2411. exp_avgs: tuple[Tensor, ...] | list[Tensor] | None,
  2412. exp_avg_sqs: tuple[Tensor, ...] | list[Tensor] | None,
  2413. max_exp_avg_sqs: tuple[Tensor, ...] | list[Tensor] | None,
  2414. state_steps: tuple[Tensor, ...] | list[Tensor] | None,
  2415. *,
  2416. lr: Tensor,
  2417. beta1: _float,
  2418. beta2: _float,
  2419. weight_decay: _float,
  2420. eps: _float,
  2421. amsgrad: _bool,
  2422. maximize: _bool,
  2423. grad_scale: Tensor | None = None,
  2424. found_inf: Tensor | None = None,
  2425. ) -> None: ...
  2426. @overload
  2427. def _fused_adam_(
  2428. self: tuple[Tensor, ...] | list[Tensor] | None,
  2429. grads: tuple[Tensor, ...] | list[Tensor] | None,
  2430. exp_avgs: tuple[Tensor, ...] | list[Tensor] | None,
  2431. exp_avg_sqs: tuple[Tensor, ...] | list[Tensor] | None,
  2432. max_exp_avg_sqs: tuple[Tensor, ...] | list[Tensor] | None,
  2433. state_steps: tuple[Tensor, ...] | list[Tensor] | None,
  2434. *,
  2435. lr: _float,
  2436. beta1: _float,
  2437. beta2: _float,
  2438. weight_decay: _float,
  2439. eps: _float,
  2440. amsgrad: _bool,
  2441. maximize: _bool,
  2442. grad_scale: Tensor | None = None,
  2443. found_inf: Tensor | None = None,
  2444. ) -> None: ...
  2445. @overload
  2446. def _fused_adamw_(
  2447. self: tuple[Tensor, ...] | list[Tensor] | None,
  2448. grads: tuple[Tensor, ...] | list[Tensor] | None,
  2449. exp_avgs: tuple[Tensor, ...] | list[Tensor] | None,
  2450. exp_avg_sqs: tuple[Tensor, ...] | list[Tensor] | None,
  2451. max_exp_avg_sqs: tuple[Tensor, ...] | list[Tensor] | None,
  2452. state_steps: tuple[Tensor, ...] | list[Tensor] | None,
  2453. *,
  2454. lr: Tensor,
  2455. beta1: _float,
  2456. beta2: _float,
  2457. weight_decay: _float,
  2458. eps: _float,
  2459. amsgrad: _bool,
  2460. maximize: _bool,
  2461. grad_scale: Tensor | None = None,
  2462. found_inf: Tensor | None = None,
  2463. ) -> None: ...
  2464. @overload
  2465. def _fused_adamw_(
  2466. self: tuple[Tensor, ...] | list[Tensor] | None,
  2467. grads: tuple[Tensor, ...] | list[Tensor] | None,
  2468. exp_avgs: tuple[Tensor, ...] | list[Tensor] | None,
  2469. exp_avg_sqs: tuple[Tensor, ...] | list[Tensor] | None,
  2470. max_exp_avg_sqs: tuple[Tensor, ...] | list[Tensor] | None,
  2471. state_steps: tuple[Tensor, ...] | list[Tensor] | None,
  2472. *,
  2473. lr: _float,
  2474. beta1: _float,
  2475. beta2: _float,
  2476. weight_decay: _float,
  2477. eps: _float,
  2478. amsgrad: _bool,
  2479. maximize: _bool,
  2480. grad_scale: Tensor | None = None,
  2481. found_inf: Tensor | None = None,
  2482. ) -> None: ...
  2483. def _fused_dropout(
  2484. input: Tensor,
  2485. p: _float,
  2486. generator: Generator | None = None,
  2487. ) -> tuple[Tensor, Tensor]: ...
  2488. def _fused_moving_avg_obs_fq_helper(
  2489. input: Tensor,
  2490. observer_on: Tensor,
  2491. fake_quant_on: Tensor,
  2492. running_min: Tensor,
  2493. running_max: Tensor,
  2494. scale: Tensor,
  2495. zero_point: Tensor,
  2496. averaging_const: _float,
  2497. quant_min: _int,
  2498. quant_max: _int,
  2499. ch_axis: _int,
  2500. per_row_fake_quant: _bool = False,
  2501. symmetric_quant: _bool = False,
  2502. ) -> torch.return_types._fused_moving_avg_obs_fq_helper: ...
  2503. def _fused_rms_norm(
  2504. input: Tensor,
  2505. normalized_shape: _size,
  2506. weight: Tensor | None,
  2507. eps: _float | None,
  2508. ) -> tuple[Tensor, Tensor]: ...
  2509. def _fused_sdp_choice(
  2510. query: Tensor,
  2511. key: Tensor,
  2512. value: Tensor,
  2513. attn_mask: Tensor | None = None,
  2514. dropout_p: _float = 0.0,
  2515. is_causal: _bool = False,
  2516. *,
  2517. scale: _float | None = None,
  2518. enable_gqa: _bool = False,
  2519. ) -> _int: ...
  2520. @overload
  2521. def _fused_sgd_(
  2522. self: tuple[Tensor, ...] | list[Tensor] | None,
  2523. grads: tuple[Tensor, ...] | list[Tensor] | None,
  2524. momentum_buffer_list: tuple[Tensor, ...] | list[Tensor] | None,
  2525. *,
  2526. weight_decay: _float,
  2527. momentum: _float,
  2528. lr: Tensor,
  2529. dampening: _float,
  2530. nesterov: _bool,
  2531. maximize: _bool,
  2532. is_first_step: _bool,
  2533. grad_scale: Tensor | None = None,
  2534. found_inf: Tensor | None = None,
  2535. ) -> None: ...
  2536. @overload
  2537. def _fused_sgd_(
  2538. self: tuple[Tensor, ...] | list[Tensor] | None,
  2539. grads: tuple[Tensor, ...] | list[Tensor] | None,
  2540. momentum_buffer_list: tuple[Tensor, ...] | list[Tensor] | None,
  2541. *,
  2542. weight_decay: _float,
  2543. momentum: _float,
  2544. lr: _float,
  2545. dampening: _float,
  2546. nesterov: _bool,
  2547. maximize: _bool,
  2548. is_first_step: _bool,
  2549. grad_scale: Tensor | None = None,
  2550. found_inf: Tensor | None = None,
  2551. ) -> None: ...
  2552. def _fw_primal_copy(
  2553. input: Tensor,
  2554. level: _int,
  2555. *,
  2556. out: Tensor | None = None,
  2557. ) -> Tensor: ...
  2558. def _grid_sampler_2d_cpu_fallback(
  2559. input: Tensor,
  2560. grid: Tensor,
  2561. interpolation_mode: _int,
  2562. padding_mode: _int,
  2563. align_corners: _bool,
  2564. ) -> Tensor: ...
  2565. def _grouped_mm(
  2566. input: Tensor,
  2567. mat2: Tensor,
  2568. offs: Tensor | None = None,
  2569. bias: Tensor | None = None,
  2570. out_dtype: _dtype | None = None,
  2571. ) -> Tensor: ...
  2572. def _has_compatible_shallow_copy_type(
  2573. input: Tensor,
  2574. from_: Tensor,
  2575. ) -> _bool: ...
  2576. def _histogramdd_bin_edges(
  2577. input: Tensor,
  2578. bins: _size,
  2579. *,
  2580. range: Sequence[_float] | None = None,
  2581. weight: Tensor | None = None,
  2582. density: _bool = False,
  2583. ) -> tuple[Tensor, ...]: ...
  2584. def _histogramdd_from_bin_cts(
  2585. input: Tensor,
  2586. bins: _size,
  2587. *,
  2588. range: Sequence[_float] | None = None,
  2589. weight: Tensor | None = None,
  2590. density: _bool = False,
  2591. ) -> Tensor: ...
  2592. def _histogramdd_from_bin_tensors(
  2593. input: Tensor,
  2594. bins: tuple[Tensor, ...] | list[Tensor] | None,
  2595. *,
  2596. weight: Tensor | None = None,
  2597. density: _bool = False,
  2598. ) -> Tensor: ...
  2599. def _index_put_impl_(
  2600. input: Tensor,
  2601. indices: tuple[Tensor, ...] | list[Tensor] | None,
  2602. values: Tensor,
  2603. accumulate: _bool = False,
  2604. unsafe: _bool = False,
  2605. ) -> Tensor: ...
  2606. def _indices_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor: ...
  2607. def _int_mm(
  2608. input: Tensor,
  2609. mat2: Tensor,
  2610. *,
  2611. out: Tensor | None = None,
  2612. ) -> Tensor: ...
  2613. def _is_all_true(input: Tensor) -> Tensor: ...
  2614. def _is_any_true(input: Tensor) -> Tensor: ...
  2615. def _is_functional_tensor(t: Tensor) -> _bool: ...
  2616. def _is_functional_tensor_base(t: Tensor) -> _bool: ...
  2617. def _is_zerotensor(input: Tensor) -> _bool: ...
  2618. def _lazy_clone(input: Tensor) -> Tensor: ...
  2619. def _linalg_check_errors(
  2620. info: Tensor,
  2621. api_name: str,
  2622. *,
  2623. is_matrix: _bool,
  2624. ) -> None: ...
  2625. def _linalg_det(
  2626. A: Tensor,
  2627. *,
  2628. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  2629. ) -> torch.return_types._linalg_det: ...
  2630. def _linalg_eigh(
  2631. A: Tensor,
  2632. UPLO: str = "L",
  2633. compute_v: _bool = True,
  2634. *,
  2635. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  2636. ) -> torch.return_types._linalg_eigh: ...
  2637. def _linalg_slogdet(
  2638. A: Tensor,
  2639. *,
  2640. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  2641. ) -> torch.return_types._linalg_slogdet: ...
  2642. def _linalg_solve_ex(
  2643. A: Tensor,
  2644. B: Tensor,
  2645. *,
  2646. left: _bool = True,
  2647. check_errors: _bool = False,
  2648. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  2649. ) -> torch.return_types._linalg_solve_ex: ...
  2650. def _linalg_svd(
  2651. A: Tensor,
  2652. full_matrices: _bool = False,
  2653. compute_uv: _bool = True,
  2654. *,
  2655. driver: str | None = None,
  2656. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  2657. ) -> torch.return_types._linalg_svd: ...
  2658. def _log_softmax(
  2659. input: Tensor,
  2660. dim: _int,
  2661. half_to_float: _bool,
  2662. *,
  2663. out: Tensor | None = None,
  2664. ) -> Tensor: ...
  2665. def _log_softmax_backward_data(
  2666. grad_output: Tensor,
  2667. output: Tensor,
  2668. dim: _int,
  2669. input_dtype: _dtype,
  2670. *,
  2671. out: Tensor | None = None,
  2672. ) -> Tensor: ...
  2673. def _logcumsumexp(
  2674. input: Tensor,
  2675. dim: _int,
  2676. *,
  2677. out: Tensor | None = None,
  2678. ) -> Tensor: ...
  2679. def _lstm_mps(
  2680. input: Tensor,
  2681. hx: tuple[Tensor, ...] | list[Tensor] | None,
  2682. params: tuple[Tensor, ...] | list[Tensor] | None,
  2683. has_biases: _bool,
  2684. num_layers: _int,
  2685. dropout: _float,
  2686. train: _bool,
  2687. bidirectional: _bool,
  2688. batch_first: _bool,
  2689. ) -> tuple[Tensor, Tensor, Tensor, Tensor, Tensor, Tensor]: ...
  2690. def _lu_with_info(
  2691. input: Tensor,
  2692. pivot: _bool = True,
  2693. check_errors: _bool = True,
  2694. ) -> torch.return_types._lu_with_info: ...
  2695. def _make_dep_token(
  2696. *,
  2697. memory_format: memory_format | None = None,
  2698. dtype: _dtype | None = None,
  2699. layout: _layout | None = None,
  2700. device: DeviceLikeType | None = None,
  2701. pin_memory: _bool | None = False,
  2702. requires_grad: _bool | None = False,
  2703. ) -> Tensor: ...
  2704. def _make_dual(primal: Tensor, tangent: Tensor, level: _int) -> Tensor: ...
  2705. def _make_dual_copy(
  2706. primal: Tensor,
  2707. tangent: Tensor,
  2708. level: _int,
  2709. *,
  2710. out: Tensor | None = None,
  2711. ) -> Tensor: ...
  2712. def _make_per_channel_quantized_tensor(
  2713. input: Tensor,
  2714. scale: Tensor,
  2715. zero_point: Tensor,
  2716. axis: _int,
  2717. ) -> Tensor: ...
  2718. def _make_per_tensor_quantized_tensor(
  2719. input: Tensor,
  2720. scale: _float,
  2721. zero_point: _int,
  2722. ) -> Tensor: ...
  2723. def _masked_scale(input: Tensor, mask: Tensor, scale: _float) -> Tensor: ...
  2724. def _masked_softmax(
  2725. input: Tensor,
  2726. mask: Tensor,
  2727. dim: _int | None = None,
  2728. mask_type: _int | None = None,
  2729. ) -> Tensor: ...
  2730. def _mixed_dtypes_linear(
  2731. input: Tensor,
  2732. weight: Tensor,
  2733. scale: Tensor,
  2734. *,
  2735. bias: Tensor | None = None,
  2736. activation: str | None = None,
  2737. ) -> Tensor: ...
  2738. def _mkldnn_reshape(input: Tensor, shape: _size) -> Tensor: ...
  2739. def _mkldnn_transpose(input: Tensor, dim0: _int, dim1: _int) -> Tensor: ...
  2740. def _mkldnn_transpose_(input: Tensor, dim0: _int, dim1: _int) -> Tensor: ...
  2741. def _mps_convolution(
  2742. input: Tensor,
  2743. weight: Tensor,
  2744. bias: Tensor | None,
  2745. padding: Sequence[_int | SymInt],
  2746. stride: Sequence[_int | SymInt],
  2747. dilation: Sequence[_int | SymInt],
  2748. groups: _int | SymInt,
  2749. ) -> Tensor: ...
  2750. def _mps_convolution_transpose(
  2751. input: Tensor,
  2752. weight: Tensor,
  2753. padding: Sequence[_int | SymInt],
  2754. output_padding: Sequence[_int | SymInt],
  2755. stride: Sequence[_int | SymInt],
  2756. dilation: Sequence[_int | SymInt],
  2757. groups: _int | SymInt,
  2758. ) -> Tensor: ...
  2759. @overload
  2760. def _native_batch_norm_legit(
  2761. input: Tensor,
  2762. weight: Tensor | None,
  2763. bias: Tensor | None,
  2764. running_mean: Tensor,
  2765. running_var: Tensor,
  2766. training: _bool,
  2767. momentum: _float,
  2768. eps: _float,
  2769. *,
  2770. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  2771. ) -> tuple[Tensor, Tensor, Tensor]: ...
  2772. @overload
  2773. def _native_batch_norm_legit(
  2774. input: Tensor,
  2775. weight: Tensor | None,
  2776. bias: Tensor | None,
  2777. training: _bool,
  2778. momentum: _float,
  2779. eps: _float,
  2780. *,
  2781. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  2782. ) -> tuple[Tensor, Tensor, Tensor]: ...
  2783. def _native_batch_norm_legit_no_training(
  2784. input: Tensor,
  2785. weight: Tensor | None,
  2786. bias: Tensor | None,
  2787. running_mean: Tensor,
  2788. running_var: Tensor,
  2789. momentum: _float,
  2790. eps: _float,
  2791. ) -> tuple[Tensor, Tensor, Tensor]: ...
  2792. def _native_multi_head_attention(
  2793. query: Tensor,
  2794. key: Tensor,
  2795. value: Tensor,
  2796. embed_dim: _int,
  2797. num_head: _int,
  2798. qkv_weight: Tensor,
  2799. qkv_bias: Tensor,
  2800. proj_weight: Tensor,
  2801. proj_bias: Tensor,
  2802. mask: Tensor | None = None,
  2803. need_weights: _bool = True,
  2804. average_attn_weights: _bool = True,
  2805. mask_type: _int | None = None,
  2806. ) -> tuple[Tensor, Tensor]: ...
  2807. def _neg_view(input: Tensor) -> Tensor: ...
  2808. def _neg_view_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor: ...
  2809. def _nested_compute_contiguous_strides_offsets(
  2810. nested_size: Tensor,
  2811. ) -> tuple[Tensor, Tensor]: ...
  2812. def _nested_from_padded(
  2813. padded: Tensor,
  2814. cpu_nested_shape_example: Tensor,
  2815. fuse_transform_0213: _bool = False,
  2816. ) -> Tensor: ...
  2817. def _nested_from_padded_and_nested_example(
  2818. padded: Tensor,
  2819. nt_example: Tensor,
  2820. ) -> Tensor: ...
  2821. def _nested_from_padded_tensor(
  2822. padded: Tensor,
  2823. offsets: Tensor,
  2824. dummy: Tensor,
  2825. ragged_idx: _int = 1,
  2826. min_seqlen: Tensor | None = None,
  2827. max_seqlen: Tensor | None = None,
  2828. sum_S: _int | SymInt | None = None,
  2829. ) -> Tensor: ...
  2830. def _nested_get_jagged_dummy(any: Tensor) -> Tensor: ...
  2831. def _nested_get_lengths(input: Tensor) -> Tensor: ...
  2832. def _nested_get_max_seqlen(input: Tensor) -> Tensor: ...
  2833. def _nested_get_min_seqlen(input: Tensor) -> Tensor: ...
  2834. def _nested_get_offsets(input: Tensor) -> Tensor: ...
  2835. def _nested_get_ragged_idx(input: Tensor) -> _int: ...
  2836. def _nested_get_values(input: Tensor) -> Tensor: ...
  2837. def _nested_get_values_copy(
  2838. input: Tensor,
  2839. *,
  2840. out: Tensor | None = None,
  2841. ) -> Tensor: ...
  2842. def _nested_tensor_from_mask(
  2843. t: Tensor,
  2844. mask: Tensor,
  2845. mask_check: _bool = True,
  2846. ) -> Tensor: ...
  2847. def _nested_tensor_from_mask_left_aligned(t: Tensor, mask: Tensor) -> _bool: ...
  2848. def _nested_tensor_from_tensor_list(
  2849. list: tuple[Tensor, ...] | list[Tensor] | None,
  2850. dtype: _dtype | None = None,
  2851. layout: _layout | None = None,
  2852. device: DeviceLikeType | None = None,
  2853. pin_memory: _bool | None = None,
  2854. ) -> Tensor: ...
  2855. def _nested_tensor_softmax_with_shape(
  2856. input: Tensor,
  2857. query: Tensor,
  2858. ) -> Tensor: ...
  2859. def _nested_view_from_buffer(
  2860. input: Tensor,
  2861. nested_size: Tensor,
  2862. nested_strides: Tensor,
  2863. offsets: Tensor,
  2864. ) -> Tensor: ...
  2865. def _nested_view_from_buffer_copy(
  2866. input: Tensor,
  2867. nested_size: Tensor,
  2868. nested_strides: Tensor,
  2869. offsets: Tensor,
  2870. *,
  2871. out: Tensor | None = None,
  2872. ) -> Tensor: ...
  2873. def _nested_view_from_jagged(
  2874. input: Tensor,
  2875. offsets: Tensor,
  2876. dummy: Tensor,
  2877. lengths: Tensor | None = None,
  2878. ragged_idx: _int = 1,
  2879. min_seqlen: Tensor | None = None,
  2880. max_seqlen: Tensor | None = None,
  2881. ) -> Tensor: ...
  2882. def _nested_view_from_jagged_copy(
  2883. input: Tensor,
  2884. offsets: Tensor,
  2885. dummy: Tensor,
  2886. lengths: Tensor | None = None,
  2887. ragged_idx: _int = 1,
  2888. min_seqlen: Tensor | None = None,
  2889. max_seqlen: Tensor | None = None,
  2890. *,
  2891. out: Tensor | None = None,
  2892. ) -> Tensor: ...
  2893. def _nnpack_available() -> _bool: ...
  2894. def _nnpack_spatial_convolution(
  2895. input: Tensor,
  2896. weight: Tensor,
  2897. bias: Tensor | None,
  2898. padding: _int | SymInt | Sequence[_int | SymInt],
  2899. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  2900. ) -> Tensor: ...
  2901. def _pack_padded_sequence(
  2902. input: Tensor,
  2903. lengths: Tensor,
  2904. batch_first: _bool,
  2905. ) -> tuple[Tensor, Tensor]: ...
  2906. def _pad_packed_sequence(
  2907. data: Tensor,
  2908. batch_sizes: Tensor,
  2909. batch_first: _bool,
  2910. padding_value: Number | _complex,
  2911. total_length: _int,
  2912. ) -> tuple[Tensor, Tensor]: ...
  2913. def _pin_memory(
  2914. input: Tensor,
  2915. device: DeviceLikeType | None = None,
  2916. ) -> Tensor: ...
  2917. def _prelu_kernel(input: Tensor, weight: Tensor) -> Tensor: ...
  2918. def _print(s: str) -> None: ...
  2919. def _propagate_xla_data(input: Tensor, output: Tensor) -> None: ...
  2920. def _remove_batch_dim(
  2921. input: Tensor,
  2922. level: _int,
  2923. batch_size: _int | SymInt,
  2924. out_dim: _int,
  2925. ) -> Tensor: ...
  2926. def _reshape_alias_copy(
  2927. input: Tensor,
  2928. size: Sequence[_int | SymInt],
  2929. stride: Sequence[_int | SymInt],
  2930. *,
  2931. out: Tensor | None = None,
  2932. ) -> Tensor: ...
  2933. def _reshape_from_tensor(input: Tensor, shape: Tensor) -> Tensor: ...
  2934. def _resize_output_(
  2935. input: Tensor,
  2936. size: Sequence[_int | SymInt],
  2937. device: DeviceLikeType | None,
  2938. ) -> Tensor: ...
  2939. def _rowwise_prune(
  2940. weight: Tensor,
  2941. mask: Tensor,
  2942. compressed_indices_dtype: _dtype,
  2943. ) -> tuple[Tensor, Tensor]: ...
  2944. def _safe_softmax(
  2945. input: Tensor,
  2946. dim: _int,
  2947. dtype: _dtype | None = None,
  2948. ) -> Tensor: ...
  2949. def _sample_dirichlet(
  2950. input: Tensor,
  2951. generator: Generator | None = None,
  2952. ) -> Tensor: ...
  2953. def _saturate_weight_to_fp16(weight: Tensor) -> Tensor: ...
  2954. def _scaled_dot_product_attention_math(
  2955. query: Tensor,
  2956. key: Tensor,
  2957. value: Tensor,
  2958. attn_mask: Tensor | None = None,
  2959. dropout_p: _float = 0.0,
  2960. is_causal: _bool = False,
  2961. dropout_mask: Tensor | None = None,
  2962. *,
  2963. scale: _float | None = None,
  2964. enable_gqa: _bool = False,
  2965. ) -> tuple[Tensor, Tensor]: ...
  2966. def _scaled_dot_product_attention_math_for_mps(
  2967. query: Tensor,
  2968. key: Tensor,
  2969. value: Tensor,
  2970. attn_mask: Tensor | None = None,
  2971. dropout_p: _float = 0.0,
  2972. is_causal: _bool = False,
  2973. dropout_mask: Tensor | None = None,
  2974. *,
  2975. scale: _float | None = None,
  2976. ) -> tuple[Tensor, Tensor]: ...
  2977. def _scaled_dot_product_cudnn_attention(
  2978. query: Tensor,
  2979. key: Tensor,
  2980. value: Tensor,
  2981. attn_bias: Tensor | None,
  2982. compute_log_sumexp: _bool,
  2983. dropout_p: _float = 0.0,
  2984. is_causal: _bool = False,
  2985. return_debug_mask: _bool = False,
  2986. *,
  2987. scale: _float | None = None,
  2988. ) -> torch.return_types._scaled_dot_product_cudnn_attention: ...
  2989. def _scaled_dot_product_efficient_attention(
  2990. query: Tensor,
  2991. key: Tensor,
  2992. value: Tensor,
  2993. attn_bias: Tensor | None,
  2994. compute_log_sumexp: _bool,
  2995. dropout_p: _float = 0.0,
  2996. is_causal: _bool = False,
  2997. *,
  2998. scale: _float | None = None,
  2999. ) -> torch.return_types._scaled_dot_product_efficient_attention: ...
  3000. def _scaled_dot_product_flash_attention(
  3001. query: Tensor,
  3002. key: Tensor,
  3003. value: Tensor,
  3004. dropout_p: _float = 0.0,
  3005. is_causal: _bool = False,
  3006. return_debug_mask: _bool = False,
  3007. *,
  3008. scale: _float | None = None,
  3009. ) -> torch.return_types._scaled_dot_product_flash_attention: ...
  3010. def _scaled_dot_product_flash_attention_for_cpu(
  3011. query: Tensor,
  3012. key: Tensor,
  3013. value: Tensor,
  3014. dropout_p: _float = 0.0,
  3015. is_causal: _bool = False,
  3016. *,
  3017. attn_mask: Tensor | None = None,
  3018. scale: _float | None = None,
  3019. ) -> torch.return_types._scaled_dot_product_flash_attention_for_cpu: ...
  3020. def _scaled_grouped_mm(
  3021. input: Tensor,
  3022. mat2: Tensor,
  3023. scale_a: Tensor,
  3024. scale_b: Tensor,
  3025. offs: Tensor | None = None,
  3026. bias: Tensor | None = None,
  3027. scale_result: Tensor | None = None,
  3028. out_dtype: _dtype | None = None,
  3029. use_fast_accum: _bool = False,
  3030. ) -> Tensor: ...
  3031. def _scaled_grouped_mm_v2(
  3032. input: Tensor,
  3033. mat2: Tensor,
  3034. scale_a: tuple[Tensor, ...] | list[Tensor] | None,
  3035. recipe_a: _size,
  3036. swizzle_a: _size,
  3037. scale_b: tuple[Tensor, ...] | list[Tensor] | None,
  3038. recipe_b: _size,
  3039. swizzle_b: _size,
  3040. offs: Tensor | None = None,
  3041. bias: Tensor | None = None,
  3042. out_dtype: _dtype | None = None,
  3043. contraction_dim: _size = (),
  3044. use_fast_accum: _bool = False,
  3045. ) -> Tensor: ...
  3046. def _scaled_mm(
  3047. input: Tensor,
  3048. mat2: Tensor,
  3049. scale_a: Tensor,
  3050. scale_b: Tensor,
  3051. bias: Tensor | None = None,
  3052. scale_result: Tensor | None = None,
  3053. out_dtype: _dtype | None = None,
  3054. use_fast_accum: _bool = False,
  3055. *,
  3056. out: Tensor | None = None,
  3057. ) -> Tensor: ...
  3058. def _scaled_mm_v2(
  3059. input: Tensor,
  3060. mat2: Tensor,
  3061. scale_a: tuple[Tensor, ...] | list[Tensor] | None,
  3062. recipe_a: _size,
  3063. swizzle_a: _size,
  3064. scale_b: tuple[Tensor, ...] | list[Tensor] | None,
  3065. recipe_b: _size,
  3066. swizzle_b: _size,
  3067. bias: Tensor | None,
  3068. out_dtype: _dtype | None,
  3069. contraction_dim: _size = (),
  3070. use_fast_accum: _bool = False,
  3071. *,
  3072. out: Tensor | None = None,
  3073. ) -> Tensor: ...
  3074. def _shape_as_tensor(input: Tensor) -> Tensor: ...
  3075. def _sobol_engine_draw(
  3076. quasi: Tensor,
  3077. n: _int,
  3078. sobolstate: Tensor,
  3079. dimension: _int,
  3080. num_generated: _int,
  3081. dtype: _dtype | None,
  3082. ) -> tuple[Tensor, Tensor]: ...
  3083. def _sobol_engine_ff_(
  3084. input: Tensor,
  3085. n: _int,
  3086. sobolstate: Tensor,
  3087. dimension: _int,
  3088. num_generated: _int,
  3089. ) -> Tensor: ...
  3090. def _sobol_engine_initialize_state_(
  3091. input: Tensor,
  3092. dimension: _int,
  3093. ) -> Tensor: ...
  3094. def _sobol_engine_scramble_(
  3095. input: Tensor,
  3096. ltm: Tensor,
  3097. dimension: _int,
  3098. ) -> Tensor: ...
  3099. def _softmax(
  3100. input: Tensor,
  3101. dim: _int,
  3102. half_to_float: _bool,
  3103. *,
  3104. out: Tensor | None = None,
  3105. ) -> Tensor: ...
  3106. def _softmax_backward_data(
  3107. grad_output: Tensor,
  3108. output: Tensor,
  3109. dim: _int,
  3110. input_dtype: _dtype,
  3111. *,
  3112. grad_input: Tensor | None = None,
  3113. ) -> Tensor: ...
  3114. def _sparse_broadcast_to(input: Tensor, size: _size) -> Tensor: ...
  3115. def _sparse_broadcast_to_copy(
  3116. input: Tensor,
  3117. size: _size,
  3118. *,
  3119. out: Tensor | None = None,
  3120. ) -> Tensor: ...
  3121. def _sparse_csr_prod(
  3122. input: Tensor,
  3123. dim: _int | _size,
  3124. keepdim: _bool = False,
  3125. *,
  3126. dtype: _dtype | None = None,
  3127. ) -> Tensor: ...
  3128. def _sparse_csr_sum(
  3129. input: Tensor,
  3130. dim: _int | _size,
  3131. keepdim: _bool = False,
  3132. *,
  3133. dtype: _dtype | None = None,
  3134. ) -> Tensor: ...
  3135. def _sparse_log_softmax_backward_data(
  3136. grad_output: Tensor,
  3137. output: Tensor,
  3138. dim: _int,
  3139. input: Tensor,
  3140. ) -> Tensor: ...
  3141. def _sparse_semi_structured_addmm(
  3142. input: Tensor,
  3143. mat1: Tensor,
  3144. mat1_meta: Tensor,
  3145. mat2: Tensor,
  3146. *,
  3147. alpha: Number | _complex = 1,
  3148. beta: Number | _complex = 1,
  3149. out_dtype: _dtype | None = None,
  3150. ) -> Tensor: ...
  3151. def _sparse_semi_structured_apply(
  3152. input: Tensor,
  3153. thread_masks: Tensor,
  3154. ) -> tuple[Tensor, Tensor]: ...
  3155. def _sparse_semi_structured_apply_dense(
  3156. input: Tensor,
  3157. thread_masks: Tensor,
  3158. ) -> Tensor: ...
  3159. def _sparse_semi_structured_linear(
  3160. input: Tensor,
  3161. weight: Tensor,
  3162. meta: Tensor,
  3163. *,
  3164. bias: Tensor | None = None,
  3165. activation: str | None = None,
  3166. out_dtype: _dtype | None = None,
  3167. ) -> Tensor: ...
  3168. def _sparse_semi_structured_mm(
  3169. mat1: Tensor,
  3170. mat1_meta: Tensor,
  3171. mat2: Tensor,
  3172. *,
  3173. out_dtype: _dtype | None = None,
  3174. ) -> Tensor: ...
  3175. def _sparse_semi_structured_tile(
  3176. input: Tensor,
  3177. algorithm: str = "",
  3178. use_cutlass: _bool = True,
  3179. ) -> tuple[Tensor, Tensor, Tensor, Tensor, Tensor]: ...
  3180. def _sparse_softmax_backward_data(
  3181. grad_output: Tensor,
  3182. output: Tensor,
  3183. dim: _int,
  3184. input: Tensor,
  3185. ) -> Tensor: ...
  3186. def _sparse_sparse_matmul(input: Tensor, other: Tensor) -> Tensor: ...
  3187. @overload
  3188. def _sparse_sum(input: Tensor) -> Tensor: ...
  3189. @overload
  3190. def _sparse_sum(input: Tensor, *, dtype: _dtype) -> Tensor: ...
  3191. @overload
  3192. def _sparse_sum(input: Tensor, dim: _int | _size) -> Tensor: ...
  3193. @overload
  3194. def _sparse_sum(
  3195. input: Tensor,
  3196. dim: _int | _size,
  3197. *,
  3198. dtype: _dtype,
  3199. ) -> Tensor: ...
  3200. def _stack(
  3201. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  3202. dim: _int = 0,
  3203. *,
  3204. out: Tensor | None = None,
  3205. ) -> Tensor: ...
  3206. def _standard_gamma(
  3207. input: Tensor,
  3208. generator: Generator | None = None,
  3209. ) -> Tensor: ...
  3210. def _standard_gamma_grad(input: Tensor, output: Tensor) -> Tensor: ...
  3211. def _sync(t: Tensor) -> None: ...
  3212. @overload
  3213. def _test_autograd_multiple_dispatch(input: Tensor) -> Tensor: ...
  3214. @overload
  3215. def _test_autograd_multiple_dispatch(input: Tensor, b: _bool) -> Tensor: ...
  3216. def _test_autograd_multiple_dispatch_view(input: Tensor) -> Tensor: ...
  3217. def _test_autograd_multiple_dispatch_view_copy(
  3218. input: Tensor,
  3219. *,
  3220. out: Tensor | None = None,
  3221. ) -> Tensor: ...
  3222. def _test_check_tensor(input: Tensor) -> Tensor: ...
  3223. def _test_functorch_fallback(input: Tensor, other: Tensor) -> Tensor: ...
  3224. def _test_parallel_materialize(
  3225. input: Tensor,
  3226. num_parallel: _int,
  3227. skip_first: _bool = False,
  3228. ) -> Tensor: ...
  3229. def _test_serialization_subcmul(
  3230. input: Tensor,
  3231. other: Tensor,
  3232. alpha: Number | _complex = 1,
  3233. ) -> Tensor: ...
  3234. def _to_cpu(
  3235. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  3236. ) -> tuple[Tensor, ...]: ...
  3237. def _to_functional_tensor(t: Tensor) -> Tensor: ...
  3238. def _to_sparse_semi_structured(dense: Tensor) -> tuple[Tensor, Tensor]: ...
  3239. def _transform_bias_rescale_qkv(
  3240. qkv: Tensor,
  3241. qkv_bias: Tensor,
  3242. num_heads: _int,
  3243. ) -> tuple[Tensor, Tensor, Tensor]: ...
  3244. def _transformer_encoder_layer_fwd(
  3245. src: Tensor,
  3246. embed_dim: _int,
  3247. num_heads: _int,
  3248. qkv_weight: Tensor,
  3249. qkv_bias: Tensor,
  3250. proj_weight: Tensor,
  3251. proj_bias: Tensor,
  3252. use_gelu: _bool,
  3253. norm_first: _bool,
  3254. eps: _float,
  3255. norm_weight_1: Tensor,
  3256. norm_bias_1: Tensor,
  3257. norm_weight_2: Tensor,
  3258. norm_bias_2: Tensor,
  3259. ffn_weight_1: Tensor,
  3260. ffn_bias_1: Tensor,
  3261. ffn_weight_2: Tensor,
  3262. ffn_bias_2: Tensor,
  3263. mask: Tensor | None = None,
  3264. mask_type: _int | None = None,
  3265. ) -> Tensor: ...
  3266. def _trilinear(
  3267. i1: Tensor,
  3268. i2: Tensor,
  3269. i3: Tensor,
  3270. expand1: _size,
  3271. expand2: _size,
  3272. expand3: _size,
  3273. sumdim: _size,
  3274. unroll_dim: _int = 1,
  3275. ) -> Tensor: ...
  3276. def _triton_multi_head_attention(
  3277. query: Tensor,
  3278. key: Tensor,
  3279. value: Tensor,
  3280. embed_dim: _int,
  3281. num_head: _int,
  3282. qkv_weight: Tensor,
  3283. qkv_bias: Tensor,
  3284. proj_weight: Tensor,
  3285. proj_bias: Tensor,
  3286. mask: Tensor | None = None,
  3287. ) -> Tensor: ...
  3288. def _triton_scaled_dot_attention(
  3289. q: Tensor,
  3290. k: Tensor,
  3291. v: Tensor,
  3292. dropout_p: _float = 0.0,
  3293. ) -> Tensor: ...
  3294. def _unique(
  3295. input: Tensor,
  3296. sorted: _bool = True,
  3297. return_inverse: _bool = False,
  3298. ) -> tuple[Tensor, Tensor]: ...
  3299. def _unique2(
  3300. input: Tensor,
  3301. sorted: _bool = True,
  3302. return_inverse: _bool = False,
  3303. return_counts: _bool = False,
  3304. ) -> tuple[Tensor, Tensor, Tensor]: ...
  3305. def _unpack_dual(
  3306. dual: Tensor,
  3307. level: _int,
  3308. ) -> torch.return_types._unpack_dual: ...
  3309. def _unsafe_index(
  3310. input: Tensor,
  3311. indices: tuple[Tensor, ...] | list[Tensor] | None,
  3312. ) -> Tensor: ...
  3313. def _unsafe_index_put(
  3314. input: Tensor,
  3315. indices: tuple[Tensor, ...] | list[Tensor] | None,
  3316. values: Tensor,
  3317. accumulate: _bool = False,
  3318. ) -> Tensor: ...
  3319. def _unsafe_masked_index(
  3320. input: Tensor,
  3321. mask: Tensor,
  3322. indices: tuple[Tensor, ...] | list[Tensor] | None,
  3323. fill: Number | _complex,
  3324. ) -> Tensor: ...
  3325. def _unsafe_masked_index_put_accumulate(
  3326. input: Tensor,
  3327. mask: Tensor,
  3328. indices: tuple[Tensor, ...] | list[Tensor] | None,
  3329. values: Tensor,
  3330. ) -> Tensor: ...
  3331. @overload
  3332. def _use_cudnn_ctc_loss(
  3333. log_probs: Tensor,
  3334. targets: Tensor,
  3335. input_lengths: Tensor,
  3336. target_lengths: Tensor,
  3337. blank: _int,
  3338. ) -> _bool: ...
  3339. @overload
  3340. def _use_cudnn_ctc_loss(
  3341. log_probs: Tensor,
  3342. targets: Tensor,
  3343. input_lengths: _size,
  3344. target_lengths: _size,
  3345. blank: _int,
  3346. ) -> _bool: ...
  3347. def _use_cudnn_rnn_flatten_weight() -> _bool: ...
  3348. def _validate_compressed_sparse_indices(
  3349. is_crow: _bool,
  3350. compressed_idx: Tensor,
  3351. plain_idx: Tensor,
  3352. cdim: _int,
  3353. dim: _int,
  3354. nnz: _int,
  3355. ) -> None: ...
  3356. def _validate_sparse_bsc_tensor_args(
  3357. ccol_indices: Tensor,
  3358. row_indices: Tensor,
  3359. values: Tensor,
  3360. size: _size,
  3361. check_pinning: _bool | None = None,
  3362. ) -> None: ...
  3363. def _validate_sparse_bsr_tensor_args(
  3364. crow_indices: Tensor,
  3365. col_indices: Tensor,
  3366. values: Tensor,
  3367. size: _size,
  3368. check_pinning: _bool | None = None,
  3369. ) -> None: ...
  3370. def _validate_sparse_compressed_tensor_args(
  3371. compressed_indices: Tensor,
  3372. plain_indices: Tensor,
  3373. values: Tensor,
  3374. size: _size,
  3375. layout: _layout,
  3376. check_pinning: _bool | None = None,
  3377. ) -> None: ...
  3378. def _validate_sparse_coo_tensor_args(
  3379. indices: Tensor,
  3380. values: Tensor,
  3381. size: _size,
  3382. is_coalesced: _bool | None = None,
  3383. check_pinning: _bool | None = None,
  3384. ) -> None: ...
  3385. def _validate_sparse_csc_tensor_args(
  3386. ccol_indices: Tensor,
  3387. row_indices: Tensor,
  3388. values: Tensor,
  3389. size: _size,
  3390. check_pinning: _bool | None = None,
  3391. ) -> None: ...
  3392. def _validate_sparse_csr_tensor_args(
  3393. crow_indices: Tensor,
  3394. col_indices: Tensor,
  3395. values: Tensor,
  3396. size: _size,
  3397. check_pinning: _bool | None = None,
  3398. ) -> None: ...
  3399. def _values_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor: ...
  3400. def _weight_int4pack_mm(
  3401. input: Tensor,
  3402. mat2: Tensor,
  3403. qGroupSize: _int,
  3404. qScaleAndZeros: Tensor,
  3405. ) -> Tensor: ...
  3406. def _weight_int4pack_mm_for_cpu(
  3407. input: Tensor,
  3408. mat2: Tensor,
  3409. qGroupSize: _int,
  3410. qScaleAndZeros: Tensor,
  3411. ) -> Tensor: ...
  3412. def _weight_int4pack_mm_with_scales_and_zeros(
  3413. input: Tensor,
  3414. mat2: Tensor,
  3415. qGroupSize: _int,
  3416. qScale: Tensor,
  3417. qZeros: Tensor,
  3418. ) -> Tensor: ...
  3419. def _weight_int8pack_mm(
  3420. input: Tensor,
  3421. mat2: Tensor,
  3422. scales: Tensor,
  3423. ) -> Tensor: ...
  3424. def _weight_norm(v: Tensor, g: Tensor, dim: _int = 0) -> Tensor: ...
  3425. def _weight_norm_interface(
  3426. v: Tensor,
  3427. g: Tensor,
  3428. dim: _int = 0,
  3429. ) -> tuple[Tensor, Tensor]: ...
  3430. def _wrapped_linear_prepack(
  3431. weight: Tensor,
  3432. weight_scale: Tensor,
  3433. weight_zero_point: Tensor,
  3434. bias: Tensor,
  3435. ) -> Tensor: ...
  3436. def _wrapped_quantized_linear_prepacked(
  3437. input: Tensor,
  3438. input_scale: Tensor,
  3439. input_zero_point: Tensor,
  3440. packed_weight: Tensor,
  3441. output_scale: Tensor,
  3442. output_zero_point: Tensor,
  3443. out_channel: _int,
  3444. ) -> Tensor: ...
  3445. def abs(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  3446. r"""
  3447. abs(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  3448. Computes the absolute value of each element in :attr:`input`.
  3449. .. math::
  3450. \text{out}_{i} = |\text{input}_{i}|
  3451. Args:
  3452. input (Tensor): the input tensor.
  3453. Keyword args:
  3454. out (Tensor, optional): the output tensor.
  3455. Example::
  3456. >>> torch.abs(torch.tensor([-1, -2, 3]))
  3457. tensor([ 1, 2, 3])
  3458. """
  3459. def abs_(input: Tensor) -> Tensor: ...
  3460. def absolute(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  3461. r"""
  3462. absolute(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  3463. Alias for :func:`torch.abs`
  3464. """
  3465. def acos(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  3466. r"""
  3467. acos(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  3468. Returns a new tensor with the arccosine (in radians) of each element in :attr:`input`.
  3469. .. math::
  3470. \text{out}_{i} = \cos^{-1}(\text{input}_{i})
  3471. Args:
  3472. input (Tensor): the input tensor.
  3473. Keyword args:
  3474. out (Tensor, optional): the output tensor.
  3475. Example::
  3476. >>> a = torch.randn(4)
  3477. >>> a
  3478. tensor([ 0.3348, -0.5889, 0.2005, -0.1584])
  3479. >>> torch.acos(a)
  3480. tensor([ 1.2294, 2.2004, 1.3690, 1.7298])
  3481. """
  3482. def acos_(input: Tensor) -> Tensor: ...
  3483. def acosh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  3484. r"""
  3485. acosh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  3486. Returns a new tensor with the inverse hyperbolic cosine of the elements of :attr:`input`.
  3487. .. math::
  3488. \text{out}_{i} = \cosh^{-1}(\text{input}_{i})
  3489. Note:
  3490. The domain of the inverse hyperbolic cosine is `[1, inf)` and values outside this range
  3491. will be mapped to ``NaN``, except for `+ INF` for which the output is mapped to `+ INF`.
  3492. Args:
  3493. input (Tensor): the input tensor.
  3494. Keyword arguments:
  3495. out (Tensor, optional): the output tensor.
  3496. Example::
  3497. >>> a = torch.randn(4).uniform_(1, 2)
  3498. >>> a
  3499. tensor([ 1.3192, 1.9915, 1.9674, 1.7151 ])
  3500. >>> torch.acosh(a)
  3501. tensor([ 0.7791, 1.3120, 1.2979, 1.1341 ])
  3502. """
  3503. def acosh_(input: Tensor) -> Tensor: ...
  3504. def adaptive_avg_pool1d(input: Tensor, output_size: _int | _size) -> Tensor: ...
  3505. def adaptive_max_pool1d(
  3506. input: Tensor,
  3507. output_size: _int | _size,
  3508. ) -> tuple[Tensor, Tensor]: ...
  3509. @overload
  3510. def add(
  3511. input: Tensor | Number | _complex,
  3512. other: Tensor | Number | _complex,
  3513. *,
  3514. alpha: Number | _complex | None = 1,
  3515. out: Tensor | None = None,
  3516. ) -> Tensor:
  3517. r"""
  3518. add(input, other, *, alpha=1, out=None) -> Tensor
  3519. Adds :attr:`other`, scaled by :attr:`alpha`, to :attr:`input`.
  3520. .. math::
  3521. \text{{out}}_i = \text{{input}}_i + \text{{alpha}} \times \text{{other}}_i
  3522. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  3523. :ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
  3524. Args:
  3525. input (Tensor): the input tensor.
  3526. other (Tensor or Number): the tensor or number to add to :attr:`input`.
  3527. Keyword arguments:
  3528. alpha (Number): the multiplier for :attr:`other`.
  3529. out (Tensor, optional): the output tensor.
  3530. Examples::
  3531. >>> a = torch.randn(4)
  3532. >>> a
  3533. tensor([ 0.0202, 1.0985, 1.3506, -0.6056])
  3534. >>> torch.add(a, 20)
  3535. tensor([ 20.0202, 21.0985, 21.3506, 19.3944])
  3536. >>> b = torch.randn(4)
  3537. >>> b
  3538. tensor([-0.9732, -0.3497, 0.6245, 0.4022])
  3539. >>> c = torch.randn(4, 1)
  3540. >>> c
  3541. tensor([[ 0.3743],
  3542. [-1.7724],
  3543. [-0.5811],
  3544. [-0.8017]])
  3545. >>> torch.add(b, c, alpha=10)
  3546. tensor([[ 2.7695, 3.3930, 4.3672, 4.1450],
  3547. [-18.6971, -18.0736, -17.0994, -17.3216],
  3548. [ -6.7845, -6.1610, -5.1868, -5.4090],
  3549. [ -8.9902, -8.3667, -7.3925, -7.6147]])
  3550. """
  3551. @overload
  3552. def add(self: Tensor, alpha: Number | _complex, other: Tensor) -> Tensor:
  3553. r"""
  3554. add(input, other, *, alpha=1, out=None) -> Tensor
  3555. Adds :attr:`other`, scaled by :attr:`alpha`, to :attr:`input`.
  3556. .. math::
  3557. \text{{out}}_i = \text{{input}}_i + \text{{alpha}} \times \text{{other}}_i
  3558. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  3559. :ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
  3560. Args:
  3561. input (Tensor): the input tensor.
  3562. other (Tensor or Number): the tensor or number to add to :attr:`input`.
  3563. Keyword arguments:
  3564. alpha (Number): the multiplier for :attr:`other`.
  3565. out (Tensor, optional): the output tensor.
  3566. Examples::
  3567. >>> a = torch.randn(4)
  3568. >>> a
  3569. tensor([ 0.0202, 1.0985, 1.3506, -0.6056])
  3570. >>> torch.add(a, 20)
  3571. tensor([ 20.0202, 21.0985, 21.3506, 19.3944])
  3572. >>> b = torch.randn(4)
  3573. >>> b
  3574. tensor([-0.9732, -0.3497, 0.6245, 0.4022])
  3575. >>> c = torch.randn(4, 1)
  3576. >>> c
  3577. tensor([[ 0.3743],
  3578. [-1.7724],
  3579. [-0.5811],
  3580. [-0.8017]])
  3581. >>> torch.add(b, c, alpha=10)
  3582. tensor([[ 2.7695, 3.3930, 4.3672, 4.1450],
  3583. [-18.6971, -18.0736, -17.0994, -17.3216],
  3584. [ -6.7845, -6.1610, -5.1868, -5.4090],
  3585. [ -8.9902, -8.3667, -7.3925, -7.6147]])
  3586. """
  3587. @overload
  3588. def add(
  3589. self: Tensor,
  3590. alpha: Number | _complex,
  3591. other: Tensor,
  3592. *,
  3593. out: Tensor,
  3594. ) -> Tensor:
  3595. r"""
  3596. add(input, other, *, alpha=1, out=None) -> Tensor
  3597. Adds :attr:`other`, scaled by :attr:`alpha`, to :attr:`input`.
  3598. .. math::
  3599. \text{{out}}_i = \text{{input}}_i + \text{{alpha}} \times \text{{other}}_i
  3600. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  3601. :ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
  3602. Args:
  3603. input (Tensor): the input tensor.
  3604. other (Tensor or Number): the tensor or number to add to :attr:`input`.
  3605. Keyword arguments:
  3606. alpha (Number): the multiplier for :attr:`other`.
  3607. out (Tensor, optional): the output tensor.
  3608. Examples::
  3609. >>> a = torch.randn(4)
  3610. >>> a
  3611. tensor([ 0.0202, 1.0985, 1.3506, -0.6056])
  3612. >>> torch.add(a, 20)
  3613. tensor([ 20.0202, 21.0985, 21.3506, 19.3944])
  3614. >>> b = torch.randn(4)
  3615. >>> b
  3616. tensor([-0.9732, -0.3497, 0.6245, 0.4022])
  3617. >>> c = torch.randn(4, 1)
  3618. >>> c
  3619. tensor([[ 0.3743],
  3620. [-1.7724],
  3621. [-0.5811],
  3622. [-0.8017]])
  3623. >>> torch.add(b, c, alpha=10)
  3624. tensor([[ 2.7695, 3.3930, 4.3672, 4.1450],
  3625. [-18.6971, -18.0736, -17.0994, -17.3216],
  3626. [ -6.7845, -6.1610, -5.1868, -5.4090],
  3627. [ -8.9902, -8.3667, -7.3925, -7.6147]])
  3628. """
  3629. @overload
  3630. def addbmm(
  3631. beta: Number | _complex,
  3632. self: Tensor,
  3633. alpha: Number | _complex,
  3634. batch1: Tensor,
  3635. batch2: Tensor,
  3636. ) -> Tensor:
  3637. r"""
  3638. addbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None) -> Tensor
  3639. Performs a batch matrix-matrix product of matrices stored
  3640. in :attr:`batch1` and :attr:`batch2`,
  3641. with a reduced add step (all matrix multiplications get accumulated
  3642. along the first dimension).
  3643. :attr:`input` is added to the final result.
  3644. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the
  3645. same number of matrices.
  3646. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  3647. :math:`(b \times m \times p)` tensor, :attr:`input` must be
  3648. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  3649. and :attr:`out` will be a :math:`(n \times p)` tensor.
  3650. .. math::
  3651. out = \beta\ \text{input} + \alpha\ (\sum_{i=0}^{b-1} \text{batch1}_i \mathbin{@} \text{batch2}_i)
  3652. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  3653. it will not be propagated.
  3654. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and :attr:`alpha`
  3655. must be real numbers, otherwise they should be integers.
  3656. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  3657. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  3658. Args:
  3659. input (Tensor): matrix to be added
  3660. batch1 (Tensor): the first batch of matrices to be multiplied
  3661. batch2 (Tensor): the second batch of matrices to be multiplied
  3662. Keyword args:
  3663. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  3664. alpha (Number, optional): multiplier for `batch1 @ batch2` (:math:`\alpha`)
  3665. out (Tensor, optional): the output tensor.
  3666. Example::
  3667. >>> M = torch.randn(3, 5)
  3668. >>> batch1 = torch.randn(10, 3, 4)
  3669. >>> batch2 = torch.randn(10, 4, 5)
  3670. >>> torch.addbmm(M, batch1, batch2)
  3671. tensor([[ 6.6311, 0.0503, 6.9768, -12.0362, -2.1653],
  3672. [ -4.8185, -1.4255, -6.6760, 8.9453, 2.5743],
  3673. [ -3.8202, 4.3691, 1.0943, -1.1109, 5.4730]])
  3674. """
  3675. @overload
  3676. def addbmm(
  3677. beta: Number | _complex,
  3678. self: Tensor,
  3679. alpha: Number | _complex,
  3680. batch1: Tensor,
  3681. batch2: Tensor,
  3682. *,
  3683. out: Tensor,
  3684. ) -> Tensor:
  3685. r"""
  3686. addbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None) -> Tensor
  3687. Performs a batch matrix-matrix product of matrices stored
  3688. in :attr:`batch1` and :attr:`batch2`,
  3689. with a reduced add step (all matrix multiplications get accumulated
  3690. along the first dimension).
  3691. :attr:`input` is added to the final result.
  3692. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the
  3693. same number of matrices.
  3694. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  3695. :math:`(b \times m \times p)` tensor, :attr:`input` must be
  3696. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  3697. and :attr:`out` will be a :math:`(n \times p)` tensor.
  3698. .. math::
  3699. out = \beta\ \text{input} + \alpha\ (\sum_{i=0}^{b-1} \text{batch1}_i \mathbin{@} \text{batch2}_i)
  3700. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  3701. it will not be propagated.
  3702. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and :attr:`alpha`
  3703. must be real numbers, otherwise they should be integers.
  3704. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  3705. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  3706. Args:
  3707. input (Tensor): matrix to be added
  3708. batch1 (Tensor): the first batch of matrices to be multiplied
  3709. batch2 (Tensor): the second batch of matrices to be multiplied
  3710. Keyword args:
  3711. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  3712. alpha (Number, optional): multiplier for `batch1 @ batch2` (:math:`\alpha`)
  3713. out (Tensor, optional): the output tensor.
  3714. Example::
  3715. >>> M = torch.randn(3, 5)
  3716. >>> batch1 = torch.randn(10, 3, 4)
  3717. >>> batch2 = torch.randn(10, 4, 5)
  3718. >>> torch.addbmm(M, batch1, batch2)
  3719. tensor([[ 6.6311, 0.0503, 6.9768, -12.0362, -2.1653],
  3720. [ -4.8185, -1.4255, -6.6760, 8.9453, 2.5743],
  3721. [ -3.8202, 4.3691, 1.0943, -1.1109, 5.4730]])
  3722. """
  3723. @overload
  3724. def addbmm(
  3725. input: Tensor,
  3726. batch1: Tensor,
  3727. batch2: Tensor,
  3728. *,
  3729. beta: Number | _complex = 1,
  3730. alpha: Number | _complex = 1,
  3731. out: Tensor | None = None,
  3732. ) -> Tensor:
  3733. r"""
  3734. addbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None) -> Tensor
  3735. Performs a batch matrix-matrix product of matrices stored
  3736. in :attr:`batch1` and :attr:`batch2`,
  3737. with a reduced add step (all matrix multiplications get accumulated
  3738. along the first dimension).
  3739. :attr:`input` is added to the final result.
  3740. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the
  3741. same number of matrices.
  3742. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  3743. :math:`(b \times m \times p)` tensor, :attr:`input` must be
  3744. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  3745. and :attr:`out` will be a :math:`(n \times p)` tensor.
  3746. .. math::
  3747. out = \beta\ \text{input} + \alpha\ (\sum_{i=0}^{b-1} \text{batch1}_i \mathbin{@} \text{batch2}_i)
  3748. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  3749. it will not be propagated.
  3750. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and :attr:`alpha`
  3751. must be real numbers, otherwise they should be integers.
  3752. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  3753. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  3754. Args:
  3755. input (Tensor): matrix to be added
  3756. batch1 (Tensor): the first batch of matrices to be multiplied
  3757. batch2 (Tensor): the second batch of matrices to be multiplied
  3758. Keyword args:
  3759. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  3760. alpha (Number, optional): multiplier for `batch1 @ batch2` (:math:`\alpha`)
  3761. out (Tensor, optional): the output tensor.
  3762. Example::
  3763. >>> M = torch.randn(3, 5)
  3764. >>> batch1 = torch.randn(10, 3, 4)
  3765. >>> batch2 = torch.randn(10, 4, 5)
  3766. >>> torch.addbmm(M, batch1, batch2)
  3767. tensor([[ 6.6311, 0.0503, 6.9768, -12.0362, -2.1653],
  3768. [ -4.8185, -1.4255, -6.6760, 8.9453, 2.5743],
  3769. [ -3.8202, 4.3691, 1.0943, -1.1109, 5.4730]])
  3770. """
  3771. @overload
  3772. def addbmm(
  3773. beta: Number | _complex,
  3774. self: Tensor,
  3775. batch1: Tensor,
  3776. batch2: Tensor,
  3777. ) -> Tensor:
  3778. r"""
  3779. addbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None) -> Tensor
  3780. Performs a batch matrix-matrix product of matrices stored
  3781. in :attr:`batch1` and :attr:`batch2`,
  3782. with a reduced add step (all matrix multiplications get accumulated
  3783. along the first dimension).
  3784. :attr:`input` is added to the final result.
  3785. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the
  3786. same number of matrices.
  3787. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  3788. :math:`(b \times m \times p)` tensor, :attr:`input` must be
  3789. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  3790. and :attr:`out` will be a :math:`(n \times p)` tensor.
  3791. .. math::
  3792. out = \beta\ \text{input} + \alpha\ (\sum_{i=0}^{b-1} \text{batch1}_i \mathbin{@} \text{batch2}_i)
  3793. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  3794. it will not be propagated.
  3795. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and :attr:`alpha`
  3796. must be real numbers, otherwise they should be integers.
  3797. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  3798. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  3799. Args:
  3800. input (Tensor): matrix to be added
  3801. batch1 (Tensor): the first batch of matrices to be multiplied
  3802. batch2 (Tensor): the second batch of matrices to be multiplied
  3803. Keyword args:
  3804. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  3805. alpha (Number, optional): multiplier for `batch1 @ batch2` (:math:`\alpha`)
  3806. out (Tensor, optional): the output tensor.
  3807. Example::
  3808. >>> M = torch.randn(3, 5)
  3809. >>> batch1 = torch.randn(10, 3, 4)
  3810. >>> batch2 = torch.randn(10, 4, 5)
  3811. >>> torch.addbmm(M, batch1, batch2)
  3812. tensor([[ 6.6311, 0.0503, 6.9768, -12.0362, -2.1653],
  3813. [ -4.8185, -1.4255, -6.6760, 8.9453, 2.5743],
  3814. [ -3.8202, 4.3691, 1.0943, -1.1109, 5.4730]])
  3815. """
  3816. @overload
  3817. def addbmm(
  3818. beta: Number | _complex,
  3819. self: Tensor,
  3820. batch1: Tensor,
  3821. batch2: Tensor,
  3822. *,
  3823. out: Tensor,
  3824. ) -> Tensor:
  3825. r"""
  3826. addbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None) -> Tensor
  3827. Performs a batch matrix-matrix product of matrices stored
  3828. in :attr:`batch1` and :attr:`batch2`,
  3829. with a reduced add step (all matrix multiplications get accumulated
  3830. along the first dimension).
  3831. :attr:`input` is added to the final result.
  3832. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the
  3833. same number of matrices.
  3834. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  3835. :math:`(b \times m \times p)` tensor, :attr:`input` must be
  3836. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  3837. and :attr:`out` will be a :math:`(n \times p)` tensor.
  3838. .. math::
  3839. out = \beta\ \text{input} + \alpha\ (\sum_{i=0}^{b-1} \text{batch1}_i \mathbin{@} \text{batch2}_i)
  3840. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  3841. it will not be propagated.
  3842. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and :attr:`alpha`
  3843. must be real numbers, otherwise they should be integers.
  3844. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  3845. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  3846. Args:
  3847. input (Tensor): matrix to be added
  3848. batch1 (Tensor): the first batch of matrices to be multiplied
  3849. batch2 (Tensor): the second batch of matrices to be multiplied
  3850. Keyword args:
  3851. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  3852. alpha (Number, optional): multiplier for `batch1 @ batch2` (:math:`\alpha`)
  3853. out (Tensor, optional): the output tensor.
  3854. Example::
  3855. >>> M = torch.randn(3, 5)
  3856. >>> batch1 = torch.randn(10, 3, 4)
  3857. >>> batch2 = torch.randn(10, 4, 5)
  3858. >>> torch.addbmm(M, batch1, batch2)
  3859. tensor([[ 6.6311, 0.0503, 6.9768, -12.0362, -2.1653],
  3860. [ -4.8185, -1.4255, -6.6760, 8.9453, 2.5743],
  3861. [ -3.8202, 4.3691, 1.0943, -1.1109, 5.4730]])
  3862. """
  3863. @overload
  3864. def addcdiv(
  3865. self: Tensor,
  3866. value: Number | _complex,
  3867. tensor1: Tensor,
  3868. tensor2: Tensor,
  3869. ) -> Tensor:
  3870. r"""
  3871. addcdiv(input, tensor1, tensor2, *, value=1, out=None) -> Tensor
  3872. Performs the element-wise division of :attr:`tensor1` by :attr:`tensor2`,
  3873. multiplies the result by the scalar :attr:`value` and adds it to :attr:`input`.
  3874. .. warning::
  3875. Integer division with addcdiv is no longer supported, and in a future
  3876. release addcdiv will perform a true division of tensor1 and tensor2.
  3877. The historic addcdiv behavior can be implemented as
  3878. (input + value * torch.trunc(tensor1 / tensor2)).to(input.dtype)
  3879. for integer inputs and as (input + value * tensor1 / tensor2) for float inputs.
  3880. The future addcdiv behavior is just the latter implementation:
  3881. (input + value * tensor1 / tensor2), for all dtypes.
  3882. .. math::
  3883. \text{out}_i = \text{input}_i + \text{value} \times \frac{\text{tensor1}_i}{\text{tensor2}_i}
  3884. The shapes of :attr:`input`, :attr:`tensor1`, and :attr:`tensor2` must be
  3885. :ref:`broadcastable <broadcasting-semantics>`.
  3886. For inputs of type `FloatTensor` or `DoubleTensor`, :attr:`value` must be
  3887. a real number, otherwise an integer.
  3888. Args:
  3889. input (Tensor): the tensor to be added
  3890. tensor1 (Tensor): the numerator tensor
  3891. tensor2 (Tensor): the denominator tensor
  3892. Keyword args:
  3893. value (Number, optional): multiplier for :math:`\text{tensor1} / \text{tensor2}`
  3894. out (Tensor, optional): the output tensor.
  3895. Example::
  3896. >>> t = torch.randn(1, 3)
  3897. >>> t1 = torch.randn(3, 1)
  3898. >>> t2 = torch.randn(1, 3)
  3899. >>> torch.addcdiv(t, t1, t2, value=0.1)
  3900. tensor([[-0.2312, -3.6496, 0.1312],
  3901. [-1.0428, 3.4292, -0.1030],
  3902. [-0.5369, -0.9829, 0.0430]])
  3903. """
  3904. @overload
  3905. def addcdiv(
  3906. self: Tensor,
  3907. value: Number | _complex,
  3908. tensor1: Tensor,
  3909. tensor2: Tensor,
  3910. *,
  3911. out: Tensor,
  3912. ) -> Tensor:
  3913. r"""
  3914. addcdiv(input, tensor1, tensor2, *, value=1, out=None) -> Tensor
  3915. Performs the element-wise division of :attr:`tensor1` by :attr:`tensor2`,
  3916. multiplies the result by the scalar :attr:`value` and adds it to :attr:`input`.
  3917. .. warning::
  3918. Integer division with addcdiv is no longer supported, and in a future
  3919. release addcdiv will perform a true division of tensor1 and tensor2.
  3920. The historic addcdiv behavior can be implemented as
  3921. (input + value * torch.trunc(tensor1 / tensor2)).to(input.dtype)
  3922. for integer inputs and as (input + value * tensor1 / tensor2) for float inputs.
  3923. The future addcdiv behavior is just the latter implementation:
  3924. (input + value * tensor1 / tensor2), for all dtypes.
  3925. .. math::
  3926. \text{out}_i = \text{input}_i + \text{value} \times \frac{\text{tensor1}_i}{\text{tensor2}_i}
  3927. The shapes of :attr:`input`, :attr:`tensor1`, and :attr:`tensor2` must be
  3928. :ref:`broadcastable <broadcasting-semantics>`.
  3929. For inputs of type `FloatTensor` or `DoubleTensor`, :attr:`value` must be
  3930. a real number, otherwise an integer.
  3931. Args:
  3932. input (Tensor): the tensor to be added
  3933. tensor1 (Tensor): the numerator tensor
  3934. tensor2 (Tensor): the denominator tensor
  3935. Keyword args:
  3936. value (Number, optional): multiplier for :math:`\text{tensor1} / \text{tensor2}`
  3937. out (Tensor, optional): the output tensor.
  3938. Example::
  3939. >>> t = torch.randn(1, 3)
  3940. >>> t1 = torch.randn(3, 1)
  3941. >>> t2 = torch.randn(1, 3)
  3942. >>> torch.addcdiv(t, t1, t2, value=0.1)
  3943. tensor([[-0.2312, -3.6496, 0.1312],
  3944. [-1.0428, 3.4292, -0.1030],
  3945. [-0.5369, -0.9829, 0.0430]])
  3946. """
  3947. @overload
  3948. def addcdiv(
  3949. input: Tensor,
  3950. tensor1: Tensor,
  3951. tensor2: Tensor,
  3952. *,
  3953. value: Number | _complex = 1,
  3954. out: Tensor | None = None,
  3955. ) -> Tensor:
  3956. r"""
  3957. addcdiv(input, tensor1, tensor2, *, value=1, out=None) -> Tensor
  3958. Performs the element-wise division of :attr:`tensor1` by :attr:`tensor2`,
  3959. multiplies the result by the scalar :attr:`value` and adds it to :attr:`input`.
  3960. .. warning::
  3961. Integer division with addcdiv is no longer supported, and in a future
  3962. release addcdiv will perform a true division of tensor1 and tensor2.
  3963. The historic addcdiv behavior can be implemented as
  3964. (input + value * torch.trunc(tensor1 / tensor2)).to(input.dtype)
  3965. for integer inputs and as (input + value * tensor1 / tensor2) for float inputs.
  3966. The future addcdiv behavior is just the latter implementation:
  3967. (input + value * tensor1 / tensor2), for all dtypes.
  3968. .. math::
  3969. \text{out}_i = \text{input}_i + \text{value} \times \frac{\text{tensor1}_i}{\text{tensor2}_i}
  3970. The shapes of :attr:`input`, :attr:`tensor1`, and :attr:`tensor2` must be
  3971. :ref:`broadcastable <broadcasting-semantics>`.
  3972. For inputs of type `FloatTensor` or `DoubleTensor`, :attr:`value` must be
  3973. a real number, otherwise an integer.
  3974. Args:
  3975. input (Tensor): the tensor to be added
  3976. tensor1 (Tensor): the numerator tensor
  3977. tensor2 (Tensor): the denominator tensor
  3978. Keyword args:
  3979. value (Number, optional): multiplier for :math:`\text{tensor1} / \text{tensor2}`
  3980. out (Tensor, optional): the output tensor.
  3981. Example::
  3982. >>> t = torch.randn(1, 3)
  3983. >>> t1 = torch.randn(3, 1)
  3984. >>> t2 = torch.randn(1, 3)
  3985. >>> torch.addcdiv(t, t1, t2, value=0.1)
  3986. tensor([[-0.2312, -3.6496, 0.1312],
  3987. [-1.0428, 3.4292, -0.1030],
  3988. [-0.5369, -0.9829, 0.0430]])
  3989. """
  3990. @overload
  3991. def addcmul(
  3992. self: Tensor,
  3993. value: Number | _complex,
  3994. tensor1: Tensor,
  3995. tensor2: Tensor,
  3996. ) -> Tensor:
  3997. r"""
  3998. addcmul(input, tensor1, tensor2, *, value=1, out=None) -> Tensor
  3999. Performs the element-wise multiplication of :attr:`tensor1`
  4000. by :attr:`tensor2`, multiplies the result by the scalar :attr:`value`
  4001. and adds it to :attr:`input`.
  4002. .. math::
  4003. \text{out}_i = \text{input}_i + \text{value} \times \text{tensor1}_i \times \text{tensor2}_i
  4004. The shapes of :attr:`tensor`, :attr:`tensor1`, and :attr:`tensor2` must be
  4005. :ref:`broadcastable <broadcasting-semantics>`.
  4006. For inputs of type `FloatTensor` or `DoubleTensor`, :attr:`value` must be
  4007. a real number, otherwise an integer.
  4008. Args:
  4009. input (Tensor): the tensor to be added
  4010. tensor1 (Tensor): the tensor to be multiplied
  4011. tensor2 (Tensor): the tensor to be multiplied
  4012. Keyword args:
  4013. value (Number, optional): multiplier for :math:`tensor1 .* tensor2`
  4014. out (Tensor, optional): the output tensor.
  4015. Example::
  4016. >>> t = torch.randn(1, 3)
  4017. >>> t1 = torch.randn(3, 1)
  4018. >>> t2 = torch.randn(1, 3)
  4019. >>> torch.addcmul(t, t1, t2, value=0.1)
  4020. tensor([[-0.8635, -0.6391, 1.6174],
  4021. [-0.7617, -0.5879, 1.7388],
  4022. [-0.8353, -0.6249, 1.6511]])
  4023. """
  4024. @overload
  4025. def addcmul(
  4026. self: Tensor,
  4027. value: Number | _complex,
  4028. tensor1: Tensor,
  4029. tensor2: Tensor,
  4030. *,
  4031. out: Tensor,
  4032. ) -> Tensor:
  4033. r"""
  4034. addcmul(input, tensor1, tensor2, *, value=1, out=None) -> Tensor
  4035. Performs the element-wise multiplication of :attr:`tensor1`
  4036. by :attr:`tensor2`, multiplies the result by the scalar :attr:`value`
  4037. and adds it to :attr:`input`.
  4038. .. math::
  4039. \text{out}_i = \text{input}_i + \text{value} \times \text{tensor1}_i \times \text{tensor2}_i
  4040. The shapes of :attr:`tensor`, :attr:`tensor1`, and :attr:`tensor2` must be
  4041. :ref:`broadcastable <broadcasting-semantics>`.
  4042. For inputs of type `FloatTensor` or `DoubleTensor`, :attr:`value` must be
  4043. a real number, otherwise an integer.
  4044. Args:
  4045. input (Tensor): the tensor to be added
  4046. tensor1 (Tensor): the tensor to be multiplied
  4047. tensor2 (Tensor): the tensor to be multiplied
  4048. Keyword args:
  4049. value (Number, optional): multiplier for :math:`tensor1 .* tensor2`
  4050. out (Tensor, optional): the output tensor.
  4051. Example::
  4052. >>> t = torch.randn(1, 3)
  4053. >>> t1 = torch.randn(3, 1)
  4054. >>> t2 = torch.randn(1, 3)
  4055. >>> torch.addcmul(t, t1, t2, value=0.1)
  4056. tensor([[-0.8635, -0.6391, 1.6174],
  4057. [-0.7617, -0.5879, 1.7388],
  4058. [-0.8353, -0.6249, 1.6511]])
  4059. """
  4060. @overload
  4061. def addcmul(
  4062. input: Tensor,
  4063. tensor1: Tensor,
  4064. tensor2: Tensor,
  4065. *,
  4066. value: Number | _complex = 1,
  4067. out: Tensor | None = None,
  4068. ) -> Tensor:
  4069. r"""
  4070. addcmul(input, tensor1, tensor2, *, value=1, out=None) -> Tensor
  4071. Performs the element-wise multiplication of :attr:`tensor1`
  4072. by :attr:`tensor2`, multiplies the result by the scalar :attr:`value`
  4073. and adds it to :attr:`input`.
  4074. .. math::
  4075. \text{out}_i = \text{input}_i + \text{value} \times \text{tensor1}_i \times \text{tensor2}_i
  4076. The shapes of :attr:`tensor`, :attr:`tensor1`, and :attr:`tensor2` must be
  4077. :ref:`broadcastable <broadcasting-semantics>`.
  4078. For inputs of type `FloatTensor` or `DoubleTensor`, :attr:`value` must be
  4079. a real number, otherwise an integer.
  4080. Args:
  4081. input (Tensor): the tensor to be added
  4082. tensor1 (Tensor): the tensor to be multiplied
  4083. tensor2 (Tensor): the tensor to be multiplied
  4084. Keyword args:
  4085. value (Number, optional): multiplier for :math:`tensor1 .* tensor2`
  4086. out (Tensor, optional): the output tensor.
  4087. Example::
  4088. >>> t = torch.randn(1, 3)
  4089. >>> t1 = torch.randn(3, 1)
  4090. >>> t2 = torch.randn(1, 3)
  4091. >>> torch.addcmul(t, t1, t2, value=0.1)
  4092. tensor([[-0.8635, -0.6391, 1.6174],
  4093. [-0.7617, -0.5879, 1.7388],
  4094. [-0.8353, -0.6249, 1.6511]])
  4095. """
  4096. @overload
  4097. def addmm(
  4098. beta: Number | _complex,
  4099. self: Tensor,
  4100. alpha: Number | _complex,
  4101. mat1: Tensor,
  4102. mat2: Tensor,
  4103. ) -> Tensor:
  4104. r"""
  4105. addmm(input, mat1, mat2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  4106. Performs a matrix multiplication of the matrices :attr:`mat1` and :attr:`mat2`.
  4107. The matrix :attr:`input` is added to the final result.
  4108. If :attr:`mat1` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
  4109. :math:`(m \times p)` tensor, then :attr:`input` must be
  4110. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  4111. and :attr:`out` will be a :math:`(n \times p)` tensor.
  4112. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4113. :attr:`mat1` and :attr:`mat2` and the added matrix :attr:`input` respectively.
  4114. .. math::
  4115. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat1}_i \mathbin{@} \text{mat2}_i)
  4116. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4117. it will not be propagated.
  4118. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4119. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4120. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`. If
  4121. :attr:`input` is sparse the result will have the same layout and if :attr:`out`
  4122. is provided it must have the same layout as :attr:`input`.
  4123. .. warning::
  4124. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  4125. or may not have autograd support. If you notice missing functionality please
  4126. open a feature request.
  4127. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  4128. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  4129. Args:
  4130. input (Tensor): matrix to be added
  4131. mat1 (Tensor): the first matrix to be matrix multiplied
  4132. mat2 (Tensor): the second matrix to be matrix multiplied
  4133. out_dtype (dtype, optional): the dtype of the output tensor,
  4134. Supported only on CUDA and for torch.float32 given
  4135. torch.float16/torch.bfloat16 input dtypes
  4136. Keyword args:
  4137. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4138. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  4139. out (Tensor, optional): the output tensor.
  4140. Example::
  4141. >>> M = torch.randn(2, 3)
  4142. >>> mat1 = torch.randn(2, 3)
  4143. >>> mat2 = torch.randn(3, 3)
  4144. >>> torch.addmm(M, mat1, mat2)
  4145. tensor([[-4.8716, 1.4671, -1.3746],
  4146. [ 0.7573, -3.9555, -2.8681]])
  4147. """
  4148. @overload
  4149. def addmm(
  4150. beta: Number | _complex,
  4151. self: Tensor,
  4152. alpha: Number | _complex,
  4153. mat1: Tensor,
  4154. mat2: Tensor,
  4155. *,
  4156. out: Tensor,
  4157. ) -> Tensor:
  4158. r"""
  4159. addmm(input, mat1, mat2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  4160. Performs a matrix multiplication of the matrices :attr:`mat1` and :attr:`mat2`.
  4161. The matrix :attr:`input` is added to the final result.
  4162. If :attr:`mat1` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
  4163. :math:`(m \times p)` tensor, then :attr:`input` must be
  4164. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  4165. and :attr:`out` will be a :math:`(n \times p)` tensor.
  4166. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4167. :attr:`mat1` and :attr:`mat2` and the added matrix :attr:`input` respectively.
  4168. .. math::
  4169. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat1}_i \mathbin{@} \text{mat2}_i)
  4170. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4171. it will not be propagated.
  4172. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4173. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4174. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`. If
  4175. :attr:`input` is sparse the result will have the same layout and if :attr:`out`
  4176. is provided it must have the same layout as :attr:`input`.
  4177. .. warning::
  4178. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  4179. or may not have autograd support. If you notice missing functionality please
  4180. open a feature request.
  4181. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  4182. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  4183. Args:
  4184. input (Tensor): matrix to be added
  4185. mat1 (Tensor): the first matrix to be matrix multiplied
  4186. mat2 (Tensor): the second matrix to be matrix multiplied
  4187. out_dtype (dtype, optional): the dtype of the output tensor,
  4188. Supported only on CUDA and for torch.float32 given
  4189. torch.float16/torch.bfloat16 input dtypes
  4190. Keyword args:
  4191. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4192. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  4193. out (Tensor, optional): the output tensor.
  4194. Example::
  4195. >>> M = torch.randn(2, 3)
  4196. >>> mat1 = torch.randn(2, 3)
  4197. >>> mat2 = torch.randn(3, 3)
  4198. >>> torch.addmm(M, mat1, mat2)
  4199. tensor([[-4.8716, 1.4671, -1.3746],
  4200. [ 0.7573, -3.9555, -2.8681]])
  4201. """
  4202. @overload
  4203. def addmm(
  4204. input: Tensor,
  4205. mat1: Tensor,
  4206. mat2: Tensor,
  4207. *,
  4208. beta: Number | _complex = 1,
  4209. alpha: Number | _complex = 1,
  4210. out: Tensor | None = None,
  4211. ) -> Tensor:
  4212. r"""
  4213. addmm(input, mat1, mat2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  4214. Performs a matrix multiplication of the matrices :attr:`mat1` and :attr:`mat2`.
  4215. The matrix :attr:`input` is added to the final result.
  4216. If :attr:`mat1` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
  4217. :math:`(m \times p)` tensor, then :attr:`input` must be
  4218. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  4219. and :attr:`out` will be a :math:`(n \times p)` tensor.
  4220. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4221. :attr:`mat1` and :attr:`mat2` and the added matrix :attr:`input` respectively.
  4222. .. math::
  4223. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat1}_i \mathbin{@} \text{mat2}_i)
  4224. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4225. it will not be propagated.
  4226. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4227. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4228. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`. If
  4229. :attr:`input` is sparse the result will have the same layout and if :attr:`out`
  4230. is provided it must have the same layout as :attr:`input`.
  4231. .. warning::
  4232. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  4233. or may not have autograd support. If you notice missing functionality please
  4234. open a feature request.
  4235. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  4236. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  4237. Args:
  4238. input (Tensor): matrix to be added
  4239. mat1 (Tensor): the first matrix to be matrix multiplied
  4240. mat2 (Tensor): the second matrix to be matrix multiplied
  4241. out_dtype (dtype, optional): the dtype of the output tensor,
  4242. Supported only on CUDA and for torch.float32 given
  4243. torch.float16/torch.bfloat16 input dtypes
  4244. Keyword args:
  4245. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4246. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  4247. out (Tensor, optional): the output tensor.
  4248. Example::
  4249. >>> M = torch.randn(2, 3)
  4250. >>> mat1 = torch.randn(2, 3)
  4251. >>> mat2 = torch.randn(3, 3)
  4252. >>> torch.addmm(M, mat1, mat2)
  4253. tensor([[-4.8716, 1.4671, -1.3746],
  4254. [ 0.7573, -3.9555, -2.8681]])
  4255. """
  4256. @overload
  4257. def addmm(
  4258. input: Tensor,
  4259. mat1: Tensor,
  4260. mat2: Tensor,
  4261. out_dtype: _dtype,
  4262. *,
  4263. beta: Number | _complex = 1,
  4264. alpha: Number | _complex = 1,
  4265. out: Tensor | None = None,
  4266. ) -> Tensor:
  4267. r"""
  4268. addmm(input, mat1, mat2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  4269. Performs a matrix multiplication of the matrices :attr:`mat1` and :attr:`mat2`.
  4270. The matrix :attr:`input` is added to the final result.
  4271. If :attr:`mat1` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
  4272. :math:`(m \times p)` tensor, then :attr:`input` must be
  4273. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  4274. and :attr:`out` will be a :math:`(n \times p)` tensor.
  4275. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4276. :attr:`mat1` and :attr:`mat2` and the added matrix :attr:`input` respectively.
  4277. .. math::
  4278. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat1}_i \mathbin{@} \text{mat2}_i)
  4279. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4280. it will not be propagated.
  4281. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4282. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4283. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`. If
  4284. :attr:`input` is sparse the result will have the same layout and if :attr:`out`
  4285. is provided it must have the same layout as :attr:`input`.
  4286. .. warning::
  4287. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  4288. or may not have autograd support. If you notice missing functionality please
  4289. open a feature request.
  4290. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  4291. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  4292. Args:
  4293. input (Tensor): matrix to be added
  4294. mat1 (Tensor): the first matrix to be matrix multiplied
  4295. mat2 (Tensor): the second matrix to be matrix multiplied
  4296. out_dtype (dtype, optional): the dtype of the output tensor,
  4297. Supported only on CUDA and for torch.float32 given
  4298. torch.float16/torch.bfloat16 input dtypes
  4299. Keyword args:
  4300. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4301. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  4302. out (Tensor, optional): the output tensor.
  4303. Example::
  4304. >>> M = torch.randn(2, 3)
  4305. >>> mat1 = torch.randn(2, 3)
  4306. >>> mat2 = torch.randn(3, 3)
  4307. >>> torch.addmm(M, mat1, mat2)
  4308. tensor([[-4.8716, 1.4671, -1.3746],
  4309. [ 0.7573, -3.9555, -2.8681]])
  4310. """
  4311. @overload
  4312. def addmm(
  4313. beta: Number | _complex,
  4314. self: Tensor,
  4315. mat1: Tensor,
  4316. mat2: Tensor,
  4317. ) -> Tensor:
  4318. r"""
  4319. addmm(input, mat1, mat2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  4320. Performs a matrix multiplication of the matrices :attr:`mat1` and :attr:`mat2`.
  4321. The matrix :attr:`input` is added to the final result.
  4322. If :attr:`mat1` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
  4323. :math:`(m \times p)` tensor, then :attr:`input` must be
  4324. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  4325. and :attr:`out` will be a :math:`(n \times p)` tensor.
  4326. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4327. :attr:`mat1` and :attr:`mat2` and the added matrix :attr:`input` respectively.
  4328. .. math::
  4329. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat1}_i \mathbin{@} \text{mat2}_i)
  4330. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4331. it will not be propagated.
  4332. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4333. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4334. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`. If
  4335. :attr:`input` is sparse the result will have the same layout and if :attr:`out`
  4336. is provided it must have the same layout as :attr:`input`.
  4337. .. warning::
  4338. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  4339. or may not have autograd support. If you notice missing functionality please
  4340. open a feature request.
  4341. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  4342. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  4343. Args:
  4344. input (Tensor): matrix to be added
  4345. mat1 (Tensor): the first matrix to be matrix multiplied
  4346. mat2 (Tensor): the second matrix to be matrix multiplied
  4347. out_dtype (dtype, optional): the dtype of the output tensor,
  4348. Supported only on CUDA and for torch.float32 given
  4349. torch.float16/torch.bfloat16 input dtypes
  4350. Keyword args:
  4351. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4352. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  4353. out (Tensor, optional): the output tensor.
  4354. Example::
  4355. >>> M = torch.randn(2, 3)
  4356. >>> mat1 = torch.randn(2, 3)
  4357. >>> mat2 = torch.randn(3, 3)
  4358. >>> torch.addmm(M, mat1, mat2)
  4359. tensor([[-4.8716, 1.4671, -1.3746],
  4360. [ 0.7573, -3.9555, -2.8681]])
  4361. """
  4362. @overload
  4363. def addmm(
  4364. beta: Number | _complex,
  4365. self: Tensor,
  4366. mat1: Tensor,
  4367. mat2: Tensor,
  4368. *,
  4369. out: Tensor,
  4370. ) -> Tensor:
  4371. r"""
  4372. addmm(input, mat1, mat2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  4373. Performs a matrix multiplication of the matrices :attr:`mat1` and :attr:`mat2`.
  4374. The matrix :attr:`input` is added to the final result.
  4375. If :attr:`mat1` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
  4376. :math:`(m \times p)` tensor, then :attr:`input` must be
  4377. :ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
  4378. and :attr:`out` will be a :math:`(n \times p)` tensor.
  4379. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4380. :attr:`mat1` and :attr:`mat2` and the added matrix :attr:`input` respectively.
  4381. .. math::
  4382. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat1}_i \mathbin{@} \text{mat2}_i)
  4383. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4384. it will not be propagated.
  4385. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4386. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4387. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`. If
  4388. :attr:`input` is sparse the result will have the same layout and if :attr:`out`
  4389. is provided it must have the same layout as :attr:`input`.
  4390. .. warning::
  4391. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  4392. or may not have autograd support. If you notice missing functionality please
  4393. open a feature request.
  4394. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  4395. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  4396. Args:
  4397. input (Tensor): matrix to be added
  4398. mat1 (Tensor): the first matrix to be matrix multiplied
  4399. mat2 (Tensor): the second matrix to be matrix multiplied
  4400. out_dtype (dtype, optional): the dtype of the output tensor,
  4401. Supported only on CUDA and for torch.float32 given
  4402. torch.float16/torch.bfloat16 input dtypes
  4403. Keyword args:
  4404. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4405. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  4406. out (Tensor, optional): the output tensor.
  4407. Example::
  4408. >>> M = torch.randn(2, 3)
  4409. >>> mat1 = torch.randn(2, 3)
  4410. >>> mat2 = torch.randn(3, 3)
  4411. >>> torch.addmm(M, mat1, mat2)
  4412. tensor([[-4.8716, 1.4671, -1.3746],
  4413. [ 0.7573, -3.9555, -2.8681]])
  4414. """
  4415. @overload
  4416. def addmv(
  4417. beta: Number | _complex,
  4418. self: Tensor,
  4419. alpha: Number | _complex,
  4420. mat: Tensor,
  4421. vec: Tensor,
  4422. ) -> Tensor:
  4423. r"""
  4424. addmv(input, mat, vec, *, beta=1, alpha=1, out=None) -> Tensor
  4425. Performs a matrix-vector product of the matrix :attr:`mat` and
  4426. the vector :attr:`vec`.
  4427. The vector :attr:`input` is added to the final result.
  4428. If :attr:`mat` is a :math:`(n \times m)` tensor, :attr:`vec` is a 1-D tensor of
  4429. size `m`, then :attr:`input` must be
  4430. :ref:`broadcastable <broadcasting-semantics>` with a 1-D tensor of size `n` and
  4431. :attr:`out` will be 1-D tensor of size `n`.
  4432. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4433. :attr:`mat` and :attr:`vec` and the added tensor :attr:`input` respectively.
  4434. .. math::
  4435. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat} \mathbin{@} \text{vec})
  4436. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4437. it will not be propagated.
  4438. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4439. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4440. Args:
  4441. input (Tensor): vector to be added
  4442. mat (Tensor): matrix to be matrix multiplied
  4443. vec (Tensor): vector to be matrix multiplied
  4444. Keyword args:
  4445. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4446. alpha (Number, optional): multiplier for :math:`mat @ vec` (:math:`\alpha`)
  4447. out (Tensor, optional): the output tensor.
  4448. Example::
  4449. >>> M = torch.randn(2)
  4450. >>> mat = torch.randn(2, 3)
  4451. >>> vec = torch.randn(3)
  4452. >>> torch.addmv(M, mat, vec)
  4453. tensor([-0.3768, -5.5565])
  4454. """
  4455. @overload
  4456. def addmv(
  4457. beta: Number | _complex,
  4458. self: Tensor,
  4459. alpha: Number | _complex,
  4460. mat: Tensor,
  4461. vec: Tensor,
  4462. *,
  4463. out: Tensor,
  4464. ) -> Tensor:
  4465. r"""
  4466. addmv(input, mat, vec, *, beta=1, alpha=1, out=None) -> Tensor
  4467. Performs a matrix-vector product of the matrix :attr:`mat` and
  4468. the vector :attr:`vec`.
  4469. The vector :attr:`input` is added to the final result.
  4470. If :attr:`mat` is a :math:`(n \times m)` tensor, :attr:`vec` is a 1-D tensor of
  4471. size `m`, then :attr:`input` must be
  4472. :ref:`broadcastable <broadcasting-semantics>` with a 1-D tensor of size `n` and
  4473. :attr:`out` will be 1-D tensor of size `n`.
  4474. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4475. :attr:`mat` and :attr:`vec` and the added tensor :attr:`input` respectively.
  4476. .. math::
  4477. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat} \mathbin{@} \text{vec})
  4478. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4479. it will not be propagated.
  4480. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4481. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4482. Args:
  4483. input (Tensor): vector to be added
  4484. mat (Tensor): matrix to be matrix multiplied
  4485. vec (Tensor): vector to be matrix multiplied
  4486. Keyword args:
  4487. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4488. alpha (Number, optional): multiplier for :math:`mat @ vec` (:math:`\alpha`)
  4489. out (Tensor, optional): the output tensor.
  4490. Example::
  4491. >>> M = torch.randn(2)
  4492. >>> mat = torch.randn(2, 3)
  4493. >>> vec = torch.randn(3)
  4494. >>> torch.addmv(M, mat, vec)
  4495. tensor([-0.3768, -5.5565])
  4496. """
  4497. @overload
  4498. def addmv(
  4499. input: Tensor,
  4500. mat: Tensor,
  4501. vec: Tensor,
  4502. *,
  4503. beta: Number | _complex = 1,
  4504. alpha: Number | _complex = 1,
  4505. out: Tensor | None = None,
  4506. ) -> Tensor:
  4507. r"""
  4508. addmv(input, mat, vec, *, beta=1, alpha=1, out=None) -> Tensor
  4509. Performs a matrix-vector product of the matrix :attr:`mat` and
  4510. the vector :attr:`vec`.
  4511. The vector :attr:`input` is added to the final result.
  4512. If :attr:`mat` is a :math:`(n \times m)` tensor, :attr:`vec` is a 1-D tensor of
  4513. size `m`, then :attr:`input` must be
  4514. :ref:`broadcastable <broadcasting-semantics>` with a 1-D tensor of size `n` and
  4515. :attr:`out` will be 1-D tensor of size `n`.
  4516. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4517. :attr:`mat` and :attr:`vec` and the added tensor :attr:`input` respectively.
  4518. .. math::
  4519. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat} \mathbin{@} \text{vec})
  4520. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4521. it will not be propagated.
  4522. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4523. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4524. Args:
  4525. input (Tensor): vector to be added
  4526. mat (Tensor): matrix to be matrix multiplied
  4527. vec (Tensor): vector to be matrix multiplied
  4528. Keyword args:
  4529. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4530. alpha (Number, optional): multiplier for :math:`mat @ vec` (:math:`\alpha`)
  4531. out (Tensor, optional): the output tensor.
  4532. Example::
  4533. >>> M = torch.randn(2)
  4534. >>> mat = torch.randn(2, 3)
  4535. >>> vec = torch.randn(3)
  4536. >>> torch.addmv(M, mat, vec)
  4537. tensor([-0.3768, -5.5565])
  4538. """
  4539. @overload
  4540. def addmv(
  4541. beta: Number | _complex,
  4542. self: Tensor,
  4543. mat: Tensor,
  4544. vec: Tensor,
  4545. ) -> Tensor:
  4546. r"""
  4547. addmv(input, mat, vec, *, beta=1, alpha=1, out=None) -> Tensor
  4548. Performs a matrix-vector product of the matrix :attr:`mat` and
  4549. the vector :attr:`vec`.
  4550. The vector :attr:`input` is added to the final result.
  4551. If :attr:`mat` is a :math:`(n \times m)` tensor, :attr:`vec` is a 1-D tensor of
  4552. size `m`, then :attr:`input` must be
  4553. :ref:`broadcastable <broadcasting-semantics>` with a 1-D tensor of size `n` and
  4554. :attr:`out` will be 1-D tensor of size `n`.
  4555. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4556. :attr:`mat` and :attr:`vec` and the added tensor :attr:`input` respectively.
  4557. .. math::
  4558. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat} \mathbin{@} \text{vec})
  4559. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4560. it will not be propagated.
  4561. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4562. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4563. Args:
  4564. input (Tensor): vector to be added
  4565. mat (Tensor): matrix to be matrix multiplied
  4566. vec (Tensor): vector to be matrix multiplied
  4567. Keyword args:
  4568. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4569. alpha (Number, optional): multiplier for :math:`mat @ vec` (:math:`\alpha`)
  4570. out (Tensor, optional): the output tensor.
  4571. Example::
  4572. >>> M = torch.randn(2)
  4573. >>> mat = torch.randn(2, 3)
  4574. >>> vec = torch.randn(3)
  4575. >>> torch.addmv(M, mat, vec)
  4576. tensor([-0.3768, -5.5565])
  4577. """
  4578. @overload
  4579. def addmv(
  4580. beta: Number | _complex,
  4581. self: Tensor,
  4582. mat: Tensor,
  4583. vec: Tensor,
  4584. *,
  4585. out: Tensor,
  4586. ) -> Tensor:
  4587. r"""
  4588. addmv(input, mat, vec, *, beta=1, alpha=1, out=None) -> Tensor
  4589. Performs a matrix-vector product of the matrix :attr:`mat` and
  4590. the vector :attr:`vec`.
  4591. The vector :attr:`input` is added to the final result.
  4592. If :attr:`mat` is a :math:`(n \times m)` tensor, :attr:`vec` is a 1-D tensor of
  4593. size `m`, then :attr:`input` must be
  4594. :ref:`broadcastable <broadcasting-semantics>` with a 1-D tensor of size `n` and
  4595. :attr:`out` will be 1-D tensor of size `n`.
  4596. :attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
  4597. :attr:`mat` and :attr:`vec` and the added tensor :attr:`input` respectively.
  4598. .. math::
  4599. \text{out} = \beta\ \text{input} + \alpha\ (\text{mat} \mathbin{@} \text{vec})
  4600. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4601. it will not be propagated.
  4602. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  4603. :attr:`alpha` must be real numbers, otherwise they should be integers.
  4604. Args:
  4605. input (Tensor): vector to be added
  4606. mat (Tensor): matrix to be matrix multiplied
  4607. vec (Tensor): vector to be matrix multiplied
  4608. Keyword args:
  4609. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4610. alpha (Number, optional): multiplier for :math:`mat @ vec` (:math:`\alpha`)
  4611. out (Tensor, optional): the output tensor.
  4612. Example::
  4613. >>> M = torch.randn(2)
  4614. >>> mat = torch.randn(2, 3)
  4615. >>> vec = torch.randn(3)
  4616. >>> torch.addmv(M, mat, vec)
  4617. tensor([-0.3768, -5.5565])
  4618. """
  4619. @overload
  4620. def addmv_(
  4621. beta: Number | _complex,
  4622. self: Tensor,
  4623. alpha: Number | _complex,
  4624. mat: Tensor,
  4625. vec: Tensor,
  4626. ) -> Tensor: ...
  4627. @overload
  4628. def addmv_(
  4629. input: Tensor,
  4630. mat: Tensor,
  4631. vec: Tensor,
  4632. *,
  4633. beta: Number | _complex = 1,
  4634. alpha: Number | _complex = 1,
  4635. ) -> Tensor: ...
  4636. @overload
  4637. def addmv_(
  4638. beta: Number | _complex,
  4639. self: Tensor,
  4640. mat: Tensor,
  4641. vec: Tensor,
  4642. ) -> Tensor: ...
  4643. @overload
  4644. def addr(
  4645. beta: Number | _complex,
  4646. self: Tensor,
  4647. alpha: Number | _complex,
  4648. vec1: Tensor,
  4649. vec2: Tensor,
  4650. ) -> Tensor:
  4651. r"""
  4652. addr(input, vec1, vec2, *, beta=1, alpha=1, out=None) -> Tensor
  4653. Performs the outer-product of vectors :attr:`vec1` and :attr:`vec2`
  4654. and adds it to the matrix :attr:`input`.
  4655. Optional values :attr:`beta` and :attr:`alpha` are scaling factors on the
  4656. outer product between :attr:`vec1` and :attr:`vec2` and the added matrix
  4657. :attr:`input` respectively.
  4658. .. math::
  4659. \text{out} = \beta\ \text{input} + \alpha\ (\text{vec1} \otimes \text{vec2})
  4660. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4661. it will not be propagated.
  4662. If :attr:`vec1` is a vector of size `n` and :attr:`vec2` is a vector
  4663. of size `m`, then :attr:`input` must be
  4664. :ref:`broadcastable <broadcasting-semantics>` with a matrix of size
  4665. :math:`(n \times m)` and :attr:`out` will be a matrix of size
  4666. :math:`(n \times m)`.
  4667. Args:
  4668. input (Tensor): matrix to be added
  4669. vec1 (Tensor): the first vector of the outer product
  4670. vec2 (Tensor): the second vector of the outer product
  4671. Keyword args:
  4672. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4673. alpha (Number, optional): multiplier for :math:`\text{vec1} \otimes \text{vec2}` (:math:`\alpha`)
  4674. out (Tensor, optional): the output tensor.
  4675. Example::
  4676. >>> vec1 = torch.arange(1., 4.)
  4677. >>> vec2 = torch.arange(1., 3.)
  4678. >>> M = torch.zeros(3, 2)
  4679. >>> torch.addr(M, vec1, vec2)
  4680. tensor([[ 1., 2.],
  4681. [ 2., 4.],
  4682. [ 3., 6.]])
  4683. """
  4684. @overload
  4685. def addr(
  4686. beta: Number | _complex,
  4687. self: Tensor,
  4688. alpha: Number | _complex,
  4689. vec1: Tensor,
  4690. vec2: Tensor,
  4691. *,
  4692. out: Tensor,
  4693. ) -> Tensor:
  4694. r"""
  4695. addr(input, vec1, vec2, *, beta=1, alpha=1, out=None) -> Tensor
  4696. Performs the outer-product of vectors :attr:`vec1` and :attr:`vec2`
  4697. and adds it to the matrix :attr:`input`.
  4698. Optional values :attr:`beta` and :attr:`alpha` are scaling factors on the
  4699. outer product between :attr:`vec1` and :attr:`vec2` and the added matrix
  4700. :attr:`input` respectively.
  4701. .. math::
  4702. \text{out} = \beta\ \text{input} + \alpha\ (\text{vec1} \otimes \text{vec2})
  4703. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4704. it will not be propagated.
  4705. If :attr:`vec1` is a vector of size `n` and :attr:`vec2` is a vector
  4706. of size `m`, then :attr:`input` must be
  4707. :ref:`broadcastable <broadcasting-semantics>` with a matrix of size
  4708. :math:`(n \times m)` and :attr:`out` will be a matrix of size
  4709. :math:`(n \times m)`.
  4710. Args:
  4711. input (Tensor): matrix to be added
  4712. vec1 (Tensor): the first vector of the outer product
  4713. vec2 (Tensor): the second vector of the outer product
  4714. Keyword args:
  4715. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4716. alpha (Number, optional): multiplier for :math:`\text{vec1} \otimes \text{vec2}` (:math:`\alpha`)
  4717. out (Tensor, optional): the output tensor.
  4718. Example::
  4719. >>> vec1 = torch.arange(1., 4.)
  4720. >>> vec2 = torch.arange(1., 3.)
  4721. >>> M = torch.zeros(3, 2)
  4722. >>> torch.addr(M, vec1, vec2)
  4723. tensor([[ 1., 2.],
  4724. [ 2., 4.],
  4725. [ 3., 6.]])
  4726. """
  4727. @overload
  4728. def addr(
  4729. input: Tensor,
  4730. vec1: Tensor,
  4731. vec2: Tensor,
  4732. *,
  4733. beta: Number | _complex = 1,
  4734. alpha: Number | _complex = 1,
  4735. out: Tensor | None = None,
  4736. ) -> Tensor:
  4737. r"""
  4738. addr(input, vec1, vec2, *, beta=1, alpha=1, out=None) -> Tensor
  4739. Performs the outer-product of vectors :attr:`vec1` and :attr:`vec2`
  4740. and adds it to the matrix :attr:`input`.
  4741. Optional values :attr:`beta` and :attr:`alpha` are scaling factors on the
  4742. outer product between :attr:`vec1` and :attr:`vec2` and the added matrix
  4743. :attr:`input` respectively.
  4744. .. math::
  4745. \text{out} = \beta\ \text{input} + \alpha\ (\text{vec1} \otimes \text{vec2})
  4746. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4747. it will not be propagated.
  4748. If :attr:`vec1` is a vector of size `n` and :attr:`vec2` is a vector
  4749. of size `m`, then :attr:`input` must be
  4750. :ref:`broadcastable <broadcasting-semantics>` with a matrix of size
  4751. :math:`(n \times m)` and :attr:`out` will be a matrix of size
  4752. :math:`(n \times m)`.
  4753. Args:
  4754. input (Tensor): matrix to be added
  4755. vec1 (Tensor): the first vector of the outer product
  4756. vec2 (Tensor): the second vector of the outer product
  4757. Keyword args:
  4758. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4759. alpha (Number, optional): multiplier for :math:`\text{vec1} \otimes \text{vec2}` (:math:`\alpha`)
  4760. out (Tensor, optional): the output tensor.
  4761. Example::
  4762. >>> vec1 = torch.arange(1., 4.)
  4763. >>> vec2 = torch.arange(1., 3.)
  4764. >>> M = torch.zeros(3, 2)
  4765. >>> torch.addr(M, vec1, vec2)
  4766. tensor([[ 1., 2.],
  4767. [ 2., 4.],
  4768. [ 3., 6.]])
  4769. """
  4770. @overload
  4771. def addr(
  4772. beta: Number | _complex,
  4773. self: Tensor,
  4774. vec1: Tensor,
  4775. vec2: Tensor,
  4776. ) -> Tensor:
  4777. r"""
  4778. addr(input, vec1, vec2, *, beta=1, alpha=1, out=None) -> Tensor
  4779. Performs the outer-product of vectors :attr:`vec1` and :attr:`vec2`
  4780. and adds it to the matrix :attr:`input`.
  4781. Optional values :attr:`beta` and :attr:`alpha` are scaling factors on the
  4782. outer product between :attr:`vec1` and :attr:`vec2` and the added matrix
  4783. :attr:`input` respectively.
  4784. .. math::
  4785. \text{out} = \beta\ \text{input} + \alpha\ (\text{vec1} \otimes \text{vec2})
  4786. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4787. it will not be propagated.
  4788. If :attr:`vec1` is a vector of size `n` and :attr:`vec2` is a vector
  4789. of size `m`, then :attr:`input` must be
  4790. :ref:`broadcastable <broadcasting-semantics>` with a matrix of size
  4791. :math:`(n \times m)` and :attr:`out` will be a matrix of size
  4792. :math:`(n \times m)`.
  4793. Args:
  4794. input (Tensor): matrix to be added
  4795. vec1 (Tensor): the first vector of the outer product
  4796. vec2 (Tensor): the second vector of the outer product
  4797. Keyword args:
  4798. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4799. alpha (Number, optional): multiplier for :math:`\text{vec1} \otimes \text{vec2}` (:math:`\alpha`)
  4800. out (Tensor, optional): the output tensor.
  4801. Example::
  4802. >>> vec1 = torch.arange(1., 4.)
  4803. >>> vec2 = torch.arange(1., 3.)
  4804. >>> M = torch.zeros(3, 2)
  4805. >>> torch.addr(M, vec1, vec2)
  4806. tensor([[ 1., 2.],
  4807. [ 2., 4.],
  4808. [ 3., 6.]])
  4809. """
  4810. @overload
  4811. def addr(
  4812. beta: Number | _complex,
  4813. self: Tensor,
  4814. vec1: Tensor,
  4815. vec2: Tensor,
  4816. *,
  4817. out: Tensor,
  4818. ) -> Tensor:
  4819. r"""
  4820. addr(input, vec1, vec2, *, beta=1, alpha=1, out=None) -> Tensor
  4821. Performs the outer-product of vectors :attr:`vec1` and :attr:`vec2`
  4822. and adds it to the matrix :attr:`input`.
  4823. Optional values :attr:`beta` and :attr:`alpha` are scaling factors on the
  4824. outer product between :attr:`vec1` and :attr:`vec2` and the added matrix
  4825. :attr:`input` respectively.
  4826. .. math::
  4827. \text{out} = \beta\ \text{input} + \alpha\ (\text{vec1} \otimes \text{vec2})
  4828. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  4829. it will not be propagated.
  4830. If :attr:`vec1` is a vector of size `n` and :attr:`vec2` is a vector
  4831. of size `m`, then :attr:`input` must be
  4832. :ref:`broadcastable <broadcasting-semantics>` with a matrix of size
  4833. :math:`(n \times m)` and :attr:`out` will be a matrix of size
  4834. :math:`(n \times m)`.
  4835. Args:
  4836. input (Tensor): matrix to be added
  4837. vec1 (Tensor): the first vector of the outer product
  4838. vec2 (Tensor): the second vector of the outer product
  4839. Keyword args:
  4840. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  4841. alpha (Number, optional): multiplier for :math:`\text{vec1} \otimes \text{vec2}` (:math:`\alpha`)
  4842. out (Tensor, optional): the output tensor.
  4843. Example::
  4844. >>> vec1 = torch.arange(1., 4.)
  4845. >>> vec2 = torch.arange(1., 3.)
  4846. >>> M = torch.zeros(3, 2)
  4847. >>> torch.addr(M, vec1, vec2)
  4848. tensor([[ 1., 2.],
  4849. [ 2., 4.],
  4850. [ 3., 6.]])
  4851. """
  4852. def adjoint(input: Tensor) -> Tensor:
  4853. r"""
  4854. adjoint(input: Tensor) -> Tensor
  4855. Returns a view of the tensor conjugated and with the last two dimensions transposed.
  4856. ``x.adjoint()`` is equivalent to ``x.transpose(-2, -1).conj()`` for complex tensors and
  4857. to ``x.transpose(-2, -1)`` for real tensors.
  4858. Args:
  4859. {input}
  4860. Example::
  4861. >>> x = torch.arange(4, dtype=torch.float)
  4862. >>> A = torch.complex(x, x).reshape(2, 2)
  4863. >>> A
  4864. tensor([[0.+0.j, 1.+1.j],
  4865. [2.+2.j, 3.+3.j]])
  4866. >>> A.adjoint()
  4867. tensor([[0.-0.j, 2.-2.j],
  4868. [1.-1.j, 3.-3.j]])
  4869. >>> (A.adjoint() == A.mH).all()
  4870. tensor(True)
  4871. """
  4872. def affine_grid_generator(
  4873. theta: Tensor,
  4874. size: Sequence[_int | SymInt],
  4875. align_corners: _bool,
  4876. ) -> Tensor: ...
  4877. def alias_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  4878. r"""
  4879. Performs the same operation as :func:`torch.alias`, but all output tensors
  4880. are freshly created instead of aliasing the input.
  4881. """
  4882. @overload
  4883. def all(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  4884. r"""
  4885. all(input: Tensor, *, out=None) -> Tensor
  4886. Tests if all elements in :attr:`input` evaluate to `True`.
  4887. .. note:: This function matches the behaviour of NumPy in returning
  4888. output of dtype `bool` for all supported dtypes except `uint8`.
  4889. For `uint8` the dtype of output is `uint8` itself.
  4890. Args:
  4891. input (Tensor): the input tensor.
  4892. Keyword args:
  4893. out (Tensor, optional): the output tensor.
  4894. Example::
  4895. >>> a = torch.rand(1, 2).bool()
  4896. >>> a
  4897. tensor([[False, True]], dtype=torch.bool)
  4898. >>> torch.all(a)
  4899. tensor(False, dtype=torch.bool)
  4900. >>> a = torch.arange(0, 3)
  4901. >>> a
  4902. tensor([0, 1, 2])
  4903. >>> torch.all(a)
  4904. tensor(False)
  4905. .. function:: all(input, dim, keepdim=False, *, out=None) -> Tensor
  4906. :noindex:
  4907. For each row of :attr:`input` in the given dimension :attr:`dim`,
  4908. returns `True` if all elements in the row evaluate to `True` and `False` otherwise.
  4909. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  4910. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  4911. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  4912. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  4913. Args:
  4914. input (Tensor): the input tensor.
  4915. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  4916. If ``None``, all dimensions are reduced.
  4917. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  4918. Keyword args:
  4919. out (Tensor, optional): the output tensor.
  4920. Example::
  4921. >>> a = torch.rand(4, 2).bool()
  4922. >>> a
  4923. tensor([[True, True],
  4924. [True, False],
  4925. [True, True],
  4926. [True, True]], dtype=torch.bool)
  4927. >>> torch.all(a, dim=1)
  4928. tensor([ True, False, True, True], dtype=torch.bool)
  4929. >>> torch.all(a, dim=0)
  4930. tensor([ True, False], dtype=torch.bool)
  4931. """
  4932. @overload
  4933. def all(
  4934. input: Tensor,
  4935. dim: _size | None = None,
  4936. keepdim: _bool = False,
  4937. *,
  4938. out: Tensor | None = None,
  4939. ) -> Tensor:
  4940. r"""
  4941. all(input: Tensor, *, out=None) -> Tensor
  4942. Tests if all elements in :attr:`input` evaluate to `True`.
  4943. .. note:: This function matches the behaviour of NumPy in returning
  4944. output of dtype `bool` for all supported dtypes except `uint8`.
  4945. For `uint8` the dtype of output is `uint8` itself.
  4946. Args:
  4947. input (Tensor): the input tensor.
  4948. Keyword args:
  4949. out (Tensor, optional): the output tensor.
  4950. Example::
  4951. >>> a = torch.rand(1, 2).bool()
  4952. >>> a
  4953. tensor([[False, True]], dtype=torch.bool)
  4954. >>> torch.all(a)
  4955. tensor(False, dtype=torch.bool)
  4956. >>> a = torch.arange(0, 3)
  4957. >>> a
  4958. tensor([0, 1, 2])
  4959. >>> torch.all(a)
  4960. tensor(False)
  4961. .. function:: all(input, dim, keepdim=False, *, out=None) -> Tensor
  4962. :noindex:
  4963. For each row of :attr:`input` in the given dimension :attr:`dim`,
  4964. returns `True` if all elements in the row evaluate to `True` and `False` otherwise.
  4965. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  4966. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  4967. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  4968. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  4969. Args:
  4970. input (Tensor): the input tensor.
  4971. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  4972. If ``None``, all dimensions are reduced.
  4973. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  4974. Keyword args:
  4975. out (Tensor, optional): the output tensor.
  4976. Example::
  4977. >>> a = torch.rand(4, 2).bool()
  4978. >>> a
  4979. tensor([[True, True],
  4980. [True, False],
  4981. [True, True],
  4982. [True, True]], dtype=torch.bool)
  4983. >>> torch.all(a, dim=1)
  4984. tensor([ True, False, True, True], dtype=torch.bool)
  4985. >>> torch.all(a, dim=0)
  4986. tensor([ True, False], dtype=torch.bool)
  4987. """
  4988. @overload
  4989. def all(
  4990. input: Tensor,
  4991. dim: _int,
  4992. keepdim: _bool = False,
  4993. *,
  4994. out: Tensor | None = None,
  4995. ) -> Tensor:
  4996. r"""
  4997. all(input: Tensor, *, out=None) -> Tensor
  4998. Tests if all elements in :attr:`input` evaluate to `True`.
  4999. .. note:: This function matches the behaviour of NumPy in returning
  5000. output of dtype `bool` for all supported dtypes except `uint8`.
  5001. For `uint8` the dtype of output is `uint8` itself.
  5002. Args:
  5003. input (Tensor): the input tensor.
  5004. Keyword args:
  5005. out (Tensor, optional): the output tensor.
  5006. Example::
  5007. >>> a = torch.rand(1, 2).bool()
  5008. >>> a
  5009. tensor([[False, True]], dtype=torch.bool)
  5010. >>> torch.all(a)
  5011. tensor(False, dtype=torch.bool)
  5012. >>> a = torch.arange(0, 3)
  5013. >>> a
  5014. tensor([0, 1, 2])
  5015. >>> torch.all(a)
  5016. tensor(False)
  5017. .. function:: all(input, dim, keepdim=False, *, out=None) -> Tensor
  5018. :noindex:
  5019. For each row of :attr:`input` in the given dimension :attr:`dim`,
  5020. returns `True` if all elements in the row evaluate to `True` and `False` otherwise.
  5021. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  5022. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  5023. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  5024. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  5025. Args:
  5026. input (Tensor): the input tensor.
  5027. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  5028. If ``None``, all dimensions are reduced.
  5029. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5030. Keyword args:
  5031. out (Tensor, optional): the output tensor.
  5032. Example::
  5033. >>> a = torch.rand(4, 2).bool()
  5034. >>> a
  5035. tensor([[True, True],
  5036. [True, False],
  5037. [True, True],
  5038. [True, True]], dtype=torch.bool)
  5039. >>> torch.all(a, dim=1)
  5040. tensor([ True, False, True, True], dtype=torch.bool)
  5041. >>> torch.all(a, dim=0)
  5042. tensor([ True, False], dtype=torch.bool)
  5043. """
  5044. @overload
  5045. def all(
  5046. input: Tensor,
  5047. dim: str | EllipsisType | None,
  5048. keepdim: _bool = False,
  5049. *,
  5050. out: Tensor | None = None,
  5051. ) -> Tensor:
  5052. r"""
  5053. all(input: Tensor, *, out=None) -> Tensor
  5054. Tests if all elements in :attr:`input` evaluate to `True`.
  5055. .. note:: This function matches the behaviour of NumPy in returning
  5056. output of dtype `bool` for all supported dtypes except `uint8`.
  5057. For `uint8` the dtype of output is `uint8` itself.
  5058. Args:
  5059. input (Tensor): the input tensor.
  5060. Keyword args:
  5061. out (Tensor, optional): the output tensor.
  5062. Example::
  5063. >>> a = torch.rand(1, 2).bool()
  5064. >>> a
  5065. tensor([[False, True]], dtype=torch.bool)
  5066. >>> torch.all(a)
  5067. tensor(False, dtype=torch.bool)
  5068. >>> a = torch.arange(0, 3)
  5069. >>> a
  5070. tensor([0, 1, 2])
  5071. >>> torch.all(a)
  5072. tensor(False)
  5073. .. function:: all(input, dim, keepdim=False, *, out=None) -> Tensor
  5074. :noindex:
  5075. For each row of :attr:`input` in the given dimension :attr:`dim`,
  5076. returns `True` if all elements in the row evaluate to `True` and `False` otherwise.
  5077. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  5078. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  5079. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  5080. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  5081. Args:
  5082. input (Tensor): the input tensor.
  5083. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  5084. If ``None``, all dimensions are reduced.
  5085. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5086. Keyword args:
  5087. out (Tensor, optional): the output tensor.
  5088. Example::
  5089. >>> a = torch.rand(4, 2).bool()
  5090. >>> a
  5091. tensor([[True, True],
  5092. [True, False],
  5093. [True, True],
  5094. [True, True]], dtype=torch.bool)
  5095. >>> torch.all(a, dim=1)
  5096. tensor([ True, False, True, True], dtype=torch.bool)
  5097. >>> torch.all(a, dim=0)
  5098. tensor([ True, False], dtype=torch.bool)
  5099. """
  5100. def allclose(
  5101. input: Tensor,
  5102. other: Tensor,
  5103. rtol: _float = 1e-05,
  5104. atol: _float = 1e-08,
  5105. equal_nan: _bool = False,
  5106. ) -> _bool:
  5107. r"""
  5108. allclose(input: Tensor, other: Tensor, rtol: float = 1e-05, atol: float = 1e-08, equal_nan: bool = False) -> bool
  5109. This function checks if :attr:`input` and :attr:`other` satisfy the condition:
  5110. .. math::
  5111. \lvert \text{input}_i - \text{other}_i \rvert \leq \texttt{atol} + \texttt{rtol} \times \lvert \text{other}_i \rvert
  5112. elementwise, for all elements of :attr:`input` and :attr:`other`. The behaviour of this function is analogous to
  5113. `numpy.allclose <https://numpy.org/doc/stable/reference/generated/numpy.allclose.html>`_
  5114. Args:
  5115. input (Tensor): first tensor to compare
  5116. other (Tensor): second tensor to compare
  5117. atol (float, optional): absolute tolerance. Default: 1e-08
  5118. rtol (float, optional): relative tolerance. Default: 1e-05
  5119. equal_nan (bool, optional): if ``True``, then two ``NaN`` s will be considered equal. Default: ``False``
  5120. Example::
  5121. >>> torch.allclose(torch.tensor([10000., 1e-07]), torch.tensor([10000.1, 1e-08]))
  5122. False
  5123. >>> torch.allclose(torch.tensor([10000., 1e-08]), torch.tensor([10000.1, 1e-09]))
  5124. True
  5125. >>> torch.allclose(torch.tensor([1.0, float('nan')]), torch.tensor([1.0, float('nan')]))
  5126. False
  5127. >>> torch.allclose(torch.tensor([1.0, float('nan')]), torch.tensor([1.0, float('nan')]), equal_nan=True)
  5128. True
  5129. """
  5130. def alpha_dropout(input: Tensor, p: _float, train: _bool) -> Tensor: ...
  5131. def alpha_dropout_(input: Tensor, p: _float, train: _bool) -> Tensor: ...
  5132. def amax(
  5133. input: Tensor,
  5134. dim: _int | _size = (),
  5135. keepdim: _bool = False,
  5136. *,
  5137. out: Tensor | None = None,
  5138. ) -> Tensor:
  5139. r"""
  5140. amax(input, dim, keepdim=False, *, out=None) -> Tensor
  5141. Returns the maximum value of each slice of the :attr:`input` tensor in the given
  5142. dimension(s) :attr:`dim`.
  5143. .. note::
  5144. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  5145. - ``amax``/``amin`` supports reducing on multiple dimensions,
  5146. - ``amax``/``amin`` does not return indices.
  5147. Both ``amax``/``amin`` evenly distribute gradients between equal values
  5148. when there are multiple input elements with the same minimum or maximum value.
  5149. For ``max``/``min``:
  5150. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  5151. - If reduce over one specified axis, only propagate to the indexed element.
  5152. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  5153. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  5154. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  5155. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  5156. Args:
  5157. input (Tensor): the input tensor.
  5158. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  5159. If ``None``, all dimensions are reduced.
  5160. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5161. Keyword args:
  5162. out (Tensor, optional): the output tensor.
  5163. Example::
  5164. >>> a = torch.randn(4, 4)
  5165. >>> a
  5166. tensor([[ 0.8177, 1.4878, -0.2491, 0.9130],
  5167. [-0.7158, 1.1775, 2.0992, 0.4817],
  5168. [-0.0053, 0.0164, -1.3738, -0.0507],
  5169. [ 1.9700, 1.1106, -1.0318, -1.0816]])
  5170. >>> torch.amax(a, 1)
  5171. tensor([1.4878, 2.0992, 0.0164, 1.9700])
  5172. """
  5173. def amin(
  5174. input: Tensor,
  5175. dim: _int | _size = (),
  5176. keepdim: _bool = False,
  5177. *,
  5178. out: Tensor | None = None,
  5179. ) -> Tensor:
  5180. r"""
  5181. amin(input, dim, keepdim=False, *, out=None) -> Tensor
  5182. Returns the minimum value of each slice of the :attr:`input` tensor in the given
  5183. dimension(s) :attr:`dim`.
  5184. .. note::
  5185. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  5186. - ``amax``/``amin`` supports reducing on multiple dimensions,
  5187. - ``amax``/``amin`` does not return indices.
  5188. Both ``amax``/``amin`` evenly distribute gradients between equal values
  5189. when there are multiple input elements with the same minimum or maximum value.
  5190. For ``max``/``min``:
  5191. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  5192. - If reduce over one specified axis, only propagate to the indexed element.
  5193. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  5194. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  5195. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  5196. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  5197. Args:
  5198. input (Tensor): the input tensor.
  5199. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  5200. If ``None``, all dimensions are reduced.
  5201. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5202. Keyword args:
  5203. out (Tensor, optional): the output tensor.
  5204. Example::
  5205. >>> a = torch.randn(4, 4)
  5206. >>> a
  5207. tensor([[ 0.6451, -0.4866, 0.2987, -1.3312],
  5208. [-0.5744, 1.2980, 1.8397, -0.2713],
  5209. [ 0.9128, 0.9214, -1.7268, -0.2995],
  5210. [ 0.9023, 0.4853, 0.9075, -1.6165]])
  5211. >>> torch.amin(a, 1)
  5212. tensor([-1.3312, -0.5744, -1.7268, -1.6165])
  5213. """
  5214. def aminmax(
  5215. input: Tensor,
  5216. *,
  5217. dim: _int | None = None,
  5218. keepdim: _bool = False,
  5219. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  5220. ) -> torch.return_types.aminmax:
  5221. r"""
  5222. aminmax(input, *, dim=None, keepdim=False, out=None) -> (Tensor min, Tensor max)
  5223. Computes the minimum and maximum values of the :attr:`input` tensor.
  5224. Args:
  5225. input (Tensor):
  5226. The input tensor
  5227. Keyword Args:
  5228. dim (Optional[int]):
  5229. The dimension along which to compute the values. If `None`,
  5230. computes the values over the entire :attr:`input` tensor.
  5231. Default is `None`.
  5232. keepdim (bool):
  5233. If `True`, the reduced dimensions will be kept in the output
  5234. tensor as dimensions with size 1 for broadcasting, otherwise
  5235. they will be removed, as if calling (:func:`torch.squeeze`).
  5236. Default is `False`.
  5237. out (Optional[Tuple[Tensor, Tensor]]):
  5238. Optional tensors on which to write the result. Must have the same
  5239. shape and dtype as the expected output.
  5240. Default is `None`.
  5241. Returns:
  5242. A named tuple `(min, max)` containing the minimum and maximum values.
  5243. Raises:
  5244. RuntimeError
  5245. If any of the dimensions to compute the values over has size 0.
  5246. .. note::
  5247. NaN values are propagated to the output if at least one value is NaN.
  5248. .. seealso::
  5249. :func:`torch.amin` computes just the minimum value
  5250. :func:`torch.amax` computes just the maximum value
  5251. Example::
  5252. >>> torch.aminmax(torch.tensor([1, -3, 5]))
  5253. torch.return_types.aminmax(
  5254. min=tensor(-3),
  5255. max=tensor(5))
  5256. >>> # aminmax propagates NaNs
  5257. >>> torch.aminmax(torch.tensor([1, -3, 5, torch.nan]))
  5258. torch.return_types.aminmax(
  5259. min=tensor(nan),
  5260. max=tensor(nan))
  5261. >>> t = torch.arange(10).view(2, 5)
  5262. >>> t
  5263. tensor([[0, 1, 2, 3, 4],
  5264. [5, 6, 7, 8, 9]])
  5265. >>> t.aminmax(dim=0, keepdim=True)
  5266. torch.return_types.aminmax(
  5267. min=tensor([[0, 1, 2, 3, 4]]),
  5268. max=tensor([[5, 6, 7, 8, 9]]))
  5269. """
  5270. def angle(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  5271. r"""
  5272. angle(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5273. Computes the element-wise angle (in radians) of the given :attr:`input` tensor.
  5274. .. math::
  5275. \text{out}_{i} = angle(\text{input}_{i})
  5276. Args:
  5277. input (Tensor): the input tensor.
  5278. Keyword args:
  5279. out (Tensor, optional): the output tensor.
  5280. .. note:: Starting in PyTorch 1.8, angle returns pi for negative real numbers,
  5281. zero for non-negative real numbers, and propagates NaNs. Previously
  5282. the function would return zero for all real numbers and not propagate
  5283. floating-point NaNs.
  5284. Example::
  5285. >>> torch.angle(torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j]))*180/3.14159
  5286. tensor([ 135., 135, -45])
  5287. """
  5288. @overload
  5289. def any(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  5290. r"""
  5291. any(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5292. Tests if any element in :attr:`input` evaluates to `True`.
  5293. .. note:: This function matches the behaviour of NumPy in returning
  5294. output of dtype `bool` for all supported dtypes except `uint8`.
  5295. For `uint8` the dtype of output is `uint8` itself.
  5296. Args:
  5297. input (Tensor): the input tensor.
  5298. Keyword args:
  5299. out (Tensor, optional): the output tensor.
  5300. Example::
  5301. >>> a = torch.rand(1, 2).bool()
  5302. >>> a
  5303. tensor([[False, True]], dtype=torch.bool)
  5304. >>> torch.any(a)
  5305. tensor(True, dtype=torch.bool)
  5306. >>> a = torch.arange(0, 3)
  5307. >>> a
  5308. tensor([0, 1, 2])
  5309. >>> torch.any(a)
  5310. tensor(True)
  5311. .. function:: any(input, dim, keepdim=False, *, out=None) -> Tensor
  5312. :noindex:
  5313. For each row of :attr:`input` in the given dimension :attr:`dim`,
  5314. returns `True` if any element in the row evaluate to `True` and `False` otherwise.
  5315. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  5316. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  5317. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  5318. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  5319. Args:
  5320. input (Tensor): the input tensor.
  5321. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  5322. If ``None``, all dimensions are reduced.
  5323. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5324. Keyword args:
  5325. out (Tensor, optional): the output tensor.
  5326. Example::
  5327. >>> a = torch.randn(4, 2) < 0
  5328. >>> a
  5329. tensor([[ True, True],
  5330. [False, True],
  5331. [ True, True],
  5332. [False, False]])
  5333. >>> torch.any(a, 1)
  5334. tensor([ True, True, True, False])
  5335. >>> torch.any(a, 0)
  5336. tensor([True, True])
  5337. """
  5338. @overload
  5339. def any(
  5340. input: Tensor,
  5341. dim: _size | None = None,
  5342. keepdim: _bool = False,
  5343. *,
  5344. out: Tensor | None = None,
  5345. ) -> Tensor:
  5346. r"""
  5347. any(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5348. Tests if any element in :attr:`input` evaluates to `True`.
  5349. .. note:: This function matches the behaviour of NumPy in returning
  5350. output of dtype `bool` for all supported dtypes except `uint8`.
  5351. For `uint8` the dtype of output is `uint8` itself.
  5352. Args:
  5353. input (Tensor): the input tensor.
  5354. Keyword args:
  5355. out (Tensor, optional): the output tensor.
  5356. Example::
  5357. >>> a = torch.rand(1, 2).bool()
  5358. >>> a
  5359. tensor([[False, True]], dtype=torch.bool)
  5360. >>> torch.any(a)
  5361. tensor(True, dtype=torch.bool)
  5362. >>> a = torch.arange(0, 3)
  5363. >>> a
  5364. tensor([0, 1, 2])
  5365. >>> torch.any(a)
  5366. tensor(True)
  5367. .. function:: any(input, dim, keepdim=False, *, out=None) -> Tensor
  5368. :noindex:
  5369. For each row of :attr:`input` in the given dimension :attr:`dim`,
  5370. returns `True` if any element in the row evaluate to `True` and `False` otherwise.
  5371. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  5372. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  5373. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  5374. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  5375. Args:
  5376. input (Tensor): the input tensor.
  5377. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  5378. If ``None``, all dimensions are reduced.
  5379. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5380. Keyword args:
  5381. out (Tensor, optional): the output tensor.
  5382. Example::
  5383. >>> a = torch.randn(4, 2) < 0
  5384. >>> a
  5385. tensor([[ True, True],
  5386. [False, True],
  5387. [ True, True],
  5388. [False, False]])
  5389. >>> torch.any(a, 1)
  5390. tensor([ True, True, True, False])
  5391. >>> torch.any(a, 0)
  5392. tensor([True, True])
  5393. """
  5394. @overload
  5395. def any(
  5396. input: Tensor,
  5397. dim: _int,
  5398. keepdim: _bool = False,
  5399. *,
  5400. out: Tensor | None = None,
  5401. ) -> Tensor:
  5402. r"""
  5403. any(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5404. Tests if any element in :attr:`input` evaluates to `True`.
  5405. .. note:: This function matches the behaviour of NumPy in returning
  5406. output of dtype `bool` for all supported dtypes except `uint8`.
  5407. For `uint8` the dtype of output is `uint8` itself.
  5408. Args:
  5409. input (Tensor): the input tensor.
  5410. Keyword args:
  5411. out (Tensor, optional): the output tensor.
  5412. Example::
  5413. >>> a = torch.rand(1, 2).bool()
  5414. >>> a
  5415. tensor([[False, True]], dtype=torch.bool)
  5416. >>> torch.any(a)
  5417. tensor(True, dtype=torch.bool)
  5418. >>> a = torch.arange(0, 3)
  5419. >>> a
  5420. tensor([0, 1, 2])
  5421. >>> torch.any(a)
  5422. tensor(True)
  5423. .. function:: any(input, dim, keepdim=False, *, out=None) -> Tensor
  5424. :noindex:
  5425. For each row of :attr:`input` in the given dimension :attr:`dim`,
  5426. returns `True` if any element in the row evaluate to `True` and `False` otherwise.
  5427. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  5428. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  5429. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  5430. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  5431. Args:
  5432. input (Tensor): the input tensor.
  5433. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  5434. If ``None``, all dimensions are reduced.
  5435. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5436. Keyword args:
  5437. out (Tensor, optional): the output tensor.
  5438. Example::
  5439. >>> a = torch.randn(4, 2) < 0
  5440. >>> a
  5441. tensor([[ True, True],
  5442. [False, True],
  5443. [ True, True],
  5444. [False, False]])
  5445. >>> torch.any(a, 1)
  5446. tensor([ True, True, True, False])
  5447. >>> torch.any(a, 0)
  5448. tensor([True, True])
  5449. """
  5450. @overload
  5451. def any(
  5452. input: Tensor,
  5453. dim: str | EllipsisType | None,
  5454. keepdim: _bool = False,
  5455. *,
  5456. out: Tensor | None = None,
  5457. ) -> Tensor:
  5458. r"""
  5459. any(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5460. Tests if any element in :attr:`input` evaluates to `True`.
  5461. .. note:: This function matches the behaviour of NumPy in returning
  5462. output of dtype `bool` for all supported dtypes except `uint8`.
  5463. For `uint8` the dtype of output is `uint8` itself.
  5464. Args:
  5465. input (Tensor): the input tensor.
  5466. Keyword args:
  5467. out (Tensor, optional): the output tensor.
  5468. Example::
  5469. >>> a = torch.rand(1, 2).bool()
  5470. >>> a
  5471. tensor([[False, True]], dtype=torch.bool)
  5472. >>> torch.any(a)
  5473. tensor(True, dtype=torch.bool)
  5474. >>> a = torch.arange(0, 3)
  5475. >>> a
  5476. tensor([0, 1, 2])
  5477. >>> torch.any(a)
  5478. tensor(True)
  5479. .. function:: any(input, dim, keepdim=False, *, out=None) -> Tensor
  5480. :noindex:
  5481. For each row of :attr:`input` in the given dimension :attr:`dim`,
  5482. returns `True` if any element in the row evaluate to `True` and `False` otherwise.
  5483. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  5484. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  5485. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  5486. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  5487. Args:
  5488. input (Tensor): the input tensor.
  5489. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  5490. If ``None``, all dimensions are reduced.
  5491. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5492. Keyword args:
  5493. out (Tensor, optional): the output tensor.
  5494. Example::
  5495. >>> a = torch.randn(4, 2) < 0
  5496. >>> a
  5497. tensor([[ True, True],
  5498. [False, True],
  5499. [ True, True],
  5500. [False, False]])
  5501. >>> torch.any(a, 1)
  5502. tensor([ True, True, True, False])
  5503. >>> torch.any(a, 0)
  5504. tensor([True, True])
  5505. """
  5506. @overload
  5507. def arange(
  5508. start: Number,
  5509. end: Number,
  5510. step: Number,
  5511. *,
  5512. out: Tensor | None = None,
  5513. dtype: _dtype | None = None,
  5514. device: DeviceLikeType | None = None,
  5515. requires_grad: _bool = False,
  5516. pin_memory: _bool = False,
  5517. ) -> Tensor:
  5518. r"""
  5519. arange(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  5520. Returns a 1-D tensor of size :math:`\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil`
  5521. with values from the interval ``[start, end)`` taken with common difference
  5522. :attr:`step` beginning from `start`.
  5523. Note: When using floating-point dtypes (especially reduced precision types like ``bfloat16``),
  5524. the results may be affected by floating-point rounding behavior. Some values in the sequence
  5525. might not be exactly representable in certain floating-point formats, which can lead to
  5526. repeated values or unexpected rounding. For precise sequences, it is recommended to use
  5527. integer dtypes instead of floating-point dtypes.
  5528. Note that non-integer :attr:`step` is subject to floating point rounding errors when
  5529. comparing against :attr:`end`; to avoid inconsistency, we advise subtracting a small epsilon from :attr:`end`
  5530. in such cases.
  5531. .. math::
  5532. \text{out}_{{i+1}} = \text{out}_{i} + \text{step}
  5533. Args:
  5534. start (Number, optional): the starting value for the set of points. Default: ``0``.
  5535. end (Number): the ending value for the set of points
  5536. step (Number, optional): the gap between each pair of adjacent points. Default: ``1``.
  5537. Keyword args:
  5538. out (Tensor, optional): the output tensor.
  5539. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  5540. 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
  5541. arguments. If any of `start`, `end`, or `stop` are floating-point, the
  5542. `dtype` is inferred to be the default dtype, see
  5543. :meth:`~torch.get_default_dtype`. Otherwise, the `dtype` is inferred to
  5544. be `torch.int64`.
  5545. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  5546. Default: ``torch.strided``.
  5547. device (:class:`torch.device`, optional): the desired device of returned tensor.
  5548. Default: if ``None``, uses the current device for the default tensor type
  5549. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  5550. for CPU tensor types and the current CUDA device for CUDA tensor types.
  5551. requires_grad (bool, optional): If autograd should record operations on the
  5552. returned tensor. Default: ``False``.
  5553. Example::
  5554. >>> torch.arange(5)
  5555. tensor([ 0, 1, 2, 3, 4])
  5556. >>> torch.arange(1, 4)
  5557. tensor([ 1, 2, 3])
  5558. >>> torch.arange(1, 2.5, 0.5)
  5559. tensor([ 1.0000, 1.5000, 2.0000])
  5560. """
  5561. @overload
  5562. def arange(
  5563. start: Number,
  5564. end: Number,
  5565. *,
  5566. out: Tensor | None = None,
  5567. dtype: _dtype | None = None,
  5568. device: DeviceLikeType | None = None,
  5569. requires_grad: _bool = False,
  5570. pin_memory: _bool = False,
  5571. ) -> Tensor:
  5572. r"""
  5573. arange(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  5574. Returns a 1-D tensor of size :math:`\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil`
  5575. with values from the interval ``[start, end)`` taken with common difference
  5576. :attr:`step` beginning from `start`.
  5577. Note: When using floating-point dtypes (especially reduced precision types like ``bfloat16``),
  5578. the results may be affected by floating-point rounding behavior. Some values in the sequence
  5579. might not be exactly representable in certain floating-point formats, which can lead to
  5580. repeated values or unexpected rounding. For precise sequences, it is recommended to use
  5581. integer dtypes instead of floating-point dtypes.
  5582. Note that non-integer :attr:`step` is subject to floating point rounding errors when
  5583. comparing against :attr:`end`; to avoid inconsistency, we advise subtracting a small epsilon from :attr:`end`
  5584. in such cases.
  5585. .. math::
  5586. \text{out}_{{i+1}} = \text{out}_{i} + \text{step}
  5587. Args:
  5588. start (Number, optional): the starting value for the set of points. Default: ``0``.
  5589. end (Number): the ending value for the set of points
  5590. step (Number, optional): the gap between each pair of adjacent points. Default: ``1``.
  5591. Keyword args:
  5592. out (Tensor, optional): the output tensor.
  5593. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  5594. 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
  5595. arguments. If any of `start`, `end`, or `stop` are floating-point, the
  5596. `dtype` is inferred to be the default dtype, see
  5597. :meth:`~torch.get_default_dtype`. Otherwise, the `dtype` is inferred to
  5598. be `torch.int64`.
  5599. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  5600. Default: ``torch.strided``.
  5601. device (:class:`torch.device`, optional): the desired device of returned tensor.
  5602. Default: if ``None``, uses the current device for the default tensor type
  5603. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  5604. for CPU tensor types and the current CUDA device for CUDA tensor types.
  5605. requires_grad (bool, optional): If autograd should record operations on the
  5606. returned tensor. Default: ``False``.
  5607. Example::
  5608. >>> torch.arange(5)
  5609. tensor([ 0, 1, 2, 3, 4])
  5610. >>> torch.arange(1, 4)
  5611. tensor([ 1, 2, 3])
  5612. >>> torch.arange(1, 2.5, 0.5)
  5613. tensor([ 1.0000, 1.5000, 2.0000])
  5614. """
  5615. @overload
  5616. def arange(
  5617. end: Number,
  5618. *,
  5619. out: Tensor | None = None,
  5620. dtype: _dtype | None = None,
  5621. device: DeviceLikeType | None = None,
  5622. requires_grad: _bool = False,
  5623. pin_memory: _bool = False,
  5624. ) -> Tensor:
  5625. r"""
  5626. arange(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  5627. Returns a 1-D tensor of size :math:`\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil`
  5628. with values from the interval ``[start, end)`` taken with common difference
  5629. :attr:`step` beginning from `start`.
  5630. Note: When using floating-point dtypes (especially reduced precision types like ``bfloat16``),
  5631. the results may be affected by floating-point rounding behavior. Some values in the sequence
  5632. might not be exactly representable in certain floating-point formats, which can lead to
  5633. repeated values or unexpected rounding. For precise sequences, it is recommended to use
  5634. integer dtypes instead of floating-point dtypes.
  5635. Note that non-integer :attr:`step` is subject to floating point rounding errors when
  5636. comparing against :attr:`end`; to avoid inconsistency, we advise subtracting a small epsilon from :attr:`end`
  5637. in such cases.
  5638. .. math::
  5639. \text{out}_{{i+1}} = \text{out}_{i} + \text{step}
  5640. Args:
  5641. start (Number, optional): the starting value for the set of points. Default: ``0``.
  5642. end (Number): the ending value for the set of points
  5643. step (Number, optional): the gap between each pair of adjacent points. Default: ``1``.
  5644. Keyword args:
  5645. out (Tensor, optional): the output tensor.
  5646. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  5647. 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
  5648. arguments. If any of `start`, `end`, or `stop` are floating-point, the
  5649. `dtype` is inferred to be the default dtype, see
  5650. :meth:`~torch.get_default_dtype`. Otherwise, the `dtype` is inferred to
  5651. be `torch.int64`.
  5652. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  5653. Default: ``torch.strided``.
  5654. device (:class:`torch.device`, optional): the desired device of returned tensor.
  5655. Default: if ``None``, uses the current device for the default tensor type
  5656. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  5657. for CPU tensor types and the current CUDA device for CUDA tensor types.
  5658. requires_grad (bool, optional): If autograd should record operations on the
  5659. returned tensor. Default: ``False``.
  5660. Example::
  5661. >>> torch.arange(5)
  5662. tensor([ 0, 1, 2, 3, 4])
  5663. >>> torch.arange(1, 4)
  5664. tensor([ 1, 2, 3])
  5665. >>> torch.arange(1, 2.5, 0.5)
  5666. tensor([ 1.0000, 1.5000, 2.0000])
  5667. """
  5668. @overload
  5669. def arange(
  5670. end: Number | _complex,
  5671. *,
  5672. out: Tensor | None = None,
  5673. dtype: _dtype | None = None,
  5674. layout: _layout | None = None,
  5675. device: DeviceLikeType | None = None,
  5676. pin_memory: _bool | None = False,
  5677. requires_grad: _bool | None = False,
  5678. ) -> Tensor:
  5679. r"""
  5680. arange(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  5681. Returns a 1-D tensor of size :math:`\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil`
  5682. with values from the interval ``[start, end)`` taken with common difference
  5683. :attr:`step` beginning from `start`.
  5684. Note: When using floating-point dtypes (especially reduced precision types like ``bfloat16``),
  5685. the results may be affected by floating-point rounding behavior. Some values in the sequence
  5686. might not be exactly representable in certain floating-point formats, which can lead to
  5687. repeated values or unexpected rounding. For precise sequences, it is recommended to use
  5688. integer dtypes instead of floating-point dtypes.
  5689. Note that non-integer :attr:`step` is subject to floating point rounding errors when
  5690. comparing against :attr:`end`; to avoid inconsistency, we advise subtracting a small epsilon from :attr:`end`
  5691. in such cases.
  5692. .. math::
  5693. \text{out}_{{i+1}} = \text{out}_{i} + \text{step}
  5694. Args:
  5695. start (Number, optional): the starting value for the set of points. Default: ``0``.
  5696. end (Number): the ending value for the set of points
  5697. step (Number, optional): the gap between each pair of adjacent points. Default: ``1``.
  5698. Keyword args:
  5699. out (Tensor, optional): the output tensor.
  5700. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  5701. 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
  5702. arguments. If any of `start`, `end`, or `stop` are floating-point, the
  5703. `dtype` is inferred to be the default dtype, see
  5704. :meth:`~torch.get_default_dtype`. Otherwise, the `dtype` is inferred to
  5705. be `torch.int64`.
  5706. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  5707. Default: ``torch.strided``.
  5708. device (:class:`torch.device`, optional): the desired device of returned tensor.
  5709. Default: if ``None``, uses the current device for the default tensor type
  5710. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  5711. for CPU tensor types and the current CUDA device for CUDA tensor types.
  5712. requires_grad (bool, optional): If autograd should record operations on the
  5713. returned tensor. Default: ``False``.
  5714. Example::
  5715. >>> torch.arange(5)
  5716. tensor([ 0, 1, 2, 3, 4])
  5717. >>> torch.arange(1, 4)
  5718. tensor([ 1, 2, 3])
  5719. >>> torch.arange(1, 2.5, 0.5)
  5720. tensor([ 1.0000, 1.5000, 2.0000])
  5721. """
  5722. @overload
  5723. def arange(
  5724. start: Number | _complex,
  5725. end: Number | _complex,
  5726. *,
  5727. dtype: _dtype | None = None,
  5728. layout: _layout | None = None,
  5729. device: DeviceLikeType | None = None,
  5730. pin_memory: _bool | None = False,
  5731. requires_grad: _bool | None = False,
  5732. ) -> Tensor:
  5733. r"""
  5734. arange(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  5735. Returns a 1-D tensor of size :math:`\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil`
  5736. with values from the interval ``[start, end)`` taken with common difference
  5737. :attr:`step` beginning from `start`.
  5738. Note: When using floating-point dtypes (especially reduced precision types like ``bfloat16``),
  5739. the results may be affected by floating-point rounding behavior. Some values in the sequence
  5740. might not be exactly representable in certain floating-point formats, which can lead to
  5741. repeated values or unexpected rounding. For precise sequences, it is recommended to use
  5742. integer dtypes instead of floating-point dtypes.
  5743. Note that non-integer :attr:`step` is subject to floating point rounding errors when
  5744. comparing against :attr:`end`; to avoid inconsistency, we advise subtracting a small epsilon from :attr:`end`
  5745. in such cases.
  5746. .. math::
  5747. \text{out}_{{i+1}} = \text{out}_{i} + \text{step}
  5748. Args:
  5749. start (Number, optional): the starting value for the set of points. Default: ``0``.
  5750. end (Number): the ending value for the set of points
  5751. step (Number, optional): the gap between each pair of adjacent points. Default: ``1``.
  5752. Keyword args:
  5753. out (Tensor, optional): the output tensor.
  5754. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  5755. 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
  5756. arguments. If any of `start`, `end`, or `stop` are floating-point, the
  5757. `dtype` is inferred to be the default dtype, see
  5758. :meth:`~torch.get_default_dtype`. Otherwise, the `dtype` is inferred to
  5759. be `torch.int64`.
  5760. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  5761. Default: ``torch.strided``.
  5762. device (:class:`torch.device`, optional): the desired device of returned tensor.
  5763. Default: if ``None``, uses the current device for the default tensor type
  5764. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  5765. for CPU tensor types and the current CUDA device for CUDA tensor types.
  5766. requires_grad (bool, optional): If autograd should record operations on the
  5767. returned tensor. Default: ``False``.
  5768. Example::
  5769. >>> torch.arange(5)
  5770. tensor([ 0, 1, 2, 3, 4])
  5771. >>> torch.arange(1, 4)
  5772. tensor([ 1, 2, 3])
  5773. >>> torch.arange(1, 2.5, 0.5)
  5774. tensor([ 1.0000, 1.5000, 2.0000])
  5775. """
  5776. @overload
  5777. def arange(
  5778. start: Number | _complex,
  5779. end: Number | _complex,
  5780. step: Number | _complex = 1,
  5781. *,
  5782. out: Tensor | None = None,
  5783. dtype: _dtype | None = None,
  5784. layout: _layout | None = None,
  5785. device: DeviceLikeType | None = None,
  5786. pin_memory: _bool | None = False,
  5787. requires_grad: _bool | None = False,
  5788. ) -> Tensor:
  5789. r"""
  5790. arange(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  5791. Returns a 1-D tensor of size :math:`\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil`
  5792. with values from the interval ``[start, end)`` taken with common difference
  5793. :attr:`step` beginning from `start`.
  5794. Note: When using floating-point dtypes (especially reduced precision types like ``bfloat16``),
  5795. the results may be affected by floating-point rounding behavior. Some values in the sequence
  5796. might not be exactly representable in certain floating-point formats, which can lead to
  5797. repeated values or unexpected rounding. For precise sequences, it is recommended to use
  5798. integer dtypes instead of floating-point dtypes.
  5799. Note that non-integer :attr:`step` is subject to floating point rounding errors when
  5800. comparing against :attr:`end`; to avoid inconsistency, we advise subtracting a small epsilon from :attr:`end`
  5801. in such cases.
  5802. .. math::
  5803. \text{out}_{{i+1}} = \text{out}_{i} + \text{step}
  5804. Args:
  5805. start (Number, optional): the starting value for the set of points. Default: ``0``.
  5806. end (Number): the ending value for the set of points
  5807. step (Number, optional): the gap between each pair of adjacent points. Default: ``1``.
  5808. Keyword args:
  5809. out (Tensor, optional): the output tensor.
  5810. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  5811. 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
  5812. arguments. If any of `start`, `end`, or `stop` are floating-point, the
  5813. `dtype` is inferred to be the default dtype, see
  5814. :meth:`~torch.get_default_dtype`. Otherwise, the `dtype` is inferred to
  5815. be `torch.int64`.
  5816. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  5817. Default: ``torch.strided``.
  5818. device (:class:`torch.device`, optional): the desired device of returned tensor.
  5819. Default: if ``None``, uses the current device for the default tensor type
  5820. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  5821. for CPU tensor types and the current CUDA device for CUDA tensor types.
  5822. requires_grad (bool, optional): If autograd should record operations on the
  5823. returned tensor. Default: ``False``.
  5824. Example::
  5825. >>> torch.arange(5)
  5826. tensor([ 0, 1, 2, 3, 4])
  5827. >>> torch.arange(1, 4)
  5828. tensor([ 1, 2, 3])
  5829. >>> torch.arange(1, 2.5, 0.5)
  5830. tensor([ 1.0000, 1.5000, 2.0000])
  5831. """
  5832. def arccos(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  5833. r"""
  5834. arccos(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5835. Alias for :func:`torch.acos`.
  5836. """
  5837. def arccos_(input: Tensor) -> Tensor: ...
  5838. def arccosh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  5839. r"""
  5840. arccosh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5841. Alias for :func:`torch.acosh`.
  5842. """
  5843. def arccosh_(input: Tensor) -> Tensor: ...
  5844. def arcsin(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  5845. r"""
  5846. arcsin(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5847. Alias for :func:`torch.asin`.
  5848. """
  5849. def arcsin_(input: Tensor) -> Tensor: ...
  5850. def arcsinh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  5851. r"""
  5852. arcsinh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5853. Alias for :func:`torch.asinh`.
  5854. """
  5855. def arcsinh_(input: Tensor) -> Tensor: ...
  5856. def arctan(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  5857. r"""
  5858. arctan(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5859. Alias for :func:`torch.atan`.
  5860. """
  5861. def arctan2(
  5862. input: Tensor,
  5863. other: Tensor,
  5864. *,
  5865. out: Tensor | None = None,
  5866. ) -> Tensor:
  5867. r"""
  5868. arctan2(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
  5869. Alias for :func:`torch.atan2`.
  5870. """
  5871. def arctan_(input: Tensor) -> Tensor: ...
  5872. def arctanh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  5873. r"""
  5874. arctanh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  5875. Alias for :func:`torch.atanh`.
  5876. """
  5877. def arctanh_(input: Tensor) -> Tensor: ...
  5878. def argmax(
  5879. input: Tensor,
  5880. dim: _int | None = None,
  5881. keepdim: _bool = False,
  5882. *,
  5883. out: Tensor | None = None,
  5884. ) -> Tensor:
  5885. r"""
  5886. argmax(input) -> LongTensor
  5887. Returns the indices of the maximum value of all elements in the :attr:`input` tensor.
  5888. This is the second value returned by :meth:`torch.max`. See its
  5889. documentation for the exact semantics of this method.
  5890. .. note:: If there are multiple maximal values then the indices of the first maximal value are returned.
  5891. Args:
  5892. input (Tensor): the input tensor.
  5893. Example::
  5894. >>> a = torch.randn(4, 4)
  5895. >>> a
  5896. tensor([[ 1.3398, 0.2663, -0.2686, 0.2450],
  5897. [-0.7401, -0.8805, -0.3402, -1.1936],
  5898. [ 0.4907, -1.3948, -1.0691, -0.3132],
  5899. [-1.6092, 0.5419, -0.2993, 0.3195]])
  5900. >>> torch.argmax(a)
  5901. tensor(0)
  5902. .. function:: argmax(input, dim, keepdim=False) -> LongTensor
  5903. :noindex:
  5904. Returns the indices of the maximum values of a tensor across a dimension.
  5905. This is the second value returned by :meth:`torch.max`. See its
  5906. documentation for the exact semantics of this method.
  5907. Args:
  5908. input (Tensor): the input tensor.
  5909. dim (int, optional): the dimension to reduce.
  5910. If ``None``, the argmax of the flattened input is returned.
  5911. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5912. Example::
  5913. >>> a = torch.randn(4, 4)
  5914. >>> a
  5915. tensor([[ 1.3398, 0.2663, -0.2686, 0.2450],
  5916. [-0.7401, -0.8805, -0.3402, -1.1936],
  5917. [ 0.4907, -1.3948, -1.0691, -0.3132],
  5918. [-1.6092, 0.5419, -0.2993, 0.3195]])
  5919. >>> torch.argmax(a, dim=1)
  5920. tensor([ 0, 2, 0, 1])
  5921. """
  5922. def argmin(
  5923. input: Tensor,
  5924. dim: _int | None = None,
  5925. keepdim: _bool = False,
  5926. *,
  5927. out: Tensor | None = None,
  5928. ) -> Tensor:
  5929. r"""
  5930. argmin(input, dim=None, keepdim=False) -> LongTensor
  5931. Returns the indices of the minimum value(s) of the flattened tensor or along a dimension
  5932. This is the second value returned by :meth:`torch.min`. See its
  5933. documentation for the exact semantics of this method.
  5934. .. note:: If there are multiple minimal values then the indices of the first minimal value are returned.
  5935. Args:
  5936. input (Tensor): the input tensor.
  5937. dim (int, optional): the dimension to reduce.
  5938. If ``None``, the argmin of the flattened input is returned.
  5939. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  5940. Example::
  5941. >>> a = torch.randn(4, 4)
  5942. >>> a
  5943. tensor([[ 0.1139, 0.2254, -0.1381, 0.3687],
  5944. [ 1.0100, -1.1975, -0.0102, -0.4732],
  5945. [-0.9240, 0.1207, -0.7506, -1.0213],
  5946. [ 1.7809, -1.2960, 0.9384, 0.1438]])
  5947. >>> torch.argmin(a)
  5948. tensor(13)
  5949. >>> torch.argmin(a, dim=1)
  5950. tensor([ 2, 1, 3, 1])
  5951. >>> torch.argmin(a, dim=1, keepdim=True)
  5952. tensor([[2],
  5953. [1],
  5954. [3],
  5955. [1]])
  5956. """
  5957. @overload
  5958. def argsort(
  5959. input: Tensor,
  5960. *,
  5961. stable: _bool,
  5962. dim: _int = -1,
  5963. descending: _bool = False,
  5964. out: Tensor | None = None,
  5965. ) -> Tensor:
  5966. r"""
  5967. argsort(input, dim=-1, descending=False, *, stable=False) -> Tensor
  5968. Returns the indices that sort a tensor along a given dimension in ascending
  5969. order by value.
  5970. This is the second value returned by :meth:`torch.sort`. See its documentation
  5971. for the exact semantics of this method.
  5972. If :attr:`stable` is ``True`` then the sorting routine becomes stable, preserving
  5973. the order of equivalent elements. If ``False``, the relative order of values
  5974. which compare equal is not guaranteed. ``True`` is slower.
  5975. Args:
  5976. input (Tensor): the input tensor.
  5977. dim (int, optional): the dimension to sort along
  5978. descending (bool, optional): controls the sorting order (ascending or descending)
  5979. Keyword args:
  5980. stable (bool, optional): controls the relative order of equivalent elements
  5981. Example::
  5982. >>> a = torch.randn(4, 4)
  5983. >>> a
  5984. tensor([[ 0.0785, 1.5267, -0.8521, 0.4065],
  5985. [ 0.1598, 0.0788, -0.0745, -1.2700],
  5986. [ 1.2208, 1.0722, -0.7064, 1.2564],
  5987. [ 0.0669, -0.2318, -0.8229, -0.9280]])
  5988. >>> torch.argsort(a, dim=1)
  5989. tensor([[2, 0, 3, 1],
  5990. [3, 2, 1, 0],
  5991. [2, 1, 0, 3],
  5992. [3, 2, 1, 0]])
  5993. """
  5994. @overload
  5995. def argsort(
  5996. input: Tensor,
  5997. dim: _int = -1,
  5998. descending: _bool = False,
  5999. ) -> Tensor:
  6000. r"""
  6001. argsort(input, dim=-1, descending=False, *, stable=False) -> Tensor
  6002. Returns the indices that sort a tensor along a given dimension in ascending
  6003. order by value.
  6004. This is the second value returned by :meth:`torch.sort`. See its documentation
  6005. for the exact semantics of this method.
  6006. If :attr:`stable` is ``True`` then the sorting routine becomes stable, preserving
  6007. the order of equivalent elements. If ``False``, the relative order of values
  6008. which compare equal is not guaranteed. ``True`` is slower.
  6009. Args:
  6010. input (Tensor): the input tensor.
  6011. dim (int, optional): the dimension to sort along
  6012. descending (bool, optional): controls the sorting order (ascending or descending)
  6013. Keyword args:
  6014. stable (bool, optional): controls the relative order of equivalent elements
  6015. Example::
  6016. >>> a = torch.randn(4, 4)
  6017. >>> a
  6018. tensor([[ 0.0785, 1.5267, -0.8521, 0.4065],
  6019. [ 0.1598, 0.0788, -0.0745, -1.2700],
  6020. [ 1.2208, 1.0722, -0.7064, 1.2564],
  6021. [ 0.0669, -0.2318, -0.8229, -0.9280]])
  6022. >>> torch.argsort(a, dim=1)
  6023. tensor([[2, 0, 3, 1],
  6024. [3, 2, 1, 0],
  6025. [2, 1, 0, 3],
  6026. [3, 2, 1, 0]])
  6027. """
  6028. @overload
  6029. def argsort(
  6030. input: Tensor,
  6031. dim: str | EllipsisType | None,
  6032. descending: _bool = False,
  6033. ) -> Tensor:
  6034. r"""
  6035. argsort(input, dim=-1, descending=False, *, stable=False) -> Tensor
  6036. Returns the indices that sort a tensor along a given dimension in ascending
  6037. order by value.
  6038. This is the second value returned by :meth:`torch.sort`. See its documentation
  6039. for the exact semantics of this method.
  6040. If :attr:`stable` is ``True`` then the sorting routine becomes stable, preserving
  6041. the order of equivalent elements. If ``False``, the relative order of values
  6042. which compare equal is not guaranteed. ``True`` is slower.
  6043. Args:
  6044. input (Tensor): the input tensor.
  6045. dim (int, optional): the dimension to sort along
  6046. descending (bool, optional): controls the sorting order (ascending or descending)
  6047. Keyword args:
  6048. stable (bool, optional): controls the relative order of equivalent elements
  6049. Example::
  6050. >>> a = torch.randn(4, 4)
  6051. >>> a
  6052. tensor([[ 0.0785, 1.5267, -0.8521, 0.4065],
  6053. [ 0.1598, 0.0788, -0.0745, -1.2700],
  6054. [ 1.2208, 1.0722, -0.7064, 1.2564],
  6055. [ 0.0669, -0.2318, -0.8229, -0.9280]])
  6056. >>> torch.argsort(a, dim=1)
  6057. tensor([[2, 0, 3, 1],
  6058. [3, 2, 1, 0],
  6059. [2, 1, 0, 3],
  6060. [3, 2, 1, 0]])
  6061. """
  6062. def argwhere(input: Tensor) -> Tensor:
  6063. r"""
  6064. argwhere(input) -> Tensor
  6065. Returns a tensor containing the indices of all non-zero elements of
  6066. :attr:`input`. Each row in the result contains the indices of a non-zero
  6067. element in :attr:`input`. The result is sorted lexicographically, with
  6068. the last index changing the fastest (C-style).
  6069. If :attr:`input` has :math:`n` dimensions, then the resulting indices tensor
  6070. :attr:`out` is of size :math:`(z \times n)`, where :math:`z` is the total number of
  6071. non-zero elements in the :attr:`input` tensor.
  6072. .. note::
  6073. This function is similar to NumPy's `argwhere`.
  6074. When :attr:`input` is on CUDA, this function causes host-device synchronization.
  6075. Args:
  6076. {input}
  6077. Example::
  6078. >>> t = torch.tensor([1, 0, 1])
  6079. >>> torch.argwhere(t)
  6080. tensor([[0],
  6081. [2]])
  6082. >>> t = torch.tensor([[1, 0, 1], [0, 1, 1]])
  6083. >>> torch.argwhere(t)
  6084. tensor([[0, 0],
  6085. [0, 2],
  6086. [1, 1],
  6087. [1, 2]])
  6088. """
  6089. def as_strided(
  6090. input: Tensor,
  6091. size: Sequence[_int | SymInt],
  6092. stride: Sequence[_int | SymInt],
  6093. storage_offset: _int | SymInt | None = None,
  6094. ) -> Tensor:
  6095. r"""
  6096. as_strided(input, size, stride, storage_offset=None) -> Tensor
  6097. Create a view of an existing `torch.Tensor` :attr:`input` with specified
  6098. :attr:`size`, :attr:`stride` and :attr:`storage_offset`.
  6099. .. warning::
  6100. Prefer using other view functions, like :meth:`torch.Tensor.view` or
  6101. :meth:`torch.Tensor.expand`, to setting a view's strides manually with
  6102. `as_strided`, as this function will throw an error on non-standard Pytorch
  6103. backends (that do not have a concept of stride) and the result will depend
  6104. on the current layout in memory. The constructed view must only refer to
  6105. elements within the Tensor's storage or a runtime error will be thrown.
  6106. If the generated view is "overlapped" (with multiple indices referring to
  6107. the same element in memory), the behavior of inplace operations on this view
  6108. is undefined (and might not throw runtime errors).
  6109. Args:
  6110. input (Tensor): the input tensor.
  6111. size (tuple or ints): the shape of the output tensor
  6112. stride (tuple or ints): the stride of the output tensor
  6113. storage_offset (int, optional): the offset in the underlying storage of the output tensor.
  6114. If ``None``, the storage_offset of the output tensor will match the input tensor.
  6115. Example::
  6116. >>> x = torch.randn(3, 3)
  6117. >>> x
  6118. tensor([[ 0.9039, 0.6291, 1.0795],
  6119. [ 0.1586, 2.1939, -0.4900],
  6120. [-0.1909, -0.7503, 1.9355]])
  6121. >>> t = torch.as_strided(x, (2, 2), (1, 2))
  6122. >>> t
  6123. tensor([[0.9039, 1.0795],
  6124. [0.6291, 0.1586]])
  6125. >>> t = torch.as_strided(x, (2, 2), (1, 2), 1)
  6126. tensor([[0.6291, 0.1586],
  6127. [1.0795, 2.1939]])
  6128. """
  6129. def as_strided_(
  6130. input: Tensor,
  6131. size: Sequence[_int | SymInt],
  6132. stride: Sequence[_int | SymInt],
  6133. storage_offset: _int | SymInt | None = None,
  6134. ) -> Tensor: ...
  6135. def as_strided_copy(
  6136. input: Tensor,
  6137. size: Sequence[_int | SymInt],
  6138. stride: Sequence[_int | SymInt],
  6139. storage_offset: _int | SymInt | None = None,
  6140. *,
  6141. out: Tensor | None = None,
  6142. ) -> Tensor:
  6143. r"""
  6144. Performs the same operation as :func:`torch.as_strided`, but all output tensors
  6145. are freshly created instead of aliasing the input.
  6146. """
  6147. def as_strided_scatter(
  6148. input: Tensor,
  6149. src: Tensor,
  6150. size: Sequence[_int | SymInt],
  6151. stride: Sequence[_int | SymInt],
  6152. storage_offset: _int | SymInt | None = None,
  6153. ) -> Tensor:
  6154. r"""
  6155. as_strided_scatter(input, src, size, stride, storage_offset=None) -> Tensor
  6156. Embeds the values of the :attr:`src` tensor into :attr:`input` along
  6157. the elements corresponding to the result of calling
  6158. input.as_strided(size, stride, storage_offset).
  6159. This function returns a tensor with fresh storage; it does not
  6160. return a view.
  6161. Args:
  6162. input (Tensor): the input tensor.
  6163. size (tuple or ints): the shape of the output tensor
  6164. stride (tuple or ints): the stride of the output tensor
  6165. storage_offset (int, optional): the offset in the underlying storage of the output tensor
  6166. .. note::
  6167. :attr:`src` must be of the proper size in order to be embedded
  6168. into :attr:`input`. Specifically, it should have the same shape as
  6169. `torch.as_strided(input, size, stride, storage_offset)`
  6170. Example::
  6171. >>> a = torch.arange(4).reshape(2, 2) + 1
  6172. >>> a
  6173. tensor([[1, 2],
  6174. [3, 4]])
  6175. >>> b = torch.zeros(3, 3)
  6176. >>> b
  6177. tensor([[0., 0., 0.],
  6178. [0., 0., 0.],
  6179. [0., 0., 0.]])
  6180. >>> torch.as_strided_scatter(b, a, (2, 2), (1, 2))
  6181. tensor([[1., 3., 2.],
  6182. [4., 0., 0.],
  6183. [0., 0., 0.]])
  6184. """
  6185. def as_tensor(
  6186. data: Any,
  6187. dtype: _dtype | None = None,
  6188. device: DeviceLikeType | None = None,
  6189. ) -> Tensor:
  6190. r"""
  6191. as_tensor(data: Any, dtype: Optional[dtype] = None, device: Optional[DeviceLikeType]) -> Tensor
  6192. Converts :attr:`data` into a tensor, sharing data and preserving autograd
  6193. history if possible.
  6194. If :attr:`data` is already a tensor with the requested dtype and device
  6195. then :attr:`data` itself is returned, but if :attr:`data` is a
  6196. tensor with a different dtype or device then it's copied as if using
  6197. `data.to(dtype=dtype, device=device)`.
  6198. If :attr:`data` is a NumPy array (an ndarray) with the same dtype and device then a
  6199. tensor is constructed using :func:`torch.from_numpy`.
  6200. If :attr:`data` is a CuPy array, the returned tensor will be located on the same device as the CuPy array unless
  6201. specifically overwritten by :attr:`device` or a default device. The device of the CuPy array is inferred from the
  6202. pointer of the array using `cudaPointerGetAttributes` unless :attr:`device` is provided with an explicit device index.
  6203. .. seealso::
  6204. :func:`torch.tensor` never shares its data and creates a new "leaf tensor" (see :doc:`/notes/autograd`).
  6205. Args:
  6206. data (array_like): Initial data for the tensor. Can be a list, tuple,
  6207. NumPy ``ndarray``, scalar, and other types.
  6208. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  6209. Default: if ``None``, infers data type from :attr:`data`.
  6210. device (:class:`torch.device`, optional): the device of the constructed tensor. If None and data is a tensor
  6211. then the device of data is used. If None and data is not a tensor then
  6212. the result tensor is constructed on the current device.
  6213. Example::
  6214. >>> a = numpy.array([1, 2, 3])
  6215. >>> t = torch.as_tensor(a)
  6216. >>> t
  6217. tensor([ 1, 2, 3])
  6218. >>> t[0] = -1
  6219. >>> a
  6220. array([-1, 2, 3])
  6221. >>> a = numpy.array([1, 2, 3])
  6222. >>> t = torch.as_tensor(a, device=torch.device('cuda'))
  6223. >>> t
  6224. tensor([ 1, 2, 3])
  6225. >>> t[0] = -1
  6226. >>> a
  6227. array([1, 2, 3])
  6228. """
  6229. def asarray(
  6230. obj: Any,
  6231. *,
  6232. dtype: _dtype | None = None,
  6233. device: DeviceLikeType | None = None,
  6234. copy: _bool | None = None,
  6235. requires_grad: _bool = False,
  6236. ) -> Tensor:
  6237. r"""
  6238. asarray(obj: Any, *, dtype: Optional[dtype], device: Optional[DeviceLikeType], copy: Optional[bool] = None, requires_grad: bool = False) -> Tensor # noqa: B950
  6239. Converts :attr:`obj` to a tensor.
  6240. :attr:`obj` can be one of:
  6241. 1. a tensor
  6242. 2. a NumPy array or a NumPy scalar
  6243. 3. a DLPack capsule
  6244. 4. an object that implements Python's buffer protocol
  6245. 5. a scalar
  6246. 6. a sequence of scalars
  6247. When :attr:`obj` is a tensor, NumPy array, or DLPack capsule the returned tensor will,
  6248. by default, not require a gradient, have the same datatype as :attr:`obj`, be on the
  6249. same device, and share memory with it. These properties can be controlled with the
  6250. :attr:`dtype`, :attr:`device`, :attr:`copy`, and :attr:`requires_grad` keyword arguments.
  6251. If the returned tensor is of a different datatype, on a different device, or a copy is
  6252. requested then it will not share its memory with :attr:`obj`. If :attr:`requires_grad`
  6253. is ``True`` then the returned tensor will require a gradient, and if :attr:`obj` is
  6254. also a tensor with an autograd history then the returned tensor will have the same history.
  6255. When :attr:`obj` is not a tensor, NumPy array, or DLPack capsule but implements Python's
  6256. buffer protocol then the buffer is interpreted as an array of bytes grouped according to
  6257. the size of the datatype passed to the :attr:`dtype` keyword argument. (If no datatype is
  6258. passed then the default floating point datatype is used, instead.) The returned tensor
  6259. will have the specified datatype (or default floating point datatype if none is specified)
  6260. and, by default, be on the CPU device and share memory with the buffer.
  6261. When :attr:`obj` is a NumPy scalar, the returned tensor will be a 0-dimensional tensor on
  6262. the CPU and that doesn't share its memory (i.e. ``copy=True``). By default datatype will
  6263. be the PyTorch datatype corresponding to the NumPy's scalar's datatype.
  6264. When :attr:`obj` is none of the above but a scalar, or a sequence of scalars then the
  6265. returned tensor will, by default, infer its datatype from the scalar values, be on the
  6266. current default device, and not share its memory.
  6267. .. seealso::
  6268. :func:`torch.tensor` creates a tensor that always copies the data from the input object.
  6269. :func:`torch.from_numpy` creates a tensor that always shares memory from NumPy arrays.
  6270. :func:`torch.frombuffer` creates a tensor that always shares memory from objects that
  6271. implement the buffer protocol.
  6272. :func:`torch.from_dlpack` creates a tensor that always shares memory from
  6273. DLPack capsules.
  6274. Args:
  6275. obj (object): a tensor, NumPy array, DLPack Capsule, object that implements Python's
  6276. buffer protocol, scalar, or sequence of scalars.
  6277. Keyword args:
  6278. dtype (:class:`torch.dtype`, optional): the datatype of the returned tensor.
  6279. Default: ``None``, which causes the datatype of the returned tensor to be
  6280. inferred from :attr:`obj`.
  6281. copy (bool, optional): controls whether the returned tensor shares memory with :attr:`obj`.
  6282. Default: ``None``, which causes the returned tensor to share memory with :attr:`obj`
  6283. whenever possible. If ``True`` then the returned tensor does not share its memory.
  6284. If ``False`` then the returned tensor shares its memory with :attr:`obj` and an
  6285. error is thrown if it cannot.
  6286. device (:class:`torch.device`, optional): the device of the returned tensor.
  6287. Default: ``None``, which causes the device of :attr:`obj` to be used. Or, if
  6288. :attr:`obj` is a Python sequence, the current default device will be used.
  6289. requires_grad (bool, optional): whether the returned tensor requires grad.
  6290. Default: ``False``, which causes the returned tensor not to require a gradient.
  6291. If ``True``, then the returned tensor will require a gradient, and if :attr:`obj`
  6292. is also a tensor with an autograd history then the returned tensor will have
  6293. the same history.
  6294. Example::
  6295. >>> a = torch.tensor([1, 2, 3])
  6296. >>> # Shares memory with tensor 'a'
  6297. >>> b = torch.asarray(a)
  6298. >>> a.data_ptr() == b.data_ptr()
  6299. True
  6300. >>> # Forces memory copy
  6301. >>> c = torch.asarray(a, copy=True)
  6302. >>> a.data_ptr() == c.data_ptr()
  6303. False
  6304. >>> a = torch.tensor([1., 2., 3.], requires_grad=True)
  6305. >>> b = a + 2
  6306. >>> b
  6307. tensor([3., 4., 5.], grad_fn=<AddBackward0>)
  6308. >>> # Shares memory with tensor 'b', with no grad
  6309. >>> c = torch.asarray(b)
  6310. >>> c
  6311. tensor([3., 4., 5.])
  6312. >>> # Shares memory with tensor 'b', retaining autograd history
  6313. >>> d = torch.asarray(b, requires_grad=True)
  6314. >>> d
  6315. tensor([3., 4., 5.], grad_fn=<AddBackward0>)
  6316. >>> array = numpy.array([1, 2, 3])
  6317. >>> # Shares memory with array 'array'
  6318. >>> t1 = torch.asarray(array)
  6319. >>> array.__array_interface__['data'][0] == t1.data_ptr()
  6320. True
  6321. >>> # Copies memory due to dtype mismatch
  6322. >>> t2 = torch.asarray(array, dtype=torch.float32)
  6323. >>> array.__array_interface__['data'][0] == t2.data_ptr()
  6324. False
  6325. >>> scalar = numpy.float64(0.5)
  6326. >>> torch.asarray(scalar)
  6327. tensor(0.5000, dtype=torch.float64)
  6328. """
  6329. def asin(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  6330. r"""
  6331. asin(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  6332. Returns a new tensor with the arcsine of the elements (in radians) in the :attr:`input` tensor.
  6333. .. math::
  6334. \text{out}_{i} = \sin^{-1}(\text{input}_{i})
  6335. Args:
  6336. input (Tensor): the input tensor.
  6337. Keyword args:
  6338. out (Tensor, optional): the output tensor.
  6339. Example::
  6340. >>> a = torch.randn(4)
  6341. >>> a
  6342. tensor([-0.5962, 1.4985, -0.4396, 1.4525])
  6343. >>> torch.asin(a)
  6344. tensor([-0.6387, nan, -0.4552, nan])
  6345. """
  6346. def asin_(input: Tensor) -> Tensor: ...
  6347. def asinh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  6348. r"""
  6349. asinh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  6350. Returns a new tensor with the inverse hyperbolic sine of the elements of :attr:`input`.
  6351. .. math::
  6352. \text{out}_{i} = \sinh^{-1}(\text{input}_{i})
  6353. Args:
  6354. input (Tensor): the input tensor.
  6355. Keyword arguments:
  6356. out (Tensor, optional): the output tensor.
  6357. Example::
  6358. >>> a = torch.randn(4)
  6359. >>> a
  6360. tensor([ 0.1606, -1.4267, -1.0899, -1.0250 ])
  6361. >>> torch.asinh(a)
  6362. tensor([ 0.1599, -1.1534, -0.9435, -0.8990 ])
  6363. """
  6364. def asinh_(input: Tensor) -> Tensor: ...
  6365. def atan(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  6366. r"""
  6367. atan(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  6368. Returns a new tensor with the arctangent of the elements (in radians) in the :attr:`input` tensor.
  6369. .. math::
  6370. \text{out}_{i} = \tan^{-1}(\text{input}_{i})
  6371. Args:
  6372. input (Tensor): the input tensor.
  6373. Keyword args:
  6374. out (Tensor, optional): the output tensor.
  6375. Example::
  6376. >>> a = torch.randn(4)
  6377. >>> a
  6378. tensor([ 0.2341, 0.2539, -0.6256, -0.6448])
  6379. >>> torch.atan(a)
  6380. tensor([ 0.2299, 0.2487, -0.5591, -0.5727])
  6381. """
  6382. def atan2(
  6383. input: Tensor,
  6384. other: Tensor,
  6385. *,
  6386. out: Tensor | None = None,
  6387. ) -> Tensor:
  6388. r"""
  6389. atan2(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
  6390. Element-wise arctangent of :math:`\text{input}_{i} / \text{other}_{i}`
  6391. with consideration of the quadrant. Returns a new tensor with the signed angles
  6392. in radians between vector :math:`(\text{other}_{i}, \text{input}_{i})`
  6393. and vector :math:`(1, 0)`. (Note that :math:`\text{other}_{i}`, the second
  6394. parameter, is the x-coordinate, while :math:`\text{input}_{i}`, the first
  6395. parameter, is the y-coordinate.)
  6396. The shapes of ``input`` and ``other`` must be
  6397. :ref:`broadcastable <broadcasting-semantics>`.
  6398. Args:
  6399. input (Tensor): the first input tensor
  6400. other (Tensor): the second input tensor
  6401. Keyword args:
  6402. out (Tensor, optional): the output tensor.
  6403. Example::
  6404. >>> a = torch.randn(4)
  6405. >>> a
  6406. tensor([ 0.9041, 0.0196, -0.3108, -2.4423])
  6407. >>> torch.atan2(a, torch.randn(4))
  6408. tensor([ 0.9833, 0.0811, -1.9743, -1.4151])
  6409. """
  6410. def atan_(input: Tensor) -> Tensor: ...
  6411. def atanh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  6412. r"""
  6413. atanh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  6414. Returns a new tensor with the inverse hyperbolic tangent of the elements of :attr:`input`.
  6415. Note:
  6416. The domain of the inverse hyperbolic tangent is `(-1, 1)` and values outside this range
  6417. will be mapped to ``NaN``, except for the values `1` and `-1` for which the output is
  6418. mapped to `+/-INF` respectively.
  6419. .. math::
  6420. \text{out}_{i} = \tanh^{-1}(\text{input}_{i})
  6421. Args:
  6422. input (Tensor): the input tensor.
  6423. Keyword arguments:
  6424. out (Tensor, optional): the output tensor.
  6425. Example::
  6426. >>> a = torch.randn(4).uniform_(-1, 1)
  6427. >>> a
  6428. tensor([ -0.9385, 0.2968, -0.8591, -0.1871 ])
  6429. >>> torch.atanh(a)
  6430. tensor([ -1.7253, 0.3060, -1.2899, -0.1893 ])
  6431. """
  6432. def atanh_(input: Tensor) -> Tensor: ...
  6433. def avg_pool1d(
  6434. input: Tensor,
  6435. kernel_size: _int | _size,
  6436. stride: _int | _size = (),
  6437. padding: _int | _size = 0,
  6438. ceil_mode: _bool = False,
  6439. count_include_pad: _bool = True,
  6440. ) -> Tensor: ...
  6441. @overload
  6442. def baddbmm(
  6443. beta: Number | _complex,
  6444. self: Tensor,
  6445. alpha: Number | _complex,
  6446. batch1: Tensor,
  6447. batch2: Tensor,
  6448. ) -> Tensor:
  6449. r"""
  6450. baddbmm(input, batch1, batch2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  6451. Performs a batch matrix-matrix product of matrices in :attr:`batch1`
  6452. and :attr:`batch2`.
  6453. :attr:`input` is added to the final result.
  6454. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the same
  6455. number of matrices.
  6456. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  6457. :math:`(b \times m \times p)` tensor, then :attr:`input` must be
  6458. :ref:`broadcastable <broadcasting-semantics>` with a
  6459. :math:`(b \times n \times p)` tensor and :attr:`out` will be a
  6460. :math:`(b \times n \times p)` tensor. Both :attr:`alpha` and :attr:`beta` mean the
  6461. same as the scaling factors used in :meth:`torch.addbmm`.
  6462. .. math::
  6463. \text{out}_i = \beta\ \text{input}_i + \alpha\ (\text{batch1}_i \mathbin{@} \text{batch2}_i)
  6464. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  6465. it will not be propagated.
  6466. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  6467. :attr:`alpha` must be real numbers, otherwise they should be integers.
  6468. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  6469. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  6470. Args:
  6471. input (Tensor): the tensor to be added
  6472. batch1 (Tensor): the first batch of matrices to be multiplied
  6473. batch2 (Tensor): the second batch of matrices to be multiplied
  6474. out_dtype (dtype, optional): the dtype of the output tensor,
  6475. Supported only on CUDA and for torch.float32 given
  6476. torch.float16/torch.bfloat16 input dtypes
  6477. Keyword args:
  6478. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  6479. alpha (Number, optional): multiplier for :math:`\text{batch1} \mathbin{@} \text{batch2}` (:math:`\alpha`)
  6480. out (Tensor, optional): the output tensor.
  6481. Example::
  6482. >>> M = torch.randn(10, 3, 5)
  6483. >>> batch1 = torch.randn(10, 3, 4)
  6484. >>> batch2 = torch.randn(10, 4, 5)
  6485. >>> torch.baddbmm(M, batch1, batch2).size()
  6486. torch.Size([10, 3, 5])
  6487. """
  6488. @overload
  6489. def baddbmm(
  6490. beta: Number | _complex,
  6491. self: Tensor,
  6492. alpha: Number | _complex,
  6493. batch1: Tensor,
  6494. batch2: Tensor,
  6495. *,
  6496. out: Tensor,
  6497. ) -> Tensor:
  6498. r"""
  6499. baddbmm(input, batch1, batch2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  6500. Performs a batch matrix-matrix product of matrices in :attr:`batch1`
  6501. and :attr:`batch2`.
  6502. :attr:`input` is added to the final result.
  6503. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the same
  6504. number of matrices.
  6505. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  6506. :math:`(b \times m \times p)` tensor, then :attr:`input` must be
  6507. :ref:`broadcastable <broadcasting-semantics>` with a
  6508. :math:`(b \times n \times p)` tensor and :attr:`out` will be a
  6509. :math:`(b \times n \times p)` tensor. Both :attr:`alpha` and :attr:`beta` mean the
  6510. same as the scaling factors used in :meth:`torch.addbmm`.
  6511. .. math::
  6512. \text{out}_i = \beta\ \text{input}_i + \alpha\ (\text{batch1}_i \mathbin{@} \text{batch2}_i)
  6513. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  6514. it will not be propagated.
  6515. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  6516. :attr:`alpha` must be real numbers, otherwise they should be integers.
  6517. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  6518. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  6519. Args:
  6520. input (Tensor): the tensor to be added
  6521. batch1 (Tensor): the first batch of matrices to be multiplied
  6522. batch2 (Tensor): the second batch of matrices to be multiplied
  6523. out_dtype (dtype, optional): the dtype of the output tensor,
  6524. Supported only on CUDA and for torch.float32 given
  6525. torch.float16/torch.bfloat16 input dtypes
  6526. Keyword args:
  6527. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  6528. alpha (Number, optional): multiplier for :math:`\text{batch1} \mathbin{@} \text{batch2}` (:math:`\alpha`)
  6529. out (Tensor, optional): the output tensor.
  6530. Example::
  6531. >>> M = torch.randn(10, 3, 5)
  6532. >>> batch1 = torch.randn(10, 3, 4)
  6533. >>> batch2 = torch.randn(10, 4, 5)
  6534. >>> torch.baddbmm(M, batch1, batch2).size()
  6535. torch.Size([10, 3, 5])
  6536. """
  6537. @overload
  6538. def baddbmm(
  6539. input: Tensor,
  6540. batch1: Tensor,
  6541. batch2: Tensor,
  6542. *,
  6543. beta: Number | _complex = 1,
  6544. alpha: Number | _complex = 1,
  6545. out: Tensor | None = None,
  6546. ) -> Tensor:
  6547. r"""
  6548. baddbmm(input, batch1, batch2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  6549. Performs a batch matrix-matrix product of matrices in :attr:`batch1`
  6550. and :attr:`batch2`.
  6551. :attr:`input` is added to the final result.
  6552. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the same
  6553. number of matrices.
  6554. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  6555. :math:`(b \times m \times p)` tensor, then :attr:`input` must be
  6556. :ref:`broadcastable <broadcasting-semantics>` with a
  6557. :math:`(b \times n \times p)` tensor and :attr:`out` will be a
  6558. :math:`(b \times n \times p)` tensor. Both :attr:`alpha` and :attr:`beta` mean the
  6559. same as the scaling factors used in :meth:`torch.addbmm`.
  6560. .. math::
  6561. \text{out}_i = \beta\ \text{input}_i + \alpha\ (\text{batch1}_i \mathbin{@} \text{batch2}_i)
  6562. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  6563. it will not be propagated.
  6564. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  6565. :attr:`alpha` must be real numbers, otherwise they should be integers.
  6566. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  6567. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  6568. Args:
  6569. input (Tensor): the tensor to be added
  6570. batch1 (Tensor): the first batch of matrices to be multiplied
  6571. batch2 (Tensor): the second batch of matrices to be multiplied
  6572. out_dtype (dtype, optional): the dtype of the output tensor,
  6573. Supported only on CUDA and for torch.float32 given
  6574. torch.float16/torch.bfloat16 input dtypes
  6575. Keyword args:
  6576. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  6577. alpha (Number, optional): multiplier for :math:`\text{batch1} \mathbin{@} \text{batch2}` (:math:`\alpha`)
  6578. out (Tensor, optional): the output tensor.
  6579. Example::
  6580. >>> M = torch.randn(10, 3, 5)
  6581. >>> batch1 = torch.randn(10, 3, 4)
  6582. >>> batch2 = torch.randn(10, 4, 5)
  6583. >>> torch.baddbmm(M, batch1, batch2).size()
  6584. torch.Size([10, 3, 5])
  6585. """
  6586. @overload
  6587. def baddbmm(
  6588. input: Tensor,
  6589. batch1: Tensor,
  6590. batch2: Tensor,
  6591. out_dtype: _dtype,
  6592. *,
  6593. beta: Number | _complex = 1,
  6594. alpha: Number | _complex = 1,
  6595. out: Tensor | None = None,
  6596. ) -> Tensor:
  6597. r"""
  6598. baddbmm(input, batch1, batch2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  6599. Performs a batch matrix-matrix product of matrices in :attr:`batch1`
  6600. and :attr:`batch2`.
  6601. :attr:`input` is added to the final result.
  6602. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the same
  6603. number of matrices.
  6604. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  6605. :math:`(b \times m \times p)` tensor, then :attr:`input` must be
  6606. :ref:`broadcastable <broadcasting-semantics>` with a
  6607. :math:`(b \times n \times p)` tensor and :attr:`out` will be a
  6608. :math:`(b \times n \times p)` tensor. Both :attr:`alpha` and :attr:`beta` mean the
  6609. same as the scaling factors used in :meth:`torch.addbmm`.
  6610. .. math::
  6611. \text{out}_i = \beta\ \text{input}_i + \alpha\ (\text{batch1}_i \mathbin{@} \text{batch2}_i)
  6612. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  6613. it will not be propagated.
  6614. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  6615. :attr:`alpha` must be real numbers, otherwise they should be integers.
  6616. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  6617. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  6618. Args:
  6619. input (Tensor): the tensor to be added
  6620. batch1 (Tensor): the first batch of matrices to be multiplied
  6621. batch2 (Tensor): the second batch of matrices to be multiplied
  6622. out_dtype (dtype, optional): the dtype of the output tensor,
  6623. Supported only on CUDA and for torch.float32 given
  6624. torch.float16/torch.bfloat16 input dtypes
  6625. Keyword args:
  6626. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  6627. alpha (Number, optional): multiplier for :math:`\text{batch1} \mathbin{@} \text{batch2}` (:math:`\alpha`)
  6628. out (Tensor, optional): the output tensor.
  6629. Example::
  6630. >>> M = torch.randn(10, 3, 5)
  6631. >>> batch1 = torch.randn(10, 3, 4)
  6632. >>> batch2 = torch.randn(10, 4, 5)
  6633. >>> torch.baddbmm(M, batch1, batch2).size()
  6634. torch.Size([10, 3, 5])
  6635. """
  6636. @overload
  6637. def baddbmm(
  6638. beta: Number | _complex,
  6639. self: Tensor,
  6640. batch1: Tensor,
  6641. batch2: Tensor,
  6642. ) -> Tensor:
  6643. r"""
  6644. baddbmm(input, batch1, batch2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  6645. Performs a batch matrix-matrix product of matrices in :attr:`batch1`
  6646. and :attr:`batch2`.
  6647. :attr:`input` is added to the final result.
  6648. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the same
  6649. number of matrices.
  6650. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  6651. :math:`(b \times m \times p)` tensor, then :attr:`input` must be
  6652. :ref:`broadcastable <broadcasting-semantics>` with a
  6653. :math:`(b \times n \times p)` tensor and :attr:`out` will be a
  6654. :math:`(b \times n \times p)` tensor. Both :attr:`alpha` and :attr:`beta` mean the
  6655. same as the scaling factors used in :meth:`torch.addbmm`.
  6656. .. math::
  6657. \text{out}_i = \beta\ \text{input}_i + \alpha\ (\text{batch1}_i \mathbin{@} \text{batch2}_i)
  6658. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  6659. it will not be propagated.
  6660. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  6661. :attr:`alpha` must be real numbers, otherwise they should be integers.
  6662. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  6663. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  6664. Args:
  6665. input (Tensor): the tensor to be added
  6666. batch1 (Tensor): the first batch of matrices to be multiplied
  6667. batch2 (Tensor): the second batch of matrices to be multiplied
  6668. out_dtype (dtype, optional): the dtype of the output tensor,
  6669. Supported only on CUDA and for torch.float32 given
  6670. torch.float16/torch.bfloat16 input dtypes
  6671. Keyword args:
  6672. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  6673. alpha (Number, optional): multiplier for :math:`\text{batch1} \mathbin{@} \text{batch2}` (:math:`\alpha`)
  6674. out (Tensor, optional): the output tensor.
  6675. Example::
  6676. >>> M = torch.randn(10, 3, 5)
  6677. >>> batch1 = torch.randn(10, 3, 4)
  6678. >>> batch2 = torch.randn(10, 4, 5)
  6679. >>> torch.baddbmm(M, batch1, batch2).size()
  6680. torch.Size([10, 3, 5])
  6681. """
  6682. @overload
  6683. def baddbmm(
  6684. beta: Number | _complex,
  6685. self: Tensor,
  6686. batch1: Tensor,
  6687. batch2: Tensor,
  6688. *,
  6689. out: Tensor,
  6690. ) -> Tensor:
  6691. r"""
  6692. baddbmm(input, batch1, batch2, out_dtype=None, *, beta=1, alpha=1, out=None) -> Tensor
  6693. Performs a batch matrix-matrix product of matrices in :attr:`batch1`
  6694. and :attr:`batch2`.
  6695. :attr:`input` is added to the final result.
  6696. :attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the same
  6697. number of matrices.
  6698. If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
  6699. :math:`(b \times m \times p)` tensor, then :attr:`input` must be
  6700. :ref:`broadcastable <broadcasting-semantics>` with a
  6701. :math:`(b \times n \times p)` tensor and :attr:`out` will be a
  6702. :math:`(b \times n \times p)` tensor. Both :attr:`alpha` and :attr:`beta` mean the
  6703. same as the scaling factors used in :meth:`torch.addbmm`.
  6704. .. math::
  6705. \text{out}_i = \beta\ \text{input}_i + \alpha\ (\text{batch1}_i \mathbin{@} \text{batch2}_i)
  6706. If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
  6707. it will not be propagated.
  6708. For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
  6709. :attr:`alpha` must be real numbers, otherwise they should be integers.
  6710. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  6711. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  6712. Args:
  6713. input (Tensor): the tensor to be added
  6714. batch1 (Tensor): the first batch of matrices to be multiplied
  6715. batch2 (Tensor): the second batch of matrices to be multiplied
  6716. out_dtype (dtype, optional): the dtype of the output tensor,
  6717. Supported only on CUDA and for torch.float32 given
  6718. torch.float16/torch.bfloat16 input dtypes
  6719. Keyword args:
  6720. beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
  6721. alpha (Number, optional): multiplier for :math:`\text{batch1} \mathbin{@} \text{batch2}` (:math:`\alpha`)
  6722. out (Tensor, optional): the output tensor.
  6723. Example::
  6724. >>> M = torch.randn(10, 3, 5)
  6725. >>> batch1 = torch.randn(10, 3, 4)
  6726. >>> batch2 = torch.randn(10, 4, 5)
  6727. >>> torch.baddbmm(M, batch1, batch2).size()
  6728. torch.Size([10, 3, 5])
  6729. """
  6730. @overload
  6731. def bartlett_window(
  6732. window_length: _int,
  6733. *,
  6734. dtype: _dtype | None = None,
  6735. layout: _layout | None = None,
  6736. device: DeviceLikeType | None = None,
  6737. pin_memory: _bool | None = False,
  6738. requires_grad: _bool | None = False,
  6739. ) -> Tensor:
  6740. r"""
  6741. bartlett_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  6742. Bartlett window function.
  6743. .. math::
  6744. w[n] = 1 - \left| \frac{2n}{N-1} - 1 \right| = \begin{cases}
  6745. \frac{2n}{N - 1} & \text{if } 0 \leq n \leq \frac{N - 1}{2} \\
  6746. 2 - \frac{2n}{N - 1} & \text{if } \frac{N - 1}{2} < n < N \\
  6747. \end{cases},
  6748. where :math:`N` is the full window size.
  6749. The input :attr:`window_length` is a positive integer controlling the
  6750. returned window size. :attr:`periodic` flag determines whether the returned
  6751. window trims off the last duplicate value from the symmetric window and is
  6752. ready to be used as a periodic window with functions like
  6753. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  6754. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  6755. ``torch.bartlett_window(L, periodic=True)`` equal to
  6756. ``torch.bartlett_window(L + 1, periodic=False)[:-1])``.
  6757. .. note::
  6758. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  6759. Arguments:
  6760. window_length (int): the size of returned window
  6761. periodic (bool, optional): If True, returns a window to be used as periodic
  6762. function. If False, return a symmetric window.
  6763. Keyword args:
  6764. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  6765. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  6766. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  6767. ``torch.strided`` (dense layout) is supported.
  6768. device (:class:`torch.device`, optional): the desired device of returned tensor.
  6769. Default: if ``None``, uses the current device for the default tensor type
  6770. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  6771. for CPU tensor types and the current CUDA device for CUDA tensor types.
  6772. requires_grad (bool, optional): If autograd should record operations on the
  6773. returned tensor. Default: ``False``.
  6774. Returns:
  6775. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window
  6776. """
  6777. @overload
  6778. def bartlett_window(
  6779. window_length: _int,
  6780. periodic: _bool,
  6781. *,
  6782. dtype: _dtype | None = None,
  6783. layout: _layout | None = None,
  6784. device: DeviceLikeType | None = None,
  6785. pin_memory: _bool | None = False,
  6786. requires_grad: _bool | None = False,
  6787. ) -> Tensor:
  6788. r"""
  6789. bartlett_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  6790. Bartlett window function.
  6791. .. math::
  6792. w[n] = 1 - \left| \frac{2n}{N-1} - 1 \right| = \begin{cases}
  6793. \frac{2n}{N - 1} & \text{if } 0 \leq n \leq \frac{N - 1}{2} \\
  6794. 2 - \frac{2n}{N - 1} & \text{if } \frac{N - 1}{2} < n < N \\
  6795. \end{cases},
  6796. where :math:`N` is the full window size.
  6797. The input :attr:`window_length` is a positive integer controlling the
  6798. returned window size. :attr:`periodic` flag determines whether the returned
  6799. window trims off the last duplicate value from the symmetric window and is
  6800. ready to be used as a periodic window with functions like
  6801. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  6802. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  6803. ``torch.bartlett_window(L, periodic=True)`` equal to
  6804. ``torch.bartlett_window(L + 1, periodic=False)[:-1])``.
  6805. .. note::
  6806. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  6807. Arguments:
  6808. window_length (int): the size of returned window
  6809. periodic (bool, optional): If True, returns a window to be used as periodic
  6810. function. If False, return a symmetric window.
  6811. Keyword args:
  6812. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  6813. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  6814. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  6815. ``torch.strided`` (dense layout) is supported.
  6816. device (:class:`torch.device`, optional): the desired device of returned tensor.
  6817. Default: if ``None``, uses the current device for the default tensor type
  6818. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  6819. for CPU tensor types and the current CUDA device for CUDA tensor types.
  6820. requires_grad (bool, optional): If autograd should record operations on the
  6821. returned tensor. Default: ``False``.
  6822. Returns:
  6823. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window
  6824. """
  6825. def batch_norm(
  6826. input: Tensor,
  6827. weight: Tensor | None,
  6828. bias: Tensor | None,
  6829. running_mean: Tensor | None,
  6830. running_var: Tensor | None,
  6831. training: _bool,
  6832. momentum: _float,
  6833. eps: _float,
  6834. cudnn_enabled: _bool,
  6835. ) -> Tensor: ...
  6836. def batch_norm_backward_elemt(
  6837. grad_out: Tensor,
  6838. input: Tensor,
  6839. mean: Tensor,
  6840. invstd: Tensor,
  6841. weight: Tensor | None,
  6842. sum_dy: Tensor,
  6843. sum_dy_xmu: Tensor,
  6844. count: Tensor,
  6845. ) -> Tensor: ...
  6846. def batch_norm_backward_reduce(
  6847. grad_out: Tensor,
  6848. input: Tensor,
  6849. mean: Tensor,
  6850. invstd: Tensor,
  6851. weight: Tensor | None,
  6852. input_g: _bool,
  6853. weight_g: _bool,
  6854. bias_g: _bool,
  6855. ) -> tuple[Tensor, Tensor, Tensor, Tensor]: ...
  6856. def batch_norm_elemt(
  6857. input: Tensor,
  6858. weight: Tensor | None,
  6859. bias: Tensor | None,
  6860. mean: Tensor,
  6861. invstd: Tensor,
  6862. eps: _float,
  6863. *,
  6864. out: Tensor | None = None,
  6865. ) -> Tensor: ...
  6866. def batch_norm_gather_stats(
  6867. input: Tensor,
  6868. mean: Tensor,
  6869. invstd: Tensor,
  6870. running_mean: Tensor | None,
  6871. running_var: Tensor | None,
  6872. momentum: _float,
  6873. eps: _float,
  6874. count: _int,
  6875. ) -> tuple[Tensor, Tensor]: ...
  6876. def batch_norm_gather_stats_with_counts(
  6877. input: Tensor,
  6878. mean: Tensor,
  6879. invstd: Tensor,
  6880. running_mean: Tensor | None,
  6881. running_var: Tensor | None,
  6882. momentum: _float,
  6883. eps: _float,
  6884. counts: Tensor,
  6885. ) -> tuple[Tensor, Tensor]: ...
  6886. def batch_norm_stats(input: Tensor, eps: _float) -> tuple[Tensor, Tensor]: ...
  6887. def batch_norm_update_stats(
  6888. input: Tensor,
  6889. running_mean: Tensor | None,
  6890. running_var: Tensor | None,
  6891. momentum: _float,
  6892. ) -> tuple[Tensor, Tensor]: ...
  6893. @overload
  6894. def bernoulli(
  6895. input: Tensor,
  6896. *,
  6897. generator: Generator | None = None,
  6898. out: Tensor | None = None,
  6899. ) -> Tensor:
  6900. r"""
  6901. bernoulli(input: Tensor, *, generator: Optional[Generator], out: Optional[Tensor]) -> Tensor
  6902. Draws binary random numbers (0 or 1) from a Bernoulli distribution.
  6903. The :attr:`input` tensor should be a tensor containing probabilities
  6904. to be used for drawing the binary random number.
  6905. Hence, all values in :attr:`input` have to be in the range:
  6906. :math:`0 \leq \text{input}_i \leq 1`.
  6907. The :math:`\text{i}^{th}` element of the output tensor will draw a
  6908. value :math:`1` according to the :math:`\text{i}^{th}` probability value given
  6909. in :attr:`input`.
  6910. .. math::
  6911. \text{out}_{i} \sim \mathrm{Bernoulli}(p = \text{input}_{i})
  6912. The returned :attr:`out` tensor only has values 0 or 1 and is of the same
  6913. shape as :attr:`input`.
  6914. :attr:`out` can have integral ``dtype``, but :attr:`input` must have floating
  6915. point ``dtype``.
  6916. Args:
  6917. input (Tensor): the input tensor of probability values for the Bernoulli distribution
  6918. Keyword args:
  6919. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  6920. out (Tensor, optional): the output tensor.
  6921. Example::
  6922. >>> a = torch.empty(3, 3).uniform_(0, 1) # generate a uniform random matrix with range [0, 1]
  6923. >>> a
  6924. tensor([[ 0.1737, 0.0950, 0.3609],
  6925. [ 0.7148, 0.0289, 0.2676],
  6926. [ 0.9456, 0.8937, 0.7202]])
  6927. >>> torch.bernoulli(a)
  6928. tensor([[ 1., 0., 0.],
  6929. [ 0., 0., 0.],
  6930. [ 1., 1., 1.]])
  6931. >>> a = torch.ones(3, 3) # probability of drawing "1" is 1
  6932. >>> torch.bernoulli(a)
  6933. tensor([[ 1., 1., 1.],
  6934. [ 1., 1., 1.],
  6935. [ 1., 1., 1.]])
  6936. >>> a = torch.zeros(3, 3) # probability of drawing "1" is 0
  6937. >>> torch.bernoulli(a)
  6938. tensor([[ 0., 0., 0.],
  6939. [ 0., 0., 0.],
  6940. [ 0., 0., 0.]])
  6941. """
  6942. @overload
  6943. def bernoulli(
  6944. input: Tensor,
  6945. p: _float,
  6946. *,
  6947. generator: Generator | None = None,
  6948. ) -> Tensor:
  6949. r"""
  6950. bernoulli(input: Tensor, *, generator: Optional[Generator], out: Optional[Tensor]) -> Tensor
  6951. Draws binary random numbers (0 or 1) from a Bernoulli distribution.
  6952. The :attr:`input` tensor should be a tensor containing probabilities
  6953. to be used for drawing the binary random number.
  6954. Hence, all values in :attr:`input` have to be in the range:
  6955. :math:`0 \leq \text{input}_i \leq 1`.
  6956. The :math:`\text{i}^{th}` element of the output tensor will draw a
  6957. value :math:`1` according to the :math:`\text{i}^{th}` probability value given
  6958. in :attr:`input`.
  6959. .. math::
  6960. \text{out}_{i} \sim \mathrm{Bernoulli}(p = \text{input}_{i})
  6961. The returned :attr:`out` tensor only has values 0 or 1 and is of the same
  6962. shape as :attr:`input`.
  6963. :attr:`out` can have integral ``dtype``, but :attr:`input` must have floating
  6964. point ``dtype``.
  6965. Args:
  6966. input (Tensor): the input tensor of probability values for the Bernoulli distribution
  6967. Keyword args:
  6968. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  6969. out (Tensor, optional): the output tensor.
  6970. Example::
  6971. >>> a = torch.empty(3, 3).uniform_(0, 1) # generate a uniform random matrix with range [0, 1]
  6972. >>> a
  6973. tensor([[ 0.1737, 0.0950, 0.3609],
  6974. [ 0.7148, 0.0289, 0.2676],
  6975. [ 0.9456, 0.8937, 0.7202]])
  6976. >>> torch.bernoulli(a)
  6977. tensor([[ 1., 0., 0.],
  6978. [ 0., 0., 0.],
  6979. [ 1., 1., 1.]])
  6980. >>> a = torch.ones(3, 3) # probability of drawing "1" is 1
  6981. >>> torch.bernoulli(a)
  6982. tensor([[ 1., 1., 1.],
  6983. [ 1., 1., 1.],
  6984. [ 1., 1., 1.]])
  6985. >>> a = torch.zeros(3, 3) # probability of drawing "1" is 0
  6986. >>> torch.bernoulli(a)
  6987. tensor([[ 0., 0., 0.],
  6988. [ 0., 0., 0.],
  6989. [ 0., 0., 0.]])
  6990. """
  6991. def bilinear(
  6992. input1: Tensor,
  6993. input2: Tensor,
  6994. weight: Tensor,
  6995. bias: Tensor | None = None,
  6996. ) -> Tensor: ...
  6997. def binary_cross_entropy_with_logits(
  6998. input: Tensor,
  6999. target: Tensor,
  7000. weight: Tensor | None = None,
  7001. pos_weight: Tensor | None = None,
  7002. reduction: _int = 1,
  7003. ) -> Tensor: ...
  7004. def bincount(
  7005. input: Tensor,
  7006. weights: Tensor | None = None,
  7007. minlength: _int | SymInt = 0,
  7008. ) -> Tensor:
  7009. r"""
  7010. bincount(input, weights=None, minlength=0) -> Tensor
  7011. Count the frequency of each value in an array of non-negative ints.
  7012. The number of bins (size 1) is one larger than the largest value in
  7013. :attr:`input` unless :attr:`input` is empty, in which case the result is a
  7014. tensor of size 0. If :attr:`minlength` is specified, the number of bins is at least
  7015. :attr:`minlength` and if :attr:`input` is empty, then the result is tensor of size
  7016. :attr:`minlength` filled with zeros. If ``n`` is the value at position ``i``,
  7017. ``out[n] += weights[i]`` if :attr:`weights` is specified else
  7018. ``out[n] += 1``.
  7019. Note:
  7020. This operation may produce nondeterministic gradients when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
  7021. Arguments:
  7022. input (Tensor): 1-d int tensor
  7023. weights (Tensor): optional, weight for each value in the input tensor.
  7024. Should be of same size as input tensor.
  7025. minlength (int): optional, minimum number of bins. Should be non-negative.
  7026. Returns:
  7027. output (Tensor): a tensor of shape ``Size([max(input) + 1])`` if
  7028. :attr:`input` is non-empty, else ``Size(0)``
  7029. Example::
  7030. >>> input = torch.randint(0, 8, (5,), dtype=torch.int64)
  7031. >>> weights = torch.linspace(0, 1, steps=5)
  7032. >>> input, weights
  7033. (tensor([4, 3, 6, 3, 4]),
  7034. tensor([ 0.0000, 0.2500, 0.5000, 0.7500, 1.0000])
  7035. >>> torch.bincount(input)
  7036. tensor([0, 0, 0, 2, 2, 0, 1])
  7037. >>> input.bincount(weights)
  7038. tensor([0.0000, 0.0000, 0.0000, 1.0000, 1.0000, 0.0000, 0.5000])
  7039. """
  7040. def binomial(
  7041. count: Tensor,
  7042. prob: Tensor,
  7043. generator: Generator | None = None,
  7044. ) -> Tensor: ...
  7045. @overload
  7046. def bitwise_and(
  7047. input: Tensor,
  7048. other: Tensor,
  7049. *,
  7050. out: Tensor | None = None,
  7051. ) -> Tensor:
  7052. r"""
  7053. bitwise_and(input, other, *, out=None) -> Tensor
  7054. Computes the bitwise AND of :attr:`input` and :attr:`other`. The input tensor must be of
  7055. integral or Boolean types. For bool tensors, it computes the logical AND.
  7056. Args:
  7057. input: the first input tensor
  7058. other: the second input tensor
  7059. Keyword args:
  7060. out (Tensor, optional): the output tensor.
  7061. Example::
  7062. >>> torch.bitwise_and(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7063. tensor([1, 0, 3], dtype=torch.int8)
  7064. >>> torch.bitwise_and(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7065. tensor([ False, True, False])
  7066. """
  7067. @overload
  7068. def bitwise_and(self: Number | _complex, other: Tensor) -> Tensor:
  7069. r"""
  7070. bitwise_and(input, other, *, out=None) -> Tensor
  7071. Computes the bitwise AND of :attr:`input` and :attr:`other`. The input tensor must be of
  7072. integral or Boolean types. For bool tensors, it computes the logical AND.
  7073. Args:
  7074. input: the first input tensor
  7075. other: the second input tensor
  7076. Keyword args:
  7077. out (Tensor, optional): the output tensor.
  7078. Example::
  7079. >>> torch.bitwise_and(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7080. tensor([1, 0, 3], dtype=torch.int8)
  7081. >>> torch.bitwise_and(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7082. tensor([ False, True, False])
  7083. """
  7084. @overload
  7085. def bitwise_and(
  7086. input: Tensor,
  7087. other: Number | _complex,
  7088. *,
  7089. out: Tensor | None = None,
  7090. ) -> Tensor:
  7091. r"""
  7092. bitwise_and(input, other, *, out=None) -> Tensor
  7093. Computes the bitwise AND of :attr:`input` and :attr:`other`. The input tensor must be of
  7094. integral or Boolean types. For bool tensors, it computes the logical AND.
  7095. Args:
  7096. input: the first input tensor
  7097. other: the second input tensor
  7098. Keyword args:
  7099. out (Tensor, optional): the output tensor.
  7100. Example::
  7101. >>> torch.bitwise_and(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7102. tensor([1, 0, 3], dtype=torch.int8)
  7103. >>> torch.bitwise_and(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7104. tensor([ False, True, False])
  7105. """
  7106. @overload
  7107. def bitwise_left_shift(
  7108. input: Tensor,
  7109. other: Tensor,
  7110. *,
  7111. out: Tensor | None = None,
  7112. ) -> Tensor:
  7113. r"""
  7114. bitwise_left_shift(input, other, *, out=None) -> Tensor
  7115. Computes the left arithmetic shift of :attr:`input` by :attr:`other` bits.
  7116. The input tensor must be of integral type. This operator supports
  7117. :ref:`broadcasting to a common shape <broadcasting-semantics>` and
  7118. :ref:`type promotion <type-promotion-doc>`.
  7119. The operation applied is:
  7120. .. math::
  7121. \text{out}_i = \text{input}_i << \text{other}_i
  7122. Args:
  7123. input (Tensor or Scalar): the first input tensor
  7124. other (Tensor or Scalar): the second input tensor
  7125. Keyword args:
  7126. out (Tensor, optional): the output tensor.
  7127. Example::
  7128. >>> torch.bitwise_left_shift(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7129. tensor([-2, -2, 24], dtype=torch.int8)
  7130. """
  7131. @overload
  7132. def bitwise_left_shift(self: Number | _complex, other: Tensor) -> Tensor:
  7133. r"""
  7134. bitwise_left_shift(input, other, *, out=None) -> Tensor
  7135. Computes the left arithmetic shift of :attr:`input` by :attr:`other` bits.
  7136. The input tensor must be of integral type. This operator supports
  7137. :ref:`broadcasting to a common shape <broadcasting-semantics>` and
  7138. :ref:`type promotion <type-promotion-doc>`.
  7139. The operation applied is:
  7140. .. math::
  7141. \text{out}_i = \text{input}_i << \text{other}_i
  7142. Args:
  7143. input (Tensor or Scalar): the first input tensor
  7144. other (Tensor or Scalar): the second input tensor
  7145. Keyword args:
  7146. out (Tensor, optional): the output tensor.
  7147. Example::
  7148. >>> torch.bitwise_left_shift(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7149. tensor([-2, -2, 24], dtype=torch.int8)
  7150. """
  7151. @overload
  7152. def bitwise_left_shift(
  7153. input: Tensor,
  7154. other: Number | _complex,
  7155. *,
  7156. out: Tensor | None = None,
  7157. ) -> Tensor:
  7158. r"""
  7159. bitwise_left_shift(input, other, *, out=None) -> Tensor
  7160. Computes the left arithmetic shift of :attr:`input` by :attr:`other` bits.
  7161. The input tensor must be of integral type. This operator supports
  7162. :ref:`broadcasting to a common shape <broadcasting-semantics>` and
  7163. :ref:`type promotion <type-promotion-doc>`.
  7164. The operation applied is:
  7165. .. math::
  7166. \text{out}_i = \text{input}_i << \text{other}_i
  7167. Args:
  7168. input (Tensor or Scalar): the first input tensor
  7169. other (Tensor or Scalar): the second input tensor
  7170. Keyword args:
  7171. out (Tensor, optional): the output tensor.
  7172. Example::
  7173. >>> torch.bitwise_left_shift(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7174. tensor([-2, -2, 24], dtype=torch.int8)
  7175. """
  7176. def bitwise_not(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  7177. r"""
  7178. bitwise_not(input, *, out=None) -> Tensor
  7179. Computes the bitwise NOT of the given input tensor. The input tensor must be of
  7180. integral or Boolean types. For bool tensors, it computes the logical NOT.
  7181. Args:
  7182. input (Tensor): the input tensor.
  7183. Keyword args:
  7184. out (Tensor, optional): the output tensor.
  7185. Example::
  7186. >>> torch.bitwise_not(torch.tensor([-1, -2, 3], dtype=torch.int8))
  7187. tensor([ 0, 1, -4], dtype=torch.int8)
  7188. """
  7189. @overload
  7190. def bitwise_or(
  7191. input: Tensor,
  7192. other: Tensor,
  7193. *,
  7194. out: Tensor | None = None,
  7195. ) -> Tensor:
  7196. r"""
  7197. bitwise_or(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
  7198. Computes the bitwise OR of :attr:`input` and :attr:`other`. The input tensor must be of
  7199. integral or Boolean types. For bool tensors, it computes the logical OR.
  7200. Args:
  7201. input: the first input tensor
  7202. other: the second input tensor
  7203. Keyword args:
  7204. out (Tensor, optional): the output tensor.
  7205. Example::
  7206. >>> torch.bitwise_or(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7207. tensor([-1, -2, 3], dtype=torch.int8)
  7208. >>> torch.bitwise_or(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7209. tensor([ True, True, False])
  7210. """
  7211. @overload
  7212. def bitwise_or(self: Number | _complex, other: Tensor) -> Tensor:
  7213. r"""
  7214. bitwise_or(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
  7215. Computes the bitwise OR of :attr:`input` and :attr:`other`. The input tensor must be of
  7216. integral or Boolean types. For bool tensors, it computes the logical OR.
  7217. Args:
  7218. input: the first input tensor
  7219. other: the second input tensor
  7220. Keyword args:
  7221. out (Tensor, optional): the output tensor.
  7222. Example::
  7223. >>> torch.bitwise_or(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7224. tensor([-1, -2, 3], dtype=torch.int8)
  7225. >>> torch.bitwise_or(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7226. tensor([ True, True, False])
  7227. """
  7228. @overload
  7229. def bitwise_or(
  7230. input: Tensor,
  7231. other: Number | _complex,
  7232. *,
  7233. out: Tensor | None = None,
  7234. ) -> Tensor:
  7235. r"""
  7236. bitwise_or(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
  7237. Computes the bitwise OR of :attr:`input` and :attr:`other`. The input tensor must be of
  7238. integral or Boolean types. For bool tensors, it computes the logical OR.
  7239. Args:
  7240. input: the first input tensor
  7241. other: the second input tensor
  7242. Keyword args:
  7243. out (Tensor, optional): the output tensor.
  7244. Example::
  7245. >>> torch.bitwise_or(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7246. tensor([-1, -2, 3], dtype=torch.int8)
  7247. >>> torch.bitwise_or(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7248. tensor([ True, True, False])
  7249. """
  7250. @overload
  7251. def bitwise_right_shift(
  7252. input: Tensor,
  7253. other: Tensor,
  7254. *,
  7255. out: Tensor | None = None,
  7256. ) -> Tensor:
  7257. r"""
  7258. bitwise_right_shift(input, other, *, out=None) -> Tensor
  7259. Computes the right arithmetic shift of :attr:`input` by :attr:`other` bits.
  7260. The input tensor must be of integral type. This operator supports
  7261. :ref:`broadcasting to a common shape <broadcasting-semantics>` and
  7262. :ref:`type promotion <type-promotion-doc>`.
  7263. In any case, if the value of the right operand is negative or is greater
  7264. or equal to the number of bits in the promoted left operand, the behavior is undefined.
  7265. The operation applied is:
  7266. .. math::
  7267. \text{out}_i = \text{input}_i >> \text{other}_i
  7268. Args:
  7269. input (Tensor or Scalar): the first input tensor
  7270. other (Tensor or Scalar): the second input tensor
  7271. Keyword args:
  7272. out (Tensor, optional): the output tensor.
  7273. Example::
  7274. >>> torch.bitwise_right_shift(torch.tensor([-2, -7, 31], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7275. tensor([-1, -7, 3], dtype=torch.int8)
  7276. """
  7277. @overload
  7278. def bitwise_right_shift(self: Number | _complex, other: Tensor) -> Tensor:
  7279. r"""
  7280. bitwise_right_shift(input, other, *, out=None) -> Tensor
  7281. Computes the right arithmetic shift of :attr:`input` by :attr:`other` bits.
  7282. The input tensor must be of integral type. This operator supports
  7283. :ref:`broadcasting to a common shape <broadcasting-semantics>` and
  7284. :ref:`type promotion <type-promotion-doc>`.
  7285. In any case, if the value of the right operand is negative or is greater
  7286. or equal to the number of bits in the promoted left operand, the behavior is undefined.
  7287. The operation applied is:
  7288. .. math::
  7289. \text{out}_i = \text{input}_i >> \text{other}_i
  7290. Args:
  7291. input (Tensor or Scalar): the first input tensor
  7292. other (Tensor or Scalar): the second input tensor
  7293. Keyword args:
  7294. out (Tensor, optional): the output tensor.
  7295. Example::
  7296. >>> torch.bitwise_right_shift(torch.tensor([-2, -7, 31], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7297. tensor([-1, -7, 3], dtype=torch.int8)
  7298. """
  7299. @overload
  7300. def bitwise_right_shift(
  7301. input: Tensor,
  7302. other: Number | _complex,
  7303. *,
  7304. out: Tensor | None = None,
  7305. ) -> Tensor:
  7306. r"""
  7307. bitwise_right_shift(input, other, *, out=None) -> Tensor
  7308. Computes the right arithmetic shift of :attr:`input` by :attr:`other` bits.
  7309. The input tensor must be of integral type. This operator supports
  7310. :ref:`broadcasting to a common shape <broadcasting-semantics>` and
  7311. :ref:`type promotion <type-promotion-doc>`.
  7312. In any case, if the value of the right operand is negative or is greater
  7313. or equal to the number of bits in the promoted left operand, the behavior is undefined.
  7314. The operation applied is:
  7315. .. math::
  7316. \text{out}_i = \text{input}_i >> \text{other}_i
  7317. Args:
  7318. input (Tensor or Scalar): the first input tensor
  7319. other (Tensor or Scalar): the second input tensor
  7320. Keyword args:
  7321. out (Tensor, optional): the output tensor.
  7322. Example::
  7323. >>> torch.bitwise_right_shift(torch.tensor([-2, -7, 31], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7324. tensor([-1, -7, 3], dtype=torch.int8)
  7325. """
  7326. @overload
  7327. def bitwise_xor(
  7328. input: Tensor,
  7329. other: Tensor,
  7330. *,
  7331. out: Tensor | None = None,
  7332. ) -> Tensor:
  7333. r"""
  7334. bitwise_xor(input, other, *, out=None) -> Tensor
  7335. Computes the bitwise XOR of :attr:`input` and :attr:`other`. The input tensor must be of
  7336. integral or Boolean types. For bool tensors, it computes the logical XOR.
  7337. Args:
  7338. input: the first input tensor
  7339. other: the second input tensor
  7340. Keyword args:
  7341. out (Tensor, optional): the output tensor.
  7342. Example::
  7343. >>> torch.bitwise_xor(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7344. tensor([-2, -2, 0], dtype=torch.int8)
  7345. >>> torch.bitwise_xor(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7346. tensor([ True, False, False])
  7347. """
  7348. @overload
  7349. def bitwise_xor(self: Number | _complex, other: Tensor) -> Tensor:
  7350. r"""
  7351. bitwise_xor(input, other, *, out=None) -> Tensor
  7352. Computes the bitwise XOR of :attr:`input` and :attr:`other`. The input tensor must be of
  7353. integral or Boolean types. For bool tensors, it computes the logical XOR.
  7354. Args:
  7355. input: the first input tensor
  7356. other: the second input tensor
  7357. Keyword args:
  7358. out (Tensor, optional): the output tensor.
  7359. Example::
  7360. >>> torch.bitwise_xor(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7361. tensor([-2, -2, 0], dtype=torch.int8)
  7362. >>> torch.bitwise_xor(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7363. tensor([ True, False, False])
  7364. """
  7365. @overload
  7366. def bitwise_xor(
  7367. input: Tensor,
  7368. other: Number | _complex,
  7369. *,
  7370. out: Tensor | None = None,
  7371. ) -> Tensor:
  7372. r"""
  7373. bitwise_xor(input, other, *, out=None) -> Tensor
  7374. Computes the bitwise XOR of :attr:`input` and :attr:`other`. The input tensor must be of
  7375. integral or Boolean types. For bool tensors, it computes the logical XOR.
  7376. Args:
  7377. input: the first input tensor
  7378. other: the second input tensor
  7379. Keyword args:
  7380. out (Tensor, optional): the output tensor.
  7381. Example::
  7382. >>> torch.bitwise_xor(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
  7383. tensor([-2, -2, 0], dtype=torch.int8)
  7384. >>> torch.bitwise_xor(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
  7385. tensor([ True, False, False])
  7386. """
  7387. @overload
  7388. def blackman_window(
  7389. window_length: _int,
  7390. *,
  7391. dtype: _dtype | None = None,
  7392. layout: _layout | None = None,
  7393. device: DeviceLikeType | None = None,
  7394. pin_memory: _bool | None = False,
  7395. requires_grad: _bool | None = False,
  7396. ) -> Tensor:
  7397. r"""
  7398. blackman_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  7399. Blackman window function.
  7400. .. math::
  7401. 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)
  7402. where :math:`N` is the full window size.
  7403. The input :attr:`window_length` is a positive integer controlling the
  7404. returned window size. :attr:`periodic` flag determines whether the returned
  7405. window trims off the last duplicate value from the symmetric window and is
  7406. ready to be used as a periodic window with functions like
  7407. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  7408. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  7409. ``torch.blackman_window(L, periodic=True)`` equal to
  7410. ``torch.blackman_window(L + 1, periodic=False)[:-1]``.
  7411. .. note::
  7412. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  7413. Arguments:
  7414. window_length (int): the size of returned window
  7415. periodic (bool, optional): If True, returns a window to be used as periodic
  7416. function. If False, return a symmetric window.
  7417. Keyword args:
  7418. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  7419. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  7420. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  7421. ``torch.strided`` (dense layout) is supported.
  7422. device (:class:`torch.device`, optional): the desired device of returned tensor.
  7423. Default: if ``None``, uses the current device for the default tensor type
  7424. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  7425. for CPU tensor types and the current CUDA device for CUDA tensor types.
  7426. requires_grad (bool, optional): If autograd should record operations on the
  7427. returned tensor. Default: ``False``.
  7428. Returns:
  7429. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window
  7430. """
  7431. @overload
  7432. def blackman_window(
  7433. window_length: _int,
  7434. periodic: _bool,
  7435. *,
  7436. dtype: _dtype | None = None,
  7437. layout: _layout | None = None,
  7438. device: DeviceLikeType | None = None,
  7439. pin_memory: _bool | None = False,
  7440. requires_grad: _bool | None = False,
  7441. ) -> Tensor:
  7442. r"""
  7443. blackman_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  7444. Blackman window function.
  7445. .. math::
  7446. 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)
  7447. where :math:`N` is the full window size.
  7448. The input :attr:`window_length` is a positive integer controlling the
  7449. returned window size. :attr:`periodic` flag determines whether the returned
  7450. window trims off the last duplicate value from the symmetric window and is
  7451. ready to be used as a periodic window with functions like
  7452. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  7453. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  7454. ``torch.blackman_window(L, periodic=True)`` equal to
  7455. ``torch.blackman_window(L + 1, periodic=False)[:-1]``.
  7456. .. note::
  7457. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  7458. Arguments:
  7459. window_length (int): the size of returned window
  7460. periodic (bool, optional): If True, returns a window to be used as periodic
  7461. function. If False, return a symmetric window.
  7462. Keyword args:
  7463. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  7464. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  7465. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  7466. ``torch.strided`` (dense layout) is supported.
  7467. device (:class:`torch.device`, optional): the desired device of returned tensor.
  7468. Default: if ``None``, uses the current device for the default tensor type
  7469. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  7470. for CPU tensor types and the current CUDA device for CUDA tensor types.
  7471. requires_grad (bool, optional): If autograd should record operations on the
  7472. returned tensor. Default: ``False``.
  7473. Returns:
  7474. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window
  7475. """
  7476. @overload
  7477. def bmm(
  7478. input: Tensor,
  7479. mat2: Tensor,
  7480. *,
  7481. out: Tensor | None = None,
  7482. ) -> Tensor:
  7483. r"""
  7484. bmm(input, mat2, out_dtype=None, *, out=None) -> Tensor
  7485. Performs a batch matrix-matrix product of matrices stored in :attr:`input`
  7486. and :attr:`mat2`.
  7487. :attr:`input` and :attr:`mat2` must be 3-D tensors each containing
  7488. the same number of matrices.
  7489. If :attr:`input` is a :math:`(b \times n \times m)` tensor, :attr:`mat2` is a
  7490. :math:`(b \times m \times p)` tensor, :attr:`out` will be a
  7491. :math:`(b \times n \times p)` tensor.
  7492. .. math::
  7493. \text{out}_i = \text{input}_i \mathbin{@} \text{mat2}_i
  7494. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  7495. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  7496. .. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
  7497. For broadcasting matrix products, see :func:`torch.matmul`.
  7498. Args:
  7499. input (Tensor): the first batch of matrices to be multiplied
  7500. mat2 (Tensor): the second batch of matrices to be multiplied
  7501. out_dtype (dtype, optional): the dtype of the output tensor,
  7502. Supported only on CUDA and for torch.float32 given
  7503. torch.float16/torch.bfloat16 input dtypes
  7504. Keyword Args:
  7505. out (Tensor, optional): the output tensor.
  7506. Example::
  7507. >>> input = torch.randn(10, 3, 4)
  7508. >>> mat2 = torch.randn(10, 4, 5)
  7509. >>> res = torch.bmm(input, mat2)
  7510. >>> res.size()
  7511. torch.Size([10, 3, 5])
  7512. """
  7513. @overload
  7514. def bmm(
  7515. input: Tensor,
  7516. mat2: Tensor,
  7517. out_dtype: _dtype,
  7518. *,
  7519. out: Tensor | None = None,
  7520. ) -> Tensor:
  7521. r"""
  7522. bmm(input, mat2, out_dtype=None, *, out=None) -> Tensor
  7523. Performs a batch matrix-matrix product of matrices stored in :attr:`input`
  7524. and :attr:`mat2`.
  7525. :attr:`input` and :attr:`mat2` must be 3-D tensors each containing
  7526. the same number of matrices.
  7527. If :attr:`input` is a :math:`(b \times n \times m)` tensor, :attr:`mat2` is a
  7528. :math:`(b \times m \times p)` tensor, :attr:`out` will be a
  7529. :math:`(b \times n \times p)` tensor.
  7530. .. math::
  7531. \text{out}_i = \text{input}_i \mathbin{@} \text{mat2}_i
  7532. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  7533. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  7534. .. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
  7535. For broadcasting matrix products, see :func:`torch.matmul`.
  7536. Args:
  7537. input (Tensor): the first batch of matrices to be multiplied
  7538. mat2 (Tensor): the second batch of matrices to be multiplied
  7539. out_dtype (dtype, optional): the dtype of the output tensor,
  7540. Supported only on CUDA and for torch.float32 given
  7541. torch.float16/torch.bfloat16 input dtypes
  7542. Keyword Args:
  7543. out (Tensor, optional): the output tensor.
  7544. Example::
  7545. >>> input = torch.randn(10, 3, 4)
  7546. >>> mat2 = torch.randn(10, 4, 5)
  7547. >>> res = torch.bmm(input, mat2)
  7548. >>> res.size()
  7549. torch.Size([10, 3, 5])
  7550. """
  7551. def broadcast_to(input: Tensor, size: Sequence[_int | SymInt]) -> Tensor:
  7552. r"""
  7553. broadcast_to(input, shape) -> Tensor
  7554. Broadcasts :attr:`input` to the shape :attr:`\shape`.
  7555. Equivalent to calling ``input.expand(shape)``. See :meth:`~Tensor.expand` for details.
  7556. Args:
  7557. input (Tensor): the input tensor.
  7558. shape (list, tuple, or :class:`torch.Size`): the new shape.
  7559. Example::
  7560. >>> x = torch.tensor([1, 2, 3])
  7561. >>> torch.broadcast_to(x, (3, 3))
  7562. tensor([[1, 2, 3],
  7563. [1, 2, 3],
  7564. [1, 2, 3]])
  7565. """
  7566. @overload
  7567. def bucketize(
  7568. input: Tensor,
  7569. boundaries: Tensor,
  7570. *,
  7571. out_int32: _bool = False,
  7572. right: _bool = False,
  7573. out: Tensor | None = None,
  7574. ) -> Tensor:
  7575. r"""
  7576. bucketize(input, boundaries, *, out_int32=False, right=False, out=None) -> Tensor
  7577. Returns the indices of the buckets to which each value in the :attr:`input` belongs, where the
  7578. boundaries of the buckets are set by :attr:`boundaries`. Return a new tensor with the same size
  7579. as :attr:`input`. If :attr:`right` is False (default), then the left boundary is open. Note that
  7580. this behavior is opposite the behavior of
  7581. `numpy.digitize <https://numpy.org/doc/stable/reference/generated/numpy.digitize.html>`_.
  7582. More formally, the returned index satisfies the following rules:
  7583. .. list-table::
  7584. :widths: 15 85
  7585. :header-rows: 1
  7586. * - :attr:`right`
  7587. - *returned index satisfies*
  7588. * - False
  7589. - ``boundaries[i-1] < input[m][n]...[l][x] <= boundaries[i]``
  7590. * - True
  7591. - ``boundaries[i-1] <= input[m][n]...[l][x] < boundaries[i]``
  7592. Args:
  7593. input (Tensor or Scalar): N-D tensor or a Scalar containing the search value(s).
  7594. boundaries (Tensor): 1-D tensor, must contain a strictly increasing sequence, or the return value is undefined.
  7595. Keyword args:
  7596. out_int32 (bool, optional): indicate the output data type. torch.int32 if True, torch.int64 otherwise.
  7597. Default value is False, i.e. default output data type is torch.int64.
  7598. right (bool, optional): determines the behavior for values in :attr:`boundaries`. See the table above.
  7599. out (Tensor, optional): the output tensor, must be the same size as :attr:`input` if provided.
  7600. Example::
  7601. >>> boundaries = torch.tensor([1, 3, 5, 7, 9])
  7602. >>> boundaries
  7603. tensor([1, 3, 5, 7, 9])
  7604. >>> v = torch.tensor([[3, 6, 9], [3, 6, 9]])
  7605. >>> v
  7606. tensor([[3, 6, 9],
  7607. [3, 6, 9]])
  7608. >>> torch.bucketize(v, boundaries)
  7609. tensor([[1, 3, 4],
  7610. [1, 3, 4]])
  7611. >>> torch.bucketize(v, boundaries, right=True)
  7612. tensor([[2, 3, 5],
  7613. [2, 3, 5]])
  7614. """
  7615. @overload
  7616. def bucketize(
  7617. self: Number | _complex,
  7618. boundaries: Tensor,
  7619. *,
  7620. out_int32: _bool = False,
  7621. right: _bool = False,
  7622. ) -> Tensor:
  7623. r"""
  7624. bucketize(input, boundaries, *, out_int32=False, right=False, out=None) -> Tensor
  7625. Returns the indices of the buckets to which each value in the :attr:`input` belongs, where the
  7626. boundaries of the buckets are set by :attr:`boundaries`. Return a new tensor with the same size
  7627. as :attr:`input`. If :attr:`right` is False (default), then the left boundary is open. Note that
  7628. this behavior is opposite the behavior of
  7629. `numpy.digitize <https://numpy.org/doc/stable/reference/generated/numpy.digitize.html>`_.
  7630. More formally, the returned index satisfies the following rules:
  7631. .. list-table::
  7632. :widths: 15 85
  7633. :header-rows: 1
  7634. * - :attr:`right`
  7635. - *returned index satisfies*
  7636. * - False
  7637. - ``boundaries[i-1] < input[m][n]...[l][x] <= boundaries[i]``
  7638. * - True
  7639. - ``boundaries[i-1] <= input[m][n]...[l][x] < boundaries[i]``
  7640. Args:
  7641. input (Tensor or Scalar): N-D tensor or a Scalar containing the search value(s).
  7642. boundaries (Tensor): 1-D tensor, must contain a strictly increasing sequence, or the return value is undefined.
  7643. Keyword args:
  7644. out_int32 (bool, optional): indicate the output data type. torch.int32 if True, torch.int64 otherwise.
  7645. Default value is False, i.e. default output data type is torch.int64.
  7646. right (bool, optional): determines the behavior for values in :attr:`boundaries`. See the table above.
  7647. out (Tensor, optional): the output tensor, must be the same size as :attr:`input` if provided.
  7648. Example::
  7649. >>> boundaries = torch.tensor([1, 3, 5, 7, 9])
  7650. >>> boundaries
  7651. tensor([1, 3, 5, 7, 9])
  7652. >>> v = torch.tensor([[3, 6, 9], [3, 6, 9]])
  7653. >>> v
  7654. tensor([[3, 6, 9],
  7655. [3, 6, 9]])
  7656. >>> torch.bucketize(v, boundaries)
  7657. tensor([[1, 3, 4],
  7658. [1, 3, 4]])
  7659. >>> torch.bucketize(v, boundaries, right=True)
  7660. tensor([[2, 3, 5],
  7661. [2, 3, 5]])
  7662. """
  7663. def can_cast(from_: _dtype, to: _dtype) -> _bool:
  7664. r"""
  7665. can_cast(from_, to) -> bool
  7666. Determines if a type conversion is allowed under PyTorch casting rules
  7667. described in the type promotion :ref:`documentation <type-promotion-doc>`.
  7668. Args:
  7669. from\_ (dtype): The original :class:`torch.dtype`.
  7670. to (dtype): The target :class:`torch.dtype`.
  7671. Example::
  7672. >>> torch.can_cast(torch.double, torch.float)
  7673. True
  7674. >>> torch.can_cast(torch.float, torch.int)
  7675. False
  7676. """
  7677. @overload
  7678. def cat(
  7679. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  7680. dim: _int = 0,
  7681. *,
  7682. out: Tensor | None = None,
  7683. ) -> Tensor:
  7684. r"""
  7685. cat(tensors, dim=0, *, out=None) -> Tensor
  7686. Concatenates the given sequence of tensors in :attr:`tensors` in the given dimension.
  7687. All tensors must either have the same shape (except in the concatenating
  7688. dimension) or be a 1-D empty tensor with size ``(0,)``.
  7689. :func:`torch.cat` can be seen as an inverse operation for :func:`torch.split`
  7690. and :func:`torch.chunk`.
  7691. :func:`torch.cat` can be best understood via examples.
  7692. .. seealso::
  7693. :func:`torch.stack` concatenates the given sequence along a new dimension.
  7694. Args:
  7695. tensors (sequence of Tensors): Non-empty tensors provided must have the same shape,
  7696. except in the cat dimension.
  7697. dim (int, optional): the dimension over which the tensors are concatenated
  7698. Keyword args:
  7699. out (Tensor, optional): the output tensor.
  7700. Example::
  7701. >>> x = torch.randn(2, 3)
  7702. >>> x
  7703. tensor([[ 0.6580, -1.0969, -0.4614],
  7704. [-0.1034, -0.5790, 0.1497]])
  7705. >>> torch.cat((x, x, x), 0)
  7706. tensor([[ 0.6580, -1.0969, -0.4614],
  7707. [-0.1034, -0.5790, 0.1497],
  7708. [ 0.6580, -1.0969, -0.4614],
  7709. [-0.1034, -0.5790, 0.1497],
  7710. [ 0.6580, -1.0969, -0.4614],
  7711. [-0.1034, -0.5790, 0.1497]])
  7712. >>> torch.cat((x, x, x), 1)
  7713. tensor([[ 0.6580, -1.0969, -0.4614, 0.6580, -1.0969, -0.4614, 0.6580,
  7714. -1.0969, -0.4614],
  7715. [-0.1034, -0.5790, 0.1497, -0.1034, -0.5790, 0.1497, -0.1034,
  7716. -0.5790, 0.1497]])
  7717. """
  7718. @overload
  7719. def cat(
  7720. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  7721. dim: str | EllipsisType | None,
  7722. *,
  7723. out: Tensor | None = None,
  7724. ) -> Tensor:
  7725. r"""
  7726. cat(tensors, dim=0, *, out=None) -> Tensor
  7727. Concatenates the given sequence of tensors in :attr:`tensors` in the given dimension.
  7728. All tensors must either have the same shape (except in the concatenating
  7729. dimension) or be a 1-D empty tensor with size ``(0,)``.
  7730. :func:`torch.cat` can be seen as an inverse operation for :func:`torch.split`
  7731. and :func:`torch.chunk`.
  7732. :func:`torch.cat` can be best understood via examples.
  7733. .. seealso::
  7734. :func:`torch.stack` concatenates the given sequence along a new dimension.
  7735. Args:
  7736. tensors (sequence of Tensors): Non-empty tensors provided must have the same shape,
  7737. except in the cat dimension.
  7738. dim (int, optional): the dimension over which the tensors are concatenated
  7739. Keyword args:
  7740. out (Tensor, optional): the output tensor.
  7741. Example::
  7742. >>> x = torch.randn(2, 3)
  7743. >>> x
  7744. tensor([[ 0.6580, -1.0969, -0.4614],
  7745. [-0.1034, -0.5790, 0.1497]])
  7746. >>> torch.cat((x, x, x), 0)
  7747. tensor([[ 0.6580, -1.0969, -0.4614],
  7748. [-0.1034, -0.5790, 0.1497],
  7749. [ 0.6580, -1.0969, -0.4614],
  7750. [-0.1034, -0.5790, 0.1497],
  7751. [ 0.6580, -1.0969, -0.4614],
  7752. [-0.1034, -0.5790, 0.1497]])
  7753. >>> torch.cat((x, x, x), 1)
  7754. tensor([[ 0.6580, -1.0969, -0.4614, 0.6580, -1.0969, -0.4614, 0.6580,
  7755. -1.0969, -0.4614],
  7756. [-0.1034, -0.5790, 0.1497, -0.1034, -0.5790, 0.1497, -0.1034,
  7757. -0.5790, 0.1497]])
  7758. """
  7759. def ccol_indices_copy(
  7760. input: Tensor,
  7761. *,
  7762. out: Tensor | None = None,
  7763. ) -> Tensor: ...
  7764. def ceil(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  7765. r"""
  7766. ceil(input, *, out=None) -> Tensor
  7767. Returns a new tensor with the ceil of the elements of :attr:`input`,
  7768. the smallest integer greater than or equal to each element.
  7769. For integer inputs, follows the array-api convention of returning a
  7770. copy of the input tensor.
  7771. .. math::
  7772. \text{out}_{i} = \left\lceil \text{input}_{i} \right\rceil
  7773. Args:
  7774. input (Tensor): the input tensor.
  7775. Keyword args:
  7776. out (Tensor, optional): the output tensor.
  7777. Example::
  7778. >>> a = torch.randn(4)
  7779. >>> a
  7780. tensor([-0.6341, -1.4208, -1.0900, 0.5826])
  7781. >>> torch.ceil(a)
  7782. tensor([-0., -1., -1., 1.])
  7783. """
  7784. def ceil_(input: Tensor) -> Tensor: ...
  7785. def celu(input: Tensor, alpha: Number | _complex = 1.0) -> Tensor: ...
  7786. def celu_(input: Tensor, alpha: Number | _complex = 1.0) -> Tensor: ...
  7787. def channel_shuffle(input: Tensor, groups: _int | SymInt) -> Tensor: ...
  7788. def cholesky(
  7789. input: Tensor,
  7790. upper: _bool = False,
  7791. *,
  7792. out: Tensor | None = None,
  7793. ) -> Tensor:
  7794. r"""
  7795. cholesky(input, upper=False, *, out=None) -> Tensor
  7796. Computes the Cholesky decomposition of a symmetric positive-definite
  7797. matrix :math:`A` or for batches of symmetric positive-definite matrices.
  7798. If :attr:`upper` is ``True``, the returned matrix ``U`` is upper-triangular, and
  7799. the decomposition has the form:
  7800. .. math::
  7801. A = U^TU
  7802. If :attr:`upper` is ``False``, the returned matrix ``L`` is lower-triangular, and
  7803. the decomposition has the form:
  7804. .. math::
  7805. A = LL^T
  7806. If :attr:`upper` is ``True``, and :math:`A` is a batch of symmetric positive-definite
  7807. matrices, then the returned tensor will be composed of upper-triangular Cholesky factors
  7808. of each of the individual matrices. Similarly, when :attr:`upper` is ``False``, the returned
  7809. tensor will be composed of lower-triangular Cholesky factors of each of the individual
  7810. matrices.
  7811. .. warning::
  7812. :func:`torch.cholesky` is deprecated in favor of :func:`torch.linalg.cholesky`
  7813. and will be removed in a future PyTorch release.
  7814. ``L = torch.cholesky(A)`` should be replaced with
  7815. .. code:: python
  7816. L = torch.linalg.cholesky(A)
  7817. ``U = torch.cholesky(A, upper=True)`` should be replaced with
  7818. .. code:: python
  7819. U = torch.linalg.cholesky(A).mH
  7820. This transform will produce equivalent results for all valid (symmetric positive definite) inputs.
  7821. Args:
  7822. input (Tensor): the input tensor :math:`A` of size :math:`(*, n, n)` where `*` is zero or more
  7823. batch dimensions consisting of symmetric positive-definite matrices.
  7824. upper (bool, optional): flag that indicates whether to return a
  7825. upper or lower triangular matrix. Default: ``False``
  7826. Keyword args:
  7827. out (Tensor, optional): the output matrix
  7828. Example::
  7829. >>> a = torch.randn(3, 3)
  7830. >>> a = a @ a.mT + 1e-3 # make symmetric positive-definite
  7831. >>> l = torch.cholesky(a)
  7832. >>> a
  7833. tensor([[ 2.4112, -0.7486, 1.4551],
  7834. [-0.7486, 1.3544, 0.1294],
  7835. [ 1.4551, 0.1294, 1.6724]])
  7836. >>> l
  7837. tensor([[ 1.5528, 0.0000, 0.0000],
  7838. [-0.4821, 1.0592, 0.0000],
  7839. [ 0.9371, 0.5487, 0.7023]])
  7840. >>> l @ l.mT
  7841. tensor([[ 2.4112, -0.7486, 1.4551],
  7842. [-0.7486, 1.3544, 0.1294],
  7843. [ 1.4551, 0.1294, 1.6724]])
  7844. >>> a = torch.randn(3, 2, 2) # Example for batched input
  7845. >>> a = a @ a.mT + 1e-03 # make symmetric positive-definite
  7846. >>> l = torch.cholesky(a)
  7847. >>> z = l @ l.mT
  7848. >>> torch.dist(z, a)
  7849. tensor(2.3842e-07)
  7850. """
  7851. def cholesky_inverse(
  7852. input: Tensor,
  7853. upper: _bool = False,
  7854. *,
  7855. out: Tensor | None = None,
  7856. ) -> Tensor:
  7857. r"""
  7858. cholesky_inverse(L, upper=False, *, out=None) -> Tensor
  7859. Computes the inverse of a complex Hermitian or real symmetric
  7860. positive-definite matrix given its Cholesky decomposition.
  7861. Let :math:`A` be a complex Hermitian or real symmetric positive-definite matrix,
  7862. and :math:`L` its Cholesky decomposition such that:
  7863. .. math::
  7864. A = LL^{\text{H}}
  7865. where :math:`L^{\text{H}}` is the conjugate transpose when :math:`L` is complex,
  7866. and the transpose when :math:`L` is real-valued.
  7867. Computes the inverse matrix :math:`A^{-1}`.
  7868. Supports input of float, double, cfloat and cdouble dtypes.
  7869. Also supports batches of matrices, and if :math:`A` is a batch of matrices
  7870. then the output has the same batch dimensions.
  7871. Args:
  7872. L (Tensor): tensor of shape `(*, n, n)` where `*` is zero or more batch dimensions
  7873. consisting of lower or upper triangular Cholesky decompositions of
  7874. symmetric or Hermitian positive-definite matrices.
  7875. upper (bool, optional): flag that indicates whether :math:`L` is lower triangular
  7876. or upper triangular. Default: ``False``
  7877. Keyword args:
  7878. out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
  7879. Example::
  7880. >>> A = torch.randn(3, 3)
  7881. >>> A = A @ A.T + torch.eye(3) * 1e-3 # Creates a symmetric positive-definite matrix
  7882. >>> L = torch.linalg.cholesky(A) # Extract Cholesky decomposition
  7883. >>> torch.cholesky_inverse(L)
  7884. tensor([[ 1.9314, 1.2251, -0.0889],
  7885. [ 1.2251, 2.4439, 0.2122],
  7886. [-0.0889, 0.2122, 0.1412]])
  7887. >>> A.inverse()
  7888. tensor([[ 1.9314, 1.2251, -0.0889],
  7889. [ 1.2251, 2.4439, 0.2122],
  7890. [-0.0889, 0.2122, 0.1412]])
  7891. >>> A = torch.randn(3, 2, 2, dtype=torch.complex64)
  7892. >>> A = A @ A.mH + torch.eye(2) * 1e-3 # Batch of Hermitian positive-definite matrices
  7893. >>> L = torch.linalg.cholesky(A)
  7894. >>> torch.dist(torch.inverse(A), torch.cholesky_inverse(L))
  7895. tensor(5.6358e-7)
  7896. """
  7897. def cholesky_solve(
  7898. input: Tensor,
  7899. input2: Tensor,
  7900. upper: _bool = False,
  7901. *,
  7902. out: Tensor | None = None,
  7903. ) -> Tensor:
  7904. r"""
  7905. cholesky_solve(B, L, upper=False, *, out=None) -> Tensor
  7906. Computes the solution of a system of linear equations with complex Hermitian
  7907. or real symmetric positive-definite lhs given its Cholesky decomposition.
  7908. Let :math:`A` be a complex Hermitian or real symmetric positive-definite matrix,
  7909. and :math:`L` its Cholesky decomposition such that:
  7910. .. math::
  7911. A = LL^{\text{H}}
  7912. where :math:`L^{\text{H}}` is the conjugate transpose when :math:`L` is complex,
  7913. and the transpose when :math:`L` is real-valued.
  7914. Returns the solution :math:`X` of the following linear system:
  7915. .. math::
  7916. AX = B
  7917. Supports inputs of float, double, cfloat and cdouble dtypes.
  7918. Also supports batches of matrices, and if :math:`A` or :math:`B` is a batch of matrices
  7919. then the output has the same batch dimensions.
  7920. Args:
  7921. B (Tensor): right-hand side tensor of shape `(*, n, k)`
  7922. where :math:`*` is zero or more batch dimensions
  7923. L (Tensor): tensor of shape `(*, n, n)` where `*` is zero or more batch dimensions
  7924. consisting of lower or upper triangular Cholesky decompositions of
  7925. symmetric or Hermitian positive-definite matrices.
  7926. upper (bool, optional): flag that indicates whether :math:`L` is lower triangular
  7927. or upper triangular. Default: ``False``.
  7928. Keyword args:
  7929. out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
  7930. Example::
  7931. >>> A = torch.randn(3, 3)
  7932. >>> A = A @ A.T + torch.eye(3) * 1e-3 # Creates a symmetric positive-definite matrix
  7933. >>> L = torch.linalg.cholesky(A) # Extract Cholesky decomposition
  7934. >>> B = torch.randn(3, 2)
  7935. >>> torch.cholesky_solve(B, L)
  7936. tensor([[ -8.1625, 19.6097],
  7937. [ -5.8398, 14.2387],
  7938. [ -4.3771, 10.4173]])
  7939. >>> A.inverse() @ B
  7940. tensor([[ -8.1626, 19.6097],
  7941. [ -5.8398, 14.2387],
  7942. [ -4.3771, 10.4173]])
  7943. >>> A = torch.randn(3, 2, 2, dtype=torch.complex64)
  7944. >>> A = A @ A.mH + torch.eye(2) * 1e-3 # Batch of Hermitian positive-definite matrices
  7945. >>> L = torch.linalg.cholesky(A)
  7946. >>> B = torch.randn(2, 1, dtype=torch.complex64)
  7947. >>> X = torch.cholesky_solve(B, L)
  7948. >>> torch.dist(X, A.inverse() @ B)
  7949. tensor(1.6881e-5)
  7950. """
  7951. def choose_qparams_optimized(
  7952. input: Tensor,
  7953. numel: _int,
  7954. n_bins: _int,
  7955. ratio: _float,
  7956. bit_width: _int,
  7957. ) -> tuple[Tensor, Tensor]: ...
  7958. def chunk(input: Tensor, chunks: _int, dim: _int = 0) -> tuple[Tensor, ...]:
  7959. r"""
  7960. chunk(input: Tensor, chunks: int, dim: int = 0) -> Tuple[Tensor, ...]
  7961. Attempts to split a tensor into the specified number of chunks. Each chunk is a view of
  7962. the input tensor.
  7963. .. note::
  7964. This function may return fewer than the specified number of chunks!
  7965. .. seealso::
  7966. :func:`torch.tensor_split` a function that always returns exactly the specified number of chunks
  7967. If the tensor size along the given dimension :attr:`dim` is divisible by :attr:`chunks`,
  7968. all returned chunks will be the same size.
  7969. If the tensor size along the given dimension :attr:`dim` is not divisible by :attr:`chunks`,
  7970. all returned chunks will be the same size, except the last one.
  7971. If such division is not possible, this function may return fewer
  7972. than the specified number of chunks.
  7973. Arguments:
  7974. input (Tensor): the tensor to split
  7975. chunks (int): number of chunks to return
  7976. dim (int): dimension along which to split the tensor
  7977. Example:
  7978. >>> torch.arange(11).chunk(6)
  7979. (tensor([0, 1]),
  7980. tensor([2, 3]),
  7981. tensor([4, 5]),
  7982. tensor([6, 7]),
  7983. tensor([8, 9]),
  7984. tensor([10]))
  7985. >>> torch.arange(12).chunk(6)
  7986. (tensor([0, 1]),
  7987. tensor([2, 3]),
  7988. tensor([4, 5]),
  7989. tensor([6, 7]),
  7990. tensor([8, 9]),
  7991. tensor([10, 11]))
  7992. >>> torch.arange(13).chunk(6)
  7993. (tensor([0, 1, 2]),
  7994. tensor([3, 4, 5]),
  7995. tensor([6, 7, 8]),
  7996. tensor([ 9, 10, 11]),
  7997. tensor([12]))
  7998. """
  7999. @overload
  8000. def clamp(
  8001. input: Tensor,
  8002. min: Tensor | None = None,
  8003. max: Tensor | None = None,
  8004. *,
  8005. out: Tensor | None = None,
  8006. ) -> Tensor:
  8007. r"""
  8008. clamp(input, min=None, max=None, *, out=None) -> Tensor
  8009. Clamps all elements in :attr:`input` into the range `[` :attr:`min`, :attr:`max` `]`.
  8010. Letting min_value and max_value be :attr:`min` and :attr:`max`, respectively, this returns:
  8011. .. math::
  8012. y_i = \min(\max(x_i, \text{min\_value}_i), \text{max\_value}_i)
  8013. If :attr:`min` is ``None``, there is no lower bound.
  8014. Or, if :attr:`max` is ``None`` there is no upper bound.
  8015. .. note::
  8016. If :attr:`min` is greater than :attr:`max` :func:`torch.clamp(..., min, max) <torch.clamp>`
  8017. sets all elements in :attr:`input` to the value of :attr:`max`.
  8018. Args:
  8019. input (Tensor): the input tensor.
  8020. min (Number or Tensor, optional): lower-bound of the range to be clamped to
  8021. max (Number or Tensor, optional): upper-bound of the range to be clamped to
  8022. Keyword args:
  8023. out (Tensor, optional): the output tensor.
  8024. Example::
  8025. >>> a = torch.randn(4)
  8026. >>> a
  8027. tensor([-1.7120, 0.1734, -0.0478, -0.0922])
  8028. >>> torch.clamp(a, min=-0.5, max=0.5)
  8029. tensor([-0.5000, 0.1734, -0.0478, -0.0922])
  8030. >>> min = torch.linspace(-1, 1, steps=4)
  8031. >>> torch.clamp(a, min=min)
  8032. tensor([-1.0000, 0.1734, 0.3333, 1.0000])
  8033. """
  8034. @overload
  8035. def clamp(
  8036. input: Tensor,
  8037. min: Number | _complex | None = None,
  8038. max: Number | _complex | None = None,
  8039. *,
  8040. out: Tensor | None = None,
  8041. ) -> Tensor:
  8042. r"""
  8043. clamp(input, min=None, max=None, *, out=None) -> Tensor
  8044. Clamps all elements in :attr:`input` into the range `[` :attr:`min`, :attr:`max` `]`.
  8045. Letting min_value and max_value be :attr:`min` and :attr:`max`, respectively, this returns:
  8046. .. math::
  8047. y_i = \min(\max(x_i, \text{min\_value}_i), \text{max\_value}_i)
  8048. If :attr:`min` is ``None``, there is no lower bound.
  8049. Or, if :attr:`max` is ``None`` there is no upper bound.
  8050. .. note::
  8051. If :attr:`min` is greater than :attr:`max` :func:`torch.clamp(..., min, max) <torch.clamp>`
  8052. sets all elements in :attr:`input` to the value of :attr:`max`.
  8053. Args:
  8054. input (Tensor): the input tensor.
  8055. min (Number or Tensor, optional): lower-bound of the range to be clamped to
  8056. max (Number or Tensor, optional): upper-bound of the range to be clamped to
  8057. Keyword args:
  8058. out (Tensor, optional): the output tensor.
  8059. Example::
  8060. >>> a = torch.randn(4)
  8061. >>> a
  8062. tensor([-1.7120, 0.1734, -0.0478, -0.0922])
  8063. >>> torch.clamp(a, min=-0.5, max=0.5)
  8064. tensor([-0.5000, 0.1734, -0.0478, -0.0922])
  8065. >>> min = torch.linspace(-1, 1, steps=4)
  8066. >>> torch.clamp(a, min=min)
  8067. tensor([-1.0000, 0.1734, 0.3333, 1.0000])
  8068. """
  8069. @overload
  8070. def clamp_(
  8071. input: Tensor,
  8072. min: Tensor | None = None,
  8073. max: Tensor | None = None,
  8074. ) -> Tensor: ...
  8075. @overload
  8076. def clamp_(
  8077. input: Tensor,
  8078. min: Number | _complex | None = None,
  8079. max: Number | _complex | None = None,
  8080. ) -> Tensor: ...
  8081. @overload
  8082. def clamp_max(
  8083. input: Tensor,
  8084. max: Tensor,
  8085. *,
  8086. out: Tensor | None = None,
  8087. ) -> Tensor: ...
  8088. @overload
  8089. def clamp_max(
  8090. input: Tensor,
  8091. max: Number | _complex,
  8092. *,
  8093. out: Tensor | None = None,
  8094. ) -> Tensor: ...
  8095. @overload
  8096. def clamp_max_(input: Tensor, max: Tensor) -> Tensor: ...
  8097. @overload
  8098. def clamp_max_(input: Tensor, max: Number | _complex) -> Tensor: ...
  8099. @overload
  8100. def clamp_min(
  8101. input: Tensor,
  8102. min: Tensor,
  8103. *,
  8104. out: Tensor | None = None,
  8105. ) -> Tensor: ...
  8106. @overload
  8107. def clamp_min(
  8108. input: Tensor,
  8109. min: Number | _complex,
  8110. *,
  8111. out: Tensor | None = None,
  8112. ) -> Tensor: ...
  8113. @overload
  8114. def clamp_min_(input: Tensor, min: Tensor) -> Tensor: ...
  8115. @overload
  8116. def clamp_min_(input: Tensor, min: Number | _complex) -> Tensor: ...
  8117. @overload
  8118. def clip(
  8119. input: Tensor,
  8120. min: Tensor | None = None,
  8121. max: Tensor | None = None,
  8122. *,
  8123. out: Tensor | None = None,
  8124. ) -> Tensor:
  8125. r"""
  8126. clip(input, min=None, max=None, *, out=None) -> Tensor
  8127. Alias for :func:`torch.clamp`.
  8128. """
  8129. @overload
  8130. def clip(
  8131. input: Tensor,
  8132. min: Number | _complex | None = None,
  8133. max: Number | _complex | None = None,
  8134. *,
  8135. out: Tensor | None = None,
  8136. ) -> Tensor:
  8137. r"""
  8138. clip(input, min=None, max=None, *, out=None) -> Tensor
  8139. Alias for :func:`torch.clamp`.
  8140. """
  8141. @overload
  8142. def clip_(
  8143. input: Tensor,
  8144. min: Tensor | None = None,
  8145. max: Tensor | None = None,
  8146. ) -> Tensor: ...
  8147. @overload
  8148. def clip_(
  8149. input: Tensor,
  8150. min: Number | _complex | None = None,
  8151. max: Number | _complex | None = None,
  8152. ) -> Tensor: ...
  8153. def clone(
  8154. input: Tensor,
  8155. *,
  8156. memory_format: memory_format | None = None,
  8157. ) -> Tensor:
  8158. r"""
  8159. clone(input, *, memory_format=torch.preserve_format) -> Tensor
  8160. Returns a copy of :attr:`input`.
  8161. .. note::
  8162. This function is differentiable, so gradients will flow back from the
  8163. result of this operation to :attr:`input`. To create a tensor without an
  8164. autograd relationship to :attr:`input` see :meth:`~Tensor.detach`.
  8165. In addition, when ``torch.preserve_format`` is used:
  8166. If the input tensor is dense (i.e., non-overlapping strided),
  8167. its memory format (including strides) is retained.
  8168. Otherwise (e.g., a non-dense view like a stepped slice),
  8169. the output is converted to the dense (contiguous) format.
  8170. Args:
  8171. input (Tensor): the input tensor.
  8172. Keyword args:
  8173. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  8174. returned tensor. Default: ``torch.preserve_format``.
  8175. """
  8176. def col_indices_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  8177. r"""
  8178. Performs the same operation as :func:`torch.col_indices`, but all output tensors
  8179. are freshly created instead of aliasing the input.
  8180. """
  8181. def column_stack(
  8182. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  8183. *,
  8184. out: Tensor | None = None,
  8185. ) -> Tensor:
  8186. r"""
  8187. column_stack(tensors, *, out=None) -> Tensor
  8188. Creates a new tensor by horizontally stacking the tensors in :attr:`tensors`.
  8189. Equivalent to ``torch.hstack(tensors)``, except each zero or one dimensional tensor ``t``
  8190. in :attr:`tensors` is first reshaped into a ``(t.numel(), 1)`` column before being stacked horizontally.
  8191. Args:
  8192. tensors (sequence of Tensors): sequence of tensors to concatenate
  8193. Keyword args:
  8194. out (Tensor, optional): the output tensor.
  8195. Example::
  8196. >>> a = torch.tensor([1, 2, 3])
  8197. >>> b = torch.tensor([4, 5, 6])
  8198. >>> torch.column_stack((a, b))
  8199. tensor([[1, 4],
  8200. [2, 5],
  8201. [3, 6]])
  8202. >>> a = torch.arange(5)
  8203. >>> b = torch.arange(10).reshape(5, 2)
  8204. >>> torch.column_stack((a, b, b))
  8205. tensor([[0, 0, 1, 0, 1],
  8206. [1, 2, 3, 2, 3],
  8207. [2, 4, 5, 4, 5],
  8208. [3, 6, 7, 6, 7],
  8209. [4, 8, 9, 8, 9]])
  8210. """
  8211. def combinations(
  8212. input: Tensor,
  8213. r: _int = 2,
  8214. with_replacement: _bool = False,
  8215. ) -> Tensor:
  8216. r"""
  8217. combinations(input: Tensor, r: int = 2, with_replacement: bool = False) -> seq
  8218. Compute combinations of length :math:`r` of the given tensor. The behavior is similar to
  8219. python's `itertools.combinations` when `with_replacement` is set to `False`, and
  8220. `itertools.combinations_with_replacement` when `with_replacement` is set to `True`.
  8221. Arguments:
  8222. input (Tensor): 1D vector.
  8223. r (int, optional): number of elements to combine
  8224. with_replacement (bool, optional): whether to allow duplication in combination
  8225. Returns:
  8226. Tensor: A tensor equivalent to converting all the input tensors into lists, do
  8227. `itertools.combinations` or `itertools.combinations_with_replacement` on these
  8228. lists, and finally convert the resulting list into tensor.
  8229. Example::
  8230. >>> a = [1, 2, 3]
  8231. >>> list(itertools.combinations(a, r=2))
  8232. [(1, 2), (1, 3), (2, 3)]
  8233. >>> list(itertools.combinations(a, r=3))
  8234. [(1, 2, 3)]
  8235. >>> list(itertools.combinations_with_replacement(a, r=2))
  8236. [(1, 1), (1, 2), (1, 3), (2, 2), (2, 3), (3, 3)]
  8237. >>> tensor_a = torch.tensor(a)
  8238. >>> torch.combinations(tensor_a)
  8239. tensor([[1, 2],
  8240. [1, 3],
  8241. [2, 3]])
  8242. >>> torch.combinations(tensor_a, r=3)
  8243. tensor([[1, 2, 3]])
  8244. >>> torch.combinations(tensor_a, with_replacement=True)
  8245. tensor([[1, 1],
  8246. [1, 2],
  8247. [1, 3],
  8248. [2, 2],
  8249. [2, 3],
  8250. [3, 3]])
  8251. """
  8252. def complex(
  8253. real: Tensor,
  8254. imag: Tensor,
  8255. *,
  8256. out: Tensor | None = None,
  8257. ) -> Tensor:
  8258. r"""
  8259. complex(real, imag, *, out=None) -> Tensor
  8260. Constructs a complex tensor with its real part equal to :attr:`real` and its
  8261. imaginary part equal to :attr:`imag`.
  8262. Args:
  8263. real (Tensor): The real part of the complex tensor. Must be half, float or double.
  8264. imag (Tensor): The imaginary part of the complex tensor. Must be same dtype
  8265. as :attr:`real`.
  8266. Keyword args:
  8267. out (Tensor): If the inputs are ``torch.float32``, must be
  8268. ``torch.complex64``. If the inputs are ``torch.float64``, must be
  8269. ``torch.complex128``.
  8270. Example::
  8271. >>> real = torch.tensor([1, 2], dtype=torch.float32)
  8272. >>> imag = torch.tensor([3, 4], dtype=torch.float32)
  8273. >>> z = torch.complex(real, imag)
  8274. >>> z
  8275. tensor([(1.+3.j), (2.+4.j)])
  8276. >>> z.dtype
  8277. torch.complex64
  8278. """
  8279. @overload
  8280. def concat(
  8281. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  8282. dim: _int = 0,
  8283. *,
  8284. out: Tensor | None = None,
  8285. ) -> Tensor:
  8286. r"""
  8287. concat(tensors, dim=0, *, out=None) -> Tensor
  8288. Alias of :func:`torch.cat`.
  8289. """
  8290. @overload
  8291. def concat(
  8292. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  8293. dim: str | EllipsisType | None,
  8294. *,
  8295. out: Tensor | None = None,
  8296. ) -> Tensor:
  8297. r"""
  8298. concat(tensors, dim=0, *, out=None) -> Tensor
  8299. Alias of :func:`torch.cat`.
  8300. """
  8301. @overload
  8302. def concatenate(
  8303. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  8304. dim: _int = 0,
  8305. *,
  8306. out: Tensor | None = None,
  8307. ) -> Tensor:
  8308. r"""
  8309. concatenate(tensors, axis=0, out=None) -> Tensor
  8310. Alias of :func:`torch.cat`.
  8311. """
  8312. @overload
  8313. def concatenate(
  8314. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  8315. dim: str | EllipsisType | None,
  8316. *,
  8317. out: Tensor | None = None,
  8318. ) -> Tensor:
  8319. r"""
  8320. concatenate(tensors, axis=0, out=None) -> Tensor
  8321. Alias of :func:`torch.cat`.
  8322. """
  8323. def conj(input: Tensor) -> Tensor:
  8324. r"""
  8325. conj(input) -> Tensor
  8326. Returns a view of :attr:`input` with a flipped conjugate bit. If :attr:`input` has a non-complex dtype,
  8327. this function just returns :attr:`input`.
  8328. .. note::
  8329. :func:`torch.conj` performs a lazy conjugation, but the actual conjugated tensor can be materialized
  8330. at any time using :func:`torch.resolve_conj`.
  8331. .. warning:: In the future, :func:`torch.conj` may return a non-writeable view for an :attr:`input` of
  8332. non-complex dtype. It's recommended that programs not modify the tensor returned by :func:`torch.conj_physical`
  8333. when :attr:`input` is of non-complex dtype to be compatible with this change.
  8334. Args:
  8335. input (Tensor): the input tensor.
  8336. Example::
  8337. >>> x = torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j])
  8338. >>> x.is_conj()
  8339. False
  8340. >>> y = torch.conj(x)
  8341. >>> y.is_conj()
  8342. True
  8343. """
  8344. def conj_physical(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  8345. r"""
  8346. conj_physical(input, *, out=None) -> Tensor
  8347. Computes the element-wise conjugate of the given :attr:`input` tensor.
  8348. If :attr:`input` has a non-complex dtype, this function just returns :attr:`input`.
  8349. .. note::
  8350. This performs the conjugate operation regardless of the fact conjugate bit is set or not.
  8351. .. warning:: In the future, :func:`torch.conj_physical` may return a non-writeable view for an :attr:`input` of
  8352. non-complex dtype. It's recommended that programs not modify the tensor returned by :func:`torch.conj_physical`
  8353. when :attr:`input` is of non-complex dtype to be compatible with this change.
  8354. .. math::
  8355. \text{out}_{i} = conj(\text{input}_{i})
  8356. Args:
  8357. input (Tensor): the input tensor.
  8358. Keyword args:
  8359. out (Tensor, optional): the output tensor.
  8360. Example::
  8361. >>> torch.conj_physical(torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j]))
  8362. tensor([-1 - 1j, -2 - 2j, 3 + 3j])
  8363. """
  8364. def conj_physical_(input: Tensor) -> Tensor: ...
  8365. def constant_pad_nd(
  8366. input: Tensor,
  8367. pad: Sequence[_int | SymInt],
  8368. value: Number | _complex = 0,
  8369. ) -> Tensor: ...
  8370. @overload
  8371. def conv1d(
  8372. input: Tensor,
  8373. weight: Tensor,
  8374. bias: Tensor | None = None,
  8375. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8376. padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8377. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8378. groups: _int | SymInt = 1,
  8379. ) -> Tensor: ...
  8380. @overload
  8381. def conv1d(
  8382. input: Tensor,
  8383. weight: Tensor,
  8384. bias: Tensor | None = None,
  8385. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8386. padding: str = "valid",
  8387. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8388. groups: _int | SymInt = 1,
  8389. ) -> Tensor: ...
  8390. @overload
  8391. def conv2d(
  8392. input: Tensor,
  8393. weight: Tensor,
  8394. bias: Tensor | None = None,
  8395. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8396. padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8397. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8398. groups: _int | SymInt = 1,
  8399. ) -> Tensor: ...
  8400. @overload
  8401. def conv2d(
  8402. input: Tensor,
  8403. weight: Tensor,
  8404. bias: Tensor | None = None,
  8405. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8406. padding: str = "valid",
  8407. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8408. groups: _int | SymInt = 1,
  8409. ) -> Tensor: ...
  8410. @overload
  8411. def conv3d(
  8412. input: Tensor,
  8413. weight: Tensor,
  8414. bias: Tensor | None = None,
  8415. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8416. padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8417. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8418. groups: _int | SymInt = 1,
  8419. ) -> Tensor: ...
  8420. @overload
  8421. def conv3d(
  8422. input: Tensor,
  8423. weight: Tensor,
  8424. bias: Tensor | None = None,
  8425. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8426. padding: str = "valid",
  8427. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8428. groups: _int | SymInt = 1,
  8429. ) -> Tensor: ...
  8430. def conv_tbc(
  8431. input: Tensor,
  8432. weight: Tensor,
  8433. bias: Tensor,
  8434. pad: _int = 0,
  8435. ) -> Tensor: ...
  8436. def conv_transpose1d(
  8437. input: Tensor,
  8438. weight: Tensor,
  8439. bias: Tensor | None = None,
  8440. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8441. padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8442. output_padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8443. groups: _int | SymInt = 1,
  8444. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8445. ) -> Tensor: ...
  8446. def conv_transpose2d(
  8447. input: Tensor,
  8448. weight: Tensor,
  8449. bias: Tensor | None = None,
  8450. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8451. padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8452. output_padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8453. groups: _int | SymInt = 1,
  8454. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8455. ) -> Tensor: ...
  8456. def conv_transpose3d(
  8457. input: Tensor,
  8458. weight: Tensor,
  8459. bias: Tensor | None = None,
  8460. stride: _int | SymInt | Sequence[_int | SymInt] = 1,
  8461. padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8462. output_padding: _int | SymInt | Sequence[_int | SymInt] = 0,
  8463. groups: _int | SymInt = 1,
  8464. dilation: _int | SymInt | Sequence[_int | SymInt] = 1,
  8465. ) -> Tensor: ...
  8466. def convolution(
  8467. input: Tensor,
  8468. weight: Tensor,
  8469. bias: Tensor | None,
  8470. stride: Sequence[_int | SymInt],
  8471. padding: Sequence[_int | SymInt],
  8472. dilation: Sequence[_int | SymInt],
  8473. transposed: _bool,
  8474. output_padding: Sequence[_int | SymInt],
  8475. groups: _int | SymInt,
  8476. ) -> Tensor: ...
  8477. @overload
  8478. def copysign(
  8479. input: Tensor,
  8480. other: Tensor,
  8481. *,
  8482. out: Tensor | None = None,
  8483. ) -> Tensor:
  8484. r"""
  8485. copysign(input, other, *, out=None) -> Tensor
  8486. Create a new floating-point tensor with the magnitude of :attr:`input` and the sign of :attr:`other`, elementwise.
  8487. .. math::
  8488. \text{out}_{i} = \begin{cases}
  8489. -|\text{input}_{i}| & \text{if } \text{other}_{i} \leq -0.0 \\
  8490. |\text{input}_{i}| & \text{if } \text{other}_{i} \geq 0.0 \\
  8491. \end{cases}
  8492. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  8493. and integer and float inputs.
  8494. Args:
  8495. input (Tensor): magnitudes.
  8496. other (Tensor or Number): contains value(s) whose signbit(s) are
  8497. applied to the magnitudes in :attr:`input`.
  8498. Keyword args:
  8499. out (Tensor, optional): the output tensor.
  8500. Example::
  8501. >>> a = torch.randn(5)
  8502. >>> a
  8503. tensor([-1.2557, -0.0026, -0.5387, 0.4740, -0.9244])
  8504. >>> torch.copysign(a, 1)
  8505. tensor([1.2557, 0.0026, 0.5387, 0.4740, 0.9244])
  8506. >>> a = torch.randn(4, 4)
  8507. >>> a
  8508. tensor([[ 0.7079, 0.2778, -1.0249, 0.5719],
  8509. [-0.0059, -0.2600, -0.4475, -1.3948],
  8510. [ 0.3667, -0.9567, -2.5757, -0.1751],
  8511. [ 0.2046, -0.0742, 0.2998, -0.1054]])
  8512. >>> b = torch.randn(4)
  8513. tensor([ 0.2373, 0.3120, 0.3190, -1.1128])
  8514. >>> torch.copysign(a, b)
  8515. tensor([[ 0.7079, 0.2778, 1.0249, -0.5719],
  8516. [ 0.0059, 0.2600, 0.4475, -1.3948],
  8517. [ 0.3667, 0.9567, 2.5757, -0.1751],
  8518. [ 0.2046, 0.0742, 0.2998, -0.1054]])
  8519. >>> a = torch.tensor([1.])
  8520. >>> b = torch.tensor([-0.])
  8521. >>> torch.copysign(a, b)
  8522. tensor([-1.])
  8523. .. note::
  8524. copysign handles signed zeros. If the other argument has a negative zero (-0),
  8525. the corresponding output value will be negative.
  8526. """
  8527. @overload
  8528. def copysign(
  8529. input: Tensor,
  8530. other: Number | _complex,
  8531. *,
  8532. out: Tensor | None = None,
  8533. ) -> Tensor:
  8534. r"""
  8535. copysign(input, other, *, out=None) -> Tensor
  8536. Create a new floating-point tensor with the magnitude of :attr:`input` and the sign of :attr:`other`, elementwise.
  8537. .. math::
  8538. \text{out}_{i} = \begin{cases}
  8539. -|\text{input}_{i}| & \text{if } \text{other}_{i} \leq -0.0 \\
  8540. |\text{input}_{i}| & \text{if } \text{other}_{i} \geq 0.0 \\
  8541. \end{cases}
  8542. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  8543. and integer and float inputs.
  8544. Args:
  8545. input (Tensor): magnitudes.
  8546. other (Tensor or Number): contains value(s) whose signbit(s) are
  8547. applied to the magnitudes in :attr:`input`.
  8548. Keyword args:
  8549. out (Tensor, optional): the output tensor.
  8550. Example::
  8551. >>> a = torch.randn(5)
  8552. >>> a
  8553. tensor([-1.2557, -0.0026, -0.5387, 0.4740, -0.9244])
  8554. >>> torch.copysign(a, 1)
  8555. tensor([1.2557, 0.0026, 0.5387, 0.4740, 0.9244])
  8556. >>> a = torch.randn(4, 4)
  8557. >>> a
  8558. tensor([[ 0.7079, 0.2778, -1.0249, 0.5719],
  8559. [-0.0059, -0.2600, -0.4475, -1.3948],
  8560. [ 0.3667, -0.9567, -2.5757, -0.1751],
  8561. [ 0.2046, -0.0742, 0.2998, -0.1054]])
  8562. >>> b = torch.randn(4)
  8563. tensor([ 0.2373, 0.3120, 0.3190, -1.1128])
  8564. >>> torch.copysign(a, b)
  8565. tensor([[ 0.7079, 0.2778, 1.0249, -0.5719],
  8566. [ 0.0059, 0.2600, 0.4475, -1.3948],
  8567. [ 0.3667, 0.9567, 2.5757, -0.1751],
  8568. [ 0.2046, 0.0742, 0.2998, -0.1054]])
  8569. >>> a = torch.tensor([1.])
  8570. >>> b = torch.tensor([-0.])
  8571. >>> torch.copysign(a, b)
  8572. tensor([-1.])
  8573. .. note::
  8574. copysign handles signed zeros. If the other argument has a negative zero (-0),
  8575. the corresponding output value will be negative.
  8576. """
  8577. def corrcoef(input: Tensor) -> Tensor:
  8578. r"""
  8579. corrcoef(input) -> Tensor
  8580. Estimates the Pearson product-moment correlation coefficient matrix of the variables given by the :attr:`input` matrix,
  8581. where rows are the variables and columns are the observations.
  8582. .. note::
  8583. The correlation coefficient matrix R is computed using the covariance matrix C as given by
  8584. :math:`R_{ij} = \frac{ C_{ij} } { \sqrt{ C_{ii} * C_{jj} } }`
  8585. .. note::
  8586. Due to floating point rounding, the resulting array may not be Hermitian and its diagonal elements may not be 1.
  8587. The real and imaginary values are clipped to the interval [-1, 1] in an attempt to improve this situation.
  8588. Args:
  8589. input (Tensor): A 2D matrix containing multiple variables and observations, or a
  8590. Scalar or 1D vector representing a single variable.
  8591. Returns:
  8592. (Tensor) The correlation coefficient matrix of the variables.
  8593. .. seealso::
  8594. :func:`torch.cov` covariance matrix.
  8595. Example::
  8596. >>> x = torch.tensor([[0, 1, 2], [2, 1, 0]])
  8597. >>> torch.corrcoef(x)
  8598. tensor([[ 1., -1.],
  8599. [-1., 1.]])
  8600. >>> x = torch.randn(2, 4)
  8601. >>> x
  8602. tensor([[-0.2678, -0.0908, -0.3766, 0.2780],
  8603. [-0.5812, 0.1535, 0.2387, 0.2350]])
  8604. >>> torch.corrcoef(x)
  8605. tensor([[1.0000, 0.3582],
  8606. [0.3582, 1.0000]])
  8607. >>> torch.corrcoef(x[0])
  8608. tensor(1.)
  8609. """
  8610. def cos(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  8611. r"""
  8612. cos(input, *, out=None) -> Tensor
  8613. Returns a new tensor with the cosine of the elements of :attr:`input` given in radians.
  8614. .. math::
  8615. \text{out}_{i} = \cos(\text{input}_{i})
  8616. Args:
  8617. input (Tensor): the input tensor.
  8618. Keyword args:
  8619. out (Tensor, optional): the output tensor.
  8620. Example::
  8621. >>> a = torch.randn(4)
  8622. >>> a
  8623. tensor([ 1.4309, 1.2706, -0.8562, 0.9796])
  8624. >>> torch.cos(a)
  8625. tensor([ 0.1395, 0.2957, 0.6553, 0.5574])
  8626. """
  8627. def cos_(input: Tensor) -> Tensor: ...
  8628. def cosh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  8629. r"""
  8630. cosh(input, *, out=None) -> Tensor
  8631. Returns a new tensor with the hyperbolic cosine of the elements of
  8632. :attr:`input`.
  8633. .. math::
  8634. \text{out}_{i} = \cosh(\text{input}_{i})
  8635. Args:
  8636. input (Tensor): the input tensor.
  8637. Keyword args:
  8638. out (Tensor, optional): the output tensor.
  8639. Example::
  8640. >>> a = torch.randn(4)
  8641. >>> a
  8642. tensor([ 0.1632, 1.1835, -0.6979, -0.7325])
  8643. >>> torch.cosh(a)
  8644. tensor([ 1.0133, 1.7860, 1.2536, 1.2805])
  8645. .. note::
  8646. When :attr:`input` is on the CPU, the implementation of torch.cosh may use
  8647. the Sleef library, which rounds very large results to infinity or negative
  8648. infinity. See `here <https://sleef.org/purec.xhtml>`_ for details.
  8649. """
  8650. def cosh_(input: Tensor) -> Tensor: ...
  8651. def cosine_embedding_loss(
  8652. input1: Tensor,
  8653. input2: Tensor,
  8654. target: Tensor,
  8655. margin: _float = 0.0,
  8656. reduction: _int = 1,
  8657. ) -> Tensor: ...
  8658. def cosine_similarity(
  8659. x1: Tensor,
  8660. x2: Tensor,
  8661. dim: _int = 1,
  8662. eps: _float = 1e-08,
  8663. ) -> Tensor: ...
  8664. @overload
  8665. def count_nonzero(input: Tensor, dim: _int | None = None) -> Tensor:
  8666. r"""
  8667. count_nonzero(input, dim=None) -> Tensor
  8668. Counts the number of non-zero values in the tensor :attr:`input` along the given :attr:`dim`.
  8669. If no dim is specified then all non-zeros in the tensor are counted.
  8670. Args:
  8671. input (Tensor): the input tensor.
  8672. dim (int or tuple of ints, optional): Dim or tuple of dims along which to count non-zeros.
  8673. Example::
  8674. >>> x = torch.zeros(3,3)
  8675. >>> x[torch.randn(3,3) > 0.5] = 1
  8676. >>> x
  8677. tensor([[0., 1., 1.],
  8678. [0., 0., 0.],
  8679. [0., 0., 1.]])
  8680. >>> torch.count_nonzero(x)
  8681. tensor(3)
  8682. >>> torch.count_nonzero(x, dim=0)
  8683. tensor([0, 1, 2])
  8684. """
  8685. @overload
  8686. def count_nonzero(input: Tensor, dim: _size) -> Tensor:
  8687. r"""
  8688. count_nonzero(input, dim=None) -> Tensor
  8689. Counts the number of non-zero values in the tensor :attr:`input` along the given :attr:`dim`.
  8690. If no dim is specified then all non-zeros in the tensor are counted.
  8691. Args:
  8692. input (Tensor): the input tensor.
  8693. dim (int or tuple of ints, optional): Dim or tuple of dims along which to count non-zeros.
  8694. Example::
  8695. >>> x = torch.zeros(3,3)
  8696. >>> x[torch.randn(3,3) > 0.5] = 1
  8697. >>> x
  8698. tensor([[0., 1., 1.],
  8699. [0., 0., 0.],
  8700. [0., 0., 1.]])
  8701. >>> torch.count_nonzero(x)
  8702. tensor(3)
  8703. >>> torch.count_nonzero(x, dim=0)
  8704. tensor([0, 1, 2])
  8705. """
  8706. def cov(
  8707. input: Tensor,
  8708. *,
  8709. correction: _int = 1,
  8710. fweights: Tensor | None = None,
  8711. aweights: Tensor | None = None,
  8712. ) -> Tensor:
  8713. r"""
  8714. cov(input, *, correction=1, fweights=None, aweights=None) -> Tensor
  8715. Estimates the covariance matrix of the variables given by the :attr:`input` matrix, where rows are
  8716. the variables and columns are the observations.
  8717. A covariance matrix is a square matrix giving the covariance of each pair of variables. The diagonal contains
  8718. the variance of each variable (covariance of a variable with itself). By definition, if :attr:`input` represents
  8719. a single variable (Scalar or 1D) then its variance is returned.
  8720. The sample covariance of the variables :math:`x` and :math:`y` is given by:
  8721. .. math::
  8722. \text{cov}(x,y) = \frac{\sum^{N}_{i = 1}(x_{i} - \bar{x})(y_{i} - \bar{y})}{\max(0,~N~-~\delta N)}
  8723. where :math:`\bar{x}` and :math:`\bar{y}` are the simple means of the :math:`x` and :math:`y` respectively, and
  8724. :math:`\delta N` is the :attr:`correction`.
  8725. If :attr:`fweights` and/or :attr:`aweights` are provided, the weighted covariance
  8726. is calculated, which is given by:
  8727. .. math::
  8728. \text{cov}_w(x,y) = \frac{\sum^{N}_{i = 1}w_i(x_{i} - \mu_x^*)(y_{i} - \mu_y^*)}
  8729. {\max(0,~\sum^{N}_{i = 1}w_i~-~\frac{\sum^{N}_{i = 1}w_ia_i}{\sum^{N}_{i = 1}w_i}~\delta N)}
  8730. where :math:`w` denotes :attr:`fweights` or :attr:`aweights` (``f`` and ``a`` for brevity) based on whichever is
  8731. provided, or :math:`w = f \times a` if both are provided, and
  8732. :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
  8733. provided, ``f`` and/or ``a`` can be seen as a :math:`\mathbb{1}` vector of appropriate size.
  8734. Args:
  8735. input (Tensor): A 2D matrix containing multiple variables and observations, or a
  8736. Scalar or 1D vector representing a single variable.
  8737. Keyword Args:
  8738. correction (int, optional): difference between the sample size and sample degrees of freedom.
  8739. Defaults to Bessel's correction, ``correction = 1`` which returns the unbiased estimate,
  8740. even if both :attr:`fweights` and :attr:`aweights` are specified. ``correction = 0``
  8741. will return the simple average. Defaults to ``1``.
  8742. fweights (tensor, optional): A Scalar or 1D tensor of observation vector frequencies representing the number of
  8743. times each observation should be repeated. Its numel must equal the number of columns of :attr:`input`.
  8744. Must have integral dtype. Ignored if ``None``. Defaults to ``None``.
  8745. aweights (tensor, optional): A Scalar or 1D array of observation vector weights.
  8746. These relative weights are typically large for observations considered "important" and smaller for
  8747. observations considered less "important". Its numel must equal the number of columns of :attr:`input`.
  8748. Must have floating point dtype. Ignored if ``None``. Defaults to ``None``.
  8749. Returns:
  8750. (Tensor) The covariance matrix of the variables.
  8751. .. seealso::
  8752. :func:`torch.corrcoef` normalized covariance matrix.
  8753. Example::
  8754. >>> x = torch.tensor([[0, 2], [1, 1], [2, 0]]).T
  8755. >>> x
  8756. tensor([[0, 1, 2],
  8757. [2, 1, 0]])
  8758. >>> torch.cov(x)
  8759. tensor([[ 1., -1.],
  8760. [-1., 1.]])
  8761. >>> torch.cov(x, correction=0)
  8762. tensor([[ 0.6667, -0.6667],
  8763. [-0.6667, 0.6667]])
  8764. >>> fw = torch.randint(1, 10, (3,))
  8765. >>> fw
  8766. tensor([1, 6, 9])
  8767. >>> aw = torch.rand(3)
  8768. >>> aw
  8769. tensor([0.4282, 0.0255, 0.4144])
  8770. >>> torch.cov(x, fweights=fw, aweights=aw)
  8771. tensor([[ 0.4169, -0.4169],
  8772. [-0.4169, 0.4169]])
  8773. """
  8774. def cross(
  8775. input: Tensor,
  8776. other: Tensor,
  8777. dim: _int | None = None,
  8778. *,
  8779. out: Tensor | None = None,
  8780. ) -> Tensor:
  8781. r"""
  8782. cross(input, other, dim=None, *, out=None) -> Tensor
  8783. Returns the cross product of vectors in dimension :attr:`dim` of :attr:`input`
  8784. and :attr:`other`.
  8785. Supports input of float, double, cfloat and cdouble dtypes. Also supports batches
  8786. of vectors, for which it computes the product along the dimension :attr:`dim`.
  8787. In this case, the output has the same batch dimensions as the inputs.
  8788. .. warning::
  8789. If :attr:`dim` is not given, it defaults to the first dimension found
  8790. with the size 3. Note that this might be unexpected.
  8791. This behavior is deprecated and will be changed to match that of :func:`torch.linalg.cross`
  8792. in a future release.
  8793. .. seealso::
  8794. :func:`torch.linalg.cross` which has dim=-1 as default.
  8795. Args:
  8796. input (Tensor): the input tensor.
  8797. other (Tensor): the second input tensor
  8798. dim (int, optional): the dimension to take the cross-product in.
  8799. Keyword args:
  8800. out (Tensor, optional): the output tensor.
  8801. Example::
  8802. >>> a = torch.randn(4, 3)
  8803. >>> a
  8804. tensor([[-0.3956, 1.1455, 1.6895],
  8805. [-0.5849, 1.3672, 0.3599],
  8806. [-1.1626, 0.7180, -0.0521],
  8807. [-0.1339, 0.9902, -2.0225]])
  8808. >>> b = torch.randn(4, 3)
  8809. >>> b
  8810. tensor([[-0.0257, -1.4725, -1.2251],
  8811. [-1.1479, -0.7005, -1.9757],
  8812. [-1.3904, 0.3726, -1.1836],
  8813. [-0.9688, -0.7153, 0.2159]])
  8814. >>> torch.cross(a, b, dim=1)
  8815. tensor([[ 1.0844, -0.5281, 0.6120],
  8816. [-2.4490, -1.5687, 1.9792],
  8817. [-0.8304, -1.3037, 0.5650],
  8818. [-1.2329, 1.9883, 1.0551]])
  8819. >>> torch.cross(a, b)
  8820. tensor([[ 1.0844, -0.5281, 0.6120],
  8821. [-2.4490, -1.5687, 1.9792],
  8822. [-0.8304, -1.3037, 0.5650],
  8823. [-1.2329, 1.9883, 1.0551]])
  8824. """
  8825. def crow_indices_copy(
  8826. input: Tensor,
  8827. *,
  8828. out: Tensor | None = None,
  8829. ) -> Tensor:
  8830. r"""
  8831. Performs the same operation as :func:`torch.crow_indices`, but all output tensors
  8832. are freshly created instead of aliasing the input.
  8833. """
  8834. @overload
  8835. def ctc_loss(
  8836. log_probs: Tensor,
  8837. targets: Tensor,
  8838. input_lengths: _size,
  8839. target_lengths: _size,
  8840. blank: _int = 0,
  8841. reduction: _int = 1,
  8842. zero_infinity: _bool = False,
  8843. ) -> Tensor: ...
  8844. @overload
  8845. def ctc_loss(
  8846. log_probs: Tensor,
  8847. targets: Tensor,
  8848. input_lengths: Tensor,
  8849. target_lengths: Tensor,
  8850. blank: _int = 0,
  8851. reduction: _int = 1,
  8852. zero_infinity: _bool = False,
  8853. ) -> Tensor: ...
  8854. def cudnn_affine_grid_generator(
  8855. theta: Tensor,
  8856. N: _int,
  8857. C: _int,
  8858. H: _int,
  8859. W: _int,
  8860. ) -> Tensor: ...
  8861. def cudnn_batch_norm(
  8862. input: Tensor,
  8863. weight: Tensor,
  8864. bias: Tensor | None,
  8865. running_mean: Tensor | None,
  8866. running_var: Tensor | None,
  8867. training: _bool,
  8868. exponential_average_factor: _float,
  8869. epsilon: _float,
  8870. *,
  8871. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  8872. ) -> tuple[Tensor, Tensor, Tensor, Tensor]: ...
  8873. def cudnn_convolution(
  8874. input: Tensor,
  8875. weight: Tensor,
  8876. padding: Sequence[_int | SymInt],
  8877. stride: Sequence[_int | SymInt],
  8878. dilation: Sequence[_int | SymInt],
  8879. groups: _int | SymInt,
  8880. benchmark: _bool,
  8881. deterministic: _bool,
  8882. allow_tf32: _bool,
  8883. *,
  8884. out: Tensor | None = None,
  8885. ) -> Tensor: ...
  8886. def cudnn_convolution_add_relu(
  8887. input: Tensor,
  8888. weight: Tensor,
  8889. z: Tensor,
  8890. alpha: Number | _complex | None,
  8891. bias: Tensor | None,
  8892. stride: Sequence[_int | SymInt],
  8893. padding: Sequence[_int | SymInt],
  8894. dilation: Sequence[_int | SymInt],
  8895. groups: _int | SymInt,
  8896. ) -> Tensor: ...
  8897. def cudnn_convolution_relu(
  8898. input: Tensor,
  8899. weight: Tensor,
  8900. bias: Tensor | None,
  8901. stride: Sequence[_int | SymInt],
  8902. padding: Sequence[_int | SymInt],
  8903. dilation: Sequence[_int | SymInt],
  8904. groups: _int | SymInt,
  8905. ) -> Tensor: ...
  8906. def cudnn_convolution_transpose(
  8907. input: Tensor,
  8908. weight: Tensor,
  8909. padding: Sequence[_int | SymInt],
  8910. output_padding: Sequence[_int | SymInt],
  8911. stride: Sequence[_int | SymInt],
  8912. dilation: Sequence[_int | SymInt],
  8913. groups: _int | SymInt,
  8914. benchmark: _bool,
  8915. deterministic: _bool,
  8916. allow_tf32: _bool,
  8917. ) -> Tensor: ...
  8918. def cudnn_grid_sampler(input: Tensor, grid: Tensor) -> Tensor: ...
  8919. def cudnn_is_acceptable(input: Tensor) -> _bool: ...
  8920. @overload
  8921. def cummax(
  8922. input: Tensor,
  8923. dim: _int,
  8924. *,
  8925. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  8926. ) -> torch.return_types.cummax:
  8927. r"""
  8928. cummax(input, dim, *, out=None) -> (Tensor, LongTensor)
  8929. Returns a namedtuple ``(values, indices)`` where ``values`` is the cumulative maximum of
  8930. elements of :attr:`input` in the dimension :attr:`dim`. And ``indices`` is the index
  8931. location of each maximum value found in the dimension :attr:`dim`.
  8932. .. math::
  8933. y_i = max(x_1, x_2, x_3, \dots, x_i)
  8934. Args:
  8935. input (Tensor): the input tensor.
  8936. dim (int): the dimension to do the operation over
  8937. Keyword args:
  8938. out (tuple, optional): the result tuple of two output tensors (values, indices)
  8939. Example::
  8940. >>> a = torch.randn(10)
  8941. >>> a
  8942. tensor([-0.3449, -1.5447, 0.0685, -1.5104, -1.1706, 0.2259, 1.4696, -1.3284,
  8943. 1.9946, -0.8209])
  8944. >>> torch.cummax(a, dim=0)
  8945. torch.return_types.cummax(
  8946. values=tensor([-0.3449, -0.3449, 0.0685, 0.0685, 0.0685, 0.2259, 1.4696, 1.4696,
  8947. 1.9946, 1.9946]),
  8948. indices=tensor([0, 0, 2, 2, 2, 5, 6, 6, 8, 8]))
  8949. """
  8950. @overload
  8951. def cummax(
  8952. input: Tensor,
  8953. dim: str | EllipsisType | None,
  8954. *,
  8955. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  8956. ) -> torch.return_types.cummax:
  8957. r"""
  8958. cummax(input, dim, *, out=None) -> (Tensor, LongTensor)
  8959. Returns a namedtuple ``(values, indices)`` where ``values`` is the cumulative maximum of
  8960. elements of :attr:`input` in the dimension :attr:`dim`. And ``indices`` is the index
  8961. location of each maximum value found in the dimension :attr:`dim`.
  8962. .. math::
  8963. y_i = max(x_1, x_2, x_3, \dots, x_i)
  8964. Args:
  8965. input (Tensor): the input tensor.
  8966. dim (int): the dimension to do the operation over
  8967. Keyword args:
  8968. out (tuple, optional): the result tuple of two output tensors (values, indices)
  8969. Example::
  8970. >>> a = torch.randn(10)
  8971. >>> a
  8972. tensor([-0.3449, -1.5447, 0.0685, -1.5104, -1.1706, 0.2259, 1.4696, -1.3284,
  8973. 1.9946, -0.8209])
  8974. >>> torch.cummax(a, dim=0)
  8975. torch.return_types.cummax(
  8976. values=tensor([-0.3449, -0.3449, 0.0685, 0.0685, 0.0685, 0.2259, 1.4696, 1.4696,
  8977. 1.9946, 1.9946]),
  8978. indices=tensor([0, 0, 2, 2, 2, 5, 6, 6, 8, 8]))
  8979. """
  8980. @overload
  8981. def cummin(
  8982. input: Tensor,
  8983. dim: _int,
  8984. *,
  8985. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  8986. ) -> torch.return_types.cummin:
  8987. r"""
  8988. cummin(input, dim, *, out=None) -> (Tensor, LongTensor)
  8989. Returns a namedtuple ``(values, indices)`` where ``values`` is the cumulative minimum of
  8990. elements of :attr:`input` in the dimension :attr:`dim`. And ``indices`` is the index
  8991. location of each maximum value found in the dimension :attr:`dim`.
  8992. .. math::
  8993. y_i = min(x_1, x_2, x_3, \dots, x_i)
  8994. Args:
  8995. input (Tensor): the input tensor.
  8996. dim (int): the dimension to do the operation over
  8997. Keyword args:
  8998. out (tuple, optional): the result tuple of two output tensors (values, indices)
  8999. Example::
  9000. >>> a = torch.randn(10)
  9001. >>> a
  9002. tensor([-0.2284, -0.6628, 0.0975, 0.2680, -1.3298, -0.4220, -0.3885, 1.1762,
  9003. 0.9165, 1.6684])
  9004. >>> torch.cummin(a, dim=0)
  9005. torch.return_types.cummin(
  9006. values=tensor([-0.2284, -0.6628, -0.6628, -0.6628, -1.3298, -1.3298, -1.3298, -1.3298,
  9007. -1.3298, -1.3298]),
  9008. indices=tensor([0, 1, 1, 1, 4, 4, 4, 4, 4, 4]))
  9009. """
  9010. @overload
  9011. def cummin(
  9012. input: Tensor,
  9013. dim: str | EllipsisType | None,
  9014. *,
  9015. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  9016. ) -> torch.return_types.cummin:
  9017. r"""
  9018. cummin(input, dim, *, out=None) -> (Tensor, LongTensor)
  9019. Returns a namedtuple ``(values, indices)`` where ``values`` is the cumulative minimum of
  9020. elements of :attr:`input` in the dimension :attr:`dim`. And ``indices`` is the index
  9021. location of each maximum value found in the dimension :attr:`dim`.
  9022. .. math::
  9023. y_i = min(x_1, x_2, x_3, \dots, x_i)
  9024. Args:
  9025. input (Tensor): the input tensor.
  9026. dim (int): the dimension to do the operation over
  9027. Keyword args:
  9028. out (tuple, optional): the result tuple of two output tensors (values, indices)
  9029. Example::
  9030. >>> a = torch.randn(10)
  9031. >>> a
  9032. tensor([-0.2284, -0.6628, 0.0975, 0.2680, -1.3298, -0.4220, -0.3885, 1.1762,
  9033. 0.9165, 1.6684])
  9034. >>> torch.cummin(a, dim=0)
  9035. torch.return_types.cummin(
  9036. values=tensor([-0.2284, -0.6628, -0.6628, -0.6628, -1.3298, -1.3298, -1.3298, -1.3298,
  9037. -1.3298, -1.3298]),
  9038. indices=tensor([0, 1, 1, 1, 4, 4, 4, 4, 4, 4]))
  9039. """
  9040. @overload
  9041. def cumprod(
  9042. input: Tensor,
  9043. dim: _int,
  9044. *,
  9045. dtype: _dtype | None = None,
  9046. out: Tensor | None = None,
  9047. ) -> Tensor:
  9048. r"""
  9049. cumprod(input, dim, *, dtype=None, out=None) -> Tensor
  9050. Returns the cumulative product of elements of :attr:`input` in the dimension
  9051. :attr:`dim`.
  9052. For example, if :attr:`input` is a vector of size N, the result will also be
  9053. a vector of size N, with elements.
  9054. .. math::
  9055. y_i = x_1 \times x_2\times x_3\times \dots \times x_i
  9056. Args:
  9057. input (Tensor): the input tensor.
  9058. dim (int): the dimension to do the operation over
  9059. Keyword args:
  9060. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  9061. If specified, the input tensor is casted to :attr:`dtype` before the operation
  9062. is performed. This is useful for preventing data type overflows. Default: None.
  9063. out (Tensor, optional): the output tensor.
  9064. Example::
  9065. >>> a = torch.randn(10)
  9066. >>> a
  9067. tensor([ 0.6001, 0.2069, -0.1919, 0.9792, 0.6727, 1.0062, 0.4126,
  9068. -0.2129, -0.4206, 0.1968])
  9069. >>> torch.cumprod(a, dim=0)
  9070. tensor([ 0.6001, 0.1241, -0.0238, -0.0233, -0.0157, -0.0158, -0.0065,
  9071. 0.0014, -0.0006, -0.0001])
  9072. >>> a[5] = 0.0
  9073. >>> torch.cumprod(a, dim=0)
  9074. tensor([ 0.6001, 0.1241, -0.0238, -0.0233, -0.0157, -0.0000, -0.0000,
  9075. 0.0000, -0.0000, -0.0000])
  9076. """
  9077. @overload
  9078. def cumprod(
  9079. input: Tensor,
  9080. dim: str | EllipsisType | None,
  9081. *,
  9082. dtype: _dtype | None = None,
  9083. out: Tensor | None = None,
  9084. ) -> Tensor:
  9085. r"""
  9086. cumprod(input, dim, *, dtype=None, out=None) -> Tensor
  9087. Returns the cumulative product of elements of :attr:`input` in the dimension
  9088. :attr:`dim`.
  9089. For example, if :attr:`input` is a vector of size N, the result will also be
  9090. a vector of size N, with elements.
  9091. .. math::
  9092. y_i = x_1 \times x_2\times x_3\times \dots \times x_i
  9093. Args:
  9094. input (Tensor): the input tensor.
  9095. dim (int): the dimension to do the operation over
  9096. Keyword args:
  9097. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  9098. If specified, the input tensor is casted to :attr:`dtype` before the operation
  9099. is performed. This is useful for preventing data type overflows. Default: None.
  9100. out (Tensor, optional): the output tensor.
  9101. Example::
  9102. >>> a = torch.randn(10)
  9103. >>> a
  9104. tensor([ 0.6001, 0.2069, -0.1919, 0.9792, 0.6727, 1.0062, 0.4126,
  9105. -0.2129, -0.4206, 0.1968])
  9106. >>> torch.cumprod(a, dim=0)
  9107. tensor([ 0.6001, 0.1241, -0.0238, -0.0233, -0.0157, -0.0158, -0.0065,
  9108. 0.0014, -0.0006, -0.0001])
  9109. >>> a[5] = 0.0
  9110. >>> torch.cumprod(a, dim=0)
  9111. tensor([ 0.6001, 0.1241, -0.0238, -0.0233, -0.0157, -0.0000, -0.0000,
  9112. 0.0000, -0.0000, -0.0000])
  9113. """
  9114. @overload
  9115. def cumsum(
  9116. input: Tensor,
  9117. dim: _int,
  9118. *,
  9119. dtype: _dtype | None = None,
  9120. out: Tensor | None = None,
  9121. ) -> Tensor:
  9122. r"""
  9123. cumsum(input, dim, *, dtype=None, out=None) -> Tensor
  9124. Returns the cumulative sum of elements of :attr:`input` in the dimension
  9125. :attr:`dim`.
  9126. For example, if :attr:`input` is a vector of size N, the result will also be
  9127. a vector of size N, with elements.
  9128. .. math::
  9129. y_i = x_1 + x_2 + x_3 + \dots + x_i
  9130. Args:
  9131. input (Tensor): the input tensor.
  9132. dim (int): the dimension to do the operation over
  9133. Keyword args:
  9134. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  9135. If specified, the input tensor is casted to :attr:`dtype` before the operation
  9136. is performed. This is useful for preventing data type overflows. Default: None.
  9137. out (Tensor, optional): the output tensor.
  9138. Example::
  9139. >>> a = torch.randint(1, 20, (10,))
  9140. >>> a
  9141. tensor([13, 7, 3, 10, 13, 3, 15, 10, 9, 10])
  9142. >>> torch.cumsum(a, dim=0)
  9143. tensor([13, 20, 23, 33, 46, 49, 64, 74, 83, 93])
  9144. """
  9145. @overload
  9146. def cumsum(
  9147. input: Tensor,
  9148. dim: str | EllipsisType | None,
  9149. *,
  9150. dtype: _dtype | None = None,
  9151. out: Tensor | None = None,
  9152. ) -> Tensor:
  9153. r"""
  9154. cumsum(input, dim, *, dtype=None, out=None) -> Tensor
  9155. Returns the cumulative sum of elements of :attr:`input` in the dimension
  9156. :attr:`dim`.
  9157. For example, if :attr:`input` is a vector of size N, the result will also be
  9158. a vector of size N, with elements.
  9159. .. math::
  9160. y_i = x_1 + x_2 + x_3 + \dots + x_i
  9161. Args:
  9162. input (Tensor): the input tensor.
  9163. dim (int): the dimension to do the operation over
  9164. Keyword args:
  9165. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  9166. If specified, the input tensor is casted to :attr:`dtype` before the operation
  9167. is performed. This is useful for preventing data type overflows. Default: None.
  9168. out (Tensor, optional): the output tensor.
  9169. Example::
  9170. >>> a = torch.randint(1, 20, (10,))
  9171. >>> a
  9172. tensor([13, 7, 3, 10, 13, 3, 15, 10, 9, 10])
  9173. >>> torch.cumsum(a, dim=0)
  9174. tensor([13, 20, 23, 33, 46, 49, 64, 74, 83, 93])
  9175. """
  9176. @overload
  9177. def cumulative_trapezoid(y: Tensor, x: Tensor, *, dim: _int = -1) -> Tensor:
  9178. r"""
  9179. cumulative_trapezoid(y, x=None, *, dx=None, dim=-1) -> Tensor
  9180. Cumulatively computes the `trapezoidal rule <https://en.wikipedia.org/wiki/Trapezoidal_rule>`_
  9181. along :attr:`dim`. By default the spacing between elements is assumed to be 1, but
  9182. :attr:`dx` can be used to specify a different constant spacing, and :attr:`x` can be
  9183. used to specify arbitrary spacing along :attr:`dim`.
  9184. For more details, please read :func:`torch.trapezoid`. The difference between :func:`torch.trapezoid`
  9185. and this function is that, :func:`torch.trapezoid` returns a value for each integration,
  9186. where as this function returns a cumulative value for every spacing within the integration. This
  9187. is analogous to how `.sum` returns a value and `.cumsum` returns a cumulative sum.
  9188. Arguments:
  9189. y (Tensor): Values to use when computing the trapezoidal rule.
  9190. x (Tensor): If specified, defines spacing between values as specified above.
  9191. Keyword arguments:
  9192. dx (float): constant spacing between values. If neither :attr:`x` or :attr:`dx`
  9193. are specified then this defaults to 1. Effectively multiplies the result by its value.
  9194. dim (int): The dimension along which to compute the trapezoidal rule.
  9195. The last (inner-most) dimension by default.
  9196. Examples::
  9197. >>> # Cumulatively computes the trapezoidal rule in 1D, spacing is implicitly 1.
  9198. >>> y = torch.tensor([1, 5, 10])
  9199. >>> torch.cumulative_trapezoid(y)
  9200. tensor([3., 10.5])
  9201. >>> # Computes the same trapezoidal rule directly up to each element to verify
  9202. >>> (1 + 5) / 2
  9203. 3.0
  9204. >>> (1 + 10 + 10) / 2
  9205. 10.5
  9206. >>> # Cumulatively computes the trapezoidal rule in 1D with constant spacing of 2
  9207. >>> # NOTE: the result is the same as before, but multiplied by 2
  9208. >>> torch.cumulative_trapezoid(y, dx=2)
  9209. tensor([6., 21.])
  9210. >>> # Cumulatively computes the trapezoidal rule in 1D with arbitrary spacing
  9211. >>> x = torch.tensor([1, 3, 6])
  9212. >>> torch.cumulative_trapezoid(y, x)
  9213. tensor([6., 28.5])
  9214. >>> # Computes the same trapezoidal rule directly up to each element to verify
  9215. >>> ((3 - 1) * (1 + 5)) / 2
  9216. 6.0
  9217. >>> ((3 - 1) * (1 + 5) + (6 - 3) * (5 + 10)) / 2
  9218. 28.5
  9219. >>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 matrix
  9220. >>> y = torch.arange(9).reshape(3, 3)
  9221. tensor([[0, 1, 2],
  9222. [3, 4, 5],
  9223. [6, 7, 8]])
  9224. >>> torch.cumulative_trapezoid(y)
  9225. tensor([[ 0.5, 2.],
  9226. [ 3.5, 8.],
  9227. [ 6.5, 14.]])
  9228. >>> # Cumulatively computes the trapezoidal rule for each column of the matrix
  9229. >>> torch.cumulative_trapezoid(y, dim=0)
  9230. tensor([[ 1.5, 2.5, 3.5],
  9231. [ 6.0, 8.0, 10.0]])
  9232. >>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 ones matrix
  9233. >>> # with the same arbitrary spacing
  9234. >>> y = torch.ones(3, 3)
  9235. >>> x = torch.tensor([1, 3, 6])
  9236. >>> torch.cumulative_trapezoid(y, x)
  9237. tensor([[2., 5.],
  9238. [2., 5.],
  9239. [2., 5.]])
  9240. >>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 ones matrix
  9241. >>> # with different arbitrary spacing per row
  9242. >>> y = torch.ones(3, 3)
  9243. >>> x = torch.tensor([[1, 2, 3], [1, 3, 5], [1, 4, 7]])
  9244. >>> torch.cumulative_trapezoid(y, x)
  9245. tensor([[1., 2.],
  9246. [2., 4.],
  9247. [3., 6.]])
  9248. """
  9249. @overload
  9250. def cumulative_trapezoid(
  9251. y: Tensor,
  9252. *,
  9253. dx: Number | _complex = 1,
  9254. dim: _int = -1,
  9255. ) -> Tensor:
  9256. r"""
  9257. cumulative_trapezoid(y, x=None, *, dx=None, dim=-1) -> Tensor
  9258. Cumulatively computes the `trapezoidal rule <https://en.wikipedia.org/wiki/Trapezoidal_rule>`_
  9259. along :attr:`dim`. By default the spacing between elements is assumed to be 1, but
  9260. :attr:`dx` can be used to specify a different constant spacing, and :attr:`x` can be
  9261. used to specify arbitrary spacing along :attr:`dim`.
  9262. For more details, please read :func:`torch.trapezoid`. The difference between :func:`torch.trapezoid`
  9263. and this function is that, :func:`torch.trapezoid` returns a value for each integration,
  9264. where as this function returns a cumulative value for every spacing within the integration. This
  9265. is analogous to how `.sum` returns a value and `.cumsum` returns a cumulative sum.
  9266. Arguments:
  9267. y (Tensor): Values to use when computing the trapezoidal rule.
  9268. x (Tensor): If specified, defines spacing between values as specified above.
  9269. Keyword arguments:
  9270. dx (float): constant spacing between values. If neither :attr:`x` or :attr:`dx`
  9271. are specified then this defaults to 1. Effectively multiplies the result by its value.
  9272. dim (int): The dimension along which to compute the trapezoidal rule.
  9273. The last (inner-most) dimension by default.
  9274. Examples::
  9275. >>> # Cumulatively computes the trapezoidal rule in 1D, spacing is implicitly 1.
  9276. >>> y = torch.tensor([1, 5, 10])
  9277. >>> torch.cumulative_trapezoid(y)
  9278. tensor([3., 10.5])
  9279. >>> # Computes the same trapezoidal rule directly up to each element to verify
  9280. >>> (1 + 5) / 2
  9281. 3.0
  9282. >>> (1 + 10 + 10) / 2
  9283. 10.5
  9284. >>> # Cumulatively computes the trapezoidal rule in 1D with constant spacing of 2
  9285. >>> # NOTE: the result is the same as before, but multiplied by 2
  9286. >>> torch.cumulative_trapezoid(y, dx=2)
  9287. tensor([6., 21.])
  9288. >>> # Cumulatively computes the trapezoidal rule in 1D with arbitrary spacing
  9289. >>> x = torch.tensor([1, 3, 6])
  9290. >>> torch.cumulative_trapezoid(y, x)
  9291. tensor([6., 28.5])
  9292. >>> # Computes the same trapezoidal rule directly up to each element to verify
  9293. >>> ((3 - 1) * (1 + 5)) / 2
  9294. 6.0
  9295. >>> ((3 - 1) * (1 + 5) + (6 - 3) * (5 + 10)) / 2
  9296. 28.5
  9297. >>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 matrix
  9298. >>> y = torch.arange(9).reshape(3, 3)
  9299. tensor([[0, 1, 2],
  9300. [3, 4, 5],
  9301. [6, 7, 8]])
  9302. >>> torch.cumulative_trapezoid(y)
  9303. tensor([[ 0.5, 2.],
  9304. [ 3.5, 8.],
  9305. [ 6.5, 14.]])
  9306. >>> # Cumulatively computes the trapezoidal rule for each column of the matrix
  9307. >>> torch.cumulative_trapezoid(y, dim=0)
  9308. tensor([[ 1.5, 2.5, 3.5],
  9309. [ 6.0, 8.0, 10.0]])
  9310. >>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 ones matrix
  9311. >>> # with the same arbitrary spacing
  9312. >>> y = torch.ones(3, 3)
  9313. >>> x = torch.tensor([1, 3, 6])
  9314. >>> torch.cumulative_trapezoid(y, x)
  9315. tensor([[2., 5.],
  9316. [2., 5.],
  9317. [2., 5.]])
  9318. >>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 ones matrix
  9319. >>> # with different arbitrary spacing per row
  9320. >>> y = torch.ones(3, 3)
  9321. >>> x = torch.tensor([[1, 2, 3], [1, 3, 5], [1, 4, 7]])
  9322. >>> torch.cumulative_trapezoid(y, x)
  9323. tensor([[1., 2.],
  9324. [2., 4.],
  9325. [3., 6.]])
  9326. """
  9327. def deg2rad(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  9328. r"""
  9329. deg2rad(input, *, out=None) -> Tensor
  9330. Returns a new tensor with each of the elements of :attr:`input`
  9331. converted from angles in degrees to radians.
  9332. Args:
  9333. input (Tensor): the input tensor.
  9334. Keyword arguments:
  9335. out (Tensor, optional): the output tensor.
  9336. Example::
  9337. >>> a = torch.tensor([[180.0, -180.0], [360.0, -360.0], [90.0, -90.0]])
  9338. >>> torch.deg2rad(a)
  9339. tensor([[ 3.1416, -3.1416],
  9340. [ 6.2832, -6.2832],
  9341. [ 1.5708, -1.5708]])
  9342. """
  9343. def deg2rad_(input: Tensor) -> Tensor: ...
  9344. @overload
  9345. def dequantize(input: Tensor) -> Tensor:
  9346. r"""
  9347. dequantize(tensor) -> Tensor
  9348. Returns an fp32 Tensor by dequantizing a quantized Tensor
  9349. Args:
  9350. tensor (Tensor): A quantized Tensor
  9351. .. function:: dequantize(tensors) -> sequence of Tensors
  9352. :noindex:
  9353. Given a list of quantized Tensors, dequantize them and return a list of fp32 Tensors
  9354. Args:
  9355. tensors (sequence of Tensors): A list of quantized Tensors
  9356. """
  9357. @overload
  9358. def dequantize(
  9359. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  9360. ) -> tuple[Tensor, ...]:
  9361. r"""
  9362. dequantize(tensor) -> Tensor
  9363. Returns an fp32 Tensor by dequantizing a quantized Tensor
  9364. Args:
  9365. tensor (Tensor): A quantized Tensor
  9366. .. function:: dequantize(tensors) -> sequence of Tensors
  9367. :noindex:
  9368. Given a list of quantized Tensors, dequantize them and return a list of fp32 Tensors
  9369. Args:
  9370. tensors (sequence of Tensors): A list of quantized Tensors
  9371. """
  9372. def det(input: Tensor) -> Tensor:
  9373. r"""
  9374. det(input) -> Tensor
  9375. Alias for :func:`torch.linalg.det`
  9376. """
  9377. def detach(input: Tensor) -> Tensor: ...
  9378. def detach_(input: Tensor) -> Tensor: ...
  9379. def detach_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  9380. r"""
  9381. Performs the same operation as :func:`torch.detach`, but all output tensors
  9382. are freshly created instead of aliasing the input.
  9383. """
  9384. def diag(
  9385. input: Tensor,
  9386. diagonal: _int = 0,
  9387. *,
  9388. out: Tensor | None = None,
  9389. ) -> Tensor:
  9390. r"""
  9391. diag(input, diagonal=0, *, out=None) -> Tensor
  9392. - If :attr:`input` is a vector (1-D tensor), then returns a 2-D square tensor
  9393. with the elements of :attr:`input` as the diagonal.
  9394. - If :attr:`input` is a matrix (2-D tensor), then returns a 1-D tensor with
  9395. the diagonal elements of :attr:`input`.
  9396. The argument :attr:`diagonal` controls which diagonal to consider:
  9397. - If :attr:`diagonal` = 0, it is the main diagonal.
  9398. - If :attr:`diagonal` > 0, it is above the main diagonal.
  9399. - If :attr:`diagonal` < 0, it is below the main diagonal.
  9400. Args:
  9401. input (Tensor): the input tensor.
  9402. diagonal (int, optional): the diagonal to consider
  9403. Keyword args:
  9404. out (Tensor, optional): the output tensor.
  9405. .. seealso::
  9406. :func:`torch.diagonal` always returns the diagonal of its input.
  9407. :func:`torch.diagflat` always constructs a tensor with diagonal elements
  9408. specified by the input.
  9409. Examples:
  9410. Get the square matrix where the input vector is the diagonal::
  9411. >>> a = torch.randn(3)
  9412. >>> a
  9413. tensor([ 0.5950,-0.0872, 2.3298])
  9414. >>> torch.diag(a)
  9415. tensor([[ 0.5950, 0.0000, 0.0000],
  9416. [ 0.0000,-0.0872, 0.0000],
  9417. [ 0.0000, 0.0000, 2.3298]])
  9418. >>> torch.diag(a, 1)
  9419. tensor([[ 0.0000, 0.5950, 0.0000, 0.0000],
  9420. [ 0.0000, 0.0000,-0.0872, 0.0000],
  9421. [ 0.0000, 0.0000, 0.0000, 2.3298],
  9422. [ 0.0000, 0.0000, 0.0000, 0.0000]])
  9423. Get the k-th diagonal of a given matrix::
  9424. >>> a = torch.randn(3, 3)
  9425. >>> a
  9426. tensor([[-0.4264, 0.0255,-0.1064],
  9427. [ 0.8795,-0.2429, 0.1374],
  9428. [ 0.1029,-0.6482,-1.6300]])
  9429. >>> torch.diag(a, 0)
  9430. tensor([-0.4264,-0.2429,-1.6300])
  9431. >>> torch.diag(a, 1)
  9432. tensor([ 0.0255, 0.1374])
  9433. """
  9434. def diag_embed(
  9435. input: Tensor,
  9436. offset: _int = 0,
  9437. dim1: _int = -2,
  9438. dim2: _int = -1,
  9439. ) -> Tensor:
  9440. r"""
  9441. diag_embed(input, offset=0, dim1=-2, dim2=-1) -> Tensor
  9442. Creates a tensor whose diagonals of certain 2D planes (specified by
  9443. :attr:`dim1` and :attr:`dim2`) are filled by :attr:`input`.
  9444. To facilitate creating batched diagonal matrices, the 2D planes formed by
  9445. the last two dimensions of the returned tensor are chosen by default.
  9446. The argument :attr:`offset` controls which diagonal to consider:
  9447. - If :attr:`offset` = 0, it is the main diagonal.
  9448. - If :attr:`offset` > 0, it is above the main diagonal.
  9449. - If :attr:`offset` < 0, it is below the main diagonal.
  9450. The size of the new matrix will be calculated to make the specified diagonal
  9451. of the size of the last input dimension.
  9452. Note that for :attr:`offset` other than :math:`0`, the order of :attr:`dim1`
  9453. and :attr:`dim2` matters. Exchanging them is equivalent to changing the
  9454. sign of :attr:`offset`.
  9455. Applying :meth:`torch.diagonal` to the output of this function with
  9456. the same arguments yields a matrix identical to input. However,
  9457. :meth:`torch.diagonal` has different default dimensions, so those
  9458. need to be explicitly specified.
  9459. Args:
  9460. input (Tensor): the input tensor. Must be at least 1-dimensional.
  9461. offset (int, optional): which diagonal to consider. Default: 0
  9462. (main diagonal).
  9463. dim1 (int, optional): first dimension with respect to which to
  9464. take diagonal. Default: -2.
  9465. dim2 (int, optional): second dimension with respect to which to
  9466. take diagonal. Default: -1.
  9467. Example::
  9468. >>> a = torch.randn(2, 3)
  9469. >>> torch.diag_embed(a)
  9470. tensor([[[ 1.5410, 0.0000, 0.0000],
  9471. [ 0.0000, -0.2934, 0.0000],
  9472. [ 0.0000, 0.0000, -2.1788]],
  9473. [[ 0.5684, 0.0000, 0.0000],
  9474. [ 0.0000, -1.0845, 0.0000],
  9475. [ 0.0000, 0.0000, -1.3986]]])
  9476. >>> torch.diag_embed(a, offset=1, dim1=0, dim2=2)
  9477. tensor([[[ 0.0000, 1.5410, 0.0000, 0.0000],
  9478. [ 0.0000, 0.5684, 0.0000, 0.0000]],
  9479. [[ 0.0000, 0.0000, -0.2934, 0.0000],
  9480. [ 0.0000, 0.0000, -1.0845, 0.0000]],
  9481. [[ 0.0000, 0.0000, 0.0000, -2.1788],
  9482. [ 0.0000, 0.0000, 0.0000, -1.3986]],
  9483. [[ 0.0000, 0.0000, 0.0000, 0.0000],
  9484. [ 0.0000, 0.0000, 0.0000, 0.0000]]])
  9485. """
  9486. def diagflat(input: Tensor, offset: _int = 0) -> Tensor:
  9487. r"""
  9488. diagflat(input, offset=0) -> Tensor
  9489. - If :attr:`input` is a vector (1-D tensor), then returns a 2-D square tensor
  9490. with the elements of :attr:`input` as the diagonal.
  9491. - If :attr:`input` is a tensor with more than one dimension, then returns a
  9492. 2-D tensor with diagonal elements equal to a flattened :attr:`input`.
  9493. The argument :attr:`offset` controls which diagonal to consider:
  9494. - If :attr:`offset` = 0, it is the main diagonal.
  9495. - If :attr:`offset` > 0, it is above the main diagonal.
  9496. - If :attr:`offset` < 0, it is below the main diagonal.
  9497. Args:
  9498. input (Tensor): the input tensor.
  9499. offset (int, optional): the diagonal to consider. Default: 0 (main
  9500. diagonal).
  9501. Examples::
  9502. >>> a = torch.randn(3)
  9503. >>> a
  9504. tensor([-0.2956, -0.9068, 0.1695])
  9505. >>> torch.diagflat(a)
  9506. tensor([[-0.2956, 0.0000, 0.0000],
  9507. [ 0.0000, -0.9068, 0.0000],
  9508. [ 0.0000, 0.0000, 0.1695]])
  9509. >>> torch.diagflat(a, 1)
  9510. tensor([[ 0.0000, -0.2956, 0.0000, 0.0000],
  9511. [ 0.0000, 0.0000, -0.9068, 0.0000],
  9512. [ 0.0000, 0.0000, 0.0000, 0.1695],
  9513. [ 0.0000, 0.0000, 0.0000, 0.0000]])
  9514. >>> a = torch.randn(2, 2)
  9515. >>> a
  9516. tensor([[ 0.2094, -0.3018],
  9517. [-0.1516, 1.9342]])
  9518. >>> torch.diagflat(a)
  9519. tensor([[ 0.2094, 0.0000, 0.0000, 0.0000],
  9520. [ 0.0000, -0.3018, 0.0000, 0.0000],
  9521. [ 0.0000, 0.0000, -0.1516, 0.0000],
  9522. [ 0.0000, 0.0000, 0.0000, 1.9342]])
  9523. """
  9524. @overload
  9525. def diagonal(
  9526. input: Tensor,
  9527. offset: _int = 0,
  9528. dim1: _int = 0,
  9529. dim2: _int = 1,
  9530. ) -> Tensor:
  9531. r"""
  9532. diagonal(input, offset=0, dim1=0, dim2=1) -> Tensor
  9533. Returns a partial view of :attr:`input` with the its diagonal elements
  9534. with respect to :attr:`dim1` and :attr:`dim2` appended as a dimension
  9535. at the end of the shape.
  9536. The argument :attr:`offset` controls which diagonal to consider:
  9537. - If :attr:`offset` = 0, it is the main diagonal.
  9538. - If :attr:`offset` > 0, it is above the main diagonal.
  9539. - If :attr:`offset` < 0, it is below the main diagonal.
  9540. Applying :meth:`torch.diag_embed` to the output of this function with
  9541. the same arguments yields a diagonal matrix with the diagonal entries
  9542. of the input. However, :meth:`torch.diag_embed` has different default
  9543. dimensions, so those need to be explicitly specified.
  9544. Args:
  9545. input (Tensor): the input tensor. Must be at least 2-dimensional.
  9546. offset (int, optional): which diagonal to consider. Default: 0
  9547. (main diagonal).
  9548. dim1 (int, optional): first dimension with respect to which to
  9549. take diagonal. Default: 0.
  9550. dim2 (int, optional): second dimension with respect to which to
  9551. take diagonal. Default: 1.
  9552. .. note:: To take a batch diagonal, pass in dim1=-2, dim2=-1.
  9553. Examples::
  9554. >>> a = torch.randn(3, 3)
  9555. >>> a
  9556. tensor([[-1.0854, 1.1431, -0.1752],
  9557. [ 0.8536, -0.0905, 0.0360],
  9558. [ 0.6927, -0.3735, -0.4945]])
  9559. >>> torch.diagonal(a)
  9560. tensor([-1.0854, -0.0905, -0.4945])
  9561. >>> torch.diagonal(a, 1)
  9562. tensor([ 1.1431, 0.0360])
  9563. >>> b = torch.randn(2, 5)
  9564. >>> b
  9565. tensor([[-1.7948, -1.2731, -0.3181, 2.0200, -1.6745],
  9566. [ 1.8262, -1.5049, 0.4114, 1.0704, -1.2607]])
  9567. >>> torch.diagonal(b, 1, 1, 0)
  9568. tensor([1.8262])
  9569. >>> x = torch.randn(2, 5, 4, 2)
  9570. >>> torch.diagonal(x, offset=-1, dim1=1, dim2=2)
  9571. tensor([[[-1.2631, 0.3755, -1.5977, -1.8172],
  9572. [-1.1065, 1.0401, -0.2235, -0.7938]],
  9573. [[-1.7325, -0.3081, 0.6166, 0.2335],
  9574. [ 1.0500, 0.7336, -0.3836, -1.1015]]])
  9575. """
  9576. @overload
  9577. def diagonal(
  9578. input: Tensor,
  9579. *,
  9580. outdim: str | EllipsisType | None,
  9581. dim1: str | EllipsisType | None,
  9582. dim2: str | EllipsisType | None,
  9583. offset: _int = 0,
  9584. ) -> Tensor:
  9585. r"""
  9586. diagonal(input, offset=0, dim1=0, dim2=1) -> Tensor
  9587. Returns a partial view of :attr:`input` with the its diagonal elements
  9588. with respect to :attr:`dim1` and :attr:`dim2` appended as a dimension
  9589. at the end of the shape.
  9590. The argument :attr:`offset` controls which diagonal to consider:
  9591. - If :attr:`offset` = 0, it is the main diagonal.
  9592. - If :attr:`offset` > 0, it is above the main diagonal.
  9593. - If :attr:`offset` < 0, it is below the main diagonal.
  9594. Applying :meth:`torch.diag_embed` to the output of this function with
  9595. the same arguments yields a diagonal matrix with the diagonal entries
  9596. of the input. However, :meth:`torch.diag_embed` has different default
  9597. dimensions, so those need to be explicitly specified.
  9598. Args:
  9599. input (Tensor): the input tensor. Must be at least 2-dimensional.
  9600. offset (int, optional): which diagonal to consider. Default: 0
  9601. (main diagonal).
  9602. dim1 (int, optional): first dimension with respect to which to
  9603. take diagonal. Default: 0.
  9604. dim2 (int, optional): second dimension with respect to which to
  9605. take diagonal. Default: 1.
  9606. .. note:: To take a batch diagonal, pass in dim1=-2, dim2=-1.
  9607. Examples::
  9608. >>> a = torch.randn(3, 3)
  9609. >>> a
  9610. tensor([[-1.0854, 1.1431, -0.1752],
  9611. [ 0.8536, -0.0905, 0.0360],
  9612. [ 0.6927, -0.3735, -0.4945]])
  9613. >>> torch.diagonal(a)
  9614. tensor([-1.0854, -0.0905, -0.4945])
  9615. >>> torch.diagonal(a, 1)
  9616. tensor([ 1.1431, 0.0360])
  9617. >>> b = torch.randn(2, 5)
  9618. >>> b
  9619. tensor([[-1.7948, -1.2731, -0.3181, 2.0200, -1.6745],
  9620. [ 1.8262, -1.5049, 0.4114, 1.0704, -1.2607]])
  9621. >>> torch.diagonal(b, 1, 1, 0)
  9622. tensor([1.8262])
  9623. >>> x = torch.randn(2, 5, 4, 2)
  9624. >>> torch.diagonal(x, offset=-1, dim1=1, dim2=2)
  9625. tensor([[[-1.2631, 0.3755, -1.5977, -1.8172],
  9626. [-1.1065, 1.0401, -0.2235, -0.7938]],
  9627. [[-1.7325, -0.3081, 0.6166, 0.2335],
  9628. [ 1.0500, 0.7336, -0.3836, -1.1015]]])
  9629. """
  9630. def diagonal_copy(
  9631. input: Tensor,
  9632. offset: _int = 0,
  9633. dim1: _int = 0,
  9634. dim2: _int = 1,
  9635. *,
  9636. out: Tensor | None = None,
  9637. ) -> Tensor:
  9638. r"""
  9639. Performs the same operation as :func:`torch.diagonal`, but all output tensors
  9640. are freshly created instead of aliasing the input.
  9641. """
  9642. def diagonal_scatter(
  9643. input: Tensor,
  9644. src: Tensor,
  9645. offset: _int = 0,
  9646. dim1: _int = 0,
  9647. dim2: _int = 1,
  9648. ) -> Tensor:
  9649. r"""
  9650. diagonal_scatter(input, src, offset=0, dim1=0, dim2=1) -> Tensor
  9651. Embeds the values of the :attr:`src` tensor into :attr:`input` along
  9652. the diagonal elements of :attr:`input`, with respect to :attr:`dim1`
  9653. and :attr:`dim2`.
  9654. This function returns a tensor with fresh storage; it does not
  9655. return a view.
  9656. The argument :attr:`offset` controls which diagonal to consider:
  9657. - If :attr:`offset` = 0, it is the main diagonal.
  9658. - If :attr:`offset` > 0, it is above the main diagonal.
  9659. - If :attr:`offset` < 0, it is below the main diagonal.
  9660. Args:
  9661. input (Tensor): the input tensor. Must be at least 2-dimensional.
  9662. src (Tensor): the tensor to embed into :attr:`input`.
  9663. offset (int, optional): which diagonal to consider. Default: 0
  9664. (main diagonal).
  9665. dim1 (int, optional): first dimension with respect to which to
  9666. take diagonal. Default: 0.
  9667. dim2 (int, optional): second dimension with respect to which to
  9668. take diagonal. Default: 1.
  9669. .. note::
  9670. :attr:`src` must be of the proper size in order to be embedded
  9671. into :attr:`input`. Specifically, it should have the same shape as
  9672. ``torch.diagonal(input, offset, dim1, dim2)``
  9673. Examples::
  9674. >>> a = torch.zeros(3, 3)
  9675. >>> a
  9676. tensor([[0., 0., 0.],
  9677. [0., 0., 0.],
  9678. [0., 0., 0.]])
  9679. >>> torch.diagonal_scatter(a, torch.ones(3), 0)
  9680. tensor([[1., 0., 0.],
  9681. [0., 1., 0.],
  9682. [0., 0., 1.]])
  9683. >>> torch.diagonal_scatter(a, torch.ones(2), 1)
  9684. tensor([[0., 1., 0.],
  9685. [0., 0., 1.],
  9686. [0., 0., 0.]])
  9687. """
  9688. def diff(
  9689. input: Tensor,
  9690. n: _int = 1,
  9691. dim: _int = -1,
  9692. prepend: Tensor | None = None,
  9693. append: Tensor | None = None,
  9694. *,
  9695. out: Tensor | None = None,
  9696. ) -> Tensor:
  9697. r"""
  9698. diff(input, n=1, dim=-1, prepend=None, append=None) -> Tensor
  9699. Computes the n-th forward difference along the given dimension.
  9700. The first-order differences are given by `out[i] = input[i + 1] - input[i]`. Higher-order
  9701. differences are calculated by using :func:`torch.diff` recursively.
  9702. Args:
  9703. input (Tensor): the tensor to compute the differences on
  9704. n (int, optional): the number of times to recursively compute the difference
  9705. dim (int, optional): the dimension to compute the difference along.
  9706. Default is the last dimension.
  9707. prepend, append (Tensor, optional): values to prepend or append to
  9708. :attr:`input` along :attr:`dim` before computing the difference.
  9709. Their dimensions must be equivalent to that of input, and their shapes
  9710. must match input's shape except on :attr:`dim`.
  9711. Keyword args:
  9712. out (Tensor, optional): the output tensor.
  9713. Example::
  9714. >>> a = torch.tensor([1, 3, 2])
  9715. >>> torch.diff(a)
  9716. tensor([ 2, -1])
  9717. >>> b = torch.tensor([4, 5])
  9718. >>> torch.diff(a, append=b)
  9719. tensor([ 2, -1, 2, 1])
  9720. >>> c = torch.tensor([[1, 2, 3], [3, 4, 5]])
  9721. >>> torch.diff(c, dim=0)
  9722. tensor([[2, 2, 2]])
  9723. >>> torch.diff(c, dim=1)
  9724. tensor([[1, 1],
  9725. [1, 1]])
  9726. """
  9727. def digamma(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  9728. r"""
  9729. digamma(input, *, out=None) -> Tensor
  9730. Alias for :func:`torch.special.digamma`.
  9731. """
  9732. def dist(input: Tensor, other: Tensor, p: Number | _complex = 2) -> Tensor:
  9733. r"""
  9734. dist(input, other, p=2) -> Tensor
  9735. Returns the p-norm of (:attr:`input` - :attr:`other`)
  9736. The shapes of :attr:`input` and :attr:`other` must be
  9737. :ref:`broadcastable <broadcasting-semantics>`.
  9738. Args:
  9739. input (Tensor): the input tensor.
  9740. other (Tensor): the Right-hand-side input tensor
  9741. p (float, optional): the norm to be computed
  9742. Example::
  9743. >>> x = torch.randn(4)
  9744. >>> x
  9745. tensor([-1.5393, -0.8675, 0.5916, 1.6321])
  9746. >>> y = torch.randn(4)
  9747. >>> y
  9748. tensor([ 0.0967, -1.0511, 0.6295, 0.8360])
  9749. >>> torch.dist(x, y, 3.5)
  9750. tensor(1.6727)
  9751. >>> torch.dist(x, y, 3)
  9752. tensor(1.6973)
  9753. >>> torch.dist(x, y, 0)
  9754. tensor(4.)
  9755. >>> torch.dist(x, y, 1)
  9756. tensor(2.6537)
  9757. """
  9758. def div(
  9759. input: Tensor | Number,
  9760. other: Tensor | Number,
  9761. *,
  9762. rounding_mode: str | None = None,
  9763. out: Tensor | None = None,
  9764. ) -> Tensor:
  9765. r"""
  9766. div(input, other, *, rounding_mode=None, out=None) -> Tensor
  9767. Divides each element of the input ``input`` by the corresponding element of
  9768. :attr:`other`.
  9769. .. math::
  9770. \text{out}_i = \frac{\text{input}_i}{\text{other}_i}
  9771. .. note::
  9772. By default, this performs a "true" division like Python 3.
  9773. See the :attr:`rounding_mode` argument for floor division.
  9774. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  9775. :ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
  9776. Always promotes integer types to the default scalar type.
  9777. Args:
  9778. input (Tensor): the dividend
  9779. other (Tensor or Number): the divisor
  9780. Keyword args:
  9781. rounding_mode (str, optional): Type of rounding applied to the result:
  9782. * None - default behavior. Performs no rounding and, if both :attr:`input` and
  9783. :attr:`other` are integer types, promotes the inputs to the default scalar type.
  9784. Equivalent to true division in Python (the ``/`` operator) and NumPy's ``np.true_divide``.
  9785. * ``"trunc"`` - rounds the results of the division towards zero.
  9786. Equivalent to C-style integer division.
  9787. * ``"floor"`` - rounds the results of the division down.
  9788. Equivalent to floor division in Python (the ``//`` operator) and NumPy's ``np.floor_divide``.
  9789. out (Tensor, optional): the output tensor.
  9790. Examples::
  9791. >>> x = torch.tensor([ 0.3810, 1.2774, -0.2972, -0.3719, 0.4637])
  9792. >>> torch.div(x, 0.5)
  9793. tensor([ 0.7620, 2.5548, -0.5944, -0.7438, 0.9274])
  9794. >>> a = torch.tensor([[-0.3711, -1.9353, -0.4605, -0.2917],
  9795. ... [ 0.1815, -1.0111, 0.9805, -1.5923],
  9796. ... [ 0.1062, 1.4581, 0.7759, -1.2344],
  9797. ... [-0.1830, -0.0313, 1.1908, -1.4757]])
  9798. >>> b = torch.tensor([ 0.8032, 0.2930, -0.8113, -0.2308])
  9799. >>> torch.div(a, b)
  9800. tensor([[-0.4620, -6.6051, 0.5676, 1.2639],
  9801. [ 0.2260, -3.4509, -1.2086, 6.8990],
  9802. [ 0.1322, 4.9764, -0.9564, 5.3484],
  9803. [-0.2278, -0.1068, -1.4678, 6.3938]])
  9804. >>> torch.div(a, b, rounding_mode='trunc')
  9805. tensor([[-0., -6., 0., 1.],
  9806. [ 0., -3., -1., 6.],
  9807. [ 0., 4., -0., 5.],
  9808. [-0., -0., -1., 6.]])
  9809. >>> torch.div(a, b, rounding_mode='floor')
  9810. tensor([[-1., -7., 0., 1.],
  9811. [ 0., -4., -2., 6.],
  9812. [ 0., 4., -1., 5.],
  9813. [-1., -1., -2., 6.]])
  9814. """
  9815. @overload
  9816. def divide(
  9817. input: Tensor,
  9818. other: Tensor,
  9819. *,
  9820. out: Tensor | None = None,
  9821. ) -> Tensor:
  9822. r"""
  9823. divide(input, other, *, rounding_mode=None, out=None) -> Tensor
  9824. Alias for :func:`torch.div`.
  9825. """
  9826. @overload
  9827. def divide(
  9828. input: Tensor,
  9829. other: Tensor,
  9830. *,
  9831. rounding_mode: str | None,
  9832. out: Tensor | None = None,
  9833. ) -> Tensor:
  9834. r"""
  9835. divide(input, other, *, rounding_mode=None, out=None) -> Tensor
  9836. Alias for :func:`torch.div`.
  9837. """
  9838. @overload
  9839. def divide(
  9840. input: Tensor,
  9841. other: Number | _complex,
  9842. *,
  9843. rounding_mode: str | None,
  9844. ) -> Tensor:
  9845. r"""
  9846. divide(input, other, *, rounding_mode=None, out=None) -> Tensor
  9847. Alias for :func:`torch.div`.
  9848. """
  9849. @overload
  9850. def divide(input: Tensor, other: Number | _complex) -> Tensor:
  9851. r"""
  9852. divide(input, other, *, rounding_mode=None, out=None) -> Tensor
  9853. Alias for :func:`torch.div`.
  9854. """
  9855. def dot(
  9856. input: Tensor,
  9857. tensor: Tensor,
  9858. *,
  9859. out: Tensor | None = None,
  9860. ) -> Tensor:
  9861. r"""
  9862. dot(input, tensor, *, out=None) -> Tensor
  9863. Computes the dot product of two 1D tensors.
  9864. .. note::
  9865. Unlike NumPy's dot, torch.dot intentionally only supports computing the dot product
  9866. of two 1D tensors with the same number of elements.
  9867. Args:
  9868. input (Tensor): first tensor in the dot product, must be 1D.
  9869. tensor (Tensor): second tensor in the dot product, must be 1D.
  9870. Keyword args:
  9871. out (Tensor, optional): the output tensor.
  9872. Example::
  9873. >>> torch.dot(torch.tensor([2, 3]), torch.tensor([2, 1]))
  9874. tensor(7)
  9875. >>> t1, t2 = torch.tensor([0, 1]), torch.tensor([2, 3])
  9876. >>> torch.dot(t1, t2)
  9877. tensor(3)
  9878. """
  9879. def dropout(input: Tensor, p: _float, train: _bool) -> Tensor: ...
  9880. def dropout_(input: Tensor, p: _float, train: _bool) -> Tensor: ...
  9881. def dsmm(input: Tensor, mat2: Tensor) -> Tensor: ...
  9882. @overload
  9883. def dsplit(input: Tensor, sections: _int) -> tuple[Tensor, ...]:
  9884. r"""
  9885. dsplit(input, indices_or_sections) -> List of Tensors
  9886. Splits :attr:`input`, a tensor with three or more dimensions, into multiple tensors
  9887. depthwise according to :attr:`indices_or_sections`. Each split is a view of
  9888. :attr:`input`.
  9889. This is equivalent to calling torch.tensor_split(input, indices_or_sections, dim=2)
  9890. (the split dimension is 2), except that if :attr:`indices_or_sections` is an integer
  9891. it must evenly divide the split dimension or a runtime error will be thrown.
  9892. This function is based on NumPy's :func:`numpy.dsplit`.
  9893. Args:
  9894. input (Tensor): tensor to split.
  9895. indices_or_sections (int or list or tuple of ints): See argument in :func:`torch.tensor_split`.
  9896. Example::
  9897. >>> t = torch.arange(16.0).reshape(2, 2, 4)
  9898. >>> t
  9899. tensor([[[ 0., 1., 2., 3.],
  9900. [ 4., 5., 6., 7.]],
  9901. [[ 8., 9., 10., 11.],
  9902. [12., 13., 14., 15.]]])
  9903. >>> torch.dsplit(t, 2)
  9904. (tensor([[[ 0., 1.],
  9905. [ 4., 5.]],
  9906. [[ 8., 9.],
  9907. [12., 13.]]]),
  9908. tensor([[[ 2., 3.],
  9909. [ 6., 7.]],
  9910. [[10., 11.],
  9911. [14., 15.]]]))
  9912. >>> torch.dsplit(t, [3, 6])
  9913. (tensor([[[ 0., 1., 2.],
  9914. [ 4., 5., 6.]],
  9915. [[ 8., 9., 10.],
  9916. [12., 13., 14.]]]),
  9917. tensor([[[ 3.],
  9918. [ 7.]],
  9919. [[11.],
  9920. [15.]]]),
  9921. tensor([], size=(2, 2, 0)))
  9922. """
  9923. @overload
  9924. def dsplit(input: Tensor, indices: _size) -> tuple[Tensor, ...]:
  9925. r"""
  9926. dsplit(input, indices_or_sections) -> List of Tensors
  9927. Splits :attr:`input`, a tensor with three or more dimensions, into multiple tensors
  9928. depthwise according to :attr:`indices_or_sections`. Each split is a view of
  9929. :attr:`input`.
  9930. This is equivalent to calling torch.tensor_split(input, indices_or_sections, dim=2)
  9931. (the split dimension is 2), except that if :attr:`indices_or_sections` is an integer
  9932. it must evenly divide the split dimension or a runtime error will be thrown.
  9933. This function is based on NumPy's :func:`numpy.dsplit`.
  9934. Args:
  9935. input (Tensor): tensor to split.
  9936. indices_or_sections (int or list or tuple of ints): See argument in :func:`torch.tensor_split`.
  9937. Example::
  9938. >>> t = torch.arange(16.0).reshape(2, 2, 4)
  9939. >>> t
  9940. tensor([[[ 0., 1., 2., 3.],
  9941. [ 4., 5., 6., 7.]],
  9942. [[ 8., 9., 10., 11.],
  9943. [12., 13., 14., 15.]]])
  9944. >>> torch.dsplit(t, 2)
  9945. (tensor([[[ 0., 1.],
  9946. [ 4., 5.]],
  9947. [[ 8., 9.],
  9948. [12., 13.]]]),
  9949. tensor([[[ 2., 3.],
  9950. [ 6., 7.]],
  9951. [[10., 11.],
  9952. [14., 15.]]]))
  9953. >>> torch.dsplit(t, [3, 6])
  9954. (tensor([[[ 0., 1., 2.],
  9955. [ 4., 5., 6.]],
  9956. [[ 8., 9., 10.],
  9957. [12., 13., 14.]]]),
  9958. tensor([[[ 3.],
  9959. [ 7.]],
  9960. [[11.],
  9961. [15.]]]),
  9962. tensor([], size=(2, 2, 0)))
  9963. """
  9964. def dstack(
  9965. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  9966. *,
  9967. out: Tensor | None = None,
  9968. ) -> Tensor:
  9969. r"""
  9970. dstack(tensors, *, out=None) -> Tensor
  9971. Stack tensors in sequence depthwise (along third axis).
  9972. This is equivalent to concatenation along the third axis after 1-D and 2-D tensors have been reshaped by :func:`torch.atleast_3d`.
  9973. Args:
  9974. tensors (sequence of Tensors): sequence of tensors to concatenate
  9975. Keyword args:
  9976. out (Tensor, optional): the output tensor.
  9977. Example::
  9978. >>> a = torch.tensor([1, 2, 3])
  9979. >>> b = torch.tensor([4, 5, 6])
  9980. >>> torch.dstack((a,b))
  9981. tensor([[[1, 4],
  9982. [2, 5],
  9983. [3, 6]]])
  9984. >>> a = torch.tensor([[1],[2],[3]])
  9985. >>> b = torch.tensor([[4],[5],[6]])
  9986. >>> torch.dstack((a,b))
  9987. tensor([[[1, 4]],
  9988. [[2, 5]],
  9989. [[3, 6]]])
  9990. """
  9991. def embedding(
  9992. weight: Tensor,
  9993. indices: Tensor,
  9994. padding_idx: _int | SymInt = -1,
  9995. scale_grad_by_freq: _bool = False,
  9996. sparse: _bool = False,
  9997. ) -> Tensor: ...
  9998. @overload
  9999. def embedding_bag(
  10000. weight: Tensor,
  10001. indices: Tensor,
  10002. offsets: Tensor,
  10003. scale_grad_by_freq: _bool,
  10004. mode: _int,
  10005. sparse: _bool,
  10006. per_sample_weights: Tensor | None,
  10007. include_last_offset: _bool,
  10008. padding_idx: _int | None,
  10009. ) -> tuple[Tensor, Tensor, Tensor, Tensor]: ...
  10010. @overload
  10011. def embedding_bag(
  10012. weight: Tensor,
  10013. indices: Tensor,
  10014. offsets: Tensor,
  10015. scale_grad_by_freq: _bool = False,
  10016. mode: _int = 0,
  10017. sparse: _bool = False,
  10018. per_sample_weights: Tensor | None = None,
  10019. include_last_offset: _bool = False,
  10020. ) -> tuple[Tensor, Tensor, Tensor, Tensor]: ...
  10021. def embedding_renorm_(
  10022. input: Tensor,
  10023. indices: Tensor,
  10024. max_norm: _float,
  10025. norm_type: _float,
  10026. ) -> Tensor: ...
  10027. @overload
  10028. def empty(
  10029. size: Sequence[_int | SymInt],
  10030. *,
  10031. memory_format: memory_format | None = None,
  10032. out: Tensor | None = None,
  10033. dtype: _dtype | None = None,
  10034. layout: _layout | None = None,
  10035. device: DeviceLikeType | None = None,
  10036. pin_memory: _bool | None = False,
  10037. requires_grad: _bool | None = False,
  10038. ) -> Tensor:
  10039. r"""
  10040. empty(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False, memory_format=torch.contiguous_format) -> Tensor
  10041. Returns a tensor filled with uninitialized data. The shape of the tensor is
  10042. defined by the variable argument :attr:`size`.
  10043. .. note::
  10044. If :func:`torch.use_deterministic_algorithms()` and
  10045. :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
  10046. ``True``, the output tensor is initialized to prevent any possible
  10047. nondeterministic behavior from using the data as an input to an operation.
  10048. Floating point and complex tensors are filled with NaN, and integer tensors
  10049. are filled with the maximum value.
  10050. Args:
  10051. size (int...): a sequence of integers defining the shape of the output tensor.
  10052. Can be a variable number of arguments or a collection like a list or tuple.
  10053. Keyword args:
  10054. out (Tensor, optional): the output tensor.
  10055. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  10056. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  10057. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  10058. Default: ``torch.strided``.
  10059. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10060. Default: if ``None``, uses the current device for the default tensor type
  10061. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  10062. for CPU tensor types and the current CUDA device for CUDA tensor types.
  10063. requires_grad (bool, optional): If autograd should record operations on the
  10064. returned tensor. Default: ``False``.
  10065. pin_memory (bool, optional): If set, returned tensor would be allocated in
  10066. the pinned memory. Works only for CPU tensors. Default: ``False``.
  10067. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  10068. returned Tensor. Default: ``torch.contiguous_format``.
  10069. Example::
  10070. >>> torch.empty((2,3), dtype=torch.int64)
  10071. tensor([[ 9.4064e+13, 2.8000e+01, 9.3493e+13],
  10072. [ 7.5751e+18, 7.1428e+18, 7.5955e+18]])
  10073. """
  10074. @overload
  10075. def empty(
  10076. *size: _int | SymInt,
  10077. memory_format: memory_format | None = None,
  10078. out: Tensor | None = None,
  10079. dtype: _dtype | None = None,
  10080. layout: _layout | None = None,
  10081. device: DeviceLikeType | None = None,
  10082. pin_memory: _bool | None = False,
  10083. requires_grad: _bool | None = False,
  10084. ) -> Tensor:
  10085. r"""
  10086. empty(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False, memory_format=torch.contiguous_format) -> Tensor
  10087. Returns a tensor filled with uninitialized data. The shape of the tensor is
  10088. defined by the variable argument :attr:`size`.
  10089. .. note::
  10090. If :func:`torch.use_deterministic_algorithms()` and
  10091. :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
  10092. ``True``, the output tensor is initialized to prevent any possible
  10093. nondeterministic behavior from using the data as an input to an operation.
  10094. Floating point and complex tensors are filled with NaN, and integer tensors
  10095. are filled with the maximum value.
  10096. Args:
  10097. size (int...): a sequence of integers defining the shape of the output tensor.
  10098. Can be a variable number of arguments or a collection like a list or tuple.
  10099. Keyword args:
  10100. out (Tensor, optional): the output tensor.
  10101. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  10102. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  10103. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  10104. Default: ``torch.strided``.
  10105. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10106. Default: if ``None``, uses the current device for the default tensor type
  10107. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  10108. for CPU tensor types and the current CUDA device for CUDA tensor types.
  10109. requires_grad (bool, optional): If autograd should record operations on the
  10110. returned tensor. Default: ``False``.
  10111. pin_memory (bool, optional): If set, returned tensor would be allocated in
  10112. the pinned memory. Works only for CPU tensors. Default: ``False``.
  10113. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  10114. returned Tensor. Default: ``torch.contiguous_format``.
  10115. Example::
  10116. >>> torch.empty((2,3), dtype=torch.int64)
  10117. tensor([[ 9.4064e+13, 2.8000e+01, 9.3493e+13],
  10118. [ 7.5751e+18, 7.1428e+18, 7.5955e+18]])
  10119. """
  10120. @overload
  10121. def empty(
  10122. size: _size,
  10123. *,
  10124. names: Sequence[str | EllipsisType | None] | None,
  10125. memory_format: memory_format | None = None,
  10126. dtype: _dtype | None = None,
  10127. layout: _layout | None = None,
  10128. device: DeviceLikeType | None = None,
  10129. pin_memory: _bool | None = False,
  10130. requires_grad: _bool | None = False,
  10131. ) -> Tensor:
  10132. r"""
  10133. empty(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False, memory_format=torch.contiguous_format) -> Tensor
  10134. Returns a tensor filled with uninitialized data. The shape of the tensor is
  10135. defined by the variable argument :attr:`size`.
  10136. .. note::
  10137. If :func:`torch.use_deterministic_algorithms()` and
  10138. :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
  10139. ``True``, the output tensor is initialized to prevent any possible
  10140. nondeterministic behavior from using the data as an input to an operation.
  10141. Floating point and complex tensors are filled with NaN, and integer tensors
  10142. are filled with the maximum value.
  10143. Args:
  10144. size (int...): a sequence of integers defining the shape of the output tensor.
  10145. Can be a variable number of arguments or a collection like a list or tuple.
  10146. Keyword args:
  10147. out (Tensor, optional): the output tensor.
  10148. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  10149. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  10150. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  10151. Default: ``torch.strided``.
  10152. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10153. Default: if ``None``, uses the current device for the default tensor type
  10154. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  10155. for CPU tensor types and the current CUDA device for CUDA tensor types.
  10156. requires_grad (bool, optional): If autograd should record operations on the
  10157. returned tensor. Default: ``False``.
  10158. pin_memory (bool, optional): If set, returned tensor would be allocated in
  10159. the pinned memory. Works only for CPU tensors. Default: ``False``.
  10160. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  10161. returned Tensor. Default: ``torch.contiguous_format``.
  10162. Example::
  10163. >>> torch.empty((2,3), dtype=torch.int64)
  10164. tensor([[ 9.4064e+13, 2.8000e+01, 9.3493e+13],
  10165. [ 7.5751e+18, 7.1428e+18, 7.5955e+18]])
  10166. """
  10167. @overload
  10168. def empty(
  10169. *size: _int,
  10170. names: Sequence[str | EllipsisType | None] | None,
  10171. memory_format: memory_format | None = None,
  10172. dtype: _dtype | None = None,
  10173. layout: _layout | None = None,
  10174. device: DeviceLikeType | None = None,
  10175. pin_memory: _bool | None = False,
  10176. requires_grad: _bool | None = False,
  10177. ) -> Tensor:
  10178. r"""
  10179. empty(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False, memory_format=torch.contiguous_format) -> Tensor
  10180. Returns a tensor filled with uninitialized data. The shape of the tensor is
  10181. defined by the variable argument :attr:`size`.
  10182. .. note::
  10183. If :func:`torch.use_deterministic_algorithms()` and
  10184. :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
  10185. ``True``, the output tensor is initialized to prevent any possible
  10186. nondeterministic behavior from using the data as an input to an operation.
  10187. Floating point and complex tensors are filled with NaN, and integer tensors
  10188. are filled with the maximum value.
  10189. Args:
  10190. size (int...): a sequence of integers defining the shape of the output tensor.
  10191. Can be a variable number of arguments or a collection like a list or tuple.
  10192. Keyword args:
  10193. out (Tensor, optional): the output tensor.
  10194. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  10195. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  10196. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  10197. Default: ``torch.strided``.
  10198. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10199. Default: if ``None``, uses the current device for the default tensor type
  10200. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  10201. for CPU tensor types and the current CUDA device for CUDA tensor types.
  10202. requires_grad (bool, optional): If autograd should record operations on the
  10203. returned tensor. Default: ``False``.
  10204. pin_memory (bool, optional): If set, returned tensor would be allocated in
  10205. the pinned memory. Works only for CPU tensors. Default: ``False``.
  10206. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  10207. returned Tensor. Default: ``torch.contiguous_format``.
  10208. Example::
  10209. >>> torch.empty((2,3), dtype=torch.int64)
  10210. tensor([[ 9.4064e+13, 2.8000e+01, 9.3493e+13],
  10211. [ 7.5751e+18, 7.1428e+18, 7.5955e+18]])
  10212. """
  10213. def empty_like(
  10214. input: Tensor,
  10215. *,
  10216. memory_format: memory_format | None = None,
  10217. dtype: _dtype | None = None,
  10218. layout: _layout | None = None,
  10219. device: DeviceLikeType | None = None,
  10220. pin_memory: _bool | None = False,
  10221. requires_grad: _bool | None = False,
  10222. ) -> Tensor:
  10223. r"""
  10224. empty_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  10225. Returns an uninitialized tensor with the same size as :attr:`input`.
  10226. ``torch.empty_like(input)`` is equivalent to
  10227. ``torch.empty(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
  10228. .. note::
  10229. If :func:`torch.use_deterministic_algorithms()` and
  10230. :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
  10231. ``True``, the output tensor is initialized to prevent any possible
  10232. nondeterministic behavior from using the data as an input to an operation.
  10233. Floating point and complex tensors are filled with NaN, and integer tensors
  10234. are filled with the maximum value.
  10235. When ``torch.preserve_format`` is used:
  10236. If the input tensor is dense (i.e., non-overlapping strided),
  10237. its memory format (including strides) is retained.
  10238. Otherwise (e.g., a non-dense view like a stepped slice),
  10239. the output is converted to the dense format.
  10240. Args:
  10241. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  10242. Keyword args:
  10243. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  10244. Default: if ``None``, defaults to the dtype of :attr:`input`.
  10245. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  10246. Default: if ``None``, defaults to the layout of :attr:`input`.
  10247. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10248. Default: if ``None``, defaults to the device of :attr:`input`.
  10249. requires_grad (bool, optional): If autograd should record operations on the
  10250. returned tensor. Default: ``False``.
  10251. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  10252. returned Tensor. Default: ``torch.preserve_format``.
  10253. Example::
  10254. >>> a=torch.empty((2,3), dtype=torch.int32, device = 'cuda')
  10255. >>> torch.empty_like(a)
  10256. tensor([[0, 0, 0],
  10257. [0, 0, 0]], device='cuda:0', dtype=torch.int32)
  10258. """
  10259. def empty_permuted(
  10260. size: Sequence[_int | SymInt],
  10261. physical_layout: _size,
  10262. *,
  10263. dtype: _dtype | None = None,
  10264. layout: _layout | None = None,
  10265. device: DeviceLikeType | None = None,
  10266. pin_memory: _bool | None = False,
  10267. requires_grad: _bool | None = False,
  10268. ) -> Tensor:
  10269. r"""
  10270. empty_permuted(size, physical_layout, *, dtype=None, layout=None, device=None, requires_grad=False, pin_memory=False) -> Tensor
  10271. Creates an uninitialized, non-overlapping and dense tensor with the
  10272. specified :attr:`size`, with :attr:`physical_layout` specifying how the
  10273. dimensions are physically laid out in memory (each logical dimension is listed
  10274. from outermost to innermost). :attr:`physical_layout` is a generalization
  10275. of NCHW/NHWC notation: if each dimension is assigned a number according to
  10276. what order they occur in size (N=0, C=1, H=2, W=3), then NCHW is ``(0, 1, 2, 3)``
  10277. while NHWC is ``(0, 2, 3, 1)``. Equivalently, the strides of the output
  10278. tensor ``t`` are such that ``t.stride(physical_layout[i]) == contiguous_strides[i]``
  10279. (notably, this function is *not* equivalent to ``torch.empty(size).permute(physical_layout)``).
  10280. Unlike :func:`torch.empty_strided`, this is guaranteed to produce a dense
  10281. tensor with no overlaps. If possible, prefer using this function over
  10282. :func:`torch.empty_strided` or manual use of :func:`torch.as_strided`.
  10283. .. note::
  10284. If :func:`torch.use_deterministic_algorithms()` and
  10285. :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
  10286. ``True``, the output tensor is initialized to prevent any possible
  10287. nondeterministic behavior from using the data as an input to an operation.
  10288. Floating point and complex tensors are filled with NaN, and integer tensors
  10289. are filled with the maximum value.
  10290. Args:
  10291. size (tuple of int): the shape of the output tensor
  10292. physical_layout (tuple of int): the ordering of dimensions physically in memory
  10293. Keyword args:
  10294. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  10295. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  10296. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  10297. Default: ``torch.strided``.
  10298. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10299. Default: if ``None``, uses the current device for the default tensor type
  10300. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  10301. for CPU tensor types and the current CUDA device for CUDA tensor types.
  10302. requires_grad (bool, optional): If autograd should record operations on the
  10303. returned tensor. Default: ``False``.
  10304. pin_memory (bool, optional): If set, returned tensor would be allocated in
  10305. the pinned memory. Works only for CPU tensors. Default: ``False``.
  10306. Examples:
  10307. >>> torch.empty((2, 3, 5, 7)).stride()
  10308. (105, 35, 7, 1)
  10309. >>> torch.empty_permuted((2, 3, 5, 7), (0, 1, 2, 3)).stride()
  10310. (105, 35, 7, 1)
  10311. >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).stride()
  10312. (105, 1, 21, 3)
  10313. >>> torch.empty_permuted((2, 3, 5, 7), (0, 2, 3, 1)).stride()
  10314. (105, 1, 21, 3)
  10315. >>> torch.empty_permuted((2, 3, 5, 7), (0, 2, 3, 1)).dim_order()
  10316. (0, 2, 3, 1)
  10317. """
  10318. def empty_quantized(
  10319. size: _size,
  10320. qtensor: Tensor,
  10321. *,
  10322. memory_format: memory_format | None = None,
  10323. dtype: _dtype | None = None,
  10324. layout: _layout | None = None,
  10325. device: DeviceLikeType | None = None,
  10326. pin_memory: _bool | None = False,
  10327. requires_grad: _bool | None = False,
  10328. ) -> Tensor: ...
  10329. def empty_strided(
  10330. size: Sequence[_int | SymInt],
  10331. stride: Sequence[_int | SymInt],
  10332. *,
  10333. dtype: _dtype | None = None,
  10334. layout: _layout | None = None,
  10335. device: DeviceLikeType | None = None,
  10336. pin_memory: _bool | None = False,
  10337. requires_grad: _bool | None = False,
  10338. ) -> Tensor:
  10339. r"""
  10340. empty_strided(size, stride, *, dtype=None, layout=None, device=None, requires_grad=False, pin_memory=False) -> Tensor
  10341. Creates a tensor with the specified :attr:`size` and :attr:`stride` and filled with undefined data.
  10342. .. warning::
  10343. If the constructed tensor is "overlapped" (with multiple indices referring to the same element
  10344. in memory) its behavior is undefined.
  10345. .. note::
  10346. If :func:`torch.use_deterministic_algorithms()` and
  10347. :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
  10348. ``True``, the output tensor is initialized to prevent any possible
  10349. nondeterministic behavior from using the data as an input to an operation.
  10350. Floating point and complex tensors are filled with NaN, and integer tensors
  10351. are filled with the maximum value.
  10352. Args:
  10353. size (tuple of int): the shape of the output tensor
  10354. stride (tuple of int): the strides of the output tensor
  10355. Keyword args:
  10356. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  10357. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  10358. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  10359. Default: ``torch.strided``.
  10360. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10361. Default: if ``None``, uses the current device for the default tensor type
  10362. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  10363. for CPU tensor types and the current CUDA device for CUDA tensor types.
  10364. requires_grad (bool, optional): If autograd should record operations on the
  10365. returned tensor. Default: ``False``.
  10366. pin_memory (bool, optional): If set, returned tensor would be allocated in
  10367. the pinned memory. Works only for CPU tensors. Default: ``False``.
  10368. Example::
  10369. >>> a = torch.empty_strided((2, 3), (1, 2))
  10370. >>> a
  10371. tensor([[8.9683e-44, 4.4842e-44, 5.1239e+07],
  10372. [0.0000e+00, 0.0000e+00, 3.0705e-41]])
  10373. >>> a.stride()
  10374. (1, 2)
  10375. >>> a.size()
  10376. torch.Size([2, 3])
  10377. """
  10378. @overload
  10379. def eq(
  10380. input: Tensor,
  10381. other: Tensor,
  10382. *,
  10383. out: Tensor | None = None,
  10384. ) -> Tensor:
  10385. r"""
  10386. eq(input, other, *, out=None) -> Tensor
  10387. Computes element-wise equality
  10388. The second argument can be a number or a tensor whose shape is
  10389. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  10390. Args:
  10391. input (Tensor): the tensor to compare
  10392. other (Tensor or float): the tensor or value to compare
  10393. Keyword args:
  10394. out (Tensor, optional): the output tensor.
  10395. Returns:
  10396. A boolean tensor that is True where :attr:`input` is equal to :attr:`other` and False elsewhere
  10397. Example::
  10398. >>> torch.eq(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  10399. tensor([[ True, False],
  10400. [False, True]])
  10401. """
  10402. @overload
  10403. def eq(
  10404. input: Tensor,
  10405. other: Number | _complex,
  10406. *,
  10407. out: Tensor | None = None,
  10408. ) -> Tensor:
  10409. r"""
  10410. eq(input, other, *, out=None) -> Tensor
  10411. Computes element-wise equality
  10412. The second argument can be a number or a tensor whose shape is
  10413. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  10414. Args:
  10415. input (Tensor): the tensor to compare
  10416. other (Tensor or float): the tensor or value to compare
  10417. Keyword args:
  10418. out (Tensor, optional): the output tensor.
  10419. Returns:
  10420. A boolean tensor that is True where :attr:`input` is equal to :attr:`other` and False elsewhere
  10421. Example::
  10422. >>> torch.eq(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  10423. tensor([[ True, False],
  10424. [False, True]])
  10425. """
  10426. def equal(input: Tensor, other: Tensor) -> _bool:
  10427. r"""
  10428. equal(input, other) -> bool
  10429. ``True`` if two tensors have the same size and elements, ``False`` otherwise.
  10430. .. note::
  10431. Tensors containing NaNs are never equal to each other. Additionally, this function does not
  10432. differentiate between the data types of the tensors during comparison. For more thorough tensor checks,
  10433. use :meth:`torch.testing.assert_close`.
  10434. Example::
  10435. >>> torch.equal(torch.tensor([1, 2]), torch.tensor([1, 2]))
  10436. True
  10437. >>> torch.equal(torch.tensor([3, torch.nan]), torch.tensor([3, torch.nan]))
  10438. False
  10439. >>> torch.equal(torch.tensor([1, 2, 3], dtype=torch.int32), torch.tensor([1, 2, 3], dtype=torch.float32))
  10440. True
  10441. """
  10442. def erf(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  10443. r"""
  10444. erf(input, *, out=None) -> Tensor
  10445. Alias for :func:`torch.special.erf`.
  10446. """
  10447. def erf_(input: Tensor) -> Tensor: ...
  10448. def erfc(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  10449. r"""
  10450. erfc(input, *, out=None) -> Tensor
  10451. Alias for :func:`torch.special.erfc`.
  10452. """
  10453. def erfc_(input: Tensor) -> Tensor: ...
  10454. def erfinv(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  10455. r"""
  10456. erfinv(input, *, out=None) -> Tensor
  10457. Alias for :func:`torch.special.erfinv`.
  10458. """
  10459. def exp(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  10460. r"""
  10461. exp(input, *, out=None) -> Tensor
  10462. Returns a new tensor with the exponential of the elements
  10463. of the input tensor :attr:`input`.
  10464. .. math::
  10465. y_{i} = e^{x_{i}}
  10466. Args:
  10467. input (Tensor): the input tensor.
  10468. Keyword args:
  10469. out (Tensor, optional): the output tensor.
  10470. Example::
  10471. >>> torch.exp(torch.tensor([0, math.log(2.)]))
  10472. tensor([ 1., 2.])
  10473. """
  10474. def exp2(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  10475. r"""
  10476. exp2(input, *, out=None) -> Tensor
  10477. Alias for :func:`torch.special.exp2`.
  10478. """
  10479. def exp2_(input: Tensor) -> Tensor: ...
  10480. def exp_(input: Tensor) -> Tensor: ...
  10481. def expand_copy(
  10482. input: Tensor,
  10483. size: Sequence[_int | SymInt],
  10484. *,
  10485. implicit: _bool = False,
  10486. out: Tensor | None = None,
  10487. ) -> Tensor:
  10488. r"""
  10489. Performs the same operation as :func:`torch.Tensor.expand`, but all output tensors
  10490. are freshly created instead of aliasing the input.
  10491. """
  10492. def expm1(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  10493. r"""
  10494. expm1(input, *, out=None) -> Tensor
  10495. Alias for :func:`torch.special.expm1`.
  10496. """
  10497. def expm1_(input: Tensor) -> Tensor: ...
  10498. @overload
  10499. def eye(
  10500. n: _int | SymInt,
  10501. *,
  10502. out: Tensor | None = None,
  10503. dtype: _dtype | None = None,
  10504. layout: _layout | None = None,
  10505. device: DeviceLikeType | None = None,
  10506. pin_memory: _bool | None = False,
  10507. requires_grad: _bool | None = False,
  10508. ) -> Tensor:
  10509. r"""
  10510. eye(n, m=None, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  10511. Returns a 2-D tensor with ones on the diagonal and zeros elsewhere.
  10512. Args:
  10513. n (int): the number of rows
  10514. m (int, optional): the number of columns with default being :attr:`n`
  10515. Keyword arguments:
  10516. out (Tensor, optional): the output tensor.
  10517. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  10518. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  10519. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  10520. Default: ``torch.strided``.
  10521. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10522. Default: if ``None``, uses the current device for the default tensor type
  10523. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  10524. for CPU tensor types and the current CUDA device for CUDA tensor types.
  10525. requires_grad (bool, optional): If autograd should record operations on the
  10526. returned tensor. Default: ``False``.
  10527. Returns:
  10528. Tensor: A 2-D tensor with ones on the diagonal and zeros elsewhere
  10529. Example::
  10530. >>> torch.eye(3)
  10531. tensor([[ 1., 0., 0.],
  10532. [ 0., 1., 0.],
  10533. [ 0., 0., 1.]])
  10534. """
  10535. @overload
  10536. def eye(
  10537. n: _int | SymInt,
  10538. m: _int | SymInt,
  10539. *,
  10540. out: Tensor | None = None,
  10541. dtype: _dtype | None = None,
  10542. layout: _layout | None = None,
  10543. device: DeviceLikeType | None = None,
  10544. pin_memory: _bool | None = False,
  10545. requires_grad: _bool | None = False,
  10546. ) -> Tensor:
  10547. r"""
  10548. eye(n, m=None, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  10549. Returns a 2-D tensor with ones on the diagonal and zeros elsewhere.
  10550. Args:
  10551. n (int): the number of rows
  10552. m (int, optional): the number of columns with default being :attr:`n`
  10553. Keyword arguments:
  10554. out (Tensor, optional): the output tensor.
  10555. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  10556. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  10557. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  10558. Default: ``torch.strided``.
  10559. device (:class:`torch.device`, optional): the desired device of returned tensor.
  10560. Default: if ``None``, uses the current device for the default tensor type
  10561. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  10562. for CPU tensor types and the current CUDA device for CUDA tensor types.
  10563. requires_grad (bool, optional): If autograd should record operations on the
  10564. returned tensor. Default: ``False``.
  10565. Returns:
  10566. Tensor: A 2-D tensor with ones on the diagonal and zeros elsewhere
  10567. Example::
  10568. >>> torch.eye(3)
  10569. tensor([[ 1., 0., 0.],
  10570. [ 0., 1., 0.],
  10571. [ 0., 0., 1.]])
  10572. """
  10573. def fake_quantize_per_channel_affine(
  10574. input: Tensor,
  10575. scale: Tensor,
  10576. zero_point: Tensor,
  10577. axis: _int,
  10578. quant_min: _int,
  10579. quant_max: _int,
  10580. ) -> Tensor:
  10581. r"""
  10582. fake_quantize_per_channel_affine(input, scale, zero_point, axis, quant_min, quant_max) -> Tensor
  10583. Returns a new tensor with the data in :attr:`input` fake quantized per channel using :attr:`scale`,
  10584. :attr:`zero_point`, :attr:`quant_min` and :attr:`quant_max`, across the channel specified by :attr:`axis`.
  10585. .. math::
  10586. \text{output} = (
  10587. min(
  10588. \text{quant\_max},
  10589. max(
  10590. \text{quant\_min},
  10591. \text{std::nearby\_int}(\text{input} / \text{scale}) + \text{zero\_point}
  10592. )
  10593. ) - \text{zero\_point}
  10594. ) \times \text{scale}
  10595. Args:
  10596. input (Tensor): the input value(s), in ``torch.float32``
  10597. scale (Tensor): quantization scale, per channel in ``torch.float32``
  10598. zero_point (Tensor): quantization zero_point, per channel in ``torch.int32`` or ``torch.half`` or ``torch.float32``
  10599. axis (int32): channel axis
  10600. quant_min (int64): lower bound of the quantized domain
  10601. quant_max (int64): upper bound of the quantized domain
  10602. Returns:
  10603. Tensor: A newly fake_quantized per channel ``torch.float32`` tensor
  10604. Example::
  10605. >>> x = torch.randn(2, 2, 2)
  10606. >>> x
  10607. tensor([[[-0.2525, -0.0466],
  10608. [ 0.3491, -0.2168]],
  10609. [[-0.5906, 1.6258],
  10610. [ 0.6444, -0.0542]]])
  10611. >>> scales = (torch.randn(2) + 1) * 0.05
  10612. >>> scales
  10613. tensor([0.0475, 0.0486])
  10614. >>> zero_points = torch.zeros(2).to(torch.int32)
  10615. >>> zero_points
  10616. tensor([0, 0])
  10617. >>> torch.fake_quantize_per_channel_affine(x, scales, zero_points, 1, 0, 255)
  10618. tensor([[[0.0000, 0.0000],
  10619. [0.3405, 0.0000]],
  10620. [[0.0000, 1.6134],
  10621. [0.6323, 0.0000]]])
  10622. """
  10623. @overload
  10624. def fake_quantize_per_tensor_affine(
  10625. input: Tensor,
  10626. scale: _float,
  10627. zero_point: _int,
  10628. quant_min: _int,
  10629. quant_max: _int,
  10630. ) -> Tensor:
  10631. r"""
  10632. fake_quantize_per_tensor_affine(input, scale, zero_point, quant_min, quant_max) -> Tensor
  10633. Returns a new tensor with the data in :attr:`input` fake quantized using :attr:`scale`,
  10634. :attr:`zero_point`, :attr:`quant_min` and :attr:`quant_max`.
  10635. .. math::
  10636. \text{output} = (
  10637. min(
  10638. \text{quant\_max},
  10639. max(
  10640. \text{quant\_min},
  10641. \text{std::nearby\_int}(\text{input} / \text{scale}) + \text{zero\_point}
  10642. )
  10643. ) - \text{zero\_point}
  10644. ) \times \text{scale}
  10645. Args:
  10646. input (Tensor): the input value(s), ``torch.float32`` tensor
  10647. scale (double scalar or ``float32`` Tensor): quantization scale
  10648. zero_point (int64 scalar or ``int32`` Tensor): quantization zero_point
  10649. quant_min (int64): lower bound of the quantized domain
  10650. quant_max (int64): upper bound of the quantized domain
  10651. Returns:
  10652. Tensor: A newly fake_quantized ``torch.float32`` tensor
  10653. Example::
  10654. >>> x = torch.randn(4)
  10655. >>> x
  10656. tensor([ 0.0552, 0.9730, 0.3973, -1.0780])
  10657. >>> torch.fake_quantize_per_tensor_affine(x, 0.1, 0, 0, 255)
  10658. tensor([0.1000, 1.0000, 0.4000, 0.0000])
  10659. >>> torch.fake_quantize_per_tensor_affine(x, torch.tensor(0.1), torch.tensor(0), 0, 255)
  10660. tensor([0.1000, 1.0000, 0.4000, 0.0000])
  10661. """
  10662. @overload
  10663. def fake_quantize_per_tensor_affine(
  10664. input: Tensor,
  10665. scale: Tensor,
  10666. zero_point: Tensor,
  10667. quant_min: _int,
  10668. quant_max: _int,
  10669. ) -> Tensor:
  10670. r"""
  10671. fake_quantize_per_tensor_affine(input, scale, zero_point, quant_min, quant_max) -> Tensor
  10672. Returns a new tensor with the data in :attr:`input` fake quantized using :attr:`scale`,
  10673. :attr:`zero_point`, :attr:`quant_min` and :attr:`quant_max`.
  10674. .. math::
  10675. \text{output} = (
  10676. min(
  10677. \text{quant\_max},
  10678. max(
  10679. \text{quant\_min},
  10680. \text{std::nearby\_int}(\text{input} / \text{scale}) + \text{zero\_point}
  10681. )
  10682. ) - \text{zero\_point}
  10683. ) \times \text{scale}
  10684. Args:
  10685. input (Tensor): the input value(s), ``torch.float32`` tensor
  10686. scale (double scalar or ``float32`` Tensor): quantization scale
  10687. zero_point (int64 scalar or ``int32`` Tensor): quantization zero_point
  10688. quant_min (int64): lower bound of the quantized domain
  10689. quant_max (int64): upper bound of the quantized domain
  10690. Returns:
  10691. Tensor: A newly fake_quantized ``torch.float32`` tensor
  10692. Example::
  10693. >>> x = torch.randn(4)
  10694. >>> x
  10695. tensor([ 0.0552, 0.9730, 0.3973, -1.0780])
  10696. >>> torch.fake_quantize_per_tensor_affine(x, 0.1, 0, 0, 255)
  10697. tensor([0.1000, 1.0000, 0.4000, 0.0000])
  10698. >>> torch.fake_quantize_per_tensor_affine(x, torch.tensor(0.1), torch.tensor(0), 0, 255)
  10699. tensor([0.1000, 1.0000, 0.4000, 0.0000])
  10700. """
  10701. @overload
  10702. def fbgemm_linear_fp16_weight(
  10703. input: Tensor,
  10704. packed_weight: Tensor,
  10705. bias: Tensor,
  10706. ) -> Tensor: ...
  10707. @overload
  10708. def fbgemm_linear_fp16_weight(
  10709. input: Tensor,
  10710. packed_weight: Tensor,
  10711. bias: Tensor,
  10712. output: Tensor,
  10713. ) -> Tensor: ...
  10714. @overload
  10715. def fbgemm_linear_fp16_weight_fp32_activation(
  10716. input: Tensor,
  10717. packed_weight: Tensor,
  10718. bias: Tensor | None,
  10719. ) -> Tensor: ...
  10720. @overload
  10721. def fbgemm_linear_fp16_weight_fp32_activation(
  10722. input: Tensor,
  10723. packed_weight: Tensor,
  10724. bias: Tensor | None,
  10725. output: Tensor,
  10726. ) -> Tensor: ...
  10727. def fbgemm_linear_int8_weight(
  10728. input: Tensor,
  10729. weight: Tensor,
  10730. packed: Tensor,
  10731. col_offsets: Tensor,
  10732. weight_scale: Number | _complex,
  10733. weight_zero_point: Number | _complex,
  10734. bias: Tensor,
  10735. ) -> Tensor: ...
  10736. def fbgemm_linear_int8_weight_fp32_activation(
  10737. input: Tensor,
  10738. weight: Tensor,
  10739. packed: Tensor,
  10740. col_offsets: Tensor,
  10741. weight_scale: Number | _complex,
  10742. weight_zero_point: Number | _complex,
  10743. bias: Tensor,
  10744. ) -> Tensor: ...
  10745. def fbgemm_linear_quantize_weight(
  10746. input: Tensor,
  10747. ) -> tuple[Tensor, Tensor, _float, _int]: ...
  10748. def fbgemm_pack_gemm_matrix_fp16(input: Tensor) -> Tensor: ...
  10749. @overload
  10750. def fbgemm_pack_quantized_matrix(input: Tensor) -> Tensor: ...
  10751. @overload
  10752. def fbgemm_pack_quantized_matrix(input: Tensor, K: _int, N: _int) -> Tensor: ...
  10753. def feature_alpha_dropout(input: Tensor, p: _float, train: _bool) -> Tensor: ...
  10754. def feature_alpha_dropout_(
  10755. input: Tensor,
  10756. p: _float,
  10757. train: _bool,
  10758. ) -> Tensor: ...
  10759. def feature_dropout(input: Tensor, p: _float, train: _bool) -> Tensor: ...
  10760. def feature_dropout_(input: Tensor, p: _float, train: _bool) -> Tensor: ...
  10761. @overload
  10762. def fill(input: Tensor, value: Tensor) -> Tensor: ...
  10763. @overload
  10764. def fill(input: Tensor, value: Number | _complex) -> Tensor: ...
  10765. @overload
  10766. def fill_(input: Tensor, value: Tensor) -> Tensor: ...
  10767. @overload
  10768. def fill_(input: Tensor, value: Number | _complex) -> Tensor: ...
  10769. def fix(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  10770. r"""
  10771. fix(input, *, out=None) -> Tensor
  10772. Alias for :func:`torch.trunc`
  10773. """
  10774. def fix_(input: Tensor) -> Tensor: ...
  10775. @overload
  10776. def flatten(
  10777. input: Tensor,
  10778. start_dim: _int = 0,
  10779. end_dim: _int = -1,
  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: _int,
  10811. end_dim: _int,
  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. start_dim: str | EllipsisType | None,
  10844. end_dim: str | EllipsisType | None,
  10845. out_dim: str | EllipsisType | None,
  10846. ) -> Tensor:
  10847. r"""
  10848. flatten(input, start_dim=0, end_dim=-1) -> Tensor
  10849. Flattens :attr:`input` by reshaping it into a one-dimensional tensor. If :attr:`start_dim` or :attr:`end_dim`
  10850. are passed, only dimensions starting with :attr:`start_dim` and ending with :attr:`end_dim` are flattened.
  10851. The order of elements in :attr:`input` is unchanged.
  10852. Unlike NumPy's flatten, which always copies input's data, this function may return the original object, a view,
  10853. or copy. If no dimensions are flattened, then the original object :attr:`input` is returned. Otherwise, if input can
  10854. be viewed as the flattened shape, then that view is returned. Finally, only if the input cannot be viewed as the
  10855. flattened shape is input's data copied. See :meth:`torch.Tensor.view` for details on when a view will be returned.
  10856. .. note::
  10857. Flattening a zero-dimensional tensor will return a one-dimensional view.
  10858. Args:
  10859. input (Tensor): the input tensor.
  10860. start_dim (int): the first dim to flatten
  10861. end_dim (int): the last dim to flatten
  10862. Example::
  10863. >>> t = torch.tensor([[[1, 2],
  10864. ... [3, 4]],
  10865. ... [[5, 6],
  10866. ... [7, 8]]])
  10867. >>> torch.flatten(t)
  10868. tensor([1, 2, 3, 4, 5, 6, 7, 8])
  10869. >>> torch.flatten(t, start_dim=1)
  10870. tensor([[1, 2, 3, 4],
  10871. [5, 6, 7, 8]])
  10872. """
  10873. @overload
  10874. def flatten(
  10875. input: Tensor,
  10876. dims: Sequence[str | EllipsisType | None],
  10877. out_dim: str | EllipsisType | None,
  10878. ) -> Tensor:
  10879. r"""
  10880. flatten(input, start_dim=0, end_dim=-1) -> Tensor
  10881. Flattens :attr:`input` by reshaping it into a one-dimensional tensor. If :attr:`start_dim` or :attr:`end_dim`
  10882. are passed, only dimensions starting with :attr:`start_dim` and ending with :attr:`end_dim` are flattened.
  10883. The order of elements in :attr:`input` is unchanged.
  10884. Unlike NumPy's flatten, which always copies input's data, this function may return the original object, a view,
  10885. or copy. If no dimensions are flattened, then the original object :attr:`input` is returned. Otherwise, if input can
  10886. be viewed as the flattened shape, then that view is returned. Finally, only if the input cannot be viewed as the
  10887. flattened shape is input's data copied. See :meth:`torch.Tensor.view` for details on when a view will be returned.
  10888. .. note::
  10889. Flattening a zero-dimensional tensor will return a one-dimensional view.
  10890. Args:
  10891. input (Tensor): the input tensor.
  10892. start_dim (int): the first dim to flatten
  10893. end_dim (int): the last dim to flatten
  10894. Example::
  10895. >>> t = torch.tensor([[[1, 2],
  10896. ... [3, 4]],
  10897. ... [[5, 6],
  10898. ... [7, 8]]])
  10899. >>> torch.flatten(t)
  10900. tensor([1, 2, 3, 4, 5, 6, 7, 8])
  10901. >>> torch.flatten(t, start_dim=1)
  10902. tensor([[1, 2, 3, 4],
  10903. [5, 6, 7, 8]])
  10904. """
  10905. def flip(input: Tensor, dims: _size) -> Tensor:
  10906. r"""
  10907. flip(input, dims) -> Tensor
  10908. Reverse the order of an n-D tensor along given axis in dims.
  10909. .. note::
  10910. `torch.flip` makes a copy of :attr:`input`'s data. This is different from NumPy's `np.flip`,
  10911. which returns a view in constant time. Since copying a tensor's data is more work than viewing that data,
  10912. `torch.flip` is expected to be slower than `np.flip`.
  10913. Args:
  10914. input (Tensor): the input tensor.
  10915. dims (a list or tuple): axis to flip on
  10916. Example::
  10917. >>> x = torch.arange(8).view(2, 2, 2)
  10918. >>> x
  10919. tensor([[[ 0, 1],
  10920. [ 2, 3]],
  10921. [[ 4, 5],
  10922. [ 6, 7]]])
  10923. >>> torch.flip(x, [0, 1])
  10924. tensor([[[ 6, 7],
  10925. [ 4, 5]],
  10926. [[ 2, 3],
  10927. [ 0, 1]]])
  10928. """
  10929. def fliplr(input: Tensor) -> Tensor:
  10930. r"""
  10931. fliplr(input) -> Tensor
  10932. Flip tensor in the left/right direction, returning a new tensor.
  10933. Flip the entries in each row in the left/right direction.
  10934. Columns are preserved, but appear in a different order than before.
  10935. Note:
  10936. Requires the tensor to be at least 2-D.
  10937. .. note::
  10938. `torch.fliplr` makes a copy of :attr:`input`'s data. This is different from NumPy's `np.fliplr`,
  10939. which returns a view in constant time. Since copying a tensor's data is more work than viewing that data,
  10940. `torch.fliplr` is expected to be slower than `np.fliplr`.
  10941. Args:
  10942. input (Tensor): Must be at least 2-dimensional.
  10943. Example::
  10944. >>> x = torch.arange(4).view(2, 2)
  10945. >>> x
  10946. tensor([[0, 1],
  10947. [2, 3]])
  10948. >>> torch.fliplr(x)
  10949. tensor([[1, 0],
  10950. [3, 2]])
  10951. """
  10952. def flipud(input: Tensor) -> Tensor:
  10953. r"""
  10954. flipud(input) -> Tensor
  10955. Flip tensor in the up/down direction, returning a new tensor.
  10956. Flip the entries in each column in the up/down direction.
  10957. Rows are preserved, but appear in a different order than before.
  10958. Note:
  10959. Requires the tensor to be at least 1-D.
  10960. .. note::
  10961. `torch.flipud` makes a copy of :attr:`input`'s data. This is different from NumPy's `np.flipud`,
  10962. which returns a view in constant time. Since copying a tensor's data is more work than viewing that data,
  10963. `torch.flipud` is expected to be slower than `np.flipud`.
  10964. Args:
  10965. input (Tensor): Must be at least 1-dimensional.
  10966. Example::
  10967. >>> x = torch.arange(4).view(2, 2)
  10968. >>> x
  10969. tensor([[0, 1],
  10970. [2, 3]])
  10971. >>> torch.flipud(x)
  10972. tensor([[2, 3],
  10973. [0, 1]])
  10974. """
  10975. @overload
  10976. def float_power(
  10977. input: Tensor,
  10978. exponent: Tensor,
  10979. *,
  10980. out: Tensor | None = None,
  10981. ) -> Tensor:
  10982. r"""
  10983. float_power(input, exponent, *, out=None) -> Tensor
  10984. Raises :attr:`input` to the power of :attr:`exponent`, elementwise, in double precision.
  10985. If neither input is complex returns a ``torch.float64`` tensor,
  10986. and if one or more inputs is complex returns a ``torch.complex128`` tensor.
  10987. .. note::
  10988. This function always computes in double precision, unlike :func:`torch.pow`,
  10989. which implements more typical :ref:`type promotion <type-promotion-doc>`.
  10990. This is useful when the computation needs to be performed in a wider or more precise dtype,
  10991. or the results of the computation may contain fractional values not representable in the input dtypes,
  10992. like when an integer base is raised to a negative integer exponent.
  10993. Args:
  10994. input (Tensor or Number): the base value(s)
  10995. exponent (Tensor or Number): the exponent value(s)
  10996. Keyword args:
  10997. out (Tensor, optional): the output tensor.
  10998. Example::
  10999. >>> a = torch.randint(10, (4,))
  11000. >>> a
  11001. tensor([6, 4, 7, 1])
  11002. >>> torch.float_power(a, 2)
  11003. tensor([36., 16., 49., 1.], dtype=torch.float64)
  11004. >>> a = torch.arange(1, 5)
  11005. >>> a
  11006. tensor([ 1, 2, 3, 4])
  11007. >>> exp = torch.tensor([2, -3, 4, -5])
  11008. >>> exp
  11009. tensor([ 2, -3, 4, -5])
  11010. >>> torch.float_power(a, exp)
  11011. tensor([1.0000e+00, 1.2500e-01, 8.1000e+01, 9.7656e-04], dtype=torch.float64)
  11012. """
  11013. @overload
  11014. def float_power(
  11015. self: Number | _complex,
  11016. exponent: Tensor,
  11017. *,
  11018. out: Tensor | None = None,
  11019. ) -> Tensor:
  11020. r"""
  11021. float_power(input, exponent, *, out=None) -> Tensor
  11022. Raises :attr:`input` to the power of :attr:`exponent`, elementwise, in double precision.
  11023. If neither input is complex returns a ``torch.float64`` tensor,
  11024. and if one or more inputs is complex returns a ``torch.complex128`` tensor.
  11025. .. note::
  11026. This function always computes in double precision, unlike :func:`torch.pow`,
  11027. which implements more typical :ref:`type promotion <type-promotion-doc>`.
  11028. This is useful when the computation needs to be performed in a wider or more precise dtype,
  11029. or the results of the computation may contain fractional values not representable in the input dtypes,
  11030. like when an integer base is raised to a negative integer exponent.
  11031. Args:
  11032. input (Tensor or Number): the base value(s)
  11033. exponent (Tensor or Number): the exponent value(s)
  11034. Keyword args:
  11035. out (Tensor, optional): the output tensor.
  11036. Example::
  11037. >>> a = torch.randint(10, (4,))
  11038. >>> a
  11039. tensor([6, 4, 7, 1])
  11040. >>> torch.float_power(a, 2)
  11041. tensor([36., 16., 49., 1.], dtype=torch.float64)
  11042. >>> a = torch.arange(1, 5)
  11043. >>> a
  11044. tensor([ 1, 2, 3, 4])
  11045. >>> exp = torch.tensor([2, -3, 4, -5])
  11046. >>> exp
  11047. tensor([ 2, -3, 4, -5])
  11048. >>> torch.float_power(a, exp)
  11049. tensor([1.0000e+00, 1.2500e-01, 8.1000e+01, 9.7656e-04], dtype=torch.float64)
  11050. """
  11051. @overload
  11052. def float_power(
  11053. input: Tensor,
  11054. exponent: Number | _complex,
  11055. *,
  11056. out: Tensor | None = None,
  11057. ) -> Tensor:
  11058. r"""
  11059. float_power(input, exponent, *, out=None) -> Tensor
  11060. Raises :attr:`input` to the power of :attr:`exponent`, elementwise, in double precision.
  11061. If neither input is complex returns a ``torch.float64`` tensor,
  11062. and if one or more inputs is complex returns a ``torch.complex128`` tensor.
  11063. .. note::
  11064. This function always computes in double precision, unlike :func:`torch.pow`,
  11065. which implements more typical :ref:`type promotion <type-promotion-doc>`.
  11066. This is useful when the computation needs to be performed in a wider or more precise dtype,
  11067. or the results of the computation may contain fractional values not representable in the input dtypes,
  11068. like when an integer base is raised to a negative integer exponent.
  11069. Args:
  11070. input (Tensor or Number): the base value(s)
  11071. exponent (Tensor or Number): the exponent value(s)
  11072. Keyword args:
  11073. out (Tensor, optional): the output tensor.
  11074. Example::
  11075. >>> a = torch.randint(10, (4,))
  11076. >>> a
  11077. tensor([6, 4, 7, 1])
  11078. >>> torch.float_power(a, 2)
  11079. tensor([36., 16., 49., 1.], dtype=torch.float64)
  11080. >>> a = torch.arange(1, 5)
  11081. >>> a
  11082. tensor([ 1, 2, 3, 4])
  11083. >>> exp = torch.tensor([2, -3, 4, -5])
  11084. >>> exp
  11085. tensor([ 2, -3, 4, -5])
  11086. >>> torch.float_power(a, exp)
  11087. tensor([1.0000e+00, 1.2500e-01, 8.1000e+01, 9.7656e-04], dtype=torch.float64)
  11088. """
  11089. def floor(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  11090. r"""
  11091. floor(input, *, out=None) -> Tensor
  11092. Returns a new tensor with the floor of the elements of :attr:`input`,
  11093. the largest integer less than or equal to each element.
  11094. For integer inputs, follows the array-api convention of returning a
  11095. copy of the input tensor.
  11096. .. math::
  11097. \text{out}_{i} = \left\lfloor \text{input}_{i} \right\rfloor
  11098. Args:
  11099. input (Tensor): the input tensor.
  11100. Keyword args:
  11101. out (Tensor, optional): the output tensor.
  11102. Example::
  11103. >>> a = torch.randn(4)
  11104. >>> a
  11105. tensor([-0.8166, 1.5308, -0.2530, -0.2091])
  11106. >>> torch.floor(a)
  11107. tensor([-1., 1., -1., -1.])
  11108. """
  11109. def floor_(input: Tensor) -> Tensor: ...
  11110. def floor_divide(
  11111. input: Tensor | Number,
  11112. other: Tensor | Number,
  11113. *,
  11114. out: Tensor | None = None,
  11115. ) -> Tensor:
  11116. r"""
  11117. floor_divide(input, other, *, out=None) -> Tensor
  11118. .. note::
  11119. Before PyTorch 1.13 :func:`torch.floor_divide` incorrectly performed
  11120. truncation division. To restore the previous behavior use
  11121. :func:`torch.div` with ``rounding_mode='trunc'``.
  11122. Computes :attr:`input` divided by :attr:`other`, elementwise, and floors
  11123. the result.
  11124. .. math::
  11125. \text{{out}}_i = \text{floor} \left( \frac{{\text{{input}}_i}}{{\text{{other}}_i}} \right)
  11126. Supports broadcasting to a common shape, type promotion, and integer and float inputs.
  11127. Args:
  11128. input (Tensor or Number): the dividend
  11129. other (Tensor or Number): the divisor
  11130. Keyword args:
  11131. out (Tensor, optional): the output tensor.
  11132. Example::
  11133. >>> a = torch.tensor([4.0, 3.0])
  11134. >>> b = torch.tensor([2.0, 2.0])
  11135. >>> torch.floor_divide(a, b)
  11136. tensor([2.0, 1.0])
  11137. >>> torch.floor_divide(a, 1.4)
  11138. tensor([2.0, 2.0])
  11139. """
  11140. def fmax(
  11141. input: Tensor,
  11142. other: Tensor,
  11143. *,
  11144. out: Tensor | None = None,
  11145. ) -> Tensor:
  11146. r"""
  11147. fmax(input, other, *, out=None) -> Tensor
  11148. Computes the element-wise maximum of :attr:`input` and :attr:`other`.
  11149. This is like :func:`torch.maximum` except it handles NaNs differently:
  11150. if exactly one of the two elements being compared is a NaN then the non-NaN element is taken as the maximum.
  11151. Only if both elements are NaN is NaN propagated.
  11152. This function is a wrapper around C++'s ``std::fmax`` and is similar to NumPy's ``fmax`` function.
  11153. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  11154. :ref:`type promotion <type-promotion-doc>`, and integer and floating-point inputs.
  11155. Args:
  11156. input (Tensor): the input tensor.
  11157. other (Tensor): the second input tensor
  11158. Keyword args:
  11159. out (Tensor, optional): the output tensor.
  11160. Example::
  11161. >>> a = torch.tensor([9.7, float('nan'), 3.1, float('nan')])
  11162. >>> b = torch.tensor([-2.2, 0.5, float('nan'), float('nan')])
  11163. >>> torch.fmax(a, b)
  11164. tensor([9.7000, 0.5000, 3.1000, nan])
  11165. """
  11166. def fmin(
  11167. input: Tensor,
  11168. other: Tensor,
  11169. *,
  11170. out: Tensor | None = None,
  11171. ) -> Tensor:
  11172. r"""
  11173. fmin(input, other, *, out=None) -> Tensor
  11174. Computes the element-wise minimum of :attr:`input` and :attr:`other`.
  11175. This is like :func:`torch.minimum` except it handles NaNs differently:
  11176. if exactly one of the two elements being compared is a NaN then the non-NaN element is taken as the minimum.
  11177. Only if both elements are NaN is NaN propagated.
  11178. This function is a wrapper around C++'s ``std::fmin`` and is similar to NumPy's ``fmin`` function.
  11179. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  11180. :ref:`type promotion <type-promotion-doc>`, and integer and floating-point inputs.
  11181. Args:
  11182. input (Tensor): the input tensor.
  11183. other (Tensor): the second input tensor
  11184. Keyword args:
  11185. out (Tensor, optional): the output tensor.
  11186. Example::
  11187. >>> a = torch.tensor([2.2, float('nan'), 2.1, float('nan')])
  11188. >>> b = torch.tensor([-9.3, 0.1, float('nan'), float('nan')])
  11189. >>> torch.fmin(a, b)
  11190. tensor([-9.3000, 0.1000, 2.1000, nan])
  11191. """
  11192. @overload
  11193. def fmod(
  11194. input: Tensor,
  11195. other: Tensor,
  11196. *,
  11197. out: Tensor | None = None,
  11198. ) -> Tensor:
  11199. r"""
  11200. fmod(input, other, *, out=None) -> Tensor
  11201. Applies C++'s `std::fmod <https://en.cppreference.com/w/cpp/numeric/math/fmod>`_ entrywise.
  11202. The result has the same sign as the dividend :attr:`input` and its absolute value
  11203. is less than that of :attr:`other`.
  11204. This function may be defined in terms of :func:`torch.div` as
  11205. .. code:: python
  11206. torch.fmod(a, b) == a - a.div(b, rounding_mode="trunc") * b
  11207. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  11208. :ref:`type promotion <type-promotion-doc>`, and integer and float inputs.
  11209. .. note::
  11210. When the divisor is zero, returns ``NaN`` for floating point dtypes
  11211. on both CPU and GPU; raises ``RuntimeError`` for integer division by
  11212. zero on CPU; Integer division by zero on GPU may return any value.
  11213. .. note::
  11214. Complex inputs are not supported. In some cases, it is not mathematically
  11215. possible to satisfy the definition of a modulo operation with complex numbers.
  11216. .. seealso::
  11217. :func:`torch.remainder` which implements Python's modulus operator.
  11218. This one is defined using division rounding down the result.
  11219. Args:
  11220. input (Tensor): the dividend
  11221. other (Tensor or Scalar): the divisor
  11222. Keyword args:
  11223. out (Tensor, optional): the output tensor.
  11224. Example::
  11225. >>> torch.fmod(torch.tensor([-3., -2, -1, 1, 2, 3]), 2)
  11226. tensor([-1., -0., -1., 1., 0., 1.])
  11227. >>> torch.fmod(torch.tensor([1, 2, 3, 4, 5]), -1.5)
  11228. tensor([1.0000, 0.5000, 0.0000, 1.0000, 0.5000])
  11229. """
  11230. @overload
  11231. def fmod(
  11232. input: Tensor,
  11233. other: Number | _complex,
  11234. *,
  11235. out: Tensor | None = None,
  11236. ) -> Tensor:
  11237. r"""
  11238. fmod(input, other, *, out=None) -> Tensor
  11239. Applies C++'s `std::fmod <https://en.cppreference.com/w/cpp/numeric/math/fmod>`_ entrywise.
  11240. The result has the same sign as the dividend :attr:`input` and its absolute value
  11241. is less than that of :attr:`other`.
  11242. This function may be defined in terms of :func:`torch.div` as
  11243. .. code:: python
  11244. torch.fmod(a, b) == a - a.div(b, rounding_mode="trunc") * b
  11245. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  11246. :ref:`type promotion <type-promotion-doc>`, and integer and float inputs.
  11247. .. note::
  11248. When the divisor is zero, returns ``NaN`` for floating point dtypes
  11249. on both CPU and GPU; raises ``RuntimeError`` for integer division by
  11250. zero on CPU; Integer division by zero on GPU may return any value.
  11251. .. note::
  11252. Complex inputs are not supported. In some cases, it is not mathematically
  11253. possible to satisfy the definition of a modulo operation with complex numbers.
  11254. .. seealso::
  11255. :func:`torch.remainder` which implements Python's modulus operator.
  11256. This one is defined using division rounding down the result.
  11257. Args:
  11258. input (Tensor): the dividend
  11259. other (Tensor or Scalar): the divisor
  11260. Keyword args:
  11261. out (Tensor, optional): the output tensor.
  11262. Example::
  11263. >>> torch.fmod(torch.tensor([-3., -2, -1, 1, 2, 3]), 2)
  11264. tensor([-1., -0., -1., 1., 0., 1.])
  11265. >>> torch.fmod(torch.tensor([1, 2, 3, 4, 5]), -1.5)
  11266. tensor([1.0000, 0.5000, 0.0000, 1.0000, 0.5000])
  11267. """
  11268. def frac(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  11269. r"""
  11270. frac(input, *, out=None) -> Tensor
  11271. Computes the fractional portion of each element in :attr:`input`.
  11272. .. math::
  11273. \text{out}_{i} = \text{input}_{i} - \left\lfloor |\text{input}_{i}| \right\rfloor * \operatorname{sgn}(\text{input}_{i})
  11274. Example::
  11275. >>> torch.frac(torch.tensor([1, 2.5, -3.2]))
  11276. tensor([ 0.0000, 0.5000, -0.2000])
  11277. """
  11278. def frac_(input: Tensor) -> Tensor: ...
  11279. def frexp(
  11280. input: Tensor,
  11281. *,
  11282. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  11283. ) -> torch.return_types.frexp:
  11284. r"""
  11285. frexp(input, *, out=None) -> (Tensor mantissa, Tensor exponent)
  11286. Decomposes :attr:`input` into mantissa and exponent tensors
  11287. such that :math:`\text{input} = \text{mantissa} \times 2^{\text{exponent}}`.
  11288. The range of mantissa is the open interval (-1, 1).
  11289. Supports float inputs.
  11290. Args:
  11291. input (Tensor): the input tensor
  11292. Keyword args:
  11293. out (tuple, optional): the output tensors
  11294. Example::
  11295. >>> x = torch.arange(9.)
  11296. >>> mantissa, exponent = torch.frexp(x)
  11297. >>> mantissa
  11298. tensor([0.0000, 0.5000, 0.5000, 0.7500, 0.5000, 0.6250, 0.7500, 0.8750, 0.5000])
  11299. >>> exponent
  11300. tensor([0, 1, 2, 2, 3, 3, 3, 3, 4], dtype=torch.int32)
  11301. >>> torch.ldexp(mantissa, exponent)
  11302. tensor([0., 1., 2., 3., 4., 5., 6., 7., 8.])
  11303. """
  11304. def frobenius_norm(
  11305. input: Tensor,
  11306. dim: _int | _size,
  11307. keepdim: _bool = False,
  11308. *,
  11309. out: Tensor | None = None,
  11310. ) -> Tensor: ...
  11311. def from_file(
  11312. filename: str,
  11313. shared: _bool | None = None,
  11314. size: _int | None = 0,
  11315. *,
  11316. dtype: _dtype | None = None,
  11317. layout: _layout | None = None,
  11318. device: DeviceLikeType | None = None,
  11319. pin_memory: _bool | None = False,
  11320. requires_grad: _bool | None = False,
  11321. ) -> Tensor:
  11322. r"""
  11323. from_file(filename, shared=None, size=0, *, dtype=None, layout=None, device=None, pin_memory=False)
  11324. Creates a CPU tensor with a storage backed by a memory-mapped file.
  11325. If ``shared`` is True, then memory is shared between processes. All changes are written to the file.
  11326. If ``shared`` is False, then changes to the tensor do not affect the file.
  11327. ``size`` is the number of elements in the Tensor. If ``shared`` is ``False``, then the file must contain
  11328. at least ``size * sizeof(dtype)`` bytes. If ``shared`` is ``True`` the file will be created if needed.
  11329. .. note::
  11330. Only CPU tensors can be mapped to files.
  11331. .. note::
  11332. For now, tensors with storages backed by a memory-mapped file cannot be created in pinned memory.
  11333. Args:
  11334. filename (str): file name to map
  11335. shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
  11336. underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
  11337. size (int): number of elements in the tensor
  11338. Keyword args:
  11339. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  11340. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  11341. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  11342. Default: ``torch.strided``.
  11343. device (:class:`torch.device`, optional): the desired device of returned tensor.
  11344. Default: if ``None``, uses the current device for the default tensor type
  11345. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  11346. for CPU tensor types and the current CUDA device for CUDA tensor types.
  11347. pin_memory (bool, optional): If set, returned tensor would be allocated in
  11348. the pinned memory. Works only for CPU tensors. Default: ``False``.
  11349. Example::
  11350. >>> t = torch.randn(2, 5, dtype=torch.float64)
  11351. >>> t.numpy().tofile('storage.pt')
  11352. >>> t_mapped = torch.from_file('storage.pt', shared=False, size=10, dtype=torch.float64)
  11353. """
  11354. def from_numpy(ndarray) -> Tensor:
  11355. r"""
  11356. from_numpy(ndarray) -> Tensor
  11357. Creates a :class:`Tensor` from a :class:`numpy.ndarray`.
  11358. The returned tensor and :attr:`ndarray` share the same memory. Modifications to
  11359. the tensor will be reflected in the :attr:`ndarray` and vice versa. The returned
  11360. tensor is not resizable.
  11361. It currently accepts :attr:`ndarray` with dtypes of ``numpy.float64``,
  11362. ``numpy.float32``, ``numpy.float16``, ``numpy.complex64``, ``numpy.complex128``,
  11363. ``numpy.int64``, ``numpy.int32``, ``numpy.int16``, ``numpy.int8``, ``numpy.uint8``,
  11364. and ``bool``.
  11365. .. warning::
  11366. Writing to a tensor created from a read-only NumPy array is not supported and will result in undefined behavior.
  11367. Example::
  11368. >>> a = numpy.array([1, 2, 3])
  11369. >>> t = torch.from_numpy(a)
  11370. >>> t
  11371. tensor([ 1, 2, 3])
  11372. >>> t[0] = -1
  11373. >>> a
  11374. array([-1, 2, 3])
  11375. """
  11376. def frombuffer(
  11377. buffer: Any,
  11378. *,
  11379. dtype: _dtype,
  11380. count: int = -1,
  11381. offset: int = 0,
  11382. requires_grad: _bool = False,
  11383. ) -> Tensor:
  11384. r"""
  11385. frombuffer(buffer, *, dtype, count=-1, offset=0, requires_grad=False) -> Tensor
  11386. Creates a 1-dimensional :class:`Tensor` from an object that implements
  11387. the Python buffer protocol.
  11388. Skips the first :attr:`offset` bytes in the buffer, and interprets the rest of
  11389. the raw bytes as a 1-dimensional tensor of type :attr:`dtype` with :attr:`count`
  11390. elements.
  11391. Note that either of the following must be true:
  11392. 1. :attr:`count` is a positive non-zero number, and the total number of bytes
  11393. in the buffer is more than :attr:`offset` plus :attr:`count` times the size
  11394. (in bytes) of :attr:`dtype`.
  11395. 2. :attr:`count` is negative, and the length (number of bytes) of the buffer
  11396. subtracted by the :attr:`offset` is a multiple of the size (in bytes) of
  11397. :attr:`dtype`.
  11398. The returned tensor and buffer share the same memory. Modifications to
  11399. the tensor will be reflected in the buffer and vice versa. The returned
  11400. tensor is not resizable.
  11401. .. note::
  11402. This function increments the reference count for the object that
  11403. owns the shared memory. Therefore, such memory will not be deallocated
  11404. before the returned tensor goes out of scope.
  11405. .. warning::
  11406. This function's behavior is undefined when passed an object implementing
  11407. the buffer protocol whose data is not on the CPU. Doing so is likely to
  11408. cause a segmentation fault.
  11409. .. warning::
  11410. This function does not try to infer the :attr:`dtype` (hence, it is not
  11411. optional). Passing a different :attr:`dtype` than its source may result
  11412. in unexpected behavior.
  11413. Args:
  11414. buffer (object): a Python object that exposes the buffer interface.
  11415. Keyword args:
  11416. dtype (:class:`torch.dtype`): the desired data type of returned tensor.
  11417. count (int, optional): the number of desired elements to be read.
  11418. If negative, all the elements (until the end of the buffer) will be
  11419. read. Default: -1.
  11420. offset (int, optional): the number of bytes to skip at the start of
  11421. the buffer. Default: 0.
  11422. requires_grad (bool, optional): If autograd should record operations on the
  11423. returned tensor. Default: ``False``.
  11424. Example::
  11425. >>> import array
  11426. >>> a = array.array('i', [1, 2, 3])
  11427. >>> t = torch.frombuffer(a, dtype=torch.int32)
  11428. >>> t
  11429. tensor([ 1, 2, 3])
  11430. >>> t[0] = -1
  11431. >>> a
  11432. array([-1, 2, 3])
  11433. >>> # Interprets the signed char bytes as 32-bit integers.
  11434. >>> # Each 4 signed char elements will be interpreted as
  11435. >>> # 1 signed 32-bit integer.
  11436. >>> import array
  11437. >>> a = array.array('b', [-1, 0, 0, 0])
  11438. >>> torch.frombuffer(a, dtype=torch.int32)
  11439. tensor([255], dtype=torch.int32)
  11440. """
  11441. @overload
  11442. def full(
  11443. size: _size,
  11444. fill_value: Number | _complex,
  11445. *,
  11446. out: Tensor | None = None,
  11447. layout: _layout = strided,
  11448. dtype: _dtype | None = None,
  11449. device: DeviceLikeType | None = None,
  11450. requires_grad: _bool = False,
  11451. pin_memory: _bool = False,
  11452. ) -> Tensor:
  11453. r"""
  11454. full(size, fill_value, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  11455. Creates a tensor of size :attr:`size` filled with :attr:`fill_value`. The
  11456. tensor's dtype is inferred from :attr:`fill_value`.
  11457. Args:
  11458. size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
  11459. shape of the output tensor.
  11460. fill_value (Scalar): the value to fill the output tensor with.
  11461. Keyword args:
  11462. out (Tensor, optional): the output tensor.
  11463. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  11464. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  11465. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  11466. Default: ``torch.strided``.
  11467. device (:class:`torch.device`, optional): the desired device of returned tensor.
  11468. Default: if ``None``, uses the current device for the default tensor type
  11469. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  11470. for CPU tensor types and the current CUDA device for CUDA tensor types.
  11471. requires_grad (bool, optional): If autograd should record operations on the
  11472. returned tensor. Default: ``False``.
  11473. Example::
  11474. >>> torch.full((2, 3), 3.141592)
  11475. tensor([[ 3.1416, 3.1416, 3.1416],
  11476. [ 3.1416, 3.1416, 3.1416]])
  11477. """
  11478. @overload
  11479. def full(
  11480. size: _size,
  11481. fill_value: Number | _complex,
  11482. *,
  11483. names: list[str | None],
  11484. layout: _layout = strided,
  11485. dtype: _dtype | None = None,
  11486. device: DeviceLikeType | None = None,
  11487. requires_grad: _bool = False,
  11488. pin_memory: _bool = False,
  11489. ) -> Tensor:
  11490. r"""
  11491. full(size, fill_value, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  11492. Creates a tensor of size :attr:`size` filled with :attr:`fill_value`. The
  11493. tensor's dtype is inferred from :attr:`fill_value`.
  11494. Args:
  11495. size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
  11496. shape of the output tensor.
  11497. fill_value (Scalar): the value to fill the output tensor with.
  11498. Keyword args:
  11499. out (Tensor, optional): the output tensor.
  11500. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  11501. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  11502. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  11503. Default: ``torch.strided``.
  11504. device (:class:`torch.device`, optional): the desired device of returned tensor.
  11505. Default: if ``None``, uses the current device for the default tensor type
  11506. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  11507. for CPU tensor types and the current CUDA device for CUDA tensor types.
  11508. requires_grad (bool, optional): If autograd should record operations on the
  11509. returned tensor. Default: ``False``.
  11510. Example::
  11511. >>> torch.full((2, 3), 3.141592)
  11512. tensor([[ 3.1416, 3.1416, 3.1416],
  11513. [ 3.1416, 3.1416, 3.1416]])
  11514. """
  11515. @overload
  11516. def full(
  11517. size: Sequence[_int | SymInt],
  11518. fill_value: Number | _complex,
  11519. *,
  11520. out: Tensor | None = None,
  11521. dtype: _dtype | None = None,
  11522. layout: _layout | None = None,
  11523. device: DeviceLikeType | None = None,
  11524. pin_memory: _bool | None = False,
  11525. requires_grad: _bool | None = False,
  11526. ) -> Tensor:
  11527. r"""
  11528. full(size, fill_value, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  11529. Creates a tensor of size :attr:`size` filled with :attr:`fill_value`. The
  11530. tensor's dtype is inferred from :attr:`fill_value`.
  11531. Args:
  11532. size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
  11533. shape of the output tensor.
  11534. fill_value (Scalar): the value to fill the output tensor with.
  11535. Keyword args:
  11536. out (Tensor, optional): the output tensor.
  11537. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  11538. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  11539. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  11540. Default: ``torch.strided``.
  11541. device (:class:`torch.device`, optional): the desired device of returned tensor.
  11542. Default: if ``None``, uses the current device for the default tensor type
  11543. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  11544. for CPU tensor types and the current CUDA device for CUDA tensor types.
  11545. requires_grad (bool, optional): If autograd should record operations on the
  11546. returned tensor. Default: ``False``.
  11547. Example::
  11548. >>> torch.full((2, 3), 3.141592)
  11549. tensor([[ 3.1416, 3.1416, 3.1416],
  11550. [ 3.1416, 3.1416, 3.1416]])
  11551. """
  11552. @overload
  11553. def full(
  11554. size: _size,
  11555. fill_value: Number | _complex,
  11556. *,
  11557. names: Sequence[str | EllipsisType | None] | None,
  11558. dtype: _dtype | None = None,
  11559. layout: _layout | None = None,
  11560. device: DeviceLikeType | None = None,
  11561. pin_memory: _bool | None = False,
  11562. requires_grad: _bool | None = False,
  11563. ) -> Tensor:
  11564. r"""
  11565. full(size, fill_value, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  11566. Creates a tensor of size :attr:`size` filled with :attr:`fill_value`. The
  11567. tensor's dtype is inferred from :attr:`fill_value`.
  11568. Args:
  11569. size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
  11570. shape of the output tensor.
  11571. fill_value (Scalar): the value to fill the output tensor with.
  11572. Keyword args:
  11573. out (Tensor, optional): the output tensor.
  11574. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  11575. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  11576. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  11577. Default: ``torch.strided``.
  11578. device (:class:`torch.device`, optional): the desired device of returned tensor.
  11579. Default: if ``None``, uses the current device for the default tensor type
  11580. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  11581. for CPU tensor types and the current CUDA device for CUDA tensor types.
  11582. requires_grad (bool, optional): If autograd should record operations on the
  11583. returned tensor. Default: ``False``.
  11584. Example::
  11585. >>> torch.full((2, 3), 3.141592)
  11586. tensor([[ 3.1416, 3.1416, 3.1416],
  11587. [ 3.1416, 3.1416, 3.1416]])
  11588. """
  11589. def full_like(
  11590. input: Tensor,
  11591. fill_value: Number | _complex,
  11592. *,
  11593. memory_format: memory_format | None = None,
  11594. dtype: _dtype | None = None,
  11595. layout: _layout | None = None,
  11596. device: DeviceLikeType | None = None,
  11597. pin_memory: _bool | None = False,
  11598. requires_grad: _bool | None = False,
  11599. ) -> Tensor:
  11600. r"""
  11601. full_like(input, fill_value, \*, dtype=None, layout=torch.strided, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  11602. Returns a tensor with the same size as :attr:`input` filled with :attr:`fill_value`.
  11603. ``torch.full_like(input, fill_value)`` is equivalent to
  11604. ``torch.full(input.size(), fill_value, dtype=input.dtype, layout=input.layout, device=input.device)``.
  11605. Args:
  11606. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  11607. fill_value: the number to fill the output tensor with.
  11608. Keyword args:
  11609. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  11610. Default: if ``None``, defaults to the dtype of :attr:`input`.
  11611. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  11612. Default: if ``None``, defaults to the layout of :attr:`input`.
  11613. device (:class:`torch.device`, optional): the desired device of returned tensor.
  11614. Default: if ``None``, defaults to the device of :attr:`input`.
  11615. requires_grad (bool, optional): If autograd should record operations on the
  11616. returned tensor. Default: ``False``.
  11617. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  11618. returned Tensor. Default: ``torch.preserve_format``.
  11619. Example::
  11620. >>> x = torch.ones(2, 3)
  11621. >>> torch.full_like(x, 3.141592)
  11622. tensor([[ 3.1416, 3.1416, 3.1416],
  11623. [ 3.1416, 3.1416, 3.1416]])
  11624. >>> torch.full_like(x, 7)
  11625. tensor([[7., 7., 7.],
  11626. [7., 7., 7.]])
  11627. >>> torch.full_like(x, 0.5, dtype=torch.int32)
  11628. tensor([[0, 0, 0],
  11629. [0, 0, 0]], dtype=torch.int32)
  11630. >>> y = torch.randn(3, 4, dtype=torch.float64)
  11631. >>> torch.full_like(y, -1.0)
  11632. tensor([[-1., -1., -1., -1.],
  11633. [-1., -1., -1., -1.],
  11634. [-1., -1., -1., -1.]], dtype=torch.float64)
  11635. """
  11636. def fused_moving_avg_obs_fake_quant(
  11637. input: Tensor,
  11638. observer_on: Tensor,
  11639. fake_quant_on: Tensor,
  11640. running_min: Tensor,
  11641. running_max: Tensor,
  11642. scale: Tensor,
  11643. zero_point: Tensor,
  11644. averaging_const: _float,
  11645. quant_min: _int,
  11646. quant_max: _int,
  11647. ch_axis: _int,
  11648. per_row_fake_quant: _bool = False,
  11649. symmetric_quant: _bool = False,
  11650. ) -> Tensor: ...
  11651. @overload
  11652. def gather(
  11653. input: Tensor,
  11654. dim: _int,
  11655. index: Tensor,
  11656. *,
  11657. sparse_grad: _bool = False,
  11658. out: Tensor | None = None,
  11659. ) -> Tensor:
  11660. r"""
  11661. gather(input, dim, index, *, sparse_grad=False, out=None) -> Tensor
  11662. Gathers values along an axis specified by `dim`.
  11663. For a 3-D tensor the output is specified by::
  11664. out[i][j][k] = input[index[i][j][k]][j][k] # if dim == 0
  11665. out[i][j][k] = input[i][index[i][j][k]][k] # if dim == 1
  11666. out[i][j][k] = input[i][j][index[i][j][k]] # if dim == 2
  11667. :attr:`input` and :attr:`index` must have the same number of dimensions.
  11668. It is also required that ``index.size(d) <= input.size(d)`` for all
  11669. dimensions ``d != dim``. :attr:`out` will have the same shape as :attr:`index`.
  11670. Note that ``input`` and ``index`` do not broadcast against each other.
  11671. When :attr:`index` is empty, we always return an empty output with the same shape
  11672. without further error checking.
  11673. Args:
  11674. input (Tensor): the source tensor
  11675. dim (int): the axis along which to index
  11676. index (LongTensor): the indices of elements to gather
  11677. Keyword arguments:
  11678. sparse_grad (bool, optional): If ``True``, gradient w.r.t. :attr:`input` will be a sparse tensor.
  11679. out (Tensor, optional): the destination tensor
  11680. Example::
  11681. >>> t = torch.tensor([[1, 2], [3, 4]])
  11682. >>> torch.gather(t, 1, torch.tensor([[0, 0], [1, 0]]))
  11683. tensor([[ 1, 1],
  11684. [ 4, 3]])
  11685. """
  11686. @overload
  11687. def gather(
  11688. input: Tensor,
  11689. dim: str | EllipsisType | None,
  11690. index: Tensor,
  11691. *,
  11692. sparse_grad: _bool = False,
  11693. out: Tensor | None = None,
  11694. ) -> Tensor:
  11695. r"""
  11696. gather(input, dim, index, *, sparse_grad=False, out=None) -> Tensor
  11697. Gathers values along an axis specified by `dim`.
  11698. For a 3-D tensor the output is specified by::
  11699. out[i][j][k] = input[index[i][j][k]][j][k] # if dim == 0
  11700. out[i][j][k] = input[i][index[i][j][k]][k] # if dim == 1
  11701. out[i][j][k] = input[i][j][index[i][j][k]] # if dim == 2
  11702. :attr:`input` and :attr:`index` must have the same number of dimensions.
  11703. It is also required that ``index.size(d) <= input.size(d)`` for all
  11704. dimensions ``d != dim``. :attr:`out` will have the same shape as :attr:`index`.
  11705. Note that ``input`` and ``index`` do not broadcast against each other.
  11706. When :attr:`index` is empty, we always return an empty output with the same shape
  11707. without further error checking.
  11708. Args:
  11709. input (Tensor): the source tensor
  11710. dim (int): the axis along which to index
  11711. index (LongTensor): the indices of elements to gather
  11712. Keyword arguments:
  11713. sparse_grad (bool, optional): If ``True``, gradient w.r.t. :attr:`input` will be a sparse tensor.
  11714. out (Tensor, optional): the destination tensor
  11715. Example::
  11716. >>> t = torch.tensor([[1, 2], [3, 4]])
  11717. >>> torch.gather(t, 1, torch.tensor([[0, 0], [1, 0]]))
  11718. tensor([[ 1, 1],
  11719. [ 4, 3]])
  11720. """
  11721. def gcd(
  11722. input: Tensor,
  11723. other: Tensor,
  11724. *,
  11725. out: Tensor | None = None,
  11726. ) -> Tensor:
  11727. r"""
  11728. gcd(input, other, *, out=None) -> Tensor
  11729. Computes the element-wise greatest common divisor (GCD) of :attr:`input` and :attr:`other`.
  11730. Both :attr:`input` and :attr:`other` must have integer types.
  11731. .. note::
  11732. This defines :math:`gcd(0, 0) = 0`.
  11733. Args:
  11734. input (Tensor): the input tensor.
  11735. other (Tensor): the second input tensor
  11736. Keyword arguments:
  11737. out (Tensor, optional): the output tensor.
  11738. Example::
  11739. >>> a = torch.tensor([5, 10, 15])
  11740. >>> b = torch.tensor([3, 4, 5])
  11741. >>> torch.gcd(a, b)
  11742. tensor([1, 2, 5])
  11743. >>> c = torch.tensor([3])
  11744. >>> torch.gcd(a, c)
  11745. tensor([1, 1, 3])
  11746. """
  11747. def gcd_(input: Tensor, other: Tensor) -> Tensor: ...
  11748. @overload
  11749. def ge(
  11750. input: Tensor,
  11751. other: Tensor,
  11752. *,
  11753. out: Tensor | None = None,
  11754. ) -> Tensor:
  11755. r"""
  11756. ge(input, other, *, out=None) -> Tensor
  11757. Computes :math:`\text{input} \geq \text{other}` element-wise.
  11758. The second argument can be a number or a tensor whose shape is
  11759. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  11760. Args:
  11761. input (Tensor): the tensor to compare
  11762. other (Tensor or float): the tensor or value to compare
  11763. Keyword args:
  11764. out (Tensor, optional): the output tensor.
  11765. Returns:
  11766. A boolean tensor that is True where :attr:`input` is greater than or equal to :attr:`other` and False elsewhere
  11767. Example::
  11768. >>> torch.ge(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  11769. tensor([[True, True], [False, True]])
  11770. """
  11771. @overload
  11772. def ge(
  11773. input: Tensor,
  11774. other: Number | _complex,
  11775. *,
  11776. out: Tensor | None = None,
  11777. ) -> Tensor:
  11778. r"""
  11779. ge(input, other, *, out=None) -> Tensor
  11780. Computes :math:`\text{input} \geq \text{other}` element-wise.
  11781. The second argument can be a number or a tensor whose shape is
  11782. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  11783. Args:
  11784. input (Tensor): the tensor to compare
  11785. other (Tensor or float): the tensor or value to compare
  11786. Keyword args:
  11787. out (Tensor, optional): the output tensor.
  11788. Returns:
  11789. A boolean tensor that is True where :attr:`input` is greater than or equal to :attr:`other` and False elsewhere
  11790. Example::
  11791. >>> torch.ge(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  11792. tensor([[True, True], [False, True]])
  11793. """
  11794. def geqrf(
  11795. input: Tensor,
  11796. *,
  11797. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  11798. ) -> torch.return_types.geqrf:
  11799. r"""
  11800. geqrf(input, *, out=None) -> (Tensor, Tensor)
  11801. This is a low-level function for calling LAPACK's geqrf directly. This function
  11802. returns a namedtuple (a, tau) as defined in `LAPACK documentation for geqrf`_ .
  11803. Computes a QR decomposition of :attr:`input`.
  11804. Both `Q` and `R` matrices are stored in the same output tensor `a`.
  11805. The elements of `R` are stored on and above the diagonal.
  11806. Elementary reflectors (or Householder vectors) implicitly defining matrix `Q`
  11807. are stored below the diagonal.
  11808. The results of this function can be used together with :func:`torch.linalg.householder_product`
  11809. to obtain the `Q` matrix or
  11810. with :func:`torch.ormqr`, which uses an implicit representation of the `Q` matrix,
  11811. for an efficient matrix-matrix multiplication.
  11812. See `LAPACK documentation for geqrf`_ for further details.
  11813. .. note::
  11814. See also :func:`torch.linalg.qr`, which computes Q and R matrices, and :func:`torch.linalg.lstsq`
  11815. with the ``driver="gels"`` option for a function that can solve matrix equations using a QR decomposition.
  11816. Args:
  11817. input (Tensor): the input matrix
  11818. Keyword args:
  11819. out (tuple, optional): the output tuple of (Tensor, Tensor). Ignored if `None`. Default: `None`.
  11820. .. _LAPACK documentation for geqrf:
  11821. http://www.netlib.org/lapack/explore-html/df/dc5/group__variants_g_ecomputational_ga3766ea903391b5cf9008132f7440ec7b.html
  11822. """
  11823. def ger(
  11824. input: Tensor,
  11825. vec2: Tensor,
  11826. *,
  11827. out: Tensor | None = None,
  11828. ) -> Tensor:
  11829. r"""
  11830. ger(input, vec2, *, out=None) -> Tensor
  11831. Alias of :func:`torch.outer`.
  11832. .. warning::
  11833. This function is deprecated and will be removed in a future PyTorch release.
  11834. Use :func:`torch.outer` instead.
  11835. """
  11836. def get_default_dtype() -> _dtype:
  11837. r"""
  11838. get_default_dtype() -> torch.dtype
  11839. Get the current default floating point :class:`torch.dtype`.
  11840. Example::
  11841. >>> torch.get_default_dtype() # initial default for floating point is torch.float32
  11842. torch.float32
  11843. >>> torch.set_default_dtype(torch.float64)
  11844. >>> torch.get_default_dtype() # default is now changed to torch.float64
  11845. torch.float64
  11846. """
  11847. def get_num_interop_threads() -> _int:
  11848. r"""
  11849. get_num_interop_threads() -> int
  11850. Returns the number of threads used for inter-op parallelism on CPU
  11851. (e.g. in JIT interpreter)
  11852. """
  11853. def get_num_threads() -> _int:
  11854. r"""
  11855. get_num_threads() -> int
  11856. Returns the number of threads used for parallelizing CPU operations
  11857. """
  11858. @overload
  11859. def gradient(
  11860. input: Tensor,
  11861. *,
  11862. spacing: Number | _complex | None = None,
  11863. dim: _int | None = None,
  11864. edge_order: _int = 1,
  11865. ) -> tuple[Tensor, ...]:
  11866. r"""
  11867. gradient(input, *, spacing=1, dim=None, edge_order=1) -> List of Tensors
  11868. Estimates the gradient of a function :math:`g : \mathbb{R}^n \rightarrow \mathbb{R}` in
  11869. one or more dimensions using the `second-order accurate central differences method
  11870. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ and
  11871. either first or second order estimates at the boundaries.
  11872. The gradient of :math:`g` is estimated using samples. By default, when :attr:`spacing` is not
  11873. specified, the samples are entirely described by :attr:`input`, and the mapping of input coordinates
  11874. to an output is the same as the tensor's mapping of indices to values. For example, for a three-dimensional
  11875. :attr:`input` the function described is :math:`g : \mathbb{R}^3 \rightarrow \mathbb{R}`, and
  11876. :math:`g(1, 2, 3)\ == input[1, 2, 3]`.
  11877. When :attr:`spacing` is specified, it modifies the relationship between :attr:`input` and input coordinates.
  11878. This is detailed in the "Keyword Arguments" section below.
  11879. The gradient is estimated by estimating each partial derivative of :math:`g` independently. This estimation is
  11880. accurate if :math:`g` is in :math:`C^3` (it has at least 3 continuous derivatives), and the estimation can be
  11881. improved by providing closer samples. Mathematically, the value at each interior point of a partial derivative
  11882. is estimated using `Taylor's theorem with remainder <https://en.wikipedia.org/wiki/Taylor%27s_theorem>`_.
  11883. Letting :math:`x` be an interior point with :math:`x-h_l` and :math:`x+h_r` be points neighboring
  11884. it to the left and right respectively, :math:`f(x+h_r)` and :math:`f(x-h_l)` can be estimated using:
  11885. .. math::
  11886. \begin{aligned}
  11887. 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) \\
  11888. 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) \\
  11889. \end{aligned}
  11890. Using the fact that :math:`f \in C^3` and solving the linear system, we derive:
  11891. .. math::
  11892. f'(x) \approx \frac{ {h_l}^2 f(x+h_r) - {h_r}^2 f(x-h_l)
  11893. + ({h_r}^2-{h_l}^2 ) f(x) }{ {h_r} {h_l}^2 + {h_r}^2 {h_l} }
  11894. .. note::
  11895. We estimate the gradient of functions in complex domain
  11896. :math:`g : \mathbb{C}^n \rightarrow \mathbb{C}` in the same way.
  11897. The value of each partial derivative at the boundary points is computed differently. See edge_order below.
  11898. Args:
  11899. input (``Tensor``): the tensor that represents the values of the function
  11900. Keyword args:
  11901. spacing (``scalar``, ``list of scalar``, ``list of Tensor``, optional): :attr:`spacing` can be used to modify
  11902. how the :attr:`input` tensor's indices relate to sample coordinates. If :attr:`spacing` is a scalar then
  11903. the indices are multiplied by the scalar to produce the coordinates. For example, if :attr:`spacing=2` the
  11904. indices (1, 2, 3) become coordinates (2, 4, 6). If :attr:`spacing` is a list of scalars then the corresponding
  11905. indices are multiplied. For example, if :attr:`spacing=(2, -1, 3)` the indices (1, 2, 3) become coordinates (2, -2, 9).
  11906. Finally, if :attr:`spacing` is a list of one-dimensional tensors then each tensor specifies the coordinates for
  11907. the corresponding dimension. For example, if the indices are (1, 2, 3) and the tensors are (t0, t1, t2), then
  11908. the coordinates are (t0[1], t1[2], t2[3])
  11909. dim (``int``, ``list of int``, optional): the dimension or dimensions to approximate the gradient over. By default
  11910. the partial gradient in every dimension is computed. Note that when :attr:`dim` is specified the elements of
  11911. the :attr:`spacing` argument must correspond with the specified dims."
  11912. edge_order (``int``, optional): 1 or 2, for `first-order
  11913. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ or
  11914. `second-order <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_
  11915. estimation of the boundary ("edge") values, respectively. Note that when :attr:`edge_order` is specified, each
  11916. dimension size of :attr:`input` should be at least edge_order+1
  11917. Examples::
  11918. >>> # Estimates the gradient of f(x)=x^2 at points [-2, -1, 2, 4]
  11919. >>> coordinates = (torch.tensor([-2., -1., 1., 4.]),)
  11920. >>> values = torch.tensor([4., 1., 1., 16.], )
  11921. >>> torch.gradient(values, spacing = coordinates)
  11922. (tensor([-3., -2., 2., 5.]),)
  11923. >>> # Estimates the gradient of the R^2 -> R function whose samples are
  11924. >>> # described by the tensor t. Implicit coordinates are [0, 1] for the outermost
  11925. >>> # dimension and [0, 1, 2, 3] for the innermost dimension, and function estimates
  11926. >>> # partial derivative for both dimensions.
  11927. >>> t = torch.tensor([[1, 2, 4, 8], [10, 20, 40, 80]])
  11928. >>> torch.gradient(t)
  11929. (tensor([[ 9., 18., 36., 72.],
  11930. [ 9., 18., 36., 72.]]),
  11931. tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  11932. [10.0000, 15.0000, 30.0000, 40.0000]]))
  11933. >>> # A scalar value for spacing modifies the relationship between tensor indices
  11934. >>> # and input coordinates by multiplying the indices to find the
  11935. >>> # coordinates. For example, below the indices of the innermost
  11936. >>> # 0, 1, 2, 3 translate to coordinates of [0, 2, 4, 6], and the indices of
  11937. >>> # the outermost dimension 0, 1 translate to coordinates of [0, 2].
  11938. >>> torch.gradient(t, spacing = 2.0) # dim = None (implicitly [0, 1])
  11939. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  11940. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  11941. tensor([[ 0.5000, 0.7500, 1.5000, 2.0000],
  11942. [ 5.0000, 7.5000, 15.0000, 20.0000]]))
  11943. >>> # doubling the spacing between samples halves the estimated partial gradients.
  11944. >>>
  11945. >>> # Estimates only the partial derivative for dimension 1
  11946. >>> torch.gradient(t, dim = 1) # spacing = None (implicitly 1.)
  11947. (tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  11948. [10.0000, 15.0000, 30.0000, 40.0000]]),)
  11949. >>> # When spacing is a list of scalars, the relationship between the tensor
  11950. >>> # indices and input coordinates changes based on dimension.
  11951. >>> # For example, below, the indices of the innermost dimension 0, 1, 2, 3 translate
  11952. >>> # to coordinates of [0, 3, 6, 9], and the indices of the outermost dimension
  11953. >>> # 0, 1 translate to coordinates of [0, 2].
  11954. >>> torch.gradient(t, spacing = [3., 2.])
  11955. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  11956. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  11957. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  11958. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  11959. >>> # The following example is a replication of the previous one with explicit
  11960. >>> # coordinates.
  11961. >>> coords = (torch.tensor([0, 2]), torch.tensor([0, 3, 6, 9]))
  11962. >>> torch.gradient(t, spacing = coords)
  11963. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  11964. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  11965. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  11966. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  11967. """
  11968. @overload
  11969. def gradient(
  11970. input: Tensor,
  11971. *,
  11972. spacing: Sequence[Number | _complex],
  11973. dim: _int | None = None,
  11974. edge_order: _int = 1,
  11975. ) -> tuple[Tensor, ...]:
  11976. r"""
  11977. gradient(input, *, spacing=1, dim=None, edge_order=1) -> List of Tensors
  11978. Estimates the gradient of a function :math:`g : \mathbb{R}^n \rightarrow \mathbb{R}` in
  11979. one or more dimensions using the `second-order accurate central differences method
  11980. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ and
  11981. either first or second order estimates at the boundaries.
  11982. The gradient of :math:`g` is estimated using samples. By default, when :attr:`spacing` is not
  11983. specified, the samples are entirely described by :attr:`input`, and the mapping of input coordinates
  11984. to an output is the same as the tensor's mapping of indices to values. For example, for a three-dimensional
  11985. :attr:`input` the function described is :math:`g : \mathbb{R}^3 \rightarrow \mathbb{R}`, and
  11986. :math:`g(1, 2, 3)\ == input[1, 2, 3]`.
  11987. When :attr:`spacing` is specified, it modifies the relationship between :attr:`input` and input coordinates.
  11988. This is detailed in the "Keyword Arguments" section below.
  11989. The gradient is estimated by estimating each partial derivative of :math:`g` independently. This estimation is
  11990. accurate if :math:`g` is in :math:`C^3` (it has at least 3 continuous derivatives), and the estimation can be
  11991. improved by providing closer samples. Mathematically, the value at each interior point of a partial derivative
  11992. is estimated using `Taylor's theorem with remainder <https://en.wikipedia.org/wiki/Taylor%27s_theorem>`_.
  11993. Letting :math:`x` be an interior point with :math:`x-h_l` and :math:`x+h_r` be points neighboring
  11994. it to the left and right respectively, :math:`f(x+h_r)` and :math:`f(x-h_l)` can be estimated using:
  11995. .. math::
  11996. \begin{aligned}
  11997. 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) \\
  11998. 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) \\
  11999. \end{aligned}
  12000. Using the fact that :math:`f \in C^3` and solving the linear system, we derive:
  12001. .. math::
  12002. f'(x) \approx \frac{ {h_l}^2 f(x+h_r) - {h_r}^2 f(x-h_l)
  12003. + ({h_r}^2-{h_l}^2 ) f(x) }{ {h_r} {h_l}^2 + {h_r}^2 {h_l} }
  12004. .. note::
  12005. We estimate the gradient of functions in complex domain
  12006. :math:`g : \mathbb{C}^n \rightarrow \mathbb{C}` in the same way.
  12007. The value of each partial derivative at the boundary points is computed differently. See edge_order below.
  12008. Args:
  12009. input (``Tensor``): the tensor that represents the values of the function
  12010. Keyword args:
  12011. spacing (``scalar``, ``list of scalar``, ``list of Tensor``, optional): :attr:`spacing` can be used to modify
  12012. how the :attr:`input` tensor's indices relate to sample coordinates. If :attr:`spacing` is a scalar then
  12013. the indices are multiplied by the scalar to produce the coordinates. For example, if :attr:`spacing=2` the
  12014. indices (1, 2, 3) become coordinates (2, 4, 6). If :attr:`spacing` is a list of scalars then the corresponding
  12015. indices are multiplied. For example, if :attr:`spacing=(2, -1, 3)` the indices (1, 2, 3) become coordinates (2, -2, 9).
  12016. Finally, if :attr:`spacing` is a list of one-dimensional tensors then each tensor specifies the coordinates for
  12017. the corresponding dimension. For example, if the indices are (1, 2, 3) and the tensors are (t0, t1, t2), then
  12018. the coordinates are (t0[1], t1[2], t2[3])
  12019. dim (``int``, ``list of int``, optional): the dimension or dimensions to approximate the gradient over. By default
  12020. the partial gradient in every dimension is computed. Note that when :attr:`dim` is specified the elements of
  12021. the :attr:`spacing` argument must correspond with the specified dims."
  12022. edge_order (``int``, optional): 1 or 2, for `first-order
  12023. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ or
  12024. `second-order <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_
  12025. estimation of the boundary ("edge") values, respectively. Note that when :attr:`edge_order` is specified, each
  12026. dimension size of :attr:`input` should be at least edge_order+1
  12027. Examples::
  12028. >>> # Estimates the gradient of f(x)=x^2 at points [-2, -1, 2, 4]
  12029. >>> coordinates = (torch.tensor([-2., -1., 1., 4.]),)
  12030. >>> values = torch.tensor([4., 1., 1., 16.], )
  12031. >>> torch.gradient(values, spacing = coordinates)
  12032. (tensor([-3., -2., 2., 5.]),)
  12033. >>> # Estimates the gradient of the R^2 -> R function whose samples are
  12034. >>> # described by the tensor t. Implicit coordinates are [0, 1] for the outermost
  12035. >>> # dimension and [0, 1, 2, 3] for the innermost dimension, and function estimates
  12036. >>> # partial derivative for both dimensions.
  12037. >>> t = torch.tensor([[1, 2, 4, 8], [10, 20, 40, 80]])
  12038. >>> torch.gradient(t)
  12039. (tensor([[ 9., 18., 36., 72.],
  12040. [ 9., 18., 36., 72.]]),
  12041. tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12042. [10.0000, 15.0000, 30.0000, 40.0000]]))
  12043. >>> # A scalar value for spacing modifies the relationship between tensor indices
  12044. >>> # and input coordinates by multiplying the indices to find the
  12045. >>> # coordinates. For example, below the indices of the innermost
  12046. >>> # 0, 1, 2, 3 translate to coordinates of [0, 2, 4, 6], and the indices of
  12047. >>> # the outermost dimension 0, 1 translate to coordinates of [0, 2].
  12048. >>> torch.gradient(t, spacing = 2.0) # dim = None (implicitly [0, 1])
  12049. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12050. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12051. tensor([[ 0.5000, 0.7500, 1.5000, 2.0000],
  12052. [ 5.0000, 7.5000, 15.0000, 20.0000]]))
  12053. >>> # doubling the spacing between samples halves the estimated partial gradients.
  12054. >>>
  12055. >>> # Estimates only the partial derivative for dimension 1
  12056. >>> torch.gradient(t, dim = 1) # spacing = None (implicitly 1.)
  12057. (tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12058. [10.0000, 15.0000, 30.0000, 40.0000]]),)
  12059. >>> # When spacing is a list of scalars, the relationship between the tensor
  12060. >>> # indices and input coordinates changes based on dimension.
  12061. >>> # For example, below, the indices of the innermost dimension 0, 1, 2, 3 translate
  12062. >>> # to coordinates of [0, 3, 6, 9], and the indices of the outermost dimension
  12063. >>> # 0, 1 translate to coordinates of [0, 2].
  12064. >>> torch.gradient(t, spacing = [3., 2.])
  12065. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12066. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12067. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12068. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12069. >>> # The following example is a replication of the previous one with explicit
  12070. >>> # coordinates.
  12071. >>> coords = (torch.tensor([0, 2]), torch.tensor([0, 3, 6, 9]))
  12072. >>> torch.gradient(t, spacing = coords)
  12073. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12074. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12075. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12076. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12077. """
  12078. @overload
  12079. def gradient(
  12080. input: Tensor,
  12081. *,
  12082. spacing: Sequence[Number | _complex],
  12083. dim: _size,
  12084. edge_order: _int = 1,
  12085. ) -> tuple[Tensor, ...]:
  12086. r"""
  12087. gradient(input, *, spacing=1, dim=None, edge_order=1) -> List of Tensors
  12088. Estimates the gradient of a function :math:`g : \mathbb{R}^n \rightarrow \mathbb{R}` in
  12089. one or more dimensions using the `second-order accurate central differences method
  12090. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ and
  12091. either first or second order estimates at the boundaries.
  12092. The gradient of :math:`g` is estimated using samples. By default, when :attr:`spacing` is not
  12093. specified, the samples are entirely described by :attr:`input`, and the mapping of input coordinates
  12094. to an output is the same as the tensor's mapping of indices to values. For example, for a three-dimensional
  12095. :attr:`input` the function described is :math:`g : \mathbb{R}^3 \rightarrow \mathbb{R}`, and
  12096. :math:`g(1, 2, 3)\ == input[1, 2, 3]`.
  12097. When :attr:`spacing` is specified, it modifies the relationship between :attr:`input` and input coordinates.
  12098. This is detailed in the "Keyword Arguments" section below.
  12099. The gradient is estimated by estimating each partial derivative of :math:`g` independently. This estimation is
  12100. accurate if :math:`g` is in :math:`C^3` (it has at least 3 continuous derivatives), and the estimation can be
  12101. improved by providing closer samples. Mathematically, the value at each interior point of a partial derivative
  12102. is estimated using `Taylor's theorem with remainder <https://en.wikipedia.org/wiki/Taylor%27s_theorem>`_.
  12103. Letting :math:`x` be an interior point with :math:`x-h_l` and :math:`x+h_r` be points neighboring
  12104. it to the left and right respectively, :math:`f(x+h_r)` and :math:`f(x-h_l)` can be estimated using:
  12105. .. math::
  12106. \begin{aligned}
  12107. 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) \\
  12108. 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) \\
  12109. \end{aligned}
  12110. Using the fact that :math:`f \in C^3` and solving the linear system, we derive:
  12111. .. math::
  12112. f'(x) \approx \frac{ {h_l}^2 f(x+h_r) - {h_r}^2 f(x-h_l)
  12113. + ({h_r}^2-{h_l}^2 ) f(x) }{ {h_r} {h_l}^2 + {h_r}^2 {h_l} }
  12114. .. note::
  12115. We estimate the gradient of functions in complex domain
  12116. :math:`g : \mathbb{C}^n \rightarrow \mathbb{C}` in the same way.
  12117. The value of each partial derivative at the boundary points is computed differently. See edge_order below.
  12118. Args:
  12119. input (``Tensor``): the tensor that represents the values of the function
  12120. Keyword args:
  12121. spacing (``scalar``, ``list of scalar``, ``list of Tensor``, optional): :attr:`spacing` can be used to modify
  12122. how the :attr:`input` tensor's indices relate to sample coordinates. If :attr:`spacing` is a scalar then
  12123. the indices are multiplied by the scalar to produce the coordinates. For example, if :attr:`spacing=2` the
  12124. indices (1, 2, 3) become coordinates (2, 4, 6). If :attr:`spacing` is a list of scalars then the corresponding
  12125. indices are multiplied. For example, if :attr:`spacing=(2, -1, 3)` the indices (1, 2, 3) become coordinates (2, -2, 9).
  12126. Finally, if :attr:`spacing` is a list of one-dimensional tensors then each tensor specifies the coordinates for
  12127. the corresponding dimension. For example, if the indices are (1, 2, 3) and the tensors are (t0, t1, t2), then
  12128. the coordinates are (t0[1], t1[2], t2[3])
  12129. dim (``int``, ``list of int``, optional): the dimension or dimensions to approximate the gradient over. By default
  12130. the partial gradient in every dimension is computed. Note that when :attr:`dim` is specified the elements of
  12131. the :attr:`spacing` argument must correspond with the specified dims."
  12132. edge_order (``int``, optional): 1 or 2, for `first-order
  12133. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ or
  12134. `second-order <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_
  12135. estimation of the boundary ("edge") values, respectively. Note that when :attr:`edge_order` is specified, each
  12136. dimension size of :attr:`input` should be at least edge_order+1
  12137. Examples::
  12138. >>> # Estimates the gradient of f(x)=x^2 at points [-2, -1, 2, 4]
  12139. >>> coordinates = (torch.tensor([-2., -1., 1., 4.]),)
  12140. >>> values = torch.tensor([4., 1., 1., 16.], )
  12141. >>> torch.gradient(values, spacing = coordinates)
  12142. (tensor([-3., -2., 2., 5.]),)
  12143. >>> # Estimates the gradient of the R^2 -> R function whose samples are
  12144. >>> # described by the tensor t. Implicit coordinates are [0, 1] for the outermost
  12145. >>> # dimension and [0, 1, 2, 3] for the innermost dimension, and function estimates
  12146. >>> # partial derivative for both dimensions.
  12147. >>> t = torch.tensor([[1, 2, 4, 8], [10, 20, 40, 80]])
  12148. >>> torch.gradient(t)
  12149. (tensor([[ 9., 18., 36., 72.],
  12150. [ 9., 18., 36., 72.]]),
  12151. tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12152. [10.0000, 15.0000, 30.0000, 40.0000]]))
  12153. >>> # A scalar value for spacing modifies the relationship between tensor indices
  12154. >>> # and input coordinates by multiplying the indices to find the
  12155. >>> # coordinates. For example, below the indices of the innermost
  12156. >>> # 0, 1, 2, 3 translate to coordinates of [0, 2, 4, 6], and the indices of
  12157. >>> # the outermost dimension 0, 1 translate to coordinates of [0, 2].
  12158. >>> torch.gradient(t, spacing = 2.0) # dim = None (implicitly [0, 1])
  12159. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12160. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12161. tensor([[ 0.5000, 0.7500, 1.5000, 2.0000],
  12162. [ 5.0000, 7.5000, 15.0000, 20.0000]]))
  12163. >>> # doubling the spacing between samples halves the estimated partial gradients.
  12164. >>>
  12165. >>> # Estimates only the partial derivative for dimension 1
  12166. >>> torch.gradient(t, dim = 1) # spacing = None (implicitly 1.)
  12167. (tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12168. [10.0000, 15.0000, 30.0000, 40.0000]]),)
  12169. >>> # When spacing is a list of scalars, the relationship between the tensor
  12170. >>> # indices and input coordinates changes based on dimension.
  12171. >>> # For example, below, the indices of the innermost dimension 0, 1, 2, 3 translate
  12172. >>> # to coordinates of [0, 3, 6, 9], and the indices of the outermost dimension
  12173. >>> # 0, 1 translate to coordinates of [0, 2].
  12174. >>> torch.gradient(t, spacing = [3., 2.])
  12175. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12176. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12177. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12178. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12179. >>> # The following example is a replication of the previous one with explicit
  12180. >>> # coordinates.
  12181. >>> coords = (torch.tensor([0, 2]), torch.tensor([0, 3, 6, 9]))
  12182. >>> torch.gradient(t, spacing = coords)
  12183. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12184. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12185. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12186. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12187. """
  12188. @overload
  12189. def gradient(
  12190. input: Tensor,
  12191. *,
  12192. spacing: tuple[Tensor, ...] | list[Tensor] | None,
  12193. dim: _int | None = None,
  12194. edge_order: _int = 1,
  12195. ) -> tuple[Tensor, ...]:
  12196. r"""
  12197. gradient(input, *, spacing=1, dim=None, edge_order=1) -> List of Tensors
  12198. Estimates the gradient of a function :math:`g : \mathbb{R}^n \rightarrow \mathbb{R}` in
  12199. one or more dimensions using the `second-order accurate central differences method
  12200. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ and
  12201. either first or second order estimates at the boundaries.
  12202. The gradient of :math:`g` is estimated using samples. By default, when :attr:`spacing` is not
  12203. specified, the samples are entirely described by :attr:`input`, and the mapping of input coordinates
  12204. to an output is the same as the tensor's mapping of indices to values. For example, for a three-dimensional
  12205. :attr:`input` the function described is :math:`g : \mathbb{R}^3 \rightarrow \mathbb{R}`, and
  12206. :math:`g(1, 2, 3)\ == input[1, 2, 3]`.
  12207. When :attr:`spacing` is specified, it modifies the relationship between :attr:`input` and input coordinates.
  12208. This is detailed in the "Keyword Arguments" section below.
  12209. The gradient is estimated by estimating each partial derivative of :math:`g` independently. This estimation is
  12210. accurate if :math:`g` is in :math:`C^3` (it has at least 3 continuous derivatives), and the estimation can be
  12211. improved by providing closer samples. Mathematically, the value at each interior point of a partial derivative
  12212. is estimated using `Taylor's theorem with remainder <https://en.wikipedia.org/wiki/Taylor%27s_theorem>`_.
  12213. Letting :math:`x` be an interior point with :math:`x-h_l` and :math:`x+h_r` be points neighboring
  12214. it to the left and right respectively, :math:`f(x+h_r)` and :math:`f(x-h_l)` can be estimated using:
  12215. .. math::
  12216. \begin{aligned}
  12217. 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) \\
  12218. 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) \\
  12219. \end{aligned}
  12220. Using the fact that :math:`f \in C^3` and solving the linear system, we derive:
  12221. .. math::
  12222. f'(x) \approx \frac{ {h_l}^2 f(x+h_r) - {h_r}^2 f(x-h_l)
  12223. + ({h_r}^2-{h_l}^2 ) f(x) }{ {h_r} {h_l}^2 + {h_r}^2 {h_l} }
  12224. .. note::
  12225. We estimate the gradient of functions in complex domain
  12226. :math:`g : \mathbb{C}^n \rightarrow \mathbb{C}` in the same way.
  12227. The value of each partial derivative at the boundary points is computed differently. See edge_order below.
  12228. Args:
  12229. input (``Tensor``): the tensor that represents the values of the function
  12230. Keyword args:
  12231. spacing (``scalar``, ``list of scalar``, ``list of Tensor``, optional): :attr:`spacing` can be used to modify
  12232. how the :attr:`input` tensor's indices relate to sample coordinates. If :attr:`spacing` is a scalar then
  12233. the indices are multiplied by the scalar to produce the coordinates. For example, if :attr:`spacing=2` the
  12234. indices (1, 2, 3) become coordinates (2, 4, 6). If :attr:`spacing` is a list of scalars then the corresponding
  12235. indices are multiplied. For example, if :attr:`spacing=(2, -1, 3)` the indices (1, 2, 3) become coordinates (2, -2, 9).
  12236. Finally, if :attr:`spacing` is a list of one-dimensional tensors then each tensor specifies the coordinates for
  12237. the corresponding dimension. For example, if the indices are (1, 2, 3) and the tensors are (t0, t1, t2), then
  12238. the coordinates are (t0[1], t1[2], t2[3])
  12239. dim (``int``, ``list of int``, optional): the dimension or dimensions to approximate the gradient over. By default
  12240. the partial gradient in every dimension is computed. Note that when :attr:`dim` is specified the elements of
  12241. the :attr:`spacing` argument must correspond with the specified dims."
  12242. edge_order (``int``, optional): 1 or 2, for `first-order
  12243. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ or
  12244. `second-order <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_
  12245. estimation of the boundary ("edge") values, respectively. Note that when :attr:`edge_order` is specified, each
  12246. dimension size of :attr:`input` should be at least edge_order+1
  12247. Examples::
  12248. >>> # Estimates the gradient of f(x)=x^2 at points [-2, -1, 2, 4]
  12249. >>> coordinates = (torch.tensor([-2., -1., 1., 4.]),)
  12250. >>> values = torch.tensor([4., 1., 1., 16.], )
  12251. >>> torch.gradient(values, spacing = coordinates)
  12252. (tensor([-3., -2., 2., 5.]),)
  12253. >>> # Estimates the gradient of the R^2 -> R function whose samples are
  12254. >>> # described by the tensor t. Implicit coordinates are [0, 1] for the outermost
  12255. >>> # dimension and [0, 1, 2, 3] for the innermost dimension, and function estimates
  12256. >>> # partial derivative for both dimensions.
  12257. >>> t = torch.tensor([[1, 2, 4, 8], [10, 20, 40, 80]])
  12258. >>> torch.gradient(t)
  12259. (tensor([[ 9., 18., 36., 72.],
  12260. [ 9., 18., 36., 72.]]),
  12261. tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12262. [10.0000, 15.0000, 30.0000, 40.0000]]))
  12263. >>> # A scalar value for spacing modifies the relationship between tensor indices
  12264. >>> # and input coordinates by multiplying the indices to find the
  12265. >>> # coordinates. For example, below the indices of the innermost
  12266. >>> # 0, 1, 2, 3 translate to coordinates of [0, 2, 4, 6], and the indices of
  12267. >>> # the outermost dimension 0, 1 translate to coordinates of [0, 2].
  12268. >>> torch.gradient(t, spacing = 2.0) # dim = None (implicitly [0, 1])
  12269. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12270. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12271. tensor([[ 0.5000, 0.7500, 1.5000, 2.0000],
  12272. [ 5.0000, 7.5000, 15.0000, 20.0000]]))
  12273. >>> # doubling the spacing between samples halves the estimated partial gradients.
  12274. >>>
  12275. >>> # Estimates only the partial derivative for dimension 1
  12276. >>> torch.gradient(t, dim = 1) # spacing = None (implicitly 1.)
  12277. (tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12278. [10.0000, 15.0000, 30.0000, 40.0000]]),)
  12279. >>> # When spacing is a list of scalars, the relationship between the tensor
  12280. >>> # indices and input coordinates changes based on dimension.
  12281. >>> # For example, below, the indices of the innermost dimension 0, 1, 2, 3 translate
  12282. >>> # to coordinates of [0, 3, 6, 9], and the indices of the outermost dimension
  12283. >>> # 0, 1 translate to coordinates of [0, 2].
  12284. >>> torch.gradient(t, spacing = [3., 2.])
  12285. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12286. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12287. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12288. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12289. >>> # The following example is a replication of the previous one with explicit
  12290. >>> # coordinates.
  12291. >>> coords = (torch.tensor([0, 2]), torch.tensor([0, 3, 6, 9]))
  12292. >>> torch.gradient(t, spacing = coords)
  12293. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12294. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12295. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12296. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12297. """
  12298. @overload
  12299. def gradient(
  12300. input: Tensor,
  12301. *,
  12302. spacing: Number | _complex,
  12303. dim: _size,
  12304. edge_order: _int = 1,
  12305. ) -> tuple[Tensor, ...]:
  12306. r"""
  12307. gradient(input, *, spacing=1, dim=None, edge_order=1) -> List of Tensors
  12308. Estimates the gradient of a function :math:`g : \mathbb{R}^n \rightarrow \mathbb{R}` in
  12309. one or more dimensions using the `second-order accurate central differences method
  12310. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ and
  12311. either first or second order estimates at the boundaries.
  12312. The gradient of :math:`g` is estimated using samples. By default, when :attr:`spacing` is not
  12313. specified, the samples are entirely described by :attr:`input`, and the mapping of input coordinates
  12314. to an output is the same as the tensor's mapping of indices to values. For example, for a three-dimensional
  12315. :attr:`input` the function described is :math:`g : \mathbb{R}^3 \rightarrow \mathbb{R}`, and
  12316. :math:`g(1, 2, 3)\ == input[1, 2, 3]`.
  12317. When :attr:`spacing` is specified, it modifies the relationship between :attr:`input` and input coordinates.
  12318. This is detailed in the "Keyword Arguments" section below.
  12319. The gradient is estimated by estimating each partial derivative of :math:`g` independently. This estimation is
  12320. accurate if :math:`g` is in :math:`C^3` (it has at least 3 continuous derivatives), and the estimation can be
  12321. improved by providing closer samples. Mathematically, the value at each interior point of a partial derivative
  12322. is estimated using `Taylor's theorem with remainder <https://en.wikipedia.org/wiki/Taylor%27s_theorem>`_.
  12323. Letting :math:`x` be an interior point with :math:`x-h_l` and :math:`x+h_r` be points neighboring
  12324. it to the left and right respectively, :math:`f(x+h_r)` and :math:`f(x-h_l)` can be estimated using:
  12325. .. math::
  12326. \begin{aligned}
  12327. 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) \\
  12328. 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) \\
  12329. \end{aligned}
  12330. Using the fact that :math:`f \in C^3` and solving the linear system, we derive:
  12331. .. math::
  12332. f'(x) \approx \frac{ {h_l}^2 f(x+h_r) - {h_r}^2 f(x-h_l)
  12333. + ({h_r}^2-{h_l}^2 ) f(x) }{ {h_r} {h_l}^2 + {h_r}^2 {h_l} }
  12334. .. note::
  12335. We estimate the gradient of functions in complex domain
  12336. :math:`g : \mathbb{C}^n \rightarrow \mathbb{C}` in the same way.
  12337. The value of each partial derivative at the boundary points is computed differently. See edge_order below.
  12338. Args:
  12339. input (``Tensor``): the tensor that represents the values of the function
  12340. Keyword args:
  12341. spacing (``scalar``, ``list of scalar``, ``list of Tensor``, optional): :attr:`spacing` can be used to modify
  12342. how the :attr:`input` tensor's indices relate to sample coordinates. If :attr:`spacing` is a scalar then
  12343. the indices are multiplied by the scalar to produce the coordinates. For example, if :attr:`spacing=2` the
  12344. indices (1, 2, 3) become coordinates (2, 4, 6). If :attr:`spacing` is a list of scalars then the corresponding
  12345. indices are multiplied. For example, if :attr:`spacing=(2, -1, 3)` the indices (1, 2, 3) become coordinates (2, -2, 9).
  12346. Finally, if :attr:`spacing` is a list of one-dimensional tensors then each tensor specifies the coordinates for
  12347. the corresponding dimension. For example, if the indices are (1, 2, 3) and the tensors are (t0, t1, t2), then
  12348. the coordinates are (t0[1], t1[2], t2[3])
  12349. dim (``int``, ``list of int``, optional): the dimension or dimensions to approximate the gradient over. By default
  12350. the partial gradient in every dimension is computed. Note that when :attr:`dim` is specified the elements of
  12351. the :attr:`spacing` argument must correspond with the specified dims."
  12352. edge_order (``int``, optional): 1 or 2, for `first-order
  12353. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ or
  12354. `second-order <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_
  12355. estimation of the boundary ("edge") values, respectively. Note that when :attr:`edge_order` is specified, each
  12356. dimension size of :attr:`input` should be at least edge_order+1
  12357. Examples::
  12358. >>> # Estimates the gradient of f(x)=x^2 at points [-2, -1, 2, 4]
  12359. >>> coordinates = (torch.tensor([-2., -1., 1., 4.]),)
  12360. >>> values = torch.tensor([4., 1., 1., 16.], )
  12361. >>> torch.gradient(values, spacing = coordinates)
  12362. (tensor([-3., -2., 2., 5.]),)
  12363. >>> # Estimates the gradient of the R^2 -> R function whose samples are
  12364. >>> # described by the tensor t. Implicit coordinates are [0, 1] for the outermost
  12365. >>> # dimension and [0, 1, 2, 3] for the innermost dimension, and function estimates
  12366. >>> # partial derivative for both dimensions.
  12367. >>> t = torch.tensor([[1, 2, 4, 8], [10, 20, 40, 80]])
  12368. >>> torch.gradient(t)
  12369. (tensor([[ 9., 18., 36., 72.],
  12370. [ 9., 18., 36., 72.]]),
  12371. tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12372. [10.0000, 15.0000, 30.0000, 40.0000]]))
  12373. >>> # A scalar value for spacing modifies the relationship between tensor indices
  12374. >>> # and input coordinates by multiplying the indices to find the
  12375. >>> # coordinates. For example, below the indices of the innermost
  12376. >>> # 0, 1, 2, 3 translate to coordinates of [0, 2, 4, 6], and the indices of
  12377. >>> # the outermost dimension 0, 1 translate to coordinates of [0, 2].
  12378. >>> torch.gradient(t, spacing = 2.0) # dim = None (implicitly [0, 1])
  12379. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12380. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12381. tensor([[ 0.5000, 0.7500, 1.5000, 2.0000],
  12382. [ 5.0000, 7.5000, 15.0000, 20.0000]]))
  12383. >>> # doubling the spacing between samples halves the estimated partial gradients.
  12384. >>>
  12385. >>> # Estimates only the partial derivative for dimension 1
  12386. >>> torch.gradient(t, dim = 1) # spacing = None (implicitly 1.)
  12387. (tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12388. [10.0000, 15.0000, 30.0000, 40.0000]]),)
  12389. >>> # When spacing is a list of scalars, the relationship between the tensor
  12390. >>> # indices and input coordinates changes based on dimension.
  12391. >>> # For example, below, the indices of the innermost dimension 0, 1, 2, 3 translate
  12392. >>> # to coordinates of [0, 3, 6, 9], and the indices of the outermost dimension
  12393. >>> # 0, 1 translate to coordinates of [0, 2].
  12394. >>> torch.gradient(t, spacing = [3., 2.])
  12395. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12396. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12397. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12398. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12399. >>> # The following example is a replication of the previous one with explicit
  12400. >>> # coordinates.
  12401. >>> coords = (torch.tensor([0, 2]), torch.tensor([0, 3, 6, 9]))
  12402. >>> torch.gradient(t, spacing = coords)
  12403. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12404. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12405. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12406. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12407. """
  12408. @overload
  12409. def gradient(
  12410. input: Tensor,
  12411. *,
  12412. spacing: tuple[Tensor, ...] | list[Tensor] | None,
  12413. dim: _size,
  12414. edge_order: _int = 1,
  12415. ) -> tuple[Tensor, ...]:
  12416. r"""
  12417. gradient(input, *, spacing=1, dim=None, edge_order=1) -> List of Tensors
  12418. Estimates the gradient of a function :math:`g : \mathbb{R}^n \rightarrow \mathbb{R}` in
  12419. one or more dimensions using the `second-order accurate central differences method
  12420. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ and
  12421. either first or second order estimates at the boundaries.
  12422. The gradient of :math:`g` is estimated using samples. By default, when :attr:`spacing` is not
  12423. specified, the samples are entirely described by :attr:`input`, and the mapping of input coordinates
  12424. to an output is the same as the tensor's mapping of indices to values. For example, for a three-dimensional
  12425. :attr:`input` the function described is :math:`g : \mathbb{R}^3 \rightarrow \mathbb{R}`, and
  12426. :math:`g(1, 2, 3)\ == input[1, 2, 3]`.
  12427. When :attr:`spacing` is specified, it modifies the relationship between :attr:`input` and input coordinates.
  12428. This is detailed in the "Keyword Arguments" section below.
  12429. The gradient is estimated by estimating each partial derivative of :math:`g` independently. This estimation is
  12430. accurate if :math:`g` is in :math:`C^3` (it has at least 3 continuous derivatives), and the estimation can be
  12431. improved by providing closer samples. Mathematically, the value at each interior point of a partial derivative
  12432. is estimated using `Taylor's theorem with remainder <https://en.wikipedia.org/wiki/Taylor%27s_theorem>`_.
  12433. Letting :math:`x` be an interior point with :math:`x-h_l` and :math:`x+h_r` be points neighboring
  12434. it to the left and right respectively, :math:`f(x+h_r)` and :math:`f(x-h_l)` can be estimated using:
  12435. .. math::
  12436. \begin{aligned}
  12437. 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) \\
  12438. 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) \\
  12439. \end{aligned}
  12440. Using the fact that :math:`f \in C^3` and solving the linear system, we derive:
  12441. .. math::
  12442. f'(x) \approx \frac{ {h_l}^2 f(x+h_r) - {h_r}^2 f(x-h_l)
  12443. + ({h_r}^2-{h_l}^2 ) f(x) }{ {h_r} {h_l}^2 + {h_r}^2 {h_l} }
  12444. .. note::
  12445. We estimate the gradient of functions in complex domain
  12446. :math:`g : \mathbb{C}^n \rightarrow \mathbb{C}` in the same way.
  12447. The value of each partial derivative at the boundary points is computed differently. See edge_order below.
  12448. Args:
  12449. input (``Tensor``): the tensor that represents the values of the function
  12450. Keyword args:
  12451. spacing (``scalar``, ``list of scalar``, ``list of Tensor``, optional): :attr:`spacing` can be used to modify
  12452. how the :attr:`input` tensor's indices relate to sample coordinates. If :attr:`spacing` is a scalar then
  12453. the indices are multiplied by the scalar to produce the coordinates. For example, if :attr:`spacing=2` the
  12454. indices (1, 2, 3) become coordinates (2, 4, 6). If :attr:`spacing` is a list of scalars then the corresponding
  12455. indices are multiplied. For example, if :attr:`spacing=(2, -1, 3)` the indices (1, 2, 3) become coordinates (2, -2, 9).
  12456. Finally, if :attr:`spacing` is a list of one-dimensional tensors then each tensor specifies the coordinates for
  12457. the corresponding dimension. For example, if the indices are (1, 2, 3) and the tensors are (t0, t1, t2), then
  12458. the coordinates are (t0[1], t1[2], t2[3])
  12459. dim (``int``, ``list of int``, optional): the dimension or dimensions to approximate the gradient over. By default
  12460. the partial gradient in every dimension is computed. Note that when :attr:`dim` is specified the elements of
  12461. the :attr:`spacing` argument must correspond with the specified dims."
  12462. edge_order (``int``, optional): 1 or 2, for `first-order
  12463. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ or
  12464. `second-order <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_
  12465. estimation of the boundary ("edge") values, respectively. Note that when :attr:`edge_order` is specified, each
  12466. dimension size of :attr:`input` should be at least edge_order+1
  12467. Examples::
  12468. >>> # Estimates the gradient of f(x)=x^2 at points [-2, -1, 2, 4]
  12469. >>> coordinates = (torch.tensor([-2., -1., 1., 4.]),)
  12470. >>> values = torch.tensor([4., 1., 1., 16.], )
  12471. >>> torch.gradient(values, spacing = coordinates)
  12472. (tensor([-3., -2., 2., 5.]),)
  12473. >>> # Estimates the gradient of the R^2 -> R function whose samples are
  12474. >>> # described by the tensor t. Implicit coordinates are [0, 1] for the outermost
  12475. >>> # dimension and [0, 1, 2, 3] for the innermost dimension, and function estimates
  12476. >>> # partial derivative for both dimensions.
  12477. >>> t = torch.tensor([[1, 2, 4, 8], [10, 20, 40, 80]])
  12478. >>> torch.gradient(t)
  12479. (tensor([[ 9., 18., 36., 72.],
  12480. [ 9., 18., 36., 72.]]),
  12481. tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12482. [10.0000, 15.0000, 30.0000, 40.0000]]))
  12483. >>> # A scalar value for spacing modifies the relationship between tensor indices
  12484. >>> # and input coordinates by multiplying the indices to find the
  12485. >>> # coordinates. For example, below the indices of the innermost
  12486. >>> # 0, 1, 2, 3 translate to coordinates of [0, 2, 4, 6], and the indices of
  12487. >>> # the outermost dimension 0, 1 translate to coordinates of [0, 2].
  12488. >>> torch.gradient(t, spacing = 2.0) # dim = None (implicitly [0, 1])
  12489. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12490. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12491. tensor([[ 0.5000, 0.7500, 1.5000, 2.0000],
  12492. [ 5.0000, 7.5000, 15.0000, 20.0000]]))
  12493. >>> # doubling the spacing between samples halves the estimated partial gradients.
  12494. >>>
  12495. >>> # Estimates only the partial derivative for dimension 1
  12496. >>> torch.gradient(t, dim = 1) # spacing = None (implicitly 1.)
  12497. (tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12498. [10.0000, 15.0000, 30.0000, 40.0000]]),)
  12499. >>> # When spacing is a list of scalars, the relationship between the tensor
  12500. >>> # indices and input coordinates changes based on dimension.
  12501. >>> # For example, below, the indices of the innermost dimension 0, 1, 2, 3 translate
  12502. >>> # to coordinates of [0, 3, 6, 9], and the indices of the outermost dimension
  12503. >>> # 0, 1 translate to coordinates of [0, 2].
  12504. >>> torch.gradient(t, spacing = [3., 2.])
  12505. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12506. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12507. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12508. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12509. >>> # The following example is a replication of the previous one with explicit
  12510. >>> # coordinates.
  12511. >>> coords = (torch.tensor([0, 2]), torch.tensor([0, 3, 6, 9]))
  12512. >>> torch.gradient(t, spacing = coords)
  12513. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12514. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12515. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12516. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12517. """
  12518. @overload
  12519. def gradient(
  12520. input: Tensor,
  12521. *,
  12522. dim: _size,
  12523. edge_order: _int = 1,
  12524. ) -> tuple[Tensor, ...]:
  12525. r"""
  12526. gradient(input, *, spacing=1, dim=None, edge_order=1) -> List of Tensors
  12527. Estimates the gradient of a function :math:`g : \mathbb{R}^n \rightarrow \mathbb{R}` in
  12528. one or more dimensions using the `second-order accurate central differences method
  12529. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ and
  12530. either first or second order estimates at the boundaries.
  12531. The gradient of :math:`g` is estimated using samples. By default, when :attr:`spacing` is not
  12532. specified, the samples are entirely described by :attr:`input`, and the mapping of input coordinates
  12533. to an output is the same as the tensor's mapping of indices to values. For example, for a three-dimensional
  12534. :attr:`input` the function described is :math:`g : \mathbb{R}^3 \rightarrow \mathbb{R}`, and
  12535. :math:`g(1, 2, 3)\ == input[1, 2, 3]`.
  12536. When :attr:`spacing` is specified, it modifies the relationship between :attr:`input` and input coordinates.
  12537. This is detailed in the "Keyword Arguments" section below.
  12538. The gradient is estimated by estimating each partial derivative of :math:`g` independently. This estimation is
  12539. accurate if :math:`g` is in :math:`C^3` (it has at least 3 continuous derivatives), and the estimation can be
  12540. improved by providing closer samples. Mathematically, the value at each interior point of a partial derivative
  12541. is estimated using `Taylor's theorem with remainder <https://en.wikipedia.org/wiki/Taylor%27s_theorem>`_.
  12542. Letting :math:`x` be an interior point with :math:`x-h_l` and :math:`x+h_r` be points neighboring
  12543. it to the left and right respectively, :math:`f(x+h_r)` and :math:`f(x-h_l)` can be estimated using:
  12544. .. math::
  12545. \begin{aligned}
  12546. 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) \\
  12547. 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) \\
  12548. \end{aligned}
  12549. Using the fact that :math:`f \in C^3` and solving the linear system, we derive:
  12550. .. math::
  12551. f'(x) \approx \frac{ {h_l}^2 f(x+h_r) - {h_r}^2 f(x-h_l)
  12552. + ({h_r}^2-{h_l}^2 ) f(x) }{ {h_r} {h_l}^2 + {h_r}^2 {h_l} }
  12553. .. note::
  12554. We estimate the gradient of functions in complex domain
  12555. :math:`g : \mathbb{C}^n \rightarrow \mathbb{C}` in the same way.
  12556. The value of each partial derivative at the boundary points is computed differently. See edge_order below.
  12557. Args:
  12558. input (``Tensor``): the tensor that represents the values of the function
  12559. Keyword args:
  12560. spacing (``scalar``, ``list of scalar``, ``list of Tensor``, optional): :attr:`spacing` can be used to modify
  12561. how the :attr:`input` tensor's indices relate to sample coordinates. If :attr:`spacing` is a scalar then
  12562. the indices are multiplied by the scalar to produce the coordinates. For example, if :attr:`spacing=2` the
  12563. indices (1, 2, 3) become coordinates (2, 4, 6). If :attr:`spacing` is a list of scalars then the corresponding
  12564. indices are multiplied. For example, if :attr:`spacing=(2, -1, 3)` the indices (1, 2, 3) become coordinates (2, -2, 9).
  12565. Finally, if :attr:`spacing` is a list of one-dimensional tensors then each tensor specifies the coordinates for
  12566. the corresponding dimension. For example, if the indices are (1, 2, 3) and the tensors are (t0, t1, t2), then
  12567. the coordinates are (t0[1], t1[2], t2[3])
  12568. dim (``int``, ``list of int``, optional): the dimension or dimensions to approximate the gradient over. By default
  12569. the partial gradient in every dimension is computed. Note that when :attr:`dim` is specified the elements of
  12570. the :attr:`spacing` argument must correspond with the specified dims."
  12571. edge_order (``int``, optional): 1 or 2, for `first-order
  12572. <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ or
  12573. `second-order <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_
  12574. estimation of the boundary ("edge") values, respectively. Note that when :attr:`edge_order` is specified, each
  12575. dimension size of :attr:`input` should be at least edge_order+1
  12576. Examples::
  12577. >>> # Estimates the gradient of f(x)=x^2 at points [-2, -1, 2, 4]
  12578. >>> coordinates = (torch.tensor([-2., -1., 1., 4.]),)
  12579. >>> values = torch.tensor([4., 1., 1., 16.], )
  12580. >>> torch.gradient(values, spacing = coordinates)
  12581. (tensor([-3., -2., 2., 5.]),)
  12582. >>> # Estimates the gradient of the R^2 -> R function whose samples are
  12583. >>> # described by the tensor t. Implicit coordinates are [0, 1] for the outermost
  12584. >>> # dimension and [0, 1, 2, 3] for the innermost dimension, and function estimates
  12585. >>> # partial derivative for both dimensions.
  12586. >>> t = torch.tensor([[1, 2, 4, 8], [10, 20, 40, 80]])
  12587. >>> torch.gradient(t)
  12588. (tensor([[ 9., 18., 36., 72.],
  12589. [ 9., 18., 36., 72.]]),
  12590. tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12591. [10.0000, 15.0000, 30.0000, 40.0000]]))
  12592. >>> # A scalar value for spacing modifies the relationship between tensor indices
  12593. >>> # and input coordinates by multiplying the indices to find the
  12594. >>> # coordinates. For example, below the indices of the innermost
  12595. >>> # 0, 1, 2, 3 translate to coordinates of [0, 2, 4, 6], and the indices of
  12596. >>> # the outermost dimension 0, 1 translate to coordinates of [0, 2].
  12597. >>> torch.gradient(t, spacing = 2.0) # dim = None (implicitly [0, 1])
  12598. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12599. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12600. tensor([[ 0.5000, 0.7500, 1.5000, 2.0000],
  12601. [ 5.0000, 7.5000, 15.0000, 20.0000]]))
  12602. >>> # doubling the spacing between samples halves the estimated partial gradients.
  12603. >>>
  12604. >>> # Estimates only the partial derivative for dimension 1
  12605. >>> torch.gradient(t, dim = 1) # spacing = None (implicitly 1.)
  12606. (tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
  12607. [10.0000, 15.0000, 30.0000, 40.0000]]),)
  12608. >>> # When spacing is a list of scalars, the relationship between the tensor
  12609. >>> # indices and input coordinates changes based on dimension.
  12610. >>> # For example, below, the indices of the innermost dimension 0, 1, 2, 3 translate
  12611. >>> # to coordinates of [0, 3, 6, 9], and the indices of the outermost dimension
  12612. >>> # 0, 1 translate to coordinates of [0, 2].
  12613. >>> torch.gradient(t, spacing = [3., 2.])
  12614. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12615. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12616. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12617. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12618. >>> # The following example is a replication of the previous one with explicit
  12619. >>> # coordinates.
  12620. >>> coords = (torch.tensor([0, 2]), torch.tensor([0, 3, 6, 9]))
  12621. >>> torch.gradient(t, spacing = coords)
  12622. (tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
  12623. [ 4.5000, 9.0000, 18.0000, 36.0000]]),
  12624. tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
  12625. [ 3.3333, 5.0000, 10.0000, 13.3333]]))
  12626. """
  12627. @overload
  12628. def greater(
  12629. input: Tensor,
  12630. other: Tensor,
  12631. *,
  12632. out: Tensor | None = None,
  12633. ) -> Tensor:
  12634. r"""
  12635. greater(input, other, *, out=None) -> Tensor
  12636. Alias for :func:`torch.gt`.
  12637. """
  12638. @overload
  12639. def greater(
  12640. input: Tensor,
  12641. other: Number | _complex,
  12642. *,
  12643. out: Tensor | None = None,
  12644. ) -> Tensor:
  12645. r"""
  12646. greater(input, other, *, out=None) -> Tensor
  12647. Alias for :func:`torch.gt`.
  12648. """
  12649. @overload
  12650. def greater_equal(
  12651. input: Tensor,
  12652. other: Tensor,
  12653. *,
  12654. out: Tensor | None = None,
  12655. ) -> Tensor:
  12656. r"""
  12657. greater_equal(input, other, *, out=None) -> Tensor
  12658. Alias for :func:`torch.ge`.
  12659. """
  12660. @overload
  12661. def greater_equal(
  12662. input: Tensor,
  12663. other: Number | _complex,
  12664. *,
  12665. out: Tensor | None = None,
  12666. ) -> Tensor:
  12667. r"""
  12668. greater_equal(input, other, *, out=None) -> Tensor
  12669. Alias for :func:`torch.ge`.
  12670. """
  12671. def grid_sampler(
  12672. input: Tensor,
  12673. grid: Tensor,
  12674. interpolation_mode: _int,
  12675. padding_mode: _int,
  12676. align_corners: _bool,
  12677. ) -> Tensor: ...
  12678. def grid_sampler_2d(
  12679. input: Tensor,
  12680. grid: Tensor,
  12681. interpolation_mode: _int,
  12682. padding_mode: _int,
  12683. align_corners: _bool,
  12684. ) -> Tensor: ...
  12685. def grid_sampler_3d(
  12686. input: Tensor,
  12687. grid: Tensor,
  12688. interpolation_mode: _int,
  12689. padding_mode: _int,
  12690. align_corners: _bool,
  12691. ) -> Tensor: ...
  12692. def group_norm(
  12693. input: Tensor,
  12694. num_groups: _int,
  12695. weight: Tensor | None = None,
  12696. bias: Tensor | None = None,
  12697. eps: _float = 1e-05,
  12698. cudnn_enabled: _bool = True,
  12699. ) -> Tensor: ...
  12700. @overload
  12701. def gru(
  12702. data: Tensor,
  12703. batch_sizes: Tensor,
  12704. hx: Tensor,
  12705. params: tuple[Tensor, ...] | list[Tensor] | None,
  12706. has_biases: _bool,
  12707. num_layers: _int,
  12708. dropout: _float,
  12709. train: _bool,
  12710. bidirectional: _bool,
  12711. ) -> tuple[Tensor, Tensor]: ...
  12712. @overload
  12713. def gru(
  12714. input: Tensor,
  12715. hx: Tensor,
  12716. params: tuple[Tensor, ...] | list[Tensor] | None,
  12717. has_biases: _bool,
  12718. num_layers: _int,
  12719. dropout: _float,
  12720. train: _bool,
  12721. bidirectional: _bool,
  12722. batch_first: _bool,
  12723. ) -> tuple[Tensor, Tensor]: ...
  12724. def gru_cell(
  12725. input: Tensor,
  12726. hx: Tensor,
  12727. w_ih: Tensor,
  12728. w_hh: Tensor,
  12729. b_ih: Tensor | None = None,
  12730. b_hh: Tensor | None = None,
  12731. ) -> Tensor: ...
  12732. @overload
  12733. def gt(
  12734. input: Tensor,
  12735. other: Tensor,
  12736. *,
  12737. out: Tensor | None = None,
  12738. ) -> Tensor:
  12739. r"""
  12740. gt(input, other, *, out=None) -> Tensor
  12741. Computes :math:`\text{input} > \text{other}` element-wise.
  12742. The second argument can be a number or a tensor whose shape is
  12743. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  12744. Args:
  12745. input (Tensor): the tensor to compare
  12746. other (Tensor or float): the tensor or value to compare
  12747. Keyword args:
  12748. out (Tensor, optional): the output tensor.
  12749. Returns:
  12750. A boolean tensor that is True where :attr:`input` is greater than :attr:`other` and False elsewhere
  12751. Example::
  12752. >>> torch.gt(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  12753. tensor([[False, True], [False, False]])
  12754. """
  12755. @overload
  12756. def gt(
  12757. input: Tensor,
  12758. other: Number | _complex,
  12759. *,
  12760. out: Tensor | None = None,
  12761. ) -> Tensor:
  12762. r"""
  12763. gt(input, other, *, out=None) -> Tensor
  12764. Computes :math:`\text{input} > \text{other}` element-wise.
  12765. The second argument can be a number or a tensor whose shape is
  12766. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  12767. Args:
  12768. input (Tensor): the tensor to compare
  12769. other (Tensor or float): the tensor or value to compare
  12770. Keyword args:
  12771. out (Tensor, optional): the output tensor.
  12772. Returns:
  12773. A boolean tensor that is True where :attr:`input` is greater than :attr:`other` and False elsewhere
  12774. Example::
  12775. >>> torch.gt(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  12776. tensor([[False, True], [False, False]])
  12777. """
  12778. @overload
  12779. def hamming_window(
  12780. window_length: _int,
  12781. *,
  12782. dtype: _dtype | None = None,
  12783. layout: _layout | None = None,
  12784. device: DeviceLikeType | None = None,
  12785. pin_memory: _bool | None = False,
  12786. requires_grad: _bool | None = False,
  12787. ) -> Tensor:
  12788. r"""
  12789. hamming_window(window_length, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) -> Tensor
  12790. Hamming window function.
  12791. .. math::
  12792. w[n] = \alpha - \beta\ \cos \left( \frac{2 \pi n}{N - 1} \right),
  12793. where :math:`N` is the full window size.
  12794. The input :attr:`window_length` is a positive integer controlling the
  12795. returned window size. :attr:`periodic` flag determines whether the returned
  12796. window trims off the last duplicate value from the symmetric window and is
  12797. ready to be used as a periodic window with functions like
  12798. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  12799. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  12800. ``torch.hamming_window(L, periodic=True)`` equal to
  12801. ``torch.hamming_window(L + 1, periodic=False)[:-1])``.
  12802. .. note::
  12803. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  12804. .. note::
  12805. This is a generalized version of :meth:`torch.hann_window`.
  12806. Arguments:
  12807. window_length (int): the size of returned window
  12808. Keyword args:
  12809. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  12810. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  12811. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  12812. ``torch.strided`` (dense layout) is supported.
  12813. device (:class:`torch.device`, optional): the desired device of returned tensor.
  12814. Default: if ``None``, uses the current device for the default tensor type
  12815. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  12816. for CPU tensor types and the current CUDA device for CUDA tensor types.
  12817. pin_memory (bool, optional): If set, returned tensor would be allocated in
  12818. the pinned memory. Works only for CPU tensors. Default: ``False``.
  12819. requires_grad (bool, optional): If autograd should record operations on the
  12820. returned tensor. Default: ``False``.
  12821. Returns:
  12822. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  12823. .. function:: hamming_window(window_length, periodic, *, dtype=None, layout=None, device=None, \
  12824. pin_memory=False, requires_grad=False) -> Tensor
  12825. :noindex:
  12826. Hamming window function with periodic specified.
  12827. Arguments:
  12828. window_length (int): the size of returned window
  12829. periodic (bool): If True, returns a window to be used as periodic
  12830. function. If False, return a symmetric window.
  12831. Keyword args:
  12832. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  12833. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  12834. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  12835. ``torch.strided`` (dense layout) is supported.
  12836. device (:class:`torch.device`, optional): the desired device of returned tensor.
  12837. Default: if ``None``, uses the current device for the default tensor type
  12838. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  12839. for CPU tensor types and the current CUDA device for CUDA tensor types.
  12840. pin_memory (bool, optional): If set, returned tensor would be allocated in
  12841. the pinned memory. Works only for CPU tensors. Default: ``False``.
  12842. requires_grad (bool, optional): If autograd should record operations on the
  12843. returned tensor. Default: ``False``.
  12844. Returns:
  12845. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  12846. .. function:: hamming_window(window_length, periodic, float alpha, *, dtype=None, layout=None, device=None, \
  12847. pin_memory=False, requires_grad=False) -> Tensor
  12848. :noindex:
  12849. Hamming window function with periodic and alpha specified.
  12850. Arguments:
  12851. window_length (int): the size of returned window
  12852. periodic (bool): If True, returns a window to be used as periodic
  12853. function. If False, return a symmetric window.
  12854. alpha (float): The coefficient :math:`\alpha` in the equation above
  12855. Keyword args:
  12856. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  12857. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  12858. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  12859. ``torch.strided`` (dense layout) is supported.
  12860. device (:class:`torch.device`, optional): the desired device of returned tensor.
  12861. Default: if ``None``, uses the current device for the default tensor type
  12862. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  12863. for CPU tensor types and the current CUDA device for CUDA tensor types.
  12864. pin_memory (bool, optional): If set, returned tensor would be allocated in
  12865. the pinned memory. Works only for CPU tensors. Default: ``False``.
  12866. requires_grad (bool, optional): If autograd should record operations on the
  12867. returned tensor. Default: ``False``.
  12868. Returns:
  12869. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  12870. .. function:: hamming_window(window_length, periodic, float alpha, float beta, *, dtype=None, layout=None, \
  12871. device=None, pin_memory=False, requires_grad=False) -> Tensor
  12872. :noindex:
  12873. Hamming window function with periodic, alpha and beta specified.
  12874. Arguments:
  12875. window_length (int): the size of returned window
  12876. periodic (bool): If True, returns a window to be used as periodic
  12877. function. If False, return a symmetric window.
  12878. alpha (float): The coefficient :math:`\alpha` in the equation above
  12879. beta (float): The coefficient :math:`\beta` in the equation above
  12880. Keyword args:
  12881. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  12882. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  12883. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  12884. ``torch.strided`` (dense layout) is supported.
  12885. device (:class:`torch.device`, optional): the desired device of returned tensor.
  12886. Default: if ``None``, uses the current device for the default tensor type
  12887. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  12888. for CPU tensor types and the current CUDA device for CUDA tensor types.
  12889. pin_memory (bool, optional): If set, returned tensor would be allocated in
  12890. the pinned memory. Works only for CPU tensors. Default: ``False``.
  12891. requires_grad (bool, optional): If autograd should record operations on the
  12892. returned tensor. Default: ``False``.
  12893. Returns:
  12894. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  12895. """
  12896. @overload
  12897. def hamming_window(
  12898. window_length: _int,
  12899. periodic: _bool,
  12900. *,
  12901. dtype: _dtype | None = None,
  12902. layout: _layout | None = None,
  12903. device: DeviceLikeType | None = None,
  12904. pin_memory: _bool | None = False,
  12905. requires_grad: _bool | None = False,
  12906. ) -> Tensor:
  12907. r"""
  12908. hamming_window(window_length, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) -> Tensor
  12909. Hamming window function.
  12910. .. math::
  12911. w[n] = \alpha - \beta\ \cos \left( \frac{2 \pi n}{N - 1} \right),
  12912. where :math:`N` is the full window size.
  12913. The input :attr:`window_length` is a positive integer controlling the
  12914. returned window size. :attr:`periodic` flag determines whether the returned
  12915. window trims off the last duplicate value from the symmetric window and is
  12916. ready to be used as a periodic window with functions like
  12917. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  12918. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  12919. ``torch.hamming_window(L, periodic=True)`` equal to
  12920. ``torch.hamming_window(L + 1, periodic=False)[:-1])``.
  12921. .. note::
  12922. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  12923. .. note::
  12924. This is a generalized version of :meth:`torch.hann_window`.
  12925. Arguments:
  12926. window_length (int): the size of returned window
  12927. Keyword args:
  12928. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  12929. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  12930. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  12931. ``torch.strided`` (dense layout) is supported.
  12932. device (:class:`torch.device`, optional): the desired device of returned tensor.
  12933. Default: if ``None``, uses the current device for the default tensor type
  12934. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  12935. for CPU tensor types and the current CUDA device for CUDA tensor types.
  12936. pin_memory (bool, optional): If set, returned tensor would be allocated in
  12937. the pinned memory. Works only for CPU tensors. Default: ``False``.
  12938. requires_grad (bool, optional): If autograd should record operations on the
  12939. returned tensor. Default: ``False``.
  12940. Returns:
  12941. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  12942. .. function:: hamming_window(window_length, periodic, *, dtype=None, layout=None, device=None, \
  12943. pin_memory=False, requires_grad=False) -> Tensor
  12944. :noindex:
  12945. Hamming window function with periodic specified.
  12946. Arguments:
  12947. window_length (int): the size of returned window
  12948. periodic (bool): If True, returns a window to be used as periodic
  12949. function. If False, return a symmetric window.
  12950. Keyword args:
  12951. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  12952. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  12953. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  12954. ``torch.strided`` (dense layout) is supported.
  12955. device (:class:`torch.device`, optional): the desired device of returned tensor.
  12956. Default: if ``None``, uses the current device for the default tensor type
  12957. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  12958. for CPU tensor types and the current CUDA device for CUDA tensor types.
  12959. pin_memory (bool, optional): If set, returned tensor would be allocated in
  12960. the pinned memory. Works only for CPU tensors. Default: ``False``.
  12961. requires_grad (bool, optional): If autograd should record operations on the
  12962. returned tensor. Default: ``False``.
  12963. Returns:
  12964. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  12965. .. function:: hamming_window(window_length, periodic, float alpha, *, dtype=None, layout=None, device=None, \
  12966. pin_memory=False, requires_grad=False) -> Tensor
  12967. :noindex:
  12968. Hamming window function with periodic and alpha specified.
  12969. Arguments:
  12970. window_length (int): the size of returned window
  12971. periodic (bool): If True, returns a window to be used as periodic
  12972. function. If False, return a symmetric window.
  12973. alpha (float): The coefficient :math:`\alpha` in the equation above
  12974. Keyword args:
  12975. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  12976. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  12977. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  12978. ``torch.strided`` (dense layout) is supported.
  12979. device (:class:`torch.device`, optional): the desired device of returned tensor.
  12980. Default: if ``None``, uses the current device for the default tensor type
  12981. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  12982. for CPU tensor types and the current CUDA device for CUDA tensor types.
  12983. pin_memory (bool, optional): If set, returned tensor would be allocated in
  12984. the pinned memory. Works only for CPU tensors. Default: ``False``.
  12985. requires_grad (bool, optional): If autograd should record operations on the
  12986. returned tensor. Default: ``False``.
  12987. Returns:
  12988. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  12989. .. function:: hamming_window(window_length, periodic, float alpha, float beta, *, dtype=None, layout=None, \
  12990. device=None, pin_memory=False, requires_grad=False) -> Tensor
  12991. :noindex:
  12992. Hamming window function with periodic, alpha and beta specified.
  12993. Arguments:
  12994. window_length (int): the size of returned window
  12995. periodic (bool): If True, returns a window to be used as periodic
  12996. function. If False, return a symmetric window.
  12997. alpha (float): The coefficient :math:`\alpha` in the equation above
  12998. beta (float): The coefficient :math:`\beta` in the equation above
  12999. Keyword args:
  13000. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13001. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13002. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13003. ``torch.strided`` (dense layout) is supported.
  13004. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13005. Default: if ``None``, uses the current device for the default tensor type
  13006. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13007. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13008. pin_memory (bool, optional): If set, returned tensor would be allocated in
  13009. the pinned memory. Works only for CPU tensors. Default: ``False``.
  13010. requires_grad (bool, optional): If autograd should record operations on the
  13011. returned tensor. Default: ``False``.
  13012. Returns:
  13013. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  13014. """
  13015. @overload
  13016. def hamming_window(
  13017. window_length: _int,
  13018. periodic: _bool,
  13019. alpha: _float,
  13020. *,
  13021. dtype: _dtype | None = None,
  13022. layout: _layout | None = None,
  13023. device: DeviceLikeType | None = None,
  13024. pin_memory: _bool | None = False,
  13025. requires_grad: _bool | None = False,
  13026. ) -> Tensor:
  13027. r"""
  13028. hamming_window(window_length, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) -> Tensor
  13029. Hamming window function.
  13030. .. math::
  13031. w[n] = \alpha - \beta\ \cos \left( \frac{2 \pi n}{N - 1} \right),
  13032. where :math:`N` is the full window size.
  13033. The input :attr:`window_length` is a positive integer controlling the
  13034. returned window size. :attr:`periodic` flag determines whether the returned
  13035. window trims off the last duplicate value from the symmetric window and is
  13036. ready to be used as a periodic window with functions like
  13037. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  13038. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  13039. ``torch.hamming_window(L, periodic=True)`` equal to
  13040. ``torch.hamming_window(L + 1, periodic=False)[:-1])``.
  13041. .. note::
  13042. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  13043. .. note::
  13044. This is a generalized version of :meth:`torch.hann_window`.
  13045. Arguments:
  13046. window_length (int): the size of returned window
  13047. Keyword args:
  13048. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13049. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13050. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13051. ``torch.strided`` (dense layout) is supported.
  13052. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13053. Default: if ``None``, uses the current device for the default tensor type
  13054. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13055. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13056. pin_memory (bool, optional): If set, returned tensor would be allocated in
  13057. the pinned memory. Works only for CPU tensors. Default: ``False``.
  13058. requires_grad (bool, optional): If autograd should record operations on the
  13059. returned tensor. Default: ``False``.
  13060. Returns:
  13061. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  13062. .. function:: hamming_window(window_length, periodic, *, dtype=None, layout=None, device=None, \
  13063. pin_memory=False, requires_grad=False) -> Tensor
  13064. :noindex:
  13065. Hamming window function with periodic specified.
  13066. Arguments:
  13067. window_length (int): the size of returned window
  13068. periodic (bool): If True, returns a window to be used as periodic
  13069. function. If False, return a symmetric window.
  13070. Keyword args:
  13071. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13072. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13073. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13074. ``torch.strided`` (dense layout) is supported.
  13075. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13076. Default: if ``None``, uses the current device for the default tensor type
  13077. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13078. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13079. pin_memory (bool, optional): If set, returned tensor would be allocated in
  13080. the pinned memory. Works only for CPU tensors. Default: ``False``.
  13081. requires_grad (bool, optional): If autograd should record operations on the
  13082. returned tensor. Default: ``False``.
  13083. Returns:
  13084. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  13085. .. function:: hamming_window(window_length, periodic, float alpha, *, dtype=None, layout=None, device=None, \
  13086. pin_memory=False, requires_grad=False) -> Tensor
  13087. :noindex:
  13088. Hamming window function with periodic and alpha specified.
  13089. Arguments:
  13090. window_length (int): the size of returned window
  13091. periodic (bool): If True, returns a window to be used as periodic
  13092. function. If False, return a symmetric window.
  13093. alpha (float): The coefficient :math:`\alpha` in the equation above
  13094. Keyword args:
  13095. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13096. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13097. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13098. ``torch.strided`` (dense layout) is supported.
  13099. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13100. Default: if ``None``, uses the current device for the default tensor type
  13101. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13102. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13103. pin_memory (bool, optional): If set, returned tensor would be allocated in
  13104. the pinned memory. Works only for CPU tensors. Default: ``False``.
  13105. requires_grad (bool, optional): If autograd should record operations on the
  13106. returned tensor. Default: ``False``.
  13107. Returns:
  13108. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  13109. .. function:: hamming_window(window_length, periodic, float alpha, float beta, *, dtype=None, layout=None, \
  13110. device=None, pin_memory=False, requires_grad=False) -> Tensor
  13111. :noindex:
  13112. Hamming window function with periodic, alpha and beta specified.
  13113. Arguments:
  13114. window_length (int): the size of returned window
  13115. periodic (bool): If True, returns a window to be used as periodic
  13116. function. If False, return a symmetric window.
  13117. alpha (float): The coefficient :math:`\alpha` in the equation above
  13118. beta (float): The coefficient :math:`\beta` in the equation above
  13119. Keyword args:
  13120. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13121. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13122. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13123. ``torch.strided`` (dense layout) is supported.
  13124. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13125. Default: if ``None``, uses the current device for the default tensor type
  13126. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13127. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13128. pin_memory (bool, optional): If set, returned tensor would be allocated in
  13129. the pinned memory. Works only for CPU tensors. Default: ``False``.
  13130. requires_grad (bool, optional): If autograd should record operations on the
  13131. returned tensor. Default: ``False``.
  13132. Returns:
  13133. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  13134. """
  13135. @overload
  13136. def hamming_window(
  13137. window_length: _int,
  13138. periodic: _bool,
  13139. alpha: _float,
  13140. beta: _float,
  13141. *,
  13142. dtype: _dtype | None = None,
  13143. layout: _layout | None = None,
  13144. device: DeviceLikeType | None = None,
  13145. pin_memory: _bool | None = False,
  13146. requires_grad: _bool | None = False,
  13147. ) -> Tensor:
  13148. r"""
  13149. hamming_window(window_length, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) -> Tensor
  13150. Hamming window function.
  13151. .. math::
  13152. w[n] = \alpha - \beta\ \cos \left( \frac{2 \pi n}{N - 1} \right),
  13153. where :math:`N` is the full window size.
  13154. The input :attr:`window_length` is a positive integer controlling the
  13155. returned window size. :attr:`periodic` flag determines whether the returned
  13156. window trims off the last duplicate value from the symmetric window and is
  13157. ready to be used as a periodic window with functions like
  13158. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  13159. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  13160. ``torch.hamming_window(L, periodic=True)`` equal to
  13161. ``torch.hamming_window(L + 1, periodic=False)[:-1])``.
  13162. .. note::
  13163. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  13164. .. note::
  13165. This is a generalized version of :meth:`torch.hann_window`.
  13166. Arguments:
  13167. window_length (int): the size of returned window
  13168. Keyword args:
  13169. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13170. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13171. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13172. ``torch.strided`` (dense layout) is supported.
  13173. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13174. Default: if ``None``, uses the current device for the default tensor type
  13175. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13176. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13177. pin_memory (bool, optional): If set, returned tensor would be allocated in
  13178. the pinned memory. Works only for CPU tensors. Default: ``False``.
  13179. requires_grad (bool, optional): If autograd should record operations on the
  13180. returned tensor. Default: ``False``.
  13181. Returns:
  13182. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  13183. .. function:: hamming_window(window_length, periodic, *, dtype=None, layout=None, device=None, \
  13184. pin_memory=False, requires_grad=False) -> Tensor
  13185. :noindex:
  13186. Hamming window function with periodic specified.
  13187. Arguments:
  13188. window_length (int): the size of returned window
  13189. periodic (bool): If True, returns a window to be used as periodic
  13190. function. If False, return a symmetric window.
  13191. Keyword args:
  13192. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13193. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13194. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13195. ``torch.strided`` (dense layout) is supported.
  13196. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13197. Default: if ``None``, uses the current device for the default tensor type
  13198. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13199. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13200. pin_memory (bool, optional): If set, returned tensor would be allocated in
  13201. the pinned memory. Works only for CPU tensors. Default: ``False``.
  13202. requires_grad (bool, optional): If autograd should record operations on the
  13203. returned tensor. Default: ``False``.
  13204. Returns:
  13205. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  13206. .. function:: hamming_window(window_length, periodic, float alpha, *, dtype=None, layout=None, device=None, \
  13207. pin_memory=False, requires_grad=False) -> Tensor
  13208. :noindex:
  13209. Hamming window function with periodic and alpha specified.
  13210. Arguments:
  13211. window_length (int): the size of returned window
  13212. periodic (bool): If True, returns a window to be used as periodic
  13213. function. If False, return a symmetric window.
  13214. alpha (float): The coefficient :math:`\alpha` in the equation above
  13215. Keyword args:
  13216. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13217. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13218. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13219. ``torch.strided`` (dense layout) is supported.
  13220. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13221. Default: if ``None``, uses the current device for the default tensor type
  13222. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13223. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13224. pin_memory (bool, optional): If set, returned tensor would be allocated in
  13225. the pinned memory. Works only for CPU tensors. Default: ``False``.
  13226. requires_grad (bool, optional): If autograd should record operations on the
  13227. returned tensor. Default: ``False``.
  13228. Returns:
  13229. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  13230. .. function:: hamming_window(window_length, periodic, float alpha, float beta, *, dtype=None, layout=None, \
  13231. device=None, pin_memory=False, requires_grad=False) -> Tensor
  13232. :noindex:
  13233. Hamming window function with periodic, alpha and beta specified.
  13234. Arguments:
  13235. window_length (int): the size of returned window
  13236. periodic (bool): If True, returns a window to be used as periodic
  13237. function. If False, return a symmetric window.
  13238. alpha (float): The coefficient :math:`\alpha` in the equation above
  13239. beta (float): The coefficient :math:`\beta` in the equation above
  13240. Keyword args:
  13241. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13242. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13243. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13244. ``torch.strided`` (dense layout) is supported.
  13245. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13246. Default: if ``None``, uses the current device for the default tensor type
  13247. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13248. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13249. pin_memory (bool, optional): If set, returned tensor would be allocated in
  13250. the pinned memory. Works only for CPU tensors. Default: ``False``.
  13251. requires_grad (bool, optional): If autograd should record operations on the
  13252. returned tensor. Default: ``False``.
  13253. Returns:
  13254. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
  13255. """
  13256. @overload
  13257. def hann_window(
  13258. window_length: _int,
  13259. *,
  13260. dtype: _dtype | None = None,
  13261. layout: _layout | None = None,
  13262. device: DeviceLikeType | None = None,
  13263. pin_memory: _bool | None = False,
  13264. requires_grad: _bool | None = False,
  13265. ) -> Tensor:
  13266. r"""
  13267. hann_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  13268. Hann window function.
  13269. .. math::
  13270. w[n] = \frac{1}{2}\ \left[1 - \cos \left( \frac{2 \pi n}{N - 1} \right)\right] =
  13271. \sin^2 \left( \frac{\pi n}{N - 1} \right),
  13272. where :math:`N` is the full window size.
  13273. The input :attr:`window_length` is a positive integer controlling the
  13274. returned window size. :attr:`periodic` flag determines whether the returned
  13275. window trims off the last duplicate value from the symmetric window and is
  13276. ready to be used as a periodic window with functions like
  13277. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  13278. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  13279. ``torch.hann_window(L, periodic=True)`` equal to
  13280. ``torch.hann_window(L + 1, periodic=False)[:-1])``.
  13281. .. note::
  13282. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  13283. Arguments:
  13284. window_length (int): the size of returned window
  13285. periodic (bool, optional): If True, returns a window to be used as periodic
  13286. function. If False, return a symmetric window.
  13287. Keyword args:
  13288. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13289. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13290. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13291. ``torch.strided`` (dense layout) is supported.
  13292. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13293. Default: if ``None``, uses the current device for the default tensor type
  13294. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13295. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13296. requires_grad (bool, optional): If autograd should record operations on the
  13297. returned tensor. Default: ``False``.
  13298. Returns:
  13299. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window
  13300. """
  13301. @overload
  13302. def hann_window(
  13303. window_length: _int,
  13304. periodic: _bool,
  13305. *,
  13306. dtype: _dtype | None = None,
  13307. layout: _layout | None = None,
  13308. device: DeviceLikeType | None = None,
  13309. pin_memory: _bool | None = False,
  13310. requires_grad: _bool | None = False,
  13311. ) -> Tensor:
  13312. r"""
  13313. hann_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  13314. Hann window function.
  13315. .. math::
  13316. w[n] = \frac{1}{2}\ \left[1 - \cos \left( \frac{2 \pi n}{N - 1} \right)\right] =
  13317. \sin^2 \left( \frac{\pi n}{N - 1} \right),
  13318. where :math:`N` is the full window size.
  13319. The input :attr:`window_length` is a positive integer controlling the
  13320. returned window size. :attr:`periodic` flag determines whether the returned
  13321. window trims off the last duplicate value from the symmetric window and is
  13322. ready to be used as a periodic window with functions like
  13323. :meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
  13324. above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
  13325. ``torch.hann_window(L, periodic=True)`` equal to
  13326. ``torch.hann_window(L + 1, periodic=False)[:-1])``.
  13327. .. note::
  13328. If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
  13329. Arguments:
  13330. window_length (int): the size of returned window
  13331. periodic (bool, optional): If True, returns a window to be used as periodic
  13332. function. If False, return a symmetric window.
  13333. Keyword args:
  13334. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  13335. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
  13336. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  13337. ``torch.strided`` (dense layout) is supported.
  13338. device (:class:`torch.device`, optional): the desired device of returned tensor.
  13339. Default: if ``None``, uses the current device for the default tensor type
  13340. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  13341. for CPU tensor types and the current CUDA device for CUDA tensor types.
  13342. requires_grad (bool, optional): If autograd should record operations on the
  13343. returned tensor. Default: ``False``.
  13344. Returns:
  13345. Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window
  13346. """
  13347. def hardshrink(
  13348. input: Tensor,
  13349. lambd: Number | _complex = 0.5,
  13350. *,
  13351. out: Tensor | None = None,
  13352. ) -> Tensor: ...
  13353. def hash_tensor(
  13354. input: Tensor,
  13355. dim: _int | _size = (),
  13356. *,
  13357. keepdim: _bool = False,
  13358. mode: _int = 0,
  13359. out: Tensor | None = None,
  13360. ) -> Tensor:
  13361. r"""
  13362. hash_tensor(input, *, mode=0) -> Tensor
  13363. Returns a hash of all elements in the :attr:`input` tensor.
  13364. Currently only mode=0 (reduction via xor) is supported. The output will always
  13365. be of type ``torch.uint64``. The elements of ``input`` are upcasted to their
  13366. 64 bit float / integer equivalent and bitcasted to ``torch.uint64`` before
  13367. reduction via xor.
  13368. Args:
  13369. input (Tensor): the input tensor.
  13370. Keyword Args:
  13371. mode (int) : The hash to use. Default: 0 (xor_reduction)
  13372. Example::
  13373. >>> a = torch.randn(1, 3)
  13374. >>> a
  13375. tensor([[ 1.1918, -1.1813, 0.3373]])
  13376. >>> torch.hash_tensor(a)
  13377. tensor(13822780554648485888, dtype=torch.uint64)
  13378. .. function:: hash_tensor(input, dim, *, keepdim=False, mode=0) -> Tensor
  13379. :noindex:
  13380. Returns the hash of each row of the :attr:`input` tensor in the given
  13381. dimension :attr:`dim` given by mode. If :attr:`dim` is a list of dimensions,
  13382. reduce over all of them.
  13383. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  13384. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  13385. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  13386. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  13387. Args:
  13388. input (Tensor): the input tensor.
  13389. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  13390. If ``None``, all dimensions are reduced.
  13391. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  13392. Keyword Args:
  13393. mode (int) : The hash to use. Default: 0 (xor_reduction)
  13394. Example::
  13395. >>> a = torch.randn(2, 4)
  13396. >>> a
  13397. tensor([[ 0.1317, -0.5554, -1.4724, -1.1391],
  13398. [ 0.0778, -0.6070, 0.6375, 0.1798]])
  13399. >>> torch.hash_tensor(a, 1)
  13400. tensor([9233691267014066176, 9255993250844508160], dtype=torch.uint64)
  13401. """
  13402. def heaviside(
  13403. input: Tensor,
  13404. values: Tensor,
  13405. *,
  13406. out: Tensor | None = None,
  13407. ) -> Tensor:
  13408. r"""
  13409. heaviside(input, values, *, out=None) -> Tensor
  13410. Computes the Heaviside step function for each element in :attr:`input`.
  13411. The Heaviside step function is defined as:
  13412. .. math::
  13413. \text{{heaviside}}(input, values) = \begin{cases}
  13414. 0, & \text{if input < 0}\\
  13415. values, & \text{if input == 0}\\
  13416. 1, & \text{if input > 0}
  13417. \end{cases}
  13418. Args:
  13419. input (Tensor): the input tensor.
  13420. values (Tensor): The values to use where :attr:`input` is zero.
  13421. Keyword arguments:
  13422. out (Tensor, optional): the output tensor.
  13423. Example::
  13424. >>> input = torch.tensor([-1.5, 0, 2.0])
  13425. >>> values = torch.tensor([0.5])
  13426. >>> torch.heaviside(input, values)
  13427. tensor([0.0000, 0.5000, 1.0000])
  13428. >>> values = torch.tensor([1.2, -2.0, 3.5])
  13429. >>> torch.heaviside(input, values)
  13430. tensor([0., -2., 1.])
  13431. """
  13432. def hinge_embedding_loss(
  13433. input: Tensor,
  13434. target: Tensor,
  13435. margin: _float = 1.0,
  13436. reduction: _int = 1,
  13437. ) -> Tensor: ...
  13438. def histc(
  13439. input: Tensor,
  13440. bins: _int = 100,
  13441. min: Number | _complex = 0,
  13442. max: Number | _complex = 0,
  13443. *,
  13444. out: Tensor | None = None,
  13445. ) -> Tensor:
  13446. r"""
  13447. histc(input, bins=100, min=0, max=0, *, out=None) -> Tensor
  13448. Computes the histogram of a tensor.
  13449. The elements are sorted into equal width bins between :attr:`min` and
  13450. :attr:`max`. If :attr:`min` and :attr:`max` are both zero, the minimum and
  13451. maximum values of the data are used.
  13452. Elements lower than min and higher than max and ``NaN`` elements are ignored.
  13453. Args:
  13454. input (Tensor): the input tensor.
  13455. bins (int): number of histogram bins
  13456. min (Scalar): lower end of the range (inclusive)
  13457. max (Scalar): upper end of the range (inclusive)
  13458. Keyword args:
  13459. out (Tensor, optional): the output tensor.
  13460. Returns:
  13461. Tensor: Histogram represented as a tensor
  13462. Example::
  13463. >>> torch.histc(torch.tensor([1., 2, 1]), bins=4, min=0, max=3)
  13464. tensor([ 0., 2., 1., 0.])
  13465. """
  13466. @overload
  13467. def histogram(
  13468. input: Tensor,
  13469. bins: Tensor,
  13470. *,
  13471. weight: Tensor | None = None,
  13472. density: _bool = False,
  13473. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  13474. ) -> torch.return_types.histogram:
  13475. r"""
  13476. histogram(input, bins, *, range=None, weight=None, density=False, out=None) -> (Tensor, Tensor)
  13477. Computes a histogram of the values in a tensor.
  13478. :attr:`bins` can be an integer or a 1D tensor.
  13479. If :attr:`bins` is an int, it specifies the number of equal-width bins.
  13480. By default, the lower and upper range of the bins is determined by the
  13481. minimum and maximum elements of the input tensor. The :attr:`range`
  13482. argument can be provided to specify a range for the bins.
  13483. If :attr:`bins` is a 1D tensor, it specifies the sequence of bin edges
  13484. including the rightmost edge. It should contain at least 2 elements
  13485. and its elements should be increasing.
  13486. Args:
  13487. input (Tensor): the input tensor.
  13488. bins: int or 1D Tensor. If int, defines the number of equal-width bins. If tensor,
  13489. defines the sequence of bin edges including the rightmost edge.
  13490. Keyword args:
  13491. range (tuple of float): Defines the range of the bins.
  13492. weight (Tensor): If provided, weight should have the same shape as input. Each value in
  13493. input contributes its associated weight towards its bin's result.
  13494. density (bool): If False, the result will contain the count (or total weight) in each bin.
  13495. If True, the result is the value of the probability density function over the bins,
  13496. normalized such that the integral over the range of the bins is 1.
  13497. out (Tensor, optional): the output tensor. (tuple, optional): The result tuple of two output tensors (hist, bin_edges).
  13498. Returns:
  13499. hist (Tensor): 1D Tensor containing the values of the histogram.
  13500. bin_edges(Tensor): 1D Tensor containing the edges of the histogram bins.
  13501. Example::
  13502. >>> torch.histogram(torch.tensor([1., 2, 1]), bins=4, range=(0., 3.), weight=torch.tensor([1., 2., 4.]))
  13503. (tensor([ 0., 5., 2., 0.]), tensor([0., 0.75, 1.5, 2.25, 3.]))
  13504. >>> torch.histogram(torch.tensor([1., 2, 1]), bins=4, range=(0., 3.), weight=torch.tensor([1., 2., 4.]), density=True)
  13505. (tensor([ 0., 0.9524, 0.3810, 0.]), tensor([0., 0.75, 1.5, 2.25, 3.]))
  13506. """
  13507. @overload
  13508. def histogram(
  13509. input: Tensor,
  13510. bins: _int = 100,
  13511. *,
  13512. range: Sequence[_float] | None = None,
  13513. weight: Tensor | None = None,
  13514. density: _bool = False,
  13515. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  13516. ) -> torch.return_types.histogram:
  13517. r"""
  13518. histogram(input, bins, *, range=None, weight=None, density=False, out=None) -> (Tensor, Tensor)
  13519. Computes a histogram of the values in a tensor.
  13520. :attr:`bins` can be an integer or a 1D tensor.
  13521. If :attr:`bins` is an int, it specifies the number of equal-width bins.
  13522. By default, the lower and upper range of the bins is determined by the
  13523. minimum and maximum elements of the input tensor. The :attr:`range`
  13524. argument can be provided to specify a range for the bins.
  13525. If :attr:`bins` is a 1D tensor, it specifies the sequence of bin edges
  13526. including the rightmost edge. It should contain at least 2 elements
  13527. and its elements should be increasing.
  13528. Args:
  13529. input (Tensor): the input tensor.
  13530. bins: int or 1D Tensor. If int, defines the number of equal-width bins. If tensor,
  13531. defines the sequence of bin edges including the rightmost edge.
  13532. Keyword args:
  13533. range (tuple of float): Defines the range of the bins.
  13534. weight (Tensor): If provided, weight should have the same shape as input. Each value in
  13535. input contributes its associated weight towards its bin's result.
  13536. density (bool): If False, the result will contain the count (or total weight) in each bin.
  13537. If True, the result is the value of the probability density function over the bins,
  13538. normalized such that the integral over the range of the bins is 1.
  13539. out (Tensor, optional): the output tensor. (tuple, optional): The result tuple of two output tensors (hist, bin_edges).
  13540. Returns:
  13541. hist (Tensor): 1D Tensor containing the values of the histogram.
  13542. bin_edges(Tensor): 1D Tensor containing the edges of the histogram bins.
  13543. Example::
  13544. >>> torch.histogram(torch.tensor([1., 2, 1]), bins=4, range=(0., 3.), weight=torch.tensor([1., 2., 4.]))
  13545. (tensor([ 0., 5., 2., 0.]), tensor([0., 0.75, 1.5, 2.25, 3.]))
  13546. >>> torch.histogram(torch.tensor([1., 2, 1]), bins=4, range=(0., 3.), weight=torch.tensor([1., 2., 4.]), density=True)
  13547. (tensor([ 0., 0.9524, 0.3810, 0.]), tensor([0., 0.75, 1.5, 2.25, 3.]))
  13548. """
  13549. @overload
  13550. def histogramdd(
  13551. input: Tensor,
  13552. bins: _int,
  13553. range: Sequence[_float] | None = None,
  13554. weight: Tensor | None = None,
  13555. density: _bool = False,
  13556. ) -> torch.return_types.histogramdd:
  13557. r"""
  13558. histogramdd(input, bins, *, range=None, weight=None, density=False, out=None) -> (Tensor, Tensor[])
  13559. Computes a multi-dimensional histogram of the values in a tensor.
  13560. Interprets the elements of an input tensor whose innermost dimension has size N
  13561. as a collection of N-dimensional points. Maps each of the points into a set of
  13562. N-dimensional bins and returns the number of points (or total weight) in each bin.
  13563. :attr:`input` must be a tensor with at least 2 dimensions.
  13564. If input has shape (M, N), each of its M rows defines a point in N-dimensional space.
  13565. If input has three or more dimensions, all but the last dimension are flattened.
  13566. Each dimension is independently associated with its own strictly increasing sequence
  13567. of bin edges. Bin edges may be specified explicitly by passing a sequence of 1D
  13568. tensors. Alternatively, bin edges may be constructed automatically by passing a
  13569. sequence of integers specifying the number of equal-width bins in each dimension.
  13570. For each N-dimensional point in input:
  13571. - Each of its coordinates is binned independently among the bin edges
  13572. corresponding to its dimension
  13573. - Binning results are combined to identify the N-dimensional bin (if any)
  13574. into which the point falls
  13575. - If the point falls into a bin, the bin's count (or total weight) is incremented
  13576. - Points which do not fall into any bin do not contribute to the output
  13577. :attr:`bins` can be a sequence of N 1D tensors, a sequence of N ints, or a single int.
  13578. If :attr:`bins` is a sequence of N 1D tensors, it explicitly specifies the N sequences
  13579. of bin edges. Each 1D tensor should contain a strictly increasing sequence with at
  13580. least one element. A sequence of K bin edges defines K-1 bins, explicitly specifying
  13581. the left and right edges of all bins. Every bin is inclusive of its left edge. Only
  13582. the rightmost bin is inclusive of its right edge.
  13583. If :attr:`bins` is a sequence of N ints, it specifies the number of equal-width bins
  13584. in each dimension. By default, the leftmost and rightmost bin edges in each dimension
  13585. are determined by the minimum and maximum elements of the input tensor in the
  13586. corresponding dimension. The :attr:`range` argument can be provided to manually
  13587. specify the leftmost and rightmost bin edges in each dimension.
  13588. If :attr:`bins` is an int, it specifies the number of equal-width bins for all dimensions.
  13589. .. note::
  13590. See also :func:`torch.histogram`, which specifically computes 1D histograms.
  13591. While :func:`torch.histogramdd` infers the dimensionality of its bins and
  13592. binned values from the shape of :attr:`input`, :func:`torch.histogram`
  13593. accepts and flattens :attr:`input` of any shape.
  13594. Args:
  13595. input (Tensor): the input tensor.
  13596. bins: Tensor[], int[], or int.
  13597. If Tensor[], defines the sequences of bin edges.
  13598. If int[], defines the number of equal-width bins in each dimension.
  13599. If int, defines the number of equal-width bins for all dimensions.
  13600. Keyword args:
  13601. range (sequence of float): Defines the leftmost and rightmost bin edges
  13602. in each dimension.
  13603. weight (Tensor): By default, each value in the input has weight 1. If a weight
  13604. tensor is passed, each N-dimensional coordinate in input
  13605. contributes its associated weight towards its bin's result.
  13606. The weight tensor should have the same shape as the :attr:`input`
  13607. tensor excluding its innermost dimension N.
  13608. density (bool): If False (default), the result will contain the count (or total weight)
  13609. in each bin. If True, each count (weight) is divided by the total count
  13610. (total weight), then divided by the volume of its associated bin.
  13611. Returns:
  13612. hist (Tensor): N-dimensional Tensor containing the values of the histogram.
  13613. bin_edges(Tensor[]): sequence of N 1D Tensors containing the bin edges.
  13614. Example::
  13615. >>> torch.histogramdd(torch.tensor([[0., 1.], [1., 0.], [2., 0.], [2., 2.]]), bins=[3, 3],
  13616. ... weight=torch.tensor([1., 2., 4., 8.]))
  13617. torch.return_types.histogramdd(
  13618. hist=tensor([[0., 1., 0.],
  13619. [2., 0., 0.],
  13620. [4., 0., 8.]]),
  13621. bin_edges=(tensor([0.0000, 0.6667, 1.3333, 2.0000]),
  13622. tensor([0.0000, 0.6667, 1.3333, 2.0000])))
  13623. >>> torch.histogramdd(torch.tensor([[0., 0.], [1., 1.], [2., 2.]]), bins=[2, 2],
  13624. ... range=[0., 1., 0., 1.], density=True)
  13625. torch.return_types.histogramdd(
  13626. hist=tensor([[2., 0.],
  13627. [0., 2.]]),
  13628. bin_edges=(tensor([0.0000, 0.5000, 1.0000]),
  13629. tensor([0.0000, 0.5000, 1.0000])))
  13630. """
  13631. @overload
  13632. def histogramdd(
  13633. input: Tensor,
  13634. bins: _size,
  13635. range: Sequence[_float] | None = None,
  13636. weight: Tensor | None = None,
  13637. density: _bool = False,
  13638. ) -> torch.return_types.histogramdd:
  13639. r"""
  13640. histogramdd(input, bins, *, range=None, weight=None, density=False, out=None) -> (Tensor, Tensor[])
  13641. Computes a multi-dimensional histogram of the values in a tensor.
  13642. Interprets the elements of an input tensor whose innermost dimension has size N
  13643. as a collection of N-dimensional points. Maps each of the points into a set of
  13644. N-dimensional bins and returns the number of points (or total weight) in each bin.
  13645. :attr:`input` must be a tensor with at least 2 dimensions.
  13646. If input has shape (M, N), each of its M rows defines a point in N-dimensional space.
  13647. If input has three or more dimensions, all but the last dimension are flattened.
  13648. Each dimension is independently associated with its own strictly increasing sequence
  13649. of bin edges. Bin edges may be specified explicitly by passing a sequence of 1D
  13650. tensors. Alternatively, bin edges may be constructed automatically by passing a
  13651. sequence of integers specifying the number of equal-width bins in each dimension.
  13652. For each N-dimensional point in input:
  13653. - Each of its coordinates is binned independently among the bin edges
  13654. corresponding to its dimension
  13655. - Binning results are combined to identify the N-dimensional bin (if any)
  13656. into which the point falls
  13657. - If the point falls into a bin, the bin's count (or total weight) is incremented
  13658. - Points which do not fall into any bin do not contribute to the output
  13659. :attr:`bins` can be a sequence of N 1D tensors, a sequence of N ints, or a single int.
  13660. If :attr:`bins` is a sequence of N 1D tensors, it explicitly specifies the N sequences
  13661. of bin edges. Each 1D tensor should contain a strictly increasing sequence with at
  13662. least one element. A sequence of K bin edges defines K-1 bins, explicitly specifying
  13663. the left and right edges of all bins. Every bin is inclusive of its left edge. Only
  13664. the rightmost bin is inclusive of its right edge.
  13665. If :attr:`bins` is a sequence of N ints, it specifies the number of equal-width bins
  13666. in each dimension. By default, the leftmost and rightmost bin edges in each dimension
  13667. are determined by the minimum and maximum elements of the input tensor in the
  13668. corresponding dimension. The :attr:`range` argument can be provided to manually
  13669. specify the leftmost and rightmost bin edges in each dimension.
  13670. If :attr:`bins` is an int, it specifies the number of equal-width bins for all dimensions.
  13671. .. note::
  13672. See also :func:`torch.histogram`, which specifically computes 1D histograms.
  13673. While :func:`torch.histogramdd` infers the dimensionality of its bins and
  13674. binned values from the shape of :attr:`input`, :func:`torch.histogram`
  13675. accepts and flattens :attr:`input` of any shape.
  13676. Args:
  13677. input (Tensor): the input tensor.
  13678. bins: Tensor[], int[], or int.
  13679. If Tensor[], defines the sequences of bin edges.
  13680. If int[], defines the number of equal-width bins in each dimension.
  13681. If int, defines the number of equal-width bins for all dimensions.
  13682. Keyword args:
  13683. range (sequence of float): Defines the leftmost and rightmost bin edges
  13684. in each dimension.
  13685. weight (Tensor): By default, each value in the input has weight 1. If a weight
  13686. tensor is passed, each N-dimensional coordinate in input
  13687. contributes its associated weight towards its bin's result.
  13688. The weight tensor should have the same shape as the :attr:`input`
  13689. tensor excluding its innermost dimension N.
  13690. density (bool): If False (default), the result will contain the count (or total weight)
  13691. in each bin. If True, each count (weight) is divided by the total count
  13692. (total weight), then divided by the volume of its associated bin.
  13693. Returns:
  13694. hist (Tensor): N-dimensional Tensor containing the values of the histogram.
  13695. bin_edges(Tensor[]): sequence of N 1D Tensors containing the bin edges.
  13696. Example::
  13697. >>> torch.histogramdd(torch.tensor([[0., 1.], [1., 0.], [2., 0.], [2., 2.]]), bins=[3, 3],
  13698. ... weight=torch.tensor([1., 2., 4., 8.]))
  13699. torch.return_types.histogramdd(
  13700. hist=tensor([[0., 1., 0.],
  13701. [2., 0., 0.],
  13702. [4., 0., 8.]]),
  13703. bin_edges=(tensor([0.0000, 0.6667, 1.3333, 2.0000]),
  13704. tensor([0.0000, 0.6667, 1.3333, 2.0000])))
  13705. >>> torch.histogramdd(torch.tensor([[0., 0.], [1., 1.], [2., 2.]]), bins=[2, 2],
  13706. ... range=[0., 1., 0., 1.], density=True)
  13707. torch.return_types.histogramdd(
  13708. hist=tensor([[2., 0.],
  13709. [0., 2.]]),
  13710. bin_edges=(tensor([0.0000, 0.5000, 1.0000]),
  13711. tensor([0.0000, 0.5000, 1.0000])))
  13712. """
  13713. @overload
  13714. def histogramdd(
  13715. input: Tensor,
  13716. bins: tuple[Tensor, ...] | list[Tensor] | None,
  13717. range: Sequence[_float] | None = None,
  13718. weight: Tensor | None = None,
  13719. density: _bool = False,
  13720. ) -> torch.return_types.histogramdd:
  13721. r"""
  13722. histogramdd(input, bins, *, range=None, weight=None, density=False, out=None) -> (Tensor, Tensor[])
  13723. Computes a multi-dimensional histogram of the values in a tensor.
  13724. Interprets the elements of an input tensor whose innermost dimension has size N
  13725. as a collection of N-dimensional points. Maps each of the points into a set of
  13726. N-dimensional bins and returns the number of points (or total weight) in each bin.
  13727. :attr:`input` must be a tensor with at least 2 dimensions.
  13728. If input has shape (M, N), each of its M rows defines a point in N-dimensional space.
  13729. If input has three or more dimensions, all but the last dimension are flattened.
  13730. Each dimension is independently associated with its own strictly increasing sequence
  13731. of bin edges. Bin edges may be specified explicitly by passing a sequence of 1D
  13732. tensors. Alternatively, bin edges may be constructed automatically by passing a
  13733. sequence of integers specifying the number of equal-width bins in each dimension.
  13734. For each N-dimensional point in input:
  13735. - Each of its coordinates is binned independently among the bin edges
  13736. corresponding to its dimension
  13737. - Binning results are combined to identify the N-dimensional bin (if any)
  13738. into which the point falls
  13739. - If the point falls into a bin, the bin's count (or total weight) is incremented
  13740. - Points which do not fall into any bin do not contribute to the output
  13741. :attr:`bins` can be a sequence of N 1D tensors, a sequence of N ints, or a single int.
  13742. If :attr:`bins` is a sequence of N 1D tensors, it explicitly specifies the N sequences
  13743. of bin edges. Each 1D tensor should contain a strictly increasing sequence with at
  13744. least one element. A sequence of K bin edges defines K-1 bins, explicitly specifying
  13745. the left and right edges of all bins. Every bin is inclusive of its left edge. Only
  13746. the rightmost bin is inclusive of its right edge.
  13747. If :attr:`bins` is a sequence of N ints, it specifies the number of equal-width bins
  13748. in each dimension. By default, the leftmost and rightmost bin edges in each dimension
  13749. are determined by the minimum and maximum elements of the input tensor in the
  13750. corresponding dimension. The :attr:`range` argument can be provided to manually
  13751. specify the leftmost and rightmost bin edges in each dimension.
  13752. If :attr:`bins` is an int, it specifies the number of equal-width bins for all dimensions.
  13753. .. note::
  13754. See also :func:`torch.histogram`, which specifically computes 1D histograms.
  13755. While :func:`torch.histogramdd` infers the dimensionality of its bins and
  13756. binned values from the shape of :attr:`input`, :func:`torch.histogram`
  13757. accepts and flattens :attr:`input` of any shape.
  13758. Args:
  13759. input (Tensor): the input tensor.
  13760. bins: Tensor[], int[], or int.
  13761. If Tensor[], defines the sequences of bin edges.
  13762. If int[], defines the number of equal-width bins in each dimension.
  13763. If int, defines the number of equal-width bins for all dimensions.
  13764. Keyword args:
  13765. range (sequence of float): Defines the leftmost and rightmost bin edges
  13766. in each dimension.
  13767. weight (Tensor): By default, each value in the input has weight 1. If a weight
  13768. tensor is passed, each N-dimensional coordinate in input
  13769. contributes its associated weight towards its bin's result.
  13770. The weight tensor should have the same shape as the :attr:`input`
  13771. tensor excluding its innermost dimension N.
  13772. density (bool): If False (default), the result will contain the count (or total weight)
  13773. in each bin. If True, each count (weight) is divided by the total count
  13774. (total weight), then divided by the volume of its associated bin.
  13775. Returns:
  13776. hist (Tensor): N-dimensional Tensor containing the values of the histogram.
  13777. bin_edges(Tensor[]): sequence of N 1D Tensors containing the bin edges.
  13778. Example::
  13779. >>> torch.histogramdd(torch.tensor([[0., 1.], [1., 0.], [2., 0.], [2., 2.]]), bins=[3, 3],
  13780. ... weight=torch.tensor([1., 2., 4., 8.]))
  13781. torch.return_types.histogramdd(
  13782. hist=tensor([[0., 1., 0.],
  13783. [2., 0., 0.],
  13784. [4., 0., 8.]]),
  13785. bin_edges=(tensor([0.0000, 0.6667, 1.3333, 2.0000]),
  13786. tensor([0.0000, 0.6667, 1.3333, 2.0000])))
  13787. >>> torch.histogramdd(torch.tensor([[0., 0.], [1., 1.], [2., 2.]]), bins=[2, 2],
  13788. ... range=[0., 1., 0., 1.], density=True)
  13789. torch.return_types.histogramdd(
  13790. hist=tensor([[2., 0.],
  13791. [0., 2.]]),
  13792. bin_edges=(tensor([0.0000, 0.5000, 1.0000]),
  13793. tensor([0.0000, 0.5000, 1.0000])))
  13794. """
  13795. def hsmm(input: Tensor, mat2: Tensor) -> Tensor: ...
  13796. @overload
  13797. def hsplit(input: Tensor, sections: _int) -> tuple[Tensor, ...]:
  13798. r"""
  13799. hsplit(input, indices_or_sections) -> List of Tensors
  13800. Splits :attr:`input`, a tensor with one or more dimensions, into multiple tensors
  13801. horizontally according to :attr:`indices_or_sections`. Each split is a view of
  13802. :attr:`input`.
  13803. If :attr:`input` is one dimensional this is equivalent to calling
  13804. torch.tensor_split(input, indices_or_sections, dim=0) (the split dimension is
  13805. zero), and if :attr:`input` has two or more dimensions it's equivalent to calling
  13806. torch.tensor_split(input, indices_or_sections, dim=1) (the split dimension is 1),
  13807. except that if :attr:`indices_or_sections` is an integer it must evenly divide
  13808. the split dimension or a runtime error will be thrown.
  13809. This function is based on NumPy's :func:`numpy.hsplit`.
  13810. Args:
  13811. input (Tensor): tensor to split.
  13812. indices_or_sections (int or list or tuple of ints): See argument in :func:`torch.tensor_split`.
  13813. Example::
  13814. >>> t = torch.arange(16.0).reshape(4,4)
  13815. >>> t
  13816. tensor([[ 0., 1., 2., 3.],
  13817. [ 4., 5., 6., 7.],
  13818. [ 8., 9., 10., 11.],
  13819. [12., 13., 14., 15.]])
  13820. >>> torch.hsplit(t, 2)
  13821. (tensor([[ 0., 1.],
  13822. [ 4., 5.],
  13823. [ 8., 9.],
  13824. [12., 13.]]),
  13825. tensor([[ 2., 3.],
  13826. [ 6., 7.],
  13827. [10., 11.],
  13828. [14., 15.]]))
  13829. >>> torch.hsplit(t, [3, 6])
  13830. (tensor([[ 0., 1., 2.],
  13831. [ 4., 5., 6.],
  13832. [ 8., 9., 10.],
  13833. [12., 13., 14.]]),
  13834. tensor([[ 3.],
  13835. [ 7.],
  13836. [11.],
  13837. [15.]]),
  13838. tensor([], size=(4, 0)))
  13839. """
  13840. @overload
  13841. def hsplit(input: Tensor, indices: _size) -> tuple[Tensor, ...]:
  13842. r"""
  13843. hsplit(input, indices_or_sections) -> List of Tensors
  13844. Splits :attr:`input`, a tensor with one or more dimensions, into multiple tensors
  13845. horizontally according to :attr:`indices_or_sections`. Each split is a view of
  13846. :attr:`input`.
  13847. If :attr:`input` is one dimensional this is equivalent to calling
  13848. torch.tensor_split(input, indices_or_sections, dim=0) (the split dimension is
  13849. zero), and if :attr:`input` has two or more dimensions it's equivalent to calling
  13850. torch.tensor_split(input, indices_or_sections, dim=1) (the split dimension is 1),
  13851. except that if :attr:`indices_or_sections` is an integer it must evenly divide
  13852. the split dimension or a runtime error will be thrown.
  13853. This function is based on NumPy's :func:`numpy.hsplit`.
  13854. Args:
  13855. input (Tensor): tensor to split.
  13856. indices_or_sections (int or list or tuple of ints): See argument in :func:`torch.tensor_split`.
  13857. Example::
  13858. >>> t = torch.arange(16.0).reshape(4,4)
  13859. >>> t
  13860. tensor([[ 0., 1., 2., 3.],
  13861. [ 4., 5., 6., 7.],
  13862. [ 8., 9., 10., 11.],
  13863. [12., 13., 14., 15.]])
  13864. >>> torch.hsplit(t, 2)
  13865. (tensor([[ 0., 1.],
  13866. [ 4., 5.],
  13867. [ 8., 9.],
  13868. [12., 13.]]),
  13869. tensor([[ 2., 3.],
  13870. [ 6., 7.],
  13871. [10., 11.],
  13872. [14., 15.]]))
  13873. >>> torch.hsplit(t, [3, 6])
  13874. (tensor([[ 0., 1., 2.],
  13875. [ 4., 5., 6.],
  13876. [ 8., 9., 10.],
  13877. [12., 13., 14.]]),
  13878. tensor([[ 3.],
  13879. [ 7.],
  13880. [11.],
  13881. [15.]]),
  13882. tensor([], size=(4, 0)))
  13883. """
  13884. def hspmm(
  13885. mat1: Tensor,
  13886. mat2: Tensor,
  13887. *,
  13888. out: Tensor | None = None,
  13889. ) -> Tensor:
  13890. r"""
  13891. hspmm(mat1, mat2, *, out=None) -> Tensor
  13892. Performs a matrix multiplication of a :ref:`sparse COO matrix
  13893. <sparse-coo-docs>` :attr:`mat1` and a strided matrix :attr:`mat2`. The
  13894. result is a (1 + 1)-dimensional :ref:`hybrid COO matrix
  13895. <sparse-hybrid-coo-docs>`.
  13896. Args:
  13897. mat1 (Tensor): the first sparse matrix to be matrix multiplied
  13898. mat2 (Tensor): the second strided matrix to be matrix multiplied
  13899. Keyword args:
  13900. out (Tensor, optional): the output tensor.
  13901. """
  13902. def hstack(
  13903. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  13904. *,
  13905. out: Tensor | None = None,
  13906. ) -> Tensor:
  13907. r"""
  13908. hstack(tensors, *, out=None) -> Tensor
  13909. Stack tensors in sequence horizontally (column wise).
  13910. This is equivalent to concatenation along the first axis for 1-D tensors, and along the second axis for all other tensors.
  13911. Args:
  13912. tensors (sequence of Tensors): sequence of tensors to concatenate
  13913. Keyword args:
  13914. out (Tensor, optional): the output tensor.
  13915. Example::
  13916. >>> a = torch.tensor([1, 2, 3])
  13917. >>> b = torch.tensor([4, 5, 6])
  13918. >>> torch.hstack((a,b))
  13919. tensor([1, 2, 3, 4, 5, 6])
  13920. >>> a = torch.tensor([[1],[2],[3]])
  13921. >>> b = torch.tensor([[4],[5],[6]])
  13922. >>> torch.hstack((a,b))
  13923. tensor([[1, 4],
  13924. [2, 5],
  13925. [3, 6]])
  13926. """
  13927. def hypot(
  13928. input: Tensor,
  13929. other: Tensor,
  13930. *,
  13931. out: Tensor | None = None,
  13932. ) -> Tensor:
  13933. r"""
  13934. hypot(input, other, *, out=None) -> Tensor
  13935. Given the legs of a right triangle, return its hypotenuse.
  13936. .. math::
  13937. \text{out}_{i} = \sqrt{\text{input}_{i}^{2} + \text{other}_{i}^{2}}
  13938. The shapes of ``input`` and ``other`` must be
  13939. :ref:`broadcastable <broadcasting-semantics>`.
  13940. Args:
  13941. input (Tensor): the first input tensor
  13942. other (Tensor): the second input tensor
  13943. Keyword args:
  13944. out (Tensor, optional): the output tensor.
  13945. Example::
  13946. >>> a = torch.hypot(torch.tensor([4.0]), torch.tensor([3.0, 4.0, 5.0]))
  13947. tensor([5.0000, 5.6569, 6.4031])
  13948. """
  13949. def i0(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  13950. r"""
  13951. i0(input, *, out=None) -> Tensor
  13952. Alias for :func:`torch.special.i0`.
  13953. """
  13954. def i0_(input: Tensor) -> Tensor: ...
  13955. def igamma(
  13956. input: Tensor,
  13957. other: Tensor,
  13958. *,
  13959. out: Tensor | None = None,
  13960. ) -> Tensor:
  13961. r"""
  13962. igamma(input, other, *, out=None) -> Tensor
  13963. Alias for :func:`torch.special.gammainc`.
  13964. """
  13965. def igammac(
  13966. input: Tensor,
  13967. other: Tensor,
  13968. *,
  13969. out: Tensor | None = None,
  13970. ) -> Tensor:
  13971. r"""
  13972. igammac(input, other, *, out=None) -> Tensor
  13973. Alias for :func:`torch.special.gammaincc`.
  13974. """
  13975. def imag(input: Tensor) -> Tensor:
  13976. r"""
  13977. imag(input) -> Tensor
  13978. Returns a new tensor containing imaginary values of the :attr:`self` tensor.
  13979. The returned tensor and :attr:`self` share the same underlying storage.
  13980. .. warning::
  13981. :func:`imag` is only supported for tensors with complex dtypes.
  13982. Args:
  13983. input (Tensor): the input tensor.
  13984. Example::
  13985. >>> x=torch.randn(4, dtype=torch.cfloat)
  13986. >>> x
  13987. tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
  13988. >>> x.imag
  13989. tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
  13990. """
  13991. @overload
  13992. def index_add(
  13993. input: Tensor,
  13994. dim: _int,
  13995. index: Tensor,
  13996. source: Tensor,
  13997. *,
  13998. alpha: Number | _complex = 1,
  13999. out: Tensor | None = None,
  14000. ) -> Tensor:
  14001. r"""
  14002. index_add(input: Tensor, dim: int, index: Tensor, source: Tensor, *, alpha: Union[Number, _complex] = 1, out: Optional[Tensor]) -> Tensor # noqa: B950
  14003. See :meth:`~Tensor.index_add_` for function description.
  14004. """
  14005. @overload
  14006. def index_add(
  14007. input: Tensor,
  14008. dim: str | EllipsisType | None,
  14009. index: Tensor,
  14010. source: Tensor,
  14011. *,
  14012. alpha: Number | _complex = 1,
  14013. ) -> Tensor:
  14014. r"""
  14015. index_add(input: Tensor, dim: int, index: Tensor, source: Tensor, *, alpha: Union[Number, _complex] = 1, out: Optional[Tensor]) -> Tensor # noqa: B950
  14016. See :meth:`~Tensor.index_add_` for function description.
  14017. """
  14018. @overload
  14019. def index_copy(
  14020. input: Tensor,
  14021. dim: _int,
  14022. index: Tensor,
  14023. source: Tensor,
  14024. *,
  14025. out: Tensor | None = None,
  14026. ) -> Tensor:
  14027. r"""
  14028. index_copy(input: Tensor, dim: int, index: Tensor, source: Tensor, *, out: Optional[Tensor]) -> Tensor
  14029. See :meth:`~Tensor.index_add_` for function description.
  14030. """
  14031. @overload
  14032. def index_copy(
  14033. input: Tensor,
  14034. dim: str | EllipsisType | None,
  14035. index: Tensor,
  14036. source: Tensor,
  14037. ) -> Tensor:
  14038. r"""
  14039. index_copy(input: Tensor, dim: int, index: Tensor, source: Tensor, *, out: Optional[Tensor]) -> Tensor
  14040. See :meth:`~Tensor.index_add_` for function description.
  14041. """
  14042. @overload
  14043. def index_fill(
  14044. input: Tensor,
  14045. dim: _int,
  14046. index: Tensor,
  14047. value: Tensor,
  14048. ) -> Tensor: ...
  14049. @overload
  14050. def index_fill(
  14051. input: Tensor,
  14052. dim: str | EllipsisType | None,
  14053. index: Tensor,
  14054. value: Tensor,
  14055. ) -> Tensor: ...
  14056. @overload
  14057. def index_fill(
  14058. input: Tensor,
  14059. dim: _int,
  14060. index: Tensor,
  14061. value: Number | _complex,
  14062. ) -> Tensor: ...
  14063. @overload
  14064. def index_fill(
  14065. input: Tensor,
  14066. dim: str | EllipsisType | None,
  14067. index: Tensor,
  14068. value: Number | _complex,
  14069. ) -> Tensor: ...
  14070. def index_put(
  14071. input: Tensor,
  14072. indices: tuple[Tensor, ...] | list[Tensor] | None,
  14073. values: Tensor,
  14074. accumulate: _bool = False,
  14075. ) -> Tensor: ...
  14076. def index_put_(
  14077. input: Tensor,
  14078. indices: tuple[Tensor, ...] | list[Tensor] | None,
  14079. values: Tensor,
  14080. accumulate: _bool = False,
  14081. ) -> Tensor: ...
  14082. def index_reduce(
  14083. input: Tensor,
  14084. dim: _int,
  14085. index: Tensor,
  14086. source: Tensor,
  14087. reduce: str,
  14088. *,
  14089. include_self: _bool = True,
  14090. out: Tensor | None = None,
  14091. ) -> Tensor:
  14092. r"""
  14093. index_reduce(input: Tensor, dim: int, index: Tensor, source: Tensor, reduce: str, *, include_self: bool = True, out: Optional[Tensor]) -> Tensor # noqa: B950
  14094. See :meth:`~Tensor.index_reduce_` for function description.
  14095. """
  14096. @overload
  14097. def index_select(
  14098. input: Tensor,
  14099. dim: _int,
  14100. index: Tensor,
  14101. *,
  14102. out: Tensor | None = None,
  14103. ) -> Tensor:
  14104. r"""
  14105. index_select(input, dim, index, *, out=None) -> Tensor
  14106. Returns a new tensor which indexes the :attr:`input` tensor along dimension
  14107. :attr:`dim` using the entries in :attr:`index`.
  14108. The returned tensor has the same number of dimensions as the original tensor
  14109. (:attr:`input`). The :attr:`dim`\ th dimension has the same size as the length
  14110. of :attr:`index`; other dimensions have the same size as in the original tensor.
  14111. .. note:: The returned tensor does **not** use the same storage as the original
  14112. tensor. If :attr:`out` has a different shape than expected, we
  14113. silently change it to the correct shape, reallocating the underlying
  14114. storage if necessary.
  14115. Args:
  14116. input (Tensor): the input tensor.
  14117. dim (int): the dimension in which we index
  14118. index (IntTensor or LongTensor): the 1-D tensor containing the indices to index
  14119. Keyword args:
  14120. out (Tensor, optional): the output tensor.
  14121. Example::
  14122. >>> x = torch.randn(3, 4)
  14123. >>> x
  14124. tensor([[ 0.1427, 0.0231, -0.5414, -1.0009],
  14125. [-0.4664, 0.2647, -0.1228, -1.1068],
  14126. [-1.1734, -0.6571, 0.7230, -0.6004]])
  14127. >>> indices = torch.tensor([0, 2])
  14128. >>> torch.index_select(x, 0, indices)
  14129. tensor([[ 0.1427, 0.0231, -0.5414, -1.0009],
  14130. [-1.1734, -0.6571, 0.7230, -0.6004]])
  14131. >>> torch.index_select(x, 1, indices)
  14132. tensor([[ 0.1427, -0.5414],
  14133. [-0.4664, -0.1228],
  14134. [-1.1734, 0.7230]])
  14135. """
  14136. @overload
  14137. def index_select(
  14138. input: Tensor,
  14139. dim: str | EllipsisType | None,
  14140. index: Tensor,
  14141. *,
  14142. out: Tensor | None = None,
  14143. ) -> Tensor:
  14144. r"""
  14145. index_select(input, dim, index, *, out=None) -> Tensor
  14146. Returns a new tensor which indexes the :attr:`input` tensor along dimension
  14147. :attr:`dim` using the entries in :attr:`index`.
  14148. The returned tensor has the same number of dimensions as the original tensor
  14149. (:attr:`input`). The :attr:`dim`\ th dimension has the same size as the length
  14150. of :attr:`index`; other dimensions have the same size as in the original tensor.
  14151. .. note:: The returned tensor does **not** use the same storage as the original
  14152. tensor. If :attr:`out` has a different shape than expected, we
  14153. silently change it to the correct shape, reallocating the underlying
  14154. storage if necessary.
  14155. Args:
  14156. input (Tensor): the input tensor.
  14157. dim (int): the dimension in which we index
  14158. index (IntTensor or LongTensor): the 1-D tensor containing the indices to index
  14159. Keyword args:
  14160. out (Tensor, optional): the output tensor.
  14161. Example::
  14162. >>> x = torch.randn(3, 4)
  14163. >>> x
  14164. tensor([[ 0.1427, 0.0231, -0.5414, -1.0009],
  14165. [-0.4664, 0.2647, -0.1228, -1.1068],
  14166. [-1.1734, -0.6571, 0.7230, -0.6004]])
  14167. >>> indices = torch.tensor([0, 2])
  14168. >>> torch.index_select(x, 0, indices)
  14169. tensor([[ 0.1427, 0.0231, -0.5414, -1.0009],
  14170. [-1.1734, -0.6571, 0.7230, -0.6004]])
  14171. >>> torch.index_select(x, 1, indices)
  14172. tensor([[ 0.1427, -0.5414],
  14173. [-0.4664, -0.1228],
  14174. [-1.1734, 0.7230]])
  14175. """
  14176. def indices_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  14177. r"""
  14178. Performs the same operation as :func:`torch.indices`, but all output tensors
  14179. are freshly created instead of aliasing the input.
  14180. """
  14181. def init_num_threads() -> None: ...
  14182. def inner(
  14183. input: Tensor,
  14184. other: Tensor,
  14185. *,
  14186. out: Tensor | None = None,
  14187. ) -> Tensor:
  14188. r"""
  14189. inner(input, other, *, out=None) -> Tensor
  14190. Computes the dot product for 1D tensors. For higher dimensions, sums the product
  14191. of elements from :attr:`input` and :attr:`other` along their last dimension.
  14192. .. note::
  14193. If either :attr:`input` or :attr:`other` is a scalar, the result is equivalent
  14194. to `torch.mul(input, other)`.
  14195. If both :attr:`input` and :attr:`other` are non-scalars, the size of their last
  14196. dimension must match and the result is equivalent to `torch.tensordot(input,
  14197. other, dims=([-1], [-1]))`
  14198. Args:
  14199. input (Tensor): First input tensor
  14200. other (Tensor): Second input tensor
  14201. Keyword args:
  14202. out (Tensor, optional): Optional output tensor to write result into. The output
  14203. shape is `input.shape[:-1] + other.shape[:-1]`.
  14204. Example::
  14205. # Dot product
  14206. >>> torch.inner(torch.tensor([1, 2, 3]), torch.tensor([0, 2, 1]))
  14207. tensor(7)
  14208. # Multidimensional input tensors
  14209. >>> a = torch.randn(2, 3)
  14210. >>> a
  14211. tensor([[0.8173, 1.0874, 1.1784],
  14212. [0.3279, 0.1234, 2.7894]])
  14213. >>> b = torch.randn(2, 4, 3)
  14214. >>> b
  14215. tensor([[[-0.4682, -0.7159, 0.1506],
  14216. [ 0.4034, -0.3657, 1.0387],
  14217. [ 0.9892, -0.6684, 0.1774],
  14218. [ 0.9482, 1.3261, 0.3917]],
  14219. [[ 0.4537, 0.7493, 1.1724],
  14220. [ 0.2291, 0.5749, -0.2267],
  14221. [-0.7920, 0.3607, -0.3701],
  14222. [ 1.3666, -0.5850, -1.7242]]])
  14223. >>> torch.inner(a, b)
  14224. tensor([[[-0.9837, 1.1560, 0.2907, 2.6785],
  14225. [ 2.5671, 0.5452, -0.6912, -1.5509]],
  14226. [[ 0.1782, 2.9843, 0.7366, 1.5672],
  14227. [ 3.5115, -0.4864, -1.2476, -4.4337]]])
  14228. # Scalar input
  14229. >>> torch.inner(a, torch.tensor(2))
  14230. tensor([[1.6347, 2.1748, 2.3567],
  14231. [0.6558, 0.2469, 5.5787]])
  14232. """
  14233. def instance_norm(
  14234. input: Tensor,
  14235. weight: Tensor | None,
  14236. bias: Tensor | None,
  14237. running_mean: Tensor | None,
  14238. running_var: Tensor | None,
  14239. use_input_stats: _bool,
  14240. momentum: _float,
  14241. eps: _float,
  14242. cudnn_enabled: _bool,
  14243. ) -> Tensor: ...
  14244. def int_repr(input: Tensor) -> Tensor: ...
  14245. def inverse(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  14246. r"""
  14247. inverse(input, *, out=None) -> Tensor
  14248. Alias for :func:`torch.linalg.inv`
  14249. """
  14250. def is_complex(input: Tensor) -> _bool:
  14251. r"""
  14252. is_complex(input: Tensor) -> bool
  14253. Returns True if the data type of :attr:`input` is a complex data type i.e.,
  14254. one of ``torch.complex64``, and ``torch.complex128``.
  14255. Args:
  14256. input (Tensor): the input tensor.
  14257. Example::
  14258. >>> torch.is_complex(torch.tensor([1, 2, 3], dtype=torch.complex64))
  14259. True
  14260. >>> torch.is_complex(torch.tensor([1, 2, 3], dtype=torch.complex128))
  14261. True
  14262. >>> torch.is_complex(torch.tensor([1, 2, 3], dtype=torch.int32))
  14263. False
  14264. >>> torch.is_complex(torch.tensor([1.0, 2.0, 3.0], dtype=torch.float16))
  14265. False
  14266. """
  14267. def is_conj(input: Tensor) -> _bool:
  14268. r"""
  14269. is_conj(input) -> (bool)
  14270. Returns True if the :attr:`input` is a conjugated tensor, i.e. its conjugate bit is set to `True`.
  14271. Args:
  14272. input (Tensor): the input tensor.
  14273. """
  14274. def is_distributed(input: Tensor) -> _bool: ...
  14275. def is_floating_point(input: Tensor) -> _bool:
  14276. r"""
  14277. is_floating_point(input: Tensor) -> bool
  14278. Returns True if the data type of :attr:`input` is a floating point data type i.e.,
  14279. one of ``torch.float64``, ``torch.float32``, ``torch.float16``, and ``torch.bfloat16``.
  14280. Args:
  14281. input (Tensor): the input tensor.
  14282. Example::
  14283. >>> torch.is_floating_point(torch.tensor([1.0, 2.0, 3.0]))
  14284. True
  14285. >>> torch.is_floating_point(torch.tensor([1, 2, 3], dtype=torch.int32))
  14286. False
  14287. >>> torch.is_floating_point(torch.tensor([1.0, 2.0, 3.0], dtype=torch.float16))
  14288. True
  14289. >>> torch.is_floating_point(torch.tensor([1, 2, 3], dtype=torch.complex64))
  14290. False
  14291. """
  14292. def is_grad_enabled() -> _bool:
  14293. r"""
  14294. is_grad_enabled() -> (bool)
  14295. Returns True if grad mode is currently enabled.
  14296. """
  14297. def is_inference(input: Tensor) -> _bool:
  14298. r"""
  14299. is_inference(input) -> (bool)
  14300. Returns True if :attr:`input` is an inference tensor.
  14301. A non-view tensor is an inference tensor if and only if it was
  14302. allocated during inference mode. A view tensor is an inference
  14303. tensor if and only if the tensor it is a view of is an inference tensor.
  14304. For details on inference mode please see
  14305. `Inference Mode <https://pytorch.org/cppdocs/notes/inference_mode.html>`_.
  14306. Args:
  14307. input (Tensor): the input tensor.
  14308. """
  14309. def is_inference_mode_enabled() -> _bool:
  14310. r"""
  14311. is_inference_mode_enabled() -> (bool)
  14312. Returns True if inference mode is currently enabled.
  14313. """
  14314. def is_neg(input: Tensor) -> _bool: ...
  14315. def is_nonzero(input: Tensor) -> _bool:
  14316. r"""
  14317. is_nonzero(input) -> (bool)
  14318. Returns True if the :attr:`input` is a single element tensor which is not equal to zero
  14319. after type conversions.
  14320. i.e. not equal to ``torch.tensor([0.])`` or ``torch.tensor([0])`` or
  14321. ``torch.tensor([False])``.
  14322. Throws a ``RuntimeError`` if ``torch.numel() != 1`` (even in case
  14323. of sparse tensors).
  14324. Args:
  14325. input (Tensor): the input tensor.
  14326. Examples::
  14327. >>> torch.is_nonzero(torch.tensor([0.]))
  14328. False
  14329. >>> torch.is_nonzero(torch.tensor([1.5]))
  14330. True
  14331. >>> torch.is_nonzero(torch.tensor([False]))
  14332. False
  14333. >>> torch.is_nonzero(torch.tensor([3]))
  14334. True
  14335. >>> torch.is_nonzero(torch.tensor([1, 3, 5]))
  14336. Traceback (most recent call last):
  14337. ...
  14338. RuntimeError: Boolean value of Tensor with more than one value is ambiguous
  14339. >>> torch.is_nonzero(torch.tensor([]))
  14340. Traceback (most recent call last):
  14341. ...
  14342. RuntimeError: Boolean value of Tensor with no values is ambiguous
  14343. """
  14344. def is_same_size(input: Tensor, other: Tensor) -> _bool: ...
  14345. def is_signed(input: Tensor) -> _bool: ...
  14346. def is_vulkan_available() -> _bool: ...
  14347. def isclose(
  14348. input: Tensor,
  14349. other: Tensor,
  14350. rtol: _float = 1e-05,
  14351. atol: _float = 1e-08,
  14352. equal_nan: _bool = False,
  14353. ) -> Tensor:
  14354. r"""
  14355. isclose(input, other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
  14356. Returns a new tensor with boolean elements representing if each element of
  14357. :attr:`input` is "close" to the corresponding element of :attr:`other`.
  14358. Closeness is defined as:
  14359. .. math::
  14360. \lvert \text{input}_i - \text{other}_i \rvert \leq \texttt{rtol} \times \lvert \text{other}_i \rvert + \texttt{atol}
  14361. where :attr:`input` and :attr:`other` are finite. Where :attr:`input`
  14362. and/or :attr:`other` are nonfinite they are close if and only if
  14363. they are equal, with NaNs being considered equal to each other when
  14364. :attr:`equal_nan` is True.
  14365. Args:
  14366. input (Tensor): first tensor to compare
  14367. other (Tensor): second tensor to compare
  14368. rtol (float, optional): relative tolerance. Default: 1e-05
  14369. atol (float, optional): absolute tolerance. Default: 1e-08
  14370. equal_nan (bool, optional): if ``True``, then two ``NaN`` s will be considered equal. Default: ``False``
  14371. Examples::
  14372. >>> torch.isclose(torch.tensor((1., 2, 3)), torch.tensor((1 + 1e-10, 3, 4)))
  14373. tensor([ True, False, False])
  14374. >>> torch.isclose(torch.tensor((float('inf'), 4)), torch.tensor((float('inf'), 6)), rtol=.5)
  14375. tensor([True, True])
  14376. """
  14377. def isfinite(input: Tensor) -> Tensor:
  14378. r"""
  14379. isfinite(input) -> Tensor
  14380. Returns a new tensor with boolean elements representing if each element is `finite` or not.
  14381. Real values are finite when they are not NaN, negative infinity, or infinity.
  14382. Complex values are finite when both their real and imaginary parts are finite.
  14383. Args:
  14384. input (Tensor): the input tensor.
  14385. Returns:
  14386. A boolean tensor that is True where :attr:`input` is finite and False elsewhere
  14387. Example::
  14388. >>> torch.isfinite(torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')]))
  14389. tensor([True, False, True, False, False])
  14390. """
  14391. @overload
  14392. def isin(
  14393. elements: Tensor,
  14394. test_elements: Tensor,
  14395. *,
  14396. assume_unique: _bool = False,
  14397. invert: _bool = False,
  14398. out: Tensor | None = None,
  14399. ) -> Tensor:
  14400. r"""
  14401. isin(elements, test_elements, *, assume_unique=False, invert=False) -> Tensor
  14402. Tests if each element of :attr:`elements` is in :attr:`test_elements`. Returns
  14403. a boolean tensor of the same shape as :attr:`elements` that is True for elements
  14404. in :attr:`test_elements` and False otherwise.
  14405. .. note::
  14406. One of :attr:`elements` or :attr:`test_elements` can be a scalar, but not both.
  14407. Args:
  14408. elements (Tensor or Scalar): Input elements
  14409. test_elements (Tensor or Scalar): Values against which to test for each input element
  14410. assume_unique (bool, optional): If True, assumes both :attr:`elements` and
  14411. :attr:`test_elements` contain unique elements, which can speed up the
  14412. calculation. Default: False
  14413. invert (bool, optional): If True, inverts the boolean return tensor, resulting in True
  14414. values for elements *not* in :attr:`test_elements`. Default: False
  14415. Returns:
  14416. A boolean tensor of the same shape as :attr:`elements` that is True for elements in
  14417. :attr:`test_elements` and False otherwise
  14418. Example:
  14419. >>> torch.isin(torch.tensor([[1, 2], [3, 4]]), torch.tensor([2, 3]))
  14420. tensor([[False, True],
  14421. [ True, False]])
  14422. """
  14423. @overload
  14424. def isin(
  14425. element: Number | _complex,
  14426. test_elements: Tensor,
  14427. *,
  14428. assume_unique: _bool = False,
  14429. invert: _bool = False,
  14430. out: Tensor | None = None,
  14431. ) -> Tensor:
  14432. r"""
  14433. isin(elements, test_elements, *, assume_unique=False, invert=False) -> Tensor
  14434. Tests if each element of :attr:`elements` is in :attr:`test_elements`. Returns
  14435. a boolean tensor of the same shape as :attr:`elements` that is True for elements
  14436. in :attr:`test_elements` and False otherwise.
  14437. .. note::
  14438. One of :attr:`elements` or :attr:`test_elements` can be a scalar, but not both.
  14439. Args:
  14440. elements (Tensor or Scalar): Input elements
  14441. test_elements (Tensor or Scalar): Values against which to test for each input element
  14442. assume_unique (bool, optional): If True, assumes both :attr:`elements` and
  14443. :attr:`test_elements` contain unique elements, which can speed up the
  14444. calculation. Default: False
  14445. invert (bool, optional): If True, inverts the boolean return tensor, resulting in True
  14446. values for elements *not* in :attr:`test_elements`. Default: False
  14447. Returns:
  14448. A boolean tensor of the same shape as :attr:`elements` that is True for elements in
  14449. :attr:`test_elements` and False otherwise
  14450. Example:
  14451. >>> torch.isin(torch.tensor([[1, 2], [3, 4]]), torch.tensor([2, 3]))
  14452. tensor([[False, True],
  14453. [ True, False]])
  14454. """
  14455. @overload
  14456. def isin(
  14457. elements: Tensor,
  14458. test_element: Number | _complex,
  14459. *,
  14460. assume_unique: _bool = False,
  14461. invert: _bool = False,
  14462. out: Tensor | None = None,
  14463. ) -> Tensor:
  14464. r"""
  14465. isin(elements, test_elements, *, assume_unique=False, invert=False) -> Tensor
  14466. Tests if each element of :attr:`elements` is in :attr:`test_elements`. Returns
  14467. a boolean tensor of the same shape as :attr:`elements` that is True for elements
  14468. in :attr:`test_elements` and False otherwise.
  14469. .. note::
  14470. One of :attr:`elements` or :attr:`test_elements` can be a scalar, but not both.
  14471. Args:
  14472. elements (Tensor or Scalar): Input elements
  14473. test_elements (Tensor or Scalar): Values against which to test for each input element
  14474. assume_unique (bool, optional): If True, assumes both :attr:`elements` and
  14475. :attr:`test_elements` contain unique elements, which can speed up the
  14476. calculation. Default: False
  14477. invert (bool, optional): If True, inverts the boolean return tensor, resulting in True
  14478. values for elements *not* in :attr:`test_elements`. Default: False
  14479. Returns:
  14480. A boolean tensor of the same shape as :attr:`elements` that is True for elements in
  14481. :attr:`test_elements` and False otherwise
  14482. Example:
  14483. >>> torch.isin(torch.tensor([[1, 2], [3, 4]]), torch.tensor([2, 3]))
  14484. tensor([[False, True],
  14485. [ True, False]])
  14486. """
  14487. def isinf(input: Tensor) -> Tensor:
  14488. r"""
  14489. isinf(input) -> Tensor
  14490. Tests if each element of :attr:`input` is infinite
  14491. (positive or negative infinity) or not.
  14492. .. note::
  14493. Complex values are infinite when their real or imaginary part is
  14494. infinite.
  14495. Args:
  14496. input (Tensor): the input tensor.
  14497. Returns:
  14498. A boolean tensor that is True where :attr:`input` is infinite and False elsewhere
  14499. Example::
  14500. >>> torch.isinf(torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')]))
  14501. tensor([False, True, False, True, False])
  14502. """
  14503. def isnan(input: Tensor) -> Tensor:
  14504. r"""
  14505. isnan(input) -> Tensor
  14506. Returns a new tensor with boolean elements representing if each element of :attr:`input`
  14507. is NaN or not. Complex values are considered NaN when either their real
  14508. and/or imaginary part is NaN.
  14509. Arguments:
  14510. input (Tensor): the input tensor.
  14511. Returns:
  14512. A boolean tensor that is True where :attr:`input` is NaN and False elsewhere
  14513. Example::
  14514. >>> torch.isnan(torch.tensor([1, float('nan'), 2]))
  14515. tensor([False, True, False])
  14516. """
  14517. def isneginf(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  14518. r"""
  14519. isneginf(input, *, out=None) -> Tensor
  14520. Tests if each element of :attr:`input` is negative infinity or not.
  14521. Args:
  14522. input (Tensor): the input tensor.
  14523. Keyword args:
  14524. out (Tensor, optional): the output tensor.
  14525. Example::
  14526. >>> a = torch.tensor([-float('inf'), float('inf'), 1.2])
  14527. >>> torch.isneginf(a)
  14528. tensor([ True, False, False])
  14529. """
  14530. def isposinf(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  14531. r"""
  14532. isposinf(input, *, out=None) -> Tensor
  14533. Tests if each element of :attr:`input` is positive infinity or not.
  14534. Args:
  14535. input (Tensor): the input tensor.
  14536. Keyword args:
  14537. out (Tensor, optional): the output tensor.
  14538. Example::
  14539. >>> a = torch.tensor([-float('inf'), float('inf'), 1.2])
  14540. >>> torch.isposinf(a)
  14541. tensor([False, True, False])
  14542. """
  14543. def isreal(input: Tensor) -> Tensor:
  14544. r"""
  14545. isreal(input) -> Tensor
  14546. Returns a new tensor with boolean elements representing if each element of :attr:`input` is real-valued or not.
  14547. All real-valued types are considered real. Complex values are considered real when their imaginary part is 0.
  14548. Arguments:
  14549. input (Tensor): the input tensor.
  14550. Returns:
  14551. A boolean tensor that is True where :attr:`input` is real and False elsewhere
  14552. Example::
  14553. >>> torch.isreal(torch.tensor([1, 1+1j, 2+0j]))
  14554. tensor([True, False, True])
  14555. """
  14556. def istft(
  14557. input: Tensor,
  14558. n_fft: _int,
  14559. hop_length: _int | None = None,
  14560. win_length: _int | None = None,
  14561. window: Tensor | None = None,
  14562. center: _bool = True,
  14563. normalized: _bool = False,
  14564. onesided: _bool | None = None,
  14565. length: _int | None = None,
  14566. return_complex: _bool = False,
  14567. ) -> Tensor: ...
  14568. @overload
  14569. def kaiser_window(
  14570. window_length: _int,
  14571. *,
  14572. dtype: _dtype | None = None,
  14573. layout: _layout | None = None,
  14574. device: DeviceLikeType | None = None,
  14575. pin_memory: _bool | None = False,
  14576. requires_grad: _bool | None = False,
  14577. ) -> Tensor:
  14578. r"""
  14579. kaiser_window(window_length, periodic=True, beta=12.0, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  14580. Computes the Kaiser window with window length :attr:`window_length` and shape parameter :attr:`beta`.
  14581. Let I_0 be the zeroth order modified Bessel function of the first kind (see :func:`torch.i0`) and
  14582. ``N = L - 1`` if :attr:`periodic` is False and ``L`` if :attr:`periodic` is True,
  14583. where ``L`` is the :attr:`window_length`. This function computes:
  14584. .. math::
  14585. out_i = I_0 \left( \beta \sqrt{1 - \left( {\frac{i - N/2}{N/2}} \right) ^2 } \right) / I_0( \beta )
  14586. Calling ``torch.kaiser_window(L, B, periodic=True)`` is equivalent to calling
  14587. ``torch.kaiser_window(L + 1, B, periodic=False)[:-1])``.
  14588. The :attr:`periodic` argument is intended as a helpful shorthand
  14589. to produce a periodic window as input to functions like :func:`torch.stft`.
  14590. .. note::
  14591. If :attr:`window_length` is one, then the returned window is a single element tensor containing a one.
  14592. Args:
  14593. window_length (int): length of the window.
  14594. periodic (bool, optional): If True, returns a periodic window suitable for use in spectral analysis.
  14595. If False, returns a symmetric window suitable for use in filter design.
  14596. beta (float, optional): shape parameter for the window.
  14597. Keyword args:
  14598. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  14599. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  14600. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  14601. ``torch.strided`` (dense layout) is supported.
  14602. device (:class:`torch.device`, optional): the desired device of returned tensor.
  14603. Default: if ``None``, uses the current device for the default tensor type
  14604. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  14605. for CPU tensor types and the current CUDA device for CUDA tensor types.
  14606. requires_grad (bool, optional): If autograd should record operations on the
  14607. returned tensor. Default: ``False``.
  14608. """
  14609. @overload
  14610. def kaiser_window(
  14611. window_length: _int,
  14612. periodic: _bool,
  14613. *,
  14614. dtype: _dtype | None = None,
  14615. layout: _layout | None = None,
  14616. device: DeviceLikeType | None = None,
  14617. pin_memory: _bool | None = False,
  14618. requires_grad: _bool | None = False,
  14619. ) -> Tensor:
  14620. r"""
  14621. kaiser_window(window_length, periodic=True, beta=12.0, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  14622. Computes the Kaiser window with window length :attr:`window_length` and shape parameter :attr:`beta`.
  14623. Let I_0 be the zeroth order modified Bessel function of the first kind (see :func:`torch.i0`) and
  14624. ``N = L - 1`` if :attr:`periodic` is False and ``L`` if :attr:`periodic` is True,
  14625. where ``L`` is the :attr:`window_length`. This function computes:
  14626. .. math::
  14627. out_i = I_0 \left( \beta \sqrt{1 - \left( {\frac{i - N/2}{N/2}} \right) ^2 } \right) / I_0( \beta )
  14628. Calling ``torch.kaiser_window(L, B, periodic=True)`` is equivalent to calling
  14629. ``torch.kaiser_window(L + 1, B, periodic=False)[:-1])``.
  14630. The :attr:`periodic` argument is intended as a helpful shorthand
  14631. to produce a periodic window as input to functions like :func:`torch.stft`.
  14632. .. note::
  14633. If :attr:`window_length` is one, then the returned window is a single element tensor containing a one.
  14634. Args:
  14635. window_length (int): length of the window.
  14636. periodic (bool, optional): If True, returns a periodic window suitable for use in spectral analysis.
  14637. If False, returns a symmetric window suitable for use in filter design.
  14638. beta (float, optional): shape parameter for the window.
  14639. Keyword args:
  14640. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  14641. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  14642. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  14643. ``torch.strided`` (dense layout) is supported.
  14644. device (:class:`torch.device`, optional): the desired device of returned tensor.
  14645. Default: if ``None``, uses the current device for the default tensor type
  14646. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  14647. for CPU tensor types and the current CUDA device for CUDA tensor types.
  14648. requires_grad (bool, optional): If autograd should record operations on the
  14649. returned tensor. Default: ``False``.
  14650. """
  14651. @overload
  14652. def kaiser_window(
  14653. window_length: _int,
  14654. periodic: _bool,
  14655. beta: _float,
  14656. *,
  14657. dtype: _dtype | None = None,
  14658. layout: _layout | None = None,
  14659. device: DeviceLikeType | None = None,
  14660. pin_memory: _bool | None = False,
  14661. requires_grad: _bool | None = False,
  14662. ) -> Tensor:
  14663. r"""
  14664. kaiser_window(window_length, periodic=True, beta=12.0, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  14665. Computes the Kaiser window with window length :attr:`window_length` and shape parameter :attr:`beta`.
  14666. Let I_0 be the zeroth order modified Bessel function of the first kind (see :func:`torch.i0`) and
  14667. ``N = L - 1`` if :attr:`periodic` is False and ``L`` if :attr:`periodic` is True,
  14668. where ``L`` is the :attr:`window_length`. This function computes:
  14669. .. math::
  14670. out_i = I_0 \left( \beta \sqrt{1 - \left( {\frac{i - N/2}{N/2}} \right) ^2 } \right) / I_0( \beta )
  14671. Calling ``torch.kaiser_window(L, B, periodic=True)`` is equivalent to calling
  14672. ``torch.kaiser_window(L + 1, B, periodic=False)[:-1])``.
  14673. The :attr:`periodic` argument is intended as a helpful shorthand
  14674. to produce a periodic window as input to functions like :func:`torch.stft`.
  14675. .. note::
  14676. If :attr:`window_length` is one, then the returned window is a single element tensor containing a one.
  14677. Args:
  14678. window_length (int): length of the window.
  14679. periodic (bool, optional): If True, returns a periodic window suitable for use in spectral analysis.
  14680. If False, returns a symmetric window suitable for use in filter design.
  14681. beta (float, optional): shape parameter for the window.
  14682. Keyword args:
  14683. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  14684. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  14685. layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
  14686. ``torch.strided`` (dense layout) is supported.
  14687. device (:class:`torch.device`, optional): the desired device of returned tensor.
  14688. Default: if ``None``, uses the current device for the default tensor type
  14689. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  14690. for CPU tensor types and the current CUDA device for CUDA tensor types.
  14691. requires_grad (bool, optional): If autograd should record operations on the
  14692. returned tensor. Default: ``False``.
  14693. """
  14694. def kl_div(
  14695. input: Tensor,
  14696. target: Tensor,
  14697. reduction: _int = 1,
  14698. *,
  14699. log_target: _bool = False,
  14700. ) -> Tensor: ...
  14701. def kron(
  14702. input: Tensor,
  14703. other: Tensor,
  14704. *,
  14705. out: Tensor | None = None,
  14706. ) -> Tensor:
  14707. r"""
  14708. kron(input, other, *, out=None) -> Tensor
  14709. Computes the Kronecker product, denoted by :math:`\otimes`, of :attr:`input` and :attr:`other`.
  14710. If :attr:`input` is a :math:`(a_0 \times a_1 \times \dots \times a_n)` tensor and :attr:`other` is a
  14711. :math:`(b_0 \times b_1 \times \dots \times b_n)` tensor, the result will be a
  14712. :math:`(a_0*b_0 \times a_1*b_1 \times \dots \times a_n*b_n)` tensor with the following entries:
  14713. .. math::
  14714. (\text{input} \otimes \text{other})_{k_0, k_1, \dots, k_n} =
  14715. \text{input}_{i_0, i_1, \dots, i_n} * \text{other}_{j_0, j_1, \dots, j_n},
  14716. where :math:`k_t = i_t * b_t + j_t` for :math:`0 \leq t \leq n`.
  14717. If one tensor has fewer dimensions than the other it is unsqueezed until it has the same number of dimensions.
  14718. Supports real-valued and complex-valued inputs.
  14719. .. note::
  14720. This function generalizes the typical definition of the Kronecker product for two matrices to two tensors,
  14721. as described above. When :attr:`input` is a :math:`(m \times n)` matrix and :attr:`other` is a
  14722. :math:`(p \times q)` matrix, the result will be a :math:`(p*m \times q*n)` block matrix:
  14723. .. math::
  14724. \mathbf{A} \otimes \mathbf{B}=\begin{bmatrix}
  14725. a_{11} \mathbf{B} & \cdots & a_{1 n} \mathbf{B} \\
  14726. \vdots & \ddots & \vdots \\
  14727. a_{m 1} \mathbf{B} & \cdots & a_{m n} \mathbf{B} \end{bmatrix}
  14728. where :attr:`input` is :math:`\mathbf{A}` and :attr:`other` is :math:`\mathbf{B}`.
  14729. Arguments:
  14730. input (Tensor)
  14731. other (Tensor)
  14732. Keyword args:
  14733. out (Tensor, optional): The output tensor. Ignored if ``None``. Default: ``None``
  14734. Examples::
  14735. >>> mat1 = torch.eye(2)
  14736. >>> mat2 = torch.ones(2, 2)
  14737. >>> torch.kron(mat1, mat2)
  14738. tensor([[1., 1., 0., 0.],
  14739. [1., 1., 0., 0.],
  14740. [0., 0., 1., 1.],
  14741. [0., 0., 1., 1.]])
  14742. >>> mat1 = torch.eye(2)
  14743. >>> mat2 = torch.arange(1, 5).reshape(2, 2)
  14744. >>> torch.kron(mat1, mat2)
  14745. tensor([[1., 2., 0., 0.],
  14746. [3., 4., 0., 0.],
  14747. [0., 0., 1., 2.],
  14748. [0., 0., 3., 4.]])
  14749. """
  14750. @overload
  14751. def kthvalue(
  14752. input: Tensor,
  14753. k: _int | SymInt,
  14754. dim: _int = -1,
  14755. keepdim: _bool = False,
  14756. *,
  14757. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  14758. ) -> torch.return_types.kthvalue:
  14759. r"""
  14760. kthvalue(input, k, dim=None, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  14761. Returns a namedtuple ``(values, indices)`` where ``values`` is the :attr:`k` th
  14762. smallest element of each row of the :attr:`input` tensor in the given dimension
  14763. :attr:`dim`. And ``indices`` is the index location of each element found.
  14764. If :attr:`dim` is not given, the last dimension of the `input` is chosen.
  14765. If :attr:`keepdim` is ``True``, both the :attr:`values` and :attr:`indices` tensors
  14766. are the same size as :attr:`input`, except in the dimension :attr:`dim` where
  14767. they are of size 1. Otherwise, :attr:`dim` is squeezed
  14768. (see :func:`torch.squeeze`), resulting in both the :attr:`values` and
  14769. :attr:`indices` tensors having 1 fewer dimension than the :attr:`input` tensor.
  14770. .. note::
  14771. When :attr:`input` is a CUDA tensor and there are multiple valid
  14772. :attr:`k` th values, this function may nondeterministically return
  14773. :attr:`indices` for any of them.
  14774. Args:
  14775. input (Tensor): the input tensor.
  14776. k (int): k for the k-th smallest element
  14777. dim (int, optional): the dimension to find the kth value along
  14778. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  14779. Keyword args:
  14780. out (tuple, optional): the output tuple of (Tensor, LongTensor)
  14781. can be optionally given to be used as output buffers
  14782. Example::
  14783. >>> x = torch.arange(1., 6.)
  14784. >>> x
  14785. tensor([ 1., 2., 3., 4., 5.])
  14786. >>> torch.kthvalue(x, 4)
  14787. torch.return_types.kthvalue(values=tensor(4.), indices=tensor(3))
  14788. >>> x=torch.arange(1.,7.).resize_(2,3)
  14789. >>> x
  14790. tensor([[ 1., 2., 3.],
  14791. [ 4., 5., 6.]])
  14792. >>> torch.kthvalue(x, 2, 0, True)
  14793. torch.return_types.kthvalue(values=tensor([[4., 5., 6.]]), indices=tensor([[1, 1, 1]]))
  14794. """
  14795. @overload
  14796. def kthvalue(
  14797. input: Tensor,
  14798. k: _int | SymInt,
  14799. dim: str | EllipsisType | None,
  14800. keepdim: _bool = False,
  14801. *,
  14802. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  14803. ) -> torch.return_types.kthvalue:
  14804. r"""
  14805. kthvalue(input, k, dim=None, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  14806. Returns a namedtuple ``(values, indices)`` where ``values`` is the :attr:`k` th
  14807. smallest element of each row of the :attr:`input` tensor in the given dimension
  14808. :attr:`dim`. And ``indices`` is the index location of each element found.
  14809. If :attr:`dim` is not given, the last dimension of the `input` is chosen.
  14810. If :attr:`keepdim` is ``True``, both the :attr:`values` and :attr:`indices` tensors
  14811. are the same size as :attr:`input`, except in the dimension :attr:`dim` where
  14812. they are of size 1. Otherwise, :attr:`dim` is squeezed
  14813. (see :func:`torch.squeeze`), resulting in both the :attr:`values` and
  14814. :attr:`indices` tensors having 1 fewer dimension than the :attr:`input` tensor.
  14815. .. note::
  14816. When :attr:`input` is a CUDA tensor and there are multiple valid
  14817. :attr:`k` th values, this function may nondeterministically return
  14818. :attr:`indices` for any of them.
  14819. Args:
  14820. input (Tensor): the input tensor.
  14821. k (int): k for the k-th smallest element
  14822. dim (int, optional): the dimension to find the kth value along
  14823. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  14824. Keyword args:
  14825. out (tuple, optional): the output tuple of (Tensor, LongTensor)
  14826. can be optionally given to be used as output buffers
  14827. Example::
  14828. >>> x = torch.arange(1., 6.)
  14829. >>> x
  14830. tensor([ 1., 2., 3., 4., 5.])
  14831. >>> torch.kthvalue(x, 4)
  14832. torch.return_types.kthvalue(values=tensor(4.), indices=tensor(3))
  14833. >>> x=torch.arange(1.,7.).resize_(2,3)
  14834. >>> x
  14835. tensor([[ 1., 2., 3.],
  14836. [ 4., 5., 6.]])
  14837. >>> torch.kthvalue(x, 2, 0, True)
  14838. torch.return_types.kthvalue(values=tensor([[4., 5., 6.]]), indices=tensor([[1, 1, 1]]))
  14839. """
  14840. def layer_norm(
  14841. input: Tensor,
  14842. normalized_shape: Sequence[_int | SymInt],
  14843. weight: Tensor | None = None,
  14844. bias: Tensor | None = None,
  14845. eps: _float = 1e-05,
  14846. cudnn_enable: _bool = True,
  14847. ) -> Tensor: ...
  14848. def lcm(
  14849. input: Tensor,
  14850. other: Tensor,
  14851. *,
  14852. out: Tensor | None = None,
  14853. ) -> Tensor:
  14854. r"""
  14855. lcm(input, other, *, out=None) -> Tensor
  14856. Computes the element-wise least common multiple (LCM) of :attr:`input` and :attr:`other`.
  14857. Both :attr:`input` and :attr:`other` must have integer types.
  14858. .. note::
  14859. This defines :math:`lcm(0, 0) = 0` and :math:`lcm(0, a) = 0`.
  14860. Args:
  14861. input (Tensor): the input tensor.
  14862. other (Tensor): the second input tensor
  14863. Keyword arguments:
  14864. out (Tensor, optional): the output tensor.
  14865. Example::
  14866. >>> a = torch.tensor([5, 10, 15])
  14867. >>> b = torch.tensor([3, 4, 5])
  14868. >>> torch.lcm(a, b)
  14869. tensor([15, 20, 15])
  14870. >>> c = torch.tensor([3])
  14871. >>> torch.lcm(a, c)
  14872. tensor([15, 30, 15])
  14873. """
  14874. def lcm_(input: Tensor, other: Tensor) -> Tensor: ...
  14875. def ldexp(
  14876. input: Tensor,
  14877. other: Tensor,
  14878. *,
  14879. out: Tensor | None = None,
  14880. ) -> Tensor:
  14881. r"""
  14882. ldexp(input, other, *, out=None) -> Tensor
  14883. Multiplies :attr:`input` by 2 ** :attr:`other`.
  14884. .. math::
  14885. \text{{out}}_i = \text{{input}}_i * 2^\text{{other}}_i
  14886. Typically this function is used to construct floating point numbers by multiplying
  14887. mantissas in :attr:`input` with integral powers of two created from the exponents
  14888. in :attr:`other`.
  14889. Args:
  14890. input (Tensor): the input tensor.
  14891. other (Tensor): a tensor of exponents, typically integers.
  14892. Keyword args:
  14893. out (Tensor, optional): the output tensor.
  14894. Example::
  14895. >>> torch.ldexp(torch.tensor([1.]), torch.tensor([1]))
  14896. tensor([2.])
  14897. >>> torch.ldexp(torch.tensor([1.0]), torch.tensor([1, 2, 3, 4]))
  14898. tensor([ 2., 4., 8., 16.])
  14899. """
  14900. def ldexp_(input: Tensor, other: Tensor) -> Tensor: ...
  14901. @overload
  14902. def le(
  14903. input: Tensor,
  14904. other: Tensor,
  14905. *,
  14906. out: Tensor | None = None,
  14907. ) -> Tensor:
  14908. r"""
  14909. le(input, other, *, out=None) -> Tensor
  14910. Computes :math:`\text{input} \leq \text{other}` element-wise.
  14911. The second argument can be a number or a tensor whose shape is
  14912. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  14913. Args:
  14914. input (Tensor): the tensor to compare
  14915. other (Tensor or Scalar): the tensor or value to compare
  14916. Keyword args:
  14917. out (Tensor, optional): the output tensor.
  14918. Returns:
  14919. A boolean tensor that is True where :attr:`input` is less than or equal to
  14920. :attr:`other` and False elsewhere
  14921. Example::
  14922. >>> torch.le(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  14923. tensor([[True, False], [True, True]])
  14924. """
  14925. @overload
  14926. def le(
  14927. input: Tensor,
  14928. other: Number | _complex,
  14929. *,
  14930. out: Tensor | None = None,
  14931. ) -> Tensor:
  14932. r"""
  14933. le(input, other, *, out=None) -> Tensor
  14934. Computes :math:`\text{input} \leq \text{other}` element-wise.
  14935. The second argument can be a number or a tensor whose shape is
  14936. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  14937. Args:
  14938. input (Tensor): the tensor to compare
  14939. other (Tensor or Scalar): the tensor or value to compare
  14940. Keyword args:
  14941. out (Tensor, optional): the output tensor.
  14942. Returns:
  14943. A boolean tensor that is True where :attr:`input` is less than or equal to
  14944. :attr:`other` and False elsewhere
  14945. Example::
  14946. >>> torch.le(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  14947. tensor([[True, False], [True, True]])
  14948. """
  14949. @overload
  14950. def lerp(
  14951. input: Tensor,
  14952. end: Tensor,
  14953. weight: Tensor,
  14954. *,
  14955. out: Tensor | None = None,
  14956. ) -> Tensor:
  14957. r"""
  14958. lerp(input, end, weight, *, out=None)
  14959. Does a linear interpolation of two tensors :attr:`start` (given by :attr:`input`) and :attr:`end` based
  14960. on a scalar or tensor :attr:`weight` and returns the resulting :attr:`out` tensor.
  14961. .. math::
  14962. \text{out}_i = \text{start}_i + \text{weight}_i \times (\text{end}_i - \text{start}_i)
  14963. The shapes of :attr:`start` and :attr:`end` must be
  14964. :ref:`broadcastable <broadcasting-semantics>`. If :attr:`weight` is a tensor, then
  14965. the shapes of :attr:`weight`, :attr:`start`, and :attr:`end` must be :ref:`broadcastable <broadcasting-semantics>`.
  14966. Args:
  14967. input (Tensor): the tensor with the starting points
  14968. end (Tensor): the tensor with the ending points
  14969. weight (float or tensor): the weight for the interpolation formula
  14970. Keyword args:
  14971. out (Tensor, optional): the output tensor.
  14972. Example::
  14973. >>> start = torch.arange(1., 5.)
  14974. >>> end = torch.empty(4).fill_(10)
  14975. >>> start
  14976. tensor([ 1., 2., 3., 4.])
  14977. >>> end
  14978. tensor([ 10., 10., 10., 10.])
  14979. >>> torch.lerp(start, end, 0.5)
  14980. tensor([ 5.5000, 6.0000, 6.5000, 7.0000])
  14981. >>> torch.lerp(start, end, torch.full_like(start, 0.5))
  14982. tensor([ 5.5000, 6.0000, 6.5000, 7.0000])
  14983. """
  14984. @overload
  14985. def lerp(
  14986. input: Tensor,
  14987. end: Tensor,
  14988. weight: Number | _complex,
  14989. *,
  14990. out: Tensor | None = None,
  14991. ) -> Tensor:
  14992. r"""
  14993. lerp(input, end, weight, *, out=None)
  14994. Does a linear interpolation of two tensors :attr:`start` (given by :attr:`input`) and :attr:`end` based
  14995. on a scalar or tensor :attr:`weight` and returns the resulting :attr:`out` tensor.
  14996. .. math::
  14997. \text{out}_i = \text{start}_i + \text{weight}_i \times (\text{end}_i - \text{start}_i)
  14998. The shapes of :attr:`start` and :attr:`end` must be
  14999. :ref:`broadcastable <broadcasting-semantics>`. If :attr:`weight` is a tensor, then
  15000. the shapes of :attr:`weight`, :attr:`start`, and :attr:`end` must be :ref:`broadcastable <broadcasting-semantics>`.
  15001. Args:
  15002. input (Tensor): the tensor with the starting points
  15003. end (Tensor): the tensor with the ending points
  15004. weight (float or tensor): the weight for the interpolation formula
  15005. Keyword args:
  15006. out (Tensor, optional): the output tensor.
  15007. Example::
  15008. >>> start = torch.arange(1., 5.)
  15009. >>> end = torch.empty(4).fill_(10)
  15010. >>> start
  15011. tensor([ 1., 2., 3., 4.])
  15012. >>> end
  15013. tensor([ 10., 10., 10., 10.])
  15014. >>> torch.lerp(start, end, 0.5)
  15015. tensor([ 5.5000, 6.0000, 6.5000, 7.0000])
  15016. >>> torch.lerp(start, end, torch.full_like(start, 0.5))
  15017. tensor([ 5.5000, 6.0000, 6.5000, 7.0000])
  15018. """
  15019. @overload
  15020. def less(
  15021. input: Tensor,
  15022. other: Tensor,
  15023. *,
  15024. out: Tensor | None = None,
  15025. ) -> Tensor:
  15026. r"""
  15027. less(input, other, *, out=None) -> Tensor
  15028. Alias for :func:`torch.lt`.
  15029. """
  15030. @overload
  15031. def less(
  15032. input: Tensor,
  15033. other: Number | _complex,
  15034. *,
  15035. out: Tensor | None = None,
  15036. ) -> Tensor:
  15037. r"""
  15038. less(input, other, *, out=None) -> Tensor
  15039. Alias for :func:`torch.lt`.
  15040. """
  15041. @overload
  15042. def less_equal(
  15043. input: Tensor,
  15044. other: Tensor,
  15045. *,
  15046. out: Tensor | None = None,
  15047. ) -> Tensor:
  15048. r"""
  15049. less_equal(input, other, *, out=None) -> Tensor
  15050. Alias for :func:`torch.le`.
  15051. """
  15052. @overload
  15053. def less_equal(
  15054. input: Tensor,
  15055. other: Number | _complex,
  15056. *,
  15057. out: Tensor | None = None,
  15058. ) -> Tensor:
  15059. r"""
  15060. less_equal(input, other, *, out=None) -> Tensor
  15061. Alias for :func:`torch.le`.
  15062. """
  15063. def lgamma(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  15064. r"""
  15065. lgamma(input, *, out=None) -> Tensor
  15066. Computes the natural logarithm of the absolute value of the gamma function on :attr:`input`.
  15067. .. math::
  15068. \text{out}_{i} = \ln |\Gamma(\text{input}_{i})|
  15069. Args:
  15070. input (Tensor): the input tensor.
  15071. Keyword args:
  15072. out (Tensor, optional): the output tensor.
  15073. Example::
  15074. >>> a = torch.arange(0.5, 2, 0.5)
  15075. >>> torch.lgamma(a)
  15076. tensor([ 0.5724, 0.0000, -0.1208])
  15077. """
  15078. @overload
  15079. def linspace(
  15080. start: Number,
  15081. end: Number,
  15082. steps: _int | None = None,
  15083. *,
  15084. out: Tensor | None = None,
  15085. dtype: _dtype | None = None,
  15086. device: DeviceLikeType | None = None,
  15087. requires_grad: _bool = False,
  15088. pin_memory: _bool = False,
  15089. ) -> Tensor:
  15090. r"""
  15091. linspace(start, end, steps, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15092. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15093. spaced from :attr:`start` to :attr:`end`, inclusive. That is, the value are:
  15094. .. math::
  15095. (\text{start},
  15096. \text{start} + \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15097. \ldots,
  15098. \text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15099. \text{end})
  15100. From PyTorch 1.11 linspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15101. Args:
  15102. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15103. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15104. steps (int): size of the constructed tensor
  15105. Keyword arguments:
  15106. out (Tensor, optional): the output tensor.
  15107. dtype (torch.dtype, optional): the data type to perform the computation in.
  15108. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15109. when both :attr:`start` and :attr:`end` are real,
  15110. and corresponding complex dtype when either is complex.
  15111. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15112. Default: ``torch.strided``.
  15113. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15114. Default: if ``None``, uses the current device for the default tensor type
  15115. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15116. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15117. requires_grad (bool, optional): If autograd should record operations on the
  15118. returned tensor. Default: ``False``.
  15119. Example::
  15120. >>> torch.linspace(3, 10, steps=5)
  15121. tensor([ 3.0000, 4.7500, 6.5000, 8.2500, 10.0000])
  15122. >>> torch.linspace(-10, 10, steps=5)
  15123. tensor([-10., -5., 0., 5., 10.])
  15124. >>> torch.linspace(start=-10, end=10, steps=5)
  15125. tensor([-10., -5., 0., 5., 10.])
  15126. >>> torch.linspace(start=-10, end=10, steps=1)
  15127. tensor([-10.])
  15128. """
  15129. @overload
  15130. def linspace(
  15131. start: Tensor,
  15132. end: Tensor,
  15133. steps: _int,
  15134. *,
  15135. out: Tensor | None = None,
  15136. dtype: _dtype | None = None,
  15137. layout: _layout | None = None,
  15138. device: DeviceLikeType | None = None,
  15139. pin_memory: _bool | None = False,
  15140. requires_grad: _bool | None = False,
  15141. ) -> Tensor:
  15142. r"""
  15143. linspace(start, end, steps, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15144. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15145. spaced from :attr:`start` to :attr:`end`, inclusive. That is, the value are:
  15146. .. math::
  15147. (\text{start},
  15148. \text{start} + \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15149. \ldots,
  15150. \text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15151. \text{end})
  15152. From PyTorch 1.11 linspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15153. Args:
  15154. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15155. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15156. steps (int): size of the constructed tensor
  15157. Keyword arguments:
  15158. out (Tensor, optional): the output tensor.
  15159. dtype (torch.dtype, optional): the data type to perform the computation in.
  15160. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15161. when both :attr:`start` and :attr:`end` are real,
  15162. and corresponding complex dtype when either is complex.
  15163. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15164. Default: ``torch.strided``.
  15165. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15166. Default: if ``None``, uses the current device for the default tensor type
  15167. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15168. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15169. requires_grad (bool, optional): If autograd should record operations on the
  15170. returned tensor. Default: ``False``.
  15171. Example::
  15172. >>> torch.linspace(3, 10, steps=5)
  15173. tensor([ 3.0000, 4.7500, 6.5000, 8.2500, 10.0000])
  15174. >>> torch.linspace(-10, 10, steps=5)
  15175. tensor([-10., -5., 0., 5., 10.])
  15176. >>> torch.linspace(start=-10, end=10, steps=5)
  15177. tensor([-10., -5., 0., 5., 10.])
  15178. >>> torch.linspace(start=-10, end=10, steps=1)
  15179. tensor([-10.])
  15180. """
  15181. @overload
  15182. def linspace(
  15183. start: Number | _complex,
  15184. end: Tensor,
  15185. steps: _int,
  15186. *,
  15187. out: Tensor | None = None,
  15188. dtype: _dtype | None = None,
  15189. layout: _layout | None = None,
  15190. device: DeviceLikeType | None = None,
  15191. pin_memory: _bool | None = False,
  15192. requires_grad: _bool | None = False,
  15193. ) -> Tensor:
  15194. r"""
  15195. linspace(start, end, steps, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15196. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15197. spaced from :attr:`start` to :attr:`end`, inclusive. That is, the value are:
  15198. .. math::
  15199. (\text{start},
  15200. \text{start} + \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15201. \ldots,
  15202. \text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15203. \text{end})
  15204. From PyTorch 1.11 linspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15205. Args:
  15206. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15207. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15208. steps (int): size of the constructed tensor
  15209. Keyword arguments:
  15210. out (Tensor, optional): the output tensor.
  15211. dtype (torch.dtype, optional): the data type to perform the computation in.
  15212. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15213. when both :attr:`start` and :attr:`end` are real,
  15214. and corresponding complex dtype when either is complex.
  15215. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15216. Default: ``torch.strided``.
  15217. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15218. Default: if ``None``, uses the current device for the default tensor type
  15219. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15220. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15221. requires_grad (bool, optional): If autograd should record operations on the
  15222. returned tensor. Default: ``False``.
  15223. Example::
  15224. >>> torch.linspace(3, 10, steps=5)
  15225. tensor([ 3.0000, 4.7500, 6.5000, 8.2500, 10.0000])
  15226. >>> torch.linspace(-10, 10, steps=5)
  15227. tensor([-10., -5., 0., 5., 10.])
  15228. >>> torch.linspace(start=-10, end=10, steps=5)
  15229. tensor([-10., -5., 0., 5., 10.])
  15230. >>> torch.linspace(start=-10, end=10, steps=1)
  15231. tensor([-10.])
  15232. """
  15233. @overload
  15234. def linspace(
  15235. start: Tensor,
  15236. end: Number | _complex,
  15237. steps: _int,
  15238. *,
  15239. out: Tensor | None = None,
  15240. dtype: _dtype | None = None,
  15241. layout: _layout | None = None,
  15242. device: DeviceLikeType | None = None,
  15243. pin_memory: _bool | None = False,
  15244. requires_grad: _bool | None = False,
  15245. ) -> Tensor:
  15246. r"""
  15247. linspace(start, end, steps, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15248. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15249. spaced from :attr:`start` to :attr:`end`, inclusive. That is, the value are:
  15250. .. math::
  15251. (\text{start},
  15252. \text{start} + \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15253. \ldots,
  15254. \text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15255. \text{end})
  15256. From PyTorch 1.11 linspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15257. Args:
  15258. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15259. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15260. steps (int): size of the constructed tensor
  15261. Keyword arguments:
  15262. out (Tensor, optional): the output tensor.
  15263. dtype (torch.dtype, optional): the data type to perform the computation in.
  15264. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15265. when both :attr:`start` and :attr:`end` are real,
  15266. and corresponding complex dtype when either is complex.
  15267. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15268. Default: ``torch.strided``.
  15269. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15270. Default: if ``None``, uses the current device for the default tensor type
  15271. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15272. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15273. requires_grad (bool, optional): If autograd should record operations on the
  15274. returned tensor. Default: ``False``.
  15275. Example::
  15276. >>> torch.linspace(3, 10, steps=5)
  15277. tensor([ 3.0000, 4.7500, 6.5000, 8.2500, 10.0000])
  15278. >>> torch.linspace(-10, 10, steps=5)
  15279. tensor([-10., -5., 0., 5., 10.])
  15280. >>> torch.linspace(start=-10, end=10, steps=5)
  15281. tensor([-10., -5., 0., 5., 10.])
  15282. >>> torch.linspace(start=-10, end=10, steps=1)
  15283. tensor([-10.])
  15284. """
  15285. @overload
  15286. def linspace(
  15287. start: Number | _complex,
  15288. end: Number | _complex,
  15289. steps: _int,
  15290. *,
  15291. out: Tensor | None = None,
  15292. dtype: _dtype | None = None,
  15293. layout: _layout | None = None,
  15294. device: DeviceLikeType | None = None,
  15295. pin_memory: _bool | None = False,
  15296. requires_grad: _bool | None = False,
  15297. ) -> Tensor:
  15298. r"""
  15299. linspace(start, end, steps, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15300. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15301. spaced from :attr:`start` to :attr:`end`, inclusive. That is, the value are:
  15302. .. math::
  15303. (\text{start},
  15304. \text{start} + \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15305. \ldots,
  15306. \text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{\text{steps} - 1},
  15307. \text{end})
  15308. From PyTorch 1.11 linspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15309. Args:
  15310. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15311. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15312. steps (int): size of the constructed tensor
  15313. Keyword arguments:
  15314. out (Tensor, optional): the output tensor.
  15315. dtype (torch.dtype, optional): the data type to perform the computation in.
  15316. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15317. when both :attr:`start` and :attr:`end` are real,
  15318. and corresponding complex dtype when either is complex.
  15319. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15320. Default: ``torch.strided``.
  15321. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15322. Default: if ``None``, uses the current device for the default tensor type
  15323. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15324. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15325. requires_grad (bool, optional): If autograd should record operations on the
  15326. returned tensor. Default: ``False``.
  15327. Example::
  15328. >>> torch.linspace(3, 10, steps=5)
  15329. tensor([ 3.0000, 4.7500, 6.5000, 8.2500, 10.0000])
  15330. >>> torch.linspace(-10, 10, steps=5)
  15331. tensor([-10., -5., 0., 5., 10.])
  15332. >>> torch.linspace(start=-10, end=10, steps=5)
  15333. tensor([-10., -5., 0., 5., 10.])
  15334. >>> torch.linspace(start=-10, end=10, steps=1)
  15335. tensor([-10.])
  15336. """
  15337. def log(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  15338. r"""
  15339. log(input, *, out=None) -> Tensor
  15340. Returns a new tensor with the natural logarithm of the elements
  15341. of :attr:`input`.
  15342. .. math::
  15343. y_{i} = \log_{e} (x_{i})
  15344. Args:
  15345. input (Tensor): the input tensor.
  15346. Keyword args:
  15347. out (Tensor, optional): the output tensor.
  15348. Example::
  15349. >>> a = torch.rand(5) * 5
  15350. >>> a
  15351. tensor([4.7767, 4.3234, 1.2156, 0.2411, 4.5739])
  15352. >>> torch.log(a)
  15353. tensor([ 1.5637, 1.4640, 0.1952, -1.4226, 1.5204])
  15354. """
  15355. def log10(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  15356. r"""
  15357. log10(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  15358. Returns a new tensor with the logarithm to the base 10 of the elements
  15359. of :attr:`input`.
  15360. .. math::
  15361. y_{i} = \log_{10} (x_{i})
  15362. Args:
  15363. input (Tensor): the input tensor.
  15364. Keyword args:
  15365. out (Tensor, optional): the output tensor.
  15366. Example::
  15367. >>> a = torch.rand(5)
  15368. >>> a
  15369. tensor([ 0.5224, 0.9354, 0.7257, 0.1301, 0.2251])
  15370. >>> torch.log10(a)
  15371. tensor([-0.2820, -0.0290, -0.1392, -0.8857, -0.6476])
  15372. """
  15373. def log10_(input: Tensor) -> Tensor: ...
  15374. def log1p(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  15375. r"""
  15376. log1p(input, *, out=None) -> Tensor
  15377. Returns a new tensor with the natural logarithm of (1 + :attr:`input`).
  15378. .. math::
  15379. y_i = \log_{e} (x_i + 1)
  15380. .. note:: This function is more accurate than :func:`torch.log` for small
  15381. values of :attr:`input`
  15382. Args:
  15383. input (Tensor): the input tensor.
  15384. Keyword args:
  15385. out (Tensor, optional): the output tensor.
  15386. Example::
  15387. >>> a = torch.randn(5)
  15388. >>> a
  15389. tensor([-1.0090, -0.9923, 1.0249, -0.5372, 0.2492])
  15390. >>> torch.log1p(a)
  15391. tensor([ nan, -4.8653, 0.7055, -0.7705, 0.2225])
  15392. """
  15393. def log1p_(input: Tensor) -> Tensor: ...
  15394. def log2(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  15395. r"""
  15396. log2(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  15397. Returns a new tensor with the logarithm to the base 2 of the elements
  15398. of :attr:`input`.
  15399. .. math::
  15400. y_{i} = \log_{2} (x_{i})
  15401. Args:
  15402. input (Tensor): the input tensor.
  15403. Keyword args:
  15404. out (Tensor, optional): the output tensor.
  15405. Example::
  15406. >>> a = torch.rand(5)
  15407. >>> a
  15408. tensor([ 0.8419, 0.8003, 0.9971, 0.5287, 0.0490])
  15409. >>> torch.log2(a)
  15410. tensor([-0.2483, -0.3213, -0.0042, -0.9196, -4.3504])
  15411. """
  15412. def log2_(input: Tensor) -> Tensor: ...
  15413. def log_(input: Tensor) -> Tensor: ...
  15414. @overload
  15415. def log_softmax(
  15416. input: Tensor,
  15417. dim: _int,
  15418. dtype: _dtype | None = None,
  15419. *,
  15420. out: Tensor | None = None,
  15421. ) -> Tensor: ...
  15422. @overload
  15423. def log_softmax(
  15424. input: Tensor,
  15425. dim: str | EllipsisType | None,
  15426. *,
  15427. dtype: _dtype | None = None,
  15428. ) -> Tensor: ...
  15429. def logaddexp(
  15430. input: Tensor,
  15431. other: Tensor,
  15432. *,
  15433. out: Tensor | None = None,
  15434. ) -> Tensor:
  15435. r"""
  15436. logaddexp(input, other, *, out=None) -> Tensor
  15437. Logarithm of the sum of exponentiations of the inputs.
  15438. Calculates pointwise :math:`\log\left(e^x + e^y\right)`. This function is useful
  15439. in statistics where the calculated probabilities of events may be so small as to
  15440. exceed the range of normal floating point numbers. In such cases the logarithm
  15441. of the calculated probability is stored. This function allows adding
  15442. probabilities stored in such a fashion.
  15443. This op should be disambiguated with :func:`torch.logsumexp` which performs a
  15444. reduction on a single tensor.
  15445. Args:
  15446. input (Tensor): the input tensor.
  15447. other (Tensor): the second input tensor
  15448. Keyword arguments:
  15449. out (Tensor, optional): the output tensor.
  15450. Example::
  15451. >>> torch.logaddexp(torch.tensor([-1.0]), torch.tensor([-1.0, -2, -3]))
  15452. tensor([-0.3069, -0.6867, -0.8731])
  15453. >>> torch.logaddexp(torch.tensor([-100.0, -200, -300]), torch.tensor([-1.0, -2, -3]))
  15454. tensor([-1., -2., -3.])
  15455. >>> torch.logaddexp(torch.tensor([1.0, 2000, 30000]), torch.tensor([-1.0, -2, -3]))
  15456. tensor([1.1269e+00, 2.0000e+03, 3.0000e+04])
  15457. """
  15458. def logaddexp2(
  15459. input: Tensor,
  15460. other: Tensor,
  15461. *,
  15462. out: Tensor | None = None,
  15463. ) -> Tensor:
  15464. r"""
  15465. logaddexp2(input, other, *, out=None) -> Tensor
  15466. Logarithm of the sum of exponentiations of the inputs in base-2.
  15467. Calculates pointwise :math:`\log_2\left(2^x + 2^y\right)`. See
  15468. :func:`torch.logaddexp` for more details.
  15469. Args:
  15470. input (Tensor): the input tensor.
  15471. other (Tensor): the second input tensor
  15472. Keyword arguments:
  15473. out (Tensor, optional): the output tensor.
  15474. """
  15475. @overload
  15476. def logcumsumexp(
  15477. input: Tensor,
  15478. dim: _int,
  15479. *,
  15480. out: Tensor | None = None,
  15481. ) -> Tensor:
  15482. r"""
  15483. logcumsumexp(input, dim, *, out=None) -> Tensor
  15484. Returns the logarithm of the cumulative summation of the exponentiation of
  15485. elements of :attr:`input` in the dimension :attr:`dim`.
  15486. For summation index :math:`j` given by `dim` and other indices :math:`i`, the result is
  15487. .. math::
  15488. \text{logcumsumexp}(x)_{ij} = \log \sum\limits_{k=0}^{j} \exp(x_{ik})
  15489. Args:
  15490. input (Tensor): the input tensor.
  15491. dim (int): the dimension to do the operation over
  15492. Keyword args:
  15493. out (Tensor, optional): the output tensor.
  15494. Example::
  15495. >>> a = torch.randn(10)
  15496. >>> torch.logcumsumexp(a, dim=0)
  15497. tensor([-0.42296738, -0.04462666, 0.86278635, 0.94622083, 1.05277811,
  15498. 1.39202815, 1.83525007, 1.84492621, 2.06084887, 2.06844475]))
  15499. """
  15500. @overload
  15501. def logcumsumexp(
  15502. input: Tensor,
  15503. dim: str | EllipsisType | None,
  15504. *,
  15505. out: Tensor | None = None,
  15506. ) -> Tensor:
  15507. r"""
  15508. logcumsumexp(input, dim, *, out=None) -> Tensor
  15509. Returns the logarithm of the cumulative summation of the exponentiation of
  15510. elements of :attr:`input` in the dimension :attr:`dim`.
  15511. For summation index :math:`j` given by `dim` and other indices :math:`i`, the result is
  15512. .. math::
  15513. \text{logcumsumexp}(x)_{ij} = \log \sum\limits_{k=0}^{j} \exp(x_{ik})
  15514. Args:
  15515. input (Tensor): the input tensor.
  15516. dim (int): the dimension to do the operation over
  15517. Keyword args:
  15518. out (Tensor, optional): the output tensor.
  15519. Example::
  15520. >>> a = torch.randn(10)
  15521. >>> torch.logcumsumexp(a, dim=0)
  15522. tensor([-0.42296738, -0.04462666, 0.86278635, 0.94622083, 1.05277811,
  15523. 1.39202815, 1.83525007, 1.84492621, 2.06084887, 2.06844475]))
  15524. """
  15525. def logdet(input: Tensor) -> Tensor:
  15526. r"""
  15527. logdet(input) -> Tensor
  15528. Calculates log determinant of a square matrix or batches of square matrices.
  15529. It returns ``-inf`` if the input has a determinant of zero, and ``NaN`` if it has
  15530. a negative determinant.
  15531. .. note::
  15532. Backward through :meth:`logdet` internally uses SVD results when :attr:`input`
  15533. is not invertible. In this case, double backward through :meth:`logdet` will
  15534. be unstable in when :attr:`input` doesn't have distinct singular values. See
  15535. :func:`torch.linalg.svd` for details.
  15536. .. seealso::
  15537. :func:`torch.linalg.slogdet` computes the sign (resp. angle) and natural logarithm of the
  15538. absolute value of the determinant of real-valued (resp. complex) square matrices.
  15539. Arguments:
  15540. input (Tensor): the input tensor of size ``(*, n, n)`` where ``*`` is zero or more
  15541. batch dimensions.
  15542. Example::
  15543. >>> A = torch.randn(3, 3)
  15544. >>> torch.det(A)
  15545. tensor(0.2611)
  15546. >>> torch.logdet(A)
  15547. tensor(-1.3430)
  15548. >>> A
  15549. tensor([[[ 0.9254, -0.6213],
  15550. [-0.5787, 1.6843]],
  15551. [[ 0.3242, -0.9665],
  15552. [ 0.4539, -0.0887]],
  15553. [[ 1.1336, -0.4025],
  15554. [-0.7089, 0.9032]]])
  15555. >>> A.det()
  15556. tensor([1.1990, 0.4099, 0.7386])
  15557. >>> A.det().log()
  15558. tensor([ 0.1815, -0.8917, -0.3031])
  15559. """
  15560. def logical_and(
  15561. input: Tensor,
  15562. other: Tensor,
  15563. *,
  15564. out: Tensor | None = None,
  15565. ) -> Tensor:
  15566. r"""
  15567. logical_and(input, other, *, out=None) -> Tensor
  15568. Computes the element-wise logical AND of the given input tensors. Zeros are treated as ``False`` and nonzeros are
  15569. treated as ``True``.
  15570. Args:
  15571. input (Tensor): the input tensor.
  15572. other (Tensor): the tensor to compute AND with
  15573. Keyword args:
  15574. out (Tensor, optional): the output tensor.
  15575. Example::
  15576. >>> torch.logical_and(torch.tensor([True, False, True]), torch.tensor([True, False, False]))
  15577. tensor([ True, False, False])
  15578. >>> a = torch.tensor([0, 1, 10, 0], dtype=torch.int8)
  15579. >>> b = torch.tensor([4, 0, 1, 0], dtype=torch.int8)
  15580. >>> torch.logical_and(a, b)
  15581. tensor([False, False, True, False])
  15582. >>> torch.logical_and(a.double(), b.double())
  15583. tensor([False, False, True, False])
  15584. >>> torch.logical_and(a.double(), b)
  15585. tensor([False, False, True, False])
  15586. >>> torch.logical_and(a, b, out=torch.empty(4, dtype=torch.bool))
  15587. tensor([False, False, True, False])
  15588. """
  15589. def logical_not(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  15590. r"""
  15591. logical_not(input, *, out=None) -> Tensor
  15592. Computes the element-wise logical NOT of the given input tensor. If not specified, the output tensor will have the bool
  15593. dtype. If the input tensor is not a bool tensor, zeros are treated as ``False`` and non-zeros are treated as ``True``.
  15594. Args:
  15595. input (Tensor): the input tensor.
  15596. Keyword args:
  15597. out (Tensor, optional): the output tensor.
  15598. Example::
  15599. >>> torch.logical_not(torch.tensor([True, False]))
  15600. tensor([False, True])
  15601. >>> torch.logical_not(torch.tensor([0, 1, -10], dtype=torch.int8))
  15602. tensor([ True, False, False])
  15603. >>> torch.logical_not(torch.tensor([0., 1.5, -10.], dtype=torch.double))
  15604. tensor([ True, False, False])
  15605. >>> torch.logical_not(torch.tensor([0., 1., -10.], dtype=torch.double), out=torch.empty(3, dtype=torch.int16))
  15606. tensor([1, 0, 0], dtype=torch.int16)
  15607. """
  15608. def logical_or(
  15609. input: Tensor,
  15610. other: Tensor,
  15611. *,
  15612. out: Tensor | None = None,
  15613. ) -> Tensor:
  15614. r"""
  15615. logical_or(input, other, *, out=None) -> Tensor
  15616. Computes the element-wise logical OR of the given input tensors. Zeros are treated as ``False`` and nonzeros are
  15617. treated as ``True``.
  15618. Args:
  15619. input (Tensor): the input tensor.
  15620. other (Tensor): the tensor to compute OR with
  15621. Keyword args:
  15622. out (Tensor, optional): the output tensor.
  15623. Example::
  15624. >>> torch.logical_or(torch.tensor([True, False, True]), torch.tensor([True, False, False]))
  15625. tensor([ True, False, True])
  15626. >>> a = torch.tensor([0, 1, 10, 0], dtype=torch.int8)
  15627. >>> b = torch.tensor([4, 0, 1, 0], dtype=torch.int8)
  15628. >>> torch.logical_or(a, b)
  15629. tensor([ True, True, True, False])
  15630. >>> torch.logical_or(a.double(), b.double())
  15631. tensor([ True, True, True, False])
  15632. >>> torch.logical_or(a.double(), b)
  15633. tensor([ True, True, True, False])
  15634. >>> torch.logical_or(a, b, out=torch.empty(4, dtype=torch.bool))
  15635. tensor([ True, True, True, False])
  15636. """
  15637. def logical_xor(
  15638. input: Tensor,
  15639. other: Tensor,
  15640. *,
  15641. out: Tensor | None = None,
  15642. ) -> Tensor:
  15643. r"""
  15644. logical_xor(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
  15645. Computes the element-wise logical XOR of the given input tensors. Zeros are treated as ``False`` and nonzeros are
  15646. treated as ``True``.
  15647. Args:
  15648. input (Tensor): the input tensor.
  15649. other (Tensor): the tensor to compute XOR with
  15650. Keyword args:
  15651. out (Tensor, optional): the output tensor.
  15652. Example::
  15653. >>> torch.logical_xor(torch.tensor([True, False, True]), torch.tensor([True, False, False]))
  15654. tensor([False, False, True])
  15655. >>> a = torch.tensor([0, 1, 10, 0], dtype=torch.int8)
  15656. >>> b = torch.tensor([4, 0, 1, 0], dtype=torch.int8)
  15657. >>> torch.logical_xor(a, b)
  15658. tensor([ True, True, False, False])
  15659. >>> torch.logical_xor(a.double(), b.double())
  15660. tensor([ True, True, False, False])
  15661. >>> torch.logical_xor(a.double(), b)
  15662. tensor([ True, True, False, False])
  15663. >>> torch.logical_xor(a, b, out=torch.empty(4, dtype=torch.bool))
  15664. tensor([ True, True, False, False])
  15665. """
  15666. def logit(
  15667. input: Tensor,
  15668. eps: _float | None = None,
  15669. *,
  15670. out: Tensor | None = None,
  15671. ) -> Tensor:
  15672. r"""
  15673. logit(input, eps=None, *, out=None) -> Tensor
  15674. Alias for :func:`torch.special.logit`.
  15675. """
  15676. def logit_(input: Tensor, eps: _float | None = None) -> Tensor: ...
  15677. @overload
  15678. def logspace(
  15679. start: Number,
  15680. end: Number,
  15681. steps: _int | None = None,
  15682. base: _float = 10.0,
  15683. *,
  15684. out: Tensor | None = None,
  15685. dtype: _dtype | None = None,
  15686. device: DeviceLikeType | None = None,
  15687. requires_grad: _bool = False,
  15688. pin_memory: _bool = False,
  15689. ) -> Tensor:
  15690. r"""
  15691. logspace(start, end, steps, base=10.0, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15692. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15693. spaced from :math:`{{\text{{base}}}}^{{\text{{start}}}}` to
  15694. :math:`{{\text{{base}}}}^{{\text{{end}}}}`, inclusive, on a logarithmic scale
  15695. with base :attr:`base`. That is, the values are:
  15696. .. math::
  15697. (\text{base}^{\text{start}},
  15698. \text{base}^{(\text{start} + \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15699. \ldots,
  15700. \text{base}^{(\text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15701. \text{base}^{\text{end}})
  15702. From PyTorch 1.11 logspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15703. Args:
  15704. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15705. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15706. steps (int): size of the constructed tensor
  15707. base (float, optional): base of the logarithm function. Default: ``10.0``.
  15708. Keyword arguments:
  15709. out (Tensor, optional): the output tensor.
  15710. dtype (torch.dtype, optional): the data type to perform the computation in.
  15711. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15712. when both :attr:`start` and :attr:`end` are real,
  15713. and corresponding complex dtype when either is complex.
  15714. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15715. Default: ``torch.strided``.
  15716. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15717. Default: if ``None``, uses the current device for the default tensor type
  15718. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15719. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15720. requires_grad (bool, optional): If autograd should record operations on the
  15721. returned tensor. Default: ``False``.
  15722. Example::
  15723. >>> torch.logspace(start=-10, end=10, steps=5)
  15724. tensor([ 1.0000e-10, 1.0000e-05, 1.0000e+00, 1.0000e+05, 1.0000e+10])
  15725. >>> torch.logspace(start=0.1, end=1.0, steps=5)
  15726. tensor([ 1.2589, 2.1135, 3.5481, 5.9566, 10.0000])
  15727. >>> torch.logspace(start=0.1, end=1.0, steps=1)
  15728. tensor([1.2589])
  15729. >>> torch.logspace(start=2, end=2, steps=1, base=2)
  15730. tensor([4.0])
  15731. """
  15732. @overload
  15733. def logspace(
  15734. start: Tensor,
  15735. end: Tensor,
  15736. steps: _int,
  15737. base: _float = 10.0,
  15738. *,
  15739. out: Tensor | None = None,
  15740. dtype: _dtype | None = None,
  15741. layout: _layout | None = None,
  15742. device: DeviceLikeType | None = None,
  15743. pin_memory: _bool | None = False,
  15744. requires_grad: _bool | None = False,
  15745. ) -> Tensor:
  15746. r"""
  15747. logspace(start, end, steps, base=10.0, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15748. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15749. spaced from :math:`{{\text{{base}}}}^{{\text{{start}}}}` to
  15750. :math:`{{\text{{base}}}}^{{\text{{end}}}}`, inclusive, on a logarithmic scale
  15751. with base :attr:`base`. That is, the values are:
  15752. .. math::
  15753. (\text{base}^{\text{start}},
  15754. \text{base}^{(\text{start} + \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15755. \ldots,
  15756. \text{base}^{(\text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15757. \text{base}^{\text{end}})
  15758. From PyTorch 1.11 logspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15759. Args:
  15760. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15761. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15762. steps (int): size of the constructed tensor
  15763. base (float, optional): base of the logarithm function. Default: ``10.0``.
  15764. Keyword arguments:
  15765. out (Tensor, optional): the output tensor.
  15766. dtype (torch.dtype, optional): the data type to perform the computation in.
  15767. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15768. when both :attr:`start` and :attr:`end` are real,
  15769. and corresponding complex dtype when either is complex.
  15770. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15771. Default: ``torch.strided``.
  15772. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15773. Default: if ``None``, uses the current device for the default tensor type
  15774. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15775. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15776. requires_grad (bool, optional): If autograd should record operations on the
  15777. returned tensor. Default: ``False``.
  15778. Example::
  15779. >>> torch.logspace(start=-10, end=10, steps=5)
  15780. tensor([ 1.0000e-10, 1.0000e-05, 1.0000e+00, 1.0000e+05, 1.0000e+10])
  15781. >>> torch.logspace(start=0.1, end=1.0, steps=5)
  15782. tensor([ 1.2589, 2.1135, 3.5481, 5.9566, 10.0000])
  15783. >>> torch.logspace(start=0.1, end=1.0, steps=1)
  15784. tensor([1.2589])
  15785. >>> torch.logspace(start=2, end=2, steps=1, base=2)
  15786. tensor([4.0])
  15787. """
  15788. @overload
  15789. def logspace(
  15790. start: Number | _complex,
  15791. end: Tensor,
  15792. steps: _int,
  15793. base: _float = 10.0,
  15794. *,
  15795. out: Tensor | None = None,
  15796. dtype: _dtype | None = None,
  15797. layout: _layout | None = None,
  15798. device: DeviceLikeType | None = None,
  15799. pin_memory: _bool | None = False,
  15800. requires_grad: _bool | None = False,
  15801. ) -> Tensor:
  15802. r"""
  15803. logspace(start, end, steps, base=10.0, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15804. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15805. spaced from :math:`{{\text{{base}}}}^{{\text{{start}}}}` to
  15806. :math:`{{\text{{base}}}}^{{\text{{end}}}}`, inclusive, on a logarithmic scale
  15807. with base :attr:`base`. That is, the values are:
  15808. .. math::
  15809. (\text{base}^{\text{start}},
  15810. \text{base}^{(\text{start} + \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15811. \ldots,
  15812. \text{base}^{(\text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15813. \text{base}^{\text{end}})
  15814. From PyTorch 1.11 logspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15815. Args:
  15816. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15817. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15818. steps (int): size of the constructed tensor
  15819. base (float, optional): base of the logarithm function. Default: ``10.0``.
  15820. Keyword arguments:
  15821. out (Tensor, optional): the output tensor.
  15822. dtype (torch.dtype, optional): the data type to perform the computation in.
  15823. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15824. when both :attr:`start` and :attr:`end` are real,
  15825. and corresponding complex dtype when either is complex.
  15826. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15827. Default: ``torch.strided``.
  15828. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15829. Default: if ``None``, uses the current device for the default tensor type
  15830. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15831. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15832. requires_grad (bool, optional): If autograd should record operations on the
  15833. returned tensor. Default: ``False``.
  15834. Example::
  15835. >>> torch.logspace(start=-10, end=10, steps=5)
  15836. tensor([ 1.0000e-10, 1.0000e-05, 1.0000e+00, 1.0000e+05, 1.0000e+10])
  15837. >>> torch.logspace(start=0.1, end=1.0, steps=5)
  15838. tensor([ 1.2589, 2.1135, 3.5481, 5.9566, 10.0000])
  15839. >>> torch.logspace(start=0.1, end=1.0, steps=1)
  15840. tensor([1.2589])
  15841. >>> torch.logspace(start=2, end=2, steps=1, base=2)
  15842. tensor([4.0])
  15843. """
  15844. @overload
  15845. def logspace(
  15846. start: Tensor,
  15847. end: Number | _complex,
  15848. steps: _int,
  15849. base: _float = 10.0,
  15850. *,
  15851. out: Tensor | None = None,
  15852. dtype: _dtype | None = None,
  15853. layout: _layout | None = None,
  15854. device: DeviceLikeType | None = None,
  15855. pin_memory: _bool | None = False,
  15856. requires_grad: _bool | None = False,
  15857. ) -> Tensor:
  15858. r"""
  15859. logspace(start, end, steps, base=10.0, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15860. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15861. spaced from :math:`{{\text{{base}}}}^{{\text{{start}}}}` to
  15862. :math:`{{\text{{base}}}}^{{\text{{end}}}}`, inclusive, on a logarithmic scale
  15863. with base :attr:`base`. That is, the values are:
  15864. .. math::
  15865. (\text{base}^{\text{start}},
  15866. \text{base}^{(\text{start} + \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15867. \ldots,
  15868. \text{base}^{(\text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15869. \text{base}^{\text{end}})
  15870. From PyTorch 1.11 logspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15871. Args:
  15872. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15873. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15874. steps (int): size of the constructed tensor
  15875. base (float, optional): base of the logarithm function. Default: ``10.0``.
  15876. Keyword arguments:
  15877. out (Tensor, optional): the output tensor.
  15878. dtype (torch.dtype, optional): the data type to perform the computation in.
  15879. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15880. when both :attr:`start` and :attr:`end` are real,
  15881. and corresponding complex dtype when either is complex.
  15882. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15883. Default: ``torch.strided``.
  15884. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15885. Default: if ``None``, uses the current device for the default tensor type
  15886. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15887. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15888. requires_grad (bool, optional): If autograd should record operations on the
  15889. returned tensor. Default: ``False``.
  15890. Example::
  15891. >>> torch.logspace(start=-10, end=10, steps=5)
  15892. tensor([ 1.0000e-10, 1.0000e-05, 1.0000e+00, 1.0000e+05, 1.0000e+10])
  15893. >>> torch.logspace(start=0.1, end=1.0, steps=5)
  15894. tensor([ 1.2589, 2.1135, 3.5481, 5.9566, 10.0000])
  15895. >>> torch.logspace(start=0.1, end=1.0, steps=1)
  15896. tensor([1.2589])
  15897. >>> torch.logspace(start=2, end=2, steps=1, base=2)
  15898. tensor([4.0])
  15899. """
  15900. @overload
  15901. def logspace(
  15902. start: Number | _complex,
  15903. end: Number | _complex,
  15904. steps: _int,
  15905. base: _float = 10.0,
  15906. *,
  15907. out: Tensor | None = None,
  15908. dtype: _dtype | None = None,
  15909. layout: _layout | None = None,
  15910. device: DeviceLikeType | None = None,
  15911. pin_memory: _bool | None = False,
  15912. requires_grad: _bool | None = False,
  15913. ) -> Tensor:
  15914. r"""
  15915. logspace(start, end, steps, base=10.0, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  15916. Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
  15917. spaced from :math:`{{\text{{base}}}}^{{\text{{start}}}}` to
  15918. :math:`{{\text{{base}}}}^{{\text{{end}}}}`, inclusive, on a logarithmic scale
  15919. with base :attr:`base`. That is, the values are:
  15920. .. math::
  15921. (\text{base}^{\text{start}},
  15922. \text{base}^{(\text{start} + \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15923. \ldots,
  15924. \text{base}^{(\text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
  15925. \text{base}^{\text{end}})
  15926. From PyTorch 1.11 logspace requires the steps argument. Use steps=100 to restore the previous behavior.
  15927. Args:
  15928. start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
  15929. end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
  15930. steps (int): size of the constructed tensor
  15931. base (float, optional): base of the logarithm function. Default: ``10.0``.
  15932. Keyword arguments:
  15933. out (Tensor, optional): the output tensor.
  15934. dtype (torch.dtype, optional): the data type to perform the computation in.
  15935. Default: if None, uses the global default dtype (see torch.get_default_dtype())
  15936. when both :attr:`start` and :attr:`end` are real,
  15937. and corresponding complex dtype when either is complex.
  15938. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  15939. Default: ``torch.strided``.
  15940. device (:class:`torch.device`, optional): the desired device of returned tensor.
  15941. Default: if ``None``, uses the current device for the default tensor type
  15942. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  15943. for CPU tensor types and the current CUDA device for CUDA tensor types.
  15944. requires_grad (bool, optional): If autograd should record operations on the
  15945. returned tensor. Default: ``False``.
  15946. Example::
  15947. >>> torch.logspace(start=-10, end=10, steps=5)
  15948. tensor([ 1.0000e-10, 1.0000e-05, 1.0000e+00, 1.0000e+05, 1.0000e+10])
  15949. >>> torch.logspace(start=0.1, end=1.0, steps=5)
  15950. tensor([ 1.2589, 2.1135, 3.5481, 5.9566, 10.0000])
  15951. >>> torch.logspace(start=0.1, end=1.0, steps=1)
  15952. tensor([1.2589])
  15953. >>> torch.logspace(start=2, end=2, steps=1, base=2)
  15954. tensor([4.0])
  15955. """
  15956. @overload
  15957. def logsumexp(
  15958. input: Tensor,
  15959. dim: _int | _size,
  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 logsumexp(
  15991. input: Tensor,
  15992. dim: Sequence[str | EllipsisType | None],
  15993. keepdim: _bool = False,
  15994. *,
  15995. out: Tensor | None = None,
  15996. ) -> Tensor:
  15997. r"""
  15998. logsumexp(input, dim, keepdim=False, *, out=None)
  15999. Returns the log of summed exponentials of each row of the :attr:`input`
  16000. tensor in the given dimension :attr:`dim`. The computation is numerically
  16001. stabilized.
  16002. For summation index :math:`j` given by `dim` and other indices :math:`i`, the result is
  16003. .. math::
  16004. \text{logsumexp}(x)_{i} = \log \sum_j \exp(x_{ij})
  16005. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  16006. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  16007. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  16008. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  16009. Args:
  16010. input (Tensor): the input tensor.
  16011. dim (int or tuple of ints): the dimension or dimensions to reduce.
  16012. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16013. Keyword args:
  16014. out (Tensor, optional): the output tensor.
  16015. Example::
  16016. >>> a = torch.randn(3, 3)
  16017. >>> torch.logsumexp(a, 1)
  16018. tensor([1.4907, 1.0593, 1.5696])
  16019. >>> torch.dist(torch.logsumexp(a, 1), torch.log(torch.sum(torch.exp(a), 1)))
  16020. tensor(1.6859e-07)
  16021. """
  16022. @overload
  16023. def lstm(
  16024. data: Tensor,
  16025. batch_sizes: Tensor,
  16026. hx: tuple[Tensor, ...] | list[Tensor] | None,
  16027. params: tuple[Tensor, ...] | list[Tensor] | None,
  16028. has_biases: _bool,
  16029. num_layers: _int,
  16030. dropout: _float,
  16031. train: _bool,
  16032. bidirectional: _bool,
  16033. ) -> tuple[Tensor, Tensor, Tensor]: ...
  16034. @overload
  16035. def lstm(
  16036. input: Tensor,
  16037. hx: tuple[Tensor, ...] | list[Tensor] | None,
  16038. params: tuple[Tensor, ...] | list[Tensor] | None,
  16039. has_biases: _bool,
  16040. num_layers: _int,
  16041. dropout: _float,
  16042. train: _bool,
  16043. bidirectional: _bool,
  16044. batch_first: _bool,
  16045. ) -> tuple[Tensor, Tensor, Tensor]: ...
  16046. def lstm_cell(
  16047. input: Tensor,
  16048. hx: tuple[Tensor, ...] | list[Tensor] | None,
  16049. w_ih: Tensor,
  16050. w_hh: Tensor,
  16051. b_ih: Tensor | None = None,
  16052. b_hh: Tensor | None = None,
  16053. ) -> tuple[Tensor, Tensor]: ...
  16054. @overload
  16055. def lt(
  16056. input: Tensor,
  16057. other: Tensor,
  16058. *,
  16059. out: Tensor | None = None,
  16060. ) -> Tensor:
  16061. r"""
  16062. lt(input, other, *, out=None) -> Tensor
  16063. Computes :math:`\text{input} < \text{other}` element-wise.
  16064. The second argument can be a number or a tensor whose shape is
  16065. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  16066. Args:
  16067. input (Tensor): the tensor to compare
  16068. other (Tensor or float): the tensor or value to compare
  16069. Keyword args:
  16070. out (Tensor, optional): the output tensor.
  16071. Returns:
  16072. A boolean tensor that is True where :attr:`input` is less than :attr:`other` and False elsewhere
  16073. Example::
  16074. >>> torch.lt(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  16075. tensor([[False, False], [True, False]])
  16076. """
  16077. @overload
  16078. def lt(
  16079. input: Tensor,
  16080. other: Number | _complex,
  16081. *,
  16082. out: Tensor | None = None,
  16083. ) -> Tensor:
  16084. r"""
  16085. lt(input, other, *, out=None) -> Tensor
  16086. Computes :math:`\text{input} < \text{other}` element-wise.
  16087. The second argument can be a number or a tensor whose shape is
  16088. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  16089. Args:
  16090. input (Tensor): the tensor to compare
  16091. other (Tensor or float): the tensor or value to compare
  16092. Keyword args:
  16093. out (Tensor, optional): the output tensor.
  16094. Returns:
  16095. A boolean tensor that is True where :attr:`input` is less than :attr:`other` and False elsewhere
  16096. Example::
  16097. >>> torch.lt(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  16098. tensor([[False, False], [True, False]])
  16099. """
  16100. def lu_solve(
  16101. input: Tensor,
  16102. LU_data: Tensor,
  16103. LU_pivots: Tensor,
  16104. *,
  16105. out: Tensor | None = None,
  16106. ) -> Tensor:
  16107. r"""
  16108. lu_solve(b, LU_data, LU_pivots, *, out=None) -> Tensor
  16109. Returns the LU solve of the linear system :math:`Ax = b` using the partially pivoted
  16110. LU factorization of A from :func:`~linalg.lu_factor`.
  16111. This function supports ``float``, ``double``, ``cfloat`` and ``cdouble`` dtypes for :attr:`input`.
  16112. .. warning::
  16113. :func:`torch.lu_solve` is deprecated in favor of :func:`torch.linalg.lu_solve`.
  16114. :func:`torch.lu_solve` will be removed in a future PyTorch release.
  16115. ``X = torch.lu_solve(B, LU, pivots)`` should be replaced with
  16116. .. code:: python
  16117. X = linalg.lu_solve(LU, pivots, B)
  16118. Arguments:
  16119. b (Tensor): the RHS tensor of size :math:`(*, m, k)`, where :math:`*`
  16120. is zero or more batch dimensions.
  16121. LU_data (Tensor): the pivoted LU factorization of A from :meth:`~linalg.lu_factor` of size :math:`(*, m, m)`,
  16122. where :math:`*` is zero or more batch dimensions.
  16123. LU_pivots (IntTensor): the pivots of the LU factorization from :meth:`~linalg.lu_factor` of size :math:`(*, m)`,
  16124. where :math:`*` is zero or more batch dimensions.
  16125. The batch dimensions of :attr:`LU_pivots` must be equal to the batch dimensions of
  16126. :attr:`LU_data`.
  16127. Keyword args:
  16128. out (Tensor, optional): the output tensor.
  16129. Example::
  16130. >>> A = torch.randn(2, 3, 3)
  16131. >>> b = torch.randn(2, 3, 1)
  16132. >>> LU, pivots = torch.linalg.lu_factor(A)
  16133. >>> x = torch.lu_solve(b, LU, pivots)
  16134. >>> torch.dist(A @ x, b)
  16135. tensor(1.00000e-07 *
  16136. 2.8312)
  16137. """
  16138. def lu_unpack(
  16139. LU_data: Tensor,
  16140. LU_pivots: Tensor,
  16141. unpack_data: _bool = True,
  16142. unpack_pivots: _bool = True,
  16143. *,
  16144. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  16145. ) -> torch.return_types.lu_unpack:
  16146. r"""
  16147. lu_unpack(LU_data, LU_pivots, unpack_data=True, unpack_pivots=True, *, out=None) -> (Tensor, Tensor, Tensor)
  16148. Unpacks the LU decomposition returned by :func:`~linalg.lu_factor` into the `P, L, U` matrices.
  16149. .. seealso::
  16150. :func:`~linalg.lu` returns the matrices from the LU decomposition. Its gradient formula is more efficient
  16151. than that of doing :func:`~linalg.lu_factor` followed by :func:`~linalg.lu_unpack`.
  16152. Args:
  16153. LU_data (Tensor): the packed LU factorization data
  16154. LU_pivots (Tensor): the packed LU factorization pivots
  16155. unpack_data (bool): flag indicating if the data should be unpacked.
  16156. If ``False``, then the returned ``L`` and ``U`` are empty tensors.
  16157. Default: ``True``
  16158. unpack_pivots (bool): flag indicating if the pivots should be unpacked into a permutation matrix ``P``.
  16159. If ``False``, then the returned ``P`` is an empty tensor.
  16160. Default: ``True``
  16161. Keyword args:
  16162. out (tuple, optional): output tuple of three tensors. Ignored if `None`.
  16163. Returns:
  16164. A namedtuple ``(P, L, U)``
  16165. Examples::
  16166. >>> A = torch.randn(2, 3, 3)
  16167. >>> LU, pivots = torch.linalg.lu_factor(A)
  16168. >>> P, L, U = torch.lu_unpack(LU, pivots)
  16169. >>> # We can recover A from the factorization
  16170. >>> A_ = P @ L @ U
  16171. >>> torch.allclose(A, A_)
  16172. True
  16173. >>> # LU factorization of a rectangular matrix:
  16174. >>> A = torch.randn(2, 3, 2)
  16175. >>> LU, pivots = torch.linalg.lu_factor(A)
  16176. >>> P, L, U = torch.lu_unpack(LU, pivots)
  16177. >>> # P, L, U are the same as returned by linalg.lu
  16178. >>> P_, L_, U_ = torch.linalg.lu(A)
  16179. >>> torch.allclose(P, P_) and torch.allclose(L, L_) and torch.allclose(U, U_)
  16180. True
  16181. """
  16182. def margin_ranking_loss(
  16183. input1: Tensor,
  16184. input2: Tensor,
  16185. target: Tensor,
  16186. margin: _float = 0.0,
  16187. reduction: _int = 1,
  16188. ) -> Tensor: ...
  16189. @overload
  16190. def masked_fill(input: Tensor, mask: Tensor, value: Tensor) -> Tensor: ...
  16191. @overload
  16192. def masked_fill(
  16193. input: Tensor,
  16194. mask: Tensor,
  16195. value: Number | _complex,
  16196. ) -> Tensor: ...
  16197. def masked_scatter(input: Tensor, mask: Tensor, source: Tensor) -> Tensor: ...
  16198. def masked_select(
  16199. input: Tensor,
  16200. mask: Tensor,
  16201. *,
  16202. out: Tensor | None = None,
  16203. ) -> Tensor:
  16204. r"""
  16205. masked_select(input, mask, *, out=None) -> Tensor
  16206. Returns a new 1-D tensor which indexes the :attr:`input` tensor according to
  16207. the boolean mask :attr:`mask` which is a `BoolTensor`.
  16208. The shapes of the :attr:`mask` tensor and the :attr:`input` tensor don't need
  16209. to match, but they must be :ref:`broadcastable <broadcasting-semantics>`.
  16210. .. note:: The returned tensor does **not** use the same storage
  16211. as the original tensor
  16212. Args:
  16213. input (Tensor): the input tensor.
  16214. mask (BoolTensor): the tensor containing the binary mask to index with
  16215. Keyword args:
  16216. out (Tensor, optional): the output tensor.
  16217. Example::
  16218. >>> x = torch.randn(3, 4)
  16219. >>> x
  16220. tensor([[ 0.3552, -2.3825, -0.8297, 0.3477],
  16221. [-1.2035, 1.2252, 0.5002, 0.6248],
  16222. [ 0.1307, -2.0608, 0.1244, 2.0139]])
  16223. >>> mask = x.ge(0.5)
  16224. >>> mask
  16225. tensor([[False, False, False, False],
  16226. [False, True, True, True],
  16227. [False, False, False, True]])
  16228. >>> torch.masked_select(x, mask)
  16229. tensor([ 1.2252, 0.5002, 0.6248, 2.0139])
  16230. """
  16231. def matmul(
  16232. input: Tensor,
  16233. other: Tensor,
  16234. *,
  16235. out: Tensor | None = None,
  16236. ) -> Tensor:
  16237. r"""
  16238. matmul(input, other, *, out=None) -> Tensor
  16239. Matrix product of two tensors.
  16240. The behavior depends on the dimensionality of the tensors as follows:
  16241. - If both tensors are 1-dimensional, the dot product (scalar) is returned.
  16242. - If both arguments are 2-dimensional, the matrix-matrix product is returned.
  16243. - If the first argument is 1-dimensional and the second argument is 2-dimensional,
  16244. a 1 is prepended to its dimension for the purpose of the matrix multiply.
  16245. After the matrix multiply, the prepended dimension is removed.
  16246. - If the first argument is 2-dimensional and the second argument is 1-dimensional,
  16247. the matrix-vector product is returned.
  16248. - If both arguments are at least 1-dimensional and at least one argument is
  16249. N-dimensional (where N > 2), then a batched matrix multiply is returned. If the first
  16250. argument is 1-dimensional, a 1 is prepended to its dimension for the purpose of the
  16251. batched matrix multiply and removed after. If the second argument is 1-dimensional, a
  16252. 1 is appended to its dimension for the purpose of the batched matrix multiply and removed after.
  16253. The first N-2 dimensions of each argument, the batch dimensions, are
  16254. :ref:`broadcast <broadcasting-semantics>` (and thus must be broadcastable).
  16255. The last 2, the matrix dimensions, are handled as in the matrix-matrix product.
  16256. For example, if :attr:`input` is a
  16257. :math:`(j \times 1 \times n \times m)` tensor and :attr:`other` is a :math:`(k \times m \times p)`
  16258. tensor, the batch dimensions are :math:`(j \times 1)` and :math:`(k)`,
  16259. and the matrix dimensions are :math:`(n \times m)` and :math:`(m \times p)`.
  16260. :attr:`out` will be a :math:`(j \times k \times n \times p)` tensor.
  16261. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`. In particular the
  16262. matrix-matrix (both arguments 2-dimensional) supports sparse arguments with the same restrictions
  16263. as :func:`torch.mm`
  16264. .. warning::
  16265. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  16266. or may not have autograd support. If you notice missing functionality please
  16267. open a feature request.
  16268. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  16269. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  16270. .. note::
  16271. The 1-dimensional dot product version of this function does not support an :attr:`out` parameter.
  16272. Arguments:
  16273. input (Tensor): the first tensor to be multiplied
  16274. other (Tensor): the second tensor to be multiplied
  16275. Keyword args:
  16276. out (Tensor, optional): the output tensor.
  16277. Example::
  16278. >>> # vector x vector
  16279. >>> tensor1 = torch.randn(3)
  16280. >>> tensor2 = torch.randn(3)
  16281. >>> torch.matmul(tensor1, tensor2).size()
  16282. torch.Size([])
  16283. >>> # matrix x vector
  16284. >>> tensor1 = torch.randn(3, 4)
  16285. >>> tensor2 = torch.randn(4)
  16286. >>> torch.matmul(tensor1, tensor2).size()
  16287. torch.Size([3])
  16288. >>> # batched matrix x broadcasted vector
  16289. >>> tensor1 = torch.randn(10, 3, 4)
  16290. >>> tensor2 = torch.randn(4)
  16291. >>> torch.matmul(tensor1, tensor2).size()
  16292. torch.Size([10, 3])
  16293. >>> # batched matrix x batched matrix
  16294. >>> tensor1 = torch.randn(10, 3, 4)
  16295. >>> tensor2 = torch.randn(10, 4, 5)
  16296. >>> torch.matmul(tensor1, tensor2).size()
  16297. torch.Size([10, 3, 5])
  16298. >>> # batched matrix x broadcasted matrix
  16299. >>> tensor1 = torch.randn(10, 3, 4)
  16300. >>> tensor2 = torch.randn(4, 5)
  16301. >>> torch.matmul(tensor1, tensor2).size()
  16302. torch.Size([10, 3, 5])
  16303. """
  16304. def matrix_exp(input: Tensor) -> Tensor:
  16305. r"""
  16306. matrix_exp(A) -> Tensor
  16307. Alias for :func:`torch.linalg.matrix_exp`.
  16308. """
  16309. def matrix_power(
  16310. input: Tensor,
  16311. n: _int,
  16312. *,
  16313. out: Tensor | None = None,
  16314. ) -> Tensor:
  16315. r"""
  16316. matrix_power(input, n, *, out=None) -> Tensor
  16317. Alias for :func:`torch.linalg.matrix_power`
  16318. """
  16319. @overload
  16320. def max(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  16321. r"""
  16322. max(input, *, out=None) -> Tensor
  16323. Returns the maximum value of all elements in the ``input`` tensor.
  16324. .. note::
  16325. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  16326. - ``amax``/``amin`` supports reducing on multiple dimensions,
  16327. - ``amax``/``amin`` does not return indices.
  16328. Both ``amax``/``amin`` evenly distribute gradients between equal values
  16329. when there are multiple input elements with the same minimum or maximum value.
  16330. For ``max``/``min``:
  16331. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  16332. - If reduce over one specified axis, only propagate to the indexed element.
  16333. Args:
  16334. input (Tensor): the input tensor.
  16335. Keyword args:
  16336. out (Tensor, optional): the output tensor.
  16337. Example::
  16338. >>> a = torch.randn(1, 3)
  16339. >>> a
  16340. tensor([[ 0.6763, 0.7445, -2.2369]])
  16341. >>> torch.max(a)
  16342. tensor(0.7445)
  16343. .. function:: max(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  16344. :noindex:
  16345. Returns a namedtuple ``(values, indices)`` where ``values`` is the maximum
  16346. value of each row of the :attr:`input` tensor in the given dimension
  16347. :attr:`dim`. And ``indices`` is the index location of each maximum value found
  16348. (argmax).
  16349. If ``keepdim`` is ``True``, the output tensors are of the same size
  16350. as ``input`` except in the dimension ``dim`` where they are of size 1.
  16351. Otherwise, ``dim`` is squeezed (see :func:`torch.squeeze`), resulting
  16352. in the output tensors having 1 fewer dimension than ``input``.
  16353. .. note:: If there are multiple maximal values in a reduced row then
  16354. the indices of the first maximal value are returned.
  16355. Args:
  16356. input (Tensor): the input tensor.
  16357. dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
  16358. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16359. Keyword args:
  16360. out (tuple, optional): the result tuple of two output tensors (max, max_indices)
  16361. Example::
  16362. >>> a = torch.randn(4, 4)
  16363. >>> a
  16364. tensor([[-1.2360, -0.2942, -0.1222, 0.8475],
  16365. [ 1.1949, -1.1127, -2.2379, -0.6702],
  16366. [ 1.5717, -0.9207, 0.1297, -1.8768],
  16367. [-0.6172, 1.0036, -0.6060, -0.2432]])
  16368. >>> torch.max(a, 1)
  16369. torch.return_types.max(values=tensor([0.8475, 1.1949, 1.5717, 1.0036]), indices=tensor([3, 0, 0, 1]))
  16370. >>> a = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
  16371. >>> a.max(dim=1, keepdim=True)
  16372. torch.return_types.max(
  16373. values=tensor([[2.], [4.]]),
  16374. indices=tensor([[1], [1]]))
  16375. >>> a.max(dim=1, keepdim=False)
  16376. torch.return_types.max(
  16377. values=tensor([2., 4.]),
  16378. indices=tensor([1, 1]))
  16379. .. function:: max(input, other, *, out=None) -> Tensor
  16380. :noindex:
  16381. See :func:`torch.maximum`.
  16382. """
  16383. @overload
  16384. def max(
  16385. input: Tensor,
  16386. other: Tensor,
  16387. *,
  16388. out: Tensor | None = None,
  16389. ) -> Tensor:
  16390. r"""
  16391. max(input, *, out=None) -> Tensor
  16392. Returns the maximum value of all elements in the ``input`` tensor.
  16393. .. note::
  16394. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  16395. - ``amax``/``amin`` supports reducing on multiple dimensions,
  16396. - ``amax``/``amin`` does not return indices.
  16397. Both ``amax``/``amin`` evenly distribute gradients between equal values
  16398. when there are multiple input elements with the same minimum or maximum value.
  16399. For ``max``/``min``:
  16400. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  16401. - If reduce over one specified axis, only propagate to the indexed element.
  16402. Args:
  16403. input (Tensor): the input tensor.
  16404. Keyword args:
  16405. out (Tensor, optional): the output tensor.
  16406. Example::
  16407. >>> a = torch.randn(1, 3)
  16408. >>> a
  16409. tensor([[ 0.6763, 0.7445, -2.2369]])
  16410. >>> torch.max(a)
  16411. tensor(0.7445)
  16412. .. function:: max(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  16413. :noindex:
  16414. Returns a namedtuple ``(values, indices)`` where ``values`` is the maximum
  16415. value of each row of the :attr:`input` tensor in the given dimension
  16416. :attr:`dim`. And ``indices`` is the index location of each maximum value found
  16417. (argmax).
  16418. If ``keepdim`` is ``True``, the output tensors are of the same size
  16419. as ``input`` except in the dimension ``dim`` where they are of size 1.
  16420. Otherwise, ``dim`` is squeezed (see :func:`torch.squeeze`), resulting
  16421. in the output tensors having 1 fewer dimension than ``input``.
  16422. .. note:: If there are multiple maximal values in a reduced row then
  16423. the indices of the first maximal value are returned.
  16424. Args:
  16425. input (Tensor): the input tensor.
  16426. dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
  16427. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16428. Keyword args:
  16429. out (tuple, optional): the result tuple of two output tensors (max, max_indices)
  16430. Example::
  16431. >>> a = torch.randn(4, 4)
  16432. >>> a
  16433. tensor([[-1.2360, -0.2942, -0.1222, 0.8475],
  16434. [ 1.1949, -1.1127, -2.2379, -0.6702],
  16435. [ 1.5717, -0.9207, 0.1297, -1.8768],
  16436. [-0.6172, 1.0036, -0.6060, -0.2432]])
  16437. >>> torch.max(a, 1)
  16438. torch.return_types.max(values=tensor([0.8475, 1.1949, 1.5717, 1.0036]), indices=tensor([3, 0, 0, 1]))
  16439. >>> a = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
  16440. >>> a.max(dim=1, keepdim=True)
  16441. torch.return_types.max(
  16442. values=tensor([[2.], [4.]]),
  16443. indices=tensor([[1], [1]]))
  16444. >>> a.max(dim=1, keepdim=False)
  16445. torch.return_types.max(
  16446. values=tensor([2., 4.]),
  16447. indices=tensor([1, 1]))
  16448. .. function:: max(input, other, *, out=None) -> Tensor
  16449. :noindex:
  16450. See :func:`torch.maximum`.
  16451. """
  16452. @overload
  16453. def max(
  16454. input: Tensor,
  16455. dim: _int,
  16456. keepdim: _bool = False,
  16457. *,
  16458. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  16459. ) -> torch.return_types.max:
  16460. r"""
  16461. max(input, *, out=None) -> Tensor
  16462. Returns the maximum value of all elements in the ``input`` tensor.
  16463. .. note::
  16464. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  16465. - ``amax``/``amin`` supports reducing on multiple dimensions,
  16466. - ``amax``/``amin`` does not return indices.
  16467. Both ``amax``/``amin`` evenly distribute gradients between equal values
  16468. when there are multiple input elements with the same minimum or maximum value.
  16469. For ``max``/``min``:
  16470. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  16471. - If reduce over one specified axis, only propagate to the indexed element.
  16472. Args:
  16473. input (Tensor): the input tensor.
  16474. Keyword args:
  16475. out (Tensor, optional): the output tensor.
  16476. Example::
  16477. >>> a = torch.randn(1, 3)
  16478. >>> a
  16479. tensor([[ 0.6763, 0.7445, -2.2369]])
  16480. >>> torch.max(a)
  16481. tensor(0.7445)
  16482. .. function:: max(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  16483. :noindex:
  16484. Returns a namedtuple ``(values, indices)`` where ``values`` is the maximum
  16485. value of each row of the :attr:`input` tensor in the given dimension
  16486. :attr:`dim`. And ``indices`` is the index location of each maximum value found
  16487. (argmax).
  16488. If ``keepdim`` is ``True``, the output tensors are of the same size
  16489. as ``input`` except in the dimension ``dim`` where they are of size 1.
  16490. Otherwise, ``dim`` is squeezed (see :func:`torch.squeeze`), resulting
  16491. in the output tensors having 1 fewer dimension than ``input``.
  16492. .. note:: If there are multiple maximal values in a reduced row then
  16493. the indices of the first maximal value are returned.
  16494. Args:
  16495. input (Tensor): the input tensor.
  16496. dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
  16497. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16498. Keyword args:
  16499. out (tuple, optional): the result tuple of two output tensors (max, max_indices)
  16500. Example::
  16501. >>> a = torch.randn(4, 4)
  16502. >>> a
  16503. tensor([[-1.2360, -0.2942, -0.1222, 0.8475],
  16504. [ 1.1949, -1.1127, -2.2379, -0.6702],
  16505. [ 1.5717, -0.9207, 0.1297, -1.8768],
  16506. [-0.6172, 1.0036, -0.6060, -0.2432]])
  16507. >>> torch.max(a, 1)
  16508. torch.return_types.max(values=tensor([0.8475, 1.1949, 1.5717, 1.0036]), indices=tensor([3, 0, 0, 1]))
  16509. >>> a = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
  16510. >>> a.max(dim=1, keepdim=True)
  16511. torch.return_types.max(
  16512. values=tensor([[2.], [4.]]),
  16513. indices=tensor([[1], [1]]))
  16514. >>> a.max(dim=1, keepdim=False)
  16515. torch.return_types.max(
  16516. values=tensor([2., 4.]),
  16517. indices=tensor([1, 1]))
  16518. .. function:: max(input, other, *, out=None) -> Tensor
  16519. :noindex:
  16520. See :func:`torch.maximum`.
  16521. """
  16522. @overload
  16523. def max(
  16524. input: Tensor,
  16525. dim: str | EllipsisType | None,
  16526. keepdim: _bool = False,
  16527. *,
  16528. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  16529. ) -> torch.return_types.max:
  16530. r"""
  16531. max(input, *, out=None) -> Tensor
  16532. Returns the maximum value of all elements in the ``input`` tensor.
  16533. .. note::
  16534. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  16535. - ``amax``/``amin`` supports reducing on multiple dimensions,
  16536. - ``amax``/``amin`` does not return indices.
  16537. Both ``amax``/``amin`` evenly distribute gradients between equal values
  16538. when there are multiple input elements with the same minimum or maximum value.
  16539. For ``max``/``min``:
  16540. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  16541. - If reduce over one specified axis, only propagate to the indexed element.
  16542. Args:
  16543. input (Tensor): the input tensor.
  16544. Keyword args:
  16545. out (Tensor, optional): the output tensor.
  16546. Example::
  16547. >>> a = torch.randn(1, 3)
  16548. >>> a
  16549. tensor([[ 0.6763, 0.7445, -2.2369]])
  16550. >>> torch.max(a)
  16551. tensor(0.7445)
  16552. .. function:: max(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  16553. :noindex:
  16554. Returns a namedtuple ``(values, indices)`` where ``values`` is the maximum
  16555. value of each row of the :attr:`input` tensor in the given dimension
  16556. :attr:`dim`. And ``indices`` is the index location of each maximum value found
  16557. (argmax).
  16558. If ``keepdim`` is ``True``, the output tensors are of the same size
  16559. as ``input`` except in the dimension ``dim`` where they are of size 1.
  16560. Otherwise, ``dim`` is squeezed (see :func:`torch.squeeze`), resulting
  16561. in the output tensors having 1 fewer dimension than ``input``.
  16562. .. note:: If there are multiple maximal values in a reduced row then
  16563. the indices of the first maximal value are returned.
  16564. Args:
  16565. input (Tensor): the input tensor.
  16566. dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
  16567. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16568. Keyword args:
  16569. out (tuple, optional): the result tuple of two output tensors (max, max_indices)
  16570. Example::
  16571. >>> a = torch.randn(4, 4)
  16572. >>> a
  16573. tensor([[-1.2360, -0.2942, -0.1222, 0.8475],
  16574. [ 1.1949, -1.1127, -2.2379, -0.6702],
  16575. [ 1.5717, -0.9207, 0.1297, -1.8768],
  16576. [-0.6172, 1.0036, -0.6060, -0.2432]])
  16577. >>> torch.max(a, 1)
  16578. torch.return_types.max(values=tensor([0.8475, 1.1949, 1.5717, 1.0036]), indices=tensor([3, 0, 0, 1]))
  16579. >>> a = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
  16580. >>> a.max(dim=1, keepdim=True)
  16581. torch.return_types.max(
  16582. values=tensor([[2.], [4.]]),
  16583. indices=tensor([[1], [1]]))
  16584. >>> a.max(dim=1, keepdim=False)
  16585. torch.return_types.max(
  16586. values=tensor([2., 4.]),
  16587. indices=tensor([1, 1]))
  16588. .. function:: max(input, other, *, out=None) -> Tensor
  16589. :noindex:
  16590. See :func:`torch.maximum`.
  16591. """
  16592. def max_pool1d(
  16593. input: Tensor,
  16594. kernel_size: _int | _size,
  16595. stride: _int | _size = (),
  16596. padding: _int | _size = 0,
  16597. dilation: _int | _size = 1,
  16598. ceil_mode: _bool = False,
  16599. ) -> Tensor: ...
  16600. def max_pool1d_with_indices(
  16601. input: Tensor,
  16602. kernel_size: _int | _size,
  16603. stride: _int | _size = (),
  16604. padding: _int | _size = 0,
  16605. dilation: _int | _size = 1,
  16606. ceil_mode: _bool = False,
  16607. ) -> tuple[Tensor, Tensor]: ...
  16608. def max_pool2d(
  16609. input: Tensor,
  16610. kernel_size: _int | _size,
  16611. stride: _int | _size = (),
  16612. padding: _int | _size = 0,
  16613. dilation: _int | _size = 1,
  16614. ceil_mode: _bool = False,
  16615. ) -> Tensor: ...
  16616. def max_pool3d(
  16617. input: Tensor,
  16618. kernel_size: _int | _size,
  16619. stride: _int | _size = (),
  16620. padding: _int | _size = 0,
  16621. dilation: _int | _size = 1,
  16622. ceil_mode: _bool = False,
  16623. ) -> Tensor: ...
  16624. def maximum(
  16625. input: Tensor,
  16626. other: Tensor,
  16627. *,
  16628. out: Tensor | None = None,
  16629. ) -> Tensor:
  16630. r"""
  16631. maximum(input, other, *, out=None) -> Tensor
  16632. Computes the element-wise maximum of :attr:`input` and :attr:`other`.
  16633. .. note::
  16634. If one of the elements being compared is a NaN, then that element is returned.
  16635. :func:`maximum` is not supported for tensors with complex dtypes.
  16636. Args:
  16637. input (Tensor): the input tensor.
  16638. other (Tensor): the second input tensor
  16639. Keyword args:
  16640. out (Tensor, optional): the output tensor.
  16641. Example::
  16642. >>> a = torch.tensor((1, 2, -1))
  16643. >>> b = torch.tensor((3, 0, 4))
  16644. >>> torch.maximum(a, b)
  16645. tensor([3, 2, 4])
  16646. """
  16647. @overload
  16648. def mean(
  16649. input: Tensor,
  16650. *,
  16651. dtype: _dtype | None = None,
  16652. out: Tensor | None = None,
  16653. ) -> Tensor:
  16654. r"""
  16655. mean(input, *, dtype=None) -> Tensor
  16656. .. note::
  16657. If the `input` tensor is empty, ``torch.mean()`` returns ``nan``.
  16658. This behavior is consistent with NumPy and follows the definition
  16659. that the mean over an empty set is undefined.
  16660. Returns the mean value of all elements in the :attr:`input` tensor. Input must be floating point or complex.
  16661. Args:
  16662. input (Tensor):
  16663. the input tensor, either of floating point or complex dtype
  16664. Keyword args:
  16665. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  16666. If specified, the input tensor is casted to :attr:`dtype` before the operation
  16667. is performed. This is useful for preventing data type overflows. Default: None.
  16668. Example::
  16669. >>> a = torch.randn(1, 3)
  16670. >>> a
  16671. tensor([[ 0.2294, -0.5481, 1.3288]])
  16672. >>> torch.mean(a)
  16673. tensor(0.3367)
  16674. .. function:: mean(input, dim, keepdim=False, *, dtype=None, out=None) -> Tensor
  16675. :noindex:
  16676. Returns the mean value of each row of the :attr:`input` tensor in the given
  16677. dimension :attr:`dim`. If :attr:`dim` is a list of dimensions,
  16678. reduce over all of them.
  16679. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  16680. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  16681. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  16682. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  16683. Args:
  16684. input (Tensor): the input tensor.
  16685. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  16686. If ``None``, all dimensions are reduced.
  16687. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16688. Keyword args:
  16689. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  16690. If specified, the input tensor is casted to :attr:`dtype` before the operation
  16691. is performed. This is useful for preventing data type overflows. Default: None.
  16692. out (Tensor, optional): the output tensor.
  16693. .. seealso::
  16694. :func:`torch.nanmean` computes the mean value of `non-NaN` elements.
  16695. Example::
  16696. >>> a = torch.randn(4, 4)
  16697. >>> a
  16698. tensor([[-0.3841, 0.6320, 0.4254, -0.7384],
  16699. [-0.9644, 1.0131, -0.6549, -1.4279],
  16700. [-0.2951, -1.3350, -0.7694, 0.5600],
  16701. [ 1.0842, -0.9580, 0.3623, 0.2343]])
  16702. >>> torch.mean(a, 1)
  16703. tensor([-0.0163, -0.5085, -0.4599, 0.1807])
  16704. >>> torch.mean(a, 1, True)
  16705. tensor([[-0.0163],
  16706. [-0.5085],
  16707. [-0.4599],
  16708. [ 0.1807]])
  16709. """
  16710. @overload
  16711. def mean(
  16712. input: Tensor,
  16713. dim: _int | _size | None,
  16714. keepdim: _bool = False,
  16715. *,
  16716. dtype: _dtype | None = None,
  16717. out: Tensor | None = None,
  16718. ) -> Tensor:
  16719. r"""
  16720. mean(input, *, dtype=None) -> Tensor
  16721. .. note::
  16722. If the `input` tensor is empty, ``torch.mean()`` returns ``nan``.
  16723. This behavior is consistent with NumPy and follows the definition
  16724. that the mean over an empty set is undefined.
  16725. Returns the mean value of all elements in the :attr:`input` tensor. Input must be floating point or complex.
  16726. Args:
  16727. input (Tensor):
  16728. the input tensor, either of floating point or complex dtype
  16729. Keyword args:
  16730. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  16731. If specified, the input tensor is casted to :attr:`dtype` before the operation
  16732. is performed. This is useful for preventing data type overflows. Default: None.
  16733. Example::
  16734. >>> a = torch.randn(1, 3)
  16735. >>> a
  16736. tensor([[ 0.2294, -0.5481, 1.3288]])
  16737. >>> torch.mean(a)
  16738. tensor(0.3367)
  16739. .. function:: mean(input, dim, keepdim=False, *, dtype=None, out=None) -> Tensor
  16740. :noindex:
  16741. Returns the mean value of each row of the :attr:`input` tensor in the given
  16742. dimension :attr:`dim`. If :attr:`dim` is a list of dimensions,
  16743. reduce over all of them.
  16744. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  16745. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  16746. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  16747. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  16748. Args:
  16749. input (Tensor): the input tensor.
  16750. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  16751. If ``None``, all dimensions are reduced.
  16752. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16753. Keyword args:
  16754. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  16755. If specified, the input tensor is casted to :attr:`dtype` before the operation
  16756. is performed. This is useful for preventing data type overflows. Default: None.
  16757. out (Tensor, optional): the output tensor.
  16758. .. seealso::
  16759. :func:`torch.nanmean` computes the mean value of `non-NaN` elements.
  16760. Example::
  16761. >>> a = torch.randn(4, 4)
  16762. >>> a
  16763. tensor([[-0.3841, 0.6320, 0.4254, -0.7384],
  16764. [-0.9644, 1.0131, -0.6549, -1.4279],
  16765. [-0.2951, -1.3350, -0.7694, 0.5600],
  16766. [ 1.0842, -0.9580, 0.3623, 0.2343]])
  16767. >>> torch.mean(a, 1)
  16768. tensor([-0.0163, -0.5085, -0.4599, 0.1807])
  16769. >>> torch.mean(a, 1, True)
  16770. tensor([[-0.0163],
  16771. [-0.5085],
  16772. [-0.4599],
  16773. [ 0.1807]])
  16774. """
  16775. @overload
  16776. def mean(
  16777. input: Tensor,
  16778. dim: Sequence[str | EllipsisType | None],
  16779. keepdim: _bool = False,
  16780. *,
  16781. dtype: _dtype | None = None,
  16782. out: Tensor | None = None,
  16783. ) -> Tensor:
  16784. r"""
  16785. mean(input, *, dtype=None) -> Tensor
  16786. .. note::
  16787. If the `input` tensor is empty, ``torch.mean()`` returns ``nan``.
  16788. This behavior is consistent with NumPy and follows the definition
  16789. that the mean over an empty set is undefined.
  16790. Returns the mean value of all elements in the :attr:`input` tensor. Input must be floating point or complex.
  16791. Args:
  16792. input (Tensor):
  16793. the input tensor, either of floating point or complex dtype
  16794. Keyword args:
  16795. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  16796. If specified, the input tensor is casted to :attr:`dtype` before the operation
  16797. is performed. This is useful for preventing data type overflows. Default: None.
  16798. Example::
  16799. >>> a = torch.randn(1, 3)
  16800. >>> a
  16801. tensor([[ 0.2294, -0.5481, 1.3288]])
  16802. >>> torch.mean(a)
  16803. tensor(0.3367)
  16804. .. function:: mean(input, dim, keepdim=False, *, dtype=None, out=None) -> Tensor
  16805. :noindex:
  16806. Returns the mean value of each row of the :attr:`input` tensor in the given
  16807. dimension :attr:`dim`. If :attr:`dim` is a list of dimensions,
  16808. reduce over all of them.
  16809. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  16810. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  16811. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  16812. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  16813. Args:
  16814. input (Tensor): the input tensor.
  16815. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  16816. If ``None``, all dimensions are reduced.
  16817. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16818. Keyword args:
  16819. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  16820. If specified, the input tensor is casted to :attr:`dtype` before the operation
  16821. is performed. This is useful for preventing data type overflows. Default: None.
  16822. out (Tensor, optional): the output tensor.
  16823. .. seealso::
  16824. :func:`torch.nanmean` computes the mean value of `non-NaN` elements.
  16825. Example::
  16826. >>> a = torch.randn(4, 4)
  16827. >>> a
  16828. tensor([[-0.3841, 0.6320, 0.4254, -0.7384],
  16829. [-0.9644, 1.0131, -0.6549, -1.4279],
  16830. [-0.2951, -1.3350, -0.7694, 0.5600],
  16831. [ 1.0842, -0.9580, 0.3623, 0.2343]])
  16832. >>> torch.mean(a, 1)
  16833. tensor([-0.0163, -0.5085, -0.4599, 0.1807])
  16834. >>> torch.mean(a, 1, True)
  16835. tensor([[-0.0163],
  16836. [-0.5085],
  16837. [-0.4599],
  16838. [ 0.1807]])
  16839. """
  16840. @overload
  16841. def median(input: Tensor) -> Tensor:
  16842. r"""
  16843. median(input) -> Tensor
  16844. Returns the median of the values in :attr:`input`.
  16845. .. note::
  16846. The median is not unique for :attr:`input` tensors with an even number
  16847. of elements. In this case the lower of the two medians is returned. To
  16848. compute the mean of both medians, use :func:`torch.quantile` with ``q=0.5`` instead.
  16849. .. warning::
  16850. This function produces deterministic (sub)gradients unlike ``median(dim=0)``
  16851. Args:
  16852. input (Tensor): the input tensor.
  16853. Example::
  16854. >>> a = torch.randn(1, 3)
  16855. >>> a
  16856. tensor([[ 1.5219, -1.5212, 0.2202]])
  16857. >>> torch.median(a)
  16858. tensor(0.2202)
  16859. .. function:: median(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  16860. :noindex:
  16861. Returns a namedtuple ``(values, indices)`` where ``values`` contains the median of each row of :attr:`input`
  16862. in the dimension :attr:`dim`, and ``indices`` contains the index of the median values found in the dimension :attr:`dim`.
  16863. By default, :attr:`dim` is the last dimension of the :attr:`input` tensor.
  16864. If :attr:`keepdim` is ``True``, the output tensors are of the same size
  16865. as :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  16866. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  16867. the outputs tensor having 1 fewer dimension than :attr:`input`.
  16868. .. note::
  16869. The median is not unique for :attr:`input` tensors with an even number
  16870. of elements in the dimension :attr:`dim`. In this case the lower of the
  16871. two medians is returned. To compute the mean of both medians in
  16872. :attr:`input`, use :func:`torch.quantile` with ``q=0.5`` instead.
  16873. .. warning::
  16874. ``indices`` does not necessarily contain the first occurrence of each
  16875. median value found, unless it is unique.
  16876. The exact implementation details are device-specific.
  16877. Do not expect the same result when run on CPU and GPU in general.
  16878. For the same reason do not expect the gradients to be deterministic.
  16879. Args:
  16880. input (Tensor): the input tensor.
  16881. dim (int, optional): the dimension to reduce.
  16882. If ``None``, all dimensions are reduced.
  16883. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16884. Keyword args:
  16885. out ((Tensor, Tensor), optional): The first tensor will be populated with the median values and the second
  16886. tensor, which must have dtype long, with their indices in the dimension
  16887. :attr:`dim` of :attr:`input`.
  16888. Example::
  16889. >>> a = torch.randn(4, 5)
  16890. >>> a
  16891. tensor([[ 0.2505, -0.3982, -0.9948, 0.3518, -1.3131],
  16892. [ 0.3180, -0.6993, 1.0436, 0.0438, 0.2270],
  16893. [-0.2751, 0.7303, 0.2192, 0.3321, 0.2488],
  16894. [ 1.0778, -1.9510, 0.7048, 0.4742, -0.7125]])
  16895. >>> torch.median(a, 1)
  16896. torch.return_types.median(values=tensor([-0.3982, 0.2270, 0.2488, 0.4742]), indices=tensor([1, 4, 4, 3]))
  16897. """
  16898. @overload
  16899. def median(
  16900. input: Tensor,
  16901. dim: _int,
  16902. keepdim: _bool = False,
  16903. *,
  16904. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  16905. ) -> torch.return_types.median:
  16906. r"""
  16907. median(input) -> Tensor
  16908. Returns the median of the values in :attr:`input`.
  16909. .. note::
  16910. The median is not unique for :attr:`input` tensors with an even number
  16911. of elements. In this case the lower of the two medians is returned. To
  16912. compute the mean of both medians, use :func:`torch.quantile` with ``q=0.5`` instead.
  16913. .. warning::
  16914. This function produces deterministic (sub)gradients unlike ``median(dim=0)``
  16915. Args:
  16916. input (Tensor): the input tensor.
  16917. Example::
  16918. >>> a = torch.randn(1, 3)
  16919. >>> a
  16920. tensor([[ 1.5219, -1.5212, 0.2202]])
  16921. >>> torch.median(a)
  16922. tensor(0.2202)
  16923. .. function:: median(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  16924. :noindex:
  16925. Returns a namedtuple ``(values, indices)`` where ``values`` contains the median of each row of :attr:`input`
  16926. in the dimension :attr:`dim`, and ``indices`` contains the index of the median values found in the dimension :attr:`dim`.
  16927. By default, :attr:`dim` is the last dimension of the :attr:`input` tensor.
  16928. If :attr:`keepdim` is ``True``, the output tensors are of the same size
  16929. as :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  16930. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  16931. the outputs tensor having 1 fewer dimension than :attr:`input`.
  16932. .. note::
  16933. The median is not unique for :attr:`input` tensors with an even number
  16934. of elements in the dimension :attr:`dim`. In this case the lower of the
  16935. two medians is returned. To compute the mean of both medians in
  16936. :attr:`input`, use :func:`torch.quantile` with ``q=0.5`` instead.
  16937. .. warning::
  16938. ``indices`` does not necessarily contain the first occurrence of each
  16939. median value found, unless it is unique.
  16940. The exact implementation details are device-specific.
  16941. Do not expect the same result when run on CPU and GPU in general.
  16942. For the same reason do not expect the gradients to be deterministic.
  16943. Args:
  16944. input (Tensor): the input tensor.
  16945. dim (int, optional): the dimension to reduce.
  16946. If ``None``, all dimensions are reduced.
  16947. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  16948. Keyword args:
  16949. out ((Tensor, Tensor), optional): The first tensor will be populated with the median values and the second
  16950. tensor, which must have dtype long, with their indices in the dimension
  16951. :attr:`dim` of :attr:`input`.
  16952. Example::
  16953. >>> a = torch.randn(4, 5)
  16954. >>> a
  16955. tensor([[ 0.2505, -0.3982, -0.9948, 0.3518, -1.3131],
  16956. [ 0.3180, -0.6993, 1.0436, 0.0438, 0.2270],
  16957. [-0.2751, 0.7303, 0.2192, 0.3321, 0.2488],
  16958. [ 1.0778, -1.9510, 0.7048, 0.4742, -0.7125]])
  16959. >>> torch.median(a, 1)
  16960. torch.return_types.median(values=tensor([-0.3982, 0.2270, 0.2488, 0.4742]), indices=tensor([1, 4, 4, 3]))
  16961. """
  16962. @overload
  16963. def median(
  16964. input: Tensor,
  16965. dim: str | EllipsisType | None,
  16966. keepdim: _bool = False,
  16967. *,
  16968. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  16969. ) -> torch.return_types.median:
  16970. r"""
  16971. median(input) -> Tensor
  16972. Returns the median of the values in :attr:`input`.
  16973. .. note::
  16974. The median is not unique for :attr:`input` tensors with an even number
  16975. of elements. In this case the lower of the two medians is returned. To
  16976. compute the mean of both medians, use :func:`torch.quantile` with ``q=0.5`` instead.
  16977. .. warning::
  16978. This function produces deterministic (sub)gradients unlike ``median(dim=0)``
  16979. Args:
  16980. input (Tensor): the input tensor.
  16981. Example::
  16982. >>> a = torch.randn(1, 3)
  16983. >>> a
  16984. tensor([[ 1.5219, -1.5212, 0.2202]])
  16985. >>> torch.median(a)
  16986. tensor(0.2202)
  16987. .. function:: median(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  16988. :noindex:
  16989. Returns a namedtuple ``(values, indices)`` where ``values`` contains the median of each row of :attr:`input`
  16990. in the dimension :attr:`dim`, and ``indices`` contains the index of the median values found in the dimension :attr:`dim`.
  16991. By default, :attr:`dim` is the last dimension of the :attr:`input` tensor.
  16992. If :attr:`keepdim` is ``True``, the output tensors are of the same size
  16993. as :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  16994. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  16995. the outputs tensor having 1 fewer dimension than :attr:`input`.
  16996. .. note::
  16997. The median is not unique for :attr:`input` tensors with an even number
  16998. of elements in the dimension :attr:`dim`. In this case the lower of the
  16999. two medians is returned. To compute the mean of both medians in
  17000. :attr:`input`, use :func:`torch.quantile` with ``q=0.5`` instead.
  17001. .. warning::
  17002. ``indices`` does not necessarily contain the first occurrence of each
  17003. median value found, unless it is unique.
  17004. The exact implementation details are device-specific.
  17005. Do not expect the same result when run on CPU and GPU in general.
  17006. For the same reason do not expect the gradients to be deterministic.
  17007. Args:
  17008. input (Tensor): the input tensor.
  17009. dim (int, optional): the dimension to reduce.
  17010. If ``None``, all dimensions are reduced.
  17011. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17012. Keyword args:
  17013. out ((Tensor, Tensor), optional): The first tensor will be populated with the median values and the second
  17014. tensor, which must have dtype long, with their indices in the dimension
  17015. :attr:`dim` of :attr:`input`.
  17016. Example::
  17017. >>> a = torch.randn(4, 5)
  17018. >>> a
  17019. tensor([[ 0.2505, -0.3982, -0.9948, 0.3518, -1.3131],
  17020. [ 0.3180, -0.6993, 1.0436, 0.0438, 0.2270],
  17021. [-0.2751, 0.7303, 0.2192, 0.3321, 0.2488],
  17022. [ 1.0778, -1.9510, 0.7048, 0.4742, -0.7125]])
  17023. >>> torch.median(a, 1)
  17024. torch.return_types.median(values=tensor([-0.3982, 0.2270, 0.2488, 0.4742]), indices=tensor([1, 4, 4, 3]))
  17025. """
  17026. @overload
  17027. def min(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  17028. r"""
  17029. min(input, *, out=None) -> Tensor
  17030. Returns the minimum value of all elements in the :attr:`input` tensor.
  17031. .. note::
  17032. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  17033. - ``amax``/``amin`` supports reducing on multiple dimensions,
  17034. - ``amax``/``amin`` does not return indices.
  17035. Both ``amax``/``amin`` evenly distribute gradients between equal values
  17036. when there are multiple input elements with the same minimum or maximum value.
  17037. For ``max``/``min``:
  17038. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  17039. - If reduce over one specified axis, only propagate to the indexed element.
  17040. Args:
  17041. input (Tensor): the input tensor.
  17042. Keyword args:
  17043. out (Tensor, optional): the output tensor.
  17044. Example::
  17045. >>> a = torch.randn(1, 3)
  17046. >>> a
  17047. tensor([[ 0.6750, 1.0857, 1.7197]])
  17048. >>> torch.min(a)
  17049. tensor(0.6750)
  17050. .. function:: min(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  17051. :noindex:
  17052. Returns a namedtuple ``(values, indices)`` where ``values`` is the minimum
  17053. value of each row of the :attr:`input` tensor in the given dimension
  17054. :attr:`dim`. And ``indices`` is the index location of each minimum value found
  17055. (argmin).
  17056. If :attr:`keepdim` is ``True``, the output tensors are of the same size as
  17057. :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  17058. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  17059. the output tensors having 1 fewer dimension than :attr:`input`.
  17060. .. note:: If there are multiple minimal values in a reduced row then
  17061. the indices of the first minimal value are returned.
  17062. Args:
  17063. input (Tensor): the input tensor.
  17064. dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
  17065. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17066. Keyword args:
  17067. out (tuple, optional): the tuple of two output tensors (min, min_indices)
  17068. Example::
  17069. >>> a = torch.randn(4, 4)
  17070. >>> a
  17071. tensor([[-0.6248, 1.1334, -1.1899, -0.2803],
  17072. [-1.4644, -0.2635, -0.3651, 0.6134],
  17073. [ 0.2457, 0.0384, 1.0128, 0.7015],
  17074. [-0.1153, 2.9849, 2.1458, 0.5788]])
  17075. >>> torch.min(a, 1)
  17076. torch.return_types.min(values=tensor([-1.1899, -1.4644, 0.0384, -0.1153]), indices=tensor([2, 0, 1, 0]))
  17077. .. function:: min(input, other, *, out=None) -> Tensor
  17078. :noindex:
  17079. See :func:`torch.minimum`.
  17080. """
  17081. @overload
  17082. def min(
  17083. input: Tensor,
  17084. other: Tensor,
  17085. *,
  17086. out: Tensor | None = None,
  17087. ) -> Tensor:
  17088. r"""
  17089. min(input, *, out=None) -> Tensor
  17090. Returns the minimum value of all elements in the :attr:`input` tensor.
  17091. .. note::
  17092. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  17093. - ``amax``/``amin`` supports reducing on multiple dimensions,
  17094. - ``amax``/``amin`` does not return indices.
  17095. Both ``amax``/``amin`` evenly distribute gradients between equal values
  17096. when there are multiple input elements with the same minimum or maximum value.
  17097. For ``max``/``min``:
  17098. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  17099. - If reduce over one specified axis, only propagate to the indexed element.
  17100. Args:
  17101. input (Tensor): the input tensor.
  17102. Keyword args:
  17103. out (Tensor, optional): the output tensor.
  17104. Example::
  17105. >>> a = torch.randn(1, 3)
  17106. >>> a
  17107. tensor([[ 0.6750, 1.0857, 1.7197]])
  17108. >>> torch.min(a)
  17109. tensor(0.6750)
  17110. .. function:: min(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  17111. :noindex:
  17112. Returns a namedtuple ``(values, indices)`` where ``values`` is the minimum
  17113. value of each row of the :attr:`input` tensor in the given dimension
  17114. :attr:`dim`. And ``indices`` is the index location of each minimum value found
  17115. (argmin).
  17116. If :attr:`keepdim` is ``True``, the output tensors are of the same size as
  17117. :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  17118. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  17119. the output tensors having 1 fewer dimension than :attr:`input`.
  17120. .. note:: If there are multiple minimal values in a reduced row then
  17121. the indices of the first minimal value are returned.
  17122. Args:
  17123. input (Tensor): the input tensor.
  17124. dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
  17125. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17126. Keyword args:
  17127. out (tuple, optional): the tuple of two output tensors (min, min_indices)
  17128. Example::
  17129. >>> a = torch.randn(4, 4)
  17130. >>> a
  17131. tensor([[-0.6248, 1.1334, -1.1899, -0.2803],
  17132. [-1.4644, -0.2635, -0.3651, 0.6134],
  17133. [ 0.2457, 0.0384, 1.0128, 0.7015],
  17134. [-0.1153, 2.9849, 2.1458, 0.5788]])
  17135. >>> torch.min(a, 1)
  17136. torch.return_types.min(values=tensor([-1.1899, -1.4644, 0.0384, -0.1153]), indices=tensor([2, 0, 1, 0]))
  17137. .. function:: min(input, other, *, out=None) -> Tensor
  17138. :noindex:
  17139. See :func:`torch.minimum`.
  17140. """
  17141. @overload
  17142. def min(
  17143. input: Tensor,
  17144. dim: _int,
  17145. keepdim: _bool = False,
  17146. *,
  17147. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  17148. ) -> torch.return_types.min:
  17149. r"""
  17150. min(input, *, out=None) -> Tensor
  17151. Returns the minimum value of all elements in the :attr:`input` tensor.
  17152. .. note::
  17153. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  17154. - ``amax``/``amin`` supports reducing on multiple dimensions,
  17155. - ``amax``/``amin`` does not return indices.
  17156. Both ``amax``/``amin`` evenly distribute gradients between equal values
  17157. when there are multiple input elements with the same minimum or maximum value.
  17158. For ``max``/``min``:
  17159. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  17160. - If reduce over one specified axis, only propagate to the indexed element.
  17161. Args:
  17162. input (Tensor): the input tensor.
  17163. Keyword args:
  17164. out (Tensor, optional): the output tensor.
  17165. Example::
  17166. >>> a = torch.randn(1, 3)
  17167. >>> a
  17168. tensor([[ 0.6750, 1.0857, 1.7197]])
  17169. >>> torch.min(a)
  17170. tensor(0.6750)
  17171. .. function:: min(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  17172. :noindex:
  17173. Returns a namedtuple ``(values, indices)`` where ``values`` is the minimum
  17174. value of each row of the :attr:`input` tensor in the given dimension
  17175. :attr:`dim`. And ``indices`` is the index location of each minimum value found
  17176. (argmin).
  17177. If :attr:`keepdim` is ``True``, the output tensors are of the same size as
  17178. :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  17179. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  17180. the output tensors having 1 fewer dimension than :attr:`input`.
  17181. .. note:: If there are multiple minimal values in a reduced row then
  17182. the indices of the first minimal value are returned.
  17183. Args:
  17184. input (Tensor): the input tensor.
  17185. dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
  17186. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17187. Keyword args:
  17188. out (tuple, optional): the tuple of two output tensors (min, min_indices)
  17189. Example::
  17190. >>> a = torch.randn(4, 4)
  17191. >>> a
  17192. tensor([[-0.6248, 1.1334, -1.1899, -0.2803],
  17193. [-1.4644, -0.2635, -0.3651, 0.6134],
  17194. [ 0.2457, 0.0384, 1.0128, 0.7015],
  17195. [-0.1153, 2.9849, 2.1458, 0.5788]])
  17196. >>> torch.min(a, 1)
  17197. torch.return_types.min(values=tensor([-1.1899, -1.4644, 0.0384, -0.1153]), indices=tensor([2, 0, 1, 0]))
  17198. .. function:: min(input, other, *, out=None) -> Tensor
  17199. :noindex:
  17200. See :func:`torch.minimum`.
  17201. """
  17202. @overload
  17203. def min(
  17204. input: Tensor,
  17205. dim: str | EllipsisType | None,
  17206. keepdim: _bool = False,
  17207. *,
  17208. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  17209. ) -> torch.return_types.min:
  17210. r"""
  17211. min(input, *, out=None) -> Tensor
  17212. Returns the minimum value of all elements in the :attr:`input` tensor.
  17213. .. note::
  17214. The difference between ``max``/``min`` and ``amax``/``amin`` is:
  17215. - ``amax``/``amin`` supports reducing on multiple dimensions,
  17216. - ``amax``/``amin`` does not return indices.
  17217. Both ``amax``/``amin`` evenly distribute gradients between equal values
  17218. when there are multiple input elements with the same minimum or maximum value.
  17219. For ``max``/``min``:
  17220. - If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
  17221. - If reduce over one specified axis, only propagate to the indexed element.
  17222. Args:
  17223. input (Tensor): the input tensor.
  17224. Keyword args:
  17225. out (Tensor, optional): the output tensor.
  17226. Example::
  17227. >>> a = torch.randn(1, 3)
  17228. >>> a
  17229. tensor([[ 0.6750, 1.0857, 1.7197]])
  17230. >>> torch.min(a)
  17231. tensor(0.6750)
  17232. .. function:: min(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  17233. :noindex:
  17234. Returns a namedtuple ``(values, indices)`` where ``values`` is the minimum
  17235. value of each row of the :attr:`input` tensor in the given dimension
  17236. :attr:`dim`. And ``indices`` is the index location of each minimum value found
  17237. (argmin).
  17238. If :attr:`keepdim` is ``True``, the output tensors are of the same size as
  17239. :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  17240. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  17241. the output tensors having 1 fewer dimension than :attr:`input`.
  17242. .. note:: If there are multiple minimal values in a reduced row then
  17243. the indices of the first minimal value are returned.
  17244. Args:
  17245. input (Tensor): the input tensor.
  17246. dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
  17247. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17248. Keyword args:
  17249. out (tuple, optional): the tuple of two output tensors (min, min_indices)
  17250. Example::
  17251. >>> a = torch.randn(4, 4)
  17252. >>> a
  17253. tensor([[-0.6248, 1.1334, -1.1899, -0.2803],
  17254. [-1.4644, -0.2635, -0.3651, 0.6134],
  17255. [ 0.2457, 0.0384, 1.0128, 0.7015],
  17256. [-0.1153, 2.9849, 2.1458, 0.5788]])
  17257. >>> torch.min(a, 1)
  17258. torch.return_types.min(values=tensor([-1.1899, -1.4644, 0.0384, -0.1153]), indices=tensor([2, 0, 1, 0]))
  17259. .. function:: min(input, other, *, out=None) -> Tensor
  17260. :noindex:
  17261. See :func:`torch.minimum`.
  17262. """
  17263. def minimum(
  17264. input: Tensor,
  17265. other: Tensor,
  17266. *,
  17267. out: Tensor | None = None,
  17268. ) -> Tensor:
  17269. r"""
  17270. minimum(input, other, *, out=None) -> Tensor
  17271. Computes the element-wise minimum of :attr:`input` and :attr:`other`.
  17272. .. note::
  17273. If one of the elements being compared is a NaN, then that element is returned.
  17274. :func:`minimum` is not supported for tensors with complex dtypes.
  17275. Args:
  17276. input (Tensor): the input tensor.
  17277. other (Tensor): the second input tensor
  17278. Keyword args:
  17279. out (Tensor, optional): the output tensor.
  17280. Example::
  17281. >>> a = torch.tensor((1, 2, -1))
  17282. >>> b = torch.tensor((3, 0, 4))
  17283. >>> torch.minimum(a, b)
  17284. tensor([1, 0, -1])
  17285. """
  17286. def miopen_batch_norm(
  17287. input: Tensor,
  17288. weight: Tensor,
  17289. bias: Tensor | None,
  17290. running_mean: Tensor | None,
  17291. running_var: Tensor | None,
  17292. training: _bool,
  17293. exponential_average_factor: _float,
  17294. epsilon: _float,
  17295. ) -> tuple[Tensor, Tensor, Tensor]: ...
  17296. def miopen_convolution(
  17297. input: Tensor,
  17298. weight: Tensor,
  17299. bias: Tensor | None,
  17300. padding: Sequence[_int | SymInt],
  17301. stride: Sequence[_int | SymInt],
  17302. dilation: Sequence[_int | SymInt],
  17303. groups: _int | SymInt,
  17304. benchmark: _bool,
  17305. deterministic: _bool,
  17306. ) -> Tensor: ...
  17307. def miopen_convolution_add_relu(
  17308. input: Tensor,
  17309. weight: Tensor,
  17310. z: Tensor,
  17311. alpha: Number | _complex | None,
  17312. bias: Tensor | None,
  17313. stride: Sequence[_int | SymInt],
  17314. padding: Sequence[_int | SymInt],
  17315. dilation: Sequence[_int | SymInt],
  17316. groups: _int | SymInt,
  17317. ) -> Tensor: ...
  17318. def miopen_convolution_relu(
  17319. input: Tensor,
  17320. weight: Tensor,
  17321. bias: Tensor | None,
  17322. stride: Sequence[_int | SymInt],
  17323. padding: Sequence[_int | SymInt],
  17324. dilation: Sequence[_int | SymInt],
  17325. groups: _int | SymInt,
  17326. ) -> Tensor: ...
  17327. def miopen_convolution_transpose(
  17328. input: Tensor,
  17329. weight: Tensor,
  17330. bias: Tensor | None,
  17331. padding: Sequence[_int | SymInt],
  17332. output_padding: Sequence[_int | SymInt],
  17333. stride: Sequence[_int | SymInt],
  17334. dilation: Sequence[_int | SymInt],
  17335. groups: _int | SymInt,
  17336. benchmark: _bool,
  17337. deterministic: _bool,
  17338. ) -> Tensor: ...
  17339. def miopen_depthwise_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. benchmark: _bool,
  17348. deterministic: _bool,
  17349. ) -> Tensor: ...
  17350. def miopen_rnn(
  17351. input: Tensor,
  17352. weight: tuple[Tensor, ...] | list[Tensor] | None,
  17353. weight_stride0: _int,
  17354. hx: Tensor,
  17355. cx: Tensor | None,
  17356. mode: _int,
  17357. hidden_size: _int,
  17358. num_layers: _int,
  17359. batch_first: _bool,
  17360. dropout: _float,
  17361. train: _bool,
  17362. bidirectional: _bool,
  17363. batch_sizes: _size,
  17364. dropout_state: Tensor | None,
  17365. ) -> tuple[Tensor, Tensor, Tensor, Tensor, Tensor]: ...
  17366. def mkldnn_adaptive_avg_pool2d(
  17367. input: Tensor,
  17368. output_size: _int | _size,
  17369. *,
  17370. out: Tensor | None = None,
  17371. ) -> Tensor: ...
  17372. def mkldnn_convolution(
  17373. input: Tensor,
  17374. weight: Tensor,
  17375. bias: Tensor | None,
  17376. padding: Sequence[_int | SymInt],
  17377. stride: Sequence[_int | SymInt],
  17378. dilation: Sequence[_int | SymInt],
  17379. groups: _int | SymInt,
  17380. ) -> Tensor: ...
  17381. def mkldnn_linear_backward_weights(
  17382. grad_output: Tensor,
  17383. input: Tensor,
  17384. weight: Tensor,
  17385. bias_defined: _bool,
  17386. ) -> tuple[Tensor, Tensor]: ...
  17387. def mkldnn_max_pool2d(
  17388. input: Tensor,
  17389. kernel_size: _int | _size,
  17390. stride: _int | _size = (),
  17391. padding: _int | _size = 0,
  17392. dilation: _int | _size = 1,
  17393. ceil_mode: _bool = False,
  17394. ) -> Tensor: ...
  17395. def mkldnn_max_pool3d(
  17396. input: Tensor,
  17397. kernel_size: _int | _size,
  17398. stride: _int | _size = (),
  17399. padding: _int | _size = 0,
  17400. dilation: _int | _size = 1,
  17401. ceil_mode: _bool = False,
  17402. ) -> Tensor: ...
  17403. def mkldnn_rnn_layer(
  17404. input: Tensor,
  17405. weight0: Tensor,
  17406. weight1: Tensor,
  17407. weight2: Tensor,
  17408. weight3: Tensor,
  17409. hx_: Tensor,
  17410. cx_: Tensor,
  17411. reverse: _bool,
  17412. batch_sizes: _size,
  17413. mode: _int,
  17414. hidden_size: _int,
  17415. num_layers: _int,
  17416. has_biases: _bool,
  17417. bidirectional: _bool,
  17418. batch_first: _bool,
  17419. train: _bool,
  17420. ) -> tuple[Tensor, Tensor, Tensor, Tensor]: ...
  17421. @overload
  17422. def mm(input: Tensor, mat2: Tensor, *, out: Tensor | None = None) -> Tensor:
  17423. r"""
  17424. mm(input, mat2, out_dtype=None, *, out=None) -> Tensor
  17425. Performs a matrix multiplication of the matrices :attr:`input` and :attr:`mat2`.
  17426. If :attr:`input` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
  17427. :math:`(m \times p)` tensor, :attr:`out` will be a :math:`(n \times p)` tensor.
  17428. .. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
  17429. For broadcasting matrix products, see :func:`torch.matmul`.
  17430. Supports strided and sparse 2-D tensors as inputs, autograd with
  17431. respect to strided inputs.
  17432. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`.
  17433. If :attr:`out` is provided its layout will be used. Otherwise, the result
  17434. layout will be deduced from that of :attr:`input`.
  17435. .. warning::
  17436. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  17437. or may not have autograd support. If you notice missing functionality please
  17438. open a feature request.
  17439. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  17440. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  17441. Args:
  17442. input (Tensor): the first matrix to be matrix multiplied
  17443. mat2 (Tensor): the second matrix to be matrix multiplied
  17444. out_dtype (dtype, optional): the dtype of the output tensor,
  17445. Supported only on CUDA and for torch.float32 given
  17446. torch.float16/torch.bfloat16 input dtypes
  17447. Keyword args:
  17448. out (Tensor, optional): the output tensor.
  17449. Example::
  17450. >>> mat1 = torch.randn(2, 3)
  17451. >>> mat2 = torch.randn(3, 3)
  17452. >>> torch.mm(mat1, mat2)
  17453. tensor([[ 0.4851, 0.5037, -0.3633],
  17454. [-0.0760, -3.6705, 2.4784]])
  17455. """
  17456. @overload
  17457. def mm(
  17458. input: Tensor,
  17459. mat2: Tensor,
  17460. out_dtype: _dtype,
  17461. *,
  17462. out: Tensor | None = None,
  17463. ) -> Tensor:
  17464. r"""
  17465. mm(input, mat2, out_dtype=None, *, out=None) -> Tensor
  17466. Performs a matrix multiplication of the matrices :attr:`input` and :attr:`mat2`.
  17467. If :attr:`input` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
  17468. :math:`(m \times p)` tensor, :attr:`out` will be a :math:`(n \times p)` tensor.
  17469. .. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
  17470. For broadcasting matrix products, see :func:`torch.matmul`.
  17471. Supports strided and sparse 2-D tensors as inputs, autograd with
  17472. respect to strided inputs.
  17473. This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`.
  17474. If :attr:`out` is provided its layout will be used. Otherwise, the result
  17475. layout will be deduced from that of :attr:`input`.
  17476. .. warning::
  17477. Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
  17478. or may not have autograd support. If you notice missing functionality please
  17479. open a feature request.
  17480. This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
  17481. On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
  17482. Args:
  17483. input (Tensor): the first matrix to be matrix multiplied
  17484. mat2 (Tensor): the second matrix to be matrix multiplied
  17485. out_dtype (dtype, optional): the dtype of the output tensor,
  17486. Supported only on CUDA and for torch.float32 given
  17487. torch.float16/torch.bfloat16 input dtypes
  17488. Keyword args:
  17489. out (Tensor, optional): the output tensor.
  17490. Example::
  17491. >>> mat1 = torch.randn(2, 3)
  17492. >>> mat2 = torch.randn(3, 3)
  17493. >>> torch.mm(mat1, mat2)
  17494. tensor([[ 0.4851, 0.5037, -0.3633],
  17495. [-0.0760, -3.6705, 2.4784]])
  17496. """
  17497. @overload
  17498. def mode(
  17499. input: Tensor,
  17500. dim: _int = -1,
  17501. keepdim: _bool = False,
  17502. *,
  17503. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  17504. ) -> torch.return_types.mode:
  17505. r"""
  17506. mode(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  17507. Returns a namedtuple ``(values, indices)`` where ``values`` is the mode
  17508. value of each row of the :attr:`input` tensor in the given dimension
  17509. :attr:`dim`, i.e. a value which appears most often
  17510. in that row, and ``indices`` is the index location of each mode value found.
  17511. By default, :attr:`dim` is the last dimension of the :attr:`input` tensor.
  17512. If :attr:`keepdim` is ``True``, the output tensors are of the same size as
  17513. :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  17514. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting
  17515. in the output tensors having 1 fewer dimension than :attr:`input`.
  17516. Args:
  17517. input (Tensor): the input tensor.
  17518. dim (int, optional): the dimension to reduce.
  17519. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17520. Keyword args:
  17521. out (tuple, optional): the result tuple of two output tensors (values, indices)
  17522. Example::
  17523. >>> b = torch.tensor([[0, 0, 0, 2, 0, 0, 2],
  17524. ... [0, 3, 0, 0, 2, 0, 1],
  17525. ... [2, 2, 2, 0, 0, 0, 3],
  17526. ... [2, 2, 3, 0, 1, 1, 0],
  17527. ... [1, 1, 0, 0, 2, 0, 2]])
  17528. >>> torch.mode(b, 0)
  17529. torch.return_types.mode(
  17530. values=tensor([0, 2, 0, 0, 0, 0, 2]),
  17531. indices=tensor([1, 3, 4, 4, 2, 4, 4]))
  17532. """
  17533. @overload
  17534. def mode(
  17535. input: Tensor,
  17536. dim: str | EllipsisType | None,
  17537. keepdim: _bool = False,
  17538. *,
  17539. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  17540. ) -> torch.return_types.mode:
  17541. r"""
  17542. mode(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  17543. Returns a namedtuple ``(values, indices)`` where ``values`` is the mode
  17544. value of each row of the :attr:`input` tensor in the given dimension
  17545. :attr:`dim`, i.e. a value which appears most often
  17546. in that row, and ``indices`` is the index location of each mode value found.
  17547. By default, :attr:`dim` is the last dimension of the :attr:`input` tensor.
  17548. If :attr:`keepdim` is ``True``, the output tensors are of the same size as
  17549. :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
  17550. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting
  17551. in the output tensors having 1 fewer dimension than :attr:`input`.
  17552. Args:
  17553. input (Tensor): the input tensor.
  17554. dim (int, optional): the dimension to reduce.
  17555. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17556. Keyword args:
  17557. out (tuple, optional): the result tuple of two output tensors (values, indices)
  17558. Example::
  17559. >>> b = torch.tensor([[0, 0, 0, 2, 0, 0, 2],
  17560. ... [0, 3, 0, 0, 2, 0, 1],
  17561. ... [2, 2, 2, 0, 0, 0, 3],
  17562. ... [2, 2, 3, 0, 1, 1, 0],
  17563. ... [1, 1, 0, 0, 2, 0, 2]])
  17564. >>> torch.mode(b, 0)
  17565. torch.return_types.mode(
  17566. values=tensor([0, 2, 0, 0, 0, 0, 2]),
  17567. indices=tensor([1, 3, 4, 4, 2, 4, 4]))
  17568. """
  17569. @overload
  17570. def moveaxis(input: Tensor, source: _int, destination: _int) -> Tensor:
  17571. r"""
  17572. moveaxis(input, source, destination) -> Tensor
  17573. Alias for :func:`torch.movedim`.
  17574. This function is equivalent to NumPy's moveaxis function.
  17575. Examples::
  17576. >>> t = torch.randn(3,2,1)
  17577. >>> t
  17578. tensor([[[-0.3362],
  17579. [-0.8437]],
  17580. [[-0.9627],
  17581. [ 0.1727]],
  17582. [[ 0.5173],
  17583. [-0.1398]]])
  17584. >>> torch.moveaxis(t, 1, 0).shape
  17585. torch.Size([2, 3, 1])
  17586. >>> torch.moveaxis(t, 1, 0)
  17587. tensor([[[-0.3362],
  17588. [-0.9627],
  17589. [ 0.5173]],
  17590. [[-0.8437],
  17591. [ 0.1727],
  17592. [-0.1398]]])
  17593. >>> torch.moveaxis(t, (1, 2), (0, 1)).shape
  17594. torch.Size([2, 1, 3])
  17595. >>> torch.moveaxis(t, (1, 2), (0, 1))
  17596. tensor([[[-0.3362, -0.9627, 0.5173]],
  17597. [[-0.8437, 0.1727, -0.1398]]])
  17598. """
  17599. @overload
  17600. def moveaxis(input: Tensor, source: _size, destination: _size) -> Tensor:
  17601. r"""
  17602. moveaxis(input, source, destination) -> Tensor
  17603. Alias for :func:`torch.movedim`.
  17604. This function is equivalent to NumPy's moveaxis function.
  17605. Examples::
  17606. >>> t = torch.randn(3,2,1)
  17607. >>> t
  17608. tensor([[[-0.3362],
  17609. [-0.8437]],
  17610. [[-0.9627],
  17611. [ 0.1727]],
  17612. [[ 0.5173],
  17613. [-0.1398]]])
  17614. >>> torch.moveaxis(t, 1, 0).shape
  17615. torch.Size([2, 3, 1])
  17616. >>> torch.moveaxis(t, 1, 0)
  17617. tensor([[[-0.3362],
  17618. [-0.9627],
  17619. [ 0.5173]],
  17620. [[-0.8437],
  17621. [ 0.1727],
  17622. [-0.1398]]])
  17623. >>> torch.moveaxis(t, (1, 2), (0, 1)).shape
  17624. torch.Size([2, 1, 3])
  17625. >>> torch.moveaxis(t, (1, 2), (0, 1))
  17626. tensor([[[-0.3362, -0.9627, 0.5173]],
  17627. [[-0.8437, 0.1727, -0.1398]]])
  17628. """
  17629. @overload
  17630. def movedim(input: Tensor, source: _int, destination: _int) -> Tensor:
  17631. r"""
  17632. movedim(input, source, destination) -> Tensor
  17633. Moves the dimension(s) of :attr:`input` at the position(s) in :attr:`source`
  17634. to the position(s) in :attr:`destination`.
  17635. Other dimensions of :attr:`input` that are not explicitly moved remain in
  17636. their original order and appear at the positions not specified in :attr:`destination`.
  17637. Args:
  17638. input (Tensor): the input tensor.
  17639. source (int or tuple of ints): Original positions of the dims to move. These must be unique.
  17640. destination (int or tuple of ints): Destination positions for each of the original dims. These must also be unique.
  17641. Examples::
  17642. >>> t = torch.randn(3,2,1)
  17643. >>> t
  17644. tensor([[[-0.3362],
  17645. [-0.8437]],
  17646. [[-0.9627],
  17647. [ 0.1727]],
  17648. [[ 0.5173],
  17649. [-0.1398]]])
  17650. >>> torch.movedim(t, 1, 0).shape
  17651. torch.Size([2, 3, 1])
  17652. >>> torch.movedim(t, 1, 0)
  17653. tensor([[[-0.3362],
  17654. [-0.9627],
  17655. [ 0.5173]],
  17656. [[-0.8437],
  17657. [ 0.1727],
  17658. [-0.1398]]])
  17659. >>> torch.movedim(t, (1, 2), (0, 1)).shape
  17660. torch.Size([2, 1, 3])
  17661. >>> torch.movedim(t, (1, 2), (0, 1))
  17662. tensor([[[-0.3362, -0.9627, 0.5173]],
  17663. [[-0.8437, 0.1727, -0.1398]]])
  17664. """
  17665. @overload
  17666. def movedim(input: Tensor, source: _size, destination: _size) -> Tensor:
  17667. r"""
  17668. movedim(input, source, destination) -> Tensor
  17669. Moves the dimension(s) of :attr:`input` at the position(s) in :attr:`source`
  17670. to the position(s) in :attr:`destination`.
  17671. Other dimensions of :attr:`input` that are not explicitly moved remain in
  17672. their original order and appear at the positions not specified in :attr:`destination`.
  17673. Args:
  17674. input (Tensor): the input tensor.
  17675. source (int or tuple of ints): Original positions of the dims to move. These must be unique.
  17676. destination (int or tuple of ints): Destination positions for each of the original dims. These must also be unique.
  17677. Examples::
  17678. >>> t = torch.randn(3,2,1)
  17679. >>> t
  17680. tensor([[[-0.3362],
  17681. [-0.8437]],
  17682. [[-0.9627],
  17683. [ 0.1727]],
  17684. [[ 0.5173],
  17685. [-0.1398]]])
  17686. >>> torch.movedim(t, 1, 0).shape
  17687. torch.Size([2, 3, 1])
  17688. >>> torch.movedim(t, 1, 0)
  17689. tensor([[[-0.3362],
  17690. [-0.9627],
  17691. [ 0.5173]],
  17692. [[-0.8437],
  17693. [ 0.1727],
  17694. [-0.1398]]])
  17695. >>> torch.movedim(t, (1, 2), (0, 1)).shape
  17696. torch.Size([2, 1, 3])
  17697. >>> torch.movedim(t, (1, 2), (0, 1))
  17698. tensor([[[-0.3362, -0.9627, 0.5173]],
  17699. [[-0.8437, 0.1727, -0.1398]]])
  17700. """
  17701. def msort(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  17702. r"""
  17703. msort(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  17704. Sorts the elements of the :attr:`input` tensor along its first dimension
  17705. in ascending order by value.
  17706. .. note:: `torch.msort(t)` is equivalent to `torch.sort(t, dim=0)[0]`.
  17707. See also :func:`torch.sort`.
  17708. Args:
  17709. input (Tensor): the input tensor.
  17710. Keyword args:
  17711. out (Tensor, optional): the output tensor.
  17712. Example::
  17713. >>> t = torch.randn(3, 4)
  17714. >>> t
  17715. tensor([[-0.1321, 0.4370, -1.2631, -1.1289],
  17716. [-2.0527, -1.1250, 0.2275, 0.3077],
  17717. [-0.0881, -0.1259, -0.5495, 1.0284]])
  17718. >>> torch.msort(t)
  17719. tensor([[-2.0527, -1.1250, -1.2631, -1.1289],
  17720. [-0.1321, -0.1259, -0.5495, 0.3077],
  17721. [-0.0881, 0.4370, 0.2275, 1.0284]])
  17722. """
  17723. def mul(
  17724. input: Tensor | Number | _complex,
  17725. other: Tensor | Number | _complex,
  17726. *,
  17727. out: Tensor | None = None,
  17728. ) -> Tensor:
  17729. r"""
  17730. mul(input, other, *, out=None) -> Tensor
  17731. Multiplies :attr:`input` by :attr:`other`.
  17732. .. math::
  17733. \text{out}_i = \text{input}_i \times \text{other}_i
  17734. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  17735. :ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
  17736. Args:
  17737. input (Tensor): the input tensor.
  17738. other (Tensor or Number): the tensor or number to multiply input by.
  17739. Keyword args:
  17740. out (Tensor, optional): the output tensor.
  17741. Examples::
  17742. >>> a = torch.randn(3)
  17743. >>> a
  17744. tensor([ 0.2015, -0.4255, 2.6087])
  17745. >>> torch.mul(a, 100)
  17746. tensor([ 20.1494, -42.5491, 260.8663])
  17747. >>> b = torch.randn(4, 1)
  17748. >>> b
  17749. tensor([[ 1.1207],
  17750. [-0.3137],
  17751. [ 0.0700],
  17752. [ 0.8378]])
  17753. >>> c = torch.randn(1, 4)
  17754. >>> c
  17755. tensor([[ 0.5146, 0.1216, -0.5244, 2.2382]])
  17756. >>> torch.mul(b, c)
  17757. tensor([[ 0.5767, 0.1363, -0.5877, 2.5083],
  17758. [-0.1614, -0.0382, 0.1645, -0.7021],
  17759. [ 0.0360, 0.0085, -0.0367, 0.1567],
  17760. [ 0.4312, 0.1019, -0.4394, 1.8753]])
  17761. """
  17762. def multinomial(
  17763. input: Tensor,
  17764. num_samples: _int | SymInt,
  17765. replacement: _bool = False,
  17766. *,
  17767. generator: Generator | None = None,
  17768. out: Tensor | None = None,
  17769. ) -> Tensor:
  17770. r"""
  17771. multinomial(input, num_samples, replacement=False, *, generator=None, out=None) -> LongTensor
  17772. Returns a tensor where each row contains :attr:`num_samples` indices sampled
  17773. from the multinomial (a stricter definition would be multivariate,
  17774. refer to :class:`torch.distributions.multinomial.Multinomial` for more details)
  17775. probability distribution located in the corresponding row
  17776. of tensor :attr:`input`.
  17777. .. note::
  17778. The rows of :attr:`input` do not need to sum to one (in which case we use
  17779. the values as weights), but must be non-negative, finite and have
  17780. a non-zero sum.
  17781. Indices are ordered from left to right according to when each was sampled
  17782. (first samples are placed in first column).
  17783. If :attr:`input` is a vector, :attr:`out` is a vector of size :attr:`num_samples`.
  17784. If :attr:`input` is a matrix with `m` rows, :attr:`out` is an matrix of shape
  17785. :math:`(m \times \text{num\_samples})`.
  17786. If replacement is ``True``, samples are drawn with replacement.
  17787. If not, they are drawn without replacement, which means that when a
  17788. sample index is drawn for a row, it cannot be drawn again for that row.
  17789. .. note::
  17790. When drawn without replacement, :attr:`num_samples` must be lower than
  17791. number of non-zero elements in :attr:`input` (or the min number of non-zero
  17792. elements in each row of :attr:`input` if it is a matrix).
  17793. Args:
  17794. input (Tensor): the input tensor containing probabilities
  17795. num_samples (int): number of samples to draw
  17796. replacement (bool, optional): whether to draw with replacement or not
  17797. Keyword args:
  17798. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  17799. out (Tensor, optional): the output tensor.
  17800. Example::
  17801. >>> weights = torch.tensor([0, 10, 3, 0], dtype=torch.float) # create a tensor of weights
  17802. >>> torch.multinomial(weights, 2)
  17803. tensor([1, 2])
  17804. >>> torch.multinomial(weights, 5) # ERROR!
  17805. RuntimeError: cannot sample n_sample > prob_dist.size(-1) samples without replacement
  17806. >>> torch.multinomial(weights, 4, replacement=True)
  17807. tensor([ 2, 1, 1, 1])
  17808. """
  17809. @overload
  17810. def multiply(
  17811. input: Tensor,
  17812. other: Tensor,
  17813. *,
  17814. out: Tensor | None = None,
  17815. ) -> Tensor:
  17816. r"""
  17817. multiply(input, other, *, out=None)
  17818. Alias for :func:`torch.mul`.
  17819. """
  17820. @overload
  17821. def multiply(input: Tensor, other: Number | _complex) -> Tensor:
  17822. r"""
  17823. multiply(input, other, *, out=None)
  17824. Alias for :func:`torch.mul`.
  17825. """
  17826. def mv(input: Tensor, vec: Tensor, *, out: Tensor | None = None) -> Tensor:
  17827. r"""
  17828. mv(input, vec, *, out=None) -> Tensor
  17829. Performs a matrix-vector product of the matrix :attr:`input` and the vector
  17830. :attr:`vec`.
  17831. If :attr:`input` is a :math:`(n \times m)` tensor, :attr:`vec` is a 1-D tensor of
  17832. size :math:`m`, :attr:`out` will be 1-D of size :math:`n`.
  17833. .. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
  17834. Args:
  17835. input (Tensor): matrix to be multiplied
  17836. vec (Tensor): vector to be multiplied
  17837. Keyword args:
  17838. out (Tensor, optional): the output tensor.
  17839. Example::
  17840. >>> mat = torch.randn(2, 3)
  17841. >>> vec = torch.randn(3)
  17842. >>> torch.mv(mat, vec)
  17843. tensor([ 1.0404, -0.6361])
  17844. """
  17845. def mvlgamma(
  17846. input: Tensor,
  17847. p: _int,
  17848. *,
  17849. out: Tensor | None = None,
  17850. ) -> Tensor:
  17851. r"""
  17852. mvlgamma(input, p, *, out=None) -> Tensor
  17853. Alias for :func:`torch.special.multigammaln`.
  17854. """
  17855. def nan_to_num(
  17856. input: Tensor,
  17857. nan: _float | None = None,
  17858. posinf: _float | None = None,
  17859. neginf: _float | None = None,
  17860. *,
  17861. out: Tensor | None = None,
  17862. ) -> Tensor:
  17863. r"""
  17864. nan_to_num(input, nan=0.0, posinf=None, neginf=None, *, out=None) -> Tensor
  17865. Replaces :literal:`NaN`, positive infinity, and negative infinity values in :attr:`input`
  17866. with the values specified by :attr:`nan`, :attr:`posinf`, and :attr:`neginf`, respectively.
  17867. By default, :literal:`NaN`\ s are replaced with zero, positive infinity is replaced with the
  17868. greatest finite value representable by :attr:`input`'s dtype, and negative infinity
  17869. is replaced with the least finite value representable by :attr:`input`'s dtype.
  17870. Args:
  17871. input (Tensor): the input tensor.
  17872. nan (Number, optional): the value to replace :literal:`NaN`\s with. Default is zero.
  17873. posinf (Number, optional): if a Number, the value to replace positive infinity values with.
  17874. If None, positive infinity values are replaced with the greatest finite value representable by :attr:`input`'s dtype.
  17875. Default is None.
  17876. neginf (Number, optional): if a Number, the value to replace negative infinity values with.
  17877. If None, negative infinity values are replaced with the lowest finite value representable by :attr:`input`'s dtype.
  17878. Default is None.
  17879. Keyword args:
  17880. out (Tensor, optional): the output tensor.
  17881. Example::
  17882. >>> x = torch.tensor([float('nan'), float('inf'), -float('inf'), 3.14])
  17883. >>> torch.nan_to_num(x)
  17884. tensor([ 0.0000e+00, 3.4028e+38, -3.4028e+38, 3.1400e+00])
  17885. >>> torch.nan_to_num(x, nan=2.0)
  17886. tensor([ 2.0000e+00, 3.4028e+38, -3.4028e+38, 3.1400e+00])
  17887. >>> torch.nan_to_num(x, nan=2.0, posinf=1.0)
  17888. tensor([ 2.0000e+00, 1.0000e+00, -3.4028e+38, 3.1400e+00])
  17889. """
  17890. def nan_to_num_(
  17891. input: Tensor,
  17892. nan: _float | None = None,
  17893. posinf: _float | None = None,
  17894. neginf: _float | None = None,
  17895. ) -> Tensor: ...
  17896. def nanmean(
  17897. input: Tensor,
  17898. dim: _int | _size | None = None,
  17899. keepdim: _bool = False,
  17900. *,
  17901. dtype: _dtype | None = None,
  17902. out: Tensor | None = None,
  17903. ) -> Tensor:
  17904. r"""
  17905. nanmean(input, dim=None, keepdim=False, *, dtype=None, out=None) -> Tensor
  17906. Computes the mean of all `non-NaN` elements along the specified dimensions.
  17907. Input must be floating point or complex.
  17908. This function is identical to :func:`torch.mean` when there are no `NaN` values
  17909. in the :attr:`input` tensor. In the presence of `NaN`, :func:`torch.mean` will
  17910. propagate the `NaN` to the output whereas :func:`torch.nanmean` will ignore the
  17911. `NaN` values (`torch.nanmean(a)` is equivalent to `torch.mean(a[~a.isnan()])`).
  17912. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  17913. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  17914. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  17915. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  17916. Args:
  17917. input (Tensor): the input tensor, either of floating point or complex dtype
  17918. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  17919. If ``None``, all dimensions are reduced.
  17920. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17921. Keyword args:
  17922. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  17923. If specified, the input tensor is casted to :attr:`dtype` before the operation
  17924. is performed. This is useful for preventing data type overflows. Default: None.
  17925. out (Tensor, optional): the output tensor.
  17926. .. seealso::
  17927. :func:`torch.mean` computes the mean value, propagating `NaN`.
  17928. Example::
  17929. >>> x = torch.tensor([[torch.nan, 1, 2], [1, 2, 3]])
  17930. >>> x.mean()
  17931. tensor(nan)
  17932. >>> x.nanmean()
  17933. tensor(1.8000)
  17934. >>> x.mean(dim=0)
  17935. tensor([ nan, 1.5000, 2.5000])
  17936. >>> x.nanmean(dim=0)
  17937. tensor([1.0000, 1.5000, 2.5000])
  17938. # If all elements in the reduced dimensions are NaN then the result is NaN
  17939. >>> torch.tensor([torch.nan]).nanmean()
  17940. tensor(nan)
  17941. """
  17942. @overload
  17943. def nanmedian(input: Tensor) -> Tensor:
  17944. r"""
  17945. nanmedian(input) -> Tensor
  17946. Returns the median of the values in :attr:`input`, ignoring ``NaN`` values.
  17947. This function is identical to :func:`torch.median` when there are no ``NaN`` values in :attr:`input`.
  17948. When :attr:`input` has one or more ``NaN`` values, :func:`torch.median` will always return ``NaN``,
  17949. while this function will return the median of the non-``NaN`` elements in :attr:`input`.
  17950. If all the elements in :attr:`input` are ``NaN`` it will also return ``NaN``.
  17951. Args:
  17952. input (Tensor): the input tensor.
  17953. Example::
  17954. >>> a = torch.tensor([1, float('nan'), 3, 2])
  17955. >>> a.median()
  17956. tensor(nan)
  17957. >>> a.nanmedian()
  17958. tensor(2.)
  17959. .. function:: nanmedian(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  17960. :noindex:
  17961. Returns a namedtuple ``(values, indices)`` where ``values`` contains the median of each row of :attr:`input`
  17962. in the dimension :attr:`dim`, ignoring ``NaN`` values, and ``indices`` contains the index of the median values
  17963. found in the dimension :attr:`dim`.
  17964. This function is identical to :func:`torch.median` when there are no ``NaN`` values in a reduced row. When a reduced row has
  17965. one or more ``NaN`` values, :func:`torch.median` will always reduce it to ``NaN``, while this function will reduce it to the
  17966. median of the non-``NaN`` elements. If all the elements in a reduced row are ``NaN`` then it will be reduced to ``NaN``, too.
  17967. Args:
  17968. input (Tensor): the input tensor.
  17969. dim (int, optional): the dimension to reduce.
  17970. If ``None``, all dimensions are reduced.
  17971. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  17972. Keyword args:
  17973. out ((Tensor, Tensor), optional): The first tensor will be populated with the median values and the second
  17974. tensor, which must have dtype long, with their indices in the dimension
  17975. :attr:`dim` of :attr:`input`.
  17976. Example::
  17977. >>> a = torch.tensor([[2, 3, 1], [float('nan'), 1, float('nan')]])
  17978. >>> a
  17979. tensor([[2., 3., 1.],
  17980. [nan, 1., nan]])
  17981. >>> a.median(0)
  17982. torch.return_types.median(values=tensor([nan, 1., nan]), indices=tensor([1, 1, 1]))
  17983. >>> a.nanmedian(0)
  17984. torch.return_types.nanmedian(values=tensor([2., 1., 1.]), indices=tensor([0, 1, 0]))
  17985. """
  17986. @overload
  17987. def nanmedian(
  17988. input: Tensor,
  17989. dim: _int,
  17990. keepdim: _bool = False,
  17991. *,
  17992. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  17993. ) -> torch.return_types.nanmedian:
  17994. r"""
  17995. nanmedian(input) -> Tensor
  17996. Returns the median of the values in :attr:`input`, ignoring ``NaN`` values.
  17997. This function is identical to :func:`torch.median` when there are no ``NaN`` values in :attr:`input`.
  17998. When :attr:`input` has one or more ``NaN`` values, :func:`torch.median` will always return ``NaN``,
  17999. while this function will return the median of the non-``NaN`` elements in :attr:`input`.
  18000. If all the elements in :attr:`input` are ``NaN`` it will also return ``NaN``.
  18001. Args:
  18002. input (Tensor): the input tensor.
  18003. Example::
  18004. >>> a = torch.tensor([1, float('nan'), 3, 2])
  18005. >>> a.median()
  18006. tensor(nan)
  18007. >>> a.nanmedian()
  18008. tensor(2.)
  18009. .. function:: nanmedian(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  18010. :noindex:
  18011. Returns a namedtuple ``(values, indices)`` where ``values`` contains the median of each row of :attr:`input`
  18012. in the dimension :attr:`dim`, ignoring ``NaN`` values, and ``indices`` contains the index of the median values
  18013. found in the dimension :attr:`dim`.
  18014. This function is identical to :func:`torch.median` when there are no ``NaN`` values in a reduced row. When a reduced row has
  18015. one or more ``NaN`` values, :func:`torch.median` will always reduce it to ``NaN``, while this function will reduce it to the
  18016. median of the non-``NaN`` elements. If all the elements in a reduced row are ``NaN`` then it will be reduced to ``NaN``, too.
  18017. Args:
  18018. input (Tensor): the input tensor.
  18019. dim (int, optional): the dimension to reduce.
  18020. If ``None``, all dimensions are reduced.
  18021. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  18022. Keyword args:
  18023. out ((Tensor, Tensor), optional): The first tensor will be populated with the median values and the second
  18024. tensor, which must have dtype long, with their indices in the dimension
  18025. :attr:`dim` of :attr:`input`.
  18026. Example::
  18027. >>> a = torch.tensor([[2, 3, 1], [float('nan'), 1, float('nan')]])
  18028. >>> a
  18029. tensor([[2., 3., 1.],
  18030. [nan, 1., nan]])
  18031. >>> a.median(0)
  18032. torch.return_types.median(values=tensor([nan, 1., nan]), indices=tensor([1, 1, 1]))
  18033. >>> a.nanmedian(0)
  18034. torch.return_types.nanmedian(values=tensor([2., 1., 1.]), indices=tensor([0, 1, 0]))
  18035. """
  18036. @overload
  18037. def nanmedian(
  18038. input: Tensor,
  18039. dim: str | EllipsisType | None,
  18040. keepdim: _bool = False,
  18041. *,
  18042. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  18043. ) -> torch.return_types.nanmedian:
  18044. r"""
  18045. nanmedian(input) -> Tensor
  18046. Returns the median of the values in :attr:`input`, ignoring ``NaN`` values.
  18047. This function is identical to :func:`torch.median` when there are no ``NaN`` values in :attr:`input`.
  18048. When :attr:`input` has one or more ``NaN`` values, :func:`torch.median` will always return ``NaN``,
  18049. while this function will return the median of the non-``NaN`` elements in :attr:`input`.
  18050. If all the elements in :attr:`input` are ``NaN`` it will also return ``NaN``.
  18051. Args:
  18052. input (Tensor): the input tensor.
  18053. Example::
  18054. >>> a = torch.tensor([1, float('nan'), 3, 2])
  18055. >>> a.median()
  18056. tensor(nan)
  18057. >>> a.nanmedian()
  18058. tensor(2.)
  18059. .. function:: nanmedian(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
  18060. :noindex:
  18061. Returns a namedtuple ``(values, indices)`` where ``values`` contains the median of each row of :attr:`input`
  18062. in the dimension :attr:`dim`, ignoring ``NaN`` values, and ``indices`` contains the index of the median values
  18063. found in the dimension :attr:`dim`.
  18064. This function is identical to :func:`torch.median` when there are no ``NaN`` values in a reduced row. When a reduced row has
  18065. one or more ``NaN`` values, :func:`torch.median` will always reduce it to ``NaN``, while this function will reduce it to the
  18066. median of the non-``NaN`` elements. If all the elements in a reduced row are ``NaN`` then it will be reduced to ``NaN``, too.
  18067. Args:
  18068. input (Tensor): the input tensor.
  18069. dim (int, optional): the dimension to reduce.
  18070. If ``None``, all dimensions are reduced.
  18071. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  18072. Keyword args:
  18073. out ((Tensor, Tensor), optional): The first tensor will be populated with the median values and the second
  18074. tensor, which must have dtype long, with their indices in the dimension
  18075. :attr:`dim` of :attr:`input`.
  18076. Example::
  18077. >>> a = torch.tensor([[2, 3, 1], [float('nan'), 1, float('nan')]])
  18078. >>> a
  18079. tensor([[2., 3., 1.],
  18080. [nan, 1., nan]])
  18081. >>> a.median(0)
  18082. torch.return_types.median(values=tensor([nan, 1., nan]), indices=tensor([1, 1, 1]))
  18083. >>> a.nanmedian(0)
  18084. torch.return_types.nanmedian(values=tensor([2., 1., 1.]), indices=tensor([0, 1, 0]))
  18085. """
  18086. @overload
  18087. def nanquantile(
  18088. input: Tensor,
  18089. q: Tensor,
  18090. dim: _int | None = None,
  18091. keepdim: _bool = False,
  18092. *,
  18093. interpolation: str = "linear",
  18094. out: Tensor | None = None,
  18095. ) -> Tensor:
  18096. r"""
  18097. nanquantile(input, q, dim=None, keepdim=False, *, interpolation='linear', out=None) -> Tensor
  18098. This is a variant of :func:`torch.quantile` that "ignores" ``NaN`` values,
  18099. computing the quantiles :attr:`q` as if ``NaN`` values in :attr:`input` did
  18100. not exist. If all values in a reduced row are ``NaN`` then the quantiles for
  18101. that reduction will be ``NaN``. See the documentation for :func:`torch.quantile`.
  18102. Args:
  18103. input (Tensor): the input tensor.
  18104. q (float or Tensor): a scalar or 1D tensor of quantile values in the range [0, 1]
  18105. dim (int, optional): the dimension to reduce.
  18106. If ``None``, all dimensions are reduced.
  18107. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  18108. Keyword arguments:
  18109. interpolation (str): interpolation method to use when the desired quantile lies between two data points.
  18110. Can be ``linear``, ``lower``, ``higher``, ``midpoint`` and ``nearest``.
  18111. Default is ``linear``.
  18112. out (Tensor, optional): the output tensor.
  18113. Example::
  18114. >>> t = torch.tensor([float('nan'), 1, 2])
  18115. >>> t.quantile(0.5)
  18116. tensor(nan)
  18117. >>> t.nanquantile(0.5)
  18118. tensor(1.5000)
  18119. >>> t = torch.tensor([[float('nan'), float('nan')], [1, 2]])
  18120. >>> t
  18121. tensor([[nan, nan],
  18122. [1., 2.]])
  18123. >>> t.nanquantile(0.5, dim=0)
  18124. tensor([1., 2.])
  18125. >>> t.nanquantile(0.5, dim=1)
  18126. tensor([ nan, 1.5000])
  18127. """
  18128. @overload
  18129. def nanquantile(
  18130. input: Tensor,
  18131. q: _float,
  18132. dim: _int | None = None,
  18133. keepdim: _bool = False,
  18134. *,
  18135. interpolation: str = "linear",
  18136. out: Tensor | None = None,
  18137. ) -> Tensor:
  18138. r"""
  18139. nanquantile(input, q, dim=None, keepdim=False, *, interpolation='linear', out=None) -> Tensor
  18140. This is a variant of :func:`torch.quantile` that "ignores" ``NaN`` values,
  18141. computing the quantiles :attr:`q` as if ``NaN`` values in :attr:`input` did
  18142. not exist. If all values in a reduced row are ``NaN`` then the quantiles for
  18143. that reduction will be ``NaN``. See the documentation for :func:`torch.quantile`.
  18144. Args:
  18145. input (Tensor): the input tensor.
  18146. q (float or Tensor): a scalar or 1D tensor of quantile values in the range [0, 1]
  18147. dim (int, optional): the dimension to reduce.
  18148. If ``None``, all dimensions are reduced.
  18149. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  18150. Keyword arguments:
  18151. interpolation (str): interpolation method to use when the desired quantile lies between two data points.
  18152. Can be ``linear``, ``lower``, ``higher``, ``midpoint`` and ``nearest``.
  18153. Default is ``linear``.
  18154. out (Tensor, optional): the output tensor.
  18155. Example::
  18156. >>> t = torch.tensor([float('nan'), 1, 2])
  18157. >>> t.quantile(0.5)
  18158. tensor(nan)
  18159. >>> t.nanquantile(0.5)
  18160. tensor(1.5000)
  18161. >>> t = torch.tensor([[float('nan'), float('nan')], [1, 2]])
  18162. >>> t
  18163. tensor([[nan, nan],
  18164. [1., 2.]])
  18165. >>> t.nanquantile(0.5, dim=0)
  18166. tensor([1., 2.])
  18167. >>> t.nanquantile(0.5, dim=1)
  18168. tensor([ nan, 1.5000])
  18169. """
  18170. def nansum(
  18171. input: Tensor,
  18172. dim: _int | _size | None = None,
  18173. keepdim: _bool = False,
  18174. *,
  18175. dtype: _dtype | None = None,
  18176. out: Tensor | None = None,
  18177. ) -> Tensor:
  18178. r"""
  18179. nansum(input, *, dtype=None) -> Tensor
  18180. Returns the sum of all elements, treating Not a Numbers (NaNs) as zero.
  18181. Args:
  18182. input (Tensor): the input tensor.
  18183. Keyword args:
  18184. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  18185. If specified, the input tensor is casted to :attr:`dtype` before the operation
  18186. is performed. This is useful for preventing data type overflows. Default: None.
  18187. Example::
  18188. >>> a = torch.tensor([1., 2., float('nan'), 4.])
  18189. >>> torch.nansum(a)
  18190. tensor(7.)
  18191. .. function:: nansum(input, dim, keepdim=False, *, dtype=None) -> Tensor
  18192. :noindex:
  18193. Returns the sum of each row of the :attr:`input` tensor in the given
  18194. dimension :attr:`dim`, treating Not a Numbers (NaNs) as zero.
  18195. If :attr:`dim` is a list of dimensions, reduce over all of them.
  18196. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  18197. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  18198. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  18199. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  18200. Args:
  18201. input (Tensor): the input tensor.
  18202. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  18203. If ``None``, all dimensions are reduced.
  18204. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  18205. Keyword args:
  18206. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  18207. If specified, the input tensor is casted to :attr:`dtype` before the operation
  18208. is performed. This is useful for preventing data type overflows. Default: None.
  18209. Example::
  18210. >>> torch.nansum(torch.tensor([1., float("nan")]))
  18211. tensor(1.)
  18212. >>> a = torch.tensor([[1, 2], [3., float("nan")]])
  18213. >>> torch.nansum(a)
  18214. tensor(6.)
  18215. >>> torch.nansum(a, dim=0)
  18216. tensor([4., 2.])
  18217. >>> torch.nansum(a, dim=1)
  18218. tensor([3., 3.])
  18219. """
  18220. @overload
  18221. def narrow(
  18222. input: Tensor,
  18223. dim: _int,
  18224. start: Tensor,
  18225. length: _int | SymInt,
  18226. ) -> Tensor:
  18227. r"""
  18228. narrow(input, dim, start, length) -> Tensor
  18229. Returns a new tensor that is a narrowed version of :attr:`input` tensor. The
  18230. dimension :attr:`dim` is input from :attr:`start` to ``start + length``. The
  18231. returned tensor and :attr:`input` tensor share the same underlying storage.
  18232. Args:
  18233. input (Tensor): the tensor to narrow
  18234. dim (int): the dimension along which to narrow
  18235. start (int or Tensor): index of the element to start the narrowed dimension
  18236. from. Can be negative, which means indexing from the end of `dim`. If
  18237. `Tensor`, it must be an 0-dim integral `Tensor` (bools not allowed)
  18238. length (int): length of the narrowed dimension, must be weakly positive
  18239. Example::
  18240. >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
  18241. >>> torch.narrow(x, 0, 0, 2)
  18242. tensor([[ 1, 2, 3],
  18243. [ 4, 5, 6]])
  18244. >>> torch.narrow(x, 1, 1, 2)
  18245. tensor([[ 2, 3],
  18246. [ 5, 6],
  18247. [ 8, 9]])
  18248. >>> torch.narrow(x, -1, torch.tensor(-1), 1)
  18249. tensor([[3],
  18250. [6],
  18251. [9]])
  18252. """
  18253. @overload
  18254. def narrow(
  18255. input: Tensor,
  18256. dim: _int,
  18257. start: _int | SymInt,
  18258. length: _int | SymInt,
  18259. ) -> Tensor:
  18260. r"""
  18261. narrow(input, dim, start, length) -> Tensor
  18262. Returns a new tensor that is a narrowed version of :attr:`input` tensor. The
  18263. dimension :attr:`dim` is input from :attr:`start` to ``start + length``. The
  18264. returned tensor and :attr:`input` tensor share the same underlying storage.
  18265. Args:
  18266. input (Tensor): the tensor to narrow
  18267. dim (int): the dimension along which to narrow
  18268. start (int or Tensor): index of the element to start the narrowed dimension
  18269. from. Can be negative, which means indexing from the end of `dim`. If
  18270. `Tensor`, it must be an 0-dim integral `Tensor` (bools not allowed)
  18271. length (int): length of the narrowed dimension, must be weakly positive
  18272. Example::
  18273. >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
  18274. >>> torch.narrow(x, 0, 0, 2)
  18275. tensor([[ 1, 2, 3],
  18276. [ 4, 5, 6]])
  18277. >>> torch.narrow(x, 1, 1, 2)
  18278. tensor([[ 2, 3],
  18279. [ 5, 6],
  18280. [ 8, 9]])
  18281. >>> torch.narrow(x, -1, torch.tensor(-1), 1)
  18282. tensor([[3],
  18283. [6],
  18284. [9]])
  18285. """
  18286. def narrow_copy(
  18287. input: Tensor,
  18288. dim: _int,
  18289. start: _int | SymInt,
  18290. length: _int | SymInt,
  18291. *,
  18292. out: Tensor | None = None,
  18293. ) -> Tensor:
  18294. r"""
  18295. narrow_copy(input, dim, start, length, *, out=None) -> Tensor
  18296. Same as :meth:`Tensor.narrow` except this returns a copy rather
  18297. than shared storage. This is primarily for sparse tensors, which
  18298. do not have a shared-storage narrow method.
  18299. Args:
  18300. input (Tensor): the tensor to narrow
  18301. dim (int): the dimension along which to narrow
  18302. start (int): index of the element to start the narrowed dimension from. Can
  18303. be negative, which means indexing from the end of `dim`
  18304. length (int): length of the narrowed dimension, must be weakly positive
  18305. Keyword args:
  18306. out (Tensor, optional): the output tensor.
  18307. Example::
  18308. >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
  18309. >>> torch.narrow_copy(x, 0, 0, 2)
  18310. tensor([[ 1, 2, 3],
  18311. [ 4, 5, 6]])
  18312. >>> torch.narrow_copy(x, 1, 1, 2)
  18313. tensor([[ 2, 3],
  18314. [ 5, 6],
  18315. [ 8, 9]])
  18316. >>> s = torch.arange(16).reshape(2, 2, 2, 2).to_sparse(2)
  18317. >>> torch.narrow_copy(s, 0, 0, 1)
  18318. tensor(indices=tensor([[0, 0],
  18319. [0, 1]]),
  18320. values=tensor([[[0, 1],
  18321. [2, 3]],
  18322. [[4, 5],
  18323. [6, 7]]]),
  18324. size=(1, 2, 2, 2), nnz=2, layout=torch.sparse_coo)
  18325. .. seealso::
  18326. :func:`torch.narrow` for a non copy variant
  18327. """
  18328. def native_batch_norm(
  18329. input: Tensor,
  18330. weight: Tensor | None,
  18331. bias: Tensor | None,
  18332. running_mean: Tensor | None,
  18333. running_var: Tensor | None,
  18334. training: _bool,
  18335. momentum: _float,
  18336. eps: _float,
  18337. *,
  18338. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  18339. ) -> tuple[Tensor, Tensor, Tensor]: ...
  18340. def native_channel_shuffle(input: Tensor, groups: _int | SymInt) -> Tensor: ...
  18341. def native_dropout(
  18342. input: Tensor,
  18343. p: _float,
  18344. train: _bool | None,
  18345. ) -> tuple[Tensor, Tensor]: ...
  18346. def native_group_norm(
  18347. input: Tensor,
  18348. weight: Tensor | None,
  18349. bias: Tensor | None,
  18350. N: _int | SymInt,
  18351. C: _int | SymInt,
  18352. HxW: _int | SymInt,
  18353. group: _int,
  18354. eps: _float,
  18355. ) -> tuple[Tensor, Tensor, Tensor]: ...
  18356. def native_layer_norm(
  18357. input: Tensor,
  18358. normalized_shape: Sequence[_int | SymInt],
  18359. weight: Tensor | None,
  18360. bias: Tensor | None,
  18361. eps: _float,
  18362. ) -> tuple[Tensor, Tensor, Tensor]: ...
  18363. @overload
  18364. def native_norm(
  18365. input: Tensor,
  18366. p: Number | _complex | None,
  18367. dim: _int | _size,
  18368. keepdim: _bool,
  18369. dtype: _dtype | None,
  18370. ) -> Tensor: ...
  18371. @overload
  18372. def native_norm(input: Tensor, p: Number | _complex = 2) -> Tensor: ...
  18373. @overload
  18374. def ne(
  18375. input: Tensor,
  18376. other: Tensor,
  18377. *,
  18378. out: Tensor | None = None,
  18379. ) -> Tensor:
  18380. r"""
  18381. ne(input, other, *, out=None) -> Tensor
  18382. Computes :math:`\text{input} \neq \text{other}` element-wise.
  18383. The second argument can be a number or a tensor whose shape is
  18384. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  18385. Args:
  18386. input (Tensor): the tensor to compare
  18387. other (Tensor or float): the tensor or value to compare
  18388. Keyword args:
  18389. out (Tensor, optional): the output tensor.
  18390. Returns:
  18391. A boolean tensor that is True where :attr:`input` is not equal to :attr:`other` and False elsewhere
  18392. Example::
  18393. >>> torch.ne(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  18394. tensor([[False, True], [True, False]])
  18395. """
  18396. @overload
  18397. def ne(
  18398. input: Tensor,
  18399. other: Number | _complex,
  18400. *,
  18401. out: Tensor | None = None,
  18402. ) -> Tensor:
  18403. r"""
  18404. ne(input, other, *, out=None) -> Tensor
  18405. Computes :math:`\text{input} \neq \text{other}` element-wise.
  18406. The second argument can be a number or a tensor whose shape is
  18407. :ref:`broadcastable <broadcasting-semantics>` with the first argument.
  18408. Args:
  18409. input (Tensor): the tensor to compare
  18410. other (Tensor or float): the tensor or value to compare
  18411. Keyword args:
  18412. out (Tensor, optional): the output tensor.
  18413. Returns:
  18414. A boolean tensor that is True where :attr:`input` is not equal to :attr:`other` and False elsewhere
  18415. Example::
  18416. >>> torch.ne(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
  18417. tensor([[False, True], [True, False]])
  18418. """
  18419. def neg(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  18420. r"""
  18421. neg(input, *, out=None) -> Tensor
  18422. Returns a new tensor with the negative of the elements of :attr:`input`.
  18423. .. math::
  18424. \text{out} = -1 \times \text{input}
  18425. Args:
  18426. input (Tensor): the input tensor.
  18427. Keyword args:
  18428. out (Tensor, optional): the output tensor.
  18429. Example::
  18430. >>> a = torch.randn(5)
  18431. >>> a
  18432. tensor([ 0.0090, -0.2262, -0.0682, -0.2866, 0.3940])
  18433. >>> torch.neg(a)
  18434. tensor([-0.0090, 0.2262, 0.0682, 0.2866, -0.3940])
  18435. """
  18436. def neg_(input: Tensor) -> Tensor: ...
  18437. def negative(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  18438. r"""
  18439. negative(input, *, out=None) -> Tensor
  18440. Alias for :func:`torch.neg`
  18441. """
  18442. def negative_(input: Tensor) -> Tensor: ...
  18443. def nextafter(
  18444. input: Tensor,
  18445. other: Tensor,
  18446. *,
  18447. out: Tensor | None = None,
  18448. ) -> Tensor:
  18449. r"""
  18450. nextafter(input, other, *, out=None) -> Tensor
  18451. Return the next floating-point value after :attr:`input` towards :attr:`other`, elementwise.
  18452. The shapes of ``input`` and ``other`` must be
  18453. :ref:`broadcastable <broadcasting-semantics>`.
  18454. Args:
  18455. input (Tensor): the first input tensor
  18456. other (Tensor): the second input tensor
  18457. Keyword args:
  18458. out (Tensor, optional): the output tensor.
  18459. Example::
  18460. >>> eps = torch.finfo(torch.float32).eps
  18461. >>> torch.nextafter(torch.tensor([1.0, 2.0]), torch.tensor([2.0, 1.0])) == torch.tensor([eps + 1, 2 - eps])
  18462. tensor([True, True])
  18463. """
  18464. @overload
  18465. def nonzero(
  18466. input: Tensor,
  18467. *,
  18468. as_tuple: Literal[False] = False,
  18469. out: Tensor | None = None,
  18470. ) -> Tensor:
  18471. r"""
  18472. nonzero(input, *, out=None, as_tuple=False) -> LongTensor or tuple of LongTensors
  18473. .. note::
  18474. :func:`torch.nonzero(..., as_tuple=False) <torch.nonzero>` (default) returns a
  18475. 2-D tensor where each row is the index for a nonzero value.
  18476. :func:`torch.nonzero(..., as_tuple=True) <torch.nonzero>` returns a tuple of 1-D
  18477. index tensors, allowing for advanced indexing, so ``x[x.nonzero(as_tuple=True)]``
  18478. gives all nonzero values of tensor ``x``. Of the returned tuple, each index tensor
  18479. contains nonzero indices for a certain dimension.
  18480. See below for more details on the two behaviors.
  18481. When :attr:`input` is on CUDA, :func:`torch.nonzero() <torch.nonzero>` causes
  18482. host-device synchronization.
  18483. **When** :attr:`as_tuple` **is** ``False`` **(default)**:
  18484. Returns a tensor containing the indices of all non-zero elements of
  18485. :attr:`input`. Each row in the result contains the indices of a non-zero
  18486. element in :attr:`input`. The result is sorted lexicographically, with
  18487. the last index changing the fastest (C-style).
  18488. If :attr:`input` has :math:`n` dimensions, then the resulting indices tensor
  18489. :attr:`out` is of size :math:`(z \times n)`, where :math:`z` is the total number of
  18490. non-zero elements in the :attr:`input` tensor.
  18491. **When** :attr:`as_tuple` **is** ``True``:
  18492. Returns a tuple of 1-D tensors, one for each dimension in :attr:`input`,
  18493. each containing the indices (in that dimension) of all non-zero elements of
  18494. :attr:`input` .
  18495. If :attr:`input` has :math:`n` dimensions, then the resulting tuple contains :math:`n`
  18496. tensors of size :math:`z`, where :math:`z` is the total number of
  18497. non-zero elements in the :attr:`input` tensor.
  18498. As a special case, when :attr:`input` has zero dimensions and a nonzero scalar
  18499. value, it is treated as a one-dimensional tensor with one element.
  18500. Args:
  18501. input (Tensor): the input tensor.
  18502. Keyword args:
  18503. out (LongTensor, optional): the output tensor containing indices
  18504. Returns:
  18505. LongTensor or tuple of LongTensor: If :attr:`as_tuple` is ``False``, the output
  18506. tensor containing indices. If :attr:`as_tuple` is ``True``, one 1-D tensor for
  18507. each dimension, containing the indices of each nonzero element along that
  18508. dimension.
  18509. Example::
  18510. >>> torch.nonzero(torch.tensor([1, 1, 1, 0, 1]))
  18511. tensor([[ 0],
  18512. [ 1],
  18513. [ 2],
  18514. [ 4]])
  18515. >>> torch.nonzero(torch.tensor([[0.6, 0.0, 0.0, 0.0],
  18516. ... [0.0, 0.4, 0.0, 0.0],
  18517. ... [0.0, 0.0, 1.2, 0.0],
  18518. ... [0.0, 0.0, 0.0,-0.4]]))
  18519. tensor([[ 0, 0],
  18520. [ 1, 1],
  18521. [ 2, 2],
  18522. [ 3, 3]])
  18523. >>> torch.nonzero(torch.tensor([1, 1, 1, 0, 1]), as_tuple=True)
  18524. (tensor([0, 1, 2, 4]),)
  18525. >>> torch.nonzero(torch.tensor([[0.6, 0.0, 0.0, 0.0],
  18526. ... [0.0, 0.4, 0.0, 0.0],
  18527. ... [0.0, 0.0, 1.2, 0.0],
  18528. ... [0.0, 0.0, 0.0,-0.4]]), as_tuple=True)
  18529. (tensor([0, 1, 2, 3]), tensor([0, 1, 2, 3]))
  18530. >>> torch.nonzero(torch.tensor(5), as_tuple=True)
  18531. (tensor([0]),)
  18532. """
  18533. @overload
  18534. def nonzero(
  18535. input: Tensor,
  18536. *,
  18537. as_tuple: Literal[True],
  18538. ) -> tuple[Tensor, ...]:
  18539. r"""
  18540. nonzero(input, *, out=None, as_tuple=False) -> LongTensor or tuple of LongTensors
  18541. .. note::
  18542. :func:`torch.nonzero(..., as_tuple=False) <torch.nonzero>` (default) returns a
  18543. 2-D tensor where each row is the index for a nonzero value.
  18544. :func:`torch.nonzero(..., as_tuple=True) <torch.nonzero>` returns a tuple of 1-D
  18545. index tensors, allowing for advanced indexing, so ``x[x.nonzero(as_tuple=True)]``
  18546. gives all nonzero values of tensor ``x``. Of the returned tuple, each index tensor
  18547. contains nonzero indices for a certain dimension.
  18548. See below for more details on the two behaviors.
  18549. When :attr:`input` is on CUDA, :func:`torch.nonzero() <torch.nonzero>` causes
  18550. host-device synchronization.
  18551. **When** :attr:`as_tuple` **is** ``False`` **(default)**:
  18552. Returns a tensor containing the indices of all non-zero elements of
  18553. :attr:`input`. Each row in the result contains the indices of a non-zero
  18554. element in :attr:`input`. The result is sorted lexicographically, with
  18555. the last index changing the fastest (C-style).
  18556. If :attr:`input` has :math:`n` dimensions, then the resulting indices tensor
  18557. :attr:`out` is of size :math:`(z \times n)`, where :math:`z` is the total number of
  18558. non-zero elements in the :attr:`input` tensor.
  18559. **When** :attr:`as_tuple` **is** ``True``:
  18560. Returns a tuple of 1-D tensors, one for each dimension in :attr:`input`,
  18561. each containing the indices (in that dimension) of all non-zero elements of
  18562. :attr:`input` .
  18563. If :attr:`input` has :math:`n` dimensions, then the resulting tuple contains :math:`n`
  18564. tensors of size :math:`z`, where :math:`z` is the total number of
  18565. non-zero elements in the :attr:`input` tensor.
  18566. As a special case, when :attr:`input` has zero dimensions and a nonzero scalar
  18567. value, it is treated as a one-dimensional tensor with one element.
  18568. Args:
  18569. input (Tensor): the input tensor.
  18570. Keyword args:
  18571. out (LongTensor, optional): the output tensor containing indices
  18572. Returns:
  18573. LongTensor or tuple of LongTensor: If :attr:`as_tuple` is ``False``, the output
  18574. tensor containing indices. If :attr:`as_tuple` is ``True``, one 1-D tensor for
  18575. each dimension, containing the indices of each nonzero element along that
  18576. dimension.
  18577. Example::
  18578. >>> torch.nonzero(torch.tensor([1, 1, 1, 0, 1]))
  18579. tensor([[ 0],
  18580. [ 1],
  18581. [ 2],
  18582. [ 4]])
  18583. >>> torch.nonzero(torch.tensor([[0.6, 0.0, 0.0, 0.0],
  18584. ... [0.0, 0.4, 0.0, 0.0],
  18585. ... [0.0, 0.0, 1.2, 0.0],
  18586. ... [0.0, 0.0, 0.0,-0.4]]))
  18587. tensor([[ 0, 0],
  18588. [ 1, 1],
  18589. [ 2, 2],
  18590. [ 3, 3]])
  18591. >>> torch.nonzero(torch.tensor([1, 1, 1, 0, 1]), as_tuple=True)
  18592. (tensor([0, 1, 2, 4]),)
  18593. >>> torch.nonzero(torch.tensor([[0.6, 0.0, 0.0, 0.0],
  18594. ... [0.0, 0.4, 0.0, 0.0],
  18595. ... [0.0, 0.0, 1.2, 0.0],
  18596. ... [0.0, 0.0, 0.0,-0.4]]), as_tuple=True)
  18597. (tensor([0, 1, 2, 3]), tensor([0, 1, 2, 3]))
  18598. >>> torch.nonzero(torch.tensor(5), as_tuple=True)
  18599. (tensor([0]),)
  18600. """
  18601. def nonzero_static(
  18602. input: Tensor,
  18603. *,
  18604. size: _int | SymInt,
  18605. fill_value: _int = -1,
  18606. out: Tensor | None = None,
  18607. ) -> Tensor: ...
  18608. def norm_except_dim(v: Tensor, pow: _int = 2, dim: _int = 0) -> Tensor: ...
  18609. @overload
  18610. def normal(
  18611. mean: Tensor,
  18612. std: Tensor,
  18613. *,
  18614. generator: Generator | None = None,
  18615. out: Tensor | None = None,
  18616. ) -> Tensor:
  18617. r"""
  18618. normal(mean, std, *, generator=None, out=None) -> Tensor
  18619. Returns a tensor of random numbers drawn from separate normal distributions
  18620. whose mean and standard deviation are given.
  18621. The :attr:`mean` is a tensor with the mean of
  18622. each output element's normal distribution
  18623. The :attr:`std` is a tensor with the standard deviation of
  18624. each output element's normal distribution
  18625. The shapes of :attr:`mean` and :attr:`std` don't need to match, but the
  18626. total number of elements in each tensor need to be the same.
  18627. .. note:: When the shapes do not match, the shape of :attr:`mean`
  18628. is used as the shape for the returned output tensor
  18629. .. note:: When :attr:`std` is a CUDA tensor, this function synchronizes
  18630. its device with the CPU.
  18631. Args:
  18632. mean (Tensor): the tensor of per-element means
  18633. std (Tensor): the tensor of per-element standard deviations
  18634. Keyword args:
  18635. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  18636. out (Tensor, optional): the output tensor.
  18637. Example::
  18638. >>> torch.normal(mean=torch.arange(1., 11.), std=torch.arange(1, 0, -0.1))
  18639. tensor([ 1.0425, 3.5672, 2.7969, 4.2925, 4.7229, 6.2134,
  18640. 8.0505, 8.1408, 9.0563, 10.0566])
  18641. .. function:: normal(mean=0.0, std, *, out=None) -> Tensor
  18642. :noindex:
  18643. Similar to the function above, but the means are shared among all drawn
  18644. elements.
  18645. Args:
  18646. mean (float, optional): the mean for all distributions
  18647. std (Tensor): the tensor of per-element standard deviations
  18648. Keyword args:
  18649. out (Tensor, optional): the output tensor.
  18650. Example::
  18651. >>> torch.normal(mean=0.5, std=torch.arange(1., 6.))
  18652. tensor([-1.2793, -1.0732, -2.0687, 5.1177, -1.2303])
  18653. .. function:: normal(mean, std=1.0, *, out=None) -> Tensor
  18654. :noindex:
  18655. Similar to the function above, but the standard deviations are shared among
  18656. all drawn elements.
  18657. Args:
  18658. mean (Tensor): the tensor of per-element means
  18659. std (float, optional): the standard deviation for all distributions
  18660. Keyword args:
  18661. out (Tensor, optional): the output tensor
  18662. Example::
  18663. >>> torch.normal(mean=torch.arange(1., 6.))
  18664. tensor([ 1.1552, 2.6148, 2.6535, 5.8318, 4.2361])
  18665. .. function:: normal(mean, std, size, *, out=None) -> Tensor
  18666. :noindex:
  18667. Similar to the function above, but the means and standard deviations are shared
  18668. among all drawn elements. The resulting tensor has size given by :attr:`size`.
  18669. Args:
  18670. mean (float): the mean for all distributions
  18671. std (float): the standard deviation for all distributions
  18672. size (int...): a sequence of integers defining the shape of the output tensor.
  18673. Keyword args:
  18674. out (Tensor, optional): the output tensor.
  18675. Example::
  18676. >>> torch.normal(2, 3, size=(1, 4))
  18677. tensor([[-1.3987, -1.9544, 3.6048, 0.7909]])
  18678. """
  18679. @overload
  18680. def normal(
  18681. mean: Tensor,
  18682. std: _float = 1,
  18683. *,
  18684. generator: Generator | None = None,
  18685. out: Tensor | None = None,
  18686. ) -> Tensor:
  18687. r"""
  18688. normal(mean, std, *, generator=None, out=None) -> Tensor
  18689. Returns a tensor of random numbers drawn from separate normal distributions
  18690. whose mean and standard deviation are given.
  18691. The :attr:`mean` is a tensor with the mean of
  18692. each output element's normal distribution
  18693. The :attr:`std` is a tensor with the standard deviation of
  18694. each output element's normal distribution
  18695. The shapes of :attr:`mean` and :attr:`std` don't need to match, but the
  18696. total number of elements in each tensor need to be the same.
  18697. .. note:: When the shapes do not match, the shape of :attr:`mean`
  18698. is used as the shape for the returned output tensor
  18699. .. note:: When :attr:`std` is a CUDA tensor, this function synchronizes
  18700. its device with the CPU.
  18701. Args:
  18702. mean (Tensor): the tensor of per-element means
  18703. std (Tensor): the tensor of per-element standard deviations
  18704. Keyword args:
  18705. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  18706. out (Tensor, optional): the output tensor.
  18707. Example::
  18708. >>> torch.normal(mean=torch.arange(1., 11.), std=torch.arange(1, 0, -0.1))
  18709. tensor([ 1.0425, 3.5672, 2.7969, 4.2925, 4.7229, 6.2134,
  18710. 8.0505, 8.1408, 9.0563, 10.0566])
  18711. .. function:: normal(mean=0.0, std, *, out=None) -> Tensor
  18712. :noindex:
  18713. Similar to the function above, but the means are shared among all drawn
  18714. elements.
  18715. Args:
  18716. mean (float, optional): the mean for all distributions
  18717. std (Tensor): the tensor of per-element standard deviations
  18718. Keyword args:
  18719. out (Tensor, optional): the output tensor.
  18720. Example::
  18721. >>> torch.normal(mean=0.5, std=torch.arange(1., 6.))
  18722. tensor([-1.2793, -1.0732, -2.0687, 5.1177, -1.2303])
  18723. .. function:: normal(mean, std=1.0, *, out=None) -> Tensor
  18724. :noindex:
  18725. Similar to the function above, but the standard deviations are shared among
  18726. all drawn elements.
  18727. Args:
  18728. mean (Tensor): the tensor of per-element means
  18729. std (float, optional): the standard deviation for all distributions
  18730. Keyword args:
  18731. out (Tensor, optional): the output tensor
  18732. Example::
  18733. >>> torch.normal(mean=torch.arange(1., 6.))
  18734. tensor([ 1.1552, 2.6148, 2.6535, 5.8318, 4.2361])
  18735. .. function:: normal(mean, std, size, *, out=None) -> Tensor
  18736. :noindex:
  18737. Similar to the function above, but the means and standard deviations are shared
  18738. among all drawn elements. The resulting tensor has size given by :attr:`size`.
  18739. Args:
  18740. mean (float): the mean for all distributions
  18741. std (float): the standard deviation for all distributions
  18742. size (int...): a sequence of integers defining the shape of the output tensor.
  18743. Keyword args:
  18744. out (Tensor, optional): the output tensor.
  18745. Example::
  18746. >>> torch.normal(2, 3, size=(1, 4))
  18747. tensor([[-1.3987, -1.9544, 3.6048, 0.7909]])
  18748. """
  18749. @overload
  18750. def normal(
  18751. mean: _float,
  18752. std: Tensor,
  18753. *,
  18754. generator: Generator | None = None,
  18755. out: Tensor | None = None,
  18756. ) -> Tensor:
  18757. r"""
  18758. normal(mean, std, *, generator=None, out=None) -> Tensor
  18759. Returns a tensor of random numbers drawn from separate normal distributions
  18760. whose mean and standard deviation are given.
  18761. The :attr:`mean` is a tensor with the mean of
  18762. each output element's normal distribution
  18763. The :attr:`std` is a tensor with the standard deviation of
  18764. each output element's normal distribution
  18765. The shapes of :attr:`mean` and :attr:`std` don't need to match, but the
  18766. total number of elements in each tensor need to be the same.
  18767. .. note:: When the shapes do not match, the shape of :attr:`mean`
  18768. is used as the shape for the returned output tensor
  18769. .. note:: When :attr:`std` is a CUDA tensor, this function synchronizes
  18770. its device with the CPU.
  18771. Args:
  18772. mean (Tensor): the tensor of per-element means
  18773. std (Tensor): the tensor of per-element standard deviations
  18774. Keyword args:
  18775. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  18776. out (Tensor, optional): the output tensor.
  18777. Example::
  18778. >>> torch.normal(mean=torch.arange(1., 11.), std=torch.arange(1, 0, -0.1))
  18779. tensor([ 1.0425, 3.5672, 2.7969, 4.2925, 4.7229, 6.2134,
  18780. 8.0505, 8.1408, 9.0563, 10.0566])
  18781. .. function:: normal(mean=0.0, std, *, out=None) -> Tensor
  18782. :noindex:
  18783. Similar to the function above, but the means are shared among all drawn
  18784. elements.
  18785. Args:
  18786. mean (float, optional): the mean for all distributions
  18787. std (Tensor): the tensor of per-element standard deviations
  18788. Keyword args:
  18789. out (Tensor, optional): the output tensor.
  18790. Example::
  18791. >>> torch.normal(mean=0.5, std=torch.arange(1., 6.))
  18792. tensor([-1.2793, -1.0732, -2.0687, 5.1177, -1.2303])
  18793. .. function:: normal(mean, std=1.0, *, out=None) -> Tensor
  18794. :noindex:
  18795. Similar to the function above, but the standard deviations are shared among
  18796. all drawn elements.
  18797. Args:
  18798. mean (Tensor): the tensor of per-element means
  18799. std (float, optional): the standard deviation for all distributions
  18800. Keyword args:
  18801. out (Tensor, optional): the output tensor
  18802. Example::
  18803. >>> torch.normal(mean=torch.arange(1., 6.))
  18804. tensor([ 1.1552, 2.6148, 2.6535, 5.8318, 4.2361])
  18805. .. function:: normal(mean, std, size, *, out=None) -> Tensor
  18806. :noindex:
  18807. Similar to the function above, but the means and standard deviations are shared
  18808. among all drawn elements. The resulting tensor has size given by :attr:`size`.
  18809. Args:
  18810. mean (float): the mean for all distributions
  18811. std (float): the standard deviation for all distributions
  18812. size (int...): a sequence of integers defining the shape of the output tensor.
  18813. Keyword args:
  18814. out (Tensor, optional): the output tensor.
  18815. Example::
  18816. >>> torch.normal(2, 3, size=(1, 4))
  18817. tensor([[-1.3987, -1.9544, 3.6048, 0.7909]])
  18818. """
  18819. @overload
  18820. def normal(
  18821. mean: _float,
  18822. std: _float,
  18823. size: Sequence[_int | SymInt],
  18824. *,
  18825. generator: Generator | None = None,
  18826. out: Tensor | None = None,
  18827. dtype: _dtype | None = None,
  18828. layout: _layout | None = None,
  18829. device: DeviceLikeType | None = None,
  18830. pin_memory: _bool | None = False,
  18831. requires_grad: _bool | None = False,
  18832. ) -> Tensor:
  18833. r"""
  18834. normal(mean, std, *, generator=None, out=None) -> Tensor
  18835. Returns a tensor of random numbers drawn from separate normal distributions
  18836. whose mean and standard deviation are given.
  18837. The :attr:`mean` is a tensor with the mean of
  18838. each output element's normal distribution
  18839. The :attr:`std` is a tensor with the standard deviation of
  18840. each output element's normal distribution
  18841. The shapes of :attr:`mean` and :attr:`std` don't need to match, but the
  18842. total number of elements in each tensor need to be the same.
  18843. .. note:: When the shapes do not match, the shape of :attr:`mean`
  18844. is used as the shape for the returned output tensor
  18845. .. note:: When :attr:`std` is a CUDA tensor, this function synchronizes
  18846. its device with the CPU.
  18847. Args:
  18848. mean (Tensor): the tensor of per-element means
  18849. std (Tensor): the tensor of per-element standard deviations
  18850. Keyword args:
  18851. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  18852. out (Tensor, optional): the output tensor.
  18853. Example::
  18854. >>> torch.normal(mean=torch.arange(1., 11.), std=torch.arange(1, 0, -0.1))
  18855. tensor([ 1.0425, 3.5672, 2.7969, 4.2925, 4.7229, 6.2134,
  18856. 8.0505, 8.1408, 9.0563, 10.0566])
  18857. .. function:: normal(mean=0.0, std, *, out=None) -> Tensor
  18858. :noindex:
  18859. Similar to the function above, but the means are shared among all drawn
  18860. elements.
  18861. Args:
  18862. mean (float, optional): the mean for all distributions
  18863. std (Tensor): the tensor of per-element standard deviations
  18864. Keyword args:
  18865. out (Tensor, optional): the output tensor.
  18866. Example::
  18867. >>> torch.normal(mean=0.5, std=torch.arange(1., 6.))
  18868. tensor([-1.2793, -1.0732, -2.0687, 5.1177, -1.2303])
  18869. .. function:: normal(mean, std=1.0, *, out=None) -> Tensor
  18870. :noindex:
  18871. Similar to the function above, but the standard deviations are shared among
  18872. all drawn elements.
  18873. Args:
  18874. mean (Tensor): the tensor of per-element means
  18875. std (float, optional): the standard deviation for all distributions
  18876. Keyword args:
  18877. out (Tensor, optional): the output tensor
  18878. Example::
  18879. >>> torch.normal(mean=torch.arange(1., 6.))
  18880. tensor([ 1.1552, 2.6148, 2.6535, 5.8318, 4.2361])
  18881. .. function:: normal(mean, std, size, *, out=None) -> Tensor
  18882. :noindex:
  18883. Similar to the function above, but the means and standard deviations are shared
  18884. among all drawn elements. The resulting tensor has size given by :attr:`size`.
  18885. Args:
  18886. mean (float): the mean for all distributions
  18887. std (float): the standard deviation for all distributions
  18888. size (int...): a sequence of integers defining the shape of the output tensor.
  18889. Keyword args:
  18890. out (Tensor, optional): the output tensor.
  18891. Example::
  18892. >>> torch.normal(2, 3, size=(1, 4))
  18893. tensor([[-1.3987, -1.9544, 3.6048, 0.7909]])
  18894. """
  18895. @overload
  18896. def not_equal(
  18897. input: Tensor,
  18898. other: Tensor,
  18899. *,
  18900. out: Tensor | None = None,
  18901. ) -> Tensor:
  18902. r"""
  18903. not_equal(input, other, *, out=None) -> Tensor
  18904. Alias for :func:`torch.ne`.
  18905. """
  18906. @overload
  18907. def not_equal(
  18908. input: Tensor,
  18909. other: Number | _complex,
  18910. *,
  18911. out: Tensor | None = None,
  18912. ) -> Tensor:
  18913. r"""
  18914. not_equal(input, other, *, out=None) -> Tensor
  18915. Alias for :func:`torch.ne`.
  18916. """
  18917. @overload
  18918. def nuclear_norm(
  18919. input: Tensor,
  18920. dim: _int | _size,
  18921. keepdim: _bool = False,
  18922. *,
  18923. out: Tensor | None = None,
  18924. ) -> Tensor: ...
  18925. @overload
  18926. def nuclear_norm(
  18927. input: Tensor,
  18928. keepdim: _bool = False,
  18929. *,
  18930. out: Tensor | None = None,
  18931. ) -> Tensor: ...
  18932. def numel(self: Tensor) -> _int:
  18933. r"""
  18934. numel(input: Tensor) -> int
  18935. Returns the total number of elements in the :attr:`input` tensor.
  18936. Args:
  18937. input (Tensor): the input tensor.
  18938. Example::
  18939. >>> a = torch.randn(1, 2, 3, 4, 5)
  18940. >>> torch.numel(a)
  18941. 120
  18942. >>> a = torch.zeros(4,4)
  18943. >>> torch.numel(a)
  18944. 16
  18945. """
  18946. @overload
  18947. def ones(
  18948. size: Sequence[_int | SymInt],
  18949. *,
  18950. out: Tensor | None = None,
  18951. dtype: _dtype | None = None,
  18952. layout: _layout | None = None,
  18953. device: DeviceLikeType | None = None,
  18954. pin_memory: _bool | None = False,
  18955. requires_grad: _bool | None = False,
  18956. ) -> Tensor:
  18957. r"""
  18958. ones(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  18959. Returns a tensor filled with the scalar value `1`, with the shape defined
  18960. by the variable argument :attr:`size`.
  18961. Args:
  18962. size (int...): a sequence of integers defining the shape of the output tensor.
  18963. Can be a variable number of arguments or a collection like a list or tuple.
  18964. Keyword arguments:
  18965. out (Tensor, optional): the output tensor.
  18966. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  18967. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  18968. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  18969. Default: ``torch.strided``.
  18970. device (:class:`torch.device`, optional): the desired device of returned tensor.
  18971. Default: if ``None``, uses the current device for the default tensor type
  18972. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  18973. for CPU tensor types and the current CUDA device for CUDA tensor types.
  18974. requires_grad (bool, optional): If autograd should record operations on the
  18975. returned tensor. Default: ``False``.
  18976. Example::
  18977. >>> torch.ones(2, 3)
  18978. tensor([[ 1., 1., 1.],
  18979. [ 1., 1., 1.]])
  18980. >>> torch.ones(5)
  18981. tensor([ 1., 1., 1., 1., 1.])
  18982. """
  18983. @overload
  18984. def ones(
  18985. *size: _int | SymInt,
  18986. out: Tensor | None = None,
  18987. dtype: _dtype | None = None,
  18988. layout: _layout | None = None,
  18989. device: DeviceLikeType | None = None,
  18990. pin_memory: _bool | None = False,
  18991. requires_grad: _bool | None = False,
  18992. ) -> Tensor:
  18993. r"""
  18994. ones(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  18995. Returns a tensor filled with the scalar value `1`, with the shape defined
  18996. by the variable argument :attr:`size`.
  18997. Args:
  18998. size (int...): a sequence of integers defining the shape of the output tensor.
  18999. Can be a variable number of arguments or a collection like a list or tuple.
  19000. Keyword arguments:
  19001. out (Tensor, optional): the output tensor.
  19002. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19003. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  19004. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  19005. Default: ``torch.strided``.
  19006. device (:class:`torch.device`, optional): the desired device of returned tensor.
  19007. Default: if ``None``, uses the current device for the default tensor type
  19008. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  19009. for CPU tensor types and the current CUDA device for CUDA tensor types.
  19010. requires_grad (bool, optional): If autograd should record operations on the
  19011. returned tensor. Default: ``False``.
  19012. Example::
  19013. >>> torch.ones(2, 3)
  19014. tensor([[ 1., 1., 1.],
  19015. [ 1., 1., 1.]])
  19016. >>> torch.ones(5)
  19017. tensor([ 1., 1., 1., 1., 1.])
  19018. """
  19019. @overload
  19020. def ones(
  19021. size: _size,
  19022. *,
  19023. names: Sequence[str | EllipsisType | None] | None,
  19024. dtype: _dtype | None = None,
  19025. layout: _layout | None = None,
  19026. device: DeviceLikeType | None = None,
  19027. pin_memory: _bool | None = False,
  19028. requires_grad: _bool | None = False,
  19029. ) -> Tensor:
  19030. r"""
  19031. ones(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  19032. Returns a tensor filled with the scalar value `1`, with the shape defined
  19033. by the variable argument :attr:`size`.
  19034. Args:
  19035. size (int...): a sequence of integers defining the shape of the output tensor.
  19036. Can be a variable number of arguments or a collection like a list or tuple.
  19037. Keyword arguments:
  19038. out (Tensor, optional): the output tensor.
  19039. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19040. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  19041. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  19042. Default: ``torch.strided``.
  19043. device (:class:`torch.device`, optional): the desired device of returned tensor.
  19044. Default: if ``None``, uses the current device for the default tensor type
  19045. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  19046. for CPU tensor types and the current CUDA device for CUDA tensor types.
  19047. requires_grad (bool, optional): If autograd should record operations on the
  19048. returned tensor. Default: ``False``.
  19049. Example::
  19050. >>> torch.ones(2, 3)
  19051. tensor([[ 1., 1., 1.],
  19052. [ 1., 1., 1.]])
  19053. >>> torch.ones(5)
  19054. tensor([ 1., 1., 1., 1., 1.])
  19055. """
  19056. @overload
  19057. def ones(
  19058. *size: _int,
  19059. names: Sequence[str | EllipsisType | None] | None,
  19060. dtype: _dtype | None = None,
  19061. layout: _layout | None = None,
  19062. device: DeviceLikeType | None = None,
  19063. pin_memory: _bool | None = False,
  19064. requires_grad: _bool | None = False,
  19065. ) -> Tensor:
  19066. r"""
  19067. ones(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  19068. Returns a tensor filled with the scalar value `1`, with the shape defined
  19069. by the variable argument :attr:`size`.
  19070. Args:
  19071. size (int...): a sequence of integers defining the shape of the output tensor.
  19072. Can be a variable number of arguments or a collection like a list or tuple.
  19073. Keyword arguments:
  19074. out (Tensor, optional): the output tensor.
  19075. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19076. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  19077. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  19078. Default: ``torch.strided``.
  19079. device (:class:`torch.device`, optional): the desired device of returned tensor.
  19080. Default: if ``None``, uses the current device for the default tensor type
  19081. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  19082. for CPU tensor types and the current CUDA device for CUDA tensor types.
  19083. requires_grad (bool, optional): If autograd should record operations on the
  19084. returned tensor. Default: ``False``.
  19085. Example::
  19086. >>> torch.ones(2, 3)
  19087. tensor([[ 1., 1., 1.],
  19088. [ 1., 1., 1.]])
  19089. >>> torch.ones(5)
  19090. tensor([ 1., 1., 1., 1., 1.])
  19091. """
  19092. def ones_like(
  19093. input: Tensor,
  19094. *,
  19095. memory_format: memory_format | None = None,
  19096. dtype: _dtype | None = None,
  19097. layout: _layout | None = None,
  19098. device: DeviceLikeType | None = None,
  19099. pin_memory: _bool | None = False,
  19100. requires_grad: _bool | None = False,
  19101. ) -> Tensor:
  19102. r"""
  19103. ones_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  19104. Returns a tensor filled with the scalar value `1`, with the same size as
  19105. :attr:`input`. ``torch.ones_like(input)`` is equivalent to
  19106. ``torch.ones(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
  19107. .. warning::
  19108. As of 0.4, this function does not support an :attr:`out` keyword. As an alternative,
  19109. the old ``torch.ones_like(input, out=output)`` is equivalent to
  19110. ``torch.ones(input.size(), out=output)``.
  19111. Args:
  19112. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  19113. Keyword arguments:
  19114. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  19115. Default: if ``None``, defaults to the dtype of :attr:`input`.
  19116. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  19117. Default: if ``None``, defaults to the layout of :attr:`input`.
  19118. device (:class:`torch.device`, optional): the desired device of returned tensor.
  19119. Default: if ``None``, defaults to the device of :attr:`input`.
  19120. requires_grad (bool, optional): If autograd should record operations on the
  19121. returned tensor. Default: ``False``.
  19122. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  19123. returned Tensor. Default: ``torch.preserve_format``.
  19124. Example::
  19125. >>> input = torch.empty(2, 3)
  19126. >>> torch.ones_like(input)
  19127. tensor([[ 1., 1., 1.],
  19128. [ 1., 1., 1.]])
  19129. """
  19130. def orgqr(
  19131. input: Tensor,
  19132. input2: Tensor,
  19133. *,
  19134. out: Tensor | None = None,
  19135. ) -> Tensor:
  19136. r"""
  19137. orgqr(input, tau) -> Tensor
  19138. Alias for :func:`torch.linalg.householder_product`.
  19139. """
  19140. def ormqr(
  19141. input: Tensor,
  19142. input2: Tensor,
  19143. input3: Tensor,
  19144. left: _bool = True,
  19145. transpose: _bool = False,
  19146. *,
  19147. out: Tensor | None = None,
  19148. ) -> Tensor:
  19149. r"""
  19150. ormqr(input, tau, other, left=True, transpose=False, *, out=None) -> Tensor
  19151. Computes the matrix-matrix multiplication of a product of Householder matrices with a general matrix.
  19152. Multiplies a :math:`m \times n` matrix `C` (given by :attr:`other`) with a matrix `Q`,
  19153. where `Q` is represented using Householder reflectors `(input, tau)`.
  19154. See `Representation of Orthogonal or Unitary Matrices`_ for further details.
  19155. If :attr:`left` is `True` then `op(Q)` times `C` is computed, otherwise the result is `C` times `op(Q)`.
  19156. When :attr:`left` is `True`, the implicit matrix `Q` has size :math:`m \times m`.
  19157. It has size :math:`n \times n` otherwise.
  19158. If :attr:`transpose` is `True` then `op` is the conjugate transpose operation, otherwise it's a no-op.
  19159. Supports inputs of float, double, cfloat and cdouble dtypes.
  19160. Also supports batched inputs, and, if the input is batched, the output is batched with the same dimensions.
  19161. .. seealso::
  19162. :func:`torch.geqrf` can be used to form the Householder representation `(input, tau)` of matrix `Q`
  19163. from the QR decomposition.
  19164. .. note::
  19165. This function supports backward but it is only fast when ``(input, tau)`` do not require gradients
  19166. and/or ``tau.size(-1)`` is very small.
  19167. ``
  19168. Args:
  19169. input (Tensor): tensor of shape `(*, mn, k)` where `*` is zero or more batch dimensions
  19170. and `mn` equals to `m` or `n` depending on the :attr:`left`.
  19171. tau (Tensor): tensor of shape `(*, min(mn, k))` where `*` is zero or more batch dimensions.
  19172. other (Tensor): tensor of shape `(*, m, n)` where `*` is zero or more batch dimensions.
  19173. left (bool): controls the order of multiplication.
  19174. transpose (bool): controls whether the matrix `Q` is conjugate transposed or not.
  19175. Keyword args:
  19176. out (Tensor, optional): the output Tensor. Ignored if `None`. Default: `None`.
  19177. .. _Representation of Orthogonal or Unitary Matrices:
  19178. https://www.netlib.org/lapack/lug/node128.html
  19179. """
  19180. def outer(
  19181. input: Tensor,
  19182. vec2: Tensor,
  19183. *,
  19184. out: Tensor | None = None,
  19185. ) -> Tensor:
  19186. r"""
  19187. outer(input, vec2, *, out=None) -> Tensor
  19188. Outer product of :attr:`input` and :attr:`vec2`.
  19189. If :attr:`input` is a vector of size :math:`n` and :attr:`vec2` is a vector of
  19190. size :math:`m`, then :attr:`out` must be a matrix of size :math:`(n \times m)`.
  19191. .. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
  19192. Args:
  19193. input (Tensor): 1-D input vector
  19194. vec2 (Tensor): 1-D input vector
  19195. Keyword args:
  19196. out (Tensor, optional): optional output matrix
  19197. Example::
  19198. >>> v1 = torch.arange(1., 5.)
  19199. >>> v2 = torch.arange(1., 4.)
  19200. >>> torch.outer(v1, v2)
  19201. tensor([[ 1., 2., 3.],
  19202. [ 2., 4., 6.],
  19203. [ 3., 6., 9.],
  19204. [ 4., 8., 12.]])
  19205. """
  19206. def pairwise_distance(
  19207. x1: Tensor,
  19208. x2: Tensor,
  19209. p: _float = 2,
  19210. eps: _float = 1e-06,
  19211. keepdim: _bool = False,
  19212. ) -> Tensor: ...
  19213. def pdist(input: Tensor, p: _float = 2) -> Tensor: ...
  19214. def permute(input: Tensor, dims: _size) -> Tensor:
  19215. r"""
  19216. permute(input, dims) -> Tensor
  19217. Returns a view of the original tensor :attr:`input` with its dimensions permuted.
  19218. Args:
  19219. input (Tensor): the input tensor.
  19220. dims (tuple of int): The desired ordering of dimensions
  19221. Example:
  19222. >>> x = torch.randn(2, 3, 5)
  19223. >>> x.size()
  19224. torch.Size([2, 3, 5])
  19225. >>> torch.permute(x, (2, 0, 1)).size()
  19226. torch.Size([5, 2, 3])
  19227. """
  19228. def permute_copy(
  19229. input: Tensor,
  19230. dims: _size,
  19231. *,
  19232. out: Tensor | None = None,
  19233. ) -> Tensor:
  19234. r"""
  19235. Performs the same operation as :func:`torch.permute`, but all output tensors
  19236. are freshly created instead of aliasing the input.
  19237. """
  19238. def pinverse(input: Tensor, rcond: _float = 1e-15) -> Tensor:
  19239. r"""
  19240. pinverse(input, rcond=1e-15) -> Tensor
  19241. Alias for :func:`torch.linalg.pinv`
  19242. """
  19243. def pixel_shuffle(input: Tensor, upscale_factor: _int) -> Tensor: ...
  19244. def pixel_unshuffle(input: Tensor, downscale_factor: _int) -> Tensor: ...
  19245. def poisson(input: Tensor, generator: Generator | None = None) -> Tensor:
  19246. r"""
  19247. poisson(input, generator=None) -> Tensor
  19248. Returns a tensor of the same size as :attr:`input` with each element
  19249. sampled from a Poisson distribution with rate parameter given by the corresponding
  19250. element in :attr:`input` i.e.,
  19251. .. math::
  19252. \text{out}_i \sim \text{Poisson}(\text{input}_i)
  19253. :attr:`input` must be non-negative.
  19254. Args:
  19255. input (Tensor): the input tensor containing the rates of the Poisson distribution
  19256. Keyword args:
  19257. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  19258. Example::
  19259. >>> rates = torch.rand(4, 4) * 5 # rate parameter between 0 and 5
  19260. >>> torch.poisson(rates)
  19261. tensor([[9., 1., 3., 5.],
  19262. [8., 6., 6., 0.],
  19263. [0., 4., 5., 3.],
  19264. [2., 1., 4., 2.]])
  19265. """
  19266. def poisson_nll_loss(
  19267. input: Tensor,
  19268. target: Tensor,
  19269. log_input: _bool,
  19270. full: _bool,
  19271. eps: _float,
  19272. reduction: _int,
  19273. ) -> Tensor: ...
  19274. def polar(
  19275. abs: Tensor,
  19276. angle: Tensor,
  19277. *,
  19278. out: Tensor | None = None,
  19279. ) -> Tensor:
  19280. r"""
  19281. polar(abs, angle, *, out=None) -> Tensor
  19282. Constructs a complex tensor whose elements are Cartesian coordinates
  19283. corresponding to the polar coordinates with absolute value :attr:`abs` and angle
  19284. :attr:`angle`.
  19285. .. math::
  19286. \text{out} = \text{abs} \cdot \cos(\text{angle}) + \text{abs} \cdot \sin(\text{angle}) \cdot j
  19287. .. note::
  19288. `torch.polar` is similar to
  19289. `std::polar <https://en.cppreference.com/w/cpp/numeric/complex/polar>`_
  19290. and does not compute the polar decomposition
  19291. of a complex tensor like Python's `cmath.polar` and SciPy's `linalg.polar` do.
  19292. The behavior of this function is undefined if `abs` is negative or NaN, or if `angle` is
  19293. infinite.
  19294. Args:
  19295. abs (Tensor): The absolute value the complex tensor. Must be float or double.
  19296. angle (Tensor): The angle of the complex tensor. Must be same dtype as
  19297. :attr:`abs`.
  19298. Keyword args:
  19299. out (Tensor): If the inputs are ``torch.float32``, must be
  19300. ``torch.complex64``. If the inputs are ``torch.float64``, must be
  19301. ``torch.complex128``.
  19302. Example::
  19303. >>> import numpy as np
  19304. >>> abs = torch.tensor([1, 2], dtype=torch.float64)
  19305. >>> angle = torch.tensor([np.pi / 2, 5 * np.pi / 4], dtype=torch.float64)
  19306. >>> z = torch.polar(abs, angle)
  19307. >>> z
  19308. tensor([(0.0000+1.0000j), (-1.4142-1.4142j)], dtype=torch.complex128)
  19309. """
  19310. def polygamma(
  19311. n: _int,
  19312. input: Tensor,
  19313. *,
  19314. out: Tensor | None = None,
  19315. ) -> Tensor:
  19316. r"""
  19317. polygamma(n, input, *, out=None) -> Tensor
  19318. Alias for :func:`torch.special.polygamma`.
  19319. """
  19320. def positive(input: Tensor) -> Tensor:
  19321. r"""
  19322. positive(input) -> Tensor
  19323. Returns :attr:`input`.
  19324. Throws a runtime error if :attr:`input` is a bool tensor.
  19325. Args:
  19326. input (Tensor): the input tensor.
  19327. Example::
  19328. >>> t = torch.randn(5)
  19329. >>> t
  19330. tensor([ 0.0090, -0.2262, -0.0682, -0.2866, 0.3940])
  19331. >>> torch.positive(t)
  19332. tensor([ 0.0090, -0.2262, -0.0682, -0.2866, 0.3940])
  19333. """
  19334. @overload
  19335. def pow(
  19336. input: Tensor,
  19337. exponent: Tensor,
  19338. *,
  19339. out: Tensor | None = None,
  19340. ) -> Tensor:
  19341. r"""
  19342. pow(input, exponent, *, out=None) -> Tensor
  19343. Takes the power of each element in :attr:`input` with :attr:`exponent` and
  19344. returns a tensor with the result.
  19345. :attr:`exponent` can be either a single ``float`` number or a `Tensor`
  19346. with the same number of elements as :attr:`input`.
  19347. When :attr:`exponent` is a scalar value, the operation applied is:
  19348. .. math::
  19349. \text{out}_i = x_i ^ \text{exponent}
  19350. When :attr:`exponent` is a tensor, the operation applied is:
  19351. .. math::
  19352. \text{out}_i = x_i ^ {\text{exponent}_i}
  19353. When :attr:`exponent` is a tensor, the shapes of :attr:`input`
  19354. and :attr:`exponent` must be :ref:`broadcastable <broadcasting-semantics>`.
  19355. Args:
  19356. input (Tensor): the input tensor.
  19357. exponent (float or tensor): the exponent value
  19358. Keyword args:
  19359. out (Tensor, optional): the output tensor.
  19360. Example::
  19361. >>> a = torch.randn(4)
  19362. >>> a
  19363. tensor([ 0.4331, 1.2475, 0.6834, -0.2791])
  19364. >>> torch.pow(a, 2)
  19365. tensor([ 0.1875, 1.5561, 0.4670, 0.0779])
  19366. >>> exp = torch.arange(1., 5.)
  19367. >>> a = torch.arange(1., 5.)
  19368. >>> a
  19369. tensor([ 1., 2., 3., 4.])
  19370. >>> exp
  19371. tensor([ 1., 2., 3., 4.])
  19372. >>> torch.pow(a, exp)
  19373. tensor([ 1., 4., 27., 256.])
  19374. .. function:: pow(self, exponent, *, out=None) -> Tensor
  19375. :noindex:
  19376. :attr:`self` is a scalar ``float`` value, and :attr:`exponent` is a tensor.
  19377. The returned tensor :attr:`out` is of the same shape as :attr:`exponent`
  19378. The operation applied is:
  19379. .. math::
  19380. \text{out}_i = \text{self} ^ {\text{exponent}_i}
  19381. Args:
  19382. self (float): the scalar base value for the power operation
  19383. exponent (Tensor): the exponent tensor
  19384. Keyword args:
  19385. out (Tensor, optional): the output tensor.
  19386. Example::
  19387. >>> exp = torch.arange(1., 5.)
  19388. >>> base = 2
  19389. >>> torch.pow(base, exp)
  19390. tensor([ 2., 4., 8., 16.])
  19391. """
  19392. @overload
  19393. def pow(
  19394. self: Number | _complex,
  19395. exponent: Tensor,
  19396. *,
  19397. out: Tensor | None = None,
  19398. ) -> Tensor:
  19399. r"""
  19400. pow(input, exponent, *, out=None) -> Tensor
  19401. Takes the power of each element in :attr:`input` with :attr:`exponent` and
  19402. returns a tensor with the result.
  19403. :attr:`exponent` can be either a single ``float`` number or a `Tensor`
  19404. with the same number of elements as :attr:`input`.
  19405. When :attr:`exponent` is a scalar value, the operation applied is:
  19406. .. math::
  19407. \text{out}_i = x_i ^ \text{exponent}
  19408. When :attr:`exponent` is a tensor, the operation applied is:
  19409. .. math::
  19410. \text{out}_i = x_i ^ {\text{exponent}_i}
  19411. When :attr:`exponent` is a tensor, the shapes of :attr:`input`
  19412. and :attr:`exponent` must be :ref:`broadcastable <broadcasting-semantics>`.
  19413. Args:
  19414. input (Tensor): the input tensor.
  19415. exponent (float or tensor): the exponent value
  19416. Keyword args:
  19417. out (Tensor, optional): the output tensor.
  19418. Example::
  19419. >>> a = torch.randn(4)
  19420. >>> a
  19421. tensor([ 0.4331, 1.2475, 0.6834, -0.2791])
  19422. >>> torch.pow(a, 2)
  19423. tensor([ 0.1875, 1.5561, 0.4670, 0.0779])
  19424. >>> exp = torch.arange(1., 5.)
  19425. >>> a = torch.arange(1., 5.)
  19426. >>> a
  19427. tensor([ 1., 2., 3., 4.])
  19428. >>> exp
  19429. tensor([ 1., 2., 3., 4.])
  19430. >>> torch.pow(a, exp)
  19431. tensor([ 1., 4., 27., 256.])
  19432. .. function:: pow(self, exponent, *, out=None) -> Tensor
  19433. :noindex:
  19434. :attr:`self` is a scalar ``float`` value, and :attr:`exponent` is a tensor.
  19435. The returned tensor :attr:`out` is of the same shape as :attr:`exponent`
  19436. The operation applied is:
  19437. .. math::
  19438. \text{out}_i = \text{self} ^ {\text{exponent}_i}
  19439. Args:
  19440. self (float): the scalar base value for the power operation
  19441. exponent (Tensor): the exponent tensor
  19442. Keyword args:
  19443. out (Tensor, optional): the output tensor.
  19444. Example::
  19445. >>> exp = torch.arange(1., 5.)
  19446. >>> base = 2
  19447. >>> torch.pow(base, exp)
  19448. tensor([ 2., 4., 8., 16.])
  19449. """
  19450. @overload
  19451. def pow(
  19452. input: Tensor,
  19453. exponent: Number | _complex,
  19454. *,
  19455. out: Tensor | None = None,
  19456. ) -> Tensor:
  19457. r"""
  19458. pow(input, exponent, *, out=None) -> Tensor
  19459. Takes the power of each element in :attr:`input` with :attr:`exponent` and
  19460. returns a tensor with the result.
  19461. :attr:`exponent` can be either a single ``float`` number or a `Tensor`
  19462. with the same number of elements as :attr:`input`.
  19463. When :attr:`exponent` is a scalar value, the operation applied is:
  19464. .. math::
  19465. \text{out}_i = x_i ^ \text{exponent}
  19466. When :attr:`exponent` is a tensor, the operation applied is:
  19467. .. math::
  19468. \text{out}_i = x_i ^ {\text{exponent}_i}
  19469. When :attr:`exponent` is a tensor, the shapes of :attr:`input`
  19470. and :attr:`exponent` must be :ref:`broadcastable <broadcasting-semantics>`.
  19471. Args:
  19472. input (Tensor): the input tensor.
  19473. exponent (float or tensor): the exponent value
  19474. Keyword args:
  19475. out (Tensor, optional): the output tensor.
  19476. Example::
  19477. >>> a = torch.randn(4)
  19478. >>> a
  19479. tensor([ 0.4331, 1.2475, 0.6834, -0.2791])
  19480. >>> torch.pow(a, 2)
  19481. tensor([ 0.1875, 1.5561, 0.4670, 0.0779])
  19482. >>> exp = torch.arange(1., 5.)
  19483. >>> a = torch.arange(1., 5.)
  19484. >>> a
  19485. tensor([ 1., 2., 3., 4.])
  19486. >>> exp
  19487. tensor([ 1., 2., 3., 4.])
  19488. >>> torch.pow(a, exp)
  19489. tensor([ 1., 4., 27., 256.])
  19490. .. function:: pow(self, exponent, *, out=None) -> Tensor
  19491. :noindex:
  19492. :attr:`self` is a scalar ``float`` value, and :attr:`exponent` is a tensor.
  19493. The returned tensor :attr:`out` is of the same shape as :attr:`exponent`
  19494. The operation applied is:
  19495. .. math::
  19496. \text{out}_i = \text{self} ^ {\text{exponent}_i}
  19497. Args:
  19498. self (float): the scalar base value for the power operation
  19499. exponent (Tensor): the exponent tensor
  19500. Keyword args:
  19501. out (Tensor, optional): the output tensor.
  19502. Example::
  19503. >>> exp = torch.arange(1., 5.)
  19504. >>> base = 2
  19505. >>> torch.pow(base, exp)
  19506. tensor([ 2., 4., 8., 16.])
  19507. """
  19508. def prelu(input: Tensor, weight: Tensor) -> Tensor: ...
  19509. @overload
  19510. def prod(input: Tensor, *, dtype: _dtype | None = None) -> Tensor:
  19511. r"""
  19512. prod(input: Tensor, *, dtype: Optional[_dtype]) -> Tensor
  19513. Returns the product of all elements in the :attr:`input` tensor.
  19514. Args:
  19515. input (Tensor): the input tensor.
  19516. Keyword args:
  19517. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19518. If specified, the input tensor is casted to :attr:`dtype` before the operation
  19519. is performed. This is useful for preventing data type overflows. Default: None.
  19520. Example::
  19521. >>> a = torch.randn(1, 3)
  19522. >>> a
  19523. tensor([[-0.8020, 0.5428, -1.5854]])
  19524. >>> torch.prod(a)
  19525. tensor(0.6902)
  19526. .. function:: prod(input, dim, keepdim=False, *, dtype=None) -> Tensor
  19527. :noindex:
  19528. Returns the product of each row of the :attr:`input` tensor in the given
  19529. dimension :attr:`dim`.
  19530. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  19531. as :attr:`input` except in the dimension :attr:`dim` where it is of size 1.
  19532. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  19533. the output tensor having 1 fewer dimension than :attr:`input`.
  19534. Args:
  19535. input (Tensor): the input tensor.
  19536. dim (int, optional): the dimension to reduce.
  19537. If ``None``, all dimensions are reduced.
  19538. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  19539. Keyword args:
  19540. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19541. If specified, the input tensor is casted to :attr:`dtype` before the operation
  19542. is performed. This is useful for preventing data type overflows. Default: None.
  19543. Example::
  19544. >>> a = torch.randn(4, 2)
  19545. >>> a
  19546. tensor([[ 0.5261, -0.3837],
  19547. [ 1.1857, -0.2498],
  19548. [-1.1646, 0.0705],
  19549. [ 1.1131, -1.0629]])
  19550. >>> torch.prod(a, 1)
  19551. tensor([-0.2018, -0.2962, -0.0821, -1.1831])
  19552. """
  19553. @overload
  19554. def prod(
  19555. input: Tensor,
  19556. dim: _int,
  19557. keepdim: _bool = False,
  19558. *,
  19559. dtype: _dtype | None = None,
  19560. out: Tensor | None = None,
  19561. ) -> Tensor:
  19562. r"""
  19563. prod(input: Tensor, *, dtype: Optional[_dtype]) -> Tensor
  19564. Returns the product of all elements in the :attr:`input` tensor.
  19565. Args:
  19566. input (Tensor): the input tensor.
  19567. Keyword args:
  19568. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19569. If specified, the input tensor is casted to :attr:`dtype` before the operation
  19570. is performed. This is useful for preventing data type overflows. Default: None.
  19571. Example::
  19572. >>> a = torch.randn(1, 3)
  19573. >>> a
  19574. tensor([[-0.8020, 0.5428, -1.5854]])
  19575. >>> torch.prod(a)
  19576. tensor(0.6902)
  19577. .. function:: prod(input, dim, keepdim=False, *, dtype=None) -> Tensor
  19578. :noindex:
  19579. Returns the product of each row of the :attr:`input` tensor in the given
  19580. dimension :attr:`dim`.
  19581. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  19582. as :attr:`input` except in the dimension :attr:`dim` where it is of size 1.
  19583. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  19584. the output tensor having 1 fewer dimension than :attr:`input`.
  19585. Args:
  19586. input (Tensor): the input tensor.
  19587. dim (int, optional): the dimension to reduce.
  19588. If ``None``, all dimensions are reduced.
  19589. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  19590. Keyword args:
  19591. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19592. If specified, the input tensor is casted to :attr:`dtype` before the operation
  19593. is performed. This is useful for preventing data type overflows. Default: None.
  19594. Example::
  19595. >>> a = torch.randn(4, 2)
  19596. >>> a
  19597. tensor([[ 0.5261, -0.3837],
  19598. [ 1.1857, -0.2498],
  19599. [-1.1646, 0.0705],
  19600. [ 1.1131, -1.0629]])
  19601. >>> torch.prod(a, 1)
  19602. tensor([-0.2018, -0.2962, -0.0821, -1.1831])
  19603. """
  19604. @overload
  19605. def prod(
  19606. input: Tensor,
  19607. dim: str | EllipsisType | None,
  19608. keepdim: _bool = False,
  19609. *,
  19610. dtype: _dtype | None = None,
  19611. out: Tensor | None = None,
  19612. ) -> Tensor:
  19613. r"""
  19614. prod(input: Tensor, *, dtype: Optional[_dtype]) -> Tensor
  19615. Returns the product of all elements in the :attr:`input` tensor.
  19616. Args:
  19617. input (Tensor): the input tensor.
  19618. Keyword args:
  19619. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19620. If specified, the input tensor is casted to :attr:`dtype` before the operation
  19621. is performed. This is useful for preventing data type overflows. Default: None.
  19622. Example::
  19623. >>> a = torch.randn(1, 3)
  19624. >>> a
  19625. tensor([[-0.8020, 0.5428, -1.5854]])
  19626. >>> torch.prod(a)
  19627. tensor(0.6902)
  19628. .. function:: prod(input, dim, keepdim=False, *, dtype=None) -> Tensor
  19629. :noindex:
  19630. Returns the product of each row of the :attr:`input` tensor in the given
  19631. dimension :attr:`dim`.
  19632. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  19633. as :attr:`input` except in the dimension :attr:`dim` where it is of size 1.
  19634. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
  19635. the output tensor having 1 fewer dimension than :attr:`input`.
  19636. Args:
  19637. input (Tensor): the input tensor.
  19638. dim (int, optional): the dimension to reduce.
  19639. If ``None``, all dimensions are reduced.
  19640. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  19641. Keyword args:
  19642. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  19643. If specified, the input tensor is casted to :attr:`dtype` before the operation
  19644. is performed. This is useful for preventing data type overflows. Default: None.
  19645. Example::
  19646. >>> a = torch.randn(4, 2)
  19647. >>> a
  19648. tensor([[ 0.5261, -0.3837],
  19649. [ 1.1857, -0.2498],
  19650. [-1.1646, 0.0705],
  19651. [ 1.1131, -1.0629]])
  19652. >>> torch.prod(a, 1)
  19653. tensor([-0.2018, -0.2962, -0.0821, -1.1831])
  19654. """
  19655. def promote_types(type1: _dtype, type2: _dtype) -> _dtype:
  19656. r"""
  19657. promote_types(type1, type2) -> dtype
  19658. Returns the :class:`torch.dtype` with the smallest size and scalar kind that is
  19659. not smaller nor of lower kind than either `type1` or `type2`. See type promotion
  19660. :ref:`documentation <type-promotion-doc>` for more information on the type
  19661. promotion logic.
  19662. Args:
  19663. type1 (:class:`torch.dtype`)
  19664. type2 (:class:`torch.dtype`)
  19665. Example::
  19666. >>> torch.promote_types(torch.int32, torch.float32)
  19667. torch.float32
  19668. >>> torch.promote_types(torch.uint8, torch.long)
  19669. torch.long
  19670. """
  19671. def put(
  19672. input: Tensor,
  19673. index: Tensor,
  19674. source: Tensor,
  19675. accumulate: _bool = False,
  19676. ) -> Tensor: ...
  19677. def q_per_channel_axis(input: Tensor) -> _int: ...
  19678. def q_per_channel_scales(input: Tensor) -> Tensor: ...
  19679. def q_per_channel_zero_points(input: Tensor) -> Tensor: ...
  19680. def q_scale(input: Tensor) -> _float: ...
  19681. def q_zero_point(input: Tensor) -> _int: ...
  19682. def qr(
  19683. input: Tensor,
  19684. some: _bool = True,
  19685. *,
  19686. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  19687. ) -> torch.return_types.qr:
  19688. r"""
  19689. qr(input: Tensor, some: bool = True, *, out: Union[Tensor, Tuple[Tensor, ...], List[Tensor], None]) -> (Tensor, Tensor)
  19690. Computes the QR decomposition of a matrix or a batch of matrices :attr:`input`,
  19691. and returns a namedtuple (Q, R) of tensors such that :math:`\text{input} = Q R`
  19692. with :math:`Q` being an orthogonal matrix or batch of orthogonal matrices and
  19693. :math:`R` being an upper triangular matrix or batch of upper triangular matrices.
  19694. If :attr:`some` is ``True``, then this function returns the thin (reduced) QR factorization.
  19695. Otherwise, if :attr:`some` is ``False``, this function returns the complete QR factorization.
  19696. .. warning::
  19697. :func:`torch.qr` is deprecated in favor of :func:`torch.linalg.qr`
  19698. and will be removed in a future PyTorch release. The boolean parameter :attr:`some` has been
  19699. replaced with a string parameter :attr:`mode`.
  19700. ``Q, R = torch.qr(A)`` should be replaced with
  19701. .. code:: python
  19702. Q, R = torch.linalg.qr(A)
  19703. ``Q, R = torch.qr(A, some=False)`` should be replaced with
  19704. .. code:: python
  19705. Q, R = torch.linalg.qr(A, mode="complete")
  19706. .. warning::
  19707. If you plan to backpropagate through QR, note that the current backward implementation
  19708. is only well-defined when the first :math:`\min(input.size(-1), input.size(-2))`
  19709. columns of :attr:`input` are linearly independent.
  19710. This behavior will probably change once QR supports pivoting.
  19711. .. note:: This function uses LAPACK for CPU inputs and MAGMA for CUDA inputs,
  19712. and may produce different (valid) decompositions on different device types
  19713. or different platforms.
  19714. Args:
  19715. input (Tensor): the input tensor of size :math:`(*, m, n)` where `*` is zero or more
  19716. batch dimensions consisting of matrices of dimension :math:`m \times n`.
  19717. some (bool, optional): Set to ``True`` for reduced QR decomposition and ``False`` for
  19718. complete QR decomposition. If `k = min(m, n)` then:
  19719. * ``some=True`` : returns `(Q, R)` with dimensions (m, k), (k, n) (default)
  19720. * ``'some=False'``: returns `(Q, R)` with dimensions (m, m), (m, n)
  19721. Keyword args:
  19722. out (tuple, optional): tuple of `Q` and `R` tensors.
  19723. The dimensions of `Q` and `R` are detailed in the description of :attr:`some` above.
  19724. Example::
  19725. >>> a = torch.tensor([[12., -51, 4], [6, 167, -68], [-4, 24, -41]])
  19726. >>> q, r = torch.qr(a)
  19727. >>> q
  19728. tensor([[-0.8571, 0.3943, 0.3314],
  19729. [-0.4286, -0.9029, -0.0343],
  19730. [ 0.2857, -0.1714, 0.9429]])
  19731. >>> r
  19732. tensor([[ -14.0000, -21.0000, 14.0000],
  19733. [ 0.0000, -175.0000, 70.0000],
  19734. [ 0.0000, 0.0000, -35.0000]])
  19735. >>> torch.mm(q, r).round()
  19736. tensor([[ 12., -51., 4.],
  19737. [ 6., 167., -68.],
  19738. [ -4., 24., -41.]])
  19739. >>> torch.mm(q.t(), q).round()
  19740. tensor([[ 1., 0., 0.],
  19741. [ 0., 1., -0.],
  19742. [ 0., -0., 1.]])
  19743. >>> a = torch.randn(3, 4, 5)
  19744. >>> q, r = torch.qr(a, some=False)
  19745. >>> torch.allclose(torch.matmul(q, r), a)
  19746. True
  19747. >>> torch.allclose(torch.matmul(q.mT, q), torch.eye(5))
  19748. True
  19749. """
  19750. @overload
  19751. def quantile(
  19752. input: Tensor,
  19753. q: Tensor,
  19754. dim: _int | None = None,
  19755. keepdim: _bool = False,
  19756. *,
  19757. interpolation: str = "linear",
  19758. out: Tensor | None = None,
  19759. ) -> Tensor:
  19760. r"""
  19761. quantile(input, q, dim=None, keepdim=False, *, interpolation='linear', out=None) -> Tensor
  19762. Computes the q-th quantiles of each row of the :attr:`input` tensor along the dimension :attr:`dim`.
  19763. To compute the quantile, we map q in [0, 1] to the range of indices [0, n] to find the location
  19764. of the quantile in the sorted input. If the quantile lies between two data points ``a < b`` with
  19765. indices ``i`` and ``j`` in the sorted order, result is computed according to the given
  19766. :attr:`interpolation` method as follows:
  19767. - ``linear``: ``a + (b - a) * fraction``, where ``fraction`` is the fractional part of the computed quantile index.
  19768. - ``lower``: ``a``.
  19769. - ``higher``: ``b``.
  19770. - ``nearest``: ``a`` or ``b``, whichever's index is closer to the computed quantile index (follows :func:`torch.round`).
  19771. - ``midpoint``: ``(a + b) / 2``.
  19772. If :attr:`q` is a 1D tensor, the first dimension of the output represents the quantiles and has size
  19773. equal to the size of :attr:`q`, the remaining dimensions are what remains from the reduction.
  19774. .. note::
  19775. By default :attr:`dim` is ``None`` resulting in the :attr:`input` tensor being flattened before computation.
  19776. Args:
  19777. input (Tensor): the input tensor.
  19778. q (float or Tensor): a scalar or 1D tensor of values in the range [0, 1].
  19779. dim (int, optional): the dimension to reduce.
  19780. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  19781. Keyword arguments:
  19782. interpolation (str, optional): interpolation method to use when the desired quantile lies between two data points.
  19783. Can be ``linear``, ``lower``, ``higher``, ``midpoint`` and ``nearest``.
  19784. Default is ``linear``.
  19785. out (Tensor, optional): the output tensor.
  19786. Example::
  19787. >>> a = torch.randn(2, 3)
  19788. >>> a
  19789. tensor([[ 0.0795, -1.2117, 0.9765],
  19790. [ 1.1707, 0.6706, 0.4884]])
  19791. >>> q = torch.tensor([0.25, 0.5, 0.75])
  19792. >>> torch.quantile(a, q, dim=1, keepdim=True)
  19793. tensor([[[-0.5661],
  19794. [ 0.5795]],
  19795. [[ 0.0795],
  19796. [ 0.6706]],
  19797. [[ 0.5280],
  19798. [ 0.9206]]])
  19799. >>> torch.quantile(a, q, dim=1, keepdim=True).shape
  19800. torch.Size([3, 2, 1])
  19801. >>> a = torch.arange(4.)
  19802. >>> a
  19803. tensor([0., 1., 2., 3.])
  19804. >>> torch.quantile(a, 0.6, interpolation='linear')
  19805. tensor(1.8000)
  19806. >>> torch.quantile(a, 0.6, interpolation='lower')
  19807. tensor(1.)
  19808. >>> torch.quantile(a, 0.6, interpolation='higher')
  19809. tensor(2.)
  19810. >>> torch.quantile(a, 0.6, interpolation='midpoint')
  19811. tensor(1.5000)
  19812. >>> torch.quantile(a, 0.6, interpolation='nearest')
  19813. tensor(2.)
  19814. >>> torch.quantile(a, 0.4, interpolation='nearest')
  19815. tensor(1.)
  19816. """
  19817. @overload
  19818. def quantile(
  19819. input: Tensor,
  19820. q: _float,
  19821. dim: _int | None = None,
  19822. keepdim: _bool = False,
  19823. *,
  19824. interpolation: str = "linear",
  19825. out: Tensor | None = None,
  19826. ) -> Tensor:
  19827. r"""
  19828. quantile(input, q, dim=None, keepdim=False, *, interpolation='linear', out=None) -> Tensor
  19829. Computes the q-th quantiles of each row of the :attr:`input` tensor along the dimension :attr:`dim`.
  19830. To compute the quantile, we map q in [0, 1] to the range of indices [0, n] to find the location
  19831. of the quantile in the sorted input. If the quantile lies between two data points ``a < b`` with
  19832. indices ``i`` and ``j`` in the sorted order, result is computed according to the given
  19833. :attr:`interpolation` method as follows:
  19834. - ``linear``: ``a + (b - a) * fraction``, where ``fraction`` is the fractional part of the computed quantile index.
  19835. - ``lower``: ``a``.
  19836. - ``higher``: ``b``.
  19837. - ``nearest``: ``a`` or ``b``, whichever's index is closer to the computed quantile index (follows :func:`torch.round`).
  19838. - ``midpoint``: ``(a + b) / 2``.
  19839. If :attr:`q` is a 1D tensor, the first dimension of the output represents the quantiles and has size
  19840. equal to the size of :attr:`q`, the remaining dimensions are what remains from the reduction.
  19841. .. note::
  19842. By default :attr:`dim` is ``None`` resulting in the :attr:`input` tensor being flattened before computation.
  19843. Args:
  19844. input (Tensor): the input tensor.
  19845. q (float or Tensor): a scalar or 1D tensor of values in the range [0, 1].
  19846. dim (int, optional): the dimension to reduce.
  19847. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  19848. Keyword arguments:
  19849. interpolation (str, optional): interpolation method to use when the desired quantile lies between two data points.
  19850. Can be ``linear``, ``lower``, ``higher``, ``midpoint`` and ``nearest``.
  19851. Default is ``linear``.
  19852. out (Tensor, optional): the output tensor.
  19853. Example::
  19854. >>> a = torch.randn(2, 3)
  19855. >>> a
  19856. tensor([[ 0.0795, -1.2117, 0.9765],
  19857. [ 1.1707, 0.6706, 0.4884]])
  19858. >>> q = torch.tensor([0.25, 0.5, 0.75])
  19859. >>> torch.quantile(a, q, dim=1, keepdim=True)
  19860. tensor([[[-0.5661],
  19861. [ 0.5795]],
  19862. [[ 0.0795],
  19863. [ 0.6706]],
  19864. [[ 0.5280],
  19865. [ 0.9206]]])
  19866. >>> torch.quantile(a, q, dim=1, keepdim=True).shape
  19867. torch.Size([3, 2, 1])
  19868. >>> a = torch.arange(4.)
  19869. >>> a
  19870. tensor([0., 1., 2., 3.])
  19871. >>> torch.quantile(a, 0.6, interpolation='linear')
  19872. tensor(1.8000)
  19873. >>> torch.quantile(a, 0.6, interpolation='lower')
  19874. tensor(1.)
  19875. >>> torch.quantile(a, 0.6, interpolation='higher')
  19876. tensor(2.)
  19877. >>> torch.quantile(a, 0.6, interpolation='midpoint')
  19878. tensor(1.5000)
  19879. >>> torch.quantile(a, 0.6, interpolation='nearest')
  19880. tensor(2.)
  19881. >>> torch.quantile(a, 0.4, interpolation='nearest')
  19882. tensor(1.)
  19883. """
  19884. def quantize_per_channel(
  19885. input: Tensor,
  19886. scales: Tensor,
  19887. zero_points: Tensor,
  19888. axis: _int,
  19889. dtype: _dtype,
  19890. ) -> Tensor:
  19891. r"""
  19892. quantize_per_channel(input, scales, zero_points, axis, dtype) -> Tensor
  19893. Converts a float tensor to a per-channel quantized tensor with given scales and zero points.
  19894. Arguments:
  19895. input (Tensor): float tensor to quantize
  19896. scales (Tensor): float 1D tensor of scales to use, size should match ``input.size(axis)``
  19897. zero_points (int): integer 1D tensor of offset to use, size should match ``input.size(axis)``
  19898. axis (int): dimension on which apply per-channel quantization
  19899. dtype (:class:`torch.dtype`): the desired data type of returned tensor.
  19900. Has to be one of the quantized dtypes: ``torch.quint8``, ``torch.qint8``, ``torch.qint32``
  19901. Returns:
  19902. Tensor: A newly quantized tensor
  19903. Example::
  19904. >>> x = torch.tensor([[-1.0, 0.0], [1.0, 2.0]])
  19905. >>> torch.quantize_per_channel(x, torch.tensor([0.1, 0.01]), torch.tensor([10, 0]), 0, torch.quint8)
  19906. tensor([[-1., 0.],
  19907. [ 1., 2.]], size=(2, 2), dtype=torch.quint8,
  19908. quantization_scheme=torch.per_channel_affine,
  19909. scale=tensor([0.1000, 0.0100], dtype=torch.float64),
  19910. zero_point=tensor([10, 0]), axis=0)
  19911. >>> torch.quantize_per_channel(x, torch.tensor([0.1, 0.01]), torch.tensor([10, 0]), 0, torch.quint8).int_repr()
  19912. tensor([[ 0, 10],
  19913. [100, 200]], dtype=torch.uint8)
  19914. """
  19915. @overload
  19916. def quantize_per_tensor(
  19917. input: Tensor,
  19918. scale: Tensor,
  19919. zero_point: Tensor,
  19920. dtype: _dtype,
  19921. ) -> Tensor:
  19922. r"""
  19923. quantize_per_tensor(input, scale, zero_point, dtype) -> Tensor
  19924. Converts a float tensor to a quantized tensor with given scale and zero point.
  19925. Arguments:
  19926. input (Tensor): float tensor or list of tensors to quantize
  19927. scale (float or Tensor): scale to apply in quantization formula
  19928. zero_point (int or Tensor): offset in integer value that maps to float zero
  19929. dtype (:class:`torch.dtype`): the desired data type of returned tensor.
  19930. Has to be one of the quantized dtypes: ``torch.quint8``, ``torch.qint8``, ``torch.qint32``
  19931. Returns:
  19932. Tensor: A newly quantized tensor or list of quantized tensors.
  19933. Example::
  19934. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8)
  19935. tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
  19936. quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10)
  19937. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8).int_repr()
  19938. tensor([ 0, 10, 20, 30], dtype=torch.uint8)
  19939. >>> torch.quantize_per_tensor([torch.tensor([-1.0, 0.0]), torch.tensor([-2.0, 2.0])],
  19940. >>> torch.tensor([0.1, 0.2]), torch.tensor([10, 20]), torch.quint8)
  19941. (tensor([-1., 0.], size=(2,), dtype=torch.quint8,
  19942. quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10),
  19943. tensor([-2., 2.], size=(2,), dtype=torch.quint8,
  19944. quantization_scheme=torch.per_tensor_affine, scale=0.2, zero_point=20))
  19945. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), torch.tensor(0.1), torch.tensor(10), torch.quint8)
  19946. tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
  19947. quantization_scheme=torch.per_tensor_affine, scale=0.10, zero_point=10)
  19948. """
  19949. @overload
  19950. def quantize_per_tensor(
  19951. input: Tensor,
  19952. scale: _float,
  19953. zero_point: _int,
  19954. dtype: _dtype,
  19955. ) -> Tensor:
  19956. r"""
  19957. quantize_per_tensor(input, scale, zero_point, dtype) -> Tensor
  19958. Converts a float tensor to a quantized tensor with given scale and zero point.
  19959. Arguments:
  19960. input (Tensor): float tensor or list of tensors to quantize
  19961. scale (float or Tensor): scale to apply in quantization formula
  19962. zero_point (int or Tensor): offset in integer value that maps to float zero
  19963. dtype (:class:`torch.dtype`): the desired data type of returned tensor.
  19964. Has to be one of the quantized dtypes: ``torch.quint8``, ``torch.qint8``, ``torch.qint32``
  19965. Returns:
  19966. Tensor: A newly quantized tensor or list of quantized tensors.
  19967. Example::
  19968. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8)
  19969. tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
  19970. quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10)
  19971. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8).int_repr()
  19972. tensor([ 0, 10, 20, 30], dtype=torch.uint8)
  19973. >>> torch.quantize_per_tensor([torch.tensor([-1.0, 0.0]), torch.tensor([-2.0, 2.0])],
  19974. >>> torch.tensor([0.1, 0.2]), torch.tensor([10, 20]), torch.quint8)
  19975. (tensor([-1., 0.], size=(2,), dtype=torch.quint8,
  19976. quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10),
  19977. tensor([-2., 2.], size=(2,), dtype=torch.quint8,
  19978. quantization_scheme=torch.per_tensor_affine, scale=0.2, zero_point=20))
  19979. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), torch.tensor(0.1), torch.tensor(10), torch.quint8)
  19980. tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
  19981. quantization_scheme=torch.per_tensor_affine, scale=0.10, zero_point=10)
  19982. """
  19983. @overload
  19984. def quantize_per_tensor(
  19985. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  19986. scales: Tensor,
  19987. zero_points: Tensor,
  19988. dtype: _dtype,
  19989. ) -> tuple[Tensor, ...]:
  19990. r"""
  19991. quantize_per_tensor(input, scale, zero_point, dtype) -> Tensor
  19992. Converts a float tensor to a quantized tensor with given scale and zero point.
  19993. Arguments:
  19994. input (Tensor): float tensor or list of tensors to quantize
  19995. scale (float or Tensor): scale to apply in quantization formula
  19996. zero_point (int or Tensor): offset in integer value that maps to float zero
  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``, ``torch.qint32``
  19999. Returns:
  20000. Tensor: A newly quantized tensor or list of quantized tensors.
  20001. Example::
  20002. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8)
  20003. tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
  20004. quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10)
  20005. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8).int_repr()
  20006. tensor([ 0, 10, 20, 30], dtype=torch.uint8)
  20007. >>> torch.quantize_per_tensor([torch.tensor([-1.0, 0.0]), torch.tensor([-2.0, 2.0])],
  20008. >>> torch.tensor([0.1, 0.2]), torch.tensor([10, 20]), torch.quint8)
  20009. (tensor([-1., 0.], size=(2,), dtype=torch.quint8,
  20010. quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10),
  20011. tensor([-2., 2.], size=(2,), dtype=torch.quint8,
  20012. quantization_scheme=torch.per_tensor_affine, scale=0.2, zero_point=20))
  20013. >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), torch.tensor(0.1), torch.tensor(10), torch.quint8)
  20014. tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
  20015. quantization_scheme=torch.per_tensor_affine, scale=0.10, zero_point=10)
  20016. """
  20017. def quantize_per_tensor_dynamic(
  20018. input: Tensor,
  20019. dtype: _dtype,
  20020. reduce_range: _bool,
  20021. ) -> Tensor:
  20022. r"""
  20023. quantize_per_tensor_dynamic(input, dtype, reduce_range) -> Tensor
  20024. Converts a float tensor to a quantized tensor with scale and zero_point calculated
  20025. dynamically based on the input.
  20026. Arguments:
  20027. input (Tensor): float tensor or list of tensors to quantize
  20028. dtype (:class:`torch.dtype`): the desired data type of returned tensor.
  20029. Has to be one of the quantized dtypes: ``torch.quint8``, ``torch.qint8``
  20030. reduce_range (bool): a flag to indicate whether to reduce the range of quantized
  20031. data by 1 bit, it's required to avoid instruction overflow for some hardwares
  20032. Returns:
  20033. Tensor: A newly (dynamically) quantized tensor
  20034. Example::
  20035. >>> t = torch.quantize_per_tensor_dynamic(torch.tensor([-1.0, 0.0, 1.0, 2.0]), torch.quint8, False)
  20036. >>> print(t)
  20037. tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
  20038. quantization_scheme=torch.per_tensor_affine, scale=0.011764705882352941,
  20039. zero_point=85)
  20040. >>> t.int_repr()
  20041. tensor([ 0, 85, 170, 255], dtype=torch.uint8)
  20042. """
  20043. def quantized_batch_norm(
  20044. input: Tensor,
  20045. weight: Tensor | None,
  20046. bias: Tensor | None,
  20047. mean: Tensor,
  20048. var: Tensor,
  20049. eps: _float,
  20050. output_scale: _float,
  20051. output_zero_point: _int,
  20052. ) -> Tensor:
  20053. r"""
  20054. quantized_batch_norm(input, weight=None, bias=None, mean, var, eps, output_scale, output_zero_point) -> Tensor
  20055. Applies batch normalization on a 4D (NCHW) quantized tensor.
  20056. .. math::
  20057. y = \frac{x - \mathrm{E}[x]}{\sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta
  20058. Arguments:
  20059. input (Tensor): quantized tensor
  20060. weight (Tensor): float tensor that corresponds to the gamma, size C
  20061. bias (Tensor): float tensor that corresponds to the beta, size C
  20062. mean (Tensor): float mean value in batch normalization, size C
  20063. var (Tensor): float tensor for variance, size C
  20064. eps (float): a value added to the denominator for numerical stability.
  20065. output_scale (float): output quantized tensor scale
  20066. output_zero_point (int): output quantized tensor zero_point
  20067. Returns:
  20068. Tensor: A quantized tensor with batch normalization applied.
  20069. Example::
  20070. >>> qx = torch.quantize_per_tensor(torch.rand(2, 2, 2, 2), 1.5, 3, torch.quint8)
  20071. >>> torch.quantized_batch_norm(qx, torch.ones(2), torch.zeros(2), torch.rand(2), torch.rand(2), 0.00001, 0.2, 2)
  20072. tensor([[[[-0.2000, -0.2000],
  20073. [ 1.6000, -0.2000]],
  20074. [[-0.4000, -0.4000],
  20075. [-0.4000, 0.6000]]],
  20076. [[[-0.2000, -0.2000],
  20077. [-0.2000, -0.2000]],
  20078. [[ 0.6000, -0.4000],
  20079. [ 0.6000, -0.4000]]]], size=(2, 2, 2, 2), dtype=torch.quint8,
  20080. quantization_scheme=torch.per_tensor_affine, scale=0.2, zero_point=2)
  20081. """
  20082. def quantized_gru_cell(
  20083. input: Tensor,
  20084. hx: Tensor,
  20085. w_ih: Tensor,
  20086. w_hh: Tensor,
  20087. b_ih: Tensor,
  20088. b_hh: Tensor,
  20089. packed_ih: Tensor,
  20090. packed_hh: Tensor,
  20091. col_offsets_ih: Tensor,
  20092. col_offsets_hh: Tensor,
  20093. scale_ih: Number | _complex,
  20094. scale_hh: Number | _complex,
  20095. zero_point_ih: Number | _complex,
  20096. zero_point_hh: Number | _complex,
  20097. ) -> Tensor: ...
  20098. def quantized_lstm_cell(
  20099. input: Tensor,
  20100. hx: tuple[Tensor, ...] | list[Tensor] | None,
  20101. w_ih: Tensor,
  20102. w_hh: Tensor,
  20103. b_ih: Tensor,
  20104. b_hh: Tensor,
  20105. packed_ih: Tensor,
  20106. packed_hh: Tensor,
  20107. col_offsets_ih: Tensor,
  20108. col_offsets_hh: Tensor,
  20109. scale_ih: Number | _complex,
  20110. scale_hh: Number | _complex,
  20111. zero_point_ih: Number | _complex,
  20112. zero_point_hh: Number | _complex,
  20113. ) -> tuple[Tensor, Tensor]: ...
  20114. def quantized_max_pool1d(
  20115. input: Tensor,
  20116. kernel_size: _int | _size,
  20117. stride: _int | _size = (),
  20118. padding: _int | _size = 0,
  20119. dilation: _int | _size = 1,
  20120. ceil_mode: _bool = False,
  20121. ) -> Tensor:
  20122. r"""
  20123. quantized_max_pool1d(input, kernel_size, stride=[], padding=0, dilation=1, ceil_mode=False) -> Tensor
  20124. Applies a 1D max pooling over an input quantized tensor composed of several input planes.
  20125. Arguments:
  20126. input (Tensor): quantized tensor
  20127. kernel_size (list of int): the size of the sliding window
  20128. stride (``list of int``, optional): the stride of the sliding window
  20129. padding (``list of int``, optional): padding to be added on both sides, must be >= 0 and <= kernel_size / 2
  20130. dilation (``list of int``, optional): The stride between elements within a sliding window, must be > 0. Default 1
  20131. ceil_mode (bool, optional): If True, will use ceil instead of floor to compute the output shape.
  20132. Defaults to False.
  20133. Returns:
  20134. Tensor: A quantized tensor with max_pool1d applied.
  20135. Example::
  20136. >>> qx = torch.quantize_per_tensor(torch.rand(2, 2), 1.5, 3, torch.quint8)
  20137. >>> torch.quantized_max_pool1d(qx, [2])
  20138. tensor([[0.0000],
  20139. [1.5000]], size=(2, 1), dtype=torch.quint8,
  20140. quantization_scheme=torch.per_tensor_affine, scale=1.5, zero_point=3)
  20141. """
  20142. def quantized_max_pool2d(
  20143. input: Tensor,
  20144. kernel_size: _int | _size,
  20145. stride: _int | _size = (),
  20146. padding: _int | _size = 0,
  20147. dilation: _int | _size = 1,
  20148. ceil_mode: _bool = False,
  20149. ) -> Tensor:
  20150. r"""
  20151. quantized_max_pool2d(input, kernel_size, stride=[], padding=0, dilation=1, ceil_mode=False) -> Tensor
  20152. Applies a 2D max pooling over an input quantized tensor composed of several input planes.
  20153. Arguments:
  20154. input (Tensor): quantized tensor
  20155. kernel_size (``list of int``): the size of the sliding window
  20156. stride (``list of int``, optional): the stride of the sliding window
  20157. padding (``list of int``, optional): padding to be added on both sides, must be >= 0 and <= kernel_size / 2
  20158. dilation (``list of int``, optional): The stride between elements within a sliding window, must be > 0. Default 1
  20159. ceil_mode (bool, optional): If True, will use ceil instead of floor to compute the output shape.
  20160. Defaults to False.
  20161. Returns:
  20162. Tensor: A quantized tensor with max_pool2d applied.
  20163. Example::
  20164. >>> qx = torch.quantize_per_tensor(torch.rand(2, 2, 2, 2), 1.5, 3, torch.quint8)
  20165. >>> torch.quantized_max_pool2d(qx, [2,2])
  20166. tensor([[[[1.5000]],
  20167. [[1.5000]]],
  20168. [[[0.0000]],
  20169. [[0.0000]]]], size=(2, 2, 1, 1), dtype=torch.quint8,
  20170. quantization_scheme=torch.per_tensor_affine, scale=1.5, zero_point=3)
  20171. """
  20172. def quantized_max_pool3d(
  20173. input: Tensor,
  20174. kernel_size: _int | _size,
  20175. stride: _int | _size = (),
  20176. padding: _int | _size = 0,
  20177. dilation: _int | _size = 1,
  20178. ceil_mode: _bool = False,
  20179. ) -> Tensor: ...
  20180. def quantized_rnn_relu_cell(
  20181. input: Tensor,
  20182. hx: Tensor,
  20183. w_ih: Tensor,
  20184. w_hh: Tensor,
  20185. b_ih: Tensor,
  20186. b_hh: Tensor,
  20187. packed_ih: Tensor,
  20188. packed_hh: Tensor,
  20189. col_offsets_ih: Tensor,
  20190. col_offsets_hh: Tensor,
  20191. scale_ih: Number | _complex,
  20192. scale_hh: Number | _complex,
  20193. zero_point_ih: Number | _complex,
  20194. zero_point_hh: Number | _complex,
  20195. ) -> Tensor: ...
  20196. def quantized_rnn_tanh_cell(
  20197. input: Tensor,
  20198. hx: Tensor,
  20199. w_ih: Tensor,
  20200. w_hh: Tensor,
  20201. b_ih: Tensor,
  20202. b_hh: Tensor,
  20203. packed_ih: Tensor,
  20204. packed_hh: Tensor,
  20205. col_offsets_ih: Tensor,
  20206. col_offsets_hh: Tensor,
  20207. scale_ih: Number | _complex,
  20208. scale_hh: Number | _complex,
  20209. zero_point_ih: Number | _complex,
  20210. zero_point_hh: Number | _complex,
  20211. ) -> Tensor: ...
  20212. def rad2deg(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  20213. r"""
  20214. rad2deg(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  20215. Returns a new tensor with each of the elements of :attr:`input`
  20216. converted from angles in radians to degrees.
  20217. Args:
  20218. input (Tensor): the input tensor.
  20219. Keyword arguments:
  20220. out (Tensor, optional): the output tensor.
  20221. Example::
  20222. >>> a = torch.tensor([[3.142, -3.142], [6.283, -6.283], [1.570, -1.570]])
  20223. >>> torch.rad2deg(a)
  20224. tensor([[ 180.0233, -180.0233],
  20225. [ 359.9894, -359.9894],
  20226. [ 89.9544, -89.9544]])
  20227. """
  20228. def rad2deg_(input: Tensor) -> Tensor: ...
  20229. @overload
  20230. def rand(
  20231. size: Sequence[_int | SymInt],
  20232. *,
  20233. generator: Generator | None,
  20234. names: Sequence[str | EllipsisType | None] | None,
  20235. dtype: _dtype | None = None,
  20236. layout: _layout | None = None,
  20237. device: DeviceLikeType | None = None,
  20238. pin_memory: _bool | None = False,
  20239. requires_grad: _bool | None = False,
  20240. ) -> Tensor:
  20241. r"""
  20242. rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  20243. Returns a tensor filled with random numbers from a uniform distribution
  20244. on the interval :math:`[0, 1)`
  20245. The shape of the tensor is defined by the variable argument :attr:`size`.
  20246. Args:
  20247. size (int...): a sequence of integers defining the shape of the output tensor.
  20248. Can be a variable number of arguments or a collection like a list or tuple.
  20249. Keyword args:
  20250. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20251. out (Tensor, optional): the output tensor.
  20252. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  20253. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  20254. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20255. Default: ``torch.strided``.
  20256. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20257. Default: if ``None``, uses the current device for the default tensor type
  20258. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20259. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20260. requires_grad (bool, optional): If autograd should record operations on the
  20261. returned tensor. Default: ``False``.
  20262. pin_memory (bool, optional): If set, returned tensor would be allocated in
  20263. the pinned memory. Works only for CPU tensors. Default: ``False``.
  20264. Example::
  20265. >>> torch.rand(4)
  20266. tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
  20267. >>> torch.rand(2, 3)
  20268. tensor([[ 0.8237, 0.5781, 0.6879],
  20269. [ 0.3816, 0.7249, 0.0998]])
  20270. """
  20271. @overload
  20272. def rand(
  20273. *size: _int | SymInt,
  20274. generator: Generator | None,
  20275. names: Sequence[str | EllipsisType | None] | None,
  20276. dtype: _dtype | None = None,
  20277. layout: _layout | None = None,
  20278. device: DeviceLikeType | None = None,
  20279. pin_memory: _bool | None = False,
  20280. requires_grad: _bool | None = False,
  20281. ) -> Tensor:
  20282. r"""
  20283. rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  20284. Returns a tensor filled with random numbers from a uniform distribution
  20285. on the interval :math:`[0, 1)`
  20286. The shape of the tensor is defined by the variable argument :attr:`size`.
  20287. Args:
  20288. size (int...): a sequence of integers defining the shape of the output tensor.
  20289. Can be a variable number of arguments or a collection like a list or tuple.
  20290. Keyword args:
  20291. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20292. out (Tensor, optional): the output tensor.
  20293. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  20294. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  20295. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20296. Default: ``torch.strided``.
  20297. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20298. Default: if ``None``, uses the current device for the default tensor type
  20299. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20300. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20301. requires_grad (bool, optional): If autograd should record operations on the
  20302. returned tensor. Default: ``False``.
  20303. pin_memory (bool, optional): If set, returned tensor would be allocated in
  20304. the pinned memory. Works only for CPU tensors. Default: ``False``.
  20305. Example::
  20306. >>> torch.rand(4)
  20307. tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
  20308. >>> torch.rand(2, 3)
  20309. tensor([[ 0.8237, 0.5781, 0.6879],
  20310. [ 0.3816, 0.7249, 0.0998]])
  20311. """
  20312. @overload
  20313. def rand(
  20314. size: Sequence[_int | SymInt],
  20315. *,
  20316. generator: Generator | None,
  20317. out: Tensor | None = None,
  20318. dtype: _dtype | None = None,
  20319. layout: _layout | None = None,
  20320. device: DeviceLikeType | None = None,
  20321. pin_memory: _bool | None = False,
  20322. requires_grad: _bool | None = False,
  20323. ) -> Tensor:
  20324. r"""
  20325. rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  20326. Returns a tensor filled with random numbers from a uniform distribution
  20327. on the interval :math:`[0, 1)`
  20328. The shape of the tensor is defined by the variable argument :attr:`size`.
  20329. Args:
  20330. size (int...): a sequence of integers defining the shape of the output tensor.
  20331. Can be a variable number of arguments or a collection like a list or tuple.
  20332. Keyword args:
  20333. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20334. out (Tensor, optional): the output tensor.
  20335. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  20336. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  20337. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20338. Default: ``torch.strided``.
  20339. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20340. Default: if ``None``, uses the current device for the default tensor type
  20341. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20342. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20343. requires_grad (bool, optional): If autograd should record operations on the
  20344. returned tensor. Default: ``False``.
  20345. pin_memory (bool, optional): If set, returned tensor would be allocated in
  20346. the pinned memory. Works only for CPU tensors. Default: ``False``.
  20347. Example::
  20348. >>> torch.rand(4)
  20349. tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
  20350. >>> torch.rand(2, 3)
  20351. tensor([[ 0.8237, 0.5781, 0.6879],
  20352. [ 0.3816, 0.7249, 0.0998]])
  20353. """
  20354. @overload
  20355. def rand(
  20356. *size: _int | SymInt,
  20357. generator: Generator | None,
  20358. out: Tensor | None = None,
  20359. dtype: _dtype | None = None,
  20360. layout: _layout | None = None,
  20361. device: DeviceLikeType | None = None,
  20362. pin_memory: _bool | None = False,
  20363. requires_grad: _bool | None = False,
  20364. ) -> Tensor:
  20365. r"""
  20366. rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  20367. Returns a tensor filled with random numbers from a uniform distribution
  20368. on the interval :math:`[0, 1)`
  20369. The shape of the tensor is defined by the variable argument :attr:`size`.
  20370. Args:
  20371. size (int...): a sequence of integers defining the shape of the output tensor.
  20372. Can be a variable number of arguments or a collection like a list or tuple.
  20373. Keyword args:
  20374. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20375. out (Tensor, optional): the output tensor.
  20376. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  20377. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  20378. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20379. Default: ``torch.strided``.
  20380. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20381. Default: if ``None``, uses the current device for the default tensor type
  20382. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20383. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20384. requires_grad (bool, optional): If autograd should record operations on the
  20385. returned tensor. Default: ``False``.
  20386. pin_memory (bool, optional): If set, returned tensor would be allocated in
  20387. the pinned memory. Works only for CPU tensors. Default: ``False``.
  20388. Example::
  20389. >>> torch.rand(4)
  20390. tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
  20391. >>> torch.rand(2, 3)
  20392. tensor([[ 0.8237, 0.5781, 0.6879],
  20393. [ 0.3816, 0.7249, 0.0998]])
  20394. """
  20395. @overload
  20396. def rand(
  20397. size: Sequence[_int | SymInt],
  20398. *,
  20399. out: Tensor | None = None,
  20400. dtype: _dtype | None = None,
  20401. layout: _layout | None = None,
  20402. device: DeviceLikeType | None = None,
  20403. pin_memory: _bool | None = False,
  20404. requires_grad: _bool | None = False,
  20405. ) -> Tensor:
  20406. r"""
  20407. rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  20408. Returns a tensor filled with random numbers from a uniform distribution
  20409. on the interval :math:`[0, 1)`
  20410. The shape of the tensor is defined by the variable argument :attr:`size`.
  20411. Args:
  20412. size (int...): a sequence of integers defining the shape of the output tensor.
  20413. Can be a variable number of arguments or a collection like a list or tuple.
  20414. Keyword args:
  20415. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20416. out (Tensor, optional): the output tensor.
  20417. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  20418. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  20419. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20420. Default: ``torch.strided``.
  20421. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20422. Default: if ``None``, uses the current device for the default tensor type
  20423. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20424. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20425. requires_grad (bool, optional): If autograd should record operations on the
  20426. returned tensor. Default: ``False``.
  20427. pin_memory (bool, optional): If set, returned tensor would be allocated in
  20428. the pinned memory. Works only for CPU tensors. Default: ``False``.
  20429. Example::
  20430. >>> torch.rand(4)
  20431. tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
  20432. >>> torch.rand(2, 3)
  20433. tensor([[ 0.8237, 0.5781, 0.6879],
  20434. [ 0.3816, 0.7249, 0.0998]])
  20435. """
  20436. @overload
  20437. def rand(
  20438. *size: _int | SymInt,
  20439. out: Tensor | None = None,
  20440. dtype: _dtype | None = None,
  20441. layout: _layout | None = None,
  20442. device: DeviceLikeType | None = None,
  20443. pin_memory: _bool | None = False,
  20444. requires_grad: _bool | None = False,
  20445. ) -> Tensor:
  20446. r"""
  20447. rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  20448. Returns a tensor filled with random numbers from a uniform distribution
  20449. on the interval :math:`[0, 1)`
  20450. The shape of the tensor is defined by the variable argument :attr:`size`.
  20451. Args:
  20452. size (int...): a sequence of integers defining the shape of the output tensor.
  20453. Can be a variable number of arguments or a collection like a list or tuple.
  20454. Keyword args:
  20455. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20456. out (Tensor, optional): the output tensor.
  20457. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  20458. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  20459. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20460. Default: ``torch.strided``.
  20461. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20462. Default: if ``None``, uses the current device for the default tensor type
  20463. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20464. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20465. requires_grad (bool, optional): If autograd should record operations on the
  20466. returned tensor. Default: ``False``.
  20467. pin_memory (bool, optional): If set, returned tensor would be allocated in
  20468. the pinned memory. Works only for CPU tensors. Default: ``False``.
  20469. Example::
  20470. >>> torch.rand(4)
  20471. tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
  20472. >>> torch.rand(2, 3)
  20473. tensor([[ 0.8237, 0.5781, 0.6879],
  20474. [ 0.3816, 0.7249, 0.0998]])
  20475. """
  20476. @overload
  20477. def rand(
  20478. size: Sequence[_int | SymInt],
  20479. *,
  20480. names: Sequence[str | EllipsisType | None] | None,
  20481. dtype: _dtype | None = None,
  20482. layout: _layout | None = None,
  20483. device: DeviceLikeType | None = None,
  20484. pin_memory: _bool | None = False,
  20485. requires_grad: _bool | None = False,
  20486. ) -> Tensor:
  20487. r"""
  20488. rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  20489. Returns a tensor filled with random numbers from a uniform distribution
  20490. on the interval :math:`[0, 1)`
  20491. The shape of the tensor is defined by the variable argument :attr:`size`.
  20492. Args:
  20493. size (int...): a sequence of integers defining the shape of the output tensor.
  20494. Can be a variable number of arguments or a collection like a list or tuple.
  20495. Keyword args:
  20496. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20497. out (Tensor, optional): the output tensor.
  20498. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  20499. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  20500. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20501. Default: ``torch.strided``.
  20502. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20503. Default: if ``None``, uses the current device for the default tensor type
  20504. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20505. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20506. requires_grad (bool, optional): If autograd should record operations on the
  20507. returned tensor. Default: ``False``.
  20508. pin_memory (bool, optional): If set, returned tensor would be allocated in
  20509. the pinned memory. Works only for CPU tensors. Default: ``False``.
  20510. Example::
  20511. >>> torch.rand(4)
  20512. tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
  20513. >>> torch.rand(2, 3)
  20514. tensor([[ 0.8237, 0.5781, 0.6879],
  20515. [ 0.3816, 0.7249, 0.0998]])
  20516. """
  20517. @overload
  20518. def rand(
  20519. *size: _int | SymInt,
  20520. names: Sequence[str | EllipsisType | None] | None,
  20521. dtype: _dtype | None = None,
  20522. layout: _layout | None = None,
  20523. device: DeviceLikeType | None = None,
  20524. pin_memory: _bool | None = False,
  20525. requires_grad: _bool | None = False,
  20526. ) -> Tensor:
  20527. r"""
  20528. rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  20529. Returns a tensor filled with random numbers from a uniform distribution
  20530. on the interval :math:`[0, 1)`
  20531. The shape of the tensor is defined by the variable argument :attr:`size`.
  20532. Args:
  20533. size (int...): a sequence of integers defining the shape of the output tensor.
  20534. Can be a variable number of arguments or a collection like a list or tuple.
  20535. Keyword args:
  20536. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20537. out (Tensor, optional): the output tensor.
  20538. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  20539. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  20540. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20541. Default: ``torch.strided``.
  20542. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20543. Default: if ``None``, uses the current device for the default tensor type
  20544. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20545. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20546. requires_grad (bool, optional): If autograd should record operations on the
  20547. returned tensor. Default: ``False``.
  20548. pin_memory (bool, optional): If set, returned tensor would be allocated in
  20549. the pinned memory. Works only for CPU tensors. Default: ``False``.
  20550. Example::
  20551. >>> torch.rand(4)
  20552. tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
  20553. >>> torch.rand(2, 3)
  20554. tensor([[ 0.8237, 0.5781, 0.6879],
  20555. [ 0.3816, 0.7249, 0.0998]])
  20556. """
  20557. @overload
  20558. def rand_like(
  20559. input: Tensor,
  20560. *,
  20561. generator: Generator | None,
  20562. memory_format: memory_format | None = None,
  20563. dtype: _dtype | None = None,
  20564. layout: _layout | None = None,
  20565. device: DeviceLikeType | None = None,
  20566. pin_memory: _bool | None = False,
  20567. requires_grad: _bool | None = False,
  20568. ) -> Tensor:
  20569. r"""
  20570. rand_like(input, *, generator=None, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  20571. Returns a tensor with the same size as :attr:`input` that is filled with
  20572. random numbers from a uniform distribution on the interval :math:`[0, 1)`.
  20573. ``torch.rand_like(input)`` is equivalent to
  20574. ``torch.rand(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
  20575. Args:
  20576. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  20577. Keyword args:
  20578. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
  20579. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  20580. Default: if ``None``, defaults to the dtype of :attr:`input`.
  20581. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  20582. Default: if ``None``, defaults to the layout of :attr:`input`.
  20583. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20584. Default: if ``None``, defaults to the device of :attr:`input`.
  20585. requires_grad (bool, optional): If autograd should record operations on the
  20586. returned tensor. Default: ``False``.
  20587. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  20588. returned Tensor. Default: ``torch.preserve_format``.
  20589. """
  20590. @overload
  20591. def rand_like(
  20592. input: Tensor,
  20593. *,
  20594. memory_format: memory_format | None = None,
  20595. dtype: _dtype | None = None,
  20596. layout: _layout | None = None,
  20597. device: DeviceLikeType | None = None,
  20598. pin_memory: _bool | None = False,
  20599. requires_grad: _bool | None = False,
  20600. ) -> Tensor:
  20601. r"""
  20602. rand_like(input, *, generator=None, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  20603. Returns a tensor with the same size as :attr:`input` that is filled with
  20604. random numbers from a uniform distribution on the interval :math:`[0, 1)`.
  20605. ``torch.rand_like(input)`` is equivalent to
  20606. ``torch.rand(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
  20607. Args:
  20608. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  20609. Keyword args:
  20610. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
  20611. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  20612. Default: if ``None``, defaults to the dtype of :attr:`input`.
  20613. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  20614. Default: if ``None``, defaults to the layout of :attr:`input`.
  20615. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20616. Default: if ``None``, defaults to the device of :attr:`input`.
  20617. requires_grad (bool, optional): If autograd should record operations on the
  20618. returned tensor. Default: ``False``.
  20619. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  20620. returned Tensor. Default: ``torch.preserve_format``.
  20621. """
  20622. @overload
  20623. def randint(
  20624. low: _int,
  20625. high: _int,
  20626. size: _size,
  20627. *,
  20628. generator: Generator | None = None,
  20629. dtype: _dtype | None = None,
  20630. device: DeviceLikeType | None = None,
  20631. requires_grad: _bool = False,
  20632. pin_memory: _bool = False,
  20633. ) -> Tensor:
  20634. r"""
  20635. randint(low=0, high, size, \*, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  20636. Returns a tensor filled with random integers generated uniformly
  20637. between :attr:`low` (inclusive) and :attr:`high` (exclusive).
  20638. The shape of the tensor is defined by the variable argument :attr:`size`.
  20639. .. note::
  20640. With the global dtype default (``torch.float32``), this function returns
  20641. a tensor with dtype ``torch.int64``.
  20642. Args:
  20643. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  20644. high (int): One above the highest integer to be drawn from the distribution.
  20645. size (tuple): a tuple defining the shape of the output tensor.
  20646. Keyword args:
  20647. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20648. out (Tensor, optional): the output tensor.
  20649. dtype (torch.dtype, optional): the desired data type of returned tensor. Default: if ``None``,
  20650. this function returns a tensor with dtype ``torch.int64``.
  20651. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20652. Default: ``torch.strided``.
  20653. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20654. Default: if ``None``, uses the current device for the default tensor type
  20655. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20656. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20657. requires_grad (bool, optional): If autograd should record operations on the
  20658. returned tensor. Default: ``False``.
  20659. Example::
  20660. >>> torch.randint(3, 5, (3,))
  20661. tensor([4, 3, 4])
  20662. >>> torch.randint(10, (2, 2))
  20663. tensor([[0, 2],
  20664. [5, 5]])
  20665. >>> torch.randint(3, 10, (2, 2))
  20666. tensor([[4, 5],
  20667. [6, 7]])
  20668. """
  20669. @overload
  20670. def randint(
  20671. high: _int,
  20672. size: _size,
  20673. *,
  20674. generator: Generator | None = None,
  20675. dtype: _dtype | None = None,
  20676. device: DeviceLikeType | None = None,
  20677. requires_grad: _bool = False,
  20678. pin_memory: _bool = False,
  20679. ) -> Tensor:
  20680. r"""
  20681. randint(low=0, high, size, \*, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  20682. Returns a tensor filled with random integers generated uniformly
  20683. between :attr:`low` (inclusive) and :attr:`high` (exclusive).
  20684. The shape of the tensor is defined by the variable argument :attr:`size`.
  20685. .. note::
  20686. With the global dtype default (``torch.float32``), this function returns
  20687. a tensor with dtype ``torch.int64``.
  20688. Args:
  20689. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  20690. high (int): One above the highest integer to be drawn from the distribution.
  20691. size (tuple): a tuple defining the shape of the output tensor.
  20692. Keyword args:
  20693. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20694. out (Tensor, optional): the output tensor.
  20695. dtype (torch.dtype, optional): the desired data type of returned tensor. Default: if ``None``,
  20696. this function returns a tensor with dtype ``torch.int64``.
  20697. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20698. Default: ``torch.strided``.
  20699. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20700. Default: if ``None``, uses the current device for the default tensor type
  20701. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20702. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20703. requires_grad (bool, optional): If autograd should record operations on the
  20704. returned tensor. Default: ``False``.
  20705. Example::
  20706. >>> torch.randint(3, 5, (3,))
  20707. tensor([4, 3, 4])
  20708. >>> torch.randint(10, (2, 2))
  20709. tensor([[0, 2],
  20710. [5, 5]])
  20711. >>> torch.randint(3, 10, (2, 2))
  20712. tensor([[4, 5],
  20713. [6, 7]])
  20714. """
  20715. @overload
  20716. def randint(
  20717. high: _int | SymInt,
  20718. size: Sequence[_int | SymInt],
  20719. *,
  20720. generator: Generator | None,
  20721. out: Tensor | None = None,
  20722. dtype: _dtype | None = None,
  20723. layout: _layout | None = None,
  20724. device: DeviceLikeType | None = None,
  20725. pin_memory: _bool | None = False,
  20726. requires_grad: _bool | None = False,
  20727. ) -> Tensor:
  20728. r"""
  20729. randint(low=0, high, size, \*, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  20730. Returns a tensor filled with random integers generated uniformly
  20731. between :attr:`low` (inclusive) and :attr:`high` (exclusive).
  20732. The shape of the tensor is defined by the variable argument :attr:`size`.
  20733. .. note::
  20734. With the global dtype default (``torch.float32``), this function returns
  20735. a tensor with dtype ``torch.int64``.
  20736. Args:
  20737. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  20738. high (int): One above the highest integer to be drawn from the distribution.
  20739. size (tuple): a tuple defining the shape of the output tensor.
  20740. Keyword args:
  20741. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20742. out (Tensor, optional): the output tensor.
  20743. dtype (torch.dtype, optional): the desired data type of returned tensor. Default: if ``None``,
  20744. this function returns a tensor with dtype ``torch.int64``.
  20745. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20746. Default: ``torch.strided``.
  20747. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20748. Default: if ``None``, uses the current device for the default tensor type
  20749. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20750. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20751. requires_grad (bool, optional): If autograd should record operations on the
  20752. returned tensor. Default: ``False``.
  20753. Example::
  20754. >>> torch.randint(3, 5, (3,))
  20755. tensor([4, 3, 4])
  20756. >>> torch.randint(10, (2, 2))
  20757. tensor([[0, 2],
  20758. [5, 5]])
  20759. >>> torch.randint(3, 10, (2, 2))
  20760. tensor([[4, 5],
  20761. [6, 7]])
  20762. """
  20763. @overload
  20764. def randint(
  20765. high: _int | SymInt,
  20766. size: Sequence[_int | SymInt],
  20767. *,
  20768. out: Tensor | None = None,
  20769. dtype: _dtype | None = None,
  20770. layout: _layout | None = None,
  20771. device: DeviceLikeType | None = None,
  20772. pin_memory: _bool | None = False,
  20773. requires_grad: _bool | None = False,
  20774. ) -> Tensor:
  20775. r"""
  20776. randint(low=0, high, size, \*, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  20777. Returns a tensor filled with random integers generated uniformly
  20778. between :attr:`low` (inclusive) and :attr:`high` (exclusive).
  20779. The shape of the tensor is defined by the variable argument :attr:`size`.
  20780. .. note::
  20781. With the global dtype default (``torch.float32``), this function returns
  20782. a tensor with dtype ``torch.int64``.
  20783. Args:
  20784. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  20785. high (int): One above the highest integer to be drawn from the distribution.
  20786. size (tuple): a tuple defining the shape of the output tensor.
  20787. Keyword args:
  20788. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20789. out (Tensor, optional): the output tensor.
  20790. dtype (torch.dtype, optional): the desired data type of returned tensor. Default: if ``None``,
  20791. this function returns a tensor with dtype ``torch.int64``.
  20792. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20793. Default: ``torch.strided``.
  20794. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20795. Default: if ``None``, uses the current device for the default tensor type
  20796. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20797. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20798. requires_grad (bool, optional): If autograd should record operations on the
  20799. returned tensor. Default: ``False``.
  20800. Example::
  20801. >>> torch.randint(3, 5, (3,))
  20802. tensor([4, 3, 4])
  20803. >>> torch.randint(10, (2, 2))
  20804. tensor([[0, 2],
  20805. [5, 5]])
  20806. >>> torch.randint(3, 10, (2, 2))
  20807. tensor([[4, 5],
  20808. [6, 7]])
  20809. """
  20810. @overload
  20811. def randint(
  20812. low: _int | SymInt,
  20813. high: _int | SymInt,
  20814. size: Sequence[_int | SymInt],
  20815. *,
  20816. generator: Generator | None,
  20817. out: Tensor | None = None,
  20818. dtype: _dtype | None = None,
  20819. layout: _layout | None = None,
  20820. device: DeviceLikeType | None = None,
  20821. pin_memory: _bool | None = False,
  20822. requires_grad: _bool | None = False,
  20823. ) -> Tensor:
  20824. r"""
  20825. randint(low=0, high, size, \*, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  20826. Returns a tensor filled with random integers generated uniformly
  20827. between :attr:`low` (inclusive) and :attr:`high` (exclusive).
  20828. The shape of the tensor is defined by the variable argument :attr:`size`.
  20829. .. note::
  20830. With the global dtype default (``torch.float32``), this function returns
  20831. a tensor with dtype ``torch.int64``.
  20832. Args:
  20833. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  20834. high (int): One above the highest integer to be drawn from the distribution.
  20835. size (tuple): a tuple defining the shape of the output tensor.
  20836. Keyword args:
  20837. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20838. out (Tensor, optional): the output tensor.
  20839. dtype (torch.dtype, optional): the desired data type of returned tensor. Default: if ``None``,
  20840. this function returns a tensor with dtype ``torch.int64``.
  20841. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20842. Default: ``torch.strided``.
  20843. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20844. Default: if ``None``, uses the current device for the default tensor type
  20845. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20846. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20847. requires_grad (bool, optional): If autograd should record operations on the
  20848. returned tensor. Default: ``False``.
  20849. Example::
  20850. >>> torch.randint(3, 5, (3,))
  20851. tensor([4, 3, 4])
  20852. >>> torch.randint(10, (2, 2))
  20853. tensor([[0, 2],
  20854. [5, 5]])
  20855. >>> torch.randint(3, 10, (2, 2))
  20856. tensor([[4, 5],
  20857. [6, 7]])
  20858. """
  20859. @overload
  20860. def randint(
  20861. low: _int | SymInt,
  20862. high: _int | SymInt,
  20863. size: Sequence[_int | SymInt],
  20864. *,
  20865. out: Tensor | None = None,
  20866. dtype: _dtype | None = None,
  20867. layout: _layout | None = None,
  20868. device: DeviceLikeType | None = None,
  20869. pin_memory: _bool | None = False,
  20870. requires_grad: _bool | None = False,
  20871. ) -> Tensor:
  20872. r"""
  20873. randint(low=0, high, size, \*, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  20874. Returns a tensor filled with random integers generated uniformly
  20875. between :attr:`low` (inclusive) and :attr:`high` (exclusive).
  20876. The shape of the tensor is defined by the variable argument :attr:`size`.
  20877. .. note::
  20878. With the global dtype default (``torch.float32``), this function returns
  20879. a tensor with dtype ``torch.int64``.
  20880. Args:
  20881. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  20882. high (int): One above the highest integer to be drawn from the distribution.
  20883. size (tuple): a tuple defining the shape of the output tensor.
  20884. Keyword args:
  20885. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  20886. out (Tensor, optional): the output tensor.
  20887. dtype (torch.dtype, optional): the desired data type of returned tensor. Default: if ``None``,
  20888. this function returns a tensor with dtype ``torch.int64``.
  20889. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  20890. Default: ``torch.strided``.
  20891. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20892. Default: if ``None``, uses the current device for the default tensor type
  20893. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  20894. for CPU tensor types and the current CUDA device for CUDA tensor types.
  20895. requires_grad (bool, optional): If autograd should record operations on the
  20896. returned tensor. Default: ``False``.
  20897. Example::
  20898. >>> torch.randint(3, 5, (3,))
  20899. tensor([4, 3, 4])
  20900. >>> torch.randint(10, (2, 2))
  20901. tensor([[0, 2],
  20902. [5, 5]])
  20903. >>> torch.randint(3, 10, (2, 2))
  20904. tensor([[4, 5],
  20905. [6, 7]])
  20906. """
  20907. @overload
  20908. def randint_like(
  20909. input: Tensor,
  20910. low: _int | SymInt,
  20911. high: _int | SymInt,
  20912. *,
  20913. generator: Generator | None,
  20914. memory_format: memory_format | None = None,
  20915. dtype: _dtype | None = None,
  20916. layout: _layout | None = None,
  20917. device: DeviceLikeType | None = None,
  20918. pin_memory: _bool | None = False,
  20919. requires_grad: _bool | None = False,
  20920. ) -> Tensor:
  20921. r"""
  20922. randint_like(input, low=0, high, \*, generator=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  20923. Returns a tensor with the same shape as Tensor :attr:`input` filled with
  20924. random integers generated uniformly between :attr:`low` (inclusive) and
  20925. :attr:`high` (exclusive).
  20926. .. note:
  20927. With the global dtype default (``torch.float32``), this function returns
  20928. a tensor with dtype ``torch.int64``.
  20929. Args:
  20930. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  20931. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  20932. high (int): One above the highest integer to be drawn from the distribution.
  20933. Keyword args:
  20934. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
  20935. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  20936. Default: if ``None``, defaults to the dtype of :attr:`input`.
  20937. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  20938. Default: if ``None``, defaults to the layout of :attr:`input`.
  20939. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20940. Default: if ``None``, defaults to the device of :attr:`input`.
  20941. requires_grad (bool, optional): If autograd should record operations on the
  20942. returned tensor. Default: ``False``.
  20943. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  20944. returned Tensor. Default: ``torch.preserve_format``.
  20945. """
  20946. @overload
  20947. def randint_like(
  20948. input: Tensor,
  20949. low: _int | SymInt,
  20950. high: _int | SymInt,
  20951. *,
  20952. memory_format: memory_format | None = None,
  20953. dtype: _dtype | None = None,
  20954. layout: _layout | None = None,
  20955. device: DeviceLikeType | None = None,
  20956. pin_memory: _bool | None = False,
  20957. requires_grad: _bool | None = False,
  20958. ) -> Tensor:
  20959. r"""
  20960. randint_like(input, low=0, high, \*, generator=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  20961. Returns a tensor with the same shape as Tensor :attr:`input` filled with
  20962. random integers generated uniformly between :attr:`low` (inclusive) and
  20963. :attr:`high` (exclusive).
  20964. .. note:
  20965. With the global dtype default (``torch.float32``), this function returns
  20966. a tensor with dtype ``torch.int64``.
  20967. Args:
  20968. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  20969. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  20970. high (int): One above the highest integer to be drawn from the distribution.
  20971. Keyword args:
  20972. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
  20973. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  20974. Default: if ``None``, defaults to the dtype of :attr:`input`.
  20975. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  20976. Default: if ``None``, defaults to the layout of :attr:`input`.
  20977. device (:class:`torch.device`, optional): the desired device of returned tensor.
  20978. Default: if ``None``, defaults to the device of :attr:`input`.
  20979. requires_grad (bool, optional): If autograd should record operations on the
  20980. returned tensor. Default: ``False``.
  20981. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  20982. returned Tensor. Default: ``torch.preserve_format``.
  20983. """
  20984. @overload
  20985. def randint_like(
  20986. input: Tensor,
  20987. high: Tensor,
  20988. *,
  20989. generator: Generator | None,
  20990. memory_format: memory_format | None = None,
  20991. dtype: _dtype | None = None,
  20992. layout: _layout | None = None,
  20993. device: DeviceLikeType | None = None,
  20994. pin_memory: _bool | None = False,
  20995. requires_grad: _bool | None = False,
  20996. ) -> Tensor:
  20997. r"""
  20998. randint_like(input, low=0, high, \*, generator=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  20999. Returns a tensor with the same shape as Tensor :attr:`input` filled with
  21000. random integers generated uniformly between :attr:`low` (inclusive) and
  21001. :attr:`high` (exclusive).
  21002. .. note:
  21003. With the global dtype default (``torch.float32``), this function returns
  21004. a tensor with dtype ``torch.int64``.
  21005. Args:
  21006. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  21007. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  21008. high (int): One above the highest integer to be drawn from the distribution.
  21009. Keyword args:
  21010. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
  21011. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  21012. Default: if ``None``, defaults to the dtype of :attr:`input`.
  21013. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  21014. Default: if ``None``, defaults to the layout of :attr:`input`.
  21015. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21016. Default: if ``None``, defaults to the device of :attr:`input`.
  21017. requires_grad (bool, optional): If autograd should record operations on the
  21018. returned tensor. Default: ``False``.
  21019. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  21020. returned Tensor. Default: ``torch.preserve_format``.
  21021. """
  21022. @overload
  21023. def randint_like(
  21024. input: Tensor,
  21025. high: Tensor,
  21026. *,
  21027. memory_format: memory_format | None = None,
  21028. dtype: _dtype | None = None,
  21029. layout: _layout | None = None,
  21030. device: DeviceLikeType | None = None,
  21031. pin_memory: _bool | None = False,
  21032. requires_grad: _bool | None = False,
  21033. ) -> Tensor:
  21034. r"""
  21035. randint_like(input, low=0, high, \*, generator=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  21036. Returns a tensor with the same shape as Tensor :attr:`input` filled with
  21037. random integers generated uniformly between :attr:`low` (inclusive) and
  21038. :attr:`high` (exclusive).
  21039. .. note:
  21040. With the global dtype default (``torch.float32``), this function returns
  21041. a tensor with dtype ``torch.int64``.
  21042. Args:
  21043. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  21044. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  21045. high (int): One above the highest integer to be drawn from the distribution.
  21046. Keyword args:
  21047. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
  21048. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  21049. Default: if ``None``, defaults to the dtype of :attr:`input`.
  21050. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  21051. Default: if ``None``, defaults to the layout of :attr:`input`.
  21052. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21053. Default: if ``None``, defaults to the device of :attr:`input`.
  21054. requires_grad (bool, optional): If autograd should record operations on the
  21055. returned tensor. Default: ``False``.
  21056. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  21057. returned Tensor. Default: ``torch.preserve_format``.
  21058. """
  21059. @overload
  21060. def randint_like(
  21061. input: Tensor,
  21062. high: _int | SymInt,
  21063. *,
  21064. generator: Generator | None,
  21065. memory_format: memory_format | None = None,
  21066. dtype: _dtype | None = None,
  21067. layout: _layout | None = None,
  21068. device: DeviceLikeType | None = None,
  21069. pin_memory: _bool | None = False,
  21070. requires_grad: _bool | None = False,
  21071. ) -> Tensor:
  21072. r"""
  21073. randint_like(input, low=0, high, \*, generator=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  21074. Returns a tensor with the same shape as Tensor :attr:`input` filled with
  21075. random integers generated uniformly between :attr:`low` (inclusive) and
  21076. :attr:`high` (exclusive).
  21077. .. note:
  21078. With the global dtype default (``torch.float32``), this function returns
  21079. a tensor with dtype ``torch.int64``.
  21080. Args:
  21081. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  21082. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  21083. high (int): One above the highest integer to be drawn from the distribution.
  21084. Keyword args:
  21085. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
  21086. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  21087. Default: if ``None``, defaults to the dtype of :attr:`input`.
  21088. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  21089. Default: if ``None``, defaults to the layout of :attr:`input`.
  21090. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21091. Default: if ``None``, defaults to the device of :attr:`input`.
  21092. requires_grad (bool, optional): If autograd should record operations on the
  21093. returned tensor. Default: ``False``.
  21094. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  21095. returned Tensor. Default: ``torch.preserve_format``.
  21096. """
  21097. @overload
  21098. def randint_like(
  21099. input: Tensor,
  21100. high: _int | SymInt,
  21101. *,
  21102. memory_format: memory_format | None = None,
  21103. dtype: _dtype | None = None,
  21104. layout: _layout | None = None,
  21105. device: DeviceLikeType | None = None,
  21106. pin_memory: _bool | None = False,
  21107. requires_grad: _bool | None = False,
  21108. ) -> Tensor:
  21109. r"""
  21110. randint_like(input, low=0, high, \*, generator=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  21111. Returns a tensor with the same shape as Tensor :attr:`input` filled with
  21112. random integers generated uniformly between :attr:`low` (inclusive) and
  21113. :attr:`high` (exclusive).
  21114. .. note:
  21115. With the global dtype default (``torch.float32``), this function returns
  21116. a tensor with dtype ``torch.int64``.
  21117. Args:
  21118. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  21119. low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
  21120. high (int): One above the highest integer to be drawn from the distribution.
  21121. Keyword args:
  21122. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
  21123. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  21124. Default: if ``None``, defaults to the dtype of :attr:`input`.
  21125. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  21126. Default: if ``None``, defaults to the layout of :attr:`input`.
  21127. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21128. Default: if ``None``, defaults to the device of :attr:`input`.
  21129. requires_grad (bool, optional): If autograd should record operations on the
  21130. returned tensor. Default: ``False``.
  21131. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  21132. returned Tensor. Default: ``torch.preserve_format``.
  21133. """
  21134. @overload
  21135. def randn(
  21136. size: Sequence[_int | SymInt],
  21137. *,
  21138. generator: Generator | None,
  21139. names: Sequence[str | EllipsisType | None] | None,
  21140. dtype: _dtype | None = None,
  21141. layout: _layout | None = None,
  21142. device: DeviceLikeType | None = None,
  21143. pin_memory: _bool | None = False,
  21144. requires_grad: _bool | None = False,
  21145. ) -> Tensor:
  21146. r"""
  21147. randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21148. Returns a tensor filled with random numbers from a normal distribution
  21149. with mean `0` and variance `1` (also called the standard normal
  21150. distribution).
  21151. .. math::
  21152. \text{out}_{i} \sim \mathcal{N}(0, 1)
  21153. For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
  21154. unit variance as
  21155. .. math::
  21156. \text{out}_{i} \sim \mathcal{CN}(0, 1)
  21157. This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
  21158. :math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
  21159. .. math::
  21160. \operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
  21161. \operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
  21162. The shape of the tensor is defined by the variable argument :attr:`size`.
  21163. Args:
  21164. size (int...): a sequence of integers defining the shape of the output tensor.
  21165. Can be a variable number of arguments or a collection like a list or tuple.
  21166. Keyword args:
  21167. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21168. out (Tensor, optional): the output tensor.
  21169. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21170. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  21171. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21172. Default: ``torch.strided``.
  21173. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21174. Default: if ``None``, uses the current device for the default tensor type
  21175. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21176. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21177. requires_grad (bool, optional): If autograd should record operations on the
  21178. returned tensor. Default: ``False``.
  21179. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21180. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21181. Example::
  21182. >>> torch.randn(4)
  21183. tensor([-2.1436, 0.9966, 2.3426, -0.6366])
  21184. >>> torch.randn(2, 3)
  21185. tensor([[ 1.5954, 2.8929, -1.0923],
  21186. [ 1.1719, -0.4709, -0.1996]])
  21187. .. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
  21188. """
  21189. @overload
  21190. def randn(
  21191. *size: _int | SymInt,
  21192. generator: Generator | None,
  21193. names: Sequence[str | EllipsisType | None] | None,
  21194. dtype: _dtype | None = None,
  21195. layout: _layout | None = None,
  21196. device: DeviceLikeType | None = None,
  21197. pin_memory: _bool | None = False,
  21198. requires_grad: _bool | None = False,
  21199. ) -> Tensor:
  21200. r"""
  21201. randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21202. Returns a tensor filled with random numbers from a normal distribution
  21203. with mean `0` and variance `1` (also called the standard normal
  21204. distribution).
  21205. .. math::
  21206. \text{out}_{i} \sim \mathcal{N}(0, 1)
  21207. For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
  21208. unit variance as
  21209. .. math::
  21210. \text{out}_{i} \sim \mathcal{CN}(0, 1)
  21211. This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
  21212. :math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
  21213. .. math::
  21214. \operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
  21215. \operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
  21216. The shape of the tensor is defined by the variable argument :attr:`size`.
  21217. Args:
  21218. size (int...): a sequence of integers defining the shape of the output tensor.
  21219. Can be a variable number of arguments or a collection like a list or tuple.
  21220. Keyword args:
  21221. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21222. out (Tensor, optional): the output tensor.
  21223. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21224. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  21225. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21226. Default: ``torch.strided``.
  21227. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21228. Default: if ``None``, uses the current device for the default tensor type
  21229. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21230. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21231. requires_grad (bool, optional): If autograd should record operations on the
  21232. returned tensor. Default: ``False``.
  21233. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21234. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21235. Example::
  21236. >>> torch.randn(4)
  21237. tensor([-2.1436, 0.9966, 2.3426, -0.6366])
  21238. >>> torch.randn(2, 3)
  21239. tensor([[ 1.5954, 2.8929, -1.0923],
  21240. [ 1.1719, -0.4709, -0.1996]])
  21241. .. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
  21242. """
  21243. @overload
  21244. def randn(
  21245. size: Sequence[_int | SymInt],
  21246. *,
  21247. generator: Generator | None,
  21248. out: Tensor | None = None,
  21249. dtype: _dtype | None = None,
  21250. layout: _layout | None = None,
  21251. device: DeviceLikeType | None = None,
  21252. pin_memory: _bool | None = False,
  21253. requires_grad: _bool | None = False,
  21254. ) -> Tensor:
  21255. r"""
  21256. randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21257. Returns a tensor filled with random numbers from a normal distribution
  21258. with mean `0` and variance `1` (also called the standard normal
  21259. distribution).
  21260. .. math::
  21261. \text{out}_{i} \sim \mathcal{N}(0, 1)
  21262. For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
  21263. unit variance as
  21264. .. math::
  21265. \text{out}_{i} \sim \mathcal{CN}(0, 1)
  21266. This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
  21267. :math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
  21268. .. math::
  21269. \operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
  21270. \operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
  21271. The shape of the tensor is defined by the variable argument :attr:`size`.
  21272. Args:
  21273. size (int...): a sequence of integers defining the shape of the output tensor.
  21274. Can be a variable number of arguments or a collection like a list or tuple.
  21275. Keyword args:
  21276. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21277. out (Tensor, optional): the output tensor.
  21278. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21279. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  21280. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21281. Default: ``torch.strided``.
  21282. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21283. Default: if ``None``, uses the current device for the default tensor type
  21284. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21285. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21286. requires_grad (bool, optional): If autograd should record operations on the
  21287. returned tensor. Default: ``False``.
  21288. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21289. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21290. Example::
  21291. >>> torch.randn(4)
  21292. tensor([-2.1436, 0.9966, 2.3426, -0.6366])
  21293. >>> torch.randn(2, 3)
  21294. tensor([[ 1.5954, 2.8929, -1.0923],
  21295. [ 1.1719, -0.4709, -0.1996]])
  21296. .. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
  21297. """
  21298. @overload
  21299. def randn(
  21300. *size: _int | SymInt,
  21301. generator: Generator | None,
  21302. out: Tensor | None = None,
  21303. dtype: _dtype | None = None,
  21304. layout: _layout | None = None,
  21305. device: DeviceLikeType | None = None,
  21306. pin_memory: _bool | None = False,
  21307. requires_grad: _bool | None = False,
  21308. ) -> Tensor:
  21309. r"""
  21310. randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21311. Returns a tensor filled with random numbers from a normal distribution
  21312. with mean `0` and variance `1` (also called the standard normal
  21313. distribution).
  21314. .. math::
  21315. \text{out}_{i} \sim \mathcal{N}(0, 1)
  21316. For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
  21317. unit variance as
  21318. .. math::
  21319. \text{out}_{i} \sim \mathcal{CN}(0, 1)
  21320. This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
  21321. :math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
  21322. .. math::
  21323. \operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
  21324. \operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
  21325. The shape of the tensor is defined by the variable argument :attr:`size`.
  21326. Args:
  21327. size (int...): a sequence of integers defining the shape of the output tensor.
  21328. Can be a variable number of arguments or a collection like a list or tuple.
  21329. Keyword args:
  21330. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21331. out (Tensor, optional): the output tensor.
  21332. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21333. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  21334. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21335. Default: ``torch.strided``.
  21336. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21337. Default: if ``None``, uses the current device for the default tensor type
  21338. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21339. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21340. requires_grad (bool, optional): If autograd should record operations on the
  21341. returned tensor. Default: ``False``.
  21342. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21343. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21344. Example::
  21345. >>> torch.randn(4)
  21346. tensor([-2.1436, 0.9966, 2.3426, -0.6366])
  21347. >>> torch.randn(2, 3)
  21348. tensor([[ 1.5954, 2.8929, -1.0923],
  21349. [ 1.1719, -0.4709, -0.1996]])
  21350. .. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
  21351. """
  21352. @overload
  21353. def randn(
  21354. size: Sequence[_int | SymInt],
  21355. *,
  21356. out: Tensor | None = None,
  21357. dtype: _dtype | None = None,
  21358. layout: _layout | None = None,
  21359. device: DeviceLikeType | None = None,
  21360. pin_memory: _bool | None = False,
  21361. requires_grad: _bool | None = False,
  21362. ) -> Tensor:
  21363. r"""
  21364. randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21365. Returns a tensor filled with random numbers from a normal distribution
  21366. with mean `0` and variance `1` (also called the standard normal
  21367. distribution).
  21368. .. math::
  21369. \text{out}_{i} \sim \mathcal{N}(0, 1)
  21370. For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
  21371. unit variance as
  21372. .. math::
  21373. \text{out}_{i} \sim \mathcal{CN}(0, 1)
  21374. This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
  21375. :math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
  21376. .. math::
  21377. \operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
  21378. \operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
  21379. The shape of the tensor is defined by the variable argument :attr:`size`.
  21380. Args:
  21381. size (int...): a sequence of integers defining the shape of the output tensor.
  21382. Can be a variable number of arguments or a collection like a list or tuple.
  21383. Keyword args:
  21384. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21385. out (Tensor, optional): the output tensor.
  21386. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21387. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  21388. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21389. Default: ``torch.strided``.
  21390. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21391. Default: if ``None``, uses the current device for the default tensor type
  21392. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21393. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21394. requires_grad (bool, optional): If autograd should record operations on the
  21395. returned tensor. Default: ``False``.
  21396. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21397. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21398. Example::
  21399. >>> torch.randn(4)
  21400. tensor([-2.1436, 0.9966, 2.3426, -0.6366])
  21401. >>> torch.randn(2, 3)
  21402. tensor([[ 1.5954, 2.8929, -1.0923],
  21403. [ 1.1719, -0.4709, -0.1996]])
  21404. .. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
  21405. """
  21406. @overload
  21407. def randn(
  21408. *size: _int | SymInt,
  21409. out: Tensor | None = None,
  21410. dtype: _dtype | None = None,
  21411. layout: _layout | None = None,
  21412. device: DeviceLikeType | None = None,
  21413. pin_memory: _bool | None = False,
  21414. requires_grad: _bool | None = False,
  21415. ) -> Tensor:
  21416. r"""
  21417. randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21418. Returns a tensor filled with random numbers from a normal distribution
  21419. with mean `0` and variance `1` (also called the standard normal
  21420. distribution).
  21421. .. math::
  21422. \text{out}_{i} \sim \mathcal{N}(0, 1)
  21423. For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
  21424. unit variance as
  21425. .. math::
  21426. \text{out}_{i} \sim \mathcal{CN}(0, 1)
  21427. This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
  21428. :math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
  21429. .. math::
  21430. \operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
  21431. \operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
  21432. The shape of the tensor is defined by the variable argument :attr:`size`.
  21433. Args:
  21434. size (int...): a sequence of integers defining the shape of the output tensor.
  21435. Can be a variable number of arguments or a collection like a list or tuple.
  21436. Keyword args:
  21437. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21438. out (Tensor, optional): the output tensor.
  21439. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21440. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  21441. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21442. Default: ``torch.strided``.
  21443. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21444. Default: if ``None``, uses the current device for the default tensor type
  21445. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21446. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21447. requires_grad (bool, optional): If autograd should record operations on the
  21448. returned tensor. Default: ``False``.
  21449. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21450. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21451. Example::
  21452. >>> torch.randn(4)
  21453. tensor([-2.1436, 0.9966, 2.3426, -0.6366])
  21454. >>> torch.randn(2, 3)
  21455. tensor([[ 1.5954, 2.8929, -1.0923],
  21456. [ 1.1719, -0.4709, -0.1996]])
  21457. .. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
  21458. """
  21459. @overload
  21460. def randn(
  21461. size: Sequence[_int | SymInt],
  21462. *,
  21463. names: Sequence[str | EllipsisType | None] | None,
  21464. dtype: _dtype | None = None,
  21465. layout: _layout | None = None,
  21466. device: DeviceLikeType | None = None,
  21467. pin_memory: _bool | None = False,
  21468. requires_grad: _bool | None = False,
  21469. ) -> Tensor:
  21470. r"""
  21471. randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21472. Returns a tensor filled with random numbers from a normal distribution
  21473. with mean `0` and variance `1` (also called the standard normal
  21474. distribution).
  21475. .. math::
  21476. \text{out}_{i} \sim \mathcal{N}(0, 1)
  21477. For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
  21478. unit variance as
  21479. .. math::
  21480. \text{out}_{i} \sim \mathcal{CN}(0, 1)
  21481. This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
  21482. :math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
  21483. .. math::
  21484. \operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
  21485. \operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
  21486. The shape of the tensor is defined by the variable argument :attr:`size`.
  21487. Args:
  21488. size (int...): a sequence of integers defining the shape of the output tensor.
  21489. Can be a variable number of arguments or a collection like a list or tuple.
  21490. Keyword args:
  21491. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21492. out (Tensor, optional): the output tensor.
  21493. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21494. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  21495. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21496. Default: ``torch.strided``.
  21497. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21498. Default: if ``None``, uses the current device for the default tensor type
  21499. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21500. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21501. requires_grad (bool, optional): If autograd should record operations on the
  21502. returned tensor. Default: ``False``.
  21503. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21504. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21505. Example::
  21506. >>> torch.randn(4)
  21507. tensor([-2.1436, 0.9966, 2.3426, -0.6366])
  21508. >>> torch.randn(2, 3)
  21509. tensor([[ 1.5954, 2.8929, -1.0923],
  21510. [ 1.1719, -0.4709, -0.1996]])
  21511. .. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
  21512. """
  21513. @overload
  21514. def randn(
  21515. *size: _int | SymInt,
  21516. names: Sequence[str | EllipsisType | None] | None,
  21517. dtype: _dtype | None = None,
  21518. layout: _layout | None = None,
  21519. device: DeviceLikeType | None = None,
  21520. pin_memory: _bool | None = False,
  21521. requires_grad: _bool | None = False,
  21522. ) -> Tensor:
  21523. r"""
  21524. randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21525. Returns a tensor filled with random numbers from a normal distribution
  21526. with mean `0` and variance `1` (also called the standard normal
  21527. distribution).
  21528. .. math::
  21529. \text{out}_{i} \sim \mathcal{N}(0, 1)
  21530. For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
  21531. unit variance as
  21532. .. math::
  21533. \text{out}_{i} \sim \mathcal{CN}(0, 1)
  21534. This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
  21535. :math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
  21536. .. math::
  21537. \operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
  21538. \operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
  21539. The shape of the tensor is defined by the variable argument :attr:`size`.
  21540. Args:
  21541. size (int...): a sequence of integers defining the shape of the output tensor.
  21542. Can be a variable number of arguments or a collection like a list or tuple.
  21543. Keyword args:
  21544. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21545. out (Tensor, optional): the output tensor.
  21546. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21547. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  21548. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21549. Default: ``torch.strided``.
  21550. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21551. Default: if ``None``, uses the current device for the default tensor type
  21552. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21553. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21554. requires_grad (bool, optional): If autograd should record operations on the
  21555. returned tensor. Default: ``False``.
  21556. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21557. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21558. Example::
  21559. >>> torch.randn(4)
  21560. tensor([-2.1436, 0.9966, 2.3426, -0.6366])
  21561. >>> torch.randn(2, 3)
  21562. tensor([[ 1.5954, 2.8929, -1.0923],
  21563. [ 1.1719, -0.4709, -0.1996]])
  21564. .. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
  21565. """
  21566. @overload
  21567. def randn_like(
  21568. input: Tensor,
  21569. *,
  21570. generator: Generator | None,
  21571. memory_format: memory_format | None = None,
  21572. dtype: _dtype | None = None,
  21573. layout: _layout | None = None,
  21574. device: DeviceLikeType | None = None,
  21575. pin_memory: _bool | None = False,
  21576. requires_grad: _bool | None = False,
  21577. ) -> Tensor:
  21578. r"""
  21579. randn_like(input, *, generator=None, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  21580. Returns a tensor with the same size as :attr:`input` that is filled with
  21581. random numbers from a normal distribution with mean 0 and variance 1. Please refer to :func:`torch.randn` for the
  21582. sampling process of complex dtypes. ``torch.randn_like(input)`` is equivalent to
  21583. ``torch.randn(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
  21584. Args:
  21585. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  21586. Keyword args:
  21587. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
  21588. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  21589. Default: if ``None``, defaults to the dtype of :attr:`input`.
  21590. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  21591. Default: if ``None``, defaults to the layout of :attr:`input`.
  21592. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21593. Default: if ``None``, defaults to the device of :attr:`input`.
  21594. requires_grad (bool, optional): If autograd should record operations on the
  21595. returned tensor. Default: ``False``.
  21596. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  21597. returned Tensor. Default: ``torch.preserve_format``.
  21598. """
  21599. @overload
  21600. def randn_like(
  21601. input: Tensor,
  21602. *,
  21603. memory_format: memory_format | None = None,
  21604. dtype: _dtype | None = None,
  21605. layout: _layout | None = None,
  21606. device: DeviceLikeType | None = None,
  21607. pin_memory: _bool | None = False,
  21608. requires_grad: _bool | None = False,
  21609. ) -> Tensor:
  21610. r"""
  21611. randn_like(input, *, generator=None, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  21612. Returns a tensor with the same size as :attr:`input` that is filled with
  21613. random numbers from a normal distribution with mean 0 and variance 1. Please refer to :func:`torch.randn` for the
  21614. sampling process of complex dtypes. ``torch.randn_like(input)`` is equivalent to
  21615. ``torch.randn(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
  21616. Args:
  21617. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  21618. Keyword args:
  21619. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
  21620. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  21621. Default: if ``None``, defaults to the dtype of :attr:`input`.
  21622. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  21623. Default: if ``None``, defaults to the layout of :attr:`input`.
  21624. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21625. Default: if ``None``, defaults to the device of :attr:`input`.
  21626. requires_grad (bool, optional): If autograd should record operations on the
  21627. returned tensor. Default: ``False``.
  21628. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  21629. returned Tensor. Default: ``torch.preserve_format``.
  21630. """
  21631. @overload
  21632. def randperm(
  21633. n: _int | SymInt,
  21634. *,
  21635. generator: Generator | None,
  21636. out: Tensor | None = None,
  21637. dtype: _dtype | None = None,
  21638. layout: _layout | None = None,
  21639. device: DeviceLikeType | None = None,
  21640. pin_memory: _bool | None = False,
  21641. requires_grad: _bool | None = False,
  21642. ) -> Tensor:
  21643. r"""
  21644. randperm(n, *, generator=None, out=None, dtype=torch.int64,layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21645. Returns a random permutation of integers from ``0`` to ``n - 1``.
  21646. Args:
  21647. n (int): the upper bound (exclusive)
  21648. Keyword args:
  21649. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21650. out (Tensor, optional): the output tensor.
  21651. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21652. Default: ``torch.int64``.
  21653. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21654. Default: ``torch.strided``.
  21655. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21656. Default: if ``None``, uses the current device for the default tensor type
  21657. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21658. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21659. requires_grad (bool, optional): If autograd should record operations on the
  21660. returned tensor. Default: ``False``.
  21661. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21662. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21663. Example::
  21664. >>> torch.randperm(4)
  21665. tensor([2, 1, 0, 3])
  21666. """
  21667. @overload
  21668. def randperm(
  21669. n: _int | SymInt,
  21670. *,
  21671. out: Tensor | None = None,
  21672. dtype: _dtype | None = None,
  21673. layout: _layout | None = None,
  21674. device: DeviceLikeType | None = None,
  21675. pin_memory: _bool | None = False,
  21676. requires_grad: _bool | None = False,
  21677. ) -> Tensor:
  21678. r"""
  21679. randperm(n, *, generator=None, out=None, dtype=torch.int64,layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
  21680. Returns a random permutation of integers from ``0`` to ``n - 1``.
  21681. Args:
  21682. n (int): the upper bound (exclusive)
  21683. Keyword args:
  21684. generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
  21685. out (Tensor, optional): the output tensor.
  21686. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21687. Default: ``torch.int64``.
  21688. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21689. Default: ``torch.strided``.
  21690. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21691. Default: if ``None``, uses the current device for the default tensor type
  21692. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21693. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21694. requires_grad (bool, optional): If autograd should record operations on the
  21695. returned tensor. Default: ``False``.
  21696. pin_memory (bool, optional): If set, returned tensor would be allocated in
  21697. the pinned memory. Works only for CPU tensors. Default: ``False``.
  21698. Example::
  21699. >>> torch.randperm(4)
  21700. tensor([2, 1, 0, 3])
  21701. """
  21702. def range(
  21703. start: Number,
  21704. end: Number,
  21705. step: Number = 1,
  21706. *,
  21707. out: Tensor | None = None,
  21708. dtype: _dtype | None = None,
  21709. device: DeviceLikeType | None = None,
  21710. requires_grad: _bool = False,
  21711. pin_memory: _bool = False,
  21712. ) -> Tensor:
  21713. r"""
  21714. range(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  21715. Returns a 1-D tensor of size :math:`\left\lfloor \frac{\text{end} - \text{start}}{\text{step}} \right\rfloor + 1`
  21716. with values from :attr:`start` to :attr:`end` with step :attr:`step`. Step is
  21717. the gap between two values in the tensor.
  21718. .. math::
  21719. \text{out}_{i+1} = \text{out}_i + \text{step}.
  21720. .. warning::
  21721. This function is deprecated and will be removed in a future release because its behavior is inconsistent with
  21722. Python's range builtin. Instead, use :func:`torch.arange`, which produces values in [start, end).
  21723. Args:
  21724. start (float, optional): the starting value for the set of points. Default: ``0``.
  21725. end (float): the ending value for the set of points
  21726. step (float, optional): the gap between each pair of adjacent points. Default: ``1``.
  21727. Keyword args:
  21728. out (Tensor, optional): the output tensor.
  21729. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  21730. 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
  21731. arguments. If any of `start`, `end`, or `step` are floating-point, the
  21732. `dtype` is inferred to be the default dtype, see
  21733. :meth:`~torch.get_default_dtype`. Otherwise, the `dtype` is inferred to
  21734. be `torch.int64`.
  21735. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  21736. Default: ``torch.strided``.
  21737. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21738. Default: if ``None``, uses the current device for the default tensor type
  21739. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  21740. for CPU tensor types and the current CUDA device for CUDA tensor types.
  21741. requires_grad (bool, optional): If autograd should record operations on the
  21742. returned tensor. Default: ``False``.
  21743. Example::
  21744. >>> torch.range(1, 4)
  21745. tensor([ 1., 2., 3., 4.])
  21746. >>> torch.range(1, 4, 0.5)
  21747. tensor([ 1.0000, 1.5000, 2.0000, 2.5000, 3.0000, 3.5000, 4.0000])
  21748. """
  21749. def ravel(input: Tensor) -> Tensor:
  21750. r"""
  21751. ravel(input) -> Tensor
  21752. Return a contiguous flattened tensor. A copy is made only if needed.
  21753. Args:
  21754. input (Tensor): the input tensor.
  21755. Example::
  21756. >>> t = torch.tensor([[[1, 2],
  21757. ... [3, 4]],
  21758. ... [[5, 6],
  21759. ... [7, 8]]])
  21760. >>> torch.ravel(t)
  21761. tensor([1, 2, 3, 4, 5, 6, 7, 8])
  21762. """
  21763. def real(input: Tensor) -> Tensor:
  21764. r"""
  21765. real(input) -> Tensor
  21766. Returns a new tensor containing real values of the :attr:`self` tensor.
  21767. The returned tensor and :attr:`self` share the same underlying storage.
  21768. Args:
  21769. input (Tensor): the input tensor.
  21770. Example::
  21771. >>> x=torch.randn(4, dtype=torch.cfloat)
  21772. >>> x
  21773. tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
  21774. >>> x.real
  21775. tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
  21776. """
  21777. def reciprocal(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  21778. r"""
  21779. reciprocal(input, *, out=None) -> Tensor
  21780. Returns a new tensor with the reciprocal of the elements of :attr:`input`
  21781. .. math::
  21782. \text{out}_{i} = \frac{1}{\text{input}_{i}}
  21783. .. note::
  21784. Unlike NumPy's reciprocal, torch.reciprocal supports integral inputs. Integral
  21785. inputs to reciprocal are automatically :ref:`promoted <type-promotion-doc>` to
  21786. the default scalar type.
  21787. Args:
  21788. input (Tensor): the input tensor.
  21789. Keyword args:
  21790. out (Tensor, optional): the output tensor.
  21791. Example::
  21792. >>> a = torch.randn(4)
  21793. >>> a
  21794. tensor([-0.4595, -2.1219, -1.4314, 0.7298])
  21795. >>> torch.reciprocal(a)
  21796. tensor([-2.1763, -0.4713, -0.6986, 1.3702])
  21797. """
  21798. def reciprocal_(input: Tensor) -> Tensor: ...
  21799. def relu(input: Tensor) -> Tensor: ...
  21800. def relu_(input: Tensor) -> Tensor: ...
  21801. @overload
  21802. def remainder(
  21803. input: Tensor,
  21804. other: Tensor,
  21805. *,
  21806. out: Tensor | None = None,
  21807. ) -> Tensor:
  21808. r"""
  21809. remainder(input, other, *, out=None) -> Tensor
  21810. Computes
  21811. `Python's modulus operation <https://docs.python.org/3/reference/expressions.html#binary-arithmetic-operations>`_
  21812. entrywise. The result has the same sign as the divisor :attr:`other` and its absolute value
  21813. is less than that of :attr:`other`.
  21814. It may also be defined in terms of :func:`torch.div` as
  21815. .. code:: python
  21816. torch.remainder(a, b) == a - a.div(b, rounding_mode="floor") * b
  21817. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  21818. :ref:`type promotion <type-promotion-doc>`, and integer and float inputs.
  21819. .. note::
  21820. Complex inputs are not supported. In some cases, it is not mathematically
  21821. possible to satisfy the definition of a modulo operation with complex numbers.
  21822. See :func:`torch.fmod` for how division by zero is handled.
  21823. .. seealso::
  21824. :func:`torch.fmod` which implements C++'s `std::fmod <https://en.cppreference.com/w/cpp/numeric/math/fmod>`_.
  21825. This one is defined in terms of division rounding towards zero.
  21826. Args:
  21827. input (Tensor or Scalar): the dividend
  21828. other (Tensor or Scalar): the divisor
  21829. Keyword args:
  21830. out (Tensor, optional): the output tensor.
  21831. Example::
  21832. >>> torch.remainder(torch.tensor([-3., -2, -1, 1, 2, 3]), 2)
  21833. tensor([ 1., 0., 1., 1., 0., 1.])
  21834. >>> torch.remainder(torch.tensor([1, 2, 3, 4, 5]), -1.5)
  21835. tensor([ -0.5000, -1.0000, 0.0000, -0.5000, -1.0000 ])
  21836. """
  21837. @overload
  21838. def remainder(self: Number | _complex, other: Tensor) -> Tensor:
  21839. r"""
  21840. remainder(input, other, *, out=None) -> Tensor
  21841. Computes
  21842. `Python's modulus operation <https://docs.python.org/3/reference/expressions.html#binary-arithmetic-operations>`_
  21843. entrywise. The result has the same sign as the divisor :attr:`other` and its absolute value
  21844. is less than that of :attr:`other`.
  21845. It may also be defined in terms of :func:`torch.div` as
  21846. .. code:: python
  21847. torch.remainder(a, b) == a - a.div(b, rounding_mode="floor") * b
  21848. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  21849. :ref:`type promotion <type-promotion-doc>`, and integer and float inputs.
  21850. .. note::
  21851. Complex inputs are not supported. In some cases, it is not mathematically
  21852. possible to satisfy the definition of a modulo operation with complex numbers.
  21853. See :func:`torch.fmod` for how division by zero is handled.
  21854. .. seealso::
  21855. :func:`torch.fmod` which implements C++'s `std::fmod <https://en.cppreference.com/w/cpp/numeric/math/fmod>`_.
  21856. This one is defined in terms of division rounding towards zero.
  21857. Args:
  21858. input (Tensor or Scalar): the dividend
  21859. other (Tensor or Scalar): the divisor
  21860. Keyword args:
  21861. out (Tensor, optional): the output tensor.
  21862. Example::
  21863. >>> torch.remainder(torch.tensor([-3., -2, -1, 1, 2, 3]), 2)
  21864. tensor([ 1., 0., 1., 1., 0., 1.])
  21865. >>> torch.remainder(torch.tensor([1, 2, 3, 4, 5]), -1.5)
  21866. tensor([ -0.5000, -1.0000, 0.0000, -0.5000, -1.0000 ])
  21867. """
  21868. @overload
  21869. def remainder(
  21870. input: Tensor,
  21871. other: Number | _complex,
  21872. *,
  21873. out: Tensor | None = None,
  21874. ) -> Tensor:
  21875. r"""
  21876. remainder(input, other, *, out=None) -> Tensor
  21877. Computes
  21878. `Python's modulus operation <https://docs.python.org/3/reference/expressions.html#binary-arithmetic-operations>`_
  21879. entrywise. The result has the same sign as the divisor :attr:`other` and its absolute value
  21880. is less than that of :attr:`other`.
  21881. It may also be defined in terms of :func:`torch.div` as
  21882. .. code:: python
  21883. torch.remainder(a, b) == a - a.div(b, rounding_mode="floor") * b
  21884. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  21885. :ref:`type promotion <type-promotion-doc>`, and integer and float inputs.
  21886. .. note::
  21887. Complex inputs are not supported. In some cases, it is not mathematically
  21888. possible to satisfy the definition of a modulo operation with complex numbers.
  21889. See :func:`torch.fmod` for how division by zero is handled.
  21890. .. seealso::
  21891. :func:`torch.fmod` which implements C++'s `std::fmod <https://en.cppreference.com/w/cpp/numeric/math/fmod>`_.
  21892. This one is defined in terms of division rounding towards zero.
  21893. Args:
  21894. input (Tensor or Scalar): the dividend
  21895. other (Tensor or Scalar): the divisor
  21896. Keyword args:
  21897. out (Tensor, optional): the output tensor.
  21898. Example::
  21899. >>> torch.remainder(torch.tensor([-3., -2, -1, 1, 2, 3]), 2)
  21900. tensor([ 1., 0., 1., 1., 0., 1.])
  21901. >>> torch.remainder(torch.tensor([1, 2, 3, 4, 5]), -1.5)
  21902. tensor([ -0.5000, -1.0000, 0.0000, -0.5000, -1.0000 ])
  21903. """
  21904. def renorm(
  21905. input: Tensor,
  21906. p: Number | _complex,
  21907. dim: _int,
  21908. maxnorm: Number | _complex,
  21909. *,
  21910. out: Tensor | None = None,
  21911. ) -> Tensor:
  21912. r"""
  21913. renorm(input, p, dim, maxnorm, *, out=None) -> Tensor
  21914. Returns a tensor where each sub-tensor of :attr:`input` along dimension
  21915. :attr:`dim` is normalized such that the `p`-norm of the sub-tensor is lower
  21916. than the value :attr:`maxnorm`
  21917. .. note:: If the norm of a row is lower than `maxnorm`, the row is unchanged
  21918. Args:
  21919. input (Tensor): the input tensor.
  21920. p (float): the power for the norm computation
  21921. dim (int): the dimension to slice over to get the sub-tensors
  21922. maxnorm (float): the maximum norm to keep each sub-tensor under
  21923. Keyword args:
  21924. out (Tensor, optional): the output tensor.
  21925. Example::
  21926. >>> x = torch.ones(3, 3)
  21927. >>> x[1].fill_(2)
  21928. tensor([ 2., 2., 2.])
  21929. >>> x[2].fill_(3)
  21930. tensor([ 3., 3., 3.])
  21931. >>> x
  21932. tensor([[ 1., 1., 1.],
  21933. [ 2., 2., 2.],
  21934. [ 3., 3., 3.]])
  21935. >>> torch.renorm(x, 1, 0, 5)
  21936. tensor([[ 1.0000, 1.0000, 1.0000],
  21937. [ 1.6667, 1.6667, 1.6667],
  21938. [ 1.6667, 1.6667, 1.6667]])
  21939. """
  21940. @overload
  21941. def repeat_interleave(
  21942. input: Tensor,
  21943. repeats: Tensor,
  21944. dim: _int | None = None,
  21945. *,
  21946. output_size: _int | SymInt | None = None,
  21947. ) -> Tensor:
  21948. r"""
  21949. repeat_interleave(input, repeats, dim=None, *, output_size=None) -> Tensor
  21950. Repeat elements of a tensor.
  21951. .. warning::
  21952. This is different from :meth:`torch.Tensor.repeat` but similar to ``numpy.repeat``.
  21953. Args:
  21954. input (Tensor): the input tensor.
  21955. repeats (Tensor or int): The number of repetitions for each element.
  21956. repeats is broadcasted to fit the shape of the given axis.
  21957. dim (int, optional): The dimension along which to repeat values.
  21958. By default, use the flattened input array, and return a flat output
  21959. array.
  21960. Keyword args:
  21961. output_size (int, optional): Total output size for the given axis
  21962. ( e.g. sum of repeats). If given, it will avoid stream synchronization
  21963. needed to calculate output shape of the tensor.
  21964. Returns:
  21965. Tensor: Repeated tensor which has the same shape as input, except along the given axis.
  21966. Example::
  21967. >>> x = torch.tensor([1, 2, 3])
  21968. >>> x.repeat_interleave(2)
  21969. tensor([1, 1, 2, 2, 3, 3])
  21970. >>> y = torch.tensor([[1, 2], [3, 4]])
  21971. >>> torch.repeat_interleave(y, 2)
  21972. tensor([1, 1, 2, 2, 3, 3, 4, 4])
  21973. >>> torch.repeat_interleave(y, 3, dim=1)
  21974. tensor([[1, 1, 1, 2, 2, 2],
  21975. [3, 3, 3, 4, 4, 4]])
  21976. >>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0)
  21977. tensor([[1, 2],
  21978. [3, 4],
  21979. [3, 4]])
  21980. >>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0, output_size=3)
  21981. tensor([[1, 2],
  21982. [3, 4],
  21983. [3, 4]])
  21984. If the `repeats` is `tensor([n1, n2, n3, ...])`, then the output will be
  21985. `tensor([0, 0, ..., 1, 1, ..., 2, 2, ..., ...])` where `0` appears `n1` times,
  21986. `1` appears `n2` times, `2` appears `n3` times, etc.
  21987. .. function:: repeat_interleave(repeats, *) -> Tensor
  21988. :noindex:
  21989. Repeats 0 repeats[0] times, 1 repeats[1] times, 2 repeats[2] times, etc.
  21990. Args:
  21991. repeats (Tensor): The number of repetitions for each element.
  21992. Returns:
  21993. Tensor: Repeated tensor of size `sum(repeats)`.
  21994. Example::
  21995. >>> torch.repeat_interleave(torch.tensor([1, 2, 3]))
  21996. tensor([0, 1, 1, 2, 2, 2])
  21997. """
  21998. @overload
  21999. def repeat_interleave(
  22000. repeats: Tensor,
  22001. *,
  22002. output_size: _int | SymInt | None = None,
  22003. ) -> Tensor:
  22004. r"""
  22005. repeat_interleave(input, repeats, dim=None, *, output_size=None) -> Tensor
  22006. Repeat elements of a tensor.
  22007. .. warning::
  22008. This is different from :meth:`torch.Tensor.repeat` but similar to ``numpy.repeat``.
  22009. Args:
  22010. input (Tensor): the input tensor.
  22011. repeats (Tensor or int): The number of repetitions for each element.
  22012. repeats is broadcasted to fit the shape of the given axis.
  22013. dim (int, optional): The dimension along which to repeat values.
  22014. By default, use the flattened input array, and return a flat output
  22015. array.
  22016. Keyword args:
  22017. output_size (int, optional): Total output size for the given axis
  22018. ( e.g. sum of repeats). If given, it will avoid stream synchronization
  22019. needed to calculate output shape of the tensor.
  22020. Returns:
  22021. Tensor: Repeated tensor which has the same shape as input, except along the given axis.
  22022. Example::
  22023. >>> x = torch.tensor([1, 2, 3])
  22024. >>> x.repeat_interleave(2)
  22025. tensor([1, 1, 2, 2, 3, 3])
  22026. >>> y = torch.tensor([[1, 2], [3, 4]])
  22027. >>> torch.repeat_interleave(y, 2)
  22028. tensor([1, 1, 2, 2, 3, 3, 4, 4])
  22029. >>> torch.repeat_interleave(y, 3, dim=1)
  22030. tensor([[1, 1, 1, 2, 2, 2],
  22031. [3, 3, 3, 4, 4, 4]])
  22032. >>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0)
  22033. tensor([[1, 2],
  22034. [3, 4],
  22035. [3, 4]])
  22036. >>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0, output_size=3)
  22037. tensor([[1, 2],
  22038. [3, 4],
  22039. [3, 4]])
  22040. If the `repeats` is `tensor([n1, n2, n3, ...])`, then the output will be
  22041. `tensor([0, 0, ..., 1, 1, ..., 2, 2, ..., ...])` where `0` appears `n1` times,
  22042. `1` appears `n2` times, `2` appears `n3` times, etc.
  22043. .. function:: repeat_interleave(repeats, *) -> Tensor
  22044. :noindex:
  22045. Repeats 0 repeats[0] times, 1 repeats[1] times, 2 repeats[2] times, etc.
  22046. Args:
  22047. repeats (Tensor): The number of repetitions for each element.
  22048. Returns:
  22049. Tensor: Repeated tensor of size `sum(repeats)`.
  22050. Example::
  22051. >>> torch.repeat_interleave(torch.tensor([1, 2, 3]))
  22052. tensor([0, 1, 1, 2, 2, 2])
  22053. """
  22054. @overload
  22055. def repeat_interleave(
  22056. input: Tensor,
  22057. repeats: _int | SymInt,
  22058. dim: _int | None = None,
  22059. *,
  22060. output_size: _int | SymInt | None = None,
  22061. ) -> Tensor:
  22062. r"""
  22063. repeat_interleave(input, repeats, dim=None, *, output_size=None) -> Tensor
  22064. Repeat elements of a tensor.
  22065. .. warning::
  22066. This is different from :meth:`torch.Tensor.repeat` but similar to ``numpy.repeat``.
  22067. Args:
  22068. input (Tensor): the input tensor.
  22069. repeats (Tensor or int): The number of repetitions for each element.
  22070. repeats is broadcasted to fit the shape of the given axis.
  22071. dim (int, optional): The dimension along which to repeat values.
  22072. By default, use the flattened input array, and return a flat output
  22073. array.
  22074. Keyword args:
  22075. output_size (int, optional): Total output size for the given axis
  22076. ( e.g. sum of repeats). If given, it will avoid stream synchronization
  22077. needed to calculate output shape of the tensor.
  22078. Returns:
  22079. Tensor: Repeated tensor which has the same shape as input, except along the given axis.
  22080. Example::
  22081. >>> x = torch.tensor([1, 2, 3])
  22082. >>> x.repeat_interleave(2)
  22083. tensor([1, 1, 2, 2, 3, 3])
  22084. >>> y = torch.tensor([[1, 2], [3, 4]])
  22085. >>> torch.repeat_interleave(y, 2)
  22086. tensor([1, 1, 2, 2, 3, 3, 4, 4])
  22087. >>> torch.repeat_interleave(y, 3, dim=1)
  22088. tensor([[1, 1, 1, 2, 2, 2],
  22089. [3, 3, 3, 4, 4, 4]])
  22090. >>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0)
  22091. tensor([[1, 2],
  22092. [3, 4],
  22093. [3, 4]])
  22094. >>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0, output_size=3)
  22095. tensor([[1, 2],
  22096. [3, 4],
  22097. [3, 4]])
  22098. If the `repeats` is `tensor([n1, n2, n3, ...])`, then the output will be
  22099. `tensor([0, 0, ..., 1, 1, ..., 2, 2, ..., ...])` where `0` appears `n1` times,
  22100. `1` appears `n2` times, `2` appears `n3` times, etc.
  22101. .. function:: repeat_interleave(repeats, *) -> Tensor
  22102. :noindex:
  22103. Repeats 0 repeats[0] times, 1 repeats[1] times, 2 repeats[2] times, etc.
  22104. Args:
  22105. repeats (Tensor): The number of repetitions for each element.
  22106. Returns:
  22107. Tensor: Repeated tensor of size `sum(repeats)`.
  22108. Example::
  22109. >>> torch.repeat_interleave(torch.tensor([1, 2, 3]))
  22110. tensor([0, 1, 1, 2, 2, 2])
  22111. """
  22112. def reshape(input: Tensor, shape: Sequence[_int | SymInt]) -> Tensor:
  22113. r"""
  22114. reshape(input, shape) -> Tensor
  22115. Returns a tensor with the same data and number of elements as :attr:`input`,
  22116. but with the specified shape. When possible, the returned tensor will be a view
  22117. of :attr:`input`. Otherwise, it will be a copy. Contiguous inputs and inputs
  22118. with compatible strides can be reshaped without copying, but you should not
  22119. depend on the copying vs. viewing behavior.
  22120. See :meth:`torch.Tensor.view` on when it is possible to return a view.
  22121. A single dimension may be -1, in which case it's inferred from the remaining
  22122. dimensions and the number of elements in :attr:`input`.
  22123. Args:
  22124. input (Tensor): the tensor to be reshaped
  22125. shape (tuple of int): the new shape
  22126. Example::
  22127. >>> a = torch.arange(4.)
  22128. >>> torch.reshape(a, (2, 2))
  22129. tensor([[ 0., 1.],
  22130. [ 2., 3.]])
  22131. >>> b = torch.tensor([[0, 1], [2, 3]])
  22132. >>> torch.reshape(b, (-1,))
  22133. tensor([ 0, 1, 2, 3])
  22134. """
  22135. def resize_as_(
  22136. input: Tensor,
  22137. the_template: Tensor,
  22138. *,
  22139. memory_format: memory_format | None = None,
  22140. ) -> Tensor: ...
  22141. def resize_as_sparse_(input: Tensor, the_template: Tensor) -> Tensor: ...
  22142. def resolve_conj(input: Tensor) -> Tensor:
  22143. r"""
  22144. resolve_conj(input) -> Tensor
  22145. Returns a new tensor with materialized conjugation if :attr:`input`'s conjugate bit is set to `True`,
  22146. else returns :attr:`input`. The output tensor will always have its conjugate bit set to `False`.
  22147. Args:
  22148. input (Tensor): the input tensor.
  22149. Example::
  22150. >>> x = torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j])
  22151. >>> y = x.conj()
  22152. >>> y.is_conj()
  22153. True
  22154. >>> z = y.resolve_conj()
  22155. >>> z
  22156. tensor([-1 - 1j, -2 - 2j, 3 + 3j])
  22157. >>> z.is_conj()
  22158. False
  22159. """
  22160. def resolve_neg(input: Tensor) -> Tensor:
  22161. r"""
  22162. resolve_neg(input) -> Tensor
  22163. Returns a new tensor with materialized negation if :attr:`input`'s negative bit is set to `True`,
  22164. else returns :attr:`input`. The output tensor will always have its negative bit set to `False`.
  22165. Args:
  22166. input (Tensor): the input tensor.
  22167. Example::
  22168. >>> x = torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j])
  22169. >>> y = x.conj()
  22170. >>> z = y.imag
  22171. >>> z.is_neg()
  22172. True
  22173. >>> out = z.resolve_neg()
  22174. >>> out
  22175. tensor([-1., -2., 3.])
  22176. >>> out.is_neg()
  22177. False
  22178. """
  22179. @overload
  22180. def result_type(tensor: Tensor, other: Tensor) -> _dtype:
  22181. r"""
  22182. result_type(tensor1, tensor2) -> dtype
  22183. Returns the :class:`torch.dtype` that would result from performing an arithmetic
  22184. operation on the provided input tensors. See type promotion :ref:`documentation <type-promotion-doc>`
  22185. for more information on the type promotion logic.
  22186. Args:
  22187. tensor1 (Tensor or Number): an input tensor or number
  22188. tensor2 (Tensor or Number): an input tensor or number
  22189. Example::
  22190. >>> torch.result_type(torch.tensor([1, 2], dtype=torch.int), 1.0)
  22191. torch.float32
  22192. >>> torch.result_type(torch.tensor([1, 2], dtype=torch.uint8), torch.tensor(1))
  22193. torch.uint8
  22194. """
  22195. @overload
  22196. def result_type(scalar: Number | _complex, tensor: Tensor) -> _dtype:
  22197. r"""
  22198. result_type(tensor1, tensor2) -> dtype
  22199. Returns the :class:`torch.dtype` that would result from performing an arithmetic
  22200. operation on the provided input tensors. See type promotion :ref:`documentation <type-promotion-doc>`
  22201. for more information on the type promotion logic.
  22202. Args:
  22203. tensor1 (Tensor or Number): an input tensor or number
  22204. tensor2 (Tensor or Number): an input tensor or number
  22205. Example::
  22206. >>> torch.result_type(torch.tensor([1, 2], dtype=torch.int), 1.0)
  22207. torch.float32
  22208. >>> torch.result_type(torch.tensor([1, 2], dtype=torch.uint8), torch.tensor(1))
  22209. torch.uint8
  22210. """
  22211. @overload
  22212. def result_type(tensor: Tensor, other: Number | _complex) -> _dtype:
  22213. r"""
  22214. result_type(tensor1, tensor2) -> dtype
  22215. Returns the :class:`torch.dtype` that would result from performing an arithmetic
  22216. operation on the provided input tensors. See type promotion :ref:`documentation <type-promotion-doc>`
  22217. for more information on the type promotion logic.
  22218. Args:
  22219. tensor1 (Tensor or Number): an input tensor or number
  22220. tensor2 (Tensor or Number): an input tensor or number
  22221. Example::
  22222. >>> torch.result_type(torch.tensor([1, 2], dtype=torch.int), 1.0)
  22223. torch.float32
  22224. >>> torch.result_type(torch.tensor([1, 2], dtype=torch.uint8), torch.tensor(1))
  22225. torch.uint8
  22226. """
  22227. @overload
  22228. def result_type(
  22229. scalar1: Number | _complex,
  22230. scalar2: Number | _complex,
  22231. ) -> _dtype:
  22232. r"""
  22233. result_type(tensor1, tensor2) -> dtype
  22234. Returns the :class:`torch.dtype` that would result from performing an arithmetic
  22235. operation on the provided input tensors. See type promotion :ref:`documentation <type-promotion-doc>`
  22236. for more information on the type promotion logic.
  22237. Args:
  22238. tensor1 (Tensor or Number): an input tensor or number
  22239. tensor2 (Tensor or Number): an input tensor or number
  22240. Example::
  22241. >>> torch.result_type(torch.tensor([1, 2], dtype=torch.int), 1.0)
  22242. torch.float32
  22243. >>> torch.result_type(torch.tensor([1, 2], dtype=torch.uint8), torch.tensor(1))
  22244. torch.uint8
  22245. """
  22246. def rms_norm(
  22247. input: Tensor,
  22248. normalized_shape: Sequence[_int | SymInt],
  22249. weight: Tensor | None = None,
  22250. eps: _float | None = None,
  22251. ) -> Tensor: ...
  22252. @overload
  22253. def rnn_relu(
  22254. data: Tensor,
  22255. batch_sizes: Tensor,
  22256. hx: Tensor,
  22257. params: tuple[Tensor, ...] | list[Tensor] | None,
  22258. has_biases: _bool,
  22259. num_layers: _int,
  22260. dropout: _float,
  22261. train: _bool,
  22262. bidirectional: _bool,
  22263. ) -> tuple[Tensor, Tensor]: ...
  22264. @overload
  22265. def rnn_relu(
  22266. input: Tensor,
  22267. hx: Tensor,
  22268. params: tuple[Tensor, ...] | list[Tensor] | None,
  22269. has_biases: _bool,
  22270. num_layers: _int,
  22271. dropout: _float,
  22272. train: _bool,
  22273. bidirectional: _bool,
  22274. batch_first: _bool,
  22275. ) -> tuple[Tensor, Tensor]: ...
  22276. def rnn_relu_cell(
  22277. input: Tensor,
  22278. hx: Tensor,
  22279. w_ih: Tensor,
  22280. w_hh: Tensor,
  22281. b_ih: Tensor | None = None,
  22282. b_hh: Tensor | None = None,
  22283. ) -> Tensor: ...
  22284. @overload
  22285. def rnn_tanh(
  22286. data: Tensor,
  22287. batch_sizes: Tensor,
  22288. hx: Tensor,
  22289. params: tuple[Tensor, ...] | list[Tensor] | None,
  22290. has_biases: _bool,
  22291. num_layers: _int,
  22292. dropout: _float,
  22293. train: _bool,
  22294. bidirectional: _bool,
  22295. ) -> tuple[Tensor, Tensor]: ...
  22296. @overload
  22297. def rnn_tanh(
  22298. input: Tensor,
  22299. hx: Tensor,
  22300. params: tuple[Tensor, ...] | list[Tensor] | None,
  22301. has_biases: _bool,
  22302. num_layers: _int,
  22303. dropout: _float,
  22304. train: _bool,
  22305. bidirectional: _bool,
  22306. batch_first: _bool,
  22307. ) -> tuple[Tensor, Tensor]: ...
  22308. def rnn_tanh_cell(
  22309. input: Tensor,
  22310. hx: Tensor,
  22311. w_ih: Tensor,
  22312. w_hh: Tensor,
  22313. b_ih: Tensor | None = None,
  22314. b_hh: Tensor | None = None,
  22315. ) -> Tensor: ...
  22316. def roll(
  22317. input: Tensor,
  22318. shifts: _int | SymInt | Sequence[_int | SymInt],
  22319. dims: _int | _size = (),
  22320. ) -> Tensor:
  22321. r"""
  22322. roll(input, shifts, dims=None) -> Tensor
  22323. Roll the tensor :attr:`input` along the given dimension(s). Elements that are
  22324. shifted beyond the last position are re-introduced at the first position. If
  22325. :attr:`dims` is `None`, the tensor will be flattened before rolling and then
  22326. restored to the original shape.
  22327. Args:
  22328. input (Tensor): the input tensor.
  22329. shifts (int or tuple of ints): The number of places by which the elements
  22330. of the tensor are shifted. If shifts is a tuple, dims must be a tuple of
  22331. the same size, and each dimension will be rolled by the corresponding
  22332. value
  22333. dims (int or tuple of ints): Axis along which to roll
  22334. Example::
  22335. >>> x = torch.tensor([1, 2, 3, 4, 5, 6, 7, 8]).view(4, 2)
  22336. >>> x
  22337. tensor([[1, 2],
  22338. [3, 4],
  22339. [5, 6],
  22340. [7, 8]])
  22341. >>> torch.roll(x, 1)
  22342. tensor([[8, 1],
  22343. [2, 3],
  22344. [4, 5],
  22345. [6, 7]])
  22346. >>> torch.roll(x, 1, 0)
  22347. tensor([[7, 8],
  22348. [1, 2],
  22349. [3, 4],
  22350. [5, 6]])
  22351. >>> torch.roll(x, -1, 0)
  22352. tensor([[3, 4],
  22353. [5, 6],
  22354. [7, 8],
  22355. [1, 2]])
  22356. >>> torch.roll(x, shifts=(2, 1), dims=(0, 1))
  22357. tensor([[6, 5],
  22358. [8, 7],
  22359. [2, 1],
  22360. [4, 3]])
  22361. """
  22362. def rot90(input: Tensor, k: _int = 1, dims: _size = (0, 1)) -> Tensor:
  22363. r"""
  22364. rot90(input, k=1, dims=(0, 1)) -> Tensor
  22365. Rotate an n-D tensor by 90 degrees in the plane specified by dims axis.
  22366. Rotation direction is from the first towards the second axis if k > 0, and from the second towards the first for k < 0.
  22367. Args:
  22368. input (Tensor): the input tensor.
  22369. k (int): number of times to rotate. Default value is 1
  22370. dims (a list or tuple): axis to rotate. Default value is [0, 1]
  22371. Example::
  22372. >>> x = torch.arange(4).view(2, 2)
  22373. >>> x
  22374. tensor([[0, 1],
  22375. [2, 3]])
  22376. >>> torch.rot90(x, 1, [0, 1])
  22377. tensor([[1, 3],
  22378. [0, 2]])
  22379. >>> x = torch.arange(8).view(2, 2, 2)
  22380. >>> x
  22381. tensor([[[0, 1],
  22382. [2, 3]],
  22383. [[4, 5],
  22384. [6, 7]]])
  22385. >>> torch.rot90(x, 1, [1, 2])
  22386. tensor([[[1, 3],
  22387. [0, 2]],
  22388. [[5, 7],
  22389. [4, 6]]])
  22390. """
  22391. @overload
  22392. def round(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  22393. r"""
  22394. round(input, *, decimals=0, out=None) -> Tensor
  22395. Rounds elements of :attr:`input` to the nearest integer.
  22396. For integer inputs, follows the array-api convention of returning a
  22397. copy of the input tensor.
  22398. The return type of output is same as that of input's dtype.
  22399. .. note::
  22400. This function implements the "round half to even" to
  22401. break ties when a number is equidistant from two
  22402. integers (e.g. `round(2.5)` is 2).
  22403. When the :attr:\`decimals\` argument is specified the
  22404. algorithm used is similar to NumPy's `around`. This
  22405. algorithm is fast but inexact and it can easily
  22406. overflow for low precision dtypes.
  22407. Eg. `round(tensor([10000], dtype=torch.float16), decimals=3)` is `inf`.
  22408. .. seealso::
  22409. :func:`torch.ceil`, which rounds up.
  22410. :func:`torch.floor`, which rounds down.
  22411. :func:`torch.trunc`, which rounds towards zero.
  22412. Args:
  22413. input (Tensor): the input tensor.
  22414. decimals (int): Number of decimal places to round to (default: 0).
  22415. If decimals is negative, it specifies the number of positions
  22416. to the left of the decimal point.
  22417. Keyword args:
  22418. out (Tensor, optional): the output tensor.
  22419. Example::
  22420. >>> torch.round(torch.tensor((4.7, -2.3, 9.1, -7.7)))
  22421. tensor([ 5., -2., 9., -8.])
  22422. >>> # Values equidistant from two integers are rounded towards the
  22423. >>> # the nearest even value (zero is treated as even)
  22424. >>> torch.round(torch.tensor([-0.5, 0.5, 1.5, 2.5]))
  22425. tensor([-0., 0., 2., 2.])
  22426. >>> # A positive decimals argument rounds to the to that decimal place
  22427. >>> torch.round(torch.tensor([0.1234567]), decimals=3)
  22428. tensor([0.1230])
  22429. >>> # A negative decimals argument rounds to the left of the decimal
  22430. >>> torch.round(torch.tensor([1200.1234567]), decimals=-3)
  22431. tensor([1000.])
  22432. """
  22433. @overload
  22434. def round(
  22435. input: Tensor,
  22436. *,
  22437. decimals: _int,
  22438. out: Tensor | None = None,
  22439. ) -> Tensor:
  22440. r"""
  22441. round(input, *, decimals=0, out=None) -> Tensor
  22442. Rounds elements of :attr:`input` to the nearest integer.
  22443. For integer inputs, follows the array-api convention of returning a
  22444. copy of the input tensor.
  22445. The return type of output is same as that of input's dtype.
  22446. .. note::
  22447. This function implements the "round half to even" to
  22448. break ties when a number is equidistant from two
  22449. integers (e.g. `round(2.5)` is 2).
  22450. When the :attr:\`decimals\` argument is specified the
  22451. algorithm used is similar to NumPy's `around`. This
  22452. algorithm is fast but inexact and it can easily
  22453. overflow for low precision dtypes.
  22454. Eg. `round(tensor([10000], dtype=torch.float16), decimals=3)` is `inf`.
  22455. .. seealso::
  22456. :func:`torch.ceil`, which rounds up.
  22457. :func:`torch.floor`, which rounds down.
  22458. :func:`torch.trunc`, which rounds towards zero.
  22459. Args:
  22460. input (Tensor): the input tensor.
  22461. decimals (int): Number of decimal places to round to (default: 0).
  22462. If decimals is negative, it specifies the number of positions
  22463. to the left of the decimal point.
  22464. Keyword args:
  22465. out (Tensor, optional): the output tensor.
  22466. Example::
  22467. >>> torch.round(torch.tensor((4.7, -2.3, 9.1, -7.7)))
  22468. tensor([ 5., -2., 9., -8.])
  22469. >>> # Values equidistant from two integers are rounded towards the
  22470. >>> # the nearest even value (zero is treated as even)
  22471. >>> torch.round(torch.tensor([-0.5, 0.5, 1.5, 2.5]))
  22472. tensor([-0., 0., 2., 2.])
  22473. >>> # A positive decimals argument rounds to the to that decimal place
  22474. >>> torch.round(torch.tensor([0.1234567]), decimals=3)
  22475. tensor([0.1230])
  22476. >>> # A negative decimals argument rounds to the left of the decimal
  22477. >>> torch.round(torch.tensor([1200.1234567]), decimals=-3)
  22478. tensor([1000.])
  22479. """
  22480. @overload
  22481. def round_(input: Tensor) -> Tensor: ...
  22482. @overload
  22483. def round_(input: Tensor, *, decimals: _int) -> Tensor: ...
  22484. def row_indices_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor: ...
  22485. def row_stack(
  22486. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  22487. *,
  22488. out: Tensor | None = None,
  22489. ) -> Tensor:
  22490. r"""
  22491. row_stack(tensors, *, out=None) -> Tensor
  22492. Alias of :func:`torch.vstack`.
  22493. """
  22494. def rrelu(
  22495. input: Tensor,
  22496. lower: Number | _complex = 0.125,
  22497. upper: Number | _complex = 0.3333333333333333,
  22498. training: _bool = False,
  22499. generator: Generator | None = None,
  22500. ) -> Tensor: ...
  22501. def rrelu_(
  22502. input: Tensor,
  22503. lower: Number | _complex = 0.125,
  22504. upper: Number | _complex = 0.3333333333333333,
  22505. training: _bool = False,
  22506. generator: Generator | None = None,
  22507. ) -> Tensor: ...
  22508. def rsqrt(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  22509. r"""
  22510. rsqrt(input, *, out=None) -> Tensor
  22511. Returns a new tensor with the reciprocal of the square-root of each of
  22512. the elements of :attr:`input`.
  22513. .. math::
  22514. \text{out}_{i} = \frac{1}{\sqrt{\text{input}_{i}}}
  22515. Args:
  22516. input (Tensor): the input tensor.
  22517. Keyword args:
  22518. out (Tensor, optional): the output tensor.
  22519. Example::
  22520. >>> a = torch.randn(4)
  22521. >>> a
  22522. tensor([-0.0370, 0.2970, 1.5420, -0.9105])
  22523. >>> torch.rsqrt(a)
  22524. tensor([ nan, 1.8351, 0.8053, nan])
  22525. """
  22526. def rsqrt_(input: Tensor) -> Tensor: ...
  22527. @overload
  22528. def rsub(
  22529. input: Tensor,
  22530. other: Tensor,
  22531. *,
  22532. alpha: Number | _complex = 1,
  22533. ) -> Tensor: ...
  22534. @overload
  22535. def rsub(
  22536. input: Tensor,
  22537. other: Number | _complex,
  22538. alpha: Number | _complex = 1,
  22539. ) -> Tensor: ...
  22540. def saddmm(
  22541. input: Tensor,
  22542. mat1: Tensor,
  22543. mat2: Tensor,
  22544. *,
  22545. beta: Number = 1,
  22546. alpha: Number = 1,
  22547. out: Tensor | None = None,
  22548. ) -> Tensor: ...
  22549. def scalar_tensor(
  22550. s: Number | _complex,
  22551. *,
  22552. dtype: _dtype | None = None,
  22553. layout: _layout | None = None,
  22554. device: DeviceLikeType | None = None,
  22555. pin_memory: _bool | None = False,
  22556. requires_grad: _bool | None = False,
  22557. ) -> Tensor: ...
  22558. @overload
  22559. def scatter(
  22560. input: Tensor,
  22561. dim: _int,
  22562. index: Tensor,
  22563. src: Tensor,
  22564. *,
  22565. reduce: str,
  22566. out: Tensor | None = None,
  22567. ) -> Tensor:
  22568. r"""
  22569. scatter(input, dim, index, src) -> Tensor
  22570. Out-of-place version of :meth:`torch.Tensor.scatter_`
  22571. """
  22572. @overload
  22573. def scatter(
  22574. input: Tensor,
  22575. dim: _int,
  22576. index: Tensor,
  22577. src: Tensor,
  22578. *,
  22579. out: Tensor | None = None,
  22580. ) -> Tensor:
  22581. r"""
  22582. scatter(input, dim, index, src) -> Tensor
  22583. Out-of-place version of :meth:`torch.Tensor.scatter_`
  22584. """
  22585. @overload
  22586. def scatter(
  22587. input: Tensor,
  22588. dim: _int,
  22589. index: Tensor,
  22590. value: Number | _complex,
  22591. *,
  22592. reduce: str,
  22593. out: Tensor | None = None,
  22594. ) -> Tensor:
  22595. r"""
  22596. scatter(input, dim, index, src) -> Tensor
  22597. Out-of-place version of :meth:`torch.Tensor.scatter_`
  22598. """
  22599. @overload
  22600. def scatter(
  22601. input: Tensor,
  22602. dim: str | EllipsisType | None,
  22603. index: Tensor,
  22604. src: Tensor,
  22605. ) -> Tensor:
  22606. r"""
  22607. scatter(input, dim, index, src) -> Tensor
  22608. Out-of-place version of :meth:`torch.Tensor.scatter_`
  22609. """
  22610. @overload
  22611. def scatter(
  22612. input: Tensor,
  22613. dim: _int,
  22614. index: Tensor,
  22615. value: Number | _complex,
  22616. *,
  22617. out: Tensor | None = None,
  22618. ) -> Tensor:
  22619. r"""
  22620. scatter(input, dim, index, src) -> Tensor
  22621. Out-of-place version of :meth:`torch.Tensor.scatter_`
  22622. """
  22623. @overload
  22624. def scatter(
  22625. input: Tensor,
  22626. dim: str | EllipsisType | None,
  22627. index: Tensor,
  22628. value: Number | _complex,
  22629. ) -> Tensor:
  22630. r"""
  22631. scatter(input, dim, index, src) -> Tensor
  22632. Out-of-place version of :meth:`torch.Tensor.scatter_`
  22633. """
  22634. @overload
  22635. def scatter_add(
  22636. input: Tensor,
  22637. dim: _int,
  22638. index: Tensor,
  22639. src: Tensor,
  22640. *,
  22641. out: Tensor | None = None,
  22642. ) -> Tensor:
  22643. r"""
  22644. scatter_add(input, dim, index, src) -> Tensor
  22645. Out-of-place version of :meth:`torch.Tensor.scatter_add_`
  22646. """
  22647. @overload
  22648. def scatter_add(
  22649. input: Tensor,
  22650. dim: str | EllipsisType | None,
  22651. index: Tensor,
  22652. src: Tensor,
  22653. ) -> Tensor:
  22654. r"""
  22655. scatter_add(input, dim, index, src) -> Tensor
  22656. Out-of-place version of :meth:`torch.Tensor.scatter_add_`
  22657. """
  22658. def scatter_reduce(
  22659. input: Tensor,
  22660. dim: _int,
  22661. index: Tensor,
  22662. src: Tensor,
  22663. reduce: str,
  22664. *,
  22665. include_self: _bool = True,
  22666. out: Tensor | None = None,
  22667. ) -> Tensor:
  22668. r"""
  22669. scatter_reduce(input, dim, index, src, reduce, *, include_self=True) -> Tensor
  22670. Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
  22671. """
  22672. @overload
  22673. def searchsorted(
  22674. sorted_sequence: Tensor,
  22675. input: Tensor,
  22676. *,
  22677. out_int32: _bool = False,
  22678. right: _bool = False,
  22679. side: str | None = None,
  22680. sorter: Tensor | None = None,
  22681. out: Tensor | None = None,
  22682. ) -> Tensor:
  22683. r"""
  22684. searchsorted(sorted_sequence, values, *, out_int32=False, right=False, side=None, out=None, sorter=None) -> Tensor
  22685. Find the indices from the *innermost* dimension of :attr:`sorted_sequence` such that, if the
  22686. corresponding values in :attr:`values` were inserted before the indices, when sorted, the order
  22687. of the corresponding *innermost* dimension within :attr:`sorted_sequence` would be preserved.
  22688. Return a new tensor with the same size as :attr:`values`. More formally,
  22689. the returned index satisfies the following rules:
  22690. .. list-table::
  22691. :widths: 12 10 78
  22692. :header-rows: 1
  22693. * - :attr:`sorted_sequence`
  22694. - :attr:`right`
  22695. - *returned index satisfies*
  22696. * - 1-D
  22697. - False
  22698. - ``sorted_sequence[i-1] < values[m][n]...[l][x] <= sorted_sequence[i]``
  22699. * - 1-D
  22700. - True
  22701. - ``sorted_sequence[i-1] <= values[m][n]...[l][x] < sorted_sequence[i]``
  22702. * - N-D
  22703. - False
  22704. - ``sorted_sequence[m][n]...[l][i-1] < values[m][n]...[l][x] <= sorted_sequence[m][n]...[l][i]``
  22705. * - N-D
  22706. - True
  22707. - ``sorted_sequence[m][n]...[l][i-1] <= values[m][n]...[l][x] < sorted_sequence[m][n]...[l][i]``
  22708. Args:
  22709. sorted_sequence (Tensor): N-D or 1-D tensor, containing monotonically increasing sequence on the *innermost*
  22710. dimension unless :attr:`sorter` is provided, in which case the sequence does not
  22711. need to be sorted
  22712. values (Tensor or Scalar): N-D tensor or a Scalar containing the search value(s).
  22713. Keyword args:
  22714. out_int32 (bool, optional): indicate the output data type. torch.int32 if True, torch.int64 otherwise.
  22715. Default value is False, i.e. default output data type is torch.int64.
  22716. right (bool, optional): if False, return the first suitable location that is found. If True, return the
  22717. last such index. If no suitable index found, return 0 for non-numerical value
  22718. (eg. nan, inf) or the size of *innermost* dimension within :attr:`sorted_sequence`
  22719. (one pass the last index of the *innermost* dimension). In other words, if False,
  22720. gets the lower bound index for each value in :attr:`values` on the corresponding
  22721. *innermost* dimension of the :attr:`sorted_sequence`. If True, gets the upper
  22722. bound index instead. Default value is False. :attr:`side` does the same and is
  22723. preferred. It will error if :attr:`side` is set to "left" while this is True.
  22724. side (str, optional): the same as :attr:`right` but preferred. "left" corresponds to False for :attr:`right`
  22725. and "right" corresponds to True for :attr:`right`. It will error if this is set to
  22726. "left" while :attr:`right` is True. Default value is None.
  22727. out (Tensor, optional): the output tensor, must be the same size as :attr:`values` if provided.
  22728. sorter (LongTensor, optional): if provided, a tensor matching the shape of the unsorted
  22729. :attr:`sorted_sequence` containing a sequence of indices that sort it in the
  22730. ascending order on the innermost dimension
  22731. Example::
  22732. >>> sorted_sequence = torch.tensor([[1, 3, 5, 7, 9], [2, 4, 6, 8, 10]])
  22733. >>> sorted_sequence
  22734. tensor([[ 1, 3, 5, 7, 9],
  22735. [ 2, 4, 6, 8, 10]])
  22736. >>> values = torch.tensor([[3, 6, 9], [3, 6, 9]])
  22737. >>> values
  22738. tensor([[3, 6, 9],
  22739. [3, 6, 9]])
  22740. >>> torch.searchsorted(sorted_sequence, values)
  22741. tensor([[1, 3, 4],
  22742. [1, 2, 4]])
  22743. >>> torch.searchsorted(sorted_sequence, values, side='right')
  22744. tensor([[2, 3, 5],
  22745. [1, 3, 4]])
  22746. >>> sorted_sequence_1d = torch.tensor([1, 3, 5, 7, 9])
  22747. >>> sorted_sequence_1d
  22748. tensor([1, 3, 5, 7, 9])
  22749. >>> torch.searchsorted(sorted_sequence_1d, values)
  22750. tensor([[1, 3, 4],
  22751. [1, 3, 4]])
  22752. """
  22753. @overload
  22754. def searchsorted(
  22755. sorted_sequence: Tensor,
  22756. self: Number | _complex,
  22757. *,
  22758. out_int32: _bool = False,
  22759. right: _bool = False,
  22760. side: str | None = None,
  22761. sorter: Tensor | None = None,
  22762. out: Tensor | None = None,
  22763. ) -> Tensor:
  22764. r"""
  22765. searchsorted(sorted_sequence, values, *, out_int32=False, right=False, side=None, out=None, sorter=None) -> Tensor
  22766. Find the indices from the *innermost* dimension of :attr:`sorted_sequence` such that, if the
  22767. corresponding values in :attr:`values` were inserted before the indices, when sorted, the order
  22768. of the corresponding *innermost* dimension within :attr:`sorted_sequence` would be preserved.
  22769. Return a new tensor with the same size as :attr:`values`. More formally,
  22770. the returned index satisfies the following rules:
  22771. .. list-table::
  22772. :widths: 12 10 78
  22773. :header-rows: 1
  22774. * - :attr:`sorted_sequence`
  22775. - :attr:`right`
  22776. - *returned index satisfies*
  22777. * - 1-D
  22778. - False
  22779. - ``sorted_sequence[i-1] < values[m][n]...[l][x] <= sorted_sequence[i]``
  22780. * - 1-D
  22781. - True
  22782. - ``sorted_sequence[i-1] <= values[m][n]...[l][x] < sorted_sequence[i]``
  22783. * - N-D
  22784. - False
  22785. - ``sorted_sequence[m][n]...[l][i-1] < values[m][n]...[l][x] <= sorted_sequence[m][n]...[l][i]``
  22786. * - N-D
  22787. - True
  22788. - ``sorted_sequence[m][n]...[l][i-1] <= values[m][n]...[l][x] < sorted_sequence[m][n]...[l][i]``
  22789. Args:
  22790. sorted_sequence (Tensor): N-D or 1-D tensor, containing monotonically increasing sequence on the *innermost*
  22791. dimension unless :attr:`sorter` is provided, in which case the sequence does not
  22792. need to be sorted
  22793. values (Tensor or Scalar): N-D tensor or a Scalar containing the search value(s).
  22794. Keyword args:
  22795. out_int32 (bool, optional): indicate the output data type. torch.int32 if True, torch.int64 otherwise.
  22796. Default value is False, i.e. default output data type is torch.int64.
  22797. right (bool, optional): if False, return the first suitable location that is found. If True, return the
  22798. last such index. If no suitable index found, return 0 for non-numerical value
  22799. (eg. nan, inf) or the size of *innermost* dimension within :attr:`sorted_sequence`
  22800. (one pass the last index of the *innermost* dimension). In other words, if False,
  22801. gets the lower bound index for each value in :attr:`values` on the corresponding
  22802. *innermost* dimension of the :attr:`sorted_sequence`. If True, gets the upper
  22803. bound index instead. Default value is False. :attr:`side` does the same and is
  22804. preferred. It will error if :attr:`side` is set to "left" while this is True.
  22805. side (str, optional): the same as :attr:`right` but preferred. "left" corresponds to False for :attr:`right`
  22806. and "right" corresponds to True for :attr:`right`. It will error if this is set to
  22807. "left" while :attr:`right` is True. Default value is None.
  22808. out (Tensor, optional): the output tensor, must be the same size as :attr:`values` if provided.
  22809. sorter (LongTensor, optional): if provided, a tensor matching the shape of the unsorted
  22810. :attr:`sorted_sequence` containing a sequence of indices that sort it in the
  22811. ascending order on the innermost dimension
  22812. Example::
  22813. >>> sorted_sequence = torch.tensor([[1, 3, 5, 7, 9], [2, 4, 6, 8, 10]])
  22814. >>> sorted_sequence
  22815. tensor([[ 1, 3, 5, 7, 9],
  22816. [ 2, 4, 6, 8, 10]])
  22817. >>> values = torch.tensor([[3, 6, 9], [3, 6, 9]])
  22818. >>> values
  22819. tensor([[3, 6, 9],
  22820. [3, 6, 9]])
  22821. >>> torch.searchsorted(sorted_sequence, values)
  22822. tensor([[1, 3, 4],
  22823. [1, 2, 4]])
  22824. >>> torch.searchsorted(sorted_sequence, values, side='right')
  22825. tensor([[2, 3, 5],
  22826. [1, 3, 4]])
  22827. >>> sorted_sequence_1d = torch.tensor([1, 3, 5, 7, 9])
  22828. >>> sorted_sequence_1d
  22829. tensor([1, 3, 5, 7, 9])
  22830. >>> torch.searchsorted(sorted_sequence_1d, values)
  22831. tensor([[1, 3, 4],
  22832. [1, 3, 4]])
  22833. """
  22834. def segment_reduce(
  22835. data: Tensor,
  22836. reduce: str,
  22837. *,
  22838. lengths: Tensor | None = None,
  22839. indices: Tensor | None = None,
  22840. offsets: Tensor | None = None,
  22841. axis: _int = 0,
  22842. unsafe: _bool = False,
  22843. initial: Number | _complex | None = None,
  22844. ) -> Tensor:
  22845. r"""
  22846. 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
  22847. Perform a segment reduction operation on the input tensor along the specified axis.
  22848. Args:
  22849. data (Tensor): The input tensor on which the segment reduction operation will be performed.
  22850. reduce (str): The type of reduction operation. Supported values are ``sum``, ``mean``, ``max``, ``min``, ``prod``.
  22851. Keyword args:
  22852. lengths (Tensor, optional): Length of each segment. Default: ``None``.
  22853. offsets (Tensor, optional): Offset of each segment. Default: ``None``.
  22854. axis (int, optional): The axis perform reduction. Default: ``0``.
  22855. unsafe (bool, optional): Skip validation If `True`. Default: ``False``.
  22856. initial (Number, optional): The initial value for the reduction operation. Default: ``None``.
  22857. Example::
  22858. >>> data = torch.tensor([[1, 2, 3, 4],[5, 6, 7, 8],[9, 10, 11, 12]], dtype=torch.float32, device='cuda')
  22859. >>> lengths = torch.tensor([2, 1], device='cuda')
  22860. >>> torch.segment_reduce(data, 'max', lengths=lengths)
  22861. tensor([[ 5., 6., 7., 8.],
  22862. [ 9., 10., 11., 12.]], device='cuda:0')
  22863. """
  22864. @overload
  22865. def select(input: Tensor, dim: _int, index: _int | SymInt) -> Tensor:
  22866. r"""
  22867. select(input, dim, index) -> Tensor
  22868. Slices the :attr:`input` tensor along the selected dimension at the given index.
  22869. This function returns a view of the original tensor with the given dimension removed.
  22870. .. note:: If :attr:`input` is a sparse tensor and returning a view of
  22871. the tensor is not possible, a RuntimeError exception is
  22872. raised. In this is the case, consider using
  22873. :func:`torch.select_copy` function.
  22874. Args:
  22875. input (Tensor): the input tensor.
  22876. dim (int): the dimension to slice
  22877. index (int): the index to select with
  22878. .. note::
  22879. :meth:`select` is equivalent to slicing. For example,
  22880. ``tensor.select(0, index)`` is equivalent to ``tensor[index]`` and
  22881. ``tensor.select(2, index)`` is equivalent to ``tensor[:,:,index]``.
  22882. """
  22883. @overload
  22884. def select(
  22885. input: Tensor,
  22886. dim: str | EllipsisType | None,
  22887. index: _int,
  22888. ) -> Tensor:
  22889. r"""
  22890. select(input, dim, index) -> Tensor
  22891. Slices the :attr:`input` tensor along the selected dimension at the given index.
  22892. This function returns a view of the original tensor with the given dimension removed.
  22893. .. note:: If :attr:`input` is a sparse tensor and returning a view of
  22894. the tensor is not possible, a RuntimeError exception is
  22895. raised. In this is the case, consider using
  22896. :func:`torch.select_copy` function.
  22897. Args:
  22898. input (Tensor): the input tensor.
  22899. dim (int): the dimension to slice
  22900. index (int): the index to select with
  22901. .. note::
  22902. :meth:`select` is equivalent to slicing. For example,
  22903. ``tensor.select(0, index)`` is equivalent to ``tensor[index]`` and
  22904. ``tensor.select(2, index)`` is equivalent to ``tensor[:,:,index]``.
  22905. """
  22906. def select_copy(
  22907. input: Tensor,
  22908. dim: _int,
  22909. index: _int | SymInt,
  22910. *,
  22911. out: Tensor | None = None,
  22912. ) -> Tensor:
  22913. r"""
  22914. Performs the same operation as :func:`torch.select`, but all output tensors
  22915. are freshly created instead of aliasing the input.
  22916. """
  22917. def select_scatter(
  22918. input: Tensor,
  22919. src: Tensor,
  22920. dim: _int,
  22921. index: _int | SymInt,
  22922. ) -> Tensor:
  22923. r"""
  22924. select_scatter(input, src, dim, index) -> Tensor
  22925. Embeds the values of the :attr:`src` tensor into :attr:`input` at the given index.
  22926. This function returns a tensor with fresh storage; it does not create a view.
  22927. Args:
  22928. input (Tensor): the input tensor.
  22929. src (Tensor): The tensor to embed into :attr:`input`
  22930. dim (int): the dimension to insert the slice into.
  22931. index (int): the index to select with
  22932. .. note::
  22933. :attr:`src` must be of the proper size in order to be embedded
  22934. into :attr:`input`. Specifically, it should have the same shape as
  22935. ``torch.select(input, dim, index)``
  22936. Example::
  22937. >>> a = torch.zeros(2, 2)
  22938. >>> b = torch.ones(2)
  22939. >>> a.select_scatter(b, 0, 0)
  22940. tensor([[1., 1.],
  22941. [0., 0.]])
  22942. """
  22943. def selu(input: Tensor) -> Tensor: ...
  22944. def selu_(input: Tensor) -> Tensor: ...
  22945. def set_flush_denormal(mode: _bool) -> _bool:
  22946. r"""
  22947. set_flush_denormal(mode) -> bool
  22948. Disables denormal floating numbers on CPU.
  22949. Returns ``True`` if your system supports flushing denormal numbers and it
  22950. successfully configures flush denormal mode. :meth:`~torch.set_flush_denormal`
  22951. is supported on x86 architectures supporting SSE3 and AArch64 architecture.
  22952. Args:
  22953. mode (bool): Controls whether to enable flush denormal mode or not
  22954. Example::
  22955. >>> torch.set_flush_denormal(True)
  22956. True
  22957. >>> torch.tensor([1e-323], dtype=torch.float64)
  22958. tensor([ 0.], dtype=torch.float64)
  22959. >>> torch.set_flush_denormal(False)
  22960. True
  22961. >>> torch.tensor([1e-323], dtype=torch.float64)
  22962. tensor(9.88131e-324 *
  22963. [ 1.0000], dtype=torch.float64)
  22964. """
  22965. def set_num_interop_threads(num: _int) -> None:
  22966. r"""
  22967. set_num_interop_threads(int)
  22968. Sets the number of threads used for interop parallelism
  22969. (e.g. in JIT interpreter) on CPU.
  22970. .. warning::
  22971. Can only be called once and before any inter-op parallel work
  22972. is started (e.g. JIT execution).
  22973. """
  22974. def set_num_threads(num: _int) -> None:
  22975. r"""
  22976. set_num_threads(int)
  22977. Sets the number of threads used for intraop parallelism on CPU.
  22978. .. warning::
  22979. To ensure that the correct number of threads is used, set_num_threads
  22980. must be called before running eager, JIT or autograd code.
  22981. """
  22982. def sgn(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  22983. r"""
  22984. sgn(input, *, out=None) -> Tensor
  22985. This function is an extension of torch.sign() to complex tensors.
  22986. It computes a new tensor whose elements have
  22987. the same angles as the corresponding elements of :attr:`input` and
  22988. absolute values (i.e. magnitudes) of one for complex tensors and
  22989. is equivalent to torch.sign() for non-complex tensors.
  22990. .. math::
  22991. \text{out}_{i} = \begin{cases}
  22992. 0 & |\text{{input}}_i| == 0 \\
  22993. \frac{{\text{{input}}_i}}{|{\text{{input}}_i}|} & \text{otherwise}
  22994. \end{cases}
  22995. Args:
  22996. input (Tensor): the input tensor.
  22997. Keyword args:
  22998. out (Tensor, optional): the output tensor.
  22999. Example::
  23000. >>> t = torch.tensor([3+4j, 7-24j, 0, 1+2j])
  23001. >>> t.sgn()
  23002. tensor([0.6000+0.8000j, 0.2800-0.9600j, 0.0000+0.0000j, 0.4472+0.8944j])
  23003. """
  23004. def sigmoid(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  23005. r"""
  23006. sigmoid(input, *, out=None) -> Tensor
  23007. Alias for :func:`torch.special.expit`.
  23008. """
  23009. def sigmoid_(input: Tensor) -> Tensor: ...
  23010. def sign(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  23011. r"""
  23012. sign(input, *, out=None) -> Tensor
  23013. Returns a new tensor with the signs of the elements of :attr:`input`.
  23014. .. math::
  23015. \text{out}_{i} = \operatorname{sgn}(\text{input}_{i})
  23016. Args:
  23017. input (Tensor): the input tensor.
  23018. Keyword args:
  23019. out (Tensor, optional): the output tensor.
  23020. Example::
  23021. >>> a = torch.tensor([0.7, -1.2, 0., 2.3])
  23022. >>> a
  23023. tensor([ 0.7000, -1.2000, 0.0000, 2.3000])
  23024. >>> torch.sign(a)
  23025. tensor([ 1., -1., 0., 1.])
  23026. """
  23027. def signbit(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  23028. r"""
  23029. signbit(input, *, out=None) -> Tensor
  23030. Tests if each element of :attr:`input` has its sign bit set or not.
  23031. Args:
  23032. input (Tensor): the input tensor.
  23033. Keyword args:
  23034. out (Tensor, optional): the output tensor.
  23035. Example::
  23036. >>> a = torch.tensor([0.7, -1.2, 0., 2.3])
  23037. >>> torch.signbit(a)
  23038. tensor([ False, True, False, False])
  23039. >>> a = torch.tensor([-0.0, 0.0])
  23040. >>> torch.signbit(a)
  23041. tensor([ True, False])
  23042. .. note::
  23043. signbit handles signed zeros, so negative zero (-0) returns True.
  23044. """
  23045. def sin(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  23046. r"""
  23047. sin(input, *, out=None) -> Tensor
  23048. Returns a new tensor with the sine of the elements in the :attr:`input` tensor,
  23049. where each value in this input tensor is in radians.
  23050. .. math::
  23051. \text{out}_{i} = \sin(\text{input}_{i})
  23052. Args:
  23053. input (Tensor): the input tensor.
  23054. Keyword args:
  23055. out (Tensor, optional): the output tensor.
  23056. Example::
  23057. >>> a = torch.randn(4)
  23058. >>> a
  23059. tensor([-0.5461, 0.1347, -2.7266, -0.2746])
  23060. >>> torch.sin(a)
  23061. tensor([-0.5194, 0.1343, -0.4032, -0.2711])
  23062. """
  23063. def sin_(input: Tensor) -> Tensor: ...
  23064. def sinc(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  23065. r"""
  23066. sinc(input, *, out=None) -> Tensor
  23067. Alias for :func:`torch.special.sinc`.
  23068. """
  23069. def sinc_(input: Tensor) -> Tensor: ...
  23070. def sinh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  23071. r"""
  23072. sinh(input, *, out=None) -> Tensor
  23073. Returns a new tensor with the hyperbolic sine of the elements of
  23074. :attr:`input`.
  23075. .. math::
  23076. \text{out}_{i} = \sinh(\text{input}_{i})
  23077. Args:
  23078. input (Tensor): the input tensor.
  23079. Keyword args:
  23080. out (Tensor, optional): the output tensor.
  23081. Example::
  23082. >>> a = torch.randn(4)
  23083. >>> a
  23084. tensor([ 0.5380, -0.8632, -0.1265, 0.9399])
  23085. >>> torch.sinh(a)
  23086. tensor([ 0.5644, -0.9744, -0.1268, 1.0845])
  23087. .. note::
  23088. When :attr:`input` is on the CPU, the implementation of torch.sinh may use
  23089. the Sleef library, which rounds very large results to infinity or negative
  23090. infinity. See `here <https://sleef.org/purec.xhtml>`_ for details.
  23091. """
  23092. def sinh_(input: Tensor) -> Tensor: ...
  23093. def slice_copy(
  23094. input: Tensor,
  23095. dim: _int = 0,
  23096. start: _int | SymInt | None = None,
  23097. end: _int | SymInt | None = None,
  23098. step: _int | SymInt = 1,
  23099. *,
  23100. out: Tensor | None = None,
  23101. ) -> Tensor:
  23102. r"""
  23103. Performs the same operation as :func:`torch.slice`, but all output tensors
  23104. are freshly created instead of aliasing the input.
  23105. """
  23106. def slice_inverse(
  23107. input: Tensor,
  23108. src: Tensor,
  23109. dim: _int = 0,
  23110. start: _int | SymInt | None = None,
  23111. end: _int | SymInt | None = None,
  23112. step: _int | SymInt = 1,
  23113. ) -> Tensor: ...
  23114. def slice_scatter(
  23115. input: Tensor,
  23116. src: Tensor,
  23117. dim: _int = 0,
  23118. start: _int | SymInt | None = None,
  23119. end: _int | SymInt | None = None,
  23120. step: _int | SymInt = 1,
  23121. *,
  23122. out: Tensor | None = None,
  23123. ) -> Tensor:
  23124. r"""
  23125. slice_scatter(input, src, dim=0, start=None, end=None, step=1) -> Tensor
  23126. Embeds the values of the :attr:`src` tensor into :attr:`input` at the given
  23127. dimension.
  23128. This function returns a tensor with fresh storage; it does not create a view.
  23129. Args:
  23130. input (Tensor): the input tensor.
  23131. src (Tensor): The tensor to embed into :attr:`input`
  23132. dim (int): the dimension to insert the slice into
  23133. start (Optional[int]): the start index of where to insert the slice
  23134. end (Optional[int]): the end index of where to insert the slice
  23135. step (int): the how many elements to skip in
  23136. Example::
  23137. >>> a = torch.zeros(8, 8)
  23138. >>> b = torch.ones(2, 8)
  23139. >>> a.slice_scatter(b, start=6)
  23140. tensor([[0., 0., 0., 0., 0., 0., 0., 0.],
  23141. [0., 0., 0., 0., 0., 0., 0., 0.],
  23142. [0., 0., 0., 0., 0., 0., 0., 0.],
  23143. [0., 0., 0., 0., 0., 0., 0., 0.],
  23144. [0., 0., 0., 0., 0., 0., 0., 0.],
  23145. [0., 0., 0., 0., 0., 0., 0., 0.],
  23146. [1., 1., 1., 1., 1., 1., 1., 1.],
  23147. [1., 1., 1., 1., 1., 1., 1., 1.]])
  23148. >>> b = torch.ones(8, 2)
  23149. >>> a.slice_scatter(b, dim=1, start=2, end=6, step=2)
  23150. tensor([[0., 0., 1., 0., 1., 0., 0., 0.],
  23151. [0., 0., 1., 0., 1., 0., 0., 0.],
  23152. [0., 0., 1., 0., 1., 0., 0., 0.],
  23153. [0., 0., 1., 0., 1., 0., 0., 0.],
  23154. [0., 0., 1., 0., 1., 0., 0., 0.],
  23155. [0., 0., 1., 0., 1., 0., 0., 0.],
  23156. [0., 0., 1., 0., 1., 0., 0., 0.],
  23157. [0., 0., 1., 0., 1., 0., 0., 0.]])
  23158. """
  23159. def slogdet(
  23160. input: Tensor,
  23161. *,
  23162. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  23163. ) -> torch.return_types.slogdet:
  23164. r"""
  23165. slogdet(input) -> (Tensor, Tensor)
  23166. Alias for :func:`torch.linalg.slogdet`
  23167. """
  23168. def smm(input: Tensor, mat2: Tensor) -> Tensor:
  23169. r"""
  23170. smm(input, mat) -> Tensor
  23171. Performs a matrix multiplication of the sparse matrix :attr:`input`
  23172. with the dense matrix :attr:`mat`.
  23173. Args:
  23174. input (Tensor): a sparse matrix to be matrix multiplied
  23175. mat (Tensor): a dense matrix to be matrix multiplied
  23176. """
  23177. @overload
  23178. def softmax(
  23179. input: Tensor,
  23180. dim: _int,
  23181. dtype: _dtype | None = None,
  23182. *,
  23183. out: Tensor | None = None,
  23184. ) -> Tensor:
  23185. r"""
  23186. softmax(input, dim, *, dtype=None) -> Tensor
  23187. Alias for :func:`torch.nn.functional.softmax`.
  23188. """
  23189. @overload
  23190. def softmax(
  23191. input: Tensor,
  23192. dim: str | EllipsisType | None,
  23193. *,
  23194. dtype: _dtype | None = None,
  23195. ) -> Tensor:
  23196. r"""
  23197. softmax(input, dim, *, dtype=None) -> Tensor
  23198. Alias for :func:`torch.nn.functional.softmax`.
  23199. """
  23200. @overload
  23201. def sort(
  23202. input: Tensor,
  23203. *,
  23204. stable: _bool | None,
  23205. dim: _int = -1,
  23206. descending: _bool = False,
  23207. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  23208. ) -> torch.return_types.sort:
  23209. r"""
  23210. sort(input, dim=-1, descending=False, *, stable=False, out=None) -> (Tensor, LongTensor)
  23211. Sorts the elements of the :attr:`input` tensor along a given dimension
  23212. in ascending order by value.
  23213. If :attr:`dim` is not given, the last dimension of the `input` is chosen.
  23214. If :attr:`descending` is ``True`` then the elements are sorted in descending
  23215. order by value.
  23216. If :attr:`stable` is ``True`` then the sorting routine becomes stable, preserving
  23217. the order of equivalent elements.
  23218. A namedtuple of (values, indices) is returned, where the `values` are the
  23219. sorted values and `indices` are the indices of the elements in the original
  23220. `input` tensor.
  23221. Args:
  23222. input (Tensor): the input tensor.
  23223. dim (int, optional): the dimension to sort along
  23224. descending (bool, optional): controls the sorting order (ascending or descending)
  23225. Keyword args:
  23226. stable (bool, optional): makes the sorting routine stable, which guarantees that the order
  23227. of equivalent elements is preserved.
  23228. out (tuple, optional): the output tuple of (`Tensor`, `LongTensor`) that can
  23229. be optionally given to be used as output buffers
  23230. Example::
  23231. >>> x = torch.randn(3, 4)
  23232. >>> sorted, indices = torch.sort(x)
  23233. >>> sorted
  23234. tensor([[-0.2162, 0.0608, 0.6719, 2.3332],
  23235. [-0.5793, 0.0061, 0.6058, 0.9497],
  23236. [-0.5071, 0.3343, 0.9553, 1.0960]])
  23237. >>> indices
  23238. tensor([[ 1, 0, 2, 3],
  23239. [ 3, 1, 0, 2],
  23240. [ 0, 3, 1, 2]])
  23241. >>> sorted, indices = torch.sort(x, 0)
  23242. >>> sorted
  23243. tensor([[-0.5071, -0.2162, 0.6719, -0.5793],
  23244. [ 0.0608, 0.0061, 0.9497, 0.3343],
  23245. [ 0.6058, 0.9553, 1.0960, 2.3332]])
  23246. >>> indices
  23247. tensor([[ 2, 0, 0, 1],
  23248. [ 0, 1, 1, 2],
  23249. [ 1, 2, 2, 0]])
  23250. >>> x = torch.tensor([0, 1] * 9)
  23251. >>> x.sort()
  23252. torch.return_types.sort(
  23253. values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
  23254. indices=tensor([ 2, 16, 4, 6, 14, 8, 0, 10, 12, 9, 17, 15, 13, 11, 7, 5, 3, 1]))
  23255. >>> x.sort(stable=True)
  23256. torch.return_types.sort(
  23257. values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
  23258. indices=tensor([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 17]))
  23259. """
  23260. @overload
  23261. def sort(
  23262. input: Tensor,
  23263. dim: _int = -1,
  23264. descending: _bool = False,
  23265. *,
  23266. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  23267. ) -> torch.return_types.sort:
  23268. r"""
  23269. sort(input, dim=-1, descending=False, *, stable=False, out=None) -> (Tensor, LongTensor)
  23270. Sorts the elements of the :attr:`input` tensor along a given dimension
  23271. in ascending order by value.
  23272. If :attr:`dim` is not given, the last dimension of the `input` is chosen.
  23273. If :attr:`descending` is ``True`` then the elements are sorted in descending
  23274. order by value.
  23275. If :attr:`stable` is ``True`` then the sorting routine becomes stable, preserving
  23276. the order of equivalent elements.
  23277. A namedtuple of (values, indices) is returned, where the `values` are the
  23278. sorted values and `indices` are the indices of the elements in the original
  23279. `input` tensor.
  23280. Args:
  23281. input (Tensor): the input tensor.
  23282. dim (int, optional): the dimension to sort along
  23283. descending (bool, optional): controls the sorting order (ascending or descending)
  23284. Keyword args:
  23285. stable (bool, optional): makes the sorting routine stable, which guarantees that the order
  23286. of equivalent elements is preserved.
  23287. out (tuple, optional): the output tuple of (`Tensor`, `LongTensor`) that can
  23288. be optionally given to be used as output buffers
  23289. Example::
  23290. >>> x = torch.randn(3, 4)
  23291. >>> sorted, indices = torch.sort(x)
  23292. >>> sorted
  23293. tensor([[-0.2162, 0.0608, 0.6719, 2.3332],
  23294. [-0.5793, 0.0061, 0.6058, 0.9497],
  23295. [-0.5071, 0.3343, 0.9553, 1.0960]])
  23296. >>> indices
  23297. tensor([[ 1, 0, 2, 3],
  23298. [ 3, 1, 0, 2],
  23299. [ 0, 3, 1, 2]])
  23300. >>> sorted, indices = torch.sort(x, 0)
  23301. >>> sorted
  23302. tensor([[-0.5071, -0.2162, 0.6719, -0.5793],
  23303. [ 0.0608, 0.0061, 0.9497, 0.3343],
  23304. [ 0.6058, 0.9553, 1.0960, 2.3332]])
  23305. >>> indices
  23306. tensor([[ 2, 0, 0, 1],
  23307. [ 0, 1, 1, 2],
  23308. [ 1, 2, 2, 0]])
  23309. >>> x = torch.tensor([0, 1] * 9)
  23310. >>> x.sort()
  23311. torch.return_types.sort(
  23312. values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
  23313. indices=tensor([ 2, 16, 4, 6, 14, 8, 0, 10, 12, 9, 17, 15, 13, 11, 7, 5, 3, 1]))
  23314. >>> x.sort(stable=True)
  23315. torch.return_types.sort(
  23316. values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
  23317. indices=tensor([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 17]))
  23318. """
  23319. @overload
  23320. def sort(
  23321. input: Tensor,
  23322. *,
  23323. stable: _bool | None,
  23324. dim: str | EllipsisType | None,
  23325. descending: _bool = False,
  23326. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  23327. ) -> torch.return_types.sort:
  23328. r"""
  23329. sort(input, dim=-1, descending=False, *, stable=False, out=None) -> (Tensor, LongTensor)
  23330. Sorts the elements of the :attr:`input` tensor along a given dimension
  23331. in ascending order by value.
  23332. If :attr:`dim` is not given, the last dimension of the `input` is chosen.
  23333. If :attr:`descending` is ``True`` then the elements are sorted in descending
  23334. order by value.
  23335. If :attr:`stable` is ``True`` then the sorting routine becomes stable, preserving
  23336. the order of equivalent elements.
  23337. A namedtuple of (values, indices) is returned, where the `values` are the
  23338. sorted values and `indices` are the indices of the elements in the original
  23339. `input` tensor.
  23340. Args:
  23341. input (Tensor): the input tensor.
  23342. dim (int, optional): the dimension to sort along
  23343. descending (bool, optional): controls the sorting order (ascending or descending)
  23344. Keyword args:
  23345. stable (bool, optional): makes the sorting routine stable, which guarantees that the order
  23346. of equivalent elements is preserved.
  23347. out (tuple, optional): the output tuple of (`Tensor`, `LongTensor`) that can
  23348. be optionally given to be used as output buffers
  23349. Example::
  23350. >>> x = torch.randn(3, 4)
  23351. >>> sorted, indices = torch.sort(x)
  23352. >>> sorted
  23353. tensor([[-0.2162, 0.0608, 0.6719, 2.3332],
  23354. [-0.5793, 0.0061, 0.6058, 0.9497],
  23355. [-0.5071, 0.3343, 0.9553, 1.0960]])
  23356. >>> indices
  23357. tensor([[ 1, 0, 2, 3],
  23358. [ 3, 1, 0, 2],
  23359. [ 0, 3, 1, 2]])
  23360. >>> sorted, indices = torch.sort(x, 0)
  23361. >>> sorted
  23362. tensor([[-0.5071, -0.2162, 0.6719, -0.5793],
  23363. [ 0.0608, 0.0061, 0.9497, 0.3343],
  23364. [ 0.6058, 0.9553, 1.0960, 2.3332]])
  23365. >>> indices
  23366. tensor([[ 2, 0, 0, 1],
  23367. [ 0, 1, 1, 2],
  23368. [ 1, 2, 2, 0]])
  23369. >>> x = torch.tensor([0, 1] * 9)
  23370. >>> x.sort()
  23371. torch.return_types.sort(
  23372. values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
  23373. indices=tensor([ 2, 16, 4, 6, 14, 8, 0, 10, 12, 9, 17, 15, 13, 11, 7, 5, 3, 1]))
  23374. >>> x.sort(stable=True)
  23375. torch.return_types.sort(
  23376. values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
  23377. indices=tensor([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 17]))
  23378. """
  23379. @overload
  23380. def sort(
  23381. input: Tensor,
  23382. dim: str | EllipsisType | None,
  23383. descending: _bool = False,
  23384. *,
  23385. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  23386. ) -> torch.return_types.sort:
  23387. r"""
  23388. sort(input, dim=-1, descending=False, *, stable=False, out=None) -> (Tensor, LongTensor)
  23389. Sorts the elements of the :attr:`input` tensor along a given dimension
  23390. in ascending order by value.
  23391. If :attr:`dim` is not given, the last dimension of the `input` is chosen.
  23392. If :attr:`descending` is ``True`` then the elements are sorted in descending
  23393. order by value.
  23394. If :attr:`stable` is ``True`` then the sorting routine becomes stable, preserving
  23395. the order of equivalent elements.
  23396. A namedtuple of (values, indices) is returned, where the `values` are the
  23397. sorted values and `indices` are the indices of the elements in the original
  23398. `input` tensor.
  23399. Args:
  23400. input (Tensor): the input tensor.
  23401. dim (int, optional): the dimension to sort along
  23402. descending (bool, optional): controls the sorting order (ascending or descending)
  23403. Keyword args:
  23404. stable (bool, optional): makes the sorting routine stable, which guarantees that the order
  23405. of equivalent elements is preserved.
  23406. out (tuple, optional): the output tuple of (`Tensor`, `LongTensor`) that can
  23407. be optionally given to be used as output buffers
  23408. Example::
  23409. >>> x = torch.randn(3, 4)
  23410. >>> sorted, indices = torch.sort(x)
  23411. >>> sorted
  23412. tensor([[-0.2162, 0.0608, 0.6719, 2.3332],
  23413. [-0.5793, 0.0061, 0.6058, 0.9497],
  23414. [-0.5071, 0.3343, 0.9553, 1.0960]])
  23415. >>> indices
  23416. tensor([[ 1, 0, 2, 3],
  23417. [ 3, 1, 0, 2],
  23418. [ 0, 3, 1, 2]])
  23419. >>> sorted, indices = torch.sort(x, 0)
  23420. >>> sorted
  23421. tensor([[-0.5071, -0.2162, 0.6719, -0.5793],
  23422. [ 0.0608, 0.0061, 0.9497, 0.3343],
  23423. [ 0.6058, 0.9553, 1.0960, 2.3332]])
  23424. >>> indices
  23425. tensor([[ 2, 0, 0, 1],
  23426. [ 0, 1, 1, 2],
  23427. [ 1, 2, 2, 0]])
  23428. >>> x = torch.tensor([0, 1] * 9)
  23429. >>> x.sort()
  23430. torch.return_types.sort(
  23431. values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
  23432. indices=tensor([ 2, 16, 4, 6, 14, 8, 0, 10, 12, 9, 17, 15, 13, 11, 7, 5, 3, 1]))
  23433. >>> x.sort(stable=True)
  23434. torch.return_types.sort(
  23435. values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
  23436. indices=tensor([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 17]))
  23437. """
  23438. def sparse_bsc_tensor(
  23439. ccol_indices: Tensor | list,
  23440. row_indices: Tensor | list,
  23441. values: Tensor | list,
  23442. size: _size | None = None,
  23443. *,
  23444. dtype: _dtype | None = None,
  23445. device: DeviceLikeType | None = None,
  23446. requires_grad: _bool = False,
  23447. check_invariants: _bool | None = None,
  23448. ) -> Tensor:
  23449. r"""
  23450. sparse_bsc_tensor(ccol_indices, row_indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) -> Tensor
  23451. Constructs a :ref:`sparse tensor in BSC (Block Compressed Sparse
  23452. Column)) <sparse-bsc-docs>` with specified 2-dimensional blocks at the
  23453. given :attr:`ccol_indices` and :attr:`row_indices`. Sparse matrix
  23454. multiplication operations in BSC format are typically faster than that
  23455. for sparse tensors in COO format. Make you have a look at :ref:`the
  23456. note on the data type of the indices <sparse-bsc-docs>`.
  23457. .. note::
  23458. If the ``device`` argument is not specified the device of the given
  23459. :attr:`values` and indices tensor(s) must match. If, however, the
  23460. argument is specified the input Tensors will be converted to the
  23461. given device and in turn determine the device of the constructed
  23462. sparse tensor.
  23463. Args:
  23464. ccol_indices (array_like): (B+1)-dimensional array of size
  23465. ``(*batchsize, ncolblocks + 1)``. The last element of each
  23466. batch is the number of non-zeros. This tensor encodes the
  23467. index in values and row_indices depending on where the given
  23468. column starts. Each successive number in the tensor subtracted
  23469. by the number before it denotes the number of elements in a
  23470. given column.
  23471. row_indices (array_like): Row block coordinates of each block in
  23472. values. (B+1)-dimensional tensor with the same length
  23473. as values.
  23474. values (array_list): Initial blocks for the tensor. Can be a list,
  23475. tuple, NumPy ``ndarray``, and other types that
  23476. represents a (1 + 2 + K)-dimensional tensor where ``K`` is the
  23477. number of dense dimensions.
  23478. size (list, tuple, :class:`torch.Size`, optional): Size of the
  23479. sparse tensor: ``(*batchsize, nrows * blocksize[0], ncols *
  23480. blocksize[1], *densesize)`` If not provided, the size will be
  23481. inferred as the minimum size big enough to hold all non-zero
  23482. blocks.
  23483. Keyword args:
  23484. dtype (:class:`torch.dtype`, optional): the desired data type of
  23485. returned tensor. Default: if None, infers data type from
  23486. :attr:`values`.
  23487. device (:class:`torch.device`, optional): the desired device of
  23488. returned tensor. Default: if None, uses the current device
  23489. for the default tensor type (see
  23490. :func:`torch.set_default_device`). :attr:`device` will be
  23491. the CPU for CPU tensor types and the current CUDA device for
  23492. CUDA tensor types.
  23493. pin_memory (bool, optional): If set, returned tensor would be allocated in
  23494. the pinned memory. Works only for CPU tensors. Default: ``False``.
  23495. requires_grad (bool, optional): If autograd should record operations on the
  23496. returned tensor. Default: ``False``.
  23497. check_invariants (bool, optional): If sparse tensor invariants are checked.
  23498. Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
  23499. initially False.
  23500. Example::
  23501. >>> ccol_indices = [0, 1, 2]
  23502. >>> row_indices = [0, 1]
  23503. >>> values = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
  23504. >>> torch.sparse_bsc_tensor(torch.tensor(ccol_indices, dtype=torch.int64),
  23505. ... torch.tensor(row_indices, dtype=torch.int64),
  23506. ... torch.tensor(values), dtype=torch.double)
  23507. tensor(ccol_indices=tensor([0, 1, 2]),
  23508. row_indices=tensor([0, 1]),
  23509. values=tensor([[[1., 2.],
  23510. [3., 4.]],
  23511. [[5., 6.],
  23512. [7., 8.]]]), size=(2, 2), nnz=2, dtype=torch.float64,
  23513. layout=torch.sparse_bsc)
  23514. """
  23515. def sparse_bsr_tensor(
  23516. crow_indices: Tensor | list,
  23517. col_indices: Tensor | list,
  23518. values: Tensor | list,
  23519. size: _size | None = None,
  23520. *,
  23521. dtype: _dtype | None = None,
  23522. device: DeviceLikeType | None = None,
  23523. requires_grad: _bool = False,
  23524. check_invariants: _bool | None = None,
  23525. ) -> Tensor:
  23526. r"""
  23527. sparse_bsr_tensor(crow_indices, col_indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) -> Tensor
  23528. Constructs a :ref:`sparse tensor in BSR (Block Compressed Sparse Row))
  23529. <sparse-bsr-docs>` with specified 2-dimensional blocks at the given
  23530. :attr:`crow_indices` and :attr:`col_indices`. Sparse matrix
  23531. multiplication operations in BSR format are typically faster than that
  23532. for sparse tensors in COO format. Make you have a look at :ref:`the
  23533. note on the data type of the indices <sparse-bsr-docs>`.
  23534. .. note::
  23535. If the ``device`` argument is not specified the device of the given
  23536. :attr:`values` and indices tensor(s) must match. If, however, the
  23537. argument is specified the input Tensors will be converted to the
  23538. given device and in turn determine the device of the constructed
  23539. sparse tensor.
  23540. Args:
  23541. crow_indices (array_like): (B+1)-dimensional array of size
  23542. ``(*batchsize, nrowblocks + 1)``. The last element of each
  23543. batch is the number of non-zeros. This tensor encodes the
  23544. block index in values and col_indices depending on where the
  23545. given row block starts. Each successive number in the tensor
  23546. subtracted by the number before it denotes the number of
  23547. blocks in a given row.
  23548. col_indices (array_like): Column block coordinates of each block
  23549. in values. (B+1)-dimensional tensor with the same length as
  23550. values.
  23551. values (array_list): Initial values for the tensor. Can be a list,
  23552. tuple, NumPy ``ndarray``, scalar, and other types that
  23553. represents a (1 + 2 + K)-dimensional tensor where ``K`` is the
  23554. number of dense dimensions.
  23555. size (list, tuple, :class:`torch.Size`, optional): Size of the
  23556. sparse tensor: ``(*batchsize, nrows * blocksize[0], ncols *
  23557. blocksize[1], *densesize)`` where ``blocksize ==
  23558. values.shape[1:3]``. If not provided, the size will be
  23559. inferred as the minimum size big enough to hold all non-zero
  23560. blocks.
  23561. Keyword args:
  23562. dtype (:class:`torch.dtype`, optional): the desired data type of
  23563. returned tensor. Default: if None, infers data type from
  23564. :attr:`values`.
  23565. device (:class:`torch.device`, optional): the desired device of
  23566. returned tensor. Default: if None, uses the current device
  23567. for the default tensor type (see
  23568. :func:`torch.set_default_device`). :attr:`device` will be
  23569. the CPU for CPU tensor types and the current CUDA device for
  23570. CUDA tensor types.
  23571. pin_memory (bool, optional): If set, returned tensor would be allocated in
  23572. the pinned memory. Works only for CPU tensors. Default: ``False``.
  23573. requires_grad (bool, optional): If autograd should record operations on the
  23574. returned tensor. Default: ``False``.
  23575. check_invariants (bool, optional): If sparse tensor invariants are checked.
  23576. Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
  23577. initially False.
  23578. Example::
  23579. >>> crow_indices = [0, 1, 2]
  23580. >>> col_indices = [0, 1]
  23581. >>> values = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
  23582. >>> torch.sparse_bsr_tensor(torch.tensor(crow_indices, dtype=torch.int64),
  23583. ... torch.tensor(col_indices, dtype=torch.int64),
  23584. ... torch.tensor(values), dtype=torch.double)
  23585. tensor(crow_indices=tensor([0, 1, 2]),
  23586. col_indices=tensor([0, 1]),
  23587. values=tensor([[[1., 2.],
  23588. [3., 4.]],
  23589. [[5., 6.],
  23590. [7., 8.]]]), size=(2, 2), nnz=2, dtype=torch.float64,
  23591. layout=torch.sparse_bsr)
  23592. """
  23593. def sparse_compressed_tensor(
  23594. compressed_indices: Tensor | list,
  23595. plain_indices: Tensor | list,
  23596. values: Tensor | list,
  23597. size: _size | None = None,
  23598. *,
  23599. dtype: _dtype | None = None,
  23600. layout: _layout | None = None,
  23601. device: DeviceLikeType | None = None,
  23602. requires_grad: _bool = False,
  23603. check_invariants: _bool | None = None,
  23604. ) -> Tensor:
  23605. r"""
  23606. 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
  23607. Constructs a :ref:`sparse tensor in Compressed Sparse format - CSR,
  23608. CSC, BSR, or BSC - <sparse-compressed-docs>` with specified values at
  23609. the given :attr:`compressed_indices` and :attr:`plain_indices`. Sparse
  23610. matrix multiplication operations in Compressed Sparse format are
  23611. typically faster than that for sparse tensors in COO format. Make you
  23612. have a look at :ref:`the note on the data type of the indices
  23613. <sparse-compressed-docs>`.
  23614. .. note::
  23615. If the ``device`` argument is not specified the device of the given
  23616. :attr:`values` and indices tensor(s) must match. If, however, the
  23617. argument is specified the input Tensors will be converted to the
  23618. given device and in turn determine the device of the constructed
  23619. sparse tensor.
  23620. Args:
  23621. compressed_indices (array_like): (B+1)-dimensional array of size
  23622. ``(*batchsize, compressed_dim_size + 1)``. The last element of
  23623. each batch is the number of non-zero elements or blocks. This
  23624. tensor encodes the index in ``values`` and ``plain_indices``
  23625. depending on where the given compressed dimension (row or
  23626. column) starts. Each successive number in the tensor
  23627. subtracted by the number before it denotes the number of
  23628. elements or blocks in a given compressed dimension.
  23629. plain_indices (array_like): Plain dimension (column or row)
  23630. coordinates of each element or block in values. (B+1)-dimensional
  23631. tensor with the same length as values.
  23632. values (array_list): Initial values for the tensor. Can be a list,
  23633. tuple, NumPy ``ndarray``, scalar, and other types. that
  23634. represents a (1+K)-dimensional (for CSR and CSC layouts) or
  23635. (1+2+K)-dimensional tensor (for BSR and BSC layouts) where
  23636. ``K`` is the number of dense dimensions.
  23637. size (list, tuple, :class:`torch.Size`, optional): Size of the
  23638. sparse tensor: ``(*batchsize, nrows * blocksize[0], ncols *
  23639. blocksize[1], *densesize)`` where ``blocksize[0] ==
  23640. blocksize[1] == 1`` for CSR and CSC formats. If not provided,
  23641. the size will be inferred as the minimum size big enough to
  23642. hold all non-zero elements or blocks.
  23643. Keyword args:
  23644. dtype (:class:`torch.dtype`, optional): the desired data type of
  23645. returned tensor. Default: if None, infers data type from
  23646. :attr:`values`.
  23647. layout (:class:`torch.layout`, required): the desired layout of
  23648. returned tensor: :attr:`torch.sparse_csr`,
  23649. :attr:`torch.sparse_csc`, :attr:`torch.sparse_bsr`, or
  23650. :attr:`torch.sparse_bsc`.
  23651. device (:class:`torch.device`, optional): the desired device of
  23652. returned tensor. Default: if None, uses the current device
  23653. for the default tensor type (see
  23654. :func:`torch.set_default_device`). :attr:`device` will be
  23655. the CPU for CPU tensor types and the current CUDA device for
  23656. CUDA tensor types.
  23657. pin_memory (bool, optional): If set, returned tensor would be allocated in
  23658. the pinned memory. Works only for CPU tensors. Default: ``False``.
  23659. requires_grad (bool, optional): If autograd should record operations on the
  23660. returned tensor. Default: ``False``.
  23661. check_invariants (bool, optional): If sparse tensor invariants are checked.
  23662. Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
  23663. initially False.
  23664. Example::
  23665. >>> compressed_indices = [0, 2, 4]
  23666. >>> plain_indices = [0, 1, 0, 1]
  23667. >>> values = [1, 2, 3, 4]
  23668. >>> torch.sparse_compressed_tensor(torch.tensor(compressed_indices, dtype=torch.int64),
  23669. ... torch.tensor(plain_indices, dtype=torch.int64),
  23670. ... torch.tensor(values), dtype=torch.double, layout=torch.sparse_csr)
  23671. tensor(crow_indices=tensor([0, 2, 4]),
  23672. col_indices=tensor([0, 1, 0, 1]),
  23673. values=tensor([1., 2., 3., 4.]), size=(2, 2), nnz=4,
  23674. dtype=torch.float64, layout=torch.sparse_csr)
  23675. """
  23676. def sparse_coo_tensor(
  23677. indices: Tensor,
  23678. values: Tensor | list,
  23679. size: _size | None = None,
  23680. *,
  23681. dtype: _dtype | None = None,
  23682. device: DeviceLikeType | None = None,
  23683. requires_grad: _bool = False,
  23684. check_invariants: _bool | None = None,
  23685. is_coalesced: _bool | None = None,
  23686. ) -> Tensor:
  23687. r"""
  23688. sparse_coo_tensor(indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None, is_coalesced=None) -> Tensor
  23689. Constructs a :ref:`sparse tensor in COO(rdinate) format
  23690. <sparse-coo-docs>` with specified values at the given
  23691. :attr:`indices`.
  23692. .. note::
  23693. This function returns an :ref:`uncoalesced tensor
  23694. <sparse-uncoalesced-coo-docs>` when :attr:`is_coalesced` is
  23695. unspecified or ``None``.
  23696. .. note::
  23697. If the ``device`` argument is not specified the device of the given
  23698. :attr:`values` and indices tensor(s) must match. If, however, the
  23699. argument is specified the input Tensors will be converted to the
  23700. given device and in turn determine the device of the constructed
  23701. sparse tensor.
  23702. Args:
  23703. indices (array_like): Initial data for the tensor. Can be a list, tuple,
  23704. NumPy ``ndarray``, scalar, and other types. Will be cast to a :class:`torch.LongTensor`
  23705. internally. The indices are the coordinates of the non-zero values in the matrix, and thus
  23706. should be two-dimensional where the first dimension is the number of tensor dimensions and
  23707. the second dimension is the number of non-zero values.
  23708. values (array_like): Initial values for the tensor. Can be a list, tuple,
  23709. NumPy ``ndarray``, scalar, and other types.
  23710. size (list, tuple, or :class:`torch.Size`, optional): Size of the sparse tensor. If not
  23711. provided the size will be inferred as the minimum size big enough to hold all non-zero
  23712. elements.
  23713. Keyword args:
  23714. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  23715. Default: if None, infers data type from :attr:`values`.
  23716. device (:class:`torch.device`, optional): the desired device of returned tensor.
  23717. Default: if None, uses the current device for the default tensor type
  23718. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  23719. for CPU tensor types and the current CUDA device for CUDA tensor types.
  23720. pin_memory (bool, optional): If set, returned tensor would be allocated in
  23721. the pinned memory. Works only for CPU tensors. Default: ``False``.
  23722. requires_grad (bool, optional): If autograd should record operations on the
  23723. returned tensor. Default: ``False``.
  23724. check_invariants (bool, optional): If sparse tensor invariants are checked.
  23725. Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
  23726. initially False.
  23727. is_coalesced (bool, optional): When``True``, the caller is
  23728. responsible for providing tensor indices that correspond to a
  23729. coalesced tensor. If the :attr:`check_invariants` flag is
  23730. False, no error will be raised if the prerequisites are not
  23731. met and this will lead to silently incorrect results. To force
  23732. coalescion please use :meth:`coalesce` on the resulting
  23733. Tensor.
  23734. Default: None: except for trivial cases (e.g. nnz < 2) the
  23735. resulting Tensor has is_coalesced set to ``False```.
  23736. Example::
  23737. >>> i = torch.tensor([[0, 1, 1],
  23738. ... [2, 0, 2]])
  23739. >>> v = torch.tensor([3, 4, 5], dtype=torch.float32)
  23740. >>> torch.sparse_coo_tensor(i, v, [2, 4])
  23741. tensor(indices=tensor([[0, 1, 1],
  23742. [2, 0, 2]]),
  23743. values=tensor([3., 4., 5.]),
  23744. size=(2, 4), nnz=3, layout=torch.sparse_coo)
  23745. >>> torch.sparse_coo_tensor(i, v) # Shape inference
  23746. tensor(indices=tensor([[0, 1, 1],
  23747. [2, 0, 2]]),
  23748. values=tensor([3., 4., 5.]),
  23749. size=(2, 3), nnz=3, layout=torch.sparse_coo)
  23750. >>> torch.sparse_coo_tensor(i, v, [2, 4],
  23751. ... dtype=torch.float64,
  23752. ... device=torch.device('cuda:0'))
  23753. tensor(indices=tensor([[0, 1, 1],
  23754. [2, 0, 2]]),
  23755. values=tensor([3., 4., 5.]),
  23756. device='cuda:0', size=(2, 4), nnz=3, dtype=torch.float64,
  23757. layout=torch.sparse_coo)
  23758. # Create an empty sparse tensor with the following invariants:
  23759. # 1. sparse_dim + dense_dim = len(SparseTensor.shape)
  23760. # 2. SparseTensor._indices().shape = (sparse_dim, nnz)
  23761. # 3. SparseTensor._values().shape = (nnz, SparseTensor.shape[sparse_dim:])
  23762. #
  23763. # For instance, to create an empty sparse tensor with nnz = 0, dense_dim = 0 and
  23764. # sparse_dim = 1 (hence indices is a 2D tensor of shape = (1, 0))
  23765. >>> S = torch.sparse_coo_tensor(torch.empty([1, 0]), [], [1])
  23766. tensor(indices=tensor([], size=(1, 0)),
  23767. values=tensor([], size=(0,)),
  23768. size=(1,), nnz=0, layout=torch.sparse_coo)
  23769. # and to create an empty sparse tensor with nnz = 0, dense_dim = 1 and
  23770. # sparse_dim = 1
  23771. >>> S = torch.sparse_coo_tensor(torch.empty([1, 0]), torch.empty([0, 2]), [1, 2])
  23772. tensor(indices=tensor([], size=(1, 0)),
  23773. values=tensor([], size=(0, 2)),
  23774. size=(1, 2), nnz=0, layout=torch.sparse_coo)
  23775. .. _torch.sparse: https://pytorch.org/docs/stable/sparse.html
  23776. """
  23777. def sparse_csc_tensor(
  23778. ccol_indices: Tensor | list,
  23779. row_indices: Tensor | list,
  23780. values: Tensor | list,
  23781. size: _size | None = None,
  23782. *,
  23783. dtype: _dtype | None = None,
  23784. device: DeviceLikeType | None = None,
  23785. requires_grad: _bool = False,
  23786. check_invariants: _bool | None = None,
  23787. ) -> Tensor:
  23788. r"""
  23789. sparse_csc_tensor(ccol_indices, row_indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) -> Tensor
  23790. Constructs a :ref:`sparse tensor in CSC (Compressed Sparse Column)
  23791. <sparse-csc-docs>` with specified values at the given
  23792. :attr:`ccol_indices` and :attr:`row_indices`. Sparse matrix
  23793. multiplication operations in CSC format are typically faster than that
  23794. for sparse tensors in COO format. Make you have a look at :ref:`the
  23795. note on the data type of the indices <sparse-csc-docs>`.
  23796. .. note::
  23797. If the ``device`` argument is not specified the device of the given
  23798. :attr:`values` and indices tensor(s) must match. If, however, the
  23799. argument is specified the input Tensors will be converted to the
  23800. given device and in turn determine the device of the constructed
  23801. sparse tensor.
  23802. Args:
  23803. ccol_indices (array_like): (B+1)-dimensional array of size
  23804. ``(*batchsize, ncols + 1)``. The last element of each batch
  23805. is the number of non-zeros. This tensor encodes the index in
  23806. values and row_indices depending on where the given column
  23807. starts. Each successive number in the tensor subtracted by the
  23808. number before it denotes the number of elements in a given
  23809. column.
  23810. row_indices (array_like): Row coordinates of each element in
  23811. values. (B+1)-dimensional tensor with the same length as
  23812. values.
  23813. values (array_list): Initial values for the tensor. Can be a list,
  23814. tuple, NumPy ``ndarray``, scalar, and other types that
  23815. represents a (1+K)-dimensional tensor where ``K`` is the number
  23816. of dense dimensions.
  23817. size (list, tuple, :class:`torch.Size`, optional): Size of the
  23818. sparse tensor: ``(*batchsize, nrows, ncols, *densesize)``. If
  23819. not provided, the size will be inferred as the minimum size
  23820. big enough to hold all non-zero elements.
  23821. Keyword args:
  23822. dtype (:class:`torch.dtype`, optional): the desired data type of
  23823. returned tensor. Default: if None, infers data type from
  23824. :attr:`values`.
  23825. device (:class:`torch.device`, optional): the desired device of
  23826. returned tensor. Default: if None, uses the current device
  23827. for the default tensor type (see
  23828. :func:`torch.set_default_device`). :attr:`device` will be
  23829. the CPU for CPU tensor types and the current CUDA device for
  23830. CUDA tensor types.
  23831. pin_memory (bool, optional): If set, returned tensor would be allocated in
  23832. the pinned memory. Works only for CPU tensors. Default: ``False``.
  23833. requires_grad (bool, optional): If autograd should record operations on the
  23834. returned tensor. Default: ``False``.
  23835. check_invariants (bool, optional): If sparse tensor invariants are checked.
  23836. Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
  23837. initially False.
  23838. Example::
  23839. >>> ccol_indices = [0, 2, 4]
  23840. >>> row_indices = [0, 1, 0, 1]
  23841. >>> values = [1, 2, 3, 4]
  23842. >>> torch.sparse_csc_tensor(torch.tensor(ccol_indices, dtype=torch.int64),
  23843. ... torch.tensor(row_indices, dtype=torch.int64),
  23844. ... torch.tensor(values), dtype=torch.double)
  23845. tensor(ccol_indices=tensor([0, 2, 4]),
  23846. row_indices=tensor([0, 1, 0, 1]),
  23847. values=tensor([1., 2., 3., 4.]), size=(2, 2), nnz=4,
  23848. dtype=torch.float64, layout=torch.sparse_csc)
  23849. """
  23850. def sparse_csr_tensor(
  23851. crow_indices: Tensor | list,
  23852. col_indices: Tensor | list,
  23853. values: Tensor | list,
  23854. size: _size | None = None,
  23855. *,
  23856. dtype: _dtype | None = None,
  23857. device: DeviceLikeType | None = None,
  23858. requires_grad: _bool = False,
  23859. check_invariants: _bool | None = None,
  23860. ) -> Tensor:
  23861. r"""
  23862. sparse_csr_tensor(crow_indices, col_indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) -> Tensor
  23863. Constructs a :ref:`sparse tensor in CSR (Compressed Sparse Row) <sparse-csr-docs>` with specified
  23864. values at the given :attr:`crow_indices` and :attr:`col_indices`. Sparse matrix multiplication operations
  23865. in CSR format are typically faster than that for sparse tensors in COO format. Make you have a look
  23866. at :ref:`the note on the data type of the indices <sparse-csr-docs>`.
  23867. .. note::
  23868. If the ``device`` argument is not specified the device of the given
  23869. :attr:`values` and indices tensor(s) must match. If, however, the
  23870. argument is specified the input Tensors will be converted to the
  23871. given device and in turn determine the device of the constructed
  23872. sparse tensor.
  23873. Args:
  23874. crow_indices (array_like): (B+1)-dimensional array of size
  23875. ``(*batchsize, nrows + 1)``. The last element of each batch
  23876. is the number of non-zeros. This tensor encodes the index in
  23877. values and col_indices depending on where the given row
  23878. starts. Each successive number in the tensor subtracted by the
  23879. number before it denotes the number of elements in a given
  23880. row.
  23881. col_indices (array_like): Column coordinates of each element in
  23882. values. (B+1)-dimensional tensor with the same length
  23883. as values.
  23884. values (array_list): Initial values for the tensor. Can be a list,
  23885. tuple, NumPy ``ndarray``, scalar, and other types that
  23886. represents a (1+K)-dimensional tensor where ``K`` is the number
  23887. of dense dimensions.
  23888. size (list, tuple, :class:`torch.Size`, optional): Size of the
  23889. sparse tensor: ``(*batchsize, nrows, ncols, *densesize)``. If
  23890. not provided, the size will be inferred as the minimum size
  23891. big enough to hold all non-zero elements.
  23892. Keyword args:
  23893. dtype (:class:`torch.dtype`, optional): the desired data type of
  23894. returned tensor. Default: if None, infers data type from
  23895. :attr:`values`.
  23896. device (:class:`torch.device`, optional): the desired device of
  23897. returned tensor. Default: if None, uses the current device
  23898. for the default tensor type (see
  23899. :func:`torch.set_default_device`). :attr:`device` will be
  23900. the CPU for CPU tensor types and the current CUDA device for
  23901. CUDA tensor types.
  23902. pin_memory (bool, optional): If set, returned tensor would be allocated in
  23903. the pinned memory. Works only for CPU tensors. Default: ``False``.
  23904. requires_grad (bool, optional): If autograd should record operations on the
  23905. returned tensor. Default: ``False``.
  23906. check_invariants (bool, optional): If sparse tensor invariants are checked.
  23907. Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
  23908. initially False.
  23909. Example::
  23910. >>> crow_indices = [0, 2, 4]
  23911. >>> col_indices = [0, 1, 0, 1]
  23912. >>> values = [1, 2, 3, 4]
  23913. >>> torch.sparse_csr_tensor(torch.tensor(crow_indices, dtype=torch.int64),
  23914. ... torch.tensor(col_indices, dtype=torch.int64),
  23915. ... torch.tensor(values), dtype=torch.double)
  23916. tensor(crow_indices=tensor([0, 2, 4]),
  23917. col_indices=tensor([0, 1, 0, 1]),
  23918. values=tensor([1., 2., 3., 4.]), size=(2, 2), nnz=4,
  23919. dtype=torch.float64, layout=torch.sparse_csr)
  23920. """
  23921. def split_copy(
  23922. input: Tensor,
  23923. split_size: _int | SymInt,
  23924. dim: _int = 0,
  23925. *,
  23926. out: tuple[Tensor, ...] | list[Tensor] | None = None,
  23927. ) -> None:
  23928. r"""
  23929. Performs the same operation as :func:`torch.split`, but all output tensors
  23930. are freshly created instead of aliasing the input.
  23931. """
  23932. def split_with_sizes(
  23933. input: Tensor,
  23934. split_sizes: Sequence[_int | SymInt],
  23935. dim: _int = 0,
  23936. ) -> tuple[Tensor, ...]: ...
  23937. def split_with_sizes_copy(
  23938. input: Tensor,
  23939. split_sizes: Sequence[_int | SymInt],
  23940. dim: _int = 0,
  23941. *,
  23942. out: tuple[Tensor, ...] | list[Tensor] | None = None,
  23943. ) -> None:
  23944. r"""
  23945. Performs the same operation as :func:`torch.split_with_sizes`, but all output tensors
  23946. are freshly created instead of aliasing the input.
  23947. """
  23948. def spmm(input: Tensor, mat2: Tensor) -> Tensor: ...
  23949. def sqrt(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  23950. r"""
  23951. sqrt(input, *, out=None) -> Tensor
  23952. Returns a new tensor with the square-root of the elements of :attr:`input`.
  23953. .. math::
  23954. \text{out}_{i} = \sqrt{\text{input}_{i}}
  23955. Args:
  23956. input (Tensor): the input tensor.
  23957. Keyword args:
  23958. out (Tensor, optional): the output tensor.
  23959. Example::
  23960. >>> a = torch.randn(4)
  23961. >>> a
  23962. tensor([-2.0755, 1.0226, 0.0831, 0.4806])
  23963. >>> torch.sqrt(a)
  23964. tensor([ nan, 1.0112, 0.2883, 0.6933])
  23965. """
  23966. def sqrt_(input: Tensor) -> Tensor: ...
  23967. def square(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  23968. r"""
  23969. square(input: Tensor, *, out: Optional[Tensor]) -> Tensor
  23970. Returns a new tensor with the square of the elements of :attr:`input`.
  23971. Args:
  23972. input (Tensor): the input tensor.
  23973. Keyword args:
  23974. out (Tensor, optional): the output tensor.
  23975. Example::
  23976. >>> a = torch.randn(4)
  23977. >>> a
  23978. tensor([-2.0755, 1.0226, 0.0831, 0.4806])
  23979. >>> torch.square(a)
  23980. tensor([ 4.3077, 1.0457, 0.0069, 0.2310])
  23981. """
  23982. def square_(input: Tensor) -> Tensor: ...
  23983. @overload
  23984. def squeeze(input: Tensor) -> Tensor:
  23985. r"""
  23986. squeeze(input: Tensor, dim: Optional[Union[int, List[int]]]) -> Tensor
  23987. Returns a tensor with all specified dimensions of :attr:`input` of size `1` removed.
  23988. For example, if `input` is of shape:
  23989. :math:`(A \times 1 \times B \times C \times 1 \times D)` then the `input.squeeze()`
  23990. will be of shape: :math:`(A \times B \times C \times D)`.
  23991. When :attr:`dim` is given, a squeeze operation is done only in the given
  23992. dimension(s). If `input` is of shape: :math:`(A \times 1 \times B)`,
  23993. ``squeeze(input, 0)`` leaves the tensor unchanged, but ``squeeze(input, 1)``
  23994. will squeeze the tensor to the shape :math:`(A \times B)`.
  23995. .. note:: The returned tensor shares the storage with the input tensor,
  23996. so changing the contents of one will change the contents of the other.
  23997. .. warning:: If the tensor has a batch dimension of size 1, then `squeeze(input)`
  23998. will also remove the batch dimension, which can lead to unexpected
  23999. errors. Consider specifying only the dims you wish to be squeezed.
  24000. Args:
  24001. input (Tensor): the input tensor.
  24002. dim (int or tuple of ints, optional): if given, the input will be squeezed
  24003. only in the specified dimensions.
  24004. .. versionchanged:: 2.0
  24005. :attr:`dim` now accepts tuples of dimensions.
  24006. Example::
  24007. >>> x = torch.zeros(2, 1, 2, 1, 2)
  24008. >>> x.size()
  24009. torch.Size([2, 1, 2, 1, 2])
  24010. >>> y = torch.squeeze(x)
  24011. >>> y.size()
  24012. torch.Size([2, 2, 2])
  24013. >>> y = torch.squeeze(x, 0)
  24014. >>> y.size()
  24015. torch.Size([2, 1, 2, 1, 2])
  24016. >>> y = torch.squeeze(x, 1)
  24017. >>> y.size()
  24018. torch.Size([2, 2, 1, 2])
  24019. >>> y = torch.squeeze(x, (1, 2, 3))
  24020. torch.Size([2, 2, 2])
  24021. """
  24022. @overload
  24023. def squeeze(input: Tensor, dim: _int) -> Tensor:
  24024. r"""
  24025. squeeze(input: Tensor, dim: Optional[Union[int, List[int]]]) -> Tensor
  24026. Returns a tensor with all specified dimensions of :attr:`input` of size `1` removed.
  24027. For example, if `input` is of shape:
  24028. :math:`(A \times 1 \times B \times C \times 1 \times D)` then the `input.squeeze()`
  24029. will be of shape: :math:`(A \times B \times C \times D)`.
  24030. When :attr:`dim` is given, a squeeze operation is done only in the given
  24031. dimension(s). If `input` is of shape: :math:`(A \times 1 \times B)`,
  24032. ``squeeze(input, 0)`` leaves the tensor unchanged, but ``squeeze(input, 1)``
  24033. will squeeze the tensor to the shape :math:`(A \times B)`.
  24034. .. note:: The returned tensor shares the storage with the input tensor,
  24035. so changing the contents of one will change the contents of the other.
  24036. .. warning:: If the tensor has a batch dimension of size 1, then `squeeze(input)`
  24037. will also remove the batch dimension, which can lead to unexpected
  24038. errors. Consider specifying only the dims you wish to be squeezed.
  24039. Args:
  24040. input (Tensor): the input tensor.
  24041. dim (int or tuple of ints, optional): if given, the input will be squeezed
  24042. only in the specified dimensions.
  24043. .. versionchanged:: 2.0
  24044. :attr:`dim` now accepts tuples of dimensions.
  24045. Example::
  24046. >>> x = torch.zeros(2, 1, 2, 1, 2)
  24047. >>> x.size()
  24048. torch.Size([2, 1, 2, 1, 2])
  24049. >>> y = torch.squeeze(x)
  24050. >>> y.size()
  24051. torch.Size([2, 2, 2])
  24052. >>> y = torch.squeeze(x, 0)
  24053. >>> y.size()
  24054. torch.Size([2, 1, 2, 1, 2])
  24055. >>> y = torch.squeeze(x, 1)
  24056. >>> y.size()
  24057. torch.Size([2, 2, 1, 2])
  24058. >>> y = torch.squeeze(x, (1, 2, 3))
  24059. torch.Size([2, 2, 2])
  24060. """
  24061. @overload
  24062. def squeeze(input: Tensor, dim: _size) -> Tensor:
  24063. r"""
  24064. squeeze(input: Tensor, dim: Optional[Union[int, List[int]]]) -> Tensor
  24065. Returns a tensor with all specified dimensions of :attr:`input` of size `1` removed.
  24066. For example, if `input` is of shape:
  24067. :math:`(A \times 1 \times B \times C \times 1 \times D)` then the `input.squeeze()`
  24068. will be of shape: :math:`(A \times B \times C \times D)`.
  24069. When :attr:`dim` is given, a squeeze operation is done only in the given
  24070. dimension(s). If `input` is of shape: :math:`(A \times 1 \times B)`,
  24071. ``squeeze(input, 0)`` leaves the tensor unchanged, but ``squeeze(input, 1)``
  24072. will squeeze the tensor to the shape :math:`(A \times B)`.
  24073. .. note:: The returned tensor shares the storage with the input tensor,
  24074. so changing the contents of one will change the contents of the other.
  24075. .. warning:: If the tensor has a batch dimension of size 1, then `squeeze(input)`
  24076. will also remove the batch dimension, which can lead to unexpected
  24077. errors. Consider specifying only the dims you wish to be squeezed.
  24078. Args:
  24079. input (Tensor): the input tensor.
  24080. dim (int or tuple of ints, optional): if given, the input will be squeezed
  24081. only in the specified dimensions.
  24082. .. versionchanged:: 2.0
  24083. :attr:`dim` now accepts tuples of dimensions.
  24084. Example::
  24085. >>> x = torch.zeros(2, 1, 2, 1, 2)
  24086. >>> x.size()
  24087. torch.Size([2, 1, 2, 1, 2])
  24088. >>> y = torch.squeeze(x)
  24089. >>> y.size()
  24090. torch.Size([2, 2, 2])
  24091. >>> y = torch.squeeze(x, 0)
  24092. >>> y.size()
  24093. torch.Size([2, 1, 2, 1, 2])
  24094. >>> y = torch.squeeze(x, 1)
  24095. >>> y.size()
  24096. torch.Size([2, 2, 1, 2])
  24097. >>> y = torch.squeeze(x, (1, 2, 3))
  24098. torch.Size([2, 2, 2])
  24099. """
  24100. @overload
  24101. def squeeze(input: Tensor, dim: str | EllipsisType | None) -> Tensor:
  24102. r"""
  24103. squeeze(input: Tensor, dim: Optional[Union[int, List[int]]]) -> Tensor
  24104. Returns a tensor with all specified dimensions of :attr:`input` of size `1` removed.
  24105. For example, if `input` is of shape:
  24106. :math:`(A \times 1 \times B \times C \times 1 \times D)` then the `input.squeeze()`
  24107. will be of shape: :math:`(A \times B \times C \times D)`.
  24108. When :attr:`dim` is given, a squeeze operation is done only in the given
  24109. dimension(s). If `input` is of shape: :math:`(A \times 1 \times B)`,
  24110. ``squeeze(input, 0)`` leaves the tensor unchanged, but ``squeeze(input, 1)``
  24111. will squeeze the tensor to the shape :math:`(A \times B)`.
  24112. .. note:: The returned tensor shares the storage with the input tensor,
  24113. so changing the contents of one will change the contents of the other.
  24114. .. warning:: If the tensor has a batch dimension of size 1, then `squeeze(input)`
  24115. will also remove the batch dimension, which can lead to unexpected
  24116. errors. Consider specifying only the dims you wish to be squeezed.
  24117. Args:
  24118. input (Tensor): the input tensor.
  24119. dim (int or tuple of ints, optional): if given, the input will be squeezed
  24120. only in the specified dimensions.
  24121. .. versionchanged:: 2.0
  24122. :attr:`dim` now accepts tuples of dimensions.
  24123. Example::
  24124. >>> x = torch.zeros(2, 1, 2, 1, 2)
  24125. >>> x.size()
  24126. torch.Size([2, 1, 2, 1, 2])
  24127. >>> y = torch.squeeze(x)
  24128. >>> y.size()
  24129. torch.Size([2, 2, 2])
  24130. >>> y = torch.squeeze(x, 0)
  24131. >>> y.size()
  24132. torch.Size([2, 1, 2, 1, 2])
  24133. >>> y = torch.squeeze(x, 1)
  24134. >>> y.size()
  24135. torch.Size([2, 2, 1, 2])
  24136. >>> y = torch.squeeze(x, (1, 2, 3))
  24137. torch.Size([2, 2, 2])
  24138. """
  24139. @overload
  24140. def squeeze_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  24141. r"""
  24142. Performs the same operation as :func:`torch.squeeze`, but all output tensors
  24143. are freshly created instead of aliasing the input.
  24144. """
  24145. @overload
  24146. def squeeze_copy(
  24147. input: Tensor,
  24148. dim: _int,
  24149. *,
  24150. out: Tensor | None = None,
  24151. ) -> Tensor:
  24152. r"""
  24153. Performs the same operation as :func:`torch.squeeze`, but all output tensors
  24154. are freshly created instead of aliasing the input.
  24155. """
  24156. @overload
  24157. def squeeze_copy(
  24158. input: Tensor,
  24159. dim: _size,
  24160. *,
  24161. out: Tensor | None = None,
  24162. ) -> Tensor:
  24163. r"""
  24164. Performs the same operation as :func:`torch.squeeze`, but all output tensors
  24165. are freshly created instead of aliasing the input.
  24166. """
  24167. @overload
  24168. def sspaddmm(
  24169. beta: Number | _complex,
  24170. self: Tensor,
  24171. alpha: Number | _complex,
  24172. mat1: Tensor,
  24173. mat2: Tensor,
  24174. ) -> Tensor:
  24175. r"""
  24176. sspaddmm(input, mat1, mat2, *, beta=1, alpha=1, out=None) -> Tensor
  24177. Matrix multiplies a sparse tensor :attr:`mat1` with a dense tensor
  24178. :attr:`mat2`, then adds the sparse tensor :attr:`input` to the result.
  24179. Note: This function is equivalent to :func:`torch.addmm`, except
  24180. :attr:`input` and :attr:`mat1` are sparse.
  24181. Args:
  24182. input (Tensor): a sparse matrix to be added
  24183. mat1 (Tensor): a sparse matrix to be matrix multiplied
  24184. mat2 (Tensor): a dense matrix to be matrix multiplied
  24185. Keyword args:
  24186. beta (Number, optional): multiplier for :attr:`mat` (:math:`\beta`)
  24187. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  24188. out (Tensor, optional): the output tensor.
  24189. """
  24190. @overload
  24191. def sspaddmm(
  24192. input: Tensor,
  24193. mat1: Tensor,
  24194. mat2: Tensor,
  24195. *,
  24196. beta: Number | _complex = 1,
  24197. alpha: Number | _complex = 1,
  24198. out: Tensor | None = None,
  24199. ) -> Tensor:
  24200. r"""
  24201. sspaddmm(input, mat1, mat2, *, beta=1, alpha=1, out=None) -> Tensor
  24202. Matrix multiplies a sparse tensor :attr:`mat1` with a dense tensor
  24203. :attr:`mat2`, then adds the sparse tensor :attr:`input` to the result.
  24204. Note: This function is equivalent to :func:`torch.addmm`, except
  24205. :attr:`input` and :attr:`mat1` are sparse.
  24206. Args:
  24207. input (Tensor): a sparse matrix to be added
  24208. mat1 (Tensor): a sparse matrix to be matrix multiplied
  24209. mat2 (Tensor): a dense matrix to be matrix multiplied
  24210. Keyword args:
  24211. beta (Number, optional): multiplier for :attr:`mat` (:math:`\beta`)
  24212. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  24213. out (Tensor, optional): the output tensor.
  24214. """
  24215. @overload
  24216. def sspaddmm(
  24217. beta: Number | _complex,
  24218. self: Tensor,
  24219. mat1: Tensor,
  24220. mat2: Tensor,
  24221. ) -> Tensor:
  24222. r"""
  24223. sspaddmm(input, mat1, mat2, *, beta=1, alpha=1, out=None) -> Tensor
  24224. Matrix multiplies a sparse tensor :attr:`mat1` with a dense tensor
  24225. :attr:`mat2`, then adds the sparse tensor :attr:`input` to the result.
  24226. Note: This function is equivalent to :func:`torch.addmm`, except
  24227. :attr:`input` and :attr:`mat1` are sparse.
  24228. Args:
  24229. input (Tensor): a sparse matrix to be added
  24230. mat1 (Tensor): a sparse matrix to be matrix multiplied
  24231. mat2 (Tensor): a dense matrix to be matrix multiplied
  24232. Keyword args:
  24233. beta (Number, optional): multiplier for :attr:`mat` (:math:`\beta`)
  24234. alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
  24235. out (Tensor, optional): the output tensor.
  24236. """
  24237. def stack(
  24238. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  24239. dim: _int = 0,
  24240. *,
  24241. out: Tensor | None = None,
  24242. ) -> Tensor:
  24243. r"""
  24244. stack(tensors, dim=0, *, out=None) -> Tensor
  24245. Concatenates a sequence of tensors along a new dimension.
  24246. All tensors need to be of the same size.
  24247. .. seealso::
  24248. :func:`torch.cat` concatenates the given sequence along an existing dimension.
  24249. Arguments:
  24250. tensors (sequence of Tensors): sequence of tensors to concatenate
  24251. dim (int, optional): dimension to insert. Has to be between 0 and the number
  24252. of dimensions of concatenated tensors (inclusive). Default: 0
  24253. Keyword args:
  24254. out (Tensor, optional): the output tensor.
  24255. Example::
  24256. >>> x = torch.randn(2, 3)
  24257. >>> x
  24258. tensor([[ 0.3367, 0.1288, 0.2345],
  24259. [ 0.2303, -1.1229, -0.1863]])
  24260. >>> torch.stack((x, x)) # same as torch.stack((x, x), dim=0)
  24261. tensor([[[ 0.3367, 0.1288, 0.2345],
  24262. [ 0.2303, -1.1229, -0.1863]],
  24263. [[ 0.3367, 0.1288, 0.2345],
  24264. [ 0.2303, -1.1229, -0.1863]]])
  24265. >>> torch.stack((x, x)).size()
  24266. torch.Size([2, 2, 3])
  24267. >>> torch.stack((x, x), dim=1)
  24268. tensor([[[ 0.3367, 0.1288, 0.2345],
  24269. [ 0.3367, 0.1288, 0.2345]],
  24270. [[ 0.2303, -1.1229, -0.1863],
  24271. [ 0.2303, -1.1229, -0.1863]]])
  24272. >>> torch.stack((x, x), dim=2)
  24273. tensor([[[ 0.3367, 0.3367],
  24274. [ 0.1288, 0.1288],
  24275. [ 0.2345, 0.2345]],
  24276. [[ 0.2303, 0.2303],
  24277. [-1.1229, -1.1229],
  24278. [-0.1863, -0.1863]]])
  24279. >>> torch.stack((x, x), dim=-1)
  24280. tensor([[[ 0.3367, 0.3367],
  24281. [ 0.1288, 0.1288],
  24282. [ 0.2345, 0.2345]],
  24283. [[ 0.2303, 0.2303],
  24284. [-1.1229, -1.1229],
  24285. [-0.1863, -0.1863]]])
  24286. """
  24287. @overload
  24288. def std(
  24289. input: Tensor,
  24290. dim: _int | _size | None,
  24291. unbiased: _bool = True,
  24292. keepdim: _bool = False,
  24293. *,
  24294. out: Tensor | None = None,
  24295. ) -> Tensor:
  24296. r"""
  24297. std(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  24298. Calculates the standard deviation over the dimensions specified by :attr:`dim`.
  24299. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  24300. reduce over all dimensions.
  24301. The standard deviation (:math:`\sigma`) is calculated as
  24302. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24303. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24304. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24305. the :attr:`correction`.
  24306. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24307. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24308. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24309. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24310. Args:
  24311. input (Tensor): the input tensor.
  24312. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24313. If ``None``, all dimensions are reduced.
  24314. Keyword args:
  24315. correction (int): difference between the sample size and sample degrees of freedom.
  24316. Defaults to `Bessel's correction`_, ``correction=1``.
  24317. .. versionchanged:: 2.0
  24318. Previously this argument was called ``unbiased`` and was a boolean
  24319. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24320. ``correction=0``.
  24321. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24322. out (Tensor, optional): the output tensor.
  24323. Example:
  24324. >>> a = torch.tensor(
  24325. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24326. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24327. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24328. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24329. ... ) # fmt: skip
  24330. >>> torch.std(a, dim=1, keepdim=True)
  24331. tensor([[1.0311],
  24332. [0.7477],
  24333. [1.2204],
  24334. [0.9087]])
  24335. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24336. """
  24337. @overload
  24338. def std(
  24339. input: Tensor,
  24340. dim: _int | _size | None = None,
  24341. *,
  24342. correction: Number | _complex | None = None,
  24343. keepdim: _bool = False,
  24344. out: Tensor | None = None,
  24345. ) -> Tensor:
  24346. r"""
  24347. std(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  24348. Calculates the standard deviation over the dimensions specified by :attr:`dim`.
  24349. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  24350. reduce over all dimensions.
  24351. The standard deviation (:math:`\sigma`) is calculated as
  24352. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24353. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24354. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24355. the :attr:`correction`.
  24356. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24357. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24358. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24359. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24360. Args:
  24361. input (Tensor): the input tensor.
  24362. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24363. If ``None``, all dimensions are reduced.
  24364. Keyword args:
  24365. correction (int): difference between the sample size and sample degrees of freedom.
  24366. Defaults to `Bessel's correction`_, ``correction=1``.
  24367. .. versionchanged:: 2.0
  24368. Previously this argument was called ``unbiased`` and was a boolean
  24369. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24370. ``correction=0``.
  24371. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24372. out (Tensor, optional): the output tensor.
  24373. Example:
  24374. >>> a = torch.tensor(
  24375. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24376. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24377. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24378. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24379. ... ) # fmt: skip
  24380. >>> torch.std(a, dim=1, keepdim=True)
  24381. tensor([[1.0311],
  24382. [0.7477],
  24383. [1.2204],
  24384. [0.9087]])
  24385. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24386. """
  24387. @overload
  24388. def std(input: Tensor, unbiased: _bool = True) -> Tensor:
  24389. r"""
  24390. std(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  24391. Calculates the standard deviation over the dimensions specified by :attr:`dim`.
  24392. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  24393. reduce over all dimensions.
  24394. The standard deviation (:math:`\sigma`) is calculated as
  24395. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24396. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24397. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24398. the :attr:`correction`.
  24399. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24400. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24401. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24402. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24403. Args:
  24404. input (Tensor): the input tensor.
  24405. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24406. If ``None``, all dimensions are reduced.
  24407. Keyword args:
  24408. correction (int): difference between the sample size and sample degrees of freedom.
  24409. Defaults to `Bessel's correction`_, ``correction=1``.
  24410. .. versionchanged:: 2.0
  24411. Previously this argument was called ``unbiased`` and was a boolean
  24412. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24413. ``correction=0``.
  24414. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24415. out (Tensor, optional): the output tensor.
  24416. Example:
  24417. >>> a = torch.tensor(
  24418. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24419. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24420. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24421. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24422. ... ) # fmt: skip
  24423. >>> torch.std(a, dim=1, keepdim=True)
  24424. tensor([[1.0311],
  24425. [0.7477],
  24426. [1.2204],
  24427. [0.9087]])
  24428. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24429. """
  24430. @overload
  24431. def std(
  24432. input: Tensor,
  24433. dim: Sequence[str | EllipsisType | None],
  24434. *,
  24435. correction: Number | _complex | None = None,
  24436. keepdim: _bool = False,
  24437. out: Tensor | None = None,
  24438. ) -> Tensor:
  24439. r"""
  24440. std(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  24441. Calculates the standard deviation over the dimensions specified by :attr:`dim`.
  24442. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  24443. reduce over all dimensions.
  24444. The standard deviation (:math:`\sigma`) is calculated as
  24445. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24446. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24447. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24448. the :attr:`correction`.
  24449. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24450. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24451. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24452. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24453. Args:
  24454. input (Tensor): the input tensor.
  24455. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24456. If ``None``, all dimensions are reduced.
  24457. Keyword args:
  24458. correction (int): difference between the sample size and sample degrees of freedom.
  24459. Defaults to `Bessel's correction`_, ``correction=1``.
  24460. .. versionchanged:: 2.0
  24461. Previously this argument was called ``unbiased`` and was a boolean
  24462. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24463. ``correction=0``.
  24464. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24465. out (Tensor, optional): the output tensor.
  24466. Example:
  24467. >>> a = torch.tensor(
  24468. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24469. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24470. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24471. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24472. ... ) # fmt: skip
  24473. >>> torch.std(a, dim=1, keepdim=True)
  24474. tensor([[1.0311],
  24475. [0.7477],
  24476. [1.2204],
  24477. [0.9087]])
  24478. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24479. """
  24480. @overload
  24481. def std(
  24482. input: Tensor,
  24483. dim: Sequence[str | EllipsisType | None],
  24484. unbiased: _bool = True,
  24485. keepdim: _bool = False,
  24486. *,
  24487. out: Tensor | None = None,
  24488. ) -> Tensor:
  24489. r"""
  24490. std(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  24491. Calculates the standard deviation over the dimensions specified by :attr:`dim`.
  24492. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  24493. reduce over all dimensions.
  24494. The standard deviation (:math:`\sigma`) is calculated as
  24495. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24496. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24497. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24498. the :attr:`correction`.
  24499. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24500. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24501. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24502. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24503. Args:
  24504. input (Tensor): the input tensor.
  24505. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24506. If ``None``, all dimensions are reduced.
  24507. Keyword args:
  24508. correction (int): difference between the sample size and sample degrees of freedom.
  24509. Defaults to `Bessel's correction`_, ``correction=1``.
  24510. .. versionchanged:: 2.0
  24511. Previously this argument was called ``unbiased`` and was a boolean
  24512. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24513. ``correction=0``.
  24514. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24515. out (Tensor, optional): the output tensor.
  24516. Example:
  24517. >>> a = torch.tensor(
  24518. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24519. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24520. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24521. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24522. ... ) # fmt: skip
  24523. >>> torch.std(a, dim=1, keepdim=True)
  24524. tensor([[1.0311],
  24525. [0.7477],
  24526. [1.2204],
  24527. [0.9087]])
  24528. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24529. """
  24530. @overload
  24531. def std_mean(
  24532. input: Tensor,
  24533. dim: _int | _size | None,
  24534. unbiased: _bool = True,
  24535. keepdim: _bool = False,
  24536. ) -> tuple[Tensor, Tensor]:
  24537. r"""
  24538. std_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  24539. Calculates the standard deviation and mean over the dimensions specified by
  24540. :attr:`dim`. :attr:`dim` can be a single dimension, list of dimensions, or
  24541. ``None`` to reduce over all dimensions.
  24542. The standard deviation (:math:`\sigma`) is calculated as
  24543. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24544. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24545. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24546. the :attr:`correction`.
  24547. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24548. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24549. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24550. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24551. Args:
  24552. input (Tensor): the input tensor.
  24553. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24554. If ``None``, all dimensions are reduced.
  24555. Keyword args:
  24556. correction (int): difference between the sample size and sample degrees of freedom.
  24557. Defaults to `Bessel's correction`_, ``correction=1``.
  24558. .. versionchanged:: 2.0
  24559. Previously this argument was called ``unbiased`` and was a boolean
  24560. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24561. ``correction=0``.
  24562. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24563. out (Tensor, optional): the output tensor.
  24564. Returns:
  24565. A tuple (std, mean) containing the standard deviation and mean.
  24566. Example:
  24567. >>> a = torch.tensor(
  24568. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24569. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24570. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24571. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24572. ... ) # fmt: skip
  24573. >>> torch.std_mean(a, dim=0, keepdim=True)
  24574. (tensor([[1.2620, 1.0028, 1.0957, 0.6038]]),
  24575. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  24576. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24577. """
  24578. @overload
  24579. def std_mean(
  24580. input: Tensor,
  24581. dim: _int | _size | None = None,
  24582. *,
  24583. correction: Number | _complex | None = None,
  24584. keepdim: _bool = False,
  24585. ) -> tuple[Tensor, Tensor]:
  24586. r"""
  24587. std_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  24588. Calculates the standard deviation and mean over the dimensions specified by
  24589. :attr:`dim`. :attr:`dim` can be a single dimension, list of dimensions, or
  24590. ``None`` to reduce over all dimensions.
  24591. The standard deviation (:math:`\sigma`) is calculated as
  24592. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24593. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24594. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24595. the :attr:`correction`.
  24596. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24597. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24598. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24599. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24600. Args:
  24601. input (Tensor): the input tensor.
  24602. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24603. If ``None``, all dimensions are reduced.
  24604. Keyword args:
  24605. correction (int): difference between the sample size and sample degrees of freedom.
  24606. Defaults to `Bessel's correction`_, ``correction=1``.
  24607. .. versionchanged:: 2.0
  24608. Previously this argument was called ``unbiased`` and was a boolean
  24609. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24610. ``correction=0``.
  24611. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24612. out (Tensor, optional): the output tensor.
  24613. Returns:
  24614. A tuple (std, mean) containing the standard deviation and mean.
  24615. Example:
  24616. >>> a = torch.tensor(
  24617. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24618. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24619. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24620. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24621. ... ) # fmt: skip
  24622. >>> torch.std_mean(a, dim=0, keepdim=True)
  24623. (tensor([[1.2620, 1.0028, 1.0957, 0.6038]]),
  24624. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  24625. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24626. """
  24627. @overload
  24628. def std_mean(
  24629. input: Tensor,
  24630. unbiased: _bool = True,
  24631. ) -> tuple[Tensor, Tensor]:
  24632. r"""
  24633. std_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  24634. Calculates the standard deviation and mean over the dimensions specified by
  24635. :attr:`dim`. :attr:`dim` can be a single dimension, list of dimensions, or
  24636. ``None`` to reduce over all dimensions.
  24637. The standard deviation (:math:`\sigma`) is calculated as
  24638. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24639. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24640. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24641. the :attr:`correction`.
  24642. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24643. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24644. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24645. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24646. Args:
  24647. input (Tensor): the input tensor.
  24648. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24649. If ``None``, all dimensions are reduced.
  24650. Keyword args:
  24651. correction (int): difference between the sample size and sample degrees of freedom.
  24652. Defaults to `Bessel's correction`_, ``correction=1``.
  24653. .. versionchanged:: 2.0
  24654. Previously this argument was called ``unbiased`` and was a boolean
  24655. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24656. ``correction=0``.
  24657. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24658. out (Tensor, optional): the output tensor.
  24659. Returns:
  24660. A tuple (std, mean) containing the standard deviation and mean.
  24661. Example:
  24662. >>> a = torch.tensor(
  24663. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24664. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24665. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24666. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24667. ... ) # fmt: skip
  24668. >>> torch.std_mean(a, dim=0, keepdim=True)
  24669. (tensor([[1.2620, 1.0028, 1.0957, 0.6038]]),
  24670. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  24671. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24672. """
  24673. @overload
  24674. def std_mean(
  24675. input: Tensor,
  24676. dim: Sequence[str | EllipsisType | None],
  24677. *,
  24678. correction: Number | _complex | None = None,
  24679. keepdim: _bool = False,
  24680. ) -> tuple[Tensor, Tensor]:
  24681. r"""
  24682. std_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  24683. Calculates the standard deviation and mean over the dimensions specified by
  24684. :attr:`dim`. :attr:`dim` can be a single dimension, list of dimensions, or
  24685. ``None`` to reduce over all dimensions.
  24686. The standard deviation (:math:`\sigma`) is calculated as
  24687. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24688. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24689. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24690. the :attr:`correction`.
  24691. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24692. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24693. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24694. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24695. Args:
  24696. input (Tensor): the input tensor.
  24697. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24698. If ``None``, all dimensions are reduced.
  24699. Keyword args:
  24700. correction (int): difference between the sample size and sample degrees of freedom.
  24701. Defaults to `Bessel's correction`_, ``correction=1``.
  24702. .. versionchanged:: 2.0
  24703. Previously this argument was called ``unbiased`` and was a boolean
  24704. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24705. ``correction=0``.
  24706. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24707. out (Tensor, optional): the output tensor.
  24708. Returns:
  24709. A tuple (std, mean) containing the standard deviation and mean.
  24710. Example:
  24711. >>> a = torch.tensor(
  24712. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24713. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24714. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24715. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24716. ... ) # fmt: skip
  24717. >>> torch.std_mean(a, dim=0, keepdim=True)
  24718. (tensor([[1.2620, 1.0028, 1.0957, 0.6038]]),
  24719. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  24720. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24721. """
  24722. @overload
  24723. def std_mean(
  24724. input: Tensor,
  24725. dim: Sequence[str | EllipsisType | None],
  24726. unbiased: _bool = True,
  24727. keepdim: _bool = False,
  24728. ) -> tuple[Tensor, Tensor]:
  24729. r"""
  24730. std_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  24731. Calculates the standard deviation and mean over the dimensions specified by
  24732. :attr:`dim`. :attr:`dim` can be a single dimension, list of dimensions, or
  24733. ``None`` to reduce over all dimensions.
  24734. The standard deviation (:math:`\sigma`) is calculated as
  24735. .. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
  24736. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  24737. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  24738. the :attr:`correction`.
  24739. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24740. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24741. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24742. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24743. Args:
  24744. input (Tensor): the input tensor.
  24745. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24746. If ``None``, all dimensions are reduced.
  24747. Keyword args:
  24748. correction (int): difference between the sample size and sample degrees of freedom.
  24749. Defaults to `Bessel's correction`_, ``correction=1``.
  24750. .. versionchanged:: 2.0
  24751. Previously this argument was called ``unbiased`` and was a boolean
  24752. with ``True`` corresponding to ``correction=1`` and ``False`` being
  24753. ``correction=0``.
  24754. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24755. out (Tensor, optional): the output tensor.
  24756. Returns:
  24757. A tuple (std, mean) containing the standard deviation and mean.
  24758. Example:
  24759. >>> a = torch.tensor(
  24760. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  24761. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  24762. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  24763. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  24764. ... ) # fmt: skip
  24765. >>> torch.std_mean(a, dim=0, keepdim=True)
  24766. (tensor([[1.2620, 1.0028, 1.0957, 0.6038]]),
  24767. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  24768. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  24769. """
  24770. @overload
  24771. def sub(
  24772. input: Tensor | Number | _complex,
  24773. other: Tensor | Number | _complex,
  24774. *,
  24775. alpha: Number | _complex | None = 1,
  24776. out: Tensor | None = None,
  24777. ) -> Tensor:
  24778. r"""
  24779. sub(input, other, *, alpha=1, out=None) -> Tensor
  24780. Subtracts :attr:`other`, scaled by :attr:`alpha`, from :attr:`input`.
  24781. .. math::
  24782. \text{{out}}_i = \text{{input}}_i - \text{{alpha}} \times \text{{other}}_i
  24783. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  24784. :ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
  24785. Args:
  24786. input (Tensor): the input tensor.
  24787. other (Tensor or Number): the tensor or number to subtract from :attr:`input`.
  24788. Keyword args:
  24789. alpha (Number): the multiplier for :attr:`other`.
  24790. out (Tensor, optional): the output tensor.
  24791. Example::
  24792. >>> a = torch.tensor((1, 2))
  24793. >>> b = torch.tensor((0, 1))
  24794. >>> torch.sub(a, b, alpha=2)
  24795. tensor([1, 0])
  24796. """
  24797. @overload
  24798. def sub(self: Tensor, alpha: Number | _complex, other: Tensor) -> Tensor:
  24799. r"""
  24800. sub(input, other, *, alpha=1, out=None) -> Tensor
  24801. Subtracts :attr:`other`, scaled by :attr:`alpha`, from :attr:`input`.
  24802. .. math::
  24803. \text{{out}}_i = \text{{input}}_i - \text{{alpha}} \times \text{{other}}_i
  24804. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  24805. :ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
  24806. Args:
  24807. input (Tensor): the input tensor.
  24808. other (Tensor or Number): the tensor or number to subtract from :attr:`input`.
  24809. Keyword args:
  24810. alpha (Number): the multiplier for :attr:`other`.
  24811. out (Tensor, optional): the output tensor.
  24812. Example::
  24813. >>> a = torch.tensor((1, 2))
  24814. >>> b = torch.tensor((0, 1))
  24815. >>> torch.sub(a, b, alpha=2)
  24816. tensor([1, 0])
  24817. """
  24818. @overload
  24819. def sub(
  24820. self: Tensor,
  24821. alpha: Number | _complex,
  24822. other: Tensor,
  24823. *,
  24824. out: Tensor,
  24825. ) -> Tensor:
  24826. r"""
  24827. sub(input, other, *, alpha=1, out=None) -> Tensor
  24828. Subtracts :attr:`other`, scaled by :attr:`alpha`, from :attr:`input`.
  24829. .. math::
  24830. \text{{out}}_i = \text{{input}}_i - \text{{alpha}} \times \text{{other}}_i
  24831. Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
  24832. :ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
  24833. Args:
  24834. input (Tensor): the input tensor.
  24835. other (Tensor or Number): the tensor or number to subtract from :attr:`input`.
  24836. Keyword args:
  24837. alpha (Number): the multiplier for :attr:`other`.
  24838. out (Tensor, optional): the output tensor.
  24839. Example::
  24840. >>> a = torch.tensor((1, 2))
  24841. >>> b = torch.tensor((0, 1))
  24842. >>> torch.sub(a, b, alpha=2)
  24843. tensor([1, 0])
  24844. """
  24845. @overload
  24846. def subtract(
  24847. input: Tensor,
  24848. other: Tensor,
  24849. *,
  24850. alpha: Number | _complex = 1,
  24851. out: Tensor | None = None,
  24852. ) -> Tensor:
  24853. r"""
  24854. subtract(input, other, *, alpha=1, out=None) -> Tensor
  24855. Alias for :func:`torch.sub`.
  24856. """
  24857. @overload
  24858. def subtract(
  24859. input: Tensor,
  24860. other: Number | _complex,
  24861. alpha: Number | _complex = 1,
  24862. ) -> Tensor:
  24863. r"""
  24864. subtract(input, other, *, alpha=1, out=None) -> Tensor
  24865. Alias for :func:`torch.sub`.
  24866. """
  24867. @overload
  24868. def sum(input: Tensor, *, dtype: _dtype | None = None) -> Tensor:
  24869. r"""
  24870. sum(input, *, dtype=None) -> Tensor
  24871. Returns the sum of all elements in the :attr:`input` tensor.
  24872. Args:
  24873. input (Tensor): the input tensor.
  24874. Keyword args:
  24875. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  24876. If specified, the input tensor is casted to :attr:`dtype` before the operation
  24877. is performed. This is useful for preventing data type overflows. Default: None.
  24878. .. note:: Use the `dtype` argument if you need the result in a specific tensor type.
  24879. Otherwise, the result type may be automatically promoted (e.g., from `torch.int32` to `torch.int64`).
  24880. Example::
  24881. >>> a = torch.randn(1, 3)
  24882. >>> a
  24883. tensor([[ 0.1133, -0.9567, 0.2958]])
  24884. >>> torch.sum(a)
  24885. tensor(-0.5475)
  24886. .. function:: sum(input, dim, keepdim=False, *, dtype=None) -> Tensor
  24887. :noindex:
  24888. Returns the sum of each row of the :attr:`input` tensor in the given
  24889. dimension :attr:`dim`. If :attr:`dim` is a list of dimensions,
  24890. reduce over all of them.
  24891. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24892. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24893. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24894. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24895. Args:
  24896. input (Tensor): the input tensor.
  24897. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24898. If ``None``, all dimensions are reduced.
  24899. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24900. Keyword args:
  24901. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  24902. If specified, the input tensor is casted to :attr:`dtype` before the operation
  24903. is performed. This is useful for preventing data type overflows. Default: None.
  24904. Example::
  24905. >>> a = torch.randn(4, 4)
  24906. >>> a
  24907. tensor([[ 0.0569, -0.2475, 0.0737, -0.3429],
  24908. [-0.2993, 0.9138, 0.9337, -1.6864],
  24909. [ 0.1132, 0.7892, -0.1003, 0.5688],
  24910. [ 0.3637, -0.9906, -0.4752, -1.5197]])
  24911. >>> torch.sum(a, 1)
  24912. tensor([-0.4598, -0.1381, 1.3708, -2.6217])
  24913. >>> b = torch.arange(4 * 5 * 6).view(4, 5, 6)
  24914. >>> torch.sum(b, (2, 1))
  24915. tensor([ 435., 1335., 2235., 3135.])
  24916. """
  24917. @overload
  24918. def sum(
  24919. input: Tensor,
  24920. dim: _int | _size | None,
  24921. keepdim: _bool = False,
  24922. *,
  24923. dtype: _dtype | None = None,
  24924. out: Tensor | None = None,
  24925. ) -> Tensor:
  24926. r"""
  24927. sum(input, *, dtype=None) -> Tensor
  24928. Returns the sum of all elements in the :attr:`input` tensor.
  24929. Args:
  24930. input (Tensor): the input tensor.
  24931. Keyword args:
  24932. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  24933. If specified, the input tensor is casted to :attr:`dtype` before the operation
  24934. is performed. This is useful for preventing data type overflows. Default: None.
  24935. .. note:: Use the `dtype` argument if you need the result in a specific tensor type.
  24936. Otherwise, the result type may be automatically promoted (e.g., from `torch.int32` to `torch.int64`).
  24937. Example::
  24938. >>> a = torch.randn(1, 3)
  24939. >>> a
  24940. tensor([[ 0.1133, -0.9567, 0.2958]])
  24941. >>> torch.sum(a)
  24942. tensor(-0.5475)
  24943. .. function:: sum(input, dim, keepdim=False, *, dtype=None) -> Tensor
  24944. :noindex:
  24945. Returns the sum of each row of the :attr:`input` tensor in the given
  24946. dimension :attr:`dim`. If :attr:`dim` is a list of dimensions,
  24947. reduce over all of them.
  24948. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  24949. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  24950. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  24951. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  24952. Args:
  24953. input (Tensor): the input tensor.
  24954. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  24955. If ``None``, all dimensions are reduced.
  24956. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  24957. Keyword args:
  24958. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  24959. If specified, the input tensor is casted to :attr:`dtype` before the operation
  24960. is performed. This is useful for preventing data type overflows. Default: None.
  24961. Example::
  24962. >>> a = torch.randn(4, 4)
  24963. >>> a
  24964. tensor([[ 0.0569, -0.2475, 0.0737, -0.3429],
  24965. [-0.2993, 0.9138, 0.9337, -1.6864],
  24966. [ 0.1132, 0.7892, -0.1003, 0.5688],
  24967. [ 0.3637, -0.9906, -0.4752, -1.5197]])
  24968. >>> torch.sum(a, 1)
  24969. tensor([-0.4598, -0.1381, 1.3708, -2.6217])
  24970. >>> b = torch.arange(4 * 5 * 6).view(4, 5, 6)
  24971. >>> torch.sum(b, (2, 1))
  24972. tensor([ 435., 1335., 2235., 3135.])
  24973. """
  24974. @overload
  24975. def sum(
  24976. input: Tensor,
  24977. dim: Sequence[str | EllipsisType | None],
  24978. keepdim: _bool = False,
  24979. *,
  24980. dtype: _dtype | None = None,
  24981. out: Tensor | None = None,
  24982. ) -> Tensor:
  24983. r"""
  24984. sum(input, *, dtype=None) -> Tensor
  24985. Returns the sum of all elements in the :attr:`input` tensor.
  24986. Args:
  24987. input (Tensor): the input tensor.
  24988. Keyword args:
  24989. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  24990. If specified, the input tensor is casted to :attr:`dtype` before the operation
  24991. is performed. This is useful for preventing data type overflows. Default: None.
  24992. .. note:: Use the `dtype` argument if you need the result in a specific tensor type.
  24993. Otherwise, the result type may be automatically promoted (e.g., from `torch.int32` to `torch.int64`).
  24994. Example::
  24995. >>> a = torch.randn(1, 3)
  24996. >>> a
  24997. tensor([[ 0.1133, -0.9567, 0.2958]])
  24998. >>> torch.sum(a)
  24999. tensor(-0.5475)
  25000. .. function:: sum(input, dim, keepdim=False, *, dtype=None) -> Tensor
  25001. :noindex:
  25002. Returns the sum of each row of the :attr:`input` tensor in the given
  25003. dimension :attr:`dim`. If :attr:`dim` is a list of dimensions,
  25004. reduce over all of them.
  25005. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  25006. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  25007. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  25008. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  25009. Args:
  25010. input (Tensor): the input tensor.
  25011. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  25012. If ``None``, all dimensions are reduced.
  25013. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  25014. Keyword args:
  25015. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  25016. If specified, the input tensor is casted to :attr:`dtype` before the operation
  25017. is performed. This is useful for preventing data type overflows. Default: None.
  25018. Example::
  25019. >>> a = torch.randn(4, 4)
  25020. >>> a
  25021. tensor([[ 0.0569, -0.2475, 0.0737, -0.3429],
  25022. [-0.2993, 0.9138, 0.9337, -1.6864],
  25023. [ 0.1132, 0.7892, -0.1003, 0.5688],
  25024. [ 0.3637, -0.9906, -0.4752, -1.5197]])
  25025. >>> torch.sum(a, 1)
  25026. tensor([-0.4598, -0.1381, 1.3708, -2.6217])
  25027. >>> b = torch.arange(4 * 5 * 6).view(4, 5, 6)
  25028. >>> torch.sum(b, (2, 1))
  25029. tensor([ 435., 1335., 2235., 3135.])
  25030. """
  25031. def svd(
  25032. input: Tensor,
  25033. some: _bool = True,
  25034. compute_uv: _bool = True,
  25035. *,
  25036. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  25037. ) -> torch.return_types.svd:
  25038. r"""
  25039. svd(input, some=True, compute_uv=True, *, out=None) -> (Tensor, Tensor, Tensor)
  25040. Computes the singular value decomposition of either a matrix or batch of
  25041. matrices :attr:`input`. The singular value decomposition is represented as a
  25042. namedtuple `(U, S, V)`, such that :attr:`input` :math:`= U \text{diag}(S) V^{\text{H}}`.
  25043. where :math:`V^{\text{H}}` is the transpose of `V` for real inputs,
  25044. and the conjugate transpose of `V` for complex inputs.
  25045. If :attr:`input` is a batch of matrices, then `U`, `S`, and `V` are also
  25046. batched with the same batch dimensions as :attr:`input`.
  25047. If :attr:`some` is `True` (default), the method returns the reduced singular
  25048. value decomposition. In this case, if the last two dimensions of :attr:`input` are
  25049. `m` and `n`, then the returned `U` and `V` matrices will contain only
  25050. `min(n, m)` orthonormal columns.
  25051. If :attr:`compute_uv` is `False`, the returned `U` and `V` will be
  25052. zero-filled matrices of shape `(m, m)` and `(n, n)`
  25053. respectively, and the same device as :attr:`input`. The argument :attr:`some`
  25054. has no effect when :attr:`compute_uv` is `False`.
  25055. Supports :attr:`input` of float, double, cfloat and cdouble data types.
  25056. The dtypes of `U` and `V` are the same as :attr:`input`'s. `S` will
  25057. always be real-valued, even if :attr:`input` is complex.
  25058. .. warning::
  25059. :func:`torch.svd` is deprecated in favor of :func:`torch.linalg.svd`
  25060. and will be removed in a future PyTorch release.
  25061. ``U, S, V = torch.svd(A, some=some, compute_uv=True)`` (default) should be replaced with
  25062. .. code:: python
  25063. U, S, Vh = torch.linalg.svd(A, full_matrices=not some)
  25064. V = Vh.mH
  25065. ``_, S, _ = torch.svd(A, some=some, compute_uv=False)`` should be replaced with
  25066. .. code:: python
  25067. S = torch.linalg.svdvals(A)
  25068. .. note:: Differences with :func:`torch.linalg.svd`:
  25069. * :attr:`some` is the opposite of
  25070. :func:`torch.linalg.svd`'s :attr:`full_matrices`. Note that
  25071. default value for both is `True`, so the default behavior is
  25072. effectively the opposite.
  25073. * :func:`torch.svd` returns `V`, whereas :func:`torch.linalg.svd` returns
  25074. `Vh`, that is, :math:`V^{\text{H}}`.
  25075. * If :attr:`compute_uv` is `False`, :func:`torch.svd` returns zero-filled
  25076. tensors for `U` and `Vh`, whereas :func:`torch.linalg.svd` returns
  25077. empty tensors.
  25078. .. note:: The singular values are returned in descending order. If :attr:`input` is a batch of matrices,
  25079. then the singular values of each matrix in the batch are returned in descending order.
  25080. .. note:: The `S` tensor can only be used to compute gradients if :attr:`compute_uv` is `True`.
  25081. .. note:: When :attr:`some` is `False`, the gradients on `U[..., :, min(m, n):]`
  25082. and `V[..., :, min(m, n):]` will be ignored in the backward pass, as those vectors
  25083. can be arbitrary bases of the corresponding subspaces.
  25084. .. note:: The implementation of :func:`torch.linalg.svd` on CPU uses LAPACK's routine `?gesdd`
  25085. (a divide-and-conquer algorithm) instead of `?gesvd` for speed. Analogously,
  25086. on GPU, it uses cuSOLVER's routines `gesvdj` and `gesvdjBatched` on CUDA 10.1.243
  25087. and later, and MAGMA's routine `gesdd` on earlier versions of CUDA.
  25088. .. note:: The returned `U` will not be contiguous. The matrix (or batch of matrices) will
  25089. be represented as a column-major matrix (i.e. Fortran-contiguous).
  25090. .. warning:: The gradients with respect to `U` and `V` will only be finite when the input does not
  25091. have zero nor repeated singular values.
  25092. .. warning:: If the distance between any two singular values is close to zero, the gradients with respect to
  25093. `U` and `V` will be numerically unstable, as they depends on
  25094. :math:`\frac{1}{\min_{i \neq j} \sigma_i^2 - \sigma_j^2}`. The same happens when the matrix
  25095. has small singular values, as these gradients also depend on `S^{-1}`.
  25096. .. warning:: For complex-valued :attr:`input` the singular value decomposition is not unique,
  25097. as `U` and `V` may be multiplied by an arbitrary phase factor :math:`e^{i \phi}` on every column.
  25098. The same happens when :attr:`input` has repeated singular values, where one may multiply
  25099. the columns of the spanning subspace in `U` and `V` by a rotation matrix
  25100. and `the resulting vectors will span the same subspace`_.
  25101. Different platforms, like NumPy, or inputs on different device types,
  25102. may produce different `U` and `V` tensors.
  25103. Args:
  25104. input (Tensor): the input tensor of size `(*, m, n)` where `*` is zero or more
  25105. batch dimensions consisting of `(m, n)` matrices.
  25106. some (bool, optional): controls whether to compute the reduced or full decomposition, and
  25107. consequently, the shape of returned `U` and `V`. Default: `True`.
  25108. compute_uv (bool, optional): controls whether to compute `U` and `V`. Default: `True`.
  25109. Keyword args:
  25110. out (tuple, optional): the output tuple of tensors
  25111. Example::
  25112. >>> a = torch.randn(5, 3)
  25113. >>> a
  25114. tensor([[ 0.2364, -0.7752, 0.6372],
  25115. [ 1.7201, 0.7394, -0.0504],
  25116. [-0.3371, -1.0584, 0.5296],
  25117. [ 0.3550, -0.4022, 1.5569],
  25118. [ 0.2445, -0.0158, 1.1414]])
  25119. >>> u, s, v = torch.svd(a)
  25120. >>> u
  25121. tensor([[ 0.4027, 0.0287, 0.5434],
  25122. [-0.1946, 0.8833, 0.3679],
  25123. [ 0.4296, -0.2890, 0.5261],
  25124. [ 0.6604, 0.2717, -0.2618],
  25125. [ 0.4234, 0.2481, -0.4733]])
  25126. >>> s
  25127. tensor([2.3289, 2.0315, 0.7806])
  25128. >>> v
  25129. tensor([[-0.0199, 0.8766, 0.4809],
  25130. [-0.5080, 0.4054, -0.7600],
  25131. [ 0.8611, 0.2594, -0.4373]])
  25132. >>> torch.dist(a, torch.mm(torch.mm(u, torch.diag(s)), v.t()))
  25133. tensor(8.6531e-07)
  25134. >>> a_big = torch.randn(7, 5, 3)
  25135. >>> u, s, v = torch.svd(a_big)
  25136. >>> torch.dist(a_big, torch.matmul(torch.matmul(u, torch.diag_embed(s)), v.mT))
  25137. tensor(2.6503e-06)
  25138. .. _the resulting vectors will span the same subspace:
  25139. (https://en.wikipedia.org/wiki/Singular_value_decomposition#Singular_values,_singular_vectors,_and_their_relation_to_the_SVD)
  25140. """
  25141. def swapaxes(input: Tensor, axis0: _int, axis1: _int) -> Tensor:
  25142. r"""
  25143. swapaxes(input, axis0, axis1) -> Tensor
  25144. Alias for :func:`torch.transpose`.
  25145. This function is equivalent to NumPy's swapaxes function.
  25146. Examples::
  25147. >>> x = torch.tensor([[[0,1],[2,3]],[[4,5],[6,7]]])
  25148. >>> x
  25149. tensor([[[0, 1],
  25150. [2, 3]],
  25151. [[4, 5],
  25152. [6, 7]]])
  25153. >>> torch.swapaxes(x, 0, 1)
  25154. tensor([[[0, 1],
  25155. [4, 5]],
  25156. [[2, 3],
  25157. [6, 7]]])
  25158. >>> torch.swapaxes(x, 0, 2)
  25159. tensor([[[0, 4],
  25160. [2, 6]],
  25161. [[1, 5],
  25162. [3, 7]]])
  25163. """
  25164. def swapdims(input: Tensor, dim0: _int, dim1: _int) -> Tensor:
  25165. r"""
  25166. swapdims(input, dim0, dim1) -> Tensor
  25167. Alias for :func:`torch.transpose`.
  25168. This function is equivalent to NumPy's swapaxes function.
  25169. Examples::
  25170. >>> x = torch.tensor([[[0,1],[2,3]],[[4,5],[6,7]]])
  25171. >>> x
  25172. tensor([[[0, 1],
  25173. [2, 3]],
  25174. [[4, 5],
  25175. [6, 7]]])
  25176. >>> torch.swapdims(x, 0, 1)
  25177. tensor([[[0, 1],
  25178. [4, 5]],
  25179. [[2, 3],
  25180. [6, 7]]])
  25181. >>> torch.swapdims(x, 0, 2)
  25182. tensor([[[0, 4],
  25183. [2, 6]],
  25184. [[1, 5],
  25185. [3, 7]]])
  25186. """
  25187. def sym_constrain_range(
  25188. size: Number | _complex,
  25189. *,
  25190. min: _int | None = None,
  25191. max: _int | None = None,
  25192. ) -> None: ...
  25193. def sym_constrain_range_for_size(
  25194. size: Number | _complex,
  25195. *,
  25196. min: _int | None = None,
  25197. max: _int | None = None,
  25198. ) -> None: ...
  25199. def t(input: Tensor) -> Tensor:
  25200. r"""
  25201. t(input) -> Tensor
  25202. Expects :attr:`input` to be <= 2-D tensor and transposes dimensions 0
  25203. and 1.
  25204. 0-D and 1-D tensors are returned as is. When input is a 2-D tensor this
  25205. is equivalent to ``transpose(input, 0, 1)``.
  25206. Args:
  25207. input (Tensor): the input tensor.
  25208. Example::
  25209. >>> x = torch.randn(())
  25210. >>> x
  25211. tensor(0.1995)
  25212. >>> torch.t(x)
  25213. tensor(0.1995)
  25214. >>> x = torch.randn(3)
  25215. >>> x
  25216. tensor([ 2.4320, -0.4608, 0.7702])
  25217. >>> torch.t(x)
  25218. tensor([ 2.4320, -0.4608, 0.7702])
  25219. >>> x = torch.randn(2, 3)
  25220. >>> x
  25221. tensor([[ 0.4875, 0.9158, -0.5872],
  25222. [ 0.3938, -0.6929, 0.6932]])
  25223. >>> torch.t(x)
  25224. tensor([[ 0.4875, 0.3938],
  25225. [ 0.9158, -0.6929],
  25226. [-0.5872, 0.6932]])
  25227. See also :func:`torch.transpose`.
  25228. """
  25229. def t_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  25230. r"""
  25231. Performs the same operation as :func:`torch.t`, but all output tensors
  25232. are freshly created instead of aliasing the input.
  25233. """
  25234. def take(
  25235. input: Tensor,
  25236. index: Tensor,
  25237. *,
  25238. out: Tensor | None = None,
  25239. ) -> Tensor:
  25240. r"""
  25241. take(input, index) -> Tensor
  25242. Returns a new tensor with the elements of :attr:`input` at the given indices.
  25243. The input tensor is treated as if it were viewed as a 1-D tensor. The result
  25244. takes the same shape as the indices.
  25245. Args:
  25246. input (Tensor): the input tensor.
  25247. index (LongTensor): the indices into tensor
  25248. Example::
  25249. >>> src = torch.tensor([[4, 3, 5],
  25250. ... [6, 7, 8]])
  25251. >>> torch.take(src, torch.tensor([0, 2, 5]))
  25252. tensor([ 4, 5, 8])
  25253. """
  25254. def take_along_dim(
  25255. input: Tensor,
  25256. indices: Tensor,
  25257. dim: _int | None = None,
  25258. *,
  25259. out: Tensor | None = None,
  25260. ) -> Tensor:
  25261. r"""
  25262. take_along_dim(input, indices, dim=None, *, out=None) -> Tensor
  25263. Selects values from :attr:`input` at the 1-dimensional indices from :attr:`indices` along the given :attr:`dim`.
  25264. If :attr:`dim` is None, the input array is treated as if it has been flattened to 1d.
  25265. Functions that return indices along a dimension, like :func:`torch.argmax` and :func:`torch.argsort`,
  25266. are designed to work with this function. See the examples below.
  25267. .. note::
  25268. This function is similar to NumPy's `take_along_axis`.
  25269. See also :func:`torch.gather`.
  25270. Args:
  25271. input (Tensor): the input tensor.
  25272. indices (LongTensor): the indices into :attr:`input`. Must have long dtype.
  25273. dim (int, optional): dimension to select along. Default: 0
  25274. Keyword args:
  25275. out (Tensor, optional): the output tensor.
  25276. Example::
  25277. >>> t = torch.tensor([[10, 30, 20], [60, 40, 50]])
  25278. >>> max_idx = torch.argmax(t)
  25279. >>> torch.take_along_dim(t, max_idx)
  25280. tensor([60])
  25281. >>> sorted_idx = torch.argsort(t, dim=1)
  25282. >>> torch.take_along_dim(t, sorted_idx, dim=1)
  25283. tensor([[10, 20, 30],
  25284. [40, 50, 60]])
  25285. """
  25286. def tan(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  25287. r"""
  25288. tan(input, *, out=None) -> Tensor
  25289. Returns a new tensor with the tangent of the elements in the :attr:`input` tensor,
  25290. where each value in this input tensor is in radians.
  25291. .. math::
  25292. \text{out}_{i} = \tan(\text{input}_{i})
  25293. Args:
  25294. input (Tensor): the input tensor.
  25295. Keyword args:
  25296. out (Tensor, optional): the output tensor.
  25297. Example::
  25298. >>> a = torch.randn(4)
  25299. >>> a
  25300. tensor([-1.2027, -1.7687, 0.4412, -1.3856])
  25301. >>> torch.tan(a)
  25302. tensor([-2.5930, 4.9859, 0.4722, -5.3366])
  25303. """
  25304. def tan_(input: Tensor) -> Tensor: ...
  25305. def tanh(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  25306. r"""
  25307. tanh(input, *, out=None) -> Tensor
  25308. Returns a new tensor with the hyperbolic tangent of the elements
  25309. of :attr:`input`.
  25310. .. math::
  25311. \text{out}_{i} = \tanh(\text{input}_{i})
  25312. Args:
  25313. input (Tensor): the input tensor.
  25314. Keyword args:
  25315. out (Tensor, optional): the output tensor.
  25316. Example::
  25317. >>> a = torch.randn(4)
  25318. >>> a
  25319. tensor([ 0.8986, -0.7279, 1.1745, 0.2611])
  25320. >>> torch.tanh(a)
  25321. tensor([ 0.7156, -0.6218, 0.8257, 0.2553])
  25322. """
  25323. def tanh_(input: Tensor) -> Tensor: ...
  25324. def tensor(
  25325. data: Any,
  25326. dtype: _dtype | None = None,
  25327. device: DeviceLikeType | None = None,
  25328. requires_grad: _bool = False,
  25329. pin_memory: _bool = False,
  25330. ) -> Tensor:
  25331. r"""
  25332. tensor(data, *, dtype=None, device=None, requires_grad=False, pin_memory=False) -> Tensor
  25333. Constructs a tensor with no autograd history (also known as a "leaf tensor", see :doc:`/notes/autograd`) by copying :attr:`data`.
  25334. .. warning::
  25335. When working with tensors prefer using :func:`torch.Tensor.clone`,
  25336. :func:`torch.Tensor.detach`, and :func:`torch.Tensor.requires_grad_` for
  25337. readability. Letting `t` be a tensor, ``torch.tensor(t)`` is equivalent to
  25338. ``t.detach().clone()``, and ``torch.tensor(t, requires_grad=True)``
  25339. is equivalent to ``t.detach().clone().requires_grad_(True)``.
  25340. .. seealso::
  25341. :func:`torch.as_tensor` preserves autograd history and avoids copies where possible.
  25342. :func:`torch.from_numpy` creates a tensor that shares storage with a NumPy array.
  25343. Args:
  25344. data (array_like): Initial data for the tensor. Can be a list, tuple,
  25345. NumPy ``ndarray``, scalar, and other types.
  25346. Keyword args:
  25347. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  25348. Default: if ``None``, infers data type from :attr:`data`.
  25349. device (:class:`torch.device`, optional): the device of the constructed tensor. If None and data is a tensor
  25350. then the device of data is used. If None and data is not a tensor then
  25351. the result tensor is constructed on the current device.
  25352. requires_grad (bool, optional): If autograd should record operations on the
  25353. returned tensor. Default: ``False``.
  25354. pin_memory (bool, optional): If set, returned tensor would be allocated in
  25355. the pinned memory. Works only for CPU tensors. Default: ``False``.
  25356. Example::
  25357. >>> torch.tensor([[0.1, 1.2], [2.2, 3.1], [4.9, 5.2]])
  25358. tensor([[ 0.1000, 1.2000],
  25359. [ 2.2000, 3.1000],
  25360. [ 4.9000, 5.2000]])
  25361. >>> torch.tensor([0, 1]) # Type inference on data
  25362. tensor([ 0, 1])
  25363. >>> torch.tensor([[0.11111, 0.222222, 0.3333333]],
  25364. ... dtype=torch.float64,
  25365. ... device=torch.device('cuda:0')) # creates a double tensor on a CUDA device
  25366. tensor([[ 0.1111, 0.2222, 0.3333]], dtype=torch.float64, device='cuda:0')
  25367. >>> torch.tensor(3.14159) # Create a zero-dimensional (scalar) tensor
  25368. tensor(3.1416)
  25369. >>> torch.tensor([]) # Create an empty tensor (of size (0,))
  25370. tensor([])
  25371. """
  25372. @overload
  25373. def tensor_split(
  25374. input: Tensor,
  25375. tensor_indices_or_sections: Tensor,
  25376. dim: _int = 0,
  25377. ) -> tuple[Tensor, ...]:
  25378. r"""
  25379. tensor_split(input, indices_or_sections, dim=0) -> List of Tensors
  25380. Splits a tensor into multiple sub-tensors, all of which are views of :attr:`input`,
  25381. along dimension :attr:`dim` according to the indices or number of sections specified
  25382. by :attr:`indices_or_sections`. This function is based on NumPy's
  25383. :func:`numpy.array_split`.
  25384. Args:
  25385. input (Tensor): the tensor to split
  25386. indices_or_sections (Tensor, int or list or tuple of ints):
  25387. If :attr:`indices_or_sections` is an integer ``n`` or a zero dimensional long tensor
  25388. with value ``n``, :attr:`input` is split into ``n`` sections along dimension :attr:`dim`.
  25389. If :attr:`input` is divisible by ``n`` along dimension :attr:`dim`, each
  25390. section will be of equal size, :code:`input.size(dim) / n`. If :attr:`input`
  25391. is not divisible by ``n``, the sizes of the first :code:`int(input.size(dim) % n)`
  25392. sections will have size :code:`int(input.size(dim) / n) + 1`, and the rest will
  25393. have size :code:`int(input.size(dim) / n)`.
  25394. If :attr:`indices_or_sections` is a list or tuple of ints, or a one-dimensional long
  25395. tensor, then :attr:`input` is split along dimension :attr:`dim` at each of the indices
  25396. in the list, tuple or tensor. For instance, :code:`indices_or_sections=[2, 3]` and :code:`dim=0`
  25397. would result in the tensors :code:`input[:2]`, :code:`input[2:3]`, and :code:`input[3:]`.
  25398. If :attr:`indices_or_sections` is a tensor, it must be a zero-dimensional or one-dimensional
  25399. long tensor on the CPU.
  25400. dim (int, optional): dimension along which to split the tensor. Default: ``0``
  25401. Example::
  25402. >>> x = torch.arange(8)
  25403. >>> torch.tensor_split(x, 3)
  25404. (tensor([0, 1, 2]), tensor([3, 4, 5]), tensor([6, 7]))
  25405. >>> x = torch.arange(7)
  25406. >>> torch.tensor_split(x, 3)
  25407. (tensor([0, 1, 2]), tensor([3, 4]), tensor([5, 6]))
  25408. >>> torch.tensor_split(x, (1, 6))
  25409. (tensor([0]), tensor([1, 2, 3, 4, 5]), tensor([6]))
  25410. >>> x = torch.arange(14).reshape(2, 7)
  25411. >>> x
  25412. tensor([[ 0, 1, 2, 3, 4, 5, 6],
  25413. [ 7, 8, 9, 10, 11, 12, 13]])
  25414. >>> torch.tensor_split(x, 3, dim=1)
  25415. (tensor([[0, 1, 2],
  25416. [7, 8, 9]]),
  25417. tensor([[ 3, 4],
  25418. [10, 11]]),
  25419. tensor([[ 5, 6],
  25420. [12, 13]]))
  25421. >>> torch.tensor_split(x, (1, 6), dim=1)
  25422. (tensor([[0],
  25423. [7]]),
  25424. tensor([[ 1, 2, 3, 4, 5],
  25425. [ 8, 9, 10, 11, 12]]),
  25426. tensor([[ 6],
  25427. [13]]))
  25428. """
  25429. @overload
  25430. def tensor_split(
  25431. input: Tensor,
  25432. sections: _int | SymInt,
  25433. dim: _int = 0,
  25434. ) -> tuple[Tensor, ...]:
  25435. r"""
  25436. tensor_split(input, indices_or_sections, dim=0) -> List of Tensors
  25437. Splits a tensor into multiple sub-tensors, all of which are views of :attr:`input`,
  25438. along dimension :attr:`dim` according to the indices or number of sections specified
  25439. by :attr:`indices_or_sections`. This function is based on NumPy's
  25440. :func:`numpy.array_split`.
  25441. Args:
  25442. input (Tensor): the tensor to split
  25443. indices_or_sections (Tensor, int or list or tuple of ints):
  25444. If :attr:`indices_or_sections` is an integer ``n`` or a zero dimensional long tensor
  25445. with value ``n``, :attr:`input` is split into ``n`` sections along dimension :attr:`dim`.
  25446. If :attr:`input` is divisible by ``n`` along dimension :attr:`dim`, each
  25447. section will be of equal size, :code:`input.size(dim) / n`. If :attr:`input`
  25448. is not divisible by ``n``, the sizes of the first :code:`int(input.size(dim) % n)`
  25449. sections will have size :code:`int(input.size(dim) / n) + 1`, and the rest will
  25450. have size :code:`int(input.size(dim) / n)`.
  25451. If :attr:`indices_or_sections` is a list or tuple of ints, or a one-dimensional long
  25452. tensor, then :attr:`input` is split along dimension :attr:`dim` at each of the indices
  25453. in the list, tuple or tensor. For instance, :code:`indices_or_sections=[2, 3]` and :code:`dim=0`
  25454. would result in the tensors :code:`input[:2]`, :code:`input[2:3]`, and :code:`input[3:]`.
  25455. If :attr:`indices_or_sections` is a tensor, it must be a zero-dimensional or one-dimensional
  25456. long tensor on the CPU.
  25457. dim (int, optional): dimension along which to split the tensor. Default: ``0``
  25458. Example::
  25459. >>> x = torch.arange(8)
  25460. >>> torch.tensor_split(x, 3)
  25461. (tensor([0, 1, 2]), tensor([3, 4, 5]), tensor([6, 7]))
  25462. >>> x = torch.arange(7)
  25463. >>> torch.tensor_split(x, 3)
  25464. (tensor([0, 1, 2]), tensor([3, 4]), tensor([5, 6]))
  25465. >>> torch.tensor_split(x, (1, 6))
  25466. (tensor([0]), tensor([1, 2, 3, 4, 5]), tensor([6]))
  25467. >>> x = torch.arange(14).reshape(2, 7)
  25468. >>> x
  25469. tensor([[ 0, 1, 2, 3, 4, 5, 6],
  25470. [ 7, 8, 9, 10, 11, 12, 13]])
  25471. >>> torch.tensor_split(x, 3, dim=1)
  25472. (tensor([[0, 1, 2],
  25473. [7, 8, 9]]),
  25474. tensor([[ 3, 4],
  25475. [10, 11]]),
  25476. tensor([[ 5, 6],
  25477. [12, 13]]))
  25478. >>> torch.tensor_split(x, (1, 6), dim=1)
  25479. (tensor([[0],
  25480. [7]]),
  25481. tensor([[ 1, 2, 3, 4, 5],
  25482. [ 8, 9, 10, 11, 12]]),
  25483. tensor([[ 6],
  25484. [13]]))
  25485. """
  25486. @overload
  25487. def tensor_split(
  25488. input: Tensor,
  25489. indices: Sequence[_int | SymInt],
  25490. dim: _int = 0,
  25491. ) -> tuple[Tensor, ...]:
  25492. r"""
  25493. tensor_split(input, indices_or_sections, dim=0) -> List of Tensors
  25494. Splits a tensor into multiple sub-tensors, all of which are views of :attr:`input`,
  25495. along dimension :attr:`dim` according to the indices or number of sections specified
  25496. by :attr:`indices_or_sections`. This function is based on NumPy's
  25497. :func:`numpy.array_split`.
  25498. Args:
  25499. input (Tensor): the tensor to split
  25500. indices_or_sections (Tensor, int or list or tuple of ints):
  25501. If :attr:`indices_or_sections` is an integer ``n`` or a zero dimensional long tensor
  25502. with value ``n``, :attr:`input` is split into ``n`` sections along dimension :attr:`dim`.
  25503. If :attr:`input` is divisible by ``n`` along dimension :attr:`dim`, each
  25504. section will be of equal size, :code:`input.size(dim) / n`. If :attr:`input`
  25505. is not divisible by ``n``, the sizes of the first :code:`int(input.size(dim) % n)`
  25506. sections will have size :code:`int(input.size(dim) / n) + 1`, and the rest will
  25507. have size :code:`int(input.size(dim) / n)`.
  25508. If :attr:`indices_or_sections` is a list or tuple of ints, or a one-dimensional long
  25509. tensor, then :attr:`input` is split along dimension :attr:`dim` at each of the indices
  25510. in the list, tuple or tensor. For instance, :code:`indices_or_sections=[2, 3]` and :code:`dim=0`
  25511. would result in the tensors :code:`input[:2]`, :code:`input[2:3]`, and :code:`input[3:]`.
  25512. If :attr:`indices_or_sections` is a tensor, it must be a zero-dimensional or one-dimensional
  25513. long tensor on the CPU.
  25514. dim (int, optional): dimension along which to split the tensor. Default: ``0``
  25515. Example::
  25516. >>> x = torch.arange(8)
  25517. >>> torch.tensor_split(x, 3)
  25518. (tensor([0, 1, 2]), tensor([3, 4, 5]), tensor([6, 7]))
  25519. >>> x = torch.arange(7)
  25520. >>> torch.tensor_split(x, 3)
  25521. (tensor([0, 1, 2]), tensor([3, 4]), tensor([5, 6]))
  25522. >>> torch.tensor_split(x, (1, 6))
  25523. (tensor([0]), tensor([1, 2, 3, 4, 5]), tensor([6]))
  25524. >>> x = torch.arange(14).reshape(2, 7)
  25525. >>> x
  25526. tensor([[ 0, 1, 2, 3, 4, 5, 6],
  25527. [ 7, 8, 9, 10, 11, 12, 13]])
  25528. >>> torch.tensor_split(x, 3, dim=1)
  25529. (tensor([[0, 1, 2],
  25530. [7, 8, 9]]),
  25531. tensor([[ 3, 4],
  25532. [10, 11]]),
  25533. tensor([[ 5, 6],
  25534. [12, 13]]))
  25535. >>> torch.tensor_split(x, (1, 6), dim=1)
  25536. (tensor([[0],
  25537. [7]]),
  25538. tensor([[ 1, 2, 3, 4, 5],
  25539. [ 8, 9, 10, 11, 12]]),
  25540. tensor([[ 6],
  25541. [13]]))
  25542. """
  25543. def threshold(
  25544. input: Tensor,
  25545. threshold: Number | _complex,
  25546. value: Number | _complex,
  25547. *,
  25548. out: Tensor | None = None,
  25549. ) -> Tensor: ...
  25550. def threshold_(
  25551. input: Tensor,
  25552. threshold: Number | _complex,
  25553. value: Number | _complex,
  25554. ) -> Tensor: ...
  25555. def tile(input: Tensor, dims: Sequence[_int | SymInt]) -> Tensor:
  25556. r"""
  25557. tile(input, dims) -> Tensor
  25558. Constructs a tensor by repeating the elements of :attr:`input`.
  25559. The :attr:`dims` argument specifies the number of repetitions
  25560. in each dimension.
  25561. If :attr:`dims` specifies fewer dimensions than :attr:`input` has, then
  25562. ones are prepended to :attr:`dims` until all dimensions are specified.
  25563. For example, if :attr:`input` has shape (8, 6, 4, 2) and :attr:`dims`
  25564. is (2, 2), then :attr:`dims` is treated as (1, 1, 2, 2).
  25565. Analogously, if :attr:`input` has fewer dimensions than :attr:`dims`
  25566. specifies, then :attr:`input` is treated as if it were unsqueezed at
  25567. dimension zero until it has as many dimensions as :attr:`dims` specifies.
  25568. For example, if :attr:`input` has shape (4, 2) and :attr:`dims`
  25569. is (3, 3, 2, 2), then :attr:`input` is treated as if it had the
  25570. shape (1, 1, 4, 2).
  25571. .. note::
  25572. This function is similar to NumPy's tile function.
  25573. Args:
  25574. input (Tensor): the tensor whose elements to repeat.
  25575. dims (tuple): the number of repetitions per dimension.
  25576. Example::
  25577. >>> x = torch.tensor([1, 2, 3])
  25578. >>> x.tile((2,))
  25579. tensor([1, 2, 3, 1, 2, 3])
  25580. >>> y = torch.tensor([[1, 2], [3, 4]])
  25581. >>> torch.tile(y, (2, 2))
  25582. tensor([[1, 2, 1, 2],
  25583. [3, 4, 3, 4],
  25584. [1, 2, 1, 2],
  25585. [3, 4, 3, 4]])
  25586. """
  25587. def topk(
  25588. input: Tensor,
  25589. k: _int | SymInt,
  25590. dim: _int = -1,
  25591. largest: _bool = True,
  25592. sorted: _bool = True,
  25593. *,
  25594. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  25595. ) -> torch.return_types.topk:
  25596. r"""
  25597. topk(input, k, dim=None, largest=True, sorted=True, *, out=None) -> (Tensor, LongTensor)
  25598. Returns the :attr:`k` largest elements of the given :attr:`input` tensor along
  25599. a given dimension.
  25600. If :attr:`dim` is not given, the last dimension of the `input` is chosen.
  25601. If :attr:`largest` is ``False`` then the `k` smallest elements are returned.
  25602. A namedtuple of `(values, indices)` is returned with the `values` and
  25603. `indices` of the largest `k` elements of each row of the `input` tensor in the
  25604. given dimension `dim`.
  25605. The boolean option :attr:`sorted` if ``True``, will make sure that the returned
  25606. `k` elements are themselves sorted
  25607. .. note::
  25608. When using `torch.topk`, the indices of tied elements are not guaranteed to be stable
  25609. and may vary across different invocations.
  25610. Args:
  25611. input (Tensor): the input tensor.
  25612. k (int): the k in "top-k"
  25613. dim (int, optional): the dimension to sort along
  25614. largest (bool, optional): controls whether to return largest or
  25615. smallest elements
  25616. sorted (bool, optional): controls whether to return the elements
  25617. in sorted order
  25618. Keyword args:
  25619. out (tuple, optional): the output tuple of (Tensor, LongTensor) that can be
  25620. optionally given to be used as output buffers
  25621. Example::
  25622. >>> x = torch.arange(1., 6.)
  25623. >>> x
  25624. tensor([ 1., 2., 3., 4., 5.])
  25625. >>> torch.topk(x, 3)
  25626. torch.return_types.topk(values=tensor([5., 4., 3.]), indices=tensor([4, 3, 2]))
  25627. """
  25628. def trace(input: Tensor) -> Tensor:
  25629. r"""
  25630. trace(input) -> Tensor
  25631. Returns the sum of the elements of the diagonal of the input 2-D matrix.
  25632. Example::
  25633. >>> x = torch.arange(1., 10.).view(3, 3)
  25634. >>> x
  25635. tensor([[ 1., 2., 3.],
  25636. [ 4., 5., 6.],
  25637. [ 7., 8., 9.]])
  25638. >>> torch.trace(x)
  25639. tensor(15.)
  25640. """
  25641. @overload
  25642. def transpose(input: Tensor, dim0: _int, dim1: _int) -> Tensor:
  25643. r"""
  25644. transpose(input, dim0, dim1) -> Tensor
  25645. Returns a tensor that is a transposed version of :attr:`input`.
  25646. The given dimensions :attr:`dim0` and :attr:`dim1` are swapped.
  25647. If :attr:`input` is a strided tensor then the resulting :attr:`out`
  25648. tensor shares its underlying storage with the :attr:`input` tensor, so
  25649. changing the content of one would change the content of the other.
  25650. If :attr:`input` is a :ref:`sparse tensor <sparse-docs>` then the
  25651. resulting :attr:`out` tensor *does not* share the underlying storage
  25652. with the :attr:`input` tensor.
  25653. If :attr:`input` is a :ref:`sparse tensor <sparse-docs>` with compressed
  25654. layout (SparseCSR, SparseBSR, SparseCSC or SparseBSC) the arguments
  25655. :attr:`dim0` and :attr:`dim1` must be both batch dimensions, or must
  25656. both be sparse dimensions. The batch dimensions of a sparse tensor are the
  25657. dimensions preceding the sparse dimensions.
  25658. .. note::
  25659. Transpositions which interchange the sparse dimensions of a `SparseCSR`
  25660. or `SparseCSC` layout tensor will result in the layout changing between
  25661. the two options. Transposition of the sparse dimensions of a ` SparseBSR`
  25662. or `SparseBSC` layout tensor will likewise generate a result with the
  25663. opposite layout.
  25664. Args:
  25665. input (Tensor): the input tensor.
  25666. dim0 (int): the first dimension to be transposed
  25667. dim1 (int): the second dimension to be transposed
  25668. Example::
  25669. >>> x = torch.randn(2, 3)
  25670. >>> x
  25671. tensor([[ 1.0028, -0.9893, 0.5809],
  25672. [-0.1669, 0.7299, 0.4942]])
  25673. >>> torch.transpose(x, 0, 1)
  25674. tensor([[ 1.0028, -0.1669],
  25675. [-0.9893, 0.7299],
  25676. [ 0.5809, 0.4942]])
  25677. See also :func:`torch.t`.
  25678. """
  25679. @overload
  25680. def transpose(
  25681. input: Tensor,
  25682. dim0: str | EllipsisType | None,
  25683. dim1: str | EllipsisType | None,
  25684. ) -> Tensor:
  25685. r"""
  25686. transpose(input, dim0, dim1) -> Tensor
  25687. Returns a tensor that is a transposed version of :attr:`input`.
  25688. The given dimensions :attr:`dim0` and :attr:`dim1` are swapped.
  25689. If :attr:`input` is a strided tensor then the resulting :attr:`out`
  25690. tensor shares its underlying storage with the :attr:`input` tensor, so
  25691. changing the content of one would change the content of the other.
  25692. If :attr:`input` is a :ref:`sparse tensor <sparse-docs>` then the
  25693. resulting :attr:`out` tensor *does not* share the underlying storage
  25694. with the :attr:`input` tensor.
  25695. If :attr:`input` is a :ref:`sparse tensor <sparse-docs>` with compressed
  25696. layout (SparseCSR, SparseBSR, SparseCSC or SparseBSC) the arguments
  25697. :attr:`dim0` and :attr:`dim1` must be both batch dimensions, or must
  25698. both be sparse dimensions. The batch dimensions of a sparse tensor are the
  25699. dimensions preceding the sparse dimensions.
  25700. .. note::
  25701. Transpositions which interchange the sparse dimensions of a `SparseCSR`
  25702. or `SparseCSC` layout tensor will result in the layout changing between
  25703. the two options. Transposition of the sparse dimensions of a ` SparseBSR`
  25704. or `SparseBSC` layout tensor will likewise generate a result with the
  25705. opposite layout.
  25706. Args:
  25707. input (Tensor): the input tensor.
  25708. dim0 (int): the first dimension to be transposed
  25709. dim1 (int): the second dimension to be transposed
  25710. Example::
  25711. >>> x = torch.randn(2, 3)
  25712. >>> x
  25713. tensor([[ 1.0028, -0.9893, 0.5809],
  25714. [-0.1669, 0.7299, 0.4942]])
  25715. >>> torch.transpose(x, 0, 1)
  25716. tensor([[ 1.0028, -0.1669],
  25717. [-0.9893, 0.7299],
  25718. [ 0.5809, 0.4942]])
  25719. See also :func:`torch.t`.
  25720. """
  25721. def transpose_copy(
  25722. input: Tensor,
  25723. dim0: _int,
  25724. dim1: _int,
  25725. *,
  25726. out: Tensor | None = None,
  25727. ) -> Tensor:
  25728. r"""
  25729. Performs the same operation as :func:`torch.transpose`, but all output tensors
  25730. are freshly created instead of aliasing the input.
  25731. """
  25732. @overload
  25733. def trapezoid(y: Tensor, x: Tensor, *, dim: _int = -1) -> Tensor:
  25734. r"""
  25735. trapezoid(y, x=None, *, dx=None, dim=-1) -> Tensor
  25736. Computes the `trapezoidal rule <https://en.wikipedia.org/wiki/Trapezoidal_rule>`_ along
  25737. :attr:`dim`. By default the spacing between elements is assumed to be 1, but
  25738. :attr:`dx` can be used to specify a different constant spacing, and :attr:`x` can be
  25739. used to specify arbitrary spacing along :attr:`dim`. Only one of :attr:`x` or :attr:`dx` should be specified.
  25740. Assuming :attr:`y` is a one-dimensional tensor with elements :math:`{y_0, y_1, ..., y_n}`,
  25741. the default computation is
  25742. .. math::
  25743. \begin{aligned}
  25744. \sum_{i = 1}^{n} \frac{1}{2} (y_i + y_{i-1})
  25745. \end{aligned}
  25746. When :attr:`dx` is specified the computation becomes
  25747. .. math::
  25748. \begin{aligned}
  25749. \sum_{i = 1}^{n} \frac{\Delta x}{2} (y_i + y_{i-1})
  25750. \end{aligned}
  25751. effectively multiplying the result by :attr:`dx`. When :attr:`x` is specified,
  25752. assuming :attr:`x` is also a one-dimensional tensor with
  25753. elements :math:`{x_0, x_1, ..., x_n}`, the computation becomes
  25754. .. math::
  25755. \begin{aligned}
  25756. \sum_{i = 1}^{n} \frac{(x_i - x_{i-1})}{2} (y_i + y_{i-1})
  25757. \end{aligned}
  25758. When :attr:`x` and :attr:`y` have the same size, the computation is as described above and no broadcasting is needed.
  25759. The broadcasting behavior of this function is as follows when their sizes are different. For both :attr:`x`
  25760. and :attr:`y`, the function computes the difference between consecutive elements along
  25761. dimension :attr:`dim`. This effectively creates two tensors, `x_diff` and `y_diff`, that have
  25762. the same shape as the original tensors except their lengths along the dimension :attr:`dim` is reduced by 1.
  25763. After that, those two tensors are broadcast together to compute final output as part of the trapezoidal rule.
  25764. See the examples below for details.
  25765. .. note::
  25766. The trapezoidal rule is a technique for approximating the definite integral of a function
  25767. by averaging its left and right Riemann sums. The approximation becomes more accurate as
  25768. the resolution of the partition increases.
  25769. Arguments:
  25770. y (Tensor): Values to use when computing the trapezoidal rule.
  25771. x (Tensor): If specified, defines spacing between values as specified above.
  25772. Keyword arguments:
  25773. dx (float): constant spacing between values. If neither :attr:`x` or :attr:`dx`
  25774. are specified then this defaults to 1. Effectively multiplies the result by its value.
  25775. dim (int): The dimension along which to compute the trapezoidal rule.
  25776. The last (inner-most) dimension by default.
  25777. Examples::
  25778. >>> # Computes the trapezoidal rule in 1D, spacing is implicitly 1
  25779. >>> y = torch.tensor([1, 5, 10])
  25780. >>> torch.trapezoid(y)
  25781. tensor(10.5)
  25782. >>> # Computes the same trapezoidal rule directly to verify
  25783. >>> (1 + 10 + 10) / 2
  25784. 10.5
  25785. >>> # Computes the trapezoidal rule in 1D with constant spacing of 2
  25786. >>> # NOTE: the result is the same as before, but multiplied by 2
  25787. >>> torch.trapezoid(y, dx=2)
  25788. 21.0
  25789. >>> # Computes the trapezoidal rule in 1D with arbitrary spacing
  25790. >>> x = torch.tensor([1, 3, 6])
  25791. >>> torch.trapezoid(y, x)
  25792. 28.5
  25793. >>> # Computes the same trapezoidal rule directly to verify
  25794. >>> ((3 - 1) * (1 + 5) + (6 - 3) * (5 + 10)) / 2
  25795. 28.5
  25796. >>> # Computes the trapezoidal rule for each row of a 3x3 matrix
  25797. >>> y = torch.arange(9).reshape(3, 3)
  25798. tensor([[0, 1, 2],
  25799. [3, 4, 5],
  25800. [6, 7, 8]])
  25801. >>> torch.trapezoid(y)
  25802. tensor([ 2., 8., 14.])
  25803. >>> # Computes the trapezoidal rule for each column of the matrix
  25804. >>> torch.trapezoid(y, dim=0)
  25805. tensor([ 6., 8., 10.])
  25806. >>> # Computes the trapezoidal rule for each row of a 3x3 ones matrix
  25807. >>> # with the same arbitrary spacing
  25808. >>> y = torch.ones(3, 3)
  25809. >>> x = torch.tensor([1, 3, 6])
  25810. >>> torch.trapezoid(y, x)
  25811. array([5., 5., 5.])
  25812. >>> # Computes the trapezoidal rule for each row of a 3x3 ones matrix
  25813. >>> # with different arbitrary spacing per row
  25814. >>> y = torch.ones(3, 3)
  25815. >>> x = torch.tensor([[1, 2, 3], [1, 3, 5], [1, 4, 7]])
  25816. >>> torch.trapezoid(y, x)
  25817. array([2., 4., 6.])
  25818. """
  25819. @overload
  25820. def trapezoid(
  25821. y: Tensor,
  25822. *,
  25823. dx: Number | _complex = 1,
  25824. dim: _int = -1,
  25825. ) -> Tensor:
  25826. r"""
  25827. trapezoid(y, x=None, *, dx=None, dim=-1) -> Tensor
  25828. Computes the `trapezoidal rule <https://en.wikipedia.org/wiki/Trapezoidal_rule>`_ along
  25829. :attr:`dim`. By default the spacing between elements is assumed to be 1, but
  25830. :attr:`dx` can be used to specify a different constant spacing, and :attr:`x` can be
  25831. used to specify arbitrary spacing along :attr:`dim`. Only one of :attr:`x` or :attr:`dx` should be specified.
  25832. Assuming :attr:`y` is a one-dimensional tensor with elements :math:`{y_0, y_1, ..., y_n}`,
  25833. the default computation is
  25834. .. math::
  25835. \begin{aligned}
  25836. \sum_{i = 1}^{n} \frac{1}{2} (y_i + y_{i-1})
  25837. \end{aligned}
  25838. When :attr:`dx` is specified the computation becomes
  25839. .. math::
  25840. \begin{aligned}
  25841. \sum_{i = 1}^{n} \frac{\Delta x}{2} (y_i + y_{i-1})
  25842. \end{aligned}
  25843. effectively multiplying the result by :attr:`dx`. When :attr:`x` is specified,
  25844. assuming :attr:`x` is also a one-dimensional tensor with
  25845. elements :math:`{x_0, x_1, ..., x_n}`, the computation becomes
  25846. .. math::
  25847. \begin{aligned}
  25848. \sum_{i = 1}^{n} \frac{(x_i - x_{i-1})}{2} (y_i + y_{i-1})
  25849. \end{aligned}
  25850. When :attr:`x` and :attr:`y` have the same size, the computation is as described above and no broadcasting is needed.
  25851. The broadcasting behavior of this function is as follows when their sizes are different. For both :attr:`x`
  25852. and :attr:`y`, the function computes the difference between consecutive elements along
  25853. dimension :attr:`dim`. This effectively creates two tensors, `x_diff` and `y_diff`, that have
  25854. the same shape as the original tensors except their lengths along the dimension :attr:`dim` is reduced by 1.
  25855. After that, those two tensors are broadcast together to compute final output as part of the trapezoidal rule.
  25856. See the examples below for details.
  25857. .. note::
  25858. The trapezoidal rule is a technique for approximating the definite integral of a function
  25859. by averaging its left and right Riemann sums. The approximation becomes more accurate as
  25860. the resolution of the partition increases.
  25861. Arguments:
  25862. y (Tensor): Values to use when computing the trapezoidal rule.
  25863. x (Tensor): If specified, defines spacing between values as specified above.
  25864. Keyword arguments:
  25865. dx (float): constant spacing between values. If neither :attr:`x` or :attr:`dx`
  25866. are specified then this defaults to 1. Effectively multiplies the result by its value.
  25867. dim (int): The dimension along which to compute the trapezoidal rule.
  25868. The last (inner-most) dimension by default.
  25869. Examples::
  25870. >>> # Computes the trapezoidal rule in 1D, spacing is implicitly 1
  25871. >>> y = torch.tensor([1, 5, 10])
  25872. >>> torch.trapezoid(y)
  25873. tensor(10.5)
  25874. >>> # Computes the same trapezoidal rule directly to verify
  25875. >>> (1 + 10 + 10) / 2
  25876. 10.5
  25877. >>> # Computes the trapezoidal rule in 1D with constant spacing of 2
  25878. >>> # NOTE: the result is the same as before, but multiplied by 2
  25879. >>> torch.trapezoid(y, dx=2)
  25880. 21.0
  25881. >>> # Computes the trapezoidal rule in 1D with arbitrary spacing
  25882. >>> x = torch.tensor([1, 3, 6])
  25883. >>> torch.trapezoid(y, x)
  25884. 28.5
  25885. >>> # Computes the same trapezoidal rule directly to verify
  25886. >>> ((3 - 1) * (1 + 5) + (6 - 3) * (5 + 10)) / 2
  25887. 28.5
  25888. >>> # Computes the trapezoidal rule for each row of a 3x3 matrix
  25889. >>> y = torch.arange(9).reshape(3, 3)
  25890. tensor([[0, 1, 2],
  25891. [3, 4, 5],
  25892. [6, 7, 8]])
  25893. >>> torch.trapezoid(y)
  25894. tensor([ 2., 8., 14.])
  25895. >>> # Computes the trapezoidal rule for each column of the matrix
  25896. >>> torch.trapezoid(y, dim=0)
  25897. tensor([ 6., 8., 10.])
  25898. >>> # Computes the trapezoidal rule for each row of a 3x3 ones matrix
  25899. >>> # with the same arbitrary spacing
  25900. >>> y = torch.ones(3, 3)
  25901. >>> x = torch.tensor([1, 3, 6])
  25902. >>> torch.trapezoid(y, x)
  25903. array([5., 5., 5.])
  25904. >>> # Computes the trapezoidal rule for each row of a 3x3 ones matrix
  25905. >>> # with different arbitrary spacing per row
  25906. >>> y = torch.ones(3, 3)
  25907. >>> x = torch.tensor([[1, 2, 3], [1, 3, 5], [1, 4, 7]])
  25908. >>> torch.trapezoid(y, x)
  25909. array([2., 4., 6.])
  25910. """
  25911. @overload
  25912. def trapz(y: Tensor, *, dx: _float = 1, dim: _int = -1) -> Tensor:
  25913. r"""
  25914. trapz(y, x, *, dim=-1) -> Tensor
  25915. Alias for :func:`torch.trapezoid`.
  25916. """
  25917. @overload
  25918. def trapz(y: Tensor, x: Tensor, *, dim: _int = -1) -> Tensor:
  25919. r"""
  25920. trapz(y, x, *, dim=-1) -> Tensor
  25921. Alias for :func:`torch.trapezoid`.
  25922. """
  25923. def triangular_solve(
  25924. input: Tensor,
  25925. A: Tensor,
  25926. upper: _bool = True,
  25927. transpose: _bool = False,
  25928. unitriangular: _bool = False,
  25929. *,
  25930. out: Tensor | tuple[Tensor, ...] | list[Tensor] | None = None,
  25931. ) -> torch.return_types.triangular_solve:
  25932. r"""
  25933. triangular_solve(b, A, upper=True, transpose=False, unitriangular=False, *, out=None) -> (Tensor, Tensor)
  25934. Solves a system of equations with a square upper or lower triangular invertible matrix :math:`A`
  25935. and multiple right-hand sides :math:`b`.
  25936. In symbols, it solves :math:`AX = b` and assumes :math:`A` is square upper-triangular
  25937. (or lower-triangular if :attr:`upper`\ `= False`) and does not have zeros on the diagonal.
  25938. `torch.triangular_solve(b, A)` can take in 2D inputs `b, A` or inputs that are
  25939. batches of 2D matrices. If the inputs are batches, then returns
  25940. batched outputs `X`
  25941. If the diagonal of :attr:`A` contains zeros or elements that are very close to zero and
  25942. :attr:`unitriangular`\ `= False` (default) or if the input matrix is badly conditioned,
  25943. the result may contain `NaN` s.
  25944. Supports input of float, double, cfloat and cdouble data types.
  25945. .. warning::
  25946. :func:`torch.triangular_solve` is deprecated in favor of :func:`torch.linalg.solve_triangular`
  25947. and will be removed in a future PyTorch release.
  25948. :func:`torch.linalg.solve_triangular` has its arguments reversed and does not return a
  25949. copy of one of the inputs.
  25950. ``X = torch.triangular_solve(B, A).solution`` should be replaced with
  25951. .. code:: python
  25952. X = torch.linalg.solve_triangular(A, B)
  25953. Args:
  25954. b (Tensor): multiple right-hand sides of size :math:`(*, m, k)` where
  25955. :math:`*` is zero of more batch dimensions
  25956. A (Tensor): the input triangular coefficient matrix of size :math:`(*, m, m)`
  25957. where :math:`*` is zero or more batch dimensions
  25958. upper (bool, optional): whether :math:`A` is upper or lower triangular. Default: ``True``.
  25959. transpose (bool, optional): solves `op(A)X = b` where `op(A) = A^T` if this flag is ``True``,
  25960. and `op(A) = A` if it is ``False``. Default: ``False``.
  25961. unitriangular (bool, optional): whether :math:`A` is unit triangular.
  25962. If True, the diagonal elements of :math:`A` are assumed to be
  25963. 1 and not referenced from :math:`A`. Default: ``False``.
  25964. Keyword args:
  25965. out ((Tensor, Tensor), optional): tuple of two tensors to write
  25966. the output to. Ignored if `None`. Default: `None`.
  25967. Returns:
  25968. A namedtuple `(solution, cloned_coefficient)` where `cloned_coefficient`
  25969. is a clone of :math:`A` and `solution` is the solution :math:`X` to :math:`AX = b`
  25970. (or whatever variant of the system of equations, depending on the keyword arguments.)
  25971. Examples::
  25972. >>> A = torch.randn(2, 2).triu()
  25973. >>> A
  25974. tensor([[ 1.1527, -1.0753],
  25975. [ 0.0000, 0.7986]])
  25976. >>> b = torch.randn(2, 3)
  25977. >>> b
  25978. tensor([[-0.0210, 2.3513, -1.5492],
  25979. [ 1.5429, 0.7403, -1.0243]])
  25980. >>> torch.triangular_solve(b, A)
  25981. torch.return_types.triangular_solve(
  25982. solution=tensor([[ 1.7841, 2.9046, -2.5405],
  25983. [ 1.9320, 0.9270, -1.2826]]),
  25984. cloned_coefficient=tensor([[ 1.1527, -1.0753],
  25985. [ 0.0000, 0.7986]]))
  25986. """
  25987. def tril(
  25988. input: Tensor,
  25989. diagonal: _int | SymInt = 0,
  25990. *,
  25991. out: Tensor | None = None,
  25992. ) -> Tensor:
  25993. r"""
  25994. tril(input, diagonal=0, *, out=None) -> Tensor
  25995. Returns the lower triangular part of the matrix (2-D tensor) or batch of matrices
  25996. :attr:`input`, the other elements of the result tensor :attr:`out` are set to 0.
  25997. The lower triangular part of the matrix is defined as the elements on and
  25998. below the diagonal.
  25999. The argument :attr:`diagonal` controls which diagonal to consider. If
  26000. :attr:`diagonal` = 0, all elements on and below the main diagonal are
  26001. retained. A positive value includes just as many diagonals above the main
  26002. diagonal, and similarly a negative value excludes just as many diagonals below
  26003. the main diagonal. The main diagonal are the set of indices
  26004. :math:`\lbrace (i, i) \rbrace` for :math:`i \in [0, \min\{d_{1}, d_{2}\} - 1]` where
  26005. :math:`d_{1}, d_{2}` are the dimensions of the matrix.
  26006. Args:
  26007. input (Tensor): the input tensor.
  26008. diagonal (int, optional): the diagonal to consider
  26009. Keyword args:
  26010. out (Tensor, optional): the output tensor.
  26011. Example::
  26012. >>> a = torch.randn(3, 3)
  26013. >>> a
  26014. tensor([[-1.0813, -0.8619, 0.7105],
  26015. [ 0.0935, 0.1380, 2.2112],
  26016. [-0.3409, -0.9828, 0.0289]])
  26017. >>> torch.tril(a)
  26018. tensor([[-1.0813, 0.0000, 0.0000],
  26019. [ 0.0935, 0.1380, 0.0000],
  26020. [-0.3409, -0.9828, 0.0289]])
  26021. >>> b = torch.randn(4, 6)
  26022. >>> b
  26023. tensor([[ 1.2219, 0.5653, -0.2521, -0.2345, 1.2544, 0.3461],
  26024. [ 0.4785, -0.4477, 0.6049, 0.6368, 0.8775, 0.7145],
  26025. [ 1.1502, 3.2716, -1.1243, -0.5413, 0.3615, 0.6864],
  26026. [-0.0614, -0.7344, -1.3164, -0.7648, -1.4024, 0.0978]])
  26027. >>> torch.tril(b, diagonal=1)
  26028. tensor([[ 1.2219, 0.5653, 0.0000, 0.0000, 0.0000, 0.0000],
  26029. [ 0.4785, -0.4477, 0.6049, 0.0000, 0.0000, 0.0000],
  26030. [ 1.1502, 3.2716, -1.1243, -0.5413, 0.0000, 0.0000],
  26031. [-0.0614, -0.7344, -1.3164, -0.7648, -1.4024, 0.0000]])
  26032. >>> torch.tril(b, diagonal=-1)
  26033. tensor([[ 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
  26034. [ 0.4785, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
  26035. [ 1.1502, 3.2716, 0.0000, 0.0000, 0.0000, 0.0000],
  26036. [-0.0614, -0.7344, -1.3164, 0.0000, 0.0000, 0.0000]])
  26037. """
  26038. def tril_indices(
  26039. row: _int,
  26040. col: _int,
  26041. offset: _int = 0,
  26042. *,
  26043. dtype: _dtype | None = None,
  26044. layout: _layout | None = None,
  26045. device: DeviceLikeType | None = None,
  26046. pin_memory: _bool | None = False,
  26047. requires_grad: _bool | None = False,
  26048. ) -> Tensor:
  26049. r"""
  26050. tril_indices(row, col, offset=0, *, dtype=torch.long, device='cpu', layout=torch.strided) -> Tensor
  26051. Returns the indices of the lower triangular part of a :attr:`row`-by-
  26052. :attr:`col` matrix in a 2-by-N Tensor, where the first row contains row
  26053. coordinates of all indices and the second row contains column coordinates.
  26054. Indices are ordered based on rows and then columns.
  26055. The lower triangular part of the matrix is defined as the elements on and
  26056. below the diagonal.
  26057. The argument :attr:`offset` controls which diagonal to consider. If
  26058. :attr:`offset` = 0, all elements on and below the main diagonal are
  26059. retained. A positive value includes just as many diagonals above the main
  26060. diagonal, and similarly a negative value excludes just as many diagonals below
  26061. the main diagonal. The main diagonal are the set of indices
  26062. :math:`\lbrace (i, i) \rbrace` for :math:`i \in [0, \min\{d_{1}, d_{2}\} - 1]`
  26063. where :math:`d_{1}, d_{2}` are the dimensions of the matrix.
  26064. .. note::
  26065. When running on CUDA, ``row * col`` must be less than :math:`2^{59}` to
  26066. prevent overflow during calculation.
  26067. Args:
  26068. row (``int``): number of rows in the 2-D matrix.
  26069. col (``int``): number of columns in the 2-D matrix.
  26070. offset (``int``): diagonal offset from the main diagonal.
  26071. Default: if not provided, 0.
  26072. Keyword args:
  26073. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor,
  26074. only support ``torch.int``, ``torch.long``. Default: if ``None``, ``torch.long``.
  26075. device (:class:`torch.device`, optional): the desired device of returned tensor.
  26076. Default: if ``None``, uses the current device for the default tensor type
  26077. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  26078. for CPU tensor types and the current CUDA device for CUDA tensor types.
  26079. layout (:class:`torch.layout`, optional): currently only support ``torch.strided``.
  26080. Example::
  26081. >>> a = torch.tril_indices(3, 3)
  26082. >>> a
  26083. tensor([[0, 1, 1, 2, 2, 2],
  26084. [0, 0, 1, 0, 1, 2]])
  26085. >>> a = torch.tril_indices(4, 3, -1)
  26086. >>> a
  26087. tensor([[1, 2, 2, 3, 3, 3],
  26088. [0, 0, 1, 0, 1, 2]])
  26089. >>> a = torch.tril_indices(4, 3, 1)
  26090. >>> a
  26091. tensor([[0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3],
  26092. [0, 1, 0, 1, 2, 0, 1, 2, 0, 1, 2]])
  26093. """
  26094. def triplet_margin_loss(
  26095. anchor: Tensor,
  26096. positive: Tensor,
  26097. negative: Tensor,
  26098. margin: _float = 1.0,
  26099. p: _float = 2,
  26100. eps: _float = 1e-06,
  26101. swap: _bool = False,
  26102. reduction: _int = 1,
  26103. ) -> Tensor: ...
  26104. def triu(
  26105. input: Tensor,
  26106. diagonal: _int | SymInt = 0,
  26107. *,
  26108. out: Tensor | None = None,
  26109. ) -> Tensor:
  26110. r"""
  26111. triu(input, diagonal=0, *, out=None) -> Tensor
  26112. Returns the upper triangular part of a matrix (2-D tensor) or batch of matrices
  26113. :attr:`input`, the other elements of the result tensor :attr:`out` are set to 0.
  26114. The upper triangular part of the matrix is defined as the elements on and
  26115. above the diagonal.
  26116. The argument :attr:`diagonal` controls which diagonal to consider. If
  26117. :attr:`diagonal` = 0, all elements on and above the main diagonal are
  26118. retained. A positive value excludes just as many diagonals above the main
  26119. diagonal, and similarly a negative value includes just as many diagonals below
  26120. the main diagonal. The main diagonal are the set of indices
  26121. :math:`\lbrace (i, i) \rbrace` for :math:`i \in [0, \min\{d_{1}, d_{2}\} - 1]` where
  26122. :math:`d_{1}, d_{2}` are the dimensions of the matrix.
  26123. Args:
  26124. input (Tensor): the input tensor.
  26125. diagonal (int, optional): the diagonal to consider
  26126. Keyword args:
  26127. out (Tensor, optional): the output tensor.
  26128. Example::
  26129. >>> a = torch.randn(3, 3)
  26130. >>> a
  26131. tensor([[ 0.2309, 0.5207, 2.0049],
  26132. [ 0.2072, -1.0680, 0.6602],
  26133. [ 0.3480, -0.5211, -0.4573]])
  26134. >>> torch.triu(a)
  26135. tensor([[ 0.2309, 0.5207, 2.0049],
  26136. [ 0.0000, -1.0680, 0.6602],
  26137. [ 0.0000, 0.0000, -0.4573]])
  26138. >>> torch.triu(a, diagonal=1)
  26139. tensor([[ 0.0000, 0.5207, 2.0049],
  26140. [ 0.0000, 0.0000, 0.6602],
  26141. [ 0.0000, 0.0000, 0.0000]])
  26142. >>> torch.triu(a, diagonal=-1)
  26143. tensor([[ 0.2309, 0.5207, 2.0049],
  26144. [ 0.2072, -1.0680, 0.6602],
  26145. [ 0.0000, -0.5211, -0.4573]])
  26146. >>> b = torch.randn(4, 6)
  26147. >>> b
  26148. tensor([[ 0.5876, -0.0794, -1.8373, 0.6654, 0.2604, 1.5235],
  26149. [-0.2447, 0.9556, -1.2919, 1.3378, -0.1768, -1.0857],
  26150. [ 0.4333, 0.3146, 0.6576, -1.0432, 0.9348, -0.4410],
  26151. [-0.9888, 1.0679, -1.3337, -1.6556, 0.4798, 0.2830]])
  26152. >>> torch.triu(b, diagonal=1)
  26153. tensor([[ 0.0000, -0.0794, -1.8373, 0.6654, 0.2604, 1.5235],
  26154. [ 0.0000, 0.0000, -1.2919, 1.3378, -0.1768, -1.0857],
  26155. [ 0.0000, 0.0000, 0.0000, -1.0432, 0.9348, -0.4410],
  26156. [ 0.0000, 0.0000, 0.0000, 0.0000, 0.4798, 0.2830]])
  26157. >>> torch.triu(b, diagonal=-1)
  26158. tensor([[ 0.5876, -0.0794, -1.8373, 0.6654, 0.2604, 1.5235],
  26159. [-0.2447, 0.9556, -1.2919, 1.3378, -0.1768, -1.0857],
  26160. [ 0.0000, 0.3146, 0.6576, -1.0432, 0.9348, -0.4410],
  26161. [ 0.0000, 0.0000, -1.3337, -1.6556, 0.4798, 0.2830]])
  26162. """
  26163. def triu_indices(
  26164. row: _int,
  26165. col: _int,
  26166. offset: _int = 0,
  26167. *,
  26168. dtype: _dtype | None = None,
  26169. layout: _layout | None = None,
  26170. device: DeviceLikeType | None = None,
  26171. pin_memory: _bool | None = False,
  26172. requires_grad: _bool | None = False,
  26173. ) -> Tensor:
  26174. r"""
  26175. triu_indices(row, col, offset=0, *, dtype=torch.long, device='cpu', layout=torch.strided) -> Tensor
  26176. Returns the indices of the upper triangular part of a :attr:`row` by
  26177. :attr:`col` matrix in a 2-by-N Tensor, where the first row contains row
  26178. coordinates of all indices and the second row contains column coordinates.
  26179. Indices are ordered based on rows and then columns.
  26180. The upper triangular part of the matrix is defined as the elements on and
  26181. above the diagonal.
  26182. The argument :attr:`offset` controls which diagonal to consider. If
  26183. :attr:`offset` = 0, all elements on and above the main diagonal are
  26184. retained. A positive value excludes just as many diagonals above the main
  26185. diagonal, and similarly a negative value includes just as many diagonals below
  26186. the main diagonal. The main diagonal are the set of indices
  26187. :math:`\lbrace (i, i) \rbrace` for :math:`i \in [0, \min\{d_{1}, d_{2}\} - 1]`
  26188. where :math:`d_{1}, d_{2}` are the dimensions of the matrix.
  26189. .. note::
  26190. When running on CUDA, ``row * col`` must be less than :math:`2^{59}` to
  26191. prevent overflow during calculation.
  26192. Args:
  26193. row (``int``): number of rows in the 2-D matrix.
  26194. col (``int``): number of columns in the 2-D matrix.
  26195. offset (``int``): diagonal offset from the main diagonal.
  26196. Default: if not provided, 0.
  26197. Keyword args:
  26198. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor,
  26199. only support ``torch.int``, ``torch.long``. Default: if ``None``, ``torch.long``.
  26200. device (:class:`torch.device`, optional): the desired device of returned tensor.
  26201. Default: if ``None``, uses the current device for the default tensor type
  26202. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  26203. for CPU tensor types and the current CUDA device for CUDA tensor types.
  26204. layout (:class:`torch.layout`, optional): currently only support ``torch.strided``.
  26205. Example::
  26206. >>> a = torch.triu_indices(3, 3)
  26207. >>> a
  26208. tensor([[0, 0, 0, 1, 1, 2],
  26209. [0, 1, 2, 1, 2, 2]])
  26210. >>> a = torch.triu_indices(4, 3, -1)
  26211. >>> a
  26212. tensor([[0, 0, 0, 1, 1, 1, 2, 2, 3],
  26213. [0, 1, 2, 0, 1, 2, 1, 2, 2]])
  26214. >>> a = torch.triu_indices(4, 3, 1)
  26215. >>> a
  26216. tensor([[0, 0, 1],
  26217. [1, 2, 2]])
  26218. """
  26219. def true_divide(
  26220. input: Tensor | Number,
  26221. other: Tensor | Number,
  26222. *,
  26223. out: Tensor | None = None,
  26224. ) -> Tensor:
  26225. r"""
  26226. true_divide(dividend, divisor, *, out) -> Tensor
  26227. Alias for :func:`torch.div` with ``rounding_mode=None``.
  26228. """
  26229. def trunc(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  26230. r"""
  26231. trunc(input, *, out=None) -> Tensor
  26232. Returns a new tensor with the truncated integer values of
  26233. the elements of :attr:`input`.
  26234. For integer inputs, follows the array-api convention of returning a
  26235. copy of the input tensor.
  26236. Args:
  26237. input (Tensor): the input tensor.
  26238. Keyword args:
  26239. out (Tensor, optional): the output tensor.
  26240. Example::
  26241. >>> a = torch.randn(4)
  26242. >>> a
  26243. tensor([ 3.4742, 0.5466, -0.8008, -0.9079])
  26244. >>> torch.trunc(a)
  26245. tensor([ 3., 0., -0., -0.])
  26246. """
  26247. def trunc_(input: Tensor) -> Tensor: ...
  26248. @overload
  26249. def unbind(input: Tensor, dim: _int = 0) -> tuple[Tensor, ...]:
  26250. r"""
  26251. unbind(input, dim=0) -> seq
  26252. Removes a tensor dimension.
  26253. Returns a tuple of all slices along a given dimension, already without it.
  26254. Arguments:
  26255. input (Tensor): the tensor to unbind
  26256. dim (int): dimension to remove
  26257. Example::
  26258. >>> torch.unbind(torch.tensor([[1, 2, 3],
  26259. >>> [4, 5, 6],
  26260. >>> [7, 8, 9]]))
  26261. (tensor([1, 2, 3]), tensor([4, 5, 6]), tensor([7, 8, 9]))
  26262. """
  26263. @overload
  26264. def unbind(
  26265. input: Tensor,
  26266. dim: str | EllipsisType | None,
  26267. ) -> tuple[Tensor, ...]:
  26268. r"""
  26269. unbind(input, dim=0) -> seq
  26270. Removes a tensor dimension.
  26271. Returns a tuple of all slices along a given dimension, already without it.
  26272. Arguments:
  26273. input (Tensor): the tensor to unbind
  26274. dim (int): dimension to remove
  26275. Example::
  26276. >>> torch.unbind(torch.tensor([[1, 2, 3],
  26277. >>> [4, 5, 6],
  26278. >>> [7, 8, 9]]))
  26279. (tensor([1, 2, 3]), tensor([4, 5, 6]), tensor([7, 8, 9]))
  26280. """
  26281. def unbind_copy(
  26282. input: Tensor,
  26283. dim: _int = 0,
  26284. *,
  26285. out: tuple[Tensor, ...] | list[Tensor] | None = None,
  26286. ) -> None:
  26287. r"""
  26288. Performs the same operation as :func:`torch.unbind`, but all output tensors
  26289. are freshly created instead of aliasing the input.
  26290. """
  26291. @overload
  26292. def unflatten(
  26293. input: Tensor,
  26294. dim: str | EllipsisType | None,
  26295. sizes: Sequence[_int | SymInt],
  26296. names: Sequence[str | EllipsisType | None],
  26297. ) -> Tensor:
  26298. r"""
  26299. unflatten(input, dim, sizes) -> Tensor
  26300. Expands a dimension of the input tensor over multiple dimensions.
  26301. .. seealso::
  26302. :func:`torch.flatten` the inverse of this function. It coalesces several dimensions into one.
  26303. Args:
  26304. input (Tensor): the input tensor.
  26305. dim (int): Dimension to be unflattened, specified as an index into
  26306. ``input.shape``.
  26307. sizes (Tuple[int]): New shape of the unflattened dimension.
  26308. One of its elements can be `-1` in which case the corresponding output
  26309. dimension is inferred. Otherwise, the product of ``sizes`` *must*
  26310. equal ``input.shape[dim]``.
  26311. Returns:
  26312. A View of input with the specified dimension unflattened.
  26313. Examples::
  26314. >>> torch.unflatten(torch.randn(3, 4, 1), 1, (2, 2)).shape
  26315. torch.Size([3, 2, 2, 1])
  26316. >>> torch.unflatten(torch.randn(3, 4, 1), 1, (-1, 2)).shape
  26317. torch.Size([3, 2, 2, 1])
  26318. >>> torch.unflatten(torch.randn(5, 12, 3), -2, (2, 2, 3, 1, 1)).shape
  26319. torch.Size([5, 2, 2, 3, 1, 1, 3])
  26320. """
  26321. @overload
  26322. def unflatten(
  26323. input: Tensor,
  26324. dim: _int,
  26325. sizes: Sequence[_int | SymInt],
  26326. ) -> Tensor:
  26327. r"""
  26328. unflatten(input, dim, sizes) -> Tensor
  26329. Expands a dimension of the input tensor over multiple dimensions.
  26330. .. seealso::
  26331. :func:`torch.flatten` the inverse of this function. It coalesces several dimensions into one.
  26332. Args:
  26333. input (Tensor): the input tensor.
  26334. dim (int): Dimension to be unflattened, specified as an index into
  26335. ``input.shape``.
  26336. sizes (Tuple[int]): New shape of the unflattened dimension.
  26337. One of its elements can be `-1` in which case the corresponding output
  26338. dimension is inferred. Otherwise, the product of ``sizes`` *must*
  26339. equal ``input.shape[dim]``.
  26340. Returns:
  26341. A View of input with the specified dimension unflattened.
  26342. Examples::
  26343. >>> torch.unflatten(torch.randn(3, 4, 1), 1, (2, 2)).shape
  26344. torch.Size([3, 2, 2, 1])
  26345. >>> torch.unflatten(torch.randn(3, 4, 1), 1, (-1, 2)).shape
  26346. torch.Size([3, 2, 2, 1])
  26347. >>> torch.unflatten(torch.randn(5, 12, 3), -2, (2, 2, 3, 1, 1)).shape
  26348. torch.Size([5, 2, 2, 3, 1, 1, 3])
  26349. """
  26350. def unfold_copy(
  26351. input: Tensor,
  26352. dimension: _int,
  26353. size: _int,
  26354. step: _int,
  26355. *,
  26356. out: Tensor | None = None,
  26357. ) -> Tensor:
  26358. r"""
  26359. Performs the same operation as :func:`torch.unfold`, but all output tensors
  26360. are freshly created instead of aliasing the input.
  26361. """
  26362. def unique_dim(
  26363. input: Tensor,
  26364. dim: _int,
  26365. sorted: _bool = True,
  26366. return_inverse: _bool = False,
  26367. return_counts: _bool = False,
  26368. ) -> tuple[Tensor, Tensor, Tensor]: ...
  26369. def unsafe_chunk(
  26370. input: Tensor,
  26371. chunks: _int,
  26372. dim: _int = 0,
  26373. ) -> tuple[Tensor, ...]:
  26374. r"""
  26375. unsafe_chunk(input, chunks, dim=0) -> List of Tensors
  26376. Works like :func:`torch.chunk` but without enforcing the autograd restrictions
  26377. on inplace modification of the outputs.
  26378. .. warning::
  26379. This function is safe to use as long as only the input, or only the outputs
  26380. are modified inplace after calling this function. It is user's
  26381. responsibility to ensure that is the case. If both the input and one or more
  26382. of the outputs are modified inplace, gradients computed by autograd will be
  26383. silently incorrect.
  26384. """
  26385. def unsafe_split(
  26386. input: Tensor,
  26387. split_size: _int | SymInt,
  26388. dim: _int = 0,
  26389. ) -> tuple[Tensor, ...]:
  26390. r"""
  26391. unsafe_split(tensor, split_size_or_sections, dim=0) -> List of Tensors
  26392. Works like :func:`torch.split` but without enforcing the autograd restrictions
  26393. on inplace modification of the outputs.
  26394. .. warning::
  26395. This function is safe to use as long as only the input, or only the outputs
  26396. are modified inplace after calling this function. It is user's
  26397. responsibility to ensure that is the case. If both the input and one or more
  26398. of the outputs are modified inplace, gradients computed by autograd will be
  26399. silently incorrect.
  26400. """
  26401. def unsafe_split_with_sizes(
  26402. input: Tensor,
  26403. split_sizes: Sequence[_int | SymInt],
  26404. dim: _int = 0,
  26405. ) -> tuple[Tensor, ...]: ...
  26406. def unsqueeze(input: Tensor, dim: _int) -> Tensor:
  26407. r"""
  26408. unsqueeze(input, dim) -> Tensor
  26409. Returns a new tensor with a dimension of size one inserted at the
  26410. specified position.
  26411. The returned tensor shares the same underlying data with this tensor.
  26412. A :attr:`dim` value within the range ``[-input.dim() - 1, input.dim() + 1)``
  26413. can be used. Negative :attr:`dim` will correspond to :meth:`unsqueeze`
  26414. applied at :attr:`dim` = ``dim + input.dim() + 1``.
  26415. Args:
  26416. input (Tensor): the input tensor.
  26417. dim (int): the index at which to insert the singleton dimension
  26418. Example::
  26419. >>> x = torch.tensor([1, 2, 3, 4])
  26420. >>> torch.unsqueeze(x, 0)
  26421. tensor([[ 1, 2, 3, 4]])
  26422. >>> torch.unsqueeze(x, 1)
  26423. tensor([[ 1],
  26424. [ 2],
  26425. [ 3],
  26426. [ 4]])
  26427. """
  26428. def unsqueeze_copy(
  26429. input: Tensor,
  26430. dim: _int,
  26431. *,
  26432. out: Tensor | None = None,
  26433. ) -> Tensor:
  26434. r"""
  26435. Performs the same operation as :func:`torch.unsqueeze`, but all output tensors
  26436. are freshly created instead of aliasing the input.
  26437. """
  26438. def values_copy(input: Tensor, *, out: Tensor | None = None) -> Tensor:
  26439. r"""
  26440. Performs the same operation as :func:`torch.values`, but all output tensors
  26441. are freshly created instead of aliasing the input.
  26442. """
  26443. def vander(
  26444. x: Tensor,
  26445. N: _int | None = None,
  26446. increasing: _bool = False,
  26447. ) -> Tensor:
  26448. r"""
  26449. vander(x, N=None, increasing=False) -> Tensor
  26450. Generates a Vandermonde matrix.
  26451. The columns of the output matrix are elementwise powers of the input vector :math:`x^{(N-1)}, x^{(N-2)}, ..., x^0`.
  26452. If increasing is True, the order of the columns is reversed :math:`x^0, x^1, ..., x^{(N-1)}`. Such a
  26453. matrix with a geometric progression in each row is named for Alexandre-Theophile Vandermonde.
  26454. Arguments:
  26455. x (Tensor): 1-D input tensor.
  26456. N (int, optional): Number of columns in the output. If N is not specified,
  26457. a square array is returned :math:`(N = len(x))`.
  26458. increasing (bool, optional): Order of the powers of the columns. If True,
  26459. the powers increase from left to right, if False (the default) they are reversed.
  26460. Returns:
  26461. Tensor: Vandermonde matrix. If increasing is False, the first column is :math:`x^{(N-1)}`,
  26462. the second :math:`x^{(N-2)}` and so forth. If increasing is True, the columns
  26463. are :math:`x^0, x^1, ..., x^{(N-1)}`.
  26464. Example::
  26465. >>> x = torch.tensor([1, 2, 3, 5])
  26466. >>> torch.vander(x)
  26467. tensor([[ 1, 1, 1, 1],
  26468. [ 8, 4, 2, 1],
  26469. [ 27, 9, 3, 1],
  26470. [125, 25, 5, 1]])
  26471. >>> torch.vander(x, N=3)
  26472. tensor([[ 1, 1, 1],
  26473. [ 4, 2, 1],
  26474. [ 9, 3, 1],
  26475. [25, 5, 1]])
  26476. >>> torch.vander(x, N=3, increasing=True)
  26477. tensor([[ 1, 1, 1],
  26478. [ 1, 2, 4],
  26479. [ 1, 3, 9],
  26480. [ 1, 5, 25]])
  26481. """
  26482. @overload
  26483. def var(
  26484. input: Tensor,
  26485. dim: _int | _size | None,
  26486. unbiased: _bool = True,
  26487. keepdim: _bool = False,
  26488. *,
  26489. out: Tensor | None = None,
  26490. ) -> Tensor:
  26491. r"""
  26492. var(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  26493. Calculates the variance over the dimensions specified by :attr:`dim`. :attr:`dim`
  26494. can be a single dimension, list of dimensions, or ``None`` to reduce over all
  26495. dimensions.
  26496. The variance (:math:`\sigma^2`) is calculated as
  26497. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26498. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26499. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26500. the :attr:`correction`.
  26501. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26502. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26503. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26504. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26505. Args:
  26506. input (Tensor): the input tensor.
  26507. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26508. If ``None``, all dimensions are reduced.
  26509. Keyword args:
  26510. correction (int): difference between the sample size and sample degrees of freedom.
  26511. Defaults to `Bessel's correction`_, ``correction=1``.
  26512. .. versionchanged:: 2.0
  26513. Previously this argument was called ``unbiased`` and was a boolean
  26514. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26515. ``correction=0``.
  26516. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26517. out (Tensor, optional): the output tensor.
  26518. Example:
  26519. >>> a = torch.tensor(
  26520. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26521. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26522. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26523. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26524. ... ) # fmt: skip
  26525. >>> torch.var(a, dim=1, keepdim=True)
  26526. tensor([[1.0631],
  26527. [0.5590],
  26528. [1.4893],
  26529. [0.8258]])
  26530. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26531. """
  26532. @overload
  26533. def var(
  26534. input: Tensor,
  26535. dim: _int | _size | None = None,
  26536. *,
  26537. correction: Number | _complex | None = None,
  26538. keepdim: _bool = False,
  26539. out: Tensor | None = None,
  26540. ) -> Tensor:
  26541. r"""
  26542. var(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  26543. Calculates the variance over the dimensions specified by :attr:`dim`. :attr:`dim`
  26544. can be a single dimension, list of dimensions, or ``None`` to reduce over all
  26545. dimensions.
  26546. The variance (:math:`\sigma^2`) is calculated as
  26547. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26548. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26549. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26550. the :attr:`correction`.
  26551. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26552. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26553. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26554. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26555. Args:
  26556. input (Tensor): the input tensor.
  26557. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26558. If ``None``, all dimensions are reduced.
  26559. Keyword args:
  26560. correction (int): difference between the sample size and sample degrees of freedom.
  26561. Defaults to `Bessel's correction`_, ``correction=1``.
  26562. .. versionchanged:: 2.0
  26563. Previously this argument was called ``unbiased`` and was a boolean
  26564. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26565. ``correction=0``.
  26566. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26567. out (Tensor, optional): the output tensor.
  26568. Example:
  26569. >>> a = torch.tensor(
  26570. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26571. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26572. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26573. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26574. ... ) # fmt: skip
  26575. >>> torch.var(a, dim=1, keepdim=True)
  26576. tensor([[1.0631],
  26577. [0.5590],
  26578. [1.4893],
  26579. [0.8258]])
  26580. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26581. """
  26582. @overload
  26583. def var(input: Tensor, unbiased: _bool = True) -> Tensor:
  26584. r"""
  26585. var(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  26586. Calculates the variance over the dimensions specified by :attr:`dim`. :attr:`dim`
  26587. can be a single dimension, list of dimensions, or ``None`` to reduce over all
  26588. dimensions.
  26589. The variance (:math:`\sigma^2`) is calculated as
  26590. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26591. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26592. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26593. the :attr:`correction`.
  26594. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26595. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26596. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26597. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26598. Args:
  26599. input (Tensor): the input tensor.
  26600. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26601. If ``None``, all dimensions are reduced.
  26602. Keyword args:
  26603. correction (int): difference between the sample size and sample degrees of freedom.
  26604. Defaults to `Bessel's correction`_, ``correction=1``.
  26605. .. versionchanged:: 2.0
  26606. Previously this argument was called ``unbiased`` and was a boolean
  26607. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26608. ``correction=0``.
  26609. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26610. out (Tensor, optional): the output tensor.
  26611. Example:
  26612. >>> a = torch.tensor(
  26613. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26614. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26615. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26616. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26617. ... ) # fmt: skip
  26618. >>> torch.var(a, dim=1, keepdim=True)
  26619. tensor([[1.0631],
  26620. [0.5590],
  26621. [1.4893],
  26622. [0.8258]])
  26623. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26624. """
  26625. @overload
  26626. def var(
  26627. input: Tensor,
  26628. dim: Sequence[str | EllipsisType | None],
  26629. *,
  26630. correction: Number | _complex | None = None,
  26631. keepdim: _bool = False,
  26632. out: Tensor | None = None,
  26633. ) -> Tensor:
  26634. r"""
  26635. var(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  26636. Calculates the variance over the dimensions specified by :attr:`dim`. :attr:`dim`
  26637. can be a single dimension, list of dimensions, or ``None`` to reduce over all
  26638. dimensions.
  26639. The variance (:math:`\sigma^2`) is calculated as
  26640. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26641. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26642. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26643. the :attr:`correction`.
  26644. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26645. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26646. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26647. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26648. Args:
  26649. input (Tensor): the input tensor.
  26650. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26651. If ``None``, all dimensions are reduced.
  26652. Keyword args:
  26653. correction (int): difference between the sample size and sample degrees of freedom.
  26654. Defaults to `Bessel's correction`_, ``correction=1``.
  26655. .. versionchanged:: 2.0
  26656. Previously this argument was called ``unbiased`` and was a boolean
  26657. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26658. ``correction=0``.
  26659. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26660. out (Tensor, optional): the output tensor.
  26661. Example:
  26662. >>> a = torch.tensor(
  26663. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26664. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26665. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26666. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26667. ... ) # fmt: skip
  26668. >>> torch.var(a, dim=1, keepdim=True)
  26669. tensor([[1.0631],
  26670. [0.5590],
  26671. [1.4893],
  26672. [0.8258]])
  26673. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26674. """
  26675. @overload
  26676. def var(
  26677. input: Tensor,
  26678. dim: Sequence[str | EllipsisType | None],
  26679. unbiased: _bool = True,
  26680. keepdim: _bool = False,
  26681. *,
  26682. out: Tensor | None = None,
  26683. ) -> Tensor:
  26684. r"""
  26685. var(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
  26686. Calculates the variance over the dimensions specified by :attr:`dim`. :attr:`dim`
  26687. can be a single dimension, list of dimensions, or ``None`` to reduce over all
  26688. dimensions.
  26689. The variance (:math:`\sigma^2`) is calculated as
  26690. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26691. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26692. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26693. the :attr:`correction`.
  26694. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26695. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26696. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26697. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26698. Args:
  26699. input (Tensor): the input tensor.
  26700. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26701. If ``None``, all dimensions are reduced.
  26702. Keyword args:
  26703. correction (int): difference between the sample size and sample degrees of freedom.
  26704. Defaults to `Bessel's correction`_, ``correction=1``.
  26705. .. versionchanged:: 2.0
  26706. Previously this argument was called ``unbiased`` and was a boolean
  26707. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26708. ``correction=0``.
  26709. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26710. out (Tensor, optional): the output tensor.
  26711. Example:
  26712. >>> a = torch.tensor(
  26713. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26714. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26715. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26716. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26717. ... ) # fmt: skip
  26718. >>> torch.var(a, dim=1, keepdim=True)
  26719. tensor([[1.0631],
  26720. [0.5590],
  26721. [1.4893],
  26722. [0.8258]])
  26723. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26724. """
  26725. @overload
  26726. def var_mean(
  26727. input: Tensor,
  26728. dim: _int | _size | None,
  26729. unbiased: _bool = True,
  26730. keepdim: _bool = False,
  26731. ) -> tuple[Tensor, Tensor]:
  26732. r"""
  26733. var_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  26734. Calculates the variance and mean over the dimensions specified by :attr:`dim`.
  26735. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  26736. reduce over all dimensions.
  26737. The variance (:math:`\sigma^2`) is calculated as
  26738. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26739. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26740. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26741. the :attr:`correction`.
  26742. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26743. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26744. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26745. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26746. Args:
  26747. input (Tensor): the input tensor.
  26748. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26749. If ``None``, all dimensions are reduced.
  26750. Keyword args:
  26751. correction (int): difference between the sample size and sample degrees of freedom.
  26752. Defaults to `Bessel's correction`_, ``correction=1``.
  26753. .. versionchanged:: 2.0
  26754. Previously this argument was called ``unbiased`` and was a boolean
  26755. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26756. ``correction=0``.
  26757. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26758. out (Tensor, optional): the output tensor.
  26759. Returns:
  26760. A tuple (var, mean) containing the variance and mean.
  26761. Example:
  26762. >>> a = torch.tensor(
  26763. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26764. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26765. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26766. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26767. ... ) # fmt: skip
  26768. >>> torch.var_mean(a, dim=0, keepdim=True)
  26769. (tensor([[1.5926, 1.0056, 1.2005, 0.3646]]),
  26770. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  26771. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26772. """
  26773. @overload
  26774. def var_mean(
  26775. input: Tensor,
  26776. dim: _int | _size | None = None,
  26777. *,
  26778. correction: Number | _complex | None = None,
  26779. keepdim: _bool = False,
  26780. ) -> tuple[Tensor, Tensor]:
  26781. r"""
  26782. var_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  26783. Calculates the variance and mean over the dimensions specified by :attr:`dim`.
  26784. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  26785. reduce over all dimensions.
  26786. The variance (:math:`\sigma^2`) is calculated as
  26787. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26788. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26789. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26790. the :attr:`correction`.
  26791. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26792. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26793. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26794. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26795. Args:
  26796. input (Tensor): the input tensor.
  26797. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26798. If ``None``, all dimensions are reduced.
  26799. Keyword args:
  26800. correction (int): difference between the sample size and sample degrees of freedom.
  26801. Defaults to `Bessel's correction`_, ``correction=1``.
  26802. .. versionchanged:: 2.0
  26803. Previously this argument was called ``unbiased`` and was a boolean
  26804. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26805. ``correction=0``.
  26806. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26807. out (Tensor, optional): the output tensor.
  26808. Returns:
  26809. A tuple (var, mean) containing the variance and mean.
  26810. Example:
  26811. >>> a = torch.tensor(
  26812. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26813. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26814. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26815. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26816. ... ) # fmt: skip
  26817. >>> torch.var_mean(a, dim=0, keepdim=True)
  26818. (tensor([[1.5926, 1.0056, 1.2005, 0.3646]]),
  26819. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  26820. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26821. """
  26822. @overload
  26823. def var_mean(
  26824. input: Tensor,
  26825. unbiased: _bool = True,
  26826. ) -> tuple[Tensor, Tensor]:
  26827. r"""
  26828. var_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  26829. Calculates the variance and mean over the dimensions specified by :attr:`dim`.
  26830. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  26831. reduce over all dimensions.
  26832. The variance (:math:`\sigma^2`) is calculated as
  26833. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26834. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26835. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26836. the :attr:`correction`.
  26837. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26838. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26839. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26840. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26841. Args:
  26842. input (Tensor): the input tensor.
  26843. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26844. If ``None``, all dimensions are reduced.
  26845. Keyword args:
  26846. correction (int): difference between the sample size and sample degrees of freedom.
  26847. Defaults to `Bessel's correction`_, ``correction=1``.
  26848. .. versionchanged:: 2.0
  26849. Previously this argument was called ``unbiased`` and was a boolean
  26850. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26851. ``correction=0``.
  26852. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26853. out (Tensor, optional): the output tensor.
  26854. Returns:
  26855. A tuple (var, mean) containing the variance and mean.
  26856. Example:
  26857. >>> a = torch.tensor(
  26858. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26859. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26860. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26861. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26862. ... ) # fmt: skip
  26863. >>> torch.var_mean(a, dim=0, keepdim=True)
  26864. (tensor([[1.5926, 1.0056, 1.2005, 0.3646]]),
  26865. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  26866. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26867. """
  26868. @overload
  26869. def var_mean(
  26870. input: Tensor,
  26871. dim: Sequence[str | EllipsisType | None],
  26872. *,
  26873. correction: Number | _complex | None = None,
  26874. keepdim: _bool = False,
  26875. ) -> tuple[Tensor, Tensor]:
  26876. r"""
  26877. var_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  26878. Calculates the variance and mean over the dimensions specified by :attr:`dim`.
  26879. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  26880. reduce over all dimensions.
  26881. The variance (:math:`\sigma^2`) is calculated as
  26882. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26883. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26884. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26885. the :attr:`correction`.
  26886. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26887. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26888. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26889. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26890. Args:
  26891. input (Tensor): the input tensor.
  26892. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26893. If ``None``, all dimensions are reduced.
  26894. Keyword args:
  26895. correction (int): difference between the sample size and sample degrees of freedom.
  26896. Defaults to `Bessel's correction`_, ``correction=1``.
  26897. .. versionchanged:: 2.0
  26898. Previously this argument was called ``unbiased`` and was a boolean
  26899. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26900. ``correction=0``.
  26901. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26902. out (Tensor, optional): the output tensor.
  26903. Returns:
  26904. A tuple (var, mean) containing the variance and mean.
  26905. Example:
  26906. >>> a = torch.tensor(
  26907. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26908. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26909. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26910. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26911. ... ) # fmt: skip
  26912. >>> torch.var_mean(a, dim=0, keepdim=True)
  26913. (tensor([[1.5926, 1.0056, 1.2005, 0.3646]]),
  26914. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  26915. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26916. """
  26917. @overload
  26918. def var_mean(
  26919. input: Tensor,
  26920. dim: Sequence[str | EllipsisType | None],
  26921. unbiased: _bool = True,
  26922. keepdim: _bool = False,
  26923. ) -> tuple[Tensor, Tensor]:
  26924. r"""
  26925. var_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
  26926. Calculates the variance and mean over the dimensions specified by :attr:`dim`.
  26927. :attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
  26928. reduce over all dimensions.
  26929. The variance (:math:`\sigma^2`) is calculated as
  26930. .. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
  26931. where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
  26932. sample mean, :math:`N` is the number of samples and :math:`\delta N` is
  26933. the :attr:`correction`.
  26934. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  26935. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
  26936. Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
  26937. output tensor having 1 (or ``len(dim)``) fewer dimension(s).
  26938. Args:
  26939. input (Tensor): the input tensor.
  26940. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  26941. If ``None``, all dimensions are reduced.
  26942. Keyword args:
  26943. correction (int): difference between the sample size and sample degrees of freedom.
  26944. Defaults to `Bessel's correction`_, ``correction=1``.
  26945. .. versionchanged:: 2.0
  26946. Previously this argument was called ``unbiased`` and was a boolean
  26947. with ``True`` corresponding to ``correction=1`` and ``False`` being
  26948. ``correction=0``.
  26949. keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
  26950. out (Tensor, optional): the output tensor.
  26951. Returns:
  26952. A tuple (var, mean) containing the variance and mean.
  26953. Example:
  26954. >>> a = torch.tensor(
  26955. ... [[ 0.2035, 1.2959, 1.8101, -0.4644],
  26956. ... [ 1.5027, -0.3270, 0.5905, 0.6538],
  26957. ... [-1.5745, 1.3330, -0.5596, -0.6548],
  26958. ... [ 0.1264, -0.5080, 1.6420, 0.1992]]
  26959. ... ) # fmt: skip
  26960. >>> torch.var_mean(a, dim=0, keepdim=True)
  26961. (tensor([[1.5926, 1.0056, 1.2005, 0.3646]]),
  26962. tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
  26963. .. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
  26964. """
  26965. def vdot(
  26966. input: Tensor,
  26967. other: Tensor,
  26968. *,
  26969. out: Tensor | None = None,
  26970. ) -> Tensor:
  26971. r"""
  26972. vdot(input, other, *, out=None) -> Tensor
  26973. Computes the dot product of two 1D vectors along a dimension.
  26974. In symbols, this function computes
  26975. .. math::
  26976. \sum_{i=1}^n \overline{x_i}y_i.
  26977. where :math:`\overline{x_i}` denotes the conjugate for complex
  26978. vectors, and it is the identity for real vectors.
  26979. .. note::
  26980. Unlike NumPy's vdot, torch.vdot intentionally only supports computing the dot product
  26981. of two 1D tensors with the same number of elements.
  26982. .. seealso::
  26983. :func:`torch.linalg.vecdot` computes the dot product of two batches of vectors along a dimension.
  26984. Args:
  26985. input (Tensor): first tensor in the dot product, must be 1D. Its conjugate is used if it's complex.
  26986. other (Tensor): second tensor in the dot product, must be 1D.
  26987. Keyword args:
  26988. .. note:: out (Tensor, optional): the output tensor.
  26989. Example::
  26990. >>> torch.vdot(torch.tensor([2, 3]), torch.tensor([2, 1]))
  26991. tensor(7)
  26992. >>> a = torch.tensor((1 +2j, 3 - 1j))
  26993. >>> b = torch.tensor((2 +1j, 4 - 0j))
  26994. >>> torch.vdot(a, b)
  26995. tensor([16.+1.j])
  26996. >>> torch.vdot(b, a)
  26997. tensor([16.-1.j])
  26998. """
  26999. def view_as_complex(input: Tensor) -> Tensor:
  27000. r"""
  27001. view_as_complex(input) -> Tensor
  27002. Returns a view of :attr:`input` as a complex tensor. For an input complex
  27003. tensor of :attr:`size` :math:`m1, m2, \dots, mi, 2`, this function returns a
  27004. new complex tensor of :attr:`size` :math:`m1, m2, \dots, mi` where the last
  27005. dimension of the input tensor is expected to represent the real and imaginary
  27006. components of complex numbers.
  27007. .. warning::
  27008. :func:`view_as_complex` is only supported for tensors with
  27009. :class:`torch.dtype` ``torch.float64`` and ``torch.float32``. The input is
  27010. expected to have the last dimension of :attr:`size` 2. In addition, the
  27011. tensor must have a `stride` of 1 for its last dimension. The strides of all
  27012. other dimensions must be even numbers.
  27013. Args:
  27014. input (Tensor): the input tensor.
  27015. Example::
  27016. >>> x=torch.randn(4, 2)
  27017. >>> x
  27018. tensor([[ 1.6116, -0.5772],
  27019. [-1.4606, -0.9120],
  27020. [ 0.0786, -1.7497],
  27021. [-0.6561, -1.6623]])
  27022. >>> torch.view_as_complex(x)
  27023. tensor([(1.6116-0.5772j), (-1.4606-0.9120j), (0.0786-1.7497j), (-0.6561-1.6623j)])
  27024. """
  27025. def view_as_complex_copy(
  27026. input: Tensor,
  27027. *,
  27028. out: Tensor | None = None,
  27029. ) -> Tensor:
  27030. r"""
  27031. Performs the same operation as :func:`torch.view_as_complex`, but all output tensors
  27032. are freshly created instead of aliasing the input.
  27033. """
  27034. def view_as_real(input: Tensor) -> Tensor:
  27035. r"""
  27036. view_as_real(input) -> Tensor
  27037. Returns a view of :attr:`input` as a real tensor. For an input complex tensor of
  27038. :attr:`size` :math:`m1, m2, \dots, mi`, this function returns a new
  27039. real tensor of size :math:`m1, m2, \dots, mi, 2`, where the last dimension of size 2
  27040. represents the real and imaginary components of complex numbers.
  27041. .. warning::
  27042. :func:`view_as_real` is only supported for tensors with ``complex dtypes``.
  27043. Args:
  27044. input (Tensor): the input tensor.
  27045. Example::
  27046. >>> x=torch.randn(4, dtype=torch.cfloat)
  27047. >>> x
  27048. tensor([(0.4737-0.3839j), (-0.2098-0.6699j), (0.3470-0.9451j), (-0.5174-1.3136j)])
  27049. >>> torch.view_as_real(x)
  27050. tensor([[ 0.4737, -0.3839],
  27051. [-0.2098, -0.6699],
  27052. [ 0.3470, -0.9451],
  27053. [-0.5174, -1.3136]])
  27054. """
  27055. def view_as_real_copy(
  27056. input: Tensor,
  27057. *,
  27058. out: Tensor | None = None,
  27059. ) -> Tensor:
  27060. r"""
  27061. Performs the same operation as :func:`torch.view_as_real`, but all output tensors
  27062. are freshly created instead of aliasing the input.
  27063. """
  27064. @overload
  27065. def view_copy(
  27066. input: Tensor,
  27067. dtype: _dtype,
  27068. *,
  27069. out: Tensor | None = None,
  27070. ) -> Tensor:
  27071. r"""
  27072. Performs the same operation as :func:`torch.view`, but all output tensors
  27073. are freshly created instead of aliasing the input.
  27074. """
  27075. @overload
  27076. def view_copy(
  27077. input: Tensor,
  27078. size: Sequence[_int | SymInt],
  27079. *,
  27080. out: Tensor | None = None,
  27081. ) -> Tensor:
  27082. r"""
  27083. Performs the same operation as :func:`torch.view`, but all output tensors
  27084. are freshly created instead of aliasing the input.
  27085. """
  27086. @overload
  27087. def vsplit(input: Tensor, sections: _int) -> tuple[Tensor, ...]:
  27088. r"""
  27089. vsplit(input, indices_or_sections) -> List of Tensors
  27090. Splits :attr:`input`, a tensor with two or more dimensions, into multiple tensors
  27091. vertically according to :attr:`indices_or_sections`. Each split is a view of
  27092. :attr:`input`.
  27093. This is equivalent to calling torch.tensor_split(input, indices_or_sections, dim=0)
  27094. (the split dimension is 0), except that if :attr:`indices_or_sections` is an integer
  27095. it must evenly divide the split dimension or a runtime error will be thrown.
  27096. This function is based on NumPy's :func:`numpy.vsplit`.
  27097. Args:
  27098. input (Tensor): tensor to split.
  27099. indices_or_sections (int or list or tuple of ints): See argument in :func:`torch.tensor_split`.
  27100. Example::
  27101. >>> t = torch.arange(16.0).reshape(4,4)
  27102. >>> t
  27103. tensor([[ 0., 1., 2., 3.],
  27104. [ 4., 5., 6., 7.],
  27105. [ 8., 9., 10., 11.],
  27106. [12., 13., 14., 15.]])
  27107. >>> torch.vsplit(t, 2)
  27108. (tensor([[0., 1., 2., 3.],
  27109. [4., 5., 6., 7.]]),
  27110. tensor([[ 8., 9., 10., 11.],
  27111. [12., 13., 14., 15.]]))
  27112. >>> torch.vsplit(t, [3, 6])
  27113. (tensor([[ 0., 1., 2., 3.],
  27114. [ 4., 5., 6., 7.],
  27115. [ 8., 9., 10., 11.]]),
  27116. tensor([[12., 13., 14., 15.]]),
  27117. tensor([], size=(0, 4)))
  27118. """
  27119. @overload
  27120. def vsplit(input: Tensor, indices: _size) -> tuple[Tensor, ...]:
  27121. r"""
  27122. vsplit(input, indices_or_sections) -> List of Tensors
  27123. Splits :attr:`input`, a tensor with two or more dimensions, into multiple tensors
  27124. vertically according to :attr:`indices_or_sections`. Each split is a view of
  27125. :attr:`input`.
  27126. This is equivalent to calling torch.tensor_split(input, indices_or_sections, dim=0)
  27127. (the split dimension is 0), except that if :attr:`indices_or_sections` is an integer
  27128. it must evenly divide the split dimension or a runtime error will be thrown.
  27129. This function is based on NumPy's :func:`numpy.vsplit`.
  27130. Args:
  27131. input (Tensor): tensor to split.
  27132. indices_or_sections (int or list or tuple of ints): See argument in :func:`torch.tensor_split`.
  27133. Example::
  27134. >>> t = torch.arange(16.0).reshape(4,4)
  27135. >>> t
  27136. tensor([[ 0., 1., 2., 3.],
  27137. [ 4., 5., 6., 7.],
  27138. [ 8., 9., 10., 11.],
  27139. [12., 13., 14., 15.]])
  27140. >>> torch.vsplit(t, 2)
  27141. (tensor([[0., 1., 2., 3.],
  27142. [4., 5., 6., 7.]]),
  27143. tensor([[ 8., 9., 10., 11.],
  27144. [12., 13., 14., 15.]]))
  27145. >>> torch.vsplit(t, [3, 6])
  27146. (tensor([[ 0., 1., 2., 3.],
  27147. [ 4., 5., 6., 7.],
  27148. [ 8., 9., 10., 11.]]),
  27149. tensor([[12., 13., 14., 15.]]),
  27150. tensor([], size=(0, 4)))
  27151. """
  27152. def vstack(
  27153. tensors: tuple[Tensor, ...] | list[Tensor] | None,
  27154. *,
  27155. out: Tensor | None = None,
  27156. ) -> Tensor:
  27157. r"""
  27158. vstack(tensors, *, out=None) -> Tensor
  27159. Stack tensors in sequence vertically (row wise).
  27160. This is equivalent to concatenation along the first axis after all 1-D tensors have been reshaped by :func:`torch.atleast_2d`.
  27161. Args:
  27162. tensors (sequence of Tensors): sequence of tensors to concatenate
  27163. Keyword args:
  27164. out (Tensor, optional): the output tensor.
  27165. Example::
  27166. >>> a = torch.tensor([1, 2, 3])
  27167. >>> b = torch.tensor([4, 5, 6])
  27168. >>> torch.vstack((a,b))
  27169. tensor([[1, 2, 3],
  27170. [4, 5, 6]])
  27171. >>> a = torch.tensor([[1],[2],[3]])
  27172. >>> b = torch.tensor([[4],[5],[6]])
  27173. >>> torch.vstack((a,b))
  27174. tensor([[1],
  27175. [2],
  27176. [3],
  27177. [4],
  27178. [5],
  27179. [6]])
  27180. """
  27181. @overload
  27182. def where(condition: Tensor) -> tuple[Tensor, ...]:
  27183. r"""
  27184. where(condition, input, other, *, out=None) -> Tensor
  27185. Return a tensor of elements selected from either :attr:`input` or :attr:`other`, depending on :attr:`condition`.
  27186. The operation is defined as:
  27187. .. math::
  27188. \text{out}_i = \begin{cases}
  27189. \text{input}_i & \text{if } \text{condition}_i \\
  27190. \text{other}_i & \text{otherwise} \\
  27191. \end{cases}
  27192. .. note::
  27193. The tensors :attr:`condition`, :attr:`input`, :attr:`other` must be :ref:`broadcastable <broadcasting-semantics>`.
  27194. Arguments:
  27195. condition (BoolTensor): When True (nonzero), yield input, otherwise yield other
  27196. input (Tensor or Scalar): value (if :attr:`input` is a scalar) or values selected at indices
  27197. where :attr:`condition` is ``True``
  27198. other (Tensor or Scalar): value (if :attr:`other` is a scalar) or values selected at indices
  27199. where :attr:`condition` is ``False``
  27200. Keyword args:
  27201. out (Tensor, optional): the output tensor.
  27202. Returns:
  27203. Tensor: A tensor of shape equal to the broadcasted shape of :attr:`condition`, :attr:`input`, :attr:`other`
  27204. Example::
  27205. >>> x = torch.randn(3, 2)
  27206. >>> y = torch.ones(3, 2)
  27207. >>> x
  27208. tensor([[-0.4620, 0.3139],
  27209. [ 0.3898, -0.7197],
  27210. [ 0.0478, -0.1657]])
  27211. >>> torch.where(x > 0, 1.0, 0.0)
  27212. tensor([[0., 1.],
  27213. [1., 0.],
  27214. [1., 0.]])
  27215. >>> torch.where(x > 0, x, y)
  27216. tensor([[ 1.0000, 0.3139],
  27217. [ 0.3898, 1.0000],
  27218. [ 0.0478, 1.0000]])
  27219. >>> x = torch.randn(2, 2, dtype=torch.double)
  27220. >>> x
  27221. tensor([[ 1.0779, 0.0383],
  27222. [-0.8785, -1.1089]], dtype=torch.float64)
  27223. >>> torch.where(x > 0, x, 0.)
  27224. tensor([[1.0779, 0.0383],
  27225. [0.0000, 0.0000]], dtype=torch.float64)
  27226. .. function:: where(condition) -> tuple of LongTensor
  27227. :noindex:
  27228. ``torch.where(condition)`` is identical to
  27229. ``torch.nonzero(condition, as_tuple=True)``.
  27230. .. note::
  27231. See also :func:`torch.nonzero`.
  27232. """
  27233. @overload
  27234. def where(
  27235. condition: Tensor,
  27236. input: Tensor,
  27237. other: Tensor,
  27238. *,
  27239. out: Tensor | None = None,
  27240. ) -> Tensor:
  27241. r"""
  27242. where(condition, input, other, *, out=None) -> Tensor
  27243. Return a tensor of elements selected from either :attr:`input` or :attr:`other`, depending on :attr:`condition`.
  27244. The operation is defined as:
  27245. .. math::
  27246. \text{out}_i = \begin{cases}
  27247. \text{input}_i & \text{if } \text{condition}_i \\
  27248. \text{other}_i & \text{otherwise} \\
  27249. \end{cases}
  27250. .. note::
  27251. The tensors :attr:`condition`, :attr:`input`, :attr:`other` must be :ref:`broadcastable <broadcasting-semantics>`.
  27252. Arguments:
  27253. condition (BoolTensor): When True (nonzero), yield input, otherwise yield other
  27254. input (Tensor or Scalar): value (if :attr:`input` is a scalar) or values selected at indices
  27255. where :attr:`condition` is ``True``
  27256. other (Tensor or Scalar): value (if :attr:`other` is a scalar) or values selected at indices
  27257. where :attr:`condition` is ``False``
  27258. Keyword args:
  27259. out (Tensor, optional): the output tensor.
  27260. Returns:
  27261. Tensor: A tensor of shape equal to the broadcasted shape of :attr:`condition`, :attr:`input`, :attr:`other`
  27262. Example::
  27263. >>> x = torch.randn(3, 2)
  27264. >>> y = torch.ones(3, 2)
  27265. >>> x
  27266. tensor([[-0.4620, 0.3139],
  27267. [ 0.3898, -0.7197],
  27268. [ 0.0478, -0.1657]])
  27269. >>> torch.where(x > 0, 1.0, 0.0)
  27270. tensor([[0., 1.],
  27271. [1., 0.],
  27272. [1., 0.]])
  27273. >>> torch.where(x > 0, x, y)
  27274. tensor([[ 1.0000, 0.3139],
  27275. [ 0.3898, 1.0000],
  27276. [ 0.0478, 1.0000]])
  27277. >>> x = torch.randn(2, 2, dtype=torch.double)
  27278. >>> x
  27279. tensor([[ 1.0779, 0.0383],
  27280. [-0.8785, -1.1089]], dtype=torch.float64)
  27281. >>> torch.where(x > 0, x, 0.)
  27282. tensor([[1.0779, 0.0383],
  27283. [0.0000, 0.0000]], dtype=torch.float64)
  27284. .. function:: where(condition) -> tuple of LongTensor
  27285. :noindex:
  27286. ``torch.where(condition)`` is identical to
  27287. ``torch.nonzero(condition, as_tuple=True)``.
  27288. .. note::
  27289. See also :func:`torch.nonzero`.
  27290. """
  27291. @overload
  27292. def where(
  27293. condition: Tensor,
  27294. self: Number | _complex,
  27295. other: Tensor,
  27296. ) -> Tensor:
  27297. r"""
  27298. where(condition, input, other, *, out=None) -> Tensor
  27299. Return a tensor of elements selected from either :attr:`input` or :attr:`other`, depending on :attr:`condition`.
  27300. The operation is defined as:
  27301. .. math::
  27302. \text{out}_i = \begin{cases}
  27303. \text{input}_i & \text{if } \text{condition}_i \\
  27304. \text{other}_i & \text{otherwise} \\
  27305. \end{cases}
  27306. .. note::
  27307. The tensors :attr:`condition`, :attr:`input`, :attr:`other` must be :ref:`broadcastable <broadcasting-semantics>`.
  27308. Arguments:
  27309. condition (BoolTensor): When True (nonzero), yield input, otherwise yield other
  27310. input (Tensor or Scalar): value (if :attr:`input` is a scalar) or values selected at indices
  27311. where :attr:`condition` is ``True``
  27312. other (Tensor or Scalar): value (if :attr:`other` is a scalar) or values selected at indices
  27313. where :attr:`condition` is ``False``
  27314. Keyword args:
  27315. out (Tensor, optional): the output tensor.
  27316. Returns:
  27317. Tensor: A tensor of shape equal to the broadcasted shape of :attr:`condition`, :attr:`input`, :attr:`other`
  27318. Example::
  27319. >>> x = torch.randn(3, 2)
  27320. >>> y = torch.ones(3, 2)
  27321. >>> x
  27322. tensor([[-0.4620, 0.3139],
  27323. [ 0.3898, -0.7197],
  27324. [ 0.0478, -0.1657]])
  27325. >>> torch.where(x > 0, 1.0, 0.0)
  27326. tensor([[0., 1.],
  27327. [1., 0.],
  27328. [1., 0.]])
  27329. >>> torch.where(x > 0, x, y)
  27330. tensor([[ 1.0000, 0.3139],
  27331. [ 0.3898, 1.0000],
  27332. [ 0.0478, 1.0000]])
  27333. >>> x = torch.randn(2, 2, dtype=torch.double)
  27334. >>> x
  27335. tensor([[ 1.0779, 0.0383],
  27336. [-0.8785, -1.1089]], dtype=torch.float64)
  27337. >>> torch.where(x > 0, x, 0.)
  27338. tensor([[1.0779, 0.0383],
  27339. [0.0000, 0.0000]], dtype=torch.float64)
  27340. .. function:: where(condition) -> tuple of LongTensor
  27341. :noindex:
  27342. ``torch.where(condition)`` is identical to
  27343. ``torch.nonzero(condition, as_tuple=True)``.
  27344. .. note::
  27345. See also :func:`torch.nonzero`.
  27346. """
  27347. @overload
  27348. def where(
  27349. condition: Tensor,
  27350. input: Tensor,
  27351. other: Number | _complex,
  27352. ) -> Tensor:
  27353. r"""
  27354. where(condition, input, other, *, out=None) -> Tensor
  27355. Return a tensor of elements selected from either :attr:`input` or :attr:`other`, depending on :attr:`condition`.
  27356. The operation is defined as:
  27357. .. math::
  27358. \text{out}_i = \begin{cases}
  27359. \text{input}_i & \text{if } \text{condition}_i \\
  27360. \text{other}_i & \text{otherwise} \\
  27361. \end{cases}
  27362. .. note::
  27363. The tensors :attr:`condition`, :attr:`input`, :attr:`other` must be :ref:`broadcastable <broadcasting-semantics>`.
  27364. Arguments:
  27365. condition (BoolTensor): When True (nonzero), yield input, otherwise yield other
  27366. input (Tensor or Scalar): value (if :attr:`input` is a scalar) or values selected at indices
  27367. where :attr:`condition` is ``True``
  27368. other (Tensor or Scalar): value (if :attr:`other` is a scalar) or values selected at indices
  27369. where :attr:`condition` is ``False``
  27370. Keyword args:
  27371. out (Tensor, optional): the output tensor.
  27372. Returns:
  27373. Tensor: A tensor of shape equal to the broadcasted shape of :attr:`condition`, :attr:`input`, :attr:`other`
  27374. Example::
  27375. >>> x = torch.randn(3, 2)
  27376. >>> y = torch.ones(3, 2)
  27377. >>> x
  27378. tensor([[-0.4620, 0.3139],
  27379. [ 0.3898, -0.7197],
  27380. [ 0.0478, -0.1657]])
  27381. >>> torch.where(x > 0, 1.0, 0.0)
  27382. tensor([[0., 1.],
  27383. [1., 0.],
  27384. [1., 0.]])
  27385. >>> torch.where(x > 0, x, y)
  27386. tensor([[ 1.0000, 0.3139],
  27387. [ 0.3898, 1.0000],
  27388. [ 0.0478, 1.0000]])
  27389. >>> x = torch.randn(2, 2, dtype=torch.double)
  27390. >>> x
  27391. tensor([[ 1.0779, 0.0383],
  27392. [-0.8785, -1.1089]], dtype=torch.float64)
  27393. >>> torch.where(x > 0, x, 0.)
  27394. tensor([[1.0779, 0.0383],
  27395. [0.0000, 0.0000]], dtype=torch.float64)
  27396. .. function:: where(condition) -> tuple of LongTensor
  27397. :noindex:
  27398. ``torch.where(condition)`` is identical to
  27399. ``torch.nonzero(condition, as_tuple=True)``.
  27400. .. note::
  27401. See also :func:`torch.nonzero`.
  27402. """
  27403. @overload
  27404. def where(
  27405. condition: Tensor,
  27406. self: Number | _complex,
  27407. other: Number | _complex,
  27408. ) -> Tensor:
  27409. r"""
  27410. where(condition, input, other, *, out=None) -> Tensor
  27411. Return a tensor of elements selected from either :attr:`input` or :attr:`other`, depending on :attr:`condition`.
  27412. The operation is defined as:
  27413. .. math::
  27414. \text{out}_i = \begin{cases}
  27415. \text{input}_i & \text{if } \text{condition}_i \\
  27416. \text{other}_i & \text{otherwise} \\
  27417. \end{cases}
  27418. .. note::
  27419. The tensors :attr:`condition`, :attr:`input`, :attr:`other` must be :ref:`broadcastable <broadcasting-semantics>`.
  27420. Arguments:
  27421. condition (BoolTensor): When True (nonzero), yield input, otherwise yield other
  27422. input (Tensor or Scalar): value (if :attr:`input` is a scalar) or values selected at indices
  27423. where :attr:`condition` is ``True``
  27424. other (Tensor or Scalar): value (if :attr:`other` is a scalar) or values selected at indices
  27425. where :attr:`condition` is ``False``
  27426. Keyword args:
  27427. out (Tensor, optional): the output tensor.
  27428. Returns:
  27429. Tensor: A tensor of shape equal to the broadcasted shape of :attr:`condition`, :attr:`input`, :attr:`other`
  27430. Example::
  27431. >>> x = torch.randn(3, 2)
  27432. >>> y = torch.ones(3, 2)
  27433. >>> x
  27434. tensor([[-0.4620, 0.3139],
  27435. [ 0.3898, -0.7197],
  27436. [ 0.0478, -0.1657]])
  27437. >>> torch.where(x > 0, 1.0, 0.0)
  27438. tensor([[0., 1.],
  27439. [1., 0.],
  27440. [1., 0.]])
  27441. >>> torch.where(x > 0, x, y)
  27442. tensor([[ 1.0000, 0.3139],
  27443. [ 0.3898, 1.0000],
  27444. [ 0.0478, 1.0000]])
  27445. >>> x = torch.randn(2, 2, dtype=torch.double)
  27446. >>> x
  27447. tensor([[ 1.0779, 0.0383],
  27448. [-0.8785, -1.1089]], dtype=torch.float64)
  27449. >>> torch.where(x > 0, x, 0.)
  27450. tensor([[1.0779, 0.0383],
  27451. [0.0000, 0.0000]], dtype=torch.float64)
  27452. .. function:: where(condition) -> tuple of LongTensor
  27453. :noindex:
  27454. ``torch.where(condition)`` is identical to
  27455. ``torch.nonzero(condition, as_tuple=True)``.
  27456. .. note::
  27457. See also :func:`torch.nonzero`.
  27458. """
  27459. @overload
  27460. def xlogy(
  27461. input: Tensor,
  27462. other: Tensor,
  27463. *,
  27464. out: Tensor | None = None,
  27465. ) -> Tensor:
  27466. r"""
  27467. xlogy(input, other, *, out=None) -> Tensor
  27468. Alias for :func:`torch.special.xlogy`.
  27469. """
  27470. @overload
  27471. def xlogy(
  27472. self: Number | _complex,
  27473. other: Tensor,
  27474. *,
  27475. out: Tensor | None = None,
  27476. ) -> Tensor:
  27477. r"""
  27478. xlogy(input, other, *, out=None) -> Tensor
  27479. Alias for :func:`torch.special.xlogy`.
  27480. """
  27481. @overload
  27482. def xlogy(
  27483. input: Tensor,
  27484. other: Number | _complex,
  27485. *,
  27486. out: Tensor | None = None,
  27487. ) -> Tensor:
  27488. r"""
  27489. xlogy(input, other, *, out=None) -> Tensor
  27490. Alias for :func:`torch.special.xlogy`.
  27491. """
  27492. @overload
  27493. def xlogy_(input: Tensor, other: Tensor) -> Tensor: ...
  27494. @overload
  27495. def xlogy_(input: Tensor, other: Number | _complex) -> Tensor: ...
  27496. def zero_(input: Tensor) -> Tensor: ...
  27497. @overload
  27498. def zeros(
  27499. size: Sequence[_int | SymInt],
  27500. *,
  27501. out: Tensor | None = None,
  27502. dtype: _dtype | None = None,
  27503. layout: _layout | None = None,
  27504. device: DeviceLikeType | None = None,
  27505. pin_memory: _bool | None = False,
  27506. requires_grad: _bool | None = False,
  27507. ) -> Tensor:
  27508. r"""
  27509. zeros(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  27510. Returns a tensor filled with the scalar value `0`, with the shape defined
  27511. by the variable argument :attr:`size`.
  27512. Args:
  27513. size (int...): a sequence of integers defining the shape of the output tensor.
  27514. Can be a variable number of arguments or a collection like a list or tuple.
  27515. Keyword args:
  27516. out (Tensor, optional): the output tensor.
  27517. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  27518. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  27519. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  27520. Default: ``torch.strided``.
  27521. device (:class:`torch.device`, optional): the desired device of returned tensor.
  27522. Default: if ``None``, uses the current device for the default tensor type
  27523. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  27524. for CPU tensor types and the current CUDA device for CUDA tensor types.
  27525. requires_grad (bool, optional): If autograd should record operations on the
  27526. returned tensor. Default: ``False``.
  27527. Example::
  27528. >>> torch.zeros(2, 3)
  27529. tensor([[ 0., 0., 0.],
  27530. [ 0., 0., 0.]])
  27531. >>> torch.zeros(5)
  27532. tensor([ 0., 0., 0., 0., 0.])
  27533. """
  27534. @overload
  27535. def zeros(
  27536. *size: _int | SymInt,
  27537. out: Tensor | None = None,
  27538. dtype: _dtype | None = None,
  27539. layout: _layout | None = None,
  27540. device: DeviceLikeType | None = None,
  27541. pin_memory: _bool | None = False,
  27542. requires_grad: _bool | None = False,
  27543. ) -> Tensor:
  27544. r"""
  27545. zeros(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  27546. Returns a tensor filled with the scalar value `0`, with the shape defined
  27547. by the variable argument :attr:`size`.
  27548. Args:
  27549. size (int...): a sequence of integers defining the shape of the output tensor.
  27550. Can be a variable number of arguments or a collection like a list or tuple.
  27551. Keyword args:
  27552. out (Tensor, optional): the output tensor.
  27553. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  27554. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  27555. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  27556. Default: ``torch.strided``.
  27557. device (:class:`torch.device`, optional): the desired device of returned tensor.
  27558. Default: if ``None``, uses the current device for the default tensor type
  27559. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  27560. for CPU tensor types and the current CUDA device for CUDA tensor types.
  27561. requires_grad (bool, optional): If autograd should record operations on the
  27562. returned tensor. Default: ``False``.
  27563. Example::
  27564. >>> torch.zeros(2, 3)
  27565. tensor([[ 0., 0., 0.],
  27566. [ 0., 0., 0.]])
  27567. >>> torch.zeros(5)
  27568. tensor([ 0., 0., 0., 0., 0.])
  27569. """
  27570. @overload
  27571. def zeros(
  27572. size: _size,
  27573. *,
  27574. names: Sequence[str | EllipsisType | None] | None,
  27575. dtype: _dtype | None = None,
  27576. layout: _layout | None = None,
  27577. device: DeviceLikeType | None = None,
  27578. pin_memory: _bool | None = False,
  27579. requires_grad: _bool | None = False,
  27580. ) -> Tensor:
  27581. r"""
  27582. zeros(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  27583. Returns a tensor filled with the scalar value `0`, with the shape defined
  27584. by the variable argument :attr:`size`.
  27585. Args:
  27586. size (int...): a sequence of integers defining the shape of the output tensor.
  27587. Can be a variable number of arguments or a collection like a list or tuple.
  27588. Keyword args:
  27589. out (Tensor, optional): the output tensor.
  27590. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  27591. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  27592. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  27593. Default: ``torch.strided``.
  27594. device (:class:`torch.device`, optional): the desired device of returned tensor.
  27595. Default: if ``None``, uses the current device for the default tensor type
  27596. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  27597. for CPU tensor types and the current CUDA device for CUDA tensor types.
  27598. requires_grad (bool, optional): If autograd should record operations on the
  27599. returned tensor. Default: ``False``.
  27600. Example::
  27601. >>> torch.zeros(2, 3)
  27602. tensor([[ 0., 0., 0.],
  27603. [ 0., 0., 0.]])
  27604. >>> torch.zeros(5)
  27605. tensor([ 0., 0., 0., 0., 0.])
  27606. """
  27607. @overload
  27608. def zeros(
  27609. *size: _int,
  27610. names: Sequence[str | EllipsisType | None] | None,
  27611. dtype: _dtype | None = None,
  27612. layout: _layout | None = None,
  27613. device: DeviceLikeType | None = None,
  27614. pin_memory: _bool | None = False,
  27615. requires_grad: _bool | None = False,
  27616. ) -> Tensor:
  27617. r"""
  27618. zeros(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
  27619. Returns a tensor filled with the scalar value `0`, with the shape defined
  27620. by the variable argument :attr:`size`.
  27621. Args:
  27622. size (int...): a sequence of integers defining the shape of the output tensor.
  27623. Can be a variable number of arguments or a collection like a list or tuple.
  27624. Keyword args:
  27625. out (Tensor, optional): the output tensor.
  27626. dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
  27627. Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
  27628. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  27629. Default: ``torch.strided``.
  27630. device (:class:`torch.device`, optional): the desired device of returned tensor.
  27631. Default: if ``None``, uses the current device for the default tensor type
  27632. (see :func:`torch.set_default_device`). :attr:`device` will be the CPU
  27633. for CPU tensor types and the current CUDA device for CUDA tensor types.
  27634. requires_grad (bool, optional): If autograd should record operations on the
  27635. returned tensor. Default: ``False``.
  27636. Example::
  27637. >>> torch.zeros(2, 3)
  27638. tensor([[ 0., 0., 0.],
  27639. [ 0., 0., 0.]])
  27640. >>> torch.zeros(5)
  27641. tensor([ 0., 0., 0., 0., 0.])
  27642. """
  27643. def zeros_like(
  27644. input: Tensor,
  27645. *,
  27646. memory_format: memory_format | None = None,
  27647. dtype: _dtype | None = None,
  27648. layout: _layout | None = None,
  27649. device: DeviceLikeType | None = None,
  27650. pin_memory: _bool | None = False,
  27651. requires_grad: _bool | None = False,
  27652. ) -> Tensor:
  27653. r"""
  27654. zeros_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
  27655. Returns a tensor filled with the scalar value `0`, with the same size as
  27656. :attr:`input`. ``torch.zeros_like(input)`` is equivalent to
  27657. ``torch.zeros(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
  27658. .. warning::
  27659. As of 0.4, this function does not support an :attr:`out` keyword. As an alternative,
  27660. the old ``torch.zeros_like(input, out=output)`` is equivalent to
  27661. ``torch.zeros(input.size(), out=output)``.
  27662. Args:
  27663. input (Tensor): the size of :attr:`input` will determine size of the output tensor.
  27664. Keyword args:
  27665. dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
  27666. Default: if ``None``, defaults to the dtype of :attr:`input`.
  27667. layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
  27668. Default: if ``None``, defaults to the layout of :attr:`input`.
  27669. device (:class:`torch.device`, optional): the desired device of returned tensor.
  27670. Default: if ``None``, defaults to the device of :attr:`input`.
  27671. requires_grad (bool, optional): If autograd should record operations on the
  27672. returned tensor. Default: ``False``.
  27673. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  27674. returned Tensor. Default: ``torch.preserve_format``.
  27675. Example::
  27676. >>> input = torch.empty(2, 3)
  27677. >>> torch.zeros_like(input)
  27678. tensor([[ 0., 0., 0.],
  27679. [ 0., 0., 0.]])
  27680. """