Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions .github/workflows/ci_modular.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: CI

on: [push, pull_request]

env:
CMAKE_BUILD_PARALLEL_LEVEL: "2" # 2 cores on each GHA VM, enable parallel builds
CTEST_OUTPUT_ON_FAILURE: "ON" # This way we don't need a flag to ctest
CTEST_PARALLEL_LEVEL: "2"
CTEST_TIME_TIMEOUT: "5" # some failures hang forever
HOMEBREW_NO_ANALYTICS: "ON" # Make Homebrew installation a little quicker
HOMEBREW_NO_AUTO_UPDATE: "ON"
HOMEBREW_NO_BOTTLE_SOURCE_FALLBACK: "ON"
HOMEBREW_NO_GITHUB_API: "ON"
HOMEBREW_NO_INSTALL_CLEANUP: "ON"

jobs:
Build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
toolchain:
- {compiler: gcc, version: 14}
build: [cmake]
with_bitset: [On, Off]
env:
BUILD_DIR: ${{ matrix.build == 'cmake' && 'build' || '.' }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python 3.x
uses: actions/setup-python@v5 # Use pip to install latest CMake, & FORD/Jin2For, etc.
with:
python-version: 3.x

- name: Install fypp
run: pip install --upgrade fypp ninja

- name: Setup Fortran compiler
uses: fortran-lang/setup-fortran@v1.6.2
id: setup-fortran
with:
compiler: ${{ matrix.toolchain.compiler }}
version: ${{ matrix.toolchain.version }}

# Build and test with built-in BLAS and LAPACK
- name: Configure with CMake
if: ${{ contains(matrix.build, 'cmake') }}
run: >-
cmake -Wdev -G Ninja
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_MAXIMUM_RANK:String=4
-DCMAKE_INSTALL_PREFIX=$PWD/_dist
-DFIND_BLAS:STRING=FALSE
-DSTDLIB_NO_BITSET:STRING=${{ matrix.with_bitset }}
-S . -B ${{ env.BUILD_DIR }}

- name: Build and compile
if: ${{ contains(matrix.build, 'cmake') }}
run: cmake --build ${{ env.BUILD_DIR }} --parallel

- name: catch build fail
if: ${{ failure() && contains(matrix.build, 'cmake') }}
run: cmake --build ${{ env.BUILD_DIR }} --verbose --parallel 1

- name: test
if: ${{ contains(matrix.build, 'cmake') }}
run: >-
ctest
--test-dir ${{ env.BUILD_DIR }}
--parallel
--output-on-failure
--no-tests=error

- name: Install project
if: ${{ contains(matrix.build, 'cmake') }}
run: cmake --install ${{ env.BUILD_DIR }}
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ if(NOT DEFINED CMAKE_MAXIMUM_RANK)
set(CMAKE_MAXIMUM_RANK 4 CACHE STRING "Maximum array rank for generated procedures")
endif()

option(STDLIB_NO_BITSET "Does not compile STDLIB BITSET" OFF)

if(STDLIB_NO_BITSET)
message(STATUS "Disable stdlib bitset module")
add_compile_definitions(STDLIB_NO_BITSET)
endif()

option(FIND_BLAS "Find external BLAS and LAPACK" ON)

# --- find external BLAS and LAPACK
Expand Down Expand Up @@ -128,6 +135,7 @@ list(
"-I${PROJECT_SOURCE_DIR}/include"
)

include_directories(${PROJECT_SOURCE_DIR}/include)
add_subdirectory(src)

if(BUILD_TESTING)
Expand Down
10 changes: 9 additions & 1 deletion config/fypp_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
from joblib import Parallel, delayed

C_PREPROCESSED = (
"example_math_swap",
"stdlib_linalg_constants" ,
"stdlib_linalg_blas" ,
"stdlib_linalg_lapack",
"test_blas_lapack"
"stdlib_math",
"stdlib_sorting",
"stdlib_sorting_ord_sort",
"stdlib_sorting_sort",
"stdlib_sorting_sort_adjoint",
"test_blas_lapack",
"test_stdlib_math",
"test_sorting"
)

def pre_process_fypp(args):
Expand Down
2 changes: 1 addition & 1 deletion doc/specs/stdlib_math.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ All arguments must have same `type` and same `kind`.
#### Examples

```fortran
{!example/math/example_math_swap.f90!}
{!example/math/example_math_swap.F90!}
```

### `gcd` function
Expand Down
14 changes: 13 additions & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@ macro(ADD_EXAMPLE name)
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endmacro(ADD_EXAMPLE)

macro(ADD_EXAMPLEPP name)
add_executable(example_${name} example_${name}.F90)
target_link_libraries(example_${name} "${PROJECT_NAME}")
add_test(NAME ${name}
COMMAND $<TARGET_FILE:example_${name}> ${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endmacro(ADD_EXAMPLEPP)



add_subdirectory(ansi)
add_subdirectory(array)
add_subdirectory(ascii)
add_subdirectory(bitsets)
if (NOT STDLIB_NO_BITSET)
add_subdirectory(bitsets)
endif()
add_subdirectory(constants)
add_subdirectory(error)
add_subdirectory(hashmaps)
Expand Down
2 changes: 1 addition & 1 deletion example/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ ADD_EXAMPLE(math_argpi)
ADD_EXAMPLE(math_deg2rad)
ADD_EXAMPLE(math_rad2deg)
ADD_EXAMPLE(math_is_close)
ADD_EXAMPLE(math_swap)
ADD_EXAMPLEPP(math_swap)
ADD_EXAMPLE(meshgrid)
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "macros.inc"
program example_math_swap
use stdlib_math, only: swap
implicit none
Expand Down Expand Up @@ -43,12 +44,14 @@ program example_math_swap
call swap(x,y)
end block

#ifdef STDLIB_BITSET
block
use stdlib_bitsets
type(bitset_64) :: x, y
call x%from_string('0000')
call y%from_string('1111')
call swap(x,y)
end block
#endif

end program example_math_swap
end program example_math_swap
4 changes: 3 additions & 1 deletion example/sorting/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ ADD_EXAMPLE(sort)
ADD_EXAMPLE(sort_adjoint)
ADD_EXAMPLE(sort_index)
ADD_EXAMPLE(radix_sort)
ADD_EXAMPLE(sort_bitset)
if (NOT STDLIB_NO_BITSET)
ADD_EXAMPLE(sort_bitset)
endif()
45 changes: 43 additions & 2 deletions include/common.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@
#:set REAL_TYPES = ["real({})".format(k) for k in REAL_KINDS]
#:set REAL_SUFFIX = REAL_KINDS

#! Real CPPS to be considered during templating
#:set REAL_CPPS = ["" for k in REAL_KINDS]

#! Collected (kind, type) tuples for real types
#:set REAL_KINDS_TYPES = list(zip(REAL_KINDS, REAL_TYPES, REAL_INIT))
#:set REAL_KINDS_TYPES = list(zip(REAL_KINDS, REAL_TYPES, REAL_INIT, REAL_CPPS))

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

#! Integer abbreviations to be considered during templating
#:set INT_INIT = ["" for k in INT_KINDS]

#! Integer CPPs to be considered during templating
#:set INT_CPPS = ["" for k in INT_KINDS]

#! Collected (kind, type) tuples for integer types
#:set INT_KINDS_TYPES = list(zip(INT_KINDS, INT_TYPES))
#:set INT_KINDS_TYPES = list(zip(INT_KINDS, INT_TYPES, INT_INIT, INT_CPPS))

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

#! String abbreviations to be considered during templating
#:set STRING_INIT = ["" for k in STRING_KINDS]

#! String CPPs to be considered during templating
#:set STRING_CPPS = ["" for k in STRING_KINDS]

#! Collected (kind, type) tuples for string derived types
#:set STRING_KINDS_TYPES = list(zip(STRING_KINDS, STRING_TYPES))

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

#! Bitset abbreviations directive to be considered during templating
#:set BITSET_INIT = ["" for k in BITSET_KINDS]

#! Bitset CPP directive to be considered during templating
#:set BITSET_CPPS = ["STDLIB_BITSET" for k in BITSET_KINDS]

#! Collected (kind, type) tuples for bitset types
#:set BITSET_KINDS_TYPES = list(zip(BITSET_KINDS, BITSET_TYPES, BITSET_INIT, BITSET_CPPS))

#! Sparse types to be considered during templating
#:set SPARSE_KINDS = ["COO", "CSR", "CSC", "ELL"]

Expand Down Expand Up @@ -463,4 +487,21 @@ ${indent}$do ${varname}$${n+1+dim_offset-i}$ = lbound(${matname}$, ${n+1+dim_off
#:endcall
#:enddef

#!
#! Encapsulate code into CPP pre-processing directives #ifdef and #endif
#!
#! Args:
#! code (str): Code to be encapsulated
#! cpp_var (str): CPP variable
#!
#:def generate_cpp(code, cpp_var)
#:if cpp_var != ""
#ifdef ${cpp_var}$
#:endif
$:code
#:if cpp_var != ""
#endif
#:endif
#:enddef generate_cpp

#:endmute
6 changes: 6 additions & 0 deletions include/macros.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

!Default: compile the bitset module
#ifdef STDLIB_NO_BITSET
#else
#define STDLIB_BITSET
#endif
23 changes: 13 additions & 10 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
if (NOT STDLIB_NO_BITSET)
add_subdirectory(bitsets)
endif()
add_subdirectory(blas)
add_subdirectory(lapack)

set(fppFiles
stdlib_ascii.fypp
stdlib_bitsets.fypp
stdlib_bitsets_64.fypp
stdlib_bitsets_large.fypp
stdlib_codata_type.fypp
stdlib_constants.fypp
stdlib_error.fypp
Expand Down Expand Up @@ -49,10 +49,6 @@ set(fppFiles
stdlib_linalg_matrix_functions.fypp
stdlib_optval.fypp
stdlib_selection.fypp
stdlib_sorting.fypp
stdlib_sorting_ord_sort.fypp
stdlib_sorting_sort.fypp
stdlib_sorting_sort_adjoint.fypp
stdlib_sparse_constants.fypp
stdlib_sparse_conversion.fypp
stdlib_sparse_kinds.fypp
Expand All @@ -79,7 +75,6 @@ set(fppFiles
stdlib_quadrature_trapz.fypp
stdlib_quadrature_simps.fypp
stdlib_random.fypp
stdlib_math.fypp
stdlib_math_linspace.fypp
stdlib_math_logspace.fypp
stdlib_math_arange.fypp
Expand All @@ -94,7 +89,13 @@ set(fppFiles
stdlib_strings.fypp
stdlib_version.fypp
)
set(cppFiles stdlib_linalg_constants.fypp)
set(cppFiles stdlib_linalg_constants.fypp
stdlib_math.fypp
stdlib_sorting.fypp
stdlib_sorting_ord_sort.fypp
stdlib_sorting_sort.fypp
stdlib_sorting_sort_adjoint.fypp
)
set(f90Files
stdlib_ansi.f90
stdlib_ansi_operator.f90
Expand All @@ -121,4 +122,6 @@ set(f90Files

configure_stdlib_target(${PROJECT_NAME} f90Files fppFiles cppFiles)

target_link_libraries(${PROJECT_NAME} PUBLIC blas lapack)
target_link_libraries(${PROJECT_NAME} PUBLIC
$<$<NOT:$<BOOL:${STDLIB_NO_BITSET}>>:bitsets>
blas lapack)
9 changes: 9 additions & 0 deletions src/bitsets/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set(bitsets_fppFiles
../stdlib_kinds.fypp
../stdlib_optval.fypp
stdlib_bitsets.fypp
stdlib_bitsets_64.fypp
stdlib_bitsets_large.fypp
)

configure_stdlib_target(bitsets "" bitsets_fppFiles "")
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 9 additions & 3 deletions src/stdlib_math.fypp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include "macros.inc"
#:include "common.fypp"
#:set IR_KINDS_TYPES = INT_KINDS_TYPES + REAL_KINDS_TYPES
#:set RC_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES
#:set BITSET_KINDS_TYPES = list(zip(BITSET_KINDS, BITSET_TYPES))
module stdlib_math
use stdlib_kinds, only: int8, int16, int32, int64, sp, dp, xdp, qp
use stdlib_optval, only: optval
#ifdef STDLIB_BITSET
use stdlib_bitsets, only: bitset_64, bitset_large
#endif

implicit none
private
Expand Down Expand Up @@ -48,8 +50,10 @@ module stdlib_math
!>
!> Version: experimental
interface swap
#:for k1, t1 in INT_KINDS_TYPES + REAL_KINDS_TYPES + BITSET_KINDS_TYPES
#:for k1, t1, a1, cpp1 in INT_KINDS_TYPES + REAL_KINDS_TYPES + BITSET_KINDS_TYPES
#:block generate_cpp(cpp_var=cpp1)
module procedure :: swap_${k1}$
#:endblock
#:endfor
#:for k1, t1 in CMPLX_KINDS_TYPES
module procedure :: swap_c${k1}$
Expand Down Expand Up @@ -527,13 +531,15 @@ contains

#:endfor

#:for k1, t1 in INT_KINDS_TYPES + REAL_KINDS_TYPES + BITSET_KINDS_TYPES
#:for k1, t1, a1, cpp1 in INT_KINDS_TYPES + REAL_KINDS_TYPES + BITSET_KINDS_TYPES
#:block generate_cpp(cpp_var=cpp1)
elemental subroutine swap_${k1}$(lhs, rhs)
${t1}$, intent(inout) :: lhs, rhs
${t1}$ :: temp
temp = lhs; lhs = rhs; rhs = temp
end subroutine

#:endblock
#:endfor

#:for k1, t1 in CMPLX_KINDS_TYPES
Expand Down
Loading
Loading