UNPKG

1.02 kBJavaScriptView Raw
1import { factory } from '../../utils/factory.js';
2import { errorTransform } from './utils/errorTransform.js';
3import { createSum } from '../../function/statistics/sum.js';
4import { lastDimToZeroBase } from './utils/lastDimToZeroBase.js';
5/**
6 * Attach a transform function to math.sum
7 * Adds a property transform containing the transform function.
8 *
9 * This transform changed the last `dim` parameter of function mean
10 * from one-based to zero based
11 */
12
13var name = 'sum';
14var dependencies = ['typed', 'config', 'add', 'numeric'];
15export var createSumTransform = /* #__PURE__ */factory(name, dependencies, _ref => {
16 var {
17 typed,
18 config,
19 add,
20 numeric
21 } = _ref;
22 var sum = createSum({
23 typed,
24 config,
25 add,
26 numeric
27 });
28 return typed(name, {
29 '...any': function any(args) {
30 args = lastDimToZeroBase(args);
31
32 try {
33 return sum.apply(null, args);
34 } catch (err) {
35 throw errorTransform(err);
36 }
37 }
38 });
39}, {
40 isTransformFunction: true
41});
\No newline at end of file