module Data.Repa.Array.Generic
( Name
, Bulk (..), BulkI
, (!)
, length
, first, last
, Load
, Target, TargetI
, computeS, computeIntoS
, empty
, singleton
, generateMaybeS, mapMaybeS
, generateEitherS, mapEitherS
, fromList, fromListInto
, toList
, convert, copy
, replicates
, mapS, map2S
, merge
, mergeMaybe
, compact
, compactIn
, process
, unfolds
, StepUnfold (..)
, filter
, insert
, findIndex
, concat
, concatWith, unlines
, intercalate
, ConcatDict
, groups
, groupsWith
, GroupsDict
, foldl, sum, product, mean, std
, correlate
, folds
, foldsWith
, Folds(..)
, FoldsDict)
where
import Data.Repa.Array.Generic.Load as A
import Data.Repa.Array.Generic.Index as A
import Data.Repa.Array.Meta as A
import Data.Repa.Array.Internals.Bulk as A
import Data.Repa.Array.Internals.Target as A
import Data.Repa.Array.Internals.Operator.Concat as A
import Data.Repa.Array.Internals.Operator.Compact as A
import Data.Repa.Array.Internals.Operator.Filter as A
import Data.Repa.Array.Internals.Operator.Fold as A
import Data.Repa.Array.Internals.Operator.Group as A
import Data.Repa.Array.Internals.Operator.Insert as A
import Data.Repa.Array.Internals.Operator.Merge as A
import Data.Repa.Array.Internals.Operator.Process as A
import Data.Repa.Array.Internals.Operator.Reduce as A
import Data.Repa.Array.Internals.Operator.Replicate as A
import qualified Data.Repa.Array.Generic.Convert as A
import qualified Data.Vector.Fusion.Stream.Monadic as V
import Control.Monad
import Prelude
hiding ( reverse, length, map, zipWith, concat, unlines
, foldl, sum, product, last
, filter)
#include "repa-array.h"
findIndex :: BulkI l a
=> (a -> Bool) -> Array l a -> Maybe Int
findIndex p !arr
= loop_findIndex V.SPEC 0
where
!len = size (extent $ layout arr)
loop_findIndex !sPEC !ix
| ix >= len = Nothing
| otherwise
= let !x = arr `index` ix
in if p x then Just ix
else loop_findIndex sPEC (ix + 1)
mapS :: (Bulk lSrc a, Target lDst b, Index lSrc ~ Index lDst)
=> Name lDst
-> (a -> b)
-> Array lSrc a
-> Array lDst b
mapS l f !xs = computeS l $! map f xs
map2S :: (Bulk lSrc1 a, Bulk lSrc2 b, Target lDst c
, Index lSrc1 ~ Index lDst
, Index lSrc2 ~ Index lDst)
=> Name lDst
-> (a -> b -> c )
-> Array lSrc1 a
-> Array lSrc2 b
-> Maybe (Array lDst c)
map2S l f xs ys
= liftM (computeS l) $! map2 f xs ys
convert :: A.Convert l1 a1 l2 a2
=> Name l2 -> Array l1 a1 -> Array l2 a2
convert _ = A.convert
copy :: (Bulk l1 a, Target l2 a, Index l1 ~ Index l2)
=> Name l2 -> Array l1 a -> Array l2 a
copy n2 arr = computeS n2 $! delay arr