summaryrefslogtreecommitdiff
path: root/lib/Numeric/LinearAlgebra/Instances.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-10-19 09:39:06 +0000
committerAlberto Ruiz <aruiz@um.es>2007-10-19 09:39:06 +0000
commit1a9c07dd1fffdbd7eb939fa6a781793419947c08 (patch)
tree849f7206f3179b60b19a6e986809b108381c9414 /lib/Numeric/LinearAlgebra/Instances.hs
parentf71bcb5b4fbc68f514acc05005cc96932ced32dc (diff)
some refactoring
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Instances.hs')
-rw-r--r--lib/Numeric/LinearAlgebra/Instances.hs23
1 files changed, 22 insertions, 1 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)
9Stability : provisional 9Stability : provisional
10Portability : portable 10Portability : portable
11 11
12Numeric instances for Vector and Matrix. 12This module exports Show, Eq, Num, Fractional, and Floating instances for Vector and Matrix.
13 13
14In the context of the standard numeric operators, one-component vectors and matrices automatically expand to match the dimensions of the other operand. 14In 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
24import Data.Packed.Matrix 24import Data.Packed.Matrix
25import Data.Packed.Vector 25import Data.Packed.Vector
26import Complex 26import Complex
27import Data.List(transpose,intersperse)
28import Foreign(Storable)
29
30------------------------------------------------------------------
31
32instance (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
36dsp 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
44instance (Show a, Storable a) => (Show (Vector a)) where
45 show v = (show (dim v))++" |> " ++ show (toList v)
46
47------------------------------------------------------------------
27 48
28adaptScalar f1 f2 f3 x y 49adaptScalar f1 f2 f3 x y
29 | dim x == 1 = f1 (x@>0) y 50 | dim x == 1 = f1 (x@>0) y