This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = window.getSelection(); | |
oRange = s.getRangeAt(0); //get the text range | |
oRect = oRange.getBoundingClientRect(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shape = (10,1000,10000) | |
function f00() | |
t0 = time() | |
x = [] | |
t1 = time() | |
@printf "empty:\t\t%.8f\n" (t1 -t0) | |
end | |
function f01() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let backprop nn eta x y = | |
let t = tag () in | |
Array.iter (fun l -> | |
l.w <- make_reverse l.w t; | |
l.b <- make_reverse l.b t; | |
) nn.layers; | |
let loss = Maths.(cross_entropy y (run_network x nn) / (F (Mat.row_num x |> float_of_int))) in | |
reverse_prop (F 1.) loss; | |
Array.iter (fun l -> | |
l.w <- Maths.((primal l.w) - (eta * (adjval l.w))) |> primal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let test_model nn x y = | |
Mat.iter2_rows (fun u v -> | |
Dataset.print_mnist_image (unpack_mat u); | |
let p = run_network u nn |> unpack_mat in | |
Owl.Mat.print p; | |
Printf.printf "prediction: %i\n" (let _, _, j = Owl.Mat.max_i p in j) | |
) x y | |
let _ = | |
let x, _, y = Dataset.load_mnist_train_data () in |
OlderNewer