Skip to content

Commit 8e3a9b7

Browse files
committed
Added BackslashSolver
1 parent d9468c5 commit 8e3a9b7

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/Algebra/LinearSolvers.jl

+23
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export numerical_setup
1515
export numerical_setup!
1616
export test_linear_solver
1717
export LUSolver
18+
export BackslashSolver
1819

1920
abstract type LinearSolver end
2021

@@ -80,4 +81,26 @@ function solve!(
8081
x .= y
8182
end
8283

84+
"""
85+
Wrapper of the backslash solver available in julia
86+
This is typically faster than LU for a single solve
87+
"""
88+
struct BackslashSolver <: LinearSolver end
89+
90+
struct BackslashSymbolicSetup <: SymbolicSetup end
91+
92+
struct BackslashNumericalSetup <: NumericalSetup end
93+
94+
symbolic_setup(::BackslashSolver,mat::AbstractMatrix) = BackslashSymbolicSetup()
95+
96+
numerical_setup(::BackslashSymbolicSetup,mat::AbstractMatrix) = BackslashNumericalSetup()
97+
98+
function numerical_setup!(ns::BackslashNumericalSetup, mat::AbstractMatrix)
99+
end
100+
101+
function solve!(
102+
x::AbstractVector,ns::BackslashNumericalSetup,A::AbstractMatrix,b::AbstractVector)
103+
copyto!(x, A\b)
104+
end
105+
83106
end

test/AlgebraTests/LinearSolversTests.jl

+9
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,13 @@ b = A*x
2828

2929
test_linear_solver(ls,A,b,x)
3030

31+
n = 10
32+
A = Laplacian(n,n,1,1)
33+
x = rand(n^2)
34+
b = A*x
35+
36+
ls = BackslashSolver()
37+
38+
test_linear_solver(ls,A,b,x)
39+
3140
end # module LinearSolversTests

0 commit comments

Comments
 (0)