ts-classify 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/README.md +169 -0
- package/package.json +21 -0
- package/ts_classify.d.ts +174 -0
- package/ts_classify.js +564 -0
- package/ts_classify_bg.wasm +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# SVM
|
|
2
|
+
|
|
3
|
+
A fast Support Vector Machine implementation in Rust, targeting both native and WebAssembly.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Binary SVM** with two solvers:
|
|
8
|
+
- **Coordinate Descent** (default) - O(N) per pass, fast for large datasets
|
|
9
|
+
- **SMO** - O(N²), useful for kernel SVMs (future)
|
|
10
|
+
- **Multiclass classification**:
|
|
11
|
+
- **One-vs-Rest (OvR)** - K classifiers for K classes, fast prediction
|
|
12
|
+
- **One-vs-One (OvO)** - K(K-1)/2 classifiers, often more accurate
|
|
13
|
+
- **Sparse vectors** - efficient for high-dimensional data (text, trigrams)
|
|
14
|
+
- **Parallel training** via rayon (native only)
|
|
15
|
+
- **Binary serialization** via bincode
|
|
16
|
+
- **WebAssembly support** with JS-friendly API
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```toml
|
|
21
|
+
[dependencies]
|
|
22
|
+
svm = { path = "." }
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### Binary SVM
|
|
28
|
+
|
|
29
|
+
```rust
|
|
30
|
+
use svm::{SVM, SparseVec};
|
|
31
|
+
|
|
32
|
+
// Sparse format: Vec<(index, value)>
|
|
33
|
+
let samples: Vec<SparseVec> = vec![
|
|
34
|
+
vec![(0, -2.0), (1, 0.0)],
|
|
35
|
+
vec![(0, -1.0), (1, 1.0)],
|
|
36
|
+
vec![(0, 1.0), (1, 0.0)],
|
|
37
|
+
vec![(0, 2.0), (1, 1.0)],
|
|
38
|
+
];
|
|
39
|
+
let labels = vec![-1.0, -1.0, 1.0, 1.0];
|
|
40
|
+
|
|
41
|
+
let mut svm = SVM::new();
|
|
42
|
+
svm.train_sparse(&samples, &labels);
|
|
43
|
+
|
|
44
|
+
assert_eq!(svm.predict_sparse(&[(0, -3.0)]), -1.0);
|
|
45
|
+
assert_eq!(svm.predict_sparse(&[(0, 3.0)]), 1.0);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Multiclass (One-vs-Rest)
|
|
49
|
+
|
|
50
|
+
```rust
|
|
51
|
+
use svm::{OneVsRestSVM, SparseVec};
|
|
52
|
+
|
|
53
|
+
let samples: Vec<SparseVec> = vec![
|
|
54
|
+
vec![(0, -2.0), (1, -2.0)], // class 0
|
|
55
|
+
vec![(0, 2.0), (1, -2.0)], // class 1
|
|
56
|
+
vec![(0, 0.0), (1, 2.0)], // class 2
|
|
57
|
+
// ... more samples
|
|
58
|
+
];
|
|
59
|
+
let labels = vec![0, 1, 2, /* ... */];
|
|
60
|
+
|
|
61
|
+
let mut svm = OneVsRestSVM::new();
|
|
62
|
+
svm.train_sparse(&samples, &labels);
|
|
63
|
+
|
|
64
|
+
let predicted_class = svm.predict_sparse(&[(0, 0.0), (1, 3.0)]);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Custom Configuration
|
|
68
|
+
|
|
69
|
+
```rust
|
|
70
|
+
use svm::{SVM, TrainConfig, Solver};
|
|
71
|
+
|
|
72
|
+
let config = TrainConfig::coordinate_descent()
|
|
73
|
+
.with_c(0.5) // regularization (default: 1.0)
|
|
74
|
+
.with_max_iter(500) // max iterations (default: 1000)
|
|
75
|
+
.with_tol(0.001); // tolerance (default: 0.01)
|
|
76
|
+
|
|
77
|
+
let mut svm = SVM::new();
|
|
78
|
+
svm.train_sparse_with_config(&samples, &labels, &config);
|
|
79
|
+
|
|
80
|
+
// Or use SMO solver
|
|
81
|
+
let config = TrainConfig::smo()
|
|
82
|
+
.with_c(1.0)
|
|
83
|
+
.with_max_iter(10000);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Serialization
|
|
87
|
+
|
|
88
|
+
```rust
|
|
89
|
+
// Save
|
|
90
|
+
let bytes = svm.to_bytes()?;
|
|
91
|
+
std::fs::write("model.bin", &bytes)?;
|
|
92
|
+
|
|
93
|
+
// Load
|
|
94
|
+
let bytes = std::fs::read("model.bin")?;
|
|
95
|
+
let svm = SVM::from_bytes(&bytes)?;
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## WebAssembly
|
|
99
|
+
|
|
100
|
+
Build for WASM (without parallel feature):
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
cargo build --release --target wasm32-unknown-unknown --no-default-features
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Or use wasm-pack:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
wasm-pack build --target web --no-default-features
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### JavaScript API
|
|
113
|
+
|
|
114
|
+
```javascript
|
|
115
|
+
import { JsOneVsRestSVM } from 'svm';
|
|
116
|
+
|
|
117
|
+
const svm = new JsOneVsRestSVM();
|
|
118
|
+
|
|
119
|
+
// Flat sparse format: [idx, val, idx, val, ...]
|
|
120
|
+
const sampleFlat = new Float64Array([0, -2.0, 1, 0.0]); // single sample
|
|
121
|
+
const samplesFlat = new Float64Array([
|
|
122
|
+
0, -2.0, 1, 0.0, // sample 0: 2 pairs
|
|
123
|
+
0, 1.0, 1, 1.0, // sample 1: 2 pairs
|
|
124
|
+
]);
|
|
125
|
+
const sampleLengths = new Uint32Array([2, 2]); // pairs per sample
|
|
126
|
+
const labels = new Int32Array([0, 1]);
|
|
127
|
+
|
|
128
|
+
svm.train(samplesFlat, sampleLengths, labels);
|
|
129
|
+
|
|
130
|
+
const prediction = svm.predict(sampleFlat);
|
|
131
|
+
|
|
132
|
+
// Serialize/deserialize
|
|
133
|
+
const bytes = svm.to_bytes();
|
|
134
|
+
const loaded = JsOneVsRestSVM.from_bytes(bytes);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Performance
|
|
138
|
+
|
|
139
|
+
Coordinate descent vs SMO on 50-class OvR:
|
|
140
|
+
|
|
141
|
+
| Solver | Train Time |
|
|
142
|
+
|--------|------------|
|
|
143
|
+
| Coordinate Descent | 6ms |
|
|
144
|
+
| SMO | 29s |
|
|
145
|
+
|
|
146
|
+
Scaling (coordinate descent, OvR):
|
|
147
|
+
|
|
148
|
+
| Classes | Classifiers | Train | Predict |
|
|
149
|
+
|---------|-------------|-------|---------|
|
|
150
|
+
| 10 | 10 | 511µs | 144ns |
|
|
151
|
+
| 50 | 50 | 560µs | 743ns |
|
|
152
|
+
| 100 | 100 | 1.4ms | 1.6µs |
|
|
153
|
+
| 5000 | 5000 | ~50-100ms | ~80µs |
|
|
154
|
+
|
|
155
|
+
## Feature Flags
|
|
156
|
+
|
|
157
|
+
- `parallel` (default) - Enable parallel training via rayon. Disable for WASM.
|
|
158
|
+
|
|
159
|
+
```toml
|
|
160
|
+
# Native with parallel
|
|
161
|
+
svm = { path = "." }
|
|
162
|
+
|
|
163
|
+
# WASM (no parallel)
|
|
164
|
+
svm = { path = ".", default-features = false }
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## License
|
|
168
|
+
|
|
169
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ts-classify",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"description": "Fast text classification with SVM and Nearest Centroid (WebAssembly)",
|
|
5
|
+
"version": "0.1.0",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/serialexp/ts-classify"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"ts_classify_bg.wasm",
|
|
13
|
+
"ts_classify.js",
|
|
14
|
+
"ts_classify.d.ts"
|
|
15
|
+
],
|
|
16
|
+
"main": "ts_classify.js",
|
|
17
|
+
"types": "ts_classify.d.ts",
|
|
18
|
+
"sideEffects": [
|
|
19
|
+
"./snippets/*"
|
|
20
|
+
]
|
|
21
|
+
}
|
package/ts_classify.d.ts
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* JS-friendly wrapper for Nearest Centroid classifier.
|
|
6
|
+
*/
|
|
7
|
+
export class JsNearestCentroid {
|
|
8
|
+
free(): void;
|
|
9
|
+
[Symbol.dispose](): void;
|
|
10
|
+
/**
|
|
11
|
+
* Deserialize from bytes.
|
|
12
|
+
*/
|
|
13
|
+
static from_bytes(bytes: Uint8Array): JsNearestCentroid;
|
|
14
|
+
/**
|
|
15
|
+
* Get cosine similarities to all class centroids.
|
|
16
|
+
* Returns flat array: [class0, similarity0, class1, similarity1, ...]
|
|
17
|
+
*/
|
|
18
|
+
margins(sample_flat: Float64Array): Float64Array;
|
|
19
|
+
constructor();
|
|
20
|
+
/**
|
|
21
|
+
* Number of classes.
|
|
22
|
+
*/
|
|
23
|
+
num_classes(): number;
|
|
24
|
+
/**
|
|
25
|
+
* Predict class for a single sparse sample.
|
|
26
|
+
*/
|
|
27
|
+
predict(sample_flat: Float64Array): number;
|
|
28
|
+
/**
|
|
29
|
+
* Serialize to bytes.
|
|
30
|
+
*/
|
|
31
|
+
to_bytes(): Uint8Array;
|
|
32
|
+
/**
|
|
33
|
+
* Train on sparse data.
|
|
34
|
+
* samples_flat: flattened sparse vectors [idx, val, idx, val, ...]
|
|
35
|
+
* sample_lengths: number of (idx, val) pairs per sample
|
|
36
|
+
* labels: integer class IDs (0, 1, 2, ...)
|
|
37
|
+
*/
|
|
38
|
+
train(samples_flat: Float64Array, sample_lengths: Uint32Array, labels: Int32Array): void;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* JS-friendly wrapper for One-vs-Rest multiclass SVM.
|
|
43
|
+
*/
|
|
44
|
+
export class JsOneVsRestSVM {
|
|
45
|
+
free(): void;
|
|
46
|
+
[Symbol.dispose](): void;
|
|
47
|
+
/**
|
|
48
|
+
* Deserialize from bytes.
|
|
49
|
+
*/
|
|
50
|
+
static from_bytes(bytes: Uint8Array): JsOneVsRestSVM;
|
|
51
|
+
/**
|
|
52
|
+
* Get margins for all classes.
|
|
53
|
+
* Returns flat array: [class0, margin0, class1, margin1, ...]
|
|
54
|
+
*/
|
|
55
|
+
margins(sample_flat: Float64Array): Float64Array;
|
|
56
|
+
constructor();
|
|
57
|
+
/**
|
|
58
|
+
* Number of classifiers.
|
|
59
|
+
*/
|
|
60
|
+
num_classifiers(): number;
|
|
61
|
+
/**
|
|
62
|
+
* Predict class for a single sparse sample.
|
|
63
|
+
*/
|
|
64
|
+
predict(sample_flat: Float64Array): number;
|
|
65
|
+
/**
|
|
66
|
+
* Serialize to bytes.
|
|
67
|
+
*/
|
|
68
|
+
to_bytes(): Uint8Array;
|
|
69
|
+
/**
|
|
70
|
+
* Train on sparse data.
|
|
71
|
+
* labels: integer class IDs (0, 1, 2, ...)
|
|
72
|
+
*/
|
|
73
|
+
train(samples_flat: Float64Array, sample_lengths: Uint32Array, labels: Int32Array): void;
|
|
74
|
+
/**
|
|
75
|
+
* Train with custom parameters.
|
|
76
|
+
*/
|
|
77
|
+
train_with_config(samples_flat: Float64Array, sample_lengths: Uint32Array, labels: Int32Array, use_smo: boolean, c: number, max_iter: number, tol: number): void;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* JS-friendly wrapper for binary SVM.
|
|
82
|
+
* Uses flat arrays for sparse vectors: [idx0, val0, idx1, val1, ...]
|
|
83
|
+
*/
|
|
84
|
+
export class JsSVM {
|
|
85
|
+
free(): void;
|
|
86
|
+
[Symbol.dispose](): void;
|
|
87
|
+
/**
|
|
88
|
+
* Deserialize from bytes.
|
|
89
|
+
*/
|
|
90
|
+
static from_bytes(bytes: Uint8Array): JsSVM;
|
|
91
|
+
/**
|
|
92
|
+
* Get the margin (decision value) for a sample.
|
|
93
|
+
*/
|
|
94
|
+
margin(sample_flat: Float64Array): number;
|
|
95
|
+
constructor();
|
|
96
|
+
/**
|
|
97
|
+
* Predict class for a single sparse sample.
|
|
98
|
+
* sample_flat: [idx, val, idx, val, ...]
|
|
99
|
+
*/
|
|
100
|
+
predict(sample_flat: Float64Array): number;
|
|
101
|
+
/**
|
|
102
|
+
* Serialize to bytes.
|
|
103
|
+
*/
|
|
104
|
+
to_bytes(): Uint8Array;
|
|
105
|
+
/**
|
|
106
|
+
* Train on sparse data.
|
|
107
|
+
* samples_flat: flattened sparse vectors [idx, val, idx, val, ...]
|
|
108
|
+
* sample_lengths: number of (idx, val) pairs per sample
|
|
109
|
+
* labels: -1.0 or 1.0 for each sample
|
|
110
|
+
*/
|
|
111
|
+
train(samples_flat: Float64Array, sample_lengths: Uint32Array, labels: Float64Array): void;
|
|
112
|
+
/**
|
|
113
|
+
* Train with custom parameters.
|
|
114
|
+
*/
|
|
115
|
+
train_with_config(samples_flat: Float64Array, sample_lengths: Uint32Array, labels: Float64Array, use_smo: boolean, c: number, max_iter: number, tol: number): void;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
119
|
+
|
|
120
|
+
export interface InitOutput {
|
|
121
|
+
readonly memory: WebAssembly.Memory;
|
|
122
|
+
readonly __wbg_jsnearestcentroid_free: (a: number, b: number) => void;
|
|
123
|
+
readonly __wbg_jsonevsrestsvm_free: (a: number, b: number) => void;
|
|
124
|
+
readonly __wbg_jssvm_free: (a: number, b: number) => void;
|
|
125
|
+
readonly jsnearestcentroid_from_bytes: (a: number, b: number) => [number, number, number];
|
|
126
|
+
readonly jsnearestcentroid_margins: (a: number, b: number, c: number) => [number, number];
|
|
127
|
+
readonly jsnearestcentroid_new: () => number;
|
|
128
|
+
readonly jsnearestcentroid_num_classes: (a: number) => number;
|
|
129
|
+
readonly jsnearestcentroid_predict: (a: number, b: number, c: number) => number;
|
|
130
|
+
readonly jsnearestcentroid_to_bytes: (a: number) => [number, number, number, number];
|
|
131
|
+
readonly jsnearestcentroid_train: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
132
|
+
readonly jsonevsrestsvm_from_bytes: (a: number, b: number) => [number, number, number];
|
|
133
|
+
readonly jsonevsrestsvm_margins: (a: number, b: number, c: number) => [number, number];
|
|
134
|
+
readonly jsonevsrestsvm_new: () => number;
|
|
135
|
+
readonly jsonevsrestsvm_num_classifiers: (a: number) => number;
|
|
136
|
+
readonly jsonevsrestsvm_predict: (a: number, b: number, c: number) => number;
|
|
137
|
+
readonly jsonevsrestsvm_to_bytes: (a: number) => [number, number, number, number];
|
|
138
|
+
readonly jsonevsrestsvm_train: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
139
|
+
readonly jsonevsrestsvm_train_with_config: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => void;
|
|
140
|
+
readonly jssvm_from_bytes: (a: number, b: number) => [number, number, number];
|
|
141
|
+
readonly jssvm_margin: (a: number, b: number, c: number) => number;
|
|
142
|
+
readonly jssvm_new: () => number;
|
|
143
|
+
readonly jssvm_predict: (a: number, b: number, c: number) => number;
|
|
144
|
+
readonly jssvm_to_bytes: (a: number) => [number, number, number, number];
|
|
145
|
+
readonly jssvm_train: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
146
|
+
readonly jssvm_train_with_config: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => void;
|
|
147
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
148
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
149
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
150
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
151
|
+
readonly __wbindgen_start: () => void;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
158
|
+
* a precompiled `WebAssembly.Module`.
|
|
159
|
+
*
|
|
160
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
161
|
+
*
|
|
162
|
+
* @returns {InitOutput}
|
|
163
|
+
*/
|
|
164
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
168
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
169
|
+
*
|
|
170
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
171
|
+
*
|
|
172
|
+
* @returns {Promise<InitOutput>}
|
|
173
|
+
*/
|
|
174
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
package/ts_classify.js
ADDED
|
@@ -0,0 +1,564 @@
|
|
|
1
|
+
/* @ts-self-types="./ts_classify.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* JS-friendly wrapper for Nearest Centroid classifier.
|
|
5
|
+
*/
|
|
6
|
+
export class JsNearestCentroid {
|
|
7
|
+
static __wrap(ptr) {
|
|
8
|
+
ptr = ptr >>> 0;
|
|
9
|
+
const obj = Object.create(JsNearestCentroid.prototype);
|
|
10
|
+
obj.__wbg_ptr = ptr;
|
|
11
|
+
JsNearestCentroidFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
__destroy_into_raw() {
|
|
15
|
+
const ptr = this.__wbg_ptr;
|
|
16
|
+
this.__wbg_ptr = 0;
|
|
17
|
+
JsNearestCentroidFinalization.unregister(this);
|
|
18
|
+
return ptr;
|
|
19
|
+
}
|
|
20
|
+
free() {
|
|
21
|
+
const ptr = this.__destroy_into_raw();
|
|
22
|
+
wasm.__wbg_jsnearestcentroid_free(ptr, 0);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Deserialize from bytes.
|
|
26
|
+
* @param {Uint8Array} bytes
|
|
27
|
+
* @returns {JsNearestCentroid}
|
|
28
|
+
*/
|
|
29
|
+
static from_bytes(bytes) {
|
|
30
|
+
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
31
|
+
const len0 = WASM_VECTOR_LEN;
|
|
32
|
+
const ret = wasm.jsnearestcentroid_from_bytes(ptr0, len0);
|
|
33
|
+
if (ret[2]) {
|
|
34
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
35
|
+
}
|
|
36
|
+
return JsNearestCentroid.__wrap(ret[0]);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get cosine similarities to all class centroids.
|
|
40
|
+
* Returns flat array: [class0, similarity0, class1, similarity1, ...]
|
|
41
|
+
* @param {Float64Array} sample_flat
|
|
42
|
+
* @returns {Float64Array}
|
|
43
|
+
*/
|
|
44
|
+
margins(sample_flat) {
|
|
45
|
+
const ptr0 = passArrayF64ToWasm0(sample_flat, wasm.__wbindgen_malloc);
|
|
46
|
+
const len0 = WASM_VECTOR_LEN;
|
|
47
|
+
const ret = wasm.jsnearestcentroid_margins(this.__wbg_ptr, ptr0, len0);
|
|
48
|
+
var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
|
|
49
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
|
|
50
|
+
return v2;
|
|
51
|
+
}
|
|
52
|
+
constructor() {
|
|
53
|
+
const ret = wasm.jsnearestcentroid_new();
|
|
54
|
+
this.__wbg_ptr = ret >>> 0;
|
|
55
|
+
JsNearestCentroidFinalization.register(this, this.__wbg_ptr, this);
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Number of classes.
|
|
60
|
+
* @returns {number}
|
|
61
|
+
*/
|
|
62
|
+
num_classes() {
|
|
63
|
+
const ret = wasm.jsnearestcentroid_num_classes(this.__wbg_ptr);
|
|
64
|
+
return ret >>> 0;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Predict class for a single sparse sample.
|
|
68
|
+
* @param {Float64Array} sample_flat
|
|
69
|
+
* @returns {number}
|
|
70
|
+
*/
|
|
71
|
+
predict(sample_flat) {
|
|
72
|
+
const ptr0 = passArrayF64ToWasm0(sample_flat, wasm.__wbindgen_malloc);
|
|
73
|
+
const len0 = WASM_VECTOR_LEN;
|
|
74
|
+
const ret = wasm.jsnearestcentroid_predict(this.__wbg_ptr, ptr0, len0);
|
|
75
|
+
return ret;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Serialize to bytes.
|
|
79
|
+
* @returns {Uint8Array}
|
|
80
|
+
*/
|
|
81
|
+
to_bytes() {
|
|
82
|
+
const ret = wasm.jsnearestcentroid_to_bytes(this.__wbg_ptr);
|
|
83
|
+
if (ret[3]) {
|
|
84
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
85
|
+
}
|
|
86
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
87
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
88
|
+
return v1;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Train on sparse data.
|
|
92
|
+
* samples_flat: flattened sparse vectors [idx, val, idx, val, ...]
|
|
93
|
+
* sample_lengths: number of (idx, val) pairs per sample
|
|
94
|
+
* labels: integer class IDs (0, 1, 2, ...)
|
|
95
|
+
* @param {Float64Array} samples_flat
|
|
96
|
+
* @param {Uint32Array} sample_lengths
|
|
97
|
+
* @param {Int32Array} labels
|
|
98
|
+
*/
|
|
99
|
+
train(samples_flat, sample_lengths, labels) {
|
|
100
|
+
const ptr0 = passArrayF64ToWasm0(samples_flat, wasm.__wbindgen_malloc);
|
|
101
|
+
const len0 = WASM_VECTOR_LEN;
|
|
102
|
+
const ptr1 = passArray32ToWasm0(sample_lengths, wasm.__wbindgen_malloc);
|
|
103
|
+
const len1 = WASM_VECTOR_LEN;
|
|
104
|
+
const ptr2 = passArray32ToWasm0(labels, wasm.__wbindgen_malloc);
|
|
105
|
+
const len2 = WASM_VECTOR_LEN;
|
|
106
|
+
wasm.jsnearestcentroid_train(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (Symbol.dispose) JsNearestCentroid.prototype[Symbol.dispose] = JsNearestCentroid.prototype.free;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* JS-friendly wrapper for One-vs-Rest multiclass SVM.
|
|
113
|
+
*/
|
|
114
|
+
export class JsOneVsRestSVM {
|
|
115
|
+
static __wrap(ptr) {
|
|
116
|
+
ptr = ptr >>> 0;
|
|
117
|
+
const obj = Object.create(JsOneVsRestSVM.prototype);
|
|
118
|
+
obj.__wbg_ptr = ptr;
|
|
119
|
+
JsOneVsRestSVMFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
120
|
+
return obj;
|
|
121
|
+
}
|
|
122
|
+
__destroy_into_raw() {
|
|
123
|
+
const ptr = this.__wbg_ptr;
|
|
124
|
+
this.__wbg_ptr = 0;
|
|
125
|
+
JsOneVsRestSVMFinalization.unregister(this);
|
|
126
|
+
return ptr;
|
|
127
|
+
}
|
|
128
|
+
free() {
|
|
129
|
+
const ptr = this.__destroy_into_raw();
|
|
130
|
+
wasm.__wbg_jsonevsrestsvm_free(ptr, 0);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Deserialize from bytes.
|
|
134
|
+
* @param {Uint8Array} bytes
|
|
135
|
+
* @returns {JsOneVsRestSVM}
|
|
136
|
+
*/
|
|
137
|
+
static from_bytes(bytes) {
|
|
138
|
+
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
139
|
+
const len0 = WASM_VECTOR_LEN;
|
|
140
|
+
const ret = wasm.jsonevsrestsvm_from_bytes(ptr0, len0);
|
|
141
|
+
if (ret[2]) {
|
|
142
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
143
|
+
}
|
|
144
|
+
return JsOneVsRestSVM.__wrap(ret[0]);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Get margins for all classes.
|
|
148
|
+
* Returns flat array: [class0, margin0, class1, margin1, ...]
|
|
149
|
+
* @param {Float64Array} sample_flat
|
|
150
|
+
* @returns {Float64Array}
|
|
151
|
+
*/
|
|
152
|
+
margins(sample_flat) {
|
|
153
|
+
const ptr0 = passArrayF64ToWasm0(sample_flat, wasm.__wbindgen_malloc);
|
|
154
|
+
const len0 = WASM_VECTOR_LEN;
|
|
155
|
+
const ret = wasm.jsonevsrestsvm_margins(this.__wbg_ptr, ptr0, len0);
|
|
156
|
+
var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
|
|
157
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
|
|
158
|
+
return v2;
|
|
159
|
+
}
|
|
160
|
+
constructor() {
|
|
161
|
+
const ret = wasm.jsonevsrestsvm_new();
|
|
162
|
+
this.__wbg_ptr = ret >>> 0;
|
|
163
|
+
JsOneVsRestSVMFinalization.register(this, this.__wbg_ptr, this);
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Number of classifiers.
|
|
168
|
+
* @returns {number}
|
|
169
|
+
*/
|
|
170
|
+
num_classifiers() {
|
|
171
|
+
const ret = wasm.jsonevsrestsvm_num_classifiers(this.__wbg_ptr);
|
|
172
|
+
return ret >>> 0;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Predict class for a single sparse sample.
|
|
176
|
+
* @param {Float64Array} sample_flat
|
|
177
|
+
* @returns {number}
|
|
178
|
+
*/
|
|
179
|
+
predict(sample_flat) {
|
|
180
|
+
const ptr0 = passArrayF64ToWasm0(sample_flat, wasm.__wbindgen_malloc);
|
|
181
|
+
const len0 = WASM_VECTOR_LEN;
|
|
182
|
+
const ret = wasm.jsonevsrestsvm_predict(this.__wbg_ptr, ptr0, len0);
|
|
183
|
+
return ret;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Serialize to bytes.
|
|
187
|
+
* @returns {Uint8Array}
|
|
188
|
+
*/
|
|
189
|
+
to_bytes() {
|
|
190
|
+
const ret = wasm.jsonevsrestsvm_to_bytes(this.__wbg_ptr);
|
|
191
|
+
if (ret[3]) {
|
|
192
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
193
|
+
}
|
|
194
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
195
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
196
|
+
return v1;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Train on sparse data.
|
|
200
|
+
* labels: integer class IDs (0, 1, 2, ...)
|
|
201
|
+
* @param {Float64Array} samples_flat
|
|
202
|
+
* @param {Uint32Array} sample_lengths
|
|
203
|
+
* @param {Int32Array} labels
|
|
204
|
+
*/
|
|
205
|
+
train(samples_flat, sample_lengths, labels) {
|
|
206
|
+
const ptr0 = passArrayF64ToWasm0(samples_flat, wasm.__wbindgen_malloc);
|
|
207
|
+
const len0 = WASM_VECTOR_LEN;
|
|
208
|
+
const ptr1 = passArray32ToWasm0(sample_lengths, wasm.__wbindgen_malloc);
|
|
209
|
+
const len1 = WASM_VECTOR_LEN;
|
|
210
|
+
const ptr2 = passArray32ToWasm0(labels, wasm.__wbindgen_malloc);
|
|
211
|
+
const len2 = WASM_VECTOR_LEN;
|
|
212
|
+
wasm.jsonevsrestsvm_train(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Train with custom parameters.
|
|
216
|
+
* @param {Float64Array} samples_flat
|
|
217
|
+
* @param {Uint32Array} sample_lengths
|
|
218
|
+
* @param {Int32Array} labels
|
|
219
|
+
* @param {boolean} use_smo
|
|
220
|
+
* @param {number} c
|
|
221
|
+
* @param {number} max_iter
|
|
222
|
+
* @param {number} tol
|
|
223
|
+
*/
|
|
224
|
+
train_with_config(samples_flat, sample_lengths, labels, use_smo, c, max_iter, tol) {
|
|
225
|
+
const ptr0 = passArrayF64ToWasm0(samples_flat, wasm.__wbindgen_malloc);
|
|
226
|
+
const len0 = WASM_VECTOR_LEN;
|
|
227
|
+
const ptr1 = passArray32ToWasm0(sample_lengths, wasm.__wbindgen_malloc);
|
|
228
|
+
const len1 = WASM_VECTOR_LEN;
|
|
229
|
+
const ptr2 = passArray32ToWasm0(labels, wasm.__wbindgen_malloc);
|
|
230
|
+
const len2 = WASM_VECTOR_LEN;
|
|
231
|
+
wasm.jsonevsrestsvm_train_with_config(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, use_smo, c, max_iter, tol);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (Symbol.dispose) JsOneVsRestSVM.prototype[Symbol.dispose] = JsOneVsRestSVM.prototype.free;
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* JS-friendly wrapper for binary SVM.
|
|
238
|
+
* Uses flat arrays for sparse vectors: [idx0, val0, idx1, val1, ...]
|
|
239
|
+
*/
|
|
240
|
+
export class JsSVM {
|
|
241
|
+
static __wrap(ptr) {
|
|
242
|
+
ptr = ptr >>> 0;
|
|
243
|
+
const obj = Object.create(JsSVM.prototype);
|
|
244
|
+
obj.__wbg_ptr = ptr;
|
|
245
|
+
JsSVMFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
246
|
+
return obj;
|
|
247
|
+
}
|
|
248
|
+
__destroy_into_raw() {
|
|
249
|
+
const ptr = this.__wbg_ptr;
|
|
250
|
+
this.__wbg_ptr = 0;
|
|
251
|
+
JsSVMFinalization.unregister(this);
|
|
252
|
+
return ptr;
|
|
253
|
+
}
|
|
254
|
+
free() {
|
|
255
|
+
const ptr = this.__destroy_into_raw();
|
|
256
|
+
wasm.__wbg_jssvm_free(ptr, 0);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Deserialize from bytes.
|
|
260
|
+
* @param {Uint8Array} bytes
|
|
261
|
+
* @returns {JsSVM}
|
|
262
|
+
*/
|
|
263
|
+
static from_bytes(bytes) {
|
|
264
|
+
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
265
|
+
const len0 = WASM_VECTOR_LEN;
|
|
266
|
+
const ret = wasm.jssvm_from_bytes(ptr0, len0);
|
|
267
|
+
if (ret[2]) {
|
|
268
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
269
|
+
}
|
|
270
|
+
return JsSVM.__wrap(ret[0]);
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Get the margin (decision value) for a sample.
|
|
274
|
+
* @param {Float64Array} sample_flat
|
|
275
|
+
* @returns {number}
|
|
276
|
+
*/
|
|
277
|
+
margin(sample_flat) {
|
|
278
|
+
const ptr0 = passArrayF64ToWasm0(sample_flat, wasm.__wbindgen_malloc);
|
|
279
|
+
const len0 = WASM_VECTOR_LEN;
|
|
280
|
+
const ret = wasm.jssvm_margin(this.__wbg_ptr, ptr0, len0);
|
|
281
|
+
return ret;
|
|
282
|
+
}
|
|
283
|
+
constructor() {
|
|
284
|
+
const ret = wasm.jssvm_new();
|
|
285
|
+
this.__wbg_ptr = ret >>> 0;
|
|
286
|
+
JsSVMFinalization.register(this, this.__wbg_ptr, this);
|
|
287
|
+
return this;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Predict class for a single sparse sample.
|
|
291
|
+
* sample_flat: [idx, val, idx, val, ...]
|
|
292
|
+
* @param {Float64Array} sample_flat
|
|
293
|
+
* @returns {number}
|
|
294
|
+
*/
|
|
295
|
+
predict(sample_flat) {
|
|
296
|
+
const ptr0 = passArrayF64ToWasm0(sample_flat, wasm.__wbindgen_malloc);
|
|
297
|
+
const len0 = WASM_VECTOR_LEN;
|
|
298
|
+
const ret = wasm.jssvm_predict(this.__wbg_ptr, ptr0, len0);
|
|
299
|
+
return ret;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Serialize to bytes.
|
|
303
|
+
* @returns {Uint8Array}
|
|
304
|
+
*/
|
|
305
|
+
to_bytes() {
|
|
306
|
+
const ret = wasm.jssvm_to_bytes(this.__wbg_ptr);
|
|
307
|
+
if (ret[3]) {
|
|
308
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
309
|
+
}
|
|
310
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
311
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
312
|
+
return v1;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Train on sparse data.
|
|
316
|
+
* samples_flat: flattened sparse vectors [idx, val, idx, val, ...]
|
|
317
|
+
* sample_lengths: number of (idx, val) pairs per sample
|
|
318
|
+
* labels: -1.0 or 1.0 for each sample
|
|
319
|
+
* @param {Float64Array} samples_flat
|
|
320
|
+
* @param {Uint32Array} sample_lengths
|
|
321
|
+
* @param {Float64Array} labels
|
|
322
|
+
*/
|
|
323
|
+
train(samples_flat, sample_lengths, labels) {
|
|
324
|
+
const ptr0 = passArrayF64ToWasm0(samples_flat, wasm.__wbindgen_malloc);
|
|
325
|
+
const len0 = WASM_VECTOR_LEN;
|
|
326
|
+
const ptr1 = passArray32ToWasm0(sample_lengths, wasm.__wbindgen_malloc);
|
|
327
|
+
const len1 = WASM_VECTOR_LEN;
|
|
328
|
+
const ptr2 = passArrayF64ToWasm0(labels, wasm.__wbindgen_malloc);
|
|
329
|
+
const len2 = WASM_VECTOR_LEN;
|
|
330
|
+
wasm.jssvm_train(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Train with custom parameters.
|
|
334
|
+
* @param {Float64Array} samples_flat
|
|
335
|
+
* @param {Uint32Array} sample_lengths
|
|
336
|
+
* @param {Float64Array} labels
|
|
337
|
+
* @param {boolean} use_smo
|
|
338
|
+
* @param {number} c
|
|
339
|
+
* @param {number} max_iter
|
|
340
|
+
* @param {number} tol
|
|
341
|
+
*/
|
|
342
|
+
train_with_config(samples_flat, sample_lengths, labels, use_smo, c, max_iter, tol) {
|
|
343
|
+
const ptr0 = passArrayF64ToWasm0(samples_flat, wasm.__wbindgen_malloc);
|
|
344
|
+
const len0 = WASM_VECTOR_LEN;
|
|
345
|
+
const ptr1 = passArray32ToWasm0(sample_lengths, wasm.__wbindgen_malloc);
|
|
346
|
+
const len1 = WASM_VECTOR_LEN;
|
|
347
|
+
const ptr2 = passArrayF64ToWasm0(labels, wasm.__wbindgen_malloc);
|
|
348
|
+
const len2 = WASM_VECTOR_LEN;
|
|
349
|
+
wasm.jssvm_train_with_config(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, use_smo, c, max_iter, tol);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
if (Symbol.dispose) JsSVM.prototype[Symbol.dispose] = JsSVM.prototype.free;
|
|
353
|
+
|
|
354
|
+
function __wbg_get_imports() {
|
|
355
|
+
const import0 = {
|
|
356
|
+
__proto__: null,
|
|
357
|
+
__wbg_Error_8c4e43fe74559d73: function(arg0, arg1) {
|
|
358
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
359
|
+
return ret;
|
|
360
|
+
},
|
|
361
|
+
__wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
|
|
362
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
363
|
+
},
|
|
364
|
+
__wbindgen_init_externref_table: function() {
|
|
365
|
+
const table = wasm.__wbindgen_externrefs;
|
|
366
|
+
const offset = table.grow(4);
|
|
367
|
+
table.set(0, undefined);
|
|
368
|
+
table.set(offset + 0, undefined);
|
|
369
|
+
table.set(offset + 1, null);
|
|
370
|
+
table.set(offset + 2, true);
|
|
371
|
+
table.set(offset + 3, false);
|
|
372
|
+
},
|
|
373
|
+
};
|
|
374
|
+
return {
|
|
375
|
+
__proto__: null,
|
|
376
|
+
"./ts_classify_bg.js": import0,
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const JsNearestCentroidFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
381
|
+
? { register: () => {}, unregister: () => {} }
|
|
382
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_jsnearestcentroid_free(ptr >>> 0, 1));
|
|
383
|
+
const JsOneVsRestSVMFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
384
|
+
? { register: () => {}, unregister: () => {} }
|
|
385
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_jsonevsrestsvm_free(ptr >>> 0, 1));
|
|
386
|
+
const JsSVMFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
387
|
+
? { register: () => {}, unregister: () => {} }
|
|
388
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_jssvm_free(ptr >>> 0, 1));
|
|
389
|
+
|
|
390
|
+
function getArrayF64FromWasm0(ptr, len) {
|
|
391
|
+
ptr = ptr >>> 0;
|
|
392
|
+
return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
396
|
+
ptr = ptr >>> 0;
|
|
397
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
let cachedFloat64ArrayMemory0 = null;
|
|
401
|
+
function getFloat64ArrayMemory0() {
|
|
402
|
+
if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
|
|
403
|
+
cachedFloat64ArrayMemory0 = new Float64Array(wasm.memory.buffer);
|
|
404
|
+
}
|
|
405
|
+
return cachedFloat64ArrayMemory0;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
function getStringFromWasm0(ptr, len) {
|
|
409
|
+
ptr = ptr >>> 0;
|
|
410
|
+
return decodeText(ptr, len);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
let cachedUint32ArrayMemory0 = null;
|
|
414
|
+
function getUint32ArrayMemory0() {
|
|
415
|
+
if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
|
|
416
|
+
cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
|
|
417
|
+
}
|
|
418
|
+
return cachedUint32ArrayMemory0;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
let cachedUint8ArrayMemory0 = null;
|
|
422
|
+
function getUint8ArrayMemory0() {
|
|
423
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
424
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
425
|
+
}
|
|
426
|
+
return cachedUint8ArrayMemory0;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function passArray32ToWasm0(arg, malloc) {
|
|
430
|
+
const ptr = malloc(arg.length * 4, 4) >>> 0;
|
|
431
|
+
getUint32ArrayMemory0().set(arg, ptr / 4);
|
|
432
|
+
WASM_VECTOR_LEN = arg.length;
|
|
433
|
+
return ptr;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
437
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
438
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
439
|
+
WASM_VECTOR_LEN = arg.length;
|
|
440
|
+
return ptr;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function passArrayF64ToWasm0(arg, malloc) {
|
|
444
|
+
const ptr = malloc(arg.length * 8, 8) >>> 0;
|
|
445
|
+
getFloat64ArrayMemory0().set(arg, ptr / 8);
|
|
446
|
+
WASM_VECTOR_LEN = arg.length;
|
|
447
|
+
return ptr;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
function takeFromExternrefTable0(idx) {
|
|
451
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
452
|
+
wasm.__externref_table_dealloc(idx);
|
|
453
|
+
return value;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
457
|
+
cachedTextDecoder.decode();
|
|
458
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
459
|
+
let numBytesDecoded = 0;
|
|
460
|
+
function decodeText(ptr, len) {
|
|
461
|
+
numBytesDecoded += len;
|
|
462
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
463
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
464
|
+
cachedTextDecoder.decode();
|
|
465
|
+
numBytesDecoded = len;
|
|
466
|
+
}
|
|
467
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
let WASM_VECTOR_LEN = 0;
|
|
471
|
+
|
|
472
|
+
let wasmModule, wasm;
|
|
473
|
+
function __wbg_finalize_init(instance, module) {
|
|
474
|
+
wasm = instance.exports;
|
|
475
|
+
wasmModule = module;
|
|
476
|
+
cachedFloat64ArrayMemory0 = null;
|
|
477
|
+
cachedUint32ArrayMemory0 = null;
|
|
478
|
+
cachedUint8ArrayMemory0 = null;
|
|
479
|
+
wasm.__wbindgen_start();
|
|
480
|
+
return wasm;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
async function __wbg_load(module, imports) {
|
|
484
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
485
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
486
|
+
try {
|
|
487
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
488
|
+
} catch (e) {
|
|
489
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
490
|
+
|
|
491
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
492
|
+
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);
|
|
493
|
+
|
|
494
|
+
} else { throw e; }
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
const bytes = await module.arrayBuffer();
|
|
499
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
500
|
+
} else {
|
|
501
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
502
|
+
|
|
503
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
504
|
+
return { instance, module };
|
|
505
|
+
} else {
|
|
506
|
+
return instance;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
function expectedResponseType(type) {
|
|
511
|
+
switch (type) {
|
|
512
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
513
|
+
}
|
|
514
|
+
return false;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
function initSync(module) {
|
|
519
|
+
if (wasm !== undefined) return wasm;
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
if (module !== undefined) {
|
|
523
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
524
|
+
({module} = module)
|
|
525
|
+
} else {
|
|
526
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
const imports = __wbg_get_imports();
|
|
531
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
532
|
+
module = new WebAssembly.Module(module);
|
|
533
|
+
}
|
|
534
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
535
|
+
return __wbg_finalize_init(instance, module);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
async function __wbg_init(module_or_path) {
|
|
539
|
+
if (wasm !== undefined) return wasm;
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
if (module_or_path !== undefined) {
|
|
543
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
544
|
+
({module_or_path} = module_or_path)
|
|
545
|
+
} else {
|
|
546
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
if (module_or_path === undefined) {
|
|
551
|
+
module_or_path = new URL('ts_classify_bg.wasm', import.meta.url);
|
|
552
|
+
}
|
|
553
|
+
const imports = __wbg_get_imports();
|
|
554
|
+
|
|
555
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
556
|
+
module_or_path = fetch(module_or_path);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
560
|
+
|
|
561
|
+
return __wbg_finalize_init(instance, module);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|