|
Data.Packed.Static.Vector | Portability | portable | Stability | experimental | Maintainer | Reiner Pope <reiner.pope@gmail.com> |
|
|
|
|
|
Description |
Statically-dimensioned 1D vectors.
|
|
Synopsis |
|
|
|
Documentation |
|
|
A vector with elements of type t and length n.
The type n encodes the vector's length, and will
usually either be Unknown or will satisfy PositiveT.
Operations which return vectors of length Unknown
will return vectors whose lengths are determined
at runtime. All operations which mention Unknown
lengths will have names ending in an uppercase U,
for example fromListU, subVectorU.
The use of Unknown facilitates manipulation
of dynamically-lengthed vectors without
using continuations for each operation, since
most operations work equally well for lengthed
as well as unlengthed vectors. When vectors
of Unknown length are used, runtime length
mismatches may arise, and the system is as safe
as hmatrix.
When the length of every vector is known, if
the code typechecks, then there will be
no runtime vector length mismatches. Equivalently,
there will be no runtime vector length mismatches
if:
- no unsafe functions are used; and
- no functions mentioning Unknown are used, i.e. no functions with suffix U are used.
| Instances | |
|
|
Shaping
|
|
Functions manipulating a vector's (static) shape.
|
|
|
"Reifies" a Vector's length in types. Useful when vectors of length Unknown
need to be used for a statically-sized operations. For instance, if v :: Vector Unknown Double,
then we can write
refineVec v (v -> forgetSize $ v + constant 5) to add a constant vector of 5s with the appropriate size.
|
|
|
Sets an arbitrary-length vector to a specific value.
> constant 1 atDim 5
[$vec| 1.0, 1.0, 1.0, 1.0, 1.0 |] |
|
atShape :: a s t -> s -> a s t | Source |
|
For type hints.
> constant (5::Double) atShape d4
[$vec| 5.0, 5.0, 5.0, 5.0 |] :: Vector D4 Double Implementation:
atShape = const.
|
|
To/from lists
|
|
|
Constructs a vector from all the elements of a list.
> fromListU [1,2,3,4,5]
[$vec| 1.0, 2.0, 3.0, 4.0, 5.0 |] |
|
|
Converts to a list of elements.
> toList [$vec|1,2,3|]
[1.0,2.0,3.0] |
|
Manipulation
|
|
|
Vector's length.
> dim [$vec|1::Double,2,3|]
3 |
|
|
Indexes a vector.
> [$vec|1,2,3|] @> 1
2.0 |
|
|
:: Storable t | | => Int | Initial index
| -> Int | Length of resultant vector
| -> Vector n t | | -> Vector Unknown t | | Extracts a subvector.
> subVectorU 2 3 [$vec|1,2,3,4,5|]
[$vec| 3.0, 4.0, 5.0 |] |
|
|
|
Joins each vector in the list.
> joinU [[$vecU|1,2,3|], [$vecU|4,5|]]
[$vec| 1.0, 2.0, 3.0, 4.0, 5.0 |] |
|
|
Creates a constant vector of any length. The length is
determined by the type.
> [$vec|1,2,3|] + constant 2
[$vec| 3.0, 4.0, 5.0 |] |
|
|
Creates a vector of arbitrary length whose
components range linearly from a to b. The vector's
length is determined by its type.
> linspace (1,5) atShape d4
[$vec| 1.0, 2.333333333333333, 3.6666666666666665, 5.0 |] |
|
|
Gives the vector's minimum entry.
> vectorMin [$vec|1,2,3|]
1.0 |
|
|
Gives the vector's maximum entry.
> vectorMax [$vec|1,2,3|]
3.0 |
|
|
Gives the index of a vector's minimum entry.
> vectorMinIndex [$vec|1,2,3|]
0
|
|
|
Gives the index of a vector's maximum entry.
> vectorMaxIndex [$vec|1,2,3|]
2 |
|
|
map for vectors.
> (*2) liftVector [$vec|1,2,3|]
[$vec| 2.0, 4.0, 6.0 |] |
|
|
zipWith for vectors.
> liftVector2 (+) [$vec|1,2,3|] (constant 3)
[$vec| 4.0, 5.0, 6.0 |] |
|
Produced by Haddock version 2.4.2 |