Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions src/math/stdlib_math_diff.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,26 @@ contains

size_prepend = 0
size_append = 0

dim_ = 1
if (present(dim)) then
if (dim == 1 .or. dim == 2) then
dim_ = dim
else
dim_ = 1
if (dim == 1 .or. dim == 2) dim_ = dim
end if

if (present(prepend)) then
if (size(prepend, 3 - dim_) /= size(x, 3 - dim_)) then
error stop "stdlib_math_diff: non-differencing dimension of 'prepend' must match 'x'"
end if
size_prepend = size(prepend, dim_)
end if

if (present(append)) then
if (size(append, 3 - dim_) /= size(x, 3 - dim_)) then
error stop "stdlib_math_diff: non-differencing dimension of 'append' must match 'x'"
end if
else
dim_ = 1
size_append = size(append, dim_)
Comment thread
jvdp1 marked this conversation as resolved.
Comment thread
jalvesz marked this conversation as resolved.
end if

if (present(prepend)) size_prepend = size(prepend, dim_)
if (present(append)) size_append = size(append, dim_)
size_x = size(x, dim_)
size_work = size_x + size_prepend + size_append

Expand All @@ -96,8 +104,6 @@ contains
allocate(y(0, size(x, 2)))
case (2)
allocate(y(size(x, 1), 0))
case default
error stop "diff_2: internal error: invalid dimension (dim_ must be 1 or 2)"
end select
return
end if
Expand Down
4 changes: 3 additions & 1 deletion test/math/test_stdlib_math.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ contains
end subroutine test_all_close_cmplx_${k1}$
#:endfor

#:for k1, t1 in REAL_KINDS_TYPES
#:for k1, t1 in REAL_KINDS_TYPES
subroutine test_diff_real_${k1}$(error)
type(error_type), allocatable, intent(out) :: error
${t1}$ :: x(6) = [${t1}$ :: 0, 5, 15, 30, 50, 75]
Expand Down Expand Up @@ -626,6 +626,8 @@ contains
call check(error, size(diff(B, 2)), 0, "size(diff(B, 2)) in test_diff_real_${k1}$ failed")
if (allocated(error)) return
call check(error, size(diff(B, 3)), 0, "size(diff(B, 3)) in test_diff_real_${k1}$ failed")
if (allocated(error)) return


end subroutine test_diff_real_${k1}$
#:endfor
Expand Down
Loading