Skip to content

Instantly share code, notes, and snippets.

View denius's full-sized avatar

Denis Telnov denius

  • Saint Petersburg, Russia
View GitHub Profile
@denius
denius / test-generated.jl
Created November 2, 2017 17:54
test evaluating default values parameters in `@generated` functions
const U = Union{Type{Val{true}}, Type{Val{false}}}
f1(p::U = Val{false}) = p isa Type{Val{true}}
f2(p::U = Val{false}) = p isa Val{true} # false
f3(p::U = Val{false}) = p <: Type{Val{true}} # false
f4(p::U = Val{false}) = p <: Val{true}
f5(p::U = Val{false}) = p === Type{Val{true}} # false
f6(p::U = Val{false}) = p === Val{true}
f7(p::U = Val{false}) = p == Type{Val{true}} # false
@denius
denius / perf-qr.jl.txt
Last active October 30, 2017 12:30
QR benchmark results
K=1
0.403818 seconds (113.14 k allocations: 5.859 MiB)
7.123 ns (0 allocations: 0 bytes)
775.527 ns (21 allocations: 1.13 KiB)
K=2
0.021828 seconds (19.79 k allocations: 1019.997 KiB)
12.328 ns (0 allocations: 0 bytes)
1.474 μs (21 allocations: 1.22 KiB)
K=3
0.036278 seconds (38.94 k allocations: 1.880 MiB)
@denius
denius / perf-qr.jl
Created October 30, 2017 11:58
QR benchmark
using StaticArrays
using BenchmarkTools, Compat
a = m = 0
for K = 1:18
a = rand(SMatrix{K,K,Float64,K*K})
m = Matrix(a)
print("K=$K\n")
@time qr(a)
@btime qr($a)
@denius
denius / qr-givens.jl
Created October 29, 2017 14:56
QR decomposition by Givens rotations
"""
QR decomposition by givens rotations of matrix without pivoting.
```math
A = Q R
```
Thin (reduced) method will produce `Q` and `R` in truncated form,
in opposite case `thin=false` Q is full, but R is still reduced, see [`qr`](@ref).
"""
@denius
denius / reflectorApplyRight!.jl
Created October 29, 2017 14:41
Application of Householder reflector from right
# apply reflector from right
# derived from base/linalg/generic.jl
@inline function reflectorApplyRight!(x::AbstractVector, τ::Number, A::AbstractMatrix)
m, n = size(A)
if length(x) != n
throw(DimensionMismatch("reflector has length $(length(x)), which must match the first dimension of matrix A, $n"))
end
@inbounds begin
for i = 1:m
# note: ommited x[1] == 1