| Portability | portable |
|---|---|
| Stability | provisional |
| Maintainer | Edward Kmett <ekmett@gmail.com> |
| Safe Haskell | Trustworthy |
Linear.Vector
Description
Operations on free vector spaces.
- class Functor f => Additive f where
- newtype E t = E {}
- negated :: (Functor f, Num a) => f a -> f a
- (^*) :: (Functor f, Num a) => f a -> a -> f a
- (*^) :: (Functor f, Num a) => a -> f a -> f a
- (^/) :: (Functor f, Fractional a) => f a -> a -> f a
- sumV :: (Foldable f, Additive v, Num a) => f (v a) -> v a
- basis :: (Applicative t, Traversable t, Num a) => [t a]
- basisFor :: (Traversable t, Num a) => t b -> [t a]
- kronecker :: (Traversable t, Num a) => t a -> t (t a)
- outer :: (Functor f, Functor g, Num a) => f a -> g a -> f (g a)
- unit :: (Applicative t, Num a) => Lens' (t a) a -> t a
Documentation
class Functor f => Additive f whereSource
A vector is an additive group with additional structure.
Methods
The zero vector
(^+^) :: Num a => f a -> f a -> f aSource
Compute the sum of two vectors
>>>V2 1 2 ^+^ V2 3 4V2 4 6
(^-^) :: Num a => f a -> f a -> f aSource
Compute the difference between two vectors
>>>V2 4 5 - V2 3 1V2 1 4
lerp :: Num a => a -> f a -> f a -> f aSource
Linearly interpolate between two vectors.
liftU2 :: (a -> a -> a) -> f a -> f a -> f aSource
Apply a function to merge the 'non-zero' components of two vectors, unioning the rest of the values.
liftI2 :: (a -> b -> c) -> f a -> f b -> f cSource
Apply a function to the components of two vectors.
- For a dense vector this is equivalent to
liftA2. - For a sparse vector this is equivalent to
intersectionWith.
Instances
| Additive [] | |
| Additive Maybe | |
| Additive Complex | |
| Additive ZipList | |
| Additive Identity | |
| Additive IntMap | |
| Additive Vector | |
| Additive V0 | |
| Additive V1 | |
| Additive V2 | |
| Additive V3 | |
| Additive V4 | |
| Additive Plucker | |
| Additive Quaternion | |
| Additive ((->) b) | |
| (Eq k, Hashable k) => Additive (HashMap k) | |
| Ord k => Additive (Map k) | |
| Dim n => Additive (V n) | |
| Additive f => Additive (Point f) |
Basis element
Instances
negated :: (Functor f, Num a) => f a -> f aSource
Compute the negation of a vector
>>>negated (V2 2 4)V2 (-2) (-4)
(^*) :: (Functor f, Num a) => f a -> a -> f aSource
Compute the right scalar product
>>>V2 3 4 ^* 2V2 6 8
(*^) :: (Functor f, Num a) => a -> f a -> f aSource
Compute the left scalar product
>>>2 *^ V2 3 4V2 6 8
(^/) :: (Functor f, Fractional a) => f a -> a -> f aSource
Compute division by a scalar on the right.
sumV :: (Foldable f, Additive v, Num a) => f (v a) -> v aSource
Sum over multiple vectors
>>>sumV [V2 1 1, V2 3 4]V2 4 5
basis :: (Applicative t, Traversable t, Num a) => [t a]Source
Produce a default basis for a vector space. If the dimensionality
of the vector space is not statically known, see basisFor.
basisFor :: (Traversable t, Num a) => t b -> [t a]Source
Produce a default basis for a vector space from which the argument is drawn.
kronecker :: (Traversable t, Num a) => t a -> t (t a)Source
Produce a diagonal matrix from a vector.
outer :: (Functor f, Functor g, Num a) => f a -> g a -> f (g a)Source
Outer (tensor) product of two vectors
unit :: (Applicative t, Num a) => Lens' (t a) a -> t aSource
Create a unit vector.
>>>unit _x :: V2 IntV2 1 0