Skip to content

Commit

Permalink
Added from __future and utf-8 encoding directive to all files (except…
Browse files Browse the repository at this point in the history
… tests)

In each file, the following code was added:

from __future__ import print_function, division, absolute_import

Some doctests are failing due to the difference in the print statement.
Some tests are failing due to the difference in the division operator.
  • Loading branch information
hgrecco committed Mar 2, 2013
1 parent a18f77d commit e62180e
Show file tree
Hide file tree
Showing 245 changed files with 993 additions and 333 deletions.
2 changes: 2 additions & 0 deletions docs/ams_presentation/linregr_bench.py
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function, division, absolute_import
import linregr_python, linregr_numba, linregr_numbapro
import numpy as np
import pylab
Expand Down
2 changes: 2 additions & 0 deletions docs/ams_presentation/linregr_numba.py
@@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
'''
Numba does not support array expressions.
Expand the array-expression into loops.
'''
from __future__ import print_function, division, absolute_import
from numba import autojit, jit, f8, int32, void

@jit(void(f8[:], f8[:], f8[:], f8, int32))
Expand Down
2 changes: 2 additions & 0 deletions docs/ams_presentation/linregr_numbapro.py
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
'''
Only added decorators to the linregr_python.py implementation.
'''
from __future__ import print_function, division, absolute_import

import numbapro
from numba import autojit, jit, f8, int32, void
Expand Down
2 changes: 2 additions & 0 deletions docs/ams_presentation/linregr_numbapro_cuda.py
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
'''
NumbaPro CUDA implementation
'''
from __future__ import print_function, division, absolute_import
from numbapro import cuda
from numba import autojit, jit, f8, int32, void
import numpy as np
Expand Down
2 changes: 2 additions & 0 deletions docs/ams_presentation/linregr_python.py
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
'''
The following implementation references:
http://aimotion.blogspot.com/2011/10/machine-learning-with-python-linear.html
'''
from __future__ import print_function, division, absolute_import

def gradient_descent(X, Y, theta, alpha, num_iters):
m = Y.shape[0]
Expand Down
2 changes: 2 additions & 0 deletions docs/gh-pages.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Script to commit the doc build outputs into the github-pages repo.
Use:
Expand All @@ -10,6 +11,7 @@
In practice, you should use either actual clean tags from a current build or
something like 'current' as a stable URL for the most current version of the """
from __future__ import print_function, division, absolute_import

#-----------------------------------------------------------------------------
# Imports
Expand Down
1 change: 1 addition & 0 deletions docs/source/conf.py
@@ -1,3 +1,4 @@
from __future__ import print_function, division, absolute_import
# -*- coding: utf-8 -*-
#
# llvmpy documentation build configuration file, created by
Expand Down
2 changes: 2 additions & 0 deletions docs/update-release-notes.py
@@ -1,9 +1,11 @@
# -*- coding: utf-8 -*-
'''
Run me to update the release notes in the documentation.
I will pull the content from ../CHANGE_LOG and insert that into
./source/doc/releases.rst
'''
from __future__ import print_function, division, absolute_import


title_template = '''
Expand Down
2 changes: 2 additions & 0 deletions examples/bubblesort.py
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function, division, absolute_import
from numba import *
import numpy as np
from timeit import default_timer as timer
Expand Down
2 changes: 2 additions & 0 deletions examples/closure.py
@@ -1,9 +1,11 @@
# -*- coding: utf-8 -*-
"""
Example for closures. Closures may be of arbitrary dept, and they keep
the scope alive as long as the closure is alive. Only variables that are
closed over (cell variables in the defining function, free variables in the
closure), are kept alive. See also numba/tests/closures/test_closure.py
"""
from __future__ import print_function, division, absolute_import

from numba import autojit, jit, float_
from numpy import linspace
Expand Down
2 changes: 2 additions & 0 deletions examples/debugout.py
@@ -1,9 +1,11 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''debugout.py
Example of using numba.utils.debugout() to view values in LLVM code
generated by Numba.
'''
from __future__ import print_function, division, absolute_import
# ______________________________________________________________________

import numpy
Expand Down
2 changes: 2 additions & 0 deletions examples/example.py
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function, division, absolute_import

from scipy.misc import lena
from numpy import ones
Expand Down
2 changes: 2 additions & 0 deletions examples/fbcorr.py
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
"""
This file demonstrates a filterbank correlation loop.
"""
from __future__ import print_function, division, absolute_import
import numpy as np
import numba
from numba.decorators import jit
Expand Down
2 changes: 2 additions & 0 deletions examples/findmulti.py
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function, division, absolute_import
from numba import jit

@jit('i4(i4,f8,i4,f8[:])')
Expand Down
2 changes: 2 additions & 0 deletions examples/mandel.py
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function, division, absolute_import
from numba import autojit
import numpy as np
from pylab import imshow, jet, show, ion
Expand Down
2 changes: 2 additions & 0 deletions examples/numbaclasses.py
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""
Example for extension classes.
Expand All @@ -17,6 +18,7 @@
(multiple inheritance with Python classes should work)
- subclassing variable sized objects like 'str' or 'tuple'
"""
from __future__ import print_function, division, absolute_import

from numba import jit, void, int_, double

Expand Down
2 changes: 2 additions & 0 deletions examples/objects.py
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function, division, absolute_import
from numba import double, autojit

class MyClass(object):
Expand Down
2 changes: 2 additions & 0 deletions examples/pointers.py
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function, division, absolute_import
import numba
from numba import *
from numba.tests.test_support import autojit_py3doc
Expand Down
2 changes: 2 additions & 0 deletions examples/simpleadd.py
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function, division, absolute_import
from numba import jit, autojit

@jit('f8(f8,f8)')
Expand Down
2 changes: 2 additions & 0 deletions examples/structures.py
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function, division, absolute_import
from numba import struct, jit, double
import numpy as np

Expand Down
2 changes: 2 additions & 0 deletions examples/sum.py
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function, division, absolute_import
from numba import double
from numba.decorators import jit as jit

Expand Down
2 changes: 2 additions & 0 deletions gen_type_conversion.py
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
"""
Generate generated_conversions.c
Utilities adjusted from Cython/Compiler/PyrexTypes.pyx
"""
from __future__ import print_function, division, absolute_import

import os

Expand Down
2 changes: 2 additions & 0 deletions getfailed.py
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function, division, absolute_import
import pickle, sys, os

noseid_file = 'numba/tests/.noseids'
Expand Down
12 changes: 7 additions & 5 deletions numba/__init__.py
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function, division, absolute_import
# Import all special functions before registering the Numba module
# type inferer

Expand Down Expand Up @@ -58,7 +60,7 @@ def _config_logger():
_config_logger()


from . import special
from . import special
from numba.typesystem import *
from numba.minivect.minitypes import FunctionType
from numba.error import *
Expand Down Expand Up @@ -149,17 +151,17 @@ def test(whitelist=None, blacklist=None):
if process.returncode == 0:
print("SUCCESS")
else:
print("FAILED: %s" % map_returncode_to_message(
process.returncode))
print(("FAILED: %s" % map_returncode_to_message(
process.returncode)))
if PY3:
out = str(out, encoding='UTF-8')
err = str(err, encoding='UTF-8')
print(out)
print(err)
print("-" * 80)
print(("-" * 80))
failed += 1

print("ran test files: failed: (%d/%d)" % (failed, run))
print(("ran test files: failed: (%d/%d)" % (failed, run)))
return failed

def nose_run(module=None):
Expand Down
20 changes: 11 additions & 9 deletions numba/_version.py
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function, division, absolute_import

IN_LONG_VERSION_PY = True
# This file helps to compute a version number in source trees obtained from
Expand All @@ -24,15 +26,15 @@ def run_command(args, cwd=None, verbose=False):
except EnvironmentError:
e = sys.exc_info()[1]
if verbose:
print("unable to run %s" % args[0])
print(("unable to run %s" % args[0]))
print(e)
return None
stdout = p.communicate()[0].strip()
if sys.version >= '3':
stdout = stdout.decode()
if p.returncode != 0:
if verbose:
print("unable to run %s (error)" % args[0])
print(("unable to run %s (error)" % args[0]))
return None
return stdout

Expand Down Expand Up @@ -71,7 +73,7 @@ def versions_from_expanded_variables(variables, tag_prefix, verbose=False):
for ref in list(refs):
if not re.search(r'\d', ref):
if verbose:
print("discarding '%s', no digits" % ref)
print(("discarding '%s', no digits" % ref))
refs.discard(ref)
# Assume all version tags have a digit. git's %d expansion
# behaves like git log --decorate=short and strips out the
Expand All @@ -80,13 +82,13 @@ def versions_from_expanded_variables(variables, tag_prefix, verbose=False):
# without digits, we filter out many common branch names like
# "release" and "stabilization", as well as "HEAD" and "master".
if verbose:
print("remaining refs: %s" % ",".join(sorted(refs)))
print(("remaining refs: %s" % ",".join(sorted(refs))))
for ref in sorted(refs):
# sorting will prefer e.g. "2.0" over "2.0rc1"
if ref.startswith(tag_prefix):
r = ref[len(tag_prefix):]
if verbose:
print("picking %s" % r)
print(("picking %s" % r))
return { "version": r,
"full": variables["full"].strip() }
# no suitable tags, so we use the full revision id
Expand Down Expand Up @@ -123,7 +125,7 @@ def versions_from_vcs(tag_prefix, versionfile_source, verbose=False):
root = os.path.dirname(here)
if not os.path.exists(os.path.join(root, ".git")):
if verbose:
print("no .git in %s" % root)
print(("no .git in %s" % root))
return {}

stdout = run_command([GIT, "describe", "--tags", "--dirty", "--always"],
Expand All @@ -132,7 +134,7 @@ def versions_from_vcs(tag_prefix, versionfile_source, verbose=False):
return {}
if not stdout.startswith(tag_prefix):
if verbose:
print("tag '%s' doesn't start with prefix '%s'" % (stdout, tag_prefix))
print(("tag '%s' doesn't start with prefix '%s'" % (stdout, tag_prefix)))
return {}
tag = stdout[len(tag_prefix):]
stdout = run_command([GIT, "rev-parse", "HEAD"], cwd=root)
Expand Down Expand Up @@ -171,8 +173,8 @@ def versions_from_parentdir(parentdir_prefix, versionfile_source, verbose=False)
dirname = os.path.basename(root)
if not dirname.startswith(parentdir_prefix):
if verbose:
print("guessing rootdir is '%s', but '%s' doesn't start with prefix '%s'" %
(root, dirname, parentdir_prefix))
print(("guessing rootdir is '%s', but '%s' doesn't start with prefix '%s'" %
(root, dirname, parentdir_prefix)))
return None
return {"version": dirname[len(parentdir_prefix):], "full": ""}

Expand Down
16 changes: 9 additions & 7 deletions numba/ad.py
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""
Example of how to use byte-code execution technique to trace accesses to numpy arrays.
Expand All @@ -6,6 +7,7 @@
* provide automatic differentiation of procedural code
"""
from __future__ import print_function, division, absolute_import

import __builtin__
import os
Expand All @@ -31,7 +33,7 @@ class FrameVM(object):
"""
def __init__(self, watcher, func):
print 'FrameVM', func
print('FrameVM', func)
self.watcher = watcher
self.func = func
self.fco = func.__code__
Expand Down Expand Up @@ -155,14 +157,14 @@ def op_FOR_ITER(self, i, op, arg):
tos = self.stack[-1]
try:
next = next(tos)
print 'next', next
print('next', next)
self.stack.append(next)
except StopIteration:
self.stack.pop(-1)
return ('rel', arg)

def op_JUMP_ABSOLUTE(self, i, op, arg):
print 'sending', arg
print('sending', arg)
return ('abs', arg)

def op_JUMP_IF_TRUE(self, i, op, arg):
Expand Down Expand Up @@ -195,19 +197,19 @@ def op_LOAD_FAST(self, i, op, arg):
self.stack.append(self._locals[arg])

def op_POP_BLOCK(self, i, op, arg):
print 'pop block, what to do?'
print('pop block, what to do?')

def op_POP_TOP(self, i, op, arg):
self.stack.pop(-1)

def op_PRINT_ITEM(self, i, op, arg):
print self.stack.pop(-1),
print(self.stack.pop(-1), end=' ')

def op_PRINT_NEWLINE(self, i, op, arg):
print ''
print('')

def op_SETUP_LOOP(self, i, op, arg):
print 'SETUP_LOOP, what to do?'
print('SETUP_LOOP, what to do?')

def op_STORE_FAST(self, i, op, arg):
#print 'STORE_FAST', self.varnames[arg]
Expand Down
2 changes: 1 addition & 1 deletion numba/annotate.py
@@ -1,10 +1,10 @@
# -*- coding: UTF-8 -*-

"""
numba --annotate
Adapted from Cython/Compiler/Annotate.py
"""
from __future__ import print_function, division, absolute_import

# Note: Work in progress

Expand Down
4 changes: 3 additions & 1 deletion numba/array_expressions.py
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function, division, absolute_import
import ast

from numba import templating
Expand Down Expand Up @@ -63,7 +65,7 @@ def get_py_ufunc_ast(self, lhs, node):
from meta import asttools

module = ast.Module(body=[ufunc_ast])
print asttools.python_source(module)
print((asttools.python_source(module)))

# Vectorize Python function
if lhs is None:
Expand Down

0 comments on commit e62180e

Please sign in to comment.