|
11 | 11 | import builtins |
12 | 12 | import inspect |
13 | 13 | import math |
| 14 | +import tempfile |
14 | 15 | from collections import OrderedDict, namedtuple |
15 | 16 | from functools import reduce |
16 | 17 | from itertools import product |
@@ -3246,14 +3247,7 @@ def arange_fill(inputs, output, offset): |
3246 | 3247 | # C order is guaranteed, and no reshape is needed |
3247 | 3248 | return lazyarr.compute(**kwargs) |
3248 | 3249 |
|
3249 | | - # In principle, when c_order is False, this would be enough: |
3250 | | - # return reshape(lazyarr, shape, c_order=c_order, **kwargs) |
3251 | | - # so that an intermediate NDArray wouldn't be needed, which is more memory efficient. |
3252 | | - # However, benchmarks show that performance is better with the approach below. |
3253 | | - # Incidentally, not requiring C order can be quite illustrative for the user to |
3254 | | - # understand how the process of computing lazy arrays (and chunking) works. |
3255 | | - larr = lazyarr.compute() # intermediate array |
3256 | | - return reshape(larr, shape, c_order=c_order, **kwargs) |
| 3250 | + return reshape(lazyarr, shape, c_order=c_order, **kwargs) |
3257 | 3251 |
|
3258 | 3252 |
|
3259 | 3253 | # Define a numpy linspace-like function |
@@ -3316,10 +3310,7 @@ def linspace_fill(inputs, output, offset): |
3316 | 3310 | # C order is guaranteed, and no reshape is needed |
3317 | 3311 | return lazyarr.compute(**kwargs) |
3318 | 3312 |
|
3319 | | - # In principle, when c_order is False, the intermediate array wouldn't be needed, |
3320 | | - # but this is faster; see arange() for more details. |
3321 | | - larr = lazyarr.compute() # intermediate array |
3322 | | - return reshape(larr, shape, c_order=c_order, **kwargs) |
| 3313 | + return reshape(lazyarr, shape, c_order=c_order, **kwargs) |
3323 | 3314 |
|
3324 | 3315 |
|
3325 | 3316 | def eye(N, M=None, k=0, dtype=np.float64, **kwargs: Any): |
@@ -3427,10 +3418,12 @@ def iter_fill(inputs, output, offset): |
3427 | 3418 | # C order is guaranteed, and no reshape is needed |
3428 | 3419 | return lazyarr.compute(**kwargs) |
3429 | 3420 |
|
3430 | | - # In principle, when c_order is False, the intermediate array wouldn't be needed, |
3431 | | - # but this is faster; see arange() for more details. |
3432 | | - larr = lazyarr.compute() # intermediate array |
3433 | | - return reshape(larr, shape, c_order=c_order, **kwargs) |
| 3421 | + # TODO: in principle, the next should work, but tests still fail: |
| 3422 | + # return reshape(lazyarr, shape, c_order=c_order, **kwargs) |
| 3423 | + # Creating a temporary file is a workaround for the issue |
| 3424 | + with tempfile.NamedTemporaryFile(suffix=".b2nd", delete=True) as tmp_file: |
| 3425 | + larr = lazyarr.compute(urlpath=tmp_file.name, mode="w") # intermediate array |
| 3426 | + return reshape(larr, shape, c_order=c_order, **kwargs) |
3434 | 3427 |
|
3435 | 3428 |
|
3436 | 3429 | def frombuffer( |
|
0 commit comments