UNPKG

1.77 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.createVarianceTransform = void 0;
7
8var _factory = require("../../utils/factory");
9
10var _is = require("../../utils/is");
11
12var _errorTransform = require("./utils/errorTransform");
13
14var _variance = require("../../function/statistics/variance");
15
16var name = 'variance';
17var dependencies = ['typed', 'add', 'subtract', 'multiply', 'divide', 'apply', 'isNaN'];
18/**
19 * Attach a transform function to math.var
20 * Adds a property transform containing the transform function.
21 *
22 * This transform changed the `dim` parameter of function var
23 * from one-based to zero based
24 */
25
26var createVarianceTransform =
27/* #__PURE__ */
28(0, _factory.factory)(name, dependencies, function (_ref) {
29 var typed = _ref.typed,
30 add = _ref.add,
31 subtract = _ref.subtract,
32 multiply = _ref.multiply,
33 divide = _ref.divide,
34 apply = _ref.apply,
35 isNaN = _ref.isNaN;
36 var variance = (0, _variance.createVariance)({
37 typed: typed,
38 add: add,
39 subtract: subtract,
40 multiply: multiply,
41 divide: divide,
42 apply: apply,
43 isNaN: isNaN
44 });
45 return typed(name, {
46 '...any': function any(args) {
47 // change last argument dim from one-based to zero-based
48 if (args.length >= 2 && (0, _is.isCollection)(args[0])) {
49 var dim = args[1];
50
51 if ((0, _is.isNumber)(dim)) {
52 args[1] = dim - 1;
53 } else if ((0, _is.isBigNumber)(dim)) {
54 args[1] = dim.minus(1);
55 }
56 }
57
58 try {
59 return variance.apply(null, args);
60 } catch (err) {
61 throw (0, _errorTransform.errorTransform)(err);
62 }
63 }
64 });
65}, {
66 isTransformFunction: true
67});
68exports.createVarianceTransform = createVarianceTransform;
\No newline at end of file