Aelve Codesearch

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

total matches: 326

battleship-combinatorics-0.0.0.2
8 matches
src/Combinatorics/Battleship/Count/Frontier.hs
   reverse, Reverse,
   foldMap,
   toList,
   mapToVector,

   fromList,
   fromString,

   propDilate,

            
src/Combinatorics/Battleship/Count/Frontier.hs
import Data.Word (Word32, Word64, )
import Data.Char (ord, chr, )

import Data.Monoid (Monoid, mempty, mappend, )
import Data.Function.HT (nest, )
import Data.Bool.HT (if', )

import qualified Test.QuickCheck as QC


            
src/Combinatorics/Battleship/Count/Frontier.hs
fromList =
   Cons . foldl (.|.) 0 .
   zipWith (\pos x -> shiftL x (pos*bitsPerNumber)) [0..] .
   map bitsFromUse

fromString :: String -> T w
fromString =
   fromList . map useFromChar

sizeOf :: (Nat w) => T w -> Size w
sizeOf _ = Size.size

lookup :: (Nat w) => T w -> Position -> Use

            
src/Combinatorics/Battleship/Count/Frontier.hs
propDilateTyped size frontier =
   dilateComb size frontier == dilateGen size frontier

mapToVector ::
   (Nat w, Storable a) => Size w -> (Use -> a) -> T w -> SV.Vector a
mapToVector (Size size) f frontier =
   SV.sample size $ f . lookup frontier

_mapToVector ::
   (Nat w, Storable a) => Size w -> (Use -> a) -> T w -> SV.Vector a
_mapToVector (Size size) f =
   SV.concat . SVL.chunks .
   SVBuilder.toLazyStorableVector (SVL.chunkSize size) .
   foldMap (SVBuilder.put . f)



            
src/Combinatorics/Battleship/Count/Frontier.hs
   let go m bits =
         if bits==0
           then m
           else go (mappend m (f $ useFromBits $ bits .&. mask)) $
                shiftR bits bitsPerNumber
   in  go mempty . decons

toListWithSize :: (Nat w) => Size w -> T w -> [Use]
toListWithSize (Size width) frontier = map (lookup frontier) $ take width [0 ..]

            
src/Combinatorics/Battleship/Count/Frontier.hs
   in  go mempty . decons

toListWithSize :: (Nat w) => Size w -> T w -> [Use]
toListWithSize (Size width) frontier = map (lookup frontier) $ take width [0 ..]

toList :: (Nat w) => T w -> [Use]
toList = toListWithSize Size.size

charFromUse :: Use -> Char

            
src/Combinatorics/Battleship/Count/Frontier.hs
            (error $ "charFromUse: illegal vertical number " ++ show n)

toString :: (Nat w) => T w -> String
toString = map charFromUse . toList


newtype Reverse w = Reverse {runReverse :: T w -> T w}
newtype Reverse1 w = Reverse1 {runReverse1 :: T (Size.P1 w) -> T (Size.P1 w)}
newtype Reverse2 w = Reverse2 {runReverse2 :: T (Size.P2 w) -> T (Size.P2 w)}

            
src/Combinatorics/Battleship/Count/Frontier.hs

instance (Nat w) => QC.Arbitrary (T w) where
   arbitrary = cons Size.size <$> QC.choose (minBound, maxBound)
   shrink = map (cons Size.size) . QC.shrink . decons

propReverse4 :: T N4 -> Bool
propReverse4 frontier =
   reverseGen Size.size frontier == reverse4spread frontier


            
comfort-array-0.4
6 matches
src/Data/Array/Comfort/Storable.hs
   Array,
   shape,
   reshape,
   mapShape,

   (!),
   Array.toList,
   Array.vectorFromList,
   toAssociations,

            
src/Data/Array/Comfort/Storable.hs
   fromBoxed,
   toBoxed,

   Array.map,
   Array.mapWithIndex,
   zipWith,
   (//),
   accumulate,
   fromAssociations,


            
src/Data/Array/Comfort/Storable.hs
import Data.Semigroup
         (Semigroup, (<>), Min(Min,getMin), Max(Max,getMax), Arg(Arg))

import Prelude2010 hiding (map, zipWith, foldl1, minimum, maximum)
import Prelude ()


shape :: Array sh a -> sh
shape = Array.shape

            
src/Data/Array/Comfort/Storable.hs
reshape :: (Shape.C sh0, Shape.C sh1) => sh1 -> Array sh0 a -> Array sh1 a
reshape = Check.reshape "Storable" shape Array.reshape

mapShape ::
   (Shape.C sh0, Shape.C sh1) => (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
mapShape f arr = reshape (f $ shape arr) arr


fromList :: (Shape.C sh, Storable a) => sh -> [a] -> Array sh a
fromList sh arr = runST (MutArrayNC.unsafeFreeze =<< MutArray.fromList sh arr)


            
src/Data/Array/Comfort/Storable.hs

sample ::
   (Shape.Indexed sh, Storable a) => sh -> (Shape.Index sh -> a) -> Array sh a
sample sh f = Array.fromList sh $ List.map f $ Shape.indices sh


fromBoxed :: (Shape.C sh, Storable a) => BoxedArray.Array sh a -> Array sh a
fromBoxed arr = Array.fromList (BoxedArray.shape arr) $ BoxedArray.toList arr


            
src/Data/Array/Comfort/Storable.hs
> limits x = (minimum x, maximum x)
-}
limits :: (Shape.C sh, Storable a, Ord a) => Array sh a -> (a,a)
limits = StrictTuple.mapPair (getMin, getMax) . foldMap (\x -> (Min x, Max x))

{-# INLINE foldMap #-}
foldMap ::
   (Shape.C sh, Storable a, Ord a, Semigroup m) => (a -> m) -> Array sh a -> m
foldMap f (Array sh x) = unsafePerformIO $

            
hmm-lapack-0.4
14 matches
src/Math/HiddenMarkovModel/Distribution.hs
      T typ sh prob -> Shape.Index sh -> MS.State g (Emission typ prob)

class EmissionProb typ where
   mapStatesShape ::
      (Shape.C sh0, Shape.C sh1) =>
      (sh0 -> sh1) -> T typ sh0 prob -> T typ sh1 prob
   {-
   This function could be implemented generically in terms of emissionStateProb
   but that would require an Info constraint.

            
src/Math/HiddenMarkovModel/Distribution.hs
instance (P.Show symbol, Ord symbol) => Format (Discrete symbol) where
   format fmt (Discrete m) =
      Output.formatAligned $
      map (\(sym,v) ->
            map (Identity . Output.text) $
            (show sym ++ ":") : map (printFmt fmt) (Vector.toList v)) $
      Array.toAssociations $ Matrix.toRowArray m

-- cf. Data.Bifunctor.Flip
newtype Flip f b a = Flip {getFlip :: f a b}


            
src/Math/HiddenMarkovModel/Distribution.hs
      randomItemProp . StorableArray.toAssociations . Matrix.takeColumn m

instance (Ord symbol) => EmissionProb (Discrete symbol) where
   mapStatesShape f (Discrete m) = Discrete $ Matrix.mapWidth f m
   emissionProb (Discrete m) = Matrix.takeRow m
   emissionStateProb (Discrete m) x s = m #! (x,s)

instance (Ord symbol) => Estimate (Discrete symbol) where
   accumulateEmissions sh =

            
src/Math/HiddenMarkovModel/Distribution.hs
instance (Ord symbol) => Estimate (Discrete symbol) where
   accumulateEmissions sh =
      DiscreteTrained .
      NonEmptyMap.map
         (StorableArray.reshape sh .
          StorableArray.fromAssociations 0 (Shape.Deferred sh) .
          Map.toList) .
      NonEmptyMap.fromListWith (Map.unionWith (+)) .
      fmap (\(state,sym) -> (sym, Map.singleton (Shape.deferIndex sh state) 1))

            
src/Math/HiddenMarkovModel/Distribution.hs
          StorableArray.fromAssociations 0 (Shape.Deferred sh) .
          Map.toList) .
      NonEmptyMap.fromListWith (Map.unionWith (+)) .
      fmap (\(state,sym) -> (sym, Map.singleton (Shape.deferIndex sh state) 1))
   trainVector sym = DiscreteTrained . NonEmptyMap.singleton sym
   combine (DiscreteTrained distr0) (DiscreteTrained distr1) =
      DiscreteTrained $ NonEmptyMap.unionWith Vector.add distr0 distr1
   normalize (DiscreteTrained distr) =
      Discrete $ normalizeProbColumns $ discreteFromMap distr

            
src/Math/HiddenMarkovModel/Distribution.hs
            -*# covarianceChol

instance (Shape.C emiSh, Eq emiSh) => EmissionProb (Gaussian emiSh) where
   mapStatesShape f (Gaussian m) = Gaussian $ Array.mapShape f m
   emissionProb (Gaussian allParams) x =
      StorableArray.fromBoxed $ fmap (gaussianEmissionProb x) allParams
   emissionStateProb (Gaussian allParams) x s =
      gaussianEmissionProb x $ allParams ! s

gaussianEmissionProb ::
   (Shape.C emiSh, Eq emiSh, Class.Real a) =>

            
src/Math/HiddenMarkovModel/Distribution.hs
         Matrix.toRowMajor . Matrix.fromRowArray hermSh . Array.reshape sh .
         Array.accumulate Vector.add
            (Array.replicate (Shape.Deferred sh) (Vector.zero hermSh)) .
         map (\(state,v) -> (Shape.deferIndex sh state, extendedHermitian v)) .
         NonEmpty.flatten
            $ xs
   trainVector xs probs =
      GaussianTrained $ Matrix.toRowMajor $ probs |*- extendedHermitian xs
   combine (GaussianTrained m0) (GaussianTrained m1) =

            
src/Math/HiddenMarkovModel/Distribution.hs
                     (Matrix.scaleRealReal c covarianceSum)
                     (Hermitian.outer MatrixShape.RowMajor center))
      in Gaussian $
         fmap (gaussianParameters . params .
               Hermitian.split . ArrMatrix.fromVector) $
         Matrix.toRowArray $ Matrix.fromRowMajor m

extendedHermitian ::
   (Shape.C emiSh, Class.Floating a) =>

            
src/Math/HiddenMarkovModel/Distribution.hs
gaussianTrained =
   GaussianTrained . Matrix.toRowMajor .
   matrixFromRowArray "HMM.Distribution.gaussianTrained" .
   fmap
      (\(weight, center, covariance) ->
         ArrMatrix.toVector $
         Hermitian.stack
            (Hermitian.fromList MatrixShape.RowMajor () [weight])
            (Matrix.singleRow MatrixShape.RowMajor center)

            
src/Math/HiddenMarkovModel/Distribution.hs
   (Shape.C emiSh, Shape.C stateSh, Class.Real prob) =>
   Array stateSh (Vector emiSh prob, Matrix.Hermitian emiSh prob) ->
   T (Gaussian emiSh) stateSh prob
gaussian = Gaussian . fmap gaussianParameters

gaussianParameters ::
   (Shape.C emiSh, Class.Real prob) =>
   (Vector emiSh prob, Matrix.Hermitian emiSh prob) ->
   (prob, Vector emiSh prob, Triangular.Upper emiSh prob)

            
src/Math/HiddenMarkovModel/Distribution.hs

instance (CSVSymbol symbol) => ToCSV (Discrete symbol) where
   toCells (Discrete m) =
      map
         (\(symbol, probs) ->
            cellFromSymbol symbol : HMMCSV.cellsFromVector probs) $
      Array.toAssociations $ Matrix.toRowArray m

instance (CSVSymbol symbol) => FromCSV (Discrete symbol) where

            
src/Math/HiddenMarkovModel/Distribution.hs
instance (CSVSymbol symbol) => FromCSV (Discrete symbol) where
   parseCells n =
      let p = parseSymbolProb n
      in fmap discreteFromList $
         liftA2 NonEmpty.Cons (HMMCSV.getRow >>= p) (HMMCSV.manyRowsUntilEnd p)

parseSymbolProb ::
   (Shape.C sh, Class.Real prob, Read prob, CSVSymbol symbol) =>
   sh -> CSV.CSVRow -> HMMCSV.CSVParser (symbol, Vector sh prob)

            
src/Math/HiddenMarkovModel/Distribution.hs
instance (Shape.Indexed emiSh) => ToCSV (Gaussian emiSh) where
   toCells (Gaussian params) =
      List.intercalate [[]] $
      map
         (\(_, center, covarianceChol) ->
            HMMCSV.cellsFromVector center :
            HMMCSV.cellsFromSquare (Triangular.toSquare covarianceChol)) $
      Array.toList params


            
src/Math/HiddenMarkovModel/Distribution.hs
      HMMCSV.assert (length gs == n) $
         printf "number of states (%d) and number of Gaussians (%d) mismatch"
            n (length gs)
      let sizes = map (vectorDim . snd3) gs
      HMMCSV.assert (ListHT.allEqual sizes) $
         printf "dimensions of emissions mismatch: %s" (show sizes)
      return $ Gaussian $ Array.fromList sh gs

parseSingleGaussian ::

            
knead-0.4.1
2 matches
src/Data/Array/Knead/Code.hs
compile name (Compose bld) = do
   LLVM.initializeNativeTarget
   m <- LLVM.newModule
   (funcs, mappings) <-
      LLVM.defineModule m $ do
         LLVM.setTarget LLVM.hostTriple
         liftM2 (,) bld LLVM.getGlobalMappings
   LLVM.writeBitcodeToFile (name ++ ".bc") m
   when False $ do

            
src/Data/Array/Knead/Code.hs
      void $ Opt.optimizeModule 3 m
      LLVM.writeBitcodeToFile (name ++ "-opt.bc") m
   EE.runEngineAccessWithModule m $
      EE.addGlobalMappings mappings >> funcs


type Exec = Compose LLVM.CodeGenModule EE.EngineAccess
type Importer f = FunPtr f -> f