def test_repr_format(self): """Check representation of a transformed dimension.""" shape = (3, 4, 5) index = (0, 2, 1) t = View(shape=shape, index=index) assert t.repr_format( 1.0) == "View(shape=(3, 4, 5), index=(0, 2, 1), 1.0)"
def test_transform(self): """Check if it transforms properly.""" shape = (3, 4, 5) index = (0, 2, 1) t = View(shape=shape, index=index) a = numpy.zeros(shape) a[index] = 2 assert t.transform(a) == 2
def test_reverse(self): """Check if it reverses `transform` properly.""" shape = (3, 4, 5) index = (0, 2, 1) a = numpy.zeros(shape) a[index] = 2 flattened = a.reshape(-1).tolist() point = [None] + flattened + [None] t = View(shape=shape, index=(0, 0, 0)) numpy.testing.assert_equal(t.reverse(point, 1), a)
def rdims3(tdim3): """Create an example of integer `Dimension`.""" rdim3 = ReshapedDimension( transformer=View(tdim3.shape, (0,), tdim3.type), original_dimension=tdim3, name="yolo3[0]", index=2, ) return {tdim3.name: rdim3}
def rdims2(tdim2): """Create a categorical example of `ReshapedDimension`.""" transformations = {} for index in itertools.product(*map(range, tdim2.shape)): key = f'{tdim2.name}[{",".join(map(str, index))}]' transformations[key] = ReshapedDimension( transformer=View(tdim2.shape, index, tdim2.type), original_dimension=tdim2, name=key, index=1, ) return transformations
def test_first(self): """Test that views are correctly identified as first""" shape = (3, 4, 5) assert View(shape=shape, index=(0, 0, 0)).first assert not View(shape=shape, index=(0, 1, 0)).first
def test_domain_and_target_type(self): """Check if attribute-like `domain_type` and `target_type` do what's expected.""" t = View(shape=None, index=None, domain_type="some fancy type") assert t.domain_type == "some fancy type" assert t.target_type == "some fancy type"