simple-squiggle

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

rightLogShift.js (4827B)


      1 "use strict";
      2 
      3 Object.defineProperty(exports, "__esModule", {
      4   value: true
      5 });
      6 exports.createRightLogShift = 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/algorithm01.js");
     17 
     18 var _algorithm6 = require("../../type/matrix/utils/algorithm10.js");
     19 
     20 var _algorithm7 = require("../../type/matrix/utils/algorithm08.js");
     21 
     22 var _factory = require("../../utils/factory.js");
     23 
     24 var _index = require("../../plain/number/index.js");
     25 
     26 var name = 'rightLogShift';
     27 var dependencies = ['typed', 'matrix', 'equalScalar', 'zeros', 'DenseMatrix'];
     28 var createRightLogShift = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
     29   var typed = _ref.typed,
     30       matrix = _ref.matrix,
     31       equalScalar = _ref.equalScalar,
     32       zeros = _ref.zeros,
     33       DenseMatrix = _ref.DenseMatrix;
     34   var algorithm01 = (0, _algorithm5.createAlgorithm01)({
     35     typed: typed
     36   });
     37   var algorithm02 = (0, _algorithm.createAlgorithm02)({
     38     typed: typed,
     39     equalScalar: equalScalar
     40   });
     41   var algorithm08 = (0, _algorithm7.createAlgorithm08)({
     42     typed: typed,
     43     equalScalar: equalScalar
     44   });
     45   var algorithm10 = (0, _algorithm6.createAlgorithm10)({
     46     typed: typed,
     47     DenseMatrix: DenseMatrix
     48   });
     49   var algorithm11 = (0, _algorithm2.createAlgorithm11)({
     50     typed: typed,
     51     equalScalar: equalScalar
     52   });
     53   var algorithm13 = (0, _algorithm3.createAlgorithm13)({
     54     typed: typed
     55   });
     56   var algorithm14 = (0, _algorithm4.createAlgorithm14)({
     57     typed: typed
     58   });
     59   /**
     60    * Bitwise right logical shift of value x by y number of bits, `x >>> y`.
     61    * For matrices, the function is evaluated element wise.
     62    * For units, the function is evaluated on the best prefix base.
     63    *
     64    * Syntax:
     65    *
     66    *    math.rightLogShift(x, y)
     67    *
     68    * Examples:
     69    *
     70    *    math.rightLogShift(4, 2)               // returns number 1
     71    *
     72    *    math.rightLogShift([16, -32, 64], 4)   // returns Array [1, 2, 3]
     73    *
     74    * See also:
     75    *
     76    *    bitAnd, bitNot, bitOr, bitXor, leftShift, rightLogShift
     77    *
     78    * @param  {number | Array | Matrix} x Value to be shifted
     79    * @param  {number} y Amount of shifts
     80    * @return {number | Array | Matrix} `x` zero-filled shifted right `y` times
     81    */
     82 
     83   return typed(name, {
     84     'number, number': _index.rightLogShiftNumber,
     85     // 'BigNumber, BigNumber': ..., // TODO: implement BigNumber support for rightLogShift
     86     'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
     87       return algorithm08(x, y, this, false);
     88     },
     89     'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
     90       return algorithm02(y, x, this, true);
     91     },
     92     'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
     93       return algorithm01(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, number | BigNumber': function SparseMatrixNumberBigNumber(x, y) {
    111       // check scalar
    112       if (equalScalar(y, 0)) {
    113         return x.clone();
    114       }
    115 
    116       return algorithm11(x, y, this, false);
    117     },
    118     'DenseMatrix, number | BigNumber': function DenseMatrixNumberBigNumber(x, y) {
    119       // check scalar
    120       if (equalScalar(y, 0)) {
    121         return x.clone();
    122       }
    123 
    124       return algorithm14(x, y, this, false);
    125     },
    126     'number | BigNumber, SparseMatrix': function numberBigNumberSparseMatrix(x, y) {
    127       // check scalar
    128       if (equalScalar(x, 0)) {
    129         return zeros(y.size(), y.storage());
    130       }
    131 
    132       return algorithm10(y, x, this, true);
    133     },
    134     'number | BigNumber, DenseMatrix': function numberBigNumberDenseMatrix(x, y) {
    135       // check scalar
    136       if (equalScalar(x, 0)) {
    137         return zeros(y.size(), y.storage());
    138       }
    139 
    140       return algorithm14(y, x, this, true);
    141     },
    142     'Array, number | BigNumber': function ArrayNumberBigNumber(x, y) {
    143       // use matrix implementation
    144       return this(matrix(x), y).valueOf();
    145     },
    146     'number | BigNumber, Array': function numberBigNumberArray(x, y) {
    147       // use matrix implementation
    148       return this(x, matrix(y)).valueOf();
    149     }
    150   });
    151 });
    152 exports.createRightLogShift = createRightLogShift;