UNPKG

4.91 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.createLeftShift = void 0;
7
8var _algorithm = require("../../type/matrix/utils/algorithm02");
9
10var _algorithm2 = require("../../type/matrix/utils/algorithm11");
11
12var _algorithm3 = require("../../type/matrix/utils/algorithm13");
13
14var _algorithm4 = require("../../type/matrix/utils/algorithm14");
15
16var _algorithm5 = require("../../type/matrix/utils/algorithm01");
17
18var _algorithm6 = require("../../type/matrix/utils/algorithm10");
19
20var _algorithm7 = require("../../type/matrix/utils/algorithm08");
21
22var _factory = require("../../utils/factory");
23
24var _number = require("../../plain/number");
25
26var _bitwise = require("../../utils/bignumber/bitwise");
27
28var name = 'leftShift';
29var dependencies = ['typed', 'matrix', 'equalScalar', 'zeros', 'DenseMatrix'];
30var 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 var leftShift = typed(name, {
86 'number, number': _number.leftShiftNumber,
87 'BigNumber, BigNumber': _bitwise.leftShiftBigNumber,
88 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
89 return algorithm08(x, y, leftShift, false);
90 },
91 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
92 return algorithm02(y, x, leftShift, true);
93 },
94 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
95 return algorithm01(x, y, leftShift, false);
96 },
97 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
98 return algorithm13(x, y, leftShift);
99 },
100 'Array, Array': function ArrayArray(x, y) {
101 // use matrix implementation
102 return leftShift(matrix(x), matrix(y)).valueOf();
103 },
104 'Array, Matrix': function ArrayMatrix(x, y) {
105 // use matrix implementation
106 return leftShift(matrix(x), y);
107 },
108 'Matrix, Array': function MatrixArray(x, y) {
109 // use matrix implementation
110 return leftShift(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, leftShift, 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, leftShift, 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, leftShift, 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, leftShift, true);
143 },
144 'Array, number | BigNumber': function ArrayNumberBigNumber(x, y) {
145 // use matrix implementation
146 return leftShift(matrix(x), y).valueOf();
147 },
148 'number | BigNumber, Array': function numberBigNumberArray(x, y) {
149 // use matrix implementation
150 return leftShift(x, matrix(y)).valueOf();
151 }
152 });
153 return leftShift;
154});
155exports.createLeftShift = createLeftShift;
\No newline at end of file