Skip to content

Instantly share code, notes, and snippets.

/// be explicite: path might be None (pseudo overloading)
type ExcelWorkbook(path: string option, fname: string) =
/// should be a singleton shared by workbooks?
let excel = getExcel()
let fqn =
match path with
| Some path -> path+"\\"+fname
| _ -> System.Environment.CurrentDirectory+fname
let workbooks =
match excel with
Namespace matrixtests-test
inititalizing the tests:
------------------------
(clojure.core/dotimes [i matrixtests-test/nx] (clojure.core/dotimes [j matrixtests-test/ny] (cg-aset! dd i j 42.0)))
"Elapsed time: 3.39473 msecs"
functional tests
----------------
Checking optimal hints on aget, CGrande
Checking optimal hints/macros on aget, CGrande
... omitting further get/set tests
(ns cfd-clojure
(:use (incanter core charts)))
;; provide discretisation linear in t and up to second order in x
(defn discretize [f m u]
(let [l (last u)
g (fn [u] (conj (map #(f m %) (partition (:x-steps m) 1 u)) (first u)))
h (fn [u] (g (concat u [l])))]
(if (= 2 (:x-steps m))
# Remember: comments in python are denoted by the pound sign
import numpy as np #here we load numpy, calling it 'np' from now on
import matplotlib.pyplot as plt #here we load matplotlib, calling it 'plt'
import time, sys #and load some utilities
from IPython.core.display import clear_output #used for inline animation
nx = 41 # try changing this number from 41 to 81 and Run All ... what happens?
dx = 2./(nx-1)
nt = 25 #nt is the number of timesteps we want to calculate
dt = .025 #dt is the amount of time each timestep covers (delta t)
@fbmnds
fbmnds / cum-fn.clj
Last active December 20, 2015 10:09
;; as pointed out by Alexander Stoddard:
;; re-invention of clojure.core/reductions
;;
(defn cum-fn
([s cfn]
(cond (empty? s) nil
(empty? (rest s)) (list (first s))
:else (lazy-seq (cons (first s) (cum-fn (first s) (rest s) cfn)))))
([x s cfn]
(cond (empty? s) nil
(defn multiply-file [in-file out-file n]
(with-open [rdr (io/reader in-file)
wrtr (io/writer out-file)]
(doseq [line (line-seq rdr)]
(.write wrtr (multiply-string line n)))))
(class (repeat 1))
; clojure.lang.LazySeq
(ancestors clojure.lang.LazySeq)
; #{clojure.lang.IPersistentCollection clojure.lang.IPending java.util.Collection
; java.util.List clojure.lang.Obj clojure.lang.ISeq clojure.lang.IMeta java.io.Serializable
; clojure.lang.IHashEq clojure.lang.IObj clojure.lang.Seqable clojure.lang.Sequential
; java.lang.Iterable java.lang.Object}
(clojure.set/difference (ancestors clojure.lang.PersistentList) (ancestors clojure.lang.LazySeq))
(require '[clojure.data.csv :as csv]
'[clojure.java.io :as io])
(defn multiply-string [s n]
(clojure.string/join [(clojure.string/join \newline (repeat n s)) "\n"]))
(defn multiply-file [in-file out-file n]
(with-open [rdr (io/reader in-file)
(def test-file "/path/to/datafile-4gb.tsv")
;;
;; here is the work done - iota does very fast file consumption into memory
;;
user> (time (def test-vec (iota/vec test-file)))
"Elapsed time: 21187.659866 msecs"
#'user/test-vec
user> (/ 21187.659866 81299000)
2.6061402804462543E-4
;;
@fbmnds
fbmnds / explicite-iteration-clr.clj
Last active December 19, 2015 14:19
Explicite iteration on CLR
(require '[clojure.clr.io :as io])
(def in-file "/path/to/datafile-4gb.tsv")
(def out-file "/path/to/datafile-16gb.tsv")
(defn multiply-string [s n]
(cond
(> n 1) (str s \newline (multiply-string s (dec n)))
(= n 1) (str s \newline)
:else nil))