Skip to content

Instantly share code, notes, and snippets.

View ryanrhymes's full-sized avatar
🎯
Focusing

Liang Wang ryanrhymes

🎯
Focusing
View GitHub Profile
s = window.getSelection();
oRange = s.getRangeAt(0); //get the text range
oRect = oRange.getBoundingClientRect();
@ryanrhymes
ryanrhymes / cpu_count.ml
Created December 9, 2016 22:49
number of cores
let cpu_count () =
try match Sys.os_type with
| "Win32" -> int_of_string (Sys.getenv "NUMBER_OF_PROCESSORS")
| _ ->
let i = Unix.open_process_in "getconf _NPROCESSORS_ONLN" in
let close () = ignore (Unix.close_process_in i) in
try Scanf.fscanf i "%d" (fun n -> close (); n) with e -> close (); raise e
with
| Not_found | Sys_error _ | Failure _ | Scanf.Scan_failure _
| End_of_file | Unix.Unix_error (_, _, _) -> 1
shape = (10,1000,10000)
function f00()
t0 = time()
x = []
t1 = time()
@printf "empty:\t\t%.8f\n" (t1 -t0)
end
function f01()
#!/usr/bin/env python
import time
import math
import numpy as npy
m, n, o = 10, 1000, 10000
shape = [m,n,o]
def f00 () :
open Owl
open Bigarray
let m, n, o = 10, 1000, 10000
let shape = [|m;n;o|]
let test_op s c op =
let ttime = ref 0. in
for i = 1 to c do
@ryanrhymes
ryanrhymes / Makefile
Created January 12, 2017 16:39
Makefile for Eigen library
CXXFLAGS0 = -shared -fPIC -ansi -pedantic -W -Wall
CXXFLAGS1 = -shared -fPIC -ansi -pedantic -Wno-extern-c-compat -Wno-c++11-long-long
CXXFLAGS2 = -c -ansi -Wno-extern-c-compat -Wno-c++11-long-long
all:
g++ ${CXXFLAGS2} -I. eigen_dsmat.cpp -o eigen_dsmat.o
g++ ${CXXFLAGS2} -I. eigen_spmat.cpp -o eigen_spmat.o
#gcc -c ffi_eigen_generated_stub.c -I. -I`ocamlfind query ctypes` -I`ocamlc -where` -o eigen_stub.o
ld -r eigen_*.o -o libeigen.o
ocamlfind ocamlc -c -package ctypes ffi_eigen_generated.ml
@ryanrhymes
ryanrhymes / eigen_dsmat.ml
Created January 12, 2017 16:41
Functor of dsmat in Eigen library
(*
* Eigen - an OCaml interface to C++ Eigen library
* Copyright (c) 2016 Liang Wang <liang.wang@cl.cam.ac.uk>
*)
module type MatSig = sig
type elt
type mat
@ryanrhymes
ryanrhymes / mnist.ml
Created March 9, 2017 17:26
re-format mnist data set
(* Test neural network on MNIST *)
#require "bitstring";;
#require "bitstring.syntax";;
open Bitstring
type t = { magic : int; items : int }
let dataset = "/Users/liang/owl_dataset/t10k-images-idx3-ubyte"
@ryanrhymes
ryanrhymes / owl_nn.ml
Created March 10, 2017 15:54
using owl to build a trivial nn sing AD module from scratch
open Owl_algodiff_ad
type layer = { mutable w : t; mutable b : t; a : t -> t }
type network = { layers : layer array }
let run_layer x l = Maths.((x $@ l.w) + l.b) |> l.a
let run_network x nn = Array.fold_left run_layer x nn.layers
open Owl
open Algodiff.AD
type layer = { mutable w : t; mutable b : t; a : t -> t }
type network = { layers : layer array }
let run_layer x l = Maths.((x $@ l.w) + l.b) |> l.a
let run_network x nn = Array.fold_left run_layer x nn.layers
let l0 = {