1
- function asArray (f:: Function , A:: GBVecOrMat{T} ; dropzeros= false , freeunpacked= false ) where {T}
1
+ function as (f:: Function , :: Type{<:Union{Matrix, Vector}} , A:: GBVecOrMat{T} ; dropzeros= false , freeunpacked= false ) where {T}
2
2
if gbget (A, SPARSITY_STATUS) != GBDENSE
3
3
X = similar (A)
4
4
if X isa GBVector
5
5
X[:] = zero (T)
6
6
else
7
7
X[:,:] = zero (T)
8
8
end
9
- # I don't like this, it defeats the purpose of this method, which is to make no copies.
9
+ # I don't like this, it defeats the purpose of this method, which is to make no copies.
10
10
# But somehow maintaining the input A in its original form is key to the to_vec implementation
11
- # for ChainRules. Temporarily it's fine, it's no worse than it originally was.
11
+ # for ChainRules/FiniteDiff . Temporarily it's fine, it's no worse than it originally was.
12
12
# TODO : fix this issue with the ChainRules code.
13
13
A = eadd (X, A)
14
14
end
@@ -28,39 +28,7 @@ function asArray(f::Function, A::GBVecOrMat{T}; dropzeros=false, freeunpacked=fa
28
28
return result
29
29
end
30
30
31
- function asCSCVectors (f:: Function , A:: GBMatrix{T} ; freeunpacked= false ) where {T}
32
- colptr, rowidx, values = _unpackcscmatrix! (A)
33
- result = try
34
- f (colptr, rowidx, values, A)
35
- finally
36
- if freeunpacked
37
- ccall (:jl_free , Cvoid, (Ptr{LibGraphBLAS. GrB_Index},), pointer (colptr))
38
- ccall (:jl_free , Cvoid, (Ptr{LibGraphBLAS. GrB_Index},), pointer (rowidx))
39
- ccall (:jl_free , Cvoid, (Ptr{T},), pointer (values))
40
- else
41
- _packcscmatrix! (A, colptr, rowidx, values)
42
- end
43
- end
44
- return result
45
- end
46
-
47
- function asCSRVectors (f:: Function , A:: GBMatrix{T} ; freeunpacked= false ) where {T}
48
- rowptr, colidx, values = _unpackcsrmatrix! (A)
49
- result = try
50
- f (rowptr, colidx, values, A)
51
- finally
52
- if freeunpacked
53
- ccall (:jl_free , Cvoid, (Ptr{LibGraphBLAS. GrB_Index},), pointer (rowptr))
54
- ccall (:jl_free , Cvoid, (Ptr{LibGraphBLAS. GrB_Index},), pointer (colidx))
55
- ccall (:jl_free , Cvoid, (Ptr{T},), pointer (values))
56
- else
57
- _packcsrmatrix! (A, rowptr, colidx, values)
58
- end
59
- end
60
- return result
61
- end
62
-
63
- function asSparseMatrixCSC (f:: Function , A:: GBMatrix{T} ; freeunpacked= false ) where {T}
31
+ function as (f:: Function , :: SparseMatrixCSC , A:: GBMatrix{T} ; freeunpacked= false ) where {T}
64
32
colptr, rowidx, values = _unpackcscmatrix! (A)
65
33
array = SparseMatrixCSC {T, LibGraphBLAS.GrB_Index} (size (A, 1 ), size (A, 2 ), colptr, rowidx, values)
66
34
result = try
@@ -77,7 +45,7 @@ function asSparseMatrixCSC(f::Function, A::GBMatrix{T}; freeunpacked=false) wher
77
45
return result
78
46
end
79
47
80
- function asSparseVector (f:: Function , A:: GBVector{T} ; freeunpacked= false ) where {T}
48
+ function as (f:: Function , :: SparseVector , A:: GBVector{T} ; freeunpacked= false ) where {T}
81
49
colptr, rowidx, values = _unpackcscmatrix! (A)
82
50
vector = SparseVector {T, LibGraphBLAS.GrB_Index} (size (A, 1 ), rowidx, values)
83
51
result = try
96
64
97
65
98
66
function Base. Matrix (A:: GBMatrix )
99
- return asArray ( A) do arr, _
67
+ return as (Matrix, A) do arr, _
100
68
return copy (arr)
101
69
end
102
70
end
103
71
104
72
function Matrix! (A:: GBMatrix )
105
- return asArray ( A; freeunpacked= true ) do arr, _
73
+ return as (Matrix, A; freeunpacked= true ) do arr, _
106
74
return copy (arr)
107
75
end
108
76
end
109
77
110
78
function Base. Vector (v:: GBVector )
111
- return asArray ( v) do vec, _
79
+ return as (Vector, v) do vec, _
112
80
return copy (vec)
113
81
end
114
82
end
115
83
116
84
function Vector! (v:: GBVector )
117
- return asArray ( v; freeunpacked= true ) do vec, _
85
+ return as (Vector, v; freeunpacked= true ) do vec, _
118
86
return copy (vec)
119
87
end
120
88
end
121
89
122
90
function SparseArrays. SparseMatrixCSC (A:: GBMatrix )
123
- return asArray ( A) do arr, _
91
+ return as (SparseMatrixCSC, A) do arr, _
124
92
return copy (arr)
125
93
end
126
94
end
127
95
128
96
function SparseArrays. SparseVector (v:: GBVector )
129
- return asArray ( v) do arr, _
97
+ return as (SparseVector, v) do arr, _
130
98
return copy (arr)
131
99
end
132
100
end
0 commit comments