Ejemplo n.º 1
0
    def test_axis(self):
        """ Test that isum(axis = 0) yields 0d arrays """
        source = [np.zeros((16,), dtype=np.float) for _ in range(10)]

        with self.subTest("axis = 0"):
            summed = last(isum(source, axis=0))
            self.assertTrue(np.allclose(summed, np.zeros_like(summed)))

        with self.subTest("axis = None"):
            summed = last(isum(source, axis=None))
            self.assertTrue(np.allclose(summed, 0))
Ejemplo n.º 2
0
    def test_glob(self):
        """ Test that pload works on glob-like patterns """
        with self.subTest("processes = 1"):
            stream = pload("tests\\data\\test_data*.npy", load_func=np.load)
            s = last(isum(stream)).astype(
                np.float)  # Cast to float for np.allclose
            self.assertTrue(np.allclose(s, np.zeros_like(s)))

        with self.subTest("processes = 2"):
            stream = pload("tests\\data\\test_data*.npy",
                           load_func=np.load,
                           processes=2)
            s = last(isum(stream)).astype(
                np.float)  # Cast to float for np.allclose
            self.assertTrue(np.allclose(s, np.zeros_like(s)))
Ejemplo n.º 3
0
    def test_return_shape(self):
        """ Test that the shape of output is as expected """
        source = [np.zeros((16,), dtype=np.float) for _ in range(10)]

        with self.subTest("axis = 0"):
            summed = last(isum(source, axis=0))
            self.assertSequenceEqual(summed.shape, (1, 10))
Ejemplo n.º 4
0
    def test_against_numpy(self):
        """ Test that isum() returns the same as numpy.sum() for various axis inputs """

        stream = [np.random.random((16, 16)) for _ in range(10)]
        stack = np.dstack(stream)

        for axis in (0, 1, 2, None):
            with self.subTest("axis = {}".format(axis)):
                from_numpy = np.sum(stack, axis=axis)
                from_isum = last(isum(stream, axis=axis))
                self.assertTrue(np.allclose(from_isum, from_numpy))
Ejemplo n.º 5
0
 def test_file_list(self):
     """ Test that iload works on iterable of filenames """
     files = [
         "tests\\data\\test_data1.npy",
         "tests\\data\\test_data2.npy",
         "tests\\data\\test_data3.npy",
     ]
     stream = iload(files, load_func=np.load)
     s = last(isum(stream)).astype(
         np.float)  # Cast to float for np.allclose
     self.assertTrue(np.allclose(s, np.zeros_like(s)))
Ejemplo n.º 6
0
 def test_dtype(self):
     """ Test a sum of floating zeros with an int accumulator """
     source = [np.zeros((16,), dtype=np.float) for _ in range(10)]
     summed = last(isum(source, dtype=np.int))
     self.assertTrue(np.allclose(summed, np.zeros_like(summed)))
     self.assertEqual(summed.dtype, np.int)
Ejemplo n.º 7
0
 def test_length(self):
     """ Test that the number of yielded elements is the same as source """
     source = [np.zeros((16,), dtype=np.float) for _ in range(10)]
     summed = list(isum(source, axis=0))
     self.assertEqual(10, len(summed))
Ejemplo n.º 8
0
 def test_ignore_nans(self):
     """ Test a sum of zeros with NaNs sprinkled """
     source = [np.zeros((16,), dtype=np.float) for _ in range(10)]
     source.append(np.full((16,), fill_value=np.nan))
     summed = last(isum(source, ignore_nan=True))
     self.assertTrue(np.allclose(summed, np.zeros_like(summed)))
Ejemplo n.º 9
0
 def test_trivial(self):
     """ Test a sum of zeros """
     source = [np.zeros((16,), dtype=np.float) for _ in range(10)]
     summed = last(isum(source))
     self.assertTrue(np.allclose(summed, np.zeros_like(summed)))
Ejemplo n.º 10
0
 def test_glob(self):
     """ Test that iload works on glob-like patterns """
     stream = iload("tests\\data\\test_data*.npy", load_func=np.load)
     s = last(isum(stream)).astype(
         np.float)  # Cast to float for np.allclose
     self.assertTrue(np.allclose(s, np.zeros_like(s)))