summaryrefslogtreecommitdiff
path: root/packages/base/src/Numeric/LinearAlgebra
diff options
context:
space:
mode:
Diffstat (limited to 'packages/base/src/Numeric/LinearAlgebra')
-rw-r--r--packages/base/src/Numeric/LinearAlgebra/Util.hs60
1 files changed, 36 insertions, 24 deletions
diff --git a/packages/base/src/Numeric/LinearAlgebra/Util.hs b/packages/base/src/Numeric/LinearAlgebra/Util.hs
index aee21b8..324fb44 100644
--- a/packages/base/src/Numeric/LinearAlgebra/Util.hs
+++ b/packages/base/src/Numeric/LinearAlgebra/Util.hs
@@ -33,8 +33,7 @@ module Numeric.LinearAlgebra.Util(
33 cross, 33 cross,
34 norm, 34 norm,
35 ℕ,ℤ,ℝ,ℂ,𝑖,i_C, --ℍ 35 ℕ,ℤ,ℝ,ℂ,𝑖,i_C, --ℍ
36 norm_1, norm_2, norm_0, norm_Inf, norm_Frob, norm_nuclear, 36 Normed(..), norm_Frob, norm_nuclear,
37 mnorm_1, mnorm_2, mnorm_0, mnorm_Inf,
38 unitary, 37 unitary,
39 mt, 38 mt,
40 (~!~), 39 (~!~),
@@ -61,7 +60,8 @@ module Numeric.LinearAlgebra.Util(
61) where 60) where
62 61
63import Data.Packed.Numeric 62import Data.Packed.Numeric
64import Numeric.LinearAlgebra.Algorithms hiding (i) 63import Numeric.LinearAlgebra.Algorithms hiding (i,Normed)
64--import qualified Numeric.LinearAlgebra.Algorithms as A
65import Numeric.Matrix() 65import Numeric.Matrix()
66import Numeric.Vector() 66import Numeric.Vector()
67import Numeric.LinearAlgebra.Random 67import Numeric.LinearAlgebra.Random
@@ -225,37 +225,49 @@ norm :: Vector Double -> Double
225-- ^ 2-norm of real vector 225-- ^ 2-norm of real vector
226norm = pnorm PNorm2 226norm = pnorm PNorm2
227 227
228norm_2 :: Normed Vector t => Vector t -> RealOf t 228class Normed a
229norm_2 = pnorm PNorm2 229 where
230 norm_0 :: a -> ℝ
231 norm_1 :: a -> ℝ
232 norm_2 :: a -> ℝ
233 norm_Inf :: a -> ℝ
230 234
231norm_1 :: Normed Vector t => Vector t -> RealOf t
232norm_1 = pnorm PNorm1
233 235
234norm_Inf :: Normed Vector t => Vector t -> RealOf t 236instance Normed (Vector ℝ)
235norm_Inf = pnorm Infinity 237 where
238 norm_0 v = sumElements (step (abs v - scalar (eps*normInf v)))
239 norm_1 = pnorm PNorm1
240 norm_2 = pnorm PNorm2
241 norm_Inf = pnorm Infinity
236 242
237norm_0 :: Vector ℝ -> ℝ 243instance Normed (Vector ℂ)
238norm_0 v = sumElements (step (abs v - scalar (eps*mx)))
239 where 244 where
240 mx = norm_Inf v 245 norm_0 v = sumElements (step (fst (fromComplex (abs v)) - scalar (eps*normInf v)))
246 norm_1 = pnorm PNorm1
247 norm_2 = pnorm PNorm2
248 norm_Inf = pnorm Infinity
241 249
242norm_Frob :: Normed Matrix t => Matrix t -> RealOf t 250instance Normed (Matrix ℝ)
243norm_Frob = pnorm Frobenius 251 where
252 norm_0 = norm_0 . flatten
253 norm_1 = pnorm PNorm1
254 norm_2 = pnorm PNorm2
255 norm_Inf = pnorm Infinity
244 256
245norm_nuclear :: Field t => Matrix t -> ℝ 257instance Normed (Matrix ℂ)
246norm_nuclear = sumElements . singularValues 258 where
259 norm_0 = norm_0 . flatten
260 norm_1 = pnorm PNorm1
261 norm_2 = pnorm PNorm2
262 norm_Inf = pnorm Infinity
247 263
248mnorm_2 :: Normed Matrix t => Matrix t -> RealOf t
249mnorm_2 = pnorm PNorm2
250 264
251mnorm_1 :: Normed Matrix t => Matrix t -> RealOf t 265norm_Frob :: (Normed (Vector t), Element t) => Matrix t ->
252mnorm_1 = pnorm PNorm1 266norm_Frob = norm_2 . flatten
253 267
254mnorm_Inf :: Normed Matrix t => Matrix t -> RealOf t 268norm_nuclear :: Field t => Matrix t ->
255mnorm_Inf = pnorm Infinity 269norm_nuclear = sumElements . singularValues
256 270
257mnorm_0 :: Matrix ℝ -> ℝ
258mnorm_0 = norm_0 . flatten
259 271
260-- | Obtains a vector in the same direction with 2-norm=1 272-- | Obtains a vector in the same direction with 2-norm=1
261unitary :: Vector Double -> Vector Double 273unitary :: Vector Double -> Vector Double