Skip to content

Instantly share code, notes, and snippets.

View cournape's full-sized avatar

David Cournapeau cournape

View GitHub Profile
import scipy.sparse
import scipy.io.mmio
import os
import gc
import time
import numpy
matrix = scipy.io.mmio.mmread(os.popen("cat sparse_matrix.head try3"))
mat2 = matrix.tocsc()
@cournape
cournape / gist:1077528
Created July 12, 2011 07:00
cython c++ example
# rectangle.pyx
cdef extern from "Rectangle.h" namespace "shapes":
cdef cppclass Rectangle:
Rectangle(int, int, int, int)
int x0, y0, x1, y1
int getLength()
int getHeight()
int getArea()
void move(int, int)
@cournape
cournape / bug.c
Created March 13, 2012 07:24
Accelerate framework bug with fork
/*
* This small snippet shows an issue when calling dgemm for square matrices above a certain size inside a forked child process.
*
* To reproduce the issue:
* - compile it ("gcc -framework Accelerate bug.c -o bug")
* - ./bug 64 (64x64 matrix) will show the output for d matrix for both parents and child:
computing for size 64
c[0][0] is 64.000000
parent d[0][0] is 64.000000
@cournape
cournape / baby_names_exercise.rst
Created November 16, 2012 13:29
baby name exercise

""" This exercise allows you to take a brief look at DB capabilities of python and the SQL Alchemy library

this directory contains the names.zip file, which contains lists of baby names given in the US, one list per year. Each list is a csv file of the following format:

name, sex, number of names
@cournape
cournape / test.py
Created June 24, 2013 14:34
simple fabric file to test all our vm
from fabric.api import run, winrm_run, cd
from fabric.decorators import task
@task
def test_windows():
winrm_run("ipconfig /all")
@task
def test_unix():
run("hostname")
PHONY: all
CC = gcc
CFLAGS = -I/usr/include/python2.7 -W -Wall -fPIC
ufunc.so: my_ufunc.o ufunc.o
$(LD) $< -o $@
my_ufunc.o: my_ufunc.c my_ufunc.h
$(CC) $(CFLAGS) -c $< -o $@
@cournape
cournape / minilib.py
Created June 24, 2013 21:20
Poor man runtime callgraph. You need linux perf (perf-tools under debian/ubuntu) and valgrind for the corresponding functions
import contextlib
import os
import signal
import subprocess
import numpy as np
def enable_callgrind():
subprocess.check_call(["callgrind_control", "--instr=on", str(os.getpid())])
@cournape
cournape / debian_version_example.py
Created September 18, 2013 19:33
Depsolver with alternative version
from depsolver import PackageInfo, Repository, Pool, Request, Requirement, Solver
from depsolver.debian_version import DebianVersion
P = PackageInfo.from_string
R = Requirement.from_string
V = DebianVersion.from_string
a_1_0_0 = P("A-1.0.0~1; depends (B, C)", V)
b_1_0_0 = P("B-1.0.0~1; depends (D <= 1.1.0~1)", V)
c_1_0_0 = P("C-1.0.0~1; depends (D <= 0.9.0~1)", V)
@cournape
cournape / rules_example.py
Created September 18, 2013 19:54
Rules generator
from depsolver.compat import OrderedDict
from depsolver import PackageInfo, Repository, Pool, Request, Requirement, Solver
from depsolver.solver.rules_generator import RulesGenerator
P = PackageInfo.from_string
R = Requirement.from_string
a_1_0_0 = P("A-1.0.0; depends (B, C)")
b_1_0_0 = P("B-1.0.0; depends (D <= 1.1.0)")
c_1_0_0 = P("C-1.0.0; depends (D <= 0.9.0)")
@cournape
cournape / test_foo.py
Created September 23, 2013 15:20
assert multiline equal not working
import unittest
a = """
asd
"""
b = """
laskj
"""