<div class="gmail_quote">On Thu, May 10, 2012 at 5:27 PM, Dag Sverre Seljebotn <span dir="ltr"><<a href="mailto:d.s.seljebotn@astro.uio.no" target="_blank">d.s.seljebotn@astro.uio.no</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 05/10/2012 08:23 PM, Chris Barker wrote:<br>
> On Thu, May 10, 2012 at 2:38 AM, Dag Sverre Seljebotn<br>
> <<a href="mailto:d.s.seljebotn@astro.uio.no">d.s.seljebotn@astro.uio.no</a>>  wrote:<br>
>> What would serve me? I use NumPy as a glorified "double*".<br>
><br>
>> all I want is my glorified<br>
>> "double*". I'm probably not a representative user.)<br>
><br>
> Actually, I think you are representative of a LOT of users -- it<br>
> turns, out, whether Jim Huginin originally was thinking this way or<br>
> not, but numpy arrays are really powerful because the provide BOTH and<br>
> nifty, full featured array object in Python, AND a wrapper around a<br>
> generic "double*" (actually char*, that could be any type).<br>
><br>
> This is are really widely used feature, and has become even more so<br>
> with Cython's numpy support.<br>
><br>
> That is one of my concerns about the "bit pattern" idea -- we've then<br>
> created a new binary type that no other standard software understands<br>
> -- that looks like a a lot of work to me to deal with, or even worse,<br>
> ripe for weird, non-obvious errors in code that access that good-old<br>
> char*.<br>
><br>
> So I'm happier with a mask implementation -- more memory, yes, but it<br>
> seems more robust an easy to deal with with outside code.<br>
<br>
</div>It's very interesting that you consider masks easier to integrate with<br>
C/C++ code than bitpatterns. I guess everybody's experience (and every<br>
C/C++/Fortran code base) is different.<br>
<div class="im"><br>
><br>
> But either way, Dag's key point is right on -- in Cython (or any other<br>
> code) -- we need to make sure ti's easy to get a regular old pointer<br>
> to a regular old C array, and get something else by accident.<br>
<br>
</div>I'm sorry if I caused any confusion -- I didn't mean to suggest that<br>
anybody would ever remove the ability of getting a pointer to an<br>
unmasked array.<br>
<br>
There is a problem that's being discussed of the opposite nature:<br>
<br>
With masked arrays, the current situation in NumPy trunk is that if<br>
you're presented with a masked array, and do not explicitly check for a<br>
mask (i.e., all existing code), you'll transparently and without warning<br>
"unmask" it -- that is, an element has the last value before NA was<br>
assigned. This is the case whether you use PEP 3118 (np.ndarray[double]<br>
or double[:]), or PyArray_DATA.<br>
<br>
According to the NEP, you should really get an exception when accessing<br>
through PEP 3118, but this seems to not be implemented. I don't know<br>
whether this was a conscious change or a lack of implementation (?).<br></blockquote><div><br></div><div>This was an error, I've made a pull request to fix it.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

PyArray_DATA will continue to transparently unmask data. However, with<br>
Travis' proposal of making a new 'ndmasked' type, old code will be<br>
protected; it will raise an exception for masked arrays instead of<br>
transparently unmasking, giving the user a chance to work around it (or<br>
update the code to work with masks).<br></blockquote><div><br></div><div>In searching for example code, the examples I found and the numpy documentation recommend using the PyArray_FromAny or related functions to sanitize the array before use. This provides a place to stop NA-masked arrays and raise an exception. Is there a lot of code out there which isn't following this practice?</div>
<div><br></div><div>Cheers,</div><div>Mark</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Regarding new code that you write to be mask-aware, fear not -- you can<br>
use PyArray_DATA and PyArray_MASKNA_DATA to get the pointers. You can't<br>
really access the mask using np.ndarray[uint8] or uint8[:], but it<br>
wouldn't be a problem for NumPy to provide such access for Cython users.<br>
<br>
Regarding native Cython support for masks, bitpatterns would be a quick<br>
job and an uncontroversial feature, we just need to agree on an<br>
extension to the PEP 3118 format string with NumPy and then it takes a<br>
few hours to implement it. Masks would require quite some hashing out on<br>
the Cython email list to figure out whether and how we would want to<br>
support it, and is quite some more development work as well. How we'd<br>
even do that is much more vague to me.<br>
<span class="HOEnZb"><font color="#888888"><br>
Dag<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
</div></div></blockquote></div><br>