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