and.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.createAnd = void 0;
  6. var _matAlgo02xDS = require("../../type/matrix/utils/matAlgo02xDS0.js");
  7. var _matAlgo11xS0s = require("../../type/matrix/utils/matAlgo11xS0s.js");
  8. var _matAlgo14xDs = require("../../type/matrix/utils/matAlgo14xDs.js");
  9. var _matAlgo06xS0S = require("../../type/matrix/utils/matAlgo06xS0S0.js");
  10. var _factory = require("../../utils/factory.js");
  11. var _matrixAlgorithmSuite = require("../../type/matrix/utils/matrixAlgorithmSuite.js");
  12. var _index = require("../../plain/number/index.js");
  13. var name = 'and';
  14. var dependencies = ['typed', 'matrix', 'equalScalar', 'zeros', 'not'];
  15. var createAnd = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
  16. var typed = _ref.typed,
  17. matrix = _ref.matrix,
  18. equalScalar = _ref.equalScalar,
  19. zeros = _ref.zeros,
  20. not = _ref.not;
  21. var matAlgo02xDS0 = (0, _matAlgo02xDS.createMatAlgo02xDS0)({
  22. typed: typed,
  23. equalScalar: equalScalar
  24. });
  25. var matAlgo06xS0S0 = (0, _matAlgo06xS0S.createMatAlgo06xS0S0)({
  26. typed: typed,
  27. equalScalar: equalScalar
  28. });
  29. var matAlgo11xS0s = (0, _matAlgo11xS0s.createMatAlgo11xS0s)({
  30. typed: typed,
  31. equalScalar: equalScalar
  32. });
  33. var matAlgo14xDs = (0, _matAlgo14xDs.createMatAlgo14xDs)({
  34. typed: typed
  35. });
  36. var matrixAlgorithmSuite = (0, _matrixAlgorithmSuite.createMatrixAlgorithmSuite)({
  37. typed: typed,
  38. matrix: matrix
  39. });
  40. /**
  41. * Logical `and`. Test whether two values are both defined with a nonzero/nonempty value.
  42. * For matrices, the function is evaluated element wise.
  43. *
  44. * Syntax:
  45. *
  46. * math.and(x, y)
  47. *
  48. * Examples:
  49. *
  50. * math.and(2, 4) // returns true
  51. *
  52. * a = [2, 0, 0]
  53. * b = [3, 7, 0]
  54. * c = 0
  55. *
  56. * math.and(a, b) // returns [true, false, false]
  57. * math.and(a, c) // returns [false, false, false]
  58. *
  59. * See also:
  60. *
  61. * not, or, xor
  62. *
  63. * @param {number | BigNumber | Complex | Unit | Array | Matrix} x First value to check
  64. * @param {number | BigNumber | Complex | Unit | Array | Matrix} y Second value to check
  65. * @return {boolean | Array | Matrix}
  66. * Returns true when both inputs are defined with a nonzero/nonempty value.
  67. */
  68. return typed(name, {
  69. 'number, number': _index.andNumber,
  70. 'Complex, Complex': function ComplexComplex(x, y) {
  71. return (x.re !== 0 || x.im !== 0) && (y.re !== 0 || y.im !== 0);
  72. },
  73. 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
  74. return !x.isZero() && !y.isZero() && !x.isNaN() && !y.isNaN();
  75. },
  76. 'Unit, Unit': typed.referToSelf(function (self) {
  77. return function (x, y) {
  78. return self(x.value || 0, y.value || 0);
  79. };
  80. }),
  81. 'SparseMatrix, any': typed.referToSelf(function (self) {
  82. return function (x, y) {
  83. // check scalar
  84. if (not(y)) {
  85. // return zero matrix
  86. return zeros(x.size(), x.storage());
  87. }
  88. return matAlgo11xS0s(x, y, self, false);
  89. };
  90. }),
  91. 'DenseMatrix, any': typed.referToSelf(function (self) {
  92. return function (x, y) {
  93. // check scalar
  94. if (not(y)) {
  95. // return zero matrix
  96. return zeros(x.size(), x.storage());
  97. }
  98. return matAlgo14xDs(x, y, self, false);
  99. };
  100. }),
  101. 'any, SparseMatrix': typed.referToSelf(function (self) {
  102. return function (x, y) {
  103. // check scalar
  104. if (not(x)) {
  105. // return zero matrix
  106. return zeros(x.size(), x.storage());
  107. }
  108. return matAlgo11xS0s(y, x, self, true);
  109. };
  110. }),
  111. 'any, DenseMatrix': typed.referToSelf(function (self) {
  112. return function (x, y) {
  113. // check scalar
  114. if (not(x)) {
  115. // return zero matrix
  116. return zeros(x.size(), x.storage());
  117. }
  118. return matAlgo14xDs(y, x, self, true);
  119. };
  120. }),
  121. 'Array, any': typed.referToSelf(function (self) {
  122. return function (x, y) {
  123. // use matrix implementation
  124. return self(matrix(x), y).valueOf();
  125. };
  126. }),
  127. 'any, Array': typed.referToSelf(function (self) {
  128. return function (x, y) {
  129. // use matrix implementation
  130. return self(x, matrix(y)).valueOf();
  131. };
  132. })
  133. }, matrixAlgorithmSuite({
  134. SS: matAlgo06xS0S0,
  135. DS: matAlgo02xDS0
  136. }));
  137. });
  138. exports.createAnd = createAnd;