@ruvector/attention-wasm 0.1.32 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,265 +1,4 @@
1
- let wasm;
2
-
3
- function addHeapObject(obj) {
4
- if (heap_next === heap.length) heap.push(heap.length + 1);
5
- const idx = heap_next;
6
- heap_next = heap[idx];
7
-
8
- heap[idx] = obj;
9
- return idx;
10
- }
11
-
12
- function debugString(val) {
13
- // primitive types
14
- const type = typeof val;
15
- if (type == 'number' || type == 'boolean' || val == null) {
16
- return `${val}`;
17
- }
18
- if (type == 'string') {
19
- return `"${val}"`;
20
- }
21
- if (type == 'symbol') {
22
- const description = val.description;
23
- if (description == null) {
24
- return 'Symbol';
25
- } else {
26
- return `Symbol(${description})`;
27
- }
28
- }
29
- if (type == 'function') {
30
- const name = val.name;
31
- if (typeof name == 'string' && name.length > 0) {
32
- return `Function(${name})`;
33
- } else {
34
- return 'Function';
35
- }
36
- }
37
- // objects
38
- if (Array.isArray(val)) {
39
- const length = val.length;
40
- let debug = '[';
41
- if (length > 0) {
42
- debug += debugString(val[0]);
43
- }
44
- for(let i = 1; i < length; i++) {
45
- debug += ', ' + debugString(val[i]);
46
- }
47
- debug += ']';
48
- return debug;
49
- }
50
- // Test for built-in
51
- const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
52
- let className;
53
- if (builtInMatches && builtInMatches.length > 1) {
54
- className = builtInMatches[1];
55
- } else {
56
- // Failed to match the standard '[object ClassName]'
57
- return toString.call(val);
58
- }
59
- if (className == 'Object') {
60
- // we're a user defined class or Object
61
- // JSON.stringify avoids problems with cycles, and is generally much
62
- // easier than looping through ownProperties of `val`.
63
- try {
64
- return 'Object(' + JSON.stringify(val) + ')';
65
- } catch (_) {
66
- return 'Object';
67
- }
68
- }
69
- // errors
70
- if (val instanceof Error) {
71
- return `${val.name}: ${val.message}\n${val.stack}`;
72
- }
73
- // TODO we could test for more things here, like `Set`s and `Map`s.
74
- return className;
75
- }
76
-
77
- function dropObject(idx) {
78
- if (idx < 132) return;
79
- heap[idx] = heap_next;
80
- heap_next = idx;
81
- }
82
-
83
- function getArrayF32FromWasm0(ptr, len) {
84
- ptr = ptr >>> 0;
85
- return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
86
- }
87
-
88
- function getArrayU8FromWasm0(ptr, len) {
89
- ptr = ptr >>> 0;
90
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
91
- }
92
-
93
- let cachedDataViewMemory0 = null;
94
- function getDataViewMemory0() {
95
- if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
96
- cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
97
- }
98
- return cachedDataViewMemory0;
99
- }
100
-
101
- let cachedFloat32ArrayMemory0 = null;
102
- function getFloat32ArrayMemory0() {
103
- if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
104
- cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
105
- }
106
- return cachedFloat32ArrayMemory0;
107
- }
108
-
109
- function getStringFromWasm0(ptr, len) {
110
- ptr = ptr >>> 0;
111
- return decodeText(ptr, len);
112
- }
113
-
114
- let cachedUint8ArrayMemory0 = null;
115
- function getUint8ArrayMemory0() {
116
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
117
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
118
- }
119
- return cachedUint8ArrayMemory0;
120
- }
121
-
122
- function getObject(idx) { return heap[idx]; }
123
-
124
- function handleError(f, args) {
125
- try {
126
- return f.apply(this, args);
127
- } catch (e) {
128
- wasm.__wbindgen_export3(addHeapObject(e));
129
- }
130
- }
131
-
132
- let heap = new Array(128).fill(undefined);
133
- heap.push(undefined, null, true, false);
134
-
135
- let heap_next = heap.length;
136
-
137
- function isLikeNone(x) {
138
- return x === undefined || x === null;
139
- }
140
-
141
- function passArrayF32ToWasm0(arg, malloc) {
142
- const ptr = malloc(arg.length * 4, 4) >>> 0;
143
- getFloat32ArrayMemory0().set(arg, ptr / 4);
144
- WASM_VECTOR_LEN = arg.length;
145
- return ptr;
146
- }
147
-
148
- function passStringToWasm0(arg, malloc, realloc) {
149
- if (realloc === undefined) {
150
- const buf = cachedTextEncoder.encode(arg);
151
- const ptr = malloc(buf.length, 1) >>> 0;
152
- getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
153
- WASM_VECTOR_LEN = buf.length;
154
- return ptr;
155
- }
156
-
157
- let len = arg.length;
158
- let ptr = malloc(len, 1) >>> 0;
159
-
160
- const mem = getUint8ArrayMemory0();
161
-
162
- let offset = 0;
163
-
164
- for (; offset < len; offset++) {
165
- const code = arg.charCodeAt(offset);
166
- if (code > 0x7F) break;
167
- mem[ptr + offset] = code;
168
- }
169
- if (offset !== len) {
170
- if (offset !== 0) {
171
- arg = arg.slice(offset);
172
- }
173
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
174
- const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
175
- const ret = cachedTextEncoder.encodeInto(arg, view);
176
-
177
- offset += ret.written;
178
- ptr = realloc(ptr, len, offset, 1) >>> 0;
179
- }
180
-
181
- WASM_VECTOR_LEN = offset;
182
- return ptr;
183
- }
184
-
185
- function takeObject(idx) {
186
- const ret = getObject(idx);
187
- dropObject(idx);
188
- return ret;
189
- }
190
-
191
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
192
- cachedTextDecoder.decode();
193
- const MAX_SAFARI_DECODE_BYTES = 2146435072;
194
- let numBytesDecoded = 0;
195
- function decodeText(ptr, len) {
196
- numBytesDecoded += len;
197
- if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
198
- cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
199
- cachedTextDecoder.decode();
200
- numBytesDecoded = len;
201
- }
202
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
203
- }
204
-
205
- const cachedTextEncoder = new TextEncoder();
206
-
207
- if (!('encodeInto' in cachedTextEncoder)) {
208
- cachedTextEncoder.encodeInto = function (arg, view) {
209
- const buf = cachedTextEncoder.encode(arg);
210
- view.set(buf);
211
- return {
212
- read: arg.length,
213
- written: buf.length
214
- };
215
- }
216
- }
217
-
218
- let WASM_VECTOR_LEN = 0;
219
-
220
- const WasmAdamFinalization = (typeof FinalizationRegistry === 'undefined')
221
- ? { register: () => {}, unregister: () => {} }
222
- : new FinalizationRegistry(ptr => wasm.__wbg_wasmadam_free(ptr >>> 0, 1));
223
-
224
- const WasmAdamWFinalization = (typeof FinalizationRegistry === 'undefined')
225
- ? { register: () => {}, unregister: () => {} }
226
- : new FinalizationRegistry(ptr => wasm.__wbg_wasmadamw_free(ptr >>> 0, 1));
227
-
228
- const WasmFlashAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
229
- ? { register: () => {}, unregister: () => {} }
230
- : new FinalizationRegistry(ptr => wasm.__wbg_wasmflashattention_free(ptr >>> 0, 1));
231
-
232
- const WasmHyperbolicAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
233
- ? { register: () => {}, unregister: () => {} }
234
- : new FinalizationRegistry(ptr => wasm.__wbg_wasmhyperbolicattention_free(ptr >>> 0, 1));
235
-
236
- const WasmInfoNCELossFinalization = (typeof FinalizationRegistry === 'undefined')
237
- ? { register: () => {}, unregister: () => {} }
238
- : new FinalizationRegistry(ptr => wasm.__wbg_wasminfonceloss_free(ptr >>> 0, 1));
239
-
240
- const WasmLRSchedulerFinalization = (typeof FinalizationRegistry === 'undefined')
241
- ? { register: () => {}, unregister: () => {} }
242
- : new FinalizationRegistry(ptr => wasm.__wbg_wasmlrscheduler_free(ptr >>> 0, 1));
243
-
244
- const WasmLinearAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
245
- ? { register: () => {}, unregister: () => {} }
246
- : new FinalizationRegistry(ptr => wasm.__wbg_wasmlinearattention_free(ptr >>> 0, 1));
247
-
248
- const WasmLocalGlobalAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
249
- ? { register: () => {}, unregister: () => {} }
250
- : new FinalizationRegistry(ptr => wasm.__wbg_wasmlocalglobalattention_free(ptr >>> 0, 1));
251
-
252
- const WasmMoEAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
253
- ? { register: () => {}, unregister: () => {} }
254
- : new FinalizationRegistry(ptr => wasm.__wbg_wasmmoeattention_free(ptr >>> 0, 1));
255
-
256
- const WasmMultiHeadAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
257
- ? { register: () => {}, unregister: () => {} }
258
- : new FinalizationRegistry(ptr => wasm.__wbg_wasmmultiheadattention_free(ptr >>> 0, 1));
259
-
260
- const WasmSGDFinalization = (typeof FinalizationRegistry === 'undefined')
261
- ? { register: () => {}, unregister: () => {} }
262
- : new FinalizationRegistry(ptr => wasm.__wbg_wasmsgd_free(ptr >>> 0, 1));
1
+ /* @ts-self-types="./ruvector_attention_wasm.d.ts" */
263
2
 
264
3
  /**
265
4
  * Adam optimizer
@@ -279,16 +18,9 @@ export class WasmAdam {
279
18
  * Get current learning rate
280
19
  * @returns {number}
281
20
  */
282
- get learning_rate() {
283
- const ret = wasm.wasmadam_learning_rate(this.__wbg_ptr);
284
- return ret;
285
- }
286
- /**
287
- * Set learning rate
288
- * @param {number} lr
289
- */
290
- set learning_rate(lr) {
291
- wasm.wasmadam_set_learning_rate(this.__wbg_ptr, lr);
21
+ get learning_rate() {
22
+ const ret = wasm.wasmadam_learning_rate(this.__wbg_ptr);
23
+ return ret;
292
24
  }
293
25
  /**
294
26
  * Create a new Adam optimizer
@@ -305,6 +37,19 @@ export class WasmAdam {
305
37
  WasmAdamFinalization.register(this, this.__wbg_ptr, this);
306
38
  return this;
307
39
  }
40
+ /**
41
+ * Reset optimizer state
42
+ */
43
+ reset() {
44
+ wasm.wasmadam_reset(this.__wbg_ptr);
45
+ }
46
+ /**
47
+ * Set learning rate
48
+ * @param {number} lr
49
+ */
50
+ set learning_rate(lr) {
51
+ wasm.wasmadam_set_learning_rate(this.__wbg_ptr, lr);
52
+ }
308
53
  /**
309
54
  * Perform optimization step
310
55
  *
@@ -321,12 +66,6 @@ export class WasmAdam {
321
66
  const len1 = WASM_VECTOR_LEN;
322
67
  wasm.wasmadam_step(this.__wbg_ptr, ptr0, len0, addHeapObject(params), ptr1, len1);
323
68
  }
324
- /**
325
- * Reset optimizer state
326
- */
327
- reset() {
328
- wasm.wasmadam_reset(this.__wbg_ptr);
329
- }
330
69
  }
331
70
  if (Symbol.dispose) WasmAdam.prototype[Symbol.dispose] = WasmAdam.prototype.free;
332
71
 
@@ -344,29 +83,14 @@ export class WasmAdamW {
344
83
  const ptr = this.__destroy_into_raw();
345
84
  wasm.__wbg_wasmadamw_free(ptr, 0);
346
85
  }
347
- /**
348
- * Get weight decay
349
- * @returns {number}
350
- */
351
- get weight_decay() {
352
- const ret = wasm.wasmadamw_weight_decay(this.__wbg_ptr);
353
- return ret;
354
- }
355
86
  /**
356
87
  * Get current learning rate
357
88
  * @returns {number}
358
89
  */
359
90
  get learning_rate() {
360
- const ret = wasm.wasmadam_learning_rate(this.__wbg_ptr);
91
+ const ret = wasm.wasmadamw_learning_rate(this.__wbg_ptr);
361
92
  return ret;
362
93
  }
363
- /**
364
- * Set learning rate
365
- * @param {number} lr
366
- */
367
- set learning_rate(lr) {
368
- wasm.wasmadam_set_learning_rate(this.__wbg_ptr, lr);
369
- }
370
94
  /**
371
95
  * Create a new AdamW optimizer
372
96
  *
@@ -384,6 +108,19 @@ export class WasmAdamW {
384
108
  WasmAdamWFinalization.register(this, this.__wbg_ptr, this);
385
109
  return this;
386
110
  }
111
+ /**
112
+ * Reset optimizer state
113
+ */
114
+ reset() {
115
+ wasm.wasmadamw_reset(this.__wbg_ptr);
116
+ }
117
+ /**
118
+ * Set learning rate
119
+ * @param {number} lr
120
+ */
121
+ set learning_rate(lr) {
122
+ wasm.wasmadamw_set_learning_rate(this.__wbg_ptr, lr);
123
+ }
387
124
  /**
388
125
  * Perform optimization step with weight decay
389
126
  * @param {Float32Array} params
@@ -397,10 +134,12 @@ export class WasmAdamW {
397
134
  wasm.wasmadamw_step(this.__wbg_ptr, ptr0, len0, addHeapObject(params), ptr1, len1);
398
135
  }
399
136
  /**
400
- * Reset optimizer state
137
+ * Get weight decay
138
+ * @returns {number}
401
139
  */
402
- reset() {
403
- wasm.wasmadamw_reset(this.__wbg_ptr);
140
+ get weight_decay() {
141
+ const ret = wasm.wasmadamw_weight_decay(this.__wbg_ptr);
142
+ return ret;
404
143
  }
405
144
  }
406
145
  if (Symbol.dispose) WasmAdamW.prototype[Symbol.dispose] = WasmAdamW.prototype.free;
@@ -419,21 +158,6 @@ export class WasmFlashAttention {
419
158
  const ptr = this.__destroy_into_raw();
420
159
  wasm.__wbg_wasmflashattention_free(ptr, 0);
421
160
  }
422
- /**
423
- * Create a new flash attention instance
424
- *
425
- * # Arguments
426
- * * `dim` - Embedding dimension
427
- * * `block_size` - Block size for tiling
428
- * @param {number} dim
429
- * @param {number} block_size
430
- */
431
- constructor(dim, block_size) {
432
- const ret = wasm.wasmflashattention_new(dim, block_size);
433
- this.__wbg_ptr = ret >>> 0;
434
- WasmFlashAttentionFinalization.register(this, this.__wbg_ptr, this);
435
- return this;
436
- }
437
161
  /**
438
162
  * Compute flash attention
439
163
  * @param {Float32Array} query
@@ -461,6 +185,21 @@ export class WasmFlashAttention {
461
185
  wasm.__wbindgen_add_to_stack_pointer(16);
462
186
  }
463
187
  }
188
+ /**
189
+ * Create a new flash attention instance
190
+ *
191
+ * # Arguments
192
+ * * `dim` - Embedding dimension
193
+ * * `block_size` - Block size for tiling
194
+ * @param {number} dim
195
+ * @param {number} block_size
196
+ */
197
+ constructor(dim, block_size) {
198
+ const ret = wasm.wasmflashattention_new(dim, block_size);
199
+ this.__wbg_ptr = ret >>> 0;
200
+ WasmFlashAttentionFinalization.register(this, this.__wbg_ptr, this);
201
+ return this;
202
+ }
464
203
  }
465
204
  if (Symbol.dispose) WasmFlashAttention.prototype[Symbol.dispose] = WasmFlashAttention.prototype.free;
466
205
 
@@ -478,21 +217,6 @@ export class WasmHyperbolicAttention {
478
217
  const ptr = this.__destroy_into_raw();
479
218
  wasm.__wbg_wasmhyperbolicattention_free(ptr, 0);
480
219
  }
481
- /**
482
- * Create a new hyperbolic attention instance
483
- *
484
- * # Arguments
485
- * * `dim` - Embedding dimension
486
- * * `curvature` - Hyperbolic curvature parameter
487
- * @param {number} dim
488
- * @param {number} curvature
489
- */
490
- constructor(dim, curvature) {
491
- const ret = wasm.wasmhyperbolicattention_new(dim, curvature);
492
- this.__wbg_ptr = ret >>> 0;
493
- WasmHyperbolicAttentionFinalization.register(this, this.__wbg_ptr, this);
494
- return this;
495
- }
496
220
  /**
497
221
  * Compute hyperbolic attention
498
222
  * @param {Float32Array} query
@@ -528,6 +252,21 @@ export class WasmHyperbolicAttention {
528
252
  const ret = wasm.wasmhyperbolicattention_curvature(this.__wbg_ptr);
529
253
  return ret;
530
254
  }
255
+ /**
256
+ * Create a new hyperbolic attention instance
257
+ *
258
+ * # Arguments
259
+ * * `dim` - Embedding dimension
260
+ * * `curvature` - Hyperbolic curvature parameter
261
+ * @param {number} dim
262
+ * @param {number} curvature
263
+ */
264
+ constructor(dim, curvature) {
265
+ const ret = wasm.wasmhyperbolicattention_new(dim, curvature);
266
+ this.__wbg_ptr = ret >>> 0;
267
+ WasmHyperbolicAttentionFinalization.register(this, this.__wbg_ptr, this);
268
+ return this;
269
+ }
531
270
  }
532
271
  if (Symbol.dispose) WasmHyperbolicAttention.prototype[Symbol.dispose] = WasmHyperbolicAttention.prototype.free;
533
272
 
@@ -545,19 +284,6 @@ export class WasmInfoNCELoss {
545
284
  const ptr = this.__destroy_into_raw();
546
285
  wasm.__wbg_wasminfonceloss_free(ptr, 0);
547
286
  }
548
- /**
549
- * Create a new InfoNCE loss instance
550
- *
551
- * # Arguments
552
- * * `temperature` - Temperature parameter for softmax
553
- * @param {number} temperature
554
- */
555
- constructor(temperature) {
556
- const ret = wasm.wasminfonceloss_new(temperature);
557
- this.__wbg_ptr = ret >>> 0;
558
- WasmInfoNCELossFinalization.register(this, this.__wbg_ptr, this);
559
- return this;
560
- }
561
287
  /**
562
288
  * Compute InfoNCE loss
563
289
  *
@@ -589,6 +315,19 @@ export class WasmInfoNCELoss {
589
315
  wasm.__wbindgen_add_to_stack_pointer(16);
590
316
  }
591
317
  }
318
+ /**
319
+ * Create a new InfoNCE loss instance
320
+ *
321
+ * # Arguments
322
+ * * `temperature` - Temperature parameter for softmax
323
+ * @param {number} temperature
324
+ */
325
+ constructor(temperature) {
326
+ const ret = wasm.wasminfonceloss_new(temperature);
327
+ this.__wbg_ptr = ret >>> 0;
328
+ WasmInfoNCELossFinalization.register(this, this.__wbg_ptr, this);
329
+ return this;
330
+ }
592
331
  }
593
332
  if (Symbol.dispose) WasmInfoNCELoss.prototype[Symbol.dispose] = WasmInfoNCELoss.prototype.free;
594
333
 
@@ -606,6 +345,14 @@ export class WasmLRScheduler {
606
345
  const ptr = this.__destroy_into_raw();
607
346
  wasm.__wbg_wasmlrscheduler_free(ptr, 0);
608
347
  }
348
+ /**
349
+ * Get learning rate for current step
350
+ * @returns {number}
351
+ */
352
+ get_lr() {
353
+ const ret = wasm.wasmlrscheduler_get_lr(this.__wbg_ptr);
354
+ return ret;
355
+ }
609
356
  /**
610
357
  * Create a new learning rate scheduler with warmup and cosine decay
611
358
  *
@@ -623,12 +370,6 @@ export class WasmLRScheduler {
623
370
  WasmLRSchedulerFinalization.register(this, this.__wbg_ptr, this);
624
371
  return this;
625
372
  }
626
- /**
627
- * Advance to next step
628
- */
629
- step() {
630
- wasm.wasmlrscheduler_step(this.__wbg_ptr);
631
- }
632
373
  /**
633
374
  * Reset scheduler
634
375
  */
@@ -636,12 +377,10 @@ export class WasmLRScheduler {
636
377
  wasm.wasmlrscheduler_reset(this.__wbg_ptr);
637
378
  }
638
379
  /**
639
- * Get learning rate for current step
640
- * @returns {number}
380
+ * Advance to next step
641
381
  */
642
- get_lr() {
643
- const ret = wasm.wasmlrscheduler_get_lr(this.__wbg_ptr);
644
- return ret;
382
+ step() {
383
+ wasm.wasmlrscheduler_step(this.__wbg_ptr);
645
384
  }
646
385
  }
647
386
  if (Symbol.dispose) WasmLRScheduler.prototype[Symbol.dispose] = WasmLRScheduler.prototype.free;
@@ -660,21 +399,6 @@ export class WasmLinearAttention {
660
399
  const ptr = this.__destroy_into_raw();
661
400
  wasm.__wbg_wasmlinearattention_free(ptr, 0);
662
401
  }
663
- /**
664
- * Create a new linear attention instance
665
- *
666
- * # Arguments
667
- * * `dim` - Embedding dimension
668
- * * `num_features` - Number of random features
669
- * @param {number} dim
670
- * @param {number} num_features
671
- */
672
- constructor(dim, num_features) {
673
- const ret = wasm.wasmlinearattention_new(dim, num_features);
674
- this.__wbg_ptr = ret >>> 0;
675
- WasmLinearAttentionFinalization.register(this, this.__wbg_ptr, this);
676
- return this;
677
- }
678
402
  /**
679
403
  * Compute linear attention
680
404
  * @param {Float32Array} query
@@ -702,6 +426,21 @@ export class WasmLinearAttention {
702
426
  wasm.__wbindgen_add_to_stack_pointer(16);
703
427
  }
704
428
  }
429
+ /**
430
+ * Create a new linear attention instance
431
+ *
432
+ * # Arguments
433
+ * * `dim` - Embedding dimension
434
+ * * `num_features` - Number of random features
435
+ * @param {number} dim
436
+ * @param {number} num_features
437
+ */
438
+ constructor(dim, num_features) {
439
+ const ret = wasm.wasmlinearattention_new(dim, num_features);
440
+ this.__wbg_ptr = ret >>> 0;
441
+ WasmLinearAttentionFinalization.register(this, this.__wbg_ptr, this);
442
+ return this;
443
+ }
705
444
  }
706
445
  if (Symbol.dispose) WasmLinearAttention.prototype[Symbol.dispose] = WasmLinearAttention.prototype.free;
707
446
 
@@ -719,23 +458,6 @@ export class WasmLocalGlobalAttention {
719
458
  const ptr = this.__destroy_into_raw();
720
459
  wasm.__wbg_wasmlocalglobalattention_free(ptr, 0);
721
460
  }
722
- /**
723
- * Create a new local-global attention instance
724
- *
725
- * # Arguments
726
- * * `dim` - Embedding dimension
727
- * * `local_window` - Size of local attention window
728
- * * `global_tokens` - Number of global attention tokens
729
- * @param {number} dim
730
- * @param {number} local_window
731
- * @param {number} global_tokens
732
- */
733
- constructor(dim, local_window, global_tokens) {
734
- const ret = wasm.wasmlocalglobalattention_new(dim, local_window, global_tokens);
735
- this.__wbg_ptr = ret >>> 0;
736
- WasmLocalGlobalAttentionFinalization.register(this, this.__wbg_ptr, this);
737
- return this;
738
- }
739
461
  /**
740
462
  * Compute local-global attention
741
463
  * @param {Float32Array} query
@@ -763,6 +485,23 @@ export class WasmLocalGlobalAttention {
763
485
  wasm.__wbindgen_add_to_stack_pointer(16);
764
486
  }
765
487
  }
488
+ /**
489
+ * Create a new local-global attention instance
490
+ *
491
+ * # Arguments
492
+ * * `dim` - Embedding dimension
493
+ * * `local_window` - Size of local attention window
494
+ * * `global_tokens` - Number of global attention tokens
495
+ * @param {number} dim
496
+ * @param {number} local_window
497
+ * @param {number} global_tokens
498
+ */
499
+ constructor(dim, local_window, global_tokens) {
500
+ const ret = wasm.wasmlocalglobalattention_new(dim, local_window, global_tokens);
501
+ this.__wbg_ptr = ret >>> 0;
502
+ WasmLocalGlobalAttentionFinalization.register(this, this.__wbg_ptr, this);
503
+ return this;
504
+ }
766
505
  }
767
506
  if (Symbol.dispose) WasmLocalGlobalAttention.prototype[Symbol.dispose] = WasmLocalGlobalAttention.prototype.free;
768
507
 
@@ -772,30 +511,13 @@ if (Symbol.dispose) WasmLocalGlobalAttention.prototype[Symbol.dispose] = WasmLoc
772
511
  export class WasmMoEAttention {
773
512
  __destroy_into_raw() {
774
513
  const ptr = this.__wbg_ptr;
775
- this.__wbg_ptr = 0;
776
- WasmMoEAttentionFinalization.unregister(this);
777
- return ptr;
778
- }
779
- free() {
780
- const ptr = this.__destroy_into_raw();
781
- wasm.__wbg_wasmmoeattention_free(ptr, 0);
782
- }
783
- /**
784
- * Create a new MoE attention instance
785
- *
786
- * # Arguments
787
- * * `dim` - Embedding dimension
788
- * * `num_experts` - Number of expert attention mechanisms
789
- * * `top_k` - Number of experts to use per query
790
- * @param {number} dim
791
- * @param {number} num_experts
792
- * @param {number} top_k
793
- */
794
- constructor(dim, num_experts, top_k) {
795
- const ret = wasm.wasmmoeattention_new(dim, num_experts, top_k);
796
- this.__wbg_ptr = ret >>> 0;
797
- WasmMoEAttentionFinalization.register(this, this.__wbg_ptr, this);
798
- return this;
514
+ this.__wbg_ptr = 0;
515
+ WasmMoEAttentionFinalization.unregister(this);
516
+ return ptr;
517
+ }
518
+ free() {
519
+ const ptr = this.__destroy_into_raw();
520
+ wasm.__wbg_wasmmoeattention_free(ptr, 0);
799
521
  }
800
522
  /**
801
523
  * Compute MoE attention
@@ -824,6 +546,23 @@ export class WasmMoEAttention {
824
546
  wasm.__wbindgen_add_to_stack_pointer(16);
825
547
  }
826
548
  }
549
+ /**
550
+ * Create a new MoE attention instance
551
+ *
552
+ * # Arguments
553
+ * * `dim` - Embedding dimension
554
+ * * `num_experts` - Number of expert attention mechanisms
555
+ * * `top_k` - Number of experts to use per query
556
+ * @param {number} dim
557
+ * @param {number} num_experts
558
+ * @param {number} top_k
559
+ */
560
+ constructor(dim, num_experts, top_k) {
561
+ const ret = wasm.wasmmoeattention_new(dim, num_experts, top_k);
562
+ this.__wbg_ptr = ret >>> 0;
563
+ WasmMoEAttentionFinalization.register(this, this.__wbg_ptr, this);
564
+ return this;
565
+ }
827
566
  }
828
567
  if (Symbol.dispose) WasmMoEAttention.prototype[Symbol.dispose] = WasmMoEAttention.prototype.free;
829
568
 
@@ -841,6 +580,33 @@ export class WasmMultiHeadAttention {
841
580
  const ptr = this.__destroy_into_raw();
842
581
  wasm.__wbg_wasmmultiheadattention_free(ptr, 0);
843
582
  }
583
+ /**
584
+ * Compute multi-head attention
585
+ * @param {Float32Array} query
586
+ * @param {any} keys
587
+ * @param {any} values
588
+ * @returns {Float32Array}
589
+ */
590
+ compute(query, keys, values) {
591
+ try {
592
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
593
+ const ptr0 = passArrayF32ToWasm0(query, wasm.__wbindgen_export);
594
+ const len0 = WASM_VECTOR_LEN;
595
+ wasm.wasmmultiheadattention_compute(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(keys), addHeapObject(values));
596
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
597
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
598
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
599
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
600
+ if (r3) {
601
+ throw takeObject(r2);
602
+ }
603
+ var v2 = getArrayF32FromWasm0(r0, r1).slice();
604
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
605
+ return v2;
606
+ } finally {
607
+ wasm.__wbindgen_add_to_stack_pointer(16);
608
+ }
609
+ }
844
610
  /**
845
611
  * Get the dimension
846
612
  * @returns {number}
@@ -875,33 +641,6 @@ export class WasmMultiHeadAttention {
875
641
  wasm.__wbindgen_add_to_stack_pointer(16);
876
642
  }
877
643
  }
878
- /**
879
- * Compute multi-head attention
880
- * @param {Float32Array} query
881
- * @param {any} keys
882
- * @param {any} values
883
- * @returns {Float32Array}
884
- */
885
- compute(query, keys, values) {
886
- try {
887
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
888
- const ptr0 = passArrayF32ToWasm0(query, wasm.__wbindgen_export);
889
- const len0 = WASM_VECTOR_LEN;
890
- wasm.wasmmultiheadattention_compute(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(keys), addHeapObject(values));
891
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
892
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
893
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
894
- var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
895
- if (r3) {
896
- throw takeObject(r2);
897
- }
898
- var v2 = getArrayF32FromWasm0(r0, r1).slice();
899
- wasm.__wbindgen_export4(r0, r1 * 4, 4);
900
- return v2;
901
- } finally {
902
- wasm.__wbindgen_add_to_stack_pointer(16);
903
- }
904
- }
905
644
  /**
906
645
  * Get the number of heads
907
646
  * @returns {number}
@@ -935,13 +674,6 @@ export class WasmSGD {
935
674
  const ret = wasm.wasmsgd_learning_rate(this.__wbg_ptr);
936
675
  return ret;
937
676
  }
938
- /**
939
- * Set learning rate
940
- * @param {number} lr
941
- */
942
- set learning_rate(lr) {
943
- wasm.wasmsgd_set_learning_rate(this.__wbg_ptr, lr);
944
- }
945
677
  /**
946
678
  * Create a new SGD optimizer
947
679
  *
@@ -959,6 +691,19 @@ export class WasmSGD {
959
691
  WasmSGDFinalization.register(this, this.__wbg_ptr, this);
960
692
  return this;
961
693
  }
694
+ /**
695
+ * Reset optimizer state
696
+ */
697
+ reset() {
698
+ wasm.wasmsgd_reset(this.__wbg_ptr);
699
+ }
700
+ /**
701
+ * Set learning rate
702
+ * @param {number} lr
703
+ */
704
+ set learning_rate(lr) {
705
+ wasm.wasmsgd_set_learning_rate(this.__wbg_ptr, lr);
706
+ }
962
707
  /**
963
708
  * Perform optimization step
964
709
  * @param {Float32Array} params
@@ -971,12 +716,6 @@ export class WasmSGD {
971
716
  const len1 = WASM_VECTOR_LEN;
972
717
  wasm.wasmsgd_step(this.__wbg_ptr, ptr0, len0, addHeapObject(params), ptr1, len1);
973
718
  }
974
- /**
975
- * Reset optimizer state
976
- */
977
- reset() {
978
- wasm.wasmsgd_reset(this.__wbg_ptr);
979
- }
980
719
  }
981
720
  if (Symbol.dispose) WasmSGD.prototype[Symbol.dispose] = WasmSGD.prototype.free;
982
721
 
@@ -1006,10 +745,173 @@ export function available_mechanisms() {
1006
745
  * @param {number | null} [epsilon]
1007
746
  * @returns {Float32Array}
1008
747
  */
1009
- export function batch_normalize(vectors, epsilon) {
748
+ export function batch_normalize(vectors, epsilon) {
749
+ try {
750
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
751
+ wasm.batch_normalize(retptr, addHeapObject(vectors), isLikeNone(epsilon) ? 0x100000001 : Math.fround(epsilon));
752
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
753
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
754
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
755
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
756
+ if (r3) {
757
+ throw takeObject(r2);
758
+ }
759
+ var v1 = getArrayF32FromWasm0(r0, r1).slice();
760
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
761
+ return v1;
762
+ } finally {
763
+ wasm.__wbindgen_add_to_stack_pointer(16);
764
+ }
765
+ }
766
+
767
+ /**
768
+ * Compute cosine similarity between two vectors
769
+ * @param {Float32Array} a
770
+ * @param {Float32Array} b
771
+ * @returns {number}
772
+ */
773
+ export function cosine_similarity(a, b) {
774
+ try {
775
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
776
+ const ptr0 = passArrayF32ToWasm0(a, wasm.__wbindgen_export);
777
+ const len0 = WASM_VECTOR_LEN;
778
+ const ptr1 = passArrayF32ToWasm0(b, wasm.__wbindgen_export);
779
+ const len1 = WASM_VECTOR_LEN;
780
+ wasm.cosine_similarity(retptr, ptr0, len0, ptr1, len1);
781
+ var r0 = getDataViewMemory0().getFloat32(retptr + 4 * 0, true);
782
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
783
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
784
+ if (r2) {
785
+ throw takeObject(r1);
786
+ }
787
+ return r0;
788
+ } finally {
789
+ wasm.__wbindgen_add_to_stack_pointer(16);
790
+ }
791
+ }
792
+
793
+ /**
794
+ * Initialize the WASM module with panic hook
795
+ */
796
+ export function init() {
797
+ wasm.init();
798
+ }
799
+
800
+ /**
801
+ * Compute L2 norm of a vector
802
+ * @param {Float32Array} vec
803
+ * @returns {number}
804
+ */
805
+ export function l2_norm(vec) {
806
+ const ptr0 = passArrayF32ToWasm0(vec, wasm.__wbindgen_export);
807
+ const len0 = WASM_VECTOR_LEN;
808
+ const ret = wasm.l2_norm(ptr0, len0);
809
+ return ret;
810
+ }
811
+
812
+ /**
813
+ * Log a message to the browser console
814
+ * @param {string} message
815
+ */
816
+ export function log(message) {
817
+ const ptr0 = passStringToWasm0(message, wasm.__wbindgen_export, wasm.__wbindgen_export2);
818
+ const len0 = WASM_VECTOR_LEN;
819
+ wasm.log(ptr0, len0);
820
+ }
821
+
822
+ /**
823
+ * Log an error to the browser console
824
+ * @param {string} message
825
+ */
826
+ export function log_error(message) {
827
+ const ptr0 = passStringToWasm0(message, wasm.__wbindgen_export, wasm.__wbindgen_export2);
828
+ const len0 = WASM_VECTOR_LEN;
829
+ wasm.log_error(ptr0, len0);
830
+ }
831
+
832
+ /**
833
+ * Normalize a vector to unit length
834
+ * @param {Float32Array} vec
835
+ */
836
+ export function normalize(vec) {
837
+ try {
838
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
839
+ var ptr0 = passArrayF32ToWasm0(vec, wasm.__wbindgen_export);
840
+ var len0 = WASM_VECTOR_LEN;
841
+ wasm.normalize(retptr, ptr0, len0, addHeapObject(vec));
842
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
843
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
844
+ if (r1) {
845
+ throw takeObject(r0);
846
+ }
847
+ } finally {
848
+ wasm.__wbindgen_add_to_stack_pointer(16);
849
+ }
850
+ }
851
+
852
+ /**
853
+ * Compute pairwise distances between vectors
854
+ * @param {any} vectors
855
+ * @returns {Float32Array}
856
+ */
857
+ export function pairwise_distances(vectors) {
858
+ try {
859
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
860
+ wasm.pairwise_distances(retptr, addHeapObject(vectors));
861
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
862
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
863
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
864
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
865
+ if (r3) {
866
+ throw takeObject(r2);
867
+ }
868
+ var v1 = getArrayF32FromWasm0(r0, r1).slice();
869
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
870
+ return v1;
871
+ } finally {
872
+ wasm.__wbindgen_add_to_stack_pointer(16);
873
+ }
874
+ }
875
+
876
+ /**
877
+ * Generate random orthogonal matrix (for initialization)
878
+ * @param {number} dim
879
+ * @returns {Float32Array}
880
+ */
881
+ export function random_orthogonal_matrix(dim) {
882
+ try {
883
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
884
+ wasm.random_orthogonal_matrix(retptr, dim);
885
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
886
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
887
+ var v1 = getArrayF32FromWasm0(r0, r1).slice();
888
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
889
+ return v1;
890
+ } finally {
891
+ wasm.__wbindgen_add_to_stack_pointer(16);
892
+ }
893
+ }
894
+
895
+ /**
896
+ * Compute scaled dot-product attention
897
+ *
898
+ * # Arguments
899
+ * * `query` - Query vector as Float32Array
900
+ * * `keys` - Array of key vectors
901
+ * * `values` - Array of value vectors
902
+ * * `scale` - Optional scaling factor (defaults to 1/sqrt(dim))
903
+ * @param {Float32Array} query
904
+ * @param {any} keys
905
+ * @param {any} values
906
+ * @param {number | null} [scale]
907
+ * @returns {Float32Array}
908
+ */
909
+ export function scaled_dot_attention(query, keys, values, scale) {
1010
910
  try {
1011
911
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1012
- wasm.batch_normalize(retptr, addHeapObject(vectors), isLikeNone(epsilon) ? 0x100000001 : Math.fround(epsilon));
912
+ const ptr0 = passArrayF32ToWasm0(query, wasm.__wbindgen_export);
913
+ const len0 = WASM_VECTOR_LEN;
914
+ wasm.scaled_dot_attention(retptr, ptr0, len0, addHeapObject(keys), addHeapObject(values), isLikeNone(scale) ? 0x100000001 : Math.fround(scale));
1013
915
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1014
916
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1015
917
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -1017,209 +919,490 @@ export function batch_normalize(vectors, epsilon) {
1017
919
  if (r3) {
1018
920
  throw takeObject(r2);
1019
921
  }
1020
- var v1 = getArrayF32FromWasm0(r0, r1).slice();
922
+ var v2 = getArrayF32FromWasm0(r0, r1).slice();
1021
923
  wasm.__wbindgen_export4(r0, r1 * 4, 4);
1022
- return v1;
924
+ return v2;
1023
925
  } finally {
1024
926
  wasm.__wbindgen_add_to_stack_pointer(16);
1025
927
  }
1026
928
  }
1027
929
 
1028
930
  /**
1029
- * Compute cosine similarity between two vectors
1030
- * @param {Float32Array} a
1031
- * @param {Float32Array} b
1032
- * @returns {number}
931
+ * Compute softmax of a vector
932
+ * @param {Float32Array} vec
1033
933
  */
1034
- export function cosine_similarity(a, b) {
934
+ export function softmax(vec) {
935
+ var ptr0 = passArrayF32ToWasm0(vec, wasm.__wbindgen_export);
936
+ var len0 = WASM_VECTOR_LEN;
937
+ wasm.softmax(ptr0, len0, addHeapObject(vec));
938
+ }
939
+
940
+ /**
941
+ * Get the version of the ruvector-attention-wasm crate
942
+ * @returns {string}
943
+ */
944
+ export function version() {
945
+ let deferred1_0;
946
+ let deferred1_1;
1035
947
  try {
1036
948
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1037
- const ptr0 = passArrayF32ToWasm0(a, wasm.__wbindgen_export);
1038
- const len0 = WASM_VECTOR_LEN;
1039
- const ptr1 = passArrayF32ToWasm0(b, wasm.__wbindgen_export);
1040
- const len1 = WASM_VECTOR_LEN;
1041
- wasm.cosine_similarity(retptr, ptr0, len0, ptr1, len1);
1042
- var r0 = getDataViewMemory0().getFloat32(retptr + 4 * 0, true);
949
+ wasm.version(retptr);
950
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1043
951
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1044
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1045
- if (r2) {
1046
- throw takeObject(r1);
1047
- }
1048
- return r0;
952
+ deferred1_0 = r0;
953
+ deferred1_1 = r1;
954
+ return getStringFromWasm0(r0, r1);
1049
955
  } finally {
1050
956
  wasm.__wbindgen_add_to_stack_pointer(16);
957
+ wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
1051
958
  }
1052
959
  }
1053
960
 
1054
- /**
1055
- * Initialize the WASM module with panic hook
1056
- */
1057
- export function init() {
1058
- wasm.init();
961
+ function __wbg_get_imports() {
962
+ const import0 = {
963
+ __proto__: null,
964
+ __wbg_Error_4577686b3a6d9b3a: function(arg0, arg1) {
965
+ const ret = Error(getStringFromWasm0(arg0, arg1));
966
+ return addHeapObject(ret);
967
+ },
968
+ __wbg_String_8564e559799eccda: function(arg0, arg1) {
969
+ const ret = String(getObject(arg1));
970
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
971
+ const len1 = WASM_VECTOR_LEN;
972
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
973
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
974
+ },
975
+ __wbg___wbindgen_boolean_get_18c4ed9422296fff: function(arg0) {
976
+ const v = getObject(arg0);
977
+ const ret = typeof(v) === 'boolean' ? v : undefined;
978
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
979
+ },
980
+ __wbg___wbindgen_copy_to_typed_array_5294f8e46aecc086: function(arg0, arg1, arg2) {
981
+ new Uint8Array(getObject(arg2).buffer, getObject(arg2).byteOffset, getObject(arg2).byteLength).set(getArrayU8FromWasm0(arg0, arg1));
982
+ },
983
+ __wbg___wbindgen_debug_string_ddde1867f49c2442: function(arg0, arg1) {
984
+ const ret = debugString(getObject(arg1));
985
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
986
+ const len1 = WASM_VECTOR_LEN;
987
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
988
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
989
+ },
990
+ __wbg___wbindgen_is_function_d633e708baf0d146: function(arg0) {
991
+ const ret = typeof(getObject(arg0)) === 'function';
992
+ return ret;
993
+ },
994
+ __wbg___wbindgen_is_object_4b3de556756ee8a8: function(arg0) {
995
+ const val = getObject(arg0);
996
+ const ret = typeof(val) === 'object' && val !== null;
997
+ return ret;
998
+ },
999
+ __wbg___wbindgen_jsval_loose_eq_1562ceb9af84e990: function(arg0, arg1) {
1000
+ const ret = getObject(arg0) == getObject(arg1);
1001
+ return ret;
1002
+ },
1003
+ __wbg___wbindgen_number_get_5854912275df1894: function(arg0, arg1) {
1004
+ const obj = getObject(arg1);
1005
+ const ret = typeof(obj) === 'number' ? obj : undefined;
1006
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
1007
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
1008
+ },
1009
+ __wbg___wbindgen_string_get_3e5751597f39a112: function(arg0, arg1) {
1010
+ const obj = getObject(arg1);
1011
+ const ret = typeof(obj) === 'string' ? obj : undefined;
1012
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1013
+ var len1 = WASM_VECTOR_LEN;
1014
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1015
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1016
+ },
1017
+ __wbg___wbindgen_throw_39bc967c0e5a9b58: function(arg0, arg1) {
1018
+ throw new Error(getStringFromWasm0(arg0, arg1));
1019
+ },
1020
+ __wbg_call_73af281463ec8b58: function() { return handleError(function (arg0, arg1) {
1021
+ const ret = getObject(arg0).call(getObject(arg1));
1022
+ return addHeapObject(ret);
1023
+ }, arguments); },
1024
+ __wbg_done_5aad55ec6b1954b1: function(arg0) {
1025
+ const ret = getObject(arg0).done;
1026
+ return ret;
1027
+ },
1028
+ __wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
1029
+ let deferred0_0;
1030
+ let deferred0_1;
1031
+ try {
1032
+ deferred0_0 = arg0;
1033
+ deferred0_1 = arg1;
1034
+ console.error(getStringFromWasm0(arg0, arg1));
1035
+ } finally {
1036
+ wasm.__wbindgen_export4(deferred0_0, deferred0_1, 1);
1037
+ }
1038
+ },
1039
+ __wbg_error_ad28debb48b5c6bb: function(arg0) {
1040
+ console.error(getObject(arg0));
1041
+ },
1042
+ __wbg_get_4920fefd3451364b: function() { return handleError(function (arg0, arg1) {
1043
+ const ret = Reflect.get(getObject(arg0), getObject(arg1));
1044
+ return addHeapObject(ret);
1045
+ }, arguments); },
1046
+ __wbg_get_unchecked_3d0f4b91c8eca4f0: function(arg0, arg1) {
1047
+ const ret = getObject(arg0)[arg1 >>> 0];
1048
+ return addHeapObject(ret);
1049
+ },
1050
+ __wbg_instanceof_ArrayBuffer_15859862b80b732d: function(arg0) {
1051
+ let result;
1052
+ try {
1053
+ result = getObject(arg0) instanceof ArrayBuffer;
1054
+ } catch (_) {
1055
+ result = false;
1056
+ }
1057
+ const ret = result;
1058
+ return ret;
1059
+ },
1060
+ __wbg_instanceof_Uint8Array_2240b7046ac16f05: function(arg0) {
1061
+ let result;
1062
+ try {
1063
+ result = getObject(arg0) instanceof Uint8Array;
1064
+ } catch (_) {
1065
+ result = false;
1066
+ }
1067
+ const ret = result;
1068
+ return ret;
1069
+ },
1070
+ __wbg_isArray_fad08a0d12828686: function(arg0) {
1071
+ const ret = Array.isArray(getObject(arg0));
1072
+ return ret;
1073
+ },
1074
+ __wbg_iterator_fc7ad8d33bab9e26: function() {
1075
+ const ret = Symbol.iterator;
1076
+ return addHeapObject(ret);
1077
+ },
1078
+ __wbg_length_5855c1f289dfffc1: function(arg0) {
1079
+ const ret = getObject(arg0).length;
1080
+ return ret;
1081
+ },
1082
+ __wbg_length_a31e05262e09b7f8: function(arg0) {
1083
+ const ret = getObject(arg0).length;
1084
+ return ret;
1085
+ },
1086
+ __wbg_log_3c5e4b64af29e724: function(arg0) {
1087
+ console.log(getObject(arg0));
1088
+ },
1089
+ __wbg_new_09959f7b4c92c246: function(arg0) {
1090
+ const ret = new Uint8Array(getObject(arg0));
1091
+ return addHeapObject(ret);
1092
+ },
1093
+ __wbg_new_227d7c05414eb861: function() {
1094
+ const ret = new Error();
1095
+ return addHeapObject(ret);
1096
+ },
1097
+ __wbg_new_cbee8c0d5c479eac: function() {
1098
+ const ret = new Array();
1099
+ return addHeapObject(ret);
1100
+ },
1101
+ __wbg_next_a5fe6f328f7affc2: function(arg0) {
1102
+ const ret = getObject(arg0).next;
1103
+ return addHeapObject(ret);
1104
+ },
1105
+ __wbg_next_e592122bb4ed4c67: function() { return handleError(function (arg0) {
1106
+ const ret = getObject(arg0).next();
1107
+ return addHeapObject(ret);
1108
+ }, arguments); },
1109
+ __wbg_prototypesetcall_f034d444741426c3: function(arg0, arg1, arg2) {
1110
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
1111
+ },
1112
+ __wbg_random_2b7bed8995d680fb: function() {
1113
+ const ret = Math.random();
1114
+ return ret;
1115
+ },
1116
+ __wbg_set_4c81cfb5dc3a333c: function(arg0, arg1, arg2) {
1117
+ getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
1118
+ },
1119
+ __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
1120
+ const ret = getObject(arg1).stack;
1121
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1122
+ const len1 = WASM_VECTOR_LEN;
1123
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1124
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1125
+ },
1126
+ __wbg_value_667dcb90597486a6: function(arg0) {
1127
+ const ret = getObject(arg0).value;
1128
+ return addHeapObject(ret);
1129
+ },
1130
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
1131
+ // Cast intrinsic for `Ref(String) -> Externref`.
1132
+ const ret = getStringFromWasm0(arg0, arg1);
1133
+ return addHeapObject(ret);
1134
+ },
1135
+ __wbindgen_object_drop_ref: function(arg0) {
1136
+ takeObject(arg0);
1137
+ },
1138
+ };
1139
+ return {
1140
+ __proto__: null,
1141
+ "./ruvector_attention_wasm_bg.js": import0,
1142
+ };
1059
1143
  }
1060
1144
 
1061
- /**
1062
- * Compute L2 norm of a vector
1063
- * @param {Float32Array} vec
1064
- * @returns {number}
1065
- */
1066
- export function l2_norm(vec) {
1067
- const ptr0 = passArrayF32ToWasm0(vec, wasm.__wbindgen_export);
1068
- const len0 = WASM_VECTOR_LEN;
1069
- const ret = wasm.l2_norm(ptr0, len0);
1070
- return ret;
1145
+ const WasmAdamFinalization = (typeof FinalizationRegistry === 'undefined')
1146
+ ? { register: () => {}, unregister: () => {} }
1147
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmadam_free(ptr >>> 0, 1));
1148
+ const WasmAdamWFinalization = (typeof FinalizationRegistry === 'undefined')
1149
+ ? { register: () => {}, unregister: () => {} }
1150
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmadamw_free(ptr >>> 0, 1));
1151
+ const WasmFlashAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
1152
+ ? { register: () => {}, unregister: () => {} }
1153
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmflashattention_free(ptr >>> 0, 1));
1154
+ const WasmHyperbolicAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
1155
+ ? { register: () => {}, unregister: () => {} }
1156
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmhyperbolicattention_free(ptr >>> 0, 1));
1157
+ const WasmInfoNCELossFinalization = (typeof FinalizationRegistry === 'undefined')
1158
+ ? { register: () => {}, unregister: () => {} }
1159
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasminfonceloss_free(ptr >>> 0, 1));
1160
+ const WasmLRSchedulerFinalization = (typeof FinalizationRegistry === 'undefined')
1161
+ ? { register: () => {}, unregister: () => {} }
1162
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmlrscheduler_free(ptr >>> 0, 1));
1163
+ const WasmLinearAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
1164
+ ? { register: () => {}, unregister: () => {} }
1165
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmlinearattention_free(ptr >>> 0, 1));
1166
+ const WasmLocalGlobalAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
1167
+ ? { register: () => {}, unregister: () => {} }
1168
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmlocalglobalattention_free(ptr >>> 0, 1));
1169
+ const WasmMoEAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
1170
+ ? { register: () => {}, unregister: () => {} }
1171
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmmoeattention_free(ptr >>> 0, 1));
1172
+ const WasmMultiHeadAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
1173
+ ? { register: () => {}, unregister: () => {} }
1174
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmmultiheadattention_free(ptr >>> 0, 1));
1175
+ const WasmSGDFinalization = (typeof FinalizationRegistry === 'undefined')
1176
+ ? { register: () => {}, unregister: () => {} }
1177
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmsgd_free(ptr >>> 0, 1));
1178
+
1179
+ function addHeapObject(obj) {
1180
+ if (heap_next === heap.length) heap.push(heap.length + 1);
1181
+ const idx = heap_next;
1182
+ heap_next = heap[idx];
1183
+
1184
+ heap[idx] = obj;
1185
+ return idx;
1071
1186
  }
1072
1187
 
1073
- /**
1074
- * Log a message to the browser console
1075
- * @param {string} message
1076
- */
1077
- export function log(message) {
1078
- const ptr0 = passStringToWasm0(message, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1079
- const len0 = WASM_VECTOR_LEN;
1080
- wasm.log(ptr0, len0);
1188
+ function debugString(val) {
1189
+ // primitive types
1190
+ const type = typeof val;
1191
+ if (type == 'number' || type == 'boolean' || val == null) {
1192
+ return `${val}`;
1193
+ }
1194
+ if (type == 'string') {
1195
+ return `"${val}"`;
1196
+ }
1197
+ if (type == 'symbol') {
1198
+ const description = val.description;
1199
+ if (description == null) {
1200
+ return 'Symbol';
1201
+ } else {
1202
+ return `Symbol(${description})`;
1203
+ }
1204
+ }
1205
+ if (type == 'function') {
1206
+ const name = val.name;
1207
+ if (typeof name == 'string' && name.length > 0) {
1208
+ return `Function(${name})`;
1209
+ } else {
1210
+ return 'Function';
1211
+ }
1212
+ }
1213
+ // objects
1214
+ if (Array.isArray(val)) {
1215
+ const length = val.length;
1216
+ let debug = '[';
1217
+ if (length > 0) {
1218
+ debug += debugString(val[0]);
1219
+ }
1220
+ for(let i = 1; i < length; i++) {
1221
+ debug += ', ' + debugString(val[i]);
1222
+ }
1223
+ debug += ']';
1224
+ return debug;
1225
+ }
1226
+ // Test for built-in
1227
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
1228
+ let className;
1229
+ if (builtInMatches && builtInMatches.length > 1) {
1230
+ className = builtInMatches[1];
1231
+ } else {
1232
+ // Failed to match the standard '[object ClassName]'
1233
+ return toString.call(val);
1234
+ }
1235
+ if (className == 'Object') {
1236
+ // we're a user defined class or Object
1237
+ // JSON.stringify avoids problems with cycles, and is generally much
1238
+ // easier than looping through ownProperties of `val`.
1239
+ try {
1240
+ return 'Object(' + JSON.stringify(val) + ')';
1241
+ } catch (_) {
1242
+ return 'Object';
1243
+ }
1244
+ }
1245
+ // errors
1246
+ if (val instanceof Error) {
1247
+ return `${val.name}: ${val.message}\n${val.stack}`;
1248
+ }
1249
+ // TODO we could test for more things here, like `Set`s and `Map`s.
1250
+ return className;
1081
1251
  }
1082
1252
 
1083
- /**
1084
- * Log an error to the browser console
1085
- * @param {string} message
1086
- */
1087
- export function log_error(message) {
1088
- const ptr0 = passStringToWasm0(message, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1089
- const len0 = WASM_VECTOR_LEN;
1090
- wasm.log_error(ptr0, len0);
1253
+ function dropObject(idx) {
1254
+ if (idx < 1028) return;
1255
+ heap[idx] = heap_next;
1256
+ heap_next = idx;
1091
1257
  }
1092
1258
 
1093
- /**
1094
- * Normalize a vector to unit length
1095
- * @param {Float32Array} vec
1096
- */
1097
- export function normalize(vec) {
1098
- try {
1099
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1100
- var ptr0 = passArrayF32ToWasm0(vec, wasm.__wbindgen_export);
1101
- var len0 = WASM_VECTOR_LEN;
1102
- wasm.normalize(retptr, ptr0, len0, addHeapObject(vec));
1103
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1104
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1105
- if (r1) {
1106
- throw takeObject(r0);
1107
- }
1108
- } finally {
1109
- wasm.__wbindgen_add_to_stack_pointer(16);
1259
+ function getArrayF32FromWasm0(ptr, len) {
1260
+ ptr = ptr >>> 0;
1261
+ return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
1262
+ }
1263
+
1264
+ function getArrayU8FromWasm0(ptr, len) {
1265
+ ptr = ptr >>> 0;
1266
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
1267
+ }
1268
+
1269
+ let cachedDataViewMemory0 = null;
1270
+ function getDataViewMemory0() {
1271
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
1272
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
1273
+ }
1274
+ return cachedDataViewMemory0;
1275
+ }
1276
+
1277
+ let cachedFloat32ArrayMemory0 = null;
1278
+ function getFloat32ArrayMemory0() {
1279
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
1280
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
1281
+ }
1282
+ return cachedFloat32ArrayMemory0;
1283
+ }
1284
+
1285
+ function getStringFromWasm0(ptr, len) {
1286
+ ptr = ptr >>> 0;
1287
+ return decodeText(ptr, len);
1288
+ }
1289
+
1290
+ let cachedUint8ArrayMemory0 = null;
1291
+ function getUint8ArrayMemory0() {
1292
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
1293
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
1110
1294
  }
1295
+ return cachedUint8ArrayMemory0;
1111
1296
  }
1112
1297
 
1113
- /**
1114
- * Compute pairwise distances between vectors
1115
- * @param {any} vectors
1116
- * @returns {Float32Array}
1117
- */
1118
- export function pairwise_distances(vectors) {
1298
+ function getObject(idx) { return heap[idx]; }
1299
+
1300
+ function handleError(f, args) {
1119
1301
  try {
1120
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1121
- wasm.pairwise_distances(retptr, addHeapObject(vectors));
1122
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1123
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1124
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1125
- var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1126
- if (r3) {
1127
- throw takeObject(r2);
1128
- }
1129
- var v1 = getArrayF32FromWasm0(r0, r1).slice();
1130
- wasm.__wbindgen_export4(r0, r1 * 4, 4);
1131
- return v1;
1132
- } finally {
1133
- wasm.__wbindgen_add_to_stack_pointer(16);
1302
+ return f.apply(this, args);
1303
+ } catch (e) {
1304
+ wasm.__wbindgen_export3(addHeapObject(e));
1134
1305
  }
1135
1306
  }
1136
1307
 
1137
- /**
1138
- * Generate random orthogonal matrix (for initialization)
1139
- * @param {number} dim
1140
- * @returns {Float32Array}
1141
- */
1142
- export function random_orthogonal_matrix(dim) {
1143
- try {
1144
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1145
- wasm.random_orthogonal_matrix(retptr, dim);
1146
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1147
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1148
- var v1 = getArrayF32FromWasm0(r0, r1).slice();
1149
- wasm.__wbindgen_export4(r0, r1 * 4, 4);
1150
- return v1;
1151
- } finally {
1152
- wasm.__wbindgen_add_to_stack_pointer(16);
1153
- }
1308
+ let heap = new Array(1024).fill(undefined);
1309
+ heap.push(undefined, null, true, false);
1310
+
1311
+ let heap_next = heap.length;
1312
+
1313
+ function isLikeNone(x) {
1314
+ return x === undefined || x === null;
1154
1315
  }
1155
1316
 
1156
- /**
1157
- * Compute scaled dot-product attention
1158
- *
1159
- * # Arguments
1160
- * * `query` - Query vector as Float32Array
1161
- * * `keys` - Array of key vectors
1162
- * * `values` - Array of value vectors
1163
- * * `scale` - Optional scaling factor (defaults to 1/sqrt(dim))
1164
- * @param {Float32Array} query
1165
- * @param {any} keys
1166
- * @param {any} values
1167
- * @param {number | null} [scale]
1168
- * @returns {Float32Array}
1169
- */
1170
- export function scaled_dot_attention(query, keys, values, scale) {
1171
- try {
1172
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1173
- const ptr0 = passArrayF32ToWasm0(query, wasm.__wbindgen_export);
1174
- const len0 = WASM_VECTOR_LEN;
1175
- wasm.scaled_dot_attention(retptr, ptr0, len0, addHeapObject(keys), addHeapObject(values), isLikeNone(scale) ? 0x100000001 : Math.fround(scale));
1176
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1177
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1178
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1179
- var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1180
- if (r3) {
1181
- throw takeObject(r2);
1317
+ function passArrayF32ToWasm0(arg, malloc) {
1318
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
1319
+ getFloat32ArrayMemory0().set(arg, ptr / 4);
1320
+ WASM_VECTOR_LEN = arg.length;
1321
+ return ptr;
1322
+ }
1323
+
1324
+ function passStringToWasm0(arg, malloc, realloc) {
1325
+ if (realloc === undefined) {
1326
+ const buf = cachedTextEncoder.encode(arg);
1327
+ const ptr = malloc(buf.length, 1) >>> 0;
1328
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
1329
+ WASM_VECTOR_LEN = buf.length;
1330
+ return ptr;
1331
+ }
1332
+
1333
+ let len = arg.length;
1334
+ let ptr = malloc(len, 1) >>> 0;
1335
+
1336
+ const mem = getUint8ArrayMemory0();
1337
+
1338
+ let offset = 0;
1339
+
1340
+ for (; offset < len; offset++) {
1341
+ const code = arg.charCodeAt(offset);
1342
+ if (code > 0x7F) break;
1343
+ mem[ptr + offset] = code;
1344
+ }
1345
+ if (offset !== len) {
1346
+ if (offset !== 0) {
1347
+ arg = arg.slice(offset);
1182
1348
  }
1183
- var v2 = getArrayF32FromWasm0(r0, r1).slice();
1184
- wasm.__wbindgen_export4(r0, r1 * 4, 4);
1185
- return v2;
1186
- } finally {
1187
- wasm.__wbindgen_add_to_stack_pointer(16);
1349
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
1350
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
1351
+ const ret = cachedTextEncoder.encodeInto(arg, view);
1352
+
1353
+ offset += ret.written;
1354
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
1188
1355
  }
1356
+
1357
+ WASM_VECTOR_LEN = offset;
1358
+ return ptr;
1189
1359
  }
1190
1360
 
1191
- /**
1192
- * Compute softmax of a vector
1193
- * @param {Float32Array} vec
1194
- */
1195
- export function softmax(vec) {
1196
- var ptr0 = passArrayF32ToWasm0(vec, wasm.__wbindgen_export);
1197
- var len0 = WASM_VECTOR_LEN;
1198
- wasm.softmax(ptr0, len0, addHeapObject(vec));
1361
+ function takeObject(idx) {
1362
+ const ret = getObject(idx);
1363
+ dropObject(idx);
1364
+ return ret;
1199
1365
  }
1200
1366
 
1201
- /**
1202
- * Get the version of the ruvector-attention-wasm crate
1203
- * @returns {string}
1204
- */
1205
- export function version() {
1206
- let deferred1_0;
1207
- let deferred1_1;
1208
- try {
1209
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1210
- wasm.version(retptr);
1211
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1212
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1213
- deferred1_0 = r0;
1214
- deferred1_1 = r1;
1215
- return getStringFromWasm0(r0, r1);
1216
- } finally {
1217
- wasm.__wbindgen_add_to_stack_pointer(16);
1218
- wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
1367
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
1368
+ cachedTextDecoder.decode();
1369
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
1370
+ let numBytesDecoded = 0;
1371
+ function decodeText(ptr, len) {
1372
+ numBytesDecoded += len;
1373
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
1374
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
1375
+ cachedTextDecoder.decode();
1376
+ numBytesDecoded = len;
1219
1377
  }
1378
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
1379
+ }
1380
+
1381
+ const cachedTextEncoder = new TextEncoder();
1382
+
1383
+ if (!('encodeInto' in cachedTextEncoder)) {
1384
+ cachedTextEncoder.encodeInto = function (arg, view) {
1385
+ const buf = cachedTextEncoder.encode(arg);
1386
+ view.set(buf);
1387
+ return {
1388
+ read: arg.length,
1389
+ written: buf.length
1390
+ };
1391
+ };
1220
1392
  }
1221
1393
 
1222
- const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
1394
+ let WASM_VECTOR_LEN = 0;
1395
+
1396
+ let wasmModule, wasm;
1397
+ function __wbg_finalize_init(instance, module) {
1398
+ wasm = instance.exports;
1399
+ wasmModule = module;
1400
+ cachedDataViewMemory0 = null;
1401
+ cachedFloat32ArrayMemory0 = null;
1402
+ cachedUint8ArrayMemory0 = null;
1403
+ wasm.__wbindgen_start();
1404
+ return wasm;
1405
+ }
1223
1406
 
1224
1407
  async function __wbg_load(module, imports) {
1225
1408
  if (typeof Response === 'function' && module instanceof Response) {
@@ -1227,14 +1410,12 @@ async function __wbg_load(module, imports) {
1227
1410
  try {
1228
1411
  return await WebAssembly.instantiateStreaming(module, imports);
1229
1412
  } catch (e) {
1230
- const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
1413
+ const validResponse = module.ok && expectedResponseType(module.type);
1231
1414
 
1232
1415
  if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
1233
1416
  console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
1234
1417
 
1235
- } else {
1236
- throw e;
1237
- }
1418
+ } else { throw e; }
1238
1419
  }
1239
1420
  }
1240
1421
 
@@ -1249,206 +1430,20 @@ async function __wbg_load(module, imports) {
1249
1430
  return instance;
1250
1431
  }
1251
1432
  }
1252
- }
1253
1433
 
1254
- function __wbg_get_imports() {
1255
- const imports = {};
1256
- imports.wbg = {};
1257
- imports.wbg.__wbg_Error_52673b7de5a0ca89 = function(arg0, arg1) {
1258
- const ret = Error(getStringFromWasm0(arg0, arg1));
1259
- return addHeapObject(ret);
1260
- };
1261
- imports.wbg.__wbg_String_8f0eb39a4a4c2f66 = function(arg0, arg1) {
1262
- const ret = String(getObject(arg1));
1263
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1264
- const len1 = WASM_VECTOR_LEN;
1265
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1266
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1267
- };
1268
- imports.wbg.__wbg___wbindgen_boolean_get_dea25b33882b895b = function(arg0) {
1269
- const v = getObject(arg0);
1270
- const ret = typeof(v) === 'boolean' ? v : undefined;
1271
- return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
1272
- };
1273
- imports.wbg.__wbg___wbindgen_copy_to_typed_array_db832bc4df7216c1 = function(arg0, arg1, arg2) {
1274
- new Uint8Array(getObject(arg2).buffer, getObject(arg2).byteOffset, getObject(arg2).byteLength).set(getArrayU8FromWasm0(arg0, arg1));
1275
- };
1276
- imports.wbg.__wbg___wbindgen_debug_string_adfb662ae34724b6 = function(arg0, arg1) {
1277
- const ret = debugString(getObject(arg1));
1278
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1279
- const len1 = WASM_VECTOR_LEN;
1280
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1281
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1282
- };
1283
- imports.wbg.__wbg___wbindgen_is_function_8d400b8b1af978cd = function(arg0) {
1284
- const ret = typeof(getObject(arg0)) === 'function';
1285
- return ret;
1286
- };
1287
- imports.wbg.__wbg___wbindgen_is_object_ce774f3490692386 = function(arg0) {
1288
- const val = getObject(arg0);
1289
- const ret = typeof(val) === 'object' && val !== null;
1290
- return ret;
1291
- };
1292
- imports.wbg.__wbg___wbindgen_jsval_loose_eq_766057600fdd1b0d = function(arg0, arg1) {
1293
- const ret = getObject(arg0) == getObject(arg1);
1294
- return ret;
1295
- };
1296
- imports.wbg.__wbg___wbindgen_number_get_9619185a74197f95 = function(arg0, arg1) {
1297
- const obj = getObject(arg1);
1298
- const ret = typeof(obj) === 'number' ? obj : undefined;
1299
- getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
1300
- getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
1301
- };
1302
- imports.wbg.__wbg___wbindgen_string_get_a2a31e16edf96e42 = function(arg0, arg1) {
1303
- const obj = getObject(arg1);
1304
- const ret = typeof(obj) === 'string' ? obj : undefined;
1305
- var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1306
- var len1 = WASM_VECTOR_LEN;
1307
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1308
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1309
- };
1310
- imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
1311
- throw new Error(getStringFromWasm0(arg0, arg1));
1312
- };
1313
- imports.wbg.__wbg_call_abb4ff46ce38be40 = function() { return handleError(function (arg0, arg1) {
1314
- const ret = getObject(arg0).call(getObject(arg1));
1315
- return addHeapObject(ret);
1316
- }, arguments) };
1317
- imports.wbg.__wbg_done_62ea16af4ce34b24 = function(arg0) {
1318
- const ret = getObject(arg0).done;
1319
- return ret;
1320
- };
1321
- imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
1322
- let deferred0_0;
1323
- let deferred0_1;
1324
- try {
1325
- deferred0_0 = arg0;
1326
- deferred0_1 = arg1;
1327
- console.error(getStringFromWasm0(arg0, arg1));
1328
- } finally {
1329
- wasm.__wbindgen_export4(deferred0_0, deferred0_1, 1);
1330
- }
1331
- };
1332
- imports.wbg.__wbg_error_7bc7d576a6aaf855 = function(arg0) {
1333
- console.error(getObject(arg0));
1334
- };
1335
- imports.wbg.__wbg_get_6b7bd52aca3f9671 = function(arg0, arg1) {
1336
- const ret = getObject(arg0)[arg1 >>> 0];
1337
- return addHeapObject(ret);
1338
- };
1339
- imports.wbg.__wbg_get_af9dab7e9603ea93 = function() { return handleError(function (arg0, arg1) {
1340
- const ret = Reflect.get(getObject(arg0), getObject(arg1));
1341
- return addHeapObject(ret);
1342
- }, arguments) };
1343
- imports.wbg.__wbg_instanceof_ArrayBuffer_f3320d2419cd0355 = function(arg0) {
1344
- let result;
1345
- try {
1346
- result = getObject(arg0) instanceof ArrayBuffer;
1347
- } catch (_) {
1348
- result = false;
1349
- }
1350
- const ret = result;
1351
- return ret;
1352
- };
1353
- imports.wbg.__wbg_instanceof_Uint8Array_da54ccc9d3e09434 = function(arg0) {
1354
- let result;
1355
- try {
1356
- result = getObject(arg0) instanceof Uint8Array;
1357
- } catch (_) {
1358
- result = false;
1434
+ function expectedResponseType(type) {
1435
+ switch (type) {
1436
+ case 'basic': case 'cors': case 'default': return true;
1359
1437
  }
1360
- const ret = result;
1361
- return ret;
1362
- };
1363
- imports.wbg.__wbg_isArray_51fd9e6422c0a395 = function(arg0) {
1364
- const ret = Array.isArray(getObject(arg0));
1365
- return ret;
1366
- };
1367
- imports.wbg.__wbg_iterator_27b7c8b35ab3e86b = function() {
1368
- const ret = Symbol.iterator;
1369
- return addHeapObject(ret);
1370
- };
1371
- imports.wbg.__wbg_length_22ac23eaec9d8053 = function(arg0) {
1372
- const ret = getObject(arg0).length;
1373
- return ret;
1374
- };
1375
- imports.wbg.__wbg_length_d45040a40c570362 = function(arg0) {
1376
- const ret = getObject(arg0).length;
1377
- return ret;
1378
- };
1379
- imports.wbg.__wbg_log_1d990106d99dacb7 = function(arg0) {
1380
- console.log(getObject(arg0));
1381
- };
1382
- imports.wbg.__wbg_new_25f239778d6112b9 = function() {
1383
- const ret = new Array();
1384
- return addHeapObject(ret);
1385
- };
1386
- imports.wbg.__wbg_new_6421f6084cc5bc5a = function(arg0) {
1387
- const ret = new Uint8Array(getObject(arg0));
1388
- return addHeapObject(ret);
1389
- };
1390
- imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
1391
- const ret = new Error();
1392
- return addHeapObject(ret);
1393
- };
1394
- imports.wbg.__wbg_next_138a17bbf04e926c = function(arg0) {
1395
- const ret = getObject(arg0).next;
1396
- return addHeapObject(ret);
1397
- };
1398
- imports.wbg.__wbg_next_3cfe5c0fe2a4cc53 = function() { return handleError(function (arg0) {
1399
- const ret = getObject(arg0).next();
1400
- return addHeapObject(ret);
1401
- }, arguments) };
1402
- imports.wbg.__wbg_prototypesetcall_dfe9b766cdc1f1fd = function(arg0, arg1, arg2) {
1403
- Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
1404
- };
1405
- imports.wbg.__wbg_random_cc1f9237d866d212 = function() {
1406
- const ret = Math.random();
1407
- return ret;
1408
- };
1409
- imports.wbg.__wbg_set_7df433eea03a5c14 = function(arg0, arg1, arg2) {
1410
- getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
1411
- };
1412
- imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
1413
- const ret = getObject(arg1).stack;
1414
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1415
- const len1 = WASM_VECTOR_LEN;
1416
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1417
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1418
- };
1419
- imports.wbg.__wbg_value_57b7b035e117f7ee = function(arg0) {
1420
- const ret = getObject(arg0).value;
1421
- return addHeapObject(ret);
1422
- };
1423
- imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
1424
- // Cast intrinsic for `Ref(String) -> Externref`.
1425
- const ret = getStringFromWasm0(arg0, arg1);
1426
- return addHeapObject(ret);
1427
- };
1428
- imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
1429
- takeObject(arg0);
1430
- };
1431
-
1432
- return imports;
1433
- }
1434
-
1435
- function __wbg_finalize_init(instance, module) {
1436
- wasm = instance.exports;
1437
- __wbg_init.__wbindgen_wasm_module = module;
1438
- cachedDataViewMemory0 = null;
1439
- cachedFloat32ArrayMemory0 = null;
1440
- cachedUint8ArrayMemory0 = null;
1441
-
1442
-
1443
- wasm.__wbindgen_start();
1444
- return wasm;
1438
+ return false;
1439
+ }
1445
1440
  }
1446
1441
 
1447
1442
  function initSync(module) {
1448
1443
  if (wasm !== undefined) return wasm;
1449
1444
 
1450
1445
 
1451
- if (typeof module !== 'undefined') {
1446
+ if (module !== undefined) {
1452
1447
  if (Object.getPrototypeOf(module) === Object.prototype) {
1453
1448
  ({module} = module)
1454
1449
  } else {
@@ -1468,7 +1463,7 @@ async function __wbg_init(module_or_path) {
1468
1463
  if (wasm !== undefined) return wasm;
1469
1464
 
1470
1465
 
1471
- if (typeof module_or_path !== 'undefined') {
1466
+ if (module_or_path !== undefined) {
1472
1467
  if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
1473
1468
  ({module_or_path} = module_or_path)
1474
1469
  } else {
@@ -1476,7 +1471,7 @@ async function __wbg_init(module_or_path) {
1476
1471
  }
1477
1472
  }
1478
1473
 
1479
- if (typeof module_or_path === 'undefined') {
1474
+ if (module_or_path === undefined) {
1480
1475
  module_or_path = new URL('ruvector_attention_wasm_bg.wasm', import.meta.url);
1481
1476
  }
1482
1477
  const imports = __wbg_get_imports();
@@ -1490,5 +1485,4 @@ async function __wbg_init(module_or_path) {
1490
1485
  return __wbg_finalize_init(instance, module);
1491
1486
  }
1492
1487
 
1493
- export { initSync };
1494
- export default __wbg_init;
1488
+ export { initSync, __wbg_init as default };