Skip to content

Commit

Permalink
PERF: Set parameters in one function call
Browse files Browse the repository at this point in the history
Instead of looping through elements, settings parameters in once function should
improve performance. Construct itkOptimizerParameters using parameters list.
  • Loading branch information
PranjalSahu committed Jun 30, 2022
1 parent 0da21c2 commit 9d7880b
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions Wrapping/Generators/Python/itk/support/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,18 +972,12 @@ def update_transform_dict(current_transform):
def transform_from_dict(transform_dict: Dict) -> "itkt.TransformBase":
import itk

def set_parameters(transform, transform_parameters, transform_fixed_parameters):
def set_parameters(transform, transform_parameters, transform_fixed_parameters, data_type):
# First set fixed parameters then parameters
o1 = transform.GetFixedParameters()
o1.SetSize(transform_fixed_parameters.shape[0])
for j, v in enumerate(transform_fixed_parameters):
o1.SetElement(j, v)
o1 = itk.OptimizerParameters[data_type](list(transform_fixed_parameters))
transform.SetFixedParameters(o1)

o2 = transform.GetParameters()
o2.SetSize(transform_parameters.shape[0])
for j, v in enumerate(transform_parameters):
o2.SetElement(j, v)
o2 = itk.OptimizerParameters[data_type](list(transform_parameters))
transform.SetParameters(o2)

# For checking transforms which don't take additional parameters while instantiation
Expand Down Expand Up @@ -1038,6 +1032,7 @@ def special_transform_check(transform_name):
transform,
transform_dict[i]["parameters"],
transform_dict[i]["fixedParameters"],
data_type
)
transforms_list.append(transform)

Expand Down

0 comments on commit 9d7880b

Please sign in to comment.