Ejemplo n.º 1
0
 def testSubtraction(self):
     """
     The binary subtraction operator
     should, when applied to two matricies, product
     the difference of the two matricies if and only if
     their dimensions are equal.
     """
     A = Matrix.fromArray([
         [0,2,3],
         [4,2,6],
         [4,5,6]
     ])
     B = Matrix.fromArray([
         [4, 9, 6],
         [7, 8, 1],
         [0, 13,2]
     ])
     C = Matrix.fromArray([
         [1,2,3],
         [4,5,6]
     ])
     diffAB = Matrix.fromArray([
         [-4, -7, -3],
         [-3, -6, 5],
         [4, -8, 4]
     ])
     self.assertEqual(A - B, diffAB)
     self.assertEqual(A - C, None)
Ejemplo n.º 2
0
    def testAddition(self):
        """
        The binary addition operator
        should, when applied to two matricies, product
        the sum of the two matricies if and only if
        their dimensions are equal.
        """

        A = Matrix.fromArray([
            [0,2,3],
            [4,2,6],
            [4,5,6]
        ])
        B = Matrix.fromArray([
            [4, 9, 6],
            [7, 8, 1],
            [0, 13,2]
        ])
        C = Matrix.fromArray([
            [1,2,3],
            [4,5,6]
        ])
        sumAB = Matrix.fromArray([
            [4, 11, 9],
            [11, 10, 7],
            [4, 18, 8]
        ])
        self.assertEqual(A + B, sumAB)
        self.assertEqual(A + C, None)
Ejemplo n.º 3
0
 def setUp(self):
     self.matrix = Matrix.fromArray([
         [1, 2, 3],
         [4, 5, 6],
         [7, 8, 9]
     ])
     self.identity = Matrix.fromArray([
         [1, 0, 0],
         [0, 1, 0],
         [0, 0, 1]
     ])
Ejemplo n.º 4
0
    def testMultiply(self):
        """
        The binary multiplication operator
        should, when applied to two matricies, produce
        the matrix product if and only if the number of rows in the left
        operand is equal to the number of columns in the right operand.

        Matrix multiplication is generally not communitive, so
        the product AB should differ from the product BA (usually)
        """
        matrixA = self.matrix
        matrixB = self.matrix.transpose()

        productAB = matrixA * matrixB
        productBA = matrixB * matrixA

        self.assertEqual(productAB, [
            [14,32,50],
            [32,77,122],
            [50,122,194]
        ])

        self.assertEqual(productBA, [
            [66,78,90],
            [78,93,108],
            [90,108,126]
        ])

        matrixC = Matrix.fromArray([
            [1,2,3],
            [4,5,6]
        ])

        self.assertEqual(matrixA * matrixC, None)
Ejemplo n.º 5
0
    def testTranspose(self):
        """
        The transpose method return a copy of the matrix
        with the columns and rows exchanged.
        """

        transpose = Matrix.fromArray([
            [1, 4, 7],
            [2, 5, 8],
            [3, 6, 9]
        ])
        self.assertEqual(self.matrix.transpose(), transpose)
Ejemplo n.º 6
0
    def testDeterminant(self):
        """
        The determinant method should return None if the
        matrix is not square. It should return zero
        if the matrix is singular.
        """

        nonSquare = Matrix.fromArray([
            [1,2,3],
            [4,5,6]
        ])
        singularMatrix = self.matrix
        self.assertEqual(nonSquare.determinant(), None)
        self.assertEqual(singularMatrix.determinant(), 0)
Ejemplo n.º 7
0
def computeDeterminant(model):
    request.det = Matrix.fromArray(model['matrix']).determinant()
Ejemplo n.º 8
0
def buildMatricies(model):
    request.matrixA = Matrix.fromArray(model['lvalue'])
    request.matrixB = Matrix.fromArray(model['rvalue'])
Ejemplo n.º 9
0
def computeDeterminant(model):
    request.det = Matrix.fromArray(model['matrix']).determinant()
Ejemplo n.º 10
0
def buildMatricies(model):
    request.matrixA = Matrix.fromArray(model['lvalue'])
    request.matrixB = Matrix.fromArray(model['rvalue'])
Ejemplo n.º 11
0
 def testDimension(self):
     matrix = Matrix.fromArray([[1, 2, 3], [4, 5, 6]])
     self.assertEqual(util.dimension(matrix), (3, 2))
Ejemplo n.º 12
0
 def testDimension(self):
     matrix = Matrix.fromArray([
         [1,2,3],
         [4,5,6]
     ])
     self.assertEqual(util.dimension(matrix), (3,2))