{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module Data.Array.Accelerate.Linear.Metric
where
import Data.Array.Accelerate as A hiding ( pattern V2 )
import Data.Array.Accelerate.Linear.Type
import Data.Array.Accelerate.Linear.Epsilon
import Data.Array.Accelerate.Linear.Vector
import qualified Linear.Metric as L
class L.Metric f => Metric f where
dot :: forall a. (A.Num a, Box f a)
=> Exp (f a)
-> Exp (f a)
-> Exp a
dot = lift2 (L.dot :: f (Exp a) -> f (Exp a) -> Exp a)
quadrance
:: forall a. (A.Num a, Box f a)
=> Exp (f a)
-> Exp a
quadrance = lift1 (L.quadrance :: f (Exp a) -> Exp a)
qd :: forall a. (A.Num a, Box f a)
=> Exp (f a)
-> Exp (f a)
-> Exp a
qd = lift2 (L.qd :: f (Exp a) -> f (Exp a) -> Exp a)
distance
:: forall a. (A.Floating a, Box f a)
=> Exp (f a)
-> Exp (f a)
-> Exp a
distance = lift2 (L.distance :: f (Exp a) -> f (Exp a) -> Exp a)
norm :: forall a. (A.Floating a, Box f a)
=> Exp (f a)
-> Exp a
norm = lift1 (L.norm :: f (Exp a) -> Exp a)
signorm
:: forall a. (A.Floating a, Box f a)
=> Exp (f a)
-> Exp (f a)
signorm = lift1 (L.signorm :: f (Exp a) -> f (Exp a))
type IsMetric f a = (Metric f, Box f a)
normalize
:: (Elt (f a), A.Floating a, IsMetric f a, Epsilon a)
=> Exp (f a)
-> Exp (f a)
normalize v
= nearZero l || nearZero (1-l)
? ( v, v ^/ sqrt l )
where
l = quadrance v
project
:: forall f a. (A.Floating a, IsMetric f a)
=> Exp (f a)
-> Exp (f a)
-> Exp (f a)
project = lift2 (L.project :: f (Exp a) -> f (Exp a) -> f (Exp a))