diff options
Diffstat (limited to 'packages/base/src/Internal/Matrix.hs')
-rw-r--r-- | packages/base/src/Internal/Matrix.hs | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/packages/base/src/Internal/Matrix.hs b/packages/base/src/Internal/Matrix.hs index 44365d0..d715cbf 100644 --- a/packages/base/src/Internal/Matrix.hs +++ b/packages/base/src/Internal/Matrix.hs | |||
@@ -16,12 +16,9 @@ | |||
16 | 16 | ||
17 | module Internal.Matrix where | 17 | module Internal.Matrix where |
18 | 18 | ||
19 | |||
20 | import Internal.Tools ( splitEvery, fi, compatdim, (//) ) | ||
21 | import Internal.Vector | 19 | import Internal.Vector |
22 | import Internal.Devel | 20 | import Internal.Devel |
23 | import Internal.Vectorized | 21 | import Internal.Vectorized |
24 | import Data.Vector.Storable ( unsafeWith, fromList ) | ||
25 | import Foreign.Marshal.Alloc ( free ) | 22 | import Foreign.Marshal.Alloc ( free ) |
26 | import Foreign.Ptr ( Ptr ) | 23 | import Foreign.Ptr ( Ptr ) |
27 | import Foreign.Storable ( Storable ) | 24 | import Foreign.Storable ( Storable ) |
@@ -30,7 +27,7 @@ import Foreign.C.Types ( CInt(..) ) | |||
30 | import Foreign.C.String ( CString, newCString ) | 27 | import Foreign.C.String ( CString, newCString ) |
31 | import System.IO.Unsafe ( unsafePerformIO ) | 28 | import System.IO.Unsafe ( unsafePerformIO ) |
32 | import Control.DeepSeq ( NFData(..) ) | 29 | import Control.DeepSeq ( NFData(..) ) |
33 | 30 | import Data.List.Split(chunksOf) | |
34 | 31 | ||
35 | ----------------------------------------------------------------- | 32 | ----------------------------------------------------------------- |
36 | 33 | ||
@@ -150,7 +147,22 @@ type t ::> s = Mt t s | |||
150 | 147 | ||
151 | -- | the inverse of 'Data.Packed.Matrix.fromLists' | 148 | -- | the inverse of 'Data.Packed.Matrix.fromLists' |
152 | toLists :: (Element t) => Matrix t -> [[t]] | 149 | toLists :: (Element t) => Matrix t -> [[t]] |
153 | toLists m = splitEvery (cols m) . toList . flatten $ m | 150 | toLists m = chunksOf (cols m) . toList . flatten $ m |
151 | |||
152 | |||
153 | |||
154 | -- | common value with \"adaptable\" 1 | ||
155 | compatdim :: [Int] -> Maybe Int | ||
156 | compatdim [] = Nothing | ||
157 | compatdim [a] = Just a | ||
158 | compatdim (a:b:xs) | ||
159 | | a==b = compatdim (b:xs) | ||
160 | | a==1 = compatdim (b:xs) | ||
161 | | b==1 = compatdim (a:xs) | ||
162 | | otherwise = Nothing | ||
163 | |||
164 | |||
165 | |||
154 | 166 | ||
155 | -- | Create a matrix from a list of vectors. | 167 | -- | Create a matrix from a list of vectors. |
156 | -- All vectors must have the same dimension, | 168 | -- All vectors must have the same dimension, |