tapewasm 0.2.0 → 0.3.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/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export {
3
3
  AotSampler,
4
4
  AdviResult,
5
5
  CompiledTape,
6
+ SampleResult,
6
7
  compileTape,
7
8
  tapewasmVersion,
8
9
  setAotExports,
package/index.js CHANGED
@@ -7,6 +7,7 @@ export {
7
7
  AotSampler,
8
8
  AdviResult,
9
9
  CompiledTape,
10
+ SampleResult,
10
11
  compileTape,
11
12
  tapewasmVersion,
12
13
  setAotExports,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tapewasm",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Compile an autodiff tape to a WebAssembly module and sample it with nuts-rs, in the browser.",
5
5
  "type": "module",
6
6
  "main": "./index.js",
package/pkg/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "tapewasm",
3
3
  "type": "module",
4
4
  "description": "Compile an autodiff tape to a wasm module and sample it with nuts-rs, in the browser. The wasm-bindgen API over tapewasm-codegen.",
5
- "version": "0.2.0",
5
+ "version": "0.3.0",
6
6
  "license": "MIT OR Apache-2.0",
7
7
  "repository": {
8
8
  "type": "git",
package/pkg/tapewasm.d.ts CHANGED
@@ -60,8 +60,13 @@ export class AotSampler {
60
60
  * spliced together: restarting Adam's moment estimates partway through
61
61
  * measurably converges to a worse optimum, so this is the only way to
62
62
  * watch a run progress without paying for that.
63
+ *
64
+ * `on_snapshot`, if given, is also called at each snapshot with the
65
+ * iteration, a copy of that `μ`, and the ELBO trace since the previous
66
+ * call — so a run inside a Worker can report as it goes rather than only
67
+ * once it returns.
63
68
  */
64
- advi(init: Float64Array, num_iters: number, mc_samples: number, learning_rate: number, seed: bigint, snapshot_every: number): AdviResult;
69
+ advi(init: Float64Array, num_iters: number, mc_samples: number, learning_rate: number, seed: bigint, snapshot_every: number, on_snapshot?: ((iter: number, mu: Float64Array, elbo: Float64Array) => void) | null): AdviResult;
65
70
  /**
66
71
  * `[log_prob, d/dparam...]`.
67
72
  */
@@ -78,10 +83,28 @@ export class AotSampler {
78
83
  * an empty array to go without.
79
84
  */
80
85
  constructor(n_params: number, scratch_init: Float64Array, layout_id: number, param_names: string[]);
86
+ /**
87
+ * [`sample`](Self::sample) with each draw's sampler statistics beside it —
88
+ * what ArviZ keeps as `sample_stats`. `chain` only labels the run: a
89
+ * different seed is what keeps two chains apart.
90
+ */
91
+ sampleWithStats(init: Float64Array, num_warmup: number, num_draws: number, seed: bigint, chain: number): SampleResult;
81
92
  /**
82
93
  * `num_warmup + num_draws` draws, row-major, `n_params` wide.
83
94
  */
84
95
  sample(init: Float64Array, num_warmup: number, num_draws: number, seed: bigint): Float64Array;
96
+ /**
97
+ * Estimate the diagonal metric from the gradients as well as the draws, as
98
+ * nuts-rs does by default. Off unless set, to match the reference
99
+ * posteriors; see [`nuts_settings`].
100
+ */
101
+ setGradBasedEstimate(on: boolean): void;
102
+ /**
103
+ * Aim warmup's step-size adaptation at this acceptance rate instead of
104
+ * nuts-rs's 0.8. Higher adapts a smaller step: fewer divergences on a hard
105
+ * geometry, more gradients per draw.
106
+ */
107
+ setTargetAccept(target: number): void;
85
108
  readonly nParams: number;
86
109
  }
87
110
 
@@ -102,6 +125,37 @@ export class CompiledTape {
102
125
  readonly wasm: Uint8Array;
103
126
  }
104
127
 
128
+ /**
129
+ * Draws and, beside each, the sampler's statistics — warmup first, as
130
+ * [`AotSampler::sample`] returns them.
131
+ */
132
+ export class SampleResult {
133
+ private constructor();
134
+ free(): void;
135
+ [Symbol.dispose](): void;
136
+ /**
137
+ * 1 where the draw's trajectory diverged.
138
+ */
139
+ readonly diverging: Uint8Array;
140
+ /**
141
+ * `num_warmup + num_draws` draws, row-major, `n_params` wide.
142
+ */
143
+ readonly draws: Float64Array;
144
+ /**
145
+ * The log density at each draw.
146
+ */
147
+ readonly lp: Float64Array;
148
+ /**
149
+ * Leapfrog steps the draw's trajectory took.
150
+ */
151
+ readonly numSteps: Uint32Array;
152
+ readonly stepSize: Float64Array;
153
+ /**
154
+ * 1 for the warmup draws.
155
+ */
156
+ readonly tuning: Uint8Array;
157
+ }
158
+
105
159
  /**
106
160
  * Release the bound module's exports. The next draw will throw.
107
161
  */
@@ -117,8 +171,15 @@ export function clearAotExports(): void;
117
171
  *
118
172
  * The format is not an artifact and carries no compatibility promise: a tape
119
173
  * is written and consumed inside one call.
174
+ *
175
+ * `reroll` says when a vectorised statement becomes a wasm loop: `"auto"`
176
+ * (the default, straight-line below a size threshold), `"always"` or
177
+ * `"never"`. Which is faster is an engine's preference, not the model's —
178
+ * on one real model straight-line was faster on V8 and slower on
179
+ * SpiderMonkey and JavaScriptCore — and `"always"` is also the smallest
180
+ * module, often by an order of magnitude.
120
181
  */
121
- export function compileTape(tape: string): CompiledTape;
182
+ export function compileTape(tape: string, reroll?: string | null): CompiledTape;
122
183
 
123
184
  /**
124
185
  * Forwards Rust panics to `console.error` with a message and backtrace rather
@@ -152,32 +213,43 @@ export interface InitOutput {
152
213
  readonly __wbg_adviresult_free: (a: number, b: number) => void;
153
214
  readonly __wbg_aotsampler_free: (a: number, b: number) => void;
154
215
  readonly __wbg_compiledtape_free: (a: number, b: number) => void;
216
+ readonly __wbg_sampleresult_free: (a: number, b: number) => void;
155
217
  readonly adviresult_elboTrace: (a: number) => [number, number];
156
218
  readonly adviresult_mu: (a: number) => [number, number];
157
219
  readonly adviresult_muSnapshots: (a: number) => [number, number];
158
220
  readonly adviresult_sigma: (a: number) => [number, number];
159
221
  readonly adviresult_snapshotIters: (a: number) => [number, number];
160
- readonly aotsampler_advi: (a: number, b: number, c: number, d: number, e: number, f: number, g: bigint, h: number) => [number, number, number];
222
+ readonly aotsampler_advi: (a: number, b: number, c: number, d: number, e: number, f: number, g: bigint, h: number, i: number) => [number, number, number];
161
223
  readonly aotsampler_logProbGrad: (a: number, b: number, c: number) => [number, number, number, number];
162
224
  readonly aotsampler_nParams: (a: number) => number;
163
225
  readonly aotsampler_new: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
164
226
  readonly aotsampler_sample: (a: number, b: number, c: number, d: number, e: number, f: bigint) => [number, number, number, number];
227
+ readonly aotsampler_sampleWithStats: (a: number, b: number, c: number, d: number, e: number, f: bigint, g: number) => [number, number, number];
228
+ readonly aotsampler_setGradBasedEstimate: (a: number, b: number) => void;
229
+ readonly aotsampler_setTargetAccept: (a: number, b: number) => [number, number];
165
230
  readonly clearAotExports: () => void;
166
- readonly compileTape: (a: number, b: number) => [number, number, number];
231
+ readonly compileTape: (a: number, b: number, c: number, d: number) => [number, number, number];
167
232
  readonly compiledtape_layoutId: (a: number) => number;
168
233
  readonly compiledtape_nParams: (a: number) => number;
169
234
  readonly compiledtape_scratchInit: (a: number) => [number, number];
170
235
  readonly compiledtape_wasm: (a: number) => [number, number];
171
236
  readonly init_panic_hook: () => void;
237
+ readonly sampleresult_diverging: (a: number) => [number, number];
238
+ readonly sampleresult_draws: (a: number) => [number, number];
239
+ readonly sampleresult_lp: (a: number) => [number, number];
240
+ readonly sampleresult_numSteps: (a: number) => [number, number];
241
+ readonly sampleresult_stepSize: (a: number) => [number, number];
242
+ readonly sampleresult_tuning: (a: number) => [number, number];
172
243
  readonly setAotExports: (a: any) => void;
173
244
  readonly sharedMemory: () => any;
174
245
  readonly tapewasmVersion: () => [number, number];
175
246
  readonly __wbindgen_malloc: (a: number, b: number) => number;
176
247
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
177
248
  readonly __wbindgen_free: (a: number, b: number, c: number) => void;
249
+ readonly __wbindgen_exn_store: (a: number) => void;
250
+ readonly __externref_table_alloc: () => number;
178
251
  readonly __wbindgen_externrefs: WebAssembly.Table;
179
252
  readonly __externref_table_dealloc: (a: number) => void;
180
- readonly __externref_table_alloc: () => number;
181
253
  readonly __wbindgen_start: () => void;
182
254
  }
183
255
 
package/pkg/tapewasm.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /* @ts-self-types="./tapewasm.d.ts" */
2
- import { aot_logp } from './snippets/tapewasm-3fbd96d1430b56d5/js/aot_bridge.js';
3
- import * as import1 from "./snippets/tapewasm-3fbd96d1430b56d5/js/aot_bridge.js"
4
- import * as import2 from "./snippets/tapewasm-3fbd96d1430b56d5/js/aot_bridge.js"
5
- import * as import3 from "./snippets/tapewasm-3fbd96d1430b56d5/js/aot_bridge.js"
6
- import * as import4 from "./snippets/tapewasm-3fbd96d1430b56d5/js/aot_bridge.js"
2
+ import { aot_logp } from './snippets/tapewasm-6c5813ce65cccbcf/js/aot_bridge.js';
3
+ import * as import1 from "./snippets/tapewasm-6c5813ce65cccbcf/js/aot_bridge.js"
4
+ import * as import2 from "./snippets/tapewasm-6c5813ce65cccbcf/js/aot_bridge.js"
5
+ import * as import3 from "./snippets/tapewasm-6c5813ce65cccbcf/js/aot_bridge.js"
6
+ import * as import4 from "./snippets/tapewasm-6c5813ce65cccbcf/js/aot_bridge.js"
7
7
 
8
8
 
9
9
  /**
@@ -121,18 +121,24 @@ export class AotSampler {
121
121
  * spliced together: restarting Adam's moment estimates partway through
122
122
  * measurably converges to a worse optimum, so this is the only way to
123
123
  * watch a run progress without paying for that.
124
+ *
125
+ * `on_snapshot`, if given, is also called at each snapshot with the
126
+ * iteration, a copy of that `μ`, and the ELBO trace since the previous
127
+ * call — so a run inside a Worker can report as it goes rather than only
128
+ * once it returns.
124
129
  * @param {Float64Array} init
125
130
  * @param {number} num_iters
126
131
  * @param {number} mc_samples
127
132
  * @param {number} learning_rate
128
133
  * @param {bigint} seed
129
134
  * @param {number} snapshot_every
135
+ * @param {((iter: number, mu: Float64Array, elbo: Float64Array) => void) | null} [on_snapshot]
130
136
  * @returns {AdviResult}
131
137
  */
132
- advi(init, num_iters, mc_samples, learning_rate, seed, snapshot_every) {
138
+ advi(init, num_iters, mc_samples, learning_rate, seed, snapshot_every, on_snapshot) {
133
139
  const ptr0 = passArrayF64ToWasm0(init, wasm.__wbindgen_malloc);
134
140
  const len0 = WASM_VECTOR_LEN;
135
- const ret = wasm.aotsampler_advi(this.__wbg_ptr, ptr0, len0, num_iters, mc_samples, learning_rate, seed, snapshot_every);
141
+ const ret = wasm.aotsampler_advi(this.__wbg_ptr, ptr0, len0, num_iters, mc_samples, learning_rate, seed, snapshot_every, isLikeNone(on_snapshot) ? 0 : addToExternrefTable0(on_snapshot));
136
142
  if (ret[2]) {
137
143
  throw takeFromExternrefTable0(ret[1]);
138
144
  }
@@ -189,6 +195,26 @@ export class AotSampler {
189
195
  AotSamplerFinalization.register(this, this.__wbg_ptr, this);
190
196
  return this;
191
197
  }
198
+ /**
199
+ * [`sample`](Self::sample) with each draw's sampler statistics beside it —
200
+ * what ArviZ keeps as `sample_stats`. `chain` only labels the run: a
201
+ * different seed is what keeps two chains apart.
202
+ * @param {Float64Array} init
203
+ * @param {number} num_warmup
204
+ * @param {number} num_draws
205
+ * @param {bigint} seed
206
+ * @param {number} chain
207
+ * @returns {SampleResult}
208
+ */
209
+ sampleWithStats(init, num_warmup, num_draws, seed, chain) {
210
+ const ptr0 = passArrayF64ToWasm0(init, wasm.__wbindgen_malloc);
211
+ const len0 = WASM_VECTOR_LEN;
212
+ const ret = wasm.aotsampler_sampleWithStats(this.__wbg_ptr, ptr0, len0, num_warmup, num_draws, seed, chain);
213
+ if (ret[2]) {
214
+ throw takeFromExternrefTable0(ret[1]);
215
+ }
216
+ return SampleResult.__wrap(ret[0]);
217
+ }
192
218
  /**
193
219
  * `num_warmup + num_draws` draws, row-major, `n_params` wide.
194
220
  * @param {Float64Array} init
@@ -208,6 +234,27 @@ export class AotSampler {
208
234
  wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
209
235
  return v2;
210
236
  }
237
+ /**
238
+ * Estimate the diagonal metric from the gradients as well as the draws, as
239
+ * nuts-rs does by default. Off unless set, to match the reference
240
+ * posteriors; see [`nuts_settings`].
241
+ * @param {boolean} on
242
+ */
243
+ setGradBasedEstimate(on) {
244
+ wasm.aotsampler_setGradBasedEstimate(this.__wbg_ptr, on);
245
+ }
246
+ /**
247
+ * Aim warmup's step-size adaptation at this acceptance rate instead of
248
+ * nuts-rs's 0.8. Higher adapts a smaller step: fewer divergences on a hard
249
+ * geometry, more gradients per draw.
250
+ * @param {number} target
251
+ */
252
+ setTargetAccept(target) {
253
+ const ret = wasm.aotsampler_setTargetAccept(this.__wbg_ptr, target);
254
+ if (ret[1]) {
255
+ throw takeFromExternrefTable0(ret[0]);
256
+ }
257
+ }
211
258
  }
212
259
  if (Symbol.dispose) AotSampler.prototype[Symbol.dispose] = AotSampler.prototype.free;
213
260
 
@@ -268,6 +315,89 @@ export class CompiledTape {
268
315
  }
269
316
  if (Symbol.dispose) CompiledTape.prototype[Symbol.dispose] = CompiledTape.prototype.free;
270
317
 
318
+ /**
319
+ * Draws and, beside each, the sampler's statistics — warmup first, as
320
+ * [`AotSampler::sample`] returns them.
321
+ */
322
+ export class SampleResult {
323
+ static __wrap(ptr) {
324
+ const obj = Object.create(SampleResult.prototype);
325
+ obj.__wbg_ptr = ptr;
326
+ SampleResultFinalization.register(obj, obj.__wbg_ptr, obj);
327
+ return obj;
328
+ }
329
+ __destroy_into_raw() {
330
+ const ptr = this.__wbg_ptr;
331
+ this.__wbg_ptr = 0;
332
+ SampleResultFinalization.unregister(this);
333
+ return ptr;
334
+ }
335
+ free() {
336
+ const ptr = this.__destroy_into_raw();
337
+ wasm.__wbg_sampleresult_free(ptr, 0);
338
+ }
339
+ /**
340
+ * 1 where the draw's trajectory diverged.
341
+ * @returns {Uint8Array}
342
+ */
343
+ get diverging() {
344
+ const ret = wasm.sampleresult_diverging(this.__wbg_ptr);
345
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
346
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
347
+ return v1;
348
+ }
349
+ /**
350
+ * `num_warmup + num_draws` draws, row-major, `n_params` wide.
351
+ * @returns {Float64Array}
352
+ */
353
+ get draws() {
354
+ const ret = wasm.sampleresult_draws(this.__wbg_ptr);
355
+ var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
356
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
357
+ return v1;
358
+ }
359
+ /**
360
+ * The log density at each draw.
361
+ * @returns {Float64Array}
362
+ */
363
+ get lp() {
364
+ const ret = wasm.sampleresult_lp(this.__wbg_ptr);
365
+ var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
366
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
367
+ return v1;
368
+ }
369
+ /**
370
+ * Leapfrog steps the draw's trajectory took.
371
+ * @returns {Uint32Array}
372
+ */
373
+ get numSteps() {
374
+ const ret = wasm.sampleresult_numSteps(this.__wbg_ptr);
375
+ var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
376
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
377
+ return v1;
378
+ }
379
+ /**
380
+ * @returns {Float64Array}
381
+ */
382
+ get stepSize() {
383
+ const ret = wasm.sampleresult_stepSize(this.__wbg_ptr);
384
+ var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
385
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
386
+ return v1;
387
+ }
388
+ /**
389
+ * 1 for the warmup draws.
390
+ * @returns {Uint8Array}
391
+ */
392
+ get tuning() {
393
+ const ret = wasm.sampleresult_tuning(this.__wbg_ptr);
394
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
395
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
396
+ return v1;
397
+ }
398
+ }
399
+ if (Symbol.dispose) SampleResult.prototype[Symbol.dispose] = SampleResult.prototype.free;
400
+
271
401
  /**
272
402
  * Release the bound module's exports. The next draw will throw.
273
403
  */
@@ -285,13 +415,23 @@ export function clearAotExports() {
285
415
  *
286
416
  * The format is not an artifact and carries no compatibility promise: a tape
287
417
  * is written and consumed inside one call.
418
+ *
419
+ * `reroll` says when a vectorised statement becomes a wasm loop: `"auto"`
420
+ * (the default, straight-line below a size threshold), `"always"` or
421
+ * `"never"`. Which is faster is an engine's preference, not the model's —
422
+ * on one real model straight-line was faster on V8 and slower on
423
+ * SpiderMonkey and JavaScriptCore — and `"always"` is also the smallest
424
+ * module, often by an order of magnitude.
288
425
  * @param {string} tape
426
+ * @param {string | null} [reroll]
289
427
  * @returns {CompiledTape}
290
428
  */
291
- export function compileTape(tape) {
429
+ export function compileTape(tape, reroll) {
292
430
  const ptr0 = passStringToWasm0(tape, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
293
431
  const len0 = WASM_VECTOR_LEN;
294
- const ret = wasm.compileTape(ptr0, len0);
432
+ var ptr1 = isLikeNone(reroll) ? 0 : passStringToWasm0(reroll, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
433
+ var len1 = WASM_VECTOR_LEN;
434
+ const ret = wasm.compileTape(ptr0, len0, ptr1, len1);
295
435
  if (ret[2]) {
296
436
  throw takeFromExternrefTable0(ret[1]);
297
437
  }
@@ -352,6 +492,13 @@ function __wbg_get_imports() {
352
492
  const ret = Error(getStringFromWasm0(arg0, arg1));
353
493
  return ret;
354
494
  },
495
+ __wbg___wbindgen_debug_string_0e68cf47c9cbd9b0: function(arg0, arg1) {
496
+ const ret = debugString(arg1);
497
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
498
+ const len1 = WASM_VECTOR_LEN;
499
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
500
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
501
+ },
355
502
  __wbg___wbindgen_memory_3f8442e22540244f: function() {
356
503
  const ret = wasm.memory;
357
504
  return ret;
@@ -367,10 +514,18 @@ function __wbg_get_imports() {
367
514
  __wbg___wbindgen_throw_5d9e815e6fdf150f: function(arg0, arg1) {
368
515
  throw new Error(getStringFromWasm0(arg0, arg1));
369
516
  },
370
- __wbg_aot_logp_897c94d09e163a67: function(arg0, arg1, arg2, arg3) {
517
+ __wbg_aot_logp_73e1e4a75800334a: function(arg0, arg1, arg2, arg3) {
371
518
  const ret = aot_logp(arg0 >>> 0, arg1 >>> 0, arg2 >>> 0, arg3 >>> 0);
372
519
  return ret;
373
520
  },
521
+ __wbg_call_5c65f3296b077120: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6) {
522
+ var v0 = getArrayF64FromWasm0(arg3, arg4).slice();
523
+ wasm.__wbindgen_free(arg3, arg4 * 8, 8);
524
+ var v1 = getArrayF64FromWasm0(arg5, arg6).slice();
525
+ wasm.__wbindgen_free(arg5, arg6 * 8, 8);
526
+ const ret = arg0.call(arg1, arg2, v0, v1);
527
+ return ret;
528
+ }, arguments); },
374
529
  __wbg_error_757e9472f8410341: function(arg0, arg1) {
375
530
  let deferred0_0;
376
531
  let deferred0_1;
@@ -406,10 +561,10 @@ function __wbg_get_imports() {
406
561
  return {
407
562
  __proto__: null,
408
563
  "./tapewasm_bg.js": import0,
409
- "./snippets/tapewasm-3fbd96d1430b56d5/js/aot_bridge.js": import1,
410
- "./snippets/tapewasm-3fbd96d1430b56d5/js/aot_bridge.js": import2,
411
- "./snippets/tapewasm-3fbd96d1430b56d5/js/aot_bridge.js": import3,
412
- "./snippets/tapewasm-3fbd96d1430b56d5/js/aot_bridge.js": import4,
564
+ "./snippets/tapewasm-6c5813ce65cccbcf/js/aot_bridge.js": import1,
565
+ "./snippets/tapewasm-6c5813ce65cccbcf/js/aot_bridge.js": import2,
566
+ "./snippets/tapewasm-6c5813ce65cccbcf/js/aot_bridge.js": import3,
567
+ "./snippets/tapewasm-6c5813ce65cccbcf/js/aot_bridge.js": import4,
413
568
  };
414
569
  }
415
570
 
@@ -422,6 +577,9 @@ const AotSamplerFinalization = (typeof FinalizationRegistry === 'undefined')
422
577
  const CompiledTapeFinalization = (typeof FinalizationRegistry === 'undefined')
423
578
  ? { register: () => {}, unregister: () => {} }
424
579
  : new FinalizationRegistry(ptr => wasm.__wbg_compiledtape_free(ptr, 1));
580
+ const SampleResultFinalization = (typeof FinalizationRegistry === 'undefined')
581
+ ? { register: () => {}, unregister: () => {} }
582
+ : new FinalizationRegistry(ptr => wasm.__wbg_sampleresult_free(ptr, 1));
425
583
 
426
584
  function addToExternrefTable0(obj) {
427
585
  const idx = wasm.__externref_table_alloc();
@@ -429,11 +587,81 @@ function addToExternrefTable0(obj) {
429
587
  return idx;
430
588
  }
431
589
 
590
+ function debugString(val) {
591
+ // primitive types
592
+ const type = typeof val;
593
+ if (type == 'number' || type == 'boolean' || val == null) {
594
+ return `${val}`;
595
+ }
596
+ if (type == 'string') {
597
+ return `"${val}"`;
598
+ }
599
+ if (type == 'symbol') {
600
+ const description = val.description;
601
+ if (description == null) {
602
+ return 'Symbol';
603
+ } else {
604
+ return `Symbol(${description})`;
605
+ }
606
+ }
607
+ if (type == 'function') {
608
+ const name = val.name;
609
+ if (typeof name == 'string' && name.length > 0) {
610
+ return `Function(${name})`;
611
+ } else {
612
+ return 'Function';
613
+ }
614
+ }
615
+ // objects
616
+ if (Array.isArray(val)) {
617
+ const length = val.length;
618
+ let debug = '[';
619
+ if (length > 0) {
620
+ debug += debugString(val[0]);
621
+ }
622
+ for(let i = 1; i < length; i++) {
623
+ debug += ', ' + debugString(val[i]);
624
+ }
625
+ debug += ']';
626
+ return debug;
627
+ }
628
+ // Test for built-in
629
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
630
+ let className;
631
+ if (builtInMatches && builtInMatches.length > 1) {
632
+ className = builtInMatches[1];
633
+ } else {
634
+ // Failed to match the standard '[object ClassName]'
635
+ return toString.call(val);
636
+ }
637
+ if (className == 'Object') {
638
+ // we're a user defined class or Object
639
+ // JSON.stringify avoids problems with cycles, and is generally much
640
+ // easier than looping through ownProperties of `val`.
641
+ try {
642
+ return 'Object(' + JSON.stringify(val) + ')';
643
+ } catch (_) {
644
+ return 'Object';
645
+ }
646
+ }
647
+ // errors
648
+ if (val instanceof Error) {
649
+ return `${val.name}: ${val.message}\n${val.stack}`;
650
+ }
651
+ // TODO we could test for more things here, like `Set`s and `Map`s.
652
+ return className;
653
+ }
654
+
432
655
  function getArrayF64FromWasm0(ptr, len) {
433
656
  ptr = ptr >>> 0;
434
657
  return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
435
658
  }
436
659
 
660
+ function getArrayU32FromWasm0(ptr, len) {
661
+ ptr = ptr >>> 0;
662
+ return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
663
+ }
664
+
437
665
  function getArrayU8FromWasm0(ptr, len) {
438
666
  ptr = ptr >>> 0;
439
667
  return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
@@ -459,6 +687,14 @@ function getStringFromWasm0(ptr, len) {
459
687
  return decodeText(ptr >>> 0, len);
460
688
  }
461
689
 
690
+ let cachedUint32ArrayMemory0 = null;
691
+ function getUint32ArrayMemory0() {
692
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
693
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
694
+ }
695
+ return cachedUint32ArrayMemory0;
696
+ }
697
+
462
698
  let cachedUint8ArrayMemory0 = null;
463
699
  function getUint8ArrayMemory0() {
464
700
  if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
@@ -467,6 +703,15 @@ function getUint8ArrayMemory0() {
467
703
  return cachedUint8ArrayMemory0;
468
704
  }
469
705
 
706
+ function handleError(f, args) {
707
+ try {
708
+ return f.apply(this, args);
709
+ } catch (e) {
710
+ const idx = addToExternrefTable0(e);
711
+ wasm.__wbindgen_exn_store(idx);
712
+ }
713
+ }
714
+
470
715
  function isLikeNone(x) {
471
716
  return x === undefined || x === null;
472
717
  }
@@ -567,6 +812,7 @@ function __wbg_finalize_init(instance, module) {
567
812
  wasmModule = module;
568
813
  cachedDataViewMemory0 = null;
569
814
  cachedFloat64ArrayMemory0 = null;
815
+ cachedUint32ArrayMemory0 = null;
570
816
  cachedUint8ArrayMemory0 = null;
571
817
  wasm.__wbindgen_start();
572
818
  return wasm;
Binary file
@@ -4,30 +4,41 @@ export const memory: WebAssembly.Memory;
4
4
  export const __wbg_adviresult_free: (a: number, b: number) => void;
5
5
  export const __wbg_aotsampler_free: (a: number, b: number) => void;
6
6
  export const __wbg_compiledtape_free: (a: number, b: number) => void;
7
+ export const __wbg_sampleresult_free: (a: number, b: number) => void;
7
8
  export const adviresult_elboTrace: (a: number) => [number, number];
8
9
  export const adviresult_mu: (a: number) => [number, number];
9
10
  export const adviresult_muSnapshots: (a: number) => [number, number];
10
11
  export const adviresult_sigma: (a: number) => [number, number];
11
12
  export const adviresult_snapshotIters: (a: number) => [number, number];
12
- export const aotsampler_advi: (a: number, b: number, c: number, d: number, e: number, f: number, g: bigint, h: number) => [number, number, number];
13
+ export const aotsampler_advi: (a: number, b: number, c: number, d: number, e: number, f: number, g: bigint, h: number, i: number) => [number, number, number];
13
14
  export const aotsampler_logProbGrad: (a: number, b: number, c: number) => [number, number, number, number];
14
15
  export const aotsampler_nParams: (a: number) => number;
15
16
  export const aotsampler_new: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
16
17
  export const aotsampler_sample: (a: number, b: number, c: number, d: number, e: number, f: bigint) => [number, number, number, number];
18
+ export const aotsampler_sampleWithStats: (a: number, b: number, c: number, d: number, e: number, f: bigint, g: number) => [number, number, number];
19
+ export const aotsampler_setGradBasedEstimate: (a: number, b: number) => void;
20
+ export const aotsampler_setTargetAccept: (a: number, b: number) => [number, number];
17
21
  export const clearAotExports: () => void;
18
- export const compileTape: (a: number, b: number) => [number, number, number];
22
+ export const compileTape: (a: number, b: number, c: number, d: number) => [number, number, number];
19
23
  export const compiledtape_layoutId: (a: number) => number;
20
24
  export const compiledtape_nParams: (a: number) => number;
21
25
  export const compiledtape_scratchInit: (a: number) => [number, number];
22
26
  export const compiledtape_wasm: (a: number) => [number, number];
23
27
  export const init_panic_hook: () => void;
28
+ export const sampleresult_diverging: (a: number) => [number, number];
29
+ export const sampleresult_draws: (a: number) => [number, number];
30
+ export const sampleresult_lp: (a: number) => [number, number];
31
+ export const sampleresult_numSteps: (a: number) => [number, number];
32
+ export const sampleresult_stepSize: (a: number) => [number, number];
33
+ export const sampleresult_tuning: (a: number) => [number, number];
24
34
  export const setAotExports: (a: any) => void;
25
35
  export const sharedMemory: () => any;
26
36
  export const tapewasmVersion: () => [number, number];
27
37
  export const __wbindgen_malloc: (a: number, b: number) => number;
28
38
  export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
29
39
  export const __wbindgen_free: (a: number, b: number, c: number) => void;
40
+ export const __wbindgen_exn_store: (a: number) => void;
41
+ export const __externref_table_alloc: () => number;
30
42
  export const __wbindgen_externrefs: WebAssembly.Table;
31
43
  export const __externref_table_dealloc: (a: number) => void;
32
- export const __externref_table_alloc: () => number;
33
44
  export const __wbindgen_start: () => void;