Skip to content

Commit

Permalink
refined DirectSum support and implemented @subtype macro
Browse files Browse the repository at this point in the history
  • Loading branch information
chakravala committed Apr 8, 2019
1 parent 6ee78eb commit 33f234c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
julia 0.7
ForceImport
SyntaxTree
DirectSum
AbstractTensors
19 changes: 18 additions & 1 deletion src/Reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,18 @@ include("switch.jl") # load switch operators

module Algebra
using Reduce, LinearAlgebra
import ..extract

include("unary.jl") # load unary operators
include("args.jl") # load calculus operators

function init_subtype(name)
Expr(:block,[:(Base.$i(r::$name...)=$i(extract.(r)...)|>$name) for i [alg;iops]]...) |> eval
Expr(:block,[:($i(r::$name...)=$i(extract.(r)...)|>$name) for i [calculus;cnan;cmat]]...) |> eval
Expr(:block,[:(Base.$i(r::$name)=$i(extract(r))|>$name) for i [sbas;[:length]]]...) |> eval
Expr(:block,[:($i(r::$name)=$i(extract(r))|>$name) for i [sfun;snan;snum;scom;sint;sran;smat]]...) |> eval
end

const variables = [
:root_multiplicities,
:requirements,
Expand All @@ -133,13 +141,22 @@ function bypass(op::Symbol,T::ExprSymbol,args)
end
end

import AbstractTensors: TensorAlgebra
import AbstractTensors: TensorAlgebra, value
for op (:exp,:reverse)
bypass(op,:TensorAlgebra,(1,))
end
for op (:+,:-)
bypass(op,:TensorAlgebra,(1,2))
end
for op (:*,:/)
bypass(op,:TensorAlgebra,(2,))
end
abs(x::X) where X<:TensorAlgebra = sqrt(abs(value(LinearAlgebra.dot(x,x))))
rank(x::X) where X<:TensorAlgebra = LinearAlgebra.rank(x)

import DirectSum: SUB, PROD
SUB(x::Expr) = -(x)
PROD(x::AbstractVector{T}) where T<:Any = *(x...)

@doc """
ws()
Expand Down
15 changes: 15 additions & 0 deletions src/rexpr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,21 @@ function show(io::IO, ::MIME"text/latex", r::RExpr)
print(io,"\n\\end{eqnarray}")
end

function extract end

macro subtype(x)
x.head :<: && throw(error("$x is not a subtype expression"))
name = x.args[1]
Expr(:struct,false,x,Expr(:block,Expr(:(::), :r, :RExpr))) |> eval
@eval begin
export $name
show(io::IO, r::$name) = show(io,r.r)
extract(r::$name) = r.r
Algebra.init_subtype($name)
end
nothing
end

const r_to_jl = Dict(
"i" => "im",
"infinity" => "Inf"
Expand Down
4 changes: 2 additions & 2 deletions src/unary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const sbas = [
:asinh,
:atan,
:atanh,
:atan2,
#:atan2,
:cos,
:cosh,
:cot,
Expand All @@ -42,10 +42,10 @@ const sbas = [
:sqrt,
:tan,
:tanh,
:gamma,
]

const sdep = [
:gamma,
:beta,
:besseli,
:besselj,
Expand Down

0 comments on commit 33f234c

Please sign in to comment.