# Path: third_party/xiuminglib/xiuminglib/imprt.py
# def preset_import(name, assert_success=False):
#     """A unified importer for both regular and ``google3`` modules, according
#     to specified presets/profiles (e.g., ignoring ``ModuleNotFoundError``).
#     """
#     if name in ('cv2', 'opencv'):
#         try:
#             # BUILD dep:
#             # "//third_party/py/cvx2",
#             from cvx2 import latest as mod
#             # Or
#             # BUILD dep:
#             # "//third_party/OpenCVX:cvx2",
#             # from google3.third_party.OpenCVX import cvx2 as cv2
#         except ModuleNotFoundError:
#             mod = import_module_404ok('cv2')
# 
#     elif name in ('tf', 'tensorflow'):
#         mod = import_module_404ok('tensorflow')
# 
#     elif name == 'gfile':
#         # BUILD deps:
#         # "//pyglib:gfile",
#         # "//file/colossus/cns",
#         mod = import_module_404ok('google3.pyglib.gfile')
# 
#     elif name == 'video_api':
#         # BUILD deps:
#         # "//learning/deepmind/video/python:video_api",
#         mod = import_module_404ok(
#             'google3.learning.deepmind.video.python.video_api')
# 
#     elif name in ('bpy', 'bmesh', 'OpenEXR', 'Imath'):
#         # BUILD deps:
#         # "//third_party/py/Imath",
#         # "//third_party/py/OpenEXR",
#         mod = import_module_404ok(name)
# 
#     elif name in ('Vector', 'Matrix', 'Quaternion'):
#         mod = import_module_404ok('mathutils')
#         mod = _get_module_class(mod, name)
# 
#     elif name == 'BVHTree':
#         mod = import_module_404ok('mathutils.bvhtree')
#         mod = _get_module_class(mod, name)
# 
#     else:
#         raise NotImplementedError(name)
# 
#     if assert_success:
#         assert mod is not None, "Failed in importing '%s'" % name
# 
#     return mod


import numpy as np
from .imprt import preset_import
    from scipy.sparse import issparse
    from scipy.sparse.linalg import eigsh
    from scipy.special import sph_harm
        from scipy.fftpack import dct
        from . import linalg
        from os.path import join
        from copy import deepcopy
        from scipy.fftpack import dct, idct
        from . import const, os as xm_os
        from .vis.matrix import matrix_as_heatmap, matrix_as_heatmap_complex
        from os.path import join
        from . import os as xm_os
        from .vis.matrix import matrix_as_heatmap_complex
        from os.path import join
        from .vis.matrix import matrix_as_heatmap
    from argparse import ArgumentParser
def main(test_id):
    """Unit tests that can also serve as example usage."""
    if test_id == 'pca':
        pts = np.random.rand(5, 8) # 8 points in 5D
        # Find all principal components
        n_pcs = pts.shape[0] - 1
        _, pcs, projs, data_mean = pca(pts, n_pcs=n_pcs)
        # Reconstruct data with only the top two PC's
        k = 2
        pts_recon = pcs[:, :k].dot(projs[:k, :]) + \
            np.tile(data_mean, (projs.shape[1], 1)).T
        print("Recon:")
        print(pts_recon)

    elif test_id == 'dct_1d_bases':
        signal = np.random.randint(0, 255, 8)
        n = len(signal)
        # Transform by my matrix
        dct_mat = dct_1d_bases(n)
        assert linalg.is_identity(dct_mat.T.dot(dct_mat), eps=1e-10)
        coeffs = dct_mat.dot(signal)
        recon = dct_mat.T.dot(coeffs)
        print("Max. difference between original and recon.: %e"
              % np.abs(signal - recon).max())
        # Transform by SciPy
        coeffs_sp = dct(signal, norm='ortho')
        print("Max. magnitude difference: %e"
              % np.abs(coeffs - coeffs_sp).max())

    elif test_id == 'dct_cameraman':

# Path: third_party/xiuminglib/xiuminglib/imprt.py
# def preset_import(name, assert_success=False):
#     """A unified importer for both regular and ``google3`` modules, according
#     to specified presets/profiles (e.g., ignoring ``ModuleNotFoundError``).
#     """
#     if name in ('cv2', 'opencv'):
#         try:
#             # BUILD dep:
#             # "//third_party/py/cvx2",
#             from cvx2 import latest as mod
#             # Or
#             # BUILD dep:
#             # "//third_party/OpenCVX:cvx2",
#             # from google3.third_party.OpenCVX import cvx2 as cv2
#         except ModuleNotFoundError:
#             mod = import_module_404ok('cv2')
# 
#     elif name in ('tf', 'tensorflow'):
#         mod = import_module_404ok('tensorflow')
# 
#     elif name == 'gfile':
#         # BUILD deps:
#         # "//pyglib:gfile",
#         # "//file/colossus/cns",
#         mod = import_module_404ok('google3.pyglib.gfile')
# 
#     elif name == 'video_api':
#         # BUILD deps:
#         # "//learning/deepmind/video/python:video_api",
#         mod = import_module_404ok(
#             'google3.learning.deepmind.video.python.video_api')
# 
#     elif name in ('bpy', 'bmesh', 'OpenEXR', 'Imath'):
#         # BUILD deps:
#         # "//third_party/py/Imath",
#         # "//third_party/py/OpenEXR",
#         mod = import_module_404ok(name)
# 
#     elif name in ('Vector', 'Matrix', 'Quaternion'):
#         mod = import_module_404ok('mathutils')
#         mod = _get_module_class(mod, name)
# 
#     elif name == 'BVHTree':
#         mod = import_module_404ok('mathutils.bvhtree')
#         mod = _get_module_class(mod, name)
# 
#     else:
#         raise NotImplementedError(name)
# 
#     if assert_success:
#         assert mod is not None, "Failed in importing '%s'" % name
# 
#     return mod


# Path: third_party/xiuminglib/xiuminglib/sig.py
import numpy as np
from .imprt import preset_import
    from scipy.sparse import issparse
    from scipy.sparse.linalg import eigsh
    from scipy.special import sph_harm
        from scipy.fftpack import dct
        from . import linalg
        from os.path import join
        from copy import deepcopy
        from scipy.fftpack import dct, idct
        from . import const, os as xm_os
        from .vis.matrix import matrix_as_heatmap, matrix_as_heatmap_complex
        from os.path import join
        from . import os as xm_os
        from .vis.matrix import matrix_as_heatmap_complex
        from os.path import join
        from .vis.matrix import matrix_as_heatmap
    from argparse import ArgumentParser

def main(test_id):
    """Unit tests that can also serve as example usage."""
    if test_id == 'pca':
        pts = np.random.rand(5, 8) # 8 points in 5D
        # Find all principal components
        n_pcs = pts.shape[0] - 1
        _, pcs, projs, data_mean = pca(pts, n_pcs=n_pcs)
        # Reconstruct data with only the top two PC's
        k = 2
        pts_recon = pcs[:, :k].dot(projs[:k, :]) + \
            np.tile(data_mean, (projs.shape[1], 1)).T
        print("Recon:")
        print(pts_recon)

    elif test_id == 'dct_1d_bases':
        signal = np.random.randint(0, 255, 8)
        n = len(signal)
        # Transform by my matrix
        dct_mat = dct_1d_bases(n)
        assert linalg.is_identity(dct_mat.T.dot(dct_mat), eps=1e-10)
        coeffs = dct_mat.dot(signal)
        recon = dct_mat.T.dot(coeffs)
        print("Max. difference between original and recon.: %e"
              % np.abs(signal - recon).max())
        # Transform by SciPy
        coeffs_sp = dct(signal, norm='ortho')
        print("Max. magnitude difference: %e"
              % np.abs(coeffs - coeffs_sp).max())

    elif test_id == 'dct_cameraman':

        cv2 = preset_import('cv2', assert_success=True)