Skip to content

Commit

Permalink
Merge branch 'develop' into deepMap-2
Browse files Browse the repository at this point in the history
  • Loading branch information
dvd101x authored Dec 6, 2024
2 parents c7a4210 + ea41b03 commit 488628c
Show file tree
Hide file tree
Showing 91 changed files with 2,944 additions and 2,295 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/browserstack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ on:
- '*'
tags:

# Allow only one concurrent test
concurrency:
group: "browserstack"
cancel-in-progress: false

jobs:
browser-tests:
runs-on: ubuntu-latest
Expand All @@ -14,7 +19,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
node-version: 22.x
- run: npm ci
- run: npm run test:browserstack
env:
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ jobs:
with:
node-version: 20.x
- run: npm ci
- run: npm run coverage && npx codecov
- run: npm run coverage
env:
CI: true
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true

build-and-test:
runs-on: ubuntu-latest
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/hyperexecute.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Hyperexecute
on:
workflow_dispatch:
inputs:
username:
required: true
description: LT Username
accessKey:
description: LT Access Key
required: true
sampleRepoLink:
description: Link to the HyperExecute sample repo
default: https://github.com/gauravchawhan/mathjs
required: true
jobs:
HyperExecute-Playwright:
runs-on: ${{ matrix.os }}
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
os: [windows-latest]
steps:
- name: Checkout sources
uses: actions/checkout@v2

- name: Starting CLI testing
shell: bash
run: |
echo "STEP 1 ) Downloading sample suite"
git clone https://github.com/gauravchawhan/mathjs
echo "STEP 2) Download CLI and setting environment variables"
cd mathjs
curl https://downloads.lambdatest.com/hyperexecute/windows/hyperexecute.exe -o hyperexecute.exe
export LT_USERNAME=${{ github.event.inputs.username }}
export LT_ACCESS_KEY=${{ github.event.inputs.accessKey }}
./hyperexecute --user $LT_USERNAME --key $LT_ACCESS_KEY --config hyperexecute.yaml
33 changes: 33 additions & 0 deletions .github/workflows/lambdatest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: LambdaTest (HyperExecute)
on:
push:
branches:
- '*'
tags:

jobs:
HyperExecute-Playwright:
runs-on: windows-latest
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
os: [windows-latest]
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Starting CI testing
shell: bash
env:
CI: true
LT_USERNAME: ${{ secrets.LT_USERNAME }}
LT_ACCESS_KEY: ${{ secrets.LT_ACCESS_KEY }}
run: |
echo "STEP 1 ) Download project"
git clone https://github.com/josdejong/mathjs
cd mathjs
echo "STEP 2) Download HyperExecute"
curl https://downloads.lambdatest.com/hyperexecute/windows/hyperexecute.exe -o hyperexecute.exe
echo "STEP 3) Run tests using HyperExecute"
./hyperexecute --user $LT_USERNAME --key $LT_ACCESS_KEY --config test/browser-test-config/lambdatest-hyperexecute-config.yaml
6 changes: 6 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 +252,11 @@ Orel Ben Neriah <77707952+orelbn@users.noreply.github.com>
Vistinum <eugene225@gmail.com>
Vas Sudanagunta <vas@commonkarma.org>
Brooks Smith <42363318+smith120bh@users.noreply.github.com>
Jmar L. Pineda <63294460+Galm007@users.noreply.github.com>
gauravchawhan <117282267+gauravchawhan@users.noreply.github.com>
Akki <63336443+Aakash-Rana@users.noreply.github.com>
Neeraj Kumawat <42885320+nkumawat34@users.noreply.github.com>
Emmanuel Ferdman <emmanuelferdman@gmail.com>
Paul K <paul@scriptcad.com>

# Generated by tools/update-authors.js
48 changes: 47 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,53 @@
# History

# changes since 13.1.1
# unpublished changes

- Fix: make derivative much faster (#3322). Thanks @paulftw.

# 2024-11-20, 14.0.0

!!! BE CAREFUL: BREAKING CHANGES !!!

- Feat: Upgrade to `fraction.js@5`, using `bigint` under the hood (#3283).
- Feat: Implement support for `Unit` in functions `ceil`, `floor`, and `fix`.
Possible breaking changes in the type definitions of arrays and matrices
due to the introduction of generics (#3269). Thanks @orelbn.
- Feat: Implement support for `log(x: Fraction, base: Fraction)`.
- Fix: #3301 precedence of `%` (mod) being higher than `*` and `/` (#3311).
Thanks @nkumawat34.
- Fix: #3222 prevent `math.import(...)` from overriding units unless you
specify `{ override: true }` (#3225).
- Fix: #3219 let functions `dotDivide`, `dotPow`, `bitXor`, `xor`, `equal`,
`larger`, `largerEq`, `smaller`, `smallerEq`, and `unequal` return a sparse
matrix when the input is two sparse matrices (#3307). Thanks @Aakash-Rana.
- Fix: Improve type definitions of arrays (#3306). Thanks @orelbn.

# 2024-11-20, 13.2.3

- Fix: #3260 improve type definitions and documentation on the callback
indices of `map`, `filter`, and `forEach`.
- Fix: #3323 support functions in function `clone`.
- Docs: fix a broken link in the documentation (#3316).
Thanks @emmanuel-ferdman.

# 2024-11-13, 13.2.2

- Fix: #1455 implicit multiplication of a fraction with unit `in` is incorrect
(#3315). Thanks @nkumawat34.

# 2024-11-06, 13.2.1

- Update to the latest version of `complex.js`.
- Fix `Index.dimension(dim)` accepting non-numeric input.
- Fix: #3290 should validate variables names in method `Parser.set` (#3308).
Thanks @nkumawat34.

# 2024-10-02, 13.2.0

- Feat: improve performance of functions `map`, `filter` and `forEach` (#3256).
Thanks @dvd101x.
- Feat: improve performance of the methods `map()` and `forEach()`
of `DenseMatrix` (#3251). Thanks @Galm007.
- Fix: #3253 cannot use identifiers containing special characters in function
`derivative`.
- Fix: improve the type definitions of `ConstantNode` to support all data
Expand All @@ -12,6 +56,8 @@
- Fix: #3246 function `leafCount` missing in the TypeScript definitions.
- Fix: #3267 implicit multiplication with a negative number and unit `in`.
- Docs: fix broken links on the Configuration page. Thanks @vassudanagunta.
- Docs: document the syntax of `map` and `forEach` in the expression parser
(#3272). Thanks @dvd101x.

# 2024-08-27, 13.1.1

Expand Down
2 changes: 1 addition & 1 deletion docs/expressions/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ The `parse` function exposes the following test functions:
- `math.parse.isDigit(c)`

The exact signature and implementation of these functions can be looked up in
the [source code of the parser](https://github.com/josdejong/mathjs/blob/master/lib/expression/parse.js). The allowed alpha characters are described here: [Constants and variables](syntax.md#constants-and-variables).
the [source code of the parser](https://github.com/josdejong/mathjs/blob/master/src/expression/parse.js). The allowed alpha characters are described here: [Constants and variables](syntax.md#constants-and-variables).

For example, the phone character <code>&#9742;</code> is not supported by default. It can be enabled
by replacing the `isAlpha` function:
Expand Down
65 changes: 63 additions & 2 deletions docs/expressions/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ Operators | Description
`!` | Factorial
`^`, `.^` | Exponentiation
`+`, `-`, `~`, `not` | Unary plus, unary minus, bitwise not, logical not
`%`, `mod` | percentage, modulus
See section below | Implicit multiplication
`*`, `/`, `.*`, `./` | Multiply, divide
`*`, `/`, `.*`, `./`,`%`, `mod` | Multiply, divide , percentage, modulus
`+`, `-` | Add, subtract
`:` | Range
`to`, `in` | Unit conversion
Expand Down Expand Up @@ -250,6 +249,68 @@ Note that math.js embodies a preference for the operator forms, in that calling
`simplify` (see [Algebra](./algebra.md)) converts any instances of the function
form into the corresponding operator.

## Map and forEach

The `map` and `forEach` functions can be used to apply a callback function to each element of an array or matrix.

The callback functions can be functions, typed functions, inline functions (only in the parser) or compiled inline functions (only in the parser).

The callback can have the following inputs:
- **value**: the current value in the array or matrix.
- **index**: the index of the current value expressed as an array of numbers.
- **array**: the array or matrix being iterated.

Below is the syntax for both functions:

### map

The `map` function applies a function to each element of an array and returns a new array with the results.

```js
const parser = math.parser()

// Define a square function
parser.evaluate('square(x) = x ^ 2')

// Apply the square function to each element of the array
parser.evaluate('result = map([1, 2, 3, 4], square)')
// result: [1, 4, 9, 16]

// Apply an inline function to each element of the array
parser.evaluate('result = map([1, 2, 3, 4], f(x) = x ^ 2)')
// result: [1, 4, 9, 16]

// Apply a compiled inline function to each element of the array
parser.evaluate('result = map([1, 2, 3, 4], x ^ 2)')
// result: [1, 4, 9, 16]
```

### forEach
The `forEach` function applies a function to each element of an array or matrix but does not return a new array. It is useful for executing side effects.

```js
// Define a function that prints each element
math.import({consoleLog: x => console.log(x)})
const parser = math.parser()

// Define a squareConsleLog function
parser.evaluate('squareConsoleLog(x) = consoleLog(x ^ 2)')

// Apply the squareConsleLog function to each element of the array
parser.evaluate('forEach([1, 2, 3, 4], squareConsleLog)')
// Prints: 1, 4, 9, 16

// Apply an inline function to each element of the array
parser.evaluate('forEach([1, 2, 3, 4], f(x) = consoleLog(x ^ 2))')
// Prints: 1, 4, 9, 16

// Apply a compiled inline function to each element of the array
parser.evaluate('forEach([1, 2, 3, 4], consoleLog(x ^ 2))')
// Prints: 1, 4, 9, 16
```

These functions are useful for performing element-wise operations on arrays or matrices.

## Constants and variables

Math.js has a number of built-in constants such as `pi` and `e`.
Expand Down
32 changes: 32 additions & 0 deletions hyperexecute.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
version: 0.1
runson: win # defines the OS to test on

concurrency: 1 # number of machines to execute the testcases
autosplit: true

# pre steps sets up the environment for testing
pre:
- npm install
- npm install karma -g
- npm install -g karma-jasmine
- npm install karma-safari-launcher -g
- npm install karma-webdriver-launcher -g
- npm i karma-mocha -g
- npm i karma-webpack -g
- npm i mocha -g


# Smart cache
cacheKey: '{{ checksum "package-lock.json" }}'
cacheDirectories:
- node_modules

# testDiscovery is used to discover all the test cases in test/unit-tests folder
testDiscovery:
type: raw
mode: dynamic
command: grep -nri 'describe' test/unit-tests -ir --include=*.test.js | sed 's/:.*//'

# command to execute the test cases
testRunnerCommand: karma start test/browser-test-config/lt_karma.js --spec= $test
Loading

0 comments on commit 488628c

Please sign in to comment.