module Data.Array.Accelerate.Examples.Internal.Util
where
import Numeric
import Data.List
import Data.Array.Accelerate as A ( Z(..), Elt, Scalar, fromList )
import Prelude as P
infixr 9 $$
($$) :: (c -> d) -> (a -> b -> c) -> a -> b -> d
($$) g f x y = g (f x y)
scalar :: Elt a => a -> Scalar a
scalar x = fromList Z [x]
showFFloatSIBase :: P.RealFloat a => Maybe Int -> a -> a -> ShowS
showFFloatSIBase p b n
= showString
. nubBy (\x y -> x == ' ' && y == ' ')
$ showFFloat p n' [ ' ', si_unit ]
where
n' = n / (b P.^^ (pow-4))
pow = P.max 0 . P.min 8 . (+) 4 . P.floor $ P.logBase b n
si_unit = "pnµm kMGT" P.!! pow