Skip to content

Commit

Permalink
close issue #359 (#422)
Browse files Browse the repository at this point in the history
  • Loading branch information
jverzani authored May 10, 2021
1 parent 5a98def commit 43cacb5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "SymPy"
uuid = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6"
version = "1.0.44"
version = "1.0.45"

[deps]
CommonSolve = "38540f10-b2f7-11e9-35d8-d573e4eb0ff2"
Expand Down
9 changes: 8 additions & 1 deletion src/matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,14 @@ function LinearAlgebra.:\(A::AbstractArray{T,2}, B::AbstractArray{S,2}) where {T
end

## Issue #359 so that A + λI is of type Sym
Base.:+(A::AbstractMatrix{T}, I::UniformScaling) where {T <: SymbolicObject} = (n=LinearAlgebra.checksquare(A); A .+ I.λ*I(n))
Base.:+(A::AbstractMatrix{T}, J::UniformScaling) where {T <: SymbolicObject} = (n=LinearAlgebra.checksquare(A); A .+ J.λ*I(n))
Base.:+(A::AbstractMatrix, J::UniformScaling{T}) where {T <: SymbolicObject} = (n=LinearAlgebra.checksquare(A); A .+ J.λ*I(n))
Base.:+(A::AbstractMatrix{T}, J::UniformScaling{T}) where {T <: SymbolicObject} = (n=LinearAlgebra.checksquare(A); A .+ J.λ*I(n))

Base.:-(J::UniformScaling, A::AbstractMatrix{T}) where {T <: SymbolicObject} = A + (-J)
Base.:-(J::UniformScaling{T}, A::AbstractMatrix) where {T <: SymbolicObject} = A + (-J)
Base.:-(J::UniformScaling{T}, A::AbstractMatrix{T}) where {T <: SymbolicObject} = A + (-J)


# Issue 397 so that A' infers correctly
Base.adjoint(x::Sym)::Sym = x.adjoint()
Expand Down
25 changes: 22 additions & 3 deletions test/test-matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,28 @@ using LinearAlgebra

## Issue #359
if VERSION >= v"1.2"
@vars a
@test eltype([a 1; 1 a] + I) == Sym
@test eltype([a 1; 1 a] + 2I) == Sym
@syms a
A1 = [a 1; 1 a]
# The first six cases work
@test typeof(A1 + a*I) == Matrix{Sym}
@test typeof(A1 - a*I) == Matrix{Sym}
@test typeof(-A1 + a*I) == Matrix{Sym}
@test typeof(-A1 - a*I) == Matrix{Sym}
@test typeof(-a*I + A1) == Matrix{Sym}
@test typeof(a*I + A1) == Matrix{Sym}
@test typeof(a*I - A1) == Matrix{Sym}
@test typeof(-a*I - A1) == Matrix{Sym}

A2 = [1 2; 2 1]
@test typeof(A2 + a*I) == Matrix{Sym}
@test typeof(A2 - a*I) == Matrix{Sym}
@test typeof(-A2 + a*I) == Matrix{Sym}
@test typeof(-A2 - a*I) == Matrix{Sym}
@test typeof(-a*I + A2) == Matrix{Sym}
@test typeof(a*I + A2) == Matrix{Sym}
@test typeof(a*I - A2) == Matrix{Sym}
@test typeof(-a*I - A2) == Matrix{Sym}

end

## Issue #397 adjoint losing type
Expand Down

2 comments on commit 43cacb5

@jverzani
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/36467

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.45 -m "<description of version>" 43cacb5a6ae85b6c293a4ceb089cc133453eda68
git push origin v1.0.45

Please sign in to comment.