-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
simplify skiplist inclusion/cimport to be more cythonize-friendly #18420
Merged
+68
−45
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d0dbe93
simplify skiplist inclusion/cimport to be more cythonize-friendly
jbrockmendel 1e80126
restore signbit as it broke on appveyor
jbrockmendel 35c87b7
Merge branch 'master' of https://github.com/pandas-dev/pandas into pr…
jbrockmendel 0fde045
make skiplist a standalone extension
jbrockmendel 64d5482
revert sqrt to use nogil version
jbrockmendel 81b1762
Merge branch 'master' of https://github.com/pandas-dev/pandas into pr…
jbrockmendel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# -*- coding: utf-8 -*- | ||
# cython: profile=False | ||
|
||
from cython cimport Py_ssize_t | ||
|
||
from numpy cimport double_t | ||
|
||
|
||
cdef extern from "src/skiplist.h": | ||
ctypedef struct node_t: | ||
node_t **next | ||
int *width | ||
double value | ||
int is_nil | ||
int levels | ||
int ref_count | ||
|
||
ctypedef struct skiplist_t: | ||
node_t *head | ||
node_t **tmp_chain | ||
int *tmp_steps | ||
int size | ||
int maxlevels | ||
|
||
skiplist_t* skiplist_init(int) nogil | ||
void skiplist_destroy(skiplist_t*) nogil | ||
double skiplist_get(skiplist_t*, int, int*) nogil | ||
int skiplist_insert(skiplist_t*, double) nogil | ||
int skiplist_remove(skiplist_t*, double) nogil | ||
|
||
|
||
# Note: Node is declared here so that IndexableSkiplist can be exposed; | ||
# Node itself not intended to be exposed. | ||
cdef class Node: | ||
cdef public: | ||
double_t value | ||
list next | ||
list width | ||
|
||
|
||
cdef class IndexableSkiplist: | ||
cdef: | ||
Py_ssize_t size, maxlevels | ||
Node head | ||
|
||
cpdef get(self, Py_ssize_t i) | ||
cpdef insert(self, double value) | ||
cpdef remove(self, double value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,7 @@ | |
|
||
# Cython version: Wes McKinney | ||
|
||
cdef extern from "math.h": | ||
double log(double x) | ||
from libc.math cimport log | ||
|
||
# MSVC does not have log2! | ||
|
||
|
@@ -16,6 +15,7 @@ cdef double Log2(double x): | |
|
||
cimport numpy as np | ||
import numpy as np | ||
from numpy cimport double_t | ||
|
||
from random import random | ||
|
||
|
@@ -25,10 +25,10 @@ np.import_array() | |
# TODO: optimize this, make less messy | ||
|
||
cdef class Node: | ||
cdef public: | ||
double_t value | ||
list next | ||
list width | ||
# cdef public: | ||
# double_t value | ||
# list next | ||
# list width | ||
|
||
def __init__(self, double_t value, list next, list width): | ||
self.value = value | ||
|
@@ -43,9 +43,9 @@ cdef class IndexableSkiplist: | |
Sorted collection supporting O(lg n) insertion, removal, and | ||
lookup by rank. | ||
""" | ||
cdef: | ||
Py_ssize_t size, maxlevels | ||
Node head | ||
# cdef: | ||
# Py_ssize_t size, maxlevels | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
# Node head | ||
|
||
def __init__(self, expected_size=100): | ||
self.size = 0 | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why are you commenting these out? just to show what the structure is? I would remove this
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.
aren't you supposed to declare the member variables in the .pyx, and not the .pxd?
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.
AFAICT the rule is that if the class is declared in the .pxd, the member variables need to be declared there (and only there)
I leave these in place so we don't have to go back and check the pxd