numbl 0.4.16 → 0.4.17
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 +1 -1
- package/dist-browser/browser.js +1 -1
- package/dist-browser/numbl-core/interpreter/builtins/dictionary.d.ts +1 -1
- package/dist-browser/numbl-core/interpreter/builtins/hash.d.ts +6 -0
- package/dist-browser/numbl-core/interpreter/builtins/index.d.ts +1 -0
- package/dist-browser/numbl-core/runtime/runtime.d.ts +1 -1
- package/dist-browser/numbl-core/runtime/runtimeMemberAccess.d.ts +1 -1
- package/dist-browser/numbl-core/version.d.ts +1 -1
- package/dist-cli/cli.js +572 -30
- package/dist-lib/lib.js +571 -29
- package/dist-lib/numbl-core/interpreter/builtins/dictionary.d.ts +1 -1
- package/dist-lib/numbl-core/interpreter/builtins/hash.d.ts +6 -0
- package/dist-lib/numbl-core/interpreter/builtins/index.d.ts +1 -0
- package/dist-lib/numbl-core/runtime/runtime.d.ts +1 -1
- package/dist-lib/numbl-core/runtime/runtimeMemberAccess.d.ts +1 -1
- package/dist-lib/numbl-core/version.d.ts +1 -1
- package/dist-site-viewer/assets/{index-ChbDz1FG.js → index-0mP47Rpm.js} +318 -318
- package/dist-site-viewer/assets/{numbl-worker-DFeAt1Cu.js → numbl-worker-DjOZZaW4.js} +165 -102
- package/dist-site-viewer/index.html +1 -1
- package/package.json +1 -1
package/dist-lib/lib.js
CHANGED
|
@@ -22398,7 +22398,7 @@ function sprintfFormat(fmt, args) {
|
|
|
22398
22398
|
if (fmt[i] === "%" && i + 1 < fmt.length) {
|
|
22399
22399
|
i++;
|
|
22400
22400
|
let spec = "%";
|
|
22401
|
-
while (i < fmt.length && !"
|
|
22401
|
+
while (i < fmt.length && !"dfigGeEsoxXuc%".includes(fmt[i])) {
|
|
22402
22402
|
if (fmt[i] === "*") {
|
|
22403
22403
|
if (argIdx >= flatArgs.length) {
|
|
22404
22404
|
outOfArgs = true;
|
|
@@ -22488,7 +22488,7 @@ function sprintfFormat(fmt, args) {
|
|
|
22488
22488
|
const gPrec = precMatch ? parseInt(precMatch[1]) : 6;
|
|
22489
22489
|
let gStr;
|
|
22490
22490
|
if (gVal === 0) {
|
|
22491
|
-
gStr = "0";
|
|
22491
|
+
gStr = Object.is(gVal, -0) ? "-0" : "0";
|
|
22492
22492
|
} else {
|
|
22493
22493
|
const exp2 = Math.floor(Math.log10(Math.abs(gVal)));
|
|
22494
22494
|
if (exp2 < -4 || exp2 >= gPrec) {
|
|
@@ -25147,6 +25147,7 @@ function indexIntoRTValue(base, indices) {
|
|
|
25147
25147
|
if (isRuntimeLogical(idx)) return idx === true;
|
|
25148
25148
|
if (isRuntimeTensor(idx))
|
|
25149
25149
|
return idx.data.length === 1 && Math.round(idx.data[0]) === 1;
|
|
25150
|
+
if (isColonIndex(idx)) return true;
|
|
25150
25151
|
return false;
|
|
25151
25152
|
});
|
|
25152
25153
|
if (allOnes) return base;
|
|
@@ -25158,6 +25159,9 @@ function indexIntoRTValue(base, indices) {
|
|
|
25158
25159
|
if (isRuntimeStructArray(base)) {
|
|
25159
25160
|
if (indices.length === 1) {
|
|
25160
25161
|
const idx = indices[0];
|
|
25162
|
+
if (isColonIndex(idx)) {
|
|
25163
|
+
return RTV.structArray(base.fieldNames, [...base.elements]);
|
|
25164
|
+
}
|
|
25161
25165
|
if (isRuntimeNumber(idx)) {
|
|
25162
25166
|
const i = Math.round(idx) - 1;
|
|
25163
25167
|
if (i < 0 || i >= base.elements.length)
|
|
@@ -39990,6 +39994,46 @@ function uniquetolElements(v, nargout, tol) {
|
|
|
39990
39994
|
if (nargout === 2) return [C, ia];
|
|
39991
39995
|
return [C, ia, icTensor];
|
|
39992
39996
|
}
|
|
39997
|
+
defineBuiltin({
|
|
39998
|
+
name: "ismembc2",
|
|
39999
|
+
cases: [
|
|
40000
|
+
{
|
|
40001
|
+
match: (argTypes) => {
|
|
40002
|
+
if (argTypes.length !== 2) return null;
|
|
40003
|
+
return [{ kind: "tensor", isComplex: false }];
|
|
40004
|
+
},
|
|
40005
|
+
apply: (args) => {
|
|
40006
|
+
const toFlat = (v) => {
|
|
40007
|
+
if (isRuntimeNumber(v)) return [v];
|
|
40008
|
+
if (isRuntimeLogical(v)) return [v ? 1 : 0];
|
|
40009
|
+
if (isRuntimeTensor(v)) return v.data;
|
|
40010
|
+
throw new RuntimeError("ismembc2: arguments must be numeric");
|
|
40011
|
+
};
|
|
40012
|
+
const a = toFlat(args[0]);
|
|
40013
|
+
const s = toFlat(args[1]);
|
|
40014
|
+
const out = allocFloat64Array(a.length);
|
|
40015
|
+
for (let i = 0; i < a.length; i++) {
|
|
40016
|
+
const x = a[i];
|
|
40017
|
+
let lo = 0;
|
|
40018
|
+
let hi = s.length - 1;
|
|
40019
|
+
let res = 0;
|
|
40020
|
+
while (lo <= hi) {
|
|
40021
|
+
const mid = lo + hi >> 1;
|
|
40022
|
+
if (s[mid] <= x) {
|
|
40023
|
+
if (s[mid] === x) res = mid + 1;
|
|
40024
|
+
lo = mid + 1;
|
|
40025
|
+
} else {
|
|
40026
|
+
hi = mid - 1;
|
|
40027
|
+
}
|
|
40028
|
+
}
|
|
40029
|
+
out[i] = res;
|
|
40030
|
+
}
|
|
40031
|
+
const shape = isRuntimeTensor(args[0]) ? [...args[0].shape] : [1, 1];
|
|
40032
|
+
return RTV.tensor(out, shape);
|
|
40033
|
+
}
|
|
40034
|
+
}
|
|
40035
|
+
]
|
|
40036
|
+
});
|
|
39993
40037
|
|
|
39994
40038
|
// src/numbl-core/interpreter/builtins/linear-algebra.ts
|
|
39995
40039
|
function isNumericJitType(t) {
|
|
@@ -46168,6 +46212,45 @@ defineBuiltin({
|
|
|
46168
46212
|
},
|
|
46169
46213
|
apply: (args) => {
|
|
46170
46214
|
const xArr = toFloatArray(args[0]);
|
|
46215
|
+
if (args.length === 4 && isRuntimeChar(args[2]) && isRuntimeChar(args[3]) && args[3].value.toLowerCase() === "pp") {
|
|
46216
|
+
const method2 = args[2].value.toLowerCase();
|
|
46217
|
+
if (method2 !== "linear")
|
|
46218
|
+
throw new RuntimeError(
|
|
46219
|
+
`interp1: 'pp' output is only supported for 'linear' method (got '${method2}')`
|
|
46220
|
+
);
|
|
46221
|
+
const yArr = toFloatArray(args[1]);
|
|
46222
|
+
const n = xArr.length;
|
|
46223
|
+
if (yArr.length !== n)
|
|
46224
|
+
throw new RuntimeError(
|
|
46225
|
+
"interp1: x and y must have the same length"
|
|
46226
|
+
);
|
|
46227
|
+
if (n < 2)
|
|
46228
|
+
throw new RuntimeError(
|
|
46229
|
+
"interp1: at least 2 sample points are required"
|
|
46230
|
+
);
|
|
46231
|
+
for (let i = 0; i + 1 < n; i++) {
|
|
46232
|
+
if (!(xArr[i] < xArr[i + 1]))
|
|
46233
|
+
throw new RuntimeError(
|
|
46234
|
+
"interp1: sample points must be unique and sorted for 'pp' output"
|
|
46235
|
+
);
|
|
46236
|
+
}
|
|
46237
|
+
const L = n - 1;
|
|
46238
|
+
const breaksOut = allocFloat64Array(n);
|
|
46239
|
+
for (let i = 0; i < n; i++) breaksOut[i] = xArr[i];
|
|
46240
|
+
const coefs = allocFloat64Array(L * 2);
|
|
46241
|
+
for (let i = 0; i < L; i++) {
|
|
46242
|
+
coefs[i] = (yArr[i + 1] - yArr[i]) / (xArr[i + 1] - xArr[i]);
|
|
46243
|
+
coefs[L + i] = yArr[i];
|
|
46244
|
+
}
|
|
46245
|
+
const fields = /* @__PURE__ */ new Map();
|
|
46246
|
+
fields.set("form", "pp");
|
|
46247
|
+
fields.set("breaks", RTV.tensor(breaksOut, [1, n]));
|
|
46248
|
+
fields.set("coefs", RTV.tensor(coefs, [L, 2]));
|
|
46249
|
+
fields.set("pieces", L);
|
|
46250
|
+
fields.set("order", 2);
|
|
46251
|
+
fields.set("dim", 1);
|
|
46252
|
+
return RTV.struct(fields);
|
|
46253
|
+
}
|
|
46171
46254
|
const xqArg = args[2];
|
|
46172
46255
|
const nn = xArr.length;
|
|
46173
46256
|
const yVal = args[1];
|
|
@@ -46196,6 +46279,7 @@ defineBuiltin({
|
|
|
46196
46279
|
throw new RuntimeError("interp1: x and y must have the same length");
|
|
46197
46280
|
let method = "linear";
|
|
46198
46281
|
let doExtrap = false;
|
|
46282
|
+
let fillValue = NaN;
|
|
46199
46283
|
for (let i = 3; i < args.length; i++) {
|
|
46200
46284
|
const a = args[i];
|
|
46201
46285
|
if (isRuntimeChar(a)) {
|
|
@@ -46206,11 +46290,13 @@ defineBuiltin({
|
|
|
46206
46290
|
const s = a.toLowerCase();
|
|
46207
46291
|
if (s === "extrap") doExtrap = true;
|
|
46208
46292
|
else method = s;
|
|
46293
|
+
} else if (isRuntimeNumber(a) || isRuntimeTensor(a)) {
|
|
46294
|
+
fillValue = toNumber(a);
|
|
46209
46295
|
}
|
|
46210
46296
|
}
|
|
46211
46297
|
const interpOne = (yArr, xq) => {
|
|
46212
46298
|
if (xq < xArr[0] || xq > xArr[nn - 1]) {
|
|
46213
|
-
if (!doExtrap) return
|
|
46299
|
+
if (!doExtrap) return fillValue;
|
|
46214
46300
|
if (method === "linear") {
|
|
46215
46301
|
if (xq < xArr[0]) {
|
|
46216
46302
|
const slope = (yArr[1] - yArr[0]) / (xArr[1] - xArr[0]);
|
|
@@ -46641,6 +46727,63 @@ function dimArgToVec(v) {
|
|
|
46641
46727
|
}
|
|
46642
46728
|
throw new RuntimeError("mkpp: dim must be a numeric scalar or vector");
|
|
46643
46729
|
}
|
|
46730
|
+
var ppIntApply = (fname) => (args) => {
|
|
46731
|
+
const pp = args[0];
|
|
46732
|
+
if (!isRuntimeStruct(pp))
|
|
46733
|
+
throw new RuntimeError(`${fname}: argument must be a pp struct`);
|
|
46734
|
+
const breaksRT = pp.fields.get("breaks");
|
|
46735
|
+
const coefsRT = pp.fields.get("coefs");
|
|
46736
|
+
const piecesRT = pp.fields.get("pieces");
|
|
46737
|
+
const orderRT = pp.fields.get("order");
|
|
46738
|
+
const dimRT = pp.fields.get("dim");
|
|
46739
|
+
if (breaksRT === void 0 || coefsRT === void 0 || piecesRT === void 0 || orderRT === void 0)
|
|
46740
|
+
throw new RuntimeError(`${fname}: pp struct missing required fields`);
|
|
46741
|
+
const breaks = toFloatArray(breaksRT);
|
|
46742
|
+
const L = Math.round(toNumber(piecesRT));
|
|
46743
|
+
const k = Math.round(toNumber(orderRT));
|
|
46744
|
+
const dim = dimRT === void 0 ? [1] : dimArgToVec(dimRT);
|
|
46745
|
+
if (dim.reduce((a, b) => a * b, 1) !== 1)
|
|
46746
|
+
throw new RuntimeError(`${fname}: only scalar-valued pp is supported`);
|
|
46747
|
+
if (!isRuntimeTensor(coefsRT))
|
|
46748
|
+
throw new RuntimeError(`${fname}: pp.coefs must be a matrix`);
|
|
46749
|
+
const coefs = coefsRT.data;
|
|
46750
|
+
const out = allocFloat64Array(L * (k + 1));
|
|
46751
|
+
for (let c = 0; c < k; c++) {
|
|
46752
|
+
for (let i = 0; i < L; i++) out[c * L + i] = coefs[c * L + i] / (k - c);
|
|
46753
|
+
}
|
|
46754
|
+
let A = 0;
|
|
46755
|
+
for (let i = 0; i < L; i++) {
|
|
46756
|
+
out[k * L + i] = A;
|
|
46757
|
+
const h = breaks[i + 1] - breaks[i];
|
|
46758
|
+
let v = out[0 * L + i];
|
|
46759
|
+
for (let c = 1; c <= k; c++) v = v * h + out[c * L + i];
|
|
46760
|
+
A = v;
|
|
46761
|
+
}
|
|
46762
|
+
const fields = /* @__PURE__ */ new Map();
|
|
46763
|
+
fields.set("form", "pp");
|
|
46764
|
+
const breaksOut = allocFloat64Array(breaks.length);
|
|
46765
|
+
for (let i = 0; i < breaks.length; i++) breaksOut[i] = breaks[i];
|
|
46766
|
+
fields.set("breaks", RTV.tensor(breaksOut, [1, breaks.length]));
|
|
46767
|
+
fields.set("coefs", RTV.tensor(out, [L, k + 1]));
|
|
46768
|
+
fields.set("pieces", L);
|
|
46769
|
+
fields.set("order", k + 1);
|
|
46770
|
+
fields.set("dim", 1);
|
|
46771
|
+
return RTV.struct(fields);
|
|
46772
|
+
};
|
|
46773
|
+
for (const fname of ["fnint", "ppint"]) {
|
|
46774
|
+
defineBuiltin({
|
|
46775
|
+
name: fname,
|
|
46776
|
+
cases: [
|
|
46777
|
+
{
|
|
46778
|
+
match: (argTypes) => {
|
|
46779
|
+
if (argTypes.length !== 1) return null;
|
|
46780
|
+
return [{ kind: "struct", fields: {} }];
|
|
46781
|
+
},
|
|
46782
|
+
apply: ppIntApply(fname)
|
|
46783
|
+
}
|
|
46784
|
+
]
|
|
46785
|
+
});
|
|
46786
|
+
}
|
|
46644
46787
|
defineBuiltin({
|
|
46645
46788
|
name: "mkpp",
|
|
46646
46789
|
cases: [
|
|
@@ -47382,6 +47525,8 @@ defineBuiltin({
|
|
|
47382
47525
|
{
|
|
47383
47526
|
match: (argTypes) => {
|
|
47384
47527
|
if (argTypes.length === 0) return [{ kind: "struct", fields: {} }];
|
|
47528
|
+
if (argTypes.length === 1 && argTypes[0].kind === "tensor")
|
|
47529
|
+
return [{ kind: "struct", fields: {} }];
|
|
47385
47530
|
if (argTypes.length % 2 !== 0) return null;
|
|
47386
47531
|
for (let i = 0; i < argTypes.length; i += 2) {
|
|
47387
47532
|
const k = argTypes[i].kind;
|
|
@@ -47391,6 +47536,13 @@ defineBuiltin({
|
|
|
47391
47536
|
},
|
|
47392
47537
|
apply: (args) => {
|
|
47393
47538
|
if (args.length === 0) return RTV.struct(/* @__PURE__ */ new Map());
|
|
47539
|
+
if (args.length === 1 && isRuntimeTensor(args[0])) {
|
|
47540
|
+
if (args[0].data.length !== 0)
|
|
47541
|
+
throw new RuntimeError(
|
|
47542
|
+
"struct: single non-empty numeric argument is not supported"
|
|
47543
|
+
);
|
|
47544
|
+
return RTV.structArray([], []);
|
|
47545
|
+
}
|
|
47394
47546
|
if (args.length % 2 !== 0)
|
|
47395
47547
|
throw new RuntimeError("struct: requires field-value pairs");
|
|
47396
47548
|
const fieldNames = [];
|
|
@@ -48183,13 +48335,48 @@ registerIBuiltin({
|
|
|
48183
48335
|
resolve: (argTypes) => {
|
|
48184
48336
|
if (argTypes.length !== 1) return null;
|
|
48185
48337
|
return {
|
|
48186
|
-
outputTypes: [{ kind: "
|
|
48338
|
+
outputTypes: [{ kind: "unknown" }],
|
|
48187
48339
|
apply: (args) => {
|
|
48188
48340
|
const C = args[0];
|
|
48189
48341
|
if (!isRuntimeCell(C))
|
|
48190
48342
|
throw new RuntimeError("cell2mat: argument must be a cell array");
|
|
48191
48343
|
const cellRows = C.shape[0];
|
|
48192
48344
|
const cellCols = C.shape.length >= 2 ? C.shape[1] : 1;
|
|
48345
|
+
if (C.data.length > 0 && C.data.some((v) => isRuntimeChar(v))) {
|
|
48346
|
+
const asCharBlock = (v) => {
|
|
48347
|
+
if (!isRuntimeChar(v))
|
|
48348
|
+
throw new RuntimeError(
|
|
48349
|
+
"cell2mat: cannot mix char and non-char cell contents"
|
|
48350
|
+
);
|
|
48351
|
+
const rows = v.shape ? v.shape[0] : v.value.length === 0 ? 0 : 1;
|
|
48352
|
+
const cols = v.shape ? v.shape[1] : v.value.length;
|
|
48353
|
+
const rowStrings = [];
|
|
48354
|
+
for (let r = 0; r < rows; r++)
|
|
48355
|
+
rowStrings.push(v.value.slice(r * cols, (r + 1) * cols));
|
|
48356
|
+
return { rows, cols, rowStrings };
|
|
48357
|
+
};
|
|
48358
|
+
const outRows = [];
|
|
48359
|
+
for (let ci = 0; ci < cellRows; ci++) {
|
|
48360
|
+
const blockHeight = asCharBlock(C.data[ci]).rows;
|
|
48361
|
+
const lines = new Array(blockHeight).fill("");
|
|
48362
|
+
for (let cj = 0; cj < cellCols; cj++) {
|
|
48363
|
+
const b = asCharBlock(C.data[cj * cellRows + ci]);
|
|
48364
|
+
if (b.rows !== blockHeight)
|
|
48365
|
+
throw new RuntimeError(
|
|
48366
|
+
"cell2mat: inconsistent cell content sizes"
|
|
48367
|
+
);
|
|
48368
|
+
for (let r = 0; r < blockHeight; r++) lines[r] += b.rowStrings[r];
|
|
48369
|
+
}
|
|
48370
|
+
outRows.push(...lines);
|
|
48371
|
+
}
|
|
48372
|
+
const width = outRows.length > 0 ? outRows[0].length : 0;
|
|
48373
|
+
if (outRows.some((r) => r.length !== width))
|
|
48374
|
+
throw new RuntimeError("cell2mat: inconsistent cell content sizes");
|
|
48375
|
+
if (outRows.length <= 1) return RTV.char(outRows[0] ?? "");
|
|
48376
|
+
const rc = RTV.char(outRows.join(""));
|
|
48377
|
+
rc.shape = [outRows.length, width];
|
|
48378
|
+
return rc;
|
|
48379
|
+
}
|
|
48193
48380
|
const asTensor = (v) => {
|
|
48194
48381
|
if (isRuntimeNumber(v))
|
|
48195
48382
|
return {
|
|
@@ -52060,14 +52247,20 @@ function dictRemove(d, keysArg) {
|
|
|
52060
52247
|
}
|
|
52061
52248
|
return RTV.dictionary(entries, d.keyType, d.valueType);
|
|
52062
52249
|
}
|
|
52063
|
-
function dictLookup(d, keysArg) {
|
|
52250
|
+
function dictLookup(d, keysArg, fallbackValue) {
|
|
52064
52251
|
const keys = expandKeys(keysArg);
|
|
52065
52252
|
const results = [];
|
|
52066
52253
|
for (const k of keys) {
|
|
52067
52254
|
const coerced = d.keyType ? coerceKey(k, d.keyType) : k;
|
|
52068
52255
|
const h = hashKey(coerced);
|
|
52069
52256
|
const entry = d.entries.get(h);
|
|
52070
|
-
if (!entry)
|
|
52257
|
+
if (!entry) {
|
|
52258
|
+
if (fallbackValue !== void 0) {
|
|
52259
|
+
results.push(fallbackValue);
|
|
52260
|
+
continue;
|
|
52261
|
+
}
|
|
52262
|
+
throw new RuntimeError("Key not found in dictionary");
|
|
52263
|
+
}
|
|
52071
52264
|
results.push(entry.value);
|
|
52072
52265
|
}
|
|
52073
52266
|
if (results.length === 1) return results[0];
|
|
@@ -52302,11 +52495,21 @@ registerIBuiltin({
|
|
|
52302
52495
|
registerIBuiltin({
|
|
52303
52496
|
name: "lookup",
|
|
52304
52497
|
resolve: (argTypes) => {
|
|
52305
|
-
if (argTypes.length !== 2 || argTypes[0].kind !== "dictionary")
|
|
52498
|
+
if (argTypes.length !== 2 && argTypes.length !== 4 || argTypes[0].kind !== "dictionary")
|
|
52499
|
+
return null;
|
|
52306
52500
|
return {
|
|
52307
52501
|
outputTypes: [{ kind: "unknown" }],
|
|
52308
52502
|
apply: (args) => {
|
|
52309
52503
|
const d = args[0];
|
|
52504
|
+
if (args.length === 4) {
|
|
52505
|
+
const optName = isRuntimeChar(args[2]) ? args[2].value : isRuntimeString(args[2]) ? args[2] : "";
|
|
52506
|
+
if (String(optName).toLowerCase() !== "fallbackvalue") {
|
|
52507
|
+
throw new RuntimeError(
|
|
52508
|
+
`Unrecognized option '${String(optName)}' for lookup`
|
|
52509
|
+
);
|
|
52510
|
+
}
|
|
52511
|
+
return dictLookup(d, args[1], args[3]);
|
|
52512
|
+
}
|
|
52310
52513
|
return dictLookup(d, args[1]);
|
|
52311
52514
|
}
|
|
52312
52515
|
};
|
|
@@ -52326,6 +52529,288 @@ registerIBuiltin({
|
|
|
52326
52529
|
}
|
|
52327
52530
|
});
|
|
52328
52531
|
|
|
52532
|
+
// src/numbl-core/interpreter/builtins/hash.ts
|
|
52533
|
+
function valueToByteString(v) {
|
|
52534
|
+
if (isRuntimeChar(v)) return v.value;
|
|
52535
|
+
if (isRuntimeString(v)) return String(v);
|
|
52536
|
+
throw new RuntimeError("hash: STR must be a char array or string");
|
|
52537
|
+
}
|
|
52538
|
+
function md5Hex(input) {
|
|
52539
|
+
const bytes = [];
|
|
52540
|
+
for (let i = 0; i < input.length; i++) bytes.push(input.charCodeAt(i) & 255);
|
|
52541
|
+
const origLenBits = bytes.length * 8;
|
|
52542
|
+
bytes.push(128);
|
|
52543
|
+
while (bytes.length % 64 !== 56) bytes.push(0);
|
|
52544
|
+
let len = origLenBits;
|
|
52545
|
+
for (let i = 0; i < 8; i++) {
|
|
52546
|
+
bytes.push(len & 255);
|
|
52547
|
+
len = Math.floor(len / 256);
|
|
52548
|
+
}
|
|
52549
|
+
const S = [
|
|
52550
|
+
7,
|
|
52551
|
+
12,
|
|
52552
|
+
17,
|
|
52553
|
+
22,
|
|
52554
|
+
7,
|
|
52555
|
+
12,
|
|
52556
|
+
17,
|
|
52557
|
+
22,
|
|
52558
|
+
7,
|
|
52559
|
+
12,
|
|
52560
|
+
17,
|
|
52561
|
+
22,
|
|
52562
|
+
7,
|
|
52563
|
+
12,
|
|
52564
|
+
17,
|
|
52565
|
+
22,
|
|
52566
|
+
5,
|
|
52567
|
+
9,
|
|
52568
|
+
14,
|
|
52569
|
+
20,
|
|
52570
|
+
5,
|
|
52571
|
+
9,
|
|
52572
|
+
14,
|
|
52573
|
+
20,
|
|
52574
|
+
5,
|
|
52575
|
+
9,
|
|
52576
|
+
14,
|
|
52577
|
+
20,
|
|
52578
|
+
5,
|
|
52579
|
+
9,
|
|
52580
|
+
14,
|
|
52581
|
+
20,
|
|
52582
|
+
4,
|
|
52583
|
+
11,
|
|
52584
|
+
16,
|
|
52585
|
+
23,
|
|
52586
|
+
4,
|
|
52587
|
+
11,
|
|
52588
|
+
16,
|
|
52589
|
+
23,
|
|
52590
|
+
4,
|
|
52591
|
+
11,
|
|
52592
|
+
16,
|
|
52593
|
+
23,
|
|
52594
|
+
4,
|
|
52595
|
+
11,
|
|
52596
|
+
16,
|
|
52597
|
+
23,
|
|
52598
|
+
6,
|
|
52599
|
+
10,
|
|
52600
|
+
15,
|
|
52601
|
+
21,
|
|
52602
|
+
6,
|
|
52603
|
+
10,
|
|
52604
|
+
15,
|
|
52605
|
+
21,
|
|
52606
|
+
6,
|
|
52607
|
+
10,
|
|
52608
|
+
15,
|
|
52609
|
+
21,
|
|
52610
|
+
6,
|
|
52611
|
+
10,
|
|
52612
|
+
15,
|
|
52613
|
+
21
|
|
52614
|
+
];
|
|
52615
|
+
const K = new Array(64);
|
|
52616
|
+
for (let i = 0; i < 64; i++)
|
|
52617
|
+
K[i] = Math.floor(Math.abs(Math.sin(i + 1)) * 4294967296) >>> 0;
|
|
52618
|
+
let a0 = 1732584193;
|
|
52619
|
+
let b0 = 4023233417;
|
|
52620
|
+
let c0 = 2562383102;
|
|
52621
|
+
let d0 = 271733878;
|
|
52622
|
+
const rotl2 = (x, c) => (x << c | x >>> 32 - c) >>> 0;
|
|
52623
|
+
for (let chunk = 0; chunk < bytes.length; chunk += 64) {
|
|
52624
|
+
const M = new Array(16);
|
|
52625
|
+
for (let j = 0; j < 16; j++) {
|
|
52626
|
+
const o = chunk + j * 4;
|
|
52627
|
+
M[j] = (bytes[o] | bytes[o + 1] << 8 | bytes[o + 2] << 16 | bytes[o + 3] << 24) >>> 0;
|
|
52628
|
+
}
|
|
52629
|
+
let A = a0;
|
|
52630
|
+
let B = b0;
|
|
52631
|
+
let C = c0;
|
|
52632
|
+
let D = d0;
|
|
52633
|
+
for (let i = 0; i < 64; i++) {
|
|
52634
|
+
let F;
|
|
52635
|
+
let g;
|
|
52636
|
+
if (i < 16) {
|
|
52637
|
+
F = B & C | ~B & D;
|
|
52638
|
+
g = i;
|
|
52639
|
+
} else if (i < 32) {
|
|
52640
|
+
F = D & B | ~D & C;
|
|
52641
|
+
g = (5 * i + 1) % 16;
|
|
52642
|
+
} else if (i < 48) {
|
|
52643
|
+
F = B ^ C ^ D;
|
|
52644
|
+
g = (3 * i + 5) % 16;
|
|
52645
|
+
} else {
|
|
52646
|
+
F = C ^ (B | ~D);
|
|
52647
|
+
g = 7 * i % 16;
|
|
52648
|
+
}
|
|
52649
|
+
F = F + A + K[i] + M[g] >>> 0;
|
|
52650
|
+
A = D;
|
|
52651
|
+
D = C;
|
|
52652
|
+
C = B;
|
|
52653
|
+
B = B + rotl2(F, S[i]) >>> 0;
|
|
52654
|
+
}
|
|
52655
|
+
a0 = a0 + A >>> 0;
|
|
52656
|
+
b0 = b0 + B >>> 0;
|
|
52657
|
+
c0 = c0 + C >>> 0;
|
|
52658
|
+
d0 = d0 + D >>> 0;
|
|
52659
|
+
}
|
|
52660
|
+
const le2 = (w) => {
|
|
52661
|
+
let s = "";
|
|
52662
|
+
for (let i = 0; i < 4; i++)
|
|
52663
|
+
s += (w >>> i * 8 & 255).toString(16).padStart(2, "0");
|
|
52664
|
+
return s;
|
|
52665
|
+
};
|
|
52666
|
+
return le2(a0) + le2(b0) + le2(c0) + le2(d0);
|
|
52667
|
+
}
|
|
52668
|
+
function sha256Hex(input) {
|
|
52669
|
+
const bytes = [];
|
|
52670
|
+
for (let i = 0; i < input.length; i++) bytes.push(input.charCodeAt(i) & 255);
|
|
52671
|
+
const origLenBits = bytes.length * 8;
|
|
52672
|
+
bytes.push(128);
|
|
52673
|
+
while (bytes.length % 64 !== 56) bytes.push(0);
|
|
52674
|
+
const hi = Math.floor(origLenBits / 4294967296);
|
|
52675
|
+
const lo = origLenBits >>> 0;
|
|
52676
|
+
for (let i = 3; i >= 0; i--) bytes.push(hi >>> i * 8 & 255);
|
|
52677
|
+
for (let i = 3; i >= 0; i--) bytes.push(lo >>> i * 8 & 255);
|
|
52678
|
+
const K = [
|
|
52679
|
+
1116352408,
|
|
52680
|
+
1899447441,
|
|
52681
|
+
3049323471,
|
|
52682
|
+
3921009573,
|
|
52683
|
+
961987163,
|
|
52684
|
+
1508970993,
|
|
52685
|
+
2453635748,
|
|
52686
|
+
2870763221,
|
|
52687
|
+
3624381080,
|
|
52688
|
+
310598401,
|
|
52689
|
+
607225278,
|
|
52690
|
+
1426881987,
|
|
52691
|
+
1925078388,
|
|
52692
|
+
2162078206,
|
|
52693
|
+
2614888103,
|
|
52694
|
+
3248222580,
|
|
52695
|
+
3835390401,
|
|
52696
|
+
4022224774,
|
|
52697
|
+
264347078,
|
|
52698
|
+
604807628,
|
|
52699
|
+
770255983,
|
|
52700
|
+
1249150122,
|
|
52701
|
+
1555081692,
|
|
52702
|
+
1996064986,
|
|
52703
|
+
2554220882,
|
|
52704
|
+
2821834349,
|
|
52705
|
+
2952996808,
|
|
52706
|
+
3210313671,
|
|
52707
|
+
3336571891,
|
|
52708
|
+
3584528711,
|
|
52709
|
+
113926993,
|
|
52710
|
+
338241895,
|
|
52711
|
+
666307205,
|
|
52712
|
+
773529912,
|
|
52713
|
+
1294757372,
|
|
52714
|
+
1396182291,
|
|
52715
|
+
1695183700,
|
|
52716
|
+
1986661051,
|
|
52717
|
+
2177026350,
|
|
52718
|
+
2456956037,
|
|
52719
|
+
2730485921,
|
|
52720
|
+
2820302411,
|
|
52721
|
+
3259730800,
|
|
52722
|
+
3345764771,
|
|
52723
|
+
3516065817,
|
|
52724
|
+
3600352804,
|
|
52725
|
+
4094571909,
|
|
52726
|
+
275423344,
|
|
52727
|
+
430227734,
|
|
52728
|
+
506948616,
|
|
52729
|
+
659060556,
|
|
52730
|
+
883997877,
|
|
52731
|
+
958139571,
|
|
52732
|
+
1322822218,
|
|
52733
|
+
1537002063,
|
|
52734
|
+
1747873779,
|
|
52735
|
+
1955562222,
|
|
52736
|
+
2024104815,
|
|
52737
|
+
2227730452,
|
|
52738
|
+
2361852424,
|
|
52739
|
+
2428436474,
|
|
52740
|
+
2756734187,
|
|
52741
|
+
3204031479,
|
|
52742
|
+
3329325298
|
|
52743
|
+
];
|
|
52744
|
+
const H2 = [
|
|
52745
|
+
1779033703,
|
|
52746
|
+
3144134277,
|
|
52747
|
+
1013904242,
|
|
52748
|
+
2773480762,
|
|
52749
|
+
1359893119,
|
|
52750
|
+
2600822924,
|
|
52751
|
+
528734635,
|
|
52752
|
+
1541459225
|
|
52753
|
+
];
|
|
52754
|
+
const rotr = (x, c) => (x >>> c | x << 32 - c) >>> 0;
|
|
52755
|
+
for (let chunk = 0; chunk < bytes.length; chunk += 64) {
|
|
52756
|
+
const W = new Array(64);
|
|
52757
|
+
for (let j = 0; j < 16; j++) {
|
|
52758
|
+
const o = chunk + j * 4;
|
|
52759
|
+
W[j] = (bytes[o] << 24 | bytes[o + 1] << 16 | bytes[o + 2] << 8 | bytes[o + 3]) >>> 0;
|
|
52760
|
+
}
|
|
52761
|
+
for (let j = 16; j < 64; j++) {
|
|
52762
|
+
const s0 = rotr(W[j - 15], 7) ^ rotr(W[j - 15], 18) ^ W[j - 15] >>> 3;
|
|
52763
|
+
const s1 = rotr(W[j - 2], 17) ^ rotr(W[j - 2], 19) ^ W[j - 2] >>> 10;
|
|
52764
|
+
W[j] = W[j - 16] + s0 + W[j - 7] + s1 >>> 0;
|
|
52765
|
+
}
|
|
52766
|
+
let [a, b, c, d, e, f, g, h] = H2;
|
|
52767
|
+
for (let j = 0; j < 64; j++) {
|
|
52768
|
+
const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
|
|
52769
|
+
const ch = e & f ^ ~e & g;
|
|
52770
|
+
const t1 = h + S1 + ch + K[j] + W[j] >>> 0;
|
|
52771
|
+
const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
|
|
52772
|
+
const maj = a & b ^ a & c ^ b & c;
|
|
52773
|
+
const t2 = S0 + maj >>> 0;
|
|
52774
|
+
h = g;
|
|
52775
|
+
g = f;
|
|
52776
|
+
f = e;
|
|
52777
|
+
e = d + t1 >>> 0;
|
|
52778
|
+
d = c;
|
|
52779
|
+
c = b;
|
|
52780
|
+
b = a;
|
|
52781
|
+
a = t1 + t2 >>> 0;
|
|
52782
|
+
}
|
|
52783
|
+
H2[0] = H2[0] + a >>> 0;
|
|
52784
|
+
H2[1] = H2[1] + b >>> 0;
|
|
52785
|
+
H2[2] = H2[2] + c >>> 0;
|
|
52786
|
+
H2[3] = H2[3] + d >>> 0;
|
|
52787
|
+
H2[4] = H2[4] + e >>> 0;
|
|
52788
|
+
H2[5] = H2[5] + f >>> 0;
|
|
52789
|
+
H2[6] = H2[6] + g >>> 0;
|
|
52790
|
+
H2[7] = H2[7] + h >>> 0;
|
|
52791
|
+
}
|
|
52792
|
+
return H2.map((w) => (w >>> 0).toString(16).padStart(8, "0")).join("");
|
|
52793
|
+
}
|
|
52794
|
+
registerIBuiltin({
|
|
52795
|
+
name: "hash",
|
|
52796
|
+
resolve: (argTypes) => {
|
|
52797
|
+
if (argTypes.length !== 2) return null;
|
|
52798
|
+
return {
|
|
52799
|
+
outputTypes: [{ kind: "char" }],
|
|
52800
|
+
apply: (args) => {
|
|
52801
|
+
const algoRaw = valueToByteString(args[0]);
|
|
52802
|
+
const algo = algoRaw.toUpperCase().replace(/-/g, "");
|
|
52803
|
+
const msg = valueToByteString(args[1]);
|
|
52804
|
+
if (algo === "MD5") return RTV.char(md5Hex(msg));
|
|
52805
|
+
if (algo === "SHA256") return RTV.char(sha256Hex(msg));
|
|
52806
|
+
throw new RuntimeError(
|
|
52807
|
+
`hash: unsupported hash function '${algoRaw}' (supported: MD5, SHA256)`
|
|
52808
|
+
);
|
|
52809
|
+
}
|
|
52810
|
+
};
|
|
52811
|
+
}
|
|
52812
|
+
});
|
|
52813
|
+
|
|
52329
52814
|
// src/numbl-core/interpreter/builtins/help-text.ts
|
|
52330
52815
|
var H = {
|
|
52331
52816
|
// ── Math ──────────────────────────────────────────────────────────────
|
|
@@ -56384,33 +56869,66 @@ function registerSpecialBuiltins(rt) {
|
|
|
56384
56869
|
};
|
|
56385
56870
|
}
|
|
56386
56871
|
});
|
|
56872
|
+
const warningStateOff = /* @__PURE__ */ new Set();
|
|
56387
56873
|
registerSpecial("warning", (nargout, args) => {
|
|
56388
56874
|
if (args.length === 0) return nargout >= 1 ? RTV.num(0) : void 0;
|
|
56389
56875
|
const margs = args.map((a) => ensureRuntimeValue(a));
|
|
56876
|
+
const isOff = (id) => warningStateOff.has(id) || warningStateOff.has("all");
|
|
56877
|
+
const stateStruct = (id) => RTV.struct(
|
|
56878
|
+
/* @__PURE__ */ new Map([
|
|
56879
|
+
["identifier", RTV.char(id)],
|
|
56880
|
+
["state", RTV.char(isOff(id) ? "off" : "on")]
|
|
56881
|
+
])
|
|
56882
|
+
);
|
|
56883
|
+
const setState = (mode, id) => {
|
|
56884
|
+
if (mode === "off") warningStateOff.add(id);
|
|
56885
|
+
else {
|
|
56886
|
+
warningStateOff.delete(id);
|
|
56887
|
+
if (id === "all") warningStateOff.clear();
|
|
56888
|
+
}
|
|
56889
|
+
};
|
|
56890
|
+
const restoreFrom = (s) => {
|
|
56891
|
+
if (!isRuntimeStruct(s)) return false;
|
|
56892
|
+
const idField = s.fields.get("identifier");
|
|
56893
|
+
const stField = s.fields.get("state");
|
|
56894
|
+
if (idField === void 0 || stField === void 0) return false;
|
|
56895
|
+
setState(toString(stField), toString(idField));
|
|
56896
|
+
return true;
|
|
56897
|
+
};
|
|
56898
|
+
if (margs.length === 1 && isRuntimeStruct(margs[0])) {
|
|
56899
|
+
if (restoreFrom(margs[0])) return nargout >= 1 ? RTV.num(0) : void 0;
|
|
56900
|
+
}
|
|
56901
|
+
if (margs.length === 1 && isRuntimeStructArray(margs[0])) {
|
|
56902
|
+
for (const el of margs[0].elements) restoreFrom(el);
|
|
56903
|
+
return nargout >= 1 ? RTV.num(0) : void 0;
|
|
56904
|
+
}
|
|
56905
|
+
if (margs.length === 1 && isRuntimeChar(margs[0])) {
|
|
56906
|
+
const mode = toString(margs[0]);
|
|
56907
|
+
if (mode === "on" || mode === "off") {
|
|
56908
|
+
const prev = stateStruct("all");
|
|
56909
|
+
setState(mode, "all");
|
|
56910
|
+
return nargout >= 1 ? prev : void 0;
|
|
56911
|
+
}
|
|
56912
|
+
}
|
|
56390
56913
|
if (margs.length === 2 && isRuntimeChar(margs[0]) && isRuntimeChar(margs[1])) {
|
|
56391
56914
|
const mode = toString(margs[0]);
|
|
56915
|
+
const id = toString(margs[1]);
|
|
56392
56916
|
if (mode === "on" || mode === "off") {
|
|
56393
|
-
|
|
56394
|
-
|
|
56395
|
-
|
|
56396
|
-
["state", RTV.char("on")],
|
|
56397
|
-
["identifier", margs[1]]
|
|
56398
|
-
])
|
|
56399
|
-
);
|
|
56917
|
+
const prev = stateStruct(id);
|
|
56918
|
+
setState(mode, id);
|
|
56919
|
+
return nargout >= 1 ? prev : void 0;
|
|
56400
56920
|
}
|
|
56401
56921
|
if (mode === "query") {
|
|
56402
|
-
return
|
|
56403
|
-
/* @__PURE__ */ new Map([
|
|
56404
|
-
["state", RTV.char("on")],
|
|
56405
|
-
["identifier", margs[1]]
|
|
56406
|
-
])
|
|
56407
|
-
);
|
|
56922
|
+
return stateStruct(id);
|
|
56408
56923
|
}
|
|
56409
56924
|
}
|
|
56410
56925
|
let fmtIdx = 0;
|
|
56411
56926
|
if (margs.length >= 2 && isRuntimeChar(margs[0]) && toString(margs[0]).includes(":")) {
|
|
56412
56927
|
fmtIdx = 1;
|
|
56413
56928
|
}
|
|
56929
|
+
if (isOff(fmtIdx === 1 ? toString(margs[0]) : "all")) {
|
|
56930
|
+
return nargout >= 1 ? RTV.num(0) : void 0;
|
|
56931
|
+
}
|
|
56414
56932
|
const fmt = toString(margs[fmtIdx]);
|
|
56415
56933
|
const fmtArgs = [];
|
|
56416
56934
|
for (let i = fmtIdx + 1; i < margs.length; i++) {
|
|
@@ -60554,7 +61072,7 @@ function multiOutputCellAssign(base, indices, results, rt) {
|
|
|
60554
61072
|
}
|
|
60555
61073
|
|
|
60556
61074
|
// src/numbl-core/runtime/runtimeMemberAccess.ts
|
|
60557
|
-
function getMember(rt, base, name) {
|
|
61075
|
+
function getMember(rt, base, name, nargout = 1) {
|
|
60558
61076
|
const mv = ensureRuntimeValue(base);
|
|
60559
61077
|
if (isRuntimeClassInstance(mv)) {
|
|
60560
61078
|
const accessorKey = `${mv.className}.get.${name}`;
|
|
@@ -60573,7 +61091,7 @@ function getMember(rt, base, name) {
|
|
|
60573
61091
|
if (field !== void 0) return field;
|
|
60574
61092
|
const method = rt.cachedResolveClassMethod(mv.className, name);
|
|
60575
61093
|
if (method) {
|
|
60576
|
-
return method(
|
|
61094
|
+
return method(nargout, base);
|
|
60577
61095
|
}
|
|
60578
61096
|
const guardKey = `${mv.className}.subsref`;
|
|
60579
61097
|
if (!rt.activeAccessors.has(guardKey)) {
|
|
@@ -63277,8 +63795,8 @@ var Runtime = class _Runtime {
|
|
|
63277
63795
|
return multiOutputCellAssign(base, indices, results, this);
|
|
63278
63796
|
}
|
|
63279
63797
|
// ── Member access ───────────────────────────────────────────────────
|
|
63280
|
-
getMember(base, name) {
|
|
63281
|
-
return getMember(this, base, name);
|
|
63798
|
+
getMember(base, name, nargout = 1) {
|
|
63799
|
+
return getMember(this, base, name, nargout);
|
|
63282
63800
|
}
|
|
63283
63801
|
getMemberDynamic(base, nameExpr) {
|
|
63284
63802
|
return getMemberDynamic(this, base, nameExpr);
|
|
@@ -66106,7 +66624,7 @@ function evalMember(expr, nargout) {
|
|
|
66106
66624
|
(el) => ensureRuntimeValue(this.rt.getMember(el, expr.name))
|
|
66107
66625
|
);
|
|
66108
66626
|
}
|
|
66109
|
-
return this.rt.getMember(base, expr.name);
|
|
66627
|
+
return this.rt.getMember(base, expr.name, nargout);
|
|
66110
66628
|
}
|
|
66111
66629
|
function tryExtractDottedName(expr) {
|
|
66112
66630
|
if (expr.type === "Ident") return expr.name;
|
|
@@ -66117,7 +66635,14 @@ function tryExtractDottedName(expr) {
|
|
|
66117
66635
|
return null;
|
|
66118
66636
|
}
|
|
66119
66637
|
function evalIndex(expr) {
|
|
66120
|
-
|
|
66638
|
+
let base = this.evalExpr(expr.base);
|
|
66639
|
+
if (Array.isArray(base)) {
|
|
66640
|
+
if (base.length === 1) base = base[0];
|
|
66641
|
+
else
|
|
66642
|
+
throw new RuntimeError(
|
|
66643
|
+
`Expression produced ${base.length} values where one was expected`
|
|
66644
|
+
);
|
|
66645
|
+
}
|
|
66121
66646
|
const indices = this.evalIndicesWithEnd(base, expr.indices);
|
|
66122
66647
|
let skipSubsref = false;
|
|
66123
66648
|
if (this.currentClassName) {
|
|
@@ -69202,7 +69727,11 @@ var stdlibFiles = [
|
|
|
69202
69727
|
},
|
|
69203
69728
|
{
|
|
69204
69729
|
name: "inputParser.m",
|
|
69205
|
-
source: "classdef inputParser < handle\n properties\n CaseSensitive = false\n FunctionName = ''\n KeepUnmatched = false\n PartialMatching = true\n StructExpand = true\n Results = struct()\n Unmatched = struct()\n UsingDefaults = {}\n Parameters = {}\n end\n properties\n required_ = {}\n optional_ = {}\n params_ = {}\n end\n methods\n function addRequired(obj, name, validator)\n if nargin < 3\n validator = [];\n end\n entry = struct('name', name, 'default', {[]}, 'validator', {{}});\n if ~isempty(validator)\n entry.validator = validator;\n end\n obj.required_{end+1} = entry;\n obj.Parameters{end+1} = name;\n end\n\n function addOptional(obj, name, default, validator)\n if nargin < 4\n validator = [];\n end\n entry = struct('name', name, 'default', {default}, 'validator', {{}});\n if ~isempty(validator)\n entry.validator = validator;\n end\n obj.optional_{end+1} = entry;\n obj.Parameters{end+1} = name;\n end\n\n function addParameter(obj, name, default, validator)\n if nargin < 4\n validator = [];\n end\n entry = struct('name', name, 'default', {default}, 'validator', {{}});\n if ~isempty(validator)\n entry.validator = validator;\n end\n obj.params_{end+1} = entry;\n obj.Parameters{end+1} = name;\n end\n\n function addParamValue(obj, name, default, validator)\n addParameter(obj, name, default, validator);\n end\n\n function parse(obj, varargin)\n s = struct();\n usingDefaults = {};\n pos = 1;\n nargs = numel(varargin);\n\n % Parse required arguments\n for i = 1:numel(obj.required_)\n entry = obj.required_{i};\n if pos > nargs\n error('Not enough input arguments. Missing required argument ''%s''.', entry.name);\n end\n val = varargin{pos};\n pos = pos + 1;\n s.(entry.name) = val;\n end\n\n % Parse optional positional arguments\n % An optional arg is consumed only if it is NOT a string matching a parameter name\n for i = 1:numel(obj.optional_)\n entry = obj.optional_{i};\n if pos <= nargs\n nextVal = varargin{pos};\n isParamName = false;\n if ischar(nextVal) || isstring(nextVal)\n paramName = char(nextVal);\n for k = 1:numel(obj.params_)\n pentry = obj.params_{k};\n if inputParser.namesMatch(paramName, pentry.name, obj.CaseSensitive)\n isParamName = true;\n break;\n end\n end\n end\n if ~isParamName\n s.(entry.name) = nextVal;\n pos = pos + 1;\n else\n s.(entry.name) = entry.default;\n usingDefaults{end+1} = entry.name;\n end\n else\n s.(entry.name) = entry.default;\n usingDefaults{end+1} = entry.name;\n end\n end\n\n % Set defaults for all parameters\n for i = 1:numel(obj.params_)\n entry = obj.params_{i};\n s.(entry.name) = entry.default;\n usingDefaults{end+1} = entry.name;\n end\n\n % Parse name-value pairs from remaining arguments\n unmatched = struct();\n while pos <= nargs\n if pos + 1 > nargs\n error('Expected name-value pair argument.');\n end\n name = varargin{pos};\n val = varargin{pos + 1};\n pos = pos + 2;\n\n if ~ischar(name) && ~isstring(name)\n error('Expected parameter name to be a string.');\n end\n name = char(name);\n\n found = false;\n for i = 1:numel(
|
|
69730
|
+
source: "classdef inputParser < handle\n properties\n CaseSensitive = false\n FunctionName = ''\n KeepUnmatched = false\n PartialMatching = true\n StructExpand = true\n Results = struct()\n Unmatched = struct()\n UsingDefaults = {}\n Parameters = {}\n end\n properties\n required_ = {}\n optional_ = {}\n params_ = {}\n end\n methods\n function addRequired(obj, name, validator)\n if nargin < 3\n validator = [];\n end\n entry = struct('name', name, 'default', {[]}, 'validator', {{}});\n if ~isempty(validator)\n entry.validator = validator;\n end\n obj.required_{end+1} = entry;\n obj.Parameters{end+1} = name;\n end\n\n function addOptional(obj, name, default, validator)\n if nargin < 4\n validator = [];\n end\n entry = struct('name', name, 'default', {default}, 'validator', {{}});\n if ~isempty(validator)\n entry.validator = validator;\n end\n obj.optional_{end+1} = entry;\n obj.Parameters{end+1} = name;\n end\n\n function addParameter(obj, name, default, validator)\n if nargin < 4\n validator = [];\n end\n entry = struct('name', name, 'default', {default}, 'validator', {{}});\n if ~isempty(validator)\n entry.validator = validator;\n end\n obj.params_{end+1} = entry;\n obj.Parameters{end+1} = name;\n end\n\n function addParamValue(obj, name, default, validator)\n if nargin < 4\n addParameter(obj, name, default);\n else\n addParameter(obj, name, default, validator);\n end\n end\n\n function parse(obj, varargin)\n s = struct();\n usingDefaults = {};\n pos = 1;\n nargs = numel(varargin);\n\n % Parse required arguments\n for i = 1:numel(obj.required_)\n entry = obj.required_{i};\n if pos > nargs\n error('Not enough input arguments. Missing required argument ''%s''.', entry.name);\n end\n val = varargin{pos};\n pos = pos + 1;\n s.(entry.name) = val;\n end\n\n % Parse optional positional arguments\n % An optional arg is consumed only if it is NOT a string matching a\n % parameter or optional name (MATLAB also accepts optionals as\n % name-value pairs, so their names terminate positional parsing)\n for i = 1:numel(obj.optional_)\n entry = obj.optional_{i};\n if pos <= nargs\n nextVal = varargin{pos};\n isParamName = false;\n if ischar(nextVal) || isstring(nextVal)\n paramName = char(nextVal);\n for k = 1:numel(obj.params_)\n pentry = obj.params_{k};\n if inputParser.namesMatch(paramName, pentry.name, obj.CaseSensitive)\n isParamName = true;\n break;\n end\n end\n if ~isParamName\n for k = 1:numel(obj.optional_)\n oentry = obj.optional_{k};\n if inputParser.namesMatch(paramName, oentry.name, obj.CaseSensitive)\n isParamName = true;\n break;\n end\n end\n end\n end\n if ~isParamName\n s.(entry.name) = nextVal;\n pos = pos + 1;\n else\n s.(entry.name) = entry.default;\n usingDefaults{end+1} = entry.name;\n end\n else\n s.(entry.name) = entry.default;\n usingDefaults{end+1} = entry.name;\n end\n end\n\n % Set defaults for all parameters\n for i = 1:numel(obj.params_)\n entry = obj.params_{i};\n s.(entry.name) = entry.default;\n usingDefaults{end+1} = entry.name;\n end\n\n % Parse name-value pairs from remaining arguments\n unmatched = struct();\n while pos <= nargs\n if pos + 1 > nargs\n error('Expected name-value pair argument.');\n end\n name = varargin{pos};\n val = varargin{pos + 1};\n pos = pos + 2;\n\n if ~ischar(name) && ~isstring(name)\n error('Expected parameter name to be a string.');\n end\n name = char(name);\n\n found = false;\n % Optionals may also be passed by name (undocumented MATLAB\n % behavior relied on by real-world code)\n candidates = [obj.params_, obj.optional_];\n for i = 1:numel(candidates)\n entry = candidates{i};\n if inputParser.namesMatch(name, entry.name, obj.CaseSensitive)\n s.(entry.name) = val;\n % Remove from usingDefaults\n newDefaults = {};\n for j = 1:numel(usingDefaults)\n if ~strcmp(usingDefaults{j}, entry.name)\n newDefaults{end+1} = usingDefaults{j};\n end\n end\n usingDefaults = newDefaults;\n found = true;\n break;\n end\n end\n if ~found\n if obj.KeepUnmatched\n unmatched.(name) = val;\n else\n error('''%s'' is not a recognized parameter.', name);\n end\n end\n end\n\n obj.Results = s;\n obj.UsingDefaults = usingDefaults;\n obj.Unmatched = unmatched;\n end\n end\n\n methods (Static)\n function tf = namesMatch(input, expected, caseSensitive)\n if caseSensitive\n tf = strcmp(input, expected);\n else\n tf = strcmpi(input, expected);\n end\n end\n end\nend\n"
|
|
69731
|
+
},
|
|
69732
|
+
{
|
|
69733
|
+
name: "normalize.m",
|
|
69734
|
+
source: "function Y = normalize(X, method, p)\n % normalize(X) z-score along the first non-singleton dimension\n % normalize(X, 'zscore') same as above\n % normalize(X, 'norm') divide by the 2-norm along that dimension\n % normalize(X, 'norm', p) divide by the p-norm (p = Inf -> max abs)\n if nargin < 2\n method = 'zscore';\n end\n if size(X, 1) == 1\n dim = 2;\n else\n dim = 1;\n end\n switch lower(method)\n case 'zscore'\n mu = mean(X, dim);\n sigma = std(X, 0, dim);\n Y = (X - mu) ./ sigma;\n case 'norm'\n if nargin < 3\n p = 2;\n end\n if isinf(p)\n n = max(abs(X), [], dim);\n else\n n = sum(abs(X) .^ p, dim) .^ (1 / p);\n end\n Y = X ./ n;\n otherwise\n error('normalize: unsupported method ''%s''', method);\n end\nend\n"
|
|
69206
69735
|
},
|
|
69207
69736
|
{
|
|
69208
69737
|
name: "parse.m",
|
|
@@ -69393,6 +69922,7 @@ var shimFiles = [
|
|
|
69393
69922
|
end
|
|
69394
69923
|
|
|
69395
69924
|
function result = keys(obj)
|
|
69925
|
+
% MATLAB's containers.Map returns keys in sorted order
|
|
69396
69926
|
if obj.Count == 0
|
|
69397
69927
|
result = {};
|
|
69398
69928
|
return;
|
|
@@ -69408,6 +69938,8 @@ var shimFiles = [
|
|
|
69408
69938
|
for i = 1:numel(k)
|
|
69409
69939
|
result{i} = char(k{i});
|
|
69410
69940
|
end
|
|
69941
|
+
% MATLAB returns a sorted 1xN row cell
|
|
69942
|
+
result = reshape(sort(result), 1, []);
|
|
69411
69943
|
else
|
|
69412
69944
|
% Numeric keys: parse back from string
|
|
69413
69945
|
if iscell(k)
|
|
@@ -69418,17 +69950,27 @@ var shimFiles = [
|
|
|
69418
69950
|
else
|
|
69419
69951
|
result = {str2double(k)};
|
|
69420
69952
|
end
|
|
69953
|
+
result = reshape(num2cell(sort(cell2mat(result))), 1, []);
|
|
69421
69954
|
end
|
|
69422
69955
|
end
|
|
69423
69956
|
|
|
69424
69957
|
function result = values(obj)
|
|
69958
|
+
% Ordered to correspond with keys() (i.e. key-sorted)
|
|
69425
69959
|
if obj.Count == 0
|
|
69426
69960
|
result = {};
|
|
69427
69961
|
return;
|
|
69428
69962
|
end
|
|
69429
|
-
|
|
69963
|
+
sortedKeys = keys(obj);
|
|
69964
|
+
v = cell(1, obj.Count);
|
|
69965
|
+
for i = 1:obj.Count
|
|
69966
|
+
v{i} = obj.data_(makeKey(sortedKeys{i}, obj.KeyType));
|
|
69967
|
+
end
|
|
69430
69968
|
if strcmp(obj.ValueType, 'any')
|
|
69431
|
-
|
|
69969
|
+
% Values are stored cell-wrapped (see subsasgn); unwrap each
|
|
69970
|
+
result = cell(1, obj.Count);
|
|
69971
|
+
for i = 1:obj.Count
|
|
69972
|
+
result{i} = v{i}{1};
|
|
69973
|
+
end
|
|
69432
69974
|
else
|
|
69433
69975
|
if iscell(v)
|
|
69434
69976
|
result = v;
|