@@ -144,7 +144,6 @@ impl<const I: usize, const O: usize> NeuralNetwork<I, O> {
144
144
return ;
145
145
}
146
146
147
- let loc = loc. as_ref ( ) ;
148
147
while !cache. is_ready ( loc) {
149
148
// essentially spinlocks until the dependency tasks are complete,
150
149
// while letting this thread do some work on random tasks.
@@ -192,7 +191,9 @@ impl<const I: usize, const O: usize> NeuralNetwork<I, O> {
192
191
}
193
192
194
193
/// 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.
196
197
/// There is no actual UB or unsafe code associated with it.
197
198
pub unsafe fn add_connection_raw ( & mut self , connection : Connection , weight : f32 ) {
198
199
let a = self . get_neuron_mut ( connection. from ) ;
@@ -280,7 +281,7 @@ impl<const I: usize, const O: usize> NeuralNetwork<I, O> {
280
281
let b = self . get_neuron_mut ( connection. to ) ;
281
282
b. input_count -= 1 ;
282
283
283
- if b. input_count < = 0 {
284
+ if b. input_count = = 0 {
284
285
self . remove_neuron ( connection. to ) ;
285
286
return true ;
286
287
}
@@ -420,6 +421,7 @@ impl<const I: usize, const O: usize> DivisionReproduction for NeuralNetwork<I, O
420
421
}
421
422
}
422
423
424
+ #[ allow( clippy:: needless_range_loop) ]
423
425
impl < const I : usize , const O : usize > CrossoverReproduction for NeuralNetwork < I , O > {
424
426
fn crossover ( & self , other : & Self , rng : & mut impl rand:: Rng ) -> Self {
425
427
let mut output_layer = self . output_layer . clone ( ) ;
@@ -591,7 +593,10 @@ impl Neuron {
591
593
}
592
594
593
595
/// 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.
595
600
pub unsafe fn remove_connection ( & mut self , output : impl AsRef < NeuronLocation > ) -> Option < f32 > {
596
601
let loc = * output. as_ref ( ) ;
597
602
let mut i = 0 ;
@@ -841,8 +846,7 @@ impl<const I: usize, const O: usize> From<&NeuralNetwork<I, O>> for NeuralNetCac
841
846
let input_layer: Vec < _ > = net. input_layer . par_iter ( ) . map ( |n| n. into ( ) ) . collect ( ) ;
842
847
let input_layer = input_layer. try_into ( ) . unwrap ( ) ;
843
848
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 ( ) ;
846
850
847
851
let output_layer: Vec < _ > = net. output_layer . par_iter ( ) . map ( |n| n. into ( ) ) . collect ( ) ;
848
852
let output_layer = output_layer. try_into ( ) . unwrap ( ) ;
0 commit comments