Skip to content

Instantly share code, notes, and snippets.

@bjodah
bjodah / Makefile
Last active August 29, 2015 14:01
Benchmark pow() vs explicit multiplication
# Enabling -ffast-math makes the two versions competetive, without it explicit is much faster...
# (~20x for exponent of 5)
CFLAGS ?= -std=c99 -O3 #-ffast-math
LIBS ?= -lrt -lm
.PHONY: all
output.txt: main
$(CC) --version > $@
./$< 42 >> $@
@bjodah
bjodah / _func.pyx
Created June 16, 2014 12:18
Non-type template arguments C++/Cython
# -*- coding: utf-8 -*-
# distutils: language = c++
from func cimport func as _func
def func(double inp):
cdef double out
_func[double, 3](&inp, &out);
return out;
@bjodah
bjodah / demo.py
Last active August 29, 2015 14:03
prototype Dictionary Of Keys based sparse (square) matrix. Implemented in cython.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from sparse import SMat
def _print(a):
{
"metadata": {
"name": "",
"signature": "sha256:ff2051673721abee70ec74bc10add60780735c583e66f767e30c0906bd95ba38"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
@bjodah
bjodah / _func.pyx
Created November 20, 2014 13:05
Compiler crash when gdb_debug=True and multiple tempate typenames are used.
# -*- coding: utf-8 -*-
# distutils: language = c++
from func cimport func as _func
def func(double inp):
cdef double out
_func[double, double](&inp, &out);
return out;
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bjodah
bjodah / _myheader.pyx
Created August 31, 2015 12:17
deferred_declaration_cython
# -*- coding: utf-8 -*-
# distutils: language = c++
from libcpp cimport bool
cdef extern from "myheader.hpp":
cdef cppclass MyInt:
void add_two()
bool is_poitive()
@bjodah
bjodah / example_infer.py
Created October 2, 2013 08:48
Code generation of typed cython code from annotated pure python code (makes cython optional). Proof of concecpt not nearly as mature as e.g. cython pure mode.
from infer import MetaInfer
from infer import types as t
class Vec2(metaclass=MetaInfer):
# Typed slots:
_typed_init_slots = (
('x', t.double, 0.0),
('y', t.double, 0.0)
)