Skip to content

Commit 2a33a98

Browse files
committed
Added additional documentation.
1 parent d489bf2 commit 2a33a98

File tree

16 files changed

+314
-47
lines changed

16 files changed

+314
-47
lines changed

arrayfire.cabal

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
name: arrayfire
22
version: 0.1.0.0
3-
synopsis: Haskell bindings to ArrayFire
4-
description: High-level Haskell bindings to ArrayFire
5-
homepage: https://github.com/dmjio/fire
3+
synopsis: Haskell bindings to the ArrayFire general-purpose GPU library
4+
homepage: https://github.com/arrayfire/arrayfire-haskell
65
license: BSD3
76
license-file: LICENSE
87
author: David Johnson
@@ -12,6 +11,12 @@ category: Math
1211
build-type: Simple
1312
extra-source-files: CHANGELOG.md
1413
cabal-version: >=1.10
14+
description: High-level Haskell bindings to the ArrayFire General-purpose GPU library
15+
.
16+
<<https://user-images.githubusercontent.com/875324/59819388-9ff83f00-92f5-11e9-9ac0-51eef200c716.png>>
17+
.
18+
<https://www.youtube.com/watch?v=tI89V1Z8QHw>
19+
.
1520

1621
library
1722
exposed-modules:

src/ArrayFire.hs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
-- |
33
-- Module : ArrayFire
44
-- Copyright : David Johnson (c) 2019-2020
5-
-- License : BSD 3
5+
-- License : BSD3
66
-- Maintainer : David Johnson <[email protected]>
77
-- Stability : Experimental
88
-- Portability : GHC
99
--
10+
-- <<https://user-images.githubusercontent.com/875324/59819703-0fbaf980-92f7-11e9-8f53-adebea590bfb.png>>
11+
--
1012
--------------------------------------------------------------------------------
1113
module ArrayFire
12-
( module ArrayFire.Algorithm
14+
( -- * Tutorial
15+
-- $tutorial
16+
module ArrayFire.Algorithm
1317
, module ArrayFire.Arith
1418
, module ArrayFire.Array
1519
, module ArrayFire.Backend
@@ -58,3 +62,37 @@ import Foreign.C.Types
5862
import Data.Int
5963
import Data.Complex
6064
import Data.Word
65+
66+
-- $tutorial
67+
--
68+
-- @
69+
-- module Main where
70+
--
71+
-- import qualified ArrayFire as A
72+
--
73+
-- main :: IO ()
74+
-- main = A.printArray $ A.matrix @Double (3,3) [1.0 .. ]
75+
-- @
76+
--
77+
-- * Exception Handling
78+
--
79+
-- @
80+
-- {\-\# LANGUAGE TypeApplications \#\-}
81+
-- module Main where
82+
--
83+
-- import qualified ArrayFire as A
84+
-- import Control.Exception ( catch )
85+
--
86+
-- main :: IO ()
87+
-- main = A.printArray (action shouldBatchOperation) \`catch\` (\\(e :: A.AFException) -> print e)
88+
-- where
89+
-- action = A.matrix \@Double (3,3) [1.0 .. ] \`A.mul\` A.matrix \@Double (2,2) [1.0 .. ]
90+
-- shouldBatchOperation = True
91+
-- @
92+
--
93+
-- The above operation is invalid since the matrix multiply has improper dimensions. The caught exception produces the following error:
94+
--
95+
-- > AFException {afExceptionType = SizeError, afExceptionCode = 203, afExceptionMsg = "Invalid input size"}
96+
--
97+
98+

src/ArrayFire/Algorithm.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
-- Stability : Experimental
1111
-- Portability : GHC
1212
--
13+
-- Functions for aggregation, manipulation of 'Array'
14+
--
1315
--------------------------------------------------------------------------------
1416
module ArrayFire.Algorithm where
1517

src/ArrayFire/Arith.hs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
-- Stability : Experimental
1111
-- Portability : GHC
1212
--
13+
-- Arithmetic functions over 'Array'
14+
--
1315
--------------------------------------------------------------------------------
1416
module ArrayFire.Arith where
1517

@@ -20,6 +22,12 @@ import ArrayFire.FFI
2022
import ArrayFire.Internal.Arith
2123
import ArrayFire.Types
2224

25+
-- | Adds two 'Array' objects
26+
--
27+
-- @
28+
-- >>> (scalar \@Int 1 \`add\` scalar \@Int 1) True
29+
-- @
30+
--
2331
add
2432
:: AFType a
2533
=> Array a
@@ -34,6 +42,12 @@ add x y (fromIntegral . fromEnum -> batch) =
3442
x `op2` y $ \arr arr1 arr2 ->
3543
af_add arr arr1 arr2 batch
3644

45+
-- | Subtracts two 'Array' objects
46+
--
47+
-- @
48+
-- >>> (scalar @Int 1 \`sub\` scalar @Int 1) True
49+
-- @
50+
--
3751
sub
3852
:: AFType a
3953
=> Array a
@@ -48,6 +62,12 @@ sub x y (fromIntegral . fromEnum -> batch) = do
4862
x `op2` y $ \arr arr1 arr2 ->
4963
af_sub arr arr1 arr2 batch
5064

65+
-- | Multiply two 'Array' objects
66+
--
67+
-- @
68+
-- >>> (scalar @Int 1 \`mul\` scalar @Int 1) True
69+
-- @
70+
--
5171
mul
5272
:: AFType a
5373
=> Array a
@@ -62,6 +82,12 @@ mul x y (fromIntegral . fromEnum -> batch) = do
6282
x `op2` y $ \arr arr1 arr2 ->
6383
af_mul arr arr1 arr2 batch
6484

85+
-- | Divide two 'Array' objects
86+
--
87+
-- @
88+
-- >>> (scalar @Int 1 \`mul\` scalar @Int 1) True
89+
-- @
90+
--
6591
div
6692
:: AFType a
6793
=> Array a
@@ -76,6 +102,12 @@ div x y (fromIntegral . fromEnum -> batch) = do
76102
x `op2` y $ \arr arr1 arr2 ->
77103
af_div arr arr1 arr2 batch
78104

105+
-- | Test if on 'Array' is less than another 'Array'
106+
--
107+
-- @
108+
-- >>> (scalar \@Int 1 \`lt\` scalar \@Int 1) True
109+
-- @
110+
--
79111
lt
80112
:: AFType a
81113
=> Array a

0 commit comments

Comments
 (0)