Skip to content

Commit

Permalink
Add concretize! for IdentityOperator
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurav-arya committed Jul 21, 2023
1 parent 36d2ef2 commit 508da8c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ has_mul!(::IdentityOperator) = true
has_ldiv(::IdentityOperator) = true
has_ldiv!(::IdentityOperator) = true

function concretize!(A, L::IdentityOperator, α, β)
@assert size(A) == (L.len, L.len)
A .*= β
for i in 1:L.len
A[i, i] += α
end
end

# opeator application
for op in (
:*, :\,
Expand Down
2 changes: 1 addition & 1 deletion test/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ end

@testset "ConcretizedOperator" begin
A = rand(2, 2); B = rand(2, 2);
L = MatrixOperator(A; update_func=(u,p,t)->t * A) + 2 * MatrixOperator(B; update_func=(u,p,t)->t * B)
L = MatrixOperator(A; update_func=(u,p,t)->t * A) + 2 * MatrixOperator(B; update_func=(u,p,t)->t * B) + I
C = ConcretizedOperator(L)
v = rand(2)
C * v L * v
Expand Down

0 comments on commit 508da8c

Please sign in to comment.