Migrated String to Text
This commit is contained in:
parent
717cfd7b34
commit
27c4349f53
7
dist/build/autogen/cabal_macros.h
vendored
7
dist/build/autogen/cabal_macros.h
vendored
@ -63,3 +63,10 @@
|
|||||||
(major1) == 3 && (major2) < 2 || \
|
(major1) == 3 && (major2) < 2 || \
|
||||||
(major1) == 3 && (major2) == 2 && (minor) <= 0)
|
(major1) == 3 && (major2) == 2 && (minor) <= 0)
|
||||||
|
|
||||||
|
/* package text-0.11.3.1 */
|
||||||
|
#define VERSION_text "0.11.3.1"
|
||||||
|
#define MIN_VERSION_text(major1,major2,minor) (\
|
||||||
|
(major1) < 0 || \
|
||||||
|
(major1) == 0 && (major2) < 11 || \
|
||||||
|
(major1) == 0 && (major2) == 11 && (minor) <= 3)
|
||||||
|
|
||||||
|
BIN
dist/build/hgraph/hgraph
vendored
BIN
dist/build/hgraph/hgraph
vendored
Binary file not shown.
BIN
dist/build/hgraph/hgraph-tmp/Main.hi
vendored
BIN
dist/build/hgraph/hgraph-tmp/Main.hi
vendored
Binary file not shown.
BIN
dist/build/test-hgraph/test-hgraph
vendored
BIN
dist/build/test-hgraph/test-hgraph
vendored
Binary file not shown.
BIN
dist/build/test-hgraph/test-hgraph-tmp/Main.hi
vendored
BIN
dist/build/test-hgraph/test-hgraph-tmp/Main.hi
vendored
Binary file not shown.
2
dist/setup-config
vendored
2
dist/setup-config
vendored
File diff suppressed because one or more lines are too long
@ -10,7 +10,7 @@ data-dir: ""
|
|||||||
executable hgraph
|
executable hgraph
|
||||||
build-depends: QuickCheck -any, Stream -any, accelerate -any,
|
build-depends: QuickCheck -any, Stream -any, accelerate -any,
|
||||||
base -any, bytestring -any, deepseq -any, ghc -any, monad-par -any,
|
base -any, bytestring -any, deepseq -any, ghc -any, monad-par -any,
|
||||||
parallel -any
|
parallel -any, text -any
|
||||||
main-is: Main.hs
|
main-is: Main.hs
|
||||||
buildable: True
|
buildable: True
|
||||||
hs-source-dirs: src
|
hs-source-dirs: src
|
||||||
@ -19,7 +19,7 @@ executable hgraph
|
|||||||
test-suite test-hgraph
|
test-suite test-hgraph
|
||||||
build-depends: QuickCheck -any, Stream -any, accelerate -any,
|
build-depends: QuickCheck -any, Stream -any, accelerate -any,
|
||||||
base -any, bytestring -any, deepseq -any, ghc -any, monad-par -any,
|
base -any, bytestring -any, deepseq -any, ghc -any, monad-par -any,
|
||||||
parallel -any
|
parallel -any, text -any
|
||||||
type: exitcode-stdio-1.0
|
type: exitcode-stdio-1.0
|
||||||
main-is: Main.hs
|
main-is: Main.hs
|
||||||
buildable: True
|
buildable: True
|
||||||
|
48
src/Main.hs
48
src/Main.hs
@ -24,12 +24,14 @@ import Data.List
|
|||||||
import System.Exit (exitFailure)
|
import System.Exit (exitFailure)
|
||||||
import System.Environment
|
import System.Environment
|
||||||
import Test.QuickCheck.All (quickCheckAll)
|
import Test.QuickCheck.All (quickCheckAll)
|
||||||
import qualified Data.ByteString.Lazy.Char8 as B
|
import qualified Data.ByteString.Char8 as B
|
||||||
import Data.ByteString.Lazy.Char8 (ByteString)
|
import Data.ByteString.Lazy.Char8 (ByteString)
|
||||||
import Control.Monad.Par.Scheds.Trace
|
import Control.Monad.Par.Scheds.Trace
|
||||||
import qualified Data.Stream as S
|
import qualified Data.Stream as S
|
||||||
import Data.Either (lefts, rights)
|
import Data.Either (lefts, rights)
|
||||||
import Debug.Trace
|
import Debug.Trace
|
||||||
|
import qualified Data.Text as T
|
||||||
|
import Data.Text.Encoding
|
||||||
import qualified Data.Array.Accelerate as A
|
import qualified Data.Array.Accelerate as A
|
||||||
-- change to Data.Array.Accelerate.CUDA as I and link accelerate-cuda to use GPU instead of CPU
|
-- change to Data.Array.Accelerate.CUDA as I and link accelerate-cuda to use GPU instead of CPU
|
||||||
import Data.Array.Accelerate.Interpreter as I
|
import Data.Array.Accelerate.Interpreter as I
|
||||||
@ -38,19 +40,20 @@ import Stream hiding (map)
|
|||||||
|
|
||||||
type Matrix e = A.Array A.DIM2 e
|
type Matrix e = A.Array A.DIM2 e
|
||||||
|
|
||||||
createGraph :: String -> Either [Int] String
|
createGraph :: T.Text -> Either [Int] T.Text
|
||||||
createGraph input = traceEvent "creating graph" createGraph' input (Left [])
|
createGraph input = createGraph' input (Left [])
|
||||||
where
|
where
|
||||||
createGraph' :: String -> Either [Int] String -> Either [Int] String
|
createGraph' :: T.Text -> Either [Int] T.Text -> Either [Int] T.Text
|
||||||
createGraph' [] r = traceEvent "recursion done." r
|
createGraph' a r
|
||||||
createGraph' (a:as) r =
|
| T.null a = r
|
||||||
let next = (createGraph' as r) in
|
| otherwise =
|
||||||
|
let next = (createGraph' (T.tail a) r) in
|
||||||
case next of
|
case next of
|
||||||
Left xs ->
|
Left xs ->
|
||||||
case a of
|
case T.head a of
|
||||||
'0' -> Left $ 0:xs
|
'0' -> Left $ 0:xs
|
||||||
'1' -> Left $ 1:xs
|
'1' -> Left $ 1:xs
|
||||||
_ -> Right $ "cannot parse " ++ (a:as)
|
_ -> Right $ T.append (T.pack "cannot parse ") a
|
||||||
Right errstr ->
|
Right errstr ->
|
||||||
Right errstr
|
Right errstr
|
||||||
--createGraph input = Right $ "Parsing-error in line: " ++ input
|
--createGraph input = Right $ "Parsing-error in line: " ++ input
|
||||||
@ -80,19 +83,17 @@ graphFolder l = graphFolder' l (Left [[]])
|
|||||||
concatWith :: String -> String -> String -> String
|
concatWith :: String -> String -> String -> String
|
||||||
concatWith d a b = a ++ d ++ b
|
concatWith d a b = a ++ d ++ b
|
||||||
|
|
||||||
emptyLine :: String -> Bool
|
emptyLine :: T.Text -> Bool
|
||||||
emptyLine "" = True
|
emptyLine a
|
||||||
emptyLine "\n" = True
|
| T.null a = True
|
||||||
emptyLine "\r\n" = True
|
| otherwise = False
|
||||||
emptyLine "\r" = True
|
|
||||||
emptyLine _ = False
|
|
||||||
|
|
||||||
emptyLog :: [String] -> Bool
|
emptyLog :: [T.Text] -> Bool
|
||||||
emptyLog [] = True
|
emptyLog [] = True
|
||||||
emptyLog a = emptyLine $ foldl1 (++) a
|
emptyLog a = False --emptyLine $ foldl True (&&) (map emptyLine a)
|
||||||
|
|
||||||
-- TODO: implement calculation
|
-- TODO: implement calculation
|
||||||
doCalculation :: Matrix Int -> ByteString
|
doCalculation :: Matrix Int -> B.ByteString
|
||||||
doCalculation a = B.pack $ "" --(show a) ++ "\n"
|
doCalculation a = B.pack $ "" --(show a) ++ "\n"
|
||||||
|
|
||||||
|
|
||||||
@ -108,10 +109,10 @@ exeMain = do
|
|||||||
-- and filter empty lines
|
-- and filter empty lines
|
||||||
(createGraph) (filter (not . emptyLine)
|
(createGraph) (filter (not . emptyLine)
|
||||||
-- split at \n, convert to String
|
-- split at \n, convert to String
|
||||||
(map B.unpack (B.split '\n' input)))
|
(T.lines (decodeUtf8 input)))
|
||||||
--egraph <- return $ graphFolder unrefined_graph
|
--egraph <- return $ graphFolder unrefined_graph
|
||||||
(graph, log, lines) <- return $ ((foldl1 (++) (lefts unrefined_graph), -- concatenated graph
|
(graph, log, lines) <- return $ ((foldl1 (++) (lefts unrefined_graph), -- concatenated graph
|
||||||
foldl (concatWith "\n") "" (rights unrefined_graph), -- concat error-log
|
T.intercalate (T.singleton '\n') (rights unrefined_graph), -- concat error-log
|
||||||
length unrefined_graph) -- number of elements in graph
|
length unrefined_graph) -- number of elements in graph
|
||||||
-- in parallel
|
-- in parallel
|
||||||
`using` parTuple3 rdeepseq rdeepseq rdeepseq)
|
`using` parTuple3 rdeepseq rdeepseq rdeepseq)
|
||||||
@ -119,13 +120,14 @@ exeMain = do
|
|||||||
-- validate graph
|
-- validate graph
|
||||||
log <- return $ let l = length graph in
|
log <- return $ let l = length graph in
|
||||||
if l /= lines*lines then
|
if l /= lines*lines then
|
||||||
log ++ "Lines dont match up. Read " ++ (show l) ++ " lines. Expected "
|
T.append log $ T.pack $ "Lines dont match up. Read " ++ (show l) ++
|
||||||
++ (show (lines*lines)) ++ " lines.\n"
|
" chars. Expected " ++ (show (lines*lines)) ++
|
||||||
|
" chars.\n"
|
||||||
else
|
else
|
||||||
log
|
log
|
||||||
output <- return $ case emptyLine log of
|
output <- return $ case emptyLine log of
|
||||||
True -> doCalculation $ A.fromList (A.Z A.:. lines A.:. lines) graph
|
True -> doCalculation $ A.fromList (A.Z A.:. lines A.:. lines) graph
|
||||||
_ -> B.pack $ "Error detected:\n" ++ log ++ "\n\n"
|
_ -> encodeUtf8 $ T.append (T.append (T.pack "Error detected:\n") log) (T.pack "\n\n")
|
||||||
B.putStr output
|
B.putStr output
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user