{-# LANGUAGE ConstraintKinds   #-}
{-# LANGUAGE FlexibleContexts  #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeApplications  #-}
{-# LANGUAGE TypeFamilies      #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
-- |
-- Module      : Data.Array.Accelerate.Classes.Floating
-- Copyright   : [2016..2020] The Accelerate Team
-- License     : BSD3
--
-- Maintainer  : Trevor L. McDonell <trevor.mcdonell@gmail.com>
-- Stability   : experimental
-- Portability : non-portable (GHC extensions)
--

module Data.Array.Accelerate.Classes.Floating (

  Floating,
  P.pi,
  P.sin, P.cos, P.tan,
  P.asin, P.acos, P.atan,
  P.sinh, P.cosh, P.tanh,
  P.asinh, P.acosh, P.atanh,
  P.exp,
  P.sqrt,
  P.log,
  (P.**),
  P.logBase,

) where

import Data.Array.Accelerate.Smart
import Data.Array.Accelerate.Type

import Data.Array.Accelerate.Classes.Fractional

import qualified Prelude                                            as P


-- | Trigonometric and hyperbolic functions and related functions
--
type Floating a = (Fractional a, P.Floating (Exp a))


instance P.Floating (Exp Half) where
  pi :: Exp Half
pi      = Exp Half
forall r. (Elt r, IsFloating (EltR r)) => Exp r
mkPi
  sin :: Exp Half -> Exp Half
sin     = Exp Half -> Exp Half
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkSin
  cos :: Exp Half -> Exp Half
cos     = Exp Half -> Exp Half
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkCos
  tan :: Exp Half -> Exp Half
tan     = Exp Half -> Exp Half
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkTan
  asin :: Exp Half -> Exp Half
asin    = Exp Half -> Exp Half
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAsin
  acos :: Exp Half -> Exp Half
acos    = Exp Half -> Exp Half
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAcos
  atan :: Exp Half -> Exp Half
atan    = Exp Half -> Exp Half
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAtan
  sinh :: Exp Half -> Exp Half
sinh    = Exp Half -> Exp Half
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkSinh
  cosh :: Exp Half -> Exp Half
cosh    = Exp Half -> Exp Half
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkCosh
  tanh :: Exp Half -> Exp Half
tanh    = Exp Half -> Exp Half
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkTanh
  asinh :: Exp Half -> Exp Half
asinh   = Exp Half -> Exp Half
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAsinh
  acosh :: Exp Half -> Exp Half
acosh   = Exp Half -> Exp Half
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAcosh
  atanh :: Exp Half -> Exp Half
atanh   = Exp Half -> Exp Half
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAtanh
  exp :: Exp Half -> Exp Half
exp     = Exp Half -> Exp Half
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkExpFloating
  sqrt :: Exp Half -> Exp Half
sqrt    = Exp Half -> Exp Half
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkSqrt
  log :: Exp Half -> Exp Half
log     = Exp Half -> Exp Half
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkLog
  ** :: Exp Half -> Exp Half -> Exp Half
(**)    = Exp Half -> Exp Half -> Exp Half
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t -> Exp t
mkFPow
  logBase :: Exp Half -> Exp Half -> Exp Half
logBase = Exp Half -> Exp Half -> Exp Half
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t -> Exp t
mkLogBase

instance P.Floating (Exp Float) where
  pi :: Exp Float
pi      = Exp Float
forall r. (Elt r, IsFloating (EltR r)) => Exp r
mkPi
  sin :: Exp Float -> Exp Float
sin     = Exp Float -> Exp Float
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkSin
  cos :: Exp Float -> Exp Float
cos     = Exp Float -> Exp Float
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkCos
  tan :: Exp Float -> Exp Float
tan     = Exp Float -> Exp Float
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkTan
  asin :: Exp Float -> Exp Float
asin    = Exp Float -> Exp Float
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAsin
  acos :: Exp Float -> Exp Float
acos    = Exp Float -> Exp Float
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAcos
  atan :: Exp Float -> Exp Float
atan    = Exp Float -> Exp Float
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAtan
  sinh :: Exp Float -> Exp Float
sinh    = Exp Float -> Exp Float
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkSinh
  cosh :: Exp Float -> Exp Float
cosh    = Exp Float -> Exp Float
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkCosh
  tanh :: Exp Float -> Exp Float
tanh    = Exp Float -> Exp Float
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkTanh
  asinh :: Exp Float -> Exp Float
asinh   = Exp Float -> Exp Float
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAsinh
  acosh :: Exp Float -> Exp Float
acosh   = Exp Float -> Exp Float
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAcosh
  atanh :: Exp Float -> Exp Float
atanh   = Exp Float -> Exp Float
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAtanh
  exp :: Exp Float -> Exp Float
exp     = Exp Float -> Exp Float
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkExpFloating
  sqrt :: Exp Float -> Exp Float
sqrt    = Exp Float -> Exp Float
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkSqrt
  log :: Exp Float -> Exp Float
log     = Exp Float -> Exp Float
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkLog
  ** :: Exp Float -> Exp Float -> Exp Float
(**)    = Exp Float -> Exp Float -> Exp Float
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t -> Exp t
mkFPow
  logBase :: Exp Float -> Exp Float -> Exp Float
logBase = Exp Float -> Exp Float -> Exp Float
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t -> Exp t
mkLogBase

instance P.Floating (Exp Double) where
  pi :: Exp Double
pi      = Exp Double
forall r. (Elt r, IsFloating (EltR r)) => Exp r
mkPi
  sin :: Exp Double -> Exp Double
sin     = Exp Double -> Exp Double
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkSin
  cos :: Exp Double -> Exp Double
cos     = Exp Double -> Exp Double
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkCos
  tan :: Exp Double -> Exp Double
tan     = Exp Double -> Exp Double
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkTan
  asin :: Exp Double -> Exp Double
asin    = Exp Double -> Exp Double
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAsin
  acos :: Exp Double -> Exp Double
acos    = Exp Double -> Exp Double
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAcos
  atan :: Exp Double -> Exp Double
atan    = Exp Double -> Exp Double
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAtan
  sinh :: Exp Double -> Exp Double
sinh    = Exp Double -> Exp Double
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkSinh
  cosh :: Exp Double -> Exp Double
cosh    = Exp Double -> Exp Double
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkCosh
  tanh :: Exp Double -> Exp Double
tanh    = Exp Double -> Exp Double
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkTanh
  asinh :: Exp Double -> Exp Double
asinh   = Exp Double -> Exp Double
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAsinh
  acosh :: Exp Double -> Exp Double
acosh   = Exp Double -> Exp Double
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAcosh
  atanh :: Exp Double -> Exp Double
atanh   = Exp Double -> Exp Double
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAtanh
  exp :: Exp Double -> Exp Double
exp     = Exp Double -> Exp Double
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkExpFloating
  sqrt :: Exp Double -> Exp Double
sqrt    = Exp Double -> Exp Double
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkSqrt
  log :: Exp Double -> Exp Double
log     = Exp Double -> Exp Double
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkLog
  ** :: Exp Double -> Exp Double -> Exp Double
(**)    = Exp Double -> Exp Double -> Exp Double
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t -> Exp t
mkFPow
  logBase :: Exp Double -> Exp Double -> Exp Double
logBase = Exp Double -> Exp Double -> Exp Double
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t -> Exp t
mkLogBase

instance P.Floating (Exp CFloat) where
  pi :: Exp CFloat
pi      = Exp Float -> Exp CFloat
forall b a.
(Elt a, Elt b, IsScalar (EltR a), IsScalar (EltR b),
 BitSizeEq (EltR a) (EltR b)) =>
Exp a -> Exp b
mkBitcast ((Elt Float, IsFloating (EltR Float)) => Exp Float
forall r. (Elt r, IsFloating (EltR r)) => Exp r
mkPi @Float)
  sin :: Exp CFloat -> Exp CFloat
sin     = Exp CFloat -> Exp CFloat
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkSin
  cos :: Exp CFloat -> Exp CFloat
cos     = Exp CFloat -> Exp CFloat
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkCos
  tan :: Exp CFloat -> Exp CFloat
tan     = Exp CFloat -> Exp CFloat
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkTan
  asin :: Exp CFloat -> Exp CFloat
asin    = Exp CFloat -> Exp CFloat
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAsin
  acos :: Exp CFloat -> Exp CFloat
acos    = Exp CFloat -> Exp CFloat
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAcos
  atan :: Exp CFloat -> Exp CFloat
atan    = Exp CFloat -> Exp CFloat
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAtan
  sinh :: Exp CFloat -> Exp CFloat
sinh    = Exp CFloat -> Exp CFloat
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkSinh
  cosh :: Exp CFloat -> Exp CFloat
cosh    = Exp CFloat -> Exp CFloat
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkCosh
  tanh :: Exp CFloat -> Exp CFloat
tanh    = Exp CFloat -> Exp CFloat
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkTanh
  asinh :: Exp CFloat -> Exp CFloat
asinh   = Exp CFloat -> Exp CFloat
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAsinh
  acosh :: Exp CFloat -> Exp CFloat
acosh   = Exp CFloat -> Exp CFloat
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAcosh
  atanh :: Exp CFloat -> Exp CFloat
atanh   = Exp CFloat -> Exp CFloat
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAtanh
  exp :: Exp CFloat -> Exp CFloat
exp     = Exp CFloat -> Exp CFloat
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkExpFloating
  sqrt :: Exp CFloat -> Exp CFloat
sqrt    = Exp CFloat -> Exp CFloat
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkSqrt
  log :: Exp CFloat -> Exp CFloat
log     = Exp CFloat -> Exp CFloat
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkLog
  ** :: Exp CFloat -> Exp CFloat -> Exp CFloat
(**)    = Exp CFloat -> Exp CFloat -> Exp CFloat
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t -> Exp t
mkFPow
  logBase :: Exp CFloat -> Exp CFloat -> Exp CFloat
logBase = Exp CFloat -> Exp CFloat -> Exp CFloat
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t -> Exp t
mkLogBase

instance P.Floating (Exp CDouble) where
  pi :: Exp CDouble
pi      = Exp Double -> Exp CDouble
forall b a.
(Elt a, Elt b, IsScalar (EltR a), IsScalar (EltR b),
 BitSizeEq (EltR a) (EltR b)) =>
Exp a -> Exp b
mkBitcast ((Elt Double, IsFloating (EltR Double)) => Exp Double
forall r. (Elt r, IsFloating (EltR r)) => Exp r
mkPi @Double)
  sin :: Exp CDouble -> Exp CDouble
sin     = Exp CDouble -> Exp CDouble
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkSin
  cos :: Exp CDouble -> Exp CDouble
cos     = Exp CDouble -> Exp CDouble
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkCos
  tan :: Exp CDouble -> Exp CDouble
tan     = Exp CDouble -> Exp CDouble
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkTan
  asin :: Exp CDouble -> Exp CDouble
asin    = Exp CDouble -> Exp CDouble
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAsin
  acos :: Exp CDouble -> Exp CDouble
acos    = Exp CDouble -> Exp CDouble
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAcos
  atan :: Exp CDouble -> Exp CDouble
atan    = Exp CDouble -> Exp CDouble
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAtan
  sinh :: Exp CDouble -> Exp CDouble
sinh    = Exp CDouble -> Exp CDouble
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkSinh
  cosh :: Exp CDouble -> Exp CDouble
cosh    = Exp CDouble -> Exp CDouble
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkCosh
  tanh :: Exp CDouble -> Exp CDouble
tanh    = Exp CDouble -> Exp CDouble
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkTanh
  asinh :: Exp CDouble -> Exp CDouble
asinh   = Exp CDouble -> Exp CDouble
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAsinh
  acosh :: Exp CDouble -> Exp CDouble
acosh   = Exp CDouble -> Exp CDouble
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAcosh
  atanh :: Exp CDouble -> Exp CDouble
atanh   = Exp CDouble -> Exp CDouble
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkAtanh
  exp :: Exp CDouble -> Exp CDouble
exp     = Exp CDouble -> Exp CDouble
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkExpFloating
  sqrt :: Exp CDouble -> Exp CDouble
sqrt    = Exp CDouble -> Exp CDouble
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkSqrt
  log :: Exp CDouble -> Exp CDouble
log     = Exp CDouble -> Exp CDouble
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t
mkLog
  ** :: Exp CDouble -> Exp CDouble -> Exp CDouble
(**)    = Exp CDouble -> Exp CDouble -> Exp CDouble
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t -> Exp t
mkFPow
  logBase :: Exp CDouble -> Exp CDouble -> Exp CDouble
logBase = Exp CDouble -> Exp CDouble -> Exp CDouble
forall t. (Elt t, IsFloating (EltR t)) => Exp t -> Exp t -> Exp t
mkLogBase