Enable weight tracking. Backfills existing buffer entries with 1.0.
(&mut self)
| 12 | impl CsrIndex { |
| 13 | /// Enable weight tracking. Backfills existing buffer entries with 1.0. |
| 14 | pub(crate) fn enable_weights(&mut self) { |
| 15 | self.has_weights = true; |
| 16 | |
| 17 | // Backfill existing dense arrays with 1.0. |
| 18 | if !self.out_targets.is_empty() { |
| 19 | self.out_weights = Some(vec![1.0; self.out_targets.len()].into()); |
| 20 | } |
| 21 | if !self.in_targets.is_empty() { |
| 22 | self.in_weights = Some(vec![1.0; self.in_targets.len()].into()); |
| 23 | } |
| 24 | |
| 25 | // Backfill existing buffer entries with 1.0. |
| 26 | for (buf, wbuf) in self |
| 27 | .buffer_out |
| 28 | .iter() |
| 29 | .zip(self.buffer_out_weights.iter_mut()) |
| 30 | { |
| 31 | if wbuf.len() < buf.len() { |
| 32 | wbuf.resize(buf.len(), 1.0); |
| 33 | } |
| 34 | } |
| 35 | for (buf, wbuf) in self.buffer_in.iter().zip(self.buffer_in_weights.iter_mut()) { |
| 36 | if wbuf.len() < buf.len() { |
| 37 | wbuf.resize(buf.len(), 1.0); |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | /// Whether this CSR has any weighted edges. |
| 43 | pub fn has_weights(&self) -> bool { |
no test coverage detected