Skip to content

Instantly share code, notes, and snippets.

#supson.jl
type ツ; end
_(::Type{ツ}) =
*(::Type{ツ}, ::Function) =
type ⎺; end
Base.:\(::Type{⎺},::Type{ツ}) =
Base.:/(::Type{ツ},::Type{⎺}) = true
\_(ツ)_/#==> true
@ityonemo
ityonemo / bloom.jl
Created November 3, 2016 23:00
bloom filter in 65 minutes in julia.
#bloom.jl - takes a file, reads binary data from the file and does whatever a
#bloom filter would do.
doc"""
`BloomFilter{V}`
defines a bloom filter over a value type V
"""
type BloomFilter{V}
filter::BitVector
hashes::Array{Function, 1}
@ityonemo
ityonemo / column_sort_inplace.jl
Created November 2, 2016 01:58
sorts a matrix by columns in place
function column_sort_inplace!(matrix::AbstractMatrix, fn::Function)
p = sort_columns_return_permutation(matrix, fn)
#first, find the permutation of the matrix, reduced by rows.
#create an array that signals the completion status of the process.
completion = falses(length(p))
#store important indices
current_root = 1 #root of the current cycle we're operating on.
current_index = 1 #array index we're operating on.
#next, allocate a short array that looks like the vector.
@ityonemo
ityonemo / driving.jl
Created October 16, 2016 20:53
queries google maps to tabulate driving distances.
#drivingtaxes.jl
using JSON
#make sure we have what we're looking for.
(length(ARGS) == 0) && throw(ErrorException("needs a file name"))
###################################
#rows iterator
type rows; tgt::Matrix; end
Base.start(r::rows) = 1
@ityonemo
ityonemo / uppertriangular.jl
Created September 28, 2016 04:36
Iterates over upper triangular indices.
#upper triangular indices - iterates over upper triangular indices in a list of
#indices.
type uppertriangular; iterable; end
Base.start(x::uppertriangular) = (1, 1)
function Base.next(x::uppertriangular, state)
(idx1, idx2) = state
next1 = idx1
next2 = idx2 + 1
if next2 > length(x.iterable)
@ityonemo
ityonemo / lookup_table_lemma.md
Last active August 18, 2016 01:16
Proof that lattice lookups only need exact values.

Definitions:

ℝᵖ - projective reals. ℝᵖ/L - projective reals represented by a Type2 Unum Lattice L. The elements are intervals, which will be denoted as x̅. An element of may also be an exact value or an ulp value, which will be denoted as ẋ.

O:(ℝᵖ/L)ⁿ → ℝᵖ/L is an implementation of an operation o:(ℝᵖ)ⁿ → ℝᵖ. The implementation must have the property o(x) ∈ O(ẋ), where ẋ is the unique ulp

@ityonemo
ityonemo / 64to16.jl
Last active June 5, 2016 01:18
converting to unsigned 16 bit integers in julia
# converting from Int64 to UInt16 in Julia can result in a minefield of inexacterrors,
# which could be performance-debilitating (if you care about that).
code_native(Int16, (Int64,))
# ==>(edited)
# pushq %rbp
# movq %rsp, %rbp
# movswq %si, %rax
# cmpq %rsi, %rax
@ityonemo
ityonemo / printlndebug.jl
Created January 30, 2016 00:23
Println debugging in julia
@macro printlndebug
println("println")
end
#use:
function donothing()
@printlndebug
nothing
end
@ityonemo
ityonemo / funwithsign.jl
Created December 15, 2015 09:24
sign is faster without branches.
code_native(sign,(Float64,))
## note two jbe opcodes. There are two jumps!
arry = rand(10000000) - 0.5
@time map(sign, arry)
# 0.38s
function sgn2(x::Float64)
xp::UInt64 = reinterpret(UInt64, x)
yp::UInt64 = ((xp & 0x7FFF_FFFF_0000_0000) >> 32) | (xp & 0x0000_0000_FFFF_FFFF)
yp = (yp & 0xFFFF_0000 >> 16) | (yp & 0x0000_FFFF)
yp = (yp & 0xFF00 >> 8) | (yp & 0x00FF)
using Base.Test
module X
macro id(v)
quote
$v
end
end
export @id
end