blob: 38063e09f20e62d284f034f0cd9a2125d5e34bd6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
{-# 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
|