Skip to content

Commit

Permalink
Merge FluxML#1549
Browse files Browse the repository at this point in the history
1549: Docstrings for f32 and f64 r=darsnack a=B-LIE

I was challenged to add docstrings to f32 and f64, and have done that.

Since I really never have used Git before, I feel on thin ice here, so I guess the challenge was more to push me out on the ice...


Co-authored-by: B-LIE <[email protected]>
  • Loading branch information
bors[bot] and B-LIE authored Mar 27, 2021
2 parents 5c40716 + 1808c75 commit e251327
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/src/utilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ Flux.orthogonal
Flux.sparse_init
```

## Changing the type of model parameters

```@docs
Flux.f64
Flux.f32
```

The default `eltype` for models is `Float32` since models are often trained/run on GPUs. The `eltype` of model `m` can be changed to `Float64` by `f64(m)`, or to `Float32` by `f32(m)`.

## Model Building

Flux provides some utility functions to help you generate models in an automated fashion.
Expand Down
11 changes: 11 additions & 0 deletions src/functor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,18 @@ adapt_storage(T::Type{<:Real}, xs::AbstractArray{<:Real}) = convert.(T, xs)

paramtype(T::Type{<:Real}, m) = fmap(x -> adapt(T, x), m)

"""
f32(m)
Convert the `eltype` of model's parameters to `Float32`.
"""
f32(m) = paramtype(Float32, m)

"""
f64(m)
Convert the `eltype` of model's parameters to `Float64`.
"""
f64(m) = paramtype(Float64, m)

# Functors for certain Julia data structures
Expand Down

0 comments on commit e251327

Please sign in to comment.