[Cython] Bug Report: can't assign zero length array to contiguous 2D memoryview
Assigning a NumPy array with a zero length dimension to a memoryview fails if the memoryview is declared contiguous in the zero-length dimension. I'm getting a run-time error that the buffer is not C-contiguous or Fortran contiguous. See examples below. Thanks, Josh Ayers cdef float [:, :] arr1 = numpy.empty((2, 0), 'f4') # works cdef float [:, :] arr2 = numpy.empty((0, 2), 'f4') # works cdef float [:, ::1] arr3 = numpy.empty((2, 0), 'f4') # fails (buffer not C-contiguous) cdef float [:, ::1] arr4 = numpy.empty((0, 2), 'f4') # works cdef float [:, :] arr5 = numpy.empty((2, 0), 'f4', order='F') # works cdef float [:, :] arr6 = numpy.empty((0, 2), 'f4', order='F') # works cdef float [::1, :] arr7 = numpy.empty((2, 0), 'f4', order='F') # works cdef float [::1, :] arr8 = numpy.empty((0, 2), 'f4', order='F') # fails (buffer not Fortran contiguous) ___ cython-devel mailing list cython-devel@python.org https://mail.python.org/mailman/listinfo/cython-devel
[Cython] PyUnicode_Tailmatch
Cython devs, In the function __Pyx_PyUnicode_Tailmatch, the return type of PyUnicode_Tailmatch is assumed to be in int. See line 543 of Cython/Utility/StringTools.c. PyUnicode_Tailmatch actually returns a Py_ssize_t. See: https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_Tailmatch. For reference, there was previously an error in the Python documentation of this function. The documentation mistakenly said it returned an int. This was fixed via Python issue 22580: https://bugs.python.org/issue22580. Thanks, Josh Ayers ___ cython-devel mailing list cython-devel@python.org https://mail.python.org/mailman/listinfo/cython-devel
[Cython] Cython 0.23.3 compiler warning with fused types
Cython devs, Using Cython 0.23.3 and Python 3.4.3, the following Cython code: ctypedef fused floating: float double cpdef add_one(floating [:] array): cdef Py_ssize_t i for i in range(array.shape[0]): array[i] += 1.0 produces the C code below. It raises a compiler warning because a long is assigned to a char. char __pyx_v_kind; ... long __pyx_t_11; ... __pyx_t_11 = __Pyx_PyObject_Ord(__pyx_t_8); ... __pyx_v_kind = __pyx_t_11; Thanks, Josh Ayers ___ cython-devel mailing list cython-devel@python.org https://mail.python.org/mailman/listinfo/cython-devel
Re: [Cython] can we deprecate for-from loops?
When the step size is a variable, the range statement falls back to a Python for loop since the direction of the loop is unknown. The "i from a <= i < b by c" syntax specifies the direction, so it is turned into a C for loop. The difference is performance could be substantial. This produces a Python for loop: def python_loop(Py_ssize_t a, Py_ssize_t b, Py_ssize_t c): cdef Py_ssize_t i for i in range(a, b, c): pass This produces a C for loop: def c_loop(Py_ssize_t a, Py_ssize_t b, Py_ssize_t c): cdef Py_ssize_t i for i from a <= i < b by c: pass On Mon, Oct 12, 2015, at 08:37 AM, Robert Bradshaw wrote: > On Sun, Oct 11, 2015 at 3:31 PM, Greg Ewing > wrote: > > Stefan Behnel wrote: > >> > >> Hi! > >> > >> The syntax construct "for i from 0 <= i < 10" has been silently outdated > >> for years. Can we start issuing a warning that normal range() loops are > >> preferred? > > > > > > I'd be in favour of replacing it with just 'for 0 <= i < 10', > > but -1 on removing it altogether. > > > > I introduced it in Pyrex for a reason -- to clearly express > > iterations over ranges of integers with arbitrary combinations > > of open/closed endpoints, > > I agree that it expresses intent clearer than the range(...) construct. > > > for use in conjunction with C code. > > I believe that reason is still valid. > > I'm not sure why "in conjunction with C code" makes any difference to > the argument, now that the basic range loop produces the same code in > Cython. Put another way, does its clarity merit a PEP to introduce > this syntax into Python? If not, it's hard to justify in Cython given > that it is a fully redundant addition to the language. > > - Robert > ___ > cython-devel mailing list > cython-devel@python.org > https://mail.python.org/mailman/listinfo/cython-devel ___ cython-devel mailing list cython-devel@python.org https://mail.python.org/mailman/listinfo/cython-devel