numpy-ts 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (469) hide show
  1. package/README.md +4 -3
  2. package/dist/esm/common/broadcasting.js +1 -1
  3. package/dist/esm/common/dtype.js +1 -1
  4. package/dist/esm/common/float16-conv.js +1 -0
  5. package/dist/esm/common/internal/compute.js +1 -1
  6. package/dist/esm/common/internal/indexing.js +1 -1
  7. package/dist/esm/common/ndarray-core.js +1 -1
  8. package/dist/esm/common/ops/advanced.js +1 -1
  9. package/dist/esm/common/ops/arithmetic.js +1 -1
  10. package/dist/esm/common/ops/bitwise.js +1 -1
  11. package/dist/esm/common/ops/comparison.js +1 -1
  12. package/dist/esm/common/ops/complex.js +1 -1
  13. package/dist/esm/common/ops/exponential.js +1 -1
  14. package/dist/esm/common/ops/fft.js +1 -1
  15. package/dist/esm/common/ops/formatting.js +1 -1
  16. package/dist/esm/common/ops/gradient.js +1 -1
  17. package/dist/esm/common/ops/hyperbolic.js +1 -1
  18. package/dist/esm/common/ops/linalg.js +2 -2
  19. package/dist/esm/common/ops/logic.js +1 -1
  20. package/dist/esm/common/ops/random.js +1 -1
  21. package/dist/esm/common/ops/reduction.js +1 -1
  22. package/dist/esm/common/ops/rounding.js +1 -1
  23. package/dist/esm/common/ops/sets.js +1 -1
  24. package/dist/esm/common/ops/shape.js +1 -1
  25. package/dist/esm/common/ops/sorting.js +1 -1
  26. package/dist/esm/common/ops/statistics.js +1 -1
  27. package/dist/esm/common/ops/trig.js +1 -1
  28. package/dist/esm/common/storage.js +1 -1
  29. package/dist/esm/common/wasm/abs.js +1 -0
  30. package/dist/esm/common/wasm/add.js +1 -0
  31. package/dist/esm/common/wasm/arccos.js +1 -0
  32. package/dist/esm/common/wasm/arcsin.js +1 -0
  33. package/dist/esm/common/wasm/arctan.js +1 -0
  34. package/dist/esm/common/wasm/argpartition.js +1 -0
  35. package/dist/esm/common/wasm/argsort.js +1 -0
  36. package/dist/esm/common/wasm/bins/abs.wasm.js +1 -0
  37. package/dist/esm/common/wasm/bins/add.wasm.js +1 -0
  38. package/dist/esm/common/wasm/bins/arccos.wasm.js +1 -0
  39. package/dist/esm/common/wasm/bins/arcsin.wasm.js +1 -0
  40. package/dist/esm/common/wasm/bins/arctan.wasm.js +1 -0
  41. package/dist/esm/common/wasm/bins/argpartition.wasm.js +1 -0
  42. package/dist/esm/common/wasm/bins/argsort.wasm.js +1 -0
  43. package/dist/esm/common/wasm/bins/bitwise_and.wasm.js +1 -0
  44. package/dist/esm/common/wasm/bins/bitwise_count.wasm.js +1 -0
  45. package/dist/esm/common/wasm/bins/bitwise_not.wasm.js +1 -0
  46. package/dist/esm/common/wasm/bins/bitwise_or.wasm.js +1 -0
  47. package/dist/esm/common/wasm/bins/bitwise_xor.wasm.js +1 -0
  48. package/dist/esm/common/wasm/bins/cholesky.wasm.js +1 -0
  49. package/dist/esm/common/wasm/bins/clip.wasm.js +1 -0
  50. package/dist/esm/common/wasm/bins/convolve.wasm.js +1 -0
  51. package/dist/esm/common/wasm/bins/copysign.wasm.js +1 -0
  52. package/dist/esm/common/wasm/bins/correlate.wasm.js +1 -0
  53. package/dist/esm/common/wasm/bins/cos.wasm.js +1 -0
  54. package/dist/esm/common/wasm/bins/cosh.wasm.js +1 -0
  55. package/dist/esm/common/wasm/bins/cross.wasm.js +1 -0
  56. package/dist/esm/common/wasm/bins/diff.wasm.js +1 -0
  57. package/dist/esm/common/wasm/bins/divide.wasm.js +1 -0
  58. package/dist/esm/common/wasm/bins/dot.wasm.js +1 -0
  59. package/dist/esm/common/wasm/bins/exp.wasm.js +1 -0
  60. package/dist/esm/common/wasm/bins/exp2.wasm.js +1 -0
  61. package/dist/esm/common/wasm/bins/fft.wasm.js +1 -0
  62. package/dist/esm/common/wasm/bins/flip.wasm.js +1 -0
  63. package/dist/esm/common/wasm/bins/frexp.wasm.js +1 -0
  64. package/dist/esm/common/wasm/bins/gather.wasm.js +1 -0
  65. package/dist/esm/common/wasm/bins/gcd.wasm.js +1 -0
  66. package/dist/esm/common/wasm/bins/gradient.wasm.js +1 -0
  67. package/dist/esm/common/wasm/bins/heaviside.wasm.js +1 -0
  68. package/dist/esm/common/wasm/bins/hypot.wasm.js +1 -0
  69. package/dist/esm/common/wasm/bins/indices.wasm.js +1 -0
  70. package/dist/esm/common/wasm/bins/inner.wasm.js +1 -0
  71. package/dist/esm/common/wasm/bins/kron.wasm.js +1 -0
  72. package/dist/esm/common/wasm/bins/ldexp.wasm.js +1 -0
  73. package/dist/esm/common/wasm/bins/left_shift.wasm.js +1 -0
  74. package/dist/esm/common/wasm/bins/lexsort.wasm.js +1 -0
  75. package/dist/esm/common/wasm/bins/logaddexp.wasm.js +1 -0
  76. package/dist/esm/common/wasm/bins/logical_and.wasm.js +1 -0
  77. package/dist/esm/common/wasm/bins/logical_not.wasm.js +1 -0
  78. package/dist/esm/common/wasm/bins/logical_or.wasm.js +1 -0
  79. package/dist/esm/common/wasm/bins/logical_xor.wasm.js +1 -0
  80. package/dist/esm/common/wasm/bins/matmul.wasm.js +1 -0
  81. package/dist/esm/common/wasm/bins/matvec.wasm.js +1 -0
  82. package/dist/esm/common/wasm/bins/max.wasm.js +1 -0
  83. package/dist/esm/common/wasm/bins/min.wasm.js +1 -0
  84. package/dist/esm/common/wasm/bins/mul.wasm.js +1 -0
  85. package/dist/esm/common/wasm/bins/neg.wasm.js +1 -0
  86. package/dist/esm/common/wasm/bins/outer.wasm.js +1 -0
  87. package/dist/esm/common/wasm/bins/pad.wasm.js +1 -0
  88. package/dist/esm/common/wasm/bins/partition.wasm.js +1 -0
  89. package/dist/esm/common/wasm/bins/power.wasm.js +1 -0
  90. package/dist/esm/common/wasm/bins/qr.wasm.js +1 -0
  91. package/dist/esm/common/wasm/bins/reciprocal.wasm.js +1 -0
  92. package/dist/esm/common/wasm/bins/reduce_all.wasm.js +1 -0
  93. package/dist/esm/common/wasm/bins/reduce_any.wasm.js +1 -0
  94. package/dist/esm/common/wasm/bins/reduce_argmax.wasm.js +1 -0
  95. package/dist/esm/common/wasm/bins/reduce_argmin.wasm.js +1 -0
  96. package/dist/esm/common/wasm/bins/reduce_count_nz.wasm.js +1 -0
  97. package/dist/esm/common/wasm/bins/reduce_max.wasm.js +1 -0
  98. package/dist/esm/common/wasm/bins/reduce_mean.wasm.js +1 -0
  99. package/dist/esm/common/wasm/bins/reduce_min.wasm.js +1 -0
  100. package/dist/esm/common/wasm/bins/reduce_nanmax.wasm.js +1 -0
  101. package/dist/esm/common/wasm/bins/reduce_nanmin.wasm.js +1 -0
  102. package/dist/esm/common/wasm/bins/reduce_nansum.wasm.js +1 -0
  103. package/dist/esm/common/wasm/bins/reduce_prod.wasm.js +1 -0
  104. package/dist/esm/common/wasm/bins/reduce_quantile.wasm.js +1 -0
  105. package/dist/esm/common/wasm/bins/reduce_std.wasm.js +1 -0
  106. package/dist/esm/common/wasm/bins/reduce_sum.wasm.js +1 -0
  107. package/dist/esm/common/wasm/bins/reduce_var.wasm.js +1 -0
  108. package/dist/esm/common/wasm/bins/repeat.wasm.js +1 -0
  109. package/dist/esm/common/wasm/bins/right_shift.wasm.js +1 -0
  110. package/dist/esm/common/wasm/bins/rng.wasm.js +1 -0
  111. package/dist/esm/common/wasm/bins/roll.wasm.js +1 -0
  112. package/dist/esm/common/wasm/bins/rot90.wasm.js +1 -0
  113. package/dist/esm/common/wasm/bins/searchsorted.wasm.js +1 -0
  114. package/dist/esm/common/wasm/bins/sign.wasm.js +1 -0
  115. package/dist/esm/common/wasm/bins/sinh.wasm.js +1 -0
  116. package/dist/esm/common/wasm/bins/sort.wasm.js +1 -0
  117. package/dist/esm/common/wasm/bins/sqrt.wasm.js +1 -0
  118. package/dist/esm/common/wasm/bins/square.wasm.js +1 -0
  119. package/dist/esm/common/wasm/bins/sub.wasm.js +1 -0
  120. package/dist/esm/common/wasm/bins/svd.wasm.js +1 -0
  121. package/dist/esm/common/wasm/bins/tan.wasm.js +1 -0
  122. package/dist/esm/common/wasm/bins/tanh.wasm.js +1 -0
  123. package/dist/esm/common/wasm/bins/tile.wasm.js +1 -0
  124. package/dist/esm/common/wasm/bins/vdot.wasm.js +1 -0
  125. package/dist/esm/common/wasm/bins/vecdot.wasm.js +1 -0
  126. package/dist/esm/common/wasm/bins/vecmat.wasm.js +1 -0
  127. package/dist/esm/common/wasm/bitwise_and.js +1 -0
  128. package/dist/esm/common/wasm/bitwise_count.js +1 -0
  129. package/dist/esm/common/wasm/bitwise_not.js +1 -0
  130. package/dist/esm/common/wasm/bitwise_or.js +1 -0
  131. package/dist/esm/common/wasm/bitwise_xor.js +1 -0
  132. package/dist/esm/common/wasm/cholesky.js +1 -0
  133. package/dist/esm/common/wasm/clip.js +1 -0
  134. package/dist/esm/common/wasm/config.js +1 -0
  135. package/dist/esm/common/wasm/convolve.js +1 -0
  136. package/dist/esm/common/wasm/copysign.js +1 -0
  137. package/dist/esm/common/wasm/correlate.js +1 -0
  138. package/dist/esm/common/wasm/cos.js +1 -0
  139. package/dist/esm/common/wasm/cosh.js +1 -0
  140. package/dist/esm/common/wasm/cross.js +1 -0
  141. package/dist/esm/common/wasm/diff.js +1 -0
  142. package/dist/esm/common/wasm/divide.js +1 -0
  143. package/dist/esm/common/wasm/dot.js +1 -0
  144. package/dist/esm/common/wasm/exp.js +1 -0
  145. package/dist/esm/common/wasm/exp2.js +1 -0
  146. package/dist/esm/common/wasm/fft.js +1 -0
  147. package/dist/esm/common/wasm/flip.js +1 -0
  148. package/dist/esm/common/wasm/frexp.js +1 -0
  149. package/dist/esm/common/wasm/gather.js +1 -0
  150. package/dist/esm/common/wasm/gcd.js +1 -0
  151. package/dist/esm/common/wasm/gradient.js +1 -0
  152. package/dist/esm/common/wasm/heaviside.js +1 -0
  153. package/dist/esm/common/wasm/hypot.js +1 -0
  154. package/dist/esm/common/wasm/indices.js +1 -0
  155. package/dist/esm/common/wasm/inner.js +1 -0
  156. package/dist/esm/common/wasm/kron.js +1 -0
  157. package/dist/esm/common/wasm/ldexp.js +1 -0
  158. package/dist/esm/common/wasm/left_shift.js +1 -0
  159. package/dist/esm/common/wasm/lexsort.js +1 -0
  160. package/dist/esm/common/wasm/logaddexp.js +1 -0
  161. package/dist/esm/common/wasm/logical_and.js +1 -0
  162. package/dist/esm/common/wasm/logical_not.js +1 -0
  163. package/dist/esm/common/wasm/logical_or.js +1 -0
  164. package/dist/esm/common/wasm/logical_xor.js +1 -0
  165. package/dist/esm/common/wasm/matmul.js +1 -0
  166. package/dist/esm/common/wasm/matvec.js +1 -0
  167. package/dist/esm/common/wasm/max.js +1 -0
  168. package/dist/esm/common/wasm/min.js +1 -0
  169. package/dist/esm/common/wasm/mul.js +1 -0
  170. package/dist/esm/common/wasm/neg.js +1 -0
  171. package/dist/esm/common/wasm/outer.js +1 -0
  172. package/dist/esm/common/wasm/pad.js +1 -0
  173. package/dist/esm/common/wasm/partition.js +1 -0
  174. package/dist/esm/common/wasm/power.js +1 -0
  175. package/dist/esm/common/wasm/qr.js +1 -0
  176. package/dist/esm/common/wasm/reciprocal.js +1 -0
  177. package/dist/esm/common/wasm/reduce_all.js +1 -0
  178. package/dist/esm/common/wasm/reduce_any.js +1 -0
  179. package/dist/esm/common/wasm/reduce_argmax.js +1 -0
  180. package/dist/esm/common/wasm/reduce_argmin.js +1 -0
  181. package/dist/esm/common/wasm/reduce_count_nz.js +1 -0
  182. package/dist/esm/common/wasm/reduce_max.js +1 -0
  183. package/dist/esm/common/wasm/reduce_mean.js +1 -0
  184. package/dist/esm/common/wasm/reduce_min.js +1 -0
  185. package/dist/esm/common/wasm/reduce_nanmax.js +1 -0
  186. package/dist/esm/common/wasm/reduce_nanmin.js +1 -0
  187. package/dist/esm/common/wasm/reduce_nansum.js +1 -0
  188. package/dist/esm/common/wasm/reduce_prod.js +1 -0
  189. package/dist/esm/common/wasm/reduce_quantile.js +1 -0
  190. package/dist/esm/common/wasm/reduce_std.js +1 -0
  191. package/dist/esm/common/wasm/reduce_sum.js +1 -0
  192. package/dist/esm/common/wasm/reduce_var.js +1 -0
  193. package/dist/esm/common/wasm/repeat.js +1 -0
  194. package/dist/esm/common/wasm/right_shift.js +1 -0
  195. package/dist/esm/common/wasm/rng.js +1 -0
  196. package/dist/esm/common/wasm/roll.js +1 -0
  197. package/dist/esm/common/wasm/rot90.js +1 -0
  198. package/dist/esm/common/wasm/runtime.js +1 -0
  199. package/dist/esm/common/wasm/searchsorted.js +1 -0
  200. package/dist/esm/common/wasm/sign.js +1 -0
  201. package/dist/esm/common/wasm/sinh.js +1 -0
  202. package/dist/esm/common/wasm/sort.js +1 -0
  203. package/dist/esm/common/wasm/sqrt.js +1 -0
  204. package/dist/esm/common/wasm/square.js +1 -0
  205. package/dist/esm/common/wasm/sub.js +1 -0
  206. package/dist/esm/common/wasm/svd.js +1 -0
  207. package/dist/esm/common/wasm/tan.js +1 -0
  208. package/dist/esm/common/wasm/tanh.js +1 -0
  209. package/dist/esm/common/wasm/tile.js +1 -0
  210. package/dist/esm/common/wasm/vdot.js +1 -0
  211. package/dist/esm/common/wasm/vecdot.js +1 -0
  212. package/dist/esm/common/wasm/vecmat.js +1 -0
  213. package/dist/esm/core/advanced.js +1 -1
  214. package/dist/esm/core/arithmetic.js +1 -1
  215. package/dist/esm/core/bitwise.js +1 -1
  216. package/dist/esm/core/complex.js +1 -1
  217. package/dist/esm/core/creation.js +1 -1
  218. package/dist/esm/core/formatting.js +1 -1
  219. package/dist/esm/core/gradient.js +1 -1
  220. package/dist/esm/core/index.js +1 -1
  221. package/dist/esm/core/linalg.js +1 -1
  222. package/dist/esm/core/logic.js +1 -1
  223. package/dist/esm/core/polynomial.js +1 -1
  224. package/dist/esm/core/reduction.js +1 -1
  225. package/dist/esm/core/rounding.js +1 -1
  226. package/dist/esm/core/sets.js +1 -1
  227. package/dist/esm/core/shape-extra.js +1 -1
  228. package/dist/esm/core/shape.js +1 -1
  229. package/dist/esm/core/sorting.js +1 -1
  230. package/dist/esm/core/statistics.js +1 -1
  231. package/dist/esm/core/trig.js +1 -1
  232. package/dist/esm/core/typechecking.js +1 -1
  233. package/dist/esm/core/types.js +1 -1
  234. package/dist/esm/core/utility.js +1 -1
  235. package/dist/esm/core.js +1 -1
  236. package/dist/esm/full/index.js +1 -1
  237. package/dist/esm/full/ndarray.js +1 -1
  238. package/dist/esm/index.js +1 -1
  239. package/dist/esm/io/file-ops.js +1 -0
  240. package/dist/esm/io/filesystem.js +1 -0
  241. package/dist/esm/io/index.js +1 -1
  242. package/dist/esm/io/npy/format.js +1 -1
  243. package/dist/esm/io/npy/index.js +1 -1
  244. package/dist/esm/io/npy/parser.js +1 -1
  245. package/dist/esm/io/npy/serializer.js +2 -2
  246. package/dist/esm/io/npz/index.js +1 -1
  247. package/dist/esm/io/npz/parser.js +1 -1
  248. package/dist/esm/io/npz/serializer.js +1 -1
  249. package/dist/esm/io/txt/index.js +1 -1
  250. package/dist/esm/io/txt/parser.js +1 -1
  251. package/dist/esm/io/zip/index.js +1 -1
  252. package/dist/esm/io/zip/reader.js +1 -1
  253. package/dist/esm/io/zip/types.js +1 -1
  254. package/dist/esm/io/zip/writer.js +1 -1
  255. package/dist/esm/node.js +1 -1
  256. package/dist/numpy-ts.browser.js +6 -6
  257. package/dist/types/common/dtype.d.ts +9 -4
  258. package/dist/types/common/float16-conv.d.ts +27 -0
  259. package/dist/types/common/internal/indexing.d.ts +15 -18
  260. package/dist/types/common/ndarray-core.d.ts +3 -13
  261. package/dist/types/common/ops/linalg.d.ts +13 -12
  262. package/dist/types/common/ops/random.d.ts +10 -5
  263. package/dist/types/common/ops/sets.d.ts +1 -1
  264. package/dist/types/common/ops/shape.d.ts +11 -0
  265. package/dist/types/common/storage.d.ts +4 -0
  266. package/dist/types/common/wasm/abs.d.ts +14 -0
  267. package/dist/types/common/wasm/add.d.ts +19 -0
  268. package/dist/types/common/wasm/arccos.d.ts +15 -0
  269. package/dist/types/common/wasm/arcsin.d.ts +15 -0
  270. package/dist/types/common/wasm/arctan.d.ts +15 -0
  271. package/dist/types/common/wasm/argpartition.d.ts +18 -0
  272. package/dist/types/common/wasm/argsort.d.ts +18 -0
  273. package/dist/types/common/wasm/bins/abs.wasm.d.ts +7 -0
  274. package/dist/types/common/wasm/bins/add.wasm.d.ts +17 -0
  275. package/dist/types/common/wasm/bins/arccos.wasm.d.ts +5 -0
  276. package/dist/types/common/wasm/bins/arcsin.wasm.d.ts +5 -0
  277. package/dist/types/common/wasm/bins/arctan.wasm.d.ts +5 -0
  278. package/dist/types/common/wasm/bins/argpartition.wasm.d.ts +21 -0
  279. package/dist/types/common/wasm/bins/argsort.wasm.d.ts +25 -0
  280. package/dist/types/common/wasm/bins/bitwise_and.wasm.d.ts +5 -0
  281. package/dist/types/common/wasm/bins/bitwise_count.wasm.d.ts +9 -0
  282. package/dist/types/common/wasm/bins/bitwise_not.wasm.d.ts +5 -0
  283. package/dist/types/common/wasm/bins/bitwise_or.wasm.d.ts +5 -0
  284. package/dist/types/common/wasm/bins/bitwise_xor.wasm.d.ts +5 -0
  285. package/dist/types/common/wasm/bins/cholesky.wasm.d.ts +3 -0
  286. package/dist/types/common/wasm/bins/clip.wasm.d.ts +11 -0
  287. package/dist/types/common/wasm/bins/convolve.wasm.d.ts +3 -0
  288. package/dist/types/common/wasm/bins/copysign.wasm.d.ts +21 -0
  289. package/dist/types/common/wasm/bins/correlate.wasm.d.ts +3 -0
  290. package/dist/types/common/wasm/bins/cos.wasm.d.ts +3 -0
  291. package/dist/types/common/wasm/bins/cosh.wasm.d.ts +5 -0
  292. package/dist/types/common/wasm/bins/cross.wasm.d.ts +9 -0
  293. package/dist/types/common/wasm/bins/diff.wasm.d.ts +13 -0
  294. package/dist/types/common/wasm/bins/divide.wasm.d.ts +23 -0
  295. package/dist/types/common/wasm/bins/dot.wasm.d.ts +9 -0
  296. package/dist/types/common/wasm/bins/exp.wasm.d.ts +5 -0
  297. package/dist/types/common/wasm/bins/exp2.wasm.d.ts +5 -0
  298. package/dist/types/common/wasm/bins/fft.wasm.d.ts +22 -0
  299. package/dist/types/common/wasm/bins/flip.wasm.d.ts +7 -0
  300. package/dist/types/common/wasm/bins/frexp.wasm.d.ts +2 -0
  301. package/dist/types/common/wasm/bins/gather.wasm.d.ts +32 -0
  302. package/dist/types/common/wasm/bins/gcd.wasm.d.ts +3 -0
  303. package/dist/types/common/wasm/bins/gradient.wasm.d.ts +11 -0
  304. package/dist/types/common/wasm/bins/heaviside.wasm.d.ts +5 -0
  305. package/dist/types/common/wasm/bins/hypot.wasm.d.ts +13 -0
  306. package/dist/types/common/wasm/bins/indices.wasm.d.ts +3 -0
  307. package/dist/types/common/wasm/bins/inner.wasm.d.ts +9 -0
  308. package/dist/types/common/wasm/bins/kron.wasm.d.ts +9 -0
  309. package/dist/types/common/wasm/bins/ldexp.wasm.d.ts +3 -0
  310. package/dist/types/common/wasm/bins/left_shift.wasm.d.ts +9 -0
  311. package/dist/types/common/wasm/bins/lexsort.wasm.d.ts +11 -0
  312. package/dist/types/common/wasm/bins/logaddexp.wasm.d.ts +21 -0
  313. package/dist/types/common/wasm/bins/logical_and.wasm.d.ts +13 -0
  314. package/dist/types/common/wasm/bins/logical_not.wasm.d.ts +7 -0
  315. package/dist/types/common/wasm/bins/logical_or.wasm.d.ts +13 -0
  316. package/dist/types/common/wasm/bins/logical_xor.wasm.d.ts +13 -0
  317. package/dist/types/common/wasm/bins/matmul.wasm.d.ts +9 -0
  318. package/dist/types/common/wasm/bins/matvec.wasm.d.ts +9 -0
  319. package/dist/types/common/wasm/bins/max.wasm.d.ts +21 -0
  320. package/dist/types/common/wasm/bins/min.wasm.d.ts +21 -0
  321. package/dist/types/common/wasm/bins/mul.wasm.d.ts +17 -0
  322. package/dist/types/common/wasm/bins/neg.wasm.d.ts +9 -0
  323. package/dist/types/common/wasm/bins/outer.wasm.d.ts +9 -0
  324. package/dist/types/common/wasm/bins/pad.wasm.d.ts +7 -0
  325. package/dist/types/common/wasm/bins/partition.wasm.d.ts +21 -0
  326. package/dist/types/common/wasm/bins/power.wasm.d.ts +13 -0
  327. package/dist/types/common/wasm/bins/qr.wasm.d.ts +3 -0
  328. package/dist/types/common/wasm/bins/reciprocal.wasm.d.ts +7 -0
  329. package/dist/types/common/wasm/bins/reduce_all.wasm.d.ts +7 -0
  330. package/dist/types/common/wasm/bins/reduce_any.wasm.d.ts +7 -0
  331. package/dist/types/common/wasm/bins/reduce_argmax.wasm.d.ts +11 -0
  332. package/dist/types/common/wasm/bins/reduce_argmin.wasm.d.ts +11 -0
  333. package/dist/types/common/wasm/bins/reduce_count_nz.wasm.d.ts +7 -0
  334. package/dist/types/common/wasm/bins/reduce_max.wasm.d.ts +20 -0
  335. package/dist/types/common/wasm/bins/reduce_mean.wasm.d.ts +21 -0
  336. package/dist/types/common/wasm/bins/reduce_min.wasm.d.ts +20 -0
  337. package/dist/types/common/wasm/bins/reduce_nanmax.wasm.d.ts +3 -0
  338. package/dist/types/common/wasm/bins/reduce_nanmin.wasm.d.ts +3 -0
  339. package/dist/types/common/wasm/bins/reduce_nansum.wasm.d.ts +3 -0
  340. package/dist/types/common/wasm/bins/reduce_prod.wasm.d.ts +19 -0
  341. package/dist/types/common/wasm/bins/reduce_quantile.wasm.d.ts +2 -0
  342. package/dist/types/common/wasm/bins/reduce_std.wasm.d.ts +11 -0
  343. package/dist/types/common/wasm/bins/reduce_sum.wasm.d.ts +17 -0
  344. package/dist/types/common/wasm/bins/reduce_var.wasm.d.ts +11 -0
  345. package/dist/types/common/wasm/bins/repeat.wasm.d.ts +7 -0
  346. package/dist/types/common/wasm/bins/right_shift.wasm.d.ts +17 -0
  347. package/dist/types/common/wasm/bins/rng.wasm.d.ts +60 -0
  348. package/dist/types/common/wasm/bins/roll.wasm.d.ts +7 -0
  349. package/dist/types/common/wasm/bins/rot90.wasm.d.ts +7 -0
  350. package/dist/types/common/wasm/bins/searchsorted.wasm.d.ts +21 -0
  351. package/dist/types/common/wasm/bins/sign.wasm.d.ts +7 -0
  352. package/dist/types/common/wasm/bins/sinh.wasm.d.ts +5 -0
  353. package/dist/types/common/wasm/bins/sort.wasm.d.ts +27 -0
  354. package/dist/types/common/wasm/bins/sqrt.wasm.d.ts +7 -0
  355. package/dist/types/common/wasm/bins/square.wasm.d.ts +9 -0
  356. package/dist/types/common/wasm/bins/sub.wasm.d.ts +17 -0
  357. package/dist/types/common/wasm/bins/svd.wasm.d.ts +2 -0
  358. package/dist/types/common/wasm/bins/tan.wasm.d.ts +3 -0
  359. package/dist/types/common/wasm/bins/tanh.wasm.d.ts +5 -0
  360. package/dist/types/common/wasm/bins/tile.wasm.d.ts +7 -0
  361. package/dist/types/common/wasm/bins/vdot.wasm.d.ts +3 -0
  362. package/dist/types/common/wasm/bins/vecdot.wasm.d.ts +9 -0
  363. package/dist/types/common/wasm/bins/vecmat.wasm.d.ts +9 -0
  364. package/dist/types/common/wasm/bitwise_and.d.ts +9 -0
  365. package/dist/types/common/wasm/bitwise_count.d.ts +11 -0
  366. package/dist/types/common/wasm/bitwise_not.d.ts +9 -0
  367. package/dist/types/common/wasm/bitwise_or.d.ts +9 -0
  368. package/dist/types/common/wasm/bitwise_xor.d.ts +9 -0
  369. package/dist/types/common/wasm/cholesky.d.ts +20 -0
  370. package/dist/types/common/wasm/clip.d.ts +13 -0
  371. package/dist/types/common/wasm/config.d.ts +21 -0
  372. package/dist/types/common/wasm/convolve.d.ts +14 -0
  373. package/dist/types/common/wasm/copysign.d.ts +19 -0
  374. package/dist/types/common/wasm/correlate.d.ts +14 -0
  375. package/dist/types/common/wasm/cos.d.ts +15 -0
  376. package/dist/types/common/wasm/cosh.d.ts +15 -0
  377. package/dist/types/common/wasm/cross.d.ts +15 -0
  378. package/dist/types/common/wasm/diff.d.ts +15 -0
  379. package/dist/types/common/wasm/divide.d.ts +11 -0
  380. package/dist/types/common/wasm/dot.d.ts +14 -0
  381. package/dist/types/common/wasm/exp.d.ts +15 -0
  382. package/dist/types/common/wasm/exp2.d.ts +15 -0
  383. package/dist/types/common/wasm/fft.d.ts +65 -0
  384. package/dist/types/common/wasm/flip.d.ts +13 -0
  385. package/dist/types/common/wasm/frexp.d.ts +9 -0
  386. package/dist/types/common/wasm/gather.d.ts +23 -0
  387. package/dist/types/common/wasm/gcd.d.ts +11 -0
  388. package/dist/types/common/wasm/gradient.d.ts +13 -0
  389. package/dist/types/common/wasm/heaviside.d.ts +11 -0
  390. package/dist/types/common/wasm/hypot.d.ts +21 -0
  391. package/dist/types/common/wasm/indices.d.ts +10 -0
  392. package/dist/types/common/wasm/inner.d.ts +20 -0
  393. package/dist/types/common/wasm/kron.d.ts +13 -0
  394. package/dist/types/common/wasm/ldexp.d.ts +9 -0
  395. package/dist/types/common/wasm/left_shift.d.ts +11 -0
  396. package/dist/types/common/wasm/lexsort.d.ts +14 -0
  397. package/dist/types/common/wasm/logaddexp.d.ts +21 -0
  398. package/dist/types/common/wasm/logical_and.d.ts +19 -0
  399. package/dist/types/common/wasm/logical_not.d.ts +13 -0
  400. package/dist/types/common/wasm/logical_or.d.ts +19 -0
  401. package/dist/types/common/wasm/logical_xor.d.ts +19 -0
  402. package/dist/types/common/wasm/matmul.d.ts +18 -0
  403. package/dist/types/common/wasm/matvec.d.ts +13 -0
  404. package/dist/types/common/wasm/max.d.ts +11 -0
  405. package/dist/types/common/wasm/min.d.ts +11 -0
  406. package/dist/types/common/wasm/mul.d.ts +19 -0
  407. package/dist/types/common/wasm/neg.d.ts +13 -0
  408. package/dist/types/common/wasm/outer.d.ts +13 -0
  409. package/dist/types/common/wasm/pad.d.ts +14 -0
  410. package/dist/types/common/wasm/partition.d.ts +20 -0
  411. package/dist/types/common/wasm/power.d.ts +19 -0
  412. package/dist/types/common/wasm/qr.d.ts +17 -0
  413. package/dist/types/common/wasm/reciprocal.d.ts +9 -0
  414. package/dist/types/common/wasm/reduce_all.d.ts +14 -0
  415. package/dist/types/common/wasm/reduce_any.d.ts +14 -0
  416. package/dist/types/common/wasm/reduce_argmax.d.ts +14 -0
  417. package/dist/types/common/wasm/reduce_argmin.d.ts +14 -0
  418. package/dist/types/common/wasm/reduce_count_nz.d.ts +14 -0
  419. package/dist/types/common/wasm/reduce_max.d.ts +19 -0
  420. package/dist/types/common/wasm/reduce_mean.d.ts +19 -0
  421. package/dist/types/common/wasm/reduce_min.d.ts +19 -0
  422. package/dist/types/common/wasm/reduce_nanmax.d.ts +14 -0
  423. package/dist/types/common/wasm/reduce_nanmin.d.ts +14 -0
  424. package/dist/types/common/wasm/reduce_nansum.d.ts +14 -0
  425. package/dist/types/common/wasm/reduce_prod.d.ts +20 -0
  426. package/dist/types/common/wasm/reduce_quantile.d.ts +15 -0
  427. package/dist/types/common/wasm/reduce_std.d.ts +14 -0
  428. package/dist/types/common/wasm/reduce_sum.d.ts +20 -0
  429. package/dist/types/common/wasm/reduce_var.d.ts +14 -0
  430. package/dist/types/common/wasm/repeat.d.ts +14 -0
  431. package/dist/types/common/wasm/right_shift.d.ts +11 -0
  432. package/dist/types/common/wasm/rng.d.ts +65 -0
  433. package/dist/types/common/wasm/roll.d.ts +13 -0
  434. package/dist/types/common/wasm/rot90.d.ts +14 -0
  435. package/dist/types/common/wasm/runtime.d.ts +55 -0
  436. package/dist/types/common/wasm/searchsorted.d.ts +12 -0
  437. package/dist/types/common/wasm/sign.d.ts +14 -0
  438. package/dist/types/common/wasm/sinh.d.ts +15 -0
  439. package/dist/types/common/wasm/sort.d.ts +20 -0
  440. package/dist/types/common/wasm/sqrt.d.ts +15 -0
  441. package/dist/types/common/wasm/square.d.ts +13 -0
  442. package/dist/types/common/wasm/sub.d.ts +19 -0
  443. package/dist/types/common/wasm/svd.d.ts +18 -0
  444. package/dist/types/common/wasm/tan.d.ts +15 -0
  445. package/dist/types/common/wasm/tanh.d.ts +15 -0
  446. package/dist/types/common/wasm/tile.d.ts +14 -0
  447. package/dist/types/common/wasm/vdot.d.ts +16 -0
  448. package/dist/types/common/wasm/vecdot.d.ts +15 -0
  449. package/dist/types/common/wasm/vecmat.d.ts +13 -0
  450. package/dist/types/core/index.d.ts +94 -1
  451. package/dist/types/core/linalg.d.ts +10 -10
  452. package/dist/types/core/reduction.d.ts +17 -17
  453. package/dist/types/core/rounding.d.ts +0 -2
  454. package/dist/types/core/sets.d.ts +1 -1
  455. package/dist/types/core/sorting.d.ts +1 -1
  456. package/dist/types/full/index.d.ts +20 -18
  457. package/dist/types/full/ndarray.d.ts +16 -22
  458. package/dist/types/index.d.ts +18 -3
  459. package/dist/types/io/file-ops.d.ts +269 -0
  460. package/dist/types/io/filesystem.d.ts +21 -0
  461. package/dist/types/io/zip/types.d.ts +2 -1
  462. package/dist/types/node.d.ts +3 -275
  463. package/package.json +54 -35
  464. package/dist/numpy-ts.node-io.cjs +0 -8
  465. package/dist/numpy-ts.node-io.cjs.map +0 -7
  466. package/dist/numpy-ts.node-io.mjs +0 -8
  467. package/dist/numpy-ts.node-io.mjs.map +0 -7
  468. package/dist/numpy-ts.node.cjs +0 -8
  469. package/dist/numpy-ts.node.cjs.map +0 -7
package/README.md CHANGED
@@ -19,10 +19,11 @@
19
19
  Complete NumPy implementation for TypeScript and JavaScript.
20
20
 
21
21
  - **📊 Extensive API** — **476 of 507 NumPy functions (93.9% coverage)**
22
- - **✅ NumPy-validated** — 6,000+ tests compared against Python NumPy
22
+ - **✅ NumPy-validated** — 10,000+ tests compared against Python NumPy
23
23
  - **🔒 Type-safe** — Full TypeScript type definitions
24
- - **🌳 Tree-shakeable** — Import only what you use
25
- - **🌐 Universal** — Works in Node.js and browsers
24
+ - **🌳 Tree-shakeable** — Import only what you use (`np.add()` -> ~10kB bundle)
25
+ - **🌐 Universal** — Works in Node.js, Deno, Bun and browsers
26
+ - **🏃🏽‍♂️ Fast** - Competitive with Python NumPy ([and sometimes faster](https://numpyts.dev/performance)) thanks to Zig-WASM kernels
26
27
 
27
28
  [Docs](https://numpyts.dev) • [Examples](https://numpyts.dev/examples) • [Benchmarks](https://numpyts.dev/performance)
28
29
 
@@ -1 +1 @@
1
- import{ArrayStorage as d}from"./storage";function c(r){if(r.length===0)return[];if(r.length===1)return Array.from(r[0]);const n=Math.max(...r.map(t=>t.length)),e=new Array(n);for(let t=0;t<n;t++){let o=1;for(const i of r){const a=i.length-n+t,s=a<0?1:i[a];if(s!==1){if(o===1)o=s;else if(o!==s)return null}}e[t]=o}return e}function h(r,n){return c([Array.from(r),Array.from(n)])!==null}function m(r,n,e){const t=r.length,o=e.length,i=new Array(o).fill(0);for(let a=0;a<t;a++){const s=o-t+a,l=r[a],u=e[s];if(l===u)i[s]=n[a];else if(l===1)i[s]=0;else throw new Error("Invalid broadcast")}return i}function f(r,n){const e=m(r.shape,r.strides,n);return d.fromData(r.data,Array.from(n),r.dtype,e,r.offset)}function p(r){if(r.length===0)return[];if(r.length===1)return r;const n=r.map(t=>Array.from(t.shape)),e=c(n);if(e===null)throw new Error(`operands could not be broadcast together with shapes ${n.map(t=>JSON.stringify(t)).join(" ")}`);return r.map(t=>f(t,e))}function y(...r){const n=c(r);if(n===null){const e=r.map(t=>`(${t.join(",")})`).join(" ");throw new Error(`shape mismatch: objects cannot be broadcast to a single shape. Mismatch is between ${e}`)}return n}function g(r,n){const e=n?` for ${n}`:"",t=r.map(o=>`(${o.join(",")})`).join(" ");return`operands could not be broadcast together${e} with shapes ${t}`}export{h as areBroadcastable,p as broadcastArrays,g as broadcastErrorMessage,y as broadcastShapes,f as broadcastTo,c as computeBroadcastShape};
1
+ import{ArrayStorage as d}from"./storage.js";function c(r){if(r.length===0)return[];if(r.length===1)return Array.from(r[0]);const n=Math.max(...r.map(t=>t.length)),e=new Array(n);for(let t=0;t<n;t++){let o=1;for(const i of r){const a=i.length-n+t,s=a<0?1:i[a];if(s!==1){if(o===1)o=s;else if(o!==s)return null}}e[t]=o}return e}function h(r,n){return c([Array.from(r),Array.from(n)])!==null}function m(r,n,e){const t=r.length,o=e.length,i=new Array(o).fill(0);for(let a=0;a<t;a++){const s=o-t+a,l=r[a],u=e[s];if(l===u)i[s]=n[a];else if(l===1)i[s]=0;else throw new Error("Invalid broadcast")}return i}function f(r,n){const e=m(r.shape,r.strides,n);return d.fromData(r.data,Array.from(n),r.dtype,e,r.offset)}function p(r){if(r.length===0)return[];if(r.length===1)return r;const n=r.map(t=>Array.from(t.shape)),e=c(n);if(e===null)throw new Error(`operands could not be broadcast together with shapes ${n.map(t=>JSON.stringify(t)).join(" ")}`);return r.map(t=>f(t,e))}function y(...r){const n=c(r);if(n===null){const e=r.map(t=>`(${t.join(",")})`).join(" ");throw new Error(`shape mismatch: objects cannot be broadcast to a single shape. Mismatch is between ${e}`)}return n}function g(r,n){const e=n?` for ${n}`:"",t=r.map(o=>`(${o.join(",")})`).join(" ");return`operands could not be broadcast together${e} with shapes ${t}`}export{h as areBroadcastable,p as broadcastArrays,g as broadcastErrorMessage,y as broadcastShapes,f as broadcastTo,c as computeBroadcastShape};
@@ -1 +1 @@
1
- const x="float64";function A(r){switch(r){case"float64":return Float64Array;case"float32":return Float32Array;case"complex128":return Float64Array;case"complex64":return Float32Array;case"int64":return BigInt64Array;case"int32":return Int32Array;case"int16":return Int16Array;case"int8":return Int8Array;case"uint64":return BigUint64Array;case"uint32":return Uint32Array;case"uint16":return Uint16Array;case"uint8":return Uint8Array;case"bool":return Uint8Array;default:throw new Error(`Unknown dtype: ${r}`)}}function D(r){switch(r){case"complex128":return 16;case"float64":case"int64":case"uint64":case"complex64":return 8;case"float32":case"int32":case"uint32":return 4;case"int16":case"uint16":return 2;case"int8":case"uint8":case"bool":return 1;default:throw new Error(`Unknown dtype: ${r}`)}}function y(r){return r==="int64"||r==="int32"||r==="int16"||r==="int8"||r==="uint64"||r==="uint32"||r==="uint16"||r==="uint8"}function p(r){return r==="float64"||r==="float32"}function m(r){return r==="int64"||r==="uint64"}function e(r){return r==="complex64"||r==="complex128"}function b(r,t,u){if(e(r)){const f=u?` ${u}`:"";throw new TypeError(`ufunc '${t}' not supported for complex dtype '${r}'.${f}`)}}function g(r,t){if(e(r))throw new Error(`'${t}' does not yet support complex dtype '${r}'. Complex support is planned but not yet implemented.`)}function C(r){if(r==="complex128")return"float64";if(r==="complex64")return"float32";throw new Error(`${r} is not a complex dtype`)}function w(r){if(r==="float64")return"complex128";if(r==="float32")return"complex64";throw new Error(`${r} is not a valid complex component dtype`)}function T(r){return typeof r=="object"&&r!==null&&"re"in r&&"im"in r}function I(r){return typeof r=="bigint"?"int64":typeof r=="number"?Number.isInteger(r)?r>=0&&r<=255?"uint8":r>=-128&&r<=127?"int8":r>=0&&r<=65535?"uint16":r>=-32768&&r<=32767?"int16":r>=0&&r<=4294967295?"uint32":r>=-2147483648&&r<=2147483647?"int32":"float64":"float64":typeof r=="boolean"?"bool":T(r)?"complex128":x}function U(r,t){if(r===t)return r;if(r==="bool")return t;if(t==="bool")return r;if(e(r)||e(t)){if(e(r)&&e(t))return r==="complex128"||t==="complex128"?"complex128":"complex64";const n=e(r)?r:t,a=e(r)?t:r;return n==="complex128"||a==="float64"||a==="int64"||a==="uint64"||a==="int32"||a==="uint32"?"complex128":"complex64"}if(p(r)||p(t)){if(r==="float64"||t==="float64")return"float64";if(r==="float32"){const n=t;return n==="int32"||n==="int64"||n==="uint32"||n==="uint64"?"float64":"float32"}if(t==="float32"){const n=r;return n==="int32"||n==="int64"||n==="uint32"||n==="uint64"?"float64":"float32"}return"float32"}const u=r.startsWith("int"),f=t.startsWith("int"),c=r.startsWith("uint"),s=t.startsWith("uint"),l=n=>n.includes("64")?64:n.includes("32")?32:n.includes("16")?16:n.includes("8")?8:0,i=l(r),o=l(t);if(r==="int64"&&t==="uint64"||r==="uint64"&&t==="int64")return"float64";if(u&&s&&i===o){if(i===8)return"int16";if(i===16)return"int32";if(i===32)return"int64"}if(c&&f&&i===o){if(o===8)return"int16";if(o===16)return"int32";if(o===32)return"int64"}if(u&&f||c&&s){const n=Math.max(i,o);return u?n===64?"int64":n===32?"int32":n===16?"int16":"int8":n===64?"uint64":n===32?"uint32":n===16?"uint16":"uint8"}return u&&s?i>o?r:o===8?"int16":o===16?"int32":o===32?"int64":"float64":c&&f?o>i?t:i===8?"int16":i===16?"int32":i===32?"int64":"float64":"float64"}function h(r){return["float64","float32","complex128","complex64","int64","int32","int16","int8","uint64","uint32","uint16","uint8","bool"].includes(r)}function F(r,t){return m(t)?BigInt(r):t==="bool"?r?1:0:Number(r)}function $(r){return r==="int64"||r==="uint64"||e(r)?"generic":r}export{x as DEFAULT_DTYPE,F as castValue,C as getComplexComponentDType,w as getComplexDType,D as getDTypeSize,A as getTypedArrayConstructor,I as inferDType,m as isBigIntDType,e as isComplexDType,T as isComplexLike,p as isFloatDType,y as isIntegerDType,h as isValidDType,U as promoteDTypes,b as throwIfComplex,g as throwIfComplexNotImplemented,$ as toStdlibDType};
1
+ const p=typeof globalThis.Float16Array<"u",m="float64";function D(r){switch(r){case"float64":return Float64Array;case"float32":return Float32Array;case"float16":return p?Float16Array:Float32Array;case"complex128":return Float64Array;case"complex64":return Float32Array;case"int64":return BigInt64Array;case"int32":return Int32Array;case"int16":return Int16Array;case"int8":return Int8Array;case"uint64":return BigUint64Array;case"uint32":return Uint32Array;case"uint16":return Uint16Array;case"uint8":return Uint8Array;case"bool":return Uint8Array;default:throw new Error(`Unknown dtype: ${r}`)}}function b(r){switch(r){case"complex128":return 16;case"float64":case"int64":case"uint64":case"complex64":return 8;case"float32":case"int32":case"uint32":return 4;case"float16":case"int16":case"uint16":return 2;case"int8":case"uint8":case"bool":return 1;default:throw new Error(`Unknown dtype: ${r}`)}}function g(r){return r==="int64"||r==="int32"||r==="int16"||r==="int8"||r==="uint64"||r==="uint32"||r==="uint16"||r==="uint8"}function x(r){return r==="float64"||r==="float32"||r==="float16"}function A(r){return r==="int64"||r==="uint64"}function e(r){return r==="complex64"||r==="complex128"}function y(r,t,u){if(e(r)){const f=u?` ${u}`:"";throw new TypeError(`ufunc '${t}' not supported for complex dtype '${r}'.${f}`)}}function C(r,t){if(e(r))throw new Error(`'${t}' does not yet support complex dtype '${r}'. Complex support is planned but not yet implemented.`)}function w(r){if(r==="complex128")return"float64";if(r==="complex64")return"float32";throw new Error(`${r} is not a complex dtype`)}function h(r){if(r==="float64")return"complex128";if(r==="float32")return"complex64";throw new Error(`${r} is not a valid complex component dtype`)}function T(r){return typeof r=="object"&&r!==null&&"re"in r&&"im"in r}function I(r){return typeof r=="bigint"?"int64":typeof r=="number"?Number.isInteger(r)?r>=0&&r<=255?"uint8":r>=-128&&r<=127?"int8":r>=0&&r<=65535?"uint16":r>=-32768&&r<=32767?"int16":r>=0&&r<=4294967295?"uint32":r>=-2147483648&&r<=2147483647?"int32":"float64":"float64":typeof r=="boolean"?"bool":T(r)?"complex128":m}function U(r,t){if(r===t)return r;if(r==="bool")return t;if(t==="bool")return r;if(e(r)||e(t)){if(e(r)&&e(t))return r==="complex128"||t==="complex128"?"complex128":"complex64";const n=e(r)?r:t,a=e(r)?t:r;return n==="complex128"||a==="float64"||a==="int64"||a==="uint64"||a==="int32"||a==="uint32"?"complex128":"complex64"}if(x(r)||x(t)){if(r==="float64"||t==="float64")return"float64";if(r==="float32"||t==="float32"){const n=r==="float32"?t:r;return n==="int32"||n==="int64"||n==="uint32"||n==="uint64"?"float64":"float32"}if(r==="float16"||t==="float16"){const n=r==="float16"?t:r;return n==="float16"||n==="int8"||n==="uint8"?"float16":n==="int16"||n==="uint16"?"float32":"float64"}return"float32"}const u=r.startsWith("int"),f=t.startsWith("int"),l=r.startsWith("uint"),c=t.startsWith("uint"),s=n=>n.includes("64")?64:n.includes("32")?32:n.includes("16")?16:n.includes("8")?8:0,i=s(r),o=s(t);if(r==="int64"&&t==="uint64"||r==="uint64"&&t==="int64")return"float64";if(u&&c&&i===o){if(i===8)return"int16";if(i===16)return"int32";if(i===32)return"int64"}if(l&&f&&i===o){if(o===8)return"int16";if(o===16)return"int32";if(o===32)return"int64"}if(u&&f||l&&c){const n=Math.max(i,o);return u?n===64?"int64":n===32?"int32":n===16?"int16":"int8":n===64?"uint64":n===32?"uint32":n===16?"uint16":"uint8"}return u&&c?i>o?r:o===8?"int16":o===16?"int32":o===32?"int64":"float64":l&&f?o>i?t:i===8?"int16":i===16?"int32":i===32?"int64":"float64":"float64"}function F(r){return["float64","float32","float16","complex128","complex64","int64","int32","int16","int8","uint64","uint32","uint16","uint8","bool"].includes(r)}function $(r,t){return A(t)?BigInt(r):t==="bool"?r?1:0:Number(r)}function B(r){return r==="int64"||r==="uint64"||r==="float16"||e(r)?"generic":r}export{m as DEFAULT_DTYPE,$ as castValue,w as getComplexComponentDType,h as getComplexDType,b as getDTypeSize,D as getTypedArrayConstructor,p as hasFloat16,I as inferDType,A as isBigIntDType,e as isComplexDType,T as isComplexLike,x as isFloatDType,g as isIntegerDType,F as isValidDType,U as promoteDTypes,y as throwIfComplex,C as throwIfComplexNotImplemented,B as toStdlibDType};
@@ -0,0 +1 @@
1
+ const x=new ArrayBuffer(4),l=new DataView(x);function c(s){const i=s>>>15&1,o=s>>>10&31,n=s&1023;let t;return o===0?t=n===0?0:n*2**-24:o===31?t=n===0?1/0:NaN:t=(n/1024+1)*2**(o-15),i?-t:t}function m(s){l.setFloat32(0,s,!1);const i=l.getUint32(0,!1),o=i>>>31&1,n=i>>>23&255,t=i&8388607;let f,e;if(n===255)f=31,e=t===0?0:512;else if(n>142)f=31,e=0;else if(n<103)f=0,e=0;else if(n<113){f=0;const r=125-n;e=(8388608|t)>>>r;const a=(8388608|t)&(1<<r)-1,u=1<<r-1;(a>u||a===u&&(e&1)!==0)&&e++}else{f=n-112,e=t>>>13;const r=t&8191;(r>4096||r===4096&&(e&1)!==0)&&(e++,e>1023&&(e=0,f++,f>30&&(f=31,e=0)))}return o<<15|f<<10|e}function b(s,i,o,n){const t=new DataView(s,i),f=new Float32Array(o);for(let e=0;e<o;e++){let r;r=t.getUint16(e*2,!0),f[e]=c(r)}return f}export{c as float16BitsToNumber,b as float16BytesToTypedArray,m as numberToFloat16Bits};
@@ -1 +1 @@
1
- import{ArrayStorage as B}from"../storage";import{promoteDTypes as C,isBigIntDType as h}from"../dtype";import{Complex as I}from"../complex";function z(t,r){const l=t.length,o=r.length,c=Math.max(l,o),s=new Array(c);for(let a=0;a<c;a++){const d=a<c-l?1:t[a-(c-l)],m=a<c-o?1:r[a-(c-o)];if(d===m)s[a]=d;else if(d===1)s[a]=m;else if(m===1)s[a]=d;else throw new Error(`operands could not be broadcast together with shapes ${JSON.stringify(Array.from(t))} ${JSON.stringify(Array.from(r))}`)}return s}function x(t,r,l){const o=t.length,c=l.length,s=new Array(c).fill(0);for(let a=0;a<o;a++){const d=c-o+a,m=t[a],u=l[d];if(m===u)s[d]=r[a];else if(m===1)s[d]=0;else throw new Error("Invalid broadcast")}return s}function D(t,r){const l=x(t.shape,t.strides,r);return B.fromData(t.data,Array.from(r),t.dtype,l,t.offset)}function M(t,r,l,o){const c=C(t.dtype,r.dtype),s=t.shape,a=r.shape;if(s.length===a.length&&s.every((n,i)=>n===a[i])&&t.isCContiguous&&r.isCContiguous&&!h(t.dtype)&&!h(r.dtype)&&!h(c)){const n=t.size,i=B.zeros(Array.from(s),c),g=i.data,p=t.data,S=r.data,N=t.offset,w=r.offset;if(N===0&&w===0)for(let f=0;f<n;f++)g[f]=l(p[f],S[f]);else for(let f=0;f<n;f++)g[f]=l(p[N+f],S[w+f]);return i}const m=z(t.shape,r.shape),u=D(t,m),y=D(r,m),b=B.zeros(m,c),A=b.data,e=b.size;if(h(c)){const n=A;for(let i=0;i<e;i++){const g=u.iget(i),p=y.iget(i),S=g instanceof I?g.re:g,N=p instanceof I?p.re:p,w=typeof S=="bigint"?S:BigInt(Math.round(S)),f=typeof N=="bigint"?N:BigInt(Math.round(N));o==="add"?n[i]=w+f:o==="subtract"?n[i]=w-f:o==="multiply"?n[i]=w*f:o==="divide"?n[i]=w/f:n[i]=BigInt(Math.round(l(Number(w),Number(f))))}}else{const n=h(t.dtype)||h(r.dtype);for(let i=0;i<e;i++){const g=u.iget(i),p=y.iget(i),S=Number(g),N=Number(p);A[i]=l(S,N)}}return b}function R(t,r,l){const o=z(t.shape,r.shape),c=D(t,o),s=D(r,o),a=o.reduce((u,y)=>u*y,1),d=new Uint8Array(a),m=h(t.dtype)||h(r.dtype);for(let u=0;u<a;u++){const y=c.iget(u),b=s.iget(u),A=Number(y),e=Number(b);d[u]=l(A,e)?1:0}return B.fromData(d,o,"bool")}function V(t,r,l=!0){const o=t.dtype,c=Array.from(t.shape),s=t.size,d=l?o:o!=="float32"&&o!=="float64"?"float64":o,m=B.zeros(c,d),u=m.data,y=t.data,b=t.offset,A=t.isCContiguous;if(h(o))if(h(d)){const e=u;if(A)for(let n=0;n<s;n++){const i=Number(y[b+n]);e[n]=BigInt(Math.round(r(i)))}else for(let n=0;n<s;n++)e[n]=BigInt(Math.round(r(Number(t.iget(n)))))}else if(A)for(let e=0;e<s;e++)u[e]=r(Number(y[b+e]));else for(let e=0;e<s;e++)u[e]=r(Number(t.iget(e)));else if(A)if(b===0)for(let e=0;e<s;e++)u[e]=r(Number(y[e]));else for(let e=0;e<s;e++)u[e]=r(Number(y[b+e]));else for(let e=0;e<s;e++)u[e]=r(Number(t.iget(e)));return m}export{z as broadcastShapes,M as elementwiseBinaryOp,R as elementwiseComparisonOp,V as elementwiseUnaryOp};
1
+ import{ArrayStorage as B}from"../storage.js";import{promoteDTypes as C,isBigIntDType as h}from"../dtype.js";import{Complex as I}from"../complex.js";function z(t,r){const l=t.length,n=r.length,c=Math.max(l,n),s=new Array(c);for(let a=0;a<c;a++){const d=a<c-l?1:t[a-(c-l)],m=a<c-n?1:r[a-(c-n)];if(d===m)s[a]=d;else if(d===1)s[a]=m;else if(m===1)s[a]=d;else throw new Error(`operands could not be broadcast together with shapes ${JSON.stringify(Array.from(t))} ${JSON.stringify(Array.from(r))}`)}return s}function x(t,r,l){const n=t.length,c=l.length,s=new Array(c).fill(0);for(let a=0;a<n;a++){const d=c-n+a,m=t[a],u=l[d];if(m===u)s[d]=r[a];else if(m===1)s[d]=0;else throw new Error("Invalid broadcast")}return s}function D(t,r){const l=x(t.shape,t.strides,r);return B.fromData(t.data,Array.from(r),t.dtype,l,t.offset)}function M(t,r,l,n){const c=C(t.dtype,r.dtype),s=t.shape,a=r.shape;if(s.length===a.length&&s.every((o,i)=>o===a[i])&&t.isCContiguous&&r.isCContiguous&&!h(t.dtype)&&!h(r.dtype)&&!h(c)){const o=t.size,i=B.zeros(Array.from(s),c),g=i.data,p=t.offset,S=r.offset,N=t.data,w=r.data;if(p===0&&S===0)for(let f=0;f<o;f++)g[f]=l(N[f],w[f]);else for(let f=0;f<o;f++)g[f]=l(N[p+f],w[S+f]);return i}const m=z(t.shape,r.shape),u=D(t,m),y=D(r,m),b=B.zeros(m,c),A=b.data,e=b.size;if(h(c)){const o=A;for(let i=0;i<e;i++){const g=u.iget(i),p=y.iget(i),S=g instanceof I?g.re:g,N=p instanceof I?p.re:p,w=typeof S=="bigint"?S:BigInt(Math.round(S)),f=typeof N=="bigint"?N:BigInt(Math.round(N));n==="add"?o[i]=w+f:n==="subtract"?o[i]=w-f:n==="multiply"?o[i]=w*f:n==="divide"?o[i]=w/f:o[i]=BigInt(Math.round(l(Number(w),Number(f))))}}else{const o=h(t.dtype)||h(r.dtype);for(let i=0;i<e;i++){const g=u.iget(i),p=y.iget(i),S=Number(g),N=Number(p);A[i]=l(S,N)}}return b}function R(t,r,l){const n=z(t.shape,r.shape),c=D(t,n),s=D(r,n),a=n.reduce((u,y)=>u*y,1),d=new Uint8Array(a),m=h(t.dtype)||h(r.dtype);for(let u=0;u<a;u++){const y=c.iget(u),b=s.iget(u),A=Number(y),e=Number(b);d[u]=l(A,e)?1:0}return B.fromData(d,n,"bool")}function V(t,r,l=!0){const n=t.dtype,c=Array.from(t.shape),s=t.size,d=l?n:n!=="float16"&&n!=="float32"&&n!=="float64"?"float64":n,m=B.zeros(c,d),u=m.data,y=t.data,b=t.offset,A=t.isCContiguous;if(h(n))if(h(d)){const e=u;if(A)for(let o=0;o<s;o++){const i=Number(y[b+o]);e[o]=BigInt(Math.round(r(i)))}else for(let o=0;o<s;o++)e[o]=BigInt(Math.round(r(Number(t.iget(o)))))}else if(A)for(let e=0;e<s;e++)u[e]=r(Number(y[b+e]));else for(let e=0;e<s;e++)u[e]=r(Number(t.iget(e)));else if(A)if(b===0)for(let e=0;e<s;e++)u[e]=r(Number(y[e]));else for(let e=0;e<s;e++)u[e]=r(Number(y[b+e]));else for(let e=0;e<s;e++)u[e]=r(Number(t.iget(e)));return m}export{z as broadcastShapes,M as elementwiseBinaryOp,R as elementwiseComparisonOp,V as elementwiseUnaryOp};
@@ -1 +1 @@
1
- function d(r){const t=new Array(r.length);let u=1;for(let e=r.length-1;e>=0;e--)t[e]=u,u*=r[e];return t}function f(r,t){let u=0,e=1;for(let n=r.length-1;n>=0;n--)u+=r[n]*e,e*=t[n];return u}function c(r,t,u){let e=u;for(let n=0;n<r.length;n++)e+=r[n]*t[n];return e}function x(r,t,u,e){const n=e.length,l=new Array(n),m=Array.from(e).filter((o,b)=>b!==t);let i=r;for(let o=m.length-1;o>=0;o--)l[o>=t?o+1:o]=i%m[o],i=Math.floor(i/m[o]);return l[t]=u,l}export{d as computeStrides,c as multiIndexToBuffer,f as multiIndexToLinear,x as outerIndexToMultiIndex};
1
+ function g(t){const u=new Array(t.length);let o=1;for(let n=t.length-1;n>=0;n--)u[n]=o,o*=t[n];return u}function A(t,u,o,n,m){const y=t.length,x=u[n],c=[],d=[];for(let r=0;r<y;r++)r!==n&&(c.push(t[r]),d.push(u[r]));const l=new Int32Array(m),s=c.length;if(s===0)l[0]=o;else if(s===1){const r=d[0];for(let e=0;e<m;e++)l[e]=o+e*r}else{const r=new Int32Array(s);r[s-1]=1;for(let e=s-2;e>=0;e--)r[e]=r[e+1]*c[e+1];for(let e=0;e<m;e++){let b=o,f=e;for(let i=0;i<s;i++){const a=f/r[i]|0;f-=a*r[i],b+=a*d[i]}l[e]=b}}return{baseOffsets:l,axisStride:x}}export{g as computeStrides,A as precomputeAxisOffsets};
@@ -1 +1 @@
1
- import{parseSlice as c,normalizeSlice as d}from"./slicing";import{getTypedArrayConstructor as m,getDTypeSize as b,isBigIntDType as y,isComplexDType as A}from"./dtype";import{Complex as f}from"./complex";import{ArrayStorage as p}from"./storage";import{array_str as _}from"./ops/formatting";class l{constructor(t,r){this._storage=t,this._base=r}get storage(){return this._storage}static fromStorage(t,r){return new l(t,r)}get shape(){return this._storage.shape}get ndim(){return this._storage.ndim}get size(){return this._storage.size}get dtype(){return this._storage.dtype}get data(){return this._storage.data}get strides(){return this._storage.strides}get flags(){return{C_CONTIGUOUS:this._storage.isCContiguous,F_CONTIGUOUS:this._storage.isFContiguous,OWNDATA:this._base===void 0}}get base(){return this._base??null}get itemsize(){return b(this._storage.dtype)}get nbytes(){return this.size*this.itemsize}fill(t){const r=this._storage.dtype,i=this.size;if(y(r)){const n=typeof t=="bigint"?t:BigInt(Math.round(Number(t)));for(let e=0;e<i;e++)this._storage.iset(e,n)}else if(r==="bool"){const n=t?1:0;for(let e=0;e<i;e++)this._storage.iset(e,n)}else{const n=Number(t);for(let e=0;e<i;e++)this._storage.iset(e,n)}}*[Symbol.iterator](){if(this.ndim===0)yield this._storage.iget(0);else if(this.ndim===1)for(let t=0;t<this.shape[0];t++)yield this._storage.iget(t);else for(let t=0;t<this.shape[0];t++)yield this.slice(String(t))}get(t){if(t.length!==this.ndim)throw new Error(`Index has ${t.length} dimensions, but array has ${this.ndim} dimensions`);const r=t.map((i,n)=>{let e=i;if(e<0&&(e=this.shape[n]+e),e<0||e>=this.shape[n])throw new Error(`Index ${i} is out of bounds for axis ${n} with size ${this.shape[n]}`);return e});return this._storage.get(...r)}set(t,r){if(t.length!==this.ndim)throw new Error(`Index has ${t.length} dimensions, but array has ${this.ndim} dimensions`);const i=t.map((e,a)=>{let o=e;if(o<0&&(o=this.shape[a]+o),o<0||o>=this.shape[a])throw new Error(`Index ${e} is out of bounds for axis ${a} with size ${this.shape[a]}`);return o}),n=this.dtype;if(A(n))this._storage.set(i,r);else if(y(n)){const e=r instanceof f?r.re:Number(r),a=typeof r=="bigint"?r:BigInt(Math.round(e));this._storage.set(i,a)}else if(n==="bool"){const a=(r instanceof f?r.re:Number(r))?1:0;this._storage.set(i,a)}else{const e=r instanceof f?r.re:Number(r);this._storage.set(i,e)}}iget(t){return this._storage.iget(t)}iset(t,r){this._storage.iset(t,r)}copy(){return new l(this._storage.copy())}astype(t,r=!0){const i=this.dtype;if(i===t&&!r)return this;if(i===t&&r)return this.copy();const n=Array.from(this.shape),e=this.size,a=m(t);if(!a)throw new Error(`Cannot convert to dtype ${t}`);const o=new a(e),g=this.data;if(y(i)&&!y(t)){const h=g;if(t==="bool")for(let s=0;s<e;s++)o[s]=h[s]!==BigInt(0)?1:0;else for(let s=0;s<e;s++)o[s]=Number(h[s])}else if(!y(i)&&y(t)){const h=g;for(let s=0;s<e;s++)o[s]=BigInt(Math.round(Number(h[s])))}else if(t==="bool"){const h=g;for(let s=0;s<e;s++)o[s]=h[s]!==0?1:0}else if(i==="bool"&&!y(t)){const h=g;for(let s=0;s<e;s++)o[s]=h[s]}else if(!y(i)&&!y(t)){const h=g;for(let s=0;s<e;s++)o[s]=h[s]}else{const h=g;for(let s=0;s<e;s++)o[s]=h[s]}const u=p.fromData(o,n,t);return new l(u)}slice(...t){if(t.length===0)return this;if(t.length>this.ndim)throw new Error(`Too many indices for array: array is ${this.ndim}-dimensional, but ${t.length} were indexed`);const r=t.map((g,u)=>{const h=c(g);return d(h,this.shape[u])});for(;r.length<this.ndim;)r.push({start:0,stop:this.shape[r.length],step:1,isIndex:!1});const i=[],n=[];let e=this._storage.offset;for(let g=0;g<r.length;g++){const u=r[g];if(e+=u.start*this._storage.strides[g],u.step===0)continue;const h=Math.max(0,Math.ceil((u.stop-u.start)/u.step));i.push(h),n.push(this._storage.strides[g]*u.step)}const a=p.fromData(this._storage.data,i,this._storage.dtype,n,e),o=this._base??this;return new l(a,o)}toString(){return _(this._storage)}toArray(){if(this.ndim===0)return this._storage.iget(0);const t=this.shape,r=t.length,i=(n,e)=>{if(e===r)return this._storage.get(...n);const a=[];for(let o=0;o<t[e];o++)n[e]=o,a.push(i(n,e+1));return a};return i(new Array(r),0)}tolist(){return this.toArray()}tobytes(){if(this._storage.isCContiguous){const i=this._storage.data,n=i.BYTES_PER_ELEMENT,e=this._storage.offset*n,a=this.size*n;return i.buffer.slice(e,e+a)}const r=this.copy()._storage.data;return r.buffer.slice(0,this.size*r.BYTES_PER_ELEMENT)}item(...t){if(t.length===0){if(this.size!==1)throw new Error("can only convert an array of size 1 to a Python scalar");return this._storage.iget(0)}if(t.length===1){const r=t[0];if(r<0||r>=this.size)throw new Error(`index ${r} is out of bounds for size ${this.size}`);return this._storage.iget(r)}return this.get(t)}}export{l as NDArrayCore};
1
+ import*as z from"./ops/shape.js";import{getTypedArrayConstructor as D,getDTypeSize as E,isBigIntDType as c,isComplexDType as w,isFloatDType as N}from"./dtype.js";import{Complex as I}from"./complex.js";import{ArrayStorage as B}from"./storage.js";import{array_str as U}from"./ops/formatting.js";const T=2**63,x={int8:-1,int16:-1,uint8:255,uint16:65535},S={int8:0,int16:0,uint8:0,uint16:0},C={int32:[-2147483648,2147483647],uint32:[0,4294967295]};function O(u,t){if(isNaN(u))return 0;if(t in x)return u>=T||u===1/0?x[t]:u<=-T||u===-1/0?S[t]:Math.trunc(u);if(t in C){const[e,n]=C[t];return u>=n||u===1/0?n:u<=e||u===-1/0?e:Math.trunc(u)}return Math.trunc(u)}class d{static{this._proxyHandler={get(t,e,n){if(typeof e=="string"){const i=parseInt(e,10);if(!isNaN(i)&&String(i)===e){const r=t._storage.ndim>0?t._storage.shape[0]:1,a=i<0?r+i:i;return t._storage.ndim<=1?t._storage.iget(a):t.slice(e)}}return Reflect.get(t,e,n)},set(t,e,n,i){if(typeof e=="string"){const r=parseInt(e,10);if(!isNaN(r)&&String(r)===e){const a=t._storage.shape[0],l=r<0?a+r:r;if(t._storage.ndim===1)return t.set([l],n),!0;const m=t.slice(String(r)),f=m.size;if(typeof n=="number"||typeof n=="bigint")m.fill(n);else if(n instanceof I)for(let h=0;h<f;h++)m._storage.iset(h,n);else if(n instanceof d){if(n.size!==f)throw new Error(`Cannot assign array of size ${n.size} into slice of size ${f}`);for(let h=0;h<f;h++)m._storage.iset(h,n._storage.iget(h))}else if(Array.isArray(n)){const h=n.flat(1/0);if(h.length!==f)throw new Error(`Cannot assign array of length ${h.length} into slice of size ${f}`);for(let p=0;p<f;p++)m._storage.iset(p,h[p])}else throw new Error(`Cannot assign value of type ${typeof n} via bracket operator`);return!0}}return Reflect.set(t,e,n,i)}}}constructor(t,e){return this._storage=t,this._base=e,new Proxy(this,d._proxyHandler)}get storage(){return this._storage}static fromStorage(t,e){return new d(t,e)}get shape(){return this._storage.shape}get ndim(){return this._storage.ndim}get size(){return this._storage.size}get dtype(){return this._storage.dtype}get data(){return this._storage.data}get strides(){return this._storage.strides}get flags(){return{C_CONTIGUOUS:this._storage.isCContiguous,F_CONTIGUOUS:this._storage.isFContiguous,OWNDATA:this._base===void 0}}get base(){return this._base??null}get itemsize(){return E(this._storage.dtype)}get nbytes(){return this.size*this.itemsize}fill(t){const e=this._storage.dtype,n=this.size;if(c(e)){const i=typeof t=="bigint"?t:BigInt(Math.round(Number(t)));for(let r=0;r<n;r++)this._storage.iset(r,i)}else if(e==="bool"){const i=t?1:0;for(let r=0;r<n;r++)this._storage.iset(r,i)}else{const i=Number(t);for(let r=0;r<n;r++)this._storage.iset(r,i)}}*[Symbol.iterator](){if(this.ndim===0)yield this._storage.iget(0);else if(this.ndim===1)for(let t=0;t<this.shape[0];t++)yield this._storage.iget(t);else for(let t=0;t<this.shape[0];t++)yield this.slice(String(t))}get(t){if(t.length!==this.ndim)throw new Error(`Index has ${t.length} dimensions, but array has ${this.ndim} dimensions`);const e=t.map((n,i)=>{let r=n;if(r<0&&(r=this.shape[i]+r),r<0||r>=this.shape[i])throw new Error(`Index ${n} is out of bounds for axis ${i} with size ${this.shape[i]}`);return r});return this._storage.get(...e)}set(t,e){if(t.length!==this.ndim)throw new Error(`Index has ${t.length} dimensions, but array has ${this.ndim} dimensions`);const n=t.map((r,a)=>{let l=r;if(l<0&&(l=this.shape[a]+l),l<0||l>=this.shape[a])throw new Error(`Index ${r} is out of bounds for axis ${a} with size ${this.shape[a]}`);return l}),i=this.dtype;if(w(i))this._storage.set(n,e);else if(c(i)){const r=e instanceof I?e.re:Number(e),a=typeof e=="bigint"?e:BigInt(Math.round(r));this._storage.set(n,a)}else if(i==="bool"){const a=(e instanceof I?e.re:Number(e))?1:0;this._storage.set(n,a)}else{const r=e instanceof I?e.re:Number(e);this._storage.set(n,r)}}iget(t){return this._storage.iget(t)}iset(t,e){this._storage.iset(t,e)}copy(){return new d(this._storage.copy())}astype(t,e=!0){const n=this.dtype;if(n===t&&!e)return this;if(n===t&&e)return this.copy();const i=Array.from(this.shape),r=this.size,a=D(t);if(!a)throw new Error(`Cannot convert to dtype ${t}`);const l=w(n),m=w(t);if(l&&m){const o=new a(r*2),s=this.data,g=o;for(let b=0;b<r*2;b++)g[b]=s[b];const y=B.fromData(o,i,t);return new d(y)}if(!l&&m){const o=new a(r*2),s=o;for(let y=0;y<r;y++)s[y*2]=Number(this.data[y]),s[y*2+1]=0;const g=B.fromData(o,i,t);return new d(g)}if(l&&!m){const o=new a(r),s=this.data;if(c(t))for(let y=0;y<r;y++)o[y]=BigInt(Math.trunc(s[y*2]));else for(let y=0;y<r;y++)o[y]=s[y*2];const g=B.fromData(o,i,t);return new d(g)}const f=new a(r),h=this.data;if(c(n)&&!c(t)){const o=h;if(t==="bool")for(let s=0;s<r;s++)f[s]=o[s]!==BigInt(0)?1:0;else for(let s=0;s<r;s++)f[s]=Number(o[s])}else if(!c(n)&&c(t)){const o=h;if(N(n)){const g=t==="int64",y=BigInt(g?"9223372036854775807":"18446744073709551615"),b=g?BigInt("-9223372036854775808"):0n;for(let A=0;A<r;A++){const _=Number(o[A]);isNaN(_)?f[A]=0n:!isFinite(_)||_>=Number(y)?f[A]=_<0?b:y:_<=Number(b)?f[A]=b:f[A]=BigInt(Math.trunc(_))}}else for(let g=0;g<r;g++)f[g]=BigInt(Math.round(Number(o[g])))}else if(t==="bool"){const o=h;for(let s=0;s<r;s++)f[s]=o[s]!==0?1:0}else if(n==="bool"&&!c(t)){const o=h;for(let s=0;s<r;s++)f[s]=o[s]}else if(!c(n)&&!c(t)){const o=h;if(N(n)&&!N(t))for(let g=0;g<r;g++)f[g]=O(o[g],t);else for(let g=0;g<r;g++)f[g]=o[g]}else{const o=h;for(let s=0;s<r;s++)f[s]=o[s]}const p=B.fromData(f,i,t);return new d(p)}slice(...t){const e=z.slice(this._storage,...t);if(e===this._storage)return this;const n=this._base??this;return new this.constructor(e,n)}toString(){return U(this._storage)}toArray(){if(this.ndim===0)return this._storage.iget(0);const t=this.shape,e=t.length,n=(i,r)=>{if(r===e)return this._storage.get(...i);const a=[];for(let l=0;l<t[r];l++)i[r]=l,a.push(n(i,r+1));return a};return n(new Array(e),0)}tolist(){return this.toArray()}tobytes(){if(this._storage.isCContiguous){const n=this._storage.data,i=n.BYTES_PER_ELEMENT,r=this._storage.offset*i,a=this.size*i;return n.buffer.slice(r,r+a)}const e=this.copy()._storage.data;return e.buffer.slice(0,this.size*e.BYTES_PER_ELEMENT)}item(...t){if(t.length===0){if(this.size!==1)throw new Error("can only convert an array of size 1 to a Python scalar");return this._storage.iget(0)}if(t.length===1){const e=t[0];if(e<0||e>=this.size)throw new Error(`index ${e} is out of bounds for size ${this.size}`);return this._storage.iget(e)}return this.get(t)}}export{d as NDArrayCore};
@@ -1 +1 @@
1
- import{ArrayStorage as w,computeStrides as N}from"../storage";import{getTypedArrayConstructor as U,isBigIntDType as $}from"../dtype";import{computeBroadcastShape as j,broadcastTo as T,broadcastShapes as q}from"../broadcasting";import{Complex as O}from"../complex";function Y(r,t){const a=r.shape,s=a.length,i=t.length;if(i<s)throw new Error("input operand has more dimensions than allowed by the axis remapping");const o=j([Array.from(a),t]);if(o===null)throw new Error(`operands could not be broadcast together with shape (${a.join(",")}) (${t.join(",")})`);for(let e=0;e<i;e++)if(o[e]!==t[e])throw new Error(`operands could not be broadcast together with shape (${a.join(",")}) (${t.join(",")})`);return T(r,t)}function Z(r){if(r.length===0)return[];if(r.length===1)return[r[0]];const t=r.map(s=>Array.from(s.shape)),a=j(t);if(a===null)throw new Error(`operands could not be broadcast together with shapes ${t.map(s=>`(${s.join(",")})`).join(" ")}`);return r.map(s=>T(s,a))}function rr(r,t,a){const s=r.shape,i=s.length,o=r.dtype;if(a===void 0){const p=r.size;for(const B of t){const x=B<0?p+B:B;if(x<0||x>=p)throw new Error(`index ${B} is out of bounds for axis 0 with size ${p}`)}const g=t.length,A=U(o);if(!A)throw new Error(`Cannot take from array with dtype ${o}`);const I=new A(g);for(let B=0;B<g;B++){let x=t[B];x<0&&(x=p+x);const m=r.iget(x);$(o),I[B]=m}return w.fromData(I,[g],o)}const e=a<0?i+a:a;if(e<0||e>=i)throw new Error(`axis ${a} is out of bounds for array of dimension ${i}`);const n=s[e];for(const p of t){const g=p<0?n+p:p;if(g<0||g>=n)throw new Error(`index ${p} is out of bounds for axis ${e} with size ${n}`)}const u=Array.from(s);u[e]=t.length;const d=u.reduce((p,g)=>p*g,1),l=U(o);if(!l)throw new Error(`Cannot take from array with dtype ${o}`);const f=new l(d),c=N(u),y=new Array(i).fill(0);for(let p=0;p<d;p++){const g=[...y];let A=y[e],I=t[A];I<0&&(I=n+I),g[e]=I;const B=r.get(...g);let x=0;for(let m=0;m<i;m++)x+=y[m]*c[m];$(o),f[x]=B;for(let m=i-1;m>=0&&(y[m]++,!(y[m]<u[m]));m--)y[m]=0}return w.fromData(f,u,o)}function tr(r,t,a){const s=r.size,i=r.dtype;let o;if(typeof a=="number"||typeof a=="bigint")o=new Array(t.length).fill(a);else{o=[];for(let e=0;e<a.size;e++){const n=a.iget(e);o.push(n instanceof O?n.re:n)}if(o.length===1)o=new Array(t.length).fill(o[0]);else if(o.length!==t.length){const e=[...o];o=[];for(let n=0;n<t.length;n++)o.push(e[n%e.length])}}for(let e=0;e<t.length;e++){let n=t[e];if(n<0&&(n=s+n),n<0||n>=s)throw new Error(`index ${t[e]} is out of bounds for axis 0 with size ${s}`);let u=o[e];$(i)?typeof u!="bigint"&&(u=BigInt(Math.round(Number(u)))):typeof u=="bigint"&&(u=Number(u)),r.iset(n,u)}}function er(r,t){if(t.length===0)throw new Error("choices cannot be empty");const a=r.shape,s=t.length,i=t[0].dtype,o=t.map(c=>Array.from(c.shape));o.unshift(Array.from(a));const e=j(o);if(e===null)throw new Error("operands could not be broadcast together");const n=T(r,e),u=t.map(c=>T(c,e)),d=e.reduce((c,y)=>c*y,1),l=U(i);if(!l)throw new Error(`Cannot choose with dtype ${i}`);const f=new l(d);for(let c=0;c<d;c++){const y=Number(n.iget(c));if(y<0||y>=s)throw new Error(`index ${y} is out of bounds for axis 0 with size ${s}`);const p=u[y].iget(c);$(i),f[c]=p}return w.fromData(f,e,i)}function or(r,t,a=!1){if(r.ndim!==t.ndim)return!1;for(let i=0;i<r.ndim;i++)if(r.shape[i]!==t.shape[i])return!1;const s=r.size;for(let i=0;i<s;i++){const o=r.iget(i),e=t.iget(i);if(a){const n=typeof o=="number"&&Number.isNaN(o),u=typeof e=="number"&&Number.isNaN(e);if(n&&u)continue}if(o!==e)return!1}return!0}function nr(r,t,a){const s=r.shape,i=s.length,o=r.dtype,e=a<0?i+a:a;if(e<0||e>=i)throw new Error(`axis ${a} is out of bounds for array of dimension ${i}`);const n=t.shape;if(n.length!==i)throw new Error(`indices and arr must have the same number of dimensions, got ${n.length} vs ${i}`);for(let g=0;g<i;g++)if(g!==e&&n[g]!==s[g]&&n[g]!==1&&s[g]!==1)throw new Error(`index ${n[g]} is out of bounds for size ${s[g]} in dimension ${g}`);const u=Array.from(n),d=u.reduce((g,A)=>g*A,1),l=U(o);if(!l)throw new Error(`Cannot take_along_axis with dtype ${o}`);const f=new l(d),c=N(s),y=N(n),p=s[e];for(let g=0;g<d;g++){const A=new Array(i);let I=g;for(let b=i-1;b>=0;b--)A[b]=I%u[b],I=Math.floor(I/u[b]);let B=0;for(let b=0;b<i;b++){const h=n[b]===1?0:A[b];B+=h*y[b]}let x=Number(t.iget(B));if(x<0&&(x=p+x),x<0||x>=p)throw new Error(`index ${x} is out of bounds for axis ${e} with size ${p}`);const m=[...A];m[e]=x;let S=0;for(let b=0;b<i;b++){const h=s[b]===1?0:m[b];S+=h*c[b]}const z=r.iget(S);$(o),f[g]=z}return w.fromData(f,u,o)}function ir(r,t,a,s){const i=r.shape,o=i.length,e=r.dtype,n=s<0?o+s:s;if(n<0||n>=o)throw new Error(`axis ${s} is out of bounds for array of dimension ${o}`);const u=t.shape,d=a.shape;if(u.length!==o||d.length!==o)throw new Error("indices, arr, and values must have same ndim");const l=i[n],f=N(i),c=N(u),y=N(d),p=u.reduce((g,A)=>g*A,1);for(let g=0;g<p;g++){const A=new Array(o);let I=g;for(let h=o-1;h>=0;h--)A[h]=I%u[h],I=Math.floor(I/u[h]);let B=0;for(let h=0;h<o;h++)B+=A[h]*c[h];let x=Number(t.iget(B));if(x<0&&(x=l+x),x<0||x>=l)throw new Error(`index ${x} is out of bounds for axis ${n} with size ${l}`);let m=0;for(let h=0;h<o;h++){const C=d[h]===1?0:A[h];m+=C*y[h]}let S=a.iget(m);const z=[...A];z[n]=x;let b=0;for(let h=0;h<o;h++)b+=z[h]*f[h];$(e)?typeof S!="bigint"&&(S=BigInt(Math.round(Number(S)))):typeof S=="bigint"&&(S=Number(S)),r.iset(b,S)}}function ar(r,t,a){const s=r.size,i=r.dtype;let o;if(typeof a=="number"||typeof a=="bigint")o=[a];else{o=[];for(let n=0;n<a.size;n++){const u=a.iget(n);o.push(u instanceof O?u.re:u)}}let e=0;for(let n=0;n<s;n++)if(t.iget(n)){let d=o[e%o.length];$(i)?typeof d!="bigint"&&(d=BigInt(Math.round(Number(d)))):typeof d=="bigint"&&(d=Number(d)),r.iset(n,d),e++}}function sr(r,t,a){const s=t.shape,i=s.length,o=t.dtype,e=$(o);if(a===void 0){const m=Math.min(r.size,t.size),S=r.isCContiguous,z=r.data,b=r.offset;let h=0;if(S)for(let E=0;E<m;E++)z[b+E]&&h++;else for(let E=0;E<m;E++)r.iget(E)&&h++;const C=U(o);if(!C)throw new Error(`Cannot compress with dtype ${o}`);const _=new C(h);let D=0;const k=t.isCContiguous;if(S&&k){const E=t.data,V=t.offset;if(e){const L=_,F=E;for(let v=0;v<m;v++)z[b+v]&&(L[D++]=F[V+v])}else{const L=_,F=E;for(let v=0;v<m;v++)z[b+v]&&(L[D++]=F[V+v])}}else for(let E=0;E<m;E++)(S?z[b+E]:r.iget(E))&&(_[D]=t.iget(E),D++);return w.fromData(_,[h],o)}const n=a<0?i+a:a;if(n<0||n>=i)throw new Error(`axis ${a} is out of bounds for array of dimension ${i}`);const u=s[n],d=Math.min(r.size,u),l=[];for(let m=0;m<d;m++)r.iget(m)&&l.push(m);const f=l.length,c=[...s];c[n]=f;const y=c.reduce((m,S)=>m*S,1),p=U(o);if(!p)throw new Error(`Cannot compress with dtype ${o}`);const g=new p(y),A=s.slice(n+1).reduce((m,S)=>m*S,1),I=s.slice(0,n).reduce((m,S)=>m*S,1);let B=0;if(t.isCContiguous){const m=t.data,S=t.offset;if(e){const z=g,b=m;for(let h=0;h<I;h++)for(let C=0;C<f;C++){const _=l[C];for(let D=0;D<A;D++){const k=h*u*A+_*A+D;z[B++]=b[S+k]}}}else{const z=g,b=m;for(let h=0;h<I;h++)for(let C=0;C<f;C++){const _=l[C];for(let D=0;D<A;D++){const k=h*u*A+_*A+D;z[B++]=b[S+k]}}}}else for(let m=0;m<I;m++)for(let S=0;S<f;S++){const z=l[S];for(let b=0;b<A;b++){const h=m*u*A+z*A+b;g[B++]=t.iget(h)}}return w.fromData(g,c,o)}function ur(r,t,a=0){if(r.length!==t.length)throw new Error("condlist and choicelist must have same length");if(r.length===0)throw new Error("condlist and choicelist cannot be empty");const s=[...r.map(c=>Array.from(c.shape)),...t.map(c=>Array.from(c.shape))],i=j(s);if(i===null)throw new Error("condlist and choicelist arrays could not be broadcast together");const o=t[0].dtype,e=i.reduce((c,y)=>c*y,1),n=U(o);if(!n)throw new Error(`Cannot select with dtype ${o}`);let u=a;$(o)?u=typeof a=="bigint"?a:BigInt(a):u=typeof a=="bigint"?Number(a):a;const d=new n(e);for(let c=0;c<e;c++)$(o),d[c]=u;const l=r.map(c=>T(c,i)),f=t.map(c=>T(c,i));for(let c=0;c<e;c++)for(let y=0;y<r.length;y++)if(l[y].iget(c)){const p=f[y].iget(c);$(o),d[c]=p;break}return w.fromData(d,i,o)}function fr(r,t,a){const s=r.size,i=r.dtype,o=[];for(let n=0;n<a.size;n++){const u=a.iget(n);o.push(u instanceof O?u.re:u)}if(o.length===0)return;let e=0;for(let n=0;n<s;n++)if(t.iget(n)){let d=o[e%o.length];$(i)?typeof d!="bigint"&&(d=BigInt(Math.round(Number(d)))):typeof d=="bigint"&&(d=Number(d)),r.iset(n,d),e++}}function R(r,t=2){if(t<1)throw new Error("ndim must be at least 1");const a=new Int32Array(r);for(let i=0;i<r;i++)a[i]=i;const s=[];for(let i=0;i<t;i++)s.push(w.fromData(new Int32Array(a),[r],"int32"));return s}function lr(r){const t=r.shape,a=t.length;if(a<2)throw new Error("array must be at least 2-D");const s=t[0];for(let i=1;i<a;i++)if(t[i]!==s)throw new Error("All dimensions of input must be equal");return R(s,a)}function G(r,t=0,a){const s=a??r,i=[],o=[];for(let e=0;e<r;e++)for(let n=0;n<=Math.min(e+t,s-1);n++)n>=0&&(i.push(e),o.push(n));return[w.fromData(new Int32Array(i),[i.length],"int32"),w.fromData(new Int32Array(o),[o.length],"int32")]}function cr(r,t=0){const a=r.shape;if(a.length!==2)throw new Error("array must be 2-D");return G(a[0],t,a[1])}function H(r,t=0,a){const s=a??r,i=[],o=[];for(let e=0;e<r;e++)for(let n=Math.max(e+t,0);n<s;n++)i.push(e),o.push(n);return[w.fromData(new Int32Array(i),[i.length],"int32"),w.fromData(new Int32Array(o),[o.length],"int32")]}function dr(r,t=0){const a=r.shape;if(a.length!==2)throw new Error("array must be 2-D");return H(a[0],t,a[1])}function yr(r,t,a=0){const s=t(r,a),i=s.shape;if(i.length!==2||i[0]!==r||i[1]!==r)throw new Error("mask_func must return n x n array");const o=[],e=[];for(let n=0;n<r;n++)for(let u=0;u<r;u++)s.get(n,u)&&(o.push(n),e.push(u));return[w.fromData(new Int32Array(o),[o.length],"int32"),w.fromData(new Int32Array(e),[e.length],"int32")]}function pr(r,t="int32"){const a=r.length,s=[a,...r],i=s.reduce((u,d)=>u*d,1),o=U(t);if(!o)throw new Error(`Cannot create indices with dtype ${t}`);const e=new o(i),n=r.reduce((u,d)=>u*d,1);for(let u=0;u<a;u++){const d=u*n;for(let l=0;l<n;l++){const f=new Array(a);let c=l;for(let p=a-1;p>=0;p--)f[p]=c%r[p],c=Math.floor(c/r[p]);const y=f[u];t==="int64"?e[d+l]=BigInt(y):e[d+l]=y}}return w.fromData(e,s,t)}function gr(...r){const t=r.length,a=[];for(let s=0;s<t;s++){const i=r[s],o=i.size,e=i.dtype,n=new Array(t).fill(1);n[s]=o;const u=U(e);if(!u)throw new Error(`Cannot create ix_ with dtype ${e}`);const d=new u(o);for(let l=0;l<o;l++){const f=i.iget(l);$(e),d[l]=f}a.push(w.fromData(d,n,e))}return a}function mr(r,t,a="raise"){if(r.length!==t.length)throw new Error("multi_index length must equal dims length");if(r.length===0)throw new Error("multi_index cannot be empty");const s=r[0].size,i=t.length,o=new Int32Array(s),e=new Array(i);let n=1;for(let u=i-1;u>=0;u--)e[u]=n,n*=t[u];for(let u=0;u<s;u++){let d=0;for(let l=0;l<i;l++){let f=Number(r[l].iget(u));const c=t[l];if(a==="wrap")f=(f%c+c)%c;else if(a==="clip")f=Math.max(0,Math.min(f,c-1));else if(f<0||f>=c)throw new Error(`index ${f} is out of bounds for axis ${l} with size ${c}`);d+=f*e[l]}o[u]=d}return w.fromData(o,[s],"int32")}function hr(r,t,a="C"){const s=t.length;let i,o;if(typeof r=="number")i=[r],o=[];else{i=[];for(let l=0;l<r.size;l++)i.push(Number(r.iget(l)));o=Array.from(r.shape)}const e=i.length,n=t.reduce((l,f)=>l*f,1),u=new Array(s);if(a==="C"){let l=1;for(let f=s-1;f>=0;f--)u[f]=l,l*=t[f]}else{let l=1;for(let f=0;f<s;f++)u[f]=l,l*=t[f]}const d=[];for(let l=0;l<s;l++){const f=new Int32Array(e);d.push(w.fromData(f,o.length?o:[1],"int32"))}for(let l=0;l<e;l++){let f=i[l];if(f<0||f>=n)throw new Error(`index ${f} is out of bounds for array with size ${n}`);if(a==="C")for(let c=0;c<s;c++){const y=Math.floor(f/u[c]);f=f%u[c],d[c].data[l]=y%t[c]}else for(let c=s-1;c>=0;c--){const y=Math.floor(f/u[c]);f=f%u[c],d[c].data[l]=y%t[c]}}return typeof r=="number"?d.map(l=>{const f=l.iget(0);return w.fromData(new Int32Array([Number(f)]),[],"int32")}):d}function Ar(r,t,a=!1){const s=r.shape,i=s.length;if(i<2)throw new Error("array must be at least 2-d");let o;if(i===2)o=s[1]+1;else{o=1;for(let d=1;d<i;d++){let l=1;for(let f=d;f<i;f++)l*=s[f];o+=l}}const e=r.size;let n=Math.min(...s);a&&i===2&&(n=Math.max(s[0],s[1]));const u=r.isCContiguous;if(typeof t=="number")if(u){const d=r.data,l=r.offset;if($(r.dtype)){const f=d,c=BigInt(Math.round(t));for(let y=0;y<n;y++){const p=y*o;if(p>=e)break;f[l+p]=c}}else for(let f=0;f<n;f++){const c=f*o;if(c>=e)break;d[l+c]=t}}else for(let d=0;d<n&&d*o<e;d++)r.iset(d*o,t);else{const d=t.size;if(u&&t.isCContiguous){const l=r.data,f=r.offset,c=t.data,y=t.offset;if($(r.dtype)){const p=l,g=c;for(let A=0;A<n;A++){const I=A*o;if(I>=e)break;p[f+I]=g[y+A%d]}}else{const p=l,g=c;for(let A=0;A<n;A++){const I=A*o;if(I>=e)break;p[f+I]=g[y+A%d]}}}else for(let l=0;l<n&&l*o<e;l++)r.iset(l*o,t.iget(l%d))}}function br(r,t,a){const s=Array.from(r.shape),i=s.length;if(t<0&&(t+=i),t<0||t>=i)throw new Error(`axis ${t} is out of bounds for array of dimension ${i}`);const o=[];for(let e=0;e<i;e++)e!==t&&o.push(s[e]);if(o.length===0){const e=a(r);if(typeof e=="number"){const n=w.zeros([1],r.dtype);return n.data[0]=e,n}return e}if(i===2){const[e,n]=s;if(t===0){const u=[];for(let l=0;l<n;l++){const f=new Float64Array(e);for(let y=0;y<e;y++)f[y]=Number(r.get(y,l));const c=w.fromData(f,[e],"float64");u.push(a(c))}const d=u[0];if(d===void 0)return w.zeros([0],"float64");if(typeof d=="number"){const l=w.zeros([n],"float64");for(let f=0;f<n;f++)l.data[f]=u[f];return l}else{const l=[d.size,n],f=w.zeros(l,"float64");for(let c=0;c<n;c++){const y=u[c];for(let p=0;p<y.size;p++)f.data[p*n+c]=Number(y.iget(p))}return f}}else{const u=[];for(let l=0;l<e;l++){const f=new Float64Array(n);for(let y=0;y<n;y++)f[y]=Number(r.get(l,y));const c=w.fromData(f,[n],"float64");u.push(a(c))}const d=u[0];if(d===void 0)return w.zeros([0],"float64");if(typeof d=="number"){const l=w.zeros([e],"float64");for(let f=0;f<e;f++)l.data[f]=u[f];return l}else{const l=[e,d.size],f=w.zeros(l,"float64");for(let c=0;c<e;c++){const y=u[c];for(let p=0;p<y.size;p++)f.data[c*y.size+p]=Number(y.iget(p))}return f}}}if(i===1){const e=a(r);if(typeof e=="number"){const n=w.zeros([1],"float64");return n.data[0]=e,n}return e}throw new Error(`apply_along_axis not fully implemented for ${i}D arrays. Only 1D and 2D arrays are supported.`)}function wr(r,t,a){let s=r;const i=r.shape.length;for(const o of a){let e=o<0?o+i:o;if(e<0||e>=i)throw new Error(`axis ${o} is out of bounds for array of dimension ${i}`);if(s=t(s,e),s.shape.length<i){const n=Array.from(s.shape);n.splice(e,0,1);const u=N(n);s=new w(s.data,n,u,0,s.dtype)}}return s}function J(r,t){return r.data.buffer===t.data.buffer}function xr(r,t){return J(r,t)}let M={divide:"warn",over:"warn",under:"ignore",invalid:"warn"};function K(){return{...M}}function Sr(r,t,a,s,i){const o=K();return r!==void 0&&(M.divide=r,M.over=r,M.under=r,M.invalid=r),t!==void 0&&(M.divide=t),a!==void 0&&(M.over=a),s!==void 0&&(M.under=s),i!==void 0&&(M.invalid=i),o}export{br as apply_along_axis,wr as apply_over_axes,or as array_equal,Z as broadcast_arrays,q as broadcast_shapes,Y as broadcast_to,er as choose,sr as compress,R as diag_indices,lr as diag_indices_from,Ar as fill_diagonal,K as geterr,pr as indices,gr as ix_,yr as mask_indices,J as may_share_memory,fr as place,tr as put,ir as put_along_axis,ar as putmask,mr as ravel_multi_index,ur as select,Sr as seterr,xr as shares_memory,rr as take,nr as take_along_axis,G as tril_indices,cr as tril_indices_from,H as triu_indices,dr as triu_indices_from,hr as unravel_index};
1
+ import{ArrayStorage as S,computeStrides as k}from"../storage.js";import{getTypedArrayConstructor as U,isBigIntDType as _}from"../dtype.js";import{computeBroadcastShape as L,broadcastTo as O,broadcastShapes as H}from"../broadcasting.js";import{Complex as q}from"../complex.js";import{wasmIndices as J}from"../wasm/indices.js";import{wasmTakeAlongAxis2D as K}from"../wasm/gather.js";function ir(r,t){const a=r.shape,u=a.length,o=t.length;if(o<u)throw new Error("input operand has more dimensions than allowed by the axis remapping");const e=L([Array.from(a),t]);if(e===null)throw new Error(`operands could not be broadcast together with shape (${a.join(",")}) (${t.join(",")})`);for(let s=0;s<o;s++)if(e[s]!==t[s])throw new Error(`operands could not be broadcast together with shape (${a.join(",")}) (${t.join(",")})`);return O(r,t)}function ar(r){if(r.length===0)return[];if(r.length===1)return[r[0]];const t=r.map(u=>Array.from(u.shape)),a=L(t);if(a===null)throw new Error(`operands could not be broadcast together with shapes ${t.map(u=>`(${u.join(",")})`).join(" ")}`);return r.map(u=>O(u,a))}function sr(r,t,a){const u=r.shape,o=u.length,e=r.dtype;if(a===void 0){const g=r.size;for(const w of t){const A=w<0?g+w:w;if(A<0||A>=g)throw new Error(`index ${w} is out of bounds for axis 0 with size ${g}`)}const p=t.length,m=U(e);if(!m)throw new Error(`Cannot take from array with dtype ${e}`);const h=new m(p);for(let w=0;w<p;w++){let A=t[w];A<0&&(A=g+A);const I=r.iget(A);_(e),h[w]=I}return S.fromData(h,[p],e)}const s=a<0?o+a:a;if(s<0||s>=o)throw new Error(`axis ${a} is out of bounds for array of dimension ${o}`);const i=u[s];for(const g of t){const p=g<0?i+g:g;if(p<0||p>=i)throw new Error(`index ${g} is out of bounds for axis ${s} with size ${i}`)}const l=Array.from(u);l[s]=t.length;const d=l.reduce((g,p)=>g*p,1),f=U(e);if(!f)throw new Error(`Cannot take from array with dtype ${e}`);const c=new f(d),n=k(l),y=new Array(o).fill(0);for(let g=0;g<d;g++){const p=[...y];let m=y[s],h=t[m];h<0&&(h=i+h),p[s]=h;const w=r.get(...p);let A=0;for(let I=0;I<o;I++)A+=y[I]*n[I];_(e),c[A]=w;for(let I=o-1;I>=0&&(y[I]++,!(y[I]<l[I]));I--)y[I]=0}return S.fromData(c,l,e)}function ur(r,t,a){const u=r.size,o=r.dtype;let e;if(typeof a=="number"||typeof a=="bigint")e=new Array(t.length).fill(a);else{e=[];for(let s=0;s<a.size;s++){const i=a.iget(s);e.push(i instanceof q?i.re:i)}if(e.length===1)e=new Array(t.length).fill(e[0]);else if(e.length!==t.length){const s=[...e];e=[];for(let i=0;i<t.length;i++)e.push(s[i%s.length])}}for(let s=0;s<t.length;s++){let i=t[s];if(i<0&&(i=u+i),i<0||i>=u)throw new Error(`index ${t[s]} is out of bounds for axis 0 with size ${u}`);let l=e[s];_(o)?typeof l!="bigint"&&(l=BigInt(Math.round(Number(l)))):typeof l=="bigint"&&(l=Number(l)),r.iset(i,l)}}function fr(r,t){if(t.length===0)throw new Error("choices cannot be empty");const a=r.shape,u=t.length,o=t[0].dtype,e=t.map(n=>Array.from(n.shape));e.unshift(Array.from(a));const s=L(e);if(s===null)throw new Error("operands could not be broadcast together");const i=O(r,s),l=t.map(n=>O(n,s)),d=s.reduce((n,y)=>n*y,1),f=U(o);if(!f)throw new Error(`Cannot choose with dtype ${o}`);const c=new f(d);for(let n=0;n<d;n++){const y=Number(i.iget(n));if(y<0||y>=u)throw new Error(`index ${y} is out of bounds for axis 0 with size ${u}`);const g=l[y].iget(n);_(o),c[n]=g}return S.fromData(c,s,o)}function lr(r,t,a=!1){if(r.ndim!==t.ndim)return!1;for(let o=0;o<r.ndim;o++)if(r.shape[o]!==t.shape[o])return!1;const u=r.size;for(let o=0;o<u;o++){const e=r.iget(o),s=t.iget(o);if(a){const i=typeof e=="number"&&Number.isNaN(e),l=typeof s=="number"&&Number.isNaN(s);if(i&&l)continue}if(e!==s)return!1}return!0}function cr(r,t,a){const u=K(r,t,a);if(u)return u;const o=r.shape,e=o.length,s=r.dtype,i=a<0?e+a:a;if(i<0||i>=e)throw new Error(`axis ${a} is out of bounds for array of dimension ${e}`);const l=t.shape;if(l.length!==e)throw new Error(`indices and arr must have the same number of dimensions, got ${l.length} vs ${e}`);for(let x=0;x<e;x++)if(x!==i&&l[x]!==o[x]&&l[x]!==1&&o[x]!==1)throw new Error(`index ${l[x]} is out of bounds for size ${o[x]} in dimension ${x}`);const d=Array.from(l),f=d.reduce((x,D)=>x*D,1),c=U(s);if(!c)throw new Error(`Cannot take_along_axis with dtype ${s}`);const n=new c(f),y=k(o),g=k(l),p=o[i],m=k(d),h=new Array(e),w=_(s),A=r.isCContiguous,I=t.isCContiguous,C=r.data,j=r.offset,z=t.data,b=t.offset;for(let x=0;x<f;x++){let D=x;for(let B=0;B<e;B++)h[B]=D/m[B]|0,D-=h[B]*m[B];let $=0;for(let B=0;B<e;B++){const F=l[B]===1?0:h[B];$+=F*g[B]}let N=Number(I?z[b+$]:t.iget($));N<0&&(N=p+N);let v=0;for(let B=0;B<e;B++){const F=B===i?N:o[B]===1?0:h[B];v+=F*y[B]}if(A)n[x]=C[j+v];else{const B=r.iget(v);n[x]=B}}return S.fromData(n,d,s)}function dr(r,t,a,u){const o=r.shape,e=o.length,s=r.dtype,i=u<0?e+u:u;if(i<0||i>=e)throw new Error(`axis ${u} is out of bounds for array of dimension ${e}`);const l=t.shape,d=a.shape;if(l.length!==e||d.length!==e)throw new Error("indices, arr, and values must have same ndim");const f=o[i],c=k(o),n=k(l),y=k(d),g=l.reduce((p,m)=>p*m,1);for(let p=0;p<g;p++){const m=new Array(e);let h=p;for(let b=e-1;b>=0;b--)m[b]=h%l[b],h=Math.floor(h/l[b]);let w=0;for(let b=0;b<e;b++)w+=m[b]*n[b];let A=Number(t.iget(w));if(A<0&&(A=f+A),A<0||A>=f)throw new Error(`index ${A} is out of bounds for axis ${i} with size ${f}`);let I=0;for(let b=0;b<e;b++){const x=d[b]===1?0:m[b];I+=x*y[b]}let C=a.iget(I);const j=[...m];j[i]=A;let z=0;for(let b=0;b<e;b++)z+=j[b]*c[b];_(s)?typeof C!="bigint"&&(C=BigInt(Math.round(Number(C)))):typeof C=="bigint"&&(C=Number(C)),r.iset(z,C)}}function yr(r,t,a){const u=r.size,o=r.dtype;let e;if(typeof a=="number"||typeof a=="bigint")e=[a];else{e=[];for(let i=0;i<a.size;i++){const l=a.iget(i);e.push(l instanceof q?l.re:l)}}let s=0;for(let i=0;i<u;i++)if(t.iget(i)){let d=e[s%e.length];_(o)?typeof d!="bigint"&&(d=BigInt(Math.round(Number(d)))):typeof d=="bigint"&&(d=Number(d)),r.iset(i,d),s++}}function gr(r,t,a){const u=t.shape,o=u.length,e=t.dtype,s=_(e);if(a===void 0){const z=Math.min(r.size,t.size),b=r.isCContiguous,x=r.data,D=r.offset;let $=0;if(b)for(let E=0;E<z;E++)x[D+E]&&$++;else for(let E=0;E<z;E++)r.iget(E)&&$++;const N=U(e);if(!N)throw new Error(`Cannot compress with dtype ${e}`);const v=new N($);let B=0;const F=t.isCContiguous;if(b&&F){const E=t.data,G=t.offset;if(s){const R=v,V=E;for(let M=0;M<z;M++)x[D+M]&&(R[B++]=V[G+M])}else{const R=v,V=E;for(let M=0;M<z;M++)x[D+M]&&(R[B++]=V[G+M])}}else for(let E=0;E<z;E++)(b?x[D+E]:r.iget(E))&&(v[B]=t.iget(E),B++);return S.fromData(v,[$],e)}const i=a<0?o+a:a;if(i<0||i>=o)throw new Error(`axis ${a} is out of bounds for array of dimension ${o}`);const l=u[i],d=Math.min(r.size,l),f=[],c=r.isCContiguous,n=r.data,y=r.offset;for(let z=0;z<d;z++)(c?n[y+z]:r.iget(z))&&f.push(z);const g=f.length,p=[...u];p[i]=g;const m=p.reduce((z,b)=>z*b,1),h=U(e);if(!h)throw new Error(`Cannot compress with dtype ${e}`);const w=new h(m),A=u.slice(i+1).reduce((z,b)=>z*b,1),I=u.slice(0,i).reduce((z,b)=>z*b,1);let C=0;if(t.isCContiguous){const z=t.data,b=t.offset;for(let x=0;x<I;x++){const D=b+x*l*A;for(let $=0;$<g;$++){const N=D+f[$]*A;w.set(z.subarray(N,N+A),C),C+=A}}}else for(let z=0;z<I;z++)for(let b=0;b<g;b++){const x=f[b];for(let D=0;D<A;D++){const $=z*l*A+x*A+D;w[C++]=t.iget($)}}return S.fromData(w,p,e)}function pr(r,t,a=0){if(r.length!==t.length)throw new Error("condlist and choicelist must have same length");if(r.length===0)throw new Error("condlist and choicelist cannot be empty");const u=[...r.map(n=>Array.from(n.shape)),...t.map(n=>Array.from(n.shape))],o=L(u);if(o===null)throw new Error("condlist and choicelist arrays could not be broadcast together");const e=t[0].dtype,s=o.reduce((n,y)=>n*y,1),i=U(e);if(!i)throw new Error(`Cannot select with dtype ${e}`);const l=_(e)?typeof a=="bigint"?a:BigInt(a):typeof a=="bigint"?Number(a):a,d=new i(s);for(let n=0;n<s;n++)_(e),d[n]=l;const f=r.map(n=>O(n,o)),c=t.map(n=>O(n,o));for(let n=0;n<s;n++)for(let y=0;y<r.length;y++)if(f[y].iget(n)){const g=c[y].iget(n);_(e),d[n]=g;break}return S.fromData(d,o,e)}function mr(r,t,a){const u=r.size,o=r.dtype,e=[];for(let i=0;i<a.size;i++){const l=a.iget(i);e.push(l instanceof q?l.re:l)}if(e.length===0)return;let s=0;for(let i=0;i<u;i++)if(t.iget(i)){let d=e[s%e.length];_(o)?typeof d!="bigint"&&(d=BigInt(Math.round(Number(d)))):typeof d=="bigint"&&(d=Number(d)),r.iset(i,d),s++}}function P(r,t=2){if(t<1)throw new Error("ndim must be at least 1");const a=new Int32Array(r);for(let o=0;o<r;o++)a[o]=o;const u=[];for(let o=0;o<t;o++)u.push(S.fromData(new Int32Array(a),[r],"int32"));return u}function hr(r){const t=r.shape,a=t.length;if(a<2)throw new Error("array must be at least 2-D");const u=t[0];for(let o=1;o<a;o++)if(t[o]!==u)throw new Error("All dimensions of input must be equal");return P(u,a)}function Q(r,t=0,a){const u=a??r,o=[],e=[];for(let s=0;s<r;s++)for(let i=0;i<=Math.min(s+t,u-1);i++)i>=0&&(o.push(s),e.push(i));return[S.fromData(new Int32Array(o),[o.length],"int32"),S.fromData(new Int32Array(e),[e.length],"int32")]}function Ar(r,t=0){const a=r.shape;if(a.length!==2)throw new Error("array must be 2-D");return Q(a[0],t,a[1])}function W(r,t=0,a){const u=a??r,o=[],e=[];for(let s=0;s<r;s++)for(let i=Math.max(s+t,0);i<u;i++)o.push(s),e.push(i);return[S.fromData(new Int32Array(o),[o.length],"int32"),S.fromData(new Int32Array(e),[e.length],"int32")]}function br(r,t=0){const a=r.shape;if(a.length!==2)throw new Error("array must be 2-D");return W(a[0],t,a[1])}function wr(r,t,a=0){const u=t(r,a),o=u.shape;if(o.length!==2||o[0]!==r||o[1]!==r)throw new Error("mask_func must return n x n array");const e=[],s=[];for(let i=0;i<r;i++)for(let l=0;l<r;l++)u.get(i,l)&&(e.push(i),s.push(l));return[S.fromData(new Int32Array(e),[e.length],"int32"),S.fromData(new Int32Array(s),[s.length],"int32")]}function Sr(r,t="int32"){const a=J(r,t);if(a)return a;const u=r.length,o=[u,...r],e=o.reduce((f,c)=>f*c,1),s=U(t);if(!s)throw new Error(`Cannot create indices with dtype ${t}`);const i=new s(e),l=r.reduce((f,c)=>f*c,1),d=new Array(u);d[u-1]=1;for(let f=u-2;f>=0;f--)d[f]=d[f+1]*r[f+1];for(let f=0;f<u;f++){const c=f*l,n=r[f],y=d[f];if(t==="int64"){const g=i;for(let p=0;p<l;p++)g[c+p]=BigInt(Math.floor(p/y)%n)}else{const g=i;for(let p=0;p<l;p++)g[c+p]=Math.floor(p/y)%n}}return S.fromData(i,o,t)}function xr(...r){const t=r.length,a=[];for(let u=0;u<t;u++){const o=r[u],e=o.size,s=o.dtype,i=new Array(t).fill(1);i[u]=e;const l=U(s);if(!l)throw new Error(`Cannot create ix_ with dtype ${s}`);const d=new l(e);for(let f=0;f<e;f++){const c=o.iget(f);_(s),d[f]=c}a.push(S.fromData(d,i,s))}return a}function Ir(r,t,a="raise"){if(r.length!==t.length)throw new Error("multi_index length must equal dims length");if(r.length===0)throw new Error("multi_index cannot be empty");const u=r[0].size,o=t.length,e=new Int32Array(u),s=new Array(o);let i=1;for(let l=o-1;l>=0;l--)s[l]=i,i*=t[l];for(let l=0;l<u;l++){let d=0;for(let f=0;f<o;f++){let c=Number(r[f].iget(l));const n=t[f];if(a==="wrap")c=(c%n+n)%n;else if(a==="clip")c=Math.max(0,Math.min(c,n-1));else if(c<0||c>=n)throw new Error(`index ${c} is out of bounds for axis ${f} with size ${n}`);d+=c*s[f]}e[l]=d}return S.fromData(e,[u],"int32")}function zr(r,t,a="C"){const u=t.length;let o,e;if(typeof r=="number")o=[r],e=[];else{o=[];for(let f=0;f<r.size;f++)o.push(Number(r.iget(f)));e=Array.from(r.shape)}const s=o.length,i=t.reduce((f,c)=>f*c,1),l=new Array(u);if(a==="C"){let f=1;for(let c=u-1;c>=0;c--)l[c]=f,f*=t[c]}else{let f=1;for(let c=0;c<u;c++)l[c]=f,f*=t[c]}const d=[];for(let f=0;f<u;f++){const c=new Int32Array(s);d.push(S.fromData(c,e.length?e:[1],"int32"))}for(let f=0;f<s;f++){let c=o[f];if(c<0||c>=i)throw new Error(`index ${c} is out of bounds for array with size ${i}`);if(a==="C")for(let n=0;n<u;n++){const y=Math.floor(c/l[n]);c=c%l[n],d[n].data[f]=y%t[n]}else for(let n=u-1;n>=0;n--){const y=Math.floor(c/l[n]);c=c%l[n],d[n].data[f]=y%t[n]}}return typeof r=="number"?d.map(f=>{const c=f.iget(0);return S.fromData(new Int32Array([Number(c)]),[],"int32")}):d}function Br(r,t,a=!1){const u=r.shape,o=u.length;if(o<2)throw new Error("array must be at least 2-d");let e;if(o===2)e=u[1]+1;else{e=1;for(let d=1;d<o;d++){let f=1;for(let c=d;c<o;c++)f*=u[c];e+=f}}const s=r.size;let i=Math.min(...u);a&&o===2&&(i=Math.max(u[0],u[1]));const l=r.isCContiguous;if(typeof t=="number")if(l){const d=r.data,f=r.offset;if(_(r.dtype)){const c=d,n=BigInt(Math.round(t));for(let y=0;y<i;y++){const g=y*e;if(g>=s)break;c[f+g]=n}}else for(let c=0;c<i;c++){const n=c*e;if(n>=s)break;d[f+n]=t}}else for(let d=0;d<i&&d*e<s;d++)r.iset(d*e,t);else{const d=t.size;if(l&&t.isCContiguous){const f=r.data,c=r.offset,n=t.data,y=t.offset;if(_(r.dtype)){const g=f,p=n;for(let m=0;m<i;m++){const h=m*e;if(h>=s)break;g[c+h]=p[y+m%d]}}else{const g=f,p=n;for(let m=0;m<i;m++){const h=m*e;if(h>=s)break;g[c+h]=p[y+m%d]}}}else for(let f=0;f<i&&f*e<s;f++)r.iset(f*e,t.iget(f%d))}}function Er(r,t,a){const u=Array.from(r.shape),o=u.length;if(t<0&&(t+=o),t<0||t>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);const e=[];for(let n=0;n<o;n++)n!==t&&e.push(u[n]);if(e.length===0){const n=a(r);if(typeof n=="number"){const y=S.zeros([1],r.dtype);return y.data[0]=n,y}return n}if(o===2){const[n,y]=u;if(t===0){const g=[];for(let m=0;m<y;m++){const h=new Float64Array(n);for(let A=0;A<n;A++)h[A]=Number(r.get(A,m));const w=S.fromData(h,[n],"float64");g.push(a(w))}const p=g[0];if(p===void 0)return S.zeros([0],"float64");if(typeof p=="number"){const m=S.zeros([y],"float64");for(let h=0;h<y;h++)m.data[h]=g[h];return m}else{const m=[p.size,y],h=S.zeros(m,"float64");for(let w=0;w<y;w++){const A=g[w];for(let I=0;I<A.size;I++)h.data[I*y+w]=Number(A.iget(I))}return h}}else{const g=[];for(let m=0;m<n;m++){const h=new Float64Array(y);for(let A=0;A<y;A++)h[A]=Number(r.get(m,A));const w=S.fromData(h,[y],"float64");g.push(a(w))}const p=g[0];if(p===void 0)return S.zeros([0],"float64");if(typeof p=="number"){const m=S.zeros([n],"float64");for(let h=0;h<n;h++)m.data[h]=g[h];return m}else{const m=[n,p.size],h=S.zeros(m,"float64");for(let w=0;w<n;w++){const A=g[w];for(let I=0;I<A.size;I++)h.data[w*A.size+I]=Number(A.iget(I))}return h}}}if(o===1){const n=a(r);if(typeof n=="number"){const y=S.zeros([1],"float64");return y.data[0]=n,y}return n}const s=u[t],i=e.reduce((n,y)=>n*y,1);function l(n){const y=new Array(e.length);let g=n;for(let p=e.length-1;p>=0;p--)y[p]=g%e[p],g=Math.floor(g/e[p]);return y}function d(n,y){const g=[];let p=0;for(let m=0;m<o;m++)g.push(m===t?y:n[p++]);return Number(r.get(...g))}const f=[];for(let n=0;n<i;n++){const y=l(n),g=new Float64Array(s);for(let m=0;m<s;m++)g[m]=d(y,m);const p=S.fromData(g,[s],"float64");f.push(a(p))}const c=f[0];if(c===void 0)return S.zeros([0],"float64");if(typeof c=="number"){const n=S.zeros(e,"float64");for(let y=0;y<i;y++)n.data[y]=f[y];return n}else{const n=[...e,...Array.from(c.shape)],y=S.zeros(n,"float64"),g=c.size;for(let p=0;p<i;p++){const m=f[p];for(let h=0;h<g;h++)y.data[p*g+h]=Number(m.iget(h))}return y}}function Cr(r,t,a){let u=r;const o=r.shape.length;for(const e of a){let s=e<0?e+o:e;if(s<0||s>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);if(u=t(u,s),u.shape.length<o){const i=Array.from(u.shape);i.splice(s,0,1);const l=k(i);u=new S(u.data,i,l,0,u.dtype)}}return u}function X(r,t){return r.data.buffer===t.data.buffer}function Dr(r,t){return X(r,t)}let T={divide:"warn",over:"warn",under:"ignore",invalid:"warn"};function Y(){return{...T}}function $r(r,t,a,u,o){const e=Y();return r!==void 0&&(T.divide=r,T.over=r,T.under=r,T.invalid=r),t!==void 0&&(T.divide=t),a!==void 0&&(T.over=a),u!==void 0&&(T.under=u),o!==void 0&&(T.invalid=o),e}export{Er as apply_along_axis,Cr as apply_over_axes,lr as array_equal,ar as broadcast_arrays,H as broadcast_shapes,ir as broadcast_to,fr as choose,gr as compress,P as diag_indices,hr as diag_indices_from,Br as fill_diagonal,Y as geterr,Sr as indices,xr as ix_,wr as mask_indices,X as may_share_memory,mr as place,ur as put,dr as put_along_axis,yr as putmask,Ir as ravel_multi_index,pr as select,$r as seterr,Dr as shares_memory,sr as take,cr as take_along_axis,Q as tril_indices,Ar as tril_indices_from,W as triu_indices,br as triu_indices_from,zr as unravel_index};
@@ -1 +1 @@
1
- import{ArrayStorage as b}from"../storage";import{isBigIntDType as N,isComplexDType as M,getComplexComponentDType as j,promoteDTypes as x,throwIfComplex as S}from"../dtype";import{elementwiseBinaryOp as D}from"../internal/compute";function P(t,r){return t.isCContiguous&&r.isCContiguous&&t.shape.length===r.shape.length&&t.shape.every((f,i)=>f===r.shape[i])}function T(t,r){return[t[r*2],t[r*2+1]]}function F(t,r,f,i){t[r*2]=f,t[r*2+1]=i}function at(t,r){if(typeof r=="number")return G(t,r);if(r.size===1&&!M(r.dtype)&&t.dtype===r.dtype){const f=Number(r.iget(0));return G(t,f)}return P(t,r)?k(t,r):D(t,r,(f,i)=>f+i,"add")}function k(t,r){const f=x(t.dtype,r.dtype),i=b.zeros(Array.from(t.shape),f),m=t.size,u=t.data,c=r.data,l=i.data,a=t.offset,e=r.offset;if(M(f)){const s=l,o=M(t.dtype),n=M(r.dtype);for(let y=0;y<m;y++){const[p,d]=o?T(u,a+y):[Number(u[a+y]),0],[A,g]=n?T(c,e+y):[Number(c[e+y]),0];F(s,y,p+A,d+g)}return i}if(N(f)){const s=l;if(!N(t.dtype)||!N(r.dtype))for(let n=0;n<m;n++){const y=typeof u[a+n]=="bigint"?u[a+n]:BigInt(Math.round(Number(u[a+n]))),p=typeof c[e+n]=="bigint"?c[e+n]:BigInt(Math.round(Number(c[e+n])));s[n]=y+p}else{const n=u,y=c;for(let p=0;p<m;p++)s[p]=n[a+p]+y[e+p]}}else if(N(t.dtype)||N(r.dtype))for(let o=0;o<m;o++){const n=typeof u[a+o]=="bigint"?Number(u[a+o]):u[a+o],y=typeof c[e+o]=="bigint"?Number(c[e+o]):c[e+o];l[o]=n+y}else if(a===0&&e===0)for(let o=0;o<m;o++)l[o]=u[o]+c[o];else for(let o=0;o<m;o++)l[o]=u[a+o]+c[e+o];return i}function nt(t,r){if(typeof r=="number")return H(t,r);if(r.size===1&&!M(r.dtype)&&t.dtype===r.dtype){const f=Number(r.iget(0));return H(t,f)}return P(t,r)?J(t,r):D(t,r,(f,i)=>f-i,"subtract")}function J(t,r){const f=x(t.dtype,r.dtype),i=b.zeros(Array.from(t.shape),f),m=t.size,u=t.data,c=r.data,l=i.data,a=t.offset,e=r.offset;if(M(f)){const s=l,o=M(t.dtype),n=M(r.dtype);for(let y=0;y<m;y++){const[p,d]=o?T(u,a+y):[Number(u[a+y]),0],[A,g]=n?T(c,e+y):[Number(c[e+y]),0];F(s,y,p-A,d-g)}return i}if(N(f)){const s=l;if(!N(t.dtype)||!N(r.dtype))for(let n=0;n<m;n++){const y=typeof u[a+n]=="bigint"?u[a+n]:BigInt(Math.round(Number(u[a+n]))),p=typeof c[e+n]=="bigint"?c[e+n]:BigInt(Math.round(Number(c[e+n])));s[n]=y-p}else{const n=u,y=c;for(let p=0;p<m;p++)s[p]=n[a+p]-y[e+p]}}else if(N(t.dtype)||N(r.dtype))for(let o=0;o<m;o++){const n=typeof u[a+o]=="bigint"?Number(u[a+o]):u[a+o],y=typeof c[e+o]=="bigint"?Number(c[e+o]):c[e+o];l[o]=n-y}else if(a===0&&e===0)for(let o=0;o<m;o++)l[o]=u[o]-c[o];else for(let o=0;o<m;o++)l[o]=u[a+o]-c[e+o];return i}function it(t,r){if(typeof r=="number")return X(t,r);if(r.size===1&&!M(r.dtype)&&t.dtype===r.dtype){const f=Number(r.iget(0));return X(t,f)}return P(t,r)?K(t,r):D(t,r,(f,i)=>f*i,"multiply")}function K(t,r){const f=x(t.dtype,r.dtype),i=b.zeros(Array.from(t.shape),f),m=t.size,u=t.data,c=r.data,l=i.data,a=t.offset,e=r.offset;if(M(f)){const s=l,o=M(t.dtype),n=M(r.dtype);for(let y=0;y<m;y++){const[p,d]=o?T(u,a+y):[Number(u[a+y]),0],[A,g]=n?T(c,e+y):[Number(c[e+y]),0],h=p*A-d*g,C=p*g+d*A;F(s,y,h,C)}return i}if(N(f)){const s=l;if(!N(t.dtype)||!N(r.dtype))for(let n=0;n<m;n++){const y=typeof u[a+n]=="bigint"?u[a+n]:BigInt(Math.round(Number(u[a+n]))),p=typeof c[e+n]=="bigint"?c[e+n]:BigInt(Math.round(Number(c[e+n])));s[n]=y*p}else{const n=u,y=c;for(let p=0;p<m;p++)s[p]=n[a+p]*y[e+p]}}else if(N(t.dtype)||N(r.dtype))for(let o=0;o<m;o++){const n=typeof u[a+o]=="bigint"?Number(u[a+o]):u[a+o],y=typeof c[e+o]=="bigint"?Number(c[e+o]):c[e+o];l[o]=n*y}else if(a===0&&e===0)for(let o=0;o<m;o++)l[o]=u[o]*c[o];else for(let o=0;o<m;o++)l[o]=u[a+o]*c[e+o];return i}function ft(t,r){if(typeof r=="number")return Q(t,r);const f=M(t.dtype),i=M(r.dtype);if(f||i){const s=x(t.dtype,r.dtype),o=b.zeros(Array.from(t.shape),s),n=o.data,y=t.size,p=t.data,d=r.data,A=t.offset,g=r.offset;for(let h=0;h<y;h++){const[C,w]=f?T(p,A+h):[Number(p[A+h]),0],[v,U]=i?T(d,g+h):[Number(d[g+h]),0],I=v*v+U*U,z=(C*v+w*U)/I,B=(w*v-C*U)/I;F(n,h,z,B)}return o}const m=t.dtype==="float64",u=r.dtype==="float64",c=t.dtype==="float32",l=r.dtype==="float32";if(m||u){const s=m?t:q(t,"float64"),o=u?r:q(r,"float64");return D(s,o,(n,y)=>n/y,"divide")}if(c||l){const s=c?t:q(t,"float32"),o=l?r:q(r,"float32");return D(s,o,(n,y)=>n/y,"divide")}const a=q(t,"float64"),e=q(r,"float64");return D(a,e,(s,o)=>s/o,"divide")}function q(t,r){const f=b.zeros(Array.from(t.shape),r),i=t.size,m=f.data;if(t.isCContiguous){const u=t.data,c=t.offset;for(let l=0;l<i;l++)m[l]=Number(u[c+l])}else for(let u=0;u<i;u++)m[u]=Number(t.iget(u));return f}function G(t,r){const f=t.dtype,i=Array.from(t.shape),m=t.data,u=t.size,c=t.offset,l=t.isCContiguous,a=b.zeros(i,f),e=a.data;if(M(f)){const s=m,o=e;if(l)for(let n=0;n<u;n++){const[y,p]=T(s,c+n);F(o,n,y+r,p)}else for(let n=0;n<u;n++){const y=t.iget(n),p=y.re??Number(y),d=y.im??0;F(o,n,p+r,d)}}else if(N(f)){const s=e,o=BigInt(Math.round(r));if(l){const n=m;for(let y=0;y<u;y++)s[y]=n[c+y]+o}else for(let n=0;n<u;n++)s[n]=t.iget(n)+o}else if(l)if(c===0)for(let s=0;s<u;s++)e[s]=Number(m[s])+r;else for(let s=0;s<u;s++)e[s]=Number(m[c+s])+r;else for(let s=0;s<u;s++)e[s]=Number(t.iget(s))+r;return a}function H(t,r){const f=t.dtype,i=Array.from(t.shape),m=t.data,u=t.size,c=t.offset,l=t.isCContiguous,a=b.zeros(i,f),e=a.data;if(M(f)){const s=m,o=e;if(l)for(let n=0;n<u;n++){const[y,p]=T(s,c+n);F(o,n,y-r,p)}else for(let n=0;n<u;n++){const y=t.iget(n),p=y.re??Number(y),d=y.im??0;F(o,n,p-r,d)}}else if(N(f)){const s=e,o=BigInt(Math.round(r));if(l){const n=m;for(let y=0;y<u;y++)s[y]=n[c+y]-o}else for(let n=0;n<u;n++)s[n]=t.iget(n)-o}else if(l)for(let s=0;s<u;s++)e[s]=Number(m[c+s])-r;else for(let s=0;s<u;s++)e[s]=Number(t.iget(s))-r;return a}function X(t,r){const f=t.dtype,i=Array.from(t.shape),m=t.data,u=t.size,c=t.offset,l=t.isCContiguous,a=b.zeros(i,f),e=a.data;if(M(f)){const s=m,o=e;if(l)for(let n=0;n<u;n++){const[y,p]=T(s,c+n);F(o,n,y*r,p*r)}else for(let n=0;n<u;n++){const y=t.iget(n),p=y.re??Number(y),d=y.im??0;F(o,n,p*r,d*r)}}else if(N(f)){const s=e,o=BigInt(Math.round(r));if(l){const n=m;for(let y=0;y<u;y++)s[y]=n[c+y]*o}else for(let n=0;n<u;n++)s[n]=t.iget(n)*o}else if(l)if(c===0)for(let s=0;s<u;s++)e[s]=Number(m[s])*r;else for(let s=0;s<u;s++)e[s]=Number(m[c+s])*r;else for(let s=0;s<u;s++)e[s]=Number(t.iget(s))*r;return a}function Q(t,r){const f=t.dtype,i=Array.from(t.shape),m=t.data,u=t.size,c=t.offset,l=t.isCContiguous;if(M(f)){const n=b.zeros(i,f),y=n.data;if(l){const p=m;for(let d=0;d<u;d++){const[A,g]=T(p,c+d);F(y,d,A/r,g/r)}}else for(let p=0;p<u;p++){const d=t.iget(p),A=d.re??Number(d),g=d.im??0;F(y,p,A/r,g/r)}return n}const e=f!=="float32"&&f!=="float64"?"float64":f,s=b.zeros(i,e),o=s.data;if(l)for(let n=0;n<u;n++)o[n]=Number(m[c+n])/r;else for(let n=0;n<u;n++)o[n]=Number(t.iget(n))/r;return s}function ut(t){const r=t.dtype,f=Array.from(t.shape),i=t.data,m=t.size,u=t.offset,c=t.isCContiguous;if(M(r)){const e=j(r),s=b.zeros(f,e),o=s.data;if(c){const n=i;for(let y=0;y<m;y++){const p=n[(u+y)*2],d=n[(u+y)*2+1];o[y]=Math.sqrt(p*p+d*d)}}else for(let n=0;n<m;n++){const y=t.iget(n),p=y.re??Number(y),d=y.im??0;o[n]=Math.sqrt(p*p+d*d)}return s}const l=b.zeros(f,r),a=l.data;if(N(r)){const e=a;if(c){const s=i;for(let o=0;o<m;o++){const n=s[u+o];e[o]=n<0n?-n:n}}else for(let s=0;s<m;s++){const o=t.iget(s);e[s]=o<0n?-o:o}}else if(c)if(u===0)for(let e=0;e<m;e++)a[e]=Math.abs(Number(i[e]));else for(let e=0;e<m;e++)a[e]=Math.abs(Number(i[u+e]));else for(let e=0;e<m;e++)a[e]=Math.abs(Number(t.iget(e)));return l}function ct(t){const r=t.dtype,f=Array.from(t.shape),i=t.data,m=t.size,u=t.offset,c=t.isCContiguous,l=b.zeros(f,r),a=l.data;if(M(r)){const e=a;if(c){const s=i;for(let o=0;o<m;o++){const[n,y]=T(s,u+o);F(e,o,-n,-y)}}else for(let s=0;s<m;s++){const o=t.iget(s),n=o.re??Number(o),y=o.im??0;F(e,s,-n,-y)}}else if(N(r)){const e=a;if(c){const s=i;for(let o=0;o<m;o++)e[o]=-s[u+o]}else for(let s=0;s<m;s++)e[s]=-t.iget(s)}else if(c)if(u===0)for(let e=0;e<m;e++)a[e]=-Number(i[e]);else for(let e=0;e<m;e++)a[e]=-Number(i[u+e]);else for(let e=0;e<m;e++)a[e]=-Number(t.iget(e));return l}function lt(t){S(t.dtype,"sign","Sign is not defined for complex numbers.");const r=t.dtype,f=Array.from(t.shape),i=t.data,m=t.size,u=t.offset,c=t.isCContiguous,l=b.zeros(f,r),a=l.data;if(N(r)){const e=a;if(c){const s=i;for(let o=0;o<m;o++){const n=s[u+o];e[o]=n>0n?1n:n<0n?-1n:0n}}else for(let s=0;s<m;s++){const o=t.iget(s);e[s]=o>0n?1n:o<0n?-1n:0n}}else if(c)for(let e=0;e<m;e++){const s=Number(i[u+e]);a[e]=s>0?1:s<0?-1:0}else for(let e=0;e<m;e++){const s=Number(t.iget(e));a[e]=s>0?1:s<0?-1:0}return l}function $(t,r){return S(t.dtype,"mod","Modulo is not defined for complex numbers."),typeof r!="number"&&S(r.dtype,"mod","Modulo is not defined for complex numbers."),typeof r=="number"?W(t,r):D(t,r,(f,i)=>(f%i+i)%i,"mod")}function W(t,r){const f=t.dtype,i=Array.from(t.shape),m=t.data,u=t.size,c=t.offset,l=t.isCContiguous,a=b.zeros(i,f),e=a.data;if(N(f)){const s=e,o=BigInt(Math.round(r));if(l){const n=m;for(let y=0;y<u;y++){const p=n[c+y];s[y]=(p%o+o)%o}}else for(let n=0;n<u;n++){const y=t.iget(n);s[n]=(y%o+o)%o}}else if(l)for(let s=0;s<u;s++){const o=Number(m[c+s]);e[s]=(o%r+r)%r}else for(let s=0;s<u;s++){const o=Number(t.iget(s));e[s]=(o%r+r)%r}return a}function Y(t,r){return S(t.dtype,"floor_divide","Floor division is not defined for complex numbers."),typeof r!="number"&&S(r.dtype,"floor_divide","Floor division is not defined for complex numbers."),typeof r=="number"?Z(t,r):D(t,r,(f,i)=>Math.floor(f/i),"floor_divide")}function Z(t,r){const f=t.dtype,i=Array.from(t.shape),m=t.data,u=t.size,c=t.offset,l=t.isCContiguous,a=b.zeros(i,f),e=a.data;if(N(f)){const s=e,o=BigInt(Math.round(r));if(l){const n=m;for(let y=0;y<u;y++)s[y]=n[c+y]/o}else for(let n=0;n<u;n++)s[n]=t.iget(n)/o}else if(l)for(let s=0;s<u;s++)e[s]=Math.floor(Number(m[c+s])/r);else for(let s=0;s<u;s++)e[s]=Math.floor(Number(t.iget(s))/r);return a}function yt(t){const r=t.dtype,f=Array.from(t.shape),i=t.data,m=t.size,u=t.offset,c=t.isCContiguous,l=b.zeros(f,r),a=l.data;if(M(r)){const e=a;if(c){const s=i;for(let o=0;o<m;o++)e[o*2]=s[(u+o)*2],e[o*2+1]=s[(u+o)*2+1]}else for(let s=0;s<m;s++){const o=t.iget(s);e[s*2]=o.re??Number(o),e[s*2+1]=o.im??0}}else if(c)for(let e=0;e<m;e++)a[e]=i[u+e];else for(let e=0;e<m;e++)a[e]=t.iget(e);return l}function mt(t){const r=t.dtype,f=Array.from(t.shape),i=t.data,m=t.size,u=t.offset,c=t.isCContiguous;if(M(r)){const o=b.zeros(f,r),n=o.data;if(c){const y=i;for(let p=0;p<m;p++){const d=y[(u+p)*2],A=y[(u+p)*2+1],g=d*d+A*A;n[p*2]=d/g,n[p*2+1]=-A/g}}else for(let y=0;y<m;y++){const p=t.iget(y),d=p.re??Number(p),A=p.im??0,g=d*d+A*A;n[y*2]=d/g,n[y*2+1]=-A/g}return o}const a=r!=="float32"&&r!=="float64"?"float64":r,e=b.zeros(f,a),s=e.data;if(c)if(u===0)for(let o=0;o<m;o++)s[o]=1/Number(i[o]);else for(let o=0;o<m;o++)s[o]=1/Number(i[u+o]);else for(let o=0;o<m;o++)s[o]=1/Number(t.iget(o));return e}function pt(t){const r=t.dtype;S(r,"cbrt","cbrt is not supported for complex numbers.");const f=Array.from(t.shape),i=t.data,m=t.size,u=t.offset,l=r!=="float32"&&r!=="float64"?"float64":r,a=b.zeros(f,l),e=a.data;if(t.isCContiguous)for(let s=0;s<m;s++)e[s]=Math.cbrt(Number(i[u+s]));else for(let s=0;s<m;s++)e[s]=Math.cbrt(Number(t.iget(s)));return a}function dt(t){const r=t.dtype;S(r,"fabs","fabs is only for real numbers. Use absolute() for complex.");const f=Array.from(t.shape),i=t.data,m=t.size,u=t.offset,c=r==="float32"?"float32":"float64",l=b.zeros(f,c),a=l.data;if(t.isCContiguous)if(u===0)for(let e=0;e<m;e++)a[e]=Math.abs(Number(i[e]));else for(let e=0;e<m;e++)a[e]=Math.abs(Number(i[u+e]));else for(let e=0;e<m;e++)a[e]=Math.abs(Number(t.iget(e)));return l}function gt(t,r){const f=Y(t,r),i=$(t,r);return[f,i]}function At(t){const r=t.dtype,f=Array.from(t.shape),i=t.data,m=t.size,u=b.zeros(f,r),c=u.data;if(M(r)){const l=i,a=c;for(let e=0;e<m;e++){const s=l[e*2],o=l[e*2+1];a[e*2]=s*s-o*o,a[e*2+1]=2*s*o}}else if(N(r)){const l=i,a=c;for(let e=0;e<m;e++)a[e]=l[e]*l[e]}else for(let l=0;l<m;l++){const a=Number(i[l]);c[l]=a*a}return u}function bt(t,r){return $(t,r)}function ht(t,r){S(t.dtype,"heaviside","Heaviside step function is not defined for complex numbers."),typeof r!="number"&&S(r.dtype,"heaviside","Heaviside step function is not defined for complex numbers.");const f=t.dtype,i=Array.from(t.shape),m=t.size,u=f==="float32"?"float32":"float64",c=b.zeros(i,u),l=c.data;if(typeof r=="number")for(let a=0;a<m;a++){const e=Number(t.iget(a));e<0?l[a]=0:e===0?l[a]=r:l[a]=1}else{const a=r.shape;if(i.every((e,s)=>e===a[s]))for(let e=0;e<m;e++){const s=Number(t.iget(e));s<0?l[e]=0:s===0?l[e]=Number(r.iget(e)):l[e]=1}else for(let e=0;e<m;e++){const s=Number(t.iget(e)),o=e%r.size;s<0?l[e]=0:s===0?l[e]=Number(r.iget(o)):l[e]=1}}return c}function St(t,r){const f=t.dtype;if(M(f)){const i=t.size,m=b.zeros(Array.from(t.shape),f),u=m.data;if(typeof r=="number")if(t.isCContiguous){const c=t.data,l=t.offset;for(let a=0;a<i;a++){const e=c[(l+a)*2],s=c[(l+a)*2+1],o=Math.hypot(e,s),n=Math.atan2(s,e),y=Math.pow(o,r),p=n*r;u[a*2]=y*Math.cos(p),u[a*2+1]=y*Math.sin(p)}}else for(let c=0;c<i;c++){const l=t.iget(c),a=Math.hypot(l.re,l.im),e=Math.atan2(l.im,l.re),s=Math.pow(a,r),o=e*r;u[c*2]=s*Math.cos(o),u[c*2+1]=s*Math.sin(o)}else{const c=M(r.dtype);if(t.isCContiguous&&r.isCContiguous){const l=t.data,a=t.offset,e=r.data,s=r.offset;for(let o=0;o<i;o++){const n=l[(a+o)*2],y=l[(a+o)*2+1];let p,d;if(c){const I=e;p=I[(s+o)*2],d=I[(s+o)*2+1]}else p=Number(e[s+o]),d=0;const A=Math.hypot(n,y),g=Math.atan2(y,n),h=Math.log(A),C=g,w=p*h-d*C,v=p*C+d*h,U=Math.exp(w);u[o*2]=U*Math.cos(v),u[o*2+1]=U*Math.sin(v)}}else for(let l=0;l<i;l++){const a=t.iget(l);let e,s;if(c){const h=r.iget(l);e=h.re,s=h.im}else e=Number(r.iget(l)),s=0;const o=Math.hypot(a.re,a.im),n=Math.atan2(a.im,a.re),y=Math.log(o),p=n,d=e*y-s*p,A=e*p+s*y,g=Math.exp(d);u[l*2]=g*Math.cos(A),u[l*2+1]=g*Math.sin(A)}}return m}if(typeof r=="number"){const i=b.zeros(Array.from(t.shape),"float64"),m=i.data,u=t.size;if(t.isCContiguous){const c=t.data,l=t.offset;for(let a=0;a<u;a++)m[a]=Math.pow(Number(c[l+a]),r)}else for(let c=0;c<u;c++)m[c]=Math.pow(Number(t.iget(c)),r);return i}return D(t,r,(i,m)=>Math.pow(i,m),"float_power")}function Nt(t,r){if(S(t.dtype,"fmod","fmod is not defined for complex numbers."),typeof r!="number"&&S(r.dtype,"fmod","fmod is not defined for complex numbers."),typeof r=="number"){const f=t.copy(),i=f.data,m=t.size;for(let u=0;u<m;u++){const c=Number(i[u]);i[u]=c-Math.trunc(c/r)*r}return f}return D(t,r,(f,i)=>f-Math.trunc(f/i)*i,"fmod")}function zt(t){S(t.dtype,"frexp","frexp is not defined for complex numbers.");const r=b.zeros(Array.from(t.shape),"float64"),f=b.zeros(Array.from(t.shape),"int32"),i=r.data,m=f.data,u=t.size;for(let c=0;c<u;c++){const l=Number(t.iget(c));if(l===0||!isFinite(l))i[c]=l,m[c]=0;else{const a=Math.floor(Math.log2(Math.abs(l)))+1,e=l/Math.pow(2,a);i[c]=e,m[c]=a}}return[r,f]}function Mt(t,r){S(t.dtype,"gcd","GCD is only defined for integers."),typeof r!="number"&&S(r.dtype,"gcd","GCD is only defined for integers.");const f=(l,a)=>{for(l=Math.abs(Math.trunc(l)),a=Math.abs(Math.trunc(a));a!==0;){const e=a;a=l%a,l=e}return l};if(typeof r=="number"){const l=b.zeros(Array.from(t.shape),"int32"),a=l.data,e=t.size,s=Math.abs(Math.trunc(r));if(t.isCContiguous){const o=t.data,n=t.offset;for(let y=0;y<e;y++)a[y]=f(Number(o[n+y]),s)}else for(let o=0;o<e;o++)a[o]=f(Number(t.iget(o)),s);return l}const i=D(t,r,f,"gcd"),m=b.zeros(Array.from(i.shape),"int32"),u=m.data,c=i.size;if(i.isCContiguous){const l=i.data,a=i.offset;for(let e=0;e<c;e++)u[e]=Math.round(Number(l[a+e]))}else for(let l=0;l<c;l++)u[l]=Math.round(Number(i.iget(l)));return m}function It(t,r){S(t.dtype,"lcm","LCM is only defined for integers."),typeof r!="number"&&S(r.dtype,"lcm","LCM is only defined for integers.");const f=(a,e)=>{for(a=Math.abs(Math.trunc(a)),e=Math.abs(Math.trunc(e));e!==0;){const s=e;e=a%e,a=s}return a},i=(a,e)=>(a=Math.abs(Math.trunc(a)),e=Math.abs(Math.trunc(e)),a===0||e===0?0:a*e/f(a,e));if(typeof r=="number"){const a=b.zeros(Array.from(t.shape),"int32"),e=a.data,s=t.size,o=Math.abs(Math.trunc(r));if(t.isCContiguous){const n=t.data,y=t.offset;for(let p=0;p<s;p++)e[p]=i(Number(n[y+p]),o)}else for(let n=0;n<s;n++)e[n]=i(Number(t.iget(n)),o);return a}const m=D(t,r,i,"lcm"),u=b.zeros(Array.from(m.shape),"int32"),c=u.data,l=m.size;if(m.isCContiguous){const a=m.data,e=m.offset;for(let s=0;s<l;s++)c[s]=Math.round(Number(a[e+s]))}else for(let a=0;a<l;a++)c[a]=Math.round(Number(m.iget(a)));return u}function Bt(t,r){if(S(t.dtype,"ldexp","ldexp is not defined for complex numbers."),typeof r!="number"&&S(r.dtype,"ldexp","ldexp is not defined for complex numbers."),typeof r=="number"){const f=b.zeros(Array.from(t.shape),"float64"),i=f.data,m=t.size,u=Math.pow(2,r);for(let c=0;c<m;c++)i[c]=Number(t.iget(c))*u;return f}return D(t,r,(f,i)=>f*Math.pow(2,i),"ldexp")}function Dt(t){S(t.dtype,"modf","modf is not defined for complex numbers.");const r=b.zeros(Array.from(t.shape),"float64"),f=b.zeros(Array.from(t.shape),"float64"),i=r.data,m=f.data,u=t.size;for(let c=0;c<u;c++){const l=Number(t.iget(c)),a=Math.trunc(l);m[c]=a,i[c]=l-a}return[r,f]}function Ft(t,r,f){S(t.dtype,"clip","clip is not supported for complex numbers.");const i=t.dtype,m=Array.from(t.shape),u=t.size,c=b.zeros(m,i),l=c.data,a=r===null||typeof r=="number",e=f===null||typeof f=="number",s=r===null?-1/0:typeof r=="number"?r:null,o=f===null?1/0:typeof f=="number"?f:null,n=t.isCContiguous,y=t.data,p=t.offset,d=!a&&r.isCContiguous,A=a?null:r.data,g=a?0:r.offset,h=a?0:r.size,C=!e&&f.isCContiguous,w=e?null:f.data,v=e?0:f.offset,U=e?0:f.size;if(N(i)){const I=l;if(n&&(a||d)&&(e||C)){const z=y,B=A,V=w;for(let O=0;O<u;O++){let R=z[p+O];const L=a?s===-1/0?R:BigInt(Math.round(s)):B[g+O%h],E=e?o===1/0?R:BigInt(Math.round(o)):V[v+O%U];R<L&&(R=L),R>E&&(R=E),I[O]=R}}else for(let z=0;z<u;z++){let B=t.iget(z);const V=a?s===-1/0?B:BigInt(Math.round(s)):r.iget(z%r.size),O=e?o===1/0?B:BigInt(Math.round(o)):f.iget(z%f.size);B<V&&(B=V),B>O&&(B=O),I[z]=B}}else if(n&&(a||d)&&(e||C))for(let I=0;I<u;I++){let z=Number(y[p+I]);const B=a?s:Number(A[g+I%h]),V=e?o:Number(w[v+I%U]);z<B&&(z=B),z>V&&(z=V),l[I]=z}else for(let I=0;I<u;I++){let z=Number(t.iget(I));const B=a?s:Number(r.iget(I%r.size)),V=e?o:Number(f.iget(I%f.size));z<B&&(z=B),z>V&&(z=V),l[I]=z}return c}function Ct(t,r){if(S(t.dtype,"maximum","maximum is not supported for complex numbers."),typeof r!="number"&&S(r.dtype,"maximum","maximum is not supported for complex numbers."),typeof r=="number"){const f=t.dtype,i=Array.from(t.shape),m=t.size,u=b.zeros(i,f),c=u.data,l=t.data;if(N(f)){const a=c,e=l,s=BigInt(Math.round(r));for(let o=0;o<m;o++)a[o]=e[o]>s?e[o]:s}else for(let a=0;a<m;a++){const e=Number(l[a]);c[a]=isNaN(e)||isNaN(r)?NaN:Math.max(e,r)}return u}return D(t,r,(f,i)=>isNaN(f)||isNaN(i)?NaN:Math.max(f,i),"maximum")}function vt(t,r){if(S(t.dtype,"minimum","minimum is not supported for complex numbers."),typeof r!="number"&&S(r.dtype,"minimum","minimum is not supported for complex numbers."),typeof r=="number"){const f=t.dtype,i=Array.from(t.shape),m=t.size,u=b.zeros(i,f),c=u.data,l=t.data;if(N(f)){const a=c,e=l,s=BigInt(Math.round(r));for(let o=0;o<m;o++)a[o]=e[o]<s?e[o]:s}else for(let a=0;a<m;a++){const e=Number(l[a]);c[a]=isNaN(e)||isNaN(r)?NaN:Math.min(e,r)}return u}return D(t,r,(f,i)=>isNaN(f)||isNaN(i)?NaN:Math.min(f,i),"minimum")}function Tt(t,r){if(S(t.dtype,"fmax","fmax is not supported for complex numbers."),typeof r!="number"&&S(r.dtype,"fmax","fmax is not supported for complex numbers."),typeof r=="number"){const f=t.dtype,i=Array.from(t.shape),m=t.size,u=b.zeros(i,f),c=u.data,l=t.data;if(N(f)){const a=c,e=l,s=BigInt(Math.round(r));for(let o=0;o<m;o++)a[o]=e[o]>s?e[o]:s}else for(let a=0;a<m;a++){const e=Number(l[a]);isNaN(e)?c[a]=r:isNaN(r)?c[a]=e:c[a]=Math.max(e,r)}return u}return D(t,r,(f,i)=>isNaN(f)?i:isNaN(i)?f:Math.max(f,i),"fmax")}function Ut(t,r){if(S(t.dtype,"fmin","fmin is not supported for complex numbers."),typeof r!="number"&&S(r.dtype,"fmin","fmin is not supported for complex numbers."),typeof r=="number"){const f=t.dtype,i=Array.from(t.shape),m=t.size,u=b.zeros(i,f),c=u.data,l=t.data;if(N(f)){const a=c,e=l,s=BigInt(Math.round(r));for(let o=0;o<m;o++)a[o]=e[o]<s?e[o]:s}else for(let a=0;a<m;a++){const e=Number(l[a]);isNaN(e)?c[a]=r:isNaN(r)?c[a]=e:c[a]=Math.min(e,r)}return u}return D(t,r,(f,i)=>isNaN(f)?i:isNaN(i)?f:Math.min(f,i),"fmin")}function Vt(t,r=0,f,i){S(t.dtype,"nan_to_num","nan_to_num is not supported for complex numbers.");const m=t.dtype,u=Array.from(t.shape),c=t.size,l=f!==void 0?f:Number.MAX_VALUE,a=i!==void 0?i:-Number.MAX_VALUE,e=b.zeros(u,m),s=e.data,o=t.data;if(N(m)){const n=s,y=o;for(let p=0;p<c;p++)n[p]=y[p]}else for(let n=0;n<c;n++){const y=Number(o[n]);isNaN(y)?s[n]=r:y===1/0?s[n]=l:y===-1/0?s[n]=a:s[n]=y}return e}function wt(t,r,f,i,m){S(t.dtype,"interp","interp is not supported for complex numbers."),S(r.dtype,"interp","interp is not supported for complex numbers."),S(f.dtype,"interp","interp is not supported for complex numbers.");const u=Array.from(t.shape),c=t.size,l=b.zeros(u,"float64"),a=l.data,e=t.data,s=r.data,o=f.data,n=r.size,y=i!==void 0?i:Number(o[0]),p=m!==void 0?m:Number(o[n-1]);for(let d=0;d<c;d++){const A=Number(e[d]);if(A<=Number(s[0])){a[d]=y;continue}if(A>=Number(s[n-1])){a[d]=p;continue}let g=0,h=n-1;for(;h-g>1;){const z=Math.floor((g+h)/2);Number(s[z])<=A?g=z:h=z}const C=Number(s[g]),w=Number(s[h]),v=Number(o[g]),U=Number(o[h]),I=(A-C)/(w-C);a[d]=v+I*(U-v)}return l}function Ot(t,r=Math.PI,f=-1,i=2*Math.PI){S(t.dtype,"unwrap","unwrap is not supported for complex numbers.");const m=Array.from(t.shape),u=m.length;if(f<0&&(f+=u),f<0||f>=u)throw new Error(`axis ${f} is out of bounds for array of dimension ${u}`);if(u===1){const e=t.size,s=b.zeros(m,"float64"),o=s.data,n=t.data;if(e===0)return s;o[0]=Number(n[0]);let y=0;for(let p=1;p<e;p++){const d=Number(n[p-1]),A=Number(n[p]);let g=A-d;g=(g+i/2)%i-i/2,g===-i/2&&A-d>0&&(g=i/2),Math.abs(g)>r&&(y-=Math.round((A-d-g)/i)*i),o[p]=A+y}return s}const c=b.zeros(m,"float64"),l=c.data,a=t.data;for(let e=0;e<t.size;e++)l[e]=Number(a[e]);if(u===2){const[e,s]=m;if(f===0)for(let o=0;o<s;o++){let n=0;for(let y=1;y<e;y++){const p=(y-1)*s+o,d=y*s+o,A=l[p],g=l[d];let h=g-A;h=(h+i/2)%i-i/2,h===-i/2&&g-A>0&&(h=i/2),Math.abs(h)>r&&(n-=Math.round((g-A-h)/i)*i),l[d]=g+n}}else for(let o=0;o<e;o++){let n=0;for(let y=1;y<s;y++){const p=o*s+(y-1),d=o*s+y,A=l[p],g=l[d];let h=g-A;h=(h+i/2)%i-i/2,h===-i/2&&g-A>0&&(h=i/2),Math.abs(h)>r&&(n-=Math.round((g-A-h)/i)*i),l[d]=g+n}}}return c}function Rt(t){S(t.dtype,"sinc","sinc is not supported for complex numbers.");const r=Array.from(t.shape),f=t.size,i=b.zeros(r,"float64"),m=i.data,u=t.data;for(let c=0;c<f;c++){const l=Number(u[c]);if(l===0)m[c]=1;else{const a=Math.PI*l;m[c]=Math.sin(a)/a}}return i}function qt(t){S(t.dtype,"i0","i0 is not supported for complex numbers.");const r=Array.from(t.shape),f=t.size,i=b.zeros(r,"float64"),m=i.data,u=t.data;for(let c=0;c<f;c++){const l=Math.abs(Number(u[c]));m[c]=_(l)}return i}function _(t){const r=Math.abs(t);if(r<3.75){const f=t/3.75,i=f*f;return 1+i*(3.5156229+i*(3.0899424+i*(1.2067492+i*(.2659732+i*(.0360768+i*.0045813)))))}else{const f=3.75/r;return Math.exp(r)/Math.sqrt(r)*(.39894228+f*(.01328592+f*(.00225319+f*(-.00157565+f*(.00916281+f*(-.02057706+f*(.02635537+f*(-.01647633+f*.00392377))))))))}}export{ut as absolute,at as add,pt as cbrt,Ft as clip,ft as divide,gt as divmod,dt as fabs,St as float_power,Y as floorDivide,Tt as fmax,Ut as fmin,Nt as fmod,zt as frexp,Mt as gcd,ht as heaviside,qt as i0,wt as interp,It as lcm,Bt as ldexp,Ct as maximum,vt as minimum,$ as mod,Dt as modf,it as multiply,Vt as nan_to_num,ct as negative,yt as positive,mt as reciprocal,bt as remainder,lt as sign,Rt as sinc,At as square,nt as subtract,Ot as unwrap};
1
+ import{ArrayStorage as b}from"../storage.js";import{isBigIntDType as N,isComplexDType as I,isIntegerDType as _,getComplexComponentDType as x,promoteDTypes as P,throwIfComplex as S}from"../dtype.js";import{elementwiseBinaryOp as v}from"../internal/compute.js";import{wasmAdd as tt,wasmAddScalar as rt}from"../wasm/add.js";import{wasmSub as et,wasmSubScalar as ot}from"../wasm/sub.js";import{wasmMul as st,wasmMulScalar as nt}from"../wasm/mul.js";import{wasmDiv as E,wasmDivScalar as at}from"../wasm/divide.js";import{wasmNeg as it}from"../wasm/neg.js";import{wasmAbs as ft}from"../wasm/abs.js";import{wasmSign as ut}from"../wasm/sign.js";import{wasmMin as j,wasmMinScalar as G}from"../wasm/min.js";import{wasmMax as k,wasmMaxScalar as H}from"../wasm/max.js";import{wasmClip as ct}from"../wasm/clip.js";import{wasmSquare as lt}from"../wasm/square.js";import{wasmReciprocal as mt}from"../wasm/reciprocal.js";import{wasmHeavisideScalar as yt,wasmHeaviside as pt}from"../wasm/heaviside.js";import{wasmLdexpScalar as dt}from"../wasm/ldexp.js";import{wasmFrexp as gt}from"../wasm/frexp.js";import{wasmGcdScalar as J,wasmGcd as At}from"../wasm/gcd.js";function V(t,r){return t.isCContiguous&&r.isCContiguous&&t.shape.length===r.shape.length&&t.shape.every((s,c)=>s===r.shape[c])}function R(t,r){return[t[r*2],t[r*2+1]]}function T(t,r,s,c){t[r*2]=s,t[r*2+1]=c}function Qt(t,r){if(typeof r=="number")return K(t,r);if(r.size===1&&!I(r.dtype)&&t.dtype===r.dtype){const s=Number(r.iget(0));return K(t,s)}if(V(t,r)){const s=tt(t,r);return s||bt(t,r)}return v(t,r,(s,c)=>s+c,"add")}function bt(t,r){const s=P(t.dtype,r.dtype),c=b.zeros(Array.from(t.shape),s),y=t.size,f=t.data,u=r.data,m=c.data,a=t.offset,n=r.offset;if(I(s)){const o=m,e=I(t.dtype),i=I(r.dtype);for(let l=0;l<y;l++){const[p,d]=e?R(f,a+l):[Number(f[a+l]),0],[g,A]=i?R(u,n+l):[Number(u[n+l]),0];T(o,l,p+g,d+A)}return c}if(N(s)){const o=m;if(!N(t.dtype)||!N(r.dtype))for(let i=0;i<y;i++){const l=typeof f[a+i]=="bigint"?f[a+i]:BigInt(Math.round(Number(f[a+i]))),p=typeof u[n+i]=="bigint"?u[n+i]:BigInt(Math.round(Number(u[n+i])));o[i]=l+p}else{const i=f,l=u;for(let p=0;p<y;p++)o[p]=i[a+p]+l[n+p]}}else if(N(t.dtype)||N(r.dtype))for(let e=0;e<y;e++){const i=typeof f[a+e]=="bigint"?Number(f[a+e]):f[a+e],l=typeof u[n+e]=="bigint"?Number(u[n+e]):u[n+e];m[e]=i+l}else if(a===0&&n===0)for(let e=0;e<y;e++)m[e]=f[e]+u[e];else for(let e=0;e<y;e++)m[e]=f[a+e]+u[n+e];return c}function Wt(t,r){if(typeof r=="number")return Q(t,r);if(r.size===1&&!I(r.dtype)&&t.dtype===r.dtype){const s=Number(r.iget(0));return Q(t,s)}if(V(t,r)){const s=et(t,r);return s||ht(t,r)}return v(t,r,(s,c)=>s-c,"subtract")}function ht(t,r){const s=P(t.dtype,r.dtype),c=b.zeros(Array.from(t.shape),s),y=t.size,f=t.data,u=r.data,m=c.data,a=t.offset,n=r.offset;if(I(s)){const o=m,e=I(t.dtype),i=I(r.dtype);for(let l=0;l<y;l++){const[p,d]=e?R(f,a+l):[Number(f[a+l]),0],[g,A]=i?R(u,n+l):[Number(u[n+l]),0];T(o,l,p-g,d-A)}return c}if(N(s)){const o=m;if(!N(t.dtype)||!N(r.dtype))for(let i=0;i<y;i++){const l=typeof f[a+i]=="bigint"?f[a+i]:BigInt(Math.round(Number(f[a+i]))),p=typeof u[n+i]=="bigint"?u[n+i]:BigInt(Math.round(Number(u[n+i])));o[i]=l-p}else{const i=f,l=u;for(let p=0;p<y;p++)o[p]=i[a+p]-l[n+p]}}else if(N(t.dtype)||N(r.dtype))for(let e=0;e<y;e++){const i=typeof f[a+e]=="bigint"?Number(f[a+e]):f[a+e],l=typeof u[n+e]=="bigint"?Number(u[n+e]):u[n+e];m[e]=i-l}else if(a===0&&n===0)for(let e=0;e<y;e++)m[e]=f[e]-u[e];else for(let e=0;e<y;e++)m[e]=f[a+e]-u[n+e];return c}function Yt(t,r){if(typeof r=="number")return W(t,r);if(r.size===1&&!I(r.dtype)&&t.dtype===r.dtype){const s=Number(r.iget(0));return W(t,s)}if(V(t,r)){const s=st(t,r);return s||St(t,r)}return v(t,r,(s,c)=>s*c,"multiply")}function St(t,r){const s=P(t.dtype,r.dtype),c=b.zeros(Array.from(t.shape),s),y=t.size,f=t.data,u=r.data,m=c.data,a=t.offset,n=r.offset;if(I(s)){const o=m,e=I(t.dtype),i=I(r.dtype);for(let l=0;l<y;l++){const[p,d]=e?R(f,a+l):[Number(f[a+l]),0],[g,A]=i?R(u,n+l):[Number(u[n+l]),0],h=p*g-d*A,z=p*A+d*g;T(o,l,h,z)}return c}if(N(s)){const o=m;if(!N(t.dtype)||!N(r.dtype))for(let i=0;i<y;i++){const l=typeof f[a+i]=="bigint"?f[a+i]:BigInt(Math.round(Number(f[a+i]))),p=typeof u[n+i]=="bigint"?u[n+i]:BigInt(Math.round(Number(u[n+i])));o[i]=l*p}else{const i=f,l=u;for(let p=0;p<y;p++)o[p]=i[a+p]*l[n+p]}}else if(N(t.dtype)||N(r.dtype))for(let e=0;e<y;e++){const i=typeof f[a+e]=="bigint"?Number(f[a+e]):f[a+e],l=typeof u[n+e]=="bigint"?Number(u[n+e]):u[n+e];m[e]=i*l}else if(a===0&&n===0)for(let e=0;e<y;e++)m[e]=f[e]*u[e];else for(let e=0;e<y;e++)m[e]=f[a+e]*u[n+e];return c}function Zt(t,r){if(typeof r=="number")return Y(t,r);if(r.size===1&&!I(r.dtype)&&!I(t.dtype)){const e=Number(r.iget(0));return Y(t,e)}const s=I(t.dtype),c=I(r.dtype);if(s||c){const e=P(t.dtype,r.dtype);if(s&&c&&t.dtype===r.dtype&&V(t,r)){const z=E(t,r);if(z)return z}const i=b.zeros(Array.from(t.shape),e),l=i.data,p=t.size,d=t.data,g=r.data,A=t.offset,h=r.offset;for(let z=0;z<p;z++){const[C,w]=s?R(d,A+z):[Number(d[A+z]),0],[F,D]=c?R(g,h+z):[Number(g[h+z]),0],M=F*F+D*D,B=(C*F+w*D)/M,U=(w*F-C*D)/M;T(l,z,B,U)}return i}if(t.dtype===r.dtype&&V(t,r)){const e=E(t,r);if(e)return e}const y=t.dtype==="float64",f=r.dtype==="float64",u=t.dtype==="float32",m=r.dtype==="float32";let a;u&&m||(u||m)&&!y&&!f?a="float32":a="float64";const n=t.dtype===a?t:L(t,a),o=r.dtype===a?r:L(r,a);if(V(n,o)){const e=E(n,o);if(e)return e}return v(n,o,(e,i)=>e/i,"divide")}function L(t,r){const s=b.zeros(Array.from(t.shape),r),c=t.size,y=s.data;if(t.isCContiguous){const f=t.data,u=t.offset;for(let m=0;m<c;m++)y[m]=Number(f[u+m])}else for(let f=0;f<c;f++)y[f]=Number(t.iget(f));return s}function K(t,r){const s=rt(t,r);if(s)return s;const c=t.dtype,y=Array.from(t.shape),f=t.data,u=t.size,m=t.offset,a=t.isCContiguous,n=b.zeros(y,c),o=n.data;if(I(c)){const e=f,i=o;if(a)for(let l=0;l<u;l++){const[p,d]=R(e,m+l);T(i,l,p+r,d)}else for(let l=0;l<u;l++){const p=t.iget(l),d=p.re??Number(p),g=p.im??0;T(i,l,d+r,g)}}else if(N(c)){const e=o,i=BigInt(Math.round(r));if(a){const l=f;for(let p=0;p<u;p++)e[p]=l[m+p]+i}else for(let l=0;l<u;l++)e[l]=t.iget(l)+i}else if(a)if(m===0)for(let e=0;e<u;e++)o[e]=Number(f[e])+r;else for(let e=0;e<u;e++)o[e]=Number(f[m+e])+r;else for(let e=0;e<u;e++)o[e]=Number(t.iget(e))+r;return n}function Q(t,r){const s=ot(t,r);if(s)return s;const c=t.dtype,y=Array.from(t.shape),f=t.data,u=t.size,m=t.offset,a=t.isCContiguous,n=b.zeros(y,c),o=n.data;if(I(c)){const e=f,i=o;if(a)for(let l=0;l<u;l++){const[p,d]=R(e,m+l);T(i,l,p-r,d)}else for(let l=0;l<u;l++){const p=t.iget(l),d=p.re??Number(p),g=p.im??0;T(i,l,d-r,g)}}else if(N(c)){const e=o,i=BigInt(Math.round(r));if(a){const l=f;for(let p=0;p<u;p++)e[p]=l[m+p]-i}else for(let l=0;l<u;l++)e[l]=t.iget(l)-i}else if(a)for(let e=0;e<u;e++)o[e]=Number(f[m+e])-r;else for(let e=0;e<u;e++)o[e]=Number(t.iget(e))-r;return n}function W(t,r){const s=nt(t,r);if(s)return s;const c=t.dtype,y=Array.from(t.shape),f=t.data,u=t.size,m=t.offset,a=t.isCContiguous,n=b.zeros(y,c),o=n.data;if(I(c)){const e=f,i=o;if(a)for(let l=0;l<u;l++){const[p,d]=R(e,m+l);T(i,l,p*r,d*r)}else for(let l=0;l<u;l++){const p=t.iget(l),d=p.re??Number(p),g=p.im??0;T(i,l,d*r,g*r)}}else if(N(c)){const e=o,i=BigInt(Math.round(r));if(a){const l=f;for(let p=0;p<u;p++)e[p]=l[m+p]*i}else for(let l=0;l<u;l++)e[l]=t.iget(l)*i}else if(a)if(m===0)for(let e=0;e<u;e++)o[e]=Number(f[e])*r;else for(let e=0;e<u;e++)o[e]=Number(f[m+e])*r;else for(let e=0;e<u;e++)o[e]=Number(t.iget(e))*r;return n}function Y(t,r){const s=t.dtype;if(I(s)){const i=Array.from(t.shape),l=t.data,p=t.size,d=t.offset,g=t.isCContiguous,A=b.zeros(i,s),h=A.data;if(g){const z=l;for(let C=0;C<p;C++){const[w,F]=R(z,d+C);T(h,C,w/r,F/r)}}else for(let z=0;z<p;z++){const C=t.iget(z),w=C.re??Number(C),F=C.im??0;T(h,z,w/r,F/r)}return A}const c=at(t,r);if(c)return c;const f=s==="float16"||s==="float32"||s==="float64"?t:L(t,"float64"),u=Array.from(f.shape),m=f.size,a=b.zeros(u,f.dtype),n=a.data,o=f.data,e=f.offset;if(f.isCContiguous)for(let i=0;i<m;i++)n[i]=o[e+i]/r;else for(let i=0;i<m;i++)n[i]=Number(f.iget(i))/r;return a}function _t(t){const r=ft(t);if(r)return r;const s=t.dtype,c=Array.from(t.shape),y=t.data,f=t.size,u=t.offset,m=t.isCContiguous;if(I(s)){const o=x(s),e=b.zeros(c,o),i=e.data;if(m){const l=y;for(let p=0;p<f;p++){const d=l[(u+p)*2],g=l[(u+p)*2+1];i[p]=Math.sqrt(d*d+g*g)}}else for(let l=0;l<f;l++){const p=t.iget(l),d=p.re??Number(p),g=p.im??0;i[l]=Math.sqrt(d*d+g*g)}return e}const a=b.zeros(c,s),n=a.data;if(N(s)){const o=n;if(m){const e=y;for(let i=0;i<f;i++){const l=e[u+i];o[i]=l<0n?-l:l}}else for(let e=0;e<f;e++){const i=t.iget(e);o[e]=i<0n?-i:i}}else if(m)if(u===0)for(let o=0;o<f;o++)n[o]=Math.abs(Number(y[o]));else for(let o=0;o<f;o++)n[o]=Math.abs(Number(y[u+o]));else for(let o=0;o<f;o++)n[o]=Math.abs(Number(t.iget(o)));return a}function xt(t){const r=it(t);if(r)return r;const s=t.dtype,c=Array.from(t.shape),y=t.data,f=t.size,u=t.offset,m=t.isCContiguous,a=b.zeros(c,s),n=a.data;if(I(s)){const o=n;if(m){const e=y;for(let i=0;i<f;i++){const[l,p]=R(e,u+i);T(o,i,-l,-p)}}else for(let e=0;e<f;e++){const i=t.iget(e),l=i.re??Number(i),p=i.im??0;T(o,e,-l,-p)}}else if(N(s)){const o=n;if(m){const e=y;for(let i=0;i<f;i++)o[i]=-e[u+i]}else for(let e=0;e<f;e++)o[e]=-t.iget(e)}else if(m)if(u===0)for(let o=0;o<f;o++)n[o]=-Number(y[o]);else for(let o=0;o<f;o++)n[o]=-Number(y[u+o]);else for(let o=0;o<f;o++)n[o]=-Number(t.iget(o));return a}function tr(t){S(t.dtype,"sign","Sign is not defined for complex numbers.");const r=ut(t);if(r)return r;const s=t.dtype,c=Array.from(t.shape),y=t.data,f=t.size,u=t.offset,m=t.isCContiguous,a=b.zeros(c,s),n=a.data;if(N(s)){const o=n;if(m){const e=y;for(let i=0;i<f;i++){const l=e[u+i];o[i]=l>0n?1n:l<0n?-1n:0n}}else for(let e=0;e<f;e++){const i=t.iget(e);o[e]=i>0n?1n:i<0n?-1n:0n}}else if(m)for(let o=0;o<f;o++){const e=Number(y[u+o]);n[o]=e>0?1:e<0?-1:0}else for(let o=0;o<f;o++){const e=Number(t.iget(o));n[o]=e>0?1:e<0?-1:0}return a}function Z(t,r){return S(t.dtype,"mod","Modulo is not defined for complex numbers."),typeof r!="number"&&S(r.dtype,"mod","Modulo is not defined for complex numbers."),typeof r=="number"?Nt(t,r):v(t,r,(s,c)=>(s%c+c)%c,"mod")}function Nt(t,r){const s=t.dtype,c=Array.from(t.shape),y=t.data,f=t.size,u=t.offset,m=t.isCContiguous,a=b.zeros(c,s),n=a.data;if(N(s)){const o=n,e=BigInt(Math.round(r));if(m){const i=y;for(let l=0;l<f;l++){const p=i[u+l];o[l]=(p%e+e)%e}}else for(let i=0;i<f;i++){const l=t.iget(i);o[i]=(l%e+e)%e}}else if(m)for(let o=0;o<f;o++){const e=Number(y[u+o]);n[o]=(e%r+r)%r}else for(let o=0;o<f;o++){const e=Number(t.iget(o));n[o]=(e%r+r)%r}return a}function zt(t,r){return S(t.dtype,"floor_divide","Floor division is not defined for complex numbers."),typeof r!="number"&&S(r.dtype,"floor_divide","Floor division is not defined for complex numbers."),typeof r=="number"?Mt(t,r):v(t,r,(s,c)=>Math.floor(s/c),"floor_divide")}function Mt(t,r){const s=t.dtype,c=Array.from(t.shape),y=t.data,f=t.size,u=t.offset,m=t.isCContiguous,a=b.zeros(c,s),n=a.data;if(N(s)){const o=n,e=BigInt(Math.round(r));if(m){const i=y;for(let l=0;l<f;l++)o[l]=i[u+l]/e}else for(let i=0;i<f;i++)o[i]=t.iget(i)/e}else if(m)for(let o=0;o<f;o++)n[o]=Math.floor(Number(y[u+o])/r);else for(let o=0;o<f;o++)n[o]=Math.floor(Number(t.iget(o))/r);return a}function rr(t){const r=t.dtype,s=Array.from(t.shape),c=t.data,y=t.size,f=t.offset,u=t.isCContiguous,m=b.zeros(s,r),a=m.data;if(I(r)){const n=a;if(u){const o=c;n.set(o.subarray(f*2,(f+y)*2))}else for(let o=0;o<y;o++){const e=t.iget(o);n[o*2]=e.re??Number(e),n[o*2+1]=e.im??0}}else if(u)a.set(c.subarray(f,f+y));else for(let n=0;n<y;n++)a[n]=t.iget(n);return m}function er(t){const r=mt(t);if(r)return r;const s=t.dtype,c=Array.from(t.shape),y=t.data,f=t.size,u=t.offset,m=t.isCContiguous;if(I(s)){const i=b.zeros(c,s),l=i.data;if(m){const p=y;for(let d=0;d<f;d++){const g=p[(u+d)*2],A=p[(u+d)*2+1],h=g*g+A*A;l[d*2]=g/h,l[d*2+1]=-A/h}}else for(let p=0;p<f;p++){const d=t.iget(p),g=d.re??Number(d),A=d.im??0,h=g*g+A*A;l[p*2]=g/h,l[p*2+1]=-A/h}return i}const n=s!=="float32"&&s!=="float64"?"float64":s,o=b.zeros(c,n),e=o.data;if(m)if(u===0)for(let i=0;i<f;i++)e[i]=1/Number(y[i]);else for(let i=0;i<f;i++)e[i]=1/Number(y[u+i]);else for(let i=0;i<f;i++)e[i]=1/Number(t.iget(i));return o}function or(t){const r=t.dtype;S(r,"cbrt","cbrt is not supported for complex numbers.");const s=Array.from(t.shape),c=t.data,y=t.size,f=t.offset,m=r!=="float32"&&r!=="float64"?"float64":r,a=b.zeros(s,m),n=a.data;if(t.isCContiguous)for(let o=0;o<y;o++)n[o]=Math.cbrt(Number(c[f+o]));else for(let o=0;o<y;o++)n[o]=Math.cbrt(Number(t.iget(o)));return a}function sr(t){const r=t.dtype;S(r,"fabs","fabs is only for real numbers. Use absolute() for complex.");const s=Array.from(t.shape),c=t.data,y=t.size,f=t.offset,u=r==="float32"?"float32":"float64",m=b.zeros(s,u),a=m.data;if(t.isCContiguous)if(f===0)for(let n=0;n<y;n++)a[n]=Math.abs(Number(c[n]));else for(let n=0;n<y;n++)a[n]=Math.abs(Number(c[f+n]));else for(let n=0;n<y;n++)a[n]=Math.abs(Number(t.iget(n)));return m}function nr(t,r){const s=zt(t,r),c=Z(t,r);return[s,c]}function ar(t){const r=lt(t);if(r)return r;const s=t.dtype,c=Array.from(t.shape),y=t.data,f=t.size,u=b.zeros(c,s),m=u.data;if(I(s)){const a=y,n=m;for(let o=0;o<f;o++){const e=a[o*2],i=a[o*2+1];n[o*2]=e*e-i*i,n[o*2+1]=2*e*i}}else if(N(s)){const a=y,n=m;for(let o=0;o<f;o++)n[o]=a[o]*a[o]}else for(let a=0;a<f;a++){const n=Number(y[a]);m[a]=n*n}return u}function ir(t,r){return Z(t,r)}function Dt(t,r){S(t.dtype,"heaviside","Heaviside step function is not defined for complex numbers."),typeof r!="number"&&S(r.dtype,"heaviside","Heaviside step function is not defined for complex numbers.");const s=t.dtype,c=Array.from(t.shape),y=t.size,f=s==="float32"?"float32":"float64",u=t.dtype===f?t:L(t,f);if(typeof r!="number"&&r.size===1)return Dt(t,Number(r.iget(0)));if(typeof r=="number"){const m=yt(u,r,f);if(m)return m;const a=b.zeros(c,f),n=a.data;if(u.isCContiguous){const o=u.data,e=u.offset;for(let i=0;i<y;i++){const l=o[e+i];n[i]=l<0?0:l===0?r:1}}else for(let o=0;o<y;o++){const e=Number(t.iget(o));n[o]=e<0?0:e===0?r:1}return a}else{const m=r.shape,a=r.dtype===f?r:L(r,f);if(c.every((n,o)=>n===m[o])){const n=pt(u,a,f);if(n)return n;const o=b.zeros(c,f),e=o.data;if(u.isCContiguous&&a.isCContiguous){const i=u.data,l=u.offset,p=a.data,d=a.offset;for(let g=0;g<y;g++){const A=i[l+g];e[g]=A<0?0:A===0?p[d+g]:1}}else for(let i=0;i<y;i++){const l=Number(t.iget(i));e[i]=l<0?0:l===0?Number(r.iget(i)):1}return o}else{const n=b.zeros(c,f),o=n.data;for(let e=0;e<y;e++){const i=Number(t.iget(e)),l=e%r.size;o[e]=i<0?0:i===0?Number(r.iget(l)):1}return n}}}function fr(t,r){const s=t.dtype;if(I(s)){const c=t.size,y=b.zeros(Array.from(t.shape),s),f=y.data;if(typeof r=="number")if(t.isCContiguous){const u=t.data,m=t.offset;for(let a=0;a<c;a++){const n=u[(m+a)*2],o=u[(m+a)*2+1],e=Math.hypot(n,o),i=Math.atan2(o,n),l=Math.pow(e,r),p=i*r;f[a*2]=l*Math.cos(p),f[a*2+1]=l*Math.sin(p)}}else for(let u=0;u<c;u++){const m=t.iget(u),a=Math.hypot(m.re,m.im),n=Math.atan2(m.im,m.re),o=Math.pow(a,r),e=n*r;f[u*2]=o*Math.cos(e),f[u*2+1]=o*Math.sin(e)}else{const u=I(r.dtype);if(t.isCContiguous&&r.isCContiguous){const m=t.data,a=t.offset,n=r.data,o=r.offset;for(let e=0;e<c;e++){const i=m[(a+e)*2],l=m[(a+e)*2+1];let p,d;if(u){const D=n;p=D[(o+e)*2],d=D[(o+e)*2+1]}else p=Number(n[o+e]),d=0;const g=Math.hypot(i,l),A=Math.atan2(l,i),h=Math.log(g),z=A,C=p*h-d*z,w=p*z+d*h,F=Math.exp(C);f[e*2]=F*Math.cos(w),f[e*2+1]=F*Math.sin(w)}}else for(let m=0;m<c;m++){const a=t.iget(m);let n,o;if(u){const h=r.iget(m);n=h.re,o=h.im}else n=Number(r.iget(m)),o=0;const e=Math.hypot(a.re,a.im),i=Math.atan2(a.im,a.re),l=Math.log(e),p=i,d=n*l-o*p,g=n*p+o*l,A=Math.exp(d);f[m*2]=A*Math.cos(g),f[m*2+1]=A*Math.sin(g)}}return y}if(typeof r=="number"){const c=b.zeros(Array.from(t.shape),"float64"),y=c.data,f=t.size;if(t.isCContiguous){const u=t.data,m=t.offset;for(let a=0;a<f;a++)y[a]=Math.pow(Number(u[m+a]),r)}else for(let u=0;u<f;u++)y[u]=Math.pow(Number(t.iget(u)),r);return c}return v(t,r,(c,y)=>Math.pow(c,y),"float_power")}function ur(t,r){if(S(t.dtype,"fmod","fmod is not defined for complex numbers."),typeof r!="number"&&S(r.dtype,"fmod","fmod is not defined for complex numbers."),typeof r=="number"){const s=t.copy(),c=s.data,y=t.size;for(let f=0;f<y;f++){const u=Number(c[f]);c[f]=u-Math.trunc(u/r)*r}return s}return v(t,r,(s,c)=>s-Math.trunc(s/c)*c,"fmod")}function cr(t){S(t.dtype,"frexp","frexp is not defined for complex numbers.");const r=gt(t);if(r)return r;const s=b.zeros(Array.from(t.shape),"float64"),c=b.zeros(Array.from(t.shape),"int32"),y=s.data,f=c.data,u=t.size;if(t.isCContiguous){const m=t.data,a=t.offset;for(let n=0;n<u;n++){const o=Number(m[a+n]);if(o===0||!isFinite(o))y[n]=o,f[n]=0;else{const e=Math.floor(Math.log2(Math.abs(o)))+1;y[n]=o/Math.pow(2,e),f[n]=e}}}else for(let m=0;m<u;m++){const a=Number(t.iget(m));if(a===0||!isFinite(a))y[m]=a,f[m]=0;else{const n=Math.floor(Math.log2(Math.abs(a)))+1;y[m]=a/Math.pow(2,n),f[m]=n}}return[s,c]}function lr(t,r){S(t.dtype,"gcd","GCD is only defined for integers."),typeof r!="number"&&S(r.dtype,"gcd","GCD is only defined for integers.");const s=(m,a)=>{for(m=Math.abs(Math.trunc(m)),a=Math.abs(Math.trunc(a));a!==0;){const n=a;a=m%a,m=n}return m};if(typeof r=="number"){const m=J(t,r);if(m)return m;const a=b.zeros(Array.from(t.shape),"int32"),n=a.data,o=t.size,e=Math.abs(Math.trunc(r));if(t.isCContiguous){const i=t.data,l=t.offset;for(let p=0;p<o;p++)n[p]=s(Number(i[l+p]),e)}else for(let i=0;i<o;i++)n[i]=s(Number(t.iget(i)),e);return a}if(typeof r!="number"&&r.size===1){const m=Number(r.iget(0)),a=J(t,m);if(a)return a}if(typeof r!="number"&&V(t,r)){const m=At(t,r);if(m)return m}const c=v(t,r,s,"gcd"),y=b.zeros(Array.from(c.shape),"int32"),f=y.data,u=c.size;if(c.isCContiguous){const m=c.data,a=c.offset;for(let n=0;n<u;n++)f[n]=Math.round(Number(m[a+n]))}else for(let m=0;m<u;m++)f[m]=Math.round(Number(c.iget(m)));return y}function mr(t,r){S(t.dtype,"lcm","LCM is only defined for integers."),typeof r!="number"&&S(r.dtype,"lcm","LCM is only defined for integers.");const s=(a,n)=>{for(a=Math.abs(Math.trunc(a)),n=Math.abs(Math.trunc(n));n!==0;){const o=n;n=a%n,a=o}return a},c=(a,n)=>(a=Math.abs(Math.trunc(a)),n=Math.abs(Math.trunc(n)),a===0||n===0?0:a*n/s(a,n));if(typeof r=="number"){const a=b.zeros(Array.from(t.shape),"int32"),n=a.data,o=t.size,e=Math.abs(Math.trunc(r));if(t.isCContiguous){const i=t.data,l=t.offset;for(let p=0;p<o;p++)n[p]=c(Number(i[l+p]),e)}else for(let i=0;i<o;i++)n[i]=c(Number(t.iget(i)),e);return a}const y=v(t,r,c,"lcm"),f=b.zeros(Array.from(y.shape),"int32"),u=f.data,m=y.size;if(y.isCContiguous){const a=y.data,n=y.offset;for(let o=0;o<m;o++)u[o]=Math.round(Number(a[n+o]))}else for(let a=0;a<m;a++)u[a]=Math.round(Number(y.iget(a)));return f}function It(t,r){if(S(t.dtype,"ldexp","ldexp is not defined for complex numbers."),typeof r!="number"&&(S(r.dtype,"ldexp","ldexp is not defined for complex numbers."),r.size===1))return It(t,Number(r.iget(0)));if(typeof r=="number"){const s=t.dtype==="float32"?"float32":"float64",c=t.dtype===s?t:L(t,s),y=dt(c,r);if(y)return y;const f=b.zeros(Array.from(t.shape),"float64"),u=f.data,m=t.size,a=Math.pow(2,r);if(t.isCContiguous){const n=t.data,o=t.offset;for(let e=0;e<m;e++)u[e]=Number(n[o+e])*a}else for(let n=0;n<m;n++)u[n]=Number(t.iget(n))*a;return f}return v(t,r,(s,c)=>s*Math.pow(2,c),"ldexp")}function yr(t){S(t.dtype,"modf","modf is not defined for complex numbers.");const r=b.zeros(Array.from(t.shape),"float64"),s=b.zeros(Array.from(t.shape),"float64"),c=r.data,y=s.data,f=t.size;for(let u=0;u<f;u++){const m=Number(t.iget(u)),a=Math.trunc(m);y[u]=a,c[u]=m-a}return[r,s]}function pr(t,r,s){if(S(t.dtype,"clip","clip is not supported for complex numbers."),(r===null||typeof r=="number")&&(s===null||typeof s=="number")){const B=ct(t,r===null?-1/0:r,s===null?1/0:s);if(B)return B}const c=t.dtype,y=Array.from(t.shape),f=t.size,u=b.zeros(y,c),m=u.data,a=r===null||typeof r=="number",n=s===null||typeof s=="number",o=r===null?-1/0:typeof r=="number"?r:null,e=s===null?1/0:typeof s=="number"?s:null,i=t.isCContiguous,l=t.data,p=t.offset,d=!a&&r.isCContiguous,g=a?null:r.data,A=a?0:r.offset,h=a?0:r.size,z=!n&&s.isCContiguous,C=n?null:s.data,w=n?0:s.offset,F=n?0:s.size;if(N(c)){const D=m;if(i&&(a||d)&&(n||z)){const M=l,B=g,U=C;for(let O=0;O<f;O++){let q=M[p+O];const X=a?o===-1/0?q:BigInt(Math.round(o)):B[A+O%h],$=n?e===1/0?q:BigInt(Math.round(e)):U[w+O%F];q<X&&(q=X),q>$&&(q=$),D[O]=q}}else for(let M=0;M<f;M++){let B=t.iget(M);const U=a?o===-1/0?B:BigInt(Math.round(o)):r.iget(M%r.size),O=n?e===1/0?B:BigInt(Math.round(e)):s.iget(M%s.size);B<U&&(B=U),B>O&&(B=O),D[M]=B}}else if(i&&(a||d)&&(n||z))for(let D=0;D<f;D++){let M=Number(l[p+D]);const B=a?o:Number(g[A+D%h]),U=n?e:Number(C[w+D%F]);M<B&&(M=B),M>U&&(M=U),m[D]=M}else for(let D=0;D<f;D++){let M=Number(t.iget(D));const B=a?o:Number(r.iget(D%r.size)),U=n?e:Number(s.iget(D%s.size));M<B&&(M=B),M>U&&(M=U),m[D]=M}return u}function dr(t,r){if(S(t.dtype,"maximum","maximum is not supported for complex numbers."),typeof r!="number"&&S(r.dtype,"maximum","maximum is not supported for complex numbers."),typeof r=="number"){const s=H(t,r);if(s)return s}else if(r.size===1){const s=H(t,Number(r.iget(0)));if(s)return s}else if(V(t,r)){const s=k(t,r);if(s)return s}if(typeof r=="number"){const s=t.dtype,c=Array.from(t.shape),y=t.size,f=b.zeros(c,s),u=f.data,m=t.data;if(N(s)){const a=u,n=m,o=BigInt(Math.round(r));for(let e=0;e<y;e++)a[e]=n[e]>o?n[e]:o}else for(let a=0;a<y;a++){const n=Number(m[a]);u[a]=isNaN(n)||isNaN(r)?NaN:Math.max(n,r)}return f}return v(t,r,(s,c)=>isNaN(s)||isNaN(c)?NaN:Math.max(s,c),"maximum")}function gr(t,r){if(S(t.dtype,"minimum","minimum is not supported for complex numbers."),typeof r!="number"&&S(r.dtype,"minimum","minimum is not supported for complex numbers."),typeof r=="number"){const s=G(t,r);if(s)return s}else if(r.size===1){const s=G(t,Number(r.iget(0)));if(s)return s}else if(V(t,r)){const s=j(t,r);if(s)return s}if(typeof r=="number"){const s=t.dtype,c=Array.from(t.shape),y=t.size,f=b.zeros(c,s),u=f.data,m=t.data;if(N(s)){const a=u,n=m,o=BigInt(Math.round(r));for(let e=0;e<y;e++)a[e]=n[e]<o?n[e]:o}else for(let a=0;a<y;a++){const n=Number(m[a]);u[a]=isNaN(n)||isNaN(r)?NaN:Math.min(n,r)}return f}return v(t,r,(s,c)=>isNaN(s)||isNaN(c)?NaN:Math.min(s,c),"minimum")}function Ar(t,r){if(S(t.dtype,"fmax","fmax is not supported for complex numbers."),typeof r!="number"&&S(r.dtype,"fmax","fmax is not supported for complex numbers."),typeof r=="number"){const s=H(t,r);if(s)return s}else if(r.size===1){const s=H(t,Number(r.iget(0)));if(s)return s}else if(V(t,r)){const s=k(t,r);if(s)return s}if(typeof r=="number"){const s=t.dtype,c=Array.from(t.shape),y=t.size,f=b.zeros(c,s),u=f.data,m=t.data;if(N(s)){const a=u,n=m,o=BigInt(Math.round(r));for(let e=0;e<y;e++)a[e]=n[e]>o?n[e]:o}else for(let a=0;a<y;a++){const n=Number(m[a]);isNaN(n)?u[a]=r:isNaN(r)?u[a]=n:u[a]=Math.max(n,r)}return f}return v(t,r,(s,c)=>isNaN(s)?c:isNaN(c)?s:Math.max(s,c),"fmax")}function br(t,r){if(S(t.dtype,"fmin","fmin is not supported for complex numbers."),typeof r!="number"&&S(r.dtype,"fmin","fmin is not supported for complex numbers."),typeof r=="number"){const s=G(t,r);if(s)return s}else if(r.size===1){const s=G(t,Number(r.iget(0)));if(s)return s}else if(V(t,r)){const s=j(t,r);if(s)return s}if(typeof r=="number"){const s=t.dtype,c=Array.from(t.shape),y=t.size,f=b.zeros(c,s),u=f.data,m=t.data;if(N(s)){const a=u,n=m,o=BigInt(Math.round(r));for(let e=0;e<y;e++)a[e]=n[e]<o?n[e]:o}else for(let a=0;a<y;a++){const n=Number(m[a]);isNaN(n)?u[a]=r:isNaN(r)?u[a]=n:u[a]=Math.min(n,r)}return f}return v(t,r,(s,c)=>isNaN(s)?c:isNaN(c)?s:Math.min(s,c),"fmin")}function hr(t,r=0,s,c){S(t.dtype,"nan_to_num","nan_to_num is not supported for complex numbers.");const y=t.dtype,f=Array.from(t.shape),u=t.size,m=s!==void 0?s:Number.MAX_VALUE,a=c!==void 0?c:-Number.MAX_VALUE,n=b.zeros(f,y),o=n.data,e=t.data;if(_(y))o.set(e.subarray(t.offset,t.offset+u));else for(let i=0;i<u;i++){const l=Number(e[i]);isNaN(l)?o[i]=r:l===1/0?o[i]=m:l===-1/0?o[i]=a:o[i]=l}return n}function Sr(t,r,s,c,y){S(t.dtype,"interp","interp is not supported for complex numbers."),S(r.dtype,"interp","interp is not supported for complex numbers."),S(s.dtype,"interp","interp is not supported for complex numbers.");const f=Array.from(t.shape),u=t.size,m=b.zeros(f,"float64"),a=m.data,n=t.data,o=r.data,e=s.data,i=r.size,l=c!==void 0?c:Number(e[0]),p=y!==void 0?y:Number(e[i-1]);for(let d=0;d<u;d++){const g=Number(n[d]);if(g<=Number(o[0])){a[d]=l;continue}if(g>=Number(o[i-1])){a[d]=p;continue}let A=0,h=i-1;for(;h-A>1;){const M=Math.floor((A+h)/2);Number(o[M])<=g?A=M:h=M}const z=Number(o[A]),C=Number(o[h]),w=Number(e[A]),F=Number(e[h]),D=(g-z)/(C-z);a[d]=w+D*(F-w)}return m}function Nr(t,r=Math.PI,s=-1,c=2*Math.PI){S(t.dtype,"unwrap","unwrap is not supported for complex numbers.");const y=Array.from(t.shape),f=y.length;if(s<0&&(s+=f),s<0||s>=f)throw new Error(`axis ${s} is out of bounds for array of dimension ${f}`);if(f===1){const n=t.size,o=b.zeros(y,"float64"),e=o.data,i=t.data;if(n===0)return o;e[0]=Number(i[0]);let l=0;for(let p=1;p<n;p++){const d=Number(i[p-1]),g=Number(i[p]);let A=g-d;A=(A+c/2)%c-c/2,A===-c/2&&g-d>0&&(A=c/2),Math.abs(A)>r&&(l-=Math.round((g-d-A)/c)*c),e[p]=g+l}return o}const u=b.zeros(y,"float64"),m=u.data,a=t.data;for(let n=0;n<t.size;n++)m[n]=Number(a[n]);if(f===2){const[n,o]=y;if(s===0)for(let e=0;e<o;e++){let i=0;for(let l=1;l<n;l++){const p=(l-1)*o+e,d=l*o+e,g=m[p],A=m[d];let h=A-g;h=(h+c/2)%c-c/2,h===-c/2&&A-g>0&&(h=c/2),Math.abs(h)>r&&(i-=Math.round((A-g-h)/c)*c),m[d]=A+i}}else for(let e=0;e<n;e++){let i=0;for(let l=1;l<o;l++){const p=e*o+(l-1),d=e*o+l,g=m[p],A=m[d];let h=A-g;h=(h+c/2)%c-c/2,h===-c/2&&A-g>0&&(h=c/2),Math.abs(h)>r&&(i-=Math.round((A-g-h)/c)*c),m[d]=A+i}}}return u}function zr(t){S(t.dtype,"sinc","sinc is not supported for complex numbers.");const r=Array.from(t.shape),s=t.size,c=b.zeros(r,"float64"),y=c.data,f=t.data;for(let u=0;u<s;u++){const m=Number(f[u]);if(m===0)y[u]=1;else{const a=Math.PI*m;y[u]=Math.sin(a)/a}}return c}function Mr(t){S(t.dtype,"i0","i0 is not supported for complex numbers.");const r=Array.from(t.shape),s=t.size,c=b.zeros(r,"float64"),y=c.data,f=t.data;for(let u=0;u<s;u++){const m=Math.abs(Number(f[u]));y[u]=Bt(m)}return c}function Bt(t){const r=Math.abs(t);if(r<3.75){const s=t/3.75,c=s*s;return 1+c*(3.5156229+c*(3.0899424+c*(1.2067492+c*(.2659732+c*(.0360768+c*.0045813)))))}else{const s=3.75/r;return Math.exp(r)/Math.sqrt(r)*(.39894228+s*(.01328592+s*(.00225319+s*(-.00157565+s*(.00916281+s*(-.02057706+s*(.02635537+s*(-.01647633+s*.00392377))))))))}}export{_t as absolute,Qt as add,or as cbrt,pr as clip,Zt as divide,nr as divmod,sr as fabs,fr as float_power,zt as floorDivide,Ar as fmax,br as fmin,ur as fmod,cr as frexp,lr as gcd,Dt as heaviside,Mr as i0,Sr as interp,mr as lcm,It as ldexp,dr as maximum,gr as minimum,Z as mod,yr as modf,Yt as multiply,hr as nan_to_num,xt as negative,rr as positive,er as reciprocal,ir as remainder,tr as sign,zr as sinc,ar as square,Wt as subtract,Nr as unwrap};
@@ -1 +1 @@
1
- import{ArrayStorage as C}from"../storage";import{isBigIntDType as z,isIntegerDType as L,promoteDTypes as F}from"../dtype";import{elementwiseBinaryOp as R}from"../internal/compute";function _(t,r){if(!L(t)&&t!=="bool")throw new TypeError(`ufunc '${r}' not supported for the input types, and the inputs could not be safely coerced to any supported types`)}function E(t,r){return t.isCContiguous&&r.isCContiguous&&t.shape.length===r.shape.length&&t.shape.every((c,l)=>c===r.shape[l])}function ut(t,r){return _(t.dtype,"bitwise_and"),typeof r=="number"?W(t,r):(_(r.dtype,"bitwise_and"),E(t,r)?Q(t,r):R(t,r,(c,l)=>c&l,"bitwise_and"))}function Q(t,r){const c=F(t.dtype,r.dtype),l=C.zeros(Array.from(t.shape),c),f=t.size,i=t.data,s=r.data,d=t.offset,u=r.offset,o=l.data;if(z(c)){const e=o;if(!z(t.dtype)||!z(r.dtype))for(let n=0;n<f;n++){const a=typeof i[d+n]=="bigint"?i[d+n]:BigInt(Math.round(Number(i[d+n]))),g=typeof s[u+n]=="bigint"?s[u+n]:BigInt(Math.round(Number(s[u+n])));e[n]=a&g}else{const n=i,a=s;for(let g=0;g<f;g++)e[g]=n[d+g]&a[u+g]}}else for(let e=0;e<f;e++)o[e]=i[d+e]&s[u+e];return l}function W(t,r){const c=t.dtype,l=Array.from(t.shape),f=t.data,i=t.offset,s=t.size,d=t.isCContiguous,u=C.zeros(l,c),o=u.data;if(z(c)){const e=o,y=BigInt(Math.round(r));if(d){const n=f;if(i===0)for(let a=0;a<s;a++)e[a]=n[a]&y;else for(let a=0;a<s;a++)e[a]=n[i+a]&y}else for(let n=0;n<s;n++)e[n]=t.iget(n)&y}else if(d)if(i===0)for(let e=0;e<s;e++)o[e]=f[e]&r;else for(let e=0;e<s;e++)o[e]=f[i+e]&r;else for(let e=0;e<s;e++)o[e]=Number(t.iget(e))&r;return u}function ct(t,r){return _(t.dtype,"bitwise_or"),typeof r=="number"?Z(t,r):(_(r.dtype,"bitwise_or"),E(t,r)?Y(t,r):R(t,r,(c,l)=>c|l,"bitwise_or"))}function Y(t,r){const c=F(t.dtype,r.dtype),l=C.zeros(Array.from(t.shape),c),f=t.size,i=t.data,s=r.data,d=t.offset,u=r.offset,o=l.data;if(z(c)){const e=o;if(!z(t.dtype)||!z(r.dtype))for(let n=0;n<f;n++){const a=typeof i[d+n]=="bigint"?i[d+n]:BigInt(Math.round(Number(i[d+n]))),g=typeof s[u+n]=="bigint"?s[u+n]:BigInt(Math.round(Number(s[u+n])));e[n]=a|g}else{const n=i,a=s;for(let g=0;g<f;g++)e[g]=n[d+g]|a[u+g]}}else for(let e=0;e<f;e++)o[e]=i[d+e]|s[u+e];return l}function Z(t,r){const c=t.dtype,l=Array.from(t.shape),f=t.data,i=t.offset,s=t.size,d=t.isCContiguous,u=C.zeros(l,c),o=u.data;if(z(c)){const e=o,y=BigInt(Math.round(r));if(d){const n=f;if(i===0)for(let a=0;a<s;a++)e[a]=n[a]|y;else for(let a=0;a<s;a++)e[a]=n[i+a]|y}else for(let n=0;n<s;n++)e[n]=t.iget(n)|y}else if(d)if(i===0)for(let e=0;e<s;e++)o[e]=f[e]|r;else for(let e=0;e<s;e++)o[e]=f[i+e]|r;else for(let e=0;e<s;e++)o[e]=Number(t.iget(e))|r;return u}function yt(t,r){return _(t.dtype,"bitwise_xor"),typeof r=="number"?tt(t,r):(_(r.dtype,"bitwise_xor"),E(t,r)?x(t,r):R(t,r,(c,l)=>c^l,"bitwise_xor"))}function x(t,r){const c=F(t.dtype,r.dtype),l=C.zeros(Array.from(t.shape),c),f=t.size,i=t.data,s=r.data,d=t.offset,u=r.offset,o=l.data;if(z(c)){const e=o;if(!z(t.dtype)||!z(r.dtype))for(let n=0;n<f;n++){const a=typeof i[d+n]=="bigint"?i[d+n]:BigInt(Math.round(Number(i[d+n]))),g=typeof s[u+n]=="bigint"?s[u+n]:BigInt(Math.round(Number(s[u+n])));e[n]=a^g}else{const n=i,a=s;for(let g=0;g<f;g++)e[g]=n[d+g]^a[u+g]}}else for(let e=0;e<f;e++)o[e]=i[d+e]^s[u+e];return l}function tt(t,r){const c=t.dtype,l=Array.from(t.shape),f=t.data,i=t.offset,s=t.size,d=t.isCContiguous,u=C.zeros(l,c),o=u.data;if(z(c)){const e=o,y=BigInt(Math.round(r));if(d){const n=f;if(i===0)for(let a=0;a<s;a++)e[a]=n[a]^y;else for(let a=0;a<s;a++)e[a]=n[i+a]^y}else for(let n=0;n<s;n++)e[n]=t.iget(n)^y}else if(d)if(i===0)for(let e=0;e<s;e++)o[e]=f[e]^r;else for(let e=0;e<s;e++)o[e]=f[i+e]^r;else for(let e=0;e<s;e++)o[e]=Number(t.iget(e))^r;return u}function H(t){_(t.dtype,"bitwise_not");const r=t.dtype,c=Array.from(t.shape),l=t.data,f=t.offset,i=t.size,s=t.isCContiguous,d=C.zeros(c,r),u=d.data;if(z(r)){const o=u;if(s){const e=l;if(f===0)for(let y=0;y<i;y++)o[y]=~e[y];else for(let y=0;y<i;y++)o[y]=~e[f+y]}else for(let e=0;e<i;e++)o[e]=~t.iget(e)}else if(s)if(f===0)for(let o=0;o<i;o++)u[o]=~l[o];else for(let o=0;o<i;o++)u[o]=~l[f+o];else for(let o=0;o<i;o++)u[o]=~Number(t.iget(o));return d}function lt(t){return H(t)}function et(t,r){if(_(t.dtype,"left_shift"),typeof r=="number")return J(t,r);if(_(r.dtype,"left_shift"),r.size===1||r.ndim===1&&r.shape[0]===1){const c=Number(r.iget(0));return J(t,c)}return E(t,r)?rt(t,r):R(t,r,(c,l)=>c<<l,"left_shift")}function rt(t,r){const c=F(t.dtype,r.dtype),l=C.zeros(Array.from(t.shape),c),f=t.size,i=t.data,s=r.data,d=t.offset,u=r.offset,o=l.data;if(z(c)){const e=o;for(let y=0;y<f;y++){const n=typeof i[d+y]=="bigint"?i[d+y]:BigInt(Math.round(Number(i[d+y]))),a=typeof s[u+y]=="bigint"?s[u+y]:BigInt(Math.round(Number(s[u+y])));e[y]=n<<a}}else for(let e=0;e<f;e++)o[e]=i[d+e]<<s[u+e];return l}function J(t,r){const c=t.dtype,l=Array.from(t.shape),f=t.data,i=t.offset,s=t.size,d=t.isCContiguous,u=C.zeros(l,c),o=u.data;if(z(c)){const e=o,y=BigInt(Math.round(r));if(d){const n=f;if(i===0)for(let a=0;a<s;a++)e[a]=n[a]<<y;else for(let a=0;a<s;a++)e[a]=n[i+a]<<y}else for(let n=0;n<s;n++)e[n]=t.iget(n)<<y}else if(d)if(i===0)for(let e=0;e<s;e++)o[e]=f[e]<<r;else for(let e=0;e<s;e++)o[e]=f[i+e]<<r;else for(let e=0;e<s;e++)o[e]=Number(t.iget(e))<<r;return u}function ot(t,r){if(_(t.dtype,"right_shift"),typeof r=="number")return K(t,r);if(_(r.dtype,"right_shift"),r.size===1||r.ndim===1&&r.shape[0]===1){const c=Number(r.iget(0));return K(t,c)}return E(t,r)?nt(t,r):R(t,r,(c,l)=>c>>l,"right_shift")}function nt(t,r){const c=F(t.dtype,r.dtype),l=C.zeros(Array.from(t.shape),c),f=t.size,i=t.data,s=r.data,d=t.offset,u=r.offset,o=l.data;if(z(c)){const e=o;for(let y=0;y<f;y++){const n=typeof i[d+y]=="bigint"?i[d+y]:BigInt(Math.round(Number(i[d+y]))),a=typeof s[u+y]=="bigint"?s[u+y]:BigInt(Math.round(Number(s[u+y])));e[y]=n>>a}}else for(let e=0;e<f;e++)o[e]=i[d+e]>>s[u+e];return l}function K(t,r){const c=t.dtype,l=Array.from(t.shape),f=t.data,i=t.offset,s=t.size,d=t.isCContiguous,u=C.zeros(l,c),o=u.data;if(z(c)){const e=o,y=BigInt(Math.round(r));if(d){const n=f;if(i===0)for(let a=0;a<s;a++)e[a]=n[a]>>y;else for(let a=0;a<s;a++)e[a]=n[i+a]>>y}else for(let n=0;n<s;n++)e[n]=t.iget(n)>>y}else if(d)if(i===0)for(let e=0;e<s;e++)o[e]=f[e]>>r;else for(let e=0;e<s;e++)o[e]=f[i+e]>>r;else for(let e=0;e<s;e++)o[e]=Number(t.iget(e))>>r;return u}function dt(t,r=-1,c="big"){const l=Array.from(t.shape),f=l.length;if(r<0&&(r=f+r),r<0||r>=f)throw new Error(`axis ${r} is out of bounds for array of dimension ${f}`);const i=l[r],s=Math.ceil(i/8),d=[...l];d[r]=s;const u=C.zeros(d,"uint8"),o=u.data,e=t.offset,y=t.isCContiguous;if(f===1){for(let I=0;I<s;I++){let p=0;for(let b=0;b<8;b++){const S=I*8+b;if(S<i){const w=y?Number(t.data[e+S])!==0?1:0:Number(t.iget(S))!==0?1:0;c==="big"?p|=w<<7-b:p|=w<<b}}o[I]=p}return u}const n=l.slice(0,r),a=l.slice(r+1),g=n.reduce((I,p)=>I*p,1),X=a.reduce((I,p)=>I*p,1),k=$(l),v=$(d);for(let I=0;I<g;I++)for(let p=0;p<X;p++)for(let b=0;b<s;b++){let S=0;for(let h=0;h<8;h++){const A=b*8+h;if(A<i){let B=0,D=I;for(let T=0;T<r;T++){const N=T<r-1?n.slice(T+1).reduce((P,j)=>P*j,1):1,V=Math.floor(D/N);D%=N,B+=V*k[T]}B+=A*k[r];let m=p;for(let T=r+1;T<f;T++){const N=T<f-1?a.slice(T-r).reduce((P,j)=>P*j,1):1,V=Math.floor(m/N);m%=N,B+=V*k[T]}const U=y?Number(t.data[e+B])!==0?1:0:Number(t.iget(B))!==0?1:0;c==="big"?S|=U<<7-h:S|=U<<h}}let w=0,M=I;for(let h=0;h<r;h++){const A=h<r-1?n.slice(h+1).reduce((D,m)=>D*m,1):1,B=Math.floor(M/A);M%=A,w+=B*v[h]}w+=b*v[r];let O=p;for(let h=r+1;h<f;h++){const A=h<f-1?a.slice(h-r).reduce((D,m)=>D*m,1):1,B=Math.floor(O/A);O%=A,w+=B*v[h]}o[w]=S}return u}function gt(t,r=-1,c=-1,l="big"){if(t.dtype!=="uint8")throw new TypeError("Expected an input array of unsigned byte data type");const f=Array.from(t.shape),i=f.length;if(r<0&&(r=i+r),r<0||r>=i)throw new Error(`axis ${r} is out of bounds for array of dimension ${i}`);const s=f[r];let d=s*8;c>=0&&(d=c);const u=[...f];u[r]=d;const o=C.zeros(u,"uint8"),e=o.data,y=t.offset,n=t.isCContiguous;if(i===1){for(let p=0;p<s;p++){const b=Number(n?t.data[y+p]:t.iget(p));for(let S=0;S<8;S++){const w=p*8+S;if(w>=d)break;l==="big"?e[w]=b>>7-S&1:e[w]=b>>S&1}}return o}const a=f.slice(0,r),g=f.slice(r+1),X=a.reduce((p,b)=>p*b,1),k=g.reduce((p,b)=>p*b,1),v=$(f),I=$(u);for(let p=0;p<X;p++)for(let b=0;b<k;b++)for(let S=0;S<s;S++){let w=0,M=p;for(let A=0;A<r;A++){const B=A<r-1?a.slice(A+1).reduce((m,U)=>m*U,1):1,D=Math.floor(M/B);M%=B,w+=D*v[A]}w+=S*v[r];let O=b;for(let A=r+1;A<i;A++){const B=A<i-1?g.slice(A-r).reduce((m,U)=>m*U,1):1,D=Math.floor(O/B);O%=B,w+=D*v[A]}const h=Number(n?t.data[y+w]:t.iget(w));for(let A=0;A<8;A++){const B=S*8+A;if(B>=d)break;let D=0;M=p;for(let m=0;m<r;m++){const U=m<r-1?a.slice(m+1).reduce((N,V)=>N*V,1):1,T=Math.floor(M/U);M%=U,D+=T*I[m]}D+=B*I[r],O=b;for(let m=r+1;m<i;m++){const U=m<i-1?g.slice(m-r).reduce((N,V)=>N*V,1):1,T=Math.floor(O/U);O%=U,D+=T*I[m]}l==="big"?e[D]=h>>7-A&1:e[D]=h>>A&1}}return o}function $(t){const r=t.length,c=new Array(r);let l=1;for(let f=r-1;f>=0;f--)c[f]=l,l*=t[f];return c}function pt(t){const r=t.dtype;_(r,"bitwise_count");const c=Array.from(t.shape),l=t.data,f=t.offset,i=t.size,s=t.isCContiguous,d=C.zeros(c,"uint8"),u=d.data;if(z(r))if(s){const o=l;if(f===0)for(let e=0;e<i;e++)u[e]=G(o[e]);else for(let e=0;e<i;e++)u[e]=G(o[f+e])}else for(let o=0;o<i;o++)u[o]=G(t.iget(o));else if(s)if(f===0)for(let o=0;o<i;o++)u[o]=q(l[o]);else for(let o=0;o<i;o++)u[o]=q(l[f+o]);else for(let o=0;o<i;o++)u[o]=q(Number(t.iget(o)));return d}function q(t){t=t>>>0;let r=0;for(;t!==0;)t=t&t-1,r++;return r}function G(t){t<0n&&(t=BigInt.asUintN(64,t));let r=0;for(;t!==0n;)t=t&t-1n,r++;return r}function At(t){return H(t)}function bt(t,r){return et(t,r)}function mt(t,r){return ot(t,r)}export{ut as bitwise_and,pt as bitwise_count,At as bitwise_invert,bt as bitwise_left_shift,H as bitwise_not,ct as bitwise_or,mt as bitwise_right_shift,yt as bitwise_xor,lt as invert,et as left_shift,dt as packbits,ot as right_shift,gt as unpackbits};
1
+ import{ArrayStorage as T}from"../storage.js";import{isBigIntDType as w,isIntegerDType as J,promoteDTypes as F}from"../dtype.js";import{elementwiseBinaryOp as E}from"../internal/compute.js";import{wasmBitwiseAnd as K}from"../wasm/bitwise_and.js";import{wasmBitwiseOr as Q}from"../wasm/bitwise_or.js";import{wasmBitwiseXor as W}from"../wasm/bitwise_xor.js";import{wasmBitwiseNot as Y}from"../wasm/bitwise_not.js";import{wasmLeftShift as Z,wasmLeftShiftScalar as tt}from"../wasm/left_shift.js";import{wasmRightShift as et,wasmRightShiftScalar as rt}from"../wasm/right_shift.js";import{wasmBitwiseCount as ot}from"../wasm/bitwise_count.js";function U(t,r){if(!J(t)&&t!=="bool")throw new TypeError(`ufunc '${r}' not supported for the input types, and the inputs could not be safely coerced to any supported types`)}function $(t,r){return t.isCContiguous&&r.isCContiguous&&t.shape.length===r.shape.length&&t.shape.every((a,l)=>a===r.shape[l])}function Ct(t,r){if(U(t.dtype,"bitwise_and"),typeof r=="number")return nt(t,r);if(U(r.dtype,"bitwise_and"),$(t,r)){const a=K(t,r);return a||it(t,r)}return E(t,r,(a,l)=>a&l,"bitwise_and")}function it(t,r){const a=F(t.dtype,r.dtype),l=T.zeros(Array.from(t.shape),a),u=t.size,f=t.data,i=r.data,y=t.offset,d=r.offset,c=l.data;if(w(a)){const e=c;if(!w(t.dtype)||!w(r.dtype))for(let o=0;o<u;o++){const s=typeof f[y+o]=="bigint"?f[y+o]:BigInt(Math.round(Number(f[y+o]))),p=typeof i[d+o]=="bigint"?i[d+o]:BigInt(Math.round(Number(i[d+o])));e[o]=s&p}else{const o=f,s=i;for(let p=0;p<u;p++)e[p]=o[y+p]&s[d+p]}}else for(let e=0;e<u;e++)c[e]=f[y+e]&i[d+e];return l}function nt(t,r){const a=t.dtype,l=Array.from(t.shape),u=t.data,f=t.offset,i=t.size,y=t.isCContiguous,d=T.zeros(l,a),c=d.data;if(w(a)){const e=c,n=BigInt(Math.round(r));if(y){const o=u;if(f===0)for(let s=0;s<i;s++)e[s]=o[s]&n;else for(let s=0;s<i;s++)e[s]=o[f+s]&n}else for(let o=0;o<i;o++)e[o]=t.iget(o)&n}else if(y)if(f===0)for(let e=0;e<i;e++)c[e]=u[e]&r;else for(let e=0;e<i;e++)c[e]=u[f+e]&r;else for(let e=0;e<i;e++)c[e]=Number(t.iget(e))&r;return d}function Dt(t,r){if(U(t.dtype,"bitwise_or"),typeof r=="number")return at(t,r);if(U(r.dtype,"bitwise_or"),$(t,r)){const a=Q(t,r);return a||st(t,r)}return E(t,r,(a,l)=>a|l,"bitwise_or")}function st(t,r){const a=F(t.dtype,r.dtype),l=T.zeros(Array.from(t.shape),a),u=t.size,f=t.data,i=r.data,y=t.offset,d=r.offset,c=l.data;if(w(a)){const e=c;if(!w(t.dtype)||!w(r.dtype))for(let o=0;o<u;o++){const s=typeof f[y+o]=="bigint"?f[y+o]:BigInt(Math.round(Number(f[y+o]))),p=typeof i[d+o]=="bigint"?i[d+o]:BigInt(Math.round(Number(i[d+o])));e[o]=s|p}else{const o=f,s=i;for(let p=0;p<u;p++)e[p]=o[y+p]|s[d+p]}}else for(let e=0;e<u;e++)c[e]=f[y+e]|i[d+e];return l}function at(t,r){const a=t.dtype,l=Array.from(t.shape),u=t.data,f=t.offset,i=t.size,y=t.isCContiguous,d=T.zeros(l,a),c=d.data;if(w(a)){const e=c,n=BigInt(Math.round(r));if(y){const o=u;if(f===0)for(let s=0;s<i;s++)e[s]=o[s]|n;else for(let s=0;s<i;s++)e[s]=o[f+s]|n}else for(let o=0;o<i;o++)e[o]=t.iget(o)|n}else if(y)if(f===0)for(let e=0;e<i;e++)c[e]=u[e]|r;else for(let e=0;e<i;e++)c[e]=u[f+e]|r;else for(let e=0;e<i;e++)c[e]=Number(t.iget(e))|r;return d}function Tt(t,r){if(U(t.dtype,"bitwise_xor"),typeof r=="number")return ut(t,r);if(U(r.dtype,"bitwise_xor"),$(t,r)){const a=W(t,r);return a||ft(t,r)}return E(t,r,(a,l)=>a^l,"bitwise_xor")}function ft(t,r){const a=F(t.dtype,r.dtype),l=T.zeros(Array.from(t.shape),a),u=t.size,f=t.data,i=r.data,y=t.offset,d=r.offset,c=l.data;if(w(a)){const e=c;if(!w(t.dtype)||!w(r.dtype))for(let o=0;o<u;o++){const s=typeof f[y+o]=="bigint"?f[y+o]:BigInt(Math.round(Number(f[y+o]))),p=typeof i[d+o]=="bigint"?i[d+o]:BigInt(Math.round(Number(i[d+o])));e[o]=s^p}else{const o=f,s=i;for(let p=0;p<u;p++)e[p]=o[y+p]^s[d+p]}}else for(let e=0;e<u;e++)c[e]=f[y+e]^i[d+e];return l}function ut(t,r){const a=t.dtype,l=Array.from(t.shape),u=t.data,f=t.offset,i=t.size,y=t.isCContiguous,d=T.zeros(l,a),c=d.data;if(w(a)){const e=c,n=BigInt(Math.round(r));if(y){const o=u;if(f===0)for(let s=0;s<i;s++)e[s]=o[s]^n;else for(let s=0;s<i;s++)e[s]=o[f+s]^n}else for(let o=0;o<i;o++)e[o]=t.iget(o)^n}else if(y)if(f===0)for(let e=0;e<i;e++)c[e]=u[e]^r;else for(let e=0;e<i;e++)c[e]=u[f+e]^r;else for(let e=0;e<i;e++)c[e]=Number(t.iget(e))^r;return d}function x(t){U(t.dtype,"bitwise_not");const r=Y(t);if(r)return r;const a=t.dtype,l=Array.from(t.shape),u=t.data,f=t.offset,i=t.size,y=t.isCContiguous,d=T.zeros(l,a),c=d.data;if(w(a)){const e=c;if(y){const n=u;if(f===0)for(let o=0;o<i;o++)e[o]=~n[o];else for(let o=0;o<i;o++)e[o]=~n[f+o]}else for(let n=0;n<i;n++)e[n]=~t.iget(n)}else if(y)if(f===0)for(let e=0;e<i;e++)c[e]=~u[e];else for(let e=0;e<i;e++)c[e]=~u[f+e];else for(let e=0;e<i;e++)c[e]=~Number(t.iget(e));return d}function Nt(t){return x(t)}function ct(t,r){if(U(t.dtype,"left_shift"),typeof r=="number")return G(t,r);if(U(r.dtype,"left_shift"),r.size===1||r.ndim===1&&r.shape[0]===1){const a=Number(r.iget(0)),l=tt(t,a);return l||G(t,a)}if($(t,r)){const a=Z(t,r);return a||lt(t,r)}return E(t,r,(a,l)=>a<<l,"left_shift")}function lt(t,r){const a=F(t.dtype,r.dtype),l=T.zeros(Array.from(t.shape),a),u=t.size,f=t.data,i=r.data,y=t.offset,d=r.offset,c=l.data;if(w(a)){const e=c;for(let n=0;n<u;n++){const o=typeof f[y+n]=="bigint"?f[y+n]:BigInt(Math.round(Number(f[y+n]))),s=typeof i[d+n]=="bigint"?i[d+n]:BigInt(Math.round(Number(i[d+n])));e[n]=o<<s}}else for(let e=0;e<u;e++)c[e]=f[y+e]<<i[d+e];return l}function G(t,r){const a=t.dtype,l=Array.from(t.shape),u=t.data,f=t.offset,i=t.size,y=t.isCContiguous,d=T.zeros(l,a),c=d.data;if(w(a)){const e=c,n=BigInt(Math.round(r));if(y){const o=u;if(f===0)for(let s=0;s<i;s++)e[s]=o[s]<<n;else for(let s=0;s<i;s++)e[s]=o[f+s]<<n}else for(let o=0;o<i;o++)e[o]=t.iget(o)<<n}else if(y)if(f===0)for(let e=0;e<i;e++)c[e]=u[e]<<r;else for(let e=0;e<i;e++)c[e]=u[f+e]<<r;else for(let e=0;e<i;e++)c[e]=Number(t.iget(e))<<r;return d}function yt(t,r){if(U(t.dtype,"right_shift"),typeof r=="number")return H(t,r);if(U(r.dtype,"right_shift"),r.size===1||r.ndim===1&&r.shape[0]===1){const a=Number(r.iget(0)),l=rt(t,a);return l||H(t,a)}if($(t,r)){const a=et(t,r);return a||dt(t,r)}return E(t,r,(a,l)=>a>>l,"right_shift")}function dt(t,r){const a=F(t.dtype,r.dtype),l=T.zeros(Array.from(t.shape),a),u=t.size,f=t.data,i=r.data,y=t.offset,d=r.offset,c=l.data;if(w(a)){const e=c;for(let n=0;n<u;n++){const o=typeof f[y+n]=="bigint"?f[y+n]:BigInt(Math.round(Number(f[y+n]))),s=typeof i[d+n]=="bigint"?i[d+n]:BigInt(Math.round(Number(i[d+n])));e[n]=o>>s}}else for(let e=0;e<u;e++)c[e]=f[y+e]>>i[d+e];return l}function H(t,r){const a=t.dtype,l=Array.from(t.shape),u=t.data,f=t.offset,i=t.size,y=t.isCContiguous,d=T.zeros(l,a),c=d.data;if(w(a)){const e=c,n=BigInt(Math.round(r));if(y){const o=u;if(f===0)for(let s=0;s<i;s++)e[s]=o[s]>>n;else for(let s=0;s<i;s++)e[s]=o[f+s]>>n}else for(let o=0;o<i;o++)e[o]=t.iget(o)>>n}else if(y)if(f===0)for(let e=0;e<i;e++)c[e]=u[e]>>r;else for(let e=0;e<i;e++)c[e]=u[f+e]>>r;else for(let e=0;e<i;e++)c[e]=Number(t.iget(e))>>r;return d}function Ut(t,r=-1,a="big"){const l=Array.from(t.shape),u=l.length;if(r<0&&(r=u+r),r<0||r>=u)throw new Error(`axis ${r} is out of bounds for array of dimension ${u}`);const f=l[r],i=Math.ceil(f/8),y=[...l];y[r]=i;const d=T.zeros(y,"uint8"),c=d.data,e=t.offset,n=t.isCContiguous;if(u===1){for(let z=0;z<i;z++){let g=0;for(let A=0;A<8;A++){const S=z*8+A;if(S<f){const I=n?Number(t.data[e+S])!==0?1:0:Number(t.iget(S))!==0?1:0;a==="big"?g|=I<<7-A:g|=I<<A}}c[z]=g}return d}const o=l.slice(0,r),s=l.slice(r+1),p=o.reduce((z,g)=>z*g,1),L=s.reduce((z,g)=>z*g,1),k=X(l),v=X(y);for(let z=0;z<p;z++)for(let g=0;g<L;g++)for(let A=0;A<i;A++){let S=0;for(let h=0;h<8;h++){const m=A*8+h;if(m<f){let B=0,C=z;for(let D=0;D<r;D++){const _=D<r-1?o.slice(D+1).reduce((P,j)=>P*j,1):1,O=Math.floor(C/_);C%=_,B+=O*k[D]}B+=m*k[r];let b=g;for(let D=r+1;D<u;D++){const _=D<u-1?s.slice(D-r).reduce((P,j)=>P*j,1):1,O=Math.floor(b/_);b%=_,B+=O*k[D]}const N=n?Number(t.data[e+B])!==0?1:0:Number(t.iget(B))!==0?1:0;a==="big"?S|=N<<7-h:S|=N<<h}}let I=0,M=z;for(let h=0;h<r;h++){const m=h<r-1?o.slice(h+1).reduce((C,b)=>C*b,1):1,B=Math.floor(M/m);M%=m,I+=B*v[h]}I+=A*v[r];let R=g;for(let h=r+1;h<u;h++){const m=h<u-1?s.slice(h-r).reduce((C,b)=>C*b,1):1,B=Math.floor(R/m);R%=m,I+=B*v[h]}c[I]=S}return d}function _t(t,r=-1,a=-1,l="big"){if(t.dtype!=="uint8")throw new TypeError("Expected an input array of unsigned byte data type");const u=Array.from(t.shape),f=u.length;if(r<0&&(r=f+r),r<0||r>=f)throw new Error(`axis ${r} is out of bounds for array of dimension ${f}`);const i=u[r];let y=i*8;a>=0&&(y=a);const d=[...u];d[r]=y;const c=T.zeros(d,"uint8"),e=c.data,n=t.offset,o=t.isCContiguous;if(f===1){for(let g=0;g<i;g++){const A=Number(o?t.data[n+g]:t.iget(g));for(let S=0;S<8;S++){const I=g*8+S;if(I>=y)break;l==="big"?e[I]=A>>7-S&1:e[I]=A>>S&1}}return c}const s=u.slice(0,r),p=u.slice(r+1),L=s.reduce((g,A)=>g*A,1),k=p.reduce((g,A)=>g*A,1),v=X(u),z=X(d);for(let g=0;g<L;g++)for(let A=0;A<k;A++)for(let S=0;S<i;S++){let I=0,M=g;for(let m=0;m<r;m++){const B=m<r-1?s.slice(m+1).reduce((b,N)=>b*N,1):1,C=Math.floor(M/B);M%=B,I+=C*v[m]}I+=S*v[r];let R=A;for(let m=r+1;m<f;m++){const B=m<f-1?p.slice(m-r).reduce((b,N)=>b*N,1):1,C=Math.floor(R/B);R%=B,I+=C*v[m]}const h=Number(o?t.data[n+I]:t.iget(I));for(let m=0;m<8;m++){const B=S*8+m;if(B>=y)break;let C=0;M=g;for(let b=0;b<r;b++){const N=b<r-1?s.slice(b+1).reduce((_,O)=>_*O,1):1,D=Math.floor(M/N);M%=N,C+=D*z[b]}C+=B*z[r],R=A;for(let b=r+1;b<f;b++){const N=b<f-1?p.slice(b-r).reduce((_,O)=>_*O,1):1,D=Math.floor(R/N);R%=N,C+=D*z[b]}l==="big"?e[C]=h>>7-m&1:e[C]=h>>m&1}}return c}function X(t){const r=t.length,a=new Array(r);let l=1;for(let u=r-1;u>=0;u--)a[u]=l,l*=t[u];return a}function Mt(t){const r=t.dtype;U(r,"bitwise_count");const a=ot(t);if(a)return a;const l=Array.from(t.shape),u=t.data,f=t.offset,i=t.size,y=t.isCContiguous,d=T.zeros(l,"uint8"),c=d.data,e=r==="int8"||r==="int16"||r==="int32"||r==="int64";if(w(r))if(y){const n=u;if(f===0)for(let o=0;o<i;o++){const s=n[o];c[o]=q(e&&s<0n?-s:s)}else for(let o=0;o<i;o++){const s=n[f+o];c[o]=q(e&&s<0n?-s:s)}}else for(let n=0;n<i;n++){const o=t.iget(n);c[n]=q(e&&o<0n?-o:o)}else if(e)if(y)if(f===0)for(let n=0;n<i;n++)c[n]=V(Math.abs(u[n]));else for(let n=0;n<i;n++)c[n]=V(Math.abs(u[f+n]));else for(let n=0;n<i;n++)c[n]=V(Math.abs(Number(t.iget(n))));else{const n=r==="uint8"?255:r==="uint16"?65535:4294967295;if(y)if(f===0)for(let o=0;o<i;o++)c[o]=V(u[o]&n);else for(let o=0;o<i;o++)c[o]=V(u[f+o]&n);else for(let o=0;o<i;o++)c[o]=V(Number(t.iget(o))&n)}return d}function V(t){t=t>>>0;let r=0;for(;t!==0;)t=t&t-1,r++;return r}function q(t){t<0n&&(t=BigInt.asUintN(64,t));let r=0;for(;t!==0n;)t=t&t-1n,r++;return r}function Rt(t){return x(t)}function vt(t,r){return ct(t,r)}function Ot(t,r){return yt(t,r)}export{Ct as bitwise_and,Mt as bitwise_count,Rt as bitwise_invert,vt as bitwise_left_shift,x as bitwise_not,Dt as bitwise_or,Ot as bitwise_right_shift,Tt as bitwise_xor,Nt as invert,ct as left_shift,Ut as packbits,yt as right_shift,_t as unpackbits};
@@ -1 +1 @@
1
- import{ArrayStorage as y}from"../storage";import{isBigIntDType as z,isComplexDType as c}from"../dtype";import{elementwiseComparisonOp as p}from"../internal/compute";import{computeBroadcastShape as g,broadcastTo as D}from"../broadcasting";import{Complex as v}from"../complex";function d(r,t){return[r[t*2],r[t*2+1]]}function x(r,t){if(c(r.dtype))return d(r.data,t);const o=r.iget(t);return o instanceof v?[o.re,o.im]:[Number(o),0]}function S(r,t,o){const i=g([Array.from(r.shape),Array.from(t.shape)]);if(!i)throw new Error("Cannot broadcast arrays together");const u=D(r,i),e=D(t,i),n=i.reduce((a,s)=>a*s,1),f=new Uint8Array(n);for(let a=0;a<n;a++){const[s,l]=x(u,a),[m,b]=x(e,a);f[a]=o(s,l,m,b)?1:0}return y.fromData(f,i,"bool")}function H(r,t){return typeof t=="number"?B(r,t):c(r.dtype)||c(t.dtype)?S(r,t,(o,i,u,e)=>o!==u?o>u:i>e):p(r,t,(o,i)=>o>i)}function J(r,t){return typeof t=="number"?I(r,t):c(r.dtype)||c(t.dtype)?S(r,t,(o,i,u,e)=>o!==u?o>=u:i>=e):p(r,t,(o,i)=>o>=i)}function K(r,t){return typeof t=="number"?N(r,t):c(r.dtype)||c(t.dtype)?S(r,t,(o,i,u,e)=>o!==u?o<u:i<e):p(r,t,(o,i)=>o<i)}function L(r,t){return typeof t=="number"?U(r,t):c(r.dtype)||c(t.dtype)?S(r,t,(o,i,u,e)=>o!==u?o<=u:i<=e):p(r,t,(o,i)=>o<=i)}function P(r,t){return typeof t=="number"?q(r,t):c(r.dtype)||c(t.dtype)?S(r,t,(o,i,u,e)=>o===u&&i===e):p(r,t,(o,i)=>o===i)}function Q(r,t){return typeof t=="number"?E(r,t):c(r.dtype)||c(t.dtype)?S(r,t,(o,i,u,e)=>o!==u||i!==e):p(r,t,(o,i)=>o!==i)}function w(r,t,o=1e-5,i=1e-8){return typeof t=="number"?M(r,t,o,i):p(r,t,(u,e)=>{const n=Math.abs(u-e),f=i+o*Math.abs(e);return n<=f})}function V(r,t,o=1e-5,i=1e-8){const u=w(r,t,o,i),e=u.data;for(let n=0;n<u.size;n++)if(e[n]===0)return!1;return!0}function W(r,t){const o=[Array.from(r.shape),Array.from(t.shape)],i=g(o);if(i===null)return!1;const u=D(r,i),e=D(t,i),n=i.length,f=i.reduce((l,m)=>l*m,1),a=z(u.dtype),s=z(e.dtype);for(let l=0;l<f;l++){let m=l;const b=new Array(n);for(let A=n-1;A>=0;A--)b[A]=m%i[A],m=Math.floor(m/i[A]);const h=u.get(...b),C=e.get(...b);if(a||s){const A=typeof h=="bigint"?h:BigInt(Number(h)),F=typeof C=="bigint"?C:BigInt(Number(C));if(A!==F)return!1}else if(h!==C)return!1}return!0}function B(r,t){const o=new Uint8Array(r.size),i=r.size,u=r.isCContiguous;if(c(r.dtype))if(u){const e=r.data,n=r.offset;for(let f=0;f<i;f++){const[a,s]=d(e,n+f);o[f]=(a!==t?a>t:s>0)?1:0}}else for(let e=0;e<i;e++){const n=r.iget(e);o[e]=(n.re!==t?n.re>t:n.im>0)?1:0}else if(u){const e=r.data,n=r.offset;for(let f=0;f<i;f++)o[f]=e[n+f]>t?1:0}else for(let e=0;e<i;e++)o[e]=Number(r.iget(e))>t?1:0;return y.fromData(o,Array.from(r.shape),"bool")}function I(r,t){const o=new Uint8Array(r.size),i=r.size,u=r.isCContiguous;if(c(r.dtype))if(u){const e=r.data,n=r.offset;for(let f=0;f<i;f++){const[a,s]=d(e,n+f);o[f]=(a!==t?a>=t:s>=0)?1:0}}else for(let e=0;e<i;e++){const n=r.iget(e);o[e]=(n.re!==t?n.re>=t:n.im>=0)?1:0}else if(u){const e=r.data,n=r.offset;for(let f=0;f<i;f++)o[f]=e[n+f]>=t?1:0}else for(let e=0;e<i;e++)o[e]=Number(r.iget(e))>=t?1:0;return y.fromData(o,Array.from(r.shape),"bool")}function N(r,t){const o=new Uint8Array(r.size),i=r.size,u=r.isCContiguous;if(c(r.dtype))if(u){const e=r.data,n=r.offset;for(let f=0;f<i;f++){const[a,s]=d(e,n+f);o[f]=(a!==t?a<t:s<0)?1:0}}else for(let e=0;e<i;e++){const n=r.iget(e);o[e]=(n.re!==t?n.re<t:n.im<0)?1:0}else if(u){const e=r.data,n=r.offset;for(let f=0;f<i;f++)o[f]=e[n+f]<t?1:0}else for(let e=0;e<i;e++)o[e]=Number(r.iget(e))<t?1:0;return y.fromData(o,Array.from(r.shape),"bool")}function U(r,t){const o=new Uint8Array(r.size),i=r.size,u=r.isCContiguous;if(c(r.dtype))if(u){const e=r.data,n=r.offset;for(let f=0;f<i;f++){const[a,s]=d(e,n+f);o[f]=(a!==t?a<=t:s<=0)?1:0}}else for(let e=0;e<i;e++){const n=r.iget(e);o[e]=(n.re!==t?n.re<=t:n.im<=0)?1:0}else if(u){const e=r.data,n=r.offset;for(let f=0;f<i;f++)o[f]=e[n+f]<=t?1:0}else for(let e=0;e<i;e++)o[e]=Number(r.iget(e))<=t?1:0;return y.fromData(o,Array.from(r.shape),"bool")}function q(r,t){const o=new Uint8Array(r.size),i=r.size,u=r.dtype,e=r.isCContiguous;if(c(u))if(e){const n=r.data,f=r.offset;for(let a=0;a<i;a++){const[s,l]=d(n,f+a);o[a]=s===t&&l===0?1:0}}else for(let n=0;n<i;n++){const f=r.iget(n);o[n]=f.re===t&&f.im===0?1:0}else if(z(u)){const n=BigInt(Math.round(t));if(e){const f=r.data,a=r.offset;for(let s=0;s<i;s++)o[s]=f[a+s]===n?1:0}else for(let f=0;f<i;f++)o[f]=r.iget(f)===n?1:0}else if(e){const n=r.data,f=r.offset;for(let a=0;a<i;a++)o[a]=n[f+a]===t?1:0}else for(let n=0;n<i;n++)o[n]=Number(r.iget(n))===t?1:0;return y.fromData(o,Array.from(r.shape),"bool")}function E(r,t){const o=new Uint8Array(r.size),i=r.size,u=r.dtype,e=r.isCContiguous;if(c(u))if(e){const n=r.data,f=r.offset;for(let a=0;a<i;a++){const[s,l]=d(n,f+a);o[a]=s!==t||l!==0?1:0}}else for(let n=0;n<i;n++){const f=r.iget(n);o[n]=f.re!==t||f.im!==0?1:0}else if(e){const n=r.data,f=r.offset;for(let a=0;a<i;a++)o[a]=n[f+a]!==t?1:0}else for(let n=0;n<i;n++)o[n]=Number(r.iget(n))!==t?1:0;return y.fromData(o,Array.from(r.shape),"bool")}function M(r,t,o,i){const u=new Uint8Array(r.size),e=r.size,n=i+o*Math.abs(t);if(r.isCContiguous){const f=r.data,a=r.offset;for(let s=0;s<e;s++){const l=Math.abs(Number(f[a+s])-t);u[s]=l<=n?1:0}}else for(let f=0;f<e;f++){const a=Math.abs(Number(r.iget(f))-t);u[f]=a<=n?1:0}return y.fromData(u,Array.from(r.shape),"bool")}export{V as allclose,W as arrayEquiv,P as equal,H as greater,J as greaterEqual,w as isclose,K as less,L as lessEqual,Q as notEqual};
1
+ import{ArrayStorage as y}from"../storage.js";import{isBigIntDType as z,isComplexDType as c}from"../dtype.js";import{elementwiseComparisonOp as p}from"../internal/compute.js";import{computeBroadcastShape as g,broadcastTo as D}from"../broadcasting.js";import{Complex as v}from"../complex.js";function d(r,t){return[r[t*2],r[t*2+1]]}function x(r,t){if(c(r.dtype))return d(r.data,t);const o=r.iget(t);return o instanceof v?[o.re,o.im]:[Number(o),0]}function S(r,t,o){const i=g([Array.from(r.shape),Array.from(t.shape)]);if(!i)throw new Error("Cannot broadcast arrays together");const u=D(r,i),e=D(t,i),n=i.reduce((a,s)=>a*s,1),f=new Uint8Array(n);for(let a=0;a<n;a++){const[s,l]=x(u,a),[m,b]=x(e,a);f[a]=o(s,l,m,b)?1:0}return y.fromData(f,i,"bool")}function H(r,t){return typeof t=="number"?B(r,t):c(r.dtype)||c(t.dtype)?S(r,t,(o,i,u,e)=>o!==u?o>u:i>e):p(r,t,(o,i)=>o>i)}function J(r,t){return typeof t=="number"?I(r,t):c(r.dtype)||c(t.dtype)?S(r,t,(o,i,u,e)=>o!==u?o>=u:i>=e):p(r,t,(o,i)=>o>=i)}function K(r,t){return typeof t=="number"?N(r,t):c(r.dtype)||c(t.dtype)?S(r,t,(o,i,u,e)=>o!==u?o<u:i<e):p(r,t,(o,i)=>o<i)}function L(r,t){return typeof t=="number"?U(r,t):c(r.dtype)||c(t.dtype)?S(r,t,(o,i,u,e)=>o!==u?o<=u:i<=e):p(r,t,(o,i)=>o<=i)}function P(r,t){return typeof t=="number"?q(r,t):c(r.dtype)||c(t.dtype)?S(r,t,(o,i,u,e)=>o===u&&i===e):p(r,t,(o,i)=>o===i)}function Q(r,t){return typeof t=="number"?E(r,t):c(r.dtype)||c(t.dtype)?S(r,t,(o,i,u,e)=>o!==u||i!==e):p(r,t,(o,i)=>o!==i)}function w(r,t,o=1e-5,i=1e-8){return typeof t=="number"?M(r,t,o,i):p(r,t,(u,e)=>{const n=Math.abs(u-e),f=i+o*Math.abs(e);return n<=f})}function V(r,t,o=1e-5,i=1e-8){const u=w(r,t,o,i),e=u.data;for(let n=0;n<u.size;n++)if(e[n]===0)return!1;return!0}function W(r,t){const o=[Array.from(r.shape),Array.from(t.shape)],i=g(o);if(i===null)return!1;const u=D(r,i),e=D(t,i),n=i.length,f=i.reduce((l,m)=>l*m,1),a=z(u.dtype),s=z(e.dtype);for(let l=0;l<f;l++){let m=l;const b=new Array(n);for(let A=n-1;A>=0;A--)b[A]=m%i[A],m=Math.floor(m/i[A]);const h=u.get(...b),C=e.get(...b);if(a||s){const A=typeof h=="bigint"?h:BigInt(Number(h)),F=typeof C=="bigint"?C:BigInt(Number(C));if(A!==F)return!1}else if(h!==C)return!1}return!0}function B(r,t){const o=new Uint8Array(r.size),i=r.size,u=r.isCContiguous;if(c(r.dtype))if(u){const e=r.data,n=r.offset;for(let f=0;f<i;f++){const[a,s]=d(e,n+f);o[f]=(a!==t?a>t:s>0)?1:0}}else for(let e=0;e<i;e++){const n=r.iget(e);o[e]=(n.re!==t?n.re>t:n.im>0)?1:0}else if(u){const e=r.data,n=r.offset;for(let f=0;f<i;f++)o[f]=e[n+f]>t?1:0}else for(let e=0;e<i;e++)o[e]=Number(r.iget(e))>t?1:0;return y.fromData(o,Array.from(r.shape),"bool")}function I(r,t){const o=new Uint8Array(r.size),i=r.size,u=r.isCContiguous;if(c(r.dtype))if(u){const e=r.data,n=r.offset;for(let f=0;f<i;f++){const[a,s]=d(e,n+f);o[f]=(a!==t?a>=t:s>=0)?1:0}}else for(let e=0;e<i;e++){const n=r.iget(e);o[e]=(n.re!==t?n.re>=t:n.im>=0)?1:0}else if(u){const e=r.data,n=r.offset;for(let f=0;f<i;f++)o[f]=e[n+f]>=t?1:0}else for(let e=0;e<i;e++)o[e]=Number(r.iget(e))>=t?1:0;return y.fromData(o,Array.from(r.shape),"bool")}function N(r,t){const o=new Uint8Array(r.size),i=r.size,u=r.isCContiguous;if(c(r.dtype))if(u){const e=r.data,n=r.offset;for(let f=0;f<i;f++){const[a,s]=d(e,n+f);o[f]=(a!==t?a<t:s<0)?1:0}}else for(let e=0;e<i;e++){const n=r.iget(e);o[e]=(n.re!==t?n.re<t:n.im<0)?1:0}else if(u){const e=r.data,n=r.offset;for(let f=0;f<i;f++)o[f]=e[n+f]<t?1:0}else for(let e=0;e<i;e++)o[e]=Number(r.iget(e))<t?1:0;return y.fromData(o,Array.from(r.shape),"bool")}function U(r,t){const o=new Uint8Array(r.size),i=r.size,u=r.isCContiguous;if(c(r.dtype))if(u){const e=r.data,n=r.offset;for(let f=0;f<i;f++){const[a,s]=d(e,n+f);o[f]=(a!==t?a<=t:s<=0)?1:0}}else for(let e=0;e<i;e++){const n=r.iget(e);o[e]=(n.re!==t?n.re<=t:n.im<=0)?1:0}else if(u){const e=r.data,n=r.offset;for(let f=0;f<i;f++)o[f]=e[n+f]<=t?1:0}else for(let e=0;e<i;e++)o[e]=Number(r.iget(e))<=t?1:0;return y.fromData(o,Array.from(r.shape),"bool")}function q(r,t){const o=new Uint8Array(r.size),i=r.size,u=r.dtype,e=r.isCContiguous;if(c(u))if(e){const n=r.data,f=r.offset;for(let a=0;a<i;a++){const[s,l]=d(n,f+a);o[a]=s===t&&l===0?1:0}}else for(let n=0;n<i;n++){const f=r.iget(n);o[n]=f.re===t&&f.im===0?1:0}else if(z(u)){const n=BigInt(Math.round(t));if(e){const f=r.data,a=r.offset;for(let s=0;s<i;s++)o[s]=f[a+s]===n?1:0}else for(let f=0;f<i;f++)o[f]=r.iget(f)===n?1:0}else if(e){const n=r.data,f=r.offset;for(let a=0;a<i;a++)o[a]=n[f+a]===t?1:0}else for(let n=0;n<i;n++)o[n]=Number(r.iget(n))===t?1:0;return y.fromData(o,Array.from(r.shape),"bool")}function E(r,t){const o=new Uint8Array(r.size),i=r.size,u=r.dtype,e=r.isCContiguous;if(c(u))if(e){const n=r.data,f=r.offset;for(let a=0;a<i;a++){const[s,l]=d(n,f+a);o[a]=s!==t||l!==0?1:0}}else for(let n=0;n<i;n++){const f=r.iget(n);o[n]=f.re!==t||f.im!==0?1:0}else if(e){const n=r.data,f=r.offset;for(let a=0;a<i;a++)o[a]=n[f+a]!==t?1:0}else for(let n=0;n<i;n++)o[n]=Number(r.iget(n))!==t?1:0;return y.fromData(o,Array.from(r.shape),"bool")}function M(r,t,o,i){const u=new Uint8Array(r.size),e=r.size,n=i+o*Math.abs(t);if(r.isCContiguous){const f=r.data,a=r.offset;for(let s=0;s<e;s++){const l=Math.abs(Number(f[a+s])-t);u[s]=l<=n?1:0}}else for(let f=0;f<e;f++){const a=Math.abs(Number(r.iget(f))-t);u[f]=a<=n?1:0}return y.fromData(u,Array.from(r.shape),"bool")}export{V as allclose,W as arrayEquiv,P as equal,H as greater,J as greaterEqual,w as isclose,K as less,L as lessEqual,Q as notEqual};
@@ -1 +1 @@
1
- import{ArrayStorage as i}from"../storage";import{isComplexDType as A,getComplexComponentDType as u,getTypedArrayConstructor as m}from"../dtype";import{Complex as D}from"../complex";function z(r){const a=r.dtype,n=Array.from(r.shape),y=r.size;if(A(a)){const c=u(a),s=i.zeros(n,c),e=s.data,o=r.data;for(let t=0;t<y;t++)e[t]=o[t*2];return s}return r.copy()}function S(r){const a=r.dtype,n=Array.from(r.shape),y=r.size;if(A(a)){const s=u(a),e=i.zeros(n,s),o=e.data,t=r.data;for(let l=0;l<y;l++)o[l]=t[l*2+1];return e}const c=a==="float32"?"float32":"float64";return i.zeros(n,c)}function F(r){const a=r.dtype,n=Array.from(r.shape),y=r.size;if(A(a)){const c=m(a),s=y*2,e=new c(s),o=r.data;for(let t=0;t<y;t++)e[t*2]=o[t*2],e[t*2+1]=-o[t*2+1];return i.fromData(e,n,a)}return r.copy()}const x=F;function T(r,a=!1){const n=r.dtype,y=Array.from(r.shape),c=r.size,s=i.zeros(y,"float64"),e=s.data;if(A(n)){const o=r.data;for(let t=0;t<c;t++){const l=o[t*2],p=o[t*2+1];let f=Math.atan2(p,l);a&&(f=f*180/Math.PI),e[t]=f}}else for(let o=0;o<c;o++){const t=r.iget(o);let p=(t instanceof D?t.re:Number(t))>=0?0:Math.PI;a&&(p=p*180/Math.PI),e[o]=p}return s}function C(r){const a=r.dtype,n=Array.from(r.shape),y=r.size,c=A(a)?u(a):a,s=i.zeros(n,c),e=s.data;if(A(a)){const o=r.data;for(let t=0;t<y;t++){const l=o[t*2],p=o[t*2+1];e[t]=Math.sqrt(l*l+p*p)}}return s}export{T as angle,C as complexAbs,F as conj,x as conjugate,S as imag,z as real};
1
+ import{ArrayStorage as i}from"../storage.js";import{isComplexDType as A,getComplexComponentDType as u,getTypedArrayConstructor as m}from"../dtype.js";import{Complex as D}from"../complex.js";function z(r){const a=r.dtype,n=Array.from(r.shape),y=r.size;if(A(a)){const c=u(a),s=i.zeros(n,c),e=s.data,o=r.data;for(let t=0;t<y;t++)e[t]=o[t*2];return s}return r.copy()}function S(r){const a=r.dtype,n=Array.from(r.shape),y=r.size;if(A(a)){const s=u(a),e=i.zeros(n,s),o=e.data,t=r.data;for(let l=0;l<y;l++)o[l]=t[l*2+1];return e}const c=a==="float32"?"float32":"float64";return i.zeros(n,c)}function F(r){const a=r.dtype,n=Array.from(r.shape),y=r.size;if(A(a)){const c=m(a),s=y*2,e=new c(s),o=r.data;for(let t=0;t<y;t++)e[t*2]=o[t*2],e[t*2+1]=-o[t*2+1];return i.fromData(e,n,a)}return r.copy()}const x=F;function T(r,a=!1){const n=r.dtype,y=Array.from(r.shape),c=r.size,s=i.zeros(y,"float64"),e=s.data;if(A(n)){const o=r.data;for(let t=0;t<c;t++){const l=o[t*2],p=o[t*2+1];let f=Math.atan2(p,l);a&&(f=f*180/Math.PI),e[t]=f}}else for(let o=0;o<c;o++){const t=r.iget(o);let p=(t instanceof D?t.re:Number(t))>=0?0:Math.PI;a&&(p=p*180/Math.PI),e[o]=p}return s}function C(r){const a=r.dtype,n=Array.from(r.shape),y=r.size,c=A(a)?u(a):a,s=i.zeros(n,c),e=s.data;if(A(a)){const o=r.data;for(let t=0;t<y;t++){const l=o[t*2],p=o[t*2+1];e[t]=Math.sqrt(l*l+p*p)}}return s}export{T as angle,C as complexAbs,F as conj,x as conjugate,S as imag,z as real};
@@ -1 +1 @@
1
- import{ArrayStorage as d}from"../storage";import{elementwiseUnaryOp as D,elementwiseBinaryOp as T,broadcastShapes as q}from"../internal/compute";import{isBigIntDType as w,isComplexDType as A,throwIfComplex as N}from"../dtype";function j(t){const r=t.dtype;if(A(r)){const f=Array.from(t.shape),y=t.size,u=t.isCContiguous,l=d.zeros(f,r),p=l.data;if(u){const e=t.data,c=t.offset;for(let a=0;a<y;a++){const o=e[(c+a)*2],s=e[(c+a)*2+1],i=Math.sqrt(o*o+s*s),n=Math.sqrt((i+o)/2),m=(s>=0?1:-1)*Math.sqrt((i-o)/2);p[a*2]=n,p[a*2+1]=m}}else for(let e=0;e<y;e++){const c=t.iget(e),a=c.re,o=c.im,s=Math.sqrt(a*a+o*o),i=Math.sqrt((s+a)/2),n=(o>=0?1:-1)*Math.sqrt((s-a)/2);p[e*2]=i,p[e*2+1]=n}return l}return D(t,Math.sqrt,!1)}function k(t,r){if(typeof r=="number")return V(t,r);const f=A(t.dtype),y=A(r.dtype);return f||y?I(t,r):T(t,r,Math.pow,"power")}function I(t,r){const f=A(t.dtype),y=A(r.dtype),u=t.dtype==="complex128"||r.dtype==="complex128"||r.dtype==="float64"?"complex128":"complex64",l=Array.from(t.shape),p=t.size,e=d.zeros(l,u),c=e.data,a=t.isCContiguous,o=r.isCContiguous,s=t.offset,i=r.offset;for(let n=0;n<p;n++){let m,g;if(f)if(a){const S=t.data;m=S[(s+n)*2],g=S[(s+n)*2+1]}else{const S=t.iget(n);m=S.re,g=S.im}else m=Number(t.iget(n)),g=0;let h,M;if(y)if(o){const S=r.data;h=S[(i+n)*2],M=S[(i+n)*2+1]}else{const S=r.iget(n);h=S.re,M=S.im}else h=Number(r.iget(n)),M=0;const C=Math.sqrt(m*m+g*g),z=Math.atan2(g,m),b=Math.log(C),F=h*b-M*z,x=h*z+M*b,v=Math.exp(F);c[n*2]=v*Math.cos(x),c[n*2+1]=v*Math.sin(x)}return e}function V(t,r){const f=t.dtype,y=Array.from(t.shape),u=t.data,l=t.size,p=t.offset,e=t.isCContiguous;if(A(f)){const n=d.zeros(y,f),m=n.data;if(e){const g=u;for(let h=0;h<l;h++){const M=g[(p+h)*2],C=g[(p+h)*2+1],z=Math.sqrt(M*M+C*C),b=Math.atan2(C,M),F=Math.pow(z,r),x=b*r;m[h*2]=F*Math.cos(x),m[h*2+1]=F*Math.sin(x)}}else for(let g=0;g<l;g++){const h=t.iget(g),M=h.re,C=h.im,z=Math.sqrt(M*M+C*C),b=Math.atan2(C,M),F=Math.pow(z,r),x=b*r;m[g*2]=F*Math.cos(x),m[g*2+1]=F*Math.sin(x)}return n}const o=f!=="float32"&&f!=="float64"&&(r<0||!Number.isInteger(r))?"float64":f,s=d.zeros(y,o),i=s.data;if(w(f))if(w(o)&&Number.isInteger(r)&&r>=0)if(e){const n=u,m=i;for(let g=0;g<l;g++)m[g]=n[p+g]**BigInt(r)}else{const n=i;for(let m=0;m<l;m++)n[m]=t.iget(m)**BigInt(r)}else if(e)for(let n=0;n<l;n++)i[n]=Math.pow(Number(u[p+n]),r);else for(let n=0;n<l;n++)i[n]=Math.pow(Number(t.iget(n)),r);else if(e)for(let n=0;n<l;n++)i[n]=Math.pow(Number(u[p+n]),r);else for(let n=0;n<l;n++)i[n]=Math.pow(Number(t.iget(n)),r);return s}function H(t){const r=t.dtype;if(A(r)){const f=Array.from(t.shape),y=t.size,u=t.isCContiguous,l=d.zeros(f,r),p=l.data;if(u){const e=t.data,c=t.offset;for(let a=0;a<y;a++){const o=e[(c+a)*2],s=e[(c+a)*2+1],i=Math.exp(o);p[a*2]=i*Math.cos(s),p[a*2+1]=i*Math.sin(s)}}else for(let e=0;e<y;e++){const c=t.iget(e),a=c.re,o=c.im,s=Math.exp(a);p[e*2]=s*Math.cos(o),p[e*2+1]=s*Math.sin(o)}return l}return D(t,Math.exp,!1)}function J(t){const r=t.dtype;if(A(r)){const f=Array.from(t.shape),y=t.size,u=t.isCContiguous,l=Math.LN2,p=d.zeros(f,r),e=p.data;if(u){const c=t.data,a=t.offset;for(let o=0;o<y;o++){const s=c[(a+o)*2],i=c[(a+o)*2+1],n=Math.exp(s*l),m=i*l;e[o*2]=n*Math.cos(m),e[o*2+1]=n*Math.sin(m)}}else for(let c=0;c<y;c++){const a=t.iget(c),o=a.re,s=a.im,i=Math.exp(o*l),n=s*l;e[c*2]=i*Math.cos(n),e[c*2+1]=i*Math.sin(n)}return p}return D(t,f=>Math.pow(2,f),!1)}function K(t){const r=t.dtype;if(A(r)){const f=Array.from(t.shape),y=t.size,u=t.isCContiguous,l=d.zeros(f,r),p=l.data;if(u){const e=t.data,c=t.offset;for(let a=0;a<y;a++){const o=e[(c+a)*2],s=e[(c+a)*2+1],i=Math.exp(o);p[a*2]=i*Math.cos(s)-1,p[a*2+1]=i*Math.sin(s)}}else for(let e=0;e<y;e++){const c=t.iget(e),a=c.re,o=c.im,s=Math.exp(a);p[e*2]=s*Math.cos(o)-1,p[e*2+1]=s*Math.sin(o)}return l}return D(t,Math.expm1,!1)}function Q(t){const r=t.dtype;if(A(r)){const f=Array.from(t.shape),y=t.size,u=t.isCContiguous,l=d.zeros(f,r),p=l.data;if(u){const e=t.data,c=t.offset;for(let a=0;a<y;a++){const o=e[(c+a)*2],s=e[(c+a)*2+1],i=Math.sqrt(o*o+s*s),n=Math.atan2(s,o);p[a*2]=Math.log(i),p[a*2+1]=n}}else for(let e=0;e<y;e++){const c=t.iget(e),a=c.re,o=c.im,s=Math.sqrt(a*a+o*o),i=Math.atan2(o,a);p[e*2]=Math.log(s),p[e*2+1]=i}return l}return D(t,Math.log,!1)}function W(t){const r=t.dtype;if(A(r)){const f=Array.from(t.shape),y=t.size,u=t.isCContiguous,l=1/Math.LN2,p=d.zeros(f,r),e=p.data;if(u){const c=t.data,a=t.offset;for(let o=0;o<y;o++){const s=c[(a+o)*2],i=c[(a+o)*2+1],n=Math.sqrt(s*s+i*i),m=Math.atan2(i,s);e[o*2]=Math.log(n)*l,e[o*2+1]=m*l}}else for(let c=0;c<y;c++){const a=t.iget(c),o=a.re,s=a.im,i=Math.sqrt(o*o+s*s),n=Math.atan2(s,o);e[c*2]=Math.log(i)*l,e[c*2+1]=n*l}return p}return D(t,Math.log2,!1)}function X(t){const r=t.dtype;if(A(r)){const f=Array.from(t.shape),y=t.size,u=t.isCContiguous,l=1/Math.LN10,p=d.zeros(f,r),e=p.data;if(u){const c=t.data,a=t.offset;for(let o=0;o<y;o++){const s=c[(a+o)*2],i=c[(a+o)*2+1],n=Math.sqrt(s*s+i*i),m=Math.atan2(i,s);e[o*2]=Math.log(n)*l,e[o*2+1]=m*l}}else for(let c=0;c<y;c++){const a=t.iget(c),o=a.re,s=a.im,i=Math.sqrt(o*o+s*s),n=Math.atan2(s,o);e[c*2]=Math.log(i)*l,e[c*2+1]=n*l}return p}return D(t,Math.log10,!1)}function Y(t){const r=t.dtype;if(A(r)){const f=Array.from(t.shape),y=t.size,u=t.isCContiguous,l=d.zeros(f,r),p=l.data;if(u){const e=t.data,c=t.offset;for(let a=0;a<y;a++){const o=e[(c+a)*2],s=e[(c+a)*2+1],i=1+o,n=Math.sqrt(i*i+s*s),m=Math.atan2(s,i);p[a*2]=Math.log(n),p[a*2+1]=m}}else for(let e=0;e<y;e++){const c=t.iget(e),a=c.re,o=c.im,s=1+a,i=Math.sqrt(s*s+o*o),n=Math.atan2(o,s);p[e*2]=Math.log(i),p[e*2+1]=n}return l}return D(t,Math.log1p,!1)}function Z(t,r){return N(t.dtype,"logaddexp","logaddexp is not supported for complex numbers."),typeof r!="number"&&N(r.dtype,"logaddexp","logaddexp is not supported for complex numbers."),typeof r=="number"?B(t,r):R(t,r)}function R(t,r){const f=q(t.shape,r.shape),y=f.reduce((a,o)=>a*o,1),u=t.dtype,l=r.dtype,p=u==="float32"&&l==="float32"?"float32":"float64",e=d.zeros(f,p),c=e.data;for(let a=0;a<y;a++){const o=(w(u),Number(t.iget(a))),s=(w(l),Number(r.iget(a))),i=Math.max(o,s),n=Math.min(o,s);c[a]=i+Math.log1p(Math.exp(n-i))}return e}function B(t,r){const f=t.dtype,y=Array.from(t.shape),u=t.size,l=t.isCContiguous,p=f==="float32"?"float32":"float64",e=d.zeros(y,p),c=e.data;if(l){const a=t.offset;for(let o=0;o<u;o++){const s=Number(t.data[a+o]),i=Math.max(s,r),n=Math.min(s,r);c[o]=i+Math.log1p(Math.exp(n-i))}}else for(let a=0;a<u;a++){const o=Number(t.iget(a)),s=Math.max(o,r),i=Math.min(o,r);c[a]=s+Math.log1p(Math.exp(i-s))}return e}function $(t,r){return N(t.dtype,"logaddexp2","logaddexp2 is not supported for complex numbers."),typeof r!="number"&&N(r.dtype,"logaddexp2","logaddexp2 is not supported for complex numbers."),typeof r=="number"?P(t,r):L(t,r)}function L(t,r){const f=q(t.shape,r.shape),y=f.reduce((o,s)=>o*s,1),u=t.dtype,l=r.dtype,p=u==="float32"&&l==="float32"?"float32":"float64",e=d.zeros(f,p),c=e.data,a=Math.LOG2E;for(let o=0;o<y;o++){const s=(w(u),Number(t.iget(o))),i=(w(l),Number(r.iget(o))),n=Math.max(s,i),m=Math.min(s,i);c[o]=n+Math.log1p(Math.pow(2,m-n))*a}return e}function P(t,r){const f=t.dtype,y=Array.from(t.shape),u=t.size,l=t.isCContiguous,p=f==="float32"?"float32":"float64",e=d.zeros(y,p),c=e.data,a=Math.LOG2E;if(l){const o=t.offset;for(let s=0;s<u;s++){const i=Number(t.data[o+s]),n=Math.max(i,r),m=Math.min(i,r);c[s]=n+Math.log1p(Math.pow(2,m-n))*a}}else for(let o=0;o<u;o++){const s=Number(t.iget(o)),i=Math.max(s,r),n=Math.min(s,r);c[o]=i+Math.log1p(Math.pow(2,n-i))*a}return e}export{H as exp,J as exp2,K as expm1,Q as log,X as log10,Y as log1p,W as log2,Z as logaddexp,$ as logaddexp2,k as power,j as sqrt};
1
+ import{ArrayStorage as d}from"../storage.js";import{elementwiseUnaryOp as D,elementwiseBinaryOp as T,broadcastShapes as q}from"../internal/compute.js";import{isBigIntDType as b,isComplexDType as M,throwIfComplex as N}from"../dtype.js";import{wasmSqrt as R}from"../wasm/sqrt.js";import{wasmPower as I,wasmPowerScalar as V}from"../wasm/power.js";import{wasmExp as L}from"../wasm/exp.js";import{wasmExp2 as P}from"../wasm/exp2.js";import{wasmLogaddexp as B,wasmLogaddexpScalar as O}from"../wasm/logaddexp.js";function ot(t){const r=t.dtype;if(M(r)){const u=Array.from(t.shape),y=t.size,p=t.isCContiguous,l=d.zeros(u,r),i=l.data;if(p){const n=t.data,e=t.offset;for(let a=0;a<y;a++){const o=n[(e+a)*2],c=n[(e+a)*2+1],s=Math.sqrt(o*o+c*c),f=Math.sqrt((s+o)/2),g=(c>=0?1:-1)*Math.sqrt((s-o)/2);i[a*2]=f,i[a*2+1]=g}}else for(let n=0;n<y;n++){const e=t.iget(n),a=e.re,o=e.im,c=Math.sqrt(a*a+o*o),s=Math.sqrt((c+a)/2),f=(o>=0?1:-1)*Math.sqrt((c-a)/2);i[n*2]=s,i[n*2+1]=f}return l}const m=R(t);return m||D(t,Math.sqrt,!1)}function at(t,r){if(typeof r=="number")return G(t,r);const m=M(t.dtype),u=M(r.dtype);if(m||u)return E(t,r);const y=I(t,r);return y||T(t,r,Math.pow,"power")}function E(t,r){const m=M(t.dtype),u=M(r.dtype),y=t.dtype==="complex128"||r.dtype==="complex128"||r.dtype==="float64"?"complex128":"complex64",p=Array.from(t.shape),l=t.size,i=d.zeros(p,y),n=i.data,e=t.isCContiguous,a=r.isCContiguous,o=t.offset,c=r.offset;for(let s=0;s<l;s++){let f,g;if(m)if(e){const S=t.data;f=S[(o+s)*2],g=S[(o+s)*2+1]}else{const S=t.iget(s);f=S.re,g=S.im}else f=Number(t.iget(s)),g=0;let h,A;if(u)if(a){const S=r.data;h=S[(c+s)*2],A=S[(c+s)*2+1]}else{const S=r.iget(s);h=S.re,A=S.im}else h=Number(r.iget(s)),A=0;const C=Math.sqrt(f*f+g*g),z=Math.atan2(g,f),w=Math.log(C),F=h*w-A*z,x=h*z+A*w,v=Math.exp(F);n[s*2]=v*Math.cos(x),n[s*2+1]=v*Math.sin(x)}return i}function G(t,r){const m=t.dtype,u=Array.from(t.shape),y=t.data,p=t.size,l=t.offset,i=t.isCContiguous;if(!M(m)){const s=V(t,r);if(s)return s}if(M(m)){const s=d.zeros(u,m),f=s.data;if(i){const g=y;for(let h=0;h<p;h++){const A=g[(l+h)*2],C=g[(l+h)*2+1],z=Math.sqrt(A*A+C*C),w=Math.atan2(C,A),F=Math.pow(z,r),x=w*r;f[h*2]=F*Math.cos(x),f[h*2+1]=F*Math.sin(x)}}else for(let g=0;g<p;g++){const h=t.iget(g),A=h.re,C=h.im,z=Math.sqrt(A*A+C*C),w=Math.atan2(C,A),F=Math.pow(z,r),x=w*r;f[g*2]=F*Math.cos(x),f[g*2+1]=F*Math.sin(x)}return s}const a=m!=="float32"&&m!=="float64"&&(r<0||!Number.isInteger(r))?"float64":m,o=d.zeros(u,a),c=o.data;if(b(m))if(b(a)&&Number.isInteger(r)&&r>=0)if(i){const s=y,f=c;for(let g=0;g<p;g++)f[g]=s[l+g]**BigInt(r)}else{const s=c;for(let f=0;f<p;f++)s[f]=t.iget(f)**BigInt(r)}else if(i)for(let s=0;s<p;s++)c[s]=Math.pow(Number(y[l+s]),r);else for(let s=0;s<p;s++)c[s]=Math.pow(Number(t.iget(s)),r);else if(i)for(let s=0;s<p;s++)c[s]=Math.pow(Number(y[l+s]),r);else for(let s=0;s<p;s++)c[s]=Math.pow(Number(t.iget(s)),r);return o}function rt(t){const r=t.dtype;if(M(r)){const u=Array.from(t.shape),y=t.size,p=t.isCContiguous,l=d.zeros(u,r),i=l.data;if(p){const n=t.data,e=t.offset;for(let a=0;a<y;a++){const o=n[(e+a)*2],c=n[(e+a)*2+1],s=Math.exp(o);i[a*2]=s*Math.cos(c),i[a*2+1]=s*Math.sin(c)}}else for(let n=0;n<y;n++){const e=t.iget(n),a=e.re,o=e.im,c=Math.exp(a);i[n*2]=c*Math.cos(o),i[n*2+1]=c*Math.sin(o)}return l}const m=L(t);return m||D(t,Math.exp,!1)}function st(t){const r=t.dtype;if(M(r)){const u=Array.from(t.shape),y=t.size,p=t.isCContiguous,l=Math.LN2,i=d.zeros(u,r),n=i.data;if(p){const e=t.data,a=t.offset;for(let o=0;o<y;o++){const c=e[(a+o)*2],s=e[(a+o)*2+1],f=Math.exp(c*l),g=s*l;n[o*2]=f*Math.cos(g),n[o*2+1]=f*Math.sin(g)}}else for(let e=0;e<y;e++){const a=t.iget(e),o=a.re,c=a.im,s=Math.exp(o*l),f=c*l;n[e*2]=s*Math.cos(f),n[e*2+1]=s*Math.sin(f)}return i}const m=P(t);return m||D(t,u=>Math.pow(2,u),!1)}function et(t){const r=t.dtype;if(M(r)){const m=Array.from(t.shape),u=t.size,y=t.isCContiguous,p=d.zeros(m,r),l=p.data;if(y){const i=t.data,n=t.offset;for(let e=0;e<u;e++){const a=i[(n+e)*2],o=i[(n+e)*2+1],c=Math.exp(a);l[e*2]=c*Math.cos(o)-1,l[e*2+1]=c*Math.sin(o)}}else for(let i=0;i<u;i++){const n=t.iget(i),e=n.re,a=n.im,o=Math.exp(e);l[i*2]=o*Math.cos(a)-1,l[i*2+1]=o*Math.sin(a)}return p}return D(t,Math.expm1,!1)}function nt(t){const r=t.dtype;if(M(r)){const m=Array.from(t.shape),u=t.size,y=t.isCContiguous,p=d.zeros(m,r),l=p.data;if(y){const i=t.data,n=t.offset;for(let e=0;e<u;e++){const a=i[(n+e)*2],o=i[(n+e)*2+1],c=Math.sqrt(a*a+o*o),s=Math.atan2(o,a);l[e*2]=Math.log(c),l[e*2+1]=s}}else for(let i=0;i<u;i++){const n=t.iget(i),e=n.re,a=n.im,o=Math.sqrt(e*e+a*a),c=Math.atan2(a,e);l[i*2]=Math.log(o),l[i*2+1]=c}return p}return D(t,Math.log,!1)}function ct(t){const r=t.dtype;if(M(r)){const m=Array.from(t.shape),u=t.size,y=t.isCContiguous,p=1/Math.LN2,l=d.zeros(m,r),i=l.data;if(y){const n=t.data,e=t.offset;for(let a=0;a<u;a++){const o=n[(e+a)*2],c=n[(e+a)*2+1],s=Math.sqrt(o*o+c*c),f=Math.atan2(c,o);i[a*2]=Math.log(s)*p,i[a*2+1]=f*p}}else for(let n=0;n<u;n++){const e=t.iget(n),a=e.re,o=e.im,c=Math.sqrt(a*a+o*o),s=Math.atan2(o,a);i[n*2]=Math.log(c)*p,i[n*2+1]=s*p}return l}return D(t,Math.log2,!1)}function it(t){const r=t.dtype;if(M(r)){const m=Array.from(t.shape),u=t.size,y=t.isCContiguous,p=1/Math.LN10,l=d.zeros(m,r),i=l.data;if(y){const n=t.data,e=t.offset;for(let a=0;a<u;a++){const o=n[(e+a)*2],c=n[(e+a)*2+1],s=Math.sqrt(o*o+c*c),f=Math.atan2(c,o);i[a*2]=Math.log(s)*p,i[a*2+1]=f*p}}else for(let n=0;n<u;n++){const e=t.iget(n),a=e.re,o=e.im,c=Math.sqrt(a*a+o*o),s=Math.atan2(o,a);i[n*2]=Math.log(c)*p,i[n*2+1]=s*p}return l}return D(t,Math.log10,!1)}function lt(t){const r=t.dtype;if(M(r)){const m=Array.from(t.shape),u=t.size,y=t.isCContiguous,p=d.zeros(m,r),l=p.data;if(y){const i=t.data,n=t.offset;for(let e=0;e<u;e++){const a=i[(n+e)*2],o=i[(n+e)*2+1],c=1+a,s=Math.sqrt(c*c+o*o),f=Math.atan2(o,c);l[e*2]=Math.log(s),l[e*2+1]=f}}else for(let i=0;i<u;i++){const n=t.iget(i),e=n.re,a=n.im,o=1+e,c=Math.sqrt(o*o+a*a),s=Math.atan2(a,o);l[i*2]=Math.log(c),l[i*2+1]=s}return p}return D(t,Math.log1p,!1)}function pt(t,r){return N(t.dtype,"logaddexp","logaddexp is not supported for complex numbers."),typeof r!="number"&&N(r.dtype,"logaddexp","logaddexp is not supported for complex numbers."),typeof r=="number"?_(t,r):U(t,r)}function U(t,r){const m=B(t,r);if(m)return m;const u=q(t.shape,r.shape),y=u.reduce((o,c)=>o*c,1),p=t.dtype,l=r.dtype,i=o=>o==="float32"||o==="int8"||o==="uint8"||o==="int16"||o==="uint16",n=i(p)&&i(l)?"float32":"float64",e=d.zeros(u,n),a=e.data;for(let o=0;o<y;o++){const c=(b(p),Number(t.iget(o))),s=(b(l),Number(r.iget(o))),f=Math.max(c,s),g=Math.min(c,s);a[o]=f+Math.log1p(Math.exp(g-f))}return e}function _(t,r){const m=O(t,r);if(m)return m;const u=t.dtype,y=Array.from(t.shape),p=t.size,l=t.isCContiguous,i=u==="float32"||u==="int8"||u==="uint8"||u==="int16"||u==="uint16"?"float32":"float64",n=d.zeros(y,i),e=n.data;if(l){const a=t.offset;for(let o=0;o<p;o++){const c=Number(t.data[a+o]),s=Math.max(c,r),f=Math.min(c,r);e[o]=s+Math.log1p(Math.exp(f-s))}}else for(let a=0;a<p;a++){const o=Number(t.iget(a)),c=Math.max(o,r),s=Math.min(o,r);e[a]=c+Math.log1p(Math.exp(s-c))}return n}function ft(t,r){return N(t.dtype,"logaddexp2","logaddexp2 is not supported for complex numbers."),typeof r!="number"&&N(r.dtype,"logaddexp2","logaddexp2 is not supported for complex numbers."),typeof r=="number"?k(t,r):j(t,r)}function j(t,r){const m=q(t.shape,r.shape),u=m.reduce((a,o)=>a*o,1),y=t.dtype,p=r.dtype,l=y==="float32"&&p==="float32"?"float32":"float64",i=d.zeros(m,l),n=i.data,e=Math.LOG2E;for(let a=0;a<u;a++){const o=(b(y),Number(t.iget(a))),c=(b(p),Number(r.iget(a))),s=Math.max(o,c),f=Math.min(o,c);n[a]=s+Math.log1p(Math.pow(2,f-s))*e}return i}function k(t,r){const m=t.dtype,u=Array.from(t.shape),y=t.size,p=t.isCContiguous,l=m==="float32"?"float32":"float64",i=d.zeros(u,l),n=i.data,e=Math.LOG2E;if(p){const a=t.offset;for(let o=0;o<y;o++){const c=Number(t.data[a+o]),s=Math.max(c,r),f=Math.min(c,r);n[o]=s+Math.log1p(Math.pow(2,f-s))*e}}else for(let a=0;a<y;a++){const o=Number(t.iget(a)),c=Math.max(o,r),s=Math.min(o,r);n[a]=c+Math.log1p(Math.pow(2,s-c))*e}return i}export{rt as exp,st as exp2,et as expm1,nt as log,it as log10,lt as log1p,ct as log2,pt as logaddexp,ft as logaddexp2,at as power,ot as sqrt};