Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
bnavigator merged 2 commits intopython-control:masterfrommurrayrm:array-by-default
Dec 28, 2020
Merged
Show file tree
Hide file tree
Changes fromall 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 deletionscontrol/config.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletioncontrol/statesp.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletioncontrol/tests/config_test.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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.

[8]ページ先頭

©2009-2025 Movatter.jp