-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSparse.hs
More file actions
83 lines (71 loc) · 1.86 KB
/
Sparse.hs
File metadata and controls
83 lines (71 loc) · 1.86 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
{-# LANGUAGE ViewPatterns #-}
module ArrayFire.Sparse where
import ArrayFire.Types
import ArrayFire.FFI
import ArrayFire.Internal.Sparse
import ArrayFire.Internal.Defines
createSparseArray
:: AFType a
=> Int
-> Int
-> Array a
-> Array a
-> Array a
-> Storage
-> Array a
createSparseArray (fromIntegral -> r) (fromIntegral -> c) arr1 arr2 arr3 s =
op3 arr1 arr2 arr3 (\p ar1 ar2 ar3 -> af_create_sparse_array p r c ar1 ar2 ar3 (toStorage s))
-- af_err af_create_sparse_array_from_ptr(af_array *out, const dim_t nRows, const dim_t nCols, const dim_t nNZ, const void * const values, const int * const rowIdx, const int * const colIdx, const af_dtype type, const af_storage stype, const af_source src);
createSparseArrayFromDense
:: AFType a
=> Array a
-> Storage
-> Array a
createSparseArrayFromDense a s =
a `op1` (\p x -> af_create_sparse_array_from_dense p x (toStorage s))
sparseConvertTo
:: AFType a
=> Array a
-> Storage
-> Array a
sparseConvertTo a s =
a `op1` (\p x -> af_sparse_convert_to p x (toStorage s))
sparseToDense
:: AFType a
=> Array a
-> Array a
sparseToDense = (`op1` af_sparse_to_dense)
sparseGetInfo
:: AFType a
=> Array a
-> (Array a, Array a, Array a, Storage)
sparseGetInfo a = do
let (a,b,c,d) = a `op3p1` af_sparse_get_info
(a,b,c,fromStorage d)
sparseGetValues
:: AFType a
=> Array a
-> Array a
sparseGetValues = (`op1` af_sparse_get_values)
sparseGetRowIdx
:: AFType a
=> Array a
-> Array a
sparseGetRowIdx = (`op1` af_sparse_get_row_idx)
sparseGetColIdx
:: AFType a
=> Array a
-> Array a
sparseGetColIdx = (`op1` af_sparse_get_col_idx)
sparseGetNNZ
:: AFType a
=> Array a
-> Int
sparseGetNNZ a =
fromIntegral (a `infoFromArray` af_sparse_get_nnz)
sparseGetStorage
:: AFType a
=> Array a
-> Storage
sparseGetStorage a =
fromStorage (a `infoFromArray` af_sparse_get_storage)