Ejemplo n.º 1
0
    def test_repr(self):
        self.zeros = ConstantArray([10, 20, 40, 50])
        self.a = TransposedArray(self.zeros, [1, 3, 0, 2])

        expected = ("TransposedArray(<ConstantArray shape=(10, 20, 40, 50) "
                    "dtype=dtype('float64')>, [1, 3, 0, 2])")
        self.assertEqual(repr(self.a), expected)
Ejemplo n.º 2
0
class Test__apply_axes_mapping(unittest.TestCase):
    def setUp(self):
        self.zeros = ConstantArray([10, 20, 40, 50])
        self.a = TransposedArray(self.zeros, [1, 3, 0, 2])

    def test_too_few_dims(self):
        msg = 'length 3, but should be of length 4'
        with self.assertRaisesRegexp(ValueError, msg):
            self.a._apply_axes_mapping(list('abc'))

    def test_correct_n_dims(self):
        r = self.a._apply_axes_mapping(list('abcd'))
        self.assertEqual(r, ('b', 'd', 'a', 'c'))

    def test_inverse(self):
        r = self.a._apply_axes_mapping(list('bdac'), inverse=True)
        self.assertEqual(r, tuple('abcd'))

    def test_too_many_dims(self):
        msg = 'length 5, but should be of length 4'
        with self.assertRaisesRegexp(ValueError, msg):
            self.a._apply_axes_mapping(list('abcde'))
Ejemplo n.º 3
0
class Test__apply_axes_mapping(unittest.TestCase):
    def setUp(self):
        self.zeros = ConstantArray([10, 20, 40, 50])
        self.a = TransposedArray(self.zeros, [1, 3, 0, 2])

    def test_too_few_dims(self):
        msg = 'length 3, but should be of length 4'
        with six.assertRaisesRegex(self, ValueError, msg):
            self.a._apply_axes_mapping(list('abc'))

    def test_correct_n_dims(self):
        r = self.a._apply_axes_mapping(list('abcd'))
        self.assertEqual(r, ('b', 'd', 'a', 'c'))

    def test_inverse(self):
        r = self.a._apply_axes_mapping(list('bdac'), inverse=True)
        self.assertEqual(r, tuple('abcd'))

    def test_too_many_dims(self):
        msg = 'length 5, but should be of length 4'
        with six.assertRaisesRegex(self, ValueError, msg):
            self.a._apply_axes_mapping(list('abcde'))
Ejemplo n.º 4
0
 def setUp(self):
     self.zeros = ConstantArray([10, 20, 40, 50])
     self.a = TransposedArray(self.zeros, [1, 3, 0, 2])
Ejemplo n.º 5
0
 def setUp(self):
     self.orig_array = np.empty([5, 6, 4, 7])
     self.arr_transposed = self.orig_array.transpose([1, 3, 0, 2])
     self.a = TransposedArray(self.orig_array, [1, 3, 0, 2])
     self.expected_shape = (6, 7, 5, 4)
Ejemplo n.º 6
0
 def transposed_shape(self, shape, axes):
     return TransposedArray(ConstantArray(shape), axes).shape
Ejemplo n.º 7
0
 def setUp(self):
     self.zeros = ConstantArray([10, 20, 40, 50])
     self.a = TransposedArray(self.zeros, [1, 3, 0, 2])
Ejemplo n.º 8
0
 def test_axes_non_list(self):
     arr = TransposedArray(self.orig_array, tuple(self.a.axes))
     result = arr[:2, 0, :, np.newaxis, :]
     self.assertEqual(result.shape, (2, 5, 1, 4))