diff options
Diffstat (limited to 'packages/base/src/Numeric/LinearAlgebra/Complex.hs')
-rw-r--r-- | packages/base/src/Numeric/LinearAlgebra/Complex.hs | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/packages/base/src/Numeric/LinearAlgebra/Complex.hs b/packages/base/src/Numeric/LinearAlgebra/Complex.hs new file mode 100644 index 0000000..17bc397 --- /dev/null +++ b/packages/base/src/Numeric/LinearAlgebra/Complex.hs | |||
@@ -0,0 +1,80 @@ | |||
1 | {-# LANGUAGE DataKinds #-} | ||
2 | {-# LANGUAGE KindSignatures #-} | ||
3 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} | ||
4 | {-# LANGUAGE MultiParamTypeClasses #-} | ||
5 | {-# LANGUAGE FunctionalDependencies #-} | ||
6 | {-# LANGUAGE FlexibleContexts #-} | ||
7 | {-# LANGUAGE ScopedTypeVariables #-} | ||
8 | {-# LANGUAGE EmptyDataDecls #-} | ||
9 | {-# LANGUAGE Rank2Types #-} | ||
10 | {-# LANGUAGE FlexibleInstances #-} | ||
11 | {-# LANGUAGE TypeOperators #-} | ||
12 | {-# LANGUAGE ViewPatterns #-} | ||
13 | {-# LANGUAGE GADTs #-} | ||
14 | |||
15 | |||
16 | {- | | ||
17 | Module : Numeric.LinearAlgebra.Complex | ||
18 | Copyright : (c) Alberto Ruiz 2006-14 | ||
19 | License : BSD3 | ||
20 | Stability : experimental | ||
21 | |||
22 | -} | ||
23 | |||
24 | module Numeric.LinearAlgebra.Complex( | ||
25 | C, | ||
26 | vec2, vec3, vec4, (&), (#), | ||
27 | vect, | ||
28 | R | ||
29 | ) where | ||
30 | |||
31 | import GHC.TypeLits | ||
32 | import Numeric.HMatrix hiding ( | ||
33 | (<>),(#>),(<·>),Konst(..),diag, disp,(¦),(——),row,col,vect,mat,linspace) | ||
34 | import qualified Numeric.HMatrix as LA | ||
35 | import Data.Proxy(Proxy) | ||
36 | import Numeric.LinearAlgebra.Static | ||
37 | |||
38 | |||
39 | |||
40 | instance forall n . KnownNat n => Show (C n) | ||
41 | where | ||
42 | show (ud1 -> v) | ||
43 | | size v == 1 = "("++show (v!0)++" :: C "++show d++")" | ||
44 | | otherwise = "(vect"++ drop 8 (show v)++" :: C "++show d++")" | ||
45 | where | ||
46 | d = fromIntegral . natVal $ (undefined :: Proxy n) :: Int | ||
47 | |||
48 | |||
49 | ud1 :: C n -> Vector ℂ | ||
50 | ud1 (C (Dim v)) = v | ||
51 | |||
52 | mkC :: Vector ℂ -> C n | ||
53 | mkC = C . Dim | ||
54 | |||
55 | |||
56 | infixl 4 & | ||
57 | (&) :: forall n . KnownNat n | ||
58 | => C n -> ℂ -> C (n+1) | ||
59 | u & x = u # (mkC (LA.scalar x) :: C 1) | ||
60 | |||
61 | infixl 4 # | ||
62 | (#) :: forall n m . (KnownNat n, KnownNat m) | ||
63 | => C n -> C m -> C (n+m) | ||
64 | (C u) # (C v) = C (vconcat u v) | ||
65 | |||
66 | |||
67 | |||
68 | vec2 :: ℂ -> ℂ -> C 2 | ||
69 | vec2 a b = C (gvec2 a b) | ||
70 | |||
71 | vec3 :: ℂ -> ℂ -> ℂ -> C 3 | ||
72 | vec3 a b c = C (gvec3 a b c) | ||
73 | |||
74 | |||
75 | vec4 :: ℂ -> ℂ -> ℂ -> ℂ -> C 4 | ||
76 | vec4 a b c d = C (gvec4 a b c d) | ||
77 | |||
78 | vect :: forall n . KnownNat n => [ℂ] -> C n | ||
79 | vect xs = C (gvect "C" xs) | ||
80 | |||