Skip to content

Commit

Permalink
[fix] Use dummy variable in for loops if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Kastakin committed Oct 12, 2022
1 parent 7d2a2af commit 3dc1bc5
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/main/python/optimizers/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def fit(self, data):
# Assemble the models and betas matrix
self.model = np.concatenate((comp_model, base_model), axis=1)
self.log_beta_ris = np.concatenate(
(np.array([0 for i in range(self.nc)]), base_log_beta), axis=0
(np.array([0 for _ in range(self.nc)]), base_log_beta), axis=0
)
self.solid_model = solid_model
self.log_ks_ris = base_log_ks
Expand Down Expand Up @@ -270,7 +270,7 @@ def fit(self, data):

# Add ref. ionic strength for components
self.species_ris = np.insert(
self.species_ris, 0, [data["ris"] for i in range(self.nc)]
self.species_ris, 0, [data["ris"] for _ in range(self.nc)]
)
# Calculate square root of reference ionic strength for species
self.species_radqris = np.sqrt(self.species_ris)
Expand Down Expand Up @@ -712,8 +712,8 @@ def _compute(self):
species_conc_calc, log_b, point
)
else:
species_sigma = np.array([None for i in range(self.nc + self.ns)])
solid_sigma = np.array([None for i in range(self.nf)])
species_sigma = np.array([None for _ in range(self.nc + self.ns)])
solid_sigma = np.array([None for _ in range(self.nf)])

# Store calculated species/solid concentration into a vector
results_species_conc.append(species_conc_calc)
Expand Down Expand Up @@ -957,10 +957,10 @@ def _checkSolidsSaturation(self, saturation_index):
False,
)
shifts_to_calculate = np.concatenate(
([True for i in range(self.nc)], cp_to_calculate)
([True for _ in range(self.nc)], cp_to_calculate)
)
else:
shifts_to_calculate = np.array([True for i in range(self.nc)])
shifts_to_calculate = np.array([True for _ in range(self.nc)])

shifts_to_skip = ~shifts_to_calculate

Expand Down Expand Up @@ -988,7 +988,7 @@ def _computeDelta(
def _computeJacobian(self, c_spec, saturation_index, with_solids, to_skip):
if with_solids:
nt = self.nc + self.nf
to_skip = np.concatenate(([False for i in range(self.nc)], to_skip))
to_skip = np.concatenate(([False for _ in range(self.nc)], to_skip))
else:
nt = self.nc

Expand Down Expand Up @@ -1183,9 +1183,9 @@ def _setBHParams(self, species, to_remove, past, zast, c, d, e, solids=False):

if not solids:
# If computing solution species adds values for components
cg = np.insert(cg, 0, [0 for i in range(self.nc)])
dg = np.insert(dg, 0, [0 for i in range(self.nc)])
eg = np.insert(eg, 0, [0 for i in range(self.nc)])
cg = np.insert(cg, 0, [0 for _ in range(self.nc)])
dg = np.insert(dg, 0, [0 for _ in range(self.nc)])
eg = np.insert(eg, 0, [0 for _ in range(self.nc)])

use_reference = (cg == 0) + (dg == 0) + (eg == 0)

Expand All @@ -1211,7 +1211,7 @@ def _damping(self, point, c, cp, log_beta, c_tot, fixed_c):
model = np.delete(model, self.ind_comp, axis=0)
model = np.delete(model, self.ind_comp, axis=1)

coeff = np.array([0 for i in range(nc)])
coeff = np.array([0 for _ in range(nc)])
a0 = np.max(np.where(model == 0, 1, np.abs(model)), axis=1)

iteration = 0
Expand Down Expand Up @@ -1353,7 +1353,7 @@ def _computePercTable(self, cans, calculated_c, model, percent_to, solids=False)
adjust_factor = np.where(adjust_factor <= 0, 1, adjust_factor)
if not solids:
adjust_factor = np.concatenate(
([1 for component in range(self.nc)], adjust_factor), axis=0
([1 for _ in range(self.nc)], adjust_factor), axis=0
)

perc_table = np.where(
Expand Down Expand Up @@ -1471,7 +1471,7 @@ def _computeErrors(self, c_spec, log_b, point):
species_sigma = np.concatenate((comp_sigma, species_sigma))

# TODO: we need to implement propagation error for solid concentrations
solid_sigma = np.array([None for i in range(self.nf)])
solid_sigma = np.array([None for _ in range(self.nf)])

return species_sigma, solid_sigma

Expand Down

0 comments on commit 3dc1bc5

Please sign in to comment.