{-# LANGUAGE TypeFamilies #-} module Numeric.ADDual.VectorOps where import Data.Kind (Type) import qualified Data.Vector as V import qualified Data.Vector.Strict as VSr import qualified Data.Vector.Storable as VS import qualified Data.Vector.Unboxed as VU import Foreign.Storable (Storable) class VectorOps v where type VectorOpsScalar v :: Type vfromListN :: Int -> [VectorOpsScalar v] -> v vfromList :: [VectorOpsScalar v] -> v vtoList :: v -> [VectorOpsScalar v] vreplicate :: Int -> VectorOpsScalar v -> v class VectorOpsNum v where vsum :: v -> VectorOpsScalar v instance VectorOps (V.Vector a) where type VectorOpsScalar (V.Vector a) = a vfromListN = V.fromListN vfromList = V.fromList vtoList = V.toList vreplicate = V.replicate instance Num a => VectorOpsNum (V.Vector a) where vsum = V.sum instance VectorOps (VSr.Vector a) where type VectorOpsScalar (VSr.Vector a) = a vfromListN = VSr.fromListN vfromList = VSr.fromList vtoList = VSr.toList vreplicate = VSr.replicate instance Num a => VectorOpsNum (VSr.Vector a) where vsum = VSr.sum instance Storable a => VectorOps (VS.Vector a) where type VectorOpsScalar (VS.Vector a) = a vfromListN = VS.fromListN vfromList = VS.fromList vtoList = VS.toList vreplicate = VS.replicate instance (Storable a, Num a) => VectorOpsNum (VS.Vector a) where vsum = VS.sum instance VU.Unbox a => VectorOps (VU.Vector a) where type VectorOpsScalar (VU.Vector a) = a vfromListN = VU.fromListN vfromList = VU.fromList vtoList = VU.toList vreplicate = VU.replicate instance (VU.Unbox a, Num a) => VectorOpsNum (VU.Vector a) where vsum = VU.sum