This commit is contained in:
Andras Schmelczer 2026-03-15 17:38:26 +00:00
parent 80c093b7ba
commit f72c43a9fa
101 changed files with 2168 additions and 1177 deletions

View file

@ -1,3 +1,6 @@
use crate::consts::NAN_U16;
use crate::data::QuantRef;
/// Per-cell accumulator for aggregating features (min/max/sum/count).
/// Uses Box<[T]> instead of Vec<T> to avoid storing capacity (saves 8 bytes per field per cell).
/// Shared by hexagon and postcode aggregation routes.
@ -20,16 +23,23 @@ impl Aggregator {
}
}
/// Add a row using row-major feature_data layout.
/// Add a row using row-major feature_data layout (quantized u16).
/// feature_data[row * num_features + feat_idx] — all features for one row
/// are contiguous, so this reads a single cache line per ~8 features.
/// are contiguous, so this reads a single cache line per ~16 features.
#[inline]
pub fn add_row(&mut self, feature_data: &[f32], row: usize, num_features: usize) {
pub fn add_row(
&mut self,
feature_data: &[u16],
row: usize,
num_features: usize,
quant: &QuantRef,
) {
self.count += 1;
let base = row * num_features;
let row_slice = &feature_data[base..base + num_features];
for (feat_index, &value) in row_slice.iter().enumerate() {
if value.is_finite() {
for (feat_index, &raw) in row_slice.iter().enumerate() {
if raw != NAN_U16 {
let value = quant.decode(feat_index, raw);
if value < self.mins[feat_index] {
self.mins[feat_index] = value;
}
@ -46,16 +56,18 @@ impl Aggregator {
#[inline]
pub fn add_row_selective(
&mut self,
feature_data: &[f32],
feature_data: &[u16],
row: usize,
num_features: usize,
indices: &[usize],
quant: &QuantRef,
) {
self.count += 1;
let base = row * num_features;
for &feat_index in indices {
let value = feature_data[base + feat_index];
if value.is_finite() {
let raw = feature_data[base + feat_index];
if raw != NAN_U16 {
let value = quant.decode(feat_index, raw);
if value < self.mins[feat_index] {
self.mins[feat_index] = value;
}