"Fossies" - the Fresh Open Source Software Archive 
Member "laspack/examples/matropt/testproc.c" (10 Feb 1995, 12057 Bytes) of package /linux/privat/old/laspack.tgz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /****************************************************************************/
2 /* testproc.c */
3 /****************************************************************************/
4 /* */
5 /* TEST PROCedures for matrix operation optimization for laspack */
6 /* */
7 /* Copyright (C) 1992-1995 Tomas Skalicky. All rights reserved. */
8 /* */
9 /****************************************************************************/
10 /* */
11 /* ANY USE OF THIS CODE CONSTITUTES ACCEPTANCE OF THE TERMS */
12 /* OF THE COPYRIGHT NOTICE (SEE FILE COPYRGHT.H) */
13 /* */
14 /****************************************************************************/
15
16 #include <string.h>
17
18 #include <laspack/errhandl.h>
19 #include <laspack/copyrght.h>
20
21 #include "testproc.h"
22
23 Vector *Test1_QV(QMatrix *Q, Vector *V)
24 /* VRes = Q * V ... very simple implementation */
25 {
26 Vector *VRes;
27
28 char *VResName;
29 size_t Dim, Row, Clm, ElCount;
30 ElType **QEl;
31
32 if (LASResult() == LASOK) {
33 if (Q->Dim == V->Dim) {
34 Dim = Q->Dim;
35 QEl = Q->El;
36 VRes = (Vector *)malloc(sizeof(Vector));
37 VResName = (char *)malloc((strlen(Q_GetName(Q)) + strlen(V_GetName(V)) + 10)
38 * sizeof(char));
39 if (VRes != NULL && VResName != NULL) {
40 sprintf(VResName, "(%s) * (%s)", Q_GetName(Q), V_GetName(V));
41 V_Constr(VRes, VResName, Dim, Tempor, True);
42 if (LASResult() == LASOK) {
43 /* initialisation of vector VRes */
44 V_SetAllCmp(VRes, 0.0);
45
46 /* analysis of multipliers of matrix Q and vector V
47 is not implemented yet */
48
49 /* multiplication of matrix elements by vector
50 components */
51 if (!Q->Symmetry) {
52 if (Q->ElOrder == Rowws) {
53 for (Row = 1; Row <= Dim; Row++) {
54 for (ElCount = 0; ElCount < Q->Len[Row]; ElCount++) {
55 Clm = QEl[Row][ElCount].Pos;
56 VRes->Cmp[Row] += QEl[Row][ElCount].Val * V->Cmp[Clm];
57 }
58 }
59 }
60 if (Q->ElOrder == Clmws) {
61 for (Clm = 1; Clm <= Dim; Clm++) {
62 for (ElCount = 0; ElCount < Q->Len[Clm]; ElCount++) {
63 Row = QEl[Clm][ElCount].Pos;
64 VRes->Cmp[Row] += QEl[Clm][ElCount].Val * V->Cmp[Clm];
65 }
66 }
67 }
68 } else {
69 /* multiplication by symmetric matrix is not
70 implemented yet */
71 V_SetAllCmp(VRes, 0.0);
72 }
73 }
74 } else {
75 LASError(LASMemAllocErr, "Mul_QV", Q_GetName(Q), V_GetName(V), NULL);
76 if (VRes != NULL)
77 free(VRes);
78 if (VResName != NULL)
79 free(VResName);
80 }
81 } else {
82 LASError(LASDimErr, "Mul_QV", Q_GetName(Q), V_GetName(V), NULL);
83 VRes = NULL;
84 }
85 } else {
86 VRes = NULL;
87 }
88
89 if (Q != NULL) {
90 if (Q->Instance == Tempor) {
91 Q_Destr(Q);
92 free(Q);
93 }
94 }
95 if (V != NULL) {
96 if (V->Instance == Tempor) {
97 V_Destr(V);
98 free(V);
99 }
100 }
101 return(VRes);
102 }
103
104 Vector *Test2_QV(QMatrix *Q, Vector *V)
105 /* VRes = Q * V ... implementation like laspack version 0.06 */
106 {
107 Vector *VRes;
108
109 char *VResName;
110 size_t Dim, Row, Clm, ElCount;
111 ElType *PtrEl;
112 Real Val;
113
114 if (LASResult() == LASOK) {
115 if (Q->Dim == V->Dim) {
116 Dim = Q->Dim;
117 VRes = (Vector *)malloc(sizeof(Vector));
118 VResName = (char *)malloc((strlen(Q_GetName(Q)) + strlen(V_GetName(V)) + 10)
119 * sizeof(char));
120 if (VRes != NULL && VResName != NULL) {
121 sprintf(VResName, "(%s) * (%s)", Q_GetName(Q), V_GetName(V));
122 V_Constr(VRes, VResName, Dim, Tempor, True);
123 if (LASResult() == LASOK) {
124 /* initialisation of vector VRes */
125 V_SetAllCmp(VRes, 0.0);
126
127 /* analysis of multipliers of matrix Q and vector V
128 is not implemented yet */
129
130 /* multiplication of matrix elements by vector
131 components */
132 if (!Q->Symmetry) {
133 if (Q->ElOrder == Rowws) {
134 for (Row = 1; Row <= Dim; Row++) {
135 PtrEl = Q->El[Row];
136 for (ElCount = Q->Len[Row]; ElCount > 0;
137 ElCount--) {
138 Val = (*PtrEl).Val;
139 Clm = (*PtrEl).Pos;
140 VRes->Cmp[Row] += Val * V->Cmp[Clm];
141 PtrEl++;
142 }
143 }
144 }
145 if (Q->ElOrder == Clmws) {
146 for (Clm = 1; Clm <= Dim; Clm++) {
147 PtrEl = Q->El[Clm];
148 for (ElCount = Q->Len[Clm]; ElCount > 0;
149 ElCount--) {
150 Val = (*PtrEl).Val;
151 Row = (*PtrEl).Pos;
152 VRes->Cmp[Row] += Val * V->Cmp[Clm];
153 PtrEl++;
154 }
155 }
156 }
157 } else {
158 /* multiplication by symmetric matrix is not
159 implemented yet */
160 V_SetAllCmp(VRes, 0.0);
161 }
162 }
163 } else {
164 LASError(LASMemAllocErr, "Mul_QV", Q_GetName(Q), V_GetName(V), NULL);
165 if (VRes != NULL)
166 free(VRes);
167 if (VResName != NULL)
168 free(VResName);
169 }
170 } else {
171 LASError(LASDimErr, "Mul_QV", Q_GetName(Q), V_GetName(V), NULL);
172 VRes = NULL;
173 }
174 } else {
175 VRes = NULL;
176 }
177
178 if (Q != NULL) {
179 if (Q->Instance == Tempor) {
180 Q_Destr(Q);
181 free(Q);
182 }
183 }
184 if (V != NULL) {
185 if (V->Instance == Tempor) {
186 V_Destr(V);
187 free(V);
188 }
189 }
190 return(VRes);
191 }
192
193 Vector *Test3_QV(QMatrix *Q, Vector *V)
194 /* VRes = Q * V ... implementation using local variables and pointers,
195 ascended counting of matrix elements */
196 {
197 Vector *VRes;
198
199 char *VResName;
200 size_t Dim, Row, Clm, Len, ElCount;
201 size_t *QLen;
202 ElType **QEl, *PtrEl;
203 Real Sum, Cmp;
204 Real *VCmp, *VResCmp;
205
206 if (LASResult() == LASOK) {
207 if (Q->Dim == V->Dim) {
208 Dim = Q->Dim;
209 VRes = (Vector *)malloc(sizeof(Vector));
210 VResName = (char *)malloc((strlen(Q_GetName(Q)) + strlen(V_GetName(V)) + 10)
211 * sizeof(char));
212 if (VRes != NULL && VResName != NULL) {
213 sprintf(VResName, "(%s) * (%s)", Q_GetName(Q), V_GetName(V));
214 V_Constr(VRes, VResName, Dim, Tempor, True);
215 if (LASResult() == LASOK) {
216 /* initialisation of vector VRes */
217 if (Q->Symmetry || Q->ElOrder == Clmws)
218 V_SetAllCmp(VRes, 0.0);
219
220 /* analysis of multipliers of matrix Q and vector V
221 is not implemented yet */
222
223 /* multiplication of matrix elements by vector
224 components */
225 VCmp = V->Cmp;
226 VResCmp = VRes->Cmp;
227 QLen = Q->Len;
228 QEl = Q->El;
229 if (!Q->Symmetry) {
230 if (Q->ElOrder == Rowws) {
231 for (Row = 1; Row <= Dim; Row++) {
232 Len = QLen[Row];
233 PtrEl = QEl[Row];
234 Sum = 0.0;
235 for (ElCount = 0; ElCount < Len; ElCount++) {
236 Sum += (*PtrEl).Val * VCmp[(*PtrEl).Pos];
237 PtrEl++;
238 }
239 VResCmp[Row] = Sum;
240 }
241 }
242 if (Q->ElOrder == Clmws) {
243 for (Clm = 1; Clm <= Dim; Clm++) {
244 Len = QLen[Clm];
245 PtrEl = QEl[Clm];
246 Cmp = VCmp[Clm];
247 for (ElCount = 0; ElCount < Len; ElCount++) {
248 VResCmp[(*PtrEl).Pos] += (*PtrEl).Val * Cmp;
249 PtrEl++;
250 }
251 }
252 }
253 } else {
254 /* multiplication by symmetric matrix is not
255 implemented yet */
256 V_SetAllCmp(VRes, 0.0);
257 }
258 }
259 } else {
260 LASError(LASMemAllocErr, "Mul_QV", Q_GetName(Q), V_GetName(V), NULL);
261 if (VRes != NULL)
262 free(VRes);
263 if (VResName != NULL)
264 free(VResName);
265 }
266 } else {
267 LASError(LASDimErr, "Mul_QV", Q_GetName(Q), V_GetName(V), NULL);
268 VRes = NULL;
269 }
270 } else {
271 VRes = NULL;
272 }
273
274 if (Q != NULL) {
275 if (Q->Instance == Tempor) {
276 Q_Destr(Q);
277 free(Q);
278 }
279 }
280 if (V != NULL) {
281 if (V->Instance == Tempor) {
282 V_Destr(V);
283 free(V);
284 }
285 }
286 return(VRes);
287 }
288
289 Vector *Test4_QV(QMatrix *Q, Vector *V)
290 /* VRes = Q * V ... implementation using local variables and pointers,
291 descended counting of matrix elements */
292 {
293 Vector *VRes;
294
295 char *VResName;
296 size_t Dim, Row, Clm, Len, ElCount;
297 size_t *QLen;
298 ElType **QEl, *PtrEl;
299 Real Sum, Cmp;
300 Real *VCmp, *VResCmp;
301
302 if (LASResult() == LASOK) {
303 if (Q->Dim == V->Dim) {
304 Dim = Q->Dim;
305 VRes = (Vector *)malloc(sizeof(Vector));
306 VResName = (char *)malloc((strlen(Q_GetName(Q)) + strlen(V_GetName(V)) + 10)
307 * sizeof(char));
308 if (VRes != NULL && VResName != NULL) {
309 sprintf(VResName, "(%s) * (%s)", Q_GetName(Q), V_GetName(V));
310 V_Constr(VRes, VResName, Dim, Tempor, True);
311 if (LASResult() == LASOK) {
312 /* initialisation of vector VRes */
313 if (Q->Symmetry || Q->ElOrder == Clmws)
314 V_SetAllCmp(VRes, 0.0);
315
316 /* analysis of multipliers of matrix Q and vector V
317 is not implemented yet */
318
319 /* multiplication of matrix elements by vector
320 components */
321 VCmp = V->Cmp;
322 VResCmp = VRes->Cmp;
323 QLen = Q->Len;
324 QEl = Q->El;
325 if (!Q->Symmetry) {
326 if (Q->ElOrder == Rowws) {
327 for (Row = Dim; Row > 0; Row--) {
328 Len = QLen[Row];
329 PtrEl = QEl[Row] + Len - 1;
330 Sum = 0.0;
331 for (ElCount = Len; ElCount > 0; ElCount--) {
332 Sum += (*PtrEl).Val * VCmp[(*PtrEl).Pos];
333 PtrEl--;
334 }
335 VResCmp[Row] = Sum;
336 }
337 }
338 if (Q->ElOrder == Clmws) {
339 for (Clm = Dim; Clm > 0; Clm--) {
340 Len = QLen[Clm];
341 PtrEl = QEl[Clm] + Len - 1;
342 Cmp = VCmp[Clm];
343 for (ElCount = Len; ElCount > 0; ElCount--) {
344 VResCmp[(*PtrEl).Pos] += (*PtrEl).Val * Cmp;
345 PtrEl--;;
346 }
347 }
348 }
349 } else {
350 /* multiplication by symmetric matrix is not
351 implemented yet */
352 V_SetAllCmp(VRes, 0.0);
353 }
354 }
355 } else {
356 LASError(LASMemAllocErr, "Mul_QV", Q_GetName(Q), V_GetName(V), NULL);
357 if (VRes != NULL)
358 free(VRes);
359 if (VResName != NULL)
360 free(VResName);
361 }
362 } else {
363 LASError(LASDimErr, "Mul_QV", Q_GetName(Q), V_GetName(V), NULL);
364 VRes = NULL;
365 }
366 } else {
367 VRes = NULL;
368 }
369
370 if (Q != NULL) {
371 if (Q->Instance == Tempor) {
372 Q_Destr(Q);
373 free(Q);
374 }
375 }
376 if (V != NULL) {
377 if (V->Instance == Tempor) {
378 V_Destr(V);
379 free(V);
380 }
381 }
382 return(VRes);
383 }