stanwasm 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +84 -0
- package/index.d.ts +10 -0
- package/index.js +20 -0
- package/package.json +33 -0
- package/pkg/LICENSE +201 -0
- package/pkg/README.md +22 -0
- package/pkg/package.json +28 -0
- package/pkg/snippets/stanwasm-2319b34998707c5e/js/aot_bridge.js +35 -0
- package/pkg/stanwasm.d.ts +195 -0
- package/pkg/stanwasm.js +596 -0
- package/pkg/stanwasm_bg.wasm +0 -0
- package/pkg/stanwasm_bg.wasm.d.ts +29 -0
package/pkg/stanwasm.js
ADDED
|
@@ -0,0 +1,596 @@
|
|
|
1
|
+
/* @ts-self-types="./stanwasm.d.ts" */
|
|
2
|
+
import { aot_logp } from './snippets/stanwasm-2319b34998707c5e/js/aot_bridge.js';
|
|
3
|
+
import * as import1 from "./snippets/stanwasm-2319b34998707c5e/js/aot_bridge.js"
|
|
4
|
+
import * as import2 from "./snippets/stanwasm-2319b34998707c5e/js/aot_bridge.js"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* One compiled Stan model. Holds both the parsed AST (`Model`) and a
|
|
9
|
+
* pre-traced `Compiled` for fast log-prob evaluation. Sampling consumes
|
|
10
|
+
* the `Compiled` and re-builds it from the retained AST afterwards, so
|
|
11
|
+
* the same `StanModel` instance can be sampled repeatedly.
|
|
12
|
+
*/
|
|
13
|
+
export class StanModel {
|
|
14
|
+
__destroy_into_raw() {
|
|
15
|
+
const ptr = this.__wbg_ptr;
|
|
16
|
+
this.__wbg_ptr = 0;
|
|
17
|
+
StanModelFinalization.unregister(this);
|
|
18
|
+
return ptr;
|
|
19
|
+
}
|
|
20
|
+
free() {
|
|
21
|
+
const ptr = this.__destroy_into_raw();
|
|
22
|
+
wasm.__wbg_stanmodel_free(ptr, 0);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* AOT-compile this model to a self-contained wasm module. Returns the
|
|
26
|
+
* wasm bytes (callers can pass these to `WebAssembly.instantiate` to
|
|
27
|
+
* obtain an independent log_prob_grad runtime — useful for Web Workers
|
|
28
|
+
* or for inspection).
|
|
29
|
+
* @returns {Uint8Array}
|
|
30
|
+
*/
|
|
31
|
+
compileToWasm() {
|
|
32
|
+
const ret = wasm.stanmodel_compileToWasm(this.__wbg_ptr);
|
|
33
|
+
if (ret[3]) {
|
|
34
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
35
|
+
}
|
|
36
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
37
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
38
|
+
return v1;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Constrained values of `parameters` + `transformed parameters` for one
|
|
42
|
+
* unconstrained draw (e.g. one row out of `sample()`'s output), flattened
|
|
43
|
+
* in `paramNames()` order.
|
|
44
|
+
* @param {Float64Array} unconstrained
|
|
45
|
+
* @returns {Float64Array}
|
|
46
|
+
*/
|
|
47
|
+
constrainDraw(unconstrained) {
|
|
48
|
+
const ptr0 = passArrayF64ToWasm0(unconstrained, wasm.__wbindgen_malloc);
|
|
49
|
+
const len0 = WASM_VECTOR_LEN;
|
|
50
|
+
const ret = wasm.stanmodel_constrainDraw(this.__wbg_ptr, ptr0, len0);
|
|
51
|
+
if (ret[3]) {
|
|
52
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
53
|
+
}
|
|
54
|
+
var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
|
|
55
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
|
|
56
|
+
return v2;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Stop step-sampling early (or clean up after it finished naturally —
|
|
60
|
+
* safe to call either way) and restore `logProbGrad`/`sample` by
|
|
61
|
+
* re-tracing, same as `sample()` does at the end of a run.
|
|
62
|
+
*/
|
|
63
|
+
finishStepSampling() {
|
|
64
|
+
wasm.stanmodel_finishStepSampling(this.__wbg_ptr);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Names of the top-level `generated quantities` declarations, flattened
|
|
68
|
+
* the same way as `paramNames()`.
|
|
69
|
+
* @returns {string[]}
|
|
70
|
+
*/
|
|
71
|
+
genQuantityNames() {
|
|
72
|
+
const ret = wasm.stanmodel_genQuantityNames(this.__wbg_ptr);
|
|
73
|
+
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
74
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
75
|
+
return v1;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Evaluate `generated quantities` for a batch of unconstrained draws
|
|
79
|
+
* (e.g. `sample()`'s output). `draws` is a flat row-major buffer of
|
|
80
|
+
* shape `(n_draws, n_params)`; the result is `(n_draws, n_gen_quantities)`,
|
|
81
|
+
* row-major, in `genQuantityNames()` order. A single RNG stream (seeded
|
|
82
|
+
* by `seed`) is shared across all draws so repeated `_rng` calls don't
|
|
83
|
+
* repeat the same values draw-to-draw.
|
|
84
|
+
*
|
|
85
|
+
* Note: unlike `sampleViaAot`, there is no AOT-compiled counterpart of
|
|
86
|
+
* this method — `compileToWasm` only exports `log_prob_grad`. Generated
|
|
87
|
+
* quantities involve RNG and branching that the flat-tape AOT codegen
|
|
88
|
+
* doesn't model, and (running once per draw rather than once per NUTS
|
|
89
|
+
* leapfrog step) don't need it for performance.
|
|
90
|
+
* @param {Float64Array} draws
|
|
91
|
+
* @param {number} num_draws
|
|
92
|
+
* @param {bigint} seed
|
|
93
|
+
* @returns {Float64Array}
|
|
94
|
+
*/
|
|
95
|
+
generatedQuantities(draws, num_draws, seed) {
|
|
96
|
+
const ptr0 = passArrayF64ToWasm0(draws, wasm.__wbindgen_malloc);
|
|
97
|
+
const len0 = WASM_VECTOR_LEN;
|
|
98
|
+
const ret = wasm.stanmodel_generatedQuantities(this.__wbg_ptr, ptr0, len0, num_draws, seed);
|
|
99
|
+
if (ret[3]) {
|
|
100
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
101
|
+
}
|
|
102
|
+
var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
|
|
103
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
|
|
104
|
+
return v2;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Evaluate log_prob and gradient at `params`. Returns a flat array of
|
|
108
|
+
* length `n_params + 1`: the log-prob is at index 0, gradients follow.
|
|
109
|
+
* @param {Float64Array} params
|
|
110
|
+
* @returns {Float64Array}
|
|
111
|
+
*/
|
|
112
|
+
logProbGrad(params) {
|
|
113
|
+
const ptr0 = passArrayF64ToWasm0(params, wasm.__wbindgen_malloc);
|
|
114
|
+
const len0 = WASM_VECTOR_LEN;
|
|
115
|
+
const ret = wasm.stanmodel_logProbGrad(this.__wbg_ptr, ptr0, len0);
|
|
116
|
+
if (ret[3]) {
|
|
117
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
118
|
+
}
|
|
119
|
+
var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
|
|
120
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
|
|
121
|
+
return v2;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Number of unconstrained parameters.
|
|
125
|
+
* @returns {number}
|
|
126
|
+
*/
|
|
127
|
+
get n_params() {
|
|
128
|
+
const ret = wasm.stanmodel_n_params(this.__wbg_ptr);
|
|
129
|
+
return ret >>> 0;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Parse `stan_src`, bind `data_json`, trace the model on the autodiff
|
|
133
|
+
* tape, and return a handle ready for sampling.
|
|
134
|
+
* @param {string} stan_src
|
|
135
|
+
* @param {string} data_json
|
|
136
|
+
*/
|
|
137
|
+
constructor(stan_src, data_json) {
|
|
138
|
+
const ptr0 = passStringToWasm0(stan_src, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
139
|
+
const len0 = WASM_VECTOR_LEN;
|
|
140
|
+
const ptr1 = passStringToWasm0(data_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
141
|
+
const len1 = WASM_VECTOR_LEN;
|
|
142
|
+
const ret = wasm.stanmodel_new(ptr0, len0, ptr1, len1);
|
|
143
|
+
if (ret[2]) {
|
|
144
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
145
|
+
}
|
|
146
|
+
this.__wbg_ptr = ret[0];
|
|
147
|
+
StanModelFinalization.register(this, this.__wbg_ptr, this);
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Constrained parameter names (parameters then transformed parameters).
|
|
152
|
+
* @returns {string[]}
|
|
153
|
+
*/
|
|
154
|
+
paramNames() {
|
|
155
|
+
const ret = wasm.stanmodel_paramNames(this.__wbg_ptr);
|
|
156
|
+
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
157
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
158
|
+
return v1;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Run NUTS sampling. Returns a flat row-major buffer of shape
|
|
162
|
+
* `(num_warmup + num_draws) × n_params`. Tuning draws come first.
|
|
163
|
+
* @param {Float64Array} init
|
|
164
|
+
* @param {number} num_warmup
|
|
165
|
+
* @param {number} num_draws
|
|
166
|
+
* @param {bigint} seed
|
|
167
|
+
* @returns {Float64Array}
|
|
168
|
+
*/
|
|
169
|
+
sample(init, num_warmup, num_draws, seed) {
|
|
170
|
+
const ptr0 = passArrayF64ToWasm0(init, wasm.__wbindgen_malloc);
|
|
171
|
+
const len0 = WASM_VECTOR_LEN;
|
|
172
|
+
const ret = wasm.stanmodel_sample(this.__wbg_ptr, ptr0, len0, num_warmup, num_draws, seed);
|
|
173
|
+
if (ret[3]) {
|
|
174
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
175
|
+
}
|
|
176
|
+
var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
|
|
177
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
|
|
178
|
+
return v2;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Same as `sample`, but evaluates `log_prob_grad` through a
|
|
182
|
+
* pre-instantiated AOT-compiled model wasm bound via `setAotExports`.
|
|
183
|
+
* V8 JITs the unrolled forward+backward pass in the AOT module, which
|
|
184
|
+
* can be substantially faster than the in-process tape replay used by
|
|
185
|
+
* `sample`. Both produce identical samples for a given seed.
|
|
186
|
+
* @param {Float64Array} init
|
|
187
|
+
* @param {number} num_warmup
|
|
188
|
+
* @param {number} num_draws
|
|
189
|
+
* @param {bigint} seed
|
|
190
|
+
* @returns {Float64Array}
|
|
191
|
+
*/
|
|
192
|
+
sampleViaAot(init, num_warmup, num_draws, seed) {
|
|
193
|
+
const ptr0 = passArrayF64ToWasm0(init, wasm.__wbindgen_malloc);
|
|
194
|
+
const len0 = WASM_VECTOR_LEN;
|
|
195
|
+
const ret = wasm.stanmodel_sampleViaAot(this.__wbg_ptr, ptr0, len0, num_warmup, num_draws, seed);
|
|
196
|
+
if (ret[3]) {
|
|
197
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
198
|
+
}
|
|
199
|
+
var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
|
|
200
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
|
|
201
|
+
return v2;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Start a step-by-step NUTS run: unlike `sample()`, which runs the whole
|
|
205
|
+
* chain inside one wasm call and returns only at the end, this leaves
|
|
206
|
+
* the sampler's state alive in the `StanModel` instance so `stepDraw()`
|
|
207
|
+
* can advance it one draw at a time — genuinely watching the sampler
|
|
208
|
+
* work, not replaying an already-finished chain. Consumes the internal
|
|
209
|
+
* `Compiled` the same way `sample()` does; call `finishStepSampling()`
|
|
210
|
+
* (or exhaust `stepDraw()` up to `num_warmup + num_draws` calls, which
|
|
211
|
+
* does it automatically) before using `logProbGrad`/`sample` again.
|
|
212
|
+
* @param {Float64Array} init
|
|
213
|
+
* @param {number} num_warmup
|
|
214
|
+
* @param {number} num_draws
|
|
215
|
+
* @param {bigint} seed
|
|
216
|
+
*/
|
|
217
|
+
startStepSampling(init, num_warmup, num_draws, seed) {
|
|
218
|
+
const ptr0 = passArrayF64ToWasm0(init, wasm.__wbindgen_malloc);
|
|
219
|
+
const len0 = WASM_VECTOR_LEN;
|
|
220
|
+
const ret = wasm.stanmodel_startStepSampling(this.__wbg_ptr, ptr0, len0, num_warmup, num_draws, seed);
|
|
221
|
+
if (ret[1]) {
|
|
222
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Advance the step-sampling chain started by `startStepSampling` by
|
|
227
|
+
* exactly one draw. Returns a flat array: `n_params` position values,
|
|
228
|
+
* then `1.0`/`0.0` for whether this draw was still in the warmup
|
|
229
|
+
* (tuning) phase, then `1.0`/`0.0` for whether it diverged, then the
|
|
230
|
+
* leapfrog `step_size` and `num_steps` nuts-rs actually used for this
|
|
231
|
+
* draw — these come straight out of nuts-rs's own dual-averaging
|
|
232
|
+
* adaptation and trajectory-length search, not anything this crate
|
|
233
|
+
* computes, so they're a way to show the real sampler internals at
|
|
234
|
+
* work rather than just the resulting draw. Once the requested
|
|
235
|
+
* `num_warmup + num_draws` draws have all been returned, this
|
|
236
|
+
* automatically restores `logProbGrad`/`sample` (by re-tracing, same as
|
|
237
|
+
* `sample()` does) and further calls fail until `startStepSampling` runs
|
|
238
|
+
* again.
|
|
239
|
+
* @returns {Float64Array}
|
|
240
|
+
*/
|
|
241
|
+
stepDraw() {
|
|
242
|
+
const ret = wasm.stanmodel_stepDraw(this.__wbg_ptr);
|
|
243
|
+
if (ret[3]) {
|
|
244
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
245
|
+
}
|
|
246
|
+
var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
|
|
247
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
|
|
248
|
+
return v1;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (Symbol.dispose) StanModel.prototype[Symbol.dispose] = StanModel.prototype.free;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Release the bound AOT exports. The next `sampleViaAot` call will throw.
|
|
255
|
+
*/
|
|
256
|
+
export function clearAotExports() {
|
|
257
|
+
wasm.clearAotExports();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Runs once when the wasm module is instantiated. Forwards Rust panics
|
|
262
|
+
* (Stan-typo'd names and invalid RNG parameters are now clean `JsError`s
|
|
263
|
+
* instead, but a handful of internal-invariant panics remain, e.g. index
|
|
264
|
+
* out of bounds on a malformed AST) to `console.error` with a real message
|
|
265
|
+
* and backtrace, instead of an opaque `RuntimeError: unreachable`. The
|
|
266
|
+
* panicking call still traps the instance — this is diagnostics, not
|
|
267
|
+
* recovery — but it means a bug report can include what actually broke.
|
|
268
|
+
*/
|
|
269
|
+
export function init_panic_hook() {
|
|
270
|
+
wasm.init_panic_hook();
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Bind a freshly-instantiated AOT model wasm's exports so subsequent
|
|
275
|
+
* `sampleViaAot` calls dispatch through it. Pass `instance.exports`.
|
|
276
|
+
* @param {any} exports
|
|
277
|
+
*/
|
|
278
|
+
export function setAotExports(exports) {
|
|
279
|
+
wasm.setAotExports(exports);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Returns the linear memory backing this wasm module. Pass to
|
|
284
|
+
* `WebAssembly.instantiate` as the `stan.memory` import when bringing up an
|
|
285
|
+
* AOT model so the two modules share buffers (zero-copy bridge).
|
|
286
|
+
* @returns {any}
|
|
287
|
+
*/
|
|
288
|
+
export function sharedMemory() {
|
|
289
|
+
const ret = wasm.sharedMemory();
|
|
290
|
+
return ret;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* @returns {string}
|
|
295
|
+
*/
|
|
296
|
+
export function version() {
|
|
297
|
+
let deferred1_0;
|
|
298
|
+
let deferred1_1;
|
|
299
|
+
try {
|
|
300
|
+
const ret = wasm.version();
|
|
301
|
+
deferred1_0 = ret[0];
|
|
302
|
+
deferred1_1 = ret[1];
|
|
303
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
304
|
+
} finally {
|
|
305
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function __wbg_get_imports() {
|
|
309
|
+
const import0 = {
|
|
310
|
+
__proto__: null,
|
|
311
|
+
__wbg_Error_bce6d499ff0a4aff: function(arg0, arg1) {
|
|
312
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
313
|
+
return ret;
|
|
314
|
+
},
|
|
315
|
+
__wbg___wbindgen_memory_9544558992fc5400: function() {
|
|
316
|
+
const ret = wasm.memory;
|
|
317
|
+
return ret;
|
|
318
|
+
},
|
|
319
|
+
__wbg___wbindgen_throw_9c31b086c2b26051: function(arg0, arg1) {
|
|
320
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
321
|
+
},
|
|
322
|
+
__wbg_aot_logp_bf34ba04055d8b4e: function(arg0, arg1, arg2) {
|
|
323
|
+
const ret = aot_logp(arg0 >>> 0, arg1 >>> 0, arg2 >>> 0);
|
|
324
|
+
return ret;
|
|
325
|
+
},
|
|
326
|
+
__wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
|
|
327
|
+
let deferred0_0;
|
|
328
|
+
let deferred0_1;
|
|
329
|
+
try {
|
|
330
|
+
deferred0_0 = arg0;
|
|
331
|
+
deferred0_1 = arg1;
|
|
332
|
+
console.error(getStringFromWasm0(arg0, arg1));
|
|
333
|
+
} finally {
|
|
334
|
+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
335
|
+
}
|
|
336
|
+
},
|
|
337
|
+
__wbg_new_227d7c05414eb861: function() {
|
|
338
|
+
const ret = new Error();
|
|
339
|
+
return ret;
|
|
340
|
+
},
|
|
341
|
+
__wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
|
|
342
|
+
const ret = arg1.stack;
|
|
343
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
344
|
+
const len1 = WASM_VECTOR_LEN;
|
|
345
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
346
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
347
|
+
},
|
|
348
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
349
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
350
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
351
|
+
return ret;
|
|
352
|
+
},
|
|
353
|
+
__wbindgen_init_externref_table: function() {
|
|
354
|
+
const table = wasm.__wbindgen_externrefs;
|
|
355
|
+
const offset = table.grow(4);
|
|
356
|
+
table.set(0, undefined);
|
|
357
|
+
table.set(offset + 0, undefined);
|
|
358
|
+
table.set(offset + 1, null);
|
|
359
|
+
table.set(offset + 2, true);
|
|
360
|
+
table.set(offset + 3, false);
|
|
361
|
+
},
|
|
362
|
+
};
|
|
363
|
+
return {
|
|
364
|
+
__proto__: null,
|
|
365
|
+
"./stanwasm_bg.js": import0,
|
|
366
|
+
"./snippets/stanwasm-2319b34998707c5e/js/aot_bridge.js": import1,
|
|
367
|
+
"./snippets/stanwasm-2319b34998707c5e/js/aot_bridge.js": import2,
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const StanModelFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
372
|
+
? { register: () => {}, unregister: () => {} }
|
|
373
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_stanmodel_free(ptr, 1));
|
|
374
|
+
|
|
375
|
+
function getArrayF64FromWasm0(ptr, len) {
|
|
376
|
+
ptr = ptr >>> 0;
|
|
377
|
+
return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function getArrayJsValueFromWasm0(ptr, len) {
|
|
381
|
+
ptr = ptr >>> 0;
|
|
382
|
+
const mem = getDataViewMemory0();
|
|
383
|
+
const result = [];
|
|
384
|
+
for (let i = ptr; i < ptr + 4 * len; i += 4) {
|
|
385
|
+
result.push(wasm.__wbindgen_externrefs.get(mem.getUint32(i, true)));
|
|
386
|
+
}
|
|
387
|
+
wasm.__externref_drop_slice(ptr, len);
|
|
388
|
+
return result;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
392
|
+
ptr = ptr >>> 0;
|
|
393
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
let cachedDataViewMemory0 = null;
|
|
397
|
+
function getDataViewMemory0() {
|
|
398
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
399
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
400
|
+
}
|
|
401
|
+
return cachedDataViewMemory0;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
let cachedFloat64ArrayMemory0 = null;
|
|
405
|
+
function getFloat64ArrayMemory0() {
|
|
406
|
+
if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
|
|
407
|
+
cachedFloat64ArrayMemory0 = new Float64Array(wasm.memory.buffer);
|
|
408
|
+
}
|
|
409
|
+
return cachedFloat64ArrayMemory0;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function getStringFromWasm0(ptr, len) {
|
|
413
|
+
return decodeText(ptr >>> 0, len);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
let cachedUint8ArrayMemory0 = null;
|
|
417
|
+
function getUint8ArrayMemory0() {
|
|
418
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
419
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
420
|
+
}
|
|
421
|
+
return cachedUint8ArrayMemory0;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function passArrayF64ToWasm0(arg, malloc) {
|
|
425
|
+
const ptr = malloc(arg.length * 8, 8) >>> 0;
|
|
426
|
+
getFloat64ArrayMemory0().set(arg, ptr / 8);
|
|
427
|
+
WASM_VECTOR_LEN = arg.length;
|
|
428
|
+
return ptr;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
432
|
+
if (realloc === undefined) {
|
|
433
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
434
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
435
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
436
|
+
WASM_VECTOR_LEN = buf.length;
|
|
437
|
+
return ptr;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
let len = arg.length;
|
|
441
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
442
|
+
|
|
443
|
+
const mem = getUint8ArrayMemory0();
|
|
444
|
+
|
|
445
|
+
let offset = 0;
|
|
446
|
+
|
|
447
|
+
for (; offset < len; offset++) {
|
|
448
|
+
const code = arg.charCodeAt(offset);
|
|
449
|
+
if (code > 0x7F) break;
|
|
450
|
+
mem[ptr + offset] = code;
|
|
451
|
+
}
|
|
452
|
+
if (offset !== len) {
|
|
453
|
+
if (offset !== 0) {
|
|
454
|
+
arg = arg.slice(offset);
|
|
455
|
+
}
|
|
456
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
457
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
458
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
459
|
+
|
|
460
|
+
offset += ret.written;
|
|
461
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
WASM_VECTOR_LEN = offset;
|
|
465
|
+
return ptr;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
function takeFromExternrefTable0(idx) {
|
|
469
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
470
|
+
wasm.__externref_table_dealloc(idx);
|
|
471
|
+
return value;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
475
|
+
cachedTextDecoder.decode();
|
|
476
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
477
|
+
let numBytesDecoded = 0;
|
|
478
|
+
function decodeText(ptr, len) {
|
|
479
|
+
numBytesDecoded += len;
|
|
480
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
481
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
482
|
+
cachedTextDecoder.decode();
|
|
483
|
+
numBytesDecoded = len;
|
|
484
|
+
}
|
|
485
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const cachedTextEncoder = new TextEncoder();
|
|
489
|
+
|
|
490
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
491
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
492
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
493
|
+
view.set(buf);
|
|
494
|
+
return {
|
|
495
|
+
read: arg.length,
|
|
496
|
+
written: buf.length
|
|
497
|
+
};
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
let WASM_VECTOR_LEN = 0;
|
|
502
|
+
|
|
503
|
+
let wasmModule, wasmInstance, wasm;
|
|
504
|
+
function __wbg_finalize_init(instance, module) {
|
|
505
|
+
wasmInstance = instance;
|
|
506
|
+
wasm = instance.exports;
|
|
507
|
+
wasmModule = module;
|
|
508
|
+
cachedDataViewMemory0 = null;
|
|
509
|
+
cachedFloat64ArrayMemory0 = null;
|
|
510
|
+
cachedUint8ArrayMemory0 = null;
|
|
511
|
+
wasm.__wbindgen_start();
|
|
512
|
+
return wasm;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
async function __wbg_load(module, imports) {
|
|
516
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
517
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
518
|
+
try {
|
|
519
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
520
|
+
} catch (e) {
|
|
521
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
522
|
+
|
|
523
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
524
|
+
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);
|
|
525
|
+
|
|
526
|
+
} else { throw e; }
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
const bytes = await module.arrayBuffer();
|
|
531
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
532
|
+
} else {
|
|
533
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
534
|
+
|
|
535
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
536
|
+
return { instance, module };
|
|
537
|
+
} else {
|
|
538
|
+
return instance;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
function expectedResponseType(type) {
|
|
543
|
+
switch (type) {
|
|
544
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
545
|
+
}
|
|
546
|
+
return false;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function initSync(module) {
|
|
551
|
+
if (wasm !== undefined) return wasm;
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
if (module !== undefined) {
|
|
555
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
556
|
+
({module} = module)
|
|
557
|
+
} else {
|
|
558
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
const imports = __wbg_get_imports();
|
|
563
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
564
|
+
module = new WebAssembly.Module(module);
|
|
565
|
+
}
|
|
566
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
567
|
+
return __wbg_finalize_init(instance, module);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
async function __wbg_init(module_or_path) {
|
|
571
|
+
if (wasm !== undefined) return wasm;
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
if (module_or_path !== undefined) {
|
|
575
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
576
|
+
({module_or_path} = module_or_path)
|
|
577
|
+
} else {
|
|
578
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
if (module_or_path === undefined) {
|
|
583
|
+
module_or_path = new URL('stanwasm_bg.wasm', import.meta.url);
|
|
584
|
+
}
|
|
585
|
+
const imports = __wbg_get_imports();
|
|
586
|
+
|
|
587
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
588
|
+
module_or_path = fetch(module_or_path);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
592
|
+
|
|
593
|
+
return __wbg_finalize_init(instance, module);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_stanmodel_free: (a: number, b: number) => void;
|
|
5
|
+
export const setAotExports: (a: any) => void;
|
|
6
|
+
export const stanmodel_compileToWasm: (a: number) => [number, number, number, number];
|
|
7
|
+
export const stanmodel_constrainDraw: (a: number, b: number, c: number) => [number, number, number, number];
|
|
8
|
+
export const stanmodel_finishStepSampling: (a: number) => void;
|
|
9
|
+
export const stanmodel_genQuantityNames: (a: number) => [number, number];
|
|
10
|
+
export const stanmodel_generatedQuantities: (a: number, b: number, c: number, d: number, e: bigint) => [number, number, number, number];
|
|
11
|
+
export const stanmodel_logProbGrad: (a: number, b: number, c: number) => [number, number, number, number];
|
|
12
|
+
export const stanmodel_n_params: (a: number) => number;
|
|
13
|
+
export const stanmodel_new: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
14
|
+
export const stanmodel_paramNames: (a: number) => [number, number];
|
|
15
|
+
export const stanmodel_sample: (a: number, b: number, c: number, d: number, e: number, f: bigint) => [number, number, number, number];
|
|
16
|
+
export const stanmodel_sampleViaAot: (a: number, b: number, c: number, d: number, e: number, f: bigint) => [number, number, number, number];
|
|
17
|
+
export const stanmodel_startStepSampling: (a: number, b: number, c: number, d: number, e: number, f: bigint) => [number, number];
|
|
18
|
+
export const stanmodel_stepDraw: (a: number) => [number, number, number, number];
|
|
19
|
+
export const version: () => [number, number];
|
|
20
|
+
export const clearAotExports: () => void;
|
|
21
|
+
export const init_panic_hook: () => void;
|
|
22
|
+
export const sharedMemory: () => any;
|
|
23
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
24
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
25
|
+
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
26
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
27
|
+
export const __externref_table_dealloc: (a: number) => void;
|
|
28
|
+
export const __externref_drop_slice: (a: number, b: number) => void;
|
|
29
|
+
export const __wbindgen_start: () => void;
|