Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/dvd101x/mathjs into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
dvd101x committed Aug 5, 2023
2 parents 75e6c70 + 49c793b commit e2bdd4a
Show file tree
Hide file tree
Showing 82 changed files with 5,164 additions and 3,195 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x]
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v3
Expand Down
6 changes: 6 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -224,5 +224,11 @@ David Contreras <david.contreras@guentner.com>
Jakub Riegel <jakubriegel112@gmail.com>
Angus Comrie <accomrie@gmail.com>
TMTron <martin.trummer@tmtron.com>
Maxim Mazurok <maxim@mazurok.com>
kunalagrwl <kunalaggarwal82@gmail.com>
Michael Greminger <michael.greminger@gmail.com>
Kiku <kiku-cn@foxmail.com>
MaybePixem <47889538+MaybePixem@users.noreply.github.com>
Aly Khaled <alykhaled2001@live.com>

# Generated by tools/update-authors.js
55 changes: 54 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,59 @@
# History

# 2023-04-03 11.8.0
# unpublished changes since 11.9.1

- Fix #2990: `DenseMatrix` can mutate input arrays (#2991).


# 2023-07-24, 11.9.1

- Fix a security vulnerability in `FunctionNode` and `SymbolNode` allowing
arbitrary code execution via `math.evaluate`. Thanks Harry Chen.
- Fix #3001: mathjs bundle containing `new Function(...)` (CSP issue).


# 2023-07-19, 11.9.0

- Implement function `solveODE` (#2958). Thanks @dvd101x.
- Implement functions `zpk2tf` and `freqz` (#2988, #2969). Thanks @alykhaled.
- Implement support for units in function `range` (#2997). Thanks @dvd101x.
- Fix #2974: `simplify` puts plus and minus signs next to each other (#2981).
Thanks @MaybePixem.
- Fix #2973: fixes and improvements in the embedded docs (#2976).
Thanks @dvd101x.
- Fix #2996: two errors in the examples in the documentation about Expression
trees.
- Fix round-off errors near zero when converting temperatures (#2962).
Thanks @costerwi.
- Refactored function `range`, reducing the amount of code (#2995).
Thanks @dvd101x.


# 2023-06-20, 11.8.2

- Fix #2971: improve typings of statistics functions `min`, `max`, `mean`,
`median`, `mode`, `std`, `sum`, `prod`, `variance`. Fixes a regression
introduced in v11.8.1.
- Fix #2972: type definitions of `Unit.divide(Unit)` have a wrong return type.


# 2023-06-13, 11.8.1

- Fix #2964: issue in function ` distance` when calculate the distance from
a point to a line (#2965). Thanks @Kiku-CN.
- Fix `math.format` not working correctly for `engineering` notation when using
BigNumbers and for `fixed` notation with `precision: 0` configured (#2956).
Thanks @mgreminger.
- Fix #2880: not possible to map cube root `cbrt`.
- Fix #2938: make the syntax description of all functions consistent in the
docs (#2941). Thanks @dvd101x.
- Fix #2954: improve the TypeScript definitions the return type of functions
`min` and `max` (#2955). Thanks @Maxim-Mazurok.
- Fix #2959: typo in an example in the docs. Thanks @kunalagrwl.
- Drop official support for Node.js 14, has reached end of life.


# 2023-04-03, 11.8.0

- Extended functions `fraction`, `bignumber`, and `number` with support for
units, see #2918 (#2926).
Expand Down
43 changes: 43 additions & 0 deletions docs/datatypes/matrices.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,49 @@ method `.set()`, the matrix will be resized. By default, new items will be
initialized with zero, but it is possible to specify an alternative value using
the optional third argument `defaultValue`.

## Advanced Indexing

Boolean array indexing is a technique that allows you to filter, replace, and set values in an array based on logical conditions. This can be done by creating a boolean array that represents the desired conditions, and then using that array as an index to select the elements of the original array that meet those conditions.

For example, a boolean array can be created to represent all the even numbers in an array, and then used to filter the original array to only include the even numbers. Alternatively, a boolean array can be created to represent all the elements of an array that are greater than a certain value, and then used to replace all the elements of the original array that are greater than that value with a new value.


```js
const q = [1, 2, 3, 4]
math.subset(q, math.index([true, false, true, false])) // Array [1, 3]

// filtering
math.subset(q, math.index(math.larger(q, 2))) // Array [3, 4]

// filtering with no matches
math.subset(q, math.index(math.larger(q, 5))) // Array []

// setting specific values, please note that the replacement value is broadcasted
q = math.subset(q, math.index(math.smaller(q, 3)), 0) // q = [0, 0, 3, 4]

// replacing specific values
math.subset(q, math.index(math.equal(q, 0)), [1, 2]) // q = [1, 2, 3, 4]
```

The same can be accomplished in the parser in a much more compact manner. Please note that everything after `#` are comments.
```js
math.evaluate(`
q = [1, 2, 3, 4]
q[[true, false, true, false]] # Matrix [1, 3]
q[q>2] # Matrix [3, 4]
q[q>5] # Matrix []
q[q <3] = 0 # q = [0, 0, 3, 4]
q[q==0] = [1, 2] # q = [1, 2, 3, 4]
`)
```
The expression inside the index can be as complex as needed as long it evaluates to an array of booleans of the same size.
```js
math.evaluate(`
q = [1, 2, 3, 4]
r = [6, 5, 4, 3]
q[q > 3 and r < 4] # [4]
`)
```

## Iterating

Expand Down
5 changes: 3 additions & 2 deletions docs/expressions/expression_trees.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ Examples:
const node1 = math.parse('a[3]')
const object = new math.SymbolNode('a')
const index = new math.IndexNode([3])
const constant3 = new math.ConstantNode(3)
const index = new math.IndexNode([constant3])
const node2 = new math.AccessorNode(object, index)
```

Expand Down Expand Up @@ -527,7 +528,7 @@ const three = new math.ConstantNode(3)

const range = new math.RangeNode(one, three)
const index = new math.IndexNode([range, two])
const node2 = new math.AccessNode(A, index)
const node2 = new math.AccessorNode(A, index)
```

### ObjectNode
Expand Down
2 changes: 1 addition & 1 deletion docs/expressions/parsing.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ parser.evaluate('f(x, y) = x^y') // f(x, y)
parser.evaluate('f(2, 3)') // 8

// get and set variables and functions
const x = parser.get('x') // x = 7
const x = parser.get('x') // x = 3.5
const f = parser.get('f') // function
const g = f(3, 3) // g = 27
parser.set('h', 500)
Expand Down
3 changes: 2 additions & 1 deletion gulpfile.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const del = require('del')
const log = require('fancy-log')
const webpack = require('webpack')
const babel = require('gulp-babel')
const mkdirp = require('mkdirp')
const { mkdirp } = require('mkdirp')
const docgenerator = require('./tools/docgenerator')
const entryGenerator = require('./tools/entryGenerator')
const validateAsciiChars = require('./tools/validateAsciiChars')
Expand Down Expand Up @@ -85,6 +85,7 @@ const webpackConfig = {
globalObject: 'this',
filename: FILE
},
node: false, // to make sure Webpack doesn't generate 'new Function("return this")' in the bundle output, see https://github.com/josdejong/mathjs/issues/3001
plugins: [
bannerPlugin
// new webpack.optimize.ModuleConcatenationPlugin()
Expand Down
Loading

0 comments on commit e2bdd4a

Please sign in to comment.