Comments (5)
I don't think it makes any difference - the assignment further up the loop takes care of the reference counting either way. Unless you're doing if y is None
or possibly if y
then I think it should all be largely the same.
I don't see why it should make any difference to the "grab array pointers" code either.
from cython.
I can reproduce that warning (although testing it on scipy's code is the first time I've seen it).
I think it's a false positive. The internal code in question:
static CYTHON_INLINE void __Pyx_XCLEAR_MEMVIEW(__Pyx_memviewslice *memslice,
int have_gil, int lineno) {
__pyx_nonatomic_int_type old_acquisition_count;
struct __pyx_memoryview_obj *memview = memslice->memview;
if (unlikely(!memview || (PyObject *) memview == Py_None)) {
memslice->memview = NULL;
return;
}
old_acquisition_count = __pyx_sub_acquisition_count(memview);
So I think it's detected that memslice->memview
points to a _Py_NoneStruct
object, and hasn't realized that None
is a singleton so the memview == Py_None
prevents __pyx_sub_acquisition_count
from ever being run in that case.
In Cython <3 the reference counting was slightly more indirect the compiler probably couldn't work as much out.
If I comment out y = None
at the end of the loop then the warning goes away.
It'd definitely be good if Cython could avoid generating this warning. We could possibly do so just by not inlining __Pyx_XCLEAR_MEMVIEW
but that might have its own performance costs (or gains...). I can't think of too many other things we could do.
If we accept my belief that it's a false positive, then I think Scipy can safely ignore it for now. I just haven't quite convinced myself I'm completely sure I'm right yet.
from cython.
We could possibly do so just by not inlining
__Pyx_XCLEAR_MEMVIEW
but that might have its own performance costs (or gains...). I can't think of too many other things we could do.
Confirmed that this does make the warning go away. Still not sure if we want to do it though.
from cython.
Thanks for having a look @da-woods.
If I comment out
y = None
at the end of the loop then the warning goes away.
That y = None
line doesn't seem to do much, it was probably just added as a safety measure. But looks like it can be deleted. So no warnings from Cython is always good, but the decision here shouldn't matter to SciPy.
from cython.
Hmm, not 100% of that "can be deleted". The code generated for it is:
__pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_dc_double(Py_None, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 184, __pyx_L1_error)
__PYX_XCLEAR_MEMVIEW(&__pyx_v_y, 1);
__pyx_v_y = __pyx_t_8;
__pyx_t_8.memview = NULL;
__pyx_t_8.data = NULL;
}
Which may be needed for bookkeeping. However, for the y = xs[ip]
line higher up in the for-loop we see the same pattern:
* y = xs[ip] # <<<<<<<<<<<<<<
if (unlikely(__pyx_v_xs == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(0, 174, __pyx_L1_error)
}
__pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_dc_double(PyTuple_GET_ITEM(__pyx_v_xs, __pyx_v_ip), PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 174, __pyx_L1_error)
__PYX_XCLEAR_MEMVIEW(&__pyx_v_y, 1);
__pyx_v_y = __pyx_t_8;
__pyx_t_8.memview = NULL;
__pyx_t_8.data = NULL;
It's not clear to me if this line makes any difference or Cython gives any kind of guarantee for this code:
# grab array pointers
nxx[ip] = y.shape[0]
xx[ip] = <double*>&y[0]
y = None
from cython.
Related Issues (20)
- [BUG] Segfault when __dealloc__ calls a non-existent method. HOT 2
- [BUG] Segfault when passing None to `cdef` method.
- [BUG] Cython inserts a call to PyMemoryView_CheckExact() which is not present in CPython API HOT 1
- Notes on "tuple table" HOT 4
- [BUG] Incompatible pointer in inlined method of derived class HOT 2
- Document and improve generation of C lines in traceback HOT 9
- [BUG] Fused type in init yields broken C program
- [BUG] `.so` file size too large? HOT 10
- [ENH] Reduce the code size of the memory view implementation HOT 2
- [BUG] cimporting from a pxd with memoryviews injects memoryview utility code
- [BUG] Complex function argument lists causing MSVC to fail HOT 10
- [BUG] Enabling limited API attempts to take the size of an opaque object HOT 11
- [ENH] Conditional Compilation HOT 2
- Migrating notes on Cython wrappers from SciPy wiki
- PyUnicode_AsUnicode missing Error with Python 3.12 on Windows HOT 5
- Use `Py_IncRef()` and `Py_DecRef()` in Limited API
- [BUG] Access violation using cython.ufunc with cimport numpy HOT 3
- [BUG] Regression in cython 3.0.9 HOT 3
- [BUG] Can not do logic with `char *` ? HOT 2
- [BUG] Compiler crash using ufunc with multiple, fused return types HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cython.