Skip to content

Commit 1c870ce

Browse files
committed
Much more inline
1 parent 590f7c3 commit 1c870ce

File tree

9 files changed

+29
-28
lines changed

9 files changed

+29
-28
lines changed

include/binsparse/detail/declamp_values.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <binsparse/matrix.h>
1010
#include <math.h>
1111

12-
double bsp_suitesparse_declamp_impl_(double value) {
12+
inline double bsp_suitesparse_declamp_impl_(double value) {
1313
const double HUGE_DOUBLE = 1e308;
1414
if (value >= HUGE_DOUBLE) {
1515
return INFINITY;
@@ -26,7 +26,7 @@ double bsp_suitesparse_declamp_impl_(double value) {
2626
// Here, we "declamp" these values to restore them to infinity.
2727
// This allows the `bsp_matrix_minimize_values` to properly minimize
2828
// matrices that have infinity values.
29-
void bsp_matrix_declamp_values(bsp_matrix_t matrix) {
29+
inline void bsp_matrix_declamp_values(bsp_matrix_t matrix) {
3030
if (matrix.values.type == BSP_FLOAT64) {
3131
double* values = (double*) matrix.values.data;
3232

include/binsparse/detail/parse_dataset.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ typedef struct {
1313
char* dataset;
1414
} bsp_fdataset_info_t;
1515

16-
bsp_fdataset_info_t bsp_parse_fdataset_string(char* str) {
16+
inline bsp_fdataset_info_t bsp_parse_fdataset_string(char* str) {
1717
size_t len = strlen(str);
1818

1919
int split = -1;
@@ -41,7 +41,7 @@ bsp_fdataset_info_t bsp_parse_fdataset_string(char* str) {
4141
}
4242
}
4343

44-
const char* bsp_get_file_extension(const char* file_name) {
44+
inline const char* bsp_get_file_extension(const char* file_name) {
4545
int64_t len = strlen(file_name);
4646
for (int64_t i = len - 1; i >= 0; i--) {
4747
if (file_name[i] == '.') {

include/binsparse/detail/shm_tools.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ typedef struct {
2020
size_t size;
2121
} bsp_shm_t;
2222

23-
bsp_shm_t bsp_shm_new(size_t size) {
23+
inline bsp_shm_t bsp_shm_new(size_t size) {
2424
bsp_shm_t shm;
2525
shm.size = size;
2626

@@ -32,11 +32,11 @@ bsp_shm_t bsp_shm_new(size_t size) {
3232
return shm;
3333
}
3434

35-
void bsp_shm_delete(bsp_shm_t shm) {
35+
inline void bsp_shm_delete(bsp_shm_t shm) {
3636
shmctl(shm.id, IPC_RMID, 0);
3737
}
3838

39-
void* bsp_shm_attach(bsp_shm_t shm) {
39+
inline void* bsp_shm_attach(bsp_shm_t shm) {
4040
void* data;
4141

4242
if ((data = shmat(shm.id, NULL, 0)) == (void*) -1) {
@@ -46,11 +46,11 @@ void* bsp_shm_attach(bsp_shm_t shm) {
4646
return data;
4747
}
4848

49-
void bsp_shm_detach(void* data) {
49+
inline void bsp_shm_detach(void* data) {
5050
shmdt(data);
5151
}
5252

53-
void* bsp_shm_malloc(size_t size) {
53+
inline void* bsp_shm_malloc(size_t size) {
5454
bsp_shm_t shm_id = bsp_shm_new(size);
5555

5656
void* ptr = bsp_shm_attach(shm_id);
@@ -60,7 +60,7 @@ void* bsp_shm_malloc(size_t size) {
6060
return ptr;
6161
}
6262

63-
void bsp_shm_free(void* ptr) {
63+
inline void bsp_shm_free(void* ptr) {
6464
bsp_shm_detach(ptr);
6565
}
6666

include/binsparse/generate.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include <binsparse/matrix.h>
1010

11-
void bsp_array_fill_random(bsp_array_t array, size_t bound) {
11+
inline void bsp_array_fill_random(bsp_array_t array, size_t bound) {
1212
if (array.type == BSP_UINT8) {
1313
uint8_t* values = (uint8_t*) array.data;
1414
for (size_t i = 0; i < array.size; i++) {
@@ -67,8 +67,9 @@ void bsp_array_fill_random(bsp_array_t array, size_t bound) {
6767
}
6868
}
6969

70-
bsp_matrix_t bsp_generate_coo(size_t m, size_t n, size_t nnz,
71-
bsp_type_t value_type, bsp_type_t index_type) {
70+
inline bsp_matrix_t bsp_generate_coo(size_t m, size_t n, size_t nnz,
71+
bsp_type_t value_type,
72+
bsp_type_t index_type) {
7273
bsp_matrix_t matrix = bsp_construct_default_matrix_t();
7374
matrix.nrows = m;
7475
matrix.ncols = n;

include/binsparse/matrix.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ typedef struct bsp_matrix_t {
2626
bsp_structure_t structure;
2727
} bsp_matrix_t;
2828

29-
bsp_matrix_t bsp_construct_default_matrix_t() {
29+
inline bsp_matrix_t bsp_construct_default_matrix_t() {
3030
bsp_matrix_t mat;
3131
mat.values = bsp_construct_default_array_t();
3232
mat.indices_0 = bsp_construct_default_array_t();
@@ -38,14 +38,14 @@ bsp_matrix_t bsp_construct_default_matrix_t() {
3838
return mat;
3939
}
4040

41-
void bsp_destroy_matrix_t(bsp_matrix_t matrix) {
41+
inline void bsp_destroy_matrix_t(bsp_matrix_t matrix) {
4242
bsp_destroy_array_t(matrix.values);
4343
bsp_destroy_array_t(matrix.indices_0);
4444
bsp_destroy_array_t(matrix.indices_1);
4545
bsp_destroy_array_t(matrix.pointers_to_1);
4646
}
4747

48-
size_t bsp_matrix_nbytes(bsp_matrix_t mat) {
48+
inline size_t bsp_matrix_nbytes(bsp_matrix_t mat) {
4949
size_t nbytes = 0;
5050
if (mat.values.size > 0) {
5151
nbytes += mat.values.size * bsp_type_size(mat.values.type);
@@ -66,7 +66,7 @@ size_t bsp_matrix_nbytes(bsp_matrix_t mat) {
6666
return nbytes;
6767
}
6868

69-
void bsp_print_matrix_info(bsp_matrix_t matrix) {
69+
inline void bsp_print_matrix_info(bsp_matrix_t matrix) {
7070
printf("%lu x %lu matrix with %lu nnz.\n", matrix.nrows, matrix.ncols,
7171
matrix.nnz);
7272
printf("%s format with %s structure\n",

include/binsparse/matrix_formats.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ typedef enum bsp_matrix_format_t {
2424
BSP_INVALID_FORMAT = 21
2525
} bsp_matrix_format_t;
2626

27-
char* bsp_get_matrix_format_string(bsp_matrix_format_t format) {
27+
inline char* bsp_get_matrix_format_string(bsp_matrix_format_t format) {
2828
if (format == BSP_DVEC) {
2929
return (char*) "DVEC";
3030
} else if (format == BSP_DMAT) {
@@ -48,7 +48,7 @@ char* bsp_get_matrix_format_string(bsp_matrix_format_t format) {
4848
}
4949
}
5050

51-
bsp_matrix_format_t bsp_get_matrix_format(char* format) {
51+
inline bsp_matrix_format_t bsp_get_matrix_format(char* format) {
5252
if (strcmp("DVEC", format) == 0) {
5353
return BSP_DVEC;
5454
} else if (strcmp("DMAT", format) == 0) {

include/binsparse/minimize_values.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
// Given a matrix `matrix`, store its values using the smallest type possible
1313
// without losing precision.
14-
bsp_matrix_t bsp_matrix_minimize_values(bsp_matrix_t matrix) {
14+
inline bsp_matrix_t bsp_matrix_minimize_values(bsp_matrix_t matrix) {
1515
if (matrix.values.type == BSP_FLOAT64) {
1616
bool float32_representable = true;
1717

include/binsparse/structure.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ typedef enum bsp_structure_t {
2222
BSP_INVALID_STRUCTURE = 106
2323
} bsp_structure_t;
2424

25-
char* bsp_get_structure_string(bsp_structure_t structure) {
25+
inline char* bsp_get_structure_string(bsp_structure_t structure) {
2626
if (structure == BSP_GENERAL) {
2727
return (char*) "general";
2828
} else if (structure == BSP_SYMMETRIC_LOWER) {
@@ -42,7 +42,7 @@ char* bsp_get_structure_string(bsp_structure_t structure) {
4242
}
4343
}
4444

45-
bsp_structure_t bsp_get_structure(char* structure) {
45+
inline bsp_structure_t bsp_get_structure(char* structure) {
4646
if (strcmp(structure, "symmetric_lower") == 0) {
4747
return BSP_SYMMETRIC_LOWER;
4848
} else if (strcmp(structure, "symmetric_upper") == 0) {

include/binsparse/types.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ typedef enum bsp_type_t {
2626
BSP_INVALID_TYPE = 13
2727
} bsp_type_t;
2828

29-
char* bsp_get_type_string(bsp_type_t type) {
29+
inline char* bsp_get_type_string(bsp_type_t type) {
3030
if (type == BSP_UINT8) {
3131
return (char*) "uint8";
3232
} else if (type == BSP_UINT16) {
@@ -58,7 +58,7 @@ char* bsp_get_type_string(bsp_type_t type) {
5858
}
5959
}
6060

61-
size_t bsp_type_size(bsp_type_t type) {
61+
inline size_t bsp_type_size(bsp_type_t type) {
6262
if (type == BSP_UINT8) {
6363
return sizeof(uint8_t);
6464
} else if (type == BSP_UINT16) {
@@ -90,7 +90,7 @@ size_t bsp_type_size(bsp_type_t type) {
9090
}
9191
}
9292

93-
hid_t bsp_get_hdf5_standard_type(bsp_type_t type) {
93+
inline hid_t bsp_get_hdf5_standard_type(bsp_type_t type) {
9494
if (type == BSP_UINT8) {
9595
return H5T_STD_U8LE;
9696
} else if (type == BSP_UINT16) {
@@ -118,7 +118,7 @@ hid_t bsp_get_hdf5_standard_type(bsp_type_t type) {
118118
}
119119
}
120120

121-
bsp_type_t bsp_get_bsp_type(hid_t type) {
121+
inline bsp_type_t bsp_get_bsp_type(hid_t type) {
122122
H5T_class_t cl = H5Tget_class(type);
123123
H5T_order_t order = H5Tget_order(type);
124124
H5T_sign_t sign = H5Tget_sign(type);
@@ -166,7 +166,7 @@ bsp_type_t bsp_get_bsp_type(hid_t type) {
166166
// NOTE: This code is a bit silly, but it seems to be the only
167167
// way to generically determine the HDF5 native types for
168168
// stdint's fixed width integer types.
169-
hid_t bsp_get_hdf5_native_type(bsp_type_t type) {
169+
inline hid_t bsp_get_hdf5_native_type(bsp_type_t type) {
170170
if (type == BSP_INT8 || type == BSP_BINT8) {
171171
if (sizeof(int8_t) == sizeof(char)) {
172172
return H5T_NATIVE_CHAR;
@@ -290,7 +290,7 @@ hid_t bsp_get_hdf5_native_type(bsp_type_t type) {
290290

291291
// Given the maximum value `max_value` that must be stored,
292292
// pick an unsigned integer type for indices.
293-
bsp_type_t bsp_pick_integer_type(size_t max_value) {
293+
inline bsp_type_t bsp_pick_integer_type(size_t max_value) {
294294
if (max_value < (size_t) UINT8_MAX) {
295295
return BSP_UINT8;
296296
} else if (max_value < (size_t) UINT16_MAX) {

0 commit comments

Comments
 (0)