Commit 3ee6f872 authored by Stefan Behnel's avatar Stefan Behnel

clean up utility code a bit

parent 0c46b7d2
////////// MemviewSliceStruct.proto ////////// ////////// MemviewSliceStruct.proto //////////
/* memoryview slice struct */ /* memoryview slice struct */
struct {{memview_struct_name}}; struct {{memview_struct_name}};
typedef struct { typedef struct {
...@@ -13,7 +11,9 @@ typedef struct { ...@@ -13,7 +11,9 @@ typedef struct {
Py_ssize_t suboffsets[{{max_dims}}]; Py_ssize_t suboffsets[{{max_dims}}];
} {{memviewslice_name}}; } {{memviewslice_name}};
/////////// Atomics.proto ///////////// /////////// Atomics.proto /////////////
#include <pythread.h> #include <pythread.h>
#ifndef CYTHON_ATOMICS #ifndef CYTHON_ATOMICS
...@@ -21,8 +21,8 @@ typedef struct { ...@@ -21,8 +21,8 @@ typedef struct {
#endif #endif
#define __pyx_atomic_int_type int #define __pyx_atomic_int_type int
/* todo: Portland pgcc, maybe OS X's OSAtomicIncrement32, // todo: Portland pgcc, maybe OS X's OSAtomicIncrement32,
libatomic + autotools-like distutils support? Such a pain... */ // libatomic + autotools-like distutils support? Such a pain...
#if CYTHON_ATOMICS && __GNUC__ >= 4 && (__GNUC_MINOR__ > 1 || \ #if CYTHON_ATOMICS && __GNUC__ >= 4 && (__GNUC_MINOR__ > 1 || \
(__GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL >= 2)) && \ (__GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL >= 2)) && \
!defined(__i386__) !defined(__i386__)
...@@ -73,9 +73,12 @@ typedef volatile __pyx_atomic_int_type __pyx_atomic_int; ...@@ -73,9 +73,12 @@ typedef volatile __pyx_atomic_int_type __pyx_atomic_int;
__pyx_sub_acquisition_count_locked(__pyx_get_slice_count_pointer(memview), memview->lock) __pyx_sub_acquisition_count_locked(__pyx_get_slice_count_pointer(memview), memview->lock)
#endif #endif
/////////////// ObjectToMemviewSlice.proto /////////////// /////////////// ObjectToMemviewSlice.proto ///////////////
static CYTHON_INLINE {{memviewslice_name}} {{funcname}}(PyObject *); static CYTHON_INLINE {{memviewslice_name}} {{funcname}}(PyObject *);
////////// MemviewSliceInit.proto ////////// ////////// MemviewSliceInit.proto //////////
#define __Pyx_BUF_MAX_NDIMS %(BUF_MAX_NDIMS)d #define __Pyx_BUF_MAX_NDIMS %(BUF_MAX_NDIMS)d
...@@ -117,9 +120,13 @@ static CYTHON_INLINE int __pyx_sub_acquisition_count_locked( ...@@ -117,9 +120,13 @@ static CYTHON_INLINE int __pyx_sub_acquisition_count_locked(
#define __PYX_XDEC_MEMVIEW(slice, have_gil) __Pyx_XDEC_MEMVIEW(slice, have_gil, __LINE__) #define __PYX_XDEC_MEMVIEW(slice, have_gil) __Pyx_XDEC_MEMVIEW(slice, have_gil, __LINE__)
static CYTHON_INLINE void __Pyx_INC_MEMVIEW({{memviewslice_name}} *, int, int); static CYTHON_INLINE void __Pyx_INC_MEMVIEW({{memviewslice_name}} *, int, int);
static CYTHON_INLINE void __Pyx_XDEC_MEMVIEW({{memviewslice_name}} *, int, int); static CYTHON_INLINE void __Pyx_XDEC_MEMVIEW({{memviewslice_name}} *, int, int);
/////////////// MemviewSliceIndex.proto /////////////// /////////////// MemviewSliceIndex.proto ///////////////
static CYTHON_INLINE char *__pyx_memviewslice_index_full( static CYTHON_INLINE char *__pyx_memviewslice_index_full(
const char *bufp, Py_ssize_t idx, Py_ssize_t stride, Py_ssize_t suboffset); const char *bufp, Py_ssize_t idx, Py_ssize_t stride, Py_ssize_t suboffset);
/////////////// ObjectToMemviewSlice /////////////// /////////////// ObjectToMemviewSlice ///////////////
...@@ -150,6 +157,7 @@ __pyx_fail: ...@@ -150,6 +157,7 @@ __pyx_fail:
return result; return result;
} }
////////// MemviewSliceInit ////////// ////////// MemviewSliceInit //////////
static int static int
...@@ -520,14 +528,18 @@ static CYTHON_INLINE void __Pyx_XDEC_MEMVIEW({{memviewslice_name}} *memslice, ...@@ -520,14 +528,18 @@ static CYTHON_INLINE void __Pyx_XDEC_MEMVIEW({{memviewslice_name}} *memslice,
} }
} }
////////// MemviewSliceCopyTemplate.proto ////////// ////////// MemviewSliceCopyTemplate.proto //////////
static {{memviewslice_name}} static {{memviewslice_name}}
__pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs, __pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs,
const char *mode, int ndim, const char *mode, int ndim,
size_t sizeof_dtype, int contig_flag, size_t sizeof_dtype, int contig_flag,
int dtype_is_object); int dtype_is_object);
////////// MemviewSliceCopyTemplate ////////// ////////// MemviewSliceCopyTemplate //////////
static {{memviewslice_name}} static {{memviewslice_name}}
__pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs, __pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs,
const char *mode, int ndim, const char *mode, int ndim,
...@@ -606,18 +618,24 @@ no_fail: ...@@ -606,18 +618,24 @@ no_fail:
return new_mvs; return new_mvs;
} }
////////// CopyContentsUtility.proto ///////// ////////// CopyContentsUtility.proto /////////
#define {{func_cname}}(slice) \ #define {{func_cname}}(slice) \
__pyx_memoryview_copy_new_contig(&slice, "{{mode}}", {{ndim}}, \ __pyx_memoryview_copy_new_contig(&slice, "{{mode}}", {{ndim}}, \
sizeof({{dtype_decl}}), {{contig_flag}}, \ sizeof({{dtype_decl}}), {{contig_flag}}, \
{{dtype_is_object}}) {{dtype_is_object}})
////////// OverlappingSlices.proto ////////// ////////// OverlappingSlices.proto //////////
static int __pyx_slices_overlap({{memviewslice_name}} *slice1, static int __pyx_slices_overlap({{memviewslice_name}} *slice1,
{{memviewslice_name}} *slice2, {{memviewslice_name}} *slice2,
int ndim, size_t itemsize); int ndim, size_t itemsize);
////////// OverlappingSlices ////////// ////////// OverlappingSlices //////////
/* Based on numpy's core/src/multiarray/array_assign.c */ /* Based on numpy's core/src/multiarray/array_assign.c */
/* Gets a half-open range [start, end) which contains the array data */ /* Gets a half-open range [start, end) which contains the array data */
...@@ -665,19 +683,27 @@ __pyx_slices_overlap({{memviewslice_name}} *slice1, ...@@ -665,19 +683,27 @@ __pyx_slices_overlap({{memviewslice_name}} *slice1,
return (start1 < end2) && (start2 < end1); return (start1 < end2) && (start2 < end1);
} }
////////// MemviewSliceIsCContig.proto ////////// ////////// MemviewSliceIsCContig.proto //////////
#define __pyx_memviewslice_is_c_contig{{ndim}}(slice) \ #define __pyx_memviewslice_is_c_contig{{ndim}}(slice) \
__pyx_memviewslice_is_contig(&slice, 'C', {{ndim}}) __pyx_memviewslice_is_contig(&slice, 'C', {{ndim}})
////////// MemviewSliceIsFContig.proto ////////// ////////// MemviewSliceIsFContig.proto //////////
#define __pyx_memviewslice_is_f_contig{{ndim}}(slice) \ #define __pyx_memviewslice_is_f_contig{{ndim}}(slice) \
__pyx_memviewslice_is_contig(&slice, 'F', {{ndim}}) __pyx_memviewslice_is_contig(&slice, 'F', {{ndim}})
////////// MemviewSliceIsContig.proto ////////// ////////// MemviewSliceIsContig.proto //////////
static int __pyx_memviewslice_is_contig(const {{memviewslice_name}} *mvs, static int __pyx_memviewslice_is_contig(const {{memviewslice_name}} *mvs,
char order, int ndim); char order, int ndim);
////////// MemviewSliceIsContig ////////// ////////// MemviewSliceIsContig //////////
static int static int
__pyx_memviewslice_is_contig(const {{memviewslice_name}} *mvs, __pyx_memviewslice_is_contig(const {{memviewslice_name}} *mvs,
char order, int ndim) char order, int ndim)
...@@ -704,6 +730,7 @@ __pyx_memviewslice_is_contig(const {{memviewslice_name}} *mvs, ...@@ -704,6 +730,7 @@ __pyx_memviewslice_is_contig(const {{memviewslice_name}} *mvs,
return 1; return 1;
} }
/////////////// MemviewSliceIndex /////////////// /////////////// MemviewSliceIndex ///////////////
static CYTHON_INLINE char * static CYTHON_INLINE char *
...@@ -717,7 +744,9 @@ __pyx_memviewslice_index_full(const char *bufp, Py_ssize_t idx, ...@@ -717,7 +744,9 @@ __pyx_memviewslice_index_full(const char *bufp, Py_ssize_t idx,
return (char *) bufp; return (char *) bufp;
} }
/////////////// MemviewDtypeToObject.proto /////////////// /////////////// MemviewDtypeToObject.proto ///////////////
{{if to_py_function}} {{if to_py_function}}
static PyObject *{{get_function}}(const char *itemp); /* proto */ static PyObject *{{get_function}}(const char *itemp); /* proto */
{{endif}} {{endif}}
...@@ -727,6 +756,7 @@ static int {{set_function}}(const char *itemp, PyObject *obj); /* proto */ ...@@ -727,6 +756,7 @@ static int {{set_function}}(const char *itemp, PyObject *obj); /* proto */
{{endif}} {{endif}}
/////////////// MemviewDtypeToObject /////////////// /////////////// MemviewDtypeToObject ///////////////
{{#__pyx_memview_<dtype_name>_to_object}} {{#__pyx_memview_<dtype_name>_to_object}}
/* Convert a dtype to or from a Python object */ /* Convert a dtype to or from a Python object */
...@@ -747,12 +777,16 @@ static int {{set_function}}(const char *itemp, PyObject *obj) { ...@@ -747,12 +777,16 @@ static int {{set_function}}(const char *itemp, PyObject *obj) {
} }
{{endif}} {{endif}}
/////////////// MemviewObjectToObject.proto /////////////// /////////////// MemviewObjectToObject.proto ///////////////
/* Function callbacks (for memoryview object) for dtype object */ /* Function callbacks (for memoryview object) for dtype object */
static PyObject *{{get_function}}(const char *itemp); /* proto */ static PyObject *{{get_function}}(const char *itemp); /* proto */
static int {{set_function}}(const char *itemp, PyObject *obj); /* proto */ static int {{set_function}}(const char *itemp, PyObject *obj); /* proto */
/////////////// MemviewObjectToObject /////////////// /////////////// MemviewObjectToObject ///////////////
static PyObject *{{get_function}}(const char *itemp) { static PyObject *{{get_function}}(const char *itemp) {
PyObject *result = *(PyObject **) itemp; PyObject *result = *(PyObject **) itemp;
Py_INCREF(result); Py_INCREF(result);
...@@ -767,6 +801,7 @@ static int {{set_function}}(const char *itemp, PyObject *obj) { ...@@ -767,6 +801,7 @@ static int {{set_function}}(const char *itemp, PyObject *obj) {
} }
/////////// ToughSlice ////////// /////////// ToughSlice //////////
/* Dimension is indexed with 'start:stop:step' */ /* Dimension is indexed with 'start:stop:step' */
if (unlikely(__pyx_memoryview_slice_memviewslice( if (unlikely(__pyx_memoryview_slice_memviewslice(
...@@ -786,7 +821,9 @@ if (unlikely(__pyx_memoryview_slice_memviewslice( ...@@ -786,7 +821,9 @@ if (unlikely(__pyx_memoryview_slice_memviewslice(
{{error_goto}} {{error_goto}}
} }
////////// SimpleSlice ////////// ////////// SimpleSlice //////////
/* Dimension is indexed with ':' only */ /* Dimension is indexed with ':' only */
{{dst}}.shape[{{new_ndim}}] = {{src}}.shape[{{dim}}]; {{dst}}.shape[{{new_ndim}}] = {{src}}.shape[{{dim}}];
...@@ -800,9 +837,11 @@ if (unlikely(__pyx_memoryview_slice_memviewslice( ...@@ -800,9 +837,11 @@ if (unlikely(__pyx_memoryview_slice_memviewslice(
{{suboffset_dim}} = {{new_ndim}}; {{suboffset_dim}} = {{new_ndim}};
{{endif}} {{endif}}
////////// SliceIndex ////////// ////////// SliceIndex //////////
/* Dimension is indexed with an integer, we could use the ToughSlice */
/* approach, but this is faster */ // Dimension is indexed with an integer, we could use the ToughSlice
// approach, but this is faster
{ {
Py_ssize_t __pyx_tmp_idx = {{idx}}; Py_ssize_t __pyx_tmp_idx = {{idx}};
...@@ -863,12 +902,15 @@ if (unlikely(__pyx_memoryview_slice_memviewslice( ...@@ -863,12 +902,15 @@ if (unlikely(__pyx_memoryview_slice_memviewslice(
{{endif}} {{endif}}
} }
////////// FillStrided1DScalar.proto ////////// ////////// FillStrided1DScalar.proto //////////
static void static void
__pyx_fill_slice_{{dtype_name}}({{type_decl}} *p, Py_ssize_t extent, Py_ssize_t stride, __pyx_fill_slice_{{dtype_name}}({{type_decl}} *p, Py_ssize_t extent, Py_ssize_t stride,
size_t itemsize, void *itemp); size_t itemsize, void *itemp);
////////// FillStrided1DScalar ////////// ////////// FillStrided1DScalar //////////
/* Fill a slice with a scalar value. The dimension is direct and strided or contiguous */ /* Fill a slice with a scalar value. The dimension is direct and strided or contiguous */
/* This can be used as a callback for the memoryview object to efficienty assign a scalar */ /* This can be used as a callback for the memoryview object to efficienty assign a scalar */
/* Currently unused */ /* Currently unused */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment