@iyulab/u-insight 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/LICENSE +21 -0
- package/README.md +253 -0
- package/package.json +32 -0
- package/u_insight.d.ts +54 -0
- package/u_insight.js +9 -0
- package/u_insight_bg.js +442 -0
- package/u_insight_bg.wasm +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 iyulab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
# u-insight
|
|
2
|
+
|
|
3
|
+
[](https://crates.io/crates/u-insight)
|
|
4
|
+
[](https://www.nuget.org/packages/UInsight)
|
|
5
|
+
[](https://docs.rs/u-insight)
|
|
6
|
+
[](https://github.com/iyulab/u-insight/actions/workflows/ci.yml)
|
|
7
|
+
|
|
8
|
+
A statistical analysis and data profiling engine in Rust with C FFI bindings.
|
|
9
|
+
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
u-insight transforms raw tabular data into actionable statistical insights. It operates in two distinct layers with **opposite assumptions about input data quality**:
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
CSV (raw)
|
|
16
|
+
│
|
|
17
|
+
├─→ Profiling ─→ "What is the state of this data?"
|
|
18
|
+
│ Tolerates dirty data (missing values, type mismatches expected)
|
|
19
|
+
│
|
|
20
|
+
│ (external preprocessing)
|
|
21
|
+
│
|
|
22
|
+
└─→ Analysis ─→ "What can we learn from this data?"
|
|
23
|
+
Requires clean numeric data (no NaN, no missing)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Built on `u-analytics` (statistical algorithms), `u-numflow` (math primitives).
|
|
27
|
+
|
|
28
|
+
## Modules
|
|
29
|
+
|
|
30
|
+
### Data Layer
|
|
31
|
+
|
|
32
|
+
| Module | Description |
|
|
33
|
+
|--------|-------------|
|
|
34
|
+
| `dataframe` | Column-major tabular data model (DataFrame, Column, DataType) |
|
|
35
|
+
| `csv_parser` | CSV parsing with automatic type inference |
|
|
36
|
+
| `error` | Error types (InsightError) |
|
|
37
|
+
|
|
38
|
+
### Profiling Layer (dirty data tolerated)
|
|
39
|
+
|
|
40
|
+
| Module | Description |
|
|
41
|
+
|--------|-------------|
|
|
42
|
+
| `profiling` | Column-level and dataset-level data profiling — descriptive stats, missing analysis, outlier flagging (IQR/Z-score/Modified Z-score), diagnostic flags |
|
|
43
|
+
|
|
44
|
+
### Analysis Layer (clean data required)
|
|
45
|
+
|
|
46
|
+
| Module | Description |
|
|
47
|
+
|--------|-------------|
|
|
48
|
+
| `analysis` | Correlation (Pearson/Spearman), regression (simple/multiple OLS), Cramer's V contingency analysis |
|
|
49
|
+
| `clustering` | K-Means++ (auto-K, Gap Statistic), Mini-Batch K-Means, DBSCAN, Hierarchical Agglomerative (Single/Complete/Average/Ward), HDBSCAN |
|
|
50
|
+
| `distribution` | ECDF, histogram bins (Sturges/Scott/FD), QQ-plot, normality tests (KS, Jarque-Bera, Shapiro-Wilk, Anderson-Darling), Grubbs test, distribution fitting |
|
|
51
|
+
| `pca` | Principal Component Analysis with auto-scaling option |
|
|
52
|
+
| `isolation_forest` | Isolation Forest anomaly detection (Liu et al. 2008) |
|
|
53
|
+
| `lof` | Local Outlier Factor (LOF) density-based anomaly detection |
|
|
54
|
+
| `mahalanobis` | Mahalanobis distance multivariate outlier detection |
|
|
55
|
+
| `feature_importance` | Variance threshold, correlation filter, VIF, condition number, composite importance, ANOVA F-test selection, Mutual Information, Permutation Importance |
|
|
56
|
+
|
|
57
|
+
### FFI Layer
|
|
58
|
+
|
|
59
|
+
| Module | Description |
|
|
60
|
+
|--------|-------------|
|
|
61
|
+
| `ffi` | C FFI bindings — 32 functions, 20 `#[repr(C)]` structs, auto-generated C header via cbindgen |
|
|
62
|
+
|
|
63
|
+
## Quick Start
|
|
64
|
+
|
|
65
|
+
```rust
|
|
66
|
+
use u_insight::csv_parser::CsvParser;
|
|
67
|
+
use u_insight::profiling::profile_dataframe;
|
|
68
|
+
|
|
69
|
+
// 1. Parse CSV
|
|
70
|
+
let csv = "name,value,active\nAlice,1.5,true\nBob,2.3,false\nCharlie,3.1,true\n";
|
|
71
|
+
let df = CsvParser::new().parse_str(csv).unwrap();
|
|
72
|
+
|
|
73
|
+
// 2. Profile
|
|
74
|
+
let profiles = profile_dataframe(&df);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Clustering
|
|
78
|
+
|
|
79
|
+
```rust
|
|
80
|
+
use u_insight::clustering::{kmeans, dbscan, KMeansConfig, DbscanConfig};
|
|
81
|
+
|
|
82
|
+
let data = vec![
|
|
83
|
+
vec![0.0, 0.0], vec![0.5, 0.5],
|
|
84
|
+
vec![10.0, 10.0], vec![10.5, 10.5],
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
// K-Means
|
|
88
|
+
let km = kmeans(&data, &KMeansConfig::new(2)).unwrap();
|
|
89
|
+
assert_eq!(km.k, 2);
|
|
90
|
+
|
|
91
|
+
// DBSCAN
|
|
92
|
+
let db = dbscan(&data, &DbscanConfig::new(1.5, 2)).unwrap();
|
|
93
|
+
assert_eq!(db.n_clusters, 2);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Distribution Analysis
|
|
97
|
+
|
|
98
|
+
```rust
|
|
99
|
+
use u_insight::distribution::{distribution_analysis, DistributionConfig};
|
|
100
|
+
|
|
101
|
+
let data: Vec<f64> = (0..50).map(|i| (i as f64 - 25.0) * 0.2).collect();
|
|
102
|
+
let result = distribution_analysis(&data, &DistributionConfig::default()).unwrap();
|
|
103
|
+
println!("Normal: {}", result.normality.is_normal);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## C FFI
|
|
107
|
+
|
|
108
|
+
u-insight builds as `cdylib` + `staticlib` for cross-language interop. A C header (`u_insight.h`) is auto-generated by cbindgen at build time.
|
|
109
|
+
|
|
110
|
+
### Profiling
|
|
111
|
+
|
|
112
|
+
| Function | Description |
|
|
113
|
+
|----------|-------------|
|
|
114
|
+
| `insight_profile_csv` | Profile a CSV string → opaque context |
|
|
115
|
+
| `insight_profile_free` | Free profile context |
|
|
116
|
+
| `insight_profile_row_count` | Row count from profile |
|
|
117
|
+
| `insight_profile_col_count` | Column count from profile |
|
|
118
|
+
| `insight_profile_column` | Get column summary |
|
|
119
|
+
|
|
120
|
+
### Clustering
|
|
121
|
+
|
|
122
|
+
| Function | Description |
|
|
123
|
+
|----------|-------------|
|
|
124
|
+
| `insight_kmeans` | K-Means++ clustering |
|
|
125
|
+
| `insight_mini_batch_kmeans` | Mini-Batch K-Means clustering |
|
|
126
|
+
| `insight_dbscan` | DBSCAN density-based clustering |
|
|
127
|
+
| `insight_hierarchical` | Hierarchical Agglomerative clustering (4 linkages) |
|
|
128
|
+
| `insight_hdbscan` | HDBSCAN clustering with membership probabilities |
|
|
129
|
+
| `insight_gap_statistic` | Gap statistic for optimal K selection |
|
|
130
|
+
|
|
131
|
+
### Dimensionality Reduction
|
|
132
|
+
|
|
133
|
+
| Function | Description |
|
|
134
|
+
|----------|-------------|
|
|
135
|
+
| `insight_pca` | Principal Component Analysis |
|
|
136
|
+
|
|
137
|
+
### Anomaly Detection
|
|
138
|
+
|
|
139
|
+
| Function | Description |
|
|
140
|
+
|----------|-------------|
|
|
141
|
+
| `insight_isolation_forest` | Isolation Forest anomaly detection |
|
|
142
|
+
| `insight_lof` | Local Outlier Factor detection |
|
|
143
|
+
| `insight_mahalanobis` | Mahalanobis distance outlier detection |
|
|
144
|
+
|
|
145
|
+
### Statistical Analysis
|
|
146
|
+
|
|
147
|
+
| Function | Description |
|
|
148
|
+
|----------|-------------|
|
|
149
|
+
| `insight_correlation` | Pearson correlation matrix |
|
|
150
|
+
| `insight_regression` | Simple linear regression |
|
|
151
|
+
| `insight_cramers_v` | Cramer's V contingency analysis |
|
|
152
|
+
|
|
153
|
+
### Distribution
|
|
154
|
+
|
|
155
|
+
| Function | Description |
|
|
156
|
+
|----------|-------------|
|
|
157
|
+
| `insight_distribution` | Normality testing (KS, JB, SW, AD) |
|
|
158
|
+
|
|
159
|
+
### Feature Importance
|
|
160
|
+
|
|
161
|
+
| Function | Description |
|
|
162
|
+
|----------|-------------|
|
|
163
|
+
| `insight_feature_importance` | Composite feature importance scores |
|
|
164
|
+
| `insight_anova_select` | ANOVA F-test feature selection |
|
|
165
|
+
| `insight_mutual_info` | Mutual information feature ranking |
|
|
166
|
+
| `insight_permutation_importance` | Permutation importance for regression |
|
|
167
|
+
|
|
168
|
+
### Memory Management
|
|
169
|
+
|
|
170
|
+
| Function | Description |
|
|
171
|
+
|----------|-------------|
|
|
172
|
+
| `insight_free_labels` | Free u32 label arrays |
|
|
173
|
+
| `insight_free_i32_array` | Free i32 arrays |
|
|
174
|
+
| `insight_free_f64_array` | Free f64 arrays |
|
|
175
|
+
| `insight_free_anova_features` | Free ANOVA feature arrays |
|
|
176
|
+
| `insight_free_mi_features` | Free MI feature arrays |
|
|
177
|
+
| `insight_free_perm_features` | Free permutation importance arrays |
|
|
178
|
+
|
|
179
|
+
### Error & Version
|
|
180
|
+
|
|
181
|
+
| Function | Description |
|
|
182
|
+
|----------|-------------|
|
|
183
|
+
| `insight_last_error` | Last error message (thread-local) |
|
|
184
|
+
| `insight_clear_error` | Clear error state |
|
|
185
|
+
| `insight_version` | Library version string |
|
|
186
|
+
|
|
187
|
+
All FFI functions use `catch_unwind` to prevent panics from crossing the FFI boundary.
|
|
188
|
+
|
|
189
|
+
## C# Binding (UInsight)
|
|
190
|
+
|
|
191
|
+
Install via NuGet — native libraries are bundled automatically:
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
dotnet add package UInsight
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
```csharp
|
|
198
|
+
using UInsight;
|
|
199
|
+
|
|
200
|
+
using var client = new InsightClient();
|
|
201
|
+
Console.WriteLine(client.GetVersion());
|
|
202
|
+
|
|
203
|
+
var data = new double[,] { {0,0}, {1,1}, {10,10}, {11,11} };
|
|
204
|
+
var result = client.KMeans(data, k: 2);
|
|
205
|
+
Console.WriteLine($"K={result.K}, WCSS={result.Wcss:F2}");
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
The binding is in `bindings/csharp/UInsight/` with:
|
|
209
|
+
|
|
210
|
+
- `Interop/NativeLibrary.cs` — `[LibraryImport]` declarations for all 32 FFI functions
|
|
211
|
+
- `Interop/NativeStructs.cs` — `[StructLayout]` mappings for all 20 C structs
|
|
212
|
+
- `InsightClient.cs` — High-level managed API (automatic memory management)
|
|
213
|
+
- `InsightException.cs` — Error code to exception conversion
|
|
214
|
+
|
|
215
|
+
## Test Status
|
|
216
|
+
|
|
217
|
+
```
|
|
218
|
+
357 lib tests + 49 doc-tests = 406 total
|
|
219
|
+
0 clippy warnings
|
|
220
|
+
Build: lib + cdylib + staticlib
|
|
221
|
+
C header: auto-generated via cbindgen (20 structs, 32 functions)
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Scope & Non-Goals
|
|
225
|
+
|
|
226
|
+
**In Scope:**
|
|
227
|
+
- Data profiling (dirty data → quality report + diagnostic flags)
|
|
228
|
+
- Statistical analysis (clean data → patterns + relationships)
|
|
229
|
+
- Correlation, regression, clustering, PCA, anomaly detection
|
|
230
|
+
- Feature importance and selection (ANOVA, MI, Permutation)
|
|
231
|
+
- Distribution analysis and normality testing
|
|
232
|
+
- C FFI for cross-language use
|
|
233
|
+
- C# binding (UInsight NuGet package)
|
|
234
|
+
|
|
235
|
+
**Out of Scope:**
|
|
236
|
+
- Visualization / charting
|
|
237
|
+
- Data cleaning / transformation / imputation
|
|
238
|
+
- ML model training / deployment
|
|
239
|
+
- Deep learning
|
|
240
|
+
|
|
241
|
+
## Requirements
|
|
242
|
+
|
|
243
|
+
- Rust 1.75+
|
|
244
|
+
- Dependencies: `u-analytics`, `u-numflow`
|
|
245
|
+
|
|
246
|
+
## Related
|
|
247
|
+
|
|
248
|
+
- [u-analytics](https://github.com/iyulab/u-analytics) -- Statistical analytics
|
|
249
|
+
- [u-numflow](https://github.com/iyulab/u-numflow) -- Mathematical primitives
|
|
250
|
+
|
|
251
|
+
## License
|
|
252
|
+
|
|
253
|
+
MIT License
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@iyulab/u-insight",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"collaborators": [
|
|
5
|
+
"iyulab"
|
|
6
|
+
],
|
|
7
|
+
"description": "Statistical analysis and data profiling engine with C FFI bindings.",
|
|
8
|
+
"version": "0.3.1",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/iyulab/u-insight"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"u_insight_bg.wasm",
|
|
16
|
+
"u_insight.js",
|
|
17
|
+
"u_insight_bg.js",
|
|
18
|
+
"u_insight.d.ts"
|
|
19
|
+
],
|
|
20
|
+
"main": "u_insight.js",
|
|
21
|
+
"types": "u_insight.d.ts",
|
|
22
|
+
"sideEffects": [
|
|
23
|
+
"./u_insight.js",
|
|
24
|
+
"./snippets/*"
|
|
25
|
+
],
|
|
26
|
+
"keywords": [
|
|
27
|
+
"statistics",
|
|
28
|
+
"profiling",
|
|
29
|
+
"analytics",
|
|
30
|
+
"ffi"
|
|
31
|
+
]
|
|
32
|
+
}
|
package/u_insight.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Computes a Pearson correlation matrix for a column-major dataset.
|
|
6
|
+
*
|
|
7
|
+
* # Input
|
|
8
|
+
* ```json
|
|
9
|
+
* { "col1": [1.0, 2.0, 3.0], "col2": [4.0, 5.0, 6.0] }
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* # Output
|
|
13
|
+
* `{ names, matrix (flattened n×n), n, high_pairs }`
|
|
14
|
+
*/
|
|
15
|
+
export function correlation_matrix(data_json: any): any;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Returns descriptive statistics for each column in a column-major dataset.
|
|
19
|
+
*
|
|
20
|
+
* # Input
|
|
21
|
+
* ```json
|
|
22
|
+
* { "col1": [1.0, 2.0, 3.0], "col2": [4.0, 5.0, 6.0] }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* # Output
|
|
26
|
+
* Array of column profile objects, one per column.
|
|
27
|
+
*/
|
|
28
|
+
export function describe(data_json: any): any;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Runs K-Means++ clustering on row-major data.
|
|
32
|
+
*
|
|
33
|
+
* # Input
|
|
34
|
+
* ```json
|
|
35
|
+
* [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* # Output
|
|
39
|
+
* `{ k, labels, centroids, wcss, iterations, cluster_sizes }`
|
|
40
|
+
*/
|
|
41
|
+
export function kmeans(data_json: any, k: number): any;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Runs Principal Component Analysis on row-major data.
|
|
45
|
+
*
|
|
46
|
+
* # Input
|
|
47
|
+
* ```json
|
|
48
|
+
* [[1.0, 0.1], [2.0, 0.2], [3.0, 0.3]]
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* # Output
|
|
52
|
+
* `{ n_components, n_features, eigenvalues, explained_variance_ratio, ... }`
|
|
53
|
+
*/
|
|
54
|
+
export function pca(data_json: any, n_components: number): any;
|
package/u_insight.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* @ts-self-types="./u_insight.d.ts" */
|
|
2
|
+
|
|
3
|
+
import * as wasm from "./u_insight_bg.wasm";
|
|
4
|
+
import { __wbg_set_wasm } from "./u_insight_bg.js";
|
|
5
|
+
__wbg_set_wasm(wasm);
|
|
6
|
+
wasm.__wbindgen_start();
|
|
7
|
+
export {
|
|
8
|
+
correlation_matrix, describe, kmeans, pca
|
|
9
|
+
} from "./u_insight_bg.js";
|
package/u_insight_bg.js
ADDED
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes a Pearson correlation matrix for a column-major dataset.
|
|
3
|
+
*
|
|
4
|
+
* # Input
|
|
5
|
+
* ```json
|
|
6
|
+
* { "col1": [1.0, 2.0, 3.0], "col2": [4.0, 5.0, 6.0] }
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* # Output
|
|
10
|
+
* `{ names, matrix (flattened n×n), n, high_pairs }`
|
|
11
|
+
* @param {any} data_json
|
|
12
|
+
* @returns {any}
|
|
13
|
+
*/
|
|
14
|
+
export function correlation_matrix(data_json) {
|
|
15
|
+
const ret = wasm.correlation_matrix(data_json);
|
|
16
|
+
if (ret[2]) {
|
|
17
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
18
|
+
}
|
|
19
|
+
return takeFromExternrefTable0(ret[0]);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Returns descriptive statistics for each column in a column-major dataset.
|
|
24
|
+
*
|
|
25
|
+
* # Input
|
|
26
|
+
* ```json
|
|
27
|
+
* { "col1": [1.0, 2.0, 3.0], "col2": [4.0, 5.0, 6.0] }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* # Output
|
|
31
|
+
* Array of column profile objects, one per column.
|
|
32
|
+
* @param {any} data_json
|
|
33
|
+
* @returns {any}
|
|
34
|
+
*/
|
|
35
|
+
export function describe(data_json) {
|
|
36
|
+
const ret = wasm.describe(data_json);
|
|
37
|
+
if (ret[2]) {
|
|
38
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
39
|
+
}
|
|
40
|
+
return takeFromExternrefTable0(ret[0]);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Runs K-Means++ clustering on row-major data.
|
|
45
|
+
*
|
|
46
|
+
* # Input
|
|
47
|
+
* ```json
|
|
48
|
+
* [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* # Output
|
|
52
|
+
* `{ k, labels, centroids, wcss, iterations, cluster_sizes }`
|
|
53
|
+
* @param {any} data_json
|
|
54
|
+
* @param {number} k
|
|
55
|
+
* @returns {any}
|
|
56
|
+
*/
|
|
57
|
+
export function kmeans(data_json, k) {
|
|
58
|
+
const ret = wasm.kmeans(data_json, k);
|
|
59
|
+
if (ret[2]) {
|
|
60
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
61
|
+
}
|
|
62
|
+
return takeFromExternrefTable0(ret[0]);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Runs Principal Component Analysis on row-major data.
|
|
67
|
+
*
|
|
68
|
+
* # Input
|
|
69
|
+
* ```json
|
|
70
|
+
* [[1.0, 0.1], [2.0, 0.2], [3.0, 0.3]]
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* # Output
|
|
74
|
+
* `{ n_components, n_features, eigenvalues, explained_variance_ratio, ... }`
|
|
75
|
+
* @param {any} data_json
|
|
76
|
+
* @param {number} n_components
|
|
77
|
+
* @returns {any}
|
|
78
|
+
*/
|
|
79
|
+
export function pca(data_json, n_components) {
|
|
80
|
+
const ret = wasm.pca(data_json, n_components);
|
|
81
|
+
if (ret[2]) {
|
|
82
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
83
|
+
}
|
|
84
|
+
return takeFromExternrefTable0(ret[0]);
|
|
85
|
+
}
|
|
86
|
+
export function __wbg_Error_83742b46f01ce22d(arg0, arg1) {
|
|
87
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
88
|
+
return ret;
|
|
89
|
+
}
|
|
90
|
+
export function __wbg_String_8564e559799eccda(arg0, arg1) {
|
|
91
|
+
const ret = String(arg1);
|
|
92
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
93
|
+
const len1 = WASM_VECTOR_LEN;
|
|
94
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
95
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
96
|
+
}
|
|
97
|
+
export function __wbg___wbindgen_boolean_get_c0f3f60bac5a78d1(arg0) {
|
|
98
|
+
const v = arg0;
|
|
99
|
+
const ret = typeof(v) === 'boolean' ? v : undefined;
|
|
100
|
+
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
101
|
+
}
|
|
102
|
+
export function __wbg___wbindgen_debug_string_5398f5bb970e0daa(arg0, arg1) {
|
|
103
|
+
const ret = debugString(arg1);
|
|
104
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
105
|
+
const len1 = WASM_VECTOR_LEN;
|
|
106
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
107
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
108
|
+
}
|
|
109
|
+
export function __wbg___wbindgen_is_function_3c846841762788c1(arg0) {
|
|
110
|
+
const ret = typeof(arg0) === 'function';
|
|
111
|
+
return ret;
|
|
112
|
+
}
|
|
113
|
+
export function __wbg___wbindgen_is_object_781bc9f159099513(arg0) {
|
|
114
|
+
const val = arg0;
|
|
115
|
+
const ret = typeof(val) === 'object' && val !== null;
|
|
116
|
+
return ret;
|
|
117
|
+
}
|
|
118
|
+
export function __wbg___wbindgen_jsval_loose_eq_5bcc3bed3c69e72b(arg0, arg1) {
|
|
119
|
+
const ret = arg0 == arg1;
|
|
120
|
+
return ret;
|
|
121
|
+
}
|
|
122
|
+
export function __wbg___wbindgen_number_get_34bb9d9dcfa21373(arg0, arg1) {
|
|
123
|
+
const obj = arg1;
|
|
124
|
+
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
125
|
+
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
126
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
127
|
+
}
|
|
128
|
+
export function __wbg___wbindgen_string_get_395e606bd0ee4427(arg0, arg1) {
|
|
129
|
+
const obj = arg1;
|
|
130
|
+
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
131
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
132
|
+
var len1 = WASM_VECTOR_LEN;
|
|
133
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
134
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
135
|
+
}
|
|
136
|
+
export function __wbg___wbindgen_throw_6ddd609b62940d55(arg0, arg1) {
|
|
137
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
138
|
+
}
|
|
139
|
+
export function __wbg_call_e133b57c9155d22c() { return handleError(function (arg0, arg1) {
|
|
140
|
+
const ret = arg0.call(arg1);
|
|
141
|
+
return ret;
|
|
142
|
+
}, arguments); }
|
|
143
|
+
export function __wbg_done_08ce71ee07e3bd17(arg0) {
|
|
144
|
+
const ret = arg0.done;
|
|
145
|
+
return ret;
|
|
146
|
+
}
|
|
147
|
+
export function __wbg_entries_e8a20ff8c9757101(arg0) {
|
|
148
|
+
const ret = Object.entries(arg0);
|
|
149
|
+
return ret;
|
|
150
|
+
}
|
|
151
|
+
export function __wbg_get_326e41e095fb2575() { return handleError(function (arg0, arg1) {
|
|
152
|
+
const ret = Reflect.get(arg0, arg1);
|
|
153
|
+
return ret;
|
|
154
|
+
}, arguments); }
|
|
155
|
+
export function __wbg_get_a8ee5c45dabc1b3b(arg0, arg1) {
|
|
156
|
+
const ret = arg0[arg1 >>> 0];
|
|
157
|
+
return ret;
|
|
158
|
+
}
|
|
159
|
+
export function __wbg_get_unchecked_329cfe50afab7352(arg0, arg1) {
|
|
160
|
+
const ret = arg0[arg1 >>> 0];
|
|
161
|
+
return ret;
|
|
162
|
+
}
|
|
163
|
+
export function __wbg_instanceof_ArrayBuffer_101e2bf31071a9f6(arg0) {
|
|
164
|
+
let result;
|
|
165
|
+
try {
|
|
166
|
+
result = arg0 instanceof ArrayBuffer;
|
|
167
|
+
} catch (_) {
|
|
168
|
+
result = false;
|
|
169
|
+
}
|
|
170
|
+
const ret = result;
|
|
171
|
+
return ret;
|
|
172
|
+
}
|
|
173
|
+
export function __wbg_instanceof_Uint8Array_740438561a5b956d(arg0) {
|
|
174
|
+
let result;
|
|
175
|
+
try {
|
|
176
|
+
result = arg0 instanceof Uint8Array;
|
|
177
|
+
} catch (_) {
|
|
178
|
+
result = false;
|
|
179
|
+
}
|
|
180
|
+
const ret = result;
|
|
181
|
+
return ret;
|
|
182
|
+
}
|
|
183
|
+
export function __wbg_isArray_33b91feb269ff46e(arg0) {
|
|
184
|
+
const ret = Array.isArray(arg0);
|
|
185
|
+
return ret;
|
|
186
|
+
}
|
|
187
|
+
export function __wbg_iterator_d8f549ec8fb061b1() {
|
|
188
|
+
const ret = Symbol.iterator;
|
|
189
|
+
return ret;
|
|
190
|
+
}
|
|
191
|
+
export function __wbg_length_b3416cf66a5452c8(arg0) {
|
|
192
|
+
const ret = arg0.length;
|
|
193
|
+
return ret;
|
|
194
|
+
}
|
|
195
|
+
export function __wbg_length_ea16607d7b61445b(arg0) {
|
|
196
|
+
const ret = arg0.length;
|
|
197
|
+
return ret;
|
|
198
|
+
}
|
|
199
|
+
export function __wbg_new_5f486cdf45a04d78(arg0) {
|
|
200
|
+
const ret = new Uint8Array(arg0);
|
|
201
|
+
return ret;
|
|
202
|
+
}
|
|
203
|
+
export function __wbg_new_a70fbab9066b301f() {
|
|
204
|
+
const ret = new Array();
|
|
205
|
+
return ret;
|
|
206
|
+
}
|
|
207
|
+
export function __wbg_new_ab79df5bd7c26067() {
|
|
208
|
+
const ret = new Object();
|
|
209
|
+
return ret;
|
|
210
|
+
}
|
|
211
|
+
export function __wbg_next_11b99ee6237339e3() { return handleError(function (arg0) {
|
|
212
|
+
const ret = arg0.next();
|
|
213
|
+
return ret;
|
|
214
|
+
}, arguments); }
|
|
215
|
+
export function __wbg_next_e01a967809d1aa68(arg0) {
|
|
216
|
+
const ret = arg0.next;
|
|
217
|
+
return ret;
|
|
218
|
+
}
|
|
219
|
+
export function __wbg_prototypesetcall_d62e5099504357e6(arg0, arg1, arg2) {
|
|
220
|
+
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
221
|
+
}
|
|
222
|
+
export function __wbg_set_282384002438957f(arg0, arg1, arg2) {
|
|
223
|
+
arg0[arg1 >>> 0] = arg2;
|
|
224
|
+
}
|
|
225
|
+
export function __wbg_set_6be42768c690e380(arg0, arg1, arg2) {
|
|
226
|
+
arg0[arg1] = arg2;
|
|
227
|
+
}
|
|
228
|
+
export function __wbg_value_21fc78aab0322612(arg0) {
|
|
229
|
+
const ret = arg0.value;
|
|
230
|
+
return ret;
|
|
231
|
+
}
|
|
232
|
+
export function __wbindgen_cast_0000000000000001(arg0) {
|
|
233
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
234
|
+
const ret = arg0;
|
|
235
|
+
return ret;
|
|
236
|
+
}
|
|
237
|
+
export function __wbindgen_cast_0000000000000002(arg0, arg1) {
|
|
238
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
239
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
240
|
+
return ret;
|
|
241
|
+
}
|
|
242
|
+
export function __wbindgen_cast_0000000000000003(arg0) {
|
|
243
|
+
// Cast intrinsic for `U64 -> Externref`.
|
|
244
|
+
const ret = BigInt.asUintN(64, arg0);
|
|
245
|
+
return ret;
|
|
246
|
+
}
|
|
247
|
+
export function __wbindgen_init_externref_table() {
|
|
248
|
+
const table = wasm.__wbindgen_externrefs;
|
|
249
|
+
const offset = table.grow(4);
|
|
250
|
+
table.set(0, undefined);
|
|
251
|
+
table.set(offset + 0, undefined);
|
|
252
|
+
table.set(offset + 1, null);
|
|
253
|
+
table.set(offset + 2, true);
|
|
254
|
+
table.set(offset + 3, false);
|
|
255
|
+
}
|
|
256
|
+
function addToExternrefTable0(obj) {
|
|
257
|
+
const idx = wasm.__externref_table_alloc();
|
|
258
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
259
|
+
return idx;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function debugString(val) {
|
|
263
|
+
// primitive types
|
|
264
|
+
const type = typeof val;
|
|
265
|
+
if (type == 'number' || type == 'boolean' || val == null) {
|
|
266
|
+
return `${val}`;
|
|
267
|
+
}
|
|
268
|
+
if (type == 'string') {
|
|
269
|
+
return `"${val}"`;
|
|
270
|
+
}
|
|
271
|
+
if (type == 'symbol') {
|
|
272
|
+
const description = val.description;
|
|
273
|
+
if (description == null) {
|
|
274
|
+
return 'Symbol';
|
|
275
|
+
} else {
|
|
276
|
+
return `Symbol(${description})`;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
if (type == 'function') {
|
|
280
|
+
const name = val.name;
|
|
281
|
+
if (typeof name == 'string' && name.length > 0) {
|
|
282
|
+
return `Function(${name})`;
|
|
283
|
+
} else {
|
|
284
|
+
return 'Function';
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
// objects
|
|
288
|
+
if (Array.isArray(val)) {
|
|
289
|
+
const length = val.length;
|
|
290
|
+
let debug = '[';
|
|
291
|
+
if (length > 0) {
|
|
292
|
+
debug += debugString(val[0]);
|
|
293
|
+
}
|
|
294
|
+
for(let i = 1; i < length; i++) {
|
|
295
|
+
debug += ', ' + debugString(val[i]);
|
|
296
|
+
}
|
|
297
|
+
debug += ']';
|
|
298
|
+
return debug;
|
|
299
|
+
}
|
|
300
|
+
// Test for built-in
|
|
301
|
+
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
302
|
+
let className;
|
|
303
|
+
if (builtInMatches && builtInMatches.length > 1) {
|
|
304
|
+
className = builtInMatches[1];
|
|
305
|
+
} else {
|
|
306
|
+
// Failed to match the standard '[object ClassName]'
|
|
307
|
+
return toString.call(val);
|
|
308
|
+
}
|
|
309
|
+
if (className == 'Object') {
|
|
310
|
+
// we're a user defined class or Object
|
|
311
|
+
// JSON.stringify avoids problems with cycles, and is generally much
|
|
312
|
+
// easier than looping through ownProperties of `val`.
|
|
313
|
+
try {
|
|
314
|
+
return 'Object(' + JSON.stringify(val) + ')';
|
|
315
|
+
} catch (_) {
|
|
316
|
+
return 'Object';
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
// errors
|
|
320
|
+
if (val instanceof Error) {
|
|
321
|
+
return `${val.name}: ${val.message}\n${val.stack}`;
|
|
322
|
+
}
|
|
323
|
+
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
324
|
+
return className;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
328
|
+
ptr = ptr >>> 0;
|
|
329
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
let cachedDataViewMemory0 = null;
|
|
333
|
+
function getDataViewMemory0() {
|
|
334
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
335
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
336
|
+
}
|
|
337
|
+
return cachedDataViewMemory0;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function getStringFromWasm0(ptr, len) {
|
|
341
|
+
ptr = ptr >>> 0;
|
|
342
|
+
return decodeText(ptr, len);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
let cachedUint8ArrayMemory0 = null;
|
|
346
|
+
function getUint8ArrayMemory0() {
|
|
347
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
348
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
349
|
+
}
|
|
350
|
+
return cachedUint8ArrayMemory0;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function handleError(f, args) {
|
|
354
|
+
try {
|
|
355
|
+
return f.apply(this, args);
|
|
356
|
+
} catch (e) {
|
|
357
|
+
const idx = addToExternrefTable0(e);
|
|
358
|
+
wasm.__wbindgen_exn_store(idx);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function isLikeNone(x) {
|
|
363
|
+
return x === undefined || x === null;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
367
|
+
if (realloc === undefined) {
|
|
368
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
369
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
370
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
371
|
+
WASM_VECTOR_LEN = buf.length;
|
|
372
|
+
return ptr;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
let len = arg.length;
|
|
376
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
377
|
+
|
|
378
|
+
const mem = getUint8ArrayMemory0();
|
|
379
|
+
|
|
380
|
+
let offset = 0;
|
|
381
|
+
|
|
382
|
+
for (; offset < len; offset++) {
|
|
383
|
+
const code = arg.charCodeAt(offset);
|
|
384
|
+
if (code > 0x7F) break;
|
|
385
|
+
mem[ptr + offset] = code;
|
|
386
|
+
}
|
|
387
|
+
if (offset !== len) {
|
|
388
|
+
if (offset !== 0) {
|
|
389
|
+
arg = arg.slice(offset);
|
|
390
|
+
}
|
|
391
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
392
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
393
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
394
|
+
|
|
395
|
+
offset += ret.written;
|
|
396
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
WASM_VECTOR_LEN = offset;
|
|
400
|
+
return ptr;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function takeFromExternrefTable0(idx) {
|
|
404
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
405
|
+
wasm.__externref_table_dealloc(idx);
|
|
406
|
+
return value;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
410
|
+
cachedTextDecoder.decode();
|
|
411
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
412
|
+
let numBytesDecoded = 0;
|
|
413
|
+
function decodeText(ptr, len) {
|
|
414
|
+
numBytesDecoded += len;
|
|
415
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
416
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
417
|
+
cachedTextDecoder.decode();
|
|
418
|
+
numBytesDecoded = len;
|
|
419
|
+
}
|
|
420
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
const cachedTextEncoder = new TextEncoder();
|
|
424
|
+
|
|
425
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
426
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
427
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
428
|
+
view.set(buf);
|
|
429
|
+
return {
|
|
430
|
+
read: arg.length,
|
|
431
|
+
written: buf.length
|
|
432
|
+
};
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
let WASM_VECTOR_LEN = 0;
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
let wasm;
|
|
440
|
+
export function __wbg_set_wasm(val) {
|
|
441
|
+
wasm = val;
|
|
442
|
+
}
|
|
Binary file
|