diff options
Diffstat (limited to 'packages')
16 files changed, 69 insertions, 114 deletions
diff --git a/packages/base/hmatrix-base.cabal b/packages/base/hmatrix-base.cabal index b884518..91dc0db 100644 --- a/packages/base/hmatrix-base.cabal +++ b/packages/base/hmatrix-base.cabal | |||
@@ -1,5 +1,5 @@ | |||
1 | Name: hmatrix-base | 1 | Name: hmatrix |
2 | Version: 0.16.0.0 | 2 | Version: 0.16.0.2 |
3 | License: BSD3 | 3 | License: BSD3 |
4 | License-file: LICENSE | 4 | License-file: LICENSE |
5 | Author: Alberto Ruiz | 5 | Author: Alberto Ruiz |
@@ -38,10 +38,10 @@ library | |||
38 | 38 | ||
39 | Numeric.LinearAlgebra.LAPACK | 39 | Numeric.LinearAlgebra.LAPACK |
40 | Numeric.LinearAlgebra.Algorithms | 40 | Numeric.LinearAlgebra.Algorithms |
41 | Data.Packed.Numeric | 41 | Numeric.Container |
42 | Numeric.LinearAlgebra.Util | 42 | Numeric.LinearAlgebra.Util |
43 | 43 | ||
44 | Numeric.LinearAlgebra.Base | 44 | Numeric.LinearAlgebra |
45 | Numeric.LinearAlgebra.Devel | 45 | Numeric.LinearAlgebra.Devel |
46 | Numeric.LinearAlgebra.Data | 46 | Numeric.LinearAlgebra.Data |
47 | 47 | ||
diff --git a/packages/base/src/Data/Packed/Numeric.hs b/packages/base/src/Numeric/Container.hs index d130ecd..c715dac 100644 --- a/packages/base/src/Data/Packed/Numeric.hs +++ b/packages/base/src/Numeric/Container.hs | |||
@@ -7,7 +7,7 @@ | |||
7 | 7 | ||
8 | ----------------------------------------------------------------------------- | 8 | ----------------------------------------------------------------------------- |
9 | -- | | 9 | -- | |
10 | -- Module : Data.Packed.Numeric | 10 | -- Module : Numeric.Container |
11 | -- Copyright : (c) Alberto Ruiz 2010-14 | 11 | -- Copyright : (c) Alberto Ruiz 2010-14 |
12 | -- License : BSD3 | 12 | -- License : BSD3 |
13 | -- Maintainer : Alberto Ruiz | 13 | -- Maintainer : Alberto Ruiz |
@@ -24,7 +24,7 @@ | |||
24 | ----------------------------------------------------------------------------- | 24 | ----------------------------------------------------------------------------- |
25 | {-# OPTIONS_HADDOCK hide #-} | 25 | {-# OPTIONS_HADDOCK hide #-} |
26 | 26 | ||
27 | module Data.Packed.Numeric ( | 27 | module Numeric.Container ( |
28 | -- * Basic functions | 28 | -- * Basic functions |
29 | module Data.Packed, | 29 | module Data.Packed, |
30 | konst, build, | 30 | konst, build, |
diff --git a/packages/base/src/Numeric/LinearAlgebra/Base.hs b/packages/base/src/Numeric/LinearAlgebra.hs index 8d44d26..96bf29f 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Base.hs +++ b/packages/base/src/Numeric/LinearAlgebra.hs | |||
@@ -8,7 +8,7 @@ Stability : provisional | |||
8 | 8 | ||
9 | -} | 9 | -} |
10 | ----------------------------------------------------------------------------- | 10 | ----------------------------------------------------------------------------- |
11 | module Numeric.LinearAlgebra.Base ( | 11 | module Numeric.LinearAlgebra ( |
12 | 12 | ||
13 | -- * Basic types and data processing | 13 | -- * Basic types and data processing |
14 | module Numeric.LinearAlgebra.Data, | 14 | module Numeric.LinearAlgebra.Data, |
@@ -132,7 +132,7 @@ import Numeric.LinearAlgebra.Data | |||
132 | 132 | ||
133 | import Numeric.Matrix() | 133 | import Numeric.Matrix() |
134 | import Numeric.Vector() | 134 | import Numeric.Vector() |
135 | import Data.Packed.Numeric | 135 | import Numeric.Container |
136 | import Numeric.LinearAlgebra.Algorithms | 136 | import Numeric.LinearAlgebra.Algorithms |
137 | import Numeric.LinearAlgebra.Util | 137 | import Numeric.LinearAlgebra.Util |
138 | import Numeric.LinearAlgebra.Random | 138 | import Numeric.LinearAlgebra.Random |
diff --git a/packages/base/src/Numeric/LinearAlgebra/Data.hs b/packages/base/src/Numeric/LinearAlgebra/Data.hs index 45fc00c..7e8af03 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Data.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Data.hs | |||
@@ -62,7 +62,7 @@ module Numeric.LinearAlgebra.Data( | |||
62 | 62 | ||
63 | import Data.Packed.Vector | 63 | import Data.Packed.Vector |
64 | import Data.Packed.Matrix | 64 | import Data.Packed.Matrix |
65 | import Data.Packed.Numeric | 65 | import Numeric.Container |
66 | import Numeric.LinearAlgebra.Util | 66 | import Numeric.LinearAlgebra.Util |
67 | import Data.Complex | 67 | import Data.Complex |
68 | 68 | ||
diff --git a/packages/base/src/Numeric/LinearAlgebra/Devel.hs b/packages/base/src/Numeric/LinearAlgebra/Devel.hs index b5ef60d..c41db2d 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Devel.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Devel.hs | |||
@@ -60,7 +60,7 @@ module Numeric.LinearAlgebra.Devel( | |||
60 | import Data.Packed.Foreign | 60 | import Data.Packed.Foreign |
61 | import Data.Packed.Development | 61 | import Data.Packed.Development |
62 | import Data.Packed.ST | 62 | import Data.Packed.ST |
63 | import Data.Packed.Numeric(Container,Contraction,LSDiv,Product, | 63 | import Numeric.Container(Container,Contraction,LSDiv,Product, |
64 | Complexable(),RealElement(), | 64 | Complexable(),RealElement(), |
65 | RealOf, ComplexOf, SingleOf, DoubleOf, IndexOf) | 65 | RealOf, ComplexOf, SingleOf, DoubleOf, IndexOf) |
66 | import Data.Packed | 66 | import Data.Packed |
diff --git a/packages/base/src/Numeric/LinearAlgebra/Random.hs b/packages/base/src/Numeric/LinearAlgebra/Random.hs index b36c7a3..7afd658 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Random.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Random.hs | |||
@@ -20,7 +20,7 @@ module Numeric.LinearAlgebra.Random ( | |||
20 | ) where | 20 | ) where |
21 | 21 | ||
22 | import Numeric.Vectorized | 22 | import Numeric.Vectorized |
23 | import Data.Packed.Numeric | 23 | import Numeric.Container |
24 | import Numeric.LinearAlgebra.Algorithms | 24 | import Numeric.LinearAlgebra.Algorithms |
25 | import System.Random(randomIO) | 25 | import System.Random(randomIO) |
26 | 26 | ||
diff --git a/packages/base/src/Numeric/LinearAlgebra/Util.hs b/packages/base/src/Numeric/LinearAlgebra/Util.hs index 440f6d1..2f91e18 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Util.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Util.hs | |||
@@ -48,7 +48,7 @@ module Numeric.LinearAlgebra.Util( | |||
48 | vtrans | 48 | vtrans |
49 | ) where | 49 | ) where |
50 | 50 | ||
51 | import Data.Packed.Numeric | 51 | import Numeric.Container |
52 | import Numeric.LinearAlgebra.Algorithms hiding (i) | 52 | import Numeric.LinearAlgebra.Algorithms hiding (i) |
53 | import Numeric.Matrix() | 53 | import Numeric.Matrix() |
54 | import Numeric.Vector() | 54 | import Numeric.Vector() |
diff --git a/packages/base/src/Numeric/LinearAlgebra/Util/Convolution.hs b/packages/base/src/Numeric/LinearAlgebra/Util/Convolution.hs index 1d4e089..e4cba8f 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Util/Convolution.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Util/Convolution.hs | |||
@@ -16,7 +16,7 @@ module Numeric.LinearAlgebra.Util.Convolution( | |||
16 | corr2, conv2, separable | 16 | corr2, conv2, separable |
17 | ) where | 17 | ) where |
18 | 18 | ||
19 | import Data.Packed.Numeric | 19 | import Numeric.Container |
20 | 20 | ||
21 | 21 | ||
22 | vectSS :: Element t => Int -> Vector t -> Matrix t | 22 | vectSS :: Element t => Int -> Vector t -> Matrix t |
diff --git a/packages/hmatrix/hmatrix.cabal b/packages/hmatrix/hmatrix.cabal index a61c64f..83a2188 100644 --- a/packages/hmatrix/hmatrix.cabal +++ b/packages/hmatrix/hmatrix.cabal | |||
@@ -1,5 +1,5 @@ | |||
1 | Name: hmatrix | 1 | Name: hmatrix-gsl |
2 | Version: 0.16.0.1 | 2 | Version: 0.16.0.0 |
3 | License: GPL | 3 | License: GPL |
4 | License-file: LICENSE | 4 | License-file: LICENSE |
5 | Author: Alberto Ruiz | 5 | Author: Alberto Ruiz |
@@ -73,7 +73,7 @@ flag debugnan | |||
73 | 73 | ||
74 | library | 74 | library |
75 | 75 | ||
76 | Build-Depends: base, hmatrix-base, array, vector, | 76 | Build-Depends: base, hmatrix, array, vector, |
77 | process, random | 77 | process, random |
78 | 78 | ||
79 | 79 | ||
@@ -90,13 +90,12 @@ library | |||
90 | Numeric.GSL.Fitting, | 90 | Numeric.GSL.Fitting, |
91 | Numeric.GSL.ODE, | 91 | Numeric.GSL.ODE, |
92 | Numeric.GSL, | 92 | Numeric.GSL, |
93 | Numeric.LinearAlgebra, | 93 | Numeric.GSL.LinearAlgebra, |
94 | Numeric.Container, | ||
95 | Graphics.Plot | 94 | Graphics.Plot |
96 | other-modules: Numeric.GSL.Internal, | 95 | other-modules: Numeric.GSL.Internal, |
97 | Numeric.GSL.LinearAlgebra, | 96 | Numeric.GSL.Vector, |
98 | Numeric.LinearAlgebra.IO, | 97 | Numeric.GSL.IO, |
99 | Numeric.LinearAlgebra.Random | 98 | Numeric.GSL.Random |
100 | 99 | ||
101 | 100 | ||
102 | C-sources: src/Numeric/GSL/gsl-aux.c | 101 | C-sources: src/Numeric/GSL/gsl-aux.c |
diff --git a/packages/hmatrix/src/Numeric/Container.hs b/packages/hmatrix/src/Numeric/Container.hs deleted file mode 100644 index 2b61d90..0000000 --- a/packages/hmatrix/src/Numeric/Container.hs +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | ----------------------------------------------------------------------------- | ||
2 | {- | | ||
3 | Module : Numeric.Container | ||
4 | Copyright : (c) Alberto Ruiz 2006-14 | ||
5 | License : GPL | ||
6 | Maintainer : Alberto Ruiz | ||
7 | Stability : provisional | ||
8 | |||
9 | -} | ||
10 | ----------------------------------------------------------------------------- | ||
11 | |||
12 | module Numeric.Container ( | ||
13 | module Data.Packed.Numeric, | ||
14 | module Numeric.LinearAlgebra.IO, | ||
15 | module Numeric.LinearAlgebra.Random, | ||
16 | meanCov | ||
17 | ) where | ||
18 | |||
19 | import Data.Packed.Numeric hiding (saveMatrix, loadMatrix) | ||
20 | import Numeric.LinearAlgebra.IO | ||
21 | import Numeric.LinearAlgebra.Random hiding (Seed) | ||
22 | import Numeric.LinearAlgebra.Util(meanCov) | ||
23 | |||
diff --git a/packages/hmatrix/src/Numeric/GSL/Fitting.hs b/packages/hmatrix/src/Numeric/GSL/Fitting.hs index 0a92373..93fb281 100644 --- a/packages/hmatrix/src/Numeric/GSL/Fitting.hs +++ b/packages/hmatrix/src/Numeric/GSL/Fitting.hs | |||
@@ -116,7 +116,7 @@ err (model,deriv) dat vsol = zip sol errs where | |||
116 | dof = length dat - (rows cov) | 116 | dof = length dat - (rows cov) |
117 | chi = norm2 (fromList $ cost (resMs model) dat sol) | 117 | chi = norm2 (fromList $ cost (resMs model) dat sol) |
118 | js = fromLists $ jacobian (resDs deriv) dat sol | 118 | js = fromLists $ jacobian (resDs deriv) dat sol |
119 | cov = inv $ trans js <> js | 119 | cov = inv $ trans js <.> js |
120 | errs = toList $ scalar c * sqrt (takeDiag cov) | 120 | errs = toList $ scalar c * sqrt (takeDiag cov) |
121 | 121 | ||
122 | 122 | ||
diff --git a/packages/hmatrix/src/Numeric/LinearAlgebra/IO.hs b/packages/hmatrix/src/Numeric/GSL/IO.hs index d2278ee..0d6031a 100644 --- a/packages/hmatrix/src/Numeric/LinearAlgebra/IO.hs +++ b/packages/hmatrix/src/Numeric/GSL/IO.hs | |||
@@ -1,6 +1,6 @@ | |||
1 | ----------------------------------------------------------------------------- | 1 | ----------------------------------------------------------------------------- |
2 | -- | | 2 | -- | |
3 | -- Module : Numeric.LinearAlgebra.IO | 3 | -- Module : Numeric.GSL.IO |
4 | -- Copyright : (c) Alberto Ruiz 2007-14 | 4 | -- Copyright : (c) Alberto Ruiz 2007-14 |
5 | -- License : GPL | 5 | -- License : GPL |
6 | -- Maintainer : Alberto Ruiz | 6 | -- Maintainer : Alberto Ruiz |
@@ -8,14 +8,14 @@ | |||
8 | -- | 8 | -- |
9 | ----------------------------------------------------------------------------- | 9 | ----------------------------------------------------------------------------- |
10 | 10 | ||
11 | module Numeric.LinearAlgebra.IO ( | 11 | module Numeric.GSL.IO ( |
12 | saveMatrix, | 12 | saveMatrix, |
13 | fwriteVector, freadVector, fprintfVector, fscanfVector, | 13 | fwriteVector, freadVector, fprintfVector, fscanfVector, |
14 | fileDimensions, loadMatrix, fromFile | 14 | fileDimensions, loadMatrix, fromFile |
15 | ) where | 15 | ) where |
16 | 16 | ||
17 | import Data.Packed | 17 | import Data.Packed |
18 | import Numeric.GSL.LinearAlgebra | 18 | import Numeric.GSL.Vector |
19 | import System.Process(readProcess) | 19 | import System.Process(readProcess) |
20 | 20 | ||
21 | 21 | ||
diff --git a/packages/hmatrix/src/Numeric/GSL/LinearAlgebra.hs b/packages/hmatrix/src/Numeric/GSL/LinearAlgebra.hs index 8bd0cc2..17e2258 100644 --- a/packages/hmatrix/src/Numeric/GSL/LinearAlgebra.hs +++ b/packages/hmatrix/src/Numeric/GSL/LinearAlgebra.hs | |||
@@ -9,13 +9,13 @@ | |||
9 | ----------------------------------------------------------------------------- | 9 | ----------------------------------------------------------------------------- |
10 | 10 | ||
11 | module Numeric.GSL.LinearAlgebra ( | 11 | module Numeric.GSL.LinearAlgebra ( |
12 | randomVector, | 12 | RandDist(..), randomVector, |
13 | saveMatrix, | 13 | saveMatrix, |
14 | fwriteVector, freadVector, fprintfVector, fscanfVector | 14 | fwriteVector, freadVector, fprintfVector, fscanfVector, |
15 | fileDimensions, loadMatrix, fromFile | ||
15 | ) where | 16 | ) where |
16 | 17 | ||
17 | import Data.Packed | 18 | import Data.Packed |
18 | import Numeric.LinearAlgebra.Base(RandDist(..)) | ||
19 | import Numeric.GSL.Internal hiding (TV,TM,TCV,TCM) | 19 | import Numeric.GSL.Internal hiding (TV,TM,TCV,TCM) |
20 | 20 | ||
21 | import Foreign.Marshal.Alloc(free) | 21 | import Foreign.Marshal.Alloc(free) |
@@ -23,11 +23,16 @@ import Foreign.Ptr(Ptr) | |||
23 | import Foreign.C.Types | 23 | import Foreign.C.Types |
24 | import Foreign.C.String(newCString) | 24 | import Foreign.C.String(newCString) |
25 | import System.IO.Unsafe(unsafePerformIO) | 25 | import System.IO.Unsafe(unsafePerformIO) |
26 | import System.Process(readProcess) | ||
26 | 27 | ||
27 | fromei x = fromIntegral (fromEnum x) :: CInt | 28 | fromei x = fromIntegral (fromEnum x) :: CInt |
28 | 29 | ||
29 | ----------------------------------------------------------------------- | 30 | ----------------------------------------------------------------------- |
30 | 31 | ||
32 | data RandDist = Uniform -- ^ uniform distribution in [0,1) | ||
33 | | Gaussian -- ^ normal distribution with mean zero and standard deviation one | ||
34 | deriving Enum | ||
35 | |||
31 | -- | Obtains a vector of pseudorandom elements from the the mt19937 generator in GSL, with a given seed. Use randomIO to get a random seed. | 36 | -- | Obtains a vector of pseudorandom elements from the the mt19937 generator in GSL, with a given seed. Use randomIO to get a random seed. |
32 | randomVector :: Int -- ^ seed | 37 | randomVector :: Int -- ^ seed |
33 | -> RandDist -- ^ distribution | 38 | -> RandDist -- ^ distribution |
@@ -35,10 +40,10 @@ randomVector :: Int -- ^ seed | |||
35 | -> Vector Double | 40 | -> Vector Double |
36 | randomVector seed dist n = unsafePerformIO $ do | 41 | randomVector seed dist n = unsafePerformIO $ do |
37 | r <- createVector n | 42 | r <- createVector n |
38 | app1 (c_random_vector_GSL (fi seed) ((fi.fromEnum) dist)) vec r "randomVectorGSL" | 43 | app1 (c_random_vector (fi seed) ((fi.fromEnum) dist)) vec r "randomVector" |
39 | return r | 44 | return r |
40 | 45 | ||
41 | foreign import ccall unsafe "random_vector_GSL" c_random_vector_GSL :: CInt -> CInt -> TV | 46 | foreign import ccall unsafe "random_vector" c_random_vector :: CInt -> CInt -> TV |
42 | 47 | ||
43 | -------------------------------------------------------------------------------- | 48 | -------------------------------------------------------------------------------- |
44 | 49 | ||
@@ -105,3 +110,26 @@ type PD = Ptr Double -- | |||
105 | type TV = CInt -> PD -> IO CInt -- | 110 | type TV = CInt -> PD -> IO CInt -- |
106 | type TM = CInt -> CInt -> PD -> IO CInt -- | 111 | type TM = CInt -> CInt -> PD -> IO CInt -- |
107 | 112 | ||
113 | -------------------------------------------------------------------------------- | ||
114 | |||
115 | {- | obtains the number of rows and columns in an ASCII data file | ||
116 | (provisionally using unix's wc). | ||
117 | -} | ||
118 | fileDimensions :: FilePath -> IO (Int,Int) | ||
119 | fileDimensions fname = do | ||
120 | wcres <- readProcess "wc" ["-w",fname] "" | ||
121 | contents <- readFile fname | ||
122 | let tot = read . head . words $ wcres | ||
123 | c = length . head . dropWhile null . map words . lines $ contents | ||
124 | if tot > 0 | ||
125 | then return (tot `div` c, c) | ||
126 | else return (0,0) | ||
127 | |||
128 | -- | Loads a matrix from an ASCII file formatted as a 2D table. | ||
129 | loadMatrix :: FilePath -> IO (Matrix Double) | ||
130 | loadMatrix file = fromFile file =<< fileDimensions file | ||
131 | |||
132 | -- | Loads a matrix from an ASCII file (the number of rows and columns must be known in advance). | ||
133 | fromFile :: FilePath -> (Int,Int) -> IO (Matrix Double) | ||
134 | fromFile filename (r,c) = reshape c `fmap` fscanfVector filename (r*c) | ||
135 | |||
diff --git a/packages/hmatrix/src/Numeric/LinearAlgebra/Random.hs b/packages/hmatrix/src/Numeric/GSL/Random.hs index fa125a0..2872b17 100644 --- a/packages/hmatrix/src/Numeric/LinearAlgebra/Random.hs +++ b/packages/hmatrix/src/Numeric/GSL/Random.hs | |||
@@ -1,6 +1,6 @@ | |||
1 | ----------------------------------------------------------------------------- | 1 | ----------------------------------------------------------------------------- |
2 | -- | | 2 | -- | |
3 | -- Module : Numeric.LinearAlgebra.Random | 3 | -- Module : Numeric.GSL.Random |
4 | -- Copyright : (c) Alberto Ruiz 2009-14 | 4 | -- Copyright : (c) Alberto Ruiz 2009-14 |
5 | -- License : GPL | 5 | -- License : GPL |
6 | -- | 6 | -- |
@@ -11,7 +11,7 @@ | |||
11 | -- | 11 | -- |
12 | ----------------------------------------------------------------------------- | 12 | ----------------------------------------------------------------------------- |
13 | 13 | ||
14 | module Numeric.LinearAlgebra.Random ( | 14 | module Numeric.GSL.Random ( |
15 | Seed, | 15 | Seed, |
16 | RandDist(..), | 16 | RandDist(..), |
17 | randomVector, | 17 | randomVector, |
@@ -20,9 +20,9 @@ module Numeric.LinearAlgebra.Random ( | |||
20 | rand, randn | 20 | rand, randn |
21 | ) where | 21 | ) where |
22 | 22 | ||
23 | import Numeric.GSL.LinearAlgebra | 23 | import Numeric.GSL.Vector |
24 | import Data.Packed.Numeric | 24 | import Numeric.Container |
25 | import Numeric.LinearAlgebra.Base(Seed,RandDist(..),cholSH) | 25 | import Numeric.LinearAlgebra(Seed,RandDist(..),cholSH) |
26 | import System.Random(randomIO) | 26 | import System.Random(randomIO) |
27 | 27 | ||
28 | 28 | ||
diff --git a/packages/hmatrix/src/Numeric/LinearAlgebra/GSL.hs b/packages/hmatrix/src/Numeric/GSL/Vector.hs index 1fde621..af79f32 100644 --- a/packages/hmatrix/src/Numeric/LinearAlgebra/GSL.hs +++ b/packages/hmatrix/src/Numeric/GSL/Vector.hs | |||
@@ -1,6 +1,6 @@ | |||
1 | ----------------------------------------------------------------------------- | 1 | ----------------------------------------------------------------------------- |
2 | -- | | 2 | -- | |
3 | -- Module : Numeric.LinearAlgebra.GSL | 3 | -- Module : Numeric.GSL.Vector |
4 | -- Copyright : (c) Alberto Ruiz 2007-14 | 4 | -- Copyright : (c) Alberto Ruiz 2007-14 |
5 | -- License : GPL | 5 | -- License : GPL |
6 | -- Maintainer : Alberto Ruiz | 6 | -- Maintainer : Alberto Ruiz |
@@ -8,32 +8,26 @@ | |||
8 | -- | 8 | -- |
9 | ----------------------------------------------------------------------------- | 9 | ----------------------------------------------------------------------------- |
10 | 10 | ||
11 | module Numeric.LinearAlgebra.GSL ( | 11 | module Numeric.GSL.Vector ( |
12 | RandDist(..), randomVector, | 12 | randomVector, |
13 | saveMatrix, | 13 | saveMatrix, |
14 | fwriteVector, freadVector, fprintfVector, fscanfVector, | 14 | fwriteVector, freadVector, fprintfVector, fscanfVector |
15 | fileDimensions, loadMatrix, fromFile | ||
16 | ) where | 15 | ) where |
17 | 16 | ||
18 | import Data.Packed | 17 | import Data.Packed |
18 | import Numeric.LinearAlgebra(RandDist(..)) | ||
19 | import Numeric.GSL.Internal hiding (TV,TM,TCV,TCM) | 19 | import Numeric.GSL.Internal hiding (TV,TM,TCV,TCM) |
20 | 20 | ||
21 | import Data.Complex | ||
22 | import Foreign.Marshal.Alloc(free) | 21 | import Foreign.Marshal.Alloc(free) |
23 | import Foreign.Ptr(Ptr) | 22 | import Foreign.Ptr(Ptr) |
24 | import Foreign.C.Types | 23 | import Foreign.C.Types |
25 | import Foreign.C.String(newCString) | 24 | import Foreign.C.String(newCString) |
26 | import System.IO.Unsafe(unsafePerformIO) | 25 | import System.IO.Unsafe(unsafePerformIO) |
27 | import System.Process(readProcess) | ||
28 | 26 | ||
29 | fromei x = fromIntegral (fromEnum x) :: CInt | 27 | fromei x = fromIntegral (fromEnum x) :: CInt |
30 | 28 | ||
31 | ----------------------------------------------------------------------- | 29 | ----------------------------------------------------------------------- |
32 | 30 | ||
33 | data RandDist = Uniform -- ^ uniform distribution in [0,1) | ||
34 | | Gaussian -- ^ normal distribution with mean zero and standard deviation one | ||
35 | deriving Enum | ||
36 | |||
37 | -- | Obtains a vector of pseudorandom elements from the the mt19937 generator in GSL, with a given seed. Use randomIO to get a random seed. | 31 | -- | Obtains a vector of pseudorandom elements from the the mt19937 generator in GSL, with a given seed. Use randomIO to get a random seed. |
38 | randomVector :: Int -- ^ seed | 32 | randomVector :: Int -- ^ seed |
39 | -> RandDist -- ^ distribution | 33 | -> RandDist -- ^ distribution |
@@ -41,10 +35,10 @@ randomVector :: Int -- ^ seed | |||
41 | -> Vector Double | 35 | -> Vector Double |
42 | randomVector seed dist n = unsafePerformIO $ do | 36 | randomVector seed dist n = unsafePerformIO $ do |
43 | r <- createVector n | 37 | r <- createVector n |
44 | app1 (c_random_vector (fi seed) ((fi.fromEnum) dist)) vec r "randomVector" | 38 | app1 (c_random_vector_GSL (fi seed) ((fi.fromEnum) dist)) vec r "randomVectorGSL" |
45 | return r | 39 | return r |
46 | 40 | ||
47 | foreign import ccall unsafe "random_vector" c_random_vector :: CInt -> CInt -> TV | 41 | foreign import ccall unsafe "random_vector_GSL" c_random_vector_GSL :: CInt -> CInt -> TV |
48 | 42 | ||
49 | -------------------------------------------------------------------------------- | 43 | -------------------------------------------------------------------------------- |
50 | 44 | ||
@@ -111,26 +105,3 @@ type PD = Ptr Double -- | |||
111 | type TV = CInt -> PD -> IO CInt -- | 105 | type TV = CInt -> PD -> IO CInt -- |
112 | type TM = CInt -> CInt -> PD -> IO CInt -- | 106 | type TM = CInt -> CInt -> PD -> IO CInt -- |
113 | 107 | ||
114 | -------------------------------------------------------------------------------- | ||
115 | |||
116 | {- | obtains the number of rows and columns in an ASCII data file | ||
117 | (provisionally using unix's wc). | ||
118 | -} | ||
119 | fileDimensions :: FilePath -> IO (Int,Int) | ||
120 | fileDimensions fname = do | ||
121 | wcres <- readProcess "wc" ["-w",fname] "" | ||
122 | contents <- readFile fname | ||
123 | let tot = read . head . words $ wcres | ||
124 | c = length . head . dropWhile null . map words . lines $ contents | ||
125 | if tot > 0 | ||
126 | then return (tot `div` c, c) | ||
127 | else return (0,0) | ||
128 | |||
129 | -- | Loads a matrix from an ASCII file formatted as a 2D table. | ||
130 | loadMatrix :: FilePath -> IO (Matrix Double) | ||
131 | loadMatrix file = fromFile file =<< fileDimensions file | ||
132 | |||
133 | -- | Loads a matrix from an ASCII file (the number of rows and columns must be known in advance). | ||
134 | fromFile :: FilePath -> (Int,Int) -> IO (Matrix Double) | ||
135 | fromFile filename (r,c) = reshape c `fmap` fscanfVector filename (r*c) | ||
136 | |||
diff --git a/packages/hmatrix/src/Numeric/LinearAlgebra.hs b/packages/hmatrix/src/Numeric/LinearAlgebra.hs deleted file mode 100644 index 71ed808..0000000 --- a/packages/hmatrix/src/Numeric/LinearAlgebra.hs +++ /dev/null | |||
@@ -1,20 +0,0 @@ | |||
1 | ----------------------------------------------------------------------------- | ||
2 | {- | | ||
3 | Module : Numeric.LinearAlgebra | ||
4 | Copyright : (c) Alberto Ruiz 2006-14 | ||
5 | License : GPL | ||
6 | Maintainer : Alberto Ruiz | ||
7 | Stability : provisional | ||
8 | |||
9 | -} | ||
10 | ----------------------------------------------------------------------------- | ||
11 | |||
12 | module Numeric.LinearAlgebra ( | ||
13 | module Numeric.Container, | ||
14 | module Numeric.LinearAlgebra.Algorithms, | ||
15 | ) where | ||
16 | |||
17 | import Numeric.Container | ||
18 | import Numeric.LinearAlgebra.Algorithms | ||
19 | import Numeric.LinearAlgebra.Util() | ||
20 | |||