Skip to content

ENH: reshape: test copy= kwarg - #432

Merged
ev-br merged 1 commit into
data-apis:masterfrom
ev-br:reshape_copy_arg
Jul 29, 2026
Merged

ENH: reshape: test copy= kwarg#432
ev-br merged 1 commit into
data-apis:masterfrom
ev-br:reshape_copy_arg

Conversation

@ev-br

@ev-br ev-br commented Mar 22, 2026

Copy link
Copy Markdown
Member

Apparently, copy= kwarg of reshape is not very well reasonably well supported:

Where the argument is supported, the test itself needs work:

@ev-br
ev-br marked this pull request as draft March 22, 2026 10:33
@ev-br

ev-br commented Mar 22, 2026

Copy link
Copy Markdown
Member Author

cross-ref #108

@ev-br

ev-br commented Jun 27, 2026

Copy link
Copy Markdown
Member Author

Cupy issue to add the copy= argument to reshape: cupy/cupy#10039

@ev-br

ev-br commented Jul 27, 2026

Copy link
Copy Markdown
Member Author

The array-api-strict failure seems to be

(Pdb) l
118  	
119  	    data = x._array
120  	    if copy:
121  	        data = np.copy(data)
122  	
123  ->	    reshaped = np.reshape(data, shape)
124  	
125  	    if copy is False and not np.shares_memory(data, reshaped):
126  	        raise AttributeError("Incompatible shape for in-place modification.")
127  	
128  	    return Array._new(reshaped, device=x.device)
(Pdb) p data
array([], dtype=float64)
(Pdb) p np.shares_memory(data, data)
False

which a kind of makes sense: if there's no data to share, nothing's shared. So it'll need a tweak in array-api-strict.

@ev-br

ev-br commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

It looks like that after data-apis/array-api-strict#232 and data-apis/array-api-compat#454 by @stanbot8, the only remaining blocker is torch.

@ev-br
ev-br force-pushed the reshape_copy_arg branch from 7011cfc to ac0173e Compare July 29, 2026 07:38
@ev-br

ev-br commented Jul 29, 2026

Copy link
Copy Markdown
Member Author

All wrapped modules have been fixed (thanks @stanbot8!), the updated test passes locally. We'll be able to improve further when

  • numpy 2.1 is the minimum supported version (will be able to drop branching on the numpy version and always use the native numpy function)
  • cupy 14 is the minimum supported version (will be able to drop the wrapper and use cupy's native copy=).

@ev-br
ev-br merged commit 4b42caf into data-apis:master Jul 29, 2026
5 checks passed
@ev-br ev-br mentioned this pull request Jul 29, 2026
45 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant