Skip to content

Commit b507b11

Browse files
committed
Update ArrayFire documentation.
1 parent 1542031 commit b507b11

File tree

3 files changed

+323
-93
lines changed

3 files changed

+323
-93
lines changed

src/ArrayFire.hs

Lines changed: 189 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,27 @@
1313
module ArrayFire
1414
( -- * Tutorial
1515
-- $tutorial
16+
17+
-- ** Modules
18+
-- $modules
19+
20+
-- ** Exceptions
21+
-- $exceptions
22+
23+
-- ** Construction
24+
-- $construction
25+
26+
-- ** Laws
27+
-- $laws
28+
29+
-- ** Conversion
30+
-- $conversion
31+
32+
-- ** Serialization
33+
-- $serialization
34+
35+
-- ** Device
36+
-- $device
1637
module ArrayFire.Algorithm
1738
, module ArrayFire.Arith
1839
, module ArrayFire.Array
@@ -65,6 +86,9 @@ import Data.Word
6586

6687
-- $tutorial
6788
--
89+
-- [ArrayFire](http://arrayfire.org/docs/gettingstarted.htm) is a high performance parallel computing library that features modules for statistical and numerical methods.
90+
-- Example usage is depicted below.
91+
--
6892
-- @
6993
-- module Main where
7094
--
@@ -74,7 +98,16 @@ import Data.Word
7498
-- main = print $ A.matrix @Double (2,2) [[1,2],[3,4]]
7599
-- @
76100
--
77-
-- * Exception Handling
101+
102+
-- $modules
103+
--
104+
-- All child modules are re-exported top-level in the "ArrayFire" module.
105+
-- We recommend importing "ArrayFire" qualified so as to avoid naming collisions.
106+
--
107+
-- >>> import qualified ArrayFire as A
108+
--
109+
110+
-- $exceptions
78111
--
79112
-- @
80113
-- {\-\# LANGUAGE TypeApplications \#\-}
@@ -96,4 +129,159 @@ import Data.Word
96129
-- > AFException {afExceptionType = SizeError, afExceptionCode = 203, afExceptionMsg = "Invalid input size"}
97130
--
98131

132+
-- $construction
133+
-- An 'Array' can be constructed using the following smart constructors:
134+
--
135+
-- >>> scalar @Double 2.0
136+
-- ArrayFire Array
137+
-- [1 1 1 1]
138+
-- 2.0000
139+
--
140+
-- >>> vector @Double 10 [1..]
141+
-- ArrayFire Array
142+
-- [10 1 1 1]
143+
-- 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 10.0000
144+
--
145+
-- >>> matrix @Double (2,2) [[1,2],[3,4]]
146+
-- ArrayFire Array
147+
-- [2 2 1 1]
148+
-- 1.0000 2.0000
149+
-- 3.0000 4.0000
150+
--
151+
-- @
152+
-- >>> cube @Double (2,2,2) [[[2,2],[2,2]],[[2,2],[2,2]]]
153+
-- ArrayFire Array
154+
-- [2 2 2 1]
155+
-- 2.0000 2.0000
156+
-- 2.0000 2.0000
157+
--
158+
-- 2.0000 2.0000
159+
-- 2.0000 2.0000
160+
-- @
161+
--
162+
-- @
163+
-- >>> tensor @Double (2,2,2,2) [[[[2,2],[2,2]],[[2,2],[2,2]]], [[[2,2],[2,2]],[[2,2],[2,2]]]]
164+
-- ArrayFire Array
165+
-- [2 2 2 2]
166+
-- 2.0000 2.0000
167+
-- 2.0000 2.0000
168+
--
169+
-- 2.0000 2.0000
170+
-- 2.0000 2.0000
171+
--
172+
--
173+
-- 2.0000 2.0000
174+
-- 2.0000 2.0000
175+
--
176+
-- 2.0000 2.0000
177+
-- 2.0000 2.0000
178+
-- @
179+
--
180+
-- Array construction can use Haskell's lazy lists, since 'take' is called on each dimension before sending to the 'C' API.
181+
--
182+
-- >>> 'mkArray' @Double [2,2] [ [1..], [1..] ]
183+
-- ArrayFire Array
184+
-- [10 1 1 1]
185+
-- 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 10.0000
186+
--
187+
-- Specifying up to 4 dimensions is allowed (anything high is ignored).
188+
189+
-- $laws
190+
-- Every 'Array' is an instance of 'Eq', 'Ord', 'Num', 'Fractional' and 'SemiGroup'
191+
--
192+
-- 'Num'
193+
--
194+
-- >>> scalar @Int 1 + scalar @Int 1
195+
-- ArrayFire Array
196+
-- [1 1 1 1]
197+
-- 2
198+
--
199+
-- >>> scalar @Int 1 - scalar @Int 1
200+
-- ArrayFire Array
201+
-- [1 1 1 1]
202+
-- 0
203+
--
204+
-- >>> scalar @Double 10 / scalar @Double 10
205+
-- ArrayFire Array
206+
-- [1 1 1 1]
207+
-- 1.0000
208+
--
209+
-- >>> abs $ scalar @Double (-10)
210+
-- ArrayFire Array
211+
-- [1 1 1 1]
212+
-- 10.0000
213+
--
214+
-- >>> negate (scalar @Double 1 [10])
215+
-- -10.0
216+
--
217+
-- >>> fromInteger 1.0 :: Array Double
218+
-- ArrayFire Array
219+
-- [1 1 1 1]
220+
-- 1.0000
221+
--
222+
-- 'Semigroup'
223+
--
224+
-- /'Array' forms a 'Semigroup' via pointwise-multiplication./
225+
--
226+
-- >>> matrix @Double (2,2) [[1,2],[3,4]] <> matrix @Double (2,2) [[1,2],[3,4]]
227+
-- ArrayFire Array
228+
-- [2 2 1 1]
229+
-- 1.0000 4.0000
230+
-- 9.0000 16.0000
231+
--
232+
-- 'Eq'
233+
--
234+
-- >>> scalar @Double 1 [10] == scalar @Double 1 [10]
235+
-- True
236+
-- >>> scalar @Double 1 [10] /= scalar @Double 1 [10]
237+
-- False
238+
--
239+
-- 'Ord'
240+
--
241+
-- >>> scalar @Double 1 [10] < scalar @Double 1 [10]
242+
-- False
243+
-- >>> scalar @Double 1 [10] > scalar @Double 1 [10]
244+
-- False
99245

246+
-- $conversion
247+
-- 'Array' can be exported into 'Haskell' using `toVector'. This will create a 'Storable' vector suitable for use in other C programs.
248+
--
249+
-- >>> vector :: Vector Double <- toVector <$> randu @Double [10,10]
250+
--
251+
252+
-- $serialization
253+
-- Each 'Array' can be serialized to disk and deserialized from disk efficiently.
254+
--
255+
-- @
256+
-- import qualified ArrayFire as A
257+
-- import Control.Monad
258+
--
259+
-- main :: IO ()
260+
-- main = do
261+
-- let arr = A.'constant' [1,1,1,1] 10
262+
-- idx <- A.'saveArray' "key" arr "file.array" False
263+
-- foundIndex <- A.'readArrayKeyCheck' "file.array" "key"
264+
-- 'when' (idx == foundIndex) $ do
265+
-- array <- A.'readArrayKey' "file.array" "key"
266+
-- 'print' array
267+
-- @
268+
-- @
269+
-- ArrayFire Array
270+
-- [ 1 1 1 1 ]
271+
-- 10
272+
-- @
273+
--
274+
275+
-- $device
276+
-- The ArrayFire API is able to see which devices are present, and will by default use the GPU if available.
277+
--
278+
-- >>> afInfo
279+
-- ArrayFire v3.6.4 (OpenCL, 64-bit Mac OSX, build 1b8030c5)
280+
-- [0] APPLE: AMD Radeon Pro 555X Compute Engine, 4096 MB <-- brackets [] signify device being used.
281+
-- -1- APPLE: Intel(R) UHD Graphics 630, 1536 MB
282+
--
283+
284+
-- $visualization
285+
-- The ArrayFire API is able to visualize
286+
-- >>> window <- createWindow 800 600 "Histogram"
287+
--

0 commit comments

Comments
 (0)