-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
127 additions
and
41 deletions.
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 @@ | ||
static PyObject * | ||
example_wrapper(PyObject *dummy, PyObject *args) | ||
{ | ||
PyObject *arg1=NULL, *arg2=NULL, *out=NULL; | ||
PyObject *arr1=NULL, *arr2=NULL, *oarr=NULL; | ||
|
||
if (!PyArg_ParseTuple(args, "OOO!", &arg1, &arg2, | ||
&PyArray_Type, &out)) return NULL; | ||
|
||
arr1 = PyArray_FROM_OTF(arg1, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY); | ||
if (arr1 == NULL) return NULL; | ||
arr2 = PyArray_FROM_OTF(arg2, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY); | ||
if (arr2 == NULL) goto fail; | ||
#if NPY_API_VERSION >= 0x0000000c | ||
oarr = PyArray_FROM_OTF(out, NPY_DOUBLE, NPY_ARRAY_INOUT_ARRAY2); | ||
#else | ||
oarr = PyArray_FROM_OTF(out, NPY_DOUBLE, NPY_ARRAY_INOUT_ARRAY); | ||
#endif | ||
if (oarr == NULL) goto fail; | ||
|
||
/* code that makes use of arguments */ | ||
/* You will probably need at least | ||
nd = PyArray_NDIM(<..>) -- number of dimensions | ||
dims = PyArray_DIMS(<..>) -- npy_intp array of length nd | ||
showing length in each dim. | ||
dptr = (double *)PyArray_DATA(<..>) -- pointer to data. | ||
If an error occurs goto fail. | ||
*/ | ||
|
||
Py_DECREF(arr1); | ||
Py_DECREF(arr2); | ||
#if NPY_API_VERSION >= 0x0000000c | ||
PyArray_ResolveWritebackIfCopy(oarr); | ||
#endif | ||
Py_DECREF(oarr); | ||
Py_INCREF(Py_None); | ||
return Py_None; | ||
|
||
fail: | ||
Py_XDECREF(arr1); | ||
Py_XDECREF(arr2); | ||
#if NPY_API_VERSION >= 0x0000000c | ||
PyArray_DiscardWritebackIfCopy(oarr); | ||
#endif | ||
Py_XDECREF(oarr); | ||
return NULL; | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import numpy as np | ||
|
||
from npstructures.raggedshape import native_extract_segments, c_extract_segments, RaggedView2 | ||
from time import time | ||
data_size = 100000000 | ||
data = np.empty(data_size, dtype=np.uint8) | ||
segment_size = 100 | ||
n_segments = data_size//(segment_size*2) | ||
starts = np.arange(n_segments)*(segment_size*2) | ||
lens = np.full(n_segments, segment_size) | ||
view = RaggedView2(starts, lens, 1) | ||
to_shape = view.get_shape() | ||
print('-----------------------') | ||
t = time() | ||
native_extract_segments(data, view, to_shape, 1) | ||
print('native_extract_segments', time()-t) | ||
t = time() | ||
c_extract_segments(data, view, to_shape, 1) | ||
print('c_extract_segments', time()-t) | ||
print('-----------------------') | ||
|
||
|
||
|
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
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