futhark-data-1.1.2.0: An implementation of the Futhark data format.

Safe Haskell | None
Language | Haskell2010

Futhark.Data

Contents

- Types of values
- Converting values

Description

This module defines an efficient value representation of the Futhark data format.

Synopsis

- data Value
  - = I8Value (Vector Int) (Vector Int8)
  - | I16Value (Vector Int) (Vector Int16)
  - | I32Value (Vector Int) (Vector Int32)
  - | I64Value (Vector Int) (Vector Int64)
  - | U8Value (Vector Int) (Vector Word8)
  - | U16Value (Vector Int) (Vector Word16)
  - | U32Value (Vector Int) (Vector Word32)
  - | U64Value (Vector Int) (Vector Word64)
  - | F16Value (Vector Int) (Vector Half)
  - | F32Value (Vector Int) (Vector Float)
  - | F64Value (Vector Int) (Vector Double)
  - | BoolValue (Vector Int) (Vector Bool)
- type Vector = Vector
- valueText :: Value -> Text
- data PrimType
  - = I8
  - | I16
  - | I32
  - | I64
  - | U8
  - | U16
  - | U32
  - | U64
  - | F16
  - | F32
  - | F64
  - | Bool
- primTypeText :: PrimType -> Text
- primTypeBytes :: PrimType -> Int
- data ValueType = ValueType [Int] PrimType
- valueTypeTextNoDims :: ValueType -> Text
- valueType :: Value -> ValueType
- valueElemType :: Value -> PrimType
- valueShape :: Value -> [Int]
- valueTypeText :: ValueType -> Text
- class GetValue t where
  - getValue :: Value -> Maybe t
- class PutValue t where
  - putValue :: t -> Maybe Value
- class PutValue1 t where
  - putValue1 :: t -> Value
- valueElems :: Value -> [Value]

# Documentation

data Value Source #

An efficiently represented Futhark value, represented as a shape vector and a value vector, which contains elements in row-major order. The size of the value vector must be equal to the product of the shape vector. This is not enforced by the representation, but consuming functions may give unexpected results if this invariant is broken. Scalars are represented with an empty shape vector.

Use `valueText` to get a human-readable representation, and `put` to obtain binary a representation.

The `Eq` instance is the naive one, meaning that no values containing NaNs will be considered equal. Use the functions from Futhark.Data.Compare if this is not what you want.

Constructors

I8Value (Vector Int) (Vector Int8) |
I16Value (Vector Int) (Vector Int16) |
I32Value (Vector Int) (Vector Int32) |
I64Value (Vector Int) (Vector Int64) |
U8Value (Vector Int) (Vector Word8) |
U16Value (Vector Int) (Vector Word16) |
U32Value (Vector Int) (Vector Word32) |
U64Value (Vector Int) (Vector Word64) |
F16Value (Vector Int) (Vector Half) |
F32Value (Vector Int) (Vector Float) |
F64Value (Vector Int) (Vector Double) |
BoolValue (Vector Int) (Vector Bool) |

#### Instances

Instances details

Binary Value Source # |
Instance details Defined in Futhark.Data Methods put :: Value -> Put Source # get :: Get Value Source # putList :: [Value] -> Put Source #
Show Value Source # |
Instance details Defined in Futhark.Data Methods showsPrec :: Int -> Value -> ShowS Source # show :: Value -> String Source # showList :: [Value] -> ShowS Source #
Eq Value Source # |
Instance details Defined in Futhark.Data Methods (==) :: Value -> Value -> Bool Source # (/=) :: Value -> Value -> Bool Source #
PutValue [Value] Source # |
Instance details Defined in Futhark.Data Methods putValue :: [Value] -> Maybe Value Source #

type Vector = Vector Source #

The value vector type.

valueText :: Value -> Text Source #

Construct a textual representation of the value as a strict text.

# Types of values

data PrimType Source #

The scalar types supported by the value format.

Constructors

I8 |
I16 |
I32 |
I64 |
U8 |
U16 |
U32 |
U64 |
F16 |
F32 |
F64 |
Bool |

#### Instances

Instances details

Bounded PrimType Source # |
Instance details Defined in Futhark.Data Methods minBound :: PrimType Source # maxBound :: PrimType Source #
Enum PrimType Source # |

Instance details

Defined in Futhark.Data

Methods

succ :: PrimType -> PrimType Source #

pred :: PrimType -> PrimType Source #

toEnum :: Int -> PrimType Source #

fromEnum :: PrimType -> Int Source #

enumFrom :: PrimType -> [PrimType] Source #

enumFromThen :: PrimType -> PrimType -> [PrimType] Source #

enumFromTo :: PrimType -> PrimType -> [PrimType] Source #

enumFromThenTo :: PrimType -> PrimType -> PrimType -> [PrimType] Source #

Show PrimType Source # |
Instance details Defined in Futhark.Data Methods showsPrec :: Int -> PrimType -> ShowS Source # show :: PrimType -> String Source # showList :: [PrimType] -> ShowS Source #
Eq PrimType Source # |
Instance details Defined in Futhark.Data Methods (==) :: PrimType -> PrimType -> Bool Source # (/=) :: PrimType -> PrimType -> Bool Source #
Ord PrimType Source # |
Instance details Defined in Futhark.Data Methods compare :: PrimType -> PrimType -> Ordering Source # (<) :: PrimType -> PrimType -> Bool Source # (<=) :: PrimType -> PrimType -> Bool Source # (>) :: PrimType -> PrimType -> Bool Source # (>=) :: PrimType -> PrimType -> Bool Source # max :: PrimType -> PrimType -> PrimType Source # min :: PrimType -> PrimType -> PrimType Source #

primTypeText :: PrimType -> Text Source #

Textual primitive type as a strict text.

primTypeBytes :: PrimType -> Int Source #

The number of bytes taken up by a single element of this type.

data ValueType Source #

The type of a simple Futhark value, comprising a shape and an element type.

Constructors

ValueType [Int] PrimType |

#### Instances

Instances details

Show ValueType Source # |
Instance details Defined in Futhark.Data Methods showsPrec :: Int -> ValueType -> ShowS Source # show :: ValueType -> String Source # showList :: [ValueType] -> ShowS Source #
Eq ValueType Source # |
Instance details Defined in Futhark.Data Methods (==) :: ValueType -> ValueType -> Bool Source # (/=) :: ValueType -> ValueType -> Bool Source #
Ord ValueType Source # |
Instance details Defined in Futhark.Data Methods compare :: ValueType -> ValueType -> Ordering Source # (<) :: ValueType -> ValueType -> Bool Source # (<=) :: ValueType -> ValueType -> Bool Source # (>) :: ValueType -> ValueType -> Bool Source # (>=) :: ValueType -> ValueType -> Bool Source # max :: ValueType -> ValueType -> ValueType Source # min :: ValueType -> ValueType -> ValueType Source #

valueTypeTextNoDims :: ValueType -> Text Source #

Prettyprint a value type with empty dimensions as a strict text. This is needed for Futhark server programs, whose types are un-sized.

valueType :: Value -> ValueType Source #

Get the type of a value.

valueElemType :: Value -> PrimType Source #

Get the element type of a value.

valueShape :: Value -> [Int] Source #

The shape of a value. Empty list in case of a scalar.

valueTypeText :: ValueType -> Text Source #

Prettyprint a value type as a strict text.

# Converting values

class GetValue t where Source #

A class for Haskell values that can be retrieved from `Value`. This is a convenience facility - don't expect it to be fast.

Methods

getValue :: Value -> Maybe t Source #

#### Instances

Instances details

GetValue Int16 Source # |
Instance details Defined in Futhark.Data Methods getValue :: Value -> Maybe Int16 Source #
GetValue Int32 Source # |
Instance details Defined in Futhark.Data Methods getValue :: Value -> Maybe Int32 Source #
GetValue Int64 Source # |
Instance details Defined in Futhark.Data Methods getValue :: Value -> Maybe Int64 Source #
GetValue Int8 Source # |
Instance details Defined in Futhark.Data Methods getValue :: Value -> Maybe Int8 Source #
GetValue Word16 Source # |
Instance details Defined in Futhark.Data Methods getValue :: Value -> Maybe Word16 Source #
GetValue Word32 Source # |
Instance details Defined in Futhark.Data Methods getValue :: Value -> Maybe Word32 Source #
GetValue Word64 Source # |
Instance details Defined in Futhark.Data Methods getValue :: Value -> Maybe Word64 Source #
GetValue Word8 Source # |
Instance details Defined in Futhark.Data Methods getValue :: Value -> Maybe Word8 Source #
GetValue Bool Source # |
Instance details Defined in Futhark.Data Methods getValue :: Value -> Maybe Bool Source #
GetValue t => GetValue [t] Source # |
Instance details Defined in Futhark.Data Methods getValue :: Value -> Maybe [t] Source #

class PutValue t where Source #

A class for Haskell values that can be converted to `Value`. This is a convenience facility - don't expect it to be fast.

Methods

putValue :: t -> Maybe Value Source #

This may fail for cases such as irregular arrays.

#### Instances

Instances details

PutValue ByteString Source # |
Instance details Defined in Futhark.Data Methods putValue :: ByteString -> Maybe Value Source #
PutValue ByteString Source # |
Instance details Defined in Futhark.Data Methods putValue :: ByteString -> Maybe Value Source #
PutValue Int16 Source # |
Instance details Defined in Futhark.Data Methods putValue :: Int16 -> Maybe Value Source #
PutValue Int32 Source # |
Instance details Defined in Futhark.Data Methods putValue :: Int32 -> Maybe Value Source #
PutValue Int64 Source # |
Instance details Defined in Futhark.Data Methods putValue :: Int64 -> Maybe Value Source #
PutValue Int8 Source # |
Instance details Defined in Futhark.Data Methods putValue :: Int8 -> Maybe Value Source #
PutValue Word16 Source # |
Instance details Defined in Futhark.Data Methods putValue :: Word16 -> Maybe Value Source #
PutValue Word32 Source # |
Instance details Defined in Futhark.Data Methods putValue :: Word32 -> Maybe Value Source #
PutValue Word64 Source # |
Instance details Defined in Futhark.Data Methods putValue :: Word64 -> Maybe Value Source #
PutValue Word8 Source # |
Instance details Defined in Futhark.Data Methods putValue :: Word8 -> Maybe Value Source #
PutValue Text Source # |
Instance details Defined in Futhark.Data Methods putValue :: Text -> Maybe Value Source #
PutValue [Value] Source # |
Instance details Defined in Futhark.Data Methods putValue :: [Value] -> Maybe Value Source #

class PutValue1 t where Source #

Like `PutValue`, but only for scalars and a few other simple things that cannot fail.

Methods

putValue1 :: t -> Value Source #

#### Instances

Instances details

PutValue1 ByteString Source # |
Instance details Defined in Futhark.Data Methods putValue1 :: ByteString -> Value Source #
PutValue1 ByteString Source # |
Instance details Defined in Futhark.Data Methods putValue1 :: ByteString -> Value Source #
PutValue1 Int16 Source # |
Instance details Defined in Futhark.Data Methods putValue1 :: Int16 -> Value Source #
PutValue1 Int32 Source # |
Instance details Defined in Futhark.Data Methods putValue1 :: Int32 -> Value Source #
PutValue1 Int64 Source # |
Instance details Defined in Futhark.Data Methods putValue1 :: Int64 -> Value Source #
PutValue1 Int8 Source # |
Instance details Defined in Futhark.Data Methods putValue1 :: Int8 -> Value Source #
PutValue1 Word16 Source # |
Instance details Defined in Futhark.Data Methods putValue1 :: Word16 -> Value Source #
PutValue1 Word32 Source # |
Instance details Defined in Futhark.Data Methods putValue1 :: Word32 -> Value Source #
PutValue1 Word64 Source # |
Instance details Defined in Futhark.Data Methods putValue1 :: Word64 -> Value Source #
PutValue1 Word8 Source # |
Instance details Defined in Futhark.Data Methods putValue1 :: Word8 -> Value Source #
PutValue1 Text Source # |
Instance details Defined in Futhark.Data Methods putValue1 :: Text -> Value Source #

valueElems :: Value -> [Value] Source #

Produce a list of the immediate elements of the value. That is, a 2D array will produce a list of 1D values. A zero-dimensional value will produce an empty list. While lists are of course inefficient, the actual values are just slices of the original value, which makes them fairly space-efficient (but beware space leaks).