@datagrok/eda 1.1.25 → 1.1.28
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/.vscode/settings.json +5 -0
- package/CHANGELOG.md +12 -0
- package/README.md +1 -0
- package/dist/05e5e0770f54f07e9474.wasm +0 -0
- package/dist/111.js +2 -0
- package/dist/111.js.map +1 -0
- package/dist/153.js +2 -0
- package/dist/153.js.map +1 -0
- package/dist/23.js +2 -2
- package/dist/23.js.map +1 -0
- package/dist/234.js +2 -0
- package/dist/234.js.map +1 -0
- package/dist/242.js +2 -0
- package/dist/242.js.map +1 -0
- package/dist/260.js +2 -0
- package/dist/260.js.map +1 -0
- package/dist/317.js +2 -0
- package/dist/317.js.map +1 -0
- package/dist/33.js +2 -0
- package/dist/33.js.map +1 -0
- package/dist/348.js +2 -0
- package/dist/348.js.map +1 -0
- package/dist/377.js +2 -0
- package/dist/377.js.map +1 -0
- package/dist/412.js +2 -0
- package/dist/412.js.map +1 -0
- package/dist/415.js +2 -0
- package/dist/415.js.map +1 -0
- package/dist/531.js +2 -0
- package/dist/531.js.map +1 -0
- package/dist/583.js +2 -0
- package/dist/583.js.map +1 -0
- package/dist/589.js +2 -0
- package/dist/589.js.map +1 -0
- package/dist/603.js +2 -0
- package/dist/603.js.map +1 -0
- package/dist/656.js +2 -0
- package/dist/656.js.map +1 -0
- package/dist/682.js +2 -0
- package/dist/682.js.map +1 -0
- package/dist/705.js +2 -0
- package/dist/705.js.map +1 -0
- package/dist/731.js +2 -0
- package/dist/731.js.map +1 -0
- package/dist/738.js +3 -0
- package/dist/738.js.map +1 -0
- package/dist/763.js +2 -0
- package/dist/763.js.map +1 -0
- package/dist/778.js +2 -0
- package/dist/778.js.map +1 -0
- package/dist/783.js +2 -0
- package/dist/783.js.map +1 -0
- package/dist/793.js +2 -0
- package/dist/793.js.map +1 -0
- package/dist/907.js +2 -0
- package/dist/907.js.map +1 -0
- package/dist/91.js +2 -0
- package/dist/91.js.map +1 -0
- package/dist/950.js +2 -0
- package/dist/950.js.map +1 -0
- package/dist/package-test.js +2 -2
- package/dist/package-test.js.map +1 -0
- package/dist/package.js +2 -2
- package/dist/package.js.map +1 -0
- package/package.json +92 -92
- package/scripts/command.txt +1 -1
- package/scripts/func.json +1 -1
- package/scripts/module.json +1 -1
- package/src/missing-values-imputation/ui.ts +80 -66
- package/src/package.ts +288 -38
- package/src/pls/pls-tools.ts +16 -15
- package/src/regression.ts +232 -0
- package/src/svm.ts +78 -38
- package/tsconfig.json +4 -4
- package/wasm/EDA.js +65 -1
- package/wasm/EDA.wasm +0 -0
- package/wasm/EDAAPI.js +30 -0
- package/wasm/EDAForWebWorker.js +1 -1
- package/wasm/callWasm.js +384 -393
- package/wasm/regression-api.cpp +66 -0
- package/wasm/regression.h +128 -0
- package/wasm/workers/fitLinearRegressionParamsWithDataNormalizingWorker.js +13 -0
- package/wasm/workers/fitLinearRegressionParamsWorker.js +13 -0
- package/webpack.config.js +1 -1
- package/dist/208.js +0 -2
- package/dist/221.js +0 -2
- package/dist/231.js +0 -2
- package/dist/261.js +0 -2
- package/dist/282.js +0 -2
- package/dist/334.js +0 -2
- package/dist/356.js +0 -2
- package/dist/36.js +0 -2
- package/dist/367.js +0 -2
- package/dist/374.js +0 -2
- package/dist/40.js +0 -2
- package/dist/413.js +0 -2
- package/dist/42.js +0 -2
- package/dist/427.js +0 -2
- package/dist/467.js +0 -2
- package/dist/523.js +0 -3
- package/dist/533.js +0 -2
- package/dist/590.js +0 -2
- package/dist/65.js +0 -2
- package/dist/694.js +0 -2
- package/dist/729.js +0 -2
- package/dist/796.js +0 -2
- package/dist/902.js +0 -2
- package/dist/910.js +0 -2
- package/dist/972.js +0 -2
- package/dist/f5343e2c2e15952ce916.wasm +0 -0
- /package/dist/{523.js.LICENSE.txt → 738.js.LICENSE.txt} +0 -0
package/wasm/callWasm.js
CHANGED
|
@@ -2,465 +2,456 @@
|
|
|
2
2
|
// It was previousely developed and does NOT provide call wasm-functions in WebWorkers.
|
|
3
3
|
|
|
4
4
|
// type-to-heap correspondence
|
|
5
|
-
const heapMap = {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const heapMap = {'i32': 'HEAP32', // Int32Array
|
|
6
|
+
'f32': 'HEAPF32', // Float32Array
|
|
7
|
+
};
|
|
8
8
|
|
|
9
9
|
// type signature to typed array ,app
|
|
10
|
-
const typeMap = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const typeMap = {'i32': Int32Array, // Int32Array
|
|
11
|
+
'f32': Float32Array, // Float32Array
|
|
12
|
+
};
|
|
13
|
+
|
|
14
14
|
// type-to-shift map
|
|
15
|
-
const shiftMap = {
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const shiftMap = {'i32': 2, // Int32Array
|
|
16
|
+
'f32': 2, // Float32Array
|
|
17
|
+
};
|
|
18
18
|
|
|
19
19
|
// type-to-column_creator map
|
|
20
|
-
const typeToColumnCreatorMap = {
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
const typeToColumnCreatorMap = {'i32': DG.Column.fromInt32Array,
|
|
21
|
+
'f32': DG.Column.fromFloat32Array};
|
|
23
22
|
|
|
24
|
-
// CLASSES THAT ARE USED BY CPP-WRAPPER
|
|
25
23
|
|
|
26
|
-
//
|
|
27
|
-
class Arg{
|
|
24
|
+
// CLASSES THAT ARE USED BY CPP-WRAPPER
|
|
28
25
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
// simple argument: a number
|
|
27
|
+
class Arg {
|
|
28
|
+
constructor(data) {
|
|
29
|
+
this.data = data;
|
|
30
|
+
}
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
complementArrOfParams(arrOfParams) {
|
|
33
|
+
arrOfParams.push(this.data);
|
|
34
|
+
}
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
complementArrOfTypes(arrOfTypes) {
|
|
37
|
+
arrOfTypes.push('number');
|
|
38
|
+
}
|
|
40
39
|
|
|
41
|
-
|
|
40
|
+
allocateMemoryForBuffer(module) {}
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
isMemoryForBufferAllocated() {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
46
45
|
|
|
47
|
-
|
|
46
|
+
putDataToBuffer(module) {}
|
|
48
47
|
|
|
49
|
-
|
|
48
|
+
getDataFromBuffer(module) {}
|
|
50
49
|
|
|
51
|
-
|
|
50
|
+
freeBuffer(module) {}
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
// column argument
|
|
55
54
|
class ArgColumn extends Arg {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
heap.set(array, this.buf >> shift);
|
|
99
|
-
}
|
|
55
|
+
constructor(data, targetType, toUpdate = false) {
|
|
56
|
+
super(data);
|
|
57
|
+
this.type = targetType;
|
|
58
|
+
this.toUpdate = toUpdate;
|
|
59
|
+
this.buf = 0;
|
|
60
|
+
this.numOfRows = data.length;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
complementArrOfParams(arrOfParams) {
|
|
64
|
+
arrOfParams.push(this.buf);
|
|
65
|
+
arrOfParams.push(this.numOfRows);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
complementArrOfTypes(arrOfTypes) {
|
|
69
|
+
arrOfTypes.push('number');
|
|
70
|
+
arrOfTypes.push('number');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
allocateMemoryForBuffer(module) {
|
|
74
|
+
this.buf = module._malloc(this.numOfRows * typeMap[this.type].BYTES_PER_ELEMENT);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
isMemoryForBufferAllocated() {
|
|
78
|
+
return (this.buf != 0);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
putDataToBuffer(module) {
|
|
82
|
+
if (this.isMemoryForBufferAllocated()) {
|
|
83
|
+
const type = this.type;
|
|
84
|
+
const shift = shiftMap[type];
|
|
85
|
+
const heap = module[heapMap[type]];
|
|
86
|
+
let array = null;
|
|
87
|
+
const col = this.data;
|
|
88
|
+
|
|
89
|
+
if (((col.type == 'int') && (type == 'i32')) ||
|
|
90
|
+
((col.type == 'double') && (type == 'f32')))
|
|
91
|
+
array = col.getRawData();
|
|
92
|
+
else
|
|
93
|
+
array = new typeMap[type](col.getRawData());
|
|
94
|
+
|
|
95
|
+
if (array)
|
|
96
|
+
heap.set(array, this.buf >> shift);
|
|
100
97
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
getDataFromBuffer(module) {
|
|
101
|
+
if (this.toUpdate && this.isMemoryForBufferAllocated()) {
|
|
102
|
+
const type = this.type;
|
|
103
|
+
const heap = module[heapMap[type]];
|
|
104
|
+
const buffer = this.buf;
|
|
105
|
+
const bytes = typeMap[type].BYTES_PER_ELEMENT;
|
|
106
|
+
const array = this.data.getRawData();
|
|
107
|
+
|
|
108
|
+
for (let i = 0; i < this.numOfRows; i++)
|
|
109
|
+
array[i] = heap[buffer / bytes + i];
|
|
113
110
|
}
|
|
111
|
+
}
|
|
114
112
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
113
|
+
freeBuffer(module) {
|
|
114
|
+
if (this.isMemoryForBufferAllocated()) {
|
|
115
|
+
module._free(this.buf);
|
|
116
|
+
this.buf = 0;
|
|
120
117
|
}
|
|
121
|
-
|
|
118
|
+
}
|
|
122
119
|
}
|
|
123
120
|
|
|
124
121
|
// new column argument: a new column is created
|
|
125
122
|
class ArgNewColumn extends ArgColumn {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
123
|
+
constructor(targetType, numOfRows) {
|
|
124
|
+
super([], targetType, true);
|
|
125
|
+
this.numOfRows = numOfRows;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
putDataToBuffer(module) {}
|
|
130
129
|
|
|
131
|
-
|
|
130
|
+
getDataFromBuffer(module) {
|
|
131
|
+
if (this.toUpdate && this.isMemoryForBufferAllocated()) {
|
|
132
|
+
const type = this.type;
|
|
133
|
+
const heap = module[heapMap[type]];
|
|
134
|
+
const buf = this.buf;
|
|
132
135
|
|
|
133
|
-
|
|
134
|
-
if(this.toUpdate && this.isMemoryForBufferAllocated()) {
|
|
135
|
-
let type = this.type;
|
|
136
|
-
let heap = module[heapMap[type]];
|
|
137
|
-
let buf = this.buf;
|
|
138
|
-
|
|
139
|
-
let columnCreator = typeToColumnCreatorMap[type];
|
|
140
|
-
|
|
141
|
-
let arr = new typeMap[type](this.numOfRows);
|
|
136
|
+
const columnCreator = typeToColumnCreatorMap[type];
|
|
142
137
|
|
|
143
|
-
|
|
144
|
-
arr[i] = heap[buf / arr.BYTES_PER_ELEMENT + i];
|
|
138
|
+
const arr = new typeMap[type](this.numOfRows);
|
|
145
139
|
|
|
146
|
-
|
|
140
|
+
for (let i = 0; i < arr.length; i++)
|
|
141
|
+
arr[i] = heap[buf / arr.BYTES_PER_ELEMENT + i];
|
|
147
142
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
// This makes mistake, when this.numOfRows = 5 (TODO: investigate why)
|
|
151
|
-
//this.data = columnCreator('name', new typeMap[type](heap.buffer, this.buf, this.numOfRows));
|
|
143
|
+
this.data = columnCreator('name', arr);
|
|
152
144
|
|
|
153
|
-
|
|
154
|
-
|
|
145
|
+
//console.log(arr);
|
|
146
|
+
|
|
147
|
+
// This makes mistake, when this.numOfRows = 5 (TODO: investigate why)
|
|
148
|
+
//this.data = columnCreator('name', new typeMap[type](heap.buffer, this.buf, this.numOfRows));
|
|
149
|
+
|
|
150
|
+
//console.log(this.data.getRawData());
|
|
155
151
|
}
|
|
152
|
+
}
|
|
156
153
|
}
|
|
157
154
|
|
|
158
155
|
// an array of columns argument
|
|
159
156
|
class ArgColumns extends Arg {
|
|
157
|
+
constructor(data, targetType, toUpdate = false) {
|
|
158
|
+
super(data);
|
|
159
|
+
this.type = targetType;
|
|
160
|
+
this.toUpdate = toUpdate;
|
|
161
|
+
this.buf = 0;
|
|
162
|
+
this.numOfColumns = data.length;
|
|
163
|
+
this.numOfRows = data[0].length;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
complementArrOfParams(arrOfParams) {
|
|
167
|
+
arrOfParams.push(this.buf);
|
|
168
|
+
arrOfParams.push(this.numOfRows);
|
|
169
|
+
arrOfParams.push(this.numOfColumns);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
complementArrOfTypes(arrOfTypes) {
|
|
173
|
+
arrOfTypes.push('number');
|
|
174
|
+
arrOfTypes.push('number');
|
|
175
|
+
arrOfTypes.push('number');
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
allocateMemoryForBuffer(module) {
|
|
179
|
+
this.buf = module._malloc(this.numOfRows * this.numOfColumns *
|
|
180
|
+
typeMap[this.type].BYTES_PER_ELEMENT);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
isMemoryForBufferAllocated() {
|
|
184
|
+
return (this.buf != 0);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
putDataToBuffer(module) {
|
|
188
|
+
if (this.isMemoryForBufferAllocated()) {
|
|
189
|
+
const type = this.type;
|
|
190
|
+
const shift = shiftMap[type];
|
|
191
|
+
const heap = module[heapMap[type]];
|
|
192
|
+
const numOfBytes = typeMap[type].BYTES_PER_ELEMENT;
|
|
193
|
+
|
|
194
|
+
// put columns data to buffer
|
|
195
|
+
for (let i = 0; i < this.numOfColumns; i++) {
|
|
196
|
+
let array = null;
|
|
197
|
+
const col = this.data[i];
|
|
198
|
+
|
|
199
|
+
if (((col.type == 'int') && (type == 'i32')) ||
|
|
200
|
+
((col.type == 'double') && (type == 'f32')))
|
|
201
|
+
array = col.getRawData();
|
|
202
|
+
else
|
|
203
|
+
array = new typeMap[type](col.getRawData());
|
|
160
204
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
this.buf = 0;
|
|
166
|
-
this.numOfColumns = data.length;
|
|
167
|
-
this.numOfRows = data[0].length;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
complementArrOfParams(arrOfParams) {
|
|
171
|
-
arrOfParams.push(this.buf);
|
|
172
|
-
arrOfParams.push(this.numOfRows);
|
|
173
|
-
arrOfParams.push(this.numOfColumns);
|
|
205
|
+
// check data array
|
|
206
|
+
if (array != null)
|
|
207
|
+
heap.set(array, (this.buf + i * this.numOfRows * numOfBytes) >> shift);
|
|
208
|
+
}
|
|
174
209
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
getDataFromBuffer(module) {
|
|
213
|
+
if (this.toUpdate && this.isMemoryForBufferAllocated()) {
|
|
214
|
+
const type = this.type;
|
|
215
|
+
const heap = module[heapMap[type]];
|
|
216
|
+
const numOfRows = this.numOfRows;
|
|
217
|
+
const numOfCols = this.numOfColumns;
|
|
218
|
+
const arr = new typeMap[type](heap.buffer, this.buf, numOfRows * numOfCols);
|
|
219
|
+
|
|
220
|
+
for (let i = 0; i < numOfCols; i++) {
|
|
221
|
+
const colData = this.data[i].getRawData();
|
|
222
|
+
for (let j = 0; j < numOfRows; j++)
|
|
223
|
+
colData[j] = arr[j + i * numOfRows];
|
|
224
|
+
}
|
|
180
225
|
}
|
|
226
|
+
}
|
|
181
227
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
228
|
+
freeBuffer(module) {
|
|
229
|
+
if (this.isMemoryForBufferAllocated()) {
|
|
230
|
+
module._free(this.buf);
|
|
231
|
+
this.buf = 0;
|
|
185
232
|
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
186
235
|
|
|
187
|
-
|
|
188
|
-
|
|
236
|
+
// an array of new columns: new columns are created
|
|
237
|
+
class ArgNewColumns extends ArgColumns {
|
|
238
|
+
constructor(targetType, numOfRows, numOfColumns) {
|
|
239
|
+
super([[]], targetType, true);
|
|
240
|
+
this.data = [];
|
|
241
|
+
this.numOfColumns = numOfColumns;
|
|
242
|
+
this.numOfRows = numOfRows;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
putDataToBuffer(module) { }
|
|
246
|
+
|
|
247
|
+
getDataFromBuffer(module) {
|
|
248
|
+
if (this.toUpdate && this.isMemoryForBufferAllocated()) {
|
|
249
|
+
const type = this.type;
|
|
250
|
+
const heap = module[heapMap[type]];
|
|
251
|
+
const numOfRows = this.numOfRows;
|
|
252
|
+
const numOfCols = this.numOfColumns;
|
|
253
|
+
const numOfBytes = typeMap[type].BYTES_PER_ELEMENT;
|
|
254
|
+
const columnCreator = typeToColumnCreatorMap[type];
|
|
255
|
+
const buf = this.buf;
|
|
256
|
+
|
|
257
|
+
for (let i = 0; i < numOfCols; i++) {
|
|
258
|
+
const arr = new typeMap[type](numOfRows);
|
|
259
|
+
|
|
260
|
+
for (let j = 0; j < numOfRows; j++)
|
|
261
|
+
arr[j] = heap[buf / numOfBytes + j + i * numOfRows];
|
|
262
|
+
|
|
263
|
+
this.data.push(columnCreator((i + 1).toString(), arr));
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// create columns: here, may be a problem when numOfRows = 5
|
|
267
|
+
/*for(let i = 0; i < numOfCols; i++)
|
|
268
|
+
this.data.push(columnCreator((i + 1).toString(), new typeMap[type](heap.buffer,
|
|
269
|
+
this.buf + i * numOfRows * numOfBytes, numOfRows)));*/
|
|
189
270
|
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
190
273
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
let shift = shiftMap[type];
|
|
195
|
-
let heap = module[heapMap[type]];
|
|
196
|
-
let numOfBytes = typeMap[type].BYTES_PER_ELEMENT;
|
|
197
|
-
|
|
198
|
-
// put columns data to buffer
|
|
199
|
-
for(let i = 0; i < this.numOfColumns; i++) {
|
|
200
|
-
let array = null;
|
|
201
|
-
let col = this.data[i];
|
|
202
|
-
|
|
203
|
-
if(((col.type == 'int') && (type == 'i32'))
|
|
204
|
-
|| ((col.type == 'double') && (type == 'f32')))
|
|
205
|
-
array = col.getRawData();
|
|
206
|
-
else
|
|
207
|
-
array = new typeMap[type](col.getRawData());
|
|
208
|
-
|
|
209
|
-
// check data array
|
|
210
|
-
if(array != null)
|
|
211
|
-
heap.set(array, (this.buf + i * this.numOfRows * numOfBytes) >> shift);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
274
|
+
// a wrapper for exported C/C++-function call
|
|
275
|
+
function cppFuncWrapper(module, cFuncName, returnType, args) {
|
|
276
|
+
let result;
|
|
215
277
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
let heap = module[heapMap[type]];
|
|
220
|
-
let numOfRows = this.numOfRows;
|
|
221
|
-
let numOfCols = this.numOfColumns;
|
|
222
|
-
let arr = new typeMap[type](heap.buffer, this.buf, numOfRows * numOfCols);
|
|
223
|
-
|
|
224
|
-
for(let i = 0; i < numOfCols; i++) {
|
|
225
|
-
let colData = this.data[i].getRawData();
|
|
226
|
-
for(let j = 0; j < numOfRows; j++)
|
|
227
|
-
colData[j] = arr[j + i * numOfRows];
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
278
|
+
// allocate memory for buffers
|
|
279
|
+
for (const arg of args)
|
|
280
|
+
arg.allocateMemoryForBuffer(module);
|
|
231
281
|
|
|
232
|
-
|
|
233
|
-
if(this.isMemoryForBufferAllocated()) {
|
|
234
|
-
module._free(this.buf);
|
|
235
|
-
this.buf = 0;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
282
|
+
let isEnoughOfMemoryAllocated = true;
|
|
238
283
|
|
|
239
|
-
|
|
284
|
+
// check memory allocation
|
|
285
|
+
for (const arg of args)
|
|
286
|
+
isEnoughOfMemoryAllocated &= arg.isMemoryForBufferAllocated();
|
|
240
287
|
|
|
241
|
-
//
|
|
242
|
-
|
|
288
|
+
// run exported function if enough of memory is allocated
|
|
289
|
+
if (isEnoughOfMemoryAllocated) {
|
|
290
|
+
const params = []; // arguments that are put to the exported function
|
|
291
|
+
const types = []; // their types
|
|
243
292
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
293
|
+
// prepare data that is put to exported function
|
|
294
|
+
for (const arg of args) {
|
|
295
|
+
arg.complementArrOfParams(params);
|
|
296
|
+
arg.complementArrOfTypes(types);
|
|
297
|
+
arg.putDataToBuffer(module);
|
|
249
298
|
}
|
|
250
299
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
getDataFromBuffer(module) {
|
|
254
|
-
if(this.toUpdate && this.isMemoryForBufferAllocated()) {
|
|
255
|
-
let type = this.type;
|
|
256
|
-
let heap = module[heapMap[type]];
|
|
257
|
-
let numOfRows = this.numOfRows;
|
|
258
|
-
let numOfCols = this.numOfColumns;
|
|
259
|
-
let numOfBytes = typeMap[type].BYTES_PER_ELEMENT;
|
|
260
|
-
let columnCreator = typeToColumnCreatorMap[type];
|
|
261
|
-
let buf = this.buf;
|
|
262
|
-
|
|
263
|
-
for(let i = 0; i < numOfCols; i++) {
|
|
264
|
-
let arr = new typeMap[type](numOfRows);
|
|
265
|
-
|
|
266
|
-
for(let j = 0; j < numOfRows; j++)
|
|
267
|
-
arr[j] = heap[buf / numOfBytes + j + i * numOfRows];
|
|
268
|
-
|
|
269
|
-
this.data.push(columnCreator((i + 1).toString(), arr));
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// create columns: here, may be a problem when numOfRows = 5
|
|
273
|
-
/*for(let i = 0; i < numOfCols; i++)
|
|
274
|
-
this.data.push(columnCreator((i + 1).toString(), new typeMap[type](heap.buffer,
|
|
275
|
-
this.buf + i * numOfRows * numOfBytes, numOfRows)));*/
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
300
|
+
const extendedTypeOfReturn = (returnType == 'num') ? 'number' : null;
|
|
279
301
|
|
|
280
|
-
//
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
// allocate memory for buffers
|
|
286
|
-
for(let arg of args)
|
|
287
|
-
arg.allocateMemoryForBuffer(module);
|
|
288
|
-
|
|
289
|
-
let isEnoughOfMemoryAllocated = true;
|
|
290
|
-
|
|
291
|
-
// check memory allocation
|
|
292
|
-
for(let arg of args)
|
|
293
|
-
isEnoughOfMemoryAllocated &= arg.isMemoryForBufferAllocated();
|
|
294
|
-
|
|
295
|
-
// run exported function if enough of memory is allocated
|
|
296
|
-
if(isEnoughOfMemoryAllocated) {
|
|
297
|
-
|
|
298
|
-
let params = []; // arguments that are put to the exported function
|
|
299
|
-
let types = []; // their types
|
|
300
|
-
|
|
301
|
-
// prepare data that is put to exported function
|
|
302
|
-
for(let arg of args) {
|
|
303
|
-
arg.complementArrOfParams(params);
|
|
304
|
-
arg.complementArrOfTypes(types);
|
|
305
|
-
arg.putDataToBuffer(module);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
let extendedTypeOfReturn = (returnType == 'num') ? 'number' : null;
|
|
309
|
-
|
|
310
|
-
// call exported function
|
|
311
|
-
if(extendedTypeOfReturn)
|
|
312
|
-
result = module.ccall(cFuncName, extendedTypeOfReturn, types, params);
|
|
313
|
-
else
|
|
314
|
-
result = module.ccall(cFuncName, extendedTypeOfReturn, types, params);
|
|
315
|
-
|
|
316
|
-
// update and get data from buffers if required
|
|
317
|
-
for(let arg of args)
|
|
318
|
-
arg.getDataFromBuffer(module);
|
|
319
|
-
}
|
|
302
|
+
// call exported function
|
|
303
|
+
if (extendedTypeOfReturn)
|
|
304
|
+
result = module.ccall(cFuncName, extendedTypeOfReturn, types, params);
|
|
305
|
+
else
|
|
306
|
+
result = module.ccall(cFuncName, extendedTypeOfReturn, types, params);
|
|
320
307
|
|
|
321
|
-
//
|
|
322
|
-
for(
|
|
323
|
-
|
|
308
|
+
// update and get data from buffers if required
|
|
309
|
+
for (const arg of args)
|
|
310
|
+
arg.getDataFromBuffer(module);
|
|
311
|
+
}
|
|
324
312
|
|
|
325
|
-
|
|
326
|
-
|
|
313
|
+
// clear buffers
|
|
314
|
+
for (const arg of args)
|
|
315
|
+
arg.freeBuffer(module);
|
|
316
|
+
|
|
317
|
+
if (result != undefined)
|
|
318
|
+
return result;
|
|
327
319
|
} // cppFuncWrapper
|
|
328
320
|
|
|
329
321
|
|
|
330
322
|
// A LAYER BETWEEN JS AND CPP-WRAPPER
|
|
331
323
|
|
|
332
324
|
// Parameters creator
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
325
|
+
const Param = {
|
|
326
|
+
intColumn(column) {
|
|
327
|
+
return new ArgColumn(column, 'i32');
|
|
328
|
+
},
|
|
329
|
+
|
|
330
|
+
newIntColumn(numOfRows) {
|
|
331
|
+
return new ArgNewColumn('i32', numOfRows);
|
|
332
|
+
},
|
|
333
|
+
|
|
334
|
+
intColumns(columns) {
|
|
335
|
+
return new ArgColumns(columns.toList(), 'i32');
|
|
336
|
+
},
|
|
337
|
+
|
|
338
|
+
newIntColumns(numOfRows, numOfColumns) {
|
|
339
|
+
return new ArgNewColumns('i32', numOfRows, numOfColumns);
|
|
340
|
+
},
|
|
341
|
+
|
|
342
|
+
floatColumn(column) {
|
|
343
|
+
return new ArgColumn(column, 'f32');
|
|
344
|
+
},
|
|
345
|
+
|
|
346
|
+
newFloatColumn(numOfRows) {
|
|
347
|
+
return new ArgNewColumn('f32', numOfRows);
|
|
348
|
+
},
|
|
349
|
+
|
|
350
|
+
floatColumns(columns) {
|
|
351
|
+
return new ArgColumns(columns.toList(), 'f32');
|
|
352
|
+
},
|
|
353
|
+
|
|
354
|
+
newFloatColumns(numOfRows, numOfColumns) {
|
|
355
|
+
return new ArgNewColumns('f32', numOfRows, numOfColumns);
|
|
356
|
+
},
|
|
357
|
+
|
|
358
|
+
int(number) {
|
|
359
|
+
return new Arg(number);
|
|
360
|
+
},
|
|
361
|
+
|
|
362
|
+
num(number) {
|
|
363
|
+
return new Arg(number);
|
|
364
|
+
},
|
|
373
365
|
};
|
|
374
366
|
|
|
375
367
|
// Return value creator
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
368
|
+
const Return = {
|
|
369
|
+
tableFromColumns(argColumns) {
|
|
370
|
+
return DG.DataFrame.fromColumns(argColumns.data);
|
|
371
|
+
},
|
|
372
|
+
|
|
373
|
+
num(number) {
|
|
374
|
+
return number;
|
|
375
|
+
},
|
|
376
|
+
|
|
377
|
+
int(number) {
|
|
378
|
+
return number;
|
|
379
|
+
},
|
|
380
|
+
|
|
381
|
+
double(number) {
|
|
382
|
+
return number;
|
|
383
|
+
},
|
|
384
|
+
|
|
385
|
+
column(argColumn) {
|
|
386
|
+
return argColumn.data;
|
|
387
|
+
},
|
|
396
388
|
};
|
|
397
389
|
|
|
398
390
|
// The main tool that combines all together
|
|
399
391
|
export function callWasm(module, funcName, inputs) {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
} // callWasm
|
|
392
|
+
// get specification of exported C/C++-function
|
|
393
|
+
const funcSpecification = module[funcName];
|
|
394
|
+
|
|
395
|
+
// get argumnets
|
|
396
|
+
const args = funcSpecification.arguments;
|
|
397
|
+
|
|
398
|
+
// array of arguments that further are used by cpp-wrapper
|
|
399
|
+
const cppFuncInput = [];
|
|
400
|
+
|
|
401
|
+
// complete an input for cpp
|
|
402
|
+
let i = 0;
|
|
403
|
+
for (const key in args) {
|
|
404
|
+
const arg = args[key];
|
|
405
|
+
|
|
406
|
+
// skip auxiliry element
|
|
407
|
+
if (key == '_callResult')
|
|
408
|
+
continue;
|
|
409
|
+
|
|
410
|
+
// create an argument
|
|
411
|
+
switch (arg.type) {
|
|
412
|
+
case 'floatColumns':
|
|
413
|
+
case 'int':
|
|
414
|
+
case 'num':
|
|
415
|
+
case 'floatColumn':
|
|
416
|
+
case 'intColumn':
|
|
417
|
+
case 'intColumns':
|
|
418
|
+
arg.data = Param[arg.type](inputs[i]);
|
|
419
|
+
i++;
|
|
420
|
+
break;
|
|
421
|
+
case 'newFloatColumns':
|
|
422
|
+
case 'newIntColumns':
|
|
423
|
+
const val1 = args[arg['numOfRows']['ref']].data[arg['numOfRows']['value']];
|
|
424
|
+
const val2 = args[arg['numOfColumns']['ref']].data[arg['numOfColumns']['value']];
|
|
425
|
+
arg.data = Param[arg.type](val1, val2);
|
|
426
|
+
break;
|
|
427
|
+
case 'newFloatColumn':
|
|
428
|
+
case 'newIntColumn':
|
|
429
|
+
const val = args[arg['numOfRows']['ref']].data[arg['numOfRows']['value']];
|
|
430
|
+
arg.data = Param[arg.type](val);
|
|
431
|
+
break;
|
|
432
|
+
} // switch
|
|
433
|
+
|
|
434
|
+
cppFuncInput.push(args[key].data);
|
|
435
|
+
} // for key
|
|
436
|
+
|
|
437
|
+
// CALL EXPORTED CPP-FUNCTION
|
|
438
|
+
const callResult = cppFuncWrapper(module, funcName, 'num', cppFuncInput);
|
|
439
|
+
|
|
440
|
+
// store result that is returned by exported cpp-function
|
|
441
|
+
args._callResult = Param.num(callResult);
|
|
442
|
+
|
|
443
|
+
// create output
|
|
444
|
+
const output = funcSpecification.output;
|
|
445
|
+
|
|
446
|
+
// if a single object must be returned
|
|
447
|
+
if (output['type'] != 'objects')
|
|
448
|
+
return Return[output['type']](args[output['source']].data);
|
|
449
|
+
|
|
450
|
+
const arrayToReturn = [];
|
|
451
|
+
|
|
452
|
+
// push data of the required arguments
|
|
453
|
+
for (const name of output['source'])
|
|
454
|
+
arrayToReturn.push(args[name].data.data);
|
|
455
|
+
|
|
456
|
+
return arrayToReturn;
|
|
457
|
+
} // callWasm
|