Skip to content

Commit 6ed460a

Browse files
committed
Create attributes as scalars, fix MatrixMarket FP printing.
1 parent a5da4a3 commit 6ed460a

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

examples/check_equivalence.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ int check_array_equivalence(bsp_array_t array1, bsp_array_t array2) {
5353
bsp_array_read(array2, i, value2);
5454

5555
if (value1 != value2) {
56-
fprintf(stderr, "Array values are not equal.\n");
56+
fprintf(stderr, "Array values are not equal. (%zu != %zu)\n", value1,
57+
value2);
5758
return 4;
5859
}
5960
} else if (mm_type1 == BSP_MM_REAL) {
@@ -62,7 +63,11 @@ int check_array_equivalence(bsp_array_t array1, bsp_array_t array2) {
6263
bsp_array_read(array2, i, value2);
6364

6465
if (value1 != value2) {
65-
fprintf(stderr, "Array values are not equal.\n");
66+
fprintf(stderr,
67+
"Array values are not equal. (%.17lg + i%.17lg != %.17lg + "
68+
"i%.17lg)\n",
69+
__real__ value1, __imag__ value1, __real__ value2,
70+
__imag__ value2);
6671
return 4;
6772
}
6873
} else if (mm_type1 == BSP_MM_COMPLEX) {

include/binsparse/hdf5_wrapper.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ void bsp_write_attribute(hid_t f, char* label, char* string) {
9696
hid_t strtype = H5Tcopy(H5T_C_S1);
9797
H5Tset_size(strtype, strlen(string));
9898
H5Tset_cset(strtype, H5T_CSET_UTF8);
99-
hsize_t size = 1;
100-
hid_t dataspace = H5Screate_simple(1, &size, H5P_DEFAULT);
99+
hid_t dataspace = H5Screate(H5S_SCALAR);
101100

102101
hid_t attribute =
103102
H5Acreate2(f, label, strtype, dataspace, H5P_DEFAULT, H5P_DEFAULT);

include/binsparse/matrix_market/matrix_market_write.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,18 @@ void bsp_mmwrite(char* file_path, bsp_matrix_t matrix) {
7676
bsp_array_read(matrix.indices_0, count, i);
7777
bsp_array_read(matrix.indices_1, count, j);
7878
bsp_array_read(matrix.values, count, value);
79-
fprintf(f, "%zu %zu %lf\n", i + 1, j + 1, value);
79+
fprintf(f, "%zu %zu %.17lg\n", i + 1, j + 1, value);
8080
} else if (mm_type == BSP_MM_COMPLEX) {
81+
// TODO: use Tim Davis' trick from SuiteSparse to limit the number of
82+
// digits printed without reducing accuracy.
8183
size_t i, j;
8284
double _Complex value;
8385
bsp_array_read(matrix.indices_0, count, i);
8486
bsp_array_read(matrix.indices_1, count, j);
8587
bsp_array_read(matrix.values, count, value);
8688
double real_value = 1.0 * value;
8789
double complex_value = 1j * value;
88-
fprintf(f, "%zu %zu %lf %lf\n", i + 1, j + 1, real_value,
90+
fprintf(f, "%zu %zu %.17lg %.17lg\n", i + 1, j + 1, real_value,
8991
complex_value);
9092
} else {
9193
assert(false);

0 commit comments

Comments
 (0)