Skip to content

Instantly share code, notes, and snippets.

View oschulz's full-sized avatar

Oliver Schulz oschulz

  • Max Planck Institute for Physics
  • Munich
View GitHub Profile
@oschulz
oschulz / cxx_root_ttree.jl
Last active January 13, 2016 23:19
Writing a CERN ROOT TTree from Julia using Cxx.jl
# Copyright (C) 2016 Oliver Schulz <oschulz@mpp.mpg.de>
# Licensed under the MIT License: http://opensource.org/licenses/MIT
# Note: Currently only works with ROOT-5, not ROOT-6, due to LLVM clashes
# between Cling and Julia.
using Cxx
using Distributions
incdir = strip(readall(`root-config --incdir`))
@oschulz
oschulz / cxx_root_gui.jl
Last active January 13, 2016 23:19
Using CERN ROOT GUI features from Julia
# Copyright (C) 2016 Oliver Schulz <oschulz@mpp.mpg.de>
# Licensed under the MIT License: http://opensource.org/licenses/MIT
# Note: Currently only works with ROOT-5, not ROOT-6, due to LLVM clashes
# between Cling and Julia.
using Cxx
using Distributions
incdir = strip(readall(`root-config --incdir`))
@oschulz
oschulz / plots-contours-viridis.ipynb
Created April 13, 2016 14:50
Plots.jl contour plot with viridis color map
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
using Cxx
cxx"""
#include <iostream>
class MyClass {
public:
int i = 0;
MyClass() { std::cerr << "INFO: MyClass()" << std::endl; }
MyClass(int j) : i(j) { std::cerr << "INFO: MyClass(" << i << ")" << std::endl; }
@oschulz
oschulz / symbolic_ml_optimization.jl
Created November 21, 2023 16:43
Demo of symbolic optimization of sparse ML models using Julia and Symbolics.jl
using Flux, StatsBase, Symbolics, SparseArrays, StaticArrays, Functors, BenchmarkTools
# Simple dummy ML classifier model:
ninputs = 10
nlatent = 40
model = Chain(
Dense(ninputs => nlatent, relu),
Dense(nlatent => nlatent, relu),
abstract type Countable{sym} end
Base.show(io::IO, x::Countable{sym}) where sym = print(io, x.n == 1 ? "$sym" : "$(x.n)$sym")
getsym(x::Countable{sym}) where sym = sym
Base.:*(n::Integer, x::Countable) = typeof(x)(n * x.n)
Base.:+(a::Countable, b::Countable) = error("Can't add $(getsym(a))s and $((getsym(b)))s")
Base.:+(a::T, b::T) where {T<:Countable} = T(a.n + b.n)