Skip to content

Commit 37d1121

Browse files
authored
Merge pull request #480 from murrayrm/array-by-default
Switch default state space matrix type to 'array' (instead of 'matrix')
2 parents 35f1e64 + 2849413 commit 37d1121

File tree

7 files changed

+57
-15
lines changed

7 files changed

+57
-15
lines changed

control/config.py

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,45 @@ def use_legacy_defaults(version):
171171
Parameters
172172
----------
173173
version : string
174-
version number of the defaults desired. ranges from '0.1' to '0.8.4'.
174+
Version number of the defaults desired. Ranges from '0.1' to '0.8.4'.
175175
"""
176-
numbers_list = version.split(".")
177-
first_digit = int(numbers_list[0])
178-
second_digit = int(numbers_list[1].strip('abcdef')) # remove trailing letters
179-
if second_digit < 8:
180-
# TODO: anything for 0.7 and below if needed
181-
pass
182-
elif second_digit == 8:
183-
if len(version) > 4:
184-
third_digit = int(version[4])
185-
use_numpy_matrix(True) # alternatively: set_defaults('statesp', use_numpy_matrix=True)
186-
else:
187-
raise ValueError('''version number not recognized. Possible values range from '0.1' to '0.8.4'.''')
176+
import re
177+
(major, minor, patch) = (None, None, None) # default values
178+
179+
# Early release tag format: REL-0.N
180+
match = re.match("REL-0.([12])", version)
181+
if match: (major, minor, patch) = (0, int(match.group(1)), 0)
182+
183+
# Early release tag format: control-0.Np
184+
match = re.match("control-0.([3-6])([a-d])", version)
185+
if match: (major, minor, patch) = \
186+
(0, int(match.group(1)), ord(match.group(2)) - ord('a') + 1)
187+
188+
# Early release tag format: v0.Np
189+
match = re.match("[vV]?0.([3-6])([a-d])", version)
190+
if match: (major, minor, patch) = \
191+
(0, int(match.group(1)), ord(match.group(2)) - ord('a') + 1)
192+
193+
# Abbreviated version format: vM.N or M.N
194+
match = re.match("([vV]?[0-9]).([0-9])", version)
195+
if match: (major, minor, patch) = \
196+
(int(match.group(1)), int(match.group(2)), 0)
197+
198+
# Standard version format: vM.N.P or M.N.P
199+
match = re.match("[vV]?([0-9]).([0-9]).([0-9])", version)
200+
if match: (major, minor, patch) = \
201+
(int(match.group(1)), int(match.group(2)), int(match.group(3)))
202+
203+
# Make sure we found match
204+
if major is None or minor is None:
205+
raise ValueError("Version number not recognized. Try M.N.P format.")
206+
207+
#
208+
# Go backwards through releases and reset defaults
209+
#
210+
211+
# Version 0.9.0: switched to 'array' as default for state space objects
212+
if major == 0 and minor < 9:
213+
set_defaults('statesp', use_numpy_matrix=True)
214+
215+
return (major, minor, patch)

control/statesp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070

7171
# Define module default parameter values
7272
_statesp_defaults = {
73-
'statesp.use_numpy_matrix': True,
73+
'statesp.use_numpy_matrix': False, # False is default in 0.9.0 and above
7474
'statesp.default_dt': None,
7575
'statesp.remove_useless_states': True,
7676
}

control/tests/config_test.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,28 @@ def test_reset_defaults(self):
214214
def test_legacy_defaults(self):
215215
ct.use_legacy_defaults('0.8.3')
216216
assert(isinstance(ct.ss(0,0,0,1).D, np.matrix))
217+
217218
ct.reset_defaults()
218219
assert(isinstance(ct.ss(0,0,0,1).D, np.ndarray))
220+
assert(not isinstance(ct.ss(0,0,0,1).D, np.matrix))
221+
222+
ct.use_legacy_defaults('0.9.0')
223+
assert(isinstance(ct.ss(0,0,0,1).D, np.ndarray))
224+
assert(not isinstance(ct.ss(0,0,0,1).D, np.matrix))
225+
219226
# test that old versions don't raise a problem
227+
ct.use_legacy_defaults('REL-0.1')
228+
ct.use_legacy_defaults('control-0.3a')
220229
ct.use_legacy_defaults('0.6c')
221230
ct.use_legacy_defaults('0.8.2')
222231
ct.use_legacy_defaults('0.1')
232+
233+
# Make sure that nonsense versions generate an error
234+
self.assertRaises(ValueError, ct.use_legacy_defaults, "a.b.c")
235+
self.assertRaises(ValueError, ct.use_legacy_defaults, "1.x.3")
236+
237+
# Leave everything like we found it
223238
ct.config.reset_defaults()
224-
225239

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

0 commit comments

Comments
 (0)