Skip to content

Feature/check dimension function - #269

Closed
don4get wants to merge 2 commits into
python-control:masterfrom
don4get:feature/check-dimension-function
Closed

don4get wants to merge 2 commits into
python-control:masterfrom
don4get:feature/check-dimension-function

Conversation

@don4get

@don4get don4get commented Jan 5, 2019

Copy link
Copy Markdown
Contributor

Add a function to check dimensions between state space matrices.

It will allow to make this kind of check uniform within the library, in a future PR.

The function requires numpy arrays as inputs but I am not sure we want to force it. Can you give me insights?

I also added some unit tests, feel free to point out some cases I might have missed.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.2%) to 78.543% when pulling 7859f8c on don4get:feature/check-dimension-function into 31e6944 on python-control:master.

2 similar comments
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.2%) to 78.543% when pulling 7859f8c on don4get:feature/check-dimension-function into 31e6944 on python-control:master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.2%) to 78.543% when pulling 7859f8c on don4get:feature/check-dimension-function into 31e6944 on python-control:master.

@murrayrm

murrayrm commented Apr 7, 2019

Copy link
Copy Markdown
Member

I don't understand why this functionality is useful? It seems like it is just adding a function that is not likely to be used by users?

@don4get

don4get commented Apr 13, 2019

Copy link
Copy Markdown
Contributor Author

Hello! Thank you for your review ;)

As I said in the description of the PR, the point here is to create an internal function to make dimension check uniform in the library.

Currently, the check is partial and varies from a control function to another:
in statefbk.py -> place:

if A_mat.shape[0] != A_mat.shape[1]:
            raise ControlDimension("A must be a square matrix. "
                                   "rows: {} != columns: {}".format(A_mat.shape[0],
                                                                    A_mat.shape[1]))

        if A_mat.shape[0] != B_mat.shape[0]:
            raise ControlDimension("The number of rows of A ({}) must equal "
                                   "the number of rows in B ({})".format(A_mat.shape[0],
                                                                         B_mat.shape[0]))

in place_varga:

if A_mat.shape[0] != A_mat.shape[1] or A_mat.shape[0] != B_mat.shape[0]:
        raise ControlDimension("Matrix dimensions are incorrect.")

in lqr:

# Check dimensions for consistency
    nstates = B.shape[0]
    ninputs = B.shape[1]
    # TODO: Create / Figure out a generic function to check for inconsistent system
    if A.shape[0] != nstates or A.shape[1] != nstates:
        raise ControlDimension("Inconsistent system dimensions.")

And it continues like this in the entire library.

With this new internal function, the check will be uniform, factorized and unit tested :)

Comment thread control/exception.py

class ControlDimension(Exception):
"""Raised when dimensions of system objects are not correct"""
pass

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed by @repagh in PR #268, this change has side effects. Suggest leaving this alone since the default behavior should be enough.

Comment thread control/statesp.py
return ss.A, ss.B, ss.C, ss.D


def consistent_dimensions(A=None, B=None, C=None, D=None):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be an internal function (_consistent_dimensions)? Also, a more description function name might be useful. Perhaps _check_statespace_dimensions?

Comment thread control/statesp.py
- D [n_outputs x n_inputs]
Parameters
----------
A: ndarray - optional

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per numpydocs, this should be "A : ndarray, optional". Same below.

np.testing.assert_array_equal(D, g.D)

def test_consistent_dimensions_322(self):
true = consistent_dimensions(self.A322, self.B322, self.C322, self.D322)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A tighter format might be self.assertTrue(_check_statespace_dimensions(self.A322, self.B322, self.C322, self.D322))

@murrayrm

Copy link
Copy Markdown
Member

If we are going to include this PR, a couple of requests:

  • Please see review comments and address as needed.

  • I think we should also find the spots in the current code that would use this functionality and add it to those portions of the code. That way we know the new functionality actually does something useful (and works in the places where we need it).

  • Need to resolve conflicts with current master.

@murrayrm murrayrm added the onhold Waiting for changes or input label May 27, 2019
@murrayrm

Copy link
Copy Markdown
Member

PR has been idle for > 6 months => stale. @don4get I will close this PR in a few days unless you will have time to work on it soon. No worries if not; just re-open when you have responded to the comments above.

@murrayrm murrayrm closed this Dec 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

onhold Waiting for changes or input

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants