numpy-ts 0.13.1 → 1.1.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 (419) hide show
  1. package/README.md +30 -251
  2. package/dist/esm/common/internal/indexing.js +1 -1
  3. package/dist/esm/common/ndarray-core.js +1 -1
  4. package/dist/esm/common/ops/advanced.js +1 -1
  5. package/dist/esm/common/ops/arithmetic.js +1 -1
  6. package/dist/esm/common/ops/bitwise.js +1 -1
  7. package/dist/esm/common/ops/exponential.js +1 -1
  8. package/dist/esm/common/ops/fft.js +1 -1
  9. package/dist/esm/common/ops/gradient.js +1 -1
  10. package/dist/esm/common/ops/hyperbolic.js +1 -1
  11. package/dist/esm/common/ops/linalg.js +2 -2
  12. package/dist/esm/common/ops/logic.js +1 -1
  13. package/dist/esm/common/ops/reduction.js +1 -1
  14. package/dist/esm/common/ops/sets.js +1 -1
  15. package/dist/esm/common/ops/shape.js +1 -1
  16. package/dist/esm/common/ops/sorting.js +1 -1
  17. package/dist/esm/common/ops/statistics.js +1 -1
  18. package/dist/esm/common/ops/trig.js +1 -1
  19. package/dist/esm/common/storage.js +1 -1
  20. package/dist/esm/common/wasm/abs.js +1 -0
  21. package/dist/esm/common/wasm/add.js +1 -0
  22. package/dist/esm/common/wasm/arccos.js +1 -0
  23. package/dist/esm/common/wasm/arcsin.js +1 -0
  24. package/dist/esm/common/wasm/arctan.js +1 -0
  25. package/dist/esm/common/wasm/argpartition.js +1 -0
  26. package/dist/esm/common/wasm/argsort.js +1 -0
  27. package/dist/esm/common/wasm/bins/abs.wasm.js +1 -0
  28. package/dist/esm/common/wasm/bins/add.wasm.js +1 -0
  29. package/dist/esm/common/wasm/bins/arccos.wasm.js +1 -0
  30. package/dist/esm/common/wasm/bins/arcsin.wasm.js +1 -0
  31. package/dist/esm/common/wasm/bins/arctan.wasm.js +1 -0
  32. package/dist/esm/common/wasm/bins/argpartition.wasm.js +1 -0
  33. package/dist/esm/common/wasm/bins/argsort.wasm.js +1 -0
  34. package/dist/esm/common/wasm/bins/bitwise_and.wasm.js +1 -0
  35. package/dist/esm/common/wasm/bins/bitwise_count.wasm.js +1 -0
  36. package/dist/esm/common/wasm/bins/bitwise_not.wasm.js +1 -0
  37. package/dist/esm/common/wasm/bins/bitwise_or.wasm.js +1 -0
  38. package/dist/esm/common/wasm/bins/bitwise_xor.wasm.js +1 -0
  39. package/dist/esm/common/wasm/bins/cholesky.wasm.js +1 -0
  40. package/dist/esm/common/wasm/bins/clip.wasm.js +1 -0
  41. package/dist/esm/common/wasm/bins/convolve.wasm.js +1 -0
  42. package/dist/esm/common/wasm/bins/copysign.wasm.js +1 -0
  43. package/dist/esm/common/wasm/bins/correlate.wasm.js +1 -0
  44. package/dist/esm/common/wasm/bins/cos.wasm.js +1 -0
  45. package/dist/esm/common/wasm/bins/cosh.wasm.js +1 -0
  46. package/dist/esm/common/wasm/bins/cross.wasm.js +1 -0
  47. package/dist/esm/common/wasm/bins/diff.wasm.js +1 -0
  48. package/dist/esm/common/wasm/bins/divide.wasm.js +1 -0
  49. package/dist/esm/common/wasm/bins/dot.wasm.js +1 -0
  50. package/dist/esm/common/wasm/bins/exp.wasm.js +1 -0
  51. package/dist/esm/common/wasm/bins/exp2.wasm.js +1 -0
  52. package/dist/esm/common/wasm/bins/fft.wasm.js +1 -0
  53. package/dist/esm/common/wasm/bins/flip.wasm.js +1 -0
  54. package/dist/esm/common/wasm/bins/frexp.wasm.js +1 -0
  55. package/dist/esm/common/wasm/bins/gather.wasm.js +1 -0
  56. package/dist/esm/common/wasm/bins/gcd.wasm.js +1 -0
  57. package/dist/esm/common/wasm/bins/gradient.wasm.js +1 -0
  58. package/dist/esm/common/wasm/bins/heaviside.wasm.js +1 -0
  59. package/dist/esm/common/wasm/bins/hypot.wasm.js +1 -0
  60. package/dist/esm/common/wasm/bins/indices.wasm.js +1 -0
  61. package/dist/esm/common/wasm/bins/inner.wasm.js +1 -0
  62. package/dist/esm/common/wasm/bins/kron.wasm.js +1 -0
  63. package/dist/esm/common/wasm/bins/ldexp.wasm.js +1 -0
  64. package/dist/esm/common/wasm/bins/left_shift.wasm.js +1 -0
  65. package/dist/esm/common/wasm/bins/lexsort.wasm.js +1 -0
  66. package/dist/esm/common/wasm/bins/logaddexp.wasm.js +1 -0
  67. package/dist/esm/common/wasm/bins/logical_and.wasm.js +1 -0
  68. package/dist/esm/common/wasm/bins/logical_not.wasm.js +1 -0
  69. package/dist/esm/common/wasm/bins/logical_or.wasm.js +1 -0
  70. package/dist/esm/common/wasm/bins/logical_xor.wasm.js +1 -0
  71. package/dist/esm/common/wasm/bins/matmul.wasm.js +1 -0
  72. package/dist/esm/common/wasm/bins/matvec.wasm.js +1 -0
  73. package/dist/esm/common/wasm/bins/max.wasm.js +1 -0
  74. package/dist/esm/common/wasm/bins/min.wasm.js +1 -0
  75. package/dist/esm/common/wasm/bins/mul.wasm.js +1 -0
  76. package/dist/esm/common/wasm/bins/neg.wasm.js +1 -0
  77. package/dist/esm/common/wasm/bins/outer.wasm.js +1 -0
  78. package/dist/esm/common/wasm/bins/pad.wasm.js +1 -0
  79. package/dist/esm/common/wasm/bins/partition.wasm.js +1 -0
  80. package/dist/esm/common/wasm/bins/power.wasm.js +1 -0
  81. package/dist/esm/common/wasm/bins/qr.wasm.js +1 -0
  82. package/dist/esm/common/wasm/bins/reciprocal.wasm.js +1 -0
  83. package/dist/esm/common/wasm/bins/reduce_all.wasm.js +1 -0
  84. package/dist/esm/common/wasm/bins/reduce_any.wasm.js +1 -0
  85. package/dist/esm/common/wasm/bins/reduce_argmax.wasm.js +1 -0
  86. package/dist/esm/common/wasm/bins/reduce_argmin.wasm.js +1 -0
  87. package/dist/esm/common/wasm/bins/reduce_count_nz.wasm.js +1 -0
  88. package/dist/esm/common/wasm/bins/reduce_max.wasm.js +1 -0
  89. package/dist/esm/common/wasm/bins/reduce_mean.wasm.js +1 -0
  90. package/dist/esm/common/wasm/bins/reduce_min.wasm.js +1 -0
  91. package/dist/esm/common/wasm/bins/reduce_nanmax.wasm.js +1 -0
  92. package/dist/esm/common/wasm/bins/reduce_nanmin.wasm.js +1 -0
  93. package/dist/esm/common/wasm/bins/reduce_nansum.wasm.js +1 -0
  94. package/dist/esm/common/wasm/bins/reduce_prod.wasm.js +1 -0
  95. package/dist/esm/common/wasm/bins/reduce_quantile.wasm.js +1 -0
  96. package/dist/esm/common/wasm/bins/reduce_std.wasm.js +1 -0
  97. package/dist/esm/common/wasm/bins/reduce_sum.wasm.js +1 -0
  98. package/dist/esm/common/wasm/bins/reduce_var.wasm.js +1 -0
  99. package/dist/esm/common/wasm/bins/repeat.wasm.js +1 -0
  100. package/dist/esm/common/wasm/bins/right_shift.wasm.js +1 -0
  101. package/dist/esm/common/wasm/bins/roll.wasm.js +1 -0
  102. package/dist/esm/common/wasm/bins/rot90.wasm.js +1 -0
  103. package/dist/esm/common/wasm/bins/searchsorted.wasm.js +1 -0
  104. package/dist/esm/common/wasm/bins/sign.wasm.js +1 -0
  105. package/dist/esm/common/wasm/bins/sinh.wasm.js +1 -0
  106. package/dist/esm/common/wasm/bins/sort.wasm.js +1 -0
  107. package/dist/esm/common/wasm/bins/sqrt.wasm.js +1 -0
  108. package/dist/esm/common/wasm/bins/square.wasm.js +1 -0
  109. package/dist/esm/common/wasm/bins/sub.wasm.js +1 -0
  110. package/dist/esm/common/wasm/bins/svd.wasm.js +1 -0
  111. package/dist/esm/common/wasm/bins/tan.wasm.js +1 -0
  112. package/dist/esm/common/wasm/bins/tanh.wasm.js +1 -0
  113. package/dist/esm/common/wasm/bins/tile.wasm.js +1 -0
  114. package/dist/esm/common/wasm/bins/vdot.wasm.js +1 -0
  115. package/dist/esm/common/wasm/bins/vecdot.wasm.js +1 -0
  116. package/dist/esm/common/wasm/bins/vecmat.wasm.js +1 -0
  117. package/dist/esm/common/wasm/bitwise_and.js +1 -0
  118. package/dist/esm/common/wasm/bitwise_count.js +1 -0
  119. package/dist/esm/common/wasm/bitwise_not.js +1 -0
  120. package/dist/esm/common/wasm/bitwise_or.js +1 -0
  121. package/dist/esm/common/wasm/bitwise_xor.js +1 -0
  122. package/dist/esm/common/wasm/cholesky.js +1 -0
  123. package/dist/esm/common/wasm/clip.js +1 -0
  124. package/dist/esm/common/wasm/config.js +1 -0
  125. package/dist/esm/common/wasm/convolve.js +1 -0
  126. package/dist/esm/common/wasm/copysign.js +1 -0
  127. package/dist/esm/common/wasm/correlate.js +1 -0
  128. package/dist/esm/common/wasm/cos.js +1 -0
  129. package/dist/esm/common/wasm/cosh.js +1 -0
  130. package/dist/esm/common/wasm/cross.js +1 -0
  131. package/dist/esm/common/wasm/diff.js +1 -0
  132. package/dist/esm/common/wasm/divide.js +1 -0
  133. package/dist/esm/common/wasm/dot.js +1 -0
  134. package/dist/esm/common/wasm/exp.js +1 -0
  135. package/dist/esm/common/wasm/exp2.js +1 -0
  136. package/dist/esm/common/wasm/fft.js +1 -0
  137. package/dist/esm/common/wasm/flip.js +1 -0
  138. package/dist/esm/common/wasm/frexp.js +1 -0
  139. package/dist/esm/common/wasm/gather.js +1 -0
  140. package/dist/esm/common/wasm/gcd.js +1 -0
  141. package/dist/esm/common/wasm/gradient.js +1 -0
  142. package/dist/esm/common/wasm/heaviside.js +1 -0
  143. package/dist/esm/common/wasm/hypot.js +1 -0
  144. package/dist/esm/common/wasm/indices.js +1 -0
  145. package/dist/esm/common/wasm/inner.js +1 -0
  146. package/dist/esm/common/wasm/kron.js +1 -0
  147. package/dist/esm/common/wasm/ldexp.js +1 -0
  148. package/dist/esm/common/wasm/left_shift.js +1 -0
  149. package/dist/esm/common/wasm/lexsort.js +1 -0
  150. package/dist/esm/common/wasm/logaddexp.js +1 -0
  151. package/dist/esm/common/wasm/logical_and.js +1 -0
  152. package/dist/esm/common/wasm/logical_not.js +1 -0
  153. package/dist/esm/common/wasm/logical_or.js +1 -0
  154. package/dist/esm/common/wasm/logical_xor.js +1 -0
  155. package/dist/esm/common/wasm/lstsq.js +1 -0
  156. package/dist/esm/common/wasm/matmul.js +1 -0
  157. package/dist/esm/common/wasm/matvec.js +1 -0
  158. package/dist/esm/common/wasm/max.js +1 -0
  159. package/dist/esm/common/wasm/min.js +1 -0
  160. package/dist/esm/common/wasm/mul.js +1 -0
  161. package/dist/esm/common/wasm/neg.js +1 -0
  162. package/dist/esm/common/wasm/outer.js +1 -0
  163. package/dist/esm/common/wasm/pad.js +1 -0
  164. package/dist/esm/common/wasm/partition.js +1 -0
  165. package/dist/esm/common/wasm/power.js +1 -0
  166. package/dist/esm/common/wasm/qr.js +1 -0
  167. package/dist/esm/common/wasm/reciprocal.js +1 -0
  168. package/dist/esm/common/wasm/reduce_all.js +1 -0
  169. package/dist/esm/common/wasm/reduce_any.js +1 -0
  170. package/dist/esm/common/wasm/reduce_argmax.js +1 -0
  171. package/dist/esm/common/wasm/reduce_argmin.js +1 -0
  172. package/dist/esm/common/wasm/reduce_count_nz.js +1 -0
  173. package/dist/esm/common/wasm/reduce_max.js +1 -0
  174. package/dist/esm/common/wasm/reduce_mean.js +1 -0
  175. package/dist/esm/common/wasm/reduce_min.js +1 -0
  176. package/dist/esm/common/wasm/reduce_nanmax.js +1 -0
  177. package/dist/esm/common/wasm/reduce_nanmin.js +1 -0
  178. package/dist/esm/common/wasm/reduce_nansum.js +1 -0
  179. package/dist/esm/common/wasm/reduce_prod.js +1 -0
  180. package/dist/esm/common/wasm/reduce_quantile.js +1 -0
  181. package/dist/esm/common/wasm/reduce_std.js +1 -0
  182. package/dist/esm/common/wasm/reduce_sum.js +1 -0
  183. package/dist/esm/common/wasm/reduce_var.js +1 -0
  184. package/dist/esm/common/wasm/repeat.js +1 -0
  185. package/dist/esm/common/wasm/right_shift.js +1 -0
  186. package/dist/esm/common/wasm/roll.js +1 -0
  187. package/dist/esm/common/wasm/rot90.js +1 -0
  188. package/dist/esm/common/wasm/runtime.js +1 -0
  189. package/dist/esm/common/wasm/searchsorted.js +1 -0
  190. package/dist/esm/common/wasm/sign.js +1 -0
  191. package/dist/esm/common/wasm/sinh.js +1 -0
  192. package/dist/esm/common/wasm/sort.js +1 -0
  193. package/dist/esm/common/wasm/sqrt.js +1 -0
  194. package/dist/esm/common/wasm/square.js +1 -0
  195. package/dist/esm/common/wasm/sub.js +1 -0
  196. package/dist/esm/common/wasm/svd.js +1 -0
  197. package/dist/esm/common/wasm/tan.js +1 -0
  198. package/dist/esm/common/wasm/tanh.js +1 -0
  199. package/dist/esm/common/wasm/tile.js +1 -0
  200. package/dist/esm/common/wasm/vdot.js +1 -0
  201. package/dist/esm/common/wasm/vecdot.js +1 -0
  202. package/dist/esm/common/wasm/vecmat.js +1 -0
  203. package/dist/esm/core/creation.js +1 -1
  204. package/dist/esm/core/linalg.js +1 -1
  205. package/dist/esm/core/polynomial.js +1 -1
  206. package/dist/esm/core/reduction.js +1 -1
  207. package/dist/esm/core/sets.js +1 -1
  208. package/dist/esm/core/shape-extra.js +1 -1
  209. package/dist/esm/core/sorting.js +1 -1
  210. package/dist/esm/full/index.js +1 -1
  211. package/dist/esm/full/ndarray.js +1 -1
  212. package/dist/esm/index.js +1 -1
  213. package/dist/esm/io/zip/types.js +1 -1
  214. package/dist/esm/io/zip/writer.js +1 -1
  215. package/dist/numpy-ts.browser.js +6 -6
  216. package/dist/numpy-ts.node-io.cjs +6 -6
  217. package/dist/numpy-ts.node-io.cjs.map +4 -4
  218. package/dist/numpy-ts.node-io.mjs +6 -6
  219. package/dist/numpy-ts.node-io.mjs.map +4 -4
  220. package/dist/numpy-ts.node.cjs +6 -6
  221. package/dist/numpy-ts.node.cjs.map +4 -4
  222. package/dist/types/common/internal/indexing.d.ts +18 -0
  223. package/dist/types/common/ndarray-core.d.ts +3 -13
  224. package/dist/types/common/ops/linalg.d.ts +13 -12
  225. package/dist/types/common/ops/sets.d.ts +1 -1
  226. package/dist/types/common/ops/shape.d.ts +11 -0
  227. package/dist/types/common/storage.d.ts +4 -0
  228. package/dist/types/common/wasm/abs.d.ts +14 -0
  229. package/dist/types/common/wasm/add.d.ts +19 -0
  230. package/dist/types/common/wasm/arccos.d.ts +15 -0
  231. package/dist/types/common/wasm/arcsin.d.ts +15 -0
  232. package/dist/types/common/wasm/arctan.d.ts +15 -0
  233. package/dist/types/common/wasm/argpartition.d.ts +18 -0
  234. package/dist/types/common/wasm/argsort.d.ts +18 -0
  235. package/dist/types/common/wasm/bins/abs.wasm.d.ts +7 -0
  236. package/dist/types/common/wasm/bins/add.wasm.d.ts +17 -0
  237. package/dist/types/common/wasm/bins/arccos.wasm.d.ts +5 -0
  238. package/dist/types/common/wasm/bins/arcsin.wasm.d.ts +5 -0
  239. package/dist/types/common/wasm/bins/arctan.wasm.d.ts +5 -0
  240. package/dist/types/common/wasm/bins/argpartition.wasm.d.ts +21 -0
  241. package/dist/types/common/wasm/bins/argsort.wasm.d.ts +25 -0
  242. package/dist/types/common/wasm/bins/bitwise_and.wasm.d.ts +5 -0
  243. package/dist/types/common/wasm/bins/bitwise_count.wasm.d.ts +9 -0
  244. package/dist/types/common/wasm/bins/bitwise_not.wasm.d.ts +5 -0
  245. package/dist/types/common/wasm/bins/bitwise_or.wasm.d.ts +5 -0
  246. package/dist/types/common/wasm/bins/bitwise_xor.wasm.d.ts +5 -0
  247. package/dist/types/common/wasm/bins/cholesky.wasm.d.ts +3 -0
  248. package/dist/types/common/wasm/bins/clip.wasm.d.ts +11 -0
  249. package/dist/types/common/wasm/bins/convolve.wasm.d.ts +3 -0
  250. package/dist/types/common/wasm/bins/copysign.wasm.d.ts +21 -0
  251. package/dist/types/common/wasm/bins/correlate.wasm.d.ts +3 -0
  252. package/dist/types/common/wasm/bins/cos.wasm.d.ts +3 -0
  253. package/dist/types/common/wasm/bins/cosh.wasm.d.ts +5 -0
  254. package/dist/types/common/wasm/bins/cross.wasm.d.ts +9 -0
  255. package/dist/types/common/wasm/bins/diff.wasm.d.ts +13 -0
  256. package/dist/types/common/wasm/bins/divide.wasm.d.ts +23 -0
  257. package/dist/types/common/wasm/bins/dot.wasm.d.ts +9 -0
  258. package/dist/types/common/wasm/bins/exp.wasm.d.ts +5 -0
  259. package/dist/types/common/wasm/bins/exp2.wasm.d.ts +5 -0
  260. package/dist/types/common/wasm/bins/fft.wasm.d.ts +17 -0
  261. package/dist/types/common/wasm/bins/flip.wasm.d.ts +7 -0
  262. package/dist/types/common/wasm/bins/frexp.wasm.d.ts +2 -0
  263. package/dist/types/common/wasm/bins/gather.wasm.d.ts +32 -0
  264. package/dist/types/common/wasm/bins/gcd.wasm.d.ts +3 -0
  265. package/dist/types/common/wasm/bins/gradient.wasm.d.ts +11 -0
  266. package/dist/types/common/wasm/bins/heaviside.wasm.d.ts +5 -0
  267. package/dist/types/common/wasm/bins/hypot.wasm.d.ts +13 -0
  268. package/dist/types/common/wasm/bins/indices.wasm.d.ts +3 -0
  269. package/dist/types/common/wasm/bins/inner.wasm.d.ts +9 -0
  270. package/dist/types/common/wasm/bins/kron.wasm.d.ts +9 -0
  271. package/dist/types/common/wasm/bins/ldexp.wasm.d.ts +3 -0
  272. package/dist/types/common/wasm/bins/left_shift.wasm.d.ts +9 -0
  273. package/dist/types/common/wasm/bins/lexsort.wasm.d.ts +11 -0
  274. package/dist/types/common/wasm/bins/logaddexp.wasm.d.ts +21 -0
  275. package/dist/types/common/wasm/bins/logical_and.wasm.d.ts +13 -0
  276. package/dist/types/common/wasm/bins/logical_not.wasm.d.ts +7 -0
  277. package/dist/types/common/wasm/bins/logical_or.wasm.d.ts +13 -0
  278. package/dist/types/common/wasm/bins/logical_xor.wasm.d.ts +13 -0
  279. package/dist/types/common/wasm/bins/matmul.wasm.d.ts +9 -0
  280. package/dist/types/common/wasm/bins/matvec.wasm.d.ts +9 -0
  281. package/dist/types/common/wasm/bins/max.wasm.d.ts +21 -0
  282. package/dist/types/common/wasm/bins/min.wasm.d.ts +21 -0
  283. package/dist/types/common/wasm/bins/mul.wasm.d.ts +17 -0
  284. package/dist/types/common/wasm/bins/neg.wasm.d.ts +9 -0
  285. package/dist/types/common/wasm/bins/outer.wasm.d.ts +9 -0
  286. package/dist/types/common/wasm/bins/pad.wasm.d.ts +7 -0
  287. package/dist/types/common/wasm/bins/partition.wasm.d.ts +21 -0
  288. package/dist/types/common/wasm/bins/power.wasm.d.ts +13 -0
  289. package/dist/types/common/wasm/bins/qr.wasm.d.ts +3 -0
  290. package/dist/types/common/wasm/bins/reciprocal.wasm.d.ts +7 -0
  291. package/dist/types/common/wasm/bins/reduce_all.wasm.d.ts +7 -0
  292. package/dist/types/common/wasm/bins/reduce_any.wasm.d.ts +7 -0
  293. package/dist/types/common/wasm/bins/reduce_argmax.wasm.d.ts +11 -0
  294. package/dist/types/common/wasm/bins/reduce_argmin.wasm.d.ts +11 -0
  295. package/dist/types/common/wasm/bins/reduce_count_nz.wasm.d.ts +7 -0
  296. package/dist/types/common/wasm/bins/reduce_max.wasm.d.ts +20 -0
  297. package/dist/types/common/wasm/bins/reduce_mean.wasm.d.ts +21 -0
  298. package/dist/types/common/wasm/bins/reduce_min.wasm.d.ts +20 -0
  299. package/dist/types/common/wasm/bins/reduce_nanmax.wasm.d.ts +3 -0
  300. package/dist/types/common/wasm/bins/reduce_nanmin.wasm.d.ts +3 -0
  301. package/dist/types/common/wasm/bins/reduce_nansum.wasm.d.ts +3 -0
  302. package/dist/types/common/wasm/bins/reduce_prod.wasm.d.ts +19 -0
  303. package/dist/types/common/wasm/bins/reduce_quantile.wasm.d.ts +2 -0
  304. package/dist/types/common/wasm/bins/reduce_std.wasm.d.ts +11 -0
  305. package/dist/types/common/wasm/bins/reduce_sum.wasm.d.ts +17 -0
  306. package/dist/types/common/wasm/bins/reduce_var.wasm.d.ts +11 -0
  307. package/dist/types/common/wasm/bins/repeat.wasm.d.ts +7 -0
  308. package/dist/types/common/wasm/bins/right_shift.wasm.d.ts +17 -0
  309. package/dist/types/common/wasm/bins/roll.wasm.d.ts +7 -0
  310. package/dist/types/common/wasm/bins/rot90.wasm.d.ts +7 -0
  311. package/dist/types/common/wasm/bins/searchsorted.wasm.d.ts +21 -0
  312. package/dist/types/common/wasm/bins/sign.wasm.d.ts +7 -0
  313. package/dist/types/common/wasm/bins/sinh.wasm.d.ts +5 -0
  314. package/dist/types/common/wasm/bins/sort.wasm.d.ts +25 -0
  315. package/dist/types/common/wasm/bins/sqrt.wasm.d.ts +7 -0
  316. package/dist/types/common/wasm/bins/square.wasm.d.ts +9 -0
  317. package/dist/types/common/wasm/bins/sub.wasm.d.ts +17 -0
  318. package/dist/types/common/wasm/bins/svd.wasm.d.ts +2 -0
  319. package/dist/types/common/wasm/bins/tan.wasm.d.ts +3 -0
  320. package/dist/types/common/wasm/bins/tanh.wasm.d.ts +5 -0
  321. package/dist/types/common/wasm/bins/tile.wasm.d.ts +7 -0
  322. package/dist/types/common/wasm/bins/vdot.wasm.d.ts +3 -0
  323. package/dist/types/common/wasm/bins/vecdot.wasm.d.ts +9 -0
  324. package/dist/types/common/wasm/bins/vecmat.wasm.d.ts +9 -0
  325. package/dist/types/common/wasm/bitwise_and.d.ts +9 -0
  326. package/dist/types/common/wasm/bitwise_count.d.ts +11 -0
  327. package/dist/types/common/wasm/bitwise_not.d.ts +9 -0
  328. package/dist/types/common/wasm/bitwise_or.d.ts +9 -0
  329. package/dist/types/common/wasm/bitwise_xor.d.ts +9 -0
  330. package/dist/types/common/wasm/cholesky.d.ts +20 -0
  331. package/dist/types/common/wasm/clip.d.ts +13 -0
  332. package/dist/types/common/wasm/config.d.ts +21 -0
  333. package/dist/types/common/wasm/convolve.d.ts +14 -0
  334. package/dist/types/common/wasm/copysign.d.ts +19 -0
  335. package/dist/types/common/wasm/correlate.d.ts +14 -0
  336. package/dist/types/common/wasm/cos.d.ts +15 -0
  337. package/dist/types/common/wasm/cosh.d.ts +15 -0
  338. package/dist/types/common/wasm/cross.d.ts +15 -0
  339. package/dist/types/common/wasm/diff.d.ts +15 -0
  340. package/dist/types/common/wasm/divide.d.ts +11 -0
  341. package/dist/types/common/wasm/dot.d.ts +14 -0
  342. package/dist/types/common/wasm/exp.d.ts +15 -0
  343. package/dist/types/common/wasm/exp2.d.ts +15 -0
  344. package/dist/types/common/wasm/fft.d.ts +29 -0
  345. package/dist/types/common/wasm/flip.d.ts +13 -0
  346. package/dist/types/common/wasm/frexp.d.ts +9 -0
  347. package/dist/types/common/wasm/gather.d.ts +23 -0
  348. package/dist/types/common/wasm/gcd.d.ts +11 -0
  349. package/dist/types/common/wasm/gradient.d.ts +13 -0
  350. package/dist/types/common/wasm/heaviside.d.ts +11 -0
  351. package/dist/types/common/wasm/hypot.d.ts +21 -0
  352. package/dist/types/common/wasm/indices.d.ts +10 -0
  353. package/dist/types/common/wasm/inner.d.ts +20 -0
  354. package/dist/types/common/wasm/kron.d.ts +13 -0
  355. package/dist/types/common/wasm/ldexp.d.ts +9 -0
  356. package/dist/types/common/wasm/left_shift.d.ts +11 -0
  357. package/dist/types/common/wasm/lexsort.d.ts +14 -0
  358. package/dist/types/common/wasm/logaddexp.d.ts +21 -0
  359. package/dist/types/common/wasm/logical_and.d.ts +19 -0
  360. package/dist/types/common/wasm/logical_not.d.ts +13 -0
  361. package/dist/types/common/wasm/logical_or.d.ts +19 -0
  362. package/dist/types/common/wasm/logical_xor.d.ts +19 -0
  363. package/dist/types/common/wasm/lstsq.d.ts +14 -0
  364. package/dist/types/common/wasm/matmul.d.ts +18 -0
  365. package/dist/types/common/wasm/matvec.d.ts +13 -0
  366. package/dist/types/common/wasm/max.d.ts +11 -0
  367. package/dist/types/common/wasm/min.d.ts +11 -0
  368. package/dist/types/common/wasm/mul.d.ts +19 -0
  369. package/dist/types/common/wasm/neg.d.ts +13 -0
  370. package/dist/types/common/wasm/outer.d.ts +13 -0
  371. package/dist/types/common/wasm/pad.d.ts +14 -0
  372. package/dist/types/common/wasm/partition.d.ts +20 -0
  373. package/dist/types/common/wasm/power.d.ts +19 -0
  374. package/dist/types/common/wasm/qr.d.ts +17 -0
  375. package/dist/types/common/wasm/reciprocal.d.ts +9 -0
  376. package/dist/types/common/wasm/reduce_all.d.ts +14 -0
  377. package/dist/types/common/wasm/reduce_any.d.ts +14 -0
  378. package/dist/types/common/wasm/reduce_argmax.d.ts +14 -0
  379. package/dist/types/common/wasm/reduce_argmin.d.ts +14 -0
  380. package/dist/types/common/wasm/reduce_count_nz.d.ts +14 -0
  381. package/dist/types/common/wasm/reduce_max.d.ts +19 -0
  382. package/dist/types/common/wasm/reduce_mean.d.ts +19 -0
  383. package/dist/types/common/wasm/reduce_min.d.ts +19 -0
  384. package/dist/types/common/wasm/reduce_nanmax.d.ts +14 -0
  385. package/dist/types/common/wasm/reduce_nanmin.d.ts +14 -0
  386. package/dist/types/common/wasm/reduce_nansum.d.ts +14 -0
  387. package/dist/types/common/wasm/reduce_prod.d.ts +20 -0
  388. package/dist/types/common/wasm/reduce_quantile.d.ts +15 -0
  389. package/dist/types/common/wasm/reduce_std.d.ts +14 -0
  390. package/dist/types/common/wasm/reduce_sum.d.ts +20 -0
  391. package/dist/types/common/wasm/reduce_var.d.ts +14 -0
  392. package/dist/types/common/wasm/repeat.d.ts +14 -0
  393. package/dist/types/common/wasm/right_shift.d.ts +11 -0
  394. package/dist/types/common/wasm/roll.d.ts +13 -0
  395. package/dist/types/common/wasm/rot90.d.ts +14 -0
  396. package/dist/types/common/wasm/runtime.d.ts +44 -0
  397. package/dist/types/common/wasm/searchsorted.d.ts +12 -0
  398. package/dist/types/common/wasm/sign.d.ts +14 -0
  399. package/dist/types/common/wasm/sinh.d.ts +15 -0
  400. package/dist/types/common/wasm/sort.d.ts +20 -0
  401. package/dist/types/common/wasm/sqrt.d.ts +15 -0
  402. package/dist/types/common/wasm/square.d.ts +13 -0
  403. package/dist/types/common/wasm/sub.d.ts +19 -0
  404. package/dist/types/common/wasm/svd.d.ts +18 -0
  405. package/dist/types/common/wasm/tan.d.ts +15 -0
  406. package/dist/types/common/wasm/tanh.d.ts +15 -0
  407. package/dist/types/common/wasm/tile.d.ts +14 -0
  408. package/dist/types/common/wasm/vdot.d.ts +16 -0
  409. package/dist/types/common/wasm/vecdot.d.ts +15 -0
  410. package/dist/types/common/wasm/vecmat.d.ts +13 -0
  411. package/dist/types/core/linalg.d.ts +10 -10
  412. package/dist/types/core/reduction.d.ts +17 -17
  413. package/dist/types/core/sets.d.ts +1 -1
  414. package/dist/types/core/sorting.d.ts +1 -1
  415. package/dist/types/full/index.d.ts +20 -18
  416. package/dist/types/full/ndarray.d.ts +16 -22
  417. package/dist/types/index.d.ts +1 -0
  418. package/dist/types/io/zip/types.d.ts +2 -1
  419. package/package.json +39 -15
package/README.md CHANGED
@@ -2,37 +2,37 @@
2
2
 
3
3
  ![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)
4
4
  [![npm version](https://img.shields.io/npm/v/numpy-ts)](https://www.npmjs.com/package/numpy-ts)
5
- ![bundle size](https://img.shields.io/bundlephobia/minzip/numpy-ts)
5
+ ![bundle size](https://img.shields.io/bundlejs/size/numpy-ts)
6
6
  ![numpy api coverage](https://img.shields.io/badge/numpy_api_coverage-94%20%25-brightgreen)
7
7
 
8
- ```
9
- ███╗ ██╗██╗ ██╗███╗ ███╗██████╗ ██╗ ██╗ ████████╗███████╗
10
- ████╗ ██║██║ ██║████╗ ████║██╔══██╗╚██╗ ██╔╝ ╚══██╔══╝██╔════╝
11
- ██╔██╗ ██║██║ ██║██╔████╔██║██████╔╝ ╚████╔╝█████╗██║ ███████╗
12
- ██║╚██╗██║██║ ██║██║╚██╔╝██║██╔═══╝ ╚██╔╝ ╚════╝██║ ╚════██║
13
- ██║ ╚████║╚██████╔╝██║ ╚═╝ ██║██║ ██║ ██║ ███████║
14
- ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚══════╝
15
- ```
8
+ <picture>
9
+ <source
10
+ media="(prefers-color-scheme: dark)"
11
+ srcset="https://raw.githubusercontent.com/dupontcyborg/numpy-ts/main/docs/images/hero-dark.svg"
12
+ />
13
+ <img
14
+ src="https://raw.githubusercontent.com/dupontcyborg/numpy-ts/main/docs/images/hero-light.svg"
15
+ alt="numpy-ts"
16
+ />
17
+ </picture>
18
+
19
+ Complete NumPy implementation for TypeScript and JavaScript.
20
+
21
+ - **📊 Extensive API** — **476 of 507 NumPy functions (93.9% coverage)**
22
+ - **✅ NumPy-validated** — 8,000+ tests compared against Python NumPy
23
+ - **🔒 Type-safe** — Full TypeScript type definitions
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
16
27
 
17
- Complete NumPy implementation for TypeScript and JavaScript
28
+ [Docs](https://numpyts.dev) [Examples](https://numpyts.dev/examples) [Benchmarks](https://numpyts.dev/performance)
18
29
 
19
- **⚠️ Under active development** — API may change before v1.0
30
+ ## Install
20
31
 
21
32
  ```bash
22
33
  npm install numpy-ts
23
34
  ```
24
35
 
25
- ## Why numpy-ts?
26
-
27
- - **📊 Extensive API** — **476 of 507 NumPy functions (93.9% coverage)**
28
- - **✅ NumPy-validated** — 6,000+ test cases cross-validated against Python NumPy
29
- - **🔒 Type-safe** — Full TypeScript support with shape and dtype inference
30
- - **🌐 Universal** — Works in Node.js and browsers with .npy/.npz file support
31
- - **🎯 Zero dependencies** — Pure TypeScript, no heavy external libraries
32
- - **🌳 Tree-shakeable** — Import only what you need (~11KB for `zeros`, not 180KB)
33
-
34
- > **💡 Bundle size tip:** Standalone functions like `sin(arr)` tree-shake well. Method chaining like `arr.sin()` is convenient but pulls in the full library. See [modular imports guide](docs/modular-imports.mdx).
35
-
36
36
  ## Quick Start
37
37
 
38
38
  ```typescript
@@ -57,239 +57,18 @@ const row = A.slice('0', ':'); // A[0, :]
57
57
  const submatrix = A.slice('0:2', '1:'); // A[0:2, 1:]
58
58
  ```
59
59
 
60
- ## Features
61
-
62
- ### API Coverage
63
-
64
- Progress toward complete NumPy API compatibility:
65
-
66
- | Category | Complete | Total | Status |
67
- |----------|----------|-------|--------|
68
- | **Arithmetic** | 29/29 | 100% | ✅ |
69
- | **Array Creation** | 35/35 | 100% | ✅ |
70
- | **Array Manipulation** | 46/46 | 100% | ✅ |
71
- | **Bit Operations** | 13/13 | 100% | ✅ |
72
- | **Broadcasting** | 3/3 | 100% | ✅ |
73
- | **Comparison** | 10/10 | 100% | ✅ |
74
- | **Exponential** | 9/9 | 100% | ✅ |
75
- | **FFT** | 18/18 | 100% | ✅ |
76
- | **Gradient** | 4/4 | 100% | ✅ |
77
- | **Hyperbolic** | 9/9 | 100% | ✅ |
78
- | **I/O** | 8/8 | 100% | ✅ |
79
- | **Indexing** | 21/21 | 100% | ✅ |
80
- | **Linear Algebra** | 16/16 | 100% | ✅ |
81
- | **Linear Algebra (linalg)** | 31/31 | 100% | ✅ |
82
- | **Logic** | 24/24 | 100% | ✅ |
83
- | **NDArray Methods** | 47/47 | 100% | ✅ |
84
- | **Other Math** | 15/15 | 100% | ✅ |
85
- | **Polynomials** | 10/10 | 100% | ✅ |
86
- | **Printing/Formatting** | 10/10 | 100% | ✅ |
87
- | **Random** | 53/53 | 100% | ✅ |
88
- | **Reductions** | 36/36 | 100% | ✅ |
89
- | **Rounding** | 7/7 | 100% | ✅ |
90
- | **Searching** | 7/7 | 100% | ✅ |
91
- | **Set Operations** | 12/12 | 100% | ✅ |
92
- | **Sorting** | 6/6 | 100% | ✅ |
93
- | **Statistics** | 11/11 | 100% | ✅ |
94
- | **Trigonometric** | 16/16 | 100% | ✅ |
95
- | **Type Checking** | 7/7 | 100% | ✅ |
96
- | **Utilities** | 10/10 | 100% | ✅ |
97
- | **Unplanned** | 0/31 | 0% | 🔴 |
98
-
99
- **Overall: 476/507 functions (93.9% coverage)**
100
-
101
- See the complete [API Reference](docs/API-REFERENCE.md) for detailed function list.
102
-
103
- ### Data Types (dtypes)
104
-
105
- NumPy-compatible type system with automatic promotion:
106
-
107
- | DType | NumPy | numpy-ts | Notes |
108
- |-------|-------|----------|-------|
109
- | **Floating Point** ||||
110
- | `float64` | ✅ | ✅ | Default dtype |
111
- | `float32` | ✅ | ✅ | |
112
- | `float16` | ✅ | ⚠️ | Planned (waiting for [this](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)) |
113
- | **Signed Integers** ||||
114
- | `int64` | ✅ | ✅ | Uses BigInt |
115
- | `int32` | ✅ | ✅ | |
116
- | `int16` | ✅ | ✅ | |
117
- | `int8` | ✅ | ✅ | |
118
- | **Unsigned Integers** ||||
119
- | `uint64` | ✅ | ✅ | Uses BigInt |
120
- | `uint32` | ✅ | ✅ | |
121
- | `uint16` | ✅ | ✅ | |
122
- | `uint8` | ✅ | ✅ | |
123
- | **Other Numeric** ||||
124
- | `bool` | ✅ | ✅ | Stored as uint8 |
125
- | `complex64` | ✅ | ✅ | |
126
- | `complex128` | ✅ | ✅ | |
127
- | **Non-Numeric** ||||
128
- | `str_` | ✅ | ❌ | Not planned |
129
- | `bytes_` | ✅ | ❌ | Not planned |
130
- | `object_` | ✅ | ❌ | Not planned |
131
- | `datetime64` | ✅ | ❌ | Not planned |
132
- | `timedelta64` | ✅ | ❌ | Not planned |
133
-
134
- **Supported: 13/20 numeric dtypes**
135
-
136
- ### Intentional Divergences from NumPy
137
-
138
- numpy-ts focuses on numeric array computing. The following NumPy features are **not planned**:
139
-
140
- | Feature | Why Not Included |
141
- |---------|------------------|
142
- | **Datetime/Timedelta** (`datetime64`, `timedelta64`) | JS has native `Date`; libraries like [date-fns](https://date-fns.org/) handle time math better |
143
- | **F-order memory layout** | Exists in NumPy for Fortran/BLAS interop, which doesn't exist in JS |
144
- | **Object dtype** (`object_`) | Defeats the purpose of typed arrays; use regular JS arrays instead |
145
- | **String/Bytes dtypes** (`str_`, `bytes_`, `U`, `S`) | JS strings are first-class; no need for fixed-width string arrays |
146
- | **Exact random sequence reproduction** | numpy-ts random functions produce statistically correct distributions but use different transformation algorithms (Box-Muller vs Ziggurat), so seeded sequences won't match NumPy exactly |
147
-
148
- These omissions keep the library focused and the bundle small. For string manipulation, datetime math, or heterogeneous data, use native JS/TS constructs alongside numpy-ts.
149
-
150
- ### NumPy Memory Model
151
-
152
- - **View tracking** — `base` attribute and `OWNDATA` flag
153
- - **Strided arrays** — C/F contiguous flags for memory layout
154
- - **Zero-copy ops** — Views for slicing, transpose, reshape (when possible)
155
-
156
- ```typescript
157
- const arr = np.ones([4, 4]);
158
- const view = arr.slice('0:2', '0:2');
159
-
160
- console.log(view.base === arr); // true - view tracks base
161
- console.log(view.flags.OWNDATA); // false - doesn't own data
162
- console.log(arr.flags.C_CONTIGUOUS); // true - row-major layout
163
- ```
164
-
165
- ## Architecture
166
-
167
- ```
168
- ┌─────────────────────────────────┐
169
- │ NumPy-Compatible API │
170
- │ Broadcasting, DType Promotion │
171
- └───────────────┬─────────────────┘
172
-
173
- ┌───────────────┴─────────────────┐
174
- │ NDArray (Views & Memory Mgmt) │
175
- │ Strided Arrays, Base Tracking │
176
- └───────────────┬─────────────────┘
177
- │- - - - - - - - - - - - - - - - - - ┐
178
- ┌───────────────┴─────────────────┐ ┌ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─┐
179
- │ TypeScript / JavaScript Core │ │ WASM Compute Engine (Future) │
180
- │ Computational Engine │ │ Optimized BLAS / arithmetic │
181
- └─────────────────────────────────┘ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─┘
182
- ```
183
-
184
- Pure TypeScript implementation built from scratch for correctness and NumPy compatibility.
185
-
186
- ## Performance
187
-
188
- ![Benchmark Results](benchmarks/results/plots/latest.png)
189
-
190
- See [benchmarks/README.md](benchmarks/README.md) for detailed performance analysis.
191
-
192
- ## File I/O
193
-
194
- Read and write `.npy` and `.npz` files with Node.js or browsers.
195
-
196
- ### Node.js
197
-
198
- ```typescript
199
- import { load, save, savez, savez_compressed } from 'numpy-ts/node';
200
-
201
- save('array.npy', arr);
202
- const arr = load('array.npy');
203
-
204
- savez('arrays.npz', { a: arr1, b: arr2 });
205
- const { a, b } = load('arrays.npz');
206
- ```
207
-
208
- ### Browser
209
-
210
- ```typescript
211
- import * as np from 'numpy-ts';
212
-
213
- // Parse fetched .npy file
214
- const response = await fetch('array.npy');
215
- const arr = np.parseNpy(await response.arrayBuffer());
216
-
217
- // Serialize for download
218
- const bytes = np.serializeNpy(arr);
219
- ```
220
-
221
- *Why separate imports?* The `/node` entry includes Node.js `fs` usage. Keeping it separate ensures browser bundles stay clean.
222
-
223
- ## Examples
224
-
225
- ### Broadcasting
226
-
227
- ```typescript
228
- const matrix = np.ones([3, 4]); // (3, 4)
229
- const row = np.arange(4); // (4,)
230
- const result = matrix.add(row); // (3, 4) - row broadcast to each row
231
-
232
- const col = np.array([[1], [2], [3]]); // (3, 1)
233
- const grid = col.multiply(row); // (3, 4) - outer product via broadcasting
234
- ```
235
-
236
- ### Slicing
237
-
238
- TypeScript doesn't support Python's `arr[0:5, :]`, so we use strings:
239
-
240
- ```typescript
241
- arr.slice('0:5', '1:3'); // arr[0:5, 1:3]
242
- arr.slice(':', '-1'); // arr[:, -1]
243
- arr.slice('::2'); // arr[::2]
244
-
245
- // Convenience helpers
246
- arr.row(0); // arr[0, :]
247
- arr.col(2); // arr[:, 2]
248
- ```
249
-
250
- ### Type Safety
60
+ ## Resources
251
61
 
252
- ```typescript
253
- const arr = np.zeros([3, 4]); // Type: NDArray<Float64>
254
- arr.shape; // Type: readonly [3, 4]
255
- arr.sum(); // Type: number
256
- ```
257
-
258
-
259
- ## Comparison with Alternatives
260
-
261
- | Feature | numpy-ts | numjs | ndarray | TensorFlow.js |
262
- |---------|----------|-------|---------|---------------|
263
- | NumPy API Coverage | 476/507 (94%) | ~20% | Different | ML-focused |
264
- | TypeScript Native | ✅ Full | Partial | ❌ No | ✅ Yes |
265
- | NumPy Validated | ✅ 6,000+ tests | Mostly | ❌ No | ❌ No |
266
- | .npy/.npz Files | ✅ v1/v2/v3 | ❌ No | ❌ No | ❌ No |
267
- | Broadcasting | ✅ Full | Limited | Limited | ✅ Full |
268
- | Bundle Size | <100kb | ~60kb | ~5kb | >100kb |
62
+ - Docs: https://numpyts.dev
63
+ - Playground: https://numpyts.dev/playground
64
+ - Usage Examples: https://numpyts.dev/examples
65
+ - API Coverage Report: https://numpyts.dev/coverage
66
+ - Performance Benchmarks: https://numpyts.dev/performance
269
67
 
270
68
  ## Contributing
271
69
 
272
- Contributions welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed instructions on:
273
-
274
- - Setting up the development environment
275
- - Adding new functions with tests
276
- - Running benchmarks
277
- - Submitting pull requests
278
-
279
- ## Documentation
280
-
281
- - **[API Reference](docs/API-REFERENCE.md)** — Complete function checklist (120+ functions)
282
- - **[Feature Details](docs/FEATURES.md)** — Broadcasting, dtypes, views, slicing
283
- - **[Contributing Guide](CONTRIBUTING.md)** — How to contribute
284
- - **[Testing Guide](docs/TESTING-GUIDE.md)** — Testing strategy and examples
285
- - **[Architecture](docs/ARCHITECTURE.md)** — System design and internals
286
-
70
+ Issues and PRs are welcome: https://github.com/dupontcyborg/numpy-ts
287
71
 
288
72
  ## License
289
73
 
290
- [MIT License](LICENSE) — Copyright (c) 2025 Nicolas Dupont
291
-
292
- ---
293
-
294
- **Bring NumPy to TypeScript!** ⭐
295
- [GitHub](https://github.com/dupontcyborg/numpy-ts) • [Issues](https://github.com/dupontcyborg/numpy-ts/issues) • [NumPy Docs](https://numpy.org/)
74
+ MIT © Nicolas Dupont
@@ -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 o=new Array(t.length);let u=1;for(let e=t.length-1;e>=0;e--)o[e]=u,u*=t[e];return o}function I(t,o){let u=0,e=1;for(let r=t.length-1;r>=0;r--)u+=t[r]*e,e*=o[r];return u}function h(t,o,u){let e=u;for(let r=0;r<t.length;r++)e+=t[r]*o[r];return e}function p(t,o,u,e){const r=e.length,d=new Array(r),f=Array.from(e).filter((m,b)=>b!==o);let i=t;for(let m=f.length-1;m>=0;m--)d[m>=o?m+1:m]=i%f[m],i=Math.floor(i/f[m]);return d[o]=u,d}function A(t,o,u,e,r){const d=t.length,f=o[e],i=[],m=[];for(let l=0;l<d;l++)l!==e&&(i.push(t[l]),m.push(o[l]));const b=new Int32Array(r),s=i.length;if(s===0)b[0]=u;else if(s===1){const l=m[0];for(let n=0;n<r;n++)b[n]=u+n*l}else{const l=new Int32Array(s);l[s-1]=1;for(let n=s-2;n>=0;n--)l[n]=l[n+1]*i[n+1];for(let n=0;n<r;n++){let a=u,x=n;for(let c=0;c<s;c++){const y=x/l[c]|0;x-=y*l[c],a+=y*m[c]}b[n]=a}}return{baseOffsets:b,axisStride:f}}export{g as computeStrides,h as multiIndexToBuffer,I as multiIndexToLinear,p as outerIndexToMultiIndex,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";import{getTypedArrayConstructor as D,getDTypeSize as E,isBigIntDType as c,isComplexDType as w,isFloatDType as N}from"./dtype";import{Complex as I}from"./complex";import{ArrayStorage as B}from"./storage";import{array_str as U}from"./ops/formatting";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";import{getTypedArrayConstructor as U,isBigIntDType as _}from"../dtype";import{computeBroadcastShape as L,broadcastTo as O,broadcastShapes as H}from"../broadcasting";import{Complex as q}from"../complex";import{wasmIndices as J}from"../wasm/indices";import{wasmTakeAlongAxis2D as K}from"../wasm/gather";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}`);let l=a;_(e)?l=typeof a=="bigint"?a:BigInt(a):l=typeof a=="bigint"?Number(a):a;const 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";import{isBigIntDType as N,isComplexDType as I,isIntegerDType as _,getComplexComponentDType as x,promoteDTypes as P,throwIfComplex as S}from"../dtype";import{elementwiseBinaryOp as v}from"../internal/compute";import{wasmAdd as tt,wasmAddScalar as rt}from"../wasm/add";import{wasmSub as et,wasmSubScalar as ot}from"../wasm/sub";import{wasmMul as st,wasmMulScalar as nt}from"../wasm/mul";import{wasmDiv as E,wasmDivScalar as at}from"../wasm/divide";import{wasmNeg as it}from"../wasm/neg";import{wasmAbs as ft}from"../wasm/abs";import{wasmSign as ut}from"../wasm/sign";import{wasmMin as j,wasmMinScalar as G}from"../wasm/min";import{wasmMax as k,wasmMaxScalar as H}from"../wasm/max";import{wasmClip as ct}from"../wasm/clip";import{wasmSquare as lt}from"../wasm/square";import{wasmReciprocal as mt}from"../wasm/reciprocal";import{wasmHeavisideScalar as yt,wasmHeaviside as pt}from"../wasm/heaviside";import{wasmLdexpScalar as dt}from"../wasm/ldexp";import{wasmFrexp as gt}from"../wasm/frexp";import{wasmGcdScalar as J,wasmGcd as At}from"../wasm/gcd";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==="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};