Skip to content

Instantly share code, notes, and snippets.

View example2.jl
import Plots
r = range(0.0, 1.0, length=512)
p = Plots.plot(
r,
x -> x^2 * (1 - x)^2,
)
Plots.png(p, "output2.png")
View example.R
#!/usr/bin/Rscript
png("output.png")
curve(x^2 * (1 - x)^2, from = 0, to = 1)
dev.off()
# time Rscript example.R
# null device
# 1
#
View logistic_comparisons.jl
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)
View runtimes.jl
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
View graphemes.R
> library("stringr")
> str_sub("", start = -1)
[1] "̃"
> str_sub("ñ", start = -1)
[1] "ñ"
View prob_f64.jl
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
View prob_uint.jl
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)
View fixed_points.jl
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
View DistributionsAPI.md

Univariate API

A new univariate distribution type should implement all of the following methods:

  • Core constructors
    • MyDistribution{T}(args[...])
    • We need to clarify whether constructors should handle input validation or not. There are use cases in which people want to avoid input validation.
  • params(d::MyDistribution{T})::Tuple: A tuple of the distribution's parameters in our canonical order.
  • minimum(d::MyDistribution{T})::T: The lowest value in the support of MyDistribution.
  • maximum(d::MyDistribution{T})::T: The highest value in the support of MyDistribution.
View retrospective_powerR
library("pwr")
library("ggplot2")
n_sims <- 1000L
n <- 10L
mu <- 0.5
sigma <- 1
true_power <- power.t.test(
n = n,