Skip to content

Instantly share code, notes, and snippets.

View xiaodaigh's full-sized avatar

evalparse xiaodaigh

View GitHub Profile
@xiaodaigh
xiaodaigh / 0-benchmarks.jl
Last active September 15, 2019 07:00
Julia On-disk formats for saving DataFrames
using CSV, Feather, JLD2, JLSO, JDF, FileIO, Blosc, StatsPlots
using DataFrames, WeakRefStrings # required for JLD2, JDF
Blosc.set_num_threads(6)
gen_benchmark(dirpath, largest_file, outpath, data_label; delim = ',', header=true) = begin
if !isdir(outpath)
mkpath(outpath)
end
@xiaodaigh
xiaodaigh / julia-slow-serialization.jl
Created September 13, 2019 05:27
Julia serialization is dog-slow
using JDF
using CSV, DataFrames
using Serialization:serialize,deserialize
using BufferedStreams
@time a = CSV.read("C:/Users/ZJ.DAI/Documents/git/format-wars/data/Performance_2016Q4.txt", delim = '|', header = false);
io = BufferedOutputStream(open("c:/data/bin.bin","w"))
@time serialize(io, a)
close(io)
@xiaodaigh
xiaodaigh / example_rayshader_4walls_hole.r
Created March 12, 2019 22:31
Example rotating sunangle
library(rayshader)
library(av)
library(future)
plan(multiprocess)
# set up an elevation matrix with a wall around the outside and a gap on each of
# the walls.
elmat1 = matrix(0, 500, 500)
elmat1[1:100, 1:200] = 3000
@xiaodaigh
xiaodaigh / ok.r
Created March 12, 2019 05:23
3d sun around a pole
library(rayshader)
library(av)
elmat1 = matrix(0, 500, 500)
elmat1[200:400, 200:400] = 971.0
sunangle = 33
for(sunangle in 140:360) {
elmat1 %>%
sphere_shade %>%
add_shadow(ray_shade(elmat1,zscale=3,maxsearch = 300, sunangle = sunangle),0.5) %>%
@xiaodaigh
xiaodaigh / cpu_bitonic_sort.jl
Last active January 29, 2019 12:46
CPU bitonic sort
shared = rand(16)
bisort(shared) = begin
NUM = UInt(length(shared))
k = UInt(2)
while (k <= NUM)
j = div(k,2)
while(j >=1)
for tid in UInt(0):UInt(NUM-1)
@xiaodaigh
xiaodaigh / benchmark_2048.jl
Created October 15, 2018 04:06
2048 Simulation challenge
using StatsBase
const DIRS = [:left, :up, :right, :down]
function init_game()
grid = zeros(Int8,4,4)
grid[rand(1:4),rand(1:4)] = rand2_1()
grid[rand(1:4),rand(1:4)] = rand2_1()
grid
end
@xiaodaigh
xiaodaigh / ctree_kmeans_iris_model_assessment
Created October 15, 2017 23:51
ctree vs kmeans on the iris dataset
# data prep ---------------------------------------------------------------
library(data.table)
data(iris)
iris_copy <- copy(iris)
setDT(iris_copy)
iris_copy_ctree <- copy(iris_copy)
# ctree model -------------------------------------------------------------
@xiaodaigh
xiaodaigh / 1_forwardflag.r
Last active December 20, 2017 21:02
Fast implementation of binary (true/false) forward looking flag
forwardflag <- function(bools, ...) {
if(typeof(bools) != "boolean") {
warning("input variable not of boolean type, the only other accepted type is 0 & 1")
}
forwardflag_(bools, ...)
}
forwardflag_ <- function(bools, period = 12) {
stopifnot(period > 0)
`infix_fn` <- function(left, right) {
#...some code
}