36 |
#include "CUnit/CUnit.h" |
#include "CUnit/CUnit.h" |
37 |
#include "test_slv_common.h" |
#include "test_slv_common.h" |
38 |
#include "assertimpl.h" |
#include "assertimpl.h" |
39 |
|
#include "printutil.h" |
40 |
|
|
41 |
/* |
/* |
42 |
* Initializes a vector_data structure. |
* Independent calculation of a vector dot product. |
43 |
* The new range (low..high) is considered proper if both low and |
* Nothing fancy, no validation of input. Assumes valid vectors. |
|
* high are zero or positive, and (low <= high). If the new range is |
|
|
* not proper (or if vec itself is NULL), then no modifications are |
|
|
* made to vec.<br><br> |
|
|
* |
|
|
* If the range is proper then vec->rng is allocated if NULL and then |
|
|
* set using low and high. Then vec->vec is allocated (if NULL) or |
|
|
* reallocated to size (high+1). The data in vec->vec is not |
|
|
* initialized or changed. The member vec->accurate is set to FALSE. |
|
|
* |
|
|
* @param vec Pointer to the vector_data to initialize. |
|
|
* @param low The lower bound of the vector's range. |
|
|
* @param high The upper bound of the vector's range. |
|
|
* @return Returns 0 if the vector is initialized successfully, |
|
|
* 1 if an improper range was specified, 2 if vec is NULL, |
|
|
* and 3 if memory cannot be allocated. |
|
44 |
*/ |
*/ |
45 |
static int init_vector(struct vector_data *vec, int32 low, int32 high) |
static real64 slow_inner_product(struct vector_data *vec1, struct vector_data *vec2) |
46 |
{ |
{ |
47 |
int32 new_size; |
int32 i; |
48 |
|
real64 product = 0.0; |
49 |
if ((low < 0) || (high < low)) |
real64 *p1 = vec1->vec + vec1->rng->low; |
50 |
return 1; |
real64 *p2 = vec2->vec + vec2->rng->low; |
51 |
|
int32 len = vec1->rng->high - vec1->rng->low + 1; |
|
if (NULL == vec) |
|
|
return 2; |
|
52 |
|
|
53 |
if (NULL == vec->rng) { |
for (i=0 ; i<len ; ++i, ++p1, ++p2) |
54 |
vec->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t)); |
product += *p1 * *p2; |
|
if (NULL == vec->rng) |
|
|
return 3; |
|
|
} |
|
|
vec->rng = mtx_range(vec->rng, low, high); |
|
|
|
|
|
new_size = high + 1; |
|
|
if (NULL == vec->vec) { |
|
|
vec->vec = (real64 *)ascmalloc((new_size)*sizeof(real64)); |
|
|
if (NULL == vec->vec) { |
|
|
ascfree(vec->rng); |
|
|
vec->rng = NULL; |
|
|
return 3; |
|
|
} |
|
|
} |
|
|
else { |
|
|
vec->vec = (real64 *)ascrealloc(vec->vec, (new_size)*sizeof(real64)); |
|
|
} |
|
55 |
|
|
56 |
vec->accurate = FALSE; |
return product; |
|
return 0; |
|
57 |
} |
} |
58 |
|
|
59 |
/* |
/* |
60 |
* Returns a new vector_data initialized to the specified range. |
* Independent calculation of an array dot product. |
61 |
* This function creates, initializes, and returns a new vector_data |
* Nothing fancy, no validation of input. |
62 |
* structure. The vector is initialized using init_vector() and |
* Assumes valid arrays of length at least len. |
|
* a pointer to the new struct is returned. If the specified range |
|
|
* is improper (see init_vector()) then a valid vector cannot be |
|
|
* created and NULL is returned.<br><br> |
|
|
* |
|
|
* Destruction of the returned vector_data is the responsibility of |
|
|
* the caller. destroy_vector() may be used for this purpose. |
|
|
* |
|
|
* @param low The lower bound of the vector's range. |
|
|
* @param high The upper bound of the vector's range. |
|
|
* @return A new initialized vector_data, or NULL if one could |
|
|
* not be created. |
|
63 |
*/ |
*/ |
64 |
static struct vector_data *create_vector(int32 low, int32 high) |
static real64 slow_dot_product(int32 len, real64 *array1, real64 *array2) |
65 |
{ |
{ |
66 |
struct vector_data *result; |
int32 i; |
67 |
|
real64 product = 0.0; |
68 |
|
|
69 |
result = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); |
for (i=0 ; i<len ; ++i, ++array1, ++array2) |
70 |
if (NULL == result) |
product += *array1 * *array2; |
71 |
return NULL; |
|
72 |
|
return product; |
|
result->rng = NULL; |
|
|
result->vec = NULL; |
|
|
if (0 != init_vector(result, low, high)) { |
|
|
ascfree(result); |
|
|
result = NULL; |
|
|
} |
|
|
return result; |
|
73 |
} |
} |
74 |
|
|
75 |
/* |
/* |
76 |
* Destroys a vector and its assocated data. |
* Independent calculation of a vector-matrix product. |
77 |
* Deallocates any memory held in vec->rng and vec->vec, |
* Nothing fancy, no validation of input. Assumes valid vector & matrix. |
|
* and then deallocates the vector itself. |
|
|
* |
|
|
* @param vec Pointer to the vector_data to destroy. |
|
78 |
*/ |
*/ |
79 |
static void destroy_vector(struct vector_data *vec) |
static void slow_vector_matrix_product(mtx_matrix_t mtx, |
80 |
|
struct vector_data *vec, |
81 |
|
struct vector_data *prod, |
82 |
|
real64 scale) |
83 |
{ |
{ |
84 |
if (NULL != vec) { |
int32 row, col; |
85 |
if (NULL != vec->rng) |
mtx_coord_t coord; |
86 |
ascfree(vec->rng); |
int32 limit = vec->rng->high; |
87 |
if (NULL != vec->vec) |
|
88 |
ascfree(vec->vec); |
coord.row = vec->rng->low; |
89 |
ascfree(vec); |
for (row=vec->rng->low ; row<=limit ; ++row) { |
90 |
|
coord.col = vec->rng->low; |
91 |
|
prod->vec[coord.row] = 0.0; |
92 |
|
for (col=vec->rng->low ; col<=limit ; ++col) { |
93 |
|
prod->vec[coord.row] += vec->vec[coord.col] * mtx_value(mtx, &coord); |
94 |
|
++coord.col; |
95 |
|
} |
96 |
|
prod->vec[coord.row] *= scale; |
97 |
|
++coord.row; |
98 |
} |
} |
99 |
} |
} |
100 |
|
|
101 |
/* |
/* int comparison function for list searches */ |
102 |
* Independent calculation of a vector dot product. |
static int compare_int32s(CONST VOIDPTR p1, CONST VOIDPTR p2) |
|
* Nothing fancy, no validation of input. Assumes valid vectors. |
|
|
*/ |
|
|
real64 slow_dot_product(struct vector_data *vec1, struct vector_data *vec2) |
|
103 |
{ |
{ |
104 |
int32 i; |
assert((NULL != p1) && (NULL != p2)); |
105 |
real64 product = 0.0; |
return *((int32*)p1) - *((int32*)p2); |
|
real64 *p1 = vec1->vec + vec1->rng->low; |
|
|
real64 *p2 = vec2->vec + vec2->rng->low; |
|
|
int32 len = vec1->rng->high - vec1->rng->low + 1; |
|
|
|
|
|
for (i=0 ; i<len ; ++i, ++p1, ++p2) |
|
|
product += *p1 * *p2; |
|
|
|
|
|
return product; |
|
106 |
} |
} |
107 |
|
|
108 |
|
|
109 |
/* |
/* |
110 |
* This function tests the slv_common.c functions and data structures. |
* This function tests the slv_common.c functions and data structures. |
111 |
* Note that some of the implementation declarated in slv_common.h is |
* Note that some of the implementation declarated in slv_common.h is |
116 |
{ |
{ |
117 |
struct vector_data *pvec1; |
struct vector_data *pvec1; |
118 |
struct vector_data *pvec2; |
struct vector_data *pvec2; |
119 |
|
struct vector_data *pvec3; |
120 |
mtx_matrix_t mtx; |
mtx_matrix_t mtx; |
121 |
|
mtx_coord_t coord; |
122 |
|
mtx_region_t region; |
123 |
real64 rarray[100]; |
real64 rarray[100]; |
124 |
|
real64 rarray2[100]; |
125 |
int i; |
int i; |
126 |
|
FILE *file_normal; |
127 |
|
int32 hi[11]; |
128 |
|
int32 hj[11]; |
129 |
|
int32 **lnkmap; |
130 |
|
int32 *lnkvars; |
131 |
|
struct gl_list_t *col_list; |
132 |
|
struct gl_list_t *lnkindex_list; |
133 |
|
int32 lnkindexes[11]; |
134 |
|
unsigned int pos; |
135 |
unsigned long prior_meminuse; |
unsigned long prior_meminuse; |
136 |
unsigned long cur_meminuse; |
unsigned long cur_meminuse; |
137 |
|
unsigned long test_meminuse; |
138 |
int i_initialized_lists = FALSE; |
int i_initialized_lists = FALSE; |
139 |
|
int i_enabled_printing = FALSE; |
140 |
|
|
141 |
#ifdef NDEBUG |
#ifdef NDEBUG |
142 |
CU_FAIL("test_slv_common() compiled with NDEBUG - some features not tested."); |
CU_FAIL("test_slv_common() compiled with NDEBUG - some features not tested."); |
143 |
#endif |
#endif |
144 |
|
#ifndef MALLOC_DEBUG |
145 |
|
CU_FAIL("test_slv_common() compiled without MALLOC_DEBUG - memory management not tested."); |
146 |
|
#endif |
147 |
|
|
148 |
prior_meminuse = ascmeminuse(); |
prior_meminuse = ascmeminuse(); |
149 |
|
|
155 |
} |
} |
156 |
|
|
157 |
for (i=0 ; i<100 ; ++i) { /* create some reals to use later */ |
for (i=0 ; i<100 ; ++i) { /* create some reals to use later */ |
158 |
rarray[i+1] = (real64)pow(i+1, i+1); |
rarray[i] = 7/2 * i; |
159 |
} |
} |
160 |
|
|
161 |
/* test create_vector(), destroy_vector() */ |
/* test slv_create_vector(), slv_destroy_vector() */ |
162 |
|
|
163 |
|
test_meminuse = ascmeminuse(); |
164 |
|
|
165 |
cur_meminuse = ascmeminuse(); |
cur_meminuse = ascmeminuse(); |
166 |
pvec1 = create_vector(-1, 0); /* error - low < 0 */ |
pvec1 = slv_create_vector(-1, 0); /* error - low < 0 */ |
167 |
CU_TEST(NULL == pvec1); |
CU_TEST(NULL == pvec1); |
168 |
|
|
169 |
destroy_vector(pvec1); |
slv_destroy_vector(pvec1); |
170 |
CU_TEST(cur_meminuse == ascmeminuse()); |
CU_TEST(cur_meminuse == ascmeminuse()); |
171 |
|
|
172 |
cur_meminuse = ascmeminuse(); |
cur_meminuse = ascmeminuse(); |
173 |
pvec1 = create_vector(0, -1); /* error - high < 0 */ |
pvec1 = slv_create_vector(0, -1); /* error - high < 0 */ |
174 |
CU_TEST(NULL == pvec1); |
CU_TEST(NULL == pvec1); |
175 |
|
|
176 |
destroy_vector(pvec1); |
slv_destroy_vector(pvec1); |
177 |
CU_TEST(cur_meminuse == ascmeminuse()); |
CU_TEST(cur_meminuse == ascmeminuse()); |
178 |
|
|
179 |
cur_meminuse = ascmeminuse(); |
cur_meminuse = ascmeminuse(); |
180 |
pvec1 = create_vector(10, 0); /* error - low > high */ |
pvec1 = slv_create_vector(10, 0); /* error - low > high */ |
181 |
CU_TEST(NULL == pvec1); |
CU_TEST(NULL == pvec1); |
182 |
|
|
183 |
destroy_vector(pvec1); |
slv_destroy_vector(pvec1); |
184 |
CU_TEST(cur_meminuse == ascmeminuse()); |
CU_TEST(cur_meminuse == ascmeminuse()); |
185 |
|
|
186 |
cur_meminuse = ascmeminuse(); |
cur_meminuse = ascmeminuse(); |
187 |
pvec1 = create_vector(0, 0); /* ok - low == high */ |
pvec1 = slv_create_vector(0, 0); /* ok - low == high */ |
188 |
CU_TEST_FATAL(NULL != pvec1); |
CU_TEST_FATAL(NULL != pvec1); |
189 |
CU_TEST_FATAL(NULL != pvec1->rng); |
CU_TEST_FATAL(NULL != pvec1->rng); |
190 |
CU_TEST(0 == pvec1->rng->low); |
CU_TEST(0 == pvec1->rng->low); |
201 |
CU_TEST(1 == AllocatedMemory(pvec1->vec, sizeof(real64))); |
CU_TEST(1 == AllocatedMemory(pvec1->vec, sizeof(real64))); |
202 |
#endif |
#endif |
203 |
|
|
204 |
destroy_vector(pvec1); |
slv_destroy_vector(pvec1); |
205 |
CU_TEST(0 == AllocatedMemory(pvec1, 0)); |
CU_TEST(0 == AllocatedMemory(pvec1, 0)); |
206 |
CU_TEST(cur_meminuse == ascmeminuse()); |
CU_TEST(cur_meminuse == ascmeminuse()); |
207 |
|
|
208 |
cur_meminuse = ascmeminuse(); |
cur_meminuse = ascmeminuse(); |
209 |
pvec1 = create_vector(0, 10); /* ok - low < high */ |
pvec1 = slv_create_vector(0, 10); /* ok - low < high */ |
210 |
CU_TEST_FATAL(NULL != pvec1); |
CU_TEST_FATAL(NULL != pvec1); |
211 |
CU_TEST_FATAL(NULL != pvec1->rng); |
CU_TEST_FATAL(NULL != pvec1->rng); |
212 |
CU_TEST(0 == pvec1->rng->low); |
CU_TEST(0 == pvec1->rng->low); |
223 |
CU_TEST(1 == AllocatedMemory(pvec1->vec, 11 * sizeof(real64))); |
CU_TEST(1 == AllocatedMemory(pvec1->vec, 11 * sizeof(real64))); |
224 |
#endif |
#endif |
225 |
|
|
226 |
destroy_vector(pvec1); |
slv_destroy_vector(pvec1); |
227 |
CU_TEST(0 == AllocatedMemory(pvec1, 0)); |
CU_TEST(0 == AllocatedMemory(pvec1, 0)); |
228 |
CU_TEST(cur_meminuse == ascmeminuse()); |
CU_TEST(cur_meminuse == ascmeminuse()); |
229 |
|
|
230 |
/* test init_vector() */ |
CU_TEST(test_meminuse == ascmeminuse()); |
231 |
|
|
232 |
|
/* test slv_init_vector() */ |
233 |
|
|
234 |
|
test_meminuse = ascmeminuse(); |
235 |
|
|
236 |
cur_meminuse = ascmeminuse(); |
cur_meminuse = ascmeminuse(); |
237 |
CU_TEST(2 == init_vector(NULL, 0, 10)); /* error - NULL vec */ |
CU_TEST(2 == slv_init_vector(NULL, 0, 10)); /* error - NULL vec */ |
238 |
CU_TEST(cur_meminuse == ascmeminuse()); |
CU_TEST(cur_meminuse == ascmeminuse()); |
239 |
|
|
240 |
cur_meminuse = ascmeminuse(); |
cur_meminuse = ascmeminuse(); |
244 |
pvec1->vec = NULL; |
pvec1->vec = NULL; |
245 |
pvec1->accurate = TRUE; |
pvec1->accurate = TRUE; |
246 |
|
|
247 |
CU_TEST(1 == init_vector(pvec1, -1, 10)); /* error - low < 0 */ |
CU_TEST(1 == slv_init_vector(pvec1, -1, 10)); /* error - low < 0 */ |
248 |
CU_TEST(NULL == pvec1->rng); |
CU_TEST(NULL == pvec1->rng); |
249 |
CU_TEST(NULL == pvec1->vec); |
CU_TEST(NULL == pvec1->vec); |
250 |
CU_TEST(TRUE == pvec1->accurate); |
CU_TEST(TRUE == pvec1->accurate); |
254 |
CU_TEST(1 == AllocatedMemory(pvec1, sizeof(struct vector_data))); |
CU_TEST(1 == AllocatedMemory(pvec1, sizeof(struct vector_data))); |
255 |
#endif |
#endif |
256 |
|
|
257 |
destroy_vector(pvec1); |
slv_destroy_vector(pvec1); |
258 |
CU_TEST(0 == AllocatedMemory(pvec1, 0)); |
CU_TEST(0 == AllocatedMemory(pvec1, 0)); |
259 |
CU_TEST(cur_meminuse == ascmeminuse()); |
CU_TEST(cur_meminuse == ascmeminuse()); |
260 |
|
|
265 |
pvec1->vec = NULL; |
pvec1->vec = NULL; |
266 |
pvec1->accurate = TRUE; |
pvec1->accurate = TRUE; |
267 |
|
|
268 |
CU_TEST(1 == init_vector(pvec1, 10, -1)); /* error - high < 0 */ |
CU_TEST(1 == slv_init_vector(pvec1, 10, -1)); /* error - high < 0 */ |
269 |
CU_TEST(NULL == pvec1->rng); |
CU_TEST(NULL == pvec1->rng); |
270 |
CU_TEST(NULL == pvec1->vec); |
CU_TEST(NULL == pvec1->vec); |
271 |
CU_TEST(TRUE == pvec1->accurate); |
CU_TEST(TRUE == pvec1->accurate); |
275 |
CU_TEST(1 == AllocatedMemory(pvec1, sizeof(struct vector_data))); |
CU_TEST(1 == AllocatedMemory(pvec1, sizeof(struct vector_data))); |
276 |
#endif |
#endif |
277 |
|
|
278 |
destroy_vector(pvec1); |
slv_destroy_vector(pvec1); |
279 |
CU_TEST(0 == AllocatedMemory(pvec1, 0)); |
CU_TEST(0 == AllocatedMemory(pvec1, 0)); |
280 |
CU_TEST(cur_meminuse == ascmeminuse()); |
CU_TEST(cur_meminuse == ascmeminuse()); |
281 |
|
|
286 |
pvec1->vec = NULL; |
pvec1->vec = NULL; |
287 |
pvec1->accurate = TRUE; |
pvec1->accurate = TRUE; |
288 |
|
|
289 |
CU_TEST(0 == init_vector(pvec1, 10, 10)); /* ok - low == high */ |
CU_TEST(0 == slv_init_vector(pvec1, 10, 10)); /* ok - low == high */ |
290 |
CU_TEST_FATAL(NULL != pvec1->rng); |
CU_TEST_FATAL(NULL != pvec1->rng); |
291 |
CU_TEST(10 == pvec1->rng->low); |
CU_TEST(10 == pvec1->rng->low); |
292 |
CU_TEST(10 == pvec1->rng->high); |
CU_TEST(10 == pvec1->rng->high); |
302 |
CU_TEST(1 == AllocatedMemory(pvec1->vec, 11 * sizeof(real64))); |
CU_TEST(1 == AllocatedMemory(pvec1->vec, 11 * sizeof(real64))); |
303 |
#endif |
#endif |
304 |
|
|
305 |
destroy_vector(pvec1); |
slv_destroy_vector(pvec1); |
306 |
CU_TEST(0 == AllocatedMemory(pvec1, 0)); |
CU_TEST(0 == AllocatedMemory(pvec1, 0)); |
307 |
CU_TEST(cur_meminuse == ascmeminuse()); |
CU_TEST(cur_meminuse == ascmeminuse()); |
308 |
|
|
313 |
pvec1->vec = NULL; |
pvec1->vec = NULL; |
314 |
pvec1->accurate = TRUE; |
pvec1->accurate = TRUE; |
315 |
|
|
316 |
CU_TEST(0 == init_vector(pvec1, 10, 100)); /* ok - low < high */ |
CU_TEST(0 == slv_init_vector(pvec1, 10, 100)); /* ok - low < high */ |
317 |
CU_TEST_FATAL(NULL != pvec1->rng); |
CU_TEST_FATAL(NULL != pvec1->rng); |
318 |
CU_TEST(10 == pvec1->rng->low); |
CU_TEST(10 == pvec1->rng->low); |
319 |
CU_TEST(100 == pvec1->rng->high); |
CU_TEST(100 == pvec1->rng->high); |
329 |
CU_TEST(1 == AllocatedMemory(pvec1->vec, 101 * sizeof(real64))); |
CU_TEST(1 == AllocatedMemory(pvec1->vec, 101 * sizeof(real64))); |
330 |
#endif |
#endif |
331 |
|
|
332 |
destroy_vector(pvec1); |
slv_destroy_vector(pvec1); |
333 |
CU_TEST(0 == AllocatedMemory(pvec1, 0)); |
CU_TEST(0 == AllocatedMemory(pvec1, 0)); |
334 |
CU_TEST(cur_meminuse == ascmeminuse()); |
CU_TEST(cur_meminuse == ascmeminuse()); |
335 |
|
|
336 |
cur_meminuse = ascmeminuse(); |
cur_meminuse = ascmeminuse(); |
337 |
pvec1 = create_vector(0,0); /* create a vector with data */ |
pvec1 = slv_create_vector(0,0); /* create a vector with data */ |
338 |
CU_TEST_FATAL(NULL != pvec1); |
CU_TEST_FATAL(NULL != pvec1); |
339 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
340 |
CU_TEST(2 == AllocatedMemory(pvec1, sizeof(struct vector_data))); |
CU_TEST(2 == AllocatedMemory(pvec1, sizeof(struct vector_data))); |
349 |
pvec1->accurate = TRUE; |
pvec1->accurate = TRUE; |
350 |
pvec1->vec[0] = rarray[0]; |
pvec1->vec[0] = rarray[0]; |
351 |
|
|
352 |
CU_TEST(1 == init_vector(pvec1, -1, 100)); /* error - low < 0 */ |
CU_TEST(1 == slv_init_vector(pvec1, -1, 100)); /* error - low < 0 */ |
353 |
CU_TEST_FATAL(NULL != pvec1->rng); |
CU_TEST_FATAL(NULL != pvec1->rng); |
354 |
CU_TEST(0 == pvec1->rng->low); |
CU_TEST(0 == pvec1->rng->low); |
355 |
CU_TEST(0 == pvec1->rng->high); |
CU_TEST(0 == pvec1->rng->high); |
362 |
CU_TEST(1 == AllocatedMemory(pvec1->vec, 1 * sizeof(real64))); |
CU_TEST(1 == AllocatedMemory(pvec1->vec, 1 * sizeof(real64))); |
363 |
#endif |
#endif |
364 |
|
|
365 |
CU_TEST(1 == init_vector(pvec1, 1, 0)); /* error - high < low */ |
CU_TEST(1 == slv_init_vector(pvec1, 1, 0)); /* error - high < low */ |
366 |
CU_TEST_FATAL(NULL != pvec1->rng); |
CU_TEST_FATAL(NULL != pvec1->rng); |
367 |
CU_TEST(0 == pvec1->rng->low); |
CU_TEST(0 == pvec1->rng->low); |
368 |
CU_TEST(0 == pvec1->rng->high); |
CU_TEST(0 == pvec1->rng->high); |
375 |
CU_TEST(1 == AllocatedMemory(pvec1->vec, 1 * sizeof(real64))); |
CU_TEST(1 == AllocatedMemory(pvec1->vec, 1 * sizeof(real64))); |
376 |
#endif |
#endif |
377 |
|
|
378 |
CU_TEST(0 == init_vector(pvec1, 0, 1)); /* ok - high > low */ |
CU_TEST(0 == slv_init_vector(pvec1, 0, 1)); /* ok - high > low */ |
379 |
CU_TEST_FATAL(NULL != pvec1->rng); |
CU_TEST_FATAL(NULL != pvec1->rng); |
380 |
CU_TEST(0 == pvec1->rng->low); |
CU_TEST(0 == pvec1->rng->low); |
381 |
CU_TEST(1 == pvec1->rng->high); |
CU_TEST(1 == pvec1->rng->high); |
391 |
pvec1->accurate = TRUE; |
pvec1->accurate = TRUE; |
392 |
pvec1->vec[1] = rarray[1]; |
pvec1->vec[1] = rarray[1]; |
393 |
|
|
394 |
CU_TEST(0 == init_vector(pvec1, 9, 10)); /* ok - high > low */ |
CU_TEST(0 == slv_init_vector(pvec1, 9, 10)); /* ok - high > low */ |
395 |
CU_TEST_FATAL(NULL != pvec1->rng); |
CU_TEST_FATAL(NULL != pvec1->rng); |
396 |
CU_TEST(9 == pvec1->rng->low); |
CU_TEST(9 == pvec1->rng->low); |
397 |
CU_TEST(10 == pvec1->rng->high); |
CU_TEST(10 == pvec1->rng->high); |
405 |
CU_TEST(1 == AllocatedMemory(pvec1->vec, 11 * sizeof(real64))); |
CU_TEST(1 == AllocatedMemory(pvec1->vec, 11 * sizeof(real64))); |
406 |
#endif |
#endif |
407 |
|
|
408 |
destroy_vector(pvec1); |
slv_destroy_vector(pvec1); |
409 |
CU_TEST(0 == AllocatedMemory(pvec1, 0)); |
CU_TEST(0 == AllocatedMemory(pvec1, 0)); |
410 |
CU_TEST(cur_meminuse == ascmeminuse()); |
CU_TEST(cur_meminuse == ascmeminuse()); |
411 |
|
|
412 |
|
CU_TEST(test_meminuse == ascmeminuse()); |
413 |
|
|
414 |
/* test slv_zero_vector() */ |
/* test slv_zero_vector() */ |
415 |
|
|
416 |
//#ifndef ASC_NO_ASSERTIONS |
test_meminuse = ascmeminuse(); |
417 |
// asc_assert_catch(TRUE); /* prepare to test assertions */ |
|
418 |
|
#ifndef ASC_NO_ASSERTIONS |
419 |
|
asc_assert_catch(TRUE); /* prepare to test assertions */ |
420 |
|
|
421 |
|
asc_assert_reset(); |
422 |
|
if (0 == setjmp(g_asc_test_env)) |
423 |
|
slv_zero_vector(NULL); /* error - NULL vec */ |
424 |
|
CU_TEST(TRUE == asc_assert_failed()); |
425 |
|
|
426 |
// asc_assert_reset(); |
pvec1 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); /* create a vector with NULL rng */ |
427 |
// if (0 == setjmp(g_asc_test_env)) |
CU_TEST_FATAL(NULL != pvec1); |
428 |
// slv_zero_vector(NULL); /* error - NULL vec */ |
pvec1->rng = NULL; |
429 |
// CU_TEST(TRUE == asc_assert_failed()); |
pvec1->vec = (real64 *)ascmalloc(10 * sizeof(real64)); |
430 |
|
|
431 |
// pvec1 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); /* create a vector with NULL rng */ |
asc_assert_reset(); |
432 |
// CU_TEST_FATAL(NULL != pvec1); |
if (0 == setjmp(g_asc_test_env)) |
433 |
// pvec1->rng = NULL; |
slv_zero_vector(pvec1); /* error - NULL vec->rng */ |
434 |
// pvec1->vec = (real64 *)ascmalloc(10 * sizeof(real64)); |
CU_TEST(TRUE == asc_assert_failed()); |
435 |
|
|
436 |
// asc_assert_reset(); |
pvec1->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t)); |
437 |
// if (0 == setjmp(g_asc_test_env)) |
ascfree(pvec1->vec); |
438 |
// slv_zero_vector(pvec1); /* error - NULL vec->rng */ |
pvec1->vec = NULL; |
439 |
// CU_TEST(TRUE == asc_assert_failed()); |
|
440 |
|
asc_assert_reset(); |
441 |
// pvec1->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t)); |
if (0 == setjmp(g_asc_test_env)) |
442 |
// ascfree(pvec1->vec); |
slv_zero_vector(pvec1); /* error - NULL vec->vec */ |
443 |
// pvec1->vec = NULL; |
CU_TEST(TRUE == asc_assert_failed()); |
444 |
|
|
445 |
// asc_assert_reset(); |
pvec1->vec = (real64 *)ascmalloc(10 * sizeof(real64)); |
446 |
// if (0 == setjmp(g_asc_test_env)) |
pvec1->rng->low = -1; |
447 |
// slv_zero_vector(pvec1); /* error - NULL vec->vec */ |
pvec1->rng->high = 10; |
448 |
// CU_TEST(TRUE == asc_assert_failed()); |
|
449 |
|
asc_assert_reset(); |
450 |
// pvec1->vec = (real64 *)ascmalloc(10 * sizeof(real64)); |
if (0 == setjmp(g_asc_test_env)) |
451 |
// pvec1->rng->low = -1; |
slv_zero_vector(pvec1); /* error - low < 0 */ |
452 |
// pvec1->rng->high = 10; |
CU_TEST(TRUE == asc_assert_failed()); |
|
|
|
|
// asc_assert_reset(); |
|
|
// if (0 == setjmp(g_asc_test_env)) |
|
|
// slv_zero_vector(pvec1); /* error - low < 0 */ |
|
|
// CU_TEST(TRUE == asc_assert_failed()); |
|
|
|
|
|
// pvec1->rng->low = 11; |
|
|
|
|
|
// asc_assert_reset(); |
|
|
// if (0 == setjmp(g_asc_test_env)) |
|
|
// slv_zero_vector(pvec1); /* error - low > high */ |
|
|
// CU_TEST(TRUE == asc_assert_failed()); |
|
453 |
|
|
454 |
// destroy_vector(pvec1); |
pvec1->rng->low = 11; |
455 |
|
|
456 |
// asc_assert_catch(FALSE); /* done testing assertions */ |
asc_assert_reset(); |
457 |
//#endif /* !ASC_NO_ASSERTIONS */ |
if (0 == setjmp(g_asc_test_env)) |
458 |
|
slv_zero_vector(pvec1); /* error - low > high */ |
459 |
|
CU_TEST(TRUE == asc_assert_failed()); |
460 |
|
|
461 |
pvec1 = create_vector(0,0); /* create & initialize a 1-element vector */ |
slv_destroy_vector(pvec1); |
462 |
|
|
463 |
|
asc_assert_catch(FALSE); /* done testing assertions */ |
464 |
|
#endif /* !ASC_NO_ASSERTIONS */ |
465 |
|
|
466 |
|
pvec1 = slv_create_vector(0,0); /* create & initialize a 1-element vector */ |
467 |
CU_TEST_FATAL(NULL != pvec1); |
CU_TEST_FATAL(NULL != pvec1); |
468 |
|
|
469 |
pvec1->vec[0] = rarray[0]; |
pvec1->vec[0] = rarray[0]; |
472 |
slv_zero_vector(pvec1); |
slv_zero_vector(pvec1); |
473 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], 0.0, 0.00001); |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], 0.0, 0.00001); |
474 |
|
|
475 |
CU_TEST_FATAL(0 == init_vector(pvec1, 0, 9)); /* redimension to larger vector */ |
CU_TEST_FATAL(0 == slv_init_vector(pvec1, 0, 9)); /* redimension to larger vector */ |
476 |
|
|
477 |
for (i=0 ; i<10 ; ++i) { |
for (i=0 ; i<10 ; ++i) { |
478 |
pvec1->vec[i] = rarray[i]; /* initialize & check the data */ |
pvec1->vec[i] = rarray[i]; /* initialize & check the data */ |
502 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001); |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001); |
503 |
} |
} |
504 |
|
|
505 |
destroy_vector(pvec1); |
slv_destroy_vector(pvec1); |
506 |
|
|
507 |
|
CU_TEST(test_meminuse == ascmeminuse()); |
508 |
|
|
509 |
/* test slv_copy_vector() */ |
/* test slv_copy_vector() */ |
510 |
|
|
511 |
//#ifndef ASC_NO_ASSERTIONS |
test_meminuse = ascmeminuse(); |
512 |
// asc_assert_catch(TRUE); /* prepare to test assertions */ |
|
513 |
|
#ifndef ASC_NO_ASSERTIONS |
514 |
|
asc_assert_catch(TRUE); /* prepare to test assertions */ |
515 |
|
|
516 |
// pvec1 = create_vector(0,10); |
pvec1 = slv_create_vector(0,10); |
517 |
// CU_TEST_FATAL(NULL != pvec1); |
CU_TEST_FATAL(NULL != pvec1); |
518 |
|
|
519 |
|
asc_assert_reset(); |
520 |
|
if (0 == setjmp(g_asc_test_env)) |
521 |
|
slv_copy_vector(NULL, pvec1); /* error - NULL srcvec */ |
522 |
|
CU_TEST(TRUE == asc_assert_failed()); |
523 |
|
|
524 |
|
asc_assert_reset(); |
525 |
|
if (0 == setjmp(g_asc_test_env)) |
526 |
|
slv_copy_vector(pvec1, NULL); /* error - NULL destvec */ |
527 |
|
CU_TEST(TRUE == asc_assert_failed()); |
528 |
|
|
529 |
|
pvec2 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); /* create a vector with NULL rng */ |
530 |
|
CU_TEST_FATAL(NULL != pvec2); |
531 |
|
pvec2->rng = NULL; |
532 |
|
pvec2->vec = (real64 *)ascmalloc(10 * sizeof(real64)); |
533 |
|
|
534 |
// asc_assert_reset(); |
asc_assert_reset(); |
535 |
// if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
536 |
// slv_copy_vector(NULL, pvec1); /* error - NULL srcvec */ |
slv_copy_vector(pvec2, pvec1); /* error - NULL srcvec->rng */ |
537 |
// CU_TEST(TRUE == asc_assert_failed()); |
CU_TEST(TRUE == asc_assert_failed()); |
538 |
|
|
539 |
// asc_assert_reset(); |
asc_assert_reset(); |
540 |
// if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
541 |
// slv_copy_vector(pvec1, NULL); /* error - NULL destvec */ |
slv_copy_vector(pvec1, pvec2); /* error - NULL destvec->rng */ |
542 |
// CU_TEST(TRUE == asc_assert_failed()); |
CU_TEST(TRUE == asc_assert_failed()); |
543 |
|
|
544 |
// pvec2 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); /* create a vector with NULL rng */ |
pvec2->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t)); |
545 |
// CU_TEST_FATAL(NULL != pvec2); |
ascfree(pvec2->vec); |
546 |
// pvec2->rng = NULL; |
pvec2->vec = NULL; |
547 |
// pvec2->vec = (real64 *)ascmalloc(10 * sizeof(real64)); |
|
548 |
|
asc_assert_reset(); |
549 |
// asc_assert_reset(); |
if (0 == setjmp(g_asc_test_env)) |
550 |
// if (0 == setjmp(g_asc_test_env)) |
slv_copy_vector(pvec2, pvec1); /* error - NULL srcvec->vec */ |
551 |
// slv_copy_vector(pvec2, pvec1); /* error - NULL srcvec->rng */ |
CU_TEST(TRUE == asc_assert_failed()); |
552 |
// CU_TEST(TRUE == asc_assert_failed()); |
|
553 |
|
asc_assert_reset(); |
554 |
// asc_assert_reset(); |
if (0 == setjmp(g_asc_test_env)) |
555 |
// if (0 == setjmp(g_asc_test_env)) |
slv_copy_vector(pvec1, pvec2); /* error - NULL destvec->vec */ |
556 |
// slv_copy_vector(pvec1, pvec2); /* error - NULL destvec->rng */ |
CU_TEST(TRUE == asc_assert_failed()); |
557 |
// CU_TEST(TRUE == asc_assert_failed()); |
|
558 |
|
pvec2->vec = (real64 *)ascmalloc(10 * sizeof(real64)); |
559 |
// pvec2->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t)); |
pvec2->rng->low = -1; |
560 |
// ascfree(pvec2->vec); |
pvec2->rng->high = 10; |
561 |
// pvec2->vec = NULL; |
|
562 |
|
asc_assert_reset(); |
563 |
// asc_assert_reset(); |
if (0 == setjmp(g_asc_test_env)) |
564 |
// if (0 == setjmp(g_asc_test_env)) |
slv_copy_vector(pvec2, pvec1); /* error - srcvec->rng->low < 0 */ |
565 |
// slv_copy_vector(pvec2, pvec1); /* error - NULL srcvec->vec */ |
CU_TEST(TRUE == asc_assert_failed()); |
566 |
// CU_TEST(TRUE == asc_assert_failed()); |
|
567 |
|
asc_assert_reset(); |
568 |
// asc_assert_reset(); |
if (0 == setjmp(g_asc_test_env)) |
569 |
// if (0 == setjmp(g_asc_test_env)) |
slv_copy_vector(pvec1, pvec2); /* error - destvec->rng->low < 0 */ |
570 |
// slv_copy_vector(pvec1, pvec2); /* error - NULL destvec->vec */ |
CU_TEST(TRUE == asc_assert_failed()); |
571 |
// CU_TEST(TRUE == asc_assert_failed()); |
|
572 |
|
pvec2->rng->low = 11; |
573 |
// pvec2->vec = (real64 *)ascmalloc(10 * sizeof(real64)); |
|
574 |
// pvec2->rng->low = -1; |
asc_assert_reset(); |
575 |
// pvec2->rng->high = 10; |
if (0 == setjmp(g_asc_test_env)) |
576 |
|
slv_copy_vector(pvec2, pvec1); /* error - srcvec low > high */ |
577 |
// asc_assert_reset(); |
CU_TEST(TRUE == asc_assert_failed()); |
|
// if (0 == setjmp(g_asc_test_env)) |
|
|
// slv_zero_vector(pvec2, pvec1); /* error - srcvec->rng->low < 0 */ |
|
|
// CU_TEST(TRUE == asc_assert_failed()); |
|
|
|
|
|
// asc_assert_reset(); |
|
|
// if (0 == setjmp(g_asc_test_env)) |
|
|
// slv_zero_vector(pvec1, pvec2); /* error - destvec->rng->low < 0 */ |
|
|
// CU_TEST(TRUE == asc_assert_failed()); |
|
|
|
|
|
// pvec2->rng->low = 11; |
|
|
|
|
|
// asc_assert_reset(); |
|
|
// if (0 == setjmp(g_asc_test_env)) |
|
|
// slv_copy_vector(pvec2, pvec1); /* error - srcvec low > high */ |
|
|
// CU_TEST(TRUE == asc_assert_failed()); |
|
578 |
|
|
579 |
// destroy_vector(pvec1); |
slv_destroy_vector(pvec1); |
580 |
// destroy_vector(pvec2); |
slv_destroy_vector(pvec2); |
581 |
|
|
582 |
// asc_assert_catch(FALSE); /* done testing assertions */ |
asc_assert_catch(FALSE); /* done testing assertions */ |
583 |
//#endif /* !ASC_NO_ASSERTIONS */ |
#endif /* !ASC_NO_ASSERTIONS */ |
584 |
|
|
585 |
pvec1 = create_vector(0,0); /* create & initialize a 1-element vectors */ |
pvec1 = slv_create_vector(0,0); /* create & initialize a 1-element vectors */ |
586 |
pvec2 = create_vector(0,0); |
pvec2 = slv_create_vector(0,0); |
587 |
CU_TEST_FATAL(NULL != pvec1); |
CU_TEST_FATAL(NULL != pvec1); |
588 |
|
|
589 |
pvec1->vec[0] = rarray[0]; |
pvec1->vec[0] = rarray[0]; |
595 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[0], 0.00001); |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[0], 0.00001); |
596 |
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], rarray[0], 0.00001); |
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], rarray[0], 0.00001); |
597 |
|
|
598 |
CU_TEST_FATAL(0 == init_vector(pvec1, 0, 9)); /* redimension pvec1 to larger vector */ |
CU_TEST_FATAL(0 == slv_init_vector(pvec1, 0, 9)); /* redimension pvec1 to larger vector */ |
599 |
|
|
600 |
for (i=0 ; i<10 ; ++i) { |
for (i=0 ; i<10 ; ++i) { |
601 |
pvec1->vec[i] = rarray[i]; /* initialize & check the data */ |
pvec1->vec[i] = rarray[i]; /* initialize & check the data */ |
620 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001); /* data in src should be intact */ |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001); /* data in src should be intact */ |
621 |
} |
} |
622 |
|
|
623 |
CU_TEST_FATAL(0 == init_vector(pvec2, 0, 9)); /* redimension pvec2 to larger vector */ |
CU_TEST_FATAL(0 == slv_init_vector(pvec2, 0, 9)); /* redimension pvec2 to larger vector */ |
624 |
slv_zero_vector(pvec2); /* zero the destvec */ |
slv_zero_vector(pvec2); /* zero the destvec */ |
625 |
pvec1->rng->low = 0; |
pvec1->rng->low = 0; |
626 |
pvec1->rng->high = 9; |
pvec1->rng->high = 9; |
642 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001); /* data should be the same */ |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001); /* data should be the same */ |
643 |
} |
} |
644 |
|
|
645 |
destroy_vector(pvec1); |
slv_destroy_vector(pvec1); |
646 |
destroy_vector(pvec2); |
slv_destroy_vector(pvec2); |
647 |
|
|
648 |
|
CU_TEST(test_meminuse == ascmeminuse()); |
649 |
|
|
650 |
/* test slv_inner_product() */ |
/* test slv_inner_product() */ |
651 |
|
|
652 |
//#ifndef ASC_NO_ASSERTIONS |
test_meminuse = ascmeminuse(); |
653 |
// asc_assert_catch(TRUE); /* prepare to test assertions */ |
|
654 |
|
#ifndef ASC_NO_ASSERTIONS |
655 |
|
asc_assert_catch(TRUE); /* prepare to test assertions */ |
656 |
|
|
657 |
|
pvec1 = slv_create_vector(0,10); |
658 |
|
CU_TEST_FATAL(NULL != pvec1); |
659 |
|
|
660 |
|
asc_assert_reset(); |
661 |
|
if (0 == setjmp(g_asc_test_env)) |
662 |
|
slv_inner_product(NULL, pvec1); /* error - NULL vec1 */ |
663 |
|
CU_TEST(TRUE == asc_assert_failed()); |
664 |
|
|
665 |
|
asc_assert_reset(); |
666 |
|
if (0 == setjmp(g_asc_test_env)) |
667 |
|
slv_inner_product(pvec1, NULL); /* error - NULL vec2 */ |
668 |
|
CU_TEST(TRUE == asc_assert_failed()); |
669 |
|
|
670 |
// pvec1 = create_vector(0,10); |
pvec2 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); /* create a vector with NULL rng */ |
671 |
// CU_TEST_FATAL(NULL != pvec1); |
CU_TEST_FATAL(NULL != pvec2); |
672 |
|
pvec2->rng = NULL; |
673 |
|
pvec2->vec = (real64 *)ascmalloc(10 * sizeof(real64)); |
674 |
|
|
675 |
// asc_assert_reset(); |
asc_assert_reset(); |
676 |
// if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
677 |
// slv_inner_product(NULL, pvec1); /* error - NULL vec1 */ |
slv_inner_product(pvec2, pvec1); /* error - NULL vec1->rng */ |
678 |
// CU_TEST(TRUE == asc_assert_failed()); |
CU_TEST(TRUE == asc_assert_failed()); |
679 |
|
|
680 |
// asc_assert_reset(); |
asc_assert_reset(); |
681 |
// if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
682 |
// slv_inner_product(pvec1, NULL); /* error - NULL vec2 */ |
slv_inner_product(pvec1, pvec2); /* error - NULL vec2->rng */ |
683 |
// CU_TEST(TRUE == asc_assert_failed()); |
CU_TEST(TRUE == asc_assert_failed()); |
684 |
|
|
685 |
// pvec2 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); /* create a vector with NULL rng */ |
pvec2->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t)); |
686 |
// CU_TEST_FATAL(NULL != pvec2); |
ascfree(pvec2->vec); |
687 |
// pvec2->rng = NULL; |
pvec2->vec = NULL; |
688 |
// pvec2->vec = (real64 *)ascmalloc(10 * sizeof(real64)); |
|
689 |
|
asc_assert_reset(); |
690 |
// asc_assert_reset(); |
if (0 == setjmp(g_asc_test_env)) |
691 |
// if (0 == setjmp(g_asc_test_env)) |
slv_inner_product(pvec2, pvec1); /* error - NULL vec1->vec */ |
692 |
// slv_inner_product(pvec2, pvec1); /* error - NULL vec1->rng */ |
CU_TEST(TRUE == asc_assert_failed()); |
693 |
// CU_TEST(TRUE == asc_assert_failed()); |
|
694 |
|
asc_assert_reset(); |
695 |
// asc_assert_reset(); |
if (0 == setjmp(g_asc_test_env)) |
696 |
// if (0 == setjmp(g_asc_test_env)) |
slv_inner_product(pvec1, pvec2); /* error - NULL vec2->vec */ |
697 |
// slv_inner_product(pvec1, pvec2); /* error - NULL vec2->rng */ |
CU_TEST(TRUE == asc_assert_failed()); |
698 |
// CU_TEST(TRUE == asc_assert_failed()); |
|
699 |
|
pvec2->vec = (real64 *)ascmalloc(10 * sizeof(real64)); |
700 |
// pvec2->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t)); |
pvec2->rng->low = -1; |
701 |
// ascfree(pvec2->vec); |
pvec2->rng->high = 10; |
702 |
// pvec2->vec = NULL; |
|
703 |
|
asc_assert_reset(); |
704 |
// asc_assert_reset(); |
if (0 == setjmp(g_asc_test_env)) |
705 |
// if (0 == setjmp(g_asc_test_env)) |
slv_inner_product(pvec2, pvec1); /* error - vec1->rng->low < 0 */ |
706 |
// slv_inner_product(pvec2, pvec1); /* error - NULL vec1->vec */ |
CU_TEST(TRUE == asc_assert_failed()); |
707 |
// CU_TEST(TRUE == asc_assert_failed()); |
|
708 |
|
asc_assert_reset(); |
709 |
// asc_assert_reset(); |
if (0 == setjmp(g_asc_test_env)) |
710 |
// if (0 == setjmp(g_asc_test_env)) |
slv_inner_product(pvec1, pvec2); /* error - vec2->rng->low < 0 */ |
711 |
// slv_inner_product(pvec1, pvec2); /* error - NULL vec2->vec */ |
CU_TEST(TRUE == asc_assert_failed()); |
712 |
// CU_TEST(TRUE == asc_assert_failed()); |
|
713 |
|
pvec2->rng->low = 11; |
714 |
// pvec2->vec = (real64 *)ascmalloc(10 * sizeof(real64)); |
|
715 |
// pvec2->rng->low = -1; |
asc_assert_reset(); |
716 |
// pvec2->rng->high = 10; |
if (0 == setjmp(g_asc_test_env)) |
717 |
|
slv_inner_product(pvec2, pvec1); /* error - vec1 low > high */ |
718 |
// asc_assert_reset(); |
CU_TEST(TRUE == asc_assert_failed()); |
|
// if (0 == setjmp(g_asc_test_env)) |
|
|
// slv_inner_product(pvec2, pvec1); /* error - vec1->rng->low < 0 */ |
|
|
// CU_TEST(TRUE == asc_assert_failed()); |
|
|
|
|
|
// asc_assert_reset(); |
|
|
// if (0 == setjmp(g_asc_test_env)) |
|
|
// slv_inner_product(pvec1, pvec2); /* error - vec2->rng->low < 0 */ |
|
|
// CU_TEST(TRUE == asc_assert_failed()); |
|
|
|
|
|
// pvec2->rng->low = 11; |
|
|
|
|
|
// asc_assert_reset(); |
|
|
// if (0 == setjmp(g_asc_test_env)) |
|
|
// slv_inner_product(pvec2, pvec1); /* error - vec1 low > high */ |
|
|
// CU_TEST(TRUE == asc_assert_failed()); |
|
719 |
|
|
720 |
// destroy_vector(pvec1); |
slv_destroy_vector(pvec1); |
721 |
// destroy_vector(pvec2); |
slv_destroy_vector(pvec2); |
722 |
|
|
723 |
// asc_assert_catch(FALSE); /* done testing assertions */ |
asc_assert_catch(FALSE); /* done testing assertions */ |
724 |
//#endif /* !ASC_NO_ASSERTIONS */ |
#endif /* !ASC_NO_ASSERTIONS */ |
725 |
|
|
726 |
pvec1 = create_vector(0,0); /* create & initialize a 1-element vectors */ |
pvec1 = slv_create_vector(0,0); /* create & initialize a 1-element vectors */ |
727 |
pvec2 = create_vector(0,0); |
pvec2 = slv_create_vector(0,0); |
728 |
CU_TEST_FATAL(NULL != pvec1); |
CU_TEST_FATAL(NULL != pvec1); |
729 |
CU_TEST_FATAL(NULL != pvec2); |
CU_TEST_FATAL(NULL != pvec2); |
730 |
|
|
733 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[0], 0.00001); |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[0], 0.00001); |
734 |
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], rarray[5], 0.00001); |
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], rarray[5], 0.00001); |
735 |
|
|
736 |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec1, pvec2), slow_dot_product(pvec1, pvec2), 0.00001); |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec1, pvec2), slow_inner_product(pvec1, pvec2), 0.00001); |
737 |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec2, pvec1), slow_dot_product(pvec1, pvec2), 0.00001); |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec2, pvec1), slow_inner_product(pvec1, pvec2), 0.00001); |
738 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[0], 0.00001); |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[0], 0.00001); |
739 |
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], rarray[5], 0.00001); |
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], rarray[5], 0.00001); |
740 |
|
|
741 |
CU_TEST_FATAL(0 == init_vector(pvec1, 0, 9)); /* redimension vectors larger */ |
CU_TEST_FATAL(0 == slv_init_vector(pvec1, 0, 9)); /* redimension vectors larger */ |
742 |
CU_TEST_FATAL(0 == init_vector(pvec2, 0, 9)); |
CU_TEST_FATAL(0 == slv_init_vector(pvec2, 0, 9)); |
743 |
|
|
744 |
for (i=0 ; i<10 ; ++i) { |
for (i=0 ; i<10 ; ++i) { |
745 |
pvec1->vec[i] = rarray[i]; /* initialize & check the data */ |
pvec1->vec[i] = rarray[i]; /* initialize & check the data */ |
746 |
pvec2->vec[i] = 2.0; |
pvec2->vec[i] = 2.0; |
747 |
} |
} |
748 |
/* check entire vectors */ |
/* check entire vectors */ |
749 |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec1, pvec2), slow_dot_product(pvec1, pvec2), 0.00001); |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec1, pvec2), slow_inner_product(pvec1, pvec2), 0.00001); |
750 |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec2, pvec1), slow_dot_product(pvec1, pvec2), 0.00001); |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec2, pvec1), slow_inner_product(pvec1, pvec2), 0.00001); |
751 |
|
|
752 |
pvec1->rng->low = 9; |
pvec1->rng->low = 9; |
753 |
pvec1->rng->high = 9; |
pvec1->rng->high = 9; |
754 |
pvec2->rng->low = 5; |
pvec2->rng->low = 5; |
755 |
pvec2->rng->high = 5; /* check 1 element subrange */ |
pvec2->rng->high = 5; /* check 1 element subrange */ |
756 |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec1, pvec2), slow_dot_product(pvec1, pvec2), 0.00001); |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec1, pvec2), slow_inner_product(pvec1, pvec2), 0.00001); |
757 |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec2, pvec1), slow_dot_product(pvec1, pvec2), 0.00001); |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec2, pvec1), slow_inner_product(pvec1, pvec2), 0.00001); |
758 |
|
|
759 |
pvec1->rng->low = 0; |
pvec1->rng->low = 0; |
760 |
pvec1->rng->high = 3; |
pvec1->rng->high = 3; |
761 |
pvec2->rng->low = 2; |
pvec2->rng->low = 2; |
762 |
pvec2->rng->high = 5; /* check 4 element subrange */ |
pvec2->rng->high = 5; /* check 4 element subrange */ |
763 |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec1, pvec2), slow_dot_product(pvec1, pvec2), 0.00001); |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec1, pvec2), slow_inner_product(pvec1, pvec2), 0.00001); |
764 |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec2, pvec1), slow_dot_product(pvec1, pvec2), 0.00001); |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec2, pvec1), slow_inner_product(pvec1, pvec2), 0.00001); |
765 |
|
|
766 |
for (i=1 ; i<10 ; ++i) { |
for (i=1 ; i<10 ; ++i) { |
767 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001); /* data in vecs should be intact */ |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001); /* data in vecs should be intact */ |
773 |
pvec2->vec[i] = rarray[9-i]; |
pvec2->vec[i] = rarray[9-i]; |
774 |
} |
} |
775 |
/* check entire vectors */ |
/* check entire vectors */ |
776 |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec1, pvec2), slow_dot_product(pvec1, pvec2), 0.00001); |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec1, pvec2), slow_inner_product(pvec1, pvec2), 0.00001); |
777 |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec2, pvec1), slow_dot_product(pvec1, pvec2), 0.00001); |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec2, pvec1), slow_inner_product(pvec1, pvec2), 0.00001); |
778 |
|
|
779 |
destroy_vector(pvec1); |
slv_destroy_vector(pvec1); |
780 |
destroy_vector(pvec2); |
slv_destroy_vector(pvec2); |
781 |
|
|
782 |
|
CU_TEST(test_meminuse == ascmeminuse()); |
783 |
|
|
784 |
/* test slv_square_norm() */ |
/* test slv_square_norm() */ |
785 |
|
|
786 |
//#ifndef ASC_NO_ASSERTIONS |
test_meminuse = ascmeminuse(); |
787 |
// asc_assert_catch(TRUE); /* prepare to test assertions */ |
|
788 |
|
#ifndef ASC_NO_ASSERTIONS |
789 |
|
asc_assert_catch(TRUE); /* prepare to test assertions */ |
790 |
|
|
791 |
|
asc_assert_reset(); |
792 |
|
if (0 == setjmp(g_asc_test_env)) |
793 |
|
slv_square_norm(NULL); /* error - NULL vec */ |
794 |
|
CU_TEST(TRUE == asc_assert_failed()); |
795 |
|
|
796 |
|
pvec1 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); /* create a vector with NULL rng */ |
797 |
|
CU_TEST_FATAL(NULL != pvec1); |
798 |
|
pvec1->rng = NULL; |
799 |
|
pvec1->vec = (real64 *)ascmalloc(10 * sizeof(real64)); |
800 |
|
|
801 |
|
asc_assert_reset(); |
802 |
|
if (0 == setjmp(g_asc_test_env)) |
803 |
|
slv_square_norm(pvec1); /* error - NULL vec->rng */ |
804 |
|
CU_TEST(TRUE == asc_assert_failed()); |
805 |
|
|
806 |
|
pvec1->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t)); |
807 |
|
ascfree(pvec1->vec); |
808 |
|
pvec1->vec = NULL; |
809 |
|
|
810 |
|
asc_assert_reset(); |
811 |
|
if (0 == setjmp(g_asc_test_env)) |
812 |
|
slv_square_norm(pvec1); /* error - NULL vec->vec */ |
813 |
|
CU_TEST(TRUE == asc_assert_failed()); |
814 |
|
|
815 |
// asc_assert_reset(); |
pvec1->vec = (real64 *)ascmalloc(10 * sizeof(real64)); |
816 |
// if (0 == setjmp(g_asc_test_env)) |
pvec1->rng->low = -1; |
817 |
// slv_square_norm(NULL); /* error - NULL vec */ |
pvec1->rng->high = 10; |
|
// CU_TEST(TRUE == asc_assert_failed()); |
|
|
|
|
|
// pvec1 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); /* create a vector with NULL rng */ |
|
|
// CU_TEST_FATAL(NULL != pvec1); |
|
|
// pvec1->rng = NULL; |
|
|
// pvec1->vec = (real64 *)ascmalloc(10 * sizeof(real64)); |
|
|
|
|
|
// asc_assert_reset(); |
|
|
// if (0 == setjmp(g_asc_test_env)) |
|
|
// slv_square_norm(pvec1); /* error - NULL vec->rng */ |
|
|
// CU_TEST(TRUE == asc_assert_failed()); |
|
|
|
|
|
// pvec1->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t)); |
|
|
// ascfree(pvec1->vec); |
|
|
// pvec1->vec = NULL; |
|
|
|
|
|
// asc_assert_reset(); |
|
|
// if (0 == setjmp(g_asc_test_env)) |
|
|
// slv_square_norm(pvec1); /* error - NULL vec->vec */ |
|
|
// CU_TEST(TRUE == asc_assert_failed()); |
|
|
|
|
|
// pvec1->vec = (real64 *)ascmalloc(10 * sizeof(real64)); |
|
|
// pvec1->rng->low = -1; |
|
|
// pvec1->rng->high = 10; |
|
|
|
|
|
// asc_assert_reset(); |
|
|
// if (0 == setjmp(g_asc_test_env)) |
|
|
// slv_square_norm(pvec1); /* error - vec->rng->low < 0 */ |
|
|
// CU_TEST(TRUE == asc_assert_failed()); |
|
|
|
|
|
// pvec1->rng->low = 11; |
|
|
|
|
|
// asc_assert_reset(); |
|
|
// if (0 == setjmp(g_asc_test_env)) |
|
|
// slv_square_norm(pvec1); /* error - vec low > high */ |
|
|
// CU_TEST(TRUE == asc_assert_failed()); |
|
818 |
|
|
819 |
// destroy_vector(pvec1); |
asc_assert_reset(); |
820 |
|
if (0 == setjmp(g_asc_test_env)) |
821 |
|
slv_square_norm(pvec1); /* error - vec->rng->low < 0 */ |
822 |
|
CU_TEST(TRUE == asc_assert_failed()); |
823 |
|
|
824 |
// asc_assert_catch(FALSE); /* done testing assertions */ |
pvec1->rng->low = 11; |
|
//#endif /* !ASC_NO_ASSERTIONS */ |
|
825 |
|
|
826 |
pvec1 = create_vector(0,0); /* create & initialize a 1-element vector */ |
asc_assert_reset(); |
827 |
|
if (0 == setjmp(g_asc_test_env)) |
828 |
|
slv_square_norm(pvec1); /* error - vec low > high */ |
829 |
|
CU_TEST(TRUE == asc_assert_failed()); |
830 |
|
|
831 |
|
slv_destroy_vector(pvec1); |
832 |
|
|
833 |
|
asc_assert_catch(FALSE); /* done testing assertions */ |
834 |
|
#endif /* !ASC_NO_ASSERTIONS */ |
835 |
|
|
836 |
|
pvec1 = slv_create_vector(0,0); /* create & initialize a 1-element vector */ |
837 |
CU_TEST_FATAL(NULL != pvec1); |
CU_TEST_FATAL(NULL != pvec1); |
838 |
|
|
839 |
pvec1->vec[0] = 0.0; |
pvec1->vec[0] = 0.0; |
840 |
CU_ASSERT_DOUBLE_EQUAL(slv_square_norm(pvec1), slow_dot_product(pvec1, pvec1), 0.00001); |
CU_ASSERT_DOUBLE_EQUAL(slv_square_norm(pvec1), slow_inner_product(pvec1, pvec1), 0.00001); |
841 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], 0.0, 0.00001); |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], 0.0, 0.00001); |
842 |
|
|
843 |
pvec1->vec[0] = rarray[7]; |
pvec1->vec[0] = rarray[7]; |
844 |
CU_ASSERT_DOUBLE_EQUAL(slv_square_norm(pvec1), slow_dot_product(pvec1, pvec1), 0.00001); |
CU_ASSERT_DOUBLE_EQUAL(slv_square_norm(pvec1), slow_inner_product(pvec1, pvec1), 0.00001); |
845 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[7], 0.00001); |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[7], 0.00001); |
846 |
|
|
847 |
CU_TEST_FATAL(0 == init_vector(pvec1, 0, 9)); /* redimension vectors larger */ |
CU_TEST_FATAL(0 == slv_init_vector(pvec1, 0, 9)); /* redimension vectors larger */ |
848 |
|
|
849 |
for (i=0 ; i<10 ; ++i) { |
for (i=0 ; i<10 ; ++i) { |
850 |
pvec1->vec[i] = rarray[i]; /* initialize the data */ |
pvec1->vec[i] = rarray[i]; /* initialize the data */ |
851 |
} |
} |
852 |
/* check entire vectors */ |
/* check entire vectors */ |
853 |
CU_ASSERT_DOUBLE_EQUAL(slv_square_norm(pvec1), slow_dot_product(pvec1, pvec1), 0.00001); |
CU_ASSERT_DOUBLE_EQUAL(slv_square_norm(pvec1), slow_inner_product(pvec1, pvec1), 0.00001); |
854 |
|
|
855 |
pvec1->rng->low = 9; |
pvec1->rng->low = 9; |
856 |
pvec1->rng->high = 9; |
pvec1->rng->high = 9; |
857 |
CU_ASSERT_DOUBLE_EQUAL(slv_square_norm(pvec1), slow_dot_product(pvec1, pvec1), 0.00001); |
CU_ASSERT_DOUBLE_EQUAL(slv_square_norm(pvec1), slow_inner_product(pvec1, pvec1), 0.00001); |
858 |
|
|
859 |
pvec1->rng->low = 0; |
pvec1->rng->low = 0; |
860 |
pvec1->rng->high = 3; |
pvec1->rng->high = 3; |
861 |
CU_ASSERT_DOUBLE_EQUAL(slv_square_norm(pvec1), slow_dot_product(pvec1, pvec1), 0.00001); |
CU_ASSERT_DOUBLE_EQUAL(slv_square_norm(pvec1), slow_inner_product(pvec1, pvec1), 0.00001); |
862 |
|
|
863 |
for (i=1 ; i<10 ; ++i) { |
for (i=1 ; i<10 ; ++i) { |
864 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001); /* data in vecs should be intact */ |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001); /* data in vecs should be intact */ |
865 |
} |
} |
866 |
slv_write_vector(stdout, pvec1); |
|
867 |
destroy_vector(pvec1); |
slv_destroy_vector(pvec1); |
868 |
|
|
869 |
|
CU_TEST(test_meminuse == ascmeminuse()); |
870 |
|
|
871 |
/* test slv_matrix_product() */ |
/* test slv_matrix_product() */ |
872 |
|
|
873 |
|
test_meminuse = ascmeminuse(); |
874 |
|
|
875 |
|
#ifndef ASC_NO_ASSERTIONS |
876 |
|
asc_assert_catch(TRUE); /* prepare to test assertions */ |
877 |
|
|
878 |
mtx = mtx_create(); |
mtx = mtx_create(); |
879 |
|
CU_TEST_FATAL(NULL != mtx); |
880 |
|
mtx_set_order(mtx, 10); |
881 |
|
pvec1 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); |
882 |
|
CU_TEST_FATAL(NULL != pvec1); |
883 |
|
pvec1->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t)); |
884 |
|
pvec1->rng->low = 0; |
885 |
|
pvec1->rng->high = 10; |
886 |
|
pvec1->vec = (real64 *)ascmalloc(11 * sizeof(real64)); |
887 |
|
pvec2 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); |
888 |
|
CU_TEST_FATAL(NULL != pvec2); |
889 |
|
pvec2->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t)); |
890 |
|
pvec2->rng->low = 0; |
891 |
|
pvec2->rng->high = 10; |
892 |
|
pvec2->vec = (real64 *)ascmalloc(11 * sizeof(real64)); |
893 |
|
|
894 |
|
asc_assert_reset(); |
895 |
|
if (0 == setjmp(g_asc_test_env)) |
896 |
|
slv_matrix_product(NULL, pvec1, pvec2, 1.0, FALSE); /* error - NULL mtx */ |
897 |
|
CU_TEST(TRUE == asc_assert_failed()); |
898 |
|
|
899 |
|
asc_assert_reset(); |
900 |
|
if (0 == setjmp(g_asc_test_env)) |
901 |
|
slv_matrix_product(mtx, NULL, pvec2, 1.0, FALSE); /* error - NULL vec */ |
902 |
|
CU_TEST(TRUE == asc_assert_failed()); |
903 |
|
|
904 |
|
asc_assert_reset(); |
905 |
|
if (0 == setjmp(g_asc_test_env)) |
906 |
|
slv_matrix_product(mtx, pvec1, NULL, 1.0, FALSE); /* error - NULL prod */ |
907 |
|
CU_TEST(TRUE == asc_assert_failed()); |
908 |
|
|
909 |
|
ascfree(pvec1->rng); |
910 |
|
pvec1->rng = NULL; |
911 |
|
|
912 |
|
asc_assert_reset(); |
913 |
|
if (0 == setjmp(g_asc_test_env)) |
914 |
|
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* error - NULL vec->rng */ |
915 |
|
CU_TEST(TRUE == asc_assert_failed()); |
916 |
|
|
917 |
|
pvec1->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t)); |
918 |
|
pvec1->rng->low = 0; |
919 |
|
pvec1->rng->high = 10; |
920 |
|
ascfree(pvec2->rng); |
921 |
|
pvec2->rng = NULL; |
922 |
|
|
923 |
|
asc_assert_reset(); |
924 |
|
if (0 == setjmp(g_asc_test_env)) |
925 |
|
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* error - NULL prod->rng */ |
926 |
|
CU_TEST(TRUE == asc_assert_failed()); |
927 |
|
|
928 |
|
pvec2->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t)); |
929 |
|
pvec2->rng->low = 0; |
930 |
|
pvec2->rng->high = 10; |
931 |
|
ascfree(pvec1->vec); |
932 |
|
pvec1->vec = NULL; |
933 |
|
|
934 |
|
asc_assert_reset(); |
935 |
|
if (0 == setjmp(g_asc_test_env)) |
936 |
|
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* error - NULL vec->vec */ |
937 |
|
CU_TEST(TRUE == asc_assert_failed()); |
938 |
|
|
939 |
|
pvec1->vec = (real64 *)ascmalloc(11 * sizeof(real64)); |
940 |
|
ascfree(pvec2->vec); |
941 |
|
pvec2->vec = NULL; |
942 |
|
|
943 |
|
asc_assert_reset(); |
944 |
|
if (0 == setjmp(g_asc_test_env)) |
945 |
|
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* error - NULL prod->vec */ |
946 |
|
CU_TEST(TRUE == asc_assert_failed()); |
947 |
|
|
948 |
|
pvec2->vec = (real64 *)ascmalloc(11 * sizeof(real64)); |
949 |
|
pvec1->rng->low = -1; |
950 |
|
pvec1->rng->high = 10; |
951 |
|
|
952 |
|
asc_assert_reset(); |
953 |
|
if (0 == setjmp(g_asc_test_env)) |
954 |
|
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* error - vec low < 0 */ |
955 |
|
CU_TEST(TRUE == asc_assert_failed()); |
956 |
|
|
957 |
|
pvec1->rng->low = 11; |
958 |
|
|
959 |
|
asc_assert_reset(); |
960 |
|
if (0 == setjmp(g_asc_test_env)) |
961 |
|
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* error - vec low > high */ |
962 |
|
CU_TEST(TRUE == asc_assert_failed()); |
963 |
|
|
964 |
|
pvec1->rng->low = 0; |
965 |
|
pvec1->rng->high = 10; |
966 |
|
pvec2->rng->low = -1; |
967 |
|
pvec2->rng->high = 10; |
968 |
|
|
969 |
|
asc_assert_reset(); |
970 |
|
if (0 == setjmp(g_asc_test_env)) |
971 |
|
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* error - prod low < 0 */ |
972 |
|
CU_TEST(TRUE == asc_assert_failed()); |
973 |
|
|
974 |
|
pvec2->rng->low = 11; |
975 |
|
|
976 |
|
asc_assert_reset(); |
977 |
|
if (0 == setjmp(g_asc_test_env)) |
978 |
|
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* error - prod low > high */ |
979 |
|
CU_TEST(TRUE == asc_assert_failed()); |
980 |
|
|
981 |
mtx_destroy(mtx); |
mtx_destroy(mtx); |
982 |
|
slv_destroy_vector(pvec1); |
983 |
|
slv_destroy_vector(pvec2); |
984 |
|
|
985 |
/* |
asc_assert_catch(FALSE); /* done testing assertions */ |
986 |
|
#endif /* !ASC_NO_ASSERTIONS */ |
987 |
|
|
988 |
extern void slv_matrix_product(mtx_matrix_t mtx, |
mtx = mtx_create(); |
989 |
struct vector_data *vec, |
mtx_set_order(mtx, 10); |
|
struct vector_data *prod, |
|
|
real64 scale, |
|
|
boolean transpose); |
|
|
|
|
|
* Calculates the product of a vector, matrix, and scale factor. |
|
|
* Stores prod := (scale)*(mtx)*(vec) if transpose = FALSE, |
|
|
* or prod := (scale)*(mtx-transpose)(vec) if transpose = TRUE. |
|
|
* vec and prod must be completely different. |
|
|
* If (!transpose) vec->vec is assumed indexed by current col and |
|
|
* prod->vec is indexed by current row of mtx. |
|
|
* If (transpose) vec->vec is assumed indexed by current row and |
|
|
* prod->vec is indexed by current col of mtx. |
|
|
* The following are not allowed and are checked by assertion: |
|
|
* - NULL mtx |
|
|
* - NULL vec |
|
|
* - NULL vec->rng |
|
|
* - NULL vec->vec |
|
|
* - vec->rng->low < 0 |
|
|
* - vec->rng->low > vec->rng->high |
|
|
* - NULL prod |
|
|
* - NULL prod->rng |
|
|
* - NULL prod->vec |
|
|
* - prod->rng->low < 0 |
|
|
* - prod->rng->low > prod->rng->high |
|
|
* |
|
|
* @param mtx The matrix for the product. |
|
|
* @param vec The vector for the product. |
|
|
* @param prod The vector to receive the matrix product. |
|
|
* @param scale The scale factor by which to multiply the matrix product. |
|
|
* @param transpose Flag for whether to use mtx or its transpose. |
|
|
* |
|
|
* @todo solver/slv_common:slv_mtx_product needs attention - |
|
|
* does it go into mtx? |
|
990 |
|
|
991 |
|
pvec1 = slv_create_vector(0,0); |
992 |
|
pvec1->vec[0] = 10.0; |
993 |
|
|
994 |
extern void slv_write_vector(FILE *fp, struct vector_data *vec); |
pvec2 = slv_create_vector(0,0); |
995 |
* Write vector information to a file stream. |
pvec3 = slv_create_vector(0,0); |
|
* Prints general information about the vector followed by the |
|
|
* values in the range of the vector to file fp. |
|
|
* |
|
|
* @param fp The file stream to receive the report. |
|
|
* @param vec The vector on which to report. |
|
996 |
|
|
997 |
|
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* mtx with all zero's */ |
998 |
|
slow_vector_matrix_product(mtx, pvec1, pvec3, 1.0); /* 1-element vector */ |
999 |
|
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], pvec3->vec[0], 0.000001); |
1000 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[0], 0.000001); |
1001 |
|
|
1002 |
|
mtx_fill_value(mtx, mtx_coord(&coord,0,0), 20.0); |
1003 |
|
|
1004 |
|
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* normal mtx */ |
1005 |
|
slow_vector_matrix_product(mtx, pvec1, pvec3, 1.0); /* 1-element vector */ |
1006 |
|
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], pvec3->vec[0], 0.000001); |
1007 |
|
CU_ASSERT_DOUBLE_EQUAL(200.0, pvec2->vec[0], 0.000001); |
1008 |
|
|
1009 |
|
slv_matrix_product(mtx, pvec1, pvec2, 1.0, TRUE); /* transpose should have no effect */ |
1010 |
|
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], pvec3->vec[0], 0.000001); |
1011 |
|
CU_ASSERT_DOUBLE_EQUAL(200.0, pvec2->vec[0], 0.000001); |
1012 |
|
|
1013 |
|
mtx_clear(mtx); |
1014 |
|
|
1015 |
|
slv_init_vector(pvec1,0,1); |
1016 |
|
pvec1->vec[0] = 10.0; |
1017 |
|
pvec1->vec[1] = 20.5; |
1018 |
|
|
1019 |
|
slv_init_vector(pvec2, 0,1); |
1020 |
|
slv_init_vector(pvec3, 0,1); |
1021 |
|
|
1022 |
|
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* empty mtx */ |
1023 |
|
slow_vector_matrix_product(mtx, pvec1, pvec3, 1.0); /* 2-element vector */ |
1024 |
|
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], pvec3->vec[0], 0.000001); |
1025 |
|
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[1], pvec3->vec[1], 0.000001); |
1026 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[0], 0.000001); |
1027 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[1], 0.000001); |
1028 |
|
|
1029 |
|
mtx_fill_value(mtx, mtx_coord(&coord,0,0), 20.0); |
1030 |
|
mtx_fill_value(mtx, mtx_coord(&coord,0,1), 0.5); |
1031 |
|
mtx_fill_value(mtx, mtx_coord(&coord,1,1), -0.455); |
1032 |
|
|
1033 |
|
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* normal mtx, but not all non-zeros */ |
1034 |
|
slow_vector_matrix_product(mtx, pvec1, pvec3, 1.0); /* 2-element vector */ |
1035 |
|
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], pvec3->vec[0], 0.000001); |
1036 |
|
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[1], pvec3->vec[1], 0.000001); |
1037 |
|
|
1038 |
|
slv_matrix_product(mtx, pvec1, pvec2, 1.0, TRUE); /* transpose of normal mtx, not all non-zeros */ |
1039 |
|
|
1040 |
|
mtx_clear(mtx); |
1041 |
|
mtx_fill_value(mtx, mtx_coord(&coord,0,0), 20.0); |
1042 |
|
mtx_fill_value(mtx, mtx_coord(&coord,1,0), 0.5); |
1043 |
|
mtx_fill_value(mtx, mtx_coord(&coord,1,1), -0.455); |
1044 |
|
|
1045 |
|
slow_vector_matrix_product(mtx, pvec1, pvec3, 1.0); /* confirm transpose works */ |
1046 |
|
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], pvec3->vec[0], 0.000001); |
1047 |
|
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[1], pvec3->vec[1], 0.000001); |
1048 |
|
|
1049 |
|
slv_init_vector(pvec1,0,10); |
1050 |
|
pvec1->vec[0] = 10.0; |
1051 |
|
pvec1->vec[1] = 20.0; |
1052 |
|
pvec1->vec[2] = 30.0; |
1053 |
|
pvec1->vec[3] = 40.0; |
1054 |
|
pvec1->vec[4] = 50.0; |
1055 |
|
pvec1->vec[5] = 60.0; |
1056 |
|
pvec1->vec[6] = 70.0; |
1057 |
|
pvec1->vec[7] = 80.0; |
1058 |
|
pvec1->vec[8] = 90.0; |
1059 |
|
pvec1->vec[9] = 100.0; |
1060 |
|
pvec1->vec[10] = 110.0; |
1061 |
|
pvec1->rng->low = 2; /* only use a subset of vector */ |
1062 |
|
pvec1->rng->high = 4; |
1063 |
|
|
1064 |
|
slv_init_vector(pvec2, 0,10); |
1065 |
|
slv_init_vector(pvec3, 0,10); |
1066 |
|
for (i=0 ; i<11 ; ++i) { /* zero product vecs so can detect subset */ |
1067 |
|
pvec2->vec[i] = 0.0; |
1068 |
|
pvec3->vec[i] = 0.0; |
1069 |
|
} |
1070 |
|
|
1071 |
|
mtx_clear(mtx); |
1072 |
|
mtx_fill_value(mtx, mtx_coord(&coord,2,2), 1.0); /* only give values in vector range */ |
1073 |
|
mtx_fill_value(mtx, mtx_coord(&coord,2,3), 1.0); |
1074 |
|
mtx_fill_value(mtx, mtx_coord(&coord,2,4), 1.0); |
1075 |
|
mtx_fill_value(mtx, mtx_coord(&coord,3,2), 2.0); |
1076 |
|
mtx_fill_value(mtx, mtx_coord(&coord,3,3), 2.0); |
1077 |
|
mtx_fill_value(mtx, mtx_coord(&coord,3,4), 2.0); |
1078 |
|
mtx_fill_value(mtx, mtx_coord(&coord,4,2), 3.0); |
1079 |
|
mtx_fill_value(mtx, mtx_coord(&coord,4,3), 3.0); |
1080 |
|
mtx_fill_value(mtx, mtx_coord(&coord,4,4), 3.0); |
1081 |
|
|
1082 |
|
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* normal mtx */ |
1083 |
|
slow_vector_matrix_product(mtx, pvec1, pvec3, 1.0); /* vector subset*/ |
1084 |
|
|
1085 |
|
for (i=0 ; i<11 ; ++i) { |
1086 |
|
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[i], pvec3->vec[i], 0.000001); |
1087 |
|
} |
1088 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[0], 0.000001); |
1089 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[1], 0.000001); |
1090 |
|
CU_ASSERT_DOUBLE_EQUAL(120.0, pvec2->vec[2], 0.000001); |
1091 |
|
CU_ASSERT_DOUBLE_EQUAL(240.0, pvec2->vec[3], 0.000001); |
1092 |
|
CU_ASSERT_DOUBLE_EQUAL(360.0, pvec2->vec[4], 0.000001); |
1093 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[5], 0.000001); |
1094 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[6], 0.000001); |
1095 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[7], 0.000001); |
1096 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[8], 0.000001); |
1097 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[9], 0.000001); |
1098 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[10], 0.000001); |
1099 |
|
|
1100 |
|
slv_matrix_product(mtx, pvec1, pvec2, 0.5, FALSE); /* different scale */ |
1101 |
|
|
1102 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[0], 0.000001); |
1103 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[1], 0.000001); |
1104 |
|
CU_ASSERT_DOUBLE_EQUAL(60.0, pvec2->vec[2], 0.000001); |
1105 |
|
CU_ASSERT_DOUBLE_EQUAL(120.0, pvec2->vec[3], 0.000001); |
1106 |
|
CU_ASSERT_DOUBLE_EQUAL(180.0, pvec2->vec[4], 0.000001); |
1107 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[5], 0.000001); |
1108 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[6], 0.000001); |
1109 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[7], 0.000001); |
1110 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[8], 0.000001); |
1111 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[9], 0.000001); |
1112 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[10], 0.000001); |
1113 |
|
|
1114 |
|
slv_matrix_product(mtx, pvec1, pvec2, 1.0, TRUE); /* transpose */ |
1115 |
|
|
1116 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[0], 0.000001); |
1117 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[1], 0.000001); |
1118 |
|
CU_ASSERT_DOUBLE_EQUAL(260.0, pvec2->vec[2], 0.000001); |
1119 |
|
CU_ASSERT_DOUBLE_EQUAL(260.0, pvec2->vec[3], 0.000001); |
1120 |
|
CU_ASSERT_DOUBLE_EQUAL(260.0, pvec2->vec[4], 0.000001); |
1121 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[5], 0.000001); |
1122 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[6], 0.000001); |
1123 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[7], 0.000001); |
1124 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[8], 0.000001); |
1125 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[9], 0.000001); |
1126 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[10], 0.000001); |
1127 |
|
|
1128 |
|
slv_matrix_product(mtx, pvec1, pvec2, 2.0, TRUE); /* transpose */ |
1129 |
|
|
1130 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[0], 0.000001); |
1131 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[1], 0.000001); |
1132 |
|
CU_ASSERT_DOUBLE_EQUAL(520.0, pvec2->vec[2], 0.000001); |
1133 |
|
CU_ASSERT_DOUBLE_EQUAL(520.0, pvec2->vec[3], 0.000001); |
1134 |
|
CU_ASSERT_DOUBLE_EQUAL(520.0, pvec2->vec[4], 0.000001); |
1135 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[5], 0.000001); |
1136 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[6], 0.000001); |
1137 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[7], 0.000001); |
1138 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[8], 0.000001); |
1139 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[9], 0.000001); |
1140 |
|
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[10], 0.000001); |
1141 |
|
|
1142 |
extern real64 slv_dot(int32 len, const real64 *a1, const real64 *a2); |
mtx_destroy(mtx); |
1143 |
|
slv_destroy_vector(pvec1); |
1144 |
|
slv_destroy_vector(pvec2); |
1145 |
|
slv_destroy_vector(pvec3); |
1146 |
|
|
1147 |
* Calculates the dot product of 2 arrays of real64. |
CU_TEST(test_meminuse == ascmeminuse()); |
|
* This is an optimized routine (loop unrolled). It takes |
|
|
* advantage of identical vectors. The 2 arrays must have |
|
|
* at least len elements. |
|
|
* The following are not allowed and are checked by assertion: |
|
|
* - NULL a1 |
|
|
* - NULL a2 |
|
|
* - len < 0 |
|
|
* |
|
|
* The same algorithm is used inside slv_inner_product(), so there |
|
|
* is no need to use this function directly if you are using the |
|
|
* vector_data type. |
|
|
* |
|
|
* @param len The length of the 2 arrays. |
|
|
* @param a1 The 1st array for the dot product. |
|
|
* @param a2 The 2nd array for the dot product. |
|
|
* @param a2 The 2nd array for the dot product. |
|
|
|
|
|
* -------------------------------- |
|
|
* General input/output routines |
|
|
* -------------------------------- |
|
1148 |
|
|
1149 |
extern FILE *slv_get_output_file(FILE *fp); |
/* test slv_write_vector() - not much to do but make sure something gets written */ |
|
*< |
|
|
* Checks a file pointer, and if NULL returns a pointer to the nul device. |
|
|
* If you are in environment that doesn't have something like |
|
|
* /dev/null (nul on Windows), you'd better be damn sure your |
|
|
* sys->p.output.*_important are not NULL. |
|
|
* |
|
|
* @param fp The file stream to check. |
|
|
* @return fp if it is not NULL, a pointer to the nul device otherwise. |
|
|
|
|
1150 |
|
|
1151 |
|
test_meminuse = ascmeminuse(); |
1152 |
|
|
1153 |
* FILE pointer macros. |
pvec1 = slv_create_vector(0,10); |
|
* fp = MIF(sys) |
|
|
* fp = LIF(sys) |
|
|
* fp = PMIF(sys) |
|
|
* fp = PLIF(sys) |
|
|
* or fprintf(MIF(sys),"stuff",data...); |
|
|
* Use of these is requested on grounds of readability but not required. |
|
|
* MIF and LIF are macros, which means any specific solver interface |
|
|
* to ASCEND can use them, since all interfaces are supposed to |
|
|
* support a parameters structure p somewhere in a larger system |
|
|
* structure (sys) they keep privately. |
|
|
* Use the PMIF or PLIF flavors if the parameters sys->p is a pointer |
|
|
* rather than a in-struct member. |
|
|
|
|
|
#define MIF(sys) slv_get_output_file( (sys)->p.output.more_important ) |
|
|
*< |
|
|
* Retrieve the "more important" output file for a system. |
|
|
* sys must exist and contain an element p of type slv_parameters_t. |
|
|
* |
|
|
* @param sys The slv_system_t to query. |
|
|
* @return A FILE * to the "more important" output file for sys. |
|
|
|
|
|
#define LIF(sys) slv_get_output_file( (sys)->p.output.less_important ) |
|
|
*< |
|
|
* Retrieve the "less important" output file for a system. |
|
|
* sys must exist and contain an element p of type slv_parameters_t. |
|
|
* |
|
|
* @param sys The slv_system_t to query. |
|
|
* @return A FILE * to the "less important" output file for sys. |
|
|
|
|
|
#define PMIF(sys) slv_get_output_file( (sys)->p->output.more_important ) |
|
|
*< |
|
|
* Retrieve the "more important" output file for a system. |
|
|
* sys must exist and contain an element p of type slv_parameters_t*. |
|
|
* |
|
|
* @param sys The slv_system_t to query. |
|
|
* @return A FILE * to the "more important" output file for sys. |
|
|
|
|
|
#define PLIF(sys) slv_get_output_file( (sys)->p->output.less_important ) |
|
|
*< |
|
|
* Retrieve the "less important" output file for a system. |
|
|
* sys must exist and contain an element p of type slv_parameters_t*. |
|
|
* |
|
|
* @param sys The slv_system_t to query. |
|
|
* @return A FILE * to the "less important" output file for sys. |
|
|
|
|
1154 |
|
|
1155 |
------------------- begin compiler dependent functions ------------------- |
if (FALSE == test_printing_enabled()) { |
1156 |
#if SLV_INSTANCES |
test_enable_printing(); |
1157 |
|
i_enabled_printing = TRUE; |
1158 |
|
} |
1159 |
|
|
1160 |
#ifdef NEWSTUFF |
if (NULL != (file_normal = fopen("slvcommontempfile1.tmp", "w+"))) { |
1161 |
extern void slv_print_obj_name(FILE *outfile, obj_objective_t obj); |
|
1162 |
*< |
slv_write_vector(file_normal, pvec1);/* write to normal open file */ |
1163 |
* Not implemented. |
rewind(file_normal); |
1164 |
* Prints the name of obj to outfile. If obj_make_name() can't |
CU_TEST(EOF != fgetc(file_normal)); /* test that file is not empty */ |
1165 |
* generate a name, the global index is printed instead. |
fclose(file_normal); |
1166 |
* @todo Implement solver/slv_common:slv_print_obj_name() or remove prototype. |
} |
1167 |
|
else { |
1168 |
|
CU_FAIL("Error opening output file 1 in test_slv_common.c"); |
1169 |
|
} |
1170 |
|
|
1171 |
|
if (TRUE == i_enabled_printing) { |
1172 |
|
test_disable_printing(); |
1173 |
|
i_enabled_printing = FALSE; |
1174 |
|
} |
1175 |
|
|
1176 |
|
slv_destroy_vector(pvec1); |
1177 |
|
|
1178 |
|
CU_TEST(test_meminuse == ascmeminuse()); |
1179 |
|
|
1180 |
|
/* test slv_dot() */ |
1181 |
|
|
1182 |
|
test_meminuse = ascmeminuse(); |
1183 |
|
|
1184 |
|
#ifndef ASC_NO_ASSERTIONS |
1185 |
|
asc_assert_catch(TRUE); /* prepare to test assertions */ |
1186 |
|
|
1187 |
|
asc_assert_reset(); |
1188 |
|
if (0 == setjmp(g_asc_test_env)) |
1189 |
|
slv_dot(10, NULL, rarray2); /* error - NULL a1 */ |
1190 |
|
CU_TEST(TRUE == asc_assert_failed()); |
1191 |
|
|
1192 |
|
asc_assert_reset(); |
1193 |
|
if (0 == setjmp(g_asc_test_env)) |
1194 |
|
slv_dot(10, rarray, NULL); /* error - NULL a2 */ |
1195 |
|
CU_TEST(TRUE == asc_assert_failed()); |
1196 |
|
|
1197 |
|
asc_assert_reset(); |
1198 |
|
if (0 == setjmp(g_asc_test_env)) |
1199 |
|
slv_dot(-10, rarray, rarray2); /* error - len < 0 */ |
1200 |
|
CU_TEST(TRUE == asc_assert_failed()); |
1201 |
|
|
1202 |
|
asc_assert_catch(FALSE); /* done testing assertions */ |
1203 |
|
#endif /* !ASC_NO_ASSERTIONS */ |
1204 |
|
|
1205 |
|
rarray2[0] = rarray[5]; |
1206 |
|
|
1207 |
|
CU_ASSERT_DOUBLE_EQUAL(slv_dot(1, rarray, rarray2), slow_dot_product(1, rarray, rarray2), 0.00001); |
1208 |
|
CU_ASSERT_DOUBLE_EQUAL(slv_dot(1, rarray2, rarray), slow_dot_product(1, rarray, rarray2), 0.00001); |
1209 |
|
|
1210 |
|
for (i=0 ; i<10 ; ++i) { |
1211 |
|
rarray2[i] = 2.0; |
1212 |
|
} |
1213 |
|
|
1214 |
|
CU_ASSERT_DOUBLE_EQUAL(slv_dot(11, rarray, rarray2), slow_dot_product(11, rarray, rarray2), 0.00001); |
1215 |
|
CU_ASSERT_DOUBLE_EQUAL(slv_dot(11, rarray2, rarray), slow_dot_product(11, rarray, rarray2), 0.00001); |
1216 |
|
|
1217 |
|
CU_ASSERT_DOUBLE_EQUAL(slv_dot(5, rarray, rarray2), slow_dot_product(5, rarray, rarray2), 0.00001); |
1218 |
|
CU_ASSERT_DOUBLE_EQUAL(slv_dot(5, rarray2, rarray), slow_dot_product(5, rarray, rarray2), 0.00001); |
1219 |
|
|
1220 |
|
CU_ASSERT_DOUBLE_EQUAL(slv_dot(0, rarray, rarray2), slow_dot_product(0, rarray, rarray2), 0.00001); |
1221 |
|
CU_ASSERT_DOUBLE_EQUAL(slv_dot(0, rarray2, rarray), slow_dot_product(0, rarray, rarray2), 0.00001); |
1222 |
|
|
1223 |
|
for (i=1 ; i<10 ; ++i) { |
1224 |
|
CU_ASSERT_DOUBLE_EQUAL(7/2 * i, rarray[i], 0.00001); /* data in arrays should be intact */ |
1225 |
|
CU_ASSERT_DOUBLE_EQUAL(rarray2[i], 2.0, 0.00001); |
1226 |
|
} |
1227 |
|
|
1228 |
|
for (i=0 ; i<10 ; ++i) { |
1229 |
|
rarray2[i] = rarray[9-i]; |
1230 |
|
} |
1231 |
|
|
1232 |
|
CU_ASSERT_DOUBLE_EQUAL(slv_dot(11, rarray, rarray2), slow_dot_product(11, rarray, rarray2), 0.00001); |
1233 |
|
CU_ASSERT_DOUBLE_EQUAL(slv_dot(11, rarray2, rarray), slow_dot_product(11, rarray, rarray2), 0.00001); |
1234 |
|
|
1235 |
|
CU_TEST(test_meminuse == ascmeminuse()); |
1236 |
|
|
1237 |
|
/* test slv_get_output_file() */ |
1238 |
|
|
1239 |
|
test_meminuse = ascmeminuse(); |
1240 |
|
|
1241 |
|
file_normal = (FILE *)100; |
1242 |
|
CU_TEST(file_normal == slv_get_output_file(file_normal)); /* non-NULL fp */ |
1243 |
|
CU_TEST(NULL != slv_get_output_file(NULL)); /* NULL fp */ |
1244 |
|
fprintf(slv_get_output_file(NULL), "\n If you see this then test_slv_common:slv_get_output_file() failed!"); |
1245 |
|
|
1246 |
|
/* MIF(), LIF(), PMIF(), PLIF() - macros accessing members - not tested */ |
1247 |
|
|
1248 |
|
/* not tested - revisit later: |
1249 |
|
* - slv_print_obj_name() |
1250 |
|
* - slv_print_rel_name() |
1251 |
|
* - slv_print_var_name() |
1252 |
|
* - slv_print_logrel_name() |
1253 |
|
* - slv_print_dis_name() |
1254 |
|
* - slv_print_obj_index() |
1255 |
|
* - slv_print_rel_sindex() |
1256 |
|
* - slv_print_var_sindex() |
1257 |
|
* - slv_print_logrel_sindex() |
1258 |
|
* - slv_print_dis_sindex() |
1259 |
|
* - slv_print_obj_index() |
1260 |
|
*/ |
1261 |
|
|
1262 |
|
test_meminuse = ascmeminuse(); |
1263 |
|
|
1264 |
|
CU_FAIL("slv_print_*_name() and slv_print_*_sindex() not tested."); |
1265 |
|
|
1266 |
|
CU_TEST(test_meminuse == ascmeminuse()); |
1267 |
|
|
1268 |
|
/* test slv_direct_solve() */ |
1269 |
|
|
1270 |
|
test_meminuse = ascmeminuse(); |
1271 |
|
|
1272 |
|
CU_FAIL("slv_direct_solve() test not implemented."); |
1273 |
|
|
1274 |
|
CU_TEST(test_meminuse == ascmeminuse()); |
1275 |
|
|
1276 |
|
/* test slv_direct_log_solve() */ |
1277 |
|
|
1278 |
|
test_meminuse = ascmeminuse(); |
1279 |
|
|
1280 |
|
CU_FAIL("slv_direct_log_solve() test not implemented."); |
1281 |
|
|
1282 |
|
CU_TEST(test_meminuse == ascmeminuse()); |
1283 |
|
|
1284 |
|
/* test slv_create_lnkmap(), slv_write_lnkmap(), slv_destroy_lnkmap() */ |
1285 |
|
|
1286 |
|
test_meminuse = ascmeminuse(); |
1287 |
|
|
1288 |
|
hi[0] = 100; |
1289 |
|
hj[0] = 1; |
1290 |
|
|
1291 |
|
CU_TEST(NULL == slv_create_lnkmap(10, 10, 1, hi, hj)); /* error - hi contains invalid index */ |
1292 |
|
|
1293 |
|
hi[0] = 1; |
1294 |
|
hj[0] = 100; |
1295 |
|
|
1296 |
|
CU_TEST(NULL == slv_create_lnkmap(10, 10, 1, hi, hj)); /* error - hj contains invalid index */ |
1297 |
|
|
1298 |
|
lnkmap = slv_create_lnkmap(10, 10, 0, hi, hj); /* 0 element arrays */ |
1299 |
|
CU_TEST_FATAL(NULL != lnkmap); |
1300 |
|
for (i=0 ; i<10 ; ++i) { |
1301 |
|
CU_TEST(0 == *lnkmap[i]); |
1302 |
|
} |
1303 |
|
|
1304 |
|
CU_TEST(0 != AllocatedMemory((VOIDPTR)lnkmap, 0)); |
1305 |
|
|
1306 |
|
slv_destroy_lnkmap(lnkmap); |
1307 |
|
|
1308 |
|
#ifdef MALLOC_DEBUG |
1309 |
|
CU_TEST(0 == AllocatedMemory((VOIDPTR)lnkmap, 0)); |
1310 |
|
#else |
1311 |
|
CU_TEST(1 == AllocatedMemory((VOIDPTR)lnkmap, 0)); |
1312 |
#endif |
#endif |
|
extern void slv_print_rel_name(FILE *outfile, |
|
|
slv_system_t sys, |
|
|
struct rel_relation *rel); |
|
|
*< |
|
|
* Prints the name of rel to outfile. If rel_make_name() can't |
|
|
* generate a name, the global index is printed instead. |
|
|
|
|
|
extern void slv_print_var_name(FILE *outfile, |
|
|
slv_system_t sys, |
|
|
struct var_variable *var); |
|
|
*< |
|
|
* Prints the name of var to outfile. If var_make_name() can't |
|
|
* generate a name, the global index is printed instead. |
|
|
|
|
|
extern void slv_print_logrel_name(FILE *outfile, |
|
|
slv_system_t sys, |
|
|
struct logrel_relation *lrel); |
|
|
*< |
|
|
* Prints the name of lrel to outfile. If logrel_make_name() can't |
|
|
* generate a name, the global index is printed instead. |
|
|
|
|
|
extern void slv_print_dis_name(FILE *outfile, |
|
|
slv_system_t sys, |
|
|
struct dis_discrete *dvar); |
|
|
*< |
|
|
* Prints the name of dvar to outfile. If dis_make_name() can't |
|
|
* generate a name, the global index is printed instead. |
|
|
|
|
1313 |
|
|
1314 |
#ifdef NEWSTUFF |
hi[0] = 1; |
1315 |
extern void slv_print_obj_index(FILE *outfile, obj_objective_t obj); |
hj[0] = 1; |
1316 |
*< |
|
1317 |
* Not implemented. |
lnkmap = slv_create_lnkmap(10, 10, 1, hi, hj); /* 1 element arrays */ |
1318 |
* Prints the index of obj to outfile. |
CU_TEST_FATAL(NULL != lnkmap); |
1319 |
* @todo Implement solver/slv_common:slv_print_obj_index() or remove prototype. |
for (i=0 ; i<10 ; ++i) { |
1320 |
|
lnkvars = lnkmap[i]; |
1321 |
|
if (i == 1) { |
1322 |
|
CU_TEST_FATAL(1 == lnkvars[0]); /* number of non-zero elements */ |
1323 |
|
CU_TEST(1 == lnkvars[1]); /* column # of 1st element */ |
1324 |
|
CU_TEST(0 == lnkvars[2]); /* link map index */ |
1325 |
|
} else { |
1326 |
|
CU_TEST(0 == lnkvars[0]); |
1327 |
|
} |
1328 |
|
} |
1329 |
|
|
1330 |
|
CU_TEST(0 != AllocatedMemory((VOIDPTR)lnkmap, 0)); |
1331 |
|
|
1332 |
|
slv_destroy_lnkmap(lnkmap); |
1333 |
|
|
1334 |
|
#ifdef MALLOC_DEBUG |
1335 |
|
CU_TEST(0 == AllocatedMemory((VOIDPTR)lnkmap, 0)); |
1336 |
|
#else |
1337 |
|
CU_TEST(1 == AllocatedMemory((VOIDPTR)lnkmap, 0)); |
1338 |
#endif |
#endif |
1339 |
extern void slv_print_rel_sindex(FILE *outfile, struct rel_relation *rel); |
|
1340 |
*< Prints the index of rel to outfile. |
/* link map order: (5,1) (3,0) (3,8) (2,10) (2,0) (2,4) (2,7) (2,2) (1,10) (1,5) (1,1) */ |
1341 |
extern void slv_print_var_sindex(FILE *outfile, struct var_variable *var); |
hi[0] = 5; /* row 5: (5,1) */ |
1342 |
*< Prints the index of var to outfile. |
hj[0] = 1; |
1343 |
extern void slv_print_logrel_sindex(FILE *outfile, struct logrel_relation *lrel); |
hi[1] = 3; /* row 3: (3,0) (3,8) */ |
1344 |
*< Prints the index of lrel to outfile. |
hj[1] = 0; |
1345 |
extern void slv_print_dis_sindex(FILE *outfile, struct dis_discrete *dvar); |
hi[2] = 3; |
1346 |
*< Prints the index of dvar to outfile. |
hj[2] = 8; |
1347 |
|
hi[3] = 2; /* row 2: (2,0) (2,2) (2,4) (2,7) (2,10) */ |
1348 |
|
hj[3] = 10; |
1349 |
|
hi[4] = 2; |
1350 |
|
hj[4] = 0; |
1351 |
|
hi[5] = 2; |
1352 |
|
hj[5] = 4; |
1353 |
|
hi[6] = 2; |
1354 |
|
hj[6] = 7; |
1355 |
|
hi[7] = 2; |
1356 |
|
hj[7] = 2; |
1357 |
|
hi[8] = 1; /* row 1: (1,1) (1,5) (1,10) */ |
1358 |
|
hj[8] = 10; |
1359 |
|
hi[9] = 1; |
1360 |
|
hj[9] = 5; |
1361 |
|
hi[10] = 1; |
1362 |
|
hj[10] = 1; |
1363 |
|
|
1364 |
|
lnkindex_list = gl_create(11); |
1365 |
|
for (i=0 ; i<11 ; ++i) { |
1366 |
|
lnkindexes[i] = i; |
1367 |
|
gl_append_ptr(lnkindex_list, &lnkindexes[i]); |
1368 |
|
} |
1369 |
|
|
1370 |
|
lnkmap = slv_create_lnkmap(6, 11, 11, hi, hj); /* multi element arrays */ |
1371 |
|
CU_TEST_FATAL(NULL != lnkmap); |
1372 |
|
|
1373 |
|
lnkvars = lnkmap[0]; |
1374 |
|
CU_TEST(0 == lnkvars[0]); /* number of non-zero elements */ |
1375 |
|
|
1376 |
|
col_list = gl_create(10); |
1377 |
|
CU_TEST_FATAL(NULL != col_list); |
1378 |
|
gl_append_ptr(col_list, &hj[8]); |
1379 |
|
gl_append_ptr(col_list, &hj[9]); |
1380 |
|
gl_append_ptr(col_list, &hj[10]); |
1381 |
|
|
1382 |
|
lnkvars = lnkmap[1]; |
1383 |
|
CU_TEST(3 == lnkvars[0]); /* number of non-zero elements */ |
1384 |
|
for (i=0 ; i<lnkvars[0] ; ++i) { |
1385 |
|
CU_TEST(0 != (pos = gl_search(col_list, &lnkvars[2*i+1], compare_int32s))); |
1386 |
|
gl_delete(col_list, pos, FALSE); |
1387 |
|
CU_TEST(0 != (pos = gl_search(lnkindex_list, &lnkvars[2*i+2], compare_int32s))); |
1388 |
|
gl_delete(lnkindex_list, pos, FALSE); |
1389 |
|
} |
1390 |
|
|
1391 |
|
gl_reset(col_list); |
1392 |
|
gl_append_ptr(col_list, &hj[3]); |
1393 |
|
gl_append_ptr(col_list, &hj[4]); |
1394 |
|
gl_append_ptr(col_list, &hj[5]); |
1395 |
|
gl_append_ptr(col_list, &hj[6]); |
1396 |
|
gl_append_ptr(col_list, &hj[7]); |
1397 |
|
|
1398 |
|
lnkvars = lnkmap[2]; |
1399 |
|
CU_TEST(5 == lnkvars[0]); /* number of non-zero elements */ |
1400 |
|
for (i=0 ; i<lnkvars[0] ; ++i) { |
1401 |
|
CU_TEST(0 != (pos = gl_search(col_list, &lnkvars[2*i+1], compare_int32s))); |
1402 |
|
gl_delete(col_list, pos, FALSE); |
1403 |
|
CU_TEST(0 != (pos = gl_search(lnkindex_list, &lnkvars[2*i+2], compare_int32s))); |
1404 |
|
gl_delete(lnkindex_list, pos, FALSE); |
1405 |
|
} |
1406 |
|
|
1407 |
|
gl_reset(col_list); |
1408 |
|
gl_append_ptr(col_list, &hj[1]); |
1409 |
|
gl_append_ptr(col_list, &hj[2]); |
1410 |
|
|
1411 |
|
lnkvars = lnkmap[3]; |
1412 |
|
CU_TEST(2 == lnkvars[0]); /* number of non-zero elements */ |
1413 |
|
for (i=0 ; i<lnkvars[0] ; ++i) { |
1414 |
|
CU_TEST(0 != (pos = gl_search(col_list, &lnkvars[2*i+1], compare_int32s))); |
1415 |
|
gl_delete(col_list, pos, FALSE); |
1416 |
|
CU_TEST(0 != (pos = gl_search(lnkindex_list, &lnkvars[2*i+2], compare_int32s))); |
1417 |
|
gl_delete(lnkindex_list, pos, FALSE); |
1418 |
|
} |
1419 |
|
|
1420 |
|
lnkvars = lnkmap[4]; |
1421 |
|
CU_TEST(0 == lnkvars[0]); /* number of non-zero elements */ |
1422 |
|
|
1423 |
|
gl_reset(col_list); |
1424 |
|
gl_append_ptr(col_list, &hj[0]); |
1425 |
|
|
1426 |
|
lnkvars = lnkmap[5]; |
1427 |
|
CU_TEST_FATAL(1 == lnkvars[0]); /* number of non-zero elements */ |
1428 |
|
for (i=0 ; i<lnkvars[0] ; ++i) { |
1429 |
|
CU_TEST(0 != (pos = gl_search(col_list, &lnkvars[2*i+1], compare_int32s))); |
1430 |
|
gl_delete(col_list, pos, FALSE); |
1431 |
|
CU_TEST(0 != (pos = gl_search(lnkindex_list, &lnkvars[2*i+2], compare_int32s))); |
1432 |
|
gl_delete(lnkindex_list, pos, FALSE); |
1433 |
|
} |
1434 |
|
|
1435 |
|
CU_TEST(0 == gl_length(lnkindex_list)); /* all lnkindexes should have been used */ |
1436 |
|
|
1437 |
|
if (FALSE == test_printing_enabled()) { |
1438 |
|
test_enable_printing(); |
1439 |
|
i_enabled_printing = TRUE; |
1440 |
|
} |
1441 |
|
|
1442 |
|
if (NULL != (file_normal = fopen("slvcommontempfile2.tmp", "w+"))) { |
1443 |
|
|
1444 |
|
slv_write_lnkmap(file_normal, 6, lnkmap); /* write to normal open file */ |
1445 |
|
rewind(file_normal); |
1446 |
|
CU_TEST(EOF != fgetc(file_normal)); /* test that file is not empty */ |
1447 |
|
fclose(file_normal); |
1448 |
|
} |
1449 |
|
else { |
1450 |
|
CU_FAIL("Error opening output file 2 in test_slv_common.c"); |
1451 |
|
} |
1452 |
|
|
1453 |
|
if (TRUE == i_enabled_printing) { |
1454 |
|
test_disable_printing(); |
1455 |
|
i_enabled_printing = FALSE; |
1456 |
|
} |
1457 |
|
|
1458 |
|
gl_destroy(col_list); |
1459 |
|
gl_destroy(lnkindex_list); |
1460 |
|
slv_destroy_lnkmap(lnkmap); |
1461 |
|
|
1462 |
|
gl_emptyrecycler(); |
1463 |
|
CU_TEST(test_meminuse == ascmeminuse()); |
1464 |
|
|
1465 |
|
/* test slv_lnkmap_from_mtx() */ |
1466 |
|
|
1467 |
|
test_meminuse = ascmeminuse(); |
1468 |
|
|
1469 |
|
mtx = mtx_create(); |
1470 |
|
CU_TEST_FATAL(NULL != mtx); |
1471 |
|
mtx_set_order(mtx, 11); |
1472 |
|
|
1473 |
|
region.row.low = 0; |
1474 |
|
region.row.high = 10; |
1475 |
|
region.col.low = 0; |
1476 |
|
region.col.high = 10; |
1477 |
|
|
1478 |
|
CU_TEST(NULL == slv_lnkmap_from_mtx(NULL, ®ion)); /* error - NULL mtx */ |
1479 |
|
|
1480 |
|
region.row.low = -1; |
1481 |
|
region.row.high = 10; |
1482 |
|
region.col.low = 0; |
1483 |
|
region.col.high = 10; |
1484 |
|
|
1485 |
|
CU_TEST(NULL == slv_lnkmap_from_mtx(mtx, ®ion)); /* error - region.row.low < 0 */ |
1486 |
|
|
1487 |
|
region.row.low = 0; |
1488 |
|
region.row.high = 11; |
1489 |
|
|
1490 |
|
CU_TEST(NULL == slv_lnkmap_from_mtx(mtx, ®ion)); /* error - region.row.high >= order */ |
1491 |
|
|
1492 |
|
region.col.low = -1; |
1493 |
|
region.col.high = 10; |
1494 |
|
|
1495 |
|
CU_TEST(NULL == slv_lnkmap_from_mtx(mtx, ®ion)); /* error - region.col.low < 0 */ |
1496 |
|
|
1497 |
|
region.col.low = 0; |
1498 |
|
region.col.high = 11; |
1499 |
|
|
1500 |
|
CU_TEST(NULL == slv_lnkmap_from_mtx(mtx, ®ion)); /* error - region.col.high >= order */ |
1501 |
|
|
1502 |
|
region.row.low = 0; |
1503 |
|
region.row.high = 10; |
1504 |
|
region.col.low = 0; |
1505 |
|
region.col.high = 10; |
1506 |
|
|
1507 |
|
lnkmap = slv_lnkmap_from_mtx(mtx, ®ion); /* empty matrix */ |
1508 |
|
CU_TEST_FATAL(NULL != lnkmap); |
1509 |
|
for (i=0 ; i<11 ; ++i) { |
1510 |
|
CU_TEST(0 == *lnkmap[i]); |
1511 |
|
} |
1512 |
|
|
1513 |
|
slv_destroy_lnkmap(lnkmap); |
1514 |
|
|
1515 |
|
mtx_fill_value(mtx, mtx_coord(&coord,5,1),10.0); /* row 5: (5,1) (5,7) */ |
1516 |
|
mtx_fill_value(mtx, mtx_coord(&coord,2,0),20.1); /* row 2: (2,0) (2,6) */ |
1517 |
|
mtx_fill_value(mtx, mtx_coord(&coord,6,4),30.2); /* row 6: (6,4) (6,5) */ |
1518 |
|
mtx_fill_value(mtx, mtx_coord(&coord,2,6),40.3); |
1519 |
|
mtx_fill_value(mtx, mtx_coord(&coord,0,2),50.4); /* row 0: (0,2) */ |
1520 |
|
mtx_fill_value(mtx, mtx_coord(&coord,5,7),59.5); |
1521 |
|
mtx_fill_value(mtx, mtx_coord(&coord,6,5),69.6); |
1522 |
|
mtx_fill_value(mtx, mtx_coord(&coord,3,8),79.7); /* row 3: (3,8) */ |
1523 |
|
mtx_fill_value(mtx, mtx_coord(&coord,9,9),89.8); /* row 9: (9,9) (9,10) */ |
1524 |
|
mtx_fill_value(mtx, mtx_coord(&coord,9,10),99.9); |
1525 |
|
|
1526 |
|
region.row.low = 3; |
1527 |
|
region.row.high = 4; |
1528 |
|
region.col.low = 0; |
1529 |
|
region.col.high = 10; |
1530 |
|
lnkmap = slv_lnkmap_from_mtx(mtx, ®ion); /* region with 1 non-zero */ |
1531 |
|
CU_TEST_FATAL(NULL != lnkmap); |
1532 |
|
lnkvars = lnkmap[3]; |
1533 |
|
CU_TEST(1 == lnkvars[0]); |
1534 |
|
CU_TEST(8 == lnkvars[1]); |
1535 |
|
CU_TEST(80 == lnkvars[2]); |
1536 |
|
for (i=0 ; i<3 ; ++i) { |
1537 |
|
CU_TEST(0 == *lnkmap[i]); |
1538 |
|
} |
1539 |
|
for (i=4 ; i<11 ; ++i) { |
1540 |
|
CU_TEST(0 == *lnkmap[i]); |
1541 |
|
} |
1542 |
|
|
1543 |
|
slv_destroy_lnkmap(lnkmap); |
1544 |
|
|
1545 |
|
lnkmap = slv_lnkmap_from_mtx(mtx, mtx_ENTIRE_MATRIX); /* entire matrix */ |
1546 |
|
CU_TEST_FATAL(NULL != lnkmap); |
1547 |
|
CU_TEST(0 == *lnkmap[1]); |
1548 |
|
CU_TEST(0 == *lnkmap[4]); |
1549 |
|
CU_TEST(0 == *lnkmap[7]); |
1550 |
|
CU_TEST(0 == *lnkmap[8]); |
1551 |
|
CU_TEST(0 == *lnkmap[10]); |
1552 |
|
|
1553 |
|
lnkvars = lnkmap[0]; |
1554 |
|
CU_TEST(1 == lnkvars[0]); |
1555 |
|
CU_TEST(2 == lnkvars[1]); |
1556 |
|
CU_TEST(50 == lnkvars[2]); |
1557 |
|
|
1558 |
|
lnkvars = lnkmap[2]; |
1559 |
|
CU_TEST(2 == lnkvars[0]); |
1560 |
|
if (0 == lnkvars[1]) { |
1561 |
|
CU_TEST(20 == lnkvars[2]); |
1562 |
|
CU_TEST(6 == lnkvars[3]); |
1563 |
|
CU_TEST(40 == lnkvars[4]); |
1564 |
|
} else if (6 == lnkvars[1]) { |
1565 |
|
CU_TEST(40 == lnkvars[2]); |
1566 |
|
CU_TEST(0 == lnkvars[3]); |
1567 |
|
CU_TEST(20 == lnkvars[4]); |
1568 |
|
} else { |
1569 |
|
CU_FAIL("Unexpected col for lnkmap row 2."); |
1570 |
|
} |
1571 |
|
|
1572 |
|
lnkvars = lnkmap[3]; |
1573 |
|
CU_TEST(1 == lnkvars[0]); |
1574 |
|
CU_TEST(8 == lnkvars[1]); |
1575 |
|
CU_TEST(80 == lnkvars[2]); |
1576 |
|
|
1577 |
|
lnkvars = lnkmap[5]; |
1578 |
|
CU_TEST(2 == lnkvars[0]); |
1579 |
|
if (1 == lnkvars[1]) { |
1580 |
|
CU_TEST(10 == lnkvars[2]); |
1581 |
|
CU_TEST(7 == lnkvars[3]); |
1582 |
|
CU_TEST(60 == lnkvars[4]); |
1583 |
|
} else if (7 == lnkvars[1]) { |
1584 |
|
CU_TEST(60 == lnkvars[2]); |
1585 |
|
CU_TEST(1 == lnkvars[3]); |
1586 |
|
CU_TEST(10 == lnkvars[4]); |
1587 |
|
} else { |
1588 |
|
CU_FAIL("Unexpected col for lnkmap row 5."); |
1589 |
|
} |
1590 |
|
|
1591 |
|
lnkvars = lnkmap[6]; |
1592 |
|
CU_TEST(2 == lnkvars[0]); |
1593 |
|
if (4 == lnkvars[1]) { |
1594 |
|
CU_TEST(30 == lnkvars[2]); |
1595 |
|
CU_TEST(5 == lnkvars[3]); |
1596 |
|
CU_TEST(70 == lnkvars[4]); |
1597 |
|
} else if (5 == lnkvars[1]) { |
1598 |
|
CU_TEST(70 == lnkvars[2]); |
1599 |
|
CU_TEST(4 == lnkvars[3]); |
1600 |
|
CU_TEST(30 == lnkvars[4]); |
1601 |
|
} else { |
1602 |
|
CU_FAIL("Unexpected col for lnkmap row 6."); |
1603 |
|
} |
1604 |
|
|
1605 |
|
lnkvars = lnkmap[9]; |
1606 |
|
CU_TEST(2 == lnkvars[0]); |
1607 |
|
if (9 == lnkvars[1]) { |
1608 |
|
CU_TEST(90 == lnkvars[2]); |
1609 |
|
CU_TEST(10 == lnkvars[3]); |
1610 |
|
CU_TEST(100 == lnkvars[4]); |
1611 |
|
} else if (10 == lnkvars[1]) { |
1612 |
|
CU_TEST(100 == lnkvars[2]); |
1613 |
|
CU_TEST(9 == lnkvars[3]); |
1614 |
|
CU_TEST(90 == lnkvars[4]); |
1615 |
|
} else { |
1616 |
|
CU_FAIL("Unexpected col for lnkmap row 9."); |
1617 |
|
} |
1618 |
|
|
1619 |
|
slv_destroy_lnkmap(lnkmap); |
1620 |
|
|
1621 |
|
mtx_destroy(mtx); |
1622 |
|
|
1623 |
|
CU_TEST(test_meminuse == ascmeminuse()); |
1624 |
|
|
1625 |
|
/* |
1626 |
|
|
1627 |
extern int slv_direct_solve(slv_system_t server, |
extern int slv_direct_solve(slv_system_t server, |
1628 |
struct rel_relation *rel, |
struct rel_relation *rel, |
1689 |
* @param perturb If TRUE, perturbs the truth values if necessary to find the solution. |
* @param perturb If TRUE, perturbs the truth values if necessary to find the solution. |
1690 |
* @param instances List of instances. |
* @param instances List of instances. |
1691 |
|
|
|
|
|
|
#endif |
|
|
-------------------- END compiler dependent functions -------------------- |
|
|
|
|
|
|
|
|
* -------------------- |
|
|
* lnkmap functions |
|
|
* -------------------- |
|
|
|
|
|
|
|
|
extern int32 **slv_create_lnkmap(int32 m, int32 n, int32 hl, int32 *hi, int32 *hj); |
|
|
*< |
|
|
* Builds a row biased mapping array from the hi,hj lists given. |
|
|
* The map returned has the following format: |
|
|
* - map[i] is a vector describing the incidence in row i of the matrix. |
|
|
* - Let vars=map[i], where vars is int32 *. |
|
|
* - vars[0]=number of incidences in the relation. |
|
|
* - For all 0<=k<vars[0] |
|
|
* - vars[2*k+1]= original column index of some var in the eqn. |
|
|
* - vars[2*k+2]= the lnk list index of element(i,vars[2*k+1]) |
|
|
* |
|
|
* The map should only be deallocated by destroy_lnkmap(). |
|
|
* The memory allocation for a lnkmap is done efficiently.<br><br> |
|
|
* |
|
|
* These create an odd compressed row mapping, given the hi and hj |
|
|
* subscript vectors. The primary utility of the lnkmap is that |
|
|
* it can be traversed rapidly when one wants to conditionally map a row of |
|
|
* a Harwell style (arbitrarily ordered) link representation |
|
|
* back into another representation where adding elements to a row |
|
|
* is easily done.<br><br> |
|
|
* |
|
|
* hi and hj should specify a unique incidence pattern, that is no |
|
|
* duplicate elements are allowed. Rowindex and colindex refer to |
|
|
* the data in hi,hj. |
|
|
* |
|
|
* @param m The number of rows expected. The map returned will be this long. |
|
|
* @param n The number of columns expected. |
|
|
* @param hl The length of hi and hj. |
|
|
* @param hi The eqn indices of a C numbered sparse matrix list. |
|
|
* @param hj The var indices of a C numbered sparse matrix list. |
|
|
|
|
|
|
|
|
extern int32 **slv_lnkmap_from_mtx(mtx_matrix_t mtx, int32 len, int32 m); |
|
|
*< |
|
|
* Generates a map from a matrix. |
|
|
* Empty rows and columns are allowed in the matrix. |
|
|
* |
|
|
* @param mtx The matrix to map. |
|
|
* @param m The number of rows expected. The map returned will be this long. |
|
|
* @param len The number of nonzeros in mtx. |
|
|
* |
|
|
* @see slv_create_lnkmap() |
|
|
|
|
|
|
|
|
extern void slv_destroy_lnkmap(int32 **map); |
|
|
*< |
|
|
* Deallocate a map created by slv_create_lnkmap() or slv_destroy_lnkmap(). |
|
|
* destroy_lnkmap() will tolerate a NULL map as input. |
|
|
* |
|
|
* @param map The lnkmap to destroy. |
|
|
|
|
|
|
|
|
extern void slv_write_lnkmap(FILE *fp, int m, int32 **map); |
|
|
*< |
|
|
* Prints a link map to a file. |
|
|
* write_lnkmap() will tolerate a NULL map as input. |
|
|
* |
|
|
* @param fp The file stream to receive the report. |
|
|
* @param m The number of rows in map to print. |
|
|
* @param map The lnkmap to print. |
|
1692 |
*/ |
*/ |
1693 |
|
|
|
|
|
|
|
|
1694 |
if (TRUE == i_initialized_lists) { /* clean up list system if necessary */ |
if (TRUE == i_initialized_lists) { /* clean up list system if necessary */ |
1695 |
gl_destroy_pool(); |
gl_destroy_pool(); |
1696 |
} |
} |