This file contains hidden or 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
(ns plumbing.graph-async | |
(:require | |
[plumbing.fnk.pfnk :as pfnk] | |
[plumbing.fnk.schema :as schema] | |
[plumbing.core :as plumbing] | |
[plumbing.graph :as graph])) | |
;; async function has ^:async metadata, callback required key. | |
;; TODO: redo with just promises/futures once they have callback options | |
;; TODO: make nicer way to specify async fnks? |
This file contains hidden or 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
;; Copyright Jason Wolfe and Prismatic, 2013. | |
;; Licensed under the EPL, same license as Clojure | |
(use 'plumbing.core) | |
(require '[clojure.java.shell :as shell] | |
'[clojure.string :as str]) | |
(import '[java.util HashSet] '[java.io File]) | |
(defn double-quote [s] (str "\"" s "\"")) |
This file contains hidden or 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
(deftype FinalizeReporter [x] | |
Object | |
(finalize [this] (println "Finalizing" x)) | |
clojure.lang.IDeref | |
(deref [this] x)) | |
(defn leaker [n] | |
(with-open [_ (reify java.io.Closeable (close [this]))] | |
(let [s (map #(FinalizeReporter. %) (take 10 (iterate inc 0)))] | |
(when (> n -1) |
This file contains hidden or 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
{:Ra (fnk [day-of-year lat] (solar-rad-et day-of-year lat)) | |
:Rs (fnk [tmax tmin {kRs 0.16} Ra] (-> (- tmax tmin) Math/sqrt (* kRs Ra))) | |
:Rso (fnk [alt Ra] (-> (* 2e-5 alt) (+ 0.75) (* Ra))) | |
:Rns (fnk [{a 0.23} Rs] (-> (- 1 a) (* Rs))) | |
:tmaxK (fnk [tmax] (to-kelvin tmax)) | |
:tminK (fnk [tmin] (to-kelvin tmin)) | |
:ea (fnk [tmin] (sat-vapour-pressure tmin)) | |
:term1 (fnk [tmaxK tminK {s 4.903e-9}] | |
(-> (Math/pow tmaxK 4) (+ (Math/pow tminK 4)) (* s) (/ 2))) | |
:term2 (fnk [ea] (-> (Math/sqrt ea) (* -0.14) (+ 0.34))) |
This file contains hidden or 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
(defn restricted-call | |
"Call fnk f on the subset of keys its input schema explicitly asks for." | |
[f in-map] | |
(f (select-keys in-map (keys (pfnk/input-schema f))))) |
This file contains hidden or 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
(fn term32635 | |
[map2634] | |
(let | |
[Rs (get map2634 :Rs nil) | |
Rso (get map2634 :Rso nil)] | |
(-> (* 1.35 Rs) (/ Rso) (- 0.35)))) |
This file contains hidden or 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 [Ra (Ra-fnk day-of-year lat) | |
Rs (Rs-fnk tmax tmin kRs Ra) | |
...]) |
This file contains hidden or 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
(eval `(fn positional-graph# | |
~arg-keywords | |
(let ~(vec (interleave (vals value-syms) function-calls)) | |
(new ~(def-graph-record g) | |
~@(->> g pfnk/output-schema keys (map value-syms)))))) |
This file contains hidden or 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
;; 1ms for 10k doubles: 20 MFlops | |
(defn dot-product [^doubles ws ^doubles xs] | |
(reduce + (map * ws xs)) |
This file contains hidden or 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
;; 8.5 us for 10k doubles: 2.3 GFlops | |
;; (11 us with *unchecked-math* false) | |
(defn dot-product [^doubles ws ^doubles xs] | |
(areduce xs i ret 0.0 | |
(+ ret (* (aget xs i) | |
(aget ws i))))) |