-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Linear algebra and numerical computation
--   
--   Purely functional interface to basic linear algebra and other
--   numerical computations, internally implemented using GSL, BLAS and
--   LAPACK.
--   
--   The Linear Algebra API is organized as follows:
--   
--   <ul>
--   <li><a>Data.Packed</a>: structure manipulation</li>
--   <li><a>Numeric.Container</a>: simple numeric functions</li>
--   <li><a>Numeric.LinearAlgebra.Algorithms</a>: matrix computations</li>
--   <li><a>Numeric.LinearAlgebra</a>: everything + instances of standard
--   Haskell numeric classes</li>
--   </ul>
@package hmatrix
@version 0.15.0.0


-- | In-place manipulation inside the ST monad. See examples/inplace.hs in
--   the distribution.
module Data.Packed.ST
data STVector s t
newVector :: Storable t => t -> Int -> ST s (STVector s t)
thawVector :: Storable t => Vector t -> ST s (STVector s t)
freezeVector :: Storable t => STVector s1 t -> ST s2 (Vector t)
runSTVector :: Storable t => (forall s. ST s (STVector s t)) -> Vector t
readVector :: Storable t => STVector s t -> Int -> ST s t
writeVector :: Storable t => STVector s t -> Int -> t -> ST s ()
modifyVector :: Storable t => STVector s t -> Int -> (t -> t) -> ST s ()
liftSTVector :: Storable t => (Vector t -> a) -> STVector s1 t -> ST s2 a
data STMatrix s t
newMatrix :: Storable t => t -> Int -> Int -> ST s (STMatrix s t)
thawMatrix :: Storable t => Matrix t -> ST s (STMatrix s t)
freezeMatrix :: Storable t => STMatrix s1 t -> ST s2 (Matrix t)
runSTMatrix :: Storable t => (forall s. ST s (STMatrix s t)) -> Matrix t
readMatrix :: Storable t => STMatrix s t -> Int -> Int -> ST s t
writeMatrix :: Storable t => STMatrix s t -> Int -> Int -> t -> ST s ()
modifyMatrix :: Storable t => STMatrix s t -> Int -> Int -> (t -> t) -> ST s ()
liftSTMatrix :: Storable t => (Matrix t -> a) -> STMatrix s1 t -> ST s2 a
newUndefinedVector :: Storable t => Int -> ST s (STVector s t)
unsafeReadVector :: Storable t => STVector s t -> Int -> ST s t
unsafeWriteVector :: Storable t => STVector s t -> Int -> t -> ST s ()
unsafeThawVector :: Storable t => Vector t -> ST s (STVector s t)
unsafeFreezeVector :: Storable t => STVector s1 t -> ST s2 (Vector t)
newUndefinedMatrix :: Storable t => MatrixOrder -> Int -> Int -> ST s (STMatrix s t)
unsafeReadMatrix :: Storable t => STMatrix s t -> Int -> Int -> ST s t
unsafeWriteMatrix :: Storable t => STMatrix s t -> Int -> Int -> t -> ST s ()
unsafeThawMatrix :: Storable t => Matrix t -> ST s (STMatrix s t)
unsafeFreezeMatrix :: Storable t => STMatrix s1 t -> ST s2 (Matrix t)


-- | FFI and hmatrix helpers.
--   
--   Sample usage, to upload a perspective matrix to a shader.
--   
--   <pre>
--   glUniformMatrix4fv 0 1 (fromIntegral gl_TRUE) `appMatrix` perspective 0.01 100 (pi/2) (4/3) 
--   </pre>
module Data.Packed.Foreign

-- | Only useful since it is left associated with a precedence of 1, unlike
--   <a>$</a>, which is right associative. e.g.
--   
--   <pre>
--   someFunction
--       `appMatrixLen` m
--       `appVectorLen` v
--       `app` other
--       `app` arguments
--       `app` go here
--   </pre>
--   
--   One could also write:
--   
--   <pre>
--   (someFunction 
--       `appMatrixLen` m
--       `appVectorLen` v) 
--       other 
--       arguments 
--       (go here)
--   </pre>
app :: (a -> b) -> a -> b
appVector :: Storable a => (Ptr a -> b) -> Vector a -> b
appVectorLen :: Storable a => (CInt -> Ptr a -> b) -> Vector a -> b
appMatrix :: Element a => (Ptr a -> b) -> Matrix a -> b
appMatrixLen :: Element a => (CInt -> CInt -> Ptr a -> b) -> Matrix a -> b
appMatrixRaw :: Storable a => (Ptr a -> b) -> Matrix a -> b
appMatrixRawLen :: Element a => (CInt -> CInt -> Ptr a -> b) -> Matrix a -> b

-- | This will disregard the order of the matrix, and simply return it
--   as-is. If the order of the matrix is RowMajor, this function is
--   identical to <a>flatten</a>.
unsafeMatrixToVector :: Matrix a -> Vector a
unsafeMatrixToForeignPtr :: Storable a => Matrix a -> (ForeignPtr a, Int)


-- | Numerical differentiation.
--   
--   
--   <a>http://www.gnu.org/software/gsl/manual/html_node/Numerical-Differentiation.html#Numerical-Differentiation</a>
--   
--   From the GSL manual: "The functions described in this chapter compute
--   numerical derivatives by finite differencing. An adaptive algorithm is
--   used to find the best choice of finite difference and to estimate the
--   error in the derivative."
module Numeric.GSL.Differentiation

-- | Adaptive central difference algorithm, <i>gsl_deriv_central</i>. For
--   example:
--   
--   <pre>
--    &gt; let deriv = derivCentral 0.01 
--    &gt; deriv sin (pi/4)
--   (0.7071067812000676,1.0600063101654055e-10)
--    &gt; cos (pi/4)
--   0.7071067811865476 
--   </pre>
derivCentral :: Double -> (Double -> Double) -> Double -> (Double, Double)

-- | Adaptive forward difference algorithm, <i>gsl_deriv_forward</i>. The
--   function is evaluated only at points greater than x, and never at x
--   itself. The derivative is returned in result and an estimate of its
--   absolute error is returned in abserr. This function should be used if
--   f(x) has a discontinuity at x, or is undefined for values less than x.
--   A backward derivative can be obtained using a negative step.
derivForward :: Double -> (Double -> Double) -> Double -> (Double, Double)

-- | Adaptive backward difference algorithm, <i>gsl_deriv_backward</i>.
derivBackward :: Double -> (Double -> Double) -> Double -> (Double, Double)


-- | Numerical integration routines.
--   
--   
--   <a>http://www.gnu.org/software/gsl/manual/html_node/Numerical-Integration.html#Numerical-Integration</a>
module Numeric.GSL.Integration

-- | Numerical integration using <i>gsl_integration_qng</i> (useful for
--   fast integration of smooth functions). For example:
--   
--   <pre>
--   &gt; let quad = integrateQNG 1E-6 
--   &gt; quad (\x -&gt; 4/(1+x*x)) 0 1 
--   (3.141592653589793,3.487868498008632e-14)
--   </pre>
integrateQNG :: Double -> (Double -> Double) -> Double -> Double -> (Double, Double)

-- | Numerical integration using <i>gsl_integration_qags</i> (adaptive
--   integration with singularities). For example:
--   
--   <pre>
--   &gt; let quad = integrateQAGS 1E-9 1000 
--   &gt; let f a x = x**(-0.5) * log (a*x)
--   &gt; quad (f 1) 0 1
--   (-3.999999999999974,4.871658632055187e-13)
--   </pre>
integrateQAGS :: Double -> Int -> (Double -> Double) -> Double -> Double -> (Double, Double)

-- | Numerical integration using <i>gsl_integration_qagi</i> (integration
--   over the infinite integral -Inf..Inf using QAGS). For example:
--   
--   <pre>
--   &gt; let quad = integrateQAGI 1E-9 1000 
--   &gt; let f a x = exp(-a * x^2)
--   &gt; quad (f 0.5) 
--   (2.5066282746310002,6.229215880648858e-11)
--   </pre>
integrateQAGI :: Double -> Int -> (Double -> Double) -> (Double, Double)

-- | Numerical integration using <i>gsl_integration_qagiu</i> (integration
--   over the semi-infinite integral a..Inf). For example:
--   
--   <pre>
--   &gt; let quad = integrateQAGIU 1E-9 1000 
--   &gt; let f a x = exp(-a * x^2)
--   &gt; quad (f 0.5) 0
--   (1.2533141373155001,3.114607940324429e-11)
--   </pre>
integrateQAGIU :: Double -> Int -> (Double -> Double) -> Double -> (Double, Double)

-- | Numerical integration using <i>gsl_integration_qagil</i> (integration
--   over the semi-infinite integral -Inf..b). For example:
--   
--   <pre>
--   &gt; let quad = integrateQAGIL 1E-9 1000 
--   &gt; let f a x = exp(-a * x^2)
--   &gt; quad (f 0.5) 0 
--   (1.2533141373155001,3.114607940324429e-11)
--   </pre>
integrateQAGIL :: Double -> Int -> (Double -> Double) -> Double -> (Double, Double)


-- | Fourier Transform.
--   
--   
--   <a>http://www.gnu.org/software/gsl/manual/html_node/Fast-Fourier-Transforms.html#Fast-Fourier-Transforms</a>
module Numeric.GSL.Fourier

-- | Fast 1D Fourier transform of a <a>Vector</a> <tt>(</tt><a>Complex</a>
--   <a>Double</a><tt>)</tt> using <i>gsl_fft_complex_forward</i>. It uses
--   the same scaling conventions as GNU Octave.
--   
--   <pre>
--   &gt; fft (<a>fromList</a> [1,2,3,4])
--   vector (4) [10.0 :+ 0.0,(-2.0) :+ 2.0,(-2.0) :+ 0.0,(-2.0) :+ (-2.0)]
--   </pre>
fft :: Vector (Complex Double) -> Vector (Complex Double)

-- | The inverse of <a>fft</a>, using <i>gsl_fft_complex_inverse</i>.
ifft :: Vector (Complex Double) -> Vector (Complex Double)


-- | Polynomials.
--   
--   
--   <a>http://www.gnu.org/software/gsl/manual/html_node/General-Polynomial-Equations.html#General-Polynomial-Equations</a>
module Numeric.GSL.Polynomials

-- | Solution of general polynomial equations, using
--   <i>gsl_poly_complex_solve</i>. For example, the three solutions of x^3
--   + 8 = 0
--   
--   <pre>
--   &gt; polySolve [8,0,0,1]
--   [(-1.9999999999999998) :+ 0.0,
--    1.0 :+ 1.732050807568877,
--    1.0 :+ (-1.732050807568877)]
--   </pre>
--   
--   The example in the GSL manual: To find the roots of x^5 -1 = 0:
--   
--   <pre>
--   &gt; polySolve [-1, 0, 0, 0, 0, 1]
--   [(-0.8090169943749475) :+ 0.5877852522924731,
--   (-0.8090169943749475) :+ (-0.5877852522924731),
--   0.30901699437494734 :+ 0.9510565162951536,
--   0.30901699437494734 :+ (-0.9510565162951536),
--   1.0 :+ 0.0]
--   </pre>
polySolve :: [Double] -> [Complex Double]


-- | Solution of ordinary differential equation (ODE) initial value
--   problems.
--   
--   
--   <a>http://www.gnu.org/software/gsl/manual/html_node/Ordinary-Differential-Equations.html</a>
--   
--   A simple example:
--   
--   <pre>
--   import Numeric.GSL
--   import Numeric.LinearAlgebra
--   import Graphics.Plot
--   
--   xdot t [x,v] = [v, -0.95*x - 0.1*v]
--   
--   ts = linspace 100 (0,20 :: Double)
--   
--   sol = odeSolve xdot [10,0] ts
--   
--   main = mplot (ts : toColumns sol)
--   </pre>
module Numeric.GSL.ODE

-- | A version of <a>odeSolveV</a> with reasonable default parameters and
--   system of equations defined using lists.
odeSolve :: (Double -> [Double] -> [Double]) -> [Double] -> Vector Double -> Matrix Double

-- | Evolution of the system with adaptive step-size control.
odeSolveV :: ODEMethod -> Double -> Double -> Double -> (Double -> Vector Double -> Vector Double) -> Vector Double -> Vector Double -> Matrix Double

-- | Stepping functions
data ODEMethod

-- | Embedded Runge-Kutta (2, 3) method.
RK2 :: ODEMethod

-- | 4th order (classical) Runge-Kutta. The error estimate is obtained by
--   halving the step-size. For more efficient estimate of the error, use
--   the embedded methods.
RK4 :: ODEMethod

-- | Embedded Runge-Kutta-Fehlberg (4, 5) method. This method is a good
--   general-purpose integrator.
RKf45 :: ODEMethod

-- | Embedded Runge-Kutta Cash-Karp (4, 5) method.
RKck :: ODEMethod

-- | Embedded Runge-Kutta Prince-Dormand (8,9) method.
RK8pd :: ODEMethod

-- | Implicit 2nd order Runge-Kutta at Gaussian points.
RK2imp :: Jacobian -> ODEMethod

-- | Implicit 4th order Runge-Kutta at Gaussian points.
RK4imp :: Jacobian -> ODEMethod

-- | Implicit Bulirsch-Stoer method of Bader and Deuflhard. The method is
--   generally suitable for stiff problems.
BSimp :: Jacobian -> ODEMethod

-- | Implicit Gaussian first order Runge-Kutta. Also known as implicit
--   Euler or backward Euler method. Error estimation is carried out by the
--   step doubling method.
RK1imp :: Jacobian -> ODEMethod

-- | A variable-coefficient linear multistep Adams method in Nordsieck
--   form. This stepper uses explicit Adams-Bashforth (predictor) and
--   implicit Adams-Moulton (corrector) methods in P(EC)^m functional
--   iteration mode. Method order varies dynamically between 1 and 12.
MSAdams :: ODEMethod

-- | A variable-coefficient linear multistep backward differentiation
--   formula (BDF) method in Nordsieck form. This stepper uses the explicit
--   BDF formula as predictor and implicit BDF formula as corrector. A
--   modified Newton iteration method is used to solve the system of
--   non-linear equations. Method order varies dynamically between 1 and 5.
--   The method is generally suitable for stiff problems.
MSBDF :: Jacobian -> ODEMethod
type Jacobian = Double -> Vector Double -> Matrix Double


-- | The library can be easily extended with additional foreign functions
--   using the tools in this module. Illustrative usage examples can be
--   found in the <tt>examples/devel</tt> folder included in the package.
module Data.Packed.Development
createVector :: Storable a => Int -> IO (Vector a)
createMatrix :: Storable a => MatrixOrder -> Int -> Int -> IO (Matrix a)
vec :: Storable t => Vector t -> (((CInt -> Ptr t -> t1) -> t1) -> IO b) -> IO b
mat :: Storable t => Matrix t -> (((CInt -> CInt -> Ptr t -> t1) -> t1) -> IO b) -> IO b
app1 :: f -> Adapt1 f t1
app2 :: f -> Adapt2 f t1 r1 t2
app3 :: f -> Adapt3 f t1 r1 t2 r2 t3
app4 :: f -> Adapt4 f t1 r1 t2 r2 t3 r3 t4
app5 :: f -> Adapt5 f t1 r1 t2 r2 t3 r3 t4 r4 t5
app6 :: f -> Adapt6 f t1 r1 t2 r2 t3 r3 t4 r4 t5 r5 t6
app7 :: f -> Adapt7 f t1 r1 t2 r2 t3 r3 t4 r4 t5 r5 t6 r6 t7
app8 :: f -> Adapt8 f t1 r1 t2 r2 t3 r3 t4 r4 t5 r5 t6 r6 t7 r7 t8
app9 :: f -> Adapt9 f t1 r1 t2 r2 t3 r3 t4 r4 t5 r5 t6 r6 t7 r7 t8 r8 t9
app10 :: f -> Adapt10 f t1 r1 t2 r2 t3 r3 t4 r4 t5 r5 t6 r6 t7 r7 t8 r8 t9 r9 t10
data MatrixOrder
RowMajor :: MatrixOrder
ColumnMajor :: MatrixOrder
orderOf :: Matrix t -> MatrixOrder
cmat :: Element t => Matrix t -> Matrix t
fmat :: Element t => Matrix t -> Matrix t

-- | <i>O(1)</i> Create a vector from a <a>ForeignPtr</a> with an offset
--   and a length.
--   
--   The data may not be modified through the <a>ForeignPtr</a> afterwards.
--   
--   If your offset is 0 it is more efficient to use
--   <a>unsafeFromForeignPtr0</a>.
unsafeFromForeignPtr :: Storable a => ForeignPtr a -> Int -> Int -> Vector a

-- | <i>O(1)</i> Yield the underlying <a>ForeignPtr</a> together with the
--   offset to the data and its length. The data may not be modified
--   through the <a>ForeignPtr</a>.
unsafeToForeignPtr :: Storable a => Vector a -> (ForeignPtr a, Int, Int)

-- | check the error code
check :: String -> IO CInt -> IO ()

-- | postfix function application (<tt>flip ($)</tt>)
(//) :: x -> (x -> y) -> y

-- | access to Vector elements without range checking
at' :: Storable a => Vector a -> Int -> a
atM' :: Storable a => Matrix a -> Int -> Int -> a


-- | A Matrix representation suitable for numerical computations using
--   LAPACK and GSL.
--   
--   This module provides basic functions for manipulation of structure.
module Data.Packed.Matrix

-- | Matrix representation suitable for GSL and LAPACK computations.
--   
--   The elements are stored in a continuous memory array.
data Matrix t

-- | Supported matrix elements.
--   
--   This class provides optimized internal operations for selected element
--   types. It provides unoptimised defaults for any <a>Storable</a> type,
--   so you can create instances simply as: <tt>instance Element Foo</tt>.
class Storable a => Element a where subMatrixD = subMatrix' transdata = transdataP constantD = constantP
rows :: Matrix t -> Int
cols :: Matrix t -> Int

-- | An easy way to create a matrix:
--   
--   <pre>
--   &gt; (2&gt;&lt;3)[1..6]
--   (2&gt;&lt;3)
--    [ 1.0, 2.0, 3.0
--    , 4.0, 5.0, 6.0 ]
--   </pre>
--   
--   This is the format produced by the instances of Show (Matrix a), which
--   can also be used for input.
--   
--   The input list is explicitly truncated, so that it can safely be used
--   with lists that are too long (like infinite lists).
--   
--   Example:
--   
--   <pre>
--   &gt; (2&gt;&lt;3)[1..]
--   (2&gt;&lt;3)
--    [ 1.0, 2.0, 3.0
--    , 4.0, 5.0, 6.0 ]
--   </pre>
(><) :: Storable a => Int -> Int -> [a] -> Matrix a

-- | Matrix transpose.
trans :: Matrix t -> Matrix t

-- | Creates a matrix from a vector by grouping the elements in rows with
--   the desired number of columns. (GNU-Octave groups by columns. To do it
--   you can define <tt>reshapeF r = trans . reshape r</tt> where r is the
--   desired number of rows.)
--   
--   <pre>
--   &gt; reshape 4 (<a>fromList</a> [1..12])
--   (3&gt;&lt;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 ]
--   </pre>
reshape :: Storable t => Int -> Vector t -> Matrix t

-- | Creates a vector by concatenation of rows. If the matrix is
--   ColumnMajor, this operation requires a transpose.
--   
--   <pre>
--   &gt; flatten (<tt>ident</tt> 3)
--    9 |&gt; [1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0]
--   </pre>
flatten :: Element t => Matrix t -> Vector t

-- | Creates a <a>Matrix</a> from a list of lists (considered as rows).
--   
--   <pre>
--   &gt; fromLists [[1,2],[3,4],[5,6]]
--   (3&gt;&lt;2)
--    [ 1.0, 2.0
--    , 3.0, 4.0
--    , 5.0, 6.0 ]
--   </pre>
fromLists :: Element t => [[t]] -> Matrix t

-- | the inverse of <a>fromLists</a>
toLists :: Element t => Matrix t -> [[t]]

-- | creates a Matrix of the specified size using the supplied function to
--   to map the row/column position to the value at that row/column
--   position.
--   
--   <pre>
--   &gt; buildMatrix 3 4 (\(r,c) -&gt; fromIntegral r * fromIntegral c)
--   (3&gt;&lt;4)
--    [ 0.0, 0.0, 0.0, 0.0, 0.0
--    , 0.0, 1.0, 2.0, 3.0, 4.0
--    , 0.0, 2.0, 4.0, 6.0, 8.0]
--   </pre>
--   
--   Hilbert matrix of order N:
--   
--   <pre>
--   hilb n = buildMatrix n n (\(i,j)-&gt;1/(fromIntegral i + fromIntegral j +1))
--   </pre>
buildMatrix :: Element a => Int -> Int -> ((Int, Int) -> a) -> Matrix a

-- | Reads a matrix position.
(@@>) :: Storable t => Matrix t -> (Int, Int) -> t

-- | creates a 1-row matrix from a vector
asRow :: Storable a => Vector a -> Matrix a

-- | creates a 1-column matrix from a vector
asColumn :: Storable a => Vector a -> Matrix a

-- | Create a matrix from a list of vectors. All vectors must have the same
--   dimension, or dimension 1, which is are automatically expanded.
fromRows :: Element t => [Vector t] -> Matrix t

-- | extracts the rows of a matrix as a list of vectors
toRows :: Element t => Matrix t -> [Vector t]

-- | Creates a matrix from a list of vectors, as columns
fromColumns :: Element t => [Vector t] -> Matrix t

-- | Creates a list of vectors from the columns of a matrix
toColumns :: Element t => Matrix t -> [Vector t]

-- | Creates a matrix from blocks given as a list of lists of matrices.
--   
--   Single row/column components are automatically expanded to match the
--   corresponding common row and column:
--   
--   <pre>
--   &gt; let disp = putStr . dispf 2
--   &gt; let vector xs = fromList xs :: Vector Double
--   &gt; let diagl = diag . vector
--   &gt; let rowm = asRow . vector
--   
--   &gt; disp $ fromBlocks [[ident 5, 7, rowm[10,20]], [3, diagl[1,2,3], 0]]
--   
--   8x10
--   1  0  0  0  0  7  7  7  10  20
--   0  1  0  0  0  7  7  7  10  20
--   0  0  1  0  0  7  7  7  10  20
--   0  0  0  1  0  7  7  7  10  20
--   0  0  0  0  1  7  7  7  10  20
--   3  3  3  3  3  1  0  0   0   0
--   3  3  3  3  3  0  2  0   0   0
--   3  3  3  3  3  0  0  3   0   0
--   </pre>
fromBlocks :: Element t => [[Matrix t]] -> Matrix t

-- | create a block diagonal matrix
diagBlock :: (Element t, Num t) => [Matrix t] -> Matrix t

-- | Partition a matrix into blocks with the given numbers of rows and
--   columns. The remaining rows and columns are discarded.
toBlocks :: Element t => [Int] -> [Int] -> Matrix t -> [[Matrix t]]

-- | Fully partition a matrix into blocks of the same size. If the
--   dimensions are not a multiple of the given size the last blocks will
--   be smaller.
toBlocksEvery :: Element t => Int -> Int -> Matrix t -> [[Matrix t]]

-- | creates matrix by repetition of a matrix a given number of rows and
--   columns
--   
--   <pre>
--   &gt; repmat (ident 2) 2 3 :: Matrix Double
--   (4&gt;&lt;6)
--    [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0
--    , 0.0, 1.0, 0.0, 1.0, 0.0, 1.0
--    , 1.0, 0.0, 1.0, 0.0, 1.0, 0.0
--    , 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 ]
--   </pre>
repmat :: Element t => Matrix t -> Int -> Int -> Matrix t

-- | Reverse rows
flipud :: Element t => Matrix t -> Matrix t

-- | Reverse columns
fliprl :: Element t => Matrix t -> Matrix t

-- | Extracts a submatrix from a matrix.
subMatrix :: Element a => (Int, Int) -> (Int, Int) -> Matrix a -> Matrix a

-- | Creates a matrix with the first n rows of another matrix
takeRows :: Element t => Int -> Matrix t -> Matrix t

-- | Creates a copy of a matrix without the first n rows
dropRows :: Element t => Int -> Matrix t -> Matrix t

-- | Creates a matrix with the first n columns of another matrix
takeColumns :: Element t => Int -> Matrix t -> Matrix t

-- | Creates a copy of a matrix without the first n columns
dropColumns :: Element t => Int -> Matrix t -> Matrix t

-- | rearranges the rows of a matrix according to the order given in a list
--   of integers.
extractRows :: Element t => [Int] -> Matrix t -> Matrix t

-- | creates a rectangular diagonal matrix:
--   
--   <pre>
--   &gt; diagRect 7 (fromList [10,20,30]) 4 5 :: Matrix Double
--   (4&gt;&lt;5)
--    [ 10.0,  7.0,  7.0, 7.0, 7.0
--    ,  7.0, 20.0,  7.0, 7.0, 7.0
--    ,  7.0,  7.0, 30.0, 7.0, 7.0
--    ,  7.0,  7.0,  7.0, 7.0, 7.0 ]
--   </pre>
diagRect :: Storable t => t -> Vector t -> Int -> Int -> Matrix t

-- | extracts the diagonal from a rectangular matrix
takeDiag :: Element t => Matrix t -> Vector t
mapMatrix :: (Storable a, Storable b) => (a -> b) -> Matrix a -> Matrix b

-- | <pre>
--   ghci&gt; mapMatrixWithIndex (\(i,j) v -&gt; 100*v + 10*i + j) (ident 3:: Matrix Double)
--   (3&gt;&lt;3)
--    [ 100.0,   1.0,   2.0
--    ,  10.0, 111.0,  12.0
--    ,  20.0,  21.0, 122.0 ]
--   </pre>
mapMatrixWithIndex :: (Element a, Storable b) => ((Int, Int) -> a -> b) -> Matrix a -> Matrix b

-- | <pre>
--   ghci&gt; mapMatrixWithIndexM (\(i,j) v -&gt; Just $ 100*v + 10*i + j) (ident 3:: Matrix Double)
--   Just (3&gt;&lt;3)
--    [ 100.0,   1.0,   2.0
--    ,  10.0, 111.0,  12.0
--    ,  20.0,  21.0, 122.0 ]
--   </pre>
mapMatrixWithIndexM :: (Element a, Storable b, Monad m) => ((Int, Int) -> a -> m b) -> Matrix a -> m (Matrix b)

-- | <pre>
--   ghci&gt; mapMatrixWithIndexM_ (\(i,j) v -&gt; printf "m[%.0f,%.0f] = %.f\n" i j v :: IO()) ((2&gt;&lt;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
--   </pre>
mapMatrixWithIndexM_ :: (Element a, Num a, Monad m) => ((Int, Int) -> a -> m ()) -> Matrix a -> m ()

-- | application of a vector function on the flattened matrix elements
liftMatrix :: (Storable a, Storable b) => (Vector a -> Vector b) -> Matrix a -> Matrix b

-- | application of a vector function on the flattened matrices elements
liftMatrix2 :: (Element t, Element a, Element b) => (Vector a -> Vector b -> Vector t) -> Matrix a -> Matrix b -> Matrix t

-- | A version of <a>liftMatrix2</a> which automatically adapt matrices
--   with a single row or column to match the dimensions of the other
--   matrix.
liftMatrix2Auto :: (Element t, Element a, Element b) => (Vector a -> Vector b -> Vector t) -> Matrix a -> Matrix b -> Matrix t
fromArray2D :: Storable e => Array (Int, Int) e -> Matrix e
instance (Element a, Read a) => Read (Matrix a)
instance (Show a, Element a) => Show (Matrix a)
instance (Binary a, Element a, Storable a) => Binary (Matrix a)


-- | Minimization of a multidimensional function using some of the
--   algorithms described in:
--   
--   
--   <a>http://www.gnu.org/software/gsl/manual/html_node/Multidimensional-Minimization.html</a>
--   
--   The example in the GSL manual:
--   
--   <pre>
--   f [x,y] = 10*(x-1)^2 + 20*(y-2)^2 + 30
--   
--   main = do
--       let (s,p) = minimize NMSimplex2 1E-2 30 [1,1] f [5,7]
--       print s
--       print p
--   
--   &gt; main
--   [0.9920430849306288,1.9969168063253182]
--    0.000  512.500  1.130  6.500  5.000
--    1.000  290.625  1.409  5.250  4.000
--    2.000  290.625  1.409  5.250  4.000
--    3.000  252.500  1.409  5.500  1.000
--    ...
--   22.000   30.001  0.013  0.992  1.997
--   23.000   30.001  0.008  0.992  1.997
--   </pre>
--   
--   The path to the solution can be graphically shown by means of:
--   
--   <pre>
--   <a>mplot</a> $ drop 3 (<a>toColumns</a> p)
--   </pre>
--   
--   Taken from the GSL manual:
--   
--   The vector Broyden-Fletcher-Goldfarb-Shanno (BFGS) algorithm is a
--   quasi-Newton method which builds up an approximation to the second
--   derivatives of the function f using the difference between successive
--   gradient vectors. By combining the first and second derivatives the
--   algorithm is able to take Newton-type steps towards the function
--   minimum, assuming quadratic behavior in that region.
--   
--   The bfgs2 version of this minimizer is the most efficient version
--   available, and is a faithful implementation of the line minimization
--   scheme described in Fletcher's Practical Methods of Optimization,
--   Algorithms 2.6.2 and 2.6.4. It supercedes the original bfgs routine
--   and requires substantially fewer function and gradient evaluations.
--   The user-supplied tolerance tol corresponds to the parameter sigma
--   used by Fletcher. A value of 0.1 is recommended for typical use
--   (larger values correspond to less accurate line searches).
--   
--   The nmsimplex2 version is a new O(N) implementation of the earlier
--   O(N^2) nmsimplex minimiser. It calculates the size of simplex as the
--   rms distance of each vertex from the center rather than the mean
--   distance, which has the advantage of allowing a linear update.
module Numeric.GSL.Minimization

-- | Minimization without derivatives
minimize :: MinimizeMethod -> Double -> Int -> [Double] -> ([Double] -> Double) -> [Double] -> ([Double], Matrix Double)

-- | Minimization without derivatives (vector version)
minimizeV :: MinimizeMethod -> Double -> Int -> Vector Double -> (Vector Double -> Double) -> Vector Double -> (Vector Double, Matrix Double)
data MinimizeMethod
NMSimplex :: MinimizeMethod
NMSimplex2 :: MinimizeMethod

-- | Minimization with derivatives.
minimizeD :: MinimizeMethodD -> Double -> Int -> Double -> Double -> ([Double] -> Double) -> ([Double] -> [Double]) -> [Double] -> ([Double], Matrix Double)

-- | Minimization with derivatives (vector version)
minimizeVD :: MinimizeMethodD -> Double -> Int -> Double -> Double -> (Vector Double -> Double) -> (Vector Double -> Vector Double) -> Vector Double -> (Vector Double, Matrix Double)
data MinimizeMethodD
ConjugateFR :: MinimizeMethodD
ConjugatePR :: MinimizeMethodD
VectorBFGS :: MinimizeMethodD
VectorBFGS2 :: MinimizeMethodD
SteepestDescent :: MinimizeMethodD

-- | <i>Deprecated: use minimize NMSimplex2 eps maxit sizes f xi </i>
minimizeNMSimplex :: ([Double] -> Double) -> [Double] -> [Double] -> Double -> Int -> ([Double], Matrix Double)

-- | <i>Deprecated: use minimizeD ConjugateFR eps maxit step tol f g xi
--   </i>
minimizeConjugateGradient :: Double -> Double -> Double -> Int -> ([Double] -> Double) -> ([Double] -> [Double]) -> [Double] -> ([Double], Matrix Double)

-- | <i>Deprecated: use minimizeD VectorBFGS2 eps maxit step tol f g xi
--   </i>
minimizeVectorBFGS2 :: Double -> Double -> Double -> Int -> ([Double] -> Double) -> ([Double] -> [Double]) -> [Double] -> ([Double], Matrix Double)
instance Enum MinimizeMethod
instance Eq MinimizeMethod
instance Show MinimizeMethod
instance Bounded MinimizeMethod
instance Enum MinimizeMethodD
instance Eq MinimizeMethodD
instance Show MinimizeMethodD
instance Bounded MinimizeMethodD


-- | Multidimensional root finding.
--   
--   
--   <a>http://www.gnu.org/software/gsl/manual/html_node/Multidimensional-Root_002dFinding.html</a>
--   
--   The example in the GSL manual:
--   
--   <pre>
--   import Numeric.GSL
--   import Numeric.LinearAlgebra(format)
--   import Text.Printf(printf)
--   
--   rosenbrock a b [x,y] = [ a*(1-x), b*(y-x^2) ]
--   
--   disp = putStrLn . format "  " (printf "%.3f")
--   
--   main = do
--       let (sol,path) = root Hybrids 1E-7 30 (rosenbrock 1 10) [-10,-5]
--       print sol
--       disp path
--   
--   &gt; main
--   [1.0,1.0]
--    0.000  -10.000  -5.000  11.000  -1050.000
--    1.000   -3.976  24.827   4.976     90.203
--    2.000   -3.976  24.827   4.976     90.203
--    3.000   -3.976  24.827   4.976     90.203
--    4.000   -1.274  -5.680   2.274    -73.018
--    5.000   -1.274  -5.680   2.274    -73.018
--    6.000    0.249   0.298   0.751      2.359
--    7.000    0.249   0.298   0.751      2.359
--    8.000    1.000   0.878  -0.000     -1.218
--    9.000    1.000   0.989  -0.000     -0.108
--   10.000    1.000   1.000   0.000      0.000
--   </pre>
module Numeric.GSL.Root
uniRoot :: UniRootMethod -> Double -> Int -> (Double -> Double) -> Double -> Double -> (Double, Matrix Double)
data UniRootMethod
Bisection :: UniRootMethod
FalsePos :: UniRootMethod
Brent :: UniRootMethod
uniRootJ :: UniRootMethodJ -> Double -> Int -> (Double -> Double) -> (Double -> Double) -> Double -> (Double, Matrix Double)
data UniRootMethodJ
UNewton :: UniRootMethodJ
Secant :: UniRootMethodJ
Steffenson :: UniRootMethodJ

-- | Nonlinear multidimensional root finding using algorithms that do not
--   require any derivative information to be supplied by the user. Any
--   derivatives needed are approximated by finite differences.
root :: RootMethod -> Double -> Int -> ([Double] -> [Double]) -> [Double] -> ([Double], Matrix Double)
data RootMethod
Hybrids :: RootMethod
Hybrid :: RootMethod
DNewton :: RootMethod
Broyden :: RootMethod

-- | Nonlinear multidimensional root finding using both the function and
--   its derivatives.
rootJ :: RootMethodJ -> Double -> Int -> ([Double] -> [Double]) -> ([Double] -> [[Double]]) -> [Double] -> ([Double], Matrix Double)
data RootMethodJ
HybridsJ :: RootMethodJ
HybridJ :: RootMethodJ
Newton :: RootMethodJ
GNewton :: RootMethodJ
instance Enum UniRootMethod
instance Eq UniRootMethod
instance Show UniRootMethod
instance Bounded UniRootMethod
instance Enum UniRootMethodJ
instance Eq UniRootMethodJ
instance Show UniRootMethodJ
instance Bounded UniRootMethodJ
instance Enum RootMethod
instance Eq RootMethod
instance Show RootMethod
instance Bounded RootMethod
instance Enum RootMethodJ
instance Eq RootMethodJ
instance Show RootMethodJ
instance Bounded RootMethodJ


-- | Functional interface to selected LAPACK functions
--   (<a>http://www.netlib.org/lapack</a>).
module Numeric.LinearAlgebra.LAPACK

-- | Matrix product based on BLAS's <i>dgemm</i>.
multiplyR :: Matrix Double -> Matrix Double -> Matrix Double

-- | Matrix product based on BLAS's <i>zgemm</i>.
multiplyC :: Matrix (Complex Double) -> Matrix (Complex Double) -> Matrix (Complex Double)

-- | Matrix product based on BLAS's <i>sgemm</i>.
multiplyF :: Matrix Float -> Matrix Float -> Matrix Float

-- | Matrix product based on BLAS's <i>cgemm</i>.
multiplyQ :: Matrix (Complex Float) -> Matrix (Complex Float) -> Matrix (Complex Float)

-- | Solve a real linear system (for square coefficient matrix and several
--   right-hand sides) using the LU decomposition, based on LAPACK's
--   <i>dgesv</i>. For underconstrained or overconstrained systems use
--   <a>linearSolveLSR</a> or <a>linearSolveSVDR</a>. See also <a>lusR</a>.
linearSolveR :: Matrix Double -> Matrix Double -> Matrix Double

-- | Solve a complex linear system (for square coefficient matrix and
--   several right-hand sides) using the LU decomposition, based on
--   LAPACK's <i>zgesv</i>. For underconstrained or overconstrained systems
--   use <a>linearSolveLSC</a> or <a>linearSolveSVDC</a>. See also
--   <a>lusC</a>.
linearSolveC :: Matrix (Complex Double) -> Matrix (Complex Double) -> Matrix (Complex Double)

-- | Solve a real linear system from a precomputed LU decomposition
--   (<a>luR</a>), using LAPACK's <i>dgetrs</i>.
lusR :: Matrix Double -> [Int] -> Matrix Double -> Matrix Double

-- | Solve a real linear system from a precomputed LU decomposition
--   (<a>luC</a>), using LAPACK's <i>zgetrs</i>.
lusC :: Matrix (Complex Double) -> [Int] -> Matrix (Complex Double) -> Matrix (Complex Double)

-- | Solves a symmetric positive definite system of linear equations using
--   a precomputed Cholesky factorization obtained by <a>cholS</a>.
cholSolveR :: Matrix Double -> Matrix Double -> Matrix Double

-- | Solves a Hermitian positive definite system of linear equations using
--   a precomputed Cholesky factorization obtained by <a>cholH</a>.
cholSolveC :: Matrix (Complex Double) -> Matrix (Complex Double) -> Matrix (Complex Double)

-- | Least squared error solution of an overconstrained real linear system,
--   or the minimum norm solution of an underconstrained system, using
--   LAPACK's <i>dgels</i>. For rank-deficient systems use
--   <a>linearSolveSVDR</a>.
linearSolveLSR :: Matrix Double -> Matrix Double -> Matrix Double

-- | Least squared error solution of an overconstrained complex linear
--   system, or the minimum norm solution of an underconstrained system,
--   using LAPACK's <i>zgels</i>. For rank-deficient systems use
--   <a>linearSolveSVDC</a>.
linearSolveLSC :: Matrix (Complex Double) -> Matrix (Complex Double) -> Matrix (Complex Double)

-- | Minimum norm solution of a general real linear least squares problem
--   Ax=B using the SVD, based on LAPACK's <i>dgelss</i>. Admits
--   rank-deficient systems but it is slower than <a>linearSolveLSR</a>.
--   The effective rank of A is determined by treating as zero those
--   singular valures which are less than rcond times the largest singular
--   value. If rcond == Nothing machine precision is used.
linearSolveSVDR :: Maybe Double -> Matrix Double -> Matrix Double -> Matrix Double

-- | Minimum norm solution of a general complex linear least squares
--   problem Ax=B using the SVD, based on LAPACK's <i>zgelss</i>. Admits
--   rank-deficient systems but it is slower than <a>linearSolveLSC</a>.
--   The effective rank of A is determined by treating as zero those
--   singular valures which are less than rcond times the largest singular
--   value. If rcond == Nothing machine precision is used.
linearSolveSVDC :: Maybe Double -> Matrix (Complex Double) -> Matrix (Complex Double) -> Matrix (Complex Double)

-- | Singular values of a real matrix, using LAPACK's <i>dgesvd</i> with
--   jobu == jobvt == 'N'.
svR :: Matrix Double -> Vector Double

-- | Singular values of a real matrix, using LAPACK's <i>dgesdd</i> with
--   jobz == 'N'.
svRd :: Matrix Double -> Vector Double

-- | Singular values of a complex matrix, using LAPACK's <i>zgesvd</i> with
--   jobu == jobvt == 'N'.
svC :: Matrix (Complex Double) -> Vector Double

-- | Singular values of a complex matrix, using LAPACK's <i>zgesdd</i> with
--   jobz == 'N'.
svCd :: Matrix (Complex Double) -> Vector Double

-- | Full SVD of a real matrix using LAPACK's <i>dgesvd</i>.
svdR :: Matrix Double -> (Matrix Double, Vector Double, Matrix Double)

-- | Full SVD of a real matrix using LAPACK's <i>dgesdd</i>.
svdRd :: Matrix Double -> (Matrix Double, Vector Double, Matrix Double)

-- | Full SVD of a complex matrix using LAPACK's <i>zgesvd</i>.
svdC :: Matrix (Complex Double) -> (Matrix (Complex Double), Vector Double, Matrix (Complex Double))

-- | Full SVD of a complex matrix using LAPACK's <i>zgesdd</i>.
svdCd :: Matrix (Complex Double) -> (Matrix (Complex Double), Vector Double, Matrix (Complex Double))

-- | Thin SVD of a real matrix, using LAPACK's <i>dgesvd</i> with jobu ==
--   jobvt == 'S'.
thinSVDR :: Matrix Double -> (Matrix Double, Vector Double, Matrix Double)

-- | Thin SVD of a real matrix, using LAPACK's <i>dgesdd</i> with jobz ==
--   'S'.
thinSVDRd :: Matrix Double -> (Matrix Double, Vector Double, Matrix Double)

-- | Thin SVD of a complex matrix, using LAPACK's <i>zgesvd</i> with jobu
--   == jobvt == 'S'.
thinSVDC :: Matrix (Complex Double) -> (Matrix (Complex Double), Vector Double, Matrix (Complex Double))

-- | Thin SVD of a complex matrix, using LAPACK's <i>zgesdd</i> with jobz
--   == 'S'.
thinSVDCd :: Matrix (Complex Double) -> (Matrix (Complex Double), Vector Double, Matrix (Complex Double))

-- | Singular values and all right singular vectors of a real matrix, using
--   LAPACK's <i>dgesvd</i> with jobu == 'N' and jobvt == 'A'.
rightSVR :: Matrix Double -> (Vector Double, Matrix Double)

-- | Singular values and all right singular vectors of a complex matrix,
--   using LAPACK's <i>zgesvd</i> with jobu == 'N' and jobvt == 'A'.
rightSVC :: Matrix (Complex Double) -> (Vector Double, Matrix (Complex Double))

-- | Singular values and all left singular vectors of a real matrix, using
--   LAPACK's <i>dgesvd</i> with jobu == 'A' and jobvt == 'N'.
leftSVR :: Matrix Double -> (Matrix Double, Vector Double)

-- | Singular values and all left singular vectors of a complex matrix,
--   using LAPACK's <i>zgesvd</i> with jobu == 'A' and jobvt == 'N'.
leftSVC :: Matrix (Complex Double) -> (Matrix (Complex Double), Vector Double)

-- | Eigenvalues and right eigenvectors of a general real matrix, using
--   LAPACK's <i>dgeev</i>. The eigenvectors are the columns of v. The
--   eigenvalues are not sorted.
eigR :: Matrix Double -> (Vector (Complex Double), Matrix (Complex Double))

-- | Eigenvalues and right eigenvectors of a general complex matrix, using
--   LAPACK's <i>zgeev</i>. The eigenvectors are the columns of v. The
--   eigenvalues are not sorted.
eigC :: Matrix (Complex Double) -> (Vector (Complex Double), Matrix (Complex Double))

-- | Eigenvalues and right eigenvectors of a symmetric real matrix, using
--   LAPACK's <i>dsyev</i>. The eigenvectors are the columns of v. The
--   eigenvalues are sorted in descending order (use <a>eigS'</a> for
--   ascending order).
eigS :: Matrix Double -> (Vector Double, Matrix Double)

-- | <a>eigS</a> in ascending order
eigS' :: Matrix Double -> (Vector Double, Matrix Double)

-- | Eigenvalues and right eigenvectors of a hermitian complex matrix,
--   using LAPACK's <i>zheev</i>. The eigenvectors are the columns of v.
--   The eigenvalues are sorted in descending order (use <a>eigH'</a> for
--   ascending order).
eigH :: Matrix (Complex Double) -> (Vector Double, Matrix (Complex Double))

-- | <a>eigH</a> in ascending order
eigH' :: Matrix (Complex Double) -> (Vector Double, Matrix (Complex Double))

-- | Eigenvalues of a general real matrix, using LAPACK's <i>dgeev</i> with
--   jobz == 'N'. The eigenvalues are not sorted.
eigOnlyR :: Matrix Double -> Vector (Complex Double)

-- | Eigenvalues of a general complex matrix, using LAPACK's <i>zgeev</i>
--   with jobz == 'N'. The eigenvalues are not sorted.
eigOnlyC :: Matrix (Complex Double) -> Vector (Complex Double)

-- | Eigenvalues of a symmetric real matrix, using LAPACK's <i>dsyev</i>
--   with jobz == 'N'. The eigenvalues are sorted in descending order.
eigOnlyS :: Matrix Double -> Vector Double

-- | Eigenvalues of a hermitian complex matrix, using LAPACK's <i>zheev</i>
--   with jobz == 'N'. The eigenvalues are sorted in descending order.
eigOnlyH :: Matrix (Complex Double) -> Vector Double

-- | LU factorization of a general real matrix, using LAPACK's
--   <i>dgetrf</i>.
luR :: Matrix Double -> (Matrix Double, [Int])

-- | LU factorization of a general complex matrix, using LAPACK's
--   <i>zgetrf</i>.
luC :: Matrix (Complex Double) -> (Matrix (Complex Double), [Int])

-- | Cholesky factorization of a real symmetric positive definite matrix,
--   using LAPACK's <i>dpotrf</i>.
cholS :: Matrix Double -> Matrix Double

-- | Cholesky factorization of a complex Hermitian positive definite
--   matrix, using LAPACK's <i>zpotrf</i>.
cholH :: Matrix (Complex Double) -> Matrix (Complex Double)

-- | Cholesky factorization of a real symmetric positive definite matrix,
--   using LAPACK's <i>dpotrf</i> (<a>Maybe</a> version).
mbCholS :: Matrix Double -> Maybe (Matrix Double)

-- | Cholesky factorization of a complex Hermitian positive definite
--   matrix, using LAPACK's <i>zpotrf</i> (<a>Maybe</a> version).
mbCholH :: Matrix (Complex Double) -> Maybe (Matrix (Complex Double))

-- | QR factorization of a real matrix, using LAPACK's <i>dgeqr2</i>.
qrR :: Matrix Double -> (Matrix Double, Vector Double)

-- | QR factorization of a complex matrix, using LAPACK's <i>zgeqr2</i>.
qrC :: Matrix (Complex Double) -> (Matrix (Complex Double), Vector (Complex Double))

-- | Hessenberg factorization of a square real matrix, using LAPACK's
--   <i>dgehrd</i>.
hessR :: Matrix Double -> (Matrix Double, Vector Double)

-- | Hessenberg factorization of a square complex matrix, using LAPACK's
--   <i>zgehrd</i>.
hessC :: Matrix (Complex Double) -> (Matrix (Complex Double), Vector (Complex Double))

-- | Schur factorization of a square real matrix, using LAPACK's
--   <i>dgees</i>.
schurR :: Matrix Double -> (Matrix Double, Matrix Double)

-- | Schur factorization of a square complex matrix, using LAPACK's
--   <i>zgees</i>.
schurC :: Matrix (Complex Double) -> (Matrix (Complex Double), Matrix (Complex Double))


-- | 1D arrays suitable for numeric computations using external libraries.
--   
--   This module provides basic functions for manipulation of structure.
module Data.Packed.Vector

-- | <a>Storable</a>-based vectors
data Vector a :: * -> *

-- | creates a Vector from a list:
--   
--   <pre>
--   &gt; fromList [2,3,5,7]
--   4 |&gt; [2.0,3.0,5.0,7.0]
--   </pre>
fromList :: Storable a => [a] -> Vector a

-- | An alternative to <a>fromList</a> with explicit dimension. The input
--   list is explicitly truncated if it is too long, so it may safely be
--   used, for instance, with infinite lists.
--   
--   This is the format used in the instances for Show (Vector a).
(|>) :: Storable a => Int -> [a] -> Vector a

-- | extracts the Vector elements to a list
--   
--   <pre>
--   &gt; toList (linspace 5 (1,10))
--   [1.0,3.25,5.5,7.75,10.0]
--   </pre>
toList :: Storable a => Vector a -> [a]

-- | creates a Vector of the specified length using the supplied function
--   to to map the index to the value at that index.
--   
--   <pre>
--   &gt; buildVector 4 fromIntegral
--   4 |&gt; [0.0,1.0,2.0,3.0]
--   </pre>
buildVector :: Storable a => Int -> (Int -> a) -> Vector a

-- | Number of elements
dim :: Storable t => Vector t -> Int

-- | Reads a vector position:
--   
--   <pre>
--   &gt; fromList [0..9] @&gt; 7
--   7.0
--   </pre>
(@>) :: Storable t => Vector t -> Int -> t

-- | takes a number of consecutive elements from a Vector
--   
--   <pre>
--   &gt; subVector 2 3 (fromList [1..10])
--   3 |&gt; [3.0,4.0,5.0]
--   </pre>
subVector :: Storable t => Int -> Int -> Vector t -> Vector t

-- | Extract consecutive subvectors of the given sizes.
--   
--   <pre>
--   &gt; takesV [3,4] (linspace 10 (1,10))
--   [3 |&gt; [1.0,2.0,3.0],4 |&gt; [4.0,5.0,6.0,7.0]]
--   </pre>
takesV :: Storable t => [Int] -> Vector t -> [Vector t]

-- | creates a new Vector by joining a list of Vectors
--   
--   <pre>
--   &gt; join [fromList [1..5], constant 1 3]
--   8 |&gt; [1.0,2.0,3.0,4.0,5.0,1.0,1.0,1.0]
--   </pre>
join :: Storable t => [Vector t] -> Vector t

-- | map on Vectors
mapVector :: (Storable a, Storable b) => (a -> b) -> Vector a -> Vector b
mapVectorWithIndex :: (Storable a, Storable b) => (Int -> a -> b) -> Vector a -> Vector b

-- | zip for Vectors
zipVector :: (Storable a, Storable b, Storable (a, b)) => Vector a -> Vector b -> Vector (a, b)

-- | zipWith for Vectors
zipVectorWith :: (Storable a, Storable b, Storable c) => (a -> b -> c) -> Vector a -> Vector b -> Vector c

-- | unzip for Vectors
unzipVector :: (Storable a, Storable b, Storable (a, b)) => Vector (a, b) -> (Vector a, Vector b)

-- | unzipWith for Vectors
unzipVectorWith :: (Storable (a, b), Storable c, Storable d) => ((a, b) -> (c, d)) -> Vector (a, b) -> (Vector c, Vector d)

-- | monadic map over Vectors the monad <tt>m</tt> must be strict
mapVectorM :: (Storable a, Storable b, Monad m) => (a -> m b) -> Vector a -> m (Vector b)

-- | monadic map over Vectors
mapVectorM_ :: (Storable a, Monad m) => (a -> m ()) -> Vector a -> m ()

-- | monadic map over Vectors with the zero-indexed index passed to the
--   mapping function the monad <tt>m</tt> must be strict
mapVectorWithIndexM :: (Storable a, Storable b, Monad m) => (Int -> a -> m b) -> Vector a -> m (Vector b)

-- | monadic map over Vectors with the zero-indexed index passed to the
--   mapping function
mapVectorWithIndexM_ :: (Storable a, Monad m) => (Int -> a -> m ()) -> Vector a -> m ()
foldLoop :: (Int -> t -> t) -> t -> Int -> t
foldVector :: Storable a => (a -> b -> b) -> b -> Vector a -> b
foldVectorG :: Storable t1 => (Int -> (Int -> t1) -> t -> t) -> t -> Vector t1 -> t
foldVectorWithIndex :: Storable a => (Int -> a -> b -> b) -> b -> Vector a -> b
instance (Binary a, Storable a) => Binary (Vector a)


-- | Types for dense <a>Vector</a> and <a>Matrix</a> of <tt>Storable</tt>
--   elements.
module Data.Packed


-- | High level generic interface to common matrix computations.
--   
--   Specific functions for particular base types can also be explicitly
--   imported from <a>Numeric.LinearAlgebra.LAPACK</a>.
module Numeric.LinearAlgebra.Algorithms

-- | 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 <a>single</a>
--   and <a>double</a>).
class (Product t, Convert t, Container Vector t, Container Matrix t, Normed Matrix t, Normed Vector t) => Field t

-- | Solve a linear system (for square coefficient matrix and several
--   right-hand sides) using the LU decomposition. For underconstrained or
--   overconstrained systems use <a>linearSolveLS</a> or
--   <a>linearSolveSVD</a>. It is similar to <a>luSolve</a> .
--   <a>luPacked</a>, but <tt>linearSolve</tt> raises an error if called on
--   a singular system.
linearSolve :: Field t => Matrix t -> Matrix t -> Matrix t

-- | Solution of a linear system (for several right hand sides) from the
--   precomputed LU factorization obtained by <a>luPacked</a>.
luSolve :: Field t => (Matrix t, [Int]) -> Matrix t -> Matrix t

-- | Solve a symmetric or Hermitian positive definite linear system using a
--   precomputed Cholesky decomposition obtained by <a>chol</a>.
cholSolve :: Field t => Matrix t -> Matrix t -> Matrix t

-- | Least squared error solution of an overconstrained linear system, or
--   the minimum norm solution of an underconstrained system. For
--   rank-deficient systems use <a>linearSolveSVD</a>.
linearSolveLS :: Field t => Matrix t -> Matrix t -> Matrix t

-- | Minimum norm solution of a general linear least squares problem Ax=B
--   using the SVD. Admits rank-deficient systems but it is slower than
--   <a>linearSolveLS</a>. The effective rank of A is determined by
--   treating as zero those singular valures which are less than <a>eps</a>
--   times the largest singular value.
linearSolveSVD :: Field t => Matrix t -> Matrix t -> Matrix t

-- | Inverse of a square matrix. See also <a>invlndet</a>.
inv :: Field t => Matrix t -> Matrix t

-- | Pseudoinverse of a general matrix.
pinv :: Field t => Matrix t -> Matrix t

-- | Determinant of a square matrix. To avoid possible overflow or
--   underflow use <a>invlndet</a>.
det :: Field t => Matrix t -> t

-- | Joint computation of inverse and logarithm of determinant of a square
--   matrix.
invlndet :: (Floating t, Field t) => Matrix t -> (Matrix t, (t, t))

-- | Number of linearly independent rows or columns.
rank :: Field t => Matrix t -> Int

-- | Reciprocal of the 2-norm condition number of a matrix, computed from
--   the singular values.
rcond :: Field t => Matrix t -> Double

-- | Full singular value decomposition.
svd :: Field t => Matrix t -> (Matrix t, Vector Double, Matrix t)

-- | A version of <a>svd</a> which returns an appropriate diagonal matrix
--   with the singular values.
--   
--   If <tt>(u,d,v) = fullSVD m</tt> then <tt>m == u &lt;&gt; d &lt;&gt;
--   trans v</tt>.
fullSVD :: Field t => Matrix t -> (Matrix t, Matrix Double, Matrix t)

-- | A version of <a>svd</a> which returns only the <tt>min (rows m) (cols
--   m)</tt> singular vectors of <tt>m</tt>.
--   
--   If <tt>(u,s,v) = thinSVD m</tt> then <tt>m == u &lt;&gt; diag s
--   &lt;&gt; trans v</tt>.
thinSVD :: Field t => Matrix t -> (Matrix t, Vector Double, Matrix t)

-- | Similar to <a>thinSVD</a>, returning only the nonzero singular values
--   and the corresponding singular vectors.
compactSVD :: Field t => Matrix t -> (Matrix t, Vector Double, Matrix t)

-- | Singular values only.
singularValues :: Field t => Matrix t -> Vector Double

-- | Singular values and all left singular vectors.
leftSV :: Field t => Matrix t -> (Matrix t, Vector Double)

-- | Singular values and all right singular vectors.
rightSV :: Field t => Matrix t -> (Vector Double, Matrix t)

-- | Eigenvalues and eigenvectors of a general square matrix.
--   
--   If <tt>(s,v) = eig m</tt> then <tt>m &lt;&gt; v == v &lt;&gt; diag
--   s</tt>
eig :: Field t => Matrix t -> (Vector (Complex Double), Matrix (Complex Double))

-- | Eigenvalues and Eigenvectors of a complex hermitian or real symmetric
--   matrix.
--   
--   If <tt>(s,v) = eigSH m</tt> then <tt>m == v &lt;&gt; diag s &lt;&gt;
--   ctrans v</tt>
eigSH :: Field t => Matrix t -> (Vector Double, Matrix t)

-- | Similar to <a>eigSH</a> without checking that the input matrix is
--   hermitian or symmetric. It works with the upper triangular part.
eigSH' :: Field t => Matrix t -> (Vector Double, Matrix t)

-- | Eigenvalues of a general square matrix.
eigenvalues :: Field t => Matrix t -> Vector (Complex Double)

-- | Eigenvalues of a complex hermitian or real symmetric matrix.
eigenvaluesSH :: Field t => Matrix t -> Vector Double

-- | Similar to <a>eigenvaluesSH</a> without checking that the input matrix
--   is hermitian or symmetric. It works with the upper triangular part.
eigenvaluesSH' :: Field t => Matrix t -> Vector Double

-- | Generalized symmetric positive definite eigensystem Av = lBv, for A
--   and B symmetric, B positive definite (conditions not checked).
geigSH' :: Field t => Matrix t -> Matrix t -> (Vector Double, Matrix t)

-- | QR factorization.
--   
--   If <tt>(q,r) = qr m</tt> then <tt>m == q &lt;&gt; r</tt>, where q is
--   unitary and r is upper triangular.
qr :: Field t => Matrix t -> (Matrix t, Matrix t)

-- | RQ factorization.
--   
--   If <tt>(r,q) = rq m</tt> then <tt>m == r &lt;&gt; q</tt>, where q is
--   unitary and r is upper triangular.
rq :: Field t => Matrix t -> (Matrix t, Matrix t)

-- | Cholesky factorization of a positive definite hermitian or symmetric
--   matrix.
--   
--   If <tt>c = chol m</tt> then <tt>c</tt> is upper triangular and <tt>m
--   == ctrans c &lt;&gt; c</tt>.
chol :: Field t => Matrix t -> Matrix t

-- | Similar to <a>chol</a>, without checking that the input matrix is
--   hermitian or symmetric. It works with the upper triangular part.
cholSH :: Field t => Matrix t -> Matrix t

-- | Similar to <a>cholSH</a>, but instead of an error (e.g., caused by a
--   matrix not positive definite) it returns <a>Nothing</a>.
mbCholSH :: Field t => Matrix t -> Maybe (Matrix t)

-- | Hessenberg factorization.
--   
--   If <tt>(p,h) = hess m</tt> then <tt>m == p &lt;&gt; h &lt;&gt; ctrans
--   p</tt>, where p is unitary and h is in upper Hessenberg form (it has
--   zero entries below the first subdiagonal).
hess :: Field t => Matrix t -> (Matrix t, Matrix t)

-- | Schur factorization.
--   
--   If <tt>(u,s) = schur m</tt> then <tt>m == u &lt;&gt; s &lt;&gt; ctrans
--   u</tt>, where u is unitary and s is a Shur matrix. A complex Schur
--   matrix is upper triangular. A real Schur matrix is upper triangular in
--   2x2 blocks.
--   
--   "Anything that the Jordan decomposition can do, the Schur
--   decomposition can do better!" (Van Loan)
schur :: Field t => Matrix t -> (Matrix t, Matrix t)

-- | Explicit LU factorization of a general matrix.
--   
--   If <tt>(l,u,p,s) = lu m</tt> then <tt>m == p &lt;&gt; l &lt;&gt;
--   u</tt>, where l is lower triangular, u is upper triangular, p is a
--   permutation matrix and s is the signature of the permutation.
lu :: Field t => Matrix t -> (Matrix t, Matrix t, Matrix t, t)

-- | Obtains the LU decomposition of a matrix in a compact data structure
--   suitable for <a>luSolve</a>.
luPacked :: Field t => Matrix t -> (Matrix t, [Int])

-- | Matrix exponential. It uses a direct translation of Algorithm 11.3.1
--   in Golub &amp; Van Loan, based on a scaled Pade approximation.
expm :: Field t => Matrix t -> Matrix t

-- | Matrix square root. Currently it uses a simple iterative algorithm
--   described in Wikipedia. It only works with invertible matrices that
--   have a real solution. For diagonalizable matrices you can try
--   <tt>matFunc sqrt</tt>.
--   
--   <pre>
--   m = (2&gt;&lt;2) [4,9
--              ,0,4] :: Matrix Double
--   </pre>
--   
--   <pre>
--   &gt;sqrtm m
--   (2&gt;&lt;2)
--    [ 2.0, 2.25
--    , 0.0,  2.0 ]
--   </pre>
sqrtm :: Field t => Matrix t -> Matrix t

-- | Generic matrix functions for diagonalizable matrices. For instance:
--   
--   <pre>
--   logm = matFunc log
--   </pre>
matFunc :: (Complex Double -> Complex Double) -> Matrix (Complex Double) -> Matrix (Complex Double)

-- | The nullspace of a matrix. See also <a>nullspaceSVD</a>.
nullspacePrec :: Field t => Double -> Matrix t -> [Vector t]

-- | The nullspace of a matrix, assumed to be one-dimensional, with machine
--   precision.
nullVector :: Field t => Matrix t -> Vector t

-- | The nullspace of a matrix from its SVD decomposition.
nullspaceSVD :: Field t => Either Double Int -> Matrix t -> (Vector Double, Matrix t) -> [Vector t]

-- | Return an orthonormal basis of the range space of a matrix
orth :: Field t => Matrix t -> [Vector t]
class RealFloat (RealOf t) => Normed c t
pnorm :: Normed c t => NormType -> c t -> RealOf t
data NormType
Infinity :: NormType
PNorm1 :: NormType
PNorm2 :: NormType
Frobenius :: NormType

-- | Approximate number of common digits in the maximum element.
relativeError :: (Normed c t, Container c t) => c t -> c t -> Int

-- | The machine precision of a Double: <tt>eps = 2.22044604925031e-16</tt>
--   (the value used by GNU-Octave).
eps :: Double

-- | 1 + 0.5*peps == 1, 1 + 0.6*peps /= 1
peps :: RealFloat x => x

-- | The imaginary unit: <tt>i = 0.0 :+ 1.0</tt>
i :: Complex Double
haussholder :: Field a => a -> Vector a -> Matrix a
unpackQR :: Field t => (Matrix t, Vector t) -> (Matrix t, Matrix t)
unpackHess :: Field t => (Matrix t -> (Matrix t, Vector t)) -> Matrix t -> (Matrix t, Matrix t)
pinvTol :: Double -> Matrix Double -> Matrix Double

-- | Numeric rank of a matrix from its singular values.
ranksv :: Double -> Int -> [Double] -> Int
instance Normed Matrix (Complex Float)
instance Normed Matrix Float
instance Normed Matrix (Complex Double)
instance Normed Matrix Double
instance Normed Vector (Complex Float)
instance Normed Vector Float
instance Normed Vector (Complex Double)
instance Normed Vector Double
instance Field (Complex Double)
instance Field Double


-- | Basic numeric operations on <a>Vector</a> and <a>Matrix</a>, including
--   conversion routines.
--   
--   The <a>Container</a> class is used to define optimized generic
--   functions which work on <a>Vector</a> and <a>Matrix</a> with real or
--   complex elements.
--   
--   Some of these functions are also available in the instances of the
--   standard numeric Haskell classes provided by
--   <a>Numeric.LinearAlgebra</a>.
module Numeric.Container

-- | creates a vector with a given number of equal components:
--   
--   <pre>
--   &gt; constant 2 7
--   7 |&gt; [2.0,2.0,2.0,2.0,2.0,2.0,2.0]
--   </pre>
constant :: Element a => a -> Int -> Vector a

-- | Creates a real vector containing a range of values:
--   
--   <pre>
--   &gt; linspace 5 (-3,7)
--   5 |&gt; [-3.0,-0.5,2.0,4.5,7.0]
--   </pre>
--   
--   Logarithmic spacing can be defined as follows:
--   
--   <pre>
--   logspace n (a,b) = 10 ** linspace n (a,b)
--   </pre>
linspace :: (Enum e, Container Vector e) => Int -> (e, e) -> Vector e

-- | Creates a square matrix with a given diagonal.
diag :: (Num a, Element a) => Vector a -> Matrix a

-- | creates the identity matrix of given dimension
ident :: (Num a, Element a) => Int -> Matrix a

-- | conjugate transpose
ctrans :: (Container Vector e, Element e) => Matrix e -> Matrix e

-- | Basic element-by-element functions for numeric containers
class (Complexable c, Fractional e, Element e) => Container c e
scalar :: Container c e => e -> c e
conj :: Container c e => c e -> c e
scale :: Container c e => e -> c e -> c e
scaleRecip :: Container c e => e -> c e -> c e
addConstant :: Container c e => e -> c e -> c e
add :: Container c e => c e -> c e -> c e
sub :: Container c e => c e -> c e -> c e
mul :: Container c e => c e -> c e -> c e
divide :: Container c e => c e -> c e -> c e
equal :: Container c e => c e -> c e -> Bool
arctan2 :: Container c e => c e -> c e -> c e
cmap :: (Container c e, Element b) => (e -> b) -> c e -> c b
konst :: Container c e => e -> IndexOf c -> c e
build :: Container c e => IndexOf c -> (ArgOf c e) -> c e
atIndex :: Container c e => c e -> IndexOf c -> e
minIndex :: Container c e => c e -> IndexOf c
maxIndex :: Container c e => c e -> IndexOf c
minElement :: Container c e => c e -> e
maxElement :: Container c e => c e -> e
sumElements :: Container c e => c e -> e
prodElements :: Container c e => c e -> e
step :: (Container c e, RealElement e) => c e -> c e
cond :: (Container c e, RealElement e) => c e -> c e -> c e -> c e -> c e -> c e
find :: Container c e => (e -> Bool) -> c e -> [IndexOf c]
assoc :: Container c e => IndexOf c -> e -> [(IndexOf c, e)] -> c e
accum :: Container c e => c e -> (e -> e -> e) -> [(IndexOf c, e)] -> c e

-- | Matrix product and related functions
class Element e => Product e
multiply :: Product e => Matrix e -> Matrix e -> Matrix e
dot :: Product e => Vector e -> Vector e -> e
absSum :: Product e => Vector e -> RealOf e
norm1 :: Product e => Vector e -> RealOf e
norm2 :: Product e => Vector e -> RealOf e
normInf :: Product e => Vector e -> RealOf e

-- | Provide optimal association order for a chain of matrix
--   multiplications and apply the multiplications.
--   
--   The algorithm is the well-known O(n^3) dynamic programming algorithm
--   that builds a pyramid of optimal associations.
--   
--   <pre>
--   m1, m2, m3, m4 :: Matrix Double
--   m1 = (10&gt;&lt;15) [1..]
--   m2 = (15&gt;&lt;20) [1..]
--   m3 = (20&gt;&lt;5) [1..]
--   m4 = (5&gt;&lt;10) [1..]
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; optimiseMult [m1,m2,m3,m4]
--   </pre>
--   
--   will perform <tt>((m1 <a>multiply</a> (m2 <a>multiply</a> m3))
--   <a>multiply</a> m4)</tt>
--   
--   The naive left-to-right multiplication would take <tt>4500</tt> scalar
--   multiplications whereas the optimised version performs <tt>2750</tt>
--   scalar multiplications. The complexity in this case is 32 (= 4^3/2) *
--   (2 comparisons, 3 scalar multiplications, 3 scalar additions, 5
--   lookups, 2 updates) + a constant (= three table allocations)
optimiseMult :: Product t => [Matrix t] -> Matrix t
mXm :: Product t => Matrix t -> Matrix t -> Matrix t
mXv :: Product t => Matrix t -> Vector t -> Vector t
vXm :: Product t => Vector t -> Matrix t -> Vector t

-- | Dot product: <tt>u &lt;.&gt; v = dot u v</tt>
(<.>) :: Product t => Vector t -> Vector t -> t
class Mul a b c | a b -> c
(<>) :: (Mul a b c, Product t) => a t -> b t -> c t
class LSDiv b c | b -> c, c -> b
(<\>) :: (LSDiv b c, Field t) => Matrix t -> b t -> c t

-- | Outer product of two vectors.
--   
--   <pre>
--   &gt; <a>fromList</a> [1,2,3] `outer` <a>fromList</a> [5,2,3]
--   (3&gt;&lt;3)
--    [  5.0, 2.0, 3.0
--    , 10.0, 4.0, 6.0
--    , 15.0, 6.0, 9.0 ]
--   </pre>
outer :: Product t => Vector t -> Vector t -> Matrix t

-- | Kronecker product of two matrices.
--   
--   <pre>
--   m1=(2&gt;&lt;3)
--    [ 1.0,  2.0, 0.0
--    , 0.0, -1.0, 3.0 ]
--   m2=(4&gt;&lt;3)
--    [  1.0,  2.0,  3.0
--    ,  4.0,  5.0,  6.0
--    ,  7.0,  8.0,  9.0
--    , 10.0, 11.0, 12.0 ]
--   </pre>
--   
--   <pre>
--   &gt; kronecker m1 m2
--   (8&gt;&lt;9)
--    [  1.0,  2.0,  3.0,   2.0,   4.0,   6.0,  0.0,  0.0,  0.0
--    ,  4.0,  5.0,  6.0,   8.0,  10.0,  12.0,  0.0,  0.0,  0.0
--    ,  7.0,  8.0,  9.0,  14.0,  16.0,  18.0,  0.0,  0.0,  0.0
--    , 10.0, 11.0, 12.0,  20.0,  22.0,  24.0,  0.0,  0.0,  0.0
--    ,  0.0,  0.0,  0.0,  -1.0,  -2.0,  -3.0,  3.0,  6.0,  9.0
--    ,  0.0,  0.0,  0.0,  -4.0,  -5.0,  -6.0, 12.0, 15.0, 18.0
--    ,  0.0,  0.0,  0.0,  -7.0,  -8.0,  -9.0, 21.0, 24.0, 27.0
--    ,  0.0,  0.0,  0.0, -10.0, -11.0, -12.0, 30.0, 33.0, 36.0 ]
--   </pre>
kronecker :: Product t => Matrix t -> Matrix t -> Matrix t
data RandDist

-- | uniform distribution in [0,1)
Uniform :: RandDist

-- | normal distribution with mean zero and standard deviation one
Gaussian :: RandDist

-- | Obtains a vector of pseudorandom elements from the the mt19937
--   generator in GSL, with a given seed. Use randomIO to get a random
--   seed.
randomVector :: Int -> RandDist -> Int -> Vector Double

-- | Obtains a matrix whose rows are pseudorandom samples from a
--   multivariate Gaussian distribution.
gaussianSample :: Seed -> Int -> Vector Double -> Matrix Double -> Matrix Double

-- | Obtains a matrix whose rows are pseudorandom samples from a
--   multivariate uniform distribution.
uniformSample :: Seed -> Int -> [(Double, Double)] -> Matrix Double

-- | Compute mean vector and covariance matrix of the rows of a matrix.
meanCov :: Matrix Double -> (Vector Double, Matrix Double)
class Convert t
real :: (Convert t, Container c t) => c (RealOf t) -> c t
complex :: (Convert t, Container c t) => c t -> c (ComplexOf t)
single :: (Convert t, Container c t) => c t -> c (SingleOf t)
double :: (Convert t, Container c t) => c t -> c (DoubleOf t)
toComplex :: (Convert t, Container c t, RealElement t) => (c t, c t) -> c (Complex t)
fromComplex :: (Convert t, Container c t, RealElement t) => c (Complex t) -> (c t, c t)

-- | Structures that may contain complex numbers
class Complexable c

-- | Supported real types
class (Element t, Element (Complex t), RealFloat t) => RealElement t

-- | Show a matrix with a given number of decimal places.
--   
--   <pre>
--   disp = putStr . dispf 3
--   
--   &gt; disp (1/3 + ident 4)
--   4x4
--   1.333  0.333  0.333  0.333
--   0.333  1.333  0.333  0.333
--   0.333  0.333  1.333  0.333
--   0.333  0.333  0.333  1.333
--   </pre>
dispf :: Int -> Matrix Double -> String

-- | Show a matrix with "autoscaling" and a given number of decimal places.
--   
--   <pre>
--   disp = putStr . disps 2
--   
--   &gt; disp $ 120 * (3&gt;&lt;4) [1..]
--   3x4  E3
--    0.12  0.24  0.36  0.48
--    0.60  0.72  0.84  0.96
--    1.08  1.20  1.32  1.44
--   </pre>
disps :: Int -> Matrix Double -> String

-- | Pretty print a complex matrix with at most n decimal digits.
dispcf :: Int -> Matrix (Complex Double) -> String

-- | Show a vector using a function for showing matrices.
--   
--   <pre>
--   disp = putStr . vecdisp (<a>dispf</a> 2)
--   
--   &gt; disp (<tt>linspace</tt> 10 (0,1))
--   10 |&gt; 0.00  0.11  0.22  0.33  0.44  0.56  0.67  0.78  0.89  1.00
--   </pre>
vecdisp :: Element t => (Matrix t -> String) -> Vector t -> String

-- | Tool to display matrices with latex syntax.
latexFormat :: String -> String -> String

-- | Creates a string from a matrix given a separator and a function to
--   show each entry. Using this function the user can easily define any
--   desired display function:
--   
--   <pre>
--   import Text.Printf(printf)
--   </pre>
--   
--   <pre>
--   disp = putStr . format "  " (printf "%.2f")
--   </pre>
format :: Element t => String -> (t -> String) -> Matrix t -> String

-- | Loads a matrix from an ASCII file formatted as a 2D table.
loadMatrix :: FilePath -> IO (Matrix Double)

-- | Saves a matrix as 2D ASCII table.
saveMatrix :: FilePath -> String -> Matrix Double -> IO ()

-- | Loads a matrix from an ASCII file (the number of rows and columns must
--   be known in advance).
fromFile :: FilePath -> (Int, Int) -> IO (Matrix Double)

-- | obtains the number of rows and columns in an ASCII data file
--   (provisionally using unix's wc).
fileDimensions :: FilePath -> IO (Int, Int)

-- | reads a matrix from a string containing a table of numbers.
readMatrix :: String -> Matrix Double

-- | Loads a vector from an ASCII file (the number of elements must be
--   known in advance).
fscanfVector :: FilePath -> Int -> IO (Vector Double)

-- | Saves the elements of a vector, with a given format (%f, %e, %g), to
--   an ASCII file.
fprintfVector :: FilePath -> String -> Vector Double -> IO ()

-- | Loads a vector from a binary file (the number of elements must be
--   known in advance).
freadVector :: FilePath -> Int -> IO (Vector Double)

-- | Saves the elements of a vector to a binary file.
fwriteVector :: FilePath -> Vector Double -> IO ()
build' :: Build f => BoundsOf f -> f -> ContainerOf f
konst' :: (Konst s, Element e) => e -> s -> ContainerOf' s e
instance LSDiv Matrix Matrix
instance LSDiv Vector Vector
instance Mul Vector Matrix Vector
instance Mul Matrix Vector Vector
instance Mul Matrix Matrix Matrix


-- | This module reexports all normally required functions for Linear
--   Algebra applications.
--   
--   It also provides instances of standard classes <a>Show</a>,
--   <a>Read</a>, <a>Eq</a>, <a>Num</a>, <a>Fractional</a>, and
--   <a>Floating</a> for <a>Vector</a> and <a>Matrix</a>. In arithmetic
--   operations one-component vectors and matrices automatically expand to
--   match the dimensions of the other operand.
module Numeric.LinearAlgebra


-- | Nonlinear Least-Squares Fitting
--   
--   
--   <a>http://www.gnu.org/software/gsl/manual/html_node/Nonlinear-Least_002dSquares-Fitting.html</a>
--   
--   The example program in the GSL manual (see examples/fitting.hs):
--   
--   <pre>
--   dat = [
--    ([0.0],([6.0133918608118675],0.1)),
--    ([1.0],([5.5153769909966535],0.1)),
--    ([2.0],([5.261094606015287],0.1)),
--    ...
--    ([39.0],([1.0619821710802808],0.1))]
--   
--   expModel [a,lambda,b] [t] = [a * exp (-lambda * t) + b]
--   
--   expModelDer [a,lambda,b] [t] = [[exp (-lambda * t), -t * a * exp(-lambda*t) , 1]]
--   
--   (sol,path) = fitModelScaled 1E-4 1E-4 20 (expModel, expModelDer) dat [1,0,0]
--   
--   &gt; path
--   (6&gt;&lt;5)
--    [ 1.0,  76.45780563978782, 1.6465931240727802, 1.8147715267618197e-2, 0.6465931240727797
--    , 2.0, 37.683816318260355,  2.858760367632973,  8.092094813253975e-2, 1.4479636296208662
--    , 3.0,    9.5807893736187,  4.948995119561291,   0.11942927999921617, 1.0945766509238248
--    , 4.0,  5.630494933603935,  5.021755718065913,   0.10287787128056883, 1.0338835440862608
--    , 5.0,  5.443976278682909,  5.045204331329302,   0.10405523433131504,  1.019416067207375
--    , 6.0, 5.4439736648994685,  5.045357818922331,   0.10404905846029407, 1.0192487112786812 ]
--   &gt; sol
--   [(5.045357818922331,6.027976702418132e-2),
--   (0.10404905846029407,3.157045047172834e-3),
--   (1.0192487112786812,3.782067731353722e-2)]
--   </pre>
module Numeric.GSL.Fitting

-- | Nonlinear multidimensional least-squares fitting.
nlFitting :: FittingMethod -> Double -> Double -> Int -> (Vector Double -> Vector Double) -> (Vector Double -> Matrix Double) -> Vector Double -> (Vector Double, Matrix Double)
data FittingMethod

-- | Interface to gsl_multifit_fdfsolver_lmsder. This is a robust and
--   efficient version of the Levenberg-Marquardt algorithm as implemented
--   in the scaled lmder routine in minpack. Minpack was written by Jorge
--   J. More, Burton S. Garbow and Kenneth E. Hillstrom.
LevenbergMarquardtScaled :: FittingMethod

-- | This is an unscaled version of the lmder algorithm. The elements of
--   the diagonal scaling matrix D are set to 1. This algorithm may be
--   useful in circumstances where the scaled version of lmder converges
--   too slowly, or the function is already scaled appropriately.
LevenbergMarquardt :: FittingMethod

-- | Higher level interface to <a>nlFitting</a>
--   <a>LevenbergMarquardtScaled</a>. The optimization function and
--   Jacobian are automatically built from a model f vs x = y and its
--   derivatives, and a list of instances (x, (y,sigma)) to be fitted.
fitModelScaled :: Double -> Double -> Int -> ([Double] -> x -> [Double], [Double] -> x -> [[Double]]) -> [(x, ([Double], Double))] -> [Double] -> ([(Double, Double)], Matrix Double)

-- | Higher level interface to <a>nlFitting</a> <a>LevenbergMarquardt</a>.
--   The optimization function and Jacobian are automatically built from a
--   model f vs x = y and its derivatives, and a list of instances (x,y) to
--   be fitted.
fitModel :: Double -> Double -> Int -> ([Double] -> x -> [Double], [Double] -> x -> [[Double]]) -> [(x, [Double])] -> [Double] -> ([Double], Matrix Double)
instance Enum FittingMethod
instance Eq FittingMethod
instance Show FittingMethod
instance Bounded FittingMethod


-- | This module reexports all available GSL functions.
--   
--   The GSL special functions are in the separate package hmatrix-special.
module Numeric.GSL

-- | This action removes the GSL default error handler (which aborts the
--   program), so that GSL errors can be handled by Haskell (using
--   Control.Exception) and ghci doesn't abort.
setErrorHandlerOff :: IO ()


module Numeric.LinearAlgebra.Util

-- | (rows &amp;&amp;&amp; cols)
size :: Matrix t -> (Int, Int)

-- | show a matrix with given number of digits after the decimal point
disp :: Int -> Matrix Double -> IO ()

-- | a real matrix of zeros
zeros :: Int -> Int -> Matrix Double

-- | a real matrix of ones
ones :: Int -> Int -> Matrix Double

-- | create a real diagonal matrix from a list
diagl :: [Double] -> Matrix Double

-- | create a single row real matrix from a list
row :: [Double] -> Matrix Double

-- | create a single column real matrix from a list
col :: [Double] -> Matrix Double

-- | concatenation of real vectors
(&) :: Vector Double -> Vector Double -> Vector Double

-- | horizontal concatenation of real matrices
(!) :: Matrix Double -> Matrix Double -> Matrix Double

-- | (00A6) horizontal concatenation of real matrices
(¦) :: Matrix Double -> Matrix Double -> Matrix Double

-- | vertical concatenation of real matrices
(#) :: Matrix Double -> Matrix Double -> Matrix Double

-- | extract selected rows
(?) :: Element t => Matrix t -> [Int] -> Matrix t

-- | (00BF) extract selected columns
(¿) :: Element t => Matrix t -> [Int] -> Matrix t

-- | pseudorandom matrix with uniform elements between 0 and 1
rand :: Int -> Int -> IO (Matrix Double)

-- | pseudorandom matrix with normal elements
randn :: Int -> Int -> IO (Matrix Double)

-- | cross product (for three-element real vectors)
cross :: Vector Double -> Vector Double -> Vector Double

-- | 2-norm of real vector
norm :: Vector Double -> Double

-- | Obtains a vector in the same direction with 2-norm=1
unitary :: Vector Double -> Vector Double

-- | trans . inv
mt :: Matrix Double -> Matrix Double

-- | Matrix of pairwise squared distances of row vectors (using the matrix
--   product trick in blog.smola.org)
pairwiseD2 :: Matrix Double -> Matrix Double -> Matrix Double

-- | outer products of rows
rowOuters :: Matrix Double -> Matrix Double -> Matrix Double

-- | solution of overconstrained homogeneous linear system
null1 :: Matrix Double -> Vector Double

-- | solution of overconstrained homogeneous symmetric linear system
null1sym :: Matrix Double -> Vector Double

-- | correlation
--   
--   <pre>
--   &gt;&gt;&gt; corr (fromList[1,2,3]) (fromList [1..10])
--   fromList [14.0,20.0,26.0,32.0,38.0,44.0,50.0,56.0]
--   </pre>
corr :: Product t => Vector t -> Vector t -> Vector t

-- | convolution (<a>corr</a> with reversed kernel and padded input,
--   equivalent to polynomial product)
--   
--   <pre>
--   &gt;&gt;&gt; conv (fromList[1,1]) (fromList [-1,1])
--   fromList [-1.0,0.0,1.0]
--   </pre>
conv :: (Product t, Num t) => Vector t -> Vector t -> Vector t

-- | similar to <a>corr</a>, using <a>min</a> instead of (*)
corrMin :: (Container Vector t, RealElement t, Product t) => Vector t -> Vector t -> Vector t

-- | 2D correlation
corr2 :: Product a => Matrix a -> Matrix a -> Matrix a

-- | 2D convolution
conv2 :: (Num a, Product a) => Matrix a -> Matrix a -> Matrix a

-- | matrix computation implemented as separated vector operations by rows
--   and columns.
separable :: Element t => (Vector t -> Vector t) -> Matrix t -> Matrix t

-- | stacking of columns
vec :: Element t => Matrix t -> Vector t

-- | half-vectorization (of the lower triangular part)
vech :: Element t => Matrix t -> Vector t

-- | duplication matrix (<tt><a>dup</a> k &lt;&gt; <a>vech</a> m ==
--   <a>vec</a> m</tt>, for symmetric m of <a>dim</a> k)
dup :: (Num t, Num (Vector t), Element t) => Int -> Matrix t

-- | generalized "vector" transposition: <tt><a>vtrans</a> 1 ==
--   <a>trans</a></tt>, and <tt><a>vtrans</a> (<a>rows</a> m) m ==
--   <a>asColumn</a> (<a>vec</a> m)</tt>
vtrans :: Element t => Int -> Matrix t -> Matrix t


-- | This module is deprecated. It can be replaced by improved drawing
--   tools available in the plot\plot-gtk packages by Vivian McPhail or
--   Gnuplot by Henning Thielemann.
module Graphics.Plot

-- | plots several vectors against the first one
--   
--   <pre>
--   &gt; let t = linspace 100 (-3,3) in mplot [t, sin t, exp (-t^2)]
--   </pre>
mplot :: [Vector Double] -> IO ()

-- | Draws a list of functions over a desired range and with a desired
--   number of points
--   
--   <pre>
--   &gt; plot [sin, cos, sin.(3*)] (0,2*pi) 1000
--   </pre>
plot :: [Vector Double -> Vector Double] -> (Double, Double) -> Int -> IO ()

-- | Draws a parametric curve. For instance, to draw a spiral we can do
--   something like:
--   
--   <pre>
--   &gt; parametricPlot (\t-&gt;(t * sin t, t * cos t)) (0,10*pi) 1000
--   </pre>
parametricPlot :: (Vector Double -> (Vector Double, Vector Double)) -> (Double, Double) -> Int -> IO ()

-- | Draws the surface represented by the function f in the desired ranges
--   and number of points, internally using <a>mesh</a>.
--   
--   <pre>
--   &gt; let f x y = cos (x + y) 
--   &gt; splot f (0,pi) (0,2*pi) 50    
--   </pre>
splot :: (Matrix Double -> Matrix Double -> Matrix Double) -> (Double, Double) -> (Double, Double) -> Int -> IO ()

-- | Draws a 3D surface representation of a real matrix.
--   
--   <pre>
--   &gt; mesh $ build (10,10) (\\i j -&gt; i + (j-5)^2)
--   </pre>
--   
--   In certain versions you can interactively rotate the graphic using the
--   mouse.
mesh :: Matrix Double -> IO ()

-- | From vectors x and y, it generates a pair of matrices to be used as x
--   and y arguments for matrix functions.
meshdom :: Vector Double -> Vector Double -> (Matrix Double, Matrix Double)

-- | writes a matrix to pgm image file
matrixToPGM :: Matrix Double -> String

-- | imshow shows a representation of a matrix as a gray level image using
--   ImageMagick's display.
imshow :: Matrix Double -> IO ()
gnuplotX :: String -> IO ()
gnuplotpdf :: String -> String -> [([[Double]], String)] -> IO ()
gnuplotWin :: String -> String -> [([[Double]], String)] -> IO ()
