ivy
ivy copied to clipboard
[Bug]: `ivy.array(0)[None]` (adding dimention to a 0-dimentional array) `UnboundLocalError: cannot access local variable 'array_queries' where it is not associated with a value`
Bug Explanation
> python -c "import ivy; ivy.array(0)[..., None]"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "./venv/lib/python3.11/site-packages/ivy/func_wrapper.py", line 643, in _handle_view_indexing
ret = fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "./venv/lib/python3.11/site-packages/ivy/data_classes/array/array.py", line 429, in __getitem__
return ivy.get_item(self._data, query)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "./venv/lib/python3.11/site-packages/ivy/func_wrapper.py", line 912, in _handle_nestable
return fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "./venv/lib/python3.11/site-packages/ivy/func_wrapper.py", line 968, in _handle_partial_mixed_function
return fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "./venv/lib/python3.11/site-packages/ivy/func_wrapper.py", line 643, in _handle_view_indexing
ret = fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "./venv/lib/python3.11/site-packages/ivy/func_wrapper.py", line 456, in _inputs_to_ivy_arrays
return fn(*ivy_args, **ivy_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "./venv/lib/python3.11/site-packages/ivy/func_wrapper.py", line 328, in _handle_array_function
return fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "./venv/lib/python3.11/site-packages/ivy/func_wrapper.py", line 761, in _handle_device
with ivy.DefaultDevice(ivy.default_device(dst_dev)):
File "./venv/lib/python3.11/site-packages/ivy/functional/ivy/device.py", line 128, in __exit__
raise exc_val
File "./venv/lib/python3.11/site-packages/ivy/func_wrapper.py", line 762, in _handle_device
return ivy.handle_soft_device_variable(*args, fn=fn, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "./venv/lib/python3.11/site-packages/ivy/functional/ivy/device.py", line 133, in handle_soft_device_variable
return ivy.current_backend().handle_soft_device_variable(*args, fn=fn, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "./venv/lib/python3.11/site-packages/ivy/functional/backends/numpy/device.py", line 68, in handle_soft_device_variable
return fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "./venv/lib/python3.11/site-packages/ivy/functional/ivy/general.py", line 2812, in get_item
query, target_shape, vector_inds = _parse_query(query, x_shape)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "./venv/lib/python3.11/site-packages/ivy/functional/ivy/general.py", line 3001, in _parse_query
indices = array_queries.reshape((*target_shape, len(x_shape)))
^^^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'array_queries' where it is not associated with a value
Steps to Reproduce Bug
python -c "import ivy; ivy.array(0)[None]"
python -c "import ivy; ivy.array(0)[..., None]"
This works:
python -c "import numpy as np; np.array(0)[None]"
python -c "import numpy as np; np.array(0)[..., None]"
python -c "import ivy; ivy.array([0])[..., None]"
python -c "import ivy; ivy.set_backend('torch'); ivy.array(0)[..., None]"
python -c "import ivy; ivy.set_backend('numpy'); ivy.array(0)[..., None]"
Environment
Ubuntu 22.04
Ivy Version
0.0.9.16 and 1.0.0.0
Backend
- [ ] NumPy
- [ ] TensorFlow
- [ ] PyTorch
- [ ] JAX
Device
CPU
I have found that this issue does not occur when ivy.set_backend("numpy") is called in advance. However, I am not sure why this makes a difference, since the documentation states that the default backend is NumPy.
@34j Apologies for any inconvenience caused by this. Thanks a lot for reporting this issue. I've tested and verified that this is indeed reproducible on my end. I'll push a fix for this shortly and link the PR here 🙂