-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathArraySpec.hs
More file actions
156 lines (130 loc) · 5.16 KB
/
ArraySpec.hs
File metadata and controls
156 lines (130 loc) · 5.16 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
module ArrayFire.ArraySpec where
import Control.Exception
import Data.Complex
import Data.Word
import Foreign.C.Types
import GHC.Int
import Test.Hspec
import ArrayFire
spec :: Spec
spec =
describe "Array tests" $ do
it "Should perform Array tests" $ do
(1 + 1) `shouldBe` 2
it "Should fail to create 0 dimension arrays" $ do
let arr = mkArray @Int [0,0,0,0] [1..]
evaluate arr `shouldThrow` anyException
it "Should fail to create 0 length arrays" $ do
let arr = mkArray @Int [0,0,0,1] []
evaluate arr `shouldThrow` anyException
it "Should fail to create 0 length arrays w/ 0 dimensions" $ do
let arr = mkArray @Int [0,0,0,0] []
evaluate arr `shouldThrow` anyException
it "Should create a column vector" $ do
let arr = mkArray @Int [9,1,1,1] (repeat 9)
isColumn arr `shouldBe` True
it "Should create a row vector" $ do
let arr = mkArray @Int [1,9,1,1] (repeat 9)
isRow arr `shouldBe` True
it "Should create a vector" $ do
let arr = mkArray @Int [9,1,1,1] (repeat 9)
isVector arr `shouldBe` True
it "Should create a vector" $ do
let arr = mkArray @Int [1,9,1,1] (repeat 9)
isVector arr `shouldBe` True
it "Should copy an array" $ do
let arr = mkArray @Int [9,9,1,1] (repeat 9)
let newArray = copyArray arr
newArray `shouldBe` arr
it "Should modify manual eval flag" $ do
setManualEvalFlag False
(`shouldBe` False) =<< getManualEvalFlag
it "Should return the number of elements" $ do
let arr = mkArray @Int [9,9,1,1] [1..]
getElements arr `shouldBe` 81
-- it "Should give an empty array" $ do
-- let arr = mkArray @Int [-1,1,1,1] []
-- getElements arr `shouldBe` 0
-- isEmpty arr `shouldBe` True
it "Should create a scalar array" $ do
let arr = mkArray @Int [1] [1]
isScalar arr `shouldBe` True
it "Should get number of dims specified" $ do
let arr = mkArray @Int [1,1,1,1] [1]
getNumDims arr `shouldBe` 1
let arr = mkArray @Int [2,3,4,5] [1..]
getNumDims arr `shouldBe` 4
let arr = mkArray @Int [2,3,4] [1..]
getNumDims arr `shouldBe` 3
it "Should get value of dims specified" $ do
let arr = mkArray @Int [2,3,4,5] (repeat 1)
getDims arr `shouldBe` (2,3,4,5)
it "Should test Sparsity" $ do
let arr = mkArray @Double [2,2,1,1] (repeat 1)
isSparse arr `shouldBe` False
it "Should make a Bit array" $ do
let arr = mkArray @CBool [2,2] [1,1,1,1]
isBool arr `shouldBe` True
it "Should make an integer array" $ do
let arr = mkArray @Int [2,2] (repeat 1)
isInteger arr `shouldBe` True
it "Should make a Floating array" $ do
let arr = mkArray @Double [2,2] (repeat 1)
isFloating arr `shouldBe` True
let arr = mkArray @CBool [2,2] (repeat 1)
isFloating arr `shouldBe` False
it "Should make a Complex array" $ do
let arr = mkArray @(Complex Double) [2,2] (repeat 1)
isComplex arr `shouldBe` True
isReal arr `shouldBe` False
it "Should make a Real array" $ do
let arr = mkArray @Double [2,2] (repeat 1)
isReal arr `shouldBe` True
isComplex arr `shouldBe` False
it "Should make a Double precision array" $ do
let arr = mkArray @Double [2,2] (repeat 1)
isDouble arr `shouldBe` True
isSingle arr `shouldBe` False
it "Should make a Single precision array" $ do
let arr = mkArray @Float [2,2] (repeat 1)
isDouble arr `shouldBe` False
isSingle arr `shouldBe` True
it "Should make a Real floating array" $ do
let arr = mkArray @Float [2,2] (repeat 1)
isRealFloating arr `shouldBe` True
let arr = mkArray @Double [2,2] (repeat 1)
isRealFloating arr `shouldBe` True
it "Should get reference count" $ do
let arr1 = mkArray @Float [2,2] (repeat 1)
arr2 = retainArray arr1
arr3 = retainArray arr2
getDataRefCount arr3 `shouldBe` 3
it "Should convert an array to a list" $ do
let arr = mkArray @Double [30,30] (repeat 1)
toList arr `shouldBe` Prelude.replicate (30 * 30) 1
let arr = mkArray @Float [10,10] (repeat (5.5))
toList arr `shouldBe` Prelude.replicate 100 5.5
let arr = mkArray @CBool [4] [1,1,0,1]
toList arr `shouldBe` [1,1,0,1]
let arr = mkArray @Int16 [10] [1..]
toList arr `shouldBe` [1..10]
let arr = mkArray @Int32 [100] [1..100]
toList arr `shouldBe` [1..100]
let arr = mkArray @Int64 [100] [1..100]
toList arr `shouldBe` [1..100]
let arr = mkArray @Int [100] [1..100]
toList arr `shouldBe` [1..100]
let arr = mkArray @(Complex Float) [1] [1 :+ 1]
toList arr `shouldBe` [1 :+ 1]
let arr = mkArray @(Complex Double) [1] [1 :+ 1]
toList arr `shouldBe` [1 :+ 1]
let arr = mkArray @Word16 [10] [1..10]
toList arr `shouldBe` [1..10]
let arr = mkArray @Word32 [10] [1..10]
toList arr `shouldBe` [1..10]
let arr = mkArray @Word64 [10] [1..10]
toList arr `shouldBe` [1..10]
let arr = mkArray @Word [10] [1..10]
toList arr `shouldBe` [1..10]