/[ascend]/trunk/ascend/linear/test/test_qr2x2.c
ViewVC logotype

Contents of /trunk/ascend/linear/test/test_qr2x2.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2527 - (show annotations) (download) (as text)
Fri Jan 20 00:44:37 2012 UTC (10 years, 5 months ago) by jpye
File MIME type: text/x-csrc
File size: 3940 byte(s)
Disabled MMIO output functions when MMIO not built.
Rewrite error messages from mem.c to use ERROR_REPORTER_HERE.
Trying to track down source of errors in test_mem.c.
1 /* ASCEND modelling environment
2 Copyright (C) 2007 Carnegie Mellon University
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18 *//**
19 @file
20 Unit test functions for linear/linsolqr.c
21 */
22 #include <string.h>
23
24 #include <ascend/general/platform.h>
25 #include <ascend/linear/linsolqr.h>
26
27 #include <test/common.h>
28 #include <test/assertimpl.h>
29
30 /*
31 Test the rank of matrix
32
33 [ 1 ]
34 */
35 static void test_qr1x1(void){
36 linsolqr_system_t L;
37 mtx_matrix_t M;
38 mtx_coord_t C;
39 mtx_range_t R;
40 mtx_region_t G;
41 int r;
42
43 /* build the matrix [[1,0],[1,1]] */
44 M = mtx_create();
45 mtx_set_order(M,1);
46 mtx_set_value(M,mtx_coord(&C,0,0), 1.0);
47
48 /* construct a 'whole matrix' region (can't use mtx_ENTIRE_MATRIX with linsolqr_set_region) */
49 R.low = 0;
50 R.high = mtx_order(M) - 1;
51 G.row = R;
52 G.col = R;
53
54 #ifdef ASC_WITH_MMIO
55 mtx_write_region_mmio(stderr,M,&G);
56 #endif
57
58 L = linsolqr_create_default();
59 linsolqr_set_matrix(L,M);
60 linsolqr_set_region(L,G);
61 linsolqr_prep(L,linsolqr_fmethod_to_fclass(linsolqr_fmethod(L)));
62 linsolqr_reorder(L, &G, linsolqr_rmethod(L));
63 linsolqr_factor(L,linsolqr_fmethod(L));
64 r = linsolqr_rank(L);
65
66 CU_ASSERT(r==1);
67 }
68
69 /*
70 Test the rank of matrix
71
72 [ 1 0
73 1 1 ]
74 */
75 static void test_qr2x2(void){
76 linsolqr_system_t L;
77 mtx_matrix_t M;
78 mtx_coord_t C;
79 mtx_range_t R;
80 mtx_region_t G;
81 int r;
82
83 /* build the matrix [[1,0],[1,1]] */
84 M = mtx_create();
85 mtx_set_order(M,2);
86 mtx_set_value(M,mtx_coord(&C,0,0), 1.0);
87 mtx_set_value(M,mtx_coord(&C,1,0), 1.0);
88 mtx_set_value(M,mtx_coord(&C,1,1), 1.0);
89
90 /* construct a 'whole matrix' region (can't use mtx_ENTIRE_MATRIX with linsolqr_set_region) */
91 R.low = 0;
92 R.high = mtx_order(M) - 1;
93 G.row = R;
94 G.col = R;
95
96 #ifdef ASC_WITH_MMIO
97 mtx_write_region_mmio(stderr,M,&G);
98 #endif
99
100 L = linsolqr_create_default();
101 linsolqr_set_matrix(L,M);
102 linsolqr_set_region(L,G);
103 linsolqr_prep(L,linsolqr_fmethod_to_fclass(linsolqr_fmethod(L)));
104 linsolqr_reorder(L, &G, linsolqr_rmethod(L));
105 linsolqr_factor(L,linsolqr_fmethod(L));
106 r = linsolqr_rank(L);
107
108 CU_ASSERT(r==2);
109 }
110
111 /*
112 Test the rank of matrix
113
114 [ 2 0 1
115 1 1 1
116 0 1 1 ]
117 */
118 static void test_qr3x3(void){
119 linsolqr_system_t L;
120 mtx_matrix_t M;
121 mtx_coord_t C;
122 mtx_range_t R;
123 mtx_region_t G;
124 int r;
125
126 /* build the matrix [[1,0],[1,1]] */
127 M = mtx_create();
128 mtx_set_order(M,3);
129 mtx_set_value(M,mtx_coord(&C,0,0), 2.0);
130 mtx_set_value(M,mtx_coord(&C,1,1), 1.0);
131 mtx_set_value(M,mtx_coord(&C,2,2), 1.0);
132 mtx_set_value(M,mtx_coord(&C,0,2), 1.0);
133 mtx_set_value(M,mtx_coord(&C,1,0), 1.0);
134 mtx_set_value(M,mtx_coord(&C,1,2), 1.0);
135 mtx_set_value(M,mtx_coord(&C,2,1), 1.0);
136
137 /* construct a 'whole matrix' region (can't use mtx_ENTIRE_MATRIX with linsolqr_set_region) */
138 R.low = 0;
139 R.high = mtx_order(M) - 1;
140 G.row = R;
141 G.col = R;
142
143 #ifdef ASC_WITH_MMIO
144 mtx_write_region_mmio(stderr,M,&G);
145 #endif
146
147 L = linsolqr_create_default();
148 linsolqr_set_matrix(L,M);
149 linsolqr_set_region(L,G);
150 linsolqr_prep(L,linsolqr_fmethod_to_fclass(linsolqr_fmethod(L)));
151 linsolqr_reorder(L, &G, linsolqr_rmethod(L));
152 linsolqr_factor(L,linsolqr_fmethod(L));
153 r = linsolqr_rank(L);
154
155 CU_ASSERT(r==3);
156 }
157
158 /*===========================================================================*/
159 /* Registration information */
160
161 #define TESTS(T)\
162 T(qr1x1) \
163 T(qr2x2) \
164 T(qr3x3)
165
166 REGISTER_TESTS_SIMPLE(linear_qrrank, TESTS)
167

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22