Skip to content

Commit

Permalink
Add doctest example for broadcast!
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt committed Aug 14, 2018
1 parent 3fe2d08 commit b2d2676
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,32 @@ Like [`broadcast`](@ref), but store the result of
Note that `dest` is only used to store the result, and does not supply
arguments to `f` unless it is also listed in the `As`,
as in `broadcast!(f, A, A, B)` to perform `A[:] = broadcast(f, A, B)`.
# Examples
```jldoctest
julia> A = [1.0; 0.0];
julia> B = [0.0; 0.0];
julia> broadcast!(+, B, A, (0, -2.0));
julia> B
2-element Array{Float64,1}:
1.0
-2.0
julia> A
2-element Array{Float64,1}:
1.0
0.0
julia> broadcast!(+, A, A, (0, -2.0));
julia> A
2-element Array{Float64,1}:
1.0
-2.0
```
"""
broadcast!(f::Tf, dest, As::Vararg{Any,N}) where {Tf,N} = (materialize!(dest, broadcasted(f, As...)); dest)

Expand Down

0 comments on commit b2d2676

Please sign in to comment.