File tree Expand file tree Collapse file tree 2 files changed +20
-5
lines changed Expand file tree Collapse file tree 2 files changed +20
-5
lines changed Original file line number Diff line number Diff line change 99
99
100
100
macro functor (args... )
101
101
@warn """ The use of `Flux.@functor` is deprecated.
102
- Most likely, you should write `Flux.@layer MyLayer` which will add various convenience methods for your type,
102
+ Most likely, you should write `Flux.@layer MyLayer`\
103
+ which will add various convenience methods for your type,\
103
104
such as pretty-printing and use with Adapt.jl.
104
- However, this is not required. Flux.jl v0.15 uses Functors.jl v0.5, which makes exploration of most nested `struct`s
105
- opt-out instead of opt-in... so Flux will automatically see inside any custom struct definitions.
105
+ However, this is not required. Flux.jl v0.15 uses Functors.jl v0.5,\
106
+ which makes exploration of most nested `struct`s opt-out instead of opt-in...\
107
+ so Flux will automatically see inside any custom struct definitions.
106
108
If you really want to apply the `@functor` macro to a custom struct, use `Functors.@functor` instead.
107
109
""" maxlog= 1
108
-
109
- return Functors. functorm ( args... )
110
+ # From https://discourse.julialang.org/t/calling-a-macro-from-within-a-macro-revisited/19680
111
+ return esc (:( $ Functors. @functor ( $ ( args... ))) )
110
112
end
111
113
112
114
# Allows caching of the parameters when params is called within gradient() to fix #2040.
Original file line number Diff line number Diff line change 2
2
ps = Flux. params ([2 ,3 ])
3
3
@test length (ps) == 1
4
4
end
5
+
6
+ @testset " Flux.@functor" begin
7
+ # https://github.com/FluxML/Flux.jl/issues/2545
8
+ struct A2545; x; y; end
9
+ Flux. @functor A2545
10
+ a = A2545 (1 , 2 )
11
+ @test fmap (x -> 2 x, a) == A2545 (2 , 4 )
12
+
13
+ struct B2545; x; y; end
14
+ Flux. @functor B2545 (x,)
15
+ b = B2545 (1 , 2 )
16
+ @test fmap (x -> 2 x, b) == B2545 (2 , 2 )
17
+ end
You can’t perform that action at this time.
0 commit comments