Skip to content

Commit

Permalink
isort (#734)
Browse files Browse the repository at this point in the history
* isort

* flake8

---------

Co-authored-by: Andreas Klöckner <[email protected]>
  • Loading branch information
matthiasdiener and inducer authored May 2, 2024
1 parent de64858 commit d9b82e1
Show file tree
Hide file tree
Showing 50 changed files with 254 additions and 234 deletions.
12 changes: 7 additions & 5 deletions aksetup_helper.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
import sys


try:
from setuptools import Extension
from setuptools.command.build_ext import ( # noqa: N812
build_ext as BaseBuildExtCommand)
from setuptools.command.build_ext import \
build_ext as BaseBuildExtCommand # noqa: N812

except ImportError:
class Extension:
Expand Down Expand Up @@ -43,8 +45,8 @@ def setup(*args, **kwargs):


def get_numpy_incpath():
from os.path import join, dirname, exists
from importlib.util import find_spec
from os.path import dirname, exists, join
origin = find_spec("numpy").origin
if origin is None:
raise RuntimeError("origin of numpy package not found")
Expand Down Expand Up @@ -769,7 +771,7 @@ def substitute(substitutions, fname):
with open(fname, "w") as outf:
outf.write("".join(new_lines))

from os import stat, chmod
from os import chmod, stat
infile_stat_res = stat(fname_in)
chmod(fname, infile_stat_res.st_mode)

Expand All @@ -778,7 +780,7 @@ def substitute(substitutions, fname):

def _run_git_command(cmd):
git_error = None
from subprocess import Popen, PIPE
from subprocess import PIPE, Popen
stdout = None
try:
popen = Popen(["git"] + cmd, stdout=PIPE)
Expand Down
2 changes: 2 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#! /usr/bin/env python3

from aksetup_helper import configure_frontend


configure_frontend()
6 changes: 3 additions & 3 deletions contrib/cldis.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
Usage: python cldis.py prog.cl <ptx/sass/asm> <build options>
"""

import glob
import os
import tempfile
import subprocess
import re
import subprocess
import sys
import glob
import tempfile


def main(ctx, tmp_dir, cl_str, output=None, build_options=[]):
Expand Down
31 changes: 14 additions & 17 deletions contrib/fortran-to-opencl/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@
THE SOFTWARE.
"""

import cgen
import numpy as np
import re
from pymbolic.parser import Parser as ExpressionParserBase
from pymbolic.mapper import CombineMapper
import pymbolic.primitives as p
from pymbolic.mapper.c_code import CCodeMapper as CCodeMapperBase
from sys import intern

from warnings import warn

import cgen
import numpy as np
import pymbolic.primitives as p
import pytools.lex
from pymbolic.mapper import CombineMapper
from pymbolic.mapper.c_code import CCodeMapper as CCodeMapperBase
from pymbolic.parser import Parser as ExpressionParserBase


class TranslatorWarning(UserWarning):
Expand Down Expand Up @@ -154,8 +153,7 @@ def __init__(self, tree_walker):
def parse_terminal(self, pstate):
scope = self.tree_walker.scope_stack[-1]

from pymbolic.parser import (
_identifier, _openpar, _closepar, _float)
from pymbolic.parser import _closepar, _float, _identifier, _openpar

next_tag = pstate.next_tag()
if next_tag is _float:
Expand Down Expand Up @@ -221,8 +219,8 @@ def parse_terminal(self, pstate):
}

def parse_prefix(self, pstate, min_precedence=0):
from pymbolic.parser import _PREC_UNARY
import pymbolic.primitives as primitives
from pymbolic.parser import _PREC_UNARY

pstate.expect_not_end()

Expand All @@ -235,10 +233,9 @@ def parse_prefix(self, pstate, min_precedence=0):

def parse_postfix(self, pstate, min_precedence, left_exp):
from pymbolic.parser import (
_PREC_CALL, _PREC_COMPARISON, _openpar,
_PREC_LOGICAL_OR, _PREC_LOGICAL_AND)
from pymbolic.primitives import (
Comparison, LogicalAnd, LogicalOr)
_PREC_CALL, _PREC_COMPARISON, _PREC_LOGICAL_AND, _PREC_LOGICAL_OR,
_openpar)
from pymbolic.primitives import Comparison, LogicalAnd, LogicalOr

next_tag = pstate.next_tag()
if next_tag is _openpar and _PREC_CALL > min_precedence:
Expand Down Expand Up @@ -351,7 +348,7 @@ def map_sum(self, expr, enclosing_prec):
complexes = [child for child in expr.children
if "c" == self.infer_type(child).kind]

from pymbolic.mapper.stringifier import PREC_SUM, PREC_NONE
from pymbolic.mapper.stringifier import PREC_NONE, PREC_SUM
real_sum = self.join_rec(" + ", reals, PREC_SUM)

if len(complexes) == 1:
Expand Down Expand Up @@ -387,7 +384,7 @@ def map_product(self, expr, enclosing_prec):
complexes = [child for child in expr.children
if "c" == self.infer_type(child).kind]

from pymbolic.mapper.stringifier import PREC_PRODUCT, PREC_NONE
from pymbolic.mapper.stringifier import PREC_NONE, PREC_PRODUCT
real_prd = self.join_rec("*", reals, PREC_PRODUCT)

if len(complexes) == 1:
Expand Down Expand Up @@ -489,7 +486,7 @@ def map_subscript(self, expr, enclosing_prec):
if isinstance(idx, tuple) and len(idx) == 1:
idx, = idx

from pymbolic.mapper.stringifier import PREC_NONE, PREC_CALL
from pymbolic.mapper.stringifier import PREC_CALL, PREC_NONE
return self.parenthesize_if_needed(
self.format("%s[%s%s]",
self.scope.translate_var_name(expr.aggregate.name),
Expand Down
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from urllib.request import urlopen


_conf_url = \
"https://raw.githubusercontent.com/inducer/sphinxconfig/main/sphinxconfig.py"
with urlopen(_conf_url) as _inf:
Expand Down
2 changes: 2 additions & 0 deletions doc/make_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import pyopencl as cl


fission = ("cl_ext_device_fission", "2011.1")
nv_devattr = ("cl_nv_device_attribute_query", "0.92")
gl_sharing = ("cl_khr_gl_sharing", "0.92")
Expand Down Expand Up @@ -548,6 +549,7 @@ def doc_class(cls):

import inspect


CONSTANT_CLASSES = [
getattr(cl, name) for name in dir(cl)
if inspect.isclass(getattr(cl, name))
Expand Down
10 changes: 6 additions & 4 deletions examples/black-hole-accretion.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
# export CL_CONFIG_USE_VECTORIZER=True
# export CL_CONFIG_CPU_VECTORIZER_MODE=16

import pyopencl as cl
import numpy
import time
import sys
import getopt
import sys
import time
from socket import gethostname

import numpy

import pyopencl as cl


def DictionariesAPI():
PhysicsList = {"Einstein": 0, "Newton": 1}
Expand Down
5 changes: 5 additions & 0 deletions examples/demo-struct-reduce.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np

import pyopencl as cl


Expand Down Expand Up @@ -55,10 +56,14 @@ def make_collector_dtype(device):
"""

from pyopencl.clrandom import rand as clrand


a_gpu = clrand(queue, (20000,), dtype=np.int32, a=0, b=10**6)
a = a_gpu.get()

from pyopencl.reduction import ReductionKernel


red = ReductionKernel(ctx, mmc_dtype,
neutral="mmc_neutral()",
reduce_expr="agg_mmc(a, b)", map_expr="mmc_from_scalar(x[i])",
Expand Down
2 changes: 2 additions & 0 deletions examples/demo.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env python

import numpy as np

import pyopencl as cl


rng = np.random.default_rng()
a_np = rng.random(50000, dtype=np.float32)
b_np = rng.random(50000, dtype=np.float32)
Expand Down
1 change: 1 addition & 0 deletions examples/demo_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pyopencl as cl
import pyopencl.array as cl_array


rng = np.random.default_rng()
a = rng.random(50000, dtype=np.float32)
b = rng.random(50000, dtype=np.float32)
Expand Down
1 change: 1 addition & 0 deletions examples/demo_array_svm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pyopencl.array as cl_array
from pyopencl.tools import SVMAllocator, SVMPool


n = 50000

rng = np.random.default_rng()
Expand Down
1 change: 1 addition & 0 deletions examples/demo_elementwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pyopencl.array
from pyopencl.elementwise import ElementwiseKernel


n = 10

rng = np.random.default_rng()
Expand Down
1 change: 1 addition & 0 deletions examples/demo_elementwise_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pyopencl.array as cl_array
from pyopencl.elementwise import ElementwiseKernel


ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)

Expand Down
2 changes: 1 addition & 1 deletion examples/demo_mandelbrot.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import time

import numpy as np
from PIL import Image

import pyopencl as cl

from PIL import Image

# You can choose a calculation routine below (calc_fractal), uncomment
# one of the three lines to test the three variations
Expand Down
6 changes: 4 additions & 2 deletions examples/demo_meta_codepy.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import numpy as np
import numpy.linalg as la
from cgen import (POD, Assign, Block, Const, FunctionBody, FunctionDeclaration,
Initializer, Module, Pointer, Value)
from cgen import (
POD, Assign, Block, Const, FunctionBody, FunctionDeclaration, Initializer,
Module, Pointer, Value)
from cgen.opencl import CLGlobal, CLKernel, CLRequiredWorkGroupSize

import pyopencl as cl


local_size = 256
thread_strides = 32
macroblock_count = 33
Expand Down
2 changes: 1 addition & 1 deletion examples/demo_meta_template.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import numpy as np
import numpy.linalg as la

from mako.template import Template

import pyopencl as cl


local_size = 256
thread_strides = 32
macroblock_count = 33
Expand Down
4 changes: 3 additions & 1 deletion examples/dump-properties.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pyopencl as cl
from optparse import OptionParser

import pyopencl as cl


parser = OptionParser()
parser.add_option("-s", "--short", action="store_true",
help="don't print all device properties")
Expand Down
4 changes: 3 additions & 1 deletion examples/gl_interop_demo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.raw.GL.VERSION.GL_1_5 import glBufferData as rawGlBufferData

import pyopencl as cl


Expand All @@ -23,8 +24,9 @@
def initialize():
platform = cl.get_platforms()[0]

from pyopencl.tools import get_gl_sharing_context_properties
import sys

from pyopencl.tools import get_gl_sharing_context_properties
if sys.platform == "darwin":
ctx = cl.Context(properties=get_gl_sharing_context_properties(),
devices=[])
Expand Down
12 changes: 6 additions & 6 deletions examples/gl_particle_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
import sys

import numpy as np

from OpenGL import GL, GLU, GLUT
from OpenGL.arrays import vbo
from OpenGL.GL import (GL_ARRAY_BUFFER, GL_BLEND, GL_COLOR_ARRAY,
GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT,
GL_DYNAMIC_DRAW, GL_FLOAT, GL_MODELVIEW,
GL_ONE_MINUS_SRC_ALPHA, GL_POINT_SMOOTH, GL_POINTS,
GL_PROJECTION, GL_SRC_ALPHA, GL_VERTEX_ARRAY)
from OpenGL.GL import (
GL_ARRAY_BUFFER, GL_BLEND, GL_COLOR_ARRAY, GL_COLOR_BUFFER_BIT,
GL_DEPTH_BUFFER_BIT, GL_DYNAMIC_DRAW, GL_FLOAT, GL_MODELVIEW,
GL_ONE_MINUS_SRC_ALPHA, GL_POINT_SMOOTH, GL_POINTS, GL_PROJECTION, GL_SRC_ALPHA,
GL_VERTEX_ARRAY)
from OpenGL.GLUT import GLUT_DEPTH, GLUT_DOUBLE, GLUT_RGBA

import pyopencl as cl
from pyopencl.tools import get_gl_sharing_context_properties


mf = cl.mem_flags

width = 800
Expand Down
1 change: 1 addition & 0 deletions examples/median-filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pyopencl as cl


# Read in image
img = imread("noisyImage.jpg").astype(np.float32)
print(img.shape)
Expand Down
4 changes: 3 additions & 1 deletion examples/narray.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# example by Roger Pau Monn'e
import pyopencl as cl
import numpy as np

import pyopencl as cl


demo_r = np.empty((500, 5), dtype=np.uint32)
ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)
Expand Down
Loading

0 comments on commit d9b82e1

Please sign in to comment.