Skip to content

Instantly share code, notes, and snippets.

Avatar

Harmen Stoppels haampie

View GitHub Profile
View unet.jl
function concat_and_crop(mx::AbstractArray{T,4}, x::AbstractArray{T,4}) where T
w, h = size(x)
mw, mh = size(mx)
rx = (1:mw) .+ ((w - mw) ÷ 2)
ry = (1:mh) .+ ((h - mh) ÷ 2)
return cat(x[rx, ry, :, :], mx, dims = 3)
end
create_model_2d_classes() = Chain(
BatchNorm(1),
@haampie
haampie / Dockerfile
Created Jan 24, 2020
Build some Qt modules with AddressSanitizer
View Dockerfile
FROM ubuntu:18.04 AS builder
SHELL ["/bin/bash", "-c"]
WORKDIR /development
RUN apt-get update && apt-get install --no-install-recommends -y \
build-essential \
curl \
file \
@haampie
haampie / hack-spack-wrapper.diff
Last active Apr 16, 2021
Spack force release mode
View hack-spack-wrapper.diff
diff --git a/lib/spack/env/cc b/lib/spack/env/cc
index 4d8c4644cb..3c4dcb35a7 100755
--- a/lib/spack/env/cc
+++ b/lib/spack/env/cc
@@ -384,6 +384,13 @@ while [ $# -ne 0 ]; do
other_args+=("$1")
fi
;;
+ -O0,-O1,-O2,-O3,-Os,-Ofast,-O)
+ # Always use -O3
@haampie
haampie / harmen_5x8.s
Last active Feb 1, 2021
Tiny Transpose {5,6,7,8} x 8
View harmen_5x8.s
vmovups ymm0, ymmword ptr [rsi]
vmovups ymm1, ymmword ptr [rsi + 32]
vmovups ymm2, ymmword ptr [rsi + 64]
vmovups ymm6, ymmword ptr [rsi + 96]
vmovups ymm7, ymmword ptr [rsi + 128]
movabs rcx, offset .rodata.cst32
mov rax, rdi
vmovaps ymm10, ymmword ptr [rcx]
vperm2f128 ymm3, ymm0, ymm1, 33 # ymm3 = ymm0[2,3],ymm1[0,1]
vperm2f128 ymm5, ymm1, ymm2, 33 # ymm5 = ymm1[2,3],ymm2[0,1]
View collections.php
<?php
final class User
{
private $name;
public function __construct(string $name)
{
$this->name = $name;
}
View stuff.jl
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 / julia.jl
Created Jul 30, 2020
expression templates
View julia.jl
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
fast_transpose.jl
View 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
tri_to_diag_2.jl
View _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
tri_to_diag.jl
View 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