@@ -378,18 +378,43 @@ contains
378378 type(error_type), allocatable, intent(out) :: error
379379 ${t1}$ :: x(6) = [${t1}$ :: 0, 5, 15, 30, 50, 75]
380380 ${t1}$ :: A(1, 3) = reshape([${t1}$ :: 1, 3, 5], [1, 3])
381+ ${t1}$ :: B(2) = [${t1}$ :: 1, 2]
381382
383+ #! rank-1 diff
382384 call check(error, all_close(diff(x), [${t1}$ :: 5, 10, 15, 20, 25]), &
383- "diff(x ) in test_diff_real_${k1}$ failed")
385+ "diff(<rank-1> ) in test_diff_real_${k1}$ failed")
384386 if (allocated(error)) return
385-
387+ call check(error, all_close(diff(x, n=0), x), &
388+ "diff(<rank-1>, n=0) in test_diff_real_${k1}$ failed")
386389 call check(error, all_close(diff(x, n=2), [${t1}$ :: 5, 5, 5, 5]), &
387- "diff(x , n=2) in test_diff_real_${k1}$ failed")
390+ "diff(<rank-1> , n=2) in test_diff_real_${k1}$ failed")
388391 if (allocated(error)) return
389392
393+ call check(error, all_close(diff(x, prepend=[${t1}$ :: 1]), [${t1}$ :: -1, 5, 10, 15, 20, 25]), &
394+ "diff(<rank-1>, prepend=[${t1}$ :: 1]) in test_diff_real_${k1}$ failed")
395+ if (allocated(error)) return
396+ call check(error, all_close(diff(x, append=[${t1}$ :: 1]), [${t1}$ :: 5, 10, 15, 20, 25, -74]), &
397+ "diff(<rank-1>, append=[${t1}$ :: 1]) in test_diff_real_${k1}$ failed")
398+ if (allocated(error)) return
399+
400+ #! rank-2 diff
401+ call check(error, all_close(diff(reshape(A, [3,1]), n=1, dim=1), reshape([${t1}$ :: 2, 2], [2, 1])), &
402+ "diff(<rank-2>, n=1, dim=1) in test_diff_real_${k1}$ failed")
403+ if (allocated(error)) return
390404 call check(error, all_close(diff(A, n=1, dim=2), reshape([${t1}$ :: 2, 2], [1, 2])), &
391- "diff(x, n=1, dim=2) in test_diff_real_${k1}$ failed")
405+ "diff(<rank-2>, n=1, dim=2) in test_diff_real_${k1}$ failed")
406+ if (allocated(error)) return
407+
408+ call check(error, all_close(diff(A, n=1, dim=2, prepend=reshape([${t1}$ :: 1], [1, 1]), &
409+ append=reshape([${t1}$ :: 2], [1, 1])), reshape([${t1}$ :: 0, 2, 2, -3], [1, 4])), &
410+ "diff(<rank-2>, n=1, dim=2, prepend=reshape([${t1}$ :: 1], [1, 1]), &
411+ &append=reshape([${t1}$ :: 2], [1, 1])) in test_diff_real_${k1}$ failed")
412+ if (allocated(error)) return
413+
414+ #! size(B, dim) <= n
415+ call check(error, size(diff(B, 2)), 0, "size(diff(B, 2)) in test_diff_real_${k1}$ failed")
392416 if (allocated(error)) return
417+ call check(error, size(diff(B, 3)), 0, "size(diff(B, 3)) in test_diff_real_${k1}$ failed")
393418
394419 end subroutine test_diff_real_${k1}$
395420 #:endfor
@@ -399,19 +424,39 @@ contains
399424 type(error_type), allocatable, intent(out) :: error
400425 ${t1}$ :: x(6) = [${t1}$ :: 0, 5, 15, 30, 50, 75]
401426 ${t1}$ :: A(1, 3) = reshape([${t1}$ :: 1, 3, 5], [1, 3])
427+ ${t1}$ :: B(2) = [${t1}$ :: 1, 2]
402428
429+ #! rank-1 diff
403430 call check(error, all(diff(x) == [${t1}$ :: 5, 10, 15, 20, 25]), &
404- "diff(x) in test_diff_int_${k1}$ failed")
431+ "diff(<rank-1>) in test_diff_int_${k1}$ failed")
432+ if (allocated(error)) return
433+ call check(error, all(diff(x, n=0) == x), &
434+ "diff(<rank-1>, n=0) in test_diff_int_${k1}$ failed")
405435 if (allocated(error)) return
406-
407436 call check(error, all(diff(x, n=2) == [${t1}$ :: 5, 5, 5, 5]), &
408- "diff(x, n=2) in test_diff_int_${k1}$ failed")
437+ "diff(<rank-1>, n=2) in test_diff_int_${k1}$ failed")
438+ if (allocated(error)) return
439+
440+ call check(error, all(diff(x, prepend=[${t1}$ :: 1]) == [${t1}$ :: -1, 5, 10, 15, 20, 25]), &
441+ "diff(<rank-1>, prepend=[${t1}$ :: 1]) in test_diff_int_${k1}$ failed")
442+ if (allocated(error)) return
443+ call check(error, all(diff(x, append=[${t1}$ :: 1]) == [${t1}$ :: 5, 10, 15, 20, 25, -74]), &
444+ "diff(<rank-1>, append=[${t1}$ :: 1]) in test_diff_int_${k1}$ failed")
409445 if (allocated(error)) return
410446
447+ #! rank-2 diff
448+ call check(error, all(diff(reshape(A, [3,1]), n=1, dim=1) == reshape([${t1}$ :: 2, 2], [2, 1])), &
449+ "diff(<rank-2>, n=1, dim=1) in test_diff_int_${k1}$ failed")
450+ if (allocated(error)) return
411451 call check(error, all(diff(A, n=1, dim=2) == reshape([${t1}$ :: 2, 2], [1, 2])), &
412452 "diff(A, n=1, dim=2) in test_diff_int_${k1}$ failed")
413453 if (allocated(error)) return
414454
455+ #! size(B, dim) <= n
456+ call check(error, size(diff(B, 2)), 0, "size(diff(B, 2)) in test_diff_real_${k1}$ failed")
457+ if (allocated(error)) return
458+ call check(error, size(diff(B, 3)), 0, "size(diff(B, 3)) in test_diff_real_${k1}$ failed")
459+
415460 end subroutine test_diff_int_${k1}$
416461 #:endfor
417462
0 commit comments