Skip to content

Instantly share code, notes, and snippets.

View c42f's full-sized avatar

Claire Foster c42f

View GitHub Profile
@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]
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 / 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;
@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 / 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 / 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