matrix - What is the linguistic way to program matrices on Haskell? -


as simple should be, whenever need use matrices on haskell, struggle. strategy chose concrete type (repa, vector, list, intmap, etc) , program it. example, used repa solve euler's problem 11, , use on marathons. unfortunately, repa isn't particularly friendly api - requires complicate type annotations, thinking representation , tracking it, converting around... also, indices reversed. means spend amount of time looking @ docs , trying align types correctly, deadly when in marathon.

i use vectors/lists, is, too, awkward, since need use toindex :: [int] → int; fromindex int → [int] functions every time index vector.

i tried creating wrapper data.vector such data matrix = matrix { shape :: [a], buffer :: vector }, noticed had create wrapper every single vector function, , different types match mutable vectors , on, , mess.

in end, need simple way deal matrices - like:

matrix = matrix.fromlist [3,3] [1,2,3,4,5,6,7,8,9] main =     matrix' <- set matrix [1,1] 0     print $ matrix [1,1]     print $ sum matrix 

or else lets me think matrices mathematical objects , not concrete implementation, failed find simple linguistic way. how it? wonder if lens can somehow?

  • you mean, matrices (i.e. arrays 2 index-dimensions)? hmatrix best fit you. matrix type little different vector wrapper, , interface feels lot “purely functional matlab” (a philosophy can't abide, oh well...) @ rate, efficient linear-algebra operations, slicing etc. through underlying gsl routines. mind, library not stateful stuff, keeps purely-functional interface , relies on optimisations of built-in routines.

  • you mean, general multi-dimensional arrays / tensors, more interested in element-wise operations rather linear algebra, , need stateful updates? old array library might right. seems have been eclipsed vector , repa on last years, imo, data.ix indexing paradigm pretty nice. sort of less mature, less “overengineered” version of repa.

  • if you're mostly interested in linear algebra, should @ least check out of more abstract libraries. vector-space interface, general , mathematical, eschews writing operations in particular basis, lot catch “mathematical bugs”.

  • and while mention lenses, there linear – elegant , abstract in different way. imo misses point of linearity bit (mathematically), it's still pretty cool , offers more operations vector-space.

  • oh, and, finally, there's matrix. it's quite of similar hmatrix, implemented in native haskell rather gsl bindings, means it's not rich in highly-optimised la algorithms, not such heavy dependency. apart that, appears more elegant.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -