Commit 0e62f678 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel 🐢

wta: Fix whitespace

parent dcb87ef9
......@@ -4,7 +4,7 @@
module IndexedTransition (IndexedTransition(..), maxIndex, fromIndex) where
import Data.Vector (Vector)
import Data.Vector ( Vector )
import qualified Data.Vector as V
import Data.Maybe
import Data.Tuple
......@@ -24,7 +24,7 @@ maxIndex spec =
fromIndex :: WTASpec m -> IndexedTransition -> (State, Transition ())
fromIndex spec (Index i) =
let n = numStates spec
(t, symbolSums) = transitionsPerState spec
(t , symbolSums ) = transitionsPerState spec
(state, stateTransition) = i `divMod` t
......@@ -35,19 +35,18 @@ fromIndex spec (Index i) =
arityTransition = stateTransition - (symbolSums V.! arity)
symbolBounds :: Vector Int = V.cons (numSymbols spec V.! arity) (V.replicate arity n)
symbolBounds :: Vector Int =
V.cons (numSymbols spec V.! arity) (V.replicate arity n)
symbolDigits = decodeFromInt symbolBounds arityTransition
symbol = V.head symbolDigits
successors = V.tail symbolDigits
trans = Transition
{ weight = ()
trans = Transition { weight = ()
, summand = aritySummand spec arity
, symbol = symbol
, successors = V.map State successors
}
in (State (fromIntegral state), trans)
index :: WTASpec m1 -> Int -> Transition m2 -> IndexedTransition
......@@ -55,10 +54,13 @@ index spec state trans =
let (t, symbolSums) = transitionsPerState spec
arity :: Int = summandArity spec (summand trans)
symbolBounds :: Vector Int = V.cons (numSymbols spec V.! arity) (V.replicate arity (numStates spec))
arityIdx :: Integer = encodeAsInt symbolBounds (V.cons (symbol trans) (V.map fromState $ successors trans))
symbolBounds :: Vector Int = V.cons
(numSymbols spec V.! arity)
(V.replicate arity (numStates spec))
arityIdx :: Integer = encodeAsInt
symbolBounds
(V.cons (symbol trans) (V.map fromState $ successors trans))
stateLocal :: Integer = symbolSums V.! arity + arityIdx
in Index $ (fromIntegral state) * t + stateLocal
-- Helpers
......@@ -74,7 +76,8 @@ aritySummand spec arity =
transitionsPerState :: WTASpec m -> (Integer, Vector Integer)
transitionsPerState spec =
let n = numStates spec
tPerSymbol = (V.imap (\i syms -> fromIntegral $ syms * n ^ i) (numSymbols spec))
tPerSymbol =
(V.imap (\i syms -> fromIntegral $ syms * n ^ i) (numSymbols spec))
runningTotal = V.scanl' (+) 0 tPerSymbol
in (V.last runningTotal, runningTotal)
......@@ -84,7 +87,6 @@ encodeAsInt maxBounds digits =
in sum (V.zipWith (*) factors (fmap fromIntegral digits))
decodeFromInt :: Vector Int -> Integer -> Vector Int
decodeFromInt maxBounds encoded =
V.map (fromIntegral . fst) $ V.postscanr' doDigit (0, encoded) (fmap fromIntegral maxBounds)
decodeFromInt maxBounds encoded = V.map (fromIntegral . fst)
$ V.postscanr' doDigit (0, encoded) (fmap fromIntegral maxBounds)
where doDigit bound (_, current) = (swap $ current `divMod` bound)
......@@ -118,9 +118,7 @@ parseZeroFreq =
)
<|> (NumTransitions <$> Options.option
Options.auto
( Options.long "transitions"
<> Options.metavar "NUM"
<> Options.help
(Options.long "transitions" <> Options.metavar "NUM" <> Options.help
("Number of transitions to generate. They will be distributed randomly over states."
)
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment