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