Beispiel #1
0
    def test(self):
        shape = (3, 5, 10)
        a = biggus.ConstantArray(shape, dtype=np.float32)
        b = biggus.ConstantArray(shape, dtype=np.float64)

        with set_chunk_size(32 // 8 * 10 - 1):
            result = biggus.sum(a * b, axis=0).ndarray()
            self.assertEqual(result.shape, shape[1:])
Beispiel #2
0
 def test_always_slices(self):
     array = biggus.ConstantArray((3, 5), dtype=np.float32)
     chunk_size = 5 - 1
     with set_chunk_size(chunk_size):
         slices = _all_slices_inner(array.shape, always_slices=True)
     expected = [[slice(0, 1, None), slice(1, 2, None), slice(2, 3, None)],
                 [slice(0, 4, None), slice(4, 5, None)]]
     self.assertEqual(slices, expected)
Beispiel #3
0
 def test_var_masked(self):
     data = biggus.ConstantArray((10, 400, 720), dtype=np.float32)
     v = biggus.var(data, axis=1)
     result = v.masked_array()
     self.assertIsInstance(result, np.ma.MaskedArray)
     self.assertEqual(result.shape, (10, 720))
     self.assertTrue(np.all(result == 0))
     self.assertTrue(np.all(result.mask == 0))
Beispiel #4
0
 def test(self):
     # If we switch evaluation engine, does it get used?
     array = biggus._Aggregation(biggus.ConstantArray(3, 2), None, None,
                                 None, None, {})
     return_value = (mock.sentinel.result, )
     engine = mock.Mock(**{'ndarrays.return_value': return_value})
     with mock.patch('biggus.engine', engine):
         result = array.ndarray()
     self.assertIs(result, mock.sentinel.result)
Beispiel #5
0
 def test_key_names(self):
     a = biggus.ConstantArray((2, 5))
     expr = biggus.mean(a + a, axis=1)
     graph = DaskEngine().graph(expr)
     func_names = {
         task[0].__name__
         for task in graph.values() if callable(task[0])
     }
     expected = {'gather', 'add', 'ConstantArray\n(2, 5)', 'mean\n(axis=1)'}
     self.assertEqual(expected, func_names)
Beispiel #6
0
 def test_all_cases(self):
     array = biggus.ConstantArray((4, 3, 5), dtype=np.float32)
     # Chunk size set to fit in two items from the second dimension into a
     # single chunk, but not the whole dimension.
     chunk_size = 5 * 3 - 1
     with set_chunk_size(chunk_size):
         slices = _all_slices(array)
     expected = [[0, 1, 2, 3],
                 [slice(0, 2, None), slice(2, 3, None)],
                 (slice(None, None, None),)]
     self.assertEqual(slices, expected)
Beispiel #7
0
 def test_repeat_arrays(self):
     a = biggus.ConstantArray((2, 5))
     expr = (a / 3.) + a - (a * 2)
     graph = DaskEngine().graph(expr)
     func_names = {
         task[0].__name__
         for task in graph.values() if callable(task[0])
     }
     expected = {
         'gather', 'add', 'subtract', 'true_divide', 'multiply',
         'ConstantArray\n(2, 5)', 'BroadcastArray\n(2, 5)'
     }
     self.assertEqual(expected, func_names)
Beispiel #8
0
 def test_sum_int(self):
     a = biggus.ConstantArray((1), dtype=np.int32)
     b = a + 1
     self.assertEqual('int32', b.dtype)
Beispiel #9
0
 def test_no_array_priority_attribute_present(self):
     arr = biggus.ConstantArray((3), 1.0)
     barr = biggus.NumpyArrayAdapter(arr)
     result = np.array([[1.]]) * barr
     target = np.array([[1.]]) * arr
     np.testing.assert_array_equal(result, target)