diff options
Diffstat (limited to 'packages/base/src/Numeric/LinearAlgebra/Real.hs')
-rw-r--r-- | packages/base/src/Numeric/LinearAlgebra/Real.hs | 59 |
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 | ||
48 | import GHC.TypeLits | 47 | import GHC.TypeLits |
49 | import Numeric.HMatrix hiding ((<>),(#>),(<ยท>),Konst(..),diag, disp,(ยฆ),(โโ)) | 48 | import Numeric.HMatrix hiding ((<>),(#>),(<ยท>),Konst(..),diag, disp,(ยฆ),(โโ),row,col) |
50 | import qualified Numeric.HMatrix as LA | 49 | import qualified Numeric.HMatrix as LA |
51 | import Data.Packed.ST | 50 | import Data.Packed.ST |
51 | import Data.Proxy(Proxy) | ||
52 | 52 | ||
53 | newtype Dim (n :: Nat) t = Dim t | 53 | newtype Dim (n :: Nat) t = Dim t |
54 | deriving Show | 54 | deriving Show |
@@ -56,7 +56,7 @@ newtype Dim (n :: Nat) t = Dim t | |||
56 | unDim :: Dim n t -> t | 56 | unDim :: Dim n t -> t |
57 | unDim (Dim x) = x | 57 | unDim (Dim x) = x |
58 | 58 | ||
59 | data Proxy :: Nat -> * | 59 | -- data Proxy :: Nat -> * |
60 | 60 | ||
61 | 61 | ||
62 | lift1F | 62 | lift1F |
@@ -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 | {- | |
227 | infixl 3 # | 227 | infixl 3 # |
228 | (#) :: L r c -> R c -> L (r+1) c | 228 | (#) :: L r c -> R c -> L (r+1) c |
229 | Dim (Dim m) # Dim v = Dim (Dim (m LA.โโ asRow v)) | 229 | Dim (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 | |||
238 | row :: R n -> L 1 n | ||
239 | row (Dim v) = Dim (Dim (asRow v)) | ||
240 | |||
241 | col :: R n -> L n 1 | ||
242 | col = tr . row | ||
236 | 243 | ||
237 | infixl 3 ยฆ | 244 | infixl 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) |
239 | Dim (Dim a) ยฆ Dim (Dim b) = Dim (Dim (a LA.ยฆ b)) | 246 | a ยฆ b = rjoin (expk a) (expk b) |
247 | where | ||
248 | Dim (Dim a') `rjoin` Dim (Dim b') = Dim (Dim (a' LA.ยฆ b')) | ||
240 | 249 | ||
241 | infixl 2 โโ | 250 | infixl 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 |
243 | Dim (Dim a) โโ Dim (Dim b) = Dim (Dim (a LA.โโ b)) | 252 | a โโ b = cjoin (expk a) (expk b) |
253 | where | ||
254 | Dim (Dim a') `cjoin` Dim (Dim b') = Dim (Dim (a' LA.โโ b')) | ||
255 | |||
256 | expk :: (KnownNat n, KnownNat m) => L m n -> L m n | ||
257 | expk 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 | {- | ||
342 | do (snd test) | ||
343 | fst test | ||
344 | -} | ||
345 | |||
346 | |||
347 | 358 | ||