Skip to content

Commit

Permalink
Merge branch 'main' into benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
BenBrock committed Aug 28, 2024
2 parents 9e3ccfd + bb40398 commit 7809a68
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 32 deletions.
2 changes: 1 addition & 1 deletion examples/benchmark_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void flush_writes() {
#endif
}

void delete_file(char* file_name) {
void delete_file(const char* file_name) {
char command[2048];
snprintf(command, 2047, "rm %s", file_name);
int rv = system(command);
Expand Down
4 changes: 2 additions & 2 deletions examples/mtx2bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ int main(int argc, char** argv) {
compression_level = atoi(argv[4]);
}

char* input_file_extension = bsp_get_file_extension(input_fname);
char* output_file_extension = bsp_get_file_extension(output_fname);
const char* input_file_extension = bsp_get_file_extension(input_fname);
const char* output_file_extension = bsp_get_file_extension(output_fname);

if (input_file_extension == NULL ||
strcmp(input_file_extension, ".mtx") != 0) {
Expand Down
8 changes: 4 additions & 4 deletions examples/simple_matrix_read.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include <binsparse/binsparse.h>

int main(int argc, char** argv) {
char* file_name = "test.hdf5";
const char* file_name = "test.hdf5";

bsp_matrix_t mat = bsp_read_matrix(file_name, NULL);

if (mat.format == BSP_COO) {
float* values = mat.values.data;
int* rowind = mat.indices_0.data;
int* colind = mat.indices_1.data;
float* values = (float*) mat.values.data;
int* rowind = (int*) mat.indices_0.data;
int* colind = (int*) mat.indices_1.data;

for (size_t i = 0; i < mat.nnz; i++) {
printf("%d, %d: %f\n", rowind[i], colind[i], values[i]);
Expand Down
6 changes: 3 additions & 3 deletions examples/simple_matrix_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ int main(int argc, char** argv) {

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

float* values = mat.values.data;
int* rowind = mat.indices_0.data;
int* colind = mat.indices_1.data;
float* values = (float*) mat.values.data;
int* rowind = (int*) mat.indices_0.data;
int* colind = (int*) mat.indices_1.data;

for (size_t i = 0; i < nnz; i++) {
printf("%d, %d: %f\n", rowind[i], colind[i], values[i]);
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int main(int argc, char** argv) {

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

int* values = array.data;
int* values = (int*) array.data;

for (size_t i = 0; i < array.size; i++) {
printf("%lu: %d\n", i, values[i]);
Expand Down
4 changes: 2 additions & 2 deletions examples/simple_write.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include <binsparse/binsparse.h>

int main(int argc, char** argv) {
char* file_name = "test.hdf5";
const char* file_name = "test.hdf5";

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

bsp_array_t array = bsp_construct_array_t(1000, BSP_INT32);

int* values = array.data;
int* values = (int*) array.data;

for (size_t i = 0; i < array.size; i++) {
bsp_array_write(array, i, i);
Expand Down
7 changes: 4 additions & 3 deletions include/binsparse/detail/cpp/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#ifdef __cplusplus

#include <string>
#include <type_traits>
#include <variant>

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

if constexpr (std::is_assignable_v<T, U>) {
if constexpr (std::is_assignable_v<T&, U>) {
value = ptr[index];
}
},
Expand All @@ -87,7 +88,7 @@ void bsp_array_write(bsp_array_t array, size_t index, U value) {
[&](auto* ptr) {
using T = std::remove_pointer_t<decltype(ptr)>;

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

if constexpr (std::is_assignable_v<T, U>) {
if constexpr (std::is_assignable_v<T&, U>) {
ptr_0[index_0] = ptr_1[index_1];
}
},
Expand Down
2 changes: 1 addition & 1 deletion include/binsparse/detail/parse_dataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bsp_fdataset_info_t bsp_parse_fdataset_string(char* str) {
}
}

char* bsp_get_file_extension(char* file_name) {
const char* bsp_get_file_extension(const char* file_name) {
int64_t len = strlen(file_name);
for (int64_t i = len - 1; i >= 0; i--) {
if (file_name[i] == '.') {
Expand Down
11 changes: 6 additions & 5 deletions include/binsparse/hdf5_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

// Write an array to a dataset / file
// Returns 0 on success, nonzero on error.
int bsp_write_array(hid_t f, char* label, bsp_array_t array,
int bsp_write_array(hid_t f, const char* label, bsp_array_t array,
int compression_level) {
if (array.type == BSP_COMPLEX_FLOAT32 || array.type == BSP_COMPLEX_FLOAT64) {
array = bsp_complex_array_to_fp(array);
Expand Down Expand Up @@ -65,7 +65,8 @@ int bsp_write_array(hid_t f, char* label, bsp_array_t array,
return 0;
}

bsp_array_t bsp_read_array_parallel(hid_t f, char* label, int num_threads) {
bsp_array_t bsp_read_array_parallel(hid_t f, const char* label,
int num_threads) {
hid_t dset = H5Dopen2(f, label, H5P_DEFAULT);

if (dset == H5I_INVALID_HID) {
Expand Down Expand Up @@ -147,7 +148,7 @@ bsp_array_t bsp_read_array_parallel(hid_t f, char* label, int num_threads) {
return array;
}

bsp_array_t bsp_read_array(hid_t f, char* label) {
bsp_array_t bsp_read_array(hid_t f, const char* label) {
hid_t dset = H5Dopen2(f, label, H5P_DEFAULT);

if (dset == H5I_INVALID_HID) {
Expand Down Expand Up @@ -186,7 +187,7 @@ bsp_array_t bsp_read_array(hid_t f, char* label) {
return array;
}

void bsp_write_attribute(hid_t f, char* label, char* string) {
void bsp_write_attribute(hid_t f, const char* label, const char* string) {
hid_t strtype = H5Tcopy(H5T_C_S1);
H5Tset_size(strtype, strlen(string));
H5Tset_cset(strtype, H5T_CSET_UTF8);
Expand All @@ -202,7 +203,7 @@ void bsp_write_attribute(hid_t f, char* label, char* string) {
H5Sclose(dataspace);
}

char* bsp_read_attribute(hid_t f, char* label) {
char* bsp_read_attribute(hid_t f, const char* label) {
hid_t attribute = H5Aopen(f, label, H5P_DEFAULT);
hid_t strtype = H5Aget_type(attribute);

Expand Down
2 changes: 1 addition & 1 deletion include/binsparse/matrix_market/matrix_market_inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ typedef struct bsp_mm_metadata {
char* comments;
} bsp_mm_metadata;

bsp_mm_metadata bsp_mmread_metadata(char* file_path) {
bsp_mm_metadata bsp_mmread_metadata(const char* file_path) {
FILE* f = fopen(file_path, "r");

assert(f != NULL);
Expand Down
9 changes: 5 additions & 4 deletions include/binsparse/matrix_market/matrix_market_read.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#include <binsparse/matrix_market/matrix_market_inspector.h>
#include <binsparse/matrix_market/matrix_market_type_t.h>

bsp_matrix_t bsp_mmread_explicit_array(char* file_path, bsp_type_t value_type,
bsp_matrix_t bsp_mmread_explicit_array(const char* file_path,
bsp_type_t value_type,
bsp_type_t index_type) {
bsp_mm_metadata metadata = bsp_mmread_metadata(file_path);

Expand Down Expand Up @@ -96,7 +97,7 @@ bsp_matrix_t bsp_mmread_explicit_array(char* file_path, bsp_type_t value_type,
return matrix;
}

bsp_matrix_t bsp_mmread_explicit_coordinate(char* file_path,
bsp_matrix_t bsp_mmread_explicit_coordinate(const char* file_path,
bsp_type_t value_type,
bsp_type_t index_type) {
bsp_mm_metadata metadata = bsp_mmread_metadata(file_path);
Expand Down Expand Up @@ -254,7 +255,7 @@ bsp_matrix_t bsp_mmread_explicit_coordinate(char* file_path,
return matrix;
}

bsp_matrix_t bsp_mmread_explicit(char* file_path, bsp_type_t value_type,
bsp_matrix_t bsp_mmread_explicit(const char* file_path, bsp_type_t value_type,
bsp_type_t index_type) {
bsp_mm_metadata metadata = bsp_mmread_metadata(file_path);

Expand All @@ -267,7 +268,7 @@ bsp_matrix_t bsp_mmread_explicit(char* file_path, bsp_type_t value_type,
}
}

bsp_matrix_t bsp_mmread(char* file_path) {
bsp_matrix_t bsp_mmread(const char* file_path) {
bsp_mm_metadata metadata = bsp_mmread_metadata(file_path);

bsp_type_t value_type;
Expand Down
2 changes: 1 addition & 1 deletion include/binsparse/matrix_market/matrix_market_write.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <binsparse/matrix_market/matrix_market_type_t.h>

void bsp_mmwrite(char* file_path, bsp_matrix_t matrix) {
void bsp_mmwrite(const char* file_path, bsp_matrix_t matrix) {
FILE* f = fopen(file_path, "w");

assert(f != NULL);
Expand Down
6 changes: 3 additions & 3 deletions include/binsparse/read_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ bsp_matrix_t bsp_read_matrix_from_group(hid_t f) {
return matrix;
}

size_t bsp_final_dot(char* str) {
size_t bsp_final_dot(const char* str) {
size_t dot_idx = 0;
for (size_t i = 0; str[i] != '\0'; i++) {
if (str[i] == '.') {
Expand All @@ -219,7 +219,7 @@ size_t bsp_final_dot(char* str) {
return dot_idx;
}

bsp_matrix_t bsp_read_matrix_parallel(char* file_name, char* group,
bsp_matrix_t bsp_read_matrix_parallel(const char* file_name, const char* group,
int num_threads) {
if (group == NULL) {
size_t idx = bsp_final_dot(file_name);
Expand All @@ -244,7 +244,7 @@ bsp_matrix_t bsp_read_matrix_parallel(char* file_name, char* group,
}
}

bsp_matrix_t bsp_read_matrix(char* file_name, char* group) {
bsp_matrix_t bsp_read_matrix(const char* file_name, const char* group) {
if (group == NULL) {
size_t idx = bsp_final_dot(file_name);
if (strcmp(file_name + idx, ".hdf5") == 0 ||
Expand Down
2 changes: 1 addition & 1 deletion include/binsparse/write_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ int bsp_write_matrix_to_group(hid_t f, bsp_matrix_t matrix, cJSON* user_json,
return 0;
}

int bsp_write_matrix(char* fname, bsp_matrix_t matrix, char* group,
int bsp_write_matrix(const char* fname, bsp_matrix_t matrix, const char* group,
cJSON* user_json, int compression_level) {
if (group == NULL) {
hid_t f = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
Expand Down

0 comments on commit 7809a68

Please sign in to comment.