Statistiques
| Révision :

root / pobysoPythonSage / src / sageSLZ / sageMatrixOperations.sage @ 87

Historique | Voir | Annoter | Télécharger (2,1 ko)

1
print "sageMatrixOperations loading..."
2
def smo_is_diagonal_complete_matrix(mat):
3
    """
4
    Check that all the element on the diagonal are not 0.
5
    """
6
    dimensions = mat.dimensions()
7
    # Must be a bidimensional matrix.
8
    if len(dimensions) != 2:
9
        return False
10
    # Must be square.
11
    if dimensions[0] != dimensions[1]:
12
        return False
13
    # A 1x1 matrix is diagonal complete if it's single element is not 0.
14
    if dimensions[0] == 1:
15
        if mat[0, 0] != 0:
16
            return True
17
        else:
18
            return False
19
    # End if
20
    for rowIndex in xrange(0, dimensions[0]):
21
        if mat[rowIndex, rowIndex] == 0:
22
            print mat.rows()[rowIndex], rowIndex
23
            return False
24
    return True
25
# End smo_is_diagonal_complete_matrix
26

    
27
def smo_is_lower_triangular_matrix(mat):
28
    """
29
    Check that the matrix is lower triangular.
30
    """
31
    dimensions = mat.dimensions()
32
    # Must be a bidimensional matrix.
33
    if len(dimensions) != 2:
34
        return False
35
    # Must be square.
36
    if dimensions[0] != dimensions[1]:
37
        return False
38
    # A 1x1 matrix is lower triangular.
39
    if dimensions[0] == 1:
40
        return True
41
    for rowIndex in xrange(0, dimensions[0]):
42
        for colIndex in xrange(rowIndex + 1, dimensions[1]):
43
            if mat[rowIndex, colIndex] != 0:
44
                print mat.rows()[rowIndex]
45
                return False
46
    return True
47
# End smo_is_lower_triangular_matrix
48

    
49
def smo_is_upper_triangular_matrix(mat):
50
    """
51
    Check that the matrix is upper triangular.
52
    """
53
    dimensions = mat.dimensions()
54
    # Must be a bidimensional matrix.
55
    if len(dimensions) != 2:
56
        return False
57
    # Must be square.
58
    if dimensions[0] != dimensions[1]:
59
        return False
60
    # A 1x1 matrix is lower triangular.
61
    if dimensions[0] == 1:
62
        return True
63
    for rowIndex in xrange(1, dimensions[0]):
64
        for colIndex in xrange(0, rowIndex):
65
            if mat[rowIndex, colIndex] != 0:
66
                print mat.rows()[rowIndex]
67
                return False
68
    return True
69
# End smo_is_upper_triangular_matrix
70

    
71
print "\t...sageMatrixOperations loaded"