numpy-ts 1.1.0 → 1.3.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 (456) hide show
  1. package/README.md +3 -11
  2. package/dist/esm/common/broadcasting.js +1 -1
  3. package/dist/esm/common/dtype.js +1 -1
  4. package/dist/esm/common/float16-conv.js +1 -0
  5. package/dist/esm/common/internal/compute.js +1 -1
  6. package/dist/esm/common/internal/indexing.js +1 -1
  7. package/dist/esm/common/ndarray-core.js +1 -1
  8. package/dist/esm/common/ops/advanced.js +1 -1
  9. package/dist/esm/common/ops/arithmetic.js +1 -1
  10. package/dist/esm/common/ops/bitwise.js +1 -1
  11. package/dist/esm/common/ops/comparison.js +1 -1
  12. package/dist/esm/common/ops/complex.js +1 -1
  13. package/dist/esm/common/ops/exponential.js +1 -1
  14. package/dist/esm/common/ops/fft.js +1 -1
  15. package/dist/esm/common/ops/formatting.js +1 -1
  16. package/dist/esm/common/ops/gradient.js +1 -1
  17. package/dist/esm/common/ops/hyperbolic.js +1 -1
  18. package/dist/esm/common/ops/linalg.js +2 -2
  19. package/dist/esm/common/ops/logic.js +1 -1
  20. package/dist/esm/common/ops/random.js +1 -1
  21. package/dist/esm/common/ops/reduction.js +1 -1
  22. package/dist/esm/common/ops/rounding.js +1 -1
  23. package/dist/esm/common/ops/sets.js +1 -1
  24. package/dist/esm/common/ops/shape.js +1 -1
  25. package/dist/esm/common/ops/sorting.js +1 -1
  26. package/dist/esm/common/ops/statistics.js +1 -1
  27. package/dist/esm/common/ops/trig.js +1 -1
  28. package/dist/esm/common/storage.js +1 -1
  29. package/dist/esm/common/wasm/abs.js +1 -1
  30. package/dist/esm/common/wasm/add.js +1 -1
  31. package/dist/esm/common/wasm/all_finite.js +1 -0
  32. package/dist/esm/common/wasm/arccos.js +1 -1
  33. package/dist/esm/common/wasm/arcsin.js +1 -1
  34. package/dist/esm/common/wasm/arctan.js +1 -1
  35. package/dist/esm/common/wasm/arctan2.js +1 -0
  36. package/dist/esm/common/wasm/argpartition.js +1 -1
  37. package/dist/esm/common/wasm/argsort.js +1 -1
  38. package/dist/esm/common/wasm/bins/abs.wasm.js +1 -1
  39. package/dist/esm/common/wasm/bins/add.wasm.js +1 -1
  40. package/dist/esm/common/wasm/bins/all_finite.wasm.js +1 -0
  41. package/dist/esm/common/wasm/bins/alloc.wasm.js +1 -0
  42. package/dist/esm/common/wasm/bins/arccos.wasm.js +1 -1
  43. package/dist/esm/common/wasm/bins/arcsin.wasm.js +1 -1
  44. package/dist/esm/common/wasm/bins/arctan.wasm.js +1 -1
  45. package/dist/esm/common/wasm/bins/arctan2.wasm.js +1 -0
  46. package/dist/esm/common/wasm/bins/argpartition.wasm.js +1 -1
  47. package/dist/esm/common/wasm/bins/argsort.wasm.js +1 -1
  48. package/dist/esm/common/wasm/bins/bitwise_and.wasm.js +1 -1
  49. package/dist/esm/common/wasm/bins/bitwise_count.wasm.js +1 -1
  50. package/dist/esm/common/wasm/bins/bitwise_not.wasm.js +1 -1
  51. package/dist/esm/common/wasm/bins/bitwise_or.wasm.js +1 -1
  52. package/dist/esm/common/wasm/bins/bitwise_xor.wasm.js +1 -1
  53. package/dist/esm/common/wasm/bins/cholesky.wasm.js +1 -1
  54. package/dist/esm/common/wasm/bins/clip.wasm.js +1 -1
  55. package/dist/esm/common/wasm/bins/convolve.wasm.js +1 -1
  56. package/dist/esm/common/wasm/bins/copysign.wasm.js +1 -1
  57. package/dist/esm/common/wasm/bins/correlate.wasm.js +1 -1
  58. package/dist/esm/common/wasm/bins/cos.wasm.js +1 -1
  59. package/dist/esm/common/wasm/bins/cosh.wasm.js +1 -1
  60. package/dist/esm/common/wasm/bins/cross.wasm.js +1 -1
  61. package/dist/esm/common/wasm/bins/diff.wasm.js +1 -1
  62. package/dist/esm/common/wasm/bins/divide.wasm.js +1 -1
  63. package/dist/esm/common/wasm/bins/divmod.wasm.js +1 -0
  64. package/dist/esm/common/wasm/bins/dot_float-relaxed.wasm.js +1 -0
  65. package/dist/esm/common/wasm/bins/dot_float.wasm.js +1 -0
  66. package/dist/esm/common/wasm/bins/dot_int.wasm.js +1 -0
  67. package/dist/esm/common/wasm/bins/exp.wasm.js +1 -1
  68. package/dist/esm/common/wasm/bins/exp2.wasm.js +1 -1
  69. package/dist/esm/common/wasm/bins/fft.wasm.js +1 -1
  70. package/dist/esm/common/wasm/bins/frexp.wasm.js +1 -1
  71. package/dist/esm/common/wasm/bins/gather.wasm.js +1 -1
  72. package/dist/esm/common/wasm/bins/gcd.wasm.js +1 -1
  73. package/dist/esm/common/wasm/bins/gradient.wasm.js +1 -1
  74. package/dist/esm/common/wasm/bins/heaviside.wasm.js +1 -1
  75. package/dist/esm/common/wasm/bins/hypot.wasm.js +1 -1
  76. package/dist/esm/common/wasm/bins/indices.wasm.js +1 -1
  77. package/dist/esm/common/wasm/bins/inner_float-relaxed.wasm.js +1 -0
  78. package/dist/esm/common/wasm/bins/inner_float.wasm.js +1 -0
  79. package/dist/esm/common/wasm/bins/inner_int.wasm.js +1 -0
  80. package/dist/esm/common/wasm/bins/isfinite.wasm.js +1 -0
  81. package/dist/esm/common/wasm/bins/isnan.wasm.js +1 -0
  82. package/dist/esm/common/wasm/bins/kron.wasm.js +1 -1
  83. package/dist/esm/common/wasm/bins/ldexp.wasm.js +1 -1
  84. package/dist/esm/common/wasm/bins/left_shift.wasm.js +1 -1
  85. package/dist/esm/common/wasm/bins/lexsort.wasm.js +1 -1
  86. package/dist/esm/common/wasm/bins/logaddexp.wasm.js +1 -1
  87. package/dist/esm/common/wasm/bins/logical_and.wasm.js +1 -1
  88. package/dist/esm/common/wasm/bins/logical_not.wasm.js +1 -1
  89. package/dist/esm/common/wasm/bins/logical_or.wasm.js +1 -1
  90. package/dist/esm/common/wasm/bins/logical_xor.wasm.js +1 -1
  91. package/dist/esm/common/wasm/bins/lu.wasm.js +1 -0
  92. package/dist/esm/common/wasm/bins/matmul_float-relaxed.wasm.js +1 -0
  93. package/dist/esm/common/wasm/bins/matmul_float.wasm.js +1 -0
  94. package/dist/esm/common/wasm/bins/matmul_int.wasm.js +1 -0
  95. package/dist/esm/common/wasm/bins/matvec_float-relaxed.wasm.js +1 -0
  96. package/dist/esm/common/wasm/bins/matvec_float.wasm.js +1 -0
  97. package/dist/esm/common/wasm/bins/matvec_int.wasm.js +1 -0
  98. package/dist/esm/common/wasm/bins/max.wasm.js +1 -1
  99. package/dist/esm/common/wasm/bins/min.wasm.js +1 -1
  100. package/dist/esm/common/wasm/bins/mul.wasm.js +1 -1
  101. package/dist/esm/common/wasm/bins/neg.wasm.js +1 -1
  102. package/dist/esm/common/wasm/bins/outer.wasm.js +1 -1
  103. package/dist/esm/common/wasm/bins/pad.wasm.js +1 -1
  104. package/dist/esm/common/wasm/bins/partition.wasm.js +1 -1
  105. package/dist/esm/common/wasm/bins/power.wasm.js +1 -1
  106. package/dist/esm/common/wasm/bins/qr.wasm.js +1 -1
  107. package/dist/esm/common/wasm/bins/reciprocal.wasm.js +1 -1
  108. package/dist/esm/common/wasm/bins/reduce_all.wasm.js +1 -1
  109. package/dist/esm/common/wasm/bins/reduce_any.wasm.js +1 -1
  110. package/dist/esm/common/wasm/bins/reduce_argmax.wasm.js +1 -1
  111. package/dist/esm/common/wasm/bins/reduce_argmin.wasm.js +1 -1
  112. package/dist/esm/common/wasm/bins/reduce_count_nz.wasm.js +1 -1
  113. package/dist/esm/common/wasm/bins/reduce_max.wasm.js +1 -1
  114. package/dist/esm/common/wasm/bins/reduce_mean.wasm.js +1 -1
  115. package/dist/esm/common/wasm/bins/reduce_min.wasm.js +1 -1
  116. package/dist/esm/common/wasm/bins/reduce_nanmax.wasm.js +1 -1
  117. package/dist/esm/common/wasm/bins/reduce_nanmin.wasm.js +1 -1
  118. package/dist/esm/common/wasm/bins/reduce_nansum.wasm.js +1 -1
  119. package/dist/esm/common/wasm/bins/reduce_prod.wasm.js +1 -1
  120. package/dist/esm/common/wasm/bins/reduce_std.wasm.js +1 -1
  121. package/dist/esm/common/wasm/bins/reduce_sum.wasm.js +1 -1
  122. package/dist/esm/common/wasm/bins/reduce_var.wasm.js +1 -1
  123. package/dist/esm/common/wasm/bins/repeat.wasm.js +1 -1
  124. package/dist/esm/common/wasm/bins/right_shift.wasm.js +1 -1
  125. package/dist/esm/common/wasm/bins/rng.wasm.js +1 -0
  126. package/dist/esm/common/wasm/bins/roll.wasm.js +1 -1
  127. package/dist/esm/common/wasm/bins/searchsorted.wasm.js +1 -1
  128. package/dist/esm/common/wasm/bins/sign.wasm.js +1 -1
  129. package/dist/esm/common/wasm/bins/signbit.wasm.js +1 -0
  130. package/dist/esm/common/wasm/bins/sin.wasm.js +1 -0
  131. package/dist/esm/common/wasm/bins/sinh.wasm.js +1 -1
  132. package/dist/esm/common/wasm/bins/sort.wasm.js +1 -1
  133. package/dist/esm/common/wasm/bins/sqrt.wasm.js +1 -1
  134. package/dist/esm/common/wasm/bins/square.wasm.js +1 -1
  135. package/dist/esm/common/wasm/bins/sub.wasm.js +1 -1
  136. package/dist/esm/common/wasm/bins/svd.wasm.js +1 -1
  137. package/dist/esm/common/wasm/bins/tan.wasm.js +1 -1
  138. package/dist/esm/common/wasm/bins/tanh.wasm.js +1 -1
  139. package/dist/esm/common/wasm/bins/tile.wasm.js +1 -1
  140. package/dist/esm/common/wasm/bins/unravel_index.wasm.js +1 -0
  141. package/dist/esm/common/wasm/bins/vdot.wasm.js +1 -1
  142. package/dist/esm/common/wasm/bins/vecdot_float-relaxed.wasm.js +1 -0
  143. package/dist/esm/common/wasm/bins/vecdot_float.wasm.js +1 -0
  144. package/dist/esm/common/wasm/bins/vecdot_int.wasm.js +1 -0
  145. package/dist/esm/common/wasm/bins/vecmat_float-relaxed.wasm.js +1 -0
  146. package/dist/esm/common/wasm/bins/vecmat_float.wasm.js +1 -0
  147. package/dist/esm/common/wasm/bins/vecmat_int.wasm.js +1 -0
  148. package/dist/esm/common/wasm/bins/vector_norm-relaxed.wasm.js +1 -0
  149. package/dist/esm/common/wasm/bins/vector_norm.wasm.js +1 -0
  150. package/dist/esm/common/wasm/bitwise_and.js +1 -1
  151. package/dist/esm/common/wasm/bitwise_count.js +1 -1
  152. package/dist/esm/common/wasm/bitwise_not.js +1 -1
  153. package/dist/esm/common/wasm/bitwise_or.js +1 -1
  154. package/dist/esm/common/wasm/bitwise_xor.js +1 -1
  155. package/dist/esm/common/wasm/cholesky.js +1 -1
  156. package/dist/esm/common/wasm/clip.js +1 -1
  157. package/dist/esm/common/wasm/config.js +1 -1
  158. package/dist/esm/common/wasm/convolve.js +1 -1
  159. package/dist/esm/common/wasm/copysign.js +1 -1
  160. package/dist/esm/common/wasm/correlate.js +1 -1
  161. package/dist/esm/common/wasm/cos.js +1 -1
  162. package/dist/esm/common/wasm/cosh.js +1 -1
  163. package/dist/esm/common/wasm/cross.js +1 -1
  164. package/dist/esm/common/wasm/detect.js +1 -0
  165. package/dist/esm/common/wasm/diff.js +1 -1
  166. package/dist/esm/common/wasm/divide.js +1 -1
  167. package/dist/esm/common/wasm/divmod.js +1 -0
  168. package/dist/esm/common/wasm/dot.js +1 -1
  169. package/dist/esm/common/wasm/exp.js +1 -1
  170. package/dist/esm/common/wasm/exp2.js +1 -1
  171. package/dist/esm/common/wasm/fft.js +1 -1
  172. package/dist/esm/common/wasm/frexp.js +1 -1
  173. package/dist/esm/common/wasm/gather.js +1 -1
  174. package/dist/esm/common/wasm/gcd.js +1 -1
  175. package/dist/esm/common/wasm/gradient.js +1 -1
  176. package/dist/esm/common/wasm/heaviside.js +1 -1
  177. package/dist/esm/common/wasm/hypot.js +1 -1
  178. package/dist/esm/common/wasm/indices.js +1 -1
  179. package/dist/esm/common/wasm/inner.js +1 -1
  180. package/dist/esm/common/wasm/isfinite.js +1 -0
  181. package/dist/esm/common/wasm/isnan.js +1 -0
  182. package/dist/esm/common/wasm/kron.js +1 -1
  183. package/dist/esm/common/wasm/ldexp.js +1 -1
  184. package/dist/esm/common/wasm/left_shift.js +1 -1
  185. package/dist/esm/common/wasm/lexsort.js +1 -1
  186. package/dist/esm/common/wasm/logaddexp.js +1 -1
  187. package/dist/esm/common/wasm/logical_and.js +1 -1
  188. package/dist/esm/common/wasm/logical_not.js +1 -1
  189. package/dist/esm/common/wasm/logical_or.js +1 -1
  190. package/dist/esm/common/wasm/logical_xor.js +1 -1
  191. package/dist/esm/common/wasm/lu.js +1 -0
  192. package/dist/esm/common/wasm/matmul.js +1 -1
  193. package/dist/esm/common/wasm/matvec.js +1 -1
  194. package/dist/esm/common/wasm/max.js +1 -1
  195. package/dist/esm/common/wasm/min.js +1 -1
  196. package/dist/esm/common/wasm/mul.js +1 -1
  197. package/dist/esm/common/wasm/neg.js +1 -1
  198. package/dist/esm/common/wasm/outer.js +1 -1
  199. package/dist/esm/common/wasm/pad.js +1 -1
  200. package/dist/esm/common/wasm/partition.js +1 -1
  201. package/dist/esm/common/wasm/power.js +1 -1
  202. package/dist/esm/common/wasm/qr.js +1 -1
  203. package/dist/esm/common/wasm/reciprocal.js +1 -1
  204. package/dist/esm/common/wasm/reduce_all.js +1 -1
  205. package/dist/esm/common/wasm/reduce_any.js +1 -1
  206. package/dist/esm/common/wasm/reduce_argmax.js +1 -1
  207. package/dist/esm/common/wasm/reduce_argmin.js +1 -1
  208. package/dist/esm/common/wasm/reduce_count_nz.js +1 -1
  209. package/dist/esm/common/wasm/reduce_max.js +1 -1
  210. package/dist/esm/common/wasm/reduce_mean.js +1 -1
  211. package/dist/esm/common/wasm/reduce_min.js +1 -1
  212. package/dist/esm/common/wasm/reduce_nanmax.js +1 -1
  213. package/dist/esm/common/wasm/reduce_nanmin.js +1 -1
  214. package/dist/esm/common/wasm/reduce_nansum.js +1 -1
  215. package/dist/esm/common/wasm/reduce_prod.js +1 -1
  216. package/dist/esm/common/wasm/reduce_quantile.js +1 -1
  217. package/dist/esm/common/wasm/reduce_std.js +1 -1
  218. package/dist/esm/common/wasm/reduce_sum.js +1 -1
  219. package/dist/esm/common/wasm/reduce_var.js +1 -1
  220. package/dist/esm/common/wasm/repeat.js +1 -1
  221. package/dist/esm/common/wasm/right_shift.js +1 -1
  222. package/dist/esm/common/wasm/rng.js +1 -0
  223. package/dist/esm/common/wasm/roll.js +1 -1
  224. package/dist/esm/common/wasm/runtime.js +1 -1
  225. package/dist/esm/common/wasm/searchsorted.js +1 -1
  226. package/dist/esm/common/wasm/sign.js +1 -1
  227. package/dist/esm/common/wasm/signbit.js +1 -0
  228. package/dist/esm/common/wasm/sin.js +1 -0
  229. package/dist/esm/common/wasm/sinh.js +1 -1
  230. package/dist/esm/common/wasm/sort.js +1 -1
  231. package/dist/esm/common/wasm/sqrt.js +1 -1
  232. package/dist/esm/common/wasm/square.js +1 -1
  233. package/dist/esm/common/wasm/sub.js +1 -1
  234. package/dist/esm/common/wasm/svd.js +1 -1
  235. package/dist/esm/common/wasm/tan.js +1 -1
  236. package/dist/esm/common/wasm/tanh.js +1 -1
  237. package/dist/esm/common/wasm/tile.js +1 -1
  238. package/dist/esm/common/wasm/unravel_index.js +1 -0
  239. package/dist/esm/common/wasm/vdot.js +1 -1
  240. package/dist/esm/common/wasm/vecdot.js +1 -1
  241. package/dist/esm/common/wasm/vecmat.js +1 -1
  242. package/dist/esm/common/wasm/vector_norm.js +1 -0
  243. package/dist/esm/core/advanced.js +1 -1
  244. package/dist/esm/core/arithmetic.js +1 -1
  245. package/dist/esm/core/bitwise.js +1 -1
  246. package/dist/esm/core/complex.js +1 -1
  247. package/dist/esm/core/creation.js +1 -1
  248. package/dist/esm/core/formatting.js +1 -1
  249. package/dist/esm/core/gradient.js +1 -1
  250. package/dist/esm/core/index.js +1 -1
  251. package/dist/esm/core/linalg.js +1 -1
  252. package/dist/esm/core/logic.js +1 -1
  253. package/dist/esm/core/polynomial.js +1 -1
  254. package/dist/esm/core/reduction.js +1 -1
  255. package/dist/esm/core/rounding.js +1 -1
  256. package/dist/esm/core/sets.js +1 -1
  257. package/dist/esm/core/shape-extra.js +1 -1
  258. package/dist/esm/core/shape.js +1 -1
  259. package/dist/esm/core/sorting.js +1 -1
  260. package/dist/esm/core/statistics.js +1 -1
  261. package/dist/esm/core/trig.js +1 -1
  262. package/dist/esm/core/typechecking.js +1 -1
  263. package/dist/esm/core/types.js +1 -1
  264. package/dist/esm/core/utility.js +1 -1
  265. package/dist/esm/core.js +1 -1
  266. package/dist/esm/full/index.js +1 -1
  267. package/dist/esm/full/ndarray.js +1 -1
  268. package/dist/esm/index.js +1 -1
  269. package/dist/esm/io/file-ops.js +1 -0
  270. package/dist/esm/io/filesystem.js +1 -0
  271. package/dist/esm/io/index.js +1 -1
  272. package/dist/esm/io/npy/format.js +1 -1
  273. package/dist/esm/io/npy/index.js +1 -1
  274. package/dist/esm/io/npy/parser.js +1 -1
  275. package/dist/esm/io/npy/serializer.js +2 -2
  276. package/dist/esm/io/npz/index.js +1 -1
  277. package/dist/esm/io/npz/parser.js +1 -1
  278. package/dist/esm/io/npz/serializer.js +1 -1
  279. package/dist/esm/io/txt/index.js +1 -1
  280. package/dist/esm/io/txt/parser.js +1 -1
  281. package/dist/esm/io/zip/index.js +1 -1
  282. package/dist/esm/io/zip/reader.js +1 -1
  283. package/dist/esm/io/zip/writer.js +1 -1
  284. package/dist/esm/node.js +1 -1
  285. package/dist/numpy-ts.browser.js +6 -6
  286. package/dist/types/common/dtype.d.ts +55 -4
  287. package/dist/types/common/float16-conv.d.ts +27 -0
  288. package/dist/types/common/internal/indexing.d.ts +9 -21
  289. package/dist/types/common/ndarray-core.d.ts +20 -0
  290. package/dist/types/common/ops/advanced.d.ts +17 -2
  291. package/dist/types/common/ops/complex.d.ts +19 -1
  292. package/dist/types/common/ops/linalg.d.ts +1 -1
  293. package/dist/types/common/ops/random.d.ts +10 -5
  294. package/dist/types/common/ops/reduction.d.ts +2 -2
  295. package/dist/types/common/ops/sets.d.ts +2 -1
  296. package/dist/types/common/ops/shape.d.ts +2 -2
  297. package/dist/types/common/ops/statistics.d.ts +2 -1
  298. package/dist/types/common/storage.d.ts +54 -2
  299. package/dist/types/common/wasm/all_finite.d.ts +8 -0
  300. package/dist/types/common/wasm/arccos.d.ts +4 -2
  301. package/dist/types/common/wasm/arcsin.d.ts +4 -2
  302. package/dist/types/common/wasm/arctan.d.ts +4 -2
  303. package/dist/types/common/wasm/arctan2.d.ts +17 -0
  304. package/dist/types/common/wasm/argpartition.d.ts +8 -3
  305. package/dist/types/common/wasm/argsort.d.ts +8 -3
  306. package/dist/types/common/wasm/bins/abs.wasm.d.ts +1 -0
  307. package/dist/types/common/wasm/bins/all_finite.wasm.d.ts +4 -0
  308. package/dist/types/common/wasm/bins/alloc.wasm.d.ts +6 -0
  309. package/dist/types/common/wasm/bins/arccos.wasm.d.ts +8 -2
  310. package/dist/types/common/wasm/bins/arcsin.wasm.d.ts +8 -2
  311. package/dist/types/common/wasm/bins/arctan.wasm.d.ts +8 -2
  312. package/dist/types/common/wasm/bins/arctan2.wasm.d.ts +11 -0
  313. package/dist/types/common/wasm/bins/convolve.wasm.d.ts +6 -0
  314. package/dist/types/common/wasm/bins/copysign.wasm.d.ts +2 -0
  315. package/dist/types/common/wasm/bins/correlate.wasm.d.ts +6 -0
  316. package/dist/types/common/wasm/bins/cos.wasm.d.ts +8 -0
  317. package/dist/types/common/wasm/bins/cosh.wasm.d.ts +8 -2
  318. package/dist/types/common/wasm/bins/divmod.wasm.d.ts +11 -0
  319. package/dist/types/common/wasm/bins/dot_float-relaxed.wasm.d.ts +5 -0
  320. package/dist/types/common/wasm/bins/dot_float.wasm.d.ts +5 -0
  321. package/dist/types/common/wasm/bins/dot_int.wasm.d.ts +5 -0
  322. package/dist/types/common/wasm/bins/exp.wasm.d.ts +8 -2
  323. package/dist/types/common/wasm/bins/exp2.wasm.d.ts +8 -2
  324. package/dist/types/common/wasm/bins/fft.wasm.d.ts +11 -0
  325. package/dist/types/common/wasm/bins/frexp.wasm.d.ts +1 -0
  326. package/dist/types/common/wasm/bins/gather.wasm.d.ts +0 -1
  327. package/dist/types/common/wasm/bins/gcd.wasm.d.ts +8 -0
  328. package/dist/types/common/wasm/bins/indices.wasm.d.ts +6 -2
  329. package/dist/types/common/wasm/bins/inner_float-relaxed.wasm.d.ts +5 -0
  330. package/dist/types/common/wasm/bins/inner_float.wasm.d.ts +5 -0
  331. package/dist/types/common/wasm/bins/inner_int.wasm.d.ts +5 -0
  332. package/dist/types/common/wasm/bins/isfinite.wasm.d.ts +4 -0
  333. package/dist/types/common/wasm/bins/isnan.wasm.d.ts +4 -0
  334. package/dist/types/common/wasm/bins/lexsort.wasm.d.ts +4 -4
  335. package/dist/types/common/wasm/bins/logical_and.wasm.d.ts +2 -0
  336. package/dist/types/common/wasm/bins/logical_not.wasm.d.ts +1 -0
  337. package/dist/types/common/wasm/bins/logical_or.wasm.d.ts +2 -0
  338. package/dist/types/common/wasm/bins/logical_xor.wasm.d.ts +2 -0
  339. package/dist/types/common/wasm/bins/lu.wasm.d.ts +7 -0
  340. package/dist/types/common/wasm/bins/matmul_float-relaxed.wasm.d.ts +5 -0
  341. package/dist/types/common/wasm/bins/matmul_float.wasm.d.ts +5 -0
  342. package/dist/types/common/wasm/bins/matmul_int.wasm.d.ts +5 -0
  343. package/dist/types/common/wasm/bins/matvec_float-relaxed.wasm.d.ts +5 -0
  344. package/dist/types/common/wasm/bins/matvec_float.wasm.d.ts +5 -0
  345. package/dist/types/common/wasm/bins/matvec_int.wasm.d.ts +5 -0
  346. package/dist/types/common/wasm/bins/neg.wasm.d.ts +1 -0
  347. package/dist/types/common/wasm/bins/qr.wasm.d.ts +0 -1
  348. package/dist/types/common/wasm/bins/reciprocal.wasm.d.ts +8 -4
  349. package/dist/types/common/wasm/bins/reduce_argmax.wasm.d.ts +8 -0
  350. package/dist/types/common/wasm/bins/reduce_argmin.wasm.d.ts +8 -0
  351. package/dist/types/common/wasm/bins/reduce_max.wasm.d.ts +1 -0
  352. package/dist/types/common/wasm/bins/reduce_min.wasm.d.ts +1 -0
  353. package/dist/types/common/wasm/bins/reduce_prod.wasm.d.ts +2 -0
  354. package/dist/types/common/wasm/bins/reduce_sum.wasm.d.ts +8 -2
  355. package/dist/types/common/wasm/bins/rng.wasm.d.ts +57 -0
  356. package/dist/types/common/wasm/bins/sign.wasm.d.ts +1 -0
  357. package/dist/types/common/wasm/bins/signbit.wasm.d.ts +8 -0
  358. package/dist/types/common/wasm/bins/sin.wasm.d.ts +11 -0
  359. package/dist/types/common/wasm/bins/sinh.wasm.d.ts +8 -2
  360. package/dist/types/common/wasm/bins/sort.wasm.d.ts +6 -4
  361. package/dist/types/common/wasm/bins/sqrt.wasm.d.ts +2 -2
  362. package/dist/types/common/wasm/bins/svd.wasm.d.ts +1 -0
  363. package/dist/types/common/wasm/bins/tan.wasm.d.ts +8 -0
  364. package/dist/types/common/wasm/bins/tanh.wasm.d.ts +8 -2
  365. package/dist/types/common/wasm/bins/unravel_index.wasm.d.ts +4 -0
  366. package/dist/types/common/wasm/bins/vecdot_float-relaxed.wasm.d.ts +5 -0
  367. package/dist/types/common/wasm/bins/vecdot_float.wasm.d.ts +5 -0
  368. package/dist/types/common/wasm/bins/vecdot_int.wasm.d.ts +5 -0
  369. package/dist/types/common/wasm/bins/vecmat_float-relaxed.wasm.d.ts +5 -0
  370. package/dist/types/common/wasm/bins/vecmat_float.wasm.d.ts +5 -0
  371. package/dist/types/common/wasm/bins/vecmat_int.wasm.d.ts +5 -0
  372. package/dist/types/common/wasm/bins/vector_norm-relaxed.wasm.d.ts +3 -0
  373. package/dist/types/common/wasm/bins/vector_norm.wasm.d.ts +3 -0
  374. package/dist/types/common/wasm/config.d.ts +25 -0
  375. package/dist/types/common/wasm/convolve.d.ts +1 -1
  376. package/dist/types/common/wasm/cos.d.ts +4 -2
  377. package/dist/types/common/wasm/cosh.d.ts +4 -2
  378. package/dist/types/common/wasm/detect.d.ts +17 -0
  379. package/dist/types/common/wasm/divide.d.ts +4 -0
  380. package/dist/types/common/wasm/divmod.d.ts +13 -0
  381. package/dist/types/common/wasm/exp.d.ts +4 -2
  382. package/dist/types/common/wasm/exp2.d.ts +4 -2
  383. package/dist/types/common/wasm/fft.d.ts +36 -0
  384. package/dist/types/common/wasm/frexp.d.ts +1 -0
  385. package/dist/types/common/wasm/gather.d.ts +4 -0
  386. package/dist/types/common/wasm/gcd.d.ts +1 -0
  387. package/dist/types/common/wasm/heaviside.d.ts +2 -2
  388. package/dist/types/common/wasm/hypot.d.ts +4 -2
  389. package/dist/types/common/wasm/indices.d.ts +2 -1
  390. package/dist/types/common/wasm/isfinite.d.ts +7 -0
  391. package/dist/types/common/wasm/isnan.d.ts +7 -0
  392. package/dist/types/common/wasm/lexsort.d.ts +3 -1
  393. package/dist/types/common/wasm/logaddexp.d.ts +4 -2
  394. package/dist/types/common/wasm/lu.d.ts +27 -0
  395. package/dist/types/common/wasm/partition.d.ts +3 -1
  396. package/dist/types/common/wasm/reduce_argmax.d.ts +5 -0
  397. package/dist/types/common/wasm/reduce_argmin.d.ts +5 -0
  398. package/dist/types/common/wasm/reduce_prod.d.ts +4 -0
  399. package/dist/types/common/wasm/reduce_quantile.d.ts +11 -3
  400. package/dist/types/common/wasm/reduce_sum.d.ts +10 -0
  401. package/dist/types/common/wasm/rng.d.ts +75 -0
  402. package/dist/types/common/wasm/runtime.d.ts +117 -23
  403. package/dist/types/common/wasm/searchsorted.d.ts +3 -1
  404. package/dist/types/common/wasm/signbit.d.ts +14 -0
  405. package/dist/types/common/wasm/sin.d.ts +17 -0
  406. package/dist/types/common/wasm/sinh.d.ts +4 -2
  407. package/dist/types/common/wasm/sort.d.ts +4 -1
  408. package/dist/types/common/wasm/sqrt.d.ts +4 -2
  409. package/dist/types/common/wasm/svd.d.ts +6 -0
  410. package/dist/types/common/wasm/tan.d.ts +4 -2
  411. package/dist/types/common/wasm/tanh.d.ts +4 -2
  412. package/dist/types/common/wasm/unravel_index.d.ts +12 -0
  413. package/dist/types/common/wasm/vector_norm.d.ts +11 -0
  414. package/dist/types/core/advanced.d.ts +10 -2
  415. package/dist/types/core/creation.d.ts +1 -1
  416. package/dist/types/core/index.d.ts +96 -2
  417. package/dist/types/core/linalg.d.ts +1 -1
  418. package/dist/types/core/rounding.d.ts +0 -2
  419. package/dist/types/core/sets.d.ts +4 -1
  420. package/dist/types/core/statistics.d.ts +2 -1
  421. package/dist/types/full/index.d.ts +19 -6
  422. package/dist/types/index.d.ts +20 -4
  423. package/dist/types/io/file-ops.d.ts +269 -0
  424. package/dist/types/io/filesystem.d.ts +21 -0
  425. package/dist/types/node.d.ts +3 -275
  426. package/package.json +52 -62
  427. package/dist/esm/common/wasm/bins/dot.wasm.js +0 -1
  428. package/dist/esm/common/wasm/bins/flip.wasm.js +0 -1
  429. package/dist/esm/common/wasm/bins/inner.wasm.js +0 -1
  430. package/dist/esm/common/wasm/bins/matmul.wasm.js +0 -1
  431. package/dist/esm/common/wasm/bins/matvec.wasm.js +0 -1
  432. package/dist/esm/common/wasm/bins/reduce_quantile.wasm.js +0 -1
  433. package/dist/esm/common/wasm/bins/rot90.wasm.js +0 -1
  434. package/dist/esm/common/wasm/bins/vecdot.wasm.js +0 -1
  435. package/dist/esm/common/wasm/bins/vecmat.wasm.js +0 -1
  436. package/dist/esm/common/wasm/flip.js +0 -1
  437. package/dist/esm/common/wasm/lstsq.js +0 -1
  438. package/dist/esm/common/wasm/rot90.js +0 -1
  439. package/dist/numpy-ts.node-io.cjs +0 -8
  440. package/dist/numpy-ts.node-io.cjs.map +0 -7
  441. package/dist/numpy-ts.node-io.mjs +0 -8
  442. package/dist/numpy-ts.node-io.mjs.map +0 -7
  443. package/dist/numpy-ts.node.cjs +0 -8
  444. package/dist/numpy-ts.node.cjs.map +0 -7
  445. package/dist/types/common/wasm/bins/dot.wasm.d.ts +0 -9
  446. package/dist/types/common/wasm/bins/flip.wasm.d.ts +0 -7
  447. package/dist/types/common/wasm/bins/inner.wasm.d.ts +0 -9
  448. package/dist/types/common/wasm/bins/matmul.wasm.d.ts +0 -9
  449. package/dist/types/common/wasm/bins/matvec.wasm.d.ts +0 -9
  450. package/dist/types/common/wasm/bins/reduce_quantile.wasm.d.ts +0 -2
  451. package/dist/types/common/wasm/bins/rot90.wasm.d.ts +0 -7
  452. package/dist/types/common/wasm/bins/vecdot.wasm.d.ts +0 -9
  453. package/dist/types/common/wasm/bins/vecmat.wasm.d.ts +0 -9
  454. package/dist/types/common/wasm/flip.d.ts +0 -13
  455. package/dist/types/common/wasm/lstsq.d.ts +0 -14
  456. package/dist/types/common/wasm/rot90.d.ts +0 -14
package/README.md CHANGED
@@ -19,13 +19,13 @@
19
19
  Complete NumPy implementation for TypeScript and JavaScript.
20
20
 
21
21
  - **📊 Extensive API** — **476 of 507 NumPy functions (93.9% coverage)**
22
- - **✅ NumPy-validated** — 8,000+ tests compared against Python NumPy
22
+ - **🏃🏽‍♂️ Fast** — [1.22x faster than NumPy](https://numpyts.dev/performance) on average across 2,400 benchmarks, thanks to Zig-WASM SIMD kernels
23
+ - **✅ NumPy-validated** — 20,000+ tests compared against Python NumPy
23
24
  - **🔒 Type-safe** — Full TypeScript type definitions
24
25
  - **🌳 Tree-shakeable** — Import only what you use (`np.add()` -> ~10kB bundle)
25
26
  - **🌐 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
27
27
 
28
- [Docs](https://numpyts.dev) • [Examples](https://numpyts.dev/examples) • [Benchmarks](https://numpyts.dev/performance)
28
+ [Docs](https://numpyts.dev) • [Playground](https://numpyts.dev/playground) • [Examples](https://numpyts.dev/examples) • [Coverage](https://numpyts.dev/coverage) • [Benchmarks](https://numpyts.dev/performance)
29
29
 
30
30
  ## Install
31
31
 
@@ -57,14 +57,6 @@ 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
- ## Resources
61
-
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
67
-
68
60
  ## Contributing
69
61
 
70
62
  Issues and PRs are welcome: https://github.com/dupontcyborg/numpy-ts
@@ -1 +1 @@
1
- import{ArrayStorage as d}from"./storage";function c(r){if(r.length===0)return[];if(r.length===1)return Array.from(r[0]);const n=Math.max(...r.map(t=>t.length)),e=new Array(n);for(let t=0;t<n;t++){let o=1;for(const i of r){const a=i.length-n+t,s=a<0?1:i[a];if(s!==1){if(o===1)o=s;else if(o!==s)return null}}e[t]=o}return e}function h(r,n){return c([Array.from(r),Array.from(n)])!==null}function m(r,n,e){const t=r.length,o=e.length,i=new Array(o).fill(0);for(let a=0;a<t;a++){const s=o-t+a,l=r[a],u=e[s];if(l===u)i[s]=n[a];else if(l===1)i[s]=0;else throw new Error("Invalid broadcast")}return i}function f(r,n){const e=m(r.shape,r.strides,n);return d.fromData(r.data,Array.from(n),r.dtype,e,r.offset)}function p(r){if(r.length===0)return[];if(r.length===1)return r;const n=r.map(t=>Array.from(t.shape)),e=c(n);if(e===null)throw new Error(`operands could not be broadcast together with shapes ${n.map(t=>JSON.stringify(t)).join(" ")}`);return r.map(t=>f(t,e))}function y(...r){const n=c(r);if(n===null){const e=r.map(t=>`(${t.join(",")})`).join(" ");throw new Error(`shape mismatch: objects cannot be broadcast to a single shape. Mismatch is between ${e}`)}return n}function g(r,n){const e=n?` for ${n}`:"",t=r.map(o=>`(${o.join(",")})`).join(" ");return`operands could not be broadcast together${e} with shapes ${t}`}export{h as areBroadcastable,p as broadcastArrays,g as broadcastErrorMessage,y as broadcastShapes,f as broadcastTo,c as computeBroadcastShape};
1
+ import{ArrayStorage as d}from"./storage.js";function c(r){if(r.length===0)return[];if(r.length===1)return Array.from(r[0]);const n=Math.max(...r.map(t=>t.length)),e=new Array(n);for(let t=0;t<n;t++){let o=1;for(const i of r){const a=i.length-n+t,s=a<0?1:i[a];if(s!==1){if(o===1)o=s;else if(o!==s)return null}}e[t]=o}return e}function h(r,n){return c([Array.from(r),Array.from(n)])!==null}function m(r,n,e){const t=r.length,o=e.length,i=new Array(o).fill(0);for(let a=0;a<t;a++){const s=o-t+a,l=r[a],u=e[s];if(l===u)i[s]=n[a];else if(l===1)i[s]=0;else throw new Error("Invalid broadcast")}return i}function f(r,n){const e=m(r.shape,r.strides,n);return d.fromData(r.data,Array.from(n),r.dtype,e,r.offset)}function p(r){if(r.length===0)return[];if(r.length===1)return r;const n=r.map(t=>Array.from(t.shape)),e=c(n);if(e===null)throw new Error(`operands could not be broadcast together with shapes ${n.map(t=>JSON.stringify(t)).join(" ")}`);return r.map(t=>f(t,e))}function y(...r){const n=c(r);if(n===null){const e=r.map(t=>`(${t.join(",")})`).join(" ");throw new Error(`shape mismatch: objects cannot be broadcast to a single shape. Mismatch is between ${e}`)}return n}function g(r,n){const e=n?` for ${n}`:"",t=r.map(o=>`(${o.join(",")})`).join(" ");return`operands could not be broadcast together${e} with shapes ${t}`}export{h as areBroadcastable,p as broadcastArrays,g as broadcastErrorMessage,y as broadcastShapes,f as broadcastTo,c as computeBroadcastShape};
@@ -1 +1 @@
1
- const x="float64";function A(r){switch(r){case"float64":return Float64Array;case"float32":return Float32Array;case"complex128":return Float64Array;case"complex64":return Float32Array;case"int64":return BigInt64Array;case"int32":return Int32Array;case"int16":return Int16Array;case"int8":return Int8Array;case"uint64":return BigUint64Array;case"uint32":return Uint32Array;case"uint16":return Uint16Array;case"uint8":return Uint8Array;case"bool":return Uint8Array;default:throw new Error(`Unknown dtype: ${r}`)}}function D(r){switch(r){case"complex128":return 16;case"float64":case"int64":case"uint64":case"complex64":return 8;case"float32":case"int32":case"uint32":return 4;case"int16":case"uint16":return 2;case"int8":case"uint8":case"bool":return 1;default:throw new Error(`Unknown dtype: ${r}`)}}function y(r){return r==="int64"||r==="int32"||r==="int16"||r==="int8"||r==="uint64"||r==="uint32"||r==="uint16"||r==="uint8"}function p(r){return r==="float64"||r==="float32"}function m(r){return r==="int64"||r==="uint64"}function e(r){return r==="complex64"||r==="complex128"}function b(r,t,u){if(e(r)){const f=u?` ${u}`:"";throw new TypeError(`ufunc '${t}' not supported for complex dtype '${r}'.${f}`)}}function g(r,t){if(e(r))throw new Error(`'${t}' does not yet support complex dtype '${r}'. Complex support is planned but not yet implemented.`)}function C(r){if(r==="complex128")return"float64";if(r==="complex64")return"float32";throw new Error(`${r} is not a complex dtype`)}function w(r){if(r==="float64")return"complex128";if(r==="float32")return"complex64";throw new Error(`${r} is not a valid complex component dtype`)}function T(r){return typeof r=="object"&&r!==null&&"re"in r&&"im"in r}function I(r){return typeof r=="bigint"?"int64":typeof r=="number"?Number.isInteger(r)?r>=0&&r<=255?"uint8":r>=-128&&r<=127?"int8":r>=0&&r<=65535?"uint16":r>=-32768&&r<=32767?"int16":r>=0&&r<=4294967295?"uint32":r>=-2147483648&&r<=2147483647?"int32":"float64":"float64":typeof r=="boolean"?"bool":T(r)?"complex128":x}function U(r,t){if(r===t)return r;if(r==="bool")return t;if(t==="bool")return r;if(e(r)||e(t)){if(e(r)&&e(t))return r==="complex128"||t==="complex128"?"complex128":"complex64";const n=e(r)?r:t,a=e(r)?t:r;return n==="complex128"||a==="float64"||a==="int64"||a==="uint64"||a==="int32"||a==="uint32"?"complex128":"complex64"}if(p(r)||p(t)){if(r==="float64"||t==="float64")return"float64";if(r==="float32"){const n=t;return n==="int32"||n==="int64"||n==="uint32"||n==="uint64"?"float64":"float32"}if(t==="float32"){const n=r;return n==="int32"||n==="int64"||n==="uint32"||n==="uint64"?"float64":"float32"}return"float32"}const u=r.startsWith("int"),f=t.startsWith("int"),c=r.startsWith("uint"),s=t.startsWith("uint"),l=n=>n.includes("64")?64:n.includes("32")?32:n.includes("16")?16:n.includes("8")?8:0,i=l(r),o=l(t);if(r==="int64"&&t==="uint64"||r==="uint64"&&t==="int64")return"float64";if(u&&s&&i===o){if(i===8)return"int16";if(i===16)return"int32";if(i===32)return"int64"}if(c&&f&&i===o){if(o===8)return"int16";if(o===16)return"int32";if(o===32)return"int64"}if(u&&f||c&&s){const n=Math.max(i,o);return u?n===64?"int64":n===32?"int32":n===16?"int16":"int8":n===64?"uint64":n===32?"uint32":n===16?"uint16":"uint8"}return u&&s?i>o?r:o===8?"int16":o===16?"int32":o===32?"int64":"float64":c&&f?o>i?t:i===8?"int16":i===16?"int32":i===32?"int64":"float64":"float64"}function h(r){return["float64","float32","complex128","complex64","int64","int32","int16","int8","uint64","uint32","uint16","uint8","bool"].includes(r)}function F(r,t){return m(t)?BigInt(r):t==="bool"?r?1:0:Number(r)}function $(r){return r==="int64"||r==="uint64"||e(r)?"generic":r}export{x as DEFAULT_DTYPE,F as castValue,C as getComplexComponentDType,w as getComplexDType,D as getDTypeSize,A as getTypedArrayConstructor,I as inferDType,m as isBigIntDType,e as isComplexDType,T as isComplexLike,p as isFloatDType,y as isIntegerDType,h as isValidDType,U as promoteDTypes,b as throwIfComplex,g as throwIfComplexNotImplemented,$ as toStdlibDType};
1
+ const s=typeof globalThis.Float16Array<"u";function y(t){return t==="float16"&&!s?"float32":t}const m="float64";function A(t){switch(t){case"float64":return Float64Array;case"float32":return Float32Array;case"float16":return s?Float16Array:Float32Array;case"complex128":return Float64Array;case"complex64":return Float32Array;case"int64":return BigInt64Array;case"int32":return Int32Array;case"int16":return Int16Array;case"int8":return Int8Array;case"uint64":return BigUint64Array;case"uint32":return Uint32Array;case"uint16":return Uint16Array;case"uint8":return Uint8Array;case"bool":return Uint8Array;default:throw new Error(`Unknown dtype: ${t}`)}}function b(t){switch(t){case"complex128":return 16;case"float64":case"int64":case"uint64":case"complex64":return 8;case"float32":case"int32":case"uint32":return 4;case"float16":case"int16":case"uint16":return 2;case"int8":case"uint8":case"bool":return 1;default:throw new Error(`Unknown dtype: ${t}`)}}function g(t){return t==="int64"||t==="int32"||t==="int16"||t==="int8"||t==="uint64"||t==="uint32"||t==="uint16"||t==="uint8"}function x(t){return t==="float64"||t==="float32"||t==="float16"}function T(t){return t==="int64"||t==="uint64"}function u(t){return t==="complex64"||t==="complex128"}function h(t,r,i){if(u(t)){const f=i?` ${i}`:"";throw new TypeError(`ufunc '${r}' not supported for complex dtype '${t}'.${f}`)}}function w(t,r,i){if(t==="bool"){const f=i?` ${i}`:"";throw new TypeError(`ufunc '${r}' not supported for boolean dtype.${f}`)}}function C(t,r){if(u(t))throw new Error(`'${r}' does not yet support complex dtype '${t}'. Complex support is planned but not yet implemented.`)}function I(t){if(t==="complex128")return"float64";if(t==="complex64")return"float32";throw new Error(`${t} is not a complex dtype`)}function U(t){if(t==="float64")return"complex128";if(t==="float32")return"complex64";throw new Error(`${t} is not a valid complex component dtype`)}function D(t){return typeof t=="object"&&t!==null&&"re"in t&&"im"in t}function F(t){return typeof t=="bigint"?"int64":typeof t=="number"?Number.isInteger(t)?t>=0&&t<=255?"uint8":t>=-128&&t<=127?"int8":t>=0&&t<=65535?"uint16":t>=-32768&&t<=32767?"int16":t>=0&&t<=4294967295?"uint32":t>=-2147483648&&t<=2147483647?"int32":"float64":"float64":typeof t=="boolean"?"bool":D(t)?"complex128":m}function $(t,r){if(t===r)return t;if(t==="bool")return r;if(r==="bool")return t;if(u(t)||u(r)){if(u(t)&&u(r))return t==="complex128"||r==="complex128"?"complex128":"complex64";const n=u(t)?t:r,a=u(t)?r:t;return n==="complex128"||a==="float64"||a==="int64"||a==="uint64"||a==="int32"||a==="uint32"?"complex128":"complex64"}if(x(t)||x(r)){if(t==="float64"||r==="float64")return"float64";if(t==="float32"||r==="float32"){const n=t==="float32"?r:t;return n==="int32"||n==="int64"||n==="uint32"||n==="uint64"?"float64":"float32"}if(t==="float16"||r==="float16"){const n=t==="float16"?r:t;return n==="float16"||n==="int8"||n==="uint8"?"float16":n==="int16"||n==="uint16"?"float32":"float64"}return"float32"}const i=t.startsWith("int"),f=r.startsWith("int"),c=t.startsWith("uint"),l=r.startsWith("uint"),p=n=>n.includes("64")?64:n.includes("32")?32:n.includes("16")?16:n.includes("8")?8:0,o=p(t),e=p(r);if(t==="int64"&&r==="uint64"||t==="uint64"&&r==="int64")return"float64";if(i&&l&&o===e){if(o===8)return"int16";if(o===16)return"int32";if(o===32)return"int64"}if(c&&f&&o===e){if(e===8)return"int16";if(e===16)return"int32";if(e===32)return"int64"}if(i&&f||c&&l){const n=Math.max(o,e);return i?n===64?"int64":n===32?"int32":n===16?"int16":"int8":n===64?"uint64":n===32?"uint32":n===16?"uint16":"uint8"}return i&&l?o>e?t:e===8?"int16":e===16?"int32":e===32?"int64":"float64":c&&f?e>o?r:o===8?"int16":o===16?"int32":o===32?"int64":"float64":"float64"}function B(t){switch(t){case"bool":case"int8":case"uint8":return s?"float16":"float32";case"int16":case"uint16":return"float32";case"int32":case"uint32":case"int64":case"uint64":return"float64";default:return t}}function E(t){return t==="bool"?"int8":t}function S(t){switch(t){case"bool":case"int8":case"int16":case"int32":return"int64";case"uint8":case"uint16":case"uint32":return"uint64";default:return t}}function k(t){return t==="float16"||t==="float32"||t==="complex64"?"complex64":"complex128"}function z(t){return t==="float16"||t==="float32"||t==="complex64"?"float32":"float64"}function R(t){return["float64","float32","float16","complex128","complex64","int64","int32","int16","int8","uint64","uint32","uint16","uint8","bool"].includes(t)}function W(t,r){return T(r)?BigInt(t):r==="bool"?t?1:0:Number(t)}function N(t){return t==="int64"||t==="uint64"||t==="float16"||u(t)?"generic":t}export{m as DEFAULT_DTYPE,E as boolArithmeticDtype,W as castValue,y as effectiveDType,z as fftRealResultDtype,k as fftResultDtype,I as getComplexComponentDType,U as getComplexDType,b as getDTypeSize,A as getTypedArrayConstructor,s as hasFloat16,F as inferDType,T as isBigIntDType,u as isComplexDType,D as isComplexLike,x as isFloatDType,g as isIntegerDType,R as isValidDType,B as mathResultDtype,$ as promoteDTypes,S as reductionAccumDtype,w as throwIfBool,h as throwIfComplex,C as throwIfComplexNotImplemented,N as toStdlibDType};
@@ -0,0 +1 @@
1
+ const x=new ArrayBuffer(4),l=new DataView(x);function c(s){const i=s>>>15&1,o=s>>>10&31,n=s&1023;let t;return o===0?t=n===0?0:n*2**-24:o===31?t=n===0?1/0:NaN:t=(n/1024+1)*2**(o-15),i?-t:t}function m(s){l.setFloat32(0,s,!1);const i=l.getUint32(0,!1),o=i>>>31&1,n=i>>>23&255,t=i&8388607;let f,e;if(n===255)f=31,e=t===0?0:512;else if(n>142)f=31,e=0;else if(n<103)f=0,e=0;else if(n<113){f=0;const r=125-n;e=(8388608|t)>>>r;const a=(8388608|t)&(1<<r)-1,u=1<<r-1;(a>u||a===u&&(e&1)!==0)&&e++}else{f=n-112,e=t>>>13;const r=t&8191;(r>4096||r===4096&&(e&1)!==0)&&(e++,e>1023&&(e=0,f++,f>30&&(f=31,e=0)))}return o<<15|f<<10|e}function b(s,i,o,n){const t=new DataView(s,i),f=new Float32Array(o);for(let e=0;e<o;e++){let r;r=t.getUint16(e*2,!0),f[e]=c(r)}return f}export{c as float16BitsToNumber,b as float16BytesToTypedArray,m as numberToFloat16Bits};
@@ -1 +1 @@
1
- import{ArrayStorage as B}from"../storage";import{promoteDTypes as C,isBigIntDType as h}from"../dtype";import{Complex as I}from"../complex";function z(t,r){const l=t.length,o=r.length,c=Math.max(l,o),s=new Array(c);for(let a=0;a<c;a++){const d=a<c-l?1:t[a-(c-l)],m=a<c-o?1:r[a-(c-o)];if(d===m)s[a]=d;else if(d===1)s[a]=m;else if(m===1)s[a]=d;else throw new Error(`operands could not be broadcast together with shapes ${JSON.stringify(Array.from(t))} ${JSON.stringify(Array.from(r))}`)}return s}function x(t,r,l){const o=t.length,c=l.length,s=new Array(c).fill(0);for(let a=0;a<o;a++){const d=c-o+a,m=t[a],u=l[d];if(m===u)s[d]=r[a];else if(m===1)s[d]=0;else throw new Error("Invalid broadcast")}return s}function D(t,r){const l=x(t.shape,t.strides,r);return B.fromData(t.data,Array.from(r),t.dtype,l,t.offset)}function M(t,r,l,o){const c=C(t.dtype,r.dtype),s=t.shape,a=r.shape;if(s.length===a.length&&s.every((n,i)=>n===a[i])&&t.isCContiguous&&r.isCContiguous&&!h(t.dtype)&&!h(r.dtype)&&!h(c)){const n=t.size,i=B.zeros(Array.from(s),c),g=i.data,p=t.data,S=r.data,N=t.offset,w=r.offset;if(N===0&&w===0)for(let f=0;f<n;f++)g[f]=l(p[f],S[f]);else for(let f=0;f<n;f++)g[f]=l(p[N+f],S[w+f]);return i}const m=z(t.shape,r.shape),u=D(t,m),y=D(r,m),b=B.zeros(m,c),A=b.data,e=b.size;if(h(c)){const n=A;for(let i=0;i<e;i++){const g=u.iget(i),p=y.iget(i),S=g instanceof I?g.re:g,N=p instanceof I?p.re:p,w=typeof S=="bigint"?S:BigInt(Math.round(S)),f=typeof N=="bigint"?N:BigInt(Math.round(N));o==="add"?n[i]=w+f:o==="subtract"?n[i]=w-f:o==="multiply"?n[i]=w*f:o==="divide"?n[i]=w/f:n[i]=BigInt(Math.round(l(Number(w),Number(f))))}}else{const n=h(t.dtype)||h(r.dtype);for(let i=0;i<e;i++){const g=u.iget(i),p=y.iget(i),S=Number(g),N=Number(p);A[i]=l(S,N)}}return b}function R(t,r,l){const o=z(t.shape,r.shape),c=D(t,o),s=D(r,o),a=o.reduce((u,y)=>u*y,1),d=new Uint8Array(a),m=h(t.dtype)||h(r.dtype);for(let u=0;u<a;u++){const y=c.iget(u),b=s.iget(u),A=Number(y),e=Number(b);d[u]=l(A,e)?1:0}return B.fromData(d,o,"bool")}function V(t,r,l=!0){const o=t.dtype,c=Array.from(t.shape),s=t.size,d=l?o:o!=="float32"&&o!=="float64"?"float64":o,m=B.zeros(c,d),u=m.data,y=t.data,b=t.offset,A=t.isCContiguous;if(h(o))if(h(d)){const e=u;if(A)for(let n=0;n<s;n++){const i=Number(y[b+n]);e[n]=BigInt(Math.round(r(i)))}else for(let n=0;n<s;n++)e[n]=BigInt(Math.round(r(Number(t.iget(n)))))}else if(A)for(let e=0;e<s;e++)u[e]=r(Number(y[b+e]));else for(let e=0;e<s;e++)u[e]=r(Number(t.iget(e)));else if(A)if(b===0)for(let e=0;e<s;e++)u[e]=r(Number(y[e]));else for(let e=0;e<s;e++)u[e]=r(Number(y[b+e]));else for(let e=0;e<s;e++)u[e]=r(Number(t.iget(e)));return m}export{z as broadcastShapes,M as elementwiseBinaryOp,R as elementwiseComparisonOp,V as elementwiseUnaryOp};
1
+ import{ArrayStorage as B}from"../storage.js";import{promoteDTypes as x,isBigIntDType as A,mathResultDtype as z}from"../dtype.js";import{Complex as C}from"../complex.js";function I(t,r){const c=t.length,a=r.length,u=Math.max(c,a),o=new Array(u);for(let n=0;n<u;n++){const f=n<u-c?1:t[n-(u-c)],i=n<u-a?1:r[n-(u-a)];if(f===i)o[n]=f;else if(f===1)o[n]=i;else if(i===1)o[n]=f;else throw new Error(`operands could not be broadcast together with shapes ${JSON.stringify(Array.from(t))} ${JSON.stringify(Array.from(r))}`)}return o}function O(t,r,c){const a=t.length,u=c.length,o=new Array(u).fill(0);for(let n=0;n<a;n++){const f=u-a+n,i=t[n],b=c[f];if(i===b)o[f]=r[n];else if(i===1)o[f]=0;else throw new Error("Invalid broadcast")}return o}function D(t,r){const c=O(t.shape,t.strides,r);return B.fromData(t.data,Array.from(r),t.dtype,c,t.offset)}function V(t,r,c,a){const u=x(t.dtype,r.dtype),o=t.shape,n=r.shape;if(o.length===n.length&&o.every((l,s)=>l===n[s])&&t.isCContiguous&&r.isCContiguous&&!A(t.dtype)&&!A(r.dtype)&&!A(u)){const l=t.size,s=B.empty(Array.from(o),u),p=s.data,h=t.offset,S=r.offset,N=t.data,w=r.data;if(h===0&&S===0)for(let m=0;m<l;m++)p[m]=c(N[m],w[m]);else for(let m=0;m<l;m++)p[m]=c(N[h+m],w[S+m]);return s}const i=I(t.shape,r.shape),b=D(t,i),y=D(r,i),g=B.empty(i,u),e=g.data,d=g.size;if(A(u)){const l=e;for(let s=0;s<d;s++){const p=b.iget(s),h=y.iget(s),S=p instanceof C?p.re:p,N=h instanceof C?h.re:h,w=typeof S=="bigint"?S:BigInt(Math.round(S)),m=typeof N=="bigint"?N:BigInt(Math.round(N));a==="add"?l[s]=w+m:a==="subtract"?l[s]=w-m:a==="multiply"?l[s]=w*m:a==="divide"?l[s]=w/m:l[s]=BigInt(Math.round(c(Number(w),Number(m))))}}else{const l=A(t.dtype)||A(r.dtype);for(let s=0;s<d;s++){const p=b.iget(s),h=y.iget(s),S=Number(p),N=Number(h);e[s]=c(S,N)}}return g}function T(t,r,c){const a=I(t.shape,r.shape),u=D(t,a),o=D(r,a),n=B.empty(a,"bool"),f=n.data,i=n.size,b=A(t.dtype)||A(r.dtype);for(let y=0;y<i;y++){const g=u.iget(y),e=o.iget(y),d=Number(g),l=Number(e);f[y]=c(d,l)?1:0}return n}function U(t,r,c=!0){const a=t.dtype,u=Array.from(t.shape),o=t.size,n=c?a:z(a),f=B.empty(u,n),i=f.data,b=t.data,y=t.offset,g=t.isCContiguous;if(A(a))if(A(n)){const e=i;if(g)for(let d=0;d<o;d++){const l=Number(b[y+d]);e[d]=BigInt(Math.round(r(l)))}else for(let d=0;d<o;d++)e[d]=BigInt(Math.round(r(Number(t.iget(d)))))}else if(g)for(let e=0;e<o;e++)i[e]=r(Number(b[y+e]));else for(let e=0;e<o;e++)i[e]=r(Number(t.iget(e)));else if(g)if(y===0)for(let e=0;e<o;e++)i[e]=r(Number(b[e]));else for(let e=0;e<o;e++)i[e]=r(Number(b[y+e]));else for(let e=0;e<o;e++)i[e]=r(Number(t.iget(e)));return f}export{I as broadcastShapes,V as elementwiseBinaryOp,T as elementwiseComparisonOp,U as elementwiseUnaryOp};
@@ -1 +1 @@
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
+ function p(n){const s=new Array(n.length);let t=1;for(let o=n.length-1;o>=0;o--)s[o]=t,t*=n[o];return s}function y(n,s,t,o,i){const f=n.length,b=s[o],u=[],l=[];for(let r=0;r<f;r++)r!==o&&(u.push(n[r]),l.push(s[r]));const m=new Int32Array(i),a=u.length;if(a===0)m[0]=t;else if(a===1){const r=l[0];for(let e=0;e<i;e++)m[e]=t+e*r}else{const r=new Int32Array(a);r[a-1]=1;for(let e=a-2;e>=0;e--)r[e]=r[e+1]*u[e+1];for(let e=0;e<i;e++){let d=t,x=e;for(let c=0;c<a;c++){const g=x/r[c]|0;x-=g*r[c],d+=g*l[c]}m[e]=d}}return{baseOffsets:m,axisStride:b}}function h(n,s){const t=n.filter(l=>l==="...").length,o=n.filter(l=>l==="newaxis").length;if(t>1)throw new Error("an index can only have a single ellipsis (...)");const i=n.length-t-o,f=s-i;if(f<0)throw new Error(`Too many indices for array: array is ${s}-dimensional, but ${i} were indexed`);if(f===0&&t===0)return n;const b=t===0?n.length:n.indexOf("..."),u=n.slice();return u.splice(b,t,...Array(f).fill(":")),u}export{p as computeStrides,h as expandEllipsis,y as precomputeAxisOffsets};
@@ -1 +1 @@
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
+ var z;import*as D from"./ops/shape.js";import{getTypedArrayConstructor as U,getDTypeSize as E,isBigIntDType as b,isComplexDType as w,isFloatDType as N}from"./dtype.js";import{Complex as I}from"./complex.js";import{ArrayStorage as B}from"./storage.js";import{array_str as S}from"./ops/formatting.js";const T=2**63,x={int8:-1,int16:-1,uint8:255,uint16:65535},O={int8:0,int16:0,uint8:0,uint16:0},C={int32:[-2147483648,2147483647],uint32:[0,4294967295]};function $(u,t){if(isNaN(u))return 0;if(t in x)return u>=T||u===1/0?x[t]:u<=-T||u===-1/0?O[t]:Math.trunc(u);if(t in C){const[e,s]=C[t];return u>=s||u===1/0?s:u<=e||u===-1/0?e:Math.trunc(u)}return Math.trunc(u)}class d{static{this._proxyHandler={get(t,e,s){if(typeof e=="string"){const n=parseInt(e,10);if(!isNaN(n)&&String(n)===e){const r=t._storage.ndim>0?t._storage.shape[0]:1,g=n<0?r+n:n;return t._storage.ndim<=1?t._storage.iget(g):t.slice(e)}}return Reflect.get(t,e,s)},set(t,e,s,n){if(typeof e=="string"){const r=parseInt(e,10);if(!isNaN(r)&&String(r)===e){const g=t._storage.shape[0],c=r<0?g+r:r;if(t._storage.ndim===1)return t.set([c],s),!0;const A=t.slice(String(r)),y=A.size;if(typeof s=="number"||typeof s=="bigint")A.fill(s);else if(s instanceof I)for(let l=0;l<y;l++)A._storage.iset(l,s);else if(s instanceof d){if(s.size!==y)throw new Error(`Cannot assign array of size ${s.size} into slice of size ${y}`);for(let l=0;l<y;l++)A._storage.iset(l,s._storage.iget(l))}else if(Array.isArray(s)){const l=s.flat(1/0);if(l.length!==y)throw new Error(`Cannot assign array of length ${l.length} into slice of size ${y}`);for(let p=0;p<y;p++)A._storage.iset(p,l[p])}else throw new Error(`Cannot assign value of type ${typeof s} via bracket operator`);return!0}}return Reflect.set(t,e,s,n)}}}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,s=this.size;if(b(e)){const n=typeof t=="bigint"?t:BigInt(Math.round(Number(t)));for(let r=0;r<s;r++)this._storage.iset(r,n)}else if(e==="bool"){const n=t?1:0;for(let r=0;r<s;r++)this._storage.iset(r,n)}else{const n=Number(t);for(let r=0;r<s;r++)this._storage.iset(r,n)}}*[(z=Symbol.iterator,Symbol.dispose,z)](){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((s,n)=>{let r=s;if(r<0&&(r=this.shape[n]+r),r<0||r>=this.shape[n])throw new Error(`Index ${s} is out of bounds for axis ${n} with size ${this.shape[n]}`);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 s=t.map((r,g)=>{let c=r;if(c<0&&(c=this.shape[g]+c),c<0||c>=this.shape[g])throw new Error(`Index ${r} is out of bounds for axis ${g} with size ${this.shape[g]}`);return c}),n=this.dtype;if(w(n))this._storage.set(s,e);else if(b(n)){const r=e instanceof I?e.re:Number(e),g=typeof e=="bigint"?e:BigInt(Math.round(r));this._storage.set(s,g)}else if(n==="bool"){const g=(e instanceof I?e.re:Number(e))?1:0;this._storage.set(s,g)}else{const r=e instanceof I?e.re:Number(e);this._storage.set(s,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 s=this.dtype;if(s===t&&!e)return this;if(s===t&&e)return this.copy();const n=Array.from(this.shape),r=this.size,g=U(t);if(!g)throw new Error(`Cannot convert to dtype ${t}`);const c=w(s),A=w(t);if(c&&A){const o=new g(r*2),i=this.data,f=o;for(let h=0;h<r*2;h++)f[h]=i[h];const a=B.fromData(o,n,t);return new d(a)}if(!c&&A){const o=new g(r*2),i=o;for(let a=0;a<r;a++)i[a*2]=Number(this.data[a]),i[a*2+1]=0;const f=B.fromData(o,n,t);return new d(f)}if(c&&!A){const o=new g(r),i=this.data;if(b(t)){const a=t==="int64";for(let h=0;h<r;h++){const m=Math.trunc(i[h*2]);isNaN(m)||!a&&m<0?o[h]=0n:o[h]=BigInt(m)}}else if(t==="bool")for(let a=0;a<r;a++)o[a]=i[a*2]!==0?1:0;else if(t==="uint32")for(let a=0;a<r;a++){const h=i[a*2];o[a]=isNaN(h)||h<0?0:h}else for(let a=0;a<r;a++)o[a]=i[a*2];const f=B.fromData(o,n,t);return new d(f)}const y=new g(r),l=this.data;if(b(s)&&!b(t)){const o=l;if(t==="bool")for(let i=0;i<r;i++)y[i]=o[i]!==BigInt(0)?1:0;else for(let i=0;i<r;i++)y[i]=Number(o[i])}else if(!b(s)&&b(t)){const o=l;if(N(s)){const f=t==="int64",a=BigInt(f?"9223372036854775807":"18446744073709551615"),h=f?BigInt("-9223372036854775808"):0n;for(let m=0;m<r;m++){const _=Number(o[m]);isNaN(_)?y[m]=0n:!isFinite(_)||_>=Number(a)?y[m]=_<0?h:a:_<=Number(h)?y[m]=h:y[m]=BigInt(Math.trunc(_))}}else for(let f=0;f<r;f++)y[f]=BigInt(Math.round(Number(o[f])))}else if(t==="bool"){const o=l;for(let i=0;i<r;i++)y[i]=o[i]!==0?1:0}else if(s==="bool"&&!b(t)){const o=l;for(let i=0;i<r;i++)y[i]=o[i]}else if(!b(s)&&!b(t)){const o=l;if(N(s)&&!N(t))for(let f=0;f<r;f++)y[f]=$(o[f],t);else for(let f=0;f<r;f++)y[f]=o[f]}else{const o=l;for(let i=0;i<r;i++)y[i]=o[i]}const p=B.fromData(y,n,t);return new d(p)}slice(...t){const e=D.slice(this._storage,...t);if(e===this._storage)return this;const s=this._base??this;return new this.constructor(e,s)}toString(){return S(this._storage)}toArray(){if(this.ndim===0)return this._storage.iget(0);const t=this.shape,e=t.length,s=(n,r)=>{if(r===e)return this._storage.get(...n);const g=[];for(let c=0;c<t[r];c++)n[r]=c,g.push(s(n,r+1));return g};return s(new Array(e),0)}tolist(){return this.toArray()}tobytes(){if(this._storage.isCContiguous){const s=this._storage.data,n=s.BYTES_PER_ELEMENT,r=s.byteOffset+this._storage.offset*n,g=this.size*n;return s.buffer.slice(r,r+g)}const e=this.copy()._storage.data;return e.buffer.slice(e.byteOffset,e.byteOffset+this.size*e.BYTES_PER_ELEMENT)}dispose(){this._storage.dispose()}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)}}typeof Symbol.dispose<"u"&&(d.prototype[Symbol.dispose]=d.prototype.dispose);export{d as NDArrayCore};
@@ -1 +1 @@
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
+ import{ArrayStorage as z,computeStrides as _}from"../storage.js";import{getTypedArrayConstructor as q,isBigIntDType as $,isComplexDType as j}from"../dtype.js";import{computeBroadcastShape as O,broadcastTo as k,broadcastShapes as G}from"../broadcasting.js";import{Complex as W}from"../complex.js";import{parseSlice as H}from"../slicing.js";import{expandEllipsis as J}from"../internal/indexing.js";import{slice as K,transpose as Y}from"./shape.js";import{wasmIndices as P}from"../wasm/indices.js";import{wasmTakeAlongAxis2D as Q}from"../wasm/gather.js";import{wasmUnravelIndex as X}from"../wasm/unravel_index.js";function ht(t,r){const n=t.shape,s=n.length,o=r.length;if(o<s)throw new Error("input operand has more dimensions than allowed by the axis remapping");const e=O([Array.from(n),r]);if(e===null)throw new Error(`operands could not be broadcast together with shape (${n.join(",")}) (${r.join(",")})`);for(let u=0;u<o;u++)if(e[u]!==r[u])throw new Error(`operands could not be broadcast together with shape (${n.join(",")}) (${r.join(",")})`);return k(t,r)}function Z(t){if(t.length===0)return[];if(t.length===1)return[t[0]];const r=t.map(s=>Array.from(s.shape)),n=O(r);if(n===null)throw new Error(`operands could not be broadcast together with shapes ${r.map(s=>`(${s.join(",")})`).join(" ")}`);return t.map(s=>k(s,n))}function bt(t,r,n){const s=t.shape,o=s.length,e=t.dtype;if(n===void 0){const S=t.size;for(const d of r){const m=d<0?S+d:d;if(m<0||m>=S)throw new Error(`index ${d} is out of bounds for axis 0 with size ${S}`)}const B=r.length,N=z.empty([B],e),C=N.data,p=j(e);for(let d=0;d<B;d++){let m=r[d];if(m<0&&(m=S+m),p){const w=t.iget(m);C[d*2]=w.re,C[d*2+1]=w.im}else $(e),C[d]=t.iget(m)}return N}const u=n<0?o+n:n;if(u<0||u>=o)throw new Error(`axis ${n} is out of bounds for array of dimension ${o}`);const a=s[u];for(const S of r){const B=S<0?a+S:S;if(B<0||B>=a)throw new Error(`index ${S} is out of bounds for axis ${u} with size ${a}`)}const y=Array.from(s);y[u]=r.length;const i=y.reduce((S,B)=>S*B,1),l=z.empty(y,e),f=l.data,c=_(y),A=new Array(o).fill(0);for(let S=0;S<i;S++){const B=[...A];let N=A[u],C=r[N];C<0&&(C=a+C),B[u]=C;const p=t.get(...B);let d=0;for(let m=0;m<o;m++)d+=A[m]*c[m];if(j(e)){const m=p;f[d*2]=m.re,f[d*2+1]=m.im}else $(e),f[d]=p;for(let m=o-1;m>=0&&(A[m]++,!(A[m]<y[m]));m--)A[m]=0}return l}function At(t,r,n){const s=t.size,o=t.dtype;let e;if(typeof n=="number"||typeof n=="bigint")e=new Array(r.length).fill(n);else{e=[];for(let u=0;u<n.size;u++){const a=n.iget(u);e.push(a instanceof W?a.re:a)}if(e.length===1)e=new Array(r.length).fill(e[0]);else if(e.length!==r.length){const u=[...e];e=[];for(let a=0;a<r.length;a++)e.push(u[a%u.length])}}for(let u=0;u<r.length;u++){let a=r[u];if(a<0&&(a=s+a),a<0||a>=s)throw new Error(`index ${r[u]} is out of bounds for axis 0 with size ${s}`);let y=e[u];$(o)?typeof y!="bigint"&&(y=BigInt(Math.round(Number(y)))):typeof y=="bigint"&&(y=Number(y)),t.iset(a,y)}}function xt(t,r){if(r.length===0)throw new Error("choices cannot be empty");const n=t.shape,s=r.length,o=r[0].dtype,e=r.map(c=>Array.from(c.shape));e.unshift(Array.from(n));const u=O(e);if(u===null)throw new Error("operands could not be broadcast together");const a=k(t,u),y=r.map(c=>k(c,u)),i=u.reduce((c,A)=>c*A,1),l=z.empty(u,o),f=l.data;for(let c=0;c<i;c++){const A=Number(a.iget(c));if(A<0||A>=s)throw new Error(`index ${A} is out of bounds for axis 0 with size ${s}`);const S=y[A].iget(c);$(o),f[c]=S}return l}function St(t,r,n=!1){if(t.ndim!==r.ndim)return!1;for(let o=0;o<t.ndim;o++)if(t.shape[o]!==r.shape[o])return!1;const s=t.size;for(let o=0;o<s;o++){const e=t.iget(o),u=r.iget(o),a=typeof e=="object"&&e!==null&&"re"in e,y=typeof u=="object"&&u!==null&&"re"in u;if(a||y){const i=a?e.re:Number(e),l=a?e.im:0,f=y?u.re:Number(u),c=y?u.im:0;if(n&&isNaN(i)&&isNaN(f)&&isNaN(l)&&isNaN(c)||n&&i===f&&isNaN(l)&&isNaN(c)||n&&isNaN(i)&&isNaN(f)&&l===c)continue;if(i!==f||l!==c)return!1;continue}if(n){const i=typeof e=="number"&&Number.isNaN(e),l=typeof u=="number"&&Number.isNaN(u);if(i&&l)continue}if(e!==u)return!1}return!0}function wt(t,r,n){const s=Q(t,r,n);if(s)return s;const o=t.shape,e=o.length,u=t.dtype,a=n<0?e+n:n;if(a<0||a>=e)throw new Error(`axis ${n} is out of bounds for array of dimension ${e}`);const y=r.shape;if(y.length!==e)throw new Error(`indices and arr must have the same number of dimensions, got ${y.length} vs ${e}`);for(let b=0;b<e;b++)if(b!==a&&y[b]!==o[b]&&y[b]!==1&&o[b]!==1)throw new Error(`index ${y[b]} is out of bounds for size ${o[b]} in dimension ${b}`);const i=Array.from(y),l=i.reduce((b,E)=>b*E,1),f=z.empty(i,u),c=f.data,A=_(o),S=_(y),B=o[a],N=_(i),C=new Array(e),p=$(u),d=j(u),m=t.isCContiguous,w=r.isCContiguous,x=t.data,h=t.offset,g=r.data,F=r.offset;for(let b=0;b<l;b++){let E=b;for(let I=0;I<e;I++)C[I]=E/N[I]|0,E-=C[I]*N[I];let D=0;for(let I=0;I<e;I++){const R=y[I]===1?0:C[I];D+=R*S[I]}let T=Number(w?g[F+D]:r.iget(D));T<0&&(T=B+T);let v=0;for(let I=0;I<e;I++){const R=I===a?T:o[I]===1?0:C[I];v+=R*A[I]}if(d)if(m){const I=(h+v)*2;c[b*2]=x[I],c[b*2+1]=x[I+1]}else{const I=t.iget(v);c[b*2]=I.re,c[b*2+1]=I.im}else if(m)c[b]=x[h+v];else{const I=t.iget(v);c[b]=I}}return f}function It(t,r,n,s){const o=t.shape,e=o.length,u=t.dtype,a=s<0?e+s:s;if(a<0||a>=e)throw new Error(`axis ${s} is out of bounds for array of dimension ${e}`);const y=r.shape,i=n.shape;if(y.length!==e||i.length!==e)throw new Error("indices, arr, and values must have same ndim");const l=o[a],f=_(o),c=_(y),A=_(i),S=y.reduce((B,N)=>B*N,1);for(let B=0;B<S;B++){const N=new Array(e);let C=B;for(let g=e-1;g>=0;g--)N[g]=C%y[g],C=Math.floor(C/y[g]);let p=0;for(let g=0;g<e;g++)p+=N[g]*c[g];let d=Number(r.iget(p));if(d<0&&(d=l+d),d<0||d>=l)throw new Error(`index ${d} is out of bounds for axis ${a} with size ${l}`);let m=0;for(let g=0;g<e;g++){const F=i[g]===1?0:N[g];m+=F*A[g]}let w=n.iget(m);const x=[...N];x[a]=d;let h=0;for(let g=0;g<e;g++)h+=x[g]*f[g];$(u)?typeof w!="bigint"&&(w=BigInt(Math.round(Number(w)))):typeof w=="bigint"&&(w=Number(w)),t.iset(h,w)}}function zt(t,r,n){const s=t.size,o=t.dtype;let e;if(typeof n=="number"||typeof n=="bigint")e=[n];else{e=[];for(let a=0;a<n.size;a++){const y=n.iget(a);e.push(y instanceof W?y.re:y)}}let u=0;for(let a=0;a<s;a++)if(r.iget(a)){let i=e[u%e.length];$(o)?typeof i!="bigint"&&(i=BigInt(Math.round(Number(i)))):typeof i=="bigint"&&(i=Number(i)),t.iset(a,i),u++}}function Bt(t,r,n){const s=r.shape,o=s.length,e=r.dtype,u=$(e);if(n===void 0){const x=Math.min(t.size,r.size),h=t.isCContiguous,g=t.data,F=t.offset;let b=0;if(h)for(let I=0;I<x;I++)g[F+I]&&b++;else for(let I=0;I<x;I++)t.iget(I)&&b++;const E=z.empty([b],e),D=E.data;let T=0;const v=r.isCContiguous;if(h&&v){const I=r.data,R=r.offset;if(u){const L=D,V=I;for(let M=0;M<x;M++)g[F+M]&&(L[T++]=V[R+M])}else{const L=D,V=I;for(let M=0;M<x;M++)g[F+M]&&(L[T++]=V[R+M])}}else for(let I=0;I<x;I++)(h?g[F+I]:t.iget(I))&&(D[T]=r.iget(I),T++);return E}const a=n<0?o+n:n;if(a<0||a>=o)throw new Error(`axis ${n} is out of bounds for array of dimension ${o}`);const y=s[a],i=Math.min(t.size,y),l=[],f=t.isCContiguous,c=t.data,A=t.offset;for(let x=0;x<i;x++)(f?c[A+x]:t.iget(x))&&l.push(x);const S=l.length,B=[...s];B[a]=S;const N=z.empty(B,e),C=N.data,p=s.slice(a+1).reduce((x,h)=>x*h,1),d=s.slice(0,a).reduce((x,h)=>x*h,1);let m=0;if(r.isCContiguous){const x=r.data,h=r.offset;for(let g=0;g<d;g++){const F=h+g*y*p;for(let b=0;b<S;b++){const E=F+l[b]*p;C.set(x.subarray(E,E+p),m),m+=p}}}else for(let x=0;x<d;x++)for(let h=0;h<S;h++){const g=l[h];for(let F=0;F<p;F++){const b=x*y*p+g*p+F;C[m++]=r.iget(b)}}return N}function Et(t,r,n=0){if(t.length!==r.length)throw new Error("condlist and choicelist must have same length");if(t.length===0)throw new Error("condlist and choicelist cannot be empty");const s=[...t.map(c=>Array.from(c.shape)),...r.map(c=>Array.from(c.shape))],o=O(s);if(o===null)throw new Error("condlist and choicelist arrays could not be broadcast together");const e=r[0].dtype,u=o.reduce((c,A)=>c*A,1),a=$(e)?typeof n=="bigint"?n:BigInt(n):typeof n=="bigint"?Number(n):n,y=z.empty(o,e),i=y.data;for(let c=0;c<u;c++)$(e),i[c]=a;const l=t.map(c=>k(c,o)),f=r.map(c=>k(c,o));for(let c=0;c<u;c++)for(let A=0;A<t.length;A++)if(l[A].iget(c)){const S=f[A].iget(c);$(e),i[c]=S;break}return y}function Ct(t,r,n){const s=t.size,o=t.dtype,e=[];for(let a=0;a<n.size;a++){const y=n.iget(a);e.push(y instanceof W?y.re:y)}if(e.length===0)return;let u=0;for(let a=0;a<s;a++)if(r.iget(a)){let i=e[u%e.length];$(o)?typeof i!="bigint"&&(i=BigInt(Math.round(Number(i)))):typeof i=="bigint"&&(i=Number(i)),t.iset(a,i),u++}}function tt(t,r=2){if(r<1)throw new Error("ndim must be at least 1");const n=new Float64Array(t);for(let o=0;o<t;o++)n[o]=o;const s=[];for(let o=0;o<r;o++){const e=z.empty([t],"float64");e.data.set(n),s.push(e)}return s}function Nt(t){const r=t.shape,n=r.length;if(n<2)throw new Error("array must be at least 2-D");const s=r[0];for(let o=1;o<n;o++)if(r[o]!==s)throw new Error("All dimensions of input must be equal");return tt(s,n)}function rt(t,r=0,n){const s=n??t,o=[],e=[];for(let y=0;y<t;y++)for(let i=0;i<=Math.min(y+r,s-1);i++)i>=0&&(o.push(y),e.push(i));const u=z.empty([o.length],"float64");u.data.set(o);const a=z.empty([e.length],"float64");return a.data.set(e),[u,a]}function Ft(t,r=0){const n=t.shape;if(n.length!==2)throw new Error("array must be 2-D");return rt(n[0],r,n[1])}function et(t,r=0,n){const s=n??t,o=[],e=[];for(let y=0;y<t;y++)for(let i=Math.max(y+r,0);i<s;i++)o.push(y),e.push(i);const u=z.empty([o.length],"float64");u.data.set(o);const a=z.empty([e.length],"float64");return a.data.set(e),[u,a]}function Dt(t,r=0){const n=t.shape;if(n.length!==2)throw new Error("array must be 2-D");return et(n[0],r,n[1])}function $t(t,r,n=0){const s=z.empty([t,t],"float64");s.data.fill(1);const o=r(s,n),e=o.shape;if(e.length!==2||e[0]!==t||e[1]!==t)throw new Error("mask_func must return n x n array");const u=[],a=[];for(let l=0;l<t;l++)for(let f=0;f<t;f++)o.get(l,f)&&(u.push(l),a.push(f));const y=z.empty([u.length],"float64");y.data.set(u);const i=z.empty([a.length],"float64");return i.data.set(a),[y,i]}function Tt(t,r="float64"){if(r==="int32"||r==="int64"||r==="float64"){const l=P(t,r);if(l)return l}const n=t.length,s=t.reduce((l,f)=>l*f,1);if(r==="bool"&&s>2)throw new TypeError("arange() is only supported for booleans when the result has at most length 2.");const o=[n,...t],e=r==="complex128"||r==="complex64",u=r==="int64"||r==="uint64",a=z.empty(o,r),y=a.data,i=new Array(n);i[n-1]=1;for(let l=n-2;l>=0;l--)i[l]=i[l+1]*t[l+1];for(let l=0;l<n;l++){const f=l*s,c=t[l],A=i[l];for(let S=0;S<s;S++){const B=Math.floor(S/A)%c;e?(y[(f+S)*2]=B,y[(f+S)*2+1]=0):u?y[f+S]=BigInt(B):y[f+S]=B}}return a}function vt(...t){const r=t.length,n=[];for(let s=0;s<r;s++){let o=t[s];if(o.dtype==="bool"){const i=[];for(let f=0;f<o.size;f++)o.iget(f)&&i.push(f);const l=z.empty([i.length],"int64");for(let f=0;f<i.length;f++)l.data[f]=BigInt(i[f]);o=l}const e=o.size,u=o.dtype,a=new Array(r).fill(1);a[s]=e;const y=z.empty(a,u);for(let i=0;i<e;i++)y.iset(i,o.iget(i));n.push(y)}return n}function Mt(t,r,n="raise"){if(t.length!==r.length)throw new Error("multi_index length must equal dims length");if(t.length===0)throw new Error("multi_index cannot be empty");const s=t[0].size,o=r.length,e=z.empty([s],"float64"),u=e.data,a=new Array(o);let y=1;for(let i=o-1;i>=0;i--)a[i]=y,y*=r[i];for(let i=0;i<s;i++){let l=0;for(let f=0;f<o;f++){let c=Number(t[f].iget(i));const A=r[f];if(n==="wrap")c=(c%A+A)%A;else if(n==="clip")c=Math.max(0,Math.min(c,A-1));else if(c<0||c>=A)throw new Error(`index ${c} is out of bounds for axis ${f} with size ${A}`);l+=c*a[f]}u[i]=l}return e}function Ut(t,r,n="C"){const s=r.length;if(n==="C"&&typeof t!="number"){const l=X(t,r);if(l)return l}let o,e;if(typeof t=="number")o=[t],e=[];else{o=[];for(let l=0;l<t.size;l++)o.push(Number(t.iget(l)));e=Array.from(t.shape)}const u=o.length,a=r.reduce((l,f)=>l*f,1),y=new Array(s);if(n==="C"){let l=1;for(let f=s-1;f>=0;f--)y[f]=l,l*=r[f]}else{let l=1;for(let f=0;f<s;f++)y[f]=l,l*=r[f]}const i=[];for(let l=0;l<s;l++){const f=z.empty(e.length?e:[1],"float64");i.push(f)}for(let l=0;l<u;l++){let f=o[l];if(f<0||f>=a)throw new Error(`index ${f} is out of bounds for array with size ${a}`);if(n==="C")for(let c=0;c<s;c++){const A=Math.floor(f/y[c]);f=f%y[c],i[c].data[l]=A%r[c]}else for(let c=s-1;c>=0;c--){const A=Math.floor(f/y[c]);f=f%y[c],i[c].data[l]=A%r[c]}}return typeof t=="number"?i.map(l=>{const f=l.iget(0),c=z.empty([],"float64");return c.data[0]=Number(f),c}):i}function _t(t,r,n=!1){const s=t.shape,o=s.length;if(o<2)throw new Error("array must be at least 2-d");let e;if(o===2)e=s[1]+1;else{e=1;for(let i=1;i<o;i++){let l=1;for(let f=i;f<o;f++)l*=s[f];e+=l}}const u=t.size;let a=Math.min(...s);n&&o===2&&(a=Math.max(s[0],s[1]));const y=t.isCContiguous;if(typeof r=="number")if(y){const i=t.data,l=t.offset;if($(t.dtype)){const f=i,c=BigInt(Math.round(r));for(let A=0;A<a;A++){const S=A*e;if(S>=u)break;f[l+S]=c}}else for(let f=0;f<a;f++){const c=f*e;if(c>=u)break;i[l+c]=r}}else for(let i=0;i<a&&i*e<u;i++)t.iset(i*e,r);else{const i=r.size;if(y&&r.isCContiguous){const l=t.data,f=t.offset,c=r.data,A=r.offset;if($(t.dtype)){const S=l,B=c;for(let N=0;N<a;N++){const C=N*e;if(C>=u)break;S[f+C]=B[A+N%i]}}else{const S=l,B=c;for(let N=0;N<a;N++){const C=N*e;if(C>=u)break;S[f+C]=B[A+N%i]}}}else for(let l=0;l<a&&l*e<u;l++)t.iset(l*e,r.iget(l%i))}}function Rt(t,r,n){const s=Array.from(t.shape),o=s.length;if(r<0&&(r+=o),r<0||r>=o)throw new Error(`axis ${r} is out of bounds for array of dimension ${o}`);const e=[];for(let p=0;p<o;p++)p!==r&&e.push(s[p]);if(e.length===0){const p=n(t);if(typeof p=="number"){const d=z.zeros([1],t.dtype);return d.data[0]=p,d}return p}const u=t.dtype;function a(p,d){const m=z.empty([p],u);for(let w=0;w<p;w++)m.iset(w,d(w));return m}const y=p=>p==="int64"||p==="uint64";function i(p,d,m){typeof m=="number"&&y(p.dtype)?p.iset(d,BigInt(Math.round(m))):p.iset(d,m)}function l(p){return typeof p=="number"||typeof p=="object"&&p!==null&&"re"in p&&!("size"in p)}function f(p){if(!l(p))return p.dtype;const d=u;return d==="complex128"||d==="complex64"?d:d==="bool"||d.startsWith("int")?"int64":d.startsWith("uint")?"uint64":d}if(o===2){const[p,d]=s;if(r===0){const m=[];for(let h=0;h<d;h++)m.push(n(a(p,g=>t.get(g,h))));const w=m[0];if(w===void 0)return z.zeros([0],u);const x=f(w);if(l(w)){const h=z.zeros([d],x);for(let g=0;g<d;g++)i(h,g,m[g]);return h}else{const g=[w.size,d],F=z.zeros(g,x);for(let b=0;b<d;b++){const E=m[b];for(let D=0;D<E.size;D++)F.iset(D*d+b,E.iget(D))}return F}}else{const m=[];for(let h=0;h<p;h++)m.push(n(a(d,g=>t.get(h,g))));const w=m[0];if(w===void 0)return z.zeros([0],u);const x=f(w);if(l(w)){const h=z.zeros([p],x);for(let g=0;g<p;g++)i(h,g,m[g]);return h}else{const g=[p,w.size],F=z.zeros(g,x);for(let b=0;b<p;b++){const E=m[b];for(let D=0;D<E.size;D++)F.iset(b*E.size+D,E.iget(D))}return F}}}if(o===1){const p=n(t);if(typeof p=="number"){const d=z.zeros([1],"float64");return d.data[0]=p,d}return p}const c=s[r],A=e.reduce((p,d)=>p*d,1);function S(p){const d=new Array(e.length);let m=p;for(let w=e.length-1;w>=0;w--)d[w]=m%e[w],m=Math.floor(m/e[w]);return d}function B(p,d){const m=[];let w=0;for(let x=0;x<o;x++)m.push(x===r?d:p[w++]);return Number(t.get(...m))}const N=[];for(let p=0;p<A;p++){const d=S(p),m=z.empty([c],"float64"),w=m.data;for(let x=0;x<c;x++)w[x]=B(d,x);N.push(n(m))}const C=N[0];if(C===void 0)return z.zeros([0],"float64");if(l(C)){const p=f(C),d=z.zeros(e,p);for(let m=0;m<A;m++)i(d,m,N[m]);return d}else{const p=C,d=[...e,...Array.from(p.shape)],m=z.zeros(d,p.dtype),w=p.size;for(let x=0;x<A;x++){const h=N[x];for(let g=0;g<w;g++)m.data[x*w+g]=Number(h.iget(g))}return m}}function kt(t,r,n){let s=t;const o=t.shape.length;for(const e of n){let u=e<0?e+o:e;if(u<0||u>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);if(s=r(s,u),s.shape.length<o){const a=Array.from(s.shape);a.splice(u,0,1);const y=_(a);s=new z(s.data,a,y,0,s.dtype)}}return s}function ot(t,r){if(t.isWasmBacked&&r.isWasmBacked){const n=t.data.byteOffset,s=n+t.data.byteLength,o=r.data.byteOffset,e=o+r.data.byteLength;return n<e&&o<s}return t.data.buffer===r.data.buffer}function jt(t,r){return ot(t,r)}let U={divide:"warn",over:"warn",under:"ignore",invalid:"warn"};function nt(){return{...U}}function Ot(t,r,n,s,o){const e=nt();return t!==void 0&&(U.divide=t,U.over=t,U.under=t,U.invalid=t),r!==void 0&&(U.divide=r),n!==void 0&&(U.over=n),s!==void 0&&(U.under=s),o!==void 0&&(U.invalid=o),e}function st(t){return z.fromData(new Int32Array(t),[t.length],"int32")}function at(t,r){let n=0,s=1;for(let o=t.length-1;o>=0;o--)n+=t[o]*s,s*=r[o];return n}function Lt(t,...r){const n=J(r,t.ndim);let s=[],o=0,e=0,u=[],a=[];for(const h of n)typeof h=="number"?(s.push(" "),u.push(h)):h==="newaxis"?(s.push(" "),u.push(h),a.push(":"),e===0&&o++):typeof h=="string"?(s.push(" "),H(h).isIndex?u.push(h):(u.push(h),a.push(":"),e===0&&o++)):Array.isArray(h)?(s.push("Y"),u.push(":"),a.push(st(h)),e++):(s.push("Y"),u.push(":"),a.push(h),e++);t=K(t,...u);let y=[];const i=[],l=[],f=[],c=[];for(let h=0;h<t.ndim;h++){const g=a[h];g instanceof z?(y.push(g),i.push(h),f.push(t.shape[h])):(l.push(h),c.push(t.shape[h]))}t=Y(t,[...i,...l]),y=Z(y);const A=y.length>0?Array.from(y[0].shape):[],S=A.reduce((h,g)=>h*g,1),B=c.reduce((h,g)=>h*g,1),N=[...A,...c],C=q(t.dtype),p=S*B,d=j(t.dtype)?p*2:p,m=new C(d),w=z.fromData(m,N,t.dtype);if(p!==0)for(let h=0;h<S;h++){const g=y.map(E=>E.iget(h));for(let E=0;E<g.length;E++){let D=g[E];if(D<0&&(D=g[E]=f[E]+D),D<0||D>=f[E])throw new Error(`index ${D} is out of bounds for axis with size ${f[E]}`)}const F=at(g,f)*B,b=h*B;if(j(t.dtype))for(let E=0;E<B;E++){const D=t.iget(F+E),v=(b+E)*2;w.data[v]=D.re,w.data[v+1]=D.im}else for(let E=0;E<B;E++)w.data[b+E]=t.iget(F+E)}if(!s.join("").trim().includes(" ")&&A.length>0){const h=A.length,g=c.length,F=[];for(let b=0;b<o;b++)F.push(b+h);for(let b=0;b<h;b++)F.push(b);for(let b=o;b<g;b++)F.push(b+h);return Y(w,F)}else return w}export{Rt as apply_along_axis,kt as apply_over_axes,St as array_equal,Z as broadcast_arrays,G as broadcast_shapes,ht as broadcast_to,xt as choose,Bt as compress,tt as diag_indices,Nt as diag_indices_from,_t as fill_diagonal,nt as geterr,Tt as indices,vt as ix_,$t as mask_indices,ot as may_share_memory,Ct as place,At as put,It as put_along_axis,zt as putmask,Mt as ravel_multi_index,Et as select,Ot as seterr,jt as shares_memory,bt as take,wt as take_along_axis,rt as tril_indices,Ft as tril_indices_from,et as triu_indices,Dt as triu_indices_from,Ut as unravel_index,Lt as vindex};
@@ -1 +1 @@
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};
1
+ import{ArrayStorage as h}from"../storage.js";import{isBigIntDType as C,isComplexDType as M,isIntegerDType as x,getComplexComponentDType as ct,promoteDTypes as E,throwIfComplex as v,throwIfBool as J,isFloatDType as L,mathResultDtype as P,boolArithmeticDtype as yt,hasFloat16 as mt}from"../dtype.js";import{elementwiseBinaryOp as O}from"../internal/compute.js";import{wasmAdd as pt,wasmAddScalar as dt}from"../wasm/add.js";import{wasmSub as gt,wasmSubScalar as At}from"../wasm/sub.js";import{wasmMul as bt,wasmMulScalar as ht}from"../wasm/mul.js";import{wasmDiv as K,wasmDivScalar as Nt}from"../wasm/divide.js";import{wasmNeg as St}from"../wasm/neg.js";import{wasmAbs as Dt}from"../wasm/abs.js";import{wasmSign as Mt}from"../wasm/sign.js";import{wasmMin as tt,wasmMinScalar as H}from"../wasm/min.js";import{wasmMax as et,wasmMaxScalar as W}from"../wasm/max.js";import{wasmClip as It}from"../wasm/clip.js";import{wasmSquare as Ct}from"../wasm/square.js";import{wasmReciprocal as Bt}from"../wasm/reciprocal.js";import{wasmHeavisideScalar as zt,wasmHeaviside as Ft}from"../wasm/heaviside.js";import{wasmLdexpScalar as wt}from"../wasm/ldexp.js";import{wasmFrexp as vt}from"../wasm/frexp.js";import{wasmGcdScalar as Tt,wasmGcd as Rt}from"../wasm/gcd.js";import{wasmDivmodScalar as Ut}from"../wasm/divmod.js";import{getComplexAt as T,setComplexAt as R,complexGreater as X,clipComplex as Vt}from"./complex.js";function q(t,e){return t.isCContiguous&&e.isCContiguous&&t.shape.length===e.shape.length&&t.shape.every((i,m)=>i===e.shape[m])}function $(t){const e=h.empty(Array.from(t.shape),"int8"),i=t.data,m=e.data,p=t.offset;for(let c=0;c<t.size;c++)m[c]=i[p+c];return e}function G(t){const e=P("bool"),i=h.empty(Array.from(t.shape),e),m=t.data,p=i.data,c=t.offset;for(let y=0;y<t.size;y++)p[y]=m[c+y];return i}function j(t,e,i,m=!1){const p=i==="max",c=typeof e=="number"?"float64":e.dtype,y=E(t.dtype,c),l=t.size,f=Array.from(t.shape),a=h.empty(f,y),o=a.data,r=M(t.dtype),s=t.data,n=t.offset;if(typeof e=="number"){const A=e,b=0,N=isNaN(A);for(let z=0;z<l;z++){let B,w;r?[B,w]=T(s,n+z):(B=Number(s[n+z]),w=0);const I=isNaN(B)||isNaN(w);let S,D;if(m)if(I&&N)S=NaN,D=NaN;else if(I)S=A,D=b;else if(N)S=B,D=w;else{const F=X(B,w,A,b);(p?F:!F)?(S=B,D=w):(S=A,D=b)}else if(I||N)S=NaN,D=NaN;else{const F=X(B,w,A,b);(p?F:!F)?(S=B,D=w):(S=A,D=b)}R(o,z,S,D)}return a}const u=M(e.dtype),d=e.data,g=e.offset;for(let A=0;A<l;A++){let b,N;r?[b,N]=T(s,n+A):(b=Number(s[n+A]),N=0);let z,B;u?[z,B]=T(d,g+A):(z=Number(d[g+A]),B=0);const w=isNaN(b)||isNaN(N),I=isNaN(z)||isNaN(B);let S,D;if(m)if(w&&I)S=NaN,D=NaN;else if(w)S=z,D=B;else if(I)S=b,D=N;else{const F=X(b,N,z,B);(p?F:!F)?(S=b,D=N):(S=z,D=B)}else if(w||I)S=NaN,D=NaN;else{const F=X(b,N,z,B);(p?F:!F)?(S=b,D=N):(S=z,D=B)}R(o,A,S,D)}return a}function me(t,e){if(typeof e=="number")return rt(t,e);if(e.size===1&&!M(e.dtype)&&t.dtype===e.dtype){const i=Number(e.iget(0));return rt(t,i)}if(q(t,e)){const i=pt(t,e);return i||Ot(t,e)}return O(t,e,(i,m)=>i+m,"add")}function Ot(t,e){const i=E(t.dtype,e.dtype),m=h.empty(Array.from(t.shape),i),p=t.size,c=t.data,y=e.data,l=m.data,f=t.offset,a=e.offset;if(M(i)){const o=l,r=M(t.dtype),s=M(e.dtype);for(let n=0;n<p;n++){const[u,d]=r?T(c,f+n):[Number(c[f+n]),0],[g,A]=s?T(y,a+n):[Number(y[a+n]),0];R(o,n,u+g,d+A)}return m}if(C(i)){const o=l;if(!C(t.dtype)||!C(e.dtype))for(let s=0;s<p;s++){const n=typeof c[f+s]=="bigint"?c[f+s]:BigInt(Math.round(Number(c[f+s]))),u=typeof y[a+s]=="bigint"?y[a+s]:BigInt(Math.round(Number(y[a+s])));o[s]=n+u}else{const s=c,n=y;for(let u=0;u<p;u++)o[u]=s[f+u]+n[a+u]}}else if(i==="bool")for(let o=0;o<p;o++)l[o]=c[f+o]+y[a+o]?1:0;else if(C(t.dtype)||C(e.dtype))for(let r=0;r<p;r++){const s=typeof c[f+r]=="bigint"?Number(c[f+r]):c[f+r],n=typeof y[a+r]=="bigint"?Number(y[a+r]):y[a+r];l[r]=s+n}else if(f===0&&a===0)for(let r=0;r<p;r++)l[r]=c[r]+y[r];else for(let r=0;r<p;r++)l[r]=c[f+r]+y[a+r];return m}function pe(t,e){if(t.dtype==="bool"&&(typeof e!="number"&&e.dtype==="bool"))throw new TypeError("ufunc 'subtract' not supported for boolean dtype. The `-` operator is not supported for booleans, use `bitwise_xor` instead.");if(typeof e=="number")return ot(t,e);if(e.size===1&&!M(e.dtype)&&t.dtype===e.dtype){const i=Number(e.iget(0));return ot(t,i)}if(q(t,e)){const i=gt(t,e);return i||Et(t,e)}return O(t,e,(i,m)=>i-m,"subtract")}function Et(t,e){const i=E(t.dtype,e.dtype),m=h.empty(Array.from(t.shape),i),p=t.size,c=t.data,y=e.data,l=m.data,f=t.offset,a=e.offset;if(M(i)){const o=l,r=M(t.dtype),s=M(e.dtype);for(let n=0;n<p;n++){const[u,d]=r?T(c,f+n):[Number(c[f+n]),0],[g,A]=s?T(y,a+n):[Number(y[a+n]),0];R(o,n,u-g,d-A)}return m}if(C(i)){const o=l;if(!C(t.dtype)||!C(e.dtype))for(let s=0;s<p;s++){const n=typeof c[f+s]=="bigint"?c[f+s]:BigInt(Math.round(Number(c[f+s]))),u=typeof y[a+s]=="bigint"?y[a+s]:BigInt(Math.round(Number(y[a+s])));o[s]=n-u}else{const s=c,n=y;for(let u=0;u<p;u++)o[u]=s[f+u]-n[a+u]}}else if(C(t.dtype)||C(e.dtype))for(let r=0;r<p;r++){const s=typeof c[f+r]=="bigint"?Number(c[f+r]):c[f+r],n=typeof y[a+r]=="bigint"?Number(y[a+r]):y[a+r];l[r]=s-n}else if(f===0&&a===0)for(let r=0;r<p;r++)l[r]=c[r]-y[r];else for(let r=0;r<p;r++)l[r]=c[f+r]-y[a+r];return m}function de(t,e){if(typeof e=="number")return st(t,e);if(e.size===1&&!M(e.dtype)&&t.dtype===e.dtype){const i=Number(e.iget(0));return st(t,i)}if(q(t,e)){const i=bt(t,e);return i||qt(t,e)}return O(t,e,(i,m)=>i*m,"multiply")}function qt(t,e){const i=E(t.dtype,e.dtype),m=h.empty(Array.from(t.shape),i),p=t.size,c=t.data,y=e.data,l=m.data,f=t.offset,a=e.offset;if(M(i)){const o=l,r=M(t.dtype),s=M(e.dtype);for(let n=0;n<p;n++){const[u,d]=r?T(c,f+n):[Number(c[f+n]),0],[g,A]=s?T(y,a+n):[Number(y[a+n]),0],b=u*g-d*A,N=u*A+d*g;R(o,n,b,N)}return m}if(C(i)){const o=l;if(!C(t.dtype)||!C(e.dtype))for(let s=0;s<p;s++){const n=typeof c[f+s]=="bigint"?c[f+s]:BigInt(Math.round(Number(c[f+s]))),u=typeof y[a+s]=="bigint"?y[a+s]:BigInt(Math.round(Number(y[a+s])));o[s]=n*u}else{const s=c,n=y;for(let u=0;u<p;u++)o[u]=s[f+u]*n[a+u]}}else if(C(t.dtype)||C(e.dtype))for(let r=0;r<p;r++){const s=typeof c[f+r]=="bigint"?Number(c[f+r]):c[f+r],n=typeof y[a+r]=="bigint"?Number(y[a+r]):y[a+r];l[r]=s*n}else if(f===0&&a===0)for(let r=0;r<p;r++)l[r]=c[r]*y[r];else for(let r=0;r<p;r++)l[r]=c[f+r]*y[a+r];return m}function ge(t,e){if(typeof e=="number")return nt(t,e);if(e.size===1&&!M(e.dtype)&&!M(t.dtype)&&t.dtype===e.dtype){const a=Number(e.iget(0));return nt(t,a)}const i=M(t.dtype),m=M(e.dtype);if(i||m){const a=E(t.dtype,e.dtype);if(i&&m&&t.dtype===e.dtype&&q(t,e)){const A=K(t,e);if(A)return A}const o=h.empty(Array.from(t.shape),a),r=o.data,s=t.size,n=t.data,u=e.data,d=t.offset,g=e.offset;for(let A=0;A<s;A++){const[b,N]=i?T(n,d+A):[Number(n[d+A]),0],[z,B]=m?T(u,g+A):[Number(u[g+A]),0],w=z*z+B*B,I=(b*z+N*B)/w,S=(N*z-b*B)/w;R(r,A,I,S)}return o}if(t.dtype===e.dtype&&q(t,e)){const a=K(t,e);if(a)return a}const p=E(t.dtype,e.dtype),c=p==="float16";let y;p==="float32"||p==="float16"?y="float32":y="float64";const l=t.dtype===y?t:k(t,y),f=e.dtype===y?e:k(e,y);try{let a;if(q(l,f)?a=K(l,f)??O(l,f,(r,s)=>r/s,"divide"):a=O(l,f,(o,r)=>o/r,"divide"),c&&mt){const o=h.empty(Array.from(a.shape),"float16");return o.data.set(a.data),a.dispose(),o}return a}finally{l!==t&&l.dispose(),f!==e&&f.dispose()}}function k(t,e){const i=h.empty(Array.from(t.shape),e),m=t.size,p=i.data;if(t.isCContiguous){const c=t.data,y=t.offset;for(let l=0;l<m;l++)p[l]=Number(c[y+l])}else for(let c=0;c<m;c++)p[c]=Number(t.iget(c));return i}function rt(t,e){const i=dt(t,e);if(i)return i;const m=t.dtype,p=Array.from(t.shape),c=t.data,y=t.size,l=t.offset,f=t.isCContiguous,a=h.empty(p,m),o=a.data;if(M(m)){const r=c,s=o;if(f)for(let n=0;n<y;n++){const[u,d]=T(r,l+n);R(s,n,u+e,d)}else for(let n=0;n<y;n++){const u=t.iget(n),d=u.re??Number(u),g=u.im??0;R(s,n,d+e,g)}}else if(C(m)){const r=o,s=BigInt(Math.round(e));if(f){const n=c;for(let u=0;u<y;u++)r[u]=n[l+u]+s}else for(let n=0;n<y;n++)r[n]=t.iget(n)+s}else if(f)if(l===0)for(let r=0;r<y;r++)o[r]=Number(c[r])+e;else for(let r=0;r<y;r++)o[r]=Number(c[l+r])+e;else for(let r=0;r<y;r++)o[r]=Number(t.iget(r))+e;return a}function ot(t,e){const i=At(t,e);if(i)return i;const m=t.dtype,p=Array.from(t.shape),c=t.data,y=t.size,l=t.offset,f=t.isCContiguous,a=h.empty(p,m),o=a.data;if(M(m)){const r=c,s=o;if(f)for(let n=0;n<y;n++){const[u,d]=T(r,l+n);R(s,n,u-e,d)}else for(let n=0;n<y;n++){const u=t.iget(n),d=u.re??Number(u),g=u.im??0;R(s,n,d-e,g)}}else if(C(m)){const r=o,s=BigInt(Math.round(e));if(f){const n=c;for(let u=0;u<y;u++)r[u]=n[l+u]-s}else for(let n=0;n<y;n++)r[n]=t.iget(n)-s}else if(f)for(let r=0;r<y;r++)o[r]=Number(c[l+r])-e;else for(let r=0;r<y;r++)o[r]=Number(t.iget(r))-e;return a}function st(t,e){const i=ht(t,e);if(i)return i;const m=t.dtype,p=Array.from(t.shape),c=t.data,y=t.size,l=t.offset,f=t.isCContiguous,a=h.empty(p,m),o=a.data;if(M(m)){const r=c,s=o;if(f)for(let n=0;n<y;n++){const[u,d]=T(r,l+n);R(s,n,u*e,d*e)}else for(let n=0;n<y;n++){const u=t.iget(n),d=u.re??Number(u),g=u.im??0;R(s,n,d*e,g*e)}}else if(C(m)){const r=o,s=BigInt(Math.round(e));if(f){const n=c;for(let u=0;u<y;u++)r[u]=n[l+u]*s}else for(let n=0;n<y;n++)r[n]=t.iget(n)*s}else if(f)if(l===0)for(let r=0;r<y;r++)o[r]=Number(c[r])*e;else for(let r=0;r<y;r++)o[r]=Number(c[l+r])*e;else for(let r=0;r<y;r++)o[r]=Number(t.iget(r))*e;return a}function nt(t,e){const i=t.dtype;if(M(i)){const y=Array.from(t.shape),l=t.data,f=t.size,a=t.offset,o=t.isCContiguous,r=h.empty(y,i),s=r.data;if(o){const n=l;for(let u=0;u<f;u++){const[d,g]=T(n,a+u);R(s,u,d/e,g/e)}}else for(let n=0;n<f;n++){const u=t.iget(n),d=u.re??Number(u),g=u.im??0;R(s,n,d/e,g/e)}return r}const m=Nt(t,e);if(m)return m;const c=i==="float16"||i==="float32"||i==="float64"?t:k(t,"float64");try{const y=Array.from(c.shape),l=c.size,f=h.empty(y,c.dtype),a=f.data,o=c.data,r=c.offset;if(c.isCContiguous)for(let s=0;s<l;s++)a[s]=o[r+s]/e;else for(let s=0;s<l;s++)a[s]=Number(c.iget(s))/e;return f}finally{c!==t&&c.dispose()}}function Ae(t){const e=Dt(t);if(e)return e;const i=t.dtype,m=Array.from(t.shape),p=t.data,c=t.size,y=t.offset,l=t.isCContiguous;if(M(i)){const o=ct(i),r=h.empty(m,o),s=r.data;if(l){const n=p;for(let u=0;u<c;u++){const d=n[(y+u)*2],g=n[(y+u)*2+1];s[u]=Math.sqrt(d*d+g*g)}}else for(let n=0;n<c;n++){const u=t.iget(n),d=u.re??Number(u),g=u.im??0;s[n]=Math.sqrt(d*d+g*g)}return r}const f=h.empty(m,i),a=f.data;if(C(i)){const o=a;if(l){const r=p;for(let s=0;s<c;s++){const n=r[y+s];o[s]=n<0n?-n:n}}else for(let r=0;r<c;r++){const s=t.iget(r);o[r]=s<0n?-s:s}}else if(l)if(y===0)for(let o=0;o<c;o++)a[o]=Math.abs(Number(p[o]));else for(let o=0;o<c;o++)a[o]=Math.abs(Number(p[y+o]));else for(let o=0;o<c;o++)a[o]=Math.abs(Number(t.iget(o)));return f}function be(t){J(t.dtype,"negative","The `-` operator is not supported for booleans, use `~` instead.");const e=St(t);if(e)return e;const i=t.dtype,m=Array.from(t.shape),p=t.data,c=t.size,y=t.offset,l=t.isCContiguous,f=h.empty(m,i),a=f.data;if(M(i)){const o=a;if(l){const r=p;for(let s=0;s<c;s++){const[n,u]=T(r,y+s);R(o,s,-n,-u)}}else for(let r=0;r<c;r++){const s=t.iget(r),n=s.re??Number(s),u=s.im??0;R(o,r,-n,-u)}}else if(C(i)){const o=a;if(l){const r=p;for(let s=0;s<c;s++)o[s]=-r[y+s]}else for(let r=0;r<c;r++)o[r]=-t.iget(r)}else if(l)if(y===0)for(let o=0;o<c;o++)a[o]=-Number(p[o]);else for(let o=0;o<c;o++)a[o]=-Number(p[y+o]);else for(let o=0;o<c;o++)a[o]=-Number(t.iget(o));return f}function he(t){if(M(t.dtype)){const o=Array.from(t.shape),r=t.size,s=h.empty(o,t.dtype),n=s.data;if(t.isCContiguous){const u=t.data,d=t.offset;for(let g=0;g<r;g++){const A=u[(d+g)*2],b=u[(d+g)*2+1],N=Math.sqrt(A*A+b*b);N===0?(n[g*2]=0,n[g*2+1]=0):(n[g*2]=A/N,n[g*2+1]=b/N)}}else for(let u=0;u<r;u++){const d=t.iget(u),g=Math.sqrt(d.re*d.re+d.im*d.im);g===0?(n[u*2]=0,n[u*2+1]=0):(n[u*2]=d.re/g,n[u*2+1]=d.im/g)}return s}J(t.dtype,"sign","Sign is not defined for boolean dtype.");const e=Mt(t);if(e)return e;const i=t.dtype,m=Array.from(t.shape),p=t.data,c=t.size,y=t.offset,l=t.isCContiguous,f=h.empty(m,i),a=f.data;if(C(i)){const o=a;if(l){const r=p;for(let s=0;s<c;s++){const n=r[y+s];o[s]=n>0n?1n:n<0n?-1n:0n}}else for(let r=0;r<c;r++){const s=t.iget(r);o[r]=s>0n?1n:s<0n?-1n:0n}}else if(l)for(let o=0;o<c;o++){const r=Number(p[y+o]);a[o]=r>0?1:r<0?-1:0}else for(let o=0;o<c;o++){const r=Number(t.iget(o));a[o]=r>0?1:r<0?-1:0}return f}function Q(t,e){return v(t.dtype,"mod","Modulo is not defined for complex numbers."),typeof e!="number"&&v(e.dtype,"mod","Modulo is not defined for complex numbers."),t.dtype==="bool"&&(typeof e=="number"||e.dtype==="bool")?Q($(t),typeof e=="number"?e:$(e)):typeof e=="number"?$t(t,e):O(t,e,(i,m)=>(i%m+m)%m,"mod")}function $t(t,e){const i=t.dtype,m=Array.from(t.shape),p=t.data,c=t.size,y=t.offset,l=t.isCContiguous,f=h.empty(m,i),a=f.data;if(C(i)){const o=a,r=BigInt(Math.round(e));if(l){const s=p;for(let n=0;n<c;n++){const u=s[y+n];o[n]=(u%r+r)%r}}else for(let s=0;s<c;s++){const n=t.iget(s);o[s]=(n%r+r)%r}}else if(l)for(let o=0;o<c;o++){const r=Number(p[y+o]);a[o]=(r%e+e)%e}else for(let o=0;o<c;o++){const r=Number(t.iget(o));a[o]=(r%e+e)%e}return f}function at(t,e){return v(t.dtype,"floor_divide","Floor division is not defined for complex numbers."),typeof e!="number"&&v(e.dtype,"floor_divide","Floor division is not defined for complex numbers."),t.dtype==="bool"&&(typeof e=="number"||e.dtype==="bool")?at($(t),typeof e=="number"?e:$(e)):typeof e=="number"?Pt(t,e):O(t,e,(i,m)=>Math.floor(i/m),"floor_divide")}function Pt(t,e){const i=t.dtype,m=Array.from(t.shape),p=t.data,c=t.size,y=t.offset,l=t.isCContiguous,f=h.empty(m,i),a=f.data;if(C(i)){const o=a,r=BigInt(Math.round(e));if(l){const s=p;for(let n=0;n<c;n++)o[n]=s[y+n]/r}else for(let s=0;s<c;s++)o[s]=t.iget(s)/r}else if(l)for(let o=0;o<c;o++)a[o]=Math.floor(Number(p[y+o])/e);else for(let o=0;o<c;o++)a[o]=Math.floor(Number(t.iget(o))/e);return f}function Ne(t){J(t.dtype,"positive","The `+` operator is not supported for booleans.");const e=t.dtype,i=Array.from(t.shape),m=t.data,p=t.size,c=t.offset,y=t.isCContiguous,l=h.empty(i,e),f=l.data;if(M(e)){const a=f;if(y){const o=m;a.set(o.subarray(c*2,(c+p)*2))}else for(let o=0;o<p;o++){const r=t.iget(o);a[o*2]=r.re??Number(r),a[o*2+1]=r.im??0}}else if(y)f.set(m.subarray(c,c+p));else for(let a=0;a<p;a++)f[a]=t.iget(a);return l}function Se(t){if(t.dtype==="bool"){const r=Array.from(t.shape),s=h.empty(r,"int8"),n=s.data,u=t.data,d=t.offset;for(let g=0;g<t.size;g++){const A=t.isCContiguous?u[d+g]:Number(t.iget(g));n[g]=A!==0?1/A|0:-1}return s}const e=Bt(t);if(e)return e;const i=t.dtype,m=Array.from(t.shape),p=t.data,c=t.size,y=t.offset,l=t.isCContiguous;if(M(i)){const r=h.empty(m,i),s=r.data;if(l){const n=p;for(let u=0;u<c;u++){const d=n[(y+u)*2],g=n[(y+u)*2+1],A=d*d+g*g;s[u*2]=d/A,s[u*2+1]=-g/A}}else for(let n=0;n<c;n++){const u=t.iget(n),d=u.re??Number(u),g=u.im??0,A=d*d+g*g;s[n*2]=d/A,s[n*2+1]=-g/A}return r}if(x(i)){const r=h.empty(m,i),s=r.data;if(C(i)){const n=s;for(let u=0;u<c;u++){const d=l?p[y+u]:t.iget(u);n[u]=d!==0n?1n/d:-1n}}else for(let n=0;n<c;n++){const u=l?p[y+n]:Number(t.iget(n));s[n]=u!==0?Math.trunc(1/u):0}return r}const a=h.empty(m,i),o=a.data;if(l)if(y===0)for(let r=0;r<c;r++)o[r]=1/Number(p[r]);else for(let r=0;r<c;r++)o[r]=1/Number(p[y+r]);else for(let r=0;r<c;r++)o[r]=1/Number(t.iget(r));return a}function De(t){const e=t.dtype;v(e,"cbrt","cbrt is not supported for complex numbers.");const i=Array.from(t.shape),m=t.data,p=t.size,c=t.offset,y=P(e),l=h.empty(i,y),f=l.data;if(t.isCContiguous)for(let a=0;a<p;a++)f[a]=Math.cbrt(Number(m[c+a]));else for(let a=0;a<p;a++)f[a]=Math.cbrt(Number(t.iget(a)));return l}function Me(t){const e=t.dtype;v(e,"fabs","fabs is only for real numbers. Use absolute() for complex.");const i=Array.from(t.shape),m=t.data,p=t.size,c=t.offset,y=P(e),l=h.empty(i,y),f=l.data;if(t.isCContiguous)if(c===0)for(let a=0;a<p;a++)f[a]=Math.abs(Number(m[a]));else for(let a=0;a<p;a++)f[a]=Math.abs(Number(m[c+a]));else for(let a=0;a<p;a++)f[a]=Math.abs(Number(t.iget(a)));return l}function Ie(t,e){if(typeof e=="number"){const p=Ut(t,e);if(p)return p}const i=at(t,e),m=Q(t,e);return[i,m]}function Ce(t){const e=Ct(t);if(e)return e;const i=t.dtype,m=Array.from(t.shape),p=t.data,c=t.size,y=yt(i),l=h.empty(m,y),f=l.data;if(M(i)){const a=p,o=f;for(let r=0;r<c;r++){const s=a[r*2],n=a[r*2+1];o[r*2]=s*s-n*n,o[r*2+1]=2*s*n}}else if(C(i)){const a=p,o=f;for(let r=0;r<c;r++)o[r]=a[r]*a[r]}else for(let a=0;a<c;a++){const o=Number(p[a]);f[a]=o*o}return l}function Be(t,e){return Q(t,e)}function Y(t,e){if(t.dtype==="bool")return Y(G(t),typeof e=="number"?e:e.dtype==="bool"?G(e):e);if(typeof e!="number"&&e.dtype==="bool")return Y(t,G(e));v(t.dtype,"heaviside","Heaviside step function is not defined for complex numbers."),typeof e!="number"&&v(e.dtype,"heaviside","Heaviside step function is not defined for complex numbers.");const i=typeof e=="number"?t.dtype:e.dtype,m=Array.from(t.shape),p=t.size,c=E(P(t.dtype),P(i)),y=c==="float16"?"float32":c,l=t.dtype===y?t:k(t,y);if(typeof e!="number"&&e.size===1)return l!==t&&l.dispose(),Y(t,Number(e.iget(0)));try{if(typeof e=="number"){const f=zt(l,e,y);if(f){if(c==="float16"){const r=h.empty(Array.from(f.shape),"float16");return r.data.set(f.data),f.dispose(),r}return f}const a=h.empty(m,c),o=a.data;if(l.isCContiguous){const r=l.data,s=l.offset;for(let n=0;n<p;n++){const u=r[s+n];o[n]=u<0?0:u===0?e:1}}else for(let r=0;r<p;r++){const s=Number(t.iget(r));o[r]=s<0?0:s===0?e:1}return a}else{const f=e.shape,a=e.dtype===y?e:k(e,y);try{if(m.every((o,r)=>o===f[r])){const o=Ft(l,a,y);if(o){if(c==="float16"){const n=h.empty(Array.from(o.shape),"float16");return n.data.set(o.data),o.dispose(),n}return o}const r=h.empty(m,c),s=r.data;if(l.isCContiguous&&a.isCContiguous){const n=l.data,u=l.offset,d=a.data,g=a.offset;for(let A=0;A<p;A++){const b=n[u+A];s[A]=b<0?0:b===0?d[g+A]:1}}else for(let n=0;n<p;n++){const u=Number(t.iget(n));s[n]=u<0?0:u===0?Number(e.iget(n)):1}return r}else{const o=h.empty(m,c),r=o.data;for(let s=0;s<p;s++){const n=Number(t.iget(s)),u=s%e.size;r[s]=n<0?0:n===0?Number(e.iget(u)):1}return o}}finally{a!==e&&a.dispose()}}}finally{l!==t&&l.dispose()}}function Lt(t,e){const i=t.dtype,m=typeof e!="number"&&M(e.dtype);if(!M(i)&&m){const l=h.empty(Array.from(t.shape),"complex128"),f=l.data;for(let a=0;a<t.size;a++)f[a*2]=Number(t.iget(a)),f[a*2+1]=0;return Lt(l,e)}if(M(i)){const l=t.size,f=h.empty(Array.from(t.shape),"complex128"),a=f.data;if(typeof e=="number")if(t.isCContiguous){const o=t.data,r=t.offset;for(let s=0;s<l;s++){const n=o[(r+s)*2],u=o[(r+s)*2+1],d=Math.hypot(n,u),g=Math.atan2(u,n),A=Math.pow(d,e),b=g*e;a[s*2]=A*Math.cos(b),a[s*2+1]=A*Math.sin(b)}}else for(let o=0;o<l;o++){const r=t.iget(o),s=Math.hypot(r.re,r.im),n=Math.atan2(r.im,r.re),u=Math.pow(s,e),d=n*e;a[o*2]=u*Math.cos(d),a[o*2+1]=u*Math.sin(d)}else{const o=M(e.dtype);if(t.isCContiguous&&e.isCContiguous){const r=t.data,s=t.offset,n=e.data,u=e.offset;for(let d=0;d<l;d++){const g=r[(s+d)*2],A=r[(s+d)*2+1];let b,N;if(o){const U=n;b=U[(u+d)*2],N=U[(u+d)*2+1]}else b=Number(n[u+d]),N=0;const z=Math.hypot(g,A),B=Math.atan2(A,g),w=Math.log(z),I=B,S=b*w-N*I,D=b*I+N*w,F=Math.exp(S);a[d*2]=F*Math.cos(D),a[d*2+1]=F*Math.sin(D)}}else for(let r=0;r<l;r++){const s=t.iget(r);let n,u;if(o){const w=e.iget(r);n=w.re,u=w.im}else n=Number(e.iget(r)),u=0;const d=Math.hypot(s.re,s.im),g=Math.atan2(s.im,s.re),A=Math.log(d),b=g,N=n*A-u*b,z=n*b+u*A,B=Math.exp(N);a[r*2]=B*Math.cos(z),a[r*2+1]=B*Math.sin(z)}}return f}if(typeof e=="number"){const l=h.empty(Array.from(t.shape),"float64"),f=l.data,a=t.size;if(t.isCContiguous){const o=t.data,r=t.offset;for(let s=0;s<a;s++)f[s]=Math.pow(Number(o[r+s]),e)}else for(let o=0;o<a;o++)f[o]=Math.pow(Number(t.iget(o)),e);return l}const p=h.empty(Array.from(t.shape),"float64"),c=p.data,y=t.size;if(t.isCContiguous&&e.isCContiguous){const l=t.data,f=t.offset,a=e.data,o=e.offset;for(let r=0;r<y;r++)c[r]=Math.pow(Number(l[f+r]),Number(a[o+r]))}else for(let l=0;l<y;l++)c[l]=Math.pow(Number(t.iget(l)),Number(e.iget(l)));return p}function it(t,e){if(v(t.dtype,"fmod","fmod is not defined for complex numbers."),typeof e!="number"&&v(e.dtype,"fmod","fmod is not defined for complex numbers."),t.dtype==="bool")return it($(t),typeof e=="number"?e:e.dtype==="bool"?$(e):e);if(typeof e!="number"&&e.dtype==="bool")return it(t,$(e));if(typeof e=="number"){const i=t.copy(),m=i.data,p=t.size;for(let c=0;c<p;c++){const y=Number(m[c]);m[c]=y-Math.trunc(y/e)*e}return i}return O(t,e,(i,m)=>i-Math.trunc(i/m)*m,"fmod")}function kt(t){if(v(t.dtype,"frexp","frexp is not defined for complex numbers."),t.dtype==="bool"){const f=G(t),[a,o]=kt(f);return f.dispose(),[a,o]}const e=vt(t);if(e)return e;const i=P(t.dtype),m=h.empty(Array.from(t.shape),i),p=h.empty(Array.from(t.shape),"int32"),c=m.data,y=p.data,l=t.size;if(t.isCContiguous){const f=t.data,a=t.offset;for(let o=0;o<l;o++){const r=Number(f[a+o]);if(r===0||!isFinite(r))c[o]=r,y[o]=0;else{const s=Math.floor(Math.log2(Math.abs(r)))+1;c[o]=r/Math.pow(2,s),y[o]=s}}}else for(let f=0;f<l;f++){const a=Number(t.iget(f));if(a===0||!isFinite(a))c[f]=a,y[f]=0;else{const o=Math.floor(Math.log2(Math.abs(a)))+1;c[f]=a/Math.pow(2,o),y[f]=o}}return[m,p]}function ft(t,e){if(v(t.dtype,"gcd","GCD is only defined for integers."),L(t.dtype))throw new TypeError(`ufunc 'gcd' not supported for float dtype '${t.dtype}'. GCD is only defined for integer dtypes.`);if(typeof e!="number"){if(v(e.dtype,"gcd","GCD is only defined for integers."),L(e.dtype))throw new TypeError(`ufunc 'gcd' not supported for float dtype '${e.dtype}'. GCD is only defined for integer dtypes.`);if(t.dtype==="bool"&&e.dtype==="bool")throw new TypeError("ufunc 'gcd' not supported for boolean dtype.")}if(typeof e!="number"&&L(E(t.dtype,e.dtype)))throw new TypeError(`ufunc 'gcd' not supported for mixed types '${t.dtype}' and '${e.dtype}'.`);if(t.dtype==="bool"&&(typeof e=="number"||e.dtype==="bool"))return ft($(t),typeof e=="number"?e:$(e));const i=(l,f)=>{for(l=Math.abs(Math.trunc(l)),f=Math.abs(Math.trunc(f));f!==0;){const a=f;f=l%f,l=a}return l},m=typeof e=="number"?t.dtype:E(t.dtype,e.dtype);if(typeof e=="number"){const l=Tt(t,e);if(l)return l;const f=h.empty(Array.from(t.shape),m),a=f.data,o=t.size,r=Math.abs(Math.trunc(e));if(t.isCContiguous){const s=t.data,n=t.offset;for(let u=0;u<o;u++)a[u]=i(Number(s[n+u]),r)}else for(let s=0;s<o;s++)a[s]=i(Number(t.iget(s)),r);return f}if(typeof e!="number"&&e.size===1)return ft(t,Number(e.iget(0)));if(typeof e!="number"&&q(t,e)){const l=Rt(t,e);if(l)return l}const p=h.empty(Array.from(t.shape),m),c=p.data,y=t.size;if(C(m)){const l=(o,r)=>{for(o=o<0n?-o:o,r=r<0n?-r:r;r!==0n;){const s=r;r=o%r,o=s}return o},f=C(t.dtype),a=C(e.dtype);for(let o=0;o<y;o++){const r=t.iget(o),s=e.iget(o),n=f?r:BigInt(Math.round(Number(r))),u=a?s:BigInt(Math.round(Number(s)));c[o]=l(n,u)}}else for(let l=0;l<y;l++)c[l]=i(Number(t.iget(l)),Number(e.iget(l)));return p}function ut(t,e){if(v(t.dtype,"lcm","LCM is only defined for integers."),L(t.dtype))throw new TypeError(`ufunc 'lcm' not supported for float dtype '${t.dtype}'. LCM is only defined for integer dtypes.`);if(v(t.dtype,"lcm","LCM is only defined for integers."),typeof e!="number"){if(v(e.dtype,"lcm","LCM is only defined for integers."),L(e.dtype))throw new TypeError(`ufunc 'lcm' not supported for float dtype '${e.dtype}'. LCM is only defined for integer dtypes.`);if(t.dtype==="bool"&&e.dtype==="bool")throw new TypeError("ufunc 'lcm' not supported for boolean dtype.")}if(typeof e!="number"&&L(E(t.dtype,e.dtype)))throw new TypeError(`ufunc 'lcm' not supported for mixed types '${t.dtype}' and '${e.dtype}'.`);if(t.dtype==="bool"&&(typeof e=="number"||e.dtype==="bool"))return ut($(t),typeof e=="number"?e:$(e));const i=(f,a)=>{for(f=Math.abs(Math.trunc(f)),a=Math.abs(Math.trunc(a));a!==0;){const o=a;a=f%a,f=o}return f},m=(f,a)=>(f=Math.abs(Math.trunc(f)),a=Math.abs(Math.trunc(a)),f===0||a===0?0:f*a/i(f,a)),p=typeof e=="number"?t.dtype:E(t.dtype,e.dtype);if(typeof e=="number"){const f=h.empty(Array.from(t.shape),p),a=f.data,o=t.size,r=Math.abs(Math.trunc(e));if(t.isCContiguous){const s=t.data,n=t.offset;for(let u=0;u<o;u++)a[u]=m(Number(s[n+u]),r)}else for(let s=0;s<o;s++)a[s]=m(Number(t.iget(s)),r);return f}if(e.size===1)return ut(t,Number(e.iget(0)));const c=h.empty(Array.from(t.shape),p),y=c.data,l=t.size;if(C(p)){const f=(s,n)=>{for(s=s<0n?-s:s,n=n<0n?-n:n;n!==0n;){const u=n;n=s%n,s=u}return s},a=(s,n)=>(s=s<0n?-s:s,n=n<0n?-n:n,s===0n||n===0n?0n:s*n/f(s,n)),o=C(t.dtype),r=C(e.dtype);for(let s=0;s<l;s++){const n=t.iget(s),u=e.iget(s),d=o?n:BigInt(Math.round(Number(n))),g=r?u:BigInt(Math.round(Number(u)));y[s]=a(d,g)}}else if(t.isCContiguous&&e.isCContiguous){const f=t.data,a=t.offset,o=e.data,r=e.offset;for(let s=0;s<l;s++)y[s]=m(Number(f[a+s]),Number(o[r+s]))}else for(let f=0;f<l;f++)y[f]=m(Number(t.iget(f)),Number(e.iget(f)));return c}function lt(t,e){if(v(t.dtype,"ldexp","ldexp is not defined for complex numbers."),t.dtype==="bool"){const y=G(t),l=lt(y,e);return y.dispose(),l}if(typeof e!="number"&&(v(e.dtype,"ldexp","ldexp is not defined for complex numbers."),e.size===1))return lt(t,Number(e.iget(0)));if(typeof e=="number"){const y=P(t.dtype),l=t.dtype===y||y==="float16"?t:k(t,y);try{const f=wt(l,e);if(f)return f;const a=h.empty(Array.from(t.shape),y),o=a.data,r=t.size,s=Math.pow(2,e);if(t.isCContiguous){const n=t.data,u=t.offset;for(let d=0;d<r;d++)o[d]=Number(n[u+d])*s}else for(let n=0;n<r;n++)o[n]=Number(t.iget(n))*s;return a}finally{l!==t&&l.dispose()}}const i=P(t.dtype),m=h.empty(Array.from(t.shape),i),p=m.data,c=t.size;if(t.isCContiguous&&e.isCContiguous){const y=t.data,l=t.offset,f=e.data,a=e.offset;for(let o=0;o<c;o++)p[o]=Number(y[l+o])*Math.pow(2,Number(f[a+o]))}else for(let y=0;y<c;y++)p[y]=Number(t.iget(y))*Math.pow(2,Number(e.iget(y)));return m}function ze(t){v(t.dtype,"modf","modf is not defined for complex numbers.");const e=P(t.dtype),i=h.empty(Array.from(t.shape),e),m=h.empty(Array.from(t.shape),e),p=i.data,c=m.data,y=t.size;for(let l=0;l<y;l++){const f=Number(t.iget(l)),a=Math.trunc(f);c[l]=a,p[l]=f-a}return[i,m]}function Gt(t,e,i){if(M(t.dtype))return Vt(t,e,i);if(t.dtype==="bool"){const I=h.empty(Array.from(t.shape),"int64"),S=t.data,D=I.data,F=t.offset;for(let V=0;V<t.size;V++)D[V]=BigInt(S[F+V]);const U=Gt(I,e,i);return I.dispose(),U}if((e===null||typeof e=="number")&&(i===null||typeof i=="number")){const D=It(t,e===null?-1/0:e,i===null?1/0:i);if(D)return D}const m=t.dtype,p=Array.from(t.shape),c=t.size,y=h.empty(p,m),l=y.data,f=e===null||typeof e=="number",a=i===null||typeof i=="number",o=e===null?-1/0:typeof e=="number"?e:null,r=i===null?1/0:typeof i=="number"?i:null,s=t.isCContiguous,n=t.data,u=t.offset,d=!f&&e.isCContiguous,g=f?null:e.data,A=f?0:e.offset,b=f?0:e.size,N=!a&&i.isCContiguous,z=a?null:i.data,B=a?0:i.offset,w=a?0:i.size;if(C(m)){const I=l;if(s&&(f||d)&&(a||N)){const S=n,D=g,F=z;for(let U=0;U<c;U++){let V=S[u+U];const Z=f?o===-1/0?V:BigInt(Math.round(o)):D[A+U%b],_=a?r===1/0?V:BigInt(Math.round(r)):F[B+U%w];V<Z&&(V=Z),V>_&&(V=_),I[U]=V}}else for(let S=0;S<c;S++){let D=t.iget(S);const F=f?o===-1/0?D:BigInt(Math.round(o)):e.iget(S%e.size),U=a?r===1/0?D:BigInt(Math.round(r)):i.iget(S%i.size);D<F&&(D=F),D>U&&(D=U),I[S]=D}}else if(s&&(f||d)&&(a||N))for(let I=0;I<c;I++){let S=Number(n[u+I]);const D=f?o:Number(g[A+I%b]),F=a?r:Number(z[B+I%w]);S<D&&(S=D),S>F&&(S=F),l[I]=S}else for(let I=0;I<c;I++){let S=Number(t.iget(I));const D=f?o:Number(e.iget(I%e.size)),F=a?r:Number(i.iget(I%i.size));S<D&&(S=D),S>F&&(S=F),l[I]=S}return y}function Fe(t,e){if(M(t.dtype)||typeof e!="number"&&M(e.dtype))return j(t,e,"max");if(typeof e=="number"){const i=W(t,e);if(i)return i}else if(e.size===1){const i=W(t,Number(e.iget(0)));if(i)return i}else if(q(t,e)){const i=et(t,e);if(i)return i}if(typeof e=="number"){const i=t.dtype,m=Array.from(t.shape),p=t.size,c=h.empty(m,i),y=c.data,l=t.data;if(C(i)){const f=y,a=l,o=BigInt(Math.round(e));for(let r=0;r<p;r++)f[r]=a[r]>o?a[r]:o}else for(let f=0;f<p;f++){const a=Number(l[f]);y[f]=isNaN(a)||isNaN(e)?NaN:Math.max(a,e)}return c}return O(t,e,(i,m)=>isNaN(i)||isNaN(m)?NaN:Math.max(i,m),"maximum")}function we(t,e){if(M(t.dtype)||typeof e!="number"&&M(e.dtype))return j(t,e,"min");if(typeof e=="number"){const i=H(t,e);if(i)return i}else if(e.size===1){const i=H(t,Number(e.iget(0)));if(i)return i}else if(q(t,e)){const i=tt(t,e);if(i)return i}if(typeof e=="number"){const i=t.dtype,m=Array.from(t.shape),p=t.size,c=h.empty(m,i),y=c.data,l=t.data;if(C(i)){const f=y,a=l,o=BigInt(Math.round(e));for(let r=0;r<p;r++)f[r]=a[r]<o?a[r]:o}else for(let f=0;f<p;f++){const a=Number(l[f]);y[f]=isNaN(a)||isNaN(e)?NaN:Math.min(a,e)}return c}return O(t,e,(i,m)=>isNaN(i)||isNaN(m)?NaN:Math.min(i,m),"minimum")}function ve(t,e){if(M(t.dtype)||typeof e!="number"&&M(e.dtype))return j(t,e,"max",!0);if(typeof e=="number"){const i=W(t,e);if(i)return i}else if(e.size===1){const i=W(t,Number(e.iget(0)));if(i)return i}else if(q(t,e)){const i=et(t,e);if(i)return i}if(typeof e=="number"){const i=t.dtype,m=Array.from(t.shape),p=t.size,c=h.empty(m,i),y=c.data,l=t.data;if(C(i)){const f=y,a=l,o=BigInt(Math.round(e));for(let r=0;r<p;r++)f[r]=a[r]>o?a[r]:o}else for(let f=0;f<p;f++){const a=Number(l[f]);isNaN(a)?y[f]=e:isNaN(e)?y[f]=a:y[f]=Math.max(a,e)}return c}return O(t,e,(i,m)=>isNaN(i)?m:isNaN(m)?i:Math.max(i,m),"fmax")}function Te(t,e){if(M(t.dtype)||typeof e!="number"&&M(e.dtype))return j(t,e,"min",!0);if(typeof e=="number"){const i=H(t,e);if(i)return i}else if(e.size===1){const i=H(t,Number(e.iget(0)));if(i)return i}else if(q(t,e)){const i=tt(t,e);if(i)return i}if(typeof e=="number"){const i=t.dtype,m=Array.from(t.shape),p=t.size,c=h.empty(m,i),y=c.data,l=t.data;if(C(i)){const f=y,a=l,o=BigInt(Math.round(e));for(let r=0;r<p;r++)f[r]=a[r]<o?a[r]:o}else for(let f=0;f<p;f++){const a=Number(l[f]);isNaN(a)?y[f]=e:isNaN(e)?y[f]=a:y[f]=Math.min(a,e)}return c}return O(t,e,(i,m)=>isNaN(i)?m:isNaN(m)?i:Math.min(i,m),"fmin")}function Re(t,e=0,i,m){const p=t.dtype,c=Array.from(t.shape),y=t.size,l=i!==void 0?i:Number.MAX_VALUE,f=m!==void 0?m:-Number.MAX_VALUE;if(M(p)){const s=h.empty(c,p),n=s.data,u=d=>isNaN(d)?e:d===1/0?l:d===-1/0?f:d;if(t.isCContiguous){const d=t.data,g=t.offset;for(let A=0;A<y;A++)n[A*2]=u(d[(g+A)*2]),n[A*2+1]=u(d[(g+A)*2+1])}else for(let d=0;d<y;d++){const g=t.iget(d);n[d*2]=u(g.re),n[d*2+1]=u(g.im)}return s}const a=h.empty(c,p),o=a.data,r=t.data;if(x(p))o.set(r.subarray(t.offset,t.offset+y));else for(let s=0;s<y;s++){const n=Number(r[s]);isNaN(n)?o[s]=e:n===1/0?o[s]=l:n===-1/0?o[s]=f:o[s]=n}return a}function Ue(t,e,i,m,p){v(t.dtype,"interp","interp is not supported for complex numbers."),v(e.dtype,"interp","interp is not supported for complex numbers."),v(i.dtype,"interp","interp is not supported for complex numbers.");const c=Array.from(t.shape),y=t.size,l=h.empty(c,"float64"),f=l.data,a=t.data,o=e.data,r=i.data,s=e.size,n=m!==void 0?m:Number(r[0]),u=p!==void 0?p:Number(r[s-1]);for(let d=0;d<y;d++){const g=Number(a[d]);if(g<=Number(o[0])){f[d]=n;continue}if(g>=Number(o[s-1])){f[d]=u;continue}let A=0,b=s-1;for(;b-A>1;){const S=Math.floor((A+b)/2);Number(o[S])<=g?A=S:b=S}const N=Number(o[A]),z=Number(o[b]),B=Number(r[A]),w=Number(r[b]),I=(g-N)/(z-N);f[d]=B+I*(w-B)}return l}function Ve(t,e=Math.PI,i=-1,m=2*Math.PI){v(t.dtype,"unwrap","unwrap is not supported for complex numbers.");const p=Array.from(t.shape),c=p.length;if(i<0&&(i+=c),i<0||i>=c)throw new Error(`axis ${i} is out of bounds for array of dimension ${c}`);const y=t.dtype==="float32"?"float32":t.dtype==="float16"?"float16":"float64";if(c===1){const o=t.size,r=h.empty(p,y),s=r.data,n=t.data;if(o===0)return r;s[0]=Number(n[0]);let u=0;for(let d=1;d<o;d++){const g=Number(n[d-1]),A=Number(n[d]);let b=A-g;b=(b+m/2)%m-m/2,b===-m/2&&A-g>0&&(b=m/2),Math.abs(b)>e&&(u-=Math.round((A-g-b)/m)*m),s[d]=A+u}return r}const l=h.empty(p,y),f=l.data,a=t.data;for(let o=0;o<t.size;o++)f[o]=Number(a[o]);if(c===2){const[o,r]=p;if(i===0)for(let s=0;s<r;s++){let n=0;for(let u=1;u<o;u++){const d=(u-1)*r+s,g=u*r+s,A=f[d],b=f[g];let N=b-A;N=(N+m/2)%m-m/2,N===-m/2&&b-A>0&&(N=m/2),Math.abs(N)>e&&(n-=Math.round((b-A-N)/m)*m),f[g]=b+n}}else for(let s=0;s<o;s++){let n=0;for(let u=1;u<r;u++){const d=s*r+(u-1),g=s*r+u,A=f[d],b=f[g];let N=b-A;N=(N+m/2)%m-m/2,N===-m/2&&b-A>0&&(N=m/2),Math.abs(N)>e&&(n-=Math.round((b-A-N)/m)*m),f[g]=b+n}}}return l}function Oe(t){if(M(t.dtype)){const l=Array.from(t.shape),f=t.size,a=h.empty(l,t.dtype),o=a.data;if(t.isCContiguous){const r=t.data,s=t.offset;for(let n=0;n<f;n++){const u=r[(s+n)*2],d=r[(s+n)*2+1];if(u===0&&d===0)o[n*2]=1,o[n*2+1]=0;else{const g=Math.PI*u,A=Math.PI*d,b=Math.sin(g)*Math.cosh(A),N=Math.cos(g)*Math.sinh(A),z=g*g+A*A;o[n*2]=(b*g+N*A)/z,o[n*2+1]=(N*g-b*A)/z}}}else for(let r=0;r<f;r++){const s=t.iget(r);if(s.re===0&&s.im===0)o[r*2]=1,o[r*2+1]=0;else{const n=Math.PI*s.re,u=Math.PI*s.im,d=Math.sin(n)*Math.cosh(u),g=Math.cos(n)*Math.sinh(u),A=n*n+u*u;o[r*2]=(d*n+g*u)/A,o[r*2+1]=(g*n-d*u)/A}}return a}const e=Array.from(t.shape),i=t.size,m=t.dtype==="float16"||t.dtype==="float32"?t.dtype:"float64",p=h.empty(e,m),c=p.data,y=t.data;for(let l=0;l<i;l++){const f=Number(y[l]);if(f===0)c[l]=1;else{const a=Math.PI*f;c[l]=Math.sin(a)/a}}return p}function Ee(t){v(t.dtype,"i0","i0 is not supported for complex numbers.");const e=Array.from(t.shape),i=t.size,m=t.dtype==="float16"||t.dtype==="float32"?t.dtype:"float64",p=h.empty(e,m),c=p.data,y=t.data;for(let l=0;l<i;l++){const f=Math.abs(Number(y[l]));c[l]=Ht(f)}return p}function Ht(t){const e=Math.abs(t);if(e<3.75){const i=t/3.75,m=i*i;return 1+m*(3.5156229+m*(3.0899424+m*(1.2067492+m*(.2659732+m*(.0360768+m*.0045813)))))}else{const i=3.75/e;return Math.exp(e)/Math.sqrt(e)*(.39894228+i*(.01328592+i*(.00225319+i*(-.00157565+i*(.00916281+i*(-.02057706+i*(.02635537+i*(-.01647633+i*.00392377))))))))}}export{Ae as absolute,me as add,De as cbrt,Gt as clip,ge as divide,Ie as divmod,Me as fabs,Lt as float_power,at as floorDivide,ve as fmax,Te as fmin,it as fmod,kt as frexp,ft as gcd,Y as heaviside,Ee as i0,Ue as interp,ut as lcm,lt as ldexp,Fe as maximum,we as minimum,Q as mod,ze as modf,de as multiply,Re as nan_to_num,be as negative,Ne as positive,Se as reciprocal,Be as remainder,he as sign,Oe as sinc,Ce as square,pe as subtract,Ve as unwrap};
@@ -1 +1 @@
1
- import{ArrayStorage as T}from"../storage";import{isBigIntDType as w,isIntegerDType as J,promoteDTypes as F}from"../dtype";import{elementwiseBinaryOp as E}from"../internal/compute";import{wasmBitwiseAnd as K}from"../wasm/bitwise_and";import{wasmBitwiseOr as Q}from"../wasm/bitwise_or";import{wasmBitwiseXor as W}from"../wasm/bitwise_xor";import{wasmBitwiseNot as Y}from"../wasm/bitwise_not";import{wasmLeftShift as Z,wasmLeftShiftScalar as tt}from"../wasm/left_shift";import{wasmRightShift as et,wasmRightShiftScalar as rt}from"../wasm/right_shift";import{wasmBitwiseCount as ot}from"../wasm/bitwise_count";function U(t,r){if(!J(t)&&t!=="bool")throw new TypeError(`ufunc '${r}' not supported for the input types, and the inputs could not be safely coerced to any supported types`)}function $(t,r){return t.isCContiguous&&r.isCContiguous&&t.shape.length===r.shape.length&&t.shape.every((a,l)=>a===r.shape[l])}function Ct(t,r){if(U(t.dtype,"bitwise_and"),typeof r=="number")return nt(t,r);if(U(r.dtype,"bitwise_and"),$(t,r)){const a=K(t,r);return a||it(t,r)}return E(t,r,(a,l)=>a&l,"bitwise_and")}function it(t,r){const a=F(t.dtype,r.dtype),l=T.zeros(Array.from(t.shape),a),u=t.size,f=t.data,i=r.data,y=t.offset,d=r.offset,c=l.data;if(w(a)){const e=c;if(!w(t.dtype)||!w(r.dtype))for(let o=0;o<u;o++){const s=typeof f[y+o]=="bigint"?f[y+o]:BigInt(Math.round(Number(f[y+o]))),p=typeof i[d+o]=="bigint"?i[d+o]:BigInt(Math.round(Number(i[d+o])));e[o]=s&p}else{const o=f,s=i;for(let p=0;p<u;p++)e[p]=o[y+p]&s[d+p]}}else for(let e=0;e<u;e++)c[e]=f[y+e]&i[d+e];return l}function nt(t,r){const a=t.dtype,l=Array.from(t.shape),u=t.data,f=t.offset,i=t.size,y=t.isCContiguous,d=T.zeros(l,a),c=d.data;if(w(a)){const e=c,n=BigInt(Math.round(r));if(y){const o=u;if(f===0)for(let s=0;s<i;s++)e[s]=o[s]&n;else for(let s=0;s<i;s++)e[s]=o[f+s]&n}else for(let o=0;o<i;o++)e[o]=t.iget(o)&n}else if(y)if(f===0)for(let e=0;e<i;e++)c[e]=u[e]&r;else for(let e=0;e<i;e++)c[e]=u[f+e]&r;else for(let e=0;e<i;e++)c[e]=Number(t.iget(e))&r;return d}function Dt(t,r){if(U(t.dtype,"bitwise_or"),typeof r=="number")return at(t,r);if(U(r.dtype,"bitwise_or"),$(t,r)){const a=Q(t,r);return a||st(t,r)}return E(t,r,(a,l)=>a|l,"bitwise_or")}function st(t,r){const a=F(t.dtype,r.dtype),l=T.zeros(Array.from(t.shape),a),u=t.size,f=t.data,i=r.data,y=t.offset,d=r.offset,c=l.data;if(w(a)){const e=c;if(!w(t.dtype)||!w(r.dtype))for(let o=0;o<u;o++){const s=typeof f[y+o]=="bigint"?f[y+o]:BigInt(Math.round(Number(f[y+o]))),p=typeof i[d+o]=="bigint"?i[d+o]:BigInt(Math.round(Number(i[d+o])));e[o]=s|p}else{const o=f,s=i;for(let p=0;p<u;p++)e[p]=o[y+p]|s[d+p]}}else for(let e=0;e<u;e++)c[e]=f[y+e]|i[d+e];return l}function at(t,r){const a=t.dtype,l=Array.from(t.shape),u=t.data,f=t.offset,i=t.size,y=t.isCContiguous,d=T.zeros(l,a),c=d.data;if(w(a)){const e=c,n=BigInt(Math.round(r));if(y){const o=u;if(f===0)for(let s=0;s<i;s++)e[s]=o[s]|n;else for(let s=0;s<i;s++)e[s]=o[f+s]|n}else for(let o=0;o<i;o++)e[o]=t.iget(o)|n}else if(y)if(f===0)for(let e=0;e<i;e++)c[e]=u[e]|r;else for(let e=0;e<i;e++)c[e]=u[f+e]|r;else for(let e=0;e<i;e++)c[e]=Number(t.iget(e))|r;return d}function Tt(t,r){if(U(t.dtype,"bitwise_xor"),typeof r=="number")return ut(t,r);if(U(r.dtype,"bitwise_xor"),$(t,r)){const a=W(t,r);return a||ft(t,r)}return E(t,r,(a,l)=>a^l,"bitwise_xor")}function ft(t,r){const a=F(t.dtype,r.dtype),l=T.zeros(Array.from(t.shape),a),u=t.size,f=t.data,i=r.data,y=t.offset,d=r.offset,c=l.data;if(w(a)){const e=c;if(!w(t.dtype)||!w(r.dtype))for(let o=0;o<u;o++){const s=typeof f[y+o]=="bigint"?f[y+o]:BigInt(Math.round(Number(f[y+o]))),p=typeof i[d+o]=="bigint"?i[d+o]:BigInt(Math.round(Number(i[d+o])));e[o]=s^p}else{const o=f,s=i;for(let p=0;p<u;p++)e[p]=o[y+p]^s[d+p]}}else for(let e=0;e<u;e++)c[e]=f[y+e]^i[d+e];return l}function ut(t,r){const a=t.dtype,l=Array.from(t.shape),u=t.data,f=t.offset,i=t.size,y=t.isCContiguous,d=T.zeros(l,a),c=d.data;if(w(a)){const e=c,n=BigInt(Math.round(r));if(y){const o=u;if(f===0)for(let s=0;s<i;s++)e[s]=o[s]^n;else for(let s=0;s<i;s++)e[s]=o[f+s]^n}else for(let o=0;o<i;o++)e[o]=t.iget(o)^n}else if(y)if(f===0)for(let e=0;e<i;e++)c[e]=u[e]^r;else for(let e=0;e<i;e++)c[e]=u[f+e]^r;else for(let e=0;e<i;e++)c[e]=Number(t.iget(e))^r;return d}function x(t){U(t.dtype,"bitwise_not");const r=Y(t);if(r)return r;const a=t.dtype,l=Array.from(t.shape),u=t.data,f=t.offset,i=t.size,y=t.isCContiguous,d=T.zeros(l,a),c=d.data;if(w(a)){const e=c;if(y){const n=u;if(f===0)for(let o=0;o<i;o++)e[o]=~n[o];else for(let o=0;o<i;o++)e[o]=~n[f+o]}else for(let n=0;n<i;n++)e[n]=~t.iget(n)}else if(y)if(f===0)for(let e=0;e<i;e++)c[e]=~u[e];else for(let e=0;e<i;e++)c[e]=~u[f+e];else for(let e=0;e<i;e++)c[e]=~Number(t.iget(e));return d}function Nt(t){return x(t)}function ct(t,r){if(U(t.dtype,"left_shift"),typeof r=="number")return G(t,r);if(U(r.dtype,"left_shift"),r.size===1||r.ndim===1&&r.shape[0]===1){const a=Number(r.iget(0)),l=tt(t,a);return l||G(t,a)}if($(t,r)){const a=Z(t,r);return a||lt(t,r)}return E(t,r,(a,l)=>a<<l,"left_shift")}function lt(t,r){const a=F(t.dtype,r.dtype),l=T.zeros(Array.from(t.shape),a),u=t.size,f=t.data,i=r.data,y=t.offset,d=r.offset,c=l.data;if(w(a)){const e=c;for(let n=0;n<u;n++){const o=typeof f[y+n]=="bigint"?f[y+n]:BigInt(Math.round(Number(f[y+n]))),s=typeof i[d+n]=="bigint"?i[d+n]:BigInt(Math.round(Number(i[d+n])));e[n]=o<<s}}else for(let e=0;e<u;e++)c[e]=f[y+e]<<i[d+e];return l}function G(t,r){const a=t.dtype,l=Array.from(t.shape),u=t.data,f=t.offset,i=t.size,y=t.isCContiguous,d=T.zeros(l,a),c=d.data;if(w(a)){const e=c,n=BigInt(Math.round(r));if(y){const o=u;if(f===0)for(let s=0;s<i;s++)e[s]=o[s]<<n;else for(let s=0;s<i;s++)e[s]=o[f+s]<<n}else for(let o=0;o<i;o++)e[o]=t.iget(o)<<n}else if(y)if(f===0)for(let e=0;e<i;e++)c[e]=u[e]<<r;else for(let e=0;e<i;e++)c[e]=u[f+e]<<r;else for(let e=0;e<i;e++)c[e]=Number(t.iget(e))<<r;return d}function yt(t,r){if(U(t.dtype,"right_shift"),typeof r=="number")return H(t,r);if(U(r.dtype,"right_shift"),r.size===1||r.ndim===1&&r.shape[0]===1){const a=Number(r.iget(0)),l=rt(t,a);return l||H(t,a)}if($(t,r)){const a=et(t,r);return a||dt(t,r)}return E(t,r,(a,l)=>a>>l,"right_shift")}function dt(t,r){const a=F(t.dtype,r.dtype),l=T.zeros(Array.from(t.shape),a),u=t.size,f=t.data,i=r.data,y=t.offset,d=r.offset,c=l.data;if(w(a)){const e=c;for(let n=0;n<u;n++){const o=typeof f[y+n]=="bigint"?f[y+n]:BigInt(Math.round(Number(f[y+n]))),s=typeof i[d+n]=="bigint"?i[d+n]:BigInt(Math.round(Number(i[d+n])));e[n]=o>>s}}else for(let e=0;e<u;e++)c[e]=f[y+e]>>i[d+e];return l}function H(t,r){const a=t.dtype,l=Array.from(t.shape),u=t.data,f=t.offset,i=t.size,y=t.isCContiguous,d=T.zeros(l,a),c=d.data;if(w(a)){const e=c,n=BigInt(Math.round(r));if(y){const o=u;if(f===0)for(let s=0;s<i;s++)e[s]=o[s]>>n;else for(let s=0;s<i;s++)e[s]=o[f+s]>>n}else for(let o=0;o<i;o++)e[o]=t.iget(o)>>n}else if(y)if(f===0)for(let e=0;e<i;e++)c[e]=u[e]>>r;else for(let e=0;e<i;e++)c[e]=u[f+e]>>r;else for(let e=0;e<i;e++)c[e]=Number(t.iget(e))>>r;return d}function Ut(t,r=-1,a="big"){const l=Array.from(t.shape),u=l.length;if(r<0&&(r=u+r),r<0||r>=u)throw new Error(`axis ${r} is out of bounds for array of dimension ${u}`);const f=l[r],i=Math.ceil(f/8),y=[...l];y[r]=i;const d=T.zeros(y,"uint8"),c=d.data,e=t.offset,n=t.isCContiguous;if(u===1){for(let z=0;z<i;z++){let g=0;for(let A=0;A<8;A++){const S=z*8+A;if(S<f){const I=n?Number(t.data[e+S])!==0?1:0:Number(t.iget(S))!==0?1:0;a==="big"?g|=I<<7-A:g|=I<<A}}c[z]=g}return d}const o=l.slice(0,r),s=l.slice(r+1),p=o.reduce((z,g)=>z*g,1),L=s.reduce((z,g)=>z*g,1),k=X(l),v=X(y);for(let z=0;z<p;z++)for(let g=0;g<L;g++)for(let A=0;A<i;A++){let S=0;for(let h=0;h<8;h++){const m=A*8+h;if(m<f){let B=0,C=z;for(let D=0;D<r;D++){const _=D<r-1?o.slice(D+1).reduce((P,j)=>P*j,1):1,O=Math.floor(C/_);C%=_,B+=O*k[D]}B+=m*k[r];let b=g;for(let D=r+1;D<u;D++){const _=D<u-1?s.slice(D-r).reduce((P,j)=>P*j,1):1,O=Math.floor(b/_);b%=_,B+=O*k[D]}const N=n?Number(t.data[e+B])!==0?1:0:Number(t.iget(B))!==0?1:0;a==="big"?S|=N<<7-h:S|=N<<h}}let I=0,M=z;for(let h=0;h<r;h++){const m=h<r-1?o.slice(h+1).reduce((C,b)=>C*b,1):1,B=Math.floor(M/m);M%=m,I+=B*v[h]}I+=A*v[r];let R=g;for(let h=r+1;h<u;h++){const m=h<u-1?s.slice(h-r).reduce((C,b)=>C*b,1):1,B=Math.floor(R/m);R%=m,I+=B*v[h]}c[I]=S}return d}function _t(t,r=-1,a=-1,l="big"){if(t.dtype!=="uint8")throw new TypeError("Expected an input array of unsigned byte data type");const u=Array.from(t.shape),f=u.length;if(r<0&&(r=f+r),r<0||r>=f)throw new Error(`axis ${r} is out of bounds for array of dimension ${f}`);const i=u[r];let y=i*8;a>=0&&(y=a);const d=[...u];d[r]=y;const c=T.zeros(d,"uint8"),e=c.data,n=t.offset,o=t.isCContiguous;if(f===1){for(let g=0;g<i;g++){const A=Number(o?t.data[n+g]:t.iget(g));for(let S=0;S<8;S++){const I=g*8+S;if(I>=y)break;l==="big"?e[I]=A>>7-S&1:e[I]=A>>S&1}}return c}const s=u.slice(0,r),p=u.slice(r+1),L=s.reduce((g,A)=>g*A,1),k=p.reduce((g,A)=>g*A,1),v=X(u),z=X(d);for(let g=0;g<L;g++)for(let A=0;A<k;A++)for(let S=0;S<i;S++){let I=0,M=g;for(let m=0;m<r;m++){const B=m<r-1?s.slice(m+1).reduce((b,N)=>b*N,1):1,C=Math.floor(M/B);M%=B,I+=C*v[m]}I+=S*v[r];let R=A;for(let m=r+1;m<f;m++){const B=m<f-1?p.slice(m-r).reduce((b,N)=>b*N,1):1,C=Math.floor(R/B);R%=B,I+=C*v[m]}const h=Number(o?t.data[n+I]:t.iget(I));for(let m=0;m<8;m++){const B=S*8+m;if(B>=y)break;let C=0;M=g;for(let b=0;b<r;b++){const N=b<r-1?s.slice(b+1).reduce((_,O)=>_*O,1):1,D=Math.floor(M/N);M%=N,C+=D*z[b]}C+=B*z[r],R=A;for(let b=r+1;b<f;b++){const N=b<f-1?p.slice(b-r).reduce((_,O)=>_*O,1):1,D=Math.floor(R/N);R%=N,C+=D*z[b]}l==="big"?e[C]=h>>7-m&1:e[C]=h>>m&1}}return c}function X(t){const r=t.length,a=new Array(r);let l=1;for(let u=r-1;u>=0;u--)a[u]=l,l*=t[u];return a}function Mt(t){const r=t.dtype;U(r,"bitwise_count");const a=ot(t);if(a)return a;const l=Array.from(t.shape),u=t.data,f=t.offset,i=t.size,y=t.isCContiguous,d=T.zeros(l,"uint8"),c=d.data,e=r==="int8"||r==="int16"||r==="int32"||r==="int64";if(w(r))if(y){const n=u;if(f===0)for(let o=0;o<i;o++){const s=n[o];c[o]=q(e&&s<0n?-s:s)}else for(let o=0;o<i;o++){const s=n[f+o];c[o]=q(e&&s<0n?-s:s)}}else for(let n=0;n<i;n++){const o=t.iget(n);c[n]=q(e&&o<0n?-o:o)}else if(e)if(y)if(f===0)for(let n=0;n<i;n++)c[n]=V(Math.abs(u[n]));else for(let n=0;n<i;n++)c[n]=V(Math.abs(u[f+n]));else for(let n=0;n<i;n++)c[n]=V(Math.abs(Number(t.iget(n))));else{const n=r==="uint8"?255:r==="uint16"?65535:4294967295;if(y)if(f===0)for(let o=0;o<i;o++)c[o]=V(u[o]&n);else for(let o=0;o<i;o++)c[o]=V(u[f+o]&n);else for(let o=0;o<i;o++)c[o]=V(Number(t.iget(o))&n)}return d}function V(t){t=t>>>0;let r=0;for(;t!==0;)t=t&t-1,r++;return r}function q(t){t<0n&&(t=BigInt.asUintN(64,t));let r=0;for(;t!==0n;)t=t&t-1n,r++;return r}function Rt(t){return x(t)}function vt(t,r){return ct(t,r)}function Ot(t,r){return yt(t,r)}export{Ct as bitwise_and,Mt as bitwise_count,Rt as bitwise_invert,vt as bitwise_left_shift,x as bitwise_not,Dt as bitwise_or,Ot as bitwise_right_shift,Tt as bitwise_xor,Nt as invert,ct as left_shift,Ut as packbits,yt as right_shift,_t as unpackbits};
1
+ import{ArrayStorage as D}from"../storage.js";import{isBigIntDType as w,isIntegerDType as Q,promoteDTypes as F}from"../dtype.js";function V(t){const e=D.empty(Array.from(t.shape),"int8"),f=t.data,y=e.data,u=t.offset;for(let n=0;n<t.size;n++)y[n]=f[u+n];return e}import{elementwiseBinaryOp as $}from"../internal/compute.js";import{wasmBitwiseAnd as Y}from"../wasm/bitwise_and.js";import{wasmBitwiseOr as Z}from"../wasm/bitwise_or.js";import{wasmBitwiseXor as tt}from"../wasm/bitwise_xor.js";import{wasmBitwiseNot as et}from"../wasm/bitwise_not.js";import{wasmLeftShift as rt,wasmLeftShiftScalar as ot}from"../wasm/left_shift.js";import{wasmRightShift as it,wasmRightShiftScalar as nt}from"../wasm/right_shift.js";import{wasmBitwiseCount as st}from"../wasm/bitwise_count.js";function U(t,e){if(!Q(t)&&t!=="bool")throw new TypeError(`ufunc '${e}' not supported for the input types, and the inputs could not be safely coerced to any supported types`)}function X(t,e){return t.isCContiguous&&e.isCContiguous&&t.shape.length===e.shape.length&&t.shape.every((f,y)=>f===e.shape[y])}function Ct(t,e){if(U(t.dtype,"bitwise_and"),typeof e=="number")return ft(t,e);if(U(e.dtype,"bitwise_and"),X(t,e)){const f=Y(t,e);return f||at(t,e)}return $(t,e,(f,y)=>f&y,"bitwise_and")}function at(t,e){const f=F(t.dtype,e.dtype),y=D.empty(Array.from(t.shape),f),u=t.size,n=t.data,i=e.data,l=t.offset,p=e.offset,c=y.data;if(w(f)){const r=c;if(!w(t.dtype)||!w(e.dtype))for(let o=0;o<u;o++){const a=typeof n[l+o]=="bigint"?n[l+o]:BigInt(Math.round(Number(n[l+o]))),d=typeof i[p+o]=="bigint"?i[p+o]:BigInt(Math.round(Number(i[p+o])));r[o]=a&d}else{const o=n,a=i;for(let d=0;d<u;d++)r[d]=o[l+d]&a[p+d]}}else for(let r=0;r<u;r++)c[r]=n[l+r]&i[p+r];return y}function ft(t,e){const f=t.dtype,y=Array.from(t.shape),u=t.data,n=t.offset,i=t.size,l=t.isCContiguous,p=D.empty(y,f),c=p.data;if(w(f)){const r=c,s=BigInt(Math.round(e));if(l){const o=u;if(n===0)for(let a=0;a<i;a++)r[a]=o[a]&s;else for(let a=0;a<i;a++)r[a]=o[n+a]&s}else for(let o=0;o<i;o++)r[o]=t.iget(o)&s}else if(l)if(n===0)for(let r=0;r<i;r++)c[r]=u[r]&e;else for(let r=0;r<i;r++)c[r]=u[n+r]&e;else for(let r=0;r<i;r++)c[r]=Number(t.iget(r))&e;return p}function Dt(t,e){if(U(t.dtype,"bitwise_or"),typeof e=="number")return ct(t,e);if(U(e.dtype,"bitwise_or"),X(t,e)){const f=Z(t,e);return f||ut(t,e)}return $(t,e,(f,y)=>f|y,"bitwise_or")}function ut(t,e){const f=F(t.dtype,e.dtype),y=D.empty(Array.from(t.shape),f),u=t.size,n=t.data,i=e.data,l=t.offset,p=e.offset,c=y.data;if(w(f)){const r=c;if(!w(t.dtype)||!w(e.dtype))for(let o=0;o<u;o++){const a=typeof n[l+o]=="bigint"?n[l+o]:BigInt(Math.round(Number(n[l+o]))),d=typeof i[p+o]=="bigint"?i[p+o]:BigInt(Math.round(Number(i[p+o])));r[o]=a|d}else{const o=n,a=i;for(let d=0;d<u;d++)r[d]=o[l+d]|a[p+d]}}else for(let r=0;r<u;r++)c[r]=n[l+r]|i[p+r];return y}function ct(t,e){const f=t.dtype,y=Array.from(t.shape),u=t.data,n=t.offset,i=t.size,l=t.isCContiguous,p=D.empty(y,f),c=p.data;if(w(f)){const r=c,s=BigInt(Math.round(e));if(l){const o=u;if(n===0)for(let a=0;a<i;a++)r[a]=o[a]|s;else for(let a=0;a<i;a++)r[a]=o[n+a]|s}else for(let o=0;o<i;o++)r[o]=t.iget(o)|s}else if(l)if(n===0)for(let r=0;r<i;r++)c[r]=u[r]|e;else for(let r=0;r<i;r++)c[r]=u[n+r]|e;else for(let r=0;r<i;r++)c[r]=Number(t.iget(r))|e;return p}function Nt(t,e){if(U(t.dtype,"bitwise_xor"),typeof e=="number")return lt(t,e);if(U(e.dtype,"bitwise_xor"),X(t,e)){const f=tt(t,e);return f||yt(t,e)}return $(t,e,(f,y)=>f^y,"bitwise_xor")}function yt(t,e){const f=F(t.dtype,e.dtype),y=D.empty(Array.from(t.shape),f),u=t.size,n=t.data,i=e.data,l=t.offset,p=e.offset,c=y.data;if(w(f)){const r=c;if(!w(t.dtype)||!w(e.dtype))for(let o=0;o<u;o++){const a=typeof n[l+o]=="bigint"?n[l+o]:BigInt(Math.round(Number(n[l+o]))),d=typeof i[p+o]=="bigint"?i[p+o]:BigInt(Math.round(Number(i[p+o])));r[o]=a^d}else{const o=n,a=i;for(let d=0;d<u;d++)r[d]=o[l+d]^a[p+d]}}else for(let r=0;r<u;r++)c[r]=n[l+r]^i[p+r];return y}function lt(t,e){const f=t.dtype,y=Array.from(t.shape),u=t.data,n=t.offset,i=t.size,l=t.isCContiguous,p=D.empty(y,f),c=p.data;if(w(f)){const r=c,s=BigInt(Math.round(e));if(l){const o=u;if(n===0)for(let a=0;a<i;a++)r[a]=o[a]^s;else for(let a=0;a<i;a++)r[a]=o[n+a]^s}else for(let o=0;o<i;o++)r[o]=t.iget(o)^s}else if(l)if(n===0)for(let r=0;r<i;r++)c[r]=u[r]^e;else for(let r=0;r<i;r++)c[r]=u[n+r]^e;else for(let r=0;r<i;r++)c[r]=Number(t.iget(r))^e;return p}function H(t){U(t.dtype,"bitwise_not");const e=et(t);if(e)return e;const f=t.dtype,y=Array.from(t.shape),u=t.data,n=t.offset,i=t.size,l=t.isCContiguous,p=D.empty(y,f),c=p.data;if(f==="bool"){if(l)for(let r=0;r<i;r++)c[r]=u[n+r]?0:1;else for(let r=0;r<i;r++)c[r]=Number(t.iget(r))?0:1;return p}if(w(f)){const r=c;if(l){const s=u;if(n===0)for(let o=0;o<i;o++)r[o]=~s[o];else for(let o=0;o<i;o++)r[o]=~s[n+o]}else for(let s=0;s<i;s++)r[s]=~t.iget(s)}else if(l)if(n===0)for(let r=0;r<i;r++)c[r]=~u[r];else for(let r=0;r<i;r++)c[r]=~u[n+r];else for(let r=0;r<i;r++)c[r]=~Number(t.iget(r));return p}function Ut(t){return H(t)}function j(t,e){if(t.dtype==="bool")return j(V(t),typeof e=="number"?e:e.dtype==="bool"?V(e):e);if(typeof e!="number"&&e.dtype==="bool")return j(t,V(e));if(U(t.dtype,"left_shift"),typeof e=="number")return J(t,e);if(U(e.dtype,"left_shift"),e.size===1||e.ndim===1&&e.shape[0]===1){const f=Number(e.iget(0)),y=ot(t,f);return y||J(t,f)}if(X(t,e)){const f=rt(t,e);return f||pt(t,e)}return $(t,e,(f,y)=>f<<y,"left_shift")}function pt(t,e){const f=F(t.dtype,e.dtype),y=D.empty(Array.from(t.shape),f),u=t.size,n=t.data,i=e.data,l=t.offset,p=e.offset,c=y.data;if(w(f)){const r=c;for(let s=0;s<u;s++){const o=typeof n[l+s]=="bigint"?n[l+s]:BigInt(Math.round(Number(n[l+s]))),a=typeof i[p+s]=="bigint"?i[p+s]:BigInt(Math.round(Number(i[p+s])));r[s]=o<<a}}else for(let r=0;r<u;r++)c[r]=n[l+r]<<i[p+r];return y}function J(t,e){const f=t.dtype,y=Array.from(t.shape),u=t.data,n=t.offset,i=t.size,l=t.isCContiguous,p=D.empty(y,f),c=p.data;if(w(f)){const r=c,s=BigInt(Math.round(e));if(l){const o=u;if(n===0)for(let a=0;a<i;a++)r[a]=o[a]<<s;else for(let a=0;a<i;a++)r[a]=o[n+a]<<s}else for(let o=0;o<i;o++)r[o]=t.iget(o)<<s}else if(l)if(n===0)for(let r=0;r<i;r++)c[r]=u[r]<<e;else for(let r=0;r<i;r++)c[r]=u[n+r]<<e;else for(let r=0;r<i;r++)c[r]=Number(t.iget(r))<<e;return p}function q(t,e){if(t.dtype==="bool")return q(V(t),typeof e=="number"?e:e.dtype==="bool"?V(e):e);if(typeof e!="number"&&e.dtype==="bool")return q(t,V(e));if(U(t.dtype,"right_shift"),typeof e=="number")return K(t,e);if(U(e.dtype,"right_shift"),e.size===1||e.ndim===1&&e.shape[0]===1){const f=Number(e.iget(0)),y=nt(t,f);return y||K(t,f)}if(X(t,e)){const f=it(t,e);return f||dt(t,e)}return $(t,e,(f,y)=>f>>y,"right_shift")}function dt(t,e){const f=F(t.dtype,e.dtype),y=D.empty(Array.from(t.shape),f),u=t.size,n=t.data,i=e.data,l=t.offset,p=e.offset,c=y.data;if(w(f)){const r=c;for(let s=0;s<u;s++){const o=typeof n[l+s]=="bigint"?n[l+s]:BigInt(Math.round(Number(n[l+s]))),a=typeof i[p+s]=="bigint"?i[p+s]:BigInt(Math.round(Number(i[p+s])));r[s]=o>>a}}else for(let r=0;r<u;r++)c[r]=n[l+r]>>i[p+r];return y}function K(t,e){const f=t.dtype,y=Array.from(t.shape),u=t.data,n=t.offset,i=t.size,l=t.isCContiguous,p=D.empty(y,f),c=p.data;if(w(f)){const r=c,s=BigInt(Math.round(e));if(l){const o=u;if(n===0)for(let a=0;a<i;a++)r[a]=o[a]>>s;else for(let a=0;a<i;a++)r[a]=o[n+a]>>s}else for(let o=0;o<i;o++)r[o]=t.iget(o)>>s}else if(l)if(n===0)for(let r=0;r<i;r++)c[r]=u[r]>>e;else for(let r=0;r<i;r++)c[r]=u[n+r]>>e;else for(let r=0;r<i;r++)c[r]=Number(t.iget(r))>>e;return p}function _t(t,e=-1,f="big"){if(t.dtype.startsWith("float")||t.dtype.startsWith("complex"))throw new TypeError(`Expected an input array of integer or boolean data type, got '${t.dtype}'`);const y=Array.from(t.shape),u=y.length;if(e<0&&(e=u+e),e<0||e>=u)throw new Error(`axis ${e} is out of bounds for array of dimension ${u}`);const n=y[e],i=Math.ceil(n/8),l=[...y];l[e]=i;const p=D.empty(l,"uint8"),c=p.data,r=t.offset,s=t.isCContiguous;if(u===1){for(let I=0;I<i;I++){let g=0;for(let A=0;A<8;A++){const S=I*8+A;if(S<n){const z=s?Number(t.data[r+S])!==0?1:0:Number(t.iget(S))!==0?1:0;f==="big"?g|=z<<7-A:g|=z<<A}}c[I]=g}return p}const o=y.slice(0,e),a=y.slice(e+1),d=o.reduce((I,g)=>I*g,1),L=a.reduce((I,g)=>I*g,1),E=x(y),v=x(l);for(let I=0;I<d;I++)for(let g=0;g<L;g++)for(let A=0;A<i;A++){let S=0;for(let h=0;h<8;h++){const m=A*8+h;if(m<n){let B=0,T=I;for(let C=0;C<e;C++){const _=C<e-1?o.slice(C+1).reduce((W,P)=>W*P,1):1,O=Math.floor(T/_);T%=_,B+=O*E[C]}B+=m*E[e];let b=g;for(let C=e+1;C<u;C++){const _=C<u-1?a.slice(C-e).reduce((W,P)=>W*P,1):1,O=Math.floor(b/_);b%=_,B+=O*E[C]}const N=s?Number(t.data[r+B])!==0?1:0:Number(t.iget(B))!==0?1:0;f==="big"?S|=N<<7-h:S|=N<<h}}let z=0,M=I;for(let h=0;h<e;h++){const m=h<e-1?o.slice(h+1).reduce((T,b)=>T*b,1):1,B=Math.floor(M/m);M%=m,z+=B*v[h]}z+=A*v[e];let R=g;for(let h=e+1;h<u;h++){const m=h<u-1?a.slice(h-e).reduce((T,b)=>T*b,1):1,B=Math.floor(R/m);R%=m,z+=B*v[h]}c[z]=S}return p}function Mt(t,e=-1,f=-1,y="big"){if(t.dtype!=="uint8")throw new TypeError("Expected an input array of unsigned byte data type");const u=Array.from(t.shape),n=u.length;if(e<0&&(e=n+e),e<0||e>=n)throw new Error(`axis ${e} is out of bounds for array of dimension ${n}`);const i=u[e];let l=i*8;f>=0&&(l=f);const p=[...u];p[e]=l;const c=D.zeros(p,"uint8"),r=c.data,s=t.offset,o=t.isCContiguous;if(n===1){for(let g=0;g<i;g++){const A=Number(o?t.data[s+g]:t.iget(g));for(let S=0;S<8;S++){const z=g*8+S;if(z>=l)break;y==="big"?r[z]=A>>7-S&1:r[z]=A>>S&1}}return c}const a=u.slice(0,e),d=u.slice(e+1),L=a.reduce((g,A)=>g*A,1),E=d.reduce((g,A)=>g*A,1),v=x(u),I=x(p);for(let g=0;g<L;g++)for(let A=0;A<E;A++)for(let S=0;S<i;S++){let z=0,M=g;for(let m=0;m<e;m++){const B=m<e-1?a.slice(m+1).reduce((b,N)=>b*N,1):1,T=Math.floor(M/B);M%=B,z+=T*v[m]}z+=S*v[e];let R=A;for(let m=e+1;m<n;m++){const B=m<n-1?d.slice(m-e).reduce((b,N)=>b*N,1):1,T=Math.floor(R/B);R%=B,z+=T*v[m]}const h=Number(o?t.data[s+z]:t.iget(z));for(let m=0;m<8;m++){const B=S*8+m;if(B>=l)break;let T=0;M=g;for(let b=0;b<e;b++){const N=b<e-1?a.slice(b+1).reduce((_,O)=>_*O,1):1,C=Math.floor(M/N);M%=N,T+=C*I[b]}T+=B*I[e],R=A;for(let b=e+1;b<n;b++){const N=b<n-1?d.slice(b-e).reduce((_,O)=>_*O,1):1,C=Math.floor(R/N);R%=N,T+=C*I[b]}y==="big"?r[T]=h>>7-m&1:r[T]=h>>m&1}}return c}function x(t){const e=t.length,f=new Array(e);let y=1;for(let u=e-1;u>=0;u--)f[u]=y,y*=t[u];return f}function Rt(t){const e=t.dtype;U(e,"bitwise_count");const f=st(t);if(f)return f;const y=Array.from(t.shape),u=t.data,n=t.offset,i=t.size,l=t.isCContiguous,p=D.empty(y,"uint8"),c=p.data,r=e==="int8"||e==="int16"||e==="int32"||e==="int64";if(w(e))if(l){const s=u;if(n===0)for(let o=0;o<i;o++){const a=s[o];c[o]=G(r&&a<0n?-a:a)}else for(let o=0;o<i;o++){const a=s[n+o];c[o]=G(r&&a<0n?-a:a)}}else for(let s=0;s<i;s++){const o=t.iget(s);c[s]=G(r&&o<0n?-o:o)}else if(r)if(l)if(n===0)for(let s=0;s<i;s++)c[s]=k(Math.abs(u[s]));else for(let s=0;s<i;s++)c[s]=k(Math.abs(u[n+s]));else for(let s=0;s<i;s++)c[s]=k(Math.abs(Number(t.iget(s))));else{const s=e==="uint8"?255:e==="uint16"?65535:4294967295;if(l)if(n===0)for(let o=0;o<i;o++)c[o]=k(u[o]&s);else for(let o=0;o<i;o++)c[o]=k(u[n+o]&s);else for(let o=0;o<i;o++)c[o]=k(Number(t.iget(o))&s)}return p}function k(t){t=t>>>0;let e=0;for(;t!==0;)t=t&t-1,e++;return e}function G(t){t<0n&&(t=BigInt.asUintN(64,t));let e=0;for(;t!==0n;)t=t&t-1n,e++;return e}function vt(t){return H(t)}function Ot(t,e){return j(t,e)}function Vt(t,e){return q(t,e)}export{Ct as bitwise_and,Rt as bitwise_count,vt as bitwise_invert,Ot as bitwise_left_shift,H as bitwise_not,Dt as bitwise_or,Vt as bitwise_right_shift,Nt as bitwise_xor,Ut as invert,j as left_shift,_t as packbits,q as right_shift,Mt as unpackbits};
@@ -1 +1 @@
1
- import{ArrayStorage as y}from"../storage";import{isBigIntDType as z,isComplexDType as c}from"../dtype";import{elementwiseComparisonOp as p}from"../internal/compute";import{computeBroadcastShape as g,broadcastTo as D}from"../broadcasting";import{Complex as v}from"../complex";function d(r,t){return[r[t*2],r[t*2+1]]}function x(r,t){if(c(r.dtype))return d(r.data,t);const o=r.iget(t);return o instanceof v?[o.re,o.im]:[Number(o),0]}function S(r,t,o){const i=g([Array.from(r.shape),Array.from(t.shape)]);if(!i)throw new Error("Cannot broadcast arrays together");const u=D(r,i),e=D(t,i),n=i.reduce((a,s)=>a*s,1),f=new Uint8Array(n);for(let a=0;a<n;a++){const[s,l]=x(u,a),[m,b]=x(e,a);f[a]=o(s,l,m,b)?1:0}return y.fromData(f,i,"bool")}function H(r,t){return typeof t=="number"?B(r,t):c(r.dtype)||c(t.dtype)?S(r,t,(o,i,u,e)=>o!==u?o>u:i>e):p(r,t,(o,i)=>o>i)}function J(r,t){return typeof t=="number"?I(r,t):c(r.dtype)||c(t.dtype)?S(r,t,(o,i,u,e)=>o!==u?o>=u:i>=e):p(r,t,(o,i)=>o>=i)}function K(r,t){return typeof t=="number"?N(r,t):c(r.dtype)||c(t.dtype)?S(r,t,(o,i,u,e)=>o!==u?o<u:i<e):p(r,t,(o,i)=>o<i)}function L(r,t){return typeof t=="number"?U(r,t):c(r.dtype)||c(t.dtype)?S(r,t,(o,i,u,e)=>o!==u?o<=u:i<=e):p(r,t,(o,i)=>o<=i)}function P(r,t){return typeof t=="number"?q(r,t):c(r.dtype)||c(t.dtype)?S(r,t,(o,i,u,e)=>o===u&&i===e):p(r,t,(o,i)=>o===i)}function Q(r,t){return typeof t=="number"?E(r,t):c(r.dtype)||c(t.dtype)?S(r,t,(o,i,u,e)=>o!==u||i!==e):p(r,t,(o,i)=>o!==i)}function w(r,t,o=1e-5,i=1e-8){return typeof t=="number"?M(r,t,o,i):p(r,t,(u,e)=>{const n=Math.abs(u-e),f=i+o*Math.abs(e);return n<=f})}function V(r,t,o=1e-5,i=1e-8){const u=w(r,t,o,i),e=u.data;for(let n=0;n<u.size;n++)if(e[n]===0)return!1;return!0}function W(r,t){const o=[Array.from(r.shape),Array.from(t.shape)],i=g(o);if(i===null)return!1;const u=D(r,i),e=D(t,i),n=i.length,f=i.reduce((l,m)=>l*m,1),a=z(u.dtype),s=z(e.dtype);for(let l=0;l<f;l++){let m=l;const b=new Array(n);for(let A=n-1;A>=0;A--)b[A]=m%i[A],m=Math.floor(m/i[A]);const h=u.get(...b),C=e.get(...b);if(a||s){const A=typeof h=="bigint"?h:BigInt(Number(h)),F=typeof C=="bigint"?C:BigInt(Number(C));if(A!==F)return!1}else if(h!==C)return!1}return!0}function B(r,t){const o=new Uint8Array(r.size),i=r.size,u=r.isCContiguous;if(c(r.dtype))if(u){const e=r.data,n=r.offset;for(let f=0;f<i;f++){const[a,s]=d(e,n+f);o[f]=(a!==t?a>t:s>0)?1:0}}else for(let e=0;e<i;e++){const n=r.iget(e);o[e]=(n.re!==t?n.re>t:n.im>0)?1:0}else if(u){const e=r.data,n=r.offset;for(let f=0;f<i;f++)o[f]=e[n+f]>t?1:0}else for(let e=0;e<i;e++)o[e]=Number(r.iget(e))>t?1:0;return y.fromData(o,Array.from(r.shape),"bool")}function I(r,t){const o=new Uint8Array(r.size),i=r.size,u=r.isCContiguous;if(c(r.dtype))if(u){const e=r.data,n=r.offset;for(let f=0;f<i;f++){const[a,s]=d(e,n+f);o[f]=(a!==t?a>=t:s>=0)?1:0}}else for(let e=0;e<i;e++){const n=r.iget(e);o[e]=(n.re!==t?n.re>=t:n.im>=0)?1:0}else if(u){const e=r.data,n=r.offset;for(let f=0;f<i;f++)o[f]=e[n+f]>=t?1:0}else for(let e=0;e<i;e++)o[e]=Number(r.iget(e))>=t?1:0;return y.fromData(o,Array.from(r.shape),"bool")}function N(r,t){const o=new Uint8Array(r.size),i=r.size,u=r.isCContiguous;if(c(r.dtype))if(u){const e=r.data,n=r.offset;for(let f=0;f<i;f++){const[a,s]=d(e,n+f);o[f]=(a!==t?a<t:s<0)?1:0}}else for(let e=0;e<i;e++){const n=r.iget(e);o[e]=(n.re!==t?n.re<t:n.im<0)?1:0}else if(u){const e=r.data,n=r.offset;for(let f=0;f<i;f++)o[f]=e[n+f]<t?1:0}else for(let e=0;e<i;e++)o[e]=Number(r.iget(e))<t?1:0;return y.fromData(o,Array.from(r.shape),"bool")}function U(r,t){const o=new Uint8Array(r.size),i=r.size,u=r.isCContiguous;if(c(r.dtype))if(u){const e=r.data,n=r.offset;for(let f=0;f<i;f++){const[a,s]=d(e,n+f);o[f]=(a!==t?a<=t:s<=0)?1:0}}else for(let e=0;e<i;e++){const n=r.iget(e);o[e]=(n.re!==t?n.re<=t:n.im<=0)?1:0}else if(u){const e=r.data,n=r.offset;for(let f=0;f<i;f++)o[f]=e[n+f]<=t?1:0}else for(let e=0;e<i;e++)o[e]=Number(r.iget(e))<=t?1:0;return y.fromData(o,Array.from(r.shape),"bool")}function q(r,t){const o=new Uint8Array(r.size),i=r.size,u=r.dtype,e=r.isCContiguous;if(c(u))if(e){const n=r.data,f=r.offset;for(let a=0;a<i;a++){const[s,l]=d(n,f+a);o[a]=s===t&&l===0?1:0}}else for(let n=0;n<i;n++){const f=r.iget(n);o[n]=f.re===t&&f.im===0?1:0}else if(z(u)){const n=BigInt(Math.round(t));if(e){const f=r.data,a=r.offset;for(let s=0;s<i;s++)o[s]=f[a+s]===n?1:0}else for(let f=0;f<i;f++)o[f]=r.iget(f)===n?1:0}else if(e){const n=r.data,f=r.offset;for(let a=0;a<i;a++)o[a]=n[f+a]===t?1:0}else for(let n=0;n<i;n++)o[n]=Number(r.iget(n))===t?1:0;return y.fromData(o,Array.from(r.shape),"bool")}function E(r,t){const o=new Uint8Array(r.size),i=r.size,u=r.dtype,e=r.isCContiguous;if(c(u))if(e){const n=r.data,f=r.offset;for(let a=0;a<i;a++){const[s,l]=d(n,f+a);o[a]=s!==t||l!==0?1:0}}else for(let n=0;n<i;n++){const f=r.iget(n);o[n]=f.re!==t||f.im!==0?1:0}else if(e){const n=r.data,f=r.offset;for(let a=0;a<i;a++)o[a]=n[f+a]!==t?1:0}else for(let n=0;n<i;n++)o[n]=Number(r.iget(n))!==t?1:0;return y.fromData(o,Array.from(r.shape),"bool")}function M(r,t,o,i){const u=new Uint8Array(r.size),e=r.size,n=i+o*Math.abs(t);if(r.isCContiguous){const f=r.data,a=r.offset;for(let s=0;s<e;s++){const l=Math.abs(Number(f[a+s])-t);u[s]=l<=n?1:0}}else for(let f=0;f<e;f++){const a=Math.abs(Number(r.iget(f))-t);u[f]=a<=n?1:0}return y.fromData(u,Array.from(r.shape),"bool")}export{V as allclose,W as arrayEquiv,P as equal,H as greater,J as greaterEqual,w as isclose,K as less,L as lessEqual,Q as notEqual};
1
+ import{ArrayStorage as m}from"../storage.js";import{isBigIntDType as D,isComplexDType as y}from"../dtype.js";import{elementwiseComparisonOp as A}from"../internal/compute.js";import{computeBroadcastShape as x,broadcastTo as C}from"../broadcasting.js";import{Complex as B}from"../complex.js";function d(t,r){return[t[r*2],t[r*2+1]]}function z(t,r){if(y(t.dtype))return d(t.data,r);const i=t.iget(r);return i instanceof B?[i.re,i.im]:[Number(i),0]}function S(t,r,i){const o=x([Array.from(t.shape),Array.from(r.shape)]);if(!o)throw new Error("Cannot broadcast arrays together");const s=C(t,o),u=C(r,o),e=o.reduce((f,c)=>f*c,1),n=m.empty(o,"bool"),a=n.data;for(let f=0;f<e;f++){const[c,l]=z(s,f),[h,b]=z(u,f);a[f]=i(c,l,h,b)?1:0}return n}function H(t,r){return typeof r=="number"?I(t,r):y(t.dtype)||y(r.dtype)?S(t,r,(i,o,s,u)=>i!==s?i>s:o>u):A(t,r,(i,o)=>i>o)}function J(t,r){return typeof r=="number"?N(t,r):y(t.dtype)||y(r.dtype)?S(t,r,(i,o,s,u)=>i!==s?i>=s:o>=u):A(t,r,(i,o)=>i>=o)}function K(t,r){return typeof r=="number"?U(t,r):y(t.dtype)||y(r.dtype)?S(t,r,(i,o,s,u)=>i!==s?i<s:o<u):A(t,r,(i,o)=>i<o)}function L(t,r){return typeof r=="number"?q(t,r):y(t.dtype)||y(r.dtype)?S(t,r,(i,o,s,u)=>i!==s?i<=s:o<=u):A(t,r,(i,o)=>i<=o)}function P(t,r){return typeof r=="number"?M(t,r):y(t.dtype)||y(r.dtype)?S(t,r,(i,o,s,u)=>i===s&&o===u):A(t,r,(i,o)=>i===o)}function Q(t,r){return typeof r=="number"?E(t,r):y(t.dtype)||y(r.dtype)?S(t,r,(i,o,s,u)=>i!==s||o!==u):A(t,r,(i,o)=>i!==o)}function v(t,r,i=1e-5,o=1e-8){return typeof r=="number"?w(t,r,i,o):y(t.dtype)||typeof r!="number"&&y(r.dtype)?S(t,r,(s,u,e,n)=>{const a=s-e,f=u-n,c=Math.hypot(a,f),l=Math.hypot(e,n);return c<=o+i*l}):A(t,r,(s,u)=>{const e=Math.abs(s-u),n=o+i*Math.abs(u);return e<=n})}function V(t,r,i=1e-5,o=1e-8){const s=v(t,r,i,o),u=s.data;for(let e=0;e<s.size;e++)if(u[e]===0)return!1;return!0}function W(t,r){const i=[Array.from(t.shape),Array.from(r.shape)],o=x(i);if(o===null)return!1;const s=C(t,o),u=C(r,o),e=o.length,n=o.reduce((c,l)=>c*l,1),a=D(s.dtype),f=D(u.dtype);for(let c=0;c<n;c++){let l=c;const h=new Array(e);for(let p=e-1;p>=0;p--)h[p]=l%o[p],l=Math.floor(l/o[p]);const b=s.get(...h),g=u.get(...h);if(a||f){const p=typeof b=="bigint"?b:BigInt(Number(b)),F=typeof g=="bigint"?g:BigInt(Number(g));if(p!==F)return!1}else if(b!==g)return!1}return!0}function I(t,r){const i=m.empty(Array.from(t.shape),"bool"),o=i.data,s=t.size,u=t.isCContiguous;if(y(t.dtype))if(u){const e=t.data,n=t.offset;for(let a=0;a<s;a++){const[f,c]=d(e,n+a);o[a]=(f!==r?f>r:c>0)?1:0}}else for(let e=0;e<s;e++){const n=t.iget(e);o[e]=(n.re!==r?n.re>r:n.im>0)?1:0}else if(u){const e=t.data,n=t.offset;for(let a=0;a<s;a++)o[a]=e[n+a]>r?1:0}else for(let e=0;e<s;e++)o[e]=Number(t.iget(e))>r?1:0;return i}function N(t,r){const i=m.empty(Array.from(t.shape),"bool"),o=i.data,s=t.size,u=t.isCContiguous;if(y(t.dtype))if(u){const e=t.data,n=t.offset;for(let a=0;a<s;a++){const[f,c]=d(e,n+a);o[a]=(f!==r?f>=r:c>=0)?1:0}}else for(let e=0;e<s;e++){const n=t.iget(e);o[e]=(n.re!==r?n.re>=r:n.im>=0)?1:0}else if(u){const e=t.data,n=t.offset;for(let a=0;a<s;a++)o[a]=e[n+a]>=r?1:0}else for(let e=0;e<s;e++)o[e]=Number(t.iget(e))>=r?1:0;return i}function U(t,r){const i=m.empty(Array.from(t.shape),"bool"),o=i.data,s=t.size,u=t.isCContiguous;if(y(t.dtype))if(u){const e=t.data,n=t.offset;for(let a=0;a<s;a++){const[f,c]=d(e,n+a);o[a]=(f!==r?f<r:c<0)?1:0}}else for(let e=0;e<s;e++){const n=t.iget(e);o[e]=(n.re!==r?n.re<r:n.im<0)?1:0}else if(u){const e=t.data,n=t.offset;for(let a=0;a<s;a++)o[a]=e[n+a]<r?1:0}else for(let e=0;e<s;e++)o[e]=Number(t.iget(e))<r?1:0;return i}function q(t,r){const i=m.empty(Array.from(t.shape),"bool"),o=i.data,s=t.size,u=t.isCContiguous;if(y(t.dtype))if(u){const e=t.data,n=t.offset;for(let a=0;a<s;a++){const[f,c]=d(e,n+a);o[a]=(f!==r?f<=r:c<=0)?1:0}}else for(let e=0;e<s;e++){const n=t.iget(e);o[e]=(n.re!==r?n.re<=r:n.im<=0)?1:0}else if(u){const e=t.data,n=t.offset;for(let a=0;a<s;a++)o[a]=e[n+a]<=r?1:0}else for(let e=0;e<s;e++)o[e]=Number(t.iget(e))<=r?1:0;return i}function M(t,r){const i=m.empty(Array.from(t.shape),"bool"),o=i.data,s=t.size,u=t.dtype,e=t.isCContiguous;if(y(u))if(e){const n=t.data,a=t.offset;for(let f=0;f<s;f++){const[c,l]=d(n,a+f);o[f]=c===r&&l===0?1:0}}else for(let n=0;n<s;n++){const a=t.iget(n);o[n]=a.re===r&&a.im===0?1:0}else if(D(u)){const n=BigInt(Math.round(r));if(e){const a=t.data,f=t.offset;for(let c=0;c<s;c++)o[c]=a[f+c]===n?1:0}else for(let a=0;a<s;a++)o[a]=t.iget(a)===n?1:0}else if(e){const n=t.data,a=t.offset;for(let f=0;f<s;f++)o[f]=n[a+f]===r?1:0}else for(let n=0;n<s;n++)o[n]=Number(t.iget(n))===r?1:0;return i}function E(t,r){const i=m.empty(Array.from(t.shape),"bool"),o=i.data,s=t.size,u=t.dtype,e=t.isCContiguous;if(y(u))if(e){const n=t.data,a=t.offset;for(let f=0;f<s;f++){const[c,l]=d(n,a+f);o[f]=c!==r||l!==0?1:0}}else for(let n=0;n<s;n++){const a=t.iget(n);o[n]=a.re!==r||a.im!==0?1:0}else if(e){const n=t.data,a=t.offset;for(let f=0;f<s;f++)o[f]=n[a+f]!==r?1:0}else for(let n=0;n<s;n++)o[n]=Number(t.iget(n))!==r?1:0;return i}function w(t,r,i,o){const s=m.empty(Array.from(t.shape),"bool"),u=s.data,e=t.size,n=o+i*Math.abs(r);if(t.isCContiguous){const a=t.data,f=t.offset;for(let c=0;c<e;c++){const l=Math.abs(Number(a[f+c])-r);u[c]=l<=n?1:0}}else for(let a=0;a<e;a++){const f=Math.abs(Number(t.iget(a))-r);u[a]=f<=n?1:0}return s}export{V as allclose,W as arrayEquiv,P as equal,H as greater,J as greaterEqual,v as isclose,K as less,L as lessEqual,Q as notEqual};
@@ -1 +1 @@
1
- import{ArrayStorage as i}from"../storage";import{isComplexDType as A,getComplexComponentDType as u,getTypedArrayConstructor as m}from"../dtype";import{Complex as D}from"../complex";function z(r){const a=r.dtype,n=Array.from(r.shape),y=r.size;if(A(a)){const c=u(a),s=i.zeros(n,c),e=s.data,o=r.data;for(let t=0;t<y;t++)e[t]=o[t*2];return s}return r.copy()}function S(r){const a=r.dtype,n=Array.from(r.shape),y=r.size;if(A(a)){const s=u(a),e=i.zeros(n,s),o=e.data,t=r.data;for(let l=0;l<y;l++)o[l]=t[l*2+1];return e}const c=a==="float32"?"float32":"float64";return i.zeros(n,c)}function F(r){const a=r.dtype,n=Array.from(r.shape),y=r.size;if(A(a)){const c=m(a),s=y*2,e=new c(s),o=r.data;for(let t=0;t<y;t++)e[t*2]=o[t*2],e[t*2+1]=-o[t*2+1];return i.fromData(e,n,a)}return r.copy()}const x=F;function T(r,a=!1){const n=r.dtype,y=Array.from(r.shape),c=r.size,s=i.zeros(y,"float64"),e=s.data;if(A(n)){const o=r.data;for(let t=0;t<c;t++){const l=o[t*2],p=o[t*2+1];let f=Math.atan2(p,l);a&&(f=f*180/Math.PI),e[t]=f}}else for(let o=0;o<c;o++){const t=r.iget(o);let p=(t instanceof D?t.re:Number(t))>=0?0:Math.PI;a&&(p=p*180/Math.PI),e[o]=p}return s}function C(r){const a=r.dtype,n=Array.from(r.shape),y=r.size,c=A(a)?u(a):a,s=i.zeros(n,c),e=s.data;if(A(a)){const o=r.data;for(let t=0;t<y;t++){const l=o[t*2],p=o[t*2+1];e[t]=Math.sqrt(l*l+p*p)}}return s}export{T as angle,C as complexAbs,F as conj,x as conjugate,S as imag,z as real};
1
+ import{ArrayStorage as f}from"../storage.js";import{isComplexDType as c,getComplexComponentDType as h,mathResultDtype as C}from"../dtype.js";import{Complex as T}from"../complex.js";function v(r){const t=r.dtype;if(c(t)){const e=h(t),s=Array.from(r.strides).map(a=>a*2);return f.fromDataShared(r.data,Array.from(r.shape),e,s,r.offset*2,r.wasmRegion)}return r.copy()}function w(r){const t=r.dtype;if(c(t)){const s=h(t),a=Array.from(r.strides).map(l=>l*2);return f.fromDataShared(r.data,Array.from(r.shape),s,a,r.offset*2+1,r.wasmRegion)}const e=Array.from(r.shape);return f.zeros(e,t)}function M(r){const t=r.dtype,e=Array.from(r.shape),s=r.size;if(c(t)){const a=f.empty(e,t),l=a.data,p=r.data;for(let n=0;n<s;n++)l[n*2]=p[n*2],l[n*2+1]=-p[n*2+1];return a}if(t==="bool"){const a=f.empty(e,"int8"),l=r.data,p=a.data,n=r.offset;for(let o=0;o<s;o++)p[o]=l[n+o];return a}return r.copy()}const V=M;function q(r,t=!1){const e=r.dtype,s=Array.from(r.shape),a=r.size,l=c(e)?h(e):e==="bool"?"float64":C(e),p=f.empty(s,l),n=p.data;if(c(e)){const o=r.data;for(let y=0;y<a;y++){const A=o[y*2],i=o[y*2+1];let b=Math.atan2(i,A);t&&(b=b*180/Math.PI),n[y]=b}}else for(let o=0;o<a;o++){const y=r.iget(o);let i=(y instanceof T?y.re:Number(y))>=0?0:Math.PI;t&&(i=i*180/Math.PI),n[o]=i}return p}function G(r){const t=r.dtype,e=Array.from(r.shape),s=r.size,a=c(t)?h(t):t;if(c(t)){const l=f.empty(e,a),p=l.data,n=r.data;for(let o=0;o<s;o++){const y=n[o*2],A=n[o*2+1];p[o]=Math.sqrt(y*y+A*A)}return l}return f.zeros(e,a)}function z(r,t){return[r[t*2],r[t*2+1]]}function N(r,t,e,s){r[t*2]=e,r[t*2+1]=s}function I(r,t,e,s){return r!==e?r>e:t>s}function O(r,t,e){const s=r.dtype,a=r.size,l=Array.from(r.shape),p=f.empty(l,s),n=p.data,o=r.data,y=r.offset,A=t===null||typeof t=="number",i=e===null||typeof e=="number",b=!A&&c(t.dtype),x=!i&&c(e.dtype);for(let u=0;u<a;u++){let[D,F]=z(o,y+u),m,g;t===null?(m=-1/0,g=-1/0):typeof t=="number"?(m=t,g=0):b?[m,g]=z(t.data,t.offset+u%t.size):(m=Number(t.data[t.offset+u%t.size]),g=0);let d,S;e===null?(d=1/0,S=1/0):typeof e=="number"?(d=e,S=0):x?[d,S]=z(e.data,e.offset+u%e.size):(d=Number(e.data[e.offset+u%e.size]),S=0),I(m,g,D,F)&&(D=m,F=g),I(D,F,d,S)&&(D=d,F=S),N(n,u,D,F)}return p}export{q as angle,O as clipComplex,G as complexAbs,I as complexGreater,M as conj,V as conjugate,z as getComplexAt,w as imag,v as real,N as setComplexAt};