Skip to content

Instantly share code, notes, and snippets.

View nlw0's full-sized avatar

Nicolau Leal Werneck nlw0

View GitHub Profile
@nlw0
nlw0 / MNIST CNN in Julia.ipynb
Last active October 8, 2019 22:33
Training a CNN on MNIST with Julia and Flux
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nlw0
nlw0 / treesize.jl
Last active October 8, 2019 19:52
Experiments reading file sizes from a large number of files
using MD5
using BenchmarkTools
function generate_tree(treeroot, N, silly=false)
mkdir(treeroot)
J = if silly 1 else N end
K = if silly N*N else N end
for j in 1:J
@nlw0
nlw0 / change.cpp
Last active December 5, 2019 16:16
change-making problem in multiple languages
#include <unordered_set>
#include <vector>
#include <optional>
#include <iostream>
#include <chrono>
#include <ctime>
template<typename T> std::optional<int> minimum_coins(T target, std::vector<T> denominations) {
auto values = new std::unordered_set<T>(); values->insert(target);
auto k = 0;
; ModuleID = 'vectest.c'
source_filename = "vectest.c"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"
; Function Attrs: noinline nounwind uwtable
define float @myfun(i32, float*) #0 {
%3 = alloca i32, align 4
%4 = alloca float*, align 8
%5 = alloca float, align 4
@nlw0
nlw0 / snip_min_f64_fast.ll
Last active April 18, 2019 21:23
LLVM passes from the min and sum reductions with float and i32 in Julia
*** IR Dump After Demanded bits analysis ***
define double @julia_myfun_15949(%jl_value_t addrspace(10)* nonnull align 16 dereferenceable(40)) !dbg !7 {
top:
%1 = alloca { i64, i8 }, align 8
%2 = call %jl_value_t*** @julia.ptls_states()
%3 = addrspacecast %jl_value_t addrspace(10)* %0 to %jl_value_t addrspace(11)*, !dbg !9
%4 = bitcast %jl_value_t addrspace(11)* %3 to double addrspace(13)* addrspace(11)*, !dbg !9
%5 = load double addrspace(13)*, double addrspace(13)* addrspace(11)* %4, align 8, !dbg !9, !tbaa !13, !nonnull !4
%6 = load double, double addrspace(13)* %5, align 8, !dbg !9, !tbaa !17
%7 = bitcast %jl_value_t addrspace(11)* %3 to %jl_value_t addrspace(10)* addrspace(11)*, !dbg !20
julia> @code_native myf(7, 3)
.text
; ┌ @ REPL[2]:1 within `myf'
; │┌ @ REPL[2]:1 within `-'
subq %rsi, %rdi
addq $-2, %rsi
; │└
; │┌ @ int.jl:54 within `*'
imulq %rdi, %rsi
; │└
@nlw0
nlw0 / juliasetdemo.jl
Last active April 4, 2019 20:12
Interactively draw the Julia set fractal using SDL
using Images
using SimpleDirectMediaLayer
const SDL2 = SimpleDirectMediaLayer
function render_julia_set!(pixels, c, J, K, ::Val{MaxIt}, cmap) where MaxIt
color_lookup(val) = cmap[val + 1]
@inbounds for j in 1:J, k in 1:K
vv = julia_pix(c, j, k, J, K, Val(MaxIt))
@nlw0
nlw0 / julia_set_anim.ipynb
Last active March 31, 2019 18:42
Julia set animation
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nlw0
nlw0 / SIMD_demo.ipynb
Created February 9, 2019 19:10
SIMD based merge sort in Julia
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nlw0
nlw0 / testcache.jl
Created February 5, 2019 22:07
Experiment to demonstrate the effects of cache memory
using BenchmarkTools
function myadd1(a, it)
N=size(a,1)
acc = 1
for i in 1:it
a[acc] = 1 + (a[acc] + 16807 * 33 * (acc + a[a[a[acc]]])) % (N-1)
acc = 1 + (acc + 16807 * 17 * acc + a[a[acc]]) % (N-1)
end
end