diff options
Diffstat (limited to 'lib/Numeric/LinearAlgebra')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Instances.hs | 23 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/Interface.hs | 4 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/Linear.hs | 2 |
3 files changed, 25 insertions, 4 deletions
diff --git a/lib/Numeric/LinearAlgebra/Instances.hs b/lib/Numeric/LinearAlgebra/Instances.hs index 388f3da..4ee576f 100644 --- a/lib/Numeric/LinearAlgebra/Instances.hs +++ b/lib/Numeric/LinearAlgebra/Instances.hs | |||
@@ -9,7 +9,7 @@ Maintainer : Alberto Ruiz (aruiz at um dot es) | |||
9 | Stability : provisional | 9 | Stability : provisional |
10 | Portability : portable | 10 | Portability : portable |
11 | 11 | ||
12 | Numeric instances for Vector and Matrix. | 12 | This module exports Show, Eq, Num, Fractional, and Floating instances for Vector and Matrix. |
13 | 13 | ||
14 | In the context of the standard numeric operators, one-component vectors and matrices automatically expand to match the dimensions of the other operand. | 14 | In the context of the standard numeric operators, one-component vectors and matrices automatically expand to match the dimensions of the other operand. |
15 | 15 | ||
@@ -24,6 +24,27 @@ import Numeric.GSL.Vector | |||
24 | import Data.Packed.Matrix | 24 | import Data.Packed.Matrix |
25 | import Data.Packed.Vector | 25 | import Data.Packed.Vector |
26 | import Complex | 26 | import Complex |
27 | import Data.List(transpose,intersperse) | ||
28 | import Foreign(Storable) | ||
29 | |||
30 | ------------------------------------------------------------------ | ||
31 | |||
32 | instance (Show a, Field a) => (Show (Matrix a)) where | ||
33 | show m = (sizes++) . dsp . map (map show) . toLists $ m | ||
34 | where sizes = "("++show (rows m)++"><"++show (cols m)++")\n" | ||
35 | |||
36 | dsp as = (++" ]") . (" ["++) . init . drop 2 . unlines . map (" , "++) . map unwords' $ transpose mtp | ||
37 | where | ||
38 | mt = transpose as | ||
39 | longs = map (maximum . map length) mt | ||
40 | mtp = zipWith (\a b -> map (pad a) b) longs mt | ||
41 | pad n str = replicate (n - length str) ' ' ++ str | ||
42 | unwords' = concat . intersperse ", " | ||
43 | |||
44 | instance (Show a, Storable a) => (Show (Vector a)) where | ||
45 | show v = (show (dim v))++" |> " ++ show (toList v) | ||
46 | |||
47 | ------------------------------------------------------------------ | ||
27 | 48 | ||
28 | adaptScalar f1 f2 f3 x y | 49 | adaptScalar f1 f2 f3 x y |
29 | | dim x == 1 = f1 (x@>0) y | 50 | | dim x == 1 = f1 (x@>0) y |
diff --git a/lib/Numeric/LinearAlgebra/Interface.hs b/lib/Numeric/LinearAlgebra/Interface.hs index 5bd207a..fd076ec 100644 --- a/lib/Numeric/LinearAlgebra/Interface.hs +++ b/lib/Numeric/LinearAlgebra/Interface.hs | |||
@@ -2,14 +2,14 @@ | |||
2 | ----------------------------------------------------------------------------- | 2 | ----------------------------------------------------------------------------- |
3 | {- | | 3 | {- | |
4 | Module : Numeric.LinearAlgebra.Interface | 4 | Module : Numeric.LinearAlgebra.Interface |
5 | Copyright : (c) Alberto Ruiz 2006 | 5 | Copyright : (c) Alberto Ruiz 2007 |
6 | License : GPL-style | 6 | License : GPL-style |
7 | 7 | ||
8 | Maintainer : Alberto Ruiz (aruiz at um dot es) | 8 | Maintainer : Alberto Ruiz (aruiz at um dot es) |
9 | Stability : provisional | 9 | Stability : provisional |
10 | Portability : portable | 10 | Portability : portable |
11 | 11 | ||
12 | Operators for frequent operations. | 12 | (Very provisional) operators for frequent operations. |
13 | 13 | ||
14 | -} | 14 | -} |
15 | ----------------------------------------------------------------------------- | 15 | ----------------------------------------------------------------------------- |
diff --git a/lib/Numeric/LinearAlgebra/Linear.hs b/lib/Numeric/LinearAlgebra/Linear.hs index a3a0183..3017936 100644 --- a/lib/Numeric/LinearAlgebra/Linear.hs +++ b/lib/Numeric/LinearAlgebra/Linear.hs | |||
@@ -25,7 +25,7 @@ import Data.Packed | |||
25 | import Numeric.GSL.Vector | 25 | import Numeric.GSL.Vector |
26 | import Complex | 26 | import Complex |
27 | 27 | ||
28 | -- | basic optimized operations | 28 | -- | A generic interface for vectors and matrices to a few element-by-element functions in Numeric.GSL.Vector. |
29 | class (Container c e) => Linear c e where | 29 | class (Container c e) => Linear c e where |
30 | scale :: e -> c e -> c e | 30 | scale :: e -> c e -> c e |
31 | addConstant :: e -> c e -> c e | 31 | addConstant :: e -> c e -> c e |