Skip to content

Instantly share code, notes, and snippets.

@inducer
inducer / remove-ipynb-output.py
Created February 27, 2014 14:53
Script to remove output in IPython notebook
#! /usr/bin/env python3
from json import load, dump
import sys
if len(sys.argv) != 3:
print("usage: %s INFILE OUTFILE", file=sys.stderr)
with open(sys.argv[1], "rt") as inf:
@inducer
inducer / akteach.sty
Created February 2, 2014 19:19
CS450 style file
\nonstopmode
\usepackage[letterpaper, margin=1in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{url}
\usepackage{hyperref}
\usepackage{keystroke}
\usepackage{tikz}
\usepackage{ifthen}
@inducer
inducer / triangle-flipping.py
Created October 31, 2013 21:21
Triangle flipping Python snippet
def find_flips(mesh, start_el_nr=None, flip_flags=None, remaining_els=None, thresh=1e-5):
if start_el_nr is None:
start_el_nr = 0
if flip_flags is None:
flip_flags = np.zeros(len(mesh), dtype=np.bool)
if remaining_els is None:
remaining_els = set(xrange(len(mesh)))
remaining_els.remove(start_el_nr)
@inducer
inducer / test_bvp.py
Created October 3, 2013 04:59
Test script for the fast BVP solver in HW4 of the 2013 integral equations class at UIUC
from __future__ import division
import numpy as np
from bvp import solve_bvp
a = -4
b = 5
def test_poisson(discr):
def u_true(x):
@inducer
inducer / legendre_discr.py
Created October 3, 2013 04:03
Template for the composite high-order Legendre discretization toolkit for HW4 of the 2013 integral equations class at UIUC
from __future__ import division
import numpy as np
import numpy.linalg as la
import scipy.special as sp
class CompositeLegendreDiscretization:
"""A discrete function space on a 1D domain consisting of multiple
subintervals, each of which is discretized as a polynomial space of
maximum degree *order*. (see constructor arguments)
@inducer
inducer / test_legendre_discr.py
Created October 3, 2013 03:58
Test script for the composite high-order Legendre discretization toolkit for HW4 of the 2013 integral equations class at UIUC
from __future__ import division
from legendre_discr import CompositeLegendreDiscretization
import numpy as np
import matplotlib.pyplot as pt
def get_left_int_error(n, order):
a = 2
b = 30
@inducer
inducer / ieee.py
Created September 25, 2013 21:06
Floating point structure playground
from __future__ import division
def pretty_print_fp(x):
print "---------------------------------------------"
print "Floating point structure for %r" % x
print "---------------------------------------------"
import struct
s = struct.pack("d", x)
print "Hex pattern:", " ".join("%02x" % ord(i) for i in s[::-1])
@inducer
inducer / trapz.py
Created September 4, 2013 16:02
Compute indefinite integrals by the trapezoidal rule
import numpy as np
def running_trapz(f, mesh):
"""Return the 1D indefinite integral of the function *f* given
at the points in *mesh*. The integral is returned at the points
of *mesh*, and the leftmost value is always zero. The integral
is approximated using the trapezoidal rule.
"""
@inducer
inducer / gist:5585945
Created May 15, 2013 17:59
Quadrature playground.ipynb
{
"metadata": {
"name": "Quadrature playground"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@inducer
inducer / map-example.py
Created December 21, 2012 16:29
Example of how to use ALLOC_HOST_PTR for alignment/faster transfers
import numpy as np
import numpy.linalg as la
import pyopencl as cl
import pyopencl.array as cl_array
from time import time
KERNEL = """