Ejemplo n.º 1
0
    def test_raise_shape_match_error(self):
        """Tests whether an error is thrown when b doesn't match a."""

        # B has more rows than a has columns!
        a = np.array([[1, 0], [0, 1]])
        b = np.array([[4, 1], [2, 2], [2, 2]])

        # Check if error is raised
        with self.assertRaises(ValueError):
            matmul(a, b)
Ejemplo n.º 2
0
    def test_raise_shape_error(self):
        """Tests if error is raised when either A or B does not have 2
        dimensions"""

        # A does not have 2 dimensions
        a = np.array([[[1, 0], [0, 1]], [[0, 1], [0, 1]]])
        b = np.array([[4, 1], [2, 2]])

        with self.assertRaises(ValueError):
            matmul(a, b)

        # B does not have 2 dimensions
        a = np.array([[1, 0], [0, 1]])
        b = np.array([[[1, 0], [0, 1]], [[0, 1], [0, 1]]])

        with self.assertRaises(ValueError):
            matmul(a, b)
    def test_raise_shape_error(self):
        """Tests if error is raised when either A or B does not have 2
        dimensions"""

        # A does not have 2 dimensions
        a = np.array([[self.a1, self.a2], [self.a2, self.a2]])
        b = np.array([self.b1, self.b2])

        with self.assertRaises(ValueError):
            matmul(a, b)

        # B does not have 2 dimensions
        a = np.array([self.a1, self.a2])
        b = np.array([[self.a1, self.a2], [self.a2, self.a2]])

        with self.assertRaises(ValueError):
            matmul(a, b)
Ejemplo n.º 4
0
    def test_multiplication(self):
        """Test the multiplication itself."""

        # Define matrix content.
        a = np.array([[1, 0], [0, 1]])
        b = np.array([[4, 1], [2, 2]])

        # Check result
        self.assertTrue(np.all(np.array([[4, 1], [2, 2]] == matmul(a, b))))
    def test_multiplication(self):
        """Test the multiplication itself."""

        # Define matrix content.
        a = np.array([self.a1, self.a2])
        b = np.array([self.b1, self.b2])

        # Check result
        self.assertTrue(np.all(np.array([self.b1, self.b2] == matmul(a, b))))