Skip to content

Commit

Permalink
Make bsp_read_matrix statically linked instead of header-only.
Browse files Browse the repository at this point in the history
  • Loading branch information
BenBrock committed Oct 24, 2024
1 parent 3ea3cb3 commit e83e90e
Show file tree
Hide file tree
Showing 9 changed files with 333 additions and 285 deletions.
15 changes: 11 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ set(CMAKE_CXX_STANDARD 20)

set(CMAKE_C_FLAGS "-O3 -march=native")

add_library(binsparse-rc STATIC)

add_subdirectory(include)
add_subdirectory(src)

# NOTE: For now, both HDF5 and cJSON are `PUBLIC`, meaning that anything that
# depends on `binsparse-rc` will also link/include HDF5 and cJSON. We can change
# these to `PRIVATE` to use them only when building binsparse-rc.

find_package(HDF5 REQUIRED COMPONENTS C)
target_link_libraries(binsparse-rc INTERFACE ${HDF5_C_LIBRARIES})
target_include_directories(binsparse-rc INTERFACE . ${HDF5_INCLUDE_DIRS})
target_link_libraries(binsparse-rc PUBLIC ${HDF5_C_LIBRARIES})
target_include_directories(binsparse-rc PUBLIC . ${HDF5_INCLUDE_DIRS})

include(FetchContent)
FetchContent_Declare(
Expand All @@ -28,8 +35,8 @@ FetchContent_Declare(
FetchContent_MakeAvailable(cJSON)

configure_file(${cJSON_SOURCE_DIR}/cJSON.h ${CMAKE_BINARY_DIR}/include/cJSON/cJSON.h)
target_include_directories(${PROJECT_NAME} INTERFACE ${CMAKE_BINARY_DIR}/include)
target_link_libraries(${PROJECT_NAME} INTERFACE cjson)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_BINARY_DIR}/include)
target_link_libraries(${PROJECT_NAME} PUBLIC cjson)

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
add_subdirectory(examples)
Expand Down
3 changes: 1 addition & 2 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
#
# SPDX-License-Identifier: BSD-3-Clause

add_library(binsparse-rc INTERFACE)
target_include_directories(binsparse-rc INTERFACE .)
target_include_directories(binsparse-rc PUBLIC .)
15 changes: 8 additions & 7 deletions include/binsparse/hdf5_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

// Write an array to a dataset / file
// Returns 0 on success, nonzero on error.
int bsp_write_array(hid_t f, const char* label, bsp_array_t array,
int compression_level) {
static inline 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 @@ -76,8 +76,8 @@ int bsp_write_array(hid_t f, const char* label, bsp_array_t array,
}

#if __STDC_VERSION__ >= 201112L
bsp_array_t bsp_read_array_parallel(hid_t f, const char* label,
int num_threads) {
static inline 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 @@ -173,7 +173,7 @@ bsp_array_t bsp_read_array_parallel(hid_t f, const char* label,
}
#endif

bsp_array_t bsp_read_array(hid_t f, const char* label) {
static inline 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 @@ -212,7 +212,8 @@ bsp_array_t bsp_read_array(hid_t f, const char* label) {
return array;
}

void bsp_write_attribute(hid_t f, const char* label, const char* string) {
static inline 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 @@ -228,7 +229,7 @@ void bsp_write_attribute(hid_t f, const char* label, const char* string) {
H5Sclose(dataspace);
}

char* bsp_read_attribute(hid_t f, const char* label) {
static inline 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 @@ -32,7 +32,7 @@ typedef struct bsp_mm_metadata {
char* comments;
} bsp_mm_metadata;

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

assert(f != NULL);
Expand Down
20 changes: 11 additions & 9 deletions include/binsparse/matrix_market/matrix_market_read.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
#include <stdint.h>
#include <stdlib.h>

#include <binsparse/matrix.h>
#include <binsparse/matrix_market/coo_sort_tools.h>
#include <binsparse/matrix_market/matrix_market_inspector.h>
#include <binsparse/matrix_market/matrix_market_type_t.h>

bsp_matrix_t bsp_mmread_explicit_array(const char* file_path,
bsp_type_t value_type,
bsp_type_t index_type) {
static inline 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);

bsp_matrix_market_type_t mm_type;
Expand Down Expand Up @@ -103,9 +104,9 @@ bsp_matrix_t bsp_mmread_explicit_array(const char* file_path,
return matrix;
}

bsp_matrix_t bsp_mmread_explicit_coordinate(const char* file_path,
bsp_type_t value_type,
bsp_type_t index_type) {
static inline 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);

bsp_matrix_market_type_t mm_type;
Expand Down Expand Up @@ -261,8 +262,9 @@ bsp_matrix_t bsp_mmread_explicit_coordinate(const char* file_path,
return matrix;
}

bsp_matrix_t bsp_mmread_explicit(const char* file_path, bsp_type_t value_type,
bsp_type_t index_type) {
static inline 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);

if (strcmp(metadata.format, "array") == 0) {
Expand All @@ -274,7 +276,7 @@ bsp_matrix_t bsp_mmread_explicit(const char* file_path, bsp_type_t value_type,
}
}

bsp_matrix_t bsp_mmread(const char* file_path) {
static inline 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 @@ -12,7 +12,7 @@

#include <binsparse/matrix_market/matrix_market_type_t.h>

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

assert(f != NULL);
Expand Down
Loading

0 comments on commit e83e90e

Please sign in to comment.