diff options
author | Alberto Ruiz <aruiz@um.es> | 2015-06-15 12:52:46 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2015-06-15 12:52:46 +0200 |
commit | 7376d022b12a27db5a396f89806a709555c1c522 (patch) | |
tree | f5bab9687cf775185f20dbc22713eddb360b495a /packages/base/src/Internal/Util.hs | |
parent | 57487d828065ea219cdb33c9dc177b67c60b34c7 (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.hs | 38 |
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 | |||
85 | type ℂ = Complex Double | 85 | type ℂ = Complex Double |
86 | 86 | ||
87 | -- | imaginary unit | 87 | -- | imaginary unit |
88 | iC :: ℂ | 88 | iC :: C |
89 | iC = 0:+1 | 89 | iC = 0:+1 |
90 | 90 | ||
91 | {- | Create a real vector. | 91 | {- | Create a real vector. |
@@ -94,7 +94,7 @@ iC = 0:+1 | |||
94 | fromList [1.0,2.0,3.0,4.0,5.0] | 94 | fromList [1.0,2.0,3.0,4.0,5.0] |
95 | 95 | ||
96 | -} | 96 | -} |
97 | vector :: [ℝ] -> Vector ℝ | 97 | vector :: [R] -> Vector R |
98 | vector = fromList | 98 | vector = fromList |
99 | 99 | ||
100 | {- | Create a real matrix. | 100 | {- | Create a real matrix. |
@@ -108,8 +108,8 @@ vector = fromList | |||
108 | -} | 108 | -} |
109 | matrix | 109 | matrix |
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 |
113 | matrix c = reshape c . fromList | 113 | matrix c = reshape c . fromList |
114 | 114 | ||
115 | 115 | ||
@@ -260,34 +260,34 @@ norm = pnorm PNorm2 | |||
260 | 260 | ||
261 | class Normed a | 261 | class 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 | ||
269 | instance Normed (Vector ℝ) | 269 | instance 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 | ||
276 | instance Normed (Vector ℂ) | 276 | instance 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 | ||
283 | instance Normed (Matrix ℝ) | 283 | instance 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 | ||
290 | instance Normed (Matrix ℂ) | 290 | instance 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 | ||
326 | norm_Frob :: (Normed (Vector t), Element t) => Matrix t -> ℝ | 326 | norm_Frob :: (Normed (Vector t), Element t) => Matrix t -> R |
327 | norm_Frob = norm_2 . flatten | 327 | norm_Frob = norm_2 . flatten |
328 | 328 | ||
329 | norm_nuclear :: Field t => Matrix t -> ℝ | 329 | norm_nuclear :: Field t => Matrix t -> R |
330 | norm_nuclear = sumElements . singularValues | 330 | norm_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) | ||
335 | False | ||
336 | >>> magnit 1E-6 (3+iC :: C) | ||
337 | True | ||
338 | >>> magnit 0 (3 :: I ./. 5) | ||
339 | True | ||
340 | |||
341 | -} | ||
332 | magnit :: (Element t, Normed (Vector t)) => R -> t -> Bool | 342 | magnit :: (Element t, Normed (Vector t)) => R -> t -> Bool |
333 | magnit e x = norm_1 (fromList [x]) > e | 343 | magnit e x = norm_1 (fromList [x]) > e |
334 | 344 | ||