_tensor_docs.py 141 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974
  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. See :func:`torch.permute`
  2927. """,
  2928. )
  2929. add_docstr_all(
  2930. "polygamma",
  2931. r"""
  2932. polygamma(n) -> Tensor
  2933. See :func:`torch.polygamma`
  2934. """,
  2935. )
  2936. add_docstr_all(
  2937. "polygamma_",
  2938. r"""
  2939. polygamma_(n) -> Tensor
  2940. In-place version of :meth:`~Tensor.polygamma`
  2941. """,
  2942. )
  2943. add_docstr_all(
  2944. "positive",
  2945. r"""
  2946. positive() -> Tensor
  2947. See :func:`torch.positive`
  2948. """,
  2949. )
  2950. add_docstr_all(
  2951. "pow",
  2952. r"""
  2953. pow(exponent) -> Tensor
  2954. See :func:`torch.pow`
  2955. """,
  2956. )
  2957. add_docstr_all(
  2958. "pow_",
  2959. r"""
  2960. pow_(exponent) -> Tensor
  2961. In-place version of :meth:`~Tensor.pow`
  2962. """,
  2963. )
  2964. add_docstr_all(
  2965. "float_power",
  2966. r"""
  2967. float_power(exponent) -> Tensor
  2968. See :func:`torch.float_power`
  2969. """,
  2970. )
  2971. add_docstr_all(
  2972. "float_power_",
  2973. r"""
  2974. float_power_(exponent) -> Tensor
  2975. In-place version of :meth:`~Tensor.float_power`
  2976. """,
  2977. )
  2978. add_docstr_all(
  2979. "prod",
  2980. r"""
  2981. prod(dim=None, keepdim=False, dtype=None) -> Tensor
  2982. See :func:`torch.prod`
  2983. """,
  2984. )
  2985. add_docstr_all(
  2986. "put_",
  2987. r"""
  2988. put_(index, source, accumulate=False) -> Tensor
  2989. Copies the elements from :attr:`source` into the positions specified by
  2990. :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
  2991. it were a 1-D tensor.
  2992. :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
  2993. the same shape.
  2994. If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
  2995. :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
  2996. contain duplicate elements.
  2997. Args:
  2998. index (LongTensor): the indices into self
  2999. source (Tensor): the tensor containing values to copy from
  3000. accumulate (bool, optional): whether to accumulate into self. Default: ``False``
  3001. Example::
  3002. >>> src = torch.tensor([[4, 3, 5],
  3003. ... [6, 7, 8]])
  3004. >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
  3005. tensor([[ 4, 9, 5],
  3006. [ 10, 7, 8]])
  3007. """,
  3008. )
  3009. add_docstr_all(
  3010. "put",
  3011. r"""
  3012. put(input, index, source, accumulate=False) -> Tensor
  3013. Out-of-place version of :meth:`torch.Tensor.put_`.
  3014. `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
  3015. """,
  3016. )
  3017. add_docstr_all(
  3018. "qr",
  3019. r"""
  3020. qr(some=True) -> (Tensor, Tensor)
  3021. See :func:`torch.qr`
  3022. """,
  3023. )
  3024. add_docstr_all(
  3025. "qscheme",
  3026. r"""
  3027. qscheme() -> torch.qscheme
  3028. Returns the quantization scheme of a given QTensor.
  3029. """,
  3030. )
  3031. add_docstr_all(
  3032. "quantile",
  3033. r"""
  3034. quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
  3035. See :func:`torch.quantile`
  3036. """,
  3037. )
  3038. add_docstr_all(
  3039. "nanquantile",
  3040. r"""
  3041. nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
  3042. See :func:`torch.nanquantile`
  3043. """,
  3044. )
  3045. add_docstr_all(
  3046. "q_scale",
  3047. r"""
  3048. q_scale() -> float
  3049. Given a Tensor quantized by linear(affine) quantization,
  3050. returns the scale of the underlying quantizer().
  3051. """,
  3052. )
  3053. add_docstr_all(
  3054. "q_zero_point",
  3055. r"""
  3056. q_zero_point() -> int
  3057. Given a Tensor quantized by linear(affine) quantization,
  3058. returns the zero_point of the underlying quantizer().
  3059. """,
  3060. )
  3061. add_docstr_all(
  3062. "q_per_channel_scales",
  3063. r"""
  3064. q_per_channel_scales() -> Tensor
  3065. Given a Tensor quantized by linear (affine) per-channel quantization,
  3066. returns a Tensor of scales of the underlying quantizer. It has the number of
  3067. elements that matches the corresponding dimensions (from q_per_channel_axis) of
  3068. the tensor.
  3069. """,
  3070. )
  3071. add_docstr_all(
  3072. "q_per_channel_zero_points",
  3073. r"""
  3074. q_per_channel_zero_points() -> Tensor
  3075. Given a Tensor quantized by linear (affine) per-channel quantization,
  3076. returns a tensor of zero_points of the underlying quantizer. It has the number of
  3077. elements that matches the corresponding dimensions (from q_per_channel_axis) of
  3078. the tensor.
  3079. """,
  3080. )
  3081. add_docstr_all(
  3082. "q_per_channel_axis",
  3083. r"""
  3084. q_per_channel_axis() -> int
  3085. Given a Tensor quantized by linear (affine) per-channel quantization,
  3086. returns the index of dimension on which per-channel quantization is applied.
  3087. """,
  3088. )
  3089. add_docstr_all(
  3090. "random_",
  3091. r"""
  3092. random_(from=0, to=None, *, generator=None) -> Tensor
  3093. Fills :attr:`self` tensor with numbers sampled from the discrete uniform
  3094. distribution over ``[from, to - 1]``. If not specified, the values are usually
  3095. only bounded by :attr:`self` tensor's data type. However, for floating point
  3096. types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
  3097. value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
  3098. will be uniform in ``[0, 2^53]``.
  3099. """,
  3100. )
  3101. add_docstr_all(
  3102. "rad2deg",
  3103. r"""
  3104. rad2deg() -> Tensor
  3105. See :func:`torch.rad2deg`
  3106. """,
  3107. )
  3108. add_docstr_all(
  3109. "rad2deg_",
  3110. r"""
  3111. rad2deg_() -> Tensor
  3112. In-place version of :meth:`~Tensor.rad2deg`
  3113. """,
  3114. )
  3115. add_docstr_all(
  3116. "deg2rad",
  3117. r"""
  3118. deg2rad() -> Tensor
  3119. See :func:`torch.deg2rad`
  3120. """,
  3121. )
  3122. add_docstr_all(
  3123. "deg2rad_",
  3124. r"""
  3125. deg2rad_() -> Tensor
  3126. In-place version of :meth:`~Tensor.deg2rad`
  3127. """,
  3128. )
  3129. add_docstr_all(
  3130. "ravel",
  3131. r"""
  3132. ravel() -> Tensor
  3133. see :func:`torch.ravel`
  3134. """,
  3135. )
  3136. add_docstr_all(
  3137. "reciprocal",
  3138. r"""
  3139. reciprocal() -> Tensor
  3140. See :func:`torch.reciprocal`
  3141. """,
  3142. )
  3143. add_docstr_all(
  3144. "reciprocal_",
  3145. r"""
  3146. reciprocal_() -> Tensor
  3147. In-place version of :meth:`~Tensor.reciprocal`
  3148. """,
  3149. )
  3150. add_docstr_all(
  3151. "record_stream",
  3152. r"""
  3153. record_stream(stream)
  3154. Marks the tensor as having been used by this stream. When the tensor
  3155. is deallocated, ensure the tensor memory is not reused for another tensor
  3156. until all work queued on :attr:`stream` at the time of deallocation is
  3157. complete.
  3158. .. note::
  3159. The caching allocator is aware of only the stream where a tensor was
  3160. allocated. Due to the awareness, it already correctly manages the life
  3161. cycle of tensors on only one stream. But if a tensor is used on a stream
  3162. different from the stream of origin, the allocator might reuse the memory
  3163. unexpectedly. Calling this method lets the allocator know which streams
  3164. have used the tensor.
  3165. .. warning::
  3166. This method is most suitable for use cases where you are providing a
  3167. function that created a tensor on a side stream, and want users to be able
  3168. to make use of the tensor without having to think carefully about stream
  3169. safety when making use of them. These safety guarantees come at some
  3170. performance and predictability cost (analogous to the tradeoff between GC
  3171. and manual memory management), so if you are in a situation where
  3172. you manage the full lifetime of your tensors, you may consider instead
  3173. manually managing CUDA events so that calling this method is not necessary.
  3174. In particular, when you call this method, on later allocations the
  3175. allocator will poll the recorded stream to see if all operations have
  3176. completed yet; you can potentially race with side stream computation and
  3177. non-deterministically reuse or fail to reuse memory for an allocation.
  3178. You can safely use tensors allocated on side streams without
  3179. :meth:`~Tensor.record_stream`; you must manually ensure that
  3180. any non-creation stream uses of a tensor are synced back to the creation
  3181. stream before you deallocate the tensor. As the CUDA caching allocator
  3182. guarantees that the memory will only be reused with the same creation stream,
  3183. this is sufficient to ensure that writes to future reallocations of the
  3184. memory will be delayed until non-creation stream uses are done.
  3185. (Counterintuitively, you may observe that on the CPU side we have already
  3186. reallocated the tensor, even though CUDA kernels on the old tensor are
  3187. still in progress. This is fine, because CUDA operations on the new
  3188. tensor will appropriately wait for the old operations to complete, as they
  3189. are all on the same stream.)
  3190. Concretely, this looks like this::
  3191. with torch.cuda.stream(s0):
  3192. x = torch.zeros(N)
  3193. s1.wait_stream(s0)
  3194. with torch.cuda.stream(s1):
  3195. y = some_comm_op(x)
  3196. ... some compute on s0 ...
  3197. # synchronize creation stream s0 to side stream s1
  3198. # before deallocating x
  3199. s0.wait_stream(s1)
  3200. del x
  3201. Note that some discretion is required when deciding when to perform
  3202. ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
  3203. after ``some_comm_op``, there wouldn't be any point in having the side
  3204. stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
  3205. Instead, the synchronization must be placed at some appropriate, later
  3206. point in time where you expect the side stream ``s1`` to have finished
  3207. work. This location is typically identified via profiling, e.g., using
  3208. Chrome traces produced
  3209. :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
  3210. place the wait too early, work on s0 will block until ``s1`` has finished,
  3211. preventing further overlapping of communication and computation. If you
  3212. place the wait too late, you will use more memory than is strictly
  3213. necessary (as you are keeping ``x`` live for longer.) For a concrete
  3214. example of how this guidance can be applied in practice, see this post:
  3215. `FSDP and CUDACachingAllocator
  3216. <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
  3217. """,
  3218. )
  3219. add_docstr_all(
  3220. "remainder",
  3221. r"""
  3222. remainder(divisor) -> Tensor
  3223. See :func:`torch.remainder`
  3224. """,
  3225. )
  3226. add_docstr_all(
  3227. "remainder_",
  3228. r"""
  3229. remainder_(divisor) -> Tensor
  3230. In-place version of :meth:`~Tensor.remainder`
  3231. """,
  3232. )
  3233. add_docstr_all(
  3234. "renorm",
  3235. r"""
  3236. renorm(p, dim, maxnorm) -> Tensor
  3237. See :func:`torch.renorm`
  3238. """,
  3239. )
  3240. add_docstr_all(
  3241. "renorm_",
  3242. r"""
  3243. renorm_(p, dim, maxnorm) -> Tensor
  3244. In-place version of :meth:`~Tensor.renorm`
  3245. """,
  3246. )
  3247. add_docstr_all(
  3248. "repeat",
  3249. r"""
  3250. repeat(*repeats) -> Tensor
  3251. Repeats this tensor along the specified dimensions.
  3252. Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
  3253. .. warning::
  3254. :meth:`~Tensor.repeat` behaves differently from
  3255. `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
  3256. but is more similar to
  3257. `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
  3258. For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
  3259. Args:
  3260. repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
  3261. Example::
  3262. >>> x = torch.tensor([1, 2, 3])
  3263. >>> x.repeat(4, 2)
  3264. tensor([[ 1, 2, 3, 1, 2, 3],
  3265. [ 1, 2, 3, 1, 2, 3],
  3266. [ 1, 2, 3, 1, 2, 3],
  3267. [ 1, 2, 3, 1, 2, 3]])
  3268. >>> x.repeat(4, 2, 1).size()
  3269. torch.Size([4, 2, 3])
  3270. """,
  3271. )
  3272. add_docstr_all(
  3273. "repeat_interleave",
  3274. r"""
  3275. repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
  3276. See :func:`torch.repeat_interleave`.
  3277. """,
  3278. )
  3279. add_docstr_all(
  3280. "requires_grad_",
  3281. r"""
  3282. requires_grad_(requires_grad=True) -> Tensor
  3283. Change if autograd should record operations on this tensor: sets this tensor's
  3284. :attr:`requires_grad` attribute in-place. Returns this tensor.
  3285. :func:`requires_grad_`'s main use case is to tell autograd to begin recording
  3286. operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
  3287. (because it was obtained through a DataLoader, or required preprocessing or
  3288. initialization), ``tensor.requires_grad_()`` makes it so that autograd will
  3289. begin to record operations on ``tensor``.
  3290. Args:
  3291. requires_grad (bool): If autograd should record operations on this tensor.
  3292. Default: ``True``.
  3293. Example::
  3294. >>> # Let's say we want to preprocess some saved weights and use
  3295. >>> # the result as new weights.
  3296. >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
  3297. >>> loaded_weights = torch.tensor(saved_weights)
  3298. >>> weights = preprocess(loaded_weights) # some function
  3299. >>> weights
  3300. tensor([-0.5503, 0.4926, -2.1158, -0.8303])
  3301. >>> # Now, start to record operations done to weights
  3302. >>> weights.requires_grad_()
  3303. >>> out = weights.pow(2).sum()
  3304. >>> out.backward()
  3305. >>> weights.grad
  3306. tensor([-1.1007, 0.9853, -4.2316, -1.6606])
  3307. """,
  3308. )
  3309. add_docstr_all(
  3310. "reshape",
  3311. r"""
  3312. reshape(*shape) -> Tensor
  3313. Returns a tensor with the same data and number of elements as :attr:`self`
  3314. but with the specified shape. This method returns a view if :attr:`shape` is
  3315. compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
  3316. possible to return a view.
  3317. See :func:`torch.reshape`
  3318. Args:
  3319. shape (tuple of ints or int...): the desired shape
  3320. """,
  3321. )
  3322. add_docstr_all(
  3323. "reshape_as",
  3324. r"""
  3325. reshape_as(other) -> Tensor
  3326. Returns this tensor as the same shape as :attr:`other`.
  3327. ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
  3328. This method returns a view if ``other.sizes()`` is compatible with the current
  3329. shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
  3330. Please see :meth:`reshape` for more information about ``reshape``.
  3331. Args:
  3332. other (:class:`torch.Tensor`): The result tensor has the same shape
  3333. as :attr:`other`.
  3334. """,
  3335. )
  3336. add_docstr_all(
  3337. "resize_",
  3338. r"""
  3339. resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
  3340. Resizes :attr:`self` tensor to the specified size. If the number of elements is
  3341. larger than the current storage size, then the underlying storage is resized
  3342. to fit the new number of elements. If the number of elements is smaller, the
  3343. underlying storage is not changed. Existing elements are preserved but any new
  3344. memory is uninitialized.
  3345. .. warning::
  3346. This is a low-level method. The storage is reinterpreted as C-contiguous,
  3347. ignoring the current strides (unless the target size equals the current
  3348. size, in which case the tensor is left unchanged). For most purposes, you
  3349. will instead want to use :meth:`~Tensor.view()`, which checks for
  3350. contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
  3351. change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
  3352. .. note::
  3353. If :func:`torch.use_deterministic_algorithms()` and
  3354. :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
  3355. ``True``, new elements are initialized to prevent nondeterministic behavior
  3356. from using the result as an input to an operation. Floating point and
  3357. complex values are set to NaN, and integer values are set to the maximum
  3358. value.
  3359. Args:
  3360. sizes (torch.Size or int...): the desired size
  3361. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  3362. Tensor. Default: ``torch.contiguous_format``. Note that memory format of
  3363. :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
  3364. Example::
  3365. >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
  3366. >>> x.resize_(2, 2)
  3367. tensor([[ 1, 2],
  3368. [ 3, 4]])
  3369. """,
  3370. )
  3371. add_docstr_all(
  3372. "resize_as_",
  3373. r"""
  3374. resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
  3375. Resizes the :attr:`self` tensor to be the same size as the specified
  3376. :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
  3377. Args:
  3378. memory_format (:class:`torch.memory_format`, optional): the desired memory format of
  3379. Tensor. Default: ``torch.contiguous_format``. Note that memory format of
  3380. :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
  3381. """,
  3382. )
  3383. add_docstr_all(
  3384. "rot90",
  3385. r"""
  3386. rot90(k, dims) -> Tensor
  3387. See :func:`torch.rot90`
  3388. """,
  3389. )
  3390. add_docstr_all(
  3391. "round",
  3392. r"""
  3393. round(decimals=0) -> Tensor
  3394. See :func:`torch.round`
  3395. """,
  3396. )
  3397. add_docstr_all(
  3398. "round_",
  3399. r"""
  3400. round_(decimals=0) -> Tensor
  3401. In-place version of :meth:`~Tensor.round`
  3402. """,
  3403. )
  3404. add_docstr_all(
  3405. "rsqrt",
  3406. r"""
  3407. rsqrt() -> Tensor
  3408. See :func:`torch.rsqrt`
  3409. """,
  3410. )
  3411. add_docstr_all(
  3412. "rsqrt_",
  3413. r"""
  3414. rsqrt_() -> Tensor
  3415. In-place version of :meth:`~Tensor.rsqrt`
  3416. """,
  3417. )
  3418. add_docstr_all(
  3419. "scatter_",
  3420. r"""
  3421. scatter_(dim, index, src, *, reduce=None) -> Tensor
  3422. Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
  3423. specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
  3424. index is specified by its index in :attr:`src` for ``dimension != dim`` and by
  3425. the corresponding value in :attr:`index` for ``dimension = dim``.
  3426. For a 3-D tensor, :attr:`self` is updated as::
  3427. self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
  3428. self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
  3429. self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
  3430. This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
  3431. It is also required that
  3432. ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
  3433. ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
  3434. Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
  3435. so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
  3436. Standard broadcasting occurs in all other cases.
  3437. Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
  3438. between ``0`` and ``self.size(dim) - 1`` inclusive.
  3439. .. warning::
  3440. When indices are not unique, the behavior is non-deterministic (one of the
  3441. values from ``src`` will be picked arbitrarily) and the gradient will be
  3442. incorrect (it will be propagated to all locations in the source that
  3443. correspond to the same index)!
  3444. .. note::
  3445. The backward pass is implemented only for ``src.shape == index.shape``.
  3446. Additionally accepts an optional :attr:`reduce` argument that allows
  3447. specification of an optional reduction operation, which is applied to all
  3448. values in the tensor :attr:`src` into :attr:`self` at the indices
  3449. specified in the :attr:`index`. For each value in :attr:`src`, the reduction
  3450. operation is applied to an index in :attr:`self` which is specified by
  3451. its index in :attr:`src` for ``dimension != dim`` and by the corresponding
  3452. value in :attr:`index` for ``dimension = dim``.
  3453. Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
  3454. is updated as::
  3455. self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
  3456. self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
  3457. self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
  3458. Reducing with the addition operation is the same as using
  3459. :meth:`~torch.Tensor.scatter_add_`.
  3460. .. warning::
  3461. The reduce argument with Tensor ``src`` is deprecated and will be removed in
  3462. a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
  3463. instead for more reduction options.
  3464. Args:
  3465. dim (int): the axis along which to index
  3466. index (LongTensor): the indices of elements to scatter, can be either empty
  3467. or of the same dimensionality as ``src``. When empty, the operation
  3468. returns ``self`` unchanged.
  3469. src (Tensor): the source element(s) to scatter.
  3470. Keyword args:
  3471. reduce (str, optional): reduction operation to apply, can be either
  3472. ``'add'`` or ``'multiply'``.
  3473. Example::
  3474. >>> src = torch.arange(1, 11).reshape((2, 5))
  3475. >>> src
  3476. tensor([[ 1, 2, 3, 4, 5],
  3477. [ 6, 7, 8, 9, 10]])
  3478. >>> index = torch.tensor([[0, 1, 2, 0]])
  3479. >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
  3480. tensor([[1, 0, 0, 4, 0],
  3481. [0, 2, 0, 0, 0],
  3482. [0, 0, 3, 0, 0]])
  3483. >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
  3484. >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
  3485. tensor([[1, 2, 3, 0, 0],
  3486. [6, 7, 0, 0, 8],
  3487. [0, 0, 0, 0, 0]])
  3488. >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
  3489. ... 1.23, reduce='multiply')
  3490. tensor([[2.0000, 2.0000, 2.4600, 2.0000],
  3491. [2.0000, 2.0000, 2.0000, 2.4600]])
  3492. >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
  3493. ... 1.23, reduce='add')
  3494. tensor([[2.0000, 2.0000, 3.2300, 2.0000],
  3495. [2.0000, 2.0000, 2.0000, 3.2300]])
  3496. .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
  3497. :noindex:
  3498. Writes the value from :attr:`value` into :attr:`self` at the indices
  3499. specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
  3500. with the :attr:`src` tensor filled entirely with :attr:`value`.
  3501. Args:
  3502. dim (int): the axis along which to index
  3503. index (LongTensor): the indices of elements to scatter, can be either empty
  3504. or of the same dimensionality as ``src``. When empty, the operation
  3505. returns ``self`` unchanged.
  3506. value (Scalar): the value to scatter.
  3507. Keyword args:
  3508. reduce (str, optional): reduction operation to apply, can be either
  3509. ``'add'`` or ``'multiply'``.
  3510. Example::
  3511. >>> index = torch.tensor([[0, 1]])
  3512. >>> value = 2
  3513. >>> torch.zeros(3, 5).scatter_(0, index, value)
  3514. tensor([[2., 0., 0., 0., 0.],
  3515. [0., 2., 0., 0., 0.],
  3516. [0., 0., 0., 0., 0.]])
  3517. """,
  3518. )
  3519. add_docstr_all(
  3520. "scatter_add_",
  3521. r"""
  3522. scatter_add_(dim, index, src) -> Tensor
  3523. Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
  3524. specified in the :attr:`index` tensor in a similar fashion as
  3525. :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
  3526. an index in :attr:`self` which is specified by its index in :attr:`src`
  3527. for ``dimension != dim`` and by the corresponding value in :attr:`index` for
  3528. ``dimension = dim``.
  3529. For a 3-D tensor, :attr:`self` is updated as::
  3530. self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
  3531. self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
  3532. self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
  3533. :attr:`self`, :attr:`index` and :attr:`src` should have same number of
  3534. dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
  3535. dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
  3536. ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
  3537. When :attr:`index` is empty, we always return the original tensor
  3538. without further error checking.
  3539. Note:
  3540. {forward_reproducibility_note}
  3541. .. note::
  3542. The backward pass is implemented only for ``src.shape == index.shape``.
  3543. Args:
  3544. dim (int): the axis along which to index
  3545. index (LongTensor): the indices of elements to scatter and add, can be
  3546. either empty or of the same dimensionality as ``src``. When empty, the
  3547. operation returns ``self`` unchanged.
  3548. src (Tensor): the source elements to scatter and add
  3549. Example::
  3550. >>> src = torch.ones((2, 5))
  3551. >>> index = torch.tensor([[0, 1, 2, 0, 0]])
  3552. >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
  3553. tensor([[1., 0., 0., 1., 1.],
  3554. [0., 1., 0., 0., 0.],
  3555. [0., 0., 1., 0., 0.]])
  3556. >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
  3557. >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
  3558. tensor([[2., 0., 0., 1., 1.],
  3559. [0., 2., 0., 0., 0.],
  3560. [0., 0., 2., 1., 1.]])
  3561. """.format(**reproducibility_notes),
  3562. )
  3563. add_docstr_all(
  3564. "scatter_reduce_",
  3565. r"""
  3566. scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
  3567. Reduces all values from the :attr:`src` tensor to the indices specified in
  3568. the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
  3569. defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
  3570. :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
  3571. index in :attr:`self` which is specified by its index in :attr:`src` for
  3572. ``dimension != dim`` and by the corresponding value in :attr:`index` for
  3573. ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
  3574. tensor are included in the reduction.
  3575. :attr:`self`, :attr:`index` and :attr:`src` should all have
  3576. the same number of dimensions. It is also required that
  3577. ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
  3578. ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
  3579. Note that ``index`` and ``src`` do not broadcast.
  3580. For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
  3581. output is given as::
  3582. self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
  3583. self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
  3584. self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
  3585. Note:
  3586. {forward_reproducibility_note}
  3587. .. note::
  3588. The backward pass is implemented only for ``src.shape == index.shape``.
  3589. .. warning::
  3590. This function is in beta and may change in the near future.
  3591. Args:
  3592. dim (int): the axis along which to index
  3593. index (LongTensor): the indices of elements to scatter and reduce.
  3594. src (Tensor): the source elements to scatter and reduce
  3595. reduce (str): the reduction operation to apply for non-unique indices
  3596. (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
  3597. include_self (bool): whether elements from the :attr:`self` tensor are
  3598. included in the reduction
  3599. Example::
  3600. >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
  3601. >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
  3602. >>> input = torch.tensor([1., 2., 3., 4.])
  3603. >>> input.scatter_reduce(0, index, src, reduce="sum")
  3604. tensor([5., 14., 8., 4.])
  3605. >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
  3606. tensor([4., 12., 5., 4.])
  3607. >>> input2 = torch.tensor([5., 4., 3., 2.])
  3608. >>> input2.scatter_reduce(0, index, src, reduce="amax")
  3609. tensor([5., 6., 5., 2.])
  3610. >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
  3611. tensor([3., 6., 5., 2.])
  3612. """.format(**reproducibility_notes),
  3613. )
  3614. add_docstr_all(
  3615. "select",
  3616. r"""
  3617. select(dim, index) -> Tensor
  3618. See :func:`torch.select`
  3619. """,
  3620. )
  3621. add_docstr_all(
  3622. "select_scatter",
  3623. r"""
  3624. select_scatter(src, dim, index) -> Tensor
  3625. See :func:`torch.select_scatter`
  3626. """,
  3627. )
  3628. add_docstr_all(
  3629. "slice_scatter",
  3630. r"""
  3631. slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
  3632. See :func:`torch.slice_scatter`
  3633. """,
  3634. )
  3635. add_docstr_all(
  3636. "set_",
  3637. r"""
  3638. set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
  3639. Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
  3640. :attr:`self` tensor will share the same storage and have the same size and
  3641. strides as :attr:`source`. Changes to elements in one tensor will be reflected
  3642. in the other.
  3643. If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
  3644. storage, offset, size, and stride.
  3645. Args:
  3646. source (Tensor or Storage): the tensor or storage to use
  3647. storage_offset (int, optional): the offset in the storage
  3648. size (torch.Size, optional): the desired size. Defaults to the size of the source.
  3649. stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
  3650. """,
  3651. )
  3652. add_docstr_all(
  3653. "sigmoid",
  3654. r"""
  3655. sigmoid() -> Tensor
  3656. See :func:`torch.sigmoid`
  3657. """,
  3658. )
  3659. add_docstr_all(
  3660. "sigmoid_",
  3661. r"""
  3662. sigmoid_() -> Tensor
  3663. In-place version of :meth:`~Tensor.sigmoid`
  3664. """,
  3665. )
  3666. add_docstr_all(
  3667. "logit",
  3668. r"""
  3669. logit() -> Tensor
  3670. See :func:`torch.logit`
  3671. """,
  3672. )
  3673. add_docstr_all(
  3674. "logit_",
  3675. r"""
  3676. logit_() -> Tensor
  3677. In-place version of :meth:`~Tensor.logit`
  3678. """,
  3679. )
  3680. add_docstr_all(
  3681. "sign",
  3682. r"""
  3683. sign() -> Tensor
  3684. See :func:`torch.sign`
  3685. """,
  3686. )
  3687. add_docstr_all(
  3688. "sign_",
  3689. r"""
  3690. sign_() -> Tensor
  3691. In-place version of :meth:`~Tensor.sign`
  3692. """,
  3693. )
  3694. add_docstr_all(
  3695. "signbit",
  3696. r"""
  3697. signbit() -> Tensor
  3698. See :func:`torch.signbit`
  3699. """,
  3700. )
  3701. add_docstr_all(
  3702. "sgn",
  3703. r"""
  3704. sgn() -> Tensor
  3705. See :func:`torch.sgn`
  3706. """,
  3707. )
  3708. add_docstr_all(
  3709. "sgn_",
  3710. r"""
  3711. sgn_() -> Tensor
  3712. In-place version of :meth:`~Tensor.sgn`
  3713. """,
  3714. )
  3715. add_docstr_all(
  3716. "sin",
  3717. r"""
  3718. sin() -> Tensor
  3719. See :func:`torch.sin`
  3720. """,
  3721. )
  3722. add_docstr_all(
  3723. "sin_",
  3724. r"""
  3725. sin_() -> Tensor
  3726. In-place version of :meth:`~Tensor.sin`
  3727. """,
  3728. )
  3729. add_docstr_all(
  3730. "sinc",
  3731. r"""
  3732. sinc() -> Tensor
  3733. See :func:`torch.sinc`
  3734. """,
  3735. )
  3736. add_docstr_all(
  3737. "sinc_",
  3738. r"""
  3739. sinc_() -> Tensor
  3740. In-place version of :meth:`~Tensor.sinc`
  3741. """,
  3742. )
  3743. add_docstr_all(
  3744. "sinh",
  3745. r"""
  3746. sinh() -> Tensor
  3747. See :func:`torch.sinh`
  3748. """,
  3749. )
  3750. add_docstr_all(
  3751. "sinh_",
  3752. r"""
  3753. sinh_() -> Tensor
  3754. In-place version of :meth:`~Tensor.sinh`
  3755. """,
  3756. )
  3757. add_docstr_all(
  3758. "size",
  3759. r"""
  3760. size(dim=None) -> torch.Size or int
  3761. Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
  3762. the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
  3763. If ``dim`` is specified, returns an int holding the size of that dimension.
  3764. Args:
  3765. dim (int, optional): The dimension for which to retrieve the size.
  3766. Example::
  3767. >>> t = torch.empty(3, 4, 5)
  3768. >>> t.size()
  3769. torch.Size([3, 4, 5])
  3770. >>> t.size(dim=1)
  3771. 4
  3772. """,
  3773. )
  3774. add_docstr_all(
  3775. "shape",
  3776. r"""
  3777. shape() -> torch.Size
  3778. Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
  3779. See also :meth:`Tensor.size`.
  3780. Example::
  3781. >>> t = torch.empty(3, 4, 5)
  3782. >>> t.size()
  3783. torch.Size([3, 4, 5])
  3784. >>> t.shape
  3785. torch.Size([3, 4, 5])
  3786. """,
  3787. )
  3788. add_docstr_all(
  3789. "sort",
  3790. r"""
  3791. sort(dim=-1, descending=False) -> (Tensor, LongTensor)
  3792. See :func:`torch.sort`
  3793. """,
  3794. )
  3795. add_docstr_all(
  3796. "msort",
  3797. r"""
  3798. msort() -> Tensor
  3799. See :func:`torch.msort`
  3800. """,
  3801. )
  3802. add_docstr_all(
  3803. "argsort",
  3804. r"""
  3805. argsort(dim=-1, descending=False) -> LongTensor
  3806. See :func:`torch.argsort`
  3807. """,
  3808. )
  3809. add_docstr_all(
  3810. "sparse_dim",
  3811. r"""
  3812. sparse_dim() -> int
  3813. Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
  3814. .. note::
  3815. Returns ``0`` if :attr:`self` is not a sparse tensor.
  3816. See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
  3817. """,
  3818. )
  3819. add_docstr_all(
  3820. "sparse_resize_",
  3821. r"""
  3822. sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
  3823. Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
  3824. size and the number of sparse and dense dimensions.
  3825. .. note::
  3826. If the number of specified elements in :attr:`self` is zero, then
  3827. :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
  3828. size and positive integers such that ``len(size) == sparse_dim +
  3829. dense_dim``.
  3830. If :attr:`self` specifies one or more elements, however, then each
  3831. dimension in :attr:`size` must not be smaller than the corresponding
  3832. dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
  3833. of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
  3834. equal the number of dense dimensions in :attr:`self`.
  3835. .. warning::
  3836. Throws an error if :attr:`self` is not a sparse tensor.
  3837. Args:
  3838. size (torch.Size): the desired size. If :attr:`self` is non-empty
  3839. sparse tensor, the desired size cannot be smaller than the
  3840. original size.
  3841. sparse_dim (int): the number of sparse dimensions
  3842. dense_dim (int): the number of dense dimensions
  3843. """,
  3844. )
  3845. add_docstr_all(
  3846. "sparse_resize_and_clear_",
  3847. r"""
  3848. sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
  3849. Removes all specified elements from a :ref:`sparse tensor
  3850. <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
  3851. size and the number of sparse and dense dimensions.
  3852. .. warning:
  3853. Throws an error if :attr:`self` is not a sparse tensor.
  3854. Args:
  3855. size (torch.Size): the desired size.
  3856. sparse_dim (int): the number of sparse dimensions
  3857. dense_dim (int): the number of dense dimensions
  3858. """,
  3859. )
  3860. add_docstr_all(
  3861. "sqrt",
  3862. r"""
  3863. sqrt() -> Tensor
  3864. See :func:`torch.sqrt`
  3865. """,
  3866. )
  3867. add_docstr_all(
  3868. "sqrt_",
  3869. r"""
  3870. sqrt_() -> Tensor
  3871. In-place version of :meth:`~Tensor.sqrt`
  3872. """,
  3873. )
  3874. add_docstr_all(
  3875. "square",
  3876. r"""
  3877. square() -> Tensor
  3878. See :func:`torch.square`
  3879. """,
  3880. )
  3881. add_docstr_all(
  3882. "square_",
  3883. r"""
  3884. square_() -> Tensor
  3885. In-place version of :meth:`~Tensor.square`
  3886. """,
  3887. )
  3888. add_docstr_all(
  3889. "squeeze",
  3890. r"""
  3891. squeeze(dim=None) -> Tensor
  3892. See :func:`torch.squeeze`
  3893. """,
  3894. )
  3895. add_docstr_all(
  3896. "squeeze_",
  3897. r"""
  3898. squeeze_(dim=None) -> Tensor
  3899. In-place version of :meth:`~Tensor.squeeze`
  3900. """,
  3901. )
  3902. add_docstr_all(
  3903. "std",
  3904. r"""
  3905. std(dim=None, *, correction=1, keepdim=False) -> Tensor
  3906. See :func:`torch.std`
  3907. """,
  3908. )
  3909. add_docstr_all(
  3910. "storage_offset",
  3911. r"""
  3912. storage_offset() -> int
  3913. Returns :attr:`self` tensor's offset in the underlying storage in terms of
  3914. number of storage elements (not bytes).
  3915. Example::
  3916. >>> x = torch.tensor([1, 2, 3, 4, 5])
  3917. >>> x.storage_offset()
  3918. 0
  3919. >>> x[3:].storage_offset()
  3920. 3
  3921. """,
  3922. )
  3923. add_docstr_all(
  3924. "untyped_storage",
  3925. r"""
  3926. untyped_storage() -> torch.UntypedStorage
  3927. Returns the underlying :class:`UntypedStorage`.
  3928. """,
  3929. )
  3930. add_docstr_all(
  3931. "stride",
  3932. r"""
  3933. stride(dim) -> tuple or int
  3934. Returns the stride of :attr:`self` tensor.
  3935. Stride is the jump necessary to go from one element to the next one in the
  3936. specified dimension :attr:`dim`. A tuple of all strides is returned when no
  3937. argument is passed in. Otherwise, an integer value is returned as the stride in
  3938. the particular dimension :attr:`dim`.
  3939. Args:
  3940. dim (int, optional): the desired dimension in which stride is required
  3941. Example::
  3942. >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
  3943. >>> x.stride()
  3944. (5, 1)
  3945. >>> x.stride(0)
  3946. 5
  3947. >>> x.stride(-1)
  3948. 1
  3949. """,
  3950. )
  3951. add_docstr_all(
  3952. "sub",
  3953. r"""
  3954. sub(other, *, alpha=1) -> Tensor
  3955. See :func:`torch.sub`.
  3956. """,
  3957. )
  3958. add_docstr_all(
  3959. "sub_",
  3960. r"""
  3961. sub_(other, *, alpha=1) -> Tensor
  3962. In-place version of :meth:`~Tensor.sub`
  3963. """,
  3964. )
  3965. add_docstr_all(
  3966. "subtract",
  3967. r"""
  3968. subtract(other, *, alpha=1) -> Tensor
  3969. See :func:`torch.subtract`.
  3970. """,
  3971. )
  3972. add_docstr_all(
  3973. "subtract_",
  3974. r"""
  3975. subtract_(other, *, alpha=1) -> Tensor
  3976. In-place version of :meth:`~Tensor.subtract`.
  3977. """,
  3978. )
  3979. add_docstr_all(
  3980. "sum",
  3981. r"""
  3982. sum(dim=None, keepdim=False, dtype=None) -> Tensor
  3983. See :func:`torch.sum`
  3984. """,
  3985. )
  3986. add_docstr_all(
  3987. "nansum",
  3988. r"""
  3989. nansum(dim=None, keepdim=False, dtype=None) -> Tensor
  3990. See :func:`torch.nansum`
  3991. """,
  3992. )
  3993. add_docstr_all(
  3994. "svd",
  3995. r"""
  3996. svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
  3997. See :func:`torch.svd`
  3998. """,
  3999. )
  4000. add_docstr_all(
  4001. "swapdims",
  4002. r"""
  4003. swapdims(dim0, dim1) -> Tensor
  4004. See :func:`torch.swapdims`
  4005. """,
  4006. )
  4007. add_docstr_all(
  4008. "swapdims_",
  4009. r"""
  4010. swapdims_(dim0, dim1) -> Tensor
  4011. In-place version of :meth:`~Tensor.swapdims`
  4012. """,
  4013. )
  4014. add_docstr_all(
  4015. "swapaxes",
  4016. r"""
  4017. swapaxes(axis0, axis1) -> Tensor
  4018. See :func:`torch.swapaxes`
  4019. """,
  4020. )
  4021. add_docstr_all(
  4022. "swapaxes_",
  4023. r"""
  4024. swapaxes_(axis0, axis1) -> Tensor
  4025. In-place version of :meth:`~Tensor.swapaxes`
  4026. """,
  4027. )
  4028. add_docstr_all(
  4029. "t",
  4030. r"""
  4031. t() -> Tensor
  4032. See :func:`torch.t`
  4033. """,
  4034. )
  4035. add_docstr_all(
  4036. "t_",
  4037. r"""
  4038. t_() -> Tensor
  4039. In-place version of :meth:`~Tensor.t`
  4040. """,
  4041. )
  4042. add_docstr_all(
  4043. "tile",
  4044. r"""
  4045. tile(dims) -> Tensor
  4046. See :func:`torch.tile`
  4047. """,
  4048. )
  4049. add_docstr_all(
  4050. "to",
  4051. r"""
  4052. to(*args, **kwargs) -> Tensor
  4053. Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
  4054. inferred from the arguments of ``self.to(*args, **kwargs)``.
  4055. .. note::
  4056. If the ``self`` Tensor already
  4057. has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
  4058. Otherwise, the returned tensor is a copy of ``self`` with the desired
  4059. :class:`torch.dtype` and :class:`torch.device`.
  4060. .. note::
  4061. If ``self`` requires gradients (``requires_grad=True``) but the target
  4062. ``dtype`` specified is an integer type, the returned tensor will implicitly
  4063. set ``requires_grad=False``. This is because only tensors with
  4064. floating-point or complex dtypes can require gradients.
  4065. Here are the ways to call ``to``:
  4066. .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
  4067. :noindex:
  4068. Returns a Tensor with the specified :attr:`dtype`
  4069. Args:
  4070. {memory_format}
  4071. .. note::
  4072. According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
  4073. converting floating point value to integer type will truncate the fractional part.
  4074. If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
  4075. the behavior is undefined and the result may vary across platforms.
  4076. .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
  4077. :noindex:
  4078. Returns a Tensor with the specified :attr:`device` and (optional)
  4079. :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
  4080. When :attr:`non_blocking` is set to ``True``, the function attempts to perform
  4081. the conversion asynchronously with respect to the host, if possible. This
  4082. asynchronous behavior applies to both pinned and pageable memory. However,
  4083. caution is advised when using this feature. For more information, refer to the
  4084. `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
  4085. When :attr:`copy` is set, a new Tensor is created even when the Tensor
  4086. already matches the desired conversion.
  4087. Args:
  4088. {memory_format}
  4089. .. method:: to(other, non_blocking=False, copy=False) -> Tensor
  4090. :noindex:
  4091. Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
  4092. the Tensor :attr:`other`.
  4093. When :attr:`non_blocking` is set to ``True``, the function attempts to perform
  4094. the conversion asynchronously with respect to the host, if possible. This
  4095. asynchronous behavior applies to both pinned and pageable memory. However,
  4096. caution is advised when using this feature. For more information, refer to the
  4097. `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
  4098. When :attr:`copy` is set, a new Tensor is created even when the Tensor
  4099. already matches the desired conversion.
  4100. Example::
  4101. >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
  4102. >>> tensor.to(torch.float64)
  4103. tensor([[-0.5044, 0.0005],
  4104. [ 0.3310, -0.0584]], dtype=torch.float64)
  4105. >>> cuda0 = torch.device('cuda:0')
  4106. >>> tensor.to(cuda0)
  4107. tensor([[-0.5044, 0.0005],
  4108. [ 0.3310, -0.0584]], device='cuda:0')
  4109. >>> tensor.to(cuda0, dtype=torch.float64)
  4110. tensor([[-0.5044, 0.0005],
  4111. [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
  4112. >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
  4113. >>> tensor.to(other, non_blocking=True)
  4114. tensor([[-0.5044, 0.0005],
  4115. [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
  4116. """.format(**common_args),
  4117. )
  4118. add_docstr_all(
  4119. "byte",
  4120. r"""
  4121. byte(memory_format=torch.preserve_format) -> Tensor
  4122. ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
  4123. Args:
  4124. {memory_format}
  4125. """.format(**common_args),
  4126. )
  4127. add_docstr_all(
  4128. "bool",
  4129. r"""
  4130. bool(memory_format=torch.preserve_format) -> Tensor
  4131. ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
  4132. Args:
  4133. {memory_format}
  4134. """.format(**common_args),
  4135. )
  4136. add_docstr_all(
  4137. "char",
  4138. r"""
  4139. char(memory_format=torch.preserve_format) -> Tensor
  4140. ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
  4141. Args:
  4142. {memory_format}
  4143. """.format(**common_args),
  4144. )
  4145. add_docstr_all(
  4146. "bfloat16",
  4147. r"""
  4148. bfloat16(memory_format=torch.preserve_format) -> Tensor
  4149. ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
  4150. Args:
  4151. {memory_format}
  4152. """.format(**common_args),
  4153. )
  4154. add_docstr_all(
  4155. "double",
  4156. r"""
  4157. double(memory_format=torch.preserve_format) -> Tensor
  4158. ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
  4159. Args:
  4160. {memory_format}
  4161. """.format(**common_args),
  4162. )
  4163. add_docstr_all(
  4164. "float",
  4165. r"""
  4166. float(memory_format=torch.preserve_format) -> Tensor
  4167. ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
  4168. Args:
  4169. {memory_format}
  4170. """.format(**common_args),
  4171. )
  4172. add_docstr_all(
  4173. "cdouble",
  4174. r"""
  4175. cdouble(memory_format=torch.preserve_format) -> Tensor
  4176. ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
  4177. Args:
  4178. {memory_format}
  4179. """.format(**common_args),
  4180. )
  4181. add_docstr_all(
  4182. "cfloat",
  4183. r"""
  4184. cfloat(memory_format=torch.preserve_format) -> Tensor
  4185. ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
  4186. Args:
  4187. {memory_format}
  4188. """.format(**common_args),
  4189. )
  4190. add_docstr_all(
  4191. "chalf",
  4192. r"""
  4193. chalf(memory_format=torch.preserve_format) -> Tensor
  4194. ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
  4195. Args:
  4196. {memory_format}
  4197. """.format(**common_args),
  4198. )
  4199. add_docstr_all(
  4200. "half",
  4201. r"""
  4202. half(memory_format=torch.preserve_format) -> Tensor
  4203. ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
  4204. Args:
  4205. {memory_format}
  4206. """.format(**common_args),
  4207. )
  4208. add_docstr_all(
  4209. "int",
  4210. r"""
  4211. int(memory_format=torch.preserve_format) -> Tensor
  4212. ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
  4213. Args:
  4214. {memory_format}
  4215. """.format(**common_args),
  4216. )
  4217. add_docstr_all(
  4218. "int_repr",
  4219. r"""
  4220. int_repr() -> Tensor
  4221. Given a quantized Tensor,
  4222. ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
  4223. underlying uint8_t values of the given Tensor.
  4224. """,
  4225. )
  4226. add_docstr_all(
  4227. "long",
  4228. r"""
  4229. long(memory_format=torch.preserve_format) -> Tensor
  4230. ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
  4231. Args:
  4232. {memory_format}
  4233. """.format(**common_args),
  4234. )
  4235. add_docstr_all(
  4236. "short",
  4237. r"""
  4238. short(memory_format=torch.preserve_format) -> Tensor
  4239. ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
  4240. Args:
  4241. {memory_format}
  4242. """.format(**common_args),
  4243. )
  4244. add_docstr_all(
  4245. "take",
  4246. r"""
  4247. take(indices) -> Tensor
  4248. See :func:`torch.take`
  4249. """,
  4250. )
  4251. add_docstr_all(
  4252. "take_along_dim",
  4253. r"""
  4254. take_along_dim(indices, dim) -> Tensor
  4255. See :func:`torch.take_along_dim`
  4256. """,
  4257. )
  4258. add_docstr_all(
  4259. "tan",
  4260. r"""
  4261. tan() -> Tensor
  4262. See :func:`torch.tan`
  4263. """,
  4264. )
  4265. add_docstr_all(
  4266. "tan_",
  4267. r"""
  4268. tan_() -> Tensor
  4269. In-place version of :meth:`~Tensor.tan`
  4270. """,
  4271. )
  4272. add_docstr_all(
  4273. "tanh",
  4274. r"""
  4275. tanh() -> Tensor
  4276. See :func:`torch.tanh`
  4277. """,
  4278. )
  4279. add_docstr_all(
  4280. "softmax",
  4281. r"""
  4282. softmax(dim) -> Tensor
  4283. Alias for :func:`torch.nn.functional.softmax`.
  4284. """,
  4285. )
  4286. add_docstr_all(
  4287. "tanh_",
  4288. r"""
  4289. tanh_() -> Tensor
  4290. In-place version of :meth:`~Tensor.tanh`
  4291. """,
  4292. )
  4293. add_docstr_all(
  4294. "tolist",
  4295. r"""
  4296. tolist() -> list or number
  4297. Returns the tensor as a (nested) list. For scalars, a standard
  4298. Python number is returned, just like with :meth:`~Tensor.item`.
  4299. Tensors are automatically moved to the CPU first if necessary.
  4300. This operation is not differentiable.
  4301. Examples::
  4302. >>> a = torch.randn(2, 2)
  4303. >>> a.tolist()
  4304. [[0.012766935862600803, 0.5415473580360413],
  4305. [-0.08909505605697632, 0.7729271650314331]]
  4306. >>> a[0,0].tolist()
  4307. 0.012766935862600803
  4308. """,
  4309. )
  4310. add_docstr_all(
  4311. "topk",
  4312. r"""
  4313. topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
  4314. See :func:`torch.topk`
  4315. """,
  4316. )
  4317. add_docstr_all(
  4318. "to_dense",
  4319. r"""
  4320. to_dense(dtype=None, *, masked_grad=True) -> Tensor
  4321. Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
  4322. Keyword args:
  4323. {dtype}
  4324. masked_grad (bool, optional): If set to ``True`` (default) and
  4325. :attr:`self` has a sparse layout then the backward of
  4326. :meth:`to_dense` returns ``grad.sparse_mask(self)``.
  4327. Example::
  4328. >>> s = torch.sparse_coo_tensor(
  4329. ... torch.tensor([[1, 1],
  4330. ... [0, 2]]),
  4331. ... torch.tensor([9, 10]),
  4332. ... size=(3, 3))
  4333. >>> s.to_dense()
  4334. tensor([[ 0, 0, 0],
  4335. [ 9, 0, 10],
  4336. [ 0, 0, 0]])
  4337. """,
  4338. )
  4339. add_docstr_all(
  4340. "to_sparse",
  4341. r"""
  4342. to_sparse(sparseDims) -> Tensor
  4343. Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
  4344. :ref:`coordinate format <sparse-coo-docs>`.
  4345. Args:
  4346. sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
  4347. Example::
  4348. >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
  4349. >>> d
  4350. tensor([[ 0, 0, 0],
  4351. [ 9, 0, 10],
  4352. [ 0, 0, 0]])
  4353. >>> d.to_sparse()
  4354. tensor(indices=tensor([[1, 1],
  4355. [0, 2]]),
  4356. values=tensor([ 9, 10]),
  4357. size=(3, 3), nnz=2, layout=torch.sparse_coo)
  4358. >>> d.to_sparse(1)
  4359. tensor(indices=tensor([[1]]),
  4360. values=tensor([[ 9, 0, 10]]),
  4361. size=(3, 3), nnz=1, layout=torch.sparse_coo)
  4362. .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
  4363. :noindex:
  4364. Returns a sparse tensor with the specified layout and blocksize. If
  4365. the :attr:`self` is strided, the number of dense dimensions could be
  4366. specified, and a hybrid sparse tensor will be created, with
  4367. `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
  4368. dimension.
  4369. .. note:: If the :attr:`self` layout and blocksize parameters match
  4370. with the specified layout and blocksize, return
  4371. :attr:`self`. Otherwise, return a sparse tensor copy of
  4372. :attr:`self`.
  4373. Args:
  4374. layout (:class:`torch.layout`, optional): The desired sparse
  4375. layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
  4376. ``torch.sparse_csc``, ``torch.sparse_bsr``, or
  4377. ``torch.sparse_bsc``. Default: if ``None``,
  4378. ``torch.sparse_coo``.
  4379. blocksize (list, tuple, :class:`torch.Size`, optional): Block size
  4380. of the resulting BSR or BSC tensor. For other layouts,
  4381. specifying the block size that is not ``None`` will result in a
  4382. RuntimeError exception. A block size must be a tuple of length
  4383. two such that its items evenly divide the two sparse dimensions.
  4384. dense_dim (int, optional): Number of dense dimensions of the
  4385. resulting CSR, CSC, BSR or BSC tensor. This argument should be
  4386. used only if :attr:`self` is a strided tensor, and must be a
  4387. value between 0 and dimension of :attr:`self` tensor minus two.
  4388. Example::
  4389. >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
  4390. >>> x.to_sparse(layout=torch.sparse_coo)
  4391. tensor(indices=tensor([[0, 2, 2],
  4392. [0, 0, 1]]),
  4393. values=tensor([1, 2, 3]),
  4394. size=(3, 2), nnz=3, layout=torch.sparse_coo)
  4395. >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
  4396. tensor(crow_indices=tensor([0, 1, 1, 2]),
  4397. col_indices=tensor([0, 0]),
  4398. values=tensor([[[1, 0]],
  4399. [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
  4400. >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
  4401. RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
  4402. >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
  4403. RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
  4404. >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
  4405. >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
  4406. tensor(crow_indices=tensor([0, 1, 1, 3]),
  4407. col_indices=tensor([0, 0, 1]),
  4408. values=tensor([[1],
  4409. [2],
  4410. [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
  4411. """,
  4412. )
  4413. add_docstr_all(
  4414. "to_sparse_csr",
  4415. r"""
  4416. to_sparse_csr(dense_dim=None) -> Tensor
  4417. Convert a tensor to compressed row storage format (CSR). Except for
  4418. strided tensors, only works with 2D tensors. If the :attr:`self` is
  4419. strided, then the number of dense dimensions could be specified, and a
  4420. hybrid CSR tensor will be created, with `dense_dim` dense dimensions
  4421. and `self.dim() - 2 - dense_dim` batch dimension.
  4422. Args:
  4423. dense_dim (int, optional): Number of dense dimensions of the
  4424. resulting CSR tensor. This argument should be used only if
  4425. :attr:`self` is a strided tensor, and must be a value between 0
  4426. and dimension of :attr:`self` tensor minus two.
  4427. Example::
  4428. >>> dense = torch.randn(5, 5)
  4429. >>> sparse = dense.to_sparse_csr()
  4430. >>> sparse._nnz()
  4431. 25
  4432. >>> dense = torch.zeros(3, 3, 1, 1)
  4433. >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
  4434. >>> dense.to_sparse_csr(dense_dim=2)
  4435. tensor(crow_indices=tensor([0, 1, 2, 3]),
  4436. col_indices=tensor([0, 2, 1]),
  4437. values=tensor([[[1.]],
  4438. [[1.]],
  4439. [[1.]]]), size=(3, 3, 1, 1), nnz=3,
  4440. layout=torch.sparse_csr)
  4441. """,
  4442. )
  4443. add_docstr_all(
  4444. "to_sparse_csc",
  4445. r"""
  4446. to_sparse_csc() -> Tensor
  4447. Convert a tensor to compressed column storage (CSC) format. Except
  4448. for strided tensors, only works with 2D tensors. If the :attr:`self`
  4449. is strided, then the number of dense dimensions could be specified,
  4450. and a hybrid CSC tensor will be created, with `dense_dim` dense
  4451. dimensions and `self.dim() - 2 - dense_dim` batch dimension.
  4452. Args:
  4453. dense_dim (int, optional): Number of dense dimensions of the
  4454. resulting CSC tensor. This argument should be used only if
  4455. :attr:`self` is a strided tensor, and must be a value between 0
  4456. and dimension of :attr:`self` tensor minus two.
  4457. Example::
  4458. >>> dense = torch.randn(5, 5)
  4459. >>> sparse = dense.to_sparse_csc()
  4460. >>> sparse._nnz()
  4461. 25
  4462. >>> dense = torch.zeros(3, 3, 1, 1)
  4463. >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
  4464. >>> dense.to_sparse_csc(dense_dim=2)
  4465. tensor(ccol_indices=tensor([0, 1, 2, 3]),
  4466. row_indices=tensor([0, 2, 1]),
  4467. values=tensor([[[1.]],
  4468. [[1.]],
  4469. [[1.]]]), size=(3, 3, 1, 1), nnz=3,
  4470. layout=torch.sparse_csc)
  4471. """,
  4472. )
  4473. add_docstr_all(
  4474. "to_sparse_bsr",
  4475. r"""
  4476. to_sparse_bsr(blocksize, dense_dim) -> Tensor
  4477. Convert a tensor to a block sparse row (BSR) storage format of given
  4478. blocksize. If the :attr:`self` is strided, then the number of dense
  4479. dimensions could be specified, and a hybrid BSR tensor will be
  4480. created, with `dense_dim` dense dimensions and `self.dim() - 2 -
  4481. dense_dim` batch dimension.
  4482. Args:
  4483. blocksize (list, tuple, :class:`torch.Size`, optional): Block size
  4484. of the resulting BSR tensor. A block size must be a tuple of
  4485. length two such that its items evenly divide the two sparse
  4486. dimensions.
  4487. dense_dim (int, optional): Number of dense dimensions of the
  4488. resulting BSR tensor. This argument should be used only if
  4489. :attr:`self` is a strided tensor, and must be a value between 0
  4490. and dimension of :attr:`self` tensor minus two.
  4491. Example::
  4492. >>> dense = torch.randn(10, 10)
  4493. >>> sparse = dense.to_sparse_csr()
  4494. >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
  4495. >>> sparse_bsr.col_indices()
  4496. tensor([0, 1, 0, 1])
  4497. >>> dense = torch.zeros(4, 3, 1)
  4498. >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
  4499. >>> dense.to_sparse_bsr((2, 1), 1)
  4500. tensor(crow_indices=tensor([0, 2, 3]),
  4501. col_indices=tensor([0, 2, 1]),
  4502. values=tensor([[[[1.]],
  4503. [[1.]]],
  4504. [[[1.]],
  4505. [[1.]]],
  4506. [[[1.]],
  4507. [[1.]]]]), size=(4, 3, 1), nnz=3,
  4508. layout=torch.sparse_bsr)
  4509. """,
  4510. )
  4511. add_docstr_all(
  4512. "to_sparse_bsc",
  4513. r"""
  4514. to_sparse_bsc(blocksize, dense_dim) -> Tensor
  4515. Convert a tensor to a block sparse column (BSC) storage format of
  4516. given blocksize. If the :attr:`self` is strided, then the number of
  4517. dense dimensions could be specified, and a hybrid BSC tensor will be
  4518. created, with `dense_dim` dense dimensions and `self.dim() - 2 -
  4519. dense_dim` batch dimension.
  4520. Args:
  4521. blocksize (list, tuple, :class:`torch.Size`, optional): Block size
  4522. of the resulting BSC tensor. A block size must be a tuple of
  4523. length two such that its items evenly divide the two sparse
  4524. dimensions.
  4525. dense_dim (int, optional): Number of dense dimensions of the
  4526. resulting BSC tensor. This argument should be used only if
  4527. :attr:`self` is a strided tensor, and must be a value between 0
  4528. and dimension of :attr:`self` tensor minus two.
  4529. Example::
  4530. >>> dense = torch.randn(10, 10)
  4531. >>> sparse = dense.to_sparse_csr()
  4532. >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
  4533. >>> sparse_bsc.row_indices()
  4534. tensor([0, 1, 0, 1])
  4535. >>> dense = torch.zeros(4, 3, 1)
  4536. >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
  4537. >>> dense.to_sparse_bsc((2, 1), 1)
  4538. tensor(ccol_indices=tensor([0, 1, 2, 3]),
  4539. row_indices=tensor([0, 1, 0]),
  4540. values=tensor([[[[1.]],
  4541. [[1.]]],
  4542. [[[1.]],
  4543. [[1.]]],
  4544. [[[1.]],
  4545. [[1.]]]]), size=(4, 3, 1), nnz=3,
  4546. layout=torch.sparse_bsc)
  4547. """,
  4548. )
  4549. add_docstr_all(
  4550. "to_mkldnn",
  4551. r"""
  4552. to_mkldnn() -> Tensor
  4553. Returns a copy of the tensor in ``torch.mkldnn`` layout.
  4554. """,
  4555. )
  4556. add_docstr_all(
  4557. "trace",
  4558. r"""
  4559. trace() -> Tensor
  4560. See :func:`torch.trace`
  4561. """,
  4562. )
  4563. add_docstr_all(
  4564. "transpose",
  4565. r"""
  4566. transpose(dim0, dim1) -> Tensor
  4567. See :func:`torch.transpose`
  4568. """,
  4569. )
  4570. add_docstr_all(
  4571. "transpose_",
  4572. r"""
  4573. transpose_(dim0, dim1) -> Tensor
  4574. In-place version of :meth:`~Tensor.transpose`
  4575. """,
  4576. )
  4577. add_docstr_all(
  4578. "triangular_solve",
  4579. r"""
  4580. triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
  4581. See :func:`torch.triangular_solve`
  4582. """,
  4583. )
  4584. add_docstr_all(
  4585. "tril",
  4586. r"""
  4587. tril(diagonal=0) -> Tensor
  4588. See :func:`torch.tril`
  4589. """,
  4590. )
  4591. add_docstr_all(
  4592. "tril_",
  4593. r"""
  4594. tril_(diagonal=0) -> Tensor
  4595. In-place version of :meth:`~Tensor.tril`
  4596. """,
  4597. )
  4598. add_docstr_all(
  4599. "triu",
  4600. r"""
  4601. triu(diagonal=0) -> Tensor
  4602. See :func:`torch.triu`
  4603. """,
  4604. )
  4605. add_docstr_all(
  4606. "triu_",
  4607. r"""
  4608. triu_(diagonal=0) -> Tensor
  4609. In-place version of :meth:`~Tensor.triu`
  4610. """,
  4611. )
  4612. add_docstr_all(
  4613. "true_divide",
  4614. r"""
  4615. true_divide(value) -> Tensor
  4616. See :func:`torch.true_divide`
  4617. """,
  4618. )
  4619. add_docstr_all(
  4620. "true_divide_",
  4621. r"""
  4622. true_divide_(value) -> Tensor
  4623. In-place version of :meth:`~Tensor.true_divide_`
  4624. """,
  4625. )
  4626. add_docstr_all(
  4627. "trunc",
  4628. r"""
  4629. trunc() -> Tensor
  4630. See :func:`torch.trunc`
  4631. """,
  4632. )
  4633. add_docstr_all(
  4634. "fix",
  4635. r"""
  4636. fix() -> Tensor
  4637. See :func:`torch.fix`.
  4638. """,
  4639. )
  4640. add_docstr_all(
  4641. "trunc_",
  4642. r"""
  4643. trunc_() -> Tensor
  4644. In-place version of :meth:`~Tensor.trunc`
  4645. """,
  4646. )
  4647. add_docstr_all(
  4648. "fix_",
  4649. r"""
  4650. fix_() -> Tensor
  4651. In-place version of :meth:`~Tensor.fix`
  4652. """,
  4653. )
  4654. add_docstr_all(
  4655. "type",
  4656. r"""
  4657. type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
  4658. Returns the type if `dtype` is not provided, else casts this object to
  4659. the specified type.
  4660. If this is already of the correct type, no copy is performed and the
  4661. original object is returned.
  4662. Args:
  4663. dtype (dtype or string): The desired type
  4664. non_blocking (bool): If ``True``, and the source is in pinned memory
  4665. and destination is on the GPU or vice versa, the copy is performed
  4666. asynchronously with respect to the host. Otherwise, the argument
  4667. has no effect.
  4668. **kwargs: For compatibility, may contain the key ``async`` in place of
  4669. the ``non_blocking`` argument. The ``async`` arg is deprecated.
  4670. """,
  4671. )
  4672. add_docstr_all(
  4673. "type_as",
  4674. r"""
  4675. type_as(tensor) -> Tensor
  4676. Returns this tensor cast to the type of the given tensor.
  4677. This is a no-op if the tensor is already of the correct type. This is
  4678. equivalent to ``self.type(tensor.type())``
  4679. Args:
  4680. tensor (Tensor): the tensor which has the desired type
  4681. """,
  4682. )
  4683. add_docstr_all(
  4684. "unfold",
  4685. r"""
  4686. unfold(dimension, size, step) -> Tensor
  4687. Returns a view of the original tensor which contains all slices of size :attr:`size` from
  4688. :attr:`self` tensor in the dimension :attr:`dimension`.
  4689. Step between two slices is given by :attr:`step`.
  4690. If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
  4691. dimension :attr:`dimension` in the returned tensor will be
  4692. `(sizedim - size) / step + 1`.
  4693. An additional dimension of size :attr:`size` is appended in the returned tensor.
  4694. Args:
  4695. dimension (int): dimension in which unfolding happens
  4696. size (int): the size of each slice that is unfolded
  4697. step (int): the step between each slice
  4698. Example::
  4699. >>> x = torch.arange(1., 8)
  4700. >>> x
  4701. tensor([ 1., 2., 3., 4., 5., 6., 7.])
  4702. >>> x.unfold(0, 2, 1)
  4703. tensor([[ 1., 2.],
  4704. [ 2., 3.],
  4705. [ 3., 4.],
  4706. [ 4., 5.],
  4707. [ 5., 6.],
  4708. [ 6., 7.]])
  4709. >>> x.unfold(0, 2, 2)
  4710. tensor([[ 1., 2.],
  4711. [ 3., 4.],
  4712. [ 5., 6.]])
  4713. """,
  4714. )
  4715. add_docstr_all(
  4716. "uniform_",
  4717. r"""
  4718. uniform_(from=0, to=1, *, generator=None) -> Tensor
  4719. Fills :attr:`self` tensor with numbers sampled from the continuous uniform
  4720. distribution:
  4721. .. math::
  4722. f(x) = \dfrac{1}{\text{to} - \text{from}}
  4723. """,
  4724. )
  4725. add_docstr_all(
  4726. "unsqueeze",
  4727. r"""
  4728. unsqueeze(dim) -> Tensor
  4729. See :func:`torch.unsqueeze`
  4730. """,
  4731. )
  4732. add_docstr_all(
  4733. "unsqueeze_",
  4734. r"""
  4735. unsqueeze_(dim) -> Tensor
  4736. In-place version of :meth:`~Tensor.unsqueeze`
  4737. """,
  4738. )
  4739. add_docstr_all(
  4740. "var",
  4741. r"""
  4742. var(dim=None, *, correction=1, keepdim=False) -> Tensor
  4743. See :func:`torch.var`
  4744. """,
  4745. )
  4746. add_docstr_all(
  4747. "vdot",
  4748. r"""
  4749. vdot(other) -> Tensor
  4750. See :func:`torch.vdot`
  4751. """,
  4752. )
  4753. add_docstr_all(
  4754. "view",
  4755. r"""
  4756. view(*shape) -> Tensor
  4757. Returns a new tensor with the same data as the :attr:`self` tensor but of a
  4758. different :attr:`shape`.
  4759. The returned tensor shares the same data and must have the same number
  4760. of elements, but may have a different size. For a tensor to be viewed, the new
  4761. view size must be compatible with its original size and stride, i.e., each new
  4762. view dimension must either be a subspace of an original dimension, or only span
  4763. across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
  4764. contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
  4765. .. math::
  4766. \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
  4767. Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
  4768. without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
  4769. :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
  4770. returns a view if the shapes are compatible, and copies (equivalent to calling
  4771. :meth:`contiguous`) otherwise.
  4772. Args:
  4773. shape (torch.Size or int...): the desired size
  4774. Example::
  4775. >>> x = torch.randn(4, 4)
  4776. >>> x.size()
  4777. torch.Size([4, 4])
  4778. >>> y = x.view(16)
  4779. >>> y.size()
  4780. torch.Size([16])
  4781. >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
  4782. >>> z.size()
  4783. torch.Size([2, 8])
  4784. >>> a = torch.randn(1, 2, 3, 4)
  4785. >>> a.size()
  4786. torch.Size([1, 2, 3, 4])
  4787. >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
  4788. >>> b.size()
  4789. torch.Size([1, 3, 2, 4])
  4790. >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
  4791. >>> c.size()
  4792. torch.Size([1, 3, 2, 4])
  4793. >>> torch.equal(b, c)
  4794. False
  4795. .. method:: view(dtype) -> Tensor
  4796. :noindex:
  4797. Returns a new tensor with the same data as the :attr:`self` tensor but of a
  4798. different :attr:`dtype`.
  4799. If the element size of :attr:`dtype` is different than that of ``self.dtype``,
  4800. then the size of the last dimension of the output will be scaled
  4801. proportionally. For instance, if :attr:`dtype` element size is twice that of
  4802. ``self.dtype``, then each pair of elements in the last dimension of
  4803. :attr:`self` will be combined, and the size of the last dimension of the output
  4804. will be half that of :attr:`self`. If :attr:`dtype` element size is half that
  4805. of ``self.dtype``, then each element in the last dimension of :attr:`self` will
  4806. be split in two, and the size of the last dimension of the output will be
  4807. double that of :attr:`self`. For this to be possible, the following conditions
  4808. must be true:
  4809. * ``self.dim()`` must be greater than 0.
  4810. * ``self.stride(-1)`` must be 1.
  4811. Additionally, if the element size of :attr:`dtype` is greater than that of
  4812. ``self.dtype``, the following conditions must be true as well:
  4813. * ``self.size(-1)`` must be divisible by the ratio between the element
  4814. sizes of the dtypes.
  4815. * ``self.storage_offset()`` must be divisible by the ratio between the
  4816. element sizes of the dtypes.
  4817. * The strides of all dimensions, except the last dimension, must be
  4818. divisible by the ratio between the element sizes of the dtypes.
  4819. If any of the above conditions are not met, an error is thrown.
  4820. .. warning::
  4821. This overload is not supported by TorchScript, and using it in a Torchscript
  4822. program will cause undefined behavior.
  4823. Args:
  4824. dtype (:class:`torch.dtype`): the desired dtype
  4825. Example::
  4826. >>> x = torch.randn(4, 4)
  4827. >>> x
  4828. tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
  4829. [-0.1520, 0.7472, 0.5617, -0.8649],
  4830. [-2.4724, -0.0334, -0.2976, -0.8499],
  4831. [-0.2109, 1.9913, -0.9607, -0.6123]])
  4832. >>> x.dtype
  4833. torch.float32
  4834. >>> y = x.view(torch.int32)
  4835. >>> y
  4836. tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
  4837. [-1105482831, 1061112040, 1057999968, -1084397505],
  4838. [-1071760287, -1123489973, -1097310419, -1084649136],
  4839. [-1101533110, 1073668768, -1082790149, -1088634448]],
  4840. dtype=torch.int32)
  4841. >>> y[0, 0] = 1000000000
  4842. >>> x
  4843. tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
  4844. [-0.1520, 0.7472, 0.5617, -0.8649],
  4845. [-2.4724, -0.0334, -0.2976, -0.8499],
  4846. [-0.2109, 1.9913, -0.9607, -0.6123]])
  4847. >>> x.view(torch.cfloat)
  4848. tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
  4849. [-0.1520+0.7472j, 0.5617-0.8649j],
  4850. [-2.4724-0.0334j, -0.2976-0.8499j],
  4851. [-0.2109+1.9913j, -0.9607-0.6123j]])
  4852. >>> x.view(torch.cfloat).size()
  4853. torch.Size([4, 2])
  4854. >>> x.view(torch.uint8)
  4855. tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
  4856. 8, 191],
  4857. [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
  4858. 93, 191],
  4859. [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
  4860. 89, 191],
  4861. [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
  4862. 28, 191]], dtype=torch.uint8)
  4863. >>> x.view(torch.uint8).size()
  4864. torch.Size([4, 16])
  4865. """,
  4866. )
  4867. add_docstr_all(
  4868. "view_as",
  4869. r"""
  4870. view_as(other) -> Tensor
  4871. View this tensor as the same size as :attr:`other`.
  4872. ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
  4873. Please see :meth:`~Tensor.view` for more information about ``view``.
  4874. Args:
  4875. other (:class:`torch.Tensor`): The result tensor has the same size
  4876. as :attr:`other`.
  4877. """,
  4878. )
  4879. add_docstr_all(
  4880. "expand",
  4881. r"""
  4882. expand(*sizes) -> Tensor
  4883. Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
  4884. to a larger size.
  4885. Passing -1 as the size for a dimension means not changing the size of
  4886. that dimension.
  4887. Tensor can be also expanded to a larger number of dimensions, and the
  4888. new ones will be appended at the front. For the new dimensions, the
  4889. size cannot be set to -1.
  4890. Expanding a tensor does not allocate new memory, but only creates a
  4891. new view on the existing tensor where a dimension of size one is
  4892. expanded to a larger size by setting the ``stride`` to 0. Any dimension
  4893. of size 1 can be expanded to an arbitrary value without allocating new
  4894. memory.
  4895. Args:
  4896. *sizes (torch.Size or int...): the desired expanded size
  4897. .. warning::
  4898. More than one element of an expanded tensor may refer to a single
  4899. memory location. As a result, in-place operations (especially ones that
  4900. are vectorized) may result in incorrect behavior. If you need to write
  4901. to the tensors, please clone them first.
  4902. Example::
  4903. >>> x = torch.tensor([[1], [2], [3]])
  4904. >>> x.size()
  4905. torch.Size([3, 1])
  4906. >>> x.expand(3, 4)
  4907. tensor([[ 1, 1, 1, 1],
  4908. [ 2, 2, 2, 2],
  4909. [ 3, 3, 3, 3]])
  4910. >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
  4911. tensor([[ 1, 1, 1, 1],
  4912. [ 2, 2, 2, 2],
  4913. [ 3, 3, 3, 3]])
  4914. """,
  4915. )
  4916. add_docstr_all(
  4917. "expand_as",
  4918. r"""
  4919. expand_as(other) -> Tensor
  4920. Expand this tensor to the same size as :attr:`other`.
  4921. ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
  4922. Please see :meth:`~Tensor.expand` for more information about ``expand``.
  4923. Args:
  4924. other (:class:`torch.Tensor`): The result tensor has the same size
  4925. as :attr:`other`.
  4926. """,
  4927. )
  4928. add_docstr_all(
  4929. "sum_to_size",
  4930. r"""
  4931. sum_to_size(*size) -> Tensor
  4932. Sum ``this`` tensor to :attr:`size`.
  4933. :attr:`size` must be broadcastable to ``this`` tensor size.
  4934. Args:
  4935. size (int...): a sequence of integers defining the shape of the output tensor.
  4936. """,
  4937. )
  4938. add_docstr_all(
  4939. "zero_",
  4940. r"""
  4941. zero_() -> Tensor
  4942. Fills :attr:`self` tensor with zeros.
  4943. """,
  4944. )
  4945. add_docstr_all(
  4946. "matmul",
  4947. r"""
  4948. matmul(tensor2) -> Tensor
  4949. See :func:`torch.matmul`
  4950. """,
  4951. )
  4952. add_docstr_all(
  4953. "chunk",
  4954. r"""
  4955. chunk(chunks, dim=0) -> List of Tensors
  4956. See :func:`torch.chunk`
  4957. """,
  4958. )
  4959. add_docstr_all(
  4960. "unsafe_chunk",
  4961. r"""
  4962. unsafe_chunk(chunks, dim=0) -> List of Tensors
  4963. See :func:`torch.unsafe_chunk`
  4964. """,
  4965. )
  4966. add_docstr_all(
  4967. "unsafe_split",
  4968. r"""
  4969. unsafe_split(split_size, dim=0) -> List of Tensors
  4970. See :func:`torch.unsafe_split`
  4971. """,
  4972. )
  4973. add_docstr_all(
  4974. "tensor_split",
  4975. r"""
  4976. tensor_split(indices_or_sections, dim=0) -> List of Tensors
  4977. See :func:`torch.tensor_split`
  4978. """,
  4979. )
  4980. add_docstr_all(
  4981. "hsplit",
  4982. r"""
  4983. hsplit(split_size_or_sections) -> List of Tensors
  4984. See :func:`torch.hsplit`
  4985. """,
  4986. )
  4987. add_docstr_all(
  4988. "vsplit",
  4989. r"""
  4990. vsplit(split_size_or_sections) -> List of Tensors
  4991. See :func:`torch.vsplit`
  4992. """,
  4993. )
  4994. add_docstr_all(
  4995. "dsplit",
  4996. r"""
  4997. dsplit(split_size_or_sections) -> List of Tensors
  4998. See :func:`torch.dsplit`
  4999. """,
  5000. )
  5001. add_docstr_all(
  5002. "stft",
  5003. r"""
  5004. stft(frame_length, hop, fft_size=None, return_onesided=True, window=None,
  5005. pad_end=0, align_to_window=None) -> Tensor
  5006. See :func:`torch.stft`
  5007. """,
  5008. )
  5009. add_docstr_all(
  5010. "istft",
  5011. r"""
  5012. istft(n_fft, hop_length=None, win_length=None, window=None,
  5013. center=True, normalized=False, onesided=True, length=None) -> Tensor
  5014. See :func:`torch.istft`
  5015. """,
  5016. )
  5017. add_docstr_all(
  5018. "det",
  5019. r"""
  5020. det() -> Tensor
  5021. See :func:`torch.det`
  5022. """,
  5023. )
  5024. add_docstr_all(
  5025. "where",
  5026. r"""
  5027. where(condition, y) -> Tensor
  5028. ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
  5029. See :func:`torch.where`
  5030. """,
  5031. )
  5032. add_docstr_all(
  5033. "logdet",
  5034. r"""
  5035. logdet() -> Tensor
  5036. See :func:`torch.logdet`
  5037. """,
  5038. )
  5039. add_docstr_all(
  5040. "slogdet",
  5041. r"""
  5042. slogdet() -> (Tensor, Tensor)
  5043. See :func:`torch.slogdet`
  5044. """,
  5045. )
  5046. add_docstr_all(
  5047. "unbind",
  5048. r"""
  5049. unbind(dim=0) -> seq
  5050. See :func:`torch.unbind`
  5051. """,
  5052. )
  5053. add_docstr_all(
  5054. "pin_memory",
  5055. r"""
  5056. pin_memory() -> Tensor
  5057. Copies the tensor to pinned memory, if it's not already pinned.
  5058. By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
  5059. """,
  5060. )
  5061. add_docstr_all(
  5062. "pinverse",
  5063. r"""
  5064. pinverse() -> Tensor
  5065. See :func:`torch.pinverse`
  5066. """,
  5067. )
  5068. add_docstr_all(
  5069. "index_add",
  5070. r"""
  5071. index_add(dim, index, source, *, alpha=1) -> Tensor
  5072. Out-of-place version of :meth:`torch.Tensor.index_add_`.
  5073. """,
  5074. )
  5075. add_docstr_all(
  5076. "index_copy",
  5077. r"""
  5078. index_copy(dim, index, tensor2) -> Tensor
  5079. Out-of-place version of :meth:`torch.Tensor.index_copy_`.
  5080. """,
  5081. )
  5082. add_docstr_all(
  5083. "index_fill",
  5084. r"""
  5085. index_fill(dim, index, value) -> Tensor
  5086. Out-of-place version of :meth:`torch.Tensor.index_fill_`.
  5087. """,
  5088. )
  5089. add_docstr_all(
  5090. "scatter",
  5091. r"""
  5092. scatter(dim, index, src) -> Tensor
  5093. Out-of-place version of :meth:`torch.Tensor.scatter_`
  5094. """,
  5095. )
  5096. add_docstr_all(
  5097. "scatter_add",
  5098. r"""
  5099. scatter_add(dim, index, src) -> Tensor
  5100. Out-of-place version of :meth:`torch.Tensor.scatter_add_`
  5101. """,
  5102. )
  5103. add_docstr_all(
  5104. "scatter_reduce",
  5105. r"""
  5106. scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
  5107. Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
  5108. """,
  5109. )
  5110. add_docstr_all(
  5111. "masked_scatter",
  5112. r"""
  5113. masked_scatter(mask, tensor) -> Tensor
  5114. Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
  5115. .. note::
  5116. The inputs :attr:`self` and :attr:`mask`
  5117. :ref:`broadcast <broadcasting-semantics>`.
  5118. Example:
  5119. >>> self = torch.tensor([0, 0, 0, 0, 0])
  5120. >>> mask = torch.tensor(
  5121. ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
  5122. ... dtype=torch.bool,
  5123. ... )
  5124. >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
  5125. >>> self.masked_scatter(mask, source)
  5126. tensor([[0, 0, 0, 0, 1],
  5127. [2, 3, 0, 4, 5]])
  5128. """,
  5129. )
  5130. add_docstr_all(
  5131. "xlogy",
  5132. r"""
  5133. xlogy(other) -> Tensor
  5134. See :func:`torch.xlogy`
  5135. """,
  5136. )
  5137. add_docstr_all(
  5138. "xlogy_",
  5139. r"""
  5140. xlogy_(other) -> Tensor
  5141. In-place version of :meth:`~Tensor.xlogy`
  5142. """,
  5143. )
  5144. add_docstr_all(
  5145. "masked_fill",
  5146. r"""
  5147. masked_fill(mask, value) -> Tensor
  5148. Out-of-place version of :meth:`torch.Tensor.masked_fill_`
  5149. """,
  5150. )
  5151. add_docstr_all(
  5152. "grad",
  5153. r"""
  5154. This attribute is ``None`` by default and becomes a Tensor the first time a call to
  5155. :func:`backward` computes gradients for ``self``.
  5156. The attribute will then contain the gradients computed and future calls to
  5157. :func:`backward` will accumulate (add) gradients into it.
  5158. """,
  5159. )
  5160. add_docstr_all(
  5161. "retain_grad",
  5162. r"""
  5163. retain_grad() -> None
  5164. Enables this Tensor to have their :attr:`grad` populated during
  5165. :func:`backward`. This is a no-op for leaf tensors.
  5166. """,
  5167. )
  5168. add_docstr_all(
  5169. "retains_grad",
  5170. r"""
  5171. Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
  5172. populated during :func:`backward`, ``False`` otherwise.
  5173. """,
  5174. )
  5175. add_docstr_all(
  5176. "requires_grad",
  5177. r"""
  5178. Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
  5179. .. note::
  5180. The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
  5181. attribute will be populated, see :attr:`is_leaf` for more details.
  5182. """,
  5183. )
  5184. add_docstr_all(
  5185. "is_leaf",
  5186. r"""
  5187. All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
  5188. For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
  5189. created by the user. This means that they are not the result of an operation and so
  5190. :attr:`grad_fn` is None.
  5191. Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
  5192. To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
  5193. Example::
  5194. >>> a = torch.rand(10, requires_grad=True)
  5195. >>> a.is_leaf
  5196. True
  5197. >>> b = torch.rand(10, requires_grad=True).cuda()
  5198. >>> b.is_leaf
  5199. False
  5200. # b was created by the operation that cast a cpu Tensor into a cuda Tensor
  5201. >>> c = torch.rand(10, requires_grad=True) + 2
  5202. >>> c.is_leaf
  5203. False
  5204. # c was created by the addition operation
  5205. >>> d = torch.rand(10).cuda()
  5206. >>> d.is_leaf
  5207. True
  5208. # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
  5209. >>> e = torch.rand(10).cuda().requires_grad_()
  5210. >>> e.is_leaf
  5211. True
  5212. # e requires gradients and has no operations creating it
  5213. >>> f = torch.rand(10, requires_grad=True, device="cuda")
  5214. >>> f.is_leaf
  5215. True
  5216. # f requires grad, has no operation creating it
  5217. """,
  5218. )
  5219. add_docstr_all(
  5220. "names",
  5221. r"""
  5222. Stores names for each of this tensor's dimensions.
  5223. ``names[idx]`` corresponds to the name of tensor dimension ``idx``.
  5224. Names are either a string if the dimension is named or ``None`` if the
  5225. dimension is unnamed.
  5226. Dimension names may contain characters or underscore. Furthermore, a dimension
  5227. name must be a valid Python variable name (i.e., does not start with underscore).
  5228. Tensors may not have two named dimensions with the same name.
  5229. .. warning::
  5230. The named tensor API is experimental and subject to change.
  5231. """,
  5232. )
  5233. add_docstr_all(
  5234. "is_cuda",
  5235. r"""
  5236. Is ``True`` if the Tensor is stored on the GPU, ``False`` otherwise.
  5237. """,
  5238. )
  5239. add_docstr_all(
  5240. "is_cpu",
  5241. r"""
  5242. Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
  5243. """,
  5244. )
  5245. add_docstr_all(
  5246. "is_xla",
  5247. r"""
  5248. Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
  5249. """,
  5250. )
  5251. add_docstr_all(
  5252. "is_ipu",
  5253. r"""
  5254. Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
  5255. """,
  5256. )
  5257. add_docstr_all(
  5258. "is_xpu",
  5259. r"""
  5260. Is ``True`` if the Tensor is stored on the XPU, ``False`` otherwise.
  5261. """,
  5262. )
  5263. add_docstr_all(
  5264. "is_quantized",
  5265. r"""
  5266. Is ``True`` if the Tensor is quantized, ``False`` otherwise.
  5267. """,
  5268. )
  5269. add_docstr_all(
  5270. "is_meta",
  5271. r"""
  5272. Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
  5273. are like normal tensors, but they carry no data.
  5274. """,
  5275. )
  5276. add_docstr_all(
  5277. "is_mps",
  5278. r"""
  5279. Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
  5280. """,
  5281. )
  5282. add_docstr_all(
  5283. "is_sparse",
  5284. r"""
  5285. Is ``True`` if the Tensor uses sparse COO storage layout, ``False`` otherwise.
  5286. """,
  5287. )
  5288. add_docstr_all(
  5289. "is_sparse_csr",
  5290. r"""
  5291. Is ``True`` if the Tensor uses sparse CSR storage layout, ``False`` otherwise.
  5292. """,
  5293. )
  5294. add_docstr_all(
  5295. "device",
  5296. r"""
  5297. Is the :class:`torch.device` where this Tensor is.
  5298. """,
  5299. )
  5300. add_docstr_all(
  5301. "ndim",
  5302. r"""
  5303. Alias for :meth:`~Tensor.dim()`
  5304. """,
  5305. )
  5306. add_docstr_all(
  5307. "itemsize",
  5308. r"""
  5309. Alias for :meth:`~Tensor.element_size()`
  5310. """,
  5311. )
  5312. add_docstr_all(
  5313. "nbytes",
  5314. r"""
  5315. Returns the number of bytes consumed by the "view" of elements of the Tensor
  5316. if the Tensor does not use sparse storage layout.
  5317. Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
  5318. """,
  5319. )
  5320. add_docstr_all(
  5321. "T",
  5322. r"""
  5323. Returns a view of this tensor with its dimensions reversed.
  5324. If ``n`` is the number of dimensions in ``x``,
  5325. ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
  5326. .. warning::
  5327. The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
  5328. is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
  5329. to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
  5330. the dimensions of a tensor.
  5331. """,
  5332. )
  5333. add_docstr_all(
  5334. "H",
  5335. r"""
  5336. Returns a view of a matrix (2-D tensor) conjugated and transposed.
  5337. ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
  5338. ``x.transpose(0, 1)`` for real matrices.
  5339. .. seealso::
  5340. :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
  5341. """,
  5342. )
  5343. add_docstr_all(
  5344. "mT",
  5345. r"""
  5346. Returns a view of this tensor with the last two dimensions transposed.
  5347. ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
  5348. """,
  5349. )
  5350. add_docstr_all(
  5351. "mH",
  5352. r"""
  5353. Accessing this property is equivalent to calling :func:`adjoint`.
  5354. """,
  5355. )
  5356. add_docstr_all(
  5357. "adjoint",
  5358. r"""
  5359. adjoint() -> Tensor
  5360. Alias for :func:`adjoint`
  5361. """,
  5362. )
  5363. add_docstr_all(
  5364. "real",
  5365. r"""
  5366. Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
  5367. The returned tensor and :attr:`self` share the same underlying storage.
  5368. Returns :attr:`self` if :attr:`self` is a real-valued tensor tensor.
  5369. Example::
  5370. >>> x=torch.randn(4, dtype=torch.cfloat)
  5371. >>> x
  5372. tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
  5373. >>> x.real
  5374. tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
  5375. """,
  5376. )
  5377. add_docstr_all(
  5378. "imag",
  5379. r"""
  5380. Returns a new tensor containing imaginary values of the :attr:`self` tensor.
  5381. The returned tensor and :attr:`self` share the same underlying storage.
  5382. .. warning::
  5383. :func:`imag` is only supported for tensors with complex dtypes.
  5384. Example::
  5385. >>> x=torch.randn(4, dtype=torch.cfloat)
  5386. >>> x
  5387. tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
  5388. >>> x.imag
  5389. tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
  5390. """,
  5391. )
  5392. add_docstr_all(
  5393. "as_subclass",
  5394. r"""
  5395. as_subclass(cls) -> Tensor
  5396. Makes a ``cls`` instance with the same data pointer as ``self``. Changes
  5397. in the output mirror changes in ``self``, and the output stays attached
  5398. to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
  5399. """,
  5400. )
  5401. add_docstr_all(
  5402. "crow_indices",
  5403. r"""
  5404. crow_indices() -> IntTensor
  5405. Returns the tensor containing the compressed row indices of the :attr:`self`
  5406. tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
  5407. The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
  5408. and of type ``int32`` or ``int64``. When using MKL routines such as sparse
  5409. matrix multiplication, it is necessary to use ``int32`` indexing in order
  5410. to avoid downcasting and potentially losing information.
  5411. Example::
  5412. >>> csr = torch.eye(5,5).to_sparse_csr()
  5413. >>> csr.crow_indices()
  5414. tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
  5415. """,
  5416. )
  5417. add_docstr_all(
  5418. "col_indices",
  5419. r"""
  5420. col_indices() -> IntTensor
  5421. Returns the tensor containing the column indices of the :attr:`self`
  5422. tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
  5423. The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
  5424. and of type ``int32`` or ``int64``. When using MKL routines such as sparse
  5425. matrix multiplication, it is necessary to use ``int32`` indexing in order
  5426. to avoid downcasting and potentially losing information.
  5427. Example::
  5428. >>> csr = torch.eye(5,5).to_sparse_csr()
  5429. >>> csr.col_indices()
  5430. tensor([0, 1, 2, 3, 4], dtype=torch.int32)
  5431. """,
  5432. )
  5433. add_docstr_all(
  5434. "to_padded_tensor",
  5435. r"""
  5436. to_padded_tensor(padding, output_size=None) -> Tensor
  5437. See :func:`to_padded_tensor`
  5438. """,
  5439. )