forked from josdejong/mathjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariance.transform.js
More file actions
30 lines (26 loc) · 1.08 KB
/
variance.transform.js
File metadata and controls
30 lines (26 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { factory } from '../../utils/factory.js'
import { errorTransform } from './utils/errorTransform.js'
import { createVariance } from '../../function/statistics/variance.js'
import { lastDimToZeroBase } from './utils/lastDimToZeroBase.js'
const name = 'variance'
const dependencies = ['typed', 'add', 'subtract', 'multiply', 'divide', 'mapSlices', 'isNaN']
/**
* Attach a transform function to math.var
* Adds a property transform containing the transform function.
*
* This transform changed the `dim` parameter of function var
* from one-based to zero based
*/
export const createVarianceTransform = /* #__PURE__ */ factory(name, dependencies, ({ typed, add, subtract, multiply, divide, mapSlices, isNaN: mathIsNaN }) => {
const variance = createVariance({ typed, add, subtract, multiply, divide, mapSlices, isNaN: mathIsNaN })
return typed(name, {
'...any': function (args) {
args = lastDimToZeroBase(args)
try {
return variance.apply(null, args)
} catch (err) {
throw errorTransform(err)
}
}
})
}, { isTransformFunction: true })