diff options
Diffstat (limited to 'packages/base')
23 files changed, 92 insertions, 134 deletions
diff --git a/packages/base/hmatrix.cabal b/packages/base/hmatrix.cabal index a487928..0ab4821 100644 --- a/packages/base/hmatrix.cabal +++ b/packages/base/hmatrix.cabal | |||
@@ -47,8 +47,7 @@ library | |||
47 | Numeric.LinearAlgebra.HMatrix | 47 | Numeric.LinearAlgebra.HMatrix |
48 | Numeric.LinearAlgebra.Static | 48 | Numeric.LinearAlgebra.Static |
49 | 49 | ||
50 | other-modules: Internal.Tools | 50 | other-modules: Internal.Vector |
51 | Internal.Vector | ||
52 | Internal.Devel | 51 | Internal.Devel |
53 | Internal.Vectorized | 52 | Internal.Vectorized |
54 | Internal.Matrix | 53 | Internal.Matrix |
diff --git a/packages/base/src/Internal/Algorithms.hs b/packages/base/src/Internal/Algorithms.hs index 328af22..aaf6fbb 100644 --- a/packages/base/src/Internal/Algorithms.hs +++ b/packages/base/src/Internal/Algorithms.hs | |||
@@ -27,12 +27,9 @@ import Internal.Matrix | |||
27 | import Internal.Element | 27 | import Internal.Element |
28 | import Internal.Conversion | 28 | import Internal.Conversion |
29 | import Internal.LAPACK as LAPACK | 29 | import Internal.LAPACK as LAPACK |
30 | import Internal.Numeric | ||
30 | import Data.List(foldl1') | 31 | import Data.List(foldl1') |
31 | import Data.Array | 32 | import Data.Array |
32 | import Internal.Numeric | ||
33 | import Data.Vector.Storable(fromList) | ||
34 | |||
35 | -- :i mul | ||
36 | 33 | ||
37 | {- | Generic linear algebra functions for double precision real and complex matrices. | 34 | {- | Generic linear algebra functions for double precision real and complex matrices. |
38 | 35 | ||
diff --git a/packages/base/src/Internal/CG.hs b/packages/base/src/Internal/CG.hs index 1193b18..fd14212 100644 --- a/packages/base/src/Internal/CG.hs +++ b/packages/base/src/Internal/CG.hs | |||
@@ -16,7 +16,6 @@ import Internal.Sparse | |||
16 | import Numeric.Vector() | 16 | import Numeric.Vector() |
17 | import Internal.Algorithms(linearSolveLS, relativeError, pnorm, NormType(..)) | 17 | import Internal.Algorithms(linearSolveLS, relativeError, pnorm, NormType(..)) |
18 | import Control.Arrow((***)) | 18 | import Control.Arrow((***)) |
19 | import Data.Vector.Storable(fromList) | ||
20 | 19 | ||
21 | {- | 20 | {- |
22 | import Util.Misc(debug, debugMat) | 21 | import Util.Misc(debug, debugMat) |
@@ -30,7 +29,6 @@ infix 0 /// | |||
30 | v /// b = debugMat b 2 asRow v | 29 | v /// b = debugMat b 2 asRow v |
31 | -} | 30 | -} |
32 | 31 | ||
33 | type R = Double | ||
34 | type V = Vector R | 32 | type V = Vector R |
35 | 33 | ||
36 | data CGState = CGState | 34 | data CGState = CGState |
diff --git a/packages/base/src/Internal/Container.hs b/packages/base/src/Internal/Container.hs index 216e31e..f6355b2 100644 --- a/packages/base/src/Internal/Container.hs +++ b/packages/base/src/Internal/Container.hs | |||
@@ -24,14 +24,12 @@ | |||
24 | 24 | ||
25 | module Internal.Container where | 25 | module Internal.Container where |
26 | 26 | ||
27 | import Internal.Tools | ||
28 | import Internal.Vector | 27 | import Internal.Vector |
29 | import Internal.Matrix | 28 | import Internal.Matrix |
30 | import Internal.Element | 29 | import Internal.Element |
31 | import Internal.Numeric | 30 | import Internal.Numeric |
32 | import Data.Complex | 31 | import Data.Complex |
33 | import Internal.Algorithms(Field,linearSolveSVD) | 32 | import Internal.Algorithms(Field,linearSolveSVD) |
34 | import Data.Vector.Storable(fromList) | ||
35 | 33 | ||
36 | ------------------------------------------------------------------ | 34 | ------------------------------------------------------------------ |
37 | 35 | ||
diff --git a/packages/base/src/Internal/Devel.hs b/packages/base/src/Internal/Devel.hs index 61d2c85..b8e04ef 100644 --- a/packages/base/src/Internal/Devel.hs +++ b/packages/base/src/Internal/Devel.hs | |||
@@ -11,7 +11,6 @@ | |||
11 | module Internal.Devel where | 11 | module Internal.Devel where |
12 | 12 | ||
13 | 13 | ||
14 | import Internal.Tools ( (//) ) | ||
15 | import Control.Monad ( when ) | 14 | import Control.Monad ( when ) |
16 | import Foreign.C.Types ( CInt ) | 15 | import Foreign.C.Types ( CInt ) |
17 | --import Foreign.Storable.Complex () | 16 | --import Foreign.Storable.Complex () |
@@ -19,6 +18,11 @@ import Foreign.Ptr(Ptr) | |||
19 | import Control.Exception as E ( SomeException, catch ) | 18 | import Control.Exception as E ( SomeException, catch ) |
20 | 19 | ||
21 | 20 | ||
21 | -- | postfix function application (@flip ($)@) | ||
22 | (//) :: x -> (x -> y) -> y | ||
23 | infixl 0 // | ||
24 | (//) = flip ($) | ||
25 | |||
22 | -- hmm.. | 26 | -- hmm.. |
23 | ww2 w1 o1 w2 o2 f = w1 o1 $ w2 o2 . f | 27 | ww2 w1 o1 w2 o2 f = w1 o1 $ w2 o2 . f |
24 | ww3 w1 o1 w2 o2 w3 o3 f = w1 o1 $ ww2 w2 o2 w3 o3 . f | 28 | ww3 w1 o1 w2 o2 w3 o3 f = w1 o1 $ ww2 w2 o2 w3 o3 . f |
diff --git a/packages/base/src/Internal/Element.hs b/packages/base/src/Internal/Element.hs index 61a75d8..55bff67 100644 --- a/packages/base/src/Internal/Element.hs +++ b/packages/base/src/Internal/Element.hs | |||
@@ -21,15 +21,14 @@ | |||
21 | 21 | ||
22 | module Internal.Element where | 22 | module Internal.Element where |
23 | 23 | ||
24 | import Internal.Tools | ||
25 | import Internal.Vector | 24 | import Internal.Vector |
26 | import Internal.Matrix | 25 | import Internal.Matrix |
27 | import Internal.Vectorized | 26 | import Internal.Vectorized |
28 | import qualified Internal.ST as ST | 27 | import qualified Internal.ST as ST |
29 | import Data.Array | 28 | import Data.Array |
30 | import Text.Printf | 29 | import Text.Printf |
31 | import Data.Vector.Storable(fromList) | ||
32 | import Data.List(transpose,intersperse) | 30 | import Data.List(transpose,intersperse) |
31 | import Data.List.Split(chunksOf) | ||
33 | import Foreign.Storable(Storable) | 32 | import Foreign.Storable(Storable) |
34 | import Control.Monad(liftM) | 33 | import Control.Monad(liftM) |
35 | 34 | ||
@@ -165,6 +164,15 @@ m ?? (er,ec) = extractR m moder rs modec cs | |||
165 | 164 | ||
166 | -------------------------------------------------------------------------------- | 165 | -------------------------------------------------------------------------------- |
167 | 166 | ||
167 | -- | obtains the common value of a property of a list | ||
168 | common :: (Eq a) => (b->a) -> [b] -> Maybe a | ||
169 | common f = commonval . map f | ||
170 | where | ||
171 | commonval :: (Eq a) => [a] -> Maybe a | ||
172 | commonval [] = Nothing | ||
173 | commonval [a] = Just a | ||
174 | commonval (a:b:xs) = if a==b then commonval (b:xs) else Nothing | ||
175 | |||
168 | 176 | ||
169 | -- | creates a matrix from a vertical list of matrices | 177 | -- | creates a matrix from a vertical list of matrices |
170 | joinVert :: Element t => [Matrix t] -> Matrix t | 178 | joinVert :: Element t => [Matrix t] -> Matrix t |
@@ -210,7 +218,7 @@ adaptBlocks ms = ms' where | |||
210 | rs = map (compatdim . map rows) ms | 218 | rs = map (compatdim . map rows) ms |
211 | cs = map (compatdim . map cols) (transpose ms) | 219 | cs = map (compatdim . map cols) (transpose ms) |
212 | szs = sequence [rs,cs] | 220 | szs = sequence [rs,cs] |
213 | ms' = splitEvery bc $ zipWith g szs (concat ms) | 221 | ms' = chunksOf bc $ zipWith g szs (concat ms) |
214 | 222 | ||
215 | g [Just nr,Just nc] m | 223 | g [Just nr,Just nc] m |
216 | | nr == r && nc == c = m | 224 | | nr == r && nc == c = m |
diff --git a/packages/base/src/Internal/IO.hs b/packages/base/src/Internal/IO.hs index e594a1c..a899cfd 100644 --- a/packages/base/src/Internal/IO.hs +++ b/packages/base/src/Internal/IO.hs | |||
@@ -16,16 +16,26 @@ module Internal.IO ( | |||
16 | loadMatrix, loadMatrix', saveMatrix | 16 | loadMatrix, loadMatrix', saveMatrix |
17 | ) where | 17 | ) where |
18 | 18 | ||
19 | import Internal.Tools | ||
20 | import Internal.Devel | 19 | import Internal.Devel |
21 | import Internal.Vector | 20 | import Internal.Vector |
22 | import Internal.Matrix | 21 | import Internal.Matrix |
23 | import Internal.Vectorized | 22 | import Internal.Vectorized |
24 | import Text.Printf(printf) | 23 | import Text.Printf(printf) |
25 | import Data.List(intersperse) | 24 | import Data.List(intersperse,transpose) |
26 | import Data.Complex | 25 | import Data.Complex |
27 | 26 | ||
28 | 27 | ||
28 | -- | Formatting tool | ||
29 | table :: String -> [[String]] -> String | ||
30 | table sep as = unlines . map unwords' $ transpose mtp | ||
31 | where | ||
32 | mt = transpose as | ||
33 | longs = map (maximum . map length) mt | ||
34 | mtp = zipWith (\a b -> map (pad a) b) longs mt | ||
35 | pad n str = replicate (n - length str) ' ' ++ str | ||
36 | unwords' = concat . intersperse sep | ||
37 | |||
38 | |||
29 | 39 | ||
30 | {- | Creates a string from a matrix given a separator and a function to show each entry. Using | 40 | {- | Creates a string from a matrix given a separator and a function to show each entry. Using |
31 | this function the user can easily define any desired display function: | 41 | this function the user can easily define any desired display function: |
diff --git a/packages/base/src/Internal/LAPACK.hs b/packages/base/src/Internal/LAPACK.hs index 9cab3f8..d6a2e6e 100644 --- a/packages/base/src/Internal/LAPACK.hs +++ b/packages/base/src/Internal/LAPACK.hs | |||
@@ -20,19 +20,15 @@ import Internal.Vector | |||
20 | import Internal.Matrix | 20 | import Internal.Matrix |
21 | import Internal.Conversion | 21 | import Internal.Conversion |
22 | import Internal.Element | 22 | import Internal.Element |
23 | |||
24 | import Foreign.Ptr(nullPtr) | 23 | import Foreign.Ptr(nullPtr) |
25 | import Foreign.C.Types | 24 | import Foreign.C.Types |
26 | import Control.Monad(when) | 25 | import Control.Monad(when) |
27 | import System.IO.Unsafe(unsafePerformIO) | 26 | import System.IO.Unsafe(unsafePerformIO) |
28 | import Data.Vector.Storable(fromList) | ||
29 | 27 | ||
30 | ----------------------------------------------------------------------------------- | 28 | ----------------------------------------------------------------------------------- |
31 | 29 | ||
32 | type TMMM t = t ..> t ..> t ..> Ok | 30 | type TMMM t = t ..> t ..> t ..> Ok |
33 | 31 | ||
34 | type R = Double | ||
35 | type C = Complex Double | ||
36 | type F = Float | 32 | type F = Float |
37 | type Q = Complex Float | 33 | type Q = Complex Float |
38 | 34 | ||
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, |
diff --git a/packages/base/src/Internal/Modular.hs b/packages/base/src/Internal/Modular.hs index 1116b96..cf50a05 100644 --- a/packages/base/src/Internal/Modular.hs +++ b/packages/base/src/Internal/Modular.hs | |||
@@ -29,13 +29,11 @@ import Internal.Vector | |||
29 | import Internal.Matrix hiding (mat,size) | 29 | import Internal.Matrix hiding (mat,size) |
30 | import Internal.Numeric | 30 | import Internal.Numeric |
31 | import Internal.Element | 31 | import Internal.Element |
32 | import Internal.Tools | ||
33 | import Internal.Container | 32 | import Internal.Container |
34 | import Internal.Util(Indexable(..),gaussElim) | 33 | import Internal.Util(Indexable(..),gaussElim) |
35 | import GHC.TypeLits | 34 | import GHC.TypeLits |
36 | import Data.Proxy(Proxy) | 35 | import Data.Proxy(Proxy) |
37 | import Foreign.ForeignPtr(castForeignPtr) | 36 | import Foreign.ForeignPtr(castForeignPtr) |
38 | import Data.Vector.Storable(fromList,unsafeToForeignPtr, unsafeFromForeignPtr) | ||
39 | import Foreign.Storable | 37 | import Foreign.Storable |
40 | import Data.Ratio | 38 | import Data.Ratio |
41 | 39 | ||
diff --git a/packages/base/src/Internal/Numeric.hs b/packages/base/src/Internal/Numeric.hs index af665a4..879daf8 100644 --- a/packages/base/src/Internal/Numeric.hs +++ b/packages/base/src/Internal/Numeric.hs | |||
@@ -18,7 +18,6 @@ | |||
18 | 18 | ||
19 | module Internal.Numeric where | 19 | module Internal.Numeric where |
20 | 20 | ||
21 | import Internal.Tools | ||
22 | import Internal.Vector | 21 | import Internal.Vector |
23 | import Internal.Matrix | 22 | import Internal.Matrix |
24 | import Internal.Element | 23 | import Internal.Element |
@@ -26,7 +25,7 @@ import Internal.ST as ST | |||
26 | import Internal.Conversion | 25 | import Internal.Conversion |
27 | import Internal.Vectorized | 26 | import Internal.Vectorized |
28 | import Internal.LAPACK(multiplyR,multiplyC,multiplyF,multiplyQ,multiplyI) | 27 | import Internal.LAPACK(multiplyR,multiplyC,multiplyF,multiplyQ,multiplyI) |
29 | import Data.Vector.Storable(fromList) | 28 | import Data.List.Split(chunksOf) |
30 | 29 | ||
31 | -------------------------------------------------------------------------------- | 30 | -------------------------------------------------------------------------------- |
32 | 31 | ||
@@ -617,7 +616,7 @@ m2=(4><3) | |||
617 | -} | 616 | -} |
618 | kronecker :: (Product t) => Matrix t -> Matrix t -> Matrix t | 617 | kronecker :: (Product t) => Matrix t -> Matrix t -> Matrix t |
619 | kronecker a b = fromBlocks | 618 | kronecker a b = fromBlocks |
620 | . splitEvery (cols a) | 619 | . chunksOf (cols a) |
621 | . map (reshape (cols b)) | 620 | . map (reshape (cols b)) |
622 | . toRows | 621 | . toRows |
623 | $ flatten a `outer` flatten b | 622 | $ flatten a `outer` flatten b |
diff --git a/packages/base/src/Internal/Random.hs b/packages/base/src/Internal/Random.hs index c44c272..8c792eb 100644 --- a/packages/base/src/Internal/Random.hs +++ b/packages/base/src/Internal/Random.hs | |||
@@ -25,8 +25,6 @@ import Internal.Matrix | |||
25 | import Internal.Numeric | 25 | import Internal.Numeric |
26 | import Internal.Algorithms | 26 | import Internal.Algorithms |
27 | import System.Random(randomIO) | 27 | import System.Random(randomIO) |
28 | import Data.Vector.Storable(fromList) | ||
29 | |||
30 | 28 | ||
31 | -- | Obtains a matrix whose rows are pseudorandom samples from a multivariate | 29 | -- | Obtains a matrix whose rows are pseudorandom samples from a multivariate |
32 | -- Gaussian distribution. | 30 | -- Gaussian distribution. |
diff --git a/packages/base/src/Internal/ST.hs b/packages/base/src/Internal/ST.hs index 25e7969..ae75a1b 100644 --- a/packages/base/src/Internal/ST.hs +++ b/packages/base/src/Internal/ST.hs | |||
@@ -32,9 +32,6 @@ module Internal.ST ( | |||
32 | import Internal.Vector | 32 | import Internal.Vector |
33 | import Internal.Matrix | 33 | import Internal.Matrix |
34 | import Internal.Vectorized | 34 | import Internal.Vectorized |
35 | import Data.Vector.Storable(unsafeWith) | ||
36 | |||
37 | |||
38 | import Control.Monad.ST(ST, runST) | 35 | import Control.Monad.ST(ST, runST) |
39 | import Foreign.Storable(Storable, peekElemOff, pokeElemOff) | 36 | import Foreign.Storable(Storable, peekElemOff, pokeElemOff) |
40 | 37 | ||
diff --git a/packages/base/src/Internal/Sparse.hs b/packages/base/src/Internal/Sparse.hs index 930bc99..b365c15 100644 --- a/packages/base/src/Internal/Sparse.hs +++ b/packages/base/src/Internal/Sparse.hs | |||
@@ -14,9 +14,7 @@ import Internal.Vector | |||
14 | import Internal.Matrix | 14 | import Internal.Matrix |
15 | import Internal.Numeric | 15 | import Internal.Numeric |
16 | import Internal.Container | 16 | import Internal.Container |
17 | import Internal.Tools | ||
18 | import qualified Data.Vector.Storable as V | 17 | import qualified Data.Vector.Storable as V |
19 | import Data.Vector.Storable(fromList) | ||
20 | import Data.Function(on) | 18 | import Data.Function(on) |
21 | import Control.Arrow((***)) | 19 | import Control.Arrow((***)) |
22 | import Control.Monad(when) | 20 | import Control.Monad(when) |
diff --git a/packages/base/src/Internal/Static.hs b/packages/base/src/Internal/Static.hs index 48327e5..01c2205 100644 --- a/packages/base/src/Internal/Static.hs +++ b/packages/base/src/Internal/Static.hs | |||
@@ -25,8 +25,8 @@ module Internal.Static where | |||
25 | 25 | ||
26 | import GHC.TypeLits | 26 | import GHC.TypeLits |
27 | import qualified Numeric.LinearAlgebra as LA | 27 | import qualified Numeric.LinearAlgebra as LA |
28 | import Numeric.LinearAlgebra hiding (konst,size) | 28 | import Numeric.LinearAlgebra hiding (konst,size,R,C) |
29 | import Internal.Vector as D | 29 | import Internal.Vector as D hiding (R,C) |
30 | import Internal.ST | 30 | import Internal.ST |
31 | import Data.Proxy(Proxy) | 31 | import Data.Proxy(Proxy) |
32 | import Foreign.Storable(Storable) | 32 | import Foreign.Storable(Storable) |
diff --git a/packages/base/src/Internal/Tools.hs b/packages/base/src/Internal/Tools.hs deleted file mode 100644 index 47115bc..0000000 --- a/packages/base/src/Internal/Tools.hs +++ /dev/null | |||
@@ -1,61 +0,0 @@ | |||
1 | -- | | ||
2 | -- Module : Internal.Tools | ||
3 | -- Copyright : (c) Alberto Ruiz 2007-15 | ||
4 | -- License : BSD3 | ||
5 | -- Maintainer : Alberto Ruiz | ||
6 | -- Stability : provisional | ||
7 | -- | ||
8 | |||
9 | module Internal.Tools where | ||
10 | |||
11 | import Data.List(transpose,intersperse) | ||
12 | import Foreign.C.Types(CInt) | ||
13 | import Data.List.Split | ||
14 | |||
15 | type I = CInt | ||
16 | |||
17 | splitEvery :: Int -> [e] -> [[e]] | ||
18 | splitEvery = chunksOf | ||
19 | |||
20 | -- | postfix function application (@flip ($)@) | ||
21 | (//) :: x -> (x -> y) -> y | ||
22 | infixl 0 // | ||
23 | (//) = flip ($) | ||
24 | |||
25 | -- | specialized fromIntegral | ||
26 | fi :: Int -> CInt | ||
27 | fi = fromIntegral | ||
28 | |||
29 | -- | specialized fromIntegral | ||
30 | ti :: CInt -> Int | ||
31 | ti = fromIntegral | ||
32 | |||
33 | -- | obtains the common value of a property of a list | ||
34 | common :: (Eq a) => (b->a) -> [b] -> Maybe a | ||
35 | common f = commonval . map f | ||
36 | where | ||
37 | commonval :: (Eq a) => [a] -> Maybe a | ||
38 | commonval [] = Nothing | ||
39 | commonval [a] = Just a | ||
40 | commonval (a:b:xs) = if a==b then commonval (b:xs) else Nothing | ||
41 | |||
42 | -- | common value with \"adaptable\" 1 | ||
43 | compatdim :: [Int] -> Maybe Int | ||
44 | compatdim [] = Nothing | ||
45 | compatdim [a] = Just a | ||
46 | compatdim (a:b:xs) | ||
47 | | a==b = compatdim (b:xs) | ||
48 | | a==1 = compatdim (b:xs) | ||
49 | | b==1 = compatdim (a:xs) | ||
50 | | otherwise = Nothing | ||
51 | |||
52 | -- | Formatting tool | ||
53 | table :: String -> [[String]] -> String | ||
54 | table sep as = unlines . map unwords' $ transpose mtp | ||
55 | where | ||
56 | mt = transpose as | ||
57 | longs = map (maximum . map length) mt | ||
58 | mtp = zipWith (\a b -> map (pad a) b) longs mt | ||
59 | pad n str = replicate (n - length str) ' ' ++ str | ||
60 | unwords' = concat . intersperse sep | ||
61 | |||
diff --git a/packages/base/src/Internal/Util.hs b/packages/base/src/Internal/Util.hs index 9900770..e9cf155 100644 --- a/packages/base/src/Internal/Util.hs +++ b/packages/base/src/Internal/Util.hs | |||
@@ -56,7 +56,6 @@ module Internal.Util( | |||
56 | gaussElim | 56 | gaussElim |
57 | ) where | 57 | ) where |
58 | 58 | ||
59 | import Internal.Tools | ||
60 | import Internal.Vector | 59 | import Internal.Vector |
61 | import Internal.Matrix hiding (size) | 60 | import Internal.Matrix hiding (size) |
62 | import Internal.Numeric | 61 | import Internal.Numeric |
@@ -76,7 +75,6 @@ import Data.List(intercalate,sortBy) | |||
76 | import Data.Function(on) | 75 | import Data.Function(on) |
77 | import Control.Arrow((&&&)) | 76 | import Control.Arrow((&&&)) |
78 | import Data.Complex | 77 | import Data.Complex |
79 | import Data.Vector.Storable(fromList) | ||
80 | 78 | ||
81 | type ℝ = Double | 79 | type ℝ = Double |
82 | type ℕ = Int | 80 | type ℕ = Int |
diff --git a/packages/base/src/Internal/Vector.hs b/packages/base/src/Internal/Vector.hs index 27ee13c..0e9161d 100644 --- a/packages/base/src/Internal/Vector.hs +++ b/packages/base/src/Internal/Vector.hs | |||
@@ -10,38 +10,56 @@ | |||
10 | -- Stability : provisional | 10 | -- Stability : provisional |
11 | -- | 11 | -- |
12 | 12 | ||
13 | module Internal.Vector where | 13 | module Internal.Vector( |
14 | 14 | I,Z,R,C, | |
15 | import Internal.Tools | 15 | fi,ti, |
16 | import Foreign.Marshal.Array ( peekArray, copyArray, advancePtr ) | 16 | Vector, fromList, unsafeToForeignPtr, unsafeFromForeignPtr, unsafeWith, |
17 | import Foreign.ForeignPtr ( ForeignPtr, castForeignPtr ) | 17 | createVector, vec, |
18 | import Foreign.Ptr ( Ptr ) | 18 | toList, dim, (@>), at', (|>), |
19 | vjoin, subVector, takesV, idxs, | ||
20 | buildVector, | ||
21 | asReal, asComplex, | ||
22 | toByteString,fromByteString, | ||
23 | zipVector, unzipVector, zipVectorWith, unzipVectorWith, | ||
24 | foldVector, foldVectorG, foldVectorWithIndex, foldLoop, | ||
25 | mapVector, mapVectorM, mapVectorM_, | ||
26 | mapVectorWithIndex, mapVectorWithIndexM, mapVectorWithIndexM_ | ||
27 | ) where | ||
28 | |||
29 | import Foreign.Marshal.Array | ||
30 | import Foreign.ForeignPtr | ||
31 | import Foreign.Ptr | ||
19 | import Foreign.Storable | 32 | import Foreign.Storable |
20 | ( Storable, peekElemOff, pokeElemOff, sizeOf ) | 33 | import Foreign.C.Types(CInt) |
21 | import Foreign.C.Types ( CInt ) | 34 | import Data.Int(Int64) |
22 | import Data.Complex ( Complex ) | 35 | import Data.Complex |
23 | import System.IO.Unsafe ( unsafePerformIO ) | 36 | import System.IO.Unsafe(unsafePerformIO) |
24 | import GHC.ForeignPtr ( mallocPlainForeignPtrBytes ) | 37 | import GHC.ForeignPtr(mallocPlainForeignPtrBytes) |
25 | import GHC.Base ( realWorld#, IO(IO), when ) | 38 | import GHC.Base(realWorld#, IO(IO), when) |
26 | import qualified Data.Vector.Storable as Vector | 39 | import qualified Data.Vector.Storable as Vector |
27 | ( Vector, slice, length ) | 40 | import Data.Vector.Storable(Vector, fromList, unsafeToForeignPtr, unsafeFromForeignPtr, unsafeWith) |
28 | import Data.Vector.Storable | ||
29 | ( fromList, unsafeToForeignPtr, unsafeFromForeignPtr, unsafeWith ) | ||
30 | |||
31 | 41 | ||
32 | #ifdef BINARY | 42 | #ifdef BINARY |
33 | |||
34 | import Data.Binary | 43 | import Data.Binary |
35 | import Control.Monad(replicateM) | 44 | import Control.Monad(replicateM) |
36 | import qualified Data.ByteString.Internal as BS | 45 | import qualified Data.ByteString.Internal as BS |
37 | import Data.Vector.Storable.Internal(updPtr) | 46 | import Data.Vector.Storable.Internal(updPtr) |
38 | import Foreign.Ptr(plusPtr) | ||
39 | |||
40 | #endif | 47 | #endif |
41 | 48 | ||
49 | type I = CInt | ||
50 | type Z = Int64 | ||
51 | type R = Double | ||
52 | type C = Complex Double | ||
53 | |||
54 | |||
55 | -- | specialized fromIntegral | ||
56 | fi :: Int -> CInt | ||
57 | fi = fromIntegral | ||
42 | 58 | ||
59 | -- | specialized fromIntegral | ||
60 | ti :: CInt -> Int | ||
61 | ti = fromIntegral | ||
43 | 62 | ||
44 | type Vector = Vector.Vector | ||
45 | 63 | ||
46 | -- | Number of elements | 64 | -- | Number of elements |
47 | dim :: (Storable t) => Vector t -> Int | 65 | dim :: (Storable t) => Vector t -> Int |
diff --git a/packages/base/src/Internal/Vectorized.hs b/packages/base/src/Internal/Vectorized.hs index ddb14c9..b9b8239 100644 --- a/packages/base/src/Internal/Vectorized.hs +++ b/packages/base/src/Internal/Vectorized.hs | |||
@@ -14,10 +14,8 @@ | |||
14 | 14 | ||
15 | module Internal.Vectorized where | 15 | module Internal.Vectorized where |
16 | 16 | ||
17 | import Internal.Tools | ||
18 | import Internal.Vector | 17 | import Internal.Vector |
19 | import Internal.Devel | 18 | import Internal.Devel |
20 | |||
21 | import Data.Complex | 19 | import Data.Complex |
22 | import Foreign.Marshal.Alloc(free,malloc) | 20 | import Foreign.Marshal.Alloc(free,malloc) |
23 | import Foreign.Marshal.Array(newArray,copyArray) | 21 | import Foreign.Marshal.Array(newArray,copyArray) |
@@ -26,9 +24,8 @@ import Foreign.Storable(peek,Storable) | |||
26 | import Foreign.C.Types | 24 | import Foreign.C.Types |
27 | import Foreign.C.String | 25 | import Foreign.C.String |
28 | import System.IO.Unsafe(unsafePerformIO) | 26 | import System.IO.Unsafe(unsafePerformIO) |
29 | |||
30 | import Control.Monad(when) | 27 | import Control.Monad(when) |
31 | import Data.Vector.Storable ( unsafeWith ) | 28 | |
32 | 29 | ||
33 | 30 | ||
34 | fromei x = fromIntegral (fromEnum x) :: CInt | 31 | fromei x = fromIntegral (fromEnum x) :: CInt |
diff --git a/packages/base/src/Numeric/LinearAlgebra/Data.hs b/packages/base/src/Numeric/LinearAlgebra/Data.hs index 196ada9..06485e6 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Data.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Data.hs | |||
@@ -88,12 +88,11 @@ module Numeric.LinearAlgebra.Data( | |||
88 | separable, | 88 | separable, |
89 | fromArray2D, | 89 | fromArray2D, |
90 | module Data.Complex, | 90 | module Data.Complex, |
91 | I,F, | 91 | R,C,I,Z,F, |
92 | Vector, Matrix, GMatrix, nRows, nCols | 92 | Vector, Matrix, GMatrix, nRows, nCols |
93 | 93 | ||
94 | ) where | 94 | ) where |
95 | 95 | ||
96 | import Internal.Tools | ||
97 | import Internal.Vector | 96 | import Internal.Vector |
98 | import Internal.Vectorized | 97 | import Internal.Vectorized |
99 | import Internal.Matrix hiding (size) | 98 | import Internal.Matrix hiding (size) |
@@ -105,6 +104,5 @@ import Internal.Util hiding ((&),(#)) | |||
105 | import Data.Complex | 104 | import Data.Complex |
106 | import Internal.Sparse | 105 | import Internal.Sparse |
107 | import Internal.Modular | 106 | import Internal.Modular |
108 | import Data.Vector.Storable(fromList) | ||
109 | 107 | ||
110 | 108 | ||
diff --git a/packages/base/src/Numeric/LinearAlgebra/Devel.hs b/packages/base/src/Numeric/LinearAlgebra/Devel.hs index 4d5b5cb..1a70663 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Devel.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Devel.hs | |||
@@ -68,7 +68,6 @@ module Numeric.LinearAlgebra.Devel( | |||
68 | 68 | ||
69 | ) where | 69 | ) where |
70 | 70 | ||
71 | import Internal.Tools | ||
72 | import Internal.Foreign | 71 | import Internal.Foreign |
73 | import Internal.Devel | 72 | import Internal.Devel |
74 | import Internal.ST | 73 | import Internal.ST |
@@ -76,5 +75,4 @@ import Internal.Vector | |||
76 | import Internal.Matrix | 75 | import Internal.Matrix |
77 | import Internal.Element | 76 | import Internal.Element |
78 | import Internal.Sparse | 77 | import Internal.Sparse |
79 | import Data.Vector.Storable (unsafeToForeignPtr, unsafeFromForeignPtr ) | ||
80 | 78 | ||
diff --git a/packages/base/src/Numeric/LinearAlgebra/Static.hs b/packages/base/src/Numeric/LinearAlgebra/Static.hs index 04c4151..dee5b2c 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Static.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Static.hs | |||
@@ -65,7 +65,7 @@ import Numeric.LinearAlgebra hiding ( | |||
65 | row,col,vector,matrix,linspace,toRows,toColumns, | 65 | row,col,vector,matrix,linspace,toRows,toColumns, |
66 | (<\>),fromList,takeDiag,svd,eig,eigSH,eigSH', | 66 | (<\>),fromList,takeDiag,svd,eig,eigSH,eigSH', |
67 | eigenvalues,eigenvaluesSH,eigenvaluesSH',build, | 67 | eigenvalues,eigenvaluesSH,eigenvaluesSH',build, |
68 | qr,size,app,mul,dot,chol,range) | 68 | qr,size,app,mul,dot,chol,range,R,C) |
69 | import qualified Numeric.LinearAlgebra as LA | 69 | import qualified Numeric.LinearAlgebra as LA |
70 | import Data.Proxy(Proxy) | 70 | import Data.Proxy(Proxy) |
71 | import Internal.Static | 71 | import Internal.Static |
diff --git a/packages/base/src/Numeric/Vector.hs b/packages/base/src/Numeric/Vector.hs index 7525890..076f485 100644 --- a/packages/base/src/Numeric/Vector.hs +++ b/packages/base/src/Numeric/Vector.hs | |||
@@ -19,11 +19,9 @@ | |||
19 | 19 | ||
20 | module Numeric.Vector () where | 20 | module Numeric.Vector () where |
21 | 21 | ||
22 | import Internal.Tools | ||
23 | import Internal.Vectorized | 22 | import Internal.Vectorized |
24 | import Internal.Vector | 23 | import Internal.Vector |
25 | import Internal.Numeric | 24 | import Internal.Numeric |
26 | import Data.Vector.Storable(fromList) | ||
27 | import Internal.Conversion | 25 | import Internal.Conversion |
28 | 26 | ||
29 | ------------------------------------------------------------------- | 27 | ------------------------------------------------------------------- |