Skip to content

Commit 4a7e090

Browse files
committed
Documentation updates.
1 parent f7f7d4b commit 4a7e090

File tree

6 files changed

+63
-51
lines changed

6 files changed

+63
-51
lines changed

src/ArrayFire.hs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ import Data.Word
9898
-- main = print $ A.matrix @Double (2,2) [[1,2],[3,4]]
9999
-- @
100100
--
101+
-- @
102+
-- ArrayFire Array
103+
-- [2 2 1 1]
104+
-- 1.0000 2.0000
105+
-- 3.0000 4.0000
106+
-- @
101107

102108
-- $modules
103109
--
@@ -133,27 +139,29 @@ import Data.Word
133139
-- An 'Array' can be constructed using the following smart constructors:
134140
--
135141
-- @
136-
-- >>> scalar @Double 2.0
142+
-- >>> scalar \@Double 2.0
137143
-- ArrayFire Array
138144
-- [1 1 1 1]
139145
-- 2.0000
140146
-- @
141147
--
142148
-- @
143-
-- >>> vector @Double 10 [1..]
149+
-- >>> vector \@Double 10 [1..]
144150
-- ArrayFire Array
145151
-- [10 1 1 1]
146152
-- 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 10.0000
153+
-- @
147154
--
148-
-- >>> matrix @Double (2,2) [[1,2],[3,4]]
155+
-- @
156+
-- >>> matrix \@Double (2,2) [[1,2],[3,4]]
149157
-- ArrayFire Array
150158
-- [2 2 1 1]
151159
-- 1.0000 2.0000
152160
-- 3.0000 4.0000
153161
-- @
154162
--
155163
-- @
156-
-- >>> cube @Double (2,2,2) [[[2,2],[2,2]],[[2,2],[2,2]]]
164+
-- >>> cube \@Double (2,2,2) [[[2,2],[2,2]],[[2,2],[2,2]]]
157165
-- ArrayFire Array
158166
-- [2 2 2 1]
159167
-- 2.0000 2.0000
@@ -164,7 +172,7 @@ import Data.Word
164172
-- @
165173
--
166174
-- @
167-
-- >>> tensor @Double (2,2,2,2) [[[[2,2],[2,2]],[[2,2],[2,2]]], [[[2,2],[2,2]],[[2,2],[2,2]]]]
175+
-- >>> tensor \@Double (2,2,2,2) [[[[2,2],[2,2]],[[2,2],[2,2]]], [[[2,2],[2,2]],[[2,2],[2,2]]]]
168176
-- ArrayFire Array
169177
-- [2 2 2 2]
170178
-- 2.0000 2.0000
@@ -183,15 +191,15 @@ import Data.Word
183191
--
184192
-- Array construction can use Haskell's lazy lists, since 'take' is called on each dimension before sending to the 'C' API.
185193
--
186-
-- >>> 'mkArray' @Double [2,2] [ [1..], [1..] ]
194+
-- >>> mkArray @Double [2,2] [ [1..], [1..] ]
187195
-- ArrayFire Array
188196
-- [10 1 1 1]
189197
-- 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 10.0000
190198
--
191199
-- Specifying up to 4 dimensions is allowed (anything high is ignored).
192200

193201
-- $laws
194-
-- Every 'Array' is an instance of 'Eq', 'Ord', 'Num', 'Fractional', 'Floating' and 'SemiGroup'
202+
-- Every 'Array' is an instance of 'Eq', 'Ord', 'Num', 'Fractional', 'Floating' and 'Semigroup'
195203
--
196204
-- 'Num'
197205
--
@@ -246,6 +254,14 @@ import Data.Word
246254
-- False
247255
-- >>> scalar @Double 1 [10] > scalar @Double 1 [10]
248256
-- False
257+
--
258+
-- 'Floating'
259+
--
260+
-- >>> pi :: Array Double
261+
-- ArrayFire Array
262+
-- [1 1 1 1]
263+
-- 3.1416
264+
--
249265

250266
-- $conversion
251267
-- 'Array' can be exported into 'Haskell' using `toVector'. This will create a 'Storable' vector suitable for use in other C programs.

src/ArrayFire/Arith.hs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ tanh = flip op1 af_tanh
12831283
-- >>> A.asinh (A.vector @Int 10 [1..])
12841284
-- ArrayFire Array
12851285
-- [10 1 1 1]
1286-
-- 0.7616 0.9640 0.9951 0.9993 0.9999 1.0000 1.0000 1.0000 1.0000 1.0000
1286+
-- 0.8814 1.4436 1.8184 2.0947 2.3124 2.4918 2.6441 2.7765 2.8934 2.9982
12871287
asinh
12881288
:: AFType a
12891289
=> Array a
@@ -1294,10 +1294,10 @@ asinh = flip op1 af_asinh
12941294

12951295
-- | Execute acosh
12961296
--
1297-
-- >>> A.acosh (A.vector @Int 10 [1..])
1297+
-- >>> A.acosh (A.vector @Double 10 [1..])
12981298
-- ArrayFire Array
12991299
-- [10 1 1 1]
1300-
-- 0.7616 0.9640 0.9951 0.9993 0.9999 1.0000 1.0000 1.0000 1.0000 1.0000
1300+
-- 0.0000 1.3170 1.7627 2.0634 2.2924 2.4779 2.6339 2.7687 2.8873 2.9932
13011301
acosh
13021302
:: AFType a
13031303
=> Array a
@@ -1308,10 +1308,10 @@ acosh = flip op1 af_acosh
13081308

13091309
-- | Execute atanh
13101310
--
1311-
-- >>> A.atanh (A.vector @Int 10 [1..])
1311+
-- >>> A.atanh (A.vector @Double 10 [1..])
13121312
-- ArrayFire Array
13131313
-- [10 1 1 1]
1314-
-- 0.7616 0.9640 0.9951 0.9993 0.9999 1.0000 1.0000 1.0000 1.0000 1.0000
1314+
-- inf nan nan nan nan nan nan nan nan nan
13151315
atanh
13161316
:: AFType a
13171317
=> Array a
@@ -1320,7 +1320,6 @@ atanh
13201320
-- ^ Result of calling 'tanh'
13211321
atanh = flip op1 af_atanh
13221322

1323-
13241323
-- | Execute root
13251324
--
13261325
-- >>> A.root (A.vector @Double 10 [1..]) (A.vector @Double 10 [1..])
@@ -1635,7 +1634,6 @@ isInf = (`op1` af_isinf)
16351634

16361635
-- | Execute isNaN
16371636
--
1638-
--
16391637
-- >>> A.isNaN $ A.acos (A.vector @Int 10 [1..])
16401638
-- ArrayFire Array
16411639
-- [10 1 1 1]

src/ArrayFire/BLAS.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ transpose arr1 (fromIntegral . fromEnum -> b) =
136136
-- | Transposes a matrix.
137137
--
138138
-- * Warning: This function mutates an array in-place, all subsequent references will be changed. Use carefully.
139-
--
139+
-- >>> array = matrix @Double (2,2) [[1..2],[3..4]]
140+
-- >>> transposeInPlace array False
141+
-- ()
140142
transposeInPlace
141143
:: Array a
142144
-- ^ Input matrix to be transposed

src/ArrayFire/Backend.hs

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
-- @
2020
--
2121
-- @
22-
-- [nix-shell:~\/arrayfire]$ .\/main
2322
-- [CPU,OpenCL]
2423
-- @
2524
--------------------------------------------------------------------------------
@@ -31,9 +30,8 @@ import ArrayFire.Internal.Types
3130

3231
-- | Set specific 'Backend' to use
3332
--
34-
-- @
35-
-- >>> 'setBackend' 'OpenCL'
36-
-- @
33+
-- >>> setBackend OpenCL
34+
-- ()
3735
setBackend
3836
:: Backend
3937
-- ^ 'Backend' to use for 'Array' construction
@@ -42,60 +40,41 @@ setBackend = afCall . af_set_backend . toAFBackend
4240

4341
-- | Retrieve count of Backends available
4442
--
45-
-- @
46-
-- >>> 'getBackendCount'
47-
-- @
48-
-- @
43+
-- >>> getBackendCount
4944
-- 2
50-
-- @
45+
--
5146
getBackendCount :: IO Int
5247
getBackendCount =
5348
fromIntegral <$>
5449
afCall1 af_get_backend_count
5550

5651
-- | Retrieve available 'Backend's
5752
--
58-
-- @
59-
-- >>> 'mapM_' 'print' '=<<' 'getAvailableBackends'
60-
-- @
61-
-- @
62-
-- 'CPU'
63-
-- 'OpenCL'
64-
-- @
53+
-- >>> mapM_ print =<< getAvailableBackends
54+
-- CPU
55+
-- OpenCL
6556
getAvailableBackends :: IO [Backend]
6657
getAvailableBackends =
6758
toBackends . fromIntegral <$>
6859
afCall1 af_get_available_backends
6960

7061
-- | Retrieve 'Backend' that specific 'Array' was created from
7162
--
72-
-- @
73-
-- >>> 'getBackend' ('scalar' \@'Double' 2.0)
74-
-- @
75-
-- @
76-
-- 'OpenCL'
77-
-- @
63+
-- >>> getBackend (scalar @Double 2.0)
64+
-- OpenCL
7865
getBackend :: Array a -> Backend
7966
getBackend = toBackend . flip infoFromArray af_get_backend_id
8067

8168
-- | Retrieve active 'Backend'
8269
--
83-
-- @
84-
-- >>> 'getActiveBackend'
85-
-- @
86-
-- @
87-
-- 'OpenCL'
88-
-- @
70+
-- >>> getActiveBackend
71+
-- OpenCL
8972
getActiveBackend :: IO Backend
9073
getActiveBackend = toBackend <$> afCall1 af_get_active_backend
9174

9275
-- | Retrieve Device ID that 'Array' was created from
9376
--
94-
-- @
95-
-- >>> 'getDeviceID' ('scalar' \@'Double' 2.0)
96-
-- @
97-
-- @
77+
-- >>> getDeviceID (scalar \@Double 2.0)
9878
-- 1
99-
-- @
10079
getDeviceID :: Array a -> Int
10180
getDeviceID = fromIntegral . flip infoFromArray af_get_device_id

src/ArrayFire/Device.hs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
--
1111
-- Information about ArrayFire API and devices
1212
--
13-
-- @
13+
-- >>> info
1414
-- ArrayFire v3.6.4 (OpenCL, 64-bit Mac OSX, build 1b8030c5)
1515
-- [0] APPLE: AMD Radeon Pro 555X Compute Engine, 4096 MB
1616
-- -1- APPLE: Intel(R) UHD Graphics 630, 1536 MB
17-
-- @
1817
--
1918
--------------------------------------------------------------------------------
2019
module ArrayFire.Device where
@@ -24,6 +23,7 @@ import ArrayFire.Internal.Device
2423
import ArrayFire.FFI
2524

2625
-- | Retrieve info from ArrayFire API
26+
--
2727
-- @
2828
-- ArrayFire v3.6.4 (OpenCL, 64-bit Mac OSX, build 1b8030c5)
2929
-- [0] APPLE: AMD Radeon Pro 555X Compute Engine, 4096 MB
@@ -33,25 +33,40 @@ info :: IO ()
3333
info = afCall af_info
3434

3535
-- | Calls 'af_init' C function from ArrayFire API
36+
--
37+
-- >>> afInit
38+
-- ()
3639
afInit :: IO ()
3740
afInit = afCall af_init
3841

3942
-- | Retrieves ArrayFire device information as 'String', same as 'info'.
43+
--
44+
-- >>> getInfoString
45+
-- "ArrayFire v3.6.4 (OpenCL, 64-bit Mac OSX, build 1b8030c5)\n[0] APPLE: AMD Radeon Pro 555X Compute Engine, 4096 MB\n-1- APPLE: Intel(R) UHD Graphics 630, 1536 MB\n"
4046
getInfoString :: IO String
4147
getInfoString = peekCString =<< afCall1 (flip af_info_string 1)
4248

4349
-- af_err af_device_info(char* d_name, char* d_platform, char *d_toolkit, char* d_compute);
4450

4551
-- | Retrieves count of devices
52+
--
53+
-- >>> getDeviceCount
54+
-- 2
4655
getDeviceCount :: IO Int
4756
getDeviceCount = fromIntegral <$> afCall1 af_get_device_count
4857

4958
-- af_err af_get_dbl_support(bool* available, const int device);
5059
-- | Sets a device by 'Int'
60+
--
61+
-- >>> setDevice 0
62+
-- ()
5163
setDevice :: Int -> IO ()
5264
setDevice (fromIntegral -> x) = afCall (af_set_device x)
5365

5466
-- | Retrieves device identifier
67+
--
68+
-- >>> getDevice
69+
-- 0
5570
getDevice :: IO Int
5671
getDevice = fromIntegral <$> afCall1 af_get_device
5772

src/ArrayFire/Statistics.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ stdev a n =
131131
a `op1` (\x y ->
132132
af_stdev x y (fromIntegral n))
133133

134-
-- | Calculates 'covariance' two 'Array's with a bias specifier.
134+
-- | Calculates 'covariance' of two 'Array's with a bias specifier.
135135
--
136136
-- >>> cov (vector @Double 10 (repeat 1)) (vector @Double 10 (repeat 1)) False
137137
-- ArrayFire Array
@@ -269,6 +269,7 @@ corrCoef a b =
269269

270270
-- | This function returns the top k values along a given dimension of the input array.
271271
--
272+
-- @
272273
-- >>> let (vals,indexes) = 'topk' ( 'vector' \@'Double' 10 [1..] ) 3 'TopKDefault'
273274
-- >>> print indexes
274275
--
@@ -280,6 +281,7 @@ corrCoef a b =
280281
-- ArrayFire 'Array'
281282
-- [3 1 1 1]
282283
-- 9 8 7
284+
-- @
283285
--
284286
-- The indices along with their values are returned. If the input is a multi-dimensional array, the indices will be the index of the value in that dimension. Order of duplicate values are not preserved. This function is optimized for small values of k.
285287
-- This function performs the operation across all dimensions of the input array.

0 commit comments

Comments
 (0)