rightLogShift.js (4402B)
1 import { createAlgorithm02 } from '../../type/matrix/utils/algorithm02.js'; 2 import { createAlgorithm11 } from '../../type/matrix/utils/algorithm11.js'; 3 import { createAlgorithm13 } from '../../type/matrix/utils/algorithm13.js'; 4 import { createAlgorithm14 } from '../../type/matrix/utils/algorithm14.js'; 5 import { createAlgorithm01 } from '../../type/matrix/utils/algorithm01.js'; 6 import { createAlgorithm10 } from '../../type/matrix/utils/algorithm10.js'; 7 import { createAlgorithm08 } from '../../type/matrix/utils/algorithm08.js'; 8 import { factory } from '../../utils/factory.js'; 9 import { rightLogShiftNumber } from '../../plain/number/index.js'; 10 var name = 'rightLogShift'; 11 var dependencies = ['typed', 'matrix', 'equalScalar', 'zeros', 'DenseMatrix']; 12 export var createRightLogShift = /* #__PURE__ */factory(name, dependencies, _ref => { 13 var { 14 typed, 15 matrix, 16 equalScalar, 17 zeros, 18 DenseMatrix 19 } = _ref; 20 var algorithm01 = createAlgorithm01({ 21 typed 22 }); 23 var algorithm02 = createAlgorithm02({ 24 typed, 25 equalScalar 26 }); 27 var algorithm08 = createAlgorithm08({ 28 typed, 29 equalScalar 30 }); 31 var algorithm10 = createAlgorithm10({ 32 typed, 33 DenseMatrix 34 }); 35 var algorithm11 = createAlgorithm11({ 36 typed, 37 equalScalar 38 }); 39 var algorithm13 = createAlgorithm13({ 40 typed 41 }); 42 var algorithm14 = createAlgorithm14({ 43 typed 44 }); 45 /** 46 * Bitwise right logical shift of value x by y number of bits, `x >>> y`. 47 * For matrices, the function is evaluated element wise. 48 * For units, the function is evaluated on the best prefix base. 49 * 50 * Syntax: 51 * 52 * math.rightLogShift(x, y) 53 * 54 * Examples: 55 * 56 * math.rightLogShift(4, 2) // returns number 1 57 * 58 * math.rightLogShift([16, -32, 64], 4) // returns Array [1, 2, 3] 59 * 60 * See also: 61 * 62 * bitAnd, bitNot, bitOr, bitXor, leftShift, rightLogShift 63 * 64 * @param {number | Array | Matrix} x Value to be shifted 65 * @param {number} y Amount of shifts 66 * @return {number | Array | Matrix} `x` zero-filled shifted right `y` times 67 */ 68 69 return typed(name, { 70 'number, number': rightLogShiftNumber, 71 // 'BigNumber, BigNumber': ..., // TODO: implement BigNumber support for rightLogShift 72 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) { 73 return algorithm08(x, y, this, false); 74 }, 75 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) { 76 return algorithm02(y, x, this, true); 77 }, 78 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) { 79 return algorithm01(x, y, this, false); 80 }, 81 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) { 82 return algorithm13(x, y, this); 83 }, 84 'Array, Array': function ArrayArray(x, y) { 85 // use matrix implementation 86 return this(matrix(x), matrix(y)).valueOf(); 87 }, 88 'Array, Matrix': function ArrayMatrix(x, y) { 89 // use matrix implementation 90 return this(matrix(x), y); 91 }, 92 'Matrix, Array': function MatrixArray(x, y) { 93 // use matrix implementation 94 return this(x, matrix(y)); 95 }, 96 'SparseMatrix, number | BigNumber': function SparseMatrixNumberBigNumber(x, y) { 97 // check scalar 98 if (equalScalar(y, 0)) { 99 return x.clone(); 100 } 101 102 return algorithm11(x, y, this, false); 103 }, 104 'DenseMatrix, number | BigNumber': function DenseMatrixNumberBigNumber(x, y) { 105 // check scalar 106 if (equalScalar(y, 0)) { 107 return x.clone(); 108 } 109 110 return algorithm14(x, y, this, false); 111 }, 112 'number | BigNumber, SparseMatrix': function numberBigNumberSparseMatrix(x, y) { 113 // check scalar 114 if (equalScalar(x, 0)) { 115 return zeros(y.size(), y.storage()); 116 } 117 118 return algorithm10(y, x, this, true); 119 }, 120 'number | BigNumber, DenseMatrix': function numberBigNumberDenseMatrix(x, y) { 121 // check scalar 122 if (equalScalar(x, 0)) { 123 return zeros(y.size(), y.storage()); 124 } 125 126 return algorithm14(y, x, this, true); 127 }, 128 'Array, number | BigNumber': function ArrayNumberBigNumber(x, y) { 129 // use matrix implementation 130 return this(matrix(x), y).valueOf(); 131 }, 132 'number | BigNumber, Array': function numberBigNumberArray(x, y) { 133 // use matrix implementation 134 return this(x, matrix(y)).valueOf(); 135 } 136 }); 137 });