# Path: modred/era.py
# def make_sampled_format(times, Markovs, dt_tol=1e-6):
# def compute_ERA_model(Markovs, num_states):
#     def __init__(
#         self, put_array=util.save_array_text, mc=None, mo=None, verbosity=1):
#     def compute_model(self, Markovs, num_states, mc=None, mo=None):
#     def put_model(self, A_dest, B_dest, C_dest):
#     def put_decomp(
#         self, sing_vals_dest, L_sing_vecs_dest, R_sing_vecs_dest,
#         Hankel_array_dest, Hankel_array2_dest):
#     def put_sing_vals(self, sing_vals_dest):
#     def _set_Markovs(self, Markovs):
#     def _assemble_Hankel(self):
# class ERA(object):
# 
# Path: modred/parallel.py
# def get_hostname():
# def get_node_ID():
# def get_num_nodes():
# def get_num_MPI_workers():
# def get_rank():
# def get_num_procs():
# def is_distributed():
# def is_rank_zero():
# def barrier():
# def print_from_rank_zero(msg, output_channel='stdout'):
# def call_from_rank_zero(func, *args, **kwargs):
# def bcast(vals):
# def call_and_bcast(func, *args, **kwargs):
# def find_assignments(tasks, task_weights=None):
# def check_for_empty_tasks(task_assignments):
# 
# Path: modred/util.py
# class UndefinedError(Exception): pass
# class InnerProductBlock(object):
# def atleast_2d_row(array):
# def atleast_2d_col(array):
# def make_iterable(arg):
# def flatten_list(my_list):
# def save_array_text(array, file_name, delimiter=None):
# def load_array_text(file_name, delimiter=None, is_complex=False):
# def get_file_list(directory, file_extension=None):
# def get_data_members(obj):
# def sum_arrays(arr1, arr2):
# def sum_lists(list1, list2):
# def smart_eq(arg1, arg2):
#     def __init__(self, inner_product):
#     def __call__(self, vecs1, vecs2):
# def svd(array, atol=1e-13, rtol=None):
# def eigh(array, atol=1e-13, rtol=None, is_positive_definite=False):
# def eig_biorthog(array, scale_choice='left'):
# def balanced_truncation(
#     A, B, C, order=None, return_sing_vals=False):
# def drss(num_states, num_inputs, num_outputs):
# def rss(num_states, num_inputs, num_outputs):
# def lsim(A, B, C, inputs, initial_condition=None):
# def impulse(A, B, C, num_time_steps=None):
# def load_signals(signal_path, delimiter=None):
# def load_multiple_signals(signal_paths, delimiter=None):
# def Hankel(first_col, last_row=None):
# def Hankel_chunks(first_col_chunks, last_row_chunks=None):
#     V = V_conj_T.conj().T
#     U = U[:, :num_nonzeros]
#     V = V[:, :num_nonzeros]
#     S = S[:num_nonzeros]
#     A = np.array(A)
#     B = np.array(B)
#     C = np.array(C)
#     U, E, V = svd(Lo.transpose().dot(Lc))
#     SL = Lo.dot(U[:, :order]).dot(np.diag(E[:order]**-0.5))
#     SR = Lc.dot(V[:, :order]).dot(np.diag(E[:order]**-0.5))
#     A = np.real(
#         np.linalg.inv(eig_vecs).dot(np.diag(eig_vals).dot(eig_vecs)))
#     B = np.random.normal(0, 1., (num_states, num_inputs))
#     C = np.random.normal(0, 1., (num_outputs, num_states))
#     A = np.linalg.inv(transformation).dot(np.diag(e_vals)).dot(transformation)
#     B = np.random.random((num_states, num_inputs))
#     C = np.random.random((num_outputs, num_states))
#     A = np.array(A)
#     B = np.array(B)
#     C = np.array(C)
# 
# Path: modred/py2to3.py
# def run_script(path, globals=None, locals=None):
# def print_stdout(msg):
# def print_stderr(msg):
# def print_msg(msg, output_channel='stdout'):


import unittest
import os
import numpy as np
from os.path import join
from shutil import rmtree
from modred import era, parallel, util
from modred.py2to3 import range
                                0, dt=dt).to_tf()
                            tf_model = scipy.signal.StateSpace(
                                A_model,
                                B_model[:, input_idx:input_idx + 1],
                                C_model[output_idx:output_idx + 1, :],
                                0, dt=dt).to_tf()
                            tf_diff = util.sub_transfer_functions(
                                tf_plant, tf_model, dt=dt)

                            # Compute transfer function norms
                            tf_plant_inf_norm = util.compute_inf_norm_discrete(
                                tf_plant, dt)
                            tf_diff_inf_norm = util.compute_inf_norm_discrete(
                                tf_diff, dt)

                            # Test values
                            print 'err_frac', (
                                tf_diff_inf_norm / tf_plant_inf_norm)
                            self.assertTrue(
                                tf_diff_inf_norm / tf_plant_inf_norm <
                                tf_rel_tol)
                    '''

                    # Also test that saved reduced model mats are equal to those
                    # returned in memory
                    np.testing.assert_equal(
                        util.load_array_text(A_path_computed), A_model)
                    np.testing.assert_equal(
                        util.load_array_text(B_path_computed), B_model)
                    np.testing.assert_equal(

# Path: modred/era.py
# def make_sampled_format(times, Markovs, dt_tol=1e-6):
# def compute_ERA_model(Markovs, num_states):
#     def __init__(
#         self, put_array=util.save_array_text, mc=None, mo=None, verbosity=1):
#     def compute_model(self, Markovs, num_states, mc=None, mo=None):
#     def put_model(self, A_dest, B_dest, C_dest):
#     def put_decomp(
#         self, sing_vals_dest, L_sing_vecs_dest, R_sing_vecs_dest,
#         Hankel_array_dest, Hankel_array2_dest):
#     def put_sing_vals(self, sing_vals_dest):
#     def _set_Markovs(self, Markovs):
#     def _assemble_Hankel(self):
# class ERA(object):
# 
# Path: modred/parallel.py
# def get_hostname():
# def get_node_ID():
# def get_num_nodes():
# def get_num_MPI_workers():
# def get_rank():
# def get_num_procs():
# def is_distributed():
# def is_rank_zero():
# def barrier():
# def print_from_rank_zero(msg, output_channel='stdout'):
# def call_from_rank_zero(func, *args, **kwargs):
# def bcast(vals):
# def call_and_bcast(func, *args, **kwargs):
# def find_assignments(tasks, task_weights=None):
# def check_for_empty_tasks(task_assignments):
# 
# Path: modred/util.py
# class UndefinedError(Exception): pass
# class InnerProductBlock(object):
# def atleast_2d_row(array):
# def atleast_2d_col(array):
# def make_iterable(arg):
# def flatten_list(my_list):
# def save_array_text(array, file_name, delimiter=None):
# def load_array_text(file_name, delimiter=None, is_complex=False):
# def get_file_list(directory, file_extension=None):
# def get_data_members(obj):
# def sum_arrays(arr1, arr2):
# def sum_lists(list1, list2):
# def smart_eq(arg1, arg2):
#     def __init__(self, inner_product):
#     def __call__(self, vecs1, vecs2):
# def svd(array, atol=1e-13, rtol=None):
# def eigh(array, atol=1e-13, rtol=None, is_positive_definite=False):
# def eig_biorthog(array, scale_choice='left'):
# def balanced_truncation(
#     A, B, C, order=None, return_sing_vals=False):
# def drss(num_states, num_inputs, num_outputs):
# def rss(num_states, num_inputs, num_outputs):
# def lsim(A, B, C, inputs, initial_condition=None):
# def impulse(A, B, C, num_time_steps=None):
# def load_signals(signal_path, delimiter=None):
# def load_multiple_signals(signal_paths, delimiter=None):
# def Hankel(first_col, last_row=None):
# def Hankel_chunks(first_col_chunks, last_row_chunks=None):
#     V = V_conj_T.conj().T
#     U = U[:, :num_nonzeros]
#     V = V[:, :num_nonzeros]
#     S = S[:num_nonzeros]
#     A = np.array(A)
#     B = np.array(B)
#     C = np.array(C)
#     U, E, V = svd(Lo.transpose().dot(Lc))
#     SL = Lo.dot(U[:, :order]).dot(np.diag(E[:order]**-0.5))
#     SR = Lc.dot(V[:, :order]).dot(np.diag(E[:order]**-0.5))
#     A = np.real(
#         np.linalg.inv(eig_vecs).dot(np.diag(eig_vals).dot(eig_vecs)))
#     B = np.random.normal(0, 1., (num_states, num_inputs))
#     C = np.random.normal(0, 1., (num_outputs, num_states))
#     A = np.linalg.inv(transformation).dot(np.diag(e_vals)).dot(transformation)
#     B = np.random.random((num_states, num_inputs))
#     C = np.random.random((num_outputs, num_states))
#     A = np.array(A)
#     B = np.array(B)
#     C = np.array(C)
# 
# Path: modred/py2to3.py
# def run_script(path, globals=None, locals=None):
# def print_stdout(msg):
# def print_stderr(msg):
# def print_msg(msg, output_channel='stdout'):


# Path: modred/tests/testera.py
import unittest
import os
import numpy as np
from os.path import join
from shutil import rmtree
from modred import era, parallel, util
from modred.py2to3 import range

                                0, dt=dt).to_tf()
                            tf_model = scipy.signal.StateSpace(
                                A_model,
                                B_model[:, input_idx:input_idx + 1],
                                C_model[output_idx:output_idx + 1, :],
                                0, dt=dt).to_tf()
                            tf_diff = util.sub_transfer_functions(
                                tf_plant, tf_model, dt=dt)

                            # Compute transfer function norms
                            tf_plant_inf_norm = util.compute_inf_norm_discrete(
                                tf_plant, dt)
                            tf_diff_inf_norm = util.compute_inf_norm_discrete(
                                tf_diff, dt)

                            # Test values
                            print 'err_frac', (
                                tf_diff_inf_norm / tf_plant_inf_norm)
                            self.assertTrue(
                                tf_diff_inf_norm / tf_plant_inf_norm <
                                tf_rel_tol)
                    '''

                    # Also test that saved reduced model mats are equal to those
                    # returned in memory
                    np.testing.assert_equal(
                        util.load_array_text(A_path_computed), A_model)
                    np.testing.assert_equal(
                        util.load_array_text(B_path_computed), B_model)
                    np.testing.assert_equal(

                        util.load_array_text(C_path_computed), C_model)