-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[stdlib_math] Add function diff
#605
Conversation
src/stdlib_math_diff.fypp
Outdated
|
||
#:for k1, t1 in RI_KINDS_TYPES | ||
pure module function diff_1_${k1}$(X, n) result(Y) | ||
${t1}$, intent(in) :: X(:) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know whether this interface has been discussed anywhere so far? A few potential issues that come to mind are:
- This routine allocates its output on every call. I can imagine in some situations that could be inefficient. Users might wish to make a more efficient
diff
call by providing the output data. For that case a subroutine interface may be preferable. - When computing differences in practice, there are different approaches that may be desired to treat the end-points. The current routines reduce the size of the array. But one might also wish to preserve the array size and do some kind of extrapolation at the missing entry. There can be a number of cases here (e.g. forward differences, backward differences, centred differences, with different implications for end-points).
Currently the routine won't support such things. While that might prove to be fine, I'd like to see some discussion to ensure we've chosen the right interface.
What is the state-of-the-art of such a function (e.g., how is it designed in other languages?)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this PR. Here are some suggestions and comments.
This comment has been minimized.
This comment has been minimized.
cf3483a
to
bd52051
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you. Here are a couple of minor comments.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Pending a few comments, it could be merged IMO, Thank you @zoziha for this PR.
Thank you @jvdp1 for your patient review, I have made changes accordingly :) |
Thank you @zoziha. This PR is fine for me. If @gareth-nx or @awvwgk could have a final look, it would be nice ;) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you! I left several suggestions in the spec doc.
Thanks @milancurcic , I have made changes accordingly. |
@gareth-nx @awvwgk are you OK with this PR going forward? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
diff
: Differences and approximate derivativesDescription
Computes differences between adjacent elements of an array.
Note: Only
diff
forrank-1/rank-2
arrays at this stage. (If there is a higherrank
demand in the future, we can consider extending it.)API:
For a rank-1 array
and for a rank-2 array
X
:real/integer
types.n
: Difference order.Note
Originally
diff
should be putted instdlib_linalg
, but considering thatdiff
can supportdate
drived types in the future, now it is putted instdlib_math
.Prior Art
diff
in Matlabdiff
in numpy