prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  [WIP] Fix assigning from complex to float (only test)
  When a user assign complex value to float array, it causes an error.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `cupy/core/_ufuncs.py`
  Content:
  ```
  1 from cupy.core._kernel import create_ufunc
  2 
  3 elementwise_copy = create_ufunc(
  4     'cupy_copy',
  5     ('?->?', 'b->b', 'B->B', 'h->h', 'H->H', 'i->i', 'I->I', 'l->l', 'L->L',
  6      'q->q', 'Q->Q', 'e->e', 'f->f', 'd->d', 'F->F', 'D->D'),
  7     'out0 = out0_type(in0)', default_casting='unsafe')
  8 # complex numbers requires out0 = complex<T>(in0)
  9
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/cupy/core/_ufuncs.py b/cupy/core/_ufuncs.py
  --- a/cupy/core/_ufuncs.py
  +++ b/cupy/core/_ufuncs.py
  @@ -1,8 +1,30 @@
   from cupy.core._kernel import create_ufunc
   
  +
  +_complex_cast_copy = '''
  +template<typename T, typename U>
  +__device__ void cast_copy(const U& x, T& y) {y = T(x);}
  +template<typename T, typename U>
  +__device__ void cast_copy(const complex<U>& x, complex<T>& y) {
  +    y = complex<T>(x);
  +}
  +template<typename T, typename U>
  +__device__ void cast_copy(const complex<U>& x, T& y) {y = T(x.real());}
  +'''
  +
  +
   elementwise_copy = create_ufunc(
       'cupy_copy',
       ('?->?', 'b->b', 'B->B', 'h->h', 'H->H', 'i->i', 'I->I', 'l->l', 'L->L',
        'q->q', 'Q->Q', 'e->e', 'f->f', 'd->d', 'F->F', 'D->D'),
  -    'out0 = out0_type(in0)', default_casting='unsafe')
  +    'cast_copy(in0, out0)',
  +    preamble=_complex_cast_copy, default_casting='unsafe')
  +
  +
  +elementwise_copy_where = create_ufunc(
  +    'cupy_copy_where',
  +    ('??->?', 'b?->b', 'B?->B', 'h?->h', 'H?->H', 'i?->i', 'I?->I', 'l?->l',
  +     'L?->L', 'q?->q', 'Q?->Q', 'e?->e', 'f?->f', 'd?->d', 'F?->F', 'D?->D'),
  +    'if (in1) cast_copy(in0, out0)',
  +    preamble=_complex_cast_copy, default_casting='unsafe')
   # complex numbers requires out0 = complex<T>(in0)
  
verification_info: {"golden_diff": "diff --git a/cupy/core/_ufuncs.py b/cupy/core/_ufuncs.py\n--- a/cupy/core/_ufuncs.py\n+++ b/cupy/core/_ufuncs.py\n@@ -1,8 +1,30 @@\n from cupy.core._kernel import create_ufunc\n \n+\n+_complex_cast_copy = '''\n+template<typename T, typename U>\n+__device__ void cast_copy(const U& x, T& y) {y = T(x);}\n+template<typename T, typename U>\n+__device__ void cast_copy(const complex<U>& x, complex<T>& y) {\n+    y = complex<T>(x);\n+}\n+template<typename T, typename U>\n+__device__ void cast_copy(const complex<U>& x, T& y) {y = T(x.real());}\n+'''\n+\n+\n elementwise_copy = create_ufunc(\n     'cupy_copy',\n     ('?->?', 'b->b', 'B->B', 'h->h', 'H->H', 'i->i', 'I->I', 'l->l', 'L->L',\n      'q->q', 'Q->Q', 'e->e', 'f->f', 'd->d', 'F->F', 'D->D'),\n-    'out0 = out0_type(in0)', default_casting='unsafe')\n+    'cast_copy(in0, out0)',\n+    preamble=_complex_cast_copy, default_casting='unsafe')\n+\n+\n+elementwise_copy_where = create_ufunc(\n+    'cupy_copy_where',\n+    ('??->?', 'b?->b', 'B?->B', 'h?->h', 'H?->H', 'i?->i', 'I?->I', 'l?->l',\n+     'L?->L', 'q?->q', 'Q?->Q', 'e?->e', 'f?->f', 'd?->d', 'F?->F', 'D?->D'),\n+    'if (in1) cast_copy(in0, out0)',\n+    preamble=_complex_cast_copy, default_casting='unsafe')\n # complex numbers requires out0 = complex<T>(in0)\n", "issue": "[WIP] Fix assigning from complex to float (only test)\nWhen a user assign complex value to float array, it causes an error.\n", "before_files": [{"content": "from cupy.core._kernel import create_ufunc\n\nelementwise_copy = create_ufunc(\n    'cupy_copy',\n    ('?->?', 'b->b', 'B->B', 'h->h', 'H->H', 'i->i', 'I->I', 'l->l', 'L->L',\n     'q->q', 'Q->Q', 'e->e', 'f->f', 'd->d', 'F->F', 'D->D'),\n    'out0 = out0_type(in0)', default_casting='unsafe')\n# complex numbers requires out0 = complex<T>(in0)\n", "path": "cupy/core/_ufuncs.py"}], "after_files": [{"content": "from cupy.core._kernel import create_ufunc\n\n\n_complex_cast_copy = '''\ntemplate<typename T, typename U>\n__device__ void cast_copy(const U& x, T& y) {y = T(x);}\ntemplate<typename T, typename U>\n__device__ void cast_copy(const complex<U>& x, complex<T>& y) {\n    y = complex<T>(x);\n}\ntemplate<typename T, typename U>\n__device__ void cast_copy(const complex<U>& x, T& y) {y = T(x.real());}\n'''\n\n\nelementwise_copy = create_ufunc(\n    'cupy_copy',\n    ('?->?', 'b->b', 'B->B', 'h->h', 'H->H', 'i->i', 'I->I', 'l->l', 'L->L',\n     'q->q', 'Q->Q', 'e->e', 'f->f', 'd->d', 'F->F', 'D->D'),\n    'cast_copy(in0, out0)',\n    preamble=_complex_cast_copy, default_casting='unsafe')\n\n\nelementwise_copy_where = create_ufunc(\n    'cupy_copy_where',\n    ('??->?', 'b?->b', 'B?->B', 'h?->h', 'H?->H', 'i?->i', 'I?->I', 'l?->l',\n     'L?->L', 'q?->q', 'Q?->Q', 'e?->e', 'f?->f', 'd?->d', 'F?->F', 'D?->D'),\n    'if (in1) cast_copy(in0, out0)',\n    preamble=_complex_cast_copy, default_casting='unsafe')\n# complex numbers requires out0 = complex<T>(in0)\n", "path": "cupy/core/_ufuncs.py"}]}