Skip to content

Commit

Permalink
Customize show for EinExpr, SizedEinExpr
Browse files Browse the repository at this point in the history
  • Loading branch information
mofeing committed Jul 25, 2024
1 parent b2b60ee commit fbf8847
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/EinExpr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ EinExpr(head::NTuple, args::NTuple) = EinExpr(collect(head), collect(args))

Base.copy(expr::EinExpr) = EinExpr(copy(expr.head), copy(expr.args))

Base.show(io::IO, path::EinExpr) = print_tree((io, node) -> print(io, head(node)), io, path)

"""
head(path::EinExpr)
Expand Down
10 changes: 10 additions & 0 deletions src/SizedEinExpr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ end

EinExpr(path::Vector{L}, size::Dict{L}) where {L} = SizedEinExpr(EinExpr(path), size)

function Base.show(io::IO, path::SizedEinExpr)
print_tree(io, path.path) do io, node
print(io, head(node))
print(
io,
" " * join(["$(flops(node, path.size)) flops", "$(length(SizedEinExpr(node, path.size))) elems"], ", "),
)
end
end

head(sexpr::SizedEinExpr) = head(sexpr.path)

"""
Expand Down

0 comments on commit fbf8847

Please sign in to comment.