-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Bugfix for broken tofile/fromfile and save/load in Mac OS X Issue #2806 #2931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This still needs the changes pointed out by @pv and me here: #2806 (comment) |
Hi, I have now implemented the changes pointed out by @pv and @njsmith. Have a look. The unit test added by 2e8a123 detects another issue with savez, though:
If I understand correctly, this is a separate problem related to reading from # This is not a real file. We have to read it the memory-intensive
# way.
# XXX: we can probably chunk this to avoid the memory hit.
data = fp.read(int(count * dtype.itemsize))
array = numpy.fromstring(data, dtype=dtype, count=count) shall I go on and do this chunking then? any ideas on how to relate the chunking constant between |
Okay, this seems to have broken travis build due to multiple declarations of the functions due to multiple imports of Can anyone give me a hint where the imports/code should go to avoid this? |
Alright, I have now moved the functions to where they should be and the travis build passes again. |
if (n2 < chunksize) { | ||
break; | ||
} | ||
n += n2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt it matters (but for the error reporting maybe), but conceptually shouldn't the break be after the addition? (same in the fwrite function)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quoting GNU libc manual: """If `fread' encounters end of file in the middle of an object, it returns the number of complete objects read, and discards the partial object.""" So it should indeed be after the addition. (EDIT: oops, edited.)
Anyway, looks nice to my C knowledge. Just a bit unsure about the tests. They use quite large intermediates, etc. so I think they may need some error handling for devices with little RAM or harddrive space? Or do we assume that "slow" tests are fine in this regard as they are not normally run? |
Sorry, accidental button press... |
Tests requiring that much memory may cause problems for people running them on machines with less physical memory -> may grind the whole machine to a halt due to the use of swap. I'd prefer adding a new decorator |
Yeah, is it possible to have this inside nose in a way that it doesn't get run accidentally, i.e. with |
Prediction: manual run test files = will not be run + bitrot. I don't see a problem in adding more nose test labels, those would then be available also for other projects using numpy.testing. |
Really I think the only long-run solution is going to be to use decorators units are gibibytes@needs(mem=4, disk=4) It's easy to extend nose to add new command line options and test filters:
|
Hi all, thanks for the input. I will let you guys decide on the unit test issues. Maybe it is worth creating a single integration/performance test that would try to push the system up to its maximum limit (>32bit) and use it to spot potential failures instead? |
I guess the immediate issue is what to do with the tests in this PR. Do I understand correctly that the tests in the PR currently allocate and write to disk arrays with 2,400,000,000 bytes? How long do these tests take to run? (It looks like Travis is set to run tests in 'fast' mode, so it's skipping these tests and I can't tell from that.) It's not reasonable to have only a few tests that use large arrays, because the usual bugs in handling large arrays are things that you can't avoid by localizing them to a particular place -- every C function that handles array indices is another potential bug. And it's entirely possible to run a large set of large-array tests with a little preparation (though it might require a machine with >8 GB RAM and the use of a ram-disk). The question is just, which tests require how much preparation, and how do we prevent people from accidentally running tests that will take multiple hours and trigger the OOM killer -- and for right now, the question is, where do these particular tests fall on that spectrum. |
It is not that slow on my Machine (16GB ram, SSD), the full test suite runs in two minutes. |
@njsmith Do the Travis bots have memory limits in the virtual environments. |
I don't know how much memory is in those VMs, let's see: #3109 On Sat, Mar 2, 2013 at 2:42 AM, Charles Harris [email protected]:
|
It looks like the travis VMs have 3 GB of accessible memory, 1.5 GB of
|
@@ -1,3 +1,5 @@ | |||
#include <numpy/npy_common.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong place for include, it should go after the guard. In fact, I'm not sure why the include is here at all.
This seems somewhat related to #2942, so it may be desirable to make the chunksize smaller. It looks like 256MB was the optimum size. |
#define NUMPYOS_FREAD_THRESHOLD 33554432 | ||
#define NUMPYOS_FWRITE_THRESHOLD 33554432 | ||
/* A general workaround of OS issues with fread/fwrite, see issue #2806 */ | ||
NPY_NO_EXPORT size_t NumPyOS_fread( void * ptr, size_t size, size_t count, FILE * stream ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function name on next line.
I'd like to get this in, but it needs some fixes. Anyone have an idea how to implement a test decorator? Is there a python function that will return the amount of usable memory? There doesn't seem to be a package in the Python standard library that does what is needed. Maybe just try to allocate a large array and catch a memory error? I'm curious if this MAC problem also affects memmap? |
Allocating a large array won't in general let you determine the amount of That said, we could use the psutil library, or some simple hacks that
|
On Tue, Jul 9, 2013 at 9:36 AM, njsmith [email protected] wrote:
The psutils library looks small, but is broken down by platform rather than Chuck |
For this, I could actually see skipping a test if it can't be reasonably implemented. It's a workaround for a MAC deficiency. Of course, it would be nice to know that it still works on other platforms... |
@sauliusl 1.8 branch coming up this Sunday, Aug 18. |
@sauliusl Are you still working with this? |
Not really, no. Though from last time the patch was working, the pull On Mon, Feb 17, 2014 at 6:50 PM, Charles Harris [email protected]:
|
Let's skip the unit test here, I do think the blocking could be smaller however. Do you know if this bug, Apple ID# 6434977, has been fixed? |
Oh, and if you pursue this, add a note in |
as NumPyOS_fwrite to unify the fwrites. Also made multiarray/ctors.c and multiarray/convert.c to use these new functions. see discussion in issue numpy#2806
…npy_os.h. This is where it was meant to go in the first place, I just misunderstood @pv.
NumPyOS_fread/NumPyOs_fwrite as pointed out by @seberg Also changed the comment style to be consistent with the rest of numpy.
Hm, I cannot reproduce the bug any more on OSX 10.9.1 (Mavericks).
Not sure how to proceed with this now. Do we still want this in core? |
Apparently it broke in Lion, but perhaps it was silently failing in earlier versions. I don't know if it got fixed in later Lion releases. I haven't seen any recent error messages about this, so, one possibility is to just let it go, with a recommendation to upgrade the OS. I know old hardware can't take that route, but... |
I can check this on OS X 10.6 if you want. Did you check there's no overlap with gh-4214? |
Closing. The fix is to upgrade to Mavericks. |
I have hacked around a fix for the issue where large matrices were not read from memory correctly (issue #2806). I have been using this branch personally ever since it was created and did not notice any problems with it, therefore I am confident in sending a pull request.
This might need a bit of refactoring to fit the rest of the code cleaner, though.
Please see #2806 for more discussion on this.