module Data.Repa.Flow.Auto.Format
(
module Data.Repa.Convert.Formats
, packFormat_i, flatPackFormat_i
, packFormatLn_i, flatPackFormatLn_i
, packAsciiLn_i, flatPackAsciiLn_i
, keyPackAsciiLn_i)
where
import Data.Word
import Data.Char
import Data.Repa.Convert.Formats
import Data.Repa.Flow.Auto as F
import Data.Repa.Array as A
import Data.Repa.Array.Auto.Format as A
import qualified Data.Repa.Convert as C
import qualified Data.Repa.Flow.Generic as G
#include "repa-flow.h"
packFormat_i
:: (C.Packable format, Elem (Value format))
=> format
-> Sources (Value format)
-> IO (Sources (Array Word8))
packFormat_i format ss
= let
packElem x
= let Just arr = A.packFormat format x
in arr
in G.map_i (A.map packElem) ss
flatPackFormat_i
:: (C.Packable format, Elem (Value format))
=> format -> Sources (Value format) -> IO (Sources Word8)
flatPackFormat_i format ss
= concat_i =<< packFormat_i format ss
packFormatLn_i
:: (C.Packable format, Elem (Value format))
=> format
-> Sources (Value format)
-> IO (Sources (Array Word8))
packFormatLn_i format ss
= F.map_i (\arr -> A.concat $ A.fromList [arr, nl])
=<< packFormat_i format ss
where !nl = A.fromList [fromIntegral $ ord '\n']
flatPackFormatLn_i
:: (C.Packable format, Elem (Value format))
=> format -> Sources (Value format) -> IO (Sources Word8)
flatPackFormatLn_i format ss
= concat_i =<< packFormatLn_i format ss
packAsciiLn_i
:: forall a
. ( C.FormatAscii a, a ~ Value (C.FormatAscii' a)
, Elem a
, Packable (C.FormatAscii' a))
=> Sources a
-> IO (Sources (Array Word8))
packAsciiLn_i ss
= F.map_i (\arr -> A.concat $ A.fromList [arr, nl])
=<< packFormat_i (C.formatAscii proxy) ss
where !nl = A.fromList [fromIntegral $ ord '\n']
proxy = (error "repa-flow: packAscii_i proxy" :: a)
flatPackAsciiLn_i
:: forall a
. ( C.FormatAscii a, a ~ Value (C.FormatAscii' a)
, Elem a
, Packable (C.FormatAscii' a))
=> Sources a -> IO (Sources Word8)
flatPackAsciiLn_i ss
= concat_i =<< packAsciiLn_i ss
keyPackAsciiLn_i
:: forall a k
. ( C.FormatAscii a, a ~ Value (C.FormatAscii' a)
, Elem a
, Packable (C.FormatAscii' a)
, Elem k, Build k)
=> Sources (k, a)
-> IO (Sources (k, Array Word8))
keyPackAsciiLn_i ss
= let
proxy = (error "repa-flow: sndPackAsciiLn_i proxy" :: a)
!nl = A.fromList [fromIntegral $ ord '\n']
packElem (k, x)
= let Just arr = A.packFormat (C.formatAscii proxy) x
in (k, A.concat $ A.fromList [arr, nl])
in G.map_i (A.map packElem) ss