Repository: scipy/scipy
File: scipy/signal/_lti_conversion.py (Python)

Code before:
    D = D.reshape((C.shape[0], B.shape[1]))

    return A, B, C, D


def abcd_normalize(A=None, B=None, C=None, D=None, *, cast_to='floating64'):
    r"""Check state-space matrices compatibility and ensure they are 2d arrays.

    Converts input matrices into two-dimensional arrays as needed. Then the dimensions
    n, q, p are determined by investigating the non-zero entries of the array shapes.
    If a parameter is ``None``, or has shape (0, 0), it is set to a
    zero-array of compatible shape. Finally, it is verified that all parameter shapes
    are compatible to each other. If that fails, a ``ValueError`` is raised. Note that
    the dimensions n, q, p are allowed to be zero.

    Parameters
    ----------
    A: array_like, optional
        Two-dimensional array of shape (n, n).
    B: array_like, optional
        Two-dimensional array of shape (n, p).
    C: array_like, optional
        Two-dimensional array of shape (q, n).
    D: array_like, optional
        Two-dimensional array of shape (q, p).
    cast_to: dtype | 'floating64' | None, optional
        Cast all matrices to the specified dtype. If set to ``'floating64'`` (default)
        the matrices are cast to ``'float64'`` if they are all real-valued else to
        ``'complex128'``. If ``None``, the matrices' dtypes are not changed.

    Returns
    -------
    A, B, C, D : array
        State-space matrices as two-dimensional arrays.

    Notes
    -----
    If a matrix of zeros is created, its dtype is ``'float64'`` if no type casting is
    performed. Also, if a matrix is not modified, the original matrix (not a copy)
    is returned.

    The :ref:`tutorial_signal_state_space_representation` section of the
    :ref:`user_guide` presents the corresponding definitions of continuous-time and
    disrcete time state space systems.

    Raises
    ------
    ValueError
        If the dimensions n, q, or p could not be determined or if the shapes are
        incompatible with each other.


Review comment (suggestion):
Here if the default is `None` then you don't need the string so that the option here will have a single type which is also easier to handle in the future. If they don't bother to enter an option to the keyword then you don't need to bother string parsing. NumPy uses `dtype` keyword in such use cases we might want to follow that.

Code after:
    D = D.reshape((C.shape[0], B.shape[1]))

    return A, B, C, D


def abcd_normalize(A=None, B=None, C=None, D=None, *, dtype=None):
    r"""Check state-space matrices compatibility and ensure they are 2d arrays.

    First, the input matrices are converted into two-dimensional arrays with
    appropriate dtype as needed. Then the dimensions n, q, p are determined by
    investigating the array shapes. If an input is ``None``, or has size zero, it is
    set to an array of zeros of compatible shape. Finally, it is verified that all
    parameter shapes are compatible with each other. If that fails, a ``ValueError`` is
    raised. Note that the dimensions n, q, p are allowed to be zero.

    Parameters
    ----------
    A : array_like, optional
        Two-dimensional array of shape (n, n).
    B : array_like, optional
        Two-dimensional array of shape (n, p).
    C : array_like, optional
        Two-dimensional array of shape (q, n).
    D : array_like, optional
        Two-dimensional array of shape (q, p).
    dtype : dtype | None, optional
        Cast all matrices to the specified dtype. If set to ``None`` (default), their
        dtypes will be "complex128" if any of the matrices are complex-valued.
        Otherwise, they will be of the type "float64".

        .. versionadded:: 1.18.0

            With this new parameter, all return values have identical dtypes.
            In previous versions the dtype of the input was preserved.

    Returns
    -------
    A, B, C, D : array
        State-space matrices as two-dimensional arrays with identical dtype.

    Raises
    ------
    ValueError
        If the dimensions n, q, or p could not be determined or if the shapes are
        incompatible with each other.

    Notes
    -----
    If a matrix is not modified, the original matrix (not a copy) is returned.

    The :ref:`tutorial_signal_state_space_representation` section of the