UNPKG

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