_casting_dicts.py 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367
  1. # mypy: ignore-errors
  2. import torch
  3. # These two dicts are autogenerated with autogen/gen_dtypes.py,
  4. # using numpy version 1.24.3.
  5. _can_cast_dict = {
  6. "no": {
  7. torch.float16: {
  8. torch.float16: True,
  9. torch.float32: False,
  10. torch.float64: False,
  11. torch.complex64: False,
  12. torch.complex128: False,
  13. torch.uint8: False,
  14. torch.uint16: False,
  15. torch.uint32: False,
  16. torch.uint64: False,
  17. torch.int8: False,
  18. torch.int16: False,
  19. torch.int32: False,
  20. torch.int64: False,
  21. torch.bool: False,
  22. },
  23. torch.float32: {
  24. torch.float16: False,
  25. torch.float32: True,
  26. torch.float64: False,
  27. torch.complex64: False,
  28. torch.complex128: False,
  29. torch.uint8: False,
  30. torch.uint16: False,
  31. torch.uint32: False,
  32. torch.uint64: False,
  33. torch.int8: False,
  34. torch.int16: False,
  35. torch.int32: False,
  36. torch.int64: False,
  37. torch.bool: False,
  38. },
  39. torch.float64: {
  40. torch.float16: False,
  41. torch.float32: False,
  42. torch.float64: True,
  43. torch.complex64: False,
  44. torch.complex128: False,
  45. torch.uint8: False,
  46. torch.uint16: False,
  47. torch.uint32: False,
  48. torch.uint64: False,
  49. torch.int8: False,
  50. torch.int16: False,
  51. torch.int32: False,
  52. torch.int64: False,
  53. torch.bool: False,
  54. },
  55. torch.complex64: {
  56. torch.float16: False,
  57. torch.float32: False,
  58. torch.float64: False,
  59. torch.complex64: True,
  60. torch.complex128: False,
  61. torch.uint8: False,
  62. torch.uint16: False,
  63. torch.uint32: False,
  64. torch.uint64: False,
  65. torch.int8: False,
  66. torch.int16: False,
  67. torch.int32: False,
  68. torch.int64: False,
  69. torch.bool: False,
  70. },
  71. torch.complex128: {
  72. torch.float16: False,
  73. torch.float32: False,
  74. torch.float64: False,
  75. torch.complex64: False,
  76. torch.complex128: True,
  77. torch.uint8: False,
  78. torch.uint16: False,
  79. torch.uint32: False,
  80. torch.uint64: False,
  81. torch.int8: False,
  82. torch.int16: False,
  83. torch.int32: False,
  84. torch.int64: False,
  85. torch.bool: False,
  86. },
  87. torch.uint8: {
  88. torch.float16: False,
  89. torch.float32: False,
  90. torch.float64: False,
  91. torch.complex64: False,
  92. torch.complex128: False,
  93. torch.uint8: True,
  94. torch.uint16: False,
  95. torch.uint32: False,
  96. torch.uint64: False,
  97. torch.int8: False,
  98. torch.int16: False,
  99. torch.int32: False,
  100. torch.int64: False,
  101. torch.bool: False,
  102. },
  103. torch.uint16: {
  104. torch.float16: False,
  105. torch.float32: False,
  106. torch.float64: False,
  107. torch.complex64: False,
  108. torch.complex128: False,
  109. torch.uint8: False,
  110. torch.uint16: True,
  111. torch.uint32: False,
  112. torch.uint64: False,
  113. torch.int8: False,
  114. torch.int16: False,
  115. torch.int32: False,
  116. torch.int64: False,
  117. torch.bool: False,
  118. },
  119. torch.uint32: {
  120. torch.float16: False,
  121. torch.float32: False,
  122. torch.float64: False,
  123. torch.complex64: False,
  124. torch.complex128: False,
  125. torch.uint8: False,
  126. torch.uint16: False,
  127. torch.uint32: True,
  128. torch.uint64: False,
  129. torch.int8: False,
  130. torch.int16: False,
  131. torch.int32: False,
  132. torch.int64: False,
  133. torch.bool: False,
  134. },
  135. torch.uint64: {
  136. torch.float16: False,
  137. torch.float32: False,
  138. torch.float64: False,
  139. torch.complex64: False,
  140. torch.complex128: False,
  141. torch.uint8: False,
  142. torch.uint16: False,
  143. torch.uint32: False,
  144. torch.uint64: True,
  145. torch.int8: False,
  146. torch.int16: False,
  147. torch.int32: False,
  148. torch.int64: False,
  149. torch.bool: False,
  150. },
  151. torch.int8: {
  152. torch.float16: False,
  153. torch.float32: False,
  154. torch.float64: False,
  155. torch.complex64: False,
  156. torch.complex128: False,
  157. torch.uint8: False,
  158. torch.uint16: False,
  159. torch.uint32: False,
  160. torch.uint64: False,
  161. torch.int8: True,
  162. torch.int16: False,
  163. torch.int32: False,
  164. torch.int64: False,
  165. torch.bool: False,
  166. },
  167. torch.int16: {
  168. torch.float16: False,
  169. torch.float32: False,
  170. torch.float64: False,
  171. torch.complex64: False,
  172. torch.complex128: False,
  173. torch.uint8: False,
  174. torch.uint16: False,
  175. torch.uint32: False,
  176. torch.uint64: False,
  177. torch.int8: False,
  178. torch.int16: True,
  179. torch.int32: False,
  180. torch.int64: False,
  181. torch.bool: False,
  182. },
  183. torch.int32: {
  184. torch.float16: False,
  185. torch.float32: False,
  186. torch.float64: False,
  187. torch.complex64: False,
  188. torch.complex128: False,
  189. torch.uint8: False,
  190. torch.uint16: False,
  191. torch.uint32: False,
  192. torch.uint64: False,
  193. torch.int8: False,
  194. torch.int16: False,
  195. torch.int32: True,
  196. torch.int64: False,
  197. torch.bool: False,
  198. },
  199. torch.int64: {
  200. torch.float16: False,
  201. torch.float32: False,
  202. torch.float64: False,
  203. torch.complex64: False,
  204. torch.complex128: False,
  205. torch.uint8: False,
  206. torch.uint16: False,
  207. torch.uint32: False,
  208. torch.uint64: False,
  209. torch.int8: False,
  210. torch.int16: False,
  211. torch.int32: False,
  212. torch.int64: True,
  213. torch.bool: False,
  214. },
  215. torch.bool: {
  216. torch.float16: False,
  217. torch.float32: False,
  218. torch.float64: False,
  219. torch.complex64: False,
  220. torch.complex128: False,
  221. torch.uint8: False,
  222. torch.uint16: False,
  223. torch.uint32: False,
  224. torch.uint64: False,
  225. torch.int8: False,
  226. torch.int16: False,
  227. torch.int32: False,
  228. torch.int64: False,
  229. torch.bool: True,
  230. },
  231. },
  232. "equiv": {
  233. torch.float16: {
  234. torch.float16: True,
  235. torch.float32: False,
  236. torch.float64: False,
  237. torch.complex64: False,
  238. torch.complex128: False,
  239. torch.uint8: False,
  240. torch.uint16: False,
  241. torch.uint32: False,
  242. torch.uint64: False,
  243. torch.int8: False,
  244. torch.int16: False,
  245. torch.int32: False,
  246. torch.int64: False,
  247. torch.bool: False,
  248. },
  249. torch.float32: {
  250. torch.float16: False,
  251. torch.float32: True,
  252. torch.float64: False,
  253. torch.complex64: False,
  254. torch.complex128: False,
  255. torch.uint8: False,
  256. torch.uint16: False,
  257. torch.uint32: False,
  258. torch.uint64: False,
  259. torch.int8: False,
  260. torch.int16: False,
  261. torch.int32: False,
  262. torch.int64: False,
  263. torch.bool: False,
  264. },
  265. torch.float64: {
  266. torch.float16: False,
  267. torch.float32: False,
  268. torch.float64: True,
  269. torch.complex64: False,
  270. torch.complex128: False,
  271. torch.uint8: False,
  272. torch.uint16: False,
  273. torch.uint32: False,
  274. torch.uint64: False,
  275. torch.int8: False,
  276. torch.int16: False,
  277. torch.int32: False,
  278. torch.int64: False,
  279. torch.bool: False,
  280. },
  281. torch.complex64: {
  282. torch.float16: False,
  283. torch.float32: False,
  284. torch.float64: False,
  285. torch.complex64: True,
  286. torch.complex128: False,
  287. torch.uint8: False,
  288. torch.uint16: False,
  289. torch.uint32: False,
  290. torch.uint64: False,
  291. torch.int8: False,
  292. torch.int16: False,
  293. torch.int32: False,
  294. torch.int64: False,
  295. torch.bool: False,
  296. },
  297. torch.complex128: {
  298. torch.float16: False,
  299. torch.float32: False,
  300. torch.float64: False,
  301. torch.complex64: False,
  302. torch.complex128: True,
  303. torch.uint8: False,
  304. torch.uint16: False,
  305. torch.uint32: False,
  306. torch.uint64: False,
  307. torch.int8: False,
  308. torch.int16: False,
  309. torch.int32: False,
  310. torch.int64: False,
  311. torch.bool: False,
  312. },
  313. torch.uint8: {
  314. torch.float16: False,
  315. torch.float32: False,
  316. torch.float64: False,
  317. torch.complex64: False,
  318. torch.complex128: False,
  319. torch.uint8: True,
  320. torch.uint16: False,
  321. torch.uint32: False,
  322. torch.uint64: False,
  323. torch.int8: False,
  324. torch.int16: False,
  325. torch.int32: False,
  326. torch.int64: False,
  327. torch.bool: False,
  328. },
  329. torch.uint16: {
  330. torch.float16: False,
  331. torch.float32: False,
  332. torch.float64: False,
  333. torch.complex64: False,
  334. torch.complex128: False,
  335. torch.uint8: False,
  336. torch.uint16: True,
  337. torch.uint32: False,
  338. torch.uint64: False,
  339. torch.int8: False,
  340. torch.int16: False,
  341. torch.int32: False,
  342. torch.int64: False,
  343. torch.bool: False,
  344. },
  345. torch.uint32: {
  346. torch.float16: False,
  347. torch.float32: False,
  348. torch.float64: False,
  349. torch.complex64: False,
  350. torch.complex128: False,
  351. torch.uint8: False,
  352. torch.uint16: False,
  353. torch.uint32: True,
  354. torch.uint64: False,
  355. torch.int8: False,
  356. torch.int16: False,
  357. torch.int32: False,
  358. torch.int64: False,
  359. torch.bool: False,
  360. },
  361. torch.uint64: {
  362. torch.float16: False,
  363. torch.float32: False,
  364. torch.float64: False,
  365. torch.complex64: False,
  366. torch.complex128: False,
  367. torch.uint8: False,
  368. torch.uint16: False,
  369. torch.uint32: False,
  370. torch.uint64: True,
  371. torch.int8: False,
  372. torch.int16: False,
  373. torch.int32: False,
  374. torch.int64: False,
  375. torch.bool: False,
  376. },
  377. torch.int8: {
  378. torch.float16: False,
  379. torch.float32: False,
  380. torch.float64: False,
  381. torch.complex64: False,
  382. torch.complex128: False,
  383. torch.uint8: False,
  384. torch.uint16: False,
  385. torch.uint32: False,
  386. torch.uint64: False,
  387. torch.int8: True,
  388. torch.int16: False,
  389. torch.int32: False,
  390. torch.int64: False,
  391. torch.bool: False,
  392. },
  393. torch.int16: {
  394. torch.float16: False,
  395. torch.float32: False,
  396. torch.float64: False,
  397. torch.complex64: False,
  398. torch.complex128: False,
  399. torch.uint8: False,
  400. torch.uint16: False,
  401. torch.uint32: False,
  402. torch.uint64: False,
  403. torch.int8: False,
  404. torch.int16: True,
  405. torch.int32: False,
  406. torch.int64: False,
  407. torch.bool: False,
  408. },
  409. torch.int32: {
  410. torch.float16: False,
  411. torch.float32: False,
  412. torch.float64: False,
  413. torch.complex64: False,
  414. torch.complex128: False,
  415. torch.uint8: False,
  416. torch.uint16: False,
  417. torch.uint32: False,
  418. torch.uint64: False,
  419. torch.int8: False,
  420. torch.int16: False,
  421. torch.int32: True,
  422. torch.int64: False,
  423. torch.bool: False,
  424. },
  425. torch.int64: {
  426. torch.float16: False,
  427. torch.float32: False,
  428. torch.float64: False,
  429. torch.complex64: False,
  430. torch.complex128: False,
  431. torch.uint8: False,
  432. torch.uint16: False,
  433. torch.uint32: False,
  434. torch.uint64: False,
  435. torch.int8: False,
  436. torch.int16: False,
  437. torch.int32: False,
  438. torch.int64: True,
  439. torch.bool: False,
  440. },
  441. torch.bool: {
  442. torch.float16: False,
  443. torch.float32: False,
  444. torch.float64: False,
  445. torch.complex64: False,
  446. torch.complex128: False,
  447. torch.uint8: False,
  448. torch.uint16: False,
  449. torch.uint32: False,
  450. torch.uint64: False,
  451. torch.int8: False,
  452. torch.int16: False,
  453. torch.int32: False,
  454. torch.int64: False,
  455. torch.bool: True,
  456. },
  457. },
  458. "safe": {
  459. torch.float16: {
  460. torch.float16: True,
  461. torch.float32: True,
  462. torch.float64: True,
  463. torch.complex64: True,
  464. torch.complex128: True,
  465. torch.uint8: False,
  466. torch.uint16: False,
  467. torch.uint32: False,
  468. torch.uint64: False,
  469. torch.int8: False,
  470. torch.int16: False,
  471. torch.int32: False,
  472. torch.int64: False,
  473. torch.bool: False,
  474. },
  475. torch.float32: {
  476. torch.float16: False,
  477. torch.float32: True,
  478. torch.float64: True,
  479. torch.complex64: True,
  480. torch.complex128: True,
  481. torch.uint8: False,
  482. torch.uint16: False,
  483. torch.uint32: False,
  484. torch.uint64: False,
  485. torch.int8: False,
  486. torch.int16: False,
  487. torch.int32: False,
  488. torch.int64: False,
  489. torch.bool: False,
  490. },
  491. torch.float64: {
  492. torch.float16: False,
  493. torch.float32: False,
  494. torch.float64: True,
  495. torch.complex64: False,
  496. torch.complex128: True,
  497. torch.uint8: False,
  498. torch.uint16: False,
  499. torch.uint32: False,
  500. torch.uint64: False,
  501. torch.int8: False,
  502. torch.int16: False,
  503. torch.int32: False,
  504. torch.int64: False,
  505. torch.bool: False,
  506. },
  507. torch.complex64: {
  508. torch.float16: False,
  509. torch.float32: False,
  510. torch.float64: False,
  511. torch.complex64: True,
  512. torch.complex128: True,
  513. torch.uint8: False,
  514. torch.uint16: False,
  515. torch.uint32: False,
  516. torch.uint64: False,
  517. torch.int8: False,
  518. torch.int16: False,
  519. torch.int32: False,
  520. torch.int64: False,
  521. torch.bool: False,
  522. },
  523. torch.complex128: {
  524. torch.float16: False,
  525. torch.float32: False,
  526. torch.float64: False,
  527. torch.complex64: False,
  528. torch.complex128: True,
  529. torch.uint8: False,
  530. torch.uint16: False,
  531. torch.uint32: False,
  532. torch.uint64: False,
  533. torch.int8: False,
  534. torch.int16: False,
  535. torch.int32: False,
  536. torch.int64: False,
  537. torch.bool: False,
  538. },
  539. torch.uint8: {
  540. torch.float16: True,
  541. torch.float32: True,
  542. torch.float64: True,
  543. torch.complex64: True,
  544. torch.complex128: True,
  545. torch.uint8: True,
  546. torch.uint16: True,
  547. torch.uint32: True,
  548. torch.uint64: True,
  549. torch.int8: False,
  550. torch.int16: True,
  551. torch.int32: True,
  552. torch.int64: True,
  553. torch.bool: False,
  554. },
  555. torch.uint16: {
  556. torch.float16: False,
  557. torch.float32: True,
  558. torch.float64: True,
  559. torch.complex64: True,
  560. torch.complex128: True,
  561. torch.uint8: False,
  562. torch.uint16: True,
  563. torch.uint32: True,
  564. torch.uint64: True,
  565. torch.int8: False,
  566. torch.int16: False,
  567. torch.int32: True,
  568. torch.int64: True,
  569. torch.bool: False,
  570. },
  571. torch.uint32: {
  572. torch.float16: False,
  573. torch.float32: False,
  574. torch.float64: True,
  575. torch.complex64: False,
  576. torch.complex128: True,
  577. torch.uint8: False,
  578. torch.uint16: False,
  579. torch.uint32: True,
  580. torch.uint64: True,
  581. torch.int8: False,
  582. torch.int16: False,
  583. torch.int32: False,
  584. torch.int64: True,
  585. torch.bool: False,
  586. },
  587. torch.uint64: {
  588. torch.float16: False,
  589. torch.float32: False,
  590. torch.float64: True,
  591. torch.complex64: False,
  592. torch.complex128: True,
  593. torch.uint8: False,
  594. torch.uint16: False,
  595. torch.uint32: False,
  596. torch.uint64: True,
  597. torch.int8: False,
  598. torch.int16: False,
  599. torch.int32: False,
  600. torch.int64: False,
  601. torch.bool: False,
  602. },
  603. torch.int8: {
  604. torch.float16: True,
  605. torch.float32: True,
  606. torch.float64: True,
  607. torch.complex64: True,
  608. torch.complex128: True,
  609. torch.uint8: False,
  610. torch.uint16: False,
  611. torch.uint32: False,
  612. torch.uint64: False,
  613. torch.int8: True,
  614. torch.int16: True,
  615. torch.int32: True,
  616. torch.int64: True,
  617. torch.bool: False,
  618. },
  619. torch.int16: {
  620. torch.float16: False,
  621. torch.float32: True,
  622. torch.float64: True,
  623. torch.complex64: True,
  624. torch.complex128: True,
  625. torch.uint8: False,
  626. torch.uint16: False,
  627. torch.uint32: False,
  628. torch.uint64: False,
  629. torch.int8: False,
  630. torch.int16: True,
  631. torch.int32: True,
  632. torch.int64: True,
  633. torch.bool: False,
  634. },
  635. torch.int32: {
  636. torch.float16: False,
  637. torch.float32: False,
  638. torch.float64: True,
  639. torch.complex64: False,
  640. torch.complex128: True,
  641. torch.uint8: False,
  642. torch.uint16: False,
  643. torch.uint32: False,
  644. torch.uint64: False,
  645. torch.int8: False,
  646. torch.int16: False,
  647. torch.int32: True,
  648. torch.int64: True,
  649. torch.bool: False,
  650. },
  651. torch.int64: {
  652. torch.float16: False,
  653. torch.float32: False,
  654. torch.float64: True,
  655. torch.complex64: False,
  656. torch.complex128: True,
  657. torch.uint8: False,
  658. torch.uint16: False,
  659. torch.uint32: False,
  660. torch.uint64: False,
  661. torch.int8: False,
  662. torch.int16: False,
  663. torch.int32: False,
  664. torch.int64: True,
  665. torch.bool: False,
  666. },
  667. torch.bool: {
  668. torch.float16: True,
  669. torch.float32: True,
  670. torch.float64: True,
  671. torch.complex64: True,
  672. torch.complex128: True,
  673. torch.uint8: True,
  674. torch.uint16: True,
  675. torch.uint32: True,
  676. torch.uint64: True,
  677. torch.int8: True,
  678. torch.int16: True,
  679. torch.int32: True,
  680. torch.int64: True,
  681. torch.bool: True,
  682. },
  683. },
  684. "same_kind": {
  685. torch.float16: {
  686. torch.float16: True,
  687. torch.float32: True,
  688. torch.float64: True,
  689. torch.complex64: True,
  690. torch.complex128: True,
  691. torch.uint8: False,
  692. torch.uint16: False,
  693. torch.uint32: False,
  694. torch.uint64: False,
  695. torch.int8: False,
  696. torch.int16: False,
  697. torch.int32: False,
  698. torch.int64: False,
  699. torch.bool: False,
  700. },
  701. torch.float32: {
  702. torch.float16: True,
  703. torch.float32: True,
  704. torch.float64: True,
  705. torch.complex64: True,
  706. torch.complex128: True,
  707. torch.uint8: False,
  708. torch.uint16: False,
  709. torch.uint32: False,
  710. torch.uint64: False,
  711. torch.int8: False,
  712. torch.int16: False,
  713. torch.int32: False,
  714. torch.int64: False,
  715. torch.bool: False,
  716. },
  717. torch.float64: {
  718. torch.float16: True,
  719. torch.float32: True,
  720. torch.float64: True,
  721. torch.complex64: True,
  722. torch.complex128: True,
  723. torch.uint8: False,
  724. torch.uint16: False,
  725. torch.uint32: False,
  726. torch.uint64: False,
  727. torch.int8: False,
  728. torch.int16: False,
  729. torch.int32: False,
  730. torch.int64: False,
  731. torch.bool: False,
  732. },
  733. torch.complex64: {
  734. torch.float16: False,
  735. torch.float32: False,
  736. torch.float64: False,
  737. torch.complex64: True,
  738. torch.complex128: True,
  739. torch.uint8: False,
  740. torch.uint16: False,
  741. torch.uint32: False,
  742. torch.uint64: False,
  743. torch.int8: False,
  744. torch.int16: False,
  745. torch.int32: False,
  746. torch.int64: False,
  747. torch.bool: False,
  748. },
  749. torch.complex128: {
  750. torch.float16: False,
  751. torch.float32: False,
  752. torch.float64: False,
  753. torch.complex64: True,
  754. torch.complex128: True,
  755. torch.uint8: False,
  756. torch.uint16: False,
  757. torch.uint32: False,
  758. torch.uint64: False,
  759. torch.int8: False,
  760. torch.int16: False,
  761. torch.int32: False,
  762. torch.int64: False,
  763. torch.bool: False,
  764. },
  765. torch.uint8: {
  766. torch.float16: True,
  767. torch.float32: True,
  768. torch.float64: True,
  769. torch.complex64: True,
  770. torch.complex128: True,
  771. torch.uint8: True,
  772. torch.uint16: True,
  773. torch.uint32: True,
  774. torch.uint64: True,
  775. torch.int8: True,
  776. torch.int16: True,
  777. torch.int32: True,
  778. torch.int64: True,
  779. torch.bool: False,
  780. },
  781. torch.uint16: {
  782. torch.float16: True,
  783. torch.float32: True,
  784. torch.float64: True,
  785. torch.complex64: True,
  786. torch.complex128: True,
  787. torch.uint8: True,
  788. torch.uint16: True,
  789. torch.uint32: True,
  790. torch.uint64: True,
  791. torch.int8: True,
  792. torch.int16: True,
  793. torch.int32: True,
  794. torch.int64: True,
  795. torch.bool: False,
  796. },
  797. torch.uint32: {
  798. torch.float16: True,
  799. torch.float32: True,
  800. torch.float64: True,
  801. torch.complex64: True,
  802. torch.complex128: True,
  803. torch.uint8: True,
  804. torch.uint16: True,
  805. torch.uint32: True,
  806. torch.uint64: True,
  807. torch.int8: True,
  808. torch.int16: True,
  809. torch.int32: True,
  810. torch.int64: True,
  811. torch.bool: False,
  812. },
  813. torch.uint64: {
  814. torch.float16: True,
  815. torch.float32: True,
  816. torch.float64: True,
  817. torch.complex64: True,
  818. torch.complex128: True,
  819. torch.uint8: True,
  820. torch.uint16: True,
  821. torch.uint32: True,
  822. torch.uint64: True,
  823. torch.int8: True,
  824. torch.int16: True,
  825. torch.int32: True,
  826. torch.int64: True,
  827. torch.bool: False,
  828. },
  829. torch.int8: {
  830. torch.float16: True,
  831. torch.float32: True,
  832. torch.float64: True,
  833. torch.complex64: True,
  834. torch.complex128: True,
  835. torch.uint8: False,
  836. torch.uint16: False,
  837. torch.uint32: False,
  838. torch.uint64: False,
  839. torch.int8: True,
  840. torch.int16: True,
  841. torch.int32: True,
  842. torch.int64: True,
  843. torch.bool: False,
  844. },
  845. torch.int16: {
  846. torch.float16: True,
  847. torch.float32: True,
  848. torch.float64: True,
  849. torch.complex64: True,
  850. torch.complex128: True,
  851. torch.uint8: False,
  852. torch.uint16: False,
  853. torch.uint32: False,
  854. torch.uint64: False,
  855. torch.int8: True,
  856. torch.int16: True,
  857. torch.int32: True,
  858. torch.int64: True,
  859. torch.bool: False,
  860. },
  861. torch.int32: {
  862. torch.float16: True,
  863. torch.float32: True,
  864. torch.float64: True,
  865. torch.complex64: True,
  866. torch.complex128: True,
  867. torch.uint8: False,
  868. torch.uint16: False,
  869. torch.uint32: False,
  870. torch.uint64: False,
  871. torch.int8: True,
  872. torch.int16: True,
  873. torch.int32: True,
  874. torch.int64: True,
  875. torch.bool: False,
  876. },
  877. torch.int64: {
  878. torch.float16: True,
  879. torch.float32: True,
  880. torch.float64: True,
  881. torch.complex64: True,
  882. torch.complex128: True,
  883. torch.uint8: False,
  884. torch.uint16: False,
  885. torch.uint32: False,
  886. torch.uint64: False,
  887. torch.int8: True,
  888. torch.int16: True,
  889. torch.int32: True,
  890. torch.int64: True,
  891. torch.bool: False,
  892. },
  893. torch.bool: {
  894. torch.float16: True,
  895. torch.float32: True,
  896. torch.float64: True,
  897. torch.complex64: True,
  898. torch.complex128: True,
  899. torch.uint8: True,
  900. torch.uint16: True,
  901. torch.uint32: True,
  902. torch.uint64: True,
  903. torch.int8: True,
  904. torch.int16: True,
  905. torch.int32: True,
  906. torch.int64: True,
  907. torch.bool: True,
  908. },
  909. },
  910. "unsafe": {
  911. torch.float16: {
  912. torch.float16: True,
  913. torch.float32: True,
  914. torch.float64: True,
  915. torch.complex64: True,
  916. torch.complex128: True,
  917. torch.uint8: True,
  918. torch.uint16: True,
  919. torch.uint32: True,
  920. torch.uint64: True,
  921. torch.int8: True,
  922. torch.int16: True,
  923. torch.int32: True,
  924. torch.int64: True,
  925. torch.bool: True,
  926. },
  927. torch.float32: {
  928. torch.float16: True,
  929. torch.float32: True,
  930. torch.float64: True,
  931. torch.complex64: True,
  932. torch.complex128: True,
  933. torch.uint8: True,
  934. torch.uint16: True,
  935. torch.uint32: True,
  936. torch.uint64: True,
  937. torch.int8: True,
  938. torch.int16: True,
  939. torch.int32: True,
  940. torch.int64: True,
  941. torch.bool: True,
  942. },
  943. torch.float64: {
  944. torch.float16: True,
  945. torch.float32: True,
  946. torch.float64: True,
  947. torch.complex64: True,
  948. torch.complex128: True,
  949. torch.uint8: True,
  950. torch.uint16: True,
  951. torch.uint32: True,
  952. torch.uint64: True,
  953. torch.int8: True,
  954. torch.int16: True,
  955. torch.int32: True,
  956. torch.int64: True,
  957. torch.bool: True,
  958. },
  959. torch.complex64: {
  960. torch.float16: True,
  961. torch.float32: True,
  962. torch.float64: True,
  963. torch.complex64: True,
  964. torch.complex128: True,
  965. torch.uint8: True,
  966. torch.uint16: True,
  967. torch.uint32: True,
  968. torch.uint64: True,
  969. torch.int8: True,
  970. torch.int16: True,
  971. torch.int32: True,
  972. torch.int64: True,
  973. torch.bool: True,
  974. },
  975. torch.complex128: {
  976. torch.float16: True,
  977. torch.float32: True,
  978. torch.float64: True,
  979. torch.complex64: True,
  980. torch.complex128: True,
  981. torch.uint8: True,
  982. torch.uint16: True,
  983. torch.uint32: True,
  984. torch.uint64: True,
  985. torch.int8: True,
  986. torch.int16: True,
  987. torch.int32: True,
  988. torch.int64: True,
  989. torch.bool: True,
  990. },
  991. torch.uint8: {
  992. torch.float16: True,
  993. torch.float32: True,
  994. torch.float64: True,
  995. torch.complex64: True,
  996. torch.complex128: True,
  997. torch.uint8: True,
  998. torch.uint16: True,
  999. torch.uint32: True,
  1000. torch.uint64: True,
  1001. torch.int8: True,
  1002. torch.int16: True,
  1003. torch.int32: True,
  1004. torch.int64: True,
  1005. torch.bool: True,
  1006. },
  1007. torch.uint16: {
  1008. torch.float16: True,
  1009. torch.float32: True,
  1010. torch.float64: True,
  1011. torch.complex64: True,
  1012. torch.complex128: True,
  1013. torch.uint8: True,
  1014. torch.uint16: True,
  1015. torch.uint32: True,
  1016. torch.uint64: True,
  1017. torch.int8: True,
  1018. torch.int16: True,
  1019. torch.int32: True,
  1020. torch.int64: True,
  1021. torch.bool: True,
  1022. },
  1023. torch.uint32: {
  1024. torch.float16: True,
  1025. torch.float32: True,
  1026. torch.float64: True,
  1027. torch.complex64: True,
  1028. torch.complex128: True,
  1029. torch.uint8: True,
  1030. torch.uint16: True,
  1031. torch.uint32: True,
  1032. torch.uint64: True,
  1033. torch.int8: True,
  1034. torch.int16: True,
  1035. torch.int32: True,
  1036. torch.int64: True,
  1037. torch.bool: True,
  1038. },
  1039. torch.uint64: {
  1040. torch.float16: True,
  1041. torch.float32: True,
  1042. torch.float64: True,
  1043. torch.complex64: True,
  1044. torch.complex128: True,
  1045. torch.uint8: True,
  1046. torch.uint16: True,
  1047. torch.uint32: True,
  1048. torch.uint64: True,
  1049. torch.int8: True,
  1050. torch.int16: True,
  1051. torch.int32: True,
  1052. torch.int64: True,
  1053. torch.bool: True,
  1054. },
  1055. torch.int8: {
  1056. torch.float16: True,
  1057. torch.float32: True,
  1058. torch.float64: True,
  1059. torch.complex64: True,
  1060. torch.complex128: True,
  1061. torch.uint8: True,
  1062. torch.uint16: True,
  1063. torch.uint32: True,
  1064. torch.uint64: True,
  1065. torch.int8: True,
  1066. torch.int16: True,
  1067. torch.int32: True,
  1068. torch.int64: True,
  1069. torch.bool: True,
  1070. },
  1071. torch.int16: {
  1072. torch.float16: True,
  1073. torch.float32: True,
  1074. torch.float64: True,
  1075. torch.complex64: True,
  1076. torch.complex128: True,
  1077. torch.uint8: True,
  1078. torch.uint16: True,
  1079. torch.uint32: True,
  1080. torch.uint64: True,
  1081. torch.int8: True,
  1082. torch.int16: True,
  1083. torch.int32: True,
  1084. torch.int64: True,
  1085. torch.bool: True,
  1086. },
  1087. torch.int32: {
  1088. torch.float16: True,
  1089. torch.float32: True,
  1090. torch.float64: True,
  1091. torch.complex64: True,
  1092. torch.complex128: True,
  1093. torch.uint8: True,
  1094. torch.uint16: True,
  1095. torch.uint32: True,
  1096. torch.uint64: True,
  1097. torch.int8: True,
  1098. torch.int16: True,
  1099. torch.int32: True,
  1100. torch.int64: True,
  1101. torch.bool: True,
  1102. },
  1103. torch.int64: {
  1104. torch.float16: True,
  1105. torch.float32: True,
  1106. torch.float64: True,
  1107. torch.complex64: True,
  1108. torch.complex128: True,
  1109. torch.uint8: True,
  1110. torch.uint16: True,
  1111. torch.uint32: True,
  1112. torch.uint64: True,
  1113. torch.int8: True,
  1114. torch.int16: True,
  1115. torch.int32: True,
  1116. torch.int64: True,
  1117. torch.bool: True,
  1118. },
  1119. torch.bool: {
  1120. torch.float16: True,
  1121. torch.float32: True,
  1122. torch.float64: True,
  1123. torch.complex64: True,
  1124. torch.complex128: True,
  1125. torch.uint8: True,
  1126. torch.uint16: True,
  1127. torch.uint32: True,
  1128. torch.uint64: True,
  1129. torch.int8: True,
  1130. torch.int16: True,
  1131. torch.int32: True,
  1132. torch.int64: True,
  1133. torch.bool: True,
  1134. },
  1135. },
  1136. }
  1137. _result_type_dict = {
  1138. torch.float16: {
  1139. torch.float16: torch.float16,
  1140. torch.float32: torch.float32,
  1141. torch.float64: torch.float64,
  1142. torch.complex64: torch.complex64,
  1143. torch.complex128: torch.complex128,
  1144. torch.uint8: torch.float16,
  1145. torch.uint16: torch.float32,
  1146. torch.uint32: torch.float64,
  1147. torch.uint64: torch.float64,
  1148. torch.int8: torch.float16,
  1149. torch.int16: torch.float32,
  1150. torch.int32: torch.float64,
  1151. torch.int64: torch.float64,
  1152. torch.bool: torch.float16,
  1153. },
  1154. torch.float32: {
  1155. torch.float16: torch.float32,
  1156. torch.float32: torch.float32,
  1157. torch.float64: torch.float64,
  1158. torch.complex64: torch.complex64,
  1159. torch.complex128: torch.complex128,
  1160. torch.uint8: torch.float32,
  1161. torch.uint16: torch.float32,
  1162. torch.uint32: torch.float64,
  1163. torch.uint64: torch.float64,
  1164. torch.int8: torch.float32,
  1165. torch.int16: torch.float32,
  1166. torch.int32: torch.float64,
  1167. torch.int64: torch.float64,
  1168. torch.bool: torch.float32,
  1169. },
  1170. torch.float64: {
  1171. torch.float16: torch.float64,
  1172. torch.float32: torch.float64,
  1173. torch.float64: torch.float64,
  1174. torch.complex64: torch.complex128,
  1175. torch.complex128: torch.complex128,
  1176. torch.uint8: torch.float64,
  1177. torch.uint16: torch.float64,
  1178. torch.uint32: torch.float64,
  1179. torch.uint64: torch.float64,
  1180. torch.int8: torch.float64,
  1181. torch.int16: torch.float64,
  1182. torch.int32: torch.float64,
  1183. torch.int64: torch.float64,
  1184. torch.bool: torch.float64,
  1185. },
  1186. torch.complex64: {
  1187. torch.float16: torch.complex64,
  1188. torch.float32: torch.complex64,
  1189. torch.float64: torch.complex128,
  1190. torch.complex64: torch.complex64,
  1191. torch.complex128: torch.complex128,
  1192. torch.uint8: torch.complex64,
  1193. torch.uint16: torch.complex64,
  1194. torch.uint32: torch.complex128,
  1195. torch.uint64: torch.complex128,
  1196. torch.int8: torch.complex64,
  1197. torch.int16: torch.complex64,
  1198. torch.int32: torch.complex128,
  1199. torch.int64: torch.complex128,
  1200. torch.bool: torch.complex64,
  1201. },
  1202. torch.complex128: {
  1203. torch.float16: torch.complex128,
  1204. torch.float32: torch.complex128,
  1205. torch.float64: torch.complex128,
  1206. torch.complex64: torch.complex128,
  1207. torch.complex128: torch.complex128,
  1208. torch.uint8: torch.complex128,
  1209. torch.uint16: torch.complex128,
  1210. torch.uint32: torch.complex128,
  1211. torch.uint64: torch.complex128,
  1212. torch.int8: torch.complex128,
  1213. torch.int16: torch.complex128,
  1214. torch.int32: torch.complex128,
  1215. torch.int64: torch.complex128,
  1216. torch.bool: torch.complex128,
  1217. },
  1218. torch.uint8: {
  1219. torch.float16: torch.float16,
  1220. torch.float32: torch.float32,
  1221. torch.float64: torch.float64,
  1222. torch.complex64: torch.complex64,
  1223. torch.complex128: torch.complex128,
  1224. torch.uint8: torch.uint8,
  1225. torch.uint16: torch.uint16,
  1226. torch.uint32: torch.uint32,
  1227. torch.uint64: torch.uint64,
  1228. torch.int8: torch.int16,
  1229. torch.int16: torch.int16,
  1230. torch.int32: torch.int32,
  1231. torch.int64: torch.int64,
  1232. torch.bool: torch.uint8,
  1233. },
  1234. torch.uint16: {
  1235. torch.float16: torch.float32,
  1236. torch.float32: torch.float32,
  1237. torch.float64: torch.float64,
  1238. torch.complex64: torch.complex64,
  1239. torch.complex128: torch.complex128,
  1240. torch.uint8: torch.uint16,
  1241. torch.uint16: torch.uint16,
  1242. torch.uint32: torch.uint32,
  1243. torch.uint64: torch.uint64,
  1244. torch.int8: torch.int32,
  1245. torch.int16: torch.int32,
  1246. torch.int32: torch.int32,
  1247. torch.int64: torch.int64,
  1248. torch.bool: torch.uint16,
  1249. },
  1250. torch.uint32: {
  1251. torch.float16: torch.float64,
  1252. torch.float32: torch.float64,
  1253. torch.float64: torch.float64,
  1254. torch.complex64: torch.complex128,
  1255. torch.complex128: torch.complex128,
  1256. torch.uint8: torch.uint32,
  1257. torch.uint16: torch.uint32,
  1258. torch.uint32: torch.uint32,
  1259. torch.uint64: torch.uint64,
  1260. torch.int8: torch.int64,
  1261. torch.int16: torch.int64,
  1262. torch.int32: torch.int64,
  1263. torch.int64: torch.int64,
  1264. torch.bool: torch.uint32,
  1265. },
  1266. torch.uint64: {
  1267. torch.float16: torch.float64,
  1268. torch.float32: torch.float64,
  1269. torch.float64: torch.float64,
  1270. torch.complex64: torch.complex128,
  1271. torch.complex128: torch.complex128,
  1272. torch.uint8: torch.uint64,
  1273. torch.uint16: torch.uint64,
  1274. torch.uint32: torch.uint64,
  1275. torch.uint64: torch.uint64,
  1276. torch.int8: torch.float64,
  1277. torch.int16: torch.float64,
  1278. torch.int32: torch.float64,
  1279. torch.int64: torch.float64,
  1280. torch.bool: torch.uint64,
  1281. },
  1282. torch.int8: {
  1283. torch.float16: torch.float16,
  1284. torch.float32: torch.float32,
  1285. torch.float64: torch.float64,
  1286. torch.complex64: torch.complex64,
  1287. torch.complex128: torch.complex128,
  1288. torch.uint8: torch.int16,
  1289. torch.uint16: torch.int32,
  1290. torch.uint32: torch.int64,
  1291. torch.uint64: torch.float64,
  1292. torch.int8: torch.int8,
  1293. torch.int16: torch.int16,
  1294. torch.int32: torch.int32,
  1295. torch.int64: torch.int64,
  1296. torch.bool: torch.int8,
  1297. },
  1298. torch.int16: {
  1299. torch.float16: torch.float32,
  1300. torch.float32: torch.float32,
  1301. torch.float64: torch.float64,
  1302. torch.complex64: torch.complex64,
  1303. torch.complex128: torch.complex128,
  1304. torch.uint8: torch.int16,
  1305. torch.uint16: torch.int32,
  1306. torch.uint32: torch.int64,
  1307. torch.uint64: torch.float64,
  1308. torch.int8: torch.int16,
  1309. torch.int16: torch.int16,
  1310. torch.int32: torch.int32,
  1311. torch.int64: torch.int64,
  1312. torch.bool: torch.int16,
  1313. },
  1314. torch.int32: {
  1315. torch.float16: torch.float64,
  1316. torch.float32: torch.float64,
  1317. torch.float64: torch.float64,
  1318. torch.complex64: torch.complex128,
  1319. torch.complex128: torch.complex128,
  1320. torch.uint8: torch.int32,
  1321. torch.uint16: torch.int32,
  1322. torch.uint32: torch.int64,
  1323. torch.uint64: torch.float64,
  1324. torch.int8: torch.int32,
  1325. torch.int16: torch.int32,
  1326. torch.int32: torch.int32,
  1327. torch.int64: torch.int64,
  1328. torch.bool: torch.int32,
  1329. },
  1330. torch.int64: {
  1331. torch.float16: torch.float64,
  1332. torch.float32: torch.float64,
  1333. torch.float64: torch.float64,
  1334. torch.complex64: torch.complex128,
  1335. torch.complex128: torch.complex128,
  1336. torch.uint8: torch.int64,
  1337. torch.uint16: torch.int64,
  1338. torch.uint32: torch.int64,
  1339. torch.uint64: torch.float64,
  1340. torch.int8: torch.int64,
  1341. torch.int16: torch.int64,
  1342. torch.int32: torch.int64,
  1343. torch.int64: torch.int64,
  1344. torch.bool: torch.int64,
  1345. },
  1346. torch.bool: {
  1347. torch.float16: torch.float16,
  1348. torch.float32: torch.float32,
  1349. torch.float64: torch.float64,
  1350. torch.complex64: torch.complex64,
  1351. torch.complex128: torch.complex128,
  1352. torch.uint8: torch.uint8,
  1353. torch.uint16: torch.uint16,
  1354. torch.uint32: torch.uint32,
  1355. torch.uint64: torch.uint64,
  1356. torch.int8: torch.int8,
  1357. torch.int16: torch.int16,
  1358. torch.int32: torch.int32,
  1359. torch.int64: torch.int64,
  1360. torch.bool: torch.bool,
  1361. },
  1362. }