This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gives roughly a 2x speedup using JULIA_NUM_THREADS=2 | |
# requires 0.7, due to closure type inference bug in 0.6 | |
using Random, SparseArrays | |
srand(1); X = sprand(20_000,100_000,0.1); v = ones(100_000); | |
function mul(X,v) | |
m,n = size(X) | |
U = zeros(size(X,1), Threads.nthreads()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To ensure correct alignment (e.g. for an 80-bit type) | |
struct StrWrap{T} | |
value::T | |
end | |
function unsafe_reinterpret(T, a::A) where {A} | |
if sizeof(T) <= sizeof(A) | |
r = Ref(a) | |
Base.@gc_preserve r begin | |
u = convert(Ptr{T}, Base.unsafe_convert(Ptr{A}, r)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
normalizecols!(X, p) | |
Normalize the non-empty columns of `X` using a `p`-norm. | |
Overwrites the contents of `X`. | |
""" | |
function normalizecols!(X::SparseMatrixCSC, p=2) | |
for col = 1:X.n | |
rr = X.colptr[col]:X.colptr[col+1]-1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Intrinsics | |
tname(::Type{Float64}) = "double" | |
tname(::Type{Float32}) = "float" | |
fname(::Type{Float64}) = "f64" | |
fname(::Type{Float32}) = "f32" | |
for f in [:add, :sub, :mul, :div, :rem] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = 2_500_000 | |
p = 1.9e-5 | |
X = sprand(n,n,p) | |
v = sprand(n,8/n) | |
function fast_A_mul_B(X::SparseMatrixCSC{TX,IX},v::SparseVector{TV,IV}) where {TX,IX,TV,IV} | |
X.n == v.n || throw(DimensionMismatch()) | |
ind_out = promote_type(IX,IV)[] | |
val_out = promote_type(TX,TV)[] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git init --bare gitprob | |
git clone gitprob gitprobwork | |
cd gitprobwork | |
echo "good" > aaaa | |
GOOD=$(git hash-object -w aaaa) | |
git add aaaa | |
git commit -m "1" | |
rm aaaa |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Distributions | |
import ForwardDiff: Dual, value, partials | |
@generated function get_values(a::NTuple{N}) where {N} | |
return ForwardDiff.tupexpr(i -> :(value(a[$i])),N) | |
end | |
ForwardDiff.value(p::ForwardDiff.Partials) = | |
ForwardDiff.Partials(get_values(p.values)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <gmp.h> | |
#include <mpfr.h> | |
int main (void) | |
{ | |
unsigned int i; | |
mpfr_t u; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using SenseHat | |
function newblob(snake) | |
while true | |
x = rand(1:8) | |
y = rand(1:8) | |
if (x,y) ∉ snake | |
return (x,y) | |
end | |
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.