From 51f4cc7b4b301142b8df73568ffaa448f9e6dd50 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Fri, 16 May 2014 14:13:49 +0200 Subject: license changes, reexport modules --- packages/base/hmatrix-base.cabal | 4 +- packages/base/src/Data/Packed.hs | 1 + packages/base/src/Data/Packed/Development.hs | 1 + packages/base/src/Data/Packed/Foreign.hs | 1 + packages/base/src/Data/Packed/Internal.hs | 6 +- packages/base/src/Data/Packed/Matrix.hs | 5 +- packages/base/src/Data/Packed/Numeric.hs | 1 - packages/base/src/Data/Packed/ST.hs | 2 +- packages/base/src/Data/Packed/Vector.hs | 5 +- packages/base/src/Numeric/Container.hs | 6 +- packages/base/src/Numeric/LinearAlgebra.hs | 30 --- .../base/src/Numeric/LinearAlgebra/Algorithms.hs | 9 +- packages/base/src/Numeric/LinearAlgebra/Base.hs | 139 ++++++++++++ packages/base/src/Numeric/LinearAlgebra/Data.hs | 68 ++++++ packages/base/src/Numeric/LinearAlgebra/Devel.hs | 68 ++++++ packages/base/src/Numeric/LinearAlgebra/LAPACK.hs | 1 - packages/base/src/Numeric/LinearAlgebra/Util.hs | 5 +- .../src/Numeric/LinearAlgebra/Util/Convolution.hs | 7 +- packages/base/src/Numeric/Matrix.hs | 7 +- packages/base/src/Numeric/Vector.hs | 5 +- packages/hmatrix/src/Numeric/Container.hs | 241 +++++++++++++++++++++ packages/hmatrix/src/Numeric/HMatrix.hs | 139 ------------ packages/hmatrix/src/Numeric/HMatrix/Data.hs | 70 ------ packages/hmatrix/src/Numeric/HMatrix/Devel.hs | 69 ------ 24 files changed, 545 insertions(+), 345 deletions(-) delete mode 100644 packages/base/src/Numeric/LinearAlgebra.hs create mode 100644 packages/base/src/Numeric/LinearAlgebra/Base.hs create mode 100644 packages/base/src/Numeric/LinearAlgebra/Data.hs create mode 100644 packages/base/src/Numeric/LinearAlgebra/Devel.hs create mode 100644 packages/hmatrix/src/Numeric/Container.hs delete mode 100644 packages/hmatrix/src/Numeric/HMatrix.hs delete mode 100644 packages/hmatrix/src/Numeric/HMatrix/Data.hs delete mode 100644 packages/hmatrix/src/Numeric/HMatrix/Devel.hs diff --git a/packages/base/hmatrix-base.cabal b/packages/base/hmatrix-base.cabal index 3f12dad..638390a 100644 --- a/packages/base/hmatrix-base.cabal +++ b/packages/base/hmatrix-base.cabal @@ -39,10 +39,12 @@ library Numeric.LinearAlgebra.LAPACK Numeric.LinearAlgebra.Algorithms Numeric.Container - Numeric.LinearAlgebra Numeric.LinearAlgebra.Util Numeric.LinearAlgebra.Util.Convolution Data.Packed.IO + Numeric.LinearAlgebra.Base + Numeric.LinearAlgebra.Devel + Numeric.LinearAlgebra.Data other-modules: Data.Packed.Internal, Data.Packed.Internal.Common, diff --git a/packages/base/src/Data/Packed.hs b/packages/base/src/Data/Packed.hs index c66718a..129bd22 100644 --- a/packages/base/src/Data/Packed.hs +++ b/packages/base/src/Data/Packed.hs @@ -10,6 +10,7 @@ Types for dense 'Vector' and 'Matrix' of 'Storable' elements. -} ----------------------------------------------------------------------------- +{-# OPTIONS_HADDOCK hide #-} module Data.Packed ( -- * Vector diff --git a/packages/base/src/Data/Packed/Development.hs b/packages/base/src/Data/Packed/Development.hs index 6dfd551..1efedc9 100644 --- a/packages/base/src/Data/Packed/Development.hs +++ b/packages/base/src/Data/Packed/Development.hs @@ -13,6 +13,7 @@ -- in the @examples\/devel@ folder included in the package. -- ----------------------------------------------------------------------------- +{-# OPTIONS_HADDOCK hide #-} module Data.Packed.Development ( createVector, createMatrix, diff --git a/packages/base/src/Data/Packed/Foreign.hs b/packages/base/src/Data/Packed/Foreign.hs index efa51ca..1ec3694 100644 --- a/packages/base/src/Data/Packed/Foreign.hs +++ b/packages/base/src/Data/Packed/Foreign.hs @@ -6,6 +6,7 @@ -- @ glUniformMatrix4fv 0 1 (fromIntegral gl_TRUE) \`appMatrix\` perspective 0.01 100 (pi\/2) (4\/3) -- @ -- +{-# OPTIONS_HADDOCK hide #-} module Data.Packed.Foreign ( app , appVector, appVectorLen diff --git a/packages/base/src/Data/Packed/Internal.hs b/packages/base/src/Data/Packed/Internal.hs index 537e51e..59a72fc 100644 --- a/packages/base/src/Data/Packed/Internal.hs +++ b/packages/base/src/Data/Packed/Internal.hs @@ -2,11 +2,9 @@ -- | -- Module : Data.Packed.Internal -- Copyright : (c) Alberto Ruiz 2007 --- License : GPL-style --- --- Maintainer : Alberto Ruiz +-- License : BSD3 +-- Maintainer : Alberto Ruiz -- Stability : provisional --- Portability : portable -- -- Reexports all internal modules -- diff --git a/packages/base/src/Data/Packed/Matrix.hs b/packages/base/src/Data/Packed/Matrix.hs index d94d167..b3be823 100644 --- a/packages/base/src/Data/Packed/Matrix.hs +++ b/packages/base/src/Data/Packed/Matrix.hs @@ -8,9 +8,8 @@ -- | -- Module : Data.Packed.Matrix -- Copyright : (c) Alberto Ruiz 2007-10 --- License : GPL --- --- Maintainer : Alberto Ruiz +-- License : BSD3 +-- Maintainer : Alberto Ruiz -- Stability : provisional -- -- A Matrix representation suitable for numerical computations using LAPACK and GSL. diff --git a/packages/base/src/Data/Packed/Numeric.hs b/packages/base/src/Data/Packed/Numeric.hs index 4892089..c13e91d 100644 --- a/packages/base/src/Data/Packed/Numeric.hs +++ b/packages/base/src/Data/Packed/Numeric.hs @@ -10,7 +10,6 @@ -- Module : Data.Packed.Numeric -- Copyright : (c) Alberto Ruiz 2010-14 -- License : BSD3 --- -- Maintainer : Alberto Ruiz -- Stability : provisional -- diff --git a/packages/base/src/Data/Packed/ST.hs b/packages/base/src/Data/Packed/ST.hs index dae457c..5c45c7b 100644 --- a/packages/base/src/Data/Packed/ST.hs +++ b/packages/base/src/Data/Packed/ST.hs @@ -9,12 +9,12 @@ -- License : BSD3 -- Maintainer : Alberto Ruiz -- Stability : provisional --- Portability : portable -- -- In-place manipulation inside the ST monad. -- See examples/inplace.hs in the distribution. -- ----------------------------------------------------------------------------- +{-# OPTIONS_HADDOCK hide #-} module Data.Packed.ST ( -- * Mutable Vectors diff --git a/packages/base/src/Data/Packed/Vector.hs b/packages/base/src/Data/Packed/Vector.hs index a8f6bb1..53fe563 100644 --- a/packages/base/src/Data/Packed/Vector.hs +++ b/packages/base/src/Data/Packed/Vector.hs @@ -4,9 +4,8 @@ -- | -- Module : Data.Packed.Vector -- Copyright : (c) Alberto Ruiz 2007-10 --- License : GPL --- --- Maintainer : Alberto Ruiz +-- License : BSD3 +-- Maintainer : Alberto Ruiz -- Stability : provisional -- -- 1D arrays suitable for numeric computations using external libraries. diff --git a/packages/base/src/Numeric/Container.hs b/packages/base/src/Numeric/Container.hs index b7d3b80..240e5f5 100644 --- a/packages/base/src/Numeric/Container.hs +++ b/packages/base/src/Numeric/Container.hs @@ -9,11 +9,9 @@ -- | -- Module : Numeric.Container -- Copyright : (c) Alberto Ruiz 2010-14 --- License : GPL --- --- Maintainer : Alberto Ruiz +-- License : BSD3 +-- Maintainer : Alberto Ruiz -- Stability : provisional --- Portability : portable -- -- Basic numeric operations on 'Vector' and 'Matrix', including conversion routines. -- diff --git a/packages/base/src/Numeric/LinearAlgebra.hs b/packages/base/src/Numeric/LinearAlgebra.hs deleted file mode 100644 index 1db860c..0000000 --- a/packages/base/src/Numeric/LinearAlgebra.hs +++ /dev/null @@ -1,30 +0,0 @@ ------------------------------------------------------------------------------ -{- | -Module : Numeric.LinearAlgebra -Copyright : (c) Alberto Ruiz 2006-10 -License : GPL-style - -Maintainer : Alberto Ruiz (aruiz at um dot es) -Stability : provisional -Portability : uses ffi - -This module reexports all normally required functions for Linear Algebra applications. - -It also provides instances of standard classes 'Show', 'Read', 'Eq', -'Num', 'Fractional', and 'Floating' for 'Vector' and 'Matrix'. -In arithmetic operations one-component vectors and matrices automatically -expand to match the dimensions of the other operand. - --} ------------------------------------------------------------------------------ -{-# OPTIONS_HADDOCK hide #-} - -module Numeric.LinearAlgebra ( - module Numeric.Container, - module Numeric.LinearAlgebra.Algorithms -) where - -import Numeric.Container -import Numeric.LinearAlgebra.Algorithms -import Numeric.Matrix() -import Numeric.Vector() diff --git a/packages/base/src/Numeric/LinearAlgebra/Algorithms.hs b/packages/base/src/Numeric/LinearAlgebra/Algorithms.hs index 6f40683..92761be 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Algorithms.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Algorithms.hs @@ -7,12 +7,10 @@ ----------------------------------------------------------------------------- {- | Module : Numeric.LinearAlgebra.Algorithms -Copyright : (c) Alberto Ruiz 2006-9 -License : GPL-style - -Maintainer : Alberto Ruiz (aruiz at um dot es) +Copyright : (c) Alberto Ruiz 2006-14 +License : BSD3 +Maintainer : Alberto Ruiz Stability : provisional -Portability : uses ffi High level generic interface to common matrix computations. @@ -20,6 +18,7 @@ Specific functions for particular base types can also be explicitly imported from "Numeric.LinearAlgebra.LAPACK". -} +{-# OPTIONS_HADDOCK hide #-} ----------------------------------------------------------------------------- module Numeric.LinearAlgebra.Algorithms ( diff --git a/packages/base/src/Numeric/LinearAlgebra/Base.hs b/packages/base/src/Numeric/LinearAlgebra/Base.hs new file mode 100644 index 0000000..8aa7846 --- /dev/null +++ b/packages/base/src/Numeric/LinearAlgebra/Base.hs @@ -0,0 +1,139 @@ +----------------------------------------------------------------------------- +{- | +Module : Numeric.LinearAlgebra +Copyright : (c) Alberto Ruiz 2006-14 +License : BSD3 +Maintainer : Alberto Ruiz +Stability : provisional + +This module reexports the most common Linear Algebra functions. + +-} +----------------------------------------------------------------------------- +module Numeric.LinearAlgebra.Base ( + + -- * Basic types and data processing + module Numeric.LinearAlgebra.Data, + + -- | The standard numeric classes are defined elementwise: + -- + -- >>> fromList [1,2,3] * fromList [3,0,-2 :: Double] + -- fromList [3.0,0.0,-6.0] + -- + -- >>> (3><3) [1..9] * ident 3 :: Matrix Double + -- (3><3) + -- [ 1.0, 0.0, 0.0 + -- , 0.0, 5.0, 0.0 + -- , 0.0, 0.0, 9.0 ] + -- + -- In arithmetic operations single-element vectors and matrices + -- (created from numeric literals or using 'scalar') automatically + -- expand to match the dimensions of the other operand: + -- + -- >>> 5 + 2*ident 3 :: Matrix Double + -- (3><3) + -- [ 7.0, 5.0, 5.0 + -- , 5.0, 7.0, 5.0 + -- , 5.0, 5.0, 7.0 ] + -- + + -- * Products + (<.>), + + -- | The matrix product is also implemented in the "Data.Monoid" instance for Matrix, where + -- single-element matrices (created from numeric literals or using 'scalar') + -- are used for scaling. + -- + -- >>> let m = (2><3)[1..] :: Matrix Double + -- >>> m <> 2 <> diagl[0.5,1,0] + -- (2><3) + -- [ 1.0, 4.0, 0.0 + -- , 4.0, 10.0, 0.0 ] + -- + -- mconcat uses 'optimiseMult' to get the optimal association order. + + (◇), + outer, kronecker, cross, + scale, + sumElements, prodElements, absSum, + + -- * Linear Systems + (<\>), + linearSolve, + linearSolveLS, + linearSolveSVD, + luSolve, + cholSolve, + + -- * Inverse and pseudoinverse + inv, pinv, pinvTol, + + -- * Determinant and rank + rcond, rank, ranksv, + det, invlndet, + + -- * Singular value decomposition + svd, + fullSVD, + thinSVD, + compactSVD, + singularValues, + leftSV, rightSV, + + -- * Eigensystems + eig, eigSH, eigSH', + eigenvalues, eigenvaluesSH, eigenvaluesSH', + geigSH', + + -- * QR + qr, rq, qrRaw, qrgr, + + -- * Cholesky + chol, cholSH, mbCholSH, + + -- * Hessenberg + hess, + + -- * Schur + schur, + + -- * LU + lu, luPacked, + + -- * Matrix functions + expm, + sqrtm, + matFunc, + + -- * Nullspace + nullspacePrec, + nullVector, + nullspaceSVD, + null1, null1sym, + + orth, + + -- * Norms + norm1, norm2, normInf, pnorm, NormType(..), + + -- * Correlation and Convolution + corr, conv, corrMin, corr2, conv2, + + -- * Random arrays + + -- | rand, randn, RandDist(..), randomVector, gaussianSample, uniformSample + + -- * Misc + meanCov, peps, relativeError, haussholder, optimiseMult, udot +) where + +import Numeric.LinearAlgebra.Data + +import Numeric.Matrix() +import Numeric.Vector() +import Numeric.Container +import Numeric.LinearAlgebra.Algorithms +import Numeric.LinearAlgebra.Util + + + diff --git a/packages/base/src/Numeric/LinearAlgebra/Data.hs b/packages/base/src/Numeric/LinearAlgebra/Data.hs new file mode 100644 index 0000000..3bc88f9 --- /dev/null +++ b/packages/base/src/Numeric/LinearAlgebra/Data.hs @@ -0,0 +1,68 @@ +-------------------------------------------------------------------------------- +{- | +Module : Numeric.LinearAlgebra.Data +Copyright : (c) Alberto Ruiz 2014 +License : BSD3 +Maintainer : Alberto Ruiz +Stability : provisional + +Basic data processing. + +-} +-------------------------------------------------------------------------------- + +module Numeric.LinearAlgebra.Data( + + -- * Vector + -- | 1D arrays are storable vectors from the vector package. + + Vector, (|>), dim, (@>), + + -- * Matrix + Matrix, (><), size, (@@>), trans, ctrans, + + -- * Construction + scalar, konst, build, assoc, accum, linspace, -- ones, zeros, + + -- * Diagonal + ident, diag, diagl, diagRect, takeDiag, + + -- * Data manipulation + fromList, toList, subVector, takesV, vjoin, + flatten, reshape, asRow, asColumn, row, col, + fromRows, toRows, fromColumns, toColumns, fromLists, toLists, fromArray2D, + takeRows, dropRows, takeColumns, dropColumns, subMatrix, (?), (¿), fliprl, flipud, + + -- * Block matrix + fromBlocks, (¦), (——), diagBlock, repmat, toBlocks, toBlocksEvery, + + -- * Mapping functions + conj, cmap, step, cond, + + -- * Find elements + find, maxIndex, minIndex, maxElement, minElement, atIndex, + + -- * IO + disp, dispf, disps, dispcf, latexFormat, format, readMatrix, + + -- | loadMatrix, saveMatrix, fromFile, fileDimensions, fscanfVector, fprintfVector, freadVector, fwriteVector + +-- * Conversion + Convert(..), + + -- * Misc + arctan2, + rows, cols, + separable, + + module Data.Complex + +) where + +import Data.Packed.Vector +import Data.Packed.Matrix +import Numeric.Container +import Data.Packed.IO +import Numeric.LinearAlgebra.Util +import Data.Complex + diff --git a/packages/base/src/Numeric/LinearAlgebra/Devel.hs b/packages/base/src/Numeric/LinearAlgebra/Devel.hs new file mode 100644 index 0000000..c41db2d --- /dev/null +++ b/packages/base/src/Numeric/LinearAlgebra/Devel.hs @@ -0,0 +1,68 @@ +-------------------------------------------------------------------------------- +{- | +Module : Numeric.HMatrix.Devel +Copyright : (c) Alberto Ruiz 2014 +License : BSD3 +Maintainer : Alberto Ruiz +Stability : provisional + +The library can be easily extended using the tools in this module. + +-} +-------------------------------------------------------------------------------- + +module Numeric.LinearAlgebra.Devel( + -- * FFI helpers + -- | Sample usage, to upload a perspective matrix to a shader. + -- + -- @ glUniformMatrix4fv 0 1 (fromIntegral gl_TRUE) \`appMatrix\` perspective 0.01 100 (pi\/2) (4\/3) + -- @ + module Data.Packed.Foreign, + + -- * FFI tools + -- | Illustrative usage examples can be found + -- in the @examples\/devel@ folder included in the package. + module Data.Packed.Development, + + -- * ST + -- | In-place manipulation inside the ST monad. + -- See examples\/inplace.hs in the distribution. + + -- ** Mutable Vectors + STVector, newVector, thawVector, freezeVector, runSTVector, + readVector, writeVector, modifyVector, liftSTVector, + -- ** Mutable Matrices + STMatrix, newMatrix, thawMatrix, freezeMatrix, runSTMatrix, + readMatrix, writeMatrix, modifyMatrix, liftSTMatrix, + -- ** Unsafe functions + newUndefinedVector, + unsafeReadVector, unsafeWriteVector, + unsafeThawVector, unsafeFreezeVector, + newUndefinedMatrix, + unsafeReadMatrix, unsafeWriteMatrix, + unsafeThawMatrix, unsafeFreezeMatrix, + + -- * Special maps and zips + mapVectorWithIndex, zipVector, zipVectorWith, unzipVector, unzipVectorWith, + mapVectorM, mapVectorM_, mapVectorWithIndexM, mapVectorWithIndexM_, + foldLoop, foldVector, foldVectorG, foldVectorWithIndex, + mapMatrixWithIndex, mapMatrixWithIndexM, mapMatrixWithIndexM_, + liftMatrix, liftMatrix2, liftMatrix2Auto, + + -- * Auxiliary classes + Element, Container, Product, Contraction, LSDiv, + Complexable(), RealElement(), + RealOf, ComplexOf, SingleOf, DoubleOf, + IndexOf, + Field, Normed +) where + +import Data.Packed.Foreign +import Data.Packed.Development +import Data.Packed.ST +import Numeric.Container(Container,Contraction,LSDiv,Product, + Complexable(),RealElement(), + RealOf, ComplexOf, SingleOf, DoubleOf, IndexOf) +import Data.Packed +import Numeric.LinearAlgebra.Algorithms(Field,Normed) + diff --git a/packages/base/src/Numeric/LinearAlgebra/LAPACK.hs b/packages/base/src/Numeric/LinearAlgebra/LAPACK.hs index 9cb67d4..40fef45 100644 --- a/packages/base/src/Numeric/LinearAlgebra/LAPACK.hs +++ b/packages/base/src/Numeric/LinearAlgebra/LAPACK.hs @@ -3,7 +3,6 @@ -- Module : Numeric.LinearAlgebra.LAPACK -- Copyright : (c) Alberto Ruiz 2006-14 -- License : BSD3 --- -- Maintainer : Alberto Ruiz -- Stability : provisional -- diff --git a/packages/base/src/Numeric/LinearAlgebra/Util.hs b/packages/base/src/Numeric/LinearAlgebra/Util.hs index 533c54b..f0470ab 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Util.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Util.hs @@ -3,9 +3,8 @@ {- | Module : Numeric.LinearAlgebra.Util Copyright : (c) Alberto Ruiz 2013 -License : GPL - -Maintainer : Alberto Ruiz (aruiz at um dot es) +License : BSD3 +Maintainer : Alberto Ruiz Stability : provisional -} diff --git a/packages/base/src/Numeric/LinearAlgebra/Util/Convolution.hs b/packages/base/src/Numeric/LinearAlgebra/Util/Convolution.hs index d04c46b..1775f14 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Util/Convolution.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Util/Convolution.hs @@ -3,9 +3,8 @@ {- | Module : Numeric.LinearAlgebra.Util.Convolution Copyright : (c) Alberto Ruiz 2012 -License : GPL - -Maintainer : Alberto Ruiz (aruiz at um dot es) +License : BSD3 +Maintainer : Alberto Ruiz Stability : provisional -} @@ -17,7 +16,7 @@ module Numeric.LinearAlgebra.Util.Convolution( corr2, conv2, separable ) where -import Numeric.LinearAlgebra +import Numeric.Container vectSS :: Element t => Int -> Vector t -> Matrix t diff --git a/packages/base/src/Numeric/Matrix.hs b/packages/base/src/Numeric/Matrix.hs index 3478aae..962ee84 100644 --- a/packages/base/src/Numeric/Matrix.hs +++ b/packages/base/src/Numeric/Matrix.hs @@ -7,12 +7,11 @@ ----------------------------------------------------------------------------- -- | -- Module : Numeric.Matrix --- Copyright : (c) Alberto Ruiz 2010 --- License : GPL-style +-- Copyright : (c) Alberto Ruiz 2014 +-- License : BSD3 -- --- Maintainer : Alberto Ruiz +-- Maintainer : Alberto Ruiz -- Stability : provisional --- Portability : portable -- -- Provides instances of standard classes 'Show', 'Read', 'Eq', -- 'Num', 'Fractional', and 'Floating' for 'Matrix'. diff --git a/packages/base/src/Numeric/Vector.hs b/packages/base/src/Numeric/Vector.hs index 2769cd9..3a425f5 100644 --- a/packages/base/src/Numeric/Vector.hs +++ b/packages/base/src/Numeric/Vector.hs @@ -7,11 +7,10 @@ -- | -- Module : Numeric.Vector -- Copyright : (c) Alberto Ruiz 2011 --- License : GPL-style +-- License : BSD3 -- --- Maintainer : Alberto Ruiz +-- Maintainer : Alberto Ruiz -- Stability : provisional --- Portability : portable -- -- Provides instances of standard classes 'Show', 'Read', 'Eq', -- 'Num', 'Fractional', and 'Floating' for 'Vector'. diff --git a/packages/hmatrix/src/Numeric/Container.hs b/packages/hmatrix/src/Numeric/Container.hs new file mode 100644 index 0000000..146780d --- /dev/null +++ b/packages/hmatrix/src/Numeric/Container.hs @@ -0,0 +1,241 @@ +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE FunctionalDependencies #-} +{-# LANGUAGE UndecidableInstances #-} + +----------------------------------------------------------------------------- +-- | +-- Module : Numeric.Container +-- Copyright : (c) Alberto Ruiz 2010-14 +-- License : BSD3 +-- Maintainer : Alberto Ruiz +-- Stability : provisional +-- Portability : portable +-- +-- Basic numeric operations on 'Vector' and 'Matrix', including conversion routines. +-- +-- The 'Container' class is used to define optimized generic functions which work +-- on 'Vector' and 'Matrix' with real or complex elements. +-- +-- Some of these functions are also available in the instances of the standard +-- numeric Haskell classes provided by "Numeric.LinearAlgebra". +-- +----------------------------------------------------------------------------- +{-# OPTIONS_HADDOCK hide #-} + +module Numeric.Container ( + -- * Basic functions + module Data.Packed, + konst, build, + linspace, + diag, ident, + ctrans, + -- * Generic operations + Container(..), + -- * Matrix product + Product(..), udot, dot, (◇), + Mul(..), + Contraction(..), + optimiseMult, + mXm,mXv,vXm,LSDiv(..), + outer, kronecker, + -- * Element conversion + Convert(..), + Complexable(), + RealElement(), + + RealOf, ComplexOf, SingleOf, DoubleOf, + + IndexOf, + module Data.Complex +) where + +import Data.Packed hiding (stepD, stepF, condD, condF, conjugateC, conjugateQ) +import Data.Packed.Numeric +import Data.Complex +import Numeric.LinearAlgebra.Algorithms(Field,linearSolveSVD) +import Data.Monoid(Monoid(mconcat)) + +------------------------------------------------------------------ + +{- | Creates a real vector containing a range of values: + +>>> linspace 5 (-3,7::Double) +fromList [-3.0,-0.5,2.0,4.5,7.0]@ + +>>> linspace 5 (8,2+i) :: Vector (Complex Double) +fromList [8.0 :+ 0.0,6.5 :+ 0.25,5.0 :+ 0.5,3.5 :+ 0.75,2.0 :+ 1.0] + +Logarithmic spacing can be defined as follows: + +@logspace n (a,b) = 10 ** linspace n (a,b)@ +-} +linspace :: (Container Vector e) => Int -> (e, e) -> Vector e +linspace 0 (a,b) = fromList[(a+b)/2] +linspace n (a,b) = addConstant a $ scale s $ fromList $ map fromIntegral [0 .. n-1] + where s = (b-a)/fromIntegral (n-1) + +-------------------------------------------------------- + +class Contraction a b c | a b -> c + where + infixl 7 <.> + {- | Matrix product, matrix vector product, and dot product + +Examples: + +>>> let a = (3><4) [1..] :: Matrix Double +>>> let v = fromList [1,0,2,-1] :: Vector Double +>>> let u = fromList [1,2,3] :: Vector Double + +>>> a +(3><4) + [ 1.0, 2.0, 3.0, 4.0 + , 5.0, 6.0, 7.0, 8.0 + , 9.0, 10.0, 11.0, 12.0 ] + +matrix × matrix: + +>>> disp 2 (a <.> trans a) +3x3 + 30 70 110 + 70 174 278 +110 278 446 + +matrix × vector: + +>>> a <.> v +fromList [3.0,11.0,19.0] + +dot product: + +>>> u <.> fromList[3,2,1::Double] +10 + +For complex vectors the first argument is conjugated: + +>>> fromList [1,i] <.> fromList[2*i+1,3] +1.0 :+ (-1.0) + +>>> fromList [1,i,1-i] <.> complex a +fromList [10.0 :+ 4.0,12.0 :+ 4.0,14.0 :+ 4.0,16.0 :+ 4.0] + +-} + (<.>) :: a -> b -> c + + +instance (Product t, Container Vector t) => Contraction (Vector t) (Vector t) t where + u <.> v = conj u `udot` v + +instance Product t => Contraction (Matrix t) (Vector t) (Vector t) where + (<.>) = mXv + +instance (Container Vector t, Product t) => Contraction (Vector t) (Matrix t) (Vector t) where + (<.>) v m = (conj v) `vXm` m + +instance Product t => Contraction (Matrix t) (Matrix t) (Matrix t) where + (<.>) = mXm + + +-------------------------------------------------------------------------------- + +class Mul a b c | a b -> c where + infixl 7 <> + -- | Matrix-matrix, matrix-vector, and vector-matrix products. + (<>) :: Product t => a t -> b t -> c t + +instance Mul Matrix Matrix Matrix where + (<>) = mXm + +instance Mul Matrix Vector Vector where + (<>) m v = flatten $ m <> asColumn v + +instance Mul Vector Matrix Vector where + (<>) v m = flatten $ asRow v <> m + +-------------------------------------------------------------------------------- + +class LSDiv c where + infixl 7 <\> + -- | least squares solution of a linear system, similar to the \\ operator of Matlab\/Octave (based on linearSolveSVD) + (<\>) :: Field t => Matrix t -> c t -> c t + +instance LSDiv Vector where + m <\> v = flatten (linearSolveSVD m (reshape 1 v)) + +instance LSDiv Matrix where + (<\>) = linearSolveSVD + +-------------------------------------------------------------------------------- + +class Konst e d c | d -> c, c -> d + where + -- | + -- >>> konst 7 3 :: Vector Float + -- fromList [7.0,7.0,7.0] + -- + -- >>> konst i (3::Int,4::Int) + -- (3><4) + -- [ 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0 + -- , 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0 + -- , 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0 ] + -- + konst :: e -> d -> c e + +instance Container Vector e => Konst e Int Vector + where + konst = konst' + +instance Container Vector e => Konst e (Int,Int) Matrix + where + konst = konst' + +-------------------------------------------------------------------------------- + +class Build d f c e | d -> c, c -> d, f -> e, f -> d, f -> c, c e -> f, d e -> f + where + -- | + -- >>> build 5 (**2) :: Vector Double + -- fromList [0.0,1.0,4.0,9.0,16.0] + -- + -- Hilbert matrix of order N: + -- + -- >>> let hilb n = build (n,n) (\i j -> 1/(i+j+1)) :: Matrix Double + -- >>> putStr . dispf 2 $ hilb 3 + -- 3x3 + -- 1.00 0.50 0.33 + -- 0.50 0.33 0.25 + -- 0.33 0.25 0.20 + -- + build :: d -> f -> c e + +instance Container Vector e => Build Int (e -> e) Vector e + where + build = build' + +instance Container Matrix e => Build (Int,Int) (e -> e -> e) Matrix e + where + build = build' + +-------------------------------------------------------------------------------- + +{- | alternative operator for '(\<.\>)' + +x25c7, white diamond + +-} +(◇) :: Contraction a b c => a -> b -> c +infixl 7 ◇ +(◇) = (<.>) + +-- | dot product: @cdot u v = 'udot' ('conj' u) v@ +dot :: (Container Vector t, Product t) => Vector t -> Vector t -> t +dot u v = udot (conj u) v + +-------------------------------------------------------------------------------- + +optimiseMult :: Monoid (Matrix t) => [Matrix t] -> Matrix t +optimiseMult = mconcat + diff --git a/packages/hmatrix/src/Numeric/HMatrix.hs b/packages/hmatrix/src/Numeric/HMatrix.hs deleted file mode 100644 index fcd3e02..0000000 --- a/packages/hmatrix/src/Numeric/HMatrix.hs +++ /dev/null @@ -1,139 +0,0 @@ ------------------------------------------------------------------------------ -{- | -Module : Numeric.HMatrix -Copyright : (c) Alberto Ruiz 2006-14 -License : GPL - -Maintainer : Alberto Ruiz -Stability : provisional - -This module reexports the most common Linear Algebra functions. - --} ------------------------------------------------------------------------------ -module Numeric.HMatrix ( - - -- * Basic types and data processing - module Numeric.HMatrix.Data, - - -- | The standard numeric classes are defined elementwise: - -- - -- >>> fromList [1,2,3] * fromList [3,0,-2 :: Double] - -- fromList [3.0,0.0,-6.0] - -- - -- >>> (3><3) [1..9] * ident 3 :: Matrix Double - -- (3><3) - -- [ 1.0, 0.0, 0.0 - -- , 0.0, 5.0, 0.0 - -- , 0.0, 0.0, 9.0 ] - -- - -- In arithmetic operations single-element vectors and matrices - -- (created from numeric literals or using 'scalar') automatically - -- expand to match the dimensions of the other operand: - -- - -- >>> 5 + 2*ident 3 :: Matrix Double - -- (3><3) - -- [ 7.0, 5.0, 5.0 - -- , 5.0, 7.0, 5.0 - -- , 5.0, 5.0, 7.0 ] - -- - - -- * Products - (<.>), - - -- | The matrix product is also implemented in the "Data.Monoid" instance for Matrix, where - -- single-element matrices (created from numeric literals or using 'scalar') - -- are used for scaling. - -- - -- >>> let m = (2><3)[1..] :: Matrix Double - -- >>> m <> 2 <> diagl[0.5,1,0] - -- (2><3) - -- [ 1.0, 4.0, 0.0 - -- , 4.0, 10.0, 0.0 ] - -- - -- mconcat uses 'optimiseMult' to get the optimal association order. - - (◇), - outer, kronecker, cross, - scale, - sumElements, prodElements, absSum, - - -- * Linear Systems - (<\>), - linearSolve, - linearSolveLS, - linearSolveSVD, - luSolve, - cholSolve, - - -- * Inverse and pseudoinverse - inv, pinv, pinvTol, - - -- * Determinant and rank - rcond, rank, ranksv, - det, invlndet, - - -- * Singular value decomposition - svd, - fullSVD, - thinSVD, - compactSVD, - singularValues, - leftSV, rightSV, - - -- * Eigensystems - eig, eigSH, eigSH', - eigenvalues, eigenvaluesSH, eigenvaluesSH', - geigSH', - - -- * QR - qr, rq, qrRaw, qrgr, - - -- * Cholesky - chol, cholSH, mbCholSH, - - -- * Hessenberg - hess, - - -- * Schur - schur, - - -- * LU - lu, luPacked, - - -- * Matrix functions - expm, - sqrtm, - matFunc, - - -- * Nullspace - nullspacePrec, - nullVector, - nullspaceSVD, - null1, null1sym, - - orth, - - -- * Norms - norm1, norm2, normInf, pnorm, NormType(..), - - -- * Correlation and Convolution - corr, conv, corrMin, corr2, conv2, - - -- * Random arrays - rand, randn, RandDist(..), randomVector, gaussianSample, uniformSample, - - -- * Misc - meanCov, peps, relativeError, haussholder, optimiseMult, udot -) where - -import Numeric.HMatrix.Data - ---import Numeric.Matrix() ---import Numeric.Vector() -import Numeric.Container -import Numeric.LinearAlgebra.Algorithms -import Numeric.LinearAlgebra.Util -import Numeric.Random - - diff --git a/packages/hmatrix/src/Numeric/HMatrix/Data.hs b/packages/hmatrix/src/Numeric/HMatrix/Data.hs deleted file mode 100644 index 5d7ce4f..0000000 --- a/packages/hmatrix/src/Numeric/HMatrix/Data.hs +++ /dev/null @@ -1,70 +0,0 @@ --------------------------------------------------------------------------------- -{- | -Module : Numeric.HMatrix.Data -Copyright : (c) Alberto Ruiz 2014 -License : GPL - -Maintainer : Alberto Ruiz -Stability : provisional - -Basic data processing. - --} --------------------------------------------------------------------------------- - -module Numeric.HMatrix.Data( - - -- * Vector - -- | 1D arrays are storable vectors from the vector package. - - Vector, (|>), dim, (@>), - - -- * Matrix - Matrix, (><), size, (@@>), trans, ctrans, - - -- * Construction - scalar, konst, build, assoc, accum, linspace, -- ones, zeros, - - -- * Diagonal - ident, diag, diagl, diagRect, takeDiag, - - -- * Data manipulation - fromList, toList, subVector, takesV, vjoin, - flatten, reshape, asRow, asColumn, row, col, - fromRows, toRows, fromColumns, toColumns, fromLists, toLists, fromArray2D, - takeRows, dropRows, takeColumns, dropColumns, subMatrix, (?), (¿), fliprl, flipud, - - -- * Block matrix - fromBlocks, (¦), (——), diagBlock, repmat, toBlocks, toBlocksEvery, - - -- * Mapping functions - conj, cmap, step, cond, - - -- * Find elements - find, maxIndex, minIndex, maxElement, minElement, atIndex, - - -- * IO - disp, dispf, disps, dispcf, latexFormat, format, - loadMatrix, saveMatrix, fromFile, fileDimensions, - readMatrix, - fscanfVector, fprintfVector, freadVector, fwriteVector, - --- * Conversion - Convert(..), - - -- * Misc - arctan2, - rows, cols, - separable, - - module Data.Complex - -) where - -import Data.Packed.Vector -import Data.Packed.Matrix -import Numeric.Container -import Numeric.IO -import Numeric.LinearAlgebra.Util -import Data.Complex - diff --git a/packages/hmatrix/src/Numeric/HMatrix/Devel.hs b/packages/hmatrix/src/Numeric/HMatrix/Devel.hs deleted file mode 100644 index b921f44..0000000 --- a/packages/hmatrix/src/Numeric/HMatrix/Devel.hs +++ /dev/null @@ -1,69 +0,0 @@ --------------------------------------------------------------------------------- -{- | -Module : Numeric.HMatrix.Devel -Copyright : (c) Alberto Ruiz 2014 -License : GPL - -Maintainer : Alberto Ruiz -Stability : provisional - -The library can be easily extended using the tools in this module. - --} --------------------------------------------------------------------------------- - -module Numeric.HMatrix.Devel( - -- * FFI helpers - -- | Sample usage, to upload a perspective matrix to a shader. - -- - -- @ glUniformMatrix4fv 0 1 (fromIntegral gl_TRUE) \`appMatrix\` perspective 0.01 100 (pi\/2) (4\/3) - -- @ - module Data.Packed.Foreign, - - -- * FFI tools - -- | Illustrative usage examples can be found - -- in the @examples\/devel@ folder included in the package. - module Data.Packed.Development, - - -- * ST - -- | In-place manipulation inside the ST monad. - -- See examples\/inplace.hs in the distribution. - - -- ** Mutable Vectors - STVector, newVector, thawVector, freezeVector, runSTVector, - readVector, writeVector, modifyVector, liftSTVector, - -- ** Mutable Matrices - STMatrix, newMatrix, thawMatrix, freezeMatrix, runSTMatrix, - readMatrix, writeMatrix, modifyMatrix, liftSTMatrix, - -- ** Unsafe functions - newUndefinedVector, - unsafeReadVector, unsafeWriteVector, - unsafeThawVector, unsafeFreezeVector, - newUndefinedMatrix, - unsafeReadMatrix, unsafeWriteMatrix, - unsafeThawMatrix, unsafeFreezeMatrix, - - -- * Special maps and zips - mapVectorWithIndex, zipVector, zipVectorWith, unzipVector, unzipVectorWith, - mapVectorM, mapVectorM_, mapVectorWithIndexM, mapVectorWithIndexM_, - foldLoop, foldVector, foldVectorG, foldVectorWithIndex, - mapMatrixWithIndex, mapMatrixWithIndexM, mapMatrixWithIndexM_, - liftMatrix, liftMatrix2, liftMatrix2Auto, - - -- * Auxiliary classes - Element, Container, Product, Contraction, LSDiv, - Complexable(), RealElement(), - RealOf, ComplexOf, SingleOf, DoubleOf, - IndexOf, - Field, Normed -) where - -import Data.Packed.Foreign -import Data.Packed.Development -import Data.Packed.ST -import Numeric.Container(Container,Contraction,LSDiv,Product, - Complexable(),RealElement(), - RealOf, ComplexOf, SingleOf, DoubleOf, IndexOf) -import Data.Packed -import Numeric.LinearAlgebra.Algorithms(Field,Normed) - -- cgit v1.2.3