Skip to content

Commit

Permalink
Revert "literal_pow: use it, add inverse"
Browse files Browse the repository at this point in the history
This reverts commit b1e2a9d.
  • Loading branch information
aplavin committed Dec 18, 2024
1 parent 3543101 commit fd02e6a
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 25 deletions.
4 changes: 0 additions & 4 deletions src/fixargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,3 @@ for kws in [(:rev,), (:by,), (:rev, :by), (:by, :rev)]
@eval set(obj, o::FixArgsT(sort, (Placeholder,), NamedTuple{$kws}), val) = @set obj[sortperm(obj; o.kwargs...)] = val
@eval modify(f, obj, o::FixArgsT(sort, (Placeholder,), NamedTuple{$kws})) = @modify(f, obj[sortperm(obj; o.kwargs...)])
end

InverseFunctions.inverse(f::FixArgsT(Base.literal_pow, (typeof(^), Placeholder, Val))) =
fixargs(Base.literal_pow, ^, Placeholder(), Val(inv(_extract_val(f.args[3]))))
_extract_val(::Val{P}) where {P} = P
5 changes: 0 additions & 5 deletions src/overrides.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@ function _parse_obj_optics(ex::Expr)
is_bcast = @capture(ex, tmpf_.(tmpargs__))
@debug "Captured f_(args__)" f args is_bcast

if f === (:^) && length(args) == 2 && args[2] isa Int
args = [f, args[1], Val(args[2])]
f = Base.literal_pow
end

args_contain_under = map(arg -> tree_contains(arg, :_), args)
f_contains_under = tree_contains(f, :_)
f_contains_under && any(args_contain_under) && error("Either the function or the arguments can contain an underscore, not both")
Expand Down
16 changes: 0 additions & 16 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -402,22 +402,6 @@ end
@test (aa=4, bb=5, cc=6) === modify(x -> Symbol(x, x), (a=4, b=5, c=6), @o keys(_)[])
end

@testitem "literal pow" begin
using Unitful
using AccessorsExtra: inverse

f1(x) = x^2
f2(x) = sqrt(x)
f3(x) = (@o _^2)(x)
f4(x) = inverse(@o _^2)(x)
f5(x, y) = @set $x^2 = y
@test (@inferred f1(2u"m")) == 4u"m"^2
@test (@inferred f2(4u"m")) == 2u"m"^(1//2)
@test (@inferred f3(2u"m")) == 4u"m"^2
@test (@inferred f4(4u"m")) == 2u"m"^(1//2)
@test (@inferred f5(2u"m", 4u"m")) == 2u"m"^(1//2)
end

@testitem "_" begin
import CompatHelperLocal as CHL
CHL.@check()
Expand Down

0 comments on commit fd02e6a

Please sign in to comment.