UNPKG

4.44 kBJavaScriptView Raw
1import { createAlgorithm02 } from '../../type/matrix/utils/algorithm02.js';
2import { createAlgorithm11 } from '../../type/matrix/utils/algorithm11.js';
3import { createAlgorithm13 } from '../../type/matrix/utils/algorithm13.js';
4import { createAlgorithm14 } from '../../type/matrix/utils/algorithm14.js';
5import { createAlgorithm01 } from '../../type/matrix/utils/algorithm01.js';
6import { createAlgorithm10 } from '../../type/matrix/utils/algorithm10.js';
7import { createAlgorithm08 } from '../../type/matrix/utils/algorithm08.js';
8import { factory } from '../../utils/factory.js';
9import { leftShiftNumber } from '../../plain/number/index.js';
10import { leftShiftBigNumber } from '../../utils/bignumber/bitwise.js';
11var name = 'leftShift';
12var dependencies = ['typed', 'matrix', 'equalScalar', 'zeros', 'DenseMatrix'];
13export var createLeftShift = /* #__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 left logical 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.leftShift(x, y)
54 *
55 * Examples:
56 *
57 * math.leftShift(1, 2) // returns number 4
58 *
59 * math.leftShift([1, 2, 3], 4) // returns Array [16, 32, 64]
60 *
61 * See also:
62 *
63 * leftShift, 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` shifted left `y` times
68 */
69
70 return typed(name, {
71 'number, number': leftShiftNumber,
72 'BigNumber, BigNumber': leftShiftBigNumber,
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});
\No newline at end of file