ruvector-math-wasm 0.1.31

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,1375 @@
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 dropObject(idx) {
13
+ if (idx < 132) return;
14
+ heap[idx] = heap_next;
15
+ heap_next = idx;
16
+ }
17
+
18
+ function getArrayF64FromWasm0(ptr, len) {
19
+ ptr = ptr >>> 0;
20
+ return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
21
+ }
22
+
23
+ function getArrayU32FromWasm0(ptr, len) {
24
+ ptr = ptr >>> 0;
25
+ return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
26
+ }
27
+
28
+ function getArrayU8FromWasm0(ptr, len) {
29
+ ptr = ptr >>> 0;
30
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
31
+ }
32
+
33
+ let cachedDataViewMemory0 = null;
34
+ function getDataViewMemory0() {
35
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
36
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
37
+ }
38
+ return cachedDataViewMemory0;
39
+ }
40
+
41
+ let cachedFloat64ArrayMemory0 = null;
42
+ function getFloat64ArrayMemory0() {
43
+ if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
44
+ cachedFloat64ArrayMemory0 = new Float64Array(wasm.memory.buffer);
45
+ }
46
+ return cachedFloat64ArrayMemory0;
47
+ }
48
+
49
+ function getStringFromWasm0(ptr, len) {
50
+ ptr = ptr >>> 0;
51
+ return decodeText(ptr, len);
52
+ }
53
+
54
+ let cachedUint32ArrayMemory0 = null;
55
+ function getUint32ArrayMemory0() {
56
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
57
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
58
+ }
59
+ return cachedUint32ArrayMemory0;
60
+ }
61
+
62
+ let cachedUint8ArrayMemory0 = null;
63
+ function getUint8ArrayMemory0() {
64
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
65
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
66
+ }
67
+ return cachedUint8ArrayMemory0;
68
+ }
69
+
70
+ function getObject(idx) { return heap[idx]; }
71
+
72
+ function handleError(f, args) {
73
+ try {
74
+ return f.apply(this, args);
75
+ } catch (e) {
76
+ wasm.__wbindgen_export(addHeapObject(e));
77
+ }
78
+ }
79
+
80
+ let heap = new Array(128).fill(undefined);
81
+ heap.push(undefined, null, true, false);
82
+
83
+ let heap_next = heap.length;
84
+
85
+ function isLikeNone(x) {
86
+ return x === undefined || x === null;
87
+ }
88
+
89
+ function passArrayF64ToWasm0(arg, malloc) {
90
+ const ptr = malloc(arg.length * 8, 8) >>> 0;
91
+ getFloat64ArrayMemory0().set(arg, ptr / 8);
92
+ WASM_VECTOR_LEN = arg.length;
93
+ return ptr;
94
+ }
95
+
96
+ function passStringToWasm0(arg, malloc, realloc) {
97
+ if (realloc === undefined) {
98
+ const buf = cachedTextEncoder.encode(arg);
99
+ const ptr = malloc(buf.length, 1) >>> 0;
100
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
101
+ WASM_VECTOR_LEN = buf.length;
102
+ return ptr;
103
+ }
104
+
105
+ let len = arg.length;
106
+ let ptr = malloc(len, 1) >>> 0;
107
+
108
+ const mem = getUint8ArrayMemory0();
109
+
110
+ let offset = 0;
111
+
112
+ for (; offset < len; offset++) {
113
+ const code = arg.charCodeAt(offset);
114
+ if (code > 0x7F) break;
115
+ mem[ptr + offset] = code;
116
+ }
117
+ if (offset !== len) {
118
+ if (offset !== 0) {
119
+ arg = arg.slice(offset);
120
+ }
121
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
122
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
123
+ const ret = cachedTextEncoder.encodeInto(arg, view);
124
+
125
+ offset += ret.written;
126
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
127
+ }
128
+
129
+ WASM_VECTOR_LEN = offset;
130
+ return ptr;
131
+ }
132
+
133
+ function takeObject(idx) {
134
+ const ret = getObject(idx);
135
+ dropObject(idx);
136
+ return ret;
137
+ }
138
+
139
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
140
+ cachedTextDecoder.decode();
141
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
142
+ let numBytesDecoded = 0;
143
+ function decodeText(ptr, len) {
144
+ numBytesDecoded += len;
145
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
146
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
147
+ cachedTextDecoder.decode();
148
+ numBytesDecoded = len;
149
+ }
150
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
151
+ }
152
+
153
+ const cachedTextEncoder = new TextEncoder();
154
+
155
+ if (!('encodeInto' in cachedTextEncoder)) {
156
+ cachedTextEncoder.encodeInto = function (arg, view) {
157
+ const buf = cachedTextEncoder.encode(arg);
158
+ view.set(buf);
159
+ return {
160
+ read: arg.length,
161
+ written: buf.length
162
+ };
163
+ }
164
+ }
165
+
166
+ let WASM_VECTOR_LEN = 0;
167
+
168
+ const TransportResultFinalization = (typeof FinalizationRegistry === 'undefined')
169
+ ? { register: () => {}, unregister: () => {} }
170
+ : new FinalizationRegistry(ptr => wasm.__wbg_transportresult_free(ptr >>> 0, 1));
171
+
172
+ const WasmFisherInformationFinalization = (typeof FinalizationRegistry === 'undefined')
173
+ ? { register: () => {}, unregister: () => {} }
174
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmfisherinformation_free(ptr >>> 0, 1));
175
+
176
+ const WasmGromovWassersteinFinalization = (typeof FinalizationRegistry === 'undefined')
177
+ ? { register: () => {}, unregister: () => {} }
178
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmgromovwasserstein_free(ptr >>> 0, 1));
179
+
180
+ const WasmNaturalGradientFinalization = (typeof FinalizationRegistry === 'undefined')
181
+ ? { register: () => {}, unregister: () => {} }
182
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmnaturalgradient_free(ptr >>> 0, 1));
183
+
184
+ const WasmProductManifoldFinalization = (typeof FinalizationRegistry === 'undefined')
185
+ ? { register: () => {}, unregister: () => {} }
186
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmproductmanifold_free(ptr >>> 0, 1));
187
+
188
+ const WasmSinkhornFinalization = (typeof FinalizationRegistry === 'undefined')
189
+ ? { register: () => {}, unregister: () => {} }
190
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmsinkhorn_free(ptr >>> 0, 1));
191
+
192
+ const WasmSlicedWassersteinFinalization = (typeof FinalizationRegistry === 'undefined')
193
+ ? { register: () => {}, unregister: () => {} }
194
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmslicedwasserstein_free(ptr >>> 0, 1));
195
+
196
+ const WasmSphericalSpaceFinalization = (typeof FinalizationRegistry === 'undefined')
197
+ ? { register: () => {}, unregister: () => {} }
198
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmsphericalspace_free(ptr >>> 0, 1));
199
+
200
+ /**
201
+ * Result of Sinkhorn transport computation
202
+ */
203
+ export class TransportResult {
204
+ static __wrap(ptr) {
205
+ ptr = ptr >>> 0;
206
+ const obj = Object.create(TransportResult.prototype);
207
+ obj.__wbg_ptr = ptr;
208
+ TransportResultFinalization.register(obj, obj.__wbg_ptr, obj);
209
+ return obj;
210
+ }
211
+ __destroy_into_raw() {
212
+ const ptr = this.__wbg_ptr;
213
+ this.__wbg_ptr = 0;
214
+ TransportResultFinalization.unregister(this);
215
+ return ptr;
216
+ }
217
+ free() {
218
+ const ptr = this.__destroy_into_raw();
219
+ wasm.__wbg_transportresult_free(ptr, 0);
220
+ }
221
+ /**
222
+ * Get number of iterations
223
+ * @returns {number}
224
+ */
225
+ get iterations() {
226
+ const ret = wasm.transportresult_iterations(this.__wbg_ptr);
227
+ return ret >>> 0;
228
+ }
229
+ /**
230
+ * Get total transport cost
231
+ * @returns {number}
232
+ */
233
+ get cost() {
234
+ const ret = wasm.transportresult_cost(this.__wbg_ptr);
235
+ return ret;
236
+ }
237
+ /**
238
+ * Get transport plan as flat array
239
+ * @returns {Float64Array}
240
+ */
241
+ get plan() {
242
+ try {
243
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
244
+ wasm.transportresult_plan(retptr, this.__wbg_ptr);
245
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
246
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
247
+ var v1 = getArrayF64FromWasm0(r0, r1).slice();
248
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
249
+ return v1;
250
+ } finally {
251
+ wasm.__wbindgen_add_to_stack_pointer(16);
252
+ }
253
+ }
254
+ /**
255
+ * Whether algorithm converged
256
+ * @returns {boolean}
257
+ */
258
+ get converged() {
259
+ const ret = wasm.transportresult_converged(this.__wbg_ptr);
260
+ return ret !== 0;
261
+ }
262
+ }
263
+ if (Symbol.dispose) TransportResult.prototype[Symbol.dispose] = TransportResult.prototype.free;
264
+
265
+ /**
266
+ * Fisher Information for WASM
267
+ */
268
+ export class WasmFisherInformation {
269
+ static __wrap(ptr) {
270
+ ptr = ptr >>> 0;
271
+ const obj = Object.create(WasmFisherInformation.prototype);
272
+ obj.__wbg_ptr = ptr;
273
+ WasmFisherInformationFinalization.register(obj, obj.__wbg_ptr, obj);
274
+ return obj;
275
+ }
276
+ __destroy_into_raw() {
277
+ const ptr = this.__wbg_ptr;
278
+ this.__wbg_ptr = 0;
279
+ WasmFisherInformationFinalization.unregister(this);
280
+ return ptr;
281
+ }
282
+ free() {
283
+ const ptr = this.__destroy_into_raw();
284
+ wasm.__wbg_wasmfisherinformation_free(ptr, 0);
285
+ }
286
+ /**
287
+ * Compute diagonal FIM from gradient samples
288
+ * @param {Float64Array} gradients
289
+ * @param {number} _num_samples
290
+ * @param {number} dim
291
+ * @returns {Float64Array}
292
+ */
293
+ diagonalFim(gradients, _num_samples, dim) {
294
+ try {
295
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
296
+ const ptr0 = passArrayF64ToWasm0(gradients, wasm.__wbindgen_export3);
297
+ const len0 = WASM_VECTOR_LEN;
298
+ wasm.wasmfisherinformation_diagonalFim(retptr, this.__wbg_ptr, ptr0, len0, _num_samples, dim);
299
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
300
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
301
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
302
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
303
+ if (r3) {
304
+ throw takeObject(r2);
305
+ }
306
+ var v2 = getArrayF64FromWasm0(r0, r1).slice();
307
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
308
+ return v2;
309
+ } finally {
310
+ wasm.__wbindgen_add_to_stack_pointer(16);
311
+ }
312
+ }
313
+ /**
314
+ * Set damping factor
315
+ * @param {number} damping
316
+ * @returns {WasmFisherInformation}
317
+ */
318
+ withDamping(damping) {
319
+ const ptr = this.__destroy_into_raw();
320
+ const ret = wasm.wasmfisherinformation_withDamping(ptr, damping);
321
+ return WasmFisherInformation.__wrap(ret);
322
+ }
323
+ /**
324
+ * Compute natural gradient
325
+ * @param {Float64Array} fim_diag
326
+ * @param {Float64Array} gradient
327
+ * @param {number} damping
328
+ * @returns {Float64Array}
329
+ */
330
+ naturalGradient(fim_diag, gradient, damping) {
331
+ try {
332
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
333
+ const ptr0 = passArrayF64ToWasm0(fim_diag, wasm.__wbindgen_export3);
334
+ const len0 = WASM_VECTOR_LEN;
335
+ const ptr1 = passArrayF64ToWasm0(gradient, wasm.__wbindgen_export3);
336
+ const len1 = WASM_VECTOR_LEN;
337
+ wasm.wasmfisherinformation_naturalGradient(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, damping);
338
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
339
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
340
+ var v3 = getArrayF64FromWasm0(r0, r1).slice();
341
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
342
+ return v3;
343
+ } finally {
344
+ wasm.__wbindgen_add_to_stack_pointer(16);
345
+ }
346
+ }
347
+ /**
348
+ * Create a new Fisher Information calculator
349
+ */
350
+ constructor() {
351
+ const ret = wasm.wasmfisherinformation_new();
352
+ this.__wbg_ptr = ret >>> 0;
353
+ WasmFisherInformationFinalization.register(this, this.__wbg_ptr, this);
354
+ return this;
355
+ }
356
+ }
357
+ if (Symbol.dispose) WasmFisherInformation.prototype[Symbol.dispose] = WasmFisherInformation.prototype.free;
358
+
359
+ /**
360
+ * Gromov-Wasserstein distance for WASM
361
+ */
362
+ export class WasmGromovWasserstein {
363
+ __destroy_into_raw() {
364
+ const ptr = this.__wbg_ptr;
365
+ this.__wbg_ptr = 0;
366
+ WasmGromovWassersteinFinalization.unregister(this);
367
+ return ptr;
368
+ }
369
+ free() {
370
+ const ptr = this.__destroy_into_raw();
371
+ wasm.__wbg_wasmgromovwasserstein_free(ptr, 0);
372
+ }
373
+ /**
374
+ * Create a new Gromov-Wasserstein calculator
375
+ * @param {number} regularization
376
+ */
377
+ constructor(regularization) {
378
+ const ret = wasm.wasmgromovwasserstein_new(regularization);
379
+ this.__wbg_ptr = ret >>> 0;
380
+ WasmGromovWassersteinFinalization.register(this, this.__wbg_ptr, this);
381
+ return this;
382
+ }
383
+ /**
384
+ * Compute GW distance between point clouds
385
+ * @param {Float64Array} source
386
+ * @param {Float64Array} target
387
+ * @param {number} dim
388
+ * @returns {number}
389
+ */
390
+ distance(source, target, dim) {
391
+ try {
392
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
393
+ const ptr0 = passArrayF64ToWasm0(source, wasm.__wbindgen_export3);
394
+ const len0 = WASM_VECTOR_LEN;
395
+ const ptr1 = passArrayF64ToWasm0(target, wasm.__wbindgen_export3);
396
+ const len1 = WASM_VECTOR_LEN;
397
+ wasm.wasmgromovwasserstein_distance(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, dim);
398
+ var r0 = getDataViewMemory0().getFloat64(retptr + 8 * 0, true);
399
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
400
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
401
+ if (r3) {
402
+ throw takeObject(r2);
403
+ }
404
+ return r0;
405
+ } finally {
406
+ wasm.__wbindgen_add_to_stack_pointer(16);
407
+ }
408
+ }
409
+ }
410
+ if (Symbol.dispose) WasmGromovWasserstein.prototype[Symbol.dispose] = WasmGromovWasserstein.prototype.free;
411
+
412
+ /**
413
+ * Natural Gradient optimizer for WASM
414
+ */
415
+ export class WasmNaturalGradient {
416
+ static __wrap(ptr) {
417
+ ptr = ptr >>> 0;
418
+ const obj = Object.create(WasmNaturalGradient.prototype);
419
+ obj.__wbg_ptr = ptr;
420
+ WasmNaturalGradientFinalization.register(obj, obj.__wbg_ptr, obj);
421
+ return obj;
422
+ }
423
+ __destroy_into_raw() {
424
+ const ptr = this.__wbg_ptr;
425
+ this.__wbg_ptr = 0;
426
+ WasmNaturalGradientFinalization.unregister(this);
427
+ return ptr;
428
+ }
429
+ free() {
430
+ const ptr = this.__destroy_into_raw();
431
+ wasm.__wbg_wasmnaturalgradient_free(ptr, 0);
432
+ }
433
+ /**
434
+ * Set damping factor
435
+ * @param {number} damping
436
+ * @returns {WasmNaturalGradient}
437
+ */
438
+ withDamping(damping) {
439
+ const ptr = this.__destroy_into_raw();
440
+ const ret = wasm.wasmnaturalgradient_withDamping(ptr, damping);
441
+ return WasmNaturalGradient.__wrap(ret);
442
+ }
443
+ /**
444
+ * Use diagonal approximation
445
+ * @param {boolean} use_diagonal
446
+ * @returns {WasmNaturalGradient}
447
+ */
448
+ withDiagonal(use_diagonal) {
449
+ const ptr = this.__destroy_into_raw();
450
+ const ret = wasm.wasmnaturalgradient_withDiagonal(ptr, use_diagonal);
451
+ return WasmNaturalGradient.__wrap(ret);
452
+ }
453
+ /**
454
+ * Create a new Natural Gradient optimizer
455
+ * @param {number} learning_rate
456
+ */
457
+ constructor(learning_rate) {
458
+ const ret = wasm.wasmnaturalgradient_new(learning_rate);
459
+ this.__wbg_ptr = ret >>> 0;
460
+ WasmNaturalGradientFinalization.register(this, this.__wbg_ptr, this);
461
+ return this;
462
+ }
463
+ /**
464
+ * Compute update step
465
+ * @param {Float64Array} gradient
466
+ * @param {Float64Array | null | undefined} gradient_samples
467
+ * @param {number} dim
468
+ * @returns {Float64Array}
469
+ */
470
+ step(gradient, gradient_samples, dim) {
471
+ try {
472
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
473
+ const ptr0 = passArrayF64ToWasm0(gradient, wasm.__wbindgen_export3);
474
+ const len0 = WASM_VECTOR_LEN;
475
+ var ptr1 = isLikeNone(gradient_samples) ? 0 : passArrayF64ToWasm0(gradient_samples, wasm.__wbindgen_export3);
476
+ var len1 = WASM_VECTOR_LEN;
477
+ wasm.wasmnaturalgradient_step(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, dim);
478
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
479
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
480
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
481
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
482
+ if (r3) {
483
+ throw takeObject(r2);
484
+ }
485
+ var v3 = getArrayF64FromWasm0(r0, r1).slice();
486
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
487
+ return v3;
488
+ } finally {
489
+ wasm.__wbindgen_add_to_stack_pointer(16);
490
+ }
491
+ }
492
+ /**
493
+ * Reset optimizer state
494
+ */
495
+ reset() {
496
+ wasm.wasmnaturalgradient_reset(this.__wbg_ptr);
497
+ }
498
+ }
499
+ if (Symbol.dispose) WasmNaturalGradient.prototype[Symbol.dispose] = WasmNaturalGradient.prototype.free;
500
+
501
+ /**
502
+ * Product manifold for WASM: E^e × H^h × S^s
503
+ */
504
+ export class WasmProductManifold {
505
+ __destroy_into_raw() {
506
+ const ptr = this.__wbg_ptr;
507
+ this.__wbg_ptr = 0;
508
+ WasmProductManifoldFinalization.unregister(this);
509
+ return ptr;
510
+ }
511
+ free() {
512
+ const ptr = this.__destroy_into_raw();
513
+ wasm.__wbg_wasmproductmanifold_free(ptr, 0);
514
+ }
515
+ /**
516
+ * Fréchet mean
517
+ * @param {Float64Array} points
518
+ * @param {number} _num_points
519
+ * @returns {Float64Array}
520
+ */
521
+ frechetMean(points, _num_points) {
522
+ try {
523
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
524
+ const ptr0 = passArrayF64ToWasm0(points, wasm.__wbindgen_export3);
525
+ const len0 = WASM_VECTOR_LEN;
526
+ wasm.wasmproductmanifold_frechetMean(retptr, this.__wbg_ptr, ptr0, len0, _num_points);
527
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
528
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
529
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
530
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
531
+ if (r3) {
532
+ throw takeObject(r2);
533
+ }
534
+ var v2 = getArrayF64FromWasm0(r0, r1).slice();
535
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
536
+ return v2;
537
+ } finally {
538
+ wasm.__wbindgen_add_to_stack_pointer(16);
539
+ }
540
+ }
541
+ /**
542
+ * Pairwise distances
543
+ * @param {Float64Array} points
544
+ * @returns {Float64Array}
545
+ */
546
+ pairwiseDistances(points) {
547
+ try {
548
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
549
+ const ptr0 = passArrayF64ToWasm0(points, wasm.__wbindgen_export3);
550
+ const len0 = WASM_VECTOR_LEN;
551
+ wasm.wasmproductmanifold_pairwiseDistances(retptr, this.__wbg_ptr, ptr0, len0);
552
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
553
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
554
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
555
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
556
+ if (r3) {
557
+ throw takeObject(r2);
558
+ }
559
+ var v2 = getArrayF64FromWasm0(r0, r1).slice();
560
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
561
+ return v2;
562
+ } finally {
563
+ wasm.__wbindgen_add_to_stack_pointer(16);
564
+ }
565
+ }
566
+ /**
567
+ * Get total dimension
568
+ * @returns {number}
569
+ */
570
+ get dim() {
571
+ const ret = wasm.wasmproductmanifold_dim(this.__wbg_ptr);
572
+ return ret >>> 0;
573
+ }
574
+ /**
575
+ * K-nearest neighbors
576
+ * @param {Float64Array} query
577
+ * @param {Float64Array} points
578
+ * @param {number} k
579
+ * @returns {Uint32Array}
580
+ */
581
+ knn(query, points, k) {
582
+ try {
583
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
584
+ const ptr0 = passArrayF64ToWasm0(query, wasm.__wbindgen_export3);
585
+ const len0 = WASM_VECTOR_LEN;
586
+ const ptr1 = passArrayF64ToWasm0(points, wasm.__wbindgen_export3);
587
+ const len1 = WASM_VECTOR_LEN;
588
+ wasm.wasmproductmanifold_knn(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, k);
589
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
590
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
591
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
592
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
593
+ if (r3) {
594
+ throw takeObject(r2);
595
+ }
596
+ var v3 = getArrayU32FromWasm0(r0, r1).slice();
597
+ wasm.__wbindgen_export2(r0, r1 * 4, 4);
598
+ return v3;
599
+ } finally {
600
+ wasm.__wbindgen_add_to_stack_pointer(16);
601
+ }
602
+ }
603
+ /**
604
+ * Create a new product manifold
605
+ *
606
+ * @param euclidean_dim - Dimension of Euclidean component
607
+ * @param hyperbolic_dim - Dimension of hyperbolic component
608
+ * @param spherical_dim - Dimension of spherical component
609
+ * @param {number} euclidean_dim
610
+ * @param {number} hyperbolic_dim
611
+ * @param {number} spherical_dim
612
+ */
613
+ constructor(euclidean_dim, hyperbolic_dim, spherical_dim) {
614
+ const ret = wasm.wasmproductmanifold_new(euclidean_dim, hyperbolic_dim, spherical_dim);
615
+ this.__wbg_ptr = ret >>> 0;
616
+ WasmProductManifoldFinalization.register(this, this.__wbg_ptr, this);
617
+ return this;
618
+ }
619
+ /**
620
+ * Exponential map
621
+ * @param {Float64Array} x
622
+ * @param {Float64Array} v
623
+ * @returns {Float64Array}
624
+ */
625
+ expMap(x, v) {
626
+ try {
627
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
628
+ const ptr0 = passArrayF64ToWasm0(x, wasm.__wbindgen_export3);
629
+ const len0 = WASM_VECTOR_LEN;
630
+ const ptr1 = passArrayF64ToWasm0(v, wasm.__wbindgen_export3);
631
+ const len1 = WASM_VECTOR_LEN;
632
+ wasm.wasmproductmanifold_expMap(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
633
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
634
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
635
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
636
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
637
+ if (r3) {
638
+ throw takeObject(r2);
639
+ }
640
+ var v3 = getArrayF64FromWasm0(r0, r1).slice();
641
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
642
+ return v3;
643
+ } finally {
644
+ wasm.__wbindgen_add_to_stack_pointer(16);
645
+ }
646
+ }
647
+ /**
648
+ * Logarithmic map
649
+ * @param {Float64Array} x
650
+ * @param {Float64Array} y
651
+ * @returns {Float64Array}
652
+ */
653
+ logMap(x, y) {
654
+ try {
655
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
656
+ const ptr0 = passArrayF64ToWasm0(x, wasm.__wbindgen_export3);
657
+ const len0 = WASM_VECTOR_LEN;
658
+ const ptr1 = passArrayF64ToWasm0(y, wasm.__wbindgen_export3);
659
+ const len1 = WASM_VECTOR_LEN;
660
+ wasm.wasmproductmanifold_logMap(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
661
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
662
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
663
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
664
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
665
+ if (r3) {
666
+ throw takeObject(r2);
667
+ }
668
+ var v3 = getArrayF64FromWasm0(r0, r1).slice();
669
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
670
+ return v3;
671
+ } finally {
672
+ wasm.__wbindgen_add_to_stack_pointer(16);
673
+ }
674
+ }
675
+ /**
676
+ * Project point onto manifold
677
+ * @param {Float64Array} point
678
+ * @returns {Float64Array}
679
+ */
680
+ project(point) {
681
+ try {
682
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
683
+ const ptr0 = passArrayF64ToWasm0(point, wasm.__wbindgen_export3);
684
+ const len0 = WASM_VECTOR_LEN;
685
+ wasm.wasmproductmanifold_project(retptr, this.__wbg_ptr, ptr0, len0);
686
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
687
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
688
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
689
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
690
+ if (r3) {
691
+ throw takeObject(r2);
692
+ }
693
+ var v2 = getArrayF64FromWasm0(r0, r1).slice();
694
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
695
+ return v2;
696
+ } finally {
697
+ wasm.__wbindgen_add_to_stack_pointer(16);
698
+ }
699
+ }
700
+ /**
701
+ * Compute distance in product manifold
702
+ * @param {Float64Array} x
703
+ * @param {Float64Array} y
704
+ * @returns {number}
705
+ */
706
+ distance(x, y) {
707
+ try {
708
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
709
+ const ptr0 = passArrayF64ToWasm0(x, wasm.__wbindgen_export3);
710
+ const len0 = WASM_VECTOR_LEN;
711
+ const ptr1 = passArrayF64ToWasm0(y, wasm.__wbindgen_export3);
712
+ const len1 = WASM_VECTOR_LEN;
713
+ wasm.wasmproductmanifold_distance(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
714
+ var r0 = getDataViewMemory0().getFloat64(retptr + 8 * 0, true);
715
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
716
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
717
+ if (r3) {
718
+ throw takeObject(r2);
719
+ }
720
+ return r0;
721
+ } finally {
722
+ wasm.__wbindgen_add_to_stack_pointer(16);
723
+ }
724
+ }
725
+ /**
726
+ * Geodesic interpolation
727
+ * @param {Float64Array} x
728
+ * @param {Float64Array} y
729
+ * @param {number} t
730
+ * @returns {Float64Array}
731
+ */
732
+ geodesic(x, y, t) {
733
+ try {
734
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
735
+ const ptr0 = passArrayF64ToWasm0(x, wasm.__wbindgen_export3);
736
+ const len0 = WASM_VECTOR_LEN;
737
+ const ptr1 = passArrayF64ToWasm0(y, wasm.__wbindgen_export3);
738
+ const len1 = WASM_VECTOR_LEN;
739
+ wasm.wasmproductmanifold_geodesic(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, t);
740
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
741
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
742
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
743
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
744
+ if (r3) {
745
+ throw takeObject(r2);
746
+ }
747
+ var v3 = getArrayF64FromWasm0(r0, r1).slice();
748
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
749
+ return v3;
750
+ } finally {
751
+ wasm.__wbindgen_add_to_stack_pointer(16);
752
+ }
753
+ }
754
+ }
755
+ if (Symbol.dispose) WasmProductManifold.prototype[Symbol.dispose] = WasmProductManifold.prototype.free;
756
+
757
+ /**
758
+ * Sinkhorn optimal transport solver for WASM
759
+ */
760
+ export class WasmSinkhorn {
761
+ __destroy_into_raw() {
762
+ const ptr = this.__wbg_ptr;
763
+ this.__wbg_ptr = 0;
764
+ WasmSinkhornFinalization.unregister(this);
765
+ return ptr;
766
+ }
767
+ free() {
768
+ const ptr = this.__destroy_into_raw();
769
+ wasm.__wbg_wasmsinkhorn_free(ptr, 0);
770
+ }
771
+ /**
772
+ * Solve optimal transport and return transport plan
773
+ * @param {Float64Array} cost_matrix
774
+ * @param {Float64Array} source_weights
775
+ * @param {Float64Array} target_weights
776
+ * @param {number} n
777
+ * @param {number} m
778
+ * @returns {TransportResult}
779
+ */
780
+ solveTransport(cost_matrix, source_weights, target_weights, n, m) {
781
+ try {
782
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
783
+ const ptr0 = passArrayF64ToWasm0(cost_matrix, wasm.__wbindgen_export3);
784
+ const len0 = WASM_VECTOR_LEN;
785
+ const ptr1 = passArrayF64ToWasm0(source_weights, wasm.__wbindgen_export3);
786
+ const len1 = WASM_VECTOR_LEN;
787
+ const ptr2 = passArrayF64ToWasm0(target_weights, wasm.__wbindgen_export3);
788
+ const len2 = WASM_VECTOR_LEN;
789
+ wasm.wasmsinkhorn_solveTransport(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, n, m);
790
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
791
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
792
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
793
+ if (r2) {
794
+ throw takeObject(r1);
795
+ }
796
+ return TransportResult.__wrap(r0);
797
+ } finally {
798
+ wasm.__wbindgen_add_to_stack_pointer(16);
799
+ }
800
+ }
801
+ /**
802
+ * Create a new Sinkhorn solver
803
+ *
804
+ * @param regularization - Entropy regularization (0.01-0.1 typical)
805
+ * @param max_iterations - Maximum iterations (100-1000 typical)
806
+ * @param {number} regularization
807
+ * @param {number} max_iterations
808
+ */
809
+ constructor(regularization, max_iterations) {
810
+ const ret = wasm.wasmsinkhorn_new(regularization, max_iterations);
811
+ this.__wbg_ptr = ret >>> 0;
812
+ WasmSinkhornFinalization.register(this, this.__wbg_ptr, this);
813
+ return this;
814
+ }
815
+ /**
816
+ * Compute transport cost between point clouds
817
+ * @param {Float64Array} source
818
+ * @param {Float64Array} target
819
+ * @param {number} dim
820
+ * @returns {number}
821
+ */
822
+ distance(source, target, dim) {
823
+ try {
824
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
825
+ const ptr0 = passArrayF64ToWasm0(source, wasm.__wbindgen_export3);
826
+ const len0 = WASM_VECTOR_LEN;
827
+ const ptr1 = passArrayF64ToWasm0(target, wasm.__wbindgen_export3);
828
+ const len1 = WASM_VECTOR_LEN;
829
+ wasm.wasmsinkhorn_distance(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, dim);
830
+ var r0 = getDataViewMemory0().getFloat64(retptr + 8 * 0, true);
831
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
832
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
833
+ if (r3) {
834
+ throw takeObject(r2);
835
+ }
836
+ return r0;
837
+ } finally {
838
+ wasm.__wbindgen_add_to_stack_pointer(16);
839
+ }
840
+ }
841
+ }
842
+ if (Symbol.dispose) WasmSinkhorn.prototype[Symbol.dispose] = WasmSinkhorn.prototype.free;
843
+
844
+ /**
845
+ * Sliced Wasserstein distance calculator for WASM
846
+ */
847
+ export class WasmSlicedWasserstein {
848
+ static __wrap(ptr) {
849
+ ptr = ptr >>> 0;
850
+ const obj = Object.create(WasmSlicedWasserstein.prototype);
851
+ obj.__wbg_ptr = ptr;
852
+ WasmSlicedWassersteinFinalization.register(obj, obj.__wbg_ptr, obj);
853
+ return obj;
854
+ }
855
+ __destroy_into_raw() {
856
+ const ptr = this.__wbg_ptr;
857
+ this.__wbg_ptr = 0;
858
+ WasmSlicedWassersteinFinalization.unregister(this);
859
+ return ptr;
860
+ }
861
+ free() {
862
+ const ptr = this.__destroy_into_raw();
863
+ wasm.__wbg_wasmslicedwasserstein_free(ptr, 0);
864
+ }
865
+ /**
866
+ * Set Wasserstein power (1 for W1, 2 for W2)
867
+ * @param {number} p
868
+ * @returns {WasmSlicedWasserstein}
869
+ */
870
+ withPower(p) {
871
+ const ptr = this.__destroy_into_raw();
872
+ const ret = wasm.wasmslicedwasserstein_withPower(ptr, p);
873
+ return WasmSlicedWasserstein.__wrap(ret);
874
+ }
875
+ /**
876
+ * Compute weighted distance
877
+ * @param {Float64Array} source
878
+ * @param {Float64Array} source_weights
879
+ * @param {Float64Array} target
880
+ * @param {Float64Array} target_weights
881
+ * @param {number} dim
882
+ * @returns {number}
883
+ */
884
+ weightedDistance(source, source_weights, target, target_weights, dim) {
885
+ const ptr0 = passArrayF64ToWasm0(source, wasm.__wbindgen_export3);
886
+ const len0 = WASM_VECTOR_LEN;
887
+ const ptr1 = passArrayF64ToWasm0(source_weights, wasm.__wbindgen_export3);
888
+ const len1 = WASM_VECTOR_LEN;
889
+ const ptr2 = passArrayF64ToWasm0(target, wasm.__wbindgen_export3);
890
+ const len2 = WASM_VECTOR_LEN;
891
+ const ptr3 = passArrayF64ToWasm0(target_weights, wasm.__wbindgen_export3);
892
+ const len3 = WASM_VECTOR_LEN;
893
+ const ret = wasm.wasmslicedwasserstein_weightedDistance(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, dim);
894
+ return ret;
895
+ }
896
+ /**
897
+ * Create a new Sliced Wasserstein calculator
898
+ *
899
+ * @param num_projections - Number of random 1D projections (100-1000 typical)
900
+ * @param {number} num_projections
901
+ */
902
+ constructor(num_projections) {
903
+ const ret = wasm.wasmslicedwasserstein_new(num_projections);
904
+ this.__wbg_ptr = ret >>> 0;
905
+ WasmSlicedWassersteinFinalization.register(this, this.__wbg_ptr, this);
906
+ return this;
907
+ }
908
+ /**
909
+ * Compute distance between two point clouds
910
+ *
911
+ * @param source - Source points as flat array [x1, y1, z1, x2, y2, z2, ...]
912
+ * @param target - Target points as flat array
913
+ * @param dim - Dimension of each point
914
+ * @param {Float64Array} source
915
+ * @param {Float64Array} target
916
+ * @param {number} dim
917
+ * @returns {number}
918
+ */
919
+ distance(source, target, dim) {
920
+ const ptr0 = passArrayF64ToWasm0(source, wasm.__wbindgen_export3);
921
+ const len0 = WASM_VECTOR_LEN;
922
+ const ptr1 = passArrayF64ToWasm0(target, wasm.__wbindgen_export3);
923
+ const len1 = WASM_VECTOR_LEN;
924
+ const ret = wasm.wasmslicedwasserstein_distance(this.__wbg_ptr, ptr0, len0, ptr1, len1, dim);
925
+ return ret;
926
+ }
927
+ /**
928
+ * Set random seed for reproducibility
929
+ * @param {bigint} seed
930
+ * @returns {WasmSlicedWasserstein}
931
+ */
932
+ withSeed(seed) {
933
+ const ptr = this.__destroy_into_raw();
934
+ const ret = wasm.wasmslicedwasserstein_withSeed(ptr, seed);
935
+ return WasmSlicedWasserstein.__wrap(ret);
936
+ }
937
+ }
938
+ if (Symbol.dispose) WasmSlicedWasserstein.prototype[Symbol.dispose] = WasmSlicedWasserstein.prototype.free;
939
+
940
+ /**
941
+ * Spherical space operations for WASM
942
+ */
943
+ export class WasmSphericalSpace {
944
+ __destroy_into_raw() {
945
+ const ptr = this.__wbg_ptr;
946
+ this.__wbg_ptr = 0;
947
+ WasmSphericalSpaceFinalization.unregister(this);
948
+ return ptr;
949
+ }
950
+ free() {
951
+ const ptr = this.__destroy_into_raw();
952
+ wasm.__wbg_wasmsphericalspace_free(ptr, 0);
953
+ }
954
+ /**
955
+ * Get ambient dimension
956
+ * @returns {number}
957
+ */
958
+ get ambientDim() {
959
+ const ret = wasm.wasmsphericalspace_ambientDim(this.__wbg_ptr);
960
+ return ret >>> 0;
961
+ }
962
+ /**
963
+ * Fréchet mean of points
964
+ * @param {Float64Array} points
965
+ * @param {number} dim
966
+ * @returns {Float64Array}
967
+ */
968
+ frechetMean(points, dim) {
969
+ try {
970
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
971
+ const ptr0 = passArrayF64ToWasm0(points, wasm.__wbindgen_export3);
972
+ const len0 = WASM_VECTOR_LEN;
973
+ wasm.wasmsphericalspace_frechetMean(retptr, this.__wbg_ptr, ptr0, len0, dim);
974
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
975
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
976
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
977
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
978
+ if (r3) {
979
+ throw takeObject(r2);
980
+ }
981
+ var v2 = getArrayF64FromWasm0(r0, r1).slice();
982
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
983
+ return v2;
984
+ } finally {
985
+ wasm.__wbindgen_add_to_stack_pointer(16);
986
+ }
987
+ }
988
+ /**
989
+ * Create a new spherical space S^{n-1} embedded in R^n
990
+ * @param {number} ambient_dim
991
+ */
992
+ constructor(ambient_dim) {
993
+ const ret = wasm.wasmsphericalspace_new(ambient_dim);
994
+ this.__wbg_ptr = ret >>> 0;
995
+ WasmSphericalSpaceFinalization.register(this, this.__wbg_ptr, this);
996
+ return this;
997
+ }
998
+ /**
999
+ * Exponential map: move from x in direction v
1000
+ * @param {Float64Array} x
1001
+ * @param {Float64Array} v
1002
+ * @returns {Float64Array}
1003
+ */
1004
+ expMap(x, v) {
1005
+ try {
1006
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1007
+ const ptr0 = passArrayF64ToWasm0(x, wasm.__wbindgen_export3);
1008
+ const len0 = WASM_VECTOR_LEN;
1009
+ const ptr1 = passArrayF64ToWasm0(v, wasm.__wbindgen_export3);
1010
+ const len1 = WASM_VECTOR_LEN;
1011
+ wasm.wasmsphericalspace_expMap(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
1012
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1013
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1014
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1015
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1016
+ if (r3) {
1017
+ throw takeObject(r2);
1018
+ }
1019
+ var v3 = getArrayF64FromWasm0(r0, r1).slice();
1020
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
1021
+ return v3;
1022
+ } finally {
1023
+ wasm.__wbindgen_add_to_stack_pointer(16);
1024
+ }
1025
+ }
1026
+ /**
1027
+ * Logarithmic map: tangent vector at x pointing toward y
1028
+ * @param {Float64Array} x
1029
+ * @param {Float64Array} y
1030
+ * @returns {Float64Array}
1031
+ */
1032
+ logMap(x, y) {
1033
+ try {
1034
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1035
+ const ptr0 = passArrayF64ToWasm0(x, wasm.__wbindgen_export3);
1036
+ const len0 = WASM_VECTOR_LEN;
1037
+ const ptr1 = passArrayF64ToWasm0(y, wasm.__wbindgen_export3);
1038
+ const len1 = WASM_VECTOR_LEN;
1039
+ wasm.wasmsphericalspace_logMap(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
1040
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1041
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1042
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1043
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1044
+ if (r3) {
1045
+ throw takeObject(r2);
1046
+ }
1047
+ var v3 = getArrayF64FromWasm0(r0, r1).slice();
1048
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
1049
+ return v3;
1050
+ } finally {
1051
+ wasm.__wbindgen_add_to_stack_pointer(16);
1052
+ }
1053
+ }
1054
+ /**
1055
+ * Project point onto sphere
1056
+ * @param {Float64Array} point
1057
+ * @returns {Float64Array}
1058
+ */
1059
+ project(point) {
1060
+ try {
1061
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1062
+ const ptr0 = passArrayF64ToWasm0(point, wasm.__wbindgen_export3);
1063
+ const len0 = WASM_VECTOR_LEN;
1064
+ wasm.wasmsphericalspace_project(retptr, this.__wbg_ptr, ptr0, len0);
1065
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1066
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1067
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1068
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1069
+ if (r3) {
1070
+ throw takeObject(r2);
1071
+ }
1072
+ var v2 = getArrayF64FromWasm0(r0, r1).slice();
1073
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
1074
+ return v2;
1075
+ } finally {
1076
+ wasm.__wbindgen_add_to_stack_pointer(16);
1077
+ }
1078
+ }
1079
+ /**
1080
+ * Geodesic distance on sphere
1081
+ * @param {Float64Array} x
1082
+ * @param {Float64Array} y
1083
+ * @returns {number}
1084
+ */
1085
+ distance(x, y) {
1086
+ try {
1087
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1088
+ const ptr0 = passArrayF64ToWasm0(x, wasm.__wbindgen_export3);
1089
+ const len0 = WASM_VECTOR_LEN;
1090
+ const ptr1 = passArrayF64ToWasm0(y, wasm.__wbindgen_export3);
1091
+ const len1 = WASM_VECTOR_LEN;
1092
+ wasm.wasmsphericalspace_distance(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
1093
+ var r0 = getDataViewMemory0().getFloat64(retptr + 8 * 0, true);
1094
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1095
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1096
+ if (r3) {
1097
+ throw takeObject(r2);
1098
+ }
1099
+ return r0;
1100
+ } finally {
1101
+ wasm.__wbindgen_add_to_stack_pointer(16);
1102
+ }
1103
+ }
1104
+ /**
1105
+ * Geodesic interpolation at fraction t
1106
+ * @param {Float64Array} x
1107
+ * @param {Float64Array} y
1108
+ * @param {number} t
1109
+ * @returns {Float64Array}
1110
+ */
1111
+ geodesic(x, y, t) {
1112
+ try {
1113
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1114
+ const ptr0 = passArrayF64ToWasm0(x, wasm.__wbindgen_export3);
1115
+ const len0 = WASM_VECTOR_LEN;
1116
+ const ptr1 = passArrayF64ToWasm0(y, wasm.__wbindgen_export3);
1117
+ const len1 = WASM_VECTOR_LEN;
1118
+ wasm.wasmsphericalspace_geodesic(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, t);
1119
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1120
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1121
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1122
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1123
+ if (r3) {
1124
+ throw takeObject(r2);
1125
+ }
1126
+ var v3 = getArrayF64FromWasm0(r0, r1).slice();
1127
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
1128
+ return v3;
1129
+ } finally {
1130
+ wasm.__wbindgen_add_to_stack_pointer(16);
1131
+ }
1132
+ }
1133
+ }
1134
+ if (Symbol.dispose) WasmSphericalSpace.prototype[Symbol.dispose] = WasmSphericalSpace.prototype.free;
1135
+
1136
+ export function start() {
1137
+ wasm.start();
1138
+ }
1139
+
1140
+ const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
1141
+
1142
+ async function __wbg_load(module, imports) {
1143
+ if (typeof Response === 'function' && module instanceof Response) {
1144
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
1145
+ try {
1146
+ return await WebAssembly.instantiateStreaming(module, imports);
1147
+ } catch (e) {
1148
+ const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
1149
+
1150
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
1151
+ 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);
1152
+
1153
+ } else {
1154
+ throw e;
1155
+ }
1156
+ }
1157
+ }
1158
+
1159
+ const bytes = await module.arrayBuffer();
1160
+ return await WebAssembly.instantiate(bytes, imports);
1161
+ } else {
1162
+ const instance = await WebAssembly.instantiate(module, imports);
1163
+
1164
+ if (instance instanceof WebAssembly.Instance) {
1165
+ return { instance, module };
1166
+ } else {
1167
+ return instance;
1168
+ }
1169
+ }
1170
+ }
1171
+
1172
+ function __wbg_get_imports() {
1173
+ const imports = {};
1174
+ imports.wbg = {};
1175
+ imports.wbg.__wbg_Error_52673b7de5a0ca89 = function(arg0, arg1) {
1176
+ const ret = Error(getStringFromWasm0(arg0, arg1));
1177
+ return addHeapObject(ret);
1178
+ };
1179
+ imports.wbg.__wbg___wbindgen_is_function_8d400b8b1af978cd = function(arg0) {
1180
+ const ret = typeof(getObject(arg0)) === 'function';
1181
+ return ret;
1182
+ };
1183
+ imports.wbg.__wbg___wbindgen_is_object_ce774f3490692386 = function(arg0) {
1184
+ const val = getObject(arg0);
1185
+ const ret = typeof(val) === 'object' && val !== null;
1186
+ return ret;
1187
+ };
1188
+ imports.wbg.__wbg___wbindgen_is_string_704ef9c8fc131030 = function(arg0) {
1189
+ const ret = typeof(getObject(arg0)) === 'string';
1190
+ return ret;
1191
+ };
1192
+ imports.wbg.__wbg___wbindgen_is_undefined_f6b95eab589e0269 = function(arg0) {
1193
+ const ret = getObject(arg0) === undefined;
1194
+ return ret;
1195
+ };
1196
+ imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
1197
+ throw new Error(getStringFromWasm0(arg0, arg1));
1198
+ };
1199
+ imports.wbg.__wbg_call_3020136f7a2d6e44 = function() { return handleError(function (arg0, arg1, arg2) {
1200
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
1201
+ return addHeapObject(ret);
1202
+ }, arguments) };
1203
+ imports.wbg.__wbg_call_abb4ff46ce38be40 = function() { return handleError(function (arg0, arg1) {
1204
+ const ret = getObject(arg0).call(getObject(arg1));
1205
+ return addHeapObject(ret);
1206
+ }, arguments) };
1207
+ imports.wbg.__wbg_crypto_574e78ad8b13b65f = function(arg0) {
1208
+ const ret = getObject(arg0).crypto;
1209
+ return addHeapObject(ret);
1210
+ };
1211
+ imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
1212
+ let deferred0_0;
1213
+ let deferred0_1;
1214
+ try {
1215
+ deferred0_0 = arg0;
1216
+ deferred0_1 = arg1;
1217
+ console.error(getStringFromWasm0(arg0, arg1));
1218
+ } finally {
1219
+ wasm.__wbindgen_export2(deferred0_0, deferred0_1, 1);
1220
+ }
1221
+ };
1222
+ imports.wbg.__wbg_getRandomValues_b8f5dbd5f3995a9e = function() { return handleError(function (arg0, arg1) {
1223
+ getObject(arg0).getRandomValues(getObject(arg1));
1224
+ }, arguments) };
1225
+ imports.wbg.__wbg_length_22ac23eaec9d8053 = function(arg0) {
1226
+ const ret = getObject(arg0).length;
1227
+ return ret;
1228
+ };
1229
+ imports.wbg.__wbg_msCrypto_a61aeb35a24c1329 = function(arg0) {
1230
+ const ret = getObject(arg0).msCrypto;
1231
+ return addHeapObject(ret);
1232
+ };
1233
+ imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
1234
+ const ret = new Error();
1235
+ return addHeapObject(ret);
1236
+ };
1237
+ imports.wbg.__wbg_new_no_args_cb138f77cf6151ee = function(arg0, arg1) {
1238
+ const ret = new Function(getStringFromWasm0(arg0, arg1));
1239
+ return addHeapObject(ret);
1240
+ };
1241
+ imports.wbg.__wbg_new_with_length_aa5eaf41d35235e5 = function(arg0) {
1242
+ const ret = new Uint8Array(arg0 >>> 0);
1243
+ return addHeapObject(ret);
1244
+ };
1245
+ imports.wbg.__wbg_node_905d3e251edff8a2 = function(arg0) {
1246
+ const ret = getObject(arg0).node;
1247
+ return addHeapObject(ret);
1248
+ };
1249
+ imports.wbg.__wbg_process_dc0fbacc7c1c06f7 = function(arg0) {
1250
+ const ret = getObject(arg0).process;
1251
+ return addHeapObject(ret);
1252
+ };
1253
+ imports.wbg.__wbg_prototypesetcall_dfe9b766cdc1f1fd = function(arg0, arg1, arg2) {
1254
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
1255
+ };
1256
+ imports.wbg.__wbg_randomFillSync_ac0988aba3254290 = function() { return handleError(function (arg0, arg1) {
1257
+ getObject(arg0).randomFillSync(takeObject(arg1));
1258
+ }, arguments) };
1259
+ imports.wbg.__wbg_require_60cc747a6bc5215a = function() { return handleError(function () {
1260
+ const ret = module.require;
1261
+ return addHeapObject(ret);
1262
+ }, arguments) };
1263
+ imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
1264
+ const ret = getObject(arg1).stack;
1265
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
1266
+ const len1 = WASM_VECTOR_LEN;
1267
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1268
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1269
+ };
1270
+ imports.wbg.__wbg_static_accessor_GLOBAL_769e6b65d6557335 = function() {
1271
+ const ret = typeof global === 'undefined' ? null : global;
1272
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
1273
+ };
1274
+ imports.wbg.__wbg_static_accessor_GLOBAL_THIS_60cf02db4de8e1c1 = function() {
1275
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
1276
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
1277
+ };
1278
+ imports.wbg.__wbg_static_accessor_SELF_08f5a74c69739274 = function() {
1279
+ const ret = typeof self === 'undefined' ? null : self;
1280
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
1281
+ };
1282
+ imports.wbg.__wbg_static_accessor_WINDOW_a8924b26aa92d024 = function() {
1283
+ const ret = typeof window === 'undefined' ? null : window;
1284
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
1285
+ };
1286
+ imports.wbg.__wbg_subarray_845f2f5bce7d061a = function(arg0, arg1, arg2) {
1287
+ const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);
1288
+ return addHeapObject(ret);
1289
+ };
1290
+ imports.wbg.__wbg_versions_c01dfd4722a88165 = function(arg0) {
1291
+ const ret = getObject(arg0).versions;
1292
+ return addHeapObject(ret);
1293
+ };
1294
+ imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
1295
+ // Cast intrinsic for `Ref(String) -> Externref`.
1296
+ const ret = getStringFromWasm0(arg0, arg1);
1297
+ return addHeapObject(ret);
1298
+ };
1299
+ imports.wbg.__wbindgen_cast_cb9088102bce6b30 = function(arg0, arg1) {
1300
+ // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
1301
+ const ret = getArrayU8FromWasm0(arg0, arg1);
1302
+ return addHeapObject(ret);
1303
+ };
1304
+ imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
1305
+ const ret = getObject(arg0);
1306
+ return addHeapObject(ret);
1307
+ };
1308
+ imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
1309
+ takeObject(arg0);
1310
+ };
1311
+
1312
+ return imports;
1313
+ }
1314
+
1315
+ function __wbg_finalize_init(instance, module) {
1316
+ wasm = instance.exports;
1317
+ __wbg_init.__wbindgen_wasm_module = module;
1318
+ cachedDataViewMemory0 = null;
1319
+ cachedFloat64ArrayMemory0 = null;
1320
+ cachedUint32ArrayMemory0 = null;
1321
+ cachedUint8ArrayMemory0 = null;
1322
+
1323
+
1324
+ wasm.__wbindgen_start();
1325
+ return wasm;
1326
+ }
1327
+
1328
+ function initSync(module) {
1329
+ if (wasm !== undefined) return wasm;
1330
+
1331
+
1332
+ if (typeof module !== 'undefined') {
1333
+ if (Object.getPrototypeOf(module) === Object.prototype) {
1334
+ ({module} = module)
1335
+ } else {
1336
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
1337
+ }
1338
+ }
1339
+
1340
+ const imports = __wbg_get_imports();
1341
+ if (!(module instanceof WebAssembly.Module)) {
1342
+ module = new WebAssembly.Module(module);
1343
+ }
1344
+ const instance = new WebAssembly.Instance(module, imports);
1345
+ return __wbg_finalize_init(instance, module);
1346
+ }
1347
+
1348
+ async function __wbg_init(module_or_path) {
1349
+ if (wasm !== undefined) return wasm;
1350
+
1351
+
1352
+ if (typeof module_or_path !== 'undefined') {
1353
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
1354
+ ({module_or_path} = module_or_path)
1355
+ } else {
1356
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
1357
+ }
1358
+ }
1359
+
1360
+ if (typeof module_or_path === 'undefined') {
1361
+ module_or_path = new URL('ruvector_math_wasm_bg.wasm', import.meta.url);
1362
+ }
1363
+ const imports = __wbg_get_imports();
1364
+
1365
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
1366
+ module_or_path = fetch(module_or_path);
1367
+ }
1368
+
1369
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
1370
+
1371
+ return __wbg_finalize_init(instance, module);
1372
+ }
1373
+
1374
+ export { initSync };
1375
+ export default __wbg_init;