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
module LevyAlphaRand | |
#a module that provides a levy alpha-stable random number in julia | |
#uses "McCulloch's algorithm", as provided in: | |
# Leccardi, M., Comparison of Three Algorithms for Levy Noise Generation | |
# | |
# Note two errors in the McCulloch formula as provided in this paper | |
# One: The phi and w values are swapped | |
# Two: The sin term should have an exponent of one, a fractional exponent would result in complex values |
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
#include <stdio.h> | |
#include <string.h> | |
typedef struct { | |
signed int exp:4; | |
signed int val:4; | |
} minifloat; | |
float to_float(minifloat m){ | |
/* generate a product accumulator */ |
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
#!/usr/bin/julia | |
#julia matrix test program. | |
v = rand(5) | |
m = rand(5,5) | |
r = zeros(5) | |
println("right product") | |
tic() |
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
var $$; | |
if(!Array.prototype.forEach){ | |
Array.prototype.forEach = function(fun){ | |
var len=this.length; | |
if(typeof fun!=="function"){ | |
throw new TypeError(); | |
} | |
var thisp = arguments[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
#test-things-from-the-book.jl | |
include("unum.jl") | |
using Unums | |
using Base.Test | |
#test various things from the book. | |
#are our representations of unums correct? | |
one16 = one(Uint16) |
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
//Hash.js -- a cute little wrapper that is really great for turning data-only objects into something that | |
//javascript explictly calls a "Hash". Useful for cosmetically improving data structure representations | |
//in your favorite console. also great for making Javascript look like some of the more friendly scripting | |
//languages like Ruby. Possibly useless for anything else, and may make your code easier to read at the | |
//expense of speed and/or memory. | |
Hash = function(object) | |
{ | |
if (object && (typeof object == 'object')) //do an initial type check to see if this can be hashified. | |
{ //if not, then you should return an empty hash {}. |
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
Function.prototype.__defineGetter__("head",function(){return this.toString().split("{")[0].trim();}); | |
Function.prototype.__defineGetter__("body",function(){return this.toString().split("{").slice(1).join("{").slice(0,-1).trim();}); | |
Function.prototype.__defineGetter__("args",function(){return this.toString().split("{")[0].match(/\([\w\s\,]*\)/)[0].slice(1,-1).split(",");}); | |
Function.prototype.__defineGetter__("stmts",function() | |
{ | |
var str = this.body; | |
var stmtlist = []; | |
var pcount = 0; | |
var lastpos = str.length - 1; | |
for (var i = str.length - 1; i >= 0; i--) |
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
abstract Unum{ESS, FSS} | |
#define an outer constructor on this type. | |
type Unum_Small{ESS, FSS} <: Unum{ESS, FSS} | |
fsize::UInt16 | |
esize::UInt16 | |
flags::UInt16 | |
fraction::UInt64 | |
exponent::UInt64 |
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
#cleaninject.jl | |
#cleanly injects some code into the AST of a function. | |
function code_to_inject() | |
println("this code is injected") | |
end | |
function code_to_inject(a,b) | |
println("injected code handles $a and $b") |
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
using Base.Test | |
module X | |
macro id(v) | |
quote | |
$v | |
end | |
end | |
export @id | |
end |
OlderNewer