Skip to content

Commit f2a2943

Browse files
committed
Fixed typed issues
1 parent cd83def commit f2a2943

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/function/matrix/broadcastMatrices.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,15 @@ export const createBroadcastMatrices = /* #__PURE__ */ factory(name, dependencie
2929
* @return {Array[Array|Matrix]} An array of matrices with the broadcasted sizes.
3030
*/
3131
return typed(name, {
32-
'...Array': broadcastArrays,
33-
'...Matrix': matrices => broadcastArrays(...matrices.map(m => m.toArray())),
34-
'...Array|Matrix': collections => broadcastArrays(...collections.map(c => isMatrix(c) ? c.toArray() : c))
32+
'...Array|Matrix': collections => {
33+
const areMatrices = collections.map(isMatrix)
34+
if(areMatrices.includes(true)) {
35+
const arrays = collections.map((c,i) => areMatrices[i] ? c.valueOf() : c)
36+
const broadcastedArrays = broadcastArrays(...arrays)
37+
const broadcastedCollections = broadcastedArrays.map((arr, i) => areMatrices[i] ? collections[i].create(arr) : arr)
38+
return broadcastedCollections
39+
}
40+
return broadcastArrays(...collections)
41+
}
3542
})
3643
})

src/function/matrix/broadcastSizes.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,16 @@ export const createBroadcastSizes = /* #__PURE__ */ factory(name, dependencies,
2929
* @return {Array} A vector with the broadcasted size.
3030
*/
3131
return typed(name, {
32-
'...Array': broadcastSizes,
33-
'...Matrix': matrices => broadcastSizes(...matrices.map(m => m.toArray())),
34-
'...Array|Matrix': collections => broadcastSizes(...collections.map(c => isMatrix(c) ? c.toArray() : c))
32+
'...Array|Matrix': collections => {
33+
const areMatrices = collections.map(isMatrix)
34+
if(areMatrices.includes(true)) {
35+
const arrays = collections.map((c,i) => areMatrices[i] ? c.valueOf() : c)
36+
const broadcastedArrays = broadcastSizes(...arrays)
37+
const broadcastedCollections = broadcastedArrays.map((arr, i) => areMatrices[i] ? collections[i].create(arr) : arr)
38+
return broadcastedCollections
39+
}
40+
return broadcastSizes(...collections)
41+
}
42+
3543
})
3644
})

0 commit comments

Comments
 (0)