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 17, 2018
1 parent 3fe2d08 commit 8074726
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,30 @@ 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]; 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 8074726

Please sign in to comment.