Skip to content

Commit 2dc99a8

Browse files
authored
add promote_op methods; close issue #324 (#325)
* add promote_op methods; close issue #324 * version bump [ci skip]
1 parent 63573fd commit 2dc99a8

File tree

5 files changed

+12
-2
lines changed

5 files changed

+12
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "SymPy"
22
uuid = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6"
3-
version = "1.0.13"
3+
version = "1.0.14"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

grep

Whitespace-only changes.

src/mathops.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
+(x::SymbolicObject, y::SymbolicObject) = x.__add__(y)
88
*(x::SymbolicObject, y::SymbolicObject) = x.__mul__(y)
9-
109
-(x::SymbolicObject, y::SymbolicObject) = x.__sub__(y)
1110
-(x::SymbolicObject) = x.__neg__()
1211
/(x::SymbolicObject, y::SymbolicObject) = x.__div__(y)

src/numbers.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
## promote up to symbolic so that math ops work
44
promote_rule(::Type{T}, ::Type{S}) where {T<:SymbolicObject, S<:Number}= T
55
Base.promote_type(::Type{Irrational{T}}, ::Type{Sym}) where {T} = Sym
6+
Base.promote_op(::T, ::Type{S}, ::Type{Sym}) where {T, S <: Number} = Sym
7+
Base.promote_op(::T, ::Type{Sym}, ::Type{S}) where {T, S <: Number} = Sym
8+
Base.promote_op(::T, ::Type{Sym}, ::Type{Sym}) where {T} = Sym # This helps out linear algebra conversions
9+
610
## Conversion
711
convert(::Type{T}, o::PyCall.PyObject) where {T <: SymbolicObject} = T(o)
812
convert(::Type{PyObject}, s::Sym) = s.__pyobject__

test/tests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,13 @@ end
584584
@test integrate(x -> 1, 0, 1) == 1
585585
@test limit(x->1, x, 0) == 1
586586
@test diff(x->1) == 0
587+
588+
## Issue 324 with inference of matrix operations
589+
A = fill(Sym("a"), 2, 2)
590+
@test eltype(A*A) == Sym
591+
@test eltype(A*ones(2,2)) == Sym
592+
@test eltype(A*Diagonal([1,1])) == Sym
593+
@test_broken eltype(A * I(2)) == Sym
587594
end
588595

589596
@testset "generic programming, issue 223" begin

0 commit comments

Comments
 (0)