@aigentic/attention-unified-wasm 0.1.29
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.
|
@@ -0,0 +1,2751 @@
|
|
|
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 _assertClass(instance, klass) {
|
|
13
|
+
if (!(instance instanceof klass)) {
|
|
14
|
+
throw new Error(`expected instance of ${klass.name}`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function debugString(val) {
|
|
19
|
+
// primitive types
|
|
20
|
+
const type = typeof val;
|
|
21
|
+
if (type == 'number' || type == 'boolean' || val == null) {
|
|
22
|
+
return `${val}`;
|
|
23
|
+
}
|
|
24
|
+
if (type == 'string') {
|
|
25
|
+
return `"${val}"`;
|
|
26
|
+
}
|
|
27
|
+
if (type == 'symbol') {
|
|
28
|
+
const description = val.description;
|
|
29
|
+
if (description == null) {
|
|
30
|
+
return 'Symbol';
|
|
31
|
+
} else {
|
|
32
|
+
return `Symbol(${description})`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (type == 'function') {
|
|
36
|
+
const name = val.name;
|
|
37
|
+
if (typeof name == 'string' && name.length > 0) {
|
|
38
|
+
return `Function(${name})`;
|
|
39
|
+
} else {
|
|
40
|
+
return 'Function';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// objects
|
|
44
|
+
if (Array.isArray(val)) {
|
|
45
|
+
const length = val.length;
|
|
46
|
+
let debug = '[';
|
|
47
|
+
if (length > 0) {
|
|
48
|
+
debug += debugString(val[0]);
|
|
49
|
+
}
|
|
50
|
+
for(let i = 1; i < length; i++) {
|
|
51
|
+
debug += ', ' + debugString(val[i]);
|
|
52
|
+
}
|
|
53
|
+
debug += ']';
|
|
54
|
+
return debug;
|
|
55
|
+
}
|
|
56
|
+
// Test for built-in
|
|
57
|
+
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
58
|
+
let className;
|
|
59
|
+
if (builtInMatches && builtInMatches.length > 1) {
|
|
60
|
+
className = builtInMatches[1];
|
|
61
|
+
} else {
|
|
62
|
+
// Failed to match the standard '[object ClassName]'
|
|
63
|
+
return toString.call(val);
|
|
64
|
+
}
|
|
65
|
+
if (className == 'Object') {
|
|
66
|
+
// we're a user defined class or Object
|
|
67
|
+
// JSON.stringify avoids problems with cycles, and is generally much
|
|
68
|
+
// easier than looping through ownProperties of `val`.
|
|
69
|
+
try {
|
|
70
|
+
return 'Object(' + JSON.stringify(val) + ')';
|
|
71
|
+
} catch (_) {
|
|
72
|
+
return 'Object';
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// errors
|
|
76
|
+
if (val instanceof Error) {
|
|
77
|
+
return `${val.name}: ${val.message}\n${val.stack}`;
|
|
78
|
+
}
|
|
79
|
+
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
80
|
+
return className;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function dropObject(idx) {
|
|
84
|
+
if (idx < 132) return;
|
|
85
|
+
heap[idx] = heap_next;
|
|
86
|
+
heap_next = idx;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function getArrayF32FromWasm0(ptr, len) {
|
|
90
|
+
ptr = ptr >>> 0;
|
|
91
|
+
return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
95
|
+
ptr = ptr >>> 0;
|
|
96
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
let cachedDataViewMemory0 = null;
|
|
100
|
+
function getDataViewMemory0() {
|
|
101
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
102
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
103
|
+
}
|
|
104
|
+
return cachedDataViewMemory0;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
let cachedFloat32ArrayMemory0 = null;
|
|
108
|
+
function getFloat32ArrayMemory0() {
|
|
109
|
+
if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
|
|
110
|
+
cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
|
|
111
|
+
}
|
|
112
|
+
return cachedFloat32ArrayMemory0;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function getStringFromWasm0(ptr, len) {
|
|
116
|
+
ptr = ptr >>> 0;
|
|
117
|
+
return decodeText(ptr, len);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
let cachedUint8ArrayMemory0 = null;
|
|
121
|
+
function getUint8ArrayMemory0() {
|
|
122
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
123
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
124
|
+
}
|
|
125
|
+
return cachedUint8ArrayMemory0;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function getObject(idx) { return heap[idx]; }
|
|
129
|
+
|
|
130
|
+
function handleError(f, args) {
|
|
131
|
+
try {
|
|
132
|
+
return f.apply(this, args);
|
|
133
|
+
} catch (e) {
|
|
134
|
+
wasm.__wbindgen_export3(addHeapObject(e));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
let heap = new Array(128).fill(undefined);
|
|
139
|
+
heap.push(undefined, null, true, false);
|
|
140
|
+
|
|
141
|
+
let heap_next = heap.length;
|
|
142
|
+
|
|
143
|
+
function isLikeNone(x) {
|
|
144
|
+
return x === undefined || x === null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function passArrayF32ToWasm0(arg, malloc) {
|
|
148
|
+
const ptr = malloc(arg.length * 4, 4) >>> 0;
|
|
149
|
+
getFloat32ArrayMemory0().set(arg, ptr / 4);
|
|
150
|
+
WASM_VECTOR_LEN = arg.length;
|
|
151
|
+
return ptr;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function passArrayJsValueToWasm0(array, malloc) {
|
|
155
|
+
const ptr = malloc(array.length * 4, 4) >>> 0;
|
|
156
|
+
const mem = getDataViewMemory0();
|
|
157
|
+
for (let i = 0; i < array.length; i++) {
|
|
158
|
+
mem.setUint32(ptr + 4 * i, addHeapObject(array[i]), true);
|
|
159
|
+
}
|
|
160
|
+
WASM_VECTOR_LEN = array.length;
|
|
161
|
+
return ptr;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
165
|
+
if (realloc === undefined) {
|
|
166
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
167
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
168
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
169
|
+
WASM_VECTOR_LEN = buf.length;
|
|
170
|
+
return ptr;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
let len = arg.length;
|
|
174
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
175
|
+
|
|
176
|
+
const mem = getUint8ArrayMemory0();
|
|
177
|
+
|
|
178
|
+
let offset = 0;
|
|
179
|
+
|
|
180
|
+
for (; offset < len; offset++) {
|
|
181
|
+
const code = arg.charCodeAt(offset);
|
|
182
|
+
if (code > 0x7F) break;
|
|
183
|
+
mem[ptr + offset] = code;
|
|
184
|
+
}
|
|
185
|
+
if (offset !== len) {
|
|
186
|
+
if (offset !== 0) {
|
|
187
|
+
arg = arg.slice(offset);
|
|
188
|
+
}
|
|
189
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
190
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
191
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
192
|
+
|
|
193
|
+
offset += ret.written;
|
|
194
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
WASM_VECTOR_LEN = offset;
|
|
198
|
+
return ptr;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function takeObject(idx) {
|
|
202
|
+
const ret = getObject(idx);
|
|
203
|
+
dropObject(idx);
|
|
204
|
+
return ret;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
208
|
+
cachedTextDecoder.decode();
|
|
209
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
210
|
+
let numBytesDecoded = 0;
|
|
211
|
+
function decodeText(ptr, len) {
|
|
212
|
+
numBytesDecoded += len;
|
|
213
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
214
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
215
|
+
cachedTextDecoder.decode();
|
|
216
|
+
numBytesDecoded = len;
|
|
217
|
+
}
|
|
218
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const cachedTextEncoder = new TextEncoder();
|
|
222
|
+
|
|
223
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
224
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
225
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
226
|
+
view.set(buf);
|
|
227
|
+
return {
|
|
228
|
+
read: arg.length,
|
|
229
|
+
written: buf.length
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
let WASM_VECTOR_LEN = 0;
|
|
235
|
+
|
|
236
|
+
const DagAttentionFactoryFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
237
|
+
? { register: () => {}, unregister: () => {} }
|
|
238
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_dagattentionfactory_free(ptr >>> 0, 1));
|
|
239
|
+
|
|
240
|
+
const GraphAttentionFactoryFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
241
|
+
? { register: () => {}, unregister: () => {} }
|
|
242
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_graphattentionfactory_free(ptr >>> 0, 1));
|
|
243
|
+
|
|
244
|
+
const HybridMambaAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
245
|
+
? { register: () => {}, unregister: () => {} }
|
|
246
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_hybridmambaattention_free(ptr >>> 0, 1));
|
|
247
|
+
|
|
248
|
+
const MambaConfigFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
249
|
+
? { register: () => {}, unregister: () => {} }
|
|
250
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_mambaconfig_free(ptr >>> 0, 1));
|
|
251
|
+
|
|
252
|
+
const MambaSSMAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
253
|
+
? { register: () => {}, unregister: () => {} }
|
|
254
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_mambassmattention_free(ptr >>> 0, 1));
|
|
255
|
+
|
|
256
|
+
const UnifiedAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
257
|
+
? { register: () => {}, unregister: () => {} }
|
|
258
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_unifiedattention_free(ptr >>> 0, 1));
|
|
259
|
+
|
|
260
|
+
const WasmCausalConeAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
261
|
+
? { register: () => {}, unregister: () => {} }
|
|
262
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmcausalconeattention_free(ptr >>> 0, 1));
|
|
263
|
+
|
|
264
|
+
const WasmCriticalPathAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
265
|
+
? { register: () => {}, unregister: () => {} }
|
|
266
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmcriticalpathattention_free(ptr >>> 0, 1));
|
|
267
|
+
|
|
268
|
+
const WasmFlashAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
269
|
+
? { register: () => {}, unregister: () => {} }
|
|
270
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmflashattention_free(ptr >>> 0, 1));
|
|
271
|
+
|
|
272
|
+
const WasmGNNLayerFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
273
|
+
? { register: () => {}, unregister: () => {} }
|
|
274
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmgnnlayer_free(ptr >>> 0, 1));
|
|
275
|
+
|
|
276
|
+
const WasmHierarchicalLorentzAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
277
|
+
? { register: () => {}, unregister: () => {} }
|
|
278
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmhierarchicallorentzattention_free(ptr >>> 0, 1));
|
|
279
|
+
|
|
280
|
+
const WasmHyperbolicAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
281
|
+
? { register: () => {}, unregister: () => {} }
|
|
282
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmhyperbolicattention_free(ptr >>> 0, 1));
|
|
283
|
+
|
|
284
|
+
const WasmLinearAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
285
|
+
? { register: () => {}, unregister: () => {} }
|
|
286
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmlinearattention_free(ptr >>> 0, 1));
|
|
287
|
+
|
|
288
|
+
const WasmLocalGlobalAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
289
|
+
? { register: () => {}, unregister: () => {} }
|
|
290
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmlocalglobalattention_free(ptr >>> 0, 1));
|
|
291
|
+
|
|
292
|
+
const WasmMinCutGatedAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
293
|
+
? { register: () => {}, unregister: () => {} }
|
|
294
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmmincutgatedattention_free(ptr >>> 0, 1));
|
|
295
|
+
|
|
296
|
+
const WasmMoEAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
297
|
+
? { register: () => {}, unregister: () => {} }
|
|
298
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmmoeattention_free(ptr >>> 0, 1));
|
|
299
|
+
|
|
300
|
+
const WasmMultiHeadAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
301
|
+
? { register: () => {}, unregister: () => {} }
|
|
302
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmmultiheadattention_free(ptr >>> 0, 1));
|
|
303
|
+
|
|
304
|
+
const WasmParallelBranchAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
305
|
+
? { register: () => {}, unregister: () => {} }
|
|
306
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmparallelbranchattention_free(ptr >>> 0, 1));
|
|
307
|
+
|
|
308
|
+
const WasmQueryDagFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
309
|
+
? { register: () => {}, unregister: () => {} }
|
|
310
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmquerydag_free(ptr >>> 0, 1));
|
|
311
|
+
|
|
312
|
+
const WasmSearchConfigFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
313
|
+
? { register: () => {}, unregister: () => {} }
|
|
314
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmsearchconfig_free(ptr >>> 0, 1));
|
|
315
|
+
|
|
316
|
+
const WasmTemporalBTSPAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
317
|
+
? { register: () => {}, unregister: () => {} }
|
|
318
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmtemporalbtspattention_free(ptr >>> 0, 1));
|
|
319
|
+
|
|
320
|
+
const WasmTensorCompressFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
321
|
+
? { register: () => {}, unregister: () => {} }
|
|
322
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmtensorcompress_free(ptr >>> 0, 1));
|
|
323
|
+
|
|
324
|
+
const WasmTopologicalAttentionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
325
|
+
? { register: () => {}, unregister: () => {} }
|
|
326
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmtopologicalattention_free(ptr >>> 0, 1));
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Factory for creating DAG attention mechanisms
|
|
330
|
+
*/
|
|
331
|
+
export class DagAttentionFactory {
|
|
332
|
+
__destroy_into_raw() {
|
|
333
|
+
const ptr = this.__wbg_ptr;
|
|
334
|
+
this.__wbg_ptr = 0;
|
|
335
|
+
DagAttentionFactoryFinalization.unregister(this);
|
|
336
|
+
return ptr;
|
|
337
|
+
}
|
|
338
|
+
free() {
|
|
339
|
+
const ptr = this.__destroy_into_raw();
|
|
340
|
+
wasm.__wbg_dagattentionfactory_free(ptr, 0);
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Get available DAG attention types
|
|
344
|
+
* @returns {any}
|
|
345
|
+
*/
|
|
346
|
+
static availableTypes() {
|
|
347
|
+
const ret = wasm.dagattentionfactory_availableTypes();
|
|
348
|
+
return takeObject(ret);
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Get description for a DAG attention type
|
|
352
|
+
* @param {string} attention_type
|
|
353
|
+
* @returns {string}
|
|
354
|
+
*/
|
|
355
|
+
static getDescription(attention_type) {
|
|
356
|
+
let deferred2_0;
|
|
357
|
+
let deferred2_1;
|
|
358
|
+
try {
|
|
359
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
360
|
+
const ptr0 = passStringToWasm0(attention_type, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
361
|
+
const len0 = WASM_VECTOR_LEN;
|
|
362
|
+
wasm.dagattentionfactory_getDescription(retptr, ptr0, len0);
|
|
363
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
364
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
365
|
+
deferred2_0 = r0;
|
|
366
|
+
deferred2_1 = r1;
|
|
367
|
+
return getStringFromWasm0(r0, r1);
|
|
368
|
+
} finally {
|
|
369
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
370
|
+
wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
if (Symbol.dispose) DagAttentionFactory.prototype[Symbol.dispose] = DagAttentionFactory.prototype.free;
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Factory for graph attention information
|
|
378
|
+
*/
|
|
379
|
+
export class GraphAttentionFactory {
|
|
380
|
+
__destroy_into_raw() {
|
|
381
|
+
const ptr = this.__wbg_ptr;
|
|
382
|
+
this.__wbg_ptr = 0;
|
|
383
|
+
GraphAttentionFactoryFinalization.unregister(this);
|
|
384
|
+
return ptr;
|
|
385
|
+
}
|
|
386
|
+
free() {
|
|
387
|
+
const ptr = this.__destroy_into_raw();
|
|
388
|
+
wasm.__wbg_graphattentionfactory_free(ptr, 0);
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Get recommended use cases for a graph attention type
|
|
392
|
+
* @param {string} attention_type
|
|
393
|
+
* @returns {any}
|
|
394
|
+
*/
|
|
395
|
+
static getUseCases(attention_type) {
|
|
396
|
+
const ptr0 = passStringToWasm0(attention_type, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
397
|
+
const len0 = WASM_VECTOR_LEN;
|
|
398
|
+
const ret = wasm.graphattentionfactory_getUseCases(ptr0, len0);
|
|
399
|
+
return takeObject(ret);
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Get available graph attention types
|
|
403
|
+
* @returns {any}
|
|
404
|
+
*/
|
|
405
|
+
static availableTypes() {
|
|
406
|
+
const ret = wasm.graphattentionfactory_availableTypes();
|
|
407
|
+
return takeObject(ret);
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Get description for a graph attention type
|
|
411
|
+
* @param {string} attention_type
|
|
412
|
+
* @returns {string}
|
|
413
|
+
*/
|
|
414
|
+
static getDescription(attention_type) {
|
|
415
|
+
let deferred2_0;
|
|
416
|
+
let deferred2_1;
|
|
417
|
+
try {
|
|
418
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
419
|
+
const ptr0 = passStringToWasm0(attention_type, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
420
|
+
const len0 = WASM_VECTOR_LEN;
|
|
421
|
+
wasm.graphattentionfactory_getDescription(retptr, ptr0, len0);
|
|
422
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
423
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
424
|
+
deferred2_0 = r0;
|
|
425
|
+
deferred2_1 = r1;
|
|
426
|
+
return getStringFromWasm0(r0, r1);
|
|
427
|
+
} finally {
|
|
428
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
429
|
+
wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
if (Symbol.dispose) GraphAttentionFactory.prototype[Symbol.dispose] = GraphAttentionFactory.prototype.free;
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Graph attention mechanism types
|
|
437
|
+
* @enum {0 | 1 | 2}
|
|
438
|
+
*/
|
|
439
|
+
export const GraphAttentionType = Object.freeze({
|
|
440
|
+
/**
|
|
441
|
+
* Graph Attention Networks (Velickovic et al., 2018)
|
|
442
|
+
*/
|
|
443
|
+
GAT: 0, "0": "GAT",
|
|
444
|
+
/**
|
|
445
|
+
* Graph Convolutional Networks (Kipf & Welling, 2017)
|
|
446
|
+
*/
|
|
447
|
+
GCN: 1, "1": "GCN",
|
|
448
|
+
/**
|
|
449
|
+
* GraphSAGE (Hamilton et al., 2017)
|
|
450
|
+
*/
|
|
451
|
+
GraphSAGE: 2, "2": "GraphSAGE",
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Hybrid layer combining Mamba SSM with standard attention
|
|
456
|
+
*
|
|
457
|
+
* Uses Mamba for long-range dependencies and attention for local patterns
|
|
458
|
+
*/
|
|
459
|
+
export class HybridMambaAttention {
|
|
460
|
+
__destroy_into_raw() {
|
|
461
|
+
const ptr = this.__wbg_ptr;
|
|
462
|
+
this.__wbg_ptr = 0;
|
|
463
|
+
HybridMambaAttentionFinalization.unregister(this);
|
|
464
|
+
return ptr;
|
|
465
|
+
}
|
|
466
|
+
free() {
|
|
467
|
+
const ptr = this.__destroy_into_raw();
|
|
468
|
+
wasm.__wbg_hybridmambaattention_free(ptr, 0);
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Get local window size
|
|
472
|
+
* @returns {number}
|
|
473
|
+
*/
|
|
474
|
+
get localWindow() {
|
|
475
|
+
const ret = wasm.hybridmambaattention_localWindow(this.__wbg_ptr);
|
|
476
|
+
return ret >>> 0;
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Create a new hybrid Mamba-Attention layer
|
|
480
|
+
* @param {MambaConfig} config
|
|
481
|
+
* @param {number} local_window
|
|
482
|
+
*/
|
|
483
|
+
constructor(config, local_window) {
|
|
484
|
+
_assertClass(config, MambaConfig);
|
|
485
|
+
var ptr0 = config.__destroy_into_raw();
|
|
486
|
+
const ret = wasm.hybridmambaattention_new(ptr0, local_window);
|
|
487
|
+
this.__wbg_ptr = ret >>> 0;
|
|
488
|
+
HybridMambaAttentionFinalization.register(this, this.__wbg_ptr, this);
|
|
489
|
+
return this;
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Forward pass
|
|
493
|
+
* @param {Float32Array} input
|
|
494
|
+
* @param {number} seq_len
|
|
495
|
+
* @returns {Float32Array}
|
|
496
|
+
*/
|
|
497
|
+
forward(input, seq_len) {
|
|
498
|
+
try {
|
|
499
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
500
|
+
const ptr0 = passArrayF32ToWasm0(input, wasm.__wbindgen_export);
|
|
501
|
+
const len0 = WASM_VECTOR_LEN;
|
|
502
|
+
wasm.hybridmambaattention_forward(retptr, this.__wbg_ptr, ptr0, len0, seq_len);
|
|
503
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
504
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
505
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
506
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
507
|
+
if (r3) {
|
|
508
|
+
throw takeObject(r2);
|
|
509
|
+
}
|
|
510
|
+
var v2 = getArrayF32FromWasm0(r0, r1).slice();
|
|
511
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
512
|
+
return v2;
|
|
513
|
+
} finally {
|
|
514
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
if (Symbol.dispose) HybridMambaAttention.prototype[Symbol.dispose] = HybridMambaAttention.prototype.free;
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* Configuration for Mamba SSM attention
|
|
522
|
+
*/
|
|
523
|
+
export class MambaConfig {
|
|
524
|
+
static __wrap(ptr) {
|
|
525
|
+
ptr = ptr >>> 0;
|
|
526
|
+
const obj = Object.create(MambaConfig.prototype);
|
|
527
|
+
obj.__wbg_ptr = ptr;
|
|
528
|
+
MambaConfigFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
529
|
+
return obj;
|
|
530
|
+
}
|
|
531
|
+
__destroy_into_raw() {
|
|
532
|
+
const ptr = this.__wbg_ptr;
|
|
533
|
+
this.__wbg_ptr = 0;
|
|
534
|
+
MambaConfigFinalization.unregister(this);
|
|
535
|
+
return ptr;
|
|
536
|
+
}
|
|
537
|
+
free() {
|
|
538
|
+
const ptr = this.__destroy_into_raw();
|
|
539
|
+
wasm.__wbg_mambaconfig_free(ptr, 0);
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Set state space dimension
|
|
543
|
+
* @param {number} state_dim
|
|
544
|
+
* @returns {MambaConfig}
|
|
545
|
+
*/
|
|
546
|
+
withStateDim(state_dim) {
|
|
547
|
+
const ptr = this.__destroy_into_raw();
|
|
548
|
+
const ret = wasm.mambaconfig_withStateDim(ptr, state_dim);
|
|
549
|
+
return MambaConfig.__wrap(ret);
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Set expansion factor
|
|
553
|
+
* @param {number} factor
|
|
554
|
+
* @returns {MambaConfig}
|
|
555
|
+
*/
|
|
556
|
+
withExpandFactor(factor) {
|
|
557
|
+
const ptr = this.__destroy_into_raw();
|
|
558
|
+
const ret = wasm.mambaconfig_withExpandFactor(ptr, factor);
|
|
559
|
+
return MambaConfig.__wrap(ret);
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Set convolution kernel size
|
|
563
|
+
* @param {number} size
|
|
564
|
+
* @returns {MambaConfig}
|
|
565
|
+
*/
|
|
566
|
+
withConvKernelSize(size) {
|
|
567
|
+
const ptr = this.__destroy_into_raw();
|
|
568
|
+
const ret = wasm.mambaconfig_withConvKernelSize(ptr, size);
|
|
569
|
+
return MambaConfig.__wrap(ret);
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Create a new Mamba configuration
|
|
573
|
+
* @param {number} dim
|
|
574
|
+
*/
|
|
575
|
+
constructor(dim) {
|
|
576
|
+
const ret = wasm.mambaconfig_new(dim);
|
|
577
|
+
this.__wbg_ptr = ret >>> 0;
|
|
578
|
+
MambaConfigFinalization.register(this, this.__wbg_ptr, this);
|
|
579
|
+
return this;
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Model dimension (d_model)
|
|
583
|
+
* @returns {number}
|
|
584
|
+
*/
|
|
585
|
+
get dim() {
|
|
586
|
+
const ret = wasm.__wbg_get_mambaconfig_dim(this.__wbg_ptr);
|
|
587
|
+
return ret >>> 0;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Model dimension (d_model)
|
|
591
|
+
* @param {number} arg0
|
|
592
|
+
*/
|
|
593
|
+
set dim(arg0) {
|
|
594
|
+
wasm.__wbg_set_mambaconfig_dim(this.__wbg_ptr, arg0);
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* State space dimension (n)
|
|
598
|
+
* @returns {number}
|
|
599
|
+
*/
|
|
600
|
+
get state_dim() {
|
|
601
|
+
const ret = wasm.__wbg_get_mambaconfig_state_dim(this.__wbg_ptr);
|
|
602
|
+
return ret >>> 0;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* State space dimension (n)
|
|
606
|
+
* @param {number} arg0
|
|
607
|
+
*/
|
|
608
|
+
set state_dim(arg0) {
|
|
609
|
+
wasm.__wbg_set_mambaconfig_state_dim(this.__wbg_ptr, arg0);
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Expansion factor for inner dimension
|
|
613
|
+
* @returns {number}
|
|
614
|
+
*/
|
|
615
|
+
get expand_factor() {
|
|
616
|
+
const ret = wasm.__wbg_get_mambaconfig_expand_factor(this.__wbg_ptr);
|
|
617
|
+
return ret >>> 0;
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Expansion factor for inner dimension
|
|
621
|
+
* @param {number} arg0
|
|
622
|
+
*/
|
|
623
|
+
set expand_factor(arg0) {
|
|
624
|
+
wasm.__wbg_set_mambaconfig_expand_factor(this.__wbg_ptr, arg0);
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Convolution kernel size
|
|
628
|
+
* @returns {number}
|
|
629
|
+
*/
|
|
630
|
+
get conv_kernel_size() {
|
|
631
|
+
const ret = wasm.__wbg_get_mambaconfig_conv_kernel_size(this.__wbg_ptr);
|
|
632
|
+
return ret >>> 0;
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* Convolution kernel size
|
|
636
|
+
* @param {number} arg0
|
|
637
|
+
*/
|
|
638
|
+
set conv_kernel_size(arg0) {
|
|
639
|
+
wasm.__wbg_set_mambaconfig_conv_kernel_size(this.__wbg_ptr, arg0);
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Delta (discretization step) range minimum
|
|
643
|
+
* @returns {number}
|
|
644
|
+
*/
|
|
645
|
+
get dt_min() {
|
|
646
|
+
const ret = wasm.__wbg_get_mambaconfig_dt_min(this.__wbg_ptr);
|
|
647
|
+
return ret;
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Delta (discretization step) range minimum
|
|
651
|
+
* @param {number} arg0
|
|
652
|
+
*/
|
|
653
|
+
set dt_min(arg0) {
|
|
654
|
+
wasm.__wbg_set_mambaconfig_dt_min(this.__wbg_ptr, arg0);
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Delta range maximum
|
|
658
|
+
* @returns {number}
|
|
659
|
+
*/
|
|
660
|
+
get dt_max() {
|
|
661
|
+
const ret = wasm.__wbg_get_mambaconfig_dt_max(this.__wbg_ptr);
|
|
662
|
+
return ret;
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Delta range maximum
|
|
666
|
+
* @param {number} arg0
|
|
667
|
+
*/
|
|
668
|
+
set dt_max(arg0) {
|
|
669
|
+
wasm.__wbg_set_mambaconfig_dt_max(this.__wbg_ptr, arg0);
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* Whether to use learnable D skip connection
|
|
673
|
+
* @returns {boolean}
|
|
674
|
+
*/
|
|
675
|
+
get use_d_skip() {
|
|
676
|
+
const ret = wasm.__wbg_get_mambaconfig_use_d_skip(this.__wbg_ptr);
|
|
677
|
+
return ret !== 0;
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Whether to use learnable D skip connection
|
|
681
|
+
* @param {boolean} arg0
|
|
682
|
+
*/
|
|
683
|
+
set use_d_skip(arg0) {
|
|
684
|
+
wasm.__wbg_set_mambaconfig_use_d_skip(this.__wbg_ptr, arg0);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
if (Symbol.dispose) MambaConfig.prototype[Symbol.dispose] = MambaConfig.prototype.free;
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* Mamba Selective State Space Model for sequence attention
|
|
691
|
+
*
|
|
692
|
+
* Provides O(n) attention-like mechanism using selective state spaces
|
|
693
|
+
*/
|
|
694
|
+
export class MambaSSMAttention {
|
|
695
|
+
static __wrap(ptr) {
|
|
696
|
+
ptr = ptr >>> 0;
|
|
697
|
+
const obj = Object.create(MambaSSMAttention.prototype);
|
|
698
|
+
obj.__wbg_ptr = ptr;
|
|
699
|
+
MambaSSMAttentionFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
700
|
+
return obj;
|
|
701
|
+
}
|
|
702
|
+
__destroy_into_raw() {
|
|
703
|
+
const ptr = this.__wbg_ptr;
|
|
704
|
+
this.__wbg_ptr = 0;
|
|
705
|
+
MambaSSMAttentionFinalization.unregister(this);
|
|
706
|
+
return ptr;
|
|
707
|
+
}
|
|
708
|
+
free() {
|
|
709
|
+
const ptr = this.__destroy_into_raw();
|
|
710
|
+
wasm.__wbg_mambassmattention_free(ptr, 0);
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* Create with default configuration
|
|
714
|
+
* @param {number} dim
|
|
715
|
+
* @returns {MambaSSMAttention}
|
|
716
|
+
*/
|
|
717
|
+
static withDefaults(dim) {
|
|
718
|
+
const ret = wasm.mambassmattention_withDefaults(dim);
|
|
719
|
+
return MambaSSMAttention.__wrap(ret);
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Compute attention-like scores (for visualization/analysis)
|
|
723
|
+
*
|
|
724
|
+
* Returns pseudo-attention scores showing which positions influence output
|
|
725
|
+
* @param {Float32Array} input
|
|
726
|
+
* @param {number} seq_len
|
|
727
|
+
* @returns {Float32Array}
|
|
728
|
+
*/
|
|
729
|
+
getAttentionScores(input, seq_len) {
|
|
730
|
+
try {
|
|
731
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
732
|
+
const ptr0 = passArrayF32ToWasm0(input, wasm.__wbindgen_export);
|
|
733
|
+
const len0 = WASM_VECTOR_LEN;
|
|
734
|
+
wasm.mambassmattention_getAttentionScores(retptr, this.__wbg_ptr, ptr0, len0, seq_len);
|
|
735
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
736
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
737
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
738
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
739
|
+
if (r3) {
|
|
740
|
+
throw takeObject(r2);
|
|
741
|
+
}
|
|
742
|
+
var v2 = getArrayF32FromWasm0(r0, r1).slice();
|
|
743
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
744
|
+
return v2;
|
|
745
|
+
} finally {
|
|
746
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
/**
|
|
750
|
+
* Create a new Mamba SSM attention layer
|
|
751
|
+
* @param {MambaConfig} config
|
|
752
|
+
*/
|
|
753
|
+
constructor(config) {
|
|
754
|
+
_assertClass(config, MambaConfig);
|
|
755
|
+
var ptr0 = config.__destroy_into_raw();
|
|
756
|
+
const ret = wasm.mambassmattention_new(ptr0);
|
|
757
|
+
this.__wbg_ptr = ret >>> 0;
|
|
758
|
+
MambaSSMAttentionFinalization.register(this, this.__wbg_ptr, this);
|
|
759
|
+
return this;
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* Get the configuration
|
|
763
|
+
* @returns {MambaConfig}
|
|
764
|
+
*/
|
|
765
|
+
get config() {
|
|
766
|
+
const ret = wasm.mambassmattention_config(this.__wbg_ptr);
|
|
767
|
+
return MambaConfig.__wrap(ret);
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Forward pass through Mamba SSM
|
|
771
|
+
*
|
|
772
|
+
* # Arguments
|
|
773
|
+
* * `input` - Input sequence (seq_len, dim) flattened to 1D
|
|
774
|
+
* * `seq_len` - Sequence length
|
|
775
|
+
*
|
|
776
|
+
* # Returns
|
|
777
|
+
* Output sequence (seq_len, dim) flattened to 1D
|
|
778
|
+
* @param {Float32Array} input
|
|
779
|
+
* @param {number} seq_len
|
|
780
|
+
* @returns {Float32Array}
|
|
781
|
+
*/
|
|
782
|
+
forward(input, seq_len) {
|
|
783
|
+
try {
|
|
784
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
785
|
+
const ptr0 = passArrayF32ToWasm0(input, wasm.__wbindgen_export);
|
|
786
|
+
const len0 = WASM_VECTOR_LEN;
|
|
787
|
+
wasm.mambassmattention_forward(retptr, this.__wbg_ptr, ptr0, len0, seq_len);
|
|
788
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
789
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
790
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
791
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
792
|
+
if (r3) {
|
|
793
|
+
throw takeObject(r2);
|
|
794
|
+
}
|
|
795
|
+
var v2 = getArrayF32FromWasm0(r0, r1).slice();
|
|
796
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
797
|
+
return v2;
|
|
798
|
+
} finally {
|
|
799
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
/**
|
|
803
|
+
* Get the inner dimension
|
|
804
|
+
* @returns {number}
|
|
805
|
+
*/
|
|
806
|
+
get innerDim() {
|
|
807
|
+
const ret = wasm.mambassmattention_innerDim(this.__wbg_ptr);
|
|
808
|
+
return ret >>> 0;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
if (Symbol.dispose) MambaSSMAttention.prototype[Symbol.dispose] = MambaSSMAttention.prototype.free;
|
|
812
|
+
|
|
813
|
+
/**
|
|
814
|
+
* Unified attention mechanism selector
|
|
815
|
+
* Automatically routes to the appropriate attention implementation
|
|
816
|
+
*/
|
|
817
|
+
export class UnifiedAttention {
|
|
818
|
+
__destroy_into_raw() {
|
|
819
|
+
const ptr = this.__wbg_ptr;
|
|
820
|
+
this.__wbg_ptr = 0;
|
|
821
|
+
UnifiedAttentionFinalization.unregister(this);
|
|
822
|
+
return ptr;
|
|
823
|
+
}
|
|
824
|
+
free() {
|
|
825
|
+
const ptr = this.__destroy_into_raw();
|
|
826
|
+
wasm.__wbg_unifiedattention_free(ptr, 0);
|
|
827
|
+
}
|
|
828
|
+
/**
|
|
829
|
+
* Check if this mechanism supports graph/DAG structures
|
|
830
|
+
* @returns {boolean}
|
|
831
|
+
*/
|
|
832
|
+
supportsGraphs() {
|
|
833
|
+
const ret = wasm.unifiedattention_supportsGraphs(this.__wbg_ptr);
|
|
834
|
+
return ret !== 0;
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* Check if this mechanism supports sequence processing
|
|
838
|
+
* @returns {boolean}
|
|
839
|
+
*/
|
|
840
|
+
supportsSequences() {
|
|
841
|
+
const ret = wasm.unifiedattention_supportsSequences(this.__wbg_ptr);
|
|
842
|
+
return ret !== 0;
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* Check if this mechanism supports hyperbolic geometry
|
|
846
|
+
* @returns {boolean}
|
|
847
|
+
*/
|
|
848
|
+
supportsHyperbolic() {
|
|
849
|
+
const ret = wasm.unifiedattention_supportsHyperbolic(this.__wbg_ptr);
|
|
850
|
+
return ret !== 0;
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* Create a new unified attention selector
|
|
854
|
+
* @param {string} mechanism
|
|
855
|
+
*/
|
|
856
|
+
constructor(mechanism) {
|
|
857
|
+
try {
|
|
858
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
859
|
+
const ptr0 = passStringToWasm0(mechanism, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
860
|
+
const len0 = WASM_VECTOR_LEN;
|
|
861
|
+
wasm.unifiedattention_new(retptr, ptr0, len0);
|
|
862
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
863
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
864
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
865
|
+
if (r2) {
|
|
866
|
+
throw takeObject(r1);
|
|
867
|
+
}
|
|
868
|
+
this.__wbg_ptr = r0 >>> 0;
|
|
869
|
+
UnifiedAttentionFinalization.register(this, this.__wbg_ptr, this);
|
|
870
|
+
return this;
|
|
871
|
+
} finally {
|
|
872
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* Get the category of the selected mechanism
|
|
877
|
+
* @returns {string}
|
|
878
|
+
*/
|
|
879
|
+
get category() {
|
|
880
|
+
let deferred1_0;
|
|
881
|
+
let deferred1_1;
|
|
882
|
+
try {
|
|
883
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
884
|
+
wasm.unifiedattention_category(retptr, this.__wbg_ptr);
|
|
885
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
886
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
887
|
+
deferred1_0 = r0;
|
|
888
|
+
deferred1_1 = r1;
|
|
889
|
+
return getStringFromWasm0(r0, r1);
|
|
890
|
+
} finally {
|
|
891
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
892
|
+
wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* Get the currently selected mechanism type
|
|
897
|
+
* @returns {string}
|
|
898
|
+
*/
|
|
899
|
+
get mechanism() {
|
|
900
|
+
let deferred1_0;
|
|
901
|
+
let deferred1_1;
|
|
902
|
+
try {
|
|
903
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
904
|
+
wasm.unifiedattention_mechanism(retptr, this.__wbg_ptr);
|
|
905
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
906
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
907
|
+
deferred1_0 = r0;
|
|
908
|
+
deferred1_1 = r1;
|
|
909
|
+
return getStringFromWasm0(r0, r1);
|
|
910
|
+
} finally {
|
|
911
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
912
|
+
wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
if (Symbol.dispose) UnifiedAttention.prototype[Symbol.dispose] = UnifiedAttention.prototype.free;
|
|
917
|
+
|
|
918
|
+
/**
|
|
919
|
+
* Causal cone attention based on dependency lightcones
|
|
920
|
+
*
|
|
921
|
+
* Nodes can only attend to ancestors in the DAG (causal predecessors).
|
|
922
|
+
* Attention strength decays with causal distance.
|
|
923
|
+
*/
|
|
924
|
+
export class WasmCausalConeAttention {
|
|
925
|
+
__destroy_into_raw() {
|
|
926
|
+
const ptr = this.__wbg_ptr;
|
|
927
|
+
this.__wbg_ptr = 0;
|
|
928
|
+
WasmCausalConeAttentionFinalization.unregister(this);
|
|
929
|
+
return ptr;
|
|
930
|
+
}
|
|
931
|
+
free() {
|
|
932
|
+
const ptr = this.__destroy_into_raw();
|
|
933
|
+
wasm.__wbg_wasmcausalconeattention_free(ptr, 0);
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
* Create a new causal cone attention instance
|
|
937
|
+
*
|
|
938
|
+
* # Arguments
|
|
939
|
+
* * `future_discount` - Discount for future nodes
|
|
940
|
+
* * `ancestor_weight` - Weight for ancestor influence
|
|
941
|
+
* @param {number} future_discount
|
|
942
|
+
* @param {number} ancestor_weight
|
|
943
|
+
*/
|
|
944
|
+
constructor(future_discount, ancestor_weight) {
|
|
945
|
+
const ret = wasm.wasmcausalconeattention_new(future_discount, ancestor_weight);
|
|
946
|
+
this.__wbg_ptr = ret >>> 0;
|
|
947
|
+
WasmCausalConeAttentionFinalization.register(this, this.__wbg_ptr, this);
|
|
948
|
+
return this;
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* Compute attention scores for the DAG
|
|
952
|
+
* @param {WasmQueryDag} dag
|
|
953
|
+
* @returns {Float32Array}
|
|
954
|
+
*/
|
|
955
|
+
forward(dag) {
|
|
956
|
+
try {
|
|
957
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
958
|
+
_assertClass(dag, WasmQueryDag);
|
|
959
|
+
wasm.wasmcausalconeattention_forward(retptr, this.__wbg_ptr, dag.__wbg_ptr);
|
|
960
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
961
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
962
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
963
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
964
|
+
if (r3) {
|
|
965
|
+
throw takeObject(r2);
|
|
966
|
+
}
|
|
967
|
+
var v1 = getArrayF32FromWasm0(r0, r1).slice();
|
|
968
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
969
|
+
return v1;
|
|
970
|
+
} finally {
|
|
971
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
if (Symbol.dispose) WasmCausalConeAttention.prototype[Symbol.dispose] = WasmCausalConeAttention.prototype.free;
|
|
976
|
+
|
|
977
|
+
/**
|
|
978
|
+
* Critical path attention weighted by path criticality
|
|
979
|
+
*
|
|
980
|
+
* Nodes on or near the critical path (longest execution path)
|
|
981
|
+
* receive higher attention scores.
|
|
982
|
+
*/
|
|
983
|
+
export class WasmCriticalPathAttention {
|
|
984
|
+
__destroy_into_raw() {
|
|
985
|
+
const ptr = this.__wbg_ptr;
|
|
986
|
+
this.__wbg_ptr = 0;
|
|
987
|
+
WasmCriticalPathAttentionFinalization.unregister(this);
|
|
988
|
+
return ptr;
|
|
989
|
+
}
|
|
990
|
+
free() {
|
|
991
|
+
const ptr = this.__destroy_into_raw();
|
|
992
|
+
wasm.__wbg_wasmcriticalpathattention_free(ptr, 0);
|
|
993
|
+
}
|
|
994
|
+
/**
|
|
995
|
+
* Create a new critical path attention instance
|
|
996
|
+
*
|
|
997
|
+
* # Arguments
|
|
998
|
+
* * `path_weight` - Weight for critical path membership
|
|
999
|
+
* * `branch_penalty` - Penalty for branching nodes
|
|
1000
|
+
* @param {number} path_weight
|
|
1001
|
+
* @param {number} branch_penalty
|
|
1002
|
+
*/
|
|
1003
|
+
constructor(path_weight, branch_penalty) {
|
|
1004
|
+
const ret = wasm.wasmcausalconeattention_new(path_weight, branch_penalty);
|
|
1005
|
+
this.__wbg_ptr = ret >>> 0;
|
|
1006
|
+
WasmCriticalPathAttentionFinalization.register(this, this.__wbg_ptr, this);
|
|
1007
|
+
return this;
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* Compute attention scores for the DAG
|
|
1011
|
+
* @param {WasmQueryDag} dag
|
|
1012
|
+
* @returns {Float32Array}
|
|
1013
|
+
*/
|
|
1014
|
+
forward(dag) {
|
|
1015
|
+
try {
|
|
1016
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1017
|
+
_assertClass(dag, WasmQueryDag);
|
|
1018
|
+
wasm.wasmcriticalpathattention_forward(retptr, this.__wbg_ptr, dag.__wbg_ptr);
|
|
1019
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1020
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1021
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1022
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1023
|
+
if (r3) {
|
|
1024
|
+
throw takeObject(r2);
|
|
1025
|
+
}
|
|
1026
|
+
var v1 = getArrayF32FromWasm0(r0, r1).slice();
|
|
1027
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
1028
|
+
return v1;
|
|
1029
|
+
} finally {
|
|
1030
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
if (Symbol.dispose) WasmCriticalPathAttention.prototype[Symbol.dispose] = WasmCriticalPathAttention.prototype.free;
|
|
1035
|
+
|
|
1036
|
+
/**
|
|
1037
|
+
* Flash attention with memory-efficient tiling
|
|
1038
|
+
*
|
|
1039
|
+
* Reduces memory usage from O(n^2) to O(n) by computing attention
|
|
1040
|
+
* in blocks and fusing operations
|
|
1041
|
+
*/
|
|
1042
|
+
export class WasmFlashAttention {
|
|
1043
|
+
__destroy_into_raw() {
|
|
1044
|
+
const ptr = this.__wbg_ptr;
|
|
1045
|
+
this.__wbg_ptr = 0;
|
|
1046
|
+
WasmFlashAttentionFinalization.unregister(this);
|
|
1047
|
+
return ptr;
|
|
1048
|
+
}
|
|
1049
|
+
free() {
|
|
1050
|
+
const ptr = this.__destroy_into_raw();
|
|
1051
|
+
wasm.__wbg_wasmflashattention_free(ptr, 0);
|
|
1052
|
+
}
|
|
1053
|
+
/**
|
|
1054
|
+
* Create a new flash attention instance
|
|
1055
|
+
*
|
|
1056
|
+
* # Arguments
|
|
1057
|
+
* * `dim` - Embedding dimension
|
|
1058
|
+
* * `block_size` - Block size for tiled computation
|
|
1059
|
+
* @param {number} dim
|
|
1060
|
+
* @param {number} block_size
|
|
1061
|
+
*/
|
|
1062
|
+
constructor(dim, block_size) {
|
|
1063
|
+
const ret = wasm.wasmflashattention_new(dim, block_size);
|
|
1064
|
+
this.__wbg_ptr = ret >>> 0;
|
|
1065
|
+
WasmFlashAttentionFinalization.register(this, this.__wbg_ptr, this);
|
|
1066
|
+
return this;
|
|
1067
|
+
}
|
|
1068
|
+
/**
|
|
1069
|
+
* Compute flash attention
|
|
1070
|
+
* @param {Float32Array} query
|
|
1071
|
+
* @param {any} keys
|
|
1072
|
+
* @param {any} values
|
|
1073
|
+
* @returns {Float32Array}
|
|
1074
|
+
*/
|
|
1075
|
+
compute(query, keys, values) {
|
|
1076
|
+
try {
|
|
1077
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1078
|
+
const ptr0 = passArrayF32ToWasm0(query, wasm.__wbindgen_export);
|
|
1079
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1080
|
+
wasm.wasmflashattention_compute(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(keys), addHeapObject(values));
|
|
1081
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1082
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1083
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1084
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1085
|
+
if (r3) {
|
|
1086
|
+
throw takeObject(r2);
|
|
1087
|
+
}
|
|
1088
|
+
var v2 = getArrayF32FromWasm0(r0, r1).slice();
|
|
1089
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
1090
|
+
return v2;
|
|
1091
|
+
} finally {
|
|
1092
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
if (Symbol.dispose) WasmFlashAttention.prototype[Symbol.dispose] = WasmFlashAttention.prototype.free;
|
|
1097
|
+
|
|
1098
|
+
/**
|
|
1099
|
+
* Graph Neural Network layer with attention mechanism
|
|
1100
|
+
*
|
|
1101
|
+
* Implements Graph Attention Networks (GAT) for HNSW topology.
|
|
1102
|
+
* Each node aggregates information from neighbors using learned attention weights.
|
|
1103
|
+
*/
|
|
1104
|
+
export class WasmGNNLayer {
|
|
1105
|
+
static __unwrap(jsValue) {
|
|
1106
|
+
if (!(jsValue instanceof WasmGNNLayer)) {
|
|
1107
|
+
return 0;
|
|
1108
|
+
}
|
|
1109
|
+
return jsValue.__destroy_into_raw();
|
|
1110
|
+
}
|
|
1111
|
+
__destroy_into_raw() {
|
|
1112
|
+
const ptr = this.__wbg_ptr;
|
|
1113
|
+
this.__wbg_ptr = 0;
|
|
1114
|
+
WasmGNNLayerFinalization.unregister(this);
|
|
1115
|
+
return ptr;
|
|
1116
|
+
}
|
|
1117
|
+
free() {
|
|
1118
|
+
const ptr = this.__destroy_into_raw();
|
|
1119
|
+
wasm.__wbg_wasmgnnlayer_free(ptr, 0);
|
|
1120
|
+
}
|
|
1121
|
+
/**
|
|
1122
|
+
* Get the output dimension
|
|
1123
|
+
* @returns {number}
|
|
1124
|
+
*/
|
|
1125
|
+
get outputDim() {
|
|
1126
|
+
const ret = wasm.wasmgnnlayer_outputDim(this.__wbg_ptr);
|
|
1127
|
+
return ret >>> 0;
|
|
1128
|
+
}
|
|
1129
|
+
/**
|
|
1130
|
+
* Create a new GNN layer with attention
|
|
1131
|
+
*
|
|
1132
|
+
* # Arguments
|
|
1133
|
+
* * `input_dim` - Dimension of input node embeddings
|
|
1134
|
+
* * `hidden_dim` - Dimension of hidden representations
|
|
1135
|
+
* * `heads` - Number of attention heads
|
|
1136
|
+
* * `dropout` - Dropout rate (0.0 to 1.0)
|
|
1137
|
+
* @param {number} input_dim
|
|
1138
|
+
* @param {number} hidden_dim
|
|
1139
|
+
* @param {number} heads
|
|
1140
|
+
* @param {number} dropout
|
|
1141
|
+
*/
|
|
1142
|
+
constructor(input_dim, hidden_dim, heads, dropout) {
|
|
1143
|
+
try {
|
|
1144
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1145
|
+
wasm.wasmgnnlayer_new(retptr, input_dim, hidden_dim, heads, dropout);
|
|
1146
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1147
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1148
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1149
|
+
if (r2) {
|
|
1150
|
+
throw takeObject(r1);
|
|
1151
|
+
}
|
|
1152
|
+
this.__wbg_ptr = r0 >>> 0;
|
|
1153
|
+
WasmGNNLayerFinalization.register(this, this.__wbg_ptr, this);
|
|
1154
|
+
return this;
|
|
1155
|
+
} finally {
|
|
1156
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
/**
|
|
1160
|
+
* Forward pass through the GNN layer
|
|
1161
|
+
*
|
|
1162
|
+
* # Arguments
|
|
1163
|
+
* * `node_embedding` - Current node's embedding (Float32Array)
|
|
1164
|
+
* * `neighbor_embeddings` - Embeddings of neighbor nodes (array of Float32Arrays)
|
|
1165
|
+
* * `edge_weights` - Weights of edges to neighbors (Float32Array)
|
|
1166
|
+
*
|
|
1167
|
+
* # Returns
|
|
1168
|
+
* Updated node embedding (Float32Array)
|
|
1169
|
+
* @param {Float32Array} node_embedding
|
|
1170
|
+
* @param {any} neighbor_embeddings
|
|
1171
|
+
* @param {Float32Array} edge_weights
|
|
1172
|
+
* @returns {Float32Array}
|
|
1173
|
+
*/
|
|
1174
|
+
forward(node_embedding, neighbor_embeddings, edge_weights) {
|
|
1175
|
+
try {
|
|
1176
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1177
|
+
const ptr0 = passArrayF32ToWasm0(node_embedding, wasm.__wbindgen_export);
|
|
1178
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1179
|
+
const ptr1 = passArrayF32ToWasm0(edge_weights, wasm.__wbindgen_export);
|
|
1180
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1181
|
+
wasm.wasmgnnlayer_forward(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(neighbor_embeddings), ptr1, len1);
|
|
1182
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1183
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1184
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1185
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1186
|
+
if (r3) {
|
|
1187
|
+
throw takeObject(r2);
|
|
1188
|
+
}
|
|
1189
|
+
var v3 = getArrayF32FromWasm0(r0, r1).slice();
|
|
1190
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
1191
|
+
return v3;
|
|
1192
|
+
} finally {
|
|
1193
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
if (Symbol.dispose) WasmGNNLayer.prototype[Symbol.dispose] = WasmGNNLayer.prototype.free;
|
|
1198
|
+
|
|
1199
|
+
/**
|
|
1200
|
+
* Hierarchical Lorentz attention in hyperbolic space
|
|
1201
|
+
*
|
|
1202
|
+
* Combines DAG hierarchy with Lorentz (hyperboloid) geometry
|
|
1203
|
+
* for multi-scale hierarchical attention.
|
|
1204
|
+
*/
|
|
1205
|
+
export class WasmHierarchicalLorentzAttention {
|
|
1206
|
+
__destroy_into_raw() {
|
|
1207
|
+
const ptr = this.__wbg_ptr;
|
|
1208
|
+
this.__wbg_ptr = 0;
|
|
1209
|
+
WasmHierarchicalLorentzAttentionFinalization.unregister(this);
|
|
1210
|
+
return ptr;
|
|
1211
|
+
}
|
|
1212
|
+
free() {
|
|
1213
|
+
const ptr = this.__destroy_into_raw();
|
|
1214
|
+
wasm.__wbg_wasmhierarchicallorentzattention_free(ptr, 0);
|
|
1215
|
+
}
|
|
1216
|
+
/**
|
|
1217
|
+
* Create a new hierarchical Lorentz attention instance
|
|
1218
|
+
*
|
|
1219
|
+
* # Arguments
|
|
1220
|
+
* * `curvature` - Hyperbolic curvature parameter
|
|
1221
|
+
* * `temperature` - Temperature for softmax
|
|
1222
|
+
* @param {number} curvature
|
|
1223
|
+
* @param {number} temperature
|
|
1224
|
+
*/
|
|
1225
|
+
constructor(curvature, temperature) {
|
|
1226
|
+
const ret = wasm.wasmcausalconeattention_new(curvature, temperature);
|
|
1227
|
+
this.__wbg_ptr = ret >>> 0;
|
|
1228
|
+
WasmHierarchicalLorentzAttentionFinalization.register(this, this.__wbg_ptr, this);
|
|
1229
|
+
return this;
|
|
1230
|
+
}
|
|
1231
|
+
/**
|
|
1232
|
+
* Compute attention scores for the DAG
|
|
1233
|
+
* @param {WasmQueryDag} dag
|
|
1234
|
+
* @returns {Float32Array}
|
|
1235
|
+
*/
|
|
1236
|
+
forward(dag) {
|
|
1237
|
+
try {
|
|
1238
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1239
|
+
_assertClass(dag, WasmQueryDag);
|
|
1240
|
+
wasm.wasmhierarchicallorentzattention_forward(retptr, this.__wbg_ptr, dag.__wbg_ptr);
|
|
1241
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1242
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1243
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1244
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1245
|
+
if (r3) {
|
|
1246
|
+
throw takeObject(r2);
|
|
1247
|
+
}
|
|
1248
|
+
var v1 = getArrayF32FromWasm0(r0, r1).slice();
|
|
1249
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
1250
|
+
return v1;
|
|
1251
|
+
} finally {
|
|
1252
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
if (Symbol.dispose) WasmHierarchicalLorentzAttention.prototype[Symbol.dispose] = WasmHierarchicalLorentzAttention.prototype.free;
|
|
1257
|
+
|
|
1258
|
+
/**
|
|
1259
|
+
* Hyperbolic attention mechanism for hierarchical data
|
|
1260
|
+
*
|
|
1261
|
+
* Operates in hyperbolic space (Poincare ball model) which naturally
|
|
1262
|
+
* represents tree-like hierarchical structures with exponential capacity
|
|
1263
|
+
*/
|
|
1264
|
+
export class WasmHyperbolicAttention {
|
|
1265
|
+
__destroy_into_raw() {
|
|
1266
|
+
const ptr = this.__wbg_ptr;
|
|
1267
|
+
this.__wbg_ptr = 0;
|
|
1268
|
+
WasmHyperbolicAttentionFinalization.unregister(this);
|
|
1269
|
+
return ptr;
|
|
1270
|
+
}
|
|
1271
|
+
free() {
|
|
1272
|
+
const ptr = this.__destroy_into_raw();
|
|
1273
|
+
wasm.__wbg_wasmhyperbolicattention_free(ptr, 0);
|
|
1274
|
+
}
|
|
1275
|
+
/**
|
|
1276
|
+
* Create a new hyperbolic attention instance
|
|
1277
|
+
*
|
|
1278
|
+
* # Arguments
|
|
1279
|
+
* * `dim` - Embedding dimension
|
|
1280
|
+
* * `curvature` - Hyperbolic curvature parameter (negative for hyperbolic space)
|
|
1281
|
+
* @param {number} dim
|
|
1282
|
+
* @param {number} curvature
|
|
1283
|
+
*/
|
|
1284
|
+
constructor(dim, curvature) {
|
|
1285
|
+
const ret = wasm.wasmhyperbolicattention_new(dim, curvature);
|
|
1286
|
+
this.__wbg_ptr = ret >>> 0;
|
|
1287
|
+
WasmHyperbolicAttentionFinalization.register(this, this.__wbg_ptr, this);
|
|
1288
|
+
return this;
|
|
1289
|
+
}
|
|
1290
|
+
/**
|
|
1291
|
+
* Compute hyperbolic attention
|
|
1292
|
+
* @param {Float32Array} query
|
|
1293
|
+
* @param {any} keys
|
|
1294
|
+
* @param {any} values
|
|
1295
|
+
* @returns {Float32Array}
|
|
1296
|
+
*/
|
|
1297
|
+
compute(query, keys, values) {
|
|
1298
|
+
try {
|
|
1299
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1300
|
+
const ptr0 = passArrayF32ToWasm0(query, wasm.__wbindgen_export);
|
|
1301
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1302
|
+
wasm.wasmhyperbolicattention_compute(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(keys), addHeapObject(values));
|
|
1303
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1304
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1305
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1306
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1307
|
+
if (r3) {
|
|
1308
|
+
throw takeObject(r2);
|
|
1309
|
+
}
|
|
1310
|
+
var v2 = getArrayF32FromWasm0(r0, r1).slice();
|
|
1311
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
1312
|
+
return v2;
|
|
1313
|
+
} finally {
|
|
1314
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
/**
|
|
1318
|
+
* Get the curvature parameter
|
|
1319
|
+
* @returns {number}
|
|
1320
|
+
*/
|
|
1321
|
+
get curvature() {
|
|
1322
|
+
const ret = wasm.wasmhyperbolicattention_curvature(this.__wbg_ptr);
|
|
1323
|
+
return ret;
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
if (Symbol.dispose) WasmHyperbolicAttention.prototype[Symbol.dispose] = WasmHyperbolicAttention.prototype.free;
|
|
1327
|
+
|
|
1328
|
+
/**
|
|
1329
|
+
* Linear attention using random feature approximation
|
|
1330
|
+
*
|
|
1331
|
+
* Achieves O(n) complexity instead of O(n^2) by approximating
|
|
1332
|
+
* the softmax kernel with random Fourier features
|
|
1333
|
+
*/
|
|
1334
|
+
export class WasmLinearAttention {
|
|
1335
|
+
__destroy_into_raw() {
|
|
1336
|
+
const ptr = this.__wbg_ptr;
|
|
1337
|
+
this.__wbg_ptr = 0;
|
|
1338
|
+
WasmLinearAttentionFinalization.unregister(this);
|
|
1339
|
+
return ptr;
|
|
1340
|
+
}
|
|
1341
|
+
free() {
|
|
1342
|
+
const ptr = this.__destroy_into_raw();
|
|
1343
|
+
wasm.__wbg_wasmlinearattention_free(ptr, 0);
|
|
1344
|
+
}
|
|
1345
|
+
/**
|
|
1346
|
+
* Create a new linear attention instance
|
|
1347
|
+
*
|
|
1348
|
+
* # Arguments
|
|
1349
|
+
* * `dim` - Embedding dimension
|
|
1350
|
+
* * `num_features` - Number of random features for kernel approximation
|
|
1351
|
+
* @param {number} dim
|
|
1352
|
+
* @param {number} num_features
|
|
1353
|
+
*/
|
|
1354
|
+
constructor(dim, num_features) {
|
|
1355
|
+
const ret = wasm.wasmlinearattention_new(dim, num_features);
|
|
1356
|
+
this.__wbg_ptr = ret >>> 0;
|
|
1357
|
+
WasmLinearAttentionFinalization.register(this, this.__wbg_ptr, this);
|
|
1358
|
+
return this;
|
|
1359
|
+
}
|
|
1360
|
+
/**
|
|
1361
|
+
* Compute linear attention
|
|
1362
|
+
* @param {Float32Array} query
|
|
1363
|
+
* @param {any} keys
|
|
1364
|
+
* @param {any} values
|
|
1365
|
+
* @returns {Float32Array}
|
|
1366
|
+
*/
|
|
1367
|
+
compute(query, keys, values) {
|
|
1368
|
+
try {
|
|
1369
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1370
|
+
const ptr0 = passArrayF32ToWasm0(query, wasm.__wbindgen_export);
|
|
1371
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1372
|
+
wasm.wasmlinearattention_compute(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(keys), addHeapObject(values));
|
|
1373
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1374
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1375
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1376
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1377
|
+
if (r3) {
|
|
1378
|
+
throw takeObject(r2);
|
|
1379
|
+
}
|
|
1380
|
+
var v2 = getArrayF32FromWasm0(r0, r1).slice();
|
|
1381
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
1382
|
+
return v2;
|
|
1383
|
+
} finally {
|
|
1384
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
if (Symbol.dispose) WasmLinearAttention.prototype[Symbol.dispose] = WasmLinearAttention.prototype.free;
|
|
1389
|
+
|
|
1390
|
+
/**
|
|
1391
|
+
* Local-global sparse attention (Longformer-style)
|
|
1392
|
+
*
|
|
1393
|
+
* Combines local sliding window attention with global tokens
|
|
1394
|
+
* for efficient long-range dependencies
|
|
1395
|
+
*/
|
|
1396
|
+
export class WasmLocalGlobalAttention {
|
|
1397
|
+
__destroy_into_raw() {
|
|
1398
|
+
const ptr = this.__wbg_ptr;
|
|
1399
|
+
this.__wbg_ptr = 0;
|
|
1400
|
+
WasmLocalGlobalAttentionFinalization.unregister(this);
|
|
1401
|
+
return ptr;
|
|
1402
|
+
}
|
|
1403
|
+
free() {
|
|
1404
|
+
const ptr = this.__destroy_into_raw();
|
|
1405
|
+
wasm.__wbg_wasmlocalglobalattention_free(ptr, 0);
|
|
1406
|
+
}
|
|
1407
|
+
/**
|
|
1408
|
+
* Create a new local-global attention instance
|
|
1409
|
+
*
|
|
1410
|
+
* # Arguments
|
|
1411
|
+
* * `dim` - Embedding dimension
|
|
1412
|
+
* * `local_window` - Size of local attention window
|
|
1413
|
+
* * `global_tokens` - Number of global attention tokens
|
|
1414
|
+
* @param {number} dim
|
|
1415
|
+
* @param {number} local_window
|
|
1416
|
+
* @param {number} global_tokens
|
|
1417
|
+
*/
|
|
1418
|
+
constructor(dim, local_window, global_tokens) {
|
|
1419
|
+
const ret = wasm.wasmlocalglobalattention_new(dim, local_window, global_tokens);
|
|
1420
|
+
this.__wbg_ptr = ret >>> 0;
|
|
1421
|
+
WasmLocalGlobalAttentionFinalization.register(this, this.__wbg_ptr, this);
|
|
1422
|
+
return this;
|
|
1423
|
+
}
|
|
1424
|
+
/**
|
|
1425
|
+
* Compute local-global attention
|
|
1426
|
+
* @param {Float32Array} query
|
|
1427
|
+
* @param {any} keys
|
|
1428
|
+
* @param {any} values
|
|
1429
|
+
* @returns {Float32Array}
|
|
1430
|
+
*/
|
|
1431
|
+
compute(query, keys, values) {
|
|
1432
|
+
try {
|
|
1433
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1434
|
+
const ptr0 = passArrayF32ToWasm0(query, wasm.__wbindgen_export);
|
|
1435
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1436
|
+
wasm.wasmlocalglobalattention_compute(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(keys), addHeapObject(values));
|
|
1437
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1438
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1439
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1440
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1441
|
+
if (r3) {
|
|
1442
|
+
throw takeObject(r2);
|
|
1443
|
+
}
|
|
1444
|
+
var v2 = getArrayF32FromWasm0(r0, r1).slice();
|
|
1445
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
1446
|
+
return v2;
|
|
1447
|
+
} finally {
|
|
1448
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
if (Symbol.dispose) WasmLocalGlobalAttention.prototype[Symbol.dispose] = WasmLocalGlobalAttention.prototype.free;
|
|
1453
|
+
|
|
1454
|
+
/**
|
|
1455
|
+
* MinCut-gated attention using flow-based bottleneck detection
|
|
1456
|
+
*
|
|
1457
|
+
* Uses minimum cut analysis to identify bottleneck nodes
|
|
1458
|
+
* and gates attention through these critical points.
|
|
1459
|
+
*/
|
|
1460
|
+
export class WasmMinCutGatedAttention {
|
|
1461
|
+
__destroy_into_raw() {
|
|
1462
|
+
const ptr = this.__wbg_ptr;
|
|
1463
|
+
this.__wbg_ptr = 0;
|
|
1464
|
+
WasmMinCutGatedAttentionFinalization.unregister(this);
|
|
1465
|
+
return ptr;
|
|
1466
|
+
}
|
|
1467
|
+
free() {
|
|
1468
|
+
const ptr = this.__destroy_into_raw();
|
|
1469
|
+
wasm.__wbg_wasmmincutgatedattention_free(ptr, 0);
|
|
1470
|
+
}
|
|
1471
|
+
/**
|
|
1472
|
+
* Create a new MinCut-gated attention instance
|
|
1473
|
+
*
|
|
1474
|
+
* # Arguments
|
|
1475
|
+
* * `gate_threshold` - Threshold for gating (0.0-1.0)
|
|
1476
|
+
* @param {number} gate_threshold
|
|
1477
|
+
*/
|
|
1478
|
+
constructor(gate_threshold) {
|
|
1479
|
+
const ret = wasm.wasmmincutgatedattention_new(gate_threshold);
|
|
1480
|
+
this.__wbg_ptr = ret >>> 0;
|
|
1481
|
+
WasmMinCutGatedAttentionFinalization.register(this, this.__wbg_ptr, this);
|
|
1482
|
+
return this;
|
|
1483
|
+
}
|
|
1484
|
+
/**
|
|
1485
|
+
* Compute attention scores for the DAG
|
|
1486
|
+
* @param {WasmQueryDag} dag
|
|
1487
|
+
* @returns {Float32Array}
|
|
1488
|
+
*/
|
|
1489
|
+
forward(dag) {
|
|
1490
|
+
try {
|
|
1491
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1492
|
+
_assertClass(dag, WasmQueryDag);
|
|
1493
|
+
wasm.wasmmincutgatedattention_forward(retptr, this.__wbg_ptr, dag.__wbg_ptr);
|
|
1494
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1495
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1496
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1497
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1498
|
+
if (r3) {
|
|
1499
|
+
throw takeObject(r2);
|
|
1500
|
+
}
|
|
1501
|
+
var v1 = getArrayF32FromWasm0(r0, r1).slice();
|
|
1502
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
1503
|
+
return v1;
|
|
1504
|
+
} finally {
|
|
1505
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
if (Symbol.dispose) WasmMinCutGatedAttention.prototype[Symbol.dispose] = WasmMinCutGatedAttention.prototype.free;
|
|
1510
|
+
|
|
1511
|
+
/**
|
|
1512
|
+
* Mixture of Experts attention mechanism
|
|
1513
|
+
*
|
|
1514
|
+
* Routes queries to specialized expert attention heads based on
|
|
1515
|
+
* learned gating functions for capacity-efficient computation
|
|
1516
|
+
*/
|
|
1517
|
+
export class WasmMoEAttention {
|
|
1518
|
+
__destroy_into_raw() {
|
|
1519
|
+
const ptr = this.__wbg_ptr;
|
|
1520
|
+
this.__wbg_ptr = 0;
|
|
1521
|
+
WasmMoEAttentionFinalization.unregister(this);
|
|
1522
|
+
return ptr;
|
|
1523
|
+
}
|
|
1524
|
+
free() {
|
|
1525
|
+
const ptr = this.__destroy_into_raw();
|
|
1526
|
+
wasm.__wbg_wasmmoeattention_free(ptr, 0);
|
|
1527
|
+
}
|
|
1528
|
+
/**
|
|
1529
|
+
* Create a new MoE attention instance
|
|
1530
|
+
*
|
|
1531
|
+
* # Arguments
|
|
1532
|
+
* * `dim` - Embedding dimension
|
|
1533
|
+
* * `num_experts` - Number of expert attention mechanisms
|
|
1534
|
+
* * `top_k` - Number of experts to activate per query
|
|
1535
|
+
* @param {number} dim
|
|
1536
|
+
* @param {number} num_experts
|
|
1537
|
+
* @param {number} top_k
|
|
1538
|
+
*/
|
|
1539
|
+
constructor(dim, num_experts, top_k) {
|
|
1540
|
+
const ret = wasm.wasmmoeattention_new(dim, num_experts, top_k);
|
|
1541
|
+
this.__wbg_ptr = ret >>> 0;
|
|
1542
|
+
WasmMoEAttentionFinalization.register(this, this.__wbg_ptr, this);
|
|
1543
|
+
return this;
|
|
1544
|
+
}
|
|
1545
|
+
/**
|
|
1546
|
+
* Compute MoE attention
|
|
1547
|
+
* @param {Float32Array} query
|
|
1548
|
+
* @param {any} keys
|
|
1549
|
+
* @param {any} values
|
|
1550
|
+
* @returns {Float32Array}
|
|
1551
|
+
*/
|
|
1552
|
+
compute(query, keys, values) {
|
|
1553
|
+
try {
|
|
1554
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1555
|
+
const ptr0 = passArrayF32ToWasm0(query, wasm.__wbindgen_export);
|
|
1556
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1557
|
+
wasm.wasmmoeattention_compute(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(keys), addHeapObject(values));
|
|
1558
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1559
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1560
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1561
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1562
|
+
if (r3) {
|
|
1563
|
+
throw takeObject(r2);
|
|
1564
|
+
}
|
|
1565
|
+
var v2 = getArrayF32FromWasm0(r0, r1).slice();
|
|
1566
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
1567
|
+
return v2;
|
|
1568
|
+
} finally {
|
|
1569
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
if (Symbol.dispose) WasmMoEAttention.prototype[Symbol.dispose] = WasmMoEAttention.prototype.free;
|
|
1574
|
+
|
|
1575
|
+
/**
|
|
1576
|
+
* Multi-head attention mechanism
|
|
1577
|
+
*
|
|
1578
|
+
* Splits input into multiple heads, applies attention, and concatenates results
|
|
1579
|
+
*/
|
|
1580
|
+
export class WasmMultiHeadAttention {
|
|
1581
|
+
__destroy_into_raw() {
|
|
1582
|
+
const ptr = this.__wbg_ptr;
|
|
1583
|
+
this.__wbg_ptr = 0;
|
|
1584
|
+
WasmMultiHeadAttentionFinalization.unregister(this);
|
|
1585
|
+
return ptr;
|
|
1586
|
+
}
|
|
1587
|
+
free() {
|
|
1588
|
+
const ptr = this.__destroy_into_raw();
|
|
1589
|
+
wasm.__wbg_wasmmultiheadattention_free(ptr, 0);
|
|
1590
|
+
}
|
|
1591
|
+
/**
|
|
1592
|
+
* Get the embedding dimension
|
|
1593
|
+
* @returns {number}
|
|
1594
|
+
*/
|
|
1595
|
+
get dim() {
|
|
1596
|
+
const ret = wasm.wasmmultiheadattention_dim(this.__wbg_ptr);
|
|
1597
|
+
return ret >>> 0;
|
|
1598
|
+
}
|
|
1599
|
+
/**
|
|
1600
|
+
* Create a new multi-head attention instance
|
|
1601
|
+
*
|
|
1602
|
+
* # Arguments
|
|
1603
|
+
* * `dim` - Embedding dimension (must be divisible by num_heads)
|
|
1604
|
+
* * `num_heads` - Number of parallel attention heads
|
|
1605
|
+
* @param {number} dim
|
|
1606
|
+
* @param {number} num_heads
|
|
1607
|
+
*/
|
|
1608
|
+
constructor(dim, num_heads) {
|
|
1609
|
+
try {
|
|
1610
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1611
|
+
wasm.wasmmultiheadattention_new(retptr, dim, num_heads);
|
|
1612
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1613
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1614
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1615
|
+
if (r2) {
|
|
1616
|
+
throw takeObject(r1);
|
|
1617
|
+
}
|
|
1618
|
+
this.__wbg_ptr = r0 >>> 0;
|
|
1619
|
+
WasmMultiHeadAttentionFinalization.register(this, this.__wbg_ptr, this);
|
|
1620
|
+
return this;
|
|
1621
|
+
} finally {
|
|
1622
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
/**
|
|
1626
|
+
* Compute multi-head attention
|
|
1627
|
+
*
|
|
1628
|
+
* # Arguments
|
|
1629
|
+
* * `query` - Query vector
|
|
1630
|
+
* * `keys` - Array of key vectors
|
|
1631
|
+
* * `values` - Array of value vectors
|
|
1632
|
+
* @param {Float32Array} query
|
|
1633
|
+
* @param {any} keys
|
|
1634
|
+
* @param {any} values
|
|
1635
|
+
* @returns {Float32Array}
|
|
1636
|
+
*/
|
|
1637
|
+
compute(query, keys, values) {
|
|
1638
|
+
try {
|
|
1639
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1640
|
+
const ptr0 = passArrayF32ToWasm0(query, wasm.__wbindgen_export);
|
|
1641
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1642
|
+
wasm.wasmmultiheadattention_compute(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(keys), addHeapObject(values));
|
|
1643
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1644
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1645
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1646
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1647
|
+
if (r3) {
|
|
1648
|
+
throw takeObject(r2);
|
|
1649
|
+
}
|
|
1650
|
+
var v2 = getArrayF32FromWasm0(r0, r1).slice();
|
|
1651
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
1652
|
+
return v2;
|
|
1653
|
+
} finally {
|
|
1654
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
/**
|
|
1658
|
+
* Get the dimension per head
|
|
1659
|
+
* @returns {number}
|
|
1660
|
+
*/
|
|
1661
|
+
get headDim() {
|
|
1662
|
+
const ret = wasm.wasmmultiheadattention_headDim(this.__wbg_ptr);
|
|
1663
|
+
return ret >>> 0;
|
|
1664
|
+
}
|
|
1665
|
+
/**
|
|
1666
|
+
* Get the number of attention heads
|
|
1667
|
+
* @returns {number}
|
|
1668
|
+
*/
|
|
1669
|
+
get numHeads() {
|
|
1670
|
+
const ret = wasm.wasmmultiheadattention_numHeads(this.__wbg_ptr);
|
|
1671
|
+
return ret >>> 0;
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
if (Symbol.dispose) WasmMultiHeadAttention.prototype[Symbol.dispose] = WasmMultiHeadAttention.prototype.free;
|
|
1675
|
+
|
|
1676
|
+
/**
|
|
1677
|
+
* Parallel branch attention for concurrent DAG branches
|
|
1678
|
+
*
|
|
1679
|
+
* Identifies parallel branches in the DAG and applies
|
|
1680
|
+
* attention patterns that respect branch independence.
|
|
1681
|
+
*/
|
|
1682
|
+
export class WasmParallelBranchAttention {
|
|
1683
|
+
__destroy_into_raw() {
|
|
1684
|
+
const ptr = this.__wbg_ptr;
|
|
1685
|
+
this.__wbg_ptr = 0;
|
|
1686
|
+
WasmParallelBranchAttentionFinalization.unregister(this);
|
|
1687
|
+
return ptr;
|
|
1688
|
+
}
|
|
1689
|
+
free() {
|
|
1690
|
+
const ptr = this.__destroy_into_raw();
|
|
1691
|
+
wasm.__wbg_wasmparallelbranchattention_free(ptr, 0);
|
|
1692
|
+
}
|
|
1693
|
+
/**
|
|
1694
|
+
* Create a new parallel branch attention instance
|
|
1695
|
+
*
|
|
1696
|
+
* # Arguments
|
|
1697
|
+
* * `max_branches` - Maximum number of branches to consider
|
|
1698
|
+
* * `sync_penalty` - Penalty for synchronization between branches
|
|
1699
|
+
* @param {number} max_branches
|
|
1700
|
+
* @param {number} sync_penalty
|
|
1701
|
+
*/
|
|
1702
|
+
constructor(max_branches, sync_penalty) {
|
|
1703
|
+
const ret = wasm.wasmparallelbranchattention_new(max_branches, sync_penalty);
|
|
1704
|
+
this.__wbg_ptr = ret >>> 0;
|
|
1705
|
+
WasmParallelBranchAttentionFinalization.register(this, this.__wbg_ptr, this);
|
|
1706
|
+
return this;
|
|
1707
|
+
}
|
|
1708
|
+
/**
|
|
1709
|
+
* Compute attention scores for the DAG
|
|
1710
|
+
* @param {WasmQueryDag} dag
|
|
1711
|
+
* @returns {Float32Array}
|
|
1712
|
+
*/
|
|
1713
|
+
forward(dag) {
|
|
1714
|
+
try {
|
|
1715
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1716
|
+
_assertClass(dag, WasmQueryDag);
|
|
1717
|
+
wasm.wasmparallelbranchattention_forward(retptr, this.__wbg_ptr, dag.__wbg_ptr);
|
|
1718
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1719
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1720
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1721
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1722
|
+
if (r3) {
|
|
1723
|
+
throw takeObject(r2);
|
|
1724
|
+
}
|
|
1725
|
+
var v1 = getArrayF32FromWasm0(r0, r1).slice();
|
|
1726
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
1727
|
+
return v1;
|
|
1728
|
+
} finally {
|
|
1729
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
if (Symbol.dispose) WasmParallelBranchAttention.prototype[Symbol.dispose] = WasmParallelBranchAttention.prototype.free;
|
|
1734
|
+
|
|
1735
|
+
/**
|
|
1736
|
+
* Minimal DAG structure for WASM attention computation
|
|
1737
|
+
*/
|
|
1738
|
+
export class WasmQueryDag {
|
|
1739
|
+
__destroy_into_raw() {
|
|
1740
|
+
const ptr = this.__wbg_ptr;
|
|
1741
|
+
this.__wbg_ptr = 0;
|
|
1742
|
+
WasmQueryDagFinalization.unregister(this);
|
|
1743
|
+
return ptr;
|
|
1744
|
+
}
|
|
1745
|
+
free() {
|
|
1746
|
+
const ptr = this.__destroy_into_raw();
|
|
1747
|
+
wasm.__wbg_wasmquerydag_free(ptr, 0);
|
|
1748
|
+
}
|
|
1749
|
+
/**
|
|
1750
|
+
* Get the number of edges
|
|
1751
|
+
* @returns {number}
|
|
1752
|
+
*/
|
|
1753
|
+
get edgeCount() {
|
|
1754
|
+
const ret = wasm.wasmquerydag_edgeCount(this.__wbg_ptr);
|
|
1755
|
+
return ret >>> 0;
|
|
1756
|
+
}
|
|
1757
|
+
/**
|
|
1758
|
+
* Get the number of nodes
|
|
1759
|
+
* @returns {number}
|
|
1760
|
+
*/
|
|
1761
|
+
get nodeCount() {
|
|
1762
|
+
const ret = wasm.wasmquerydag_nodeCount(this.__wbg_ptr);
|
|
1763
|
+
return ret >>> 0;
|
|
1764
|
+
}
|
|
1765
|
+
/**
|
|
1766
|
+
* Create a new empty DAG
|
|
1767
|
+
*/
|
|
1768
|
+
constructor() {
|
|
1769
|
+
const ret = wasm.wasmquerydag_new();
|
|
1770
|
+
this.__wbg_ptr = ret >>> 0;
|
|
1771
|
+
WasmQueryDagFinalization.register(this, this.__wbg_ptr, this);
|
|
1772
|
+
return this;
|
|
1773
|
+
}
|
|
1774
|
+
/**
|
|
1775
|
+
* Serialize to JSON
|
|
1776
|
+
* @returns {string}
|
|
1777
|
+
*/
|
|
1778
|
+
toJson() {
|
|
1779
|
+
let deferred1_0;
|
|
1780
|
+
let deferred1_1;
|
|
1781
|
+
try {
|
|
1782
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1783
|
+
wasm.wasmquerydag_toJson(retptr, this.__wbg_ptr);
|
|
1784
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1785
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1786
|
+
deferred1_0 = r0;
|
|
1787
|
+
deferred1_1 = r1;
|
|
1788
|
+
return getStringFromWasm0(r0, r1);
|
|
1789
|
+
} finally {
|
|
1790
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1791
|
+
wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
/**
|
|
1795
|
+
* Add an edge between nodes
|
|
1796
|
+
*
|
|
1797
|
+
* # Arguments
|
|
1798
|
+
* * `from` - Source node ID
|
|
1799
|
+
* * `to` - Target node ID
|
|
1800
|
+
*
|
|
1801
|
+
* # Returns
|
|
1802
|
+
* True if edge was added successfully
|
|
1803
|
+
* @param {number} from
|
|
1804
|
+
* @param {number} to
|
|
1805
|
+
* @returns {boolean}
|
|
1806
|
+
*/
|
|
1807
|
+
addEdge(from, to) {
|
|
1808
|
+
const ret = wasm.wasmquerydag_addEdge(this.__wbg_ptr, from, to);
|
|
1809
|
+
return ret !== 0;
|
|
1810
|
+
}
|
|
1811
|
+
/**
|
|
1812
|
+
* Add a node with operator type and cost
|
|
1813
|
+
*
|
|
1814
|
+
* # Arguments
|
|
1815
|
+
* * `op_type` - Operator type: "scan", "filter", "join", "aggregate", "project", "sort"
|
|
1816
|
+
* * `cost` - Estimated execution cost
|
|
1817
|
+
*
|
|
1818
|
+
* # Returns
|
|
1819
|
+
* Node ID
|
|
1820
|
+
* @param {string} op_type
|
|
1821
|
+
* @param {number} cost
|
|
1822
|
+
* @returns {number}
|
|
1823
|
+
*/
|
|
1824
|
+
addNode(op_type, cost) {
|
|
1825
|
+
const ptr0 = passStringToWasm0(op_type, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
1826
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1827
|
+
const ret = wasm.wasmquerydag_addNode(this.__wbg_ptr, ptr0, len0, cost);
|
|
1828
|
+
return ret >>> 0;
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
if (Symbol.dispose) WasmQueryDag.prototype[Symbol.dispose] = WasmQueryDag.prototype.free;
|
|
1832
|
+
|
|
1833
|
+
/**
|
|
1834
|
+
* Search configuration for differentiable search
|
|
1835
|
+
*/
|
|
1836
|
+
export class WasmSearchConfig {
|
|
1837
|
+
__destroy_into_raw() {
|
|
1838
|
+
const ptr = this.__wbg_ptr;
|
|
1839
|
+
this.__wbg_ptr = 0;
|
|
1840
|
+
WasmSearchConfigFinalization.unregister(this);
|
|
1841
|
+
return ptr;
|
|
1842
|
+
}
|
|
1843
|
+
free() {
|
|
1844
|
+
const ptr = this.__destroy_into_raw();
|
|
1845
|
+
wasm.__wbg_wasmsearchconfig_free(ptr, 0);
|
|
1846
|
+
}
|
|
1847
|
+
/**
|
|
1848
|
+
* Create a new search configuration
|
|
1849
|
+
* @param {number} k
|
|
1850
|
+
* @param {number} temperature
|
|
1851
|
+
*/
|
|
1852
|
+
constructor(k, temperature) {
|
|
1853
|
+
const ret = wasm.wasmparallelbranchattention_new(k, temperature);
|
|
1854
|
+
this.__wbg_ptr = ret >>> 0;
|
|
1855
|
+
WasmSearchConfigFinalization.register(this, this.__wbg_ptr, this);
|
|
1856
|
+
return this;
|
|
1857
|
+
}
|
|
1858
|
+
/**
|
|
1859
|
+
* Number of top results to return
|
|
1860
|
+
* @returns {number}
|
|
1861
|
+
*/
|
|
1862
|
+
get k() {
|
|
1863
|
+
const ret = wasm.__wbg_get_mambaconfig_dim(this.__wbg_ptr);
|
|
1864
|
+
return ret >>> 0;
|
|
1865
|
+
}
|
|
1866
|
+
/**
|
|
1867
|
+
* Number of top results to return
|
|
1868
|
+
* @param {number} arg0
|
|
1869
|
+
*/
|
|
1870
|
+
set k(arg0) {
|
|
1871
|
+
wasm.__wbg_set_mambaconfig_dim(this.__wbg_ptr, arg0);
|
|
1872
|
+
}
|
|
1873
|
+
/**
|
|
1874
|
+
* Temperature for softmax
|
|
1875
|
+
* @returns {number}
|
|
1876
|
+
*/
|
|
1877
|
+
get temperature() {
|
|
1878
|
+
const ret = wasm.__wbg_get_wasmsearchconfig_temperature(this.__wbg_ptr);
|
|
1879
|
+
return ret;
|
|
1880
|
+
}
|
|
1881
|
+
/**
|
|
1882
|
+
* Temperature for softmax
|
|
1883
|
+
* @param {number} arg0
|
|
1884
|
+
*/
|
|
1885
|
+
set temperature(arg0) {
|
|
1886
|
+
wasm.__wbg_set_wasmsearchconfig_temperature(this.__wbg_ptr, arg0);
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
if (Symbol.dispose) WasmSearchConfig.prototype[Symbol.dispose] = WasmSearchConfig.prototype.free;
|
|
1890
|
+
|
|
1891
|
+
/**
|
|
1892
|
+
* Temporal BTSP (Behavioral Time-Series Pattern) attention
|
|
1893
|
+
*
|
|
1894
|
+
* Incorporates temporal patterns and behavioral sequences
|
|
1895
|
+
* for time-aware DAG attention.
|
|
1896
|
+
*/
|
|
1897
|
+
export class WasmTemporalBTSPAttention {
|
|
1898
|
+
__destroy_into_raw() {
|
|
1899
|
+
const ptr = this.__wbg_ptr;
|
|
1900
|
+
this.__wbg_ptr = 0;
|
|
1901
|
+
WasmTemporalBTSPAttentionFinalization.unregister(this);
|
|
1902
|
+
return ptr;
|
|
1903
|
+
}
|
|
1904
|
+
free() {
|
|
1905
|
+
const ptr = this.__destroy_into_raw();
|
|
1906
|
+
wasm.__wbg_wasmtemporalbtspattention_free(ptr, 0);
|
|
1907
|
+
}
|
|
1908
|
+
/**
|
|
1909
|
+
* Create a new temporal BTSP attention instance
|
|
1910
|
+
*
|
|
1911
|
+
* # Arguments
|
|
1912
|
+
* * `eligibility_decay` - Decay rate for eligibility traces (0.0-1.0)
|
|
1913
|
+
* * `baseline_attention` - Baseline attention for nodes without history
|
|
1914
|
+
* @param {number} eligibility_decay
|
|
1915
|
+
* @param {number} baseline_attention
|
|
1916
|
+
*/
|
|
1917
|
+
constructor(eligibility_decay, baseline_attention) {
|
|
1918
|
+
const ret = wasm.wasmcausalconeattention_new(eligibility_decay, baseline_attention);
|
|
1919
|
+
this.__wbg_ptr = ret >>> 0;
|
|
1920
|
+
WasmTemporalBTSPAttentionFinalization.register(this, this.__wbg_ptr, this);
|
|
1921
|
+
return this;
|
|
1922
|
+
}
|
|
1923
|
+
/**
|
|
1924
|
+
* Compute attention scores for the DAG
|
|
1925
|
+
* @param {WasmQueryDag} dag
|
|
1926
|
+
* @returns {Float32Array}
|
|
1927
|
+
*/
|
|
1928
|
+
forward(dag) {
|
|
1929
|
+
try {
|
|
1930
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1931
|
+
_assertClass(dag, WasmQueryDag);
|
|
1932
|
+
wasm.wasmtemporalbtspattention_forward(retptr, this.__wbg_ptr, dag.__wbg_ptr);
|
|
1933
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1934
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1935
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1936
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1937
|
+
if (r3) {
|
|
1938
|
+
throw takeObject(r2);
|
|
1939
|
+
}
|
|
1940
|
+
var v1 = getArrayF32FromWasm0(r0, r1).slice();
|
|
1941
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
1942
|
+
return v1;
|
|
1943
|
+
} finally {
|
|
1944
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
if (Symbol.dispose) WasmTemporalBTSPAttention.prototype[Symbol.dispose] = WasmTemporalBTSPAttention.prototype.free;
|
|
1949
|
+
|
|
1950
|
+
/**
|
|
1951
|
+
* Tensor compressor with adaptive level selection
|
|
1952
|
+
*
|
|
1953
|
+
* Compresses embeddings based on access frequency for memory-efficient GNN
|
|
1954
|
+
*/
|
|
1955
|
+
export class WasmTensorCompress {
|
|
1956
|
+
__destroy_into_raw() {
|
|
1957
|
+
const ptr = this.__wbg_ptr;
|
|
1958
|
+
this.__wbg_ptr = 0;
|
|
1959
|
+
WasmTensorCompressFinalization.unregister(this);
|
|
1960
|
+
return ptr;
|
|
1961
|
+
}
|
|
1962
|
+
free() {
|
|
1963
|
+
const ptr = this.__destroy_into_raw();
|
|
1964
|
+
wasm.__wbg_wasmtensorcompress_free(ptr, 0);
|
|
1965
|
+
}
|
|
1966
|
+
/**
|
|
1967
|
+
* Decompress a compressed tensor
|
|
1968
|
+
* @param {any} compressed
|
|
1969
|
+
* @returns {Float32Array}
|
|
1970
|
+
*/
|
|
1971
|
+
decompress(compressed) {
|
|
1972
|
+
try {
|
|
1973
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1974
|
+
wasm.wasmtensorcompress_decompress(retptr, this.__wbg_ptr, addHeapObject(compressed));
|
|
1975
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1976
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1977
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1978
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1979
|
+
if (r3) {
|
|
1980
|
+
throw takeObject(r2);
|
|
1981
|
+
}
|
|
1982
|
+
var v1 = getArrayF32FromWasm0(r0, r1).slice();
|
|
1983
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
1984
|
+
return v1;
|
|
1985
|
+
} finally {
|
|
1986
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1987
|
+
}
|
|
1988
|
+
}
|
|
1989
|
+
/**
|
|
1990
|
+
* Compress with explicit compression level
|
|
1991
|
+
*
|
|
1992
|
+
* # Arguments
|
|
1993
|
+
* * `embedding` - The input embedding vector
|
|
1994
|
+
* * `level` - Compression level: "none", "half", "pq8", "pq4", "binary"
|
|
1995
|
+
* @param {Float32Array} embedding
|
|
1996
|
+
* @param {string} level
|
|
1997
|
+
* @returns {any}
|
|
1998
|
+
*/
|
|
1999
|
+
compressWithLevel(embedding, level) {
|
|
2000
|
+
try {
|
|
2001
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
2002
|
+
const ptr0 = passArrayF32ToWasm0(embedding, wasm.__wbindgen_export);
|
|
2003
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2004
|
+
const ptr1 = passStringToWasm0(level, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
2005
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2006
|
+
wasm.wasmtensorcompress_compressWithLevel(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
2007
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
2008
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
2009
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
2010
|
+
if (r2) {
|
|
2011
|
+
throw takeObject(r1);
|
|
2012
|
+
}
|
|
2013
|
+
return takeObject(r0);
|
|
2014
|
+
} finally {
|
|
2015
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
/**
|
|
2019
|
+
* Get compression ratio estimate for a given access frequency
|
|
2020
|
+
* @param {number} access_freq
|
|
2021
|
+
* @returns {number}
|
|
2022
|
+
*/
|
|
2023
|
+
getCompressionRatio(access_freq) {
|
|
2024
|
+
const ret = wasm.wasmtensorcompress_getCompressionRatio(this.__wbg_ptr, access_freq);
|
|
2025
|
+
return ret;
|
|
2026
|
+
}
|
|
2027
|
+
/**
|
|
2028
|
+
* Create a new tensor compressor
|
|
2029
|
+
*/
|
|
2030
|
+
constructor() {
|
|
2031
|
+
const ret = wasm.wasmtensorcompress_new();
|
|
2032
|
+
this.__wbg_ptr = ret >>> 0;
|
|
2033
|
+
WasmTensorCompressFinalization.register(this, this.__wbg_ptr, this);
|
|
2034
|
+
return this;
|
|
2035
|
+
}
|
|
2036
|
+
/**
|
|
2037
|
+
* Compress an embedding based on access frequency
|
|
2038
|
+
*
|
|
2039
|
+
* # Arguments
|
|
2040
|
+
* * `embedding` - The input embedding vector
|
|
2041
|
+
* * `access_freq` - Access frequency in range [0.0, 1.0]
|
|
2042
|
+
* - f > 0.8: Full precision (hot data)
|
|
2043
|
+
* - f > 0.4: Half precision (warm data)
|
|
2044
|
+
* - f > 0.1: 8-bit PQ (cool data)
|
|
2045
|
+
* - f > 0.01: 4-bit PQ (cold data)
|
|
2046
|
+
* - f <= 0.01: Binary (archive)
|
|
2047
|
+
* @param {Float32Array} embedding
|
|
2048
|
+
* @param {number} access_freq
|
|
2049
|
+
* @returns {any}
|
|
2050
|
+
*/
|
|
2051
|
+
compress(embedding, access_freq) {
|
|
2052
|
+
try {
|
|
2053
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
2054
|
+
const ptr0 = passArrayF32ToWasm0(embedding, wasm.__wbindgen_export);
|
|
2055
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2056
|
+
wasm.wasmtensorcompress_compress(retptr, this.__wbg_ptr, ptr0, len0, access_freq);
|
|
2057
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
2058
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
2059
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
2060
|
+
if (r2) {
|
|
2061
|
+
throw takeObject(r1);
|
|
2062
|
+
}
|
|
2063
|
+
return takeObject(r0);
|
|
2064
|
+
} finally {
|
|
2065
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
if (Symbol.dispose) WasmTensorCompress.prototype[Symbol.dispose] = WasmTensorCompress.prototype.free;
|
|
2070
|
+
|
|
2071
|
+
/**
|
|
2072
|
+
* Topological attention based on DAG position
|
|
2073
|
+
*
|
|
2074
|
+
* Assigns attention scores based on node position in topological order.
|
|
2075
|
+
* Earlier nodes (closer to sources) get higher attention.
|
|
2076
|
+
*/
|
|
2077
|
+
export class WasmTopologicalAttention {
|
|
2078
|
+
__destroy_into_raw() {
|
|
2079
|
+
const ptr = this.__wbg_ptr;
|
|
2080
|
+
this.__wbg_ptr = 0;
|
|
2081
|
+
WasmTopologicalAttentionFinalization.unregister(this);
|
|
2082
|
+
return ptr;
|
|
2083
|
+
}
|
|
2084
|
+
free() {
|
|
2085
|
+
const ptr = this.__destroy_into_raw();
|
|
2086
|
+
wasm.__wbg_wasmtopologicalattention_free(ptr, 0);
|
|
2087
|
+
}
|
|
2088
|
+
/**
|
|
2089
|
+
* Create a new topological attention instance
|
|
2090
|
+
*
|
|
2091
|
+
* # Arguments
|
|
2092
|
+
* * `decay_factor` - Decay factor for position-based attention (0.0-1.0)
|
|
2093
|
+
* @param {number} decay_factor
|
|
2094
|
+
*/
|
|
2095
|
+
constructor(decay_factor) {
|
|
2096
|
+
const ret = wasm.wasmmincutgatedattention_new(decay_factor);
|
|
2097
|
+
this.__wbg_ptr = ret >>> 0;
|
|
2098
|
+
WasmTopologicalAttentionFinalization.register(this, this.__wbg_ptr, this);
|
|
2099
|
+
return this;
|
|
2100
|
+
}
|
|
2101
|
+
/**
|
|
2102
|
+
* Compute attention scores for the DAG
|
|
2103
|
+
*
|
|
2104
|
+
* # Returns
|
|
2105
|
+
* Attention scores for each node
|
|
2106
|
+
* @param {WasmQueryDag} dag
|
|
2107
|
+
* @returns {Float32Array}
|
|
2108
|
+
*/
|
|
2109
|
+
forward(dag) {
|
|
2110
|
+
try {
|
|
2111
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
2112
|
+
_assertClass(dag, WasmQueryDag);
|
|
2113
|
+
wasm.wasmtopologicalattention_forward(retptr, this.__wbg_ptr, dag.__wbg_ptr);
|
|
2114
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
2115
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
2116
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
2117
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
2118
|
+
if (r3) {
|
|
2119
|
+
throw takeObject(r2);
|
|
2120
|
+
}
|
|
2121
|
+
var v1 = getArrayF32FromWasm0(r0, r1).slice();
|
|
2122
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
2123
|
+
return v1;
|
|
2124
|
+
} finally {
|
|
2125
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
2126
|
+
}
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
if (Symbol.dispose) WasmTopologicalAttention.prototype[Symbol.dispose] = WasmTopologicalAttention.prototype.free;
|
|
2130
|
+
|
|
2131
|
+
/**
|
|
2132
|
+
* Get information about all available attention mechanisms
|
|
2133
|
+
* @returns {any}
|
|
2134
|
+
*/
|
|
2135
|
+
export function availableMechanisms() {
|
|
2136
|
+
const ret = wasm.availableMechanisms();
|
|
2137
|
+
return takeObject(ret);
|
|
2138
|
+
}
|
|
2139
|
+
|
|
2140
|
+
/**
|
|
2141
|
+
* Compute cosine similarity between two vectors
|
|
2142
|
+
* @param {Float32Array} a
|
|
2143
|
+
* @param {Float32Array} b
|
|
2144
|
+
* @returns {number}
|
|
2145
|
+
*/
|
|
2146
|
+
export function cosineSimilarity(a, b) {
|
|
2147
|
+
try {
|
|
2148
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
2149
|
+
const ptr0 = passArrayF32ToWasm0(a, wasm.__wbindgen_export);
|
|
2150
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2151
|
+
const ptr1 = passArrayF32ToWasm0(b, wasm.__wbindgen_export);
|
|
2152
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2153
|
+
wasm.cosineSimilarity(retptr, ptr0, len0, ptr1, len1);
|
|
2154
|
+
var r0 = getDataViewMemory0().getFloat32(retptr + 4 * 0, true);
|
|
2155
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
2156
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
2157
|
+
if (r2) {
|
|
2158
|
+
throw takeObject(r1);
|
|
2159
|
+
}
|
|
2160
|
+
return r0;
|
|
2161
|
+
} finally {
|
|
2162
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
2163
|
+
}
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
/**
|
|
2167
|
+
* Get summary statistics about the unified attention library
|
|
2168
|
+
* @returns {any}
|
|
2169
|
+
*/
|
|
2170
|
+
export function getStats() {
|
|
2171
|
+
const ret = wasm.getStats();
|
|
2172
|
+
return takeObject(ret);
|
|
2173
|
+
}
|
|
2174
|
+
|
|
2175
|
+
/**
|
|
2176
|
+
* Differentiable search using soft attention mechanism
|
|
2177
|
+
*
|
|
2178
|
+
* # Arguments
|
|
2179
|
+
* * `query` - The query vector
|
|
2180
|
+
* * `candidate_embeddings` - List of candidate embedding vectors
|
|
2181
|
+
* * `config` - Search configuration
|
|
2182
|
+
*
|
|
2183
|
+
* # Returns
|
|
2184
|
+
* Object with indices and weights for top-k candidates
|
|
2185
|
+
* @param {Float32Array} query
|
|
2186
|
+
* @param {any} candidate_embeddings
|
|
2187
|
+
* @param {WasmSearchConfig} config
|
|
2188
|
+
* @returns {any}
|
|
2189
|
+
*/
|
|
2190
|
+
export function graphDifferentiableSearch(query, candidate_embeddings, config) {
|
|
2191
|
+
try {
|
|
2192
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
2193
|
+
const ptr0 = passArrayF32ToWasm0(query, wasm.__wbindgen_export);
|
|
2194
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2195
|
+
_assertClass(config, WasmSearchConfig);
|
|
2196
|
+
wasm.graphDifferentiableSearch(retptr, ptr0, len0, addHeapObject(candidate_embeddings), config.__wbg_ptr);
|
|
2197
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
2198
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
2199
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
2200
|
+
if (r2) {
|
|
2201
|
+
throw takeObject(r1);
|
|
2202
|
+
}
|
|
2203
|
+
return takeObject(r0);
|
|
2204
|
+
} finally {
|
|
2205
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
2206
|
+
}
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2209
|
+
/**
|
|
2210
|
+
* Hierarchical forward pass through multiple GNN layers
|
|
2211
|
+
*
|
|
2212
|
+
* # Arguments
|
|
2213
|
+
* * `query` - The query vector
|
|
2214
|
+
* * `layer_embeddings` - Embeddings organized by layer
|
|
2215
|
+
* * `gnn_layers` - Array of GNN layers
|
|
2216
|
+
*
|
|
2217
|
+
* # Returns
|
|
2218
|
+
* Final embedding after hierarchical processing
|
|
2219
|
+
* @param {Float32Array} query
|
|
2220
|
+
* @param {any} layer_embeddings
|
|
2221
|
+
* @param {WasmGNNLayer[]} gnn_layers
|
|
2222
|
+
* @returns {Float32Array}
|
|
2223
|
+
*/
|
|
2224
|
+
export function graphHierarchicalForward(query, layer_embeddings, gnn_layers) {
|
|
2225
|
+
try {
|
|
2226
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
2227
|
+
const ptr0 = passArrayF32ToWasm0(query, wasm.__wbindgen_export);
|
|
2228
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2229
|
+
const ptr1 = passArrayJsValueToWasm0(gnn_layers, wasm.__wbindgen_export);
|
|
2230
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2231
|
+
wasm.graphHierarchicalForward(retptr, ptr0, len0, addHeapObject(layer_embeddings), ptr1, len1);
|
|
2232
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
2233
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
2234
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
2235
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
2236
|
+
if (r3) {
|
|
2237
|
+
throw takeObject(r2);
|
|
2238
|
+
}
|
|
2239
|
+
var v3 = getArrayF32FromWasm0(r0, r1).slice();
|
|
2240
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
2241
|
+
return v3;
|
|
2242
|
+
} finally {
|
|
2243
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
|
|
2247
|
+
/**
|
|
2248
|
+
* Initialize the WASM module with panic hook for better error messages
|
|
2249
|
+
*/
|
|
2250
|
+
export function init() {
|
|
2251
|
+
wasm.init();
|
|
2252
|
+
}
|
|
2253
|
+
|
|
2254
|
+
/**
|
|
2255
|
+
* Compute scaled dot-product attention
|
|
2256
|
+
*
|
|
2257
|
+
* Standard transformer attention: softmax(QK^T / sqrt(d)) * V
|
|
2258
|
+
*
|
|
2259
|
+
* # Arguments
|
|
2260
|
+
* * `query` - Query vector (Float32Array)
|
|
2261
|
+
* * `keys` - Array of key vectors (JsValue - array of Float32Arrays)
|
|
2262
|
+
* * `values` - Array of value vectors (JsValue - array of Float32Arrays)
|
|
2263
|
+
* * `scale` - Optional scaling factor (defaults to 1/sqrt(dim))
|
|
2264
|
+
*
|
|
2265
|
+
* # Returns
|
|
2266
|
+
* Attention-weighted output vector
|
|
2267
|
+
* @param {Float32Array} query
|
|
2268
|
+
* @param {any} keys
|
|
2269
|
+
* @param {any} values
|
|
2270
|
+
* @param {number | null} [scale]
|
|
2271
|
+
* @returns {Float32Array}
|
|
2272
|
+
*/
|
|
2273
|
+
export function scaledDotAttention(query, keys, values, scale) {
|
|
2274
|
+
try {
|
|
2275
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
2276
|
+
const ptr0 = passArrayF32ToWasm0(query, wasm.__wbindgen_export);
|
|
2277
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2278
|
+
wasm.scaledDotAttention(retptr, ptr0, len0, addHeapObject(keys), addHeapObject(values), isLikeNone(scale) ? 0x100000001 : Math.fround(scale));
|
|
2279
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
2280
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
2281
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
2282
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
2283
|
+
if (r3) {
|
|
2284
|
+
throw takeObject(r2);
|
|
2285
|
+
}
|
|
2286
|
+
var v2 = getArrayF32FromWasm0(r0, r1).slice();
|
|
2287
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
2288
|
+
return v2;
|
|
2289
|
+
} finally {
|
|
2290
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
|
|
2294
|
+
/**
|
|
2295
|
+
* Softmax normalization
|
|
2296
|
+
* @param {Float32Array} values
|
|
2297
|
+
* @returns {Float32Array}
|
|
2298
|
+
*/
|
|
2299
|
+
export function softmax(values) {
|
|
2300
|
+
try {
|
|
2301
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
2302
|
+
const ptr0 = passArrayF32ToWasm0(values, wasm.__wbindgen_export);
|
|
2303
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2304
|
+
wasm.softmax(retptr, ptr0, len0);
|
|
2305
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
2306
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
2307
|
+
var v2 = getArrayF32FromWasm0(r0, r1).slice();
|
|
2308
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
2309
|
+
return v2;
|
|
2310
|
+
} finally {
|
|
2311
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
2312
|
+
}
|
|
2313
|
+
}
|
|
2314
|
+
|
|
2315
|
+
/**
|
|
2316
|
+
* Temperature-scaled softmax
|
|
2317
|
+
* @param {Float32Array} values
|
|
2318
|
+
* @param {number} temperature
|
|
2319
|
+
* @returns {Float32Array}
|
|
2320
|
+
*/
|
|
2321
|
+
export function temperatureSoftmax(values, temperature) {
|
|
2322
|
+
try {
|
|
2323
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
2324
|
+
const ptr0 = passArrayF32ToWasm0(values, wasm.__wbindgen_export);
|
|
2325
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2326
|
+
wasm.temperatureSoftmax(retptr, ptr0, len0, temperature);
|
|
2327
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
2328
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
2329
|
+
var v2 = getArrayF32FromWasm0(r0, r1).slice();
|
|
2330
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
2331
|
+
return v2;
|
|
2332
|
+
} finally {
|
|
2333
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
2334
|
+
}
|
|
2335
|
+
}
|
|
2336
|
+
|
|
2337
|
+
/**
|
|
2338
|
+
* Get the version of the unified attention WASM crate
|
|
2339
|
+
* @returns {string}
|
|
2340
|
+
*/
|
|
2341
|
+
export function version() {
|
|
2342
|
+
let deferred1_0;
|
|
2343
|
+
let deferred1_1;
|
|
2344
|
+
try {
|
|
2345
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
2346
|
+
wasm.version(retptr);
|
|
2347
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
2348
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
2349
|
+
deferred1_0 = r0;
|
|
2350
|
+
deferred1_1 = r1;
|
|
2351
|
+
return getStringFromWasm0(r0, r1);
|
|
2352
|
+
} finally {
|
|
2353
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
2354
|
+
wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2357
|
+
|
|
2358
|
+
const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
|
|
2359
|
+
|
|
2360
|
+
async function __wbg_load(module, imports) {
|
|
2361
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
2362
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
2363
|
+
try {
|
|
2364
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
2365
|
+
} catch (e) {
|
|
2366
|
+
const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
|
|
2367
|
+
|
|
2368
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
2369
|
+
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);
|
|
2370
|
+
|
|
2371
|
+
} else {
|
|
2372
|
+
throw e;
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
|
|
2377
|
+
const bytes = await module.arrayBuffer();
|
|
2378
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
2379
|
+
} else {
|
|
2380
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
2381
|
+
|
|
2382
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
2383
|
+
return { instance, module };
|
|
2384
|
+
} else {
|
|
2385
|
+
return instance;
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
|
|
2390
|
+
function __wbg_get_imports() {
|
|
2391
|
+
const imports = {};
|
|
2392
|
+
imports.wbg = {};
|
|
2393
|
+
imports.wbg.__wbg_Error_52673b7de5a0ca89 = function(arg0, arg1) {
|
|
2394
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
2395
|
+
return addHeapObject(ret);
|
|
2396
|
+
};
|
|
2397
|
+
imports.wbg.__wbg_Number_2d1dcfcf4ec51736 = function(arg0) {
|
|
2398
|
+
const ret = Number(getObject(arg0));
|
|
2399
|
+
return ret;
|
|
2400
|
+
};
|
|
2401
|
+
imports.wbg.__wbg_String_8f0eb39a4a4c2f66 = function(arg0, arg1) {
|
|
2402
|
+
const ret = String(getObject(arg1));
|
|
2403
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
2404
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2405
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
2406
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
2407
|
+
};
|
|
2408
|
+
imports.wbg.__wbg___wbindgen_bigint_get_as_i64_6e32f5e6aff02e1d = function(arg0, arg1) {
|
|
2409
|
+
const v = getObject(arg1);
|
|
2410
|
+
const ret = typeof(v) === 'bigint' ? v : undefined;
|
|
2411
|
+
getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
|
|
2412
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
2413
|
+
};
|
|
2414
|
+
imports.wbg.__wbg___wbindgen_boolean_get_dea25b33882b895b = function(arg0) {
|
|
2415
|
+
const v = getObject(arg0);
|
|
2416
|
+
const ret = typeof(v) === 'boolean' ? v : undefined;
|
|
2417
|
+
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
2418
|
+
};
|
|
2419
|
+
imports.wbg.__wbg___wbindgen_debug_string_adfb662ae34724b6 = function(arg0, arg1) {
|
|
2420
|
+
const ret = debugString(getObject(arg1));
|
|
2421
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
2422
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2423
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
2424
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
2425
|
+
};
|
|
2426
|
+
imports.wbg.__wbg___wbindgen_in_0d3e1e8f0c669317 = function(arg0, arg1) {
|
|
2427
|
+
const ret = getObject(arg0) in getObject(arg1);
|
|
2428
|
+
return ret;
|
|
2429
|
+
};
|
|
2430
|
+
imports.wbg.__wbg___wbindgen_is_bigint_0e1a2e3f55cfae27 = function(arg0) {
|
|
2431
|
+
const ret = typeof(getObject(arg0)) === 'bigint';
|
|
2432
|
+
return ret;
|
|
2433
|
+
};
|
|
2434
|
+
imports.wbg.__wbg___wbindgen_is_function_8d400b8b1af978cd = function(arg0) {
|
|
2435
|
+
const ret = typeof(getObject(arg0)) === 'function';
|
|
2436
|
+
return ret;
|
|
2437
|
+
};
|
|
2438
|
+
imports.wbg.__wbg___wbindgen_is_object_ce774f3490692386 = function(arg0) {
|
|
2439
|
+
const val = getObject(arg0);
|
|
2440
|
+
const ret = typeof(val) === 'object' && val !== null;
|
|
2441
|
+
return ret;
|
|
2442
|
+
};
|
|
2443
|
+
imports.wbg.__wbg___wbindgen_is_string_704ef9c8fc131030 = function(arg0) {
|
|
2444
|
+
const ret = typeof(getObject(arg0)) === 'string';
|
|
2445
|
+
return ret;
|
|
2446
|
+
};
|
|
2447
|
+
imports.wbg.__wbg___wbindgen_is_undefined_f6b95eab589e0269 = function(arg0) {
|
|
2448
|
+
const ret = getObject(arg0) === undefined;
|
|
2449
|
+
return ret;
|
|
2450
|
+
};
|
|
2451
|
+
imports.wbg.__wbg___wbindgen_jsval_eq_b6101cc9cef1fe36 = function(arg0, arg1) {
|
|
2452
|
+
const ret = getObject(arg0) === getObject(arg1);
|
|
2453
|
+
return ret;
|
|
2454
|
+
};
|
|
2455
|
+
imports.wbg.__wbg___wbindgen_jsval_loose_eq_766057600fdd1b0d = function(arg0, arg1) {
|
|
2456
|
+
const ret = getObject(arg0) == getObject(arg1);
|
|
2457
|
+
return ret;
|
|
2458
|
+
};
|
|
2459
|
+
imports.wbg.__wbg___wbindgen_number_get_9619185a74197f95 = function(arg0, arg1) {
|
|
2460
|
+
const obj = getObject(arg1);
|
|
2461
|
+
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
2462
|
+
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
2463
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
2464
|
+
};
|
|
2465
|
+
imports.wbg.__wbg___wbindgen_string_get_a2a31e16edf96e42 = function(arg0, arg1) {
|
|
2466
|
+
const obj = getObject(arg1);
|
|
2467
|
+
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
2468
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
2469
|
+
var len1 = WASM_VECTOR_LEN;
|
|
2470
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
2471
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
2472
|
+
};
|
|
2473
|
+
imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
|
|
2474
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
2475
|
+
};
|
|
2476
|
+
imports.wbg.__wbg_call_3020136f7a2d6e44 = function() { return handleError(function (arg0, arg1, arg2) {
|
|
2477
|
+
const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
|
|
2478
|
+
return addHeapObject(ret);
|
|
2479
|
+
}, arguments) };
|
|
2480
|
+
imports.wbg.__wbg_call_abb4ff46ce38be40 = function() { return handleError(function (arg0, arg1) {
|
|
2481
|
+
const ret = getObject(arg0).call(getObject(arg1));
|
|
2482
|
+
return addHeapObject(ret);
|
|
2483
|
+
}, arguments) };
|
|
2484
|
+
imports.wbg.__wbg_crypto_574e78ad8b13b65f = function(arg0) {
|
|
2485
|
+
const ret = getObject(arg0).crypto;
|
|
2486
|
+
return addHeapObject(ret);
|
|
2487
|
+
};
|
|
2488
|
+
imports.wbg.__wbg_done_62ea16af4ce34b24 = function(arg0) {
|
|
2489
|
+
const ret = getObject(arg0).done;
|
|
2490
|
+
return ret;
|
|
2491
|
+
};
|
|
2492
|
+
imports.wbg.__wbg_entries_83c79938054e065f = function(arg0) {
|
|
2493
|
+
const ret = Object.entries(getObject(arg0));
|
|
2494
|
+
return addHeapObject(ret);
|
|
2495
|
+
};
|
|
2496
|
+
imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
|
|
2497
|
+
let deferred0_0;
|
|
2498
|
+
let deferred0_1;
|
|
2499
|
+
try {
|
|
2500
|
+
deferred0_0 = arg0;
|
|
2501
|
+
deferred0_1 = arg1;
|
|
2502
|
+
console.error(getStringFromWasm0(arg0, arg1));
|
|
2503
|
+
} finally {
|
|
2504
|
+
wasm.__wbindgen_export4(deferred0_0, deferred0_1, 1);
|
|
2505
|
+
}
|
|
2506
|
+
};
|
|
2507
|
+
imports.wbg.__wbg_getRandomValues_b8f5dbd5f3995a9e = function() { return handleError(function (arg0, arg1) {
|
|
2508
|
+
getObject(arg0).getRandomValues(getObject(arg1));
|
|
2509
|
+
}, arguments) };
|
|
2510
|
+
imports.wbg.__wbg_get_6b7bd52aca3f9671 = function(arg0, arg1) {
|
|
2511
|
+
const ret = getObject(arg0)[arg1 >>> 0];
|
|
2512
|
+
return addHeapObject(ret);
|
|
2513
|
+
};
|
|
2514
|
+
imports.wbg.__wbg_get_af9dab7e9603ea93 = function() { return handleError(function (arg0, arg1) {
|
|
2515
|
+
const ret = Reflect.get(getObject(arg0), getObject(arg1));
|
|
2516
|
+
return addHeapObject(ret);
|
|
2517
|
+
}, arguments) };
|
|
2518
|
+
imports.wbg.__wbg_get_with_ref_key_1dc361bd10053bfe = function(arg0, arg1) {
|
|
2519
|
+
const ret = getObject(arg0)[getObject(arg1)];
|
|
2520
|
+
return addHeapObject(ret);
|
|
2521
|
+
};
|
|
2522
|
+
imports.wbg.__wbg_instanceof_ArrayBuffer_f3320d2419cd0355 = function(arg0) {
|
|
2523
|
+
let result;
|
|
2524
|
+
try {
|
|
2525
|
+
result = getObject(arg0) instanceof ArrayBuffer;
|
|
2526
|
+
} catch (_) {
|
|
2527
|
+
result = false;
|
|
2528
|
+
}
|
|
2529
|
+
const ret = result;
|
|
2530
|
+
return ret;
|
|
2531
|
+
};
|
|
2532
|
+
imports.wbg.__wbg_instanceof_Uint8Array_da54ccc9d3e09434 = function(arg0) {
|
|
2533
|
+
let result;
|
|
2534
|
+
try {
|
|
2535
|
+
result = getObject(arg0) instanceof Uint8Array;
|
|
2536
|
+
} catch (_) {
|
|
2537
|
+
result = false;
|
|
2538
|
+
}
|
|
2539
|
+
const ret = result;
|
|
2540
|
+
return ret;
|
|
2541
|
+
};
|
|
2542
|
+
imports.wbg.__wbg_isArray_51fd9e6422c0a395 = function(arg0) {
|
|
2543
|
+
const ret = Array.isArray(getObject(arg0));
|
|
2544
|
+
return ret;
|
|
2545
|
+
};
|
|
2546
|
+
imports.wbg.__wbg_isSafeInteger_ae7d3f054d55fa16 = function(arg0) {
|
|
2547
|
+
const ret = Number.isSafeInteger(getObject(arg0));
|
|
2548
|
+
return ret;
|
|
2549
|
+
};
|
|
2550
|
+
imports.wbg.__wbg_iterator_27b7c8b35ab3e86b = function() {
|
|
2551
|
+
const ret = Symbol.iterator;
|
|
2552
|
+
return addHeapObject(ret);
|
|
2553
|
+
};
|
|
2554
|
+
imports.wbg.__wbg_length_22ac23eaec9d8053 = function(arg0) {
|
|
2555
|
+
const ret = getObject(arg0).length;
|
|
2556
|
+
return ret;
|
|
2557
|
+
};
|
|
2558
|
+
imports.wbg.__wbg_length_d45040a40c570362 = function(arg0) {
|
|
2559
|
+
const ret = getObject(arg0).length;
|
|
2560
|
+
return ret;
|
|
2561
|
+
};
|
|
2562
|
+
imports.wbg.__wbg_msCrypto_a61aeb35a24c1329 = function(arg0) {
|
|
2563
|
+
const ret = getObject(arg0).msCrypto;
|
|
2564
|
+
return addHeapObject(ret);
|
|
2565
|
+
};
|
|
2566
|
+
imports.wbg.__wbg_new_1ba21ce319a06297 = function() {
|
|
2567
|
+
const ret = new Object();
|
|
2568
|
+
return addHeapObject(ret);
|
|
2569
|
+
};
|
|
2570
|
+
imports.wbg.__wbg_new_25f239778d6112b9 = function() {
|
|
2571
|
+
const ret = new Array();
|
|
2572
|
+
return addHeapObject(ret);
|
|
2573
|
+
};
|
|
2574
|
+
imports.wbg.__wbg_new_6421f6084cc5bc5a = function(arg0) {
|
|
2575
|
+
const ret = new Uint8Array(getObject(arg0));
|
|
2576
|
+
return addHeapObject(ret);
|
|
2577
|
+
};
|
|
2578
|
+
imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
|
|
2579
|
+
const ret = new Error();
|
|
2580
|
+
return addHeapObject(ret);
|
|
2581
|
+
};
|
|
2582
|
+
imports.wbg.__wbg_new_no_args_cb138f77cf6151ee = function(arg0, arg1) {
|
|
2583
|
+
const ret = new Function(getStringFromWasm0(arg0, arg1));
|
|
2584
|
+
return addHeapObject(ret);
|
|
2585
|
+
};
|
|
2586
|
+
imports.wbg.__wbg_new_with_length_aa5eaf41d35235e5 = function(arg0) {
|
|
2587
|
+
const ret = new Uint8Array(arg0 >>> 0);
|
|
2588
|
+
return addHeapObject(ret);
|
|
2589
|
+
};
|
|
2590
|
+
imports.wbg.__wbg_next_138a17bbf04e926c = function(arg0) {
|
|
2591
|
+
const ret = getObject(arg0).next;
|
|
2592
|
+
return addHeapObject(ret);
|
|
2593
|
+
};
|
|
2594
|
+
imports.wbg.__wbg_next_3cfe5c0fe2a4cc53 = function() { return handleError(function (arg0) {
|
|
2595
|
+
const ret = getObject(arg0).next();
|
|
2596
|
+
return addHeapObject(ret);
|
|
2597
|
+
}, arguments) };
|
|
2598
|
+
imports.wbg.__wbg_node_905d3e251edff8a2 = function(arg0) {
|
|
2599
|
+
const ret = getObject(arg0).node;
|
|
2600
|
+
return addHeapObject(ret);
|
|
2601
|
+
};
|
|
2602
|
+
imports.wbg.__wbg_process_dc0fbacc7c1c06f7 = function(arg0) {
|
|
2603
|
+
const ret = getObject(arg0).process;
|
|
2604
|
+
return addHeapObject(ret);
|
|
2605
|
+
};
|
|
2606
|
+
imports.wbg.__wbg_prototypesetcall_dfe9b766cdc1f1fd = function(arg0, arg1, arg2) {
|
|
2607
|
+
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
|
|
2608
|
+
};
|
|
2609
|
+
imports.wbg.__wbg_randomFillSync_ac0988aba3254290 = function() { return handleError(function (arg0, arg1) {
|
|
2610
|
+
getObject(arg0).randomFillSync(takeObject(arg1));
|
|
2611
|
+
}, arguments) };
|
|
2612
|
+
imports.wbg.__wbg_require_60cc747a6bc5215a = function() { return handleError(function () {
|
|
2613
|
+
const ret = module.require;
|
|
2614
|
+
return addHeapObject(ret);
|
|
2615
|
+
}, arguments) };
|
|
2616
|
+
imports.wbg.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
|
|
2617
|
+
getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
|
|
2618
|
+
};
|
|
2619
|
+
imports.wbg.__wbg_set_7df433eea03a5c14 = function(arg0, arg1, arg2) {
|
|
2620
|
+
getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
|
|
2621
|
+
};
|
|
2622
|
+
imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
|
|
2623
|
+
const ret = getObject(arg1).stack;
|
|
2624
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
2625
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2626
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
2627
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
2628
|
+
};
|
|
2629
|
+
imports.wbg.__wbg_static_accessor_GLOBAL_769e6b65d6557335 = function() {
|
|
2630
|
+
const ret = typeof global === 'undefined' ? null : global;
|
|
2631
|
+
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
2632
|
+
};
|
|
2633
|
+
imports.wbg.__wbg_static_accessor_GLOBAL_THIS_60cf02db4de8e1c1 = function() {
|
|
2634
|
+
const ret = typeof globalThis === 'undefined' ? null : globalThis;
|
|
2635
|
+
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
2636
|
+
};
|
|
2637
|
+
imports.wbg.__wbg_static_accessor_SELF_08f5a74c69739274 = function() {
|
|
2638
|
+
const ret = typeof self === 'undefined' ? null : self;
|
|
2639
|
+
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
2640
|
+
};
|
|
2641
|
+
imports.wbg.__wbg_static_accessor_WINDOW_a8924b26aa92d024 = function() {
|
|
2642
|
+
const ret = typeof window === 'undefined' ? null : window;
|
|
2643
|
+
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
2644
|
+
};
|
|
2645
|
+
imports.wbg.__wbg_subarray_845f2f5bce7d061a = function(arg0, arg1, arg2) {
|
|
2646
|
+
const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);
|
|
2647
|
+
return addHeapObject(ret);
|
|
2648
|
+
};
|
|
2649
|
+
imports.wbg.__wbg_value_57b7b035e117f7ee = function(arg0) {
|
|
2650
|
+
const ret = getObject(arg0).value;
|
|
2651
|
+
return addHeapObject(ret);
|
|
2652
|
+
};
|
|
2653
|
+
imports.wbg.__wbg_versions_c01dfd4722a88165 = function(arg0) {
|
|
2654
|
+
const ret = getObject(arg0).versions;
|
|
2655
|
+
return addHeapObject(ret);
|
|
2656
|
+
};
|
|
2657
|
+
imports.wbg.__wbg_wasmgnnlayer_unwrap = function(arg0) {
|
|
2658
|
+
const ret = WasmGNNLayer.__unwrap(getObject(arg0));
|
|
2659
|
+
return ret;
|
|
2660
|
+
};
|
|
2661
|
+
imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
|
|
2662
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
2663
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
2664
|
+
return addHeapObject(ret);
|
|
2665
|
+
};
|
|
2666
|
+
imports.wbg.__wbindgen_cast_4625c577ab2ec9ee = function(arg0) {
|
|
2667
|
+
// Cast intrinsic for `U64 -> Externref`.
|
|
2668
|
+
const ret = BigInt.asUintN(64, arg0);
|
|
2669
|
+
return addHeapObject(ret);
|
|
2670
|
+
};
|
|
2671
|
+
imports.wbg.__wbindgen_cast_cb9088102bce6b30 = function(arg0, arg1) {
|
|
2672
|
+
// Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
|
|
2673
|
+
const ret = getArrayU8FromWasm0(arg0, arg1);
|
|
2674
|
+
return addHeapObject(ret);
|
|
2675
|
+
};
|
|
2676
|
+
imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
|
|
2677
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
2678
|
+
const ret = arg0;
|
|
2679
|
+
return addHeapObject(ret);
|
|
2680
|
+
};
|
|
2681
|
+
imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
|
|
2682
|
+
const ret = getObject(arg0);
|
|
2683
|
+
return addHeapObject(ret);
|
|
2684
|
+
};
|
|
2685
|
+
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
|
|
2686
|
+
takeObject(arg0);
|
|
2687
|
+
};
|
|
2688
|
+
|
|
2689
|
+
return imports;
|
|
2690
|
+
}
|
|
2691
|
+
|
|
2692
|
+
function __wbg_finalize_init(instance, module) {
|
|
2693
|
+
wasm = instance.exports;
|
|
2694
|
+
__wbg_init.__wbindgen_wasm_module = module;
|
|
2695
|
+
cachedDataViewMemory0 = null;
|
|
2696
|
+
cachedFloat32ArrayMemory0 = null;
|
|
2697
|
+
cachedUint8ArrayMemory0 = null;
|
|
2698
|
+
|
|
2699
|
+
|
|
2700
|
+
wasm.__wbindgen_start();
|
|
2701
|
+
return wasm;
|
|
2702
|
+
}
|
|
2703
|
+
|
|
2704
|
+
function initSync(module) {
|
|
2705
|
+
if (wasm !== undefined) return wasm;
|
|
2706
|
+
|
|
2707
|
+
|
|
2708
|
+
if (typeof module !== 'undefined') {
|
|
2709
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
2710
|
+
({module} = module)
|
|
2711
|
+
} else {
|
|
2712
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
2713
|
+
}
|
|
2714
|
+
}
|
|
2715
|
+
|
|
2716
|
+
const imports = __wbg_get_imports();
|
|
2717
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
2718
|
+
module = new WebAssembly.Module(module);
|
|
2719
|
+
}
|
|
2720
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
2721
|
+
return __wbg_finalize_init(instance, module);
|
|
2722
|
+
}
|
|
2723
|
+
|
|
2724
|
+
async function __wbg_init(module_or_path) {
|
|
2725
|
+
if (wasm !== undefined) return wasm;
|
|
2726
|
+
|
|
2727
|
+
|
|
2728
|
+
if (typeof module_or_path !== 'undefined') {
|
|
2729
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
2730
|
+
({module_or_path} = module_or_path)
|
|
2731
|
+
} else {
|
|
2732
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
2733
|
+
}
|
|
2734
|
+
}
|
|
2735
|
+
|
|
2736
|
+
if (typeof module_or_path === 'undefined') {
|
|
2737
|
+
module_or_path = new URL('ruvector_attention_unified_wasm_bg.wasm', import.meta.url);
|
|
2738
|
+
}
|
|
2739
|
+
const imports = __wbg_get_imports();
|
|
2740
|
+
|
|
2741
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
2742
|
+
module_or_path = fetch(module_or_path);
|
|
2743
|
+
}
|
|
2744
|
+
|
|
2745
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
2746
|
+
|
|
2747
|
+
return __wbg_finalize_init(instance, module);
|
|
2748
|
+
}
|
|
2749
|
+
|
|
2750
|
+
export { initSync };
|
|
2751
|
+
export default __wbg_init;
|