Aelve Codesearch

grep over package repositories
Please provide a string to search for.
3+ characters are required.
Index updated 5 hours ago

total matches: 231

OrderedBits-0.0.1.2
3 matches
Data/Bits/Ordered.hs
-- | A stream with the currently active bits, lowest to highest.

activeBitsS :: (Ranked t, Monad m) => t -> SM.Stream m Int
activeBitsS t = SM.unfoldr (fmap (id &&& (`maybeNextActive` t))) (maybeLsb t)
{-# Inline activeBitsS #-}

-- * Population count methods

-- | The /slow/ default implementation. We sort the vector, not the list,

            
Data/Bits/Ordered.hs
-- | Memoizes popcount arrays. The limit to memoization is enforced by
-- popCntMemo, not here.

_popCntMemoInt = map popCntSorted [0..]
{-# NoInline _popCntMemoInt #-}

-- | Memoized version of 'popCntSorted' for @Word@s.
--
-- NOTE Since this uses @popCntSorted@ for now it will still require a lot

            
Data/Bits/Ordered.hs
-- | Memoizes popcount arrays. The limit to memoization is enforced by
-- popCntMemo, not here.

_popCntMemoWord = map popCntSorted [0..]
{-# NoInline _popCntMemoWord #-}

-- | Enumerate all sets with the same population count. Given a population
-- @i@, this returns @Just j@ with @j>i@ (but same number of set bits) or
-- @Nothing@. For a population count of @k@, start with @2^(k+1) -1@.

            
dense-0.1.0.0
7 matches
src/Data/Dense/Generic.hs
  , accum

  -- ** Mapping
  , map
  , imap

  -- * Zipping
  -- ** Tuples
  , Data.Dense.Generic.zip
  , Data.Dense.Generic.zip3

            
src/Data/Dense/Generic.hs

import           Control.Comonad
import           Control.Comonad.Store
import           Control.Lens                      hiding (imap)
import           Control.Monad                     (liftM)
import           Control.Monad.Primitive
import           Control.Monad.ST
import qualified Data.Foldable                     as F
import           Data.Functor.Classes

            
src/Data/Dense/Generic.hs
import           Data.Dense.Mutable               (MArray (..))
import qualified Data.Dense.Mutable               as M

import           Prelude                           hiding (map, null, replicate,
                                                    zipWith, zipWith3)

-- Aliases -------------------------------------------------------------

-- | 'Boxed' array.

            
src/Data/Dense/Generic.hs
-- Modifying -----------------------------------------------------------

-- | /O(n)/ Map a function over an array
map :: (Vector v a, Vector v b) => (a -> b) -> Array v f a -> Array v f b
map f (Array l a) = Array l (G.map f a)
{-# INLINE map #-}

-- | /O(n)/ Apply a function to every element of a vector and its index
imap :: (Shape f, Vector v a, Vector v b) => (f Int -> a -> b) -> Array v f a -> Array v f b
imap f (Array l v) =
  Array l $ (G.unstream . Bundle.inplace (Stream.zipWith f (streamIndexes l)) id . G.stream) v
{-# INLINE imap #-}

-- Bulk updates --------------------------------------------------------

-- | For each pair (i,a) from the list, replace the array element at
--   position i by a.

            
src/Data/Dense/Generic.hs
      -> Array v f a    -- ^ initial array
      -> [(f Int, b)]   -- ^ list of index/value pairs (of length @n@)
      -> Array v f a
accum f (Array l v) us = Array l $ G.accum f v (over (mapped . _1) (shapeToIndex l) us)
{-# INLINE accum #-}

------------------------------------------------------------------------
-- Streams
------------------------------------------------------------------------

            
src/Data/Dense/Generic.hs
    F.for_ [0..x'-1] $ \i ->
      GM.write mv (i*y + j) (v G.! i)
  return mv
  where x' = minimum $ fmap G.length vs
{-# INLINE transposeConcat #-}

-- | Traversal over a single plane of a 3D array given a lens onto that
--   plane (like '_xy', '_yz', '_zx').
ixPlane :: Vector v a

            
src/Data/Dense/Generic.hs
{-# INLINE [0] unsafeOrdinals #-}

setOrdinals :: (Indexable (f Int) p, Vector v a, Shape f) => [f Int] -> p a a -> Array v f a -> Array v f a
setOrdinals is f (Array l v) = Array l $ G.unsafeUpd v (fmap g is)
  where g x = let i = shapeToIndex l x in (,) i $ indexed f x (G.unsafeIndex v i)
{-# INLINE setOrdinals #-}

{-# RULES
"unsafeOrdinals/setOrdinals" forall (is :: [f Int]).

            
inline-r-0.10.2
8 matches
src/Data/Vector/SEXP.hs
  -- * Elementwise operations

  -- ** Mapping
  , map
  , imap
  , concatMap

  -- ** Monadic mapping
  , mapM
  , mapM_
  , forM
  , forM_

  -- ** Zipping
  , zipWith

            
src/Data/Vector/SEXP.hs
-- | /O(n)/ Concatenate all vectors in the list
concat :: SVECTOR ty a => [Vector ty a] -> Vector ty a
{-# INLINE concat #-}
concat vs = phony $ \p -> unW $ G.concat $ Prelude.map (withW p) vs

-- Monadic initialisation
-- ----------------------

-- | /O(n)/ Execute the monadic action the given number of times and store the

            
src/Data/Vector/SEXP.hs

{-
-- | /O(n)/ Yield the vector obtained by replacing each element @i@ of the
-- index Vector s ty by @xs'!'i@. This is equivalent to @'map' (xs'!') is@ but is
-- often much more efficient.
--
-- > backpermute <a,b,c,d> <0,3,2,3,1,0> = <a,d,c,d,b,a>
backpermute :: VECTOR s ty a => Vector s ty a -> Vector Int -> Vector s ty a
{-# INLINE backpermute #-}

            
src/Data/Vector/SEXP.hs
-- -------

-- | /O(n)/ Map a function over a vector
map :: (SVECTOR ty a, SVECTOR ty b) => (a -> b) -> Vector ty a -> Vector ty b
{-# INLINE map #-}
map f v = phony $ unW . proxyFW (G.map f) v

-- | /O(n)/ Apply a function to every element of a Vector ty and its index
imap :: (SVECTOR ty a, SVECTOR ty b) => (Int -> a -> b) -> Vector ty a -> Vector ty b
{-# INLINE imap #-}
imap f v = phony $ unW . proxyFW (G.imap f) v


-- | Map a function over a Vector ty and concatenate the results.
concatMap :: (SVECTOR tya a, SVECTOR tyb b)
          => (a -> Vector tyb b)

            
src/Data/Vector/SEXP.hs
    withW p v
#endif

-- Monadic mapping
-- ---------------

-- | /O(n)/ Apply the monadic action to all elements of the vector, yielding a
-- vector of results
mapM :: (Monad m, SVECTOR ty a, SVECTOR ty b) => (a -> m b) -> Vector ty a -> m (Vector ty b)

            
src/Data/Vector/SEXP.hs

-- | /O(n)/ Apply the monadic action to all elements of the vector, yielding a
-- vector of results
mapM :: (Monad m, SVECTOR ty a, SVECTOR ty b) => (a -> m b) -> Vector ty a -> m (Vector ty b)
{-# INLINE mapM #-}
mapM f v = phony $ \p -> unW <$> proxyFW (G.mapM f) v p

-- | /O(n)/ Apply the monadic action to all elements of a Vector ty and ignore the
-- results
mapM_ :: (Monad m, SVECTOR ty a) => (a -> m b) -> Vector ty a -> m ()
{-# INLINE mapM_ #-}
mapM_ f v = phony $ proxyFW (G.mapM_ f) v

-- | /O(n)/ Apply the monadic action to all elements of the vector, yielding a
-- vector of results. Equvalent to @flip 'mapM'@.
forM :: (Monad m, SVECTOR ty a, SVECTOR ty b) => Vector ty a -> (a -> m b) -> m (Vector ty b)
{-# INLINE forM #-}
forM v f = phony $ \p -> unW <$> proxyFW (`G.forM` f) v p

-- | /O(n)/ Apply the monadic action to all elements of a Vector ty and ignore the

            
src/Data/Vector/SEXP.hs
forM v f = phony $ \p -> unW <$> proxyFW (`G.forM` f) v p

-- | /O(n)/ Apply the monadic action to all elements of a Vector ty and ignore the
-- results. Equivalent to @flip 'mapM_'@.
forM_ :: (Monad m, SVECTOR ty a) => Vector ty a -> (a -> m b) -> m ()
{-# INLINE forM_ #-}
forM_ v f = phony $ proxyFW (`G.forM_` f) v

-- Zipping

            
src/Data/Vector/SEXP.hs
    let xs' = lift $ G.stream (withW p xs)
        ys' = lift $ G.stream (withW p ys)
        sz  = smaller (sSize xs') (sSize ys')
    in proxyW <$> Prelude.fmap G.unstream (Bundle.unsafeFromList sz <$> Stream.toList (Stream.zipWithM f (sElems xs') (sElems ys')))
              <*> pure p
#else
zipWithM f xs ys = phony $ \p ->
    proxyW <$>
    unstreamM (Stream.zipWithM f (G.stream (withW p xs)) (G.stream (withW p ys))) <*>

            
massiv-0.4.3.0
9 matches
src/Data/Massiv/Array/Manifest/Vector/Stream.hs
  , take
  , slice
  , traverse
  , mapM
  , concatMap
  , append
  , zipWith
  , zipWithM
  -- ** Folding

            
src/Data/Massiv/Array/Manifest/Vector/Stream.hs
  , fromList
  , fromListN
  -- ** Filter
  , mapMaybe
  , mapMaybeA
  , mapMaybeM
  , filter
  , filterA
  , filterM
  , transStepsId
  -- * Useful re-exports

            
src/Data/Massiv/Array/Manifest/Vector/Stream.hs
import Data.Vector.Fusion.Bundle.Size
import qualified Data.Vector.Fusion.Stream.Monadic as S
import Data.Vector.Fusion.Util
import Prelude hiding (zipWith, mapM, traverse, length, foldl, foldr, filter, concatMap, drop, take)




-- TODO: benchmark: `fmap snd . isteps`

            
src/Data/Massiv/Array/Manifest/Vector/Stream.hs



-- TODO: benchmark: `fmap snd . isteps`
steps :: forall r ix e m . (Monad m, Source r ix e) => Array r ix e -> Steps m e
steps arr = k `seq` arr `seq` Steps (S.Stream step 0) (Exact k)
  where
    k = totalElem $ size arr
    step i

            
src/Data/Massiv/Array/Manifest/Vector/Stream.hs
uncons :: Monad m => Steps m e -> m (Maybe (e, Steps m e))
uncons sts@(Steps str _) = do
  mx <- str S.!? 0
  pure $ fmap (, drop 1 sts) mx
{-# INLINE uncons #-}

snoc :: Monad m => Steps m e -> e -> Steps m e
snoc (Steps str k) e = Steps (S.snoc str e) (k + 1)
{-# INLINE snoc #-}

            
src/Data/Massiv/Array/Manifest/Vector/Stream.hs
append (Steps str1 k1) (Steps str2 k2) = Steps (str1 S.++ str2) (k1 + k2)
{-# INLINE append #-}

mapM :: Monad m => (e -> m a) -> Steps m e -> Steps m a
mapM f (Steps str k) = Steps (S.mapM f str) k
{-# INLINE mapM #-}

zipWith :: Monad m => (a -> b -> e) -> Steps m a -> Steps m b -> Steps m e
zipWith f (Steps str1 k1) (Steps str2 k2) = Steps (S.zipWith f str1 str2) (smaller k1 k2)
{-# INLINE zipWith #-}


            
src/Data/Massiv/Array/Manifest/Vector/Stream.hs
{-# INLINE foldrM #-}


mapMaybe :: Monad m => (a -> Maybe e) -> Steps m a -> Steps m e
mapMaybe f (Steps str k) = Steps (S.mapMaybe f str) (toMax k)
{-# INLINE mapMaybe #-}

concatMap :: Monad m => (a -> Steps m e) -> Steps m a -> Steps m e
concatMap f (Steps str _) = Steps (S.concatMap (stepsStream . f) str) Unknown
{-# INLINE concatMap #-}


            
src/Data/Massiv/Array/Manifest/Vector/Stream.hs
{-# INLINE concatMap #-}


mapMaybeA :: (Monad m, Applicative f) => (a -> f (Maybe e)) -> Steps Id a -> f (Steps m e)
mapMaybeA f (Steps str k) = (`Steps` toMax k) <$> liftListA (mapMaybeListA f) str
{-# INLINE mapMaybeA #-}

mapMaybeM :: Monad m => (a -> m (Maybe b)) -> Steps m a -> Steps m b
mapMaybeM f (Steps str k) = Steps (mapMaybeStreamM f str) (toMax k)
{-# INLINE mapMaybeM #-}

mapMaybeListA :: Applicative f => (a -> f (Maybe b)) -> [a] -> f [b]
mapMaybeListA f = fmap catMaybes . Traversable.traverse f
{-# INLINE mapMaybeListA #-}

mapMaybeStreamM :: Monad m => (a -> m (Maybe b)) -> S.Stream m a -> S.Stream m b
mapMaybeStreamM f (S.Stream step t) = S.Stream step' t
  where
    step' s = do
      r <- step s
      case r of
        S.Yield x s' -> do

            
src/Data/Massiv/Array/Manifest/Vector/Stream.hs
        S.Skip s' -> return $ S.Skip s'
        S.Done -> return S.Done
    {-# INLINE step' #-}
{-# INLINE mapMaybeStreamM #-}

filter :: Monad m => (a -> Bool) -> Steps m a -> Steps m a
filter f (Steps str k) = Steps (S.filter f str) (toMax k)
{-# INLINE filter #-}


            
neural-network-hmatrix-0.1.0.0
3 matches
Data/NeuralNetwork/Backend/HMatrix/Utils.hs
import System.IO.Unsafe ( unsafePerformIO )

-- fft2d :: Matrix (Complex Double) -> Matrix (Complex Double)
-- fft2d m = let !x = fromRows $ map fft $ unsafeToRows m
--               !y = fromColumns $ map fft $ toColumns x
--           in y
-- ifft2d :: Matrix (Complex Double) -> Matrix (Complex Double)
-- ifft2d m = let !x = fromRows $ map ifft $ unsafeToRows m
--                !y = fromColumns $ map ifft $ toColumns x
--            in y

-- fft2d :: Matrix (Complex Double) -> Matrix (Complex Double)
-- fft2d m = let rh:rr = map fft $ force $ toRows m
--               x = fromRows $ withStrategy (parList rdeepseq) rr `pseq` (rh : rr)
--               sh:ss = map fft $ force $ toColumns x
--               y = fromColumns $ withStrategy (parList rdeepseq) ss `pseq` (sh : ss)
--           in y
--
-- ifft2d :: Matrix (Complex Double) -> Matrix (Complex Double)
-- ifft2d m = let rh:rr = map fft $ force $ toRows m

            
Data/NeuralNetwork/Backend/HMatrix/Utils.hs
--           in y
--
-- ifft2d :: Matrix (Complex Double) -> Matrix (Complex Double)
-- ifft2d m = let rh:rr = map fft $ force $ toRows m
--                x = fromRows $ withStrategy (parList rdeepseq) rr `pseq` (rh : rr)
--                sh:ss = map fft $ force $ toColumns x
--                y = fromColumns $ withStrategy (parList rdeepseq) ss `pseq` (sh : ss)
--            in y

-- conv2d_b :: (Numeric t, ConvFD t, Container Vector t, Container Matrix t)
--          => Matrix t -> Matrix t -> Matrix t

            
Data/NeuralNetwork/Backend/HMatrix/Utils.hs
--     (w,h) = size k
--     (s,t) = size m
--     (u,v) = (s-w+1, t-h+1)
--     subs  = map (\s->subMatrix s (w,h) m) $ [(x,y) | x<-[0..u-1], y<-[0..v-1]]
--     -- use unsafe* methods to create the intermediate matrix fast.
--     t_rows = u*v
--     t_cols = w*h
--     !transformed = matrixFromVector RowMajor t_rows t_cols $ VecS.create $ do
--         mat <- VecM.new (t_rows*t_cols)