vector-space-map 0.1.0.0 → 0.1.0.1
raw patch · 2 files changed
+9/−3 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- src/Data/Map/Vector.hs +7/−1
- vector-space-map.cabal +2/−2
src/Data/Map/Vector.hs view
@@ -55,6 +55,7 @@ (ConstantMap f) <*> (MapVector vs) = MapVector $ f <$> vs (MapVector fs) <*> (ConstantMap v) = MapVector $ ($ v) <$> fs (MapVector fs) <*> (MapVector vs) = MapVector $ Map.intersectionWith ($) fs vs + {-# INLINABLE (<*>) #-} instance (AdditiveGroup v, Ord k) => AdditiveGroup (MapVector k v) where zeroV = MapVector Map.empty @@ -63,25 +64,30 @@ (ConstantMap v) ^+^ (MapVector vs) = MapVector $ (v ^+^) <$> vs (MapVector vs) ^+^ (ConstantMap v) = MapVector $ (^+^ v) <$> vs (MapVector vs) ^+^ (MapVector vs') = MapVector $ Map.unionWith (^+^) vs vs' + {-# INLINABLE (^+^) #-} instance (Ord k, VectorSpace v) => VectorSpace (MapVector k v) where type Scalar (MapVector k v) = Scalar v -- therefore Scalar (MapVector k (Mapvector k' v)) -- = Scalar v s *^ v = (s *^) <$> v + {-# INLINABLE (*^) #-} instance (Ord k, VectorSpace v, InnerSpace v, AdditiveGroup (Scalar v)) => InnerSpace (MapVector k v) where (ConstantMap v) <.> (ConstantMap v') = v <.> v' (ConstantMap v) <.> (MapVector vs) = foldl' (^+^) zeroV $ (v <.>) <$> vs (MapVector vs) <.> (ConstantMap v) = foldl' (^+^) zeroV $ (<.> v) <$> vs (MapVector vs) <.> (MapVector vs') = foldl' (^+^) zeroV $ Map.intersectionWith (<.>) vs vs' + {-# INLINABLE (<.>) #-} instance (Ord k, AdditiveGroup v, Num v) => Num (MapVector k v) where (+) = (^+^) + {-# INLINE (+) #-} x * y = (*) <$> x <*> y + {-# INLINE (*) #-} abs = fmap abs + {-# INLINE abs #-} fromInteger = pure . fromInteger signum = error "no signum for MapVectors" - -- It looks like a HasBasis instance should be possible; -- I just haven't spent the time to figure it out.
vector-space-map.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: vector-space-map -version: 0.1.0.0 +version: 0.1.0.1 synopsis: vector-space operations for finite maps using Data.Map description: Data.Map.Vector provides @MapVector@, a wrapper around @Map@ from @containers@ which supports constant maps, i.e. maps containing only one value. This allows an identity under intersection and an @Applicative@ instance. It also has instances of @AdditiveGroup@, @VectorSpace@, @InnerSpace@, and @Num@ with appropriate value types. Provides operations for addition, subtraction, element-wise multiplication (through @Num@), scalar multiplication (through @VectorSpace@), and dot product. homepage: https://github.com/conklech/vector-space-map @@ -22,7 +22,7 @@ source-repository this type: git location: git://github.com/conklech/vector-space-map.git - tag: 0.1.0.0 + tag: 0.1.0.1 library hs-source-dirs: src