Skip to content

Switch default state space matrix type to 'array' (instead of 'matrix') #480

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

Merged
merged 2 commits into from
Dec 28, 2020
Merged
Show file tree
Hide file tree
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
54 changes: 41 additions & 13 deletions control/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,45 @@ def use_legacy_defaults(version):
Parameters
----------
version : string
version number of the defaults desired. ranges from '0.1' to '0.8.4'.
Version number of the defaults desired. Ranges from '0.1' to '0.8.4'.
"""
numbers_list = version.split(".")
first_digit = int(numbers_list[0])
second_digit = int(numbers_list[1].strip('abcdef')) # remove trailing letters
if second_digit < 8:
# TODO: anything for 0.7 and below if needed
pass
elif second_digit == 8:
if len(version) > 4:
third_digit = int(version[4])
use_numpy_matrix(True) # alternatively: set_defaults('statesp', use_numpy_matrix=True)
else:
raise ValueError('''version number not recognized. Possible values range from '0.1' to '0.8.4'.''')
import re
(major, minor, patch) = (None, None, None) # default values

# Early release tag format: REL-0.N
match = re.match("REL-0.([12])", version)
if match: (major, minor, patch) = (0, int(match.group(1)), 0)

# Early release tag format: control-0.Np
match = re.match("control-0.([3-6])([a-d])", version)
if match: (major, minor, patch) = \
(0, int(match.group(1)), ord(match.group(2)) - ord('a') + 1)

# Early release tag format: v0.Np
match = re.match("[vV]?0.([3-6])([a-d])", version)
if match: (major, minor, patch) = \
(0, int(match.group(1)), ord(match.group(2)) - ord('a') + 1)

# Abbreviated version format: vM.N or M.N
match = re.match("([vV]?[0-9]).([0-9])", version)
if match: (major, minor, patch) = \
(int(match.group(1)), int(match.group(2)), 0)

# Standard version format: vM.N.P or M.N.P
match = re.match("[vV]?([0-9]).([0-9]).([0-9])", version)
if match: (major, minor, patch) = \
(int(match.group(1)), int(match.group(2)), int(match.group(3)))

# Make sure we found match
if major is None or minor is None:
raise ValueError("Version number not recognized. Try M.N.P format.")

#
# Go backwards through releases and reset defaults
#

# Version 0.9.0: switched to 'array' as default for state space objects
if major == 0 and minor < 9:
set_defaults('statesp', use_numpy_matrix=True)

return (major, minor, patch)
2 changes: 1 addition & 1 deletion control/statesp.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

# Define module default parameter values
_statesp_defaults = {
'statesp.use_numpy_matrix': True,
'statesp.use_numpy_matrix': False, # False is default in 0.9.0 and above
'statesp.default_dt': None,
'statesp.remove_useless_states': True,
}
Expand Down
16 changes: 15 additions & 1 deletion control/tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,28 @@ def test_reset_defaults(self):
def test_legacy_defaults(self):
ct.use_legacy_defaults('0.8.3')
assert(isinstance(ct.ss(0,0,0,1).D, np.matrix))

ct.reset_defaults()
assert(isinstance(ct.ss(0,0,0,1).D, np.ndarray))
assert(not isinstance(ct.ss(0,0,0,1).D, np.matrix))

ct.use_legacy_defaults('0.9.0')
assert(isinstance(ct.ss(0,0,0,1).D, np.ndarray))
assert(not isinstance(ct.ss(0,0,0,1).D, np.matrix))

# test that old versions don't raise a problem
ct.use_legacy_defaults('REL-0.1')
ct.use_legacy_defaults('control-0.3a')
ct.use_legacy_defaults('0.6c')
ct.use_legacy_defaults('0.8.2')
ct.use_legacy_defaults('0.1')

# Make sure that nonsense versions generate an error
self.assertRaises(ValueError, ct.use_legacy_defaults, "a.b.c")
self.assertRaises(ValueError, ct.use_legacy_defaults, "1.x.3")

# Leave everything like we found it
ct.config.reset_defaults()


def test_change_default_dt(self):
ct.set_defaults('statesp', default_dt=0)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.