Skip to content

Set_item: improve error message on un-broadcastable lhs & rhs #476

@manopapad

Description

@manopapad

The following:

x = cn.arange(4).reshape((2,2)).astype(np.float64)
inds = (
    cn.array([0, 1]),
    cn.array([0, 1]),
)
x[inds] = cn.zeros((3,))

produces an assertion failure:

Traceback (most recent call last):
  File "/Users/mpapadakis/legate.core/install/lib/python3.8/site-packages/legion_top.py", line 440, in legion_python_main
    run_path(args[start], run_name='__main__')
  File "/Users/mpapadakis/legate.core/install/lib/python3.8/site-packages/legion_top.py", line 255, in run_path
    exec(code, module.__dict__, module.__dict__)
  File "a.py", line 43, in <module>
    x[inds] = cn.zeros((3,))
  File "/Users/mpapadakis/cunumeric/cunumeric/coverage.py", line 107, in wrapper
    return func(*args, **kwargs)
  File "/Users/mpapadakis/cunumeric/cunumeric/array.py", line 105, in wrapper
    return func(*args, **kwargs)
  File "/Users/mpapadakis/cunumeric/cunumeric/array.py", line 1513, in __setitem__
    self._thunk.set_item(key, value._thunk)
  File "/Users/mpapadakis/cunumeric/cunumeric/deferred.py", line 81, in wrapper
    return func(*args, **kwargs)
  File "/Users/mpapadakis/cunumeric/cunumeric/deferred.py", line 734, in set_item
    rhs_tmp = rhs._broadcast(index_array.base.shape)
  File "/Users/mpapadakis/cunumeric/cunumeric/deferred.py", line 643, in _broadcast
    assert result.shape[dim] == 1
AssertionError

while this variant:

x = cn.arange(4).reshape((2,2)).astype(np.float64)
inds = (
    cn.array([0, 1]),
    cn.array([0, 1]),
)
x[inds] = cn.zeros((1,3))

makes it to the task launch stage before failing:

Traceback (most recent call last):
  File "/Users/mpapadakis/legate.core/install/lib/python3.8/site-packages/legion_top.py", line 440, in legion_python_main
    run_path(args[start], run_name='__main__')
  File "/Users/mpapadakis/legate.core/install/lib/python3.8/site-packages/legion_top.py", line 255, in run_path
    exec(code, module.__dict__, module.__dict__)
  File "a.py", line 43, in <module>
    x[inds] = cn.zeros((1,3))
  File "/Users/mpapadakis/cunumeric/cunumeric/coverage.py", line 107, in wrapper
    return func(*args, **kwargs)
  File "/Users/mpapadakis/cunumeric/cunumeric/array.py", line 105, in wrapper
    return func(*args, **kwargs)
  File "/Users/mpapadakis/cunumeric/cunumeric/array.py", line 1513, in __setitem__
    self._thunk.set_item(key, value._thunk)
  File "/Users/mpapadakis/cunumeric/cunumeric/deferred.py", line 81, in wrapper
    return func(*args, **kwargs)
  File "/Users/mpapadakis/cunumeric/cunumeric/deferred.py", line 763, in set_item
    copy.execute()
  File "/Users/mpapadakis/legate.core/install/lib/python3.8/site-packages/legate/core/operation.py", line 167, in execute
    self._context.runtime.submit(self)
  File "/Users/mpapadakis/legate.core/install/lib/python3.8/site-packages/legate/core/runtime.py", line 1048, in submit
    self.flush_scheduling_window()
  File "/Users/mpapadakis/legate.core/install/lib/python3.8/site-packages/legate/core/runtime.py", line 1041, in flush_scheduling_window
    self._schedule(ops)
  File "/Users/mpapadakis/legate.core/install/lib/python3.8/site-packages/legate/core/runtime.py", line 1031, in _schedule
    strategies.append(partitioner.partition_stores())
  File "/Users/mpapadakis/legate.core/install/lib/python3.8/site-packages/legate/core/solver.py", line 404, in partition_stores
    for c in op.constraints:
  File "/Users/mpapadakis/legate.core/install/lib/python3.8/site-packages/legate/core/operation.py", line 790, in constraints
    raise ValueError(
ValueError: Each input must have the same shape as the corresponding target indirect field, but got (2, 3) and (2,)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions