@@ -8,7 +8,7 @@ module stdlib_math
88 public :: clip, gcd, linspace, logspace
99 public :: EULERS_NUMBER_SP, EULERS_NUMBER_DP
1010 public :: DEFAULT_LINSPACE_LENGTH, DEFAULT_LOGSPACE_BASE, DEFAULT_LOGSPACE_LENGTH
11- public :: arange, arg, argd, argpi, is_close, all_close
11+ public :: arange, arg, argd, argpi, is_close, all_close, diff
1212
1313 integer , parameter :: DEFAULT_LINSPACE_LENGTH = 100
1414 integer , parameter :: DEFAULT_LOGSPACE_LENGTH = 50
@@ -596,6 +596,85 @@ logical pure module function all_close_4_cdp(a, b, rel_tol, abs_tol, equal_nan)
596596 logical , intent (in ), optional :: equal_nan
597597 end function all_close_4_cdp
598598 end interface all_close
599+
600+ ! > Version: experimental
601+ ! >
602+ ! > Computes differences between adjacent elements of an array.
603+ ! > ([Specification](../page/specs/stdlib_math.html#diff))
604+ interface diff
605+ pure module function diff_1_sp(x, n, prepend, append) result(y)
606+ real (sp), intent (in ) :: x(:)
607+ integer , intent (in ), optional :: n
608+ real (sp), intent (in ), optional :: prepend(:), append (:)
609+ real (sp), allocatable :: y(:)
610+ end function diff_1_sp
611+ pure module function diff_2_sp(X, n, dim, prepend, append) result(y)
612+ real (sp), intent (in ) :: x(:, :)
613+ integer , intent (in ), optional :: n, dim
614+ real (sp), intent (in ), optional :: prepend(:, :), append (:, :)
615+ real (sp), allocatable :: y(:, :)
616+ end function diff_2_sp
617+ pure module function diff_1_dp(x, n, prepend, append) result(y)
618+ real (dp), intent (in ) :: x(:)
619+ integer , intent (in ), optional :: n
620+ real (dp), intent (in ), optional :: prepend(:), append (:)
621+ real (dp), allocatable :: y(:)
622+ end function diff_1_dp
623+ pure module function diff_2_dp(X, n, dim, prepend, append) result(y)
624+ real (dp), intent (in ) :: x(:, :)
625+ integer , intent (in ), optional :: n, dim
626+ real (dp), intent (in ), optional :: prepend(:, :), append (:, :)
627+ real (dp), allocatable :: y(:, :)
628+ end function diff_2_dp
629+ pure module function diff_1_int8(x, n, prepend, append) result(y)
630+ integer (int8), intent (in ) :: x(:)
631+ integer , intent (in ), optional :: n
632+ integer (int8), intent (in ), optional :: prepend(:), append (:)
633+ integer (int8), allocatable :: y(:)
634+ end function diff_1_int8
635+ pure module function diff_2_int8(X, n, dim, prepend, append) result(y)
636+ integer (int8), intent (in ) :: x(:, :)
637+ integer , intent (in ), optional :: n, dim
638+ integer (int8), intent (in ), optional :: prepend(:, :), append (:, :)
639+ integer (int8), allocatable :: y(:, :)
640+ end function diff_2_int8
641+ pure module function diff_1_int16(x, n, prepend, append) result(y)
642+ integer (int16), intent (in ) :: x(:)
643+ integer , intent (in ), optional :: n
644+ integer (int16), intent (in ), optional :: prepend(:), append (:)
645+ integer (int16), allocatable :: y(:)
646+ end function diff_1_int16
647+ pure module function diff_2_int16(X, n, dim, prepend, append) result(y)
648+ integer (int16), intent (in ) :: x(:, :)
649+ integer , intent (in ), optional :: n, dim
650+ integer (int16), intent (in ), optional :: prepend(:, :), append (:, :)
651+ integer (int16), allocatable :: y(:, :)
652+ end function diff_2_int16
653+ pure module function diff_1_int32(x, n, prepend, append) result(y)
654+ integer (int32), intent (in ) :: x(:)
655+ integer , intent (in ), optional :: n
656+ integer (int32), intent (in ), optional :: prepend(:), append (:)
657+ integer (int32), allocatable :: y(:)
658+ end function diff_1_int32
659+ pure module function diff_2_int32(X, n, dim, prepend, append) result(y)
660+ integer (int32), intent (in ) :: x(:, :)
661+ integer , intent (in ), optional :: n, dim
662+ integer (int32), intent (in ), optional :: prepend(:, :), append (:, :)
663+ integer (int32), allocatable :: y(:, :)
664+ end function diff_2_int32
665+ pure module function diff_1_int64(x, n, prepend, append) result(y)
666+ integer (int64), intent (in ) :: x(:)
667+ integer , intent (in ), optional :: n
668+ integer (int64), intent (in ), optional :: prepend(:), append (:)
669+ integer (int64), allocatable :: y(:)
670+ end function diff_1_int64
671+ pure module function diff_2_int64(X, n, dim, prepend, append) result(y)
672+ integer (int64), intent (in ) :: x(:, :)
673+ integer , intent (in ), optional :: n, dim
674+ integer (int64), intent (in ), optional :: prepend(:, :), append (:, :)
675+ integer (int64), allocatable :: y(:, :)
676+ end function diff_2_int64
677+ end interface diff
599678
600679contains
601680
0 commit comments