josdejong / josdejong/mathjs

Matrix sum along a dimension is defined to return a `MathScalarType`, but might return higher dimension

Open
#3,202 5 comments 0 reactions 1 assignee Claimed by @deflucaseng View on GitHub
bug help wanted typescript
Dominant language
JavaScript
Stars
15.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
When summing over an axis of a matrix, we always lose just one dimension. If the matrix is 2D, we'll get a 1D array. If the matrix is 3D, we'll get a 2D matrix.
What happens now, is that `math.sum` declares that it returns a `MathScalarType`, instead of optionally returning a matrix.

**To Reproduce**
```
const mat = math.matrix([[1,2,3],[4,5,6]])
console.log(math.sum(mat, 0))

> DenseMatrix { _data: [ 5, 7, 9 ], _size: [ 3 ], _datatype: undefined }
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.