variance.transform.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { factory } from '../../utils/factory.js';
  2. import { errorTransform } from './utils/errorTransform.js';
  3. import { createVariance } from '../../function/statistics/variance.js';
  4. import { lastDimToZeroBase } from './utils/lastDimToZeroBase.js';
  5. var name = 'variance';
  6. var dependencies = ['typed', 'add', 'subtract', 'multiply', 'divide', 'apply', 'isNaN'];
  7. /**
  8. * Attach a transform function to math.var
  9. * Adds a property transform containing the transform function.
  10. *
  11. * This transform changed the `dim` parameter of function var
  12. * from one-based to zero based
  13. */
  14. export var createVarianceTransform = /* #__PURE__ */factory(name, dependencies, _ref => {
  15. var {
  16. typed,
  17. add,
  18. subtract,
  19. multiply,
  20. divide,
  21. apply,
  22. isNaN
  23. } = _ref;
  24. var variance = createVariance({
  25. typed,
  26. add,
  27. subtract,
  28. multiply,
  29. divide,
  30. apply,
  31. isNaN
  32. });
  33. return typed(name, {
  34. '...any': function any(args) {
  35. args = lastDimToZeroBase(args);
  36. try {
  37. return variance.apply(null, args);
  38. } catch (err) {
  39. throw errorTransform(err);
  40. }
  41. }
  42. });
  43. }, {
  44. isTransformFunction: true
  45. });