Skip to content

Removing loop from build_dual_from_vertices - #490

Open
lassejsc wants to merge 2 commits into
fmihpc:devfrom
lassejsc:buildDualsTrick
Open

Removing loop from build_dual_from_vertices#490
lassejsc wants to merge 2 commits into
fmihpc:devfrom
lassejsc:buildDualsTrick

Conversation

@lassejsc

@lassejsc lassejsc commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Found a trick to remove the loop sort of by accident. it does make it slightly faster.

For example for

    f = pt.vlsvfile.VlsvReader(name)
    x, y, z = np.meshgrid(
        np.linspace(0, 16, 100000), np.linspace(0, 2, 20), np.linspace(0, 2, 20)
    )
    x = dx * x * np.random.random()
    y = dx * y * np.random.random()
    z = dx * z * np.random.random()

    coor = np.vstack([x.ravel(), y.ravel(), z.ravel()]).T
    cell_vertex_sets = f.get_cell_corner_vertices(
        coorpy
    )  # these are enough to fetch the neighbours
    cell_neighbor_sets = {c: set() for c in cell_vertex_sets.keys()}
    vertices_todo = set().union(*cell_vertex_sets.values())
    
    # print(coor)
    t0 = time.time()
    arr1 = f.build_dual_from_vertices(vertices_todo)
    # print("python arr",arr)
    t1 = time.time() - t0
    f = pt.vlsvfile.VlsvReader(name)
    t0 = time.time()
    arr2 = f.build_dual_from_vertices_new(vertices_todo)
    t2 = time.time() - t0

Over ten runs gives me speed up of t1/t2 with mean t1 and t2 as

means 1.5215530983190788 old avg 0.010848474502563477 new avg 0.007144737243652344

also checked that the bboxes it produces and the output remain the same

@lassejsc
lassejsc marked this pull request as ready for review July 27, 2026 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant