simple-squiggle

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

unequal.js (5861B)


      1 "use strict";
      2 
      3 Object.defineProperty(exports, "__esModule", {
      4   value: true
      5 });
      6 exports.createUnequalNumber = exports.createUnequal = void 0;
      7 
      8 var _factory = require("../../utils/factory.js");
      9 
     10 var _algorithm = require("../../type/matrix/utils/algorithm03.js");
     11 
     12 var _algorithm2 = require("../../type/matrix/utils/algorithm07.js");
     13 
     14 var _algorithm3 = require("../../type/matrix/utils/algorithm12.js");
     15 
     16 var _algorithm4 = require("../../type/matrix/utils/algorithm14.js");
     17 
     18 var _algorithm5 = require("../../type/matrix/utils/algorithm13.js");
     19 
     20 var name = 'unequal';
     21 var dependencies = ['typed', 'config', 'equalScalar', 'matrix', 'DenseMatrix'];
     22 var createUnequal = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
     23   var typed = _ref.typed,
     24       config = _ref.config,
     25       equalScalar = _ref.equalScalar,
     26       matrix = _ref.matrix,
     27       DenseMatrix = _ref.DenseMatrix;
     28   var algorithm03 = (0, _algorithm.createAlgorithm03)({
     29     typed: typed
     30   });
     31   var algorithm07 = (0, _algorithm2.createAlgorithm07)({
     32     typed: typed,
     33     DenseMatrix: DenseMatrix
     34   });
     35   var algorithm12 = (0, _algorithm3.createAlgorithm12)({
     36     typed: typed,
     37     DenseMatrix: DenseMatrix
     38   });
     39   var algorithm13 = (0, _algorithm5.createAlgorithm13)({
     40     typed: typed
     41   });
     42   var algorithm14 = (0, _algorithm4.createAlgorithm14)({
     43     typed: typed
     44   });
     45   /**
     46    * Test whether two values are unequal.
     47    *
     48    * The function tests whether the relative difference between x and y is
     49    * larger than the configured epsilon. The function cannot be used to compare
     50    * values smaller than approximately 2.22e-16.
     51    *
     52    * For matrices, the function is evaluated element wise.
     53    * In case of complex numbers, x.re must unequal y.re, or x.im must unequal y.im.
     54    * Strings are compared by their numerical value.
     55    *
     56    * Values `null` and `undefined` are compared strictly, thus `null` is unequal
     57    * with everything except `null`, and `undefined` is unequal with everything
     58    * except `undefined`.
     59    *
     60    * Syntax:
     61    *
     62    *    math.unequal(x, y)
     63    *
     64    * Examples:
     65    *
     66    *    math.unequal(2 + 2, 3)       // returns true
     67    *    math.unequal(2 + 2, 4)       // returns false
     68    *
     69    *    const a = math.unit('50 cm')
     70    *    const b = math.unit('5 m')
     71    *    math.unequal(a, b)           // returns false
     72    *
     73    *    const c = [2, 5, 1]
     74    *    const d = [2, 7, 1]
     75    *
     76    *    math.unequal(c, d)           // returns [false, true, false]
     77    *    math.deepEqual(c, d)         // returns false
     78    *
     79    *    math.unequal(0, null)        // returns true
     80    * See also:
     81    *
     82    *    equal, deepEqual, smaller, smallerEq, larger, largerEq, compare
     83    *
     84    * @param  {number | BigNumber | Fraction | boolean | Complex | Unit | string | Array | Matrix | undefined} x First value to compare
     85    * @param  {number | BigNumber | Fraction | boolean | Complex | Unit | string | Array | Matrix | undefined} y Second value to compare
     86    * @return {boolean | Array | Matrix} Returns true when the compared values are unequal, else returns false
     87    */
     88 
     89   return typed('unequal', {
     90     'any, any': function anyAny(x, y) {
     91       // strict equality for null and undefined?
     92       if (x === null) {
     93         return y !== null;
     94       }
     95 
     96       if (y === null) {
     97         return x !== null;
     98       }
     99 
    100       if (x === undefined) {
    101         return y !== undefined;
    102       }
    103 
    104       if (y === undefined) {
    105         return x !== undefined;
    106       }
    107 
    108       return _unequal(x, y);
    109     },
    110     'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
    111       return algorithm07(x, y, _unequal);
    112     },
    113     'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
    114       return algorithm03(y, x, _unequal, true);
    115     },
    116     'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
    117       return algorithm03(x, y, _unequal, false);
    118     },
    119     'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
    120       return algorithm13(x, y, _unequal);
    121     },
    122     'Array, Array': function ArrayArray(x, y) {
    123       // use matrix implementation
    124       return this(matrix(x), matrix(y)).valueOf();
    125     },
    126     'Array, Matrix': function ArrayMatrix(x, y) {
    127       // use matrix implementation
    128       return this(matrix(x), y);
    129     },
    130     'Matrix, Array': function MatrixArray(x, y) {
    131       // use matrix implementation
    132       return this(x, matrix(y));
    133     },
    134     'SparseMatrix, any': function SparseMatrixAny(x, y) {
    135       return algorithm12(x, y, _unequal, false);
    136     },
    137     'DenseMatrix, any': function DenseMatrixAny(x, y) {
    138       return algorithm14(x, y, _unequal, false);
    139     },
    140     'any, SparseMatrix': function anySparseMatrix(x, y) {
    141       return algorithm12(y, x, _unequal, true);
    142     },
    143     'any, DenseMatrix': function anyDenseMatrix(x, y) {
    144       return algorithm14(y, x, _unequal, true);
    145     },
    146     'Array, any': function ArrayAny(x, y) {
    147       // use matrix implementation
    148       return algorithm14(matrix(x), y, _unequal, false).valueOf();
    149     },
    150     'any, Array': function anyArray(x, y) {
    151       // use matrix implementation
    152       return algorithm14(matrix(y), x, _unequal, true).valueOf();
    153     }
    154   });
    155 
    156   function _unequal(x, y) {
    157     return !equalScalar(x, y);
    158   }
    159 });
    160 exports.createUnequal = createUnequal;
    161 var createUnequalNumber = (0, _factory.factory)(name, ['typed', 'equalScalar'], function (_ref2) {
    162   var typed = _ref2.typed,
    163       equalScalar = _ref2.equalScalar;
    164   return typed(name, {
    165     'any, any': function anyAny(x, y) {
    166       // strict equality for null and undefined?
    167       if (x === null) {
    168         return y !== null;
    169       }
    170 
    171       if (y === null) {
    172         return x !== null;
    173       }
    174 
    175       if (x === undefined) {
    176         return y !== undefined;
    177       }
    178 
    179       if (y === undefined) {
    180         return x !== undefined;
    181       }
    182 
    183       return !equalScalar(x, y);
    184     }
    185   });
    186 });
    187 exports.createUnequalNumber = createUnequalNumber;