Skip to content

Instantly share code, notes, and snippets.

View haampie's full-sized avatar

Harmen Stoppels haampie

View GitHub Profile
@haampie
haampie / schur.jl
Last active July 15, 2018 19:05
Comparing stuff
# Comparison of bulge chasing of real matrix with modified GenericLinearAlgebra vs https://github.com/haampie/IRAM.jl/pull/48
# Run with Julia Version 0.7.0-beta2.6.
# Modifications to GenericLinearAlgebra only include commenting out lines that apply / store rotations.
using LinearAlgebra, GenericLinearAlgebra, IRAM, BenchmarkTools
function compare_hessenberg_to_uppertriangular(n)
# Random real Hessenberg matrix
H = triu(rand(n, n), -1)
@haampie
haampie / powm.jl
Created July 14, 2018 16:17
Power method
using LinearAlgebra
mutable struct State{Tv,V<:AbstractVector{Tv}, T}
x::V
r::V
Ax::V
θ::T
end
function power_method(A::AbstractMatrix{T}) where {T}
@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]
@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 / 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 / _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 / 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 / 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 / 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 / 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