{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE UnicodeSyntax #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE TypeApplications #-}
module Math.LinearMap.Category.Instances where
import Math.VectorSpace.DimensionAware
import Math.LinearMap.Category.Class
import Data.VectorSpace
import Data.Basis
#if MIN_VERSION_manifolds_core(0,6,0)
import Math.Manifold.Core.Types (EmptyMfd)
#endif
import Math.Manifold.Core.PseudoAffine
import Prelude ()
import qualified Prelude as Hask
import Control.Category.Constrained.Prelude
import Control.Arrow.Constrained
import Data.Coerce
import Data.Type.Coercion
import Data.Tagged
import Data.Proxy
import Data.Foldable (foldl')
import Data.VectorSpace.Free
import Data.VectorSpace.Free.FiniteSupportedSequence
import Data.VectorSpace.Free.Sequence as Seq
import qualified Linear.Matrix as Mat
import qualified Linear.Vector as Mat
import qualified Linear.Metric as Mat
import Linear ( V0(V0), V1(V1), V2(V2), V3(V3), V4(V4)
, _x, _y, _z, _w )
import Control.Lens ((^.))
import Control.Monad.ST (ST)
import qualified Data.Vector as Arr
import qualified Data.Vector.Unboxed as UArr
import qualified Data.Vector.Generic as GArr
import Math.LinearMap.Asserted
import Math.VectorSpace.ZeroDimensional
import qualified Math.VectorSpace.DimensionAware.Theorems.MaybeNat as Maybe
import qualified Test.QuickCheck as QC
import GHC.TypeNats (natVal)
import qualified GHC.Exts as GHC
import qualified GHC.Generics as GHC
import Data.Singletons (SingI, sing, Sing)
#if MIN_VERSION_singletons(3,0,0)
import GHC.TypeLits.Singletons (withKnownNat)
#else
import Data.Singletons.TypeLits (withKnownNat)
#endif
#if MIN_VERSION_manifolds_core(0,6,0)
instance LinearSpace v => Semimanifold (EmptyMfd v) where
type Needle (EmptyMfd v) = v
EmptyMfd v
p .+~^ :: EmptyMfd v -> Needle (EmptyMfd v) -> EmptyMfd v
.+~^ Needle (EmptyMfd v)
_ = case EmptyMfd v
p of {}
EmptyMfd v
p .-~^ :: EmptyMfd v -> Needle (EmptyMfd v) -> EmptyMfd v
.-~^ Needle (EmptyMfd v)
_ = case EmptyMfd v
p of {}
semimanifoldWitness :: SemimanifoldWitness (EmptyMfd v)
semimanifoldWitness = case forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness @v of
LinearManifoldWitness v
LinearManifoldWitness -> forall x.
(Semimanifold (Needle x), Needle (Needle x) ~ Needle x) =>
SemimanifoldWitness x
SemimanifoldWitness
instance LinearSpace v => PseudoAffine (EmptyMfd v) where
EmptyMfd v
p .-~. :: EmptyMfd v -> EmptyMfd v -> Maybe (Needle (EmptyMfd v))
.-~. EmptyMfd v
_ = case EmptyMfd v
p of {}
EmptyMfd v
p .-~! :: HasCallStack => EmptyMfd v -> EmptyMfd v -> Needle (EmptyMfd v)
.-~! EmptyMfd v
_ = case EmptyMfd v
p of {}
#endif
infixr 7 <.>^
(<.>^) :: LinearSpace v => DualVector v -> v -> Scalar v
DualVector v
f<.>^ :: forall v. LinearSpace v => DualVector v -> v -> Scalar v
<.>^v
v = (forall v.
(LinearSpace v, LinearSpace v) =>
Bilinear (DualVector v) v (Scalar v)
applyDualVectorforall s v w. LinearFunction s v w -> v -> w
-+$>DualVector v
f)forall s v w. LinearFunction s v w -> v -> w
-+$>v
v
type ℝ = Double
autoLinearManifoldWitness :: (Semimanifold v, AffineSpace v, v ~ Needle v, v ~ Diff v
#if !MIN_VERSION_manifolds_core(0,6,0)
, v ~ Interior v
#endif
)
=> LinearManifoldWitness v
autoLinearManifoldWitness :: forall v.
(Semimanifold v, AffineSpace v, v ~ Needle v, v ~ Diff v) =>
LinearManifoldWitness v
autoLinearManifoldWitness = forall v.
(Needle v ~ v, AffineSpace v, Diff v ~ v) =>
LinearManifoldWitness v
LinearManifoldWitness
#if !MIN_VERSION_manifolds_core(0,6,0)
BoundarylessWitness
#endif
#define LinearScalarSpace(S) \
instance Num' (S) where {closedScalarWitness = ClosedScalarWitness}; \
instance TensorSpace (S) where { \
type TensorProduct (S) w = w; \
scalarSpaceWitness = ScalarSpaceWitness; \
linearManifoldWitness = autoLinearManifoldWitness; \
zeroTensor = Tensor zeroV; \
scaleTensor = bilinearFunction $ \μ (Tensor t) -> Tensor $ μ*^t; \
addTensors (Tensor v) (Tensor w) = Tensor $ v ^+^ w; \
subtractTensors (Tensor v) (Tensor w) = Tensor $ v ^-^ w; \
negateTensor = LinearFunction $ \(Tensor v) -> Tensor (negateV v); \
toFlatTensor = LinearFunction $ follow Tensor; \
fromFlatTensor = LinearFunction $ flout Tensor; \
tensorProduct = bilinearFunction $ \μ \
-> follow Tensor . getLinearFunction (scaleWith μ); \
transposeTensor = toFlatTensor . LinearFunction (flout Tensor); \
fmapTensor = bilinearFunction $ \f (Tensor t) -> Tensor (f-+$>t); \
fzipTensorWith = bilinearFunction \
$ \(LinearFunction f) -> follow Tensor <<< f <<< flout Tensor *** flout Tensor; \
tensorUnsafeFromArrayWithOffset i ar \
= Tensor (unsafeFromArrayWithOffset i ar); \
tensorUnsafeWriteArrayWithOffset ar i (Tensor v) \
= unsafeWriteArrayWithOffset ar i v; \
coerceFmapTensorProduct _ VSCCoercion = Coercion; \
wellDefinedTensor (Tensor w) = Tensor <$> wellDefinedVector w }; \
instance LinearSpace (S) where { \
type DualVector (S) = (S); \
dualSpaceWitness = DualSpaceWitness; \
linearId = LinearMap 1; \
tensorId = uncurryLinearMap $ LinearMap $ fmap (LinearFunction $ follow Tensor) -+$> id; \
idTensor = Tensor 1; \
fromLinearForm = LinearFunction $ flout LinearMap; \
coerceDoubleDual = VSCCoercion; \
contractTensorMap = LinearFunction $ flout Tensor . flout LinearMap; \
contractMapTensor = LinearFunction $ flout LinearMap . flout Tensor; \
applyDualVector = scale; \
applyLinear = LinearFunction $ \(LinearMap w) -> scaleV w; \
applyTensorFunctional = bilinearFunction $ \(LinearMap du) (Tensor u) -> du<.>^u; \
applyTensorLinMap = bilinearFunction $ \fℝuw (Tensor u) \
-> let LinearMap fuw = curryLinearMap $ fℝuw \
in (applyLinear-+$>fuw) -+$> u; \
composeLinear = bilinearFunction $ \f (LinearMap g) \
-> LinearMap $ (applyLinear-+$>f)-+$>g; \
useTupleLinearSpaceComponents _ = usingNonTupleTypeAsTupleError }
LinearScalarSpace(ℝ)
LinearScalarSpace(Float)
LinearScalarSpace(Rational)
{-# INLINE tensorUnsafeFromArrayWithOffsetViaList #-}
tensorUnsafeFromArrayWithOffsetViaList
:: ∀ v w n m α . ( n`Dimensional`v
, m`Dimensional`w
, Scalar v ~ Scalar w
, GArr.Vector α (Scalar v) )
=> ([w] -> TensorProduct v w) -> Int -> α (Scalar v) -> (v⊗w)
tensorUnsafeFromArrayWithOffsetViaList :: forall v w (n :: Nat) (m :: Nat) (α :: * -> *).
(Dimensional n v, Dimensional m w, Scalar v ~ Scalar w,
Vector α (Scalar v)) =>
([w] -> TensorProduct v w) -> Int -> α (Scalar v) -> v ⊗ w
tensorUnsafeFromArrayWithOffsetViaList [w] -> TensorProduct v w
l2v Int
i α (Scalar v)
ar
= forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ [w] -> TensorProduct v w
l2v [ forall (n :: Nat) v (α :: * -> *).
(Dimensional n v, Vector α (Scalar v)) =>
Int -> α (Scalar v) -> v
unsafeFromArrayWithOffset
(Int
i forall a. Num a => a -> a -> a
+ Int
j forall a. Num a => a -> a -> a
* forall v (n :: Nat) a. (Dimensional n v, Integral a) => a
dimension @w) α (Scalar v)
ar
| Int
j <- [Int
0 .. forall v (n :: Nat) a. (Dimensional n v, Integral a) => a
dimension @v forall a. Num a => a -> a -> a
- Int
1] ]
{-# INLINE tensorUnsafeWriteArrayWithOffsetViaList #-}
tensorUnsafeWriteArrayWithOffsetViaList
:: ∀ v w n m α σ . ( n`Dimensional`v
, m`Dimensional`w
, Scalar v ~ Scalar w
, GArr.Vector α (Scalar v) )
=> (TensorProduct v w -> [w]) -> GArr.Mutable α σ (Scalar v)
-> Int -> (v⊗w) -> ST σ ()
tensorUnsafeWriteArrayWithOffsetViaList :: forall v w (n :: Nat) (m :: Nat) (α :: * -> *) σ.
(Dimensional n v, Dimensional m w, Scalar v ~ Scalar w,
Vector α (Scalar v)) =>
(TensorProduct v w -> [w])
-> Mutable α σ (Scalar v) -> Int -> (v ⊗ w) -> ST σ ()
tensorUnsafeWriteArrayWithOffsetViaList TensorProduct v w -> [w]
v2l Mutable α σ (Scalar v)
ar Int
i (Tensor TensorProduct v w
t)
= forall (t :: * -> *) (k :: * -> * -> *) (l :: * -> * -> *)
(f :: * -> *) a b uk ul.
(Foldable t k l, Monoidal f l l, Monoidal f k k, Function l,
Arrow k (->), Arrow l (->), ul ~ UnitObject l, uk ~ UnitObject k,
uk ~ ul, ObjectPair l ul ul, ObjectPair l (f ul) (f ul),
ObjectPair l (f ul) (t a), ObjectPair l ul (t a),
ObjectPair l (t a) ul, ObjectPair l (f ul) a, ObjectPair k b (f b),
ObjectPair k b ul, ObjectPair k uk uk, ObjectPair k (f uk) a,
ObjectPair k (f uk) (f uk)) =>
t a -> k a (f b) -> f uk
forM_ (forall a b. [a] -> [b] -> [(a, b)]
zip [Int
0..] forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ TensorProduct v w -> [w]
v2l TensorProduct v w
t) forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Int
j, w
v)
-> forall (n :: Nat) v (α :: * -> *) σ.
(Dimensional n v, Vector α (Scalar v)) =>
Mutable α σ (Scalar v) -> Int -> v -> ST σ ()
unsafeWriteArrayWithOffset Mutable α σ (Scalar v)
ar
(Int
i forall a. Num a => a -> a -> a
+ Int
j forall a. Num a => a -> a -> a
* forall v (n :: Nat) a. (Dimensional n v, Integral a) => a
dimension @w) w
v
#if MIN_VERSION_manifolds_core(0,6,0)
#define FreeLinSpaceInteriorDecls
#else
#define FreeLinSpaceInteriorDecls \
toInterior = pure; fromInterior = id; translateP = Tagged (^+^);
#endif
#define FreeLinearSpace( V, d, LV, tp \
, tenspl, tenid, dspan \
, contraction, contraaction \
, frls, tols ) \
instance Num s => Semimanifold (V s) where { \
type Needle (V s) = V s; \
FreeLinSpaceInteriorDecls \
(.+~^) = (^+^) }; \
instance Num s => PseudoAffine (V s) where { \
v.-~.w = pure (v^-^w); (.-~!) = (^-^) }; \
instance ∀ s . (Num' s, Eq s) => DimensionAware (V s) where { \
type StaticDimension (V s) = 'Just (d); \
dimensionalityWitness = IsStaticDimensional }; \
instance ∀ s . (Num' s, Eq s) => (d)`Dimensional`V (s) where { \
unsafeFromArrayWithOffset \
= unsafeFromArrayWithOffsetViaList (frls); \
unsafeWriteArrayWithOffset \
= unsafeWriteArrayWithOffsetViaList (tols) \
}; \
instance ∀ s . (Num' s, Eq s) => TensorSpace (V s) where { \
type TensorProduct (V s) w = V w; \
scalarSpaceWitness = case closedScalarWitness :: ClosedScalarWitness s of{ \
ClosedScalarWitness -> ScalarSpaceWitness}; \
linearManifoldWitness = autoLinearManifoldWitness; \
zeroTensor = Tensor $ pure zeroV; \
addTensors (Tensor m) (Tensor n) = Tensor $ liftA2 (^+^) m n; \
subtractTensors (Tensor m) (Tensor n) = Tensor $ liftA2 (^-^) m n; \
negateTensor = LinearFunction $ Tensor . fmap negateV . getTensorProduct; \
scaleTensor = bilinearFunction \
$ \μ -> Tensor . fmap (μ*^) . getTensorProduct; \
toFlatTensor = case closedScalarWitness :: ClosedScalarWitness s of{ \
ClosedScalarWitness -> LinearFunction $ follow Tensor}; \
fromFlatTensor = case closedScalarWitness :: ClosedScalarWitness s of{ \
ClosedScalarWitness -> LinearFunction $ flout Tensor}; \
tensorProduct = bilinearFunction $ \w v -> Tensor $ fmap (*^v) w; \
transposeTensor = LinearFunction (tp); \
fmapTensor = bilinearFunction $ \
\(LinearFunction f) -> pretendLike Tensor $ fmap f; \
fzipTensorWith = bilinearFunction $ \
\(LinearFunction f) (Tensor vw, Tensor vx) \
-> Tensor $ liftA2 (curry f) vw vx; \
tensorUnsafeFromArrayWithOffset \
= tensorUnsafeFromArrayWithOffsetViaList (frls); \
tensorUnsafeWriteArrayWithOffset \
= tensorUnsafeWriteArrayWithOffsetViaList (tols); \
coerceFmapTensorProduct _ VSCCoercion = Coercion; \
wellDefinedTensor = getTensorProduct >>> Hask.traverse wellDefinedVector \
>>> fmap Tensor }; \
instance ∀ s . (Num' s, Eq s) => LinearSpace (V s) where { \
type DualVector (V s) = V s; \
dualSpaceWitness = case closedScalarWitness :: ClosedScalarWitness s of \
{ClosedScalarWitness -> DualSpaceWitness}; \
linearId = LV Mat.identity; \
idTensor = Tensor Mat.identity; \
tensorId = ti dualSpaceWitness where \
{ ti :: ∀ w . (LinearSpace w, Scalar w ~ s) => DualSpaceWitness w -> (V s⊗w)+>(V s⊗w) \
; ti DualSpaceWitness = LinearMap $ \
fmap (\f -> fmap (LinearFunction $ Tensor . f)-+$>asTensor $ id) \
(tenid :: V (w -> V w)) }; \
coerceDoubleDual = VSCCoercion; \
fromLinearForm = case closedScalarWitness :: ClosedScalarWitness s of{ \
ClosedScalarWitness -> LinearFunction $ flout LinearMap}; \
contractTensorMap = LinearFunction $ (contraction) . coerce . getLinearMap; \
contractMapTensor = LinearFunction $ (contraction) . coerce . getTensorProduct; \
{-contractTensorWith = bilinearFunction $ \
\(Tensor wv) dw -> fmap (arr $ applyDualVector $ dw) wv; -} \
contractLinearMapAgainst = bilinearFunction $ getLinearMap >>> (contraaction); \
applyDualVector = bilinearFunction Mat.dot; \
applyLinear = bilinearFunction $ \(LV m) \
-> foldl' (^+^) zeroV . liftA2 (^*) m; \
applyTensorFunctional = bilinearFunction $ \(LinearMap f) (Tensor t) \
-> sum $ liftA2 (<.>^) f t; \
applyTensorLinMap = bilinearFunction $ \(LinearMap f) (Tensor t) \
-> foldl' (^+^) zeroV $ liftA2 ((fromTensor-+$=>) >>> \
getLinearFunction . getLinearFunction applyLinear) f t; \
composeLinear = bilinearFunction $ \
\f (LinearMap g) -> LinearMap $ fmap ((applyLinear-+$>f)-+$>) g; \
useTupleLinearSpaceComponents _ = usingNonTupleTypeAsTupleError }
FreeLinearSpace( V0, 0
, LinearMap
, \(Tensor V0) -> zeroV
, \_ -> LinearMap V0
, V0
, LinearMap V0
, \V0 -> zeroV
, \V0 _ -> 0
, \[] -> V0
, \V0 -> []
)
FreeLinearSpace( V1, 1
, LinearMap
, \(Tensor (V1 w₀)) -> w₀⊗V1 1
, \w -> LinearMap $ V1 (Tensor $ V1 w)
, V1 V1
, LinearMap . V1 . blockVectSpan $ V1 1
, \(V1 (V1 w)) -> w
, \(V1 x) f -> (f$x)^._x
, \[x] -> V1 x
, \(V1 x) -> [x]
)
FreeLinearSpace( V2, 2
, LinearMap
, \(Tensor (V2 w₀ w₁)) -> w₀⊗V2 1 0
^+^ w₁⊗V2 0 1
, \w -> LinearMap $ V2 (Tensor $ V2 w zeroV)
(Tensor $ V2 zeroV w)
, V2 (`V2`zeroV) (V2 zeroV)
, LinearMap $ V2 (blockVectSpan $ V2 1 0)
(blockVectSpan $ V2 0 1)
, \(V2 (V2 w₀ _)
(V2 _ w₁)) -> w₀^+^w₁
, \(V2 x y) f -> (f$x)^._x + (f$y)^._y
, \(x:y:[]) -> V2 x y
, \(V2 x y) -> (x:y:[])
)
FreeLinearSpace( V3, 3
, LinearMap
, \(Tensor (V3 w₀ w₁ w₂)) -> w₀⊗V3 1 0 0
^+^ w₁⊗V3 0 1 0
^+^ w₂⊗V3 0 0 1
, \w -> LinearMap $ V3 (Tensor $ V3 w zeroV zeroV)
(Tensor $ V3 zeroV w zeroV)
(Tensor $ V3 zeroV zeroV w)
, V3 (\w -> V3 w zeroV zeroV)
(\w -> V3 zeroV w zeroV)
(\w -> V3 zeroV zeroV w)
, LinearMap $ V3 (blockVectSpan $ V3 1 0 0)
(blockVectSpan $ V3 0 1 0)
(blockVectSpan $ V3 0 0 1)
, \(V3 (V3 w₀ _ _)
(V3 _ w₁ _)
(V3 _ _ w₂)) -> w₀^+^w₁^+^w₂
, \(V3 x y z) f -> (f$x)^._x + (f$y)^._y + (f$z)^._z
, \(x:y:z:[]) -> V3 x y z
, \(V3 x y z) -> x:y:z:[]
)
FreeLinearSpace( V4, 4
, LinearMap
, \(Tensor (V4 w₀ w₁ w₂ w₃)) -> w₀⊗V4 1 0 0 0
^+^ w₁⊗V4 0 1 0 0
^+^ w₂⊗V4 0 0 1 0
^+^ w₃⊗V4 0 0 0 1
, \w -> V4 (LinearMap $ V4 w zeroV zeroV zeroV)
(LinearMap $ V4 zeroV w zeroV zeroV)
(LinearMap $ V4 zeroV zeroV w zeroV)
(LinearMap $ V4 zeroV zeroV zeroV w)
, V4 (\w -> V4 w zeroV zeroV zeroV)
(\w -> V4 zeroV w zeroV zeroV)
(\w -> V4 zeroV zeroV w zeroV)
(\w -> V4 zeroV zeroV zeroV w)
, LinearMap $ V4 (blockVectSpan $ V4 1 0 0 0)
(blockVectSpan $ V4 0 1 0 0)
(blockVectSpan $ V4 0 0 1 0)
(blockVectSpan $ V4 0 0 0 1)
, \(V4 (V4 w₀ _ _ _)
(V4 _ w₁ _ _)
(V4 _ _ w₂ _)
(V4 _ _ _ w₃)) -> w₀^+^w₁^+^w₂^+^w₃
, \(V4 x y z w) f -> (f$x)^._x + (f$y)^._y + (f$z)^._z + (f$w)^._w
, \(x:y:z:w:[]) -> V4 x y z w
, \(V4 x y z w) -> x:y:z:w:[]
)
instance (Num' n, TensorProduct (DualVector n) n ~ n) => Num (LinearMap n n n) where
LinearMap TensorProduct (DualVector n) n
n + :: LinearMap n n n -> LinearMap n n n -> LinearMap n n n
+ LinearMap TensorProduct (DualVector n) n
m = forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ TensorProduct (DualVector n) n
n forall a. Num a => a -> a -> a
+ TensorProduct (DualVector n) n
m
LinearMap TensorProduct (DualVector n) n
n - :: LinearMap n n n -> LinearMap n n n -> LinearMap n n n
- LinearMap TensorProduct (DualVector n) n
m = forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ TensorProduct (DualVector n) n
n forall a. Num a => a -> a -> a
- TensorProduct (DualVector n) n
m
LinearMap TensorProduct (DualVector n) n
n * :: LinearMap n n n -> LinearMap n n n -> LinearMap n n n
* LinearMap TensorProduct (DualVector n) n
m = forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ TensorProduct (DualVector n) n
n forall a. Num a => a -> a -> a
* TensorProduct (DualVector n) n
m
abs :: LinearMap n n n -> LinearMap n n n
abs (LinearMap TensorProduct (DualVector n) n
n) = forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall a. Num a => a -> a
abs TensorProduct (DualVector n) n
n
signum :: LinearMap n n n -> LinearMap n n n
signum (LinearMap TensorProduct (DualVector n) n
n) = forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall a. Num a => a -> a
signum TensorProduct (DualVector n) n
n
fromInteger :: Integer -> LinearMap n n n
fromInteger = forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall a. Num a => Integer -> a
fromInteger
instance (Fractional' n, TensorProduct (DualVector n) n ~ n)
=> Fractional (LinearMap n n n) where
LinearMap TensorProduct (DualVector n) n
n / :: LinearMap n n n -> LinearMap n n n -> LinearMap n n n
/ LinearMap TensorProduct (DualVector n) n
m = forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ TensorProduct (DualVector n) n
n forall a. Fractional a => a -> a -> a
/ TensorProduct (DualVector n) n
m
recip :: LinearMap n n n -> LinearMap n n n
recip (LinearMap TensorProduct (DualVector n) n
n) = forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall a. Fractional a => a -> a
recip TensorProduct (DualVector n) n
n
fromRational :: Rational -> LinearMap n n n
fromRational = forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall a. Fractional a => Rational -> a
fromRational
instance (Num' n, UArr.Unbox n) => Semimanifold (FinSuppSeq n) where
type Needle (FinSuppSeq n) = FinSuppSeq n
.+~^ :: FinSuppSeq n -> Needle (FinSuppSeq n) -> FinSuppSeq n
(.+~^) = forall p. AffineSpace p => p -> Diff p -> p
(.+^)
#if !MIN_VERSION_manifolds_core(0,6,0)
translateP = Tagged (.+^); toInterior = pure; fromInterior = id
#endif
instance (Num' n, UArr.Unbox n) => PseudoAffine (FinSuppSeq n) where
FinSuppSeq n
v.-~. :: FinSuppSeq n -> FinSuppSeq n -> Maybe (Needle (FinSuppSeq n))
.-~.FinSuppSeq n
w = forall a. a -> Maybe a
Just forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ FinSuppSeq n
vforall p. AffineSpace p => p -> p -> Diff p
.-.FinSuppSeq n
w; .-~! :: HasCallStack =>
FinSuppSeq n -> FinSuppSeq n -> Needle (FinSuppSeq n)
(.-~!) = forall p. AffineSpace p => p -> p -> Diff p
(.-.)
instance (Num' n, UArr.Unbox n) => DimensionAware (FinSuppSeq n) where
type StaticDimension (FinSuppSeq n) = 'Nothing
dimensionalityWitness :: DimensionalityWitness (FinSuppSeq n)
dimensionalityWitness = forall v. (StaticDimension v ~ 'Nothing) => DimensionalityWitness v
IsFlexibleDimensional
instance (Num' n, UArr.Unbox n) => TensorSpace (FinSuppSeq n) where
type TensorProduct (FinSuppSeq n) v = [v]
wellDefinedVector :: FinSuppSeq n -> Maybe (FinSuppSeq n)
wellDefinedVector (FinSuppSeq Vector n
v) = forall n. Vector n -> FinSuppSeq n
FinSuppSeq forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> forall (m :: * -> *) a b.
(Monad m, Unbox a, Unbox b) =>
(a -> m b) -> Vector a -> m (Vector b)
UArr.mapM forall v. TensorSpace v => v -> Maybe v
wellDefinedVector Vector n
v
scalarSpaceWitness :: ScalarSpaceWitness (FinSuppSeq n)
scalarSpaceWitness = case forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness n of
ClosedScalarWitness n
ClosedScalarWitness -> forall v.
(Num' (Scalar v), Scalar (Scalar v) ~ Scalar v) =>
ScalarSpaceWitness v
ScalarSpaceWitness
linearManifoldWitness :: LinearManifoldWitness (FinSuppSeq n)
linearManifoldWitness = forall v.
(Semimanifold v, AffineSpace v, v ~ Needle v, v ~ Diff v) =>
LinearManifoldWitness v
autoLinearManifoldWitness
zeroTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (FinSuppSeq n)) =>
FinSuppSeq n ⊗ w
zeroTensor = forall s v w. TensorProduct v w -> Tensor s v w
Tensor []
toFlatTensor :: FinSuppSeq n -+> (FinSuppSeq n ⊗ Scalar (FinSuppSeq n))
toFlatTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall a. Unbox a => Vector a -> [a]
UArr.toList forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall n. FinSuppSeq n -> Vector n
getFiniteSeq
fromFlatTensor :: (FinSuppSeq n ⊗ Scalar (FinSuppSeq n)) -+> FinSuppSeq n
fromFlatTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall n. Vector n -> FinSuppSeq n
FinSuppSeq forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall a. Unbox a => [a] -> Vector a
UArr.fromList forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s v w. Tensor s v w -> TensorProduct v w
getTensorProduct
addTensors :: forall w.
(TensorSpace w, Scalar w ~ Scalar (FinSuppSeq n)) =>
(FinSuppSeq n ⊗ w) -> (FinSuppSeq n ⊗ w) -> FinSuppSeq n ⊗ w
addTensors (Tensor TensorProduct (FinSuppSeq n) w
s) (Tensor TensorProduct (FinSuppSeq n) w
t) = forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (f :: * -> *) a.
Additive f =>
(a -> a -> a) -> f a -> f a -> f a
Mat.liftU2 forall v. AdditiveGroup v => v -> v -> v
(^+^) TensorProduct (FinSuppSeq n) w
s TensorProduct (FinSuppSeq n) w
t
subtractTensors :: forall w.
(TensorSpace (FinSuppSeq n), TensorSpace w,
Scalar w ~ Scalar (FinSuppSeq n)) =>
(FinSuppSeq n ⊗ w) -> (FinSuppSeq n ⊗ w) -> FinSuppSeq n ⊗ w
subtractTensors (Tensor TensorProduct (FinSuppSeq n) w
s) (Tensor TensorProduct (FinSuppSeq n) w
t) = forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (f :: * -> *) a.
Additive f =>
(a -> a -> a) -> f a -> f a -> f a
Mat.liftU2 forall v. AdditiveGroup v => v -> v -> v
(^-^) TensorProduct (FinSuppSeq n) w
s TensorProduct (FinSuppSeq n) w
t
scaleTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (FinSuppSeq n)) =>
Bilinear
(Scalar (FinSuppSeq n)) (FinSuppSeq n ⊗ w) (FinSuppSeq n ⊗ w)
scaleTensor = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \n
μ (Tensor TensorProduct (FinSuppSeq n) w
t) -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (n
μforall v. VectorSpace v => Scalar v -> v -> v
*^)forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$>TensorProduct (FinSuppSeq n) w
t
negateTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (FinSuppSeq n)) =>
(FinSuppSeq n ⊗ w) -+> (FinSuppSeq n ⊗ w)
negateTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Tensor TensorProduct (FinSuppSeq n) w
t) -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v. AdditiveGroup v => v -> v
negateVforall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$>TensorProduct (FinSuppSeq n) w
t
tensorProduct :: forall w.
(TensorSpace w, Scalar w ~ Scalar (FinSuppSeq n)) =>
Bilinear (FinSuppSeq n) w (FinSuppSeq n ⊗ w)
tensorProduct = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(FinSuppSeq Vector n
v) w
w -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (forall v. VectorSpace v => Scalar v -> v -> v
*^w
w)forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$>forall a. Unbox a => Vector a -> [a]
UArr.toList Vector n
v
transposeTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (FinSuppSeq n)) =>
(FinSuppSeq n ⊗ w) -+> (w ⊗ FinSuppSeq n)
transposeTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Tensor TensorProduct (FinSuppSeq n) w
a)
-> let n :: Int
n = forall (t :: * -> *) a. Foldable t => t a -> Int
length TensorProduct (FinSuppSeq n) w
a
in forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' forall v. AdditiveGroup v => v -> v -> v
(^+^) forall v. AdditiveGroup v => v
zeroV
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith ( \Int
i w
w -> forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear v w (v ⊗ w)
tensorProduct w
w forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v. HasBasis v => Basis v -> v
basisValue Int
i )
[Int
0..] TensorProduct (FinSuppSeq n) w
a
fmapTensor :: forall w x.
(TensorSpace w, TensorSpace x, Scalar w ~ Scalar (FinSuppSeq n),
Scalar x ~ Scalar (FinSuppSeq n)) =>
Bilinear (w -+> x) (FinSuppSeq n ⊗ w) (FinSuppSeq n ⊗ x)
fmapTensor = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction n w x
f (Tensor TensorProduct (FinSuppSeq n) w
a) -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (LinearFunction n w x
fforall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$) TensorProduct (FinSuppSeq n) w
a
fzipTensorWith :: forall u w x.
(TensorSpace u, TensorSpace w, TensorSpace x,
Scalar u ~ Scalar (FinSuppSeq n), Scalar w ~ Scalar (FinSuppSeq n),
Scalar x ~ Scalar (FinSuppSeq n)) =>
Bilinear
((w, x) -+> u)
(FinSuppSeq n ⊗ w, FinSuppSeq n ⊗ x)
(FinSuppSeq n ⊗ u)
fzipTensorWith = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction n (w, x) u
f (Tensor TensorProduct (FinSuppSeq n) w
a, Tensor TensorProduct (FinSuppSeq n) x
b)
-> forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (forall (k :: * -> * -> *) a b c.
(Curry k, ObjectPair k a b, ObjectMorphism k b c) =>
k (a, b) c -> k a (k b c)
curry forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
Object a c) =>
k b c -> a b c
arr LinearFunction n (w, x) u
f) TensorProduct (FinSuppSeq n) w
a TensorProduct (FinSuppSeq n) x
b
tensorUnsafeFromArrayWithOffset :: forall w (α :: * -> *) (n :: Nat) (m :: Nat).
(Dimensional n (FinSuppSeq n), TensorSpace w, Dimensional m w,
Scalar w ~ Scalar (FinSuppSeq n),
Vector α (Scalar (FinSuppSeq n))) =>
Int -> α (Scalar (FinSuppSeq n)) -> FinSuppSeq n ⊗ w
tensorUnsafeFromArrayWithOffset
= forall {k} v (n :: k) r. (StaticDimension v ~ 'Nothing) => r
notStaticDimensionalContradiction @(FinSuppSeq n)
tensorUnsafeWriteArrayWithOffset :: forall w (α :: * -> *) σ (n :: Nat) (m :: Nat).
(Dimensional n (FinSuppSeq n), TensorSpace w, Dimensional m w,
Scalar w ~ Scalar (FinSuppSeq n),
Vector α (Scalar (FinSuppSeq n))) =>
Mutable α σ (Scalar (FinSuppSeq n))
-> Int -> (FinSuppSeq n ⊗ w) -> ST σ ()
tensorUnsafeWriteArrayWithOffset
= forall {k} v (n :: k) r. (StaticDimension v ~ 'Nothing) => r
notStaticDimensionalContradiction @(FinSuppSeq n)
coerceFmapTensorProduct :: forall (p :: * -> *) a b.
(Functor p, TensorSpace a, Scalar a ~ Scalar (FinSuppSeq n),
TensorSpace b, Scalar b ~ Scalar (FinSuppSeq n)) =>
p (FinSuppSeq n)
-> VSCCoercion (Scalar (FinSuppSeq n)) a b
-> Coercion
(TensorProduct (FinSuppSeq n) a) (TensorProduct (FinSuppSeq n) b)
coerceFmapTensorProduct p (FinSuppSeq n)
_ VSCCoercion (Scalar (FinSuppSeq n)) a b
VSCCoercion = forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion
wellDefinedTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (FinSuppSeq n)) =>
(FinSuppSeq n ⊗ w) -> Maybe (FinSuppSeq n ⊗ w)
wellDefinedTensor (Tensor TensorProduct (FinSuppSeq n) w
a) = forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
Hask.traverse forall v. TensorSpace v => v -> Maybe v
wellDefinedVector TensorProduct (FinSuppSeq n) w
a
instance (Num' n, UArr.Unbox n) => Semimanifold (Sequence n) where
type Needle (Sequence n) = Sequence n
.+~^ :: Sequence n -> Needle (Sequence n) -> Sequence n
(.+~^) = forall p. AffineSpace p => p -> Diff p -> p
(.+^)
#if !MIN_VERSION_manifolds_core(0,6,0)
translateP = Tagged (.+^); toInterior = pure; fromInterior = id
#endif
instance (Num' n, UArr.Unbox n) => PseudoAffine (Sequence n) where
Sequence n
v.-~. :: Sequence n -> Sequence n -> Maybe (Needle (Sequence n))
.-~.Sequence n
w = forall a. a -> Maybe a
Just forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Sequence n
vforall p. AffineSpace p => p -> p -> Diff p
.-.Sequence n
w; .-~! :: HasCallStack => Sequence n -> Sequence n -> Needle (Sequence n)
(.-~!) = forall p. AffineSpace p => p -> p -> Diff p
(.-.)
instance (Num' n, UArr.Unbox n) => DimensionAware (Sequence n) where
type StaticDimension (Sequence n) = 'Nothing
dimensionalityWitness :: DimensionalityWitness (Sequence n)
dimensionalityWitness = forall v. (StaticDimension v ~ 'Nothing) => DimensionalityWitness v
IsFlexibleDimensional
instance (Num' n, UArr.Unbox n) => TensorSpace (Sequence n) where
type TensorProduct (Sequence n) v = [v]
wellDefinedVector :: Sequence n -> Maybe (Sequence n)
wellDefinedVector (SoloChunk Int
n Vector n
c) = forall (array :: * -> *) n. Int -> array n -> GSequence array n
SoloChunk Int
n forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> forall (m :: * -> *) a b.
(Monad m, Unbox a, Unbox b) =>
(a -> m b) -> Vector a -> m (Vector b)
UArr.mapM forall v. TensorSpace v => v -> Maybe v
wellDefinedVector Vector n
c
wellDefinedVector (Sequence Vector n
h Sequence n
r) = forall (array :: * -> *) n.
array n -> GSequence array n -> GSequence array n
Sequence forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> forall (m :: * -> *) a b.
(Monad m, Unbox a, Unbox b) =>
(a -> m b) -> Vector a -> m (Vector b)
UArr.mapM forall v. TensorSpace v => v -> Maybe v
wellDefinedVector Vector n
h
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Applicative f r t, ObjectMorphism r a b,
ObjectMorphism t (f a) (f b), Object t (t (f a) (f b)),
ObjectPair r (r a b) a, ObjectPair t (f (r a b)) (f a), Object r a,
Object r b) =>
t (f (r a b)) (t (f a) (f b))
<*> forall v. TensorSpace v => v -> Maybe v
wellDefinedVector Sequence n
r
wellDefinedTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Sequence n)) =>
(Sequence n ⊗ w) -> Maybe (Sequence n ⊗ w)
wellDefinedTensor (Tensor TensorProduct (Sequence n) w
a) = forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
Hask.traverse forall v. TensorSpace v => v -> Maybe v
wellDefinedVector TensorProduct (Sequence n) w
a
scalarSpaceWitness :: ScalarSpaceWitness (Sequence n)
scalarSpaceWitness = case forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness n of
ClosedScalarWitness n
ClosedScalarWitness -> forall v.
(Num' (Scalar v), Scalar (Scalar v) ~ Scalar v) =>
ScalarSpaceWitness v
ScalarSpaceWitness
linearManifoldWitness :: LinearManifoldWitness (Sequence n)
linearManifoldWitness = forall v.
(Semimanifold v, AffineSpace v, v ~ Needle v, v ~ Diff v) =>
LinearManifoldWitness v
autoLinearManifoldWitness
zeroTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Sequence n)) =>
Sequence n ⊗ w
zeroTensor = forall s v w. TensorProduct v w -> Tensor s v w
Tensor []
toFlatTensor :: Sequence n -+> (Sequence n ⊗ Scalar (Sequence n))
toFlatTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall l. IsList l => l -> [Item l]
GHC.toList
fromFlatTensor :: (Sequence n ⊗ Scalar (Sequence n)) -+> Sequence n
fromFlatTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall l. IsList l => [Item l] -> l
GHC.fromList forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s v w. Tensor s v w -> TensorProduct v w
getTensorProduct
addTensors :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Sequence n)) =>
(Sequence n ⊗ w) -> (Sequence n ⊗ w) -> Sequence n ⊗ w
addTensors (Tensor TensorProduct (Sequence n) w
s) (Tensor TensorProduct (Sequence n) w
t) = forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (f :: * -> *) a.
Additive f =>
(a -> a -> a) -> f a -> f a -> f a
Mat.liftU2 forall v. AdditiveGroup v => v -> v -> v
(^+^) TensorProduct (Sequence n) w
s TensorProduct (Sequence n) w
t
subtractTensors :: forall w.
(TensorSpace (Sequence n), TensorSpace w,
Scalar w ~ Scalar (Sequence n)) =>
(Sequence n ⊗ w) -> (Sequence n ⊗ w) -> Sequence n ⊗ w
subtractTensors (Tensor TensorProduct (Sequence n) w
s) (Tensor TensorProduct (Sequence n) w
t) = forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (f :: * -> *) a.
Additive f =>
(a -> a -> a) -> f a -> f a -> f a
Mat.liftU2 forall v. AdditiveGroup v => v -> v -> v
(^-^) TensorProduct (Sequence n) w
s TensorProduct (Sequence n) w
t
scaleTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Sequence n)) =>
Bilinear (Scalar (Sequence n)) (Sequence n ⊗ w) (Sequence n ⊗ w)
scaleTensor = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \n
μ (Tensor TensorProduct (Sequence n) w
t) -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (n
μforall v. VectorSpace v => Scalar v -> v -> v
*^)forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$>TensorProduct (Sequence n) w
t
negateTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Sequence n)) =>
(Sequence n ⊗ w) -+> (Sequence n ⊗ w)
negateTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Tensor TensorProduct (Sequence n) w
t) -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v. AdditiveGroup v => v -> v
negateVforall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$>TensorProduct (Sequence n) w
t
tensorProduct :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Sequence n)) =>
Bilinear (Sequence n) w (Sequence n ⊗ w)
tensorProduct = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \Sequence n
v w
w -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (forall v. VectorSpace v => Scalar v -> v -> v
*^w
w)forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$>forall l. IsList l => l -> [Item l]
GHC.toList Sequence n
v
transposeTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Sequence n)) =>
(Sequence n ⊗ w) -+> (w ⊗ Sequence n)
transposeTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Tensor TensorProduct (Sequence n) w
a)
-> let n :: Int
n = forall (t :: * -> *) a. Foldable t => t a -> Int
length TensorProduct (Sequence n) w
a
in forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' forall v. AdditiveGroup v => v -> v -> v
(^+^) forall v. AdditiveGroup v => v
zeroV
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\Int
i w
w -> (forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear v w (v ⊗ w)
tensorProduct w
w) forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v. HasBasis v => Basis v -> v
basisValue Int
i)
[Int
0..] TensorProduct (Sequence n) w
a
fmapTensor :: forall w x.
(TensorSpace w, TensorSpace x, Scalar w ~ Scalar (Sequence n),
Scalar x ~ Scalar (Sequence n)) =>
Bilinear (w -+> x) (Sequence n ⊗ w) (Sequence n ⊗ x)
fmapTensor = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction n w x
f (Tensor TensorProduct (Sequence n) w
a) -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (LinearFunction n w x
fforall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$) TensorProduct (Sequence n) w
a
fzipTensorWith :: forall u w x.
(TensorSpace u, TensorSpace w, TensorSpace x,
Scalar u ~ Scalar (Sequence n), Scalar w ~ Scalar (Sequence n),
Scalar x ~ Scalar (Sequence n)) =>
Bilinear
((w, x) -+> u) (Sequence n ⊗ w, Sequence n ⊗ x) (Sequence n ⊗ u)
fzipTensorWith = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction n (w, x) u
f (Tensor TensorProduct (Sequence n) w
a, Tensor TensorProduct (Sequence n) x
b)
-> forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (forall (k :: * -> * -> *) a b c.
(Curry k, ObjectPair k a b, ObjectMorphism k b c) =>
k (a, b) c -> k a (k b c)
curry forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
Object a c) =>
k b c -> a b c
arr LinearFunction n (w, x) u
f) TensorProduct (Sequence n) w
a TensorProduct (Sequence n) x
b
tensorUnsafeFromArrayWithOffset :: forall w (α :: * -> *) (n :: Nat) (m :: Nat).
(Dimensional n (Sequence n), TensorSpace w, Dimensional m w,
Scalar w ~ Scalar (Sequence n), Vector α (Scalar (Sequence n))) =>
Int -> α (Scalar (Sequence n)) -> Sequence n ⊗ w
tensorUnsafeFromArrayWithOffset
= forall {k} v (n :: k) r. (StaticDimension v ~ 'Nothing) => r
notStaticDimensionalContradiction @(Sequence n)
tensorUnsafeWriteArrayWithOffset :: forall w (α :: * -> *) σ (n :: Nat) (m :: Nat).
(Dimensional n (Sequence n), TensorSpace w, Dimensional m w,
Scalar w ~ Scalar (Sequence n), Vector α (Scalar (Sequence n))) =>
Mutable α σ (Scalar (Sequence n))
-> Int -> (Sequence n ⊗ w) -> ST σ ()
tensorUnsafeWriteArrayWithOffset
= forall {k} v (n :: k) r. (StaticDimension v ~ 'Nothing) => r
notStaticDimensionalContradiction @(Sequence n)
coerceFmapTensorProduct :: forall (p :: * -> *) a b.
(Functor p, TensorSpace a, Scalar a ~ Scalar (Sequence n),
TensorSpace b, Scalar b ~ Scalar (Sequence n)) =>
p (Sequence n)
-> VSCCoercion (Scalar (Sequence n)) a b
-> Coercion
(TensorProduct (Sequence n) a) (TensorProduct (Sequence n) b)
coerceFmapTensorProduct p (Sequence n)
_ VSCCoercion (Scalar (Sequence n)) a b
VSCCoercion = forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion
instance ∀ n . (Num' n, UArr.Unbox n) => LinearSpace (Sequence n) where
type DualVector (Sequence n) = FinSuppSeq n
dualSpaceWitness :: DualSpaceWitness (Sequence n)
dualSpaceWitness = case forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness n of
ClosedScalarWitness n
ClosedScalarWitness -> forall v.
(LinearSpace (Scalar v), DualVector (Scalar v) ~ Scalar v,
LinearSpace (DualVector v), Scalar (DualVector v) ~ Scalar v,
DualVector (DualVector v) ~ v,
StaticDimension (DualVector v) ~ StaticDimension v) =>
DualSpaceWitness v
DualSpaceWitness
linearId :: Sequence n +> Sequence n
linearId = forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap [forall v. HasBasis v => Basis v -> v
basisValue Int
i | Int
i<-[Int
0..]]
tensorId :: forall w.
(LinearSpace w, Scalar w ~ Scalar (Sequence n)) =>
(Sequence n ⊗ w) +> (Sequence n ⊗ w)
tensorId = forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap [forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall s a b. VSCCoercion s a b -> a -> b
-+$=> forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
Object t (f b)) =>
r a b -> t (f a) (f b)
fmap (forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
\w
w -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall a. Int -> a -> [a]
replicate (Int
iforall a. Num a => a -> a -> a
-Int
1) forall v. AdditiveGroup v => v
zeroV forall a. [a] -> [a] -> [a]
++ [w
w]) forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id | Int
i<-[Int
0..]]
applyDualVector :: LinearSpace (Sequence n) =>
Bilinear
(DualVector (Sequence n)) (Sequence n) (Scalar (Sequence n))
applyDualVector = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall {c}.
(Unbox c, Num c) =>
Int -> FinSuppSeq c -> GSequence Vector c -> c
adv Int
Seq.minimumChunkSize
where adv :: Int -> FinSuppSeq c -> GSequence Vector c -> c
adv Int
_ (FinSuppSeq Vector c
v) (Seq.SoloChunk Int
o Vector c
q)
= forall a. (Unbox a, Num a) => Vector a -> a
UArr.sum forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall a b c.
(Unbox a, Unbox b, Unbox c) =>
(a -> b -> c) -> Vector a -> Vector b -> Vector c
UArr.zipWith forall a. Num a => a -> a -> a
(*) (forall a. Unbox a => Int -> Vector a -> Vector a
UArr.drop Int
o Vector c
v) Vector c
q
adv Int
chunkSize (FinSuppSeq Vector c
v) (Sequence Vector c
c GSequence Vector c
r)
| forall a. Unbox a => Vector a -> Int
UArr.length Vector c
v forall a. Ord a => a -> a -> Bool
> Int
chunkSize
= forall a. (Unbox a, Num a) => Vector a -> a
UArr.sum (forall a b c.
(Unbox a, Unbox b, Unbox c) =>
(a -> b -> c) -> Vector a -> Vector b -> Vector c
UArr.zipWith forall a. Num a => a -> a -> a
(*) Vector c
v Vector c
c)
forall a. Num a => a -> a -> a
+ Int -> FinSuppSeq c -> GSequence Vector c -> c
adv (Int
chunkSizeforall a. Num a => a -> a -> a
*Int
2) (forall n. Vector n -> FinSuppSeq n
FinSuppSeq forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall a. Unbox a => Int -> Vector a -> Vector a
UArr.drop Int
chunkSize Vector c
v) GSequence Vector c
r
| Bool
otherwise = forall a. (Unbox a, Num a) => Vector a -> a
UArr.sum forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall a b c.
(Unbox a, Unbox b, Unbox c) =>
(a -> b -> c) -> Vector a -> Vector b -> Vector c
UArr.zipWith forall a. Num a => a -> a -> a
(*) Vector c
v Vector c
c
applyLinear :: forall w.
(TensorSpace w, Scalar w ~ Scalar (Sequence n)) =>
Bilinear (Sequence n +> w) (Sequence n) w
applyLinear = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall {v} {w} {c} {s}.
(TensorProduct (DualVector v) w ~ [c], VectorSpace c,
Unbox (Scalar c)) =>
Int -> LinearMap s v w -> GSequence Vector (Scalar c) -> c
apl Int
Seq.minimumChunkSize
where apl :: Int -> LinearMap s v w -> GSequence Vector (Scalar c) -> c
apl Int
_ (LinearMap TensorProduct (DualVector v) w
m) (Seq.SoloChunk Int
o Vector (Scalar c)
q)
= forall (f :: * -> *) v. (Foldable f, AdditiveGroup v) => f v -> v
sumV forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith forall v. VectorSpace v => Scalar v -> v -> v
(*^) (forall a. Unbox a => Vector a -> [a]
UArr.toList Vector (Scalar c)
q) (forall a. Int -> [a] -> [a]
drop Int
o TensorProduct (DualVector v) w
m)
apl Int
chunkSize (LinearMap TensorProduct (DualVector v) w
m) (Sequence Vector (Scalar c)
c GSequence Vector (Scalar c)
r)
| forall (t :: * -> *) a. Foldable t => t a -> Bool
null [c]
mr = forall (f :: * -> *) v. (Foldable f, AdditiveGroup v) => f v -> v
sumV forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith forall v. VectorSpace v => Scalar v -> v -> v
(*^) (forall a. Unbox a => Vector a -> [a]
UArr.toList Vector (Scalar c)
c) [c]
mc
| Bool
otherwise = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' forall v. AdditiveGroup v => v -> v -> v
(^+^) (Int -> LinearMap s v w -> GSequence Vector (Scalar c) -> c
apl (Int
chunkSizeforall a. Num a => a -> a -> a
*Int
2) (forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap [c]
mr) GSequence Vector (Scalar c)
r)
(forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith forall v. VectorSpace v => Scalar v -> v -> v
(*^) (forall a. Unbox a => Vector a -> [a]
UArr.toList Vector (Scalar c)
c) [c]
mc)
where ([c]
mc, [c]
mr) = forall a. Int -> [a] -> ([a], [a])
splitAt Int
chunkSize TensorProduct (DualVector v) w
m
applyTensorFunctional :: forall u.
(LinearSpace u, Scalar u ~ Scalar (Sequence n)) =>
Bilinear
(DualVector (Sequence n ⊗ u))
(Sequence n ⊗ u)
(Scalar (Sequence n))
applyTensorFunctional = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap TensorProduct (DualVector (Sequence n)) (DualVector u)
m) (Tensor TensorProduct (Sequence n) u
t) -> forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith forall v. LinearSpace v => DualVector v -> v -> Scalar v
(<.>^) TensorProduct (DualVector (Sequence n)) (DualVector u)
m TensorProduct (Sequence n) u
t
applyTensorLinMap :: forall u w.
(LinearSpace u, TensorSpace w, Scalar u ~ Scalar (Sequence n),
Scalar w ~ Scalar (Sequence n)) =>
Bilinear ((Sequence n ⊗ u) +> w) (Sequence n ⊗ u) w
applyTensorLinMap = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
Object a c) =>
k b c -> a b c
arr forall u v w s.
(LinearSpace u, LinearSpace v, TensorSpace w, Scalar u ~ s,
Scalar v ~ s, Scalar w ~ s) =>
VSCCoercion
s (LinearMap s (Tensor s u v) w) (LinearMap s u (LinearMap s v w))
curryLinearMap forall (k :: * -> * -> *) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>>
\(LinearMap TensorProduct (DualVector (Sequence n)) (LinearMap n u w)
m) (Tensor TensorProduct (Sequence n) u
t)
-> forall (f :: * -> *) v. (Foldable f, AdditiveGroup v) => f v -> v
sumV forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinear) TensorProduct (DualVector (Sequence n)) (LinearMap n u w)
m TensorProduct (Sequence n) u
t
useTupleLinearSpaceComponents :: forall x y φ.
(Sequence n ~ (x, y)) =>
((LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ) -> φ
useTupleLinearSpaceComponents (LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ
_ = forall a. a
usingNonTupleTypeAsTupleError
coerceDoubleDual :: VSCCoercion
(Scalar (Sequence n))
(Sequence n)
(DualVector (DualVector (Sequence n)))
coerceDoubleDual = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness @n of
ScalarSpaceWitness n
ScalarSpaceWitness -> forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion
instance ∀ n . (Num' n, UArr.Unbox n) => LinearSpace (FinSuppSeq n) where
type DualVector (FinSuppSeq n) = Sequence n
dualSpaceWitness :: DualSpaceWitness (FinSuppSeq n)
dualSpaceWitness = case forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness n of
ClosedScalarWitness n
ClosedScalarWitness -> forall v.
(LinearSpace (Scalar v), DualVector (Scalar v) ~ Scalar v,
LinearSpace (DualVector v), Scalar (DualVector v) ~ Scalar v,
DualVector (DualVector v) ~ v,
StaticDimension (DualVector v) ~ StaticDimension v) =>
DualSpaceWitness v
DualSpaceWitness
linearId :: FinSuppSeq n +> FinSuppSeq n
linearId = forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap [forall v. HasBasis v => Basis v -> v
basisValue Int
i | Int
i<-[Int
0..]]
tensorId :: forall w.
(LinearSpace w, Scalar w ~ Scalar (FinSuppSeq n)) =>
(FinSuppSeq n ⊗ w) +> (FinSuppSeq n ⊗ w)
tensorId = forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap [forall s v w.
LinearSpace v =>
VSCCoercion s (LinearMap s v w) (Tensor s (DualVector v) w)
asTensor forall s a b. VSCCoercion s a b -> a -> b
-+$=> forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
Object t (f b)) =>
r a b -> t (f a) (f b)
fmap (forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
\w
w -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall a. Int -> a -> [a]
replicate (Int
iforall a. Num a => a -> a -> a
-Int
1) forall v. AdditiveGroup v => v
zeroV forall a. [a] -> [a] -> [a]
++ [w
w]) forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id | Int
i<-[Int
0..]]
applyDualVector :: LinearSpace (FinSuppSeq n) =>
Bilinear
(DualVector (FinSuppSeq n)) (FinSuppSeq n) (Scalar (FinSuppSeq n))
applyDualVector = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall {c}.
(Unbox c, Num c) =>
Int -> GSequence Vector c -> FinSuppSeq c -> c
adv Int
Seq.minimumChunkSize
where adv :: Int -> GSequence Vector c -> FinSuppSeq c -> c
adv Int
_ (Seq.SoloChunk Int
o Vector c
q) (FinSuppSeq Vector c
v)
= forall a. (Unbox a, Num a) => Vector a -> a
UArr.sum forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall a b c.
(Unbox a, Unbox b, Unbox c) =>
(a -> b -> c) -> Vector a -> Vector b -> Vector c
UArr.zipWith forall a. Num a => a -> a -> a
(*) Vector c
q (forall a. Unbox a => Int -> Vector a -> Vector a
UArr.drop Int
o Vector c
v)
adv Int
chunkSize (Sequence Vector c
c GSequence Vector c
r) (FinSuppSeq Vector c
v)
| forall a. Unbox a => Vector a -> Int
UArr.length Vector c
v forall a. Ord a => a -> a -> Bool
> Int
chunkSize
= forall a. (Unbox a, Num a) => Vector a -> a
UArr.sum (forall a b c.
(Unbox a, Unbox b, Unbox c) =>
(a -> b -> c) -> Vector a -> Vector b -> Vector c
UArr.zipWith forall a. Num a => a -> a -> a
(*) Vector c
c Vector c
v)
forall a. Num a => a -> a -> a
+ Int -> GSequence Vector c -> FinSuppSeq c -> c
adv (Int
chunkSizeforall a. Num a => a -> a -> a
*Int
2) GSequence Vector c
r (forall n. Vector n -> FinSuppSeq n
FinSuppSeq forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall a. Unbox a => Int -> Vector a -> Vector a
UArr.drop Int
chunkSize Vector c
v)
| Bool
otherwise = forall a. (Unbox a, Num a) => Vector a -> a
UArr.sum forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall a b c.
(Unbox a, Unbox b, Unbox c) =>
(a -> b -> c) -> Vector a -> Vector b -> Vector c
UArr.zipWith forall a. Num a => a -> a -> a
(*) Vector c
c Vector c
v
applyLinear :: forall w.
(TensorSpace w, Scalar w ~ Scalar (FinSuppSeq n)) =>
Bilinear (FinSuppSeq n +> w) (FinSuppSeq n) w
applyLinear = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap TensorProduct (DualVector (FinSuppSeq n)) w
m) (FinSuppSeq Vector n
v)
-> forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' forall v. AdditiveGroup v => v -> v -> v
(^+^) forall v. AdditiveGroup v => v
zeroV forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith forall v. VectorSpace v => Scalar v -> v -> v
(*^) (forall a. Unbox a => Vector a -> [a]
UArr.toList Vector n
v) TensorProduct (DualVector (FinSuppSeq n)) w
m
applyTensorFunctional :: forall u.
(LinearSpace u, Scalar u ~ Scalar (FinSuppSeq n)) =>
Bilinear
(DualVector (FinSuppSeq n ⊗ u))
(FinSuppSeq n ⊗ u)
(Scalar (FinSuppSeq n))
applyTensorFunctional = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap TensorProduct (DualVector (FinSuppSeq n)) (DualVector u)
m) (Tensor TensorProduct (FinSuppSeq n) u
t) -> forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith forall v. LinearSpace v => DualVector v -> v -> Scalar v
(<.>^) TensorProduct (DualVector (FinSuppSeq n)) (DualVector u)
m TensorProduct (FinSuppSeq n) u
t
applyTensorLinMap :: forall u w.
(LinearSpace u, TensorSpace w, Scalar u ~ Scalar (FinSuppSeq n),
Scalar w ~ Scalar (FinSuppSeq n)) =>
Bilinear ((FinSuppSeq n ⊗ u) +> w) (FinSuppSeq n ⊗ u) w
applyTensorLinMap = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
Object a c) =>
k b c -> a b c
arr forall u v w s.
(LinearSpace u, LinearSpace v, TensorSpace w, Scalar u ~ s,
Scalar v ~ s, Scalar w ~ s) =>
VSCCoercion
s (LinearMap s (Tensor s u v) w) (LinearMap s u (LinearMap s v w))
curryLinearMap forall (k :: * -> * -> *) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>>
\(LinearMap TensorProduct (DualVector (FinSuppSeq n)) (LinearMap n u w)
m) (Tensor TensorProduct (FinSuppSeq n) u
t)
-> forall (f :: * -> *) v. (Foldable f, AdditiveGroup v) => f v -> v
sumV forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinear) TensorProduct (DualVector (FinSuppSeq n)) (LinearMap n u w)
m TensorProduct (FinSuppSeq n) u
t
useTupleLinearSpaceComponents :: forall x y φ.
(FinSuppSeq n ~ (x, y)) =>
((LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ) -> φ
useTupleLinearSpaceComponents (LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ
_ = forall a. a
usingNonTupleTypeAsTupleError
coerceDoubleDual :: VSCCoercion
(Scalar (FinSuppSeq n))
(FinSuppSeq n)
(DualVector (DualVector (FinSuppSeq n)))
coerceDoubleDual = case forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness @n of
ScalarSpaceWitness n
ScalarSpaceWitness -> forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion
instance GHC.IsList (Tensor s (Sequence s) v) where
type Item (Tensor s (Sequence s) v) = v
fromList :: [Item (Tensor s (Sequence s) v)] -> Tensor s (Sequence s) v
fromList = forall s v w. TensorProduct v w -> Tensor s v w
Tensor
toList :: Tensor s (Sequence s) v -> [Item (Tensor s (Sequence s) v)]
toList = forall s v w. Tensor s v w -> TensorProduct v w
getTensorProduct
instance GHC.IsList (Tensor s (FinSuppSeq s) v) where
type Item (Tensor s (FinSuppSeq s) v) = v
fromList :: [Item (Tensor s (FinSuppSeq s) v)] -> Tensor s (FinSuppSeq s) v
fromList = forall s v w. TensorProduct v w -> Tensor s v w
Tensor
toList :: Tensor s (FinSuppSeq s) v -> [Item (Tensor s (FinSuppSeq s) v)]
toList = forall s v w. Tensor s v w -> TensorProduct v w
getTensorProduct
newtype SymmetricTensor s v
= SymTensor { forall s v. SymmetricTensor s v -> Tensor s v v
getSymmetricTensor :: Tensor s v v }
deriving instance (Show (Tensor s v v)) => Show (SymmetricTensor s v)
instance (TensorSpace v, Scalar v ~ s) => AffineSpace (SymmetricTensor s v) where
type Diff (SymmetricTensor s v) = SymmetricTensor s v
.+^ :: SymmetricTensor s v
-> Diff (SymmetricTensor s v) -> SymmetricTensor s v
(.+^) = forall v. AdditiveGroup v => v -> v -> v
(^+^)
.-. :: SymmetricTensor s v
-> SymmetricTensor s v -> Diff (SymmetricTensor s v)
(.-.) = forall v. AdditiveGroup v => v -> v -> v
(^-^)
instance (TensorSpace v, Scalar v ~ s) => AdditiveGroup (SymmetricTensor s v) where
SymTensor Tensor s v v
s ^+^ :: SymmetricTensor s v -> SymmetricTensor s v -> SymmetricTensor s v
^+^ SymTensor Tensor s v v
t = forall s v. Tensor s v v -> SymmetricTensor s v
SymTensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s v v
s forall v. AdditiveGroup v => v -> v -> v
^+^ Tensor s v v
t
zeroV :: SymmetricTensor s v
zeroV = forall s v. Tensor s v v -> SymmetricTensor s v
SymTensor forall v. AdditiveGroup v => v
zeroV
negateV :: SymmetricTensor s v -> SymmetricTensor s v
negateV (SymTensor Tensor s v v
t) = forall s v. Tensor s v v -> SymmetricTensor s v
SymTensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v. AdditiveGroup v => v -> v
negateV Tensor s v v
t
instance (TensorSpace v, Scalar v ~ s)
=> VectorSpace (SymmetricTensor s v) where
type Scalar (SymmetricTensor s v) = s
Scalar (SymmetricTensor s v)
μ *^ :: Scalar (SymmetricTensor s v)
-> SymmetricTensor s v -> SymmetricTensor s v
*^ SymTensor Tensor s v v
f = forall s v. Tensor s v v -> SymmetricTensor s v
SymTensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Scalar (SymmetricTensor s v)
μforall v. VectorSpace v => Scalar v -> v -> v
*^Tensor s v v
f
instance (TensorSpace v, Scalar v ~ s) => Semimanifold (SymmetricTensor s v) where
type Needle (SymmetricTensor s v) = SymmetricTensor s v
.+~^ :: SymmetricTensor s v
-> Needle (SymmetricTensor s v) -> SymmetricTensor s v
(.+~^) = forall v. AdditiveGroup v => v -> v -> v
(^+^)
#if !MIN_VERSION_manifolds_core(0,6,0)
fromInterior = id
toInterior = pure
translateP = Tagged (^+^)
#endif
instance (TensorSpace v, Scalar v ~ s) => PseudoAffine (SymmetricTensor s v) where
.-~! :: HasCallStack =>
SymmetricTensor s v
-> SymmetricTensor s v -> Needle (SymmetricTensor s v)
(.-~!) = forall v. AdditiveGroup v => v -> v -> v
(^-^)
SymmetricTensor s v
p.-~. :: SymmetricTensor s v
-> SymmetricTensor s v -> Maybe (Needle (SymmetricTensor s v))
.-~.SymmetricTensor s v
q = forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure (SymmetricTensor s v
pforall v. AdditiveGroup v => v -> v -> v
^-^SymmetricTensor s v
q)
instance ∀ s v . (Num' s, TensorSpace v, Scalar v ~ s)
=> DimensionAware (SymmetricTensor s v) where
type StaticDimension (SymmetricTensor s v)
= Maybe.FmapTriangularNum (StaticDimension v)
dimensionalityWitness :: DimensionalityWitness (SymmetricTensor s v)
dimensionalityWitness = case forall v. DimensionAware v => DimensionalityWitness v
dimensionalityWitness @v of
DimensionalityWitness v
IsFlexibleDimensional -> forall v. (StaticDimension v ~ 'Nothing) => DimensionalityWitness v
IsFlexibleDimensional
DimensionalityWitness v
IsStaticDimensional
-> forall (n :: Nat) r. Sing n -> (KnownNat n => r) -> r
withKnownNat (forall (a :: Nat). Sing a -> Sing (TriangularNum a)
Maybe.triangularNumSing (forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @v))
forall (n :: Nat) v. Dimensional n v => DimensionalityWitness v
IsStaticDimensional
instance ∀ s v n m . ( Num' s, n`Dimensional`v, TensorSpace v, Scalar v ~ s
, m ~ Maybe.TriangularNum n )
=> m`Dimensional`(SymmetricTensor s v) where
knownDimensionalitySing :: Sing m
knownDimensionalitySing = forall (a :: Nat). Sing a -> Sing (TriangularNum a)
Maybe.triangularNumSing forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v (n :: Nat). Dimensional n v => Sing n
dimensionalitySing @v
instance (Num' s, TensorSpace v, Scalar v ~ s) => TensorSpace (SymmetricTensor s v) where
type TensorProduct (SymmetricTensor s v) x = Tensor s v (Tensor s v x)
wellDefinedVector :: SymmetricTensor s v -> Maybe (SymmetricTensor s v)
wellDefinedVector (SymTensor Tensor s v v
t) = forall s v. Tensor s v v -> SymmetricTensor s v
SymTensor forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> forall v. TensorSpace v => v -> Maybe v
wellDefinedVector Tensor s v v
t
scalarSpaceWitness :: ScalarSpaceWitness (SymmetricTensor s v)
scalarSpaceWitness = case forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness s of
ClosedScalarWitness s
ClosedScalarWitness -> forall v.
(Num' (Scalar v), Scalar (Scalar v) ~ Scalar v) =>
ScalarSpaceWitness v
ScalarSpaceWitness
linearManifoldWitness :: LinearManifoldWitness (SymmetricTensor s v)
linearManifoldWitness = forall v.
(Semimanifold v, AffineSpace v, v ~ Needle v, v ~ Diff v) =>
LinearManifoldWitness v
autoLinearManifoldWitness
zeroTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (SymmetricTensor s v)) =>
SymmetricTensor s v ⊗ w
zeroTensor = forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall v. AdditiveGroup v => v
zeroV
toFlatTensor :: SymmetricTensor s v
-+> (SymmetricTensor s v ⊗ Scalar (SymmetricTensor s v))
toFlatTensor = case forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness s of
ClosedScalarWitness s
ClosedScalarWitness -> forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(SymTensor Tensor s v v
t)
-> forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
Object t (f b)) =>
r a b -> t (f a) (f b)
fmap forall v. TensorSpace v => v -+> (v ⊗ Scalar v)
toFlatTensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s v v
t
fromFlatTensor :: (SymmetricTensor s v ⊗ Scalar (SymmetricTensor s v))
-+> SymmetricTensor s v
fromFlatTensor = case forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness s of
ClosedScalarWitness s
ClosedScalarWitness -> forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Tensor TensorProduct (SymmetricTensor s v) s
t)
-> forall s v. Tensor s v v -> SymmetricTensor s v
SymTensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
Object t (f b)) =>
r a b -> t (f a) (f b)
fmap forall v. TensorSpace v => (v ⊗ Scalar v) -+> v
fromFlatTensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ TensorProduct (SymmetricTensor s v) s
t
addTensors :: forall w.
(TensorSpace w, Scalar w ~ Scalar (SymmetricTensor s v)) =>
(SymmetricTensor s v ⊗ w)
-> (SymmetricTensor s v ⊗ w) -> SymmetricTensor s v ⊗ w
addTensors (Tensor TensorProduct (SymmetricTensor s v) w
f) (Tensor TensorProduct (SymmetricTensor s v) w
g) = forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ TensorProduct (SymmetricTensor s v) w
fforall v. AdditiveGroup v => v -> v -> v
^+^TensorProduct (SymmetricTensor s v) w
g
subtractTensors :: forall w.
(TensorSpace (SymmetricTensor s v), TensorSpace w,
Scalar w ~ Scalar (SymmetricTensor s v)) =>
(SymmetricTensor s v ⊗ w)
-> (SymmetricTensor s v ⊗ w) -> SymmetricTensor s v ⊗ w
subtractTensors (Tensor TensorProduct (SymmetricTensor s v) w
f) (Tensor TensorProduct (SymmetricTensor s v) w
g) = forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ TensorProduct (SymmetricTensor s v) w
fforall v. AdditiveGroup v => v -> v -> v
^-^TensorProduct (SymmetricTensor s v) w
g
negateTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (SymmetricTensor s v)) =>
(SymmetricTensor s v ⊗ w) -+> (SymmetricTensor s v ⊗ w)
negateTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Tensor TensorProduct (SymmetricTensor s v) w
f) -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v. AdditiveGroup v => v -> v
negateV TensorProduct (SymmetricTensor s v) w
f
scaleTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (SymmetricTensor s v)) =>
Bilinear
(Scalar (SymmetricTensor s v))
(SymmetricTensor s v ⊗ w)
(SymmetricTensor s v ⊗ w)
scaleTensor = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \s
μ (Tensor TensorProduct (SymmetricTensor s v) w
f) -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ s
μ forall v. VectorSpace v => Scalar v -> v -> v
*^ TensorProduct (SymmetricTensor s v) w
f
tensorProduct :: forall w.
(TensorSpace w, Scalar w ~ Scalar (SymmetricTensor s v)) =>
Bilinear (SymmetricTensor s v) w (SymmetricTensor s v ⊗ w)
tensorProduct = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(SymTensor Tensor s v v
t) w
g
-> forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
Object t (f b)) =>
r a b -> t (f a) (f b)
fmap (forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction (forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v,
Num' (Scalar v)) =>
v -> w -> v ⊗ w
⊗w
g)) forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s v v
t
transposeTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (SymmetricTensor s v)) =>
(SymmetricTensor s v ⊗ w) -+> (w ⊗ SymmetricTensor s v)
transposeTensor = forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(Tensor TensorProduct (SymmetricTensor s v) w
f) -> forall s v w. LinearFunction s v w -> v -> w
getLinearFunction (
forall a. HasCallStack => a
undefined
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
(v ⊗ w) -+> (w ⊗ v)
transposeTensor forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
Object a c) =>
k b c -> a b c
arr forall s u v w.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
VSCCoercion
s (Tensor s u (Tensor s v w)) (Tensor s (Tensor s u v) w)
lassocTensor) TensorProduct (SymmetricTensor s v) w
f
fmapTensor :: forall w x.
(TensorSpace w, TensorSpace x,
Scalar w ~ Scalar (SymmetricTensor s v),
Scalar x ~ Scalar (SymmetricTensor s v)) =>
Bilinear
(w -+> x) (SymmetricTensor s v ⊗ w) (SymmetricTensor s v ⊗ x)
fmapTensor = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction s w x
f (Tensor TensorProduct (SymmetricTensor s v) w
t) -> forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
Object t (f b)) =>
r a b -> t (f a) (f b)
fmap (forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
Object t (f b)) =>
r a b -> t (f a) (f b)
fmap LinearFunction s w x
f) forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ TensorProduct (SymmetricTensor s v) w
t
fzipTensorWith :: forall u w x.
(TensorSpace u, TensorSpace w, TensorSpace x,
Scalar u ~ Scalar (SymmetricTensor s v),
Scalar w ~ Scalar (SymmetricTensor s v),
Scalar x ~ Scalar (SymmetricTensor s v)) =>
Bilinear
((w, x) -+> u)
(SymmetricTensor s v ⊗ w, SymmetricTensor s v ⊗ x)
(SymmetricTensor s v ⊗ u)
fzipTensorWith = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \LinearFunction s (w, x) u
f (Tensor TensorProduct (SymmetricTensor s v) w
s, Tensor TensorProduct (SymmetricTensor s v) x
t)
-> forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b c.
(Monoidal f r t, ObjectPair r a b, Object r c,
ObjectPair t (f a) (f b), Object t (f c)) =>
r (a, b) c -> t (f a, f b) (f c)
fzipWith (forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b c.
(Monoidal f r t, ObjectPair r a b, Object r c,
ObjectPair t (f a) (f b), Object t (f c)) =>
r (a, b) c -> t (f a, f b) (f c)
fzipWith LinearFunction s (w, x) u
f) forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (TensorProduct (SymmetricTensor s v) w
s,TensorProduct (SymmetricTensor s v) x
t)
coerceFmapTensorProduct :: forall (p :: * -> *) a b.
(Functor p, TensorSpace a, Scalar a ~ Scalar (SymmetricTensor s v),
TensorSpace b, Scalar b ~ Scalar (SymmetricTensor s v)) =>
p (SymmetricTensor s v)
-> VSCCoercion (Scalar (SymmetricTensor s v)) a b
-> Coercion
(TensorProduct (SymmetricTensor s v) a)
(TensorProduct (SymmetricTensor s v) b)
coerceFmapTensorProduct p (SymmetricTensor s v)
_ VSCCoercion (Scalar (SymmetricTensor s v)) a b
crc = forall a. HasCallStack => a
undefined
wellDefinedTensor :: forall w.
(TensorSpace w, Scalar w ~ Scalar (SymmetricTensor s v)) =>
(SymmetricTensor s v ⊗ w) -> Maybe (SymmetricTensor s v ⊗ w)
wellDefinedTensor (Tensor TensorProduct (SymmetricTensor s v) w
t) = forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> forall v. TensorSpace v => v -> Maybe v
wellDefinedVector TensorProduct (SymmetricTensor s v) w
t
instance ∀ s v . (Num' s, LinearSpace v, Scalar v ~ s)
=> LinearSpace (SymmetricTensor s v) where
type DualVector (SymmetricTensor s v) = SymmetricTensor s (DualVector v)
dualSpaceWitness :: DualSpaceWitness (SymmetricTensor s v)
dualSpaceWitness = case ( forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness s
, forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v ) of
(ClosedScalarWitness s
ClosedScalarWitness, DualSpaceWitness v
DualSpaceWitness) -> forall v.
(LinearSpace (Scalar v), DualVector (Scalar v) ~ Scalar v,
LinearSpace (DualVector v), Scalar (DualVector v) ~ Scalar v,
DualVector (DualVector v) ~ v,
StaticDimension (DualVector v) ~ StaticDimension v) =>
DualSpaceWitness v
DualSpaceWitness
linearId :: SymmetricTensor s v +> SymmetricTensor s v
linearId = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v of
DualSpaceWitness v
DualSpaceWitness -> forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap forall a. HasCallStack => a
undefined
tensorId :: forall w.
(LinearSpace w, Scalar w ~ Scalar (SymmetricTensor s v)) =>
(SymmetricTensor s v ⊗ w) +> (SymmetricTensor s v ⊗ w)
tensorId = forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap forall a. HasCallStack => a
undefined
applyLinear :: forall w.
(TensorSpace w, Scalar w ~ Scalar (SymmetricTensor s v)) =>
Bilinear (SymmetricTensor s v +> w) (SymmetricTensor s v) w
applyLinear = case forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v of
DualSpaceWitness v
DualSpaceWitness -> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap TensorProduct (DualVector (SymmetricTensor s v)) w
f) (SymTensor Tensor s v v
t)
-> (forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v w.
(LinearSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
Bilinear (v +> w) v w
applyLinear
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s u v w.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
VSCCoercion
s (LinearMap s u (Tensor s v w)) (Tensor s (LinearMap s u v) w)
deferLinearMap forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMap forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ TensorProduct (DualVector (SymmetricTensor s v)) w
f) forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s v v
t
applyDualVector :: LinearSpace (SymmetricTensor s v) =>
Bilinear
(DualVector (SymmetricTensor s v))
(SymmetricTensor s v)
(Scalar (SymmetricTensor s v))
applyDualVector = forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(SymTensor Tensor s (DualVector v) (DualVector v)
f) (SymTensor Tensor s v v
v)
-> forall s v w. LinearFunction s v w -> v -> w
getLinearFunction
(forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v.
(LinearSpace v, LinearSpace v) =>
Bilinear (DualVector v) v (Scalar v)
applyDualVector forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall s a b. VSCCoercion s a b -> a -> b
-+$=> Tensor s (DualVector v) (DualVector v)
f) Tensor s v v
v
applyTensorFunctional :: ∀ u . (LinearSpace u, Scalar u ~ s)
=> LinearFunction s
(LinearMap s (SymmetricTensor s v) (DualVector u))
(LinearFunction s (Tensor s (SymmetricTensor s v) u) s)
applyTensorFunctional :: forall u.
(LinearSpace u, Scalar u ~ s) =>
LinearFunction
s
(LinearMap s (SymmetricTensor s v) (DualVector u))
(LinearFunction s (Tensor s (SymmetricTensor s v) u) s)
applyTensorFunctional = case (forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @v, forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @u) of
(DualSpaceWitness v
DualSpaceWitness, DualSpaceWitness u
DualSpaceWitness)
-> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap TensorProduct (DualVector (SymmetricTensor s v)) (DualVector u)
f) (Tensor TensorProduct (SymmetricTensor s v) u
t)
-> forall s v w. LinearFunction s v w -> v -> w
getLinearFunction
(forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v u.
(LinearSpace v, LinearSpace u, Scalar u ~ Scalar v) =>
Bilinear (DualVector (v ⊗ u)) (v ⊗ u) (Scalar v)
applyTensorFunctional
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
Object t (f b)) =>
r a b -> t (f a) (f b)
fmap forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall s a b. VSCCoercion s a b -> a -> b
-+$=> TensorProduct (DualVector (SymmetricTensor s v)) (DualVector u)
f) TensorProduct (SymmetricTensor s v) u
t
applyTensorLinMap :: ∀ u w . ( LinearSpace u, Scalar u ~ s
, TensorSpace w, Scalar w ~ s )
=> LinearFunction s
(LinearMap s (Tensor s (SymmetricTensor s v) u) w)
(LinearFunction s (Tensor s (SymmetricTensor s v) u) w)
applyTensorLinMap :: forall u w.
(LinearSpace u, Scalar u ~ s, TensorSpace w, Scalar w ~ s) =>
LinearFunction
s
(LinearMap s (Tensor s (SymmetricTensor s v) u) w)
(LinearFunction s (Tensor s (SymmetricTensor s v) u) w)
applyTensorLinMap = case (forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @v, forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @u) of
(DualSpaceWitness v
DualSpaceWitness, DualSpaceWitness u
DualSpaceWitness)
-> forall v w y. (v -> w -> y) -> Bilinear v w y
bilinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(LinearMap (Tensor TensorProduct
(DualVector v)
(Tensor s (DualVector v) (Tensor s (DualVector u) w))
f)) (Tensor TensorProduct (SymmetricTensor s v) u
t)
-> forall s v w. LinearFunction s v w -> v -> w
getLinearFunction (forall s v w. LinearFunction s v w -> v -> w
getLinearFunction forall v u w.
(LinearSpace v, LinearSpace u, TensorSpace w, Scalar u ~ Scalar v,
Scalar w ~ Scalar v) =>
Bilinear ((v ⊗ u) +> w) (v ⊗ u) w
applyTensorLinMap
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall u v w s.
(LinearSpace u, LinearSpace v, TensorSpace w, Scalar u ~ s,
Scalar v ~ s, Scalar w ~ s) =>
VSCCoercion
s (LinearMap s u (LinearMap s v w)) (LinearMap s (Tensor s u v) w)
uncurryLinearMap
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
Object t (f b)) =>
r a b -> t (f a) (f b)
fmap (forall u v w s.
(LinearSpace u, LinearSpace v, TensorSpace w, Scalar u ~ s,
Scalar v ~ s, Scalar w ~ s) =>
VSCCoercion
s (LinearMap s u (LinearMap s v w)) (LinearMap s (Tensor s u v) w)
uncurryLinearMap forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
Object t (f b)) =>
r a b -> t (f a) (f b)
fmap forall s v w.
LinearSpace v =>
VSCCoercion s (Tensor s (DualVector v) w) (LinearMap s v w)
fromTensor)
forall s a b. VSCCoercion s a b -> a -> b
-+$=> forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap TensorProduct
(DualVector v)
(Tensor s (DualVector v) (Tensor s (DualVector u) w))
f) TensorProduct (SymmetricTensor s v) u
t
useTupleLinearSpaceComponents :: forall x y φ.
(SymmetricTensor s v ~ (x, y)) =>
((LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ) -> φ
useTupleLinearSpaceComponents (LinearSpace x, LinearSpace y, Scalar x ~ Scalar y) => φ
_ = forall a. a
usingNonTupleTypeAsTupleError
coerceDoubleDual :: VSCCoercion
(Scalar (SymmetricTensor s v))
(SymmetricTensor s v)
(DualVector (DualVector (SymmetricTensor s v)))
coerceDoubleDual = case (forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @v, forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness @s) of
(DualSpaceWitness v
DualSpaceWitness, ScalarSpaceWitness s
ScalarSpaceWitness) -> forall a b s.
(Coercible a b, StaticDimension a ~ StaticDimension b) =>
VSCCoercion s a b
VSCCoercion
squareV :: (Num' s, s ~ Scalar v)
=> TensorSpace v => v -> SymmetricTensor s v
squareV :: forall s v.
(Num' s, s ~ Scalar v, TensorSpace v) =>
v -> SymmetricTensor s v
squareV v
v = forall s v. Tensor s v v -> SymmetricTensor s v
SymTensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ v
vforall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v,
Num' (Scalar v)) =>
v -> w -> v ⊗ w
⊗v
v
squareVs :: (Num' s, s ~ Scalar v)
=> TensorSpace v => [v] -> SymmetricTensor s v
squareVs :: forall s v.
(Num' s, s ~ Scalar v, TensorSpace v) =>
[v] -> SymmetricTensor s v
squareVs [v]
vs = forall s v. Tensor s v v -> SymmetricTensor s v
SymTensor forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall v w.
(TensorSpace v, TensorSpace w, Scalar w ~ Scalar v) =>
[(v, w)] -> v ⊗ w
tensorProducts [(v
v,v
v) | v
v<-[v]
vs]
type v⊗〃+>w = LinearMap (Scalar v) (SymmetricTensor (Scalar v) v) w
currySymBilin :: LinearSpace v => (v⊗〃+>w) -+> (v+>(v+>w))
currySymBilin :: forall v w. LinearSpace v => (v ⊗〃+> w) -+> (v +> (v +> w))
currySymBilin = forall a. HasCallStack => a
undefined
newtype LinearApplicativeSpace f y
= LinearApplicativeSpace { forall (f :: * -> *) y. LinearApplicativeSpace f y -> f y
getLinearApplicativeSpace :: f y }
instance ( GHC.Generic1 f, TensorSpace y
, TensorSpace (f y), Scalar (f y) ~ Scalar y
, Monoidal f (LinearFunction (Scalar y)) (LinearFunction (Scalar y)) )
=> AffineSpace (LinearApplicativeSpace f y) where
type Diff (LinearApplicativeSpace f y) = LinearApplicativeSpace f y
.+^ :: LinearApplicativeSpace f y
-> Diff (LinearApplicativeSpace f y) -> LinearApplicativeSpace f y
(.+^) = forall v. AdditiveGroup v => v -> v -> v
(^+^)
.-. :: LinearApplicativeSpace f y
-> LinearApplicativeSpace f y -> Diff (LinearApplicativeSpace f y)
(.-.) = forall v. AdditiveGroup v => v -> v -> v
(^-^)
instance ∀ f y . ( GHC.Generic1 f, TensorSpace y
, TensorSpace (f y), Scalar (f y) ~ Scalar y
, Monoidal f (LinearFunction (Scalar y)) (LinearFunction (Scalar y)) )
=> AdditiveGroup (LinearApplicativeSpace f y) where
zeroV :: LinearApplicativeSpace f y
zeroV = forall (f :: * -> *) y. f y -> LinearApplicativeSpace f y
LinearApplicativeSpace forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall s v w. LinearFunction s v w -> v -> w
getLinearFunction
( forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
Object t (f b)) =>
r a b -> t (f a) (f b)
fmap forall v. AdditiveGroup v => v
zeroV
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *).
Monoidal f r t =>
t (UnitObject t) (f (UnitObject r))
pureUnit :: LinearFunction (Scalar y) (ZeroDim (Scalar y))
(f (ZeroDim (Scalar y)))) ) forall v. AdditiveGroup v => v
zeroV
LinearApplicativeSpace f y
a^+^ :: LinearApplicativeSpace f y
-> LinearApplicativeSpace f y -> LinearApplicativeSpace f y
^+^LinearApplicativeSpace f y
b
= forall (f :: * -> *) y. f y -> LinearApplicativeSpace f y
LinearApplicativeSpace
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall s v w. LinearFunction s v w -> v -> w
getLinearFunction
(forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b c.
(Monoidal f r t, ObjectPair r a b, Object r c,
ObjectPair t (f a) (f b), Object t (f c)) =>
r (a, b) c -> t (f a, f b) (f c)
fzipWith (forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (k :: * -> * -> *) a b c.
(Curry k, ObjectPair k a b, ObjectMorphism k b c) =>
k a (k b c) -> k (a, b) c
uncurry forall v. AdditiveGroup v => v -> v -> v
(^+^)))
(f y
a,f y
b)
LinearApplicativeSpace f y
a^-^ :: LinearApplicativeSpace f y
-> LinearApplicativeSpace f y -> LinearApplicativeSpace f y
^-^LinearApplicativeSpace f y
b
= forall (f :: * -> *) y. f y -> LinearApplicativeSpace f y
LinearApplicativeSpace
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall s v w. LinearFunction s v w -> v -> w
getLinearFunction
(forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b c.
(Monoidal f r t, ObjectPair r a b, Object r c,
ObjectPair t (f a) (f b), Object t (f c)) =>
r (a, b) c -> t (f a, f b) (f c)
fzipWith (forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall (k :: * -> * -> *) a b c.
(Curry k, ObjectPair k a b, ObjectMorphism k b c) =>
k a (k b c) -> k (a, b) c
uncurry forall v. AdditiveGroup v => v -> v -> v
(^-^)))
(f y
a,f y
b)
negateV :: LinearApplicativeSpace f y -> LinearApplicativeSpace f y
negateV (LinearApplicativeSpace f y
a) = forall (f :: * -> *) y. f y -> LinearApplicativeSpace f y
LinearApplicativeSpace
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall s v w. LinearFunction s v w -> v -> w
getLinearFunction (forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
Object t (f b)) =>
r a b -> t (f a) (f b)
fmap forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ forall s v w. (v -> w) -> LinearFunction s v w
LinearFunction forall v. AdditiveGroup v => v -> v
negateV) f y
a
instance ( GHC.Generic1 f, TensorSpace y
, TensorSpace (f y), Scalar (f y) ~ Scalar y
, Monoidal f (LinearFunction (Scalar y)) (LinearFunction (Scalar y)) )
=> VectorSpace (LinearApplicativeSpace f y) where
type Scalar (LinearApplicativeSpace f y) = Scalar y
*^ :: Scalar (LinearApplicativeSpace f y)
-> LinearApplicativeSpace f y -> LinearApplicativeSpace f y
(*^) = forall a. HasCallStack => a
undefined
instance ( GHC.Generic1 f, TensorSpace y
, TensorSpace (f y), Scalar (f y) ~ Scalar y
, Monoidal f (LinearFunction (Scalar y)) (LinearFunction (Scalar y)) )
=> Semimanifold (LinearApplicativeSpace f y) where
type Needle (LinearApplicativeSpace f y) = LinearApplicativeSpace f y
#if !MIN_VERSION_manifolds_core(0,6,0)
type Interior (LinearApplicativeSpace f y) = LinearApplicativeSpace f y
toInterior = Just; fromInterior = id
translateP = Tagged (^+^)
#endif
.+~^ :: LinearApplicativeSpace f y
-> Needle (LinearApplicativeSpace f y)
-> LinearApplicativeSpace f y
(.+~^) = forall v. AdditiveGroup v => v -> v -> v
(^+^)
instance ( GHC.Generic1 f, TensorSpace y
, TensorSpace (f y), Scalar (f y) ~ Scalar y
, Monoidal f (LinearFunction (Scalar y)) (LinearFunction (Scalar y)) )
=> PseudoAffine (LinearApplicativeSpace f y) where
.-~! :: HasCallStack =>
LinearApplicativeSpace f y
-> LinearApplicativeSpace f y
-> Needle (LinearApplicativeSpace f y)
(.-~!) = forall p. AffineSpace p => p -> p -> Diff p
(.-.)
LinearApplicativeSpace f y
p.-~. :: LinearApplicativeSpace f y
-> LinearApplicativeSpace f y
-> Maybe (Needle (LinearApplicativeSpace f y))
.-~.LinearApplicativeSpace f y
q = forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure (LinearApplicativeSpace f y
pforall p. AffineSpace p => p -> p -> Diff p
.-.LinearApplicativeSpace f y
q)
instance (InnerSpace v, Scalar v ~ ℝ, TensorSpace v)
=> InnerSpace (Tensor ℝ ℝ v) where
Tensor TensorProduct ℝ v
t <.> :: Tensor ℝ ℝ v -> Tensor ℝ ℝ v -> Scalar (Tensor ℝ ℝ v)
<.> Tensor TensorProduct ℝ v
u = TensorProduct ℝ v
t forall v. InnerSpace v => v -> v -> Scalar v
<.> TensorProduct ℝ v
u
instance (InnerSpace v, TensorSpace v, Scalar v ~ ℝ)
=> InnerSpace (LinearMap ℝ ℝ v) where
LinearMap TensorProduct (DualVector ℝ) v
f <.> :: LinearMap ℝ ℝ v -> LinearMap ℝ ℝ v -> Scalar (LinearMap ℝ ℝ v)
<.> LinearMap TensorProduct (DualVector ℝ) v
g = TensorProduct (DualVector ℝ) v
fforall v. InnerSpace v => v -> v -> Scalar v
<.>TensorProduct (DualVector ℝ) v
g
instance ( TensorSpace u, TensorSpace v, TensorSpace w
, Num s, Scalar u ~ s, Scalar v ~ s, Scalar w ~ s
, InnerSpace (Tensor s u w), InnerSpace (Tensor s v w) )
=> InnerSpace (Tensor s (u,v) w) where
Tensor (Tensor s u w
uw,Tensor s v w
vw) <.> :: Tensor s (u, v) w
-> Tensor s (u, v) w -> Scalar (Tensor s (u, v) w)
<.> Tensor (Tensor s u w
uw',Tensor s v w
vw') = Tensor s u w
uwforall v. InnerSpace v => v -> v -> Scalar v
<.>Tensor s u w
uw' forall a. Num a => a -> a -> a
+ Tensor s v w
vwforall v. InnerSpace v => v -> v -> Scalar v
<.>Tensor s v w
vw'
instance ( LinearSpace u, LinearSpace v, TensorSpace w
, Num s, Scalar u ~ s, Scalar v ~ s, Scalar w ~ s
, InnerSpace (LinearMap s u w), InnerSpace (LinearMap s v w) )
=> InnerSpace (LinearMap s (u,v) w) where
<.> :: LinearMap s (u, v) w
-> LinearMap s (u, v) w -> Scalar (LinearMap s (u, v) w)
(<.>) = case (forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @u, forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @v) of
(DualSpaceWitness u
DualSpaceWitness, DualSpaceWitness v
DualSpaceWitness)
-> \(LinearMap (Tensor s (DualVector u) w
uw,Tensor s (DualVector v) w
vw)) (LinearMap (Tensor s (DualVector u) w
uw',Tensor s (DualVector v) w
vw'))
-> (forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMapforall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$Tensor s (DualVector u) w
uw)forall v. InnerSpace v => v -> v -> Scalar v
<.>(forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMapforall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$Tensor s (DualVector u) w
uw')
forall a. Num a => a -> a -> a
+ (forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMapforall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$Tensor s (DualVector v) w
vw)forall v. InnerSpace v => v -> v -> Scalar v
<.>(forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMapforall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$Tensor s (DualVector v) w
vw')
instance ( TensorSpace u, TensorSpace v, TensorSpace w
, Num s, Scalar u ~ s, Scalar v ~ s, Scalar w ~ s
, InnerSpace (Tensor s u (Tensor s v w)) )
=> InnerSpace (Tensor s (Tensor s u v) w) where
Tensor s (Tensor s u v) w
s <.> :: Tensor s (Tensor s u v) w
-> Tensor s (Tensor s u v) w -> Scalar (Tensor s (Tensor s u v) w)
<.> Tensor s (Tensor s u v) w
t = (forall s u v w.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
VSCCoercion
s (Tensor s (Tensor s u v) w) (Tensor s u (Tensor s v w))
rassocTensorforall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$Tensor s (Tensor s u v) w
s)forall v. InnerSpace v => v -> v -> Scalar v
<.>(forall s u v w.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
VSCCoercion
s (Tensor s (Tensor s u v) w) (Tensor s u (Tensor s v w))
rassocTensorforall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$Tensor s (Tensor s u v) w
t)
instance ( LinearSpace u, TensorSpace v, TensorSpace w
, Num s, Scalar u ~ s, Scalar v ~ s, Scalar w ~ s
, InnerSpace (LinearMap s u (Tensor s v w)) )
=> InnerSpace (Tensor s (LinearMap s u v) w) where
Tensor s (LinearMap s u v) w
s <.> :: Tensor s (LinearMap s u v) w
-> Tensor s (LinearMap s u v) w
-> Scalar (Tensor s (LinearMap s u v) w)
<.> Tensor s (LinearMap s u v) w
t = (forall s u v w.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
VSCCoercion
s (Tensor s (LinearMap s u v) w) (LinearMap s u (Tensor s v w))
hasteLinearMapforall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$Tensor s (LinearMap s u v) w
s)forall v. InnerSpace v => v -> v -> Scalar v
<.>(forall s u v w.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
VSCCoercion
s (Tensor s (LinearMap s u v) w) (LinearMap s u (Tensor s v w))
hasteLinearMapforall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$Tensor s (LinearMap s u v) w
t)
instance ( LinearSpace u, LinearSpace v, TensorSpace w
, Num s, Scalar u ~ s, Scalar v ~ s, Scalar w ~ s
, InnerSpace (LinearMap s u (LinearMap s v w)) )
=> InnerSpace (LinearMap s (Tensor s u v) w) where
LinearMap s (Tensor s u v) w
s <.> :: LinearMap s (Tensor s u v) w
-> LinearMap s (Tensor s u v) w
-> Scalar (LinearMap s (Tensor s u v) w)
<.> LinearMap s (Tensor s u v) w
t = (forall u v w s.
(LinearSpace u, LinearSpace v, TensorSpace w, Scalar u ~ s,
Scalar v ~ s, Scalar w ~ s) =>
VSCCoercion
s (LinearMap s (Tensor s u v) w) (LinearMap s u (LinearMap s v w))
curryLinearMapforall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$LinearMap s (Tensor s u v) w
s)forall v. InnerSpace v => v -> v -> Scalar v
<.>(forall u v w s.
(LinearSpace u, LinearSpace v, TensorSpace w, Scalar u ~ s,
Scalar v ~ s, Scalar w ~ s) =>
VSCCoercion
s (LinearMap s (Tensor s u v) w) (LinearMap s u (LinearMap s v w))
curryLinearMapforall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$LinearMap s (Tensor s u v) w
t)
instance ( LinearSpace u, LinearSpace v, TensorSpace w
, Num s, Scalar u ~ s, Scalar v ~ s, Scalar w ~ s
, InnerSpace (Tensor s u (LinearMap s v w)) )
=> InnerSpace (LinearMap s (LinearMap s u v) w) where
LinearMap s (LinearMap s u v) w
s <.> :: LinearMap s (LinearMap s u v) w
-> LinearMap s (LinearMap s u v) w
-> Scalar (LinearMap s (LinearMap s u v) w)
<.> LinearMap s (LinearMap s u v) w
t = (forall s u v w.
(LinearSpace u, Scalar u ~ s, LinearSpace v, Scalar v ~ s,
TensorSpace w, Scalar w ~ s) =>
VSCCoercion
s (LinearMap s (LinearMap s u v) w) (Tensor s u (LinearMap s v w))
coCurryLinearMapforall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$LinearMap s (LinearMap s u v) w
s)forall v. InnerSpace v => v -> v -> Scalar v
<.>(forall s u v w.
(LinearSpace u, Scalar u ~ s, LinearSpace v, Scalar v ~ s,
TensorSpace w, Scalar w ~ s) =>
VSCCoercion
s (LinearMap s (LinearMap s u v) w) (Tensor s u (LinearMap s v w))
coCurryLinearMapforall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$LinearMap s (LinearMap s u v) w
t)
instance (Show v) => Show (Tensor ℝ ℝ v) where
showsPrec :: Int -> Tensor ℝ ℝ v -> ShowS
showsPrec Int
p (Tensor TensorProduct ℝ v
t) = Bool -> ShowS -> ShowS
showParen (Int
pforall a. Ord a => a -> a -> Bool
>Int
9) forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (String
"Tensor "forall a. [a] -> [a] -> [a]
++) forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
10 TensorProduct ℝ v
t
instance (QC.Arbitrary v, Scalar v ~ ℝ) => QC.Arbitrary (Tensor ℝ ℝ v) where
arbitrary :: Gen (Tensor ℝ ℝ v)
arbitrary = forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> forall a. Arbitrary a => Gen a
QC.arbitrary
shrink :: Tensor ℝ ℝ v -> [Tensor ℝ ℝ v]
shrink (Tensor TensorProduct ℝ v
t) = forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> forall a. Arbitrary a => a -> [a]
QC.shrink TensorProduct ℝ v
t
instance (QC.Arbitrary v, Scalar v ~ ℝ) => QC.Arbitrary (LinearMap ℝ ℝ v) where
arbitrary :: Gen (LinearMap ℝ ℝ v)
arbitrary = forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> forall a. Arbitrary a => Gen a
QC.arbitrary
shrink :: LinearMap ℝ ℝ v -> [LinearMap ℝ ℝ v]
shrink (LinearMap TensorProduct (DualVector ℝ) v
t) = forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> forall a. Arbitrary a => a -> [a]
QC.shrink TensorProduct (DualVector ℝ) v
t
#define FreeArbitrarySpace(S) \
instance (QC.Arbitrary v, Scalar v ~ ℝ) => QC.Arbitrary (Tensor ℝ (S ℝ) v) where { \
arbitrary = Tensor <$> Hask.traverse (const QC.arbitrary) zeroV }; \
instance (QC.Arbitrary v, Scalar v ~ ℝ) => QC.Arbitrary (LinearMap ℝ (S ℝ) v) where { \
arbitrary = LinearMap <$> Hask.traverse (const QC.arbitrary) zeroV }
FreeArbitrarySpace(V0)
FreeArbitrarySpace(V1)
FreeArbitrarySpace(V2)
FreeArbitrarySpace(V3)
FreeArbitrarySpace(V4)
instance ( QC.Arbitrary (Tensor s u w), QC.Arbitrary (Tensor s v w)
, Scalar u ~ s, Scalar v ~ s, Scalar w ~ s )
=> QC.Arbitrary (Tensor s (u,v) w) where
arbitrary :: Gen (Tensor s (u, v) w)
arbitrary = forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> forall a. Arbitrary a => Gen a
QC.arbitrary
shrink :: Tensor s (u, v) w -> [Tensor s (u, v) w]
shrink (Tensor TensorProduct (u, v) w
t) = forall s v w. TensorProduct v w -> Tensor s v w
Tensor forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> forall a. Arbitrary a => a -> [a]
QC.shrink TensorProduct (u, v) w
t
instance ( LinearSpace u, LinearSpace v, TensorSpace w
, QC.Arbitrary (LinearMap s u w), QC.Arbitrary (LinearMap s v w)
, Scalar u ~ s, Scalar v ~ s, Scalar w ~ s )
=> QC.Arbitrary (LinearMap s (u,v) w) where
arbitrary :: Gen (LinearMap s (u, v) w)
arbitrary = case (forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @u, forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @v) of
(DualSpaceWitness u
DualSpaceWitness, DualSpaceWitness v
DualSpaceWitness) -> forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> do
(,) forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> (forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
Object a c) =>
k b c -> a b c
arr forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (LinearMap s (DualVector v) w) (Tensor s v w)
fromLinearMap forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> forall a. Arbitrary a => Gen a
QC.arbitrary)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Applicative f r t, ObjectMorphism r a b,
ObjectMorphism t (f a) (f b), Object t (t (f a) (f b)),
ObjectPair r (r a b) a, ObjectPair t (f (r a b)) (f a), Object r a,
Object r b) =>
t (f (r a b)) (t (f a) (f b))
<*> (forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
Object a c) =>
k b c -> a b c
arr forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (LinearMap s (DualVector v) w) (Tensor s v w)
fromLinearMap forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> forall a. Arbitrary a => Gen a
QC.arbitrary)
shrink :: LinearMap s (u, v) w -> [LinearMap s (u, v) w]
shrink = case (forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @u, forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @v) of
(DualSpaceWitness u
DualSpaceWitness, DualSpaceWitness v
DualSpaceWitness) -> \(LinearMap (Tensor s (DualVector u) w
x,Tensor s (DualVector v) w
y)) -> forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> do
(LinearMap s u w
x',LinearMap s v w
y') <- forall a. Arbitrary a => a -> [a]
QC.shrink (forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMap forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s (DualVector u) w
x, forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (Tensor s v w) (LinearMap s (DualVector v) w)
asLinearMap forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Tensor s (DualVector v) w
y)
forall (m :: * -> *) a. Monad m (->) => a -> m a
return (forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (LinearMap s (DualVector v) w) (Tensor s v w)
fromLinearMap forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap s u w
x', forall s v w.
(LinearSpace v, Scalar v ~ s) =>
VSCCoercion s (LinearMap s (DualVector v) w) (Tensor s v w)
fromLinearMap forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap s v w
y')
instance ( TensorSpace u, TensorSpace v, TensorSpace w
, QC.Arbitrary (u⊗(v⊗w))
, Scalar u ~ s, Scalar v ~ s, Scalar w ~ s )
=> QC.Arbitrary (Tensor s (Tensor s u v) w) where
arbitrary :: Gen (Tensor s (Tensor s u v) w)
arbitrary = forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
Object a c) =>
k b c -> a b c
arr forall s u v w.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
VSCCoercion
s (Tensor s u (Tensor s v w)) (Tensor s (Tensor s u v) w)
lassocTensor forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> forall a. Arbitrary a => Gen a
QC.arbitrary
shrink :: Tensor s (Tensor s u v) w -> [Tensor s (Tensor s u v) w]
shrink (Tensor TensorProduct (Tensor s u v) w
t) = forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
Object a c) =>
k b c -> a b c
arr forall s u v w.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
VSCCoercion
s (Tensor s u (Tensor s v w)) (Tensor s (Tensor s u v) w)
lassocTensor forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> forall a. Arbitrary a => a -> [a]
QC.shrink (forall s v w. TensorProduct v w -> Tensor s v w
Tensor TensorProduct (Tensor s u v) w
t)
instance ( LinearSpace u, LinearSpace v, TensorSpace w
, QC.Arbitrary (u+>(v+>w))
, Scalar u ~ s, Scalar v ~ s, Scalar w ~ s )
=> QC.Arbitrary (LinearMap s (Tensor s u v) w) where
arbitrary :: Gen (LinearMap s (Tensor s u v) w)
arbitrary = forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
Object a c) =>
k b c -> a b c
arr forall u v w s.
(LinearSpace u, LinearSpace v, TensorSpace w, Scalar u ~ s,
Scalar v ~ s, Scalar w ~ s) =>
VSCCoercion
s (LinearMap s u (LinearMap s v w)) (LinearMap s (Tensor s u v) w)
uncurryLinearMap forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> forall a. Arbitrary a => Gen a
QC.arbitrary
shrink :: LinearMap s (Tensor s u v) w -> [LinearMap s (Tensor s u v) w]
shrink LinearMap s (Tensor s u v) w
f = forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
Object a c) =>
k b c -> a b c
arr forall u v w s.
(LinearSpace u, LinearSpace v, TensorSpace w, Scalar u ~ s,
Scalar v ~ s, Scalar w ~ s) =>
VSCCoercion
s (LinearMap s u (LinearMap s v w)) (LinearMap s (Tensor s u v) w)
uncurryLinearMap forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> forall a. Arbitrary a => a -> [a]
QC.shrink (forall u v w s.
(LinearSpace u, LinearSpace v, TensorSpace w, Scalar u ~ s,
Scalar v ~ s, Scalar w ~ s) =>
VSCCoercion
s (LinearMap s (Tensor s u v) w) (LinearMap s u (LinearMap s v w))
curryLinearMap forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap s (Tensor s u v) w
f)
instance ( LinearSpace u, TensorSpace v, TensorSpace w
, QC.Arbitrary (u+>(v⊗w))
, Scalar u ~ s, Scalar v ~ s, Scalar w ~ s )
=> QC.Arbitrary (Tensor s (LinearMap s u v) w) where
arbitrary :: Gen (Tensor s (LinearMap s u v) w)
arbitrary = forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
Object a c) =>
k b c -> a b c
arr forall s u v w.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
VSCCoercion
s (LinearMap s u (Tensor s v w)) (Tensor s (LinearMap s u v) w)
deferLinearMap forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> forall a. Arbitrary a => Gen a
QC.arbitrary
shrink :: Tensor s (LinearMap s u v) w -> [Tensor s (LinearMap s u v) w]
shrink (Tensor TensorProduct (LinearMap s u v) w
t) = forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
Object a c) =>
k b c -> a b c
arr forall s u v w.
(TensorSpace u, TensorSpace v, TensorSpace w) =>
VSCCoercion
s (LinearMap s u (Tensor s v w)) (Tensor s (LinearMap s u v) w)
deferLinearMap forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> forall a. Arbitrary a => a -> [a]
QC.shrink (forall s v w. TensorProduct (DualVector v) w -> LinearMap s v w
LinearMap TensorProduct (LinearMap s u v) w
t)
instance ( LinearSpace u, LinearSpace v, TensorSpace w
, QC.Arbitrary (u⊗(v+>w))
, Scalar u ~ s, Scalar v ~ s, Scalar w ~ s )
=> QC.Arbitrary (LinearMap s (LinearMap s u v) w) where
arbitrary :: Gen (LinearMap s (LinearMap s u v) w)
arbitrary = forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
Object a c) =>
k b c -> a b c
arr forall s u v w.
(LinearSpace u, Scalar u ~ s, LinearSpace v, Scalar v ~ s,
TensorSpace w, Scalar w ~ s) =>
VSCCoercion
s (Tensor s u (LinearMap s v w)) (LinearMap s (LinearMap s u v) w)
coUncurryLinearMap forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> forall a. Arbitrary a => Gen a
QC.arbitrary
shrink :: LinearMap s (LinearMap s u v) w
-> [LinearMap s (LinearMap s u v) w]
shrink LinearMap s (LinearMap s u v) w
f = forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
Object a c) =>
k b c -> a b c
arr forall s u v w.
(LinearSpace u, Scalar u ~ s, LinearSpace v, Scalar v ~ s,
TensorSpace w, Scalar w ~ s) =>
VSCCoercion
s (Tensor s u (LinearMap s v w)) (LinearMap s (LinearMap s u v) w)
coUncurryLinearMap forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> forall a. Arbitrary a => a -> [a]
QC.shrink (forall s u v w.
(LinearSpace u, Scalar u ~ s, LinearSpace v, Scalar v ~ s,
TensorSpace w, Scalar w ~ s) =>
VSCCoercion
s (LinearMap s (LinearMap s u v) w) (Tensor s u (LinearMap s v w))
coCurryLinearMap forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap s (LinearMap s u v) w
f)