Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Handle .ndim and [:, np.newaxis] on VariableView #1412

Merged
merged 1 commit into from
May 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion brian2/core/variables.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

"""
Classes used to specify the type of a function, variable or common
sub-expression.
Expand Down Expand Up @@ -1091,6 +1090,16 @@ def get_with_index_array(self, item):
elif (isinstance(item, slice) and item == slice(None)
and self.index_var == '_idx'):
indices = slice(None)
# Quick fix for matplotlib calling 1-d variables as var[:, np.newaxis]
# The test is a bit verbose, but we need to avoid comparisons that raise errors
# (e.g. comparing an array to slice(None))
elif (isinstance(item, tuple) and
len(item) == 2 and
isinstance(item[0], slice) and
item[0] == slice(None) and
item[1] is None and
self.index_var == '_idx'):
return variable.get_value()[item]
else:
indices = self.indexing(item, self.index_var)

Expand Down Expand Up @@ -1400,6 +1409,10 @@ def __repr__(self):
def shape(self):
return self.get_item(slice(None), level=1).shape

@property
def ndim(self):
return self.get_item(slice(None), level=1).ndim

@property
def dtype(self):
return self.get_item(slice(None), level=1).dtype
Expand Down