Skip to content

Instantly share code, notes, and snippets.

@inducer
inducer / export-bug.py
Created July 21, 2012 05:48
OpenCascade export bug
import OCC.gp as gp
import OCC.BRepPrimAPI as brep
import OCC.BRepAlgoAPI as brep_alg
import OCC.Utils.DataExchange.IGES as iges
import OCC.Utils.DataExchange.STEP as step
import OCC.Display.SimpleGui as gui
objs = []
for x in [0, 21]:
ax = gp.gp_Ax2(gp.gp_Pnt(x,0,0), gp.gp_Dir(0,1,0))
@inducer
inducer / scan.cl
Created July 24, 2012 04:35
PyOpenCL scan code generator
#define K ${k_group_size}
KERNEL
REQD_WG_SIZE(WG_SIZE, 1, 1)
void ${name_prefix}_scan_intervals(
${argument_signature},
GLOBAL_MEM scan_type *partial_scan_buffer,
const index_type N,
const index_type interval_size
@inducer
inducer / README
Created September 3, 2012 22:49
Timing example
Please get your timing code from
https://github.com/hpc12/lec1-demo
@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 = """
@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 / 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 / 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 / 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 / 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_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):