Skip to content

Instantly share code, notes, and snippets.

Avatar

Harmen Stoppels haampie

View GitHub Profile
View test
0.5258035496409385338996633621320518075577262895034576824436935036190909359484821735511244086357105703763089095001084909503562784106432631780885381833487161441115426324089735535648577478022198173062961599662707079574920200839277886235481421364962201726366096411855900154689889962293083318039904967542464945043705977339467548513433912472348985230682047335936507184327257718362160494751446144883847282407215005669970705901314196397855777633081493954608446354...
@haampie
haampie / pell.txt
Last active Nov 14, 2016
Pell's equation
View pell.txt
3^2 - 2 * 2^2 = 1
9^2 - 5 * 4^2 = 1
View 94.cc
#include <iostream>
#include <tuple>
using pell = std::pair<size_t, size_t>;
inline pell next(pell const &solution)
{
return {
2 * solution.first + 3 * solution.second,
2 * solution.second + solution.first
View inject.js
var autocompletes = ['name', 'honorific-prefix', 'given-name',
'additional-name', 'family-name', 'honorific-suffix',
'nickname', 'username', 'new-password',
'current-password', 'organization-title', 'organization',
'street-address', 'address-line1', 'address-line2',
'address-line3', 'address-level4', 'address-level3',
'address-level2', 'address-level1', 'country',
'country-name', 'postal-code', 'cc-name', 'cc-given-name',
'cc-additional-name', 'cc-family-name', 'cc-exp',
'cc-exp-month', 'cc-exp-year', 'cc-csc', 'cc-type',
@haampie
haampie / better_collections.php
Last active Apr 16, 2017
better_collections.php
View better_collections.php
<?php
function take(Iterator $it, int $n) {
for ($i = 0; $i < $n && $it->valid(); $i++, $it->next()) {
yield $it->current();
}
}
function filter(Iterator $it, callable $f) {
foreach ($it as $item) {
@haampie
haampie / gmres.jl
Last active Jun 10, 2017
More efficient GMRES
View gmres.jl
using BenchmarkTools
using IterativeSolvers
module GMRES
using Base.LinAlg.axpy!
function gmres(A, b; outer::Int = 5, restart::Int = 20, tol = sqrt(eps(real(eltype(b)))))
T = eltype(b)
@haampie
haampie / reortho.jl
Created Jun 15, 2017
reorthogonalization.jl
View reortho.jl
import Base.LinAlg.BlasFloat
import Base.LinAlg.BLAS: gemv!, gemv, axpy!
using BenchmarkTools
function classical_gram_schmidt!{T<:BlasFloat}(V::StridedMatrix{T}, w::StridedVector{T})
# orthogonalize
h = gemv('T', one(T), V, w)
gemv!('N', -one(T), V, h, one(T), w)
View 3d.jl
function literature_example()
# Problem: Δu + 1000uₓ = f
# u = 0 on the boundaries
# f(x, y, z) = exp(xyz) sin(πx) sin(πy) sin(πz)
# 2nd order central differences (shows serious wiggles)
# Unknowns per dimension
N = 50
# Total number of unknowns
View unsafe.jl
struct UnsafeView{T, N} <: DenseArray{T, N}
dim::NTuple{N, Int}
ptr::Ptr{T}
end
const UnsafeVectorView{T} = UnsafeView{T,1}
const UnsafeMatrixView{T} = UnsafeView{T,2}
@inline Base.size(v::UnsafeView) = v.dim
@inline Base.size(v::UnsafeVectorView, idx::Int) = idx == 1 ? v.dim[idx] : 1
@haampie
haampie / jacobi.jl
Created Aug 9, 2017
Comparison row / column
View jacobi.jl
import Base: start, next, done
using BenchmarkTools
mutable struct RowJacobi{matT,vecT}
A::matT
x::vecT
next::vecT
b::vecT
maxiter::Int