Skip to content

Commit

Permalink
implemented Real, Complex constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
chakravala committed Aug 12, 2023
1 parent 9703c79 commit f2f177c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DirectSum"
uuid = "22fd7b30-a8c0-5bf2-aabe-97783860d07c"
authors = ["Michael Reed"]
version = "0.8.5"
version = "0.8.6"

[deps]
ComputedFieldTypes = "459fdd68-db75-56b8-8c15-d717a790f88e"
Expand Down
29 changes: 29 additions & 0 deletions src/DirectSum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,21 @@ for VG ∈ ((:V,),(:V,:G))
end
end

#(::Type{T})(m::Single{V,G,B,<:Real} where {V,G,B}) where T<:Real = T(value(m))
Base.Real(m::Single{V,G,B,<:Real} where {V,G,B}) = value(m)
(::Type{T})(m::Single{V,G,B,<:Real} where {V,G,B}) where T<:AbstractFloat = T(value(m))
(::Type{Bool})(m::Single{V,G,B,<:Real} where {V,G,B}) = Bool(value(m))
(::Type{T})(m::Single{V,G,B,<:Real} where {V,G,B}) where T<:Signed = T(value(m))
(::Type{Rational})(m::Single{V,G,B,<:Real} where {V,G,B}) = Rational(value(m))
(::Type{Rational{T}})(m::Single{V,G,B,<:Real} where {V,G,B}) where T<:Integer = Rational{T}(value(m))
(::Type{T})(m::Single{V,G,B,<:Real} where {V,G,B}) where T<:AbstractIrrational = T(value(m))
(::Type{Complex})(m::Single{V,0,B,T} where {V,B}) where T<:Real = Complex(value(m),zero(T))
(::Type{Complex{T}})(m::Single{V,0,B,<:Real} where {V,B}) where T = Complex{T}(value(m),zero(T))
(::Type{Complex})(m::Single{V,G,B,T} where {V,G,B}) where T<:Real = Complex(zero(T),value(m))
(::Type{Complex{T}})(m::Single{V,G,B,<:Real} where {V,G,B}) where T = Complex{T}(zero(T),value(m))
(::Type{Complex})(m::Single{V,G,B,<:Complex} where {V,G,B}) = value(m)
(::Type{Complex{T}})(m::Single{V,G,B,<:Complex} where {V,G,B}) where T = Complex{T}(value(m))

equal(a::TensorTerm{V,G},b::TensorTerm{V,G}) where {V,G} = basis(a) == basis(b) ? value(a) == value(b) : 0 == value(a) == value(b)

for T (Fields...,Symbol,Expr)
Expand Down Expand Up @@ -477,6 +492,20 @@ end
@pure One(b::Type{Submanifold{V}}) where V = Submanifold{V}()
@pure One(V::Type{<:TensorBundle}) = Submanifold{V()}()

(::Type{T})(m::Zero) where T<:Real = zero(T)
#(::Type{T})(m::Submanifold) where T<:Real = one(T) # causes ambiguity
Base.Real(m::Submanifold) = one(Real)
(::Type{T})(m::Submanifold) where T<:AbstractFloat = one(T)
(::Type{T})(m::Submanifold) where T<:Signed = one(T)
(::Type{Rational})(m::Submanifold) = one(Rational)
(::Type{Rational{T}})(m::Submanifold) where T = one(Rational{T})
(::Type{Complex})(m::Zero) = Complex(0)
(::Type{Complex{T}})(m::Zero) where T = Complex{T}(zero(T),zero(T))
(::Type{Complex})(m::One) = Complex(1)
(::Type{Complex{T}})(m::One) where T = Complex{T}(one(T),zero(T))
(::Type{Complex})(m::Submanifold) = Complex(0,1)
(::Type{Complex{T}})(m::Submanifold) where T = Complex{T}(zero(T),value(m))

for id (:Zero,:One)
@eval begin
@inline $id(t::T) where T<:TensorAlgebra = $id(Manifold(t))
Expand Down

2 comments on commit f2f177c

@chakravala
Copy link
Owner Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

@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/89478

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 v0.8.6 -m "<description of version>" f2f177c44690e9bc693db6e8a404de21291360f6
git push origin v0.8.6

Please sign in to comment.