diff options
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Interface.hs')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Interface.hs | 118 |
1 files changed, 0 insertions, 118 deletions
diff --git a/lib/Numeric/LinearAlgebra/Interface.hs b/lib/Numeric/LinearAlgebra/Interface.hs deleted file mode 100644 index fa3e209..0000000 --- a/lib/Numeric/LinearAlgebra/Interface.hs +++ /dev/null | |||
@@ -1,118 +0,0 @@ | |||
1 | {-# OPTIONS_GHC -fglasgow-exts #-} | ||
2 | {-# LANGUAGE UndecidableInstances #-} | ||
3 | ----------------------------------------------------------------------------- | ||
4 | {- | | ||
5 | Module : Numeric.LinearAlgebra.Interface | ||
6 | Copyright : (c) Alberto Ruiz 2007 | ||
7 | License : GPL-style | ||
8 | |||
9 | Maintainer : Alberto Ruiz (aruiz at um dot es) | ||
10 | Stability : provisional | ||
11 | Portability : portable | ||
12 | |||
13 | Some useful operators, and Show, Read, Eq, Num, Fractional, and Floating instances for Vector and Matrix. | ||
14 | |||
15 | In the context of the standard numeric operators, one-component vectors and matrices automatically expand to match the dimensions of the other operand. | ||
16 | |||
17 | |||
18 | -} | ||
19 | ----------------------------------------------------------------------------- | ||
20 | |||
21 | module Numeric.LinearAlgebra.Interface( | ||
22 | (<>),(<.>), | ||
23 | (<\>), | ||
24 | (.*),(*/), | ||
25 | (<|>),(<->), | ||
26 | ) where | ||
27 | |||
28 | import Numeric.Vector | ||
29 | import Numeric.Matrix | ||
30 | import Numeric.LinearAlgebra.Algorithms | ||
31 | import Numeric.LinearAlgebra.Linear | ||
32 | |||
33 | class Mul a b c | a b -> c where | ||
34 | infixl 7 <> | ||
35 | -- | Matrix-matrix, matrix-vector, and vector-matrix products. | ||
36 | (<>) :: Product t => a t -> b t -> c t | ||
37 | |||
38 | instance Mul Matrix Matrix Matrix where | ||
39 | (<>) = mXm | ||
40 | |||
41 | instance Mul Matrix Vector Vector where | ||
42 | (<>) m v = flatten $ m <> (asColumn v) | ||
43 | |||
44 | instance Mul Vector Matrix Vector where | ||
45 | (<>) v m = flatten $ (asRow v) <> m | ||
46 | |||
47 | --------------------------------------------------- | ||
48 | |||
49 | -- | Dot product: @u \<.\> v = dot u v@ | ||
50 | --(<.>) :: (Field t) => Vector t -> Vector t -> t | ||
51 | (<.>) :: Vectors Vector t => Vector t -> Vector t -> t | ||
52 | infixl 7 <.> | ||
53 | (<.>) = dot | ||
54 | |||
55 | ---------------------------------------------------- | ||
56 | |||
57 | {-# DEPRECATED (.*) "use scale a x or scalar a * x" #-} | ||
58 | |||
59 | -- -- | @x .* a = scale x a@ | ||
60 | -- (.*) :: (Linear c a) => a -> c a -> c a | ||
61 | infixl 7 .* | ||
62 | a .* x = scale a x | ||
63 | |||
64 | ---------------------------------------------------- | ||
65 | |||
66 | {-# DEPRECATED (*/) "use scale (recip a) x or x / scalar a" #-} | ||
67 | |||
68 | -- -- | @a *\/ x = scale (recip x) a@ | ||
69 | -- (*/) :: (Linear c a) => c a -> a -> c a | ||
70 | infixl 7 */ | ||
71 | v */ x = scale (recip x) v | ||
72 | |||
73 | -- | least squares solution of a linear system, similar to the \\ operator of Matlab\/Octave (based on linearSolveSVD). | ||
74 | (<\>) :: (Field a) => Matrix a -> Vector a -> Vector a | ||
75 | infixl 7 <\> | ||
76 | m <\> v = flatten (linearSolveSVD m (reshape 1 v)) | ||
77 | |||
78 | ------------------------------------------------ | ||
79 | |||
80 | {-# DEPRECATED (<|>) "define operator a & b = fromBlocks[[a,b]] and use asRow/asColumn to join vectors" #-} | ||
81 | {-# DEPRECATED (<->) "define operator a // b = fromBlocks[[a],[b]] and use asRow/asColumn to join vectors" #-} | ||
82 | |||
83 | class Joinable a b where | ||
84 | joinH :: Element t => a t -> b t -> Matrix t | ||
85 | joinV :: Element t => a t -> b t -> Matrix t | ||
86 | |||
87 | instance Joinable Matrix Matrix where | ||
88 | joinH m1 m2 = fromBlocks [[m1,m2]] | ||
89 | joinV m1 m2 = fromBlocks [[m1],[m2]] | ||
90 | |||
91 | instance Joinable Matrix Vector where | ||
92 | joinH m v = joinH m (asColumn v) | ||
93 | joinV m v = joinV m (asRow v) | ||
94 | |||
95 | instance Joinable Vector Matrix where | ||
96 | joinH v m = joinH (asColumn v) m | ||
97 | joinV v m = joinV (asRow v) m | ||
98 | |||
99 | infixl 4 <|> | ||
100 | infixl 3 <-> | ||
101 | |||
102 | {-- - | Horizontal concatenation of matrices and vectors: | ||
103 | |||
104 | @> (ident 3 \<-\> 3 * ident 3) \<|\> fromList [1..6.0] | ||
105 | (6><4) | ||
106 | [ 1.0, 0.0, 0.0, 1.0 | ||
107 | , 0.0, 1.0, 0.0, 2.0 | ||
108 | , 0.0, 0.0, 1.0, 3.0 | ||
109 | , 3.0, 0.0, 0.0, 4.0 | ||
110 | , 0.0, 3.0, 0.0, 5.0 | ||
111 | , 0.0, 0.0, 3.0, 6.0 ]@ | ||
112 | -} | ||
113 | -- (<|>) :: (Element t, Joinable a b) => a t -> b t -> Matrix t | ||
114 | a <|> b = joinH a b | ||
115 | |||
116 | -- -- | Vertical concatenation of matrices and vectors. | ||
117 | -- (<->) :: (Element t, Joinable a b) => a t -> b t -> Matrix t | ||
118 | a <-> b = joinV a b | ||