and.js 4.4 KB

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