<commit_before># A marching cube test
import numpy as np

try:
    import numba as nb
    numba_present = True
except ImportError:
    import warnings
    warnings.warn(
        "Numba not installed. The isosurface generation will be extremely slow",
        ImportWarning)
    numba_present = False

def marching_cubes(field, isolevel):
    # The field is like gridpoints, and gridpoints define cubes.
    triangles = []
    # Here we determine the value for each field
    for i in range(field.shape[0] - 1):
        for j in range(field.shape[1] - 1):
            for k in range(field.shape[2] - 1):

                points = {
                    0: (i, j, k),
                    1: (i, j+1, k),
                    2: (i+1, j+1, k),
                    3: (i+1, j, k),
                    4: (i, j, k+1),
                    5: (i, j+1, k+1),
                    6: (i+1, j+1, k+1),
                    7: (i+1, j, k+1)
                }
                # Which kind of cube is this guy?
                cube_index = 0
                if field[points[0]] < isolevel: cube_index |= 1
                if field[points[1]] < isolevel: cube_index |= 2
                if field[points[2]] < isolevel: cube_index |= 4
                if field[points[3]] < isolevel: cube_index |= 8
                if field[points[4]] < isolevel: cube_index |= 16
                if field[points[5]] < isolevel: cube_index |= 32
                if field[points[6]] < isolevel: cube_index |= 64
                if field[points[7]] < isolevel: cube_index |= 128

                # Get the faces from the cube

                for e1,e2,e3 in tris_as_edges[cube_index]:
                    # Get the three interpolated points on the edges
                    triangle = []
                    for edge in (e1, e2, e3):
                        s, e = edge2pts[edge]
                        p1, p2 = np.array(points[e], 'f'), np.array(points[s], 'f')
                        v = interpolate_edge_coordinates(p1, field[points[e]],
                                                         p2, field[points[s]],
                                                         isolevel)
                        triangle.append(v)
                    triangles.append(triangle)
    triangles_ = np.array(triangles) # triangles_ NUMBA BUG

    if len(triangles) == 0:
        return np.array([])

    # TODO Let's just invert for now, but no one knows what the problem is
    triangles_[:, :, [0, 1]] = triangles_[:, :, [1, 0]]
    return triangles_



def interpolate_edge_coordinates(point1, value1, point2, value2, isolevel):
    return point1 + (isolevel - value1) * (point2 - point1)/(value2 - value1)

if numba_present:
    marching_cubes = nb.jit('pyobject(f4[:, :, :], f4)')(marching_cubes)
    interpolate_edge_coordinates = np.jit(interpolate_edge_coordinates)

# Returns the vertices that make up an edge
edge2pts = [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),
            (0,4),(1,5),(2,6),(3,7)]

# For a given case (0-255), this array yields the corresponding
# triangles, given as a tuple of three edges
tris_as_edges = [
    [],
    [(0, 8, 3)],
    [(0, 1, 9)],
    [(1, 8, 3), (9, 8, 1)],
    [(1, 2, 10)],
    [(0, 8, 3), (1, 2, 10)],<commit_msg>Minor mistake<commit_after># A marching cube test
import numpy as np

try:
    import numba as nb
    numba_present = True
except ImportError:
    import warnings
    warnings.warn(
        "Numba not installed. The isosurface generation will be extremely slow",
        ImportWarning)
    numba_present = False

def marching_cubes(field, isolevel):
    # The field is like gridpoints, and gridpoints define cubes.
    triangles = []
    # Here we determine the value for each field
    for i in range(field.shape[0] - 1):
        for j in range(field.shape[1] - 1):
            for k in range(field.shape[2] - 1):

                points = {
                    0: (i, j, k),
                    1: (i, j+1, k),
                    2: (i+1, j+1, k),
                    3: (i+1, j, k),
                    4: (i, j, k+1),
                    5: (i, j+1, k+1),
                    6: (i+1, j+1, k+1),
                    7: (i+1, j, k+1)
                }
                # Which kind of cube is this guy?
                cube_index = 0
                if field[points[0]] < isolevel: cube_index |= 1
                if field[points[1]] < isolevel: cube_index |= 2
                if field[points[2]] < isolevel: cube_index |= 4
                if field[points[3]] < isolevel: cube_index |= 8
                if field[points[4]] < isolevel: cube_index |= 16
                if field[points[5]] < isolevel: cube_index |= 32
                if field[points[6]] < isolevel: cube_index |= 64
                if field[points[7]] < isolevel: cube_index |= 128

                # Get the faces from the cube

                for e1,e2,e3 in tris_as_edges[cube_index]:
                    # Get the three interpolated points on the edges
                    triangle = []
                    for edge in (e1, e2, e3):
                        s, e = edge2pts[edge]
                        p1, p2 = np.array(points[e], 'f'), np.array(points[s], 'f')
                        v = interpolate_edge_coordinates(p1, field[points[e]],
                                                         p2, field[points[s]],
                                                         isolevel)
                        triangle.append(v)
                    triangles.append(triangle)
    triangles_ = np.array(triangles) # triangles_ NUMBA BUG

    if len(triangles) == 0:
        return np.array([])

    # TODO Let's just invert for now, but no one knows what the problem is
    triangles_[:, :, [0, 1]] = triangles_[:, :, [1, 0]]
    return triangles_



def interpolate_edge_coordinates(point1, value1, point2, value2, isolevel):
    return point1 + (isolevel - value1) * (point2 - point1)/(value2 - value1)

if numba_present:
    marching_cubes = nb.jit('pyobject(f4[:, :, :], f4)')(marching_cubes)
    interpolate_edge_coordinates = nb.jit(interpolate_edge_coordinates)

# Returns the vertices that make up an edge
edge2pts = [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),
            (0,4),(1,5),(2,6),(3,7)]

# For a given case (0-255), this array yields the corresponding
# triangles, given as a tuple of three edges
tris_as_edges = [
    [],
    [(0, 8, 3)],
    [(0, 1, 9)],
    [(1, 8, 3), (9, 8, 1)],
    [(1, 2, 10)],
    [(0, 8, 3), (1, 2, 10)],
{'fraction_non_alphanumeric': 0.13048855905998763, 'fraction_numerical': 0.039579468150896725, 'mean_word_length': 1.664332784184514, 'pattern_counts': {'":': 0, '<': 19, '<?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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6854702', 'n_tokens_mistral': 2274, 'n_tokens_neox': 2031, 'n_words': 594}