Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #157 from firedrakeproject/desix
Browse files Browse the repository at this point in the history
Remove Python 2 compatibility
  • Loading branch information
miklos1 authored Dec 11, 2017
2 parents d1f93d9 + f7bded1 commit 3869116
Show file tree
Hide file tree
Showing 52 changed files with 37 additions and 164 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ notifications:

language: python
python:
- "2.7"
- "3.5"

before_install:
- pip install -r requirements.txt
- pip install flake8
- pip install flake8-future-import
- pip install --upgrade pytest

install:
Expand Down
2 changes: 0 additions & 2 deletions gem/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
from __future__ import absolute_import, print_function, division

from gem.gem import * # noqa
from gem.optimise import select_expression # noqa
3 changes: 0 additions & 3 deletions gem/coffee.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
This file is NOT for code generation as a COFFEE AST.
"""

from __future__ import absolute_import, print_function, division
from six.moves import map, range

from collections import OrderedDict
import itertools
import logging
Expand Down
8 changes: 2 additions & 6 deletions gem/gem.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
indices.
"""

from __future__ import absolute_import, print_function, division
from six import with_metaclass
from six.moves import range, zip

from abc import ABCMeta
from itertools import chain
from operator import attrgetter
Expand Down Expand Up @@ -57,7 +53,7 @@ def __call__(self, *args, **kwargs):
return obj


class Node(with_metaclass(NodeMeta, NodeBase)):
class Node(NodeBase, metaclass=NodeMeta):
"""Abstract GEM node class."""

__slots__ = ('free_indices',)
Expand Down Expand Up @@ -380,7 +376,7 @@ def __new__(cls, condition, then, else_):
return self


class IndexBase(with_metaclass(ABCMeta)):
class IndexBase(metaclass=ABCMeta):
"""Abstract base class for indices."""
pass

Expand Down
5 changes: 1 addition & 4 deletions gem/impero.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
(Command?) after clicking on them.
"""

from __future__ import absolute_import, print_function, division
from six import with_metaclass

from abc import ABCMeta, abstractmethod

from gem.node import Node as NodeBase
Expand All @@ -24,7 +21,7 @@ class Node(NodeBase):
__slots__ = ()


class Terminal(with_metaclass(ABCMeta, Node)):
class Terminal(Node, metaclass=ABCMeta):
"""Abstract class for terminal Impero nodes"""

__slots__ = ()
Expand Down
6 changes: 1 addition & 5 deletions gem/impero_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@
C code or a COFFEE AST.
"""

from __future__ import absolute_import, print_function, division
from six.moves import filter

import collections
from functools import singledispatch
from itertools import chain, groupby

from singledispatch import singledispatch

from gem.node import traversal, collect_refcount
from gem import gem, impero as imp, optimise, scheduling

Expand Down
5 changes: 1 addition & 4 deletions gem/interpreter.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
"""
An interpreter for GEM trees.
"""
from __future__ import absolute_import, print_function, division
from six.moves import map

import numpy
import operator
import math
from collections import OrderedDict
from singledispatch import singledispatch
from functools import singledispatch
import itertools

from gem import gem, node
Expand Down
3 changes: 0 additions & 3 deletions gem/node.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"""Generic abstract node class and utility functions for creating
expression DAG languages."""

from __future__ import absolute_import, print_function, division
from six.moves import map, zip

import collections


Expand Down
8 changes: 2 additions & 6 deletions gem/optimise.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
"""A set of routines implementing various transformations on GEM
expressions."""

from __future__ import absolute_import, print_function, division
from six.moves import filter, map, zip, zip_longest

from collections import OrderedDict, defaultdict
from functools import partial, reduce
from itertools import combinations, permutations
from functools import singledispatch, partial, reduce
from itertools import combinations, permutations, zip_longest

import numpy
from singledispatch import singledispatch

from gem.utils import groupby
from gem.node import (Memoizer, MemoizerArg, reuse_if_untouched,
Expand Down
13 changes: 5 additions & 8 deletions gem/refactorise.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
"""Data structures and algorithms for generic expansion and
refactorisation."""

from __future__ import absolute_import, print_function, division
from six import iteritems
from six.moves import intern, map

from collections import Counter, OrderedDict, defaultdict, namedtuple
from itertools import product
from sys import intern

from gem.node import Memoizer, traversal
from gem.gem import Node, Zero, Product, Sum, Indexed, ListTensor, one
Expand Down Expand Up @@ -73,7 +70,7 @@ def add(self, sum_indices, atomics, rest):
assert len(sum_indices) == len(sum_indices_set)

atomics = tuple(atomics)
atomics_set = frozenset(iteritems(Counter(atomics)))
atomics_set = frozenset(Counter(atomics).items())

assert isinstance(rest, Node)

Expand All @@ -83,7 +80,7 @@ def add(self, sum_indices, atomics, rest):

def __iter__(self):
"""Iteration yields :py:class:`Monomial` objects"""
for key, (sum_indices, atomics) in iteritems(self.ordering):
for key, (sum_indices, atomics) in self.ordering.items():
rest = self.monomials[key]
yield Monomial(sum_indices, atomics, rest)

Expand All @@ -95,9 +92,9 @@ def sum(*args):
assert isinstance(arg, MonomialSum)
# Optimised implementation: no need to decompose and
# reconstruct key.
for key, rest in iteritems(arg.monomials):
for key, rest in arg.monomials.items():
result.monomials[key] = Sum(result.monomials[key], rest)
for key, value in iteritems(arg.ordering):
for key, value in arg.ordering.items():
result.ordering.setdefault(key, value)
return result

Expand Down
2 changes: 0 additions & 2 deletions gem/scheduling.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""Schedules operations to evaluate a multi-root expression DAG,
forming an ordered list of Impero terminals."""

from __future__ import absolute_import, print_function, division

import collections
import functools

Expand Down
5 changes: 1 addition & 4 deletions gem/unconcatenate.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,10 @@
unconcatenation, and then add up the results.
"""

from __future__ import absolute_import, print_function, division
from six.moves import map, range, zip

from functools import singledispatch
from itertools import chain

import numpy
from singledispatch import singledispatch

from gem.node import Memoizer, reuse_if_untouched
from gem.gem import (ComponentTensor, Concatenate, FlexiblyIndexed,
Expand Down
5 changes: 1 addition & 4 deletions gem/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import absolute_import, print_function, division
from six import viewitems

import collections


Expand Down Expand Up @@ -36,7 +33,7 @@ def groupby(iterable, key=None):
groups = collections.OrderedDict()
for elem in iterable:
groups.setdefault(key(elem), []).append(elem)
return viewitems(groups)
return groups.items()


def make_proxy_class(name, cls):
Expand Down
2 changes: 0 additions & 2 deletions requirements-ext.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
numpy
singledispatch
six
6 changes: 1 addition & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
[flake8]
ignore =
E501,E226,E731,E741,
FI14,FI54,
FI50,FI51,FI53
ignore = E501,E226,E731,E741
exclude = .git,__pycache__,build,dist
min-version = 2.7
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function, division, absolute_import

from distutils.core import setup

version = "0.0.1"
Expand Down
2 changes: 0 additions & 2 deletions tests/test_codegen.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, print_function, division

import pytest

from gem import impero_utils
Expand Down
2 changes: 0 additions & 2 deletions tests/test_coffee_optimise.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, print_function, division

import pytest

from gem.gem import Index, Indexed, Product, Variable, Division, Literal, Sum
Expand Down
1 change: 0 additions & 1 deletion tests/test_create_fiat_element.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import, print_function, division
import pytest

import FIAT
Expand Down
1 change: 0 additions & 1 deletion tests/test_create_finat_element.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import, print_function, division
import pytest

import ufl
Expand Down
2 changes: 0 additions & 2 deletions tests/test_delta_elimination.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, print_function, division

import pytest

from gem.gem import Delta, Identity, Index, Indexed, one
Expand Down
1 change: 0 additions & 1 deletion tests/test_estimated_degree.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import, print_function, division
import logging

import pytest
Expand Down
1 change: 0 additions & 1 deletion tests/test_firedrake_972.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import, print_function, division
import numpy
import pytest

Expand Down
3 changes: 0 additions & 3 deletions tests/test_flexibly_indexed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import absolute_import, print_function, division
from six.moves import range

from itertools import product

import numpy
Expand Down
1 change: 0 additions & 1 deletion tests/test_gem_failure.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import, print_function, division
from ufl import (triangle, tetrahedron, FiniteElement,
TrialFunction, TestFunction, inner, grad, dx, dS)
from tsfc import compile_form
Expand Down
2 changes: 0 additions & 2 deletions tests/test_geometry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, print_function, division

import pytest
import numpy as np

Expand Down
1 change: 0 additions & 1 deletion tests/test_idempotency.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import, print_function, division
import ufl
from tsfc import compile_form
import pytest
Expand Down
3 changes: 1 addition & 2 deletions tests/test_pickle_gem.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from __future__ import absolute_import, print_function, division
from six.moves import cPickle as pickle, range
import pickle
import gem
import numpy
import pytest
Expand Down
2 changes: 0 additions & 2 deletions tests/test_refactorise.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, print_function, division

from functools import partial

import pytest
Expand Down
2 changes: 0 additions & 2 deletions tests/test_simplification.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, print_function, division

import pytest

from gem.gem import Variable, Zero, Conditional, \
Expand Down
3 changes: 0 additions & 3 deletions tests/test_sum_factorisation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import absolute_import, print_function, division
from six.moves import range

import numpy
import pytest

Expand Down
2 changes: 0 additions & 2 deletions tests/test_tensor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, print_function, division

import numpy
import pytest

Expand Down
3 changes: 0 additions & 3 deletions tests/test_underintegration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import absolute_import, print_function, division
from six.moves import range

from functools import reduce

import numpy
Expand Down
2 changes: 0 additions & 2 deletions tsfc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, print_function, division

from tsfc.driver import compile_form, compile_expression_at_points # noqa: F401
from tsfc.parameters import default_parameters # noqa: F401

Expand Down
5 changes: 1 addition & 4 deletions tsfc/coffee.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
This is the final stage of code generation in TSFC."""

from __future__ import absolute_import, print_function, division

from collections import defaultdict
from functools import reduce
from functools import singledispatch, reduce
from math import isnan
import itertools

import numpy
from singledispatch import singledispatch

import coffee.base as coffee

Expand Down
3 changes: 0 additions & 3 deletions tsfc/coffee_mode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import absolute_import, print_function, division
from six.moves import zip

from functools import partial, reduce

from gem.node import traversal
Expand Down
12 changes: 4 additions & 8 deletions tsfc/driver.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
from __future__ import absolute_import, print_function, division
from six import iterkeys, iteritems, viewitems
from six.moves import range, zip

import collections
import operator
import string
Expand Down Expand Up @@ -186,8 +182,8 @@ def compile_integral(integral_data, form_data, prefix, parameters,

# Finalise mode representations into a set of assignments
assignments = []
for mode, var_reps in iteritems(mode_irs):
assignments.extend(mode.flatten(viewitems(var_reps), index_cache))
for mode, var_reps in mode_irs.items():
assignments.extend(mode.flatten(var_reps.items(), index_cache))

if assignments:
return_variables, expressions = zip(*assignments)
Expand All @@ -197,8 +193,8 @@ def compile_integral(integral_data, form_data, prefix, parameters,

# Need optimised roots for COFFEE
options = dict(reduce(operator.and_,
[viewitems(mode.finalise_options)
for mode in iterkeys(mode_irs)]))
[mode.finalise_options.items()
for mode in mode_irs.keys()]))
expressions = impero_utils.preprocess_gem(expressions, **options)
assignments = list(zip(return_variables, expressions))

Expand Down
Loading

0 comments on commit 3869116

Please sign in to comment.