Skip to content

Commit 7d9e548

Browse files
committed
Add Backend docs, additional tests.
1 parent b307eb0 commit 7d9e548

File tree

5 files changed

+33
-6
lines changed

5 files changed

+33
-6
lines changed

src/ArrayFire/Backend.hs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,33 @@ import ArrayFire.FFI
1414
import ArrayFire.Internal.Backend
1515
import ArrayFire.Types
1616

17-
setBackend :: Backend -> IO ()
17+
-- | Set specific 'Backend' to use
18+
setBackend
19+
:: Backend
20+
-- ^ 'Backend' to use for 'Array' construction
21+
-> IO ()
1822
setBackend = afCall . af_set_backend . toAFBackend
1923

24+
-- | Retrieve count of Backends available
2025
getBackendCount :: IO Int
2126
getBackendCount =
2227
fromIntegral <$>
2328
afCall1 af_get_backend_count
2429

30+
-- | Retrieve available 'Backend's
2531
getAvailableBackends :: IO [Backend]
2632
getAvailableBackends =
2733
toBackends . fromIntegral <$>
2834
afCall1 af_get_available_backends
2935

30-
getBackendID :: Array a -> Backend
31-
getBackendID = toBackend . flip infoFromArray af_get_backend_id
36+
-- | Retrieve 'Backend' that specific 'Array' was created from
37+
getBackend :: Array a -> Backend
38+
getBackend = toBackend . flip infoFromArray af_get_backend_id
3239

40+
-- | Retrieve active 'Backend'
3341
getActiveBackend :: IO Backend
3442
getActiveBackend = toBackend <$> afCall1 af_get_active_backend
3543

44+
-- | Retrieve Device ID that 'Array' was created from
3645
getDeviceID :: Array a -> Int
3746
getDeviceID = fromIntegral . flip infoFromArray af_get_device_id

src/ArrayFire/Vision.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,26 @@ import ArrayFire.Internal.Features
2626
import ArrayFire.Internal.Vision
2727
import ArrayFire.Types
2828

29+
-- | FAST feature detectors
30+
--
31+
-- A circle of radius 3 pixels, translating into a total of 16 pixels, is checked for sequential segments of pixels much brighter or much darker than the central one.
32+
-- For a pixel p to be considered a feature, there must exist a sequential segment of arc_length pixels in the circle around it such that all are greather than (p + thr) or smaller than (p - thr).
33+
-- After all features in the image are detected, if nonmax is true, the non-maximal suppression is applied, checking all detected features and the features detected in its 8-neighborhood and discard it if its score is non maximal.
2934
fast
3035
:: Array a
36+
-- ^ Array containing a grayscale image (color images are not supported)
3137
-> Float
38+
-- ^ FAST threshold for which a pixel of the circle around the central pixel is considered to be greater or smaller
3239
-> Int
40+
-- ^ Length of arc (or sequential segment) to be tested, must be within range [9-16]
3341
-> Bool
42+
-- ^ Performs non-maximal suppression if true
3443
-> Float
44+
-- ^ Maximum ratio of features to detect, the maximum number of features is calculated by feature_ratio * in.elements(). The maximum number of features is not based on the score, instead, features detected after the limit is reached are discarded
3545
-> Int
46+
-- ^ Is the length of the edges in the image to be discarded by FAST (minimum is 3, as the radius of the circle)
3647
-> Features
48+
-- ^ Struct containing arrays for x and y coordinates and score, while array orientation is set to 0 as FAST does not compute orientation, and size is set to 1 as FAST does not compute multiple scales
3749
fast (Array fptr) thr (fromIntegral -> arc) (fromIntegral . fromEnum -> non) ratio (fromIntegral -> edge)
3850
= unsafePerformIO . mask_ . withForeignPtr fptr $ \aptr ->
3951
do feat <- alloca $ \ptr -> do

test/ArrayFire/BackendSpec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ spec =
1818
setBackend backend
1919
(`shouldBe` backend) =<< getActiveBackend
2020
let arr = matrix @Int (2,2) [1..]
21-
getBackendID arr `shouldBe` backend
21+
getBackend arr `shouldBe` backend

test/ArrayFire/LAPACKSpec.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ spec =
3030
A.getDims s `shouldBe` (3,3,1,1)
3131
A.getDims v `shouldBe` (3,3,1,1)
3232
A.getDims d `shouldBe` (3,1,1,1)
33-
it "Should get determinant" $ do
33+
it "Should get determinant of Double" $ do
34+
let eles = [3 A.:+ 1, 8 A.:+ 1, 4 A.:+ 1, 6 A.:+ 1]
35+
(x,y) = A.det (A.matrix @(A.Complex Double) (2,2) eles)
36+
x `shouldBe` (-14)
3437
let (x,y) = A.det $ A.matrix @Double (2,2) [3,8,4,6]
3538
x `shouldBe` (-14)
3639
it "Should calculate inverse" $ do

test/ArrayFire/VisionSpec.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ import Test.Hspec
77
spec :: Spec
88
spec =
99
describe "Vision spec" $ do
10-
it "Should get difference of gaussians" $ do
10+
it "Should construct Features for fast feature detection" $ do
11+
let arr = A.vector @Int 30000 [1..]
12+
let feats = A.fast arr 1.0 9 False 1.0 3
1113
(1 + 1) `shouldBe` 2
14+

0 commit comments

Comments
 (0)