@ruvector/cnn 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,804 @@
1
+ /* @ts-self-types="./ruvector_cnn_wasm.d.ts" */
2
+
3
+ /**
4
+ * Configuration for CNN embedder
5
+ */
6
+ export class EmbedderConfig {
7
+ __destroy_into_raw() {
8
+ const ptr = this.__wbg_ptr;
9
+ this.__wbg_ptr = 0;
10
+ EmbedderConfigFinalization.unregister(this);
11
+ return ptr;
12
+ }
13
+ free() {
14
+ const ptr = this.__destroy_into_raw();
15
+ wasm.__wbg_embedderconfig_free(ptr, 0);
16
+ }
17
+ constructor() {
18
+ const ret = wasm.embedderconfig_new();
19
+ this.__wbg_ptr = ret >>> 0;
20
+ EmbedderConfigFinalization.register(this, this.__wbg_ptr, this);
21
+ return this;
22
+ }
23
+ /**
24
+ * Output embedding dimension
25
+ * @returns {number}
26
+ */
27
+ get embedding_dim() {
28
+ const ret = wasm.__wbg_get_embedderconfig_embedding_dim(this.__wbg_ptr);
29
+ return ret >>> 0;
30
+ }
31
+ /**
32
+ * Input image size (square)
33
+ * @returns {number}
34
+ */
35
+ get input_size() {
36
+ const ret = wasm.__wbg_get_embedderconfig_input_size(this.__wbg_ptr);
37
+ return ret >>> 0;
38
+ }
39
+ /**
40
+ * Whether to L2 normalize embeddings
41
+ * @returns {boolean}
42
+ */
43
+ get normalize() {
44
+ const ret = wasm.__wbg_get_embedderconfig_normalize(this.__wbg_ptr);
45
+ return ret !== 0;
46
+ }
47
+ /**
48
+ * Output embedding dimension
49
+ * @param {number} arg0
50
+ */
51
+ set embedding_dim(arg0) {
52
+ wasm.__wbg_set_embedderconfig_embedding_dim(this.__wbg_ptr, arg0);
53
+ }
54
+ /**
55
+ * Input image size (square)
56
+ * @param {number} arg0
57
+ */
58
+ set input_size(arg0) {
59
+ wasm.__wbg_set_embedderconfig_input_size(this.__wbg_ptr, arg0);
60
+ }
61
+ /**
62
+ * Whether to L2 normalize embeddings
63
+ * @param {boolean} arg0
64
+ */
65
+ set normalize(arg0) {
66
+ wasm.__wbg_set_embedderconfig_normalize(this.__wbg_ptr, arg0);
67
+ }
68
+ }
69
+ if (Symbol.dispose) EmbedderConfig.prototype[Symbol.dispose] = EmbedderConfig.prototype.free;
70
+
71
+ /**
72
+ * Layer operations for building custom networks
73
+ */
74
+ export class LayerOps {
75
+ __destroy_into_raw() {
76
+ const ptr = this.__wbg_ptr;
77
+ this.__wbg_ptr = 0;
78
+ LayerOpsFinalization.unregister(this);
79
+ return ptr;
80
+ }
81
+ free() {
82
+ const ptr = this.__destroy_into_raw();
83
+ wasm.__wbg_layerops_free(ptr, 0);
84
+ }
85
+ /**
86
+ * Apply batch normalization (returns new array)
87
+ * @param {Float32Array} input
88
+ * @param {Float32Array} gamma
89
+ * @param {Float32Array} beta
90
+ * @param {Float32Array} mean
91
+ * @param {Float32Array} _var
92
+ * @param {number} epsilon
93
+ * @returns {Float32Array}
94
+ */
95
+ static batch_norm(input, gamma, beta, mean, _var, epsilon) {
96
+ try {
97
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
98
+ const ptr0 = passArrayF32ToWasm0(input, wasm.__wbindgen_export2);
99
+ const len0 = WASM_VECTOR_LEN;
100
+ const ptr1 = passArrayF32ToWasm0(gamma, wasm.__wbindgen_export2);
101
+ const len1 = WASM_VECTOR_LEN;
102
+ const ptr2 = passArrayF32ToWasm0(beta, wasm.__wbindgen_export2);
103
+ const len2 = WASM_VECTOR_LEN;
104
+ const ptr3 = passArrayF32ToWasm0(mean, wasm.__wbindgen_export2);
105
+ const len3 = WASM_VECTOR_LEN;
106
+ const ptr4 = passArrayF32ToWasm0(_var, wasm.__wbindgen_export2);
107
+ const len4 = WASM_VECTOR_LEN;
108
+ wasm.layerops_batch_norm(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, epsilon);
109
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
110
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
111
+ var v6 = getArrayF32FromWasm0(r0, r1).slice();
112
+ wasm.__wbindgen_export(r0, r1 * 4, 4);
113
+ return v6;
114
+ } finally {
115
+ wasm.__wbindgen_add_to_stack_pointer(16);
116
+ }
117
+ }
118
+ /**
119
+ * Apply global average pooling
120
+ * Returns one value per channel
121
+ * @param {Float32Array} input
122
+ * @param {number} height
123
+ * @param {number} width
124
+ * @param {number} channels
125
+ * @returns {Float32Array}
126
+ */
127
+ static global_avg_pool(input, height, width, channels) {
128
+ try {
129
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
130
+ const ptr0 = passArrayF32ToWasm0(input, wasm.__wbindgen_export2);
131
+ const len0 = WASM_VECTOR_LEN;
132
+ wasm.layerops_global_avg_pool(retptr, ptr0, len0, height, width, channels);
133
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
134
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
135
+ var v2 = getArrayF32FromWasm0(r0, r1).slice();
136
+ wasm.__wbindgen_export(r0, r1 * 4, 4);
137
+ return v2;
138
+ } finally {
139
+ wasm.__wbindgen_add_to_stack_pointer(16);
140
+ }
141
+ }
142
+ }
143
+ if (Symbol.dispose) LayerOps.prototype[Symbol.dispose] = LayerOps.prototype.free;
144
+
145
+ /**
146
+ * SIMD-optimized operations
147
+ */
148
+ export class SimdOps {
149
+ __destroy_into_raw() {
150
+ const ptr = this.__wbg_ptr;
151
+ this.__wbg_ptr = 0;
152
+ SimdOpsFinalization.unregister(this);
153
+ return ptr;
154
+ }
155
+ free() {
156
+ const ptr = this.__destroy_into_raw();
157
+ wasm.__wbg_simdops_free(ptr, 0);
158
+ }
159
+ /**
160
+ * Dot product of two vectors
161
+ * @param {Float32Array} a
162
+ * @param {Float32Array} b
163
+ * @returns {number}
164
+ */
165
+ static dot_product(a, b) {
166
+ const ptr0 = passArrayF32ToWasm0(a, wasm.__wbindgen_export2);
167
+ const len0 = WASM_VECTOR_LEN;
168
+ const ptr1 = passArrayF32ToWasm0(b, wasm.__wbindgen_export2);
169
+ const len1 = WASM_VECTOR_LEN;
170
+ const ret = wasm.simdops_dot_product(ptr0, len0, ptr1, len1);
171
+ return ret;
172
+ }
173
+ /**
174
+ * L2 normalize a vector (returns new array)
175
+ * @param {Float32Array} data
176
+ * @returns {Float32Array}
177
+ */
178
+ static l2_normalize(data) {
179
+ try {
180
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
181
+ const ptr0 = passArrayF32ToWasm0(data, wasm.__wbindgen_export2);
182
+ const len0 = WASM_VECTOR_LEN;
183
+ wasm.simdops_l2_normalize(retptr, ptr0, len0);
184
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
185
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
186
+ var v2 = getArrayF32FromWasm0(r0, r1).slice();
187
+ wasm.__wbindgen_export(r0, r1 * 4, 4);
188
+ return v2;
189
+ } finally {
190
+ wasm.__wbindgen_add_to_stack_pointer(16);
191
+ }
192
+ }
193
+ /**
194
+ * ReLU activation (returns new array)
195
+ * @param {Float32Array} data
196
+ * @returns {Float32Array}
197
+ */
198
+ static relu(data) {
199
+ try {
200
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
201
+ const ptr0 = passArrayF32ToWasm0(data, wasm.__wbindgen_export2);
202
+ const len0 = WASM_VECTOR_LEN;
203
+ wasm.simdops_relu(retptr, ptr0, len0);
204
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
205
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
206
+ var v2 = getArrayF32FromWasm0(r0, r1).slice();
207
+ wasm.__wbindgen_export(r0, r1 * 4, 4);
208
+ return v2;
209
+ } finally {
210
+ wasm.__wbindgen_add_to_stack_pointer(16);
211
+ }
212
+ }
213
+ /**
214
+ * ReLU6 activation (returns new array)
215
+ * @param {Float32Array} data
216
+ * @returns {Float32Array}
217
+ */
218
+ static relu6(data) {
219
+ try {
220
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
221
+ const ptr0 = passArrayF32ToWasm0(data, wasm.__wbindgen_export2);
222
+ const len0 = WASM_VECTOR_LEN;
223
+ wasm.simdops_relu6(retptr, ptr0, len0);
224
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
225
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
226
+ var v2 = getArrayF32FromWasm0(r0, r1).slice();
227
+ wasm.__wbindgen_export(r0, r1 * 4, 4);
228
+ return v2;
229
+ } finally {
230
+ wasm.__wbindgen_add_to_stack_pointer(16);
231
+ }
232
+ }
233
+ }
234
+ if (Symbol.dispose) SimdOps.prototype[Symbol.dispose] = SimdOps.prototype.free;
235
+
236
+ /**
237
+ * WASM CNN Embedder for image feature extraction
238
+ */
239
+ export class WasmCnnEmbedder {
240
+ __destroy_into_raw() {
241
+ const ptr = this.__wbg_ptr;
242
+ this.__wbg_ptr = 0;
243
+ WasmCnnEmbedderFinalization.unregister(this);
244
+ return ptr;
245
+ }
246
+ free() {
247
+ const ptr = this.__destroy_into_raw();
248
+ wasm.__wbg_wasmcnnembedder_free(ptr, 0);
249
+ }
250
+ /**
251
+ * Compute cosine similarity between two embeddings
252
+ * @param {Float32Array} a
253
+ * @param {Float32Array} b
254
+ * @returns {number}
255
+ */
256
+ cosine_similarity(a, b) {
257
+ try {
258
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
259
+ const ptr0 = passArrayF32ToWasm0(a, wasm.__wbindgen_export2);
260
+ const len0 = WASM_VECTOR_LEN;
261
+ const ptr1 = passArrayF32ToWasm0(b, wasm.__wbindgen_export2);
262
+ const len1 = WASM_VECTOR_LEN;
263
+ wasm.wasmcnnembedder_cosine_similarity(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
264
+ var r0 = getDataViewMemory0().getFloat32(retptr + 4 * 0, true);
265
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
266
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
267
+ if (r2) {
268
+ throw takeObject(r1);
269
+ }
270
+ return r0;
271
+ } finally {
272
+ wasm.__wbindgen_add_to_stack_pointer(16);
273
+ }
274
+ }
275
+ /**
276
+ * Get the embedding dimension
277
+ * @returns {number}
278
+ */
279
+ get embedding_dim() {
280
+ const ret = wasm.wasmcnnembedder_embedding_dim(this.__wbg_ptr);
281
+ return ret >>> 0;
282
+ }
283
+ /**
284
+ * Extract embedding from image data (RGB format, row-major)
285
+ * @param {Uint8Array} image_data
286
+ * @param {number} width
287
+ * @param {number} height
288
+ * @returns {Float32Array}
289
+ */
290
+ extract(image_data, width, height) {
291
+ try {
292
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
293
+ const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_export2);
294
+ const len0 = WASM_VECTOR_LEN;
295
+ wasm.wasmcnnembedder_extract(retptr, this.__wbg_ptr, ptr0, len0, width, height);
296
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
297
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
298
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
299
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
300
+ if (r3) {
301
+ throw takeObject(r2);
302
+ }
303
+ var v2 = getArrayF32FromWasm0(r0, r1).slice();
304
+ wasm.__wbindgen_export(r0, r1 * 4, 4);
305
+ return v2;
306
+ } finally {
307
+ wasm.__wbindgen_add_to_stack_pointer(16);
308
+ }
309
+ }
310
+ /**
311
+ * Create a new CNN embedder
312
+ * @param {EmbedderConfig | null} [config]
313
+ */
314
+ constructor(config) {
315
+ try {
316
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
317
+ let ptr0 = 0;
318
+ if (!isLikeNone(config)) {
319
+ _assertClass(config, EmbedderConfig);
320
+ ptr0 = config.__destroy_into_raw();
321
+ }
322
+ wasm.wasmcnnembedder_new(retptr, ptr0);
323
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
324
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
325
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
326
+ if (r2) {
327
+ throw takeObject(r1);
328
+ }
329
+ this.__wbg_ptr = r0 >>> 0;
330
+ WasmCnnEmbedderFinalization.register(this, this.__wbg_ptr, this);
331
+ return this;
332
+ } finally {
333
+ wasm.__wbindgen_add_to_stack_pointer(16);
334
+ }
335
+ }
336
+ }
337
+ if (Symbol.dispose) WasmCnnEmbedder.prototype[Symbol.dispose] = WasmCnnEmbedder.prototype.free;
338
+
339
+ /**
340
+ * InfoNCE loss for contrastive learning (SimCLR style)
341
+ */
342
+ export class WasmInfoNCELoss {
343
+ __destroy_into_raw() {
344
+ const ptr = this.__wbg_ptr;
345
+ this.__wbg_ptr = 0;
346
+ WasmInfoNCELossFinalization.unregister(this);
347
+ return ptr;
348
+ }
349
+ free() {
350
+ const ptr = this.__destroy_into_raw();
351
+ wasm.__wbg_wasminfonceloss_free(ptr, 0);
352
+ }
353
+ /**
354
+ * Compute loss for a batch of embedding pairs
355
+ * embeddings: [2N, D] flattened where (i, i+N) are positive pairs
356
+ * @param {Float32Array} embeddings
357
+ * @param {number} batch_size
358
+ * @param {number} dim
359
+ * @returns {number}
360
+ */
361
+ forward(embeddings, batch_size, dim) {
362
+ try {
363
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
364
+ const ptr0 = passArrayF32ToWasm0(embeddings, wasm.__wbindgen_export2);
365
+ const len0 = WASM_VECTOR_LEN;
366
+ wasm.wasminfonceloss_forward(retptr, this.__wbg_ptr, ptr0, len0, batch_size, dim);
367
+ var r0 = getDataViewMemory0().getFloat32(retptr + 4 * 0, true);
368
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
369
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
370
+ if (r2) {
371
+ throw takeObject(r1);
372
+ }
373
+ return r0;
374
+ } finally {
375
+ wasm.__wbindgen_add_to_stack_pointer(16);
376
+ }
377
+ }
378
+ /**
379
+ * Create new InfoNCE loss with temperature parameter
380
+ * @param {number} temperature
381
+ */
382
+ constructor(temperature) {
383
+ const ret = wasm.wasminfonceloss_new(temperature);
384
+ this.__wbg_ptr = ret >>> 0;
385
+ WasmInfoNCELossFinalization.register(this, this.__wbg_ptr, this);
386
+ return this;
387
+ }
388
+ /**
389
+ * Get the temperature parameter
390
+ * @returns {number}
391
+ */
392
+ get temperature() {
393
+ const ret = wasm.wasminfonceloss_temperature(this.__wbg_ptr);
394
+ return ret;
395
+ }
396
+ }
397
+ if (Symbol.dispose) WasmInfoNCELoss.prototype[Symbol.dispose] = WasmInfoNCELoss.prototype.free;
398
+
399
+ /**
400
+ * Triplet loss for metric learning
401
+ */
402
+ export class WasmTripletLoss {
403
+ __destroy_into_raw() {
404
+ const ptr = this.__wbg_ptr;
405
+ this.__wbg_ptr = 0;
406
+ WasmTripletLossFinalization.unregister(this);
407
+ return ptr;
408
+ }
409
+ free() {
410
+ const ptr = this.__destroy_into_raw();
411
+ wasm.__wbg_wasmtripletloss_free(ptr, 0);
412
+ }
413
+ /**
414
+ * Compute loss for a batch of triplets
415
+ * @param {Float32Array} anchors
416
+ * @param {Float32Array} positives
417
+ * @param {Float32Array} negatives
418
+ * @param {number} dim
419
+ * @returns {number}
420
+ */
421
+ forward(anchors, positives, negatives, dim) {
422
+ try {
423
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
424
+ const ptr0 = passArrayF32ToWasm0(anchors, wasm.__wbindgen_export2);
425
+ const len0 = WASM_VECTOR_LEN;
426
+ const ptr1 = passArrayF32ToWasm0(positives, wasm.__wbindgen_export2);
427
+ const len1 = WASM_VECTOR_LEN;
428
+ const ptr2 = passArrayF32ToWasm0(negatives, wasm.__wbindgen_export2);
429
+ const len2 = WASM_VECTOR_LEN;
430
+ wasm.wasmtripletloss_forward(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, dim);
431
+ var r0 = getDataViewMemory0().getFloat32(retptr + 4 * 0, true);
432
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
433
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
434
+ if (r2) {
435
+ throw takeObject(r1);
436
+ }
437
+ return r0;
438
+ } finally {
439
+ wasm.__wbindgen_add_to_stack_pointer(16);
440
+ }
441
+ }
442
+ /**
443
+ * Compute loss for a single triplet
444
+ * @param {Float32Array} anchor
445
+ * @param {Float32Array} positive
446
+ * @param {Float32Array} negative
447
+ * @returns {number}
448
+ */
449
+ forward_single(anchor, positive, negative) {
450
+ try {
451
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
452
+ const ptr0 = passArrayF32ToWasm0(anchor, wasm.__wbindgen_export2);
453
+ const len0 = WASM_VECTOR_LEN;
454
+ const ptr1 = passArrayF32ToWasm0(positive, wasm.__wbindgen_export2);
455
+ const len1 = WASM_VECTOR_LEN;
456
+ const ptr2 = passArrayF32ToWasm0(negative, wasm.__wbindgen_export2);
457
+ const len2 = WASM_VECTOR_LEN;
458
+ wasm.wasmtripletloss_forward_single(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
459
+ var r0 = getDataViewMemory0().getFloat32(retptr + 4 * 0, true);
460
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
461
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
462
+ if (r2) {
463
+ throw takeObject(r1);
464
+ }
465
+ return r0;
466
+ } finally {
467
+ wasm.__wbindgen_add_to_stack_pointer(16);
468
+ }
469
+ }
470
+ /**
471
+ * Get the margin parameter
472
+ * @returns {number}
473
+ */
474
+ get margin() {
475
+ const ret = wasm.wasmtripletloss_margin(this.__wbg_ptr);
476
+ return ret;
477
+ }
478
+ /**
479
+ * Create new triplet loss with margin
480
+ * @param {number} margin
481
+ */
482
+ constructor(margin) {
483
+ const ret = wasm.wasmtripletloss_new(margin);
484
+ this.__wbg_ptr = ret >>> 0;
485
+ WasmTripletLossFinalization.register(this, this.__wbg_ptr, this);
486
+ return this;
487
+ }
488
+ }
489
+ if (Symbol.dispose) WasmTripletLoss.prototype[Symbol.dispose] = WasmTripletLoss.prototype.free;
490
+
491
+ /**
492
+ * Initialize panic hook for better error messages
493
+ */
494
+ export function init() {
495
+ wasm.init();
496
+ }
497
+
498
+ function __wbg_get_imports() {
499
+ const import0 = {
500
+ __proto__: null,
501
+ __wbg___wbindgen_throw_39bc967c0e5a9b58: function(arg0, arg1) {
502
+ throw new Error(getStringFromWasm0(arg0, arg1));
503
+ },
504
+ __wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
505
+ let deferred0_0;
506
+ let deferred0_1;
507
+ try {
508
+ deferred0_0 = arg0;
509
+ deferred0_1 = arg1;
510
+ console.error(getStringFromWasm0(arg0, arg1));
511
+ } finally {
512
+ wasm.__wbindgen_export(deferred0_0, deferred0_1, 1);
513
+ }
514
+ },
515
+ __wbg_new_227d7c05414eb861: function() {
516
+ const ret = new Error();
517
+ return addHeapObject(ret);
518
+ },
519
+ __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
520
+ const ret = getObject(arg1).stack;
521
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
522
+ const len1 = WASM_VECTOR_LEN;
523
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
524
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
525
+ },
526
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
527
+ // Cast intrinsic for `Ref(String) -> Externref`.
528
+ const ret = getStringFromWasm0(arg0, arg1);
529
+ return addHeapObject(ret);
530
+ },
531
+ __wbindgen_object_drop_ref: function(arg0) {
532
+ takeObject(arg0);
533
+ },
534
+ };
535
+ return {
536
+ __proto__: null,
537
+ "./ruvector_cnn_wasm_bg.js": import0,
538
+ };
539
+ }
540
+
541
+ const EmbedderConfigFinalization = (typeof FinalizationRegistry === 'undefined')
542
+ ? { register: () => {}, unregister: () => {} }
543
+ : new FinalizationRegistry(ptr => wasm.__wbg_embedderconfig_free(ptr >>> 0, 1));
544
+ const LayerOpsFinalization = (typeof FinalizationRegistry === 'undefined')
545
+ ? { register: () => {}, unregister: () => {} }
546
+ : new FinalizationRegistry(ptr => wasm.__wbg_layerops_free(ptr >>> 0, 1));
547
+ const SimdOpsFinalization = (typeof FinalizationRegistry === 'undefined')
548
+ ? { register: () => {}, unregister: () => {} }
549
+ : new FinalizationRegistry(ptr => wasm.__wbg_simdops_free(ptr >>> 0, 1));
550
+ const WasmCnnEmbedderFinalization = (typeof FinalizationRegistry === 'undefined')
551
+ ? { register: () => {}, unregister: () => {} }
552
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmcnnembedder_free(ptr >>> 0, 1));
553
+ const WasmInfoNCELossFinalization = (typeof FinalizationRegistry === 'undefined')
554
+ ? { register: () => {}, unregister: () => {} }
555
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasminfonceloss_free(ptr >>> 0, 1));
556
+ const WasmTripletLossFinalization = (typeof FinalizationRegistry === 'undefined')
557
+ ? { register: () => {}, unregister: () => {} }
558
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmtripletloss_free(ptr >>> 0, 1));
559
+
560
+ function addHeapObject(obj) {
561
+ if (heap_next === heap.length) heap.push(heap.length + 1);
562
+ const idx = heap_next;
563
+ heap_next = heap[idx];
564
+
565
+ heap[idx] = obj;
566
+ return idx;
567
+ }
568
+
569
+ function _assertClass(instance, klass) {
570
+ if (!(instance instanceof klass)) {
571
+ throw new Error(`expected instance of ${klass.name}`);
572
+ }
573
+ }
574
+
575
+ function dropObject(idx) {
576
+ if (idx < 1028) return;
577
+ heap[idx] = heap_next;
578
+ heap_next = idx;
579
+ }
580
+
581
+ function getArrayF32FromWasm0(ptr, len) {
582
+ ptr = ptr >>> 0;
583
+ return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
584
+ }
585
+
586
+ let cachedDataViewMemory0 = null;
587
+ function getDataViewMemory0() {
588
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
589
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
590
+ }
591
+ return cachedDataViewMemory0;
592
+ }
593
+
594
+ let cachedFloat32ArrayMemory0 = null;
595
+ function getFloat32ArrayMemory0() {
596
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
597
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
598
+ }
599
+ return cachedFloat32ArrayMemory0;
600
+ }
601
+
602
+ function getStringFromWasm0(ptr, len) {
603
+ ptr = ptr >>> 0;
604
+ return decodeText(ptr, len);
605
+ }
606
+
607
+ let cachedUint8ArrayMemory0 = null;
608
+ function getUint8ArrayMemory0() {
609
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
610
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
611
+ }
612
+ return cachedUint8ArrayMemory0;
613
+ }
614
+
615
+ function getObject(idx) { return heap[idx]; }
616
+
617
+ let heap = new Array(1024).fill(undefined);
618
+ heap.push(undefined, null, true, false);
619
+
620
+ let heap_next = heap.length;
621
+
622
+ function isLikeNone(x) {
623
+ return x === undefined || x === null;
624
+ }
625
+
626
+ function passArray8ToWasm0(arg, malloc) {
627
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
628
+ getUint8ArrayMemory0().set(arg, ptr / 1);
629
+ WASM_VECTOR_LEN = arg.length;
630
+ return ptr;
631
+ }
632
+
633
+ function passArrayF32ToWasm0(arg, malloc) {
634
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
635
+ getFloat32ArrayMemory0().set(arg, ptr / 4);
636
+ WASM_VECTOR_LEN = arg.length;
637
+ return ptr;
638
+ }
639
+
640
+ function passStringToWasm0(arg, malloc, realloc) {
641
+ if (realloc === undefined) {
642
+ const buf = cachedTextEncoder.encode(arg);
643
+ const ptr = malloc(buf.length, 1) >>> 0;
644
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
645
+ WASM_VECTOR_LEN = buf.length;
646
+ return ptr;
647
+ }
648
+
649
+ let len = arg.length;
650
+ let ptr = malloc(len, 1) >>> 0;
651
+
652
+ const mem = getUint8ArrayMemory0();
653
+
654
+ let offset = 0;
655
+
656
+ for (; offset < len; offset++) {
657
+ const code = arg.charCodeAt(offset);
658
+ if (code > 0x7F) break;
659
+ mem[ptr + offset] = code;
660
+ }
661
+ if (offset !== len) {
662
+ if (offset !== 0) {
663
+ arg = arg.slice(offset);
664
+ }
665
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
666
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
667
+ const ret = cachedTextEncoder.encodeInto(arg, view);
668
+
669
+ offset += ret.written;
670
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
671
+ }
672
+
673
+ WASM_VECTOR_LEN = offset;
674
+ return ptr;
675
+ }
676
+
677
+ function takeObject(idx) {
678
+ const ret = getObject(idx);
679
+ dropObject(idx);
680
+ return ret;
681
+ }
682
+
683
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
684
+ cachedTextDecoder.decode();
685
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
686
+ let numBytesDecoded = 0;
687
+ function decodeText(ptr, len) {
688
+ numBytesDecoded += len;
689
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
690
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
691
+ cachedTextDecoder.decode();
692
+ numBytesDecoded = len;
693
+ }
694
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
695
+ }
696
+
697
+ const cachedTextEncoder = new TextEncoder();
698
+
699
+ if (!('encodeInto' in cachedTextEncoder)) {
700
+ cachedTextEncoder.encodeInto = function (arg, view) {
701
+ const buf = cachedTextEncoder.encode(arg);
702
+ view.set(buf);
703
+ return {
704
+ read: arg.length,
705
+ written: buf.length
706
+ };
707
+ };
708
+ }
709
+
710
+ let WASM_VECTOR_LEN = 0;
711
+
712
+ let wasmModule, wasm;
713
+ function __wbg_finalize_init(instance, module) {
714
+ wasm = instance.exports;
715
+ wasmModule = module;
716
+ cachedDataViewMemory0 = null;
717
+ cachedFloat32ArrayMemory0 = null;
718
+ cachedUint8ArrayMemory0 = null;
719
+ wasm.__wbindgen_start();
720
+ return wasm;
721
+ }
722
+
723
+ async function __wbg_load(module, imports) {
724
+ if (typeof Response === 'function' && module instanceof Response) {
725
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
726
+ try {
727
+ return await WebAssembly.instantiateStreaming(module, imports);
728
+ } catch (e) {
729
+ const validResponse = module.ok && expectedResponseType(module.type);
730
+
731
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
732
+ 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);
733
+
734
+ } else { throw e; }
735
+ }
736
+ }
737
+
738
+ const bytes = await module.arrayBuffer();
739
+ return await WebAssembly.instantiate(bytes, imports);
740
+ } else {
741
+ const instance = await WebAssembly.instantiate(module, imports);
742
+
743
+ if (instance instanceof WebAssembly.Instance) {
744
+ return { instance, module };
745
+ } else {
746
+ return instance;
747
+ }
748
+ }
749
+
750
+ function expectedResponseType(type) {
751
+ switch (type) {
752
+ case 'basic': case 'cors': case 'default': return true;
753
+ }
754
+ return false;
755
+ }
756
+ }
757
+
758
+ function initSync(module) {
759
+ if (wasm !== undefined) return wasm;
760
+
761
+
762
+ if (module !== undefined) {
763
+ if (Object.getPrototypeOf(module) === Object.prototype) {
764
+ ({module} = module)
765
+ } else {
766
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
767
+ }
768
+ }
769
+
770
+ const imports = __wbg_get_imports();
771
+ if (!(module instanceof WebAssembly.Module)) {
772
+ module = new WebAssembly.Module(module);
773
+ }
774
+ const instance = new WebAssembly.Instance(module, imports);
775
+ return __wbg_finalize_init(instance, module);
776
+ }
777
+
778
+ async function __wbg_init(module_or_path) {
779
+ if (wasm !== undefined) return wasm;
780
+
781
+
782
+ if (module_or_path !== undefined) {
783
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
784
+ ({module_or_path} = module_or_path)
785
+ } else {
786
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
787
+ }
788
+ }
789
+
790
+ if (module_or_path === undefined) {
791
+ module_or_path = new URL('ruvector_cnn_wasm_bg.wasm', import.meta.url);
792
+ }
793
+ const imports = __wbg_get_imports();
794
+
795
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
796
+ module_or_path = fetch(module_or_path);
797
+ }
798
+
799
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
800
+
801
+ return __wbg_finalize_init(instance, module);
802
+ }
803
+
804
+ export { initSync, __wbg_init as default };