# Path: pyphysim/subspace/projections.py
# @staticmethod
# def calcProjectionMatrix(A: np.ndarray) -> np.ndarray:
#     """
#     Calculates the projection matrix that projects a vector (or a
#     matrix) into the signal space spanned by the columns of `A`.
# 
#     Parameters
#     ----------
#     A : np.ndarray
#         A matrix whose columns form a basis for the desired subspace.
# 
#     Returns
#     -------
#     np.ndarray
#         The projection matrix that can be used to project a vector or a
#         matrix into the subspace spanned by the columns of `A`
# 
#     See also
#     --------
#     calcOrthogonalProjectionMatrix
# 
#     Examples
#     --------
#     >>> A = np.array([[1 + 1j, 2 - 2j], [3 - 2j, 0], \
#                       [-1 - 1j, 2 - 3j]])
#     >>> # Matrix that projects into the subspace spanned by the columns
#     >>> # of A
#     >>> Q = calcProjectionMatrix(A)
#     >>> np.allclose(Q.round(4), np.array( \
#       [[ 0.5239+0.j, 0.0366+0.3296j, 0.3662+0.0732j], \
#        [ 0.0366-0.3296j, 0.7690+0.j, -0.0789+0.2479j], \
#        [ 0.3662-0.0732j, -0.0789-0.2479j, 0.7070-0.j]]))
#     True
#     """
#     # MATLAB version: A/(A'*A)*A';
#     A_H = A.conjugate().transpose()
#     return (A.dot(np.linalg.inv(A_H.dot(A)))).dot(A_H)


import math
import numpy as np
from typing import cast
from .projections import calcProjectionMatrix
    matrix1 : np.ndarray
        A 2D numpy array.
    matrix2 : np.ndarray
        A 2D numpy array.

    Returns
    -------
    chord_dist : float
        The chordal distance.

    Notes
    -----
    Same as :func:`calc_chordal_distance`, but implemented differently.

    See also
    --------
    calc_chordal_distance,
    calc_chordal_distance_from_principal_angles

    Examples
    --------
    >>> A = np.arange(1, 9.)
    >>> A.shape = (4, 2)
    >>> B = np.array([[1.2, 2.1], [2.9, 4.3], [5.2, 6.1], [6.8, 8.1]])
    >>> print(round(calc_chordal_distance_2(A, B), 8))
    0.47386786
    """
    return cast(
        float,  #
        (np.linalg.norm(

# Path: pyphysim/subspace/projections.py
# @staticmethod
# def calcProjectionMatrix(A: np.ndarray) -> np.ndarray:
#     """
#     Calculates the projection matrix that projects a vector (or a
#     matrix) into the signal space spanned by the columns of `A`.
# 
#     Parameters
#     ----------
#     A : np.ndarray
#         A matrix whose columns form a basis for the desired subspace.
# 
#     Returns
#     -------
#     np.ndarray
#         The projection matrix that can be used to project a vector or a
#         matrix into the subspace spanned by the columns of `A`
# 
#     See also
#     --------
#     calcOrthogonalProjectionMatrix
# 
#     Examples
#     --------
#     >>> A = np.array([[1 + 1j, 2 - 2j], [3 - 2j, 0], \
#                       [-1 - 1j, 2 - 3j]])
#     >>> # Matrix that projects into the subspace spanned by the columns
#     >>> # of A
#     >>> Q = calcProjectionMatrix(A)
#     >>> np.allclose(Q.round(4), np.array( \
#       [[ 0.5239+0.j, 0.0366+0.3296j, 0.3662+0.0732j], \
#        [ 0.0366-0.3296j, 0.7690+0.j, -0.0789+0.2479j], \
#        [ 0.3662-0.0732j, -0.0789-0.2479j, 0.7070-0.j]]))
#     True
#     """
#     # MATLAB version: A/(A'*A)*A';
#     A_H = A.conjugate().transpose()
#     return (A.dot(np.linalg.inv(A_H.dot(A)))).dot(A_H)


# Path: pyphysim/subspace/metrics.py
import math
import numpy as np
from typing import cast
from .projections import calcProjectionMatrix

    matrix1 : np.ndarray
        A 2D numpy array.
    matrix2 : np.ndarray
        A 2D numpy array.

    Returns
    -------
    chord_dist : float
        The chordal distance.

    Notes
    -----
    Same as :func:`calc_chordal_distance`, but implemented differently.

    See also
    --------
    calc_chordal_distance,
    calc_chordal_distance_from_principal_angles

    Examples
    --------
    >>> A = np.arange(1, 9.)
    >>> A.shape = (4, 2)
    >>> B = np.array([[1.2, 2.1], [2.9, 4.3], [5.2, 6.1], [6.8, 8.1]])
    >>> print(round(calc_chordal_distance_2(A, B), 8))
    0.47386786
    """
    return cast(
        float,  #
        (np.linalg.norm(

            calcProjectionMatrix(matrix1) - calcProjectionMatrix(matrix2),