Skip to content

Commit aaf8cb7

Browse files
committed
CPP modularized bitset module
1 parent 9e4c230 commit aaf8cb7

23 files changed

+210
-58
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ if(NOT DEFINED CMAKE_MAXIMUM_RANK)
4949
set(CMAKE_MAXIMUM_RANK 4 CACHE STRING "Maximum array rank for generated procedures")
5050
endif()
5151

52+
53+
option(STDLIB_WITH_BITSET "Compile STDLIB BITSET" ON)
54+
55+
if(STDLIB_WITH_BITSET)
56+
message(STATUS "Enable stdlib bitset module")
57+
add_compile_definitions(STDLIB_BITSET)
58+
endif()
59+
5260
option(FIND_BLAS "Find external BLAS and LAPACK" ON)
5361

5462
# --- find external BLAS and LAPACK

cmake/stdlib.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ function(configure_stdlib_target target_name regular_sources_var fypp_files_var
101101
$<BUILD_INTERFACE:${LIB_MOD_DIR}>
102102
$<INSTALL_INTERFACE:${CMAKE_INSTALL_MODULEDIR}>
103103
)
104+
target_include_directories(${target_name} PRIVATE
105+
${PROJECT_SOURCE_DIR}/include
106+
)
104107

105108
install(TARGETS ${target_name}
106109
EXPORT ${PROJECT_NAME}-targets

doc/specs/stdlib_math.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ All arguments must have same `type` and same `kind`.
9393
#### Examples
9494

9595
```fortran
96-
{!example/math/example_math_swap.f90!}
96+
{!example/math/example_math_swap.F90!}
9797
```
9898

9999
### `gcd` function

example/CMakeLists.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,22 @@ macro(ADD_EXAMPLE name)
66
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
77
endmacro(ADD_EXAMPLE)
88

9+
macro(ADD_EXAMPLEPP name)
10+
add_executable(example_${name} example_${name}.F90)
11+
target_link_libraries(example_${name} "${PROJECT_NAME}")
12+
add_test(NAME ${name}
13+
COMMAND $<TARGET_FILE:example_${name}> ${CMAKE_CURRENT_BINARY_DIR}
14+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
15+
endmacro(ADD_EXAMPLEPP)
16+
17+
18+
919
add_subdirectory(ansi)
1020
add_subdirectory(array)
1121
add_subdirectory(ascii)
12-
add_subdirectory(bitsets)
22+
if (STDLIB_WITH_BITSET)
23+
add_subdirectory(bitsets)
24+
endif()
1325
add_subdirectory(constants)
1426
add_subdirectory(error)
1527
add_subdirectory(hashmaps)

example/math/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ ADD_EXAMPLE(math_argpi)
1515
ADD_EXAMPLE(math_deg2rad)
1616
ADD_EXAMPLE(math_rad2deg)
1717
ADD_EXAMPLE(math_is_close)
18-
ADD_EXAMPLE(math_swap)
18+
ADD_EXAMPLEPP(math_swap)
1919
ADD_EXAMPLE(meshgrid)

example/math/example_math_swap.f90 renamed to example/math/example_math_swap.F90

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ program example_math_swap
4343
call swap(x,y)
4444
end block
4545

46+
#ifdef STDLIB_BITSET
4647
block
4748
use stdlib_bitsets
4849
type(bitset_64) :: x, y
4950
call x%from_string('0000')
5051
call y%from_string('1111')
5152
call swap(x,y)
5253
end block
54+
#endif
5355

54-
end program example_math_swap
56+
end program example_math_swap

example/sorting/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ ADD_EXAMPLE(sort)
33
ADD_EXAMPLE(sort_adjoint)
44
ADD_EXAMPLE(sort_index)
55
ADD_EXAMPLE(radix_sort)
6-
ADD_EXAMPLE(sort_bitset)
6+
if (STDLIB_WITH_BITSET)
7+
ADD_EXAMPLE(sort_bitset)
8+
endif()

include/common.fypp

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@
4545
#:set REAL_TYPES = ["real({})".format(k) for k in REAL_KINDS]
4646
#:set REAL_SUFFIX = REAL_KINDS
4747

48+
#! Real CPPS to be considered during templating
49+
#:set REAL_CPPS = ["" for k in REAL_KINDS]
50+
4851
#! Collected (kind, type) tuples for real types
49-
#:set REAL_KINDS_TYPES = list(zip(REAL_KINDS, REAL_TYPES, REAL_INIT))
52+
#:set REAL_KINDS_TYPES = list(zip(REAL_KINDS, REAL_TYPES, REAL_INIT, REAL_CPPS))
5053

5154
#! Complex kinds to be considered during templating
5255
#:set CMPLX_KINDS = ["sp", "dp"]
@@ -102,8 +105,14 @@ $:"s" if cmplx=="c" else "d" if cmplx=="z" else "x" if cmplx=="y" else "q" if cm
102105
#! Integer types to be considered during templating
103106
#:set INT_TYPES = ["integer({})".format(k) for k in INT_KINDS]
104107

108+
#! Integer abbreviations to be considered during templating
109+
#:set INT_INIT = ["" for k in INT_KINDS]
110+
111+
#! Integer CPPs to be considered during templating
112+
#:set INT_CPPS = ["" for k in INT_KINDS]
113+
105114
#! Collected (kind, type) tuples for integer types
106-
#:set INT_KINDS_TYPES = list(zip(INT_KINDS, INT_TYPES))
115+
#:set INT_KINDS_TYPES = list(zip(INT_KINDS, INT_TYPES, INT_INIT, INT_CPPS))
107116

108117
#! Logical kinds to be considered during templating
109118
#:set LOG_KINDS = ["lk"]
@@ -123,6 +132,12 @@ $:"s" if cmplx=="c" else "d" if cmplx=="z" else "x" if cmplx=="y" else "q" if cm
123132
#! String types to be considered during templating
124133
#:set STRING_TYPES = ["type({})".format(k) for k in STRING_KINDS]
125134

135+
#! String abbreviations to be considered during templating
136+
#:set STRING_INIT = ["" for k in STRING_KINDS]
137+
138+
#! String CPPs to be considered during templating
139+
#:set STRING_CPPS = ["" for k in STRING_KINDS]
140+
126141
#! Collected (kind, type) tuples for string derived types
127142
#:set STRING_KINDS_TYPES = list(zip(STRING_KINDS, STRING_TYPES))
128143

@@ -132,6 +147,15 @@ $:"s" if cmplx=="c" else "d" if cmplx=="z" else "x" if cmplx=="y" else "q" if cm
132147
#! Bitset types to be considered during templating
133148
#:set BITSET_TYPES = ["type({})".format(k) for k in BITSET_KINDS]
134149

150+
#! Bitset abbreviations directive to be considered during templating
151+
#:set BITSET_INIT = ["" for k in BITSET_KINDS]
152+
153+
#! Bitset CPP directive to be considered during templating
154+
#:set BITSET_CPPS = ["STDLIB_BITSET" for k in BITSET_KINDS]
155+
156+
#! Collected (kind, type) tuples for bitset types
157+
#:set BITSET_KINDS_TYPES = list(zip(BITSET_KINDS, BITSET_TYPES, BITSET_INIT, BITSET_CPPS))
158+
135159
#! Sparse types to be considered during templating
136160
#:set SPARSE_KINDS = ["COO", "CSR", "CSC", "ELL"]
137161

@@ -463,4 +487,23 @@ ${indent}$do ${varname}$${n+1+dim_offset-i}$ = lbound(${matname}$, ${n+1+dim_off
463487
#:endcall
464488
#:enddef
465489

490+
#!
491+
492+
#!
493+
#! Encapsulate code into CPP pre-processing directives #ifdef and #endif
494+
#!
495+
#! Args:
496+
#! code (str): Code to be encapsulated
497+
#! cpp_var (str): CPP variable
498+
#!
499+
#:def generate_cpp(code, cpp_var)
500+
#:if cpp_var != ""
501+
#ifdef ${cpp_var}$
502+
#:endif
503+
$:code
504+
#:if cpp_var != ""
505+
#endif
506+
#:endif
507+
#:enddef generate_cpp
508+
466509
#:endmute

src/CMakeLists.txt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
if (STDLIB_WITH_BITSET)
2+
add_subdirectory(bitsets)
3+
endif()
14
add_subdirectory(blas)
25
add_subdirectory(lapack)
36

47
set(fppFiles
58
stdlib_ascii.fypp
6-
stdlib_bitsets.fypp
7-
stdlib_bitsets_64.fypp
8-
stdlib_bitsets_large.fypp
99
stdlib_codata_type.fypp
1010
stdlib_constants.fypp
1111
stdlib_error.fypp
@@ -49,10 +49,6 @@ set(fppFiles
4949
stdlib_linalg_matrix_functions.fypp
5050
stdlib_optval.fypp
5151
stdlib_selection.fypp
52-
stdlib_sorting.fypp
53-
stdlib_sorting_ord_sort.fypp
54-
stdlib_sorting_sort.fypp
55-
stdlib_sorting_sort_adjoint.fypp
5652
stdlib_sparse_constants.fypp
5753
stdlib_sparse_conversion.fypp
5854
stdlib_sparse_kinds.fypp
@@ -79,7 +75,6 @@ set(fppFiles
7975
stdlib_quadrature_trapz.fypp
8076
stdlib_quadrature_simps.fypp
8177
stdlib_random.fypp
82-
stdlib_math.fypp
8378
stdlib_math_linspace.fypp
8479
stdlib_math_logspace.fypp
8580
stdlib_math_arange.fypp
@@ -94,7 +89,13 @@ set(fppFiles
9489
stdlib_strings.fypp
9590
stdlib_version.fypp
9691
)
97-
set(cppFiles stdlib_linalg_constants.fypp)
92+
set(cppFiles stdlib_linalg_constants.fypp
93+
stdlib_math.fypp
94+
stdlib_sorting.fypp
95+
stdlib_sorting_ord_sort.fypp
96+
stdlib_sorting_sort.fypp
97+
stdlib_sorting_sort_adjoint.fypp
98+
)
9899
set(f90Files
99100
stdlib_ansi.f90
100101
stdlib_ansi_operator.f90
@@ -121,4 +122,6 @@ set(f90Files
121122

122123
configure_stdlib_target(${PROJECT_NAME} f90Files fppFiles cppFiles)
123124

124-
target_link_libraries(${PROJECT_NAME} PUBLIC blas lapack)
125+
target_link_libraries(${PROJECT_NAME} PUBLIC
126+
$<$<BOOL:${STDLIB_WITH_BITSET}>:bitsets>
127+
blas lapack)

src/bitsets/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
set(bitsets_fppFiles
2+
../stdlib_kinds.fypp
3+
../stdlib_optval.fypp
4+
stdlib_bitsets.fypp
5+
stdlib_bitsets_64.fypp
6+
stdlib_bitsets_large.fypp
7+
)
8+
9+
configure_stdlib_target(bitsets "" bitsets_fppFiles "")

0 commit comments

Comments
 (0)