Related: #178, #192
I'm currently trying to add type-safe vector & matrix types to F#+ but I'm not sure what to implement.
Here are the ones I can think of:
map and filter) in a type-safe manner (e.g. item indexed with type-level natural).but I can imagine many other necessary operations are missing.
Can anyone provide me a list of other operations which can take advantage of type-level naturals and/or should be implemented?
It might be possible to make them applicatives but we'll need a way to express an infinite vector for the pure operation.
@cannorin, in addition to what you mentioned, I think these operations could be valuable:
Transpose: Mat<n,m> -> Mat<m,n>
Tensor (Kronecker) product: Mat<n1,m1> -> Mat<n2,m2> -> Mat<n1 * n2, m1 * m2>
Direct sum: Mat<n1,m1> -> Mat<n2,m2> -> Mat<n1 + n2, m1 + m2>
Vertical block sum: Mat<n1,m> -> Mat<n2,m> -> Mat<n1 + n2, m>
Horizontal block sum: Mat<n,m1> -> Mat<n,m2> -> Mat<n, m1 + m2>
Hadamard (element-wise) product: Mat<n,m> -> Mat<n,m> -> Mat<n, m>
I prefer to think of vectors as either (n,1) matrices or (1,n) matrices (covectors); this simplifies things as the vector operations are then special cases of the matrix ones. I think MATLAB adopts this philosophy but I鈥檓 not certain.
@nasosev After some experiments, I decided not to merge matrix and vector into one type: the conversion between 1D array and 2D array is expensive and the implementation of pretty printer and other type classes becomes much complicated (e.g. vectors are foldable but matrices are not).
Most helpful comment
@nasosev After some experiments, I decided not to merge matrix and vector into one type: the conversion between 1D array and 2D array is expensive and the implementation of pretty printer and other type classes becomes much complicated (e.g. vectors are foldable but matrices are not).