Skip to content

Commit

Permalink
Merge pull request #27 from nakib/issue26-bugfix
Browse files Browse the repository at this point in the history
Allowed subscripting the last index of array.
  • Loading branch information
milancurcic authored Dec 7, 2022
2 parents 81df769 + 73559b9 commit a2cd6ea
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions fpm.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "functional"
version = "0.6.1"
version = "0.6.2"
license = "BSD-3-Clause"
author = "Milan Curcic"
maintainer = "[email protected]"
copyright = "Copyright (c) 2016-2020, functional-fortran contributors"
copyright = "Copyright (c) 2016-2022, functional-fortran contributors"
20 changes: 10 additions & 10 deletions src/functional.f90
Original file line number Diff line number Diff line change
Expand Up @@ -3629,7 +3629,7 @@ pure function subscript_i1(x, ind) result(subscript)
integer(i1), dimension(:), allocatable :: subscript
integer(i1), dimension(:), allocatable :: indices
integer :: i
indices = pack(ind, ind > 0 .and. ind < size(x))
indices = pack(ind, ind > 0 .and. ind <= size(x))
allocate(subscript(size(indices)))
do concurrent(i = 1:size(indices))
subscript(i) = x(indices(i))
Expand All @@ -3646,7 +3646,7 @@ pure function subscript_i2(x, ind) result(subscript)
integer(i2), dimension(:), allocatable :: subscript
integer(i2), dimension(:), allocatable :: indices
integer :: i
indices = pack(ind, ind > 0 .and. ind < size(x))
indices = pack(ind, ind > 0 .and. ind <= size(x))
allocate(subscript(size(indices)))
do concurrent(i = 1:size(indices))
subscript(i) = x(indices(i))
Expand All @@ -3663,7 +3663,7 @@ pure function subscript_i4(x, ind) result(subscript)
integer(i4), dimension(:), allocatable :: subscript
integer(i4), dimension(:), allocatable :: indices
integer :: i
indices = pack(ind, ind > 0 .and. ind < size(x))
indices = pack(ind, ind > 0 .and. ind <= size(x))
allocate(subscript(size(indices)))
do concurrent(i = 1:size(indices))
subscript(i) = x(indices(i))
Expand All @@ -3680,7 +3680,7 @@ pure function subscript_i8(x, ind) result(subscript)
integer(i8), dimension(:), allocatable :: subscript
integer(i8), dimension(:), allocatable :: indices
integer :: i
indices = pack(ind, ind > 0 .and. ind < size(x))
indices = pack(ind, ind > 0 .and. ind <= size(x))
allocate(subscript(size(indices)))
do concurrent(i = 1:size(indices))
subscript(i) = x(indices(i))
Expand All @@ -3697,7 +3697,7 @@ pure function subscript_r4(x, ind) result(subscript)
real(r4), dimension(:), allocatable :: subscript
integer(i4), dimension(:), allocatable :: indices
integer :: i
indices = pack(ind, ind > 0 .and. ind < size(x))
indices = pack(ind, ind > 0 .and. ind <= size(x))
allocate(subscript(size(indices)))
do concurrent(i = 1:size(indices))
subscript(i) = x(indices(i))
Expand All @@ -3714,7 +3714,7 @@ pure function subscript_r8(x, ind) result(subscript)
real(r8), dimension(:), allocatable :: subscript
integer(i4), dimension(:), allocatable :: indices
integer :: i
indices = pack(ind, ind > 0 .and. ind < size(x))
indices = pack(ind, ind > 0 .and. ind <= size(x))
allocate(subscript(size(indices)))
do concurrent(i = 1:size(indices))
subscript(i) = x(indices(i))
Expand All @@ -3731,7 +3731,7 @@ pure function subscript_r16(x, ind) result(subscript)
real(r16), dimension(:), allocatable :: subscript
integer(i4), dimension(:), allocatable :: indices
integer :: i
indices = pack(ind, ind > 0 .and. ind < size(x))
indices = pack(ind, ind > 0 .and. ind <= size(x))
allocate(subscript(size(indices)))
do concurrent(i = 1:size(indices))
subscript(i) = x(indices(i))
Expand All @@ -3748,7 +3748,7 @@ pure function subscript_c4(x, ind) result(subscript)
complex(r4), dimension(:), allocatable :: subscript
integer(i4), dimension(:), allocatable :: indices
integer :: i
indices = pack(ind, ind > 0 .and. ind < size(x))
indices = pack(ind, ind > 0 .and. ind <= size(x))
allocate(subscript(size(indices)))
do concurrent(i = 1:size(indices))
subscript(i) = x(indices(i))
Expand All @@ -3765,7 +3765,7 @@ pure function subscript_c8(x, ind) result(subscript)
complex(r8), dimension(:), allocatable :: subscript
integer(i4), dimension(:), allocatable :: indices
integer :: i
indices = pack(ind, ind > 0 .and. ind < size(x))
indices = pack(ind, ind > 0 .and. ind <= size(x))
allocate(subscript(size(indices)))
do concurrent(i = 1:size(indices))
subscript(i) = x(indices(i))
Expand All @@ -3782,7 +3782,7 @@ pure function subscript_c16(x, ind) result(subscript)
complex(r16), dimension(:), allocatable :: subscript
integer(i4), dimension(:), allocatable :: indices
integer :: i
indices = pack(ind, ind > 0 .and. ind < size(x))
indices = pack(ind, ind > 0 .and. ind <= size(x))
allocate(subscript(size(indices)))
do concurrent(i = 1:size(indices))
subscript(i) = x(indices(i))
Expand Down
6 changes: 5 additions & 1 deletion test/test_subscript.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ program test_subscript
integer :: n, ntests

n = 1
ntests = 11
ntests = 12
call initialize_tests(tests, ntests)

tests(n) = assert(all(subscript([1_int8, 2_int8, 3_int8], [2_int8]) == [2_int8]), &
Expand Down Expand Up @@ -45,6 +45,10 @@ program test_subscript
'subscript out of bounds returns empty array')
n = n + 1

tests(n) = assert(all(subscript([1, 2, 3], [3]) == [3]), &
'subscript of last element')
n = n + 1

tests(n) = assert(all(subscript(arange(cmplx(1._real32, 0._real32), &
cmplx(3._real32, 0._real32)), [2])&
== [cmplx(2._real32, 0._real32)]), &
Expand Down

0 comments on commit a2cd6ea

Please sign in to comment.