Skip to content

Commit c9d57a1

Browse files
committed
Included an algorithm for Array and scalars
1 parent 0f834fb commit c9d57a1

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { factory } from '../../../utils/factory.js'
2+
import { deepMap as map } from '../../../utils/array.js'
3+
4+
const name = 'matAlgo15xAs'
5+
const dependencies = []
6+
7+
export const createMatAlgo15xAs = /* #__PURE__ */ factory(name, dependencies, () => {
8+
/**
9+
* Iterates over Array items and invokes the callback function f(Aij..z, b).
10+
* Callback function invoked MxN times.
11+
*
12+
* C(i,j,...z) = f(Aij..z, b)
13+
*
14+
* @param {Array} a The Array instance (A)
15+
* @param {Scalar} b The Scalar value
16+
* @param {Function} cf The f(Aij..z,b) operation to invoke
17+
* @param {boolean} inverse A true value indicates callback should be invoked f(b,Aij..z)
18+
*
19+
* @return {Array} Array (C)
20+
*
21+
* https://github.com/josdejong/mathjs/pull/346#issuecomment-97659042
22+
*/
23+
return function matAlgo14xDs (a, b, cf, inverse) {
24+
return inverse ? map(a, v => cf(b, v)) : map(a, v => cf(v, b))
25+
}
26+
})

src/type/matrix/utils/matrixAlgorithmSuite.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { factory } from '../../../utils/factory.js'
22
import { extend } from '../../../utils/object.js'
33
import { createMatAlgo13xDD } from './matAlgo13xDD.js'
44
import { createMatAlgo14xDs } from './matAlgo14xDs.js'
5+
import { createMatAlgo15xAs } from './matAlgo15xAs.js'
56
import { broadcast } from './broadcast.js'
67

78
const name = 'matrixAlgorithmSuite'
@@ -11,6 +12,7 @@ export const createMatrixAlgorithmSuite = /* #__PURE__ */ factory(
1112
name, dependencies, ({ typed, matrix }) => {
1213
const matAlgo13xDD = createMatAlgo13xDD({ typed })
1314
const matAlgo14xDs = createMatAlgo14xDs({ typed })
15+
const matAlgo15xAs = createMatAlgo15xAs()
1416

1517
/**
1618
* Return a signatures object with the usual boilerplate of
@@ -115,9 +117,9 @@ export const createMatrixAlgorithmSuite = /* #__PURE__ */ factory(
115117
matrixSignatures[scalar + ', DenseMatrix'] =
116118
(x, y) => matAlgo14xDs(y, x, elop, true)
117119
matrixSignatures['Array,' + scalar] =
118-
(x, y) => matAlgo14xDs(matrix(x), y, elop, false).valueOf()
120+
(x, y) => matAlgo15xAs(x, y, elop, false)
119121
matrixSignatures[scalar + ', Array'] =
120-
(x, y) => matAlgo14xDs(matrix(y), x, elop, true).valueOf()
122+
(x, y) => matAlgo15xAs(y, x, elop, true)
121123
} else {
122124
matrixSignatures['DenseMatrix,' + scalar] =
123125
typed.referToSelf(self => (x, y) => {
@@ -129,11 +131,11 @@ export const createMatrixAlgorithmSuite = /* #__PURE__ */ factory(
129131
})
130132
matrixSignatures['Array,' + scalar] =
131133
typed.referToSelf(self => (x, y) => {
132-
return matAlgo14xDs(matrix(x), y, self, false).valueOf()
134+
return matAlgo15xAs(x, y, self, false)
133135
})
134136
matrixSignatures[scalar + ', Array'] =
135137
typed.referToSelf(self => (x, y) => {
136-
return matAlgo14xDs(matrix(y), x, self, true).valueOf()
138+
return matAlgo15xAs(y, x, self, true)
137139
})
138140
}
139141
}

0 commit comments

Comments
 (0)