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
{:paths ["."] :deps {robert/hooke {:mvn/version "1.3.0"} | |
com.taoensso/tufte {:mvn/version "2.4.5"}}} |
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
(defn copy2clip [x] | |
(let [w (StringWriter.)] | |
(pprint x w) | |
(.. Toolkit getDefaultToolkit getSystemClipboard | |
(setContents (StringSelection. (.toString w)) nil)))) |
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
(require '[clojure.core.matrix :as m]) | |
(defn mup [mat rs cs f] | |
(m/set-selection mat rs cs | |
(f (m/select mat rs cs)))) | |
(defn qr | |
" | |
QR decomposition by Householder reflection | |
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
(require '[criterium.core :as c]) | |
(defprotocol W (w [this x y])) | |
(def w1 (reify W (w [t x y] (* x y)))) | |
(c/quick-bench (w w1 4 4)) | |
; protocol dispatch | |
; Execution time mean : 6.625560 ns |
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 [eval-right? clojure.core/eval] (intern 'clojure.core 'eval (fn [form] (if (= 'right? (last form)) (eval-right? (butlast form)) 'right?)))) |
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
; https://www.scientificamerican.com/article/is-inequality-inevitable/ | |
; https://threadreaderapp.com/thread/1210332075787608065.html | |
(defn economy-dw | |
" | |
Simulate one round of | |
random transfers of wealth | |
between the given agents' accounts | |
(a vector of initial amounts) |
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
; I was curious as to whether unrolling | |
; this use of transducers would be faster | |
; | |
; in fact it's slower | |
; we're given an array which we | |
; process using fns f, g and h | |
(defn test1-xf [^bytes data] | |
(comp |
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 [{z :x x 'y y "z" :keys [x y z] :syms [x y z] :strs [x y z]} {:x 1 'y 2 "z" 3}] [x y z]) | |
=> [nil nil 3] | |
(let [{z :x x 'y y "z" :keys [x y z] :syms [x y z]} {:x 1 'y 2 "z" 3}] [x y z]) | |
=> [nil 2 nil] | |
(let [{z :x x 'y y "z" :keys [x y z]} {:x 1 'y 2 "z" 3}] [x y z]) | |
=> [1 nil nil] | |
(let [{z :x x 'y y "z"} {:x 1 'y 2 "z" 3}] [x y z]) |
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
(defn add [x y] (+ x y))=> #'user/add(defn addm [{x :x y :y}] (+ x y))=> #'user/addm(reduce (fn [r i] (addm {:x r :y i})) 0 (range 128))=> 8128(quick-bench (reduce (fn [r i] (add r i)) 0 (range 128)))Evaluation count : 270720 in 6 samples of 45120 calls. Execution time mean : 2.212768 µs Execution time std-deviation : 76.515990 ns Execution time lower quantile : 2.130557 µs ( 2.5%) Execution time upper quantile : 2.336060 µs (97.5%) Overhead used : 1.902301 nsFound 1 outliers in 6 samples (16.6667 %) low-severe 1 (16.6667 %) Variance from outliers : 13.8889 % Variance is moderately inflated by outliers=> nil(quick-bench (reduce (fn [r i] (add r i)) 0 (range 128)))Evaluation count : 265158 in 6 samples of 44193 calls. Execution time mean : 2.323233 µs Execution time std-deviation : 176.530052 ns Execution time lower quantile : 2.223932 µs ( 2.5%) Execution time upper quantile : 2.626066 µs (97.5%) Overhead used : 1.902301 nsFound 1 outl |
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
(ns mms | |
(:require | |
[clojure.math.combinatorics :as x] | |
[clojure.set :as set])) | |
(defn derive-set | |
" | |
A copy of derive for sets | |
" | |
([h a-set parent-set] |
NewerOlder