@iyulab/u-numflow 0.12.0 → 0.13.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/README.md CHANGED
@@ -35,7 +35,7 @@ u-numflow provides foundational mathematical, statistical, and probabilistic bui
35
35
 
36
36
  ```toml
37
37
  [dependencies]
38
- u-numflow = "0.12"
38
+ u-numflow = "0.13"
39
39
  ```
40
40
 
41
41
  ```rust
@@ -210,6 +210,12 @@ const up = interval_difference([[0, 168]], down); // [[30, 168]]
210
210
  console.log(interval_measure(up)); // 138
211
211
  ```
212
212
 
213
+ `codes()` returns every refusal `code` the functions throw, with the fields that
214
+ can come with it — `{ refusals: [{ code, fields }], violations: [] }` — built from
215
+ the table the refusals come from; the table below explains each. The C library
216
+ returns the same JSON from `unumflow_codes()` and the .NET package from
217
+ `Numflow.Codes`.
218
+
213
219
  **Errors.** A refusal throws an `Error` whose `message` is readable text and which
214
220
  carries a `code` naming the reason, next to the values behind it:
215
221
 
@@ -234,6 +240,8 @@ try {
234
240
  | `non_positive_data` | `parameter`, `index`, `got` | Box-Cox data with a value `≤ 0` — `index` is the first such value |
235
241
  | `insufficient_data` | `parameter`, `min`, `got` | Fewer values than the function needs (`std_dev`/`variance` 2, Box-Cox 2) |
236
242
  | `invalid_transform` | — | A Box-Cox result that is not finite |
243
+ | `invalid_inverse` | — | An inverse Box-Cox whose result is not finite |
244
+ | `internal` | — | A fault in this package rather than in the request — please report it |
237
245
 
238
246
  In `parameter_out_of_range`, `min` and `max` are inclusive bounds and are always
239
247
  present — `null` when that end is unbounded or open. An open (exclusive) end is
@@ -61,6 +61,23 @@ function chi_squared_quantile(p, k) {
61
61
  }
62
62
  exports.chi_squared_quantile = chi_squared_quantile;
63
63
 
64
+ /**
65
+ * Every refusal `code` the functions of this package throw, with the fields
66
+ * that can come with it: `{ refusals: [{ code, fields }], violations: [] }`.
67
+ *
68
+ * It is built from the table the refusals come from, so a caller that
69
+ * translates codes can check its list against the package's.
70
+ * @returns {Codes}
71
+ */
72
+ function codes() {
73
+ const ret = wasm.codes();
74
+ if (ret[2]) {
75
+ throw takeFromExternrefTable0(ret[1]);
76
+ }
77
+ return takeFromExternrefTable0(ret[0]);
78
+ }
79
+ exports.codes = codes;
80
+
64
81
  /**
65
82
  * `P(X ≤ x)` for the distribution `{ kind, ...parameters }`.
66
83
  *
@@ -690,6 +707,9 @@ function __wbg_get_imports() {
690
707
  __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
691
708
  arg0[arg1] = arg2;
692
709
  },
710
+ __wbg_set_bea140a88be9b277: function(arg0, arg1, arg2) {
711
+ arg0[arg1 >>> 0] = arg2;
712
+ },
693
713
  __wbg_value_f3c585ee8f5ba40c: function(arg0) {
694
714
  const ret = arg0.value;
695
715
  return ret;
@@ -5,6 +5,25 @@
5
5
  */
6
6
  export type DistributionSpec = { kind: "uniform"; min: number; max: number } | { kind: "triangular"; min: number; mode: number; max: number } | { kind: "pert"; min: number; mode: number; max: number; lambda?: number } | { kind: "normal"; mu: number; sigma: number } | { kind: "lognormal"; mu: number; sigma: number } | { kind: "weibull"; shape: number; scale: number } | { kind: "exponential"; rate: number } | { kind: "gamma"; shape: number; rate: number } | { kind: "beta"; alpha: number; beta: number } | { kind: "chi_squared"; k: number };
7
7
 
8
+ /**
9
+ * A refusal reason: the `code` a refusal carries (the WebAssembly `Error`'s,
10
+ * the C error body's) and the fields that can stand beside it.
11
+ */
12
+ export interface RefusalCode {
13
+ code: string;
14
+ fields: string[];
15
+ }
16
+
17
+ /**
18
+ * A violation a checker reports. This package has no checker; the type is
19
+ * here so every engine's [`Codes`] has one shape.
20
+ */
21
+ export interface ViolationCode {
22
+ code: string;
23
+ fields: string[];
24
+ checkers: string[];
25
+ }
26
+
8
27
  /**
9
28
  * Mean and variance of a distribution.
10
29
  */
@@ -21,6 +40,15 @@ export interface LambdaEstimateDto {
21
40
  at_bound: boolean;
22
41
  }
23
42
 
43
+ /**
44
+ * What this package can answer with besides a result: every refusal
45
+ * `code`, and no violations -- it has no checker.
46
+ */
47
+ export interface Codes {
48
+ refusals: RefusalCode[];
49
+ violations: ViolationCode[];
50
+ }
51
+
24
52
 
25
53
  /**
26
54
  * Apply the Box-Cox power transformation to positive data.
@@ -51,6 +79,15 @@ export function chi_squared_cdf(x: number, k: number): number;
51
79
  */
52
80
  export function chi_squared_quantile(p: number, k: number): number;
53
81
 
82
+ /**
83
+ * Every refusal `code` the functions of this package throw, with the fields
84
+ * that can come with it: `{ refusals: [{ code, fields }], violations: [] }`.
85
+ *
86
+ * It is built from the table the refusals come from, so a caller that
87
+ * translates codes can check its list against the package's.
88
+ */
89
+ export function codes(): Codes;
90
+
54
91
  /**
55
92
  * `P(X ≤ x)` for the distribution `{ kind, ...parameters }`.
56
93
  *
Binary file
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "iyulab"
6
6
  ],
7
7
  "description": "Foundational mathematical primitives: statistics, probability distributions, random sampling, and collections.",
8
- "version": "0.12.0",
8
+ "version": "0.13.1",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
package/u_numflow.d.ts CHANGED
@@ -5,6 +5,25 @@
5
5
  */
6
6
  export type DistributionSpec = { kind: "uniform"; min: number; max: number } | { kind: "triangular"; min: number; mode: number; max: number } | { kind: "pert"; min: number; mode: number; max: number; lambda?: number } | { kind: "normal"; mu: number; sigma: number } | { kind: "lognormal"; mu: number; sigma: number } | { kind: "weibull"; shape: number; scale: number } | { kind: "exponential"; rate: number } | { kind: "gamma"; shape: number; rate: number } | { kind: "beta"; alpha: number; beta: number } | { kind: "chi_squared"; k: number };
7
7
 
8
+ /**
9
+ * A refusal reason: the `code` a refusal carries (the WebAssembly `Error`'s,
10
+ * the C error body's) and the fields that can stand beside it.
11
+ */
12
+ export interface RefusalCode {
13
+ code: string;
14
+ fields: string[];
15
+ }
16
+
17
+ /**
18
+ * A violation a checker reports. This package has no checker; the type is
19
+ * here so every engine's [`Codes`] has one shape.
20
+ */
21
+ export interface ViolationCode {
22
+ code: string;
23
+ fields: string[];
24
+ checkers: string[];
25
+ }
26
+
8
27
  /**
9
28
  * Mean and variance of a distribution.
10
29
  */
@@ -21,6 +40,15 @@ export interface LambdaEstimateDto {
21
40
  at_bound: boolean;
22
41
  }
23
42
 
43
+ /**
44
+ * What this package can answer with besides a result: every refusal
45
+ * `code`, and no violations -- it has no checker.
46
+ */
47
+ export interface Codes {
48
+ refusals: RefusalCode[];
49
+ violations: ViolationCode[];
50
+ }
51
+
24
52
 
25
53
  /**
26
54
  * Apply the Box-Cox power transformation to positive data.
@@ -51,6 +79,15 @@ export function chi_squared_cdf(x: number, k: number): number;
51
79
  */
52
80
  export function chi_squared_quantile(p: number, k: number): number;
53
81
 
82
+ /**
83
+ * Every refusal `code` the functions of this package throw, with the fields
84
+ * that can come with it: `{ refusals: [{ code, fields }], violations: [] }`.
85
+ *
86
+ * It is built from the table the refusals come from, so a caller that
87
+ * translates codes can check its list against the package's.
88
+ */
89
+ export function codes(): Codes;
90
+
54
91
  /**
55
92
  * `P(X ≤ x)` for the distribution `{ kind, ...parameters }`.
56
93
  *
package/u_numflow.js CHANGED
@@ -5,5 +5,5 @@ import { __wbg_set_wasm } from "./u_numflow_bg.js";
5
5
  __wbg_set_wasm(wasm);
6
6
  wasm.__wbindgen_start();
7
7
  export {
8
- box_cox, chi_squared_cdf, chi_squared_quantile, distribution_cdf, distribution_moments, distribution_quantile, distribution_sample, estimate_lambda, f_distribution_cdf, f_distribution_quantile, interval_difference, interval_intersection, interval_measure, interval_normalize, interval_union, inverse_normal_cdf, mean, normal_cdf, normal_sf, rfft, std_dev, t_distribution_cdf, t_distribution_quantile, variance
8
+ box_cox, chi_squared_cdf, chi_squared_quantile, codes, distribution_cdf, distribution_moments, distribution_quantile, distribution_sample, estimate_lambda, f_distribution_cdf, f_distribution_quantile, interval_difference, interval_intersection, interval_measure, interval_normalize, interval_union, inverse_normal_cdf, mean, normal_cdf, normal_sf, rfft, std_dev, t_distribution_cdf, t_distribution_quantile, variance
9
9
  } from "./u_numflow_bg.js";
package/u_numflow_bg.js CHANGED
@@ -56,6 +56,22 @@ export function chi_squared_quantile(p, k) {
56
56
  return ret[0];
57
57
  }
58
58
 
59
+ /**
60
+ * Every refusal `code` the functions of this package throw, with the fields
61
+ * that can come with it: `{ refusals: [{ code, fields }], violations: [] }`.
62
+ *
63
+ * It is built from the table the refusals come from, so a caller that
64
+ * translates codes can check its list against the package's.
65
+ * @returns {Codes}
66
+ */
67
+ export function codes() {
68
+ const ret = wasm.codes();
69
+ if (ret[2]) {
70
+ throw takeFromExternrefTable0(ret[1]);
71
+ }
72
+ return takeFromExternrefTable0(ret[0]);
73
+ }
74
+
59
75
  /**
60
76
  * `P(X ≤ x)` for the distribution `{ kind, ...parameters }`.
61
77
  *
@@ -661,6 +677,9 @@ export function __wbg_set_145a351398b48c65() { return handleError(function (arg0
661
677
  export function __wbg_set_6be42768c690e380(arg0, arg1, arg2) {
662
678
  arg0[arg1] = arg2;
663
679
  }
680
+ export function __wbg_set_bea140a88be9b277(arg0, arg1, arg2) {
681
+ arg0[arg1 >>> 0] = arg2;
682
+ }
664
683
  export function __wbg_value_f3c585ee8f5ba40c(arg0) {
665
684
  const ret = arg0.value;
666
685
  return ret;
package/u_numflow_bg.wasm CHANGED
Binary file