Skip to content

[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

Description

@34j

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

Activity

  1. added
    Bug Report
    on Oct 26, 2024
  2. 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`[/+] on Oct 26, 2024
  3. 34j commented on Oct 26, 2024

    @34j
    Author

    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.

  4. hmahmood24 commented on Oct 26, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Bug Report

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions