Skip to content

Commit 99afeeb

Browse files
committed
fix(math): add cross-dimension shape validation for diff prepend/append
1 parent ee33055 commit 99afeeb

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/math/stdlib_math_diff.fypp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,20 @@ contains
8585
dim_ = 1
8686
end if
8787

88-
if (present(prepend)) size_prepend = size(prepend, dim_)
89-
if (present(append)) size_append = size(append, dim_)
88+
if (present(prepend)) then
89+
if (size(prepend, 3 - dim_) /= size(x, 3 - dim_)) then
90+
error stop "stdlib_math_diff: non-differencing dimension of 'prepend' must match 'x'"
91+
end if
92+
size_prepend = size(prepend, dim_)
93+
end if
94+
95+
if (present(append)) then
96+
if (size(append, 3 - dim_) /= size(x, 3 - dim_)) then
97+
error stop "stdlib_math_diff: non-differencing dimension of 'append' must match 'x'"
98+
end if
99+
size_append = size(append, dim_)
100+
end if
101+
90102
size_x = size(x, dim_)
91103
size_work = size_x + size_prepend + size_append
92104

0 commit comments

Comments
 (0)