# Dense layer field alias

**URL:** <https://discourse.julialang.org/t/dense-layer-field-alias/78993>\
**Category:** Machine Learning\
**Tags:** flux\
**Created:** [April 4, 2022, 8:41am UTC](https://discourse.julialang.org/t/dense-layer-field-alias/78993 "2022-04-04T08:41:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rasmus\_Hoier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rasmus_hoier/32/24036_2.png) [@Rasmus\_Hoier](https://discourse.julialang.org/u/Rasmus_Hoier)\
**Post date:** [April 4, 2022, 8:41am UTC](https://discourse.julialang.org/t/dense-layer-field-alias/78993/1 "2022-04-04T08:41:08Z")

</div>

Hi, I am writing a custom layer and am trying to emulate the UI of Flux layers.

In the definition of Flux’s Dense layer the Dense struct has a field `weight`, but this field also has a kind of alias `W`. How/where is this alias defined? It was not apparent to me from reading the [source code](https://github.com/FluxML/Flux.jl/blob/6405ab32c2d33da090a6fbaaf66a6a9a09673978/src/layers/basic.jl#L141).

```julia
using Flux
a = Dense(3,3)
a.W === a.weight # is true

```

---

<div class="post-metadata">

**Author:** ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)\
**Post date:** [April 4, 2022, 9:32am UTC](https://discourse.julialang.org/t/dense-layer-field-alias/78993/2 "2022-04-04T09:32:59Z")

</div>

`a.W` is actually `getproperty(a, :W)`. This is not specific to Flux, but how the dot works in Julia.

Flux adds a specialization to `getproperty`. See `@which a.W` and the corresponding source file.

---

<div class="post-metadata">

**Author:** ![Rasmus\_Hoier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rasmus_hoier/32/24036_2.png) [@Rasmus\_Hoier](https://discourse.julialang.org/u/Rasmus_Hoier)\
**Post date:** [April 4, 2022, 10:28am UTC](https://discourse.julialang.org/t/dense-layer-field-alias/78993/3 "2022-04-04T10:28:45Z")

</div>

Thanks 🙂  
I found the relevant lines of code in my local install by using @which like you explained. Turns out a.W and a.b is deprecated syntax, and has been removed from master in this [commit](https://github.com/FluxML/Flux.jl/commit/9ea69ec040d1af933aed453c8b1bfd5507ebfbec#diff-5b453f8f7fb34afbebfc6f688a8209aa0532c8b1c3e95393f97afcbc37a473e7L1).

> **Old field name aliasing code**
>
> ```julia
> function Base.getproperty(a::Dense, s::Symbol)
> if s === :W
> Base.depwarn("field name dense.W is deprecated in favour of dense.weight", :Dense)
> return getfield(a, :weight)
> elseif s === :b
> Base.depwarn("field name dense.b is deprecated in favour of dense.bias", :Dense)
> return getfield(a, :bias)
> end
> return getfield(a, s)
> end
> 
> ```
