You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the release of math.js v15, the behavior of `subset` when indexing matrices and arrays has changed. If your code relies on the previous behavior (where indexing with an array or matrix of size 1 would always return the value itself), you may need to update your code or enable legacy mode.
337
+
## Migrate indexing behavior to mathjs v15
339
338
340
-
### How to migrate
339
+
With the release of math.js v15, the behavior of `subset` when indexing matrices and arrays has changed. If your code relies on the previous behavior (where indexing with an array or matrix of size 1 would always return the value itself), you may need to update your code or enable legacy mode.
341
340
342
-
-**Option 1: Enable legacy behavior**
343
-
If you want your code to work as before without changes, enable legacy mode by adding:
344
-
```js
345
-
math.config({ legacySubset:true })
346
-
```
347
-
This restores the old behavior for `subset`.
341
+
To maintain the old indexing behavior without need for any code changes, use the configuration option `legacySubset`:
348
342
349
-
-**Option 2: Update your code**
350
-
Update your code to use scalar indices when you want to eliminate dimensions, or use array indices to preserve dimensions.
343
+
```js
344
+
math.config({ legacySubset:true })
345
+
```
351
346
352
-
### Migration examples
347
+
To migrate your code, you'll have to change all matrix indexes from the old index notation to the new index notation. Basically: scalar indexes have to be wrapped in array brackets if you want an array as output. Here some examples:
Copy file name to clipboardExpand all lines: docs/expressions/syntax.md
+10-6Lines changed: 10 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -680,9 +680,7 @@ resolving of the nested index needs to be split in two separate operations.
680
680
in JavaScript: They are one-based with an included upper-bound, similar to most
681
681
math applications.*
682
682
683
-
*IMPORTANT: Matrix indexing behaves differently depending on the type of input.
684
-
If an index for a dimension is a scalar (single value), that dimension is
685
-
removed from the result. For more information of the changes go to [Migrate to V15](../datatypes/matrices.md#migrate-to-v15).*
683
+
*IMPORTANT: The matrix indexing behavior has been changed in mathjs `v15`, see section [Migrate matrix indexing to mathjs v15](#migrate-matrix-indexing-to-mathjs-v15).*
With v15, matrix indexing has changed to be more consistent and predictable. In v14, using a scalar index would sometimes reduce the dimensionality of the result. In v15, if you want to preserve dimensions, use array, matrix, or range indices. If you want a scalar value, use scalar indices.
708
+
With mathjs v15, matrix indexing has changed to be more consistent and predictable. In v14, using a scalar index would sometimes reduce the dimensionality of the result. In v15, if you want to preserve dimensions, use array, matrix, or range indices. If you want a scalar value, use scalar indices.
711
709
712
-
For example:
710
+
To maintain the old indexing behavior without need for any code changes, use the configuration option `legacySubset`:
711
+
712
+
```js
713
+
math.config({ legacySubset:true })
714
+
```
715
+
716
+
To migrate your code, you'll have to change all matrix indexes from the old index notation to the new index notation. Basically: scalar indexes have to be wrapped in array brackets if you want an array as output. Here some examples:
0 commit comments