Skip to content

Commit 7d115dd

Browse files
committed
added norm, cond, opnorm methods
1 parent 607fee9 commit 7d115dd

File tree

1 file changed

+66
-3
lines changed

1 file changed

+66
-3
lines changed

src/extendable.jl

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ $(SIGNATURES)
9797
Find index in CSC matrix and set value if it exists. Otherwise,
9898
set index in extension.
9999
"""
100-
function Base.setindex!(ext::ExtendableSparseMatrix{Tv,Ti}, v, i::Integer, j::Integer) where{Tv,Ti<:Integer}
100+
101+
function Base.setindex!(ext::ExtendableSparseMatrix{Tv,Ti}, v, i,j) where{Tv,Ti<:Integer}
101102
k=findindex(ext.cscmatrix,i,j)
102103
if k>0
103104
ext.cscmatrix.nzval[k]=v
@@ -111,8 +112,6 @@ end
111112

112113

113114

114-
115-
116115
"""
117116
$(SIGNATURES)
118117
@@ -260,3 +259,67 @@ function LinearAlgebra.ldiv!(r::AbstractArray{T,2} where T, ext::ExtendableSpar
260259
@inbounds flush!(ext)
261260
return LinearAlgebra.ldiv!(r,ext.cscmatrix,x)
262261
end
262+
263+
264+
265+
"""
266+
$(SIGNATURES)
267+
268+
[`flush!`](@ref) and calculate norm from cscmatrix
269+
"""
270+
function LinearAlgebra.norm(A::ExtendableSparseMatrix, p::Real=2)
271+
@time @inbounds flush!(A)
272+
return LinearAlgebra.norm(A.cscmatrix,p)
273+
end
274+
275+
"""
276+
$(SIGNATURES)
277+
278+
[`flush!`](@ref) and calculate opnorm from cscmatrix
279+
"""
280+
function LinearAlgebra.opnorm(A::ExtendableSparseMatrix, p::Real=2)
281+
@inbounds flush!(A)
282+
return LinearAlgebra.opnorm(A.cscmatrix,p)
283+
end
284+
285+
"""
286+
$(SIGNATURES)
287+
288+
[`flush!`](@ref) and calculate cond from cscmatrix
289+
"""
290+
function LinearAlgebra.cond(A::ExtendableSparseMatrix, p::Real=2)
291+
@inbounds flush!(A)
292+
return LinearAlgebra.cond(A.cscmatrix,p)
293+
end
294+
295+
296+
297+
"""
298+
$(SIGNATURES)
299+
300+
Add SparseMatrixCSC matrix and [`ExtendableSparseMatrix`](@ref) ext.
301+
"""
302+
function Base.:+(ext::ExtendableSparseMatrix{Tv,Ti},csc::SparseMatrixCSC{Tv,Ti}) where {Tv,Ti<:Integer}
303+
@inbounds flush!(ext)
304+
return ext.cscmatrix+csc
305+
end
306+
307+
"""
308+
$(SIGNATURES)
309+
310+
Subtract SparseMatrixCSC matrix from [`ExtendableSparseMatrix`](@ref) ext.
311+
"""
312+
function Base.:-(ext::ExtendableSparseMatrix{Tv,Ti},csc::SparseMatrixCSC{Tv,Ti}) where {Tv,Ti<:Integer}
313+
@inbounds flush!(ext)
314+
return ext.cscmatrix-csc
315+
end
316+
317+
"""
318+
$(SIGNATURES)
319+
320+
Subtract [`ExtendableSparseMatrix`](@ref) ext from SparseMatrixCSC.
321+
"""
322+
function Base.:-(csc::SparseMatrixCSC{Tv,Ti},ext::ExtendableSparseMatrix{Tv,Ti}) where {Tv,Ti<:Integer}
323+
@inbounds flush!(ext)
324+
return csc - ext.cscmatrix
325+
end

0 commit comments

Comments
 (0)