Skip to content

Commit 7809a68

Browse files
committed
Merge branch 'main' into benchmarks
2 parents 9e3ccfd + bb40398 commit 7809a68

14 files changed

+35
-32
lines changed

examples/benchmark_write.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void flush_writes() {
6262
#endif
6363
}
6464

65-
void delete_file(char* file_name) {
65+
void delete_file(const char* file_name) {
6666
char command[2048];
6767
snprintf(command, 2047, "rm %s", file_name);
6868
int rv = system(command);

examples/mtx2bsp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ int main(int argc, char** argv) {
7070
compression_level = atoi(argv[4]);
7171
}
7272

73-
char* input_file_extension = bsp_get_file_extension(input_fname);
74-
char* output_file_extension = bsp_get_file_extension(output_fname);
73+
const char* input_file_extension = bsp_get_file_extension(input_fname);
74+
const char* output_file_extension = bsp_get_file_extension(output_fname);
7575

7676
if (input_file_extension == NULL ||
7777
strcmp(input_file_extension, ".mtx") != 0) {

examples/simple_matrix_read.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#include <binsparse/binsparse.h>
22

33
int main(int argc, char** argv) {
4-
char* file_name = "test.hdf5";
4+
const char* file_name = "test.hdf5";
55

66
bsp_matrix_t mat = bsp_read_matrix(file_name, NULL);
77

88
if (mat.format == BSP_COO) {
9-
float* values = mat.values.data;
10-
int* rowind = mat.indices_0.data;
11-
int* colind = mat.indices_1.data;
9+
float* values = (float*) mat.values.data;
10+
int* rowind = (int*) mat.indices_0.data;
11+
int* colind = (int*) mat.indices_1.data;
1212

1313
for (size_t i = 0; i < mat.nnz; i++) {
1414
printf("%d, %d: %f\n", rowind[i], colind[i], values[i]);

examples/simple_matrix_write.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ int main(int argc, char** argv) {
77

88
bsp_matrix_t mat = bsp_generate_coo(m, n, nnz, BSP_FLOAT32, BSP_INT32);
99

10-
float* values = mat.values.data;
11-
int* rowind = mat.indices_0.data;
12-
int* colind = mat.indices_1.data;
10+
float* values = (float*) mat.values.data;
11+
int* rowind = (int*) mat.indices_0.data;
12+
int* colind = (int*) mat.indices_1.data;
1313

1414
for (size_t i = 0; i < nnz; i++) {
1515
printf("%d, %d: %f\n", rowind[i], colind[i], values[i]);

examples/simple_read.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ int main(int argc, char** argv) {
77

88
bsp_array_t array = bsp_read_array(f, "test");
99

10-
int* values = array.data;
10+
int* values = (int*) array.data;
1111

1212
for (size_t i = 0; i < array.size; i++) {
1313
printf("%lu: %d\n", i, values[i]);

examples/simple_write.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include <binsparse/binsparse.h>
22

33
int main(int argc, char** argv) {
4-
char* file_name = "test.hdf5";
4+
const char* file_name = "test.hdf5";
55

66
hid_t f = H5Fcreate(file_name, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
77

88
bsp_array_t array = bsp_construct_array_t(1000, BSP_INT32);
99

10-
int* values = array.data;
10+
int* values = (int*) array.data;
1111

1212
for (size_t i = 0; i < array.size; i++) {
1313
bsp_array_write(array, i, i);

include/binsparse/detail/cpp/array.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#ifdef __cplusplus
44

5+
#include <string>
56
#include <type_traits>
67
#include <variant>
78

@@ -71,7 +72,7 @@ void bsp_array_read(bsp_array_t array, size_t index, T& value) {
7172
[&](auto* ptr) {
7273
using U = std::remove_pointer_t<decltype(ptr)>;
7374

74-
if constexpr (std::is_assignable_v<T, U>) {
75+
if constexpr (std::is_assignable_v<T&, U>) {
7576
value = ptr[index];
7677
}
7778
},
@@ -87,7 +88,7 @@ void bsp_array_write(bsp_array_t array, size_t index, U value) {
8788
[&](auto* ptr) {
8889
using T = std::remove_pointer_t<decltype(ptr)>;
8990

90-
if constexpr (std::is_assignable_v<T, U>) {
91+
if constexpr (std::is_assignable_v<T&, U>) {
9192
ptr[index] = value;
9293
}
9394
},
@@ -105,7 +106,7 @@ void bsp_array_awrite(bsp_array_t array_0, size_t index_0, bsp_array_t array_1,
105106
using T = std::remove_pointer_t<decltype(ptr_0)>;
106107
using U = std::remove_pointer_t<decltype(ptr_1)>;
107108

108-
if constexpr (std::is_assignable_v<T, U>) {
109+
if constexpr (std::is_assignable_v<T&, U>) {
109110
ptr_0[index_0] = ptr_1[index_1];
110111
}
111112
},

include/binsparse/detail/parse_dataset.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ bsp_fdataset_info_t bsp_parse_fdataset_string(char* str) {
3535
}
3636
}
3737

38-
char* bsp_get_file_extension(char* file_name) {
38+
const char* bsp_get_file_extension(const char* file_name) {
3939
int64_t len = strlen(file_name);
4040
for (int64_t i = len - 1; i >= 0; i--) {
4141
if (file_name[i] == '.') {

include/binsparse/hdf5_wrapper.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
// Write an array to a dataset / file
1313
// Returns 0 on success, nonzero on error.
14-
int bsp_write_array(hid_t f, char* label, bsp_array_t array,
14+
int bsp_write_array(hid_t f, const char* label, bsp_array_t array,
1515
int compression_level) {
1616
if (array.type == BSP_COMPLEX_FLOAT32 || array.type == BSP_COMPLEX_FLOAT64) {
1717
array = bsp_complex_array_to_fp(array);
@@ -65,7 +65,8 @@ int bsp_write_array(hid_t f, char* label, bsp_array_t array,
6565
return 0;
6666
}
6767

68-
bsp_array_t bsp_read_array_parallel(hid_t f, char* label, int num_threads) {
68+
bsp_array_t bsp_read_array_parallel(hid_t f, const char* label,
69+
int num_threads) {
6970
hid_t dset = H5Dopen2(f, label, H5P_DEFAULT);
7071

7172
if (dset == H5I_INVALID_HID) {
@@ -147,7 +148,7 @@ bsp_array_t bsp_read_array_parallel(hid_t f, char* label, int num_threads) {
147148
return array;
148149
}
149150

150-
bsp_array_t bsp_read_array(hid_t f, char* label) {
151+
bsp_array_t bsp_read_array(hid_t f, const char* label) {
151152
hid_t dset = H5Dopen2(f, label, H5P_DEFAULT);
152153

153154
if (dset == H5I_INVALID_HID) {
@@ -186,7 +187,7 @@ bsp_array_t bsp_read_array(hid_t f, char* label) {
186187
return array;
187188
}
188189

189-
void bsp_write_attribute(hid_t f, char* label, char* string) {
190+
void bsp_write_attribute(hid_t f, const char* label, const char* string) {
190191
hid_t strtype = H5Tcopy(H5T_C_S1);
191192
H5Tset_size(strtype, strlen(string));
192193
H5Tset_cset(strtype, H5T_CSET_UTF8);
@@ -202,7 +203,7 @@ void bsp_write_attribute(hid_t f, char* label, char* string) {
202203
H5Sclose(dataspace);
203204
}
204205

205-
char* bsp_read_attribute(hid_t f, char* label) {
206+
char* bsp_read_attribute(hid_t f, const char* label) {
206207
hid_t attribute = H5Aopen(f, label, H5P_DEFAULT);
207208
hid_t strtype = H5Aget_type(attribute);
208209

include/binsparse/matrix_market/matrix_market_inspector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ typedef struct bsp_mm_metadata {
2626
char* comments;
2727
} bsp_mm_metadata;
2828

29-
bsp_mm_metadata bsp_mmread_metadata(char* file_path) {
29+
bsp_mm_metadata bsp_mmread_metadata(const char* file_path) {
3030
FILE* f = fopen(file_path, "r");
3131

3232
assert(f != NULL);

0 commit comments

Comments
 (0)