This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
julia> import BenchmarkTools: @btime | |
julia> @inline _logistic_bounds(x::Float16) = (Float16(-16.64), Float16(7.625)) | |
_logistic_bounds (generic function with 1 method) | |
julia> @inline _logistic_bounds(x::Float32) = (-103.27893f0, 16.635532f0) | |
_logistic_bounds (generic function with 2 methods) | |
julia> @inline _logistic_bounds(x::Float64) = (-744.4400719213812, 36.7368005696771) | |
_logistic_bounds (generic function with 3 methods) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
│ Row │ expr_type │ count │ percentage │ | |
│ │ Any │ Int64 │ Float64 │ | |
├─────┼────────────────────────────────┼────────┼─────────────┤ | |
│ 1 │ ExprKind{:outer} │ 1 │ 0.000226006 │ | |
│ 2 │ ExprKind{:/=} │ 1 │ 0.000226006 │ | |
│ 3 │ ExprKind{:typed_vcat} │ 1 │ 0.000226006 │ | |
│ 4 │ ExprKind{:.+=} │ 1 │ 0.000226006 │ | |
│ 5 │ ExprKind{:%=} │ 3 │ 0.000678017 │ | |
│ 6 │ ExprKind{:⊻=} │ 7 │ 0.00158204 │ | |
│ 7 │ ExprKind{:.=} │ 8 │ 0.00180804 │ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RCall: @R_str | |
function runtimes(n_reps) | |
times = Array{Float64}(undef, n_reps) | |
x = rand(10_000_000) | |
for i in 1:n_reps | |
times[i] = @elapsed sum(x) | |
end | |
times | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> library("stringr") | |
> str_sub("ñ", start = -1) | |
[1] "̃" | |
> str_sub("ñ", start = -1) | |
[1] "ñ" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function prob_f64(n) | |
s = 0 | |
for _ in 1:n | |
z_i = rand(UInt) | |
x_i = reinterpret(Float64, z_i) | |
s += Int(x_i == x_i + 1.0) | |
end | |
s, n | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function prob(n) | |
s = 0 | |
for _ in 1:n | |
x_i = rand(UInt) | |
s += Int(Float64(x_i) === Float64(x_i + 1)) | |
end | |
s, n | |
end | |
prob(1_000_000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fixed_point(f, x0) | |
x, x_old = f(x0), x0 | |
n = 1 | |
while x !== x_old | |
x, x_old = f(x), x | |
n += 1 | |
end | |
(x, n) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("pwr") | |
library("ggplot2") | |
n_sims <- 1000L | |
n <- 10L | |
mu <- 0.5 | |
sigma <- 1 | |
true_power <- power.t.test( | |
n = n, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using BenchmarkTools | |
n = 10_000_000 | |
x = rand(n) | |
y = [ifelse(iseven(i), missing, x[i]) for i in 1:n] | |
sum(x) | |
sum(y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 0.6 Approach | |
using BenchmarkTools | |
using NullableArrays | |
n = 10_000_000 | |
x = rand(n) | |
y = NullableArray{Float64}(n) | |
for i in 1:n | |
if !iseven(i) |