Skip to content

Commit 0a958f9

Browse files
committed
solve clippy errors
1 parent 31b6e7d commit 0a958f9

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/neuralnet.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ impl<const I: usize, const O: usize> NeuralNetwork<I, O> {
144144
return;
145145
}
146146

147-
let loc = loc.as_ref();
148147
while !cache.is_ready(loc) {
149148
// essentially spinlocks until the dependency tasks are complete,
150149
// while letting this thread do some work on random tasks.
@@ -192,7 +191,9 @@ impl<const I: usize, const O: usize> NeuralNetwork<I, O> {
192191
}
193192

194193
/// Adds a connection but does not check for cyclic linkages.
195-
/// Marked as unsafe because it could cause a hang/livelock when predicting due to cyclic linkage.
194+
///
195+
/// # Safety
196+
/// This is marked as unsafe because it could cause a hang/livelock when predicting due to cyclic linkage.
196197
/// There is no actual UB or unsafe code associated with it.
197198
pub unsafe fn add_connection_raw(&mut self, connection: Connection, weight: f32) {
198199
let a = self.get_neuron_mut(connection.from);
@@ -280,7 +281,7 @@ impl<const I: usize, const O: usize> NeuralNetwork<I, O> {
280281
let b = self.get_neuron_mut(connection.to);
281282
b.input_count -= 1;
282283

283-
if b.input_count <= 0 {
284+
if b.input_count == 0 {
284285
self.remove_neuron(connection.to);
285286
return true;
286287
}
@@ -420,6 +421,7 @@ impl<const I: usize, const O: usize> DivisionReproduction for NeuralNetwork<I, O
420421
}
421422
}
422423

424+
#[allow(clippy::needless_range_loop)]
423425
impl<const I: usize, const O: usize> CrossoverReproduction for NeuralNetwork<I, O> {
424426
fn crossover(&self, other: &Self, rng: &mut impl rand::Rng) -> Self {
425427
let mut output_layer = self.output_layer.clone();
@@ -591,7 +593,10 @@ impl Neuron {
591593
}
592594

593595
/// Tries to remove a connection from the neuron and returns the weight if it was found.
594-
/// Marked as unsafe because it will not update the destination's [`input_count`][Neuron::input_count].
596+
///
597+
/// # Safety
598+
/// This is marked as unsafe because it will not update the destination's [`input_count`][Neuron::input_count].
599+
/// Similar to [`add_connection_raw`][NeuralNetwork::add_connection_raw], this does not mean UB or anything.
595600
pub unsafe fn remove_connection(&mut self, output: impl AsRef<NeuronLocation>) -> Option<f32> {
596601
let loc = *output.as_ref();
597602
let mut i = 0;
@@ -841,8 +846,7 @@ impl<const I: usize, const O: usize> From<&NeuralNetwork<I, O>> for NeuralNetCac
841846
let input_layer: Vec<_> = net.input_layer.par_iter().map(|n| n.into()).collect();
842847
let input_layer = input_layer.try_into().unwrap();
843848

844-
let hidden_layers: Vec<_> = net.hidden_layers.par_iter().map(|n| n.into()).collect();
845-
let hidden_layers = hidden_layers.try_into().unwrap();
849+
let hidden_layers = net.hidden_layers.par_iter().map(|n| n.into()).collect();
846850

847851
let output_layer: Vec<_> = net.output_layer.par_iter().map(|n| n.into()).collect();
848852
let output_layer = output_layer.try_into().unwrap();

0 commit comments

Comments
 (0)