From 24924d0ce379428452469cb279c0ce39ffb61a5d Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Sun, 9 Jun 2013 19:10:10 -0400 Subject: [PATCH] Work around missing bin() in Py2.5 --- pyopencl/algorithm.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pyopencl/algorithm.py b/pyopencl/algorithm.py index f2eb9a1d..bedfb1a0 100644 --- a/pyopencl/algorithm.py +++ b/pyopencl/algorithm.py @@ -246,8 +246,20 @@ def unique(ary, is_equal_expr="a == b", extra_args=[], preamble="", # {{{ radix_sort +def to_bin(n): + # Py 2.5 has no built-in bin() + digs = [] + while True: + digs.append(str(n % 2)) + n /= 2 + if not n: + break + digs.reverse() + return ''.join(digs) + + def _padded_bin(i, l): - s = bin(i)[2:] + s = to_bin(i) while len(s) < l: s = '0' + s return s -- GitLab