Skip to content

Instantly share code, notes, and snippets.

@syllog1sm
Created May 30, 2015 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syllog1sm/a13542690c59d5e60ebf to your computer and use it in GitHub Desktop.
Save syllog1sm/a13542690c59d5e60ebf to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<!-- Generated by Cython 0.20.1 on Sat May 30 04:30:00 2015 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body { font-family: courier; font-size: 12; }
.code { font-size: 9; color: #444444; display: none; margin-left: 20px; }
.py_c_api { color: red; }
.py_macro_api { color: #FF7000; }
.pyx_c_api { color: #FF3000; }
.pyx_macro_api { color: #FF7000; }
.refnanny { color: #FFA000; }
.error_goto { color: #FFA000; }
.tag { }
.coerce { color: #008000; border: 1px dotted #008000 }
.py_attr { color: #FF0000; font-weight: bold; }
.c_attr { color: #0000FF; }
.py_call { color: #FF0000; font-weight: bold; }
.c_call { color: #0000FF; }
.line { margin: 0em }
</style>
<script>
function toggleDiv(id) {
theDiv = document.getElementById(id);
if (theDiv.style.display != 'block') theDiv.style.display = 'block';
else theDiv.style.display = 'none';
}
</script>
</head>
<body>
<p>Generated by Cython 0.20.1 on Sat May 30 04:30:00 2015
<p>Raw output: <a href="hav.c">hav.c</a>
<pre class='line' style='background-color: #FFFFff' onclick='toggleDiv("line1")'> 1: from libc.math cimport sin, cos, acos</pre>
<pre id='line1' class='code' style='background-color: #FFFFff'></pre><pre class='line' style='background-color: #FFFFff' onclick='toggleDiv("line2")'> 2: </pre>
<pre id='line2' class='code' style='background-color: #FFFFff'></pre><pre class='line' style='background-color: #FFFF1e' onclick='toggleDiv("line3")'> 3: cpdef haversine(double lat1, double lng1, double lat2, double lng2):</pre>
<pre id='line3' class='code' style='background-color: #FFFF1e'>static PyObject *__pyx_pw_3hav_1haversine(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_3hav_haversine(double __pyx_v_lat1, double __pyx_v_lng1, double __pyx_v_lat2, double __pyx_v_lng2, CYTHON_UNUSED int __pyx_skip_dispatch) {
double __pyx_v_theta1;
double __pyx_v_theta2;
double __pyx_v_c;
double __pyx_v_arc;
double __pyx_v_phi1;
double __pyx_v_phi2;
PyObject *__pyx_r = NULL;
<span class='refnanny'>__Pyx_RefNannyDeclarations</span>
<span class='refnanny'>__Pyx_RefNannySetupContext</span>("haversine", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
<span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_6);
<span class='pyx_c_api'>__Pyx_AddTraceback</span>("hav.haversine", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
<span class='refnanny'>__Pyx_XGIVEREF</span>(__pyx_r);
<span class='refnanny'>__Pyx_RefNannyFinishContext</span>();
return __pyx_r;
}
/* Python wrapper */
static PyObject *__pyx_pw_3hav_1haversine(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_3hav_haversine[] = "Given two (lat, lng) tuples, returns the distance between them in\n meters.";
static PyObject *__pyx_pw_3hav_1haversine(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
double __pyx_v_lat1;
double __pyx_v_lng1;
double __pyx_v_lat2;
double __pyx_v_lng2;
PyObject *__pyx_r = 0;
<span class='refnanny'>__Pyx_RefNannyDeclarations</span>
<span class='refnanny'>__Pyx_RefNannySetupContext</span>("haversine (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&amp;__pyx_n_s_lat1,&amp;__pyx_n_s_lng1,&amp;__pyx_n_s_lat2,&amp;__pyx_n_s_lng2,0};
PyObject* values[4] = {0,0,0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = <span class='py_macro_api'>PyTuple_GET_SIZE</span>(__pyx_args);
switch (pos_args) {
case 4: values[3] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 3);
case 3: values[2] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 2);
case 2: values[1] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 1);
case 1: values[0] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 0);
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = <span class='py_c_api'>PyDict_Size</span>(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = <span class='py_c_api'>PyDict_GetItem</span>(__pyx_kwds, __pyx_n_s_lat1)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
case 1:
if (likely((values[1] = <span class='py_c_api'>PyDict_GetItem</span>(__pyx_kwds, __pyx_n_s_lng1)) != 0)) kw_args--;
else {
<span class='pyx_c_api'>__Pyx_RaiseArgtupleInvalid</span>("haversine", 1, 4, 4, 1); <span class='error_goto'>{__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L3_error;}</span>
}
case 2:
if (likely((values[2] = <span class='py_c_api'>PyDict_GetItem</span>(__pyx_kwds, __pyx_n_s_lat2)) != 0)) kw_args--;
else {
<span class='pyx_c_api'>__Pyx_RaiseArgtupleInvalid</span>("haversine", 1, 4, 4, 2); <span class='error_goto'>{__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L3_error;}</span>
}
case 3:
if (likely((values[3] = <span class='py_c_api'>PyDict_GetItem</span>(__pyx_kwds, __pyx_n_s_lng2)) != 0)) kw_args--;
else {
<span class='pyx_c_api'>__Pyx_RaiseArgtupleInvalid</span>("haversine", 1, 4, 4, 3); <span class='error_goto'>{__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L3_error;}</span>
}
}
if (unlikely(kw_args &gt; 0)) {
if (unlikely(<span class='pyx_c_api'>__Pyx_ParseOptionalKeywords</span>(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "haversine") &lt; 0)) <span class='error_goto'>{__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L3_error;}</span>
}
} else if (<span class='py_macro_api'>PyTuple_GET_SIZE</span>(__pyx_args) != 4) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 0);
values[1] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 1);
values[2] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 2);
values[3] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 3);
}
__pyx_v_lat1 = __pyx_<span class='py_c_api'>PyFloat_AsDouble</span>(values[0]);<span class='error_goto'> if (unlikely((__pyx_v_lat1 == (double)-1) &amp;&amp; PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L3_error;}</span>
__pyx_v_lng1 = __pyx_<span class='py_c_api'>PyFloat_AsDouble</span>(values[1]);<span class='error_goto'> if (unlikely((__pyx_v_lng1 == (double)-1) &amp;&amp; PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L3_error;}</span>
__pyx_v_lat2 = __pyx_<span class='py_c_api'>PyFloat_AsDouble</span>(values[2]);<span class='error_goto'> if (unlikely((__pyx_v_lat2 == (double)-1) &amp;&amp; PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L3_error;}</span>
__pyx_v_lng2 = __pyx_<span class='py_c_api'>PyFloat_AsDouble</span>(values[3]);<span class='error_goto'> if (unlikely((__pyx_v_lng2 == (double)-1) &amp;&amp; PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L3_error;}</span>
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
<span class='pyx_c_api'>__Pyx_RaiseArgtupleInvalid</span>("haversine", 1, 4, 4, <span class='py_macro_api'>PyTuple_GET_SIZE</span>(__pyx_args)); <span class='error_goto'>{__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L3_error;}</span>
__pyx_L3_error:;
<span class='pyx_c_api'>__Pyx_AddTraceback</span>("hav.haversine", __pyx_clineno, __pyx_lineno, __pyx_filename);
<span class='refnanny'>__Pyx_RefNannyFinishContext</span>();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_3hav_haversine(__pyx_self, __pyx_v_lat1, __pyx_v_lng1, __pyx_v_lat2, __pyx_v_lng2);
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
/* function exit code */
<span class='refnanny'>__Pyx_RefNannyFinishContext</span>();
return __pyx_r;
}
static PyObject *__pyx_pf_3hav_haversine(CYTHON_UNUSED PyObject *__pyx_self, double __pyx_v_lat1, double __pyx_v_lng1, double __pyx_v_lat2, double __pyx_v_lng2) {
PyObject *__pyx_r = NULL;
<span class='refnanny'>__Pyx_RefNannyDeclarations</span>
<span class='refnanny'>__Pyx_RefNannySetupContext</span>("haversine", 0);
<span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_r);
__pyx_t_1 = __pyx_f_3hav_haversine(__pyx_v_lat1, __pyx_v_lng1, __pyx_v_lat2, __pyx_v_lng2, 0);<span class='error_goto'> if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;}</span>
<span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* function exit code */
__pyx_L1_error:;
<span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1);
<span class='pyx_c_api'>__Pyx_AddTraceback</span>("hav.haversine", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
<span class='refnanny'>__Pyx_XGIVEREF</span>(__pyx_r);
<span class='refnanny'>__Pyx_RefNannyFinishContext</span>();
return __pyx_r;
}
</pre><pre class='line' style='background-color: #FFFFff' onclick='toggleDiv("line4")'> 4: """Given two (lat, lng) tuples, returns the distance between them in</pre>
<pre id='line4' class='code' style='background-color: #FFFFff'></pre><pre class='line' style='background-color: #FFFFff' onclick='toggleDiv("line5")'> 5: meters."""</pre>
<pre id='line5' class='code' style='background-color: #FFFFff'></pre><pre class='line' style='background-color: #FFFFff' onclick='toggleDiv("line6")'> 6: </pre>
<pre id='line6' class='code' style='background-color: #FFFFff'></pre><pre class='line' style='background-color: #FFFFff' onclick='toggleDiv("line7")'> 7: if lat1 &gt; 90 or lat1 &lt; -90 or lat2 &gt; 90 or lat2 &lt; -90:</pre>
<pre id='line7' class='code' style='background-color: #FFFFff'> __pyx_t_1 = ((__pyx_v_lat1 &gt; 90.0) != 0);
if (!__pyx_t_1) {
__pyx_t_2 = ((__pyx_v_lat1 &lt; -90.0) != 0);
if (!__pyx_t_2) {
__pyx_t_3 = ((__pyx_v_lat2 &gt; 90.0) != 0);
if (!__pyx_t_3) {
__pyx_t_4 = ((__pyx_v_lat2 &lt; -90.0) != 0);
__pyx_t_5 = __pyx_t_4;
} else {
__pyx_t_5 = __pyx_t_3;
}
__pyx_t_3 = __pyx_t_5;
} else {
__pyx_t_3 = __pyx_t_2;
}
__pyx_t_2 = __pyx_t_3;
} else {
__pyx_t_2 = __pyx_t_1;
}
if (__pyx_t_2) {
</pre><pre class='line' style='background-color: #FFFF7f' onclick='toggleDiv("line8")'> 8: raise ValueError("Invalid latitude (should be between +/- 90)")</pre>
<pre id='line8' class='code' style='background-color: #FFFF7f'> __pyx_t_6 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(__pyx_builtin_ValueError, __pyx_tuple_, NULL);<span class='error_goto'> if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;}</span>
<span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6);
<span class='pyx_c_api'>__Pyx_Raise</span>(__pyx_t_6, 0, 0, 0);
<span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0;
<span class='error_goto'>{__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;}</span>
}
/* … */
__pyx_tuple_ = <span class='py_c_api'>PyTuple_Pack</span>(1, __pyx_kp_s_Invalid_latitude_should_be_betwe);<span class='error_goto'> if (unlikely(!__pyx_tuple_)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;}</span>
<span class='refnanny'>__Pyx_GOTREF</span>(__pyx_tuple_);
<span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_tuple_);
</pre><pre class='line' style='background-color: #FFFFff' onclick='toggleDiv("line9")'> 9: if lng1 &gt; 180 or lng1 &lt; -180 or lng2 &gt; 180 or lng2 &lt; -180:</pre>
<pre id='line9' class='code' style='background-color: #FFFFff'> __pyx_t_2 = ((__pyx_v_lng1 &gt; 180.0) != 0);
if (!__pyx_t_2) {
__pyx_t_1 = ((__pyx_v_lng1 &lt; -180.0) != 0);
if (!__pyx_t_1) {
__pyx_t_3 = ((__pyx_v_lng2 &gt; 180.0) != 0);
if (!__pyx_t_3) {
__pyx_t_5 = ((__pyx_v_lng2 &lt; -180.0) != 0);
__pyx_t_4 = __pyx_t_5;
} else {
__pyx_t_4 = __pyx_t_3;
}
__pyx_t_3 = __pyx_t_4;
} else {
__pyx_t_3 = __pyx_t_1;
}
__pyx_t_1 = __pyx_t_3;
} else {
__pyx_t_1 = __pyx_t_2;
}
if (__pyx_t_1) {
</pre><pre class='line' style='background-color: #FFFFaa' onclick='toggleDiv("line10")'> 10: raise ValueError("Invalid longitude (should be between +/- 180)")</pre>
<pre id='line10' class='code' style='background-color: #FFFFaa'> __pyx_t_6 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(__pyx_builtin_ValueError, __pyx_tuple__2, NULL);<span class='error_goto'> if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;}</span>
<span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6);
<span class='pyx_c_api'>__Pyx_Raise</span>(__pyx_t_6, 0, 0, 0);
<span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0;
<span class='error_goto'>{__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;}</span>
}
</pre><pre class='line' style='background-color: #FFFFff' onclick='toggleDiv("line11")'> 11: </pre>
<pre id='line11' class='code' style='background-color: #FFFFff'></pre><pre class='line' style='background-color: #FFFFff' onclick='toggleDiv("line12")'> 12: cdef double ph1</pre>
<pre id='line12' class='code' style='background-color: #FFFFff'></pre><pre class='line' style='background-color: #FFFFff' onclick='toggleDiv("line13")'> 13: cdef double ph2</pre>
<pre id='line13' class='code' style='background-color: #FFFFff'></pre><pre class='line' style='background-color: #FFFFff' onclick='toggleDiv("line14")'> 14: cdef double theta1</pre>
<pre id='line14' class='code' style='background-color: #FFFFff'></pre><pre class='line' style='background-color: #FFFFff' onclick='toggleDiv("line15")'> 15: cdef double theta2</pre>
<pre id='line15' class='code' style='background-color: #FFFFff'></pre><pre class='line' style='background-color: #FFFFff' onclick='toggleDiv("line16")'> 16: cdef double c</pre>
<pre id='line16' class='code' style='background-color: #FFFFff'></pre><pre class='line' style='background-color: #FFFFff' onclick='toggleDiv("line17")'> 17: cdef double arc</pre>
<pre id='line17' class='code' style='background-color: #FFFFff'></pre><pre class='line' style='background-color: #FFFFff' onclick='toggleDiv("line18")'> 18: </pre>
<pre id='line18' class='code' style='background-color: #FFFFff'></pre><pre class='line' style='background-color: #FFFFff' onclick='toggleDiv("line19")'> 19: phi1 = (90.0 - lat1) * 0.0174532925</pre>
<pre id='line19' class='code' style='background-color: #FFFFff'> __pyx_v_phi1 = ((90.0 - __pyx_v_lat1) * 0.0174532925);
</pre><pre class='line' style='background-color: #FFFFff' onclick='toggleDiv("line20")'> 20: phi2 = (90.0 - lat2) * 0.0174532925</pre>
<pre id='line20' class='code' style='background-color: #FFFFff'> __pyx_v_phi2 = ((90.0 - __pyx_v_lat2) * 0.0174532925);
</pre><pre class='line' style='background-color: #FFFFff' onclick='toggleDiv("line21")'> 21: theta1 = lng1 * 0.0174532925</pre>
<pre id='line21' class='code' style='background-color: #FFFFff'> __pyx_v_theta1 = (__pyx_v_lng1 * 0.0174532925);
</pre><pre class='line' style='background-color: #FFFFff' onclick='toggleDiv("line22")'> 22: theta2 = lng2 * 0.0174532925</pre>
<pre id='line22' class='code' style='background-color: #FFFFff'> __pyx_v_theta2 = (__pyx_v_lng2 * 0.0174532925);
</pre><pre class='line' style='background-color: #FFFFff' onclick='toggleDiv("line23")'> 23: </pre>
<pre id='line23' class='code' style='background-color: #FFFFff'></pre><pre class='line' style='background-color: #FFFFff' onclick='toggleDiv("line24")'> 24: c = (sin(phi1) * sin(phi2) * cos(theta1 - theta2) + cos(phi1) * cos(phi2))</pre>
<pre id='line24' class='code' style='background-color: #FFFFff'> __pyx_v_c = (((sin(__pyx_v_phi1) * sin(__pyx_v_phi2)) * cos((__pyx_v_theta1 - __pyx_v_theta2))) + (cos(__pyx_v_phi1) * cos(__pyx_v_phi2)));
</pre><pre class='line' style='background-color: #FFFFff' onclick='toggleDiv("line25")'> 25: arc = acos(c)</pre>
<pre id='line25' class='code' style='background-color: #FFFFff'> __pyx_v_arc = acos(__pyx_v_c);
</pre><pre class='line' style='background-color: #FFFF9f' onclick='toggleDiv("line26")'> 26: return arc * 6367444.7</pre>
<pre id='line26' class='code' style='background-color: #FFFF9f'> <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_r);
__pyx_t_6 = <span class='py_c_api'>PyFloat_FromDouble</span>((__pyx_v_arc * 6367444.7));<span class='error_goto'> if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}</span>
<span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6);
__pyx_r = __pyx_t_6;
__pyx_t_6 = 0;
goto __pyx_L0;
</pre></body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment