mirror of
https://github.com/HuwCampbell/grenade.git
synced 2024-11-22 06:55:13 +03:00
Give a slightly not terrible error message
This commit is contained in:
parent
cb2eb0db8f
commit
8349a85b0f
@ -69,7 +69,7 @@ loadShakespeare :: FilePath -> ExceptT String IO (Vector Int, M.Map Char Int, Ve
|
||||
loadShakespeare path = do
|
||||
contents <- lift $ readFile path
|
||||
let annotated = annotateCapitals contents
|
||||
(m,cs) <- ExceptT . return . note "Couldn't fit data in hotMap" $ hotMap (Proxy :: Proxy 40) annotated
|
||||
(m,cs) <- ExceptT . return $ hotMap (Proxy :: Proxy 40) annotated
|
||||
hot <- ExceptT . return . note "Couldn't generate hot values" $ traverse (`M.lookup` m) annotated
|
||||
return (V.fromList hot, m, cs)
|
||||
|
||||
|
@ -52,15 +52,16 @@ oneHot hot =
|
||||
|
||||
-- | Create a one hot map from any enumerable.
|
||||
-- Returns a map, and the ordered list for the reverse transformation
|
||||
hotMap :: (Ord a, KnownNat n) => Proxy n -> [a] -> Maybe (Map a Int, Vector a)
|
||||
hotMap :: (Ord a, KnownNat n) => Proxy n -> [a] -> Either String (Map a Int, Vector a)
|
||||
hotMap n as =
|
||||
let len = fromIntegral $ natVal n
|
||||
uniq = [ c | (c:_) <- group $ sort as]
|
||||
hotl = length uniq
|
||||
in if hotl == len
|
||||
then
|
||||
Just (M.fromList $ zip uniq [0..], V.fromList uniq)
|
||||
else Nothing
|
||||
Right (M.fromList $ zip uniq [0..], V.fromList uniq)
|
||||
else
|
||||
Left ("Couldn't create hotMap of size " ++ show len ++ " from vector with " ++ show hotl ++ " unique characters")
|
||||
|
||||
-- | From a map and value, create a 1D Shape
|
||||
-- with one index hot (1) with the rest 0.
|
||||
|
Loading…
Reference in New Issue
Block a user