packages feed

Vec 0.9.3 → 0.9.4

raw patch · 5 files changed

+112/−8 lines, 5 files

Files

Data/Vec.hs view
@@ -132,6 +132,5 @@ import Data.Vec.LinAlg import Data.Vec.Packed import Data.Vec.Nat-import Data.Vec.Instances  
Data/Vec/Base.hs view
@@ -21,8 +21,8 @@                        take,drop,head,tail,sum,last,product,                        minimum,maximum,length) import qualified Prelude as P--+import Foreign+import Test.QuickCheck  -- | The vector constructor. @(:.)@ for vectors is like @(:)@ for lists, and -- @()@ takes the place of @[]@. (The list of instances here is not meant to be@@ -109,12 +109,12 @@   -- this when you mean that. Because number literals can be converted to   -- vectors, and matrices are vectors of vectors, the following works   -- -  -- > fromList [1,2,3,4] :: 'Mat22' Int +  -- > fromList [1,2,3,4] :: Mat22 Int    -- > > ((1):.(1):.()):.((2):.(2):.()):.()   --   -- even though we meant to do this   ---  -- > 'matFromList' [1,2,3,4] :: 'Mat22' Int +  -- > matFromList [1,2,3,4] :: Mat22 Int    -- > > ((1):.(2):.()):.((3):.(4):.()):.()   fromList :: [a] -> v @@ -448,3 +448,110 @@   ++-- Storable instances. ++instance Storable a => Storable (a:.()) where+  sizeOf _ = sizeOf (undefined::a)+  alignment _ = alignment (undefined::a)+  peek p = peek (castPtr p) >>= \a -> return (a:.())+  peekByteOff p o = peek (p`plusPtr`o)+  peekElemOff p i = peek (p`plusPtr`(i*sizeOf(undefined::a)))+  poke p (a:._) = poke (castPtr p) a+  pokeByteOff p o x = poke (p`plusPtr`o) x+  pokeElemOff p i x = poke (p`plusPtr`(i*sizeOf(undefined::a))) x+  {-# INLINE sizeOf #-}+  {-# INLINE alignment #-}+  {-# INLINE peek #-}+  {-# INLINE peekByteOff #-}+  {-# INLINE peekElemOff #-}+  {-# INLINE poke #-}+  {-# INLINE pokeByteOff #-}+  {-# INLINE pokeElemOff #-}++instance (Vec (Succ (Succ n)) a (a:.a:.v), Storable a, Storable (a:.v)) +  => Storable (a:.a:.v) +  where+  sizeOf _ = sizeOf (undefined::a) + sizeOf (undefined::(a:.v))+  alignment _ = alignment (undefined::a)+  peek p = +    peek (castPtr p) >>= \a -> +    peek (castPtr (p`plusPtr`sizeOf(undefined::a))) >>= \v -> +    return (a:.v)+  peekByteOff p o = peek (p`plusPtr`o)+  peekElemOff p i = peek (p`plusPtr`(i*sizeOf(undefined::(a:.a:.v))))+  poke p (a:.v) = +    poke (castPtr p) a >> +    poke (castPtr (p`plusPtr`sizeOf(undefined::a))) v+  pokeByteOff p o x = poke (p`plusPtr`o) x+  pokeElemOff p i x = poke (p`plusPtr`(i*sizeOf(undefined::(a:.a:.v)))) x+  {-# INLINE sizeOf #-}+  {-# INLINE alignment #-}+  {-# INLINE peek #-}+  {-# INLINE peekByteOff #-}+  {-# INLINE peekElemOff #-}+  {-# INLINE poke #-}+  {-# INLINE pokeByteOff #-}+  {-# INLINE pokeElemOff #-}+++-- Num and Fractional instances : All arithmetic is done component-wise and+-- literals construct uniform vectors and matrices. +--+-- The rule is : +--    If the method is unary, it's a map.  +--    If it's binary, it's a zipWith.++instance+    (Eq (a:.u)+    ,Show (a:.u)+    ,Num a+    ,Map a a (a:.u) (a:.u) +    ,ZipWith a a a (a:.u) (a:.u) (a:.u)+    ,Vec (Succ l) a (a:.u)+    )+    => Num (a:.u) +  where+    (+) u v = zipWith (+) u v +    (-) u v = zipWith (-) u v+    (*) u v = zipWith (*) u v+    abs u = map abs u+    signum u = map signum u+    fromInteger i = vec (fromInteger i)+    {-# INLINE (+) #-}+    {-# INLINE (-) #-}+    {-# INLINE (*) #-}+    {-# INLINE abs #-}+    {-# INLINE signum #-}+    {-# INLINE fromInteger #-}+++instance +    (Fractional a+    ,Ord (a:.u)+    ,ZipWith a a a (a:.u) (a:.u) (a:.u)+    ,Map a a (a:.u) (a:.u)+    ,Vec (Succ l) a (a:.u)+    ,Show (a:.u)+    ) +    => Fractional (a:.u) +  where+    (/) u v = zipWith (/) u v+    recip u = map recip u+    fromRational r = vec (fromRational r)+    {-# INLINE (/) #-}+    {-# INLINE recip #-}+    {-# INLINE fromRational #-}++++-- Arbitrary instances++instance Arbitrary a => Arbitrary (a:.()) where+  arbitrary = arbitrary >>= return . (:.())+  coarbitrary (a:._) = variant 0 . coarbitrary a++instance (Length (a:.v) (Succ n), Arbitrary a', Arbitrary (a:.v)) => Arbitrary (a':.a:.v) where+  arbitrary = arbitrary >>= \a -> +              arbitrary >>= \v -> return (a:.v);+  coarbitrary (a:.v) = variant (length v) . coarbitrary a . coarbitrary v
Data/Vec/LinAlg.hs view
@@ -51,7 +51,6 @@ import qualified Prelude as P import Data.Vec.Base import Data.Vec.Nat-import Data.Vec.Instances  import Control.Monad import Data.Maybe
Data/Vec/Packed.hs view
@@ -50,7 +50,6 @@ import Data.Vec.Base as V import Data.Vec.Nat import Data.Vec.LinAlg --just for haddock-import Data.Vec.Instances import Data.Word import Data.Int import Foreign
Vec.cabal view
@@ -1,5 +1,5 @@ Name:                Vec-Version:             0.9.3+Version:             0.9.4 License:             BSD3 License-file:        LICENSE Author:              Scott E. Dillard