You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+35Lines changed: 35 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -87,3 +87,38 @@ These types have methods that perform many operations efficiently,
87
87
including elementary algebra operations like multiplication and addition,
88
88
as well as linear algebra methods like
89
89
`norm`, `adjoint`, `transpose` and `vec`.
90
+
91
+
## Warning!
92
+
93
+
Broadcasting operations and `map`, `mapreduce` are also done efficiently, by evaluating the function being applied only once:
94
+
95
+
```julia
96
+
julia>map(sqrt, Fill(4, 2,5)) # one evaluation, not 10, to save time
97
+
2×5 Fill{Float64}: entries equal to 2.0
98
+
99
+
julia>println.(Fill(pi, 10))
100
+
π
101
+
10-element Fill{Nothing}: entries equal to nothing
102
+
```
103
+
104
+
Notice that this will only match the behaviour of a dense matrix from `fill` if the function is pure. And that this shortcut is taken *before* any other fused broadcast:
105
+
106
+
```julia
107
+
julia>map(_ ->rand(), Fill("pi", 2,5)) # not a pure function!
108
+
2×5 Fill{Float64}: entries equal to 0.7201617100284206
109
+
110
+
julia>map(_ ->rand(), fill("4", 2,5)) # 10 evaluations, different answer!
111
+
2×5 Matrix{Float64}:
112
+
0.436750.2708090.565360.09480890.24655
113
+
0.9593630.795980.2386620.4019090.317716
114
+
115
+
julia>ones(1,5) .+ (_ ->rand()).(Fill("vec", 2)) # Fill broadcast is done first
0 commit comments