-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathData.hs
More file actions
57 lines (50 loc) · 1.57 KB
/
Data.hs
File metadata and controls
57 lines (50 loc) · 1.57 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
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE KindSignatures #-}
module ArrayFire.Data where
import Control.Exception
import Control.Monad
import Foreign.C.String
import Foreign.C.Types
import Foreign.Marshal hiding (void)
import Foreign.Marshal.Array
import Foreign.ForeignPtr
import Foreign.Ptr
import Foreign.Storable
import Data.Proxy
import ArrayFire.Internal.Array
import ArrayFire.Exception
import ArrayFire.Types
import ArrayFire.Internal.Defines
import ArrayFire.Internal.Data
-- /**
-- \param[out] arr is the generated array of given type
-- \param[in] val is the value of each element in the generated array
-- \param[in] ndims is size of dimension array \p dims
-- \param[in] dims is the array containing sizes of the dimension
-- \param[in] type is the type of array to generate
-- \ingroup data_func_constant
-- /
constant
:: forall dims
. (Dims dims)
=> Double -> IO (Array Double)
constant val = do
ptr <- alloca $ \ptrPtr -> mask_ $ do
dimArray <- newArray dimt
throwAFError =<< af_constant ptrPtr val n dimArray typ
peek ptrPtr
Array <$>
newForeignPtr
af_release_array_finalizer
ptr
where
n = fromIntegral (length dimt)
dimt = toDims (Proxy @ dims)
typ = afType (Proxy @ Double)