summaryrefslogtreecommitdiff
path: root/lib/Numeric/LinearAlgebra/Util.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Util.hs')
-rw-r--r--lib/Numeric/LinearAlgebra/Util.hs122
1 files changed, 0 insertions, 122 deletions
diff --git a/lib/Numeric/LinearAlgebra/Util.hs b/lib/Numeric/LinearAlgebra/Util.hs
deleted file mode 100644
index 24317e3..0000000
--- a/lib/Numeric/LinearAlgebra/Util.hs
+++ /dev/null
@@ -1,122 +0,0 @@
1-----------------------------------------------------------------------------
2{- |
3Module : Numeric.LinearAlgebra.Util
4Copyright : (c) Alberto Ruiz 2010
5License : GPL
6
7Maintainer : Alberto Ruiz (aruiz at um dot es)
8Stability : provisional
9Portability : portable
10
11Alternative interface and utilities for creation of real arrays, useful to work in interactive mode.
12
13-}
14-----------------------------------------------------------------------------
15
16module Numeric.LinearAlgebra.Util(
17 module Numeric.LinearAlgebra,
18 (<>), (*>), (<*), (<\>), (\>),
19 vector,
20 eye,
21 zeros, ones,
22 diagl,
23 row,
24 col,
25 (#),(&), (//), blocks,
26 rand,
27 splitEvery,
28 table
29) where
30
31import Numeric.LinearAlgebra hiding ((<>), (<|>), (<->), (<\>), (.*), (*/))
32import Data.Packed.Internal.Common(table,splitEvery)
33import System.Random(randomIO)
34
35infixl 7 <>
36-- | Matrix product ('multiply')
37(<>) :: Field t => Matrix t -> Matrix t -> Matrix t
38(<>) = multiply
39
40infixl 7 *>
41-- | matrix x vector
42(*>) :: Field t => Matrix t -> Vector t -> Vector t
43m *> v = flatten $ m <> (asColumn v)
44
45infixl 7 <*
46-- | vector x matrix
47(<*) :: Field t => Vector t -> Matrix t -> Vector t
48v <* m = flatten $ (asRow v) <> m
49
50
51-- | Least squares solution of a linear system for several right-hand sides, similar to the \\ operator of Matlab\/Octave. (\<\\\>) = 'linearSolveSVD'.
52(<\>) :: (Field a) => Matrix a -> Matrix a -> Matrix a
53infixl 7 <\>
54(<\>) = linearSolveSVD
55
56-- | Least squares solution of a linear system for a single right-hand side. See '(\<\\\>)'.
57(\>) :: (Field a) => Matrix a -> Vector a -> Vector a
58infixl 7 \>
59m \> v = flatten (m <\> reshape 1 v)
60
61-- | Pseudorandom matrix with uniform elements between 0 and 1.
62rand :: Int -- ^ rows
63 -> Int -- ^ columns
64 -> IO (Matrix Double)
65rand r c = do
66 seed <- randomIO
67 return (reshape c $ randomVector seed Uniform (r*c))
68
69-- | Real identity matrix.
70eye :: Int -> Matrix Double
71eye = ident
72
73-- | Create a real vector from a list.
74vector :: [Double] -> Vector Double
75vector = fromList
76
77-- | Create a real diagonal matrix from a list.
78diagl :: [Double] -> Matrix Double
79diagl = diag . vector
80
81-- | Create a matrix or zeros.
82zeros :: Int -- ^ rows
83 -> Int -- ^ columns
84 -> Matrix Double
85zeros r c = reshape c (constant 0 (r*c))
86
87-- | Create a matrix or ones.
88ones :: Int -- ^ rows
89 -> Int -- ^ columns
90 -> Matrix Double
91ones r c = reshape c (constant 1 (r*c))
92
93
94-- | Concatenation of real vectors.
95infixl 9 #
96(#) :: Vector Double -> Vector Double -> Vector Double
97a # b = join [a,b]
98
99
100-- | Horizontal concatenation of real matrices.
101infixl 8 &
102(&) :: Matrix Double -> Matrix Double -> Matrix Double
103a & b = fromBlocks [[a,b]]
104
105-- | Vertical concatenation of real matrices.
106infixl 7 //
107(//) :: Matrix Double -> Matrix Double -> Matrix Double
108a // b = fromBlocks [[a],[b]]
109
110-- | Real block matrix from a rectangular list of lists.
111blocks :: [[Matrix Double]] -> Matrix Double
112blocks = fromBlocks
113
114-- | A real matrix with a single row, create from a list of elements.
115row :: [Double] -> Matrix Double
116row = asRow . vector
117
118-- | A real matrix with a single column, created from a list of elements.
119col :: [Double] -> Matrix Double
120col = asColumn . vector
121
122