Skip to content

Commit e429d8d

Browse files
committed
Generalized @Simplify to arbitrary amount of arguments
1 parent 75d7dd9 commit e429d8d

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/operators.jl

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,21 @@ macro simplify(qt)
5252

5353
esc(ret)
5454
else
55-
@assert length(qt.args[1].args) == 4
56-
Cname,Ctyp = qt.args[1].args[4].args
57-
esc(quote
58-
LazyArrays.ApplyStyle(::typeof(*), ::Type{<:$Atyp}, ::Type{<:$Btyp}, ::Type{<:$Ctyp}) = ContinuumArrays.SimplifyStyle()
59-
function Base.copy(M::ContinuumArrays.QMul3{<:$Atyp,<:$Btyp,<:$Ctyp})
60-
$Aname,$Bname,$Cname = M.args
61-
$mat
55+
apply_style_fun = :(LazyArrays.ApplyStyle(::typeof(*)) = ContinuumArrays.SimplifyStyle())
56+
copy_fun = :(function Base.copy(M::Mul{<:ContinuumArrays.AbstractQuasiArrayApplyStyle, <:Tuple{}})
57+
() = M.args
58+
$mat
59+
end)
60+
for arg in qt.args[1].args[2:end]
61+
arg isa Expr && arg.head == :(::) ||
62+
throw(ArgumentError("Invalid argument specification $(arg)"))
63+
arg_name, arg_typ = arg.args
64+
push!(apply_style_fun.args[1].args, :(::Type{<:$(arg_typ)}))
65+
push!(copy_fun.args[1].args[2].args[2].args[3].args[1].args, :(<:$(arg_typ)))
66+
push!(copy_fun.args[2].args[2].args[1].args, arg_name)
6267
end
63-
end)
64-
end
68+
esc(Expr(:block, apply_style_fun, copy_fun))
69+
end
6570
else # A\
6671
mat = qt.args[2]
6772
@assert qt.args[1].args[1] == :(\)

0 commit comments

Comments
 (0)