Skip to content

Commit aad1ec4

Browse files
author
Jeremy E Kozdon
committed
Clean up some function comments and names
1 parent 98bc85a commit aad1ec4

3 files changed

Lines changed: 35 additions & 44 deletions

File tree

src/mat.jl

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,11 @@ function destroy(M::AbstractMat{PetscLib}) where {PetscLib}
1616
return nothing
1717
end
1818

19-
"""
20-
MatSeqAIJ{PetscLib, PetscScalar}
21-
22-
PETSc sparse array using AIJ format (also known as a compressed sparse row or
23-
CSR format).
24-
25-
Memory allocation is handled by PETSc.
26-
27-
# External Links
28-
$(_doc_external("Mat/MatCreateSeqAIJ"))
29-
"""
30-
mutable struct MatSeqAIJ{PetscLib, PetscScalar} <:
31-
AbstractMat{PetscLib, PetscScalar}
32-
ptr::CMat
33-
end
34-
3519
"""
3620
MatSeqAIJ(petsclib, num_rows, num_cols, nonzeros)
3721
38-
Create a PETSc sparse array using AIJ format (also known as a compressed sparse
39-
row or CSR format) of size `num_rows X num_cols` with `nonzeros` per row
22+
Create a PETSc serial sparse array using AIJ format (also known as a compressed
23+
sparse row or CSR format) of size `num_rows X num_cols` with `nonzeros` per row
4024
4125
If `nonzeros` is an `Integer` the same number of non-zeros will be used for each
4226
row, if `nonzeros` is a `Vector{PetscInt}` then one value must be specified for
@@ -47,6 +31,11 @@ Memory allocation is handled by PETSc and garbage collection can be used.
4731
# External Links
4832
$(_doc_external("Mat/MatCreateSeqAIJ"))
4933
"""
34+
mutable struct MatSeqAIJ{PetscLib, PetscScalar} <:
35+
AbstractMat{PetscLib, PetscScalar}
36+
ptr::CMat
37+
end
38+
5039
function MatSeqAIJ(
5140
petsclib::PetscLib,
5241
num_rows::Integer,
@@ -112,53 +101,54 @@ function MatSeqDense(
112101
end
113102

114103
"""
115-
assemble(M::AbstractMat[, t::MatAssemblyType = MAT_FINAL_ASSEMBLY)
104+
assemble!(M::AbstractMat[, t::MatAssemblyType = MAT_FINAL_ASSEMBLY)
116105
117106
Assemble the matrix `M` with assembly type `t`.
118107
119-
For overlapping assembly see [`assemblybegin`](@ref) and [`assemblyend`](@ref)
108+
For overlapping assembly see [`assemblybegin!`](@ref) and [`assemblyend!`](@ref)
120109
121110
# External Links
122111
$(_doc_external("Mat/MatAssemblyBegin"))
123112
$(_doc_external("Mat/MatAssemblyEnd"))
124113
"""
125-
function assemble(M::AbstractMat, t::MatAssemblyType = MAT_FINAL_ASSEMBLY)
126-
assemblybegin(M, t)
127-
assemblyend(M, t)
114+
function assemble!(M::AbstractMat, t::MatAssemblyType = MAT_FINAL_ASSEMBLY)
115+
assemblybegin!(M, t)
116+
assemblyend!(M, t)
117+
return M
128118
end
129119

130120
"""
131-
assemblybegin(M::AbstractMat[, t::MatAssemblyType = MAT_FINAL_ASSEMBLY)
121+
assemblybegin!(M::AbstractMat[, t::MatAssemblyType = MAT_FINAL_ASSEMBLY)
132122
133123
Begin assembly of the matrix `M` with assembly type `t`; finished with
134-
[`assemblyend`](@ref).
124+
[`assemblyend!`](@ref).
135125
136126
# External Links
137127
$(_doc_external("Mat/MatAssemblyBegin"))
138128
"""
139-
function assemblybegin(
129+
function assemblybegin!(
140130
M::AbstractMat{PetscLib},
141131
t::MatAssemblyType = MAT_FINAL_ASSEMBLY,
142132
) where {PetscLib}
143133
LibPETSc.MatAssemblyBegin(PetscLib, M, t)
144-
return nothing
134+
return M
145135
end
146136

147137
"""
148-
assemblyend(M::AbstractMat[, t::MatAssemblyType = MAT_FINAL_ASSEMBLY)
138+
assemblyend!(M::AbstractMat[, t::MatAssemblyType = MAT_FINAL_ASSEMBLY)
149139
150140
Finish assembly of the matrix `M` with assembly type `t`; start assembly with
151-
[`assemblybegin`](@ref).
141+
[`assemblybegin!`](@ref).
152142
153143
# External Links
154144
$(_doc_external("Mat/MatAssemblyEnd"))
155145
"""
156-
function assemblyend(
146+
function assemblyend!(
157147
M::AbstractMat{PetscLib},
158148
t::MatAssemblyType = MAT_FINAL_ASSEMBLY,
159149
) where {PetscLib}
160150
LibPETSc.MatAssemblyEnd(PetscLib, M, t)
161-
return nothing
151+
return M
162152
end
163153

164154
function Base.size(A::AbstractMat{PetscLib}) where {PetscLib}
@@ -193,7 +183,7 @@ Base.show(io::IO, ::MIME"text/plain", mat::AbstractMat) = _show(io, mat)
193183
row0idxs::Vector{PetscInt},
194184
col0idxs::Vector{PetscInt},
195185
rowvals::Array{PetscScalar},
196-
insertmode::InsertMode;
186+
insertmode::InsertMode = INSERT_VALUES;
197187
num_rows = length(row0idxs),
198188
num_cols = length(col0idxs)
199189
)
@@ -212,7 +202,7 @@ function setvalues!(
212202
row0idxs::Vector{PetscInt},
213203
col0idxs::Vector{PetscInt},
214204
rowvals::Array{PetscScalar},
215-
insertmode::InsertMode;
205+
insertmode::InsertMode = INSERT_VALUES;
216206
num_rows = length(row0idxs),
217207
num_cols = length(col0idxs),
218208
) where {PetscLib, PetscScalar, PetscInt}

src/vec.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ end
121121
An sequentially-stored MPI PETSc vector for `petsclib.PetscScalar` of local
122122
length `local_length` and global length `global_length` without ghost elements.
123123
124-
If `global_length isa Int` then `local_length` can be set to `PETSC_DECIDE`.
124+
If `global_length isa Int` then `local_length` can be set to `PETSC_DECIDE` in
125+
which case PETSc will decide the local_length.
125126
126127
# External Links
127128
$(_doc_external("Vec/VecCreateMPI"))

test/mat.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ using LinearAlgebra: norm, mul!, Adjoint, Transpose, issymmetric, ishermitian
1414

1515
@test size(A) == (num_rows, num_cols)
1616
B = PETSc.MatSeqAIJ(petsclib, num_rows, num_cols, nz_int)
17-
PETSc.assemble(A)
18-
PETSc.assemble(B)
17+
PETSc.assemble!(A)
18+
PETSc.assemble!(B)
1919
# both empty
2020
@test A == B
2121

2222
C = PETSc.MatSeqAIJ(petsclib, num_rows, num_cols, nz_vec)
2323
@test size(A) == (num_rows, num_cols)
24-
PETSc.assemble(C)
24+
PETSc.assemble!(C)
2525
# both empty
2626
@test A == C
2727

@@ -30,7 +30,7 @@ using LinearAlgebra: norm, mul!, Adjoint, Transpose, issymmetric, ishermitian
3030
D[1, [1, 2]] .= [1, 2]
3131
D[2, [3, 4]] .= [3, 4]
3232
D[5, [3, 4]] .= [3, 4]
33-
PETSc.assemble(D)
33+
PETSc.assemble!(D)
3434

3535
DJ = zeros(PetscScalar, num_rows, num_cols)
3636
DJ[1, [1, 2]] .= [1, 2]
@@ -41,7 +41,7 @@ using LinearAlgebra: norm, mul!, Adjoint, Transpose, issymmetric, ishermitian
4141
D[1, [1, 2]] .= [1, 2im]
4242
D[2, [3, 4]] .= [3, 4im]
4343
D[5, [3, 4]] .= [3, 4im]
44-
PETSc.assemble(D)
44+
PETSc.assemble!(D)
4545

4646
DJ = zeros(PetscScalar, num_rows, num_cols)
4747
DJ[1, [1, 2]] .= [1, 2im]
@@ -53,7 +53,7 @@ using LinearAlgebra: norm, mul!, Adjoint, Transpose, issymmetric, ishermitian
5353
E[2, [1, 3, 4]] .= [1, 3, 4]
5454
E[3, [3, 4]] .= [3, 4]
5555
E[4, [5]] .= [6]
56-
PETSc.assemble(E)
56+
PETSc.assemble!(E)
5757

5858
@test A != E
5959
@test D != E
@@ -87,13 +87,13 @@ using LinearAlgebra: norm, mul!, Adjoint, Transpose, issymmetric, ishermitian
8787
A[1, 1] = 1
8888
A[2, 1] = -2
8989
A[1, 2] = -2
90-
PETSc.assemble(A)
90+
PETSc.assemble!(A)
9191

9292
B = PETSc.MatSeqAIJ(petsclib, 5, 5, 2)
9393
B[1, 1] = 1
9494
B[2, 1] = 2
9595
B[1, 2] = -2
96-
PETSc.assemble(B)
96+
PETSc.assemble!(B)
9797

9898
@test issymmetric(A)
9999
@test ishermitian(A)
@@ -104,13 +104,13 @@ using LinearAlgebra: norm, mul!, Adjoint, Transpose, issymmetric, ishermitian
104104
A[1, 1] = 1
105105
A[2, 1] = -2 + im
106106
A[1, 2] = -2 - im
107-
PETSc.assemble(A)
107+
PETSc.assemble!(A)
108108

109109
B = PETSc.MatSeqAIJ(petsclib, 5, 5, 2)
110110
B[1, 1] = 1
111111
B[2, 1] = -2 + im
112112
B[1, 2] = -2 + im
113-
PETSc.assemble(B)
113+
PETSc.assemble!(B)
114114
@test !issymmetric(A)
115115
@test ishermitian(A)
116116
@test issymmetric(B)

0 commit comments

Comments
 (0)