@@ -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
663663y = [[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
667667y = [[stdlib_math(module):diff(interface)]](x [, n, dim, prepend, append])
668668```
@@ -677,35 +677,36 @@ Pure function.
677677
678678#### Arguments
679679
680- Note: The ` x ` , ` prepend ` and ` append ` arguments must have the same ` type ` , ` kind ` and ` rank ` .
681-
682- ` x ` : Shall be a ` real/integer ` and ` rank-1/rank-2 ` array.
680+ ` x ` : The array to take a difference of.
681+ Shall be a ` real/integer ` and ` rank-1/rank-2 ` array.
683682This argument is ` intent(in) ` .
684683
685- ` n ` : Shall be an ` integer ` scalar.
686- This argument is ` intent(in) ` and ` optional ` , which is ` 1 ` by default.
687- It represents to calculate the n-th order difference.
688-
689- ` dim ` : Shall be an ` integer ` scalar.
690- This argument is ` intent(in) ` and ` optional ` , which is ` 1 ` by default.
691- It gives the dimension of the input array along which the difference is calculated, between ` 1 ` and ` rank(x) ` .
684+ ` n ` : How many times to iteratively calculate the difference.
685+ Shall be an ` integer ` scalar.
686+ This argument is ` intent(in) ` and ` optional ` , and has value of ` 1 ` by default.
692687
693- ` prepend ` : Shall be a ` real/integer ` and ` rank-1/rank-2 ` array, which is no value by default.
694- This argument is ` intent(in) ` and ` optional ` .
688+ ` dim ` : The dimension of the input array along which to calculate the difference.
689+ Its value must be between ` 1 ` and ` rank(x) ` .
690+ Shall be an ` integer ` scalar.
691+ This argument is ` intent(in) ` and ` optional ` and has a value of ` 1 ` by default.
695692
696- ` append ` : Shall be a ` real/integer ` and ` rank-1/rank-2 ` array, which is no value by default.
697- This argument is ` intent(in) ` and ` optional ` .
693+ ` prepend ` , ` append ` : Arrays to prepend or append to a along axis prior to performing the difference.
694+ The dimension and shape must match a except along axis.
695+ Shall be a ` real/integer ` and ` rank-1/rank-2 ` array.
696+ This argument is ` intent(in) ` and ` optional ` , which is no value by default.
698697
699698Note:
700- - If the value of ` n ` is less than or equal to ` 0 ` , the return value of ` y ` is ` x ` . (Not recommended)
701- - If the value of ` dim ` is not equal to ` 1 ` or ` 2 ` ,
702- ` 1 ` will be used by the internal process of ` diff ` . (Not recommended)
699+ - The ` x ` , ` prepend ` and ` append ` arguments must have the same ` type ` , ` kind ` and ` rank ` .
700+ - If the value of ` n ` is less than or equal to ` 0 ` (which is not recommended), the return value of ` diff ` is ` x ` .
701+ - If the value of ` dim ` is not equal to ` 1 ` or ` 2 ` (which is not recommended),
702+ ` 1 ` will be used by the internal process of ` diff ` .
703703
704- #### Result value
705704
706- Note: That ` y ` generally has one fewer element than ` x ` .
705+ #### Result value
707706
708- Returns a ` real/integer ` and ` rank-1/rank-2 ` array.
707+ Returns the finite difference of the input array.
708+ Shall be a ` real/integer ` and ` rank-1/rank-2 ` array.
709+ When both ` prepend ` and ` append ` are not present, the result ` y ` has one fewer element than ` x ` alongside the dimension ` dim ` .
709710
710711#### Example
711712
@@ -720,16 +721,16 @@ program demo_diff
720721 integer :: A(3, 3) = reshape([1, 7, 17, 3, 11, 19, 5, 13, 23], [3, 3])
721722 integer :: Y(3, 2)
722723
723- print *, diff(i) !! [0, 1, 1, 2, 3, 5]
724- print *, diff(x, 2) !! [5.0, 5.0, 5.0, 5.0]
724+ print *, diff(i) ! [0, 1, 1, 2, 3, 5]
725+ print *, diff(x, 2) ! [5.0, 5.0, 5.0, 5.0]
725726
726727 Y = diff(A, n=1, dim=2)
727- print *, Y(1, :) !! [2, 2]
728- print *, Y(2, :) !! [4, 2]
729- print *, Y(3, :) !! [2, 4]
728+ print *, Y(1, :) ! [2, 2]
729+ print *, Y(2, :) ! [4, 2]
730+ print *, Y(3, :) ! [2, 4]
730731
731- print *, diff(i, prepend=[0]) !! [1, 0, 1, 1, 2, 3, 5]
732- print *, diff(i, append=[21]) !! [0, 1, 1, 2, 3, 5, 8]
732+ print *, diff(i, prepend=[0]) ! [1, 0, 1, 1, 2, 3, 5]
733+ print *, diff(i, append=[21]) ! [0, 1, 1, 2, 3, 5, 8]
733734
734735end program demo_diff
735736```
0 commit comments