Skip to content

Commit

Permalink
Corrections for compatibility with Julia 1.10 and SymPy 2
Browse files Browse the repository at this point in the history
  • Loading branch information
jfbarthelemy committed Jan 14, 2024
1 parent da859b1 commit 5e3e5e8
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 149 deletions.
1 change: 1 addition & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
- '1.7'
- '1.8'
- '1.9'
- '1.10'
- 'nightly'
os:
- ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
/docs/build/

.vscode/*

local

6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TensND"
uuid = "474b5345-2588-4284-8a58-2430a1a40cb0"
authors = ["Jean-François Barthélémy"]
version = "0.1.1"
version = "0.1.2"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand All @@ -15,11 +15,11 @@ TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
[compat]
OMEinsum = "0.6, 0.7"
Rotations = "1"
SymPy = "1"
SymPy = "2"
Symbolics = "4, 5"
Tensors = "1"
TimerOutputs = "0.5"
julia = "1.7, 1.8, 1.9"
julia = "1.7, 1.8, 1.9, 1.10"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
103 changes: 0 additions & 103 deletions setuplib/README.md

This file was deleted.

10 changes: 5 additions & 5 deletions src/array_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ for OP in (:(tsimplify), :(tfactor), :(tsubs), :(ttrigsimp), :(texpand_trig))
end

for OP in (:(simplify), :(factor), :(subs), :(diff))
@eval $(Symbol("t",OP))(x::Sym, args...; kwargs...) = SymPy.$OP(x, args...; kwargs...)
@eval $(Symbol("t",OP))(x::T, args...; kwargs...) where {T<:Sym} = SymPy.$OP(x, args...; kwargs...)
end
for OP in (:(trigsimp), :(expand_trig))
@eval $(Symbol("t",OP))(x::Sym, args...; kwargs...) = sympy.$OP(x, args...; kwargs...)
@eval $(Symbol("t",OP))(x::T, args...; kwargs...) where {T<:Sym} = sympy.$OP(x, args...; kwargs...)
end
for OP in (:(tsimplify), :(tfactor), :(tsubs), :(tdiff), :(ttrigsimp), :(texpand_trig))
@eval $OP(m::AbstractArray{Sym}, args...; kwargs...) = $OP.(m, args...; kwargs...)
@eval $OP(m::Array{Sym}, args...; kwargs...) = $OP.(m, args...; kwargs...)
@eval $OP(m::Symmetric{Sym}, args...; kwargs...) = Symmetric($OP.(m, args...; kwargs...))
@eval $OP(m::AbstractArray{T}, args...; kwargs...) where {T<:Sym} = $OP.(m, args...; kwargs...)
@eval $OP(m::Array{T}, args...; kwargs...) where {T<:Sym} = $OP.(m, args...; kwargs...)
@eval $OP(m::Symmetric{T}, args...; kwargs...) where {T<:Sym} = Symmetric($OP.(m, args...; kwargs...))
end

tsimplify(x::Num, args...; kwargs...) = Symbolics.simplify(x, args...; kwargs...)
Expand Down
11 changes: 6 additions & 5 deletions src/bases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function superscriptnumber(i::Integer)
return join(c)
end

diago(M::AbstractMatrix) = [M[i,i] for i in 1:min(size(M)...)]

"""
Basis(v::AbstractMatrix{T}, ::Val{:cov})
Expand Down Expand Up @@ -99,7 +100,7 @@ struct Basis{dim,T} <: AbstractBasis{dim,T}
elseif isidentity(gᵢⱼ)
return RotatedBasis(eᵢ)
elseif isdiag(gᵢⱼ)
χ = sqrt.(diag(gᵢⱼ))
χ = sqrt.(diago(gᵢⱼ))
return OrthogonalBasis(RotatedBasis(eᵢ .* transpose(inv.(χ))), χ)
else
eᵢ = Matrix(eᵢ)
Expand Down Expand Up @@ -137,7 +138,7 @@ struct Basis{dim,T} <: AbstractBasis{dim,T}
if isidentity(gᵢⱼ)
return RotatedBasis(eᵢ)
elseif isdiagonal(gᵢⱼ)
χ = sqrt.(diag(gᵢⱼ))
χ = sqrt.(diago(gᵢⱼ))
return OrthogonalBasis(RotatedBasis(eᵢ .* transpose(inv.(χ))), χ)
else
if T <: SymType
Expand All @@ -161,7 +162,7 @@ struct Basis{dim,T} <: AbstractBasis{dim,T}
if isidentity(gⁱʲ)
return RotatedBasis(eⁱ)
elseif isdiagonal(gⁱʲ)
= inv.(sqrt.(diag(gⁱʲ)))
= inv.(sqrt.(diago(gⁱʲ)))
return OrthogonalBasis(RotatedBasis(eⁱ .* transpose(uχ)), uχ)
else
if T <: SymType
Expand Down Expand Up @@ -507,9 +508,9 @@ isorthonormal(ℬ::AbstractBasis) = isidentity(metric(ℬ))
isorthonormal(::OrthonormalBasis) = true

for OP in (:(tsimplify), :(tfactor), :(tsubs), :(tdiff), :(ttrigsimp), :(texpand_trig))
@eval $OP(b::AbstractBasis{dim,Sym}, args...; kwargs...) where {dim} =
@eval $OP(b::AbstractBasis{dim,<:Sym}, args...; kwargs...) where {dim} =
Basis($OP(b.eᵢ, args...; kwargs...))
@eval $OP(b::CanonicalBasis{dim,Sym}, args...; kwargs...) where {dim} = b
@eval $OP(b::CanonicalBasis{dim,<:Sym}, args...; kwargs...) where {dim} = b
end
for OP in (:(tsimplify), :(tsubs), :(tdiff))
@eval $OP(b::AbstractBasis{dim,Num}, args...; kwargs...) where {dim} =
Expand Down
10 changes: 5 additions & 5 deletions src/coorsystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ function coorsys_cartesian(coords::NTuple{3,T}=symbols("x y z", real=true)) wher
χᵢ = ntuple(_ -> one(eltype(coords)), dim)
return CoorSystemSym(OM, coords, ℬ, χᵢ)
end
coorsys_cartesian(::Val{Sym}, coords=symbols("x y z", real=true)) = coorsys_cartesian(coords)
coorsys_cartesian(::Val{<:Sym}, coords=symbols("x y z", real=true)) = coorsys_cartesian(coords)
coorsys_cartesian(::Val{Num}, coords=Tuple(@variables x y z)) = coorsys_cartesian(coords)


Expand Down Expand Up @@ -393,7 +393,7 @@ function coorsys_polar(
OM = r * 𝐞ʳ
return CoorSystemSym(OM, coords, ℬᵖ, (one(eltype(coords)), r))
end
coorsys_polar(::Val{Sym}, coords=(symbols("r", positive=true),
coorsys_polar(::Val{<:Sym}, coords=(symbols("r", positive=true),
symbols("θ", real=true)); canonical=false) = coorsys_polar(coords; canonical=canonical)
coorsys_polar(::Val{Num}, coords=Tuple(@variables r θ); canonical=false) = coorsys_polar(coords; canonical=canonical)

Expand Down Expand Up @@ -430,7 +430,7 @@ function coorsys_cylindrical(

return CoorSystemSym(OM, coords, ℬᶜ, (one(eltype(coords)), r, one(eltype(coords))))
end
coorsys_cylindrical(::Val{Sym}, coords=(symbols("r", positive=true),
coorsys_cylindrical(::Val{<:Sym}, coords=(symbols("r", positive=true),
symbols("θ", real=true), symbols("z", real=true)); canonical=false) = coorsys_cylindrical(coords; canonical=canonical)
coorsys_cylindrical(::Val{Num}, coords=Tuple(@variables r θ z); canonical=false) = coorsys_cylindrical(coords; canonical=canonical)

Expand Down Expand Up @@ -479,7 +479,7 @@ function coorsys_spherical(
rules = Dict(abs(sin(θ)) => sin(θ), transpose(tan(θ)) => tan(θ), 1 // 1 => 1, 2 // 1 => 2)
return CoorSystemSym(OM, coords, ℬˢ, (r, r * sin(θ), one(eltype(coords))); rules=rules)
end
coorsys_spherical(::Val{Sym}, coords=(symbols("θ", real=true),
coorsys_spherical(::Val{<:Sym}, coords=(symbols("θ", real=true),
symbols("ϕ", real=true), symbols("r", positive=true)); canonical=false) = coorsys_spherical(coords; canonical=canonical)
coorsys_spherical(::Val{Num}, coords=Tuple(@variables θ ϕ r); canonical=false) = coorsys_spherical(coords; canonical=canonical)

Expand Down Expand Up @@ -546,7 +546,7 @@ function coorsys_spheroidal(
to_coords=to_coords
)
end
coorsys_spheroidal(::Val{Sym}, coords=(
coorsys_spheroidal(::Val{<:Sym}, coords=(
symbols("ϕ", real=true),
symbols("p", real=true),
symbols("q", positive=true),
Expand Down
Loading

0 comments on commit 5e3e5e8

Please sign in to comment.