qft-wasm 1.0.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.
- package/README.md +299 -0
- package/package.json +31 -0
- package/qft_wasm.d.ts +288 -0
- package/qft_wasm.js +899 -0
- package/qft_wasm_bg.wasm +0 -0
package/qft_wasm.js
ADDED
|
@@ -0,0 +1,899 @@
|
|
|
1
|
+
/* @ts-self-types="./qft_wasm.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Encoding strategies for file conversion.
|
|
5
|
+
* @enum {0 | 1 | 2 | 3 | 4}
|
|
6
|
+
*/
|
|
7
|
+
export const Encoding = Object.freeze({
|
|
8
|
+
Amplitude: 0, "0": "Amplitude",
|
|
9
|
+
BasisState: 1, "1": "BasisState",
|
|
10
|
+
Qram: 2, "2": "Qram",
|
|
11
|
+
Angle: 3, "3": "Angle",
|
|
12
|
+
Block: 4, "4": "Block",
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A Quantum File Type (.qft) file handle for JavaScript/TypeScript.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```javascript
|
|
20
|
+
* import { QftFile } from 'qft-wasm';
|
|
21
|
+
*
|
|
22
|
+
* // Create a 4-qubit state
|
|
23
|
+
* const file = new QftFile(4);
|
|
24
|
+
* console.log(file.numQubits); // 4
|
|
25
|
+
* console.log(file.dimension); // 16
|
|
26
|
+
*
|
|
27
|
+
* // Set Bell-like state
|
|
28
|
+
* const real = new Float64Array(16);
|
|
29
|
+
* const imag = new Float64Array(16);
|
|
30
|
+
* real[0] = 1 / Math.sqrt(2);
|
|
31
|
+
* real[15] = 1 / Math.sqrt(2);
|
|
32
|
+
* file.setAmplitudes(real, imag);
|
|
33
|
+
*
|
|
34
|
+
* // Save to bytes
|
|
35
|
+
* const bytes = file.toBytes();
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export class QftFile {
|
|
39
|
+
static __wrap(ptr) {
|
|
40
|
+
ptr = ptr >>> 0;
|
|
41
|
+
const obj = Object.create(QftFile.prototype);
|
|
42
|
+
obj.__wbg_ptr = ptr;
|
|
43
|
+
QftFileFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
44
|
+
return obj;
|
|
45
|
+
}
|
|
46
|
+
__destroy_into_raw() {
|
|
47
|
+
const ptr = this.__wbg_ptr;
|
|
48
|
+
this.__wbg_ptr = 0;
|
|
49
|
+
QftFileFinalization.unregister(this);
|
|
50
|
+
return ptr;
|
|
51
|
+
}
|
|
52
|
+
free() {
|
|
53
|
+
const ptr = this.__destroy_into_raw();
|
|
54
|
+
wasm.__wbg_qftfile_free(ptr, 0);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Bond dimension for MPS compression.
|
|
58
|
+
* @returns {number}
|
|
59
|
+
*/
|
|
60
|
+
get bondDimension() {
|
|
61
|
+
const ret = wasm.qftfile_bondDimension(this.__wbg_ptr);
|
|
62
|
+
return ret >>> 0;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Dimension of the state vector (2^numQubits).
|
|
66
|
+
* @returns {number}
|
|
67
|
+
*/
|
|
68
|
+
get dimension() {
|
|
69
|
+
const ret = wasm.qftfile_dimension(this.__wbg_ptr);
|
|
70
|
+
return ret >>> 0;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Calculate fidelity with another state: |⟨self|other⟩|².
|
|
74
|
+
*
|
|
75
|
+
* @param other - Another QftFile
|
|
76
|
+
* @returns Fidelity between 0 and 1
|
|
77
|
+
* @param {QftFile} other
|
|
78
|
+
* @returns {number}
|
|
79
|
+
*/
|
|
80
|
+
fidelity(other) {
|
|
81
|
+
_assertClass(other, QftFile);
|
|
82
|
+
const ret = wasm.qftfile_fidelity(this.__wbg_ptr, other.__wbg_ptr);
|
|
83
|
+
if (ret[2]) {
|
|
84
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
85
|
+
}
|
|
86
|
+
return ret[0];
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Create from Uint8Array.
|
|
90
|
+
* @param {Uint8Array} data
|
|
91
|
+
* @returns {QftFile}
|
|
92
|
+
*/
|
|
93
|
+
static fromBytes(data) {
|
|
94
|
+
const ret = wasm.qftfile_fromBytes(data);
|
|
95
|
+
if (ret[2]) {
|
|
96
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
97
|
+
}
|
|
98
|
+
return QftFile.__wrap(ret[0]);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Create from JSON string.
|
|
102
|
+
* @param {string} json
|
|
103
|
+
* @returns {QftFile}
|
|
104
|
+
*/
|
|
105
|
+
static fromJson(json) {
|
|
106
|
+
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
107
|
+
const len0 = WASM_VECTOR_LEN;
|
|
108
|
+
const ret = wasm.qftfile_fromJson(ptr0, len0);
|
|
109
|
+
if (ret[2]) {
|
|
110
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
111
|
+
}
|
|
112
|
+
return QftFile.__wrap(ret[0]);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get a single amplitude by basis state index.
|
|
116
|
+
*
|
|
117
|
+
* @param index - Basis state index (0 to 2^n - 1)
|
|
118
|
+
* @returns Object with real and imag properties
|
|
119
|
+
* @param {number} index
|
|
120
|
+
* @returns {any}
|
|
121
|
+
*/
|
|
122
|
+
getAmplitude(index) {
|
|
123
|
+
const ret = wasm.qftfile_getAmplitude(this.__wbg_ptr, index);
|
|
124
|
+
if (ret[2]) {
|
|
125
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
126
|
+
}
|
|
127
|
+
return takeFromExternrefTable0(ret[0]);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get the imaginary parts of amplitudes as Float64Array.
|
|
131
|
+
* @returns {Float64Array}
|
|
132
|
+
*/
|
|
133
|
+
getAmplitudesImag() {
|
|
134
|
+
const ret = wasm.qftfile_getAmplitudesImag(this.__wbg_ptr);
|
|
135
|
+
return ret;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Get the real parts of amplitudes as Float64Array.
|
|
139
|
+
* @returns {Float64Array}
|
|
140
|
+
*/
|
|
141
|
+
getAmplitudesReal() {
|
|
142
|
+
const ret = wasm.qftfile_getAmplitudesReal(this.__wbg_ptr);
|
|
143
|
+
return ret;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Get metadata value by key.
|
|
147
|
+
* @param {string} key
|
|
148
|
+
* @returns {string | undefined}
|
|
149
|
+
*/
|
|
150
|
+
getMetadata(key) {
|
|
151
|
+
const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
152
|
+
const len0 = WASM_VECTOR_LEN;
|
|
153
|
+
const ret = wasm.qftfile_getMetadata(this.__wbg_ptr, ptr0, len0);
|
|
154
|
+
let v2;
|
|
155
|
+
if (ret[0] !== 0) {
|
|
156
|
+
v2 = getStringFromWasm0(ret[0], ret[1]).slice();
|
|
157
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
158
|
+
}
|
|
159
|
+
return v2;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Get all metadata as a JavaScript object.
|
|
163
|
+
* @returns {any}
|
|
164
|
+
*/
|
|
165
|
+
getMetadataObject() {
|
|
166
|
+
const ret = wasm.qftfile_getMetadataObject(this.__wbg_ptr);
|
|
167
|
+
if (ret[2]) {
|
|
168
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
169
|
+
}
|
|
170
|
+
return takeFromExternrefTable0(ret[0]);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Whether Golay error correction is enabled.
|
|
174
|
+
* @returns {boolean}
|
|
175
|
+
*/
|
|
176
|
+
get golayEnabled() {
|
|
177
|
+
const ret = wasm.qftfile_golayEnabled(this.__wbg_ptr);
|
|
178
|
+
return ret !== 0;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Check if the state is normalized.
|
|
182
|
+
*
|
|
183
|
+
* @param tolerance - Tolerance for check (default: 1e-10)
|
|
184
|
+
* @returns true if normalized within tolerance
|
|
185
|
+
* @param {number | null} [tolerance]
|
|
186
|
+
* @returns {boolean}
|
|
187
|
+
*/
|
|
188
|
+
isNormalized(tolerance) {
|
|
189
|
+
const ret = wasm.qftfile_isNormalized(this.__wbg_ptr, !isLikeNone(tolerance), isLikeNone(tolerance) ? 0 : tolerance);
|
|
190
|
+
return ret !== 0;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Create a new QFT file with the specified number of qubits.
|
|
194
|
+
*
|
|
195
|
+
* @param numQubits - Number of qubits (1-30)
|
|
196
|
+
* @returns A new QftFile initialized to |0...0⟩
|
|
197
|
+
* @throws Error if numQubits is not in range 1-30
|
|
198
|
+
* @param {number} num_qubits
|
|
199
|
+
*/
|
|
200
|
+
constructor(num_qubits) {
|
|
201
|
+
const ret = wasm.qftfile_new(num_qubits);
|
|
202
|
+
if (ret[2]) {
|
|
203
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
204
|
+
}
|
|
205
|
+
this.__wbg_ptr = ret[0] >>> 0;
|
|
206
|
+
QftFileFinalization.register(this, this.__wbg_ptr, this);
|
|
207
|
+
return this;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Calculate the norm squared.
|
|
211
|
+
* @returns {number}
|
|
212
|
+
*/
|
|
213
|
+
normSquared() {
|
|
214
|
+
const ret = wasm.qftfile_normSquared(this.__wbg_ptr);
|
|
215
|
+
return ret;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Normalize the state vector in place.
|
|
219
|
+
*/
|
|
220
|
+
normalize() {
|
|
221
|
+
const ret = wasm.qftfile_normalize(this.__wbg_ptr);
|
|
222
|
+
if (ret[1]) {
|
|
223
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Number of qubits in the quantum state.
|
|
228
|
+
* @returns {number}
|
|
229
|
+
*/
|
|
230
|
+
get numQubits() {
|
|
231
|
+
const ret = wasm.qftfile_numQubits(this.__wbg_ptr);
|
|
232
|
+
return ret >>> 0;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Set a single amplitude by basis state index.
|
|
236
|
+
*
|
|
237
|
+
* @param index - Basis state index (0 to 2^n - 1)
|
|
238
|
+
* @param real - Real part of amplitude
|
|
239
|
+
* @param imag - Imaginary part of amplitude
|
|
240
|
+
* @param {number} index
|
|
241
|
+
* @param {number} real
|
|
242
|
+
* @param {number} imag
|
|
243
|
+
*/
|
|
244
|
+
setAmplitude(index, real, imag) {
|
|
245
|
+
const ret = wasm.qftfile_setAmplitude(this.__wbg_ptr, index, real, imag);
|
|
246
|
+
if (ret[1]) {
|
|
247
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Set amplitudes from Float64Arrays.
|
|
252
|
+
*
|
|
253
|
+
* @param real - Real parts of amplitudes
|
|
254
|
+
* @param imag - Imaginary parts of amplitudes
|
|
255
|
+
* @param {Float64Array} real
|
|
256
|
+
* @param {Float64Array} imag
|
|
257
|
+
*/
|
|
258
|
+
setAmplitudes(real, imag) {
|
|
259
|
+
const ret = wasm.qftfile_setAmplitudes(this.__wbg_ptr, real, imag);
|
|
260
|
+
if (ret[1]) {
|
|
261
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Set metadata key-value pair.
|
|
266
|
+
* @param {string} key
|
|
267
|
+
* @param {string} value
|
|
268
|
+
*/
|
|
269
|
+
setMetadata(key, value) {
|
|
270
|
+
const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
271
|
+
const len0 = WASM_VECTOR_LEN;
|
|
272
|
+
const ptr1 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
273
|
+
const len1 = WASM_VECTOR_LEN;
|
|
274
|
+
wasm.qftfile_setMetadata(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* @param {number} value
|
|
278
|
+
*/
|
|
279
|
+
set bondDimension(value) {
|
|
280
|
+
const ret = wasm.qftfile_set_bondDimension(this.__wbg_ptr, value);
|
|
281
|
+
if (ret[1]) {
|
|
282
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* @param {boolean} value
|
|
287
|
+
*/
|
|
288
|
+
set golayEnabled(value) {
|
|
289
|
+
wasm.qftfile_set_golayEnabled(this.__wbg_ptr, value);
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Serialize to Uint8Array.
|
|
293
|
+
* @returns {Uint8Array}
|
|
294
|
+
*/
|
|
295
|
+
toBytes() {
|
|
296
|
+
const ret = wasm.qftfile_toBytes(this.__wbg_ptr);
|
|
297
|
+
return ret;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Export to JSON string.
|
|
301
|
+
* @returns {string}
|
|
302
|
+
*/
|
|
303
|
+
toJson() {
|
|
304
|
+
let deferred2_0;
|
|
305
|
+
let deferred2_1;
|
|
306
|
+
try {
|
|
307
|
+
const ret = wasm.qftfile_toJson(this.__wbg_ptr);
|
|
308
|
+
var ptr1 = ret[0];
|
|
309
|
+
var len1 = ret[1];
|
|
310
|
+
if (ret[3]) {
|
|
311
|
+
ptr1 = 0; len1 = 0;
|
|
312
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
313
|
+
}
|
|
314
|
+
deferred2_0 = ptr1;
|
|
315
|
+
deferred2_1 = len1;
|
|
316
|
+
return getStringFromWasm0(ptr1, len1);
|
|
317
|
+
} finally {
|
|
318
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (Symbol.dispose) QftFile.prototype[Symbol.dispose] = QftFile.prototype.free;
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Streaming converter for large files.
|
|
326
|
+
*/
|
|
327
|
+
export class StreamingConverter {
|
|
328
|
+
__destroy_into_raw() {
|
|
329
|
+
const ptr = this.__wbg_ptr;
|
|
330
|
+
this.__wbg_ptr = 0;
|
|
331
|
+
StreamingConverterFinalization.unregister(this);
|
|
332
|
+
return ptr;
|
|
333
|
+
}
|
|
334
|
+
free() {
|
|
335
|
+
const ptr = this.__destroy_into_raw();
|
|
336
|
+
wasm.__wbg_streamingconverter_free(ptr, 0);
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Get recommended chunk size.
|
|
340
|
+
* @returns {number}
|
|
341
|
+
*/
|
|
342
|
+
get chunkSize() {
|
|
343
|
+
const ret = wasm.streamingconverter_chunkSize(this.__wbg_ptr);
|
|
344
|
+
return ret >>> 0;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Check if conversion is complete.
|
|
348
|
+
* @returns {boolean}
|
|
349
|
+
*/
|
|
350
|
+
get isComplete() {
|
|
351
|
+
const ret = wasm.streamingconverter_isComplete(this.__wbg_ptr);
|
|
352
|
+
return ret !== 0;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Create a new streaming converter.
|
|
356
|
+
*
|
|
357
|
+
* @param totalSize - Total size of input data in bytes
|
|
358
|
+
* @param chunkSize - Size of each chunk (default: 1MB)
|
|
359
|
+
* @param encoding - Encoding strategy (default: Amplitude)
|
|
360
|
+
* @param {number} total_size
|
|
361
|
+
* @param {number | null} [chunk_size]
|
|
362
|
+
* @param {Encoding | null} [encoding]
|
|
363
|
+
*/
|
|
364
|
+
constructor(total_size, chunk_size, encoding) {
|
|
365
|
+
const ret = wasm.streamingconverter_new(total_size, isLikeNone(chunk_size) ? 0x100000001 : (chunk_size) >>> 0, isLikeNone(encoding) ? 5 : encoding);
|
|
366
|
+
this.__wbg_ptr = ret >>> 0;
|
|
367
|
+
StreamingConverterFinalization.register(this, this.__wbg_ptr, this);
|
|
368
|
+
return this;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Process a chunk of data.
|
|
372
|
+
*
|
|
373
|
+
* @param data - Uint8Array chunk
|
|
374
|
+
* @returns QftFile for this chunk
|
|
375
|
+
* @param {Uint8Array} data
|
|
376
|
+
* @returns {QftFile}
|
|
377
|
+
*/
|
|
378
|
+
processChunk(data) {
|
|
379
|
+
const ret = wasm.streamingconverter_processChunk(this.__wbg_ptr, data);
|
|
380
|
+
if (ret[2]) {
|
|
381
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
382
|
+
}
|
|
383
|
+
return QftFile.__wrap(ret[0]);
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Get conversion progress (0.0 to 1.0).
|
|
387
|
+
* @returns {number}
|
|
388
|
+
*/
|
|
389
|
+
get progress() {
|
|
390
|
+
const ret = wasm.streamingconverter_progress(this.__wbg_ptr);
|
|
391
|
+
return ret;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
if (Symbol.dispose) StreamingConverter.prototype[Symbol.dispose] = StreamingConverter.prototype.free;
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Create a Bell state for testing.
|
|
398
|
+
* @returns {QftFile}
|
|
399
|
+
*/
|
|
400
|
+
export function createBellState() {
|
|
401
|
+
const ret = wasm.createBellState();
|
|
402
|
+
if (ret[2]) {
|
|
403
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
404
|
+
}
|
|
405
|
+
return QftFile.__wrap(ret[0]);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Create a GHZ state for testing.
|
|
410
|
+
* @param {number} num_qubits
|
|
411
|
+
* @returns {QftFile}
|
|
412
|
+
*/
|
|
413
|
+
export function createGhzState(num_qubits) {
|
|
414
|
+
const ret = wasm.createGhzState(num_qubits);
|
|
415
|
+
if (ret[2]) {
|
|
416
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
417
|
+
}
|
|
418
|
+
return QftFile.__wrap(ret[0]);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Create a uniform superposition state.
|
|
423
|
+
* @param {number} num_qubits
|
|
424
|
+
* @returns {QftFile}
|
|
425
|
+
*/
|
|
426
|
+
export function createUniformState(num_qubits) {
|
|
427
|
+
const ret = wasm.createUniformState(num_qubits);
|
|
428
|
+
if (ret[2]) {
|
|
429
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
430
|
+
}
|
|
431
|
+
return QftFile.__wrap(ret[0]);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Calculate fidelity between two states from bytes.
|
|
436
|
+
* @param {Uint8Array} data1
|
|
437
|
+
* @param {Uint8Array} data2
|
|
438
|
+
* @returns {number}
|
|
439
|
+
*/
|
|
440
|
+
export function fidelityFromBytes(data1, data2) {
|
|
441
|
+
const ret = wasm.fidelityFromBytes(data1, data2);
|
|
442
|
+
if (ret[2]) {
|
|
443
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
444
|
+
}
|
|
445
|
+
return ret[0];
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Initialize the WASM module with better error messages
|
|
450
|
+
*/
|
|
451
|
+
export function init() {
|
|
452
|
+
wasm.init();
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Verify a QFT file's integrity from bytes.
|
|
457
|
+
* @param {Uint8Array} data
|
|
458
|
+
* @returns {boolean}
|
|
459
|
+
*/
|
|
460
|
+
export function verify(data) {
|
|
461
|
+
const ret = wasm.verify(data);
|
|
462
|
+
return ret !== 0;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Get library version.
|
|
467
|
+
* @returns {string}
|
|
468
|
+
*/
|
|
469
|
+
export function version() {
|
|
470
|
+
let deferred1_0;
|
|
471
|
+
let deferred1_1;
|
|
472
|
+
try {
|
|
473
|
+
const ret = wasm.version();
|
|
474
|
+
deferred1_0 = ret[0];
|
|
475
|
+
deferred1_1 = ret[1];
|
|
476
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
477
|
+
} finally {
|
|
478
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
function __wbg_get_imports() {
|
|
483
|
+
const import0 = {
|
|
484
|
+
__proto__: null,
|
|
485
|
+
__wbg_Error_8c4e43fe74559d73: function(arg0, arg1) {
|
|
486
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
487
|
+
return ret;
|
|
488
|
+
},
|
|
489
|
+
__wbg_String_8f0eb39a4a4c2f66: function(arg0, arg1) {
|
|
490
|
+
const ret = String(arg1);
|
|
491
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
492
|
+
const len1 = WASM_VECTOR_LEN;
|
|
493
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
494
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
495
|
+
},
|
|
496
|
+
__wbg___wbindgen_debug_string_0bc8482c6e3508ae: function(arg0, arg1) {
|
|
497
|
+
const ret = debugString(arg1);
|
|
498
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
499
|
+
const len1 = WASM_VECTOR_LEN;
|
|
500
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
501
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
502
|
+
},
|
|
503
|
+
__wbg___wbindgen_is_string_cd444516edc5b180: function(arg0) {
|
|
504
|
+
const ret = typeof(arg0) === 'string';
|
|
505
|
+
return ret;
|
|
506
|
+
},
|
|
507
|
+
__wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
|
|
508
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
509
|
+
},
|
|
510
|
+
__wbg_error_7534b8e9a36f1ab4: function(arg0, arg1) {
|
|
511
|
+
let deferred0_0;
|
|
512
|
+
let deferred0_1;
|
|
513
|
+
try {
|
|
514
|
+
deferred0_0 = arg0;
|
|
515
|
+
deferred0_1 = arg1;
|
|
516
|
+
console.error(getStringFromWasm0(arg0, arg1));
|
|
517
|
+
} finally {
|
|
518
|
+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
519
|
+
}
|
|
520
|
+
},
|
|
521
|
+
__wbg_length_32ed9a279acd054c: function(arg0) {
|
|
522
|
+
const ret = arg0.length;
|
|
523
|
+
return ret;
|
|
524
|
+
},
|
|
525
|
+
__wbg_length_f7386240689107f3: function(arg0) {
|
|
526
|
+
const ret = arg0.length;
|
|
527
|
+
return ret;
|
|
528
|
+
},
|
|
529
|
+
__wbg_new_361308b2356cecd0: function() {
|
|
530
|
+
const ret = new Object();
|
|
531
|
+
return ret;
|
|
532
|
+
},
|
|
533
|
+
__wbg_new_8a6f238a6ece86ea: function() {
|
|
534
|
+
const ret = new Error();
|
|
535
|
+
return ret;
|
|
536
|
+
},
|
|
537
|
+
__wbg_new_dca287b076112a51: function() {
|
|
538
|
+
const ret = new Map();
|
|
539
|
+
return ret;
|
|
540
|
+
},
|
|
541
|
+
__wbg_new_from_slice_38c66b2d6c31f4b7: function(arg0, arg1) {
|
|
542
|
+
const ret = new Float64Array(getArrayF64FromWasm0(arg0, arg1));
|
|
543
|
+
return ret;
|
|
544
|
+
},
|
|
545
|
+
__wbg_new_from_slice_a3d2629dc1826784: function(arg0, arg1) {
|
|
546
|
+
const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
|
|
547
|
+
return ret;
|
|
548
|
+
},
|
|
549
|
+
__wbg_prototypesetcall_aefe6319f589ab4b: function(arg0, arg1, arg2) {
|
|
550
|
+
Float64Array.prototype.set.call(getArrayF64FromWasm0(arg0, arg1), arg2);
|
|
551
|
+
},
|
|
552
|
+
__wbg_prototypesetcall_bdcdcc5842e4d77d: function(arg0, arg1, arg2) {
|
|
553
|
+
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
554
|
+
},
|
|
555
|
+
__wbg_set_1eb0999cf5d27fc8: function(arg0, arg1, arg2) {
|
|
556
|
+
const ret = arg0.set(arg1, arg2);
|
|
557
|
+
return ret;
|
|
558
|
+
},
|
|
559
|
+
__wbg_set_3f1d0b984ed272ed: function(arg0, arg1, arg2) {
|
|
560
|
+
arg0[arg1] = arg2;
|
|
561
|
+
},
|
|
562
|
+
__wbg_set_6cb8631f80447a67: function() { return handleError(function (arg0, arg1, arg2) {
|
|
563
|
+
const ret = Reflect.set(arg0, arg1, arg2);
|
|
564
|
+
return ret;
|
|
565
|
+
}, arguments); },
|
|
566
|
+
__wbg_stack_0ed75d68575b0f3c: function(arg0, arg1) {
|
|
567
|
+
const ret = arg1.stack;
|
|
568
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
569
|
+
const len1 = WASM_VECTOR_LEN;
|
|
570
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
571
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
572
|
+
},
|
|
573
|
+
__wbindgen_cast_0000000000000001: function(arg0) {
|
|
574
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
575
|
+
const ret = arg0;
|
|
576
|
+
return ret;
|
|
577
|
+
},
|
|
578
|
+
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
579
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
580
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
581
|
+
return ret;
|
|
582
|
+
},
|
|
583
|
+
__wbindgen_init_externref_table: function() {
|
|
584
|
+
const table = wasm.__wbindgen_externrefs;
|
|
585
|
+
const offset = table.grow(4);
|
|
586
|
+
table.set(0, undefined);
|
|
587
|
+
table.set(offset + 0, undefined);
|
|
588
|
+
table.set(offset + 1, null);
|
|
589
|
+
table.set(offset + 2, true);
|
|
590
|
+
table.set(offset + 3, false);
|
|
591
|
+
},
|
|
592
|
+
};
|
|
593
|
+
return {
|
|
594
|
+
__proto__: null,
|
|
595
|
+
"./qft_wasm_bg.js": import0,
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
const QftFileFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
600
|
+
? { register: () => {}, unregister: () => {} }
|
|
601
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_qftfile_free(ptr >>> 0, 1));
|
|
602
|
+
const StreamingConverterFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
603
|
+
? { register: () => {}, unregister: () => {} }
|
|
604
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_streamingconverter_free(ptr >>> 0, 1));
|
|
605
|
+
|
|
606
|
+
function addToExternrefTable0(obj) {
|
|
607
|
+
const idx = wasm.__externref_table_alloc();
|
|
608
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
609
|
+
return idx;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
function _assertClass(instance, klass) {
|
|
613
|
+
if (!(instance instanceof klass)) {
|
|
614
|
+
throw new Error(`expected instance of ${klass.name}`);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
function debugString(val) {
|
|
619
|
+
// primitive types
|
|
620
|
+
const type = typeof val;
|
|
621
|
+
if (type == 'number' || type == 'boolean' || val == null) {
|
|
622
|
+
return `${val}`;
|
|
623
|
+
}
|
|
624
|
+
if (type == 'string') {
|
|
625
|
+
return `"${val}"`;
|
|
626
|
+
}
|
|
627
|
+
if (type == 'symbol') {
|
|
628
|
+
const description = val.description;
|
|
629
|
+
if (description == null) {
|
|
630
|
+
return 'Symbol';
|
|
631
|
+
} else {
|
|
632
|
+
return `Symbol(${description})`;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
if (type == 'function') {
|
|
636
|
+
const name = val.name;
|
|
637
|
+
if (typeof name == 'string' && name.length > 0) {
|
|
638
|
+
return `Function(${name})`;
|
|
639
|
+
} else {
|
|
640
|
+
return 'Function';
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
// objects
|
|
644
|
+
if (Array.isArray(val)) {
|
|
645
|
+
const length = val.length;
|
|
646
|
+
let debug = '[';
|
|
647
|
+
if (length > 0) {
|
|
648
|
+
debug += debugString(val[0]);
|
|
649
|
+
}
|
|
650
|
+
for(let i = 1; i < length; i++) {
|
|
651
|
+
debug += ', ' + debugString(val[i]);
|
|
652
|
+
}
|
|
653
|
+
debug += ']';
|
|
654
|
+
return debug;
|
|
655
|
+
}
|
|
656
|
+
// Test for built-in
|
|
657
|
+
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
658
|
+
let className;
|
|
659
|
+
if (builtInMatches && builtInMatches.length > 1) {
|
|
660
|
+
className = builtInMatches[1];
|
|
661
|
+
} else {
|
|
662
|
+
// Failed to match the standard '[object ClassName]'
|
|
663
|
+
return toString.call(val);
|
|
664
|
+
}
|
|
665
|
+
if (className == 'Object') {
|
|
666
|
+
// we're a user defined class or Object
|
|
667
|
+
// JSON.stringify avoids problems with cycles, and is generally much
|
|
668
|
+
// easier than looping through ownProperties of `val`.
|
|
669
|
+
try {
|
|
670
|
+
return 'Object(' + JSON.stringify(val) + ')';
|
|
671
|
+
} catch (_) {
|
|
672
|
+
return 'Object';
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
// errors
|
|
676
|
+
if (val instanceof Error) {
|
|
677
|
+
return `${val.name}: ${val.message}\n${val.stack}`;
|
|
678
|
+
}
|
|
679
|
+
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
680
|
+
return className;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
function getArrayF64FromWasm0(ptr, len) {
|
|
684
|
+
ptr = ptr >>> 0;
|
|
685
|
+
return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
689
|
+
ptr = ptr >>> 0;
|
|
690
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
let cachedDataViewMemory0 = null;
|
|
694
|
+
function getDataViewMemory0() {
|
|
695
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
696
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
697
|
+
}
|
|
698
|
+
return cachedDataViewMemory0;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
let cachedFloat64ArrayMemory0 = null;
|
|
702
|
+
function getFloat64ArrayMemory0() {
|
|
703
|
+
if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
|
|
704
|
+
cachedFloat64ArrayMemory0 = new Float64Array(wasm.memory.buffer);
|
|
705
|
+
}
|
|
706
|
+
return cachedFloat64ArrayMemory0;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
function getStringFromWasm0(ptr, len) {
|
|
710
|
+
ptr = ptr >>> 0;
|
|
711
|
+
return decodeText(ptr, len);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
let cachedUint8ArrayMemory0 = null;
|
|
715
|
+
function getUint8ArrayMemory0() {
|
|
716
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
717
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
718
|
+
}
|
|
719
|
+
return cachedUint8ArrayMemory0;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
function handleError(f, args) {
|
|
723
|
+
try {
|
|
724
|
+
return f.apply(this, args);
|
|
725
|
+
} catch (e) {
|
|
726
|
+
const idx = addToExternrefTable0(e);
|
|
727
|
+
wasm.__wbindgen_exn_store(idx);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
function isLikeNone(x) {
|
|
732
|
+
return x === undefined || x === null;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
736
|
+
if (realloc === undefined) {
|
|
737
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
738
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
739
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
740
|
+
WASM_VECTOR_LEN = buf.length;
|
|
741
|
+
return ptr;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
let len = arg.length;
|
|
745
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
746
|
+
|
|
747
|
+
const mem = getUint8ArrayMemory0();
|
|
748
|
+
|
|
749
|
+
let offset = 0;
|
|
750
|
+
|
|
751
|
+
for (; offset < len; offset++) {
|
|
752
|
+
const code = arg.charCodeAt(offset);
|
|
753
|
+
if (code > 0x7F) break;
|
|
754
|
+
mem[ptr + offset] = code;
|
|
755
|
+
}
|
|
756
|
+
if (offset !== len) {
|
|
757
|
+
if (offset !== 0) {
|
|
758
|
+
arg = arg.slice(offset);
|
|
759
|
+
}
|
|
760
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
761
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
762
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
763
|
+
|
|
764
|
+
offset += ret.written;
|
|
765
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
WASM_VECTOR_LEN = offset;
|
|
769
|
+
return ptr;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
function takeFromExternrefTable0(idx) {
|
|
773
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
774
|
+
wasm.__externref_table_dealloc(idx);
|
|
775
|
+
return value;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
779
|
+
cachedTextDecoder.decode();
|
|
780
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
781
|
+
let numBytesDecoded = 0;
|
|
782
|
+
function decodeText(ptr, len) {
|
|
783
|
+
numBytesDecoded += len;
|
|
784
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
785
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
786
|
+
cachedTextDecoder.decode();
|
|
787
|
+
numBytesDecoded = len;
|
|
788
|
+
}
|
|
789
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
const cachedTextEncoder = new TextEncoder();
|
|
793
|
+
|
|
794
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
795
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
796
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
797
|
+
view.set(buf);
|
|
798
|
+
return {
|
|
799
|
+
read: arg.length,
|
|
800
|
+
written: buf.length
|
|
801
|
+
};
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
let WASM_VECTOR_LEN = 0;
|
|
806
|
+
|
|
807
|
+
let wasmModule, wasm;
|
|
808
|
+
function __wbg_finalize_init(instance, module) {
|
|
809
|
+
wasm = instance.exports;
|
|
810
|
+
wasmModule = module;
|
|
811
|
+
cachedDataViewMemory0 = null;
|
|
812
|
+
cachedFloat64ArrayMemory0 = null;
|
|
813
|
+
cachedUint8ArrayMemory0 = null;
|
|
814
|
+
wasm.__wbindgen_start();
|
|
815
|
+
return wasm;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
async function __wbg_load(module, imports) {
|
|
819
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
820
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
821
|
+
try {
|
|
822
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
823
|
+
} catch (e) {
|
|
824
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
825
|
+
|
|
826
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
827
|
+
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);
|
|
828
|
+
|
|
829
|
+
} else { throw e; }
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
const bytes = await module.arrayBuffer();
|
|
834
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
835
|
+
} else {
|
|
836
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
837
|
+
|
|
838
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
839
|
+
return { instance, module };
|
|
840
|
+
} else {
|
|
841
|
+
return instance;
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
function expectedResponseType(type) {
|
|
846
|
+
switch (type) {
|
|
847
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
848
|
+
}
|
|
849
|
+
return false;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
function initSync(module) {
|
|
854
|
+
if (wasm !== undefined) return wasm;
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
if (module !== undefined) {
|
|
858
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
859
|
+
({module} = module)
|
|
860
|
+
} else {
|
|
861
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
const imports = __wbg_get_imports();
|
|
866
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
867
|
+
module = new WebAssembly.Module(module);
|
|
868
|
+
}
|
|
869
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
870
|
+
return __wbg_finalize_init(instance, module);
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
async function __wbg_init(module_or_path) {
|
|
874
|
+
if (wasm !== undefined) return wasm;
|
|
875
|
+
|
|
876
|
+
|
|
877
|
+
if (module_or_path !== undefined) {
|
|
878
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
879
|
+
({module_or_path} = module_or_path)
|
|
880
|
+
} else {
|
|
881
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
if (module_or_path === undefined) {
|
|
886
|
+
module_or_path = new URL('qft_wasm_bg.wasm', import.meta.url);
|
|
887
|
+
}
|
|
888
|
+
const imports = __wbg_get_imports();
|
|
889
|
+
|
|
890
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
891
|
+
module_or_path = fetch(module_or_path);
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
895
|
+
|
|
896
|
+
return __wbg_finalize_init(instance, module);
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
export { initSync, __wbg_init as default };
|