sum.transform.js 1014 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { factory } from '../../utils/factory.js';
  2. import { errorTransform } from './utils/errorTransform.js';
  3. import { createSum } from '../../function/statistics/sum.js';
  4. import { 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 sum
  10. * from one-based to zero based
  11. */
  12. var name = 'sum';
  13. var dependencies = ['typed', 'config', 'add', 'numeric'];
  14. export var createSumTransform = /* #__PURE__ */factory(name, dependencies, _ref => {
  15. var {
  16. typed,
  17. config,
  18. add,
  19. numeric
  20. } = _ref;
  21. var sum = createSum({
  22. typed,
  23. config,
  24. add,
  25. numeric
  26. });
  27. return typed(name, {
  28. '...any': function any(args) {
  29. args = lastDimToZeroBase(args);
  30. try {
  31. return sum.apply(null, args);
  32. } catch (err) {
  33. throw errorTransform(err);
  34. }
  35. }
  36. });
  37. }, {
  38. isTransformFunction: true
  39. });