Skip to content

Commit c1a85c4

Browse files
authored
Merge branch 'fortran-lang:master' into sparse
2 parents 0f2ee3b + 95f0c59 commit c1a85c4

File tree

13 files changed

+368
-9
lines changed

13 files changed

+368
-9
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ jobs:
169169
cxx: [icpc]
170170
env:
171171
MACOS_HPCKIT_URL: >-
172-
https://registrationcenter-download.intel.com/akdlm/irc_nas/18242/m_HPCKit_p_2021.4.0.3389_offline.dmg
172+
https://registrationcenter-download.intel.com/akdlm/IRC_NAS/a99cb1c5-5af6-4824-9811-ae172d24e594/m_HPCKit_p_2023.1.0.44543.dmg
173173
MACOS_FORTRAN_COMPONENTS: all
174174
FC: ${{ matrix.fc }}
175175
CC: ${{ matrix.cc }}

CHANGELOG.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,65 @@
1+
# Version 0.4.0
2+
3+
Full release notes available at [v0.4.0] tag.
4+
5+
[v0.4.0]: https://github.com/fortran-lang/stdlib/releases/tag/v0.4.0
6+
7+
- new module `stdlib_str2num`
8+
[#743](https://github.com/fortran-lang/stdlib/pull/743)
9+
- new procedures: `to_num`, `to_num_from_stream`
10+
11+
Changes to existing scripts and modules
12+
13+
- change in .gitignore
14+
- addition of the file extensions `.dat` and `.stream`
15+
[#768](https://github.com/fortran-lang/stdlib/pull/768)
16+
- addition of `.gitignore` to `stdlib-fpm`
17+
[#769](https://github.com/fortran-lang/stdlib/pull/769)
18+
- change in CI/CD
19+
- support of GCC 13
20+
[#737](https://github.com/fortran-lang/stdlib/pull/737)
21+
- support of Intel compiler `ifx`
22+
[#752](https://github.com/fortran-lang/stdlib/pull/752)
23+
- change in script `fpm-deployment.sh`
24+
- changes to facilitate `fypp` preprocessing for the `fpm` deployment
25+
[#758](https://github.com/fortran-lang/stdlib/pull/758)
26+
- change in module `stdlib_ascii`
27+
- Improved procedures `to_lower` and `to_upper`
28+
[#733](https://github.com/fortran-lang/stdlib/pull/733)
29+
- change in module `stdlib_bitsets`
30+
- initialization in `bitset_type`
31+
[#753](https://github.com/fortran-lang/stdlib/pull/753)
32+
- improved procedure `bit_count_large`
33+
[#756](https://github.com/fortran-lang/stdlib/pull/756)
34+
- change in module `stdlib_hashmaps`
35+
- new procedure `get_all_keys`
36+
[#741](https://github.com/fortran-lang/stdlib/pull/741)
37+
- new file permissions
38+
[#762](https://github.com/fortran-lang/stdlib/pull/762)
39+
- change in module `stdlib_math`
40+
- new procedure `meshgrid`
41+
[#764](https://github.com/fortran-lang/stdlib/pull/764)
42+
- change in module `stdlib_specialfunctions_gamma`
43+
- fix procedure `gamma`
44+
[#730](https://github.com/fortran-lang/stdlib/pull/730)
45+
- change in module `stdlib_string_type`
46+
- fix procedure `move`
47+
[#736](https://github.com/fortran-lang/stdlib/pull/736)
48+
[#773](https://github.com/fortran-lang/stdlib/pull/773)
49+
- change in `SpookyV2Test.cpp`
50+
- Fix undefined use of <cstdint> types
51+
[#747](https://github.com/fortran-lang/stdlib/pull/747)
52+
53+
Changes to the existing documentation
54+
55+
- change in the specs `stdlib_hashmaps`
56+
- Correction of an intent of the variable "conflict"
57+
[#739](https://github.com/fortran-lang/stdlib/pull/739)
58+
- change in README.md
59+
- instructions to build `stdlib` with `fpm` through the `fpm-deployment.sh` script
60+
[#757](https://github.com/fortran-lang/stdlib/pull/757)
61+
62+
163
# Version 0.3.0
264

365
Full release notes available at [v0.3.0] tag.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ GCC Fortran | 10, 11, 12, 13 | macOS 12.6.3 (21G419) | x86_64
9292
GCC Fortran (MSYS) | 13 | Windows Server 2022 (10.0.20348 Build 1547) | x86_64
9393
GCC Fortran (MinGW) | 13 | Windows Server 2022 (10.0.20348 Build 1547) | x86_64, i686
9494
Intel oneAPI LLVM | 2024.0 | Ubuntu 22.04.2 LTS | x86_64
95-
Intel oneAPI classic | 2021.1 | macOS 12.6.3 (21G419) | x86_64
95+
Intel oneAPI classic | 2023.1 | macOS 12.6.3 (21G419) | x86_64
9696

9797
The following combinations are known to work, but they are not tested in the CI:
9898

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.0
1+
0.4.0

doc/specs/stdlib_math.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,3 +554,59 @@ When both `prepend` and `append` are not present, the result `y` has one fewer e
554554
```fortran
555555
{!example/math/example_diff.f90!}
556556
```
557+
558+
### `meshgrid` subroutine
559+
560+
#### Description
561+
562+
Computes a list of coordinate matrices from coordinate vectors.
563+
564+
For $n \geq 1$ coordinate vectors $(x_1, x_2, ..., x_n)$ of sizes $(s_1, s_2, ..., s_n)$, `meshgrid` computes $n$ coordinate matrices $(X_1, X_2, ..., X_n)$ with identical shape corresponding to the selected indexing:
565+
- Cartesian indexing (default behavior): the shape of the coordinate matrices is $(s_2, s_1, s_3, s_4, ... s_n)$.
566+
- matrix indexing: the shape of the coordinate matrices is $(s_1, s_2, s_3, s_4, ... s_n)$.
567+
568+
#### Syntax
569+
570+
For a 2D problem in Cartesian indexing:
571+
`call [[stdlib_math(module):meshgrid(interface)]](x, y, xm, ym)`
572+
573+
For a 3D problem in Cartesian indexing:
574+
`call [[stdlib_math(module):meshgrid(interface)]](x, y, z, xm, ym, zm)`
575+
576+
For a 3D problem in matrix indexing:
577+
`call [[stdlib_math(module):meshgrid(interface)]](x, y, z, xm, ym, zm, indexing="ij")`
578+
579+
The subroutine can be called in `n`-dimensional situations, as long as `n` is inferior to the maximum allowed array rank.
580+
581+
#### Status
582+
583+
Experimental.
584+
585+
#### Class
586+
587+
Subroutine.
588+
589+
#### Arguments
590+
591+
For a `n`-dimensional problem, with `n >= 1`:
592+
593+
`x1, x2, ..., xn`: The coordinate vectors.
594+
Shall be `real/integer` and `rank-1` arrays.
595+
These arguments are `intent(in)`.
596+
597+
`xm1, xm2, ..., xmn`: The coordinate matrices.
598+
Shall be arrays of type `real` or `integer` of adequate shape:
599+
- for Cartesian indexing, the shape of the coordinate matrices must be `[size(x2), size(x1), size(x3), ..., size(xn)]`.
600+
- for matrix indexing, the shape of the coordinate matrices must be `[size(x1), size(x2), size(x3), ..., size(xn)]`.
601+
602+
These argument are `intent(out)`.
603+
604+
`indexing`: the selected indexing.
605+
Shall be an `integer` equal to `stdlib_meshgrid_xy` for Cartesian indexing (default), or `stdlib_meshgrid_ij` for matrix indexing. `stdlib_meshgrid_xy` and `stdlib_meshgrid_ij` are public constants defined in the module.
606+
This argument is `intent(in)` and `optional`, and is equal to `stdlib_meshgrid_xy` by default.
607+
608+
#### Example
609+
610+
```fortran
611+
{!example/math/example_meshgrid.f90!}
612+
```

example/math/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ ADD_EXAMPLE(math_argd)
1313
ADD_EXAMPLE(math_arg)
1414
ADD_EXAMPLE(math_argpi)
1515
ADD_EXAMPLE(math_is_close)
16+
ADD_EXAMPLE(meshgrid)

example/math/example_meshgrid.f90

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
program example_meshgrid
2+
3+
use stdlib_math, only: meshgrid, linspace, stdlib_meshgrid_ij
4+
use stdlib_kinds, only: sp
5+
6+
implicit none
7+
8+
integer, parameter :: nx = 3, ny = 2
9+
real(sp) :: x(nx), y(ny), &
10+
xm_cart(ny, nx), ym_cart(ny, nx), &
11+
xm_mat(nx, ny), ym_mat(nx, ny)
12+
13+
x = linspace(0_sp, 1_sp, nx)
14+
y = linspace(0_sp, 1_sp, ny)
15+
16+
call meshgrid(x, y, xm_cart, ym_cart)
17+
print *, "xm_cart = "
18+
call print_2d_array(xm_cart)
19+
print *, "ym_cart = "
20+
call print_2d_array(ym_cart)
21+
22+
call meshgrid(x, y, xm_mat, ym_mat, indexing=stdlib_meshgrid_ij)
23+
print *, "xm_mat = "
24+
call print_2d_array(xm_mat)
25+
print *, "ym_mat = "
26+
call print_2d_array(ym_mat)
27+
28+
contains
29+
subroutine print_2d_array(array)
30+
real(sp), intent(in) :: array(:, :)
31+
integer :: i
32+
33+
do i = 1, size(array, dim=1)
34+
print *, array(i, :)
35+
end do
36+
end subroutine
37+
end program example_meshgrid

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ set(fppFiles
5858
stdlib_math_is_close.fypp
5959
stdlib_math_all_close.fypp
6060
stdlib_math_diff.fypp
61+
stdlib_math_meshgrid.fypp
6162
stdlib_str2num.fypp
6263
stdlib_string_type.fypp
6364
stdlib_string_type_constructor.fypp

src/stdlib_math.fypp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ module stdlib_math
1414
public :: EULERS_NUMBER_QP
1515
#:endif
1616
public :: DEFAULT_LINSPACE_LENGTH, DEFAULT_LOGSPACE_BASE, DEFAULT_LOGSPACE_LENGTH
17-
public :: arange, arg, argd, argpi, is_close, all_close, diff
17+
public :: stdlib_meshgrid_ij, stdlib_meshgrid_xy
18+
public :: arange, arg, argd, argpi, is_close, all_close, diff, meshgrid
1819

1920
integer, parameter :: DEFAULT_LINSPACE_LENGTH = 100
2021
integer, parameter :: DEFAULT_LOGSPACE_LENGTH = 50
@@ -32,6 +33,9 @@ module stdlib_math
3233
real(kind=${k1}$), parameter :: PI_${k1}$ = acos(-1.0_${k1}$)
3334
#:endfor
3435

36+
!> Values for optional argument `indexing` of `meshgrid`
37+
integer, parameter :: stdlib_meshgrid_xy = 0, stdlib_meshgrid_ij = 1
38+
3539
interface clip
3640
#:for k1, t1 in IR_KINDS_TYPES
3741
module procedure clip_${k1}$
@@ -382,6 +386,30 @@ module stdlib_math
382386
#:endfor
383387
end interface diff
384388

389+
390+
!> Version: experimental
391+
!>
392+
!> Computes a list of coordinate matrices from coordinate vectors.
393+
!> ([Specification](../page/specs/stdlib_math.html#meshgrid))
394+
interface meshgrid
395+
#:set RANKS = range(1, MAXRANK + 1)
396+
#:for k1, t1 in IR_KINDS_TYPES
397+
#:for rank in RANKS
398+
#:set RName = rname("meshgrid", rank, t1, k1)
399+
module subroutine ${RName}$(&
400+
${"".join(f"x{i}, " for i in range(1, rank + 1))}$ &
401+
${"".join(f"xm{i}, " for i in range(1, rank + 1))}$ &
402+
indexing &
403+
)
404+
#:for i in range(1, rank + 1)
405+
${t1}$, intent(in) :: x${i}$(:)
406+
${t1}$, intent(out) :: xm${i}$ ${ranksuffix(rank)}$
407+
#:endfor
408+
integer, intent(in), optional :: indexing
409+
end subroutine ${RName}$
410+
#:endfor
411+
#:endfor
412+
end interface meshgrid
385413
contains
386414

387415
#:for k1, t1 in IR_KINDS_TYPES

src/stdlib_math_meshgrid.fypp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#:include "common.fypp"
2+
#:set IR_KINDS_TYPES = INT_KINDS_TYPES + REAL_KINDS_TYPES
3+
#:set RANKS = range(1, MAXRANK + 1)
4+
5+
#:def meshgrid_loop(indices)
6+
#:for j in reversed(indices)
7+
do i${j}$ = 1, size(x${j}$)
8+
#:endfor
9+
#:for j in indices
10+
xm${j}$(${"".join(f"i{j}," for j in indices).removesuffix(",")}$) = &
11+
x${j}$(i${j}$)
12+
#:endfor
13+
#:for j in indices
14+
end do
15+
#:endfor
16+
#:enddef
17+
18+
submodule(stdlib_math) stdlib_math_meshgrid
19+
20+
use stdlib_error, only: error_stop
21+
22+
contains
23+
24+
#:for k1, t1 in IR_KINDS_TYPES
25+
#:for rank in RANKS
26+
#:if rank == 1
27+
#:set XY_INDICES = [1]
28+
#:set IJ_INDICES = [1]
29+
#:else
30+
#:set XY_INDICES = [2, 1] + [j for j in range(3, rank + 1)]
31+
#:set IJ_INDICES = [1, 2] + [j for j in range(3, rank + 1)]
32+
#:endif
33+
#: set RName = rname("meshgrid", rank, t1, k1)
34+
module procedure ${RName}$
35+
36+
integer :: ${"".join(f"i{j}," for j in range(1, rank + 1)).removesuffix(",")}$
37+
38+
select case (optval(indexing, stdlib_meshgrid_xy))
39+
case (stdlib_meshgrid_xy)
40+
$:meshgrid_loop(XY_INDICES)
41+
case (stdlib_meshgrid_ij)
42+
$:meshgrid_loop(IJ_INDICES)
43+
case default
44+
call error_stop("ERROR (meshgrid): unexpected indexing.")
45+
end select
46+
end procedure
47+
#:endfor
48+
#:endfor
49+
50+
end submodule

0 commit comments

Comments
 (0)