packages feed

vector-space 0.7.3 → 0.7.6

raw patch · 4 files changed

+62/−4 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.LinearMap: firstL :: (HasBasis u, HasBasis u', HasBasis v, HasTrie (Basis u), HasTrie (Basis v), (Scalar u) ~ (Scalar v), (Scalar u) ~ (Scalar u')) => (u :-* u') -> ((u, v) :-* (u', v))
+ Data.LinearMap: instance (HasTrie (Basis u), VectorSpace v) => VectorSpace (u :-* v)
+ Data.VectorSpace: project :: (InnerSpace v, s ~ (Scalar v), Floating s) => v -> v -> v

Files

src/Data/AdditiveGroup.hs view
@@ -102,6 +102,36 @@   Just a' ^+^ Just b' = Just (a' ^+^ b')   negateV = fmap negateV +{-++Alexey Khudyakov wrote:++  I looked through vector-space package and found lawless instance. Namely Maybe's AdditiveGroup instance++  It's group so following relation is expected to hold. Otherwise it's not a group.+  > x ^+^ negateV x == zeroV++  Here is counterexample:++  > let x = Just 2 in x ^+^ negateV x == zeroV+  False++  I think it's not possible to sensibly define group instance for+  Maybe a at all.+++I see that the problem here is in distinguishing 'Just zeroV' from+Nothing. I could fix the Just + Just line to use Nothing instead of Just+zeroV when a' ^+^ b' == zeroV, although doing so would require Eq a and+hence lose some generality. Even so, the abstraction leak would probably+show up elsewhere.++Hm.++-}+++  -- Memo tries instance (HasTrie u, AdditiveGroup v) => AdditiveGroup (u :->: v) where
src/Data/LinearMap.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE TypeOperators, FlexibleContexts, TypeFamilies, GeneralizedNewtypeDeriving, StandaloneDeriving #-}--- {-# OPTIONS_GHC -Wall -fno-warn-orphans #-}+{-# OPTIONS_GHC -Wall -fno-warn-orphans #-} ---------------------------------------------------------------------- -- | -- Module      :  Data.LinearMap@@ -17,6 +17,7 @@    , inLMap, inLMap2, inLMap3    , liftMS, liftMS2, liftMS3    , liftL, liftL2, liftL3+   , firstL    )   where @@ -46,6 +47,28 @@ newtype u :-* v = LMap { unLMap :: LMap' u v }  deriving instance (HasTrie (Basis u), AdditiveGroup v) => AdditiveGroup (u :-* v)++instance (HasTrie (Basis u), VectorSpace v) =>+         VectorSpace (u :-* v) where+  type Scalar (u :-* v) = Scalar v+  (*^) s = (inLMap.liftMS.fmap) (s *^)++firstL :: ( HasBasis u, HasBasis u', HasBasis v+          , HasTrie (Basis u), HasTrie (Basis v) +          , Scalar u ~ Scalar v, Scalar u ~ Scalar u'+          ) =>+          (u :-* u') -> ((u,v) :-* (u',v))+firstL = linear.first.lapply++-- TODO: more efficient firstL++-- liftMS :: (AdditiveGroup a) => (a -> b) -> (MSum a -> MSum b)++-- (s *^) :: v -> v+-- fmap (s *^) :: (Basis u :->: v) -> (Basis u :->: v)+-- (liftMS.fmap) (s *^) :: LMap' u v -> LMap' u v+-- (inLMap.liftMS.fmap) (s *^) :: (u :-* v) -> (u :-* v)+  -- Before version 0.7, u :-* v was a type synonym, resulting in a subtle -- ambiguity: u:-*v == u':-*v' does not imply that u==u', since Basis
src/Data/VectorSpace.hs view
@@ -27,7 +27,7 @@   ( module Data.AdditiveGroup   , VectorSpace(..), (^/), (^*)   , InnerSpace(..)-  , lerp, magnitudeSq, magnitude, normalized+  , lerp, magnitudeSq, magnitude, normalized, project   ) where  import Control.Applicative (liftA2)@@ -81,6 +81,11 @@ -- given the zero vector, then return it. normalized :: (InnerSpace v, s ~ Scalar v, Floating s) =>  v -> v normalized v = v ^/ magnitude v++-- | @project u v@ computes the projection of @v@ onto @u@.+project :: (InnerSpace v, s ~ Scalar v, Floating s) => v -> v -> v+project u v = (v <.> u') *^ u'+  where u' = normalized u  instance VectorSpace Double where   type Scalar Double = Double
vector-space.cabal view
@@ -1,5 +1,5 @@ Name:                vector-space-Version:             0.7.3+Version:             0.7.6 Cabal-Version:       >= 1.2 Synopsis:            Vector & affine spaces, linear maps, and derivatives (requires ghc 6.9 or better) Category:            math@@ -20,7 +20,7 @@ Maintainer:          conal@conal.net Homepage:            http://haskell.org/haskellwiki/vector-space Package-Url:         http://code.haskell.org/vector-space-Copyright:           (c) 2008-2010 by Conal Elliott+Copyright:           (c) 2008-2011 by Conal Elliott License:             BSD3 License-File:        COPYING Stability:           experimental