@@ -658,11 +658,11 @@ Computes differences between adjacent elements of an array.
658
658
659
659
#### Syntax
660
660
661
- For rank-1 array
661
+ For a rank-1 array
662
662
``` fortran
663
663
y = [[stdlib_math(module):diff(interface)]](x [, n, prepend, append])
664
664
```
665
- and for rank-2 array
665
+ and for a rank-2 array
666
666
``` fortran
667
667
y = [[stdlib_math(module):diff(interface)]](x [, n, dim, prepend, append])
668
668
```
@@ -677,35 +677,36 @@ Pure function.
677
677
678
678
#### Arguments
679
679
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.
683
682
This argument is ` intent(in) ` .
684
683
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.
692
687
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.
695
692
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.
698
697
699
698
Note:
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 ` .
703
703
704
- #### Result value
705
704
706
- Note: That ` y ` generally has one fewer element than ` x ` .
705
+ #### Result value
707
706
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 ` .
709
710
710
711
#### Example
711
712
@@ -720,16 +721,16 @@ program demo_diff
720
721
integer :: A(3, 3) = reshape([1, 7, 17, 3, 11, 19, 5, 13, 23], [3, 3])
721
722
integer :: Y(3, 2)
722
723
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]
725
726
726
727
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]
730
731
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]
733
734
734
735
end program demo_diff
735
736
```
0 commit comments