Commit f32720cb authored by Daniel Böckenhoff (Laptop)'s avatar Daniel Böckenhoff (Laptop)
Browse files

tests run, copy constructor changed ot not return but use rest of __new__

parent 3bd4bb4e
......@@ -8,6 +8,7 @@ from tempfile import NamedTemporaryFile
import sympy # NOQA: F401
ATOL = 1e-8
class Base_Test(object):
"""
......@@ -26,15 +27,13 @@ class Base_Test(object):
Test coordinate transformations in circle
"""
transformer = self._inst.copy()
transformer.transform(tfields.bases.CYLINDER)
self.assertTrue(self._inst.equal(transformer))
self.assertTrue(self._inst.equal(transformer, atol=ATOL))
if len(self._inst) > 0:
self.assertFalse(np.array_equal(self._inst, transformer))
transformer.transform(tfields.bases.CARTESIAN)
self.assertTrue(self._inst.equal(transformer))
self.assertTrue(np.array_equal(self._inst, transformer))
self.assertTrue(self._inst.equal(transformer, atol=ATOL))
def test_spericalTrafo(self):
"""
......@@ -44,7 +43,7 @@ class Base_Test(object):
transformer.transform(tfields.bases.SPHERICAL)
transformer.transform(tfields.bases.CARTESIAN)
self.assertTrue(np.array_equal(self._inst, transformer))
self.assertTrue(self._inst.equal(transformer, atol=ATOL))
def test_basic_merge(self):
merge_list = [self._inst.copy() for i in range(3)]
......@@ -57,14 +56,16 @@ class Base_Test(object):
value = np.allclose(merge_list[0],
obj[i * len(self._inst): (i + 1) *
len(self._inst)],
atol=1e-8)
atol=ATOL)
self.assertTrue(value)
obj_cs = type(self._inst).merged(*merge_list, coordSys=tfields.bases.CYLINDER)
self.assertTrue(all(
[np.array_equal(merge_list[1],
obj_cs[i * len(self._inst): (i + 1) * len(self._inst)])
for i in range(len(merge_list))]))
for i in range(len(merge_list)):
value = np.allclose(merge_list[1],
obj_cs[i * len(self._inst): (i + 1) *
len(self._inst)],
atol=ATOL)
self.assertTrue(value)
def tearDown(self):
del self._inst
......
......@@ -29,7 +29,11 @@ def get_coord_system(base):
if isinstance(base, string_types):
base = getattr(tfields.bases, base)
if not isinstance(base, sympy.diffgeom.CoordSystem):
raise TypeError("Wrong type of coordSystem base.")
bse_tpe = type(base)
expctd_tpe = type(sympy.diffgeom.CoordSystem)
raise TypeError("Wrong type of coordSystem base {bse_tpe}. "
"Expected {expctd_tpe}"
.format(**locals()))
return base
......
......@@ -358,25 +358,18 @@ class Tensors(AbstractNdarray):
def __new__(cls, tensors, **kwargs):
dtype = kwargs.pop('dtype', np.float64)
order = kwargs.pop('order', None)
''' copy constructor '''
print type(tensors), cls, issubclass(type(tensors), cls)
if issubclass(type(tensors), cls) or issubclass(cls, type(tensors)):
obj = tensors.copy()
if dtype != obj.dtype or order is not None:
obj = obj.astype(dtype, order=order)
coordSys = kwargs.pop('coordSys', None)
if kwargs:
raise AttributeError("In copy constructor only 'dtype' and 'coordSys' "
"attribute is supported. Kwargs {kwargs} "
"are not consumed"
.format(**locals()))
if coordSys is not None:
obj.transform(coordSys)
return obj
dim = kwargs.pop('dim', None)
''' copy constructor extracts the kwargs from tensors'''
if issubclass(type(tensors), Tensors):
dtype = tensors.dtype
if dim is not None:
dim = tensors.dim
coordSys = kwargs.pop('coordSys', tensors.coordSys)
tensors = tensors.copy()
tensors.transform(coordSys)
kwargs['coordSys'] = coordSys
''' demand iterable structure '''
try:
len(tensors)
......@@ -447,6 +440,7 @@ class Tensors(AbstractNdarray):
... [4, 2, 3],
... [2, 0, 1]])
Merge also shifts the maps to still refer to the same tensors
>>> tm_a = tfields.TensorMaps(merge, maps=[[[0, 1, 2]]])
>>> tm_b = tm_a.copy()
>>> tm_a.coordSys
......@@ -610,29 +604,29 @@ class Tensors(AbstractNdarray):
CARTESIAN to CYLINDER
>>> tCart = tfields.Tensors([[3, 4, 42], [1, 0, 0], [0, 1, -1], [-1, 0, 1], [0, 0, 0]])
>>> tCyl = tCart.copy()
>>> tCyl.transform('cylinder')
>>> assert tCyl.coordSys == 'cylinder'
>>> t_cyl = tCart.copy()
>>> t_cyl.transform('cylinder')
>>> assert t_cyl.coordSys == 'cylinder'
R
>>> assert tCyl[0, 0] == 5
>>> assert tCyl[1, 0] == 1
>>> assert tCyl[2, 0] == 1
>>> assert tCyl[4, 0] == 0
>>> assert t_cyl[0, 0] == 5
>>> assert t_cyl[1, 0] == 1
>>> assert t_cyl[2, 0] == 1
>>> assert t_cyl[4, 0] == 0
Phi
>>> assert round(tCyl[0, 1], 10) == round(np.arctan(4. / 3), 10)
>>> assert tCyl[1, 1] == 0
>>> assert round(tCyl[2, 1], 10) == round(np.pi / 2, 10)
>>> assert tCyl[1, 1] == 0
>>> assert round(t_cyl[0, 1], 10) == round(np.arctan(4. / 3), 10)
>>> assert t_cyl[1, 1] == 0
>>> assert round(t_cyl[2, 1], 10) == round(np.pi / 2, 10)
>>> assert t_cyl[1, 1] == 0
Z
>>> assert tCyl[0, 2] == 42
>>> assert tCyl[2, 2] == -1
>>> assert t_cyl[0, 2] == 42
>>> assert t_cyl[2, 2] == -1
>>> tCyl.transform('cartesian')
>>> assert tCyl.coordSys == 'cartesian'
>>> assert tCyl[0, 0] == 3
>>> t_cyl.transform('cartesian')
>>> assert t_cyl.coordSys == 'cartesian'
>>> assert t_cyl[0, 0] == 3
"""
# scalars empty already there
......@@ -1228,9 +1222,7 @@ class TensorMaps(TensorFields):
Copying takes care of coordSys
>>> mesh_copy.transform(tfields.bases.CYLINDER)
>>> mesh_copy.coordSys
>>> mesh_cp_cyl = TensorMaps(mesh_copy)
>>> mesh_cp_cyl.coordSys
>>> mesh_cp_cyl = tfields.TensorMaps(mesh_copy)
>>> assert mesh_cp_cyl.coordSys == tfields.bases.CYLINDER
Raises:
......
Supports Markdown
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