simple-squiggle

A restricted subset of Squiggle
Log | Files | Refs | README

or.js (4225B)


      1 "use strict";
      2 
      3 Object.defineProperty(exports, "__esModule", {
      4   value: true
      5 });
      6 exports.createOr = void 0;
      7 
      8 var _algorithm = require("../../type/matrix/utils/algorithm03.js");
      9 
     10 var _algorithm2 = require("../../type/matrix/utils/algorithm12.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/algorithm05.js");
     17 
     18 var _factory = require("../../utils/factory.js");
     19 
     20 var _index = require("../../plain/number/index.js");
     21 
     22 var name = 'or';
     23 var dependencies = ['typed', 'matrix', 'equalScalar', 'DenseMatrix'];
     24 var createOr = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
     25   var typed = _ref.typed,
     26       matrix = _ref.matrix,
     27       equalScalar = _ref.equalScalar,
     28       DenseMatrix = _ref.DenseMatrix;
     29   var algorithm03 = (0, _algorithm.createAlgorithm03)({
     30     typed: typed
     31   });
     32   var algorithm05 = (0, _algorithm5.createAlgorithm05)({
     33     typed: typed,
     34     equalScalar: equalScalar
     35   });
     36   var algorithm12 = (0, _algorithm2.createAlgorithm12)({
     37     typed: typed,
     38     DenseMatrix: DenseMatrix
     39   });
     40   var algorithm13 = (0, _algorithm3.createAlgorithm13)({
     41     typed: typed
     42   });
     43   var algorithm14 = (0, _algorithm4.createAlgorithm14)({
     44     typed: typed
     45   });
     46   /**
     47    * Logical `or`. Test if at least one value is defined with a nonzero/nonempty value.
     48    * For matrices, the function is evaluated element wise.
     49    *
     50    * Syntax:
     51    *
     52    *    math.or(x, y)
     53    *
     54    * Examples:
     55    *
     56    *    math.or(2, 4)   // returns true
     57    *
     58    *    a = [2, 5, 0]
     59    *    b = [0, 22, 0]
     60    *    c = 0
     61    *
     62    *    math.or(a, b)   // returns [true, true, false]
     63    *    math.or(b, c)   // returns [false, true, false]
     64    *
     65    * See also:
     66    *
     67    *    and, not, xor
     68    *
     69    * @param  {number | BigNumber | Complex | Unit | Array | Matrix} x First value to check
     70    * @param  {number | BigNumber | Complex | Unit | Array | Matrix} y Second value to check
     71    * @return {boolean | Array | Matrix}
     72    *            Returns true when one of the inputs is defined with a nonzero/nonempty value.
     73    */
     74 
     75   return typed(name, {
     76     'number, number': _index.orNumber,
     77     'Complex, Complex': function ComplexComplex(x, y) {
     78       return x.re !== 0 || x.im !== 0 || y.re !== 0 || y.im !== 0;
     79     },
     80     'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
     81       return !x.isZero() && !x.isNaN() || !y.isZero() && !y.isNaN();
     82     },
     83     'Unit, Unit': function UnitUnit(x, y) {
     84       return this(x.value || 0, y.value || 0);
     85     },
     86     'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
     87       return algorithm05(x, y, this);
     88     },
     89     'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
     90       return algorithm03(y, x, this, true);
     91     },
     92     'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
     93       return algorithm03(x, y, this, false);
     94     },
     95     'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
     96       return algorithm13(x, y, this);
     97     },
     98     'Array, Array': function ArrayArray(x, y) {
     99       // use matrix implementation
    100       return this(matrix(x), matrix(y)).valueOf();
    101     },
    102     'Array, Matrix': function ArrayMatrix(x, y) {
    103       // use matrix implementation
    104       return this(matrix(x), y);
    105     },
    106     'Matrix, Array': function MatrixArray(x, y) {
    107       // use matrix implementation
    108       return this(x, matrix(y));
    109     },
    110     'SparseMatrix, any': function SparseMatrixAny(x, y) {
    111       return algorithm12(x, y, this, false);
    112     },
    113     'DenseMatrix, any': function DenseMatrixAny(x, y) {
    114       return algorithm14(x, y, this, false);
    115     },
    116     'any, SparseMatrix': function anySparseMatrix(x, y) {
    117       return algorithm12(y, x, this, true);
    118     },
    119     'any, DenseMatrix': function anyDenseMatrix(x, y) {
    120       return algorithm14(y, x, this, true);
    121     },
    122     'Array, any': function ArrayAny(x, y) {
    123       // use matrix implementation
    124       return algorithm14(matrix(x), y, this, false).valueOf();
    125     },
    126     'any, Array': function anyArray(x, y) {
    127       // use matrix implementation
    128       return algorithm14(matrix(y), x, this, true).valueOf();
    129     }
    130   });
    131 });
    132 exports.createOr = createOr;