Skip to content

Instantly share code, notes, and snippets.

View dataPulverizer's full-sized avatar

dataPulverizer dataPulverizer

View GitHub Profile
@mppf
mppf / dp-m2.chpl
Created May 17, 2020 11:34
variants on dp question
// shows program modified to avoid array views in inner loops
class AbstractKernel {
// assumes x[xfirst, ..] and y[yfirst, ..] have shape 1..p
proc kernel(x, xfirst: int, y: [?D] ?T, yfirst: int, p: int): T
{
return x[xfirst, 0]; // out of bounds (intentionally?)
}
}
@valmat
valmat / vlm.utils.destructing.d
Last active June 1, 2020 18:20
variable destructuring; array to variables list; destructuring assign. Traversable, Tuple
//
// May destructing variables for itarable types and tuples
//
module vlm.utils.destructing;
import std.range : empty, popFront, front;
import std.traits : isIterable;
import std.typecons : Tuple, tuple, isTuple;
import std.functional : forward;
@Godisemo
Godisemo / idx_io.jl
Last active April 29, 2020 13:18
Julia parser and writer for the IDX file format used by e.g. the MNIST dataset
const idx_types = [(UInt8, 0x08), (Int8, 0x09), (Int16, 0x0B), (Int32, 0x0C), (Float32, 0x0D), (Float64, 0x0E)]
const typefromcode = Dict(idx_types)
const codefromtype = Dict(map(reverse, idx_types))
function write_idx(stream::Union{IOStream,String}, data::Array{T,N}) where {T,N}
dims = convert(Array{Int32}, collect(size(data)))
write(stream, 0x00, 0x00, typefromcode[T], UInt8(N), hton.(dims), hton.(data))
end
read_idx(filename::String) = open(read_idx, filename)