Skip to content

Commit 2e94608

Browse files
committed
Add interface tests and add initialize!
1 parent a78b271 commit 2e94608

File tree

11 files changed

+51
-20
lines changed

11 files changed

+51
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ dimensions = [2; 3; 0; 1] # The dimension of row/column
2020

2121
system = System{Float64}(graph_matrix, dimensions; symmetric=false) # The resulting linear system. Set symmetric=true for symmetric systems
2222

23-
randomize!(system) # Randomize all system entries
23+
initialize!(system) # initialize! all system entries
2424
system.matrix_entries[1,2].value = rand(2,3) # Directly set the value of a matrix entry
2525
system.vector_entries[4].value = rand(1) # Directly set the value of a vector entry
2626

benchmark/example_benchmark.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ A[13,21] = A[21,13] = 1
7777
A[16,30] = A[30,16] = 1
7878
A[20,36] = A[36,20] = 1
7979

80-
function randomize_posdef!(system)
81-
randomize!(system,rand)
80+
function initialize!_posdef!(system)
81+
initialize!(system,rand)
8282
for i=1:size(A)[1]
8383
system.matrix_entries[i,i].value += 1000*I
8484
end
@@ -89,10 +89,10 @@ system = System{Float64}(A, ones(Int,size(A)[1])*3)
8989
systemldlt = System{Float64}(A, ones(Int,size(A)[1])*3, symmetric=true)
9090
systemllt = System{Float64}(A, ones(Int,size(A)[1])*3, symmetric=true)
9191

92-
SUITE["ldu"] = @benchmarkable ldu_solve!($system) samples=2 setup=(randomize!($system))
93-
SUITE["lu"] = @benchmarkable lu_solve!($system) samples=2 setup=(randomize!($system))
94-
SUITE["ldlt"] = @benchmarkable ldlt_solve!($systemldlt) samples=2 setup=(randomize!($systemldlt))
95-
SUITE["llt"] = @benchmarkable llt_solve!($systemllt) samples=2 setup=(randomize_posdef!($systemllt))
92+
SUITE["ldu"] = @benchmarkable ldu_solve!($system) samples=2 setup=(initialize!($system))
93+
SUITE["lu"] = @benchmarkable lu_solve!($system) samples=2 setup=(initialize!($system))
94+
SUITE["ldlt"] = @benchmarkable ldlt_solve!($systemldlt) samples=2 setup=(initialize!($systemldlt))
95+
SUITE["llt"] = @benchmarkable llt_solve!($systemllt) samples=2 setup=(initialize!_posdef!($systemllt))
9696

9797
# A = [
9898
# 0 1 1 1 1

src/GraphBasedSystems.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export System,
1111

1212
full_matrix,
1313
full_vector,
14-
randomize!,
14+
initialize!,
1515
reset_inverse_diagonals!,
1616

1717
children,

src/system/entry.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function Base.zero(::Type{Entry})
2828
return nothing
2929
end
3030

31-
function randomize!(entry::Entry, rand_function = randn)
31+
function initialize!(entry::Entry, init_function = randn)
3232
value = entry.value
33-
entry.value = rand_function(eltype(value), size(value))
33+
entry.value = init_function(eltype(value), size(value))
3434
end

src/system/interface.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,27 @@ function ranges(dims::AbstractVector)
2323
return range_dict
2424
end
2525

26-
function randomize!(system::System, rand_function = randn)
26+
function initialize!(system::System, init_function = randn)
2727
for entry in system.matrix_entries.nzval
28-
randomize!(entry, rand_function)
28+
initialize!(entry, init_function)
2929
end
3030
for entry in system.vector_entries
31-
randomize!(entry, rand_function)
31+
initialize!(entry, init_function)
3232
end
3333
end
3434

35-
function randomize!(system::System{N,<:Symmetric}, rand_function = randn) where N
35+
function initialize!(system::System{N,<:Symmetric}, init_function = randn) where N
3636
matrix_entries = system.matrix_entries
3737

3838
for entry in matrix_entries.nzval
39-
randomize!(entry, rand_function)
39+
initialize!(entry, init_function)
4040
end
4141
for i=1:N
4242
matrix_entries[i,i].value += matrix_entries[i,i].value'
4343
end
4444

4545
for entry in system.vector_entries
46-
randomize!(entry, rand_function)
46+
initialize!(entry, init_function)
4747
end
4848
end
4949

test/interface.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using GraphBasedSystems
2+
using LinearAlgebra
3+
4+
include("adjacency_matrix.jl")
5+
6+
system = System{Float64}(A, rand(0:3, size(A)[1]))
7+
8+
children(system, 1)
9+
connections(system, 1)
10+
parents(system, 1)
11+
children(system, 10)
12+
connections(system, 10)
13+
parents(system, 10)
14+
@test true
15+
16+
@test GraphBasedSystems.ranges(system) == GraphBasedSystems.ranges(system.dims)
17+
18+
initialize!(system, rand)
19+
initialize!(system, randn)
20+
initialize!(system, ones)
21+
initialize!(system, zeros)
22+
23+
@test true
24+
25+
reset_inverse_diagonals!(system)
26+
27+
@test true

test/ldlt_test.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ include("adjacency_matrix.jl")
77
system = System{Float64}(A, rand(0:3, size(A)[1]), symmetric=true)
88

99
for i=1:10
10-
randomize!(system)
10+
initialize!(system)
1111

1212
F = full_matrix(system)
1313
f = full_vector(system)

test/ldu_test.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ include("adjacency_matrix.jl")
77
system = System{Float64}(A, rand(0:3, size(A)[1]))
88

99
for i=1:10
10-
randomize!(system)
10+
initialize!(system)
1111

1212
F = full_matrix(system)
1313
f = full_vector(system)

test/llt_test.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ include("adjacency_matrix.jl")
77
system = System{Float64}(A, rand(0:3, size(A)[1]), symmetric=true)
88

99
for i=1:10
10-
randomize!(system)
10+
initialize!(system)
1111
F = full_matrix(system)
1212
while !isposdef(F)
1313
for i=1:size(A)[1]

test/lu_test.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ include("adjacency_matrix.jl")
77
system = System{Float64}(A, rand(0:3, size(A)[1]))
88

99
for i=1:10
10-
randomize!(system)
10+
initialize!(system)
1111

1212
F = full_matrix(system)
1313
f = full_vector(system)

0 commit comments

Comments
 (0)