diff options
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Linear.hs')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Linear.hs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/Numeric/LinearAlgebra/Linear.hs b/lib/Numeric/LinearAlgebra/Linear.hs index 699985f..7e23745 100644 --- a/lib/Numeric/LinearAlgebra/Linear.hs +++ b/lib/Numeric/LinearAlgebra/Linear.hs | |||
@@ -23,7 +23,13 @@ import Numeric.GSL.Vector | |||
23 | 23 | ||
24 | -- | A generic interface for vectors and matrices to a few element-by-element functions in Numeric.GSL.Vector. | 24 | -- | A generic interface for vectors and matrices to a few element-by-element functions in Numeric.GSL.Vector. |
25 | class (Container c e) => Linear c e where | 25 | class (Container c e) => Linear c e where |
26 | -- | create a structure with a single element | ||
27 | scalar :: e -> c e | ||
26 | scale :: e -> c e -> c e | 28 | scale :: e -> c e -> c e |
29 | -- | scale the element by element reciprocal of the object: | ||
30 | -- | ||
31 | -- @scaleRecip 2 (fromList [5,i]) == 2 |> [0.4 :+ 0.0,0.0 :+ (-2.0)]@ | ||
32 | scaleRecip :: e -> c e -> c e | ||
27 | addConstant :: e -> c e -> c e | 33 | addConstant :: e -> c e -> c e |
28 | add :: c e -> c e -> c e | 34 | add :: c e -> c e -> c e |
29 | sub :: c e -> c e -> c e | 35 | sub :: c e -> c e -> c e |
@@ -31,10 +37,8 @@ class (Container c e) => Linear c e where | |||
31 | mul :: c e -> c e -> c e | 37 | mul :: c e -> c e -> c e |
32 | -- | element by element division | 38 | -- | element by element division |
33 | divide :: c e -> c e -> c e | 39 | divide :: c e -> c e -> c e |
34 | -- | scale the element by element reciprocal of the object: @scaleRecip 2 (fromList [5,i]) == 2 |> [0.4 :+ 0.0,0.0 :+ (-2.0)]@ | ||
35 | scaleRecip :: e -> c e -> c e | ||
36 | equal :: c e -> c e -> Bool | 40 | equal :: c e -> c e -> Bool |
37 | -- numequal :: Double -> c e -> c e -> Bool | 41 | |
38 | 42 | ||
39 | instance Linear Vector Double where | 43 | instance Linear Vector Double where |
40 | scale = vectorMapValR Scale | 44 | scale = vectorMapValR Scale |
@@ -45,6 +49,7 @@ instance Linear Vector Double where | |||
45 | mul = vectorZipR Mul | 49 | mul = vectorZipR Mul |
46 | divide = vectorZipR Div | 50 | divide = vectorZipR Div |
47 | equal u v = dim u == dim v && vectorMax (vectorMapR Abs (sub u v)) == 0.0 | 51 | equal u v = dim u == dim v && vectorMax (vectorMapR Abs (sub u v)) == 0.0 |
52 | scalar x = fromList [x] | ||
48 | 53 | ||
49 | instance Linear Vector (Complex Double) where | 54 | instance Linear Vector (Complex Double) where |
50 | scale = vectorMapValC Scale | 55 | scale = vectorMapValC Scale |
@@ -55,6 +60,7 @@ instance Linear Vector (Complex Double) where | |||
55 | mul = vectorZipC Mul | 60 | mul = vectorZipC Mul |
56 | divide = vectorZipC Div | 61 | divide = vectorZipC Div |
57 | equal u v = dim u == dim v && vectorMax (mapVector magnitude (sub u v)) == 0.0 | 62 | equal u v = dim u == dim v && vectorMax (mapVector magnitude (sub u v)) == 0.0 |
63 | scalar x = fromList [x] | ||
58 | 64 | ||
59 | instance (Linear Vector a, Container Matrix a) => (Linear Matrix a) where | 65 | instance (Linear Vector a, Container Matrix a) => (Linear Matrix a) where |
60 | scale x = liftMatrix (scale x) | 66 | scale x = liftMatrix (scale x) |
@@ -65,3 +71,4 @@ instance (Linear Vector a, Container Matrix a) => (Linear Matrix a) where | |||
65 | mul = liftMatrix2 mul | 71 | mul = liftMatrix2 mul |
66 | divide = liftMatrix2 divide | 72 | divide = liftMatrix2 divide |
67 | equal a b = cols a == cols b && flatten a `equal` flatten b | 73 | equal a b = cols a == cols b && flatten a `equal` flatten b |
74 | scalar x = (1><1) [x] | ||