Commits

Sergey Astanin committed d954e1b

at, indexing operation.

Comments (0)

Files changed (1)

src/Data/MatrixMarket.hs

   , mm'rows, mm'cols, mm'shape
   , toList
   , toCompleteList
+  , at
     -- * Re-exports
   , Complex(..)
   )
     | i /= j     = [p, ((j,i),conj v)]
     | otherwise  = [p]
 
+-- | Get an element of the matrix at the specified position.
+-- Warning: This operation is slow.
+at :: MValue a => Matrix a -> (Int, Int) -> a
+m `at` ij = maybe 0 id $ lookup ij $ toCompleteList m
+
 -- | Write Matrix Market format.
 dumpMM :: MValue a => Matrix a -> String
 dumpMM (MM md fld sy coms) = unlines $ header : (map ('%':) coms) ++ body