dotPow.js (3544B)
1 import { factory } from '../../utils/factory.js'; 2 import { createAlgorithm03 } from '../../type/matrix/utils/algorithm03.js'; 3 import { createAlgorithm07 } from '../../type/matrix/utils/algorithm07.js'; 4 import { createAlgorithm11 } from '../../type/matrix/utils/algorithm11.js'; 5 import { createAlgorithm12 } from '../../type/matrix/utils/algorithm12.js'; 6 import { createAlgorithm13 } from '../../type/matrix/utils/algorithm13.js'; 7 import { createAlgorithm14 } from '../../type/matrix/utils/algorithm14.js'; 8 var name = 'dotPow'; 9 var dependencies = ['typed', 'equalScalar', 'matrix', 'pow', 'DenseMatrix']; 10 export var createDotPow = /* #__PURE__ */factory(name, dependencies, _ref => { 11 var { 12 typed, 13 equalScalar, 14 matrix, 15 pow, 16 DenseMatrix 17 } = _ref; 18 var algorithm03 = createAlgorithm03({ 19 typed 20 }); 21 var algorithm07 = createAlgorithm07({ 22 typed, 23 DenseMatrix 24 }); 25 var algorithm11 = createAlgorithm11({ 26 typed, 27 equalScalar 28 }); 29 var algorithm12 = createAlgorithm12({ 30 typed, 31 DenseMatrix 32 }); 33 var algorithm13 = createAlgorithm13({ 34 typed 35 }); 36 var algorithm14 = createAlgorithm14({ 37 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 return 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 this(matrix(x), matrix(y)).valueOf(); 80 }, 81 'Array, Matrix': function ArrayMatrix(x, y) { 82 // use matrix implementation 83 return this(matrix(x), y); 84 }, 85 'Matrix, Array': function MatrixArray(x, y) { 86 // use matrix implementation 87 return this(x, matrix(y)); 88 }, 89 'SparseMatrix, any': function SparseMatrixAny(x, y) { 90 return algorithm11(x, y, this, false); 91 }, 92 'DenseMatrix, any': function DenseMatrixAny(x, y) { 93 return algorithm14(x, y, this, false); 94 }, 95 'any, SparseMatrix': function anySparseMatrix(x, y) { 96 return algorithm12(y, x, this, true); 97 }, 98 'any, DenseMatrix': function anyDenseMatrix(x, y) { 99 return algorithm14(y, x, this, true); 100 }, 101 'Array, any': function ArrayAny(x, y) { 102 // use matrix implementation 103 return algorithm14(matrix(x), y, this, false).valueOf(); 104 }, 105 'any, Array': function anyArray(x, y) { 106 // use matrix implementation 107 return algorithm14(matrix(y), x, this, true).valueOf(); 108 } 109 }); 110 });