Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/optimise branch building #271

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions polytope_feature/datacube/tensor_index_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ def add_value(self, value):
new_values.sort()
self.values = tuple(new_values)

def add_values(self, values):
new_values = list(self.values)
new_values.extend(values)
new_values.sort()
self.values = tuple(new_values)

def create_child(self, axis, value, next_nodes):
node = TensorIndexTree(axis, (value,))
existing_child = self.find_child(node)
Expand Down
17 changes: 10 additions & 7 deletions polytope_feature/engine/hullslicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def find_values_between(self, polytope, ax, node, datacube, lower, upper):
self.axis_values_between[(flattened_tuple, ax.name, lower, upper, method)] = values
return values

def remap_values(self, ax, value):
def remap_value(self, ax, value):
remapped_val = self.remapped_vals.get((value, ax.name), None)
if remapped_val is None:
remapped_val = value
Expand All @@ -109,6 +109,12 @@ def remap_values(self, ax, value):
self.remapped_vals[(value, ax.name)] = remapped_val
return remapped_val

def remap_values(self, ax, values):
if not isinstance(values, List):
return self.remap_value(ax, values)
remapped_vals = [self.remap_value(ax, val) for val in values]
return remapped_vals

def _build_sliceable_child(self, polytope, ax, node, datacube, values, next_nodes, slice_axis_idx):
for i, value in enumerate(values):
if i == 0 or ax.name not in self.compressed_axes:
Expand All @@ -122,18 +128,17 @@ def _build_sliceable_child(self, polytope, ax, node, datacube, values, next_node
child["unsliced_polytopes"].add(new_polytope)
next_nodes.append(child)
else:
remapped_val = self.remap_values(ax, value)
child.add_value(remapped_val)
remapped_val = self.remap_values(ax, values[1:])
child.add_values(remapped_val)
break

def _build_branch(self, ax, node, datacube, next_nodes):
if ax.name not in self.compressed_axes:
parent_node = node.parent
right_unsliced_polytopes = []
for polytope in node["unsliced_polytopes"]:
if ax.name in polytope._axes:
right_unsliced_polytopes.append(polytope)
for i, polytope in enumerate(right_unsliced_polytopes):
node._parent = parent_node
lower, upper, slice_axis_idx = polytope.extents(ax.name)
# here, first check if the axis is an unsliceable axis and directly build node if it is
# NOTE: we should have already created the ax_is_unsliceable cache before
Expand All @@ -154,9 +159,7 @@ def _build_branch(self, ax, node, datacube, next_nodes):
all_lowers = []
first_polytope = False
first_slice_axis_idx = False
parent_node = node.parent
for polytope in node["unsliced_polytopes"]:
node._parent = parent_node
if ax.name in polytope._axes:
# keep track of the first polytope defined on the given axis
if not first_polytope:
Expand Down
Loading