Skip to content

Instantly share code, notes, and snippets.

View haampie's full-sized avatar

Harmen Stoppels haampie

View GitHub Profile
@haampie
haampie / jacobi.jl
Created August 9, 2017 10:19
Comparison row / column
import Base: start, next, done
using BenchmarkTools
mutable struct RowJacobi{matT,vecT}
A::matT
x::vecT
next::vecT
b::vecT
maxiter::Int
@haampie
haampie / hessenberg.jl
Last active February 28, 2018 22:49
hessenberg optimization
using BenchmarkTools
import Base.BLAS: BlasInt, @blasfunc, liblapack
# subroutine dhseqr (
# character JOB,
# character COMPZ,
# integer N,
# integer ILO,
# integer IHI,
@haampie
haampie / conversions.jl
Last active March 22, 2018 14:08
Conversions
using BenchmarkTools
import Base: getindex
@inline function getindex(v::UnitRange{Int32}, i::Integer)
first(v) + Core.Intrinsics.trunc_int(Int32, i) - one(Int32)
end
function copy_via_broadcast!(x::AbstractVector{Ti}, r::UnitRange{Ti}) where {Ti}
x .= r
@haampie
haampie / the_bench.jl
Last active March 25, 2018 20:18
the_bench.jl
import Base: start, next, done
using Base: BitInteger
using BenchmarkTools
struct OpenRange{T}
start::T
stop::T
end
@haampie
haampie / results.txt
Last active March 27, 2018 12:28
Range performance
With bounds check Using @inbounds
Range type Index type Current New x faster Current New x faster
StepRange{Bool,Bool} Int8 93.605 μs 46.465 μs 2.0 83.849 μs 29.769 μs 2.8
StepRange{Bool,Bool} UInt8 92.478 μs 42.743 μs 2.2 81.760 μs 29.775 μs 2.7
StepRange{Bool,Bool} Int32 91.492 μs 45.854 μs 2.0 83.108 μs 29.780 μs 2.8
StepRange{Bool,Bool} UInt32 89.812 μs 41.530 μs 2.2 82.168 μs 26.783 μs 3.1
StepRange{Bool,Bool} Int64 92.273 μs 45.849 μs 2.0 78.521 μs 29.781 μs 2.6
StepRange{Bool,Bool} UInt64 86.641 μs 44.617 μs 1.9 74.546 μs 29.793 μs 2.5
StepRange{Int8,Int8} Int8 24.084 μs 21.805 μs 1.1 11.753 μs 1.444 μs 8.1
StepRange{Int8,Int8} UInt8 24.099 μs 28.102 μs 0.9 11.755 μs 1.444 μs 8.1
@haampie
haampie / results.jl
Last active April 1, 2018 10:44
sparse_mat_vec.jl
> a, b = bench(100_000, Float64, Int64)
(Trial(704.422 μs), Trial(1.505 ms)) # Julia 0.6
(Trial(1.354 ms), Trial(735.759 μs)) # Julia 0.7
@haampie
haampie / _zip.jl
Last active June 6, 2018 07:00
zip
module ZipStuff
import Base: iterate
using Test, Base.Iterators
abstract type AbstractZip end
struct ZipBase{H} <: AbstractZip
head::H
end
@haampie
haampie / generate_zip.jl
Created June 6, 2018 15:24
otherzip.jl
module Zipperino
import Base: iterate, tail, @nexprs, @ntuple
using Test, Base.Iterators
struct LinearZip{N,T}
t::T
end
zip(a...) = LinearZip{length(a),typeof(a)}(a)
@haampie
haampie / things.jl
Created June 14, 2018 08:38
things.jl
using Base.LinAlg: givensAlgorithm
import Base: convert
struct Householder{T}
u::T
end
"""
Returns a reflector s.t. Q * x = norm(x) * e1.
"""
@haampie
haampie / stuff.jl
Created July 13, 2018 21:45
relation
using LinearAlgebra
using Test
function generate_real_H_with_imaginary_eigs(n, T::Type = Float64)
while true
H = triu(rand(T, n + 1, n), -1)
λs = sort!(eigvals(view(H, 1 : n, 1 : n)), by = abs)
for i = 1 : n
μ = λs[i]