Skip to content

Instantly share code, notes, and snippets.

# Drop this in the Demos directory of Cython and run
# python setup.py build_ext --inplace && python -c 'import time_exc'
# cython: cdivision=True
# distutils: extra_compile_args = -O3
import time
cdef int with_nothing(bint bad):
@robertwb
robertwb / isnan_timings.pyx
Last active August 11, 2016 17:15
isnan timings
from libc.math cimport isnan as c_isnan
from math import isnan as math_isnan
from cmath import isnan as cmath_isnan
from numpy import isnan as numpy_isnan
cdef extern from "numpy/npy_math.h":
bint npy_isnan(double x)
def time_c_isnan(double value, long N=1000000):
cdef bint res = 0
def fake_cythonize(patterns):
import glob, json, os
from distutils.extension import Extension
def is_package_dir(path):
return os.path.exists(os.path.join(path, '__init__.py'))
def package(filename):
dir = os.path.dirname(str(filename))
#distutils: language=c++
from libcpp.memory cimport shared_ptr
from cpython.buffer cimport PyObject_GetBuffer, PyBUF_FULL
cdef extern from *:
cdef cppclass CppObj:
pass
cdef shared_ptr[CppObj] cpp_function(Py_buffer *buf)
from collections import defaultdict
import re
import sys
all = defaultdict(dict)
lineno = None
for line in sys.stdin:
m = re.match(r' */\* "(.*\.pyx)":(\d+)', line)
if m:
#ifndef __BaseClass__
#define __BaseClass__
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;
class BaseClass
{
public:
BaseClass(){};
#ifndef __BaseClass__
#define __BaseClass__
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;
class BaseClass
{
public:
BaseClass(){};
import time
import cython
import numpy as np
@cython.boundscheck(False)
@cython.wraparound(False)
@cython.nonecheck(False)
@cython.cdivision(True)