julia> macro unpacker(expr)
(expr.head != :(=) || length(expr.args) != 2) && error("Expression needs to be of form `name = value`")
name, value = expr.args
@gensym(props, x)
return esc(quote
$props = propertynames($value)
macro $name($x)
return Expr(:(=), Expr(:tuple, $props...), $x)
end
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
# Background: | |
# - Release in ≈ 2012 | |
# - Intended for scientific programming, but solving 2-language-problem | |
# - Replace Matlab/Fortran/C++ with free, dynamic language (inspired by | |
# Matlab, Python, Ruby, LISP, Perl,...) | |
# - Has become really good alternative to Matlab & Python | |
# - GC, dynamic, but strong nominal parametric type system with | |
# multiple dispatch | |
# - Extensive standard library (numerics, glue code), loads of packages | |
# - JIT-compiled |
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 CategoricalArrays | |
using DataFrames | |
using Distributions | |
using DynamicPPL | |
using MixedModels | |
using Plots | |
using StatsFuns | |
using StatsModels | |
using StatsPlots | |
using Turing |
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> HasFields(::Type{T}) where {T} = Val{true}() | |
HasFields (generic function with 1 method) | |
julia> HasFields(::Type{T}, ::Type{U}, name) where {T, U} = Val{fieldtype(T, name) <: U}() | |
HasFields (generic function with 2 methods) | |
julia> HasFields(Some, Any, :value) | |
Val{true}() | |
julia> HasFields(::Type{T}, ::Type{U}, name, names...) where {T, U} = Val{fieldtype(T, name) <: U && HasFields(T, U, names...) isa Val{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
# trying to refactor https://codereview.stackexchange.com/q/259818/180160 | |
# not tested for correctness | |
const EPSILON = 1e-6 | |
log_ϕ(x, μ, σ) = -(((x - μ) / σ)^2 - log(2π)) / 2 - log(σ) | |
ϕ(x, μ, σ) = exp(log_ϕ(x, μ, σ)) | |
log_likelihood(x, θ) = sum(log(θ.p' * ϕ.(xₜ, θ.μ, θ.σ)) for xₜ in x) | |
function normalize!(θ; eps=EPSILON) |
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
IRTools.@dynamo function sloppyifs(f, args...) | |
ir = IRTools.IR(f, args...) | |
ir === nothing && return | |
IRTools.recurse!(ir) | |
for block in IRTools.blocks(ir) | |
bblock = IRTools.BasicBlock(block) | |
for b in eachindex(IRTools.branches(bblock)) | |
branch = bblock.branches[b] | |
if IRTools.isconditional(branch) |
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 IRTools | |
abstract type AbstractNode end | |
struct Node <: AbstractNode | |
ir::IRTools.IR | |
children::Vector{<:AbstractNode} | |
end | |
Node(ir) = Node(ir, Vector{AbstractNode}()) |
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
{-# LANGUAGE DataKinds, | |
TypeFamilies, | |
PolyKinds, | |
GADTs, | |
ConstraintKinds #-} | |
module MonadicFlow ( | |
Sec, | |
Less, | |
open, |
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 Einsum | |
using TensorOperations | |
const N = 9851 | |
const K = 35 | |
const D = 16 | |
const x = rand(N, D) | |
const μ = rand(D, K) |
NewerOlder