Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[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 #28838

Open
4 tasks
34j opened this issue Oct 26, 2024 · 2 comments
Assignees
Labels
Bug Report Report bugs detected in Ivy.

Comments

@34j
Copy link

34j commented Oct 26, 2024

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

@34j 34j added the Bug Report Report bugs detected in Ivy. label Oct 26, 2024
@34j 34j changed the title [Bug]: ivy.array(0)[..., None]UnboundLocalError: cannot access local variable 'array_queries' where it is not associated with a value [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 Oct 26, 2024
@34j
Copy link
Author

34j commented Oct 26, 2024

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.

@hmahmood24
Copy link
Contributor

@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 🙂

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Bug Report Report bugs detected in Ivy.
Projects
None yet
Development

No branches or pull requests

2 participants