1- struct Level{Ti,Tv }
2- A:: SparseMatrixCSC{Ti,Tv }
3- P:: SparseMatrixCSC{Ti,Tv }
4- R:: SparseMatrixCSC{Ti,Tv }
1+ struct Level{T,V }
2+ A:: SparseMatrixCSC{T,V }
3+ P:: SparseMatrixCSC{T,V }
4+ R:: SparseMatrixCSC{T,V }
55end
66
77struct MultiLevel{S, Pre, Post, Ti, Tv}
@@ -66,8 +66,10 @@ function solve{T}(ml::MultiLevel, b::Vector{T},
6666 tol = 1e-5 ;
6767 verbose = false ,
6868 log = false )
69- x = zeros (T, size (b))
70- residuals = Vector {T} ()
69+ V = promote_type (eltype (ml. levels[1 ]. A), eltype (b))
70+ x = zeros (V, size (b))
71+ tol = eltype (b)(tol)
72+ residuals = Vector {V} ()
7173 A = length (ml) == 1 ? ml. final_A : ml. levels[1 ]. A
7274 normb = norm (b)
7375 if normb != 0
@@ -91,14 +93,14 @@ function solve{T}(ml::MultiLevel, b::Vector{T},
9193 return x
9294 end
9395end
94- function __solve {T} (v:: V , ml, x:: Vector{T} , b:: Vector{T} , lvl)
96+ function __solve (v:: V , ml, x, b, lvl)
9597
9698 A = ml. levels[lvl]. A
9799 presmoother! (ml. presmoother, A, x, b)
98100
99101 res = b - A * x
100102 coarse_b = ml. levels[lvl]. R * res
101- coarse_x = zeros (T , size (coarse_b))
103+ coarse_x = zeros (eltype (coarse_b) , size (coarse_b))
102104
103105 if lvl == length (ml. levels)
104106 coarse_x = coarse_solver (ml. coarse_solver, ml. final_A, coarse_b)
@@ -113,5 +115,4 @@ function __solve{T}(v::V, ml, x::Vector{T}, b::Vector{T}, lvl)
113115 x
114116end
115117
116- coarse_solver {Tv,Ti} (:: Pinv , A:: SparseMatrixCSC{Tv,Ti} , b:: Vector{Tv} ) =
117- pinv (full (A)) * b
118+ coarse_solver (:: Pinv , A, b) = pinv (full (A)) * b
0 commit comments