Skip to content

Commit

Permalink
Skip recurssion for flat matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
dvd101x committed Feb 12, 2025
1 parent 9727495 commit 105759c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/type/matrix/DenseMatrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,18 @@ export const createDenseMatrixClass = /* #__PURE__ */ factory(name, dependencies
*/
DenseMatrix.prototype.map = function (callback) {
const me = this
const size = me._size
const maxDepth = size.length

if (maxDepth === 0) return me.clone()

const result = new DenseMatrix(me)
const fastCallback = optimizeCallback(callback, me._data, 'map')
if (maxDepth === 1) {
return new DenseMatrix(
me._data.map((value, index) => fastCallback(value, [index], me))
)
}

result._forEach(function (arr, i, index) {
arr[i] = fastCallback(arr[i], index, me)
Expand Down

0 comments on commit 105759c

Please sign in to comment.