<commit_before>import numpy as np
from .matutils import mkvc


def cyl2cart(grid):
    """
    Take a grid defined in cylindrical coordinates :math:`(r, \theta, z)` and
    transform it to cartesian coordinates.
    """
    grid = np.atleast_2d(grid)
    return np.hstack([
        mkvc(grid[:, 0]*np.cos(grid[:, 1]), 2),
        mkvc(grid[:, 0]*np.sin(grid[:, 1]), 2),
        mkvc(grid[:, 2], 2)
    ])


def rotationMatrixFromNormals(v0, v1, tol=1e-20):
    """
    Performs the minimum number of rotations to define a rotation from the
    direction indicated by the vector n0 to the direction indicated by n1.
    The axis of rotation is n0 x n1
    https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula

    :param numpy.array v0: vector of length 3
    :param numpy.array v1: vector of length 3
    :param tol = 1e-20: tolerance. If the norm of the cross product between the two vectors is below this, no rotation is performed
    :rtype: numpy.array, 3x3
    :return: rotation matrix which rotates the frame so that n0 is aligned with n1
    """

    # ensure both n0, n1 are vectors of length 1
    assert len(v0) == 3, "Length of n0 should be 3"
    assert len(v1) == 3, "Length of n1 should be 3"

    # ensure both are true normals
    n0 = v0*1./np.linalg.norm(v0)
    n1 = v1*1./np.linalg.norm(v1)

    n0dotn1 = n0.dot(n1)

    # define the rotation axis, which is the cross product of the two vectors<commit_msg>Add a cart2cyl utility<commit_after>import numpy as np
from .matutils import mkvc


def cyl2cart(grid):
    """
    Take a grid defined in cylindrical coordinates :math:`(r, \theta, z)` and
    transform it to cartesian coordinates.
    """
    grid = np.atleast_2d(grid)
    return np.hstack([
        mkvc(grid[:, 0]*np.cos(grid[:, 1]), 2),
        mkvc(grid[:, 0]*np.sin(grid[:, 1]), 2),
        mkvc(grid[:, 2], 2)
    ])


def cart2cyl(grid, points=None):
    """
    Take a grid defined in cartesian coordinates and transform it to cyl
    coordinates
    """
    if points is None:
        points = grid

    points = np.atleast_2d(points)
    grid = np.atleast_2d(grid)

    theta = np.arctan2(grid[:, 1], grid[:, 0])

    return np.hstack([
        mkvc(np.cos(theta)*points[:, 0] + np.sin(theta)*points[:, 1], 2),
        mkvc(-np.sin(theta)*points[:, 0] + np.cos(theta)*points[:, 1], 2),
        mkvc(points[:, 2], 2)
    ])


def rotationMatrixFromNormals(v0, v1, tol=1e-20):
    """
    Performs the minimum number of rotations to define a rotation from the
    direction indicated by the vector n0 to the direction indicated by n1.
    The axis of rotation is n0 x n1
    https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula

    :param numpy.array v0: vector of length 3
    :param numpy.array v1: vector of length 3
    :param tol = 1e-20: tolerance. If the norm of the cross product between the two vectors is below this, no rotation is performed
    :rtype: numpy.array, 3x3
    :return: rotation matrix which rotates the frame so that n0 is aligned with n1
    """

    # ensure both n0, n1 are vectors of length 1
    assert len(v0) == 3, "Length of n0 should be 3"
    assert len(v1) == 3, "Length of n1 should be 3"

    # ensure both are true normals
    n0 = v0*1./np.linalg.norm(v0)
    n1 = v1*1./np.linalg.norm(v1)

    n0dotn1 = n0.dot(n1)

    # define the rotation axis, which is the cross product of the two vectors
{'fraction_non_alphanumeric': 0.11485090050191911, 'fraction_numerical': 0.03690581635665781, 'mean_word_length': 2.8987341772151898, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6176254', 'n_tokens_mistral': 1201, 'n_tokens_neox': 1131, 'n_words': 412}