Skip to content

Instantly share code, notes, and snippets.

@acardona
acardona / test-numba.py
Created June 2, 2015 13:49
numba speeds up python code 30x to 50x in Ubuntu 14.04!
# Albert Cardona 2015-06-02
# Test the speed up provided by just-in-time compilation of python code
# using the numba JIT framework.
# The operation to test is a trivial one: the difference of the logarithm,
# pairwise, in two arrays of randomly generated floating-point numbers.
# For a far more realistic test involving a python implementation of
# the non-uniform fast fourier transform, see:
# https://jakevdp.github.io/blog/2015/02/24/optimizing-python-with-numpy-and-numba/
#
# To resolve issues with numba compilation (mostly type mismatches), see:
# Albert Cardona 2012-09-06
# Animate an Orthoslice view of an image volume in the 3D Viewer
# and record it into an ImageStack.
# Assumes that the Orthoslice view is already present in the 3D Viewer
# and then the scripts limits itself to iterating through the slices in a specific axis
# and to rotate when desired.
from ij3d import Image3DUniverse
from math import radians
@acardona
acardona / parse-bibtex-with-monads.clj
Created September 8, 2012 09:13
A parser for a subset of BibTeX files, written with clojure monads
; Albert Cardona, 2012-09-08
; http://albert.rierol.net/clojure-monads.html
(ns my.parse.bib5
(:use [clojure.algo.monads :only [domonad with-monad state-t maybe-m fetch-state set-state m-seq m-plus m-result]])
(:use [clojure.string :only [lower-case]])
(:use [clojure.pprint :only [pprint]]))
(set! *warn-on-reflection* true)
@acardona
acardona / gist:1454607
Created December 10, 2011 04:51
A virtual image of ImgLib2 with a filled ROI
// Goal: a virtual image (a function, if you want)
// with dimensions 512, 512
// and a background of value 0
// and a ROI of dimensions 200, 200 at position 100, 100
// filled with a value 127.
// ERROR: the ROI has the right dimensions
// but its top-left is positioned with negative coordinates.
// A virtual image with a ROI filled with value 127
(ns my.numeric.test
(:import [fiji.scripting Weaver]))
(def a (ref nil))
; Compile once
(def w (Weaver/inline
"int n = ((Number)ref.deref()).intValue();
double sum = 0;
for (int i=0; i<n; ++i) {
(ns my.numeric.test)
(def a (ref nil))
(defn ^double sum
[^double a
^double b]
(+ a b))
(defn w1
@acardona
acardona / test-eval.clj
Created November 29, 2011 17:18
A minimal test to show a non-working (eval (read-string ...))
(ns my.test
(:import [javax.swing JFrame JPanel JButton JLabel]
[java.awt Dimension]
[java.awt.event ActionListener]))
(defn parse
[^String s]
(println (eval (read-string s))))
(let [^JLabel input (JLabel. "[255 255 255]")]
; find-all-to-all returns a lazy list of lists of object instances
; and we want a map of instance vs. number of appearances
; This one blows up RAM:
(apply merge-with +
(map #(zipmap % (repeat 1))
(find-all-to-all-paths nodes degrees)))