Skip to content

Commit

Permalink
fix LoopSum.asarray assertion
Browse files Browse the repository at this point in the history
In `LoopSum.asarray` the axes that are invariant to the loop index are shuffled
to the start to minimize the number of ravels. After the shuffle and ravels all
but the last axes are asserted to be invariant to the loop index. The check,
however, incorrectly checks for constness, which is more strict than being
invariant to the loop index. This patch fixes the assertion and removes an
`int` check, which is always false since the shapes are always of type
`evaluable.Array`.
  • Loading branch information
joostvanzwieten committed Aug 27, 2021
1 parent 02bd952 commit f8fa841
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions nutils/evaluable.py
Original file line number Diff line number Diff line change
Expand Up @@ -3545,11 +3545,11 @@ def _assparse(self):
*elem_indices, elem_values = (InsertAxis(arr, 1) for arr in (*elem_indices, elem_values))
else:
# minimize ravels by transposing all variable length axes to the end
variable = tuple(i for i, n in enumerate(elem_values.shape) if not numeric.isint(n) and self.index in n.arguments)
variable = tuple(i for i, n in enumerate(elem_values.shape) if self.index in n.arguments)
*elem_indices, elem_values = (Transpose.to_end(arr, *variable) for arr in (*elem_indices, elem_values))
for i in variable[:-1]:
*elem_indices, elem_values = map(Ravel, (*elem_indices, elem_values))
assert all(n.isconstant for n in elem_values.shape[:-1])
assert all(self.index not in n.arguments for n in elem_values.shape[:-1])
chunks.append(tuple(loop_concatenate(arr, self.index) for arr in (*elem_indices, elem_values)))
return tuple(chunks)

Expand Down

0 comments on commit f8fa841

Please sign in to comment.