From e168d61eb429aa1de2d68075a4b89a8522e44038 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Thu, 1 May 2014 22:47:02 +0200 Subject: top reexport module --- lib/Numeric/Container.hs | 15 ++-- lib/Numeric/HMatrix.hs | 117 ++++++++++++++++++++++++++++++++ lib/Numeric/HMatrix/Data.hs | 75 ++++++++++++++++++++ lib/Numeric/HMatrix/Devel.hs | 64 +++++++++++++++++ lib/Numeric/LinearAlgebra/Algorithms.hs | 9 ++- lib/Numeric/LinearAlgebra/Data.hs | 97 -------------------------- lib/Numeric/LinearAlgebra/Data/Devel.hs | 63 ----------------- 7 files changed, 273 insertions(+), 167 deletions(-) create mode 100644 lib/Numeric/HMatrix.hs create mode 100644 lib/Numeric/HMatrix/Data.hs create mode 100644 lib/Numeric/HMatrix/Devel.hs delete mode 100644 lib/Numeric/LinearAlgebra/Data.hs delete mode 100644 lib/Numeric/LinearAlgebra/Data/Devel.hs (limited to 'lib') diff --git a/lib/Numeric/Container.hs b/lib/Numeric/Container.hs index 5339c7e..d1ce588 100644 --- a/lib/Numeric/Container.hs +++ b/lib/Numeric/Container.hs @@ -105,28 +105,35 @@ cdot u v = udot (conj u) v class Contraction a b c | a b -> c, a c -> b, b c -> a where infixl 7 <> - {- | matrix-matrix product, matrix-vector product, unconjugated dot product + {- | Matrix-matrix product, matrix-vector product, and unconjugated dot product >>> let a = (3><4) [1..] :: Matrix 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 <> fromList [1,0,2,-1::Double] fromList [3.0,11.0,19.0] +vector × matrix: + >>> fromList [1,2,3::Double] <> a fromList [38.0,44.0,50.0,56.0] +unconjugated dot product: + >>> fromList [1,i] <> fromList[2*i+1,3] 1.0 :+ 5.0 @@ -160,9 +167,9 @@ instance LSDiv Matrix Matrix where -------------------------------------------------------- -{- | dot product : @u · v = 'cdot' u v@ +{- | Dot product : @u · v = 'cdot' u v@ - unicode 0x00b7, Alt-Gr . + (unicode 0x00b7, Alt-Gr .) >>> fromList [1,i] · fromList[2*i+1,3] 1.0 :+ (-1.0) diff --git a/lib/Numeric/HMatrix.hs b/lib/Numeric/HMatrix.hs new file mode 100644 index 0000000..8e0b4a2 --- /dev/null +++ b/lib/Numeric/HMatrix.hs @@ -0,0 +1,117 @@ +----------------------------------------------------------------------------- +{- | +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] + -- + -- In arithmetic operations single-element vectors and matrices automatically + -- expand to match the dimensions of the other operand. + -- + -- >>> 2 * ident 3 + -- 2 * ident 3 :: Matrix Double + -- (3><3) + -- [ 2.0, 0.0, 0.0 + -- , 0.0, 2.0, 0.0 + -- , 0.0, 0.0, 2.0 ] + -- + + -- * Products + (<>), (·), outer, kronecker, cross, + optimiseMult, 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, + + -- * 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, + + -- * Correlation and Convolution + corr, conv, corrMin, corr2, conv2, + + -- * Random arrays + rand, randn, RandDist(..), randomVector, gaussianSample, uniformSample, + + -- * Misc + meanCov, peps, relativeError, haussholder +) where + +import Numeric.HMatrix.Data + +import Numeric.Matrix() +import Numeric.Vector() +import Numeric.Container +import Numeric.LinearAlgebra.Algorithms +import Numeric.LinearAlgebra.Util + + diff --git a/lib/Numeric/HMatrix/Data.hs b/lib/Numeric/HMatrix/Data.hs new file mode 100644 index 0000000..49dad10 --- /dev/null +++ b/lib/Numeric/HMatrix/Data.hs @@ -0,0 +1,75 @@ +-------------------------------------------------------------------------------- +{- | +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, vecdisp, latexFormat, format, + loadMatrix, saveMatrix, fromFile, fileDimensions, + readMatrix, + fscanfVector, fprintfVector, freadVector, fwriteVector, + +-- * Conversion + Convert(..), + Complexable(), + RealElement(), + + RealOf, ComplexOf, SingleOf, DoubleOf, + + IndexOf, + + -- * Misc + arctan2, + rows, cols, + separable, + + module Data.Complex + +) where + +import Data.Packed.Vector +import Data.Packed.Matrix +import Numeric.Container +import Numeric.LinearAlgebra.Util +import Data.Complex + diff --git a/lib/Numeric/HMatrix/Devel.hs b/lib/Numeric/HMatrix/Devel.hs new file mode 100644 index 0000000..37bf826 --- /dev/null +++ b/lib/Numeric/HMatrix/Devel.hs @@ -0,0 +1,64 @@ +-------------------------------------------------------------------------------- +{- | +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, + + -- * Misc + Element, Container, Product, Contraction, LSDiv, Field +) where + +import Data.Packed.Foreign +import Data.Packed.Development +import Data.Packed.ST +import Numeric.Container(Container,Contraction,LSDiv,Product) +import Data.Packed +import Numeric.LinearAlgebra.Algorithms(Field) + + diff --git a/lib/Numeric/LinearAlgebra/Algorithms.hs b/lib/Numeric/LinearAlgebra/Algorithms.hs index 7c1c032..de9cb00 100644 --- a/lib/Numeric/LinearAlgebra/Algorithms.hs +++ b/lib/Numeric/LinearAlgebra/Algorithms.hs @@ -21,6 +21,8 @@ imported from "Numeric.LinearAlgebra.LAPACK". -} ----------------------------------------------------------------------------- +{-# OPTIONS_HADDOCK hide #-} + module Numeric.LinearAlgebra.Algorithms ( -- * Supported types @@ -85,8 +87,9 @@ import Data.Array import Numeric.ContainerBoot -{- | Class used to define generic linear algebra computations for both real and complex matrices. Only double precision is supported in this version (we can -transform single precision objects using 'single' and 'double'). +{- | Generic linear algebra functions for double precision real and complex matrices. + +(Single precision data can be converted using 'single' and 'double'). -} class (Product t, @@ -438,7 +441,7 @@ i = 0:+1 ----------------------------------------------------------------------- --- | The nullspace of a matrix from its SVD decomposition. +-- | The nullspace of a matrix from its precomputed SVD decomposition. nullspaceSVD :: Field t => Either Double Int -- ^ Left \"numeric\" zero (eg. 1*'eps'), -- or Right \"theoretical\" matrix rank. diff --git a/lib/Numeric/LinearAlgebra/Data.hs b/lib/Numeric/LinearAlgebra/Data.hs deleted file mode 100644 index a3639d5..0000000 --- a/lib/Numeric/LinearAlgebra/Data.hs +++ /dev/null @@ -1,97 +0,0 @@ --------------------------------------------------------------------------------- -{- | -Module : Numeric.LinearAlgebra.Data -Copyright : (c) Alberto Ruiz 2014 -License : GPL - -Maintainer : Alberto Ruiz -Stability : provisional - --} --------------------------------------------------------------------------------- - -module Numeric.LinearAlgebra.Data( - -- * Vector - -- | 1D arrays are storable vectors from the vector package. - - Vector, (|>), dim, (@>), - - -- * Matrix - Matrix, (><), size, (@@>), trans, ctrans, - - -- * Construction functions - - scalar, konst, build, assoc, accum, linspace, -- ones, zeros, - - -- * Data manipulation - - fromList, toList, subVector, takesV, vjoin, - - flatten, reshape, asRow, asColumn, row, col, - - fromRows, toRows, fromColumns, toColumns, fromLists, toLists, - - takeRows, dropRows, takeColumns, dropColumns, subMatrix, (?), (¿), fliprl, flipud, - - -- * Diagonal matrices - - ident, diag, diagl, diagRect, takeDiag, - - -- * Block matrices - - fromBlocks, (¦), (——), diagBlock, repmat, toBlocks, toBlocksEvery, - - -- * Mapping functions - - conj, cmap, step, cond, - - -- * Find elements - - find, maxIndex, minIndex, maxElement, minElement, atIndex, - - -- * Products - - (<>), (·), outer, kronecker, cross, - sumElements, prodElements, absSum, - optimiseMult, - - corr, conv, corrMin, corr2, conv2, - - (<\>), - - -- * Random arrays - - rand, randn, RandDist(..), randomVector, gaussianSample, uniformSample, - - -- * IO - - disp, dispf, disps, dispcf, vecdisp, latexFormat, format, - loadMatrix, saveMatrix, fromFile, fileDimensions, - readMatrix, - fscanfVector, fprintfVector, freadVector, fwriteVector, - --- * Element conversion - Convert(..), - Complexable(), - RealElement(), - - RealOf, ComplexOf, SingleOf, DoubleOf, - - IndexOf, - - module Data.Complex, - - -- * Misc - scale, meanCov, arctan2, - rows, cols, - separable, - fromArray2D - -) where - -import Data.Packed.Vector -import Data.Packed.Matrix -import Numeric.Container -import Numeric.LinearAlgebra.Util -import Data.Complex - diff --git a/lib/Numeric/LinearAlgebra/Data/Devel.hs b/lib/Numeric/LinearAlgebra/Data/Devel.hs deleted file mode 100644 index 88c980c..0000000 --- a/lib/Numeric/LinearAlgebra/Data/Devel.hs +++ /dev/null @@ -1,63 +0,0 @@ --------------------------------------------------------------------------------- -{- | -Module : Numeric.LinearAlgebra.Data.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.LinearAlgebra.Data.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, - - -- * Misc - Element, Container, Product, Contraction, LSDiv -) where - -import Data.Packed.Foreign -import Data.Packed.Development -import Data.Packed.ST -import Numeric.Container(Container,Contraction,LSDiv,Product) -import Data.Packed - - -- cgit v1.2.3