Commit 31f2b698 authored by Daniel Boeckenhoff's avatar Daniel Boeckenhoff
Browse files

some python3 specifics

parent 9bc2a23f
......@@ -129,7 +129,12 @@ def cartesian_to_spherical(array):
# phi for phi between -pi, pi
problemPhiIndices = np.where((array[:, 0] < 0) & (array[:, 1] == 0))
with warnings.catch_warnings():
warnings.filterwarnings('ignore', message="invalid value encountered in divide")
# python2.7
warnings.filterwarnings('ignore',
message="invalid value encountered in divide")
# python3.x
warnings.filterwarnings('ignore',
message="invalid value encountered in true_divide")
array[:, 1] = np.sign(array[:, 1]) * np.arccos(array[:, 0] / np.sqrt(xy))
array[:, 1][problemPhiIndices] = np.pi
......
......@@ -183,7 +183,7 @@ class AbstractNdarray(np.ndarray):
inst = super(AbstractNdarray, self).copy(*args, **kwargs)
for attr in self._iter_slots():
value = getattr(self, attr)
if hasattr(value, 'copy'):
if hasattr(value, 'copy') and not isinstance(value, list):
setattr(inst, attr, value.copy(*args, **kwargs))
elif isinstance(value, list):
list_copy = []
......@@ -307,7 +307,7 @@ class AbstractNdarray(np.ndarray):
part_dict = part._as_dict()
for part_attr, part_value in part_dict.items():
d["{attr}::{i}::{part_attr}".format(**locals())] = part_value
continue
continue
if isinstance(value, AbstractNdarray):
value = value._as_dict()
d[attr] = value
......@@ -1763,9 +1763,7 @@ class TensorMaps(TensorFields):
keep_indices = indices[mask]
if isinstance(keep_indices, int):
keep_indices = [keep_indices]
delete_indices = set(indices).difference(set(keep_indices))
# delete_indices = indices[~mask]
# delete_indices = set(delete_indices) # set speeds up everything enormously
delete_indices = set(indices.flat).difference(set(keep_indices.flat))
masks = []
for mp_idx in range(len(self.maps)):
......@@ -1834,5 +1832,5 @@ class TensorMaps(TensorFields):
if __name__ == '__main__': # pragma: no cover
import doctest
doctest.testmod()
# doctest.run_docstring_examples(TensorFields.__getitem__, globals())
# doctest.run_docstring_examples(TensorMaps.cut, globals())
# doctest.run_docstring_examples(AbstractNdarray._save_npz, globals())
import numpy as np
import functools
def ensure_complex(*base_vectors):
......@@ -95,8 +96,8 @@ def igrid(*base_vectors, **kwargs):
else:
base_vectors = to_base_vectors(*base_vectors)
obj = np.empty(shape=(reduce(lambda x, y: x * y,
map(len, base_vectors)),
obj = np.empty(shape=(functools.reduce(lambda x, y: x * y,
map(len, base_vectors)),
len(base_vectors)))
def loop_rec(y, n_max, i=0, n=None, *vals):
......
......@@ -508,7 +508,7 @@ class Mesh3D(tfields.TensorMaps):
# new vertex
new_face.append(len(vertices))
vertices = np.append(vertices,
[map(float, item)],
[[float(x) for x in item]],
axis=0)
fields = [np.append(field,
np.full((1,) + field.shape[1:], np.nan),
......@@ -649,6 +649,7 @@ class Mesh3D(tfields.TensorMaps):
to redo the same cut fast
Examples:
define the cut
>>> import numpy as np
>>> import tfields
>>> from sympy.abc import x,y,z
>>> cutExpr = x > 1.5
......
......@@ -407,8 +407,12 @@ class Triangles3D(tfields.TensorFields):
# matrix vector product for matrices and vectors
barCoords = np.einsum('...ji,...i', self._baricentric_matrix, ap)
with warnings.catch_warnings():
# python2.7
warnings.filterwarnings('ignore', message="invalid value encountered in divide")
warnings.filterwarnings('ignore', message="divide by zero encountered in divide")
# python3.x
warnings.filterwarnings('ignore', message="invalid value encountered in true_divide")
warnings.filterwarnings('ignore', message="divide by zero encountered in true_divide")
barCoords[:, 2] /= delta # allow devide by 0.
return barCoords
......
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