packages feed

hmatrix 0.11.0.4 → 0.11.1.0

raw patch · 7 files changed

+168/−5 lines, 7 filesdep ~QuickCheckPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: QuickCheck

API changes (from Hackage documentation)

+ Data.Packed.Matrix: mapMatrix :: (Storable a, Storable b) => (a -> b) -> Matrix a -> Matrix b
+ Data.Packed.Matrix: mapMatrixWithIndex :: (Storable t, Element a, Num a) => ((a, a) -> a -> t) -> Matrix a -> Matrix t
+ Data.Packed.Matrix: mapMatrixWithIndexM :: (Storable t, Element a, Num a, Functor f, Monad f) => ((a, a) -> a -> f t) -> Matrix a -> f (Matrix t)
+ Data.Packed.Matrix: mapMatrixWithIndexM_ :: (Element a, Num a, Functor f, Monad f) => ((a, a) -> a -> f ()) -> Matrix a -> f ()
+ Numeric.Container: class Mul a b c | a b -> c
- Numeric.Container: (<->) :: (Joinable a b, Element t) => a t -> b t -> Matrix t
+ Numeric.Container: (<->) :: (Element t, Joinable a b) => a t -> b t -> Matrix t
- Numeric.Container: (<|>) :: (Joinable a b, Element t) => a t -> b t -> Matrix t
+ Numeric.Container: (<|>) :: (Element t, Joinable a b) => a t -> b t -> Matrix t
- Numeric.Container: cmap :: (Container c e, Element a, Element b) => (a -> b) -> c a -> c b
+ Numeric.Container: cmap :: (Container c e, Element b) => (e -> b) -> c e -> c b
- Numeric.LinearAlgebra.Algorithms: economy :: (Element t1, Element t2, Element t) => (Matrix t -> (Matrix t1, Vector Double, Matrix t2)) -> Matrix t -> (Matrix t1, Vector Double, Matrix t2)
+ Numeric.LinearAlgebra.Algorithms: economy :: (Element t, Element t1, Element t2) => (Matrix t -> (Matrix t1, Vector Double, Matrix t2)) -> Matrix t -> (Matrix t1, Vector Double, Matrix t2)
- Numeric.LinearAlgebra.Algorithms: full :: (Storable t1, Num t1) => (Matrix t -> (t2, Vector t1, t3)) -> Matrix t -> (t2, Matrix t1, t3)
+ Numeric.LinearAlgebra.Algorithms: full :: (Num t1, Storable t1) => (Matrix t -> (t2, Vector t1, t3)) -> Matrix t -> (t2, Matrix t1, t3)

Files

CHANGES view
@@ -1,3 +1,9 @@+0.11.1.0+========++- exported Mul+- mapMatrixWithIndex{,M,M_}+ 0.11.0.0 ======== 
THANKS view
@@ -89,8 +89,9 @@   helped with the configuration.  - Carter Schonwald helped with the configuration for Homebrew OS X and-  found a tolerance problem in test "1E5 rots".+  found a tolerance problem in test "1E5 rots". He also discovered+  a bug in the signature of cmap.  - Duncan Coutts reported a problem with configure.hs and contributed-  a solution and a simplified a Setup.lhs.+  a solution and a simplified Setup.lhs. 
+ examples/multiply.hs view
@@ -0,0 +1,100 @@+{-# LANGUAGE UnicodeSyntax+           , MultiParamTypeClasses+           , FunctionalDependencies+           , FlexibleInstances+           , FlexibleContexts+--           , OverlappingInstances+           , UndecidableInstances #-}++import Numeric.LinearAlgebra++class Scaling a b c | a b -> c where+ -- ^ 0x22C5	8901	DOT OPERATOR, scaling+ infixl 7 ⋅+ (⋅) :: a -> b -> c++class Contraction a b c | a b -> c where+ -- ^ 0x00D7	215	MULTIPLICATION SIGN	×, contraction+ infixl 7 ×+ (×) :: a -> b -> c++class Outer a b c | a b -> c where+ -- ^ 0x2297	8855	CIRCLED TIMES	⊗, outer product (not associative)+ infixl 7 ⊗+ (⊗) :: a -> b -> c+++-------++instance (Num t) => Scaling t t t where+    (⋅) = (*)++instance Container Vector t => Scaling t (Vector t) (Vector t) where+    (⋅) = scale++instance Container Vector t => Scaling (Vector t) t (Vector t) where+    (⋅) = flip scale++instance Container Vector t => Scaling t (Matrix t) (Matrix t) where+    (⋅) = scale++instance Container Vector t => Scaling (Matrix t) t (Matrix t) where+    (⋅) = flip scale+++instance Product t => Contraction (Vector t) (Vector t) t where+    (×) = dot++instance Product t => Contraction (Matrix t) (Vector t) (Vector t) where+    (×) = mXv++instance Product t => Contraction (Vector t) (Matrix t) (Vector t) where+    (×) = vXm++instance Product t => Contraction (Matrix t) (Matrix t) (Matrix t) where+    (×) = mXm+++--instance Scaling a b c => Contraction a b c where+--    (×) = (⋅)++-----++instance Product t => Outer (Vector t) (Vector t) (Matrix t) where+    (⊗) = outer++instance Product t => Outer (Vector t) (Matrix t) (Matrix t) where+    v ⊗ m = kronecker (asColumn v) m++instance Product t => Outer (Matrix t) (Vector t) (Matrix t) where+    m ⊗ v = kronecker m (asRow v)++instance Product t => Outer (Matrix t) (Matrix t) (Matrix t) where+    (⊗) = kronecker++-----+++v = 3 |> [1..] :: Vector Double++m = (3 >< 3) [1..] :: Matrix Double++s = 3 :: Double++a = s ⋅ v × m × m × v ⋅ s++b = (v ⊗ m) ⊗ (v ⊗ m)++c = v ⊗ m ⊗ v ⊗ m++d = s ⋅ (3 |> [10,20..] :: Vector Double)++main = do+    print $ scale s v <> m <.> v +    print $ scale s v <.> (m <> v)+    print $ s * (v <> m <.> v)+    print $ s ⋅ v × m × v+    print a+    print (b == c)+    print d+
hmatrix.cabal view
@@ -1,5 +1,5 @@ Name:               hmatrix-Version:            0.11.0.4+Version:            0.11.1.0 License:            GPL License-file:       LICENSE Author:             Alberto Ruiz@@ -54,6 +54,7 @@                     examples/vector.hs                     examples/monadic.hs                     examples/bool.hs+                    examples/multiply.hs  extra-source-files: lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.h,                     lib/Numeric/LinearAlgebra/LAPACK/clapack.h
lib/Data/Packed/Matrix.hs view
@@ -36,6 +36,7 @@     subMatrix, takeRows, dropRows, takeColumns, dropColumns,     extractRows,     diagRect, takeDiag,+    mapMatrix, mapMatrixWithIndex, mapMatrixWithIndexM, mapMatrixWithIndexM_,     liftMatrix, liftMatrix2, liftMatrix2Auto,fromArray2D ) where @@ -44,6 +45,7 @@ import Data.List(transpose,intersperse) import Data.Array import Foreign.Storable+import Control.Arrow((***))  ------------------------------------------------------------------- @@ -348,3 +350,56 @@     cs = replicate qc c ++ if rc > 0 then [rc] else []  -------------------------------------------------------------------++mk c g = \k v -> g ((fromIntegral *** fromIntegral) (divMod k c)) v ++{- | ++@ghci> mapMatrixWithIndexM_ (\\(i,j) v -> printf \"m[%.0f,%.0f] = %.f\\n\" i j v :: IO()) ((2><3)[1 :: Double ..])+m[0,0] = 1+m[0,1] = 2+m[0,2] = 3+m[1,0] = 4+m[1,1] = 5+m[1,2] = 6@+-}+mapMatrixWithIndexM_+  :: (Element a, Num a,+      Functor f, Monad f) =>+      ((a, a) -> a -> f ()) -> Matrix a -> f ()+mapMatrixWithIndexM_ g m = mapVectorWithIndexM_ (mk c g) . flatten $ m +  where+    c = cols m++{- |++@ghci> mapMatrixWithIndexM (\\(i,j) v -> Just $ 100*v + 10*i + j) (ident 3:: Matrix Double)+Just (3><3)+ [ 100.0,   1.0,   2.0+ ,  10.0, 111.0,  12.0+ ,  20.0,  21.0, 122.0 ]@+-}+mapMatrixWithIndexM+  :: (Foreign.Storable.Storable t, +      Element a, Num a,+      Functor f, Monad f) =>+      ((a, a) -> a -> f t) -> Matrix a -> f (Matrix t)+mapMatrixWithIndexM g m = fmap (reshape c) . mapVectorWithIndexM (mk c g) . flatten $ m +    where+      c = cols m++{- |+@ghci> mapMatrixWithIndex (\\(i,j) v -> 100*v + 10*i + j) (ident 3:: Matrix Double)+(3><3)+ [ 100.0,   1.0,   2.0+ ,  10.0, 111.0,  12.0+ ,  20.0,  21.0, 122.0 ]@+ -}+mapMatrixWithIndex :: (Foreign.Storable.Storable t, +      Element a, Num a) =>+      ((a, a) -> a -> t) -> Matrix a -> Matrix t+mapMatrixWithIndex g = head . mapMatrixWithIndexM (\a b -> [g a b])++mapMatrix :: (Storable a, Storable b) => (a -> b) -> Matrix a -> Matrix b+mapMatrix f = liftMatrix (mapVector f)+
lib/Numeric/Container.hs view
@@ -36,7 +36,7 @@     -- * Matrix product     Product(..),     optimiseMult,-    mXm,mXv,vXm,(<.>),(<>),(<\>),+    mXm,mXv,vXm,(<.>),Mul(..),(<\>),     outer, kronecker,     -- * Random numbers     RandDist(..),
lib/Numeric/ContainerBoot.hs view
@@ -95,7 +95,7 @@     arctan2     :: c e -> c e -> c e     --     -- | cannot implement instance Functor because of Element class constraint-    cmap        :: (Element a, Element b) => (a -> b) -> c a -> c b+    cmap        :: (Element b) => (e -> b) -> c e -> c b     -- | constant structure of given size     konst       :: e -> IndexOf c -> c e     -- | create a structure using a function