UNPKG

4.1 kBJavaScriptView Raw
1import { factory } from '../../utils/factory';
2import { createAlgorithm02 } from '../../type/matrix/utils/algorithm02';
3import { createAlgorithm03 } from '../../type/matrix/utils/algorithm03';
4import { createAlgorithm07 } from '../../type/matrix/utils/algorithm07';
5import { createAlgorithm11 } from '../../type/matrix/utils/algorithm11';
6import { createAlgorithm12 } from '../../type/matrix/utils/algorithm12';
7import { createAlgorithm13 } from '../../type/matrix/utils/algorithm13';
8import { createAlgorithm14 } from '../../type/matrix/utils/algorithm14';
9var name = 'dotDivide';
10var dependencies = ['typed', 'matrix', 'equalScalar', 'divideScalar', 'DenseMatrix'];
11export var createDotDivide =
12/* #__PURE__ */
13factory(name, dependencies, function (_ref) {
14 var typed = _ref.typed,
15 matrix = _ref.matrix,
16 equalScalar = _ref.equalScalar,
17 divideScalar = _ref.divideScalar,
18 DenseMatrix = _ref.DenseMatrix;
19 var algorithm02 = createAlgorithm02({
20 typed: typed,
21 equalScalar: equalScalar
22 });
23 var algorithm03 = createAlgorithm03({
24 typed: typed
25 });
26 var algorithm07 = createAlgorithm07({
27 typed: typed,
28 DenseMatrix: DenseMatrix
29 });
30 var algorithm11 = createAlgorithm11({
31 typed: typed,
32 equalScalar: equalScalar
33 });
34 var algorithm12 = createAlgorithm12({
35 typed: typed,
36 DenseMatrix: DenseMatrix
37 });
38 var algorithm13 = createAlgorithm13({
39 typed: typed
40 });
41 var algorithm14 = createAlgorithm14({
42 typed: typed
43 });
44 /**
45 * Divide two matrices element wise. The function accepts both matrices and
46 * scalar values.
47 *
48 * Syntax:
49 *
50 * math.dotDivide(x, y)
51 *
52 * Examples:
53 *
54 * math.dotDivide(2, 4) // returns 0.5
55 *
56 * a = [[9, 5], [6, 1]]
57 * b = [[3, 2], [5, 2]]
58 *
59 * math.dotDivide(a, b) // returns [[3, 2.5], [1.2, 0.5]]
60 * math.divide(a, b) // returns [[1.75, 0.75], [-1.75, 2.25]]
61 *
62 * See also:
63 *
64 * divide, multiply, dotMultiply
65 *
66 * @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} x Numerator
67 * @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} y Denominator
68 * @return {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} Quotient, `x ./ y`
69 */
70
71 var dotDivide = typed(name, {
72 'any, any': divideScalar,
73 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
74 return algorithm07(x, y, divideScalar, false);
75 },
76 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
77 return algorithm02(y, x, divideScalar, true);
78 },
79 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
80 return algorithm03(x, y, divideScalar, false);
81 },
82 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
83 return algorithm13(x, y, divideScalar);
84 },
85 'Array, Array': function ArrayArray(x, y) {
86 // use matrix implementation
87 return dotDivide(matrix(x), matrix(y)).valueOf();
88 },
89 'Array, Matrix': function ArrayMatrix(x, y) {
90 // use matrix implementation
91 return dotDivide(matrix(x), y);
92 },
93 'Matrix, Array': function MatrixArray(x, y) {
94 // use matrix implementation
95 return dotDivide(x, matrix(y));
96 },
97 'SparseMatrix, any': function SparseMatrixAny(x, y) {
98 return algorithm11(x, y, divideScalar, false);
99 },
100 'DenseMatrix, any': function DenseMatrixAny(x, y) {
101 return algorithm14(x, y, divideScalar, false);
102 },
103 'any, SparseMatrix': function anySparseMatrix(x, y) {
104 return algorithm12(y, x, divideScalar, true);
105 },
106 'any, DenseMatrix': function anyDenseMatrix(x, y) {
107 return algorithm14(y, x, divideScalar, true);
108 },
109 'Array, any': function ArrayAny(x, y) {
110 // use matrix implementation
111 return algorithm14(matrix(x), y, divideScalar, false).valueOf();
112 },
113 'any, Array': function anyArray(x, y) {
114 // use matrix implementation
115 return algorithm14(matrix(y), x, divideScalar, true).valueOf();
116 }
117 });
118 return dotDivide;
119});
\No newline at end of file