Skip to content

Commit da1253d

Browse files
committed
add sorting example
1 parent 47afe34 commit da1253d

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

FortranCon2021-stdlib/examples/Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ FC = gfortran
22
STDLIB_CFLAGS = $(shell pkg-config --cflags fortran_stdlib)
33
STDLIB_LIBS = $(shell pkg-config --libs fortran_stdlib)
44

5-
all: ex_bitsets ex_logger
5+
all: ex_bitsets ex_logger ex_sorting
66

77
ex_bitsets: ex_bitsets.f90
88
$(FC) $(STDLIB_CFLAGS) $^ -o $@ $(STDLIB_LIBS)
99

1010
ex_logger: ex_logger.f90
1111
$(FC) $(STDLIB_CFLAGS) $^ -o $@ $(STDLIB_LIBS)
1212

13+
ex_sorting: ex_sorting.f90
14+
$(FC) $(STDLIB_CFLAGS) $^ -o $@ $(STDLIB_LIBS)
15+
1316
clean:
1417
$(RM) ex_bitsets
1518
$(RM) ex_logger
19+
$(RM) ex_sorting
1620

FortranCon2021-stdlib/stdlib-talk.pdf

1023 Bytes
Binary file not shown.

FortranCon2021-stdlib/stdlib-talk.tex

+32
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,38 @@
184184
\end{frame}
185185

186186

187+
\begin{frame}[fragile]
188+
\frametitle{Demo: stdlib\_sorting}
189+
\begin{block}{ex\_sorting.f90}
190+
\small
191+
\begin{verbatim}
192+
use stdlib_sorting, only: sort_index
193+
use stdlib_kinds, only: int64
194+
implicit none
195+
196+
integer :: digits(6) = [3,1,4,1,5,9]
197+
character :: chars(6) = ['a','b','c','d','e','f']
198+
integer(int64) :: index(6)
199+
call sort_index(digits, index)
200+
print '(6i1)', digits ! 113459
201+
print '(6i1)', index ! 241356
202+
print '(6a1)', chars(index) ! bdacef
203+
end
204+
\end{verbatim}
205+
\end{block}
206+
207+
\note{
208+
And finally, we'll have a brief look at the new sorting module.
209+
Currently, there are three sorting subroutines.
210+
Two, called ``sort'' and ``ord_sort'' are for basic in-place sorting, with different tradeoffs.
211+
The third, ``sort_index'', is what some other languages call ``argsort''.
212+
In addition to performing a sort, it returns an array of the indices that put the original array in sorted order.
213+
You can then use this as a vector subscript to permute other arrays in the same way.
214+
All three sorting sorting routines can also sort in descending order and can take a user-supplied workspace array to allocating internal workspace.
215+
}
216+
\end{frame}
217+
218+
187219
\begin{frame}
188220
\frametitle{New contributors have been key to stdlib's growth}
189221

0 commit comments

Comments
 (0)