Skip to content

Commit 957d1b1

Browse files
committed
Bool -> CBool and Int -> CInt
Use proper C types when dealing with C.
1 parent d0ca933 commit 957d1b1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+441
-395
lines changed

arrayfire.cabal

-5
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ executable gen
114114
test-suite test
115115
type:
116116
exitcode-stdio-1.0
117-
ghc-options:
118-
-threaded -rtsopts
119117
main-is:
120118
Main.hs
121119
hs-source-dirs:
@@ -148,6 +146,3 @@ test-suite test
148146
ArrayFire.StatisticsSpec
149147
ArrayFire.UtilSpec
150148
ArrayFire.VisionSpec
151-
152-
153-
-- ag -l | entr sh -c 'cabal build test && dist/build/test/test

gen/Print.hs

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ showType "af_someenum_t" = "AFSomeEnum"
5454
showType "size_t" = "CSize"
5555
showType "uintl" = "UIntL"
5656
showType "intl" = "IntL"
57+
showType "int" = "CInt"
58+
showType "bool" = "CBool"
5759
showType "af_index_t" = "AFIndex"
5860
showType "af_cspace_t" = "AFCSpace"
5961
showType "afcl_platform" = "AFCLPlatform"

shell.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ in
55
pkgs.lib.overrideDerivation pkg (drv: {
66
shellHook = ''
77
function ghcid () {
8-
${pkgs.haskellPackages.ghcid}/bin/ghcid -c 'cabal repl'
8+
${pkgs.haskellPackages.ghcid}/bin/ghcid -c 'cabal repl lib:arrayfire'
99
};
1010
function test-runner () {
1111
${pkgs.ag}/bin/ag -l | \

src/ArrayFire/Algorithm.hs

+22-22
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ sum
2626
-- ^ Dimension along which to perform sum
2727
-> a
2828
-- ^ Will return the sum of all values in the input array along the specified dimension
29-
sum x n = getScalar (x `op1` (\p a -> af_sum p a n))
29+
sum x (fromIntegral -> n) = getScalar (x `op1` (\p a -> af_sum p a n))
3030

3131
sumNaN
3232
:: (Fractional a, AFType a)
@@ -38,7 +38,7 @@ sumNaN
3838
-- ^ Default value to use in the case of NaN
3939
-> a
4040
-- ^ Will return the sum of all values in the input array along the specified dimension, substituted with the default value
41-
sumNaN n i d = getScalar (n `op1` (\p a -> af_sum_nan p a i d))
41+
sumNaN n (fromIntegral -> i) d = getScalar (n `op1` (\p a -> af_sum_nan p a i d))
4242

4343
product
4444
:: AFType a
@@ -48,7 +48,7 @@ product
4848
-- ^ Dimension along which to perform product
4949
-> a
5050
-- ^ Will return the product of all values in the input array along the specified dimension
51-
product x n = getScalar (x `op1` (\p a -> af_product p a n))
51+
product x (fromIntegral -> n) = getScalar (x `op1` (\p a -> af_product p a n))
5252

5353
productNaN
5454
:: (AFType a, Fractional a)
@@ -60,7 +60,7 @@ productNaN
6060
-- ^ Default value to use in the case of NaN
6161
-> a
6262
-- ^ Will return the product of all values in the input array along the specified dimension, substituted with the default value
63-
productNaN n i d = getScalar (n `op1` (\p a -> af_product_nan p a i d))
63+
productNaN n (fromIntegral -> i) d = getScalar (n `op1` (\p a -> af_product_nan p a i d))
6464

6565
min
6666
:: AFType a
@@ -70,7 +70,7 @@ min
7070
-- ^ Dimension along which to retrieve the min element
7171
-> a
7272
-- ^ Will contain the minimum of all values in the input array along dim
73-
min x n = getScalar (x `op1` (\p a -> af_min p a n))
73+
min x (fromIntegral -> n) = getScalar (x `op1` (\p a -> af_min p a n))
7474

7575
max
7676
:: AFType a
@@ -80,7 +80,7 @@ max
8080
-- ^ Dimension along which to retrieve the max element
8181
-> a
8282
-- ^ Will contain the maximum of all values in the input array along dim
83-
max x n = getScalar (x `op1` (\p a -> af_max p a n))
83+
max x (fromIntegral -> n) = getScalar (x `op1` (\p a -> af_max p a n))
8484

8585
allTrue
8686
:: forall a. AFType a
@@ -90,7 +90,7 @@ allTrue
9090
-- ^ Dimension along which to see if all elements are True
9191
-> Bool
9292
-- ^ Will contain the maximum of all values in the input array along dim
93-
allTrue x n = getScalar @Bool @a (x `op1` (\p a -> af_all_true p a n))
93+
allTrue x (fromIntegral -> n) = getScalar @Bool @a (x `op1` (\p a -> af_all_true p a n))
9494

9595
anyTrue
9696
:: forall a . AFType a
@@ -100,7 +100,7 @@ anyTrue
100100
-- ^ Dimension along which to see if all elements are True
101101
-> Bool
102102
-- ^ Returns if all elements are true
103-
anyTrue x n = getScalar @Bool @a (x `op1` (\p a -> af_any_true p a n))
103+
anyTrue x (fromIntegral -> n) = getScalar @Bool @a (x `op1` (\p a -> af_any_true p a n))
104104

105105
count
106106
:: forall a . AFType a
@@ -110,7 +110,7 @@ count
110110
-- ^ Dimension along which to count
111111
-> Int
112112
-- ^ Count of all elements along dimension
113-
count x n = getScalar @Int @a (x `op1` (\p a -> af_count p a n))
113+
count x (fromIntegral -> n) = getScalar @Int @a (x `op1` (\p a -> af_count p a n))
114114

115115
-- | Note: imag is always set to 0 when in is real
116116
sumAll
@@ -197,7 +197,7 @@ imin
197197
-- ^ The dimension along which the minimum value is extracted
198198
-> (Array a, Array a)
199199
-- ^ will contain the minimum of all values in in along dim, will also contain the location of minimum of all values in in along dim
200-
imin a n = op2p a (\x y z -> af_imin x y z n)
200+
imin a (fromIntegral -> n) = op2p a (\x y z -> af_imin x y z n)
201201

202202
imax
203203
:: AFType a
@@ -207,7 +207,7 @@ imax
207207
-- ^ The dimension along which the minimum value is extracted
208208
-> (Array a, Array a)
209209
-- ^ will contain the maximum of all values in in along dim, will also contain the location of maximum of all values in in along dim
210-
imax a n = op2p a (\x y z -> af_imax x y z n)
210+
imax a (fromIntegral -> n) = op2p a (\x y z -> af_imax x y z n)
211211

212212
iminAll
213213
:: AFType a
@@ -237,7 +237,7 @@ accum
237237
-- ^ Dimension along which to calculate the sum
238238
-> Array a
239239
-- ^ Contains inclusive sum
240-
accum a n = a `op1` (\x y -> af_accum x y n)
240+
accum a (fromIntegral -> n) = a `op1` (\x y -> af_accum x y n)
241241

242242
scan
243243
:: AFType a
@@ -251,7 +251,7 @@ scan
251251
-- ^ Should the scan be inclusive or not
252252
-> Array a
253253
-- ^ The scan of the input
254-
scan a d op batch =
254+
scan a (fromIntegral -> d) op (fromIntegral . fromEnum -> batch) =
255255
a `op1` (\x y -> af_scan x y d (toBinaryOp op) batch)
256256

257257
scanByKey
@@ -267,7 +267,7 @@ scanByKey
267267
-> Bool
268268
-- ^ Is the scan incluside or not
269269
-> Array a
270-
scanByKey a b d op batch =
270+
scanByKey a b (fromIntegral -> d) op (fromIntegral . fromEnum -> batch) =
271271
op2 a b (\x y z -> af_scan_by_key x y z d (toBinaryOp op) batch)
272272

273273
where'
@@ -286,7 +286,7 @@ diff1
286286
-- ^ Dimension along which numerical difference is performed
287287
-> Array a
288288
-- ^ Will contain first order numerical difference
289-
diff1 a n = a `op1` (\p x -> af_diff1 p x n)
289+
diff1 a (fromIntegral -> n) = a `op1` (\p x -> af_diff1 p x n)
290290

291291
diff2
292292
:: AFType a
@@ -296,7 +296,7 @@ diff2
296296
-- ^ Dimension along which numerical difference is performed
297297
-> Array a
298298
-- ^ Will contain second order numerical difference
299-
diff2 a n = a `op1` (\p x -> af_diff2 p x n)
299+
diff2 a (fromIntegral -> n) = a `op1` (\p x -> af_diff2 p x n)
300300

301301
sort
302302
:: AFType a
@@ -308,7 +308,7 @@ sort
308308
-- ^ Return results in ascending order
309309
-> Array a
310310
-- ^ Will contain sorted input
311-
sort a (fromIntegral -> n) b =
311+
sort a (fromIntegral -> n) (fromIntegral . fromEnum -> b) =
312312
a `op1` (\p x -> af_sort p x n b)
313313

314314
sortIndex
@@ -321,7 +321,7 @@ sortIndex
321321
-- ^ Return results in ascending order
322322
-> (Array a, Array a)
323323
-- ^ Contains the sorted, contains indices for original input
324-
sortIndex a (fromIntegral -> n) b =
324+
sortIndex a (fromIntegral -> n) (fromIntegral . fromEnum -> b) =
325325
a `op2p` (\p1 p2 p3 -> af_sort_index p1 p2 p3 n b)
326326

327327
sortByKey
@@ -335,7 +335,7 @@ sortByKey
335335
-> Bool
336336
-- ^ Return results in ascending order
337337
-> (Array a, Array a)
338-
sortByKey a1 a2 (fromIntegral -> n) b =
338+
sortByKey a1 a2 (fromIntegral -> n) (fromIntegral . fromEnum -> b) =
339339
op2p2 a1 a2 (\w x y z -> af_sort_by_key w x y z n b)
340340

341341
setUnique
@@ -346,7 +346,7 @@ setUnique
346346
-- ^ if true, skips the sorting steps internally
347347
-> Array a
348348
-- ^ Will contain the unique values from in
349-
setUnique a b =
349+
setUnique a (fromIntegral . fromEnum -> b) =
350350
op1 a (\x y -> af_set_unique x y b)
351351

352352
setUnion
@@ -358,7 +358,7 @@ setUnion
358358
-> Bool
359359
-- ^ If true, skips calling unique internally
360360
-> Array a
361-
setUnion a1 a2 b =
361+
setUnion a1 a2 (fromIntegral . fromEnum -> b) =
362362
op2 a1 a2 (\x y z -> af_set_union x y z b)
363363

364364
setIntersect
@@ -371,5 +371,5 @@ setIntersect
371371
-- ^ If true, skips calling unique internally
372372
-> Array a
373373
-- ^ Intersection of first and second array
374-
setIntersect a1 a2 b =
374+
setIntersect a1 a2 (fromIntegral . fromEnum -> b) =
375375
op2 a1 a2 (\x y z -> af_set_intersect x y z b)

0 commit comments

Comments
 (0)