Skip to content

Instantly share code, notes, and snippets.

View c42f's full-sized avatar

Claire Foster c42f

  • I'm independent :)
  • Brisbane
  • X @c42f_
View GitHub Profile
@c42f
c42f / chol_dual.jl
Last active August 29, 2015 14:02
Cholesky decomposition for autodiff
using DualNumbers
# Solve the matrix system
#
# B = U'*M + M'*U
#
# for M where B is symmetric and U is upper triangular. This looks a bit like
# the *-Sylvester equation, but has significantly more symmetry.
function tri_ss_solve!{T<:Base.LinAlg.BlasFloat}(M::AbstractArray{T,2}, U::AbstractArray{T,2}, B::AbstractArray{T,2})
# This turns out to be a forward substitution algorithm in terms of the
@c42f
c42f / GeneratedTypes.jl
Last active June 8, 2016 21:53
Experimenting with generated types
module GeneratedTypes
# First an example of a simple "generic" type
immutable GenericImmutable{FieldNames, FieldTypes<:Tuple}
fieldvalues::FieldTypes
end
@generated function getfield{FieldNames, FieldTypes, Name}(gi::GenericImmutable{FieldNames,FieldTypes},::Type{Val{Name}})
fieldnumber = findfirst(FieldNames, Name)
fieldnumber > 0 || error("Field $name not found")
@c42f
c42f / SimpleSymbolic.jl
Last active July 26, 2016 03:05 — forked from andyferris/SimpleSymbolic.jl
Simply symbolic manipulations and some matrix math for Euler angle rotations
module SimpleSymbolic
immutable S{Ex}
x::Ex
end
macro S(ex)
Expr(:call, :S, Expr(:quote, ex))
end
@c42f
c42f / scanf.c
Created August 8, 2016 02:58
prototyping for sscanf in julia
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE* f = fopen("AUSGeoid09_GDA94_V1.01_DOV.txt", "r");
if (!f || fscanf(f, "%*[^\n]\n") != 0)
return 1;
int hlen = 10;
int hindex = 0;
solve_divisor{T}(::Type{T},a,b,N) = solve_divisor(convert(T, a), convert(T, b), convert(T, N))
function solve_divisor{T}(a::T, b::T, N::T)
#x = nextfloat(typemin(T))
x = T(1)
while x < 2 #prevfloat(typemax(T))
if ((a*x)*N)/(x*N) == a && ((b*x)*N)/(x*N) == b
return x
end
x = nextfloat(x)
@c42f
c42f / inverses.jl
Created June 9, 2017 13:45
static matrix inverses
using StaticArrays
import StaticArrays.SUnitRange
@noinline function inv2(a::StaticMatrix{4,4})
# See http://www.freevec.org/function/inverse_matrix_4x4_using_partitioning
# Partition
i1 = SUnitRange(1,2)
i2 = SUnitRange(3,4)
@inbounds P = a[i1,i1]
@c42f
c42f / unroll.jl
Created November 9, 2017 10:30
unroll macro
module Unroll
struct Vec{N,T} <: AbstractVector{T}
data::NTuple{N,T}
end
Base.size(v::Vec) = (length(v.data),)
Base.getindex(v::Vec, i::Int) = v.data[i]
function _unroll_for(ex)
@c42f
c42f / TurboColormap.ipynb
Created August 21, 2019 13:44
Recomputing the polynomial approximation for the Turbo colormap
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@c42f
c42f / StructuredConcurrency
Last active September 17, 2019 03:59
Cancellation vs Structured Concurrency
Chris Foster 4 days ago
Current notes are in my fork of the Juleps repo at
https://github.com/c42f/Juleps/blob/cjf/structured-concurrency/StructuredConcurrency.md
but most people seem to ignore the main Juleps repo so I haven't sent a PR yet (also it's very WIP).
We could move the notes to Jameson's julep wiki or somewhere else more conducive to collaboration? (edited)
Kiran Pamnany 3 days ago
This is nicely written -- good literature survey.
Kiran Pamnany 3 days ago
I'd be very interested in your (or anyone's) thoughts on Erlang's approach.
@c42f
c42f / exc_lowering.jl
Last active September 23, 2019 07:37
Sketch of lowering for improved exception handling
using Base.Meta
struct ErrorResult{E}
e::E
end
function insert_wraparg!(ex, name)
@assert isexpr(ex, :call) # todo
insert!(ex.args, 2, name)
ex