Пример #1
0
    def assertAlmostEqualVector(self, found, expected, precision = 1e-7):
        # we can use the optimized version if the two arrays are 1D numpy float arrays
        if isinstance(found, numpy.ndarray) and \
           isinstance(expected, numpy.ndarray) and \
           found.ndim == 1 and expected.ndim == 1 and \
           found.dtype == expected.dtype and \
           found.dtype == numpy.float32:
            return self.assertTrue(almostEqualArray(found, expected, precision))

        self.assertEqual(len(found), len(expected))
        for val1, val2 in zip(found, expected):
            self.assertAlmostEqual(val1, val2, precision)
Пример #2
0
    def assertAlmostEqualVector(self, found, expected, precision = 1e-7):
        # we can use the optimized version if the two arrays are 1D numpy float arrays
        if isinstance(found, numpy.ndarray) and \
           isinstance(expected, numpy.ndarray) and \
           found.ndim == 1 and expected.ndim == 1 and \
           found.dtype == expected.dtype and \
           found.dtype == numpy.float32:
            return self.assertTrue(almostEqualArray(found, expected, precision))

        self.assertEqual(len(found), len(expected))
        for val1, val2 in zip(found, expected):
            self.assertAlmostEqual(val1, val2, precision)
Пример #3
0
    def assertAlmostEqualMatrix(self, found, expected, precision = 1e-7):
        # we can use the optimized version if the two arrays are 2D numpy float arrays
        if isinstance(found, numpy.ndarray) and \
           isinstance(expected, numpy.ndarray) and \
           found.ndim == 2 and expected.ndim == 2 and \
           found.dtype == expected.dtype and \
           found.dtype == numpy.float32:
            return self.assertTrue(almostEqualArray(found, expected, precision))

        self.assertEqual(len(found), len(expected))

        for v1, v2 in zip(found, expected):
            self.assertEqual(len(v1), len(v2))
            self.assertAlmostEqualVector(array(v1).flatten(), array(v2).flatten(), precision)
Пример #4
0
    def assertAlmostEqualMatrix(self, found, expected, precision = 1e-7):
        # we can use the optimized version if the two arrays are 2D numpy float arrays
        if isinstance(found, numpy.ndarray) and \
           isinstance(expected, numpy.ndarray) and \
           found.ndim == 2 and expected.ndim == 2 and \
           found.dtype == expected.dtype and \
           found.dtype == numpy.float32:
            return self.assertTrue(almostEqualArray(found, expected, precision))

        self.assertEqual(len(found), len(expected))
        count = 0
        for v1, v2 in zip(found, expected):
            self.assertEqual(len(v1), len(v2))
            for val1, val2 in zip(v1, v2):
                if (isinstance(val1, numpy.ndarray)):
                    self.assertAlmostEqual(val1.all(), val2.all(), precision)
                else:
                    self.assertAlmostEqual(val1, val2, precision)

            count += 1
Пример #5
0
    def assertAlmostEqualMatrix(self, found, expected, precision = 1e-7):
        # we can use the optimized version if the two arrays are 2D numpy float arrays
        if isinstance(found, numpy.ndarray) and \
           isinstance(expected, numpy.ndarray) and \
           found.ndim == 2 and expected.ndim == 2 and \
           found.dtype == expected.dtype and \
           found.dtype == numpy.float32:
            return self.assertTrue(almostEqualArray(found, expected, precision))

        self.assertEqual(len(found), len(expected))
        count = 0
        for v1, v2 in zip(found, expected):
            self.assertEqual(len(v1), len(v2))
            for val1, val2 in zip(v1, v2):
                if (isinstance(val1, numpy.ndarray)):
                    self.assertAlmostEqual(val1.all(), val2.all(), precision)
                else:
                    self.assertAlmostEqual(val1, val2, precision)

            count += 1