question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cupy_array[:] = numpy_array does not work

See original GitHub issue

It would be nice if __setitem__ worked with Numpy arrays as right-hand side. Currently one gets the error

    Traceback (most recent call last):
      File "cupy/core/core.pyx", line 1575, in cupy.core.core.ndarray.__setitem__
      File "cupy/core/core.pyx", line 3043, in cupy.core.core._scatter_op
      File "cupy/core/core.pyx", line 442, in cupy.core.core.ndarray.fill
    ValueError: non-scalar numpy.ndarray cannot be used for fill

A straightforward implementation could first cast to a cupy array and then do the usual setitem. An optimization for same dtype and size (assuming contiguous memory) would be to just use cudaMemcpy cupy_array.data.copy_from_host, but that may not be very relevant.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
leofangcommented, Nov 18, 2021

@orodbhen Try setting the env var CUPY_EXPERIMENTAL_SLICE_COPY=1.

0reactions
leofangcommented, Nov 18, 2021

There’s at least cupy.asarray() that can take a numpy array.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Basics of CuPy — CuPy 11.4.0 documentation
The cupy.asnumpy() method returns a NumPy array (array on the host), whereas cupy.asarray() method returns a CuPy array ...
Read more >
cuPy error : Implicit conversion to a host NumPy array via ...
Converting a cuDF series into a CuPy array with cupy.asarray(series) requires CuPy-compatible data types. You may want to double check your ...
Read more >
Standard array subclasses — NumPy v1.23 Manual
Subclassing a numpy.ndarray is possible but if your goal is to create an array with modified behavior, as do dask arrays for distributed...
Read more >
Using your GPU with CuPy - The Carpentries Incubator
CuPy is a GPU array library that implements a subset of the NumPy and SciPy interfaces. This makes it a very convenient tool...
Read more >
Python CuPy - GeeksforGeeks
It is an implementation of a NumPy-compatible multi-dimensional array on CUDA. CuPy consists of cupy.ndarray, the core multi-dimensional ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found