summaryrefslogtreecommitdiff
path: root/packages/base/src/Internal/Util.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2015-06-15 12:52:46 +0200
committerAlberto Ruiz <aruiz@um.es>2015-06-15 12:52:46 +0200
commit7376d022b12a27db5a396f89806a709555c1c522 (patch)
treef5bab9687cf775185f20dbc22713eddb360b495a /packages/base/src/Internal/Util.hs
parent57487d828065ea219cdb33c9dc177b67c60b34c7 (diff)
documentation, more general cond, remove some unicode, minor changes
Diffstat (limited to 'packages/base/src/Internal/Util.hs')
-rw-r--r--packages/base/src/Internal/Util.hs38
1 files changed, 24 insertions, 14 deletions
diff --git a/packages/base/src/Internal/Util.hs b/packages/base/src/Internal/Util.hs
index 09ba21c..f08f710 100644
--- a/packages/base/src/Internal/Util.hs
+++ b/packages/base/src/Internal/Util.hs
@@ -85,7 +85,7 @@ type ℤ = Int
85type ℂ = Complex Double 85type ℂ = Complex Double
86 86
87-- | imaginary unit 87-- | imaginary unit
88iC :: 88iC :: C
89iC = 0:+1 89iC = 0:+1
90 90
91{- | Create a real vector. 91{- | Create a real vector.
@@ -94,7 +94,7 @@ iC = 0:+1
94fromList [1.0,2.0,3.0,4.0,5.0] 94fromList [1.0,2.0,3.0,4.0,5.0]
95 95
96-} 96-}
97vector :: [] -> Vector 97vector :: [R] -> Vector R
98vector = fromList 98vector = fromList
99 99
100{- | Create a real matrix. 100{- | Create a real matrix.
@@ -108,8 +108,8 @@ vector = fromList
108-} 108-}
109matrix 109matrix
110 :: Int -- ^ number of columns 110 :: Int -- ^ number of columns
111 -> [] -- ^ elements in row order 111 -> [R] -- ^ elements in row order
112 -> Matrix 112 -> Matrix R
113matrix c = reshape c . fromList 113matrix c = reshape c . fromList
114 114
115 115
@@ -260,34 +260,34 @@ norm = pnorm PNorm2
260 260
261class Normed a 261class Normed a
262 where 262 where
263 norm_0 :: a -> 263 norm_0 :: a -> R
264 norm_1 :: a -> 264 norm_1 :: a -> R
265 norm_2 :: a -> 265 norm_2 :: a -> R
266 norm_Inf :: a -> 266 norm_Inf :: a -> R
267 267
268 268
269instance Normed (Vector ) 269instance Normed (Vector R)
270 where 270 where
271 norm_0 v = sumElements (step (abs v - scalar (eps*normInf v))) 271 norm_0 v = sumElements (step (abs v - scalar (eps*normInf v)))
272 norm_1 = pnorm PNorm1 272 norm_1 = pnorm PNorm1
273 norm_2 = pnorm PNorm2 273 norm_2 = pnorm PNorm2
274 norm_Inf = pnorm Infinity 274 norm_Inf = pnorm Infinity
275 275
276instance Normed (Vector ) 276instance Normed (Vector C)
277 where 277 where
278 norm_0 v = sumElements (step (fst (fromComplex (abs v)) - scalar (eps*normInf v))) 278 norm_0 v = sumElements (step (fst (fromComplex (abs v)) - scalar (eps*normInf v)))
279 norm_1 = pnorm PNorm1 279 norm_1 = pnorm PNorm1
280 norm_2 = pnorm PNorm2 280 norm_2 = pnorm PNorm2
281 norm_Inf = pnorm Infinity 281 norm_Inf = pnorm Infinity
282 282
283instance Normed (Matrix ) 283instance Normed (Matrix R)
284 where 284 where
285 norm_0 = norm_0 . flatten 285 norm_0 = norm_0 . flatten
286 norm_1 = pnorm PNorm1 286 norm_1 = pnorm PNorm1
287 norm_2 = pnorm PNorm2 287 norm_2 = pnorm PNorm2
288 norm_Inf = pnorm Infinity 288 norm_Inf = pnorm Infinity
289 289
290instance Normed (Matrix ) 290instance Normed (Matrix C)
291 where 291 where
292 norm_0 = norm_0 . flatten 292 norm_0 = norm_0 . flatten
293 norm_1 = pnorm PNorm1 293 norm_1 = pnorm PNorm1
@@ -323,12 +323,22 @@ instance Normed (Vector (Complex Float))
323 norm_Inf = norm_Inf . double 323 norm_Inf = norm_Inf . double
324 324
325 325
326norm_Frob :: (Normed (Vector t), Element t) => Matrix t -> 326norm_Frob :: (Normed (Vector t), Element t) => Matrix t -> R
327norm_Frob = norm_2 . flatten 327norm_Frob = norm_2 . flatten
328 328
329norm_nuclear :: Field t => Matrix t -> 329norm_nuclear :: Field t => Matrix t -> R
330norm_nuclear = sumElements . singularValues 330norm_nuclear = sumElements . singularValues
331 331
332{- | Check if the absolute value or complex magnitude is greater than a given threshold
333
334>>> magnit 1E-6 (1E-12 :: R)
335False
336>>> magnit 1E-6 (3+iC :: C)
337True
338>>> magnit 0 (3 :: I ./. 5)
339True
340
341-}
332magnit :: (Element t, Normed (Vector t)) => R -> t -> Bool 342magnit :: (Element t, Normed (Vector t)) => R -> t -> Bool
333magnit e x = norm_1 (fromList [x]) > e 343magnit e x = norm_1 (fromList [x]) > e
334 344