예제 #1
0
 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)"
예제 #2
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
예제 #3
0
 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)
예제 #4
0
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}
예제 #5
0
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
예제 #6
0
 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
예제 #7
0
 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"