Skip to content

Commit ab0256a

Browse files
committed
Minor update of diff doc.
1 parent 74c5c11 commit ab0256a

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

doc/specs/stdlib_math.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -658,11 +658,11 @@ Computes differences between adjacent elements of an array.
658658

659659
#### Syntax
660660

661-
For rank-1 array
661+
For a rank-1 array
662662
```fortran
663663
y = [[stdlib_math(module):diff(interface)]](x [, n, prepend, append])
664664
```
665-
and for rank-2 array
665+
and for a rank-2 array
666666
```fortran
667667
y = [[stdlib_math(module):diff(interface)]](x [, n, dim, prepend, append])
668668
```
@@ -677,8 +677,6 @@ Pure function.
677677

678678
#### Arguments
679679

680-
Note: The `x`, `prepend` and `append` arguments must have the same `type`, `kind` and `rank`.
681-
682680
`x`: Shall be a `real/integer` and `rank-1/rank-2` array.
683681
This argument is `intent(in)`.
684682

@@ -697,15 +695,16 @@ This argument is `intent(in)` and `optional`.
697695
This argument is `intent(in)` and `optional`.
698696

699697
Note:
698+
- The `x`, `prepend` and `append` arguments must have the same `type`, `kind` and `rank`.
700699
- If the value of `n` is less than or equal to `0`, the return value of `y` is `x`. (Not recommended)
701700
- If the value of `dim` is not equal to `1` or `2`,
702701
`1` will be used by the internal process of `diff`. (Not recommended)
703702

704-
#### Result value
705703

706-
Note: That `y` generally has one fewer element than `x`.
704+
#### Result value
707705

708706
Returns a `real/integer` and `rank-1/rank-2` array.
707+
When both `prepend` and `append` are not present, the result `y` has one fewer element than `x` alongside the dimension `dim`.
709708

710709
#### Example
711710

src/tests/math/test_stdlib_math.fypp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,12 @@ contains
452452
"diff(<rank-2>, n=1, dim=2) in test_diff_int_${k1}$ failed")
453453
if (allocated(error)) return
454454

455+
call check(error, all(diff(A, n=1, dim=2, prepend=reshape([${t1}$ :: 1], [1, 1]), &
456+
append=reshape([${t1}$ :: 2], [1, 1])) == reshape([${t1}$ :: 0, 2, 2, -3], [1, 4])), &
457+
"diff(<rank-2>, n=1, dim=2, prepend=reshape([${t1}$ :: 1], [1, 1]), &
458+
&append=reshape([${t1}$ :: 2], [1, 1])) in test_diff_int_${k1}$ failed")
459+
if (allocated(error)) return
460+
455461
!> size(B, dim) <= n
456462
call check(error, size(diff(B, 2)), 0, "size(diff(B, 2)) in test_diff_int_${k1}$ failed")
457463
if (allocated(error)) return

0 commit comments

Comments
 (0)