mlx-bun 0.0.7 → 0.0.8

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/src/mlx/ops.ts CHANGED
@@ -315,6 +315,13 @@ export function cumsum(a: MlxArray, axis: number, s: S = gpuStream): MlxArray {
315
315
  );
316
316
  }
317
317
 
318
+ /** Cumulative maximum along `axis` (inclusive, forward) — mlx.core.cummax. */
319
+ export function cummax(a: MlxArray, axis: number, s: S = gpuStream): MlxArray {
320
+ return new MlxArray(
321
+ outArray("cummax", (o) => C.mlx_cummax(o, a.handle, axis, false, true, s)),
322
+ );
323
+ }
324
+
318
325
  export function where(cond: MlxArray, x: MlxArray, y: MlxArray, s: S = gpuStream): MlxArray {
319
326
  return new MlxArray(
320
327
  outArray("where", (o) => C.mlx_where(o, cond.handle, x.handle, y.handle, s)),
@@ -370,6 +377,38 @@ export function less(a: MlxArray, b: MlxArray, s: S = gpuStream): MlxArray {
370
377
  return new MlxArray(outArray("less", (o) => C.mlx_less(o, a.handle, b.handle, s)));
371
378
  }
372
379
 
380
+ export function lessEqual(a: MlxArray, b: MlxArray, s: S = gpuStream): MlxArray {
381
+ return new MlxArray(outArray("less_equal", (o) => C.mlx_less_equal(o, a.handle, b.handle, s)));
382
+ }
383
+
384
+ export function logicalNot(a: MlxArray, s: S = gpuStream): MlxArray {
385
+ return new MlxArray(outArray("logical_not", (o) => C.mlx_logical_not(o, a.handle, s)));
386
+ }
387
+
388
+ export function equal(a: MlxArray, b: MlxArray, s: S = gpuStream): MlxArray {
389
+ return new MlxArray(outArray("equal", (o) => C.mlx_equal(o, a.handle, b.handle, s)));
390
+ }
391
+
392
+ /** Reduce-all to a scalar (mlx.core.all). */
393
+ export function allReduce(a: MlxArray, s: S = gpuStream): MlxArray {
394
+ return new MlxArray(outArray("all", (o) => C.mlx_all(o, a.handle, false, s)));
395
+ }
396
+
397
+ /** any along one axis (mlx.core.any). */
398
+ export function anyAxis(a: MlxArray, axis: number, keepdims: boolean, s: S = gpuStream): MlxArray {
399
+ return new MlxArray(outArray("any_axis", (o) => C.mlx_any_axis(o, a.handle, axis, keepdims, s)));
400
+ }
401
+
402
+ /** Read a 0-d/1-elem boolean array to host (forces eval). */
403
+ export function itemBool(a: MlxArray): boolean {
404
+ const u = a.astype(Dtype.uint32);
405
+ try {
406
+ return itemUint32(u) !== 0;
407
+ } finally {
408
+ u.dispose();
409
+ }
410
+ }
411
+
373
412
  export function logicalAnd(a: MlxArray, b: MlxArray, s: S = gpuStream): MlxArray {
374
413
  return new MlxArray(
375
414
  outArray("logical_and", (o) => C.mlx_logical_and(o, a.handle, b.handle, s)),
@@ -443,6 +482,34 @@ export function randomKey(seed: bigint): MlxArray {
443
482
  return new MlxArray(outArray("random_key", (o) => C.mlx_random_key(o, seed)));
444
483
  }
445
484
 
485
+ /** Set the GLOBAL mlx PRNG seed (mlx.core.random.seed). Calls to randint/etc
486
+ * with a null key thread the global key, so seeding then calling in the same
487
+ * order as the reference reproduces its draws bit-for-bit. */
488
+ export function randomSeed(seed: bigint): void {
489
+ if (C.mlx_random_seed(seed) !== 0) throw new Error(`mlx_random_seed failed: ${takeMlxError() ?? ""}`);
490
+ }
491
+
492
+ /** Uniform integers in [low, high) — mlx.core.random.randint. With key=null it
493
+ * uses (and advances) the global key, matching mx.random.randint exactly. */
494
+ export function randint(
495
+ low: number, high: number, shape: number[], dtype: Dtype,
496
+ key: MlxArray | null = null, s: S = gpuStream,
497
+ ): MlxArray {
498
+ const buf = new Int32Array(shape);
499
+ const lo = MlxArray.fromInt32(new Int32Array([low]), []);
500
+ const hi = MlxArray.fromInt32(new Int32Array([high]), []);
501
+ try {
502
+ return new MlxArray(
503
+ outArray("random_randint", (o) =>
504
+ C.mlx_random_randint(o, lo.handle, hi.handle, ptr(buf), BigInt(shape.length), dtype, key?.handle ?? 0n, s),
505
+ ),
506
+ );
507
+ } finally {
508
+ lo.dispose();
509
+ hi.dispose();
510
+ }
511
+ }
512
+
446
513
  export function randomCategorical(logits: MlxArray, key: MlxArray | null, s: S = gpuStream): MlxArray {
447
514
  return new MlxArray(
448
515
  outArray("categorical", (o) =>