hmatrix 0.11.1.0 → 0.12.0.0
raw patch · 22 files changed
+132/−79 lines, 22 filesdep ~vectorPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: vector
API changes (from Hackage documentation)
+ Data.Packed.Vector: mapVectorWithIndex :: (Storable a, Storable b) => (Int -> a -> b) -> Vector a -> Vector b
+ Numeric.LinearAlgebra.Algorithms: geigSH' :: Field t => Matrix t -> Matrix t -> (Vector Double, Matrix t)
Files
- CHANGES +9/−0
- INSTALL +7/−3
- THANKS +5/−0
- hmatrix.cabal +3/−3
- lib/Data/Packed/Internal/Matrix.hs +8/−4
- lib/Data/Packed/Internal/Vector.hs +24/−2
- lib/Data/Packed/Matrix.hs +3/−2
- lib/Data/Packed/ST.hs +10/−2
- lib/Data/Packed/Vector.hs +1/−1
- lib/Numeric/GSL/Differentiation.hs +4/−1
- lib/Numeric/GSL/Fitting.hs +4/−2
- lib/Numeric/GSL/Fourier.hs +1/−1
- lib/Numeric/GSL/Integration.hs +4/−2
- lib/Numeric/GSL/Internal.hs +4/−1
- lib/Numeric/GSL/Minimization.hs +4/−2
- lib/Numeric/GSL/ODE.hs +4/−2
- lib/Numeric/GSL/Polynomials.hs +1/−1
- lib/Numeric/GSL/Root.hs +4/−2
- lib/Numeric/GSL/Vector.hs +4/−1
- lib/Numeric/LinearAlgebra/Algorithms.hs +18/−0
- lib/Numeric/LinearAlgebra/LAPACK.hs +4/−3
- lib/Numeric/Vector.hs +6/−44
CHANGES view
@@ -1,7 +1,16 @@+0.11.2.0+========++- geigSH' (symmetric generalized eigensystem)++- mapVectorWithIndex++ 0.11.1.0 ======== - exported Mul+ - mapMatrixWithIndex{,M,M_} 0.11.0.0
INSTALL view
@@ -9,11 +9,13 @@ INSTALLATION ON WINDOWS -1) Install the Haskell Platform (tested on 2009.2.0.2).+1) Install the Haskell Platform (tested on 2011.2.0.1) + > cabal update+ 2) Download and unzip the following file into a stable folder %GSL% - http://code.haskell.org/hmatrix/gsl-lapack-windows.zip+ http://perception.inf.um.es/hmatrix/gsl-lapack-windows.zip 3.a) In a msys shell installation should be fully automatic: @@ -23,9 +25,11 @@ > cabal unpack hmatrix - Edit hmatrix.cabal, in line 18 change build-type to "Simple", and then+ Edit hmatrix.cabal, in line 28 change build-type to "Simple", and then > cabal install --extra-lib-dir=%GSL% --extra-include-dir=%GSL%++ It may be necessary to put the dlls in the search path. 4) If everything is ok we can run the tests:
THANKS view
@@ -95,3 +95,8 @@ - Duncan Coutts reported a problem with configure.hs and contributed a solution and a simplified Setup.lhs. +- Mark Wright fixed the import of vector >= 0.8.++- Bas van Dijk fixed the import of vector >= 0.8, got rid of some+ deprecation warnings and used more explicit imports.+
hmatrix.cabal view
@@ -1,5 +1,5 @@ Name: hmatrix-Version: 0.11.1.0+Version: 0.12.0.0 License: GPL License-file: LICENSE Author: Alberto Ruiz@@ -21,7 +21,7 @@ . - "Numeric.LinearAlgebra": everything + instances of standard Haskell numeric classes Category: Math-tested-with: GHC ==6.10.4, GHC ==6.12.1, GHC ==6.12.3, GHC ==7.0.1, GHC==7.0.2+tested-with: GHC ==6.10.4, GHC ==6.12.1, GHC ==6.12.3, GHC ==7.0.1, GHC==7.0.2, GHC==7.2.1 cabal-version: >=1.6 @@ -144,7 +144,7 @@ lib/Numeric/GSL/gsl-aux.c if flag(vector)- Build-Depends: vector >= 0.7+ Build-Depends: vector >= 0.8 cpp-options: -DVECTOR if flag(binary)
lib/Data/Packed/Internal/Matrix.hs view
@@ -39,10 +39,14 @@ import Data.Packed.Internal.Signatures import Data.Packed.Internal.Vector -import Foreign hiding (xor)-import Data.Complex-import Foreign.C.Types-import Foreign.C.String+import Foreign.Marshal.Alloc(alloca, free)+import Foreign.Marshal.Array(newArray)+import Foreign.Ptr(Ptr, castPtr)+import Foreign.Storable(Storable, peekElemOff, pokeElemOff, poke, sizeOf)+import Data.Complex(Complex)+import Foreign.C.Types(CInt, CChar)+import Foreign.C.String(newCString)+import System.IO.Unsafe(unsafePerformIO) -----------------------------------------------------------------
lib/Data/Packed/Internal/Vector.hs view
@@ -17,7 +17,7 @@ Vector, dim, fromList, toList, (|>), join, (@>), safe, at, at', subVector, takesV,- mapVector, zipVectorWith, unzipVectorWith,+ mapVector, mapVectorWithIndex, zipVectorWith, unzipVectorWith, mapVectorM, mapVectorM_, mapVectorWithIndexM, mapVectorWithIndexM_, foldVector, foldVectorG, foldLoop, foldVectorWithIndex, createVector, vec,@@ -32,11 +32,16 @@ import Data.Packed.Internal.Common import Data.Packed.Internal.Signatures-import Foreign+import Foreign.Marshal.Alloc(free)+import Foreign.Marshal.Array(peekArray, pokeArray, copyArray, advancePtr)+import Foreign.ForeignPtr(ForeignPtr, castForeignPtr)+import Foreign.Ptr(Ptr)+import Foreign.Storable(Storable, peekElemOff, pokeElemOff, sizeOf) import Foreign.C.String import Foreign.C.Types(CInt,CChar) import Data.Complex import Control.Monad(when)+import System.IO.Unsafe(unsafePerformIO) #if __GLASGOW_HASKELL__ >= 605 import GHC.ForeignPtr (mallocPlainForeignPtrBytes)@@ -55,6 +60,8 @@ unsafeToForeignPtr, unsafeFromForeignPtr, unsafeWith)+#else+import Foreign.ForeignPtr(withForeignPtr) #endif #ifdef VECTOR@@ -496,6 +503,21 @@ _ <- f k x mapVectorM' (k+1) t {-# INLINE mapVectorWithIndexM_ #-}+++mapVectorWithIndex :: (Storable a, Storable b) => (Int -> a -> b) -> Vector a -> Vector b+--mapVectorWithIndex g = head . mapVectorWithIndexM (\a b -> [g a b])+mapVectorWithIndex f v = unsafePerformIO $ do+ w <- createVector (dim v)+ unsafeWith v $ \p ->+ unsafeWith w $ \q -> do+ let go (-1) = return ()+ go !k = do x <- peekElemOff p k+ pokeElemOff q k (f k x)+ go (k-1)+ go (dim v -1)+ return w+{-# INLINE mapVectorWithIndex #-} -------------------------------------------------------------------
lib/Data/Packed/Matrix.hs view
@@ -42,9 +42,10 @@ import Data.Packed.Internal import qualified Data.Packed.ST as ST-import Data.List(transpose,intersperse) import Data.Array-import Foreign.Storable++import Data.List(transpose,intersperse)+import Foreign.Storable(Storable) import Control.Arrow((***)) -------------------------------------------------------------------
lib/Data/Packed/ST.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE Rank2Types #-} {-# LANGUAGE BangPatterns #-}@@ -33,8 +34,15 @@ ) where import Data.Packed.Internal-import Control.Monad.ST-import Foreign++import Control.Monad.ST(ST, runST)+import Foreign.Storable(Storable, peekElemOff, pokeElemOff)++#if MIN_VERSION_base(4,4,0)+import Control.Monad.ST.Unsafe(unsafeIOToST)+#else+import Control.Monad.ST(unsafeIOToST)+#endif {-# INLINE ioReadV #-} ioReadV :: Storable t => Vector t -> Int -> IO t
lib/Data/Packed/Vector.hs view
@@ -20,7 +20,7 @@ fromList, (|>), toList, buildVector, dim, (@>), subVector, takesV, join,- mapVector, zipVector, zipVectorWith, unzipVector, unzipVectorWith,+ mapVector, mapVectorWithIndex, zipVector, zipVectorWith, unzipVector, unzipVectorWith, mapVectorM, mapVectorM_, mapVectorWithIndexM, mapVectorWithIndexM_, foldLoop, foldVector, foldVectorG, foldVectorWithIndex ) where
lib/Numeric/GSL/Differentiation.hs view
@@ -22,9 +22,12 @@ derivBackward ) where -import Foreign import Foreign.C.Types(CInt)+import Foreign.Marshal.Alloc(malloc, free)+import Foreign.Ptr(Ptr, FunPtr, freeHaskellFunPtr)+import Foreign.Storable(peek) import Data.Packed.Internal(check,(//))+import System.IO.Unsafe(unsafePerformIO) derivGen :: CInt -- ^ type: 0 central, 1 forward, 2 backward
lib/Numeric/GSL/Fitting.hs view
@@ -51,9 +51,11 @@ import Data.Packed.Internal import Numeric.LinearAlgebra-import Foreign-import Foreign.C.Types(CInt) import Numeric.GSL.Internal++import Foreign.Ptr(FunPtr, freeHaskellFunPtr)+import Foreign.C.Types(CInt)+import System.IO.Unsafe(unsafePerformIO) -------------------------------------------------------------------------
lib/Numeric/GSL/Fourier.hs view
@@ -22,8 +22,8 @@ import Data.Packed.Internal import Data.Complex-import Foreign import Foreign.C.Types(CInt)+import System.IO.Unsafe (unsafePerformIO) genfft code v = unsafePerformIO $ do r <- createVector (dim v)
lib/Numeric/GSL/Integration.hs view
@@ -20,10 +20,12 @@ integrateQAGS ) where -import Foreign import Foreign.C.Types(CInt)+import Foreign.Marshal.Alloc(malloc, free)+import Foreign.Ptr(Ptr, FunPtr, freeHaskellFunPtr)+import Foreign.Storable(peek) import Data.Packed.Internal(check,(//))-+import System.IO.Unsafe(unsafePerformIO) {- | conversion of Haskell functions into function pointers that can be used in the C side -}
lib/Numeric/GSL/Internal.hs view
@@ -13,8 +13,11 @@ module Numeric.GSL.Internal where import Data.Packed.Internal-import Foreign++import Foreign.Marshal.Array(copyArray)+import Foreign.Ptr(Ptr, FunPtr) import Foreign.C.Types(CInt)+import System.IO.Unsafe(unsafePerformIO) iv :: (Vector Double -> Double) -> (CInt -> Ptr Double -> Double) iv f n p = f (createV (fromIntegral n) copy "iv") where
lib/Numeric/GSL/Minimization.hs view
@@ -62,9 +62,11 @@ import Data.Packed.Internal import Data.Packed.Matrix-import Foreign-import Foreign.C.Types(CInt) import Numeric.GSL.Internal++import Foreign.Ptr(Ptr, FunPtr, freeHaskellFunPtr)+import Foreign.C.Types(CInt)+import System.IO.Unsafe(unsafePerformIO) ------------------------------------------------------------------------
lib/Numeric/GSL/ODE.hs view
@@ -33,9 +33,11 @@ ) where import Data.Packed.Internal-import Foreign-import Foreign.C.Types(CInt) import Numeric.GSL.Internal++import Foreign.Ptr(FunPtr, nullFunPtr, freeHaskellFunPtr)+import Foreign.C.Types(CInt)+import System.IO.Unsafe(unsafePerformIO) -------------------------------------------------------------------------
lib/Numeric/GSL/Polynomials.hs view
@@ -21,7 +21,7 @@ import Data.Packed.Internal import Data.Complex-import Foreign+import System.IO.Unsafe (unsafePerformIO) {- | Solution of general polynomial equations, using /gsl_poly_complex_solve/. For example, the three solutions of x^3 + 8 = 0
lib/Numeric/GSL/Root.hs view
@@ -51,9 +51,11 @@ import Data.Packed.Internal import Data.Packed.Matrix-import Foreign-import Foreign.C.Types(CInt) import Numeric.GSL.Internal++import Foreign.Ptr(FunPtr, freeHaskellFunPtr)+import Foreign.C.Types(CInt)+import System.IO.Unsafe(unsafePerformIO) -------------------------------------------------------------------------
lib/Numeric/GSL/Vector.hs view
@@ -28,8 +28,11 @@ import Data.Packed.Internal.Vector import Data.Complex-import Foreign+import Foreign.Marshal.Alloc(free)+import Foreign.Marshal.Array(newArray)+import Foreign.Ptr(Ptr) import Foreign.C.Types(CInt)+import System.IO.Unsafe(unsafePerformIO) fromei x = fromIntegral (fromEnum x) :: CInt
lib/Numeric/LinearAlgebra/Algorithms.hs view
@@ -44,6 +44,7 @@ -- ** Eigensystems eig, eigSH, eigSH', eigenvalues, eigenvaluesSH, eigenvaluesSH',+ geigSH', -- ** QR qr, rq, -- ** Cholesky@@ -711,4 +712,21 @@ relativeError x y = dig (norm (x `sub` y) / norm x) where norm = pnorm Infinity dig r = round $ -logBase 10 (realToFrac r :: Double)++----------------------------------------------------------------------++-- | Generalized symmetric positive definite eigensystem Av = lBv,+-- for A and B symmetric, B positive definite (conditions not checked).+geigSH' :: Field t+ => Matrix t -- ^ A+ -> Matrix t -- ^ B+ -> (Vector Double, Matrix t)+geigSH' a b = (l,v')+ where+ u = cholSH b+ iu = inv u+ c = ctrans iu <> a <> iu+ (l,v) = eigSH' c+ v' = iu <> v+ (<>) = mXm
lib/Numeric/LinearAlgebra/LAPACK.hs view
@@ -43,12 +43,13 @@ import Data.Packed.Internal import Data.Packed.Matrix---import Data.Complex import Numeric.Conversion import Numeric.GSL.Vector(vectorMapValR, FunCodeSV(Scale))-import Foreign-import Foreign.C.Types (CInt)++import Foreign.Ptr(nullPtr)+import Foreign.C.Types(CInt) import Control.Monad(when)+import System.IO.Unsafe(unsafePerformIO) -----------------------------------------------------------------------------------
lib/Numeric/Vector.hs view
@@ -6,7 +6,7 @@ ----------------------------------------------------------------------------- -- | -- Module : Numeric.Vector--- Copyright : (c) Alberto Ruiz 2010+-- Copyright : (c) Alberto Ruiz 2011 -- License : GPL-style -- -- Maintainer : Alberto Ruiz <aruiz@um.es>@@ -18,8 +18,7 @@ -- ----------------------------------------------------------------------------- -module Numeric.Vector (- ) where+module Numeric.Vector () where import Numeric.GSL.Vector import Numeric.Container@@ -37,29 +36,20 @@ instance (Show a, Storable a) => (Show (Vector a)) where show v = (show (dim v))++" |> " ++ show (toList v) -#endif--#ifdef VECTOR--instance (Element a, Read a) => Read (Vector a) where- readsPrec _ s = [(fromList . read $ listnums, rest)]- where (thing,trest) = breakAt ']' s- (dims,listnums) = breakAt ' ' (dropWhile (==' ') thing)- rest = drop 31 trest-#else+instance Container Vector a => Eq (Vector a) where+ (==) = equal instance (Element a, Read a) => Read (Vector a) where readsPrec _ s = [((d |>) . read $ listnums, rest)] where (thing,rest) = breakAt ']' s (dims,listnums) = breakAt '>' thing d = read . init . fst . breakAt '|' $ dims+ breakAt c l = (a++[c],tail b) where+ (a,b) = break (==c) l #endif -breakAt c l = (a++[c],tail b) where- (a,b) = break (==c) l - ------------------------------------------------------------------ adaptScalar f1 f2 f3 x y@@ -69,13 +59,6 @@ ------------------------------------------------------------------ -#ifndef VECTOR--instance Container Vector a => Eq (Vector a) where- (==) = equal--#endif- instance Num (Vector Float) where (+) = adaptScalar addConstant add (flip addConstant) negate = scale (-1)@@ -199,25 +182,4 @@ sqrt = vectorMapQ Sqrt (**) = adaptScalar (vectorMapValQ PowSV) (vectorZipQ Pow) (flip (vectorMapValQ PowVS)) pi = fromList [pi]------------------------------------------------------------------ instance (Storable a, Num (Vector a)) => Monoid (Vector a) where--- mempty = 0 { idim = 0 }--- mappend a b = mconcat [a,b]--- mconcat = j . filter ((>0).dim)--- where j [] = mempty--- j l = join l--------------------------------------------------------------------- instance (NFData a, Storable a) => NFData (Vector a) where--- rnf = rnf . (@>0)------ instance (NFData a, Element a) => NFData (Matrix a) where--- rnf = rnf . flatten-----------------------------------------------------------------------------