packages feed

storable-static-array 0.6.0.0 → 0.6.0.1

raw patch · 4 files changed

+32/−14 lines, 4 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Foreign.Marshal.StaticVector: instance (IxStatic k d, Storable e, Vector b e) => Storable (StaticVector k b d e)
- Foreign.Marshal.StaticVector: instance (Vector b e, Show e) => Show (StaticVector k b d e)
- Foreign.Marshal.StaticVector: instance Eq (backing elements) => Eq (StaticVector k backing dimensions elements)
+ Foreign.Marshal.StaticVector: instance [overlap ok] (IxStatic k d, Storable e) => Storable (StaticVector k Vector d e)
+ Foreign.Marshal.StaticVector: instance [overlap ok] (IxStatic k d, Storable e, Vector b e) => Storable (StaticVector k b d e)
+ Foreign.Marshal.StaticVector: instance [overlap ok] (Vector b e, Show e) => Show (StaticVector k b d e)
+ Foreign.Marshal.StaticVector: instance [overlap ok] Eq (backing elements) => Eq (StaticVector k backing dimensions elements)

Files

Data/Ix/Static.hs view
@@ -55,7 +55,7 @@ fromNat :: forall (proxy :: Nat -> *) (n :: Nat). SingI n => proxy n -> Int fromNat _ = fromInteger $ fromSing (sing :: Sing n) --- | This class connects dimension description types with 'IArray'+-- | This class connects dimension description types with 'Ix' -- index types and values. class Ix (Index d) => IxStatic d where     -- | The index type for this dimension description@@ -73,9 +73,7 @@     type Index (n ': n2 ': ns) = (Int, Index (n2 ': ns))     taggedBounds = Tagged ((0, b0), (fromNat (Proxy :: Proxy n) - 1, bn))       where-        (b0, bn) = untag (taggedBounds :: Tagged (n2 ': ns)-                                                 (Index (n2 ': ns),-                                                  Index (n2 ': ns)))+        (b0, bn) = proxy taggedBounds (Proxy :: Proxy (n2 ': ns))  instance SingI a => IxStatic (a :: Nat) where     type Index a = Int@@ -143,8 +141,7 @@     type Index (n :. n2 :. ns) = (Int, Index (n2 :. ns))     taggedBounds = Tagged ((0, b0), (fromNat (Proxy :: Proxy n) - 1, bn))       where-        (b0, bn) = untag (taggedBounds :: Tagged (n2 :. ns)-                                          (Index (n2 :. ns), Index (n2 :. ns)))+        (b0, bn) = proxy taggedBounds (Proxy :: Proxy (n2 :. ns))  -- | An alternative dimension type to promoted pairs, provided for -- syntactic compatibility with @CPP@.
Foreign/Marshal/StaticArray.hs view
@@ -51,7 +51,7 @@  import Data.Ix.Static -import Data.Tagged+import Data.Proxy  import Foreign.Ptr import Foreign.Storable@@ -79,7 +79,7 @@ {-# INLINEABLE staticBounds #-} staticBounds :: forall b d e. IxStatic d =>                 StaticArray b d e -> (Index d, Index d)-staticBounds _ = untag (taggedBounds :: Tagged d (Index d, Index d))+staticBounds _ = proxy taggedBounds (Proxy :: Proxy d)  -- | Create a new 'StaticArray' from a list of indices and -- elements. This has all the semantic caveats of 'array', except that
Foreign/Marshal/StaticVector.hs view
@@ -4,6 +4,7 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE RecursiveDo #-}+{-# LANGUAGE OverlappingInstances #-} {-|  This module defines 'StaticVector', a simple wrapper around@@ -32,14 +33,17 @@ import Data.Ix import Data.Ix.Static -import qualified Data.Vector.Generic         as VG-import qualified Data.Vector.Generic.Mutable as VGM+import qualified Data.Vector.Generic          as VG+import qualified Data.Vector.Generic.Mutable  as VGM+import qualified Data.Vector.Storable         as VS+import qualified Data.Vector.Storable.Mutable as VSM -import Data.Tagged+import Data.Proxy  import Foreign.Ptr import Foreign.Storable import Foreign.Marshal.Array+import Foreign.Marshal.Utils   -- | A minimal 'VG.Vector' wrapper that encodes the full dimensions of@@ -67,7 +71,7 @@ {-# INLINEABLE staticBounds #-} staticBounds :: forall b d e. IxStatic d =>                 StaticVector b d e -> (Index d, Index d)-staticBounds _ = untag (taggedBounds :: Tagged d (Index d, Index d))+staticBounds _ = proxy taggedBounds (Proxy :: Proxy d)  -- | Get the compile-time size from a 'StaticVector'. Does not examine -- its argument.@@ -91,7 +95,7 @@ instance (IxStatic d, Storable e, VG.Vector b e) =>          Storable (StaticVector b d e) where     {-# INLINEABLE sizeOf #-}-    sizeOf a = sizeOf (undefined :: e) * rangeSize (staticBounds a)+    sizeOf a = sizeOf (undefined :: e) * staticSize a     {-# INLINEABLE alignment #-}     alignment _ = alignment (undefined :: e)     {-# INLINEABLE poke #-}@@ -109,5 +113,22 @@                 x <- peek $ advancePtr src i                 VGM.unsafeWrite v i x +            sv <- StaticVector <$> VG.unsafeFreeze v+        return sv++instance (IxStatic d, Storable e) =>+         Storable (StaticVector VS.Vector d e) where+    {-# INLINEABLE sizeOf #-}+    sizeOf a = sizeOf (undefined :: e) * staticSize a+    {-# INLINEABLE alignment #-}+    alignment _ = alignment (undefined :: e)+    {-# INLINEABLE poke #-}+    poke dst sv@(StaticVector v) = do+        VS.unsafeWith v $ \src -> copyBytes dst (castPtr src) $ sizeOf sv+    {-# INLINEABLE peek #-}+    peek src = do+        rec let size = staticSize sv+            v <- VSM.unsafeNew size+            VSM.unsafeWith v $ \dst -> copyBytes (castPtr dst) src $ sizeOf sv             sv <- StaticVector <$> VG.unsafeFreeze v         return sv
storable-static-array.cabal view
@@ -1,5 +1,5 @@ name:                storable-static-array-version:             0.6.0.0+version:             0.6.0.1 synopsis:            Statically-sized array wrappers with Storable instances                      for FFI marshaling description:         Uses type-level numeric literals to wrap arrays in a type