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

Code before:
        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 behavior. 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

        Initialize a single rotation:

        >>> r = R.from_matrix([
        ... [0, -1, 0],

Review comment (bug):
Consider strengthening the wording. As is, it's a single word, "unsafe", in a middle of a paragraph. Reading it for the first time I can't help wondering what it means: crashes, segfaults, silently wrong answers, or something else? Some readers can imagine the Rust-popularized meaning, which is I suppose not what it meant here.

Code after:
        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

        Initialize a single rotation:

        >>> r = R.from_matrix([