Currently the code for matrix.mul-vec requires "matrix m must be equal to vector dim", where by inspection of the source code m appears to be the number of rows in the matrix:
But this isn't the correct requirement, at least mathematically speaking: it is the number of columns in the matrix that should match the vector dimension. One way of checking this is to observe, from the source code itself,
#{
v += vec.at(n) * mat.at(m).at(n)
}
that the matrix entries getting matched with the vector entries come from the nested n axis, which are the columns (not rows) of the matrix.
So the assertion that mat.len() == vector.dim(vec) is (1) not actually necessary for valid matrix multiplication on vectors, (2) doesn't catch actual dimension mismatches with the columns, and (3) prevents certain useful things, such as multiplying by a non-square matrix in order to project vectors into 2D coordinates.
Currently the code for
matrix.mul-vec
requires "matrixm
must be equal to vector dim", where by inspection of the source codem
appears to be the number of rows in the matrix:https://github.com/cetz-package/cetz/blob/86509124affe0b8d3640abd1549ba0b944949d98/src/matrix.typ#L229-L242
But this isn't the correct requirement, at least mathematically speaking: it is the number of columns in the matrix that should match the vector dimension. One way of checking this is to observe, from the source code itself,
that the matrix entries getting matched with the vector entries come from the nested
n
axis, which are the columns (not rows) of the matrix.So the assertion that
mat.len() == vector.dim(vec)
is (1) not actually necessary for valid matrix multiplication on vectors, (2) doesn't catch actual dimension mismatches with the columns, and (3) prevents certain useful things, such as multiplying by a non-square matrix in order to project vectors into 2D coordinates.