add.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.createAdd = void 0;
  6. var _factory = require("../../utils/factory.js");
  7. var _matAlgo01xDSid = require("../../type/matrix/utils/matAlgo01xDSid.js");
  8. var _matAlgo04xSidSid = require("../../type/matrix/utils/matAlgo04xSidSid.js");
  9. var _matAlgo10xSids = require("../../type/matrix/utils/matAlgo10xSids.js");
  10. var _matrixAlgorithmSuite = require("../../type/matrix/utils/matrixAlgorithmSuite.js");
  11. var name = 'add';
  12. var dependencies = ['typed', 'matrix', 'addScalar', 'equalScalar', 'DenseMatrix', 'SparseMatrix', 'concat'];
  13. var createAdd = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
  14. var typed = _ref.typed,
  15. matrix = _ref.matrix,
  16. addScalar = _ref.addScalar,
  17. equalScalar = _ref.equalScalar,
  18. DenseMatrix = _ref.DenseMatrix,
  19. SparseMatrix = _ref.SparseMatrix,
  20. concat = _ref.concat;
  21. var matAlgo01xDSid = (0, _matAlgo01xDSid.createMatAlgo01xDSid)({
  22. typed: typed
  23. });
  24. var matAlgo04xSidSid = (0, _matAlgo04xSidSid.createMatAlgo04xSidSid)({
  25. typed: typed,
  26. equalScalar: equalScalar
  27. });
  28. var matAlgo10xSids = (0, _matAlgo10xSids.createMatAlgo10xSids)({
  29. typed: typed,
  30. DenseMatrix: DenseMatrix
  31. });
  32. var matrixAlgorithmSuite = (0, _matrixAlgorithmSuite.createMatrixAlgorithmSuite)({
  33. typed: typed,
  34. matrix: matrix,
  35. concat: concat
  36. });
  37. /**
  38. * Add two or more values, `x + y`.
  39. * For matrices, the function is evaluated element wise.
  40. *
  41. * Syntax:
  42. *
  43. * math.add(x, y)
  44. * math.add(x, y, z, ...)
  45. *
  46. * Examples:
  47. *
  48. * math.add(2, 3) // returns number 5
  49. * math.add(2, 3, 4) // returns number 9
  50. *
  51. * const a = math.complex(2, 3)
  52. * const b = math.complex(-4, 1)
  53. * math.add(a, b) // returns Complex -2 + 4i
  54. *
  55. * math.add([1, 2, 3], 4) // returns Array [5, 6, 7]
  56. *
  57. * const c = math.unit('5 cm')
  58. * const d = math.unit('2.1 mm')
  59. * math.add(c, d) // returns Unit 52.1 mm
  60. *
  61. * math.add("2.3", "4") // returns number 6.3
  62. *
  63. * See also:
  64. *
  65. * subtract, sum
  66. *
  67. * @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} x First value to add
  68. * @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} y Second value to add
  69. * @return {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} Sum of `x` and `y`
  70. */
  71. return typed(name, {
  72. 'any, any': addScalar,
  73. 'any, any, ...any': typed.referToSelf(function (self) {
  74. return function (x, y, rest) {
  75. var result = self(x, y);
  76. for (var i = 0; i < rest.length; i++) {
  77. result = self(result, rest[i]);
  78. }
  79. return result;
  80. };
  81. })
  82. }, matrixAlgorithmSuite({
  83. elop: addScalar,
  84. DS: matAlgo01xDSid,
  85. SS: matAlgo04xSidSid,
  86. Ss: matAlgo10xSids
  87. }));
  88. });
  89. exports.createAdd = createAdd;