11 Nov 2012 00:01
[repa] beginner questions
Dmitry Malikov <malikov.d.y <at> gmail.com>
2012-11-10 23:01:48 GMT
2012-11-10 23:01:48 GMT
Playing around with repa arrays and got some questions.
1) How I can get list of indexes of array that suffice some predicate?
> a1
AUnboxed (Z :. 3) (fromList [False,False,True])
it :: Array U (Z :. Int) Bool
Indexes of element that satisfying specific predicate could be obtained
like that:
> (\a p → Data.List.map (subtract 1 . snd) $ filter (p . fst) $ zip
(toList a) [1..]) a1 (== False)
[0,1]
Looks ugly. How REPA users used to do filtering like that without
converting to list?
2) How can I apply some function `f' to each row of 2D array `a' and
collect results in single value?
f ∷ (Shape sh, Source r Bool) ⇒ Array r sh Bool → Bool
f a = (== toList a) $
foldl1 (Prelude.zipWith (||)) $
Prelude.map toList $
foldl (\l k -> filter (\x -> x ! (Z :. k) == False) l)
[b1,b2,b3,b4] $
findWhich (== False) a
and ∷ [Bool] → Bool
(Continue reading)
RSS Feed