and.js (4751B)
1 "use strict"; 2 3 Object.defineProperty(exports, "__esModule", { 4 value: true 5 }); 6 exports.createAnd = void 0; 7 8 var _algorithm = require("../../type/matrix/utils/algorithm02.js"); 9 10 var _algorithm2 = require("../../type/matrix/utils/algorithm11.js"); 11 12 var _algorithm3 = require("../../type/matrix/utils/algorithm13.js"); 13 14 var _algorithm4 = require("../../type/matrix/utils/algorithm14.js"); 15 16 var _algorithm5 = require("../../type/matrix/utils/algorithm06.js"); 17 18 var _factory = require("../../utils/factory.js"); 19 20 var _index = require("../../plain/number/index.js"); 21 22 var name = 'and'; 23 var dependencies = ['typed', 'matrix', 'equalScalar', 'zeros', 'not']; 24 var createAnd = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) { 25 var typed = _ref.typed, 26 matrix = _ref.matrix, 27 equalScalar = _ref.equalScalar, 28 zeros = _ref.zeros, 29 not = _ref.not; 30 var algorithm02 = (0, _algorithm.createAlgorithm02)({ 31 typed: typed, 32 equalScalar: equalScalar 33 }); 34 var algorithm06 = (0, _algorithm5.createAlgorithm06)({ 35 typed: typed, 36 equalScalar: equalScalar 37 }); 38 var algorithm11 = (0, _algorithm2.createAlgorithm11)({ 39 typed: typed, 40 equalScalar: equalScalar 41 }); 42 var algorithm13 = (0, _algorithm3.createAlgorithm13)({ 43 typed: typed 44 }); 45 var algorithm14 = (0, _algorithm4.createAlgorithm14)({ 46 typed: typed 47 }); 48 /** 49 * Logical `and`. Test whether two values are both defined with a nonzero/nonempty value. 50 * For matrices, the function is evaluated element wise. 51 * 52 * Syntax: 53 * 54 * math.and(x, y) 55 * 56 * Examples: 57 * 58 * math.and(2, 4) // returns true 59 * 60 * a = [2, 0, 0] 61 * b = [3, 7, 0] 62 * c = 0 63 * 64 * math.and(a, b) // returns [true, false, false] 65 * math.and(a, c) // returns [false, false, false] 66 * 67 * See also: 68 * 69 * not, or, xor 70 * 71 * @param {number | BigNumber | Complex | Unit | Array | Matrix} x First value to check 72 * @param {number | BigNumber | Complex | Unit | Array | Matrix} y Second value to check 73 * @return {boolean | Array | Matrix} 74 * Returns true when both inputs are defined with a nonzero/nonempty value. 75 */ 76 77 return typed(name, { 78 'number, number': _index.andNumber, 79 'Complex, Complex': function ComplexComplex(x, y) { 80 return (x.re !== 0 || x.im !== 0) && (y.re !== 0 || y.im !== 0); 81 }, 82 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) { 83 return !x.isZero() && !y.isZero() && !x.isNaN() && !y.isNaN(); 84 }, 85 'Unit, Unit': function UnitUnit(x, y) { 86 return this(x.value || 0, y.value || 0); 87 }, 88 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) { 89 return algorithm06(x, y, this, false); 90 }, 91 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) { 92 return algorithm02(y, x, this, true); 93 }, 94 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) { 95 return algorithm02(x, y, this, false); 96 }, 97 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) { 98 return algorithm13(x, y, this); 99 }, 100 'Array, Array': function ArrayArray(x, y) { 101 // use matrix implementation 102 return this(matrix(x), matrix(y)).valueOf(); 103 }, 104 'Array, Matrix': function ArrayMatrix(x, y) { 105 // use matrix implementation 106 return this(matrix(x), y); 107 }, 108 'Matrix, Array': function MatrixArray(x, y) { 109 // use matrix implementation 110 return this(x, matrix(y)); 111 }, 112 'SparseMatrix, any': function SparseMatrixAny(x, y) { 113 // check scalar 114 if (not(y)) { 115 // return zero matrix 116 return zeros(x.size(), x.storage()); 117 } 118 119 return algorithm11(x, y, this, false); 120 }, 121 'DenseMatrix, any': function DenseMatrixAny(x, y) { 122 // check scalar 123 if (not(y)) { 124 // return zero matrix 125 return zeros(x.size(), x.storage()); 126 } 127 128 return algorithm14(x, y, this, false); 129 }, 130 'any, SparseMatrix': function anySparseMatrix(x, y) { 131 // check scalar 132 if (not(x)) { 133 // return zero matrix 134 return zeros(x.size(), x.storage()); 135 } 136 137 return algorithm11(y, x, this, true); 138 }, 139 'any, DenseMatrix': function anyDenseMatrix(x, y) { 140 // check scalar 141 if (not(x)) { 142 // return zero matrix 143 return zeros(x.size(), x.storage()); 144 } 145 146 return algorithm14(y, x, this, true); 147 }, 148 'Array, any': function ArrayAny(x, y) { 149 // use matrix implementation 150 return this(matrix(x), y).valueOf(); 151 }, 152 'any, Array': function anyArray(x, y) { 153 // use matrix implementation 154 return this(x, matrix(y)).valueOf(); 155 } 156 }); 157 }); 158 exports.createAnd = createAnd;