Skip to content

Commit 39b97bb

Browse files
committed
refactor(math): use explicit select case for diff shape allocation
Improved the boundary condition handling in diff_2 functions by using an explicit select case for dimensions. This ensures that: 1. Shape preservation logic is clear. 2. Invalid dimension values (dim_ != 1 or 2) trigger a descriptive error stop.
1 parent e7f4fa4 commit 39b97bb

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/math/stdlib_math_diff.fypp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,14 @@ contains
9191
size_work = size_x + size_prepend + size_append
9292

9393
if (size_work <= n_) then
94-
if (dim_ == 1) then
94+
select case (dim_)
95+
case (1)
9596
allocate(y(0, size(x, 2)))
96-
else
97+
case (2)
9798
allocate(y(size(x, 1), 0))
98-
end if
99+
case default
100+
error stop "diff_2: invalid dimension (dim_ must be 1 or 2)"
101+
end select
99102
return
100103
end if
101104

0 commit comments

Comments
 (0)