diff options
author | Alberto Ruiz <aruiz@um.es> | 2011-01-08 18:52:36 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2011-01-08 18:52:36 +0000 |
commit | 920241f2ebcdafae6814e4d8817c4859df13db55 (patch) | |
tree | 194f5e9c4676fe8861239b01448a953a9bfd7231 /lib/Numeric | |
parent | 9fc924dc107cd619c60a421d288dafb92f417b8c (diff) |
documentation
Diffstat (limited to 'lib/Numeric')
-rw-r--r-- | lib/Numeric/ContainerBoot.hs | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/lib/Numeric/ContainerBoot.hs b/lib/Numeric/ContainerBoot.hs index 250d4c5..fd94e06 100644 --- a/lib/Numeric/ContainerBoot.hs +++ b/lib/Numeric/ContainerBoot.hs | |||
@@ -121,10 +121,24 @@ class (Complexable c, Fractional e, Element e) => Container c e where | |||
121 | sumElements :: c e -> e | 121 | sumElements :: c e -> e |
122 | -- | the product of elements (faster than using @fold@) | 122 | -- | the product of elements (faster than using @fold@) |
123 | prodElements :: c e -> e | 123 | prodElements :: c e -> e |
124 | -- | a more efficient implementation of @cmap (\\x -> if x>0 then 1 else 0)@ | 124 | |
125 | -- | A more efficient implementation of @cmap (\\x -> if x>0 then 1 else 0)@ | ||
126 | -- | ||
127 | -- @> step $ linspace 5 (-1,1::Double) | ||
128 | -- 5 |> [0.0,0.0,0.0,1.0,1.0]@ | ||
129 | |||
125 | step :: RealElement e => c e -> c e | 130 | step :: RealElement e => c e -> c e |
126 | 131 | ||
127 | -- | element by element @case compare a b of LT -> l, EQ -> e, GT -> g@ | 132 | -- | Element by element version of @case compare a b of {LT -> l; EQ -> e; GT -> g}@. |
133 | -- | ||
134 | -- Arguments with any dimension = 1 are automatically expanded: | ||
135 | -- | ||
136 | -- @> cond ((1>\<4)[1..]) ((3>\<1)[1..]) 0 100 ((3>\<4)[1..]) :: Matrix Double | ||
137 | -- (3><4) | ||
138 | -- [ 100.0, 2.0, 3.0, 4.0 | ||
139 | -- , 0.0, 100.0, 7.0, 8.0 | ||
140 | -- , 0.0, 0.0, 100.0, 12.0 ]@ | ||
141 | |||
128 | cond :: RealElement e | 142 | cond :: RealElement e |
129 | => c e -- ^ a | 143 | => c e -- ^ a |
130 | -> c e -- ^ b | 144 | -> c e -- ^ b |
@@ -133,16 +147,33 @@ class (Complexable c, Fractional e, Element e) => Container c e where | |||
133 | -> c e -- ^ g | 147 | -> c e -- ^ g |
134 | -> c e -- ^ result | 148 | -> c e -- ^ result |
135 | 149 | ||
136 | -- | find index of elements which satisfy a predicate | 150 | -- | Find index of elements which satisfy a predicate |
151 | -- | ||
152 | -- @> find (>0) (ident 3 :: Matrix Double) | ||
153 | -- [(0,0),(1,1),(2,2)]@ | ||
154 | |||
137 | find :: (e -> Bool) -> c e -> [IndexOf c] | 155 | find :: (e -> Bool) -> c e -> [IndexOf c] |
138 | 156 | ||
139 | -- | create a structure from an association list | 157 | -- | Create a structure from an association list |
158 | -- | ||
159 | -- @> assoc 5 0 [(2,7),(1,3)] :: Vector Double | ||
160 | -- 5 |> [0.0,3.0,7.0,0.0,0.0]@ | ||
161 | |||
140 | assoc :: IndexOf c -- ^ size | 162 | assoc :: IndexOf c -- ^ size |
141 | -> e -- ^ default value | 163 | -> e -- ^ default value |
142 | -> [(IndexOf c, e)] -- ^ association list | 164 | -> [(IndexOf c, e)] -- ^ association list |
143 | -> c e -- ^ result | 165 | -> c e -- ^ result |
144 | 166 | ||
145 | -- | modify a structure using an update function | 167 | -- | Modify a structure using an update function |
168 | -- | ||
169 | -- @> accum (ident 5) (+) [((1,1),5),((0,3),3)] :: Matrix Double | ||
170 | -- (5><5) | ||
171 | -- [ 1.0, 0.0, 0.0, 3.0, 0.0 | ||
172 | -- , 0.0, 6.0, 0.0, 0.0, 0.0 | ||
173 | -- , 0.0, 0.0, 1.0, 0.0, 0.0 | ||
174 | -- , 0.0, 0.0, 0.0, 1.0, 0.0 | ||
175 | -- , 0.0, 0.0, 0.0, 0.0, 1.0 ]@ | ||
176 | |||
146 | accum :: c e -- ^ initial structure | 177 | accum :: c e -- ^ initial structure |
147 | -> (e -> e -> e) -- ^ update function | 178 | -> (e -> e -> e) -- ^ update function |
148 | -> [(IndexOf c, e)] -- ^ association list | 179 | -> [(IndexOf c, e)] -- ^ association list |