88
88
"""
89
89
90
90
91
- take_1d_template = """
92
- @cython.wraparound(False)
93
- @cython.boundscheck(False)
94
- def take_1d_%(name)s_%(dest)s(%(c_type_in)s[:] values,
95
- int64_t[:] indexer,
96
- %(c_type_out)s[:] out,
97
- fill_value=np.nan):
91
+ inner_take_1d_template = """\
98
92
cdef:
99
93
Py_ssize_t i, n, idx
100
94
%(c_type_out)s fv
@@ -112,6 +106,33 @@ def take_1d_%(name)s_%(dest)s(%(c_type_in)s[:] values,
112
106
%(tab)s out[i] = %(preval)svalues[idx]%(postval)s
113
107
"""
114
108
109
+ take_1d_template = """\
110
+ @cython.wraparound(False)
111
+ @cython.boundscheck(False)
112
+ cdef inline take_1d_%(name)s_%(dest)s_memview(%(c_type_in)s[:] values,
113
+ int64_t[:] indexer,
114
+ %(c_type_out)s[:] out,
115
+ fill_value=np.nan):
116
+ """ + inner_take_1d_template + """
117
+
118
+ @cython.wraparound(False)
119
+ @cython.boundscheck(False)
120
+ def take_1d_%(name)s_%(dest)s(ndarray[%(c_type_in)s, ndim=1] values,
121
+ int64_t[:] indexer,
122
+ %(c_type_out)s[:] out,
123
+ fill_value=np.nan):
124
+
125
+ if values.flags.writeable:
126
+ # We can call the memoryview version of the code
127
+ take_1d_%(name)s_%(dest)s_memview(values, indexer, out,
128
+ fill_value=fill_value)
129
+ return
130
+
131
+ # We cannot use the memoryview version on readonly-buffers due to
132
+ # a limitation of Cython's typed memoryviews. Instead we can use
133
+ # the slightly slower Cython ndarray type directly.
134
+ """ + inner_take_1d_template
135
+
115
136
inner_take_2d_axis0_template = """\
116
137
cdef:
117
138
Py_ssize_t i, j, k, n, idx
0 commit comments