Skip to content

Commit a571383

Browse files
Analysis of vany/vall
1 parent 6a55dec commit a571383

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,29 @@ Define a linearized cost model, with `t` the time required to evaluate one eleme
4646
t_{0} n (1 - p)^n
4747
```
4848
<img src="https://render.githubusercontent.com/render/math?math={t_{0} n (1 - p)^{n}}#gh-light-mode-only">
49-
<img src="https://render.githubusercontent.com/render/math?math={\color{white}t_{0} n (1 - p)^{n}}#gh-dark-mode-only">
49+
<img src="https://render.githubusercontent.com/render/math?math={\color{white}t_{0} n (1 - p)^{n}}#gh-dark-mode-only">
50+
Thus, the point at which non-vectorized evaluation is optimal is
51+
```julia
52+
t₀ * (1 - p)^n < tᵥ
53+
```
54+
Or, rearranging: non-vectorized is optimal when `p > 1 - (tᵥ/t₀)^(1/n)`. Intuitively, as `(tᵥ/t₀)` becomes smaller, larger `p` is needed to make the non-vectorized option optimal.
55+
Holding `(tᵥ/t₀)` constant, increasing `n` results in a rapid decrease in the `p` required for the non-vectorized option to be optimal. Consider the following examples, denoting `r = (tᵥ/t₀)`
56+
```julia
57+
julia> p(r, n) = 1 - r^(1/n)
58+
p (generic function with 1 method)
59+
60+
julia> p.(.1, 10 .^ (1:4))
61+
4-element Vector{Float64}:
62+
0.2056717652757185
63+
0.02276277904418933
64+
0.0022999361774467264
65+
0.0002302320018434667
66+
67+
julia> p.(.01, 10 .^ (1:4))
68+
4-element Vector{Float64}:
69+
0.36904265551980675
70+
0.045007413978564004
71+
0.004594582648473011
72+
0.0004604109969121861
73+
```
74+
However, due to the current implementation details of Base `any`/`all`, early breakout occurs only when the reduction is being carried out across the entire array (i.e. does not occur when reducing over a subset of dimensions). Thus, the current advice is to use `vany`/`vall` unless one is reducing over the entire array, and even then, one should consider the `p` and `n` for one's problem.

0 commit comments

Comments
 (0)