This file contains hidden or 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 foo(n::Integer) | |
| x::Int = 0 | |
| t1::Float64 = @elapsed for i in 1:n | |
| x = x + 1 | |
| end | |
| @printf "Int: %f\n" t1 | |
| y::BigInt = BigInt(0) | |
| t2::Float64 = @elapsed for i in 1:n | |
| y = y + BigInt(1) |
This file contains hidden or 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 Distributions | |
| import Distributions.entropy | |
| function entropy(d::FDist) | |
| a, b = d.ndf, d.ddf | |
| a2, b2 = a / 2.0, b / 2.0 | |
| return log(a / b) + lbeta(a2, b2) + | |
| (1.0 - a2) * digamma(a2) - | |
| (1.0 + b2) * digamma(b2) + | |
| (a2 + b2) * digamma(a2 + b2) |
This file contains hidden or 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 isint64(s::String) | |
| for chr in s | |
| if chr == 'e' || chr == '.' | |
| return false | |
| end | |
| end | |
| return true | |
| end |
This file contains hidden or 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
| # Utilities needed in rand() | |
| # (exp(x) - 1) / x | |
| function d2(z::Real) | |
| const p1 = 0.840066852536483239e3 | |
| const p2 = 0.200011141589964569e2 | |
| const q1 = 0.168013370507926648e4 | |
| const q2 = 0.18013370407390023e3 | |
| const q3 = 1.0 |
This file contains hidden or 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 Stats, Distributions, Vega | |
| Vega.plot(qq::QQPair) = Vega.plot(x = qq.qx, y = qq.qy, kind = :scatter) | |
| qqplot(x::Vector, y::Vector) = plot(qqbuild(x, y)) | |
| qqplot(x::Vector, d::UnivariateDistribution) = plot(qqbuild(x, d)) | |
| qqplot(d::UnivariateDistribution, x::Vector) = plot(qqbuild(d, x)) | |
| x = rand(Normal(), 10_000) | |
| y = rand(Cauchy(), 10_000) |
This file contains hidden or 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 Stats, Distributions, Vega | |
| Vega.plot(qq::QQPair) = Vega.plot(x = qq.qx, y = qq.qy, kind = :scatter) | |
| qqplot(x::Vector, y::Vector) = plot(qqbuild(x, y)) | |
| qqplot(x::Vector, d::UnivariateDistribution) = plot(qqbuild(x, d)) | |
| qqplot(d::UnivariateDistribution, x::Vector) = plot(qqbuild(d, x)) | |
| x = rand(Normal(), 10_000) | |
| y = rand(Cauchy(), 10_000) |
This file contains hidden or 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
| # f(z = x + iy) = u(x, y) + i * v(x, y) | |
| function finite_difference{T <: Complex}(f::Function, | |
| z::T, | |
| alongx::Bool = true, | |
| alongu::Bool = true) | |
| epsilon = sqrt(eps(max(abs(one(T)), abs(z)))) | |
| if alongx | |
| zplusdz = z + epsilon | |
| else | |
| zplusdz = z + epsilon * im |
This file contains hidden or 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
| # Always ignore one run | |
| x = 0 | |
| @elapsed for i in 1:100_000_000 | |
| x += 1 | |
| end # => 3.330939854 | |
| # Second time is more accurate |
This file contains hidden or 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
| # step1ab!() gets rid of plurals and -ed or -ing. e.g. | |
| # | |
| # caresses -> caress | |
| # ponies -> poni | |
| # ties -> ti | |
| # caress -> caress | |
| # cats -> cat | |
| # | |
| # feed -> feed | |
| # agreed -> agree |
This file contains hidden or 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
| f <- function(ex) {} | |
| f(print("Goodbye, cruel R argument passing semantics")) | |
| g <- function(ex) {ex} | |
| g(print("Hello, cruel R argument semantics")) |