Skip to content

Commit 88459bd

Browse files
Apply suggestions from code review
Co-authored-by: willtebbutt <wt0881@my.bristol.ac.uk>
1 parent 15577d3 commit 88459bd

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/rule_definition_tools.jl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,10 @@ propagator_name(fname::QuoteNode, propname::Symbol) = propagator_name(fname.valu
254254
@non_differentiable(signature_expression)
255255
256256
A helper to make it easier to declare that a method is not not differentiable.
257-
This is a short-hand for defining a [`frule`](@ref) and an [`rrule`](@ref)+ pullback that
258-
returns [`DoesNotExist()`](@ref) for all partials (except for the function `s̄elf`-partial
257+
This is a short-hand for defining an [`frule`](@ref) and [`rrule`](@ref) that
258+
return [`DoesNotExist()`](@ref) for all partials (except for the function `s̄elf`-partial
259259
itself which is `NO_FIELDS`)
260260
261-
The usage is to put the macro before a function signature.
262261
Keyword arguments should not be included.
263262
264263
```jldoctest
@@ -309,7 +308,7 @@ function _nondiff_frule_expr(primal_sig_parts, primal_invoke)
309308
:(=),
310309
Expr(:call, :(ChainRulesCore.frule), esc(:_), esc.(primal_sig_parts)...),
311310
# Julia functions always only have 1 output, so just return a single DoesNotExist()
312-
Expr(:tuple, primal_invoke, DoesNotExist())
311+
Expr(:tuple, primal_invoke, DoesNotExist()),
313312
)
314313
end
315314

@@ -379,14 +378,14 @@ end
379378
"turn both `a` and `a::S` into `a`"
380379
_unconstrain(arg::Symbol) = arg
381380
function _unconstrain(arg::Expr)
382-
Meta.isexpr(arg, :(::), 2) && return arg.args[1] # dop constraint.
381+
Meta.isexpr(arg, :(::), 2) && return arg.args[1] # drop constraint.
383382
error("malformed arguments: $arg")
384383
end
385384

386-
"turn both `a` and `::Number` into `a::Number` into `a::Number` etc"
387-
function _constrain_and_name(arg::Expr, default_constraint)
385+
"turn both `a` and `::constraint` into `a::constraint` etc"
386+
function _constrain_and_name(arg::Expr, _)
388387
Meta.isexpr(arg, :(::), 2) && return arg # it is already fine.
389388
Meta.isexpr(arg, :(::), 1) && return Expr(:(::), gensym(), arg.args[1]) #add name
390389
error("malformed arguments: $arg")
391390
end
392-
_constrain_and_name(name::Symbol, constraint) = Expr(:(::), name, constraint) # add type
391+
_constrain_and_name(name::Symbol, constraint) = Expr(:(::), name, constraint) # add type

test/rule_definition_tools.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
)
2222
end
2323

24-
@testset "specific signature" begin
24+
@testset "constrained signature" begin
2525
nonembed_identity(x) = x
2626
@non_differentiable nonembed_identity(::Integer)
2727

@@ -62,4 +62,3 @@
6262

6363
end
6464
end
65-

0 commit comments

Comments
 (0)