Skip to content

Commit 19d5127

Browse files
further reducing use of numpy arrays for representing configs
1 parent b170eef commit 19d5127

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

kernel_tuner/strategies/diff_evo.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def mutate_de_2(best_idx, randos_idx, F, min_idx, max_idx, best):
338338
def binomial_crossover(donor_vector, target, CR):
339339
"""Performs binomial crossover of donor_vector with target given crossover rate CR."""
340340
# Create the trial vector by mixing parameters from the target and donor vectors
341-
trial_vector = np.copy(target)
341+
trial_vector = target.copy()
342342
dimensions = len(donor_vector)
343343

344344
# Generate a random array of floats for comparison with the crossover rate CR
@@ -350,9 +350,11 @@ def binomial_crossover(donor_vector, target, CR):
350350
crossover_points[np.random.randint(0, dimensions)] = True
351351

352352
# Apply crossover
353-
trial_vector[crossover_points] = np.array(donor_vector)[crossover_points]
353+
for i, d in enumerate(donor_vector):
354+
if crossover_points[i]:
355+
trial_vector[i] = donor_vector[i]
354356

355-
return list(trial_vector)
357+
return trial_vector
356358

357359

358360
def exponential_crossover(donor_vector, target, CR):
@@ -363,7 +365,7 @@ def exponential_crossover(donor_vector, target, CR):
363365
from the donor vector and the rest from the target vector.
364366
"""
365367
dimensions = len(target)
366-
trial_idx = np.copy(target)
368+
trial_vector = target.copy()
367369

368370
# 1. Select a random starting point for the crossover block.
369371
start_point = np.random.randint(0, dimensions)
@@ -374,10 +376,10 @@ def exponential_crossover(donor_vector, target, CR):
374376
l = 0
375377
while np.random.rand() < CR and l < dimensions:
376378
crossover_point = (start_point + l) % dimensions
377-
trial_idx[crossover_point] = np.array(donor_vector)[crossover_point]
379+
trial_vector[crossover_point] = donor_vector[crossover_point]
378380
l += 1
379381

380-
return list(trial_idx)
382+
return trial_vector
381383

382384

383385
def repair(trial_vector, searchspace):

0 commit comments

Comments
 (0)