# 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
            idct(coeffs_sp, type=2, norm='ortho').T,
            type=2, norm='ortho').T
        recon_sp_quarter = idct(
            idct(coeffs_sp_quarter, type=2, norm='ortho').T,
            type=2, norm='ortho').T
        cv2.imwrite(join(outdir, 'recon_scipy.png'), recon_sp) # TODO: switch to xm.io.img
        cv2.imwrite(join(outdir, 'recon_scipy_quarter.png'), recon_sp_quarter) # TODO: switch to xm.io.img
        print("(Ours 1-Step Quarter Recon. vs. SciPy) Max. difference: %e" %
              np.abs(recon_sp_quarter.ravel() - recon_1step_quarter).max())

    elif test_id == 'dft_1d_bases':
        signal = np.random.randint(0, 255, 10)
        n = len(signal)
        # Transform by my matrix
        dft_mat = dft_1d_bases(n)
        coeffs = dft_mat.dot(signal)
        # Transform by NumPy
        coeffs_np = np.fft.fft(signal, norm='ortho')
        print("Max. magnitude difference: %e"
              % np.abs(coeffs - coeffs_np).max())

    elif test_id == 'dft_2d_freq':
        h, w = 4, 8
        freq_h, freq_w = dft_2d_freq(h, w)
        print("Along height:")
        print(freq_h)
        print("Along width:")
        print(freq_w)

    elif test_id == 'dft_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

            idct(coeffs_sp, type=2, norm='ortho').T,
            type=2, norm='ortho').T
        recon_sp_quarter = idct(
            idct(coeffs_sp_quarter, type=2, norm='ortho').T,
            type=2, norm='ortho').T
        cv2.imwrite(join(outdir, 'recon_scipy.png'), recon_sp) # TODO: switch to xm.io.img
        cv2.imwrite(join(outdir, 'recon_scipy_quarter.png'), recon_sp_quarter) # TODO: switch to xm.io.img
        print("(Ours 1-Step Quarter Recon. vs. SciPy) Max. difference: %e" %
              np.abs(recon_sp_quarter.ravel() - recon_1step_quarter).max())

    elif test_id == 'dft_1d_bases':
        signal = np.random.randint(0, 255, 10)
        n = len(signal)
        # Transform by my matrix
        dft_mat = dft_1d_bases(n)
        coeffs = dft_mat.dot(signal)
        # Transform by NumPy
        coeffs_np = np.fft.fft(signal, norm='ortho')
        print("Max. magnitude difference: %e"
              % np.abs(coeffs - coeffs_np).max())

    elif test_id == 'dft_2d_freq':
        h, w = 4, 8
        freq_h, freq_w = dft_2d_freq(h, w)
        print("Along height:")
        print(freq_h)
        print("Along width:")
        print(freq_w)

    elif test_id == 'dft_cameraman':

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