<commit_before>"""statesp.py

State space representation and functions.

This file contains the StateSpace class, which is used to represent linear
systems in state space.  This is the primary representation for the
python-control library.

"""

# Python 3 compatability (needs to go here)
from __future__ import print_function

"""Copyright (c) 2010 by California Institute of Technology
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.

3. Neither the name of the California Institute of Technology nor
   the names of its contributors may be used to endorse or promote
   products derived from this software without specific prior
   written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL CALTECH
OR THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

Author: <NAME>
Date: 24 May 09
Revised: <NAME>, Dec 10

$Id$
"""

import numpy as np
from numpy import all, angle, any, array, asarray, concatenate, cos, delete, \
    dot, empty, exp, eye, matrix, ones, pi, poly, poly1d, roots, shape, sin, \
    zeros, squeeze
from numpy.random import rand, randn
from numpy.linalg import solve, eigvals, matrix_rank
from numpy.linalg.linalg import LinAlgError
from scipy.signal import lti, cont2discrete
# from exceptions import Exception
import warnings
from .lti import LTI, timebase, timebaseEqual, isdtime
from .xferfcn import _convertToTransferFunction
from copy import deepcopy

__all__ = ['StateSpace', 'ss', 'rss', 'drss', 'tf2ss', 'ssdata']

class StateSpace(LTI):
    """A class for representing state-space models

    The StateSpace class is used to represent state-space realizations of linear
    time-invariant (LTI) systems:

        dx/dt = A x + B u
            y = C x + D u

    where u is the input, y is the output, and x is the state.

    The main data members are the A, B, C, and D matrices.  The class also
    keeps track of the number of states (i.e., the size of A).

    Discrete-time state space system are implemented by using the 'dt' instance
    variable and setting it to the sampling period.  If 'dt' is not None,
    then it must match whenever two state space systems are combined.
    Setting dt = 0 specifies a continuous system, while leaving dt = None
    means the system timebase is not specified.  If 'dt' is set to True, the
    system will be treated as a discrete time system with unspecified
    sampling time.

    """

    def __init__(self, *args):
        """Construct a state space object.

        The default constructor is StateSpace(A, B, C, D), where A, B, C, D are
        matrices or equivalent objects.  To call the copy constructor, call
        StateSpace(sys), where sys is a StateSpace object.

        """

        if len(args) == 4:
            # The user provided A, B, C, and D matrices.
            (A, B, C, D) = args
            dt = None;
        elif len(args) == 5:
            # Discrete time system
            (A, B, C, D, dt) = args
        elif len(args) == 1:
            # Use the copy constructor.
            if not isinstance(args[0], StateSpace):
                raise TypeError("The one-argument constructor can only take in \
a StateSpace object.  Recived %s." % type(args[0]))
            A = args[0].A
            B = args[0].B
            C = args[0].C
            D = args[0].D
            try:
                dt = args[0].dt
            except NameError:
                dt = None;
        else:
            raise ValueError("Needs 1 or 4 arguments; received %i." % len(args))

        # Here we're going to convert inputs to matrices, if the user gave a
        # non-matrix type.
        #! TODO: [A, B, C, D] = map(matrix, [A, B, C, D])?
        matrices = [A, B, C, D]
        for i in range(len(matrices)):
            # Convert to matrix first, if necessary.
            matrices[i] = matrix(matrices[i])
        [A, B, C, D] = matrices

        LTI.__init__(self, B.shape[1], C.shape[0], dt)
        self.A = A
        self.B = B
        self.C = C
        self.D = D

        self.states = A.shape[0]
<commit_msg>Replaced a loop with a map<commit_after>"""statesp.py

State space representation and functions.

This file contains the StateSpace class, which is used to represent linear
systems in state space.  This is the primary representation for the
python-control library.

"""

# Python 3 compatability (needs to go here)
from __future__ import print_function

"""Copyright (c) 2010 by California Institute of Technology
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.

3. Neither the name of the California Institute of Technology nor
   the names of its contributors may be used to endorse or promote
   products derived from this software without specific prior
   written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL CALTECH
OR THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

Author: <NAME>
Date: 24 May 09
Revised: <NAME>, Dec 10

$Id$
"""

import numpy as np
from numpy import all, angle, any, array, asarray, concatenate, cos, delete, \
    dot, empty, exp, eye, matrix, ones, pi, poly, poly1d, roots, shape, sin, \
    zeros, squeeze
from numpy.random import rand, randn
from numpy.linalg import solve, eigvals, matrix_rank
from numpy.linalg.linalg import LinAlgError
from scipy.signal import lti, cont2discrete
# from exceptions import Exception
import warnings
from .lti import LTI, timebase, timebaseEqual, isdtime
from .xferfcn import _convertToTransferFunction
from copy import deepcopy

__all__ = ['StateSpace', 'ss', 'rss', 'drss', 'tf2ss', 'ssdata']

class StateSpace(LTI):
    """A class for representing state-space models

    The StateSpace class is used to represent state-space realizations of linear
    time-invariant (LTI) systems:

        dx/dt = A x + B u
            y = C x + D u

    where u is the input, y is the output, and x is the state.

    The main data members are the A, B, C, and D matrices.  The class also
    keeps track of the number of states (i.e., the size of A).

    Discrete-time state space system are implemented by using the 'dt' instance
    variable and setting it to the sampling period.  If 'dt' is not None,
    then it must match whenever two state space systems are combined.
    Setting dt = 0 specifies a continuous system, while leaving dt = None
    means the system timebase is not specified.  If 'dt' is set to True, the
    system will be treated as a discrete time system with unspecified
    sampling time.

    """

    def __init__(self, *args):
        """Construct a state space object.

        The default constructor is StateSpace(A, B, C, D), where A, B, C, D are
        matrices or equivalent objects.  To call the copy constructor, call
        StateSpace(sys), where sys is a StateSpace object.

        """

        if len(args) == 4:
            # The user provided A, B, C, and D matrices.
            (A, B, C, D) = args
            dt = None;
        elif len(args) == 5:
            # Discrete time system
            (A, B, C, D, dt) = args
        elif len(args) == 1:
            # Use the copy constructor.
            if not isinstance(args[0], StateSpace):
                raise TypeError("The one-argument constructor can only take in \
a StateSpace object.  Recived %s." % type(args[0]))
            A = args[0].A
            B = args[0].B
            C = args[0].C
            D = args[0].D
            try:
                dt = args[0].dt
            except NameError:
                dt = None;
        else:
            raise ValueError("Needs 1 or 4 arguments; received %i." % len(args))

        # Here we're going to convert inputs to matrices, if the user gave a
        # non-matrix type.
        A, B, C, D = map(matrix, [A, B, C, D])

        LTI.__init__(self, B.shape[1], C.shape[0], dt)
        self.A = A
        self.B = B
        self.C = C
        self.D = D

        self.states = A.shape[0]

{'fraction_non_alphanumeric': 0.071990441103256, 'fraction_numerical': 0.0065717415115005475, 'mean_word_length': 2.8350515463917527, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3578950', 'n_tokens_mistral': 2855, 'n_tokens_neox': 2684, 'n_words': 1352}