Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
df810151
Commit
df810151
authored
Sep 29, 2018
by
Raymond Hettinger
Committed by
GitHub
Sep 29, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Speed-up math.dist() by 30% (GH-9628)
parent
e45473e3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
6 deletions
+12
-6
Modules/clinic/mathmodule.c.h
Modules/clinic/mathmodule.c.h
+4
-3
Modules/mathmodule.c
Modules/mathmodule.c
+8
-3
No files found.
Modules/clinic/mathmodule.c.h
View file @
df810151
...
...
@@ -294,8 +294,9 @@ math_dist(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
PyObject
*
p
;
PyObject
*
q
;
if
(
!
_PyArg_ParseStack
(
args
,
nargs
,
"O!O!:dist"
,
&
PyTuple_Type
,
&
p
,
&
PyTuple_Type
,
&
q
))
{
if
(
!
_PyArg_UnpackStack
(
args
,
nargs
,
"dist"
,
2
,
2
,
&
p
,
&
q
))
{
goto
exit
;
}
return_value
=
math_dist_impl
(
module
,
p
,
q
);
...
...
@@ -522,4 +523,4 @@ math_isclose(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
exit:
return
return_value
;
}
/*[clinic end generated code: output=
d936137c1189b89
b input=a9049054013a1b77]*/
/*[clinic end generated code: output=
239c51a5acefbaf
b input=a9049054013a1b77]*/
Modules/mathmodule.c
View file @
df810151
...
...
@@ -2101,8 +2101,8 @@ vector_norm(Py_ssize_t n, double *vec, double max, int found_nan)
/*[clinic input]
math.dist
p: object
(subclass_of='&PyTuple_Type')
q: object
(subclass_of='&PyTuple_Type')
p: object
q: object
/
Return the Euclidean distance between two points p and q.
...
...
@@ -2116,7 +2116,7 @@ Roughly equivalent to:
static
PyObject
*
math_dist_impl
(
PyObject
*
module
,
PyObject
*
p
,
PyObject
*
q
)
/*[clinic end generated code: output=56bd9538d06bbcfe input=
937122eaa5f19272
]*/
/*[clinic end generated code: output=56bd9538d06bbcfe input=
8c83c07c7a524664
]*/
{
PyObject
*
item
;
double
max
=
0
.
0
;
...
...
@@ -2126,6 +2126,11 @@ math_dist_impl(PyObject *module, PyObject *p, PyObject *q)
double
diffs_on_stack
[
NUM_STACK_ELEMS
];
double
*
diffs
=
diffs_on_stack
;
if
(
!
PyTuple_Check
(
p
)
||
!
PyTuple_Check
(
q
))
{
PyErr_SetString
(
PyExc_TypeError
,
"dist argument must be a tuple"
);
return
NULL
;
}
m
=
PyTuple_GET_SIZE
(
p
);
n
=
PyTuple_GET_SIZE
(
q
);
if
(
m
!=
n
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment