@seantalts/stanli 0.11.1 → 0.12.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.mjs CHANGED
@@ -167,6 +167,14 @@ function pathfinderInitOptions(value) {
167
167
  * lp__, accept_stat__, stepsize__, treedepth__, n_leapfrog__,
168
168
  * divergent__, energy__. Other methods return null for samplerStats.
169
169
  */
170
+ // JSON.stringify writes null for a non-finite number, which Stan's data
171
+ // reader rejects. It takes these quoted tokens.
172
+ function stanNumber(key, value) {
173
+ if (typeof value !== "number" || Number.isFinite(value)) return value;
174
+ if (Number.isNaN(value)) return "NaN";
175
+ return value > 0 ? "Infinity" : "-Infinity";
176
+ }
177
+
170
178
  export function sample(opts) {
171
179
  const sampler = opts.sampler === "walnuts" || opts.sampler === "pathfinder"
172
180
  ? opts.sampler : "nuts";
@@ -180,7 +188,7 @@ export function sample(opts) {
180
188
  live: !!opts.onLive,
181
189
  dataJson: typeof opts.data === "string"
182
190
  ? opts.data
183
- : JSON.stringify(opts.data || {}),
191
+ : JSON.stringify(opts.data || {}, stanNumber),
184
192
  seed: opts.seed == null ? 1 : opts.seed,
185
193
  warmup: opts.warmup == null ? 1000 : opts.warmup,
186
194
  samples: opts.samples == null ? 1000 : opts.samples,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seantalts/stanli",
3
- "version": "0.11.1",
3
+ "version": "0.12.0",
4
4
  "description": "Full Stan in the browser: stanc3 compiles the model in JS, a WASM runtime lowers it to an op graph and runs NUTS. No server, no C++ toolchain.",
5
5
  "type": "module",
6
6
  "main": "index.mjs",