Skip to content

Commit 5648b0c

Browse files
committed
Merge branch 'master' of https://github.com/fortran-lang/stdlib into fix-diff2-bounds-check
2 parents f054da6 + ac98d3b commit 5648b0c

4 files changed

Lines changed: 41 additions & 12 deletions

File tree

CMakeLists.txt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ cmake_minimum_required(VERSION 3.14.0)
44
set(CMAKE_USER_MAKE_RULES_OVERRIDE ${CMAKE_CURRENT_SOURCE_DIR}/config/DefaultFlags.cmake)
55

66
project(fortran_stdlib
7-
LANGUAGES Fortran C
8-
DESCRIPTION "Community driven and agreed upon de facto standard library for Fortran"
7+
LANGUAGES Fortran C
8+
DESCRIPTION "Community driven and agreed upon de facto standard library for Fortran"
99
)
1010

1111
# Read version from file
@@ -116,8 +116,19 @@ endif()
116116

117117
# --- find preprocessor
118118
find_program(FYPP fypp)
119-
if(NOT FYPP)
120-
message(FATAL_ERROR "Preprocessor fypp not found! Please install fypp following the instructions in https://fypp.readthedocs.io/en/stable/fypp.html#installing")
119+
if(NOT FYPP OR "${FYPP}" MATCHES "NOTFOUND")
120+
message(FATAL_ERROR
121+
"\n [stdlib Build Error]: Preprocessor 'fypp' not found!\n"
122+
" ------------------------------------------------------------------------\n"
123+
" The fypp preprocessor is required to generate Fortran source from templates.\n\n"
124+
" Please install fypp following the instructions at https://github.com/aradi/fypp\n\n"
125+
" To diagnose your installation, please run the following in your terminal:\n"
126+
" Windows: 'where fypp' and 'where python'\n"
127+
" Linux/macOS: 'which fypp' and 'which python'\n\n"
128+
" Ensure the executable is in your PATH or set it manually during configuration:\n"
129+
" cmake -B build -DFYPP_EXECUTABLE=/path/to/fypp\n"
130+
" ------------------------------------------------------------------------\n"
131+
)
121132
endif()
122133

123134
# Custom preprocessor flags
@@ -156,4 +167,4 @@ install(EXPORT ${PROJECT_NAME}-targets
156167
)
157168

158169
# Export a pkg-config file
159-
include(${PROJECT_SOURCE_DIR}/config/export_pc.cmake)
170+
include(${PROJECT_SOURCE_DIR}/config/export_pc.cmake)

cmake/stdlib.cmake

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
#
1111
function(preprocess preproc preprocopts srcext trgext srcfiles trgfiles)
1212

13+
# Defensive check: Ensure the preprocessor path is valid before defining custom commands.
14+
# This prevents "empty command" errors during the build phase.
15+
if(NOT preproc OR "${preproc}" MATCHES "NOTFOUND")
16+
message(FATAL_ERROR "preprocess function called with invalid preprocessor path: '${preproc}'")
17+
endif()
18+
1319
set(_trgfiles)
1420
foreach(srcfile IN LISTS srcfiles)
1521
get_filename_component(filename ${srcfile} NAME)
@@ -87,8 +93,8 @@ function(configure_stdlib_target target_name regular_sources_var fypp_files_var
8793
endif()
8894

8995
set(LIB_MOD_DIR ${CMAKE_CURRENT_BINARY_DIR}/mod_files/${target_name}/)
90-
#set(INSTALL_MOD_DIR "${CMAKE_INSTALL_MODULEDIR}/${target_name}")
9196
set(INSTALL_MOD_DIR "${CMAKE_INSTALL_MODULEDIR}")
97+
9298
# We need the module directory before we finish the configure stage since the
9399
# build interface might resolve before the module directory is generated by CMake
94100
if(NOT EXISTS "${LIB_MOD_DIR}")
@@ -115,7 +121,7 @@ endfunction()
115121
# Determine if a module will be compiled
116122
#
117123
# Defines a CMake function that creates an ON/OFF option for a given stdlib module,
118-
#sets a compile definition accordingly, and prints its enabled/disabled status.
124+
# sets a compile definition accordingly, and prints its enabled/disabled status.
119125
#
120126
# Args:
121127
# module [in]: Name of the module to be compiled
@@ -133,4 +139,4 @@ function(check_modular module)
133139
add_compile_definitions(STDLIB_${umodule}=0)
134140
endif()
135141

136-
endfunction()
142+
endfunction()

doc/specs/stdlib_sparse.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,16 @@ If the `diagonal` array has not been previously allocated, the `diag` subroutine
296296

297297
### Syntax
298298

299-
`call ` [[stdlib_sparse_conversion(module):coo2csr(interface)]] `(coo,csr)`
299+
`call ` [[stdlib_sparse_conversion(module):coo2csr(interface)]] `(coo,csr[,sort_data])`
300300

301301
### Arguments
302302

303303
`coo` : Shall be a `COO` type of `real` or `complex` type. It is an `intent(in)` argument.
304304

305305
`csr` : Shall be a `CSR` type of `real` or `complex` type. It is an `intent(out)` argument.
306306

307+
`sort_data`, `optional` : Shall be a `logical` argument to determine whether data in the COO graph should be sorted before obtaining the CSR representation. The transformation from COO to CSR depends on the former being sorted in row-major order and not having duplicate pairs. Using this boolean will call a sorting routine at the cost of extra runtime, default `.false.`. It is an `intent(in)` argument.
308+
307309
### Syntax
308310

309311
`call ` [[stdlib_sparse_conversion(module):coo2csc(interface)]] `(coo,csc)`

src/sparse/stdlib_sparse_conversion.fypp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
!!
77
! This code was modified from https://github.com/jalvesz/FSPARSE by its author: Alves Jose
88
module stdlib_sparse_conversion
9+
use stdlib_optval, only: optval
910
use stdlib_sorting, only: sort
1011
use stdlib_sparse_constants
1112
use stdlib_sparse_kinds
@@ -215,11 +216,20 @@ contains
215216
#:endfor
216217

217218
#:for k1, t1, s1 in (KINDS_TYPES)
218-
subroutine coo2csr_${s1}$(COO,CSR)
219-
type(COO_${s1}$_type), intent(in) :: COO
220-
type(CSR_${s1}$_type), intent(out) :: CSR
219+
subroutine coo2csr_${s1}$(COO, CSR, sort_data)
220+
type(COO_${s1}$_type), intent(inout) :: COO
221+
type(CSR_${s1}$_type), intent(out) :: CSR
222+
logical, intent(in), optional :: sort_data
223+
logical :: sort_data_
221224
integer(ilp) :: i
222225

226+
sort_data_ = optval(x=sort_data, default=.false.)
227+
228+
if(sort_data_) then
229+
call sort_coo_unique_${s1}$( COO%index, COO%data, COO%nnz, COO%nrows, COO%ncols )
230+
COO%is_sorted = .true.
231+
end if
232+
223233
CSR%nnz = COO%nnz; CSR%nrows = COO%nrows; CSR%ncols = COO%ncols
224234
CSR%storage = COO%storage
225235

0 commit comments

Comments
 (0)