Skip to content

Commit

Permalink
2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mmomtchev committed Mar 22, 2022
1 parent 2cb472c commit 9d916d1
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 106 deletions.
205 changes: 102 additions & 103 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![Test published packages](https://github.com/mmomtchev/exprtk.js/actions/workflows/test-release.yml/badge.svg)](https://github.com/mmomtchev/exprtk.js/actions/workflows/test-release.yml)
[![codecov](https://codecov.io/gh/mmomtchev/exprtk.js/branch/main/graph/badge.svg?token=H8v2uuZGYg)](https://codecov.io/gh/mmomtchev/exprtk.js)

[https://exprtk.js.org](https://exprtk.js.org)
<https://exprtk.js.org>

Node.js bindings for [ExprTk](http://www.partow.net/programming/exprtk/index.html) [(Github)](https://github.com/ArashPartow/exprtk) by [@ArashPartow](https://github.com/ArashPartow)

Expand All @@ -19,8 +19,9 @@ Even in single-threaded synchronous mode `ExprTk.js` outperforms the native JS `
It also supports being directly called from native add-ons, including native threads, without any synchronization with V8, allowing JS code to drive multi-threaded mathematical transformations.

It has two main use cases:
* Performing heavy mathematical calculation in Express-like frameworks which are not allowed to block
* Speed-up of back-end calculation by parallelizing over multiple cores

* Performing heavy mathematical calculation in Express-like frameworks which are not allowed to block
* Speed-up of back-end calculation by parallelizing over multiple cores

# Installation

Expand All @@ -40,9 +41,7 @@ npm install exprtk.js --build-from-source

If you do not use the integer types, you can obtain a significantly smaller binary by doing:

```
npm install exprtk.js --build-from-source --disable_int
```
npm install exprtk.js --build-from-source --disable_int

However this won't have any effect on the startup times, since the addon uses lazy binding and does not load code that is not used.

Expand Down Expand Up @@ -162,93 +161,78 @@ const r = await mean.evalAsync(inputArray);

### Table of Contents

* [toString](#tostring)
* [allocator](#allocator)
* [expression](#expression)
* [maxActive](#maxactive)
* [maxParallel](#maxparallel)
* [scalars](#scalars)
* [type](#type)
* [vectors](#vectors)
* [cwise](#cwise)
* [Expression](#expression)
* [Parameters](#parameters)
* [Examples](#examples)
* [eval](#eval)
* [Parameters](#parameters-1)
* [Examples](#examples-1)
* [map](#map)
* [Parameters](#parameters-2)
* [Examples](#examples-2)
* [reduce](#reduce)
* [Parameters](#parameters-3)
* [Examples](#examples-3)
* [allocator](#allocator-1)
* [maxParallel](#maxparallel-1)
* [type](#type-1)
* [Expression](#expression-1)
* [Parameters](#parameters-4)
* [Examples](#examples-4)

## toString

Get a string representation of this object

Returns **string**&#x20;
* [toString](#tostring)
* [cwise](#cwise)
* [Parameters](#parameters-1)
* [Examples](#examples-1)
* [eval](#eval)
* [Parameters](#parameters-2)
* [Examples](#examples-2)
* [map](#map)
* [Parameters](#parameters-3)
* [Examples](#examples-3)
* [reduce](#reduce)
* [Parameters](#parameters-4)
* [Examples](#examples-4)
* [allocator](#allocator)
* [expression](#expression-1)
* [maxActive](#maxactive)
* [maxParallel](#maxparallel)
* [scalars](#scalars)
* [type](#type)
* [type](#type-1)
* [vectors](#vectors)
* [allocator](#allocator-1)
* [maxParallel](#maxparallel-1)

## allocator

Return the data type constructor

Type: TypedArrayConstructor

## expression

Return the expression as a string

Type: string

## maxActive

Get the currently reached peak of simultaneously running instances for this Expression

Type: number

## maxParallel

Get/set the maximum allowed parallel instances for this Expression
## Expression

Type: number
### Parameters

## scalars
* `expression` **string** function
* `variables` **Array\<string>?** An array containing all the scalar variables' names, will be determined automatically if omitted, however order won't be guaranteed, scalars are passed by value
* `vectors` **Record\<string, number>?** An object containing all the vector variables' names and their sizes, vector size must be known at compilation (object construction), vectors are passed by reference and can be modified by the ExprTk expression

Return the scalar arguments as an array
### Examples

Type: Array\<string>
```javascript
// This determines the internally used type
const expr = require("exprtk.js").Float64;

## type
// arithmetic mean of 2 variables
const mean = new Expression('(a+b)/2', ['a', 'b']);

Return the type as a string
// naive stddev of an array of 1024 elements
const stddev = new Expression(
'var sum := 0; var sumsq := 0; ' +
'for (var i := 0; i < x[]; i += 1) { sum += x[i]; sumsq += x[i] * x[i] }; ' +
'(sumsq - (sum*sum) / x[]) / (x[] - 1);',
[], {x: 1024})
```

Type: string
Returns **[Expression](#expression)** The `Expression` represents an expression compiled to an AST from a string. Expressions come in different flavors depending on the internal type used.

## vectors
### toString

Return the vector arguments as an object
Get a string representation of this object

Type: Record\<string, Array\<number>>
Returns **string**&#x20;

## cwise
### cwise

Generic vector operation with implicit traversal.

Supports automatic type conversions, multiple inputs and writing into a pre-existing array.

### Parameters
#### Parameters

* `arguments` **Record\<string, (number | TypedArray\<T>)>**&#x20;
* `arguments` **...(Array<(number | TypedArray\<T>)> | Record\<string, (number | TypedArray\<T>)>)** of the function, iterator removed

### Examples
#### Examples

```javascript
// Air density of humid air from relative humidity (phi), temperature (T) and pressure (P)
Expand Down Expand Up @@ -295,17 +279,17 @@ await density.cwiseAsync(os.cpus().length, {phi, T, P, R, Md, Mv}, result);

Returns **TypedArray\<T>**&#x20;

## eval
### eval

Evaluate the expression.

All arrays must match the internal data type.

### Parameters
#### Parameters

* `arguments` **...(Array<(number | TypedArray\<T>)> | Record\<string, (number | TypedArray\<T>)>)** of the function

### Examples
#### Examples

```javascript
// These two are equivalent
Expand All @@ -319,7 +303,7 @@ expr.evalAsync(2, 5, (e,r) => console.log(e, r));

Returns **number**&#x20;

## map
### map

Evaluate the expression for every element of a TypedArray.

Expand All @@ -332,15 +316,15 @@ If target is specified, it will write the data into a preallocated array.
This can be used when multiple operations are chained to avoid reallocating a new array at every step.
Otherwise it will return a new array.

### Parameters
#### Parameters

* `threads` **TypedArray\<T>?** number of threads to use, 1 if not specified
* `target` **TypedArray\<T>?** array in which the data is to be written, will allocate a new array if none is specified
* `array` **TypedArray\<T>** for the expression to be iterated over
* `iterator` **string** variable name
* `arguments` **...(Array<(number | TypedArray\<T>)> | Record\<string, (number | TypedArray\<T>)>)** of the function, iterator removed

### Examples
#### Examples

```javascript
// Clamp values in an array to [0..1000]
Expand Down Expand Up @@ -370,7 +354,7 @@ const r2 = await expr.mapAsync(4, array, 'x', {f: 0, c: 0});

Returns **TypedArray\<T>**&#x20;

## reduce
### reduce

Evaluate the expression for every element of a TypedArray
passing a scalar accumulator to every evaluation.
Expand All @@ -380,15 +364,15 @@ faster than calling `array.reduce(expr.eval)`.

All arrays must match the internal data type.

### Parameters
#### Parameters

* `array` **TypedArray\<T>** for the expression to be iterated over
* `iterator` **string** variable name
* `accumulator` **string** variable name
* `initializer` **number** for the accumulator
* `arguments` **...(Array<(number | TypedArray\<T>)> | Record\<string, (number | TypedArray\<T>)>)** of the function, iterator removed

### Examples
#### Examples

```javascript
// n-power sum of an array
Expand All @@ -406,51 +390,66 @@ const sumSq = await sum.reduceAsync(array, 'x', {'a' : 0}, (e,r) => console.log(

Returns **number**&#x20;

## allocator
### allocator

Return the data type constructor

Type: TypedArrayConstructor

## maxParallel
### expression

Get the number of threads available for evaluating expressions.
Set by the `EXPRTKJS_THREADS` environment variable.
Return the expression as a string

Type: string

### maxActive

Get the currently reached peak of simultaneously running instances for this Expression

Type: number

## type
### maxParallel

Get/set the maximum allowed parallel instances for this Expression

Type: number

### scalars

Return the scalar arguments as an array

Type: Array\<string>

### type

Return the type as a string

Type: string

## Expression
### type

### Parameters
Return the type as a string

* `expression` **string** function
* `variables` **Array\<string>?** An array containing all the scalar variables' names, will be determined automatically if omitted, however order won't be guaranteed, scalars are passed by value
* `vectors` **Record\<string, number>?** An object containing all the vector variables' names and their sizes, vector size must be known at compilation (object construction), vectors are passed by reference and can be modified by the ExprTk expression
Type: string

### Examples
### vectors

```javascript
// This determines the internally used type
const expr = require("exprtk.js").Float64;
Return the vector arguments as an object

// arithmetic mean of 2 variables
const mean = new Expression('(a+b)/2', ['a', 'b']);
Type: Record\<string, Array\<number>>

// naive stddev of an array of 1024 elements
const stddev = new Expression(
'var sum := 0; var sumsq := 0; ' +
'for (var i := 0; i < x[]; i += 1) { sum += x[i]; sumsq += x[i] * x[i] }; ' +
'(sumsq - (sum*sum) / x[]) / (x[] - 1);',
[], {x: 1024})
```
### allocator

Returns **[Expression](#expression)**&#x20;
Return the data type constructor

Type: TypedArrayConstructor

### maxParallel

Get the number of threads available for evaluating expressions.
Set by the `EXPRTKJS_THREADS` environment variable.

Type: number

# Notes

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"postpublish": "gh workflow run test-npm.yml -F version=$npm_package_version"
},
"name": "exprtk.js",
"version": "2.0.0",
"version": "2.0.1",
"description": "JS Mathematical Expression Toolkit Library",
"repository": {
"type": "git",
Expand Down

0 comments on commit 9d916d1

Please sign in to comment.