@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.
Files changed (111) hide show
  1. package/.vscode/settings.json +5 -0
  2. package/CHANGELOG.md +12 -0
  3. package/README.md +1 -0
  4. package/dist/05e5e0770f54f07e9474.wasm +0 -0
  5. package/dist/111.js +2 -0
  6. package/dist/111.js.map +1 -0
  7. package/dist/153.js +2 -0
  8. package/dist/153.js.map +1 -0
  9. package/dist/23.js +2 -2
  10. package/dist/23.js.map +1 -0
  11. package/dist/234.js +2 -0
  12. package/dist/234.js.map +1 -0
  13. package/dist/242.js +2 -0
  14. package/dist/242.js.map +1 -0
  15. package/dist/260.js +2 -0
  16. package/dist/260.js.map +1 -0
  17. package/dist/317.js +2 -0
  18. package/dist/317.js.map +1 -0
  19. package/dist/33.js +2 -0
  20. package/dist/33.js.map +1 -0
  21. package/dist/348.js +2 -0
  22. package/dist/348.js.map +1 -0
  23. package/dist/377.js +2 -0
  24. package/dist/377.js.map +1 -0
  25. package/dist/412.js +2 -0
  26. package/dist/412.js.map +1 -0
  27. package/dist/415.js +2 -0
  28. package/dist/415.js.map +1 -0
  29. package/dist/531.js +2 -0
  30. package/dist/531.js.map +1 -0
  31. package/dist/583.js +2 -0
  32. package/dist/583.js.map +1 -0
  33. package/dist/589.js +2 -0
  34. package/dist/589.js.map +1 -0
  35. package/dist/603.js +2 -0
  36. package/dist/603.js.map +1 -0
  37. package/dist/656.js +2 -0
  38. package/dist/656.js.map +1 -0
  39. package/dist/682.js +2 -0
  40. package/dist/682.js.map +1 -0
  41. package/dist/705.js +2 -0
  42. package/dist/705.js.map +1 -0
  43. package/dist/731.js +2 -0
  44. package/dist/731.js.map +1 -0
  45. package/dist/738.js +3 -0
  46. package/dist/738.js.map +1 -0
  47. package/dist/763.js +2 -0
  48. package/dist/763.js.map +1 -0
  49. package/dist/778.js +2 -0
  50. package/dist/778.js.map +1 -0
  51. package/dist/783.js +2 -0
  52. package/dist/783.js.map +1 -0
  53. package/dist/793.js +2 -0
  54. package/dist/793.js.map +1 -0
  55. package/dist/907.js +2 -0
  56. package/dist/907.js.map +1 -0
  57. package/dist/91.js +2 -0
  58. package/dist/91.js.map +1 -0
  59. package/dist/950.js +2 -0
  60. package/dist/950.js.map +1 -0
  61. package/dist/package-test.js +2 -2
  62. package/dist/package-test.js.map +1 -0
  63. package/dist/package.js +2 -2
  64. package/dist/package.js.map +1 -0
  65. package/package.json +92 -92
  66. package/scripts/command.txt +1 -1
  67. package/scripts/func.json +1 -1
  68. package/scripts/module.json +1 -1
  69. package/src/missing-values-imputation/ui.ts +80 -66
  70. package/src/package.ts +288 -38
  71. package/src/pls/pls-tools.ts +16 -15
  72. package/src/regression.ts +232 -0
  73. package/src/svm.ts +78 -38
  74. package/tsconfig.json +4 -4
  75. package/wasm/EDA.js +65 -1
  76. package/wasm/EDA.wasm +0 -0
  77. package/wasm/EDAAPI.js +30 -0
  78. package/wasm/EDAForWebWorker.js +1 -1
  79. package/wasm/callWasm.js +384 -393
  80. package/wasm/regression-api.cpp +66 -0
  81. package/wasm/regression.h +128 -0
  82. package/wasm/workers/fitLinearRegressionParamsWithDataNormalizingWorker.js +13 -0
  83. package/wasm/workers/fitLinearRegressionParamsWorker.js +13 -0
  84. package/webpack.config.js +1 -1
  85. package/dist/208.js +0 -2
  86. package/dist/221.js +0 -2
  87. package/dist/231.js +0 -2
  88. package/dist/261.js +0 -2
  89. package/dist/282.js +0 -2
  90. package/dist/334.js +0 -2
  91. package/dist/356.js +0 -2
  92. package/dist/36.js +0 -2
  93. package/dist/367.js +0 -2
  94. package/dist/374.js +0 -2
  95. package/dist/40.js +0 -2
  96. package/dist/413.js +0 -2
  97. package/dist/42.js +0 -2
  98. package/dist/427.js +0 -2
  99. package/dist/467.js +0 -2
  100. package/dist/523.js +0 -3
  101. package/dist/533.js +0 -2
  102. package/dist/590.js +0 -2
  103. package/dist/65.js +0 -2
  104. package/dist/694.js +0 -2
  105. package/dist/729.js +0 -2
  106. package/dist/796.js +0 -2
  107. package/dist/902.js +0 -2
  108. package/dist/910.js +0 -2
  109. package/dist/972.js +0 -2
  110. package/dist/f5343e2c2e15952ce916.wasm +0 -0
  111. /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 = {"i32": "HEAP32", // Int32Array
6
- "f32": "HEAPF32" // Float32Array
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 = {"i32": Int32Array, // Int32Array
11
- "f32": Float32Array // Float32Array
12
- };
13
-
10
+ const typeMap = {'i32': Int32Array, // Int32Array
11
+ 'f32': Float32Array, // Float32Array
12
+ };
13
+
14
14
  // type-to-shift map
15
- const shiftMap = {"i32": 2, // Int32Array
16
- "f32": 2 // Float32Array
17
- };
15
+ const shiftMap = {'i32': 2, // Int32Array
16
+ 'f32': 2, // Float32Array
17
+ };
18
18
 
19
19
  // type-to-column_creator map
20
- const typeToColumnCreatorMap = {"i32": DG.Column.fromInt32Array,
21
- "f32": DG.Column.fromFloat32Array};
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
- // simple argument: a number
27
- class Arg{
24
+ // CLASSES THAT ARE USED BY CPP-WRAPPER
28
25
 
29
- constructor(data) {
30
- this.data = data;
31
- }
26
+ // simple argument: a number
27
+ class Arg {
28
+ constructor(data) {
29
+ this.data = data;
30
+ }
32
31
 
33
- complementArrOfParams(arrOfParams) {
34
- arrOfParams.push(this.data);
35
- }
32
+ complementArrOfParams(arrOfParams) {
33
+ arrOfParams.push(this.data);
34
+ }
36
35
 
37
- complementArrOfTypes(arrOfTypes) {
38
- arrOfTypes.push('number');
39
- }
36
+ complementArrOfTypes(arrOfTypes) {
37
+ arrOfTypes.push('number');
38
+ }
40
39
 
41
- allocateMemoryForBuffer(module) {}
40
+ allocateMemoryForBuffer(module) {}
42
41
 
43
- isMemoryForBufferAllocated(){
44
- return true;
45
- }
42
+ isMemoryForBufferAllocated() {
43
+ return true;
44
+ }
46
45
 
47
- putDataToBuffer(module) {}
46
+ putDataToBuffer(module) {}
48
47
 
49
- getDataFromBuffer(module) {}
48
+ getDataFromBuffer(module) {}
50
49
 
51
- freeBuffer(module) {}
50
+ freeBuffer(module) {}
52
51
  }
53
52
 
54
53
  // column argument
55
54
  class ArgColumn extends Arg {
56
-
57
- constructor(data, targetType, toUpdate = false) {
58
- super(data);
59
- this.type = targetType;
60
- this.toUpdate = toUpdate;
61
- this.buf = 0;
62
- this.numOfRows = data.length;
63
- }
64
-
65
- complementArrOfParams(arrOfParams) {
66
- arrOfParams.push(this.buf);
67
- arrOfParams.push(this.numOfRows);
68
- }
69
-
70
- complementArrOfTypes(arrOfTypes) {
71
- arrOfTypes.push('number');
72
- arrOfTypes.push('number');
73
- }
74
-
75
- allocateMemoryForBuffer(module) {
76
- this.buf = module._malloc(this.numOfRows * typeMap[this.type].BYTES_PER_ELEMENT);
77
- }
78
-
79
- isMemoryForBufferAllocated(){
80
- return (this.buf != 0);
81
- }
82
-
83
- putDataToBuffer(module) {
84
- if(this.isMemoryForBufferAllocated()) {
85
- let type = this.type;
86
- let shift = shiftMap[type];
87
- let heap = module[heapMap[type]];
88
- let array = null;
89
- let col = this.data;
90
-
91
- if(((col.type == 'int') && (type == 'i32'))
92
- || ((col.type == 'double') && (type == 'f32')))
93
- array = col.getRawData();
94
- else
95
- array = new typeMap[type](col.getRawData());
96
-
97
- if(array)
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
- getDataFromBuffer(module) {
103
- if(this.toUpdate && this.isMemoryForBufferAllocated()) {
104
- let type = this.type;
105
- let heap = module[heapMap[type]];
106
- let buffer = this.buf;
107
- let bytes = typeMap[type].BYTES_PER_ELEMENT;
108
- let array = this.data.getRawData();
109
-
110
- for(let i = 0; i < this.numOfRows; i++)
111
- array[i] = heap[buffer / bytes + i];
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
- freeBuffer(module) {
116
- if(this.isMemoryForBufferAllocated()) {
117
- module._free(this.buf);
118
- this.buf = 0;
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
- constructor(targetType, numOfRows) {
127
- super([], targetType, true);
128
- this.numOfRows = numOfRows;
129
- }
123
+ constructor(targetType, numOfRows) {
124
+ super([], targetType, true);
125
+ this.numOfRows = numOfRows;
126
+ }
127
+
128
+ putDataToBuffer(module) {}
130
129
 
131
- putDataToBuffer(module) {}
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
- getDataFromBuffer(module) {
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
- for(let i = 0; i < arr.length; i++)
144
- arr[i] = heap[buf / arr.BYTES_PER_ELEMENT + i];
138
+ const arr = new typeMap[type](this.numOfRows);
145
139
 
146
- this.data = columnCreator('name', arr);
140
+ for (let i = 0; i < arr.length; i++)
141
+ arr[i] = heap[buf / arr.BYTES_PER_ELEMENT + i];
147
142
 
148
- //console.log(arr);
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
- //console.log(this.data.getRawData());
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
- constructor(data, targetType, toUpdate = false) {
162
- super(data);
163
- this.type = targetType;
164
- this.toUpdate = toUpdate;
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
- complementArrOfTypes(arrOfTypes) {
177
- arrOfTypes.push('number');
178
- arrOfTypes.push('number');
179
- arrOfTypes.push('number');
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
- allocateMemoryForBuffer(module) {
183
- this.buf = module._malloc(this.numOfRows * this.numOfColumns
184
- * typeMap[this.type].BYTES_PER_ELEMENT);
228
+ freeBuffer(module) {
229
+ if (this.isMemoryForBufferAllocated()) {
230
+ module._free(this.buf);
231
+ this.buf = 0;
185
232
  }
233
+ }
234
+ }
186
235
 
187
- isMemoryForBufferAllocated(){
188
- return (this.buf != 0);
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
- putDataToBuffer(module) {
192
- if(this.isMemoryForBufferAllocated()) {
193
- let type = this.type;
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
- getDataFromBuffer(module) {
217
- if(this.toUpdate && this.isMemoryForBufferAllocated()) {
218
- let type = this.type;
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
- freeBuffer(module) {
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
- // an array of new columns: new columns are created
242
- class ArgNewColumns extends ArgColumns {
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
- constructor(targetType, numOfRows, numOfColumns) {
245
- super([[]], targetType, true);
246
- this.data = [];
247
- this.numOfColumns = numOfColumns;
248
- this.numOfRows = numOfRows;
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
- putDataToBuffer(module) { }
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
- // a wrapper for exported C/C++-function call
281
- function cppFuncWrapper(module, cFuncName, returnType, args)
282
- {
283
- let result;
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
- // clear buffers
322
- for(let arg of args)
323
- arg.freeBuffer(module);
308
+ // update and get data from buffers if required
309
+ for (const arg of args)
310
+ arg.getDataFromBuffer(module);
311
+ }
324
312
 
325
- if(result != undefined)
326
- return result;
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
- let Param = {
334
- intColumn (column) {
335
- return new ArgColumn(column, 'i32');
336
- },
337
-
338
- newIntColumn (numOfRows) {
339
- return new ArgNewColumn('i32', numOfRows);
340
- },
341
-
342
- intColumns(columns){
343
- return new ArgColumns(columns.toList(), 'i32');
344
- },
345
-
346
- newIntColumns(numOfRows, numOfColumns) {
347
- return new ArgNewColumns('i32', numOfRows, numOfColumns);
348
- },
349
-
350
- floatColumn (column) {
351
- return new ArgColumn(column, 'f32');
352
- },
353
-
354
- newFloatColumn (numOfRows) {
355
- return new ArgNewColumn('f32', numOfRows);
356
- },
357
-
358
- floatColumns(columns){
359
- return new ArgColumns(columns.toList(), 'f32');
360
- },
361
-
362
- newFloatColumns(numOfRows, numOfColumns) {
363
- return new ArgNewColumns('f32', numOfRows, numOfColumns);
364
- },
365
-
366
- int(number) {
367
- return new Arg(number);
368
- },
369
-
370
- num(number) {
371
- return new Arg(number);
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
- let Return = {
377
- tableFromColumns(argColumns) {
378
- return DG.DataFrame.fromColumns(argColumns.data);
379
- },
380
-
381
- num(number) {
382
- return number;
383
- },
384
-
385
- int(number) {
386
- return number;
387
- },
388
-
389
- double(number) {
390
- return number;
391
- },
392
-
393
- column(argColumn) {
394
- return argColumn.data;
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
- // get specification of exported C/C++-function
401
- let funcSpecification = module[funcName];
402
-
403
- // get argumnets
404
- let args = funcSpecification.arguments;
405
-
406
- // array of arguments that further are used by cpp-wrapper
407
- let cppFuncInput = [];
408
-
409
- // complete an input for cpp
410
- let i = 0;
411
- for(let key in args){
412
- let arg = args[key];
413
-
414
- // skip auxiliry element
415
- if(key == '_callResult')
416
- continue;
417
-
418
- // create an argument
419
- switch(arg.type){
420
- case 'floatColumns':
421
- case 'int':
422
- case 'num':
423
- case 'floatColumn':
424
- case 'intColumn':
425
- case 'intColumns':
426
- arg.data = Param[arg.type](inputs[i]);
427
- i++;
428
- break;
429
- case 'newFloatColumns':
430
- case 'newIntColumns':
431
- let val1 = args[ arg['numOfRows']['ref'] ].data[arg['numOfRows']['value']];
432
- let val2 = args[ arg['numOfColumns']['ref'] ].data[arg['numOfColumns']['value']];
433
- arg.data = Param[arg.type](val1, val2);
434
- break;
435
- case 'newFloatColumn':
436
- case 'newIntColumn':
437
- let val = args[ arg['numOfRows']['ref'] ].data[arg['numOfRows']['value']];
438
- arg.data = Param[arg.type](val);
439
- break;
440
- } // switch
441
-
442
- cppFuncInput.push(args[key].data);
443
-
444
- } // for key
445
-
446
- // CALL EXPORTED CPP-FUNCTION
447
- let callResult = cppFuncWrapper(module, funcName, 'num', cppFuncInput);
448
-
449
- // store result that is returned by exported cpp-function
450
- args._callResult = Param.num(callResult);
451
-
452
- // create output
453
- let output = funcSpecification.output;
454
-
455
- // if a single object must be returned
456
- if(output['type'] != 'objects')
457
- return Return[output['type']](args[output['source']].data);
458
-
459
- let arrayToReturn = [];
460
-
461
- // push data of the required arguments
462
- for(let name of output['source'])
463
- arrayToReturn.push(args[name].data.data);
464
-
465
- return arrayToReturn;
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