Skip to content

Commit a8ec24d

Browse files
committed
docs: some updates in the description to migrate matrix index behavior to v15 (see #3485)
1 parent 7dda1d7 commit a8ec24d

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

docs/datatypes/matrices.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -333,23 +333,18 @@ c.subset(math.index(1, [0, 1]), [2, 3]) // Matrix, [[0, 1], [2, 3]]
333333
e.resize([2, 3], 0) // Matrix, [[0, 0, 0], [0, 0, 0]]
334334
e.subset(math.index(1, 2), 5) // Matrix, [[0, 0, 0], [0, 0, 5]]
335335
```
336-
## Migrate to v15
337336

338-
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
339338

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.
341340

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`:
348342

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+
```
351346

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:
353348

354349
```js
355350
const m = math.matrix([[1, 2, 3], [4, 5, 6]])

docs/expressions/syntax.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -680,9 +680,7 @@ resolving of the nested index needs to be split in two separate operations.
680680
in JavaScript: They are one-based with an included upper-bound, similar to most
681681
math applications.*
682682

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).*
686684

687685
```js
688686
parser = math.parser()
@@ -705,11 +703,17 @@ parser.evaluate('d[2, 1:end]') // Matrix, [43, 50]
705703
parser.evaluate('c[end - 1 : -1 : 2]') // Matrix, [8, 7, 6]
706704
```
707705

708-
#### Matrix Migration examples
706+
#### Migrate matrix indexing to mathjs v15
709707

710-
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.
711709

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:
713717

714718
```js
715719
parser = math.parser()

0 commit comments

Comments
 (0)