linear 0.9.2 → 1.0.1
raw patch · 12 files changed
+116/−51 lines, 12 filesdep −base-orphansdep ~distributivedep ~lensdep ~semigroupoids
Dependencies removed: base-orphans
Dependency ranges changed: distributive, lens, semigroupoids, semigroups, unordered-containers
Files
- .travis.yml +1/−3
- CHANGELOG.markdown +28/−0
- linear.cabal +14/−16
- src/Linear/Matrix.hs +23/−5
- src/Linear/Metric.hs +3/−0
- src/Linear/Plucker.hs +1/−1
- src/Linear/Quaternion.hs +1/−1
- src/Linear/V2.hs +1/−1
- src/Linear/V3.hs +1/−1
- src/Linear/V4.hs +1/−1
- src/Linear/Vector.hs +19/−10
- travis/cabal-apt-install +23/−12
.travis.yml view
@@ -4,9 +4,7 @@ # - mkdir -p ~/.cabal && cp travis/config ~/.cabal/config && cabal update # Try installing some of the build-deps with apt-get for speed.- - travis/cabal-apt-install --only-dependencies --force-reinstall $mode-- - sudo apt-get -q -y install hlint || cabal install hlint+ - travis/cabal-apt-install $mode install: - cabal configure $mode
CHANGELOG.markdown view
@@ -1,3 +1,31 @@+1.0+---+* Strict vectors+* Exported `mkTransformationMat`+* Bumped dependency bounds.++0.9.1 [bug fix]+-----+* Exported `Linear.V0`!++0.9+---+* Added sparse vector support.++0.8+---+* Added `Linear.V0`++0.7+---+* Added `Linear.Instances`+* More documentation++0.6+---+* Removed the direct dependency on `lens`.+* Added `Linear.Core` to cover vector spaces as corepresentable functors.+ 0.5 ------- * Added `Ix` instances for `V2`, `V3`, and `V4`
linear.cabal view
@@ -1,6 +1,6 @@ name: linear category: Math, Algebra-version: 0.9.2+version: 1.0.1 license: BSD3 cabal-version: >= 1.8 license-file: LICENSE@@ -30,14 +30,14 @@ library build-depends:- base >= 4.5 && < 5,- containers >= 0.4 && < 0.6,- distributive >= 0.2.2,- hashable >= 1.1 && < 1.3,- semigroups >= 0.9,- semigroupoids >= 3,- transformers >= 0.2 && < 0.4,- unordered-containers >= 0.2.3+ base >= 4.5 && < 5,+ containers >= 0.4 && < 0.6,+ distributive >= 0.2.2 && < 1,+ hashable >= 1.1 && < 1.3,+ semigroups >= 0.9 && < 1,+ semigroupoids >= 3 && < 4,+ transformers >= 0.2 && < 0.4,+ unordered-containers >= 0.2.3 && < 0.3 exposed-modules: Linear@@ -60,16 +60,14 @@ -- Verify the results of the examples test-suite doctests- type: exitcode-stdio-1.0- main-is: doctests.hs+ type: exitcode-stdio-1.0+ main-is: doctests.hs+ ghc-options: -Wall -Werror -threaded+ hs-source-dirs: tests build-depends: base, directory >= 1.0 && < 1.3, doctest >= 0.8 && < 0.10, filepath >= 1.3 && < 1.4,- lens >= 3.7,+ lens >= 3.8.4, simple-reflect >= 0.3.1-- ghc-options: -Wall -Werror -threaded- hs-source-dirs: tests-
src/Linear/Matrix.hs view
@@ -11,7 +11,7 @@ -- Simple matrix operation for low-dimensional primitives. ---------------------------------------------------------------------------- module Linear.Matrix- ( (!*!), (!*) , (*!), (!!*), (*!!)+ ( (!*!), (!+!), (!-!), (!*) , (*!), (!!*), (*!!) , adjoint , M22, M33, M44, M43, m33_to_m44, m43_to_m44 , det22, det33, inv22, inv33@@ -20,6 +20,7 @@ , translation , fromQuaternion , mkTransformation+ , mkTransformationMat ) where import Control.Applicative@@ -33,7 +34,7 @@ import Linear.V2 import Linear.V3 import Linear.V4-import Linear.Vector ((*^))+import Linear.Vector ((*^), Additive, liftU2, (^+^), (^-^)) import Linear.Conjugate -- $setup@@ -53,16 +54,31 @@ f !*! g = fmap (\r -> Foldable.sum . liftF2 (*) r <$> g') f where g' = distribute g +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)+(!+!) :: (Additive m, Additive n, Num a) => m (n a) -> m (n a) -> m (n a)+as !+! bs = liftU2 (^+^) as bs++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)+(!-!) :: (Additive m, Additive n, Num a) => m (n a) -> m (n a) -> m (n a)+as !-! bs = liftU2 (^-^) as bs++infixl 7 !* -- | Matrix * column vector -- -- >>> V2 (V3 1 2 3) (V3 4 5 6) !* V3 7 8 9 -- V2 50 122-infixl 7 *! (!*) :: (Functor m, Metric r, Num a) => m (r a) -> r a -> m a m !* v = dot v <$> m -infixl 7 !*-+infixl 7 *! -- | Row vector * matrix -- -- >>> V2 1 2 *! V2 (V3 3 4 5) (V3 6 7 8)@@ -127,6 +143,8 @@ y2 = y * y z2 = z * z +-- | Build a transformation matrix from a rotation matrix and a+-- translation vector. mkTransformationMat :: Num a => M33 a -> V3 a -> M44 a mkTransformationMat (V3 r1 r2 r3) (V3 tx ty tz) = V4 (snoc3 r1 tx) (snoc3 r2 ty) (snoc3 r3 tz) (V4 0 0 0 1)
src/Linear/Metric.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE DefaultSignatures #-} ----------------------------------------------------------------------------- -- |@@ -31,8 +32,10 @@ -- >>> V2 1 2 `dot` V2 3 4 -- 11 dot :: Num a => f a -> f a -> a+#ifndef HLINT default dot :: (Foldable f, Num a) => f a -> f a -> a dot x y = Foldable.sum $ liftF2 (*) x y+#endif -- | Compute the squared norm. The name quadrance arises from -- Norman J. Wildberger's rational trigonometry.
src/Linear/Plucker.hs view
@@ -45,7 +45,7 @@ {-# ANN module "HLint: ignore Reduce duplication" #-} -- | 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)+data Plucker a = Plucker !a !a !a !a !a !a deriving (Eq,Ord,Show,Read) 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
@@ -51,7 +51,7 @@ {-# ANN module "HLint: ignore Reduce duplication" #-} -- | Quaternions-data Quaternion a = Quaternion a {-# UNPACK #-}!(V3 a)+data Quaternion a = Quaternion !a {-# UNPACK #-}!(V3 a) deriving (Eq,Ord,Read,Show,Data,Typeable) instance Functor Quaternion where
src/Linear/V2.hs view
@@ -55,7 +55,7 @@ -- >>> sum (V2 1 2) -- 3 -data V2 a = V2 a a deriving (Eq,Ord,Show,Read,Data,Typeable)+data V2 a = V2 !a !a deriving (Eq,Ord,Show,Read,Data,Typeable) instance Functor V2 where fmap f (V2 a b) = V2 (f a) (f b)
src/Linear/V3.hs view
@@ -39,7 +39,7 @@ {-# ANN module "HLint: ignore Reduce duplication" #-} -- | A 3-dimensional vector-data V3 a = V3 a a a deriving (Eq,Ord,Show,Read,Data,Typeable)+data V3 a = V3 !a !a !a deriving (Eq,Ord,Show,Read,Data,Typeable) instance Functor V3 where fmap f (V3 a b c) = V3 (f a) (f b) (f c)
src/Linear/V4.hs view
@@ -41,7 +41,7 @@ {-# ANN module "HLint: ignore Reduce duplication" #-} -- | A 4-dimensional vector.-data V4 a = V4 a a a a deriving (Eq,Ord,Show,Read,Data,Typeable)+data V4 a = V4 !a !a !a !a deriving (Eq,Ord,Show,Read,Data,Typeable) 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
@@ -56,8 +56,8 @@ -- V2 4 6 (^+^) :: Num a => f a -> f a -> f a #ifndef HLINT- default (^+^) :: (Applicative f, Num a) => f a -> f a -> f a- (^+^) = liftA2 (+)+ default (^+^) :: (Num a) => f a -> f a -> f a+ (^+^) = liftU2 (+) {-# INLINE (^+^) #-} #endif @@ -67,8 +67,8 @@ -- V2 1 4 (^-^) :: Num a => f a -> f a -> f a #ifndef HLINT- default (^-^) :: (Applicative f, Num a) => f a -> f a -> f a- (^-^) = liftA2 (-)+ default (^-^) :: (Num a) => f a -> f a -> f a+ x ^-^ y = x ^+^ negated y {-# INLINE (^-^) #-} #endif @@ -77,20 +77,29 @@ lerp alpha u v = alpha *^ u ^+^ (1 - alpha) *^ v {-# INLINE lerp #-} + -- | Apply a function to merge the 'non-zero' components of two vectors.+ --+ -- * For a dense vector this is equivalent to 'liftA2'.+ --+ -- * For a sparse vector this is equivalent to 'unionWith'.+ liftU2 :: (a -> a -> a) -> f a -> f a -> f a+#ifndef HLINT+ default liftU2 :: (Applicative f) => (a -> a -> a) -> f a -> f a -> f a+ liftU2 = liftA2+ {-# INLINE liftU2 #-}+#endif+ instance Additive IntMap where zero = IntMap.empty- (^+^) = IntMap.unionWith (+)- xs ^-^ ys = IntMap.unionWith (+) xs (negated ys)+ liftU2 = IntMap.unionWith instance Ord k => Additive (Map k) where zero = Map.empty- (^+^) = Map.unionWith (+)- xs ^-^ ys = Map.unionWith (+) xs (negated ys)+ liftU2 = Map.unionWith instance (Eq k, Hashable k) => Additive (HashMap k) where zero = HashMap.empty- (^+^) = HashMap.unionWith (+)- xs ^-^ ys = HashMap.unionWith (+) xs (negated ys)+ liftU2 = HashMap.unionWith instance Additive ((->) b)
travis/cabal-apt-install view
@@ -1,16 +1,27 @@-#!/bin/sh+#! /bin/bash set -eu -sudo apt-get -q update-sudo apt-get -q -y install dctrl-tools+APT="sudo apt-get -q -y"+CABAL_INSTALL_DEPS="cabal install --only-dependencies --force-reinstall" -# Try installing some of the build-deps with apt-get for speed.-eval "$(- printf '%s' "grep-aptavail -n -sPackage '(' -FFALSE -X FALSE ')'"- 2>/dev/null cabal install "$@" --dry-run -v | \- sed -nre "s/^([^ ]+)-[0-9.]+ \(.*$/ -o '(' -FPackage -X libghc-\1-dev ')'/p" | \- xargs -d'\n'-)" | sort -u | xargs -d'\n' sudo apt-get -q -y install -- libghc-quickcheck2-dev+$APT update+$APT install dctrl-tools -# Install whatever is still needed with cabal.-cabal install "$@"+# Find potential system packages to satisfy cabal dependencies+deps()+{+ local M='^\([^ ]\+\)-[0-9.]\+ (.*$'+ local G=' -o ( -FPackage -X libghc-\L\1\E-dev )'+ local E="$($CABAL_INSTALL_DEPS "$@" --dry-run -v 2> /dev/null \+ | sed -ne "s/$M/$G/p" | sort -u)"+ grep-aptavail -n -sPackage \( -FNone -X None \) $E | sort -u+}++$APT install $(deps "$@") libghc-quickcheck2-dev # QuickCheck is special+$CABAL_INSTALL_DEPS "$@" # Install the rest via Hackage++if ! $APT install hlint ; then+ $APT install $(deps hlint)+ cabal install hlint+fi+