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.
- package/README.md +3 -11
- package/dist/esm/common/broadcasting.js +1 -1
- package/dist/esm/common/dtype.js +1 -1
- package/dist/esm/common/float16-conv.js +1 -0
- package/dist/esm/common/internal/compute.js +1 -1
- package/dist/esm/common/internal/indexing.js +1 -1
- package/dist/esm/common/ndarray-core.js +1 -1
- package/dist/esm/common/ops/advanced.js +1 -1
- package/dist/esm/common/ops/arithmetic.js +1 -1
- package/dist/esm/common/ops/bitwise.js +1 -1
- package/dist/esm/common/ops/comparison.js +1 -1
- package/dist/esm/common/ops/complex.js +1 -1
- package/dist/esm/common/ops/exponential.js +1 -1
- package/dist/esm/common/ops/fft.js +1 -1
- package/dist/esm/common/ops/formatting.js +1 -1
- package/dist/esm/common/ops/gradient.js +1 -1
- package/dist/esm/common/ops/hyperbolic.js +1 -1
- package/dist/esm/common/ops/linalg.js +2 -2
- package/dist/esm/common/ops/logic.js +1 -1
- package/dist/esm/common/ops/random.js +1 -1
- package/dist/esm/common/ops/reduction.js +1 -1
- package/dist/esm/common/ops/rounding.js +1 -1
- package/dist/esm/common/ops/sets.js +1 -1
- package/dist/esm/common/ops/shape.js +1 -1
- package/dist/esm/common/ops/sorting.js +1 -1
- package/dist/esm/common/ops/statistics.js +1 -1
- package/dist/esm/common/ops/trig.js +1 -1
- package/dist/esm/common/storage.js +1 -1
- package/dist/esm/common/wasm/abs.js +1 -1
- package/dist/esm/common/wasm/add.js +1 -1
- package/dist/esm/common/wasm/all_finite.js +1 -0
- package/dist/esm/common/wasm/arccos.js +1 -1
- package/dist/esm/common/wasm/arcsin.js +1 -1
- package/dist/esm/common/wasm/arctan.js +1 -1
- package/dist/esm/common/wasm/arctan2.js +1 -0
- package/dist/esm/common/wasm/argpartition.js +1 -1
- package/dist/esm/common/wasm/argsort.js +1 -1
- package/dist/esm/common/wasm/bins/abs.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/add.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/all_finite.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/alloc.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/arccos.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/arcsin.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/arctan.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/arctan2.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/argpartition.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/argsort.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/bitwise_and.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/bitwise_count.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/bitwise_not.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/bitwise_or.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/bitwise_xor.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/cholesky.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/clip.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/convolve.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/copysign.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/correlate.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/cos.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/cosh.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/cross.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/diff.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/divide.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/divmod.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/dot_float-relaxed.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/dot_float.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/dot_int.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/exp.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/exp2.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/fft.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/frexp.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/gather.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/gcd.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/gradient.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/heaviside.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/hypot.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/indices.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/inner_float-relaxed.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/inner_float.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/inner_int.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/isfinite.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/isnan.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/kron.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/ldexp.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/left_shift.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/lexsort.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/logaddexp.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/logical_and.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/logical_not.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/logical_or.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/logical_xor.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/lu.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/matmul_float-relaxed.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/matmul_float.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/matmul_int.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/matvec_float-relaxed.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/matvec_float.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/matvec_int.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/max.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/min.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/mul.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/neg.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/outer.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/pad.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/partition.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/power.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/qr.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/reciprocal.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/reduce_all.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/reduce_any.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/reduce_argmax.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/reduce_argmin.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/reduce_count_nz.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/reduce_max.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/reduce_mean.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/reduce_min.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/reduce_nanmax.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/reduce_nanmin.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/reduce_nansum.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/reduce_prod.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/reduce_std.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/reduce_sum.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/reduce_var.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/repeat.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/right_shift.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/rng.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/roll.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/searchsorted.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/sign.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/signbit.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/sin.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/sinh.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/sort.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/sqrt.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/square.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/sub.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/svd.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/tan.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/tanh.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/tile.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/unravel_index.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/vdot.wasm.js +1 -1
- package/dist/esm/common/wasm/bins/vecdot_float-relaxed.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/vecdot_float.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/vecdot_int.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/vecmat_float-relaxed.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/vecmat_float.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/vecmat_int.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/vector_norm-relaxed.wasm.js +1 -0
- package/dist/esm/common/wasm/bins/vector_norm.wasm.js +1 -0
- package/dist/esm/common/wasm/bitwise_and.js +1 -1
- package/dist/esm/common/wasm/bitwise_count.js +1 -1
- package/dist/esm/common/wasm/bitwise_not.js +1 -1
- package/dist/esm/common/wasm/bitwise_or.js +1 -1
- package/dist/esm/common/wasm/bitwise_xor.js +1 -1
- package/dist/esm/common/wasm/cholesky.js +1 -1
- package/dist/esm/common/wasm/clip.js +1 -1
- package/dist/esm/common/wasm/config.js +1 -1
- package/dist/esm/common/wasm/convolve.js +1 -1
- package/dist/esm/common/wasm/copysign.js +1 -1
- package/dist/esm/common/wasm/correlate.js +1 -1
- package/dist/esm/common/wasm/cos.js +1 -1
- package/dist/esm/common/wasm/cosh.js +1 -1
- package/dist/esm/common/wasm/cross.js +1 -1
- package/dist/esm/common/wasm/detect.js +1 -0
- package/dist/esm/common/wasm/diff.js +1 -1
- package/dist/esm/common/wasm/divide.js +1 -1
- package/dist/esm/common/wasm/divmod.js +1 -0
- package/dist/esm/common/wasm/dot.js +1 -1
- package/dist/esm/common/wasm/exp.js +1 -1
- package/dist/esm/common/wasm/exp2.js +1 -1
- package/dist/esm/common/wasm/fft.js +1 -1
- package/dist/esm/common/wasm/frexp.js +1 -1
- package/dist/esm/common/wasm/gather.js +1 -1
- package/dist/esm/common/wasm/gcd.js +1 -1
- package/dist/esm/common/wasm/gradient.js +1 -1
- package/dist/esm/common/wasm/heaviside.js +1 -1
- package/dist/esm/common/wasm/hypot.js +1 -1
- package/dist/esm/common/wasm/indices.js +1 -1
- package/dist/esm/common/wasm/inner.js +1 -1
- package/dist/esm/common/wasm/isfinite.js +1 -0
- package/dist/esm/common/wasm/isnan.js +1 -0
- package/dist/esm/common/wasm/kron.js +1 -1
- package/dist/esm/common/wasm/ldexp.js +1 -1
- package/dist/esm/common/wasm/left_shift.js +1 -1
- package/dist/esm/common/wasm/lexsort.js +1 -1
- package/dist/esm/common/wasm/logaddexp.js +1 -1
- package/dist/esm/common/wasm/logical_and.js +1 -1
- package/dist/esm/common/wasm/logical_not.js +1 -1
- package/dist/esm/common/wasm/logical_or.js +1 -1
- package/dist/esm/common/wasm/logical_xor.js +1 -1
- package/dist/esm/common/wasm/lu.js +1 -0
- package/dist/esm/common/wasm/matmul.js +1 -1
- package/dist/esm/common/wasm/matvec.js +1 -1
- package/dist/esm/common/wasm/max.js +1 -1
- package/dist/esm/common/wasm/min.js +1 -1
- package/dist/esm/common/wasm/mul.js +1 -1
- package/dist/esm/common/wasm/neg.js +1 -1
- package/dist/esm/common/wasm/outer.js +1 -1
- package/dist/esm/common/wasm/pad.js +1 -1
- package/dist/esm/common/wasm/partition.js +1 -1
- package/dist/esm/common/wasm/power.js +1 -1
- package/dist/esm/common/wasm/qr.js +1 -1
- package/dist/esm/common/wasm/reciprocal.js +1 -1
- package/dist/esm/common/wasm/reduce_all.js +1 -1
- package/dist/esm/common/wasm/reduce_any.js +1 -1
- package/dist/esm/common/wasm/reduce_argmax.js +1 -1
- package/dist/esm/common/wasm/reduce_argmin.js +1 -1
- package/dist/esm/common/wasm/reduce_count_nz.js +1 -1
- package/dist/esm/common/wasm/reduce_max.js +1 -1
- package/dist/esm/common/wasm/reduce_mean.js +1 -1
- package/dist/esm/common/wasm/reduce_min.js +1 -1
- package/dist/esm/common/wasm/reduce_nanmax.js +1 -1
- package/dist/esm/common/wasm/reduce_nanmin.js +1 -1
- package/dist/esm/common/wasm/reduce_nansum.js +1 -1
- package/dist/esm/common/wasm/reduce_prod.js +1 -1
- package/dist/esm/common/wasm/reduce_quantile.js +1 -1
- package/dist/esm/common/wasm/reduce_std.js +1 -1
- package/dist/esm/common/wasm/reduce_sum.js +1 -1
- package/dist/esm/common/wasm/reduce_var.js +1 -1
- package/dist/esm/common/wasm/repeat.js +1 -1
- package/dist/esm/common/wasm/right_shift.js +1 -1
- package/dist/esm/common/wasm/rng.js +1 -0
- package/dist/esm/common/wasm/roll.js +1 -1
- package/dist/esm/common/wasm/runtime.js +1 -1
- package/dist/esm/common/wasm/searchsorted.js +1 -1
- package/dist/esm/common/wasm/sign.js +1 -1
- package/dist/esm/common/wasm/signbit.js +1 -0
- package/dist/esm/common/wasm/sin.js +1 -0
- package/dist/esm/common/wasm/sinh.js +1 -1
- package/dist/esm/common/wasm/sort.js +1 -1
- package/dist/esm/common/wasm/sqrt.js +1 -1
- package/dist/esm/common/wasm/square.js +1 -1
- package/dist/esm/common/wasm/sub.js +1 -1
- package/dist/esm/common/wasm/svd.js +1 -1
- package/dist/esm/common/wasm/tan.js +1 -1
- package/dist/esm/common/wasm/tanh.js +1 -1
- package/dist/esm/common/wasm/tile.js +1 -1
- package/dist/esm/common/wasm/unravel_index.js +1 -0
- package/dist/esm/common/wasm/vdot.js +1 -1
- package/dist/esm/common/wasm/vecdot.js +1 -1
- package/dist/esm/common/wasm/vecmat.js +1 -1
- package/dist/esm/common/wasm/vector_norm.js +1 -0
- package/dist/esm/core/advanced.js +1 -1
- package/dist/esm/core/arithmetic.js +1 -1
- package/dist/esm/core/bitwise.js +1 -1
- package/dist/esm/core/complex.js +1 -1
- package/dist/esm/core/creation.js +1 -1
- package/dist/esm/core/formatting.js +1 -1
- package/dist/esm/core/gradient.js +1 -1
- package/dist/esm/core/index.js +1 -1
- package/dist/esm/core/linalg.js +1 -1
- package/dist/esm/core/logic.js +1 -1
- package/dist/esm/core/polynomial.js +1 -1
- package/dist/esm/core/reduction.js +1 -1
- package/dist/esm/core/rounding.js +1 -1
- package/dist/esm/core/sets.js +1 -1
- package/dist/esm/core/shape-extra.js +1 -1
- package/dist/esm/core/shape.js +1 -1
- package/dist/esm/core/sorting.js +1 -1
- package/dist/esm/core/statistics.js +1 -1
- package/dist/esm/core/trig.js +1 -1
- package/dist/esm/core/typechecking.js +1 -1
- package/dist/esm/core/types.js +1 -1
- package/dist/esm/core/utility.js +1 -1
- package/dist/esm/core.js +1 -1
- package/dist/esm/full/index.js +1 -1
- package/dist/esm/full/ndarray.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/io/file-ops.js +1 -0
- package/dist/esm/io/filesystem.js +1 -0
- package/dist/esm/io/index.js +1 -1
- package/dist/esm/io/npy/format.js +1 -1
- package/dist/esm/io/npy/index.js +1 -1
- package/dist/esm/io/npy/parser.js +1 -1
- package/dist/esm/io/npy/serializer.js +2 -2
- package/dist/esm/io/npz/index.js +1 -1
- package/dist/esm/io/npz/parser.js +1 -1
- package/dist/esm/io/npz/serializer.js +1 -1
- package/dist/esm/io/txt/index.js +1 -1
- package/dist/esm/io/txt/parser.js +1 -1
- package/dist/esm/io/zip/index.js +1 -1
- package/dist/esm/io/zip/reader.js +1 -1
- package/dist/esm/io/zip/writer.js +1 -1
- package/dist/esm/node.js +1 -1
- package/dist/numpy-ts.browser.js +6 -6
- package/dist/types/common/dtype.d.ts +55 -4
- package/dist/types/common/float16-conv.d.ts +27 -0
- package/dist/types/common/internal/indexing.d.ts +9 -21
- package/dist/types/common/ndarray-core.d.ts +20 -0
- package/dist/types/common/ops/advanced.d.ts +17 -2
- package/dist/types/common/ops/complex.d.ts +19 -1
- package/dist/types/common/ops/linalg.d.ts +1 -1
- package/dist/types/common/ops/random.d.ts +10 -5
- package/dist/types/common/ops/reduction.d.ts +2 -2
- package/dist/types/common/ops/sets.d.ts +2 -1
- package/dist/types/common/ops/shape.d.ts +2 -2
- package/dist/types/common/ops/statistics.d.ts +2 -1
- package/dist/types/common/storage.d.ts +54 -2
- package/dist/types/common/wasm/all_finite.d.ts +8 -0
- package/dist/types/common/wasm/arccos.d.ts +4 -2
- package/dist/types/common/wasm/arcsin.d.ts +4 -2
- package/dist/types/common/wasm/arctan.d.ts +4 -2
- package/dist/types/common/wasm/arctan2.d.ts +17 -0
- package/dist/types/common/wasm/argpartition.d.ts +8 -3
- package/dist/types/common/wasm/argsort.d.ts +8 -3
- package/dist/types/common/wasm/bins/abs.wasm.d.ts +1 -0
- package/dist/types/common/wasm/bins/all_finite.wasm.d.ts +4 -0
- package/dist/types/common/wasm/bins/alloc.wasm.d.ts +6 -0
- package/dist/types/common/wasm/bins/arccos.wasm.d.ts +8 -2
- package/dist/types/common/wasm/bins/arcsin.wasm.d.ts +8 -2
- package/dist/types/common/wasm/bins/arctan.wasm.d.ts +8 -2
- package/dist/types/common/wasm/bins/arctan2.wasm.d.ts +11 -0
- package/dist/types/common/wasm/bins/convolve.wasm.d.ts +6 -0
- package/dist/types/common/wasm/bins/copysign.wasm.d.ts +2 -0
- package/dist/types/common/wasm/bins/correlate.wasm.d.ts +6 -0
- package/dist/types/common/wasm/bins/cos.wasm.d.ts +8 -0
- package/dist/types/common/wasm/bins/cosh.wasm.d.ts +8 -2
- package/dist/types/common/wasm/bins/divmod.wasm.d.ts +11 -0
- package/dist/types/common/wasm/bins/dot_float-relaxed.wasm.d.ts +5 -0
- package/dist/types/common/wasm/bins/dot_float.wasm.d.ts +5 -0
- package/dist/types/common/wasm/bins/dot_int.wasm.d.ts +5 -0
- package/dist/types/common/wasm/bins/exp.wasm.d.ts +8 -2
- package/dist/types/common/wasm/bins/exp2.wasm.d.ts +8 -2
- package/dist/types/common/wasm/bins/fft.wasm.d.ts +11 -0
- package/dist/types/common/wasm/bins/frexp.wasm.d.ts +1 -0
- package/dist/types/common/wasm/bins/gather.wasm.d.ts +0 -1
- package/dist/types/common/wasm/bins/gcd.wasm.d.ts +8 -0
- package/dist/types/common/wasm/bins/indices.wasm.d.ts +6 -2
- package/dist/types/common/wasm/bins/inner_float-relaxed.wasm.d.ts +5 -0
- package/dist/types/common/wasm/bins/inner_float.wasm.d.ts +5 -0
- package/dist/types/common/wasm/bins/inner_int.wasm.d.ts +5 -0
- package/dist/types/common/wasm/bins/isfinite.wasm.d.ts +4 -0
- package/dist/types/common/wasm/bins/isnan.wasm.d.ts +4 -0
- package/dist/types/common/wasm/bins/lexsort.wasm.d.ts +4 -4
- package/dist/types/common/wasm/bins/logical_and.wasm.d.ts +2 -0
- package/dist/types/common/wasm/bins/logical_not.wasm.d.ts +1 -0
- package/dist/types/common/wasm/bins/logical_or.wasm.d.ts +2 -0
- package/dist/types/common/wasm/bins/logical_xor.wasm.d.ts +2 -0
- package/dist/types/common/wasm/bins/lu.wasm.d.ts +7 -0
- package/dist/types/common/wasm/bins/matmul_float-relaxed.wasm.d.ts +5 -0
- package/dist/types/common/wasm/bins/matmul_float.wasm.d.ts +5 -0
- package/dist/types/common/wasm/bins/matmul_int.wasm.d.ts +5 -0
- package/dist/types/common/wasm/bins/matvec_float-relaxed.wasm.d.ts +5 -0
- package/dist/types/common/wasm/bins/matvec_float.wasm.d.ts +5 -0
- package/dist/types/common/wasm/bins/matvec_int.wasm.d.ts +5 -0
- package/dist/types/common/wasm/bins/neg.wasm.d.ts +1 -0
- package/dist/types/common/wasm/bins/qr.wasm.d.ts +0 -1
- package/dist/types/common/wasm/bins/reciprocal.wasm.d.ts +8 -4
- package/dist/types/common/wasm/bins/reduce_argmax.wasm.d.ts +8 -0
- package/dist/types/common/wasm/bins/reduce_argmin.wasm.d.ts +8 -0
- package/dist/types/common/wasm/bins/reduce_max.wasm.d.ts +1 -0
- package/dist/types/common/wasm/bins/reduce_min.wasm.d.ts +1 -0
- package/dist/types/common/wasm/bins/reduce_prod.wasm.d.ts +2 -0
- package/dist/types/common/wasm/bins/reduce_sum.wasm.d.ts +8 -2
- package/dist/types/common/wasm/bins/rng.wasm.d.ts +57 -0
- package/dist/types/common/wasm/bins/sign.wasm.d.ts +1 -0
- package/dist/types/common/wasm/bins/signbit.wasm.d.ts +8 -0
- package/dist/types/common/wasm/bins/sin.wasm.d.ts +11 -0
- package/dist/types/common/wasm/bins/sinh.wasm.d.ts +8 -2
- package/dist/types/common/wasm/bins/sort.wasm.d.ts +6 -4
- package/dist/types/common/wasm/bins/sqrt.wasm.d.ts +2 -2
- package/dist/types/common/wasm/bins/svd.wasm.d.ts +1 -0
- package/dist/types/common/wasm/bins/tan.wasm.d.ts +8 -0
- package/dist/types/common/wasm/bins/tanh.wasm.d.ts +8 -2
- package/dist/types/common/wasm/bins/unravel_index.wasm.d.ts +4 -0
- package/dist/types/common/wasm/bins/vecdot_float-relaxed.wasm.d.ts +5 -0
- package/dist/types/common/wasm/bins/vecdot_float.wasm.d.ts +5 -0
- package/dist/types/common/wasm/bins/vecdot_int.wasm.d.ts +5 -0
- package/dist/types/common/wasm/bins/vecmat_float-relaxed.wasm.d.ts +5 -0
- package/dist/types/common/wasm/bins/vecmat_float.wasm.d.ts +5 -0
- package/dist/types/common/wasm/bins/vecmat_int.wasm.d.ts +5 -0
- package/dist/types/common/wasm/bins/vector_norm-relaxed.wasm.d.ts +3 -0
- package/dist/types/common/wasm/bins/vector_norm.wasm.d.ts +3 -0
- package/dist/types/common/wasm/config.d.ts +25 -0
- package/dist/types/common/wasm/convolve.d.ts +1 -1
- package/dist/types/common/wasm/cos.d.ts +4 -2
- package/dist/types/common/wasm/cosh.d.ts +4 -2
- package/dist/types/common/wasm/detect.d.ts +17 -0
- package/dist/types/common/wasm/divide.d.ts +4 -0
- package/dist/types/common/wasm/divmod.d.ts +13 -0
- package/dist/types/common/wasm/exp.d.ts +4 -2
- package/dist/types/common/wasm/exp2.d.ts +4 -2
- package/dist/types/common/wasm/fft.d.ts +36 -0
- package/dist/types/common/wasm/frexp.d.ts +1 -0
- package/dist/types/common/wasm/gather.d.ts +4 -0
- package/dist/types/common/wasm/gcd.d.ts +1 -0
- package/dist/types/common/wasm/heaviside.d.ts +2 -2
- package/dist/types/common/wasm/hypot.d.ts +4 -2
- package/dist/types/common/wasm/indices.d.ts +2 -1
- package/dist/types/common/wasm/isfinite.d.ts +7 -0
- package/dist/types/common/wasm/isnan.d.ts +7 -0
- package/dist/types/common/wasm/lexsort.d.ts +3 -1
- package/dist/types/common/wasm/logaddexp.d.ts +4 -2
- package/dist/types/common/wasm/lu.d.ts +27 -0
- package/dist/types/common/wasm/partition.d.ts +3 -1
- package/dist/types/common/wasm/reduce_argmax.d.ts +5 -0
- package/dist/types/common/wasm/reduce_argmin.d.ts +5 -0
- package/dist/types/common/wasm/reduce_prod.d.ts +4 -0
- package/dist/types/common/wasm/reduce_quantile.d.ts +11 -3
- package/dist/types/common/wasm/reduce_sum.d.ts +10 -0
- package/dist/types/common/wasm/rng.d.ts +75 -0
- package/dist/types/common/wasm/runtime.d.ts +117 -23
- package/dist/types/common/wasm/searchsorted.d.ts +3 -1
- package/dist/types/common/wasm/signbit.d.ts +14 -0
- package/dist/types/common/wasm/sin.d.ts +17 -0
- package/dist/types/common/wasm/sinh.d.ts +4 -2
- package/dist/types/common/wasm/sort.d.ts +4 -1
- package/dist/types/common/wasm/sqrt.d.ts +4 -2
- package/dist/types/common/wasm/svd.d.ts +6 -0
- package/dist/types/common/wasm/tan.d.ts +4 -2
- package/dist/types/common/wasm/tanh.d.ts +4 -2
- package/dist/types/common/wasm/unravel_index.d.ts +12 -0
- package/dist/types/common/wasm/vector_norm.d.ts +11 -0
- package/dist/types/core/advanced.d.ts +10 -2
- package/dist/types/core/creation.d.ts +1 -1
- package/dist/types/core/index.d.ts +96 -2
- package/dist/types/core/linalg.d.ts +1 -1
- package/dist/types/core/rounding.d.ts +0 -2
- package/dist/types/core/sets.d.ts +4 -1
- package/dist/types/core/statistics.d.ts +2 -1
- package/dist/types/full/index.d.ts +19 -6
- package/dist/types/index.d.ts +20 -4
- package/dist/types/io/file-ops.d.ts +269 -0
- package/dist/types/io/filesystem.d.ts +21 -0
- package/dist/types/node.d.ts +3 -275
- package/package.json +52 -62
- package/dist/esm/common/wasm/bins/dot.wasm.js +0 -1
- package/dist/esm/common/wasm/bins/flip.wasm.js +0 -1
- package/dist/esm/common/wasm/bins/inner.wasm.js +0 -1
- package/dist/esm/common/wasm/bins/matmul.wasm.js +0 -1
- package/dist/esm/common/wasm/bins/matvec.wasm.js +0 -1
- package/dist/esm/common/wasm/bins/reduce_quantile.wasm.js +0 -1
- package/dist/esm/common/wasm/bins/rot90.wasm.js +0 -1
- package/dist/esm/common/wasm/bins/vecdot.wasm.js +0 -1
- package/dist/esm/common/wasm/bins/vecmat.wasm.js +0 -1
- package/dist/esm/common/wasm/flip.js +0 -1
- package/dist/esm/common/wasm/lstsq.js +0 -1
- package/dist/esm/common/wasm/rot90.js +0 -1
- package/dist/numpy-ts.node-io.cjs +0 -8
- package/dist/numpy-ts.node-io.cjs.map +0 -7
- package/dist/numpy-ts.node-io.mjs +0 -8
- package/dist/numpy-ts.node-io.mjs.map +0 -7
- package/dist/numpy-ts.node.cjs +0 -8
- package/dist/numpy-ts.node.cjs.map +0 -7
- package/dist/types/common/wasm/bins/dot.wasm.d.ts +0 -9
- package/dist/types/common/wasm/bins/flip.wasm.d.ts +0 -7
- package/dist/types/common/wasm/bins/inner.wasm.d.ts +0 -9
- package/dist/types/common/wasm/bins/matmul.wasm.d.ts +0 -9
- package/dist/types/common/wasm/bins/matvec.wasm.d.ts +0 -9
- package/dist/types/common/wasm/bins/reduce_quantile.wasm.d.ts +0 -2
- package/dist/types/common/wasm/bins/rot90.wasm.d.ts +0 -7
- package/dist/types/common/wasm/bins/vecdot.wasm.d.ts +0 -9
- package/dist/types/common/wasm/bins/vecmat.wasm.d.ts +0 -9
- package/dist/types/common/wasm/flip.d.ts +0 -13
- package/dist/types/common/wasm/lstsq.d.ts +0 -14
- package/dist/types/common/wasm/rot90.d.ts +0 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ArrayStorage as O}from"../storage";import{isBigIntDType as L,isComplexDType as U,isFloatDType as H,throwIfComplex as ot}from"../dtype";import{computeStrides as k,precomputeAxisOffsets as P}from"../internal/indexing";import{Complex as Q}from"../complex";import{wasmReduceSum as bt,wasmReduceSumStrided as Nt}from"../wasm/reduce_sum";import{wasmReduceMax as St,wasmReduceMaxStrided as At}from"../wasm/reduce_max";import{wasmReduceMin as It,wasmReduceMinStrided as ht}from"../wasm/reduce_min";import{wasmReduceArgmax as zt}from"../wasm/reduce_argmax";import{wasmReduceArgmin as wt}from"../wasm/reduce_argmin";import{wasmReduceMean as Dt,wasmReduceMeanStrided as Ct}from"../wasm/reduce_mean";import{wasmReduceVar as Ft}from"../wasm/reduce_var";import{wasmReduceNansum as Rt}from"../wasm/reduce_nansum";import{wasmReduceNanmin as vt}from"../wasm/reduce_nanmin";import{wasmReduceNanmax as $t}from"../wasm/reduce_nanmax";import{wasmReduceProd as Bt,wasmReduceProdStrided as Et}from"../wasm/reduce_prod";import{wasmReduceQuantile as Ot}from"../wasm/reduce_quantile";import{wasmReduceAny as gt}from"../wasm/reduce_any";import{wasmReduceAll as Vt}from"../wasm/reduce_all";const W=new Float32Array(2);function st(t){switch(t){case"int8":case"int16":case"int32":return"int64";case"uint8":case"uint16":case"uint32":return"uint64";default:return t}}function Tt(t){switch(t){case"int8":case"int16":case"int32":case"uint8":case"uint16":case"uint32":case"int64":case"uint64":return"float64";default:return t}}function j(t,x,z){const u=O.zeros(Array(x).fill(1),z);return u.iset(0,t),u}function tt(t,x,z=!1){const u=t.dtype,m=t.shape,b=m.length,S=t.size,h=t.data,A=t.offset,R=t.strides,I=t.isCContiguous;if(x===void 0){const e=bt(t);if(e!==null)return e;if(U(u)){let o=0,i=0;if(I){const a=h;for(let s=0;s<S;s++)o+=a[(A+s)*2],i+=a[(A+s)*2+1]}else for(let a=0;a<S;a++){const s=t.iget(a);o+=s.re,i+=s.im}return new Q(o,i)}else if(L(u)){let o=BigInt(0);if(I){const i=h;for(let a=0;a<S;a++)o+=i[A+a]}else for(let i=0;i<S;i++)o+=t.iget(i);return Number(o)}else if(u==="float32"){if(W[0]=0,I)for(let o=0;o<S;o++)W[0]+=Number(h[A+o]);else for(let o=0;o<S;o++)W[0]+=Number(t.iget(o));return W[0]}else{let o=0;if(I)if(A===0)for(let i=0;i<S;i++)o+=Number(h[i]);else for(let i=0;i<S;i++)o+=Number(h[A+i]);else for(let i=0;i<S;i++)o+=Number(t.iget(i));return o}}let w=x;if(w<0&&(w=b+w),w<0||w>=b)throw new Error(`axis ${x} is out of bounds for array of dimension ${b}`);const v=st(u),D=Array.from(m).filter((e,o)=>o!==w);if(D.length===0){const e=tt(t);if(!z)return e;const o=O.zeros(Array(b).fill(1),v);return o.iset(0,e),o}const g=O.zeros(D,v),y=g.data,d=m[w],c=D.reduce((e,o)=>e*o,1);if(I&&!U(u)){const e=m.slice(0,w).reduce((a,s)=>a*s,1),o=m.slice(w+1).reduce((a,s)=>a*s,1),i=Nt(t,e,d,o);if(i){const a=z?m.map((p,f)=>f===w?1:p):D;if(v==="float64")return O.fromData(i.data,a,v);if(v==="float32"){const p=new Float32Array(i.data.length),f=i.data;for(let l=0;l<f.length;l++)p[l]=f[l];return O.fromData(p,a,v)}const s=i.data;for(let p=0;p<s.length;p++)y[p]=y instanceof BigInt64Array||y instanceof BigUint64Array?BigInt(Math.round(s[p])):s[p];return z?O.fromData(y,a,v):g}}const{baseOffsets:n,axisStride:r}=P(m,R,A,w,c);if(U(u)){const e=h,o=y;if(u==="complex64")for(let i=0;i<c;i++){W[0]=0,W[1]=0;let a=n[i];for(let s=0;s<d;s++)W[0]+=e[a*2],W[1]+=e[a*2+1],a+=r;o[i*2]=W[0],o[i*2+1]=W[1]}else for(let i=0;i<c;i++){let a=0,s=0,p=n[i];for(let f=0;f<d;f++)a+=e[p*2],s+=e[p*2+1],p+=r;o[i*2]=a,o[i*2+1]=s}}else if(L(u)){const e=h,o=y;for(let i=0;i<c;i++){let a=BigInt(0),s=n[i];for(let p=0;p<d;p++)a+=e[s],s+=r;o[i]=a}}else if(L(v)){const e=y;for(let o=0;o<c;o++){let i=0,a=n[o];for(let s=0;s<d;s++)i+=Number(h[a]),a+=r;e[o]=BigInt(Math.round(i))}}else if(u==="float32")for(let e=0;e<c;e++){W[0]=0;let o=n[e];for(let i=0;i<d;i++)W[0]+=Number(h[o]),o+=r;y[e]=W[0]}else for(let e=0;e<c;e++){let o=0,i=n[e];for(let a=0;a<d;a++)o+=Number(h[i]),i+=r;y[e]=o}if(z){const e=[...m];return e[w]=1,O.fromData(y,e,v)}return g}function nt(t,x,z=!1){const u=t.dtype,m=t.shape;if(x===void 0){const D=Dt(t);if(D!==null)return D;const g=tt(t);return g instanceof Q?new Q(g.re/t.size,g.im/t.size):g/t.size}let b=x;if(b<0&&(b=m.length+b),b<0||b>=m.length)throw new Error(`axis ${x} is out of bounds for array of dimension ${m.length}`);if(t.isCContiguous&&!U(u)){const D=m[b],g=z?m.map((n,r)=>r===b?1:n):Array.from(m).filter((n,r)=>r!==b),y=m.slice(0,b).reduce((n,r)=>n*r,1),d=m.slice(b+1).reduce((n,r)=>n*r,1),c=Ct(t,y,D,d);if(c)return O.fromData(c.data,g,"float64")}const S=tt(t,x,z);if(typeof S=="number")return S/m[b];if(S instanceof Q)return new Q(S.re/m[b],S.im/m[b]);const h=m[b],A=Tt(u),R=O.zeros(Array.from(S.shape),A),I=R.data,w=S.data,v=S.dtype;if(U(u)){const D=w,g=I,y=S.size;for(let d=0;d<y;d++)g[d*2]=D[d*2]/h,g[d*2+1]=D[d*2+1]/h}else if(L(v)){const D=w;for(let g=0;g<I.length;g++)I[g]=Number(D[g])/h}else for(let D=0;D<I.length;D++)I[D]=Number(w[D])/h;return R}function Y(t,x,z=!1){const u=t.dtype,m=t.shape,b=m.length,S=t.size,h=t.data,A=t.offset,R=t.strides;if(U(u)){const n=h;if(x===void 0){if(S===0)throw new Error("max of empty array");let l=n[A*2],N=n[A*2+1];for(let C=1;C<S;C++){const B=n[(A+C)*2],F=n[(A+C)*2+1];if(isNaN(B)||isNaN(F))return new Q(NaN,NaN);(B>l||B===l&&F>N)&&(l=B,N=F)}return isNaN(l)||isNaN(N)?new Q(NaN,NaN):new Q(l,N)}let r=x;if(r<0&&(r=b+r),r<0||r>=b)throw new Error(`axis ${x} is out of bounds for array of dimension ${b}`);const e=Array.from(m).filter((l,N)=>N!==r);if(e.length===0){const l=Y(t);return z?j(l,b,u):l}const o=O.zeros(e,u),i=o.data,a=m[r],s=e.reduce((l,N)=>l*N,1),{baseOffsets:p,axisStride:f}=P(m,R,A,r,s);for(let l=0;l<s;l++){let N=p[l],C=n[N*2],B=n[N*2+1];N+=f;for(let F=1;F<a;F++){const $=n[N*2],E=n[N*2+1];if(N+=f,isNaN($)||isNaN(E)){C=NaN,B=NaN;break}($>C||$===C&&E>B)&&(C=$,B=E)}i[l*2]=C,i[l*2+1]=B}if(z){const l=[...m];return l[r]=1,O.fromData(i,l,u)}return o}if(x===void 0){const n=St(t);if(n!==null)return n;if(S===0)throw new Error("max of empty array");if(t.isCContiguous){let r=h[A];if(A===0)for(let e=1;e<S;e++)h[e]>r&&(r=h[e]);else for(let e=1;e<S;e++)h[A+e]>r&&(r=h[A+e]);return Number(r)}else{let r=t.iget(0);for(let e=1;e<S;e++){const o=t.iget(e);o>r&&(r=o)}return Number(r)}}let I=x;if(I<0&&(I=b+I),I<0||I>=b)throw new Error(`axis ${x} is out of bounds for array of dimension ${b}`);const w=Array.from(m).filter((n,r)=>r!==I);if(w.length===0){const n=Y(t);return z?j(n,b,u):n}const v=O.zeros(w,u),D=v.data,g=m[I],y=w.reduce((n,r)=>n*r,1);if(t.isCContiguous&&!U(u)){const n=m.slice(0,I).reduce((o,i)=>o*i,1),r=m.slice(I+1).reduce((o,i)=>o*i,1),e=At(t,n,g,r);if(e){const o=z?m.map((i,a)=>a===I?1:i):w;return O.fromData(e.data,o,u)}}const{baseOffsets:d,axisStride:c}=P(m,R,A,I,y);if(L(u)){const n=h,r=D;for(let e=0;e<y;e++){let o=d[e],i=n[o];o+=c;for(let a=1;a<g;a++){const s=n[o];s>i&&(i=s),o+=c}r[e]=i}}else for(let n=0;n<y;n++){let r=-1/0,e=d[n];for(let o=0;o<g;o++){const i=Number(h[e]);i>r&&(r=i),e+=c}D[n]=r}if(z){const n=[...m];return n[I]=1,O.fromData(D,n,u)}return v}function at(t,x,z=!1){const u=t.dtype,m=t.shape,b=m.length,S=t.size,h=t.data,A=t.offset,R=t.strides,I=t.isCContiguous;if(x===void 0){const e=Bt(t);if(e!==null)return e;if(U(u)){let o=1,i=0;if(I){const a=h;for(let s=0;s<S;s++){const p=a[(A+s)*2],f=a[(A+s)*2+1],l=o*p-i*f,N=o*f+i*p;o=l,i=N}}else for(let a=0;a<S;a++){const s=t.iget(a),p=s.re,f=s.im,l=o*p-i*f,N=o*f+i*p;o=l,i=N}return new Q(o,i)}else if(L(u)){let o=BigInt(1);if(I){const i=h;for(let a=0;a<S;a++)o*=i[A+a]}else for(let i=0;i<S;i++)o*=t.iget(i);return Number(o)}else if(u==="float32"){if(W[0]=1,I)for(let o=0;o<S;o++)W[0]*=Number(h[A+o]);else for(let o=0;o<S;o++)W[0]*=Number(t.iget(o));return W[0]}else{let o=1;if(I)if(A===0)for(let i=0;i<S;i++)o*=Number(h[i]);else for(let i=0;i<S;i++)o*=Number(h[A+i]);else for(let i=0;i<S;i++)o*=Number(t.iget(i));return o}}let w=x;if(w<0&&(w=b+w),w<0||w>=b)throw new Error(`axis ${x} is out of bounds for array of dimension ${b}`);const v=st(u),D=Array.from(m).filter((e,o)=>o!==w);if(D.length===0){const e=at(t);return z?j(e,b,v):e}const g=O.zeros(D,v),y=g.data,d=m[w],c=D.reduce((e,o)=>e*o,1);if(I&&!U(u)){const e=m.slice(0,w).reduce((a,s)=>a*s,1),o=m.slice(w+1).reduce((a,s)=>a*s,1),i=Et(t,e,d,o);if(i){const a=z?m.map((s,p)=>p===w?1:s):D;return O.fromData(i.data,a,v)}}const{baseOffsets:n,axisStride:r}=P(m,R,A,w,c);if(U(u)){const e=h,o=y;if(u==="complex64")for(let i=0;i<c;i++){W[0]=1,W[1]=0;let a=n[i];for(let s=0;s<d;s++){const p=e[a*2],f=e[a*2+1],l=W[0],N=W[1];W[0]=l*p-N*f,W[1]=l*f+N*p,a+=r}o[i*2]=W[0],o[i*2+1]=W[1]}else for(let i=0;i<c;i++){let a=1,s=0,p=n[i];for(let f=0;f<d;f++){const l=e[p*2],N=e[p*2+1],C=a*l-s*N,B=a*N+s*l;a=C,s=B,p+=r}o[i*2]=a,o[i*2+1]=s}}else if(L(u)){const e=h,o=y;for(let i=0;i<c;i++){let a=BigInt(1),s=n[i];for(let p=0;p<d;p++)a*=e[s],s+=r;o[i]=a}}else if(L(v)){const e=y;for(let o=0;o<c;o++){let i=BigInt(1),a=n[o];for(let s=0;s<d;s++)i*=BigInt(Number(h[a])),a+=r;e[o]=i}}else if(u==="float32")for(let e=0;e<c;e++){W[0]=1;let o=n[e];for(let i=0;i<d;i++)W[0]*=Number(h[o]),o+=r;y[e]=W[0]}else for(let e=0;e<c;e++){let o=1,i=n[e];for(let a=0;a<d;a++)o*=Number(h[i]),i+=r;y[e]=o}if(z){const e=[...m];return e[w]=1,O.fromData(y,e,v)}return g}function Z(t,x,z=!1){const u=t.dtype,m=t.shape,b=m.length,S=t.size,h=t.data,A=t.offset,R=t.strides;if(U(u)){const n=h;if(x===void 0){if(S===0)throw new Error("min of empty array");let l=n[A*2],N=n[A*2+1];for(let C=1;C<S;C++){const B=n[(A+C)*2],F=n[(A+C)*2+1];if(isNaN(B)||isNaN(F))return new Q(NaN,NaN);(B<l||B===l&&F<N)&&(l=B,N=F)}return isNaN(l)||isNaN(N)?new Q(NaN,NaN):new Q(l,N)}let r=x;if(r<0&&(r=b+r),r<0||r>=b)throw new Error(`axis ${x} is out of bounds for array of dimension ${b}`);const e=Array.from(m).filter((l,N)=>N!==r);if(e.length===0){const l=Z(t);return z?j(l,b,u):l}const o=O.zeros(e,u),i=o.data,a=m[r],s=e.reduce((l,N)=>l*N,1),{baseOffsets:p,axisStride:f}=P(m,R,A,r,s);for(let l=0;l<s;l++){let N=p[l],C=n[N*2],B=n[N*2+1];N+=f;for(let F=1;F<a;F++){const $=n[N*2],E=n[N*2+1];if(N+=f,isNaN($)||isNaN(E)){C=NaN,B=NaN;break}($<C||$===C&&E<B)&&(C=$,B=E)}i[l*2]=C,i[l*2+1]=B}if(z){const l=[...m];return l[r]=1,O.fromData(i,l,u)}return o}if(x===void 0){const n=It(t);if(n!==null)return n;if(S===0)throw new Error("min of empty array");if(t.isCContiguous){let r=h[A];if(A===0)for(let e=1;e<S;e++)h[e]<r&&(r=h[e]);else for(let e=1;e<S;e++)h[A+e]<r&&(r=h[A+e]);return Number(r)}else{let r=t.iget(0);for(let e=1;e<S;e++){const o=t.iget(e);o<r&&(r=o)}return Number(r)}}let I=x;if(I<0&&(I=b+I),I<0||I>=b)throw new Error(`axis ${x} is out of bounds for array of dimension ${b}`);const w=Array.from(m).filter((n,r)=>r!==I);if(w.length===0){const n=Z(t);return z?j(n,b,u):n}const v=O.zeros(w,u),D=v.data,g=m[I],y=w.reduce((n,r)=>n*r,1);if(t.isCContiguous&&!U(u)){const n=m.slice(0,I).reduce((o,i)=>o*i,1),r=m.slice(I+1).reduce((o,i)=>o*i,1),e=ht(t,n,g,r);if(e){const o=z?m.map((i,a)=>a===I?1:i):w;return O.fromData(e.data,o,u)}}const{baseOffsets:d,axisStride:c}=P(m,R,A,I,y);if(L(u)){const n=h,r=D;for(let e=0;e<y;e++){let o=d[e],i=n[o];o+=c;for(let a=1;a<g;a++){const s=n[o];s<i&&(i=s),o+=c}r[e]=i}}else for(let n=0;n<y;n++){let r=1/0,e=d[n];for(let o=0;o<g;o++){const i=Number(h[e]);i<r&&(r=i),e+=c}D[n]=r}if(z){const n=[...m];return n[I]=1,O.fromData(D,n,u)}return v}function J(t,x,z,u){return t<z?-1:t>z?1:x<u?-1:x>u?1:0}function ft(t,x){const z=t.dtype,u=U(z),m=t.shape,b=m.length,S=t.size,h=t.data,A=t.offset,R=t.strides,I=t.isCContiguous;if(x===void 0){const r=wt(t);if(r!==null)return r;if(S===0)throw new Error("argmin of empty array");if(u)if(I){const e=h;let o=e[A*2],i=e[A*2+1],a=0;for(let s=1;s<S;s++){const p=e[(A+s)*2],f=e[(A+s)*2+1];J(p,f,o,i)<0&&(o=p,i=f,a=s)}return a}else{const e=t.iget(0);let o=e.re,i=e.im,a=0;for(let s=1;s<S;s++){const p=t.iget(s);J(p.re,p.im,o,i)<0&&(o=p.re,i=p.im,a=s)}return a}if(I){let e=h[A],o=0;if(A===0)for(let i=1;i<S;i++)h[i]<e&&(e=h[i],o=i);else for(let i=1;i<S;i++)h[A+i]<e&&(e=h[A+i],o=i);return o}else{let e=t.iget(0),o=0;for(let i=1;i<S;i++){const a=t.iget(i);a<e&&(e=a,o=i)}return o}}let w=x;if(w<0&&(w=b+w),w<0||w>=b)throw new Error(`axis ${x} is out of bounds for array of dimension ${b}`);const v=Array.from(m).filter((r,e)=>e!==w);if(v.length===0)return ft(t);const D=O.zeros(v,"int32"),g=D.data,y=m[w],d=v.reduce((r,e)=>r*e,1),{baseOffsets:c,axisStride:n}=P(m,R,A,w,d);if(u){const r=h;for(let e=0;e<d;e++){let o=c[e],i=r[o*2],a=r[o*2+1],s=0;o+=n;for(let p=1;p<y;p++){const f=r[o*2],l=r[o*2+1];J(f,l,i,a)<0&&(i=f,a=l,s=p),o+=n}g[e]=s}}else if(L(z)){const r=h;for(let e=0;e<d;e++){let o=c[e],i=r[o],a=0;o+=n;for(let s=1;s<y;s++){const p=r[o];p<i&&(i=p,a=s),o+=n}g[e]=a}}else for(let r=0;r<d;r++){let e=1/0,o=0,i=c[r];for(let a=0;a<y;a++){const s=Number(h[i]);s<e&&(e=s,o=a),i+=n}g[r]=o}return D}function lt(t,x){const z=t.dtype,u=U(z),m=t.shape,b=m.length,S=t.size,h=t.data,A=t.offset,R=t.strides,I=t.isCContiguous;if(x===void 0){const r=zt(t);if(r!==null)return r;if(S===0)throw new Error("argmax of empty array");if(u)if(I){const e=h;let o=e[A*2],i=e[A*2+1],a=0;for(let s=1;s<S;s++){const p=e[(A+s)*2],f=e[(A+s)*2+1];J(p,f,o,i)>0&&(o=p,i=f,a=s)}return a}else{const e=t.iget(0);let o=e.re,i=e.im,a=0;for(let s=1;s<S;s++){const p=t.iget(s);J(p.re,p.im,o,i)>0&&(o=p.re,i=p.im,a=s)}return a}if(I){let e=h[A],o=0;for(let i=1;i<S;i++)h[A+i]>e&&(e=h[A+i],o=i);return o}else{let e=t.iget(0),o=0;for(let i=1;i<S;i++){const a=t.iget(i);a>e&&(e=a,o=i)}return o}}let w=x;if(w<0&&(w=b+w),w<0||w>=b)throw new Error(`axis ${x} is out of bounds for array of dimension ${b}`);const v=Array.from(m).filter((r,e)=>e!==w);if(v.length===0)return lt(t);const D=O.zeros(v,"int32"),g=D.data,y=m[w],d=v.reduce((r,e)=>r*e,1),{baseOffsets:c,axisStride:n}=P(m,R,A,w,d);if(u){const r=h;for(let e=0;e<d;e++){let o=c[e],i=r[o*2],a=r[o*2+1],s=0;o+=n;for(let p=1;p<y;p++){const f=r[o*2],l=r[o*2+1];J(f,l,i,a)>0&&(i=f,a=l,s=p),o+=n}g[e]=s}}else if(L(z)){const r=h;for(let e=0;e<d;e++){let o=c[e],i=r[o],a=0;o+=n;for(let s=1;s<y;s++){const p=r[o];p>i&&(i=p,a=s),o+=n}g[e]=a}}else for(let r=0;r<d;r++){let e=-1/0,o=0,i=c[r];for(let a=0;a<y;a++){const s=Number(h[i]);s>e&&(e=s,o=a),i+=n}g[r]=o}return D}function ut(t,x,z=0,u=!1){const m=t.dtype,b=t.shape,S=b.length,h=t.size,A=t.data,R=t.offset,I=t.strides,w=nt(t,x,u),v=t.isCContiguous;if(x===void 0){const a=Ft(t);if(a!==null)return a;if(U(m)){const f=w;let l=0;if(v){const N=A;for(let C=0;C<h;C++){const B=N[(R+C)*2],F=N[(R+C)*2+1],$=B-f.re,E=F-f.im;l+=$*$+E*E}}else for(let N=0;N<h;N++){const C=t.iget(N),B=C.re-f.re,F=C.im-f.im;l+=B*B+F*F}return l/(h-z)}const s=w;let p=0;if(v)for(let f=0;f<h;f++){const l=Number(A[R+f])-s;p+=l*l}else for(let f=0;f<h;f++){const l=Number(t.iget(f))-s;p+=l*l}return p/(h-z)}let D=x;if(D<0&&(D=S+D),D<0||D>=S)throw new Error(`axis ${x} is out of bounds for array of dimension ${S}`);const g=b[D],y=w,d=y.data,c=u?y.shape:Array.from(b).filter((a,s)=>s!==D),n=O.zeros(Array.from(c),"float64"),r=n.data,e=c.reduce((a,s)=>a*s,1),{baseOffsets:o,axisStride:i}=P(b,I,R,D,e);if(U(m)){const a=A,s=d;for(let p=0;p<e;p++){let f=0;const l=s[p*2],N=s[p*2+1];let C=o[p];for(let B=0;B<g;B++){const F=a[C*2],$=a[C*2+1],E=F-l,T=$-N;f+=E*E+T*T,C+=i}r[p]=f/(g-z)}}else for(let a=0;a<e;a++){let s=0;const p=Number(d[a]);let f=o[a];for(let l=0;l<g;l++){const N=Number(A[f])-p;s+=N*N,f+=i}r[a]=s/(g-z)}return n}function ue(t,x,z=0,u=!1){const m=ut(t,x,z,u);if(typeof m=="number")return Math.sqrt(m);const b=O.zeros(Array.from(m.shape),"float64"),S=m.data,h=b.data;for(let A=0;A<S.length;A++)h[A]=Math.sqrt(Number(S[A]));return b}function _t(t,x,z=!1){const u=t.shape,m=u.length,b=t.size,S=t.data,h=t.offset,A=t.strides,R=t.isCContiguous;if(x===void 0){const n=Vt(t);if(n!==null)return n===1;if(R){for(let r=0;r<b;r++)if(!S[h+r])return!1}else for(let r=0;r<b;r++)if(!t.iget(r))return!1;return!0}let I=x;if(I<0&&(I=m+I),I<0||I>=m)throw new Error(`axis ${x} is out of bounds for array of dimension ${m}`);const w=Array.from(u).filter((n,r)=>r!==I);if(w.length===0){const n=_t(t);if(!z)return n;const r=O.zeros(Array(m).fill(1),"bool");return r.iset(0,n?1:0),r}const v=O.zeros(w,"bool"),D=v.data,g=u[I],y=w.reduce((n,r)=>n*r,1),{baseOffsets:d,axisStride:c}=P(u,A,h,I,y);for(let n=0;n<y;n++){let r=!0,e=d[n];for(let o=0;o<g;o++){if(!S[e]){r=!1;break}e+=c}D[n]=r?1:0}if(z){const n=[...u];return n[I]=1,O.fromData(D,n,"bool")}return v}function Mt(t,x,z=!1){const u=t.shape,m=u.length,b=t.size,S=t.data,h=t.offset,A=t.strides,R=t.isCContiguous;if(x===void 0){const n=gt(t);if(n!==null)return n===1;if(R){for(let r=0;r<b;r++)if(S[h+r])return!0}else for(let r=0;r<b;r++)if(t.iget(r))return!0;return!1}let I=x;if(I<0&&(I=m+I),I<0||I>=m)throw new Error(`axis ${x} is out of bounds for array of dimension ${m}`);const w=Array.from(u).filter((n,r)=>r!==I);if(w.length===0){const n=Mt(t);if(!z)return n;const r=O.zeros(Array(m).fill(1),"bool");return r.iset(0,n?1:0),r}const v=O.zeros(w,"bool"),D=v.data,g=u[I],y=w.reduce((n,r)=>n*r,1),{baseOffsets:d,axisStride:c}=P(u,A,h,I,y);for(let n=0;n<y;n++){let r=!1,e=d[n];for(let o=0;o<g;o++){if(S[e]){r=!0;break}e+=c}D[n]=r?1:0}if(z){const n=[...u];return n[I]=1,O.fromData(D,n,"bool")}return v}function Ut(t,x){const z=t.dtype,u=t.shape,m=u.length,b=t.data,S=t.offset,h=t.strides,A=t.isCContiguous;if(U(z)){const r=b,e=t.size;if(x===void 0){const $=O.zeros([e],z),E=$.data;let T=0,_=0;if(A)for(let V=0;V<e;V++)T+=r[(S+V)*2],_+=r[(S+V)*2+1],E[V*2]=T,E[V*2+1]=_;else for(let V=0;V<e;V++){const M=t.iget(V);T+=M.re,_+=M.im,E[V*2]=T,E[V*2+1]=_}return $}let o=x;if(o<0&&(o=m+o),o<0||o>=m)throw new Error(`axis ${x} is out of bounds for array of dimension ${m}`);const i=O.zeros([...u],z),a=i.data,s=u[o],p=Array.from(u).filter(($,E)=>E!==o),f=p.length===0?1:p.reduce(($,E)=>$*E,1),{baseOffsets:l,axisStride:N}=P(u,h,S,o,f),C=k(u),{baseOffsets:B,axisStride:F}=P(u,C,0,o,f);for(let $=0;$<f;$++){let E=l[$],T=B[$],_=0,V=0;for(let M=0;M<s;M++)_+=r[E*2],V+=r[E*2+1],a[T*2]=_,a[T*2+1]=V,E+=N,T+=F}return i}if(x===void 0){const r=t.size,e=new Float64Array(r);let o=0;if(A)for(let i=0;i<r;i++)o+=Number(b[S+i]),e[i]=o;else for(let i=0;i<r;i++)o+=Number(t.iget(i)),e[i]=o;return O.fromData(e,[r],"float64")}let R=x;if(R<0&&(R=m+R),R<0||R>=m)throw new Error(`axis ${x} is out of bounds for array of dimension ${m}`);const I=new Float64Array(t.size),w=u[R],v=Array.from(u).filter((r,e)=>e!==R),D=v.length===0?1:v.reduce((r,e)=>r*e,1),{baseOffsets:g,axisStride:y}=P(u,h,S,R,D),d=k(u),{baseOffsets:c,axisStride:n}=P(u,d,0,R,D);for(let r=0;r<D;r++){let e=g[r],o=c[r],i=0;for(let a=0;a<w;a++)i+=Number(b[e]),I[o]=i,e+=y,o+=n}return O.fromData(I,[...u],"float64")}function Pt(t,x){const z=t.dtype,u=t.shape,m=u.length,b=t.data,S=t.offset,h=t.strides,A=t.isCContiguous;if(U(z)){const r=b,e=t.size;if(x===void 0){const $=O.zeros([e],z),E=$.data;let T=1,_=0;if(A)for(let V=0;V<e;V++){const M=r[(S+V)*2],K=r[(S+V)*2+1],G=T*M-_*K,X=T*K+_*M;T=G,_=X,E[V*2]=T,E[V*2+1]=_}else for(let V=0;V<e;V++){const M=t.iget(V),K=M.re,G=M.im,X=T*K-_*G,rt=T*G+_*K;T=X,_=rt,E[V*2]=T,E[V*2+1]=_}return $}let o=x;if(o<0&&(o=m+o),o<0||o>=m)throw new Error(`axis ${x} is out of bounds for array of dimension ${m}`);const i=O.zeros([...u],z),a=i.data,s=u[o],p=Array.from(u).filter(($,E)=>E!==o),f=p.length===0?1:p.reduce(($,E)=>$*E,1),{baseOffsets:l,axisStride:N}=P(u,h,S,o,f),C=k(u),{baseOffsets:B,axisStride:F}=P(u,C,0,o,f);for(let $=0;$<f;$++){let E=l[$],T=B[$],_=1,V=0;for(let M=0;M<s;M++){const K=r[E*2],G=r[E*2+1],X=_*K-V*G,rt=_*G+V*K;_=X,V=rt,a[T*2]=_,a[T*2+1]=V,E+=N,T+=F}}return i}if(x===void 0){const r=t.size,e=new Float64Array(r);let o=1;if(A)for(let i=0;i<r;i++)o*=Number(b[S+i]),e[i]=o;else for(let i=0;i<r;i++)o*=Number(t.iget(i)),e[i]=o;return O.fromData(e,[r],"float64")}let R=x;if(R<0&&(R=m+R),R<0||R>=m)throw new Error(`axis ${x} is out of bounds for array of dimension ${m}`);const I=new Float64Array(t.size),w=u[R],v=Array.from(u).filter((r,e)=>e!==R),D=v.length===0?1:v.reduce((r,e)=>r*e,1),{baseOffsets:g,axisStride:y}=P(u,h,S,R,D),d=k(u),{baseOffsets:c,axisStride:n}=P(u,d,0,R,D);for(let r=0;r<D;r++){let e=g[r],o=c[r],i=1;for(let a=0;a<w;a++)i*=Number(b[e]),I[o]=i,e+=y,o+=n}return O.fromData(I,[...u],"float64")}function ce(t,x,z=!1){const u=t.dtype;if(U(u)){const v=Y(t,x,z),D=Z(t,x,z);if(v instanceof Q&&D instanceof Q)return new Q(v.re-D.re,v.im-D.im);const g=v,y=D,d=g.data,c=y.data,n=new Float64Array(g.size*2);for(let r=0;r<g.size;r++)n[r*2]=d[r*2]-c[r*2],n[r*2+1]=d[r*2+1]-c[r*2+1];return O.fromData(n,[...g.shape],u)}const m=Y(t,x,z),b=Z(t,x,z);if(typeof m=="number"&&typeof b=="number"){const v=m-b;if(u==="int8"||u==="int16"||u==="int32"||u==="uint8"||u==="uint16"||u==="uint32"){const D=O.zeros([1],u);return D.iset(0,v),Number(D.iget(0))}return v}const S=m,h=b,A=S.data,R=h.data,I=O.zeros([...S.shape],u),w=I.data;for(let v=0;v<S.size;v++)w[v]=Number(A[v])-Number(R[v]);return I}function qt(t,x,z=!1){return et(t,.5,x,z)}function me(t,x,z,u=!1){return et(t,x/100,z,u)}function et(t,x,z,u=!1){if(ot(t.dtype,"quantile","Complex numbers are not orderable."),x<0||x>1)throw new Error("Quantile must be between 0 and 1");const m=t.shape,b=m.length,S=t.data,h=t.offset,A=t.strides;if(z===void 0){const c=Ot(t,x);if(c!==null)return c;const n=[];if(t.isCContiguous)for(let p=0;p<t.size;p++)n.push(Number(S[h+p]));else for(let p=0;p<t.size;p++)n.push(Number(t.iget(p)));n.sort((p,f)=>p-f);const e=n.length,o=x*(e-1),i=Math.floor(o),a=Math.ceil(o);if(i===a)return n[i];const s=o-i;return n[i]*(1-s)+n[a]*s}let R=z;if(R<0&&(R=b+R),R<0||R>=b)throw new Error(`axis ${z} is out of bounds for array of dimension ${b}`);const I=Array.from(m).filter((c,n)=>n!==R);if(I.length===0){const c=et(t,x);if(!u)return c;const n=O.zeros(Array(b).fill(1),"float64");return n.iset(0,c),n}const w=I.reduce((c,n)=>c*n,1),v=m[R],D=new Float64Array(w),{baseOffsets:g,axisStride:y}=P(m,A,h,R,w);for(let c=0;c<w;c++){const n=[];let r=g[c];for(let s=0;s<v;s++)n.push(Number(S[r])),r+=y;n.sort((s,p)=>s-p);const e=n.length,o=x*(e-1),i=Math.floor(o),a=Math.ceil(o);if(i===a)D[c]=n[i];else{const s=o-i;D[c]=n[i]*(1-s)+n[a]*s}}const d=O.fromData(D,I,"float64");if(u){const c=[...m];return c[R]=1,O.fromData(D,c,"float64")}return d}function ct(t,x,z,u=!1){const m=t.dtype,b=t.shape,S=b.length,h=t.data,A=t.offset,R=t.strides;if(z===void 0)return nt(t,x,u);if(U(m)){const e=h,o=z.data,i=z.offset;if(x===void 0){let F=0,$=0,E=0;if(t.isCContiguous)for(let _=0;_<t.size;_++){const V=Number(o[i+_%z.size]),M=e[(A+_)*2],K=e[(A+_)*2+1];F+=M*V,$+=K*V,E+=V}else for(let _=0;_<t.size;_++){const V=Number(o[i+_%z.size]),M=t.iget(_);F+=M.re*V,$+=M.im*V,E+=V}return E===0?new Q(NaN,NaN):new Q(F/E,$/E)}let a=x;if(a<0&&(a=S+a),a<0||a>=S)throw new Error(`axis ${x} is out of bounds for array of dimension ${S}`);const s=Array.from(b).filter((F,$)=>$!==a);if(s.length===0){const F=ct(t,void 0,z);return u?j(F,S,m):F}const p=s.reduce((F,$)=>F*$,1),f=b[a],l=O.zeros(s,m),N=l.data,{baseOffsets:C,axisStride:B}=P(b,R,A,a,p);for(let F=0;F<p;F++){let $=0,E=0,T=0,_=C[F];for(let V=0;V<f;V++){const M=Number(o[i+V%z.size]),K=e[_*2],G=e[_*2+1];$+=K*M,E+=G*M,T+=M,_+=B}T===0?(N[F*2]=NaN,N[F*2+1]=NaN):(N[F*2]=$/T,N[F*2+1]=E/T)}if(u){const F=[...b];return F[a]=1,O.fromData(N,F,m)}return l}const I=z.offset;if(x===void 0){let e=0,o=0;const i=z.data;if(t.isCContiguous)for(let s=0;s<t.size;s++){const p=Number(i[I+s%z.size]);e+=Number(h[A+s])*p,o+=p}else for(let s=0;s<t.size;s++){const p=Number(i[I+s%z.size]);e+=Number(t.iget(s))*p,o+=p}return o===0?NaN:e/o}let w=x;if(w<0&&(w=S+w),w<0||w>=S)throw new Error(`axis ${x} is out of bounds for array of dimension ${S}`);const v=Array.from(b).filter((e,o)=>o!==w);if(v.length===0){const e=ct(t,void 0,z);return u?j(e,S,"float64"):e}const D=v.reduce((e,o)=>e*o,1),g=b[w],y=z.data,d=new Float64Array(D),{baseOffsets:c,axisStride:n}=P(b,R,A,w,D);for(let e=0;e<D;e++){let o=0,i=0,a=c[e];for(let s=0;s<g;s++){const p=Number(y[I+s%z.size]);o+=Number(h[a])*p,i+=p,a+=n}d[e]=i===0?NaN:o/i}const r=O.fromData(d,v,"float64");if(u){const e=[...b];return e[w]=1,O.fromData(d,e,"float64")}return r}function q(t,x){return isNaN(t)||isNaN(x)}function Wt(t,x,z=!1){const u=t.dtype,m=U(u),b=t.shape,S=b.length,h=t.data,A=t.offset,R=t.strides;if(!m&&!H(u))return tt(t,x,z);if(x===void 0){const n=Rt(t);if(n!==null)return n;if(m){const o=h;let i=0,a=0;if(t.isCContiguous)for(let p=0;p<t.size;p++){const f=o[(A+p)*2],l=o[(A+p)*2+1];q(f,l)||(i+=f,a+=l)}else for(let p=0;p<t.size;p++){const f=t.iget(p),l=f.re,N=f.im;q(l,N)||(i+=l,a+=N)}return new Q(i,a)}let r=0;if(t.isCContiguous)for(let o=0;o<t.size;o++){const i=Number(h[A+o]);isNaN(i)||(r+=i)}else for(let o=0;o<t.size;o++){const i=Number(t.iget(o));isNaN(i)||(r+=i)}return r}let I=x;if(I<0&&(I=S+I),I<0||I>=S)throw new Error(`axis ${x} is out of bounds for array of dimension ${S}`);const w=Array.from(b).filter((n,r)=>r!==I);if(w.length===0){const n=Wt(t);return z?j(n,S,u):n}const v=w.reduce((n,r)=>n*r,1),D=b[I],{baseOffsets:g,axisStride:y}=P(b,R,A,I,v);if(m){const n=h,r=new Float64Array(v*2);for(let e=0;e<v;e++){let o=0,i=0,a=g[e];for(let s=0;s<D;s++){const p=n[a*2],f=n[a*2+1];q(p,f)||(o+=p,i+=f),a+=y}r[e*2]=o,r[e*2+1]=i}if(z){const e=[...b];return e[I]=1,O.fromData(r,e,u)}return O.fromData(r,w,u)}const d=new Float64Array(v);for(let n=0;n<v;n++){let r=0,e=g[n];for(let o=0;o<D;o++){const i=Number(h[e]);isNaN(i)||(r+=i),e+=y}d[n]=r}const c=O.fromData(d,w,"float64");if(z){const n=[...b];return n[I]=1,O.fromData(d,n,"float64")}return c}function Qt(t,x,z=!1){const u=t.dtype,m=U(u);if(!m&&!H(u))return at(t,x,z);const b=t.shape,S=b.length,h=t.data,A=t.offset,R=t.strides;if(x===void 0){if(m){const e=h;let o=1,i=0;if(t.isCContiguous)for(let s=0;s<t.size;s++){const p=e[(A+s)*2],f=e[(A+s)*2+1];if(!q(p,f)){const l=o*p-i*f,N=o*f+i*p;o=l,i=N}}else for(let s=0;s<t.size;s++){const p=t.iget(s),f=p.re,l=p.im;if(!q(f,l)){const N=o*f-i*l,C=o*l+i*f;o=N,i=C}}return new Q(o,i)}let n=1;if(t.isCContiguous)for(let e=0;e<t.size;e++){const o=Number(h[A+e]);isNaN(o)||(n*=o)}else for(let e=0;e<t.size;e++){const o=Number(t.iget(e));isNaN(o)||(n*=o)}return n}let I=x;if(I<0&&(I=S+I),I<0||I>=S)throw new Error(`axis ${x} is out of bounds for array of dimension ${S}`);const w=Array.from(b).filter((n,r)=>r!==I);if(w.length===0){const n=Qt(t);return z?j(n,S,u):n}const v=w.reduce((n,r)=>n*r,1),D=b[I],{baseOffsets:g,axisStride:y}=P(b,R,A,I,v);if(m){const n=h,r=new Float64Array(v*2);for(let e=0;e<v;e++){let o=1,i=0,a=g[e];for(let s=0;s<D;s++){const p=n[a*2],f=n[a*2+1];if(!q(p,f)){const l=o*p-i*f,N=o*f+i*p;o=l,i=N}a+=y}r[e*2]=o,r[e*2+1]=i}if(z){const e=[...b];return e[I]=1,O.fromData(r,e,u)}return O.fromData(r,w,u)}const d=new Float64Array(v);for(let n=0;n<v;n++){let r=1,e=g[n];for(let o=0;o<D;o++){const i=Number(h[e]);isNaN(i)||(r*=i),e+=y}d[n]=r}const c=O.fromData(d,w,"float64");if(z){const n=[...b];return n[I]=1,O.fromData(d,n,"float64")}return c}function Kt(t,x,z=!1){const u=t.dtype,m=U(u);if(!m&&!H(u))return nt(t,x,z);const b=t.shape,S=b.length,h=t.data,A=t.offset,R=t.strides;if(x===void 0){if(m){const o=h;let i=0,a=0,s=0;if(t.isCContiguous)for(let f=0;f<t.size;f++){const l=o[(A+f)*2],N=o[(A+f)*2+1];q(l,N)||(i+=l,a+=N,s++)}else for(let f=0;f<t.size;f++){const l=t.iget(f),N=l.re,C=l.im;q(N,C)||(i+=N,a+=C,s++)}return s===0?new Q(NaN,NaN):new Q(i/s,a/s)}let n=0,r=0;if(t.isCContiguous)for(let o=0;o<t.size;o++){const i=Number(h[A+o]);isNaN(i)||(n+=i,r++)}else for(let o=0;o<t.size;o++){const i=Number(t.iget(o));isNaN(i)||(n+=i,r++)}return r===0?NaN:n/r}let I=x;if(I<0&&(I=S+I),I<0||I>=S)throw new Error(`axis ${x} is out of bounds for array of dimension ${S}`);const w=Array.from(b).filter((n,r)=>r!==I);if(w.length===0){const n=Kt(t);return z?j(n,S,u):n}const v=w.reduce((n,r)=>n*r,1),D=b[I],{baseOffsets:g,axisStride:y}=P(b,R,A,I,v);if(m){const n=h,r=new Float64Array(v*2);for(let e=0;e<v;e++){let o=0,i=0,a=0,s=g[e];for(let p=0;p<D;p++){const f=n[s*2],l=n[s*2+1];q(f,l)||(o+=f,i+=l,a++),s+=y}a===0?(r[e*2]=NaN,r[e*2+1]=NaN):(r[e*2]=o/a,r[e*2+1]=i/a)}if(z){const e=[...b];return e[I]=1,O.fromData(r,e,u)}return O.fromData(r,w,u)}const d=new Float64Array(v);for(let n=0;n<v;n++){let r=0,e=0,o=g[n];for(let i=0;i<D;i++){const a=Number(h[o]);isNaN(a)||(r+=a,e++),o+=y}d[n]=e===0?NaN:r/e}const c=O.fromData(d,w,"float64");if(z){const n=[...b];return n[I]=1,O.fromData(d,n,"float64")}return c}function it(t,x,z=0,u=!1){const m=t.dtype;if(!U(m)&&!H(m))return ut(t,x,z,u);const b=t.shape,S=b.length,h=t.data,A=t.offset,R=t.strides;if(U(m)){const n=h;if(x===void 0){let l=0,N=0,C=0;const B=t.isCContiguous;if(B)for(let T=0;T<t.size;T++){const _=n[(A+T)*2],V=n[(A+T)*2+1];q(_,V)||(l+=_,N+=V,C++)}else for(let T=0;T<t.size;T++){const _=t.iget(T),V=_.re,M=_.im;q(V,M)||(l+=V,N+=M,C++)}if(C-z<=0)return NaN;const F=l/C,$=N/C;let E=0;if(B)for(let T=0;T<t.size;T++){const _=n[(A+T)*2],V=n[(A+T)*2+1];if(!q(_,V)){const M=_-F,K=V-$;E+=M*M+K*K}}else for(let T=0;T<t.size;T++){const _=t.iget(T),V=_.re,M=_.im;if(!q(V,M)){const K=V-F,G=M-$;E+=K*K+G*G}}return E/(C-z)}let r=x;if(r<0&&(r=S+r),r<0||r>=S)throw new Error(`axis ${x} is out of bounds for array of dimension ${S}`);const e=Array.from(b).filter((l,N)=>N!==r);if(e.length===0){const l=it(t,void 0,z);return u?j(l,S,"float64"):l}const o=e.reduce((l,N)=>l*N,1),i=b[r],a=new Float64Array(o),{baseOffsets:s,axisStride:p}=P(b,R,A,r,o);for(let l=0;l<o;l++){let N=0,C=0,B=0,F=s[l];for(let _=0;_<i;_++){const V=n[F*2],M=n[F*2+1];q(V,M)||(N+=V,C+=M,B++),F+=p}if(B-z<=0){a[l]=NaN;continue}const $=N/B,E=C/B;let T=0;F=s[l];for(let _=0;_<i;_++){const V=n[F*2],M=n[F*2+1];if(!q(V,M)){const K=V-$,G=M-E;T+=K*K+G*G}F+=p}a[l]=T/(B-z)}const f=O.fromData(a,e,"float64");if(u){const l=[...b];return l[r]=1,O.fromData(a,l,"float64")}return f}if(x===void 0){let n=0,r=0;const e=t.isCContiguous;if(e)for(let a=0;a<t.size;a++){const s=Number(h[A+a]);isNaN(s)||(n+=s,r++)}else for(let a=0;a<t.size;a++){const s=Number(t.iget(a));isNaN(s)||(n+=s,r++)}if(r-z<=0)return NaN;const o=n/r;let i=0;if(e)for(let a=0;a<t.size;a++){const s=Number(h[A+a]);isNaN(s)||(i+=(s-o)**2)}else for(let a=0;a<t.size;a++){const s=Number(t.iget(a));isNaN(s)||(i+=(s-o)**2)}return i/(r-z)}let I=x;if(I<0&&(I=S+I),I<0||I>=S)throw new Error(`axis ${x} is out of bounds for array of dimension ${S}`);const w=Array.from(b).filter((n,r)=>r!==I);if(w.length===0){const n=it(t,void 0,z);return u?j(n,S,"float64"):n}const v=w.reduce((n,r)=>n*r,1),D=b[I],g=new Float64Array(v),{baseOffsets:y,axisStride:d}=P(b,R,A,I,v);for(let n=0;n<v;n++){let r=0,e=0,o=y[n];for(let s=0;s<D;s++){const p=Number(h[o]);isNaN(p)||(r+=p,e++),o+=d}if(e-z<=0){g[n]=NaN;continue}const i=r/e;let a=0;o=y[n];for(let s=0;s<D;s++){const p=Number(h[o]);isNaN(p)||(a+=(p-i)**2),o+=d}g[n]=a/(e-z)}const c=O.fromData(g,w,"float64");if(u){const n=[...b];return n[I]=1,O.fromData(g,n,"float64")}return c}function de(t,x,z=0,u=!1){const m=it(t,x,z,u);if(typeof m=="number")return Math.sqrt(m);const b=m,S=new Float64Array(b.size);for(let h=0;h<b.size;h++)S[h]=Math.sqrt(Number(b.data[h]));return O.fromData(S,[...b.shape],"float64")}function mt(t,x,z=!1){const u=t.dtype,m=t.shape,b=m.length,S=t.data,h=t.offset,A=t.strides;if(!U(u)&&!H(u))return Z(t,x,z);if(U(u)){const c=S;if(x===void 0){let f=1/0,l=1/0,N=!1;if(t.isCContiguous)for(let B=0;B<t.size;B++){const F=c[(h+B)*2],$=c[(h+B)*2+1];isNaN(F)||isNaN($)||(N?(F<f||F===f&&$<l)&&(f=F,l=$):(f=F,l=$,N=!0))}else for(let B=0;B<t.size;B++){const F=t.iget(B),$=F.re,E=F.im;isNaN($)||isNaN(E)||(N?($<f||$===f&&E<l)&&(f=$,l=E):(f=$,l=E,N=!0))}return N?new Q(f,l):new Q(NaN,NaN)}let n=x;if(n<0&&(n=b+n),n<0||n>=b)throw new Error(`axis ${x} is out of bounds for array of dimension ${b}`);const r=Array.from(m).filter((f,l)=>l!==n);if(r.length===0){const f=mt(t);return z?j(f,b,u):f}const e=r.reduce((f,l)=>f*l,1),o=m[n],i=new Float64Array(e*2),{baseOffsets:a,axisStride:s}=P(m,A,h,n,e);for(let f=0;f<e;f++){let l=1/0,N=1/0,C=!1,B=a[f];for(let F=0;F<o;F++){const $=c[B*2],E=c[B*2+1];B+=s,!(isNaN($)||isNaN(E))&&(C?($<l||$===l&&E<N)&&(l=$,N=E):(l=$,N=E,C=!0))}i[f*2]=C?l:NaN,i[f*2+1]=C?N:NaN}const p=O.fromData(i,r,u);if(z){const f=[...m];return f[n]=1,O.fromData(i,f,u)}return p}if(x===void 0){const c=vt(t);if(c!==null)return c;let n=1/0;if(t.isCContiguous)for(let e=0;e<t.size;e++){const o=Number(S[h+e]);!isNaN(o)&&o<n&&(n=o)}else for(let e=0;e<t.size;e++){const o=Number(t.iget(e));!isNaN(o)&&o<n&&(n=o)}return n===1/0?NaN:n}let R=x;if(R<0&&(R=b+R),R<0||R>=b)throw new Error(`axis ${x} is out of bounds for array of dimension ${b}`);const I=Array.from(m).filter((c,n)=>n!==R);if(I.length===0){const c=mt(t);return z?j(c,b,"float64"):c}const w=I.reduce((c,n)=>c*n,1),v=m[R],D=new Float64Array(w),{baseOffsets:g,axisStride:y}=P(m,A,h,R,w);for(let c=0;c<w;c++){let n=1/0,r=g[c];for(let e=0;e<v;e++){const o=Number(S[r]);!isNaN(o)&&o<n&&(n=o),r+=y}D[c]=n===1/0?NaN:n}const d=O.fromData(D,I,"float64");if(z){const c=[...m];return c[R]=1,O.fromData(D,c,"float64")}return d}function dt(t,x,z=!1){const u=t.dtype,m=t.shape,b=m.length,S=t.data,h=t.offset,A=t.strides;if(!U(u)&&!H(u))return Y(t,x,z);if(U(u)){const c=S;if(x===void 0){let f=-1/0,l=-1/0,N=!1;if(t.isCContiguous)for(let B=0;B<t.size;B++){const F=c[(h+B)*2],$=c[(h+B)*2+1];isNaN(F)||isNaN($)||(N?(F>f||F===f&&$>l)&&(f=F,l=$):(f=F,l=$,N=!0))}else for(let B=0;B<t.size;B++){const F=t.iget(B),$=F.re,E=F.im;isNaN($)||isNaN(E)||(N?($>f||$===f&&E>l)&&(f=$,l=E):(f=$,l=E,N=!0))}return N?new Q(f,l):new Q(NaN,NaN)}let n=x;if(n<0&&(n=b+n),n<0||n>=b)throw new Error(`axis ${x} is out of bounds for array of dimension ${b}`);const r=Array.from(m).filter((f,l)=>l!==n);if(r.length===0){const f=dt(t);return z?j(f,b,u):f}const e=r.reduce((f,l)=>f*l,1),o=m[n],i=new Float64Array(e*2),{baseOffsets:a,axisStride:s}=P(m,A,h,n,e);for(let f=0;f<e;f++){let l=-1/0,N=-1/0,C=!1,B=a[f];for(let F=0;F<o;F++){const $=c[B*2],E=c[B*2+1];B+=s,!(isNaN($)||isNaN(E))&&(C?($>l||$===l&&E>N)&&(l=$,N=E):(l=$,N=E,C=!0))}i[f*2]=C?l:NaN,i[f*2+1]=C?N:NaN}const p=O.fromData(i,r,u);if(z){const f=[...m];return f[n]=1,O.fromData(i,f,u)}return p}if(x===void 0){const c=$t(t);if(c!==null)return c;let n=-1/0;if(t.isCContiguous)for(let e=0;e<t.size;e++){const o=Number(S[h+e]);!isNaN(o)&&o>n&&(n=o)}else for(let e=0;e<t.size;e++){const o=Number(t.iget(e));!isNaN(o)&&o>n&&(n=o)}return n===-1/0?NaN:n}let R=x;if(R<0&&(R=b+R),R<0||R>=b)throw new Error(`axis ${x} is out of bounds for array of dimension ${b}`);const I=Array.from(m).filter((c,n)=>n!==R);if(I.length===0){const c=dt(t);return z?j(c,b,"float64"):c}const w=I.reduce((c,n)=>c*n,1),v=m[R],D=new Float64Array(w),{baseOffsets:g,axisStride:y}=P(m,A,h,R,w);for(let c=0;c<w;c++){let n=-1/0,r=g[c];for(let e=0;e<v;e++){const o=Number(S[r]);!isNaN(o)&&o>n&&(n=o),r+=y}D[c]=n===-1/0?NaN:n}const d=O.fromData(D,I,"float64");if(z){const c=[...m];return c[R]=1,O.fromData(D,c,"float64")}return d}function xt(t,x){const z=t.dtype;if(!U(z)&&!H(z))return ft(t,x);const u=t.shape,m=u.length,b=t.data,S=t.offset,h=t.strides;if(U(z)){const y=b;if(x===void 0){let a=1/0,s=1/0,p=-1;if(t.isCContiguous)for(let l=0;l<t.size;l++){const N=y[(S+l)*2],C=y[(S+l)*2+1];!q(N,C)&&J(N,C,a,s)<0&&(a=N,s=C,p=l)}else for(let l=0;l<t.size;l++){const N=t.iget(l),C=N.re,B=N.im;!q(C,B)&&J(C,B,a,s)<0&&(a=C,s=B,p=l)}return p}let d=x;if(d<0&&(d=m+d),d<0||d>=m)throw new Error(`axis ${x} is out of bounds for array of dimension ${m}`);const c=Array.from(u).filter((a,s)=>s!==d);if(c.length===0)return xt(t);const n=c.reduce((a,s)=>a*s,1),r=u[d],e=new Int32Array(n),{baseOffsets:o,axisStride:i}=P(u,h,S,d,n);for(let a=0;a<n;a++){let s=1/0,p=1/0,f=0,l=o[a];for(let N=0;N<r;N++){const C=y[l*2],B=y[l*2+1];!q(C,B)&&J(C,B,s,p)<0&&(s=C,p=B,f=N),l+=i}e[a]=f}return O.fromData(e,c,"int32")}if(x===void 0){let y=1/0,d=-1;if(t.isCContiguous)for(let n=0;n<t.size;n++){const r=Number(b[S+n]);!isNaN(r)&&r<y&&(y=r,d=n)}else for(let n=0;n<t.size;n++){const r=Number(t.iget(n));!isNaN(r)&&r<y&&(y=r,d=n)}return d}let A=x;if(A<0&&(A=m+A),A<0||A>=m)throw new Error(`axis ${x} is out of bounds for array of dimension ${m}`);const R=Array.from(u).filter((y,d)=>d!==A);if(R.length===0)return xt(t);const I=R.reduce((y,d)=>y*d,1),w=u[A],v=new Int32Array(I),{baseOffsets:D,axisStride:g}=P(u,h,S,A,I);for(let y=0;y<I;y++){let d=1/0,c=0,n=D[y];for(let r=0;r<w;r++){const e=Number(b[n]);!isNaN(e)&&e<d&&(d=e,c=r),n+=g}v[y]=c}return O.fromData(v,R,"int32")}function pt(t,x){const z=t.dtype;if(!U(z)&&!H(z))return lt(t,x);const u=t.shape,m=u.length,b=t.data,S=t.offset,h=t.strides;if(U(z)){const y=b;if(x===void 0){let a=-1/0,s=-1/0,p=-1;if(t.isCContiguous)for(let l=0;l<t.size;l++){const N=y[(S+l)*2],C=y[(S+l)*2+1];!q(N,C)&&J(N,C,a,s)>0&&(a=N,s=C,p=l)}else for(let l=0;l<t.size;l++){const N=t.iget(l),C=N.re,B=N.im;!q(C,B)&&J(C,B,a,s)>0&&(a=C,s=B,p=l)}return p}let d=x;if(d<0&&(d=m+d),d<0||d>=m)throw new Error(`axis ${x} is out of bounds for array of dimension ${m}`);const c=Array.from(u).filter((a,s)=>s!==d);if(c.length===0)return pt(t);const n=c.reduce((a,s)=>a*s,1),r=u[d],e=new Int32Array(n),{baseOffsets:o,axisStride:i}=P(u,h,S,d,n);for(let a=0;a<n;a++){let s=-1/0,p=-1/0,f=0,l=o[a];for(let N=0;N<r;N++){const C=y[l*2],B=y[l*2+1];!q(C,B)&&J(C,B,s,p)>0&&(s=C,p=B,f=N),l+=i}e[a]=f}return O.fromData(e,c,"int32")}if(x===void 0){let y=-1/0,d=-1;if(t.isCContiguous)for(let n=0;n<t.size;n++){const r=Number(b[S+n]);!isNaN(r)&&r>y&&(y=r,d=n)}else for(let n=0;n<t.size;n++){const r=Number(t.iget(n));!isNaN(r)&&r>y&&(y=r,d=n)}return d}let A=x;if(A<0&&(A=m+A),A<0||A>=m)throw new Error(`axis ${x} is out of bounds for array of dimension ${m}`);const R=Array.from(u).filter((y,d)=>d!==A);if(R.length===0)return pt(t);const I=R.reduce((y,d)=>y*d,1),w=u[A],v=new Int32Array(I),{baseOffsets:D,axisStride:g}=P(u,h,S,A,I);for(let y=0;y<I;y++){let d=-1/0,c=0,n=D[y];for(let r=0;r<w;r++){const e=Number(b[n]);!isNaN(e)&&e>d&&(d=e,c=r),n+=g}v[y]=c}return O.fromData(v,R,"int32")}function xe(t,x){const z=t.dtype;if(!U(z)&&!H(z))return Ut(t,x);const u=t.shape,m=u.length,b=t.data,S=t.offset;if(U(z)){const y=b,d=t.size;if(x===void 0){const f=O.zeros([d],z),l=f.data;let N=0,C=0;if(t.isCContiguous)for(let F=0;F<d;F++){const $=y[(S+F)*2],E=y[(S+F)*2+1];q($,E)||(N+=$,C+=E),l[F*2]=N,l[F*2+1]=C}else for(let F=0;F<d;F++){const $=t.iget(F),E=$.re,T=$.im;q(E,T)||(N+=E,C+=T),l[F*2]=N,l[F*2+1]=C}return f}let c=x;if(c<0&&(c=m+c),c<0||c>=m)throw new Error(`axis ${x} is out of bounds for array of dimension ${m}`);const n=O.zeros([...u],z),r=n.data,e=u[c],o=[];let i=1;for(let f=m-1;f>=0;f--)o.unshift(i),i*=u[f];const a=t.size,s=o[c];if(t.isCContiguous)for(let f=0;f<a;f++){const l=y[(S+f)*2],N=y[(S+f)*2+1],C=Math.floor(f/s)%e,B=q(l,N);C===0?(r[f*2]=B?0:l,r[f*2+1]=B?0:N):(r[f*2]=r[(f-s)*2]+(B?0:l),r[f*2+1]=r[(f-s)*2+1]+(B?0:N))}else for(let f=0;f<a;f++){const l=t.iget(f),N=l.re,C=l.im,B=Math.floor(f/s)%e,F=q(N,C);B===0?(r[f*2]=F?0:N,r[f*2+1]=F?0:C):(r[f*2]=r[(f-s)*2]+(F?0:N),r[f*2+1]=r[(f-s)*2+1]+(F?0:C))}return n}if(x===void 0){const y=t.size,d=new Float64Array(y);let c=0;if(t.isCContiguous)for(let r=0;r<y;r++){const e=Number(b[S+r]);isNaN(e)||(c+=e),d[r]=c}else for(let r=0;r<y;r++){const e=Number(t.iget(r));isNaN(e)||(c+=e),d[r]=c}return O.fromData(d,[y],"float64")}let h=x;if(h<0&&(h=m+h),h<0||h>=m)throw new Error(`axis ${x} is out of bounds for array of dimension ${m}`);const A=new Float64Array(t.size),R=u[h],I=[];let w=1;for(let y=m-1;y>=0;y--)I.unshift(w),w*=u[y];const v=t.size,D=I[h];if(t.isCContiguous)for(let y=0;y<v;y++){const d=Number(b[S+y]);Math.floor(y/D)%R===0?A[y]=isNaN(d)?0:d:A[y]=A[y-D]+(isNaN(d)?0:d)}else for(let y=0;y<v;y++){const d=Number(t.iget(y));Math.floor(y/D)%R===0?A[y]=isNaN(d)?0:d:A[y]=A[y-D]+(isNaN(d)?0:d)}return O.fromData(A,[...u],"float64")}function pe(t,x){const z=t.dtype;if(!U(z)&&!H(z))return Pt(t,x);const u=t.shape,m=u.length,b=t.data,S=t.offset;if(U(z)){const y=b,d=t.size;if(x===void 0){const f=O.zeros([d],z),l=f.data;let N=1,C=0;if(t.isCContiguous)for(let F=0;F<d;F++){const $=y[(S+F)*2],E=y[(S+F)*2+1];if(!q($,E)){const T=N*$-C*E,_=N*E+C*$;N=T,C=_}l[F*2]=N,l[F*2+1]=C}else for(let F=0;F<d;F++){const $=t.iget(F),E=$.re,T=$.im;if(!q(E,T)){const _=N*E-C*T,V=N*T+C*E;N=_,C=V}l[F*2]=N,l[F*2+1]=C}return f}let c=x;if(c<0&&(c=m+c),c<0||c>=m)throw new Error(`axis ${x} is out of bounds for array of dimension ${m}`);const n=O.zeros([...u],z),r=n.data,e=u[c],o=[];let i=1;for(let f=m-1;f>=0;f--)o.unshift(i),i*=u[f];const a=t.size,s=o[c];if(t.isCContiguous)for(let f=0;f<a;f++){const l=y[(S+f)*2],N=y[(S+f)*2+1],C=Math.floor(f/s)%e,B=q(l,N);if(C===0)r[f*2]=B?1:l,r[f*2+1]=B?0:N;else{const F=r[(f-s)*2],$=r[(f-s)*2+1];B?(r[f*2]=F,r[f*2+1]=$):(r[f*2]=F*l-$*N,r[f*2+1]=F*N+$*l)}}else for(let f=0;f<a;f++){const l=t.iget(f),N=l.re,C=l.im,B=Math.floor(f/s)%e,F=q(N,C);if(B===0)r[f*2]=F?1:N,r[f*2+1]=F?0:C;else{const $=r[(f-s)*2],E=r[(f-s)*2+1];F?(r[f*2]=$,r[f*2+1]=E):(r[f*2]=$*N-E*C,r[f*2+1]=$*C+E*N)}}return n}if(x===void 0){const y=t.size,d=new Float64Array(y);let c=1;if(t.isCContiguous)for(let r=0;r<y;r++){const e=Number(b[S+r]);isNaN(e)||(c*=e),d[r]=c}else for(let r=0;r<y;r++){const e=Number(t.iget(r));isNaN(e)||(c*=e),d[r]=c}return O.fromData(d,[y],"float64")}let h=x;if(h<0&&(h=m+h),h<0||h>=m)throw new Error(`axis ${x} is out of bounds for array of dimension ${m}`);const A=new Float64Array(t.size),R=u[h],I=[];let w=1;for(let y=m-1;y>=0;y--)I.unshift(w),w*=u[y];const v=t.size,D=I[h];if(t.isCContiguous)for(let y=0;y<v;y++){const d=Number(b[S+y]);Math.floor(y/D)%R===0?A[y]=isNaN(d)?1:d:A[y]=A[y-D]*(isNaN(d)?1:d)}else for(let y=0;y<v;y++){const d=Number(t.iget(y));Math.floor(y/D)%R===0?A[y]=isNaN(d)?1:d:A[y]=A[y-D]*(isNaN(d)?1:d)}return O.fromData(A,[...u],"float64")}function jt(t,x,z=!1){if(ot(t.dtype,"nanmedian","Complex numbers are not orderable."),!H(t.dtype))return qt(t,x,z);const u=t.shape,m=u.length,b=t.data,S=t.offset,h=t.strides;if(x===void 0){const d=[];if(t.isCContiguous)for(let e=0;e<t.size;e++){const o=Number(b[S+e]);isNaN(o)||d.push(o)}else for(let e=0;e<t.size;e++){const o=Number(t.iget(e));isNaN(o)||d.push(o)}if(d.length===0)return NaN;d.sort((e,o)=>e-o);const n=d.length,r=Math.floor(n/2);return n%2===0?(d[r-1]+d[r])/2:d[r]}let A=x;if(A<0&&(A=m+A),A<0||A>=m)throw new Error(`axis ${x} is out of bounds for array of dimension ${m}`);const R=Array.from(u).filter((d,c)=>c!==A);if(R.length===0){const d=jt(t);return z?j(d,m,"float64"):d}const I=R.reduce((d,c)=>d*c,1),w=u[A],v=new Float64Array(I),{baseOffsets:D,axisStride:g}=P(u,h,S,A,I);for(let d=0;d<I;d++){const c=[];let n=D[d];for(let o=0;o<w;o++){const i=Number(b[n]);isNaN(i)||c.push(i),n+=g}if(c.length===0){v[d]=NaN;continue}c.sort((o,i)=>o-i);const r=c.length,e=Math.floor(r/2);r%2===0?v[d]=(c[e-1]+c[e])/2:v[d]=c[e]}const y=O.fromData(v,R,"float64");if(z){const d=[...u];return d[A]=1,O.fromData(v,d,"float64")}return y}function yt(t,x,z,u=!1){if(ot(t.dtype,"nanquantile","Complex numbers are not orderable."),!H(t.dtype))return et(t,x,z,u);if(x<0||x>1)throw new Error("Quantile must be between 0 and 1");const m=t.shape,b=m.length,S=t.data,h=t.offset,A=t.strides;if(z===void 0){const c=[];if(t.isCContiguous)for(let s=0;s<t.size;s++){const p=Number(S[h+s]);isNaN(p)||c.push(p)}else for(let s=0;s<t.size;s++){const p=Number(t.iget(s));isNaN(p)||c.push(p)}if(c.length===0)return NaN;c.sort((s,p)=>s-p);const r=c.length,e=x*(r-1),o=Math.floor(e),i=Math.ceil(e);if(o===i)return c[o];const a=e-o;return c[o]*(1-a)+c[i]*a}let R=z;if(R<0&&(R=b+R),R<0||R>=b)throw new Error(`axis ${z} is out of bounds for array of dimension ${b}`);const I=Array.from(m).filter((c,n)=>n!==R);if(I.length===0){const c=yt(t,x);return u?j(c,b,"float64"):c}const w=I.reduce((c,n)=>c*n,1),v=m[R],D=new Float64Array(w),{baseOffsets:g,axisStride:y}=P(m,A,h,R,w);for(let c=0;c<w;c++){const n=[];let r=g[c];for(let s=0;s<v;s++){const p=Number(S[r]);isNaN(p)||n.push(p),r+=y}if(n.length===0){D[c]=NaN;continue}n.sort((s,p)=>s-p);const e=n.length,o=x*(e-1),i=Math.floor(o),a=Math.ceil(o);if(i===a)D[c]=n[i];else{const s=o-i;D[c]=n[i]*(1-s)+n[a]*s}}const d=O.fromData(D,I,"float64");if(u){const c=[...m];return c[R]=1,O.fromData(D,c,"float64")}return d}function ye(t,x,z,u=!1){return yt(t,x/100,z,u)}export{_t as all,Mt as any,lt as argmax,ft as argmin,ct as average,Pt as cumprod,Ut as cumsum,Y as max,nt as mean,qt as median,Z as min,pt as nanargmax,xt as nanargmin,pe as nancumprod,xe as nancumsum,dt as nanmax,Kt as nanmean,jt as nanmedian,mt as nanmin,ye as nanpercentile,Qt as nanprod,yt as nanquantile,de as nanstd,Wt as nansum,it as nanvar,me as percentile,at as prod,ce as ptp,et as quantile,ue as std,tt as sum,ut as variance};
|
|
1
|
+
import{ArrayStorage as O}from"../storage.js";import{hasFloat16 as mt,isBigIntDType as j,isComplexDType as U,isFloatDType as H,throwIfComplex as dt,reductionAccumDtype as it}from"../dtype.js";import{computeStrides as k,precomputeAxisOffsets as W}from"../internal/indexing.js";import{Complex as Q}from"../complex.js";import{wasmReduceSum as Dt,wasmReduceSumStrided as Ct,wasmReduceSumStridedComplex as Ft,wasmReduceSumComplex as Rt}from"../wasm/reduce_sum.js";import{wasmReduceMax as vt,wasmReduceMaxStrided as $t}from"../wasm/reduce_max.js";import{wasmReduceMin as gt,wasmReduceMinStrided as Bt}from"../wasm/reduce_min.js";import{wasmReduceArgmax as Ot,wasmReduceArgmaxStrided as Et}from"../wasm/reduce_argmax.js";import{wasmReduceArgmin as Tt,wasmReduceArgminStrided as _t}from"../wasm/reduce_argmin.js";import{wasmReduceMean as Vt,wasmReduceMeanStrided as Mt}from"../wasm/reduce_mean.js";import{wasmReduceVar as Ut}from"../wasm/reduce_var.js";import{wasmReduceNansum as Pt}from"../wasm/reduce_nansum.js";import{wasmReduceNanmin as Wt}from"../wasm/reduce_nanmin.js";import{wasmReduceNanmax as qt}from"../wasm/reduce_nanmax.js";import{wasmReduceProd as Qt,wasmReduceProdStrided as Kt,wasmReduceProdStridedComplex as jt}from"../wasm/reduce_prod.js";import{wasmReduceQuantile as Gt,wasmReduceQuantileStrided as Ht}from"../wasm/reduce_quantile.js";import{wasmReduceAny as Jt}from"../wasm/reduce_any.js";import{wasmReduceAll as Lt}from"../wasm/reduce_all.js";import{wasmReduceStd as Xt}from"../wasm/reduce_std.js";const J=new Float32Array(2),Z=typeof globalThis.Float16Array<"u"?new Float16Array(2):null;function Y(r){return r==="float16"?Z:r==="float32"?J:null}function lt(r,b){const S=Y(b);return S?(S[0]=r,S[0]):r}function pt(r){switch(r){case"bool":case"int8":case"int16":case"int32":return"int64";case"uint8":case"uint16":case"uint32":return"uint64";default:return r}}function Yt(r){switch(r){case"bool":case"int8":case"int16":case"int32":case"uint8":case"uint16":case"uint32":case"int64":case"uint64":return"float64";default:return r}}function G(r,b,S){const u=O.zeros(Array(b).fill(1),S);return u.iset(0,r),u}function et(r,b,S=!1){const u=r.dtype,m=r.shape,y=m.length,h=r.size,A=r.data,x=r.offset,D=r.strides,w=r.isCContiguous;if(b===void 0){const e=Dt(r);if(e!==null)return e;if(U(u)){const o=Rt(r);if(o!==null)return new Q(o[0],o[1]);let t=0,s=0;if(w){const a=A;for(let f=0;f<h;f++)t+=a[(x+f)*2],s+=a[(x+f)*2+1]}else for(let a=0;a<h;a++){const f=r.iget(a);t+=f.re,s+=f.im}return new Q(t,s)}else if(j(u)){let o=BigInt(0);if(w){const t=A;for(let s=0;s<h;s++)o+=t[x+s]}else for(let t=0;t<h;t++)o+=r.iget(t);return Number(o)}else if(u==="float32"||u==="float16"&&Z){const o=Y(u);if(o[0]=0,w){const t=u==="float16"?new Float32Array(A.subarray(x,x+h)):A,s=u==="float16"?0:x;for(let a=0;a<h;a++)o[0]+=Number(t[s+a])}else for(let t=0;t<h;t++)o[0]+=Number(r.iget(t));return o[0]}else{let o=0;if(w)if(x===0)for(let t=0;t<h;t++)o+=Number(A[t]);else for(let t=0;t<h;t++)o+=Number(A[x+t]);else for(let t=0;t<h;t++)o+=Number(r.iget(t));return o}}let z=b;if(z<0&&(z=y+z),z<0||z>=y)throw new Error(`axis ${b} is out of bounds for array of dimension ${y}`);const C=pt(u),g=Array.from(m).filter((e,o)=>o!==z);if(g.length===0){const e=et(r);if(!S)return e;const o=O.zeros(Array(y).fill(1),C);return o.iset(0,e),o}const $=m[z],v=g.reduce((e,o)=>e*o,1);if(w&&!U(u)){const e=m.slice(0,z).reduce((s,a)=>s*a,1),o=m.slice(z+1).reduce((s,a)=>s*a,1),t=Ct(r,e,$,o);if(t){const s=S?m.map((a,f)=>f===z?1:a):g;if(C==="float64"){const a=new Array(s.length);let f=1;for(let l=s.length-1;l>=0;l--)a[l]=f,f*=s[l];const N=O.fromDataShared(t.data,s,C,a,0,t.wasmRegion);return t.dispose(),N}try{if(C==="float32"){const l=O.empty(s,C),p=l.data,I=t.data;for(let R=0;R<I.length;R++)p[R]=I[R];return l}const a=O.zeros(g,C),f=a.data,N=t.data;for(let l=0;l<N.length;l++)f[l]=f instanceof BigInt64Array||f instanceof BigUint64Array?BigInt(Math.round(N[l])):N[l];return S?O.fromData(f,s,C):a}finally{t.dispose()}}}const c=O.zeros(g,C),d=c.data,{baseOffsets:i,axisStride:n}=W(m,D,x,z,v);if(U(u)){if(w){const t=m.slice(0,z).reduce((f,N)=>f*N,1),s=m.slice(z+1).reduce((f,N)=>f*N,1),a=Ft(r,t,$,s);if(a){const f=S?m.map((l,p)=>p===z?1:l):g,N=O.fromDataShared(a.data,f,u,k(f),0,a.wasmRegion);return a.dispose(),c.dispose(),N}}const e=A,o=d;if(u==="complex64")for(let t=0;t<v;t++){J[0]=0,J[1]=0;let s=i[t];for(let a=0;a<$;a++)J[0]+=e[s*2],J[1]+=e[s*2+1],s+=n;o[t*2]=J[0],o[t*2+1]=J[1]}else for(let t=0;t<v;t++){let s=0,a=0,f=i[t];for(let N=0;N<$;N++)s+=e[f*2],a+=e[f*2+1],f+=n;o[t*2]=s,o[t*2+1]=a}}else if(j(u)){const e=A,o=d;for(let t=0;t<v;t++){let s=BigInt(0),a=i[t];for(let f=0;f<$;f++)s+=e[a],a+=n;o[t]=s}}else if(j(C)){const e=d;for(let o=0;o<v;o++){let t=0,s=i[o];for(let a=0;a<$;a++)t+=Number(A[s]),s+=n;e[o]=BigInt(Math.round(t))}}else if(u==="float32"||u==="float16"&&Z){const e=Y(u);for(let o=0;o<v;o++){e[0]=0;let t=i[o];for(let s=0;s<$;s++)e[0]+=Number(A[t]),t+=n;d[o]=e[0]}}else for(let e=0;e<v;e++){let o=0,t=i[e];for(let s=0;s<$;s++)o+=Number(A[t]),t+=n;d[e]=o}if(S){const e=[...m];return e[z]=1,O.fromData(d,e,C)}return c}function ft(r,b,S=!1){const u=r.dtype,m=r.shape;if(b===void 0){const x=Vt(r);if(x!==null)return x;if(u==="float16"||u==="float32"){let w=0;const z=r.offset;if(r.isCContiguous)for(let C=0;C<r.size;C++)w+=Number(r.data[z+C]);else for(let C=0;C<r.size;C++)w+=Number(r.iget(C));return lt(w/r.size,u)}const D=et(r);return D instanceof Q?new Q(D.re/r.size,D.im/r.size):D/r.size}let y=b;if(y<0&&(y=m.length+y),y<0||y>=m.length)throw new Error(`axis ${b} is out of bounds for array of dimension ${m.length}`);if(r.isCContiguous&&!U(u)){const x=m[y],D=S?m.map((g,$)=>$===y?1:g):Array.from(m).filter((g,$)=>$!==y),w=m.slice(0,y).reduce((g,$)=>g*$,1),z=m.slice(y+1).reduce((g,$)=>g*$,1),C=Mt(r,w,x,z);if(C){const g=H(u)?u:"float64";if(g==="float64"){const v=new Array(D.length);let c=1;for(let i=D.length-1;i>=0;i--)v[i]=c,c*=D[i];const d=O.fromDataShared(C.data,D,"float64",v,0,C.wasmRegion);return C.dispose(),d}const $=O.empty(D,g);return $.data.set(C.data),C.dispose(),$}}let h;if(u==="float16"||u==="float32"){const x=O.zeros(Array.from(m),"float64"),D=r.data,w=x.data,z=r.offset;if(r.isCContiguous){const g=u==="float16"&&mt?new Float32Array(D.subarray(z,z+r.size)):D,$=u==="float16"&&mt?0:z;for(let v=0;v<r.size;v++)w[v]=Number(g[$+v])}else for(let g=0;g<r.size;g++)w[g]=Number(r.iget(g));const C=et(x,y,S);if(x.dispose(),typeof C=="number")return lt(C/m[y],u);h=C;try{const g=m[y],$=h.data,v=O.empty(Array.from(h.shape),u),c=v.data;for(let d=0;d<$.length;d++)c[d]=$[d]/g;return v}finally{h.dispose()}}const A=et(r,b,S);if(typeof A=="number")return A/m[y];if(A instanceof Q)return new Q(A.re/m[y],A.im/m[y]);try{const x=m[y],D=Yt(u),w=O.zeros(Array.from(A.shape),D),z=w.data,C=A.data,g=A.dtype;if(U(u)){const $=C,v=z,c=A.size;for(let d=0;d<c;d++)v[d*2]=$[d*2]/x,v[d*2+1]=$[d*2+1]/x}else if(j(g)){const $=C;for(let v=0;v<z.length;v++)z[v]=Number($[v])/x}else for(let $=0;$<z.length;$++)z[$]=Number(C[$])/x;return w}finally{A.dispose()}}function ot(r,b,S=!1){const u=r.dtype,m=r.shape,y=m.length,h=r.size,A=r.data,x=r.offset,D=r.strides;if(U(u)){const i=A;if(b===void 0){if(h===0)throw new Error("max of empty array");let l=i[x*2],p=i[x*2+1];for(let I=1;I<h;I++){const R=i[(x+I)*2],F=i[(x+I)*2+1];if(isNaN(R)||isNaN(F))return new Q(NaN,NaN);(R>l||R===l&&F>p)&&(l=R,p=F)}return isNaN(l)||isNaN(p)?new Q(NaN,NaN):new Q(l,p)}let n=b;if(n<0&&(n=y+n),n<0||n>=y)throw new Error(`axis ${b} is out of bounds for array of dimension ${y}`);const e=Array.from(m).filter((l,p)=>p!==n);if(e.length===0){const l=ot(r);return S?G(l,y,u):l}const o=O.zeros(e,u),t=o.data,s=m[n],a=e.reduce((l,p)=>l*p,1),{baseOffsets:f,axisStride:N}=W(m,D,x,n,a);for(let l=0;l<a;l++){let p=f[l],I=i[p*2],R=i[p*2+1];p+=N;for(let F=1;F<s;F++){const B=i[p*2],E=i[p*2+1];if(p+=N,isNaN(B)||isNaN(E)){I=NaN,R=NaN;break}(B>I||B===I&&E>R)&&(I=B,R=E)}t[l*2]=I,t[l*2+1]=R}if(S){const l=[...m];return l[n]=1,O.fromData(t,l,u)}return o}if(b===void 0){const i=vt(r);if(i!==null)return i;if(h===0)throw new Error("max of empty array");if(r.isCContiguous){let n=A[x];if(x===0)for(let e=1;e<h;e++)A[e]>n&&(n=A[e]);else for(let e=1;e<h;e++)A[x+e]>n&&(n=A[x+e]);return Number(n)}else{let n=r.iget(0);for(let e=1;e<h;e++){const o=r.iget(e);o>n&&(n=o)}return Number(n)}}let w=b;if(w<0&&(w=y+w),w<0||w>=y)throw new Error(`axis ${b} is out of bounds for array of dimension ${y}`);const z=Array.from(m).filter((i,n)=>n!==w);if(z.length===0){const i=ot(r);return S?G(i,y,u):i}const C=m[w],g=z.reduce((i,n)=>i*n,1);if(r.isCContiguous&&!U(u)){const i=m.slice(0,w).reduce((o,t)=>o*t,1),n=m.slice(w+1).reduce((o,t)=>o*t,1),e=$t(r,i,C,n);if(e){const o=S?m.map((f,N)=>N===w?1:f):z,t=new Array(o.length);let s=1;for(let f=o.length-1;f>=0;f--)t[f]=s,s*=o[f];const a=O.fromDataShared(e.data,o,u,t,0,e.wasmRegion);return e.dispose(),a}}const $=O.zeros(z,u),v=$.data,{baseOffsets:c,axisStride:d}=W(m,D,x,w,g);if(j(u)){const i=A,n=v;for(let e=0;e<g;e++){let o=c[e],t=i[o];o+=d;for(let s=1;s<C;s++){const a=i[o];a>t&&(t=a),o+=d}n[e]=t}}else for(let i=0;i<g;i++){let n=-1/0,e=c[i];for(let o=0;o<C;o++){const t=Number(A[e]);t>n&&(n=t),e+=d}v[i]=n}if(S){const i=[...m];return i[w]=1,O.fromData(v,i,u)}return $}function yt(r,b,S=!1){const u=r.dtype,m=r.shape,y=m.length,h=r.size,A=r.data,x=r.offset,D=r.strides,w=r.isCContiguous;if(b===void 0){const e=Qt(r);if(e!==null)return e;if(U(u)){let o=1,t=0;if(w){const s=A;for(let a=0;a<h;a++){const f=s[(x+a)*2],N=s[(x+a)*2+1],l=o*f-t*N,p=o*N+t*f;o=l,t=p}}else for(let s=0;s<h;s++){const a=r.iget(s),f=a.re,N=a.im,l=o*f-t*N,p=o*N+t*f;o=l,t=p}return new Q(o,t)}else if(j(u)){let o=BigInt(1);if(w){const t=A;for(let s=0;s<h;s++)o*=t[x+s]}else for(let t=0;t<h;t++)o*=r.iget(t);return Number(o)}else if(u==="float32"||u==="float16"&&Z){const o=Y(u);if(o[0]=1,w)for(let t=0;t<h;t++)o[0]*=Number(A[x+t]);else for(let t=0;t<h;t++)o[0]*=Number(r.iget(t));return o[0]}else{let o=1;if(w)if(x===0)for(let t=0;t<h;t++)o*=Number(A[t]);else for(let t=0;t<h;t++)o*=Number(A[x+t]);else for(let t=0;t<h;t++)o*=Number(r.iget(t));return o}}let z=b;if(z<0&&(z=y+z),z<0||z>=y)throw new Error(`axis ${b} is out of bounds for array of dimension ${y}`);const C=pt(u),g=Array.from(m).filter((e,o)=>o!==z);if(g.length===0){const e=yt(r);return S?G(e,y,C):e}const $=m[z],v=g.reduce((e,o)=>e*o,1);if(w&&!U(u)){const e=m.slice(0,z).reduce((s,a)=>s*a,1),o=m.slice(z+1).reduce((s,a)=>s*a,1),t=Kt(r,e,$,o);if(t){const s=S?m.map((l,p)=>p===z?1:l):g,a=new Array(s.length);let f=1;for(let l=s.length-1;l>=0;l--)a[l]=f,f*=s[l];const N=O.fromDataShared(t.data,s,C,a,0,t.wasmRegion);return t.dispose(),N}}const c=O.zeros(g,C),d=c.data,{baseOffsets:i,axisStride:n}=W(m,D,x,z,v);if(U(u)){if(w){const t=m.slice(0,z).reduce((f,N)=>f*N,1),s=m.slice(z+1).reduce((f,N)=>f*N,1),a=jt(r,t,$,s);if(a){const f=S?m.map((l,p)=>p===z?1:l):g,N=O.fromDataShared(a.data,f,u,k(f),0,a.wasmRegion);return a.dispose(),c.dispose(),N}}const e=A,o=d;if(u==="complex64")for(let t=0;t<v;t++){J[0]=1,J[1]=0;let s=i[t];for(let a=0;a<$;a++){const f=e[s*2],N=e[s*2+1],l=J[0],p=J[1];J[0]=l*f-p*N,J[1]=l*N+p*f,s+=n}o[t*2]=J[0],o[t*2+1]=J[1]}else for(let t=0;t<v;t++){let s=1,a=0,f=i[t];for(let N=0;N<$;N++){const l=e[f*2],p=e[f*2+1],I=s*l-a*p,R=s*p+a*l;s=I,a=R,f+=n}o[t*2]=s,o[t*2+1]=a}}else if(j(u)){const e=A,o=d;for(let t=0;t<v;t++){let s=BigInt(1),a=i[t];for(let f=0;f<$;f++)s*=e[a],a+=n;o[t]=s}}else if(j(C)){const e=d;for(let o=0;o<v;o++){let t=BigInt(1),s=i[o];for(let a=0;a<$;a++)t*=BigInt(Number(A[s])),s+=n;e[o]=t}}else if(u==="float32"||u==="float16"&&Z){const e=Y(u);for(let o=0;o<v;o++){e[0]=1;let t=i[o];for(let s=0;s<$;s++)e[0]*=Number(A[t]),t+=n;d[o]=e[0]}}else for(let e=0;e<v;e++){let o=1,t=i[e];for(let s=0;s<$;s++)o*=Number(A[t]),t+=n;d[e]=o}if(S){const e=[...m];return e[z]=1,O.fromData(d,e,C)}return c}function nt(r,b,S=!1){const u=r.dtype,m=r.shape,y=m.length,h=r.size,A=r.data,x=r.offset,D=r.strides;if(U(u)){const i=A;if(b===void 0){if(h===0)throw new Error("min of empty array");let l=i[x*2],p=i[x*2+1];for(let I=1;I<h;I++){const R=i[(x+I)*2],F=i[(x+I)*2+1];if(isNaN(R)||isNaN(F))return new Q(NaN,NaN);(R<l||R===l&&F<p)&&(l=R,p=F)}return isNaN(l)||isNaN(p)?new Q(NaN,NaN):new Q(l,p)}let n=b;if(n<0&&(n=y+n),n<0||n>=y)throw new Error(`axis ${b} is out of bounds for array of dimension ${y}`);const e=Array.from(m).filter((l,p)=>p!==n);if(e.length===0){const l=nt(r);return S?G(l,y,u):l}const o=O.zeros(e,u),t=o.data,s=m[n],a=e.reduce((l,p)=>l*p,1),{baseOffsets:f,axisStride:N}=W(m,D,x,n,a);for(let l=0;l<a;l++){let p=f[l],I=i[p*2],R=i[p*2+1];p+=N;for(let F=1;F<s;F++){const B=i[p*2],E=i[p*2+1];if(p+=N,isNaN(B)||isNaN(E)){I=NaN,R=NaN;break}(B<I||B===I&&E<R)&&(I=B,R=E)}t[l*2]=I,t[l*2+1]=R}if(S){const l=[...m];return l[n]=1,O.fromData(t,l,u)}return o}if(b===void 0){const i=gt(r);if(i!==null)return i;if(h===0)throw new Error("min of empty array");if(r.isCContiguous){let n=A[x];if(x===0)for(let e=1;e<h;e++)A[e]<n&&(n=A[e]);else for(let e=1;e<h;e++)A[x+e]<n&&(n=A[x+e]);return Number(n)}else{let n=r.iget(0);for(let e=1;e<h;e++){const o=r.iget(e);o<n&&(n=o)}return Number(n)}}let w=b;if(w<0&&(w=y+w),w<0||w>=y)throw new Error(`axis ${b} is out of bounds for array of dimension ${y}`);const z=Array.from(m).filter((i,n)=>n!==w);if(z.length===0){const i=nt(r);return S?G(i,y,u):i}const C=m[w],g=z.reduce((i,n)=>i*n,1);if(r.isCContiguous&&!U(u)){const i=m.slice(0,w).reduce((o,t)=>o*t,1),n=m.slice(w+1).reduce((o,t)=>o*t,1),e=Bt(r,i,C,n);if(e){const o=S?m.map((f,N)=>N===w?1:f):z,t=new Array(o.length);let s=1;for(let f=o.length-1;f>=0;f--)t[f]=s,s*=o[f];const a=O.fromDataShared(e.data,o,u,t,0,e.wasmRegion);return e.dispose(),a}}const $=O.zeros(z,u),v=$.data,{baseOffsets:c,axisStride:d}=W(m,D,x,w,g);if(j(u)){const i=A,n=v;for(let e=0;e<g;e++){let o=c[e],t=i[o];o+=d;for(let s=1;s<C;s++){const a=i[o];a<t&&(t=a),o+=d}n[e]=t}}else for(let i=0;i<g;i++){let n=1/0,e=c[i];for(let o=0;o<C;o++){const t=Number(A[e]);t<n&&(n=t),e+=d}v[i]=n}if(S){const i=[...m];return i[w]=1,O.fromData(v,i,u)}return $}function X(r,b,S,u){return r<S?-1:r>S?1:b<u?-1:b>u?1:0}function xt(r,b){const S=r.dtype,u=U(S),m=r.shape,y=m.length,h=r.size,A=r.data,x=r.offset,D=r.strides,w=r.isCContiguous;if(b===void 0){const n=Tt(r);if(n!==null)return n;if(h===0)throw new Error("argmin of empty array");if(u)if(w){const e=A;let o=e[x*2],t=e[x*2+1],s=0;for(let a=1;a<h;a++){const f=e[(x+a)*2],N=e[(x+a)*2+1];X(f,N,o,t)<0&&(o=f,t=N,s=a)}return s}else{const e=r.iget(0);let o=e.re,t=e.im,s=0;for(let a=1;a<h;a++){const f=r.iget(a);X(f.re,f.im,o,t)<0&&(o=f.re,t=f.im,s=a)}return s}if(w){let e=A[x],o=0;if(x===0)for(let t=1;t<h;t++)A[t]<e&&(e=A[t],o=t);else for(let t=1;t<h;t++)A[x+t]<e&&(e=A[x+t],o=t);return o}else{let e=r.iget(0),o=0;for(let t=1;t<h;t++){const s=r.iget(t);s<e&&(e=s,o=t)}return o}}let z=b;if(z<0&&(z=y+z),z<0||z>=y)throw new Error(`axis ${b} is out of bounds for array of dimension ${y}`);const C=Array.from(m).filter((n,e)=>e!==z);if(C.length===0)return xt(r);const g=m[z];if(r.isCContiguous&&!U(S)){const n=m.slice(0,z).reduce((t,s)=>t*s,1),e=m.slice(z+1).reduce((t,s)=>t*s,1),o=_t(r,n,g,e);if(o){const t=new Array(C.length);let s=1;for(let f=C.length-1;f>=0;f--)t[f]=s,s*=C[f];const a=O.fromDataShared(o.data,C,"int32",t,0,o.wasmRegion);return o.dispose(),a}}const $=O.zeros(C,"int32"),v=$.data,c=C.reduce((n,e)=>n*e,1),{baseOffsets:d,axisStride:i}=W(m,D,x,z,c);if(u){const n=A;for(let e=0;e<c;e++){let o=d[e],t=n[o*2],s=n[o*2+1],a=0;o+=i;for(let f=1;f<g;f++){const N=n[o*2],l=n[o*2+1];X(N,l,t,s)<0&&(t=N,s=l,a=f),o+=i}v[e]=a}}else if(j(S)){const n=A;for(let e=0;e<c;e++){let o=d[e],t=n[o],s=0;o+=i;for(let a=1;a<g;a++){const f=n[o];f<t&&(t=f,s=a),o+=i}v[e]=s}}else for(let n=0;n<c;n++){let e=1/0,o=0,t=d[n];for(let s=0;s<g;s++){const a=Number(A[t]);a<e&&(e=a,o=s),t+=i}v[n]=o}return $}function bt(r,b){const S=r.dtype,u=U(S),m=r.shape,y=m.length,h=r.size,A=r.data,x=r.offset,D=r.strides,w=r.isCContiguous;if(b===void 0){const n=Ot(r);if(n!==null)return n;if(h===0)throw new Error("argmax of empty array");if(u)if(w){const e=A;let o=e[x*2],t=e[x*2+1],s=0;for(let a=1;a<h;a++){const f=e[(x+a)*2],N=e[(x+a)*2+1];X(f,N,o,t)>0&&(o=f,t=N,s=a)}return s}else{const e=r.iget(0);let o=e.re,t=e.im,s=0;for(let a=1;a<h;a++){const f=r.iget(a);X(f.re,f.im,o,t)>0&&(o=f.re,t=f.im,s=a)}return s}if(w){let e=A[x],o=0;for(let t=1;t<h;t++)A[x+t]>e&&(e=A[x+t],o=t);return o}else{let e=r.iget(0),o=0;for(let t=1;t<h;t++){const s=r.iget(t);s>e&&(e=s,o=t)}return o}}let z=b;if(z<0&&(z=y+z),z<0||z>=y)throw new Error(`axis ${b} is out of bounds for array of dimension ${y}`);const C=Array.from(m).filter((n,e)=>e!==z);if(C.length===0)return bt(r);const g=m[z];if(r.isCContiguous&&!U(S)){const n=m.slice(0,z).reduce((t,s)=>t*s,1),e=m.slice(z+1).reduce((t,s)=>t*s,1),o=Et(r,n,g,e);if(o){const t=new Array(C.length);let s=1;for(let f=C.length-1;f>=0;f--)t[f]=s,s*=C[f];const a=O.fromDataShared(o.data,C,"int32",t,0,o.wasmRegion);return o.dispose(),a}}const $=O.zeros(C,"int32"),v=$.data,c=C.reduce((n,e)=>n*e,1),{baseOffsets:d,axisStride:i}=W(m,D,x,z,c);if(u){const n=A;for(let e=0;e<c;e++){let o=d[e],t=n[o*2],s=n[o*2+1],a=0;o+=i;for(let f=1;f<g;f++){const N=n[o*2],l=n[o*2+1];X(N,l,t,s)>0&&(t=N,s=l,a=f),o+=i}v[e]=a}}else if(j(S)){const n=A;for(let e=0;e<c;e++){let o=d[e],t=n[o],s=0;o+=i;for(let a=1;a<g;a++){const f=n[o];f>t&&(t=f,s=a),o+=i}v[e]=s}}else for(let n=0;n<c;n++){let e=-1/0,o=0,t=d[n];for(let s=0;s<g;s++){const a=Number(A[t]);a>e&&(e=a,o=s),t+=i}v[n]=o}return $}function At(r,b,S=0,u=!1){const m=r.dtype,y=r.shape,h=y.length,A=r.size,x=r.data,D=r.offset,w=r.strides;let z;if(m==="float16"&&b===void 0&&Z){const c=et(r);Z[0]=c,Z[0]/=A,z=Z[0]}else z=ft(r,b,u);const C=r.isCContiguous;if(b===void 0){const c=Ut(r);if(c!==null)return c;if(U(m)){const e=z;let o=0;if(C){const t=x;for(let s=0;s<A;s++){const a=t[(D+s)*2],f=t[(D+s)*2+1],N=a-e.re,l=f-e.im;o+=N*N+l*l}}else for(let t=0;t<A;t++){const s=r.iget(t),a=s.re-e.re,f=s.im-e.im;o+=a*a+f*f}return o/(A-S)}const d=z,i=Y(m);if(i){if(i[0]=0,C)for(let e=0;e<A;e++){const o=Number(x[D+e])-d;i[0]+=o*o}else for(let e=0;e<A;e++){const o=Number(r.iget(e))-d;i[0]+=o*o}return i[0]/=A-S,i[0]}let n=0;if(C)for(let e=0;e<A;e++){const o=Number(x[D+e])-d;n+=o*o}else for(let e=0;e<A;e++){const o=Number(r.iget(e))-d;n+=o*o}return n/(A-S)}let g=b;if(g<0&&(g=h+g),g<0||g>=h)throw new Error(`axis ${b} is out of bounds for array of dimension ${h}`);const $=y[g],v=z;try{const c=v.data,d=u?v.shape:Array.from(y).filter((s,a)=>a!==g),i=O.zeros(Array.from(d),"float64"),n=i.data,e=d.reduce((s,a)=>s*a,1),{baseOffsets:o,axisStride:t}=W(y,w,D,g,e);if(U(m)){const s=x,a=c;for(let f=0;f<e;f++){let N=0;const l=a[f*2],p=a[f*2+1];let I=o[f];for(let R=0;R<$;R++){const F=s[I*2],B=s[I*2+1],E=F-l,T=B-p;N+=E*E+T*T,I+=t}n[f]=N/($-S)}}else{const s=Y(m);if(s){i.dispose();const a=O.empty(Array.from(d),m),f=a.data;for(let N=0;N<e;N++){s[0]=0;const l=Number(c[N]);let p=o[N];for(let I=0;I<$;I++){const R=Number(x[p])-l;s[0]+=R*R,p+=t}s[0]/=$-S,f[N]=s[0]}return a}for(let a=0;a<e;a++){let f=0;const N=Number(c[a]);let l=o[a];for(let p=0;p<$;p++){const I=Number(x[l])-N;f+=I*I,l+=t}n[a]=f/($-S)}}return i}finally{v.dispose()}}function Ce(r,b,S=0,u=!1){if(b===void 0&&S===0&&!u){const y=Xt(r);if(y!==null)return y}const m=At(r,b,S,u);if(typeof m=="number")return Math.sqrt(m);try{const y=O.zeros(Array.from(m.shape),"float64"),h=m.data,A=y.data;for(let x=0;x<h.length;x++)A[x]=Math.sqrt(Number(h[x]));return y}finally{m.dispose()}}function Zt(r,b,S=!1){const u=r.shape,m=u.length,y=r.size,h=r.data,A=r.offset,x=r.strides,D=r.isCContiguous,w=U(r.dtype);if(b===void 0){const n=Lt(r);if(n!==null)return n===1;if(w){if(D){const e=h;for(let o=0;o<y;o++){const t=e[(A+o)*2],s=e[(A+o)*2+1];if(t===0&&s===0)return!1}}else for(let e=0;e<y;e++){const o=r.iget(e);if(o.re===0&&o.im===0)return!1}return!0}if(D){for(let e=0;e<y;e++)if(!h[A+e])return!1}else for(let e=0;e<y;e++)if(!r.iget(e))return!1;return!0}let z=b;if(z<0&&(z=m+z),z<0||z>=m)throw new Error(`axis ${b} is out of bounds for array of dimension ${m}`);const C=Array.from(u).filter((n,e)=>e!==z);if(C.length===0){const n=Zt(r);if(!S)return n;const e=O.zeros(Array(m).fill(1),"bool");return e.iset(0,n?1:0),e}const g=O.zeros(C,"bool"),$=g.data,v=u[z],c=C.reduce((n,e)=>n*e,1),{baseOffsets:d,axisStride:i}=W(u,x,A,z,c);if(w){const n=h;for(let e=0;e<c;e++){let o=!0,t=d[e];for(let s=0;s<v;s++){const a=n[t*2],f=n[t*2+1];if(a===0&&f===0){o=!1;break}t+=i}$[e]=o?1:0}}else for(let n=0;n<c;n++){let e=!0,o=d[n];for(let t=0;t<v;t++){if(!h[o]){e=!1;break}o+=i}$[n]=e?1:0}if(S){const n=[...u];return n[z]=1,O.fromData($,n,"bool")}return g}function kt(r,b,S=!1){const u=r.shape,m=u.length,y=r.size,h=r.data,A=r.offset,x=r.strides,D=r.isCContiguous,w=U(r.dtype);if(b===void 0){const n=Jt(r);if(n!==null)return n===1;if(w){if(D){const e=h;for(let o=0;o<y;o++){const t=e[(A+o)*2],s=e[(A+o)*2+1];if(t!==0||s!==0)return!0}}else for(let e=0;e<y;e++){const o=r.iget(e);if(o.re!==0||o.im!==0)return!0}return!1}if(D){for(let e=0;e<y;e++)if(h[A+e])return!0}else for(let e=0;e<y;e++)if(r.iget(e))return!0;return!1}let z=b;if(z<0&&(z=m+z),z<0||z>=m)throw new Error(`axis ${b} is out of bounds for array of dimension ${m}`);const C=Array.from(u).filter((n,e)=>e!==z);if(C.length===0){const n=kt(r);if(!S)return n;const e=O.zeros(Array(m).fill(1),"bool");return e.iset(0,n?1:0),e}const g=O.zeros(C,"bool"),$=g.data,v=u[z],c=C.reduce((n,e)=>n*e,1),{baseOffsets:d,axisStride:i}=W(u,x,A,z,c);if(w){const n=h;for(let e=0;e<c;e++){let o=!1,t=d[e];for(let s=0;s<v;s++){const a=n[t*2],f=n[t*2+1];if(a!==0||f!==0){o=!0;break}t+=i}$[e]=o?1:0}}else for(let n=0;n<c;n++){let e=!1,o=d[n];for(let t=0;t<v;t++){if(h[o]){e=!0;break}o+=i}$[n]=e?1:0}if(S){const n=[...u];return n[z]=1,O.fromData($,n,"bool")}return g}function te(r,b){const S=r.dtype,u=r.shape,m=u.length,y=r.data,h=r.offset,A=r.strides,x=r.isCContiguous;if(U(S)){const t=y,s=r.size;if(b===void 0){const _=O.zeros([s],S),V=_.data;let M=0,P=0;if(x)for(let q=0;q<s;q++)M+=t[(h+q)*2],P+=t[(h+q)*2+1],V[q*2]=M,V[q*2+1]=P;else for(let q=0;q<s;q++){const L=r.iget(q);M+=L.re,P+=L.im,V[q*2]=M,V[q*2+1]=P}return _}let a=b;if(a<0&&(a=m+a),a<0||a>=m)throw new Error(`axis ${b} is out of bounds for array of dimension ${m}`);const f=O.zeros([...u],S),N=f.data,l=u[a],p=Array.from(u).filter((_,V)=>V!==a),I=p.length===0?1:p.reduce((_,V)=>_*V,1),{baseOffsets:R,axisStride:F}=W(u,A,h,a,I),B=k(u),{baseOffsets:E,axisStride:T}=W(u,B,0,a,I);for(let _=0;_<I;_++){let V=R[_],M=E[_],P=0,q=0;for(let L=0;L<l;L++)P+=t[V*2],q+=t[V*2+1],N[M*2]=P,N[M*2+1]=q,V+=F,M+=T}return f}if(b===void 0){const t=r.size,s=Y(S);if(s){const p=O.empty([t],S),I=p.data;if(s[0]=0,x)for(let R=0;R<t;R++)s[0]+=Number(y[h+R]),I[R]=s[0];else for(let R=0;R<t;R++)s[0]+=Number(r.iget(R)),I[R]=s[0];return p}const a=it(S);if(j(S)){const p=O.empty([t],a),I=p.data;let R=0n;if(x)for(let F=0;F<t;F++)R+=y[h+F],I[F]=R;else for(let F=0;F<t;F++)R+=r.iget(F),I[F]=R;return p}if(j(a)){const p=O.empty([t],a),I=p.data;let R=0;if(x)for(let F=0;F<t;F++)R+=y[h+F],I[F]=BigInt(R);else for(let F=0;F<t;F++)R+=Number(r.iget(F)),I[F]=BigInt(R);return p}const f=O.empty([t],a),N=f.data;let l=0;if(x)for(let p=0;p<t;p++)l+=Number(y[h+p]),N[p]=l;else for(let p=0;p<t;p++)l+=Number(r.iget(p)),N[p]=l;return f}let D=b;if(D<0&&(D=m+D),D<0||D>=m)throw new Error(`axis ${b} is out of bounds for array of dimension ${m}`);const w=Y(S),z=w?S:it(S),C=O.empty([...u],z),g=C.data,$=u[D],v=Array.from(u).filter((t,s)=>s!==D),c=v.length===0?1:v.reduce((t,s)=>t*s,1),{baseOffsets:d,axisStride:i}=W(u,A,h,D,c),n=k(u),{baseOffsets:e,axisStride:o}=W(u,n,0,D,c);if(w)for(let t=0;t<c;t++){let s=d[t],a=e[t];w[0]=0;for(let f=0;f<$;f++)w[0]+=Number(y[s]),g[a]=w[0],s+=i,a+=o}else if(j(S)){const t=g;for(let s=0;s<c;s++){let a=d[s],f=e[s],N=0n;for(let l=0;l<$;l++)N+=y[a],t[f]=N,a+=i,f+=o}}else if(j(z)){const t=g;for(let s=0;s<c;s++){let a=d[s],f=e[s],N=0;for(let l=0;l<$;l++)N+=y[a],t[f]=BigInt(N),a+=i,f+=o}}else for(let t=0;t<c;t++){let s=d[t],a=e[t],f=0;for(let N=0;N<$;N++)f+=Number(y[s]),g[a]=f,s+=i,a+=o}return C}function ee(r,b){const S=r.dtype,u=r.shape,m=u.length,y=r.data,h=r.offset,A=r.strides,x=r.isCContiguous;if(U(S)){const o=y,t=r.size;if(b===void 0){const T=O.zeros([t],S),_=T.data;let V=1,M=0;if(x)for(let P=0;P<t;P++){const q=o[(h+P)*2],L=o[(h+P)*2+1],tt=V*q-M*L,rt=V*L+M*q;V=tt,M=rt,_[P*2]=V,_[P*2+1]=M}else for(let P=0;P<t;P++){const q=r.iget(P),L=q.re,tt=q.im,rt=V*L-M*tt,at=V*tt+M*L;V=rt,M=at,_[P*2]=V,_[P*2+1]=M}return T}let s=b;if(s<0&&(s=m+s),s<0||s>=m)throw new Error(`axis ${b} is out of bounds for array of dimension ${m}`);const a=O.zeros([...u],S),f=a.data,N=u[s],l=Array.from(u).filter((T,_)=>_!==s),p=l.length===0?1:l.reduce((T,_)=>T*_,1),{baseOffsets:I,axisStride:R}=W(u,A,h,s,p),F=k(u),{baseOffsets:B,axisStride:E}=W(u,F,0,s,p);for(let T=0;T<p;T++){let _=I[T],V=B[T],M=1,P=0;for(let q=0;q<N;q++){const L=o[_*2],tt=o[_*2+1],rt=M*L-P*tt,at=M*tt+P*L;M=rt,P=at,f[V*2]=M,f[V*2+1]=P,_+=R,V+=E}}return a}if(b===void 0){const o=r.size,t=it(S);if(j(S)){const N=O.empty([o],t),l=N.data;let p=1n;if(x)for(let I=0;I<o;I++)p*=y[h+I],l[I]=p;else for(let I=0;I<o;I++)p*=r.iget(I),l[I]=p;return N}if(j(t)){const N=O.empty([o],t),l=N.data;let p=1;if(x)for(let I=0;I<o;I++)p*=y[h+I],l[I]=BigInt(p);else for(let I=0;I<o;I++)p*=Number(r.iget(I)),l[I]=BigInt(p);return N}const s=O.empty([o],t),a=s.data;let f=1;if(x)for(let N=0;N<o;N++)f*=Number(y[h+N]),a[N]=f;else for(let N=0;N<o;N++)f*=Number(r.iget(N)),a[N]=f;return s}let D=b;if(D<0&&(D=m+D),D<0||D>=m)throw new Error(`axis ${b} is out of bounds for array of dimension ${m}`);const w=it(S),z=O.empty([...u],w),C=z.data,g=u[D],$=Array.from(u).filter((o,t)=>t!==D),v=$.length===0?1:$.reduce((o,t)=>o*t,1),{baseOffsets:c,axisStride:d}=W(u,A,h,D,v),i=k(u),{baseOffsets:n,axisStride:e}=W(u,i,0,D,v);if(j(S)){const o=C;for(let t=0;t<v;t++){let s=c[t],a=n[t],f=1n;for(let N=0;N<g;N++)f*=y[s],o[a]=f,s+=d,a+=e}}else if(j(w)){const o=C;for(let t=0;t<v;t++){let s=c[t],a=n[t],f=1;for(let N=0;N<g;N++)f*=y[s],o[a]=BigInt(f),s+=d,a+=e}}else for(let o=0;o<v;o++){let t=c[o],s=n[o],a=1;for(let f=0;f<g;f++)a*=Number(y[t]),C[s]=a,t+=d,s+=e}return z}function Fe(r,b,S=!1){const u=r.dtype;if(u==="bool")throw new TypeError("ufunc 'subtract' not supported for boolean dtype. The '-' operator is not supported for booleans, use 'bitwise_xor' instead.");if(U(u)){const x=ot(r,b,S),D=nt(r,b,S);if(x instanceof Q&&D instanceof Q)return new Q(x.re-D.re,x.im-D.im);const w=x,z=D;try{const C=w.data,g=z.data,$=O.empty([...w.shape],u),v=$.data;for(let c=0;c<w.size;c++)v[c*2]=C[c*2]-g[c*2],v[c*2+1]=C[c*2+1]-g[c*2+1];return $}finally{w.dispose(),z.dispose()}}const m=ot(r,b,S),y=nt(r,b,S);if(typeof m=="number"&&typeof y=="number"){const x=m-y;if(u==="int8"||u==="int16"||u==="int32"||u==="uint8"||u==="uint16"||u==="uint32"){const D=O.zeros([1],u);try{return D.iset(0,x),Number(D.iget(0))}finally{D.dispose()}}return x}const h=m,A=y;try{const x=h.data,D=A.data,w=O.zeros([...h.shape],u),z=w.data;for(let C=0;C<h.size;C++)z[C]=Number(x[C])-Number(D[C]);return w}finally{h.dispose(),A.dispose()}}function ut(r,b,S,u){const m=r.dtype,y=r.shape,h=y.length;if(b===void 0||h===1){const v=r.size,c=[];if(r.isCContiguous){const n=r.data,e=r.offset;for(let o=0;o<v;o++){const t=n[(e+o)*2],s=n[(e+o)*2+1];u&&(isNaN(t)||isNaN(s))||c.push([t,s])}}else for(let n=0;n<v;n++){const e=r.iget(n);u&&(isNaN(e.re)||isNaN(e.im))||c.push([e.re,e.im])}c.sort((n,e)=>n[0]!==e[0]?n[0]-e[0]:n[1]-e[1]);const d=c.length;if(d===0)return new Q(NaN,NaN);const i=Math.floor(d/2);return d%2===1?new Q(c[i][0],c[i][1]):new Q((c[i-1][0]+c[i][0])/2,(c[i-1][1]+c[i][1])/2)}let A=b;if(A<0&&(A+=h),A<0||A>=h)throw new Error(`axis ${b} is out of bounds for array of dimension ${h}`);const x=Array.from(y).filter((v,c)=>c!==A);if(x.length===0){const v=ut(r,void 0,!1,u);return S?G(v,h,m):v}const D=x.reduce((v,c)=>v*c,1),w=y[A],z=O.empty(x,m),C=z.data,g=Array.from(y).slice(A+1).reduce((v,c)=>v*c,1),$=w*g;for(let v=0;v<D;v++){const c=Math.floor(v/g),d=v%g,i=c*$+d,n=[];for(let t=0;t<w;t++){const s=i+t*g,a=r.iget(s);u&&(isNaN(a.re)||isNaN(a.im))||n.push([a.re,a.im])}n.sort((t,s)=>t[0]!==s[0]?t[0]-s[0]:t[1]-s[1]);const e=n.length,o=Math.floor(e/2);e===0?(C[v*2]=NaN,C[v*2+1]=NaN):e%2===1?(C[v*2]=n[o][0],C[v*2+1]=n[o][1]):(C[v*2]=(n[o-1][0]+n[o][0])/2,C[v*2+1]=(n[o-1][1]+n[o][1])/2)}if(S){const v=Array.from(y);return v[A]=1,O.fromData(z.data,v,m)}return z}function re(r,b,S=!1){if(r.dtype==="bool"){const u=O.empty(Array.from(r.shape),"float64"),m=r.data,y=u.data,h=r.offset;if(r.isCContiguous)for(let A=0;A<r.size;A++)y[A]=Number(m[h+A]);else for(let A=0;A<r.size;A++)y[A]=Number(r.iget(A));try{return st(u,.5,b,S)}finally{u.dispose()}}return U(r.dtype)?ut(r,b,S,!1):st(r,.5,b,S)}function Re(r,b,S,u=!1){return st(r,b/100,S,u)}function st(r,b,S,u=!1){if(dt(r.dtype,"quantile","Complex numbers are not orderable."),r.dtype==="bool")throw new TypeError("ufunc 'subtract' not supported for boolean dtype. The '-' operator is not supported for booleans, use 'bitwise_xor' instead.");if(b<0||b>1)throw new Error("Quantile must be between 0 and 1");const m=r.shape,y=m.length,h=r.data,A=r.offset,x=r.strides;if(S===void 0){const i=Gt(r,b);if(i!==null)return i;const n=[];if(r.isCContiguous)for(let N=0;N<r.size;N++)n.push(Number(h[A+N]));else for(let N=0;N<r.size;N++)n.push(Number(r.iget(N)));n.sort((N,l)=>N-l);const o=n.length,t=b*(o-1),s=Math.floor(t),a=Math.ceil(t);if(s===a)return n[s];const f=t-s;return n[s]*(1-f)+n[a]*f}let D=S;if(D<0&&(D=y+D),D<0||D>=y)throw new Error(`axis ${S} is out of bounds for array of dimension ${y}`);const w=Array.from(m).filter((i,n)=>n!==D);if(w.length===0){const i=st(r,b);if(!u)return i;const n=O.zeros(Array(y).fill(1),"float64");return n.iset(0,i),n}const z=m[D];if(r.isCContiguous&&!U(r.dtype)){const i=m.slice(0,D).reduce((o,t)=>o*t,1),n=m.slice(D+1).reduce((o,t)=>o*t,1),e=Ht(r,i,z,n,b);if(e){if(u){const t=[...m];t[D]=1;const s=O.fromDataShared(e.data,t,"float64",k(t),0,e.wasmRegion);return e.dispose(),s}const o=O.fromDataShared(e.data,w,"float64",k(w),0,e.wasmRegion);return e.dispose(),o}}const C=w.reduce((i,n)=>i*n,1),g=O.empty(w,"float64"),$=g.data,{baseOffsets:v,axisStride:c}=W(m,x,A,D,C),d=new Float64Array(z);for(let i=0;i<C;i++){let n=v[i];for(let f=0;f<z;f++)d[f]=Number(h[n]),n+=c;d.sort();const e=z,o=d,t=b*(e-1),s=Math.floor(t),a=Math.ceil(t);if(s===a)$[i]=o[s];else{const f=t-s;$[i]=o[s]*(1-f)+o[a]*f}}if(u){const i=[...m];return i[D]=1,O.fromData($,i,"float64")}return g}function St(r,b,S,u=!1){const m=r.dtype,y=r.shape,h=y.length,A=r.data,x=r.offset,D=r.strides;if(S===void 0)return ft(r,b,u);if(U(m)){const e=A,o=S.data,t=S.offset;if(b===void 0){let F=0,B=0,E=0;if(r.isCContiguous)for(let _=0;_<r.size;_++){const V=Number(o[t+_%S.size]),M=e[(x+_)*2],P=e[(x+_)*2+1];F+=M*V,B+=P*V,E+=V}else for(let _=0;_<r.size;_++){const V=Number(o[t+_%S.size]),M=r.iget(_);F+=M.re*V,B+=M.im*V,E+=V}return E===0?new Q(NaN,NaN):new Q(F/E,B/E)}let s=b;if(s<0&&(s=h+s),s<0||s>=h)throw new Error(`axis ${b} is out of bounds for array of dimension ${h}`);const a=Array.from(y).filter((F,B)=>B!==s);if(a.length===0){const F=St(r,void 0,S);return u?G(F,h,m):F}const f=a.reduce((F,B)=>F*B,1),N=y[s],l=O.zeros(a,m),p=l.data,{baseOffsets:I,axisStride:R}=W(y,D,x,s,f);for(let F=0;F<f;F++){let B=0,E=0,T=0,_=I[F];for(let V=0;V<N;V++){const M=Number(o[t+V%S.size]),P=e[_*2],q=e[_*2+1];B+=P*M,E+=q*M,T+=M,_+=R}T===0?(p[F*2]=NaN,p[F*2+1]=NaN):(p[F*2]=B/T,p[F*2+1]=E/T)}if(u){const F=[...y];return F[s]=1,O.fromData(p,F,m)}return l}const w=S.offset;if(b===void 0){let e=0,o=0;const t=S.data;if(r.isCContiguous)for(let a=0;a<r.size;a++){const f=Number(t[w+a%S.size]);e+=Number(A[x+a])*f,o+=f}else for(let a=0;a<r.size;a++){const f=Number(t[w+a%S.size]);e+=Number(r.iget(a))*f,o+=f}return o===0?NaN:lt(e/o,m)}let z=b;if(z<0&&(z=h+z),z<0||z>=h)throw new Error(`axis ${b} is out of bounds for array of dimension ${h}`);const C=Array.from(y).filter((e,o)=>o!==z);if(C.length===0){const e=St(r,void 0,S);return u?G(e,h,"float64"):e}const g=C.reduce((e,o)=>e*o,1),$=y[z],v=S.data,c=O.empty(C,"float64"),d=c.data,{baseOffsets:i,axisStride:n}=W(y,D,x,z,g);for(let e=0;e<g;e++){let o=0,t=0,s=i[e];for(let a=0;a<$;a++){const f=Number(v[w+a%S.size]);o+=Number(A[s])*f,t+=f,s+=n}d[e]=t===0?NaN:o/t}if(u){const e=[...y];return e[z]=1,O.fromData(d,e,"float64")}return c}function K(r,b){return isNaN(r)||isNaN(b)}function oe(r,b,S=!1){const u=r.dtype,m=U(u),y=r.shape,h=y.length,A=r.data,x=r.offset,D=r.strides;if(!m&&!H(u))return et(r,b,S);if(b===void 0){const i=Pt(r);if(i!==null)return i;if(m){const t=A;let s=0,a=0;if(r.isCContiguous)for(let N=0;N<r.size;N++){const l=t[(x+N)*2],p=t[(x+N)*2+1];K(l,p)||(s+=l,a+=p)}else for(let N=0;N<r.size;N++){const l=r.iget(N),p=l.re,I=l.im;K(p,I)||(s+=p,a+=I)}return new Q(s,a)}const n=Y(u);if(n){if(n[0]=0,r.isCContiguous)for(let s=0;s<r.size;s++){const a=Number(A[x+s]);isNaN(a)||(n[0]+=a)}else for(let s=0;s<r.size;s++){const a=Number(r.iget(s));isNaN(a)||(n[0]+=a)}return n[0]}let e=0;if(r.isCContiguous)for(let t=0;t<r.size;t++){const s=Number(A[x+t]);isNaN(s)||(e+=s)}else for(let t=0;t<r.size;t++){const s=Number(r.iget(t));isNaN(s)||(e+=s)}return e}let w=b;if(w<0&&(w=h+w),w<0||w>=h)throw new Error(`axis ${b} is out of bounds for array of dimension ${h}`);const z=Array.from(y).filter((i,n)=>n!==w);if(z.length===0){const i=oe(r);return S?G(i,h,u):i}const C=z.reduce((i,n)=>i*n,1),g=y[w],{baseOffsets:$,axisStride:v}=W(y,D,x,w,C);if(m){const i=A,n=O.empty(z,u),e=n.data;for(let o=0;o<C;o++){let t=0,s=0,a=$[o];for(let f=0;f<g;f++){const N=i[a*2],l=i[a*2+1];K(N,l)||(t+=N,s+=l),a+=v}e[o*2]=t,e[o*2+1]=s}if(S){const o=[...y];return o[w]=1,O.fromData(e,o,u)}return n}const c=O.empty(z,"float64"),d=c.data;for(let i=0;i<C;i++){let n=0,e=$[i];for(let o=0;o<g;o++){const t=Number(A[e]);isNaN(t)||(n+=t),e+=v}d[i]=n}if(S){const i=[...y];return i[w]=1,O.fromData(d,i,"float64")}return c}function ne(r,b,S=!1){const u=r.dtype,m=U(u);if(!m&&!H(u))return yt(r,b,S);const y=r.shape,h=y.length,A=r.data,x=r.offset,D=r.strides;if(b===void 0){if(m){const e=A;let o=1,t=0;if(r.isCContiguous)for(let a=0;a<r.size;a++){const f=e[(x+a)*2],N=e[(x+a)*2+1];if(!K(f,N)){const l=o*f-t*N,p=o*N+t*f;o=l,t=p}}else for(let a=0;a<r.size;a++){const f=r.iget(a),N=f.re,l=f.im;if(!K(N,l)){const p=o*N-t*l,I=o*l+t*N;o=p,t=I}}return new Q(o,t)}let i=1;if(r.isCContiguous)for(let e=0;e<r.size;e++){const o=Number(A[x+e]);isNaN(o)||(i*=o)}else for(let e=0;e<r.size;e++){const o=Number(r.iget(e));isNaN(o)||(i*=o)}return i}let w=b;if(w<0&&(w=h+w),w<0||w>=h)throw new Error(`axis ${b} is out of bounds for array of dimension ${h}`);const z=Array.from(y).filter((i,n)=>n!==w);if(z.length===0){const i=ne(r);return S?G(i,h,u):i}const C=z.reduce((i,n)=>i*n,1),g=y[w],{baseOffsets:$,axisStride:v}=W(y,D,x,w,C);if(m){const i=A,n=O.empty(z,u),e=n.data;for(let o=0;o<C;o++){let t=1,s=0,a=$[o];for(let f=0;f<g;f++){const N=i[a*2],l=i[a*2+1];if(!K(N,l)){const p=t*N-s*l,I=t*l+s*N;t=p,s=I}a+=v}e[o*2]=t,e[o*2+1]=s}if(S){const o=[...y];return o[w]=1,O.fromData(e,o,u)}return n}const c=O.empty(z,"float64"),d=c.data;for(let i=0;i<C;i++){let n=1,e=$[i];for(let o=0;o<g;o++){const t=Number(A[e]);isNaN(t)||(n*=t),e+=v}d[i]=n}if(S){const i=[...y];return i[w]=1,O.fromData(d,i,"float64")}return c}function se(r,b,S=!1){const u=r.dtype,m=U(u);if(!m&&!H(u))return ft(r,b,S);const y=r.shape,h=y.length,A=r.data,x=r.offset,D=r.strides;if(b===void 0){if(m){const t=A;let s=0,a=0,f=0;if(r.isCContiguous)for(let l=0;l<r.size;l++){const p=t[(x+l)*2],I=t[(x+l)*2+1];K(p,I)||(s+=p,a+=I,f++)}else for(let l=0;l<r.size;l++){const p=r.iget(l),I=p.re,R=p.im;K(I,R)||(s+=I,a+=R,f++)}return f===0?new Q(NaN,NaN):new Q(s/f,a/f)}const i=Y(u);let n=0;const e=r.isCContiguous;if(i){if(i[0]=0,e)for(let t=0;t<r.size;t++){const s=Number(A[x+t]);isNaN(s)||(i[0]+=s,n++)}else for(let t=0;t<r.size;t++){const s=Number(r.iget(t));isNaN(s)||(i[0]+=s,n++)}return n===0?NaN:(i[0]/=n,i[0])}let o=0;if(e)for(let t=0;t<r.size;t++){const s=Number(A[x+t]);isNaN(s)||(o+=s,n++)}else for(let t=0;t<r.size;t++){const s=Number(r.iget(t));isNaN(s)||(o+=s,n++)}return n===0?NaN:o/n}let w=b;if(w<0&&(w=h+w),w<0||w>=h)throw new Error(`axis ${b} is out of bounds for array of dimension ${h}`);const z=Array.from(y).filter((i,n)=>n!==w);if(z.length===0){const i=se(r);return S?G(i,h,u):i}const C=z.reduce((i,n)=>i*n,1),g=y[w],{baseOffsets:$,axisStride:v}=W(y,D,x,w,C);if(m){const i=A,n=O.empty(z,u),e=n.data;for(let o=0;o<C;o++){let t=0,s=0,a=0,f=$[o];for(let N=0;N<g;N++){const l=i[f*2],p=i[f*2+1];K(l,p)||(t+=l,s+=p,a++),f+=v}a===0?(e[o*2]=NaN,e[o*2+1]=NaN):(e[o*2]=t/a,e[o*2+1]=s/a)}if(S){const o=[...y];return o[w]=1,O.fromData(e,o,u)}return n}const c=O.empty(z,"float64"),d=c.data;for(let i=0;i<C;i++){let n=0,e=0,o=$[i];for(let t=0;t<g;t++){const s=Number(A[o]);isNaN(s)||(n+=s,e++),o+=v}d[i]=e===0?NaN:n/e}if(S){const i=[...y];return i[w]=1,O.fromData(d,i,"float64")}return c}function ct(r,b,S=0,u=!1){const m=r.dtype;if(!U(m)&&!H(m))return At(r,b,S,u);const y=r.shape,h=y.length,A=r.data,x=r.offset,D=r.strides;if(U(m)){const i=A;if(b===void 0){let l=0,p=0,I=0;const R=r.isCContiguous;if(R)for(let T=0;T<r.size;T++){const _=i[(x+T)*2],V=i[(x+T)*2+1];K(_,V)||(l+=_,p+=V,I++)}else for(let T=0;T<r.size;T++){const _=r.iget(T),V=_.re,M=_.im;K(V,M)||(l+=V,p+=M,I++)}if(I-S<=0)return NaN;const F=l/I,B=p/I;let E=0;if(R)for(let T=0;T<r.size;T++){const _=i[(x+T)*2],V=i[(x+T)*2+1];if(!K(_,V)){const M=_-F,P=V-B;E+=M*M+P*P}}else for(let T=0;T<r.size;T++){const _=r.iget(T),V=_.re,M=_.im;if(!K(V,M)){const P=V-F,q=M-B;E+=P*P+q*q}}return E/(I-S)}let n=b;if(n<0&&(n=h+n),n<0||n>=h)throw new Error(`axis ${b} is out of bounds for array of dimension ${h}`);const e=Array.from(y).filter((l,p)=>p!==n);if(e.length===0){const l=ct(r,void 0,S);return u?G(l,h,"float64"):l}const o=e.reduce((l,p)=>l*p,1),t=y[n],s=O.empty(e,"float64"),a=s.data,{baseOffsets:f,axisStride:N}=W(y,D,x,n,o);for(let l=0;l<o;l++){let p=0,I=0,R=0,F=f[l];for(let _=0;_<t;_++){const V=i[F*2],M=i[F*2+1];K(V,M)||(p+=V,I+=M,R++),F+=N}if(R-S<=0){a[l]=NaN;continue}const B=p/R,E=I/R;let T=0;F=f[l];for(let _=0;_<t;_++){const V=i[F*2],M=i[F*2+1];if(!K(V,M)){const P=V-B,q=M-E;T+=P*P+q*q}F+=N}a[l]=T/(R-S)}if(u){const l=[...y];return l[n]=1,O.fromData(a,l,"float64")}return s}if(b===void 0){let i=0,n=0;const e=r.isCContiguous;if(e)for(let s=0;s<r.size;s++){const a=Number(A[x+s]);isNaN(a)||(i+=a,n++)}else for(let s=0;s<r.size;s++){const a=Number(r.iget(s));isNaN(a)||(i+=a,n++)}if(n-S<=0)return NaN;const o=i/n;let t=0;if(e)for(let s=0;s<r.size;s++){const a=Number(A[x+s]);isNaN(a)||(t+=(a-o)**2)}else for(let s=0;s<r.size;s++){const a=Number(r.iget(s));isNaN(a)||(t+=(a-o)**2)}return t/(n-S)}let w=b;if(w<0&&(w=h+w),w<0||w>=h)throw new Error(`axis ${b} is out of bounds for array of dimension ${h}`);const z=Array.from(y).filter((i,n)=>n!==w);if(z.length===0){const i=ct(r,void 0,S);return u?G(i,h,"float64"):i}const C=z.reduce((i,n)=>i*n,1),g=y[w],$=O.empty(z,"float64"),v=$.data,{baseOffsets:c,axisStride:d}=W(y,D,x,w,C);for(let i=0;i<C;i++){let n=0,e=0,o=c[i];for(let a=0;a<g;a++){const f=Number(A[o]);isNaN(f)||(n+=f,e++),o+=d}if(e-S<=0){v[i]=NaN;continue}const t=n/e;let s=0;o=c[i];for(let a=0;a<g;a++){const f=Number(A[o]);isNaN(f)||(s+=(f-t)**2),o+=d}v[i]=s/(e-S)}if(u){const i=[...y];return i[w]=1,O.fromData(v,i,"float64")}return $}function ve(r,b,S=0,u=!1){const m=ct(r,b,S,u);if(typeof m=="number")return Math.sqrt(m);const y=m,h=O.empty([...y.shape],"float64"),A=h.data;for(let x=0;x<y.size;x++)A[x]=Math.sqrt(Number(y.data[x]));return h}function Nt(r,b,S=!1){const u=r.dtype,m=r.shape,y=m.length,h=r.data,A=r.offset,x=r.strides;if(!U(u)&&!H(u))return nt(r,b,S);if(U(u)){const i=h;if(b===void 0){let l=1/0,p=1/0,I=!1;if(r.isCContiguous)for(let F=0;F<r.size;F++){const B=i[(A+F)*2],E=i[(A+F)*2+1];isNaN(B)||isNaN(E)||(I?(B<l||B===l&&E<p)&&(l=B,p=E):(l=B,p=E,I=!0))}else for(let F=0;F<r.size;F++){const B=r.iget(F),E=B.re,T=B.im;isNaN(E)||isNaN(T)||(I?(E<l||E===l&&T<p)&&(l=E,p=T):(l=E,p=T,I=!0))}return I?new Q(l,p):new Q(NaN,NaN)}let n=b;if(n<0&&(n=y+n),n<0||n>=y)throw new Error(`axis ${b} is out of bounds for array of dimension ${y}`);const e=Array.from(m).filter((l,p)=>p!==n);if(e.length===0){const l=Nt(r);return S?G(l,y,u):l}const o=e.reduce((l,p)=>l*p,1),t=m[n],s=O.empty(e,u),a=s.data,{baseOffsets:f,axisStride:N}=W(m,x,A,n,o);for(let l=0;l<o;l++){let p=1/0,I=1/0,R=!1,F=f[l];for(let B=0;B<t;B++){const E=i[F*2],T=i[F*2+1];F+=N,!(isNaN(E)||isNaN(T))&&(R?(E<p||E===p&&T<I)&&(p=E,I=T):(p=E,I=T,R=!0))}a[l*2]=R?p:NaN,a[l*2+1]=R?I:NaN}if(S){const l=[...m];return l[n]=1,O.fromData(a,l,u)}return s}if(b===void 0){const i=Wt(r);if(i!==null)return i;let n=1/0;if(r.isCContiguous)for(let o=0;o<r.size;o++){const t=Number(h[A+o]);!isNaN(t)&&t<n&&(n=t)}else for(let o=0;o<r.size;o++){const t=Number(r.iget(o));!isNaN(t)&&t<n&&(n=t)}return n===1/0?NaN:n}let D=b;if(D<0&&(D=y+D),D<0||D>=y)throw new Error(`axis ${b} is out of bounds for array of dimension ${y}`);const w=Array.from(m).filter((i,n)=>n!==D);if(w.length===0){const i=Nt(r);return S?G(i,y,"float64"):i}const z=H(u)?u:"float64",C=w.reduce((i,n)=>i*n,1),g=m[D],$=O.empty(w,z),v=$.data,{baseOffsets:c,axisStride:d}=W(m,x,A,D,C);for(let i=0;i<C;i++){let n=1/0,e=c[i];for(let o=0;o<g;o++){const t=Number(h[e]);!isNaN(t)&&t<n&&(n=t),e+=d}v[i]=n===1/0?NaN:n}if(S){const i=[...m];return i[D]=1,O.fromData(v,i,"float64")}return $}function It(r,b,S=!1){const u=r.dtype,m=r.shape,y=m.length,h=r.data,A=r.offset,x=r.strides;if(!U(u)&&!H(u))return ot(r,b,S);if(U(u)){const i=h;if(b===void 0){let l=-1/0,p=-1/0,I=!1;if(r.isCContiguous)for(let F=0;F<r.size;F++){const B=i[(A+F)*2],E=i[(A+F)*2+1];isNaN(B)||isNaN(E)||(I?(B>l||B===l&&E>p)&&(l=B,p=E):(l=B,p=E,I=!0))}else for(let F=0;F<r.size;F++){const B=r.iget(F),E=B.re,T=B.im;isNaN(E)||isNaN(T)||(I?(E>l||E===l&&T>p)&&(l=E,p=T):(l=E,p=T,I=!0))}return I?new Q(l,p):new Q(NaN,NaN)}let n=b;if(n<0&&(n=y+n),n<0||n>=y)throw new Error(`axis ${b} is out of bounds for array of dimension ${y}`);const e=Array.from(m).filter((l,p)=>p!==n);if(e.length===0){const l=It(r);return S?G(l,y,u):l}const o=e.reduce((l,p)=>l*p,1),t=m[n],s=O.empty(e,u),a=s.data,{baseOffsets:f,axisStride:N}=W(m,x,A,n,o);for(let l=0;l<o;l++){let p=-1/0,I=-1/0,R=!1,F=f[l];for(let B=0;B<t;B++){const E=i[F*2],T=i[F*2+1];F+=N,!(isNaN(E)||isNaN(T))&&(R?(E>p||E===p&&T>I)&&(p=E,I=T):(p=E,I=T,R=!0))}a[l*2]=R?p:NaN,a[l*2+1]=R?I:NaN}if(S){const l=[...m];return l[n]=1,O.fromData(a,l,u)}return s}if(b===void 0){const i=qt(r);if(i!==null)return i;let n=-1/0;if(r.isCContiguous)for(let o=0;o<r.size;o++){const t=Number(h[A+o]);!isNaN(t)&&t>n&&(n=t)}else for(let o=0;o<r.size;o++){const t=Number(r.iget(o));!isNaN(t)&&t>n&&(n=t)}return n===-1/0?NaN:n}let D=b;if(D<0&&(D=y+D),D<0||D>=y)throw new Error(`axis ${b} is out of bounds for array of dimension ${y}`);const w=Array.from(m).filter((i,n)=>n!==D);if(w.length===0){const i=It(r);return S?G(i,y,"float64"):i}const z=H(u)?u:"float64",C=w.reduce((i,n)=>i*n,1),g=m[D],$=O.empty(w,z),v=$.data,{baseOffsets:c,axisStride:d}=W(m,x,A,D,C);for(let i=0;i<C;i++){let n=-1/0,e=c[i];for(let o=0;o<g;o++){const t=Number(h[e]);!isNaN(t)&&t>n&&(n=t),e+=d}v[i]=n===-1/0?NaN:n}if(S){const i=[...m];return i[D]=1,O.fromData(v,i,"float64")}return $}function ht(r,b){const S=r.dtype;if(!U(S)&&!H(S))return xt(r,b);const u=r.shape,m=u.length,y=r.data,h=r.offset,A=r.strides;if(U(S)){const c=y;if(b===void 0){let f=1/0,N=1/0,l=-1;if(r.isCContiguous)for(let I=0;I<r.size;I++){const R=c[(h+I)*2],F=c[(h+I)*2+1];!K(R,F)&&X(R,F,f,N)<0&&(f=R,N=F,l=I)}else for(let I=0;I<r.size;I++){const R=r.iget(I),F=R.re,B=R.im;!K(F,B)&&X(F,B,f,N)<0&&(f=F,N=B,l=I)}return l}let d=b;if(d<0&&(d=m+d),d<0||d>=m)throw new Error(`axis ${b} is out of bounds for array of dimension ${m}`);const i=Array.from(u).filter((f,N)=>N!==d);if(i.length===0)return ht(r);const n=i.reduce((f,N)=>f*N,1),e=u[d],o=O.empty(i,"int32"),t=o.data,{baseOffsets:s,axisStride:a}=W(u,A,h,d,n);for(let f=0;f<n;f++){let N=1/0,l=1/0,p=0,I=s[f];for(let R=0;R<e;R++){const F=c[I*2],B=c[I*2+1];!K(F,B)&&X(F,B,N,l)<0&&(N=F,l=B,p=R),I+=a}t[f]=p}return o}if(b===void 0){let c=1/0,d=-1;if(r.isCContiguous)for(let n=0;n<r.size;n++){const e=Number(y[h+n]);!isNaN(e)&&e<c&&(c=e,d=n)}else for(let n=0;n<r.size;n++){const e=Number(r.iget(n));!isNaN(e)&&e<c&&(c=e,d=n)}return d}let x=b;if(x<0&&(x=m+x),x<0||x>=m)throw new Error(`axis ${b} is out of bounds for array of dimension ${m}`);const D=Array.from(u).filter((c,d)=>d!==x);if(D.length===0)return ht(r);const w=D.reduce((c,d)=>c*d,1),z=u[x],C=O.empty(D,"int32"),g=C.data,{baseOffsets:$,axisStride:v}=W(u,A,h,x,w);for(let c=0;c<w;c++){let d=1/0,i=0,n=$[c];for(let e=0;e<z;e++){const o=Number(y[n]);!isNaN(o)&&o<d&&(d=o,i=e),n+=v}g[c]=i}return C}function zt(r,b){const S=r.dtype;if(!U(S)&&!H(S))return bt(r,b);const u=r.shape,m=u.length,y=r.data,h=r.offset,A=r.strides;if(U(S)){const c=y;if(b===void 0){let f=-1/0,N=-1/0,l=-1;if(r.isCContiguous)for(let I=0;I<r.size;I++){const R=c[(h+I)*2],F=c[(h+I)*2+1];!K(R,F)&&X(R,F,f,N)>0&&(f=R,N=F,l=I)}else for(let I=0;I<r.size;I++){const R=r.iget(I),F=R.re,B=R.im;!K(F,B)&&X(F,B,f,N)>0&&(f=F,N=B,l=I)}return l}let d=b;if(d<0&&(d=m+d),d<0||d>=m)throw new Error(`axis ${b} is out of bounds for array of dimension ${m}`);const i=Array.from(u).filter((f,N)=>N!==d);if(i.length===0)return zt(r);const n=i.reduce((f,N)=>f*N,1),e=u[d],o=O.empty(i,"int32"),t=o.data,{baseOffsets:s,axisStride:a}=W(u,A,h,d,n);for(let f=0;f<n;f++){let N=-1/0,l=-1/0,p=0,I=s[f];for(let R=0;R<e;R++){const F=c[I*2],B=c[I*2+1];!K(F,B)&&X(F,B,N,l)>0&&(N=F,l=B,p=R),I+=a}t[f]=p}return o}if(b===void 0){let c=-1/0,d=-1;if(r.isCContiguous)for(let n=0;n<r.size;n++){const e=Number(y[h+n]);!isNaN(e)&&e>c&&(c=e,d=n)}else for(let n=0;n<r.size;n++){const e=Number(r.iget(n));!isNaN(e)&&e>c&&(c=e,d=n)}return d}let x=b;if(x<0&&(x=m+x),x<0||x>=m)throw new Error(`axis ${b} is out of bounds for array of dimension ${m}`);const D=Array.from(u).filter((c,d)=>d!==x);if(D.length===0)return zt(r);const w=D.reduce((c,d)=>c*d,1),z=u[x],C=O.empty(D,"int32"),g=C.data,{baseOffsets:$,axisStride:v}=W(u,A,h,x,w);for(let c=0;c<w;c++){let d=-1/0,i=0,n=$[c];for(let e=0;e<z;e++){const o=Number(y[n]);!isNaN(o)&&o>d&&(d=o,i=e),n+=v}g[c]=i}return C}function $e(r,b){const S=r.dtype;if(!U(S)&&!H(S))return te(r,b);const u=r.shape,m=u.length,y=r.data,h=r.offset;if(U(S)){const c=y,d=r.size;if(b===void 0){const l=O.zeros([d],S),p=l.data;let I=0,R=0;if(r.isCContiguous)for(let B=0;B<d;B++){const E=c[(h+B)*2],T=c[(h+B)*2+1];K(E,T)||(I+=E,R+=T),p[B*2]=I,p[B*2+1]=R}else for(let B=0;B<d;B++){const E=r.iget(B),T=E.re,_=E.im;K(T,_)||(I+=T,R+=_),p[B*2]=I,p[B*2+1]=R}return l}let i=b;if(i<0&&(i=m+i),i<0||i>=m)throw new Error(`axis ${b} is out of bounds for array of dimension ${m}`);const n=O.zeros([...u],S),e=n.data,o=u[i],t=[];let s=1;for(let l=m-1;l>=0;l--)t.unshift(s),s*=u[l];const a=r.size,f=t[i];if(r.isCContiguous)for(let l=0;l<a;l++){const p=c[(h+l)*2],I=c[(h+l)*2+1],R=Math.floor(l/f)%o,F=K(p,I);R===0?(e[l*2]=F?0:p,e[l*2+1]=F?0:I):(e[l*2]=e[(l-f)*2]+(F?0:p),e[l*2+1]=e[(l-f)*2+1]+(F?0:I))}else for(let l=0;l<a;l++){const p=r.iget(l),I=p.re,R=p.im,F=Math.floor(l/f)%o,B=K(I,R);F===0?(e[l*2]=B?0:I,e[l*2+1]=B?0:R):(e[l*2]=e[(l-f)*2]+(B?0:I),e[l*2+1]=e[(l-f)*2+1]+(B?0:R))}return n}if(b===void 0){const c=r.size,d=O.empty([c],S),i=d.data;let n=0;if(r.isCContiguous)for(let o=0;o<c;o++){const t=Number(y[h+o]);isNaN(t)||(n+=t),i[o]=n}else for(let o=0;o<c;o++){const t=Number(r.iget(o));isNaN(t)||(n+=t),i[o]=n}return d}let A=b;if(A<0&&(A=m+A),A<0||A>=m)throw new Error(`axis ${b} is out of bounds for array of dimension ${m}`);const x=O.empty([...u],S),D=x.data,w=u[A],z=[];let C=1;for(let c=m-1;c>=0;c--)z.unshift(C),C*=u[c];const g=r.size,$=z[A];if(r.isCContiguous)for(let c=0;c<g;c++){const d=Number(y[h+c]);Math.floor(c/$)%w===0?D[c]=isNaN(d)?0:d:D[c]=D[c-$]+(isNaN(d)?0:d)}else for(let c=0;c<g;c++){const d=Number(r.iget(c));Math.floor(c/$)%w===0?D[c]=isNaN(d)?0:d:D[c]=D[c-$]+(isNaN(d)?0:d)}return x}function ge(r,b){const S=r.dtype;if(!U(S)&&!H(S))return ee(r,b);const u=r.shape,m=u.length,y=r.data,h=r.offset;if(U(S)){const c=y,d=r.size;if(b===void 0){const l=O.zeros([d],S),p=l.data;let I=1,R=0;if(r.isCContiguous)for(let B=0;B<d;B++){const E=c[(h+B)*2],T=c[(h+B)*2+1];if(!K(E,T)){const _=I*E-R*T,V=I*T+R*E;I=_,R=V}p[B*2]=I,p[B*2+1]=R}else for(let B=0;B<d;B++){const E=r.iget(B),T=E.re,_=E.im;if(!K(T,_)){const V=I*T-R*_,M=I*_+R*T;I=V,R=M}p[B*2]=I,p[B*2+1]=R}return l}let i=b;if(i<0&&(i=m+i),i<0||i>=m)throw new Error(`axis ${b} is out of bounds for array of dimension ${m}`);const n=O.zeros([...u],S),e=n.data,o=u[i],t=[];let s=1;for(let l=m-1;l>=0;l--)t.unshift(s),s*=u[l];const a=r.size,f=t[i];if(r.isCContiguous)for(let l=0;l<a;l++){const p=c[(h+l)*2],I=c[(h+l)*2+1],R=Math.floor(l/f)%o,F=K(p,I);if(R===0)e[l*2]=F?1:p,e[l*2+1]=F?0:I;else{const B=e[(l-f)*2],E=e[(l-f)*2+1];F?(e[l*2]=B,e[l*2+1]=E):(e[l*2]=B*p-E*I,e[l*2+1]=B*I+E*p)}}else for(let l=0;l<a;l++){const p=r.iget(l),I=p.re,R=p.im,F=Math.floor(l/f)%o,B=K(I,R);if(F===0)e[l*2]=B?1:I,e[l*2+1]=B?0:R;else{const E=e[(l-f)*2],T=e[(l-f)*2+1];B?(e[l*2]=E,e[l*2+1]=T):(e[l*2]=E*I-T*R,e[l*2+1]=E*R+T*I)}}return n}if(b===void 0){const c=r.size,d=O.empty([c],S),i=d.data;let n=1;if(r.isCContiguous)for(let o=0;o<c;o++){const t=Number(y[h+o]);isNaN(t)||(n*=t),i[o]=n}else for(let o=0;o<c;o++){const t=Number(r.iget(o));isNaN(t)||(n*=t),i[o]=n}return d}let A=b;if(A<0&&(A=m+A),A<0||A>=m)throw new Error(`axis ${b} is out of bounds for array of dimension ${m}`);const x=O.empty([...u],S),D=x.data,w=u[A],z=[];let C=1;for(let c=m-1;c>=0;c--)z.unshift(C),C*=u[c];const g=r.size,$=z[A];if(r.isCContiguous)for(let c=0;c<g;c++){const d=Number(y[h+c]);Math.floor(c/$)%w===0?D[c]=isNaN(d)?1:d:D[c]=D[c-$]*(isNaN(d)?1:d)}else for(let c=0;c<g;c++){const d=Number(r.iget(c));Math.floor(c/$)%w===0?D[c]=isNaN(d)?1:d:D[c]=D[c-$]*(isNaN(d)?1:d)}return x}function ie(r,b,S=!1){if(U(r.dtype))return ut(r,b,S,!0);if(!H(r.dtype))return re(r,b,S);const u=r.shape,m=u.length,y=r.data,h=r.offset,A=r.strides;if(b===void 0){const c=[];if(r.isCContiguous)for(let e=0;e<r.size;e++){const o=Number(y[h+e]);isNaN(o)||c.push(o)}else for(let e=0;e<r.size;e++){const o=Number(r.iget(e));isNaN(o)||c.push(o)}if(c.length===0)return NaN;c.sort((e,o)=>e-o);const i=c.length,n=Math.floor(i/2);return i%2===0?(c[n-1]+c[n])/2:c[n]}let x=b;if(x<0&&(x=m+x),x<0||x>=m)throw new Error(`axis ${b} is out of bounds for array of dimension ${m}`);const D=Array.from(u).filter((c,d)=>d!==x);if(D.length===0){const c=ie(r);return S?G(c,m,"float64"):c}const w=D.reduce((c,d)=>c*d,1),z=u[x],C=O.empty(D,"float64"),g=C.data,{baseOffsets:$,axisStride:v}=W(u,A,h,x,w);for(let c=0;c<w;c++){const d=[];let i=$[c];for(let o=0;o<z;o++){const t=Number(y[i]);isNaN(t)||d.push(t),i+=v}if(d.length===0){g[c]=NaN;continue}d.sort((o,t)=>o-t);const n=d.length,e=Math.floor(n/2);n%2===0?g[c]=(d[e-1]+d[e])/2:g[c]=d[e]}if(S){const c=[...u];return c[x]=1,O.fromData(g,c,"float64")}return C}function wt(r,b,S,u=!1){if(dt(r.dtype,"nanquantile","Complex numbers are not orderable."),r.dtype==="bool")throw new TypeError("ufunc 'subtract' not supported for boolean dtype. The '-' operator is not supported for booleans, use 'bitwise_xor' instead.");if(!H(r.dtype))return st(r,b,S,u);if(b<0||b>1)throw new Error("Quantile must be between 0 and 1");const m=r.shape,y=m.length,h=r.data,A=r.offset,x=r.strides;if(S===void 0){const d=[];if(r.isCContiguous)for(let a=0;a<r.size;a++){const f=Number(h[A+a]);isNaN(f)||d.push(f)}else for(let a=0;a<r.size;a++){const f=Number(r.iget(a));isNaN(f)||d.push(f)}if(d.length===0)return NaN;d.sort((a,f)=>a-f);const n=d.length,e=b*(n-1),o=Math.floor(e),t=Math.ceil(e);if(o===t)return d[o];const s=e-o;return d[o]*(1-s)+d[t]*s}let D=S;if(D<0&&(D=y+D),D<0||D>=y)throw new Error(`axis ${S} is out of bounds for array of dimension ${y}`);const w=Array.from(m).filter((d,i)=>i!==D);if(w.length===0){const d=wt(r,b);return u?G(d,y,"float64"):d}const z=w.reduce((d,i)=>d*i,1),C=m[D],g=O.empty(w,"float64"),$=g.data,{baseOffsets:v,axisStride:c}=W(m,x,A,D,z);for(let d=0;d<z;d++){const i=[];let n=v[d];for(let a=0;a<C;a++){const f=Number(h[n]);isNaN(f)||i.push(f),n+=c}if(i.length===0){$[d]=NaN;continue}i.sort((a,f)=>a-f);const e=i.length,o=b*(e-1),t=Math.floor(o),s=Math.ceil(o);if(t===s)$[d]=i[t];else{const a=o-t;$[d]=i[t]*(1-a)+i[s]*a}}if(u){const d=[...m];return d[D]=1,O.fromData($,d,"float64")}return g}function Be(r,b,S,u=!1){return wt(r,b/100,S,u)}export{Zt as all,kt as any,bt as argmax,xt as argmin,St as average,ee as cumprod,te as cumsum,ot as max,ft as mean,re as median,nt as min,zt as nanargmax,ht as nanargmin,ge as nancumprod,$e as nancumsum,It as nanmax,se as nanmean,ie as nanmedian,Nt as nanmin,Be as nanpercentile,ne as nanprod,wt as nanquantile,ve as nanstd,oe as nansum,ct as nanvar,Re as percentile,yt as prod,Fe as ptp,st as quantile,Ce as std,et as sum,At as variance};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ArrayStorage as
|
|
1
|
+
import{ArrayStorage as y}from"../storage.js";import{throwIfComplex as g,isComplexDType as A,isIntegerDType as l,mathResultDtype as b}from"../dtype.js";function z(t,o){const u=t.dtype,f=Array.from(t.shape),c=t.size,i=y.empty(f,u),n=i.data;if(t.isCContiguous){const e=t.data,s=t.offset;for(let r=0;r<c;r++)n[r*2]=o(e[(s+r)*2]),n[r*2+1]=o(e[(s+r)*2+1])}else for(let e=0;e<c;e++){const s=t.iget(e);n[e*2]=o(s.re),n[e*2+1]=o(s.im)}return i}function d(t){if(!isFinite(t))return t;const o=Math.floor(t),u=t-o;return Math.abs(u-.5)<1e-10?o%2===0?o:o+1:Math.round(t)}function C(t,o=0){if(A(t.dtype)){const r=Math.pow(10,o);return z(t,a=>d(a*r)/r)}if(l(t.dtype)&&o>=0)return t.copy();if(t.dtype==="bool"){const r=b("bool"),a=y.empty(Array.from(t.shape),r),p=t.data,h=t.offset;for(let m=0;m<t.size;m++)a.data[m]=p[h+m];return a}const u=t.dtype,f=Array.from(t.shape),c=t.size,i=u,n=y.zeros(f,i),e=n.data,s=Math.pow(10,o);if(t.isCContiguous){const r=t.data,a=t.offset;for(let p=0;p<c;p++){const h=Number(r[a+p]);e[p]=d(h*s)/s}}else for(let r=0;r<c;r++){const a=Number(t.iget(r));e[r]=d(a*s)/s}return n}function N(t){if(g(t.dtype,"ceil","Rounding is not defined for complex numbers."),l(t.dtype))return t.copy();const o=t.dtype,u=Array.from(t.shape),f=t.size,c=o,i=y.zeros(u,c),n=i.data;if(t.isCContiguous){const e=t.data,s=t.offset;for(let r=0;r<f;r++)n[r]=Math.ceil(Number(e[s+r]))}else for(let e=0;e<f;e++)n[e]=Math.ceil(Number(t.iget(e)));return i}function F(t){if(g(t.dtype,"fix","Rounding is not defined for complex numbers."),l(t.dtype))return t.copy();const o=t.dtype,u=Array.from(t.shape),f=t.size,c=o,i=y.zeros(u,c),n=i.data;if(t.isCContiguous){const e=t.data,s=t.offset;for(let r=0;r<f;r++)n[r]=Math.trunc(Number(e[s+r]))}else for(let e=0;e<f;e++)n[e]=Math.trunc(Number(t.iget(e)));return i}function R(t){if(g(t.dtype,"floor","Rounding is not defined for complex numbers."),l(t.dtype))return t.copy();const o=t.dtype,u=Array.from(t.shape),f=t.size,c=o,i=y.zeros(u,c),n=i.data;if(t.isCContiguous){const e=t.data,s=t.offset;for(let r=0;r<f;r++)n[r]=Math.floor(Number(e[s+r]))}else for(let e=0;e<f;e++)n[e]=Math.floor(Number(t.iget(e)));return i}function v(t){if(A(t.dtype))return z(t,d);if(l(t.dtype)||t.dtype==="bool"){const e=b(t.dtype),s=y.empty(Array.from(t.shape),e),r=t.data,a=t.offset;for(let p=0;p<t.size;p++)s.data[p]=Number(r[a+p]);return s}const o=t.dtype,u=Array.from(t.shape),f=t.size,c=o,i=y.zeros(u,c),n=i.data;if(t.isCContiguous){const e=t.data,s=t.offset;for(let r=0;r<f;r++)n[r]=d(Number(e[s+r]))}else for(let e=0;e<f;e++)n[e]=d(Number(t.iget(e)));return i}function w(t,o=0){return C(t,o)}function T(t){if(g(t.dtype,"trunc","Rounding is not defined for complex numbers."),l(t.dtype))return t.copy();const o=t.dtype,u=Array.from(t.shape),f=t.size,c=o,i=y.zeros(u,c),n=i.data;if(t.isCContiguous){const e=t.data,s=t.offset;for(let r=0;r<f;r++)n[r]=Math.trunc(Number(e[s+r]))}else for(let e=0;e<f;e++)n[e]=Math.trunc(Number(t.iget(e)));return i}export{C as around,N as ceil,F as fix,R as floor,v as rint,w as round,T as trunc};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ArrayStorage as z}from"../storage";import{isComplexDType as
|
|
1
|
+
import{ArrayStorage as z}from"../storage.js";import{isComplexDType as H}from"../dtype.js";function P(o,f,s,l){const c=isNaN(o)||isNaN(f),r=isNaN(s)||isNaN(l);return c&&r?0:c?1:r||o<s?-1:o>s?1:f<l?-1:f>l?1:0}function W(o,f,s,l){const c=isNaN(o)||isNaN(f),r=isNaN(s)||isNaN(l);return c&&r?!0:c||r?!1:o===s&&f===l}function Q(o,f,s,l,c,r,t,u,A){const g=new Int32Array(r),y=t?new Int32Array(r).fill(-1):null;for(let x=0;x<s;x++){const n=Number(o[f+x])-c;g[n]++,y!==null&&y[n]===-1&&(y[n]=x)}let d=0;for(let x=0;x<r;x++)g[x]>0&&d++;const h=z.zeros([d],l),e=h.data,w=e instanceof BigInt64Array||e instanceof BigUint64Array,N=A?z.zeros([d],"int32"):null,q=N?N.data:null,B=t?z.zeros([d],"int32"):null,b=B?B.data:null,j=u?new Int32Array(r).fill(-1):null;let K=0;for(let x=0;x<r;x++)g[x]>0&&(w?e[K]=BigInt(x+c):e[K]=x+c,q&&(q[K]=g[x]),b&&(b[K]=y[x]),j&&(j[x]=K),K++);if(!t&&!u&&!A)return h;const J={values:h};if(B&&(J.indices=B),u){const x=z.zeros([s],"int32"),n=x.data;for(let m=0;m<s;m++)n[m]=j[Number(o[f+m])-c];J.inverse=x}return N&&(J.counts=N),J}function V(o,f=!1,s=!1,l=!1,c){if(c!==void 0){const n=Array.from(o.shape),m=n.length;let a=c<0?m+c:c;if(a<0||a>=m)throw new Error(`unique: axis ${c} out of bounds for array of dimension ${m}`);const F=n[a],D=[];for(let I=0;I<F;I++){const T=[],U=n.filter((i,S)=>S!==a),L=U.reduce((i,S)=>i*S,1);for(let i=0;i<L;i++){let S=i;const v=new Array(U.length);for(let $=U.length-1;$>=0;$--)v[$]=S%U[$],S=Math.floor(S/U[$]);const G=[];let O=0;for(let $=0;$<m;$++)G.push($===a?I:v[O++]);T.push(Number(o.get(...G)))}D.push(T.join(","))}const k=D.map((I,T)=>({key:I,i:T}));k.sort((I,T)=>I.key<T.key?-1:I.key>T.key?1:0);const _=[];let E;for(const{key:I,i:T}of k)I!==E&&(_.push(T),E=I);const p=n.map((I,T)=>T===a?_.length:I),M=z.zeros(p,o.dtype);for(let I=0;I<_.length;I++){const T=_[I],U=n.filter((i,S)=>S!==a),L=U.reduce((i,S)=>i*S,1);for(let i=0;i<L;i++){let S=i;const v=new Array(U.length);for(let R=U.length-1;R>=0;R--)v[R]=S%U[R],S=Math.floor(S/U[R]);const G=[],O=[];let $=0;for(let R=0;R<m;R++)G.push(R===a?T:v[$]),O.push(R===a?I:v[$]),R!==a&&$++;M.set(O,Number(o.get(...G)))}}return M}const r=o.dtype,t=o.size,u=o.data,A=o.offset;if(H(r)){const n=u,m=[];for(let i=0;i<t;i++)m.push({re:n[(A+i)*2],im:n[(A+i)*2+1],index:i});m.sort((i,S)=>P(i.re,i.im,S.re,S.im));const a=[],F=[],D=new Array(t),k=[];let _,E,p=0;for(let i=0;i<m.length;i++){const{re:S,im:v,index:G}=m[i];_===void 0||!W(S,v,_,E)?(_!==void 0&&k.push(p),a.push({re:S,im:v}),F.push(G),p=1,_=S,E=v):p++}p>0&&k.push(p);const M=new Map;let I=-1;for(let i=0;i<a.length;i++){const{re:S,im:v}=a[i];isNaN(S)||isNaN(v)?I=i:M.set(`${S},${v}`,i)}for(let i=0;i<t;i++){const S=n[(A+i)*2],v=n[(A+i)*2+1];isNaN(S)||isNaN(v)?D[i]=I:D[i]=M.get(`${S},${v}`)}const T=z.zeros([a.length],r),U=T.data;for(let i=0;i<a.length;i++)U[i*2]=a[i].re,U[i*2+1]=a[i].im;if(!f&&!s&&!l)return T;const L={values:T};if(f){const i=z.zeros([F.length],"int32"),S=i.data;for(let v=0;v<F.length;v++)S[v]=F[v];L.indices=i}if(s){const i=z.zeros([D.length],"int32"),S=i.data;for(let v=0;v<D.length;v++)S[v]=D[v];L.inverse=i}if(l){const i=z.zeros([k.length],"int32"),S=i.data;for(let v=0;v<k.length;v++)S[v]=k[v];L.counts=i}return L}if(r==="int8"||r==="uint8")return Q(u,A,t,r,r==="int8"?-128:0,256,f,s,l);if(r==="int16"||r==="uint16"||r==="int32"||r==="uint32"){let n=Number(u[A]),m=n;for(let F=1;F<t;F++){const D=Number(u[A+F]);D<n?n=D:D>m&&(m=D)}const a=m-n+1;if(a<=4*t)return Q(u,A,t,r,n,a,f,s,l)}const g=u instanceof BigInt64Array||u instanceof BigUint64Array,y=r==="float64"||r==="float32"||r==="float16";if(!f&&!s){const n=new Float64Array(t);for(let p=0;p<t;p++)n[p]=Number(u[A+p]);if(n.sort(),t===0){const p=z.zeros([0],r);return l?{values:p,counts:z.zeros([0],"int32")}:p}const m=[n[0]],a=[1];for(let p=1;p<t;p++){const M=n[p],I=n[p-1];M!==I&&!(M!==M&&I!==I)?(m.push(M),a.push(1)):a[a.length-1]++}const F=m.length,D=z.zeros([F],r),k=D.data;if(g)for(let p=0;p<F;p++)k[p]=BigInt(m[p]);else for(let p=0;p<F;p++)k[p]=m[p];if(!l)return D;const _=z.zeros([F],"int32"),E=_.data;for(let p=0;p<F;p++)E[p]=a[p];return{values:D,counts:_}}const d=new Float64Array(t),h=new Int32Array(t);for(let n=0;n<t;n++)d[n]=Number(u[A+n]),h[n]=n;y?h.sort((n,m)=>{const a=d[n],F=d[m];return a!==a&&F!==F?0:a!==a?1:F!==F?-1:a-F}):h.sort((n,m)=>d[n]-d[m]);const e=[],w=[],N=[];let q,B=0;for(let n=0;n<t;n++){const m=h[n],a=d[m];q===void 0||(y?a!==a&&q===q||a===a&&q!==q||a===a&&a!==q:a!==q)?(q!==void 0&&N.push(B),e.push(a),w.push(m),B=1,q=a):B++}B>0&&N.push(B);const b=e.length,j=z.zeros([b],r),K=j.data,J=K instanceof BigInt64Array||K instanceof BigUint64Array;for(let n=0;n<b;n++)K[n]=J?BigInt(e[n]):e[n];if(!f&&!s&&!l)return j;const x={values:j};if(f){const n=z.zeros([b],"int32"),m=n.data;for(let a=0;a<b;a++)m[a]=w[a];x.indices=n}if(s){const n=new Map;let m=-1;for(let D=0;D<b;D++){const k=e[D];k!==k?m=D:n.set(k,D)}const a=z.zeros([t],"int32"),F=a.data;for(let D=0;D<t;D++){const k=d[D];F[D]=k!==k?m:n.get(k)}x.inverse=a}if(l){const n=z.zeros([b],"int32"),m=n.data;for(let a=0;a<b;a++)m[a]=N[a];x.counts=n}return x}function C(o,f,s,l=0){if(s){const c=Number(o[(l+f)*2]),r=Number(o[(l+f)*2+1]);return`${c},${r}`}return String(Number(o[l+f]))}function tt(o,f){return X(o,f)}function rt(o,f){const s=o.dtype,l=H(s),c=V(o),r=V(f),t=new Set;for(let y=0;y<r.size;y++)t.add(C(r.data,y,l));const u=[];for(let y=0;y<c.size;y++){const d=C(c.data,y,l);t.has(d)&&u.push(y)}if(l){const y=z.zeros([u.length],s),d=y.data,h=c.data;for(let e=0;e<u.length;e++){const w=u[e];d[e*2]=h[w*2],d[e*2+1]=h[w*2+1]}return y}const A=z.zeros([u.length],s),g=A.data;for(let y=0;y<u.length;y++)g[y]=c.data[u[y]];return A}function X(o,f){const s=Array.from(o.shape),l=o.size,c=H(o.dtype),r=new Set;for(let A=0;A<f.size;A++)r.add(C(f.data,A,c,f.offset));const t=z.zeros(s,"bool"),u=t.data;for(let A=0;A<l;A++){const g=C(o.data,A,c,o.offset);u[A]=r.has(g)?1:0}return t}function et(o,f){const s=o.dtype,l=H(s),c=V(o),r=new Set;for(let g=0;g<f.size;g++)r.add(C(f.data,g,l,f.offset));const t=[];for(let g=0;g<c.size;g++){const y=C(c.data,g,l);r.has(y)||t.push(g)}if(l){const g=z.zeros([t.length],s),y=g.data,d=c.data;for(let h=0;h<t.length;h++){const e=t[h];y[h*2]=d[e*2],y[h*2+1]=d[e*2+1]}return g}const u=z.zeros([t.length],s),A=u.data;for(let g=0;g<t.length;g++)A[g]=c.data[t[g]];return u}function nt(o,f){const s=o.dtype,l=H(s),c=V(o),r=V(f),t=new Set,u=new Set;for(let e=0;e<c.size;e++)t.add(C(c.data,e,l));for(let e=0;e<r.size;e++)u.add(C(r.data,e,l));const A=[],g=[];for(let e=0;e<c.size;e++){const w=C(c.data,e,l);u.has(w)||A.push(e)}for(let e=0;e<r.size;e++){const w=C(r.data,e,l);t.has(w)||g.push(e)}if(l){const e=[],w=c.data,N=r.data;for(const b of A)e.push({re:w[b*2],im:w[b*2+1]});for(const b of g)e.push({re:N[b*2],im:N[b*2+1]});e.sort((b,j)=>P(b.re,b.im,j.re,j.im));const q=z.zeros([e.length],s),B=q.data;for(let b=0;b<e.length;b++)B[b*2]=e[b].re,B[b*2+1]=e[b].im;return q}const y=[];for(const e of A)y.push(Number(c.data[e]));for(const e of g)y.push(Number(r.data[e]));y.sort((e,w)=>isNaN(e)&&isNaN(w)?0:isNaN(e)?1:isNaN(w)?-1:e-w);const d=z.zeros([y.length],s),h=d.data;for(let e=0;e<y.length;e++)h[e]=y[e];return d}function st(o,f){const s=o.dtype,l=H(s),c=V(o),r=V(f),t=new Set,u=[];if(l){const d=c.data,h=r.data;for(let N=0;N<c.size;N++){const q=d[N*2],B=d[N*2+1],b=`${q},${B}`;t.has(b)||(t.add(b),u.push({re:q,im:B}))}for(let N=0;N<r.size;N++){const q=h[N*2],B=h[N*2+1],b=`${q},${B}`;t.has(b)||(t.add(b),u.push({re:q,im:B}))}u.sort((N,q)=>P(N.re,N.im,q.re,q.im));const e=z.zeros([u.length],s),w=e.data;for(let N=0;N<u.length;N++)w[N*2]=u[N].re,w[N*2+1]=u[N].im;return e}const A=[];for(let d=0;d<c.size;d++){const h=Number(c.data[d]),e=String(h);t.has(e)||(t.add(e),A.push(h))}for(let d=0;d<r.size;d++){const h=Number(r.data[d]),e=String(h);t.has(e)||(t.add(e),A.push(h))}A.sort((d,h)=>isNaN(d)&&isNaN(h)?0:isNaN(d)?1:isNaN(h)?-1:d-h);const g=z.zeros([A.length],s),y=g.data;for(let d=0;d<A.length;d++)y[d]=A[d];return g}function at(o,f="fb"){const s=o.dtype,l=o.data,c=o.size,r=o.offset;if(c===0)return z.zeros([0],s);let t=0,u=c-1;if(H(s)){const y=l;if(f!=="b")for(;t<c&&y[(r+t)*2]===0&&y[(r+t)*2+1]===0;)t++;if(f!=="f")for(;u>=t&&y[(r+u)*2]===0&&y[(r+u)*2+1]===0;)u--;if(t>u)return z.zeros([0],s);const d=u-t+1,h=z.zeros([d],s);return h.data.set(y.subarray((r+t)*2,(r+t+d)*2)),h}if(l instanceof BigInt64Array||l instanceof BigUint64Array){if(f!=="b")for(;t<c&&l[r+t]===0n;)t++;if(f!=="f")for(;u>=t&&l[r+u]===0n;)u--}else{const y=l.subarray(r,r+c);if(f!=="b")for(;t<c&&y[t]===0;)t++;if(f!=="f")for(;u>=t&&y[u]===0;)u--}if(t>u)return z.zeros([0],s);const A=u-t+1,g=z.zeros([A],s);return l instanceof BigInt64Array||l instanceof BigUint64Array,g.data.set(l.subarray(r+t,r+t+A)),g}function ot(o){const s=V(o,!0,!0,!0);return{values:s.values,indices:s.indices,inverse_indices:s.inverse,counts:s.counts}}function it(o){const s=V(o,!1,!1,!0);return{values:s.values,counts:s.counts}}function ut(o){const s=V(o,!1,!0,!1);return{values:s.values,inverse_indices:s.inverse}}function lt(o){return V(o)}export{tt as in1d,rt as intersect1d,X as isin,et as setdiff1d,nt as setxor1d,at as trim_zeros,st as union1d,V as unique,ot as unique_all,it as unique_counts,ut as unique_inverse,lt as unique_values};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ArrayStorage as z,computeStrides as T}from"../storage";import{getTypedArrayConstructor as U,isBigIntDType as v,isComplexDType as F}from"../dtype";import{wasmFlip as M}from"../wasm/flip";import{wasmTile2D as q}from"../wasm/tile";import{wasmRoll as j}from"../wasm/roll";import{wasmRot90 as K}from"../wasm/rot90";import{wasmRepeat as P}from"../wasm/repeat";import{parseSlice as N,normalizeSlice as _}from"../slicing";function sr(r,...t){if(t.length===0)return r;if(t.length>r.ndim)throw new Error(`Too many indices for array: array is ${r.ndim}-dimensional, but ${t.length} were indexed`);const n=t.map((f,a)=>{const u=N(f);return _(u,r.shape[a])});for(;n.length<r.ndim;)n.push({start:0,stop:r.shape[n.length],step:1,isIndex:!1});const e=[],s=[];let i=r.offset;for(let f=0;f<n.length;f++){const a=n[f];if(i+=a.start*r.strides[f],a.isIndex)continue;const u=Math.max(0,Math.ceil((a.stop-a.start)/a.step));e.push(u),s.push(r.strides[f]*a.step)}return z.fromData(r.data,e,r.dtype,s,i)}function fr(r,...t){if(t.length===0)return r;if(t.length>r.ndim)throw new Error(`Too many indices for array: array is ${r.ndim}-dimensional, but ${t.length} were indexed`);const n=t.map((f,a)=>{const u=N(f);return _(u,r.shape[a])});for(;n.length<r.ndim;)n.push({start:0,stop:r.shape[n.length],step:1,isIndex:!1});const e=[],s=[];let i=r.offset;for(let f=0;f<n.length;f++){const a=n[f];i+=a.start*r.strides[f];const u=a.isIndex?1:Math.max(0,Math.ceil((a.stop-a.start)/a.step));e.push(u),s.push(r.strides[f]*a.step)}return z.fromData(r.data,e,r.dtype,s,i)}function D(r,t){const n=r.size,e=r.dtype,s=t.indexOf(-1);let i;if(s!==-1){const o=t.reduce((h,y,l)=>l===s?h:h*y,1),m=n/o;if(!Number.isInteger(m))throw new Error(`cannot reshape array of size ${n} into shape ${JSON.stringify(t)}`);i=t.map((h,y)=>y===s?m:h)}else i=t;if(i.reduce((o,m)=>o*m,1)!==n)throw new Error(`cannot reshape array of size ${n} into shape ${JSON.stringify(i)}`);if(r.isCContiguous){const o=r.data;return z.fromData(o,i,e,T(i),0)}const u=r.copy().data;return z.fromData(u,i,e,T(i),0)}function J(r){const t=r.size,n=r.dtype,e=U(n);if(!e)throw new Error(`Cannot flatten array with dtype ${n}`);const s=F(n),i=s?t*2:t;if(r.isCContiguous){const u=r.data,o=s?r.offset*2:r.offset,m=u.slice(o,o+i);return z.fromData(m,[t],n,[1],0)}const f=new e(i),a=v(n);if(s)for(let u=0;u<t;u++){const o=r.iget(u);f[u*2]=o.re,f[u*2+1]=o.im}else for(let u=0;u<t;u++){const o=r.iget(u);f[u]=o}return z.fromData(f,[t],n,[1],0)}function ur(r){const t=r.size,n=r.dtype;if(r.isCContiguous){const e=r.data;return z.fromData(e,[t],n,[1],0)}return J(r)}function G(r,t){const n=r.shape,e=n.length,s=r.strides,i=r.data,f=r.dtype;let a;if(t===void 0)a=Array.from({length:e},(h,y)=>e-1-y);else{if(t.length!==e)throw new Error(`axes must have length ${e}, got ${t.length}`);const h=new Set;for(const y of t){const l=y<0?e+y:y;if(l<0||l>=e)throw new Error(`axis ${y} is out of bounds for array of dimension ${e}`);if(h.has(l))throw new Error("repeated axis in transpose");h.add(l)}a=t.map(y=>y<0?e+y:y)}const u=a.map(h=>n[h]),o=Array.from(s),m=a.map(h=>o[h]);return z.fromData(i,u,f,m,r.offset)}function cr(r,t){const n=r.shape,e=n.length,s=r.strides,i=r.data,f=r.dtype;if(t===void 0){const a=[],u=[];for(let o=0;o<e;o++)n[o]!==1&&(a.push(n[o]),u.push(s[o]));return z.fromData(i,a,f,u,r.offset)}else{const a=t<0?e+t:t;if(a<0||a>=e)throw new Error(`axis ${t} is out of bounds for array of dimension ${e}`);if(n[a]!==1)throw new Error(`cannot select an axis which has size not equal to one (axis ${t} has size ${n[a]})`);const u=[],o=[];for(let m=0;m<e;m++)m!==a&&(u.push(n[m]),o.push(s[m]));return z.fromData(i,u,f,o,r.offset)}}function O(r,t){const n=r.shape,e=n.length,s=r.strides,i=r.data,f=r.dtype;let a=t;if(a<0&&(a=e+t+1),a<0||a>e)throw new Error(`axis ${t} is out of bounds for array of dimension ${e+1}`);const u=[...Array.from(n)];u.splice(a,0,1);const o=[...Array.from(s)],m=a<e?s[a]*(n[a]||1):1;return o.splice(a,0,m),z.fromData(i,u,f,o,r.offset)}function dr(r,t,n){const e=r.shape,s=e.length,i=r.strides,f=r.data,a=r.dtype;let u=t<0?s+t:t,o=n<0?s+n:n;if(u<0||u>=s)throw new Error(`axis1 ${t} is out of bounds for array of dimension ${s}`);if(o<0||o>=s)throw new Error(`axis2 ${n} is out of bounds for array of dimension ${s}`);if(u===o)return z.fromData(f,Array.from(e),a,Array.from(i),r.offset);const m=Array.from(e),h=Array.from(i);return[m[u],m[o]]=[m[o],m[u]],[h[u],h[o]]=[h[o],h[u]],z.fromData(f,m,a,h,r.offset)}function H(r,t,n){const e=r.ndim,s=Array.isArray(t)?t:[t],i=Array.isArray(n)?n:[n];if(s.length!==i.length)throw new Error("source and destination must have the same number of elements");const f=s.map(o=>{const m=o<0?e+o:o;if(m<0||m>=e)throw new Error(`source axis ${o} is out of bounds for array of dimension ${e}`);return m}),a=i.map(o=>{const m=o<0?e+o:o;if(m<0||m>=e)throw new Error(`destination axis ${o} is out of bounds for array of dimension ${e}`);return m});if(new Set(f).size!==f.length)throw new Error("repeated axis in source");if(new Set(a).size!==a.length)throw new Error("repeated axis in destination");const u=[];for(let o=0;o<e;o++)f.includes(o)||u.push(o);for(let o=0;o<f.length;o++){const m=a[o];u.splice(m,0,f[o])}return G(r,u)}function R(r,t=0){if(r.length===0)throw new Error("need at least one array to concatenate");if(r.length===1)return r[0].copy();const n=r[0],e=n.ndim,s=n.dtype,i=t<0?e+t:t;if(i<0||i>=e)throw new Error(`axis ${t} is out of bounds for array of dimension ${e}`);for(let l=1;l<r.length;l++){const p=r[l];if(p.ndim!==e)throw new Error("all the input arrays must have same number of dimensions");for(let A=0;A<e;A++)if(A!==i&&p.shape[A]!==n.shape[A])throw new Error("all the input array dimensions except for the concatenation axis must match exactly")}const f=Array.from(n.shape);let a=n.shape[i];for(let l=1;l<r.length;l++)a+=r[l].shape[i];f[i]=a;const u=f.reduce((l,p)=>l*p,1),o=U(s);if(!o)throw new Error(`Cannot concatenate arrays with dtype ${s}`);const m=new o(u),h=T(f);let y=0;for(const l of r){const p=l.shape[i];Q(l,m,f,h,i,y,s),y+=p}return z.fromData(m,f,s)}function Q(r,t,n,e,s,i,f){const a=r.shape,u=a.length,o=r.size,m=f==="int64"||f==="uint64";if(s===0&&r.isCContiguous&&u>0){const l=i*e[0],p=r.data,A=r.offset,w=A+o;t.set(p.subarray(A,w),l);return}if(s===1&&u===2&&r.isCContiguous){const l=a[0],p=a[1],A=n[1],w=r.data,E=r.offset;for(let c=0;c<l;c++){const d=E+c*p,x=c*A+i;t.set(w.subarray(d,d+p),x)}return}const h=new Array(u).fill(0),y=i*e[s];for(let l=0;l<o;l++){const p=r.iget(l);let A=y;for(let w=0;w<u;w++)A+=h[w]*e[w];t[A]=p;for(let w=u-1;w>=0&&(h[w]++,!(h[w]<a[w]));w--)h[w]=0}}function lr(r,t=0){if(r.length===0)throw new Error("need at least one array to stack");const n=r[0],e=n.shape,s=n.ndim,i=t<0?s+1+t:t;if(i<0||i>s)throw new Error(`axis ${t} is out of bounds for array of dimension ${s+1}`);for(let a=1;a<r.length;a++){const u=r[a];if(u.ndim!==s)throw new Error("all input arrays must have the same shape");for(let o=0;o<s;o++)if(u.shape[o]!==e[o])throw new Error("all input arrays must have the same shape")}const f=r.map(a=>O(a,i));return R(f,i)}function V(r){if(r.length===0)throw new Error("need at least one array to stack");const t=r.map(n=>n.ndim===1?D(n,[1,n.shape[0]]):n);return R(t,0)}function W(r){if(r.length===0)throw new Error("need at least one array to stack");return r.every(n=>n.ndim===1)?R(r,0):R(r,1)}function yr(r){if(r.length===0)throw new Error("need at least one array to stack");const t=r.map(n=>n.ndim===1?D(O(D(n,[1,n.shape[0]]),2),[1,n.shape[0],1]):n.ndim===2?O(n,2):n);return R(t,2)}function pr(r,t,n=0){const e=r.shape,s=e.length,i=n<0?s+n:n;if(i<0||i>=s)throw new Error(`axis ${n} is out of bounds for array of dimension ${s}`);const f=e[i];let a;if(typeof t=="number"){if(f%t!==0)throw new Error("array split does not result in an equal division");const u=f/t;a=[];for(let o=1;o<t;o++)a.push(o*u)}else a=t;return L(r,a,i)}function k(r,t,n=0){const e=r.shape,s=e.length,i=n<0?s+n:n;if(i<0||i>=s)throw new Error(`axis ${n} is out of bounds for array of dimension ${s}`);const f=e[i];let a;if(typeof t=="number"){const u=t,o=Math.floor(f/u),m=f%u;a=[];let h=0;for(let y=0;y<u-1;y++)h+=o+(y<m?1:0),a.push(h)}else a=t;return L(r,a,i)}function L(r,t,n){const e=r.shape,s=e[n],i=[0,...t,s],f=[];for(let a=0;a<i.length-1;a++){const u=i[a],o=i[a+1];if(u>o)throw new Error("split indices must be in ascending order");const m=Array.from(e);m[n]=o-u;const h=r.offset+u*r.strides[n];f.push(z.fromData(r.data,m,r.dtype,Array.from(r.strides),h))}return f}function mr(r,t){if(r.ndim<2)throw new Error("vsplit only works on arrays of 2 or more dimensions");return k(r,t,0)}function hr(r,t){if(r.ndim<1)throw new Error("hsplit only works on arrays of 1 or more dimensions");const n=r.ndim===1?0:1;return k(r,t,n)}function Ar(r,t){const n=r.shape,e=n.length,s=r.dtype,i=Array.isArray(t)?t:[t];if(e===2&&i.length===2&&r.isCContiguous){const c=q(r,i[0],i[1]);if(c)return c}if(e===1&&i.length===1&&r.isCContiguous){const c=q(r,1,i[0]);if(c)return z.fromData(c.data,[r.size*i[0]],r.dtype)}const f=Math.max(e,i.length),a=new Array(f).fill(1),u=new Array(f).fill(1);for(let c=0;c<e;c++)a[f-e+c]=n[c];for(let c=0;c<i.length;c++)u[f-i.length+c]=i[c];const o=a.map((c,d)=>c*u[d]),m=o.reduce((c,d)=>c*d,1),h=U(s);if(!h)throw new Error(`Cannot tile array with dtype ${s}`);const y=new h(m),l=T(o);let p=r;e<f&&(p=D(r,a));const A=s==="int64"||s==="uint64",w=p.strides,E=new Array(f).fill(0);for(let c=0;c<m;c++){let d=p.offset;for(let b=0;b<f;b++){const S=E[b]%a[b];d+=S*w[b]}const x=p.data[d];let I=0;for(let b=0;b<f;b++)I+=E[b]*l[b];y[I]=x;for(let b=f-1;b>=0&&(E[b]++,!(E[b]<o[b]));b--)E[b]=0}return z.fromData(y,o,s)}function wr(r,t,n){const e=r.shape,s=e.length,i=r.dtype,f=r.size;if(n===void 0){if(typeof t=="number"&&r.isCContiguous){const g=P(r,t);if(g)return g}const c=f,d=Array.isArray(t)?t:new Array(c).fill(t);if(d.length!==c)throw new Error(`operands could not be broadcast together with shape (${c},) (${d.length},)`);const x=d.reduce((g,B)=>g+B,0),I=U(i);if(!I)throw new Error(`Cannot repeat array with dtype ${i}`);const b=new I(x);let S=0;for(let g=0;g<c;g++){const B=r.iget(g),C=d[g];for(let $=0;$<C;$++)b[S++]=B}return z.fromData(b,[x],i)}const a=n<0?s+n:n;if(a<0||a>=s)throw new Error(`axis ${n} is out of bounds for array of dimension ${s}`);const u=e[a],o=Array.isArray(t)?t:new Array(u).fill(t);if(o.length!==u)throw new Error(`operands could not be broadcast together with shape (${u},) (${o.length},)`);const m=Array.from(e);m[a]=o.reduce((c,d)=>c+d,0);const h=m.reduce((c,d)=>c*d,1),y=U(i);if(!y)throw new Error(`Cannot repeat array with dtype ${i}`);const l=new y(h),p=T(m),A=new Array(s).fill(0),w=i==="int64"||i==="uint64",E=[0];for(let c=0;c<u;c++)E.push(E[c]+o[c]);for(let c=0;c<f;c++){const d=r.iget(c),x=A[a],I=o[x];let b=0;for(let B=0;B<s;B++)B!==a&&(b+=A[B]*p[B]);const S=p[a],g=E[x];for(let B=0;B<I;B++){const C=b+(g+B)*S;l[C]=d}for(let B=s-1;B>=0&&(A[B]++,!(A[B]<e[B]));B--)A[B]=0}return z.fromData(l,m,i)}function br(r,t){const n=r.shape,e=n.length,s=r.dtype,i=r.size;let f;if(t===void 0)f=new Set(Array.from({length:e},(y,l)=>l));else if(typeof t=="number"){const y=t<0?e+t:t;if(y<0||y>=e)throw new Error(`axis ${t} is out of bounds for array of dimension ${e}`);f=new Set([y])}else f=new Set(t.map(y=>{const l=y<0?e+y:y;if(l<0||l>=e)throw new Error(`axis ${y} is out of bounds for array of dimension ${e}`);return l}));const a=U(s);if(!a)throw new Error(`Cannot flip array with dtype ${s}`);const u=v(s);if(f.size===e&&r.isCContiguous&&!F(s)){const y=M(r);if(y)return y}const o=new a(i);if(e===1&&r.isCContiguous){const y=r.data,l=r.offset;for(let p=0;p<i;p++)o[p]=y[l+i-1-p];return z.fromData(o,[...n],s)}if(e===2&&r.isCContiguous){const y=n[0],l=n[1],p=r.data,A=r.offset;if(f.size===2){for(let w=0;w<i;w++)o[w]=p[A+i-1-w];return z.fromData(o,[...n],s)}if(f.size===1){if(f.has(0)){for(let w=0;w<y;w++){const E=A+(y-1-w)*l,c=w*l;for(let d=0;d<l;d++)o[c+d]=p[E+d]}return z.fromData(o,[...n],s)}else if(f.has(1)){for(let w=0;w<y;w++){const E=A+w*l,c=w*l;for(let d=0;d<l;d++)o[c+d]=p[E+l-1-d]}return z.fromData(o,[...n],s)}}}const m=new Array(e),h=new Array(e).fill(0);for(let y=0;y<i;y++){for(let A=0;A<e;A++)m[A]=f.has(A)?n[A]-1-h[A]:h[A];let l=r.offset;for(let A=0;A<e;A++)l+=m[A]*r.strides[A];const p=r.data[l];o[y]=p;for(let A=e-1;A>=0&&(h[A]++,!(h[A]<n[A]));A--)h[A]=0}return z.fromData(o,[...n],s)}function Sr(r,t=1,n=[0,1]){const e=r.shape,s=e.length,i=r.dtype;if(s<2)throw new Error("Input must be at least 2-D");const f=n[0]<0?s+n[0]:n[0],a=n[1]<0?s+n[1]:n[1];if(f<0||f>=s||a<0||a>=s)throw new Error(`Axes are out of bounds for array of dimension ${s}`);if(f===a)throw new Error("Axes must be different");if(t=(t%4+4)%4,t===0)return r.copy();if(s===2&&f===0&&a===1&&r.isCContiguous){if(t===1){const c=K(r);if(c)return c}else if(t===2){const c=M(r);if(c)return c}}const u=U(i);if(!u)throw new Error(`Cannot rotate array with dtype ${i}`);const o=[...e];(t===1||t===3)&&([o[f],o[a]]=[o[a],o[f]]);const m=o.reduce((c,d)=>c*d,1),h=new u(m),y=v(i),l=r.data;if(s===2&&f===0&&a===1){const c=e[0],d=e[1];if(t===1){const x=d,I=c;if(y){const b=l,S=h;for(let g=0;g<x;g++){const B=g*I,C=d-1-g;for(let $=0;$<I;$++)S[B+$]=b[$*d+C]}}else{const b=l,S=h;for(let g=0;g<x;g++){const B=g*I,C=d-1-g;for(let $=0;$<I;$++)S[B+$]=b[$*d+C]}}}else if(t===2)if(y){const x=l,I=h;for(let b=0;b<c;b++){const S=b*d,g=(c-1-b)*d;for(let B=0;B<d;B++)I[S+B]=x[g+(d-1-B)]}}else{const x=l,I=h;for(let b=0;b<c;b++){const S=b*d,g=(c-1-b)*d;for(let B=0;B<d;B++)I[S+B]=x[g+(d-1-B)]}}else{const x=d,I=c;if(y){const b=l,S=h;for(let g=0;g<x;g++){const B=g*I;for(let C=0;C<I;C++)S[B+C]=b[(c-1-C)*d+g]}}else{const b=l,S=h;for(let g=0;g<x;g++){const B=g*I;for(let C=0;C<I;C++)S[B+C]=b[(c-1-C)*d+g]}}}return z.fromData(h,o,i)}const p=T(o),A=T(e),w=new Array(s).fill(0),E=new Array(s);for(let c=0;c<r.size;c++){for(let S=0;S<s;S++)E[S]=w[S];let d,x;t===1?(d=e[a]-1-w[a],x=w[f]):t===2?(d=e[f]-1-w[f],x=e[a]-1-w[a],E[f]=d,E[a]=x):(d=w[a],x=e[f]-1-w[f]),t!==2&&(E[f]=d,E[a]=x);let I=0;for(let S=0;S<s;S++)I+=E[S]*p[S];let b=0;for(let S=0;S<s;S++)b+=w[S]*A[S];if(y){const S=l,g=h;g[I]=S[b]}else{const S=l,g=h;g[I]=S[b]}for(let S=s-1;S>=0&&(w[S]++,!(w[S]<e[S]));S--)w[S]=0}return z.fromData(h,o,i)}function gr(r,t,n){const e=r.shape,s=e.length,i=r.dtype,f=r.size;if(n===void 0){const p=Array.isArray(t)?t.reduce((d,x)=>d+x,0):t;if(r.isCContiguous){const d=j(r,p);if(d)return d}const A=J(r),w=U(i);if(!w)throw new Error(`Cannot roll array with dtype ${i}`);const E=new w(f),c=v(i);for(let d=0;d<f;d++){const x=((d-p)%f+f)%f,I=A.iget(x);E[d]=I}return z.fromData(E,[...e],i)}const a=Array.isArray(t)?t:[t],u=Array.isArray(n)?n:[n];if(a.length!==u.length)throw new Error("shift and axis must have the same length");const o=u.map(p=>{const A=p<0?s+p:p;if(A<0||A>=s)throw new Error(`axis ${p} is out of bounds for array of dimension ${s}`);return A}),m=U(i);if(!m)throw new Error(`Cannot roll array with dtype ${i}`);const h=new m(f),y=v(i),l=new Array(s).fill(0);for(let p=0;p<f;p++){const A=[...l];for(let c=0;c<o.length;c++){const d=o[c],x=e[d],I=a[c];A[d]=((A[d]-I)%x+x)%x}let w=r.offset;for(let c=0;c<s;c++)w+=A[c]*r.strides[c];const E=r.data[w];h[p]=E;for(let c=s-1;c>=0&&(l[c]++,!(l[c]<e[c]));c--)l[c]=0}return z.fromData(h,[...e],i)}function Br(r,t,n=0){const e=r.ndim;let s=t<0?e+t:t;if(s<0||s>=e)throw new Error(`axis ${t} is out of bounds for array of dimension ${e}`);let i=n<0?e+n:n;if(i<0||i>e)throw new Error(`start ${n} is out of bounds`);return s<i&&i--,s===i?z.fromData(r.data,Array.from(r.shape),r.dtype,Array.from(r.strides),r.offset):H(r,s,i)}function xr(r,t){if(r.ndim<3)throw new Error("dsplit only works on arrays of 3 or more dimensions");return k(r,t,2)}function Er(r){if(r.length===0)throw new Error("need at least one array to stack");const t=r.map(n=>n.ndim===1?D(n,[n.shape[0],1]):n);return W(t)}const Ir=V;function zr(r,t){const n=r.dtype,e=t.reduce((u,o)=>u*o,1),s=r.size,i=U(n);if(!i)throw new Error(`Cannot resize array with dtype ${n}`);const f=new i(e),a=v(n);for(let u=0;u<e;u++){const o=u%s,m=r.iget(o);f[u]=m}return z.fromData(f,t,n)}function Cr(r){return r.map(t=>t.ndim===0?D(t,[1]):t)}function $r(r){return r.map(t=>t.ndim===0?D(t,[1,1]):t.ndim===1?D(t,[1,t.shape[0]]):t)}function Dr(r){return r.map(t=>t.ndim===0?D(t,[1,1,1]):t.ndim===1?D(t,[1,t.shape[0],1]):t.ndim===2?D(t,[t.shape[0],t.shape[1],1]):t)}function Ur(r,t=0){return R(r,t)}function Tr(r,t=0){const n=r.shape,e=n.length,s=t<0?e+t:t;if(s<0||s>=e)throw new Error(`axis ${t} is out of bounds for array of dimension ${e}`);const i=n[s],f=new Array(i),a=r.data,u=r.dtype,o=r.strides,m=r.offset,h=[],y=[];for(let p=0;p<e;p++)p!==s&&(h.push(n[p]),y.push(o[p]));const l=o[s];for(let p=0;p<i;p++)f[p]=z.fromData(a,h,u,y,m+p*l);return f}function Rr(r,t=1){if(r.length===0)throw new Error("need at least one array to block");return r.length===1?r[0].copy():R(r,-1)}export{k as arraySplit,Cr as atleast1d,$r as atleast2d,Dr as atleast3d,Rr as block,Er as columnStack,Ur as concat,R as concatenate,xr as dsplit,yr as dstack,O as expandDims,J as flatten,br as flip,hr as hsplit,W as hstack,H as moveaxis,ur as ravel,wr as repeat,D as reshape,zr as resize,gr as roll,Br as rollaxis,Sr as rot90,Ir as rowStack,sr as slice,fr as sliceKeepDim,pr as split,cr as squeeze,lr as stack,dr as swapaxes,Ar as tile,G as transpose,Tr as unstack,mr as vsplit,V as vstack};
|
|
1
|
+
import{ArrayStorage as I,computeStrides as R}from"../storage.js";import{getTypedArrayConstructor as L,isBigIntDType as v,isComplexDType as U,hasFloat16 as k}from"../dtype.js";import{wasmTile2D as q}from"../wasm/tile.js";import{wasmRoll as H}from"../wasm/roll.js";import{wasmRepeat as Q}from"../wasm/repeat.js";import{parseSlice as N,normalizeSlice as _}from"../slicing.js";import{expandEllipsis as j}from"../internal/indexing.js";function ur(r,...t){if(t.length===0)return r;t=j(t,r.ndim);const n=[],o=[];let u=r.offset,a=0;for(let f=0;f<t.length;f++){const s=t[f];if(typeof s=="number"){const i=s,e=r.shape[a],l=i<0?e+i:i;if(l<0||l>=e)throw new Error(`Index ${i} is out of bounds for size ${e}`);const d=r.strides[a];a++,u+=l*d;continue}else if(s==="newaxis")n.push(1),o.push(0);else{const i=N(s),e=_(i,r.shape[a]),l=r.strides[a];if(a++,u+=e.start*l,e.isIndex)continue;const d=Math.max(0,Math.ceil((e.stop-e.start)/e.step));n.push(d),o.push(l*e.step)}}return I.fromDataShared(r.data,n,r.dtype,o,u,r.wasmRegion)}function cr(r,...t){if(t.length===0)return r;t=j(t,r.ndim);const n=[],o=[];let u=r.offset,a=0;for(let f=0;f<t.length;f++){const s=t[f];if(typeof s=="number"){const i=r.strides[a];a++,u+=s*i,n.push(1),o.push(i)}else if(s==="newaxis")n.push(1),o.push(0);else{const i=N(s),e=_(i,r.shape[a]),l=r.strides[a];a++,u+=e.start*l;const d=e.isIndex?1:Math.max(0,Math.ceil((e.stop-e.start)/e.step));n.push(d),o.push(l*e.step)}}return I.fromDataShared(r.data,n,r.dtype,o,u,r.wasmRegion)}function C(r,t){const n=r.size,o=r.dtype,u=t.indexOf(-1);let a;if(u!==-1){const d=t.reduce((S,h,A)=>A===u?S:S*h,1),y=n/d;if(!Number.isInteger(y))throw new Error(`cannot reshape array of size ${n} into shape ${JSON.stringify(t)}`);a=t.map((S,h)=>h===u?y:S)}else a=t;if(a.reduce((d,y)=>d*y,1)!==n)throw new Error(`cannot reshape array of size ${n} into shape ${JSON.stringify(a)}`);if(r.isCContiguous){const d=r.data;return I.fromDataShared(d,a,o,R(a),0,r.wasmRegion)}const s=U(o),i=I.empty(a,o),e=i.data,l=v(o);if(s)for(let d=0;d<n;d++){const y=r.iget(d);e[d*2]=y.re,e[d*2+1]=y.im}else if(l)for(let d=0;d<n;d++)e[d]=r.iget(d);else for(let d=0;d<n;d++)e[d]=r.iget(d);return i}function J(r){const t=r.size,n=r.dtype;if(!L(n))throw new Error(`Cannot flatten array with dtype ${n}`);const u=U(n),a=u?t*2:t;if(r.isCContiguous){const e=r.data,l=u?r.offset*2:r.offset,d=I.empty([t],n);return d.data.set(e.subarray(l,l+a)),d}const f=I.empty([t],n),s=f.data,i=v(n);if(u)for(let e=0;e<t;e++){const l=r.iget(e);s[e*2]=l.re,s[e*2+1]=l.im}else for(let e=0;e<t;e++){const l=r.iget(e);s[e]=l}return f}function lr(r){const t=r.size,n=r.dtype;if(r.isCContiguous){const o=r.data;return I.fromDataShared(o,[t],n,[1],0,r.wasmRegion)}return J(r)}function V(r,t){const n=r.shape,o=n.length,u=r.strides,a=r.data,f=r.dtype;let s;if(t===void 0)s=Array.from({length:o},(d,y)=>o-1-y);else{if(t.length!==o)throw new Error(`axes must have length ${o}, got ${t.length}`);const d=new Set;for(const y of t){const S=y<0?o+y:y;if(S<0||S>=o)throw new Error(`axis ${y} is out of bounds for array of dimension ${o}`);if(d.has(S))throw new Error("repeated axis in transpose");d.add(S)}s=t.map(y=>y<0?o+y:y)}const i=s.map(d=>n[d]),e=Array.from(u),l=s.map(d=>e[d]);return I.fromDataShared(a,i,f,l,r.offset,r.wasmRegion)}function dr(r,t){const n=r.shape,o=n.length,u=r.strides,a=r.data,f=r.dtype;if(t===void 0){const s=[],i=[];for(let e=0;e<o;e++)n[e]!==1&&(s.push(n[e]),i.push(u[e]));return I.fromDataShared(a,s,f,i,r.offset,r.wasmRegion)}else{const s=t<0?o+t:t;if(s<0||s>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);if(n[s]!==1)throw new Error(`cannot select an axis which has size not equal to one (axis ${t} has size ${n[s]})`);const i=[],e=[];for(let l=0;l<o;l++)l!==s&&(i.push(n[l]),e.push(u[l]));return I.fromDataShared(a,i,f,e,r.offset,r.wasmRegion)}}function T(r,t){const n=r.shape,o=n.length,u=r.strides,a=r.data,f=r.dtype;let s=t;if(s<0&&(s=o+t+1),s<0||s>o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o+1}`);const i=[...Array.from(n)];i.splice(s,0,1);const e=[...Array.from(u)],l=s<o?u[s]*(n[s]||1):1;return e.splice(s,0,l),I.fromDataShared(a,i,f,e,r.offset,r.wasmRegion)}function yr(r,t,n){const o=r.shape,u=o.length,a=r.strides,f=r.data,s=r.dtype;let i=t<0?u+t:t,e=n<0?u+n:n;if(i<0||i>=u)throw new Error(`axis1 ${t} is out of bounds for array of dimension ${u}`);if(e<0||e>=u)throw new Error(`axis2 ${n} is out of bounds for array of dimension ${u}`);if(i===e)return I.fromDataShared(f,Array.from(o),s,Array.from(a),r.offset,r.wasmRegion);const l=Array.from(o),d=Array.from(a);return[l[i],l[e]]=[l[e],l[i]],[d[i],d[e]]=[d[e],d[i]],I.fromDataShared(f,l,s,d,r.offset,r.wasmRegion)}function W(r,t,n){const o=r.ndim,u=Array.isArray(t)?t:[t],a=Array.isArray(n)?n:[n];if(u.length!==a.length)throw new Error("source and destination must have the same number of elements");const f=u.map(e=>{const l=e<0?o+e:e;if(l<0||l>=o)throw new Error(`source axis ${e} is out of bounds for array of dimension ${o}`);return l}),s=a.map(e=>{const l=e<0?o+e:e;if(l<0||l>=o)throw new Error(`destination axis ${e} is out of bounds for array of dimension ${o}`);return l});if(new Set(f).size!==f.length)throw new Error("repeated axis in source");if(new Set(s).size!==s.length)throw new Error("repeated axis in destination");const i=[];for(let e=0;e<o;e++)f.includes(e)||i.push(e);for(let e=0;e<f.length;e++){const l=s[e];i.splice(l,0,f[e])}return V(r,i)}function D(r,t=0){if(r.length===0)throw new Error("need at least one array to concatenate");if(r.length===1)return r[0].copy();const n=r[0],o=n.ndim,u=n.dtype,a=t<0?o+t:t;if(a<0||a>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);for(let y=1;y<r.length;y++){const S=r[y];if(S.ndim!==o)throw new Error("all the input arrays must have same number of dimensions");for(let h=0;h<o;h++)if(h!==a&&S.shape[h]!==n.shape[h])throw new Error("all the input array dimensions except for the concatenation axis must match exactly")}const f=Array.from(n.shape);let s=n.shape[a];for(let y=1;y<r.length;y++)s+=r[y].shape[a];f[a]=s;const i=I.empty(f,u),e=i.data,l=R(f);let d=0;for(const y of r){const S=y.shape[a];X(y,e,f,l,a,d,u),d+=S}return i}function X(r,t,n,o,u,a,f){const s=r.shape,i=s.length,e=r.size,l=f==="int64"||f==="uint64",d=f==="complex128"||f==="complex64",y=d?2:1;if(u===0&&r.isCContiguous&&i>0){const A=a*o[0]*y,x=r.data,g=r.offset*y,c=g+e*y;t.set(x.subarray(g,c),A);return}if(u===1&&i===2&&r.isCContiguous){const A=s[0],x=s[1],g=n[1],c=r.data,b=r.offset*y;for(let w=0;w<A;w++){const m=b+w*x*y,p=(w*g+a)*y;t.set(c.subarray(m,m+x*y),p)}return}if(f==="float16"&&k&&r.isCContiguous){const A=new Float32Array(r.data.subarray(r.offset,r.offset+e)),x=new Array(i).fill(0),g=a*o[u];for(let c=0;c<e;c++){let b=g;for(let w=0;w<i;w++)b+=x[w]*o[w];t[b]=A[c];for(let w=i-1;w>=0&&(x[w]++,!(x[w]<s[w]));w--)x[w]=0}return}const S=new Array(i).fill(0),h=a*o[u];for(let A=0;A<e;A++){const x=r.iget(A);let g=h;for(let c=0;c<i;c++)g+=S[c]*o[c];if(d){const c=x;t[g*2]=c.re,t[g*2+1]=c.im}else t[g]=x;for(let c=i-1;c>=0&&(S[c]++,!(S[c]<s[c]));c--)S[c]=0}}function mr(r,t=0){if(r.length===0)throw new Error("need at least one array to stack");const n=r[0],o=n.shape,u=n.ndim,a=t<0?u+1+t:t;if(a<0||a>u)throw new Error(`axis ${t} is out of bounds for array of dimension ${u+1}`);for(let i=1;i<r.length;i++){const e=r[i];if(e.ndim!==u)throw new Error("all input arrays must have the same shape");for(let l=0;l<u;l++)if(e.shape[l]!==o[l])throw new Error("all input arrays must have the same shape")}const f=r.map(i=>T(i,a)),s=D(f,a);for(const i of f)i.dispose();return s}function Y(r){if(r.length===0)throw new Error("need at least one array to stack");const t=r.map(n=>n.ndim===1?C(n,[1,n.shape[0]]):n);return D(t,0)}function Z(r){if(r.length===0)throw new Error("need at least one array to stack");return r.every(n=>n.ndim===1)?D(r,0):D(r,1)}function pr(r){if(r.length===0)throw new Error("need at least one array to stack");const t=r.map(n=>n.ndim===1?C(T(C(n,[1,n.shape[0]]),2),[1,n.shape[0],1]):n.ndim===2?T(n,2):n);return D(t,2)}function hr(r,t,n=0){const o=r.shape,u=o.length,a=n<0?u+n:n;if(a<0||a>=u)throw new Error(`axis ${n} is out of bounds for array of dimension ${u}`);const f=o[a];let s;if(typeof t=="number"){if(f%t!==0)throw new Error("array split does not result in an equal division");const i=f/t;s=[];for(let e=1;e<t;e++)s.push(e*i)}else s=t;return K(r,s,a)}function O(r,t,n=0){const o=r.shape,u=o.length,a=n<0?u+n:n;if(a<0||a>=u)throw new Error(`axis ${n} is out of bounds for array of dimension ${u}`);const f=o[a];let s;if(typeof t=="number"){const i=t,e=Math.floor(f/i),l=f%i;s=[];let d=0;for(let y=0;y<i-1;y++)d+=e+(y<l?1:0),s.push(d)}else s=t;return K(r,s,a)}function K(r,t,n){const o=r.shape,u=o[n],a=[0,...t,u],f=[];for(let s=0;s<a.length-1;s++){const i=a[s],e=a[s+1];if(i>e)throw new Error("split indices must be in ascending order");const l=Array.from(o);l[n]=e-i;const d=r.offset+i*r.strides[n];f.push(I.fromData(r.data,l,r.dtype,Array.from(r.strides),d))}return f}function Ar(r,t){if(r.ndim<2)throw new Error("vsplit only works on arrays of 2 or more dimensions");return O(r,t,0)}function wr(r,t){if(r.ndim<1)throw new Error("hsplit only works on arrays of 1 or more dimensions");const n=r.ndim===1?0:1;return O(r,t,n)}function Sr(r,t){const n=r.shape,o=n.length,u=r.dtype,a=Array.isArray(t)?t:[t];if(o===2&&a.length===2&&r.isCContiguous){const c=q(r,a[0],a[1]);if(c)return c}if(o===1&&a.length===1&&r.isCContiguous){const c=q(r,1,a[0]);if(c)return I.fromData(c.data,[r.size*a[0]],r.dtype)}const f=Math.max(o,a.length),s=new Array(f).fill(1),i=new Array(f).fill(1);for(let c=0;c<o;c++)s[f-o+c]=n[c];for(let c=0;c<a.length;c++)i[f-a.length+c]=a[c];const e=s.map((c,b)=>c*i[b]),l=e.reduce((c,b)=>c*b,1),d=I.empty(e,u),y=d.data,S=R(e);let h=r;o<f&&(h=C(r,s));const A=u==="int64"||u==="uint64",x=h.strides;if(u==="float16"&&k&&h.isCContiguous){const c=h.size,b=new Float32Array(h.data.subarray(h.offset,h.offset+c)),w=new Float32Array(l),m=new Array(f).fill(0);for(let p=0;p<l;p++){let F=0;for(let z=0;z<f;z++){const E=m[z]%s[z];F+=E*x[z]}w[p]=b[F];for(let z=f-1;z>=0&&(m[z]++,!(m[z]<e[z]));z--)m[z]=0}return y.set(w),d}const g=new Array(f).fill(0);for(let c=0;c<l;c++){let b=h.offset;for(let p=0;p<f;p++){const F=g[p]%s[p];b+=F*x[p]}const w=h.data[b];let m=0;for(let p=0;p<f;p++)m+=g[p]*S[p];y[m]=w;for(let p=f-1;p>=0&&(g[p]++,!(g[p]<e[p]));p--)g[p]=0}return d}function br(r,t,n){const o=r.shape,u=o.length,a=r.dtype,f=r.size;if(n===void 0){if(typeof t=="number"&&r.isCContiguous){const z=Q(r,t);if(z)return z}const c=f,b=Array.isArray(t)?t:new Array(c).fill(t);if(b.length!==c)throw new Error(`operands could not be broadcast together with shape (${c},) (${b.length},)`);const w=b.reduce((z,E)=>z+E,0),m=I.empty([w],a),p=m.data;if(a==="float16"&&k&&r.isCContiguous){const z=new Float32Array(r.data.subarray(r.offset,r.offset+c)),E=new Float32Array(w);let B=0;for(let $=0;$<c;$++){const P=z[$],G=b[$];for(let M=0;M<G;M++)E[B++]=P}return p.set(E),m}let F=0;for(let z=0;z<c;z++){const E=r.iget(z),B=b[z];for(let $=0;$<B;$++)p[F++]=E}return m}const s=n<0?u+n:n;if(s<0||s>=u)throw new Error(`axis ${n} is out of bounds for array of dimension ${u}`);const i=o[s],e=Array.isArray(t)?t:new Array(i).fill(t);if(e.length!==i)throw new Error(`operands could not be broadcast together with shape (${i},) (${e.length},)`);const l=Array.from(o);l[s]=e.reduce((c,b)=>c+b,0);const d=I.empty(l,a),y=d.data,S=l.reduce((c,b)=>c*b,1),h=R(l),A=new Array(u).fill(0),x=a==="int64"||a==="uint64",g=[0];for(let c=0;c<i;c++)g.push(g[c]+e[c]);if(a==="float16"&&k&&r.isCContiguous){const c=new Float32Array(r.data.subarray(r.offset,r.offset+f)),b=new Float32Array(S);for(let w=0;w<f;w++){const m=c[w],p=A[s],F=e[p];let z=0;for(let $=0;$<u;$++)$!==s&&(z+=A[$]*h[$]);const E=h[s],B=g[p];for(let $=0;$<F;$++)b[z+(B+$)*E]=m;for(let $=u-1;$>=0&&(A[$]++,!(A[$]<o[$]));$--)A[$]=0}return y.set(b),d}for(let c=0;c<f;c++){const b=r.iget(c),w=A[s],m=e[w];let p=0;for(let E=0;E<u;E++)E!==s&&(p+=A[E]*h[E]);const F=h[s],z=g[w];for(let E=0;E<m;E++){const B=p+(z+E)*F;y[B]=b}for(let E=u-1;E>=0&&(A[E]++,!(A[E]<o[E]));E--)A[E]=0}return d}function xr(r,t){const n=r.shape,o=n.length,u=r.dtype;let a;if(t===void 0)a=new Set(Array.from({length:o},(i,e)=>e));else if(typeof t=="number"){const i=t<0?o+t:t;if(i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);a=new Set([i])}else a=new Set(t.map(i=>{const e=i<0?o+i:i;if(e<0||e>=o)throw new Error(`axis ${i} is out of bounds for array of dimension ${o}`);return e}));const f=Array.from(r.strides);let s=r.offset;for(const i of a)s+=(n[i]-1)*f[i],f[i]=-f[i];return I.fromDataShared(r.data,[...n],u,f,s,r.wasmRegion)}function gr(r,t=1,n=[0,1]){const o=r.shape,u=o.length,a=r.dtype;if(u<2)throw new Error("Input must be at least 2-D");const f=n[0]<0?u+n[0]:n[0],s=n[1]<0?u+n[1]:n[1];if(f<0||f>=u||s<0||s>=u)throw new Error(`Axes are out of bounds for array of dimension ${u}`);if(f===s)throw new Error("Axes must be different");if(t=(t%4+4)%4,t===0)return r.copy();const i=Array.from(r.strides),e=[...o],l=i[f],d=i[s],y=o[f],S=o[s];let h=r.offset;return t===1?(i[f]=-d,i[s]=l,h+=(S-1)*d,e[f]=S,e[s]=y):t===2?(i[f]=-l,i[s]=-d,h+=(y-1)*l+(S-1)*d):(i[f]=d,i[s]=-l,h+=(y-1)*l,e[f]=S,e[s]=y),I.fromDataShared(r.data,e,a,i,h,r.wasmRegion)}function zr(r,t,n){const o=r.shape,u=o.length,a=r.dtype,f=r.size;if(n===void 0){const A=Array.isArray(t)?t.reduce((m,p)=>m+p,0):t;if(r.isCContiguous){const m=H(r,A);if(m)return m}const x=J(r),g=I.empty([...o],a),c=g.data,b=v(a);if(a==="float16"&&k&&x.isCContiguous){const m=new Float32Array(x.data.subarray(x.offset,x.offset+f)),p=new Float32Array(f);for(let F=0;F<f;F++){const z=((F-A)%f+f)%f;p[F]=m[z]}return c.set(p),g}const w=U(a);for(let m=0;m<f;m++){const p=((m-A)%f+f)%f;if(w){const F=x.iget(p);c[m*2]=F.re,c[m*2+1]=F.im}else c[m]=x.iget(p)}return g}const s=Array.isArray(t)?t:[t],i=Array.isArray(n)?n:[n];if(s.length!==i.length)throw new Error("shift and axis must have the same length");const e=i.map(A=>{const x=A<0?u+A:A;if(x<0||x>=u)throw new Error(`axis ${A} is out of bounds for array of dimension ${u}`);return x}),l=I.empty([...o],a),d=l.data,y=v(a),S=new Array(u).fill(0);if(a==="float16"&&k&&r.isCContiguous){const A=new Float32Array(r.data.subarray(r.offset,r.offset+f)),x=new Float32Array(f),g=r.strides;for(let c=0;c<f;c++){const b=[...S];for(let m=0;m<e.length;m++){const p=e[m],F=o[p],z=s[m];b[p]=((b[p]-z)%F+F)%F}let w=0;for(let m=0;m<u;m++)w+=b[m]*g[m];x[c]=A[w];for(let m=u-1;m>=0&&(S[m]++,!(S[m]<o[m]));m--)S[m]=0}return d.set(x),l}const h=U(a);for(let A=0;A<f;A++){const x=[...S];for(let c=0;c<e.length;c++){const b=e[c],w=o[b],m=s[c];x[b]=((x[b]-m)%w+w)%w}let g=r.offset;for(let c=0;c<u;c++)g+=x[c]*r.strides[c];if(h){const c=g*2;d[A*2]=r.data[c],d[A*2+1]=r.data[c+1]}else d[A]=r.data[g];for(let c=u-1;c>=0&&(S[c]++,!(S[c]<o[c]));c--)S[c]=0}return l}function Er(r,t,n=0){const o=r.ndim;let u=t<0?o+t:t;if(u<0||u>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let a=n<0?o+n:n;if(a<0||a>o)throw new Error(`start ${n} is out of bounds`);return u<a&&a--,u===a?I.fromData(r.data,Array.from(r.shape),r.dtype,Array.from(r.strides),r.offset):W(r,u,a)}function Ir(r,t){if(r.ndim<3)throw new Error("dsplit only works on arrays of 3 or more dimensions");return O(r,t,2)}function $r(r){if(r.length===0)throw new Error("need at least one array to stack");const t=r.map(n=>n.ndim===1?C(n,[n.shape[0],1]):n);return Z(t)}const Fr=Y;function Cr(r,t){const n=r.dtype,o=t.reduce((e,l)=>e*l,1),u=r.size;if(!L(n))throw new Error(`Cannot resize array with dtype ${n}`);const f=I.empty(t,n),s=f.data,i=v(n);for(let e=0;e<o;e++){const l=e%u,d=r.iget(l);s[e]=d}return f}function Br(r){return r.map(t=>t.ndim===0?C(t,[1]):t)}function Dr(r){return r.map(t=>t.ndim===0?C(t,[1,1]):t.ndim===1?C(t,[1,t.shape[0]]):t)}function kr(r){return r.map(t=>t.ndim===0?C(t,[1,1,1]):t.ndim===1?C(t,[1,t.shape[0],1]):t.ndim===2?C(t,[t.shape[0],t.shape[1],1]):t)}function vr(r,t=0){return D(r,t)}function Rr(r,t=0){const n=r.shape,o=n.length,u=t<0?o+t:t;if(u<0||u>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);const a=n[u],f=new Array(a),s=r.data,i=r.dtype,e=r.strides,l=r.offset,d=[],y=[];for(let h=0;h<o;h++)h!==u&&(d.push(n[h]),y.push(e[h]));const S=e[u];for(let h=0;h<a;h++)f[h]=I.fromData(s,d,i,y,l+h*S);return f}function Ur(r,t=1){if(r.length===0)throw new Error("need at least one array to block");return r.length===1?r[0].copy():D(r,-1)}export{O as arraySplit,Br as atleast1d,Dr as atleast2d,kr as atleast3d,Ur as block,$r as columnStack,vr as concat,D as concatenate,Ir as dsplit,pr as dstack,T as expandDims,J as flatten,xr as flip,wr as hsplit,Z as hstack,W as moveaxis,lr as ravel,br as repeat,C as reshape,Cr as resize,zr as roll,Er as rollaxis,gr as rot90,Fr as rowStack,ur as slice,cr as sliceKeepDim,hr as split,dr as squeeze,mr as stack,yr as swapaxes,Sr as tile,V as transpose,Rr as unstack,Ar as vsplit,Y as vstack};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ArrayStorage as M}from"../storage";import{isBigIntDType as L,isComplexDType as $}from"../dtype";import{computeStrides as V,precomputeAxisOffsets as _}from"../internal/indexing";import{wasmReduceCountNz as Z}from"../wasm/reduce_count_nz";import{wasmSort as G,wasmSortSlices as H}from"../wasm/sort";import{wasmArgsort as J,wasmArgsortSlices as Q}from"../wasm/argsort";import{wasmPartition as k,wasmPartitionSlices as tt}from"../wasm/partition";import{wasmArgpartition as et,wasmArgpartitionSlices as rt}from"../wasm/argpartition";import{wasmSearchsorted as ot}from"../wasm/searchsorted";import{wasmLexsort as st}from"../wasm/lexsort";import{wasmExtract as nt,wasmWhere as it}from"../wasm/gather";function E(t,p,e){if(e){const n=t[p*2],x=t[p*2+1];return n!==0||x!==0}return!!t[p]}function j(t,p,e,n){const x=isNaN(t)||isNaN(p),b=isNaN(e)||isNaN(n);return x&&b?0:x?1:b||t<e?-1:t>e?1:p<n?-1:p>n?1:0}function Ct(t,p=-1){const e=t.shape,n=e.length,x=t.dtype,b=t.data,m=t.offset,I=t.strides;if(n===0)return t.copy();let u=p;if(u<0&&(u=n+u),u<0||u>=n)throw new Error(`axis ${p} is out of bounds for array of dimension ${n}`);const o=t.copy(),i=o.data,s=e[u],v=Array.from(e).filter((r,y)=>y!==u),h=v.length===0?1:v.reduce((r,y)=>r*y,1),{baseOffsets:c,axisStride:d}=_(e,I,m,u,h),f=V(e),{baseOffsets:l,axisStride:a}=_(e,f,0,u,h);if(n===1&&o.isCContiguous){const r=G(o);if(r)return r}if(a===1&&H(i,l,s,h,x))return o;if($(x)){const r=b,y=i;for(let A=0;A<h;A++){const N=[];let S=c[A];for(let w=0;w<s;w++)N.push({re:r[S*2],im:r[S*2+1],idx:w}),S+=d;N.sort((w,T)=>j(w.re,w.im,T.re,T.im));let z=l[A];for(let w=0;w<s;w++)y[z*2]=N[w].re,y[z*2+1]=N[w].im,z+=a}}else if(L(x)){const r=b,y=i;for(let A=0;A<h;A++){const N=[];let S=c[A];for(let w=0;w<s;w++)N.push({value:r[S],idx:w}),S+=d;N.sort((w,T)=>w.value<T.value?-1:w.value>T.value?1:0);let z=l[A];for(let w=0;w<s;w++)y[z]=N[w].value,z+=a}}else for(let r=0;r<h;r++){const y=[];let A=c[r];for(let S=0;S<s;S++)y.push(Number(b[A])),A+=d;y.sort((S,z)=>isNaN(S)&&isNaN(z)?0:isNaN(S)?1:isNaN(z)?-1:S-z);let N=l[r];for(let S=0;S<s;S++)i[N]=y[S],N+=a}return o}function Ft(t,p=-1){const e=t.shape,n=e.length,x=t.dtype,b=t.data,m=t.offset,I=t.strides;if(n===0)return M.zeros([0],"int32");let u=p;if(u<0&&(u=n+u),u<0||u>=n)throw new Error(`axis ${p} is out of bounds for array of dimension ${n}`);const o=M.zeros(Array.from(e),"int32"),i=o.data,s=e[u],v=Array.from(e).filter((r,y)=>y!==u),h=v.length===0?1:v.reduce((r,y)=>r*y,1),{baseOffsets:c,axisStride:d}=_(e,I,m,u,h),f=V(e),{baseOffsets:l,axisStride:a}=_(e,f,0,u,h);if(n===1&&t.isCContiguous){const r=J(t);if(r)return r}if(a===1&&d===1&&Q(b,i,c,l,s,h,x))return o;if($(x)){const r=b;for(let y=0;y<h;y++){const A=[];let N=c[y];for(let z=0;z<s;z++)A.push({re:r[N*2],im:r[N*2+1],idx:z}),N+=d;A.sort((z,w)=>j(z.re,z.im,w.re,w.im));let S=l[y];for(let z=0;z<s;z++)i[S]=A[z].idx,S+=a}}else if(L(x)){const r=b;for(let y=0;y<h;y++){const A=[];let N=c[y];for(let z=0;z<s;z++)A.push({value:r[N],idx:z}),N+=d;A.sort((z,w)=>z.value<w.value?-1:z.value>w.value?1:0);let S=l[y];for(let z=0;z<s;z++)i[S]=A[z].idx,S+=a}}else for(let r=0;r<h;r++){const y=[];let A=c[r];for(let S=0;S<s;S++)y.push({value:Number(b[A]),idx:S}),A+=d;y.sort((S,z)=>isNaN(S.value)&&isNaN(z.value)?0:isNaN(S.value)?1:isNaN(z.value)?-1:S.value-z.value);let N=l[r];for(let S=0;S<s;S++)i[N]=y[S].idx,N+=a}return o}function Dt(t){if(t.length===0)return M.zeros([0],"int32");const e=t[0].size;for(const s of t){if(s.ndim!==1)throw new Error("keys must be 1D arrays");if(s.size!==e)throw new Error("all keys must have the same length")}const n=st(t);if(n)return n;const x=[];for(let s=0;s<e;s++)x.push(s);const b=t.map(s=>$(s.dtype)),m=t.map(s=>s.isCContiguous),I=t.map(s=>s.data),u=t.map(s=>s.offset);x.sort((s,v)=>{for(let h=t.length-1;h>=0;h--)if(b[h]){let c,d,f,l;if(m[h]){const a=I[h],r=u[h];c=a[(r+s)*2],d=a[(r+s)*2+1],f=a[(r+v)*2],l=a[(r+v)*2+1]}else{const a=t[h].iget(s),r=t[h].iget(v);c=a.re,d=a.im,f=r.re,l=r.im}if(c<f)return-1;if(c>f)return 1;if(d<l)return-1;if(d>l)return 1}else{let c,d;if(m[h]){const f=I[h],l=u[h];c=Number(f[l+s]),d=Number(f[l+v])}else c=Number(t[h].iget(s)),d=Number(t[h].iget(v));if(isNaN(c)&&isNaN(d))continue;if(isNaN(c))return 1;if(isNaN(d)||c<d)return-1;if(c>d)return 1}return 0});const o=M.zeros([e],"int32"),i=o.data;for(let s=0;s<e;s++)i[s]=x[s];return o}function at(t,p){let e=0,n=t.length-1;for(;e<n;){const x=Math.floor((e+n)/2),b=t[e],m=t[x],I=t[n];let u;b<=m&&m<=I||I<=m&&m<=b?u=x:m<=b&&b<=I||I<=b&&b<=m?u=e:u=n;const o=t[u];[t[u],t[n]]=[t[n],t[u]];let i=e;for(let s=e;s<n;s++){const v=t[s],h=isNaN(v),c=isNaN(o);!h&&(c||v<=o)&&([t[i],t[s]]=[t[s],t[i]],i++)}if([t[i],t[n]]=[t[n],t[i]],i===p)return;i<p?e=i+1:n=i-1}}function lt(t,p){let e=0,n=t.length-1;for(;e<n;){const x=Math.floor((e+n)/2),b=t[e],m=t[x],I=t[n];let u;b<=m&&m<=I||I<=m&&m<=b?u=x:m<=b&&b<=I||I<=b&&b<=m?u=e:u=n;const o=t[u];[t[u],t[n]]=[t[n],t[u]];let i=e;for(let s=e;s<n;s++)t[s]<=o&&([t[i],t[s]]=[t[s],t[i]],i++);if([t[i],t[n]]=[t[n],t[i]],i===p)return;i<p?e=i+1:n=i-1}}function ut(t,p){let e=0,n=t.length-1;for(;e<n;){const x=Math.floor((e+n)/2),b=t[e].value,m=t[x].value,I=t[n].value;let u;b<=m&&m<=I||I<=m&&m<=b?u=x:m<=b&&b<=I||I<=b&&b<=m?u=e:u=n;const o=t[u].value;[t[u],t[n]]=[t[n],t[u]];let i=e;for(let s=e;s<n;s++){const v=t[s].value,h=isNaN(v),c=isNaN(o);!h&&(c||v<=o)&&([t[i],t[s]]=[t[s],t[i]],i++)}if([t[i],t[n]]=[t[n],t[i]],i===p)return;i<p?e=i+1:n=i-1}}function ft(t,p){let e=0,n=t.length-1;for(;e<n;){const x=Math.floor((e+n)/2),b=t[e].value,m=t[x].value,I=t[n].value;let u;b<=m&&m<=I||I<=m&&m<=b?u=x:m<=b&&b<=I||I<=b&&b<=m?u=e:u=n;const o=t[u].value;[t[u],t[n]]=[t[n],t[u]];let i=e;for(let s=e;s<n;s++)t[s].value<=o&&([t[i],t[s]]=[t[s],t[i]],i++);if([t[i],t[n]]=[t[n],t[i]],i===p)return;i<p?e=i+1:n=i-1}}function Bt(t,p,e=-1){const n=t.shape,x=n.length,b=t.dtype;if(x===0)return t.copy();let m=e;if(m<0&&(m=x+m),m<0||m>=x)throw new Error(`axis ${e} is out of bounds for array of dimension ${x}`);const I=n[m];let u=p;if(u<0&&(u=I+u),u<0||u>=I)throw new Error(`kth(=${p}) out of bounds (${I})`);if(x===1&&t.isCContiguous&&!$(b)){const f=t.copy(),l=k(f,u);if(l)return l}const o=t.copy(),i=o.data,s=Array.from(n).filter((f,l)=>l!==m),v=s.length===0?1:s.reduce((f,l)=>f*l,1),h=V(n),{baseOffsets:c,axisStride:d}=_(n,h,0,m,v);if(d===1&&!$(b)&&tt(i,c,I,v,u,b))return o;if(L(b)){const f=i;for(let l=0;l<v;l++){const a=[];let r=c[l];for(let y=0;y<I;y++)a.push(f[r]),r+=d;lt(a,u),r=c[l];for(let y=0;y<I;y++)f[r]=a[y],r+=d}}else for(let f=0;f<v;f++){const l=[];let a=c[f];for(let r=0;r<I;r++)l.push(Number(i[a])),a+=d;at(l,u),a=c[f];for(let r=0;r<I;r++)i[a]=l[r],a+=d}return o}function Tt(t,p,e=-1){const n=t.shape,x=n.length,b=t.dtype,m=t.data,I=t.offset,u=t.strides;if(x===0)return M.zeros([0],"int32");let o=e;if(o<0&&(o=x+o),o<0||o>=x)throw new Error(`axis ${e} is out of bounds for array of dimension ${x}`);const i=n[o];let s=p;if(s<0&&(s=i+s),s<0||s>=i)throw new Error(`kth(=${p}) out of bounds (${i})`);if(x===1&&t.isCContiguous&&!$(b)){const A=et(t,s);if(A)return A}const v=M.zeros(Array.from(n),"int32"),h=v.data,c=Array.from(n).filter((A,N)=>N!==o),d=c.length===0?1:c.reduce((A,N)=>A*N,1),{baseOffsets:f,axisStride:l}=_(n,u,I,o,d),a=V(n),{baseOffsets:r,axisStride:y}=_(n,a,0,o,d);if(y===1&&l===1&&!$(b)&&rt(m,h,f,r,i,d,s,b))return v;if(L(b)){const A=m;for(let N=0;N<d;N++){const S=[];let z=f[N];for(let T=0;T<i;T++)S.push({value:A[z],idx:T}),z+=l;ft(S,s);let w=r[N];for(let T=0;T<i;T++)h[w]=S[T].idx,w+=y}}else for(let A=0;A<d;A++){const N=[];let S=f[A];for(let w=0;w<i;w++)N.push({value:Number(m[S]),idx:w}),S+=l;ut(N,s);let z=r[A];for(let w=0;w<i;w++)h[z]=N[w].idx,z+=y}return v}function Ot(t){const p=t.dtype,e=t.size,n=t.isCContiguous,x=t.data,b=t.offset;if($(p)){const m=[];if(n){const o=x;for(let i=0;i<e;i++)m.push({re:o[(b+i)*2],im:o[(b+i)*2+1]})}else for(let o=0;o<e;o++){const i=t.iget(o);m.push({re:i.re,im:i.im})}m.sort((o,i)=>j(o.re,o.im,i.re,i.im));const I=M.zeros([e],"complex128"),u=I.data;for(let o=0;o<e;o++)u[o*2]=m[o].re,u[o*2+1]=m[o].im;return I}else{const m=[];if(n)for(let o=0;o<e;o++)m.push(Number(x[b+o]));else for(let o=0;o<e;o++)m.push(Number(t.iget(o)));m.sort((o,i)=>isNaN(o)&&isNaN(i)?0:isNaN(o)?1:isNaN(i)?-1:o-i);const I=M.zeros([e],"complex128"),u=I.data;for(let o=0;o<e;o++)u[o*2]=m[o],u[o*2+1]=0;return I}}function ct(t){const p=t.shape,e=p.length,n=t.size,x=$(t.dtype),b=t.isCContiguous,m=t.data,I=t.offset,u=[];for(let h=0;h<e;h++)u.push([]);const o=[];let i=1;for(let h=e-1;h>=0;h--)o.unshift(i),i*=p[h];if(b&&!x&&e>=1){const h=[];for(let f=0;f<e;f++)h.push(new Int32Array(n));let c=0;for(let f=0;f<n;f++)if(m[I+f]){let l=f;for(let a=0;a<e;a++)h[a][c]=l/o[a]|0,l-=h[a][c]*o[a];c++}const d=[];for(let f=0;f<e;f++){const l=M.zeros([c],"int32");l.data.set(h[f].subarray(0,c)),d.push(l)}return d}if(b){for(let h=0;h<n;h++)if(E(m,I+h,x)){let c=h;for(let d=0;d<e;d++){const f=Math.floor(c/o[d]);c=c%o[d],u[d].push(f)}}}else for(let h=0;h<n;h++){const c=t.iget(h);if(x?c.re!==0||c.im!==0:!!c){let f=h;for(let l=0;l<e;l++){const a=Math.floor(f/o[l]);f=f%o[l],u[l].push(a)}}}const s=u[0]?.length??0,v=[];for(let h=0;h<e;h++){const c=M.zeros([s],"int32"),d=c.data;for(let f=0;f<s;f++)d[f]=u[h][f];v.push(c)}return v}function Mt(t){const p=t.shape,e=p.length,n=t.size,x=$(t.dtype),b=t.isCContiguous,m=t.data,I=t.offset,u=[],o=[];let i=1;for(let d=e-1;d>=0;d--)o.unshift(i),i*=p[d];if(b){for(let d=0;d<n;d++)if(E(m,I+d,x)){const f=[];let l=d;for(let a=0;a<e;a++){const r=Math.floor(l/o[a]);l=l%o[a],f.push(r)}u.push(f)}}else for(let d=0;d<n;d++){const f=t.iget(d);if(x?f.re!==0||f.im!==0:!!f){const a=[];let r=d;for(let y=0;y<e;y++){const A=Math.floor(r/o[y]);r=r%o[y],a.push(A)}u.push(a)}}const s=u.length,v=e===0?[s,1]:[s,e],h=M.zeros(v,"int32"),c=h.data;for(let d=0;d<s;d++){const f=u[d];for(let l=0;l<(e===0?1:e);l++)c[d*(e===0?1:e)+l]=f[l]??0}return h}function $t(t){const p=t.size,e=$(t.dtype),n=t.isCContiguous,x=t.data,b=t.offset;if(n&&!e){const o=new Int32Array(p);let i=0;for(let v=0;v<p;v++)x[b+v]&&(o[i++]=v);const s=M.zeros([i],"int32");return s.data.set(o.subarray(0,i)),s}const m=[];if(n)for(let o=0;o<p;o++)E(x,b+o,e)&&m.push(o);else for(let o=0;o<p;o++){const i=t.iget(o);(e?i.re!==0||i.im!==0:i)&&m.push(o)}const I=M.zeros([m.length],"int32"),u=I.data;for(let o=0;o<m.length;o++)u[o]=m[o];return I}function Et(t,p,e){if(p===void 0&&e===void 0)return ct(t);if(p===void 0||e===void 0)throw new Error("either both or neither of x and y should be given");if(t.size===p.size&&p.size===e.size&&p.dtype===e.dtype&&t.shape.length===p.shape.length&&t.shape.every((g,F)=>g===p.shape[F])&&p.shape.every((g,F)=>g===e.shape[F])){const g=it(t,p,e);if(g)return g}const n=t.shape,x=p.shape,b=e.shape,m=Math.max(n.length,x.length,b.length),I=g=>{const F=Array(m).fill(1);for(let D=0;D<g.length;D++)F[m-g.length+D]=g[D];return F},u=I(n),o=I(x),i=I(b),s=[];for(let g=0;g<m;g++){const F=[u[g],o[g],i[g]],D=Math.max(...F);for(const C of F)if(C!==1&&C!==D)throw new Error("operands could not be broadcast together");s.push(D)}const v=p.dtype,h=M.zeros(s,v),c=h.data,d=(g,F)=>{const D=[];let C=1;for(let O=g.length-1;O>=0;O--)D.unshift(C),C*=g[O];for(;D.length<F.length;)D.unshift(0);for(let O=0;O<F.length;O++)F[O]===1&&s[O]!==1&&(D[O]=0);return D},f=d(n,u),l=d(x,o),a=d(b,i),r=[];let y=1;for(let g=s.length-1;g>=0;g--)r.unshift(y),y*=s[g];const A=s.reduce((g,F)=>g*F,1),N=$(t.dtype),S=$(v),z=t.isCContiguous,w=t.data,T=t.offset,P=p.isCContiguous,q=p.data,R=p.offset,W=e.isCContiguous,K=e.data,U=e.offset;if(n.length===s.length&&x.length===s.length&&b.length===s.length&&n.every((g,F)=>g===s[F])&&x.every((g,F)=>g===s[F])&&b.every((g,F)=>g===s[F])&&z&&P&&W)if(S){const g=c,F=q,D=K;if(N)for(let C=0;C<A;C++)E(w,T+C,!0)?(g[C*2]=F[(R+C)*2],g[C*2+1]=F[(R+C)*2+1]):(g[C*2]=D[(U+C)*2],g[C*2+1]=D[(U+C)*2+1]);else for(let C=0;C<A;C++)w[T+C]?(g[C*2]=F[(R+C)*2],g[C*2+1]=F[(R+C)*2+1]):(g[C*2]=D[(U+C)*2],g[C*2+1]=D[(U+C)*2+1])}else if(L(v)){const g=c,F=q,D=K;for(let C=0;C<A;C++)w[T+C]?g[C]=F[R+C]:g[C]=D[U+C]}else for(let g=0;g<A;g++)w[T+g]?c[g]=q[R+g]:c[g]=K[U+g];else for(let g=0;g<A;g++){let F=g,D=0,C=0,O=0;for(let B=0;B<m;B++){const Y=Math.floor(F/r[B]);F=F%r[B],D+=Y*f[B],C+=Y*l[B],O+=Y*a[B]}let X;if(z)X=E(w,T+D,N);else{const B=t.iget(D);X=N?B.re!==0||B.im!==0:!!B}if(X)if(S)if(P){const B=q;c[g*2]=B[(R+C)*2],c[g*2+1]=B[(R+C)*2+1]}else{const B=p.iget(C);c[g*2]=B.re,c[g*2+1]=B.im}else P?c[g]=q[R+C]:c[g]=p.iget(C);else if(S)if(W){const B=K;c[g*2]=B[(U+O)*2],c[g*2+1]=B[(U+O)*2+1]}else{const B=e.iget(O);c[g*2]=B.re,c[g*2+1]=B.im}else W?c[g]=K[U+O]:c[g]=e.iget(O)}return h}function Rt(t,p,e="left"){if(t.ndim!==1)throw new Error("storage must be 1D");const n=t.size,x=p.size,b=$(t.dtype),m=t.isCContiguous,I=t.data,u=t.offset,o=p.isCContiguous,i=p.data,s=p.offset;if(!b){const c=ot(t,p,e);if(c)return c}const v=M.zeros([x],"int32"),h=v.data;if(b)if(m&&o){const c=I,d=i;for(let f=0;f<x;f++){const l=d[(s+f)*2],a=d[(s+f)*2+1];let r=0,y=n;if(e==="left")for(;r<y;){const A=Math.floor((r+y)/2),N=c[(u+A)*2],S=c[(u+A)*2+1];j(N,S,l,a)<0?r=A+1:y=A}else for(;r<y;){const A=Math.floor((r+y)/2),N=c[(u+A)*2],S=c[(u+A)*2+1];j(N,S,l,a)<=0?r=A+1:y=A}h[f]=r}}else for(let c=0;c<x;c++){const d=p.iget(c),f=d.re,l=d.im;let a=0,r=n;if(e==="left")for(;a<r;){const y=Math.floor((a+r)/2),A=t.iget(y);j(A.re,A.im,f,l)<0?a=y+1:r=y}else for(;a<r;){const y=Math.floor((a+r)/2),A=t.iget(y);j(A.re,A.im,f,l)<=0?a=y+1:r=y}h[c]=a}else if(m&&o)for(let c=0;c<x;c++){const d=Number(i[s+c]);let f=0,l=n;if(e==="left")for(;f<l;){const a=Math.floor((f+l)/2);Number(I[u+a])<d?f=a+1:l=a}else for(;f<l;){const a=Math.floor((f+l)/2);Number(I[u+a])<=d?f=a+1:l=a}h[c]=f}else for(let c=0;c<x;c++){const d=Number(p.iget(c));let f=0,l=n;if(e==="left")for(;f<l;){const a=Math.floor((f+l)/2);Number(t.iget(a))<d?f=a+1:l=a}else for(;f<l;){const a=Math.floor((f+l)/2);Number(t.iget(a))<=d?f=a+1:l=a}h[c]=f}return v}function Ut(t,p){const e=nt(t,p);if(e)return e;const n=p.dtype,x=$(t.dtype),b=$(n),m=Math.min(t.size,p.size),I=t.isCContiguous,u=t.data,o=t.offset,i=p.isCContiguous,s=p.data,v=p.offset;let h=0;if(I)for(let l=0;l<m;l++)E(u,o+l,x)&&h++;else for(let l=0;l<m;l++){const a=t.iget(l);(x?a.re!==0||a.im!==0:a)&&h++}const c=M.zeros([h],n),d=c.data;let f=0;if(I&&i)if(L(n)){const l=d,a=s;for(let r=0;r<m;r++)E(u,o+r,x)&&(l[f++]=a[v+r])}else if(b){const l=d,a=s;for(let r=0;r<m;r++)E(u,o+r,x)&&(l[f*2]=a[(v+r)*2],l[f*2+1]=a[(v+r)*2+1],f++)}else for(let l=0;l<m;l++)E(u,o+l,x)&&(d[f++]=s[v+l]);else{const l=I?a=>E(u,o+a,x):a=>{const r=t.iget(a);if(x){const y=r;return y.re!==0||y.im!==0}return!!r};if(L(n)){const a=d;for(let r=0;r<m;r++)l(r)&&(a[f++]=p.iget(r))}else if(b){const a=d;for(let r=0;r<m;r++)if(l(r)){const y=p.iget(r);a[f*2]=y.re,a[f*2+1]=y.im,f++}}else for(let a=0;a<m;a++)l(a)&&(d[f++]=p.iget(a))}return c}function mt(t,p){const e=t.shape,n=e.length,x=t.data,b=t.size,m=t.offset,I=t.strides,u=$(t.dtype),o=t.isCContiguous;if(p===void 0){const a=Z(t);if(a!==null)return a;let r=0;if(o)for(let y=0;y<b;y++)E(x,m+y,u)&&r++;else for(let y=0;y<b;y++){const A=t.iget(y);if(u){const N=A;(N.re!==0||N.im!==0)&&r++}else A!==0&&A!==BigInt(0)&&r++}return r}let i=p;if(i<0&&(i=n+i),i<0||i>=n)throw new Error(`axis ${p} is out of bounds for array of dimension ${n}`);const s=Array.from(e).filter((a,r)=>r!==i);if(s.length===0)return mt(t);const v=M.zeros(s,"int32"),h=v.data,c=e[i],d=s.reduce((a,r)=>a*r,1),{baseOffsets:f,axisStride:l}=_(e,I,m,i,d);for(let a=0;a<d;a++){let r=0,y=f[a];for(let A=0;A<c;A++)E(x,y,u)&&r++,y+=l;h[a]=r}return v}export{Tt as argpartition,Ft as argsort,Mt as argwhere,mt as count_nonzero,Ut as extract,$t as flatnonzero,Dt as lexsort,ct as nonzero,Bt as partition,Rt as searchsorted,Ct as sort,Ot as sort_complex,Et as where};
|
|
1
|
+
import{ArrayStorage as R}from"../storage.js";import{isBigIntDType as q,isComplexDType as M,hasFloat16 as Z}from"../dtype.js";import{computeStrides as P,precomputeAxisOffsets as L}from"../internal/indexing.js";import{wasmReduceCountNz as G}from"../wasm/reduce_count_nz.js";import{wasmSort as H,wasmSortSlices as J}from"../wasm/sort.js";import{wasmArgsort as Q,wasmArgsortSlices as k}from"../wasm/argsort.js";import{wasmPartition as tt,wasmPartitionSlices as et}from"../wasm/partition.js";import{wasmArgpartition as ot,wasmArgpartitionSlices as rt}from"../wasm/argpartition.js";import{wasmSearchsorted as st}from"../wasm/searchsorted.js";import{wasmLexsort as nt}from"../wasm/lexsort.js";import{wasmExtract as it,wasmWhere as at}from"../wasm/gather.js";function $(t,u,s){if(s){const r=t[u*2],d=t[u*2+1];return r!==0||d!==0}return!!t[u]}function E(t,u,s,r){const d=isNaN(t)||isNaN(u),h=isNaN(s)||isNaN(r);return d&&h?0:d?1:h||t<s?-1:t>s?1:u<r?-1:u>r?1:0}function Dt(t,u=-1){const s=t.shape,r=s.length,d=t.dtype,h=t.data,b=t.offset,g=t.strides;if(r===0)return t.copy();let m=u;if(m<0&&(m=r+m),m<0||m>=r)throw new Error(`axis ${u} is out of bounds for array of dimension ${r}`);const a=t.copy(),i=a.data,e=s[m],N=Array.from(s).filter((o,p)=>p!==m),x=N.length===0?1:N.reduce((o,p)=>o*p,1),{baseOffsets:c,axisStride:y}=L(s,g,b,m,x),l=P(s),{baseOffsets:f,axisStride:n}=L(s,l,0,m,x);if(r===1&&a.isCContiguous){const o=H(a);if(o)return o}if(n===1&&J(i,f,e,x,d))return a;if(M(d)){const o=h,p=i;for(let A=0;A<x;A++){const F=[];let I=c[A];for(let z=0;z<e;z++)F.push({re:o[I*2],im:o[I*2+1],idx:z}),I+=y;F.sort((z,B)=>E(z.re,z.im,B.re,B.im));let S=f[A];for(let z=0;z<e;z++)p[S*2]=F[z].re,p[S*2+1]=F[z].im,S+=n}}else if(q(d)){const o=h,p=i;for(let A=0;A<x;A++){const F=[];let I=c[A];for(let z=0;z<e;z++)F.push({value:o[I],idx:z}),I+=y;F.sort((z,B)=>z.value<B.value?-1:z.value>B.value?1:0);let S=f[A];for(let z=0;z<e;z++)p[S]=F[z].value,S+=n}}else if(d==="float16"&&Z&&t.isCContiguous&&a.isCContiguous)for(let o=0;o<x;o++){const p=c[o],A=y===1?new Float32Array(h.subarray(p,p+e)):Float32Array.from({length:e},(I,S)=>Number(h[p+S*y]));A.sort((I,S)=>isNaN(I)&&isNaN(S)?0:isNaN(I)?1:isNaN(S)?-1:I-S);const F=f[o];if(n===1)i.subarray(F,F+e).set(A);else for(let I=0;I<e;I++)i[F+I*n]=A[I]}else for(let o=0;o<x;o++){const p=[];let A=c[o];for(let I=0;I<e;I++)p.push(Number(h[A])),A+=y;p.sort((I,S)=>isNaN(I)&&isNaN(S)?0:isNaN(I)?1:isNaN(S)?-1:I-S);let F=f[o];for(let I=0;I<e;I++)i[F]=p[I],F+=n}return a}function Bt(t,u=-1){const s=t.shape,r=s.length,d=t.dtype,h=t.data,b=t.offset,g=t.strides;if(r===0)return R.zeros([0],"float64");let m=u;if(m<0&&(m=r+m),m<0||m>=r)throw new Error(`axis ${u} is out of bounds for array of dimension ${r}`);const a=R.zeros(Array.from(s),"float64"),i=a.data,e=s[m],N=Array.from(s).filter((o,p)=>p!==m),x=N.length===0?1:N.reduce((o,p)=>o*p,1),{baseOffsets:c,axisStride:y}=L(s,g,b,m,x),l=P(s),{baseOffsets:f,axisStride:n}=L(s,l,0,m,x);if(r===1&&t.isCContiguous){const o=Q(t);if(o)return o}if(n===1&&y===1&&k(h,i,c,f,e,x,d))return a;if(M(d)){const o=h;for(let p=0;p<x;p++){const A=[];let F=c[p];for(let S=0;S<e;S++)A.push({re:o[F*2],im:o[F*2+1],idx:S}),F+=y;A.sort((S,z)=>E(S.re,S.im,z.re,z.im));let I=f[p];for(let S=0;S<e;S++)i[I]=A[S].idx,I+=n}}else if(q(d)){const o=h;for(let p=0;p<x;p++){const A=[];let F=c[p];for(let S=0;S<e;S++)A.push({value:o[F],idx:S}),F+=y;A.sort((S,z)=>S.value<z.value?-1:S.value>z.value?1:0);let I=f[p];for(let S=0;S<e;S++)i[I]=A[S].idx,I+=n}}else if(d==="float16"&&Z&&t.isCContiguous)for(let o=0;o<x;o++){const p=c[o],A=y===1?new Float32Array(h.subarray(p,p+e)):Float32Array.from({length:e},(S,z)=>Number(h[p+z*y])),F=Array.from({length:e},(S,z)=>z);F.sort((S,z)=>{const B=A[S],j=A[z];return isNaN(B)&&isNaN(j)?0:isNaN(B)?1:isNaN(j)?-1:B-j});let I=f[o];for(let S=0;S<e;S++)i[I]=F[S],I+=n}else for(let o=0;o<x;o++){const p=[];let A=c[o];for(let I=0;I<e;I++)p.push({value:Number(h[A]),idx:I}),A+=y;p.sort((I,S)=>isNaN(I.value)&&isNaN(S.value)?0:isNaN(I.value)?1:isNaN(S.value)?-1:I.value-S.value);let F=f[o];for(let I=0;I<e;I++)i[F]=p[I].idx,F+=n}return a}function Tt(t){if(t.length===0)return R.zeros([0],"float64");const s=t[0].size;for(const e of t){if(e.ndim!==1)throw new Error("keys must be 1D arrays");if(e.size!==s)throw new Error("all keys must have the same length")}const r=nt(t);if(r)return r;const d=[];for(let e=0;e<s;e++)d.push(e);const h=t.map(e=>M(e.dtype)),b=t.map(e=>e.isCContiguous),g=t.map(e=>e.data),m=t.map(e=>e.offset);d.sort((e,N)=>{for(let x=t.length-1;x>=0;x--)if(h[x]){let c,y,l,f;if(b[x]){const n=g[x],o=m[x];c=n[(o+e)*2],y=n[(o+e)*2+1],l=n[(o+N)*2],f=n[(o+N)*2+1]}else{const n=t[x].iget(e),o=t[x].iget(N);c=n.re,y=n.im,l=o.re,f=o.im}if(c<l)return-1;if(c>l)return 1;if(y<f)return-1;if(y>f)return 1}else{let c,y;if(b[x]){const l=g[x],f=m[x];c=Number(l[f+e]),y=Number(l[f+N])}else c=Number(t[x].iget(e)),y=Number(t[x].iget(N));if(isNaN(c)&&isNaN(y))continue;if(isNaN(c))return 1;if(isNaN(y)||c<y)return-1;if(c>y)return 1}return 0});const a=R.zeros([s],"float64"),i=a.data;for(let e=0;e<s;e++)i[e]=d[e];return a}function lt(t,u){let s=0,r=t.length-1;for(;s<r;){const d=Math.floor((s+r)/2),h=t[s],b=t[d],g=t[r];let m;h<=b&&b<=g||g<=b&&b<=h?m=d:b<=h&&h<=g||g<=h&&h<=b?m=s:m=r;const a=t[m];[t[m],t[r]]=[t[r],t[m]];let i=s;for(let e=s;e<r;e++){const N=t[e],x=isNaN(N),c=isNaN(a);!x&&(c||N<=a)&&([t[i],t[e]]=[t[e],t[i]],i++)}if([t[i],t[r]]=[t[r],t[i]],i===u)return;i<u?s=i+1:r=i-1}}function ut(t,u,s){let r=0,d=t.length-1;for(;r<d;){const h=Math.floor((r+d)/2),b=E(t[r],u[r],t[h],u[h]),g=E(t[r],u[r],t[d],u[d]),m=E(t[h],u[h],t[d],u[d]);let a;b<=0&&m<=0||m>=0&&b>=0?a=h:b>=0&&g<=0||g>=0&&b<=0?a=r:a=d;const i=t[a],e=u[a];[t[a],t[d]]=[t[d],t[a]],[u[a],u[d]]=[u[d],u[a]];let N=r;for(let x=r;x<d;x++)E(t[x],u[x],i,e)<=0&&([t[N],t[x]]=[t[x],t[N]],[u[N],u[x]]=[u[x],u[N]],N++);if([t[N],t[d]]=[t[d],t[N]],[u[N],u[d]]=[u[d],u[N]],N===s)return;N<s?r=N+1:d=N-1}}function ft(t,u){let s=0,r=t.length-1;for(;s<r;){const d=Math.floor((s+r)/2),h=t[s],b=t[d],g=t[r];let m;h<=b&&b<=g||g<=b&&b<=h?m=d:b<=h&&h<=g||g<=h&&h<=b?m=s:m=r;const a=t[m];[t[m],t[r]]=[t[r],t[m]];let i=s;for(let e=s;e<r;e++)t[e]<=a&&([t[i],t[e]]=[t[e],t[i]],i++);if([t[i],t[r]]=[t[r],t[i]],i===u)return;i<u?s=i+1:r=i-1}}function ct(t,u){let s=0,r=t.length-1;for(;s<r;){const d=Math.floor((s+r)/2),h=t[s].value,b=t[d].value,g=t[r].value;let m;h<=b&&b<=g||g<=b&&b<=h?m=d:b<=h&&h<=g||g<=h&&h<=b?m=s:m=r;const a=t[m].value;[t[m],t[r]]=[t[r],t[m]];let i=s;for(let e=s;e<r;e++){const N=t[e].value,x=isNaN(N),c=isNaN(a);!x&&(c||N<=a)&&([t[i],t[e]]=[t[e],t[i]],i++)}if([t[i],t[r]]=[t[r],t[i]],i===u)return;i<u?s=i+1:r=i-1}}function mt(t,u){let s=0,r=t.length-1;for(;s<r;){const d=Math.floor((s+r)/2),h=t[s].value,b=t[d].value,g=t[r].value;let m;h<=b&&b<=g||g<=b&&b<=h?m=d:b<=h&&h<=g||g<=h&&h<=b?m=s:m=r;const a=t[m].value;[t[m],t[r]]=[t[r],t[m]];let i=s;for(let e=s;e<r;e++)t[e].value<=a&&([t[i],t[e]]=[t[e],t[i]],i++);if([t[i],t[r]]=[t[r],t[i]],i===u)return;i<u?s=i+1:r=i-1}}function Mt(t,u,s=-1){const r=t.shape,d=r.length,h=t.dtype;if(d===0)return t.copy();let b=s;if(b<0&&(b=d+b),b<0||b>=d)throw new Error(`axis ${s} is out of bounds for array of dimension ${d}`);const g=r[b];let m=u;if(m<0&&(m=g+m),m<0||m>=g)throw new Error(`kth(=${u}) out of bounds (${g})`);if(d===1&&t.isCContiguous&&!M(h)){const l=t.copy(),f=tt(l,m);if(f)return f}const a=t.copy(),i=a.data,e=Array.from(r).filter((l,f)=>f!==b),N=e.length===0?1:e.reduce((l,f)=>l*f,1),x=P(r),{baseOffsets:c,axisStride:y}=L(r,x,0,b,N);if(y===1&&!M(h)&&et(i,c,g,N,m,h))return a;if(q(h)){const l=i;for(let f=0;f<N;f++){const n=[];let o=c[f];for(let p=0;p<g;p++)n.push(l[o]),o+=y;ft(n,m),o=c[f];for(let p=0;p<g;p++)l[o]=n[p],o+=y}}else if(M(h)){const l=i;for(let f=0;f<N;f++){const n=new Array(g),o=new Array(g);let p=c[f];for(let A=0;A<g;A++)n[A]=l[p*2],o[A]=l[p*2+1],p+=y;ut(n,o,m),p=c[f];for(let A=0;A<g;A++)l[p*2]=n[A],l[p*2+1]=o[A],p+=y}}else for(let l=0;l<N;l++){const f=[];let n=c[l];for(let o=0;o<g;o++)f.push(Number(i[n])),n+=y;lt(f,m),n=c[l];for(let o=0;o<g;o++)i[n]=f[o],n+=y}return a}function Ot(t,u,s=-1){const r=t.shape,d=r.length,h=t.dtype,b=t.data,g=t.offset,m=t.strides;if(d===0)return R.zeros([0],"float64");let a=s;if(a<0&&(a=d+a),a<0||a>=d)throw new Error(`axis ${s} is out of bounds for array of dimension ${d}`);const i=r[a];let e=u;if(e<0&&(e=i+e),e<0||e>=i)throw new Error(`kth(=${u}) out of bounds (${i})`);if(d===1&&t.isCContiguous&&!M(h)){const A=ot(t,e);if(A)return A}const N=R.zeros(Array.from(r),"float64"),x=N.data,c=Array.from(r).filter((A,F)=>F!==a),y=c.length===0?1:c.reduce((A,F)=>A*F,1),{baseOffsets:l,axisStride:f}=L(r,m,g,a,y),n=P(r),{baseOffsets:o,axisStride:p}=L(r,n,0,a,y);if(p===1&&f===1&&!M(h)&&rt(b,x,l,o,i,y,e,h))return N;if(q(h)){const A=b;for(let F=0;F<y;F++){const I=[];let S=l[F];for(let B=0;B<i;B++)I.push({value:A[S],idx:B}),S+=f;mt(I,e);let z=o[F];for(let B=0;B<i;B++)x[z]=I[B].idx,z+=p}}else for(let A=0;A<y;A++){const F=[];let I=l[A];for(let z=0;z<i;z++)F.push({value:Number(b[I]),idx:z}),I+=f;ct(F,e);let S=o[A];for(let z=0;z<i;z++)x[S]=F[z].idx,S+=p}return N}function Rt(t){const u=t.dtype,s=t.size,r=t.isCContiguous,d=t.data,h=t.offset;if(M(u)){const b=[];if(r){const a=d;for(let i=0;i<s;i++)b.push({re:a[(h+i)*2],im:a[(h+i)*2+1]})}else for(let a=0;a<s;a++){const i=t.iget(a);b.push({re:i.re,im:i.im})}b.sort((a,i)=>E(a.re,a.im,i.re,i.im));const g=R.zeros([s],u),m=g.data;for(let a=0;a<s;a++)m[a*2]=b[a].re,m[a*2+1]=b[a].im;return g}else{const b=[];if(r)for(let e=0;e<s;e++)b.push(Number(d[h+e]));else for(let e=0;e<s;e++)b.push(Number(t.iget(e)));b.sort((e,N)=>isNaN(e)&&isNaN(N)?0:isNaN(e)?1:isNaN(N)?-1:e-N);const m=new Set(["int8","uint8","int16","uint16"]).has(u)?"complex64":"complex128",a=R.zeros([s],m),i=a.data;for(let e=0;e<s;e++)i[e*2]=b[e],i[e*2+1]=0;return a}}function dt(t){const u=t.shape,s=u.length,r=t.size,d=M(t.dtype),h=t.isCContiguous,b=t.data,g=t.offset,m=[];for(let x=0;x<s;x++)m.push([]);const a=[];let i=1;for(let x=s-1;x>=0;x--)a.unshift(i),i*=u[x];if(h&&!d&&s>=1){const x=[];for(let l=0;l<s;l++)x.push(new Float64Array(r));let c=0;for(let l=0;l<r;l++)if(b[g+l]){let f=l;for(let n=0;n<s;n++)x[n][c]=f/a[n]|0,f-=x[n][c]*a[n];c++}const y=[];for(let l=0;l<s;l++){const f=R.zeros([c],"float64");f.data.set(x[l].subarray(0,c)),y.push(f)}return y}if(h){for(let x=0;x<r;x++)if($(b,g+x,d)){let c=x;for(let y=0;y<s;y++){const l=Math.floor(c/a[y]);c=c%a[y],m[y].push(l)}}}else for(let x=0;x<r;x++){const c=t.iget(x);if(d?c.re!==0||c.im!==0:!!c){let l=x;for(let f=0;f<s;f++){const n=Math.floor(l/a[f]);l=l%a[f],m[f].push(n)}}}const e=m[0]?.length??0,N=[];for(let x=0;x<s;x++){const c=R.zeros([e],"float64"),y=c.data;for(let l=0;l<e;l++)y[l]=m[x][l];N.push(c)}return N}function $t(t){const u=t.shape,s=u.length,r=t.size,d=M(t.dtype),h=t.isCContiguous,b=t.data,g=t.offset,m=s===0?1:s,a=[];let i=1;for(let y=s-1;y>=0;y--)a.unshift(i),i*=u[y];let e=0;if(h)for(let y=0;y<r;y++)$(b,g+y,d)&&e++;else for(let y=0;y<r;y++){const l=t.iget(y);(d?l.re!==0||l.im!==0:l)&&e++}const N=R.zeros([e,m],"float64"),x=N.data;let c=0;if(h){for(let y=0;y<r;y++)if($(b,g+y,d)){let l=y;const f=c*m;for(let n=0;n<s;n++){const o=a[n];x[f+n]=l/o|0,l=l%o}c++}}else for(let y=0;y<r;y++){const l=t.iget(y);if(d?l.re!==0||l.im!==0:!!l){let n=y;const o=c*m;for(let p=0;p<s;p++){const A=a[p];x[o+p]=n/A|0,n=n%A}c++}}return N}function Et(t){const u=t.size,s=M(t.dtype),r=t.isCContiguous,d=t.data,h=t.offset;if(r&&!s){const a=new Float64Array(u);let i=0;for(let N=0;N<u;N++)d[h+N]&&(a[i++]=N);const e=R.zeros([i],"float64");return e.data.set(a.subarray(0,i)),e}const b=[];if(r)for(let a=0;a<u;a++)$(d,h+a,s)&&b.push(a);else for(let a=0;a<u;a++){const i=t.iget(a);(s?i.re!==0||i.im!==0:i)&&b.push(a)}const g=R.zeros([b.length],"float64"),m=g.data;for(let a=0;a<b.length;a++)m[a]=b[a];return g}function Ut(t,u,s){if(u===void 0&&s===void 0)return dt(t);if(u===void 0||s===void 0)throw new Error("either both or neither of x and y should be given");if(t.size===u.size&&u.size===s.size&&u.dtype===s.dtype&&t.shape.length===u.shape.length&&t.shape.every((v,C)=>v===u.shape[C])&&u.shape.every((v,C)=>v===s.shape[C])){const v=at(t,u,s);if(v)return v}const r=t.shape,d=u.shape,h=s.shape,b=Math.max(r.length,d.length,h.length),g=v=>{const C=Array(b).fill(1);for(let D=0;D<v.length;D++)C[b-v.length+D]=v[D];return C},m=g(r),a=g(d),i=g(h),e=[];for(let v=0;v<b;v++){const C=[m[v],a[v],i[v]],D=Math.max(...C);for(const w of C)if(w!==1&&w!==D)throw new Error("operands could not be broadcast together");e.push(D)}const N=u.dtype,x=R.zeros(e,N),c=x.data,y=(v,C)=>{const D=[];let w=1;for(let O=v.length-1;O>=0;O--)D.unshift(w),w*=v[O];for(;D.length<C.length;)D.unshift(0);for(let O=0;O<C.length;O++)C[O]===1&&e[O]!==1&&(D[O]=0);return D},l=y(r,m),f=y(d,a),n=y(h,i),o=[];let p=1;for(let v=e.length-1;v>=0;v--)o.unshift(p),p*=e[v];const A=e.reduce((v,C)=>v*C,1),F=M(t.dtype),I=M(N),S=t.isCContiguous,z=t.data,B=t.offset,j=u.isCContiguous,K=u.data,U=u.offset,W=s.isCContiguous,V=s.data,_=s.offset;if(r.length===e.length&&d.length===e.length&&h.length===e.length&&r.every((v,C)=>v===e[C])&&d.every((v,C)=>v===e[C])&&h.every((v,C)=>v===e[C])&&S&&j&&W)if(I){const v=c,C=K,D=V;if(F)for(let w=0;w<A;w++)$(z,B+w,!0)?(v[w*2]=C[(U+w)*2],v[w*2+1]=C[(U+w)*2+1]):(v[w*2]=D[(_+w)*2],v[w*2+1]=D[(_+w)*2+1]);else for(let w=0;w<A;w++)z[B+w]?(v[w*2]=C[(U+w)*2],v[w*2+1]=C[(U+w)*2+1]):(v[w*2]=D[(_+w)*2],v[w*2+1]=D[(_+w)*2+1])}else if(q(N)){const v=c,C=K,D=V;for(let w=0;w<A;w++)z[B+w]?v[w]=C[U+w]:v[w]=D[_+w]}else for(let v=0;v<A;v++)z[B+v]?c[v]=K[U+v]:c[v]=V[_+v];else for(let v=0;v<A;v++){let C=v,D=0,w=0,O=0;for(let T=0;T<b;T++){const Y=Math.floor(C/o[T]);C=C%o[T],D+=Y*l[T],w+=Y*f[T],O+=Y*n[T]}let X;if(S)X=$(z,B+D,F);else{const T=t.iget(D);X=F?T.re!==0||T.im!==0:!!T}if(X)if(I)if(j){const T=K;c[v*2]=T[(U+w)*2],c[v*2+1]=T[(U+w)*2+1]}else{const T=u.iget(w);c[v*2]=T.re,c[v*2+1]=T.im}else j?c[v]=K[U+w]:c[v]=u.iget(w);else if(I)if(W){const T=V;c[v*2]=T[(_+O)*2],c[v*2+1]=T[(_+O)*2+1]}else{const T=s.iget(O);c[v*2]=T.re,c[v*2+1]=T.im}else W?c[v]=V[_+O]:c[v]=s.iget(O)}return x}function _t(t,u,s="left"){if(t.ndim!==1)throw new Error("storage must be 1D");const r=t.size,d=u.size,h=M(t.dtype),b=t.isCContiguous,g=t.data,m=t.offset,a=u.isCContiguous,i=u.data,e=u.offset;if(!h){const c=st(t,u,s);if(c)return c}const N=R.zeros([d],"float64"),x=N.data;if(h)if(b&&a){const c=g,y=i;for(let l=0;l<d;l++){const f=y[(e+l)*2],n=y[(e+l)*2+1];let o=0,p=r;if(s==="left")for(;o<p;){const A=Math.floor((o+p)/2),F=c[(m+A)*2],I=c[(m+A)*2+1];E(F,I,f,n)<0?o=A+1:p=A}else for(;o<p;){const A=Math.floor((o+p)/2),F=c[(m+A)*2],I=c[(m+A)*2+1];E(F,I,f,n)<=0?o=A+1:p=A}x[l]=o}}else for(let c=0;c<d;c++){const y=u.iget(c),l=y.re,f=y.im;let n=0,o=r;if(s==="left")for(;n<o;){const p=Math.floor((n+o)/2),A=t.iget(p);E(A.re,A.im,l,f)<0?n=p+1:o=p}else for(;n<o;){const p=Math.floor((n+o)/2),A=t.iget(p);E(A.re,A.im,l,f)<=0?n=p+1:o=p}x[c]=n}else if(b&&a)for(let c=0;c<d;c++){const y=Number(i[e+c]);let l=0,f=r;if(s==="left")for(;l<f;){const n=Math.floor((l+f)/2);Number(g[m+n])<y?l=n+1:f=n}else for(;l<f;){const n=Math.floor((l+f)/2);Number(g[m+n])<=y?l=n+1:f=n}x[c]=l}else for(let c=0;c<d;c++){const y=Number(u.iget(c));let l=0,f=r;if(s==="left")for(;l<f;){const n=Math.floor((l+f)/2);Number(t.iget(n))<y?l=n+1:f=n}else for(;l<f;){const n=Math.floor((l+f)/2);Number(t.iget(n))<=y?l=n+1:f=n}x[c]=l}return N}function Lt(t,u){const s=it(t,u);if(s)return s;const r=u.dtype,d=M(t.dtype),h=M(r),b=Math.min(t.size,u.size),g=t.isCContiguous,m=t.data,a=t.offset,i=u.isCContiguous,e=u.data,N=u.offset;let x=0;if(g)for(let f=0;f<b;f++)$(m,a+f,d)&&x++;else for(let f=0;f<b;f++){const n=t.iget(f);(d?n.re!==0||n.im!==0:n)&&x++}const c=R.zeros([x],r),y=c.data;let l=0;if(g&&i)if(q(r)){const f=y,n=e;for(let o=0;o<b;o++)$(m,a+o,d)&&(f[l++]=n[N+o])}else if(h){const f=y,n=e;for(let o=0;o<b;o++)$(m,a+o,d)&&(f[l*2]=n[(N+o)*2],f[l*2+1]=n[(N+o)*2+1],l++)}else for(let f=0;f<b;f++)$(m,a+f,d)&&(y[l++]=e[N+f]);else{const f=g?n=>$(m,a+n,d):n=>{const o=t.iget(n);if(d){const p=o;return p.re!==0||p.im!==0}return!!o};if(q(r)){const n=y;for(let o=0;o<b;o++)f(o)&&(n[l++]=u.iget(o))}else if(h){const n=y;for(let o=0;o<b;o++)if(f(o)){const p=u.iget(o);n[l*2]=p.re,n[l*2+1]=p.im,l++}}else for(let n=0;n<b;n++)f(n)&&(y[l++]=u.iget(n))}return c}function yt(t,u){const s=t.shape,r=s.length,d=t.data,h=t.size,b=t.offset,g=t.strides,m=M(t.dtype),a=t.isCContiguous;if(u===void 0){const n=G(t);if(n!==null)return n;let o=0;if(a)for(let p=0;p<h;p++)$(d,b+p,m)&&o++;else for(let p=0;p<h;p++){const A=t.iget(p);if(m){const F=A;(F.re!==0||F.im!==0)&&o++}else A!==0&&A!==BigInt(0)&&o++}return o}let i=u;if(i<0&&(i=r+i),i<0||i>=r)throw new Error(`axis ${u} is out of bounds for array of dimension ${r}`);const e=Array.from(s).filter((n,o)=>o!==i);if(e.length===0)return yt(t);const N=R.zeros(e,"float64"),x=N.data,c=s[i],y=e.reduce((n,o)=>n*o,1),{baseOffsets:l,axisStride:f}=L(s,g,b,i,y);for(let n=0;n<y;n++){let o=0,p=l[n];for(let A=0;A<c;A++)$(d,p,m)&&o++,p+=f;x[n]=o}return N}export{Ot as argpartition,Bt as argsort,$t as argwhere,yt as count_nonzero,Lt as extract,Et as flatnonzero,Tt as lexsort,dt as nonzero,Mt as partition,_t as searchsorted,Dt as sort,Rt as sort_complex,Ut as where};
|