# Dot syntax and reduction

**URL:** https://discourse.julialang.org/t/dot-syntax-and-reduction/2091
**Category:** General Usage
**Tags:** question
**Created:** [February 13, 2017, 10:16pm UTC](https://discourse.julialang.org/t/dot-syntax-and-reduction/2091 "2017-02-13T22:16:51Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [February 13, 2017, 10:16pm UTC](https://discourse.julialang.org/t/dot-syntax-and-reduction/2091/1 "2017-02-13T22:16:51Z")

</div>

If I do:

```julia
all(x .== 0)

```

where `x` is a huge vector (for example), will this instantiate the intermediate array of Booleans (`x .== 0`)?

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [February 13, 2017, 10:24pm UTC](https://discourse.julialang.org/t/dot-syntax-and-reduction/2091/2 "2017-02-13T22:24:17Z")

</div>

Yes, it will. But you can use a generator to compute the answer without creating an intermediate array. It’s easy to see the difference using `BenchmarkTools.jl`:

```julia
julia> x = zeros(1000000);

julia> @benchmark all($x .== 0)
BenchmarkTools.Trial:
  memory estimate: 164.73 KiB
  allocs estimate: 741
  --------------
  minimum time: 2.086 ms (0.00% GC)
  median time: 2.201 ms (0.00% GC)
  mean time: 2.405 ms (0.39% GC)
  maximum time: 5.671 ms (0.00% GC)
  --------------
  samples: 2054
  evals/sample: 1
  time tolerance: 5.00%
  memory tolerance: 1.00%

julia> @benchmark all(xx == 0 for xx in $x)
BenchmarkTools.Trial:
  memory estimate: 16 bytes
  allocs estimate: 1
  --------------
  minimum time: 490.032 μs (0.00% GC)
  median time: 506.804 μs (0.00% GC)
  mean time: 558.958 μs (0.00% GC)
  maximum time: 2.241 ms (0.00% GC)
  --------------
  samples: 8580
  evals/sample: 1
  time tolerance: 5.00%
  memory tolerance: 1.00%

```

(look at the difference in memory allocation in particular).

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [February 13, 2017, 10:26pm UTC](https://discourse.julialang.org/t/dot-syntax-and-reduction/2091/3 "2017-02-13T22:26:58Z")

</div>

Or use the version with a predicate:

```julia
all(x->x==0, y)

```

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [February 14, 2017, 12:11am UTC](https://discourse.julialang.org/t/dot-syntax-and-reduction/2091/4 "2017-02-14T00:11:21Z")

</div>

Or `all(iszero, y)`, since 0.6 provides a function `iszero` to efficiently check whether `x == zero(x)`, and `iszero` is supported in 0.5 via the Compat package. If `y` is an array, you can just do `iszero(y)` also.

---

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [February 14, 2017, 12:16am UTC](https://discourse.julialang.org/t/dot-syntax-and-reduction/2091/5 "2017-02-14T00:16:51Z")

</div>

@stevengj That’s nice. How is `iszero(x)` more efficient than `x == zero(x)` (for a scalar)?

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [February 14, 2017, 1:21am UTC](https://discourse.julialang.org/t/dot-syntax-and-reduction/2091/6 "2017-02-14T01:21:48Z")

</div>

For more complicated scalar types, `zero(x)` can involve creating an instance of a complicated object, which `iszero(x)` can avoid. An extreme example of this would be a BigFloat.

---

<div class="post-metadata">

### Author: ![ettersi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ettersi/32/6829_2.png) [@ettersi](https://discourse.julialang.org/u/ettersi)
#### Post date: [March 16, 2018, 11:19pm UTC](https://discourse.julialang.org/t/dot-syntax-and-reduction/2091/7 "2018-03-16T23:19:57Z")

</div>

Are there any plans that Julia would eventually eliminate the temporary in expressions like `prod(a.+b)`? Me for one would definitely want this.
