def test_staggered_format_conversion(self): tensor = math.zeros([1, 5, 5, 2]) tensor[:, 0, 0, :] = 1 components = unstack_staggered_tensor(tensor) self.assertEqual(len(components), 2) np.testing.assert_equal(components[0].shape, [1, 5, 4, 1]) np.testing.assert_equal(components[1].shape, [1, 4, 5, 1]) tensor2 = stack_staggered_components(components) np.testing.assert_equal(tensor, tensor2)
def test_staggered_construction(self): # pylint: disable-msg = unsubscriptable-object tensor = math.zeros([1, 5, 5, 2]) staggered = StaggeredGrid(tensor, name='') assert len(staggered.data) == 2 assert isinstance(staggered.data[0], CenteredGrid) assert staggered.data[0].component_count == 1 np.testing.assert_equal(staggered.data[0].box.lower, [-0.5, 0]) staggered2 = StaggeredGrid(unstack_staggered_tensor(tensor), name='') struct.print_differences(staggered, staggered2) self.assertEqual(staggered, staggered2) staggered3 = StaggeredGrid([staggered.data[0], staggered2.data[1]], name='') self.assertEqual(staggered3, staggered)