summaryrefslogtreecommitdiff
path: root/lib/Numeric/LinearAlgebra/Interface.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Interface.hs')
-rw-r--r--lib/Numeric/LinearAlgebra/Interface.hs118
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{- |
5Module : Numeric.LinearAlgebra.Interface
6Copyright : (c) Alberto Ruiz 2007
7License : GPL-style
8
9Maintainer : Alberto Ruiz (aruiz at um dot es)
10Stability : provisional
11Portability : portable
12
13Some useful operators, and Show, Read, Eq, Num, Fractional, and Floating instances for Vector and Matrix.
14
15In 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
21module Numeric.LinearAlgebra.Interface(
22 (<>),(<.>),
23 (<\>),
24 (.*),(*/),
25 (<|>),(<->),
26) where
27
28import Numeric.Vector
29import Numeric.Matrix
30import Numeric.LinearAlgebra.Algorithms
31import Numeric.LinearAlgebra.Linear
32
33class 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
38instance Mul Matrix Matrix Matrix where
39 (<>) = mXm
40
41instance Mul Matrix Vector Vector where
42 (<>) m v = flatten $ m <> (asColumn v)
43
44instance 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
52infixl 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
61infixl 7 .*
62a .* 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
70infixl 7 */
71v */ 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
75infixl 7 <\>
76m <\> 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
83class 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
87instance Joinable Matrix Matrix where
88 joinH m1 m2 = fromBlocks [[m1,m2]]
89 joinV m1 m2 = fromBlocks [[m1],[m2]]
90
91instance Joinable Matrix Vector where
92 joinH m v = joinH m (asColumn v)
93 joinV m v = joinV m (asRow v)
94
95instance Joinable Vector Matrix where
96 joinH v m = joinH (asColumn v) m
97 joinV v m = joinV (asRow v) m
98
99infixl 4 <|>
100infixl 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
114a <|> b = joinH a b
115
116-- -- | Vertical concatenation of matrices and vectors.
117-- (<->) :: (Element t, Joinable a b) => a t -> b t -> Matrix t
118a <-> b = joinV a b