Skip to content

Instantly share code, notes, and snippets.

@maxbennedich
maxbennedich / sparse_show.jl
Last active January 16, 2019 14:28
Braille plot sparse show
const BRAILLE = split("⠀⠁⠂⠄⡀⠈⠐⠠⢀", "") .|> s -> Int(s[1])
function show_any_nonzero(S::SparseMatrixCSC; maxw = displaysize(stdout)[2], maxh = displaysize(stdout)[1]-3)
h,w = size(S)
h > 4maxh && (w = max(1, (w*4maxh+h÷2)÷h); h = 4maxh)
w > 2maxw && (h = max(1, (h*2maxw+w÷2)÷w); w = 2maxw)
P = fill(BRAILLE[1], (w+3)÷2, (h+3)÷4)
P[end, :].=10
@inbounds for c = 0:w-1, r = 0:h-1
_anynz(S, r*S.m÷h+1, c*S.n÷w+1, (r+1)*S.m÷h, (c+1)*S.n÷w) &&
@maxbennedich
maxbennedich / mat_vect_benchmark.jl
Last active August 2, 2018 15:54
Matrix-vector multiplication benchmarks (Julia 0.7 version)
# Matrix-vector multiplication benchmarks (Julia 0.7 version)
using LinearAlgebra
using Statistics
using Printf
f(a, b) = a * b # Matrix-vector multiplication
#f(a, b) = log(1 + a^b) # Slow operation
function mul_broadcast!(M, v)