Skip to content

udelal upravu calc_distance, a napsal funkce spatial_points a pytest …#3

Open
IvaNodyanosh wants to merge 3 commits intomainfrom
nodianosh_spatial
Open

udelal upravu calc_distance, a napsal funkce spatial_points a pytest …#3
IvaNodyanosh wants to merge 3 commits intomainfrom
nodianosh_spatial

Conversation

@IvaNodyanosh
Copy link
Copy Markdown
Collaborator

No description provided.

def spatial_points(points_k, points_m, min_distance):
tree = cKDTree(points_m)
result = []

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

max_neighbours = 5

import numpy as np
from scipy.spatial import cKDTree

def spatial_points(points_k, points_m, min_distance):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

points_k -> target_points
points_m -> mixing_points
... i jinde

tree = cKDTree(points_m)
result = []

__, idx = tree.query(points_k, k=5)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment shape : (len(points_k), max_neighbours)


__, idx = tree.query(points_k, k=5)

for i in range(len(points_k)):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vectorize the loops:

point_k shape = ( K, dim); idx.shape = (5, K)

diff = point_k[None, :, :] - points_m[idx[:, :], :]
dist = np.linalg.norm(diff, axis = -1)

import numpy as np
from field_synthesis.functions.spatial_points import spatial_points


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zkusit změřit před a po vektorizaci.

class FieldSynthesis():

def __init__(self, area_size: float, count_points: int, num_source: int, dimension: int = 2, seed: int = 42):
self.area_size = area_size
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dokumentovat atributy.




def generate_points(self):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor as @cached_property:

@cached_property
def anchor_points(self):
...

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.

2 participants