Пример #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)
Пример #2
0
 def test_multidim_stack_multidim(self):
     # Multidim stack of arrays shape (4, 6)
     arrays = np.array([[ConstantArray((), i) for i in range(6)]
                        for i in range(4)])
     msg = 'multidimensional stacks not yet supported'
     with self.assertRaisesRegexp(ValueError, msg):
         ArrayStack.multidim_array_stack(arrays, (3, 2, 4))
Пример #3
0
 def test_values(self):
     shape = (3, 4, 5)
     value = 81
     array = ConstantArray(shape, value)
     result = array.ndarray()
     expected = np.empty(shape)
     expected[()] = value
     np.testing.assert_array_equal(result, expected)
Пример #4
0
 def test_have_enough_memory(self):
     # Using np.broadcast results in the actual data needing to be
     # realised. The code gets around this by using strides = 0.
     # Pick an array size which isn't realistic to realise in a
     # full array.
     a = ConstantArray([int(10 ** i) for i in range(4, 12)])
     self.assertEqual(BroadcastArray._compute_broadcast_kwargs(a.shape,
                                                               a.shape)[0],
                      tuple(int(10 ** i) for i in range(4, 12)),
                      )
Пример #5
0
 def test_shape_tuple_like_int(self):
     array = ConstantArray(('34', '93'))
     self.assertEqual(array.shape, (34, 93))
Пример #6
0
 def test_shape_tuple(self):
     shape = (30, 10, 20)
     array = ConstantArray(shape)
     self.assertEqual(array.shape, shape)
Пример #7
0
 def test_shape_scalar_like_int(self):
     array = ConstantArray('34')
     self.assertEqual(array.shape, (34,))
Пример #8
0
 def transposed_shape(self, shape, axes):
     return TransposedArray(ConstantArray(shape), axes).shape
Пример #9
0
 def test_shape_scalar(self):
     shape = 5
     array = ConstantArray(shape)
     self.assertEqual(array.shape, (shape,))
Пример #10
0
 def test_value(self):
     value = 6
     array = ConstantArray(3, value)
     self.assertEqual(array.value, value)
Пример #11
0
 def test_too_many_axes(self):
     in_arr = ConstantArray([3, 2])
     msg = 'must have length 3 but was actually length 4'
     with self.assertRaisesRegexp(ValueError, msg):
         array = NewAxesArray(in_arr, [1, 2, 0, 1])
Пример #12
0
 def test_right_only_new_axes(self):
     in_arr = ConstantArray([3, 2])
     array = NewAxesArray(in_arr, [0, 0, 2])
     self.assertEqual(array.shape, (3, 2, 1, 1))
Пример #13
0
 def test_dtype_default(self):
     array = ConstantArray(())
     self.assertEqual(array.dtype, np.dtype('f8'))
Пример #14
0
 def test_many_new_axes(self):
     in_arr = ConstantArray([3, 2])
     array = NewAxesArray(in_arr, [3, 1, 2])
     self.assertEqual(array.shape, (1, 1, 1, 3, 1, 2, 1, 1))
Пример #15
0
 def test_left_only_new_axes(self):
     in_arr = ConstantArray([3, 2])
     array = NewAxesArray(in_arr, [1, 0, 0])
     self.assertEqual(array.shape, (1, 3, 2))
Пример #16
0
 def test_no_new_axes(self):
     in_arr = ConstantArray([3, 1])
     array = NewAxesArray(in_arr, [0, 0, 0])
     self.assertEqual(array.shape, (3, 1))
Пример #17
0
 def test_successful_attribute(self):
     in_arr = ConstantArray([3, 1])
     array = NewAxesArray(in_arr, [2, 0, 4])
     self.assertIs(array.array, in_arr)
     self.assertIsInstance(array._new_axes, np.ndarray)
     self.assertEqual(list(array._new_axes), [2, 0, 4])
Пример #18
0
 def test_new_axes_negative(self):
     in_arr = ConstantArray([1, 2])
     msg = 'Only positive integer types may be used for new_axes.'
     with self.assertRaisesRegexp(ValueError, msg):
         array = NewAxesArray(in_arr, [-1, 0, 1])
Пример #19
0
 def test_shape_invalid_scalar(self):
     with self.assertRaises(ValueError):
         array = ConstantArray('foo')
Пример #20
0
 def test_indexing_slice(self):
     shape = (30, 10, 20)
     array = ConstantArray(shape)
     result = array[:5]
     data = np.zeros(shape)[:5]
     self.assertEqual(result.shape, data.shape)
Пример #21
0
 def test_shape_invalid_tuple(self):
     with self.assertRaises(ValueError):
         array = ConstantArray(('foo', 'bar'))
Пример #22
0
 def test_masked(self):
     shape = (3, 4, 5)
     array = ConstantArray(shape)
     result = array.masked_array()
     self.assertTrue(np.ma.isMaskedArray(result))
Пример #23
0
 def test_dtype(self):
     dtype = 'i2'
     array = ConstantArray((), dtype=dtype)
     self.assertIs(array.dtype, np.dtype(dtype))
Пример #24
0
 def assert_newaxis_keys(self, shape, new_axes, expected):
     in_arr = ConstantArray(shape)
     array = NewAxesArray(in_arr, new_axes)
     keys = array._newaxis_keys()
     self.assertEqual(keys, expected)
Пример #25
0
 def test_dtype_default_integer(self):
     array = ConstantArray((), 42)
     self.assertEqual(array.dtype, np.dtype(np.int_))
Пример #26
0
 def test_values_default(self):
     shape = (3, 4, 5)
     array = ConstantArray(shape)
     result = array.ndarray()
     np.testing.assert_array_equal(result, np.zeros(shape))
Пример #27
0
 def test_newaxis(self):
     array = ConstantArray([2, 3])
     result = array[:5, np.newaxis]
     self.assertEqual(result.shape, (2, 1, 3))
Пример #28
0
 def test_dtype(self):
     shape = (3, 4, 5)
     array = ConstantArray(shape, dtype='i4')
     result = array.ndarray()
     self.assertEqual(result.dtype, np.dtype('i4'))
Пример #29
0
 def test_values(self):
     shape = (3, 4, 5)
     array = ConstantArray(shape)
     result = array.masked_array()
     np.testing.assert_array_equal(result, np.ma.zeros(shape))
Пример #30
0
 def test_dtype_default(self):
     shape = (3, 4, 5)
     array = ConstantArray(shape)
     result = array.ndarray()
     self.assertEqual(result.dtype, np.dtype('f8'))