-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathFeatures.hs
More file actions
165 lines (155 loc) · 3.18 KB
/
Features.hs
File metadata and controls
165 lines (155 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
{-# LANGUAGE ViewPatterns #-}
--------------------------------------------------------------------------------
-- |
-- Module : ArrayFire.Features
-- Copyright : David Johnson (c) 2019-2020
-- License : BSD 3
-- Maintainer : David Johnson <djohnson.m@gmail.com>
-- Stability : Experimental
-- Portability : GHC
--
-- Functions for constructing and querying 'Features'
--
-- @
-- >>> createFeatures 10
-- @
--
--------------------------------------------------------------------------------
module ArrayFire.Features where
import Foreign.Marshal
import Foreign.Storable
import Foreign.ForeignPtr
import System.IO.Unsafe
import ArrayFire.Internal.Features
import ArrayFire.Internal.Types
import ArrayFire.FFI
import ArrayFire.Exception
-- | Construct Features
--
-- >>> features = createFeatures 10
--
createFeatures
:: Int
-> Features
createFeatures (fromIntegral -> n) =
unsafePerformIO $ do
ptr <-
alloca $ \ptrInput -> do
throwAFError =<< ptrInput `af_create_features` n
peek ptrInput
fptr <- newForeignPtr af_release_features ptr
pure (Features fptr)
-- | Retain Features
--
-- >>> features = retainFeatures (createFeatures 10)
--
retainFeatures
:: Features
-> Features
retainFeatures = (`op1f` af_retain_features)
-- | Get number of Features
--
-- link
--
-- >>> getFeaturesNum (createFeatures 10)
-- 10
--
getFeaturesNum
:: Features
-> Int
getFeaturesNum = fromIntegral . (`infoFromFeatures` af_get_features_num)
-- | Get Feature X-position
--
-- >>> getFeaturesXPos (createFeatures 10)
-- ArrayFire Array
-- [10 1 1 1]
-- 0.0000
-- 1.8750
-- 0.0000
-- 2.3750
-- 0.0000
-- 2.5938
-- 0.0000
-- 2.0000
-- 0.0000
-- 2.4375
getFeaturesXPos
:: Features
-> Array a
getFeaturesXPos = (`featuresToArray` af_get_features_xpos)
-- | Get Feature Y-position
--
-- >>> getFeaturesYPos (createFeatures 10)
-- ArrayFire Array
-- [10 1 1 1]
-- nan
-- nan
-- nan
-- nan
-- nan
-- nan
-- nan
-- nan
-- nan
-- nan
getFeaturesYPos
:: Features
-> Array a
getFeaturesYPos = (`featuresToArray` af_get_features_ypos)
-- | Get Feature Score
--
-- >>> getFeaturesScore (createFeatures 10)
-- ArrayFire Array
-- [10 1 1 1]
-- nan
-- nan
-- nan
-- nan
-- nan
-- nan
-- nan
-- nan
-- nan
-- nan
getFeaturesScore
:: Features
-> Array a
getFeaturesScore = (`featuresToArray` af_get_features_score)
-- | Get Feature orientation
--
-- >>> getFeaturesOrientation (createFeatures 10)
-- ArrayFire Array
-- [10 1 1 1]
-- nan
-- nan
-- nan
-- nan
-- nan
-- nan
-- nan
-- nan
-- nan
-- nan
getFeaturesOrientation
:: Features
-> Array a
getFeaturesOrientation = (`featuresToArray` af_get_features_orientation)
-- | Get Feature size
--
-- >>> getFeaturesSize (createFeatures 10)
-- ArrayFire Array
-- [10 1 1 1]
-- nan
-- nan
-- nan
-- nan
-- nan
-- nan
-- nan
-- nan
-- nan
-- nan
getFeaturesSize
:: Features
-> Array a
getFeaturesSize = (`featuresToArray` af_get_features_size)