Skip to content

Commit

Permalink
Fixes a bug introduced in __len__ method changes in earlier commit, w…
Browse files Browse the repository at this point in the history
…here length could return zero.
  • Loading branch information
peterdsharpe committed Apr 6, 2024
1 parent 6818b3c commit ef0c24e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 35 deletions.
20 changes: 8 additions & 12 deletions aerosandbox/dynamics/point_mass/common_point_mass.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,16 @@ def get_item_of_attribute(a):
return new_instance

def __len__(self):
length = 0
length = 1
for v in self.state.values():
if np.length(v) == 1:
try:
v[0]
length = 1
except (TypeError, IndexError, KeyError) as e:
lv = np.length(v)
if lv != 1:
if length == 1:
length = lv
elif length == lv:
pass
elif length == 0 or length == 1:
length = np.length(v)
elif length == np.length(v):
pass
else:
raise ValueError("State variables are appear vectorized, but of different lengths!")
else:
raise ValueError("State variables are appear vectorized, but of different lengths!")
return length

def __array__(self, dtype="O"):
Expand Down
20 changes: 8 additions & 12 deletions aerosandbox/performance/operating_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,16 @@ def get_item_of_attribute(a):
return new_instance

def __len__(self):
length = 0
length = 1
for v in self.state.values():
if np.length(v) == 1:
try:
v[0]
length = 1
except (TypeError, IndexError, KeyError) as e:
lv = np.length(v)
if lv != 1:
if length == 1:
length = lv
elif length == lv:
pass
elif length == 0 or length == 1:
length = np.length(v)
elif length == np.length(v):
pass
else:
raise ValueError("State variables are appear vectorized, but of different lengths!")
else:
raise ValueError("State variables are appear vectorized, but of different lengths!")
return length

def __array__(self, dtype="O"):
Expand Down
18 changes: 7 additions & 11 deletions aerosandbox/weights/mass_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,14 @@ def __len__(self):
self.Iyz,
self.Ixz,
]:
if np.length(v) == 1:
try:
v[0]
length = 1
except (TypeError, IndexError, KeyError) as e:
lv = np.length(v)
if lv != 1:
if length == 1:
length = lv
elif length == lv:
pass
elif length == 0 or length == 1:
length = np.length(v)
elif length == np.length(v):
pass
else:
raise ValueError("State variables are appear vectorized, but of different lengths!")
else:
raise ValueError("State variables are appear vectorized, but of different lengths!")
return length

def __array__(self, dtype="O"):
Expand Down

0 comments on commit ef0c24e

Please sign in to comment.