linear-accelerate 0.3 → 0.4
raw patch · 15 files changed
+187/−110 lines, 15 filesdep +doctestdep ~basesetup-changed
Dependencies added: doctest
Dependency ranges changed: base
Files
- .travis.yml +11/−6
- CHANGELOG.markdown +33/−2
- README.markdown +2/−0
- Setup.lhs +24/−34
- Warning.hs +5/−0
- linear-accelerate.cabal +15/−5
- src/Data/Array/Accelerate/Linear/Epsilon.hs +4/−4
- src/Data/Array/Accelerate/Linear/Matrix.hs +23/−21
- src/Data/Array/Accelerate/Linear/Metric.hs +4/−1
- src/Data/Array/Accelerate/Linear/V1.hs +3/−3
- src/Data/Array/Accelerate/Linear/V2.hs +7/−7
- src/Data/Array/Accelerate/Linear/V3.hs +1/−1
- src/Data/Array/Accelerate/Linear/V4.hs +1/−1
- src/Data/Array/Accelerate/Linear/Vector.hs +29/−25
- tests/doctests.hs +25/−0
.travis.yml view
@@ -4,7 +4,8 @@ # directory to speed subsequent compilations. # language: generic-dist: precise+dist: trusty+sudo: false cache: directories:@@ -23,18 +24,22 @@ matrix: include:- - env: GHC=7.8.4 CABAL=1.18+ - env: GHC=7.8.4 CABAL=1.24 compiler: "GHC 7.8"- addons: { apt: { sources: [ *apt_sources ], packages: [ *apt_packages, cabal-install-1.18 ] }}+ addons: { apt: { sources: [ *apt_sources ], packages: [ *apt_packages, cabal-install-1.24 ] }} - - env: GHC=7.10.3 CABAL=1.22+ - env: GHC=7.10.3 CABAL=1.24 compiler: "GHC 7.10"- addons: { apt: { sources: [ *apt_sources ], packages: [ *apt_packages, cabal-install-1.22 ] }}+ addons: { apt: { sources: [ *apt_sources ], packages: [ *apt_packages, cabal-install-1.24 ] }} - env: GHC=8.0.2 CABAL=1.24 compiler: "GHC 8.0" addons: { apt: { sources: [ *apt_sources ], packages: [ *apt_packages, cabal-install-1.24 ] }} + - env: GHC=8.2.0 CABAL=1.24+ compiler: "GHC 8.2"+ addons: { apt: { sources: [ *apt_sources ], packages: [ *apt_packages, cabal-install-1.24 ] }}+ # - env: GHC=head CABAL=head # compiler: "GHC HEAD" # addons: { apt: { sources: [ *apt_sources ], packages: [ *apt_packages, ghc-head, cabal-install-head ] }}@@ -65,7 +70,7 @@ cabal install cabal haddock else- stack build --no-terminal --haddock --no-haddock-deps+ stack test --no-terminal --haddock --no-haddock-deps fi after_success:
CHANGELOG.markdown view
@@ -1,4 +1,35 @@-0.1----+# Change Log++Notable changes to the project will be documented in this file.++The format is based on [Keep a Changelog](http://keepachangelog.com/) and the+project adheres to the [Haskell Package Versioning Policy+(PVP)](https://pvp.haskell.org)++## [0.4]++* Revamp `Setup.hs` to use `cabal-doctest`. This makes `linear-accelerate`+ build with `Cabal-2.0`.+* Fix handedness of `(-^)` and `(^-)`.+* Re-enable the `doctest`s.++## [0.3]++* Expanded API coverage++## [0.2]++* Fix [#1]: Move `Data.Complex` instances into the `accelerate` package++## [0.1]+ * Repository initialized+++[0.4]: https://github.com/ekmett/linear-accelerate/compare/v0.3...v0.4+[0.3]: https://github.com/ekmett/linear-accelerate/compare/v0.2...v0.3+[0.2]: https://github.com/ekmett/linear-accelerate/compare/v0.1...v0.2+[0.1]: https://github.com/ekmett/linear-accelerate/compare/3db20f05af0a1488fcbc3ea28f8561ce73289b73...v0.1++[#1]: https://github.com/ekmett/linear-accelerate/issues/1
README.markdown view
@@ -1,6 +1,8 @@ linear-accelerate ================= +[](https://hackage.haskell.org/package/linear-accelerate) [](http://travis-ci.org/ekmett/linear-accelerate)+ This package provides orphan instances that allows you to use `linear` vector spaces in `accelerate`. Contact Information
Setup.lhs view
@@ -1,44 +1,34 @@-#!/usr/bin/runhaskell \begin{code}+{-# LANGUAGE CPP #-} {-# OPTIONS_GHC -Wall #-} module Main (main) where -import Data.List ( nub )-import Data.Version ( showVersion )-import Distribution.Package ( PackageName(PackageName), PackageId, InstalledPackageId, packageVersion, packageName )-import Distribution.PackageDescription ( PackageDescription(), TestSuite(..) )-import Distribution.Simple ( defaultMainWithHooks, UserHooks(..), simpleUserHooks )-import Distribution.Simple.Utils ( rewriteFile, createDirectoryIfMissingVerbose )-import Distribution.Simple.BuildPaths ( autogenModulesDir )-import Distribution.Simple.Setup ( BuildFlags(buildVerbosity), fromFlag )-import Distribution.Simple.LocalBuildInfo ( withLibLBI, withTestLBI, LocalBuildInfo(), ComponentLocalBuildInfo(componentPackageDeps) )-import Distribution.Verbosity ( Verbosity )-import System.FilePath ( (</>) )+#ifndef MIN_VERSION_cabal_doctest+#define MIN_VERSION_cabal_doctest(x,y,z) 0+#endif +#if MIN_VERSION_cabal_doctest(1,0,0)++import Distribution.Extra.Doctest ( defaultMainWithDoctests ) main :: IO ()-main = defaultMainWithHooks simpleUserHooks- { buildHook = \pkg lbi hooks flags -> do- generateBuildModule (fromFlag (buildVerbosity flags)) pkg lbi- buildHook simpleUserHooks pkg lbi hooks flags- }+main = defaultMainWithDoctests "doctests" -generateBuildModule :: Verbosity -> PackageDescription -> LocalBuildInfo -> IO ()-generateBuildModule verbosity pkg lbi = do- let dir = autogenModulesDir lbi- createDirectoryIfMissingVerbose verbosity True dir- withLibLBI pkg lbi $ \_ libcfg -> do- withTestLBI pkg lbi $ \suite suitecfg -> do- rewriteFile (dir </> "Build_" ++ testName suite ++ ".hs") $ unlines- [ "module Build_" ++ testName suite ++ " where"- , "deps :: [String]"- , "deps = " ++ (show $ formatdeps (testDeps libcfg suitecfg))- ]- where- formatdeps = map (formatone . snd)- formatone p = case packageName p of- PackageName n -> n ++ "-" ++ showVersion (packageVersion p)+#else -testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [(InstalledPackageId, PackageId)]-testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys+#ifdef MIN_VERSION_Cabal+-- If the macro is defined, we have new cabal-install,+-- but for some reason we don't have cabal-doctest in package-db+--+-- Probably we are running cabal sdist, when otherwise using new-build+-- workflow+import Warning ()+#endif++import Distribution.Simple++main :: IO ()+main = defaultMain++#endif \end{code}
+ Warning.hs view
@@ -0,0 +1,5 @@+module Warning+ {-# WARNING ["You are configuring this package without cabal-doctest installed.",+ "The doctests test-suite will not work as a result.",+ "To fix this, install cabal-doctest before configuring."] #-}+ () where
linear-accelerate.cabal view
@@ -1,6 +1,6 @@ name: linear-accelerate category: Math, Algebra, Compilers/Interpreters, Concurrency, Data, Parallelism-version: 0.3+version: 0.4 license: BSD3 cabal-version: >= 1.8 license-file: LICENSE@@ -18,6 +18,7 @@ .vim.custom CHANGELOG.markdown README.markdown+ Warning.hs source-repository head type: git@@ -25,14 +26,14 @@ source-repository this type: git- tag: v0.3+ tag: v0.4 location: git://github.com/ekmett/linear-accelerate.git custom-setup setup-depends:- base >= 4.5- , Cabal >= 1.18- , filepath >= 1.0+ base >= 4 && < 5,+ Cabal,+ cabal-doctest >= 1 && < 1.1 library build-depends:@@ -63,3 +64,12 @@ ghc-options: -Wall -fwarn-tabs -O2 hs-source-dirs: src +test-suite doctests+ type: exitcode-stdio-1.0+ main-is: doctests.hs+ default-language: Haskell2010+ build-depends:+ base == 4.*,+ doctest >= 0.11.1 && < 0.12+ ghc-options: -Wall -threaded+ hs-source-dirs: tests
src/Data/Array/Accelerate/Linear/Epsilon.hs view
@@ -23,16 +23,16 @@ -- | Provides a fairly subjective test to see if a quantity is near zero. ----- >>> nearZero (1e-11 :: Double)+-- >>> nearZero (1e-11 :: Exp Double) -- False ----- >>> nearZero (1e-17 :: Double)+-- >>> nearZero (1e-17 :: Exp Double) -- True ----- >>> nearZero (1e-5 :: Float)+-- >>> nearZero (1e-5 :: Exp Float) -- False ----- >>> nearZero (1e-7 :: Float)+-- >>> nearZero (1e-7 :: Exp Float) -- True -- class Num a => Epsilon a where
src/Data/Array/Accelerate/Linear/Matrix.hs view
@@ -50,14 +50,12 @@ import Prelude as P + infixl 7 !*! -- | Matrix product. This can compute any combination of sparse and dense multiplication. ----- >>> V2 (V3 1 2 3) (V3 4 5 6) !*! V3 (V2 1 2) (V2 3 4) (V2 4 5)--- V2 (V2 19 25) (V2 43 58)------ >>> V2 (fromList [(1,2)]) (fromList [(2,3)]) !*! fromList [(1,V3 0 0 1), (2, V3 0 0 5)]--- V2 (V3 0 0 2) (V3 0 0 15)+-- >>> lift (V2 (V3 1 2 3) (V3 4 5 6) :: M23 Int) !*! lift (V3 (V2 1 2) (V2 3 4) (V2 4 5) :: M32 Int)+-- ((19,25),(43,58)) -- (!*!) :: (Functor m, Foldable t, Additive t, Additive n, A.Num a, Box2 m t a, Box2 t n a, Box2 m n a) => Exp (m (t a))@@ -69,8 +67,8 @@ infixl 6 !+! -- | Entry-wise matrix addition. ----- >>> V2 (V3 1 2 3) (V3 4 5 6) !+! V2 (V3 7 8 9) (V3 1 2 3)--- V2 (V3 8 10 12) (V3 5 7 9)+-- >>> lift (V2 (V3 1 2 3) (V3 4 5 6) :: M23 Int) !+! lift (V2 (V3 7 8 9) (V3 1 2 3) :: M23 Int)+-- ((8,10,12),(5,7,9)) -- (!+!) :: (Additive m, Additive n, A.Num a, Box2 m n a) => Exp (m (n a))@@ -82,8 +80,8 @@ infixl 6 !-! -- | Entry-wise matrix subtraction. ----- >>> V2 (V3 1 2 3) (V3 4 5 6) !-! V2 (V3 7 8 9) (V3 1 2 3)--- V2 (V3 (-6) (-6) (-6)) (V3 3 3 3)+-- >>> lift (V2 (V3 1 2 3) (V3 4 5 6) :: M23 Int) !-! lift (V2 (V3 7 8 9) (V3 1 2 3) :: M23 Int)+-- ((-6,-6,-6),(3,3,3)) -- (!-!) :: (Additive m, Additive n, A.Num a, Box2 m n a) => Exp (m (n a))@@ -95,8 +93,8 @@ infixl 7 !* -- | Matrix * column vector ----- >>> V2 (V3 1 2 3) (V3 4 5 6) !* V3 7 8 9--- V2 50 122+-- >>> lift (V2 (V3 1 2 3) (V3 4 5 6) :: M23 Int) !* lift (V3 7 8 9 :: V3 Int)+-- (50,122) -- (!*) :: (Functor m, Foldable r, Additive r, A.Num a, Box2 m r a, Box m a) => Exp (m (r a))@@ -108,8 +106,8 @@ infixl 7 *! -- | Row vector * matrix ----- >>> V2 1 2 *! V2 (V3 3 4 5) (V3 6 7 8)--- V3 15 18 21+-- >>> lift (V2 1 2 :: V2 Int) *! lift (V2 (V3 3 4 5) (V3 6 7 8) :: M23 Int)+-- (15,18,21) -- (*!) :: (Metric r, Additive n, Num a) => r a -> r (n a) -> n a -- f *! g = dot f <$> distribute g@@ -124,8 +122,8 @@ infixl 7 *!! -- | Scalar-matrix product ----- >>> 5 *!! V2 (V2 1 2) (V2 3 4)--- V2 (V2 5 10) (V2 15 20)+-- >>> 5 *!! lift (V2 (V2 1 2) (V2 3 4) :: M22 Int)+-- ((5,10),(15,20)) -- (*!!) :: (Functor m, Functor r, A.Num a, Box2 m r a) => Exp a@@ -137,8 +135,8 @@ infixl 7 !!* -- | Matrix-scalar product ----- >>> V2 (V2 1 2) (V2 3 4) !!* 5--- V2 (V2 5 10) (V2 15 20)+-- >>> lift (V2 (V2 1 2) (V2 3 4) :: M22 Int) !!* 5+-- ((5,10),(15,20)) -- (!!*) :: (Functor m, Functor r, A.Num a, Box2 m r a) => Exp (m (r a))@@ -159,11 +157,15 @@ -- |The identity matrix for any dimension vector. ----- >>> identity :: M44 Int--- V4 (V4 1 0 0 0) (V4 0 1 0 0) (V4 0 0 1 0) (V4 0 0 0 1)+-- >>> identity :: Exp (M44 Int)+-- let x0 = 1 in+-- let x1 = 0+-- in ((x0,x1,x1,x1),(x1,x0,x1,x1),(x1,x1,x0,x1),(x1,x1,x1,x0)) ----- >>> identity :: V3 (V3 Int)--- V3 (V3 1 0 0) (V3 0 1 0) (V3 0 0 1)+-- >>> identity :: Exp (V3 (V3 Int))+-- let x0 = 1 in+-- let x1 = 0+-- in ((x0,x1,x1),(x1,x0,x1),(x1,x1,x0)) -- identity :: forall t a. (Traversable t, Applicative t, A.Num a, Box2 t t a) => Exp (t (t a)) identity = lift (L.identity :: t (t (Exp a)))
src/Data/Array/Accelerate/Linear/Metric.hs view
@@ -27,6 +27,9 @@ import qualified Linear.Metric as L +-- $setup+-- >>> import Data.Array.Accelerate.Linear.V2 ()+-- >>> import Linear.V2 -- | Free and sparse inner product/metric spaces. --@@ -35,7 +38,7 @@ -- | Compute the inner product of two vectors or (equivalently) convert a -- vector @f a@ into a covector @f a -> a@. --- -- >>> V2 1 2 `dot` V2 3 4+ -- >>> lift (V2 1 2 :: V2 Int) `dot` lift (V2 3 4 :: V2 Int) -- 11 -- dot :: forall a. (A.Num a, Box f a)
src/Data/Array/Accelerate/Linear/V1.hs view
@@ -48,11 +48,11 @@ -- class L.R1 t => R1 t where -- |- -- >>> V1 2 ^._x+ -- >>> lift (V1 2 :: V1 Int) ^._x -- 2 --- -- >>> V1 2 & _x .~ 3- -- V1 3+ -- >>> lift (V1 2 :: V1 Int) & _x .~ 3+ -- (3) -- _x :: (Elt a, Box t a) => Lens' (Exp (t a)) (Exp a) _x = liftLens (L._x :: Lens' (t (Exp a)) (Exp a))
src/Data/Array/Accelerate/Linear/V2.hs view
@@ -50,8 +50,8 @@ -- | the counter-clockwise perpendicular vector ----- >>> perp $ V2 10 20--- V2 (-20) 10+-- >>> perp $ lift (V2 10 20 :: V2 Int)+-- (-20,10) -- perp :: forall a. A.Num a => Exp (V2 a) -> Exp (V2 a) perp = lift1 (L.perp :: V2 (Exp a) -> V2 (Exp a))@@ -68,11 +68,11 @@ -- class (L.R2 t, R1 t) => R2 t where -- |- -- >>> V2 1 2 ^._y+ -- >>> lift (V2 1 2 :: V2 Int) ^._y -- 2 --- -- >>> V2 1 2 & _y .~ 3- -- V2 1 3+ -- >>> lift (V2 1 2 :: V2 Int) & _y .~ 3+ -- (1,3) -- _y :: (Elt a, Box t a) => Lens' (Exp (t a)) (Exp a) _y = liftLens (L._y :: Lens' (t (Exp a)) (Exp a))@@ -82,8 +82,8 @@ -- |--- >>> V2 1 2 ^. _yx--- V2 2 1+-- >>> lift (V2 1 2 :: V2 Int) ^. _yx+-- (2,1) -- _yx :: forall t a. (R2 t, Elt a, Box t a) => Lens' (Exp (t a)) (Exp (V2 a)) _yx = liftLens (L._yx :: Lens' (t (Exp a)) (V2 (Exp a)))
src/Data/Array/Accelerate/Linear/V3.hs view
@@ -69,7 +69,7 @@ -- class (L.R3 t, R2 t) => R3 t where -- |- -- >>> V3 1 2 3 ^. _z+ -- >>> lift (V3 1 2 3 :: V3 Int) ^. _z -- 3 -- _z :: forall a. (Elt a, Box t a) => Lens' (Exp (t a)) (Exp a)
src/Data/Array/Accelerate/Linear/V4.hs view
@@ -86,7 +86,7 @@ -- class (L.R4 t, R3 t) => R4 t where -- |- -- >>> V4 1 2 3 4 ^._w+ -- >>> lift (V4 1 2 3 4 :: V4 Int) ^._w -- 4 -- _w :: forall a. (Elt a, Box t a) => Lens' (Exp (t a)) (Exp a)
src/Data/Array/Accelerate/Linear/Vector.hs view
@@ -31,6 +31,10 @@ infixl 6 ^+^, ^+, +^, ^-^, ^-, -^ infixl 7 ^*, *^, ^/, /^ +-- $setup+-- >>> import Data.Array.Accelerate.Linear.V2 ()+-- >>> import Linear.V2+ -- | A vector is an additive group with additional structure. -- -- TODO: Support both 'Exp' and 'Acc'@@ -44,8 +48,8 @@ -- | Compute the sum of two vectors --- -- >>> V2 1 2 ^+^ V2 3 4- -- V2 4 6+ -- >>> lift (V2 1 2 :: V2 Int) ^+^ lift (V2 3 4 :: V2 Int)+ -- (4,6) -- (^+^) :: forall a. (A.Num a, Box f a) => Exp (f a)@@ -55,8 +59,8 @@ -- | Compute the difference between two vectors --- -- >>> V2 4 5 - V2 3 1- -- V2 1 4+ -- >>> lift (V2 4 5 :: V2 Int) ^-^ lift (V2 3 1 :: V2 Int)+ -- (1,4) -- (^-^) :: forall a. (A.Num a, Box f a) => Exp (f a)@@ -86,8 +90,8 @@ -- | Compute the negation of a vector ----- >>> negated (V2 2 4)--- V2 (-2) (-4)+-- >>> negated (lift (V2 2 4 :: V2 Int))+-- (-2,-4) -- negated :: forall f a. (Functor f, A.Num a, Box f a)@@ -97,8 +101,8 @@ -- | Compute the left scalar product ----- >>> 2 *^ V2 3 4--- V2 6 8+-- >>> 2 *^ lift (V2 3 4 :: V2 Int)+-- (6,8) -- (*^) :: forall f a. (Functor f, A.Num a, Box f a) => Exp a@@ -108,8 +112,8 @@ -- | Compute the right scalar product ----- >>> V2 3 4 ^* 2--- V2 6 8+-- >>> lift (V2 3 4 :: V2 Int) ^* 2+-- (6,8) -- (^*) :: forall f a. (Functor f, A.Num a, Box f a) => Exp (f a)@@ -119,7 +123,7 @@ -- | Compute division by a scalar on the right ----- V2 4 6 ^/ 2+-- lift (V2 4 6 :: V2 Double) ^/ 2 -- V2 2 3 -- (^/) :: forall f a. (Functor f, A.Fractional a, Box f a)@@ -130,8 +134,8 @@ -- | Compute division of a scalar on the left ----- >>> 4 /^ V2 2 4--- V2 2 1+-- >>> 4 /^ lift (V2 2 4 :: V2 Double)+-- (2.0,1.0) -- (/^) :: forall f a. (Functor f, A.Fractional a, Box f a) => Exp a@@ -141,45 +145,45 @@ -- | Addition with a scalar on the left ----- >>> 2 +^ V2 3 4--- V2 5 4+-- >>> 2 +^ lift (V2 3 4 :: V2 Int)+-- (5,6) -- (+^) :: forall f a. (Functor f, A.Num a, Box f a) => Exp a -> Exp (f a) -> Exp (f a)-(+^) = lift2 ((\a f -> fmap (+a) f) :: Exp a -> f (Exp a) -> f (Exp a))+(+^) = lift2 ((\a f -> fmap (a+) f) :: Exp a -> f (Exp a) -> f (Exp a)) -- | Addition with a scalar on the right ----- >>> V2 1 2 ^+ 3--- V2 4 3+-- >>> lift (V2 1 2 :: V2 Int) ^+ 3+-- (4,5) -- (^+) :: forall f a. (Functor f, A.Num a, Box f a) => Exp (f a) -> Exp a -> Exp (f a)-(^+) = lift2 ((\f a -> fmap (a+) f) :: f (Exp a) -> Exp a -> f (Exp a))+(^+) = lift2 ((\f a -> fmap (+a) f) :: f (Exp a) -> Exp a -> f (Exp a)) -- | Subtraction with a scalar on the left ----- >>> 2 -^ V2 3 4--- V2 1 2+-- >>> 2 -^ lift (V2 3 4 :: V2 Int)+-- (-1,-2) -- (-^) :: forall f a. (Functor f, A.Num a, Box f a) => Exp a -> Exp (f a) -> Exp (f a)-(-^) = lift2 ((\a f -> fmap (A.subtract a) f) :: Exp a -> f (Exp a) -> f (Exp a))+(-^) = lift2 ((\a f -> fmap (a-) f) :: Exp a -> f (Exp a) -> f (Exp a)) -- | Subtraction with a scalar on the right ----- >>> V2 1 2 ^- 3--- V2 (-2) (-1)+-- >>> lift (V2 1 2 :: V2 Int) ^- 3+-- (-2,-1) -- (^-) :: forall f a. (Functor f, A.Num a, Box f a) => Exp (f a) -> Exp a -> Exp (f a)-(^-) = lift2 ((\f a -> fmap (a-) f) :: f (Exp a) -> Exp a -> f (Exp a))+(^-) = lift2 ((\f a -> fmap (A.subtract a) f) :: f (Exp a) -> Exp a -> f (Exp a))
+ tests/doctests.hs view
@@ -0,0 +1,25 @@+-----------------------------------------------------------------------------+-- |+-- Module : Main (doctests)+-- Copyright : (C) 2012-14 Edward Kmett+-- License : BSD-style (see the file LICENSE)+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : provisional+-- Portability : portable+--+-- This module provides doctests for a project based on the actual versions+-- of the packages it was built with. It requires a corresponding Setup.lhs+-- to be added to the project+-----------------------------------------------------------------------------+module Main where++import Build_doctests (flags, pkgs, module_sources)+import Data.Foldable (traverse_)+import Test.DocTest++main :: IO ()+main = do+ traverse_ putStrLn args+ doctest args+ where+ args = flags ++ pkgs ++ module_sources