10000 CLN: use float64_t consistently instead of double, double_t by jbrockmendel · Pull Request #23583 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

CLN: use float64_t consistently instead of double, double_t #23583

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

Merged
merged 19 commits into from
Nov 11, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
use float64_t instead of double
  • Loading branch information
jbrockmendel committed Nov 7, 2018
commit fa38001ca5fdbc09824de79ef749e77c0688b8fd
7 changes: 3 additions & 4 deletions pandas/_libs/algos.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ from numpy cimport (ndarray,
NPY_FLOAT32, NPY_FLOAT64,
NPY_OBJECT,
int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t,
uint32_t, uint64_t, float32_t, float64_t,
double_t)
uint32_t, uint64_t, float32_t, float64_t)
cnp.import_array()


Expand All @@ -32,8 +31,8 @@ import missing

cdef float64_t FP_ERR = 1e-13

cdef double NaN = <double>np.NaN
cdef double nan = NaN
cdef float64_t NaN = <float64_t>np.NaN
cdef float64_t nan = NaN

cdef int64_t iNaT = get_nat()

Expand Down
7 changes: 3 additions & 4 deletions pandas/_libs/groupby.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ from libc.stdlib cimport malloc, free
import numpy as np
cimport numpy as cnp
from numpy cimport (ndarray,
double_t,
int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t,
uint32_t, uint64_t, float32_t, float64_t)
cnp.import_array()
Expand All @@ -22,8 +21,8 @@ from algos import take_2d_axis1_float64_float64, groupsort_indexer, tiebreakers

cdef int64_t iNaT = get_nat()

cdef double NaN = <double>np.NaN
cdef double nan = NaN
cdef float64_t NaN = <float64_t>np.NaN
cdef float64_t nan = NaN


cdef inline float64_t median_linear(float64_t* a, int n) nogil:
Expand Down Expand Up @@ -73,7 +72,7 @@ cdef inline float64_t kth_smallest_c(float64_t* a,
Py_ssize_t n) nogil:
cdef:
Py_ssize_t i, j, l, m
double_t x, t
float64_t x, t

l = 0
m = n - 1
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/groupby_helper.pxi.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ WARNING: DO NOT edit .pxi FILE directly, .pxi is generated from .pxi.in
"""

cdef extern from "numpy/npy_math.h":
double NAN "NPY_NAN"
float64_t NAN "NPY_NAN"
_int64_max = np.iinfo(np.int64).max

# ----------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/hashtable.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ from libc.stdlib cimport malloc, free

import numpy as np
cimport numpy as cnp
from numpy cimport ndarray, uint8_t, uint32_t
from numpy cimport ndarray, uint8_t, uint32_t, float64_t
cnp.import_array()

cdef extern from "numpy/npy_math.h":
double NAN "NPY_NAN"
float64_t NAN "NPY_NAN"


from khash cimport (
Expand Down
15 changes: 11 additions & 4 deletions pandas/_libs/interval.pyx
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
# -*- coding: utf-8 -*-
import numbers
from operator import le, lt

from cpython.object cimport (Py_EQ, Py_NE, Py_GT, Py_LT, Py_GE, Py_LE,
PyObject_RichCompare)

cimport cython
from cython cimport Py_ssize_t
import cython
from cython import Py_ssize_t

import numpy as np
from numpy cimport ndarray
cimport numpy as cnp
from numpy cimport (
int64_t, int32_t, float64_t, float32_t, uint64_t,
ndarray,
PyArray_ArgSort, NPY_QUICKSORT, PyArray_Take)
cnp.import_array()

from operator import le, lt

cimport util
util.import_array()

from hashtable cimport Int64Vector, Int64VectorData

from tslibs import Timestamp
from tslibs.timezones cimport tz_compare

Expand Down
25 changes: 5 additions & 20 deletions pandas/_libs/intervaltree.pxi.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,16 @@ Template for intervaltree
WARNING: DO NOT edit .pxi FILE directly, .pxi is generated from .pxi.in
"""

from numpy cimport (
int64_t, int32_t, float64_t, float32_t, uint64_t,
ndarray,
PyArray_ArgSort, NPY_QUICKSORT, PyArray_Take)
import numpy as np

cimport cython
from cython cimport Py_ssize_t

cimport numpy as cnp
cnp.import_array()

from hashtable cimport Int64Vector, Int64VectorData


ctypedef fused scalar_t:
float64_t
float32_t
int64_t
int32_t
uint64_t


#----------------------------------------------------------------------
# ----------------------------------------------------------------------
# IntervalTree
#----------------------------------------------------------------------
# ----------------------------------------------------------------------

cdef class IntervalTree(IntervalMixin):
"""A centered interval tree
Expand Down Expand Up @@ -202,9 +186,10 @@ cdef sort_values_and_indices(all_values, all_indices, subset):
sorted_indices = take(indices, sorter)
return sorted_values, sorted_indices

#----------------------------------------------------------------------

# ----------------------------------------------------------------------
# Nodes
#----------------------------------------------------------------------
# ----------------------------------------------------------------------

# we need specialized nodes and leaves to optimize for different dtype and
# closed values
Expand Down
6 changes: 3 additions & 3 deletions pandas/_libs/join.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ from numpy cimport (ndarray,
cnp.import_array()


cdef double NaN = <double>np.NaN
cdef double nan = NaN
cdef float64_t NaN = <float64_t>np.NaN
cdef float64_t nan = NaN

from pandas._libs.algos import groupsort_indexer, ensure_platform_int
from pandas.core.algorithms import take_nd
Expand Down Expand Up @@ -673,7 +673,7 @@ ctypedef fused asof_t:
int32_t
int64_t
float
double
float64_t

ctypedef fused by_t:
object
Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ cdef extern from "numpy/arrayobject.h":


cdef extern from "src/parse_helper.h":
int floatify(object, double *result, int *maybe_int) except -1
int floatify(object, float64_t *result, int *maybe_int) except -1

cimport util
from util cimport (is_nan,
Expand All @@ -71,7 +71,7 @@ cdef int64_t NPY_NAT = util.get_nat()
iNaT = util.get_nat()

cdef bint PY2 = sys.version_info[0] == 2
cdef double nan = <double>np.NaN
cdef float64_t nan = <float64_t>np.NaN


def values_from_object(obj: object):
Expand Down
6 changes: 3 additions & 3 deletions pandas/_libs/missing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ from cython import Py_ssize_t

import numpy as np
cimport numpy as cnp
from numpy cimport ndarray, int64_t, uint8_t
from numpy cimport ndarray, int64_t, uint8_t, float64_t
cnp.import_array()

cimport util

from tslibs.np_datetime cimport get_timedelta64_value, get_datetime64_value
from tslibs.nattype import NaT

cdef double INF = <double>np.inf
cdef double NEGINF = -INF
cdef float64_t INF = <float64_t>np.inf
cdef float64_t NEGINF = -INF

cdef int64_t NPY_NAT = util.get_nat()

Expand Down
36 changes: 18 additions & 18 deletions pandas/_libs/parsers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ CParserError = ParserError

cdef bint PY3 = (sys.version_info[0] >= 3)

cdef double INF = <double>np.inf
cdef double NEGINF = -INF
cdef float64_t INF = <float64_t>np.inf
cdef float64_t NEGINF = -INF


cdef extern from "errno.h":
Expand Down Expand Up @@ -182,10 +182,10 @@ cdef extern from "parser/tokenizer.h":
int64_t skip_first_N_rows
int64_t skipfooter
# pick one, depending on whether the converter requires GIL
double (*double_converter_nogil)(const char *, char **,
char, char, char, int) nogil
double (*double_converter_withgil)(const char *, char **,
char, char, char, int)
float64_t (*double_converter_nogil)(const char *, char **,
char, char, char, int) nogil
float64_t (*double_converter_withgil)(const char *, char **,
char, char, char, int)

# error handling
char *warn_msg
Expand Down Expand Up @@ -233,12 +233,12 @@ cdef extern from "parser/tokenizer.h":
uint64_t str_to_uint64(uint_state *state, char *p_item, int64_t int_max,
uint64_t uint_max, int *error, char tsep) nogil

double xstrtod(const char *p, char **q, char decimal, char sci,
char tsep, int skip_trailing) nogil
double precise_xstrtod(const char *p, char **q, char decimal, char sci,
char tsep, int skip_trailing) nogil
double round_trip(const char *p, char **q, char decimal, char sci,
float64_t xstrtod(const char *p, char **q, char decimal, char sci,
char tsep, int skip_trailing) nogil
float64_t precise_xstrtod(const char *p, char **q, char decimal, char sci,
char tsep, int skip_trailing) nogil
float64_t round_trip(const char *p, char **q, char decimal, char sci,
char tsep, int skip_trailing) nogil

int to_boolean(const char *item, uint8_t *val) nogil

Expand Down Expand Up @@ -1697,16 +1697,16 @@ cdef _try_double(parser_t *parser, int64_t col,
coliter_t it
const char *word = NULL
char *p_end
double *data
double NA = na_values[np.float64]
float64_t *data
float64_t NA = na_values[np.float64]
kh_float64_t *na_fset
ndarray result
khiter_t k
bint use_na_flist = len(na_flist) > 0

lines = line_end - line_start
result = np.empty(lines, dtype=np.float64)
data = <double *>result.data
data = <float64_t *>result.data
na_fset = kset_float64_from_list(na_flist)
if parser.double_converter_nogil != NULL: # if it can run without the GIL
with nogil:
Expand All @@ -1717,8 +1717,8 @@ cdef _try_double(parser_t *parser, int64_t col,
else:
assert parser.double_converter_withgil != NULL
error = _try_double_nogil(parser,
<double (*)(const char *, char **,
char, char, char, int)
<float64_t (*)(const char *, char **,
char, char, char, int)
nogil>parser.double_converter_withgil,
col, line_start, line_end,
na_filter, na_hashset, use_na_flist,
Expand All @@ -1730,14 +1730,14 @@ cdef _try_double(parser_t *parser, int64_t col,


cdef inline int _try_double_nogil(parser_t *parser,
double (*double_converter)(
float64_t (*double_converter)(
const char *, char **, char,
char, char, int) nogil,
int col, int line_start, int line_end,
bint na_filter, kh_str_t *na_hashset,
bint use_na_flist,
const kh_float64_t *na_flist,
double NA, double *data,
float64_t NA, float64_t *data,
int *na_count) nogil:
cdef:
int error,
Expand Down
Loading
0