Skip to content

Commit e7f4fa4

Browse files
committed
fix(math): preserve non-differenced dimension shape in diff for 2D arrays
When diff is applied to a 2D array and the number of differences (n) exceeds the size of the operated dimension, the function previously returned allocate(y(0, 0)), incorrectly collapsing both dimensions. This fix preserves the size of the non-differenced dimension: - dim=1: allocate(y(0, size(x, 2))) - dim=2: allocate(y(size(x, 1), 0))
1 parent ee33055 commit e7f4fa4

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/math/stdlib_math_diff.fypp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ contains
9191
size_work = size_x + size_prepend + size_append
9292

9393
if (size_work <= n_) then
94-
allocate(y(0, 0))
94+
if (dim_ == 1) then
95+
allocate(y(0, size(x, 2)))
96+
else
97+
allocate(y(size(x, 1), 0))
98+
end if
9599
return
96100
end if
97101

0 commit comments

Comments
 (0)