@sdeverywhere/runtime 0.2.8 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -150,7 +150,7 @@ The `emcc` command line options should be similar to the following:
150
150
 
151
151
  ```
152
152
  $ emcc \
153
- build/<mymodel>.c build/macros.c build/model.c build/vensim.c \
153
+ build/<mymodel>.c build/macros.c build/model.c build/vensim.c build/allocation.c \
154
154
  -Ibuild -o ./output/<mymodel>.js -Wall -Os \
155
155
  -s STRICT=1 -s MALLOC=emmalloc -s FILESYSTEM=0 -s MODULARIZE=1 \
156
156
  -s EXPORTED_FUNCTIONS="['_malloc','_free','_getInitialTime','_getFinalTime','_getSaveper','_setLookup','_runModelWithBuffers']" \
package/dist/index.cjs CHANGED
@@ -1245,6 +1245,8 @@ function getJsModelFunctions() {
1245
1245
  let ctx;
1246
1246
  const cachedVectors = /* @__PURE__ */ new Map();
1247
1247
  const cachedSortVectors = /* @__PURE__ */ new Map();
1248
+ const cachedInvertWorkMatrices = /* @__PURE__ */ new Map();
1249
+ const cachedInvertResultMatrices = /* @__PURE__ */ new Map();
1248
1250
  return {
1249
1251
  setContext(context) {
1250
1252
  ctx = context;
@@ -1279,6 +1281,74 @@ function getJsModelFunctions() {
1279
1281
  INTEGER(x) {
1280
1282
  return Math.trunc(x);
1281
1283
  },
1284
+ INVERT_MATRIX(matrix, n) {
1285
+ let work = cachedInvertWorkMatrices.get(n);
1286
+ if (work === void 0) {
1287
+ work = Array(n);
1288
+ for (let i = 0; i < n; i++) {
1289
+ work[i] = Array(2 * n);
1290
+ }
1291
+ cachedInvertWorkMatrices.set(n, work);
1292
+ }
1293
+ let result = cachedInvertResultMatrices.get(n);
1294
+ if (result === void 0) {
1295
+ result = Array(n);
1296
+ for (let i = 0; i < n; i++) {
1297
+ result[i] = Array(n);
1298
+ }
1299
+ cachedInvertResultMatrices.set(n, result);
1300
+ }
1301
+ for (let i = 0; i < n; i++) {
1302
+ for (let j = 0; j < n; j++) {
1303
+ work[i][j] = matrix[i][j];
1304
+ work[i][n + j] = i === j ? 1 : 0;
1305
+ }
1306
+ }
1307
+ for (let k = 0; k < n; k++) {
1308
+ let pivot = k;
1309
+ let max = Math.abs(work[k][k]);
1310
+ for (let i = k + 1; i < n; i++) {
1311
+ const v = Math.abs(work[i][k]);
1312
+ if (v > max) {
1313
+ max = v;
1314
+ pivot = i;
1315
+ }
1316
+ }
1317
+ if (max === 0) {
1318
+ for (let i = 0; i < n; i++) {
1319
+ for (let j = 0; j < n; j++) {
1320
+ result[i][j] = _NA_;
1321
+ }
1322
+ }
1323
+ return result;
1324
+ }
1325
+ if (pivot !== k) {
1326
+ const tmpRow = work[k];
1327
+ work[k] = work[pivot];
1328
+ work[pivot] = tmpRow;
1329
+ }
1330
+ const p = work[k][k];
1331
+ for (let j = 0; j < 2 * n; j++) {
1332
+ work[k][j] /= p;
1333
+ }
1334
+ for (let i = 0; i < n; i++) {
1335
+ if (i !== k) {
1336
+ const f = work[i][k];
1337
+ if (f !== 0) {
1338
+ for (let j = 0; j < 2 * n; j++) {
1339
+ work[i][j] -= f * work[k][j];
1340
+ }
1341
+ }
1342
+ }
1343
+ }
1344
+ }
1345
+ for (let i = 0; i < n; i++) {
1346
+ for (let j = 0; j < n; j++) {
1347
+ result[i][j] = work[i][n + j];
1348
+ }
1349
+ }
1350
+ return result;
1351
+ },
1282
1352
  LN(x) {
1283
1353
  return Math.log(x);
1284
1354
  },