Overview
Using mapPos on submatrices does not generate the expected indices. I'm fairly sure this occurs because the function doesn't factor in the column offset when calling decode.
Versions
- matrix v0.3.6.1
- GHC v8.4.4
Example
The following gives unexpected results:
import qualified Data.Matrix as M
m = M.identity 3
sm = M.submatrix 2 3 1 2 m
unexpected = M.mapPos const sm
This assigns the following to unexpected:
┌ ┐
│ (2,2) (3,1) │
│ (4,1) (4,2) │
└ ┘
This could have one of two possible expected results. The first is to have the upper-left element be (1,1):
┌ ┐
│ (1,1) (1,2) │
│ (2,1) (2,2) │
└ ┘
The second is to have the upper-left element be (2,1), consistent with the submatrix offset:
┌ ┐
│ (2,1) (2,2) │
│ (3,1) (3,2) │
└ ┘
In my opinion, the first option provides more consistent results. It would prevent divergent behavior when, for example, calling mapPos on a 2x2 submatrix vs. a 2x2 matrix with no internal offsets.