summaryrefslogtreecommitdiff
path: root/lib/Numeric
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Numeric')
-rw-r--r--lib/Numeric/Container.hs91
-rw-r--r--lib/Numeric/LinearAlgebra/Algorithms.hs2
-rw-r--r--lib/Numeric/Matrix.hs75
3 files changed, 93 insertions, 75 deletions
diff --git a/lib/Numeric/Container.hs b/lib/Numeric/Container.hs
index 0fecf86..8cf3e07 100644
--- a/lib/Numeric/Container.hs
+++ b/lib/Numeric/Container.hs
@@ -20,11 +20,14 @@
20----------------------------------------------------------------------------- 20-----------------------------------------------------------------------------
21 21
22module Numeric.Container ( 22module Numeric.Container (
23 -- * Generic operations
23 Container(..), 24 Container(..),
25 -- * Matrix product and related functions
24 Product(..), 26 Product(..),
25 mXm,mXv,vXm, 27 mXm,mXv,vXm,
26 outer, kronecker, 28 outer, kronecker,
27 29
30 -- * Element conversion
28 Convert(..), 31 Convert(..),
29 Complexable(), 32 Complexable(),
30 RealElement(), 33 RealElement(),
@@ -32,7 +35,11 @@ module Numeric.Container (
32 RealOf, ComplexOf, SingleOf, DoubleOf, 35 RealOf, ComplexOf, SingleOf, DoubleOf,
33 36
34 IndexOf, 37 IndexOf,
35 module Data.Complex 38 module Data.Complex,
39 -- * Deprecated
40 (.*),(*/),(<|>),(<->),
41 vectorMax,vectorMin,
42 vectorMaxIndex, vectorMinIndex
36) where 43) where
37 44
38import Data.Packed 45import Data.Packed
@@ -397,3 +404,85 @@ type family ElementOf c
397type instance ElementOf (Vector a) = a 404type instance ElementOf (Vector a) = a
398type instance ElementOf (Matrix a) = a 405type instance ElementOf (Matrix a) = a
399 406
407------------------------------------------------------------
408
409----------------------------------------------------
410
411{-# DEPRECATED (.*) "use scale a x or scalar a * x" #-}
412
413-- -- | @x .* a = scale x a@
414-- (.*) :: (Linear c a) => a -> c a -> c a
415infixl 7 .*
416a .* x = scale a x
417
418----------------------------------------------------
419
420{-# DEPRECATED (*/) "use scale (recip a) x or x / scalar a" #-}
421
422-- -- | @a *\/ x = scale (recip x) a@
423-- (*/) :: (Linear c a) => c a -> a -> c a
424infixl 7 */
425v */ x = scale (recip x) v
426
427
428------------------------------------------------
429
430{-# DEPRECATED (<|>) "define operator a & b = fromBlocks[[a,b]] and use asRow/asColumn to join vectors" #-}
431{-# DEPRECATED (<->) "define operator a // b = fromBlocks[[a],[b]] and use asRow/asColumn to join vectors" #-}
432
433class Joinable a b where
434 joinH :: Element t => a t -> b t -> Matrix t
435 joinV :: Element t => a t -> b t -> Matrix t
436
437instance Joinable Matrix Matrix where
438 joinH m1 m2 = fromBlocks [[m1,m2]]
439 joinV m1 m2 = fromBlocks [[m1],[m2]]
440
441instance Joinable Matrix Vector where
442 joinH m v = joinH m (asColumn v)
443 joinV m v = joinV m (asRow v)
444
445instance Joinable Vector Matrix where
446 joinH v m = joinH (asColumn v) m
447 joinV v m = joinV (asRow v) m
448
449infixl 4 <|>
450infixl 3 <->
451
452{-- - | Horizontal concatenation of matrices and vectors:
453
454@> (ident 3 \<-\> 3 * ident 3) \<|\> fromList [1..6.0]
455(6><4)
456 [ 1.0, 0.0, 0.0, 1.0
457 , 0.0, 1.0, 0.0, 2.0
458 , 0.0, 0.0, 1.0, 3.0
459 , 3.0, 0.0, 0.0, 4.0
460 , 0.0, 3.0, 0.0, 5.0
461 , 0.0, 0.0, 3.0, 6.0 ]@
462-}
463-- (<|>) :: (Element t, Joinable a b) => a t -> b t -> Matrix t
464a <|> b = joinH a b
465
466-- -- | Vertical concatenation of matrices and vectors.
467-- (<->) :: (Element t, Joinable a b) => a t -> b t -> Matrix t
468a <-> b = joinV a b
469
470-------------------------------------------------------------------
471
472{-# DEPRECATED vectorMin "use minElement" #-}
473vectorMin :: (Container Vector t, Element t) => Vector t -> t
474vectorMin = minElement
475
476{-# DEPRECATED vectorMax "use maxElement" #-}
477vectorMax :: (Container Vector t, Element t) => Vector t -> t
478vectorMax = maxElement
479
480
481{-# DEPRECATED vectorMaxIndex "use minIndex" #-}
482vectorMaxIndex :: Vector Double -> Int
483vectorMaxIndex = round . toScalarR MaxIdx
484
485{-# DEPRECATED vectorMinIndex "use maxIndex" #-}
486vectorMinIndex :: Vector Double -> Int
487vectorMinIndex = round . toScalarR MinIdx
488
diff --git a/lib/Numeric/LinearAlgebra/Algorithms.hs b/lib/Numeric/LinearAlgebra/Algorithms.hs
index 28cf88f..4f6f54d 100644
--- a/lib/Numeric/LinearAlgebra/Algorithms.hs
+++ b/lib/Numeric/LinearAlgebra/Algorithms.hs
@@ -79,7 +79,7 @@ import Data.Packed.Matrix
79import Numeric.LinearAlgebra.LAPACK as LAPACK 79import Numeric.LinearAlgebra.LAPACK as LAPACK
80import Data.List(foldl1') 80import Data.List(foldl1')
81import Data.Array 81import Data.Array
82import Numeric.Container 82import Numeric.Container hiding ((.*),(*/))
83 83
84-- | Auxiliary typeclass used to define generic computations for both real and complex matrices. 84-- | Auxiliary typeclass used to define generic computations for both real and complex matrices.
85class (Product t, 85class (Product t,
diff --git a/lib/Numeric/Matrix.hs b/lib/Numeric/Matrix.hs
index 3d1ac94..f78e0c2 100644
--- a/lib/Numeric/Matrix.hs
+++ b/lib/Numeric/Matrix.hs
@@ -31,10 +31,7 @@ module Numeric.Matrix (
31 --module Numeric.Container, 31 --module Numeric.Container,
32 optimiseMult, 32 optimiseMult,
33 -- * Operators 33 -- * Operators
34 (<>), (<\>), 34 (<>), (<\>)
35 -- * Deprecated
36 (.*),(*/),(<|>),(<->),
37 vectorMax,vectorMin
38 ) where 35 ) where
39 36
40------------------------------------------------------------------- 37-------------------------------------------------------------------
@@ -101,77 +98,9 @@ instance Mul Matrix Vector Vector where
101instance Mul Vector Matrix Vector where 98instance Mul Vector Matrix Vector where
102 (<>) v m = flatten $ (asRow v) <> m 99 (<>) v m = flatten $ (asRow v) <> m
103 100
104---------------------------------------------------- 101--------------------------------------------------------
105
106{-# DEPRECATED (.*) "use scale a x or scalar a * x" #-}
107
108-- -- | @x .* a = scale x a@
109-- (.*) :: (Linear c a) => a -> c a -> c a
110infixl 7 .*
111a .* x = scale a x
112
113----------------------------------------------------
114
115{-# DEPRECATED (*/) "use scale (recip a) x or x / scalar a" #-}
116
117-- -- | @a *\/ x = scale (recip x) a@
118-- (*/) :: (Linear c a) => c a -> a -> c a
119infixl 7 */
120v */ x = scale (recip x) v
121 102
122-- | least squares solution of a linear system, similar to the \\ operator of Matlab\/Octave (based on linearSolveSVD). 103-- | least squares solution of a linear system, similar to the \\ operator of Matlab\/Octave (based on linearSolveSVD).
123(<\>) :: (Field a) => Matrix a -> Vector a -> Vector a 104(<\>) :: (Field a) => Matrix a -> Vector a -> Vector a
124infixl 7 <\> 105infixl 7 <\>
125m <\> v = flatten (linearSolveSVD m (reshape 1 v)) 106m <\> v = flatten (linearSolveSVD m (reshape 1 v))
126
127------------------------------------------------
128
129{-# DEPRECATED (<|>) "define operator a & b = fromBlocks[[a,b]] and use asRow/asColumn to join vectors" #-}
130{-# DEPRECATED (<->) "define operator a // b = fromBlocks[[a],[b]] and use asRow/asColumn to join vectors" #-}
131
132class Joinable a b where
133 joinH :: Element t => a t -> b t -> Matrix t
134 joinV :: Element t => a t -> b t -> Matrix t
135
136instance Joinable Matrix Matrix where
137 joinH m1 m2 = fromBlocks [[m1,m2]]
138 joinV m1 m2 = fromBlocks [[m1],[m2]]
139
140instance Joinable Matrix Vector where
141 joinH m v = joinH m (asColumn v)
142 joinV m v = joinV m (asRow v)
143
144instance Joinable Vector Matrix where
145 joinH v m = joinH (asColumn v) m
146 joinV v m = joinV (asRow v) m
147
148infixl 4 <|>
149infixl 3 <->
150
151{-- - | Horizontal concatenation of matrices and vectors:
152
153@> (ident 3 \<-\> 3 * ident 3) \<|\> fromList [1..6.0]
154(6><4)
155 [ 1.0, 0.0, 0.0, 1.0
156 , 0.0, 1.0, 0.0, 2.0
157 , 0.0, 0.0, 1.0, 3.0
158 , 3.0, 0.0, 0.0, 4.0
159 , 0.0, 3.0, 0.0, 5.0
160 , 0.0, 0.0, 3.0, 6.0 ]@
161-}
162-- (<|>) :: (Element t, Joinable a b) => a t -> b t -> Matrix t
163a <|> b = joinH a b
164
165-- -- | Vertical concatenation of matrices and vectors.
166-- (<->) :: (Element t, Joinable a b) => a t -> b t -> Matrix t
167a <-> b = joinV a b
168
169-------------------------------------------------------------------
170
171{-# DEPRECATED vectorMin "use minElement" #-}
172vectorMin :: (Container Vector t, Element t) => Vector t -> t
173vectorMin = minElement
174
175{-# DEPRECATED vectorMax "use maxElement" #-}
176vectorMax :: (Container Vector t, Element t) => Vector t -> t
177vectorMax = maxElement