Permalink
Browse files

Add shape accesor for matrices

  • Loading branch information...
Shimuuar committed Aug 31, 2012
1 parent 552b89c commit 7eeae1d0ca3b533aaee1a3e623ec6606e0a33521
Showing with 12 additions and 0 deletions.
  1. +6 −0 Data/Matrix/Generic.hs
  2. +6 −0 Data/Matrix/Generic/Mutable.hs
View
@@ -18,6 +18,7 @@ module Data.Matrix.Generic (
-- * Accessors
, rows
, cols
+ , shape
, (@!)
, unsafeIndex
-- * Converions to/from mutable
@@ -79,6 +80,11 @@ cols :: IsMatrix mat a => mat a -> Int
{-# INLINE cols #-}
cols = basicCols
+-- | Shape of the matrix.
+shape :: IsMatrix mat a => mat a -> (Int,Int)
+{-# INLINE shape #-}
+shape m = (rows m, cols m)
+
-- | Indexing operator without range checking.
unsafeIndex :: IsMatrix mat a
@@ -17,6 +17,7 @@ module Data.Matrix.Generic.Mutable (
-- * Accesors
, rows
, cols
+ , shape
-- * Reading and writing
, read
, write
@@ -80,6 +81,11 @@ cols :: IsMMatrix mat a => mat s a -> Int
{-# INLINE cols #-}
cols = basicCols
+-- | Shape of the matrix.
+shape :: IsMMatrix mat a => mat s a -> (Int,Int)
+{-# INLINE shape #-}
+shape m = (rows m, cols m)
+
-- | Whether index could be mutated. E.g. not every element of banded
-- matrix could be written to. Function need not to check that
-- indices are inside of the matrix and free to return anything if

0 comments on commit 7eeae1d

Please sign in to comment.