simple-squiggle

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

or.js (3899B)


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