{-# LANGUAGE ViewPatterns #-}
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
createFeatures
:: Int
-> Features
createFeatures :: Int -> Features
createFeatures (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
n) =
IO Features -> Features
forall a. IO a -> a
unsafePerformIO (IO Features -> Features) -> IO Features -> Features
forall a b. (a -> b) -> a -> b
$ do
AFFeatures
ptr <-
(Ptr AFFeatures -> IO AFFeatures) -> IO AFFeatures
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr AFFeatures -> IO AFFeatures) -> IO AFFeatures)
-> (Ptr AFFeatures -> IO AFFeatures) -> IO AFFeatures
forall a b. (a -> b) -> a -> b
$ \Ptr AFFeatures
ptrInput -> do
AFErr -> IO ()
throwAFError (AFErr -> IO ()) -> IO AFErr -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr AFFeatures
ptrInput Ptr AFFeatures -> DimT -> IO AFErr
`af_create_features` DimT
n
Ptr AFFeatures -> IO AFFeatures
forall a. Storable a => Ptr a -> IO a
peek Ptr AFFeatures
ptrInput
ForeignPtr ()
fptr <- FinalizerPtr () -> AFFeatures -> IO (ForeignPtr ())
forall a. FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
newForeignPtr FinalizerPtr ()
af_release_features AFFeatures
ptr
Features -> IO Features
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ForeignPtr () -> Features
Features ForeignPtr ()
fptr)
retainFeatures
:: Features
-> Features
retainFeatures :: Features -> Features
retainFeatures = (Features -> (Ptr AFFeatures -> AFFeatures -> IO AFErr) -> Features
`op1f` Ptr AFFeatures -> AFFeatures -> IO AFErr
af_retain_features)
getFeaturesNum
:: Features
-> Int
getFeaturesNum :: Features -> Int
getFeaturesNum = DimT -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (DimT -> Int) -> (Features -> DimT) -> Features -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Features -> (Ptr DimT -> AFFeatures -> IO AFErr) -> DimT
forall a.
Storable a =>
Features -> (Ptr a -> AFFeatures -> IO AFErr) -> a
`infoFromFeatures` Ptr DimT -> AFFeatures -> IO AFErr
af_get_features_num)
getFeaturesXPos
:: Features
-> Array a
getFeaturesXPos :: forall a. Features -> Array a
getFeaturesXPos = (Features -> (Ptr AFFeatures -> AFFeatures -> IO AFErr) -> Array a
forall a.
Features -> (Ptr AFFeatures -> AFFeatures -> IO AFErr) -> Array a
`featuresToArray` Ptr AFFeatures -> AFFeatures -> IO AFErr
af_get_features_xpos)
getFeaturesYPos
:: Features
-> Array a
getFeaturesYPos :: forall a. Features -> Array a
getFeaturesYPos = (Features -> (Ptr AFFeatures -> AFFeatures -> IO AFErr) -> Array a
forall a.
Features -> (Ptr AFFeatures -> AFFeatures -> IO AFErr) -> Array a
`featuresToArray` Ptr AFFeatures -> AFFeatures -> IO AFErr
af_get_features_ypos)
getFeaturesScore
:: Features
-> Array a
getFeaturesScore :: forall a. Features -> Array a
getFeaturesScore = (Features -> (Ptr AFFeatures -> AFFeatures -> IO AFErr) -> Array a
forall a.
Features -> (Ptr AFFeatures -> AFFeatures -> IO AFErr) -> Array a
`featuresToArray` Ptr AFFeatures -> AFFeatures -> IO AFErr
af_get_features_score)
getFeaturesOrientation
:: Features
-> Array a
getFeaturesOrientation :: forall a. Features -> Array a
getFeaturesOrientation = (Features -> (Ptr AFFeatures -> AFFeatures -> IO AFErr) -> Array a
forall a.
Features -> (Ptr AFFeatures -> AFFeatures -> IO AFErr) -> Array a
`featuresToArray` Ptr AFFeatures -> AFFeatures -> IO AFErr
af_get_features_orientation)
getFeaturesSize
:: Features
-> Array a
getFeaturesSize :: forall a. Features -> Array a
getFeaturesSize = (Features -> (Ptr AFFeatures -> AFFeatures -> IO AFErr) -> Array a
forall a.
Features -> (Ptr AFFeatures -> AFFeatures -> IO AFErr) -> Array a
`featuresToArray` Ptr AFFeatures -> AFFeatures -> IO AFErr
af_get_features_size)