tapewasm 0.2.0 → 0.3.1
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 +28 -0
- package/index.js +2 -0
- package/package.json +1 -1
- package/pkg/package.json +1 -1
- package/pkg/tapewasm.d.ts +87 -5
- package/pkg/tapewasm.js +270 -14
- package/pkg/tapewasm_bg.wasm +0 -0
- package/pkg/tapewasm_bg.wasm.d.ts +14 -3
- /package/pkg/snippets/{tapewasm-3fbd96d1430b56d5 → tapewasm-cbf82a3d7bc31b1b}/js/aot_bridge.js +0 -0
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,
|
|
@@ -10,3 +11,30 @@ export {
|
|
|
10
11
|
sharedMemory,
|
|
11
12
|
} from "./pkg/tapewasm.js";
|
|
12
13
|
export { default } from "./pkg/tapewasm.js";
|
|
14
|
+
|
|
15
|
+
/** What `"auto"` uses: right for SpiderMonkey and JavaScriptCore. */
|
|
16
|
+
export const RE_ROLL_ABOVE: number;
|
|
17
|
+
/** For an engine that prefers straight-line, as V8 does. */
|
|
18
|
+
export const V8_RE_ROLL_ABOVE: number;
|
|
19
|
+
|
|
20
|
+
export interface Calibration {
|
|
21
|
+
/** Threshold to pass to `compileTape`. */
|
|
22
|
+
above: number;
|
|
23
|
+
/** False when the measurement could not run; `above` is the built-in value. */
|
|
24
|
+
measured: boolean;
|
|
25
|
+
prefersStraight?: boolean;
|
|
26
|
+
straightMs?: number;
|
|
27
|
+
loopedMs?: number;
|
|
28
|
+
error?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Measure which shape this engine prefers and return a threshold for
|
|
33
|
+
* `compileTape`'s `reroll` argument. Call after `init()`. Cached; pass
|
|
34
|
+
* `{ force: true }` to measure again. Never throws — on failure it returns
|
|
35
|
+
* the built-in threshold.
|
|
36
|
+
*/
|
|
37
|
+
export function calibrateReroll(options?: { force?: boolean; rounds?: number }): Promise<number>;
|
|
38
|
+
|
|
39
|
+
/** What the last `calibrateReroll` measured, or `null` before the first call. */
|
|
40
|
+
export function lastCalibration(): Calibration | null;
|
package/index.js
CHANGED
|
@@ -7,10 +7,12 @@ export {
|
|
|
7
7
|
AotSampler,
|
|
8
8
|
AdviResult,
|
|
9
9
|
CompiledTape,
|
|
10
|
+
SampleResult,
|
|
10
11
|
compileTape,
|
|
11
12
|
tapewasmVersion,
|
|
12
13
|
setAotExports,
|
|
13
14
|
clearAotExports,
|
|
14
15
|
sharedMemory,
|
|
15
16
|
} from "./pkg/tapewasm.js";
|
|
17
|
+
export { calibrateReroll, lastCalibration, RE_ROLL_ABOVE, V8_RE_ROLL_ABOVE } from "./calibrate.js";
|
|
16
18
|
export default init;
|
package/package.json
CHANGED
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.
|
|
5
|
+
"version": "0.3.1",
|
|
6
6
|
"license": "MIT OR Apache-2.0",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
package/pkg/tapewasm.d.ts
CHANGED
|
@@ -60,10 +60,19 @@ 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...]`.
|
|
72
|
+
*
|
|
73
|
+
* The evaluator behind it is built on the first call and reused, so
|
|
74
|
+
* calling this in a row costs one `scratch_init` copy rather than one per
|
|
75
|
+
* call — the same evaluator `sample` and `advi` keep for a whole run.
|
|
67
76
|
*/
|
|
68
77
|
logProbGrad(params: Float64Array): Float64Array;
|
|
69
78
|
/**
|
|
@@ -78,10 +87,28 @@ export class AotSampler {
|
|
|
78
87
|
* an empty array to go without.
|
|
79
88
|
*/
|
|
80
89
|
constructor(n_params: number, scratch_init: Float64Array, layout_id: number, param_names: string[]);
|
|
90
|
+
/**
|
|
91
|
+
* [`sample`](Self::sample) with each draw's sampler statistics beside it —
|
|
92
|
+
* what ArviZ keeps as `sample_stats`. `chain` only labels the run: a
|
|
93
|
+
* different seed is what keeps two chains apart.
|
|
94
|
+
*/
|
|
95
|
+
sampleWithStats(init: Float64Array, num_warmup: number, num_draws: number, seed: bigint, chain: number): SampleResult;
|
|
81
96
|
/**
|
|
82
97
|
* `num_warmup + num_draws` draws, row-major, `n_params` wide.
|
|
83
98
|
*/
|
|
84
99
|
sample(init: Float64Array, num_warmup: number, num_draws: number, seed: bigint): Float64Array;
|
|
100
|
+
/**
|
|
101
|
+
* Estimate the diagonal metric from the gradients as well as the draws, as
|
|
102
|
+
* nuts-rs does by default. Off unless set, to match the reference
|
|
103
|
+
* posteriors; see [`nuts_settings`].
|
|
104
|
+
*/
|
|
105
|
+
setGradBasedEstimate(on: boolean): void;
|
|
106
|
+
/**
|
|
107
|
+
* Aim warmup's step-size adaptation at this acceptance rate instead of
|
|
108
|
+
* nuts-rs's 0.8. Higher adapts a smaller step: fewer divergences on a hard
|
|
109
|
+
* geometry, more gradients per draw.
|
|
110
|
+
*/
|
|
111
|
+
setTargetAccept(target: number): void;
|
|
85
112
|
readonly nParams: number;
|
|
86
113
|
}
|
|
87
114
|
|
|
@@ -102,6 +129,37 @@ export class CompiledTape {
|
|
|
102
129
|
readonly wasm: Uint8Array;
|
|
103
130
|
}
|
|
104
131
|
|
|
132
|
+
/**
|
|
133
|
+
* Draws and, beside each, the sampler's statistics — warmup first, as
|
|
134
|
+
* [`AotSampler::sample`] returns them.
|
|
135
|
+
*/
|
|
136
|
+
export class SampleResult {
|
|
137
|
+
private constructor();
|
|
138
|
+
free(): void;
|
|
139
|
+
[Symbol.dispose](): void;
|
|
140
|
+
/**
|
|
141
|
+
* 1 where the draw's trajectory diverged.
|
|
142
|
+
*/
|
|
143
|
+
readonly diverging: Uint8Array;
|
|
144
|
+
/**
|
|
145
|
+
* `num_warmup + num_draws` draws, row-major, `n_params` wide.
|
|
146
|
+
*/
|
|
147
|
+
readonly draws: Float64Array;
|
|
148
|
+
/**
|
|
149
|
+
* The log density at each draw.
|
|
150
|
+
*/
|
|
151
|
+
readonly lp: Float64Array;
|
|
152
|
+
/**
|
|
153
|
+
* Leapfrog steps the draw's trajectory took.
|
|
154
|
+
*/
|
|
155
|
+
readonly numSteps: Uint32Array;
|
|
156
|
+
readonly stepSize: Float64Array;
|
|
157
|
+
/**
|
|
158
|
+
* 1 for the warmup draws.
|
|
159
|
+
*/
|
|
160
|
+
readonly tuning: Uint8Array;
|
|
161
|
+
}
|
|
162
|
+
|
|
105
163
|
/**
|
|
106
164
|
* Release the bound module's exports. The next draw will throw.
|
|
107
165
|
*/
|
|
@@ -117,8 +175,21 @@ export function clearAotExports(): void;
|
|
|
117
175
|
*
|
|
118
176
|
* The format is not an artifact and carries no compatibility promise: a tape
|
|
119
177
|
* is written and consumed inside one call.
|
|
178
|
+
*
|
|
179
|
+
* `reroll` says when a vectorised statement becomes a wasm loop: `"auto"`
|
|
180
|
+
* (the default, straight-line below a size threshold), `"always"`, `"never"`,
|
|
181
|
+
* or a node count to re-roll past, written as a number.
|
|
182
|
+
*
|
|
183
|
+
* **Which is faster is an engine's preference, not the model's.** Measured
|
|
184
|
+
* across three engines, straight-line and re-rolled cross over between 8,026
|
|
185
|
+
* and 24,564 nodes in V8 and around 2,000 in SpiderMonkey and JavaScriptCore
|
|
186
|
+
* — an order of magnitude apart, so no single threshold serves all three. `"auto"` takes the
|
|
187
|
+
* lower one: near-optimal for two of the three, and up to 7.6x off on V8 for
|
|
188
|
+
* a trace between them. A caller that knows its engine passes the number.
|
|
189
|
+
*
|
|
190
|
+
* `"always"` is also the smallest module, often by an order of magnitude.
|
|
120
191
|
*/
|
|
121
|
-
export function compileTape(tape: string): CompiledTape;
|
|
192
|
+
export function compileTape(tape: string, reroll?: string | null): CompiledTape;
|
|
122
193
|
|
|
123
194
|
/**
|
|
124
195
|
* Forwards Rust panics to `console.error` with a message and backtrace rather
|
|
@@ -152,32 +223,43 @@ export interface InitOutput {
|
|
|
152
223
|
readonly __wbg_adviresult_free: (a: number, b: number) => void;
|
|
153
224
|
readonly __wbg_aotsampler_free: (a: number, b: number) => void;
|
|
154
225
|
readonly __wbg_compiledtape_free: (a: number, b: number) => void;
|
|
226
|
+
readonly __wbg_sampleresult_free: (a: number, b: number) => void;
|
|
155
227
|
readonly adviresult_elboTrace: (a: number) => [number, number];
|
|
156
228
|
readonly adviresult_mu: (a: number) => [number, number];
|
|
157
229
|
readonly adviresult_muSnapshots: (a: number) => [number, number];
|
|
158
230
|
readonly adviresult_sigma: (a: number) => [number, number];
|
|
159
231
|
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];
|
|
232
|
+
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
233
|
readonly aotsampler_logProbGrad: (a: number, b: number, c: number) => [number, number, number, number];
|
|
162
234
|
readonly aotsampler_nParams: (a: number) => number;
|
|
163
235
|
readonly aotsampler_new: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
|
|
164
236
|
readonly aotsampler_sample: (a: number, b: number, c: number, d: number, e: number, f: bigint) => [number, number, number, number];
|
|
237
|
+
readonly aotsampler_sampleWithStats: (a: number, b: number, c: number, d: number, e: number, f: bigint, g: number) => [number, number, number];
|
|
238
|
+
readonly aotsampler_setGradBasedEstimate: (a: number, b: number) => void;
|
|
239
|
+
readonly aotsampler_setTargetAccept: (a: number, b: number) => [number, number];
|
|
165
240
|
readonly clearAotExports: () => void;
|
|
166
|
-
readonly compileTape: (a: number, b: number) => [number, number, number];
|
|
241
|
+
readonly compileTape: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
167
242
|
readonly compiledtape_layoutId: (a: number) => number;
|
|
168
243
|
readonly compiledtape_nParams: (a: number) => number;
|
|
169
244
|
readonly compiledtape_scratchInit: (a: number) => [number, number];
|
|
170
245
|
readonly compiledtape_wasm: (a: number) => [number, number];
|
|
171
246
|
readonly init_panic_hook: () => void;
|
|
247
|
+
readonly sampleresult_diverging: (a: number) => [number, number];
|
|
248
|
+
readonly sampleresult_draws: (a: number) => [number, number];
|
|
249
|
+
readonly sampleresult_lp: (a: number) => [number, number];
|
|
250
|
+
readonly sampleresult_numSteps: (a: number) => [number, number];
|
|
251
|
+
readonly sampleresult_stepSize: (a: number) => [number, number];
|
|
252
|
+
readonly sampleresult_tuning: (a: number) => [number, number];
|
|
172
253
|
readonly setAotExports: (a: any) => void;
|
|
173
254
|
readonly sharedMemory: () => any;
|
|
174
255
|
readonly tapewasmVersion: () => [number, number];
|
|
175
256
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
176
257
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
177
258
|
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
259
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
260
|
+
readonly __externref_table_alloc: () => number;
|
|
178
261
|
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
179
262
|
readonly __externref_table_dealloc: (a: number) => void;
|
|
180
|
-
readonly __externref_table_alloc: () => number;
|
|
181
263
|
readonly __wbindgen_start: () => void;
|
|
182
264
|
}
|
|
183
265
|
|
package/pkg/tapewasm.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/* @ts-self-types="./tapewasm.d.ts" */
|
|
2
|
-
import { aot_logp } from './snippets/tapewasm-
|
|
3
|
-
import * as import1 from "./snippets/tapewasm-
|
|
4
|
-
import * as import2 from "./snippets/tapewasm-
|
|
5
|
-
import * as import3 from "./snippets/tapewasm-
|
|
6
|
-
import * as import4 from "./snippets/tapewasm-
|
|
2
|
+
import { aot_logp } from './snippets/tapewasm-cbf82a3d7bc31b1b/js/aot_bridge.js';
|
|
3
|
+
import * as import1 from "./snippets/tapewasm-cbf82a3d7bc31b1b/js/aot_bridge.js"
|
|
4
|
+
import * as import2 from "./snippets/tapewasm-cbf82a3d7bc31b1b/js/aot_bridge.js"
|
|
5
|
+
import * as import3 from "./snippets/tapewasm-cbf82a3d7bc31b1b/js/aot_bridge.js"
|
|
6
|
+
import * as import4 from "./snippets/tapewasm-cbf82a3d7bc31b1b/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
|
}
|
|
@@ -140,6 +146,10 @@ export class AotSampler {
|
|
|
140
146
|
}
|
|
141
147
|
/**
|
|
142
148
|
* `[log_prob, d/dparam...]`.
|
|
149
|
+
*
|
|
150
|
+
* The evaluator behind it is built on the first call and reused, so
|
|
151
|
+
* calling this in a row costs one `scratch_init` copy rather than one per
|
|
152
|
+
* call — the same evaluator `sample` and `advi` keep for a whole run.
|
|
143
153
|
* @param {Float64Array} params
|
|
144
154
|
* @returns {Float64Array}
|
|
145
155
|
*/
|
|
@@ -189,6 +199,26 @@ export class AotSampler {
|
|
|
189
199
|
AotSamplerFinalization.register(this, this.__wbg_ptr, this);
|
|
190
200
|
return this;
|
|
191
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* [`sample`](Self::sample) with each draw's sampler statistics beside it —
|
|
204
|
+
* what ArviZ keeps as `sample_stats`. `chain` only labels the run: a
|
|
205
|
+
* different seed is what keeps two chains apart.
|
|
206
|
+
* @param {Float64Array} init
|
|
207
|
+
* @param {number} num_warmup
|
|
208
|
+
* @param {number} num_draws
|
|
209
|
+
* @param {bigint} seed
|
|
210
|
+
* @param {number} chain
|
|
211
|
+
* @returns {SampleResult}
|
|
212
|
+
*/
|
|
213
|
+
sampleWithStats(init, num_warmup, num_draws, seed, chain) {
|
|
214
|
+
const ptr0 = passArrayF64ToWasm0(init, wasm.__wbindgen_malloc);
|
|
215
|
+
const len0 = WASM_VECTOR_LEN;
|
|
216
|
+
const ret = wasm.aotsampler_sampleWithStats(this.__wbg_ptr, ptr0, len0, num_warmup, num_draws, seed, chain);
|
|
217
|
+
if (ret[2]) {
|
|
218
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
219
|
+
}
|
|
220
|
+
return SampleResult.__wrap(ret[0]);
|
|
221
|
+
}
|
|
192
222
|
/**
|
|
193
223
|
* `num_warmup + num_draws` draws, row-major, `n_params` wide.
|
|
194
224
|
* @param {Float64Array} init
|
|
@@ -208,6 +238,27 @@ export class AotSampler {
|
|
|
208
238
|
wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
|
|
209
239
|
return v2;
|
|
210
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* Estimate the diagonal metric from the gradients as well as the draws, as
|
|
243
|
+
* nuts-rs does by default. Off unless set, to match the reference
|
|
244
|
+
* posteriors; see [`nuts_settings`].
|
|
245
|
+
* @param {boolean} on
|
|
246
|
+
*/
|
|
247
|
+
setGradBasedEstimate(on) {
|
|
248
|
+
wasm.aotsampler_setGradBasedEstimate(this.__wbg_ptr, on);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Aim warmup's step-size adaptation at this acceptance rate instead of
|
|
252
|
+
* nuts-rs's 0.8. Higher adapts a smaller step: fewer divergences on a hard
|
|
253
|
+
* geometry, more gradients per draw.
|
|
254
|
+
* @param {number} target
|
|
255
|
+
*/
|
|
256
|
+
setTargetAccept(target) {
|
|
257
|
+
const ret = wasm.aotsampler_setTargetAccept(this.__wbg_ptr, target);
|
|
258
|
+
if (ret[1]) {
|
|
259
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
211
262
|
}
|
|
212
263
|
if (Symbol.dispose) AotSampler.prototype[Symbol.dispose] = AotSampler.prototype.free;
|
|
213
264
|
|
|
@@ -268,6 +319,89 @@ export class CompiledTape {
|
|
|
268
319
|
}
|
|
269
320
|
if (Symbol.dispose) CompiledTape.prototype[Symbol.dispose] = CompiledTape.prototype.free;
|
|
270
321
|
|
|
322
|
+
/**
|
|
323
|
+
* Draws and, beside each, the sampler's statistics — warmup first, as
|
|
324
|
+
* [`AotSampler::sample`] returns them.
|
|
325
|
+
*/
|
|
326
|
+
export class SampleResult {
|
|
327
|
+
static __wrap(ptr) {
|
|
328
|
+
const obj = Object.create(SampleResult.prototype);
|
|
329
|
+
obj.__wbg_ptr = ptr;
|
|
330
|
+
SampleResultFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
331
|
+
return obj;
|
|
332
|
+
}
|
|
333
|
+
__destroy_into_raw() {
|
|
334
|
+
const ptr = this.__wbg_ptr;
|
|
335
|
+
this.__wbg_ptr = 0;
|
|
336
|
+
SampleResultFinalization.unregister(this);
|
|
337
|
+
return ptr;
|
|
338
|
+
}
|
|
339
|
+
free() {
|
|
340
|
+
const ptr = this.__destroy_into_raw();
|
|
341
|
+
wasm.__wbg_sampleresult_free(ptr, 0);
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* 1 where the draw's trajectory diverged.
|
|
345
|
+
* @returns {Uint8Array}
|
|
346
|
+
*/
|
|
347
|
+
get diverging() {
|
|
348
|
+
const ret = wasm.sampleresult_diverging(this.__wbg_ptr);
|
|
349
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
350
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
351
|
+
return v1;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* `num_warmup + num_draws` draws, row-major, `n_params` wide.
|
|
355
|
+
* @returns {Float64Array}
|
|
356
|
+
*/
|
|
357
|
+
get draws() {
|
|
358
|
+
const ret = wasm.sampleresult_draws(this.__wbg_ptr);
|
|
359
|
+
var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
|
|
360
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
|
|
361
|
+
return v1;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* The log density at each draw.
|
|
365
|
+
* @returns {Float64Array}
|
|
366
|
+
*/
|
|
367
|
+
get lp() {
|
|
368
|
+
const ret = wasm.sampleresult_lp(this.__wbg_ptr);
|
|
369
|
+
var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
|
|
370
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
|
|
371
|
+
return v1;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Leapfrog steps the draw's trajectory took.
|
|
375
|
+
* @returns {Uint32Array}
|
|
376
|
+
*/
|
|
377
|
+
get numSteps() {
|
|
378
|
+
const ret = wasm.sampleresult_numSteps(this.__wbg_ptr);
|
|
379
|
+
var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
|
|
380
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
381
|
+
return v1;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* @returns {Float64Array}
|
|
385
|
+
*/
|
|
386
|
+
get stepSize() {
|
|
387
|
+
const ret = wasm.sampleresult_stepSize(this.__wbg_ptr);
|
|
388
|
+
var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
|
|
389
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
|
|
390
|
+
return v1;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* 1 for the warmup draws.
|
|
394
|
+
* @returns {Uint8Array}
|
|
395
|
+
*/
|
|
396
|
+
get tuning() {
|
|
397
|
+
const ret = wasm.sampleresult_tuning(this.__wbg_ptr);
|
|
398
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
399
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
400
|
+
return v1;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
if (Symbol.dispose) SampleResult.prototype[Symbol.dispose] = SampleResult.prototype.free;
|
|
404
|
+
|
|
271
405
|
/**
|
|
272
406
|
* Release the bound module's exports. The next draw will throw.
|
|
273
407
|
*/
|
|
@@ -285,13 +419,29 @@ export function clearAotExports() {
|
|
|
285
419
|
*
|
|
286
420
|
* The format is not an artifact and carries no compatibility promise: a tape
|
|
287
421
|
* is written and consumed inside one call.
|
|
422
|
+
*
|
|
423
|
+
* `reroll` says when a vectorised statement becomes a wasm loop: `"auto"`
|
|
424
|
+
* (the default, straight-line below a size threshold), `"always"`, `"never"`,
|
|
425
|
+
* or a node count to re-roll past, written as a number.
|
|
426
|
+
*
|
|
427
|
+
* **Which is faster is an engine's preference, not the model's.** Measured
|
|
428
|
+
* across three engines, straight-line and re-rolled cross over between 8,026
|
|
429
|
+
* and 24,564 nodes in V8 and around 2,000 in SpiderMonkey and JavaScriptCore
|
|
430
|
+
* — an order of magnitude apart, so no single threshold serves all three. `"auto"` takes the
|
|
431
|
+
* lower one: near-optimal for two of the three, and up to 7.6x off on V8 for
|
|
432
|
+
* a trace between them. A caller that knows its engine passes the number.
|
|
433
|
+
*
|
|
434
|
+
* `"always"` is also the smallest module, often by an order of magnitude.
|
|
288
435
|
* @param {string} tape
|
|
436
|
+
* @param {string | null} [reroll]
|
|
289
437
|
* @returns {CompiledTape}
|
|
290
438
|
*/
|
|
291
|
-
export function compileTape(tape) {
|
|
439
|
+
export function compileTape(tape, reroll) {
|
|
292
440
|
const ptr0 = passStringToWasm0(tape, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
293
441
|
const len0 = WASM_VECTOR_LEN;
|
|
294
|
-
|
|
442
|
+
var ptr1 = isLikeNone(reroll) ? 0 : passStringToWasm0(reroll, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
443
|
+
var len1 = WASM_VECTOR_LEN;
|
|
444
|
+
const ret = wasm.compileTape(ptr0, len0, ptr1, len1);
|
|
295
445
|
if (ret[2]) {
|
|
296
446
|
throw takeFromExternrefTable0(ret[1]);
|
|
297
447
|
}
|
|
@@ -352,6 +502,13 @@ function __wbg_get_imports() {
|
|
|
352
502
|
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
353
503
|
return ret;
|
|
354
504
|
},
|
|
505
|
+
__wbg___wbindgen_debug_string_0e68cf47c9cbd9b0: function(arg0, arg1) {
|
|
506
|
+
const ret = debugString(arg1);
|
|
507
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
508
|
+
const len1 = WASM_VECTOR_LEN;
|
|
509
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
510
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
511
|
+
},
|
|
355
512
|
__wbg___wbindgen_memory_3f8442e22540244f: function() {
|
|
356
513
|
const ret = wasm.memory;
|
|
357
514
|
return ret;
|
|
@@ -367,10 +524,18 @@ function __wbg_get_imports() {
|
|
|
367
524
|
__wbg___wbindgen_throw_5d9e815e6fdf150f: function(arg0, arg1) {
|
|
368
525
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
369
526
|
},
|
|
370
|
-
|
|
527
|
+
__wbg_aot_logp_88e25d7a78bf7680: function(arg0, arg1, arg2, arg3) {
|
|
371
528
|
const ret = aot_logp(arg0 >>> 0, arg1 >>> 0, arg2 >>> 0, arg3 >>> 0);
|
|
372
529
|
return ret;
|
|
373
530
|
},
|
|
531
|
+
__wbg_call_d9fe056b59ca67cb: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6) {
|
|
532
|
+
var v0 = getArrayF64FromWasm0(arg3, arg4).slice();
|
|
533
|
+
wasm.__wbindgen_free(arg3, arg4 * 8, 8);
|
|
534
|
+
var v1 = getArrayF64FromWasm0(arg5, arg6).slice();
|
|
535
|
+
wasm.__wbindgen_free(arg5, arg6 * 8, 8);
|
|
536
|
+
const ret = arg0.call(arg1, arg2, v0, v1);
|
|
537
|
+
return ret;
|
|
538
|
+
}, arguments); },
|
|
374
539
|
__wbg_error_757e9472f8410341: function(arg0, arg1) {
|
|
375
540
|
let deferred0_0;
|
|
376
541
|
let deferred0_1;
|
|
@@ -406,10 +571,10 @@ function __wbg_get_imports() {
|
|
|
406
571
|
return {
|
|
407
572
|
__proto__: null,
|
|
408
573
|
"./tapewasm_bg.js": import0,
|
|
409
|
-
"./snippets/tapewasm-
|
|
410
|
-
"./snippets/tapewasm-
|
|
411
|
-
"./snippets/tapewasm-
|
|
412
|
-
"./snippets/tapewasm-
|
|
574
|
+
"./snippets/tapewasm-cbf82a3d7bc31b1b/js/aot_bridge.js": import1,
|
|
575
|
+
"./snippets/tapewasm-cbf82a3d7bc31b1b/js/aot_bridge.js": import2,
|
|
576
|
+
"./snippets/tapewasm-cbf82a3d7bc31b1b/js/aot_bridge.js": import3,
|
|
577
|
+
"./snippets/tapewasm-cbf82a3d7bc31b1b/js/aot_bridge.js": import4,
|
|
413
578
|
};
|
|
414
579
|
}
|
|
415
580
|
|
|
@@ -422,6 +587,9 @@ const AotSamplerFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
|
422
587
|
const CompiledTapeFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
423
588
|
? { register: () => {}, unregister: () => {} }
|
|
424
589
|
: new FinalizationRegistry(ptr => wasm.__wbg_compiledtape_free(ptr, 1));
|
|
590
|
+
const SampleResultFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
591
|
+
? { register: () => {}, unregister: () => {} }
|
|
592
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_sampleresult_free(ptr, 1));
|
|
425
593
|
|
|
426
594
|
function addToExternrefTable0(obj) {
|
|
427
595
|
const idx = wasm.__externref_table_alloc();
|
|
@@ -429,11 +597,81 @@ function addToExternrefTable0(obj) {
|
|
|
429
597
|
return idx;
|
|
430
598
|
}
|
|
431
599
|
|
|
600
|
+
function debugString(val) {
|
|
601
|
+
// primitive types
|
|
602
|
+
const type = typeof val;
|
|
603
|
+
if (type == 'number' || type == 'boolean' || val == null) {
|
|
604
|
+
return `${val}`;
|
|
605
|
+
}
|
|
606
|
+
if (type == 'string') {
|
|
607
|
+
return `"${val}"`;
|
|
608
|
+
}
|
|
609
|
+
if (type == 'symbol') {
|
|
610
|
+
const description = val.description;
|
|
611
|
+
if (description == null) {
|
|
612
|
+
return 'Symbol';
|
|
613
|
+
} else {
|
|
614
|
+
return `Symbol(${description})`;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
if (type == 'function') {
|
|
618
|
+
const name = val.name;
|
|
619
|
+
if (typeof name == 'string' && name.length > 0) {
|
|
620
|
+
return `Function(${name})`;
|
|
621
|
+
} else {
|
|
622
|
+
return 'Function';
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
// objects
|
|
626
|
+
if (Array.isArray(val)) {
|
|
627
|
+
const length = val.length;
|
|
628
|
+
let debug = '[';
|
|
629
|
+
if (length > 0) {
|
|
630
|
+
debug += debugString(val[0]);
|
|
631
|
+
}
|
|
632
|
+
for(let i = 1; i < length; i++) {
|
|
633
|
+
debug += ', ' + debugString(val[i]);
|
|
634
|
+
}
|
|
635
|
+
debug += ']';
|
|
636
|
+
return debug;
|
|
637
|
+
}
|
|
638
|
+
// Test for built-in
|
|
639
|
+
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
640
|
+
let className;
|
|
641
|
+
if (builtInMatches && builtInMatches.length > 1) {
|
|
642
|
+
className = builtInMatches[1];
|
|
643
|
+
} else {
|
|
644
|
+
// Failed to match the standard '[object ClassName]'
|
|
645
|
+
return toString.call(val);
|
|
646
|
+
}
|
|
647
|
+
if (className == 'Object') {
|
|
648
|
+
// we're a user defined class or Object
|
|
649
|
+
// JSON.stringify avoids problems with cycles, and is generally much
|
|
650
|
+
// easier than looping through ownProperties of `val`.
|
|
651
|
+
try {
|
|
652
|
+
return 'Object(' + JSON.stringify(val) + ')';
|
|
653
|
+
} catch (_) {
|
|
654
|
+
return 'Object';
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
// errors
|
|
658
|
+
if (val instanceof Error) {
|
|
659
|
+
return `${val.name}: ${val.message}\n${val.stack}`;
|
|
660
|
+
}
|
|
661
|
+
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
662
|
+
return className;
|
|
663
|
+
}
|
|
664
|
+
|
|
432
665
|
function getArrayF64FromWasm0(ptr, len) {
|
|
433
666
|
ptr = ptr >>> 0;
|
|
434
667
|
return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
|
|
435
668
|
}
|
|
436
669
|
|
|
670
|
+
function getArrayU32FromWasm0(ptr, len) {
|
|
671
|
+
ptr = ptr >>> 0;
|
|
672
|
+
return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
|
|
673
|
+
}
|
|
674
|
+
|
|
437
675
|
function getArrayU8FromWasm0(ptr, len) {
|
|
438
676
|
ptr = ptr >>> 0;
|
|
439
677
|
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
@@ -459,6 +697,14 @@ function getStringFromWasm0(ptr, len) {
|
|
|
459
697
|
return decodeText(ptr >>> 0, len);
|
|
460
698
|
}
|
|
461
699
|
|
|
700
|
+
let cachedUint32ArrayMemory0 = null;
|
|
701
|
+
function getUint32ArrayMemory0() {
|
|
702
|
+
if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
|
|
703
|
+
cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
|
|
704
|
+
}
|
|
705
|
+
return cachedUint32ArrayMemory0;
|
|
706
|
+
}
|
|
707
|
+
|
|
462
708
|
let cachedUint8ArrayMemory0 = null;
|
|
463
709
|
function getUint8ArrayMemory0() {
|
|
464
710
|
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
@@ -467,6 +713,15 @@ function getUint8ArrayMemory0() {
|
|
|
467
713
|
return cachedUint8ArrayMemory0;
|
|
468
714
|
}
|
|
469
715
|
|
|
716
|
+
function handleError(f, args) {
|
|
717
|
+
try {
|
|
718
|
+
return f.apply(this, args);
|
|
719
|
+
} catch (e) {
|
|
720
|
+
const idx = addToExternrefTable0(e);
|
|
721
|
+
wasm.__wbindgen_exn_store(idx);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
|
|
470
725
|
function isLikeNone(x) {
|
|
471
726
|
return x === undefined || x === null;
|
|
472
727
|
}
|
|
@@ -567,6 +822,7 @@ function __wbg_finalize_init(instance, module) {
|
|
|
567
822
|
wasmModule = module;
|
|
568
823
|
cachedDataViewMemory0 = null;
|
|
569
824
|
cachedFloat64ArrayMemory0 = null;
|
|
825
|
+
cachedUint32ArrayMemory0 = null;
|
|
570
826
|
cachedUint8ArrayMemory0 = null;
|
|
571
827
|
wasm.__wbindgen_start();
|
|
572
828
|
return wasm;
|
package/pkg/tapewasm_bg.wasm
CHANGED
|
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;
|
/package/pkg/snippets/{tapewasm-3fbd96d1430b56d5 → tapewasm-cbf82a3d7bc31b1b}/js/aot_bridge.js
RENAMED
|
File without changes
|