Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View haampie's full-sized avatar

Harmen Stoppels haampie

View GitHub Profile
@haampie
haampie / julia.jl
Created July 30, 2020 13:43
expression templates
using LinearAlgebra, LoopVectorization
function error_norm(u::AbstractArray{T}, v::AbstractArray{T}) where T
result = T(0)
@avx for i = eachindex(u)
result += (u[i] - v[i])^2
end
return sqrt(result)
@haampie
haampie / fast_transpose.jl
Last active May 23, 2020 10:04
fast_transpose.jl
using SIMDPirates
canonicalize(A) = A
canonicalize(A::Union{<:SubArray}) = canonicalize(parent(A))
function version_1!(B::AbstractMatrix{Float64}, A::AbstractMatrix{Float64})
m, n = size(A)
Ac = canonicalize(A)
@haampie
haampie / _tri_to_diag_2.jl
Last active May 11, 2020 23:11
tri_to_diag_2.jl
using LinearAlgebra: givensAlgorithm, SymTridiagonal, I, Diagonal
using Base: @propagate_inbounds
import LinearAlgebra: lmul!, rmul!
import Base: Matrix
@propagate_inbounds is_offdiagonal_small(H::SymTridiagonal{T}, i::Int, tol = eps(real(T))) where {T} =
abs(H.ev[i]) ≤ tol*(abs(H.dv[i]) + abs(H.dv[i+1]))
abstract type SmallRotation end
@haampie
haampie / tri_to_diag.jl
Last active May 11, 2020 22:47
tri_to_diag.jl
using LinearAlgebra: givensAlgorithm, SymTridiagonal, I, Diagonal
using Base: @propagate_inbounds
import LinearAlgebra: lmul!, rmul!
import Base: Matrix
@propagate_inbounds is_offdiagonal_small(H::SymTridiagonal{T}, i::Int, tol = eps(real(T))) where {T} =
abs(H.ev[i]) ≤ tol*(abs(H.dv[i]) + abs(H.dv[i+1]))
abstract type SmallRotation end
@haampie
haampie / givens.jl
Created May 10, 2020 19:10
givens.jl
using SIMD
using BenchmarkTools
using Test
struct Rot{T}
c::T
s::T
end
mul(G::Rot, a, b) = (G.c * a + G.s * b, -G.s * a + G.c * b)
@haampie
haampie / sort_cache_by.jl
Created April 14, 2020 11:05
sort_cache_by.jl
import Base: getindex, setindex, length, isless
struct SortPair{A,B}
x::A
mapped::B
end
struct SortCache{A,B,AV,BV} <: AbstractVector{SortPair{A,B}}
xs::AV
mapped::BV
@haampie
haampie / PrimeMonstrosity.jl
Created December 18, 2019 17:32
prime-monstrosity.jl
module PrimeMonstrosity
const bit_1 = ~(0x01 << 7)
const bit_2 = ~(0x01 << 6)
const bit_3 = ~(0x01 << 5)
const bit_4 = ~(0x01 << 4)
const bit_5 = ~(0x01 << 3)
const bit_6 = ~(0x01 << 2)
const bit_7 = ~(0x01 << 1)
const bit_8 = ~(0x01 << 0)
@haampie
haampie / trace.txt
Last active August 29, 2019 08:42
btmon trace
Bluetooth monitor ver 5.50
= Note: Linux version 5.0.0-25-generic (x86_64) 0.401834
= Note: Bluetooth subsystem version 2.22 0.401835
= New Index: 80:C5:F2:F8:D6:54 (Primary,USB,hci0) [hci0] 0.401836
@ MGMT Open: btmon (privileged) version 1.14 {0x0001} 0.401851
= bluetoothd: Bluetooth daemon 5.50 3.341004
@ MGMT Open: bluetoothd (privileged) version 1.14 {0x0002} 3.342105
= bluetoothd: Starting SDP server 3.342212
= bluetoothd: Excluding (cli) wiimote 3.342323
@ MGMT Command: Read Management Version In.. (0x0001) plen 0 {0x0002} 3.343725
@haampie
haampie / testing.cpp
Last active March 15, 2019 21:42
everything_compile_time.cpp
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
using namespace std;
// Some instances of events; we're using "public" const data members.
struct UsernameChanged {
string const username;
@haampie
haampie / cerfacs.cu
Created December 3, 2018 16:30
cerfacs.cu
// Computes y <- alpha * A * x + beta * y for tall and skinny A.
// Compile with `nvcc -O3 -o cerfacs cerfacs.cu`
// Assumes we have a *large* basis of COLS = 100 columns, you can play with this param
// Timing is measured without copies from / to device (copies should not happen in a good impl of arnoldi anyways)
// Assumes a fixed number of 256 threads per block.
#include <stdio.h>
#include <sys/time.h>
#define COLS 100