Skip to content

Commit b439876

Browse files
authored
Update to add SPDX identifiers (#13)
* Add SPDX statement to files.
1 parent 122cce8 commit b439876

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+573
-18
lines changed

.clang-format

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# SPDX-FileCopyrightText: 2024 Binsparse Developers
2+
#
3+
# SPDX-License-Identifier: BSD-3-Clause
4+
15
---
26
BasedOnStyle: LLVM
37
PointerAlignment: Left

.github/workflows/ci.yml

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# SPDX-FileCopyrightText: 2024 Binsparse Developers
2+
#
3+
# SPDX-License-Identifier: BSD-3-Clause
4+
15
name: "CI"
26

37
on:

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-FileCopyrightText: 2024 Binsparse Developers
2+
#
3+
# SPDX-License-Identifier: BSD-3-Clause
4+
5+
scripts
6+
venv
7+
build
8+
._*

.pre-commit-config.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# SPDX-FileCopyrightText: 2024 Binsparse Developers
2+
#
3+
# SPDX-License-Identifier: BSD-3-Clause
4+
15
repos:
26

37
- repo: https://github.com/pre-commit/mirrors-clang-format
@@ -12,3 +16,8 @@ repos:
1216
- id: end-of-file-fixer
1317
- id: mixed-line-ending
1418
- id: check-added-large-files
19+
20+
- repo: https://github.com/fsfe/reuse-tool
21+
rev: v2.1.0
22+
hooks:
23+
- id: reuse

CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# SPDX-FileCopyrightText: 2024 Binsparse Developers
2+
#
3+
# SPDX-License-Identifier: BSD-3-Clause
4+
15
cmake_minimum_required(VERSION 3.5)
26
project(binsparse-rc)
37

File renamed without changes.

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
<!--
2+
SPDX-FileCopyrightText: 2024 Binsparse Developers
3+
4+
SPDX-License-Identifier: BSD-3-Clause
5+
-->
6+
17
# Binsparse C Reference Implementation
28

39
This library is a reference implementation of the [binsparse Binary Sparse Format Specification](https://github.com/GraphBLAS/binsparse-specification) written using C.

examples/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# SPDX-FileCopyrightText: 2024 Binsparse Developers
2+
#
3+
# SPDX-License-Identifier: BSD-3-Clause
4+
15
function(add_example example_name)
26
add_executable(${example_name} ${example_name}.c)
37
target_link_libraries(${example_name} binsparse-rc)
@@ -10,6 +14,7 @@ add_example(simple_write)
1014
add_example(mtx2bsp)
1115
add_example(bsp2mtx)
1216
add_example(check_equivalence)
17+
add_example(check_equivalence_parallel)
1318
add_example(bsp-ls)
1419
add_example(benchmark_read)
1520
add_example(benchmark_read_parallel)

examples/benchmark_read.c

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Binsparse Developers
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
17
#include <binsparse/binsparse.h>
28
#include <stdlib.h>
39
#include <time.h>

examples/benchmark_read_parallel.c

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Binsparse Developers
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
17
#include <binsparse/binsparse.h>
28
#include <stdlib.h>
39
#include <time.h>
@@ -61,8 +67,9 @@ int main(int argc, char** argv) {
6167
char* file_name = argv[1];
6268

6369
printf("Opening %s\n", file_name);
70+
fflush(stdout);
6471

65-
const int num_trials = 2;
72+
const int num_trials = 10;
6673

6774
int num_threads = 6;
6875

@@ -71,11 +78,10 @@ int main(int argc, char** argv) {
7178
size_t nbytes = 0;
7279

7380
// To flush the filesystem cache before each trial, change to `true`.
74-
bool cold_cache = true;
81+
bool cold_cache = false;
7582

7683
// If running warm cache experiments, read once to warm cache.
77-
if (!cold_cache && false) {
78-
printf("Warm cache read...\n");
84+
if (!cold_cache) {
7985
bsp_matrix_t mat = bsp_read_matrix_parallel(file_name, NULL, num_threads);
8086
bsp_destroy_matrix_t(mat);
8187
}
@@ -84,6 +90,7 @@ int main(int argc, char** argv) {
8490
if (cold_cache) {
8591
flush_cache();
8692
}
93+
fflush(stdout);
8794
double begin = gettime();
8895
bsp_matrix_t mat = bsp_read_matrix_parallel(file_name, NULL, num_threads);
8996
double end = gettime();
@@ -95,6 +102,7 @@ int main(int argc, char** argv) {
95102
double gbytes = ((double) nbytes) / 1024 / 1024 / 1024;
96103
double gbytes_s = gbytes / durations[i];
97104
printf("FORPARSER: %s,%lf,%lf\n", file_name, durations[i], gbytes_s);
105+
fflush(stdout);
98106
}
99107

100108
printf("[");

examples/benchmark_write.c

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Binsparse Developers
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
17
#include <binsparse/binsparse.h>
28
#include <stdlib.h>
39
#include <time.h>

examples/bsp-ls.c

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Binsparse Developers
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
17
#include <binsparse/binsparse.h>
28

39
herr_t visit_group(hid_t loc_id, const char* name, const H5L_info_t* linfo,

examples/bsp2mtx.c

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Binsparse Developers
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
17
#include <binsparse/binsparse.h>
28
#include <stdio.h>
39

examples/check_equivalence.c

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Binsparse Developers
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
17
#include <binsparse/binsparse.h>
28

39
int check_array_equivalence(bsp_array_t array1, bsp_array_t array2) {

examples/check_equivalence_parallel.c

+217
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Binsparse Developers
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#include <binsparse/binsparse.h>
8+
9+
int check_array_equivalence(bsp_array_t array1, bsp_array_t array2) {
10+
if (array1.size != array2.size) {
11+
fprintf(stderr, "Array sizes do not match. %zu != %zu\n", array1.size,
12+
array2.size);
13+
return 1;
14+
}
15+
16+
if (array1.size == 0) {
17+
return 0;
18+
}
19+
20+
bsp_matrix_market_type_t mm_type1 = BSP_MM_REAL;
21+
22+
if ((array1.type >= BSP_UINT8 && array1.type <= BSP_INT64) ||
23+
array1.type == BSP_BINT8) {
24+
mm_type1 = BSP_MM_INTEGER;
25+
} else if (array1.type >= BSP_FLOAT32 && array1.type <= BSP_FLOAT64) {
26+
mm_type1 = BSP_MM_REAL;
27+
} else if (array1.type == BSP_COMPLEX_FLOAT32 ||
28+
array1.type == BSP_COMPLEX_FLOAT64) {
29+
mm_type1 = BSP_MM_COMPLEX;
30+
} else {
31+
fprintf(stderr, "Unhandled array type.\n");
32+
return 2;
33+
}
34+
35+
bsp_matrix_market_type_t mm_type2 = BSP_MM_REAL;
36+
37+
if ((array2.type >= BSP_UINT8 && array2.type <= BSP_INT64) ||
38+
array2.type == BSP_BINT8) {
39+
mm_type2 = BSP_MM_INTEGER;
40+
} else if (array2.type >= BSP_FLOAT32 && array2.type <= BSP_FLOAT64) {
41+
mm_type2 = BSP_MM_REAL;
42+
} else if (array2.type == BSP_COMPLEX_FLOAT32 ||
43+
array2.type == BSP_COMPLEX_FLOAT64) {
44+
mm_type2 = BSP_MM_COMPLEX;
45+
} else {
46+
fprintf(stderr, "Unhandled array type.\n");
47+
return 2;
48+
}
49+
50+
if (mm_type1 != mm_type2) {
51+
fprintf(stderr, "Array types do not match.\n");
52+
return 3;
53+
}
54+
55+
for (size_t i = 0; i < array1.size; i++) {
56+
if (mm_type1 == BSP_MM_INTEGER) {
57+
size_t value1, value2;
58+
bsp_array_read(array1, i, value1);
59+
bsp_array_read(array2, i, value2);
60+
61+
if (value1 != value2) {
62+
fprintf(stderr, "Array values are not equal. (%zu != %zu)\n", value1,
63+
value2);
64+
return 4;
65+
}
66+
} else if (mm_type1 == BSP_MM_REAL) {
67+
double value1, value2;
68+
bsp_array_read(array1, i, value1);
69+
bsp_array_read(array2, i, value2);
70+
71+
if (value1 != value2) {
72+
fprintf(stderr, "Array values are not equal. (%.17lg != %.17lg)\n",
73+
value1, value2);
74+
return 4;
75+
}
76+
} else if (mm_type1 == BSP_MM_COMPLEX) {
77+
double _Complex value1, value2;
78+
bsp_array_read(array1, i, value1);
79+
bsp_array_read(array2, i, value2);
80+
81+
if (value1 != value2) {
82+
fprintf(stderr,
83+
"Array values are not equal. (%.17lg + i%.17lg != %.17lg + "
84+
"i%.17lg)\n",
85+
__real__ value1, __imag__ value1, __real__ value2,
86+
__imag__ value2);
87+
return 4;
88+
}
89+
}
90+
}
91+
92+
return 0;
93+
}
94+
95+
int main(int argc, char** argv) {
96+
if (argc < 3) {
97+
printf(
98+
"usage: ./check_equivalence [file1.{mtx/hdf5}] [file2.{mtx/hdf5}]\n");
99+
100+
printf(" Note: the second argument will be read in parallel if it is a "
101+
"Binsparse file.\n");
102+
return 1;
103+
}
104+
105+
char* file1 = argv[1];
106+
char* file2 = argv[2];
107+
108+
int num_threads = 6;
109+
110+
bsp_fdataset_info_t info1 = bsp_parse_fdataset_string(argv[1]);
111+
bsp_fdataset_info_t info2 = bsp_parse_fdataset_string(argv[2]);
112+
113+
printf("Matrix 1: %s and %s\n", info1.fname,
114+
(info1.dataset == NULL) ? "root" : info1.dataset);
115+
printf("Matrix 2: %s and %s\n", info2.fname,
116+
(info2.dataset == NULL) ? "root" : info2.dataset);
117+
118+
fflush(stdout);
119+
120+
bsp_matrix_t matrix1 = bsp_read_matrix(info1.fname, info1.dataset);
121+
bsp_matrix_t matrix2 =
122+
bsp_read_matrix_parallel(info2.fname, info2.dataset, num_threads);
123+
124+
bool perform_suitesparse_declamping = true;
125+
if (perform_suitesparse_declamping &&
126+
strcmp(bsp_get_file_extension(file1), ".mtx") == 0) {
127+
bsp_matrix_declamp_values(matrix1);
128+
}
129+
130+
if (perform_suitesparse_declamping &&
131+
strcmp(bsp_get_file_extension(file2), ".mtx") == 0) {
132+
bsp_matrix_declamp_values(matrix2);
133+
}
134+
135+
// If matrices are not the same format, try to convert.
136+
if (matrix1.format != matrix2.format) {
137+
if (matrix1.format != BSP_COOR) {
138+
bsp_matrix_t intermediate = bsp_convert_matrix(matrix1, BSP_COOR);
139+
bsp_destroy_matrix_t(matrix1);
140+
matrix1 = intermediate;
141+
}
142+
143+
if (matrix2.format != BSP_COOR) {
144+
bsp_matrix_t intermediate = bsp_convert_matrix(matrix2, BSP_COOR);
145+
bsp_destroy_matrix_t(matrix2);
146+
matrix2 = intermediate;
147+
}
148+
}
149+
150+
if (matrix1.format != matrix2.format) {
151+
fprintf(stderr, "Formats do not match. (%s != %s)\n",
152+
bsp_get_matrix_format_string(matrix1.format),
153+
bsp_get_matrix_format_string(matrix2.format));
154+
fprintf(stderr, "FAIL!\n");
155+
return 1;
156+
}
157+
158+
if (matrix1.structure != matrix2.structure) {
159+
fprintf(stderr, "Structures do not match. (%s != %s)\n",
160+
bsp_get_structure_string(matrix1.structure),
161+
bsp_get_structure_string(matrix2.structure));
162+
fprintf(stderr, "FAIL!\n");
163+
return 2;
164+
}
165+
166+
if (matrix1.nrows != matrix2.nrows || matrix1.ncols != matrix2.ncols) {
167+
fprintf(stderr, "Dimensions do not match. (%zu, %zu) != (%zu, %zu)\n",
168+
matrix1.nrows, matrix1.ncols, matrix2.nrows, matrix2.ncols);
169+
fprintf(stderr, "FAIL!\n");
170+
return 3;
171+
}
172+
173+
if (matrix1.nnz != matrix2.nnz) {
174+
fprintf(stderr, "Number of stored values does not match. %zu != %zu\n",
175+
matrix1.nnz, matrix2.nnz);
176+
fprintf(stderr, "FAIL!\n");
177+
return 4;
178+
}
179+
180+
if (matrix1.is_iso != matrix2.is_iso) {
181+
fprintf(stderr, "ISO-ness does not match. %s != %s\n",
182+
(matrix1.is_iso) ? "true" : "false",
183+
(matrix2.is_iso) ? "true" : "false");
184+
fprintf(stderr, "FAIL!\n");
185+
return 5;
186+
}
187+
188+
if (check_array_equivalence(matrix1.values, matrix2.values) != 0) {
189+
fprintf(stderr, "Value arrays not equivalent.\n");
190+
fprintf(stderr, "FAIL!\n");
191+
return 6;
192+
}
193+
194+
if (check_array_equivalence(matrix1.indices_0, matrix2.indices_0) != 0) {
195+
fprintf(stderr, "Indices_0 arrays not equivalent.\n");
196+
fprintf(stderr, "FAIL!\n");
197+
return 7;
198+
}
199+
200+
if (check_array_equivalence(matrix1.indices_1, matrix2.indices_1) != 0) {
201+
fprintf(stderr, "Indices_1 arrays not equivalent.\n");
202+
fprintf(stderr, "FAIL!\n");
203+
return 8;
204+
}
205+
206+
if (check_array_equivalence(matrix1.pointers_to_1, matrix2.pointers_to_1) !=
207+
0) {
208+
fprintf(stderr, "Pointers_to_1 arrays not equivalent.\n");
209+
fprintf(stderr, "FAIL!\n");
210+
return 9;
211+
}
212+
213+
printf("The files are equivalent.\n");
214+
printf("OK!\n");
215+
216+
return 0;
217+
}

0 commit comments

Comments
 (0)