-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | utilities for DP -- -- Small set of utility functions @package DPutils @version 0.0.0.2 -- | Pipes that introduce parallelism on different levels. module Pipes.Parallel -- | Evaluates chunks of pipes elements in parallel with a pure function. pipePar :: (Monad m) => Int -> Strategy b -> (a -> b) -> Pipe a b m () -- | Evaluates chunks of pipes elements in parallel with a pure function. -- Before and after each parallel step, a monadic function is run. This -- allows generation of certain statistics or information during runs. pipeParBA :: (Monad m) => Int -> Strategy b -> (a -> b) -> ([a] -> m (x, [a])) -> (x -> [b] -> m [b]) -> Pipe a b m () -- | Triangular numbers and various helper functions. -- -- Main use is for linearization of triangular array indexing. -- -- Triangular numbers: @ T_n = Σ_{k=1)^n k = 1 + 2 + 3 + ... + n = -- -- n * (n+1) / 2 = (n+1) choose 2 @ module Math.TriangularNumbers -- | Triangular numbers. -- -- https://oeis.org/A000217 triangularNumber :: Int -> Int -- | Size of an upper triangle starting at i and ending at -- j. "(0,N)" what be the normal thing to use. linearizeUppertri :: (Int, Int) -> Int -- | Subword indexing. Given the longest subword and the current subword, -- calculate a linear index "[0,..]". "(l,n)" in this case means "l"ower -- bound, length "n". And "(i,j)" is the normal index. -- --
--   0 1 2 3    <- j = ...
--   
--   0 1 2 3    i=0
--   _ 4 5 6    i=1
--   _ _ 7 8    i=2
--         9    i=3
--   
--   i=2, j=3  -> (4+1) * i - tri i + j
--   
--   _
--   _ _  the triangular number to subtract.
--   
toLinear :: Int -> (Int, Int) -> Int -- | Linear index to paired. -- -- We have indices in [0,N], and linear index k. -- --
--   (N+1)*i - (i*(i+1)/2) + j == K
--   
fromLinear :: Int -> Int -> (Int, Int) module Data.Paired.Common -- | Shall we combine elements on the main diagonal as well? -- -- If we choose NoDiag, we deal with upper triangular matrices -- that are effectively one element smaller. data OnDiag OnDiag :: OnDiag NoDiag :: OnDiag -- | Select only a subset of the possible enumerations. data Enumerate -- | Enumerate all elements All :: Enumerate -- | Enumerate from a value and at most N elements FromN :: Int -> Int -> Enumerate -- | If the size of the input is known before-hand or not. data SizeHint UnknownSize :: SizeHint KnownSize :: Int -> SizeHint instance GHC.Classes.Eq Data.Paired.Common.SizeHint instance GHC.Classes.Eq Data.Paired.Common.Enumerate instance GHC.Classes.Eq Data.Paired.Common.OnDiag -- | Efficient enumeration of subsets of triangular elements. Given a list -- [1..n] we want to enumerate a subset [(i,j)] of -- ordered pairs in such a way that we only have to hold the elements -- necessary for this subset in memory. module Data.Paired.Foldable -- | Generalized upper triangular elements. Given a list of elements -- [e_1,...,e_k], we want to return pairs (e_i,e_j) -- such that we have all ordered pairs with i<j (if -- NoDiagonal elements), or i<=j (if -- OnDiagonal elements). -- -- upperTri will force the spine of t a but is consumed -- linearly with a strict Data.Foldable.foldl'. Internally we -- keep a Data.IntMap of the retained elements. -- -- This is important if the Enumerate type is set to FromN k -- n. We start at the kth element, and produce n -- elements. -- -- TODO compare IntMap and HashMap. -- -- TODO inRange is broken. upperTri :: (Foldable t) => SizeHint -> OnDiag -> Enumerate -> t a -> Either String (IntMap a, Int, [((Int, Int), (a, a))]) module Data.Paired.Vector -- | Upper triangular elements. upperTriVG :: (Vector v a, Vector w (a, a)) => OnDiag -> v a -> (Int, w (a, a)) -- | Outer pairing of all as with all bs. This one is -- quasi-trivial, but here for completeness. rectangularVG :: (Vector va a, Vector vb b, Vector w (a, b)) => va a -> vb b -> (Int, w (a, b))