3 ms·
as far as I know, Eigen is type-safe only with regards to dimensions of vector spaces. It can check at compile time that a dot product is taken over two compati
by gugagore 12y ago
as far as I know, Eigen is type-safe only with regards to dimensions of vector spaces. It can check at compile time that a dot product is taken over two compatibly-sized vectors, or that a matrix-matrix multiply makes sense dimensionally.
It doesn't have a notion of vector spaces with units. It can't keep track (not Eigen, at least) that a vector [m, kg] cannot be inner-product'd with itself unless its through a norm that produces the correct dimension, otherwise the units are m^2 + kg^2.
- sjtrny 12y agoIsn't that the default behaviour for most linear algebra systems? (e.g. MATLAB). Maybe I'm missing something but I don't really care about compile time checking and it seems an impossible task anyway with variable/dynamic sized inputs.
- gugagore 12y agoYes, it is impossible for a compiler to know the size of a matrix whose size is determined at runtime. But a lot of times you do know the size of matrices and not only is it more type-safe to have the type of a matrix be parametrized by its size, it also allows for more efficient code generation. If you don't know the size of a matrix and vector, you necessarily need a loop. If you know your matrix is 3 by 2, you may just, at compile time, unroll the loop completely. I don't know which default behavior you mean.
- dllthomas 12y agoIt's impossible for a compiler to know the size of a matrix whose size is determined at runtime, but it's not impossible for a compiler to prove that whatever the size your logic is still correct (or at least doesn't break any of the invariants you've established). Depending on the nature of those invariants and the complexity of your logic, you may need dependent types.