summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/base/hmatrix.cabal13
-rw-r--r--packages/base/src/Internal/Element.hs81
-rw-r--r--packages/base/src/Internal/Numeric.hs78
3 files changed, 86 insertions, 86 deletions
diff --git a/packages/base/hmatrix.cabal b/packages/base/hmatrix.cabal
index c573b49..a487928 100644
--- a/packages/base/hmatrix.cabal
+++ b/packages/base/hmatrix.cabal
@@ -41,15 +41,13 @@ library
41 41
42 hs-source-dirs: src 42 hs-source-dirs: src
43 43
44 exposed-modules: 44 exposed-modules: Numeric.LinearAlgebra
45 Numeric.LinearAlgebra
46 Numeric.LinearAlgebra.Devel 45 Numeric.LinearAlgebra.Devel
47 Numeric.LinearAlgebra.Data 46 Numeric.LinearAlgebra.Data
48 Numeric.LinearAlgebra.HMatrix 47 Numeric.LinearAlgebra.HMatrix
49 Numeric.LinearAlgebra.Static 48 Numeric.LinearAlgebra.Static
50 49
51 other-modules: 50 other-modules: Internal.Tools
52 Internal.Tools
53 Internal.Vector 51 Internal.Vector
54 Internal.Devel 52 Internal.Devel
55 Internal.Vectorized 53 Internal.Vectorized
@@ -67,14 +65,13 @@ library
67 Internal.Sparse 65 Internal.Sparse
68 Internal.Convolution 66 Internal.Convolution
69 Internal.Chain 67 Internal.Chain
68 Numeric.Vector
70 Internal.CG 69 Internal.CG
70 Numeric.Matrix
71 Internal.Util 71 Internal.Util
72 Internal.Modular 72 Internal.Modular
73 Internal.Static 73 Internal.Static
74 Numeric.Vector 74
75 Numeric.Matrix
76
77
78 C-sources: src/Internal/C/lapack-aux.c 75 C-sources: src/Internal/C/lapack-aux.c
79 src/Internal/C/vector-aux.c 76 src/Internal/C/vector-aux.c
80 77
diff --git a/packages/base/src/Internal/Element.hs b/packages/base/src/Internal/Element.hs
index 6fc2981..0f61370 100644
--- a/packages/base/src/Internal/Element.hs
+++ b/packages/base/src/Internal/Element.hs
@@ -24,9 +24,10 @@ module Internal.Element where
24import Internal.Tools 24import Internal.Tools
25import Internal.Vector 25import Internal.Vector
26import Internal.Matrix 26import Internal.Matrix
27import Internal.Vectorized
27import qualified Internal.ST as ST 28import qualified Internal.ST as ST
28import Data.Array 29import Data.Array
29 30import Text.Printf
30import Data.Vector.Storable(fromList) 31import Data.Vector.Storable(fromList)
31import Data.List(transpose,intersperse) 32import Data.List(transpose,intersperse)
32import Foreign.Storable(Storable) 33import Foreign.Storable(Storable)
@@ -78,7 +79,83 @@ instance (Element a, Read a) => Read (Matrix a) where
78breakAt c l = (a++[c],tail b) where 79breakAt c l = (a++[c],tail b) where
79 (a,b) = break (==c) l 80 (a,b) = break (==c) l
80 81
81------------------------------------------------------------------ 82--------------------------------------------------------------------------------
83
84data Extractor
85 = All
86 | Range Int Int Int
87 | Pos (Vector I)
88 | PosCyc (Vector I)
89 | Take Int
90 | TakeLast Int
91 | Drop Int
92 | DropLast Int
93 deriving Show
94
95
96--
97infixl 9 ??
98(??) :: Element t => Matrix t -> (Extractor,Extractor) -> Matrix t
99
100minEl = toScalarI Min
101maxEl = toScalarI Max
102cmodi = vectorMapValI ModVS
103
104extractError m e = error $ printf "can't extract %s from matrix %dx%d" (show e) (rows m) (cols m)
105
106m ?? (Range a s b,e) | s /= 1 = m ?? (Pos (idxs [a,a+s .. b]), e)
107m ?? (e,Range a s b) | s /= 1 = m ?? (e, Pos (idxs [a,a+s .. b]))
108
109m ?? e@(Range a _ b,_) | a < 0 || b >= rows m = extractError m e
110m ?? e@(_,Range a _ b) | a < 0 || b >= cols m = extractError m e
111
112m ?? e@(Pos vs,_) | dim vs>0 && (minEl vs < 0 || maxEl vs >= fi (rows m)) = extractError m e
113m ?? e@(_,Pos vs) | dim vs>0 && (minEl vs < 0 || maxEl vs >= fi (cols m)) = extractError m e
114
115m ?? (All,All) = m
116
117m ?? (Range a _ b,e) | a > b = m ?? (Take 0,e)
118m ?? (e,Range a _ b) | a > b = m ?? (e,Take 0)
119
120m ?? (Take n,e)
121 | n <= 0 = (0><cols m) [] ?? (All,e)
122 | n >= rows m = m ?? (All,e)
123
124m ?? (e,Take n)
125 | n <= 0 = (rows m><0) [] ?? (e,All)
126 | n >= cols m = m ?? (e,All)
127
128m ?? (Drop n,e)
129 | n <= 0 = m ?? (All,e)
130 | n >= rows m = (0><cols m) [] ?? (All,e)
131
132m ?? (e,Drop n)
133 | n <= 0 = m ?? (e,All)
134 | n >= cols m = (rows m><0) [] ?? (e,All)
135
136m ?? (TakeLast n, e) = m ?? (Drop (rows m - n), e)
137m ?? (e, TakeLast n) = m ?? (e, Drop (cols m - n))
138
139m ?? (DropLast n, e) = m ?? (Take (rows m - n), e)
140m ?? (e, DropLast n) = m ?? (e, Take (cols m - n))
141
142m ?? (er,ec) = extractR m moder rs modec cs
143 where
144 (moder,rs) = mkExt (rows m) er
145 (modec,cs) = mkExt (cols m) ec
146 ran a b = (0, idxs [a,b])
147 pos ks = (1, ks)
148 mkExt _ (Pos ks) = pos ks
149 mkExt n (PosCyc ks)
150 | n == 0 = mkExt n (Take 0)
151 | otherwise = pos (cmodi (fi n) ks)
152 mkExt _ (Range mn _ mx) = ran mn mx
153 mkExt _ (Take k) = ran 0 (k-1)
154 mkExt n (Drop k) = ran k (n-1)
155 mkExt n _ = ran 0 (n-1) -- All
156
157--------------------------------------------------------------------------------
158
82 159
83-- | creates a matrix from a vertical list of matrices 160-- | creates a matrix from a vertical list of matrices
84joinVert :: Element t => [Matrix t] -> Matrix t 161joinVert :: Element t => [Matrix t] -> Matrix t
diff --git a/packages/base/src/Internal/Numeric.hs b/packages/base/src/Internal/Numeric.hs
index 86a4a4c..af665a4 100644
--- a/packages/base/src/Internal/Numeric.hs
+++ b/packages/base/src/Internal/Numeric.hs
@@ -27,9 +27,8 @@ import Internal.Conversion
27import Internal.Vectorized 27import Internal.Vectorized
28import Internal.LAPACK(multiplyR,multiplyC,multiplyF,multiplyQ,multiplyI) 28import Internal.LAPACK(multiplyR,multiplyC,multiplyF,multiplyQ,multiplyI)
29import Data.Vector.Storable(fromList) 29import Data.Vector.Storable(fromList)
30import Text.Printf(printf)
31 30
32------------------------------------------------------------------- 31--------------------------------------------------------------------------------
33 32
34type family IndexOf (c :: * -> *) 33type family IndexOf (c :: * -> *)
35 34
@@ -41,80 +40,7 @@ type family ArgOf (c :: * -> *) a
41type instance ArgOf Vector a = a -> a 40type instance ArgOf Vector a = a -> a
42type instance ArgOf Matrix a = a -> a -> a 41type instance ArgOf Matrix a = a -> a -> a
43 42
44-------------------------------------------------------------------------- 43--------------------------------------------------------------------------------
45
46data Extractor
47 = All
48 | Range Int Int Int
49 | Pos (Vector I)
50 | PosCyc (Vector I)
51 | Take Int
52 | TakeLast Int
53 | Drop Int
54 | DropLast Int
55 deriving Show
56
57
58--
59infixl 9 ??
60(??) :: Element t => Matrix t -> (Extractor,Extractor) -> Matrix t
61
62
63extractError m e = error $ printf "can't extract %s from matrix %dx%d" (show e) (rows m) (cols m)
64
65m ?? (Range a s b,e) | s /= 1 = m ?? (Pos (idxs [a,a+s .. b]), e)
66m ?? (e,Range a s b) | s /= 1 = m ?? (e, Pos (idxs [a,a+s .. b]))
67
68m ?? e@(Range a _ b,_) | a < 0 || b >= rows m = extractError m e
69m ?? e@(_,Range a _ b) | a < 0 || b >= cols m = extractError m e
70
71m ?? e@(Pos vs,_) | minElement vs < 0 || maxElement vs >= fromIntegral (rows m) = extractError m e
72m ?? e@(_,Pos vs) | minElement vs < 0 || maxElement vs >= fromIntegral (cols m) = extractError m e
73
74m ?? (All,All) = m
75
76m ?? (Range a _ b,e) | a > b = m ?? (Take 0,e)
77m ?? (e,Range a _ b) | a > b = m ?? (e,Take 0)
78
79m ?? (Take n,e)
80 | n <= 0 = (0><cols m) [] ?? (All,e)
81 | n >= rows m = m ?? (All,e)
82
83m ?? (e,Take n)
84 | n <= 0 = (rows m><0) [] ?? (e,All)
85 | n >= cols m = m ?? (e,All)
86
87m ?? (Drop n,e)
88 | n <= 0 = m ?? (All,e)
89 | n >= rows m = (0><cols m) [] ?? (All,e)
90
91m ?? (e,Drop n)
92 | n <= 0 = m ?? (e,All)
93 | n >= cols m = (rows m><0) [] ?? (e,All)
94
95m ?? (TakeLast n, e) = m ?? (Drop (rows m - n), e)
96m ?? (e, TakeLast n) = m ?? (e, Drop (cols m - n))
97
98m ?? (DropLast n, e) = m ?? (Take (rows m - n), e)
99m ?? (e, DropLast n) = m ?? (e, Take (cols m - n))
100
101m ?? (er,ec) = extractR m moder rs modec cs
102 where
103 (moder,rs) = mkExt (rows m) er
104 (modec,cs) = mkExt (cols m) ec
105 ran a b = (0, idxs [a,b])
106 pos ks = (1, ks)
107 mkExt _ (Pos ks) = pos ks
108 mkExt n (PosCyc ks)
109 | n == 0 = mkExt n (Take 0)
110 | otherwise = pos (cmod n ks)
111 mkExt _ (Range mn _ mx) = ran mn mx
112 mkExt _ (Take k) = ran 0 (k-1)
113 mkExt n (Drop k) = ran k (n-1)
114 mkExt n _ = ran 0 (n-1) -- All
115
116-------------------------------------------------------------------
117
118 44
119-- | Basic element-by-element functions for numeric containers 45-- | Basic element-by-element functions for numeric containers
120class Element e => Container c e 46class Element e => Container c e