-
-
Notifications
You must be signed in to change notification settings - Fork 12.2k
ENH: Add gcd and lcm ufuncs #8774
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -550,6 +550,8 @@ Math operations | |
| square | ||
| cbrt | ||
| reciprocal | ||
| gcd | ||
| lcm | ||
|
|
||
| .. tip:: | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1041,6 +1041,7 @@ NPY_NO_EXPORT void | |
| /**begin repeat | ||
| * #TYPE = BYTE, SHORT, INT, LONG, LONGLONG# | ||
| * #type = npy_byte, npy_short, npy_int, npy_long, npy_longlong# | ||
| * #c = ,,,l,ll# | ||
| */ | ||
|
|
||
| NPY_NO_EXPORT NPY_GCC_OPT_3 void | ||
|
|
@@ -1132,11 +1133,26 @@ NPY_NO_EXPORT void | |
| } | ||
| } | ||
|
|
||
| /**begin repeat1 | ||
| * #kind = gcd, lcm# | ||
| **/ | ||
| NPY_NO_EXPORT void | ||
| @TYPE@_@kind@(char **args, npy_intp *dimensions, npy_intp *steps, void *NPY_UNUSED(func)) | ||
| { | ||
| BINARY_LOOP { | ||
| const @type@ in1 = *(@type@ *)ip1; | ||
| const @type@ in2 = *(@type@ *)ip2; | ||
| *((@type@ *)op1) = npy_@kind@@c@(in1, in2); | ||
| } | ||
| } | ||
| /**end repeat1**/ | ||
|
|
||
| /**end repeat**/ | ||
|
|
||
| /**begin repeat | ||
| * #TYPE = UBYTE, USHORT, UINT, ULONG, ULONGLONG# | ||
| * #type = npy_ubyte, npy_ushort, npy_uint, npy_ulong, npy_ulonglong# | ||
| * #c = u,u,u,ul,ull# | ||
|
||
| */ | ||
|
|
||
| NPY_NO_EXPORT void | ||
|
|
@@ -1204,6 +1220,20 @@ NPY_NO_EXPORT void | |
| } | ||
| } | ||
|
|
||
| /**begin repeat1 | ||
| * #kind = gcd, lcm# | ||
| **/ | ||
| NPY_NO_EXPORT void | ||
| @TYPE@_@kind@(char **args, npy_intp *dimensions, npy_intp *steps, void *NPY_UNUSED(func)) | ||
| { | ||
| BINARY_LOOP { | ||
| const @type@ in1 = *(@type@ *)ip1; | ||
| const @type@ in2 = *(@type@ *)ip2; | ||
| *((@type@ *)op1) = npy_@kind@@c@(in1, in2); | ||
| } | ||
| } | ||
| /**end repeat1**/ | ||
|
|
||
| /**end repeat**/ | ||
|
|
||
| /* | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
Got this wrong until now. The identity of gcd is
0since by definition,gcd(a, 0) == a.The identity for
lcmis some kind of epsilon. For the integers, that epsilon is simply1(lcm(a, 1) = a). However, for the rationals, (iedecimal.Decimal), this is incorrect (lcm(0.2, 1) != 0.2), nor is such an epsilon really representable anyway.