hmatrix-0.9.3.0: Linear algebra and numerical computationSource codeContentsIndex
Data.Packed.Vector
Portabilityportable
Stabilityprovisional
MaintainerAlberto Ruiz <aruiz@um.es>
Description
1D arrays suitable for numeric computations using external libraries.
Synopsis
data Vector t
fromList :: Storable a => [a] -> Vector a
(|>) :: Storable a => Int -> [a] -> Vector a
toList :: Storable a => Vector a -> [a]
buildVector :: Element a => Int -> (Int -> a) -> Vector a
dim :: Storable t => Vector t -> Int
(@>) :: Storable t => Vector t -> Int -> t
subVector :: Storable t => Int -> Int -> Vector t -> Vector t
takesV :: Storable t => [Int] -> Vector t -> [Vector t]
join :: Storable t => [Vector t] -> Vector t
constant :: Element a => a -> Int -> Vector a
linspace :: Int -> (Double, Double) -> Vector Double
vecdisp :: Element t => (Matrix t -> String) -> Vector t -> String
vectorMax :: Vector Double -> Double
vectorMin :: Vector Double -> Double
vectorMaxIndex :: Vector Double -> Int
vectorMinIndex :: Vector Double -> Int
mapVector :: (Storable a, Storable b) => (a -> b) -> Vector a -> Vector b
zipVector :: (Storable a, Storable b, Storable c) => (a -> b -> c) -> Vector a -> Vector b -> Vector c
fscanfVector :: FilePath -> Int -> IO (Vector Double)
fprintfVector :: FilePath -> String -> Vector Double -> IO ()
freadVector :: FilePath -> Int -> IO (Vector Double)
fwriteVector :: FilePath -> Vector Double -> IO ()
foldLoop :: (Int -> t -> t) -> t -> Int -> t
foldVector :: (Double -> b -> b) -> b -> Vector Double -> b
foldVectorG :: Storable a => (Int -> (Int -> a) -> t -> t) -> t -> Vector a -> t
Documentation
data Vector t Source
One-dimensional array of objects stored in a contiguous memory block.
show/hide Instances
fromList :: Storable a => [a] -> Vector aSource

creates a Vector from a list:

> fromList [2,3,5,7]
4 |> [2.0,3.0,5.0,7.0]
(|>) :: Storable a => Int -> [a] -> Vector aSource

An alternative to fromList 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).

toList :: Storable a => Vector a -> [a]Source

extracts the Vector elements to a list

> toList (linspace 5 (1,10))
[1.0,3.25,5.5,7.75,10.0]
buildVector :: Element a => Int -> (Int -> a) -> Vector aSource

creates a Vector of the specified length using the supplied function to to map the index to the value at that index.

> buildVector 4 fromIntegral
4 |> [0.0,1.0,2.0,3.0]
dim :: Storable t => Vector t -> IntSource
Number of elements
(@>) :: Storable t => Vector t -> Int -> tSource

Reads a vector position:

> fromList [0..9] @> 7
7.0
subVectorSource
:: Storable t
=> Intindex of the starting element
-> Intnumber of elements to extract
-> Vector tsource
-> Vector tresult

takes a number of consecutive elements from a Vector

> subVector 2 3 (fromList [1..10])
3 |> [3.0,4.0,5.0]
takesV :: Storable t => [Int] -> Vector t -> [Vector t]Source

Extract consecutive subvectors of the given sizes.

> takesV [3,4] (linspace 10 (1,10))
[3 |> [1.0,2.0,3.0],4 |> [4.0,5.0,6.0,7.0]]
join :: Storable t => [Vector t] -> Vector tSource

creates a new Vector by joining a list of Vectors

> join [fromList [1..5], constant 1 3]
8 |> [1.0,2.0,3.0,4.0,5.0,1.0,1.0,1.0]
constant :: Element a => a -> Int -> Vector aSource

creates a vector with a given number of equal components:

> constant 2 7
7 |> [2.0,2.0,2.0,2.0,2.0,2.0,2.0]
linspace :: Int -> (Double, Double) -> Vector DoubleSource

Creates a real vector containing a range of values:

> linspace 5 (-3,7)
5 |> [-3.0,-0.5,2.0,4.5,7.0]

Logarithmic spacing can be defined as follows:

logspace n (a,b) = 10 ** linspace n (a,b)
vecdisp :: Element t => (Matrix t -> String) -> Vector t -> StringSource

Show a vector using a function for showing matrices.

disp = putStr . vecdisp (dispf 2)

> disp (linspace 10 (0,1))
10 |> 0.00  0.11  0.22  0.33  0.44  0.56  0.67  0.78  0.89  1.00
vectorMax :: Vector Double -> DoubleSource
vectorMin :: Vector Double -> DoubleSource
vectorMaxIndex :: Vector Double -> IntSource
vectorMinIndex :: Vector Double -> IntSource
mapVector :: (Storable a, Storable b) => (a -> b) -> Vector a -> Vector bSource
map on Vectors
zipVector :: (Storable a, Storable b, Storable c) => (a -> b -> c) -> Vector a -> Vector b -> Vector cSource
zipWith for Vectors
fscanfVector :: FilePath -> Int -> IO (Vector Double)Source
Loads a vector from an ASCII file (the number of elements must be known in advance).
fprintfVector :: FilePath -> String -> Vector Double -> IO ()Source
Saves the elements of a vector, with a given format (%f, %e, %g), to an ASCII file.
freadVector :: FilePath -> Int -> IO (Vector Double)Source
Loads a vector from a binary file (the number of elements must be known in advance).
fwriteVector :: FilePath -> Vector Double -> IO ()Source
Saves the elements of a vector to a binary file.
foldLoop :: (Int -> t -> t) -> t -> Int -> tSource
foldVector :: (Double -> b -> b) -> b -> Vector Double -> bSource
foldVectorG :: Storable a => (Int -> (Int -> a) -> t -> t) -> t -> Vector a -> tSource
Produced by Haddock version 2.6.1