-
This is a numbered list.
-
I'm going to include a fenced code block as part of this bullet:
Code More Code
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <iomanip> | |
// | |
// Utilities | |
// | |
// RETURNS() is used to avoid writing boilerplate "->decltype(x) { return x; }" phrases. | |
// | |
// USAGE: auto function(<arguments>) RETURNS(<some-expression>); | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
The following code inverts the matrix input using LU-decomposition with backsubstitution of unit vectors. Reference: Numerical Recipies in C, 2nd ed., by Press, Teukolsky, Vetterling & Flannery. | |
you can solve Ax=b using three lines of ublas code: | |
permutation_matrix<> piv; | |
lu_factorize(A, piv); | |
lu_substitute(A, piv, x); | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define this to turn on error checking | |
#define CUDA_ERROR_CHECK | |
#define CudaSafeCall( err ) __cudaSafeCall( err, __FILE__, __LINE__ ) | |
#define CudaCheckError() __cudaCheckError( __FILE__, __LINE__ ) | |
inline void __cudaSafeCall( cudaError err, const char *file, const int line ) | |
{ | |
#ifdef CUDA_ERROR_CHECK | |
if ( cudaSuccess != err ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Python.h> | |
#include <numpy/arrayobject.h> | |
#include "chi2.h" | |
/* Docstrings */ | |
static char module_docstring[] = | |
"This module provides an interface for calculating chi-squared using C."; | |
static char chi2_docstring[] = | |
"Calculate the chi-squared of some data given a model."; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass[]{article} | |
\usepackage{amssymb,amsmath} | |
\usepackage{ifxetex,ifluatex} | |
\ifxetex | |
\usepackage{fontspec,xltxtra,xunicode} | |
\defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase} | |
\newcommand{\euro}{€} | |
\else | |
\ifluatex | |
\usepackage{fontspec} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INCDIR = $(HOME)/opt/local/include/luajit-2.0 | |
LIBDIR = $(HOME)/opt/local/lib | |
LIB = -lluajit-51 | |
all: native | |
native: | |
cc --std=c99 -o native-co native.c -I$(INCDIR) -L$(LIBDIR) $(LIB) -pagezero_size 10000 -image_base 100000000 | |
clean: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Class-based decorators. | |
This code was originally published as part of an article at | |
http://tech.novapost.fr/python-class-based-decorators-en.html | |
To run this file: | |
.. code-block:: sh | |
wget -O sample.py https://gist.github.com/benoitbryon/5168914/raw/ |
OlderNewer