Skip to content

Instantly share code, notes, and snippets.

View jakebolewski's full-sized avatar
🌨️
⛷️

Jake Bolewski jakebolewski

🌨️
⛷️
View GitHub Profile
@GaelVaroquaux
GaelVaroquaux / 00README.rst
Last active September 15, 2023 03:58
Copy-less bindings of C-generated arrays with Cython

Cython example of exposing C-computed arrays in Python without data copies

The goal of this example is to show how an existing C codebase for numerical computing (here c_code.c) can be wrapped in Cython to be exposed in Python.

The meat of the example is that the data is allocated in C, but exposed in Python without a copy using the PyArray_SimpleNewFromData numpy

(defn ensure-initialized [p]
(or (deref p 0 nil) (throw (IllegalStateException. "Method called on half-initialized object."))))
(defmacro reify-let
[name bindings & impls]
(let [p (gensym "p")
delegate (fn [x]
(if (seq? x)
(let [[method args] x]
`(~method ~args (~method (ensure-initialized ~p) ~@(next args))))
@simgt
simgt / host_device_transfer_bug.cpp
Last active December 18, 2015 16:39
Host-buffers to device transfer and mapping failure with an AMD GCN device
#include <CL/cl.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#define STRINGIFY(s) #s
@staticfloat
staticfloat / debugging.md
Last active February 24, 2017 03:11
Julia Debugging Procedures

Julia Debugging Procedures

So you managed to break Julia. Congratulations! Collected here are some general procedures you can undergo for common symptoms encountered when something goes awry. Including the information from these debugging steps can greatly help the maintainers when tracking down a segfault or trying to figure out why your script is running slower than expected.

If you've been directed to this page, find the symptom that best matches what you're experiencing and follow the instructions to generate the debugging information requested. Table of symptoms:

@houshuang
houshuang / gist:6748566
Created September 29, 2013 01:45
Automatically open function in Sublime Text (first Julia macro)
macro whichs(ex)
ex = expand(ex)
exret = Expr(:call, :error, "expression is not a function call")
if !isa(ex, Expr)
# do nothing -> error
elseif ex.head == :call
exret = Expr(:call, :whichs, map(esc, ex.args)...)
elseif ex.head == :body
a1 = ex.args[1]
if isa(a1, Expr) && a1.head == :call
@sbos
sbos / HMM.jl
Created November 1, 2013 11:25
Hidden Markov Model in Julia
module HMM
using Distributions
import Distributions.rand
import Distributions.fit
immutable HiddenMarkovModel{TP, K}
theta::Vector{TP}
A::Matrix{Float64}
@albop
albop / gist:7525675
Created November 18, 2013 10:26
zero_based_indexing
rewrite(x::Number) = x
rewrite(x::Symbol) = x
rewrite(x::String) = x
function rewrite(expr)
if expr.head == :ref
return Expr(expr.head, expr.args[1], [rewrite(:( 1 + $i)) for i in expr.args[2:end]]...)
else
return Expr(expr.head, [rewrite(i) for i in expr.args]...)
end
@anthgur
anthgur / git2types.jl
Last active December 28, 2015 22:29
A quick test I created to interact with libgit2.
type GitAtomic
val::Clong
function GitAtomic()
new(zero(Clong))
end
end
type GitRefcount
refcount_val::Clong
owner::Ptr{Void}
@MikeInnes
MikeInnes / startup.jl
Last active February 5, 2023 12:54
Some useful macros for Julia
# Repeat an operation n times, e.g.
# @dotimes 100 println("hi")
macro dotimes(n, body)
quote
for i = 1:$(esc(n))
$(esc(body))
end
end
end
require 'rugged'
repo = Rugged::Repository.init_at('./test-repo')
index = repo.index
base_commit_options = {
author: { name: "Matt", email: "matt@test.com" },
committer: { name: "Matt", email: "matt@test.com" },
update_ref: 'HEAD'