Showing 2 of 7 files from the diff.

@@ -28,26 +28,28 @@
Loading
28 28
const COLAMD_ERROR_out_of_memory = -10
29 29
const COLAMD_ERROR_internal_error = -999
30 30
31 -
const colamd_statuses = Dict(COLAMD_OK => "ok",
32 -
                             COLAMD_OK_BUT_JUMBLED => "ok, but columns of input matrix were jumbled (unsorted columns or duplicate entries)",
33 -
                             COLAMD_ERROR_A_not_present => "rowval is a null pointer",
34 -
                             COLAMD_ERROR_p_not_present => "colptr is a null pointer",
35 -
                             COLAMD_ERROR_nrow_negative => "nrow is negative",
36 -
                             COLAMD_ERROR_ncol_negative => "nccol is negative",
37 -
                             COLAMD_ERROR_nnz_negative => "number of nonzeros in matrix is negative",
38 -
                             COLAMD_ERROR_p0_nonzero => "p[0] is nonzero",
39 -
                             COLAMD_ERROR_A_too_small => "workspace is too small",
40 -
                             COLAMD_ERROR_col_length_negative => "a column has a negative number of entries",
41 -
                             COLAMD_ERROR_row_index_out_of_bounds => "a row index is out of bounds",
42 -
                             COLAMD_ERROR_out_of_memory => "out of memory",
43 -
                             COLAMD_ERROR_internal_error => "internal error",
44 -
                            )                         
45 -
46 -
mutable struct Colamd{T<:Union{Cint,_Clong}} 
47 -
  knobs :: Vector{Cdouble}
48 -
  stats :: Vector{T}
49 -
50 -
  function Colamd{T}() where T <: Union{Cint,_Clong}
31 +
const colamd_statuses = Dict(
32 +
  COLAMD_OK => "ok",
33 +
  COLAMD_OK_BUT_JUMBLED =>
34 +
    "ok, but columns of input matrix were jumbled (unsorted columns or duplicate entries)",
35 +
  COLAMD_ERROR_A_not_present => "rowval is a null pointer",
36 +
  COLAMD_ERROR_p_not_present => "colptr is a null pointer",
37 +
  COLAMD_ERROR_nrow_negative => "nrow is negative",
38 +
  COLAMD_ERROR_ncol_negative => "nccol is negative",
39 +
  COLAMD_ERROR_nnz_negative => "number of nonzeros in matrix is negative",
40 +
  COLAMD_ERROR_p0_nonzero => "p[0] is nonzero",
41 +
  COLAMD_ERROR_A_too_small => "workspace is too small",
42 +
  COLAMD_ERROR_col_length_negative => "a column has a negative number of entries",
43 +
  COLAMD_ERROR_row_index_out_of_bounds => "a row index is out of bounds",
44 +
  COLAMD_ERROR_out_of_memory => "out of memory",
45 +
  COLAMD_ERROR_internal_error => "internal error",
46 +
)
47 +
48 +
mutable struct Colamd{T <: Union{Cint, _Clong}}
49 +
  knobs::Vector{Cdouble}
50 +
  stats::Vector{T}
51 +
52 +
  function Colamd{T}() where {T <: Union{Cint, _Clong}}
51 53
    knobs = zeros(Cdouble, COLAMD_KNOBS)
52 54
    stats = zeros(T, COLAMD_STATS)
53 55
    ccall(_colamd_set_defaults, Nothing, (Ptr{Cdouble},), knobs)
@@ -55,8 +57,8 @@
Loading
55 57
  end
56 58
end
57 59
58 -
function show(io :: IO, meta :: Colamd)
59 -
  s  = "dense row parameter: $(meta.knobs[COLAMD_DENSE_ROW])\n"
60 +
function show(io::IO, meta::Colamd)
61 +
  s = "dense row parameter: $(meta.knobs[COLAMD_DENSE_ROW])\n"
60 62
  s *= "dense col parameter: $(meta.knobs[COLAMD_DENSE_COL])\n"
61 63
  s *= "aggressive absorption: $(meta.knobs[COLAMD_AGGRESSIVE])\n"
62 64
  s *= "memory defragmentation: $(meta.stats[COLAMD_DEFRAG_COUNT])\n"
@@ -64,50 +66,56 @@
Loading
64 66
  print(io, s)
65 67
end
66 68
67 -
@inline print(io :: IO, meta :: Colamd) = show(io, meta)
69 +
@inline print(io::IO, meta::Colamd) = show(io, meta)
68 70
69 71
for (fn, typ) in ((:_colamd_recommended, Cint), (:_colamd_l_recommended, _Clong))
70 72
  @eval begin
71 73
    function colamd_recommended(nnz::$typ, nrow::$typ, ncol::$typ)
72 -
      len = ccall($fn, $typ,
73 -
                  ($typ, $typ, $typ),
74 -
                   nnz , nrow, ncol)
74 +
      len = ccall($fn, $typ, ($typ, $typ, $typ), nnz, nrow, ncol)
75 75
      return len
76 76
    end
77 77
  end
78 78
end
79 79
80 80
for (orderfn, typ) in ((:_colamd, Cint), (:_colamd_l, _Clong))
81 -
82 81
  @eval begin
83 -
84 -
    function colamd(A::SparseMatrixCSC{F,$typ}, meta::Colamd{$typ}) where F
82 +
    function colamd(A::SparseMatrixCSC{F, $typ}, meta::Colamd{$typ}) where {F}
85 83
      nrow, ncol = size(A)
86 84
      nnz = A.colptr[end] - 1
87 85
      p = A.colptr .- $typ(1)  # 0-based indexing
88 86
      len = colamd_recommended($typ(nnz), $typ(nrow), $typ(ncol))
89 87
      workspace = zeros($typ, len)
90 88
      workspace[1:length(A.rowval)] .= A.rowval .- $typ(1)
91 -
      valid = ccall($orderfn, $typ,
92 -
                    ($typ, $typ, $typ, $Ptr{$typ}, Ptr{$typ}, Ptr{Cdouble},  Ptr{$typ}),
93 -
                     nrow, ncol,  len,  workspace,         p,   meta.knobs, meta.stats)
89 +
      valid = ccall(
90 +
        $orderfn,
91 +
        $typ,
92 +
        ($typ, $typ, $typ, $Ptr{$typ}, Ptr{$typ}, Ptr{Cdouble}, Ptr{$typ}),
93 +
        nrow,
94 +
        ncol,
95 +
        len,
96 +
        workspace,
97 +
        p,
98 +
        meta.knobs,
99 +
        meta.stats,
100 +
      )
94 101
      Bool(valid) || throw("colamd status: $(colamd_statuses[meta.stats[COLAMD_STATUS]])")
95 102
      pop!(p)  # remove the number of nnz
96 103
      p .+= $typ(1)  # 1-based indexing
97 104
      return p
98 105
    end
99 106
100 -
    colamd(A :: Symmetric{F,SparseMatrixCSC{F,$typ}}, meta::Colamd{$typ}) where F = colamd(A.data, meta)
101 -
107 +
    colamd(A::Symmetric{F, SparseMatrixCSC{F, $typ}}, meta::Colamd{$typ}) where {F} =
108 +
      colamd(A.data, meta)
102 109
  end
103 110
end
104 111
105 -
function colamd(A :: SparseMatrixCSC{F,T}) where {F,T<:Union{Cint,_Clong}}
112 +
function colamd(A::SparseMatrixCSC{F, T}) where {F, T <: Union{Cint, _Clong}}
106 113
  meta = Colamd{T}()
107 114
  colamd(A, meta)
108 115
end
109 116
110 -
@inline colamd(A :: Symmetric{F,SparseMatrixCSC{F,T}}) where {F,T<:Union{Cint,_Clong}} = colamd(A.data)
117 +
@inline colamd(A::Symmetric{F, SparseMatrixCSC{F, T}}) where {F, T <: Union{Cint, _Clong}} =
118 +
  colamd(A.data)
111 119
112 120
"""
113 121
    colamd(A, meta)
@@ -122,34 +130,43 @@
Loading
122 130
colamd
123 131
124 132
for (fn, typ) in ((:_symamd, Cint), (:_symamd_l, _Clong))
125 -
126 133
  @eval begin
127 -
128 -
    function symamd(A::SparseMatrixCSC{F,$typ}, meta::Colamd{$typ}) where F
134 +
    function symamd(A::SparseMatrixCSC{F, $typ}, meta::Colamd{$typ}) where {F}
129 135
      nrow, ncol = size(A)
130 136
      colptr = A.colptr .- $typ(1)  # 0-based indexing
131 137
      rowval = A.rowval .- $typ(1)
132 -
      p = zeros($typ, nrow+1) # p is used as a workspace during the ordering, which is why it must be of length n+1, not just n
133 -
      valid = ccall($fn, $typ,
134 -
                    ($typ, Ref{$typ}, Ref{$typ}, Ptr{$typ}, Ptr{Cdouble},  Ptr{$typ},                                   Ptr{Cvoid},                           Ptr{Cvoid}),
135 -
                     nrow,    rowval,    colptr,         p,   meta.knobs, meta.stats, @cfunction(calloc, Ptr{Cvoid}, ($typ, $typ)), @cfunction(free, Cvoid, (Ptr{Cvoid},)))
138 +
      p = zeros($typ, nrow + 1) # p is used as a workspace during the ordering, which is why it must be of length n+1, not just n
139 +
      valid = ccall(
140 +
        $fn,
141 +
        $typ,
142 +
        ($typ, Ref{$typ}, Ref{$typ}, Ptr{$typ}, Ptr{Cdouble}, Ptr{$typ}, Ptr{Cvoid}, Ptr{Cvoid}),
143 +
        nrow,
144 +
        rowval,
145 +
        colptr,
146 +
        p,
147 +
        meta.knobs,
148 +
        meta.stats,
149 +
        @cfunction(calloc, Ptr{Cvoid}, ($typ, $typ)),
150 +
        @cfunction(free, Cvoid, (Ptr{Cvoid},))
151 +
      )
136 152
      Bool(valid) || throw("symamd status: $(colamd_statuses[meta.stats[COLAMD_STATUS]])")
137 153
      pop!(p)
138 154
      p .+= $typ(1)  # 1-based indexing
139 155
      return p
140 156
    end
141 157
142 -
    symamd(A :: Symmetric{F,SparseMatrixCSC{F,$typ}}, meta::Colamd{$typ}) where F = symamd(A.data, meta)
143 -
158 +
    symamd(A::Symmetric{F, SparseMatrixCSC{F, $typ}}, meta::Colamd{$typ}) where {F} =
159 +
      symamd(A.data, meta)
144 160
  end
145 161
end
146 162
147 -
function symamd(A :: SparseMatrixCSC{F,T}) where {F,T<:Union{Cint,_Clong}}
163 +
function symamd(A::SparseMatrixCSC{F, T}) where {F, T <: Union{Cint, _Clong}}
148 164
  meta = Colamd{T}()
149 165
  symamd(A, meta)
150 166
end
151 167
152 -
@inline symamd(A :: Symmetric{F,SparseMatrixCSC{F,T}}) where {F,T<:Union{Cint,_Clong}} = symamd(A.data)
168 +
@inline symamd(A::Symmetric{F, SparseMatrixCSC{F, T}}) where {F, T <: Union{Cint, _Clong}} =
169 +
  symamd(A.data)
153 170
154 171
"""
155 172
    symamd(A, meta)

@@ -41,11 +41,12 @@
Loading
41 41
const AMD_INVALID = -2        # input arguments not valid
42 42
const AMD_OK_BUT_JUMBLED = 1  # input ok but AMD will need to perform extra work
43 43
44 -
const amd_statuses = Dict(AMD_OK => "ok",
45 -
                          AMD_OUT_OF_MEMORY => "out of memory",
46 -
                          AMD_INVALID => "input invalid",
47 -
                          AMD_OK_BUT_JUMBLED => "ok but jumbled",
48 -
                         )
44 +
const amd_statuses = Dict(
45 +
  AMD_OK => "ok",
46 +
  AMD_OUT_OF_MEMORY => "out of memory",
47 +
  AMD_INVALID => "input invalid",
48 +
  AMD_OK_BUT_JUMBLED => "ok but jumbled",
49 +
)
49 50
50 51
"""Base type to hold control and information related to a call to AMD.
51 52
`control` is a vector of C doubles with components:
@@ -59,8 +60,8 @@
Loading
59 60
`info` is a vector of C doubles that contains statistics on the ordering.
60 61
"""
61 62
mutable struct Amd
62 -
  control :: Vector{Cdouble}
63 -
  info :: Vector{Cdouble}
63 +
  control::Vector{Cdouble}
64 +
  info::Vector{Cdouble}
64 65
65 66
  function Amd()
66 67
    control = zeros(Cdouble, AMD_CONTROL)
@@ -70,8 +71,8 @@
Loading
70 71
  end
71 72
end
72 73
73 -
function show(io :: IO, meta :: Amd)
74 -
  s  = "Control:\n"
74 +
function show(io::IO, meta::Amd)
75 +
  s = "Control:\n"
75 76
  s *= "  dense row parameter: $(meta.control[AMD_DENSE])\n"
76 77
  s *= "  aggressive absorption: $(meta.control[AMD_AGGRESSIVE])\n"
77 78
  s *= "Info:\n"
@@ -84,8 +85,8 @@
Loading
84 85
  print(io, s)
85 86
end
86 87
87 -
function print(io :: IO, meta :: Amd)
88 -
  s  = "Control:\n"
88 +
function print(io::IO, meta::Amd)
89 +
  s = "Control:\n"
89 90
  s *= "  dense row parameter: $(meta.control[AMD_DENSE])\n"
90 91
  s *= "  aggressive absorption: $(meta.control[AMD_AGGRESSIVE])\n"
91 92
  s *= "Info:\n"
@@ -107,54 +108,56 @@
Loading
107 108
end
108 109
109 110
for (validfn, typ) in ((:_amd_valid, Cint), (:_amd_l_valid, _Clong))
110 -
111 111
  @eval begin
112 -
113 -
    function amd_valid(A :: SparseMatrixCSC{F,$typ}) where F
112 +
    function amd_valid(A::SparseMatrixCSC{F, $typ}) where {F}
114 113
      nrow, ncol = size(A)
115 114
      colptr = A.colptr .- $typ(1)  # 0-based indexing
116 115
      rowval = A.rowval .- $typ(1)
117 -
      valid = ccall($validfn, $typ,
118 -
                    ($typ, $typ, Ptr{$typ}, Ptr{$typ}), nrow, ncol, colptr, rowval)
116 +
      valid = ccall($validfn, $typ, ($typ, $typ, Ptr{$typ}, Ptr{$typ}), nrow, ncol, colptr, rowval)
119 117
      return valid == AMD_OK || valid == AMD_OK_BUT_JUMBLED
120 118
    end
121 119
122 -
    amd_valid(A :: Symmetric{F,SparseMatrixCSC{F,$typ}}) where F = amd_valid(A.data)
123 -
120 +
    amd_valid(A::Symmetric{F, SparseMatrixCSC{F, $typ}}) where {F} = amd_valid(A.data)
124 121
  end
125 122
end
126 123
127 -
128 124
for (orderfn, typ) in ((:_amd_order, Cint), (:_amd_l_order, _Clong))
129 -
130 125
  @eval begin
131 -
132 -
    function amd(A::SparseMatrixCSC{F,$typ}, meta::Amd) where F
126 +
    function amd(A::SparseMatrixCSC{F, $typ}, meta::Amd) where {F}
133 127
      nrow, ncol = size(A)
134 128
      nrow == ncol || error("AMD: input matrix must be square")
135 129
      colptr = A.colptr .- $typ(1)  # 0-based indexing
136 130
      rowval = A.rowval .- $typ(1)
137 131
138 132
      p = zeros($typ, nrow)
139 -
      valid = ccall($orderfn, $typ,
140 -
                    ($typ, Ref{$typ}, Ref{$typ}, Ptr{$typ}, Ptr{Cdouble}, Ptr{Cdouble}),
141 -
                     nrow, colptr,    rowval,    p,         meta.control, meta.info)
142 -
      (valid == AMD_OK || valid == AMD_OK_BUT_JUMBLED) || throw("amd_order returns: $(amd_statuses[valid])")
133 +
      valid = ccall(
134 +
        $orderfn,
135 +
        $typ,
136 +
        ($typ, Ref{$typ}, Ref{$typ}, Ptr{$typ}, Ptr{Cdouble}, Ptr{Cdouble}),
137 +
        nrow,
138 +
        colptr,
139 +
        rowval,
140 +
        p,
141 +
        meta.control,
142 +
        meta.info,
143 +
      )
144 +
      (valid == AMD_OK || valid == AMD_OK_BUT_JUMBLED) ||
145 +
        throw("amd_order returns: $(amd_statuses[valid])")
143 146
      p .+= 1
144 147
      return p
145 148
    end
146 149
147 -
    amd(A :: Symmetric{F,SparseMatrixCSC{F,$typ}}, meta::Amd) where F = amd(A.data, meta)
148 -
150 +
    amd(A::Symmetric{F, SparseMatrixCSC{F, $typ}}, meta::Amd) where {F} = amd(A.data, meta)
149 151
  end
150 152
end
151 153
152 -
function amd(A :: SparseMatrixCSC{F,T}) where {F,T<:Union{Cint,_Clong}}
154 +
function amd(A::SparseMatrixCSC{F, T}) where {F, T <: Union{Cint, _Clong}}
153 155
  meta = Amd()
154 156
  amd(A, meta)
155 157
end
156 158
157 -
@inline amd(A :: Symmetric{F,SparseMatrixCSC{F,T}}) where {F,T<:Union{Cint,_Clong}} = amd(A.data)
159 +
@inline amd(A::Symmetric{F, SparseMatrixCSC{F, T}}) where {F, T <: Union{Cint, _Clong}} =
160 +
  amd(A.data)
158 161
159 162
"""
160 163
    amd(A, meta)
Files Coverage
src 95.16%
Project Totals (3 files) 95.16%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading