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
params{T}(::Type{T}) = T.parameters | |
# Parameterize column types and fields | |
# by utilizing tuples | |
type DataFrame{C<:Tuple, F<:Tuple} | |
columns::C | |
fields::Type{F} | |
function DataFrame(columns::C, fields::Type{F}) | |
nrows = length(first(columns)) | |
equallengths = true |
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 ForwardDiff | |
function check_failure_ratio(test_hessf::Function, input::Array, original::Array, max_iter=10e6) | |
bad_versions = 0 | |
for iter = 1:max_iter | |
if maximum(abs(test_hessf(input) - original)) > 1 | |
bad_versions += 1; | |
end | |
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
# This file is a naive implementation of numbers of the form x + y*i where i^2 = p | |
####################### | |
# GeneralComplex type # | |
####################### | |
immutable GeneralComplex{p,T} <: Number | |
x::T | |
y::T | |
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
@everywhere module A | |
immutable Foo{T} | |
x::T | |
end | |
cross(a::Foo, b::Foo) = Foo(a.x * b.x) | |
function reload_cross(a, b) | |
include(joinpath(pwd(), "parallel-reload-bug.jl")) | |
return A.cross(a, b) |
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
# execute by running `➜ mpiexec -n $NUM_PROCS julia mpi_pagerank_kernel0.jl` | |
import MPI | |
MPI.Init() | |
###################### | |
# KronGraph500NoPerm # | |
###################### |
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 tupexpr(f, N) | |
ex = Expr(:tuple, [f(i) for i=1:N]...) | |
return quote | |
@inbounds return $(ex) | |
end | |
end | |
@inline iszero_tuple(::Tuple{}) = true | |
@inline zero_tuple(::Type{Tuple{}}) = tuple() | |
@inline one_tuple(::Type{Tuple{}}) = tuple() |
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 ForwardDiff | |
using BenchmarkTools | |
function gen_beta_kl_obj(alpha2, beta2) | |
lgamma_alpha2 = lgamma(alpha2) | |
lgamma_beta2 = lgamma(beta2) | |
return x -> begin | |
alpha1, beta1 = x | |
alpha_diff = alpha1 - alpha2 | |
beta_diff = beta1 - beta2 |
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 | |
using ReverseDiff: @forward, GradientTape, gradient!, compile | |
# Similar to XDiff's @diff_rule, except it gets the derivative automatically via forward mode. | |
# In future versions, `@forward` will no longer be necessary. | |
@forward logistic(x::Real) = 1 / (1 + exp(-x)) | |
# This is how I would write this for ReverseDiff usage if parser fusion didn't mess things up. | |
# In the future, this form will be performant (all the pieces already exist, they just have | |
# to be hooked up). |
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 Cassette | |
function rosenbrock(x) | |
a = one(eltype(x)) | |
b = 100.0 | |
result = zero(a) | |
for i in 1:length(x)-1 | |
result += (a - x[i])^2 + b*(x[i+1] - x[i]^2)^2 | |
end | |
return result |
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
# This script requires an up-to-date ForwardDiff, ReverseDiff, and Julia v0.6 installation. | |
using ForwardDiff, ReverseDiff | |
D_f(f) = x::Number -> ForwardDiff.derivative(f, x) | |
# ReverseDiff's API only supports array inputs, so we just wrap our scalar input in a | |
# 1-element array and extract our scalar derivative from the returned gradient array | |
D_r(f) = x::Number -> ReverseDiff.gradient(y -> f(y[1]), [x])[1] |
OlderNewer