Commit 2126ef50 authored by Theo Steininger's avatar Theo Steininger

Added Python3 compatibility

parent 083f6433
Pipeline #11937 failed with stage
in 5 minutes and 6 seconds
......@@ -17,13 +17,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import division
from __future__ import absolute_import
from version import __version__
from .version import __version__
from config import configuration
from distributed_data_object import distributed_data_object
from d2o_librarian import d2o_librarian
from .config import configuration
from .distributed_data_object import distributed_data_object
from .d2o_librarian import d2o_librarian
from strategies import STRATEGIES
from .strategies import STRATEGIES
from factory_methods import *
from .factory_methods import *
from __future__ import absolute_import
# D2O
# Copyright (C) 2016 Theo Steininger
#
......@@ -16,5 +17,5 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from d2o_config import dependency_injector,\
from .d2o_config import dependency_injector,\
configuration
......@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from builtins import object
import numpy as np
......@@ -29,7 +30,7 @@ class d2o_iter(object):
def __iter__(self):
return self
def next(self):
def __next__(self):
if self.n == 0:
raise StopIteration()
......
......@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from builtins import object
from weakref import WeakValueDictionary as weakdict
......
from __future__ import division
from __future__ import absolute_import
# D2O
# Copyright (C) 2016 Theo Steininger
#
......@@ -23,10 +25,10 @@ from keepers import Versionable,\
from d2o.config import configuration as gc,\
dependency_injector as gdi
from d2o_librarian import d2o_librarian
from cast_axis_to_tuple import cast_axis_to_tuple
from .d2o_librarian import d2o_librarian
from .cast_axis_to_tuple import cast_axis_to_tuple
from strategies import STRATEGIES
from .strategies import STRATEGIES
MPI = gdi[gc['mpi_module']]
......@@ -174,7 +176,7 @@ class distributed_data_object(Loggable, Versionable, object):
if distribution_strategy is None:
distribution_strategy = gc['default_distribution_strategy']
from distributor_factory import distributor_factory
from .distributor_factory import distributor_factory
self.distributor = distributor_factory.get_distributor(
distribution_strategy=distribution_strategy,
comm=comm,
......@@ -263,7 +265,7 @@ class distributed_data_object(Loggable, Versionable, object):
# repair its class
new_copy.__class__ = self.__class__
# now copy everthing in the __dict__ except for the data array
for key, value in self.__dict__.items():
for key, value in list(self.__dict__.items()):
if key != 'data':
new_copy.__dict__[key] = value
else:
......@@ -837,7 +839,7 @@ class distributed_data_object(Loggable, Versionable, object):
_builtin_helper
"""
return self.__div__(other)
return self._builtin_helper('__truediv__', other)
def __rdiv__(self, other):
""" x.__rdiv__(y) <==> y/x
......@@ -857,7 +859,7 @@ class distributed_data_object(Loggable, Versionable, object):
_builtin_helper
"""
return self.__rdiv__(other)
return self._builtin_helper('__rtruediv__', other)
def __idiv__(self, other):
""" x.__idiv__(y) <==> x/=y
......@@ -879,7 +881,9 @@ class distributed_data_object(Loggable, Versionable, object):
_builtin_helper
"""
return self.__idiv__(other)
return self._builtin_helper('__itruediv__',
other,
inplace=True)
def __floordiv__(self, other):
""" x.__floordiv__(y) <==> x//y
......@@ -1472,7 +1476,10 @@ class distributed_data_object(Loggable, Versionable, object):
if axis is ():
return self.copy()
if minlength is not None:
length = max(self.amax() + 1, minlength)
else:
length = self.amax() + 1
return self.distributor.bincount(obj=self,
length=length,
......
This diff is collapsed.
......@@ -16,6 +16,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from builtins import map
from builtins import object
import numpy as np
from d2o.config import configuration as gc,\
......@@ -54,15 +56,17 @@ class _dtype_converter(object):
[np.dtype('complex128'), MPI.DOUBLE_COMPLEX]]
to_mpi_pre_dict = np.array(pre_dict)
to_mpi_pre_dict[:, 0] = map(self.dictionize_np, to_mpi_pre_dict[:, 0])
to_mpi_pre_dict[:, 0] = list(map(self.dictionize_np,
to_mpi_pre_dict[:, 0]))
self._to_mpi_dict = dict(to_mpi_pre_dict)
to_np_pre_dict = np.array(pre_dict)[:, ::-1]
to_np_pre_dict[:, 0] = map(self.dictionize_mpi, to_np_pre_dict[:, 0])
to_np_pre_dict[:, 0] = list(map(self.dictionize_mpi,
to_np_pre_dict[:, 0]))
self._to_np_dict = dict(to_np_pre_dict)
def dictionize_np(self, x):
dic = x.type.__dict__.items()
dic = list(x.type.__dict__.items())
if x.type is np.float:
dic[24] = 0
dic[29] = 0
......
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import numpy as np
from d2o.config import configuration as gc
from distributed_data_object import distributed_data_object
from .distributed_data_object import distributed_data_object
from strategies import STRATEGIES
from .strategies import STRATEGIES
__all__ = ['arange']
......
......@@ -16,6 +16,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from builtins import next
from builtins import range
import itertools
......@@ -52,7 +54,7 @@ def slicing_generator(shape, axes):
raise ValueError("ERROR: axes(axis) does not match shape.")
axes_select = [0 if x in axes else 1 for x, y in enumerate(shape)]
axes_iterables =\
[range(y) for x, y in enumerate(shape) if x not in axes]
[list(range(y)) for x, y in enumerate(shape) if x not in axes]
for current_index in itertools.product(*axes_iterables):
it_iter = iter(current_index)
slice_list = [next(it_iter) if use_axis else
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment