_tensor_docs.py 142 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014
  1. # mypy: allow-untyped-defs
  2. """Adds docstrings to Tensor functions"""
  3. import torch._C
  4. from torch._C import _add_docstr as add_docstr
  5. from torch._torch_docs import parse_kwargs, reproducibility_notes
  6. def add_docstr_all(method: str, docstr: str) -> None:
  7. add_docstr(getattr(torch._C.TensorBase, method), docstr)
  8. common_args = parse_kwargs(
  9. """
  10. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  11. returned Tensor. Default: ``torch.preserve_format``.
  12. """
  13. )
  14. new_common_args = parse_kwargs(
  15. """
  16. size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
  17. shape of the output tensor.
  18. dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
  19. Default: if None, same :class:`torch.dtype` as this tensor.
  20. device (:class:`torch.device`, optional): the desired device of returned tensor.
  21. Default: if None, same :class:`torch.device` as this tensor.
  22. requires_grad (bool, optional): If autograd should record operations on the
  23. returned tensor. Default: ``False``.
  24. pin_memory (bool, optional): If set, returned tensor would be allocated in
  25. the pinned memory. Works only for CPU tensors. Default: ``False``.
  26. layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
  27. Default: ``torch.strided``.
  28. """
  29. )
  30. add_docstr_all(
  31. "new_tensor",
  32. """
  33. new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, \
  34. pin_memory=False) -> Tensor
  35. """
  36. + r"""
  37. Returns a new Tensor with :attr:`data` as the tensor data.
  38. By default, the returned Tensor has the same :class:`torch.dtype` and
  39. :class:`torch.device` as this tensor.
  40. .. warning::
  41. :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
  42. ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
  43. or :func:`torch.Tensor.detach`.
  44. If you have a numpy array and want to avoid a copy, use
  45. :func:`torch.from_numpy`.
  46. .. warning::
  47. When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
  48. and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
  49. and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
  50. The equivalents using ``detach()`` and ``clone()`` are recommended.
  51. Args:
  52. data (array_like): The returned Tensor copies :attr:`data`.
  53. Keyword args:
  54. {dtype}
  55. {device}
  56. {requires_grad}
  57. {layout}
  58. {pin_memory}
  59. Example::
  60. >>> tensor = torch.ones((2,), dtype=torch.int8)
  61. >>> data = [[0, 1], [2, 3]]
  62. >>> tensor.new_tensor(data)
  63. tensor([[ 0, 1],
  64. [ 2, 3]], dtype=torch.int8)
  65. """.format(**new_common_args),
  66. )
  67. add_docstr_all(
  68. "new_full",
  69. """
  70. new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, \
  71. pin_memory=False) -> Tensor
  72. """
  73. + r"""
  74. Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
  75. By default, the returned Tensor has the same :class:`torch.dtype` and
  76. :class:`torch.device` as this tensor.
  77. Args:
  78. fill_value (scalar): the number to fill the output tensor with.
  79. Keyword args:
  80. {dtype}
  81. {device}
  82. {requires_grad}
  83. {layout}
  84. {pin_memory}
  85. Example::
  86. >>> tensor = torch.ones((2,), dtype=torch.float64)
  87. >>> tensor.new_full((3, 4), 3.141592)
  88. tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
  89. [ 3.1416, 3.1416, 3.1416, 3.1416],
  90. [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
  91. """.format(**new_common_args),
  92. )
  93. add_docstr_all(
  94. "new_empty",
  95. """
  96. new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, \
  97. pin_memory=False) -> Tensor
  98. """
  99. + r"""
  100. Returns a Tensor of size :attr:`size` filled with uninitialized data.
  101. By default, the returned Tensor has the same :class:`torch.dtype` and
  102. :class:`torch.device` as this tensor.
  103. Args:
  104. size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
  105. shape of the output tensor.
  106. Keyword args:
  107. {dtype}
  108. {device}
  109. {requires_grad}
  110. {layout}
  111. {pin_memory}
  112. Example::
  113. >>> tensor = torch.ones(())
  114. >>> tensor.new_empty((2, 3))
  115. tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
  116. [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
  117. """.format(**new_common_args),
  118. )
  119. add_docstr_all(
  120. "new_empty_strided",
  121. """
  122. new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, \
  123. pin_memory=False) -> Tensor
  124. """
  125. + r"""
  126. Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
  127. uninitialized data. By default, the returned Tensor has the same
  128. :class:`torch.dtype` and :class:`torch.device` as this tensor.
  129. Args:
  130. size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
  131. shape of the output tensor.
  132. Keyword args:
  133. {dtype}
  134. {device}
  135. {requires_grad}
  136. {layout}
  137. {pin_memory}
  138. Example::
  139. >>> tensor = torch.ones(())
  140. >>> tensor.new_empty_strided((2, 3), (3, 1))
  141. tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
  142. [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
  143. """.format(**new_common_args),
  144. )
  145. add_docstr_all(
  146. "new_ones",
  147. """
  148. new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, \
  149. pin_memory=False) -> Tensor
  150. """
  151. + r"""
  152. Returns a Tensor of size :attr:`size` filled with ``1``.
  153. By default, the returned Tensor has the same :class:`torch.dtype` and
  154. :class:`torch.device` as this tensor.
  155. Args:
  156. size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
  157. shape of the output tensor.
  158. Keyword args:
  159. {dtype}
  160. {device}
  161. {requires_grad}
  162. {layout}
  163. {pin_memory}
  164. Example::
  165. >>> tensor = torch.tensor((), dtype=torch.int32)
  166. >>> tensor.new_ones((2, 3))
  167. tensor([[ 1, 1, 1],
  168. [ 1, 1, 1]], dtype=torch.int32)
  169. """.format(**new_common_args),
  170. )
  171. add_docstr_all(
  172. "new_zeros",
  173. """
  174. new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, \
  175. pin_memory=False) -> Tensor
  176. """
  177. + r"""
  178. Returns a Tensor of size :attr:`size` filled with ``0``.
  179. By default, the returned Tensor has the same :class:`torch.dtype` and
  180. :class:`torch.device` as this tensor.
  181. Args:
  182. size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
  183. shape of the output tensor.
  184. Keyword args:
  185. {dtype}
  186. {device}
  187. {requires_grad}
  188. {layout}
  189. {pin_memory}
  190. Example::
  191. >>> tensor = torch.tensor((), dtype=torch.float64)
  192. >>> tensor.new_zeros((2, 3))
  193. tensor([[ 0., 0., 0.],
  194. [ 0., 0., 0.]], dtype=torch.float64)
  195. """.format(**new_common_args),
  196. )
  197. add_docstr_all(
  198. "abs",
  199. r"""
  200. abs() -> Tensor
  201. See :func:`torch.abs`
  202. """,
  203. )
  204. add_docstr_all(
  205. "abs_",
  206. r"""
  207. abs_() -> Tensor
  208. In-place version of :meth:`~Tensor.abs`
  209. """,
  210. )
  211. add_docstr_all(
  212. "absolute",
  213. r"""
  214. absolute() -> Tensor
  215. Alias for :func:`abs`
  216. """,
  217. )
  218. add_docstr_all(
  219. "absolute_",
  220. r"""
  221. absolute_() -> Tensor
  222. In-place version of :meth:`~Tensor.absolute`
  223. Alias for :func:`abs_`
  224. """,
  225. )
  226. add_docstr_all(
  227. "acos",
  228. r"""
  229. acos() -> Tensor
  230. See :func:`torch.acos`
  231. """,
  232. )
  233. add_docstr_all(
  234. "acos_",
  235. r"""
  236. acos_() -> Tensor
  237. In-place version of :meth:`~Tensor.acos`
  238. """,
  239. )
  240. add_docstr_all(
  241. "arccos",
  242. r"""
  243. arccos() -> Tensor
  244. See :func:`torch.arccos`
  245. """,
  246. )
  247. add_docstr_all(
  248. "arccos_",
  249. r"""
  250. arccos_() -> Tensor
  251. In-place version of :meth:`~Tensor.arccos`
  252. """,
  253. )
  254. add_docstr_all(
  255. "acosh",
  256. r"""
  257. acosh() -> Tensor
  258. See :func:`torch.acosh`
  259. """,
  260. )
  261. add_docstr_all(
  262. "acosh_",
  263. r"""
  264. acosh_() -> Tensor
  265. In-place version of :meth:`~Tensor.acosh`
  266. """,
  267. )
  268. add_docstr_all(
  269. "arccosh",
  270. r"""
  271. acosh() -> Tensor
  272. See :func:`torch.arccosh`
  273. """,
  274. )
  275. add_docstr_all(
  276. "arccosh_",
  277. r"""
  278. acosh_() -> Tensor
  279. In-place version of :meth:`~Tensor.arccosh`
  280. """,
  281. )
  282. add_docstr_all(
  283. "add",
  284. r"""
  285. add(other, *, alpha=1) -> Tensor
  286. Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
  287. and :attr:`other` are specified, each element of :attr:`other` is scaled by
  288. :attr:`alpha` before being used.
  289. When :attr:`other` is a tensor, the shape of :attr:`other` must be
  290. :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
  291. tensor
  292. See :func:`torch.add`
  293. """,
  294. )
  295. add_docstr_all(
  296. "add_",
  297. r"""
  298. add_(other, *, alpha=1) -> Tensor
  299. In-place version of :meth:`~Tensor.add`
  300. """,
  301. )
  302. add_docstr_all(
  303. "addbmm",
  304. r"""
  305. addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
  306. See :func:`torch.addbmm`
  307. """,
  308. )
  309. add_docstr_all(
  310. "addbmm_",
  311. r"""
  312. addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
  313. In-place version of :meth:`~Tensor.addbmm`
  314. """,
  315. )
  316. add_docstr_all(
  317. "addcdiv",
  318. r"""
  319. addcdiv(tensor1, tensor2, *, value=1) -> Tensor
  320. See :func:`torch.addcdiv`
  321. """,
  322. )
  323. add_docstr_all(
  324. "addcdiv_",
  325. r"""
  326. addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
  327. In-place version of :meth:`~Tensor.addcdiv`
  328. """,
  329. )
  330. add_docstr_all(
  331. "addcmul",
  332. r"""
  333. addcmul(tensor1, tensor2, *, value=1) -> Tensor
  334. See :func:`torch.addcmul`
  335. """,
  336. )
  337. add_docstr_all(
  338. "addcmul_",
  339. r"""
  340. addcmul_(tensor1, tensor2, *, value=1) -> Tensor
  341. In-place version of :meth:`~Tensor.addcmul`
  342. """,
  343. )
  344. add_docstr_all(
  345. "addmm",
  346. r"""
  347. addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
  348. See :func:`torch.addmm`
  349. """,
  350. )
  351. add_docstr_all(
  352. "addmm_",
  353. r"""
  354. addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
  355. In-place version of :meth:`~Tensor.addmm`
  356. """,
  357. )
  358. add_docstr_all(
  359. "addmv",
  360. r"""
  361. addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
  362. See :func:`torch.addmv`
  363. """,
  364. )
  365. add_docstr_all(
  366. "addmv_",
  367. r"""
  368. addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
  369. In-place version of :meth:`~Tensor.addmv`
  370. """,
  371. )
  372. add_docstr_all(
  373. "sspaddmm",
  374. r"""
  375. sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
  376. See :func:`torch.sspaddmm`
  377. """,
  378. )
  379. add_docstr_all(
  380. "smm",
  381. r"""
  382. smm(mat) -> Tensor
  383. See :func:`torch.smm`
  384. """,
  385. )
  386. add_docstr_all(
  387. "addr",
  388. r"""
  389. addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
  390. See :func:`torch.addr`
  391. """,
  392. )
  393. add_docstr_all(
  394. "addr_",
  395. r"""
  396. addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
  397. In-place version of :meth:`~Tensor.addr`
  398. """,
  399. )
  400. add_docstr_all(
  401. "align_as",
  402. r"""
  403. align_as(other) -> Tensor
  404. Permutes the dimensions of the :attr:`self` tensor to match the dimension order
  405. in the :attr:`other` tensor, adding size-one dims for any new names.
  406. This operation is useful for explicit broadcasting by names (see examples).
  407. All of the dims of :attr:`self` must be named in order to use this method.
  408. The resulting tensor is a view on the original tensor.
  409. All dimension names of :attr:`self` must be present in ``other.names``.
  410. :attr:`other` may contain named dimensions that are not in ``self.names``;
  411. the output tensor has a size-one dimension for each of those new names.
  412. To align a tensor to a specific order, use :meth:`~Tensor.align_to`.
  413. Examples::
  414. # Example 1: Applying a mask
  415. >>> mask = torch.randint(2, [127, 128], dtype=torch.bool).refine_names('W', 'H')
  416. >>> imgs = torch.randn(32, 128, 127, 3, names=('N', 'H', 'W', 'C'))
  417. >>> imgs.masked_fill_(mask.align_as(imgs), 0)
  418. # Example 2: Applying a per-channel-scale
  419. >>> def scale_channels(input, scale):
  420. >>> scale = scale.refine_names('C')
  421. >>> return input * scale.align_as(input)
  422. >>> num_channels = 3
  423. >>> scale = torch.randn(num_channels, names=('C',))
  424. >>> imgs = torch.rand(32, 128, 128, num_channels, names=('N', 'H', 'W', 'C'))
  425. >>> more_imgs = torch.rand(32, num_channels, 128, 128, names=('N', 'C', 'H', 'W'))
  426. >>> videos = torch.randn(3, num_channels, 128, 128, 128, names=('N', 'C', 'H', 'W', 'D'))
  427. # scale_channels is agnostic to the dimension order of the input
  428. >>> scale_channels(imgs, scale)
  429. >>> scale_channels(more_imgs, scale)
  430. >>> scale_channels(videos, scale)
  431. .. warning::
  432. The named tensor API is experimental and subject to change.
  433. """,
  434. )
  435. add_docstr_all(
  436. "all",
  437. r"""
  438. all(dim=None, keepdim=False) -> Tensor
  439. See :func:`torch.all`
  440. """,
  441. )
  442. add_docstr_all(
  443. "allclose",
  444. r"""
  445. allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
  446. See :func:`torch.allclose`
  447. """,
  448. )
  449. add_docstr_all(
  450. "angle",
  451. r"""
  452. angle() -> Tensor
  453. See :func:`torch.angle`
  454. """,
  455. )
  456. add_docstr_all(
  457. "any",
  458. r"""
  459. any(dim=None, keepdim=False) -> Tensor
  460. See :func:`torch.any`
  461. """,
  462. )
  463. add_docstr_all(
  464. "apply_",
  465. r"""
  466. apply_(callable) -> Tensor
  467. Applies the function :attr:`callable` to each element in the tensor, replacing
  468. each element with the value returned by :attr:`callable`.
  469. .. note::
  470. This function only works with CPU tensors and should not be used in code
  471. sections that require high performance.
  472. """,
  473. )
  474. add_docstr_all(
  475. "asin",
  476. r"""
  477. asin() -> Tensor
  478. See :func:`torch.asin`
  479. """,
  480. )
  481. add_docstr_all(
  482. "asin_",
  483. r"""
  484. asin_() -> Tensor
  485. In-place version of :meth:`~Tensor.asin`
  486. """,
  487. )
  488. add_docstr_all(
  489. "arcsin",
  490. r"""
  491. arcsin() -> Tensor
  492. See :func:`torch.arcsin`
  493. """,
  494. )
  495. add_docstr_all(
  496. "arcsin_",
  497. r"""
  498. arcsin_() -> Tensor
  499. In-place version of :meth:`~Tensor.arcsin`
  500. """,
  501. )
  502. add_docstr_all(
  503. "asinh",
  504. r"""
  505. asinh() -> Tensor
  506. See :func:`torch.asinh`
  507. """,
  508. )
  509. add_docstr_all(
  510. "asinh_",
  511. r"""
  512. asinh_() -> Tensor
  513. In-place version of :meth:`~Tensor.asinh`
  514. """,
  515. )
  516. add_docstr_all(
  517. "arcsinh",
  518. r"""
  519. arcsinh() -> Tensor
  520. See :func:`torch.arcsinh`
  521. """,
  522. )
  523. add_docstr_all(
  524. "arcsinh_",
  525. r"""
  526. arcsinh_() -> Tensor
  527. In-place version of :meth:`~Tensor.arcsinh`
  528. """,
  529. )
  530. add_docstr_all(
  531. "as_strided",
  532. r"""
  533. as_strided(size, stride, storage_offset=None) -> Tensor
  534. See :func:`torch.as_strided`
  535. """,
  536. )
  537. add_docstr_all(
  538. "as_strided_",
  539. r"""
  540. as_strided_(size, stride, storage_offset=None) -> Tensor
  541. In-place version of :meth:`~Tensor.as_strided`
  542. """,
  543. )
  544. add_docstr_all(
  545. "atan",
  546. r"""
  547. atan() -> Tensor
  548. See :func:`torch.atan`
  549. """,
  550. )
  551. add_docstr_all(
  552. "atan_",
  553. r"""
  554. atan_() -> Tensor
  555. In-place version of :meth:`~Tensor.atan`
  556. """,
  557. )
  558. add_docstr_all(
  559. "arctan",
  560. r"""
  561. arctan() -> Tensor
  562. See :func:`torch.arctan`
  563. """,
  564. )
  565. add_docstr_all(
  566. "arctan_",
  567. r"""
  568. arctan_() -> Tensor
  569. In-place version of :meth:`~Tensor.arctan`
  570. """,
  571. )
  572. add_docstr_all(
  573. "atan2",
  574. r"""
  575. atan2(other) -> Tensor
  576. See :func:`torch.atan2`
  577. """,
  578. )
  579. add_docstr_all(
  580. "atan2_",
  581. r"""
  582. atan2_(other) -> Tensor
  583. In-place version of :meth:`~Tensor.atan2`
  584. """,
  585. )
  586. add_docstr_all(
  587. "arctan2",
  588. r"""
  589. arctan2(other) -> Tensor
  590. See :func:`torch.arctan2`
  591. """,
  592. )
  593. add_docstr_all(
  594. "arctan2_",
  595. r"""
  596. atan2_(other) -> Tensor
  597. In-place version of :meth:`~Tensor.arctan2`
  598. """,
  599. )
  600. add_docstr_all(
  601. "atanh",
  602. r"""
  603. atanh() -> Tensor
  604. See :func:`torch.atanh`
  605. """,
  606. )
  607. add_docstr_all(
  608. "atanh_",
  609. r"""
  610. atanh_(other) -> Tensor
  611. In-place version of :meth:`~Tensor.atanh`
  612. """,
  613. )
  614. add_docstr_all(
  615. "arctanh",
  616. r"""
  617. arctanh() -> Tensor
  618. See :func:`torch.arctanh`
  619. """,
  620. )
  621. add_docstr_all(
  622. "arctanh_",
  623. r"""
  624. arctanh_(other) -> Tensor
  625. In-place version of :meth:`~Tensor.arctanh`
  626. """,
  627. )
  628. add_docstr_all(
  629. "baddbmm",
  630. r"""
  631. baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
  632. See :func:`torch.baddbmm`
  633. """,
  634. )
  635. add_docstr_all(
  636. "baddbmm_",
  637. r"""
  638. baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
  639. In-place version of :meth:`~Tensor.baddbmm`
  640. """,
  641. )
  642. add_docstr_all(
  643. "bernoulli",
  644. r"""
  645. bernoulli(*, generator=None) -> Tensor
  646. Returns a result tensor where each :math:`\texttt{result[i]}` is independently
  647. sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
  648. floating point ``dtype``, and the result will have the same ``dtype``.
  649. See :func:`torch.bernoulli`
  650. """,
  651. )
  652. add_docstr_all(
  653. "bernoulli_",
  654. r"""
  655. bernoulli_(p=0.5, *, generator=None) -> Tensor
  656. Fills each location of :attr:`self` with an independent sample from
  657. :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
  658. ``dtype``.
  659. :attr:`p` should either be a scalar or tensor containing probabilities to be
  660. used for drawing the binary random number.
  661. If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
  662. will be set to a value sampled from
  663. :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
  664. floating point ``dtype``.
  665. See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
  666. """,
  667. )
  668. add_docstr_all(
  669. "bincount",
  670. r"""
  671. bincount(weights=None, minlength=0) -> Tensor
  672. See :func:`torch.bincount`
  673. """,
  674. )
  675. add_docstr_all(
  676. "bitwise_not",
  677. r"""
  678. bitwise_not() -> Tensor
  679. See :func:`torch.bitwise_not`
  680. """,
  681. )
  682. add_docstr_all(
  683. "bitwise_not_",
  684. r"""
  685. bitwise_not_() -> Tensor
  686. In-place version of :meth:`~Tensor.bitwise_not`
  687. """,
  688. )
  689. add_docstr_all(
  690. "bitwise_and",
  691. r"""
  692. bitwise_and() -> Tensor
  693. See :func:`torch.bitwise_and`
  694. """,
  695. )
  696. add_docstr_all(
  697. "bitwise_and_",
  698. r"""
  699. bitwise_and_() -> Tensor
  700. In-place version of :meth:`~Tensor.bitwise_and`
  701. """,
  702. )
  703. add_docstr_all(
  704. "bitwise_or",
  705. r"""
  706. bitwise_or() -> Tensor
  707. See :func:`torch.bitwise_or`
  708. """,
  709. )
  710. add_docstr_all(
  711. "bitwise_or_",
  712. r"""
  713. bitwise_or_() -> Tensor
  714. In-place version of :meth:`~Tensor.bitwise_or`
  715. """,
  716. )
  717. add_docstr_all(
  718. "bitwise_xor",
  719. r"""
  720. bitwise_xor() -> Tensor
  721. See :func:`torch.bitwise_xor`
  722. """,
  723. )
  724. add_docstr_all(
  725. "bitwise_xor_",
  726. r"""
  727. bitwise_xor_() -> Tensor
  728. In-place version of :meth:`~Tensor.bitwise_xor`
  729. """,
  730. )
  731. add_docstr_all(
  732. "bitwise_left_shift",
  733. r"""
  734. bitwise_left_shift(other) -> Tensor
  735. See :func:`torch.bitwise_left_shift`
  736. """,
  737. )
  738. add_docstr_all(
  739. "bitwise_left_shift_",
  740. r"""
  741. bitwise_left_shift_(other) -> Tensor
  742. In-place version of :meth:`~Tensor.bitwise_left_shift`
  743. """,
  744. )
  745. add_docstr_all(
  746. "bitwise_right_shift",
  747. r"""
  748. bitwise_right_shift(other) -> Tensor
  749. See :func:`torch.bitwise_right_shift`
  750. """,
  751. )
  752. add_docstr_all(
  753. "bitwise_right_shift_",
  754. r"""
  755. bitwise_right_shift_(other) -> Tensor
  756. In-place version of :meth:`~Tensor.bitwise_right_shift`
  757. """,
  758. )
  759. add_docstr_all(
  760. "broadcast_to",
  761. r"""
  762. broadcast_to(shape) -> Tensor
  763. See :func:`torch.broadcast_to`.
  764. """,
  765. )
  766. add_docstr_all(
  767. "logical_and",
  768. r"""
  769. logical_and() -> Tensor
  770. See :func:`torch.logical_and`
  771. """,
  772. )
  773. add_docstr_all(
  774. "logical_and_",
  775. r"""
  776. logical_and_() -> Tensor
  777. In-place version of :meth:`~Tensor.logical_and`
  778. """,
  779. )
  780. add_docstr_all(
  781. "logical_not",
  782. r"""
  783. logical_not() -> Tensor
  784. See :func:`torch.logical_not`
  785. """,
  786. )
  787. add_docstr_all(
  788. "logical_not_",
  789. r"""
  790. logical_not_() -> Tensor
  791. In-place version of :meth:`~Tensor.logical_not`
  792. """,
  793. )
  794. add_docstr_all(
  795. "logical_or",
  796. r"""
  797. logical_or() -> Tensor
  798. See :func:`torch.logical_or`
  799. """,
  800. )
  801. add_docstr_all(
  802. "logical_or_",
  803. r"""
  804. logical_or_() -> Tensor
  805. In-place version of :meth:`~Tensor.logical_or`
  806. """,
  807. )
  808. add_docstr_all(
  809. "logical_xor",
  810. r"""
  811. logical_xor() -> Tensor
  812. See :func:`torch.logical_xor`
  813. """,
  814. )
  815. add_docstr_all(
  816. "logical_xor_",
  817. r"""
  818. logical_xor_() -> Tensor
  819. In-place version of :meth:`~Tensor.logical_xor`
  820. """,
  821. )
  822. add_docstr_all(
  823. "bmm",
  824. r"""
  825. bmm(batch2) -> Tensor
  826. See :func:`torch.bmm`
  827. """,
  828. )
  829. add_docstr_all(
  830. "cauchy_",
  831. r"""
  832. cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
  833. Fills the tensor with numbers drawn from the Cauchy distribution:
  834. .. math::
  835. f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
  836. .. note::
  837. Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
  838. """,
  839. )
  840. add_docstr_all(
  841. "ceil",
  842. r"""
  843. ceil() -> Tensor
  844. See :func:`torch.ceil`
  845. """,
  846. )
  847. add_docstr_all(
  848. "ceil_",
  849. r"""
  850. ceil_() -> Tensor
  851. In-place version of :meth:`~Tensor.ceil`
  852. """,
  853. )
  854. add_docstr_all(
  855. "cholesky",
  856. r"""
  857. cholesky(upper=False) -> Tensor
  858. See :func:`torch.cholesky`
  859. """,
  860. )
  861. add_docstr_all(
  862. "cholesky_solve",
  863. r"""
  864. cholesky_solve(input2, upper=False) -> Tensor
  865. See :func:`torch.cholesky_solve`
  866. """,
  867. )
  868. add_docstr_all(
  869. "cholesky_inverse",
  870. r"""
  871. cholesky_inverse(upper=False) -> Tensor
  872. See :func:`torch.cholesky_inverse`
  873. """,
  874. )
  875. add_docstr_all(
  876. "clamp",
  877. r"""
  878. clamp(min=None, max=None) -> Tensor
  879. See :func:`torch.clamp`
  880. """,
  881. )
  882. add_docstr_all(
  883. "clamp_",
  884. r"""
  885. clamp_(min=None, max=None) -> Tensor
  886. In-place version of :meth:`~Tensor.clamp`
  887. """,
  888. )
  889. add_docstr_all(
  890. "clip",
  891. r"""
  892. clip(min=None, max=None) -> Tensor
  893. Alias for :meth:`~Tensor.clamp`.
  894. """,
  895. )
  896. add_docstr_all(
  897. "clip_",
  898. r"""
  899. clip_(min=None, max=None) -> Tensor
  900. Alias for :meth:`~Tensor.clamp_`.
  901. """,
  902. )
  903. add_docstr_all(
  904. "clone",
  905. r"""
  906. clone(*, memory_format=torch.preserve_format) -> Tensor
  907. See :func:`torch.clone`
  908. """.format(**common_args),
  909. )
  910. add_docstr_all(
  911. "coalesce",
  912. r"""
  913. coalesce() -> Tensor
  914. Returns a coalesced copy of :attr:`self` if :attr:`self` is an
  915. :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
  916. Returns :attr:`self` if :attr:`self` is a coalesced tensor.
  917. .. warning::
  918. Throws an error if :attr:`self` is not a sparse COO tensor.
  919. """,
  920. )
  921. add_docstr_all(
  922. "contiguous",
  923. r"""
  924. contiguous(memory_format=torch.contiguous_format) -> Tensor
  925. Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
  926. :attr:`self` tensor is already in the specified memory format, this function returns the
  927. :attr:`self` tensor.
  928. Args:
  929. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  930. returned Tensor. Default: ``torch.contiguous_format``.
  931. """,
  932. )
  933. add_docstr_all(
  934. "copy_",
  935. r"""
  936. copy_(src, non_blocking=False) -> Tensor
  937. Copies the elements from :attr:`src` into :attr:`self` tensor and returns
  938. :attr:`self`.
  939. The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
  940. with the :attr:`self` tensor. It may be of a different data type or reside on a
  941. different device.
  942. Args:
  943. src (Tensor): the source tensor to copy from
  944. non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
  945. the copy may occur asynchronously with respect to the host. For other
  946. cases, this argument has no effect. Default: ``False``
  947. """,
  948. )
  949. add_docstr_all(
  950. "conj",
  951. r"""
  952. conj() -> Tensor
  953. See :func:`torch.conj`
  954. """,
  955. )
  956. add_docstr_all(
  957. "conj_physical",
  958. r"""
  959. conj_physical() -> Tensor
  960. See :func:`torch.conj_physical`
  961. """,
  962. )
  963. add_docstr_all(
  964. "conj_physical_",
  965. r"""
  966. conj_physical_() -> Tensor
  967. In-place version of :meth:`~Tensor.conj_physical`
  968. """,
  969. )
  970. add_docstr_all(
  971. "resolve_conj",
  972. r"""
  973. resolve_conj() -> Tensor
  974. See :func:`torch.resolve_conj`
  975. """,
  976. )
  977. add_docstr_all(
  978. "resolve_neg",
  979. r"""
  980. resolve_neg() -> Tensor
  981. See :func:`torch.resolve_neg`
  982. """,
  983. )
  984. add_docstr_all(
  985. "copysign",
  986. r"""
  987. copysign(other) -> Tensor
  988. See :func:`torch.copysign`
  989. """,
  990. )
  991. add_docstr_all(
  992. "copysign_",
  993. r"""
  994. copysign_(other) -> Tensor
  995. In-place version of :meth:`~Tensor.copysign`
  996. """,
  997. )
  998. add_docstr_all(
  999. "cos",
  1000. r"""
  1001. cos() -> Tensor
  1002. See :func:`torch.cos`
  1003. """,
  1004. )
  1005. add_docstr_all(
  1006. "cos_",
  1007. r"""
  1008. cos_() -> Tensor
  1009. In-place version of :meth:`~Tensor.cos`
  1010. """,
  1011. )
  1012. add_docstr_all(
  1013. "cosh",
  1014. r"""
  1015. cosh() -> Tensor
  1016. See :func:`torch.cosh`
  1017. """,
  1018. )
  1019. add_docstr_all(
  1020. "cosh_",
  1021. r"""
  1022. cosh_() -> Tensor
  1023. In-place version of :meth:`~Tensor.cosh`
  1024. """,
  1025. )
  1026. add_docstr_all(
  1027. "cpu",
  1028. r"""
  1029. cpu(memory_format=torch.preserve_format) -> Tensor
  1030. Returns a copy of this object in CPU memory.
  1031. If this object is already in CPU memory,
  1032. then no copy is performed and the original object is returned.
  1033. Args:
  1034. {memory_format}
  1035. """.format(**common_args),
  1036. )
  1037. add_docstr_all(
  1038. "count_nonzero",
  1039. r"""
  1040. count_nonzero(dim=None) -> Tensor
  1041. See :func:`torch.count_nonzero`
  1042. """,
  1043. )
  1044. add_docstr_all(
  1045. "cov",
  1046. r"""
  1047. cov(*, correction=1, fweights=None, aweights=None) -> Tensor
  1048. See :func:`torch.cov`
  1049. """,
  1050. )
  1051. add_docstr_all(
  1052. "corrcoef",
  1053. r"""
  1054. corrcoef() -> Tensor
  1055. See :func:`torch.corrcoef`
  1056. """,
  1057. )
  1058. add_docstr_all(
  1059. "cross",
  1060. r"""
  1061. cross(other, dim=None) -> Tensor
  1062. See :func:`torch.cross`
  1063. """,
  1064. )
  1065. add_docstr_all(
  1066. "cuda",
  1067. r"""
  1068. cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
  1069. Returns a copy of this object in CUDA memory.
  1070. If this object is already in CUDA memory and on the correct device,
  1071. then no copy is performed and the original object is returned.
  1072. Args:
  1073. device (:class:`torch.device`, optional): The destination GPU device.
  1074. Defaults to the current CUDA device.
  1075. non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
  1076. the copy will be asynchronous with respect to the host.
  1077. Otherwise, the argument has no effect. Default: ``False``.
  1078. {memory_format}
  1079. """.format(**common_args),
  1080. )
  1081. add_docstr_all(
  1082. "mtia",
  1083. r"""
  1084. mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
  1085. Returns a copy of this object in MTIA memory.
  1086. If this object is already in MTIA memory and on the correct device,
  1087. then no copy is performed and the original object is returned.
  1088. Args:
  1089. device (:class:`torch.device`, optional): The destination MTIA device.
  1090. Defaults to the current MTIA device.
  1091. non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
  1092. the copy will be asynchronous with respect to the host.
  1093. Otherwise, the argument has no effect. Default: ``False``.
  1094. {memory_format}
  1095. """.format(**common_args),
  1096. )
  1097. add_docstr_all(
  1098. "ipu",
  1099. r"""
  1100. ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
  1101. Returns a copy of this object in IPU memory.
  1102. If this object is already in IPU memory and on the correct device,
  1103. then no copy is performed and the original object is returned.
  1104. Args:
  1105. device (:class:`torch.device`, optional): The destination IPU device.
  1106. Defaults to the current IPU device.
  1107. non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
  1108. the copy will be asynchronous with respect to the host.
  1109. Otherwise, the argument has no effect. Default: ``False``.
  1110. {memory_format}
  1111. """.format(**common_args),
  1112. )
  1113. add_docstr_all(
  1114. "xpu",
  1115. r"""
  1116. xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
  1117. Returns a copy of this object in XPU memory.
  1118. If this object is already in XPU memory and on the correct device,
  1119. then no copy is performed and the original object is returned.
  1120. Args:
  1121. device (:class:`torch.device`, optional): The destination XPU device.
  1122. Defaults to the current XPU device.
  1123. non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
  1124. the copy will be asynchronous with respect to the host.
  1125. Otherwise, the argument has no effect. Default: ``False``.
  1126. {memory_format}
  1127. """.format(**common_args),
  1128. )
  1129. add_docstr_all(
  1130. "logcumsumexp",
  1131. r"""
  1132. logcumsumexp(dim) -> Tensor
  1133. See :func:`torch.logcumsumexp`
  1134. """,
  1135. )
  1136. add_docstr_all(
  1137. "cummax",
  1138. r"""
  1139. cummax(dim) -> (Tensor, Tensor)
  1140. See :func:`torch.cummax`
  1141. """,
  1142. )
  1143. add_docstr_all(
  1144. "cummin",
  1145. r"""
  1146. cummin(dim) -> (Tensor, Tensor)
  1147. See :func:`torch.cummin`
  1148. """,
  1149. )
  1150. add_docstr_all(
  1151. "cumprod",
  1152. r"""
  1153. cumprod(dim, dtype=None) -> Tensor
  1154. See :func:`torch.cumprod`
  1155. """,
  1156. )
  1157. add_docstr_all(
  1158. "cumprod_",
  1159. r"""
  1160. cumprod_(dim, dtype=None) -> Tensor
  1161. In-place version of :meth:`~Tensor.cumprod`
  1162. """,
  1163. )
  1164. add_docstr_all(
  1165. "cumsum",
  1166. r"""
  1167. cumsum(dim, dtype=None) -> Tensor
  1168. See :func:`torch.cumsum`
  1169. """,
  1170. )
  1171. add_docstr_all(
  1172. "cumsum_",
  1173. r"""
  1174. cumsum_(dim, dtype=None) -> Tensor
  1175. In-place version of :meth:`~Tensor.cumsum`
  1176. """,
  1177. )
  1178. add_docstr_all(
  1179. "data_ptr",
  1180. r"""
  1181. data_ptr() -> int
  1182. Returns the address of the first element of :attr:`self` tensor.
  1183. """,
  1184. )
  1185. add_docstr_all(
  1186. "dequantize",
  1187. r"""
  1188. dequantize() -> Tensor
  1189. Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
  1190. """,
  1191. )
  1192. add_docstr_all(
  1193. "dense_dim",
  1194. r"""
  1195. dense_dim() -> int
  1196. Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
  1197. .. note::
  1198. Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
  1199. See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
  1200. """,
  1201. )
  1202. add_docstr_all(
  1203. "diag",
  1204. r"""
  1205. diag(diagonal=0) -> Tensor
  1206. See :func:`torch.diag`
  1207. """,
  1208. )
  1209. add_docstr_all(
  1210. "diag_embed",
  1211. r"""
  1212. diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
  1213. See :func:`torch.diag_embed`
  1214. """,
  1215. )
  1216. add_docstr_all(
  1217. "diagflat",
  1218. r"""
  1219. diagflat(offset=0) -> Tensor
  1220. See :func:`torch.diagflat`
  1221. """,
  1222. )
  1223. add_docstr_all(
  1224. "diagonal",
  1225. r"""
  1226. diagonal(offset=0, dim1=0, dim2=1) -> Tensor
  1227. See :func:`torch.diagonal`
  1228. """,
  1229. )
  1230. add_docstr_all(
  1231. "diagonal_scatter",
  1232. r"""
  1233. diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
  1234. See :func:`torch.diagonal_scatter`
  1235. """,
  1236. )
  1237. add_docstr_all(
  1238. "as_strided_scatter",
  1239. r"""
  1240. as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
  1241. See :func:`torch.as_strided_scatter`
  1242. """,
  1243. )
  1244. add_docstr_all(
  1245. "fill_diagonal_",
  1246. r"""
  1247. fill_diagonal_(fill_value, wrap=False) -> Tensor
  1248. Fill the main diagonal of a tensor that has at least 2-dimensions.
  1249. When dims>2, all dimensions of input must be of equal length.
  1250. This function modifies the input tensor in-place, and returns the input tensor.
  1251. Arguments:
  1252. fill_value (Scalar): the fill value
  1253. wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
  1254. Example::
  1255. >>> a = torch.zeros(3, 3)
  1256. >>> a.fill_diagonal_(5)
  1257. tensor([[5., 0., 0.],
  1258. [0., 5., 0.],
  1259. [0., 0., 5.]])
  1260. >>> b = torch.zeros(7, 3)
  1261. >>> b.fill_diagonal_(5)
  1262. tensor([[5., 0., 0.],
  1263. [0., 5., 0.],
  1264. [0., 0., 5.],
  1265. [0., 0., 0.],
  1266. [0., 0., 0.],
  1267. [0., 0., 0.],
  1268. [0., 0., 0.]])
  1269. >>> c = torch.zeros(7, 3)
  1270. >>> c.fill_diagonal_(5, wrap=True)
  1271. tensor([[5., 0., 0.],
  1272. [0., 5., 0.],
  1273. [0., 0., 5.],
  1274. [0., 0., 0.],
  1275. [5., 0., 0.],
  1276. [0., 5., 0.],
  1277. [0., 0., 5.]])
  1278. """,
  1279. )
  1280. add_docstr_all(
  1281. "floor_divide",
  1282. r"""
  1283. floor_divide(value) -> Tensor
  1284. See :func:`torch.floor_divide`
  1285. """,
  1286. )
  1287. add_docstr_all(
  1288. "floor_divide_",
  1289. r"""
  1290. floor_divide_(value) -> Tensor
  1291. In-place version of :meth:`~Tensor.floor_divide`
  1292. """,
  1293. )
  1294. add_docstr_all(
  1295. "diff",
  1296. r"""
  1297. diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
  1298. See :func:`torch.diff`
  1299. """,
  1300. )
  1301. add_docstr_all(
  1302. "digamma",
  1303. r"""
  1304. digamma() -> Tensor
  1305. See :func:`torch.digamma`
  1306. """,
  1307. )
  1308. add_docstr_all(
  1309. "digamma_",
  1310. r"""
  1311. digamma_() -> Tensor
  1312. In-place version of :meth:`~Tensor.digamma`
  1313. """,
  1314. )
  1315. add_docstr_all(
  1316. "dim",
  1317. r"""
  1318. dim() -> int
  1319. Returns the number of dimensions of :attr:`self` tensor.
  1320. """,
  1321. )
  1322. add_docstr_all(
  1323. "dist",
  1324. r"""
  1325. dist(other, p=2) -> Tensor
  1326. See :func:`torch.dist`
  1327. """,
  1328. )
  1329. add_docstr_all(
  1330. "div",
  1331. r"""
  1332. div(value, *, rounding_mode=None) -> Tensor
  1333. See :func:`torch.div`
  1334. """,
  1335. )
  1336. add_docstr_all(
  1337. "div_",
  1338. r"""
  1339. div_(value, *, rounding_mode=None) -> Tensor
  1340. In-place version of :meth:`~Tensor.div`
  1341. """,
  1342. )
  1343. add_docstr_all(
  1344. "divide",
  1345. r"""
  1346. divide(value, *, rounding_mode=None) -> Tensor
  1347. See :func:`torch.divide`
  1348. """,
  1349. )
  1350. add_docstr_all(
  1351. "divide_",
  1352. r"""
  1353. divide_(value, *, rounding_mode=None) -> Tensor
  1354. In-place version of :meth:`~Tensor.divide`
  1355. """,
  1356. )
  1357. add_docstr_all(
  1358. "dot",
  1359. r"""
  1360. dot(other) -> Tensor
  1361. See :func:`torch.dot`
  1362. """,
  1363. )
  1364. add_docstr_all(
  1365. "element_size",
  1366. r"""
  1367. element_size() -> int
  1368. Returns the size in bytes of an individual element.
  1369. Example::
  1370. >>> torch.tensor([]).element_size()
  1371. 4
  1372. >>> torch.tensor([], dtype=torch.uint8).element_size()
  1373. 1
  1374. """,
  1375. )
  1376. add_docstr_all(
  1377. "eq",
  1378. r"""
  1379. eq(other) -> Tensor
  1380. See :func:`torch.eq`
  1381. """,
  1382. )
  1383. add_docstr_all(
  1384. "eq_",
  1385. r"""
  1386. eq_(other) -> Tensor
  1387. In-place version of :meth:`~Tensor.eq`
  1388. """,
  1389. )
  1390. add_docstr_all(
  1391. "equal",
  1392. r"""
  1393. equal(other) -> bool
  1394. See :func:`torch.equal`
  1395. """,
  1396. )
  1397. add_docstr_all(
  1398. "erf",
  1399. r"""
  1400. erf() -> Tensor
  1401. See :func:`torch.erf`
  1402. """,
  1403. )
  1404. add_docstr_all(
  1405. "erf_",
  1406. r"""
  1407. erf_() -> Tensor
  1408. In-place version of :meth:`~Tensor.erf`
  1409. """,
  1410. )
  1411. add_docstr_all(
  1412. "erfc",
  1413. r"""
  1414. erfc() -> Tensor
  1415. See :func:`torch.erfc`
  1416. """,
  1417. )
  1418. add_docstr_all(
  1419. "erfc_",
  1420. r"""
  1421. erfc_() -> Tensor
  1422. In-place version of :meth:`~Tensor.erfc`
  1423. """,
  1424. )
  1425. add_docstr_all(
  1426. "erfinv",
  1427. r"""
  1428. erfinv() -> Tensor
  1429. See :func:`torch.erfinv`
  1430. """,
  1431. )
  1432. add_docstr_all(
  1433. "erfinv_",
  1434. r"""
  1435. erfinv_() -> Tensor
  1436. In-place version of :meth:`~Tensor.erfinv`
  1437. """,
  1438. )
  1439. add_docstr_all(
  1440. "exp",
  1441. r"""
  1442. exp() -> Tensor
  1443. See :func:`torch.exp`
  1444. """,
  1445. )
  1446. add_docstr_all(
  1447. "exp_",
  1448. r"""
  1449. exp_() -> Tensor
  1450. In-place version of :meth:`~Tensor.exp`
  1451. """,
  1452. )
  1453. add_docstr_all(
  1454. "exp2",
  1455. r"""
  1456. exp2() -> Tensor
  1457. See :func:`torch.exp2`
  1458. """,
  1459. )
  1460. add_docstr_all(
  1461. "exp2_",
  1462. r"""
  1463. exp2_() -> Tensor
  1464. In-place version of :meth:`~Tensor.exp2`
  1465. """,
  1466. )
  1467. add_docstr_all(
  1468. "expm1",
  1469. r"""
  1470. expm1() -> Tensor
  1471. See :func:`torch.expm1`
  1472. """,
  1473. )
  1474. add_docstr_all(
  1475. "expm1_",
  1476. r"""
  1477. expm1_() -> Tensor
  1478. In-place version of :meth:`~Tensor.expm1`
  1479. """,
  1480. )
  1481. add_docstr_all(
  1482. "exponential_",
  1483. r"""
  1484. exponential_(lambd=1, *, generator=None) -> Tensor
  1485. Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
  1486. .. math::
  1487. f(x) = \lambda e^{-\lambda x}, x > 0
  1488. .. note::
  1489. In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
  1490. implying that zero can be sampled from the exponential distribution.
  1491. However, :func:`torch.Tensor.exponential_` does not sample zero,
  1492. which means that its actual support is the interval (0, :math:`\inf`).
  1493. Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
  1494. """,
  1495. )
  1496. add_docstr_all(
  1497. "fill_",
  1498. r"""
  1499. fill_(value) -> Tensor
  1500. Fills :attr:`self` tensor with the specified value.
  1501. """,
  1502. )
  1503. add_docstr_all(
  1504. "floor",
  1505. r"""
  1506. floor() -> Tensor
  1507. See :func:`torch.floor`
  1508. """,
  1509. )
  1510. add_docstr_all(
  1511. "flip",
  1512. r"""
  1513. flip(dims) -> Tensor
  1514. See :func:`torch.flip`
  1515. """,
  1516. )
  1517. add_docstr_all(
  1518. "fliplr",
  1519. r"""
  1520. fliplr() -> Tensor
  1521. See :func:`torch.fliplr`
  1522. """,
  1523. )
  1524. add_docstr_all(
  1525. "flipud",
  1526. r"""
  1527. flipud() -> Tensor
  1528. See :func:`torch.flipud`
  1529. """,
  1530. )
  1531. add_docstr_all(
  1532. "roll",
  1533. r"""
  1534. roll(shifts, dims) -> Tensor
  1535. See :func:`torch.roll`
  1536. """,
  1537. )
  1538. add_docstr_all(
  1539. "floor_",
  1540. r"""
  1541. floor_() -> Tensor
  1542. In-place version of :meth:`~Tensor.floor`
  1543. """,
  1544. )
  1545. add_docstr_all(
  1546. "fmod",
  1547. r"""
  1548. fmod(divisor) -> Tensor
  1549. See :func:`torch.fmod`
  1550. """,
  1551. )
  1552. add_docstr_all(
  1553. "fmod_",
  1554. r"""
  1555. fmod_(divisor) -> Tensor
  1556. In-place version of :meth:`~Tensor.fmod`
  1557. """,
  1558. )
  1559. add_docstr_all(
  1560. "frac",
  1561. r"""
  1562. frac() -> Tensor
  1563. See :func:`torch.frac`
  1564. """,
  1565. )
  1566. add_docstr_all(
  1567. "frac_",
  1568. r"""
  1569. frac_() -> Tensor
  1570. In-place version of :meth:`~Tensor.frac`
  1571. """,
  1572. )
  1573. add_docstr_all(
  1574. "frexp",
  1575. r"""
  1576. frexp(input) -> (Tensor mantissa, Tensor exponent)
  1577. See :func:`torch.frexp`
  1578. """,
  1579. )
  1580. add_docstr_all(
  1581. "flatten",
  1582. r"""
  1583. flatten(start_dim=0, end_dim=-1) -> Tensor
  1584. See :func:`torch.flatten`
  1585. """,
  1586. )
  1587. add_docstr_all(
  1588. "gather",
  1589. r"""
  1590. gather(dim, index) -> Tensor
  1591. See :func:`torch.gather`
  1592. """,
  1593. )
  1594. add_docstr_all(
  1595. "gcd",
  1596. r"""
  1597. gcd(other) -> Tensor
  1598. See :func:`torch.gcd`
  1599. """,
  1600. )
  1601. add_docstr_all(
  1602. "gcd_",
  1603. r"""
  1604. gcd_(other) -> Tensor
  1605. In-place version of :meth:`~Tensor.gcd`
  1606. """,
  1607. )
  1608. add_docstr_all(
  1609. "ge",
  1610. r"""
  1611. ge(other) -> Tensor
  1612. See :func:`torch.ge`.
  1613. """,
  1614. )
  1615. add_docstr_all(
  1616. "ge_",
  1617. r"""
  1618. ge_(other) -> Tensor
  1619. In-place version of :meth:`~Tensor.ge`.
  1620. """,
  1621. )
  1622. add_docstr_all(
  1623. "greater_equal",
  1624. r"""
  1625. greater_equal(other) -> Tensor
  1626. See :func:`torch.greater_equal`.
  1627. """,
  1628. )
  1629. add_docstr_all(
  1630. "greater_equal_",
  1631. r"""
  1632. greater_equal_(other) -> Tensor
  1633. In-place version of :meth:`~Tensor.greater_equal`.
  1634. """,
  1635. )
  1636. add_docstr_all(
  1637. "geometric_",
  1638. r"""
  1639. geometric_(p, *, generator=None) -> Tensor
  1640. Fills :attr:`self` tensor with elements drawn from the geometric distribution:
  1641. .. math::
  1642. P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
  1643. .. note::
  1644. :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
  1645. :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
  1646. hence draws samples in :math:`\{0, 1, \ldots\}`.
  1647. """,
  1648. )
  1649. add_docstr_all(
  1650. "geqrf",
  1651. r"""
  1652. geqrf() -> (Tensor, Tensor)
  1653. See :func:`torch.geqrf`
  1654. """,
  1655. )
  1656. add_docstr_all(
  1657. "ger",
  1658. r"""
  1659. ger(vec2) -> Tensor
  1660. See :func:`torch.ger`
  1661. """,
  1662. )
  1663. add_docstr_all(
  1664. "inner",
  1665. r"""
  1666. inner(other) -> Tensor
  1667. See :func:`torch.inner`.
  1668. """,
  1669. )
  1670. add_docstr_all(
  1671. "outer",
  1672. r"""
  1673. outer(vec2) -> Tensor
  1674. See :func:`torch.outer`.
  1675. """,
  1676. )
  1677. add_docstr_all(
  1678. "hypot",
  1679. r"""
  1680. hypot(other) -> Tensor
  1681. See :func:`torch.hypot`
  1682. """,
  1683. )
  1684. add_docstr_all(
  1685. "hypot_",
  1686. r"""
  1687. hypot_(other) -> Tensor
  1688. In-place version of :meth:`~Tensor.hypot`
  1689. """,
  1690. )
  1691. add_docstr_all(
  1692. "i0",
  1693. r"""
  1694. i0() -> Tensor
  1695. See :func:`torch.i0`
  1696. """,
  1697. )
  1698. add_docstr_all(
  1699. "i0_",
  1700. r"""
  1701. i0_() -> Tensor
  1702. In-place version of :meth:`~Tensor.i0`
  1703. """,
  1704. )
  1705. add_docstr_all(
  1706. "igamma",
  1707. r"""
  1708. igamma(other) -> Tensor
  1709. See :func:`torch.igamma`
  1710. """,
  1711. )
  1712. add_docstr_all(
  1713. "igamma_",
  1714. r"""
  1715. igamma_(other) -> Tensor
  1716. In-place version of :meth:`~Tensor.igamma`
  1717. """,
  1718. )
  1719. add_docstr_all(
  1720. "igammac",
  1721. r"""
  1722. igammac(other) -> Tensor
  1723. See :func:`torch.igammac`
  1724. """,
  1725. )
  1726. add_docstr_all(
  1727. "igammac_",
  1728. r"""
  1729. igammac_(other) -> Tensor
  1730. In-place version of :meth:`~Tensor.igammac`
  1731. """,
  1732. )
  1733. add_docstr_all(
  1734. "indices",
  1735. r"""
  1736. indices() -> Tensor
  1737. Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
  1738. .. warning::
  1739. Throws an error if :attr:`self` is not a sparse COO tensor.
  1740. See also :meth:`Tensor.values`.
  1741. .. note::
  1742. This method can only be called on a coalesced sparse tensor. See
  1743. :meth:`Tensor.coalesce` for details.
  1744. """,
  1745. )
  1746. add_docstr_all(
  1747. "get_device",
  1748. r"""
  1749. get_device() -> Device ordinal (Integer)
  1750. For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
  1751. For CPU tensors, this function returns `-1`.
  1752. Example::
  1753. >>> x = torch.randn(3, 4, 5, device='cuda:0')
  1754. >>> x.get_device()
  1755. 0
  1756. >>> x.cpu().get_device()
  1757. -1
  1758. """,
  1759. )
  1760. add_docstr_all(
  1761. "values",
  1762. r"""
  1763. values() -> Tensor
  1764. Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
  1765. .. warning::
  1766. Throws an error if :attr:`self` is not a sparse COO tensor.
  1767. See also :meth:`Tensor.indices`.
  1768. .. note::
  1769. This method can only be called on a coalesced sparse tensor. See
  1770. :meth:`Tensor.coalesce` for details.
  1771. """,
  1772. )
  1773. add_docstr_all(
  1774. "gt",
  1775. r"""
  1776. gt(other) -> Tensor
  1777. See :func:`torch.gt`.
  1778. """,
  1779. )
  1780. add_docstr_all(
  1781. "gt_",
  1782. r"""
  1783. gt_(other) -> Tensor
  1784. In-place version of :meth:`~Tensor.gt`.
  1785. """,
  1786. )
  1787. add_docstr_all(
  1788. "greater",
  1789. r"""
  1790. greater(other) -> Tensor
  1791. See :func:`torch.greater`.
  1792. """,
  1793. )
  1794. add_docstr_all(
  1795. "greater_",
  1796. r"""
  1797. greater_(other) -> Tensor
  1798. In-place version of :meth:`~Tensor.greater`.
  1799. """,
  1800. )
  1801. add_docstr_all(
  1802. "has_names",
  1803. r"""
  1804. Is ``True`` if any of this tensor's dimensions are named. Otherwise, is ``False``.
  1805. """,
  1806. )
  1807. add_docstr_all(
  1808. "hardshrink",
  1809. r"""
  1810. hardshrink(lambd=0.5) -> Tensor
  1811. See :func:`torch.nn.functional.hardshrink`
  1812. """,
  1813. )
  1814. add_docstr_all(
  1815. "heaviside",
  1816. r"""
  1817. heaviside(values) -> Tensor
  1818. See :func:`torch.heaviside`
  1819. """,
  1820. )
  1821. add_docstr_all(
  1822. "heaviside_",
  1823. r"""
  1824. heaviside_(values) -> Tensor
  1825. In-place version of :meth:`~Tensor.heaviside`
  1826. """,
  1827. )
  1828. add_docstr_all(
  1829. "histc",
  1830. r"""
  1831. histc(bins=100, min=0, max=0) -> Tensor
  1832. See :func:`torch.histc`
  1833. """,
  1834. )
  1835. add_docstr_all(
  1836. "histogram",
  1837. r"""
  1838. histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
  1839. See :func:`torch.histogram`
  1840. """,
  1841. )
  1842. add_docstr_all(
  1843. "index_add_",
  1844. r"""
  1845. index_add_(dim, index, source, *, alpha=1) -> Tensor
  1846. Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
  1847. tensor by adding to the indices in the order given in :attr:`index`. For example,
  1848. if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
  1849. ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
  1850. The :attr:`dim`\ th dimension of ``source`` must have the same size as the
  1851. length of :attr:`index` (which must be a vector), and all other dimensions must
  1852. match :attr:`self`, or an error will be raised.
  1853. For a 3-D tensor the output is given as::
  1854. self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
  1855. self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
  1856. self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
  1857. Note:
  1858. {forward_reproducibility_note}
  1859. Args:
  1860. dim (int): dimension along which to index
  1861. index (Tensor): indices of ``source`` to select from,
  1862. should have dtype either `torch.int64` or `torch.int32`
  1863. source (Tensor): the tensor containing values to add
  1864. Keyword args:
  1865. alpha (Number): the scalar multiplier for ``source``
  1866. Example::
  1867. >>> x = torch.ones(5, 3)
  1868. >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
  1869. >>> index = torch.tensor([0, 4, 2])
  1870. >>> x.index_add_(0, index, t)
  1871. tensor([[ 2., 3., 4.],
  1872. [ 1., 1., 1.],
  1873. [ 8., 9., 10.],
  1874. [ 1., 1., 1.],
  1875. [ 5., 6., 7.]])
  1876. >>> x.index_add_(0, index, t, alpha=-1)
  1877. tensor([[ 1., 1., 1.],
  1878. [ 1., 1., 1.],
  1879. [ 1., 1., 1.],
  1880. [ 1., 1., 1.],
  1881. [ 1., 1., 1.]])
  1882. """.format(**reproducibility_notes),
  1883. )
  1884. add_docstr_all(
  1885. "index_copy_",
  1886. r"""
  1887. index_copy_(dim, index, tensor) -> Tensor
  1888. Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
  1889. the indices in the order given in :attr:`index`. For example, if ``dim == 0``
  1890. and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
  1891. ``j``\ th row of :attr:`self`.
  1892. The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
  1893. length of :attr:`index` (which must be a vector), and all other dimensions must
  1894. match :attr:`self`, or an error will be raised.
  1895. .. note::
  1896. If :attr:`index` contains duplicate entries, multiple elements from
  1897. :attr:`tensor` will be copied to the same index of :attr:`self`. The result
  1898. is nondeterministic since it depends on which copy occurs last.
  1899. Args:
  1900. dim (int): dimension along which to index
  1901. index (LongTensor): indices of :attr:`tensor` to select from
  1902. tensor (Tensor): the tensor containing values to copy
  1903. Example::
  1904. >>> x = torch.zeros(5, 3)
  1905. >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
  1906. >>> index = torch.tensor([0, 4, 2])
  1907. >>> x.index_copy_(0, index, t)
  1908. tensor([[ 1., 2., 3.],
  1909. [ 0., 0., 0.],
  1910. [ 7., 8., 9.],
  1911. [ 0., 0., 0.],
  1912. [ 4., 5., 6.]])
  1913. """,
  1914. )
  1915. add_docstr_all(
  1916. "index_fill_",
  1917. r"""
  1918. index_fill_(dim, index, value) -> Tensor
  1919. Fills the elements of the :attr:`self` tensor with value :attr:`value` by
  1920. selecting the indices in the order given in :attr:`index`.
  1921. Args:
  1922. dim (int): dimension along which to index
  1923. index (LongTensor): indices of :attr:`self` tensor to fill in
  1924. value (float): the value to fill with
  1925. Example::
  1926. >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
  1927. >>> index = torch.tensor([0, 2])
  1928. >>> x.index_fill_(1, index, -1)
  1929. tensor([[-1., 2., -1.],
  1930. [-1., 5., -1.],
  1931. [-1., 8., -1.]])
  1932. """,
  1933. )
  1934. add_docstr_all(
  1935. "index_put_",
  1936. r"""
  1937. index_put_(indices, values, accumulate=False) -> Tensor
  1938. Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
  1939. the indices specified in :attr:`indices` (which is a tuple of Tensors). The
  1940. expression ``tensor.index_put_(indices, values)`` is equivalent to
  1941. ``tensor[indices] = values``. Returns :attr:`self`.
  1942. If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
  1943. :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
  1944. contain duplicate elements.
  1945. Args:
  1946. indices (tuple of LongTensor): tensors used to index into `self`.
  1947. values (Tensor): tensor of same dtype as `self`.
  1948. accumulate (bool): whether to accumulate into self
  1949. """,
  1950. )
  1951. add_docstr_all(
  1952. "index_put",
  1953. r"""
  1954. index_put(indices, values, accumulate=False) -> Tensor
  1955. Out-place version of :meth:`~Tensor.index_put_`.
  1956. """,
  1957. )
  1958. add_docstr_all(
  1959. "index_reduce_",
  1960. r"""
  1961. index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
  1962. Accumulate the elements of ``source`` into the :attr:`self`
  1963. tensor by accumulating to the indices in the order given in :attr:`index`
  1964. using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
  1965. ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
  1966. row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
  1967. :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
  1968. in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
  1969. to are treated as if they were filled with the reduction identities.
  1970. The :attr:`dim`\ th dimension of ``source`` must have the same size as the
  1971. length of :attr:`index` (which must be a vector), and all other dimensions must
  1972. match :attr:`self`, or an error will be raised.
  1973. For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
  1974. output is given as::
  1975. self[index[i], :, :] *= src[i, :, :] # if dim == 0
  1976. self[:, index[i], :] *= src[:, i, :] # if dim == 1
  1977. self[:, :, index[i]] *= src[:, :, i] # if dim == 2
  1978. Note:
  1979. {forward_reproducibility_note}
  1980. .. note::
  1981. This function only supports floating point tensors.
  1982. .. warning::
  1983. This function is in beta and may change in the near future.
  1984. Args:
  1985. dim (int): dimension along which to index
  1986. index (Tensor): indices of ``source`` to select from,
  1987. should have dtype either `torch.int64` or `torch.int32`
  1988. source (FloatTensor): the tensor containing values to accumulate
  1989. reduce (str): the reduction operation to apply
  1990. (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
  1991. Keyword args:
  1992. include_self (bool): whether the elements from the ``self`` tensor are
  1993. included in the reduction
  1994. Example::
  1995. >>> x = torch.empty(5, 3).fill_(2)
  1996. >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
  1997. >>> index = torch.tensor([0, 4, 2, 0])
  1998. >>> x.index_reduce_(0, index, t, 'prod')
  1999. tensor([[20., 44., 72.],
  2000. [ 2., 2., 2.],
  2001. [14., 16., 18.],
  2002. [ 2., 2., 2.],
  2003. [ 8., 10., 12.]])
  2004. >>> x = torch.empty(5, 3).fill_(2)
  2005. >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
  2006. tensor([[10., 22., 36.],
  2007. [ 2., 2., 2.],
  2008. [ 7., 8., 9.],
  2009. [ 2., 2., 2.],
  2010. [ 4., 5., 6.]])
  2011. """.format(**reproducibility_notes),
  2012. )
  2013. add_docstr_all(
  2014. "index_select",
  2015. r"""
  2016. index_select(dim, index) -> Tensor
  2017. See :func:`torch.index_select`
  2018. """,
  2019. )
  2020. add_docstr_all(
  2021. "sparse_mask",
  2022. r"""
  2023. sparse_mask(mask) -> Tensor
  2024. Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
  2025. strided tensor :attr:`self` filtered by the indices of the sparse
  2026. tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
  2027. ignored. :attr:`self` and :attr:`mask` tensors must have the same
  2028. shape.
  2029. .. note::
  2030. The returned sparse tensor might contain duplicate values if :attr:`mask`
  2031. is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
  2032. if such behavior is not desired.
  2033. .. note::
  2034. The returned sparse tensor has the same indices as the sparse tensor
  2035. :attr:`mask`, even when the corresponding values in :attr:`self` are
  2036. zeros.
  2037. Args:
  2038. mask (Tensor): a sparse tensor whose indices are used as a filter
  2039. Example::
  2040. >>> nse = 5
  2041. >>> dims = (5, 5, 2, 2)
  2042. >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
  2043. ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
  2044. >>> V = torch.randn(nse, dims[2], dims[3])
  2045. >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
  2046. >>> D = torch.randn(dims)
  2047. >>> D.sparse_mask(S)
  2048. tensor(indices=tensor([[0, 0, 0, 2],
  2049. [0, 1, 4, 3]]),
  2050. values=tensor([[[ 1.6550, 0.2397],
  2051. [-0.1611, -0.0779]],
  2052. [[ 0.2326, -1.0558],
  2053. [ 1.4711, 1.9678]],
  2054. [[-0.5138, -0.0411],
  2055. [ 1.9417, 0.5158]],
  2056. [[ 0.0793, 0.0036],
  2057. [-0.2569, -0.1055]]]),
  2058. size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
  2059. """,
  2060. )
  2061. add_docstr_all(
  2062. "inverse",
  2063. r"""
  2064. inverse() -> Tensor
  2065. See :func:`torch.inverse`
  2066. """,
  2067. )
  2068. add_docstr_all(
  2069. "isnan",
  2070. r"""
  2071. isnan() -> Tensor
  2072. See :func:`torch.isnan`
  2073. """,
  2074. )
  2075. add_docstr_all(
  2076. "isinf",
  2077. r"""
  2078. isinf() -> Tensor
  2079. See :func:`torch.isinf`
  2080. """,
  2081. )
  2082. add_docstr_all(
  2083. "isposinf",
  2084. r"""
  2085. isposinf() -> Tensor
  2086. See :func:`torch.isposinf`
  2087. """,
  2088. )
  2089. add_docstr_all(
  2090. "isneginf",
  2091. r"""
  2092. isneginf() -> Tensor
  2093. See :func:`torch.isneginf`
  2094. """,
  2095. )
  2096. add_docstr_all(
  2097. "isfinite",
  2098. r"""
  2099. isfinite() -> Tensor
  2100. See :func:`torch.isfinite`
  2101. """,
  2102. )
  2103. add_docstr_all(
  2104. "isclose",
  2105. r"""
  2106. isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
  2107. See :func:`torch.isclose`
  2108. """,
  2109. )
  2110. add_docstr_all(
  2111. "isreal",
  2112. r"""
  2113. isreal() -> Tensor
  2114. See :func:`torch.isreal`
  2115. """,
  2116. )
  2117. add_docstr_all(
  2118. "is_coalesced",
  2119. r"""
  2120. is_coalesced() -> bool
  2121. Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
  2122. <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
  2123. .. warning::
  2124. Throws an error if :attr:`self` is not a sparse COO tensor.
  2125. See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
  2126. """,
  2127. )
  2128. add_docstr_all(
  2129. "is_contiguous",
  2130. r"""
  2131. is_contiguous(memory_format=torch.contiguous_format) -> bool
  2132. Returns True if :attr:`self` tensor is contiguous in memory in the order specified
  2133. by memory format.
  2134. Args:
  2135. memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
  2136. order. Default: ``torch.contiguous_format``.
  2137. """,
  2138. )
  2139. add_docstr_all(
  2140. "is_pinned",
  2141. r"""
  2142. Returns true if this tensor resides in pinned memory.
  2143. By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
  2144. """,
  2145. )
  2146. add_docstr_all(
  2147. "is_floating_point",
  2148. r"""
  2149. is_floating_point() -> bool
  2150. Returns True if the data type of :attr:`self` is a floating point data type.
  2151. """,
  2152. )
  2153. add_docstr_all(
  2154. "is_complex",
  2155. r"""
  2156. is_complex() -> bool
  2157. Returns True if the data type of :attr:`self` is a complex data type.
  2158. """,
  2159. )
  2160. add_docstr_all(
  2161. "is_inference",
  2162. r"""
  2163. is_inference() -> bool
  2164. See :func:`torch.is_inference`
  2165. """,
  2166. )
  2167. add_docstr_all(
  2168. "is_conj",
  2169. r"""
  2170. is_conj() -> bool
  2171. Returns True if the conjugate bit of :attr:`self` is set to true.
  2172. """,
  2173. )
  2174. add_docstr_all(
  2175. "is_neg",
  2176. r"""
  2177. is_neg() -> bool
  2178. Returns True if the negative bit of :attr:`self` is set to true.
  2179. """,
  2180. )
  2181. add_docstr_all(
  2182. "is_signed",
  2183. r"""
  2184. is_signed() -> bool
  2185. Returns True if the data type of :attr:`self` is a signed data type.
  2186. """,
  2187. )
  2188. add_docstr_all(
  2189. "is_set_to",
  2190. r"""
  2191. is_set_to(tensor) -> bool
  2192. Returns True if both tensors are pointing to the exact same memory (same
  2193. storage, offset, size and stride).
  2194. """,
  2195. )
  2196. add_docstr_all(
  2197. "item",
  2198. r"""
  2199. item() -> number
  2200. Returns the value of this tensor as a standard Python number. This only works
  2201. for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
  2202. This operation is not differentiable.
  2203. Example::
  2204. >>> x = torch.tensor([1.0])
  2205. >>> x.item()
  2206. 1.0
  2207. """,
  2208. )
  2209. add_docstr_all(
  2210. "kron",
  2211. r"""
  2212. kron(other) -> Tensor
  2213. See :func:`torch.kron`
  2214. """,
  2215. )
  2216. add_docstr_all(
  2217. "kthvalue",
  2218. r"""
  2219. kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
  2220. See :func:`torch.kthvalue`
  2221. """,
  2222. )
  2223. add_docstr_all(
  2224. "ldexp",
  2225. r"""
  2226. ldexp(other) -> Tensor
  2227. See :func:`torch.ldexp`
  2228. """,
  2229. )
  2230. add_docstr_all(
  2231. "ldexp_",
  2232. r"""
  2233. ldexp_(other) -> Tensor
  2234. In-place version of :meth:`~Tensor.ldexp`
  2235. """,
  2236. )
  2237. add_docstr_all(
  2238. "lcm",
  2239. r"""
  2240. lcm(other) -> Tensor
  2241. See :func:`torch.lcm`
  2242. """,
  2243. )
  2244. add_docstr_all(
  2245. "lcm_",
  2246. r"""
  2247. lcm_(other) -> Tensor
  2248. In-place version of :meth:`~Tensor.lcm`
  2249. """,
  2250. )
  2251. add_docstr_all(
  2252. "le",
  2253. r"""
  2254. le(other) -> Tensor
  2255. See :func:`torch.le`.
  2256. """,
  2257. )
  2258. add_docstr_all(
  2259. "le_",
  2260. r"""
  2261. le_(other) -> Tensor
  2262. In-place version of :meth:`~Tensor.le`.
  2263. """,
  2264. )
  2265. add_docstr_all(
  2266. "less_equal",
  2267. r"""
  2268. less_equal(other) -> Tensor
  2269. See :func:`torch.less_equal`.
  2270. """,
  2271. )
  2272. add_docstr_all(
  2273. "less_equal_",
  2274. r"""
  2275. less_equal_(other) -> Tensor
  2276. In-place version of :meth:`~Tensor.less_equal`.
  2277. """,
  2278. )
  2279. add_docstr_all(
  2280. "lerp",
  2281. r"""
  2282. lerp(end, weight) -> Tensor
  2283. See :func:`torch.lerp`
  2284. """,
  2285. )
  2286. add_docstr_all(
  2287. "lerp_",
  2288. r"""
  2289. lerp_(end, weight) -> Tensor
  2290. In-place version of :meth:`~Tensor.lerp`
  2291. """,
  2292. )
  2293. add_docstr_all(
  2294. "lgamma",
  2295. r"""
  2296. lgamma() -> Tensor
  2297. See :func:`torch.lgamma`
  2298. """,
  2299. )
  2300. add_docstr_all(
  2301. "lgamma_",
  2302. r"""
  2303. lgamma_() -> Tensor
  2304. In-place version of :meth:`~Tensor.lgamma`
  2305. """,
  2306. )
  2307. add_docstr_all(
  2308. "log",
  2309. r"""
  2310. log() -> Tensor
  2311. See :func:`torch.log`
  2312. """,
  2313. )
  2314. add_docstr_all(
  2315. "log_",
  2316. r"""
  2317. log_() -> Tensor
  2318. In-place version of :meth:`~Tensor.log`
  2319. """,
  2320. )
  2321. add_docstr_all(
  2322. "log10",
  2323. r"""
  2324. log10() -> Tensor
  2325. See :func:`torch.log10`
  2326. """,
  2327. )
  2328. add_docstr_all(
  2329. "log10_",
  2330. r"""
  2331. log10_() -> Tensor
  2332. In-place version of :meth:`~Tensor.log10`
  2333. """,
  2334. )
  2335. add_docstr_all(
  2336. "log1p",
  2337. r"""
  2338. log1p() -> Tensor
  2339. See :func:`torch.log1p`
  2340. """,
  2341. )
  2342. add_docstr_all(
  2343. "log1p_",
  2344. r"""
  2345. log1p_() -> Tensor
  2346. In-place version of :meth:`~Tensor.log1p`
  2347. """,
  2348. )
  2349. add_docstr_all(
  2350. "log2",
  2351. r"""
  2352. log2() -> Tensor
  2353. See :func:`torch.log2`
  2354. """,
  2355. )
  2356. add_docstr_all(
  2357. "log2_",
  2358. r"""
  2359. log2_() -> Tensor
  2360. In-place version of :meth:`~Tensor.log2`
  2361. """,
  2362. )
  2363. add_docstr_all(
  2364. "logaddexp",
  2365. r"""
  2366. logaddexp(other) -> Tensor
  2367. See :func:`torch.logaddexp`
  2368. """,
  2369. )
  2370. add_docstr_all(
  2371. "logaddexp2",
  2372. r"""
  2373. logaddexp2(other) -> Tensor
  2374. See :func:`torch.logaddexp2`
  2375. """,
  2376. )
  2377. add_docstr_all(
  2378. "log_normal_",
  2379. r"""
  2380. log_normal_(mean=1, std=2, *, generator=None)
  2381. Fills :attr:`self` tensor with numbers samples from the log-normal distribution
  2382. parameterized by the given mean :math:`\mu` and standard deviation
  2383. :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
  2384. standard deviation of the underlying normal distribution, and not of the
  2385. returned distribution:
  2386. .. math::
  2387. f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
  2388. """,
  2389. )
  2390. add_docstr_all(
  2391. "logsumexp",
  2392. r"""
  2393. logsumexp(dim, keepdim=False) -> Tensor
  2394. See :func:`torch.logsumexp`
  2395. """,
  2396. )
  2397. add_docstr_all(
  2398. "lt",
  2399. r"""
  2400. lt(other) -> Tensor
  2401. See :func:`torch.lt`.
  2402. """,
  2403. )
  2404. add_docstr_all(
  2405. "lt_",
  2406. r"""
  2407. lt_(other) -> Tensor
  2408. In-place version of :meth:`~Tensor.lt`.
  2409. """,
  2410. )
  2411. add_docstr_all(
  2412. "less",
  2413. r"""
  2414. lt(other) -> Tensor
  2415. See :func:`torch.less`.
  2416. """,
  2417. )
  2418. add_docstr_all(
  2419. "less_",
  2420. r"""
  2421. less_(other) -> Tensor
  2422. In-place version of :meth:`~Tensor.less`.
  2423. """,
  2424. )
  2425. add_docstr_all(
  2426. "lu_solve",
  2427. r"""
  2428. lu_solve(LU_data, LU_pivots) -> Tensor
  2429. See :func:`torch.lu_solve`
  2430. """,
  2431. )
  2432. add_docstr_all(
  2433. "map_",
  2434. r"""
  2435. map_(tensor, callable)
  2436. Applies :attr:`callable` for each element in :attr:`self` tensor and the given
  2437. :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
  2438. the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
  2439. The :attr:`callable` should have the signature::
  2440. def callable(a, b) -> number
  2441. """,
  2442. )
  2443. add_docstr_all(
  2444. "masked_scatter_",
  2445. r"""
  2446. masked_scatter_(mask, source)
  2447. Copies elements from :attr:`source` into :attr:`self` tensor at positions where
  2448. the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
  2449. starting at position 0 of :attr:`source` and continuing in order one-by-one for each
  2450. occurrence of :attr:`mask` being True.
  2451. The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
  2452. with the shape of the underlying tensor. The :attr:`source` should have at least
  2453. as many elements as the number of ones in :attr:`mask`.
  2454. Args:
  2455. mask (BoolTensor): the boolean mask
  2456. source (Tensor): the tensor to copy from
  2457. .. note::
  2458. The :attr:`mask` operates on the :attr:`self` tensor, not on the given
  2459. :attr:`source` tensor.
  2460. Example:
  2461. >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
  2462. >>> mask = torch.tensor(
  2463. ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
  2464. ... dtype=torch.bool,
  2465. ... )
  2466. >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
  2467. >>> self.masked_scatter_(mask, source)
  2468. tensor([[0, 0, 0, 0, 1],
  2469. [2, 3, 0, 4, 5]])
  2470. """,
  2471. )
  2472. add_docstr_all(
  2473. "masked_fill_",
  2474. r"""
  2475. masked_fill_(mask, value)
  2476. Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
  2477. True. The shape of :attr:`mask` must be
  2478. :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
  2479. tensor.
  2480. Args:
  2481. mask (BoolTensor): the boolean mask
  2482. value (float): the value to fill in with
  2483. """,
  2484. )
  2485. add_docstr_all(
  2486. "masked_select",
  2487. r"""
  2488. masked_select(mask) -> Tensor
  2489. See :func:`torch.masked_select`
  2490. """,
  2491. )
  2492. add_docstr_all(
  2493. "matrix_power",
  2494. r"""
  2495. matrix_power(n) -> Tensor
  2496. .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
  2497. Alias for :func:`torch.linalg.matrix_power`
  2498. """,
  2499. )
  2500. add_docstr_all(
  2501. "matrix_exp",
  2502. r"""
  2503. matrix_exp() -> Tensor
  2504. See :func:`torch.matrix_exp`
  2505. """,
  2506. )
  2507. add_docstr_all(
  2508. "max",
  2509. r"""
  2510. max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
  2511. See :func:`torch.max`
  2512. """,
  2513. )
  2514. add_docstr_all(
  2515. "amax",
  2516. r"""
  2517. amax(dim=None, keepdim=False) -> Tensor
  2518. See :func:`torch.amax`
  2519. """,
  2520. )
  2521. add_docstr_all(
  2522. "maximum",
  2523. r"""
  2524. maximum(other) -> Tensor
  2525. See :func:`torch.maximum`
  2526. """,
  2527. )
  2528. add_docstr_all(
  2529. "fmax",
  2530. r"""
  2531. fmax(other) -> Tensor
  2532. See :func:`torch.fmax`
  2533. """,
  2534. )
  2535. add_docstr_all(
  2536. "argmax",
  2537. r"""
  2538. argmax(dim=None, keepdim=False) -> LongTensor
  2539. See :func:`torch.argmax`
  2540. """,
  2541. )
  2542. add_docstr_all(
  2543. "argwhere",
  2544. r"""
  2545. argwhere() -> Tensor
  2546. See :func:`torch.argwhere`
  2547. """,
  2548. )
  2549. add_docstr_all(
  2550. "mean",
  2551. r"""
  2552. mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
  2553. See :func:`torch.mean`
  2554. """,
  2555. )
  2556. add_docstr_all(
  2557. "nanmean",
  2558. r"""
  2559. nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
  2560. See :func:`torch.nanmean`
  2561. """,
  2562. )
  2563. add_docstr_all(
  2564. "median",
  2565. r"""
  2566. median(dim=None, keepdim=False) -> (Tensor, LongTensor)
  2567. See :func:`torch.median`
  2568. """,
  2569. )
  2570. add_docstr_all(
  2571. "nanmedian",
  2572. r"""
  2573. nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
  2574. See :func:`torch.nanmedian`
  2575. """,
  2576. )
  2577. add_docstr_all(
  2578. "min",
  2579. r"""
  2580. min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
  2581. See :func:`torch.min`
  2582. """,
  2583. )
  2584. add_docstr_all(
  2585. "amin",
  2586. r"""
  2587. amin(dim=None, keepdim=False) -> Tensor
  2588. See :func:`torch.amin`
  2589. """,
  2590. )
  2591. add_docstr_all(
  2592. "minimum",
  2593. r"""
  2594. minimum(other) -> Tensor
  2595. See :func:`torch.minimum`
  2596. """,
  2597. )
  2598. add_docstr_all(
  2599. "aminmax",
  2600. r"""
  2601. aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
  2602. See :func:`torch.aminmax`
  2603. """,
  2604. )
  2605. add_docstr_all(
  2606. "fmin",
  2607. r"""
  2608. fmin(other) -> Tensor
  2609. See :func:`torch.fmin`
  2610. """,
  2611. )
  2612. add_docstr_all(
  2613. "argmin",
  2614. r"""
  2615. argmin(dim=None, keepdim=False) -> LongTensor
  2616. See :func:`torch.argmin`
  2617. """,
  2618. )
  2619. add_docstr_all(
  2620. "mm",
  2621. r"""
  2622. mm(mat2) -> Tensor
  2623. See :func:`torch.mm`
  2624. """,
  2625. )
  2626. add_docstr_all(
  2627. "mode",
  2628. r"""
  2629. mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
  2630. See :func:`torch.mode`
  2631. """,
  2632. )
  2633. add_docstr_all(
  2634. "movedim",
  2635. r"""
  2636. movedim(source, destination) -> Tensor
  2637. See :func:`torch.movedim`
  2638. """,
  2639. )
  2640. add_docstr_all(
  2641. "moveaxis",
  2642. r"""
  2643. moveaxis(source, destination) -> Tensor
  2644. See :func:`torch.moveaxis`
  2645. """,
  2646. )
  2647. add_docstr_all(
  2648. "mul",
  2649. r"""
  2650. mul(value) -> Tensor
  2651. See :func:`torch.mul`.
  2652. """,
  2653. )
  2654. add_docstr_all(
  2655. "mul_",
  2656. r"""
  2657. mul_(value) -> Tensor
  2658. In-place version of :meth:`~Tensor.mul`.
  2659. """,
  2660. )
  2661. add_docstr_all(
  2662. "multiply",
  2663. r"""
  2664. multiply(value) -> Tensor
  2665. See :func:`torch.multiply`.
  2666. """,
  2667. )
  2668. add_docstr_all(
  2669. "multiply_",
  2670. r"""
  2671. multiply_(value) -> Tensor
  2672. In-place version of :meth:`~Tensor.multiply`.
  2673. """,
  2674. )
  2675. add_docstr_all(
  2676. "multinomial",
  2677. r"""
  2678. multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
  2679. See :func:`torch.multinomial`
  2680. """,
  2681. )
  2682. add_docstr_all(
  2683. "mv",
  2684. r"""
  2685. mv(vec) -> Tensor
  2686. See :func:`torch.mv`
  2687. """,
  2688. )
  2689. add_docstr_all(
  2690. "mvlgamma",
  2691. r"""
  2692. mvlgamma(p) -> Tensor
  2693. See :func:`torch.mvlgamma`
  2694. """,
  2695. )
  2696. add_docstr_all(
  2697. "mvlgamma_",
  2698. r"""
  2699. mvlgamma_(p) -> Tensor
  2700. In-place version of :meth:`~Tensor.mvlgamma`
  2701. """,
  2702. )
  2703. add_docstr_all(
  2704. "narrow",
  2705. r"""
  2706. narrow(dimension, start, length) -> Tensor
  2707. See :func:`torch.narrow`.
  2708. """,
  2709. )
  2710. add_docstr_all(
  2711. "narrow_copy",
  2712. r"""
  2713. narrow_copy(dimension, start, length) -> Tensor
  2714. See :func:`torch.narrow_copy`.
  2715. """,
  2716. )
  2717. add_docstr_all(
  2718. "ndimension",
  2719. r"""
  2720. ndimension() -> int
  2721. Alias for :meth:`~Tensor.dim()`
  2722. """,
  2723. )
  2724. add_docstr_all(
  2725. "nan_to_num",
  2726. r"""
  2727. nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
  2728. See :func:`torch.nan_to_num`.
  2729. """,
  2730. )
  2731. add_docstr_all(
  2732. "nan_to_num_",
  2733. r"""
  2734. nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
  2735. In-place version of :meth:`~Tensor.nan_to_num`.
  2736. """,
  2737. )
  2738. add_docstr_all(
  2739. "ne",
  2740. r"""
  2741. ne(other) -> Tensor
  2742. See :func:`torch.ne`.
  2743. """,
  2744. )
  2745. add_docstr_all(
  2746. "ne_",
  2747. r"""
  2748. ne_(other) -> Tensor
  2749. In-place version of :meth:`~Tensor.ne`.
  2750. """,
  2751. )
  2752. add_docstr_all(
  2753. "not_equal",
  2754. r"""
  2755. not_equal(other) -> Tensor
  2756. See :func:`torch.not_equal`.
  2757. """,
  2758. )
  2759. add_docstr_all(
  2760. "not_equal_",
  2761. r"""
  2762. not_equal_(other) -> Tensor
  2763. In-place version of :meth:`~Tensor.not_equal`.
  2764. """,
  2765. )
  2766. add_docstr_all(
  2767. "neg",
  2768. r"""
  2769. neg() -> Tensor
  2770. See :func:`torch.neg`
  2771. """,
  2772. )
  2773. add_docstr_all(
  2774. "negative",
  2775. r"""
  2776. negative() -> Tensor
  2777. See :func:`torch.negative`
  2778. """,
  2779. )
  2780. add_docstr_all(
  2781. "neg_",
  2782. r"""
  2783. neg_() -> Tensor
  2784. In-place version of :meth:`~Tensor.neg`
  2785. """,
  2786. )
  2787. add_docstr_all(
  2788. "negative_",
  2789. r"""
  2790. negative_() -> Tensor
  2791. In-place version of :meth:`~Tensor.negative`
  2792. """,
  2793. )
  2794. add_docstr_all(
  2795. "nelement",
  2796. r"""
  2797. nelement() -> int
  2798. Alias for :meth:`~Tensor.numel`
  2799. """,
  2800. )
  2801. add_docstr_all(
  2802. "nextafter",
  2803. r"""
  2804. nextafter(other) -> Tensor
  2805. See :func:`torch.nextafter`
  2806. """,
  2807. )
  2808. add_docstr_all(
  2809. "nextafter_",
  2810. r"""
  2811. nextafter_(other) -> Tensor
  2812. In-place version of :meth:`~Tensor.nextafter`
  2813. """,
  2814. )
  2815. add_docstr_all(
  2816. "nonzero",
  2817. r"""
  2818. nonzero() -> LongTensor
  2819. See :func:`torch.nonzero`
  2820. """,
  2821. )
  2822. add_docstr_all(
  2823. "nonzero_static",
  2824. r"""
  2825. nonzero_static(input, *, size, fill_value=-1) -> Tensor
  2826. Returns a 2-D tensor where each row is the index for a non-zero value.
  2827. The returned Tensor has the same `torch.dtype` as `torch.nonzero()`.
  2828. Args:
  2829. input (Tensor): the input tensor to count non-zero elements.
  2830. Keyword args:
  2831. size (int): the size of non-zero elements expected to be included in the out
  2832. tensor. Pad the out tensor with `fill_value` if the `size` is larger
  2833. than total number of non-zero elements, truncate out tensor if `size`
  2834. is smaller. The size must be a non-negative integer.
  2835. fill_value (int, optional): the value to fill the output tensor with when `size` is larger
  2836. than the total number of non-zero elements. Default is `-1` to represent
  2837. invalid index.
  2838. Example:
  2839. # Example 1: Padding
  2840. >>> input_tensor = torch.tensor([[1, 0], [3, 2]])
  2841. >>> static_size = 4
  2842. >>> t = torch.nonzero_static(input_tensor, size=static_size)
  2843. tensor([[ 0, 0],
  2844. [ 1, 0],
  2845. [ 1, 1],
  2846. [ -1, -1]], dtype=torch.int64)
  2847. # Example 2: Truncating
  2848. >>> input_tensor = torch.tensor([[1, 0], [3, 2]])
  2849. >>> static_size = 2
  2850. >>> t = torch.nonzero_static(input_tensor, size=static_size)
  2851. tensor([[ 0, 0],
  2852. [ 1, 0]], dtype=torch.int64)
  2853. # Example 3: 0 size
  2854. >>> input_tensor = torch.tensor([10])
  2855. >>> static_size = 0
  2856. >>> t = torch.nonzero_static(input_tensor, size=static_size)
  2857. tensor([], size=(0, 1), dtype=torch.int64)
  2858. # Example 4: 0 rank input
  2859. >>> input_tensor = torch.tensor(10)
  2860. >>> static_size = 2
  2861. >>> t = torch.nonzero_static(input_tensor, size=static_size)
  2862. tensor([], size=(2, 0), dtype=torch.int64)
  2863. """,
  2864. )
  2865. add_docstr_all(
  2866. "norm",
  2867. r"""
  2868. norm(p=2, dim=None, keepdim=False) -> Tensor
  2869. See :func:`torch.norm`
  2870. """,
  2871. )
  2872. add_docstr_all(
  2873. "normal_",
  2874. r"""
  2875. normal_(mean=0, std=1, *, generator=None) -> Tensor
  2876. Fills :attr:`self` tensor with elements samples from the normal distribution
  2877. parameterized by :attr:`mean` and :attr:`std`.
  2878. """,
  2879. )
  2880. add_docstr_all(
  2881. "numel",
  2882. r"""
  2883. numel() -> int
  2884. See :func:`torch.numel`
  2885. """,
  2886. )
  2887. add_docstr_all(
  2888. "numpy",
  2889. r"""
  2890. numpy(*, force=False) -> numpy.ndarray
  2891. Returns the tensor as a NumPy :class:`ndarray`.
  2892. If :attr:`force` is ``False`` (the default), the conversion
  2893. is performed only if the tensor is on the CPU, does not require grad,
  2894. does not have its conjugate bit set, and is a dtype and layout that
  2895. NumPy supports. The returned ndarray and the tensor will share their
  2896. storage, so changes to the tensor will be reflected in the ndarray
  2897. and vice versa.
  2898. If :attr:`force` is ``True`` this is equivalent to
  2899. calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
  2900. If the tensor isn't on the CPU or the conjugate or negative bit is set,
  2901. the tensor won't share its storage with the returned ndarray.
  2902. Setting :attr:`force` to ``True`` can be a useful shorthand.
  2903. Args:
  2904. force (bool): if ``True``, the ndarray may be a copy of the tensor
  2905. instead of always sharing memory, defaults to ``False``.
  2906. """,
  2907. )
  2908. add_docstr_all(
  2909. "orgqr",
  2910. r"""
  2911. orgqr(input2) -> Tensor
  2912. See :func:`torch.orgqr`
  2913. """,
  2914. )
  2915. add_docstr_all(
  2916. "ormqr",
  2917. r"""
  2918. ormqr(input2, input3, left=True, transpose=False) -> Tensor
  2919. See :func:`torch.ormqr`
  2920. """,
  2921. )
  2922. add_docstr_all(
  2923. "permute",
  2924. r"""
  2925. permute(*dims) -> Tensor
  2926. Returns a view of the tensor with its dimensions permuted.
  2927. Args:
  2928. dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
  2929. Example:
  2930. >>> x = torch.randn(2, 3, 5)
  2931. >>> x.size()
  2932. torch.Size([2, 3, 5])
  2933. >>> x.permute(2, 0, 1).size()
  2934. torch.Size([5, 2, 3])
  2935. """,
  2936. )
  2937. add_docstr_all(
  2938. "polygamma",
  2939. r"""
  2940. polygamma(n) -> Tensor
  2941. See :func:`torch.polygamma`
  2942. """,
  2943. )
  2944. add_docstr_all(
  2945. "polygamma_",
  2946. r"""
  2947. polygamma_(n) -> Tensor
  2948. In-place version of :meth:`~Tensor.polygamma`
  2949. """,
  2950. )
  2951. add_docstr_all(
  2952. "positive",
  2953. r"""
  2954. positive() -> Tensor
  2955. See :func:`torch.positive`
  2956. """,
  2957. )
  2958. add_docstr_all(
  2959. "pow",
  2960. r"""
  2961. pow(exponent) -> Tensor
  2962. See :func:`torch.pow`
  2963. """,
  2964. )
  2965. add_docstr_all(
  2966. "pow_",
  2967. r"""
  2968. pow_(exponent) -> Tensor
  2969. In-place version of :meth:`~Tensor.pow`
  2970. """,
  2971. )
  2972. add_docstr_all(
  2973. "float_power",
  2974. r"""
  2975. float_power(exponent) -> Tensor
  2976. See :func:`torch.float_power`
  2977. """,
  2978. )
  2979. add_docstr_all(
  2980. "float_power_",
  2981. r"""
  2982. float_power_(exponent) -> Tensor
  2983. In-place version of :meth:`~Tensor.float_power`
  2984. """,
  2985. )
  2986. add_docstr_all(
  2987. "prod",
  2988. r"""
  2989. prod(dim=None, keepdim=False, dtype=None) -> Tensor
  2990. See :func:`torch.prod`
  2991. """,
  2992. )
  2993. add_docstr_all(
  2994. "put_",
  2995. r"""
  2996. put_(index, source, accumulate=False) -> Tensor
  2997. Copies the elements from :attr:`source` into the positions specified by
  2998. :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
  2999. it were a 1-D tensor.
  3000. :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
  3001. the same shape.
  3002. If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
  3003. :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
  3004. contain duplicate elements.
  3005. Args:
  3006. index (LongTensor): the indices into self
  3007. source (Tensor): the tensor containing values to copy from
  3008. accumulate (bool, optional): whether to accumulate into self. Default: ``False``
  3009. Example::
  3010. >>> src = torch.tensor([[4, 3, 5],
  3011. ... [6, 7, 8]])
  3012. >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
  3013. tensor([[ 4, 9, 5],
  3014. [ 10, 7, 8]])
  3015. """,
  3016. )
  3017. add_docstr_all(
  3018. "put",
  3019. r"""
  3020. put(input, index, source, accumulate=False) -> Tensor
  3021. Out-of-place version of :meth:`torch.Tensor.put_`.
  3022. `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
  3023. """,
  3024. )
  3025. add_docstr_all(
  3026. "qr",
  3027. r"""
  3028. qr(some=True) -> (Tensor, Tensor)
  3029. See :func:`torch.qr`
  3030. """,
  3031. )
  3032. add_docstr_all(
  3033. "qscheme",
  3034. r"""
  3035. qscheme() -> torch.qscheme
  3036. Returns the quantization scheme of a given QTensor.
  3037. """,
  3038. )
  3039. add_docstr_all(
  3040. "quantile",
  3041. r"""
  3042. quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
  3043. See :func:`torch.quantile`
  3044. """,
  3045. )
  3046. add_docstr_all(
  3047. "nanquantile",
  3048. r"""
  3049. nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
  3050. See :func:`torch.nanquantile`
  3051. """,
  3052. )
  3053. add_docstr_all(
  3054. "q_scale",
  3055. r"""
  3056. q_scale() -> float
  3057. Given a Tensor quantized by linear(affine) quantization,
  3058. returns the scale of the underlying quantizer().
  3059. """,
  3060. )
  3061. add_docstr_all(
  3062. "q_zero_point",
  3063. r"""
  3064. q_zero_point() -> int
  3065. Given a Tensor quantized by linear(affine) quantization,
  3066. returns the zero_point of the underlying quantizer().
  3067. """,
  3068. )
  3069. add_docstr_all(
  3070. "q_per_channel_scales",
  3071. r"""
  3072. q_per_channel_scales() -> Tensor
  3073. Given a Tensor quantized by linear (affine) per-channel quantization,
  3074. returns a Tensor of scales of the underlying quantizer. It has the number of
  3075. elements that matches the corresponding dimensions (from q_per_channel_axis) of
  3076. the tensor.
  3077. """,
  3078. )
  3079. add_docstr_all(
  3080. "q_per_channel_zero_points",
  3081. r"""
  3082. q_per_channel_zero_points() -> Tensor
  3083. Given a Tensor quantized by linear (affine) per-channel quantization,
  3084. returns a tensor of zero_points of the underlying quantizer. It has the number of
  3085. elements that matches the corresponding dimensions (from q_per_channel_axis) of
  3086. the tensor.
  3087. """,
  3088. )
  3089. add_docstr_all(
  3090. "q_per_channel_axis",
  3091. r"""
  3092. q_per_channel_axis() -> int
  3093. Given a Tensor quantized by linear (affine) per-channel quantization,
  3094. returns the index of dimension on which per-channel quantization is applied.
  3095. """,
  3096. )
  3097. add_docstr_all(
  3098. "random_",
  3099. r"""
  3100. random_(from=0, to=None, *, generator=None) -> Tensor
  3101. Fills :attr:`self` tensor with numbers sampled from the discrete uniform
  3102. distribution over ``[from, to - 1]``. If not specified, the values are usually
  3103. only bounded by :attr:`self` tensor's data type. However, for floating point
  3104. types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
  3105. value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
  3106. will be uniform in ``[0, 2^53]``.
  3107. """,
  3108. )
  3109. add_docstr_all(
  3110. "rad2deg",
  3111. r"""
  3112. rad2deg() -> Tensor
  3113. See :func:`torch.rad2deg`
  3114. """,
  3115. )
  3116. add_docstr_all(
  3117. "rad2deg_",
  3118. r"""
  3119. rad2deg_() -> Tensor
  3120. In-place version of :meth:`~Tensor.rad2deg`
  3121. """,
  3122. )
  3123. add_docstr_all(
  3124. "deg2rad",
  3125. r"""
  3126. deg2rad() -> Tensor
  3127. See :func:`torch.deg2rad`
  3128. """,
  3129. )
  3130. add_docstr_all(
  3131. "deg2rad_",
  3132. r"""
  3133. deg2rad_() -> Tensor
  3134. In-place version of :meth:`~Tensor.deg2rad`
  3135. """,
  3136. )
  3137. add_docstr_all(
  3138. "ravel",
  3139. r"""
  3140. ravel() -> Tensor
  3141. see :func:`torch.ravel`
  3142. """,
  3143. )
  3144. add_docstr_all(
  3145. "reciprocal",
  3146. r"""
  3147. reciprocal() -> Tensor
  3148. See :func:`torch.reciprocal`
  3149. """,
  3150. )
  3151. add_docstr_all(
  3152. "reciprocal_",
  3153. r"""
  3154. reciprocal_() -> Tensor
  3155. In-place version of :meth:`~Tensor.reciprocal`
  3156. """,
  3157. )
  3158. add_docstr_all(
  3159. "record_stream",
  3160. r"""
  3161. record_stream(stream)
  3162. Marks the tensor as having been used by this stream. When the tensor
  3163. is deallocated, ensure the tensor memory is not reused for another tensor
  3164. until all work queued on :attr:`stream` at the time of deallocation is
  3165. complete.
  3166. .. note::
  3167. The caching allocator is aware of only the stream where a tensor was
  3168. allocated. Due to the awareness, it already correctly manages the life
  3169. cycle of tensors on only one stream. But if a tensor is used on a stream
  3170. different from the stream of origin, the allocator might reuse the memory
  3171. unexpectedly. Calling this method lets the allocator know which streams
  3172. have used the tensor.
  3173. .. warning::
  3174. This method is most suitable for use cases where you are providing a
  3175. function that created a tensor on a side stream, and want users to be able
  3176. to make use of the tensor without having to think carefully about stream
  3177. safety when making use of them. These safety guarantees come at some
  3178. performance and predictability cost (analogous to the tradeoff between GC
  3179. and manual memory management), so if you are in a situation where
  3180. you manage the full lifetime of your tensors, you may consider instead
  3181. manually managing CUDA events so that calling this method is not necessary.
  3182. In particular, when you call this method, on later allocations the
  3183. allocator will poll the recorded stream to see if all operations have
  3184. completed yet; you can potentially race with side stream computation and
  3185. non-deterministically reuse or fail to reuse memory for an allocation.
  3186. You can safely use tensors allocated on side streams without
  3187. :meth:`~Tensor.record_stream`; you must manually ensure that
  3188. any non-creation stream uses of a tensor are synced back to the creation
  3189. stream before you deallocate the tensor. As the CUDA caching allocator
  3190. guarantees that the memory will only be reused with the same creation stream,
  3191. this is sufficient to ensure that writes to future reallocations of the
  3192. memory will be delayed until non-creation stream uses are done.
  3193. (Counterintuitively, you may observe that on the CPU side we have already
  3194. reallocated the tensor, even though CUDA kernels on the old tensor are
  3195. still in progress. This is fine, because CUDA operations on the new
  3196. tensor will appropriately wait for the old operations to complete, as they
  3197. are all on the same stream.)
  3198. Concretely, this looks like this::
  3199. with torch.cuda.stream(s0):
  3200. x = torch.zeros(N)
  3201. s1.wait_stream(s0)
  3202. with torch.cuda.stream(s1):
  3203. y = some_comm_op(x)
  3204. ... some compute on s0 ...
  3205. # synchronize creation stream s0 to side stream s1
  3206. # before deallocating x
  3207. s0.wait_stream(s1)
  3208. del x
  3209. Note that some discretion is required when deciding when to perform
  3210. ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
  3211. after ``some_comm_op``, there wouldn't be any point in having the side
  3212. stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
  3213. Instead, the synchronization must be placed at some appropriate, later
  3214. point in time where you expect the side stream ``s1`` to have finished
  3215. work. This location is typically identified via profiling, e.g., using
  3216. Chrome traces produced
  3217. :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
  3218. place the wait too early, work on s0 will block until ``s1`` has finished,
  3219. preventing further overlapping of communication and computation. If you
  3220. place the wait too late, you will use more memory than is strictly
  3221. necessary (as you are keeping ``x`` live for longer.) For a concrete
  3222. example of how this guidance can be applied in practice, see this post:
  3223. `FSDP and CUDACachingAllocator
  3224. <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
  3225. """,
  3226. )
  3227. add_docstr_all(
  3228. "remainder",
  3229. r"""
  3230. remainder(divisor) -> Tensor
  3231. See :func:`torch.remainder`
  3232. """,
  3233. )
  3234. add_docstr_all(
  3235. "remainder_",
  3236. r"""
  3237. remainder_(divisor) -> Tensor
  3238. In-place version of :meth:`~Tensor.remainder`
  3239. """,
  3240. )
  3241. add_docstr_all(
  3242. "renorm",
  3243. r"""
  3244. renorm(p, dim, maxnorm) -> Tensor
  3245. See :func:`torch.renorm`
  3246. """,
  3247. )
  3248. add_docstr_all(
  3249. "renorm_",
  3250. r"""
  3251. renorm_(p, dim, maxnorm) -> Tensor
  3252. In-place version of :meth:`~Tensor.renorm`
  3253. """,
  3254. )
  3255. add_docstr_all(
  3256. "repeat",
  3257. r"""
  3258. repeat(*repeats) -> Tensor
  3259. Repeats this tensor along the specified dimensions.
  3260. Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
  3261. .. warning::
  3262. :meth:`~Tensor.repeat` behaves differently from
  3263. `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
  3264. but is more similar to
  3265. `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
  3266. For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
  3267. Args:
  3268. repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
  3269. Example::
  3270. >>> x = torch.tensor([1, 2, 3])
  3271. >>> x.repeat(4, 2)
  3272. tensor([[ 1, 2, 3, 1, 2, 3],
  3273. [ 1, 2, 3, 1, 2, 3],
  3274. [ 1, 2, 3, 1, 2, 3],
  3275. [ 1, 2, 3, 1, 2, 3]])
  3276. >>> x.repeat(4, 2, 1).size()
  3277. torch.Size([4, 2, 3])
  3278. """,
  3279. )
  3280. add_docstr_all(
  3281. "repeat_interleave",
  3282. r"""
  3283. repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
  3284. See :func:`torch.repeat_interleave`.
  3285. """,
  3286. )
  3287. add_docstr_all(
  3288. "requires_grad_",
  3289. r"""
  3290. requires_grad_(requires_grad=True) -> Tensor
  3291. Change if autograd should record operations on this tensor: sets this tensor's
  3292. :attr:`requires_grad` attribute in-place. Returns this tensor.
  3293. :func:`requires_grad_`'s main use case is to tell autograd to begin recording
  3294. operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
  3295. (because it was obtained through a DataLoader, or required preprocessing or
  3296. initialization), ``tensor.requires_grad_()`` makes it so that autograd will
  3297. begin to record operations on ``tensor``.
  3298. Args:
  3299. requires_grad (bool): If autograd should record operations on this tensor.
  3300. Default: ``True``.
  3301. Example::
  3302. >>> # Let's say we want to preprocess some saved weights and use
  3303. >>> # the result as new weights.
  3304. >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
  3305. >>> loaded_weights = torch.tensor(saved_weights)
  3306. >>> weights = preprocess(loaded_weights) # some function
  3307. >>> weights
  3308. tensor([-0.5503, 0.4926, -2.1158, -0.8303])
  3309. >>> # Now, start to record operations done to weights
  3310. >>> weights.requires_grad_()
  3311. >>> out = weights.pow(2).sum()
  3312. >>> out.backward()
  3313. >>> weights.grad
  3314. tensor([-1.1007, 0.9853, -4.2316, -1.6606])
  3315. """,
  3316. )
  3317. add_docstr_all(
  3318. "reshape",
  3319. r"""
  3320. reshape(*shape) -> Tensor
  3321. Returns a tensor with the same data and number of elements as :attr:`self`
  3322. but with the specified shape. This method returns a view if :attr:`shape` is
  3323. compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
  3324. possible to return a view.
  3325. See :func:`torch.reshape`
  3326. Args:
  3327. shape (tuple of ints or int...): the desired shape
  3328. """,
  3329. )
  3330. add_docstr_all(
  3331. "reshape_as",
  3332. r"""
  3333. reshape_as(other) -> Tensor
  3334. Returns this tensor as the same shape as :attr:`other`.
  3335. ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
  3336. This method returns a view if ``other.sizes()`` is compatible with the current
  3337. shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
  3338. Please see :meth:`reshape` for more information about ``reshape``.
  3339. Args:
  3340. other (:class:`torch.Tensor`): The result tensor has the same shape
  3341. as :attr:`other`.
  3342. """,
  3343. )
  3344. add_docstr_all(
  3345. "resize_",
  3346. r"""
  3347. resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
  3348. Resizes :attr:`self` tensor to the specified size. If the number of elements is
  3349. larger than the current storage size, then the underlying storage is resized
  3350. to fit the new number of elements. If the number of elements is smaller, the
  3351. underlying storage is not changed. Existing elements are preserved but any new
  3352. memory is uninitialized.
  3353. .. warning::
  3354. This is a low-level method. The storage is reinterpreted as C-contiguous,
  3355. ignoring the current strides (unless the target size equals the current
  3356. size, in which case the tensor is left unchanged). For most purposes, you
  3357. will instead want to use :meth:`~Tensor.view()`, which checks for
  3358. contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
  3359. change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
  3360. .. note::
  3361. If :func:`torch.use_deterministic_algorithms()` and
  3362. :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
  3363. ``True``, new elements are initialized to prevent nondeterministic behavior
  3364. from using the result as an input to an operation. Floating point and
  3365. complex values are set to NaN, and integer values are set to the maximum
  3366. value.
  3367. Args:
  3368. sizes (torch.Size or int...): the desired size
  3369. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  3370. Tensor. Default: ``torch.contiguous_format``. Note that memory format of
  3371. :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
  3372. Example::
  3373. >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
  3374. >>> x.resize_(2, 2)
  3375. tensor([[ 1, 2],
  3376. [ 3, 4]])
  3377. """,
  3378. )
  3379. add_docstr_all(
  3380. "resize_as_",
  3381. r"""
  3382. resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
  3383. Resizes the :attr:`self` tensor to be the same size as the specified
  3384. :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
  3385. Args:
  3386. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  3387. Tensor. Default: ``torch.contiguous_format``. Note that memory format of
  3388. :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
  3389. """,
  3390. )
  3391. add_docstr_all(
  3392. "rot90",
  3393. r"""
  3394. rot90(k, dims) -> Tensor
  3395. See :func:`torch.rot90`
  3396. """,
  3397. )
  3398. add_docstr_all(
  3399. "round",
  3400. r"""
  3401. round(decimals=0) -> Tensor
  3402. See :func:`torch.round`
  3403. """,
  3404. )
  3405. add_docstr_all(
  3406. "round_",
  3407. r"""
  3408. round_(decimals=0) -> Tensor
  3409. In-place version of :meth:`~Tensor.round`
  3410. """,
  3411. )
  3412. add_docstr_all(
  3413. "rsqrt",
  3414. r"""
  3415. rsqrt() -> Tensor
  3416. See :func:`torch.rsqrt`
  3417. """,
  3418. )
  3419. add_docstr_all(
  3420. "rsqrt_",
  3421. r"""
  3422. rsqrt_() -> Tensor
  3423. In-place version of :meth:`~Tensor.rsqrt`
  3424. """,
  3425. )
  3426. add_docstr_all(
  3427. "scatter_",
  3428. r"""
  3429. scatter_(dim, index, src, *, reduce=None) -> Tensor
  3430. Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
  3431. specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
  3432. index is specified by its index in :attr:`src` for ``dimension != dim`` and by
  3433. the corresponding value in :attr:`index` for ``dimension = dim``.
  3434. For a 3-D tensor, :attr:`self` is updated as::
  3435. self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
  3436. self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
  3437. self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
  3438. This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
  3439. It is also required that
  3440. ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
  3441. ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
  3442. Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
  3443. so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
  3444. Standard broadcasting occurs in all other cases.
  3445. Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
  3446. between ``0`` and ``self.size(dim) - 1`` inclusive.
  3447. .. warning::
  3448. When indices are not unique, the behavior is non-deterministic (one of the
  3449. values from ``src`` will be picked arbitrarily) and the gradient will be
  3450. incorrect (it will be propagated to all locations in the source that
  3451. correspond to the same index)!
  3452. .. note::
  3453. The backward pass is implemented only for ``src.shape == index.shape``.
  3454. Additionally accepts an optional :attr:`reduce` argument that allows
  3455. specification of an optional reduction operation, which is applied to all
  3456. values in the tensor :attr:`src` into :attr:`self` at the indices
  3457. specified in the :attr:`index`. For each value in :attr:`src`, the reduction
  3458. operation is applied to an index in :attr:`self` which is specified by
  3459. its index in :attr:`src` for ``dimension != dim`` and by the corresponding
  3460. value in :attr:`index` for ``dimension = dim``.
  3461. Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
  3462. is updated as::
  3463. self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
  3464. self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
  3465. self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
  3466. Reducing with the addition operation is the same as using
  3467. :meth:`~torch.Tensor.scatter_add_`.
  3468. .. warning::
  3469. The reduce argument with Tensor ``src`` is deprecated and will be removed in
  3470. a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
  3471. instead for more reduction options.
  3472. Args:
  3473. dim (int): the axis along which to index
  3474. index (LongTensor): the indices of elements to scatter, can be either empty
  3475. or of the same dimensionality as ``src``. When empty, the operation
  3476. returns ``self`` unchanged.
  3477. src (Tensor): the source element(s) to scatter.
  3478. Keyword args:
  3479. reduce (str, optional): reduction operation to apply, can be either
  3480. ``'add'`` or ``'multiply'``.
  3481. Example::
  3482. >>> src = torch.arange(1, 11).reshape((2, 5))
  3483. >>> src
  3484. tensor([[ 1, 2, 3, 4, 5],
  3485. [ 6, 7, 8, 9, 10]])
  3486. >>> index = torch.tensor([[0, 1, 2, 0]])
  3487. >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
  3488. tensor([[1, 0, 0, 4, 0],
  3489. [0, 2, 0, 0, 0],
  3490. [0, 0, 3, 0, 0]])
  3491. >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
  3492. >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
  3493. tensor([[1, 2, 3, 0, 0],
  3494. [6, 7, 0, 0, 8],
  3495. [0, 0, 0, 0, 0]])
  3496. >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
  3497. ... 1.23, reduce='multiply')
  3498. tensor([[2.0000, 2.0000, 2.4600, 2.0000],
  3499. [2.0000, 2.0000, 2.0000, 2.4600]])
  3500. >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
  3501. ... 1.23, reduce='add')
  3502. tensor([[2.0000, 2.0000, 3.2300, 2.0000],
  3503. [2.0000, 2.0000, 2.0000, 3.2300]])
  3504. .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
  3505. :noindex:
  3506. Writes the value from :attr:`value` into :attr:`self` at the indices
  3507. specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
  3508. with the :attr:`src` tensor filled entirely with :attr:`value`.
  3509. Args:
  3510. dim (int): the axis along which to index
  3511. index (LongTensor): the indices of elements to scatter, can be either empty
  3512. or of the same dimensionality as ``src``. When empty, the operation
  3513. returns ``self`` unchanged.
  3514. value (Scalar): the value to scatter.
  3515. Keyword args:
  3516. reduce (str, optional): reduction operation to apply, can be either
  3517. ``'add'`` or ``'multiply'``.
  3518. Example::
  3519. >>> index = torch.tensor([[0, 1]])
  3520. >>> value = 2
  3521. >>> torch.zeros(3, 5).scatter_(0, index, value)
  3522. tensor([[2., 0., 0., 0., 0.],
  3523. [0., 2., 0., 0., 0.],
  3524. [0., 0., 0., 0., 0.]])
  3525. """,
  3526. )
  3527. add_docstr_all(
  3528. "scatter_add_",
  3529. r"""
  3530. scatter_add_(dim, index, src) -> Tensor
  3531. Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
  3532. specified in the :attr:`index` tensor in a similar fashion as
  3533. :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
  3534. an index in :attr:`self` which is specified by its index in :attr:`src`
  3535. for ``dimension != dim`` and by the corresponding value in :attr:`index` for
  3536. ``dimension = dim``.
  3537. For a 3-D tensor, :attr:`self` is updated as::
  3538. self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
  3539. self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
  3540. self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
  3541. :attr:`self`, :attr:`index` and :attr:`src` should have same number of
  3542. dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
  3543. dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
  3544. ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
  3545. When :attr:`index` is empty, we always return the original tensor
  3546. without further error checking.
  3547. Note:
  3548. {forward_reproducibility_note}
  3549. .. note::
  3550. The backward pass is implemented only for ``src.shape == index.shape``.
  3551. Args:
  3552. dim (int): the axis along which to index
  3553. index (LongTensor): the indices of elements to scatter and add, can be
  3554. either empty or of the same dimensionality as ``src``. When empty, the
  3555. operation returns ``self`` unchanged.
  3556. src (Tensor): the source elements to scatter and add
  3557. Example::
  3558. >>> src = torch.ones((2, 5))
  3559. >>> index = torch.tensor([[0, 1, 2, 0, 0]])
  3560. >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
  3561. tensor([[1., 0., 0., 1., 1.],
  3562. [0., 1., 0., 0., 0.],
  3563. [0., 0., 1., 0., 0.]])
  3564. >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
  3565. >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
  3566. tensor([[2., 0., 0., 1., 1.],
  3567. [0., 2., 0., 0., 0.],
  3568. [0., 0., 2., 1., 1.]])
  3569. """.format(**reproducibility_notes),
  3570. )
  3571. add_docstr_all(
  3572. "scatter_reduce_",
  3573. r"""
  3574. scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
  3575. Reduces all values from the :attr:`src` tensor to the indices specified in
  3576. the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
  3577. defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
  3578. :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
  3579. index in :attr:`self` which is specified by its index in :attr:`src` for
  3580. ``dimension != dim`` and by the corresponding value in :attr:`index` for
  3581. ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
  3582. tensor are included in the reduction.
  3583. :attr:`self`, :attr:`index` and :attr:`src` should all have
  3584. the same number of dimensions. It is also required that
  3585. ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
  3586. ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
  3587. Note that ``index`` and ``src`` do not broadcast.
  3588. For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
  3589. output is given as::
  3590. self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
  3591. self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
  3592. self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
  3593. Note:
  3594. {forward_reproducibility_note}
  3595. .. note::
  3596. The backward pass is implemented only for ``src.shape == index.shape``.
  3597. .. warning::
  3598. This function is in beta and may change in the near future.
  3599. Args:
  3600. dim (int): the axis along which to index
  3601. index (LongTensor): the indices of elements to scatter and reduce.
  3602. src (Tensor): the source elements to scatter and reduce
  3603. reduce (str): the reduction operation to apply for non-unique indices
  3604. (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
  3605. include_self (bool): whether elements from the :attr:`self` tensor are
  3606. included in the reduction
  3607. Example::
  3608. >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
  3609. >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
  3610. >>> input = torch.tensor([1., 2., 3., 4.])
  3611. >>> input.scatter_reduce(0, index, src, reduce="sum")
  3612. tensor([5., 14., 8., 4.])
  3613. >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
  3614. tensor([4., 12., 5., 4.])
  3615. >>> input2 = torch.tensor([5., 4., 3., 2.])
  3616. >>> input2.scatter_reduce(0, index, src, reduce="amax")
  3617. tensor([5., 6., 5., 2.])
  3618. >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
  3619. tensor([3., 6., 5., 2.])
  3620. """.format(**reproducibility_notes),
  3621. )
  3622. add_docstr_all(
  3623. "select",
  3624. r"""
  3625. select(dim, index) -> Tensor
  3626. See :func:`torch.select`
  3627. """,
  3628. )
  3629. add_docstr_all(
  3630. "select_scatter",
  3631. r"""
  3632. select_scatter(src, dim, index) -> Tensor
  3633. See :func:`torch.select_scatter`
  3634. """,
  3635. )
  3636. add_docstr_all(
  3637. "slice_scatter",
  3638. r"""
  3639. slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
  3640. See :func:`torch.slice_scatter`
  3641. """,
  3642. )
  3643. add_docstr_all(
  3644. "set_",
  3645. r"""
  3646. set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
  3647. Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
  3648. :attr:`self` tensor will share the same storage and have the same size and
  3649. strides as :attr:`source`. Changes to elements in one tensor will be reflected
  3650. in the other.
  3651. If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
  3652. storage, offset, size, and stride.
  3653. Args:
  3654. source (Tensor or Storage): the tensor or storage to use
  3655. storage_offset (int, optional): the offset in the storage
  3656. size (torch.Size, optional): the desired size. Defaults to the size of the source.
  3657. stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
  3658. """,
  3659. )
  3660. add_docstr_all(
  3661. "sigmoid",
  3662. r"""
  3663. sigmoid() -> Tensor
  3664. See :func:`torch.sigmoid`
  3665. """,
  3666. )
  3667. add_docstr_all(
  3668. "sigmoid_",
  3669. r"""
  3670. sigmoid_() -> Tensor
  3671. In-place version of :meth:`~Tensor.sigmoid`
  3672. """,
  3673. )
  3674. add_docstr_all(
  3675. "logit",
  3676. r"""
  3677. logit() -> Tensor
  3678. See :func:`torch.logit`
  3679. """,
  3680. )
  3681. add_docstr_all(
  3682. "logit_",
  3683. r"""
  3684. logit_() -> Tensor
  3685. In-place version of :meth:`~Tensor.logit`
  3686. """,
  3687. )
  3688. add_docstr_all(
  3689. "sign",
  3690. r"""
  3691. sign() -> Tensor
  3692. See :func:`torch.sign`
  3693. """,
  3694. )
  3695. add_docstr_all(
  3696. "sign_",
  3697. r"""
  3698. sign_() -> Tensor
  3699. In-place version of :meth:`~Tensor.sign`
  3700. """,
  3701. )
  3702. add_docstr_all(
  3703. "signbit",
  3704. r"""
  3705. signbit() -> Tensor
  3706. See :func:`torch.signbit`
  3707. """,
  3708. )
  3709. add_docstr_all(
  3710. "sgn",
  3711. r"""
  3712. sgn() -> Tensor
  3713. See :func:`torch.sgn`
  3714. """,
  3715. )
  3716. add_docstr_all(
  3717. "sgn_",
  3718. r"""
  3719. sgn_() -> Tensor
  3720. In-place version of :meth:`~Tensor.sgn`
  3721. """,
  3722. )
  3723. add_docstr_all(
  3724. "sin",
  3725. r"""
  3726. sin() -> Tensor
  3727. See :func:`torch.sin`
  3728. """,
  3729. )
  3730. add_docstr_all(
  3731. "sin_",
  3732. r"""
  3733. sin_() -> Tensor
  3734. In-place version of :meth:`~Tensor.sin`
  3735. """,
  3736. )
  3737. add_docstr_all(
  3738. "sinc",
  3739. r"""
  3740. sinc() -> Tensor
  3741. See :func:`torch.sinc`
  3742. """,
  3743. )
  3744. add_docstr_all(
  3745. "sinc_",
  3746. r"""
  3747. sinc_() -> Tensor
  3748. In-place version of :meth:`~Tensor.sinc`
  3749. """,
  3750. )
  3751. add_docstr_all(
  3752. "sinh",
  3753. r"""
  3754. sinh() -> Tensor
  3755. See :func:`torch.sinh`
  3756. """,
  3757. )
  3758. add_docstr_all(
  3759. "sinh_",
  3760. r"""
  3761. sinh_() -> Tensor
  3762. In-place version of :meth:`~Tensor.sinh`
  3763. """,
  3764. )
  3765. add_docstr_all(
  3766. "size",
  3767. r"""
  3768. size(dim=None) -> torch.Size or int
  3769. Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
  3770. the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
  3771. If ``dim`` is specified, returns an int holding the size of that dimension.
  3772. Args:
  3773. dim (int, optional): The dimension for which to retrieve the size.
  3774. Example::
  3775. >>> t = torch.empty(3, 4, 5)
  3776. >>> t.size()
  3777. torch.Size([3, 4, 5])
  3778. >>> t.size(dim=1)
  3779. 4
  3780. """,
  3781. )
  3782. add_docstr_all(
  3783. "shape",
  3784. r"""
  3785. shape() -> torch.Size
  3786. Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
  3787. See also :meth:`Tensor.size`.
  3788. Example::
  3789. >>> t = torch.empty(3, 4, 5)
  3790. >>> t.size()
  3791. torch.Size([3, 4, 5])
  3792. >>> t.shape
  3793. torch.Size([3, 4, 5])
  3794. """,
  3795. )
  3796. add_docstr_all(
  3797. "sort",
  3798. r"""
  3799. sort(dim=-1, descending=False) -> (Tensor, LongTensor)
  3800. See :func:`torch.sort`
  3801. """,
  3802. )
  3803. add_docstr_all(
  3804. "msort",
  3805. r"""
  3806. msort() -> Tensor
  3807. See :func:`torch.msort`
  3808. """,
  3809. )
  3810. add_docstr_all(
  3811. "argsort",
  3812. r"""
  3813. argsort(dim=-1, descending=False) -> LongTensor
  3814. See :func:`torch.argsort`
  3815. """,
  3816. )
  3817. add_docstr_all(
  3818. "sparse_dim",
  3819. r"""
  3820. sparse_dim() -> int
  3821. Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
  3822. .. note::
  3823. Returns ``0`` if :attr:`self` is not a sparse tensor.
  3824. See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
  3825. """,
  3826. )
  3827. add_docstr_all(
  3828. "sparse_resize_",
  3829. r"""
  3830. sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
  3831. Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
  3832. size and the number of sparse and dense dimensions.
  3833. .. note::
  3834. If the number of specified elements in :attr:`self` is zero, then
  3835. :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
  3836. size and positive integers such that ``len(size) == sparse_dim +
  3837. dense_dim``.
  3838. If :attr:`self` specifies one or more elements, however, then each
  3839. dimension in :attr:`size` must not be smaller than the corresponding
  3840. dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
  3841. of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
  3842. equal the number of dense dimensions in :attr:`self`.
  3843. .. warning::
  3844. Throws an error if :attr:`self` is not a sparse tensor.
  3845. Args:
  3846. size (torch.Size): the desired size. If :attr:`self` is non-empty
  3847. sparse tensor, the desired size cannot be smaller than the
  3848. original size.
  3849. sparse_dim (int): the number of sparse dimensions
  3850. dense_dim (int): the number of dense dimensions
  3851. """,
  3852. )
  3853. add_docstr_all(
  3854. "sparse_resize_and_clear_",
  3855. r"""
  3856. sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
  3857. Removes all specified elements from a :ref:`sparse tensor
  3858. <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
  3859. size and the number of sparse and dense dimensions.
  3860. .. warning:
  3861. Throws an error if :attr:`self` is not a sparse tensor.
  3862. Args:
  3863. size (torch.Size): the desired size.
  3864. sparse_dim (int): the number of sparse dimensions
  3865. dense_dim (int): the number of dense dimensions
  3866. """,
  3867. )
  3868. add_docstr_all(
  3869. "sqrt",
  3870. r"""
  3871. sqrt() -> Tensor
  3872. See :func:`torch.sqrt`
  3873. """,
  3874. )
  3875. add_docstr_all(
  3876. "sqrt_",
  3877. r"""
  3878. sqrt_() -> Tensor
  3879. In-place version of :meth:`~Tensor.sqrt`
  3880. """,
  3881. )
  3882. add_docstr_all(
  3883. "square",
  3884. r"""
  3885. square() -> Tensor
  3886. See :func:`torch.square`
  3887. """,
  3888. )
  3889. add_docstr_all(
  3890. "square_",
  3891. r"""
  3892. square_() -> Tensor
  3893. In-place version of :meth:`~Tensor.square`
  3894. """,
  3895. )
  3896. add_docstr_all(
  3897. "squeeze",
  3898. r"""
  3899. squeeze(dim=None) -> Tensor
  3900. See :func:`torch.squeeze`
  3901. """,
  3902. )
  3903. add_docstr_all(
  3904. "squeeze_",
  3905. r"""
  3906. squeeze_(dim=None) -> Tensor
  3907. In-place version of :meth:`~Tensor.squeeze`
  3908. """,
  3909. )
  3910. add_docstr_all(
  3911. "std",
  3912. r"""
  3913. std(dim=None, *, correction=1, keepdim=False) -> Tensor
  3914. See :func:`torch.std`
  3915. """,
  3916. )
  3917. add_docstr_all(
  3918. "storage_offset",
  3919. r"""
  3920. storage_offset() -> int
  3921. Returns :attr:`self` tensor's offset in the underlying storage in terms of
  3922. number of storage elements (not bytes).
  3923. Example::
  3924. >>> x = torch.tensor([1, 2, 3, 4, 5])
  3925. >>> x.storage_offset()
  3926. 0
  3927. >>> x[3:].storage_offset()
  3928. 3
  3929. """,
  3930. )
  3931. add_docstr_all(
  3932. "untyped_storage",
  3933. r"""
  3934. untyped_storage() -> torch.UntypedStorage
  3935. Returns the underlying :class:`UntypedStorage`.
  3936. """,
  3937. )
  3938. add_docstr_all(
  3939. "stride",
  3940. r"""
  3941. stride(dim) -> tuple or int
  3942. Returns the stride of :attr:`self` tensor.
  3943. Stride is the jump necessary to go from one element to the next one in the
  3944. specified dimension :attr:`dim`. A tuple of all strides is returned when no
  3945. argument is passed in. Otherwise, an integer value is returned as the stride in
  3946. the particular dimension :attr:`dim`.
  3947. Args:
  3948. dim (int, optional): the desired dimension in which stride is required
  3949. Example::
  3950. >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
  3951. >>> x.stride()
  3952. (5, 1)
  3953. >>> x.stride(0)
  3954. 5
  3955. >>> x.stride(-1)
  3956. 1
  3957. """,
  3958. )
  3959. add_docstr_all(
  3960. "sub",
  3961. r"""
  3962. sub(other, *, alpha=1) -> Tensor
  3963. See :func:`torch.sub`.
  3964. """,
  3965. )
  3966. add_docstr_all(
  3967. "sub_",
  3968. r"""
  3969. sub_(other, *, alpha=1) -> Tensor
  3970. In-place version of :meth:`~Tensor.sub`
  3971. """,
  3972. )
  3973. add_docstr_all(
  3974. "subtract",
  3975. r"""
  3976. subtract(other, *, alpha=1) -> Tensor
  3977. See :func:`torch.subtract`.
  3978. """,
  3979. )
  3980. add_docstr_all(
  3981. "subtract_",
  3982. r"""
  3983. subtract_(other, *, alpha=1) -> Tensor
  3984. In-place version of :meth:`~Tensor.subtract`.
  3985. """,
  3986. )
  3987. add_docstr_all(
  3988. "sum",
  3989. r"""
  3990. sum(dim=None, keepdim=False, dtype=None) -> Tensor
  3991. See :func:`torch.sum`
  3992. """,
  3993. )
  3994. add_docstr_all(
  3995. "nansum",
  3996. r"""
  3997. nansum(dim=None, keepdim=False, dtype=None) -> Tensor
  3998. See :func:`torch.nansum`
  3999. """,
  4000. )
  4001. add_docstr_all(
  4002. "svd",
  4003. r"""
  4004. svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
  4005. See :func:`torch.svd`
  4006. """,
  4007. )
  4008. add_docstr_all(
  4009. "swapdims",
  4010. r"""
  4011. swapdims(dim0, dim1) -> Tensor
  4012. See :func:`torch.swapdims`
  4013. """,
  4014. )
  4015. add_docstr_all(
  4016. "swapdims_",
  4017. r"""
  4018. swapdims_(dim0, dim1) -> Tensor
  4019. In-place version of :meth:`~Tensor.swapdims`
  4020. """,
  4021. )
  4022. add_docstr_all(
  4023. "swapaxes",
  4024. r"""
  4025. swapaxes(axis0, axis1) -> Tensor
  4026. See :func:`torch.swapaxes`
  4027. """,
  4028. )
  4029. add_docstr_all(
  4030. "swapaxes_",
  4031. r"""
  4032. swapaxes_(axis0, axis1) -> Tensor
  4033. In-place version of :meth:`~Tensor.swapaxes`
  4034. """,
  4035. )
  4036. add_docstr_all(
  4037. "t",
  4038. r"""
  4039. t() -> Tensor
  4040. See :func:`torch.t`
  4041. """,
  4042. )
  4043. add_docstr_all(
  4044. "t_",
  4045. r"""
  4046. t_() -> Tensor
  4047. In-place version of :meth:`~Tensor.t`
  4048. """,
  4049. )
  4050. add_docstr_all(
  4051. "tile",
  4052. r"""
  4053. tile(dims) -> Tensor
  4054. See :func:`torch.tile`
  4055. """,
  4056. )
  4057. add_docstr_all(
  4058. "to",
  4059. r"""
  4060. to(*args, **kwargs) -> Tensor
  4061. Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
  4062. inferred from the arguments of ``self.to(*args, **kwargs)``.
  4063. .. note::
  4064. If the ``self`` Tensor already
  4065. has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
  4066. Otherwise, the returned tensor is a copy of ``self`` with the desired
  4067. :class:`torch.dtype` and :class:`torch.device`.
  4068. .. note::
  4069. If ``self`` requires gradients (``requires_grad=True``) but the target
  4070. ``dtype`` specified is an integer type, the returned tensor will implicitly
  4071. set ``requires_grad=False``. This is because only tensors with
  4072. floating-point or complex dtypes can require gradients.
  4073. Here are the ways to call ``to``:
  4074. .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
  4075. :noindex:
  4076. Returns a Tensor with the specified :attr:`dtype`
  4077. Args:
  4078. {memory_format}
  4079. .. note::
  4080. According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
  4081. converting floating point value to integer type will truncate the fractional part.
  4082. If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
  4083. the behavior is undefined and the result may vary across platforms.
  4084. .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
  4085. :noindex:
  4086. Returns a Tensor with the specified :attr:`device` and (optional)
  4087. :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
  4088. When :attr:`non_blocking` is set to ``True``, the function attempts to perform
  4089. the conversion asynchronously with respect to the host, if possible. This
  4090. asynchronous behavior applies to both pinned and pageable memory. However,
  4091. caution is advised when using this feature. For more information, refer to the
  4092. `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
  4093. When :attr:`copy` is set, a new Tensor is created even when the Tensor
  4094. already matches the desired conversion.
  4095. Args:
  4096. {memory_format}
  4097. .. method:: to(other, non_blocking=False, copy=False) -> Tensor
  4098. :noindex:
  4099. Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
  4100. the Tensor :attr:`other`.
  4101. When :attr:`non_blocking` is set to ``True``, the function attempts to perform
  4102. the conversion asynchronously with respect to the host, if possible. This
  4103. asynchronous behavior applies to both pinned and pageable memory. However,
  4104. caution is advised when using this feature. For more information, refer to the
  4105. `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
  4106. When :attr:`copy` is set, a new Tensor is created even when the Tensor
  4107. already matches the desired conversion.
  4108. Example::
  4109. >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
  4110. >>> tensor.to(torch.float64)
  4111. tensor([[-0.5044, 0.0005],
  4112. [ 0.3310, -0.0584]], dtype=torch.float64)
  4113. >>> cuda0 = torch.device('cuda:0')
  4114. >>> tensor.to(cuda0)
  4115. tensor([[-0.5044, 0.0005],
  4116. [ 0.3310, -0.0584]], device='cuda:0')
  4117. >>> tensor.to(cuda0, dtype=torch.float64)
  4118. tensor([[-0.5044, 0.0005],
  4119. [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
  4120. >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
  4121. >>> tensor.to(other, non_blocking=True)
  4122. tensor([[-0.5044, 0.0005],
  4123. [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
  4124. """.format(**common_args),
  4125. )
  4126. add_docstr_all(
  4127. "byte",
  4128. r"""
  4129. byte(memory_format=torch.preserve_format) -> Tensor
  4130. ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
  4131. Args:
  4132. {memory_format}
  4133. """.format(**common_args),
  4134. )
  4135. add_docstr_all(
  4136. "bool",
  4137. r"""
  4138. bool(memory_format=torch.preserve_format) -> Tensor
  4139. ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
  4140. Args:
  4141. {memory_format}
  4142. """.format(**common_args),
  4143. )
  4144. add_docstr_all(
  4145. "char",
  4146. r"""
  4147. char(memory_format=torch.preserve_format) -> Tensor
  4148. ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
  4149. Args:
  4150. {memory_format}
  4151. """.format(**common_args),
  4152. )
  4153. add_docstr_all(
  4154. "bfloat16",
  4155. r"""
  4156. bfloat16(memory_format=torch.preserve_format) -> Tensor
  4157. ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
  4158. Args:
  4159. {memory_format}
  4160. """.format(**common_args),
  4161. )
  4162. add_docstr_all(
  4163. "double",
  4164. r"""
  4165. double(memory_format=torch.preserve_format) -> Tensor
  4166. ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
  4167. Args:
  4168. {memory_format}
  4169. """.format(**common_args),
  4170. )
  4171. add_docstr_all(
  4172. "float",
  4173. r"""
  4174. float(memory_format=torch.preserve_format) -> Tensor
  4175. ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
  4176. Args:
  4177. {memory_format}
  4178. """.format(**common_args),
  4179. )
  4180. add_docstr_all(
  4181. "cdouble",
  4182. r"""
  4183. cdouble(memory_format=torch.preserve_format) -> Tensor
  4184. ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
  4185. Args:
  4186. {memory_format}
  4187. """.format(**common_args),
  4188. )
  4189. add_docstr_all(
  4190. "cfloat",
  4191. r"""
  4192. cfloat(memory_format=torch.preserve_format) -> Tensor
  4193. ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
  4194. Args:
  4195. {memory_format}
  4196. """.format(**common_args),
  4197. )
  4198. add_docstr_all(
  4199. "chalf",
  4200. r"""
  4201. chalf(memory_format=torch.preserve_format) -> Tensor
  4202. ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
  4203. Args:
  4204. {memory_format}
  4205. """.format(**common_args),
  4206. )
  4207. add_docstr_all(
  4208. "half",
  4209. r"""
  4210. half(memory_format=torch.preserve_format) -> Tensor
  4211. ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
  4212. Args:
  4213. {memory_format}
  4214. """.format(**common_args),
  4215. )
  4216. add_docstr_all(
  4217. "int",
  4218. r"""
  4219. int(memory_format=torch.preserve_format) -> Tensor
  4220. ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
  4221. Args:
  4222. {memory_format}
  4223. """.format(**common_args),
  4224. )
  4225. add_docstr_all(
  4226. "int_repr",
  4227. r"""
  4228. int_repr() -> Tensor
  4229. Given a quantized Tensor,
  4230. ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
  4231. underlying uint8_t values of the given Tensor.
  4232. """,
  4233. )
  4234. add_docstr_all(
  4235. "long",
  4236. r"""
  4237. long(memory_format=torch.preserve_format) -> Tensor
  4238. ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
  4239. Args:
  4240. {memory_format}
  4241. """.format(**common_args),
  4242. )
  4243. add_docstr_all(
  4244. "short",
  4245. r"""
  4246. short(memory_format=torch.preserve_format) -> Tensor
  4247. ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
  4248. Args:
  4249. {memory_format}
  4250. """.format(**common_args),
  4251. )
  4252. add_docstr_all(
  4253. "take",
  4254. r"""
  4255. take(indices) -> Tensor
  4256. See :func:`torch.take`
  4257. """,
  4258. )
  4259. add_docstr_all(
  4260. "take_along_dim",
  4261. r"""
  4262. take_along_dim(indices, dim) -> Tensor
  4263. See :func:`torch.take_along_dim`
  4264. """,
  4265. )
  4266. add_docstr_all(
  4267. "tan",
  4268. r"""
  4269. tan() -> Tensor
  4270. See :func:`torch.tan`
  4271. """,
  4272. )
  4273. add_docstr_all(
  4274. "tan_",
  4275. r"""
  4276. tan_() -> Tensor
  4277. In-place version of :meth:`~Tensor.tan`
  4278. """,
  4279. )
  4280. add_docstr_all(
  4281. "tanh",
  4282. r"""
  4283. tanh() -> Tensor
  4284. See :func:`torch.tanh`
  4285. """,
  4286. )
  4287. add_docstr_all(
  4288. "softmax",
  4289. r"""
  4290. softmax(dim) -> Tensor
  4291. Alias for :func:`torch.nn.functional.softmax`.
  4292. """,
  4293. )
  4294. add_docstr_all(
  4295. "tanh_",
  4296. r"""
  4297. tanh_() -> Tensor
  4298. In-place version of :meth:`~Tensor.tanh`
  4299. """,
  4300. )
  4301. add_docstr_all(
  4302. "tolist",
  4303. r"""
  4304. tolist() -> list or number
  4305. Returns the tensor as a (nested) list. For scalars, a standard
  4306. Python number is returned, just like with :meth:`~Tensor.item`.
  4307. Tensors are automatically moved to the CPU first if necessary.
  4308. This operation is not differentiable.
  4309. Examples::
  4310. >>> a = torch.randn(2, 2)
  4311. >>> a.tolist()
  4312. [[0.012766935862600803, 0.5415473580360413],
  4313. [-0.08909505605697632, 0.7729271650314331]]
  4314. >>> a[0,0].tolist()
  4315. 0.012766935862600803
  4316. """,
  4317. )
  4318. add_docstr_all(
  4319. "topk",
  4320. r"""
  4321. topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
  4322. See :func:`torch.topk`
  4323. """,
  4324. )
  4325. add_docstr_all(
  4326. "to_dense",
  4327. r"""
  4328. to_dense(dtype=None, *, masked_grad=True) -> Tensor
  4329. Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
  4330. Keyword args:
  4331. {dtype}
  4332. masked_grad (bool, optional): If set to ``True`` (default) and
  4333. :attr:`self` has a sparse layout then the backward of
  4334. :meth:`to_dense` returns ``grad.sparse_mask(self)``.
  4335. Example::
  4336. >>> s = torch.sparse_coo_tensor(
  4337. ... torch.tensor([[1, 1],
  4338. ... [0, 2]]),
  4339. ... torch.tensor([9, 10]),
  4340. ... size=(3, 3))
  4341. >>> s.to_dense()
  4342. tensor([[ 0, 0, 0],
  4343. [ 9, 0, 10],
  4344. [ 0, 0, 0]])
  4345. """,
  4346. )
  4347. add_docstr_all(
  4348. "to_sparse",
  4349. r"""
  4350. to_sparse(sparseDims) -> Tensor
  4351. Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
  4352. :ref:`coordinate format <sparse-coo-docs>`.
  4353. Args:
  4354. sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
  4355. Example::
  4356. >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
  4357. >>> d
  4358. tensor([[ 0, 0, 0],
  4359. [ 9, 0, 10],
  4360. [ 0, 0, 0]])
  4361. >>> d.to_sparse()
  4362. tensor(indices=tensor([[1, 1],
  4363. [0, 2]]),
  4364. values=tensor([ 9, 10]),
  4365. size=(3, 3), nnz=2, layout=torch.sparse_coo)
  4366. >>> d.to_sparse(1)
  4367. tensor(indices=tensor([[1]]),
  4368. values=tensor([[ 9, 0, 10]]),
  4369. size=(3, 3), nnz=1, layout=torch.sparse_coo)
  4370. .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
  4371. :noindex:
  4372. Returns a sparse tensor with the specified layout and blocksize. If
  4373. the :attr:`self` is strided, the number of dense dimensions could be
  4374. specified, and a hybrid sparse tensor will be created, with
  4375. `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
  4376. dimension.
  4377. .. note:: If the :attr:`self` layout and blocksize parameters match
  4378. with the specified layout and blocksize, return
  4379. :attr:`self`. Otherwise, return a sparse tensor copy of
  4380. :attr:`self`.
  4381. Args:
  4382. layout (:class:`torch.layout`, optional): The desired sparse
  4383. layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
  4384. ``torch.sparse_csc``, ``torch.sparse_bsr``, or
  4385. ``torch.sparse_bsc``. Default: if ``None``,
  4386. ``torch.sparse_coo``.
  4387. blocksize (list, tuple, :class:`torch.Size`, optional): Block size
  4388. of the resulting BSR or BSC tensor. For other layouts,
  4389. specifying the block size that is not ``None`` will result in a
  4390. RuntimeError exception. A block size must be a tuple of length
  4391. two such that its items evenly divide the two sparse dimensions.
  4392. dense_dim (int, optional): Number of dense dimensions of the
  4393. resulting CSR, CSC, BSR or BSC tensor. This argument should be
  4394. used only if :attr:`self` is a strided tensor, and must be a
  4395. value between 0 and dimension of :attr:`self` tensor minus two.
  4396. Example::
  4397. >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
  4398. >>> x.to_sparse(layout=torch.sparse_coo)
  4399. tensor(indices=tensor([[0, 2, 2],
  4400. [0, 0, 1]]),
  4401. values=tensor([1, 2, 3]),
  4402. size=(3, 2), nnz=3, layout=torch.sparse_coo)
  4403. >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
  4404. tensor(crow_indices=tensor([0, 1, 1, 2]),
  4405. col_indices=tensor([0, 0]),
  4406. values=tensor([[[1, 0]],
  4407. [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
  4408. >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
  4409. RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
  4410. >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
  4411. RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
  4412. >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
  4413. >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
  4414. tensor(crow_indices=tensor([0, 1, 1, 3]),
  4415. col_indices=tensor([0, 0, 1]),
  4416. values=tensor([[1],
  4417. [2],
  4418. [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
  4419. """,
  4420. )
  4421. add_docstr_all(
  4422. "to_sparse_csr",
  4423. r"""
  4424. to_sparse_csr(dense_dim=None) -> Tensor
  4425. Convert a tensor to compressed row storage format (CSR). Except for
  4426. strided tensors, only works with 2D tensors. If the :attr:`self` is
  4427. strided, then the number of dense dimensions could be specified, and a
  4428. hybrid CSR tensor will be created, with `dense_dim` dense dimensions
  4429. and `self.dim() - 2 - dense_dim` batch dimension.
  4430. Args:
  4431. dense_dim (int, optional): Number of dense dimensions of the
  4432. resulting CSR tensor. This argument should be used only if
  4433. :attr:`self` is a strided tensor, and must be a value between 0
  4434. and dimension of :attr:`self` tensor minus two.
  4435. Example::
  4436. >>> dense = torch.randn(5, 5)
  4437. >>> sparse = dense.to_sparse_csr()
  4438. >>> sparse._nnz()
  4439. 25
  4440. >>> dense = torch.zeros(3, 3, 1, 1)
  4441. >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
  4442. >>> dense.to_sparse_csr(dense_dim=2)
  4443. tensor(crow_indices=tensor([0, 1, 2, 3]),
  4444. col_indices=tensor([0, 2, 1]),
  4445. values=tensor([[[1.]],
  4446. [[1.]],
  4447. [[1.]]]), size=(3, 3, 1, 1), nnz=3,
  4448. layout=torch.sparse_csr)
  4449. """,
  4450. )
  4451. add_docstr_all(
  4452. "to_sparse_csc",
  4453. r"""
  4454. to_sparse_csc() -> Tensor
  4455. Convert a tensor to compressed column storage (CSC) format. Except
  4456. for strided tensors, only works with 2D tensors. If the :attr:`self`
  4457. is strided, then the number of dense dimensions could be specified,
  4458. and a hybrid CSC tensor will be created, with `dense_dim` dense
  4459. dimensions and `self.dim() - 2 - dense_dim` batch dimension.
  4460. Args:
  4461. dense_dim (int, optional): Number of dense dimensions of the
  4462. resulting CSC tensor. This argument should be used only if
  4463. :attr:`self` is a strided tensor, and must be a value between 0
  4464. and dimension of :attr:`self` tensor minus two.
  4465. Example::
  4466. >>> dense = torch.randn(5, 5)
  4467. >>> sparse = dense.to_sparse_csc()
  4468. >>> sparse._nnz()
  4469. 25
  4470. >>> dense = torch.zeros(3, 3, 1, 1)
  4471. >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
  4472. >>> dense.to_sparse_csc(dense_dim=2)
  4473. tensor(ccol_indices=tensor([0, 1, 2, 3]),
  4474. row_indices=tensor([0, 2, 1]),
  4475. values=tensor([[[1.]],
  4476. [[1.]],
  4477. [[1.]]]), size=(3, 3, 1, 1), nnz=3,
  4478. layout=torch.sparse_csc)
  4479. """,
  4480. )
  4481. add_docstr_all(
  4482. "to_sparse_bsr",
  4483. r"""
  4484. to_sparse_bsr(blocksize, dense_dim) -> Tensor
  4485. Convert a tensor to a block sparse row (BSR) storage format of given
  4486. blocksize. If the :attr:`self` is strided, then the number of dense
  4487. dimensions could be specified, and a hybrid BSR tensor will be
  4488. created, with `dense_dim` dense dimensions and `self.dim() - 2 -
  4489. dense_dim` batch dimension.
  4490. Args:
  4491. blocksize (list, tuple, :class:`torch.Size`, optional): Block size
  4492. of the resulting BSR tensor. A block size must be a tuple of
  4493. length two such that its items evenly divide the two sparse
  4494. dimensions.
  4495. dense_dim (int, optional): Number of dense dimensions of the
  4496. resulting BSR tensor. This argument should be used only if
  4497. :attr:`self` is a strided tensor, and must be a value between 0
  4498. and dimension of :attr:`self` tensor minus two.
  4499. Example::
  4500. >>> dense = torch.randn(10, 10)
  4501. >>> sparse = dense.to_sparse_csr()
  4502. >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
  4503. >>> sparse_bsr.col_indices()
  4504. tensor([0, 1, 0, 1])
  4505. >>> dense = torch.zeros(4, 3, 1)
  4506. >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
  4507. >>> dense.to_sparse_bsr((2, 1), 1)
  4508. tensor(crow_indices=tensor([0, 2, 3]),
  4509. col_indices=tensor([0, 2, 1]),
  4510. values=tensor([[[[1.]],
  4511. [[1.]]],
  4512. [[[1.]],
  4513. [[1.]]],
  4514. [[[1.]],
  4515. [[1.]]]]), size=(4, 3, 1), nnz=3,
  4516. layout=torch.sparse_bsr)
  4517. """,
  4518. )
  4519. add_docstr_all(
  4520. "to_sparse_bsc",
  4521. r"""
  4522. to_sparse_bsc(blocksize, dense_dim) -> Tensor
  4523. Convert a tensor to a block sparse column (BSC) storage format of
  4524. given blocksize. If the :attr:`self` is strided, then the number of
  4525. dense dimensions could be specified, and a hybrid BSC tensor will be
  4526. created, with `dense_dim` dense dimensions and `self.dim() - 2 -
  4527. dense_dim` batch dimension.
  4528. Args:
  4529. blocksize (list, tuple, :class:`torch.Size`, optional): Block size
  4530. of the resulting BSC tensor. A block size must be a tuple of
  4531. length two such that its items evenly divide the two sparse
  4532. dimensions.
  4533. dense_dim (int, optional): Number of dense dimensions of the
  4534. resulting BSC tensor. This argument should be used only if
  4535. :attr:`self` is a strided tensor, and must be a value between 0
  4536. and dimension of :attr:`self` tensor minus two.
  4537. Example::
  4538. >>> dense = torch.randn(10, 10)
  4539. >>> sparse = dense.to_sparse_csr()
  4540. >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
  4541. >>> sparse_bsc.row_indices()
  4542. tensor([0, 1, 0, 1])
  4543. >>> dense = torch.zeros(4, 3, 1)
  4544. >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
  4545. >>> dense.to_sparse_bsc((2, 1), 1)
  4546. tensor(ccol_indices=tensor([0, 1, 2, 3]),
  4547. row_indices=tensor([0, 1, 0]),
  4548. values=tensor([[[[1.]],
  4549. [[1.]]],
  4550. [[[1.]],
  4551. [[1.]]],
  4552. [[[1.]],
  4553. [[1.]]]]), size=(4, 3, 1), nnz=3,
  4554. layout=torch.sparse_bsc)
  4555. """,
  4556. )
  4557. add_docstr_all(
  4558. "to_mkldnn",
  4559. r"""
  4560. to_mkldnn() -> Tensor
  4561. Returns a copy of the tensor in ``torch.mkldnn`` layout.
  4562. """,
  4563. )
  4564. add_docstr_all(
  4565. "trace",
  4566. r"""
  4567. trace() -> Tensor
  4568. See :func:`torch.trace`
  4569. """,
  4570. )
  4571. add_docstr_all(
  4572. "transpose",
  4573. r"""
  4574. transpose(dim0, dim1) -> Tensor
  4575. See :func:`torch.transpose`
  4576. """,
  4577. )
  4578. add_docstr_all(
  4579. "transpose_",
  4580. r"""
  4581. transpose_(dim0, dim1) -> Tensor
  4582. In-place version of :meth:`~Tensor.transpose`
  4583. """,
  4584. )
  4585. add_docstr_all(
  4586. "triangular_solve",
  4587. r"""
  4588. triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
  4589. See :func:`torch.triangular_solve`
  4590. """,
  4591. )
  4592. add_docstr_all(
  4593. "tril",
  4594. r"""
  4595. tril(diagonal=0) -> Tensor
  4596. See :func:`torch.tril`
  4597. """,
  4598. )
  4599. add_docstr_all(
  4600. "tril_",
  4601. r"""
  4602. tril_(diagonal=0) -> Tensor
  4603. In-place version of :meth:`~Tensor.tril`
  4604. """,
  4605. )
  4606. add_docstr_all(
  4607. "triu",
  4608. r"""
  4609. triu(diagonal=0) -> Tensor
  4610. See :func:`torch.triu`
  4611. """,
  4612. )
  4613. add_docstr_all(
  4614. "triu_",
  4615. r"""
  4616. triu_(diagonal=0) -> Tensor
  4617. In-place version of :meth:`~Tensor.triu`
  4618. """,
  4619. )
  4620. add_docstr_all(
  4621. "true_divide",
  4622. r"""
  4623. true_divide(value) -> Tensor
  4624. See :func:`torch.true_divide`
  4625. """,
  4626. )
  4627. add_docstr_all(
  4628. "true_divide_",
  4629. r"""
  4630. true_divide_(value) -> Tensor
  4631. In-place version of :meth:`~Tensor.true_divide_`
  4632. """,
  4633. )
  4634. add_docstr_all(
  4635. "trunc",
  4636. r"""
  4637. trunc() -> Tensor
  4638. See :func:`torch.trunc`
  4639. """,
  4640. )
  4641. add_docstr_all(
  4642. "fix",
  4643. r"""
  4644. fix() -> Tensor
  4645. See :func:`torch.fix`.
  4646. """,
  4647. )
  4648. add_docstr_all(
  4649. "trunc_",
  4650. r"""
  4651. trunc_() -> Tensor
  4652. In-place version of :meth:`~Tensor.trunc`
  4653. """,
  4654. )
  4655. add_docstr_all(
  4656. "fix_",
  4657. r"""
  4658. fix_() -> Tensor
  4659. In-place version of :meth:`~Tensor.fix`
  4660. """,
  4661. )
  4662. add_docstr_all(
  4663. "type",
  4664. r"""
  4665. type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
  4666. Returns the type if `dtype` is not provided, else casts this object to
  4667. the specified type.
  4668. If this is already of the correct type, no copy is performed and the
  4669. original object is returned.
  4670. Args:
  4671. dtype (dtype or string): The desired type
  4672. non_blocking (bool): If ``True``, and the source is in pinned memory
  4673. and destination is on the GPU or vice versa, the copy is performed
  4674. asynchronously with respect to the host. Otherwise, the argument
  4675. has no effect.
  4676. **kwargs: For compatibility, may contain the key ``async`` in place of
  4677. the ``non_blocking`` argument. The ``async`` arg is deprecated.
  4678. """,
  4679. )
  4680. add_docstr_all(
  4681. "type_as",
  4682. r"""
  4683. type_as(tensor) -> Tensor
  4684. Returns this tensor cast to the type of the given tensor.
  4685. This is a no-op if the tensor is already of the correct type. This is
  4686. equivalent to ``self.type(tensor.type())``
  4687. Args:
  4688. tensor (Tensor): the tensor which has the desired type
  4689. """,
  4690. )
  4691. add_docstr_all(
  4692. "unfold",
  4693. r"""
  4694. unfold(dimension, size, step) -> Tensor
  4695. Returns a view of the original tensor which contains all slices of size :attr:`size` from
  4696. :attr:`self` tensor in the dimension :attr:`dimension`.
  4697. Step between two slices is given by :attr:`step`.
  4698. If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
  4699. dimension :attr:`dimension` in the returned tensor will be
  4700. `(sizedim - size) / step + 1`.
  4701. An additional dimension of size :attr:`size` is appended in the returned tensor.
  4702. Args:
  4703. dimension (int): dimension in which unfolding happens
  4704. size (int): the size of each slice that is unfolded
  4705. step (int): the step between each slice
  4706. Example::
  4707. >>> x = torch.arange(1., 8)
  4708. >>> x
  4709. tensor([ 1., 2., 3., 4., 5., 6., 7.])
  4710. >>> x.unfold(0, 2, 1)
  4711. tensor([[ 1., 2.],
  4712. [ 2., 3.],
  4713. [ 3., 4.],
  4714. [ 4., 5.],
  4715. [ 5., 6.],
  4716. [ 6., 7.]])
  4717. >>> x.unfold(0, 2, 2)
  4718. tensor([[ 1., 2.],
  4719. [ 3., 4.],
  4720. [ 5., 6.]])
  4721. """,
  4722. )
  4723. add_docstr_all(
  4724. "uniform_",
  4725. r"""
  4726. uniform_(from=0, to=1, *, generator=None) -> Tensor
  4727. Fills :attr:`self` tensor with numbers sampled from the continuous uniform
  4728. distribution:
  4729. .. math::
  4730. f(x) = \dfrac{1}{\text{to} - \text{from}}
  4731. """,
  4732. )
  4733. add_docstr_all(
  4734. "unsqueeze",
  4735. r"""
  4736. unsqueeze(dim) -> Tensor
  4737. See :func:`torch.unsqueeze`
  4738. """,
  4739. )
  4740. add_docstr_all(
  4741. "unsqueeze_",
  4742. r"""
  4743. unsqueeze_(dim) -> Tensor
  4744. In-place version of :meth:`~Tensor.unsqueeze`
  4745. """,
  4746. )
  4747. add_docstr_all(
  4748. "var",
  4749. r"""
  4750. var(dim=None, *, correction=1, keepdim=False) -> Tensor
  4751. See :func:`torch.var`
  4752. """,
  4753. )
  4754. add_docstr_all(
  4755. "vdot",
  4756. r"""
  4757. vdot(other) -> Tensor
  4758. See :func:`torch.vdot`
  4759. """,
  4760. )
  4761. add_docstr_all(
  4762. "view",
  4763. r"""
  4764. view(*shape) -> Tensor
  4765. Returns a new tensor with the same data as the :attr:`self` tensor but of a
  4766. different :attr:`shape`.
  4767. The returned tensor shares the same data and must have the same number
  4768. of elements, but may have a different size. For a tensor to be viewed, the new
  4769. view size must be compatible with its original size and stride, i.e., each new
  4770. view dimension must either be a subspace of an original dimension, or only span
  4771. across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
  4772. contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
  4773. .. math::
  4774. \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
  4775. Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
  4776. without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
  4777. :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
  4778. returns a view if the shapes are compatible, and copies (equivalent to calling
  4779. :meth:`contiguous`) otherwise.
  4780. Args:
  4781. shape (torch.Size or int...): the desired size
  4782. Example::
  4783. >>> x = torch.randn(4, 4)
  4784. >>> x.size()
  4785. torch.Size([4, 4])
  4786. >>> y = x.view(16)
  4787. >>> y.size()
  4788. torch.Size([16])
  4789. >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
  4790. >>> z.size()
  4791. torch.Size([2, 8])
  4792. >>> a = torch.randn(1, 2, 3, 4)
  4793. >>> a.size()
  4794. torch.Size([1, 2, 3, 4])
  4795. >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
  4796. >>> b.size()
  4797. torch.Size([1, 3, 2, 4])
  4798. >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
  4799. >>> c.size()
  4800. torch.Size([1, 3, 2, 4])
  4801. >>> torch.equal(b, c)
  4802. False
  4803. .. method:: view(dtype) -> Tensor
  4804. :noindex:
  4805. Returns a new tensor with the same data as the :attr:`self` tensor but of a
  4806. different :attr:`dtype`.
  4807. If the element size of :attr:`dtype` is different than that of ``self.dtype``,
  4808. then the size of the last dimension of the output will be scaled
  4809. proportionally. For instance, if :attr:`dtype` element size is twice that of
  4810. ``self.dtype``, then each pair of elements in the last dimension of
  4811. :attr:`self` will be combined, and the size of the last dimension of the output
  4812. will be half that of :attr:`self`. If :attr:`dtype` element size is half that
  4813. of ``self.dtype``, then each element in the last dimension of :attr:`self` will
  4814. be split in two, and the size of the last dimension of the output will be
  4815. double that of :attr:`self`. For this to be possible, the following conditions
  4816. must be true:
  4817. * ``self.dim()`` must be greater than 0.
  4818. * ``self.stride(-1)`` must be 1.
  4819. Additionally, if the element size of :attr:`dtype` is greater than that of
  4820. ``self.dtype``, the following conditions must be true as well:
  4821. * ``self.size(-1)`` must be divisible by the ratio between the element
  4822. sizes of the dtypes.
  4823. * ``self.storage_offset()`` must be divisible by the ratio between the
  4824. element sizes of the dtypes.
  4825. * The strides of all dimensions, except the last dimension, must be
  4826. divisible by the ratio between the element sizes of the dtypes.
  4827. If any of the above conditions are not met, an error is thrown.
  4828. .. warning::
  4829. This overload is not supported by TorchScript, and using it in a Torchscript
  4830. program will cause undefined behavior.
  4831. Args:
  4832. dtype (:class:`torch.dtype`): the desired dtype
  4833. Example::
  4834. >>> x = torch.randn(4, 4)
  4835. >>> x
  4836. tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
  4837. [-0.1520, 0.7472, 0.5617, -0.8649],
  4838. [-2.4724, -0.0334, -0.2976, -0.8499],
  4839. [-0.2109, 1.9913, -0.9607, -0.6123]])
  4840. >>> x.dtype
  4841. torch.float32
  4842. >>> y = x.view(torch.int32)
  4843. >>> y
  4844. tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
  4845. [-1105482831, 1061112040, 1057999968, -1084397505],
  4846. [-1071760287, -1123489973, -1097310419, -1084649136],
  4847. [-1101533110, 1073668768, -1082790149, -1088634448]],
  4848. dtype=torch.int32)
  4849. >>> y[0, 0] = 1000000000
  4850. >>> x
  4851. tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
  4852. [-0.1520, 0.7472, 0.5617, -0.8649],
  4853. [-2.4724, -0.0334, -0.2976, -0.8499],
  4854. [-0.2109, 1.9913, -0.9607, -0.6123]])
  4855. >>> x.view(torch.cfloat)
  4856. tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
  4857. [-0.1520+0.7472j, 0.5617-0.8649j],
  4858. [-2.4724-0.0334j, -0.2976-0.8499j],
  4859. [-0.2109+1.9913j, -0.9607-0.6123j]])
  4860. >>> x.view(torch.cfloat).size()
  4861. torch.Size([4, 2])
  4862. >>> x.view(torch.uint8)
  4863. tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
  4864. 8, 191],
  4865. [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
  4866. 93, 191],
  4867. [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
  4868. 89, 191],
  4869. [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
  4870. 28, 191]], dtype=torch.uint8)
  4871. >>> x.view(torch.uint8).size()
  4872. torch.Size([4, 16])
  4873. """,
  4874. )
  4875. add_docstr_all(
  4876. "view_as",
  4877. r"""
  4878. view_as(other) -> Tensor
  4879. View this tensor as the same size as :attr:`other`.
  4880. ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
  4881. Please see :meth:`~Tensor.view` for more information about ``view``.
  4882. Args:
  4883. other (:class:`torch.Tensor`): The result tensor has the same size
  4884. as :attr:`other`.
  4885. """,
  4886. )
  4887. add_docstr_all(
  4888. "expand",
  4889. r"""
  4890. expand(*sizes) -> Tensor
  4891. Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
  4892. to a larger size.
  4893. Passing -1 as the size for a dimension means not changing the size of
  4894. that dimension.
  4895. Tensor can be also expanded to a larger number of dimensions, and the
  4896. new ones will be appended at the front. For the new dimensions, the
  4897. size cannot be set to -1.
  4898. Expanding a tensor does not allocate new memory, but only creates a
  4899. new view on the existing tensor where a dimension of size one is
  4900. expanded to a larger size by setting the ``stride`` to 0. Any dimension
  4901. of size 1 can be expanded to an arbitrary value without allocating new
  4902. memory.
  4903. Args:
  4904. *sizes (torch.Size or int...): the desired expanded size
  4905. .. warning::
  4906. More than one element of an expanded tensor may refer to a single
  4907. memory location. As a result, in-place operations (especially ones that
  4908. are vectorized) may result in incorrect behavior. If you need to write
  4909. to the tensors, please clone them first.
  4910. Example::
  4911. >>> x = torch.tensor([[1], [2], [3]])
  4912. >>> x.size()
  4913. torch.Size([3, 1])
  4914. >>> x.expand(3, 4)
  4915. tensor([[ 1, 1, 1, 1],
  4916. [ 2, 2, 2, 2],
  4917. [ 3, 3, 3, 3]])
  4918. >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
  4919. tensor([[ 1, 1, 1, 1],
  4920. [ 2, 2, 2, 2],
  4921. [ 3, 3, 3, 3]])
  4922. """,
  4923. )
  4924. add_docstr_all(
  4925. "expand_as",
  4926. r"""
  4927. expand_as(other) -> Tensor
  4928. Expand this tensor to the same size as :attr:`other`.
  4929. ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
  4930. Please see :meth:`~Tensor.expand` for more information about ``expand``.
  4931. Args:
  4932. other (:class:`torch.Tensor`): The result tensor has the same size
  4933. as :attr:`other`.
  4934. """,
  4935. )
  4936. add_docstr_all(
  4937. "sum_to_size",
  4938. r"""
  4939. sum_to_size(*size) -> Tensor
  4940. Sum ``this`` tensor to :attr:`size`.
  4941. :attr:`size` must be broadcastable to ``this`` tensor size.
  4942. Args:
  4943. size (int...): a sequence of integers defining the shape of the output tensor.
  4944. """,
  4945. )
  4946. add_docstr_all(
  4947. "zero_",
  4948. r"""
  4949. zero_() -> Tensor
  4950. Fills :attr:`self` tensor with zeros.
  4951. """,
  4952. )
  4953. add_docstr_all(
  4954. "matmul",
  4955. r"""
  4956. matmul(tensor2) -> Tensor
  4957. See :func:`torch.matmul`
  4958. """,
  4959. )
  4960. add_docstr_all(
  4961. "chunk",
  4962. r"""
  4963. chunk(chunks, dim=0) -> List of Tensors
  4964. See :func:`torch.chunk`
  4965. """,
  4966. )
  4967. add_docstr_all(
  4968. "unsafe_chunk",
  4969. r"""
  4970. unsafe_chunk(chunks, dim=0) -> List of Tensors
  4971. See :func:`torch.unsafe_chunk`
  4972. """,
  4973. )
  4974. add_docstr_all(
  4975. "unsafe_split",
  4976. r"""
  4977. unsafe_split(split_size, dim=0) -> List of Tensors
  4978. See :func:`torch.unsafe_split`
  4979. """,
  4980. )
  4981. add_docstr_all(
  4982. "tensor_split",
  4983. r"""
  4984. tensor_split(indices_or_sections, dim=0) -> List of Tensors
  4985. See :func:`torch.tensor_split`
  4986. """,
  4987. )
  4988. add_docstr_all(
  4989. "hsplit",
  4990. r"""
  4991. hsplit(split_size_or_sections) -> List of Tensors
  4992. See :func:`torch.hsplit`
  4993. """,
  4994. )
  4995. add_docstr_all(
  4996. "vsplit",
  4997. r"""
  4998. vsplit(split_size_or_sections) -> List of Tensors
  4999. See :func:`torch.vsplit`
  5000. """,
  5001. )
  5002. add_docstr_all(
  5003. "dsplit",
  5004. r"""
  5005. dsplit(split_size_or_sections) -> List of Tensors
  5006. See :func:`torch.dsplit`
  5007. """,
  5008. )
  5009. add_docstr_all(
  5010. "stft",
  5011. r"""
  5012. stft(frame_length, hop, fft_size=None, return_onesided=True, window=None,
  5013. pad_end=0, align_to_window=None) -> Tensor
  5014. See :func:`torch.stft`
  5015. """,
  5016. )
  5017. add_docstr_all(
  5018. "istft",
  5019. r"""
  5020. istft(n_fft, hop_length=None, win_length=None, window=None,
  5021. center=True, normalized=False, onesided=True, length=None) -> Tensor
  5022. See :func:`torch.istft`
  5023. """,
  5024. )
  5025. add_docstr_all(
  5026. "det",
  5027. r"""
  5028. det() -> Tensor
  5029. See :func:`torch.det`
  5030. """,
  5031. )
  5032. add_docstr_all(
  5033. "where",
  5034. r"""
  5035. where(condition, y) -> Tensor
  5036. ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
  5037. See :func:`torch.where`
  5038. """,
  5039. )
  5040. add_docstr_all(
  5041. "logdet",
  5042. r"""
  5043. logdet() -> Tensor
  5044. See :func:`torch.logdet`
  5045. """,
  5046. )
  5047. add_docstr_all(
  5048. "slogdet",
  5049. r"""
  5050. slogdet() -> (Tensor, Tensor)
  5051. See :func:`torch.slogdet`
  5052. """,
  5053. )
  5054. add_docstr_all(
  5055. "unbind",
  5056. r"""
  5057. unbind(dim=0) -> seq
  5058. See :func:`torch.unbind`
  5059. """,
  5060. )
  5061. add_docstr_all(
  5062. "pin_memory",
  5063. r"""
  5064. pin_memory() -> Tensor
  5065. Copies the tensor to pinned memory, if it's not already pinned.
  5066. By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
  5067. """,
  5068. )
  5069. add_docstr_all(
  5070. "pinverse",
  5071. r"""
  5072. pinverse() -> Tensor
  5073. See :func:`torch.pinverse`
  5074. """,
  5075. )
  5076. add_docstr_all(
  5077. "index_add",
  5078. r"""
  5079. index_add(dim, index, source, *, alpha=1) -> Tensor
  5080. Out-of-place version of :meth:`torch.Tensor.index_add_`.
  5081. """,
  5082. )
  5083. add_docstr_all(
  5084. "index_copy",
  5085. r"""
  5086. index_copy(dim, index, tensor2) -> Tensor
  5087. Out-of-place version of :meth:`torch.Tensor.index_copy_`.
  5088. """,
  5089. )
  5090. add_docstr_all(
  5091. "index_fill",
  5092. r"""
  5093. index_fill(dim, index, value) -> Tensor
  5094. Out-of-place version of :meth:`torch.Tensor.index_fill_`.
  5095. """,
  5096. )
  5097. add_docstr_all(
  5098. "scatter",
  5099. r"""
  5100. scatter(dim, index, src) -> Tensor
  5101. Out-of-place version of :meth:`torch.Tensor.scatter_`
  5102. """,
  5103. )
  5104. add_docstr_all(
  5105. "scatter_add",
  5106. r"""
  5107. scatter_add(dim, index, src) -> Tensor
  5108. Out-of-place version of :meth:`torch.Tensor.scatter_add_`
  5109. """,
  5110. )
  5111. add_docstr_all(
  5112. "scatter_reduce",
  5113. r"""
  5114. scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
  5115. Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
  5116. """,
  5117. )
  5118. add_docstr_all(
  5119. "masked_scatter",
  5120. r"""
  5121. masked_scatter(mask, tensor) -> Tensor
  5122. Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
  5123. .. note::
  5124. The inputs :attr:`self` and :attr:`mask`
  5125. :ref:`broadcast <broadcasting-semantics>`.
  5126. Example:
  5127. >>> self = torch.tensor([0, 0, 0, 0, 0])
  5128. >>> mask = torch.tensor(
  5129. ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
  5130. ... dtype=torch.bool,
  5131. ... )
  5132. >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
  5133. >>> self.masked_scatter(mask, source)
  5134. tensor([[0, 0, 0, 0, 1],
  5135. [2, 3, 0, 4, 5]])
  5136. """,
  5137. )
  5138. add_docstr_all(
  5139. "xlogy",
  5140. r"""
  5141. xlogy(other) -> Tensor
  5142. See :func:`torch.xlogy`
  5143. """,
  5144. )
  5145. add_docstr_all(
  5146. "xlogy_",
  5147. r"""
  5148. xlogy_(other) -> Tensor
  5149. In-place version of :meth:`~Tensor.xlogy`
  5150. """,
  5151. )
  5152. add_docstr_all(
  5153. "masked_fill",
  5154. r"""
  5155. masked_fill(mask, value) -> Tensor
  5156. Out-of-place version of :meth:`torch.Tensor.masked_fill_`
  5157. """,
  5158. )
  5159. add_docstr_all(
  5160. "grad",
  5161. r"""
  5162. This attribute is ``None`` by default and becomes a Tensor the first time a call to
  5163. :func:`backward` computes gradients for ``self``.
  5164. The attribute will then contain the gradients computed and future calls to
  5165. :func:`backward` will accumulate (add) gradients into it.
  5166. """,
  5167. )
  5168. add_docstr_all(
  5169. "grad_dtype",
  5170. r"""
  5171. The allowed dtype of :attr:``grad`` for this tensor.
  5172. :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
  5173. ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
  5174. incoming gradients to this dtype. This attribute is only accessible and
  5175. settable for leaf tensors.
  5176. .. warning::
  5177. Use with caution. Diverging the dtypes of a tensor and its gradient may
  5178. break downstream systems that assume they match.
  5179. Example::
  5180. >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
  5181. >>> x.grad_dtype
  5182. torch.float32
  5183. >>> x.grad_dtype = torch.float16
  5184. >>> x.grad_dtype
  5185. torch.float16
  5186. >>> # Allow any gradient dtype
  5187. >>> x.grad_dtype = None
  5188. >>> x.grad_dtype
  5189. """,
  5190. )
  5191. add_docstr_all(
  5192. "retain_grad",
  5193. r"""
  5194. retain_grad() -> None
  5195. Enables this Tensor to have their :attr:`grad` populated during
  5196. :func:`backward`. This is a no-op for leaf tensors.
  5197. """,
  5198. )
  5199. add_docstr_all(
  5200. "retains_grad",
  5201. r"""
  5202. Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
  5203. populated during :func:`backward`, ``False`` otherwise.
  5204. """,
  5205. )
  5206. add_docstr_all(
  5207. "requires_grad",
  5208. r"""
  5209. Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
  5210. .. note::
  5211. The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
  5212. attribute will be populated, see :attr:`is_leaf` for more details.
  5213. """,
  5214. )
  5215. add_docstr_all(
  5216. "is_leaf",
  5217. r"""
  5218. All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
  5219. For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
  5220. created by the user. This means that they are not the result of an operation and so
  5221. :attr:`grad_fn` is None.
  5222. Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
  5223. To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
  5224. Example::
  5225. >>> a = torch.rand(10, requires_grad=True)
  5226. >>> a.is_leaf
  5227. True
  5228. >>> b = torch.rand(10, requires_grad=True).cuda()
  5229. >>> b.is_leaf
  5230. False
  5231. # b was created by the operation that cast a cpu Tensor into a cuda Tensor
  5232. >>> c = torch.rand(10, requires_grad=True) + 2
  5233. >>> c.is_leaf
  5234. False
  5235. # c was created by the addition operation
  5236. >>> d = torch.rand(10).cuda()
  5237. >>> d.is_leaf
  5238. True
  5239. # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
  5240. >>> e = torch.rand(10).cuda().requires_grad_()
  5241. >>> e.is_leaf
  5242. True
  5243. # e requires gradients and has no operations creating it
  5244. >>> f = torch.rand(10, requires_grad=True, device="cuda")
  5245. >>> f.is_leaf
  5246. True
  5247. # f requires grad, has no operation creating it
  5248. """,
  5249. )
  5250. add_docstr_all(
  5251. "names",
  5252. r"""
  5253. Stores names for each of this tensor's dimensions.
  5254. ``names[idx]`` corresponds to the name of tensor dimension ``idx``.
  5255. Names are either a string if the dimension is named or ``None`` if the
  5256. dimension is unnamed.
  5257. Dimension names may contain characters or underscore. Furthermore, a dimension
  5258. name must be a valid Python variable name (i.e., does not start with underscore).
  5259. Tensors may not have two named dimensions with the same name.
  5260. .. warning::
  5261. The named tensor API is experimental and subject to change.
  5262. """,
  5263. )
  5264. add_docstr_all(
  5265. "is_cuda",
  5266. r"""
  5267. Is ``True`` if the Tensor is stored on the GPU, ``False`` otherwise.
  5268. """,
  5269. )
  5270. add_docstr_all(
  5271. "is_cpu",
  5272. r"""
  5273. Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
  5274. """,
  5275. )
  5276. add_docstr_all(
  5277. "is_xla",
  5278. r"""
  5279. Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
  5280. """,
  5281. )
  5282. add_docstr_all(
  5283. "is_ipu",
  5284. r"""
  5285. Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
  5286. """,
  5287. )
  5288. add_docstr_all(
  5289. "is_xpu",
  5290. r"""
  5291. Is ``True`` if the Tensor is stored on the XPU, ``False`` otherwise.
  5292. """,
  5293. )
  5294. add_docstr_all(
  5295. "is_quantized",
  5296. r"""
  5297. Is ``True`` if the Tensor is quantized, ``False`` otherwise.
  5298. """,
  5299. )
  5300. add_docstr_all(
  5301. "is_meta",
  5302. r"""
  5303. Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
  5304. are like normal tensors, but they carry no data.
  5305. """,
  5306. )
  5307. add_docstr_all(
  5308. "is_mps",
  5309. r"""
  5310. Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
  5311. """,
  5312. )
  5313. add_docstr_all(
  5314. "is_sparse",
  5315. r"""
  5316. Is ``True`` if the Tensor uses sparse COO storage layout, ``False`` otherwise.
  5317. """,
  5318. )
  5319. add_docstr_all(
  5320. "is_sparse_csr",
  5321. r"""
  5322. Is ``True`` if the Tensor uses sparse CSR storage layout, ``False`` otherwise.
  5323. """,
  5324. )
  5325. add_docstr_all(
  5326. "device",
  5327. r"""
  5328. Is the :class:`torch.device` where this Tensor is.
  5329. """,
  5330. )
  5331. add_docstr_all(
  5332. "ndim",
  5333. r"""
  5334. Alias for :meth:`~Tensor.dim()`
  5335. """,
  5336. )
  5337. add_docstr_all(
  5338. "itemsize",
  5339. r"""
  5340. Alias for :meth:`~Tensor.element_size()`
  5341. """,
  5342. )
  5343. add_docstr_all(
  5344. "nbytes",
  5345. r"""
  5346. Returns the number of bytes consumed by the "view" of elements of the Tensor
  5347. if the Tensor does not use sparse storage layout.
  5348. Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
  5349. """,
  5350. )
  5351. add_docstr_all(
  5352. "T",
  5353. r"""
  5354. Returns a view of this tensor with its dimensions reversed.
  5355. If ``n`` is the number of dimensions in ``x``,
  5356. ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
  5357. .. warning::
  5358. The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
  5359. is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
  5360. to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
  5361. the dimensions of a tensor.
  5362. """,
  5363. )
  5364. add_docstr_all(
  5365. "H",
  5366. r"""
  5367. Returns a view of a matrix (2-D tensor) conjugated and transposed.
  5368. ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
  5369. ``x.transpose(0, 1)`` for real matrices.
  5370. .. seealso::
  5371. :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
  5372. """,
  5373. )
  5374. add_docstr_all(
  5375. "mT",
  5376. r"""
  5377. Returns a view of this tensor with the last two dimensions transposed.
  5378. ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
  5379. """,
  5380. )
  5381. add_docstr_all(
  5382. "mH",
  5383. r"""
  5384. Accessing this property is equivalent to calling :func:`adjoint`.
  5385. """,
  5386. )
  5387. add_docstr_all(
  5388. "adjoint",
  5389. r"""
  5390. adjoint() -> Tensor
  5391. Alias for :func:`adjoint`
  5392. """,
  5393. )
  5394. add_docstr_all(
  5395. "real",
  5396. r"""
  5397. Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
  5398. The returned tensor and :attr:`self` share the same underlying storage.
  5399. Returns :attr:`self` if :attr:`self` is a real-valued tensor tensor.
  5400. Example::
  5401. >>> x=torch.randn(4, dtype=torch.cfloat)
  5402. >>> x
  5403. tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
  5404. >>> x.real
  5405. tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
  5406. """,
  5407. )
  5408. add_docstr_all(
  5409. "imag",
  5410. r"""
  5411. Returns a new tensor containing imaginary values of the :attr:`self` tensor.
  5412. The returned tensor and :attr:`self` share the same underlying storage.
  5413. .. warning::
  5414. :func:`imag` is only supported for tensors with complex dtypes.
  5415. Example::
  5416. >>> x=torch.randn(4, dtype=torch.cfloat)
  5417. >>> x
  5418. tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
  5419. >>> x.imag
  5420. tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
  5421. """,
  5422. )
  5423. add_docstr_all(
  5424. "as_subclass",
  5425. r"""
  5426. as_subclass(cls) -> Tensor
  5427. Makes a ``cls`` instance with the same data pointer as ``self``. Changes
  5428. in the output mirror changes in ``self``, and the output stays attached
  5429. to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
  5430. """,
  5431. )
  5432. add_docstr_all(
  5433. "crow_indices",
  5434. r"""
  5435. crow_indices() -> IntTensor
  5436. Returns the tensor containing the compressed row indices of the :attr:`self`
  5437. tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
  5438. The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
  5439. and of type ``int32`` or ``int64``. When using MKL routines such as sparse
  5440. matrix multiplication, it is necessary to use ``int32`` indexing in order
  5441. to avoid downcasting and potentially losing information.
  5442. Example::
  5443. >>> csr = torch.eye(5,5).to_sparse_csr()
  5444. >>> csr.crow_indices()
  5445. tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
  5446. """,
  5447. )
  5448. add_docstr_all(
  5449. "col_indices",
  5450. r"""
  5451. col_indices() -> IntTensor
  5452. Returns the tensor containing the column indices of the :attr:`self`
  5453. tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
  5454. The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
  5455. and of type ``int32`` or ``int64``. When using MKL routines such as sparse
  5456. matrix multiplication, it is necessary to use ``int32`` indexing in order
  5457. to avoid downcasting and potentially losing information.
  5458. Example::
  5459. >>> csr = torch.eye(5,5).to_sparse_csr()
  5460. >>> csr.col_indices()
  5461. tensor([0, 1, 2, 3, 4], dtype=torch.int32)
  5462. """,
  5463. )
  5464. add_docstr_all(
  5465. "to_padded_tensor",
  5466. r"""
  5467. to_padded_tensor(padding, output_size=None) -> Tensor
  5468. See :func:`to_padded_tensor`
  5469. """,
  5470. )