示例#1
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)
示例#2
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)
示例#3
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)
示例#4
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))
示例#5
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)),
                      )
示例#6
0
 def test_value(self):
     value = 6
     array = ConstantArray(3, value)
     self.assertEqual(array.value, value)
示例#7
0
 def test_shape_invalid_scalar(self):
     with self.assertRaises(ValueError):
         array = ConstantArray('foo')
示例#8
0
 def test_shape_scalar_like_int(self):
     array = ConstantArray('34')
     self.assertEqual(array.shape, (34,))
示例#9
0
 def test_shape_scalar(self):
     shape = 5
     array = ConstantArray(shape)
     self.assertEqual(array.shape, (shape,))
示例#10
0
 def test_dtype(self):
     shape = (3, 4, 5)
     array = ConstantArray(shape, dtype='i4')
     result = array.ndarray()
     self.assertEqual(result.dtype, np.dtype('i4'))
示例#11
0
 def test_masked(self):
     shape = (3, 4, 5)
     array = ConstantArray(shape)
     result = array.masked_array()
     self.assertTrue(np.ma.isMaskedArray(result))
示例#12
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))
示例#13
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))
示例#14
0
 def transposed_shape(self, shape, axes):
     return TransposedArray(ConstantArray(shape), axes).shape
示例#15
0
 def test_dtype_default(self):
     array = ConstantArray(())
     self.assertEqual(array.dtype, np.dtype('f8'))
示例#16
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)
示例#17
0
 def test_dtype(self):
     shape = (3, 4, 5)
     array = ConstantArray(shape, dtype="i4")
     result = array.ndarray()
     self.assertEqual(result.dtype, np.dtype("i4"))
示例#18
0
 def test_dtype(self):
     shape = (3, 4, 5)
     array = ConstantArray(shape, dtype='i4')
     result = array.masked_array()
     self.assertEqual(result.dtype, np.dtype('i4'))
示例#19
0
 def test_dtype_default(self):
     shape = (3, 4, 5)
     array = ConstantArray(shape)
     result = array.ndarray()
     self.assertEqual(result.dtype, np.dtype("f8"))
示例#20
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))
示例#21
0
 def test_masked(self):
     shape = (3, 4, 5)
     array = ConstantArray(shape)
     result = array.masked_array()
     self.assertTrue(np.ma.isMaskedArray(result))
示例#22
0
 def test_dtype_default(self):
     shape = (3, 4, 5)
     array = ConstantArray(shape)
     result = array.ndarray()
     self.assertEqual(result.dtype, np.dtype('f8'))
示例#23
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)
示例#24
0
 def test_shape_tuple(self):
     shape = (30, 10, 20)
     array = ConstantArray(shape)
     self.assertEqual(array.shape, shape)
示例#25
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])
示例#26
0
 def test_shape_tuple_like_int(self):
     array = ConstantArray(('34', '93'))
     self.assertEqual(array.shape, (34, 93))
示例#27
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])
示例#28
0
 def test_shape_invalid_tuple(self):
     with self.assertRaises(ValueError):
         array = ConstantArray(('foo', 'bar'))
示例#29
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])
示例#30
0
 def test_dtype(self):
     dtype = 'i2'
     array = ConstantArray((), dtype=dtype)
     self.assertIs(array.dtype, np.dtype(dtype))
示例#31
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))
示例#32
0
 def test_dtype_default_integer(self):
     array = ConstantArray((), 42)
     self.assertEqual(array.dtype, np.dtype(np.int_))
示例#33
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))
示例#34
0
 def test_newaxis(self):
     array = ConstantArray([2, 3])
     result = array[:5, np.newaxis]
     self.assertEqual(result.shape, (2, 1, 3))
示例#35
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))
示例#36
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))
示例#37
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))