summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2014-05-16 09:20:47 +0200
committerAlberto Ruiz <aruiz@um.es>2014-05-16 09:20:47 +0200
commit0ab93b8eb934167e16dbae193c4fd2b5359a184b (patch)
treee5d7236890c8310dae90952bfb5f6195dd97295c
parenta86c60a5fbfc73ff3080c88007625c2cd094e80f (diff)
instances moved to base
-rw-r--r--packages/base/hmatrix-base.cabal3
-rw-r--r--packages/base/src/Numeric/Chain.hs (renamed from packages/hmatrix/src/Numeric/Chain.hs)5
-rw-r--r--packages/base/src/Numeric/Matrix.hs (renamed from packages/hmatrix/src/Numeric/Matrix.hs)4
-rw-r--r--packages/base/src/Numeric/Vector.hs (renamed from packages/hmatrix/src/Numeric/Vector.hs)3
-rw-r--r--packages/hmatrix/Config.hs154
-rw-r--r--packages/hmatrix/Setup.lhs15
-rw-r--r--packages/hmatrix/hmatrix.cabal3
-rw-r--r--packages/hmatrix/src/Numeric/Container.hs6
8 files changed, 18 insertions, 175 deletions
diff --git a/packages/base/hmatrix-base.cabal b/packages/base/hmatrix-base.cabal
index 8571e7a..8eeb97e 100644
--- a/packages/base/hmatrix-base.cabal
+++ b/packages/base/hmatrix-base.cabal
@@ -39,12 +39,15 @@ library
39 Numeric.LinearAlgebra.LAPACK 39 Numeric.LinearAlgebra.LAPACK
40 Data.Packed.Numeric 40 Data.Packed.Numeric
41 Numeric.Vectorized 41 Numeric.Vectorized
42 Numeric.Vector
43 Numeric.Matrix
42 44
43 other-modules: Data.Packed.Internal, 45 other-modules: Data.Packed.Internal,
44 Data.Packed.Internal.Common, 46 Data.Packed.Internal.Common,
45 Data.Packed.Internal.Signatures, 47 Data.Packed.Internal.Signatures,
46 Data.Packed.Internal.Vector, 48 Data.Packed.Internal.Vector,
47 Data.Packed.Internal.Matrix 49 Data.Packed.Internal.Matrix
50 Numeric.Chain
48 51
49 C-sources: src/C/lapack-aux.c 52 C-sources: src/C/lapack-aux.c
50 src/C/vector-aux.c 53 src/C/vector-aux.c
diff --git a/packages/hmatrix/src/Numeric/Chain.hs b/packages/base/src/Numeric/Chain.hs
index de6a86f..fbdb01b 100644
--- a/packages/hmatrix/src/Numeric/Chain.hs
+++ b/packages/base/src/Numeric/Chain.hs
@@ -130,7 +130,7 @@ chain_paren (r,c) ixes ma = let ((lr,lc),(rr,rc)) = fromJust $ (ixes A.! r) A.!
130 130
131-------------------------------------------------------------------------- 131--------------------------------------------------------------------------
132 132
133{- TESTS -} 133{- TESTS
134 134
135-- optimal association is ((m1*(m2*m3))*m4) 135-- optimal association is ((m1*(m2*m3))*m4)
136m1, m2, m3, m4 :: Matrix Double 136m1, m2, m3, m4 :: Matrix Double
@@ -138,3 +138,6 @@ m1 = (10><15) [1..]
138m2 = (15><20) [1..] 138m2 = (15><20) [1..]
139m3 = (20><5) [1..] 139m3 = (20><5) [1..]
140m4 = (5><10) [1..] 140m4 = (5><10) [1..]
141
142-}
143
diff --git a/packages/hmatrix/src/Numeric/Matrix.hs b/packages/base/src/Numeric/Matrix.hs
index e285ff2..3478aae 100644
--- a/packages/hmatrix/src/Numeric/Matrix.hs
+++ b/packages/base/src/Numeric/Matrix.hs
@@ -27,9 +27,11 @@ module Numeric.Matrix (
27 27
28------------------------------------------------------------------- 28-------------------------------------------------------------------
29 29
30import Numeric.Container 30import Data.Packed
31import Data.Packed.Numeric
31import qualified Data.Monoid as M 32import qualified Data.Monoid as M
32import Data.List(partition) 33import Data.List(partition)
34import Numeric.Chain
33 35
34------------------------------------------------------------------- 36-------------------------------------------------------------------
35 37
diff --git a/packages/hmatrix/src/Numeric/Vector.hs b/packages/base/src/Numeric/Vector.hs
index 4c59d32..2769cd9 100644
--- a/packages/hmatrix/src/Numeric/Vector.hs
+++ b/packages/base/src/Numeric/Vector.hs
@@ -21,7 +21,8 @@
21module Numeric.Vector () where 21module Numeric.Vector () where
22 22
23import Numeric.Vectorized 23import Numeric.Vectorized
24import Numeric.Container 24import Data.Packed.Vector
25import Data.Packed.Numeric
25 26
26------------------------------------------------------------------- 27-------------------------------------------------------------------
27 28
diff --git a/packages/hmatrix/Config.hs b/packages/hmatrix/Config.hs
deleted file mode 100644
index 5145d1a..0000000
--- a/packages/hmatrix/Config.hs
+++ /dev/null
@@ -1,154 +0,0 @@
1{-
2 GSL and LAPACK may require auxiliary libraries which depend on OS,
3 distribution, and implementation. This script tries to to find out
4 the correct link command for your system.
5 Suggestions and contributions are welcome.
6
7 By default we try to link -lgsl -llapack. This works in ubuntu/debian,
8 both with and without ATLAS.
9 If this fails we try different sets of additional libraries which are
10 known to work in some systems.
11
12 The desired libraries can also be explicitly given by the user using cabal
13 flags (e.g., -fmkl, -faccelerate) or --configure-option=link:lib1,lib2,lib3,...
14
15-}
16
17module Config(config) where
18
19import System.Process
20import System.Exit
21import System.Environment
22import System.Directory(createDirectoryIfMissing)
23import System.FilePath((</>))
24import Data.List(isPrefixOf, intercalate)
25import Distribution.Simple.LocalBuildInfo
26import Distribution.Simple.Configure
27import Distribution.PackageDescription
28
29-- possible additional dependencies for the desired libs (by default gsl lapack)
30
31opts = [ "" -- Ubuntu/Debian
32 , "blas"
33 , "blas cblas"
34 , "cblas"
35 , "gslcblas"
36 , "blas gslcblas"
37 , "f77blas"
38 , "f77blas cblas atlas gcc_s" -- Arch Linux (older version of atlas-lapack)
39 , "blas gslcblas gfortran" -- Arch Linux with normal blas and lapack
40 ]
41
42-- location of test program
43testProgLoc bInfo = buildDir bInfo </> "dummy.c"
44testOutLoc bInfo = buildDir bInfo </> "dummy"
45
46-- write test program
47writeTestProg bInfo contents = writeFile (testProgLoc bInfo) contents
48
49-- compile, discarding error messages
50compile cmd = do
51 let processRecord = (shell $ unwords cmd) { std_out = CreatePipe
52 , std_err = CreatePipe }
53 ( _, _, _, h) <- createProcess processRecord
54 waitForProcess h
55
56-- command to compile the test program
57compileCmd bInfo buildInfo = [ "gcc "
58 , (unwords $ ccOptions buildInfo)
59 , (unwords $ cppOptions buildInfo)
60 , (unwords $ map ("-I"++) $ includeDirs buildInfo)
61 , testProgLoc bInfo
62 , "-o"
63 , testOutLoc bInfo
64 , (unwords $ map ("-L"++) $ extraLibDirs buildInfo)
65 ]
66
67-- compile a simple program with symbols from GSL and LAPACK with the given libs
68testprog bInfo buildInfo libs fmks = do
69 writeTestProg bInfo "#include <gsl/gsl_sf_gamma.h>\nint main(){dgemm_(); zgesvd_(); gsl_sf_gamma(5);}"
70 compile $ compileCmd bInfo
71 buildInfo
72 ++ [ (prepend "-l" $ libs)
73 , (prepend "-framework " fmks) ]
74
75prepend x = unwords . map (x++) . words
76
77check bInfo buildInfo libs fmks = (ExitSuccess ==) `fmap` testprog bInfo buildInfo libs fmks
78
79-- simple test for GSL
80gsl bInfo buildInfo = do
81 writeTestProg bInfo "#include <gsl/gsl_sf_gamma.h>\nint main(){gsl_sf_gamma(5);}"
82 compile $ compileCmd bInfo buildInfo ++ ["-lgsl", "-lgslcblas"]
83
84-- test for gsl >= 1.12
85gsl112 bInfo buildInfo = do
86 writeTestProg bInfo "#include <gsl/gsl_sf_exp.h>\nint main(){gsl_sf_exprel_n_CF_e(1,1,0);}"
87 compile $ compileCmd bInfo buildInfo ++ ["-lgsl", "-lgslcblas"]
88
89-- test for odeiv2
90gslodeiv2 bInfo buildInfo = do
91 writeTestProg bInfo "#include <gsl/gsl_odeiv2.h>\nint main(){return 0;}"
92 compile $ compileCmd bInfo buildInfo ++ ["-lgsl", "-lgslcblas"]
93
94checkCommand c = (ExitSuccess ==) `fmap` c
95
96-- test different configurations until the first one works
97try _ _ _ _ [] = return Nothing
98try l i b f (opt:rest) = do
99 ok <- check l i (b ++ " " ++ opt) f
100 if ok then return (Just opt)
101 else try l i b f rest
102
103-- read --configure-option=link:lib1,lib2,lib3,etc
104linkop = "--configure-option=link:"
105getUserLink = concatMap (g . drop (length linkop)) . filter (isPrefixOf linkop)
106 where g = map cs
107 cs ',' = ' '
108 cs x = x
109
110config :: LocalBuildInfo -> IO HookedBuildInfo
111
112config bInfo = do
113 putStr "Checking foreign libraries..."
114 args <- getArgs
115
116 let Just lib = library . localPkgDescr $ bInfo
117 buildInfo = libBuildInfo lib
118 base = unwords . extraLibs $ buildInfo
119 fwks = unwords . frameworks $ buildInfo
120 auxpref = getUserLink args
121
122 -- We extract the desired libs from hmatrix.cabal (using a cabal flags)
123 -- and from a posible --configure-option=link:lib1,lib2,lib3
124 -- by default the desired libs are gsl lapack.
125
126 let pref = if null (words (base ++ " " ++ auxpref)) then "gsl lapack" else auxpref
127 fullOpts = map ((pref++" ")++) opts
128
129 -- create the build directory (used for tmp files) if necessary
130 createDirectoryIfMissing True $ buildDir bInfo
131
132 r <- try bInfo buildInfo base fwks fullOpts
133
134 case r of
135 Nothing -> do
136 putStrLn " FAIL"
137 g <- checkCommand $ gsl bInfo buildInfo
138 if g
139 then putStrLn " *** Sorry, I can't link LAPACK."
140 else putStrLn " *** Sorry, I can't link GSL."
141 putStrLn " *** Please make sure that the appropriate -dev packages are installed."
142 putStrLn " *** You can also specify the required libraries using"
143 putStrLn " *** cabal install hmatrix --configure-option=link:lib1,lib2,lib3,etc."
144 return (Just emptyBuildInfo { buildable = False }, [])
145 Just ops -> do
146 putStrLn $ " OK " ++ ops
147 g1 <- checkCommand $ gsl112 bInfo buildInfo
148 let op1 = if g1 then "" else "-DGSL110"
149 g2 <- checkCommand $ gslodeiv2 bInfo buildInfo
150 let op2 = if g2 then "" else "-DGSLODE1"
151 opts = filter (not.null) [op1,op2]
152 let hbi = emptyBuildInfo { extraLibs = words ops, ccOptions = opts }
153 return (Just hbi, [])
154
diff --git a/packages/hmatrix/Setup.lhs b/packages/hmatrix/Setup.lhs
index e3f9847..4b19c19 100644
--- a/packages/hmatrix/Setup.lhs
+++ b/packages/hmatrix/Setup.lhs
@@ -1,18 +1,5 @@
1#! /usr/bin/env runhaskell 1#! /usr/bin/env runhaskell
2 2
3> import Distribution.Simple 3> import Distribution.Simple
4> import Distribution.Simple.Setup 4> main = defaultMain
5> import Distribution.PackageDescription
6> import Distribution.Simple.LocalBuildInfo
7
8> import System.Process(system)
9> import Config(config)
10
11> main = defaultMainWithHooks simpleUserHooks { confHook = c }
12
13> c x y = do
14> binfo <- confHook simpleUserHooks x y
15> pbi <- config binfo
16> let pkg_descr = localPkgDescr binfo
17> return $ binfo { localPkgDescr = updatePackageDescription pbi pkg_descr }
18 5
diff --git a/packages/hmatrix/hmatrix.cabal b/packages/hmatrix/hmatrix.cabal
index 73edac4..369c412 100644
--- a/packages/hmatrix/hmatrix.cabal
+++ b/packages/hmatrix/hmatrix.cabal
@@ -102,9 +102,6 @@ library
102 Numeric.GSL.Internal, 102 Numeric.GSL.Internal,
103 Numeric.GSL.Vector, 103 Numeric.GSL.Vector,
104 Numeric.IO, 104 Numeric.IO,
105 Numeric.Chain,
106 Numeric.Vector,
107 Numeric.Matrix,
108 Numeric.LinearAlgebra.Util.Convolution 105 Numeric.LinearAlgebra.Util.Convolution
109 106
110 107
diff --git a/packages/hmatrix/src/Numeric/Container.hs b/packages/hmatrix/src/Numeric/Container.hs
index 645a83f..e7f23d4 100644
--- a/packages/hmatrix/src/Numeric/Container.hs
+++ b/packages/hmatrix/src/Numeric/Container.hs
@@ -66,11 +66,11 @@ module Numeric.Container (
66 66
67import Data.Packed hiding (stepD, stepF, condD, condF, conjugateC, conjugateQ) 67import Data.Packed hiding (stepD, stepF, condD, condF, conjugateC, conjugateQ)
68import Data.Packed.Numeric 68import Data.Packed.Numeric
69import Numeric.Chain
70import Numeric.IO 69import Numeric.IO
71import Data.Complex 70import Data.Complex
72import Numeric.LinearAlgebra.Algorithms(Field,linearSolveSVD) 71import Numeric.LinearAlgebra.Algorithms(Field,linearSolveSVD)
73import Numeric.Random 72import Numeric.Random
73import Data.Monoid(Monoid(mconcat))
74 74
75------------------------------------------------------------------ 75------------------------------------------------------------------
76 76
@@ -268,4 +268,8 @@ infixl 7 ◇
268dot :: (Container Vector t, Product t) => Vector t -> Vector t -> t 268dot :: (Container Vector t, Product t) => Vector t -> Vector t -> t
269dot u v = udot (conj u) v 269dot u v = udot (conj u) v
270 270
271--------------------------------------------------------------------------------
272
273optimiseMult :: Monoid (Matrix t) => [Matrix t] -> Matrix t
274optimiseMult = mconcat
271 275