Skip to content

Commit 791a2de

Browse files
Refactor substitution methods and add LinearAlgebra dependency
- Add LinearAlgebra dependency in Project.toml - Introduce type aliases ForwardSubstitution and BackSubstitution - Modify ForwardSubstitutionProblem constructor to use inner constructor - Update test runner to include specific substitution test files - Remove setup.jl script
1 parent d210332 commit 791a2de

File tree

10 files changed

+108
-29
lines changed

10 files changed

+108
-29
lines changed

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
jl:=julia
2+
3+
init:
4+
$(jl) -e 'd=pwd(); @assert isdir(d);\
5+
using Pkg: activate, instantiate, develop, precompile; \
6+
activate(d); instantiate(); activate(joinpath(d, "examples")); \
7+
develop(path=d); instantiate(); precompile();'
8+
@echo "environment initialized at: $$PWD"
9+
10+
update:
11+
$(jl) -e 'd=pwd(); @assert isdir(d);\
12+
using Pkg: activate, update, develop, precompile; \
13+
activate(d); update(); activate(joinpath(d, "examples")); \
14+
update(); precompile();'
15+
@echo "environment updated at: $$PWD"
16+
17+
test:
18+
@echo "Running tests at: $$PWD"
19+
$(jl) -e 'd=pwd(); @assert isdir(d);\
20+
using Pkg: activate, test; \
21+
activate(d); test();'

Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ uuid = "555e9691-8231-4cde-a0d7-6dc20204a59a"
33
authors = ["Junjie Yang <yangjunjie0320@gmail.com> and contributors"]
44
version = "1.0.0-DEV"
55

6+
[deps]
7+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
8+
69
[compat]
10+
LinearAlgebra = "1.11.0"
711
julia = "1"
812

913
[extras]

examples/Manifest.toml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This file is machine-generated - editing it directly is not advised
2+
3+
julia_version = "1.11.3"
4+
manifest_format = "2.0"
5+
project_hash = "6bccd7e9beaf72625f8173864188b586b1c437d4"
6+
7+
[[deps.Artifacts]]
8+
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
9+
version = "1.11.0"
10+
11+
[[deps.CompilerSupportLibraries_jll]]
12+
deps = ["Artifacts", "Libdl"]
13+
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
14+
version = "1.1.1+0"
15+
16+
[[deps.Libdl]]
17+
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
18+
version = "1.11.0"
19+
20+
[[deps.LinearAlgebra]]
21+
deps = ["Libdl", "OpenBLAS_jll", "libblastrampoline_jll"]
22+
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
23+
version = "1.11.0"
24+
25+
[[deps.OpenBLAS_jll]]
26+
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"]
27+
uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
28+
version = "0.3.27+1"
29+
30+
[[deps.SimpleLinearAlgebra]]
31+
deps = ["LinearAlgebra"]
32+
path = "/Users/yangjunjie/.julia/dev/SimpleLinearAlgebra"
33+
uuid = "555e9691-8231-4cde-a0d7-6dc20204a59a"
34+
version = "1.0.0-DEV"
35+
36+
[[deps.libblastrampoline_jll]]
37+
deps = ["Artifacts", "Libdl"]
38+
uuid = "8e850b90-86db-534c-a0d3-1478176c7d93"
39+
version = "5.11.0+0"

examples/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[deps]
2+
SimpleLinearAlgebra = "555e9691-8231-4cde-a0d7-6dc20204a59a"

src/back_substitution.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ struct BackSubstitutionSolution <: LinearSystemSolutionMixin
1515
x::AbstractVector
1616
end
1717

18+
BackSubstitution = BackSubstitutionProblem
19+
1820
function kernel(prob::BackSubstitutionProblem)
1921
u = prob.u
2022
b = copy(prob.b)
@@ -35,4 +37,5 @@ function kernel(prob::BackSubstitutionProblem)
3537
return BackSubstitutionSolution(x)
3638
end
3739

38-
export BackSubstitutionProblem, kernel
40+
41+
export BackSubstitution, kernel

src/forward_substitution.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ struct ForwardSubstitutionProblem <: LinearSystemProblemMixin
22
l::AbstractMatrix
33
b::AbstractVector
44
tol::Real
5-
end
65

7-
function ForwardSubstitutionProblem(l, b, tol)
8-
if !istril(l)
9-
ArgumentError("Matrix must be lower triangular") |> throw
6+
function ForwardSubstitutionProblem(l, b, tol)
7+
if !istril(l)
8+
ArgumentError("Matrix must be lower triangular") |> throw
9+
end
10+
return new(l, b, tol)
1011
end
11-
return new(l, b, tol)
1212
end
1313

14+
ForwardSubstitution = ForwardSubstitutionProblem
15+
1416
struct ForwardSubstitutionSolution <: LinearSystemSolutionMixin
1517
x::AbstractVector
1618
end
@@ -32,4 +34,5 @@ function kernel(prob::ForwardSubstitutionProblem)
3234
return ForwardSubstitutionSolution(x)
3335
end
3436

35-
export ForwardSubstitutionProblem, kernel
37+
38+
export ForwardSubstitution, kernel

src/setup.jl

Lines changed: 0 additions & 19 deletions
This file was deleted.

test/backward_substitution.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@testset "backward substitution" begin
2+
n = 10
3+
tol = 1e-10
4+
u = LinearAlgebra.triu(rand(n, n))
5+
b = rand(n)
6+
7+
p = BackSubstitution(u, b, tol)
8+
s = kernel(p)
9+
x = s.x
10+
@test maximum(abs, u * x - b) < tol
11+
end

test/forward_substitution.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@testset "forward substitution" begin
2+
n = 10
3+
tol = 1e-10
4+
u = LinearAlgebra.tril(rand(n, n))
5+
b = rand(n)
6+
7+
p = ForwardSubstitution(u, b, tol)
8+
s = kernel(p)
9+
x = s.x
10+
@test maximum(abs, u * x - b) < tol
11+
end

test/runtests.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
using SimpleLinearAlgebra
2-
using Test
2+
using Test, LinearAlgebra
33

4-
@testset "SimpleLinearAlgebra.jl" begin
5-
# Write your tests here.
4+
@testset "forward substitution" begin
5+
include("forward_substitution.jl")
6+
end
7+
8+
@testset "backward substitution" begin
9+
include("backward_substitution.jl")
610
end

0 commit comments

Comments
 (0)