Copyright | (c) Justin Le 2019 |
---|---|
License | BSD3 |
Maintainer | justin@jle.im |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
A unified interface for values in vector spaces that can be added and scaled (purely and also in-place), and measured.
Synopsis
- class Num c => Linear c a | a -> c where
- sumLinear :: (Linear c a, Foldable t) => t a -> a
- gAdd :: forall c a. (ADTRecord a, Constraints a (Linear c)) => a -> a -> a
- gZeroL :: forall c a. (ADTRecord a, Constraints a (Linear c)) => a
- gScale :: forall c a. (ADTRecord a, Constraints a (Linear c)) => c -> a -> a
- class Linear c a => Metric c a where
- gDot :: forall c a. (ADT a, Constraints a (Metric c), Num c) => a -> a -> c
- gNorm_inf :: forall c a. (ADT a, Constraints a (Metric c), Ord c) => a -> c
- gNorm_0 :: forall c a. (ADT a, Constraints a (Metric c), Num c) => a -> c
- gNorm_1 :: forall c a. (ADT a, Constraints a (Metric c), Num c) => a -> c
- gNorm_2 :: forall c a. (ADT a, Constraints a (Metric c), Floating c) => a -> c
- gQuadrance :: forall c a. (ADT a, Constraints a (Metric c), Num c) => a -> c
- class (Mutable m a, Linear c a) => LinearInPlace m c a where
- sumLinearInPlace :: (LinearInPlace m c a, Foldable t) => Ref m a -> t a -> m ()
- linearWit :: forall a c d. (Linear c a, Linear d a) => c :~: d
Documentation
class Num c => Linear c a | a -> c where Source #
If a
is an instance of
, you can add together values
of Linear
ca
, and scale them using c
s.
For example, if you have a vector of doubles, you can add them together component-wise, and scale them by multiplying every item by the scalar.
Mathematically, this means that a
forms something like a module or
vector space over c
, where c
can be any Num
instance.
Nothing
(.+.) :: a -> a -> a infixl 6 Source #
Add together a
s. Should be associative.
x .+. (y .+. z) == (x .+. y) .+. z
The "zero" a
, meant to form an identity with .+.
.
x .+. zeroL == x zeroL .+. y == y
If a
is an instance of Num
, this can be just 0.
(.*) :: c -> a -> a infixl 7 Source #
Scale an a
by a factor c
. Should distribute over .+.
.
a .* (x .+. y) == (a .* x) .+. (a .* y) a .* (b .* c) == (a * b) .* c
(.+.) :: (ADTRecord a, Constraints a (Linear c)) => a -> a -> a infixl 6 Source #
Add together a
s. Should be associative.
x .+. (y .+. z) == (x .+. y) .+. z
zeroL :: (ADTRecord a, Constraints a (Linear c)) => a Source #
The "zero" a
, meant to form an identity with .+.
.
x .+. zeroL == x zeroL .+. y == y
If a
is an instance of Num
, this can be just 0.
(.*) :: (ADTRecord a, Constraints a (Linear c)) => c -> a -> a infixl 7 Source #
Scale an a
by a factor c
. Should distribute over .+.
.
a .* (x .+. y) == (a .* x) .+. (a .* y) a .* (b .* c) == (a * b) .* c
Instances
Linear Double Double Source # | |
Linear Float Float Source # | |
Linear Int Int Source # | |
Linear Integer Integer Source # | |
KnownNat n => Linear Double (R n) Source # | |
Linear Rational (Ratio Integer) Source # | |
(KnownNat n, KnownNat m) => Linear Double (L n m) Source # | |
(Linear c a, Linear c b) => Linear c (a, b) Source # | |
(Linear c (f a), Linear c (Rec f (b ': bs))) => Linear c (Rec f (a ': (b ': bs))) Source # | |
Linear c (f a) => Linear c (Rec f (a ': ([] :: [Type]))) Source # | |
(Linear c a, Linear c b, Linear c d) => Linear c (a, b, d) Source # | |
(Num a, Vector v a, KnownNat n) => Linear a (Vector v n a) Source # | |
(Linear c a, Linear c b, Linear c d, Linear c e) => Linear c (a, b, d, e) Source # | |
(Linear c a, Linear c b, Linear c d, Linear c e, Linear c f) => Linear c (a, b, d, e, f) Source # | |
RealFloat a => Linear (Complex a) (Complex a) Source # | |
class Linear c a => Metric c a where Source #
Class for values supporting an inner product and various norms.
Nothing
(<.>) :: a -> a -> c infixl 7 Source #
Sum of component-wise product
Maximum absolute component. Is undefined if no components exist.
Number of non-zero components
Sum of absolute components
Square root of sum of squared components
Sum of squared components
(<.>) :: (ADT a, Constraints a (Metric c)) => a -> a -> c infixl 7 Source #
Sum of component-wise product
norm_inf :: (ADT a, Constraints a (Metric c), Ord c) => a -> c Source #
Maximum absolute component. Is undefined if no components exist.
norm_0 :: (ADT a, Constraints a (Metric c)) => a -> c Source #
Number of non-zero components
norm_1 :: (ADT a, Constraints a (Metric c)) => a -> c Source #
Sum of absolute components
norm_2 :: Floating c => a -> c Source #
Square root of sum of squared components
quadrance :: (ADT a, Constraints a (Metric c)) => a -> c Source #
Sum of squared components
Instances
Metric Double Double Source # | |
Metric Float Float Source # | |
Metric Int Int Source # | |
Metric Integer Integer Source # | |
KnownNat n => Metric Double (R n) Source # | |
Metric Rational (Ratio Integer) Source # | |
Defined in Numeric.Opto.Update | |
(KnownNat n, KnownNat m) => Metric Double (L n m) Source # | |
(Metric c a, Metric c b, Ord c, Floating c) => Metric c (a, b) Source # | |
(Floating c, Ord c, Metric c (f a), Metric c (Rec f (b ': bs))) => Metric c (Rec f (a ': (b ': bs))) Source # | |
Metric c (f a) => Metric c (Rec f (a ': ([] :: [Type]))) Source # | |
(Metric c a, Metric c b, Metric c d, Ord c, Floating c) => Metric c (a, b, d) Source # | |
(Floating a, Ord a, Vector v a, KnownNat n) => Metric a (Vector v n a) Source # | |
(Metric c a, Metric c b, Metric c d, Metric c e, Ord c, Floating c) => Metric c (a, b, d, e) Source # | |
(Metric c a, Metric c b, Metric c d, Metric c e, Metric c f, Ord c, Floating c) => Metric c (a, b, d, e, f) Source # | |
RealFloat a => Metric (Complex a) (Complex a) Source # | |
gQuadrance :: forall c a. (ADT a, Constraints a (Metric c), Num c) => a -> c Source #
class (Mutable m a, Linear c a) => LinearInPlace m c a where Source #
Instaces of Linear
that support certain in-place mutations.
Inspired by the BLAS Level 1 API. A
means
that LinearInPlace
m v c av
is a mutable reference to an a
that can be updated as an
action in monad m
.
Nothing
(.+.=) :: Ref m a -> a -> m () infix 4 Source #
Add a value in-place.
(.*=) :: Ref m a -> c -> m () infix 4 Source #
Scale a value in-place.
(.*+=) :: Ref m a -> (c, a) -> m () infix 4 Source #
Add a scaled value in-place.
Instances
sumLinearInPlace :: (LinearInPlace m c a, Foldable t) => Ref m a -> t a -> m () Source #
Given some starting reference v
, add every item in a foldable
container into that reference in-place.