Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f0629ae

Browse files
authored
Merge branch 'master' into hash_functions2
2 parents 28f2d6f + 30f5321 commit f0629ae

File tree

11 files changed

+550
-0
lines changed

11 files changed

+550
-0
lines changed

‎CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ Features available from the latest git source
1414
`new_pengy_hash_seed`, `new_spooky_hash_seed`,
1515
`odd_random_integer`, `pengy_hash`, `spooky_hash`, `spookyhash_128`, and
1616
`universal_mult_hash`
17+
- new module `stdlib_array`
18+
[#603](https://github.com/fortran-lang/stdlib/pull/603)
19+
- new procedures `trueloc`, `falseloc`
1720
- new module `stdlib_distribution_uniform`
1821
[#272](https://github.com/fortran-lang/stdlib/pull/272)
1922
- new module `stdlib_selection`

‎doc/specs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This is and index/directory of the specifications (specs) for each new module/fe
1111

1212
## Experimental Features & Modules
1313

14+
- [array](./stdlib_array.html) - Procedures for index manipulation and array handling
1415
- [ascii](./stdlib_ascii.html) - Procedures for handling ASCII characters
1516
- [bitsets](./stdlib_bitsets.html) - Bitset data types and procedures
1617
- [error](./stdlib_error.html) - Catching and handling errors

‎doc/specs/stdlib_array.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
---
2+
title: array
3+
---
4+
5+
# The `stdlib_array` module
6+
7+
[TOC]
8+
9+
## Introduction
10+
11+
Module for index manipulation and array handling tasks.
12+
13+
## Procedures and methods provided
14+
15+
16+
### `trueloc`
17+
18+
#### Status
19+
20+
Experimental
21+
22+
#### Description
23+
24+
Turn a logical mask into an index array by selecting all true values.
25+
Provides similar functionality like the built-in `where` or the intrinsic procedures `merge` and `pack` when working with logical mask.
26+
The built-in / intrinsics are usually preferable to `trueloc`, unless the access to the index array is required.
27+
28+
#### Syntax
29+
30+
`loc = [[trueloc(function)]] (array[, lbound])`
31+
32+
#### Class
33+
34+
Pure function.
35+
36+
#### Arguments
37+
38+
`array`: List of default logical arrays. This argument is `intent(in)`.
39+
40+
`lbound`: Lower bound of the array to index. This argument is `optional` and `intent(in)`.
41+
42+
#### Return value
43+
44+
Returns an array of default integer size, with a maximum length of `size(array)` elements.
45+
46+
#### Examples
47+
48+
```fortran
49+
program demo_trueloc
50+
use stdlib_array, only : trueloc
51+
implicit none
52+
real, allocatable :: array(:)
53+
allocate(array(500))
54+
call random_number(array)
55+
array(trueloc(array > 0.5)) = 0.0
56+
end program demo_trueloc
57+
```
58+
59+
60+
### `falseloc`
61+
62+
#### Status
63+
64+
Experimental
65+
66+
#### Description
67+
68+
Turn a logical mask into an index array by selecting all false values.
69+
Provides similar functionality like the built-in `where` or the intrinsic procedures `merge` and `pack` when working with logical mask.
70+
The built-in / intrinsics are usually preferable to `falseloc`, unless the access to the index array is required.
71+
72+
#### Syntax
73+
74+
`loc = [[falseloc(function)]] (array[, lbound])`
75+
76+
#### Class
77+
78+
Pure function.
79+
80+
#### Arguments
81+
82+
`array`: List of default logical arrays. This argument is `intent(in)`.
83+
84+
`lbound`: Lower bound of the array to index. This argument is `optional` and `intent(in)`.
85+
86+
#### Return value
87+
88+
Returns an array of default integer size, with a maximum length of `size(array)` elements.
89+
90+
#### Examples
91+
92+
```fortran
93+
program demo_falseloc
94+
use stdlib_array, only : falseloc
95+
implicit none
96+
real, allocatable :: array(:)
97+
allocate(array(-200:200))
98+
call random_number(array)
99+
array(falseloc(array < 0.5), lbound(array)) = 0.0
100+
end program demo_falseloc
101+
```

‎src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ list(
7979
fypp_f90("${fyppFlags}" "${fppFiles}" outFiles)
8080

8181
set(SRC
82+
stdlib_array.f90
8283
stdlib_error.f90
8384
stdlib_logger.f90
8485
stdlib_system.F90

‎src/Makefile.manual

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ SRCFYPP = \
5454
stdlib_version.fypp
5555

5656
SRC = f18estop.f90 \
57+
stdlib_array.f90 \
5758
stdlib_error.f90 \
5859
stdlib_specialfunctions.f90 \
5960
stdlib_specialfunctions_legendre.f90 \

‎src/stdlib_array.f90

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
! SPDX-Identifier: MIT
2+
3+
!> Module for index manipulation and general array handling
4+
!>
5+
!> The specification of this module is available [here](../page/specs/stdlib_array.html).
6+
module stdlib_array
7+
implicit none
8+
private
9+
10+
public :: trueloc, falseloc
11+
12+
contains
13+
14+
!> Version: experimental
15+
!>
16+
!> Return the positions of the true elements in array.
17+
!> [Specification](../page/specs/stdlib_array.html#trueloc)
18+
pure function trueloc(array, lbound) result(loc)
19+
!> Mask of logicals
20+
logical, intent(in) :: array(:)
21+
!> Lower bound of array to index
22+
integer, intent(in), optional :: lbound
23+
!> Locations of true elements
24+
integer :: loc(count(array))
25+
26+
call logicalloc(loc, array, .true., lbound)
27+
end function trueloc
28+
29+
!> Version: experimental
30+
!>
31+
!> Return the positions of the false elements in array.
32+
!> [Specification](../page/specs/stdlib_array.html#falseloc)
33+
pure function falseloc(array, lbound) result(loc)
34+
!> Mask of logicals
35+
logical, intent(in) :: array(:)
36+
!> Lower bound of array to index
37+
integer, intent(in), optional :: lbound
38+
!> Locations of false elements
39+
integer :: loc(count(.not.array))
40+
41+
call logicalloc(loc, array, .false., lbound)
42+
end function falseloc
43+
44+
!> Return the positions of the truthy elements in array
45+
pure subroutine logicalloc(loc, array, truth, lbound)
46+
!> Locations of truthy elements
47+
integer, intent(out) :: loc(:)
48+
!> Mask of logicals
49+
logical, intent(in) :: array(:)
50+
!> Truthy value
51+
logical, intent(in) :: truth
52+
!> Lower bound of array to index
53+
integer, intent(in), optional :: lbound
54+
integer :: i, pos, offset
55+
56+
offset = 0
57+
if (present(lbound)) offset = lbound - 1
58+
59+
i = 0
60+
do pos = 1, size(array)
61+
if (array(pos).eqv.truth) then
62+
i = i + 1
63+
loc(i) = pos + offset
64+
end if
65+
end do
66+
end subroutine logicalloc
67+
68+
end module stdlib_array

‎src/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ list(
1515
"-I${PROJECT_SOURCE_DIR}/src"
1616
)
1717

18+
add_subdirectory(array)
1819
add_subdirectory(ascii)
1920
add_subdirectory(bitsets)
2021
add_subdirectory(hash_functions)

‎src/tests/Makefile.manual

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ testdrive.F90:
1212
$(FETCH) https://github.com/fortran-lang/test-drive/raw/v0.4.0/src/testdrive.F90 > $@
1313

1414
all test clean::
15+
$(MAKE) -f Makefile.manual --directory=array $@
1516
$(MAKE) -f Makefile.manual --directory=ascii $@
1617
$(MAKE) -f Makefile.manual --directory=bitsets $@
1718
$(MAKE) -f Makefile.manual --directory=hash_functions_perf $@

‎src/tests/array/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ADDTEST(logicalloc)

‎src/tests/array/Makefile.manual

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
PROGS_SRC = test_logicalloc.f90
2+
3+
4+
include ../Makefile.manual.test.mk

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /