arithmetic.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. import numpy as np
  2. c16 = np.complex128()
  3. f8 = np.float64()
  4. i8 = np.int64()
  5. u8 = np.uint64()
  6. c8 = np.complex64()
  7. f4 = np.float32()
  8. i4 = np.int32()
  9. u4 = np.uint32()
  10. dt = np.datetime64(0, "D")
  11. td = np.timedelta64(0, "D")
  12. b_ = np.bool_()
  13. b = bool()
  14. c = complex()
  15. f = float()
  16. i = int()
  17. AR = np.array([0], dtype=np.float64)
  18. AR.setflags(write=False)
  19. # unary ops
  20. reveal_type(-c16) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  21. reveal_type(-c8) # E: numpy.complexfloating[numpy.typing._32Bit, numpy.typing._32Bit]
  22. reveal_type(-f8) # E: numpy.floating[numpy.typing._64Bit]
  23. reveal_type(-f4) # E: numpy.floating[numpy.typing._32Bit]
  24. reveal_type(-i8) # E: numpy.signedinteger[numpy.typing._64Bit]
  25. reveal_type(-i4) # E: numpy.signedinteger[numpy.typing._32Bit]
  26. reveal_type(-u8) # E: numpy.unsignedinteger[numpy.typing._64Bit]
  27. reveal_type(-u4) # E: numpy.unsignedinteger[numpy.typing._32Bit]
  28. reveal_type(-td) # E: numpy.timedelta64
  29. reveal_type(-AR) # E: Any
  30. reveal_type(+c16) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  31. reveal_type(+c8) # E: numpy.complexfloating[numpy.typing._32Bit, numpy.typing._32Bit]
  32. reveal_type(+f8) # E: numpy.floating[numpy.typing._64Bit]
  33. reveal_type(+f4) # E: numpy.floating[numpy.typing._32Bit]
  34. reveal_type(+i8) # E: numpy.signedinteger[numpy.typing._64Bit]
  35. reveal_type(+i4) # E: numpy.signedinteger[numpy.typing._32Bit]
  36. reveal_type(+u8) # E: numpy.unsignedinteger[numpy.typing._64Bit]
  37. reveal_type(+u4) # E: numpy.unsignedinteger[numpy.typing._32Bit]
  38. reveal_type(+td) # E: numpy.timedelta64
  39. reveal_type(+AR) # E: Any
  40. reveal_type(abs(c16)) # E: numpy.floating[numpy.typing._64Bit]
  41. reveal_type(abs(c8)) # E: numpy.floating[numpy.typing._32Bit]
  42. reveal_type(abs(f8)) # E: numpy.floating[numpy.typing._64Bit]
  43. reveal_type(abs(f4)) # E: numpy.floating[numpy.typing._32Bit]
  44. reveal_type(abs(i8)) # E: numpy.signedinteger[numpy.typing._64Bit]
  45. reveal_type(abs(i4)) # E: numpy.signedinteger[numpy.typing._32Bit]
  46. reveal_type(abs(u8)) # E: numpy.unsignedinteger[numpy.typing._64Bit]
  47. reveal_type(abs(u4)) # E: numpy.unsignedinteger[numpy.typing._32Bit]
  48. reveal_type(abs(td)) # E: numpy.timedelta64
  49. reveal_type(abs(b_)) # E: numpy.bool_
  50. reveal_type(abs(AR)) # E: Any
  51. # Time structures
  52. reveal_type(dt + td) # E: numpy.datetime64
  53. reveal_type(dt + i) # E: numpy.datetime64
  54. reveal_type(dt + i4) # E: numpy.datetime64
  55. reveal_type(dt + i8) # E: numpy.datetime64
  56. reveal_type(dt - dt) # E: numpy.timedelta64
  57. reveal_type(dt - i) # E: numpy.datetime64
  58. reveal_type(dt - i4) # E: numpy.datetime64
  59. reveal_type(dt - i8) # E: numpy.datetime64
  60. reveal_type(td + td) # E: numpy.timedelta64
  61. reveal_type(td + i) # E: numpy.timedelta64
  62. reveal_type(td + i4) # E: numpy.timedelta64
  63. reveal_type(td + i8) # E: numpy.timedelta64
  64. reveal_type(td - td) # E: numpy.timedelta64
  65. reveal_type(td - i) # E: numpy.timedelta64
  66. reveal_type(td - i4) # E: numpy.timedelta64
  67. reveal_type(td - i8) # E: numpy.timedelta64
  68. reveal_type(td / f) # E: numpy.timedelta64
  69. reveal_type(td / f4) # E: numpy.timedelta64
  70. reveal_type(td / f8) # E: numpy.timedelta64
  71. reveal_type(td / td) # E: numpy.floating[numpy.typing._64Bit]
  72. reveal_type(td // td) # E: numpy.signedinteger[numpy.typing._64Bit]
  73. # boolean
  74. reveal_type(b_ / b) # E: numpy.floating[numpy.typing._64Bit]
  75. reveal_type(b_ / b_) # E: numpy.floating[numpy.typing._64Bit]
  76. reveal_type(b_ / i) # E: numpy.floating[numpy.typing._64Bit]
  77. reveal_type(b_ / i8) # E: numpy.floating[numpy.typing._64Bit]
  78. reveal_type(b_ / i4) # E: numpy.floating[numpy.typing._64Bit]
  79. reveal_type(b_ / u8) # E: numpy.floating[numpy.typing._64Bit]
  80. reveal_type(b_ / u4) # E: numpy.floating[numpy.typing._64Bit]
  81. reveal_type(b_ / f) # E: numpy.floating[numpy.typing._64Bit]
  82. reveal_type(b_ / f8) # E: numpy.floating[numpy.typing._64Bit]
  83. reveal_type(b_ / f4) # E: numpy.floating[numpy.typing._32Bit]
  84. reveal_type(b_ / c) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  85. reveal_type(b_ / c16) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  86. reveal_type(b_ / c8) # E: numpy.complexfloating[numpy.typing._32Bit, numpy.typing._32Bit]
  87. reveal_type(b / b_) # E: numpy.floating[numpy.typing._64Bit]
  88. reveal_type(b_ / b_) # E: numpy.floating[numpy.typing._64Bit]
  89. reveal_type(i / b_) # E: numpy.floating[numpy.typing._64Bit]
  90. reveal_type(i8 / b_) # E: numpy.floating[numpy.typing._64Bit]
  91. reveal_type(i4 / b_) # E: numpy.floating[numpy.typing._64Bit]
  92. reveal_type(u8 / b_) # E: numpy.floating[numpy.typing._64Bit]
  93. reveal_type(u4 / b_) # E: numpy.floating[numpy.typing._64Bit]
  94. reveal_type(f / b_) # E: numpy.floating[numpy.typing._64Bit]
  95. reveal_type(f8 / b_) # E: numpy.floating[numpy.typing._64Bit]
  96. reveal_type(f4 / b_) # E: numpy.floating[numpy.typing._32Bit]
  97. reveal_type(c / b_) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  98. reveal_type(c16 / b_) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  99. reveal_type(c8 / b_) # E: numpy.complexfloating[numpy.typing._32Bit, numpy.typing._32Bit]
  100. # Complex
  101. reveal_type(c16 + c16) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  102. reveal_type(c16 + f8) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  103. reveal_type(c16 + i8) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  104. reveal_type(c16 + c8) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  105. reveal_type(c16 + f4) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  106. reveal_type(c16 + i4) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  107. reveal_type(c16 + b_) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  108. reveal_type(c16 + b) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  109. reveal_type(c16 + c) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  110. reveal_type(c16 + f) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  111. reveal_type(c16 + i) # E: numpy.complexfloating[Any, Any]
  112. reveal_type(c16 + AR) # E: Any
  113. reveal_type(c16 + c16) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  114. reveal_type(f8 + c16) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  115. reveal_type(i8 + c16) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  116. reveal_type(c8 + c16) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  117. reveal_type(f4 + c16) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  118. reveal_type(i4 + c16) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  119. reveal_type(b_ + c16) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  120. reveal_type(b + c16) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  121. reveal_type(c + c16) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  122. reveal_type(f + c16) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  123. reveal_type(i + c16) # E: numpy.complexfloating[Any, Any]
  124. reveal_type(AR + c16) # E: Any
  125. reveal_type(c8 + c16) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  126. reveal_type(c8 + f8) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  127. reveal_type(c8 + i8) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  128. reveal_type(c8 + c8) # E: numpy.complexfloating[numpy.typing._32Bit, numpy.typing._32Bit]
  129. reveal_type(c8 + f4) # E: numpy.complexfloating[numpy.typing._32Bit, numpy.typing._32Bit]
  130. reveal_type(c8 + i4) # E: numpy.complexfloating[numpy.typing._32Bit, numpy.typing._32Bit]
  131. reveal_type(c8 + b_) # E: numpy.complexfloating[numpy.typing._32Bit, numpy.typing._32Bit]
  132. reveal_type(c8 + b) # E: numpy.complexfloating[numpy.typing._32Bit, numpy.typing._32Bit]
  133. reveal_type(c8 + c) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  134. reveal_type(c8 + f) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  135. reveal_type(c8 + i) # E: numpy.complexfloating[Any, Any]
  136. reveal_type(c8 + AR) # E: Any
  137. reveal_type(c16 + c8) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  138. reveal_type(f8 + c8) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  139. reveal_type(i8 + c8) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  140. reveal_type(c8 + c8) # E: numpy.complexfloating[numpy.typing._32Bit, numpy.typing._32Bit]
  141. reveal_type(f4 + c8) # E: numpy.complexfloating[numpy.typing._32Bit, numpy.typing._32Bit]
  142. reveal_type(i4 + c8) # E: numpy.complexfloating[numpy.typing._32Bit, numpy.typing._32Bit]
  143. reveal_type(b_ + c8) # E: numpy.complexfloating[numpy.typing._32Bit, numpy.typing._32Bit]
  144. reveal_type(b + c8) # E: numpy.complexfloating[numpy.typing._32Bit, numpy.typing._32Bit]
  145. reveal_type(c + c8) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  146. reveal_type(f + c8) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  147. reveal_type(i + c8) # E: numpy.complexfloating[Any, Any]
  148. reveal_type(AR + c8) # E: Any
  149. # Float
  150. reveal_type(f8 + f8) # E: numpy.floating[numpy.typing._64Bit]
  151. reveal_type(f8 + i8) # E: numpy.floating[numpy.typing._64Bit]
  152. reveal_type(f8 + f4) # E: numpy.floating[numpy.typing._64Bit]
  153. reveal_type(f8 + i4) # E: numpy.floating[numpy.typing._64Bit]
  154. reveal_type(f8 + b_) # E: numpy.floating[numpy.typing._64Bit]
  155. reveal_type(f8 + b) # E: numpy.floating[numpy.typing._64Bit]
  156. reveal_type(f8 + c) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  157. reveal_type(f8 + f) # E: numpy.floating[numpy.typing._64Bit]
  158. reveal_type(f8 + i) # E: numpy.floating[Any]
  159. reveal_type(f8 + AR) # E: Any
  160. reveal_type(f8 + f8) # E: numpy.floating[numpy.typing._64Bit]
  161. reveal_type(i8 + f8) # E: numpy.floating[numpy.typing._64Bit]
  162. reveal_type(f4 + f8) # E: numpy.floating[numpy.typing._64Bit]
  163. reveal_type(i4 + f8) # E: numpy.floating[numpy.typing._64Bit]
  164. reveal_type(b_ + f8) # E: numpy.floating[numpy.typing._64Bit]
  165. reveal_type(b + f8) # E: numpy.floating[numpy.typing._64Bit]
  166. reveal_type(c + f8) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  167. reveal_type(f + f8) # E: numpy.floating[numpy.typing._64Bit]
  168. reveal_type(i + f8) # E: numpy.floating[Any]
  169. reveal_type(AR + f8) # E: Any
  170. reveal_type(f4 + f8) # E: numpy.floating[numpy.typing._64Bit]
  171. reveal_type(f4 + i8) # E: numpy.floating[numpy.typing._64Bit]
  172. reveal_type(f4 + f4) # E: numpy.floating[numpy.typing._32Bit]
  173. reveal_type(f4 + i4) # E: numpy.floating[numpy.typing._32Bit]
  174. reveal_type(f4 + b_) # E: numpy.floating[numpy.typing._32Bit]
  175. reveal_type(f4 + b) # E: numpy.floating[numpy.typing._32Bit]
  176. reveal_type(f4 + c) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  177. reveal_type(f4 + f) # E: numpy.floating[numpy.typing._64Bit]
  178. reveal_type(f4 + i) # E: numpy.floating[Any]
  179. reveal_type(f4 + AR) # E: Any
  180. reveal_type(f8 + f4) # E: numpy.floating[numpy.typing._64Bit]
  181. reveal_type(i8 + f4) # E: numpy.floating[numpy.typing._64Bit]
  182. reveal_type(f4 + f4) # E: umpy.floating[numpy.typing._32Bit]
  183. reveal_type(i4 + f4) # E: umpy.floating[numpy.typing._32Bit]
  184. reveal_type(b_ + f4) # E: umpy.floating[numpy.typing._32Bit]
  185. reveal_type(b + f4) # E: umpy.floating[numpy.typing._32Bit]
  186. reveal_type(c + f4) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  187. reveal_type(f + f4) # E: numpy.floating[numpy.typing._64Bit]
  188. reveal_type(i + f4) # E: numpy.floating[Any]
  189. reveal_type(AR + f4) # E: Any
  190. # Int
  191. reveal_type(i8 + i8) # E: numpy.signedinteger[numpy.typing._64Bit]
  192. reveal_type(i8 + u8) # E: Any
  193. reveal_type(i8 + i4) # E: numpy.signedinteger[numpy.typing._64Bit]
  194. reveal_type(i8 + u4) # E: Any
  195. reveal_type(i8 + b_) # E: numpy.signedinteger[numpy.typing._64Bit]
  196. reveal_type(i8 + b) # E: numpy.signedinteger[numpy.typing._64Bit]
  197. reveal_type(i8 + c) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  198. reveal_type(i8 + f) # E: numpy.floating[numpy.typing._64Bit]
  199. reveal_type(i8 + i) # E: numpy.signedinteger[Any]
  200. reveal_type(i8 + AR) # E: Any
  201. reveal_type(u8 + u8) # E: numpy.unsignedinteger[numpy.typing._64Bit]
  202. reveal_type(u8 + i4) # E: Any
  203. reveal_type(u8 + u4) # E: numpy.unsignedinteger[numpy.typing._64Bit]
  204. reveal_type(u8 + b_) # E: numpy.unsignedinteger[numpy.typing._64Bit]
  205. reveal_type(u8 + b) # E: numpy.unsignedinteger[numpy.typing._64Bit]
  206. reveal_type(u8 + c) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  207. reveal_type(u8 + f) # E: numpy.floating[numpy.typing._64Bit]
  208. reveal_type(u8 + i) # E: Any
  209. reveal_type(u8 + AR) # E: Any
  210. reveal_type(i8 + i8) # E: numpy.signedinteger[numpy.typing._64Bit]
  211. reveal_type(u8 + i8) # E: Any
  212. reveal_type(i4 + i8) # E: numpy.signedinteger[numpy.typing._64Bit]
  213. reveal_type(u4 + i8) # E: Any
  214. reveal_type(b_ + i8) # E: numpy.signedinteger[numpy.typing._64Bit]
  215. reveal_type(b + i8) # E: numpy.signedinteger[numpy.typing._64Bit]
  216. reveal_type(c + i8) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  217. reveal_type(f + i8) # E: numpy.floating[numpy.typing._64Bit]
  218. reveal_type(i + i8) # E: numpy.signedinteger[Any]
  219. reveal_type(AR + i8) # E: Any
  220. reveal_type(u8 + u8) # E: numpy.unsignedinteger[numpy.typing._64Bit]
  221. reveal_type(i4 + u8) # E: Any
  222. reveal_type(u4 + u8) # E: numpy.unsignedinteger[numpy.typing._64Bit]
  223. reveal_type(b_ + u8) # E: numpy.unsignedinteger[numpy.typing._64Bit]
  224. reveal_type(b + u8) # E: numpy.unsignedinteger[numpy.typing._64Bit]
  225. reveal_type(c + u8) # E: numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit]
  226. reveal_type(f + u8) # E: numpy.floating[numpy.typing._64Bit]
  227. reveal_type(i + u8) # E: Any
  228. reveal_type(AR + u8) # E: Any
  229. reveal_type(i4 + i8) # E: numpy.signedinteger[numpy.typing._64Bit]
  230. reveal_type(i4 + i4) # E: numpy.signedinteger[numpy.typing._32Bit]
  231. reveal_type(i4 + i) # E: numpy.signedinteger[Any]
  232. reveal_type(i4 + b_) # E: numpy.signedinteger[numpy.typing._32Bit]
  233. reveal_type(i4 + b) # E: numpy.signedinteger[numpy.typing._32Bit]
  234. reveal_type(i4 + AR) # E: Any
  235. reveal_type(u4 + i8) # E: Any
  236. reveal_type(u4 + i4) # E: Any
  237. reveal_type(u4 + u8) # E: numpy.unsignedinteger[numpy.typing._64Bit]
  238. reveal_type(u4 + u4) # E: numpy.unsignedinteger[numpy.typing._32Bit]
  239. reveal_type(u4 + i) # E: Any
  240. reveal_type(u4 + b_) # E: numpy.unsignedinteger[numpy.typing._32Bit]
  241. reveal_type(u4 + b) # E: numpy.unsignedinteger[numpy.typing._32Bit]
  242. reveal_type(u4 + AR) # E: Any
  243. reveal_type(i8 + i4) # E: numpy.signedinteger[numpy.typing._64Bit]
  244. reveal_type(i4 + i4) # E: numpy.signedinteger[numpy.typing._32Bit]
  245. reveal_type(i + i4) # E: numpy.signedinteger[Any]
  246. reveal_type(b_ + i4) # E: numpy.signedinteger[numpy.typing._32Bit]
  247. reveal_type(b + i4) # E: numpy.signedinteger[numpy.typing._32Bit]
  248. reveal_type(AR + i4) # E: Any
  249. reveal_type(i8 + u4) # E: Any
  250. reveal_type(i4 + u4) # E: Any
  251. reveal_type(u8 + u4) # E: numpy.unsignedinteger[numpy.typing._64Bit]
  252. reveal_type(u4 + u4) # E: numpy.unsignedinteger[numpy.typing._32Bit]
  253. reveal_type(b_ + u4) # E: numpy.unsignedinteger[numpy.typing._32Bit]
  254. reveal_type(b + u4) # E: numpy.unsignedinteger[numpy.typing._32Bit]
  255. reveal_type(i + u4) # E: Any
  256. reveal_type(AR + u4) # E: Any