fixed-vector 0.1.2 → 0.1.2.1
raw patch · 4 files changed
+164/−10 lines, 4 filesdep +doctestdep +filemanipdep ~basePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: doctest, filemanip
Dependency ranges changed: base
API changes (from Hackage documentation)
+ Data.Vector.Fixed: eq :: (Vector v a, Eq a) => v a -> v a -> Bool
- Data.Vector.Fixed: imap :: (Vector v a, Vector v b, Monad m) => (Int -> a -> b) -> v a -> v b
+ Data.Vector.Fixed: imap :: (Vector v a, Vector v b) => (Int -> a -> b) -> v a -> v b
Files
- Data/Vector/Fixed.hs +137/−7
- Data/Vector/Fixed/Boxed.hs +1/−1
- fixed-vector.cabal +13/−2
- test/Doctests.hs +13/−0
Data/Vector/Fixed.hs view
@@ -48,6 +48,8 @@ , tail , tailWith , (!)+ -- ** Comparison+ , eq -- ** Map , map , mapM@@ -112,13 +114,21 @@ -- TODO: does not fuse!--- | Newtype wrapper for partially constructed vectors. /n/ is number--- of uninitialized elements.++-- | Generic function for construction of arbitrary vectors. It+-- represents partially constructed vector where /n/ is number of+-- uninitialized elements, /v/ is type of vector and /a/ element type. ----- Example of use:+-- Uninitialized vector could be obtained from 'con' and vector+-- elements could be added from left to right using '|>' operator.+-- Finally it could be converted to vector using 'vec' function. ----- >>> vec $ con |> 1 |> 3 :: Complex Double--- > 1 :+ 3+-- Construction of complex number which could be seen as 2-element vector:+--+-- >>> import Data.Complex+-- >>> vec $ con |> 1 |> 3 :: Complex Double+-- 1.0 :+ 3.0+-- newtype New n v a = New (Fn n a (v a)) -- | Convert fully applied constructor to vector@@ -145,6 +155,21 @@ ---------------------------------------------------------------- -- | Replicate value /n/ times.+--+-- Examples:+--+-- >>> import Data.Vector.Fixed.Boxed (Vec2)+-- >>> replicate 1 :: Vec2 Int -- Two element vector+-- fromList [1,1]+--+-- >>> import Data.Vector.Fixed.Boxed (Vec3)+-- >>> replicate 2 :: Vec3 Double -- Three element vector+-- fromList [2.0,2.0,2.0]+--+-- >>> import Data.Vector.Fixed.Boxed (Vec)+-- >>> replicate "foo" :: Vec N5 String+-- fromList ["foo","foo","foo","foo","foo"]+-- replicate :: Vector v a => a -> v a {-# INLINE replicate #-} replicate x = create $ Cont@@ -159,6 +184,17 @@ h -- | Execute monadic action for every element of vector.+--+-- Examples:+--+-- >>> import Data.Vector.Fixed.Boxed (Vec2,Vec3)+-- >>> replicateM (Just 3) :: Maybe (Vec3 Int)+-- Just fromList [3,3,3]+-- >>> replicateM (putStrLn "Hi!") :: IO (Vec2 ())+-- Hi!+-- Hi!+-- fromList [(),()]+-- replicateM :: (Vector v a, Monad m) => m a -> m (v a) {-# INLINE replicateM #-} replicateM x = replicateFM x construct@@ -173,6 +209,17 @@ ---------------------------------------------------------------- -- | Unit vector along Nth axis,+--+-- Examples:+--+-- >>> import Data.Vector.Fixed.Boxed (Vec3)+-- >>> basis 0 :: Vec3 Int+-- fromList [1,0,0]+-- >>> basis 1 :: Vec3 Int+-- fromList [0,1,0]+-- >>> basis 2 :: Vec3 Int+-- fromList [0,0,1]+-- basis :: forall v a. (Vector v a, Num a) => Int -> v a {-# INLINE basis #-} basis n = create $ Cont@@ -189,7 +236,14 @@ ---------------------------------------------------------------- --- | Generate vector.+-- | Generate vector from function which maps element's index to its value.+--+-- Examples:+--+-- >>> import Data.Vector.Fixed.Unboxed (Vec)+-- >>> generate (^2) :: Vec N4 Int+-- fromList [0,1,4,9]+-- generate :: forall v a. (Vector v a) => (Int -> a) -> v a {-# INLINE generate #-} generate f = create $ Cont@@ -218,6 +272,14 @@ ---------------------------------------------------------------- -- | First element of vector.+--+-- Examples:+--+-- >>> import Data.Vector.Fixed.Boxed (Vec3)+-- >>> let x = vec $ con |> 1 |> 2 |> 3 :: Vec3 Int+-- >>> head x+-- 1+-- head :: (Vector v a, Dim v ~ S n) => v a -> a {-# INLINE head #-} head v = inspectV v@@ -234,6 +296,14 @@ ---------------------------------------------------------------- -- | Tail of vector.+--+-- Examples:+--+-- >>> import Data.Vector.Fixed.Boxed (Vec2, Vec3)+-- >>> let x = vec $ con |> 1 |> 2 |> 3 :: Vec3 Int+-- >>> tail x :: Vec2 Int+-- fromList [2,3]+-- tail :: (Vector v a, Vector w a, Dim v ~ S (Dim w)) => v a -> w a {-# INLINE tail #-}@@ -250,6 +320,14 @@ -- function. For example @'sum' . 'tail'@ will fail with unhelpful -- error message because return value of @tail@ is polymorphic. But -- @'tailWith' 'sum'@ works just fine.+--+-- Examples:+--+-- >>> import Data.Vector.Fixed.Boxed (Vec3)+-- >>> let x = vec $ con |> 1 |> 2 |> 3 :: Vec3 Int+-- >>> tailWith sum x+-- 5+-- tailWith :: (Arity n, Vector v a, Dim v ~ S n) => (forall w. (Vector w a, Dim w ~ n) => w a -> r) -- ^ Continuation -> v a -- ^ Vector@@ -370,17 +448,54 @@ sum = foldl (+) 0 -- | Maximum element of vector+--+-- Examples:+--+-- >>> import Data.Vector.Fixed.Boxed (Vec3)+-- >>> let x = vec $ con |> 1 |> 2 |> 3 :: Vec3 Int+-- >>> maximum x+-- 3+-- maximum :: (Vector v a, Dim v ~ S n, Ord a) => v a -> a {-# INLINE maximum #-} maximum = foldl1 max -- | Minimum element of vector+--+-- Examples:+--+-- >>> import Data.Vector.Fixed.Boxed (Vec3)+-- >>> let x = vec $ con |> 1 |> 2 |> 3 :: Vec3 Int+-- >>> minimum x+-- 1+-- minimum :: (Vector v a, Dim v ~ S n, Ord a) => v a -> a {-# INLINE minimum #-} minimum = foldl1 min +---------------------------------------------------------------- +-- | Test two vectors for equality.+--+-- Examples:+--+-- >>> import Data.Vector.Fixed.Boxed (Vec2)+-- >>> let v0 = basis 0 :: Vec2 Int+-- >>> let v1 = basis 1 :: Vec2 Int+-- >>> v0 `eq` v0+-- True+-- >>> v0 `eq` v1+-- False+--+eq :: (Vector v a, Eq a) => v a -> v a -> Bool+{-# INLINE eq #-}+eq v w = inspectV w+ $ inspectV v+ $ fmap (fmap runID)+ $ izipWithFM (\_ a b -> return (a == b))+ $ foldlF (&&) True+ ---------------------------------------------------------------- -- | Map over vector@@ -425,7 +540,7 @@ -- | Apply function to every element of the vector and its index.-imap :: (Vector v a, Vector v b, Monad m) =>+imap :: (Vector v a, Vector v b) => (Int -> a -> b) -> v a -> v b {-# INLINE imap #-} imap f v = create $ Cont@@ -464,6 +579,21 @@ ---------------------------------------------------------------- -- | Zip two vector together using function.+--+-- Examples:+--+-- >>> import Data.Vector.Fixed.Boxed (Vec3)+-- >>> let b0 = basis 0 :: Vec3 Int+-- >>> let b1 = basis 1 :: Vec3 Int+-- >>> let b2 = basis 2 :: Vec3 Int+-- >>> let vplus x y = zipWith (+) x y+-- >>> vplus b0 b1+-- fromList [1,1,0]+-- >>> vplus b0 b2+-- fromList [1,0,1]+-- >>> vplus b1 b2+-- fromList [0,1,1]+-- zipWith :: (Vector v a, Vector v b, Vector v c) => (a -> b -> c) -> v a -> v b -> v c {-# INLINE zipWith #-}
Data/Vector/Fixed/Boxed.hs view
@@ -27,7 +27,7 @@ -- Data type ---------------------------------------------------------------- --- | Unboxed vector with fixed length+-- | Vector with fixed length which can hold any value. newtype Vec n a = Vec (Array a) -- | Mutable unboxed vector with fixed length
fixed-vector.cabal view
@@ -1,5 +1,5 @@ Name: fixed-vector-Version: 0.1.2+Version: 0.1.2.1 Synopsis: Generic vectors with fixed length Description: Generic vectors with fixed length. Package is structured as follows:@@ -28,7 +28,7 @@ * @foldM@ and @tailWith@ added. Type synonyms for numbers up to 6 are added. @Fun@ is reexported from @Data.Vector.Fixed@. -Cabal-Version: >= 1.6+Cabal-Version: >= 1.8 License: BSD3 License-File: LICENSE Author: Aleksey Khudyakov <alexey.skladnoy@gmail.com>@@ -59,3 +59,14 @@ Data.Vector.Fixed.Primitive Data.Vector.Fixed.Unboxed Data.Vector.Fixed.Storable++Test-Suite doctests+ Type: exitcode-stdio-1.0+ Hs-Source-Dirs: test+ Main-Is: Doctests.hs+ Build-Depends:+ base >=3 && <5,+ primitive,+ -- Additional test dependencies.+ doctest == 0.9.*,+ filemanip == 0.3.6.*
+ test/Doctests.hs view
@@ -0,0 +1,13 @@+module Main+where++import Test.DocTest+import System.FilePath.Find ((==?), always, extension, find)++find_sources :: IO [FilePath]+find_sources = find always (extension ==? ".hs") "Data"++main :: IO ()+main = do+ sources <- find_sources+ doctest $ sources