Skip to content

Instantly share code, notes, and snippets.

View paulhendricks's full-sized avatar

Paul Hendricks paulhendricks

View GitHub Profile

Effective Modern CMake

Getting Started

For a brief user-level introduction to CMake, watch C++ Weekly, Episode 78, Intro to CMake by Jason Turner. LLVM’s CMake Primer provides a good high-level introduction to the CMake syntax. Go read it now.

After that, watch Mathieu Ropert’s CppCon 2017 talk Using Modern CMake Patterns to Enforce a Good Modular Design (slides). It provides a thorough explanation of what modern CMake is and why it is so much better than “old school” CMake. The modular design ideas in this talk are based on the book [Large-Scale C++ Software Design](https://www.amazon.de/Large-Scale-Soft

@paulhendricks
paulhendricks / latency.txt
Created May 28, 2018 03:45 — forked from understeer/latency.txt
HPC-oriented Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference/hit 1.5 ns 4 cycles
Floating-point add/mult/FMA operation 1.5 ns 4 cycles
L2 cache reference/hit 5 ns 12 ~ 17 cycles
Branch mispredict 6 ns 15 ~ 20 cycles
L3 cache hit (unshared cache line) 16 ns 42 cycles
L3 cache hit (shared line in another core) 25 ns 65 cycles
Mutex lock/unlock 25 ns
L3 cache hit (modified in another core) 29 ns 75 cycles
'''Trains a simple convnet on the MNIST dataset.
Gets to 99.25% test accuracy after 12 epochs
(there is still a lot of margin for parameter tuning).
16 seconds per epoch on a GRID K520 GPU.
'''
from __future__ import print_function
import keras
from keras.datasets import mnist
@paulhendricks
paulhendricks / data2.csv
Created August 2, 2016 19:26 — forked from BenHeubl/data2.csv
nuviun's Wearable Health Innovation Scoring - test
We can make this file beautiful and searchable if this error is corrected: It looks like row 4 should actually have 5 columns, instead of 4. in line 3.
innovationScore,innovationScore2,names,type,description
4.7,470,3L Labs Footlogger,medical,"The 3L Labs Footlogger is a wearable fitness tracking device that aims at spotting health problems early, as well as logging daily activity. Placed in the user's shoe, 8 sensors coupled to 1 accelerometer help identify and record exercise habits. The data is then disclosed to the user via text or smartphone app. This computing device's technology can be used for athletes training, regular everyday workouts and rehabilitation."
5.44,544,4D Force,,"The 4D Force is a wearable technology that detects brain waves and converts them into electric signals. 4D Force developed a platform that can capture and compute high quality EEG/ EOG/EMG signals. With the device, users can control games by using the power of their thoughts. 4D Force can also be used for medical purposes as it has the ability to interpret electrical signals generated by the body, and create recommendations for changes in lifestyle."
4,400,4iiii Viiiiva,Fitnes
#!/usr/bin/env julia
using Luxor
Drawing(500, 500, "/tmp/julia-flowers.png")
background("white")
function juliaflowers(cpos::Point, radius; petals=30, outercircleratio=0.75, innercircleratio=0.65)
# clockwise, from bottom LEFT...
points3 = ngon(cpos, radius, 3, pi/6, vertices=true)
import numpy as np
import theano; import theano.tensor as T; import theano.tensor.nnet as nnet
X_train = np.array([[0, 0], [0, 1], [1, 0], [1, 1]]).reshape((4, 2))
y_train = np.array([0, 1, 1, 0])
x = T.dvector('x')
y = T.dscalar('y')
theta_0 = theano.shared(np.array(np.random.rand(3, 3), dtype=theano.config.floatX), name='theta_0')
theta_1 = theano.shared(np.array(np.random.rand(4, 1), dtype=theano.config.floatX), name='theta_1')
layer_1 = nnet.sigmoid(T.dot(theta_0.T, T.concatenate([np.array([1], dtype=theano.config.floatX), x])))
layer_2 = T.sum(nnet.sigmoid(T.dot(theta_1.T, T.concatenate([np.array([1], dtype=theano.config.floatX), layer_1]))))
# Good - I can customize the way the file is read in
df <- read.csv("foo.csv", stringsAsFactors = FALSE)
df <- read.table("foo.txt", delimiter = "\t", stringsAsFactors = FALSE)
df <- read.table("foo.txt", delimiter = "|", stringsAsFactors = FALSE)
analyze(df)
# Bad - arguments are needed to customize how foo.csv is read in
analyze("foo.csv", stringsAsFactors = FALSE)
analyze("foo.txt", delimiter = "\t", stringsAsFactors = FALSE)
n <- 10000
alpha <- rnorm(n, 20, 5) # Customers spend on average $20 per transaction
plot(density(alpha))
b <- 10 # Customers who are petite spend on average $10 more per transaction
petite <- rbinom(n, size = 1, prob = 0.25) # Let's say 25% of customers are petite
eps <- rnorm(n, 0, 5) # Add some error
plot(density(eps))
y_true <- alpha + b * petite + eps
plot(density(y_true))
y_true[y_true < 0] <- 0
@paulhendricks
paulhendricks / setup.py
Last active October 28, 2016 14:14
A setup.py file for OpenAI's rllab
"""A setuptools based setup module.
See:
https://packaging.python.org/en/latest/distributing.html
https://github.com/pypa/sampleproject
"""
# Always prefer setuptools over distutils
from setuptools import setup, find_packages
# To use a consistent encoding
from codecs import open
# good
hello_world <- 1L
# bad - can I call hello(world)? It's unclear.
hello.world <- 1L