~ubuntu-branches/ubuntu/maverick/openturns/maverick

« back to all changes in this revision

Viewing changes to python/test/t_Matrix_std.py

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2010-05-10 17:27:55 UTC
  • mfrom: (1.1.4 upstream) (5.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100510172755-cb5ynskknqqi5rhp
Tags: 0.13.2-2ubuntu1
* Merge with Debian testing. No changes left.
* ubuntu_fix-python-2.6.patch: fix detection of python 2.6 libs, to not use
  LOCALMODLIBS. This pulls a dependency on SSL and makes the package FTBFS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
TESTPREAMBLE()
7
7
 
8
 
  
9
 
# TEST NUMBER ZERO : DEFAULT CONSTRUCTOR AND STRING CONVERTER
10
 
print  "test number zero : default constructor and string converter" 
11
 
  
12
 
# Default constructor
13
 
matrix0 =Matrix() 
14
 
  
15
 
# String converter
16
 
print  "matrix0 = " , matrix0 
17
 
 
18
 
  
19
 
# TEST NUMBER ONE : CONSTRUCTOR WITH SIZE, OPERATOR() AND STRING CONVERTER
20
 
print  "test number one : constructor with size, operator() and string converter" 
21
 
  
22
 
# Constructor with size
23
 
matrix1 = Matrix(2,2)
24
 
  
25
 
# Check operator() methods
26
 
matrix1[0,0]=1. 
27
 
matrix1[1,0]=2. 
28
 
matrix1[0,1]=3. 
29
 
matrix1[1,1]=4. 
30
 
    
31
 
# String converter
32
 
print  "matrix1 = " , matrix1 
33
 
  
34
 
  
35
 
# TEST NUMBER TWO : COPY CONSTRUCTOR AND STRING CONVERTER
36
 
print  "test number two : copy constructor and string converter" 
37
 
  
38
 
# Copy constructor
39
 
matrix2 = Matrix(matrix1)
40
 
  
41
 
# String converter
42
 
print  "matrix2 = " , matrix2 
43
 
  
44
 
  
45
 
# TEST NUMBER THREE : GET DIMENSIONS METHODS
46
 
print  "test number three : get dimensions methods" 
47
 
  
48
 
# Get dimension methods
49
 
print  "matrix1's nbRows = " , matrix1.getNbRows() 
50
 
print "matrix1's nbColumns = " , matrix1.getNbColumns() 
51
 
            
52
 
            
53
 
# TEST NUMBER FOUR : CONSTRUCTOR WITH COLLECTION
54
 
print  "test number four : constructor with collection method" 
55
 
  
56
 
# Create the collection of values
57
 
elementsValues = NumericalScalarCollection()
58
 
elementsValues.add(1.)
59
 
elementsValues.add(2.)
60
 
elementsValues.add(3.)
61
 
elementsValues.add(4.)
62
 
elementsValues.add(5.)
63
 
elementsValues.add(6.)
64
 
  
65
 
# Check the content of the collection
66
 
print  "elementsValues = " , elementsValues 
67
 
 
68
 
# Check the constructor with collection
69
 
matrix0bis = Matrix(2,2,elementsValues)
70
 
print  "matrix0bis = " , matrix0bis 
71
 
 
72
 
# TEST NUMBER FIVE : ASSIGNMENT METHOD
73
 
print  "test number five : assignment method" 
74
 
  
75
 
# Assignment method
76
 
 # No sense with pyton
77
 
  
78
 
  
79
 
# TEST NUMBER SIX : TRANSPOSITION METHOD
80
 
print  "test number six : transposition method" 
81
 
  
82
 
# Check transpose method
83
 
matrix4 = matrix1.transpose()
84
 
print  "matrix1 transposed = " , matrix4 
85
 
  
86
 
  
87
 
# TEST NUMBER SEVEN : ADDITION METHOD
88
 
print  "test number seven : addition method" 
89
 
  
90
 
# Check addition method : we check the operator and the symmetry of the operator, thus testing the comparison operator
91
 
sum1 = matrix1 + matrix4 
92
 
sum2 = matrix4 + matrix1  
93
 
print  "sum1 = " , sum1 
94
 
print  "sum2 = " , sum2
95
 
print  "sum1 equals sum2 = " , sum1 == sum2
96
 
  
97
 
  
98
 
# TEST NUMBER EIGHT : SUBSTRACTION METHOD
99
 
print  "test number eight : substraction method" 
100
 
  
101
 
# Check substraction method
102
 
diff = matrix1-matrix4 
103
 
print  "diff = " , diff 
104
 
  
105
 
  
106
 
# TEST NUMBER NINE : MATRIX MULTIPLICATION METHOD
107
 
print  "test number nine : matrix multiplication method" 
108
 
  
109
 
# Check multiplication method
110
 
prod = matrix1*matrix4 
111
 
print  "prod = " , prod
112
 
  
113
 
  
114
 
# TEST NUMBER TEN : MULTIPLICATION WITH A NUMERICAL POINT METHOD
115
 
print  "test number ten : multiplication with a numerical point method" 
116
 
 
117
 
# Create the numerical point
118
 
pt = NumericalPoint()
119
 
pt.add(1.) 
120
 
pt.add(2.) 
121
 
print  "pt = " , repr(pt)
122
 
  
123
 
# Check the product method
124
 
ptResult = matrix1* pt
125
 
print  "ptResult = " , repr(ptResult)
126
 
  
127
 
# TEST NUMBER ELEVEN : MULTIPLICATION AND DIVISION BY A NUMERICAL SCALAR METHODS
128
 
print  "test number eleven : multiplication and division by a numerical scalar methods" 
129
 
 
130
 
# Check the multiplication method 
131
 
s=3.
132
 
scalprod1 = matrix1 * s
133
 
#bug PYTHON scalprod2 = s * matrix1 
134
 
scalprod3 = matrix1 * s 
135
 
print  "scalprod1 = " , scalprod1 
136
 
#print  "scalprod2 = " , scalprod2 
137
 
print  "scalprod3 = " , scalprod3
138
 
#print  "scalprod1 equals scalprod2 = " , (scalprod1 == scalprod2) 
139
 
print  "scalprod1 equals scalprod3 = " , (scalprod1 == scalprod3) 
140
 
#print  "scalprod2 equals scalprod3 = " , (scalprod2 == scalprod3) 
141
 
 
142
 
# Check the division method
143
 
scaldiv1 = matrix1/s
144
 
scaldiv2 = matrix1/s
145
 
print  "scaldiv1 = " , scaldiv1 
146
 
print  "scaldiv2 = " , scaldiv2 
147
 
print  "scaldiv1 equals scaldiv2 = " , (scaldiv1 == scaldiv2)
148
 
 
149
 
  
150
 
# TEST NUMBER TWELVE : ISEMPTY METHOD
151
 
print  "test number twelve : isEmpty method"  
152
 
  
153
 
# Check method isEmpty
154
 
matrix5 = Matrix()
155
 
matrix6 = Matrix()
156
 
# matrix6.setDimensions(0,3)
157
 
print  "matrix1 is empty = " , matrix1.isEmpty() 
158
 
print  "matrix5 is empty = " , matrix5.isEmpty()
159
 
print  "matrix6 is empty = " , matrix6.isEmpty() 
160
 
print  "matrix0 is empty = " , matrix0.isEmpty()  
161
 
            
162
 
# TEST NUMBER FOURTEEN : MULTIPLICATION WITH A NUMERICAL POINT METHOD
163
 
print  "test number fourteen : multiplication with a numerical point method"  
164
 
  
165
 
# Create the numerical point
166
 
pt_test = NumericalPoint()
167
 
pt_test.add(1.) 
168
 
pt_test.add(2.) 
169
 
print  "pt_test = " , repr(pt_test)
170
 
  
171
 
A = Matrix(2,2)
172
 
A[0,0]=0.5 
173
 
A[1,0]=-(sqrt(3.)/2) 
174
 
A[0,1]=(sqrt(3.)/2) 
175
 
A[1,1]=0.5 
176
 
B=A.transpose()
177
 
id=B*A
178
 
  
179
 
# Check the product method
180
 
ptResult2 = id* pt_test 
181
 
print  "A = " , A 
182
 
print  "B = " , B
183
 
print  "id = " , id 
184
 
print  "ptResult2 = " , repr(ptResult2)
 
8
try:
 
9
    # TEST NUMBER ZERO : DEFAULT CONSTRUCTOR AND STRING CONVERTER
 
10
    print  "test number zero : default constructor and string converter"
 
11
 
 
12
    # Default constructor
 
13
    matrix0 = Matrix()
 
14
 
 
15
    # String converter
 
16
    print  "matrix0 = " , repr(matrix0)
 
17
 
 
18
 
 
19
    # TEST NUMBER ONE : CONSTRUCTOR WITH SIZE, OPERATOR() AND STRING CONVERTER
 
20
    print  "test number one : constructor with size, operator() and string converter"
 
21
 
 
22
    # Constructor with size
 
23
    matrix1 = Matrix(2,2)
 
24
 
 
25
    # Check operator() methods
 
26
    matrix1[0,0]=1.
 
27
    matrix1[1,0]=2.
 
28
    matrix1[0,1]=3.
 
29
    matrix1[1,1]=4.
 
30
 
 
31
    # String converter
 
32
    print  "matrix1 = " , repr(matrix1)
 
33
 
 
34
 
 
35
    # TEST NUMBER TWO : COPY CONSTRUCTOR AND STRING CONVERTER
 
36
    print  "test number two : copy constructor and string converter"
 
37
 
 
38
    # Copy constructor
 
39
    matrix2 = Matrix(matrix1)
 
40
 
 
41
    # String converter
 
42
    print  "matrix2 = " , repr(matrix2)
 
43
 
 
44
 
 
45
    # TEST NUMBER THREE : GET DIMENSIONS METHODS
 
46
    print  "test number three : get dimensions methods"
 
47
 
 
48
    # Get dimension methods
 
49
    print  "matrix1's nbRows = " , matrix1.getNbRows()
 
50
    print "matrix1's nbColumns = " , matrix1.getNbColumns()
 
51
 
 
52
 
 
53
    # TEST NUMBER FOUR : CONSTRUCTOR WITH COLLECTION
 
54
    print  "test number four : constructor with collection method"
 
55
 
 
56
    # Create the collection of values
 
57
    elementsValues = NumericalScalarCollection()
 
58
    elementsValues.add(1.)
 
59
    elementsValues.add(2.)
 
60
    elementsValues.add(3.)
 
61
    elementsValues.add(4.)
 
62
    elementsValues.add(5.)
 
63
    elementsValues.add(6.)
 
64
 
 
65
    # Check the content of the collection
 
66
    print  "elementsValues = " , elementsValues
 
67
 
 
68
    # Check the constructor with collection
 
69
    matrix0bis = Matrix(2,2,elementsValues)
 
70
    print  "matrix0bis = " , repr(matrix0bis)
 
71
 
 
72
    # TEST NUMBER FIVE : ASSIGNMENT METHOD
 
73
    print  "test number five : assignment method"
 
74
 
 
75
    # Assignment method
 
76
    # No sense with pyton
 
77
 
 
78
 
 
79
    # TEST NUMBER SIX : TRANSPOSITION METHOD
 
80
    print  "test number six : transposition method"
 
81
 
 
82
    # Check transpose method
 
83
    matrix4 = matrix1.transpose()
 
84
    print  "matrix1 transposed = " , repr(matrix4)
 
85
 
 
86
 
 
87
    # TEST NUMBER SEVEN : ADDITION METHOD
 
88
    print  "test number seven : addition method"
 
89
 
 
90
    # Check addition method : we check the operator and the symmetry of the operator, thus testing the comparison operator
 
91
    sum1 = matrix1 + matrix4
 
92
    sum2 = matrix4 + matrix1
 
93
    print  "sum1 = " , repr(sum1)
 
94
    print  "sum2 = " , repr(sum2)
 
95
    print  "sum1 equals sum2 = " , sum1 == sum2
 
96
 
 
97
 
 
98
    # TEST NUMBER EIGHT : SUBSTRACTION METHOD
 
99
    print  "test number eight : substraction method"
 
100
 
 
101
    # Check substraction method
 
102
    diff = matrix1-matrix4
 
103
    print  "diff = " , repr(diff)
 
104
 
 
105
 
 
106
    # TEST NUMBER NINE : MATRIX MULTIPLICATION METHOD
 
107
    print  "test number nine : matrix multiplication method"
 
108
 
 
109
    # Check multiplication method
 
110
    prod = matrix1*matrix4
 
111
    print  "prod = " , repr(prod)
 
112
 
 
113
 
 
114
    # TEST NUMBER TEN : MULTIPLICATION WITH A NUMERICAL POINT METHOD
 
115
    print  "test number ten : multiplication with a numerical point method"
 
116
 
 
117
    # Create the numerical point
 
118
    pt = NumericalPoint()
 
119
    pt.add(1.)
 
120
    pt.add(2.)
 
121
    print  "pt = " , repr(pt)
 
122
 
 
123
    # Check the product method
 
124
    ptResult = matrix1* pt
 
125
    print  "ptResult = " , repr(ptResult)
 
126
 
 
127
    # TEST NUMBER ELEVEN : MULTIPLICATION AND DIVISION BY A NUMERICAL SCALAR METHODS
 
128
    print  "test number eleven : multiplication and division by a numerical scalar methods"
 
129
 
 
130
    # Check the multiplication method
 
131
    s=3.
 
132
    scalprod1 = matrix1 * s
 
133
    #bug PYTHON scalprod2 = s * matrix1
 
134
    scalprod3 = matrix1 * s
 
135
    print  "scalprod1 = " , repr(scalprod1)
 
136
    #print  "scalprod2 = " , scalprod2
 
137
    print  "scalprod3 = " , repr(scalprod3)
 
138
    #print  "scalprod1 equals scalprod2 = " , (scalprod1 == scalprod2)
 
139
    print  "scalprod1 equals scalprod3 = " , (scalprod1 == scalprod3)
 
140
    #print  "scalprod2 equals scalprod3 = " , (scalprod2 == scalprod3)
 
141
 
 
142
    # Check the division method
 
143
    scaldiv1 = matrix1/s
 
144
    scaldiv2 = matrix1/s
 
145
    print  "scaldiv1 = " , repr(scaldiv1)
 
146
    print  "scaldiv2 = " , repr(scaldiv2)
 
147
    print  "scaldiv1 equals scaldiv2 = " , (scaldiv1 == scaldiv2)
 
148
 
 
149
 
 
150
    # TEST NUMBER TWELVE : ISEMPTY METHOD
 
151
    print  "test number twelve : isEmpty method"
 
152
 
 
153
    # Check method isEmpty
 
154
    matrix5 = Matrix()
 
155
    matrix6 = Matrix()
 
156
    # matrix6.setDimensions(0,3)
 
157
    print  "matrix1 is empty = " , matrix1.isEmpty()
 
158
    print  "matrix5 is empty = " , matrix5.isEmpty()
 
159
    print  "matrix6 is empty = " , matrix6.isEmpty()
 
160
    print  "matrix0 is empty = " , matrix0.isEmpty()
 
161
 
 
162
    # TEST NUMBER FOURTEEN : MULTIPLICATION WITH A NUMERICAL POINT METHOD
 
163
    print  "test number fourteen : multiplication with a numerical point method"
 
164
 
 
165
    # Create the numerical point
 
166
    pt_test = NumericalPoint()
 
167
    pt_test.add(1.)
 
168
    pt_test.add(2.)
 
169
    print  "pt_test = " , repr(pt_test)
 
170
 
 
171
    A = Matrix(2,2)
 
172
    A[0,0]=0.5
 
173
    A[1,0]=-(sqrt(3.)/2)
 
174
    A[0,1]=(sqrt(3.)/2)
 
175
    A[1,1]=0.5
 
176
    B=A.transpose()
 
177
    id=B*A
 
178
 
 
179
    # Check the product method
 
180
    ptResult2 = id* pt_test
 
181
    print  "A = " , repr(A)
 
182
    print  "B = " , repr(B)
 
183
    print  "id = " , repr(id)
 
184
    print  "ptResult2 = " , repr(ptResult2)
 
185
except:
 
186
    import sys
 
187
    print "t_Matrix_std.py", sys.exc_type, sys.exc_value