packages feed

futhark-data 1.0.0.1 → 1.0.1.1

raw patch · 6 files changed

+40/−6 lines, 6 filesdep +halfPVP ok

version bump matches the API change (PVP)

Dependencies added: half

API changes (from Hackage documentation)

+ Futhark.Data: F16 :: PrimType
+ Futhark.Data: F16Value :: Vector Int -> Vector Half -> Value

Files

CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for futhark-data +## 1.0.1.1 -- 2021-08-04++* Support the `f16` type.+ ## 1.0.0.1 -- 2021-06-09  * Fixed crash in value comparison.
futhark-data.cabal view
@@ -1,6 +1,6 @@ cabal-version:      2.4 name:               futhark-data-version:            1.0.0.1+version:            1.0.1.1 synopsis:           An implementation of the Futhark data format.  description: The Futhark compiler and its tools uses a simple external@@ -9,7 +9,7 @@              these values, as well as utility functions for reading              and writing values in both the textual and binary format. -category:           Data+category:           Futhark author:             Troels Henriksen maintainer:         athas@sigkill.dk bug-reports:        https://github.com/diku-dk/futhark-data-haskell/issues@@ -31,6 +31,7 @@                     , bytestring >=0.10.8                     , bytestring-to-vector >=0.3.0.1                     , containers >=0.6.2.1+                    , half >= 0.3                     , megaparsec >=9.0.0                     , mtl >=2.2.1                     , text >=1.2.2.2
src/Futhark/Data.hs view
@@ -42,6 +42,7 @@ import qualified Data.Text.Lazy.Builder as TB import qualified Data.Vector.Storable as SVec import Data.Vector.Storable.ByteString (byteStringToVector, vectorToByteString)+import Numeric.Half  -- | The value vector type. type Vector = SVec.Vector@@ -69,6 +70,7 @@   | 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)@@ -86,6 +88,7 @@   put (U16Value shape vs) = putBinaryValue " u16" shape vs   put (U32Value shape vs) = putBinaryValue " u32" shape vs   put (U64Value shape vs) = putBinaryValue " u64" shape vs+  put (F16Value shape vs) = putBinaryValue " f16" shape vs   put (F32Value shape vs) = putBinaryValue " f32" shape vs   put (F64Value shape vs) = putBinaryValue " f64" shape vs   -- Bool must be treated specially because the Storable instance@@ -122,6 +125,7 @@       " u16" -> get' (U16Value shape') num_elems 2       " u32" -> get' (U32Value shape') num_elems 4       " u64" -> get' (U64Value shape') num_elems 8+      " f16" -> get' (F16Value shape') num_elems 2       " f32" -> get' (F32Value shape') num_elems 4       " f64" -> get' (F64Value shape') num_elems 8       -- Bool must be treated specially because the Storable instance@@ -181,12 +185,18 @@     U16Value shape vs -> f pNum shape vs     U32Value shape vs -> f pNum shape vs     U64Value shape vs -> f pNum shape vs+    F16Value shape vs -> f pF16 shape vs     F32Value shape vs -> f pF32 shape vs     F64Value shape vs -> f pF64 shape vs     BoolValue shape vs -> f pBool shape vs   where     suffix = primTypeText $ valueElemType v     pNum x = TB.fromString (show x) <> TB.fromText suffix+    pF16 x+      | isInfinite x, x >= 0 = "f16.inf"+      | isInfinite x, x < 0 = "-f16.inf"+      | isNaN x = "f16.nan"+      | otherwise = pNum x     pF32 x       | isInfinite x, x >= 0 = "f32.inf"       | isInfinite x, x < 0 = "-f32.inf"@@ -204,7 +214,7 @@     f p shape vs = LT.toStrict $ TB.toLazyText $ arrayText p (SVec.toList shape) vs  -- | The scalar types supported by the value format.-data PrimType = I8 | I16 | I32 | I64 | U8 | U16 | U32 | U64 | F32 | F64 | Bool+data PrimType = I8 | I16 | I32 | I64 | U8 | U16 | U32 | U64 | F16 | F32 | F64 | Bool   deriving (Eq, Ord, Show, Enum, Bounded)  -- | Textual primitive type as a strict text.@@ -217,6 +227,7 @@ primTypeText U16 = "u16" primTypeText U32 = "u32" primTypeText U64 = "u64"+primTypeText F16 = "f16" primTypeText F32 = "f32" primTypeText F64 = "f64" primTypeText Bool = "bool"@@ -231,6 +242,7 @@ primTypeBytes U16 = 2 primTypeBytes U32 = 4 primTypeBytes U64 = 8+primTypeBytes F16 = 2 primTypeBytes F32 = 4 primTypeBytes F64 = 8 primTypeBytes Bool = 1@@ -267,6 +279,7 @@ valueElemType U16Value {} = U16 valueElemType U32Value {} = U32 valueElemType U64Value {} = U64+valueElemType F16Value {} = F16 valueElemType F32Value {} = F32 valueElemType F64Value {} = F64 valueElemType BoolValue {} = Bool@@ -281,6 +294,7 @@ valueShape (U16Value shape _) = SVec.toList shape valueShape (U32Value shape _) = SVec.toList shape valueShape (U64Value shape _) = SVec.toList shape+valueShape (F16Value shape _) = SVec.toList shape valueShape (F32Value shape _) = SVec.toList shape valueShape (F64Value shape _) = SVec.toList shape valueShape (BoolValue shape _) = SVec.toList shape@@ -311,6 +325,7 @@           U16Value _ vs -> slices U16Value vs           U32Value _ vs -> slices U32Value vs           U64Value _ vs -> slices U64Value vs+          F16Value _ vs -> slices F16Value vs           F32Value _ vs -> slices F32Value vs           F64Value _ vs -> slices F64Value vs           BoolValue _ vs -> slices BoolValue vs@@ -423,6 +438,7 @@       U16Value {} -> U16Value res_shape $ foldMap getVec (x : xs)       U32Value {} -> U32Value res_shape $ foldMap getVec (x : xs)       U64Value {} -> U64Value res_shape $ foldMap getVec (x : xs)+      F16Value {} -> F16Value res_shape $ foldMap getVec (x : xs)       F32Value {} -> F32Value res_shape $ foldMap getVec (x : xs)       F64Value {} -> F64Value res_shape $ foldMap getVec (x : xs)       BoolValue {} -> BoolValue res_shape $ foldMap getVec (x : xs)@@ -435,6 +451,7 @@       getVec (U16Value _ vec) = SVec.unsafeCast vec       getVec (U32Value _ vec) = SVec.unsafeCast vec       getVec (U64Value _ vec) = SVec.unsafeCast vec+      getVec (F16Value _ vec) = SVec.unsafeCast vec       getVec (F32Value _ vec) = SVec.unsafeCast vec       getVec (F64Value _ vec) = SVec.unsafeCast vec       getVec (BoolValue _ vec) = SVec.unsafeCast vec
src/Futhark/Data/Compare.hs view
@@ -98,6 +98,8 @@         compareNum got_vs expected_vs       (U64Value _ got_vs, U64Value _ expected_vs) ->         compareNum got_vs expected_vs+      (F16Value _ got_vs, F16Value _ expected_vs) ->+        compareFloat (tolerance (toleranceFloat tol) expected_vs) got_vs expected_vs       (F32Value _ got_vs, F32Value _ expected_vs) ->         compareFloat (tolerance (toleranceFloat tol) expected_vs) got_vs expected_vs       (F64Value _ got_vs, F64Value _ expected_vs) ->
src/Futhark/Data/Parser.hs view
@@ -43,6 +43,7 @@       "u16" $> U16,       "u32" $> U32,       "u64" $> U64,+      "f16" $> F16,       "f32" $> F32,       "f64" $> F64,       "bool" $> Bool@@ -63,7 +64,7 @@ parseIntConst :: Parsec Void T.Text Value parseIntConst = do   x <- parseInteger-  notFollowedBy $ "f32" <|> "f64" <|> "." <|> "e"+  notFollowedBy $ choice ["f16", "f32", "f64", ".", "e"]   choice     [ intV I8Value x "i8",       intV I16Value x "i16",@@ -82,10 +83,15 @@ parseFloatConst :: Parsec Void T.Text Value parseFloatConst =   choice-    [ "f32.nan" $> scalar F32Value (0 / 0),+    [ "f16.nan" $> scalar F16Value (0 / 0),+      "f32.nan" $> scalar F32Value (0 / 0),       "f64.nan" $> scalar F64Value (0 / 0),+      --+      "f16.inf" $> scalar F16Value (1 / 0),       "f32.inf" $> scalar F32Value (1 / 0),       "f64.inf" $> scalar F64Value (1 / 0),+      --+      "-f16.inf" $> scalar F16Value (-1 / 0),       "-f32.inf" $> scalar F32Value (-1 / 0),       "-f64.inf" $> scalar F64Value (-1 / 0),       numeric@@ -95,7 +101,8 @@       x <-         signed (pure ()) $ choice [try float, fromInteger <$> decimal]       choice-        [ floatV F32Value x "f32",+        [ floatV F16Value x "f16",+          floatV F32Value x "f32",           floatV F64Value x "f64",           floatV F64Value x ""         ]@@ -140,6 +147,7 @@     U16 -> U16Value (SVec.fromList dims) mempty     U32 -> U32Value (SVec.fromList dims) mempty     U64 -> U64Value (SVec.fromList dims) mempty+    F16 -> F16Value (SVec.fromList dims) mempty     F32 -> F32Value (SVec.fromList dims) mempty     F64 -> F64Value (SVec.fromList dims) mempty     Bool -> BoolValue (SVec.fromList dims) mempty
tests/Tests.hs view
@@ -105,8 +105,10 @@       test "3i64" $ scalar I64Value 3,       test "1.0" $ scalar F64Value 1,       test "2f32" $ scalar F32Value 2,+      test "2f16" $ scalar F16Value 2,       test "3.1f64" $ scalar F64Value 3.1,       test "f32.nan" $ scalar F32Value (0 / 0),+      test "f16.nan" $ scalar F16Value (0 / 0),       test "f64.nan" $ scalar F64Value (0 / 0),       test "f64.inf" $ scalar F64Value (1 / 0),       test "-f64.inf" $ scalar F64Value (-1 / 0),