1 | 'use strict'
|
2 |
|
3 | const isInteger = require('../../utils/number').isInteger
|
4 | const bigRightArithShift = require('../../utils/bignumber/rightArithShift')
|
5 |
|
6 | function factory (type, config, load, typed) {
|
7 | const latex = require('../../utils/latex')
|
8 |
|
9 | const matrix = load(require('../../type/matrix/function/matrix'))
|
10 | const equalScalar = load(require('../relational/equalScalar'))
|
11 | const zeros = load(require('../matrix/zeros'))
|
12 |
|
13 | const algorithm01 = load(require('../../type/matrix/utils/algorithm01'))
|
14 | const algorithm02 = load(require('../../type/matrix/utils/algorithm02'))
|
15 | const algorithm08 = load(require('../../type/matrix/utils/algorithm08'))
|
16 | const algorithm10 = load(require('../../type/matrix/utils/algorithm10'))
|
17 | const algorithm11 = load(require('../../type/matrix/utils/algorithm11'))
|
18 | const algorithm13 = load(require('../../type/matrix/utils/algorithm13'))
|
19 | const algorithm14 = load(require('../../type/matrix/utils/algorithm14'))
|
20 |
|
21 | |
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | const rightArithShift = typed('rightArithShift', {
|
45 |
|
46 | 'number, number': function (x, y) {
|
47 | if (!isInteger(x) || !isInteger(y)) {
|
48 | throw new Error('Integers expected in function rightArithShift')
|
49 | }
|
50 |
|
51 | return x >> y
|
52 | },
|
53 |
|
54 | 'BigNumber, BigNumber': bigRightArithShift,
|
55 |
|
56 | 'SparseMatrix, SparseMatrix': function (x, y) {
|
57 | return algorithm08(x, y, rightArithShift, false)
|
58 | },
|
59 |
|
60 | 'SparseMatrix, DenseMatrix': function (x, y) {
|
61 | return algorithm02(y, x, rightArithShift, true)
|
62 | },
|
63 |
|
64 | 'DenseMatrix, SparseMatrix': function (x, y) {
|
65 | return algorithm01(x, y, rightArithShift, false)
|
66 | },
|
67 |
|
68 | 'DenseMatrix, DenseMatrix': function (x, y) {
|
69 | return algorithm13(x, y, rightArithShift)
|
70 | },
|
71 |
|
72 | 'Array, Array': function (x, y) {
|
73 |
|
74 | return rightArithShift(matrix(x), matrix(y)).valueOf()
|
75 | },
|
76 |
|
77 | 'Array, Matrix': function (x, y) {
|
78 |
|
79 | return rightArithShift(matrix(x), y)
|
80 | },
|
81 |
|
82 | 'Matrix, Array': function (x, y) {
|
83 |
|
84 | return rightArithShift(x, matrix(y))
|
85 | },
|
86 |
|
87 | 'SparseMatrix, number | BigNumber': function (x, y) {
|
88 |
|
89 | if (equalScalar(y, 0)) {
|
90 | return x.clone()
|
91 | }
|
92 | return algorithm11(x, y, rightArithShift, false)
|
93 | },
|
94 |
|
95 | 'DenseMatrix, number | BigNumber': function (x, y) {
|
96 |
|
97 | if (equalScalar(y, 0)) {
|
98 | return x.clone()
|
99 | }
|
100 | return algorithm14(x, y, rightArithShift, false)
|
101 | },
|
102 |
|
103 | 'number | BigNumber, SparseMatrix': function (x, y) {
|
104 |
|
105 | if (equalScalar(x, 0)) {
|
106 | return zeros(y.size(), y.storage())
|
107 | }
|
108 | return algorithm10(y, x, rightArithShift, true)
|
109 | },
|
110 |
|
111 | 'number | BigNumber, DenseMatrix': function (x, y) {
|
112 |
|
113 | if (equalScalar(x, 0)) {
|
114 | return zeros(y.size(), y.storage())
|
115 | }
|
116 | return algorithm14(y, x, rightArithShift, true)
|
117 | },
|
118 |
|
119 | 'Array, number | BigNumber': function (x, y) {
|
120 |
|
121 | return rightArithShift(matrix(x), y).valueOf()
|
122 | },
|
123 |
|
124 | 'number | BigNumber, Array': function (x, y) {
|
125 |
|
126 | return rightArithShift(x, matrix(y)).valueOf()
|
127 | }
|
128 | })
|
129 |
|
130 | rightArithShift.toTex = {
|
131 | 2: `\\left(\${args[0]}${latex.operators['rightArithShift']}\${args[1]}\\right)`
|
132 | }
|
133 |
|
134 | return rightArithShift
|
135 | }
|
136 |
|
137 | exports.name = 'rightArithShift'
|
138 | exports.factory = factory
|