{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module Data.Array.Accelerate.Linear.Matrix (
(!*!), (!+!), (!-!), (!*), (*!), (!!*), (*!!), (!!/),
M22, M23, M24, M32, M33, M34, M42, M43, M44,
m33_to_m44, m43_to_m44,
det22, det33, det44,
inv22, inv33, inv44,
identity,
transpose,
Trace(..),
fromQuaternion,
mkTransformation,
mkTransformationMat,
) where
import Data.Array.Accelerate as A hiding ( transpose, pattern V2, pattern V3, pattern V4 )
import Data.Array.Accelerate.Linear.Lift
import Data.Array.Accelerate.Linear.Trace
import Data.Array.Accelerate.Linear.Type
import Data.Array.Accelerate.Linear.Quaternion
import Data.Array.Accelerate.Linear.V3
import Data.Array.Accelerate.Linear.Vector
import Linear.Matrix ( M22, M23, M24, M32, M33, M34, M42, M43, M44 )
import qualified Linear.Matrix as L
import Data.Distributive
import Data.Foldable
import Data.Traversable
import Control.Applicative
import Prelude as P
infixl 7 !*!
(!*!) :: (Functor m, Foldable t, Additive t, Additive n, A.Num a, Box2 m t a, Box2 t n a, Box2 m n a)
=> Exp (m (t a))
-> Exp (t (n a))
-> Exp (m (n a))
f !*! g = lift (unlift' f L.!*! unlift' g)
infixl 6 !+!
(!+!) :: (Additive m, Additive n, A.Num a, Box2 m n a)
=> Exp (m (n a))
-> Exp (m (n a))
-> Exp (m (n a))
f !+! g = lift (unlift' f L.!+! unlift' g)
infixl 6 !-!
(!-!) :: (Additive m, Additive n, A.Num a, Box2 m n a)
=> Exp (m (n a))
-> Exp (m (n a))
-> Exp (m (n a))
f !-! g = lift (unlift' f L.!-! unlift' g)
infixl 7 !*
(!*) :: (Functor m, Foldable r, Additive r, A.Num a, Box2 m r a, Box m a)
=> Exp (m (r a))
-> Exp (r a)
-> Exp (m a)
m !* v = lift (unlift' m L.!* unlift v)
infixl 7 *!
(*!) :: (Foldable t, Additive f, Additive t, A.Num a, Box t a, Box f a, Box2 t f a)
=> Exp (t a)
-> Exp (t (f a))
-> Exp (f a)
f *! g = lift (unlift f L.*! unlift' g)
infixl 7 *!!
(*!!) :: (Functor m, Functor r, A.Num a, Box2 m r a)
=> Exp a
-> Exp (m (r a))
-> Exp (m (r a))
s *!! m = lift (unlift s L.*!! unlift' m)
infixl 7 !!*
(!!*) :: (Functor m, Functor r, A.Num a, Box2 m r a)
=> Exp (m (r a))
-> Exp a
-> Exp (m (r a))
(!!*) = flip (*!!)
infixl 7 !!/
(!!/) :: (Functor m, Functor r, A.Floating a, Box2 m r a)
=> Exp (m (r a))
-> Exp a
-> Exp (m (r a))
m !!/ s = lift (unlift' m L.!!/ unlift s)
identity :: forall t a. (Traversable t, Applicative t, A.Num a, Box2 t t a) => Exp (t (t a))
identity = lift (L.identity :: t (t (Exp a)))
transpose
:: (Distributive g, Functor f, Box2 f g a, Box2 g f a)
=> Exp (f (g a))
-> Exp (g (f a))
transpose = lift . L.transpose . unlift'
fromQuaternion :: forall a. A.Num a => Exp (Quaternion a) -> Exp (M33 a)
fromQuaternion = lift1 (L.fromQuaternion :: Quaternion (Exp a) -> M33 (Exp a))
mkTransformation :: forall a. A.Num a => Exp (Quaternion a) -> Exp (V3 a) -> Exp (M44 a)
mkTransformation = lift2 (L.mkTransformation :: Quaternion (Exp a) -> V3 (Exp a) -> M44 (Exp a))
mkTransformationMat :: A.Num a => Exp (M33 a) -> Exp (V3 a) -> Exp (M44 a)
mkTransformationMat m v =
let r = L.mkTransformationMat (unlift' m) (unlift v)
in lift r
m43_to_m44 :: A.Num a => Exp (M43 a) -> Exp (M44 a)
m43_to_m44 m43 =
let m44 = L.m43_to_m44 (unlift' m43)
in lift m44
m33_to_m44 :: A.Num a => Exp (M33 a) -> Exp (M44 a)
m33_to_m44 m33 =
let m44 = L.m33_to_m44 (unlift' m33)
in lift m44
det22 :: A.Num a => Exp (M22 a) -> Exp a
det22 = L.det22 . unlift'
det33 :: A.Num a => Exp (M33 a) -> Exp a
det33 = L.det33 . unlift'
det44 :: A.Num a => Exp (M44 a) -> Exp a
det44 = L.det44 . unlift'
inv22 :: A.Fractional a => Exp (M22 a) -> Exp (M22 a)
inv22 m =
let r = L.inv22 (unlift' m)
in lift r
inv33 :: A.Fractional a => Exp (M33 a) -> Exp (M33 a)
inv33 m =
let r = L.inv33 (unlift' m)
in lift r
inv44 :: A.Fractional a => Exp (M44 a) -> Exp (M44 a)
inv44 m =
let r = L.inv44 (unlift' m)
in lift r