matrix 0.3.1.0 → 0.3.1.1
raw patch · 2 files changed
+33/−11 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Data/Matrix.hs +32/−10
- matrix.cabal +1/−1
Data/Matrix.hs view
@@ -90,6 +90,11 @@ (q,r) = quotRem k m -- | Type of matrices.+--+-- Elements can be of any type. Rows and columns+-- are indexed starting by 1. This means that, if @m :: Matrix a@ and+-- @i,j :: Int@, then @m ! (i,j)@ is the element in the @i@-th row and+-- @j@-th column of @m@. data Matrix a = M { nrows :: {-# UNPACK #-} !Int -- ^ Number of rows. , ncols :: {-# UNPACK #-} !Int -- ^ Number of columns.@@ -116,7 +121,7 @@ -- | /O(rows*cols)/. Similar to 'V.force', drop any extra memory. ----- Useful when using 'submatrix' from a big matrix.+-- Useful when using 'getRow' from a big matrix. forceMatrix :: Matrix a -> Matrix a forceMatrix (M n m v) = M n m $ V.force v @@ -231,16 +236,24 @@ fromList n m = M n m . V.fromListN (n*m) -- | Create a matrix from an non-empty list of non-empty lists.--- /Each list must have the same number of elements/.--- For example:+-- /Each list must have at least as many elements as the first list/.+-- Examples: -- -- > fromLists [ [1,2,3] ( 1 2 3 ) -- > , [4,5,6] ( 4 5 6 ) -- > , [7,8,9] ] = ( 7 8 9 ) --+-- > fromLists [ [1,2,3 ] ( 1 2 3 )+-- > , [4,5,6,7] ( 4 5 6 )+-- > , [8,9,0 ] ] = ( 8 9 0 )+-- fromLists :: [[a]] -> Matrix a {-# INLINE fromLists #-}-fromLists xss = fromList (length xss) (length $ head xss) $ concat xss+fromLists [] = error "fromLists: empty list."+fromLists (xs:xss) = fromList n m $ concat $ xs : fmap (take m) xss+ where+ n = 1 + length xss+ m = length xs -- | /O(1)/. Represent a vector as a one row matrix. rowVector :: V.Vector a -> Matrix a@@ -346,14 +359,14 @@ {-# INLINE unsafeMset #-} unsafeMset x m p v = MV.unsafeWrite v (encode m p) x --- | /O(1)/. Replace the value of a cell in a matrix.+-- | Replace the value of a cell in a matrix. setElem :: a -- ^ New value. -> (Int,Int) -- ^ Position to replace. -> Matrix a -- ^ Original matrix. -> Matrix a -- ^ Matrix with the given position replaced with the given value. setElem x p (M n m v) = M n m $ V.modify (msetElem x m p) v --- | /O(1)/. Unsafe variant of 'setElem', without bounds checking.+-- | Unsafe variant of 'setElem', without bounds checking. unsafeSet :: a -- ^ New value. -> (Int,Int) -- ^ Position to replace. -> Matrix a -- ^ Original matrix.@@ -378,6 +391,11 @@ -- > ( 1 2 3 ) ( 4 5 6 0 0 ) -- > ( 4 5 6 ) ( 7 8 9 0 0 ) -- > extendTo 0 4 5 ( 7 8 9 ) = ( 0 0 0 0 0 )+--+-- The definition of 'extendTo' is based on 'setSize':+--+-- > extendTo e n m a = setSize e (max n $ nrows a) (max m $ ncols a) a+-- extendTo :: a -- ^ Element to add when extending. -> Int -- ^ Minimal number of rows. -> Int -- ^ Minimal number of columns.@@ -435,7 +453,7 @@ minorMatrix r c (M n m v) = M (n-1) (m-1) $ V.ifilter (\k _ -> let (i,j) = decode m k in i /= r && j /= c) v --- | Make a block-partition of a matrix using a given element as reference.+-- | /O(rows*cols)/. Make a block-partition of a matrix using a given element as reference. -- The element will stay in the bottom-right corner of the top-left corner matrix. -- -- > ( ) ( | )@@ -463,8 +481,12 @@ splitBlocks i j a@(M n m _) = ( submatrix 1 i 1 j a , submatrix 1 i (j+1) m a , submatrix (i+1) n 1 j a , submatrix (i+1) n (j+1) m a ) ---- | Join blocks of the form detailed in 'splitBlocks'.+-- | Join blocks of the form detailed in 'splitBlocks'. Precisely:+--+-- > joinBlocks (tl,tr,bl,br) =+-- > (tl <|> tr)+-- > <->+-- > (bl <|> br) joinBlocks :: (Matrix a,Matrix a,Matrix a,Matrix a) -> Matrix a joinBlocks (tl,tr,bl,br) = (tl <|> tr) <->@@ -506,7 +528,7 @@ ------------------------------------------------------- ---- MATRIX OPERATIONS --- | Perform an operation elementwise. The input matrices are assumed+-- | Perform an operation element-wise. The input matrices are assumed -- to have the same dimensions, but this is not checked. elementwise :: (a -> b -> c) -> (Matrix a -> Matrix b -> Matrix c) elementwise f (M n m v) (M _ _ v') = M n m $ V.zipWith f v v'
matrix.cabal view
@@ -1,5 +1,5 @@ Name: matrix -Version: 0.3.1.0 +Version: 0.3.1.1 Author: Daniel Díaz Category: Math Build-type: Simple