Skip to content

Instantly share code, notes, and snippets.

View likr's full-sized avatar

Yosuke Onoue likr

View GitHub Profile
@likr
likr / clbench.py
Created June 16, 2012 00:35
pyopencl benchmark
import pyopencl as cl
from pyopencl import array as clarray
from pyopencl import clmath
from pyopencl import clrandom
import numpy
from time import time
def timeit(f, args):
n = 100
t = 0
@likr
likr / fizzbuzz.py
Created August 9, 2012 08:41
PyOpenCL FizzBuzz
# coding: utf-8
# vim: filetype=pyopencl.python
from __future__ import print_function
import numpy as np
import pyopencl as cl
from pyopencl import array as clarray
from pyopencl.scan import ExclusiveScanKernel
src = '''//CL//
@likr
likr / gaussian.py
Created September 17, 2012 06:02
PyOpenCL image2d exapmle
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: filetype=pyopencl.python
import sys
import time
from PyQt4 import QtCore
from PyQt4 import QtGui
import pyopencl as cl
import numpy
@likr
likr / nikakudori.py
Created September 22, 2012 01:16
二角取り生成
#!/usr/bin/env python2.7
# coding: utf-8
from __future__ import print_function
from __future__ import division
class Board(object):
def __init__(self, W, H):
assert W * H % 4 == 0
@likr
likr / kp.ml
Created October 3, 2012 17:42
DP for Knapsack Problem
type item = {w:int; p:int}
(* 2004, Kellerer et al., Knapsack Problems, p.23 *)
let dp2 items c =
let n = Array.length items in
let z = Array.make (c + 1) 0 in
for j = 0 to n - 1 do
let {w=wj; p=pj} = items.(j) in
for d = c downto wj do
let o = z.(d - wj) + pj in
# vim: filetype=pyopencl.python
import numpy as np
from PIL import Image
import pyopencl as cl
from pyopencl import array as clarray
SRC = '''//CL//
__constant const int CHECKER_SIZE = 10;
float2 polar(const int2);
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: filetype=pyopencl.python
from __future__ import division
import sys
import math
import random
import itertools
# coding: utf-8
def dfs(i, w, c, x):
if i == len(w):
return True
wi = w[i]
for j in range(len(c)):
if wi > c[j]:
continue
@likr
likr / kp.rs
Created July 15, 2013 23:52
Rust code for solving knapsack problem.
fn dp (p : &[int], w : &[int], c : int) -> int {
let mut z = std::vec::from_elem((c + 1) as uint, 0);
for p.iter().zip(w.iter()).advance |(pj, wj)| {
for std::uint::range_rev(c as uint, (*wj - 1) as uint) |k| {
z[k] = match z[k - *wj as uint] + *pj {
v if v > z[k] => v,
_ => z[k]
}
}
}
@likr
likr / kinoko.html
Last active December 23, 2015 23:29
<html>
<link rel="stylesheet" href="bgstretcher.css" />
<script type="text/javascript" src="jquery-1.6.1.js"></script>
<script type="text/javascript" src="bgstretcher.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var iter = 0;
var images = ['images/白い画像.jpg', 'images/sample-2.jpg'];