<commit_before>import numpy as np

import pysdf_tools


def compute_sdf_and_gradient(grid_world, sdf_resolution, sdf_origin, frame='world'):
    """
    :param grid_world: a 2d numpy array of the world full of 0 and 1
    :param sdf_resolution: float in meters
    :param sdf_origin: size 2 np.array (vector) in meters
    :param frame: unused
    :return: a tuple (sdf, sdf_gradient) as numpy arrays
    """
    y_height = grid_world.shape[0] * sdf_resolution
    x_width = grid_world.shape[1] * sdf_resolution
    origin_transform = pysdf_tools.Isometry3d([
        [1.0, 0.0, 0.0, sdf_origin[0]],
        [0.0, 1.0, 0.0, sdf_origin[1]],
        [0.0, 0.0, 1.0, 0.0],
        [0.0, 0.0, 0.0, 1.0]
    ])

    oob_value = pysdf_tools.COLLISION_CELL(-10000)
    occupied_value = pysdf_tools.COLLISION_CELL(1)

    # 2d means this should be one cell in z
    z = sdf_resolution

    grid = pysdf_tools.CollisionMapGrid(origin_transform, frame, sdf_resolution, x_width, y_height, z, oob_value)
    for x_index in range(grid.GetNumXCells()):
        for y_index in range(grid.GetNumYCells()):
            occupied = (grid_world[y_index, x_index] == 1)
            if occupied:
                grid.SetValue(x_index, y_index, 0, occupied_value)
    sdf_result = grid.ExtractSignedDistanceField(oob_value.occupancy, False, False)
    sdf_voxelgrid = sdf_result[0]
    np_sdf = np.array(sdf_voxelgrid.GetRawData())
    # NOTE: when the data is flattened in C++, it is done so in column-major order. In 3d it's z,y,x order meaning that
    #  in memory [x=0,y=0,z=0] is followed by [0,0,1] and [0,0,2].
    #  However, the numpy reshape method assumes row major. Therefore we must transpose.<commit_msg>fix bug in grid creation call<commit_after>import numpy as np

import pysdf_tools


def compute_sdf_and_gradient(grid_world, sdf_resolution, sdf_origin, frame='world'):
    """
    :param grid_world: a 2d numpy array of the world full of 0 and 1
    :param sdf_resolution: float in meters
    :param sdf_origin: size 2 np.array (vector) in meters
    :param frame: unused
    :return: a tuple (sdf, sdf_gradient) as numpy arrays
    """
    y_height = grid_world.shape[0]
    x_width = grid_world.shape[1]
    origin_transform = pysdf_tools.Isometry3d([
        [1.0, 0.0, 0.0, sdf_origin[0]],
        [0.0, 1.0, 0.0, sdf_origin[1]],
        [0.0, 0.0, 1.0, 0.0],
        [0.0, 0.0, 0.0, 1.0]
    ])

    oob_value = pysdf_tools.COLLISION_CELL(-10000)
    occupied_value = pysdf_tools.COLLISION_CELL(1)

    # 2d means this should be one cell in z
    z = 1

    grid = pysdf_tools.CollisionMapGrid(origin_transform, frame, sdf_resolution, x_width, y_height, z, oob_value)
    for x_index in range(grid.GetNumXCells()):
        for y_index in range(grid.GetNumYCells()):
            occupied = (grid_world[y_index, x_index] == 1)
            if occupied:
                grid.SetValue(x_index, y_index, 0, occupied_value)
    sdf_result = grid.ExtractSignedDistanceField(oob_value.occupancy, False, False)
    sdf_voxelgrid = sdf_result[0]
    np_sdf = np.array(sdf_voxelgrid.GetRawData())
    # NOTE: when the data is flattened in C++, it is done so in column-major order. In 3d it's z,y,x order meaning that
    #  in memory [x=0,y=0,z=0] is followed by [0,0,1] and [0,0,2].
    #  However, the numpy reshape method assumes row major. Therefore we must transpose.
{'fraction_non_alphanumeric': 0.11068134483784588, 'fraction_numerical': 0.034216007140731926, 'mean_word_length': 3.2025, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '6687105', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1233, 'n_words': 332}