linear 1.20.5 → 1.20.6
raw patch · 21 files changed
+563/−215 lines, 21 filesdep −directorydep −filepathdep ~deepseqdep ~doctestdep ~lenssetup-changednew-uploader
Dependencies removed: directory, filepath
Dependency ranges changed: deepseq, doctest, lens, reflection, vector
Files
- .gitignore +2/−0
- .travis.yml +79/−17
- CHANGELOG.markdown +12/−0
- README.markdown +2/−0
- Setup.lhs +163/−29
- linear.cabal +17/−9
- src/Linear/Affine.hs +52/−12
- src/Linear/Matrix.hs +1/−1
- src/Linear/Plucker.hs +24/−9
- src/Linear/Quaternion.hs +23/−7
- src/Linear/Trace.hs +3/−0
- src/Linear/V.hs +40/−8
- src/Linear/V0.hs +20/−2
- src/Linear/V1.hs +17/−4
- src/Linear/V2.hs +19/−4
- src/Linear/V3.hs +23/−8
- src/Linear/V4.hs +24/−8
- src/Linear/Vector.hs +0/−71
- tests/UnitTests.hs +10/−2
- tests/V.hs +13/−0
- tests/doctests.hs +19/−24
.gitignore view
@@ -1,4 +1,5 @@ dist+dist-newstyle docs wiki TAGS@@ -11,3 +12,4 @@ *.hi *~ *#+.stack-work/
.travis.yml view
@@ -1,30 +1,90 @@-env:- - GHCVER=7.4.2 CABALVER=1.18- - GHCVER=7.6.3 CABALVER=1.18- - GHCVER=7.8.4 CABALVER=1.18- - GHCVER=7.10.1 CABALVER=1.22- - GHCVER=8.0.1 CABALVER=1.24- - GHCVER=head CABALVER=1.22+# This file has been generated -- see https://github.com/hvr/multi-ghc-travis+language: c+sudo: false +cache:+ directories:+ - $HOME/.cabsnap+ - $HOME/.cabal/packages++before_cache:+ - rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log+ - rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index.tar+ matrix:+ include:+ - env: CABALVER=1.18 GHCVER=7.4.2+ compiler: ": #GHC 7.4.2"+ addons: {apt: {packages: [cabal-install-1.18,ghc-7.4.2], sources: [hvr-ghc]}}+ - env: CABALVER=1.18 GHCVER=7.6.3+ compiler: ": #GHC 7.6.3"+ addons: {apt: {packages: [cabal-install-1.18,ghc-7.6.3], sources: [hvr-ghc]}}+ - env: CABALVER=1.18 GHCVER=7.8.4+ compiler: ": #GHC 7.8.4"+ addons: {apt: {packages: [cabal-install-1.18,ghc-7.8.4], sources: [hvr-ghc]}}+ - env: CABALVER=1.24 GHCVER=7.10.3+ compiler: ": #GHC 7.10.3"+ addons: {apt: {packages: [cabal-install-1.24,ghc-7.10.3], sources: [hvr-ghc]}}+ - env: CABALVER=1.24 GHCVER=8.0.2+ compiler: ": #GHC 8.0.2"+ addons: {apt: {packages: [cabal-install-1.24,ghc-8.0.2], sources: [hvr-ghc]}}+ - env: CABALVER=1.24 GHCVER=8.2.1+ compiler: ": #GHC 8.2.1"+ addons: {apt: {packages: [cabal-install-1.24,ghc-8.2.1], sources: [hvr-ghc]}}+ - env: CABALVER=1.24 GHCVER=head+ compiler: ": #GHC head"+ addons: {apt: {packages: [cabal-install-1.24,ghc-head], sources: [hvr-ghc]}}+ allow_failures:- - env: GHCVER=head CABALVER=1.24+ - env: CABALVER=1.24 GHCVER=head before_install:- - travis_retry sudo add-apt-repository -y ppa:hvr/ghc- - travis_retry sudo apt-get update- - travis_retry sudo apt-get install cabal-install-$CABALVER ghc-$GHCVER+ - unset CC - export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH- - cabal --version install:- - travis_retry cabal update- - cabal install --enable-tests --only-dependencies+ - cabal --version+ - echo "$(ghc --version) [$(ghc --print-project-git-commit-id 2> /dev/null || echo '?')]"+ - if [ -f $HOME/.cabal/packages/hackage.haskell.org/00-index.tar.gz ];+ then+ zcat $HOME/.cabal/packages/hackage.haskell.org/00-index.tar.gz >+ $HOME/.cabal/packages/hackage.haskell.org/00-index.tar;+ fi+ - travis_retry cabal update -v+ - sed -i 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config+ - cabal install --only-dependencies --enable-tests --enable-benchmarks --dry -v > installplan.txt+ - sed -i -e '1,/^Resolving /d' installplan.txt; cat installplan.txt +# check whether current requested install-plan matches cached package-db snapshot+ - if diff -u installplan.txt $HOME/.cabsnap/installplan.txt;+ then+ echo "cabal build-cache HIT";+ rm -rfv .ghc;+ cp -a $HOME/.cabsnap/ghc $HOME/.ghc;+ cp -a $HOME/.cabsnap/lib $HOME/.cabsnap/share $HOME/.cabsnap/bin $HOME/.cabal/;+ else+ echo "cabal build-cache MISS";+ rm -rf $HOME/.cabsnap;+ mkdir -p $HOME/.ghc $HOME/.cabal/lib $HOME/.cabal/share $HOME/.cabal/bin;+ cabal install -j --only-dependencies --enable-tests --enable-benchmarks;+ fi++# snapshot package-db on cache miss+ - if [ ! -d $HOME/.cabsnap ];+ then+ echo "snapshotting package-db to build-cache";+ mkdir $HOME/.cabsnap;+ cp -a $HOME/.ghc $HOME/.cabsnap/ghc;+ cp -a $HOME/.cabal/lib $HOME/.cabal/share $HOME/.cabal/bin installplan.txt $HOME/.cabsnap/;+ fi++# Here starts the actual work to be performed for the package under test;+# any command which exits with a non-zero exit code causes the build to fail. script:- - cabal configure -v2 --enable-tests- - cabal build- - cabal sdist+ - cabal configure -v2 --enable-tests --enable-benchmarks # -v2 provides useful information for debugging+ - cabal build # this builds all libraries and executables (including tests/benchmarks)+ - cabal test+ - cabal sdist # tests that a source-distribution can be generated - export SRC_TGZ=$(cabal info . | awk '{print $2 ".tar.gz";exit}') ; cd dist/; if [ -f "$SRC_TGZ" ]; then@@ -41,3 +101,5 @@ skip_join: true template: - "\x0313linear\x0f/\x0306%{branch}\x0f \x0314%{commit}\x0f %{message} \x0302\x1f%{build_url}\x0f"++# EOF
CHANGELOG.markdown view
@@ -1,3 +1,15 @@+1.20.6+------+* Revamp `Setup.hs` to use `cabal-doctest`. This makes it build+ with `Cabal-2.0`, and makes the `doctest`s work with `cabal new-build` and+ sandboxes.+* Make `(1 / x)` and `recip x` agree in the `Fractional` instance for `Quaternion`+* Use newtype instances for `Point` vectors in `Linear.Affine`+* Enable `PolyKinds` in `Linear.Trace`. Also enable `PolyKinds` when GHC 7.6 or+ later is used (previously, it was GHC 7.8 or later).+* Fix a segfault arising from the `MVector` instance for `V`+* Add `Finite` class for conversion between `V` and fixed-size vector types+ 1.20.5 ------ * GHC 8 compatibility
README.markdown view
@@ -1,6 +1,8 @@ linear ====== +[](https://hackage.haskell.org/package/linear) [](http://travis-ci.org/ekmett/linear)+ Highly polymorphic vector space operations on sparse and free vector spaces. Contact Information
Setup.lhs view
@@ -1,48 +1,182 @@-#!/usr/bin/runhaskell \begin{code}-{-# OPTIONS_GHC -Wall #-}+{-# LANGUAGE CPP #-}+{-# LANGUAGE OverloadedStrings #-} module Main (main) where +#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 )+#else++-- Otherwise we provide a shim++#ifndef MIN_VERSION_Cabal+#define MIN_VERSION_Cabal(x,y,z) 0+#endif+#ifndef MIN_VERSION_directory+#define MIN_VERSION_directory(x,y,z) 0+#endif+#if MIN_VERSION_Cabal(1,24,0)+#define InstalledPackageId UnitId+#endif++import Control.Monad ( when ) import Data.List ( nub )-import Data.Version ( showVersion )-import Distribution.Package ( PackageName(PackageName), PackageId, InstalledPackageId, packageVersion, packageName )-import Distribution.PackageDescription ( PackageDescription(), TestSuite(..) )+import Data.String ( fromString )+import Distribution.Package ( InstalledPackageId )+import Distribution.Package ( PackageId, Package (..), packageVersion )+import Distribution.PackageDescription ( PackageDescription(), TestSuite(..) , Library (..), BuildInfo (..)) 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 Distribution.Simple.Setup ( BuildFlags(buildDistPref, buildVerbosity), fromFlag)+import Distribution.Simple.LocalBuildInfo ( withPackageDB, withLibLBI, withTestLBI, LocalBuildInfo(), ComponentLocalBuildInfo(componentPackageDeps), compiler )+import Distribution.Simple.Compiler ( showCompilerId , PackageDB (..))+import Distribution.Text ( display , simpleParse ) import System.FilePath ( (</>) ) -main :: IO ()-main = defaultMainWithHooks simpleUserHooks- { buildHook = \pkg lbi hooks flags -> do- generateBuildModule (fromFlag (buildVerbosity flags)) pkg lbi- buildHook simpleUserHooks pkg lbi hooks flags- }+#if MIN_VERSION_Cabal(1,25,0)+import Distribution.Simple.BuildPaths ( autogenComponentModulesDir )+#endif -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"+#if MIN_VERSION_directory(1,2,2)+import System.Directory (makeAbsolute)+#else+import System.Directory (getCurrentDirectory)+import System.FilePath (isAbsolute)++makeAbsolute :: FilePath -> IO FilePath+makeAbsolute p | isAbsolute p = return p+ | otherwise = do+ cwd <- getCurrentDirectory+ return $ cwd </> p+#endif++generateBuildModule :: String -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()+generateBuildModule testsuiteName flags pkg lbi = do+ let verbosity = fromFlag (buildVerbosity flags)+ let distPref = fromFlag (buildDistPref flags)++ -- Package DBs+ let dbStack = withPackageDB lbi ++ [ SpecificPackageDB $ distPref </> "package.conf.inplace" ]+ let dbFlags = "-hide-all-packages" : packageDbArgs dbStack++ withLibLBI pkg lbi $ \lib libcfg -> do+ let libBI = libBuildInfo lib++ -- modules+ let modules = exposedModules lib ++ otherModules libBI+ -- it seems that doctest is happy to take in module names, not actual files!+ let module_sources = modules++ -- We need the directory with library's cabal_macros.h!+#if MIN_VERSION_Cabal(1,25,0)+ let libAutogenDir = autogenComponentModulesDir lbi libcfg+#else+ let libAutogenDir = autogenModulesDir lbi+#endif++ -- Lib sources and includes+ iArgs <- mapM (fmap ("-i"++) . makeAbsolute) $ libAutogenDir : hsSourceDirs libBI+ includeArgs <- mapM (fmap ("-I"++) . makeAbsolute) $ includeDirs libBI++ -- CPP includes, i.e. include cabal_macros.h+ let cppFlags = map ("-optP"++) $+ [ "-include", libAutogenDir ++ "/cabal_macros.h" ]+ ++ cppOptions libBI++ withTestLBI pkg lbi $ \suite suitecfg -> when (testName suite == fromString testsuiteName) $ do++ -- get and create autogen dir+#if MIN_VERSION_Cabal(1,25,0)+ let testAutogenDir = autogenComponentModulesDir lbi suitecfg+#else+ let testAutogenDir = autogenModulesDir lbi+#endif+ createDirectoryIfMissingVerbose verbosity True testAutogenDir++ -- write autogen'd file+ rewriteFile (testAutogenDir </> "Build_doctests.hs") $ unlines+ [ "module Build_doctests where" , ""- , "autogen_dir :: String"- , "autogen_dir = " ++ show dir+ -- -package-id etc. flags+ , "pkgs :: [String]"+ , "pkgs = " ++ (show $ formatDeps $ testDeps libcfg suitecfg) , ""- , "deps :: [String]"- , "deps = " ++ (show $ formatdeps (testDeps libcfg suitecfg))+ , "flags :: [String]"+ , "flags = " ++ show (iArgs ++ includeArgs ++ dbFlags ++ cppFlags)+ , ""+ , "module_sources :: [String]"+ , "module_sources = " ++ show (map display module_sources) ] where- formatdeps = map (formatone . snd)- formatone p = case packageName p of- PackageName n -> n ++ "-" ++ showVersion (packageVersion p)+ -- we do this check in Setup, as then doctests don't need to depend on Cabal+ isOldCompiler = maybe False id $ do+ a <- simpleParse $ showCompilerId $ compiler lbi+ b <- simpleParse "7.5"+ return $ packageVersion (a :: PackageId) < b + formatDeps = map formatOne+ formatOne (installedPkgId, pkgId)+ -- The problem is how different cabal executables handle package databases+ -- when doctests depend on the library+ | packageId pkg == pkgId = "-package=" ++ display pkgId+ | otherwise = "-package-id=" ++ display installedPkgId++ -- From Distribution.Simple.Program.GHC+ packageDbArgs :: [PackageDB] -> [String]+ packageDbArgs | isOldCompiler = packageDbArgsConf+ | otherwise = packageDbArgsDb++ -- GHC <7.6 uses '-package-conf' instead of '-package-db'.+ packageDbArgsConf :: [PackageDB] -> [String]+ packageDbArgsConf dbstack = case dbstack of+ (GlobalPackageDB:UserPackageDB:dbs) -> concatMap specific dbs+ (GlobalPackageDB:dbs) -> ("-no-user-package-conf")+ : concatMap specific dbs+ _ -> ierror+ where+ specific (SpecificPackageDB db) = [ "-package-conf=" ++ db ]+ specific _ = ierror+ ierror = error $ "internal error: unexpected package db stack: "+ ++ show dbstack++ -- GHC >= 7.6 uses the '-package-db' flag. See+ -- https://ghc.haskell.org/trac/ghc/ticket/5977.+ packageDbArgsDb :: [PackageDB] -> [String]+ -- special cases to make arguments prettier in common scenarios+ packageDbArgsDb dbstack = case dbstack of+ (GlobalPackageDB:UserPackageDB:dbs)+ | all isSpecific dbs -> concatMap single dbs+ (GlobalPackageDB:dbs)+ | all isSpecific dbs -> "-no-user-package-db"+ : concatMap single dbs+ dbs -> "-clear-package-db"+ : concatMap single dbs+ where+ single (SpecificPackageDB db) = [ "-package-db=" ++ db ]+ single GlobalPackageDB = [ "-global-package-db" ]+ single UserPackageDB = [ "-user-package-db" ]+ isSpecific (SpecificPackageDB _) = True+ isSpecific _ = False+ testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [(InstalledPackageId, PackageId)] testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys++defaultMainWithDoctests :: String -> IO ()+defaultMainWithDoctests testSuiteName = defaultMainWithHooks simpleUserHooks+ { buildHook = \pkg lbi hooks flags -> do+ generateBuildModule testSuiteName flags pkg lbi+ buildHook simpleUserHooks pkg lbi hooks flags+ }++#endif++main :: IO ()+main = defaultMainWithDoctests "doctests" \end{code}
linear.cabal view
@@ -1,6 +1,6 @@ name: linear category: Math, Algebra-version: 1.20.5+version: 1.20.6 license: BSD3 cabal-version: >= 1.8 license-file: LICENSE@@ -13,7 +13,7 @@ synopsis: Linear Algebra description: Types and combinators for linear algebra on free vector spaces build-type: Custom-tested-with: GHC == 7.4.2, GHC == 7.6.1, GHC == 7.8.4, GHC == 7.10.1, GHC==8.0.1+tested-with: GHC == 7.4.2, GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.3, GHC==8.0.2, GHC==8.2.1 extra-source-files: .gitignore .travis.yml@@ -38,8 +38,14 @@ source-repository head type: git- location: git://github.com/ekmett/linear.git+ location: https://github.com/ekmett/linear +custom-setup+ setup-depends:+ base >= 4 && < 5,+ Cabal,+ cabal-doctest >= 1 && < 1.1+ library build-depends: adjunctions >= 4 && < 5,@@ -61,7 +67,7 @@ transformers >= 0.2 && < 0.6, transformers-compat >= 0.4 && < 1, unordered-containers >= 0.2.3 && < 0.3,- vector >= 0.10 && < 0.12,+ vector >= 0.10 && < 0.13, void >= 0.6 && < 1 if flag(template-haskell) && impl(ghc)@@ -111,9 +117,7 @@ hs-source-dirs: tests build-depends: base,- directory >= 1.0 && < 1.3,- doctest >= 0.8 && < 0.12,- filepath >= 1.3 && < 1.5,+ doctest >= 0.11.1 && < 0.12, lens, simple-reflect >= 0.3.1 @@ -121,15 +125,19 @@ type: exitcode-stdio-1.0 main-is: UnitTests.hs other-modules: Plucker, Binary+ if impl(ghc >= 7.7)+ other-modules: V ghc-options: -Wall -threaded hs-source-dirs: tests build-depends: base, binary, bytestring,+ deepseq, test-framework >= 0.8, test-framework-hunit >= 0.3, HUnit >= 1.2.5,- linear-+ linear,+ reflection,+ vector
src/Linear/Affine.hs view
@@ -12,7 +12,7 @@ {-# LANGUAGE DeriveGeneric #-} #endif {-# LANGUAGE DeriveDataTypeable #-}-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ < 708+#if defined(__GLASGOW_HASKELL__) {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE ScopedTypeVariables #-} #endif@@ -33,6 +33,9 @@ import Control.Lens import Data.Binary as Binary import Data.Bytes.Serial+#if __GLASGOW_HASKELL__ >= 708+import Data.Coerce+#endif import Data.Complex (Complex) import Data.Data import Data.Distributive@@ -47,6 +50,9 @@ import Data.Map (Map) import Data.Serialize as Cereal import Data.Vector (Vector)+import qualified Data.Vector.Generic.Mutable as M+import qualified Data.Vector.Generic as G+import qualified Data.Vector.Unboxed.Base as U import Foreign.Storable #if __GLASGOW_HASKELL__ >= 702 import GHC.Generics (Generic)@@ -54,9 +60,6 @@ #if __GLASGOW_HASKELL__ >= 706 import GHC.Generics (Generic1) #endif-import qualified Data.Vector.Generic.Mutable as M-import qualified Data.Vector.Generic as G-import qualified Data.Vector.Unboxed.Base as U import Linear.Epsilon import Linear.Metric import Linear.Plucker@@ -149,6 +152,13 @@ #endif ) +#if __GLASGOW_HASKELL__ >= 707+instance Finite f => Finite (Point f) where+ type Size (Point f) = Size f+ toV (P v) = toV v+ fromV v = P (fromV v)+#endif+ instance NFData (f a) => NFData (Point f a) where rnf (P x) = rnf x @@ -190,17 +200,47 @@ _Wrapped' = _Point {-# INLINE _Wrapped' #-} +#if __GLASGOW_HASKELL__ >= 708+-- These are stolen from Data.Profunctor.Unsafe+(.#) :: Coercible b a => (b -> c) -> (a -> b) -> a -> c+f .# _ = coerce f+{-# INLINE (.#) #-}++(#.) :: Coercible c b => (b -> c) -> (a -> b) -> a -> c+(#.) _ = coerce (\x -> x :: b) :: forall a b. Coercible b a => a -> b+{-# INLINE (#.) #-}+#else+(.#), (#.) :: (b -> c) -> (a -> b) -> a -> c+(.#) = (.)+{-# INLINE (.#) #-}+(#.) = (.)+{-# INLINE (#.) #-}+#endif++unP :: Point f a -> f a+unP (P x) = x+{-# INLINE unP #-}++-- We can't use GND to derive 'Bind' because 'join' causes+-- role troubles. However, GHC 7.8 and above let us use+-- explicit coercions for (>>-). instance Bind f => Bind (Point f) where- join (P m) = P $ join $ fmap (\(P m')->m') m+#if __GLASGOW_HASKELL__ >= 708+ (>>-) = ((P .) . (. (unP .))) #. (>>-) .# unP+#else+ P m >>- f = P $ m >>- unP . f+#endif+ join (P m) = P $ m >>- \(P m') -> m' instance Distributive f => Distributive (Point f) where distribute = P . collect (\(P p) -> p)+ collect = (P .) #. collect .# (unP .) instance Representable f => Representable (Point f) where type Rep (Point f) = Rep f- tabulate f = P (tabulate f)+ tabulate = P #. tabulate {-# INLINE tabulate #-}- index (P xs) = Rep.index xs+ index = Rep.index .# unP {-# INLINE index #-} type instance Index (Point f a) = Index (f a)@@ -238,11 +278,11 @@ instance Additive f => Affine (Point f) where type Diff (Point f) = f- P x .-. P y = x ^-^ y+ (.-.) = (. unP) #. (^-^) .# unP {-# INLINE (.-.) #-}- P x .+^ v = P (x ^+^ v)+ (.+^) = (P .) #. (^+^) .# unP {-# INLINE (.+^) #-}- P x .-^ v = P (x ^-^ v)+ (.-^) = (P .) #. (^-^) .# unP {-# INLINE (.-^) #-} -- | Vector spaces have origins.@@ -255,8 +295,8 @@ relative p0 = iso (.-. p0) (p0 .+^) {-# INLINE relative #-} -data instance U.Vector (Point f a) = V_P !(U.Vector (f a))-data instance U.MVector s (Point f a) = MV_P !(U.MVector s (f a))+newtype instance U.Vector (Point f a) = V_P (U.Vector (f a))+newtype instance U.MVector s (Point f a) = MV_P (U.MVector s (f a)) instance U.Unbox (f a) => U.Unbox (Point f a) instance U.Unbox (f a) => M.MVector U.MVector (Point f a) where
src/Linear/Matrix.hs view
@@ -167,7 +167,7 @@ type M22 a = V2 (V2 a) -- | A 2x3 matrix with row-major representation type M23 a = V2 (V3 a)--- | A 2x3 matrix with row-major representation+-- | A 2x4 matrix with row-major representation type M24 a = V2 (V4 a) -- | A 3x2 matrix with row-major representation type M32 a = V3 (V2 a)
src/Linear/Plucker.hs view
@@ -4,10 +4,13 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE GADTs #-}-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702+#if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Trustworthy #-} {-# LANGUAGE DeriveGeneric #-} #endif+#if __GLASGOW_HASKELL__ >= 707+{-# LANGUAGE DataKinds #-}+#endif #ifndef MIN_VERSION_vector #define MIN_VERSION_vector(x,y,z) 1@@ -70,21 +73,26 @@ import Data.Semigroup import Data.Semigroup.Foldable import Data.Serialize as Cereal+#if __GLASGOW_HASKELL__ >= 707+import qualified Data.Vector as V+#endif+import qualified Data.Vector.Generic.Mutable as M+import qualified Data.Vector.Generic as G+import qualified Data.Vector.Unboxed.Base as U import Foreign.Ptr (castPtr) import Foreign.Storable (Storable(..)) import GHC.Arr (Ix(..))-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702+#if __GLASGOW_HASKELL__ >= 702 import GHC.Generics (Generic) #endif-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 706+#if __GLASGOW_HASKELL__ >= 706 import GHC.Generics (Generic1) #endif-import qualified Data.Vector.Generic.Mutable as M-import qualified Data.Vector.Generic as G-import qualified Data.Vector.Unboxed.Base as U- import Linear.Epsilon import Linear.Metric+#if __GLASGOW_HASKELL__ >= 707+import Linear.V+#endif import Linear.V2 import Linear.V3 import Linear.V4@@ -94,13 +102,20 @@ -- | Plücker coordinates for lines in a 3-dimensional space. data Plucker a = Plucker !a !a !a !a !a !a deriving (Eq,Ord,Show,Read-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702+#if __GLASGOW_HASKELL__ >= 702 ,Generic #endif-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 706+#if __GLASGOW_HASKELL__ >= 706 ,Generic1 #endif )++#if __GLASGOW_HASKELL__ >= 707+instance Finite Plucker where+ type Size Plucker = 6+ toV (Plucker a b c d e f) = V (V.fromListN 6 [a,b,c,d,e,f])+ fromV (V v) = Plucker (v V.! 0) (v V.! 1) (v V.! 2) (v V.! 3) (v V.! 4) (v V.! 5)+#endif instance Functor Plucker where fmap g (Plucker a b c d e f) = Plucker (g a) (g b) (g c) (g d) (g e) (g f)
src/Linear/Quaternion.hs view
@@ -5,10 +5,13 @@ {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE CPP #-} {-# LANGUAGE TypeFamilies #-}-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702+#if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Trustworthy #-} {-# LANGUAGE DeriveGeneric #-} #endif+#if __GLASGOW_HASKELL__ >= 707+{-# LANGUAGE DataKinds #-}+#endif #ifndef MIN_VERSION_vector #define MIN_VERSION_vector(x,y,z) 1@@ -62,20 +65,26 @@ import GHC.Arr (Ix(..)) import qualified Data.Foldable as F import Data.Monoid+#if __GLASGOW_HASKELL__ >= 707+import qualified Data.Vector as V+#endif+import qualified Data.Vector.Generic.Mutable as M+import qualified Data.Vector.Generic as G+import qualified Data.Vector.Unboxed.Base as U import Foreign.Ptr (castPtr, plusPtr) import Foreign.Storable (Storable(..))-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702+#if __GLASGOW_HASKELL__ >= 702 import GHC.Generics (Generic) #endif-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 706+#if __GLASGOW_HASKELL__ >= 706 import GHC.Generics (Generic1) #endif-import qualified Data.Vector.Generic.Mutable as M-import qualified Data.Vector.Generic as G-import qualified Data.Vector.Unboxed.Base as U import Linear.Epsilon import Linear.Conjugate import Linear.Metric+#if __GLASGOW_HASKELL__ >= 707+import Linear.V+#endif import Linear.V3 import Linear.Vector import Prelude hiding (any)@@ -93,6 +102,13 @@ #endif ) +#if __GLASGOW_HASKELL__ >= 707+instance Finite Quaternion where+ type Size Quaternion = 4+ toV (Quaternion a (V3 b c d)) = V (V.fromListN 4 [a, b, c, d])+ fromV (V v) = Quaternion (v V.! 0) (V3 (v V.! 1) (v V.! 2) (v V.! 3))+#endif+ instance Functor Quaternion where fmap f (Quaternion e v) = Quaternion (f e) (fmap f v) {-# INLINE fmap #-}@@ -261,7 +277,7 @@ (r0*q3-r1*q2+r2*q1-r3*q0)) ^/ (r0*r0 + r1*r1 + r2*r2 + r3*r3) {-# INLINE (/) #-}- recip q = q ^/ quadrance q+ recip q@(Quaternion e v) = Quaternion e (negate v) ^/ quadrance q {-# INLINE recip #-} fromRational x = Quaternion (fromRational x) 0 {-# INLINE fromRational #-}
src/Linear/Trace.hs view
@@ -1,6 +1,9 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE DefaultSignatures #-}+#if __GLASGOW_HASKELL__ >= 706+{-# LANGUAGE PolyKinds #-}+#endif #if __GLASGOW_HASKELL__ >= 702 && __GLASGOW_HASKELL__ < 710 {-# LANGUAGE Trustworthy #-} #endif
src/Linear/V.hs view
@@ -2,6 +2,7 @@ {-# LANGUAGE KindSignatures #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE DefaultSignatures #-} {-# LANGUAGE Rank2Types #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE EmptyDataDecls #-}@@ -10,6 +11,8 @@ #if __GLASGOW_HASKELL__ >= 707 {-# LANGUAGE DataKinds #-} {-# LANGUAGE PolyKinds #-}+#endif+#if __GLASGOW_HASKELL__ >= 707 {-# LANGUAGE RoleAnnotations #-} #define USE_TYPE_LITS 1 #endif@@ -50,6 +53,10 @@ , reifyVectorNat #endif , fromVector+#if __GLASGOW_HASKELL__ >= 707+ , Finite(..)+ , _V, _V'+#endif ) where #if __GLASGOW_HASKELL__ < 710@@ -62,6 +69,9 @@ import Control.Lens as Lens import Data.Binary as Binary import Data.Bytes.Serial+#if __GLASGOW_HASKELL__ >= 707+import Data.Complex+#endif import Data.Data import Data.Distributive import Data.Foldable as Foldable@@ -114,9 +124,31 @@ #if __GLASGOW_HASKELL__ >= 707 type role V nominal representational-#endif +class Finite v where+ type Size (v :: * -> *) :: Nat -- this should allow kind k, for Reifies k Int+ toV :: v a -> V (Size v) a+ default toV :: Foldable v => v a -> V (Size v) a+ toV = V . V.fromList . Foldable.toList+ fromV :: V (Size v) a -> v a +instance Finite Complex where+ type Size Complex = 2+ toV (a :+ b) = V (V.fromListN 2 [a, b])+ fromV (V v) = (v V.! 0) :+ (v V.! 1)++_V :: (Finite u, Finite v) => Iso (V (Size u) a) (V (Size v) b) (u a) (v b)+_V = iso fromV toV++_V' :: Finite v => Iso (V (Size v) a) (V (Size v) b) (v a) (v b)+_V' = iso fromV toV++instance Finite (V (n :: Nat)) where+ type Size (V n) = n+ toV = id+ fromV = id+#endif+ newtype V n a = V { toVector :: V.Vector a } deriving (Eq,Ord,Show,Read,Typeable,NFData , Generic -- GHC bug: https://ghc.haskell.org/trac/ghc/ticket/8468@@ -124,6 +156,7 @@ ,Generic1 #endif )+ dim :: forall n a. Dim n => V n a -> Int dim _ = reflectDim (Proxy :: Proxy n) {-# INLINE dim #-}@@ -158,7 +191,7 @@ reifyDim :: Int -> (forall (n :: *). Dim n => Proxy n -> r) -> r reifyDim i f = R.reify i (go f) where- go :: Reifies n Int => (Proxy (ReifiedDim n) -> a) -> proxy n -> a+ go :: (Proxy (ReifiedDim n) -> a) -> proxy n -> a go g _ = g Proxy {-# INLINE reifyDim #-} @@ -217,7 +250,6 @@ {-# INLINE product #-} #endif - instance FoldableWithIndex Int (V n) where ifoldMap f (V as) = ifoldMap f as {-# INLINE ifoldMap #-}@@ -524,14 +556,14 @@ basicUnsafeRead (MV_VN _ v) i = liftM V $ V.generateM d (\j -> M.basicUnsafeRead v (d*i+j)) where d = reflectDim (Proxy :: Proxy n)- basicUnsafeWrite (MV_VN _ v0) i0 (V vn0) = let d0 = V.length vn0 in go v0 vn0 d0 (d0*i0) i0+ basicUnsafeWrite (MV_VN _ v0) i (V vn0) = let d0 = V.length vn0 in go v0 vn0 d0 (d0*i) 0 where- go v vn d o i- | i >= d = return ()+ go v vn d o j+ | j >= d = return () | otherwise = do- a <- G.basicUnsafeIndexM vn i+ a <- G.basicUnsafeIndexM vn j M.basicUnsafeWrite v o a- go v vn d (o+1) (i-1)+ go v vn d (o+1) (j+1) #if MIN_VERSION_vector(0,11,0) basicInitialize (MV_VN _ v) = M.basicInitialize v {-# INLINE basicInitialize #-}
src/Linear/V0.hs view
@@ -4,11 +4,16 @@ {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-}-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702++#if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE Trustworthy #-} #endif +#if __GLASGOW_HASKELL__ >= 707+{-# LANGUAGE DataKinds #-}+#endif+ #ifndef MIN_VERSION_hashable #define MIN_VERSION_hashable(x,y,z) 1 #endif@@ -54,11 +59,14 @@ import Data.Ix import Data.Semigroup import Data.Serialize -- cereal+#if __GLASGOW_HASKELL__ >= 707+import qualified Data.Vector as V+#endif import Foreign.Storable (Storable(..)) #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702 import GHC.Generics (Generic) #endif-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 706+#if __GLASGOW_HASKELL__ >= 706 import GHC.Generics (Generic1) #endif import qualified Data.Vector.Generic.Mutable as M@@ -67,6 +75,9 @@ import Linear.Metric import Linear.Epsilon import Linear.Vector+#if __GLASGOW_HASKELL__ >= 707+import Linear.V+#endif import Prelude hiding (sum) -- $setup@@ -88,6 +99,13 @@ ,Generic1 #endif )++#if __GLASGOW_HASKELL__ >= 707+instance Finite V0 where+ type Size V0 = 0+ toV _ = V V.empty+ fromV _ = V0+#endif instance Serial1 V0 where serializeWith _ = serialize
src/Linear/V1.hs view
@@ -8,11 +8,13 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE ScopedTypeVariables #-}--- {-# OPTIONS_GHC -fno-warn-name-shadowing #-}-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702+#if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Trustworthy #-} {-# LANGUAGE DeriveGeneric #-} #endif+#if __GLASGOW_HASKELL__ >= 707+{-# LANGUAGE DataKinds #-}+#endif #ifndef MIN_VERSION_hashable #define MIN_VERSION_hashable(x,y,z) 1@@ -60,12 +62,16 @@ import Data.Functor.Rep import Data.Hashable import Data.Semigroup.Foldable+#if __GLASGOW_HASKELL__ >= 707+import qualified Data.Vector as V+import Linear.V+#endif import Foreign.Storable (Storable) import GHC.Arr (Ix(..))-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702+#if __GLASGOW_HASKELL__ >= 702 import GHC.Generics (Generic) #endif-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 706+#if __GLASGOW_HASKELL__ >= 706 import GHC.Generics (Generic1) #endif import Linear.Metric@@ -111,6 +117,13 @@ ,Generic1 #endif )++#if __GLASGOW_HASKELL__ >= 707+instance Finite V1 where+ type Size V1 = 1+ toV (V1 a) = V (V.singleton a)+ fromV (V v) = V1 (v V.! 0)+#endif instance Foldable1 V1 where foldMap1 f (V1 a) = f a
src/Linear/V2.hs view
@@ -4,12 +4,14 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE MultiParamTypeClasses #-}--- {-# OPTIONS_GHC -fno-warn-name-shadowing #-} {-# LANGUAGE CPP #-}-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702+#if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Trustworthy #-} {-# LANGUAGE DeriveGeneric #-} #endif+#if __GLASGOW_HASKELL__ >= 707+{-# LANGUAGE DataKinds #-}+#endif #ifndef MIN_VERSION_vector #define MIN_VERSION_vector(x,y,z) 1@@ -60,13 +62,16 @@ import Data.Semigroup import Data.Semigroup.Foldable import Data.Serialize as Cereal+#if __GLASGOW_HASKELL__ >= 707+import qualified Data.Vector as V+#endif import Foreign.Ptr (castPtr) import Foreign.Storable (Storable(..)) import GHC.Arr (Ix(..))-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702+#if __GLASGOW_HASKELL__ >= 702 import GHC.Generics (Generic) #endif-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 706+#if __GLASGOW_HASKELL__ >= 706 import GHC.Generics (Generic1) #endif import qualified Data.Vector.Generic.Mutable as M@@ -74,6 +79,9 @@ import qualified Data.Vector.Unboxed.Base as U import Linear.Metric import Linear.Epsilon+#if __GLASGOW_HASKELL__ >= 707+import Linear.V+#endif import Linear.Vector import Linear.V1 (R1(..),ex) import Prelude hiding (sum)@@ -104,6 +112,13 @@ ,Generic1 #endif )++#if __GLASGOW_HASKELL__ >= 707+instance Finite V2 where+ type Size V2 = 2+ toV (V2 a b) = V (V.fromListN 2 [a,b])+ fromV (V v) = V2 (v V.! 0) (v V.! 1)+#endif instance Functor V2 where fmap f (V2 a b) = V2 (f a) (f b)
src/Linear/V3.hs view
@@ -5,10 +5,13 @@ {-# LANGUAGE RankNTypes #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE CPP #-}-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702+#if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Trustworthy #-} {-# LANGUAGE DeriveGeneric #-} #endif+#if __GLASGOW_HASKELL__ >= 707+{-# LANGUAGE DataKinds #-}+#endif #ifndef MIN_VERSION_vector #define MIN_VERSION_vector(x,y,z) 1@@ -59,20 +62,26 @@ import Data.Semigroup import Data.Semigroup.Foldable import Data.Serialize as Cereal -- cereal+#if __GLASGOW_HASKELL__ >= 707+import qualified Data.Vector as V+#endif+import qualified Data.Vector.Generic.Mutable as M+import qualified Data.Vector.Generic as G+import qualified Data.Vector.Unboxed.Base as U import Foreign.Ptr (castPtr) import Foreign.Storable (Storable(..)) import GHC.Arr (Ix(..))-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702+#if __GLASGOW_HASKELL__ >= 702 import GHC.Generics (Generic) #endif-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 706+#if __GLASGOW_HASKELL__ >= 706 import GHC.Generics (Generic1) #endif-import qualified Data.Vector.Generic.Mutable as M-import qualified Data.Vector.Generic as G-import qualified Data.Vector.Unboxed.Base as U import Linear.Epsilon import Linear.Metric+#if __GLASGOW_HASKELL__ >= 707+import Linear.V+#endif import Linear.V2 import Linear.Vector @@ -80,14 +89,20 @@ -- | A 3-dimensional vector data V3 a = V3 !a !a !a deriving (Eq,Ord,Show,Read,Data,Typeable-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702+#if __GLASGOW_HASKELL__ >= 702 ,Generic #endif-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 706+#if __GLASGOW_HASKELL__ >= 706 ,Generic1 #endif ) +#if __GLASGOW_HASKELL__ >= 707+instance Finite V3 where+ type Size V3 = 3 + toV (V3 a b c) = V (V.fromListN 3 [a,b,c])+ fromV (V v) = V3 (v V.! 0) (v V.! 1) (v V.! 2)+#endif instance Functor V3 where fmap f (V3 a b c) = V3 (f a) (f b) (f c)
src/Linear/V4.hs view
@@ -5,10 +5,13 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE CPP #-}-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702+#if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Trustworthy #-} {-# LANGUAGE DeriveGeneric #-} #endif+#if __GLASGOW_HASKELL__ >= 707+{-# LANGUAGE DataKinds #-}+#endif #ifndef MIN_VERSION_vector #define MIN_VERSION_vector(x,y,z) 1@@ -65,20 +68,26 @@ import Data.Semigroup import Data.Semigroup.Foldable import Data.Serialize as Cereal+#if __GLASGOW_HASKELL__ >= 707+import qualified Data.Vector as V+#endif+import qualified Data.Vector.Generic.Mutable as M+import qualified Data.Vector.Generic as G+import qualified Data.Vector.Unboxed.Base as U import Foreign.Ptr (castPtr) import Foreign.Storable (Storable(..)) import GHC.Arr (Ix(..))-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702+#if __GLASGOW_HASKELL__ >= 702 import GHC.Generics (Generic) #endif-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 706+#if __GLASGOW_HASKELL__ >= 706 import GHC.Generics (Generic1) #endif-import qualified Data.Vector.Generic.Mutable as M-import qualified Data.Vector.Generic as G-import qualified Data.Vector.Unboxed.Base as U import Linear.Epsilon import Linear.Metric+#if __GLASGOW_HASKELL__ >= 707+import Linear.V+#endif import Linear.V2 import Linear.V3 import Linear.Vector@@ -87,13 +96,20 @@ -- | A 4-dimensional vector. data V4 a = V4 !a !a !a !a deriving (Eq,Ord,Show,Read,Data,Typeable-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702+#if __GLASGOW_HASKELL__ >= 702 ,Generic #endif-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 706+#if __GLASGOW_HASKELL__ >= 706 ,Generic1 #endif )++#if __GLASGOW_HASKELL__ >= 707+instance Finite V4 where+ type Size V4 = 4+ toV (V4 a b c d) = V (V.fromListN 4 [a,b,c,d])+ fromV (V v) = V4 (v V.! 0) (v V.! 1) (v V.! 2) (v V.! 3)+#endif instance Functor V4 where fmap f (V4 a b c d) = V4 (f a) (f b) (f c) (f d)
src/Linear/Vector.hs view
@@ -129,26 +129,15 @@ -- >>> V2 1 2 ^+^ V2 3 4 -- V2 4 6 (^+^) :: Num a => f a -> f a -> f a-#ifdef USE_GHC_GENERICS-#ifndef HLINT- default (^+^) :: Num a => f a -> f a -> f a (^+^) = liftU2 (+) {-# INLINE (^+^) #-}-#endif-#endif -- | Compute the difference between two vectors -- -- >>> V2 4 5 ^-^ V2 3 1 -- V2 1 4 (^-^) :: Num a => f a -> f a -> f a-#ifdef USE_GHC_GENERICS-#ifndef HLINT- default (^-^) :: Num a => f a -> f a -> f a x ^-^ y = x ^+^ negated y- {-# INLINE (^-^) #-}-#endif-#endif -- | Linearly interpolate between two vectors. lerp :: Num a => a -> f a -> f a -> f a@@ -190,12 +179,6 @@ {-# INLINE liftU2 #-} liftI2 = liftA2 {-# INLINE liftI2 #-}-#ifndef USE_GHC_GENERICS- (^+^) = liftU2 (+)- {-# INLINE (^+^) #-}- x ^-^ y = x ^+^ negated y- {-# INLINE (^-^) #-}-#endif instance Additive Vector where zero = mempty@@ -212,12 +195,6 @@ {-# INLINE liftU2 #-} liftI2 = Vector.zipWith {-# INLINE liftI2 #-}-#ifndef USE_GHC_GENERICS- (^+^) = liftU2 (+)- {-# INLINE (^+^) #-}- x ^-^ y = x ^+^ negated y- {-# INLINE (^-^) #-}-#endif instance Additive Maybe where zero = Nothing@@ -228,12 +205,6 @@ {-# INLINE liftU2 #-} liftI2 = liftA2 {-# INLINE liftI2 #-}-#ifndef USE_GHC_GENERICS- (^+^) = liftU2 (+)- {-# INLINE (^+^) #-}- x ^-^ y = x ^+^ negated y- {-# INLINE (^-^) #-}-#endif instance Additive [] where zero = []@@ -245,12 +216,6 @@ {-# INLINE liftU2 #-} liftI2 = Prelude.zipWith {-# INLINE liftI2 #-}-#ifndef USE_GHC_GENERICS- (^+^) = liftU2 (+)- {-# INLINE (^+^) #-}- x ^-^ y = x ^+^ negated y- {-# INLINE (^-^) #-}-#endif instance Additive IntMap where zero = IntMap.empty@@ -259,12 +224,6 @@ {-# INLINE liftU2 #-} liftI2 = IntMap.intersectionWith {-# INLINE liftI2 #-}-#ifndef USE_GHC_GENERICS- (^+^) = liftU2 (+)- {-# INLINE (^+^) #-}- x ^-^ y = x ^+^ negated y- {-# INLINE (^-^) #-}-#endif instance Ord k => Additive (Map k) where zero = Map.empty@@ -273,12 +232,6 @@ {-# INLINE liftU2 #-} liftI2 = Map.intersectionWith {-# INLINE liftI2 #-}-#ifndef USE_GHC_GENERICS- (^+^) = liftU2 (+)- {-# INLINE (^+^) #-}- x ^-^ y = x ^+^ negated y- {-# INLINE (^-^) #-}-#endif instance (Eq k, Hashable k) => Additive (HashMap k) where zero = HashMap.empty@@ -287,12 +240,6 @@ {-# INLINE liftU2 #-} liftI2 = HashMap.intersectionWith {-# INLINE liftI2 #-}-#ifndef USE_GHC_GENERICS- (^+^) = liftU2 (+)- {-# INLINE (^+^) #-}- x ^-^ y = x ^+^ negated y- {-# INLINE (^-^) #-}-#endif instance Additive ((->) b) where zero = const 0@@ -301,12 +248,6 @@ {-# INLINE liftU2 #-} liftI2 = liftA2 {-# INLINE liftI2 #-}-#ifndef USE_GHC_GENERICS- (^+^) = liftU2 (+)- {-# INLINE (^+^) #-}- x ^-^ y = x ^+^ negated y- {-# INLINE (^-^) #-}-#endif instance Additive Complex where zero = 0 :+ 0@@ -315,12 +256,6 @@ {-# INLINE liftU2 #-} liftI2 f (a :+ b) (c :+ d) = f a c :+ f b d {-# INLINE liftI2 #-}-#ifndef USE_GHC_GENERICS- (^+^) = liftU2 (+)- {-# INLINE (^+^) #-}- x ^-^ y = x ^+^ negated y- {-# INLINE (^-^) #-}-#endif instance Additive Identity where zero = Identity 0@@ -329,12 +264,6 @@ {-# INLINE liftU2 #-} liftI2 = liftA2 {-# INLINE liftI2 #-}-#ifndef USE_GHC_GENERICS- (^+^) = liftU2 (+)- {-# INLINE (^+^) #-}- x ^-^ y = x ^+^ negated y- {-# INLINE (^-^) #-}-#endif -- | Compute the negation of a vector --
tests/UnitTests.hs view
@@ -1,12 +1,20 @@+{-# LANGUAGE CPP #-} module Main (main) where import Test.Framework (defaultMain, testGroup, Test) import Test.Framework.Providers.HUnit import qualified Plucker import qualified Binary+#if __GLASGOW_HASKELL__ >= 707+import qualified V+#endif tests :: [Test]-tests = [ testGroup "Plucker" $ hUnitTestToTests Plucker.tests - , testGroup "Binary" $ hUnitTestToTests Binary.tests ]+tests = [ testGroup "Plucker" $ hUnitTestToTests Plucker.tests+ , testGroup "Binary" $ hUnitTestToTests Binary.tests+#if __GLASGOW_HASKELL__ >= 707+ , testGroup "V" $ hUnitTestToTests V.tests+#endif+ ] main :: IO () main = defaultMain tests
+ tests/V.hs view
@@ -0,0 +1,13 @@+{-# LANGUAGE DataKinds #-}+module V (tests) where++import Control.DeepSeq (rnf)+import qualified Data.Vector.Unboxed as U (fromList)+import Linear.V (V)+import Test.HUnit++v10 :: V 10 Int+v10 = return 5++tests :: Test+tests = test [ "GH124" ~: rnf (U.fromList [v10]) ~?= () ]
tests/doctests.hs view
@@ -1,30 +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 (autogen_dir, deps)-import Control.Applicative-import Control.Monad-import Data.List-import System.Directory-import System.FilePath+import Build_doctests (flags, pkgs, module_sources)+import Data.Foldable (traverse_) import Test.DocTest main :: IO ()-main = getSources >>= \sources -> doctest $- "-isrc"- : ("-i" ++ autogen_dir)- : "-optP-include"- : ("-optP" ++ autogen_dir ++ "/cabal_macros.h")- : "-hide-all-packages"- : map ("-package="++) deps ++ sources--getSources :: IO [FilePath]-getSources = filter (isSuffixOf ".hs") <$> go "src"+main = do+ traverse_ putStrLn args+ doctest args where- go dir = do- (dirs, files) <- getFilesAndDirectories dir- (files ++) . concat <$> mapM go dirs--getFilesAndDirectories :: FilePath -> IO ([FilePath], [FilePath])-getFilesAndDirectories dir = do- c <- map (dir </>) . filter (`notElem` ["..", "."]) <$> getDirectoryContents dir- (,) <$> filterM doesDirectoryExist c <*> filterM doesFileExist c+ args = flags ++ pkgs ++ module_sources