From cf3c788f0c44577ac1a5365e8154200b53a36409 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Tue, 27 May 2014 10:41:40 +0200 Subject: static dimensions, cont. --- packages/base/src/Data/Packed/Internal/Numeric.hs | 7 ++-- packages/base/src/Data/Packed/Numeric.hs | 41 +++++++++++++++++++---- 2 files changed, 39 insertions(+), 9 deletions(-) (limited to 'packages/base/src/Data/Packed') diff --git a/packages/base/src/Data/Packed/Internal/Numeric.hs b/packages/base/src/Data/Packed/Internal/Numeric.hs index 3c1c1d0..0205a17 100644 --- a/packages/base/src/Data/Packed/Internal/Numeric.hs +++ b/packages/base/src/Data/Packed/Internal/Numeric.hs @@ -3,6 +3,7 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE UndecidableInstances #-} ----------------------------------------------------------------------------- @@ -692,12 +693,12 @@ condV f a b l e t = f a' b' l' e' t' -------------------------------------------------------------------------------- -class Transposable t +class Transposable m mt | m -> mt, mt -> m where -- | (conjugate) transpose - tr :: t -> t + tr :: m -> mt -instance (Container Vector t) => Transposable (Matrix t) +instance (Container Vector t) => Transposable (Matrix t) (Matrix t) where tr = ctrans diff --git a/packages/base/src/Data/Packed/Numeric.hs b/packages/base/src/Data/Packed/Numeric.hs index 01cf6c5..7d88cbc 100644 --- a/packages/base/src/Data/Packed/Numeric.hs +++ b/packages/base/src/Data/Packed/Numeric.hs @@ -32,7 +32,7 @@ module Data.Packed.Numeric ( diag, ident, ctrans, -- * Generic operations - Container(..), + Container(..), Numeric, -- add, mul, sub, divide, equal, scaleRecip, addConstant, scalar, conj, scale, arctan2, cmap, atIndex, minIndex, maxIndex, minElement, maxElement, @@ -40,7 +40,7 @@ module Data.Packed.Numeric ( step, cond, find, assoc, accum, Transposable(..), Linear(..), -- * Matrix product - Product(..), udot, dot, (◇), + Product(..), udot, dot, (◇), (<·>), (#>), Mul(..), Contraction(..),(<.>), optimiseMult, @@ -96,7 +96,7 @@ linspace n (a,b) = addConstant a $ scale s $ fromList $ map fromIntegral [0 .. n -------------------------------------------------------- -{- | Matrix product, matrix - vector product, and dot product (equivalent to 'contraction') +{- Matrix product, matrix - vector product, and dot product (equivalent to 'contraction') (This operator can also be written using the unicode symbol ◇ (25c7).) @@ -138,9 +138,8 @@ For complex vectors the first argument is conjugated: >>> fromList [1,i,1-i] <.> complex a fromList [10.0 :+ 4.0,12.0 :+ 4.0,14.0 :+ 4.0,16.0 :+ 4.0] -} -infixl 7 <.> -(<.>) :: Contraction a b c => a -> b -> c -(<.>) = contraction + + class Contraction a b c | a b -> c @@ -160,6 +159,23 @@ instance (Container Vector t, Product t) => Contraction (Vector t) (Matrix t) (V instance Product t => Contraction (Matrix t) (Matrix t) (Matrix t) where contraction = mXm +-------------------------------------------------------------------------------- + +infixl 7 <.> +-- | An infix synonym for 'dot' +(<.>) :: Numeric t => Vector t -> Vector t -> t +(<.>) = dot + + +infixr 8 <·>, #> +-- | dot product +(<·>) :: Numeric t => Vector t -> Vector t -> t +(<·>) = dot + + +-- | matrix-vector product +(#>) :: Numeric t => Matrix t -> Vector t -> Vector t +(#>) = mXv -------------------------------------------------------------------------------- @@ -286,3 +302,16 @@ meanCov x = (med,cov) where -------------------------------------------------------------------------------- +class ( Container Vector t + , Container Matrix t + , Konst t Int Vector + , Konst t (Int,Int) Matrix + , Product t + ) => Numeric t + +instance Numeric Double +instance Numeric (Complex Double) +instance Numeric Float +instance Numeric (Complex Float) + +-------------------------------------------------------------------------------- -- cgit v1.2.3