wgblas 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/README.md +20 -18
  2. package/dist/wgblas.browser.js +2172 -1174
  3. package/index.d.mts +49 -44
  4. package/index.mjs +11 -0
  5. package/package.json +133 -63
  6. package/src/classes/Complex32.d.mts +43 -0
  7. package/src/classes/Complex32.mjs +82 -0
  8. package/src/classes/Complex64.d.mts +44 -0
  9. package/src/classes/Complex64.mjs +76 -0
  10. package/src/classes/GpuMatrix.d.mts +41 -41
  11. package/src/classes/GpuMatrix.mjs +126 -17
  12. package/src/classes/GpuVector.d.mts +36 -40
  13. package/src/classes/GpuVector.mjs +66 -11
  14. package/src/cscal/cscal.d.mts +47 -0
  15. package/src/cscal/cscal.mjs +98 -0
  16. package/src/dasum/dasum.d.mts +4 -4
  17. package/src/dasum/dasum.mjs +38 -20
  18. package/src/daxpy/daxpy.d.mts +56 -0
  19. package/src/daxpy/daxpy.mjs +150 -0
  20. package/src/dcopy/dcopy.d.mts +52 -0
  21. package/src/dcopy/dcopy.mjs +140 -0
  22. package/src/ddot/ddot.d.mts +62 -0
  23. package/src/ddot/ddot.mjs +184 -0
  24. package/src/devdocs.mjs +13 -0
  25. package/src/dnrm2/dnrm2.d.mts +50 -0
  26. package/src/dnrm2/dnrm2.mjs +189 -0
  27. package/src/drot/drot.d.mts +67 -0
  28. package/src/drot/drot.mjs +170 -0
  29. package/src/drotm/drotm.d.mts +67 -0
  30. package/src/drotm/drotm.mjs +171 -0
  31. package/src/dscal/dscal.d.mts +52 -0
  32. package/src/dscal/dscal.mjs +119 -0
  33. package/src/dswap/dswap.d.mts +57 -0
  34. package/src/dswap/dswap.mjs +155 -0
  35. package/src/idamax/idamax.d.mts +20 -2
  36. package/src/idamax/idamax.mjs +56 -24
  37. package/src/init.mjs +117 -56
  38. package/src/isamax/isamax.d.mts +20 -2
  39. package/src/isamax/isamax.mjs +21 -16
  40. package/src/random/random.d.mts +37 -39
  41. package/src/random/random.mjs +39 -7
  42. package/src/sasum/sasum.d.mts +2 -2
  43. package/src/sasum/sasum.mjs +20 -16
  44. package/src/saxpy/saxpy.d.mts +2 -2
  45. package/src/saxpy/saxpy.mjs +14 -11
  46. package/src/scopy/scopy.d.mts +2 -2
  47. package/src/scopy/scopy.mjs +13 -9
  48. package/src/sdot/sdot.d.mts +2 -2
  49. package/src/sdot/sdot.mjs +21 -17
  50. package/src/sgemm/sgemm.d.mts +2 -2
  51. package/src/sgemm/sgemm.mjs +109 -40
  52. package/src/sgemmtr/sgemmtr.d.mts +3 -2
  53. package/src/sgemmtr/sgemmtr.mjs +98 -40
  54. package/src/sgemv/sgemv.d.mts +2 -2
  55. package/src/sgemv/sgemv.mjs +69 -41
  56. package/src/sger/sger.d.mts +2 -2
  57. package/src/sger/sger.mjs +43 -19
  58. package/src/shaders/__test_pipeline_a.wgsl +3 -0
  59. package/src/shaders/__test_pipeline_b.wgsl +2 -0
  60. package/src/shaders/cscal.wgsl +33 -0
  61. package/src/shaders/daxpy.wgsl +66 -0
  62. package/src/shaders/dcopy.wgsl +34 -0
  63. package/src/shaders/ddot.wgsl +106 -0
  64. package/src/shaders/dnrm2.wgsl +167 -0
  65. package/src/shaders/drot.wgsl +81 -0
  66. package/src/shaders/drotm.wgsl +99 -0
  67. package/src/shaders/dscal.wgsl +60 -0
  68. package/src/shaders/dswap.wgsl +38 -0
  69. package/src/shaders/f64/utils/add.wgsl +6 -0
  70. package/src/shaders/f64/utils/divide.wgsl +45 -0
  71. package/src/shaders/f64/utils/multiply.wgsl +19 -10
  72. package/src/shaders/f64/utils/sqrt.wgsl +45 -0
  73. package/src/shaders/index.mjs +233 -14
  74. package/src/shaders/reduction/scaledSum.wgsl +65 -0
  75. package/src/shaders/reduction/scaledSumF64.wgsl +93 -0
  76. package/src/shaders/sgemm_large.wgsl +107 -18
  77. package/src/shaders/sgemm_small.wgsl +115 -15
  78. package/src/shaders/sgemmtr_large.wgsl +4 -1
  79. package/src/shaders/sgemmtr_small.wgsl +4 -1
  80. package/src/shaders/sgemv_n.wgsl +3 -1
  81. package/src/shaders/sgemv_t.wgsl +3 -1
  82. package/src/shaders/snrm2.wgsl +72 -23
  83. package/src/shaders/ssymv.wgsl +3 -1
  84. package/src/snrm2/snrm2.d.mts +2 -2
  85. package/src/snrm2/snrm2.mjs +41 -23
  86. package/src/srot/srot.d.mts +2 -4
  87. package/src/srot/srot.mjs +16 -11
  88. package/src/srotm/srotm.d.mts +2 -4
  89. package/src/srotm/srotm.mjs +17 -11
  90. package/src/sscal/sscal.d.mts +3 -3
  91. package/src/sscal/sscal.mjs +14 -12
  92. package/src/sswap/sswap.d.mts +2 -2
  93. package/src/sswap/sswap.mjs +18 -10
  94. package/src/ssymm/ssymm.d.mts +5 -4
  95. package/src/ssymm/ssymm.mjs +150 -54
  96. package/src/ssymv/ssymv.d.mts +2 -2
  97. package/src/ssymv/ssymv.mjs +47 -26
  98. package/src/ssyr/ssyr.d.mts +2 -2
  99. package/src/ssyr/ssyr.mjs +38 -17
  100. package/src/ssyr2/ssyr2.d.mts +2 -2
  101. package/src/ssyr2/ssyr2.mjs +48 -21
  102. package/src/ssyr2k/ssyr2k.d.mts +3 -2
  103. package/src/ssyr2k/ssyr2k.mjs +140 -62
  104. package/src/ssyrk/ssyrk.d.mts +3 -2
  105. package/src/ssyrk/ssyrk.mjs +91 -39
  106. package/src/strmm/strmm.d.mts +5 -4
  107. package/src/strmm/strmm.mjs +174 -60
  108. package/src/strmv/strmv.d.mts +2 -2
  109. package/src/strmv/strmv.mjs +42 -20
  110. package/src/strsm/strsm.d.mts +6 -4
  111. package/src/strsm/strsm.mjs +438 -174
  112. package/src/strsv/strsv.d.mts +5 -3
  113. package/src/strsv/strsv.mjs +89 -34
  114. package/src/util/benchmark.mjs +9 -9
  115. package/src/util/bindgroup.mjs +1 -3
  116. package/src/util/buffer.mjs +139 -24
  117. package/src/util/complex.mjs +87 -0
  118. package/src/util/compute.mjs +19 -16
  119. package/src/util/constants.mjs +57 -0
  120. package/src/util/device.mjs +49 -0
  121. package/src/util/pipeline.mjs +44 -10
  122. package/src/util/workgroup.mjs +72 -7
  123. package/src/shaders/browser-shaders.mjs +0 -81
  124. package/src/shaders/f64add.wgsl +0 -281
package/index.d.mts CHANGED
@@ -3,23 +3,34 @@
3
3
  */
4
4
  export { GpuVector } from "./src/classes/GpuVector.mjs";
5
5
  export { GpuMatrix } from "./src/classes/GpuMatrix.mjs";
6
+ export { Complex32, Complex32Array } from "./src/classes/Complex32.mjs";
7
+ export { Complex64, Complex64Array } from "./src/classes/Complex64.mjs";
6
8
  export {
7
9
  randomFloat32Array,
8
10
  randomFloat64Array,
9
11
  randomTriangularFloat32Array,
10
12
  } from "./src/random/random.mjs";
11
13
  export { sscal } from "./src/sscal/sscal.mjs";
14
+ export { cscal } from "./src/cscal/cscal.mjs";
15
+ export { dscal } from "./src/dscal/dscal.mjs";
12
16
  export { sswap } from "./src/sswap/sswap.mjs";
17
+ export { dswap } from "./src/dswap/dswap.mjs";
13
18
  export { saxpy } from "./src/saxpy/saxpy.mjs";
19
+ export { daxpy } from "./src/daxpy/daxpy.mjs";
14
20
  export { scopy } from "./src/scopy/scopy.mjs";
21
+ export { dcopy } from "./src/dcopy/dcopy.mjs";
15
22
  export { sdot } from "./src/sdot/sdot.mjs";
16
23
  export { sasum } from "./src/sasum/sasum.mjs";
17
24
  export { dasum } from "./src/dasum/dasum.mjs";
25
+ export { ddot } from "./src/ddot/ddot.mjs";
18
26
  export { snrm2 } from "./src/snrm2/snrm2.mjs";
27
+ export { dnrm2 } from "./src/dnrm2/dnrm2.mjs";
19
28
  export { isamax } from "./src/isamax/isamax.mjs";
20
29
  export { idamax } from "./src/idamax/idamax.mjs";
21
30
  export { srot } from "./src/srot/srot.mjs";
31
+ export { drot } from "./src/drot/drot.mjs";
22
32
  export { srotm } from "./src/srotm/srotm.mjs";
33
+ export { drotm } from "./src/drotm/drotm.mjs";
23
34
  export { sgemv } from "./src/sgemv/sgemv.mjs";
24
35
  export { ssymv } from "./src/ssymv/ssymv.mjs";
25
36
  export { strmv } from "./src/strmv/strmv.mjs";
@@ -38,43 +49,37 @@ export { strsm } from "./src/strsm/strsm.mjs";
38
49
  /**
39
50
  * Initializes the WebGPU device.
40
51
  *
52
+ * Devices are cached per option set: the same options return the same device,
53
+ * different options a separate one — so one process can drive several GPUs
54
+ * (`"high-performance"` and `"low-power"` typically resolve to the discrete and
55
+ * integrated adapters). Each routine dispatches to the device you pass it; GPU
56
+ * buffers cannot cross devices, so a `GpuVector`/`GpuMatrix` from one is
57
+ * rejected by another. {@link cleanup} releases them all.
58
+ *
41
59
  * @param options.powerPreference - GPU power preference (default: `"high-performance"`).
42
60
  * This is a hint to the browser: on dual-GPU systems, `"high-performance"` typically favors the discrete GPU
43
61
  * and `"low-power"` favors the integrated one.
44
62
  * See [MDN: GPU.requestAdapter()](https://developer.mozilla.org/en-US/docs/Web/API/GPU/requestAdapter).
45
- * @param options.benchmark - enable GPU timestamp queries; BLAS functions return `{ result, gpuTimeMs }` (default: `false`)
63
+ * @param options.benchmark - enable GPU timestamp queries; BLAS functions then also return `gpuTimeMs`
64
+ * alongside their normal result (e.g. sscal returns `{ x, gpuTimeMs }`, saxpy returns `{ y, gpuTimeMs }`) —
65
+ * see each routine's own docs for its exact return shape (default: `false`)
46
66
  * @param options.dumpShaders - Node-only. Forwards Dawn's `dump_shaders` debug toggle, printing
47
67
  * each pipeline's WGSL and compiled backend IR (SPIR-V/Vulkan, MSL/Metal, or HLSL/D3D12,
48
68
  * whichever Dawn picked) to stderr as it compiles. A Dawn passthrough, not a wgblas format —
49
69
  * no effect in the browser, which gives pages no API to request compiled shader IR (default: `false`)
50
70
  *
51
- * @example Default (high-performance GPU)
52
- * ```js
53
- * import { init, gpuName } from "wgblas";
54
- * await init();
55
- * const { description, device } = gpuName();
56
- * console.log("description:", description, "device:", device);
57
- * ```
71
+ * **Default (high-performance GPU):**
72
+ * {@includeCode examples/init/init.js}
73
+ *
74
+ * **Low-power (integrated GPU):**
75
+ * {@includeCode examples/init-low-power/init-low-power.js}
76
+ *
77
+ * **Benchmark mode:**
78
+ * {@includeCode examples/init-benchmark/init-benchmark.js}
58
79
  *
59
- * @example Low-power (integrated GPU)
60
- * ```js
61
- * import { init, gpuName } from "wgblas";
62
- * await init({ powerPreference: "low-power" });
63
- * const { description, device } = gpuName();
64
- * console.log("description:", description, "device:", device);
65
- * ```
80
+ * **Two GPUs at once:**
81
+ * {@includeCode examples/init-two-gpus/init-two-gpus.js}
66
82
  *
67
- * @example Benchmark mode
68
- * ```js
69
- * import { init, sscal } from "wgblas";
70
- * const device = await init({ benchmark: true });
71
- * const n = 5;
72
- * const alpha = 2.0;
73
- * const x = new Float32Array([1, 2, 3, 4, 5]);
74
- * const { result, gpuTimeMs } = await sscal(device, n, alpha, x, 1);
75
- * console.log(`Result: [${Array.from(result).join(", ")}]`);
76
- * console.log(`GPU time: ${gpuTimeMs.toFixed(3)} ms`);
77
- * ```
78
83
  * @see [Source code: init.mjs](https://github.com/manit2004/wgblas/blob/main/src/init.mjs#L18-L54)
79
84
  * @category Core
80
85
  */
@@ -85,33 +90,33 @@ export declare function init(options?: {
85
90
  }): Promise<GPUDevice>;
86
91
 
87
92
  /**
88
- * Destroys the WebGPU device, releases the adapter, resets benchmark state, and fires all internal
89
- * cleanup callbacks (e.g. releasing cached GPU pipelines and buffers). Call when done (required in Node.js to prevent crash on exit).
93
+ * Destroys devices created by {@link init} and releases their cached pipelines and buffers.
94
+ * Call when done (required in Node.js to prevent crash on exit).
90
95
  *
91
- * @example
92
- * ```js
93
- * import { init, cleanup, gpuName } from "wgblas";
96
+ * With no argument, releases every device at once. Pass a device to release
97
+ * just that one and leave the others usable — handy when driving several GPUs.
98
+ * Unknown or already-released devices are ignored, so this is safe to call
99
+ * more than once.
94
100
  *
95
- * await init();
96
- * console.log("GPU:", gpuName().description);
97
- * if (typeof process !== "undefined") cleanup(); // Node.js only — browser cleanup is automatic
98
- * ```
101
+ * @param device - the device to release; omit to release all of them.
102
+ *
103
+ * {@includeCode examples/cleanup/cleanup.js}
99
104
  * @see [Source code: init.mjs](https://github.com/manit2004/wgblas/blob/main/src/init.mjs#L56-L65)
100
105
  * @category Core
101
106
  */
102
- export declare function cleanup(): void;
107
+ export declare function cleanup(device?: GPUDevice): void;
103
108
 
104
109
  /**
105
110
  * Returns the GPU device name from the WebGPU adapter info. Must be called after `init()`.
106
111
  *
107
- * @example
108
- * ```js
109
- * import { init, gpuName } from "wgblas";
110
- * await init();
111
- * const { description, device } = gpuName();
112
- * console.log("description:", description, "device:", device);
113
- * ```
112
+ * @param device - which device to report on; defaults to the one from the first
113
+ * `init()` call. Pass it explicitly when driving more than one GPU.
114
+ *
115
+ * {@includeCode examples/init/init.js}
114
116
  * @see [Source code: init.mjs](https://github.com/manit2004/wgblas/blob/main/src/init.mjs#L81-L87)
115
117
  * @category Core
116
118
  */
117
- export declare function gpuName(): { description: string; device: string };
119
+ export declare function gpuName(device?: GPUDevice): {
120
+ description: string;
121
+ device: string;
122
+ };
package/index.mjs CHANGED
@@ -1,23 +1,34 @@
1
1
  export { init, cleanup, gpuName } from "./src/init.mjs";
2
2
  export { GpuVector } from "./src/classes/GpuVector.mjs";
3
3
  export { GpuMatrix } from "./src/classes/GpuMatrix.mjs";
4
+ export { Complex32, Complex32Array } from "./src/classes/Complex32.mjs";
5
+ export { Complex64, Complex64Array } from "./src/classes/Complex64.mjs";
4
6
  export {
5
7
  randomFloat32Array,
6
8
  randomFloat64Array,
7
9
  randomTriangularFloat32Array,
8
10
  } from "./src/random/random.mjs";
9
11
  export { sscal } from "./src/sscal/sscal.mjs";
12
+ export { cscal } from "./src/cscal/cscal.mjs";
13
+ export { dscal } from "./src/dscal/dscal.mjs";
10
14
  export { sswap } from "./src/sswap/sswap.mjs";
15
+ export { dswap } from "./src/dswap/dswap.mjs";
11
16
  export { saxpy } from "./src/saxpy/saxpy.mjs";
17
+ export { daxpy } from "./src/daxpy/daxpy.mjs";
12
18
  export { scopy } from "./src/scopy/scopy.mjs";
19
+ export { dcopy } from "./src/dcopy/dcopy.mjs";
13
20
  export { sdot } from "./src/sdot/sdot.mjs";
14
21
  export { sasum } from "./src/sasum/sasum.mjs";
15
22
  export { dasum } from "./src/dasum/dasum.mjs";
23
+ export { ddot } from "./src/ddot/ddot.mjs";
16
24
  export { snrm2 } from "./src/snrm2/snrm2.mjs";
25
+ export { dnrm2 } from "./src/dnrm2/dnrm2.mjs";
17
26
  export { isamax } from "./src/isamax/isamax.mjs";
18
27
  export { idamax } from "./src/idamax/idamax.mjs";
19
28
  export { srot } from "./src/srot/srot.mjs";
29
+ export { drot } from "./src/drot/drot.mjs";
20
30
  export { srotm } from "./src/srotm/srotm.mjs";
31
+ export { drotm } from "./src/drotm/drotm.mjs";
21
32
  export { sgemv } from "./src/sgemv/sgemv.mjs";
22
33
  export { ssymv } from "./src/ssymv/ssymv.mjs";
23
34
  export { strmv } from "./src/strmv/strmv.mjs";
package/package.json CHANGED
@@ -1,131 +1,175 @@
1
1
  {
2
2
  "name": "wgblas",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "BLAS on WebGPU",
5
5
  "type": "module",
6
6
  "main": "index.mjs",
7
7
  "types": "./index.d.mts",
8
8
  "exports": {
9
9
  ".": {
10
- "import": "./index.mjs",
11
- "types": "./index.d.mts"
10
+ "types": "./index.d.mts",
11
+ "import": "./index.mjs"
12
12
  },
13
13
  "./browser": "./dist/wgblas.browser.js",
14
14
  "./classes/GpuVector": {
15
- "import": "./src/classes/GpuVector.mjs",
16
- "types": "./src/classes/GpuVector.d.mts"
15
+ "types": "./src/classes/GpuVector.d.mts",
16
+ "import": "./src/classes/GpuVector.mjs"
17
17
  },
18
18
  "./classes/GpuMatrix": {
19
- "import": "./src/classes/GpuMatrix.mjs",
20
- "types": "./src/classes/GpuMatrix.d.mts"
19
+ "types": "./src/classes/GpuMatrix.d.mts",
20
+ "import": "./src/classes/GpuMatrix.mjs"
21
+ },
22
+ "./classes/Complex32": {
23
+ "types": "./src/classes/Complex32.d.mts",
24
+ "import": "./src/classes/Complex32.mjs"
25
+ },
26
+ "./classes/Complex64": {
27
+ "types": "./src/classes/Complex64.d.mts",
28
+ "import": "./src/classes/Complex64.mjs"
21
29
  },
22
30
  "./random": {
23
- "import": "./src/random/random.mjs",
24
- "types": "./src/random/random.d.mts"
31
+ "types": "./src/random/random.d.mts",
32
+ "import": "./src/random/random.mjs"
25
33
  },
26
34
  "./sscal": {
27
- "import": "./src/sscal/sscal.mjs",
28
- "types": "./src/sscal/sscal.d.mts"
35
+ "types": "./src/sscal/sscal.d.mts",
36
+ "import": "./src/sscal/sscal.mjs"
37
+ },
38
+ "./cscal": {
39
+ "types": "./src/cscal/cscal.d.mts",
40
+ "import": "./src/cscal/cscal.mjs"
41
+ },
42
+ "./dscal": {
43
+ "types": "./src/dscal/dscal.d.mts",
44
+ "import": "./src/dscal/dscal.mjs"
29
45
  },
30
46
  "./sswap": {
31
- "import": "./src/sswap/sswap.mjs",
32
- "types": "./src/sswap/sswap.d.mts"
47
+ "types": "./src/sswap/sswap.d.mts",
48
+ "import": "./src/sswap/sswap.mjs"
49
+ },
50
+ "./dswap": {
51
+ "types": "./src/dswap/dswap.d.mts",
52
+ "import": "./src/dswap/dswap.mjs"
33
53
  },
34
54
  "./saxpy": {
35
- "import": "./src/saxpy/saxpy.mjs",
36
- "types": "./src/saxpy/saxpy.d.mts"
55
+ "types": "./src/saxpy/saxpy.d.mts",
56
+ "import": "./src/saxpy/saxpy.mjs"
57
+ },
58
+ "./daxpy": {
59
+ "types": "./src/daxpy/daxpy.d.mts",
60
+ "import": "./src/daxpy/daxpy.mjs"
37
61
  },
38
62
  "./scopy": {
39
- "import": "./src/scopy/scopy.mjs",
40
- "types": "./src/scopy/scopy.d.mts"
63
+ "types": "./src/scopy/scopy.d.mts",
64
+ "import": "./src/scopy/scopy.mjs"
65
+ },
66
+ "./dcopy": {
67
+ "types": "./src/dcopy/dcopy.d.mts",
68
+ "import": "./src/dcopy/dcopy.mjs"
41
69
  },
42
70
  "./sdot": {
43
- "import": "./src/sdot/sdot.mjs",
44
- "types": "./src/sdot/sdot.d.mts"
71
+ "types": "./src/sdot/sdot.d.mts",
72
+ "import": "./src/sdot/sdot.mjs"
45
73
  },
46
74
  "./sasum": {
47
- "import": "./src/sasum/sasum.mjs",
48
- "types": "./src/sasum/sasum.d.mts"
75
+ "types": "./src/sasum/sasum.d.mts",
76
+ "import": "./src/sasum/sasum.mjs"
49
77
  },
50
78
  "./dasum": {
51
- "import": "./src/dasum/dasum.mjs",
52
- "types": "./src/dasum/dasum.d.mts"
79
+ "types": "./src/dasum/dasum.d.mts",
80
+ "import": "./src/dasum/dasum.mjs"
81
+ },
82
+ "./ddot": {
83
+ "types": "./src/ddot/ddot.d.mts",
84
+ "import": "./src/ddot/ddot.mjs"
53
85
  },
54
86
  "./snrm2": {
55
- "import": "./src/snrm2/snrm2.mjs",
56
- "types": "./src/snrm2/snrm2.d.mts"
87
+ "types": "./src/snrm2/snrm2.d.mts",
88
+ "import": "./src/snrm2/snrm2.mjs"
89
+ },
90
+ "./dnrm2": {
91
+ "types": "./src/dnrm2/dnrm2.d.mts",
92
+ "import": "./src/dnrm2/dnrm2.mjs"
57
93
  },
58
94
  "./isamax": {
59
- "import": "./src/isamax/isamax.mjs",
60
- "types": "./src/isamax/isamax.d.mts"
95
+ "types": "./src/isamax/isamax.d.mts",
96
+ "import": "./src/isamax/isamax.mjs"
61
97
  },
62
98
  "./idamax": {
63
- "import": "./src/idamax/idamax.mjs",
64
- "types": "./src/idamax/idamax.d.mts"
99
+ "types": "./src/idamax/idamax.d.mts",
100
+ "import": "./src/idamax/idamax.mjs"
65
101
  },
66
102
  "./srot": {
67
- "import": "./src/srot/srot.mjs",
68
- "types": "./src/srot/srot.d.mts"
103
+ "types": "./src/srot/srot.d.mts",
104
+ "import": "./src/srot/srot.mjs"
105
+ },
106
+ "./drot": {
107
+ "types": "./src/drot/drot.d.mts",
108
+ "import": "./src/drot/drot.mjs"
69
109
  },
70
110
  "./srotm": {
71
- "import": "./src/srotm/srotm.mjs",
72
- "types": "./src/srotm/srotm.d.mts"
111
+ "types": "./src/srotm/srotm.d.mts",
112
+ "import": "./src/srotm/srotm.mjs"
113
+ },
114
+ "./drotm": {
115
+ "types": "./src/drotm/drotm.d.mts",
116
+ "import": "./src/drotm/drotm.mjs"
73
117
  },
74
118
  "./sgemv": {
75
- "import": "./src/sgemv/sgemv.mjs",
76
- "types": "./src/sgemv/sgemv.d.mts"
119
+ "types": "./src/sgemv/sgemv.d.mts",
120
+ "import": "./src/sgemv/sgemv.mjs"
77
121
  },
78
122
  "./ssymv": {
79
- "import": "./src/ssymv/ssymv.mjs",
80
- "types": "./src/ssymv/ssymv.d.mts"
123
+ "types": "./src/ssymv/ssymv.d.mts",
124
+ "import": "./src/ssymv/ssymv.mjs"
81
125
  },
82
126
  "./strmv": {
83
- "import": "./src/strmv/strmv.mjs",
84
- "types": "./src/strmv/strmv.d.mts"
127
+ "types": "./src/strmv/strmv.d.mts",
128
+ "import": "./src/strmv/strmv.mjs"
85
129
  },
86
130
  "./strsv": {
87
- "import": "./src/strsv/strsv.mjs",
88
- "types": "./src/strsv/strsv.d.mts"
131
+ "types": "./src/strsv/strsv.d.mts",
132
+ "import": "./src/strsv/strsv.mjs"
89
133
  },
90
134
  "./sger": {
91
- "import": "./src/sger/sger.mjs",
92
- "types": "./src/sger/sger.d.mts"
135
+ "types": "./src/sger/sger.d.mts",
136
+ "import": "./src/sger/sger.mjs"
93
137
  },
94
138
  "./ssyr": {
95
- "import": "./src/ssyr/ssyr.mjs",
96
- "types": "./src/ssyr/ssyr.d.mts"
139
+ "types": "./src/ssyr/ssyr.d.mts",
140
+ "import": "./src/ssyr/ssyr.mjs"
97
141
  },
98
142
  "./ssyr2": {
99
- "import": "./src/ssyr2/ssyr2.mjs",
100
- "types": "./src/ssyr2/ssyr2.d.mts"
143
+ "types": "./src/ssyr2/ssyr2.d.mts",
144
+ "import": "./src/ssyr2/ssyr2.mjs"
101
145
  },
102
146
  "./sgemm": {
103
- "import": "./src/sgemm/sgemm.mjs",
104
- "types": "./src/sgemm/sgemm.d.mts"
147
+ "types": "./src/sgemm/sgemm.d.mts",
148
+ "import": "./src/sgemm/sgemm.mjs"
105
149
  },
106
150
  "./sgemmtr": {
107
- "import": "./src/sgemmtr/sgemmtr.mjs",
108
- "types": "./src/sgemmtr/sgemmtr.d.mts"
151
+ "types": "./src/sgemmtr/sgemmtr.d.mts",
152
+ "import": "./src/sgemmtr/sgemmtr.mjs"
109
153
  },
110
154
  "./ssyrk": {
111
- "import": "./src/ssyrk/ssyrk.mjs",
112
- "types": "./src/ssyrk/ssyrk.d.mts"
155
+ "types": "./src/ssyrk/ssyrk.d.mts",
156
+ "import": "./src/ssyrk/ssyrk.mjs"
113
157
  },
114
158
  "./ssyr2k": {
115
- "import": "./src/ssyr2k/ssyr2k.mjs",
116
- "types": "./src/ssyr2k/ssyr2k.d.mts"
159
+ "types": "./src/ssyr2k/ssyr2k.d.mts",
160
+ "import": "./src/ssyr2k/ssyr2k.mjs"
117
161
  },
118
162
  "./ssymm": {
119
- "import": "./src/ssymm/ssymm.mjs",
120
- "types": "./src/ssymm/ssymm.d.mts"
163
+ "types": "./src/ssymm/ssymm.d.mts",
164
+ "import": "./src/ssymm/ssymm.mjs"
121
165
  },
122
166
  "./strmm": {
123
- "import": "./src/strmm/strmm.mjs",
124
- "types": "./src/strmm/strmm.d.mts"
167
+ "types": "./src/strmm/strmm.d.mts",
168
+ "import": "./src/strmm/strmm.mjs"
125
169
  },
126
170
  "./strsm": {
127
- "import": "./src/strsm/strsm.mjs",
128
- "types": "./src/strsm/strsm.d.mts"
171
+ "types": "./src/strsm/strsm.d.mts",
172
+ "import": "./src/strsm/strsm.mjs"
129
173
  }
130
174
  },
131
175
  "files": [
@@ -179,7 +223,18 @@
179
223
  "@commitlint/cli": "^21.2.1",
180
224
  "@commitlint/config-conventional": "^21.2.0",
181
225
  "@eslint/js": "^10.0.1",
226
+ "@size-limit/file": "^13.0.3",
227
+ "@stdlib/array-complex64": "^0.3.2",
228
+ "@stdlib/blas-base-cscal": "^0.1.1",
182
229
  "@stdlib/blas-base-dasum": "^0.4.1",
230
+ "@stdlib/blas-base-daxpy": "^0.4.1",
231
+ "@stdlib/blas-base-dcopy": "^0.4.1",
232
+ "@stdlib/blas-base-ddot": "^0.4.1",
233
+ "@stdlib/blas-base-dnrm2": "^0.4.1",
234
+ "@stdlib/blas-base-drot": "^0.1.1",
235
+ "@stdlib/blas-base-drotm": "^0.2.1",
236
+ "@stdlib/blas-base-dscal": "^0.4.1",
237
+ "@stdlib/blas-base-dswap": "^0.4.1",
183
238
  "@stdlib/blas-base-idamax": "^0.1.1",
184
239
  "@stdlib/blas-base-isamax": "^0.1.1",
185
240
  "@stdlib/blas-base-sasum": "^0.3.1",
@@ -199,8 +254,10 @@
199
254
  "@stdlib/blas-base-ssyr2": "^0.1.1",
200
255
  "@stdlib/blas-base-strmv": "^0.1.0",
201
256
  "@stdlib/blas-base-strsv": "^0.1.1",
257
+ "@stdlib/complex-float32-ctor": "^0.1.1",
202
258
  "@stdlib/random-array-uniform": "^0.2.2",
203
259
  "@stdlib/random-base-uniform": "^0.2.3",
260
+ "c8": "^12.0.0",
204
261
  "esbuild": "^0.28.1",
205
262
  "eslint": "^10.6.0",
206
263
  "fast-check": "^4.8.0",
@@ -208,7 +265,10 @@
208
265
  "husky": "^9.1.7",
209
266
  "lint-staged": "^17.0.8",
210
267
  "prettier": "^3.9.4",
268
+ "publint": "^0.3.24",
269
+ "size-limit": "^13.0.3",
211
270
  "typedoc": "^0.28.19",
271
+ "typedoc-plugin-katex": "^0.1.2",
212
272
  "typescript": "^6.0.3",
213
273
  "vite": "^8.0.16"
214
274
  },
@@ -216,12 +276,22 @@
216
276
  "prepare": "husky",
217
277
  "build:browser": "node scripts/build-browser.mjs",
218
278
  "docs": "npx typedoc && npm run build:browser",
219
- "prepublishOnly": "npm run build:browser"
279
+ "prepublishOnly": "npm run build:browser",
280
+ "coverage": "c8 --reporter=text --reporter=html node --test $(find tests \\( -name 'test.*.js' -o -name 'gpustorage.*.js' \\))",
281
+ "cpd": "jscpd src",
282
+ "size": "npm run build:browser && size-limit"
220
283
  },
221
284
  "lint-staged": {
222
285
  "*.{js,mjs,cjs}": [
223
286
  "prettier --write",
224
287
  "eslint"
225
288
  ]
226
- }
289
+ },
290
+ "size-limit": [
291
+ {
292
+ "name": "browser bundle (brotli)",
293
+ "path": "dist/wgblas.browser.js",
294
+ "limit": "50 KB"
295
+ }
296
+ ]
227
297
  }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * A single 32-bit (f32) complex number: a real and an imaginary component.
3
+ * JavaScript has no native complex number type, so this is the value type
4
+ * every complex routine in this library builds on.
5
+ *
6
+ * @see <a href="https://github.com/manit2004/wgblas/blob/main/src/classes/Complex32.mjs#L8">Source code: Complex32.mjs (L8)</a>
7
+ * @category Classes
8
+ */
9
+ export declare class Complex32 {
10
+ /**
11
+ * @param re - real component, rounded to the nearest f32
12
+ * @param im - imaginary component, rounded to the nearest f32
13
+ *
14
+ * {@includeCode ../../examples/complex32/complex32.js}
15
+ */
16
+ constructor(re: number, im: number);
17
+
18
+ /** Real component (f32-rounded via `Math.fround`). */
19
+ re: number;
20
+
21
+ /** Imaginary component (f32-rounded via `Math.fround`). */
22
+ im: number;
23
+ }
24
+
25
+ /**
26
+ * An array of Complex32 values — array-of-structs, each element its own
27
+ * independent Complex32 instance (as opposed to a struct-of-arrays layout
28
+ * with separate re/im buffers). Extends the native Array, so indexing
29
+ * (`arr[i]`), `.length`, iteration, `.map`, etc. all work as expected.
30
+ *
31
+ * @see <a href="https://github.com/manit2004/wgblas/blob/main/src/classes/Complex32.mjs#L38">Source code: Complex32.mjs (L38)</a>
32
+ * @category Classes
33
+ */
34
+ export declare class Complex32Array extends Array<Complex32> {
35
+ /**
36
+ * @param arg - a length (fills with that many zero-valued Complex32
37
+ * entries), a flat interleaved `[re, im, re, im, ...]` list of numbers,
38
+ * or an iterable of existing Complex32 instances to copy
39
+ *
40
+ * {@includeCode ../../examples/complex32array/complex32array.js}
41
+ */
42
+ constructor(arg?: number | Iterable<number> | Iterable<Complex32>);
43
+ }
@@ -0,0 +1,82 @@
1
+ /** @module devdocs/classes/Complex32 */
2
+
3
+ /**
4
+ * A single 32-bit (f32) complex number: a real and an imaginary component.
5
+ * JavaScript has no native complex number type, so this is the value type
6
+ * every complex routine in this library builds on.
7
+ */
8
+ export class Complex32 {
9
+ /**
10
+ * @param {number} re - real component, rounded to the nearest f32 (same
11
+ * `Math.fround` truncation splitDoubleDouble uses for f64 emulation) —
12
+ * a plain JS number is an f64, and "32" in Complex32 means each
13
+ * component is genuinely f32-precision, not just f64 stored in an
14
+ * f32-sized slot
15
+ * @param {number} im - imaginary component, rounded to the nearest f32
16
+ */
17
+ constructor(re, im) {
18
+ this.re = Math.fround(re);
19
+ this.im = Math.fround(im);
20
+ }
21
+ }
22
+
23
+ /**
24
+ * An array of Complex32 values — array-of-structs, each element its own
25
+ * independent Complex32 instance (as opposed to a struct-of-arrays layout
26
+ * with separate re/im buffers). Extends the native Array so indexing
27
+ * (`arr[i]`), `.length`, iteration, `.map`, etc. all work as expected.
28
+ *
29
+ * Mirrors @stdlib/array-complex64's constructor overloads (minus the
30
+ * ArrayBuffer-view form, which needs a flat backing buffer — incompatible
31
+ * with storing genuine Complex32 instances one per slot):
32
+ *
33
+ * new Complex32Array() // empty
34
+ * new Complex32Array(length) // length zero-valued entries
35
+ * new Complex32Array([1, 5, 3, 8]) // flat [re, im, re, im, ...] pairs
36
+ * new Complex32Array([z1, z2]) // copies existing Complex32 instances
37
+ */
38
+ export class Complex32Array extends Array {
39
+ /**
40
+ * @param {number|Iterable<number>|Iterable<Complex32>} [arg] - a length,
41
+ * a flat interleaved [re, im, ...] list of numbers, or an iterable of
42
+ * existing Complex32 instances
43
+ */
44
+ constructor(arg) {
45
+ if (arg === undefined) {
46
+ super();
47
+ return;
48
+ }
49
+ if (typeof arg === "number") {
50
+ super(arg);
51
+ for (let i = 0; i < arg; i++) this[i] = new Complex32(0, 0);
52
+ return;
53
+ }
54
+
55
+ const items = Array.from(arg);
56
+ super();
57
+ if (items.length === 0) return;
58
+
59
+ if (items[0] instanceof Complex32) {
60
+ for (const z of items) {
61
+ if (!(z instanceof Complex32))
62
+ throw new Error(
63
+ "Complex32Array expects every element to be a Complex32.",
64
+ );
65
+ this.push(z);
66
+ }
67
+ return;
68
+ }
69
+
70
+ if (items.length % 2 !== 0)
71
+ throw new Error(
72
+ "Complex32Array expects an even number of interleaved [re, im, ...] values.",
73
+ );
74
+ for (let i = 0; i < items.length; i += 2) {
75
+ if (typeof items[i] !== "number" || typeof items[i + 1] !== "number")
76
+ throw new Error(
77
+ "Complex32Array expects interleaved [re, im, ...] values to be numbers.",
78
+ );
79
+ this.push(new Complex32(items[i], items[i + 1]));
80
+ }
81
+ }
82
+ }