summaryrefslogtreecommitdiff
path: root/packages/base/src/Numeric/LinearAlgebra/Real.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2014-05-28 12:16:34 +0200
committerAlberto Ruiz <aruiz@um.es>2014-05-28 12:16:34 +0200
commit2734dd1ddc6b31aba6377ef969a33967babca519 (patch)
tree5a353499f64d2c4defba6d517628c904cbc82036 /packages/base/src/Numeric/LinearAlgebra/Real.hs
parent3c1c5e59e3d699f3e17519f19d47f7dab2403879 (diff)
fix static blocks, GMatrix
Diffstat (limited to 'packages/base/src/Numeric/LinearAlgebra/Real.hs')
-rw-r--r--packages/base/src/Numeric/LinearAlgebra/Real.hs59
1 files changed, 35 insertions, 24 deletions
diff --git a/packages/base/src/Numeric/LinearAlgebra/Real.hs b/packages/base/src/Numeric/LinearAlgebra/Real.hs
index 1e8b544..5634031 100644
--- a/packages/base/src/Numeric/LinearAlgebra/Real.hs
+++ b/packages/base/src/Numeric/LinearAlgebra/Real.hs
@@ -29,26 +29,26 @@ module Numeric.LinearAlgebra.Real(
29 vec2, vec3, vec4, ๐•ง, (&), 29 vec2, vec3, vec4, ๐•ง, (&),
30 -- * Matrix 30 -- * Matrix
31 L, Sq, 31 L, Sq,
32 ๐•ž, 32 row, col, (ยฆ),(โ€”โ€”),
33 (#),(ยฆ),(โ€”โ€”), 33 Konst(..),
34 Konst(..), 34 eye,
35 eye, 35 diagR, diag,
36 diagR, diag, 36 blockAt,
37 blockAt,
38 -- * Products 37 -- * Products
39 (<>),(#>),(<ยท>), 38 (<>),(#>),(<ยท>),
40 -- * Pretty printing 39 -- * Pretty printing
41 Disp(..), 40 Disp(..),
42 -- * Misc 41 -- * Misc
43 Dim, unDim, 42 Dim, unDim,
44 module Numeric.HMatrix 43 module Numeric.HMatrix
45) where 44) where
46 45
47 46
48import GHC.TypeLits 47import GHC.TypeLits
49import Numeric.HMatrix hiding ((<>),(#>),(<ยท>),Konst(..),diag, disp,(ยฆ),(โ€”โ€”)) 48import Numeric.HMatrix hiding ((<>),(#>),(<ยท>),Konst(..),diag, disp,(ยฆ),(โ€”โ€”),row,col)
50import qualified Numeric.HMatrix as LA 49import qualified Numeric.HMatrix as LA
51import Data.Packed.ST 50import Data.Packed.ST
51import Data.Proxy(Proxy)
52 52
53newtype Dim (n :: Nat) t = Dim t 53newtype Dim (n :: Nat) t = Dim t
54 deriving Show 54 deriving Show
@@ -56,7 +56,7 @@ newtype Dim (n :: Nat) t = Dim t
56unDim :: Dim n t -> t 56unDim :: Dim n t -> t
57unDim (Dim x) = x 57unDim (Dim x) = x
58 58
59data Proxy :: Nat -> * 59-- data Proxy :: Nat -> *
60 60
61 61
62lift1F 62lift1F
@@ -223,7 +223,7 @@ instance Disp (R n)
223 else putStr "Dim " >> putStr (tail . dropWhile (/='x') $ su) 223 else putStr "Dim " >> putStr (tail . dropWhile (/='x') $ su)
224 224
225-------------------------------------------------------------------------------- 225--------------------------------------------------------------------------------
226 226{-
227infixl 3 # 227infixl 3 #
228(#) :: L r c -> R c -> L (r+1) c 228(#) :: L r c -> R c -> L (r+1) c
229Dim (Dim m) # Dim v = Dim (Dim (m LA.โ€”โ€” asRow v)) 229Dim (Dim m) # Dim v = Dim (Dim (m LA.โ€”โ€” asRow v))
@@ -233,14 +233,31 @@ Dim (Dim m) # Dim v = Dim (Dim (m LA.โ€”โ€” asRow v))
233๐•ž = Dim (Dim (LA.konst 0 (0,d))) 233๐•ž = Dim (Dim (LA.konst 0 (0,d)))
234 where 234 where
235 d = fromIntegral . natVal $ (undefined :: Proxy n) 235 d = fromIntegral . natVal $ (undefined :: Proxy n)
236-}
237
238row :: R n -> L 1 n
239row (Dim v) = Dim (Dim (asRow v))
240
241col :: R n -> L n 1
242col = tr . row
236 243
237infixl 3 ยฆ 244infixl 3 ยฆ
238(ยฆ) :: L r c1 -> L r c2 -> L r (c1+c2) 245(ยฆ) :: (KnownNat r, KnownNat c1, KnownNat c2) => L r c1 -> L r c2 -> L r (c1+c2)
239Dim (Dim a) ยฆ Dim (Dim b) = Dim (Dim (a LA.ยฆ b)) 246a ยฆ b = rjoin (expk a) (expk b)
247 where
248 Dim (Dim a') `rjoin` Dim (Dim b') = Dim (Dim (a' LA.ยฆ b'))
240 249
241infixl 2 โ€”โ€” 250infixl 2 โ€”โ€”
242(โ€”โ€”) :: L r1 c -> L r2 c -> L (r1+r2) c 251(โ€”โ€”) :: (KnownNat r1, KnownNat r2, KnownNat c) => L r1 c -> L r2 c -> L (r1+r2) c
243Dim (Dim a) โ€”โ€” Dim (Dim b) = Dim (Dim (a LA.โ€”โ€” b)) 252a โ€”โ€” b = cjoin (expk a) (expk b)
253 where
254 Dim (Dim a') `cjoin` Dim (Dim b') = Dim (Dim (a' LA.โ€”โ€” b'))
255
256expk :: (KnownNat n, KnownNat m) => L m n -> L m n
257expk x | singleton x = konst (d2 x `atIndex` (0,0))
258 | otherwise = x
259 where
260 singleton (d2 -> m) = rows m == 1 && cols m == 1
244 261
245 262
246{- 263{-
@@ -338,10 +355,4 @@ instance (KnownNat n', KnownNat m') => Testable (L n' m')
338 where 355 where
339 checkT _ = test 356 checkT _ = test
340 357
341{-
342do (snd test)
343fst test
344-}
345
346
347 358