hasktorch-0.2.0.0: Functional differentiable programming in Haskell
Safe HaskellSafe-Inferred
LanguageHaskell2010

Torch.Data.CsvDatastream

Contents

Synopsis

Documentation

data NamedColumns Source #

Constructors

Unnamed 
Named 

data CsvDatastream' batches (named :: NamedColumns) Source #

A CSV datastream. The datastream instance of this type streams samples of batches from a CSV file at the specified file path. Batches are yielded in constant memory, but if shuffling is enabled, then there will be at most BufferSize records stored in memory.

Constructors

CsvDatastream' 

Fields

Instances

Instances details
(MonadBaseControl IO m, MonadSafe m, FromRecord batch) => Datastream m () (CsvDatastream batch) (Vector batch) Source # 
Instance details

Defined in Torch.Data.CsvDatastream

Methods

streamSamples :: CsvDatastream batch -> () -> ListT m (Vector batch) Source #

(MonadBaseControl IO m, MonadSafe m, FromNamedRecord batch) => Datastream m () (CsvDatastreamNamed batch) (Vector batch) Source # 
Instance details

Defined in Torch.Data.CsvDatastream

Methods

streamSamples :: CsvDatastreamNamed batch -> () -> ListT m (Vector batch) Source #

type CsvDatastream batches = CsvDatastream' batches Unnamed Source #

A specialized version of CsvDatastream'. Use this type if you want to decode a CSV file with records defined by the order of the columns.

type CsvDatastreamNamed batches = CsvDatastream' batches Named Source #

A specialized version of CsvDatastream'. Use this type if you want to decode a CSV file with records that have FromNamedRecord instance. This decodes each field of the record by the corresponding column with the given header name.

csvDatastream :: forall (isNamed :: NamedColumns) batches. FilePath -> CsvDatastream' batches isNamed Source #

Produce a CsvDatastream' from the given file with default options, and comma separated columns.

tsvDatastream :: forall (isNamed :: NamedColumns) batches. FilePath -> CsvDatastream' batches isNamed Source #

Produce a CsvDatastream' from the given file with default options, and tab separated columns.

Reexports

class FromField a where Source #

A type that can be converted from a single CSV field, with the possibility of failure.

When writing an instance, use empty, mzero, or fail to make a conversion fail, e.g. if a Field can't be converted to the given type.

Example type and instance:

{-# LANGUAGE OverloadedStrings #-}

data Color = Red | Green | Blue

instance FromField Color where
    parseField s
        | s == "R"  = pure Red
        | s == "G"  = pure Green
        | s == "B"  = pure Blue
        | otherwise = mzero

Methods

parseField :: Field -> Parser a Source #

Instances

Instances details
FromField Int16

Accepts a signed decimal number. Ignores whitespace.

Instance details

Defined in Data.Csv.Conversion

FromField Int32

Accepts a signed decimal number. Ignores whitespace.

Instance details

Defined in Data.Csv.Conversion

FromField Int64

Accepts a signed decimal number. Ignores whitespace.

Instance details

Defined in Data.Csv.Conversion

FromField Int8

Accepts a signed decimal number. Ignores whitespace.

Instance details

Defined in Data.Csv.Conversion

FromField Word16

Accepts an unsigned decimal number. Ignores whitespace.

Instance details

Defined in Data.Csv.Conversion

FromField Word32

Accepts an unsigned decimal number. Ignores whitespace.

Instance details

Defined in Data.Csv.Conversion

FromField Word64

Accepts an unsigned decimal number. Ignores whitespace.

Instance details

Defined in Data.Csv.Conversion

FromField Word8

Accepts an unsigned decimal number. Ignores whitespace.

Instance details

Defined in Data.Csv.Conversion

FromField ByteString 
Instance details

Defined in Data.Csv.Conversion

FromField ByteString 
Instance details

Defined in Data.Csv.Conversion

FromField ShortByteString 
Instance details

Defined in Data.Csv.Conversion

FromField Scientific

Accepts the same syntax as rational. Ignores whitespace.

Since: cassava-0.5.1.0

Instance details

Defined in Data.Csv.Conversion

FromField Text

Assumes UTF-8 encoding. Fails on invalid byte sequences.

Instance details

Defined in Data.Csv.Conversion

FromField Text

Assumes UTF-8 encoding. Fails on invalid byte sequences.

Instance details

Defined in Data.Csv.Conversion

FromField ShortText

Assumes UTF-8 encoding. Fails on invalid byte sequences.

Since: cassava-0.5.0.0

Instance details

Defined in Data.Csv.Conversion

FromField Integer

Accepts a signed decimal number. Ignores whitespace.

Instance details

Defined in Data.Csv.Conversion

FromField Natural

Accepts an unsigned decimal number. Ignores whitespace.

Since: cassava-0.5.1.0

Instance details

Defined in Data.Csv.Conversion

FromField ()

Ignores the Field. Always succeeds.

Instance details

Defined in Data.Csv.Conversion

Methods

parseField :: Field -> Parser () Source #

FromField Char

Assumes UTF-8 encoding.

Instance details

Defined in Data.Csv.Conversion

FromField Double

Accepts same syntax as rational. Ignores whitespace.

Instance details

Defined in Data.Csv.Conversion

FromField Float

Accepts same syntax as rational. Ignores whitespace.

Instance details

Defined in Data.Csv.Conversion

FromField Int

Accepts a signed decimal number. Ignores whitespace.

Instance details

Defined in Data.Csv.Conversion

FromField Word

Accepts an unsigned decimal number. Ignores whitespace.

Instance details

Defined in Data.Csv.Conversion

FromField a => FromField (Identity a)

Since: cassava-0.5.2.0

Instance details

Defined in Data.Csv.Conversion

FromField a => FromField (Maybe a)

Nothing if the Field is empty, Just otherwise.

Instance details

Defined in Data.Csv.Conversion

Methods

parseField :: Field -> Parser (Maybe a) Source #

FromField [Char]

Assumes UTF-8 encoding. Fails on invalid byte sequences.

Instance details

Defined in Data.Csv.Conversion

FromField a => FromField (Either Field a)

Left field if conversion failed, Right otherwise.

Instance details

Defined in Data.Csv.Conversion

FromField a => FromField (Const a b)

Since: cassava-0.5.2.0

Instance details

Defined in Data.Csv.Conversion

Methods

parseField :: Field -> Parser (Const a b) Source #

class FromRecord a where Source #

A type that can be converted from a single CSV record, with the possibility of failure.

When writing an instance, use empty, mzero, or fail to make a conversion fail, e.g. if a Record has the wrong number of columns.

Given this example data:

John,56
Jane,55

here's an example type and instance:

data Person = Person { name :: !Text, age :: !Int }

instance FromRecord Person where
    parseRecord v
        | length v == 2 = Person <$>
                          v .! 0 <*>
                          v .! 1
        | otherwise     = mzero

Minimal complete definition

Nothing

Instances

Instances details
FromField a => FromRecord (Only a) 
Instance details

Defined in Data.Csv.Conversion

FromField a => FromRecord (Vector a) 
Instance details

Defined in Data.Csv.Conversion

(FromField a, Unbox a) => FromRecord (Vector a) 
Instance details

Defined in Data.Csv.Conversion

FromField a => FromRecord [a] 
Instance details

Defined in Data.Csv.Conversion

Methods

parseRecord :: Record -> Parser [a] Source #

(FromField a, FromField b) => FromRecord (a, b) 
Instance details

Defined in Data.Csv.Conversion

Methods

parseRecord :: Record -> Parser (a, b) Source #

(FromField a, FromField b, FromField c) => FromRecord (a, b, c) 
Instance details

Defined in Data.Csv.Conversion

Methods

parseRecord :: Record -> Parser (a, b, c) Source #

(FromField a, FromField b, FromField c, FromField d) => FromRecord (a, b, c, d) 
Instance details

Defined in Data.Csv.Conversion

Methods

parseRecord :: Record -> Parser (a, b, c, d) Source #

(FromField a, FromField b, FromField c, FromField d, FromField e) => FromRecord (a, b, c, d, e) 
Instance details

Defined in Data.Csv.Conversion

Methods

parseRecord :: Record -> Parser (a, b, c, d, e) Source #

(FromField a, FromField b, FromField c, FromField d, FromField e, FromField f) => FromRecord (a, b, c, d, e, f) 
Instance details

Defined in Data.Csv.Conversion

Methods

parseRecord :: Record -> Parser (a, b, c, d, e, f) Source #

(FromField a, FromField b, FromField c, FromField d, FromField e, FromField f, FromField g) => FromRecord (a, b, c, d, e, f, g) 
Instance details

Defined in Data.Csv.Conversion

Methods

parseRecord :: Record -> Parser (a, b, c, d, e, f, g) Source #

(FromField a, FromField b, FromField c, FromField d, FromField e, FromField f, FromField g, FromField h) => FromRecord (a, b, c, d, e, f, g, h) 
Instance details

Defined in Data.Csv.Conversion

Methods

parseRecord :: Record -> Parser (a, b, c, d, e, f, g, h) Source #

(FromField a, FromField b, FromField c, FromField d, FromField e, FromField f, FromField g, FromField h, FromField i) => FromRecord (a, b, c, d, e, f, g, h, i) 
Instance details

Defined in Data.Csv.Conversion

Methods

parseRecord :: Record -> Parser (a, b, c, d, e, f, g, h, i) Source #

(FromField a, FromField b, FromField c, FromField d, FromField e, FromField f, FromField g, FromField h, FromField i, FromField j) => FromRecord (a, b, c, d, e, f, g, h, i, j) 
Instance details

Defined in Data.Csv.Conversion

Methods

parseRecord :: Record -> Parser (a, b, c, d, e, f, g, h, i, j) Source #

(FromField a, FromField b, FromField c, FromField d, FromField e, FromField f, FromField g, FromField h, FromField i, FromField j, FromField k) => FromRecord (a, b, c, d, e, f, g, h, i, j, k) 
Instance details

Defined in Data.Csv.Conversion

Methods

parseRecord :: Record -> Parser (a, b, c, d, e, f, g, h, i, j, k) Source #

(FromField a, FromField b, FromField c, FromField d, FromField e, FromField f, FromField g, FromField h, FromField i, FromField j, FromField k, FromField l) => FromRecord (a, b, c, d, e, f, g, h, i, j, k, l) 
Instance details

Defined in Data.Csv.Conversion

Methods

parseRecord :: Record -> Parser (a, b, c, d, e, f, g, h, i, j, k, l) Source #

(FromField a, FromField b, FromField c, FromField d, FromField e, FromField f, FromField g, FromField h, FromField i, FromField j, FromField k, FromField l, FromField m) => FromRecord (a, b, c, d, e, f, g, h, i, j, k, l, m) 
Instance details

Defined in Data.Csv.Conversion

Methods

parseRecord :: Record -> Parser (a, b, c, d, e, f, g, h, i, j, k, l, m) Source #

(FromField a, FromField b, FromField c, FromField d, FromField e, FromField f, FromField g, FromField h, FromField i, FromField j, FromField k, FromField l, FromField m, FromField n) => FromRecord (a, b, c, d, e, f, g, h, i, j, k, l, m, n) 
Instance details

Defined in Data.Csv.Conversion

Methods

parseRecord :: Record -> Parser (a, b, c, d, e, f, g, h, i, j, k, l, m, n) Source #

(FromField a, FromField b, FromField c, FromField d, FromField e, FromField f, FromField g, FromField h, FromField i, FromField j, FromField k, FromField l, FromField m, FromField n, FromField o) => FromRecord (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) 
Instance details

Defined in Data.Csv.Conversion

Methods

parseRecord :: Record -> Parser (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) Source #

class FromNamedRecord a where Source #

A type that can be converted from a single CSV record, with the possibility of failure.

When writing an instance, use empty, mzero, or fail to make a conversion fail, e.g. if a Record has the wrong number of columns.

Given this example data:

name,age
John,56
Jane,55

here's an example type and instance:

{-# LANGUAGE OverloadedStrings #-}

data Person = Person { name :: !Text, age :: !Int }

instance FromNamedRecord Person where
    parseNamedRecord m = Person <$>
                         m .: "name" <*>
                         m .: "age"

Note the use of the OverloadedStrings language extension which enables ByteString values to be written as string literals.

Minimal complete definition

Nothing

Instances

Instances details
(FromField a, FromField b, Ord a) => FromNamedRecord (Map a b) 
Instance details

Defined in Data.Csv.Conversion

(Eq a, FromField a, FromField b, Hashable a) => FromNamedRecord (HashMap a b) 
Instance details

Defined in Data.Csv.Conversion