Skip to content

Fix: a and c matrices must have at least one column in td04ad_r #5

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

Conversation

roryyorke
Copy link
Collaborator

Related to python-control/python-control#129 (comment)

Previously the a and c matrices submitted to SLICOT's TD04AD via Slycot's td04ad_r could have zero columns if the submitted transfer functions were constant. This is reasonable, but f2py (or possibly other numpy component) objected. The fix is to ensure a minimum of 1 column; this doesn't affect the result, since TD04AD returns the number of required states, and only the required parts of the a, b, and c matrices are returned.

Unfortunately a similar fix does not work for td04ad_c; I believe this is due to a bug in SLICOT. I'll file a separate issue for that.

This does not address the case when there are either no inputs (m=0) or outputs (p=0); I suspect a similar failure would occur in that case.

This allows conversion of static gain (i.e., constant) transfer
functions.

SLICOT and Fortran can possibly handle the 0 case, but f2py seems to not
like dimensions of length 0.

td04ad_c needs a similar fix, but I couldn't get it to work; I suspect
this is due to a bug in SLICOT.
@slivingston slivingston self-assigned this Jan 12, 2017
@slivingston
Copy link
Member

I confirmed that your proposed change provides for the correct output. Before merging, I want to understand where the wrapper generated by f2py fails when nr=0. I will study this before 22 Jan.

@roryyorke
Copy link
Collaborator Author

FWIW, this

       PROGRAM EMPTY
       REAL X(0) 
       END 

doesn't compile on my system (Ubuntu 14.04, compiler "fort77 Version 1.15" (from gcc)); error

Error on line 3: Declaration error for x: nonpositive dimension

Further, this fairly authentic looking Fortran 77 Standard says

          2.6  Array

          An array is a nonempty sequence of data that has a name
          and a type.  The name of an array is a symbolic name.

so it could just be invalid to have an empty array in Fortran 77.

@slivingston slivingston merged commit 9a098d1 into python-control:master Jan 26, 2017
@slivingston
Copy link
Member

The error that is addressed by this PR is thrown from the function array_from_pyobj of f2py, and in particular the message

ValueError: failed to create intent(cache|hide)|optional array-- must have defined dimensions but got...

is from line 684 in numpy/f2py/src/fortranobject.c. The conditional block is entered because count_nonpos (cf. code around line 595 of fortranobject.c detects that the number of columns of A or C is 0.

@slivingston
Copy link
Member

Regarding the case of no inputs (m=0), the same error occurs because the number of columns of D is m, as at line 239 of transform.pyf and as can be found in the code that is generated by f2py,

  /* Processing variable d */
  d_Dims[0]=max(1,p),d_Dims[1]=m;
  capi_d_intent |= F2PY_INTENT_HIDE|F2PY_INTENT_OUT;
  capi_d_tmp = array_from_pyobj(NPY_DOUBLE,d_Dims,d_Rank,capi_d_intent,Py_None);

Regarding the case of no outputs (p=0), it succeeds if m > 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants