SUPPORTED_BACKENDS = ("Autograd", "Callable", "PyTorch", "TensorFlow")
    X = matrix / la.norm(matrix, axis=0)[np.newaxis, :]
def create_cost_egrad(manifold, matrix, backend):
        def cost(X):
        def cost(X):
        def egrad(X):
        def cost(X):
        def cost(X):
def run(backend=SUPPORTED_BACKENDS[0], quiet=True): SUPPORTED_BACKENDS = ("Autograd", "Callable", "PyTorch", "TensorFlow")
def create_cost_egrad(manifold, matrix, backend):
        def cost(x):
        def cost(x):
        def egrad(x):
        def cost(x):
        def cost(x):
def run(backend=SUPPORTED_BACKENDS[0], quiet=True): SUPPORTED_BACKENDS = ("Autograd", "Callable", "PyTorch", "TensorFlow")
def create_cost_egrad_ehess(manifold, matrix, backend):
        def cost(X):
        def cost(X):
        def egrad(X):
        def ehess(X, H):
        def cost(X):
        def cost(X):
        def egrad(X):
def run(backend=SUPPORTED_BACKENDS[0], quiet=True): SUPPORTED_BACKENDS = ("Autograd", "Callable", "PyTorch", "TensorFlow")
            X = u @ np.diag(s) @ vt
            X = u @ np.diag(s) @ vt
            X = u @ np.diag(s) @ vt
            S = np.diag(s)
            X = torch.matmul(u, torch.matmul(torch.diag(s), vt))
            X = tf.matmul(u, tf.matmul(tf.linalg.diag(s), vt))
def create_cost_egrad(manifold, matrix, backend):
        def cost(u, s, vt):
        def cost(u, s, vt):
        def egrad(u, s, vt):
        def cost(u, s, vt):
        def cost(u, s, vt):
def run(backend=SUPPORTED_BACKENDS[0], quiet=True): SUPPORTED_BACKENDS = ("Autograd", "Callable", "PyTorch", "TensorFlow")
            X = torch.matmul(Y, torch.transpose(Y, 1, 0))
            X = tf.matmul(Y, tf.transpose(Y))
def create_cost_egrad_ehess(manifold, matrix, backend):
        def cost(Y):
        def cost(Y):
        def egrad(Y):
        def ehess(Y, U):
        def cost(Y):
        def cost(Y):
def run(backend=SUPPORTED_BACKENDS[0], quiet=True): SUPPORTED_BACKENDS = ("Autograd", "Callable", "PyTorch", "TensorFlow")
def create_cost_egrad_ehess(manifold, samples, targets, backend):
        def cost(weights):
        def cost(weights):
        def egrad(weights):
        def ehess(weights, vector):
        def cost(weights):
        def cost(weights):
def run(backend=SUPPORTED_BACKENDS[0], quiet=True): SUPPORTED_BACKENDS = ("Autograd", "Callable", "PyTorch", "TensorFlow")
    J = np.append(np.ones(n - 1), -1)
    A = np.random.randn(k, n, m)
    B = np.random.randn(k, n, m)
    X = solver.solve(problem)
def create_cost_egrad(manifold, ABt, backend):
        def cost(X):
        def cost(X):
        def egrad(X):
        def cost(X):
        def cost(X):
def compute_optimal_solution(ABt):
def run(backend=SUPPORTED_BACKENDS[0], quiet=True): SUPPORTED_BACKENDS = ("Autograd", "PyTorch", "TensorFlow")
            Y = X @ X.T
            Y = torch.matmul(X, torch.transpose(X, 1, 0))
            Y = tf.matmul(X, tf.transpose(X))
def create_cost(manifold, epsilon, backend):
        def cost(X):
        def cost(X):
        def cost(X):
def run(backend=SUPPORTED_BACKENDS[0], quiet=True): SUPPORTED_BACKENDS = ("Autograd", "Callable", "PyTorch", "TensorFlow")
def create_cost_egrad_ehess(manifold, samples, backend):
        def cost(w):
        def cost(w):
        def egrad(w):
        def ehess(w, h):
        def cost(w):
        def cost(w):
def run(backend=SUPPORTED_BACKENDS[0], quiet=True): SUPPORTED_BACKENDS = ("Autograd", "Callable", "PyTorch", "TensorFlow")
    X = solver.solve(problem)
    C = X.T @ X
def create_cost_egrad_ehess(manifold, matrix, backend):
        def cost(X):
        def cost(X):
        def egrad(X):
        def ehess(X, H):
        def cost(X):
        def cost(X):
def run(backend=SUPPORTED_BACKENDS[0], quiet=True): SUPPORTED_BACKENDS = ("Autograd", "Callable", "PyTorch", "TensorFlow")
def create_cost_egrad(manifold, matrix, backend):
        def cost(x):
        def cost(x):
        def egrad(x):
        def cost(x):
        def cost(x):
def run(backend=SUPPORTED_BACKENDS[0], quiet=True):
import matplotlib
from nose2.tools import params
from examples import (
    closest_unit_norm_column_approximation,
    dominant_eigenvector,
    dominant_invariant_subspace,
    low_rank_matrix_approximation,
    low_rank_psd_matrix_approximation,
    multiple_linear_regression,
    optimal_rotations,
    packing_on_the_sphere,
    pca,
    rank_k_correlation_matrix_approximation,
)
from examples.advanced import check_gradient
from ._test import TestCase




class TestExamples(TestCase):
    @params(*closest_unit_norm_column_approximation.SUPPORTED_BACKENDS)
    def test_closest_unit_norm_column_approximation(self, backend):
        closest_unit_norm_column_approximation.run(backend)

    @params(*dominant_eigenvector.SUPPORTED_BACKENDS)
    def test_dominant_eigenvector(self, backend):
        dominant_eigenvector.run(backend)

    @params(*dominant_invariant_subspace.SUPPORTED_BACKENDS)
    def test_dominant_invariant_subspace(self, backend):
        dominant_invariant_subspace.run(backend)

    @params(*low_rank_matrix_approximation.SUPPORTED_BACKENDS)
    def test_low_rank_matrix_approximation(self, backend):
        low_rank_matrix_approximation.run(backend)

    @params(*low_rank_psd_matrix_approximation.SUPPORTED_BACKENDS)
    def test_low_rank_psd_matrix_approximation(self, backend):
        low_rank_psd_matrix_approximation.run(backend)

    @params(*multiple_linear_regression.SUPPORTED_BACKENDS)
    def test_multiple_linear_regression(self, backend):
        multiple_linear_regression.run(backend)

    @params(*optimal_rotations.SUPPORTED_BACKENDS)
    def test_optimal_rotations(self, backend):
        optimal_rotations.run(backend)

    @params(*packing_on_the_sphere.SUPPORTED_BACKENDS)
    def test_packing_on_the_sphere(self, backend):
        packing_on_the_sphere.run(backend)


    @params(*pca.SUPPORTED_BACKENDS)