Repository: scipy/scipy
File: scipy/spatial/transform/_rotation.py (Python)

Code before:
        >>> r.as_quat()
        array([0.        , 0.        , 0.70710678, 0.70710678])
        """
        return Rotation(quat, normalize=True, scalar_first=scalar_first)

    @staticmethod
    @xp_capabilities(
        skip_backends=[("dask.array", "missing linalg.cross/det functions")]
    )
    def from_matrix(matrix: ArrayLike, *, normalize: bool = True) -> Rotation:
        """Initialize from rotation matrix.

        Rotations in 3 dimensions can be represented with 3 x 3 orthogonal
        matrices [1]_. If the input is not orthogonal, an approximation is
        created by orthogonalizing the input matrix using the method described
        in [2]_, and then converting the orthogonal rotation matrices to
        quaternions using the algorithm described in [3]_. Matrices must be
        right-handed.

        Parameters
        ----------
        matrix : array_like, shape (..., 3, 3)
            A single matrix or an ND array of matrices, where the last two dimensions
            contain the rotation matrices.
        normalize : bool, optional
            If True, then the given matrices are orthogonalized via Singular Value
            Decomposition (SVD) to form a valid rotation matrix before the conversion.
            Default is True.

        Returns
        -------
        rotation : `Rotation` instance
            Object containing the rotations represented by the rotation
            matrices.

        References
        ----------
        .. [1] https://en.wikipedia.org/wiki/Rotation_matrix#In_three_dimensions
        .. [2] https://en.wikipedia.org/wiki/Orthogonal_Procrustes_problem
        .. [3] F. Landis Markley, "Unit Quaternion from Rotation Matrix",
               Journal of guidance, control, and dynamics vol. 31.2, pp.
               440-442, 2008.

        Examples
        --------
        >>> from scipy.spatial.transform import Rotation as R
        >>> import numpy as np

        Initialize a single rotation:

        >>> r = R.from_matrix([

Review comment (suggestion):
I'd reword this to something more along the lines of cautioning users to only make this False if the matrix is known orthogonal, as it's unsafe behavior otherwise. Also with the confusion in terminology we've had, should probably specify orthogonal and _unit_ norm.

Code after:
        >>> r.as_quat()
        array([0.        , 0.        , 0.70710678, 0.70710678])
        """
        return Rotation(quat, normalize=True, scalar_first=scalar_first)

    @staticmethod
    @xp_capabilities(
        skip_backends=[("dask.array", "missing linalg.cross/det functions")]
    )
    def from_matrix(matrix: ArrayLike, *, assume_valid: bool = False) -> Rotation:
        """Initialize from rotation matrix.

        Rotations in 3 dimensions can be represented with 3 x 3 orthogonal
        matrices [1]_. If the input is not orthogonal, an approximation is
        created by orthogonalizing the input matrix using the method described
        in [2]_, and then converting the orthogonal rotation matrices to
        quaternions using the algorithm described in [3]_. Matrices must be
        right-handed.

        Parameters
        ----------
        matrix : array_like, shape (..., 3, 3)
            A single matrix or an ND array of matrices, where the last two dimensions
            contain the rotation matrices.
        assume_valid : bool, optional
            Must be False unless users can guarantee the input is a valid rotation
            matrix, i.e. it is orthogonal, rows and columns have unit norm and the
            determinant is 1. Setting this to True without ensuring these properties
            is unsafe and will silently lead to incorrect results. If True,
            normalization steps are skipped, which can improve runtime performance.
            Default is False.

        Returns
        -------
        rotation : `Rotation` instance
            Object containing the rotations represented by the rotation
            matrices.

        References
        ----------
        .. [1] https://en.wikipedia.org/wiki/Rotation_matrix#In_three_dimensions
        .. [2] https://en.wikipedia.org/wiki/Orthogonal_Procrustes_problem
        .. [3] F. Landis Markley, "Unit Quaternion from Rotation Matrix",
               Journal of guidance, control, and dynamics vol. 31.2, pp.
               440-442, 2008.

        Examples
        --------
        >>> from scipy.spatial.transform import Rotation as R
        >>> import numpy as np