-
Notifications
You must be signed in to change notification settings - Fork 184
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
GCD (Greatest Common Divisior) #515
Comments
This comment has been minimized.
This comment has been minimized.
Do you think it would be a good idea to split |
Even if you have a measurable performance gain, which I pretty much doubt
(depending on how you swap things), then you do increase the burden on the
user/programmer. They will now have to decide which one to use.
Op wo 22 sep. 2021 om 11:26 schreef Carl ***@***.***>:
… Do you think it would be a good idea to split gcd into one gcd which
swaps the arguments if necessary and another gcd which requires the first
argument to be the greater one? I wonder if this could be used in some
situations to make the routine a little bit faster.
On the one hand it will just be a tiny performance improvement (if any),
on the other hand this would be very easy to implement (gcd with swap
calls gcd without swap).
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#515 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN6YR6GZ4JUBYR2PZDUCVLUDGOKXANCNFSM5DQYTFVA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
I would implement this to get started with stdlib. |
CC from PR:
|
I've used One thing I would point out is the similarity with some of the intrinsic functions, i.e. Currently, the standard does not allow writing variadic functions like |
Two cases with arrays: Wolfram https://reference.wolfram.com/language/ref/GCD.html |
If we only plan to support two scalars or a vector I'm fine with putting these under the same interface like this: interface gcd
elemental function gcd_scalar(a,b) result(res)
integer, intent(in) :: a, b
integer :: res
end function
function gcd_vector(v) result(res)
integer, intent(in) :: v(:)
integer :: res
end function
end interface But as a language built on the foundation of arrays, I think a transformational function like shown below, fits well with existing Fortran intrinsics: function gcdval(array,dim,mask) result(res)
integer, intent(in) :: array(:,:)
integer, intent(in) :: dim
logical, intent(in) :: mask(:,:)
integer :: res(:)
end function Maybe @FortranFan is willing to share his opinion on what is the value/need for the |
I've never used I don't know whether a
|
There were two posts about the GCD algorithm in Hacker News recently:
|
As suggested in #365, providing
gcd
function out of the box will be a good addition.Description
Have a look at these comments to know more:
#365 (comment)
j3-fortran/fortran_proposals#221 (comment)
Prior Art
Many languages provide
gcd
out of the box.The text was updated successfully, but these errors were encountered: