UNPKG

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